2 * Universal Interface for Intel High Definition Audio Codec
4 * HD audio interface patch for Realtek ALC codecs
6 * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
7 * PeiSen Hou <pshou@realtek.com.tw>
8 * Takashi Iwai <tiwai@suse.de>
9 * Jonathan Woithe <jwoithe@just42.net>
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.
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.
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
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_auto_parser.h"
39 /* unsol event tags */
40 #define ALC_FRONT_EVENT 0x01
41 #define ALC_DCVOL_EVENT 0x02
42 #define ALC_HP_EVENT 0x04
43 #define ALC_MIC_EVENT 0x08
46 #define GPIO_MASK 0x03
48 /* extra amp-initialization sequence types */
57 struct alc_customize_define {
59 unsigned char port_connectivity;
60 unsigned char check_sum;
61 unsigned char customization;
62 unsigned char external_amp;
63 unsigned int enable_pcbeep:1;
64 unsigned int platform_type:1;
66 unsigned int override:1;
67 unsigned int fixup:1; /* Means that this sku is set by driver, not read from hw */
71 hda_nid_t pin; /* multi-io widget pin NID */
72 hda_nid_t dac; /* DAC to be connected */
73 unsigned int ctl_in; /* cached input-pin control value */
77 ALC_AUTOMUTE_PIN, /* change the pin control */
78 ALC_AUTOMUTE_AMP, /* mute/unmute the pin AMP */
79 ALC_AUTOMUTE_MIXER, /* mute/unmute mixer widget AMP */
82 #define MAX_VOL_NIDS 0x40
84 /* make compatible with old code */
85 #define alc_apply_pincfgs snd_hda_apply_pincfgs
86 #define alc_apply_fixup snd_hda_apply_fixup
87 #define alc_pick_fixup snd_hda_pick_fixup
88 #define alc_fixup hda_fixup
89 #define alc_pincfg hda_pintbl
90 #define alc_model_fixup hda_model_fixup
92 #define ALC_FIXUP_PINS HDA_FIXUP_PINS
93 #define ALC_FIXUP_VERBS HDA_FIXUP_VERBS
94 #define ALC_FIXUP_FUNC HDA_FIXUP_FUNC
96 #define ALC_FIXUP_ACT_PRE_PROBE HDA_FIXUP_ACT_PRE_PROBE
97 #define ALC_FIXUP_ACT_PROBE HDA_FIXUP_ACT_PROBE
98 #define ALC_FIXUP_ACT_INIT HDA_FIXUP_ACT_INIT
99 #define ALC_FIXUP_ACT_BUILD HDA_FIXUP_ACT_BUILD
102 #define MAX_NID_PATH_DEPTH 5
104 /* output-path: DAC -> ... -> pin
105 * idx[] contains the source index number of the next widget;
106 * e.g. idx[0] is the index of the DAC selected by path[1] widget
107 * multi[] indicates whether it's a selector widget with multi-connectors
108 * (i.e. the connection selection is mandatory)
109 * vol_ctl and mute_ctl contains the NIDs for the assigned mixers
113 hda_nid_t path[MAX_NID_PATH_DEPTH];
114 unsigned char idx[MAX_NID_PATH_DEPTH];
115 unsigned char multi[MAX_NID_PATH_DEPTH];
116 unsigned int ctls[2]; /* 0 = volume, 1 = mute */
120 struct hda_gen_spec gen;
122 /* codec parameterization */
123 const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */
124 unsigned int num_mixers;
125 const struct snd_kcontrol_new *cap_mixer; /* capture mixer */
126 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
128 char stream_name_analog[32]; /* analog PCM stream */
129 const struct hda_pcm_stream *stream_analog_playback;
130 const struct hda_pcm_stream *stream_analog_capture;
131 const struct hda_pcm_stream *stream_analog_alt_playback;
132 const struct hda_pcm_stream *stream_analog_alt_capture;
134 char stream_name_digital[32]; /* digital PCM stream */
135 const struct hda_pcm_stream *stream_digital_playback;
136 const struct hda_pcm_stream *stream_digital_capture;
139 struct hda_multi_out multiout; /* playback set-up
140 * max_channels, dacs must be set
141 * dig_out_nid and hp_nid are optional
143 hda_nid_t alt_dac_nid;
144 hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */
148 unsigned int num_adc_nids;
149 const hda_nid_t *adc_nids;
150 const hda_nid_t *capsrc_nids;
151 hda_nid_t dig_in_nid; /* digital-in NID; optional */
152 hda_nid_t mixer_nid; /* analog-mixer NID */
153 DECLARE_BITMAP(vol_ctls, MAX_VOL_NIDS << 1);
154 DECLARE_BITMAP(sw_ctls, MAX_VOL_NIDS << 1);
156 /* capture setup for dynamic dual-adc switch */
158 unsigned int cur_adc_stream_tag;
159 unsigned int cur_adc_format;
162 unsigned int num_mux_defs;
163 const struct hda_input_mux *input_mux;
164 unsigned int cur_mux[3];
165 hda_nid_t ext_mic_pin;
166 hda_nid_t dock_mic_pin;
167 hda_nid_t int_mic_pin;
170 const struct hda_channel_mode *channel_mode;
171 int num_channel_mode;
173 int const_channel_count; /* min. channel count (for speakers) */
174 int ext_channel_count; /* current channel count for multi-io */
176 /* PCM information */
177 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
179 /* dynamic controls, init_verbs and input_mux */
180 struct auto_pin_cfg autocfg;
181 struct alc_customize_define cdefine;
182 struct snd_array kctls;
183 struct hda_input_mux private_imux[3];
184 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
185 hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS];
186 hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS];
187 hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS];
188 unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS];
189 int int_mic_idx, ext_mic_idx, dock_mic_idx; /* for auto-mic */
190 hda_nid_t inv_dmic_pin;
194 hda_nid_t all_dacs[16];
197 struct snd_array out_path;
200 void (*init_hook)(struct hda_codec *codec);
202 void (*power_hook)(struct hda_codec *codec);
204 void (*shutup)(struct hda_codec *codec);
205 void (*automute_hook)(struct hda_codec *codec);
207 /* for pin sensing */
208 unsigned int hp_jack_present:1;
209 unsigned int line_jack_present:1;
210 unsigned int master_mute:1;
211 unsigned int auto_mic:1;
212 unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */
213 unsigned int automute_speaker:1; /* automute speaker outputs */
214 unsigned int automute_lo:1; /* automute LO outputs */
215 unsigned int detect_hp:1; /* Headphone detection enabled */
216 unsigned int detect_lo:1; /* Line-out detection enabled */
217 unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */
218 unsigned int automute_lo_possible:1; /* there are line outs and HP */
219 unsigned int keep_vref_in_automute:1; /* Don't clear VREF in automute */
222 unsigned int no_analog :1; /* digital I/O only */
223 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
224 unsigned int single_input_src:1;
225 unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */
226 unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */
227 unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */
228 unsigned int inv_dmic_fixup:1; /* has inverted digital-mic workaround */
229 unsigned int inv_dmic_muted:1; /* R-ch of inv d-mic is muted? */
230 unsigned int no_primary_hp:1; /* Don't prefer HP pins to speaker pins */
232 /* auto-mute control */
234 hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS];
237 int codec_variant; /* flag for other variants */
239 /* for virtual master */
240 hda_nid_t vmaster_nid;
241 struct hda_vmaster_mute_hook vmaster_mute;
243 struct hda_loopback_check loopback;
245 struct hda_amp_list loopback_list[8];
250 unsigned int pll_coef_idx, pll_coef_bit;
255 struct alc_multi_io multi_io[4];
258 struct snd_array bind_ctls;
261 static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
262 int dir, unsigned int bits)
266 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
267 if (query_amp_caps(codec, nid, dir) & bits)
272 #define nid_has_mute(codec, nid, dir) \
273 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
274 #define nid_has_volume(codec, nid, dir) \
275 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
280 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
281 struct snd_ctl_elem_info *uinfo)
283 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
284 struct alc_spec *spec = codec->spec;
285 unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
286 if (mux_idx >= spec->num_mux_defs)
288 if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
290 return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
293 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
294 struct snd_ctl_elem_value *ucontrol)
296 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
297 struct alc_spec *spec = codec->spec;
298 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
300 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
304 static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
306 struct alc_spec *spec = codec->spec;
307 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
309 if (spec->cur_adc && spec->cur_adc != new_adc) {
310 /* stream is running, let's swap the current ADC */
311 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
312 spec->cur_adc = new_adc;
313 snd_hda_codec_setup_stream(codec, new_adc,
314 spec->cur_adc_stream_tag, 0,
315 spec->cur_adc_format);
321 static inline hda_nid_t get_capsrc(struct alc_spec *spec, int idx)
323 return spec->capsrc_nids ?
324 spec->capsrc_nids[idx] : spec->adc_nids[idx];
327 static void call_update_outputs(struct hda_codec *codec);
328 static void alc_inv_dmic_sync(struct hda_codec *codec, bool force);
330 /* for shared I/O, change the pin-control accordingly */
331 static void update_shared_mic_hp(struct hda_codec *codec, bool set_as_mic)
333 struct alc_spec *spec = codec->spec;
335 hda_nid_t pin = spec->autocfg.inputs[1].pin;
336 /* NOTE: this assumes that there are only two inputs, the
337 * first is the real internal mic and the second is HP/mic jack.
340 val = snd_hda_get_default_vref(codec, pin);
342 /* This pin does not have vref caps - let's enable vref on pin 0x18
343 instead, as suggested by Realtek */
344 if (val == AC_PINCTL_VREF_HIZ) {
345 const hda_nid_t vref_pin = 0x18;
346 /* Sanity check pin 0x18 */
347 if (get_wcaps_type(get_wcaps(codec, vref_pin)) == AC_WID_PIN &&
348 get_defcfg_connect(snd_hda_codec_get_pincfg(codec, vref_pin)) == AC_JACK_PORT_NONE) {
349 unsigned int vref_val = snd_hda_get_default_vref(codec, vref_pin);
350 if (vref_val != AC_PINCTL_VREF_HIZ)
351 snd_hda_set_pin_ctl(codec, vref_pin, PIN_IN | (set_as_mic ? vref_val : 0));
355 val = set_as_mic ? val | PIN_IN : PIN_HP;
356 snd_hda_set_pin_ctl(codec, pin, val);
358 spec->automute_speaker = !set_as_mic;
359 call_update_outputs(codec);
362 /* select the given imux item; either unmute exclusively or select the route */
363 static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
364 unsigned int idx, bool force)
366 struct alc_spec *spec = codec->spec;
367 const struct hda_input_mux *imux;
368 unsigned int mux_idx;
369 int i, type, num_conns;
372 if (!spec->input_mux)
375 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
376 imux = &spec->input_mux[mux_idx];
377 if (!imux->num_items && mux_idx > 0)
378 imux = &spec->input_mux[0];
379 if (!imux->num_items)
382 if (idx >= imux->num_items)
383 idx = imux->num_items - 1;
384 if (spec->cur_mux[adc_idx] == idx && !force)
386 spec->cur_mux[adc_idx] = idx;
388 if (spec->shared_mic_hp)
389 update_shared_mic_hp(codec, spec->cur_mux[adc_idx]);
391 if (spec->dyn_adc_switch) {
392 alc_dyn_adc_pcm_resetup(codec, idx);
393 adc_idx = spec->dyn_adc_idx[idx];
396 nid = get_capsrc(spec, adc_idx);
399 num_conns = snd_hda_get_num_conns(codec, nid);
403 type = get_wcaps_type(get_wcaps(codec, nid));
404 if (type == AC_WID_AUD_MIX) {
405 /* Matrix-mixer style (e.g. ALC882) */
406 int active = imux->items[idx].index;
407 for (i = 0; i < num_conns; i++) {
408 unsigned int v = (i == active) ? 0 : HDA_AMP_MUTE;
409 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, i,
413 /* MUX style (e.g. ALC880) */
414 snd_hda_codec_write_cache(codec, nid, 0,
415 AC_VERB_SET_CONNECT_SEL,
416 imux->items[idx].index);
418 alc_inv_dmic_sync(codec, true);
422 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
423 struct snd_ctl_elem_value *ucontrol)
425 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
426 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
427 return alc_mux_select(codec, adc_idx,
428 ucontrol->value.enumerated.item[0], false);
432 * set up the input pin config (depending on the given auto-pin type)
434 static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
437 unsigned int val = PIN_IN;
438 if (auto_pin_type == AUTO_PIN_MIC)
439 val |= snd_hda_get_default_vref(codec, nid);
440 snd_hda_set_pin_ctl(codec, nid, val);
444 * Append the given mixer and verb elements for the later use
445 * The mixer array is referred in build_controls(), and init_verbs are
448 static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
450 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
452 spec->mixers[spec->num_mixers++] = mix;
456 * GPIO setup tables, used in initialization
458 /* Enable GPIO mask and set output */
459 static const struct hda_verb alc_gpio1_init_verbs[] = {
460 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
461 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
462 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
466 static const struct hda_verb alc_gpio2_init_verbs[] = {
467 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
468 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
469 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
473 static const struct hda_verb alc_gpio3_init_verbs[] = {
474 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
475 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
476 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
481 * Fix hardware PLL issue
482 * On some codecs, the analog PLL gating control must be off while
483 * the default value is 1.
485 static void alc_fix_pll(struct hda_codec *codec)
487 struct alc_spec *spec = codec->spec;
492 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
494 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
495 AC_VERB_GET_PROC_COEF, 0);
496 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
498 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
499 val & ~(1 << spec->pll_coef_bit));
502 static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
503 unsigned int coef_idx, unsigned int coef_bit)
505 struct alc_spec *spec = codec->spec;
507 spec->pll_coef_idx = coef_idx;
508 spec->pll_coef_bit = coef_bit;
513 * Jack detections for HP auto-mute and mic-switch
516 /* check each pin in the given array; returns true if any of them is plugged */
517 static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
521 for (i = 0; i < num_pins; i++) {
522 hda_nid_t nid = pins[i];
525 present |= snd_hda_jack_detect(codec, nid);
530 /* standard HP/line-out auto-mute helper */
531 static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
532 bool mute, bool hp_out)
534 struct alc_spec *spec = codec->spec;
535 unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0;
536 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
539 for (i = 0; i < num_pins; i++) {
540 hda_nid_t nid = pins[i];
544 switch (spec->automute_mode) {
545 case ALC_AUTOMUTE_PIN:
546 /* don't reset VREF value in case it's controlling
547 * the amp (see alc861_fixup_asus_amp_vref_0f())
549 if (spec->keep_vref_in_automute) {
550 val = snd_hda_codec_read(codec, nid, 0,
551 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
556 snd_hda_set_pin_ctl(codec, nid, val);
558 case ALC_AUTOMUTE_AMP:
559 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
560 HDA_AMP_MUTE, mute_bits);
562 case ALC_AUTOMUTE_MIXER:
563 nid = spec->automute_mixer_nid[i];
566 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
567 HDA_AMP_MUTE, mute_bits);
568 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1,
569 HDA_AMP_MUTE, mute_bits);
575 /* Toggle outputs muting */
576 static void update_outputs(struct hda_codec *codec)
578 struct alc_spec *spec = codec->spec;
581 /* Control HP pins/amps depending on master_mute state;
582 * in general, HP pins/amps control should be enabled in all cases,
583 * but currently set only for master_mute, just to be safe
585 if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */
586 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
587 spec->autocfg.hp_pins, spec->master_mute, true);
589 if (!spec->automute_speaker)
592 on = spec->hp_jack_present | spec->line_jack_present;
593 on |= spec->master_mute;
594 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
595 spec->autocfg.speaker_pins, on, false);
597 /* toggle line-out mutes if needed, too */
598 /* if LO is a copy of either HP or Speaker, don't need to handle it */
599 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
600 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
602 if (!spec->automute_lo)
605 on = spec->hp_jack_present;
606 on |= spec->master_mute;
607 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
608 spec->autocfg.line_out_pins, on, false);
611 static void call_update_outputs(struct hda_codec *codec)
613 struct alc_spec *spec = codec->spec;
614 if (spec->automute_hook)
615 spec->automute_hook(codec);
617 update_outputs(codec);
620 /* standard HP-automute helper */
621 static void alc_hp_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
623 struct alc_spec *spec = codec->spec;
625 spec->hp_jack_present =
626 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
627 spec->autocfg.hp_pins);
628 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
630 call_update_outputs(codec);
633 /* standard line-out-automute helper */
634 static void alc_line_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
636 struct alc_spec *spec = codec->spec;
638 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
640 /* check LO jack only when it's different from HP */
641 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
644 spec->line_jack_present =
645 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
646 spec->autocfg.line_out_pins);
647 if (!spec->automute_speaker || !spec->detect_lo)
649 call_update_outputs(codec);
652 #define get_connection_index(codec, mux, nid) \
653 snd_hda_get_conn_index(codec, mux, nid, 0)
655 /* standard mic auto-switch helper */
656 static void alc_mic_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
658 struct alc_spec *spec = codec->spec;
659 hda_nid_t *pins = spec->imux_pins;
661 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
663 if (snd_BUG_ON(!spec->adc_nids))
665 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
668 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
669 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
670 else if (spec->dock_mic_idx >= 0 &&
671 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
672 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
674 alc_mux_select(codec, 0, spec->int_mic_idx, false);
677 /* update the master volume per volume-knob's unsol event */
678 static void alc_update_knob_master(struct hda_codec *codec, struct hda_jack_tbl *jack)
681 struct snd_kcontrol *kctl;
682 struct snd_ctl_elem_value *uctl;
684 kctl = snd_hda_find_mixer_ctl(codec, "Master Playback Volume");
687 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
690 val = snd_hda_codec_read(codec, jack->nid, 0,
691 AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
692 val &= HDA_AMP_VOLMASK;
693 uctl->value.integer.value[0] = val;
694 uctl->value.integer.value[1] = val;
695 kctl->put(kctl, uctl);
699 static void alc880_unsol_event(struct hda_codec *codec, unsigned int res)
701 /* For some reason, the res given from ALC880 is broken.
702 Here we adjust it properly. */
703 snd_hda_jack_unsol_event(codec, res >> 2);
706 /* call init functions of standard auto-mute helpers */
707 static void alc_inithook(struct hda_codec *codec)
709 alc_hp_automute(codec, NULL);
710 alc_line_automute(codec, NULL);
711 alc_mic_automute(codec, NULL);
714 /* additional initialization for ALC888 variants */
715 static void alc888_coef_init(struct hda_codec *codec)
719 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
720 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
721 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
722 if ((tmp & 0xf0) == 0x20)
724 snd_hda_codec_read(codec, 0x20, 0,
725 AC_VERB_SET_PROC_COEF, 0x830);
728 snd_hda_codec_read(codec, 0x20, 0,
729 AC_VERB_SET_PROC_COEF, 0x3030);
732 /* additional initialization for ALC889 variants */
733 static void alc889_coef_init(struct hda_codec *codec)
737 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
738 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
739 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
740 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
743 /* turn on/off EAPD control (only if available) */
744 static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
746 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
748 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
749 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
753 /* turn on/off EAPD controls of the codec */
754 static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
756 /* We currently only handle front, HP */
757 static hda_nid_t pins[] = {
758 0x0f, 0x10, 0x14, 0x15, 0
761 for (p = pins; *p; p++)
762 set_eapd(codec, *p, on);
765 /* generic shutup callback;
766 * just turning off EPAD and a little pause for avoiding pop-noise
768 static void alc_eapd_shutup(struct hda_codec *codec)
770 alc_auto_setup_eapd(codec, false);
774 /* generic EAPD initialization */
775 static void alc_auto_init_amp(struct hda_codec *codec, int type)
779 alc_auto_setup_eapd(codec, true);
782 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
785 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
788 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
790 case ALC_INIT_DEFAULT:
791 switch (codec->vendor_id) {
793 snd_hda_codec_write(codec, 0x1a, 0,
794 AC_VERB_SET_COEF_INDEX, 7);
795 tmp = snd_hda_codec_read(codec, 0x1a, 0,
796 AC_VERB_GET_PROC_COEF, 0);
797 snd_hda_codec_write(codec, 0x1a, 0,
798 AC_VERB_SET_COEF_INDEX, 7);
799 snd_hda_codec_write(codec, 0x1a, 0,
800 AC_VERB_SET_PROC_COEF,
809 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
810 alc889_coef_init(codec);
813 alc888_coef_init(codec);
815 #if 0 /* XXX: This may cause the silent output on speaker on some machines */
818 snd_hda_codec_write(codec, 0x20, 0,
819 AC_VERB_SET_COEF_INDEX, 7);
820 tmp = snd_hda_codec_read(codec, 0x20, 0,
821 AC_VERB_GET_PROC_COEF, 0);
822 snd_hda_codec_write(codec, 0x20, 0,
823 AC_VERB_SET_COEF_INDEX, 7);
824 snd_hda_codec_write(codec, 0x20, 0,
825 AC_VERB_SET_PROC_COEF,
835 * Auto-Mute mode mixer enum support
837 static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
838 struct snd_ctl_elem_info *uinfo)
840 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
841 struct alc_spec *spec = codec->spec;
842 static const char * const texts3[] = {
843 "Disabled", "Speaker Only", "Line Out+Speaker"
846 if (spec->automute_speaker_possible && spec->automute_lo_possible)
847 return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3);
848 return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
851 static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
852 struct snd_ctl_elem_value *ucontrol)
854 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
855 struct alc_spec *spec = codec->spec;
856 unsigned int val = 0;
857 if (spec->automute_speaker)
859 if (spec->automute_lo)
862 ucontrol->value.enumerated.item[0] = val;
866 static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
867 struct snd_ctl_elem_value *ucontrol)
869 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
870 struct alc_spec *spec = codec->spec;
872 switch (ucontrol->value.enumerated.item[0]) {
874 if (!spec->automute_speaker && !spec->automute_lo)
876 spec->automute_speaker = 0;
877 spec->automute_lo = 0;
880 if (spec->automute_speaker_possible) {
881 if (!spec->automute_lo && spec->automute_speaker)
883 spec->automute_speaker = 1;
884 spec->automute_lo = 0;
885 } else if (spec->automute_lo_possible) {
886 if (spec->automute_lo)
888 spec->automute_lo = 1;
893 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
895 if (spec->automute_speaker && spec->automute_lo)
897 spec->automute_speaker = 1;
898 spec->automute_lo = 1;
903 call_update_outputs(codec);
907 static const struct snd_kcontrol_new alc_automute_mode_enum = {
908 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
909 .name = "Auto-Mute Mode",
910 .info = alc_automute_mode_info,
911 .get = alc_automute_mode_get,
912 .put = alc_automute_mode_put,
915 static struct snd_kcontrol_new *
916 alc_kcontrol_new(struct alc_spec *spec, const char *name,
917 const struct snd_kcontrol_new *temp)
919 struct snd_kcontrol_new *knew = snd_array_new(&spec->kctls);
923 knew->name = kstrdup(name, GFP_KERNEL);
929 static int alc_add_automute_mode_enum(struct hda_codec *codec)
931 struct alc_spec *spec = codec->spec;
933 if (!alc_kcontrol_new(spec, "Auto-Mute Mode", &alc_automute_mode_enum))
939 * Check the availability of HP/line-out auto-mute;
940 * Set up appropriately if really supported
942 static int alc_init_automute(struct hda_codec *codec)
944 struct alc_spec *spec = codec->spec;
945 struct auto_pin_cfg *cfg = &spec->autocfg;
951 if (cfg->line_out_pins[0])
953 if (cfg->speaker_pins[0])
955 if (present < 2) /* need two different output types */
958 if (!cfg->speaker_pins[0] &&
959 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
960 memcpy(cfg->speaker_pins, cfg->line_out_pins,
961 sizeof(cfg->speaker_pins));
962 cfg->speaker_outs = cfg->line_outs;
965 if (!cfg->hp_pins[0] &&
966 cfg->line_out_type == AUTO_PIN_HP_OUT) {
967 memcpy(cfg->hp_pins, cfg->line_out_pins,
968 sizeof(cfg->hp_pins));
969 cfg->hp_outs = cfg->line_outs;
972 spec->automute_mode = ALC_AUTOMUTE_PIN;
974 for (i = 0; i < cfg->hp_outs; i++) {
975 hda_nid_t nid = cfg->hp_pins[i];
976 if (!is_jack_detectable(codec, nid))
978 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
980 snd_hda_jack_detect_enable_callback(codec, nid, ALC_HP_EVENT,
985 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
986 if (cfg->speaker_outs)
987 for (i = 0; i < cfg->line_outs; i++) {
988 hda_nid_t nid = cfg->line_out_pins[i];
989 if (!is_jack_detectable(codec, nid))
991 snd_printdd("realtek: Enable Line-Out "
992 "auto-muting on NID 0x%x\n", nid);
993 snd_hda_jack_detect_enable_callback(codec, nid, ALC_FRONT_EVENT,
997 spec->automute_lo_possible = spec->detect_hp;
1000 spec->automute_speaker_possible = cfg->speaker_outs &&
1001 (spec->detect_hp || spec->detect_lo);
1003 spec->automute_lo = spec->automute_lo_possible;
1004 spec->automute_speaker = spec->automute_speaker_possible;
1006 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
1007 /* create a control for automute mode */
1008 err = alc_add_automute_mode_enum(codec);
1015 /* return the position of NID in the list, or -1 if not found */
1016 static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1019 for (i = 0; i < nums; i++)
1025 /* check whether dynamic ADC-switching is available */
1026 static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
1028 struct alc_spec *spec = codec->spec;
1029 struct hda_input_mux *imux = &spec->private_imux[0];
1033 if (imux != spec->input_mux) /* no dynamic imux? */
1036 for (n = 0; n < spec->num_adc_nids; n++) {
1037 cap = spec->private_capsrc_nids[n];
1038 for (i = 0; i < imux->num_items; i++) {
1039 pin = spec->imux_pins[i];
1042 if (get_connection_index(codec, cap, pin) < 0)
1045 if (i >= imux->num_items)
1046 return true; /* no ADC-switch is needed */
1049 for (i = 0; i < imux->num_items; i++) {
1050 pin = spec->imux_pins[i];
1051 for (n = 0; n < spec->num_adc_nids; n++) {
1052 cap = spec->private_capsrc_nids[n];
1053 idx = get_connection_index(codec, cap, pin);
1055 imux->items[i].index = idx;
1056 spec->dyn_adc_idx[i] = n;
1062 snd_printdd("realtek: enabling ADC switching\n");
1063 spec->dyn_adc_switch = 1;
1067 /* check whether all auto-mic pins are valid; setup indices if OK */
1068 static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1070 struct alc_spec *spec = codec->spec;
1071 const struct hda_input_mux *imux;
1073 if (!spec->auto_mic)
1075 if (spec->auto_mic_valid_imux)
1076 return true; /* already checked */
1078 /* fill up imux indices */
1079 if (!alc_check_dyn_adc_switch(codec)) {
1084 imux = spec->input_mux;
1085 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1086 spec->imux_pins, imux->num_items);
1087 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1088 spec->imux_pins, imux->num_items);
1089 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1090 spec->imux_pins, imux->num_items);
1091 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1093 return false; /* no corresponding imux */
1096 snd_hda_jack_detect_enable_callback(codec, spec->ext_mic_pin,
1097 ALC_MIC_EVENT, alc_mic_automute);
1098 if (spec->dock_mic_pin)
1099 snd_hda_jack_detect_enable_callback(codec, spec->dock_mic_pin,
1103 spec->auto_mic_valid_imux = 1;
1109 * Check the availability of auto-mic switch;
1110 * Set up if really supported
1112 static int alc_init_auto_mic(struct hda_codec *codec)
1114 struct alc_spec *spec = codec->spec;
1115 struct auto_pin_cfg *cfg = &spec->autocfg;
1116 hda_nid_t fixed, ext, dock;
1119 if (spec->shared_mic_hp)
1120 return 0; /* no auto-mic for the shared I/O */
1122 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1124 fixed = ext = dock = 0;
1125 for (i = 0; i < cfg->num_inputs; i++) {
1126 hda_nid_t nid = cfg->inputs[i].pin;
1127 unsigned int defcfg;
1128 defcfg = snd_hda_codec_get_pincfg(codec, nid);
1129 switch (snd_hda_get_input_pin_attr(defcfg)) {
1130 case INPUT_PIN_ATTR_INT:
1132 return 0; /* already occupied */
1133 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1134 return 0; /* invalid type */
1137 case INPUT_PIN_ATTR_UNUSED:
1138 return 0; /* invalid entry */
1139 case INPUT_PIN_ATTR_DOCK:
1141 return 0; /* already occupied */
1142 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1143 return 0; /* invalid type */
1148 return 0; /* already occupied */
1149 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1150 return 0; /* invalid type */
1161 if (!is_jack_detectable(codec, ext))
1162 return 0; /* no unsol support */
1163 if (dock && !is_jack_detectable(codec, dock))
1164 return 0; /* no unsol support */
1166 /* check imux indices */
1167 spec->ext_mic_pin = ext;
1168 spec->int_mic_pin = fixed;
1169 spec->dock_mic_pin = dock;
1172 if (!alc_auto_mic_check_imux(codec))
1175 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1181 /* check the availabilities of auto-mute and auto-mic switches */
1182 static int alc_auto_check_switches(struct hda_codec *codec)
1186 err = alc_init_automute(codec);
1189 err = alc_init_auto_mic(codec);
1196 * Realtek SSID verification
1199 /* Could be any non-zero and even value. When used as fixup, tells
1200 * the driver to ignore any present sku defines.
1202 #define ALC_FIXUP_SKU_IGNORE (2)
1204 static void alc_fixup_sku_ignore(struct hda_codec *codec,
1205 const struct hda_fixup *fix, int action)
1207 struct alc_spec *spec = codec->spec;
1208 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
1209 spec->cdefine.fixup = 1;
1210 spec->cdefine.sku_cfg = ALC_FIXUP_SKU_IGNORE;
1214 static int alc_auto_parse_customize_define(struct hda_codec *codec)
1216 unsigned int ass, tmp, i;
1218 struct alc_spec *spec = codec->spec;
1220 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1222 if (spec->cdefine.fixup) {
1223 ass = spec->cdefine.sku_cfg;
1224 if (ass == ALC_FIXUP_SKU_IGNORE)
1229 ass = codec->subsystem_id & 0xffff;
1230 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
1234 if (codec->vendor_id == 0x10ec0260)
1236 ass = snd_hda_codec_get_pincfg(codec, nid);
1239 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1240 codec->chip_name, ass);
1246 for (i = 1; i < 16; i++) {
1250 if (((ass >> 16) & 0xf) != tmp)
1253 spec->cdefine.port_connectivity = ass >> 30;
1254 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1255 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1256 spec->cdefine.customization = ass >> 8;
1258 spec->cdefine.sku_cfg = ass;
1259 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1260 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1261 spec->cdefine.swap = (ass & 0x2) >> 1;
1262 spec->cdefine.override = ass & 0x1;
1264 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1265 nid, spec->cdefine.sku_cfg);
1266 snd_printd("SKU: port_connectivity=0x%x\n",
1267 spec->cdefine.port_connectivity);
1268 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1269 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1270 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1271 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1272 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1273 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1274 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1279 /* return true if the given NID is found in the list */
1280 static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1282 return find_idx_in_nid_list(nid, list, nums) >= 0;
1285 /* check subsystem ID and set up device-specific initialization;
1286 * return 1 if initialized, 0 if invalid SSID
1288 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1289 * 31 ~ 16 : Manufacture ID
1291 * 7 ~ 0 : Assembly ID
1292 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1294 static int alc_subsystem_id(struct hda_codec *codec,
1295 hda_nid_t porta, hda_nid_t porte,
1296 hda_nid_t portd, hda_nid_t porti)
1298 unsigned int ass, tmp, i;
1300 struct alc_spec *spec = codec->spec;
1302 if (spec->cdefine.fixup) {
1303 ass = spec->cdefine.sku_cfg;
1304 if (ass == ALC_FIXUP_SKU_IGNORE)
1309 ass = codec->subsystem_id & 0xffff;
1310 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1313 /* invalid SSID, check the special NID pin defcfg instead */
1315 * 31~30 : port connectivity
1318 * 19~16 : Check sum (15:1)
1323 if (codec->vendor_id == 0x10ec0260)
1325 ass = snd_hda_codec_get_pincfg(codec, nid);
1326 snd_printd("realtek: No valid SSID, "
1327 "checking pincfg 0x%08x for NID 0x%x\n",
1331 if ((ass >> 30) != 1) /* no physical connection */
1336 for (i = 1; i < 16; i++) {
1340 if (((ass >> 16) & 0xf) != tmp)
1343 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1344 ass & 0xffff, codec->vendor_id);
1348 * 2 : 0 --> Desktop, 1 --> Laptop
1349 * 3~5 : External Amplifier control
1352 tmp = (ass & 0x38) >> 3; /* external Amp control */
1355 spec->init_amp = ALC_INIT_GPIO1;
1358 spec->init_amp = ALC_INIT_GPIO2;
1361 spec->init_amp = ALC_INIT_GPIO3;
1365 spec->init_amp = ALC_INIT_DEFAULT;
1369 /* is laptop or Desktop and enable the function "Mute internal speaker
1370 * when the external headphone out jack is plugged"
1372 if (!(ass & 0x8000))
1375 * 10~8 : Jack location
1376 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1378 * 15 : 1 --> enable the function "Mute internal speaker
1379 * when the external headphone out jack is plugged"
1381 if (!spec->autocfg.hp_pins[0] &&
1382 !(spec->autocfg.line_out_pins[0] &&
1383 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
1385 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1396 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1397 spec->autocfg.line_outs))
1399 spec->autocfg.hp_pins[0] = nid;
1404 /* Check the validity of ALC subsystem-id
1405 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1406 static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
1408 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
1409 struct alc_spec *spec = codec->spec;
1410 snd_printd("realtek: "
1411 "Enable default setup for auto mode as fallback\n");
1412 spec->init_amp = ALC_INIT_DEFAULT;
1417 * COEF access helper functions
1419 static int alc_read_coef_idx(struct hda_codec *codec,
1420 unsigned int coef_idx)
1423 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1425 val = snd_hda_codec_read(codec, 0x20, 0,
1426 AC_VERB_GET_PROC_COEF, 0);
1430 static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1431 unsigned int coef_val)
1433 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1435 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1439 /* a special bypass for COEF 0; read the cached value at the second time */
1440 static unsigned int alc_get_coef0(struct hda_codec *codec)
1442 struct alc_spec *spec = codec->spec;
1444 spec->coef0 = alc_read_coef_idx(codec, 0);
1449 * Digital I/O handling
1452 /* set right pin controls for digital I/O */
1453 static void alc_auto_init_digital(struct hda_codec *codec)
1455 struct alc_spec *spec = codec->spec;
1459 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1460 pin = spec->autocfg.dig_out_pins[i];
1463 snd_hda_set_pin_ctl(codec, pin, PIN_OUT);
1465 dac = spec->multiout.dig_out_nid;
1467 dac = spec->slave_dig_outs[i - 1];
1468 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
1470 snd_hda_codec_write(codec, dac, 0,
1471 AC_VERB_SET_AMP_GAIN_MUTE,
1474 pin = spec->autocfg.dig_in_pin;
1476 snd_hda_set_pin_ctl(codec, pin, PIN_IN);
1479 /* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1480 static void alc_auto_parse_digital(struct hda_codec *codec)
1482 struct alc_spec *spec = codec->spec;
1486 /* support multiple SPDIFs; the secondary is set up as a slave */
1488 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1490 err = snd_hda_get_connections(codec,
1491 spec->autocfg.dig_out_pins[i],
1492 conn, ARRAY_SIZE(conn));
1495 dig_nid = conn[0]; /* assume the first element is audio-out */
1497 spec->multiout.dig_out_nid = dig_nid;
1498 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1500 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
1501 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
1503 spec->slave_dig_outs[nums - 1] = dig_nid;
1508 if (spec->autocfg.dig_in_pin) {
1509 dig_nid = codec->start_nid;
1510 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1511 unsigned int wcaps = get_wcaps(codec, dig_nid);
1512 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1514 if (!(wcaps & AC_WCAP_DIGITAL))
1516 if (!(wcaps & AC_WCAP_CONN_LIST))
1518 err = get_connection_index(codec, dig_nid,
1519 spec->autocfg.dig_in_pin);
1521 spec->dig_in_nid = dig_nid;
1529 * capture mixer elements
1531 static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1532 struct snd_ctl_elem_info *uinfo)
1534 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1535 struct alc_spec *spec = codec->spec;
1539 mutex_lock(&codec->control_mutex);
1540 if (spec->vol_in_capsrc)
1541 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1543 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1544 kcontrol->private_value = val;
1545 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
1546 mutex_unlock(&codec->control_mutex);
1550 static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1551 unsigned int size, unsigned int __user *tlv)
1553 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1554 struct alc_spec *spec = codec->spec;
1558 mutex_lock(&codec->control_mutex);
1559 if (spec->vol_in_capsrc)
1560 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1562 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1563 kcontrol->private_value = val;
1564 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
1565 mutex_unlock(&codec->control_mutex);
1569 typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1570 struct snd_ctl_elem_value *ucontrol);
1572 static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1573 struct snd_ctl_elem_value *ucontrol,
1574 getput_call_t func, bool is_put)
1576 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1577 struct alc_spec *spec = codec->spec;
1580 mutex_lock(&codec->control_mutex);
1581 if (is_put && spec->dyn_adc_switch) {
1582 for (i = 0; i < spec->num_adc_nids; i++) {
1583 kcontrol->private_value =
1584 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1586 err = func(kcontrol, ucontrol);
1591 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1592 if (spec->vol_in_capsrc)
1593 kcontrol->private_value =
1594 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1597 kcontrol->private_value =
1598 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1600 err = func(kcontrol, ucontrol);
1602 if (err >= 0 && is_put)
1603 alc_inv_dmic_sync(codec, false);
1605 mutex_unlock(&codec->control_mutex);
1609 static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1610 struct snd_ctl_elem_value *ucontrol)
1612 return alc_cap_getput_caller(kcontrol, ucontrol,
1613 snd_hda_mixer_amp_volume_get, false);
1616 static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1617 struct snd_ctl_elem_value *ucontrol)
1619 return alc_cap_getput_caller(kcontrol, ucontrol,
1620 snd_hda_mixer_amp_volume_put, true);
1623 /* capture mixer elements */
1624 #define alc_cap_sw_info snd_ctl_boolean_stereo_info
1626 static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1627 struct snd_ctl_elem_value *ucontrol)
1629 return alc_cap_getput_caller(kcontrol, ucontrol,
1630 snd_hda_mixer_amp_switch_get, false);
1633 static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1634 struct snd_ctl_elem_value *ucontrol)
1636 return alc_cap_getput_caller(kcontrol, ucontrol,
1637 snd_hda_mixer_amp_switch_put, true);
1640 #define _DEFINE_CAPMIX(num) \
1642 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1643 .name = "Capture Switch", \
1644 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1646 .info = alc_cap_sw_info, \
1647 .get = alc_cap_sw_get, \
1648 .put = alc_cap_sw_put, \
1651 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1652 .name = "Capture Volume", \
1653 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1654 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1655 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1657 .info = alc_cap_vol_info, \
1658 .get = alc_cap_vol_get, \
1659 .put = alc_cap_vol_put, \
1660 .tlv = { .c = alc_cap_vol_tlv }, \
1663 #define _DEFINE_CAPSRC(num) \
1665 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1666 /* .name = "Capture Source", */ \
1667 .name = "Input Source", \
1669 .info = alc_mux_enum_info, \
1670 .get = alc_mux_enum_get, \
1671 .put = alc_mux_enum_put, \
1674 #define DEFINE_CAPMIX(num) \
1675 static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
1676 _DEFINE_CAPMIX(num), \
1677 _DEFINE_CAPSRC(num), \
1681 #define DEFINE_CAPMIX_NOSRC(num) \
1682 static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
1683 _DEFINE_CAPMIX(num), \
1687 /* up to three ADCs */
1691 DEFINE_CAPMIX_NOSRC(1);
1692 DEFINE_CAPMIX_NOSRC(2);
1693 DEFINE_CAPMIX_NOSRC(3);
1696 * Inverted digital-mic handling
1698 * First off, it's a bit tricky. The "Inverted Internal Mic Capture Switch"
1699 * gives the additional mute only to the right channel of the digital mic
1700 * capture stream. This is a workaround for avoiding the almost silence
1701 * by summing the stereo stream from some (known to be ForteMedia)
1704 * The logic is to call alc_inv_dmic_sync() after each action (possibly)
1705 * modifying ADC amp. When the mute flag is set, it mutes the R-channel
1706 * without caching so that the cache can still keep the original value.
1707 * The cached value is then restored when the flag is set off or any other
1708 * than d-mic is used as the current input source.
1710 static void alc_inv_dmic_sync(struct hda_codec *codec, bool force)
1712 struct alc_spec *spec = codec->spec;
1715 if (!spec->inv_dmic_fixup)
1717 if (!spec->inv_dmic_muted && !force)
1719 for (i = 0; i < spec->num_adc_nids; i++) {
1720 int src = spec->dyn_adc_switch ? 0 : i;
1721 bool dmic_fixup = false;
1725 if (spec->inv_dmic_muted &&
1726 spec->imux_pins[spec->cur_mux[src]] == spec->inv_dmic_pin)
1728 if (!dmic_fixup && !force)
1730 if (spec->vol_in_capsrc) {
1731 nid = spec->capsrc_nids[i];
1732 parm = AC_AMP_SET_RIGHT | AC_AMP_SET_OUTPUT;
1735 nid = spec->adc_nids[i];
1736 parm = AC_AMP_SET_RIGHT | AC_AMP_SET_INPUT;
1739 /* we care only right channel */
1740 v = snd_hda_codec_amp_read(codec, nid, 1, dir, 0);
1741 if (v & 0x80) /* if already muted, we don't need to touch */
1743 if (dmic_fixup) /* add mute for d-mic */
1745 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
1750 static int alc_inv_dmic_sw_get(struct snd_kcontrol *kcontrol,
1751 struct snd_ctl_elem_value *ucontrol)
1753 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1754 struct alc_spec *spec = codec->spec;
1756 ucontrol->value.integer.value[0] = !spec->inv_dmic_muted;
1760 static int alc_inv_dmic_sw_put(struct snd_kcontrol *kcontrol,
1761 struct snd_ctl_elem_value *ucontrol)
1763 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1764 struct alc_spec *spec = codec->spec;
1765 unsigned int val = !ucontrol->value.integer.value[0];
1767 if (val == spec->inv_dmic_muted)
1769 spec->inv_dmic_muted = val;
1770 alc_inv_dmic_sync(codec, true);
1774 static const struct snd_kcontrol_new alc_inv_dmic_sw = {
1775 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1776 .info = snd_ctl_boolean_mono_info,
1777 .get = alc_inv_dmic_sw_get,
1778 .put = alc_inv_dmic_sw_put,
1781 static int alc_add_inv_dmic_mixer(struct hda_codec *codec, hda_nid_t nid)
1783 struct alc_spec *spec = codec->spec;
1785 if (!alc_kcontrol_new(spec, "Inverted Internal Mic Capture Switch",
1788 spec->inv_dmic_fixup = 1;
1789 spec->inv_dmic_muted = 0;
1790 spec->inv_dmic_pin = nid;
1794 /* typically the digital mic is put at node 0x12 */
1795 static void alc_fixup_inv_dmic_0x12(struct hda_codec *codec,
1796 const struct alc_fixup *fix, int action)
1798 if (action == ALC_FIXUP_ACT_PROBE)
1799 alc_add_inv_dmic_mixer(codec, 0x12);
1803 * virtual master controls
1807 * slave controls for virtual master
1809 static const char * const alc_slave_pfxs[] = {
1810 "Front", "Surround", "Center", "LFE", "Side",
1811 "Headphone", "Speaker", "Mono", "Line Out",
1812 "CLFE", "Bass Speaker", "PCM",
1817 * build control elements
1820 #define NID_MAPPING (-1)
1822 #define SUBDEV_SPEAKER_ (0 << 6)
1823 #define SUBDEV_HP_ (1 << 6)
1824 #define SUBDEV_LINE_ (2 << 6)
1825 #define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1826 #define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1827 #define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1829 static void alc_free_kctls(struct hda_codec *codec);
1831 #ifdef CONFIG_SND_HDA_INPUT_BEEP
1832 /* additional beep mixers; the actual parameters are overwritten at build */
1833 static const struct snd_kcontrol_new alc_beep_mixer[] = {
1834 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
1835 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
1840 static int __alc_build_controls(struct hda_codec *codec)
1842 struct alc_spec *spec = codec->spec;
1843 struct snd_kcontrol *kctl = NULL;
1844 const struct snd_kcontrol_new *knew;
1849 for (i = 0; i < spec->num_mixers; i++) {
1850 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1854 if (spec->cap_mixer) {
1855 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1859 if (spec->multiout.dig_out_nid) {
1860 err = snd_hda_create_dig_out_ctls(codec,
1861 spec->multiout.dig_out_nid,
1862 spec->multiout.dig_out_nid,
1863 spec->pcm_rec[1].pcm_type);
1866 if (!spec->no_analog) {
1867 err = snd_hda_create_spdif_share_sw(codec,
1871 spec->multiout.share_spdif = 1;
1874 if (spec->dig_in_nid) {
1875 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1880 #ifdef CONFIG_SND_HDA_INPUT_BEEP
1881 /* create beep controls if needed */
1882 if (spec->beep_amp) {
1883 const struct snd_kcontrol_new *knew;
1884 for (knew = alc_beep_mixer; knew->name; knew++) {
1885 struct snd_kcontrol *kctl;
1886 kctl = snd_ctl_new1(knew, codec);
1889 kctl->private_value = spec->beep_amp;
1890 err = snd_hda_ctl_add(codec, 0, kctl);
1897 /* if we have no master control, let's create it */
1898 if (!spec->no_analog &&
1899 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1900 unsigned int vmaster_tlv[4];
1901 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
1902 HDA_OUTPUT, vmaster_tlv);
1903 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1904 vmaster_tlv, alc_slave_pfxs,
1909 if (!spec->no_analog &&
1910 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1911 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
1912 NULL, alc_slave_pfxs,
1914 true, &spec->vmaster_mute.sw_kctl);
1919 /* assign Capture Source enums to NID */
1920 if (spec->capsrc_nids || spec->adc_nids) {
1921 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
1923 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1924 for (i = 0; kctl && i < kctl->count; i++) {
1925 err = snd_hda_add_nid(codec, kctl, i,
1926 get_capsrc(spec, i));
1931 if (spec->cap_mixer && spec->adc_nids) {
1932 const char *kname = kctl ? kctl->id.name : NULL;
1933 for (knew = spec->cap_mixer; knew->name; knew++) {
1934 if (kname && strcmp(knew->name, kname) == 0)
1936 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1937 for (i = 0; kctl && i < kctl->count; i++) {
1938 err = snd_hda_add_nid(codec, kctl, i,
1946 /* other nid->control mapping */
1947 for (i = 0; i < spec->num_mixers; i++) {
1948 for (knew = spec->mixers[i]; knew->name; knew++) {
1949 if (knew->iface != NID_MAPPING)
1951 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1954 u = knew->subdevice;
1955 for (j = 0; j < 4; j++, u >>= 8) {
1960 case SUBDEV_SPEAKER_:
1961 nid = spec->autocfg.speaker_pins[nid];
1964 nid = spec->autocfg.line_out_pins[nid];
1967 nid = spec->autocfg.hp_pins[nid];
1972 err = snd_hda_add_nid(codec, kctl, 0, nid);
1976 u = knew->private_value;
1977 for (j = 0; j < 4; j++, u >>= 8) {
1981 err = snd_hda_add_nid(codec, kctl, 0, nid);
1988 alc_free_kctls(codec); /* no longer needed */
1993 static int alc_build_jacks(struct hda_codec *codec)
1995 struct alc_spec *spec = codec->spec;
1997 if (spec->shared_mic_hp) {
1999 int nid = spec->autocfg.inputs[1].pin;
2000 err = snd_hda_jack_add_kctl(codec, nid, "Headphone Mic", 0);
2003 err = snd_hda_jack_detect_enable(codec, nid, 0);
2008 return snd_hda_jack_add_kctls(codec, &spec->autocfg);
2011 static int alc_build_controls(struct hda_codec *codec)
2013 int err = __alc_build_controls(codec);
2017 err = alc_build_jacks(codec);
2020 alc_apply_fixup(codec, ALC_FIXUP_ACT_BUILD);
2029 static void alc_init_special_input_src(struct hda_codec *codec);
2030 static void alc_auto_init_std(struct hda_codec *codec);
2032 static int alc_init(struct hda_codec *codec)
2034 struct alc_spec *spec = codec->spec;
2036 if (spec->init_hook)
2037 spec->init_hook(codec);
2040 alc_auto_init_amp(codec, spec->init_amp);
2042 snd_hda_gen_apply_verbs(codec);
2043 alc_init_special_input_src(codec);
2044 alc_auto_init_std(codec);
2046 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2048 hda_call_check_power_status(codec, 0x01);
2053 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2055 struct alc_spec *spec = codec->spec;
2056 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2061 * Analog playback callbacks
2063 static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
2064 struct hda_codec *codec,
2065 struct snd_pcm_substream *substream)
2067 struct alc_spec *spec = codec->spec;
2068 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2072 static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2073 struct hda_codec *codec,
2074 unsigned int stream_tag,
2075 unsigned int format,
2076 struct snd_pcm_substream *substream)
2078 struct alc_spec *spec = codec->spec;
2079 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2080 stream_tag, format, substream);
2083 static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2084 struct hda_codec *codec,
2085 struct snd_pcm_substream *substream)
2087 struct alc_spec *spec = codec->spec;
2088 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2094 static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2095 struct hda_codec *codec,
2096 struct snd_pcm_substream *substream)
2098 struct alc_spec *spec = codec->spec;
2099 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2102 static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2103 struct hda_codec *codec,
2104 unsigned int stream_tag,
2105 unsigned int format,
2106 struct snd_pcm_substream *substream)
2108 struct alc_spec *spec = codec->spec;
2109 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2110 stream_tag, format, substream);
2113 static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2114 struct hda_codec *codec,
2115 struct snd_pcm_substream *substream)
2117 struct alc_spec *spec = codec->spec;
2118 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2121 static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2122 struct hda_codec *codec,
2123 struct snd_pcm_substream *substream)
2125 struct alc_spec *spec = codec->spec;
2126 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2132 static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2133 struct hda_codec *codec,
2134 unsigned int stream_tag,
2135 unsigned int format,
2136 struct snd_pcm_substream *substream)
2138 struct alc_spec *spec = codec->spec;
2140 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
2141 stream_tag, 0, format);
2145 static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2146 struct hda_codec *codec,
2147 struct snd_pcm_substream *substream)
2149 struct alc_spec *spec = codec->spec;
2151 snd_hda_codec_cleanup_stream(codec,
2152 spec->adc_nids[substream->number + 1]);
2156 /* analog capture with dynamic dual-adc changes */
2157 static int dyn_adc_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)
2163 struct alc_spec *spec = codec->spec;
2164 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
2165 spec->cur_adc_stream_tag = stream_tag;
2166 spec->cur_adc_format = format;
2167 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2171 static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2172 struct hda_codec *codec,
2173 struct snd_pcm_substream *substream)
2175 struct alc_spec *spec = codec->spec;
2176 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2181 static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
2185 .nid = 0, /* fill later */
2187 .prepare = dyn_adc_capture_pcm_prepare,
2188 .cleanup = dyn_adc_capture_pcm_cleanup
2194 static const struct hda_pcm_stream alc_pcm_analog_playback = {
2198 /* NID is set in alc_build_pcms */
2200 .open = alc_playback_pcm_open,
2201 .prepare = alc_playback_pcm_prepare,
2202 .cleanup = alc_playback_pcm_cleanup
2206 static const struct hda_pcm_stream alc_pcm_analog_capture = {
2210 /* NID is set in alc_build_pcms */
2213 static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
2217 /* NID is set in alc_build_pcms */
2220 static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
2221 .substreams = 2, /* can be overridden */
2224 /* NID is set in alc_build_pcms */
2226 .prepare = alc_alt_capture_pcm_prepare,
2227 .cleanup = alc_alt_capture_pcm_cleanup
2231 static const struct hda_pcm_stream alc_pcm_digital_playback = {
2235 /* NID is set in alc_build_pcms */
2237 .open = alc_dig_playback_pcm_open,
2238 .close = alc_dig_playback_pcm_close,
2239 .prepare = alc_dig_playback_pcm_prepare,
2240 .cleanup = alc_dig_playback_pcm_cleanup
2244 static const struct hda_pcm_stream alc_pcm_digital_capture = {
2248 /* NID is set in alc_build_pcms */
2251 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
2252 static const struct hda_pcm_stream alc_pcm_null_stream = {
2258 static int alc_build_pcms(struct hda_codec *codec)
2260 struct alc_spec *spec = codec->spec;
2261 struct hda_pcm *info = spec->pcm_rec;
2262 const struct hda_pcm_stream *p;
2263 bool have_multi_adcs;
2266 codec->num_pcms = 1;
2267 codec->pcm_info = info;
2269 if (spec->no_analog)
2272 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2273 "%s Analog", codec->chip_name);
2274 info->name = spec->stream_name_analog;
2276 if (spec->multiout.num_dacs > 0) {
2277 p = spec->stream_analog_playback;
2279 p = &alc_pcm_analog_playback;
2280 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2281 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2282 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
2283 spec->multiout.max_channels;
2284 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
2285 spec->autocfg.line_outs == 2)
2286 info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap =
2289 if (spec->adc_nids) {
2290 p = spec->stream_analog_capture;
2292 if (spec->dyn_adc_switch)
2293 p = &dyn_adc_pcm_analog_capture;
2295 p = &alc_pcm_analog_capture;
2297 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2298 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2301 if (spec->channel_mode) {
2302 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2303 for (i = 0; i < spec->num_channel_mode; i++) {
2304 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2305 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2311 /* SPDIF for stream index #1 */
2312 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2313 snprintf(spec->stream_name_digital,
2314 sizeof(spec->stream_name_digital),
2315 "%s Digital", codec->chip_name);
2316 codec->num_pcms = 2;
2317 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
2318 info = spec->pcm_rec + 1;
2319 info->name = spec->stream_name_digital;
2320 if (spec->dig_out_type)
2321 info->pcm_type = spec->dig_out_type;
2323 info->pcm_type = HDA_PCM_TYPE_SPDIF;
2324 if (spec->multiout.dig_out_nid) {
2325 p = spec->stream_digital_playback;
2327 p = &alc_pcm_digital_playback;
2328 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2329 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2331 if (spec->dig_in_nid) {
2332 p = spec->stream_digital_capture;
2334 p = &alc_pcm_digital_capture;
2335 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2336 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2338 /* FIXME: do we need this for all Realtek codec models? */
2339 codec->spdif_status_reset = 1;
2342 if (spec->no_analog)
2345 /* If the use of more than one ADC is requested for the current
2346 * model, configure a second analog capture-only PCM.
2348 have_multi_adcs = (spec->num_adc_nids > 1) &&
2349 !spec->dyn_adc_switch && !spec->auto_mic &&
2350 (!spec->input_mux || spec->input_mux->num_items > 1);
2351 /* Additional Analaog capture for index #2 */
2352 if (spec->alt_dac_nid || have_multi_adcs) {
2353 codec->num_pcms = 3;
2354 info = spec->pcm_rec + 2;
2355 info->name = spec->stream_name_analog;
2356 if (spec->alt_dac_nid) {
2357 p = spec->stream_analog_alt_playback;
2359 p = &alc_pcm_analog_alt_playback;
2360 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2361 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2364 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2365 alc_pcm_null_stream;
2366 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2368 if (have_multi_adcs) {
2369 p = spec->stream_analog_alt_capture;
2371 p = &alc_pcm_analog_alt_capture;
2372 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2373 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2375 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2376 spec->num_adc_nids - 1;
2378 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2379 alc_pcm_null_stream;
2380 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
2387 static inline void alc_shutup(struct hda_codec *codec)
2389 struct alc_spec *spec = codec->spec;
2391 if (spec && spec->shutup)
2392 spec->shutup(codec);
2393 snd_hda_shutup_pins(codec);
2396 static void alc_free_kctls(struct hda_codec *codec)
2398 struct alc_spec *spec = codec->spec;
2400 if (spec->kctls.list) {
2401 struct snd_kcontrol_new *kctl = spec->kctls.list;
2403 for (i = 0; i < spec->kctls.used; i++)
2404 kfree(kctl[i].name);
2406 snd_array_free(&spec->kctls);
2409 static void alc_free_bind_ctls(struct hda_codec *codec)
2411 struct alc_spec *spec = codec->spec;
2412 if (spec->bind_ctls.list) {
2413 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2415 for (i = 0; i < spec->bind_ctls.used; i++)
2418 snd_array_free(&spec->bind_ctls);
2421 static void alc_free(struct hda_codec *codec)
2423 struct alc_spec *spec = codec->spec;
2428 alc_free_kctls(codec);
2429 alc_free_bind_ctls(codec);
2430 snd_array_free(&spec->out_path);
2431 snd_hda_gen_free(&spec->gen);
2433 snd_hda_detach_beep_device(codec);
2437 static void alc_power_eapd(struct hda_codec *codec)
2439 alc_auto_setup_eapd(codec, false);
2442 static int alc_suspend(struct hda_codec *codec)
2444 struct alc_spec *spec = codec->spec;
2446 if (spec && spec->power_hook)
2447 spec->power_hook(codec);
2453 static int alc_resume(struct hda_codec *codec)
2455 msleep(150); /* to avoid pop noise */
2456 codec->patch_ops.init(codec);
2457 snd_hda_codec_resume_amp(codec);
2458 snd_hda_codec_resume_cache(codec);
2459 alc_inv_dmic_sync(codec, true);
2460 hda_call_check_power_status(codec, 0x01);
2467 static const struct hda_codec_ops alc_patch_ops = {
2468 .build_controls = alc_build_controls,
2469 .build_pcms = alc_build_pcms,
2472 .unsol_event = snd_hda_jack_unsol_event,
2474 .resume = alc_resume,
2477 .suspend = alc_suspend,
2478 .check_power_status = alc_check_power_status,
2480 .reboot_notify = alc_shutup,
2484 /* replace the codec chip_name with the given string */
2485 static int alc_codec_rename(struct hda_codec *codec, const char *name)
2487 kfree(codec->chip_name);
2488 codec->chip_name = kstrdup(name, GFP_KERNEL);
2489 if (!codec->chip_name) {
2497 * Rename codecs appropriately from COEF value
2499 struct alc_codec_rename_table {
2500 unsigned int vendor_id;
2501 unsigned short coef_mask;
2502 unsigned short coef_bits;
2506 static struct alc_codec_rename_table rename_tbl[] = {
2507 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2508 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2509 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2510 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2511 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2512 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2513 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
2514 { 0x10ec0269, 0x00f0, 0x0030, "ALC269VD" },
2515 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2516 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2517 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2518 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2519 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2520 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2521 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2522 { } /* terminator */
2525 static int alc_codec_rename_from_preset(struct hda_codec *codec)
2527 const struct alc_codec_rename_table *p;
2529 for (p = rename_tbl; p->vendor_id; p++) {
2530 if (p->vendor_id != codec->vendor_id)
2532 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
2533 return alc_codec_rename(codec, p->name);
2539 * Automatic parse of I/O pins from the BIOS configuration
2544 ALC_CTL_WIDGET_MUTE,
2549 static const struct snd_kcontrol_new alc_control_templates[] = {
2550 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2551 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2552 HDA_BIND_MUTE(NULL, 0, 0, 0),
2553 HDA_BIND_VOL(NULL, 0),
2554 HDA_BIND_SW(NULL, 0),
2557 /* add dynamic controls */
2558 static int add_control(struct alc_spec *spec, int type, const char *name,
2559 int cidx, unsigned long val)
2561 struct snd_kcontrol_new *knew;
2563 knew = alc_kcontrol_new(spec, name, &alc_control_templates[type]);
2567 if (get_amp_nid_(val))
2568 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
2569 knew->private_value = val;
2573 static int add_control_with_pfx(struct alc_spec *spec, int type,
2574 const char *pfx, const char *dir,
2575 const char *sfx, int cidx, unsigned long val)
2578 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
2579 return add_control(spec, type, name, cidx, val);
2582 #define add_pb_vol_ctrl(spec, type, pfx, val) \
2583 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2584 #define add_pb_sw_ctrl(spec, type, pfx, val) \
2585 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2586 #define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2587 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2588 #define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2589 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
2591 static const char * const channel_name[4] = {
2592 "Front", "Surround", "CLFE", "Side"
2595 static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2596 bool can_be_master, int *index)
2598 struct auto_pin_cfg *cfg = &spec->autocfg;
2601 if (cfg->line_outs == 1 && !spec->multi_ios &&
2602 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
2605 switch (cfg->line_out_type) {
2606 case AUTO_PIN_SPEAKER_OUT:
2607 if (cfg->line_outs == 1)
2609 if (cfg->line_outs == 2)
2610 return ch ? "Bass Speaker" : "Speaker";
2612 case AUTO_PIN_HP_OUT:
2613 /* for multi-io case, only the primary out */
2614 if (ch && spec->multi_ios)
2619 if (cfg->line_outs == 1 && !spec->multi_ios)
2623 if (ch >= ARRAY_SIZE(channel_name)) {
2628 return channel_name[ch];
2632 /* add the powersave loopback-list entry */
2633 static void add_loopback_list(struct alc_spec *spec, hda_nid_t mix, int idx)
2635 struct hda_amp_list *list;
2637 if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
2639 list = spec->loopback_list + spec->num_loopbacks;
2641 list->dir = HDA_INPUT;
2643 spec->num_loopbacks++;
2644 spec->loopback.amplist = spec->loopback_list;
2647 #define add_loopback_list(spec, mix, idx) /* NOP */
2650 /* create input playback/capture controls for the given pin */
2651 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
2652 const char *ctlname, int ctlidx,
2653 int idx, hda_nid_t mix_nid)
2657 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
2658 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2661 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
2662 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2665 add_loopback_list(spec, mix_nid, idx);
2669 static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
2671 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2672 return (pincap & AC_PINCAP_IN) != 0;
2675 /* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
2676 static int alc_auto_fill_adc_caps(struct hda_codec *codec)
2678 struct alc_spec *spec = codec->spec;
2680 hda_nid_t *adc_nids = spec->private_adc_nids;
2681 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2682 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
2685 nid = codec->start_nid;
2686 for (i = 0; i < codec->num_nodes; i++, nid++) {
2688 unsigned int caps = get_wcaps(codec, nid);
2689 int type = get_wcaps_type(caps);
2691 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2693 adc_nids[nums] = nid;
2694 cap_nids[nums] = nid;
2698 type = get_wcaps_type(get_wcaps(codec, src));
2699 if (type == AC_WID_PIN)
2701 if (type == AC_WID_AUD_SEL) {
2702 cap_nids[nums] = src;
2705 n = snd_hda_get_num_conns(codec, src);
2707 cap_nids[nums] = src;
2711 if (snd_hda_get_connections(codec, src, &src, 1) != 1)
2714 if (++nums >= max_nums)
2717 spec->adc_nids = spec->private_adc_nids;
2718 spec->capsrc_nids = spec->private_capsrc_nids;
2719 spec->num_adc_nids = nums;
2723 /* create playback/capture controls for input pins */
2724 static int alc_auto_create_input_ctls(struct hda_codec *codec)
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];
2731 int i, c, err, idx, type_idx = 0;
2732 const char *prev_label = NULL;
2734 num_adcs = alc_auto_fill_adc_caps(codec);
2738 for (i = 0; i < cfg->num_inputs; i++) {
2742 pin = cfg->inputs[i].pin;
2743 if (!alc_is_input_pin(codec, pin))
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))
2756 idx = get_connection_index(codec, mixer, pin);
2758 err = new_analog_input(spec, pin,
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);
2770 spec->imux_pins[imux->num_items] = pin;
2771 snd_hda_add_imux_item(imux, label, idx, NULL);
2777 spec->num_mux_defs = 1;
2778 spec->input_mux = imux;
2783 /* create a shared input with the headphone out */
2784 static int alc_auto_create_shared_input(struct hda_codec *codec)
2786 struct alc_spec *spec = codec->spec;
2787 struct auto_pin_cfg *cfg = &spec->autocfg;
2788 unsigned int defcfg;
2791 /* only one internal input pin? */
2792 if (cfg->num_inputs != 1)
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)
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 */
2803 return 0; /* both not available */
2805 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2806 return 0; /* no input */
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);
2816 static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
2817 unsigned int pin_type)
2819 snd_hda_set_pin_ctl(codec, nid, pin_type);
2821 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2822 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2826 static int get_pin_type(int line_out_type)
2828 if (line_out_type == AUTO_PIN_HP_OUT)
2834 static void alc_auto_init_analog_input(struct hda_codec *codec)
2836 struct alc_spec *spec = codec->spec;
2837 struct auto_pin_cfg *cfg = &spec->autocfg;
2840 for (i = 0; i < cfg->num_inputs; i++) {
2841 hda_nid_t nid = cfg->inputs[i].pin;
2842 if (alc_is_input_pin(codec, nid)) {
2843 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
2844 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
2845 snd_hda_codec_write(codec, nid, 0,
2846 AC_VERB_SET_AMP_GAIN_MUTE,
2851 /* mute all loopback inputs */
2852 if (spec->mixer_nid) {
2853 int nums = snd_hda_get_num_conns(codec, spec->mixer_nid);
2854 for (i = 0; i < nums; i++)
2855 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2856 AC_VERB_SET_AMP_GAIN_MUTE,
2861 /* convert from MIX nid to DAC */
2862 static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid)
2867 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT)
2869 num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list));
2870 for (i = 0; i < num; i++) {
2871 if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT)
2877 /* go down to the selector widget before the mixer */
2878 static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin)
2881 int num = snd_hda_get_connections(codec, pin, srcs,
2884 get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL)
2889 /* get MIX nid connected to the given pin targeted to DAC */
2890 static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
2896 pin = alc_go_down_to_selector(codec, pin);
2897 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2898 for (i = 0; i < num; i++) {
2899 if (alc_auto_mix_to_dac(codec, mix[i]) == dac)
2905 /* select the connection from pin to DAC if needed */
2906 static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin,
2912 pin = alc_go_down_to_selector(codec, pin);
2913 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2916 for (i = 0; i < num; i++) {
2917 if (alc_auto_mix_to_dac(codec, mix[i]) == dac) {
2918 snd_hda_codec_update_cache(codec, pin, 0,
2919 AC_VERB_SET_CONNECT_SEL, i);
2926 static bool alc_is_dac_already_used(struct hda_codec *codec, hda_nid_t nid)
2928 struct alc_spec *spec = codec->spec;
2931 for (i = 0; i < spec->out_path.used; i++) {
2932 struct nid_path *path = snd_array_elem(&spec->out_path, i);
2933 if (path->path[0] == nid)
2939 /* check whether the DAC is reachable from the pin */
2940 static bool alc_auto_is_dac_reachable(struct hda_codec *codec,
2941 hda_nid_t pin, hda_nid_t dac)
2945 return snd_hda_get_conn_index(codec, pin, dac, true) >= 0;
2948 /* look for an empty DAC slot */
2949 static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
2951 struct alc_spec *spec = codec->spec;
2954 for (i = 0; i < spec->num_all_dacs; i++) {
2955 hda_nid_t nid = spec->all_dacs[i];
2956 if (!nid || alc_is_dac_already_used(codec, nid))
2958 if (alc_auto_is_dac_reachable(codec, pin, nid))
2964 /* called recursively */
2965 static bool __parse_output_path(struct hda_codec *codec, hda_nid_t nid,
2966 hda_nid_t target_dac, int with_aa_mix,
2967 struct nid_path *path, int depth)
2969 struct alc_spec *spec = codec->spec;
2973 if (nid == spec->mixer_nid) {
2976 with_aa_mix = 2; /* mark aa-mix is included */
2979 nums = snd_hda_get_connections(codec, nid, conn, ARRAY_SIZE(conn));
2980 for (i = 0; i < nums; i++) {
2981 if (get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT)
2983 if (conn[i] == target_dac ||
2984 (!target_dac && !alc_is_dac_already_used(codec, conn[i]))) {
2985 /* aa-mix is requested but not included? */
2986 if (!(spec->mixer_nid && with_aa_mix == 1))
2990 if (depth >= MAX_NID_PATH_DEPTH)
2992 for (i = 0; i < nums; i++) {
2994 type = get_wcaps_type(get_wcaps(codec, conn[i]));
2995 if (type == AC_WID_AUD_OUT)
2997 if (__parse_output_path(codec, conn[i], target_dac,
2998 with_aa_mix, path, depth + 1))
3004 path->path[path->depth] = conn[i];
3005 path->idx[path->depth] = i;
3006 if (nums > 1 && get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_MIX)
3007 path->multi[path->depth] = 1;
3012 /* parse the output path from the given nid to the target DAC;
3013 * when target_dac is 0, try to find an empty DAC;
3014 * when with_aa_mix is 0, paths with spec->mixer_nid are excluded
3016 static bool parse_output_path(struct hda_codec *codec, hda_nid_t nid,
3017 hda_nid_t target_dac, int with_aa_mix,
3018 struct nid_path *path)
3020 if (__parse_output_path(codec, nid, target_dac, with_aa_mix, path, 1)) {
3021 path->path[path->depth] = nid;
3024 snd_printdd("output-path: depth=%d, %02x/%02x/%02x/%02x/%02x\n",
3025 path->depth, path->path[0], path->path[1],
3026 path->path[2], path->path[3], path->path[4]);
3033 static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
3035 struct alc_spec *spec = codec->spec;
3037 hda_nid_t nid_found = 0;
3039 for (i = 0; i < spec->num_all_dacs; i++) {
3040 hda_nid_t nid = spec->all_dacs[i];
3041 if (!nid || alc_is_dac_already_used(codec, nid))
3043 if (alc_auto_is_dac_reachable(codec, pin, nid)) {
3052 /* mark up volume and mute control NIDs: used during badness parsing and
3053 * at creating actual controls
3055 static inline unsigned int get_ctl_pos(unsigned int data)
3057 hda_nid_t nid = get_amp_nid_(data);
3059 if (snd_BUG_ON(nid >= MAX_VOL_NIDS))
3061 dir = get_amp_direction_(data);
3062 return (nid << 1) | dir;
3065 #define is_ctl_used(bits, data) \
3066 test_bit(get_ctl_pos(data), bits)
3067 #define mark_ctl_usage(bits, data) \
3068 set_bit(get_ctl_pos(data), bits)
3070 static void clear_vol_marks(struct hda_codec *codec)
3072 struct alc_spec *spec = codec->spec;
3073 memset(spec->vol_ctls, 0, sizeof(spec->vol_ctls));
3074 memset(spec->sw_ctls, 0, sizeof(spec->sw_ctls));
3077 /* badness definition */
3079 /* No primary DAC is found for the main output */
3080 BAD_NO_PRIMARY_DAC = 0x10000,
3081 /* No DAC is found for the extra output */
3082 BAD_NO_DAC = 0x4000,
3083 /* No possible multi-ios */
3084 BAD_MULTI_IO = 0x103,
3085 /* No individual DAC for extra output */
3086 BAD_NO_EXTRA_DAC = 0x102,
3087 /* No individual DAC for extra surrounds */
3088 BAD_NO_EXTRA_SURR_DAC = 0x101,
3089 /* Primary DAC shared with main surrounds */
3090 BAD_SHARED_SURROUND = 0x100,
3091 /* Primary DAC shared with main CLFE */
3092 BAD_SHARED_CLFE = 0x10,
3093 /* Primary DAC shared with extra surrounds */
3094 BAD_SHARED_EXTRA_SURROUND = 0x10,
3095 /* Volume widget is shared */
3096 BAD_SHARED_VOL = 0x10,
3099 static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3100 hda_nid_t pin, hda_nid_t dac);
3101 static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3102 hda_nid_t pin, hda_nid_t dac);
3104 static bool add_new_out_path(struct hda_codec *codec, hda_nid_t pin,
3107 struct alc_spec *spec = codec->spec;
3108 struct nid_path *path;
3110 path = snd_array_new(&spec->out_path);
3113 memset(path, 0, sizeof(*path));
3114 if (parse_output_path(codec, pin, dac, 0, path))
3117 spec->out_path.used--;
3121 static int eval_shared_vol_badness(struct hda_codec *codec, hda_nid_t pin,
3124 struct alc_spec *spec = codec->spec;
3129 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3131 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3132 if (is_ctl_used(spec->vol_ctls, nid))
3133 badness += BAD_SHARED_VOL;
3135 mark_ctl_usage(spec->vol_ctls, val);
3137 badness += BAD_SHARED_VOL;
3138 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3140 unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid));
3141 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT)
3142 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3144 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
3145 if (is_ctl_used(spec->sw_ctls, val))
3146 badness += BAD_SHARED_VOL;
3148 mark_ctl_usage(spec->sw_ctls, val);
3150 badness += BAD_SHARED_VOL;
3154 struct badness_table {
3155 int no_primary_dac; /* no primary DAC */
3156 int no_dac; /* no secondary DACs */
3157 int shared_primary; /* primary DAC is shared with main output */
3158 int shared_surr; /* secondary DAC shared with main or primary */
3159 int shared_clfe; /* third DAC shared with main or primary */
3160 int shared_surr_main; /* secondary DAC sahred with main/DAC0 */
3163 static struct badness_table main_out_badness = {
3164 .no_primary_dac = BAD_NO_PRIMARY_DAC,
3165 .no_dac = BAD_NO_DAC,
3166 .shared_primary = BAD_NO_PRIMARY_DAC,
3167 .shared_surr = BAD_SHARED_SURROUND,
3168 .shared_clfe = BAD_SHARED_CLFE,
3169 .shared_surr_main = BAD_SHARED_SURROUND,
3172 static struct badness_table extra_out_badness = {
3173 .no_primary_dac = BAD_NO_DAC,
3174 .no_dac = BAD_NO_DAC,
3175 .shared_primary = BAD_NO_EXTRA_DAC,
3176 .shared_surr = BAD_SHARED_EXTRA_SURROUND,
3177 .shared_clfe = BAD_SHARED_EXTRA_SURROUND,
3178 .shared_surr_main = BAD_NO_EXTRA_SURR_DAC,
3181 /* try to assign DACs to pins and return the resultant badness */
3182 static int alc_auto_fill_dacs(struct hda_codec *codec, int num_outs,
3183 const hda_nid_t *pins, hda_nid_t *dacs,
3184 const struct badness_table *bad)
3186 struct alc_spec *spec = codec->spec;
3187 struct auto_pin_cfg *cfg = &spec->autocfg;
3195 for (i = 0; i < num_outs; i++) {
3196 hda_nid_t pin = pins[i];
3198 dacs[i] = alc_auto_look_for_dac(codec, pin);
3199 if (!dacs[i] && !i) {
3200 for (j = 1; j < num_outs; j++) {
3201 if (alc_auto_is_dac_reachable(codec, pin, dacs[j])) {
3210 if (alc_auto_is_dac_reachable(codec, pin, dacs[0]))
3212 else if (cfg->line_outs > i &&
3213 alc_auto_is_dac_reachable(codec, pin,
3214 spec->private_dac_nids[i]))
3215 dac = spec->private_dac_nids[i];
3218 badness += bad->shared_primary;
3220 badness += bad->shared_surr;
3222 badness += bad->shared_clfe;
3223 } else if (alc_auto_is_dac_reachable(codec, pin,
3224 spec->private_dac_nids[0])) {
3225 dac = spec->private_dac_nids[0];
3226 badness += bad->shared_surr_main;
3228 badness += bad->no_primary_dac;
3230 badness += bad->no_dac;
3232 if (!add_new_out_path(codec, pin, dac))
3235 badness += eval_shared_vol_badness(codec, pin, dac);
3241 static int alc_auto_fill_multi_ios(struct hda_codec *codec,
3242 hda_nid_t reference_pin,
3243 bool hardwired, int offset);
3245 static bool alc_map_singles(struct hda_codec *codec, int outs,
3246 const hda_nid_t *pins, hda_nid_t *dacs)
3250 for (i = 0; i < outs; i++) {
3254 dac = get_dac_if_single(codec, pins[i]);
3257 if (add_new_out_path(codec, pins[i], dac)) {
3265 /* fill in the dac_nids table from the parsed pin configuration */
3266 static int fill_and_eval_dacs(struct hda_codec *codec,
3267 bool fill_hardwired,
3268 bool fill_mio_first)
3270 struct alc_spec *spec = codec->spec;
3271 struct auto_pin_cfg *cfg = &spec->autocfg;
3272 int i, err, badness;
3274 /* set num_dacs once to full for alc_auto_look_for_dac() */
3275 spec->multiout.num_dacs = cfg->line_outs;
3276 spec->multiout.dac_nids = spec->private_dac_nids;
3277 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
3278 memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid));
3279 memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid));
3280 spec->multi_ios = 0;
3281 snd_array_free(&spec->out_path);
3282 clear_vol_marks(codec);
3285 /* fill hard-wired DACs first */
3286 if (fill_hardwired) {
3289 mapped = alc_map_singles(codec, cfg->line_outs,
3291 spec->private_dac_nids);
3292 mapped |= alc_map_singles(codec, cfg->hp_outs,
3294 spec->multiout.hp_out_nid);
3295 mapped |= alc_map_singles(codec, cfg->speaker_outs,
3297 spec->multiout.extra_out_nid);
3298 if (fill_mio_first && cfg->line_outs == 1 &&
3299 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3300 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], true, 0);
3307 badness += alc_auto_fill_dacs(codec, cfg->line_outs, cfg->line_out_pins,
3308 spec->private_dac_nids,
3311 /* re-count num_dacs and squash invalid entries */
3312 spec->multiout.num_dacs = 0;
3313 for (i = 0; i < cfg->line_outs; i++) {
3314 if (spec->private_dac_nids[i])
3315 spec->multiout.num_dacs++;
3317 memmove(spec->private_dac_nids + i,
3318 spec->private_dac_nids + i + 1,
3319 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
3320 spec->private_dac_nids[cfg->line_outs - 1] = 0;
3324 if (fill_mio_first &&
3325 cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3326 /* try to fill multi-io first */
3327 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
3330 /* we don't count badness at this stage yet */
3333 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
3334 err = alc_auto_fill_dacs(codec, cfg->hp_outs, cfg->hp_pins,
3335 spec->multiout.hp_out_nid,
3336 &extra_out_badness);
3341 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3342 err = alc_auto_fill_dacs(codec, cfg->speaker_outs,
3344 spec->multiout.extra_out_nid,
3345 &extra_out_badness);
3350 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3351 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
3356 if (cfg->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3357 /* try multi-ios with HP + inputs */
3359 if (cfg->line_outs >= 3)
3361 err = alc_auto_fill_multi_ios(codec, cfg->hp_pins[0], false,
3368 if (spec->multi_ios == 2) {
3369 for (i = 0; i < 2; i++)
3370 spec->private_dac_nids[spec->multiout.num_dacs++] =
3371 spec->multi_io[i].dac;
3372 spec->ext_channel_count = 2;
3373 } else if (spec->multi_ios) {
3374 spec->multi_ios = 0;
3375 badness += BAD_MULTI_IO;
3381 #define DEBUG_BADNESS
3383 #ifdef DEBUG_BADNESS
3384 #define debug_badness snd_printdd
3386 #define debug_badness(...)
3389 static void debug_show_configs(struct alc_spec *spec, struct auto_pin_cfg *cfg)
3391 debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3392 cfg->line_out_pins[0], cfg->line_out_pins[1],
3393 cfg->line_out_pins[2], cfg->line_out_pins[2],
3394 spec->multiout.dac_nids[0],
3395 spec->multiout.dac_nids[1],
3396 spec->multiout.dac_nids[2],
3397 spec->multiout.dac_nids[3]);
3398 if (spec->multi_ios > 0)
3399 debug_badness("multi_ios(%d) = %x/%x : %x/%x\n",
3401 spec->multi_io[0].pin, spec->multi_io[1].pin,
3402 spec->multi_io[0].dac, spec->multi_io[1].dac);
3403 debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3404 cfg->hp_pins[0], cfg->hp_pins[1],
3405 cfg->hp_pins[2], cfg->hp_pins[2],
3406 spec->multiout.hp_out_nid[0],
3407 spec->multiout.hp_out_nid[1],
3408 spec->multiout.hp_out_nid[2],
3409 spec->multiout.hp_out_nid[3]);
3410 debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3411 cfg->speaker_pins[0], cfg->speaker_pins[1],
3412 cfg->speaker_pins[2], cfg->speaker_pins[3],
3413 spec->multiout.extra_out_nid[0],
3414 spec->multiout.extra_out_nid[1],
3415 spec->multiout.extra_out_nid[2],
3416 spec->multiout.extra_out_nid[3]);
3419 /* find all available DACs of the codec */
3420 static void alc_fill_all_nids(struct hda_codec *codec)
3422 struct alc_spec *spec = codec->spec;
3424 hda_nid_t nid = codec->start_nid;
3426 spec->num_all_dacs = 0;
3427 memset(spec->all_dacs, 0, sizeof(spec->all_dacs));
3428 for (i = 0; i < codec->num_nodes; i++, nid++) {
3429 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_OUT)
3431 if (spec->num_all_dacs >= ARRAY_SIZE(spec->all_dacs)) {
3432 snd_printk(KERN_ERR "hda: Too many DACs!\n");
3435 spec->all_dacs[spec->num_all_dacs++] = nid;
3439 static int alc_auto_fill_dac_nids(struct hda_codec *codec)
3441 struct alc_spec *spec = codec->spec;
3442 struct auto_pin_cfg *cfg = &spec->autocfg;
3443 struct auto_pin_cfg *best_cfg;
3444 int best_badness = INT_MAX;
3446 bool fill_hardwired = true, fill_mio_first = true;
3447 bool best_wired = true, best_mio = true;
3448 bool hp_spk_swapped = false;
3450 alc_fill_all_nids(codec);
3452 best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL);
3458 badness = fill_and_eval_dacs(codec, fill_hardwired,
3464 debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n",
3465 cfg->line_out_type, fill_hardwired, fill_mio_first,
3467 debug_show_configs(spec, cfg);
3468 if (badness < best_badness) {
3469 best_badness = badness;
3471 best_wired = fill_hardwired;
3472 best_mio = fill_mio_first;
3476 fill_mio_first = !fill_mio_first;
3477 if (!fill_mio_first)
3479 fill_hardwired = !fill_hardwired;
3480 if (!fill_hardwired)
3484 hp_spk_swapped = true;
3485 if (cfg->speaker_outs > 0 &&
3486 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3487 cfg->hp_outs = cfg->line_outs;
3488 memcpy(cfg->hp_pins, cfg->line_out_pins,
3489 sizeof(cfg->hp_pins));
3490 cfg->line_outs = cfg->speaker_outs;
3491 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3492 sizeof(cfg->speaker_pins));
3493 cfg->speaker_outs = 0;
3494 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3495 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
3496 fill_hardwired = true;
3499 if (cfg->hp_outs > 0 &&
3500 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3501 cfg->speaker_outs = cfg->line_outs;
3502 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3503 sizeof(cfg->speaker_pins));
3504 cfg->line_outs = cfg->hp_outs;
3505 memcpy(cfg->line_out_pins, cfg->hp_pins,
3506 sizeof(cfg->hp_pins));
3508 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3509 cfg->line_out_type = AUTO_PIN_HP_OUT;
3510 fill_hardwired = true;
3518 fill_and_eval_dacs(codec, best_wired, best_mio);
3520 debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n",
3521 cfg->line_out_type, best_wired, best_mio);
3522 debug_show_configs(spec, cfg);
3524 if (cfg->line_out_pins[0])
3526 alc_look_for_out_vol_nid(codec, cfg->line_out_pins[0],
3527 spec->multiout.dac_nids[0]);
3529 /* clear the bitmap flags for creating controls */
3530 clear_vol_marks(codec);
3535 static int alc_auto_add_vol_ctl(struct hda_codec *codec,
3536 const char *pfx, int cidx,
3537 hda_nid_t nid, unsigned int chs)
3539 struct alc_spec *spec = codec->spec;
3543 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3544 if (is_ctl_used(spec->vol_ctls, val) && chs != 2) /* exclude LFE */
3546 mark_ctl_usage(spec->vol_ctls, val);
3547 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
3551 static int alc_auto_add_stereo_vol(struct hda_codec *codec,
3552 const char *pfx, int cidx,
3556 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3558 return alc_auto_add_vol_ctl(codec, pfx, cidx, nid, chs);
3561 /* create a mute-switch for the given mixer widget;
3562 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3564 static int alc_auto_add_sw_ctl(struct hda_codec *codec,
3565 const char *pfx, int cidx,
3566 hda_nid_t nid, unsigned int chs)
3568 struct alc_spec *spec = codec->spec;
3574 wid_type = get_wcaps_type(get_wcaps(codec, nid));
3575 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) {
3576 type = ALC_CTL_WIDGET_MUTE;
3577 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3578 } else if (snd_hda_get_num_conns(codec, nid) == 1) {
3579 type = ALC_CTL_WIDGET_MUTE;
3580 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
3582 type = ALC_CTL_BIND_MUTE;
3583 val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
3585 if (is_ctl_used(spec->sw_ctls, val) && chs != 2) /* exclude LFE */
3587 mark_ctl_usage(spec->sw_ctls, val);
3588 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
3591 static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
3592 int cidx, hda_nid_t nid)
3595 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3597 return alc_auto_add_sw_ctl(codec, pfx, cidx, nid, chs);
3600 static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3601 hda_nid_t pin, hda_nid_t dac)
3603 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3604 if (nid_has_mute(codec, pin, HDA_OUTPUT))
3606 else if (mix && nid_has_mute(codec, mix, HDA_INPUT))
3608 else if (nid_has_mute(codec, dac, HDA_OUTPUT))
3613 static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3614 hda_nid_t pin, hda_nid_t dac)
3616 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3617 if (nid_has_volume(codec, dac, HDA_OUTPUT))
3619 else if (nid_has_volume(codec, mix, HDA_OUTPUT))
3621 else if (nid_has_volume(codec, pin, HDA_OUTPUT))
3626 /* add playback controls from the parsed DAC table */
3627 static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
3628 const struct auto_pin_cfg *cfg)
3630 struct alc_spec *spec = codec->spec;
3631 int i, err, noutputs;
3633 noutputs = cfg->line_outs;
3634 if (spec->multi_ios > 0 && cfg->line_outs < 3)
3635 noutputs += spec->multi_ios;
3637 for (i = 0; i < noutputs; i++) {
3643 dac = spec->multiout.dac_nids[i];
3646 if (i >= cfg->line_outs) {
3647 pin = spec->multi_io[i - 1].pin;
3649 name = channel_name[i];
3651 pin = cfg->line_out_pins[i];
3652 name = alc_get_line_out_pfx(spec, i, true, &index);
3655 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3656 vol = alc_look_for_out_vol_nid(codec, pin, dac);
3657 if (!name || !strcmp(name, "CLFE")) {
3659 err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1);
3662 err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2);
3665 err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1);
3668 err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2);
3672 err = alc_auto_add_stereo_vol(codec, name, index, vol);
3675 err = alc_auto_add_stereo_sw(codec, name, index, sw);
3683 static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
3684 hda_nid_t dac, const char *pfx,
3687 struct alc_spec *spec = codec->spec;
3693 /* the corresponding DAC is already occupied */
3694 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
3695 return 0; /* no way */
3696 /* create a switch only */
3697 val = HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT);
3698 if (is_ctl_used(spec->sw_ctls, val))
3699 return 0; /* already created */
3700 mark_ctl_usage(spec->sw_ctls, val);
3701 return __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, cidx, val);
3704 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3705 vol = alc_look_for_out_vol_nid(codec, pin, dac);
3706 err = alc_auto_add_stereo_vol(codec, pfx, cidx, vol);
3709 err = alc_auto_add_stereo_sw(codec, pfx, cidx, sw);
3715 static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3717 struct hda_ctl_ops *ops)
3719 struct alc_spec *spec = codec->spec;
3720 struct hda_bind_ctls **ctlp, *ctl;
3721 ctlp = snd_array_new(&spec->bind_ctls);
3724 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3731 /* add playback controls for speaker and HP outputs */
3732 static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3733 const hda_nid_t *pins,
3734 const hda_nid_t *dacs,
3737 struct alc_spec *spec = codec->spec;
3738 struct hda_bind_ctls *ctl;
3742 if (!num_pins || !pins[0])
3745 if (num_pins == 1) {
3746 hda_nid_t dac = *dacs;
3748 dac = spec->multiout.dac_nids[0];
3749 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
3752 for (i = 0; i < num_pins; i++) {
3754 if (dacs[num_pins - 1])
3755 dac = dacs[i]; /* with individual volumes */
3758 if (num_pins == 2 && i == 1 && !strcmp(pfx, "Speaker")) {
3759 err = alc_auto_create_extra_out(codec, pins[i], dac,
3761 } else if (num_pins >= 3) {
3762 snprintf(name, sizeof(name), "%s %s",
3763 pfx, channel_name[i]);
3764 err = alc_auto_create_extra_out(codec, pins[i], dac,
3767 err = alc_auto_create_extra_out(codec, pins[i], dac,
3773 if (dacs[num_pins - 1])
3776 /* Let's create a bind-controls for volumes */
3777 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3781 for (i = 0; i < num_pins; i++) {
3783 if (!pins[i] || !dacs[i])
3785 vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]);
3788 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3791 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3792 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3799 static int alc_auto_create_hp_out(struct hda_codec *codec)
3801 struct alc_spec *spec = codec->spec;
3802 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3803 spec->autocfg.hp_pins,
3804 spec->multiout.hp_out_nid,
3808 static int alc_auto_create_speaker_out(struct hda_codec *codec)
3810 struct alc_spec *spec = codec->spec;
3811 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3812 spec->autocfg.speaker_pins,
3813 spec->multiout.extra_out_nid,
3817 static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
3818 hda_nid_t pin, int pin_type,
3822 hda_nid_t nid, mix = 0;
3823 hda_nid_t srcs[HDA_MAX_CONNECTIONS];
3825 alc_set_pin_output(codec, pin, pin_type);
3826 nid = alc_go_down_to_selector(codec, pin);
3827 num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
3828 for (i = 0; i < num; i++) {
3829 if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
3837 /* need the manual connection? */
3839 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
3840 /* unmute mixer widget inputs */
3841 if (nid_has_mute(codec, mix, HDA_INPUT)) {
3842 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3844 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3847 /* initialize volume */
3848 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3850 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3853 /* unmute DAC if it's not assigned to a mixer */
3854 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3855 if (nid == mix && nid_has_mute(codec, dac, HDA_OUTPUT))
3856 snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3860 static void alc_auto_init_multi_out(struct hda_codec *codec)
3862 struct alc_spec *spec = codec->spec;
3863 int pin_type = get_pin_type(spec->autocfg.line_out_type);
3866 for (i = 0; i <= HDA_SIDE; i++) {
3867 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3869 alc_auto_set_output_and_unmute(codec, nid, pin_type,
3870 spec->multiout.dac_nids[i]);
3874 static void alc_auto_init_extra_out(struct hda_codec *codec)
3876 struct alc_spec *spec = codec->spec;
3880 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3881 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3883 pin = spec->autocfg.hp_pins[i];
3886 dac = spec->multiout.hp_out_nid[i];
3888 if (i > 0 && spec->multiout.hp_out_nid[0])
3889 dac = spec->multiout.hp_out_nid[0];
3891 dac = spec->multiout.dac_nids[0];
3893 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
3895 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3896 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3898 pin = spec->autocfg.speaker_pins[i];
3901 dac = spec->multiout.extra_out_nid[i];
3903 if (i > 0 && spec->multiout.extra_out_nid[0])
3904 dac = spec->multiout.extra_out_nid[0];
3906 dac = spec->multiout.dac_nids[0];
3908 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
3912 /* check whether the given pin can be a multi-io pin */
3913 static bool can_be_multiio_pin(struct hda_codec *codec,
3914 unsigned int location, hda_nid_t nid)
3916 unsigned int defcfg, caps;
3918 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3919 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3921 if (location && get_defcfg_location(defcfg) != location)
3923 caps = snd_hda_query_pin_caps(codec, nid);
3924 if (!(caps & AC_PINCAP_OUT))
3932 * When hardwired is set, try to fill ony hardwired pins, and returns
3933 * zero if any pins are filled, non-zero if nothing found.
3934 * When hardwired is off, try to fill possible input pins, and returns
3935 * the badness value.
3937 static int alc_auto_fill_multi_ios(struct hda_codec *codec,
3938 hda_nid_t reference_pin,
3939 bool hardwired, int offset)
3941 struct alc_spec *spec = codec->spec;
3942 struct auto_pin_cfg *cfg = &spec->autocfg;
3943 int type, i, j, dacs, num_pins, old_pins;
3944 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
3945 unsigned int location = get_defcfg_location(defcfg);
3948 old_pins = spec->multi_ios;
3953 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3954 for (i = 0; i < cfg->num_inputs; i++) {
3955 if (cfg->inputs[i].type != type)
3957 if (can_be_multiio_pin(codec, location,
3958 cfg->inputs[i].pin))
3965 dacs = spec->multiout.num_dacs;
3966 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3967 for (i = 0; i < cfg->num_inputs; i++) {
3968 hda_nid_t nid = cfg->inputs[i].pin;
3971 if (cfg->inputs[i].type != type)
3973 if (!can_be_multiio_pin(codec, location, nid))
3975 for (j = 0; j < spec->multi_ios; j++) {
3976 if (nid == spec->multi_io[j].pin)
3979 if (j < spec->multi_ios)
3982 if (offset && offset + spec->multi_ios < dacs) {
3983 dac = spec->private_dac_nids[offset + spec->multi_ios];
3984 if (!alc_auto_is_dac_reachable(codec, nid, dac))
3988 dac = get_dac_if_single(codec, nid);
3990 dac = alc_auto_look_for_dac(codec, nid);
3995 if (!add_new_out_path(codec, nid, dac)) {
3999 spec->multi_io[spec->multi_ios].pin = nid;
4000 spec->multi_io[spec->multi_ios].dac = dac;
4002 if (spec->multi_ios >= 2)
4008 badness = BAD_MULTI_IO;
4009 if (old_pins == spec->multi_ios) {
4011 return 1; /* nothing found */
4013 return badness; /* no badness if nothing found */
4015 if (!hardwired && spec->multi_ios < 2) {
4016 /* cancel newly assigned paths */
4017 spec->out_path.used -= spec->multi_ios - old_pins;
4018 spec->multi_ios = old_pins;
4025 static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
4026 struct snd_ctl_elem_info *uinfo)
4028 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4029 struct alc_spec *spec = codec->spec;
4031 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
4033 uinfo->value.enumerated.items = spec->multi_ios + 1;
4034 if (uinfo->value.enumerated.item > spec->multi_ios)
4035 uinfo->value.enumerated.item = spec->multi_ios;
4036 sprintf(uinfo->value.enumerated.name, "%dch",
4037 (uinfo->value.enumerated.item + 1) * 2);
4041 static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
4042 struct snd_ctl_elem_value *ucontrol)
4044 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4045 struct alc_spec *spec = codec->spec;
4046 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
4050 static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
4052 struct alc_spec *spec = codec->spec;
4053 hda_nid_t nid = spec->multi_io[idx].pin;
4055 if (!spec->multi_io[idx].ctl_in)
4056 spec->multi_io[idx].ctl_in =
4057 snd_hda_codec_read(codec, nid, 0,
4058 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4060 snd_hda_set_pin_ctl_cache(codec, nid, PIN_OUT);
4061 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
4062 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
4064 alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
4066 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
4067 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
4068 HDA_AMP_MUTE, HDA_AMP_MUTE);
4069 snd_hda_set_pin_ctl_cache(codec, nid,
4070 spec->multi_io[idx].ctl_in);
4075 static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
4076 struct snd_ctl_elem_value *ucontrol)
4078 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4079 struct alc_spec *spec = codec->spec;
4082 ch = ucontrol->value.enumerated.item[0];
4083 if (ch < 0 || ch > spec->multi_ios)
4085 if (ch == (spec->ext_channel_count - 1) / 2)
4087 spec->ext_channel_count = (ch + 1) * 2;
4088 for (i = 0; i < spec->multi_ios; i++)
4089 alc_set_multi_io(codec, i, i < ch);
4090 spec->multiout.max_channels = max(spec->ext_channel_count,
4091 spec->const_channel_count);
4092 if (spec->need_dac_fix)
4093 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
4097 static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
4098 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4099 .name = "Channel Mode",
4100 .info = alc_auto_ch_mode_info,
4101 .get = alc_auto_ch_mode_get,
4102 .put = alc_auto_ch_mode_put,
4105 static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
4107 struct alc_spec *spec = codec->spec;
4109 if (spec->multi_ios > 0) {
4110 if (!alc_kcontrol_new(spec, "Channel Mode",
4111 &alc_auto_channel_mode_enum))
4117 /* filter out invalid adc_nids (and capsrc_nids) that don't give all
4120 static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
4122 struct alc_spec *spec = codec->spec;
4123 const struct hda_input_mux *imux;
4124 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4125 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4128 imux = spec->input_mux;
4131 if (spec->dyn_adc_switch)
4136 for (n = 0; n < spec->num_adc_nids; n++) {
4137 hda_nid_t cap = spec->private_capsrc_nids[n];
4138 int num_conns = snd_hda_get_num_conns(codec, cap);
4139 for (i = 0; i < imux->num_items; i++) {
4140 hda_nid_t pin = spec->imux_pins[i];
4142 if (get_connection_index(codec, cap, pin) < 0)
4144 } else if (num_conns <= imux->items[i].index)
4147 if (i >= imux->num_items) {
4148 adc_nids[nums] = spec->private_adc_nids[n];
4149 capsrc_nids[nums++] = cap;
4153 /* check whether ADC-switch is possible */
4154 if (!alc_check_dyn_adc_switch(codec)) {
4155 if (spec->shared_mic_hp) {
4156 spec->shared_mic_hp = 0;
4157 spec->private_imux[0].num_items = 1;
4160 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
4161 " using fallback 0x%x\n",
4162 codec->chip_name, spec->private_adc_nids[0]);
4163 spec->num_adc_nids = 1;
4167 } else if (nums != spec->num_adc_nids) {
4168 memcpy(spec->private_adc_nids, adc_nids,
4169 nums * sizeof(hda_nid_t));
4170 memcpy(spec->private_capsrc_nids, capsrc_nids,
4171 nums * sizeof(hda_nid_t));
4172 spec->num_adc_nids = nums;
4176 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
4177 else if (spec->input_mux->num_items == 1 || spec->shared_mic_hp)
4178 spec->num_adc_nids = 1; /* reduce to a single ADC */
4182 * initialize ADC paths
4184 static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
4186 struct alc_spec *spec = codec->spec;
4189 nid = spec->adc_nids[adc_idx];
4191 if (nid_has_mute(codec, nid, HDA_INPUT)) {
4192 snd_hda_codec_write(codec, nid, 0,
4193 AC_VERB_SET_AMP_GAIN_MUTE,
4197 if (!spec->capsrc_nids)
4199 nid = spec->capsrc_nids[adc_idx];
4200 if (nid_has_mute(codec, nid, HDA_OUTPUT))
4201 snd_hda_codec_write(codec, nid, 0,
4202 AC_VERB_SET_AMP_GAIN_MUTE,
4206 static void alc_auto_init_input_src(struct hda_codec *codec)
4208 struct alc_spec *spec = codec->spec;
4211 for (c = 0; c < spec->num_adc_nids; c++)
4212 alc_auto_init_adc(codec, c);
4213 if (spec->dyn_adc_switch)
4216 nums = spec->num_adc_nids;
4217 for (c = 0; c < nums; c++)
4218 alc_mux_select(codec, c, spec->cur_mux[c], true);
4221 /* add mic boosts if needed */
4222 static int alc_auto_add_mic_boost(struct hda_codec *codec)
4224 struct alc_spec *spec = codec->spec;
4225 struct auto_pin_cfg *cfg = &spec->autocfg;
4229 const char *prev_label = NULL;
4231 for (i = 0; i < cfg->num_inputs; i++) {
4232 if (cfg->inputs[i].type > AUTO_PIN_MIC)
4234 nid = cfg->inputs[i].pin;
4235 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
4237 char boost_label[32];
4239 label = hda_get_autocfg_input_label(codec, cfg, i);
4240 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
4241 label = "Headphone Mic";
4242 if (prev_label && !strcmp(label, prev_label))
4248 snprintf(boost_label, sizeof(boost_label),
4249 "%s Boost Volume", label);
4250 err = add_control(spec, ALC_CTL_WIDGET_VOL,
4251 boost_label, type_idx,
4252 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
4260 /* select or unmute the given capsrc route */
4261 static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
4264 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
4265 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
4267 } else if (snd_hda_get_num_conns(codec, cap) > 1) {
4268 snd_hda_codec_write_cache(codec, cap, 0,
4269 AC_VERB_SET_CONNECT_SEL, idx);
4273 /* set the default connection to that pin */
4274 static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
4276 struct alc_spec *spec = codec->spec;
4281 for (i = 0; i < spec->num_adc_nids; i++) {
4282 hda_nid_t cap = get_capsrc(spec, i);
4285 idx = get_connection_index(codec, cap, pin);
4288 select_or_unmute_capsrc(codec, cap, idx);
4289 return i; /* return the found index */
4291 return -1; /* not found */
4294 /* initialize some special cases for input sources */
4295 static void alc_init_special_input_src(struct hda_codec *codec)
4297 struct alc_spec *spec = codec->spec;
4300 for (i = 0; i < spec->autocfg.num_inputs; i++)
4301 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
4304 /* assign appropriate capture mixers */
4305 static void set_capture_mixer(struct hda_codec *codec)
4307 struct alc_spec *spec = codec->spec;
4308 static const struct snd_kcontrol_new *caps[2][3] = {
4309 { alc_capture_mixer_nosrc1,
4310 alc_capture_mixer_nosrc2,
4311 alc_capture_mixer_nosrc3 },
4312 { alc_capture_mixer1,
4314 alc_capture_mixer3 },
4317 /* check whether either of ADC or MUX has a volume control */
4318 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
4319 if (!spec->capsrc_nids)
4320 return; /* no volume */
4321 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
4322 return; /* no volume in capsrc, too */
4323 spec->vol_in_capsrc = 1;
4326 if (spec->num_adc_nids > 0) {
4330 if (spec->input_mux && spec->input_mux->num_items > 1)
4332 if (spec->auto_mic) {
4335 } else if (spec->dyn_adc_switch)
4338 if (spec->num_adc_nids > 3)
4339 spec->num_adc_nids = 3;
4340 else if (!spec->num_adc_nids)
4342 num_adcs = spec->num_adc_nids;
4344 spec->cap_mixer = caps[mux][num_adcs - 1];
4349 * standard auto-parser initializations
4351 static void alc_auto_init_std(struct hda_codec *codec)
4353 alc_auto_init_multi_out(codec);
4354 alc_auto_init_extra_out(codec);
4355 alc_auto_init_analog_input(codec);
4356 alc_auto_init_input_src(codec);
4357 alc_auto_init_digital(codec);
4358 alc_inithook(codec);
4362 * Digital-beep handlers
4364 #ifdef CONFIG_SND_HDA_INPUT_BEEP
4365 #define set_beep_amp(spec, nid, idx, dir) \
4366 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4368 static const struct snd_pci_quirk beep_white_list[] = {
4369 SND_PCI_QUIRK(0x1043, 0x103c, "ASUS", 1),
4370 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
4371 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
4372 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
4373 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
4374 SND_PCI_QUIRK(0x1458, 0xa002, "GA-MA790X", 1),
4375 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
4379 static inline int has_cdefine_beep(struct hda_codec *codec)
4381 struct alc_spec *spec = codec->spec;
4382 const struct snd_pci_quirk *q;
4383 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
4386 return spec->cdefine.enable_pcbeep;
4389 #define set_beep_amp(spec, nid, idx, dir) /* NOP */
4390 #define has_cdefine_beep(codec) 0
4393 /* parse the BIOS configuration and set up the alc_spec */
4394 /* return 1 if successful, 0 if the proper config is not found,
4395 * or a negative error code
4397 static int alc_parse_auto_config(struct hda_codec *codec,
4398 const hda_nid_t *ignore_nids,
4399 const hda_nid_t *ssid_nids)
4401 struct alc_spec *spec = codec->spec;
4402 struct auto_pin_cfg *cfg = &spec->autocfg;
4405 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
4409 if (!cfg->line_outs) {
4410 if (cfg->dig_outs || cfg->dig_in_pin) {
4411 spec->multiout.max_channels = 2;
4412 spec->no_analog = 1;
4415 return 0; /* can't find valid BIOS pin config */
4418 if (!spec->no_primary_hp &&
4419 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
4420 cfg->line_outs <= cfg->hp_outs) {
4421 /* use HP as primary out */
4422 cfg->speaker_outs = cfg->line_outs;
4423 memcpy(cfg->speaker_pins, cfg->line_out_pins,
4424 sizeof(cfg->speaker_pins));
4425 cfg->line_outs = cfg->hp_outs;
4426 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
4428 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
4429 cfg->line_out_type = AUTO_PIN_HP_OUT;
4432 err = alc_auto_fill_dac_nids(codec);
4435 err = alc_auto_add_multi_channel_mode(codec);
4438 err = alc_auto_create_multi_out_ctls(codec, cfg);
4441 err = alc_auto_create_hp_out(codec);
4444 err = alc_auto_create_speaker_out(codec);
4447 err = alc_auto_create_shared_input(codec);
4450 err = alc_auto_create_input_ctls(codec);
4454 /* check the multiple speaker pins */
4455 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
4456 spec->const_channel_count = cfg->line_outs * 2;
4458 spec->const_channel_count = cfg->speaker_outs * 2;
4460 if (spec->multi_ios > 0)
4461 spec->multiout.max_channels = max(spec->ext_channel_count,
4462 spec->const_channel_count);
4464 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4467 alc_auto_parse_digital(codec);
4469 if (!spec->no_analog)
4470 alc_remove_invalid_adc_nids(codec);
4473 alc_ssid_check(codec, ssid_nids);
4475 if (!spec->no_analog) {
4476 err = alc_auto_check_switches(codec);
4479 err = alc_auto_add_mic_boost(codec);
4484 if (spec->kctls.list)
4485 add_mixer(spec, spec->kctls.list);
4487 if (!spec->no_analog && !spec->cap_mixer)
4488 set_capture_mixer(codec);
4493 /* common preparation job for alc_spec */
4494 static int alc_alloc_spec(struct hda_codec *codec, hda_nid_t mixer_nid)
4496 struct alc_spec *spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4502 codec->single_adc_amp = 1;
4503 spec->mixer_nid = mixer_nid;
4504 snd_hda_gen_init(&spec->gen);
4505 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
4506 snd_array_init(&spec->bind_ctls, sizeof(struct hda_bind_ctls *), 8);
4507 snd_array_init(&spec->out_path, sizeof(struct nid_path), 8);
4509 err = alc_codec_rename_from_preset(codec);
4517 static int alc880_parse_auto_config(struct hda_codec *codec)
4519 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
4520 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4521 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
4530 ALC880_FIXUP_MEDION_RIM,
4533 ALC880_FIXUP_EAPD_COEF,
4534 ALC880_FIXUP_TCL_S700,
4535 ALC880_FIXUP_VOL_KNOB,
4536 ALC880_FIXUP_FUJITSU,
4538 ALC880_FIXUP_UNIWILL,
4539 ALC880_FIXUP_UNIWILL_DIG,
4541 ALC880_FIXUP_3ST_BASE,
4543 ALC880_FIXUP_3ST_DIG,
4544 ALC880_FIXUP_5ST_BASE,
4546 ALC880_FIXUP_5ST_DIG,
4547 ALC880_FIXUP_6ST_BASE,
4549 ALC880_FIXUP_6ST_DIG,
4552 /* enable the volume-knob widget support on NID 0x21 */
4553 static void alc880_fixup_vol_knob(struct hda_codec *codec,
4554 const struct alc_fixup *fix, int action)
4556 if (action == ALC_FIXUP_ACT_PROBE)
4557 snd_hda_jack_detect_enable_callback(codec, 0x21, ALC_DCVOL_EVENT, alc_update_knob_master);
4560 static const struct alc_fixup alc880_fixups[] = {
4561 [ALC880_FIXUP_GPIO1] = {
4562 .type = ALC_FIXUP_VERBS,
4563 .v.verbs = alc_gpio1_init_verbs,
4565 [ALC880_FIXUP_GPIO2] = {
4566 .type = ALC_FIXUP_VERBS,
4567 .v.verbs = alc_gpio2_init_verbs,
4569 [ALC880_FIXUP_MEDION_RIM] = {
4570 .type = ALC_FIXUP_VERBS,
4571 .v.verbs = (const struct hda_verb[]) {
4572 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4573 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4577 .chain_id = ALC880_FIXUP_GPIO2,
4579 [ALC880_FIXUP_LG] = {
4580 .type = ALC_FIXUP_PINS,
4581 .v.pins = (const struct alc_pincfg[]) {
4582 /* disable bogus unused pins */
4583 { 0x16, 0x411111f0 },
4584 { 0x18, 0x411111f0 },
4585 { 0x1a, 0x411111f0 },
4589 [ALC880_FIXUP_W810] = {
4590 .type = ALC_FIXUP_PINS,
4591 .v.pins = (const struct alc_pincfg[]) {
4592 /* disable bogus unused pins */
4593 { 0x17, 0x411111f0 },
4597 .chain_id = ALC880_FIXUP_GPIO2,
4599 [ALC880_FIXUP_EAPD_COEF] = {
4600 .type = ALC_FIXUP_VERBS,
4601 .v.verbs = (const struct hda_verb[]) {
4602 /* change to EAPD mode */
4603 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4604 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4608 [ALC880_FIXUP_TCL_S700] = {
4609 .type = ALC_FIXUP_VERBS,
4610 .v.verbs = (const struct hda_verb[]) {
4611 /* change to EAPD mode */
4612 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4613 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4617 .chain_id = ALC880_FIXUP_GPIO2,
4619 [ALC880_FIXUP_VOL_KNOB] = {
4620 .type = ALC_FIXUP_FUNC,
4621 .v.func = alc880_fixup_vol_knob,
4623 [ALC880_FIXUP_FUJITSU] = {
4624 /* override all pins as BIOS on old Amilo is broken */
4625 .type = ALC_FIXUP_PINS,
4626 .v.pins = (const struct alc_pincfg[]) {
4627 { 0x14, 0x0121411f }, /* HP */
4628 { 0x15, 0x99030120 }, /* speaker */
4629 { 0x16, 0x99030130 }, /* bass speaker */
4630 { 0x17, 0x411111f0 }, /* N/A */
4631 { 0x18, 0x411111f0 }, /* N/A */
4632 { 0x19, 0x01a19950 }, /* mic-in */
4633 { 0x1a, 0x411111f0 }, /* N/A */
4634 { 0x1b, 0x411111f0 }, /* N/A */
4635 { 0x1c, 0x411111f0 }, /* N/A */
4636 { 0x1d, 0x411111f0 }, /* N/A */
4637 { 0x1e, 0x01454140 }, /* SPDIF out */
4641 .chain_id = ALC880_FIXUP_VOL_KNOB,
4643 [ALC880_FIXUP_F1734] = {
4644 /* almost compatible with FUJITSU, but no bass and SPDIF */
4645 .type = ALC_FIXUP_PINS,
4646 .v.pins = (const struct alc_pincfg[]) {
4647 { 0x14, 0x0121411f }, /* HP */
4648 { 0x15, 0x99030120 }, /* speaker */
4649 { 0x16, 0x411111f0 }, /* N/A */
4650 { 0x17, 0x411111f0 }, /* N/A */
4651 { 0x18, 0x411111f0 }, /* N/A */
4652 { 0x19, 0x01a19950 }, /* mic-in */
4653 { 0x1a, 0x411111f0 }, /* N/A */
4654 { 0x1b, 0x411111f0 }, /* N/A */
4655 { 0x1c, 0x411111f0 }, /* N/A */
4656 { 0x1d, 0x411111f0 }, /* N/A */
4657 { 0x1e, 0x411111f0 }, /* N/A */
4661 .chain_id = ALC880_FIXUP_VOL_KNOB,
4663 [ALC880_FIXUP_UNIWILL] = {
4664 /* need to fix HP and speaker pins to be parsed correctly */
4665 .type = ALC_FIXUP_PINS,
4666 .v.pins = (const struct alc_pincfg[]) {
4667 { 0x14, 0x0121411f }, /* HP */
4668 { 0x15, 0x99030120 }, /* speaker */
4669 { 0x16, 0x99030130 }, /* bass speaker */
4673 [ALC880_FIXUP_UNIWILL_DIG] = {
4674 .type = ALC_FIXUP_PINS,
4675 .v.pins = (const struct alc_pincfg[]) {
4676 /* disable bogus unused pins */
4677 { 0x17, 0x411111f0 },
4678 { 0x19, 0x411111f0 },
4679 { 0x1b, 0x411111f0 },
4680 { 0x1f, 0x411111f0 },
4684 [ALC880_FIXUP_Z71V] = {
4685 .type = ALC_FIXUP_PINS,
4686 .v.pins = (const struct alc_pincfg[]) {
4687 /* set up the whole pins as BIOS is utterly broken */
4688 { 0x14, 0x99030120 }, /* speaker */
4689 { 0x15, 0x0121411f }, /* HP */
4690 { 0x16, 0x411111f0 }, /* N/A */
4691 { 0x17, 0x411111f0 }, /* N/A */
4692 { 0x18, 0x01a19950 }, /* mic-in */
4693 { 0x19, 0x411111f0 }, /* N/A */
4694 { 0x1a, 0x01813031 }, /* line-in */
4695 { 0x1b, 0x411111f0 }, /* N/A */
4696 { 0x1c, 0x411111f0 }, /* N/A */
4697 { 0x1d, 0x411111f0 }, /* N/A */
4698 { 0x1e, 0x0144111e }, /* SPDIF */
4702 [ALC880_FIXUP_3ST_BASE] = {
4703 .type = ALC_FIXUP_PINS,
4704 .v.pins = (const struct alc_pincfg[]) {
4705 { 0x14, 0x01014010 }, /* line-out */
4706 { 0x15, 0x411111f0 }, /* N/A */
4707 { 0x16, 0x411111f0 }, /* N/A */
4708 { 0x17, 0x411111f0 }, /* N/A */
4709 { 0x18, 0x01a19c30 }, /* mic-in */
4710 { 0x19, 0x0121411f }, /* HP */
4711 { 0x1a, 0x01813031 }, /* line-in */
4712 { 0x1b, 0x02a19c40 }, /* front-mic */
4713 { 0x1c, 0x411111f0 }, /* N/A */
4714 { 0x1d, 0x411111f0 }, /* N/A */
4715 /* 0x1e is filled in below */
4716 { 0x1f, 0x411111f0 }, /* N/A */
4720 [ALC880_FIXUP_3ST] = {
4721 .type = ALC_FIXUP_PINS,
4722 .v.pins = (const struct alc_pincfg[]) {
4723 { 0x1e, 0x411111f0 }, /* N/A */
4727 .chain_id = ALC880_FIXUP_3ST_BASE,
4729 [ALC880_FIXUP_3ST_DIG] = {
4730 .type = ALC_FIXUP_PINS,
4731 .v.pins = (const struct alc_pincfg[]) {
4732 { 0x1e, 0x0144111e }, /* SPDIF */
4736 .chain_id = ALC880_FIXUP_3ST_BASE,
4738 [ALC880_FIXUP_5ST_BASE] = {
4739 .type = ALC_FIXUP_PINS,
4740 .v.pins = (const struct alc_pincfg[]) {
4741 { 0x14, 0x01014010 }, /* front */
4742 { 0x15, 0x411111f0 }, /* N/A */
4743 { 0x16, 0x01011411 }, /* CLFE */
4744 { 0x17, 0x01016412 }, /* surr */
4745 { 0x18, 0x01a19c30 }, /* mic-in */
4746 { 0x19, 0x0121411f }, /* HP */
4747 { 0x1a, 0x01813031 }, /* line-in */
4748 { 0x1b, 0x02a19c40 }, /* front-mic */
4749 { 0x1c, 0x411111f0 }, /* N/A */
4750 { 0x1d, 0x411111f0 }, /* N/A */
4751 /* 0x1e is filled in below */
4752 { 0x1f, 0x411111f0 }, /* N/A */
4756 [ALC880_FIXUP_5ST] = {
4757 .type = ALC_FIXUP_PINS,
4758 .v.pins = (const struct alc_pincfg[]) {
4759 { 0x1e, 0x411111f0 }, /* N/A */
4763 .chain_id = ALC880_FIXUP_5ST_BASE,
4765 [ALC880_FIXUP_5ST_DIG] = {
4766 .type = ALC_FIXUP_PINS,
4767 .v.pins = (const struct alc_pincfg[]) {
4768 { 0x1e, 0x0144111e }, /* SPDIF */
4772 .chain_id = ALC880_FIXUP_5ST_BASE,
4774 [ALC880_FIXUP_6ST_BASE] = {
4775 .type = ALC_FIXUP_PINS,
4776 .v.pins = (const struct alc_pincfg[]) {
4777 { 0x14, 0x01014010 }, /* front */
4778 { 0x15, 0x01016412 }, /* surr */
4779 { 0x16, 0x01011411 }, /* CLFE */
4780 { 0x17, 0x01012414 }, /* side */
4781 { 0x18, 0x01a19c30 }, /* mic-in */
4782 { 0x19, 0x02a19c40 }, /* front-mic */
4783 { 0x1a, 0x01813031 }, /* line-in */
4784 { 0x1b, 0x0121411f }, /* HP */
4785 { 0x1c, 0x411111f0 }, /* N/A */
4786 { 0x1d, 0x411111f0 }, /* N/A */
4787 /* 0x1e is filled in below */
4788 { 0x1f, 0x411111f0 }, /* N/A */
4792 [ALC880_FIXUP_6ST] = {
4793 .type = ALC_FIXUP_PINS,
4794 .v.pins = (const struct alc_pincfg[]) {
4795 { 0x1e, 0x411111f0 }, /* N/A */
4799 .chain_id = ALC880_FIXUP_6ST_BASE,
4801 [ALC880_FIXUP_6ST_DIG] = {
4802 .type = ALC_FIXUP_PINS,
4803 .v.pins = (const struct alc_pincfg[]) {
4804 { 0x1e, 0x0144111e }, /* SPDIF */
4808 .chain_id = ALC880_FIXUP_6ST_BASE,
4812 static const struct snd_pci_quirk alc880_fixup_tbl[] = {
4813 SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_FIXUP_W810),
4814 SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_FIXUP_Z71V),
4815 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_FIXUP_GPIO1),
4816 SND_PCI_QUIRK(0x1558, 0x5401, "Clevo GPIO2", ALC880_FIXUP_GPIO2),
4817 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo", ALC880_FIXUP_EAPD_COEF),
4818 SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_FIXUP_UNIWILL_DIG),
4819 SND_PCI_QUIRK(0x1584, 0x9054, "Uniwill", ALC880_FIXUP_F1734),
4820 SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_FIXUP_UNIWILL),
4821 SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_FIXUP_VOL_KNOB),
4822 SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_FIXUP_W810),
4823 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
4824 SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_FIXUP_F1734),
4825 SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FIXUP_FUJITSU),
4826 SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_FIXUP_F1734),
4827 SND_PCI_QUIRK(0x1734, 0x10b0, "FSC Amilo Pi1556", ALC880_FIXUP_FUJITSU),
4828 SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_FIXUP_LG),
4829 SND_PCI_QUIRK(0x1854, 0x005f, "LG P1 Express", ALC880_FIXUP_LG),
4830 SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_FIXUP_LG),
4831 SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_FIXUP_TCL_S700),
4833 /* Below is the copied entries from alc880_quirks.c.
4834 * It's not quite sure whether BIOS sets the correct pin-config table
4835 * on these machines, thus they are kept to be compatible with
4836 * the old static quirks. Once when it's confirmed to work without
4837 * these overrides, it'd be better to remove.
4839 SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_FIXUP_5ST_DIG),
4840 SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_FIXUP_6ST),
4841 SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_FIXUP_3ST_DIG),
4842 SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_FIXUP_6ST_DIG),
4843 SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_FIXUP_6ST_DIG),
4844 SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_FIXUP_6ST_DIG),
4845 SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_FIXUP_3ST_DIG),
4846 SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_FIXUP_3ST),
4847 SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_FIXUP_6ST_DIG),
4848 SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_FIXUP_3ST),
4849 SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_FIXUP_3ST),
4850 SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_FIXUP_5ST),
4851 SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_FIXUP_5ST),
4852 SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_FIXUP_5ST),
4853 SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_FIXUP_6ST_DIG),
4854 SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_FIXUP_6ST_DIG),
4855 SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_FIXUP_6ST_DIG),
4856 SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_FIXUP_6ST_DIG),
4857 SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_FIXUP_5ST_DIG),
4858 SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_FIXUP_5ST_DIG),
4859 SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_FIXUP_5ST_DIG),
4860 SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_FIXUP_6ST_DIG), /* broken BIOS */
4861 SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_FIXUP_6ST_DIG),
4862 SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4863 SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4864 SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4865 SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4866 SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4867 SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4868 SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4869 SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4870 SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4871 SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4873 SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_FIXUP_3ST),
4874 SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_FIXUP_5ST_DIG),
4875 SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_FIXUP_6ST_DIG),
4879 static const struct alc_model_fixup alc880_fixup_models[] = {
4880 {.id = ALC880_FIXUP_3ST, .name = "3stack"},
4881 {.id = ALC880_FIXUP_3ST_DIG, .name = "3stack-digout"},
4882 {.id = ALC880_FIXUP_5ST, .name = "5stack"},
4883 {.id = ALC880_FIXUP_5ST_DIG, .name = "5stack-digout"},
4884 {.id = ALC880_FIXUP_6ST, .name = "6stack"},
4885 {.id = ALC880_FIXUP_6ST_DIG, .name = "6stack-digout"},
4891 * OK, here we have finally the patch for ALC880
4893 static int patch_alc880(struct hda_codec *codec)
4895 struct alc_spec *spec;
4898 err = alc_alloc_spec(codec, 0x0b);
4903 spec->need_dac_fix = 1;
4905 alc_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl,
4907 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4909 /* automatic parse from the BIOS config */
4910 err = alc880_parse_auto_config(codec);
4914 if (!spec->no_analog) {
4915 err = snd_hda_attach_beep_device(codec, 0x1);
4918 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4921 codec->patch_ops = alc_patch_ops;
4922 codec->patch_ops.unsol_event = alc880_unsol_event;
4925 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4938 static int alc260_parse_auto_config(struct hda_codec *codec)
4940 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
4941 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
4942 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
4949 ALC260_FIXUP_HP_DC5750,
4950 ALC260_FIXUP_HP_PIN_0F,
4953 ALC260_FIXUP_GPIO1_TOGGLE,
4954 ALC260_FIXUP_REPLACER,
4955 ALC260_FIXUP_HP_B1900,
4959 static void alc260_gpio1_automute(struct hda_codec *codec)
4961 struct alc_spec *spec = codec->spec;
4962 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
4963 spec->hp_jack_present);
4966 static void alc260_fixup_gpio1_toggle(struct hda_codec *codec,
4967 const struct alc_fixup *fix, int action)
4969 struct alc_spec *spec = codec->spec;
4970 if (action == ALC_FIXUP_ACT_PROBE) {
4971 /* although the machine has only one output pin, we need to
4972 * toggle GPIO1 according to the jack state
4974 spec->automute_hook = alc260_gpio1_automute;
4975 spec->detect_hp = 1;
4976 spec->automute_speaker = 1;
4977 spec->autocfg.hp_pins[0] = 0x0f; /* copy it for automute */
4978 snd_hda_jack_detect_enable_callback(codec, 0x0f, ALC_HP_EVENT,
4980 snd_hda_gen_add_verbs(&spec->gen, alc_gpio1_init_verbs);
4984 static void alc260_fixup_kn1(struct hda_codec *codec,
4985 const struct alc_fixup *fix, int action)
4987 struct alc_spec *spec = codec->spec;
4988 static const struct alc_pincfg pincfgs[] = {
4989 { 0x0f, 0x02214000 }, /* HP/speaker */
4990 { 0x12, 0x90a60160 }, /* int mic */
4991 { 0x13, 0x02a19000 }, /* ext mic */
4992 { 0x18, 0x01446000 }, /* SPDIF out */
4993 /* disable bogus I/O pins */
4994 { 0x10, 0x411111f0 },
4995 { 0x11, 0x411111f0 },
4996 { 0x14, 0x411111f0 },
4997 { 0x15, 0x411111f0 },
4998 { 0x16, 0x411111f0 },
4999 { 0x17, 0x411111f0 },
5000 { 0x19, 0x411111f0 },
5005 case ALC_FIXUP_ACT_PRE_PROBE:
5006 alc_apply_pincfgs(codec, pincfgs);
5008 case ALC_FIXUP_ACT_PROBE:
5009 spec->init_amp = ALC_INIT_NONE;
5014 static const struct alc_fixup alc260_fixups[] = {
5015 [ALC260_FIXUP_HP_DC5750] = {
5016 .type = ALC_FIXUP_PINS,
5017 .v.pins = (const struct alc_pincfg[]) {
5018 { 0x11, 0x90130110 }, /* speaker */
5022 [ALC260_FIXUP_HP_PIN_0F] = {
5023 .type = ALC_FIXUP_PINS,
5024 .v.pins = (const struct alc_pincfg[]) {
5025 { 0x0f, 0x01214000 }, /* HP */
5029 [ALC260_FIXUP_COEF] = {
5030 .type = ALC_FIXUP_VERBS,
5031 .v.verbs = (const struct hda_verb[]) {
5032 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5033 { 0x20, AC_VERB_SET_PROC_COEF, 0x3040 },
5037 .chain_id = ALC260_FIXUP_HP_PIN_0F,
5039 [ALC260_FIXUP_GPIO1] = {
5040 .type = ALC_FIXUP_VERBS,
5041 .v.verbs = alc_gpio1_init_verbs,
5043 [ALC260_FIXUP_GPIO1_TOGGLE] = {
5044 .type = ALC_FIXUP_FUNC,
5045 .v.func = alc260_fixup_gpio1_toggle,
5047 .chain_id = ALC260_FIXUP_HP_PIN_0F,
5049 [ALC260_FIXUP_REPLACER] = {
5050 .type = ALC_FIXUP_VERBS,
5051 .v.verbs = (const struct hda_verb[]) {
5052 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5053 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5057 .chain_id = ALC260_FIXUP_GPIO1_TOGGLE,
5059 [ALC260_FIXUP_HP_B1900] = {
5060 .type = ALC_FIXUP_FUNC,
5061 .v.func = alc260_fixup_gpio1_toggle,
5063 .chain_id = ALC260_FIXUP_COEF,
5065 [ALC260_FIXUP_KN1] = {
5066 .type = ALC_FIXUP_FUNC,
5067 .v.func = alc260_fixup_kn1,
5071 static const struct snd_pci_quirk alc260_fixup_tbl[] = {
5072 SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_FIXUP_GPIO1),
5073 SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF),
5074 SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1),
5075 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750),
5076 SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900),
5077 SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1),
5078 SND_PCI_QUIRK(0x152d, 0x0729, "Quanta KN1", ALC260_FIXUP_KN1),
5079 SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER),
5080 SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_FIXUP_COEF),
5086 static int patch_alc260(struct hda_codec *codec)
5088 struct alc_spec *spec;
5091 err = alc_alloc_spec(codec, 0x07);
5097 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
5098 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5100 /* automatic parse from the BIOS config */
5101 err = alc260_parse_auto_config(codec);
5105 if (!spec->no_analog) {
5106 err = snd_hda_attach_beep_device(codec, 0x1);
5109 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
5112 codec->patch_ops = alc_patch_ops;
5113 spec->shutup = alc_eapd_shutup;
5115 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5126 * ALC882/883/885/888/889 support
5128 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
5129 * configuration. Each pin widget can choose any input DACs and a mixer.
5130 * Each ADC is connected from a mixer of all inputs. This makes possible
5131 * 6-channel independent captures.
5133 * In addition, an independent DAC for the multi-playback (not used in this
5141 ALC882_FIXUP_ABIT_AW9D_MAX,
5142 ALC882_FIXUP_LENOVO_Y530,
5143 ALC882_FIXUP_PB_M5210,
5144 ALC882_FIXUP_ACER_ASPIRE_7736,
5145 ALC882_FIXUP_ASUS_W90V,
5147 ALC889_FIXUP_VAIO_TT,
5148 ALC888_FIXUP_EEE1601,
5151 ALC883_FIXUP_ACER_EAPD,
5156 ALC882_FIXUP_ASUS_W2JC,
5157 ALC882_FIXUP_ACER_ASPIRE_4930G,
5158 ALC882_FIXUP_ACER_ASPIRE_8930G,
5159 ALC882_FIXUP_ASPIRE_8930G_VERBS,
5160 ALC885_FIXUP_MACPRO_GPIO,
5161 ALC889_FIXUP_DAC_ROUTE,
5162 ALC889_FIXUP_MBP_VREF,
5163 ALC889_FIXUP_IMAC91_VREF,
5164 ALC882_FIXUP_INV_DMIC,
5165 ALC882_FIXUP_NO_PRIMARY_HP,
5168 static void alc889_fixup_coef(struct hda_codec *codec,
5169 const struct alc_fixup *fix, int action)
5171 if (action != ALC_FIXUP_ACT_INIT)
5173 alc889_coef_init(codec);
5176 /* toggle speaker-output according to the hp-jack state */
5177 static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
5179 unsigned int gpiostate, gpiomask, gpiodir;
5181 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
5182 AC_VERB_GET_GPIO_DATA, 0);
5185 gpiostate |= (1 << pin);
5187 gpiostate &= ~(1 << pin);
5189 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
5190 AC_VERB_GET_GPIO_MASK, 0);
5191 gpiomask |= (1 << pin);
5193 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
5194 AC_VERB_GET_GPIO_DIRECTION, 0);
5195 gpiodir |= (1 << pin);
5198 snd_hda_codec_write(codec, codec->afg, 0,
5199 AC_VERB_SET_GPIO_MASK, gpiomask);
5200 snd_hda_codec_write(codec, codec->afg, 0,
5201 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
5205 snd_hda_codec_write(codec, codec->afg, 0,
5206 AC_VERB_SET_GPIO_DATA, gpiostate);
5209 /* set up GPIO at initialization */
5210 static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
5211 const struct alc_fixup *fix, int action)
5213 if (action != ALC_FIXUP_ACT_INIT)
5215 alc882_gpio_mute(codec, 0, 0);
5216 alc882_gpio_mute(codec, 1, 0);
5219 /* Fix the connection of some pins for ALC889:
5220 * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
5221 * work correctly (bko#42740)
5223 static void alc889_fixup_dac_route(struct hda_codec *codec,
5224 const struct alc_fixup *fix, int action)
5226 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
5227 /* fake the connections during parsing the tree */
5228 hda_nid_t conn1[2] = { 0x0c, 0x0d };
5229 hda_nid_t conn2[2] = { 0x0e, 0x0f };
5230 snd_hda_override_conn_list(codec, 0x14, 2, conn1);
5231 snd_hda_override_conn_list(codec, 0x15, 2, conn1);
5232 snd_hda_override_conn_list(codec, 0x18, 2, conn2);
5233 snd_hda_override_conn_list(codec, 0x1a, 2, conn2);
5234 } else if (action == ALC_FIXUP_ACT_PROBE) {
5235 /* restore the connections */
5236 hda_nid_t conn[5] = { 0x0c, 0x0d, 0x0e, 0x0f, 0x26 };
5237 snd_hda_override_conn_list(codec, 0x14, 5, conn);
5238 snd_hda_override_conn_list(codec, 0x15, 5, conn);
5239 snd_hda_override_conn_list(codec, 0x18, 5, conn);
5240 snd_hda_override_conn_list(codec, 0x1a, 5, conn);
5244 /* Set VREF on HP pin */
5245 static void alc889_fixup_mbp_vref(struct hda_codec *codec,
5246 const struct alc_fixup *fix, int action)
5248 struct alc_spec *spec = codec->spec;
5249 static hda_nid_t nids[2] = { 0x14, 0x15 };
5252 if (action != ALC_FIXUP_ACT_INIT)
5254 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5255 unsigned int val = snd_hda_codec_get_pincfg(codec, nids[i]);
5256 if (get_defcfg_device(val) != AC_JACK_HP_OUT)
5258 val = snd_hda_codec_read(codec, nids[i], 0,
5259 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5260 val |= AC_PINCTL_VREF_80;
5261 snd_hda_set_pin_ctl(codec, nids[i], val);
5262 spec->keep_vref_in_automute = 1;
5267 /* Set VREF on speaker pins on imac91 */
5268 static void alc889_fixup_imac91_vref(struct hda_codec *codec,
5269 const struct alc_fixup *fix, int action)
5271 struct alc_spec *spec = codec->spec;
5272 static hda_nid_t nids[2] = { 0x18, 0x1a };
5275 if (action != ALC_FIXUP_ACT_INIT)
5277 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5279 val = snd_hda_codec_read(codec, nids[i], 0,
5280 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5281 val |= AC_PINCTL_VREF_50;
5282 snd_hda_set_pin_ctl(codec, nids[i], val);
5284 spec->keep_vref_in_automute = 1;
5287 /* Don't take HP output as primary
5288 * strangely, the speaker output doesn't work on VAIO Z through DAC 0x05
5290 static void alc882_fixup_no_primary_hp(struct hda_codec *codec,
5291 const struct alc_fixup *fix, int action)
5293 struct alc_spec *spec = codec->spec;
5294 if (action == ALC_FIXUP_ACT_PRE_PROBE)
5295 spec->no_primary_hp = 1;
5298 static const struct alc_fixup alc882_fixups[] = {
5299 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
5300 .type = ALC_FIXUP_PINS,
5301 .v.pins = (const struct alc_pincfg[]) {
5302 { 0x15, 0x01080104 }, /* side */
5303 { 0x16, 0x01011012 }, /* rear */
5304 { 0x17, 0x01016011 }, /* clfe */
5308 [ALC882_FIXUP_LENOVO_Y530] = {
5309 .type = ALC_FIXUP_PINS,
5310 .v.pins = (const struct alc_pincfg[]) {
5311 { 0x15, 0x99130112 }, /* rear int speakers */
5312 { 0x16, 0x99130111 }, /* subwoofer */
5316 [ALC882_FIXUP_PB_M5210] = {
5317 .type = ALC_FIXUP_VERBS,
5318 .v.verbs = (const struct hda_verb[]) {
5319 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
5323 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
5324 .type = ALC_FIXUP_FUNC,
5325 .v.func = alc_fixup_sku_ignore,
5327 [ALC882_FIXUP_ASUS_W90V] = {
5328 .type = ALC_FIXUP_PINS,
5329 .v.pins = (const struct alc_pincfg[]) {
5330 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
5334 [ALC889_FIXUP_CD] = {
5335 .type = ALC_FIXUP_PINS,
5336 .v.pins = (const struct alc_pincfg[]) {
5337 { 0x1c, 0x993301f0 }, /* CD */
5341 [ALC889_FIXUP_VAIO_TT] = {
5342 .type = ALC_FIXUP_PINS,
5343 .v.pins = (const struct alc_pincfg[]) {
5344 { 0x17, 0x90170111 }, /* hidden surround speaker */
5348 [ALC888_FIXUP_EEE1601] = {
5349 .type = ALC_FIXUP_VERBS,
5350 .v.verbs = (const struct hda_verb[]) {
5351 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5352 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
5356 [ALC882_FIXUP_EAPD] = {
5357 .type = ALC_FIXUP_VERBS,
5358 .v.verbs = (const struct hda_verb[]) {
5359 /* change to EAPD mode */
5360 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5361 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
5365 [ALC883_FIXUP_EAPD] = {
5366 .type = ALC_FIXUP_VERBS,
5367 .v.verbs = (const struct hda_verb[]) {
5368 /* change to EAPD mode */
5369 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5370 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5374 [ALC883_FIXUP_ACER_EAPD] = {
5375 .type = ALC_FIXUP_VERBS,
5376 .v.verbs = (const struct hda_verb[]) {
5377 /* eanable EAPD on Acer laptops */
5378 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5379 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5383 [ALC882_FIXUP_GPIO1] = {
5384 .type = ALC_FIXUP_VERBS,
5385 .v.verbs = alc_gpio1_init_verbs,
5387 [ALC882_FIXUP_GPIO2] = {
5388 .type = ALC_FIXUP_VERBS,
5389 .v.verbs = alc_gpio2_init_verbs,
5391 [ALC882_FIXUP_GPIO3] = {
5392 .type = ALC_FIXUP_VERBS,
5393 .v.verbs = alc_gpio3_init_verbs,
5395 [ALC882_FIXUP_ASUS_W2JC] = {
5396 .type = ALC_FIXUP_VERBS,
5397 .v.verbs = alc_gpio1_init_verbs,
5399 .chain_id = ALC882_FIXUP_EAPD,
5401 [ALC889_FIXUP_COEF] = {
5402 .type = ALC_FIXUP_FUNC,
5403 .v.func = alc889_fixup_coef,
5405 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
5406 .type = ALC_FIXUP_PINS,
5407 .v.pins = (const struct alc_pincfg[]) {
5408 { 0x16, 0x99130111 }, /* CLFE speaker */
5409 { 0x17, 0x99130112 }, /* surround speaker */
5413 .chain_id = ALC882_FIXUP_GPIO1,
5415 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
5416 .type = ALC_FIXUP_PINS,
5417 .v.pins = (const struct alc_pincfg[]) {
5418 { 0x16, 0x99130111 }, /* CLFE speaker */
5419 { 0x1b, 0x99130112 }, /* surround speaker */
5423 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
5425 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
5426 /* additional init verbs for Acer Aspire 8930G */
5427 .type = ALC_FIXUP_VERBS,
5428 .v.verbs = (const struct hda_verb[]) {
5429 /* Enable all DACs */
5430 /* DAC DISABLE/MUTE 1? */
5431 /* setting bits 1-5 disables DAC nids 0x02-0x06
5432 * apparently. Init=0x38 */
5433 { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
5434 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5435 /* DAC DISABLE/MUTE 2? */
5436 /* some bit here disables the other DACs.
5438 { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
5439 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5441 * This laptop has a stereo digital microphone.
5442 * The mics are only 1cm apart which makes the stereo
5443 * useless. However, either the mic or the ALC889
5444 * makes the signal become a difference/sum signal
5445 * instead of standard stereo, which is annoying.
5446 * So instead we flip this bit which makes the
5447 * codec replicate the sum signal to both channels,
5448 * turning it into a normal mono mic.
5450 /* DMIC_CONTROL? Init value = 0x0001 */
5451 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5452 { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
5453 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5454 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5458 .chain_id = ALC882_FIXUP_GPIO1,
5460 [ALC885_FIXUP_MACPRO_GPIO] = {
5461 .type = ALC_FIXUP_FUNC,
5462 .v.func = alc885_fixup_macpro_gpio,
5464 [ALC889_FIXUP_DAC_ROUTE] = {
5465 .type = ALC_FIXUP_FUNC,
5466 .v.func = alc889_fixup_dac_route,
5468 [ALC889_FIXUP_MBP_VREF] = {
5469 .type = ALC_FIXUP_FUNC,
5470 .v.func = alc889_fixup_mbp_vref,
5472 .chain_id = ALC882_FIXUP_GPIO1,
5474 [ALC889_FIXUP_IMAC91_VREF] = {
5475 .type = ALC_FIXUP_FUNC,
5476 .v.func = alc889_fixup_imac91_vref,
5478 .chain_id = ALC882_FIXUP_GPIO1,
5480 [ALC882_FIXUP_INV_DMIC] = {
5481 .type = ALC_FIXUP_FUNC,
5482 .v.func = alc_fixup_inv_dmic_0x12,
5484 [ALC882_FIXUP_NO_PRIMARY_HP] = {
5485 .type = ALC_FIXUP_FUNC,
5486 .v.func = alc882_fixup_no_primary_hp,
5490 static const struct snd_pci_quirk alc882_fixup_tbl[] = {
5491 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
5492 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5493 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
5494 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5495 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
5496 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
5497 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
5498 ALC882_FIXUP_ACER_ASPIRE_4930G),
5499 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
5500 ALC882_FIXUP_ACER_ASPIRE_4930G),
5501 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
5502 ALC882_FIXUP_ACER_ASPIRE_8930G),
5503 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
5504 ALC882_FIXUP_ACER_ASPIRE_8930G),
5505 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
5506 ALC882_FIXUP_ACER_ASPIRE_4930G),
5507 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
5508 ALC882_FIXUP_ACER_ASPIRE_4930G),
5509 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
5510 ALC882_FIXUP_ACER_ASPIRE_4930G),
5511 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
5512 SND_PCI_QUIRK(0x1025, 0x021e, "Acer Aspire 5739G",
5513 ALC882_FIXUP_ACER_ASPIRE_4930G),
5514 SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE),
5515 SND_PCI_QUIRK(0x1025, 0x026b, "Acer Aspire 8940G", ALC882_FIXUP_ACER_ASPIRE_8930G),
5516 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
5517 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
5518 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
5519 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
5520 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
5521 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
5522 SND_PCI_QUIRK(0x104d, 0x905a, "Sony Vaio Z", ALC882_FIXUP_NO_PRIMARY_HP),
5524 /* All Apple entries are in codec SSIDs */
5525 SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC889_FIXUP_MBP_VREF),
5526 SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC889_FIXUP_MBP_VREF),
5527 SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
5528 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
5529 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
5530 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
5531 SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC889_FIXUP_MBP_VREF),
5532 SND_PCI_QUIRK(0x106b, 0x3000, "iMac", ALC889_FIXUP_MBP_VREF),
5533 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
5534 SND_PCI_QUIRK(0x106b, 0x3400, "MacBookAir 1,1", ALC889_FIXUP_MBP_VREF),
5535 SND_PCI_QUIRK(0x106b, 0x3500, "MacBookAir 2,1", ALC889_FIXUP_MBP_VREF),
5536 SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889_FIXUP_MBP_VREF),
5537 SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
5538 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
5539 SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC889_FIXUP_IMAC91_VREF),
5540 SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC889_FIXUP_IMAC91_VREF),
5541 SND_PCI_QUIRK(0x106b, 0x4100, "Macmini 3,1", ALC889_FIXUP_IMAC91_VREF),
5542 SND_PCI_QUIRK(0x106b, 0x4200, "Mac Pro 5,1", ALC885_FIXUP_MACPRO_GPIO),
5543 SND_PCI_QUIRK(0x106b, 0x4300, "iMac 9,1", ALC889_FIXUP_IMAC91_VREF),
5544 SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC889_FIXUP_IMAC91_VREF),
5545 SND_PCI_QUIRK(0x106b, 0x4900, "iMac 9,1 Aluminum", ALC889_FIXUP_IMAC91_VREF),
5546 SND_PCI_QUIRK(0x106b, 0x4a00, "Macbook 5,2", ALC889_FIXUP_IMAC91_VREF),
5548 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
5549 SND_PCI_QUIRK(0x1462, 0x7350, "MSI-7350", ALC889_FIXUP_CD),
5550 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
5551 SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte EP45-DS3", ALC889_FIXUP_CD),
5552 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
5553 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
5554 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
5555 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
5556 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
5560 static const struct alc_model_fixup alc882_fixup_models[] = {
5561 {.id = ALC882_FIXUP_ACER_ASPIRE_4930G, .name = "acer-aspire-4930g"},
5562 {.id = ALC882_FIXUP_ACER_ASPIRE_8930G, .name = "acer-aspire-8930g"},
5563 {.id = ALC883_FIXUP_ACER_EAPD, .name = "acer-aspire"},
5564 {.id = ALC882_FIXUP_INV_DMIC, .name = "inv-dmic"},
5565 {.id = ALC882_FIXUP_NO_PRIMARY_HP, .name = "no-primary-hp"},
5570 * BIOS auto configuration
5572 /* almost identical with ALC880 parser... */
5573 static int alc882_parse_auto_config(struct hda_codec *codec)
5575 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
5576 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5577 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
5582 static int patch_alc882(struct hda_codec *codec)
5584 struct alc_spec *spec;
5587 err = alc_alloc_spec(codec, 0x0b);
5593 switch (codec->vendor_id) {
5598 /* ALC883 and variants */
5599 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5603 alc_pick_fixup(codec, alc882_fixup_models, alc882_fixup_tbl,
5605 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5607 alc_auto_parse_customize_define(codec);
5609 /* automatic parse from the BIOS config */
5610 err = alc882_parse_auto_config(codec);
5614 if (!spec->no_analog && has_cdefine_beep(codec)) {
5615 err = snd_hda_attach_beep_device(codec, 0x1);
5618 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5621 codec->patch_ops = alc_patch_ops;
5623 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5636 static int alc262_parse_auto_config(struct hda_codec *codec)
5638 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
5639 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5640 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
5647 ALC262_FIXUP_FSC_H270,
5648 ALC262_FIXUP_HP_Z200,
5650 ALC262_FIXUP_LENOVO_3000,
5652 ALC262_FIXUP_BENQ_T31,
5653 ALC262_FIXUP_INV_DMIC,
5656 static const struct alc_fixup alc262_fixups[] = {
5657 [ALC262_FIXUP_FSC_H270] = {
5658 .type = ALC_FIXUP_PINS,
5659 .v.pins = (const struct alc_pincfg[]) {
5660 { 0x14, 0x99130110 }, /* speaker */
5661 { 0x15, 0x0221142f }, /* front HP */
5662 { 0x1b, 0x0121141f }, /* rear HP */
5666 [ALC262_FIXUP_HP_Z200] = {
5667 .type = ALC_FIXUP_PINS,
5668 .v.pins = (const struct alc_pincfg[]) {
5669 { 0x16, 0x99130120 }, /* internal speaker */
5673 [ALC262_FIXUP_TYAN] = {
5674 .type = ALC_FIXUP_PINS,
5675 .v.pins = (const struct alc_pincfg[]) {
5676 { 0x14, 0x1993e1f0 }, /* int AUX */
5680 [ALC262_FIXUP_LENOVO_3000] = {
5681 .type = ALC_FIXUP_VERBS,
5682 .v.verbs = (const struct hda_verb[]) {
5683 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
5687 .chain_id = ALC262_FIXUP_BENQ,
5689 [ALC262_FIXUP_BENQ] = {
5690 .type = ALC_FIXUP_VERBS,
5691 .v.verbs = (const struct hda_verb[]) {
5692 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5693 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5697 [ALC262_FIXUP_BENQ_T31] = {
5698 .type = ALC_FIXUP_VERBS,
5699 .v.verbs = (const struct hda_verb[]) {
5700 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5701 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5705 [ALC262_FIXUP_INV_DMIC] = {
5706 .type = ALC_FIXUP_FUNC,
5707 .v.func = alc_fixup_inv_dmic_0x12,
5711 static const struct snd_pci_quirk alc262_fixup_tbl[] = {
5712 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
5713 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
5714 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
5715 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
5716 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
5717 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
5718 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
5719 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
5723 static const struct alc_model_fixup alc262_fixup_models[] = {
5724 {.id = ALC262_FIXUP_INV_DMIC, .name = "inv-dmic"},
5730 static int patch_alc262(struct hda_codec *codec)
5732 struct alc_spec *spec;
5735 err = alc_alloc_spec(codec, 0x0b);
5742 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
5747 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5748 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
5749 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5750 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
5753 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5755 alc_pick_fixup(codec, alc262_fixup_models, alc262_fixup_tbl,
5757 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5759 alc_auto_parse_customize_define(codec);
5761 /* automatic parse from the BIOS config */
5762 err = alc262_parse_auto_config(codec);
5766 if (!spec->no_analog && has_cdefine_beep(codec)) {
5767 err = snd_hda_attach_beep_device(codec, 0x1);
5770 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5773 codec->patch_ops = alc_patch_ops;
5774 spec->shutup = alc_eapd_shutup;
5776 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5788 /* bind Beep switches of both NID 0x0f and 0x10 */
5789 static const struct hda_bind_ctls alc268_bind_beep_sw = {
5790 .ops = &snd_hda_bind_sw,
5792 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
5793 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
5798 static const struct snd_kcontrol_new alc268_beep_mixer[] = {
5799 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
5800 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
5804 /* set PCBEEP vol = 0, mute connections */
5805 static const struct hda_verb alc268_beep_init_verbs[] = {
5806 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5807 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5808 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5813 ALC268_FIXUP_INV_DMIC,
5814 ALC268_FIXUP_HP_EAPD,
5817 static const struct alc_fixup alc268_fixups[] = {
5818 [ALC268_FIXUP_INV_DMIC] = {
5819 .type = ALC_FIXUP_FUNC,
5820 .v.func = alc_fixup_inv_dmic_0x12,
5822 [ALC268_FIXUP_HP_EAPD] = {
5823 .type = ALC_FIXUP_VERBS,
5824 .v.verbs = (const struct hda_verb[]) {
5825 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 0},
5831 static const struct alc_model_fixup alc268_fixup_models[] = {
5832 {.id = ALC268_FIXUP_INV_DMIC, .name = "inv-dmic"},
5833 {.id = ALC268_FIXUP_HP_EAPD, .name = "hp-eapd"},
5837 static const struct snd_pci_quirk alc268_fixup_tbl[] = {
5838 /* below is codec SSID since multiple Toshiba laptops have the
5839 * same PCI SSID 1179:ff00
5841 SND_PCI_QUIRK(0x1179, 0xff06, "Toshiba P200", ALC268_FIXUP_HP_EAPD),
5846 * BIOS auto configuration
5848 static int alc268_parse_auto_config(struct hda_codec *codec)
5850 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5851 struct alc_spec *spec = codec->spec;
5852 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
5854 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
5855 add_mixer(spec, alc268_beep_mixer);
5856 snd_hda_gen_add_verbs(&spec->gen, alc268_beep_init_verbs);
5864 static int patch_alc268(struct hda_codec *codec)
5866 struct alc_spec *spec;
5867 int i, has_beep, err;
5869 /* ALC268 has no aa-loopback mixer */
5870 err = alc_alloc_spec(codec, 0);
5876 alc_pick_fixup(codec, alc268_fixup_models, alc268_fixup_tbl, alc268_fixups);
5877 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5879 /* automatic parse from the BIOS config */
5880 err = alc268_parse_auto_config(codec);
5885 for (i = 0; i < spec->num_mixers; i++) {
5886 if (spec->mixers[i] == alc268_beep_mixer) {
5893 err = snd_hda_attach_beep_device(codec, 0x1);
5896 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
5897 /* override the amp caps for beep generator */
5898 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
5899 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
5900 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
5901 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5902 (0 << AC_AMPCAP_MUTE_SHIFT));
5905 codec->patch_ops = alc_patch_ops;
5906 spec->shutup = alc_eapd_shutup;
5908 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5920 static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
5924 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5925 /* NID is set in alc_build_pcms */
5927 .open = alc_playback_pcm_open,
5928 .prepare = alc_playback_pcm_prepare,
5929 .cleanup = alc_playback_pcm_cleanup
5933 static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
5937 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5938 /* NID is set in alc_build_pcms */
5941 /* different alc269-variants */
5943 ALC269_TYPE_ALC269VA,
5944 ALC269_TYPE_ALC269VB,
5945 ALC269_TYPE_ALC269VC,
5946 ALC269_TYPE_ALC269VD,
5953 * BIOS auto configuration
5955 static int alc269_parse_auto_config(struct hda_codec *codec)
5957 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
5958 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
5959 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5960 struct alc_spec *spec = codec->spec;
5961 const hda_nid_t *ssids;
5963 switch (spec->codec_variant) {
5964 case ALC269_TYPE_ALC269VA:
5965 case ALC269_TYPE_ALC269VC:
5966 case ALC269_TYPE_ALC280:
5967 case ALC269_TYPE_ALC284:
5968 ssids = alc269va_ssids;
5970 case ALC269_TYPE_ALC269VB:
5971 case ALC269_TYPE_ALC269VD:
5972 case ALC269_TYPE_ALC282:
5973 ssids = alc269_ssids;
5976 ssids = alc269_ssids;
5980 return alc_parse_auto_config(codec, alc269_ignore, ssids);
5983 static void alc269vb_toggle_power_output(struct hda_codec *codec, int power_up)
5985 int val = alc_read_coef_idx(codec, 0x04);
5990 alc_write_coef_idx(codec, 0x04, val);
5993 static void alc269_shutup(struct hda_codec *codec)
5995 struct alc_spec *spec = codec->spec;
5997 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
6000 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
6001 alc269vb_toggle_power_output(codec, 0);
6002 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
6003 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
6009 static int alc269_resume(struct hda_codec *codec)
6011 struct alc_spec *spec = codec->spec;
6013 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
6014 alc269vb_toggle_power_output(codec, 0);
6015 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
6016 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
6020 codec->patch_ops.init(codec);
6022 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
6023 alc269vb_toggle_power_output(codec, 1);
6024 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
6025 (alc_get_coef0(codec) & 0x00ff) == 0x017) {
6029 snd_hda_codec_resume_amp(codec);
6030 snd_hda_codec_resume_cache(codec);
6031 hda_call_check_power_status(codec, 0x01);
6034 #endif /* CONFIG_PM */
6036 static void alc269_fixup_pincfg_no_hp_to_lineout(struct hda_codec *codec,
6037 const struct alc_fixup *fix, int action)
6039 struct alc_spec *spec = codec->spec;
6041 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6042 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
6045 static void alc269_fixup_hweq(struct hda_codec *codec,
6046 const struct alc_fixup *fix, int action)
6050 if (action != ALC_FIXUP_ACT_INIT)
6052 coef = alc_read_coef_idx(codec, 0x1e);
6053 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
6056 static void alc271_fixup_dmic(struct hda_codec *codec,
6057 const struct alc_fixup *fix, int action)
6059 static const struct hda_verb verbs[] = {
6060 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
6061 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
6066 if (strcmp(codec->chip_name, "ALC271X"))
6068 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
6069 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
6070 snd_hda_sequence_write(codec, verbs);
6073 static void alc269_fixup_pcm_44k(struct hda_codec *codec,
6074 const struct alc_fixup *fix, int action)
6076 struct alc_spec *spec = codec->spec;
6078 if (action != ALC_FIXUP_ACT_PROBE)
6081 /* Due to a hardware problem on Lenovo Ideadpad, we need to
6082 * fix the sample rate of analog I/O to 44.1kHz
6084 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
6085 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
6088 static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
6089 const struct alc_fixup *fix, int action)
6093 if (action != ALC_FIXUP_ACT_INIT)
6095 /* The digital-mic unit sends PDM (differential signal) instead of
6096 * the standard PCM, thus you can't record a valid mono stream as is.
6097 * Below is a workaround specific to ALC269 to control the dmic
6098 * signal source as mono.
6100 coef = alc_read_coef_idx(codec, 0x07);
6101 alc_write_coef_idx(codec, 0x07, coef | 0x80);
6104 static void alc269_quanta_automute(struct hda_codec *codec)
6106 update_outputs(codec);
6108 snd_hda_codec_write(codec, 0x20, 0,
6109 AC_VERB_SET_COEF_INDEX, 0x0c);
6110 snd_hda_codec_write(codec, 0x20, 0,
6111 AC_VERB_SET_PROC_COEF, 0x680);
6113 snd_hda_codec_write(codec, 0x20, 0,
6114 AC_VERB_SET_COEF_INDEX, 0x0c);
6115 snd_hda_codec_write(codec, 0x20, 0,
6116 AC_VERB_SET_PROC_COEF, 0x480);
6119 static void alc269_fixup_quanta_mute(struct hda_codec *codec,
6120 const struct alc_fixup *fix, int action)
6122 struct alc_spec *spec = codec->spec;
6123 if (action != ALC_FIXUP_ACT_PROBE)
6125 spec->automute_hook = alc269_quanta_automute;
6128 /* update mute-LED according to the speaker mute state via mic1 VREF pin */
6129 static void alc269_fixup_mic1_mute_hook(void *private_data, int enabled)
6131 struct hda_codec *codec = private_data;
6132 unsigned int pinval = AC_PINCTL_IN_EN + (enabled ?
6133 AC_PINCTL_VREF_HIZ : AC_PINCTL_VREF_80);
6134 snd_hda_set_pin_ctl_cache(codec, 0x18, pinval);
6137 static void alc269_fixup_mic1_mute(struct hda_codec *codec,
6138 const struct alc_fixup *fix, int action)
6140 struct alc_spec *spec = codec->spec;
6142 case ALC_FIXUP_ACT_BUILD:
6143 spec->vmaster_mute.hook = alc269_fixup_mic1_mute_hook;
6144 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
6146 case ALC_FIXUP_ACT_INIT:
6147 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
6152 /* update mute-LED according to the speaker mute state via mic2 VREF pin */
6153 static void alc269_fixup_mic2_mute_hook(void *private_data, int enabled)
6155 struct hda_codec *codec = private_data;
6156 unsigned int pinval = enabled ? 0x20 : 0x24;
6157 snd_hda_set_pin_ctl_cache(codec, 0x19, pinval);
6160 static void alc269_fixup_mic2_mute(struct hda_codec *codec,
6161 const struct alc_fixup *fix, int action)
6163 struct alc_spec *spec = codec->spec;
6165 case ALC_FIXUP_ACT_BUILD:
6166 spec->vmaster_mute.hook = alc269_fixup_mic2_mute_hook;
6167 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
6169 case ALC_FIXUP_ACT_INIT:
6170 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
6175 static void alc271_hp_gate_mic_jack(struct hda_codec *codec,
6176 const struct alc_fixup *fix,
6179 struct alc_spec *spec = codec->spec;
6181 if (action == ALC_FIXUP_ACT_PROBE)
6182 snd_hda_jack_set_gating_jack(codec, spec->ext_mic_pin,
6183 spec->autocfg.hp_pins[0]);
6187 ALC269_FIXUP_SONY_VAIO,
6188 ALC275_FIXUP_SONY_VAIO_GPIO2,
6189 ALC269_FIXUP_DELL_M101Z,
6190 ALC269_FIXUP_SKU_IGNORE,
6191 ALC269_FIXUP_ASUS_G73JW,
6192 ALC269_FIXUP_LENOVO_EAPD,
6193 ALC275_FIXUP_SONY_HWEQ,
6195 ALC269_FIXUP_PCM_44K,
6196 ALC269_FIXUP_STEREO_DMIC,
6197 ALC269_FIXUP_QUANTA_MUTE,
6198 ALC269_FIXUP_LIFEBOOK,
6201 ALC269VB_FIXUP_AMIC,
6202 ALC269VB_FIXUP_DMIC,
6203 ALC269_FIXUP_MIC1_MUTE_LED,
6204 ALC269_FIXUP_MIC2_MUTE_LED,
6205 ALC269_FIXUP_INV_DMIC,
6206 ALC269_FIXUP_LENOVO_DOCK,
6207 ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT,
6208 ALC271_FIXUP_AMIC_MIC2,
6209 ALC271_FIXUP_HP_GATE_MIC_JACK,
6212 static const struct alc_fixup alc269_fixups[] = {
6213 [ALC269_FIXUP_SONY_VAIO] = {
6214 .type = ALC_FIXUP_VERBS,
6215 .v.verbs = (const struct hda_verb[]) {
6216 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
6220 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
6221 .type = ALC_FIXUP_VERBS,
6222 .v.verbs = (const struct hda_verb[]) {
6223 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
6224 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
6225 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
6229 .chain_id = ALC269_FIXUP_SONY_VAIO
6231 [ALC269_FIXUP_DELL_M101Z] = {
6232 .type = ALC_FIXUP_VERBS,
6233 .v.verbs = (const struct hda_verb[]) {
6234 /* Enables internal speaker */
6235 {0x20, AC_VERB_SET_COEF_INDEX, 13},
6236 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
6240 [ALC269_FIXUP_SKU_IGNORE] = {
6241 .type = ALC_FIXUP_FUNC,
6242 .v.func = alc_fixup_sku_ignore,
6244 [ALC269_FIXUP_ASUS_G73JW] = {
6245 .type = ALC_FIXUP_PINS,
6246 .v.pins = (const struct alc_pincfg[]) {
6247 { 0x17, 0x99130111 }, /* subwoofer */
6251 [ALC269_FIXUP_LENOVO_EAPD] = {
6252 .type = ALC_FIXUP_VERBS,
6253 .v.verbs = (const struct hda_verb[]) {
6254 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6258 [ALC275_FIXUP_SONY_HWEQ] = {
6259 .type = ALC_FIXUP_FUNC,
6260 .v.func = alc269_fixup_hweq,
6262 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
6264 [ALC271_FIXUP_DMIC] = {
6265 .type = ALC_FIXUP_FUNC,
6266 .v.func = alc271_fixup_dmic,
6268 [ALC269_FIXUP_PCM_44K] = {
6269 .type = ALC_FIXUP_FUNC,
6270 .v.func = alc269_fixup_pcm_44k,
6272 .chain_id = ALC269_FIXUP_QUANTA_MUTE
6274 [ALC269_FIXUP_STEREO_DMIC] = {
6275 .type = ALC_FIXUP_FUNC,
6276 .v.func = alc269_fixup_stereo_dmic,
6278 [ALC269_FIXUP_QUANTA_MUTE] = {
6279 .type = ALC_FIXUP_FUNC,
6280 .v.func = alc269_fixup_quanta_mute,
6282 [ALC269_FIXUP_LIFEBOOK] = {
6283 .type = ALC_FIXUP_PINS,
6284 .v.pins = (const struct alc_pincfg[]) {
6285 { 0x1a, 0x2101103f }, /* dock line-out */
6286 { 0x1b, 0x23a11040 }, /* dock mic-in */
6290 .chain_id = ALC269_FIXUP_QUANTA_MUTE
6292 [ALC269_FIXUP_AMIC] = {
6293 .type = ALC_FIXUP_PINS,
6294 .v.pins = (const struct alc_pincfg[]) {
6295 { 0x14, 0x99130110 }, /* speaker */
6296 { 0x15, 0x0121401f }, /* HP out */
6297 { 0x18, 0x01a19c20 }, /* mic */
6298 { 0x19, 0x99a3092f }, /* int-mic */
6302 [ALC269_FIXUP_DMIC] = {
6303 .type = ALC_FIXUP_PINS,
6304 .v.pins = (const struct alc_pincfg[]) {
6305 { 0x12, 0x99a3092f }, /* int-mic */
6306 { 0x14, 0x99130110 }, /* speaker */
6307 { 0x15, 0x0121401f }, /* HP out */
6308 { 0x18, 0x01a19c20 }, /* mic */
6312 [ALC269VB_FIXUP_AMIC] = {
6313 .type = ALC_FIXUP_PINS,
6314 .v.pins = (const struct alc_pincfg[]) {
6315 { 0x14, 0x99130110 }, /* speaker */
6316 { 0x18, 0x01a19c20 }, /* mic */
6317 { 0x19, 0x99a3092f }, /* int-mic */
6318 { 0x21, 0x0121401f }, /* HP out */
6322 [ALC269VB_FIXUP_DMIC] = {
6323 .type = ALC_FIXUP_PINS,
6324 .v.pins = (const struct alc_pincfg[]) {
6325 { 0x12, 0x99a3092f }, /* int-mic */
6326 { 0x14, 0x99130110 }, /* speaker */
6327 { 0x18, 0x01a19c20 }, /* mic */
6328 { 0x21, 0x0121401f }, /* HP out */
6332 [ALC269_FIXUP_MIC1_MUTE_LED] = {
6333 .type = ALC_FIXUP_FUNC,
6334 .v.func = alc269_fixup_mic1_mute,
6336 [ALC269_FIXUP_MIC2_MUTE_LED] = {
6337 .type = ALC_FIXUP_FUNC,
6338 .v.func = alc269_fixup_mic2_mute,
6340 [ALC269_FIXUP_INV_DMIC] = {
6341 .type = ALC_FIXUP_FUNC,
6342 .v.func = alc_fixup_inv_dmic_0x12,
6344 [ALC269_FIXUP_LENOVO_DOCK] = {
6345 .type = ALC_FIXUP_PINS,
6346 .v.pins = (const struct alc_pincfg[]) {
6347 { 0x19, 0x23a11040 }, /* dock mic */
6348 { 0x1b, 0x2121103f }, /* dock headphone */
6352 .chain_id = ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT
6354 [ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT] = {
6355 .type = ALC_FIXUP_FUNC,
6356 .v.func = alc269_fixup_pincfg_no_hp_to_lineout,
6358 [ALC271_FIXUP_AMIC_MIC2] = {
6359 .type = ALC_FIXUP_PINS,
6360 .v.pins = (const struct alc_pincfg[]) {
6361 { 0x14, 0x99130110 }, /* speaker */
6362 { 0x19, 0x01a19c20 }, /* mic */
6363 { 0x1b, 0x99a7012f }, /* int-mic */
6364 { 0x21, 0x0121401f }, /* HP out */
6368 [ALC271_FIXUP_HP_GATE_MIC_JACK] = {
6369 .type = ALC_FIXUP_FUNC,
6370 .v.func = alc271_hp_gate_mic_jack,
6372 .chain_id = ALC271_FIXUP_AMIC_MIC2,
6376 static const struct snd_pci_quirk alc269_fixup_tbl[] = {
6377 SND_PCI_QUIRK(0x1025, 0x029b, "Acer 1810TZ", ALC269_FIXUP_INV_DMIC),
6378 SND_PCI_QUIRK(0x1025, 0x0349, "Acer AOD260", ALC269_FIXUP_INV_DMIC),
6379 SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_MIC2_MUTE_LED),
6380 SND_PCI_QUIRK(0x103c, 0x1972, "HP Pavilion 17", ALC269_FIXUP_MIC1_MUTE_LED),
6381 SND_PCI_QUIRK(0x1043, 0x1427, "Asus Zenbook UX31E", ALC269VB_FIXUP_DMIC),
6382 SND_PCI_QUIRK(0x1043, 0x1517, "Asus Zenbook UX31A", ALC269VB_FIXUP_DMIC),
6383 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
6384 SND_PCI_QUIRK(0x1043, 0x1b13, "Asus U41SV", ALC269_FIXUP_INV_DMIC),
6385 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
6386 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
6387 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
6388 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
6389 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
6390 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
6391 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6392 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6393 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
6394 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
6395 SND_PCI_QUIRK(0x1025, 0x0742, "Acer AO756", ALC271_FIXUP_HP_GATE_MIC_JACK),
6396 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
6397 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
6398 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
6399 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
6400 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
6401 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
6402 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
6403 SND_PCI_QUIRK(0x17aa, 0x21f6, "Thinkpad T530", ALC269_FIXUP_LENOVO_DOCK),
6404 SND_PCI_QUIRK(0x17aa, 0x21fa, "Thinkpad X230", ALC269_FIXUP_LENOVO_DOCK),
6405 SND_PCI_QUIRK(0x17aa, 0x21f3, "Thinkpad T430", ALC269_FIXUP_LENOVO_DOCK),
6406 SND_PCI_QUIRK(0x17aa, 0x21fb, "Thinkpad T430s", ALC269_FIXUP_LENOVO_DOCK),
6407 SND_PCI_QUIRK(0x17aa, 0x2203, "Thinkpad X230 Tablet", ALC269_FIXUP_LENOVO_DOCK),
6408 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_PCM_44K),
6409 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
6412 /* Below is a quirk table taken from the old code.
6413 * Basically the device should work as is without the fixup table.
6414 * If BIOS doesn't give a proper info, enable the corresponding
6417 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
6419 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
6420 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
6421 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
6422 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
6423 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
6424 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
6425 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
6426 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
6427 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
6428 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
6429 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
6430 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
6431 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
6432 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
6433 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
6434 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
6435 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
6436 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
6437 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
6438 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
6439 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
6440 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
6441 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
6442 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
6443 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
6444 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
6445 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
6446 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
6447 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
6448 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
6449 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
6450 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
6451 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
6452 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
6453 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
6454 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
6455 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
6456 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
6457 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
6462 static const struct alc_model_fixup alc269_fixup_models[] = {
6463 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
6464 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
6465 {.id = ALC269_FIXUP_STEREO_DMIC, .name = "alc269-dmic"},
6466 {.id = ALC271_FIXUP_DMIC, .name = "alc271-dmic"},
6467 {.id = ALC269_FIXUP_INV_DMIC, .name = "inv-dmic"},
6468 {.id = ALC269_FIXUP_LENOVO_DOCK, .name = "lenovo-dock"},
6473 static void alc269_fill_coef(struct hda_codec *codec)
6475 struct alc_spec *spec = codec->spec;
6478 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
6481 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
6482 alc_write_coef_idx(codec, 0xf, 0x960b);
6483 alc_write_coef_idx(codec, 0xe, 0x8817);
6486 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
6487 alc_write_coef_idx(codec, 0xf, 0x960b);
6488 alc_write_coef_idx(codec, 0xe, 0x8814);
6491 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
6492 val = alc_read_coef_idx(codec, 0x04);
6493 /* Power up output pin */
6494 alc_write_coef_idx(codec, 0x04, val | (1<<11));
6497 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
6498 val = alc_read_coef_idx(codec, 0xd);
6499 if ((val & 0x0c00) >> 10 != 0x1) {
6500 /* Capless ramp up clock control */
6501 alc_write_coef_idx(codec, 0xd, val | (1<<10));
6503 val = alc_read_coef_idx(codec, 0x17);
6504 if ((val & 0x01c0) >> 6 != 0x4) {
6505 /* Class D power on reset */
6506 alc_write_coef_idx(codec, 0x17, val | (1<<7));
6510 val = alc_read_coef_idx(codec, 0xd); /* Class D */
6511 alc_write_coef_idx(codec, 0xd, val | (1<<14));
6513 val = alc_read_coef_idx(codec, 0x4); /* HP */
6514 alc_write_coef_idx(codec, 0x4, val | (1<<11));
6519 static int patch_alc269(struct hda_codec *codec)
6521 struct alc_spec *spec;
6524 err = alc_alloc_spec(codec, 0x0b);
6530 alc_pick_fixup(codec, alc269_fixup_models,
6531 alc269_fixup_tbl, alc269_fixups);
6532 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6534 alc_auto_parse_customize_define(codec);
6536 switch (codec->vendor_id) {
6538 spec->codec_variant = ALC269_TYPE_ALC269VA;
6539 switch (alc_get_coef0(codec) & 0x00f0) {
6541 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
6542 spec->cdefine.platform_type == 1)
6543 err = alc_codec_rename(codec, "ALC271X");
6544 spec->codec_variant = ALC269_TYPE_ALC269VB;
6547 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
6548 codec->bus->pci->subsystem_device == 0x21f3)
6549 err = alc_codec_rename(codec, "ALC3202");
6550 spec->codec_variant = ALC269_TYPE_ALC269VC;
6553 spec->codec_variant = ALC269_TYPE_ALC269VD;
6556 alc_fix_pll_init(codec, 0x20, 0x04, 15);
6560 spec->init_hook = alc269_fill_coef;
6561 alc269_fill_coef(codec);
6566 spec->codec_variant = ALC269_TYPE_ALC280;
6570 spec->codec_variant = ALC269_TYPE_ALC282;
6574 spec->codec_variant = ALC269_TYPE_ALC284;
6578 /* automatic parse from the BIOS config */
6579 err = alc269_parse_auto_config(codec);
6583 if (!spec->no_analog && has_cdefine_beep(codec)) {
6584 err = snd_hda_attach_beep_device(codec, 0x1);
6587 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
6590 codec->patch_ops = alc_patch_ops;
6592 codec->patch_ops.resume = alc269_resume;
6594 spec->shutup = alc269_shutup;
6596 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6609 static int alc861_parse_auto_config(struct hda_codec *codec)
6611 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
6612 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
6613 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
6616 /* Pin config fixes */
6618 ALC861_FIXUP_FSC_AMILO_PI1505,
6619 ALC861_FIXUP_AMP_VREF_0F,
6620 ALC861_FIXUP_NO_JACK_DETECT,
6621 ALC861_FIXUP_ASUS_A6RP,
6624 /* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
6625 static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
6626 const struct alc_fixup *fix, int action)
6628 struct alc_spec *spec = codec->spec;
6631 if (action != ALC_FIXUP_ACT_INIT)
6633 val = snd_hda_codec_read(codec, 0x0f, 0,
6634 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
6635 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
6636 val |= AC_PINCTL_IN_EN;
6637 val |= AC_PINCTL_VREF_50;
6638 snd_hda_set_pin_ctl(codec, 0x0f, val);
6639 spec->keep_vref_in_automute = 1;
6642 /* suppress the jack-detection */
6643 static void alc_fixup_no_jack_detect(struct hda_codec *codec,
6644 const struct alc_fixup *fix, int action)
6646 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6647 codec->no_jack_detect = 1;
6650 static const struct alc_fixup alc861_fixups[] = {
6651 [ALC861_FIXUP_FSC_AMILO_PI1505] = {
6652 .type = ALC_FIXUP_PINS,
6653 .v.pins = (const struct alc_pincfg[]) {
6654 { 0x0b, 0x0221101f }, /* HP */
6655 { 0x0f, 0x90170310 }, /* speaker */
6659 [ALC861_FIXUP_AMP_VREF_0F] = {
6660 .type = ALC_FIXUP_FUNC,
6661 .v.func = alc861_fixup_asus_amp_vref_0f,
6663 [ALC861_FIXUP_NO_JACK_DETECT] = {
6664 .type = ALC_FIXUP_FUNC,
6665 .v.func = alc_fixup_no_jack_detect,
6667 [ALC861_FIXUP_ASUS_A6RP] = {
6668 .type = ALC_FIXUP_FUNC,
6669 .v.func = alc861_fixup_asus_amp_vref_0f,
6671 .chain_id = ALC861_FIXUP_NO_JACK_DETECT,
6675 static const struct snd_pci_quirk alc861_fixup_tbl[] = {
6676 SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP),
6677 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", ALC861_FIXUP_AMP_VREF_0F),
6678 SND_PCI_QUIRK(0x1462, 0x7254, "HP DX2200", ALC861_FIXUP_NO_JACK_DETECT),
6679 SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", ALC861_FIXUP_AMP_VREF_0F),
6680 SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", ALC861_FIXUP_AMP_VREF_0F),
6681 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", ALC861_FIXUP_FSC_AMILO_PI1505),
6687 static int patch_alc861(struct hda_codec *codec)
6689 struct alc_spec *spec;
6692 err = alc_alloc_spec(codec, 0x15);
6698 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
6699 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6701 /* automatic parse from the BIOS config */
6702 err = alc861_parse_auto_config(codec);
6706 if (!spec->no_analog) {
6707 err = snd_hda_attach_beep_device(codec, 0x23);
6710 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
6713 codec->patch_ops = alc_patch_ops;
6715 spec->power_hook = alc_power_eapd;
6718 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6732 * In addition, an independent DAC
6734 static int alc861vd_parse_auto_config(struct hda_codec *codec)
6736 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
6737 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6738 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
6742 ALC660VD_FIX_ASUS_GPIO1,
6743 ALC861VD_FIX_DALLAS,
6746 /* exclude VREF80 */
6747 static void alc861vd_fixup_dallas(struct hda_codec *codec,
6748 const struct alc_fixup *fix, int action)
6750 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
6751 snd_hda_override_pin_caps(codec, 0x18, 0x00000734);
6752 snd_hda_override_pin_caps(codec, 0x19, 0x0000073c);
6756 static const struct alc_fixup alc861vd_fixups[] = {
6757 [ALC660VD_FIX_ASUS_GPIO1] = {
6758 .type = ALC_FIXUP_VERBS,
6759 .v.verbs = (const struct hda_verb[]) {
6761 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6762 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
6763 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
6767 [ALC861VD_FIX_DALLAS] = {
6768 .type = ALC_FIXUP_FUNC,
6769 .v.func = alc861vd_fixup_dallas,
6773 static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
6774 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
6775 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
6776 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
6782 static int patch_alc861vd(struct hda_codec *codec)
6784 struct alc_spec *spec;
6787 err = alc_alloc_spec(codec, 0x0b);
6793 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
6794 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6796 /* automatic parse from the BIOS config */
6797 err = alc861vd_parse_auto_config(codec);
6801 if (!spec->no_analog) {
6802 err = snd_hda_attach_beep_device(codec, 0x23);
6805 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6808 codec->patch_ops = alc_patch_ops;
6810 spec->shutup = alc_eapd_shutup;
6812 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6824 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
6825 * configuration. Each pin widget can choose any input DACs and a mixer.
6826 * Each ADC is connected from a mixer of all inputs. This makes possible
6827 * 6-channel independent captures.
6829 * In addition, an independent DAC for the multi-playback (not used in this
6834 * BIOS auto configuration
6837 static int alc662_parse_auto_config(struct hda_codec *codec)
6839 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
6840 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
6841 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6842 const hda_nid_t *ssids;
6844 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
6845 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
6846 ssids = alc663_ssids;
6848 ssids = alc662_ssids;
6849 return alc_parse_auto_config(codec, alc662_ignore, ssids);
6852 static void alc272_fixup_mario(struct hda_codec *codec,
6853 const struct alc_fixup *fix, int action)
6855 if (action != ALC_FIXUP_ACT_PROBE)
6857 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
6858 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
6859 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
6860 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6861 (0 << AC_AMPCAP_MUTE_SHIFT)))
6863 "hda_codec: failed to override amp caps for NID 0x2\n");
6867 ALC662_FIXUP_ASPIRE,
6868 ALC662_FIXUP_IDEAPAD,
6870 ALC662_FIXUP_CZC_P10T,
6871 ALC662_FIXUP_SKU_IGNORE,
6872 ALC662_FIXUP_HP_RP5800,
6873 ALC662_FIXUP_ASUS_MODE1,
6874 ALC662_FIXUP_ASUS_MODE2,
6875 ALC662_FIXUP_ASUS_MODE3,
6876 ALC662_FIXUP_ASUS_MODE4,
6877 ALC662_FIXUP_ASUS_MODE5,
6878 ALC662_FIXUP_ASUS_MODE6,
6879 ALC662_FIXUP_ASUS_MODE7,
6880 ALC662_FIXUP_ASUS_MODE8,
6881 ALC662_FIXUP_NO_JACK_DETECT,
6882 ALC662_FIXUP_ZOTAC_Z68,
6883 ALC662_FIXUP_INV_DMIC,
6886 static const struct alc_fixup alc662_fixups[] = {
6887 [ALC662_FIXUP_ASPIRE] = {
6888 .type = ALC_FIXUP_PINS,
6889 .v.pins = (const struct alc_pincfg[]) {
6890 { 0x15, 0x99130112 }, /* subwoofer */
6894 [ALC662_FIXUP_IDEAPAD] = {
6895 .type = ALC_FIXUP_PINS,
6896 .v.pins = (const struct alc_pincfg[]) {
6897 { 0x17, 0x99130112 }, /* subwoofer */
6901 [ALC272_FIXUP_MARIO] = {
6902 .type = ALC_FIXUP_FUNC,
6903 .v.func = alc272_fixup_mario,
6905 [ALC662_FIXUP_CZC_P10T] = {
6906 .type = ALC_FIXUP_VERBS,
6907 .v.verbs = (const struct hda_verb[]) {
6908 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6912 [ALC662_FIXUP_SKU_IGNORE] = {
6913 .type = ALC_FIXUP_FUNC,
6914 .v.func = alc_fixup_sku_ignore,
6916 [ALC662_FIXUP_HP_RP5800] = {
6917 .type = ALC_FIXUP_PINS,
6918 .v.pins = (const struct alc_pincfg[]) {
6919 { 0x14, 0x0221201f }, /* HP out */
6923 .chain_id = ALC662_FIXUP_SKU_IGNORE
6925 [ALC662_FIXUP_ASUS_MODE1] = {
6926 .type = ALC_FIXUP_PINS,
6927 .v.pins = (const struct alc_pincfg[]) {
6928 { 0x14, 0x99130110 }, /* speaker */
6929 { 0x18, 0x01a19c20 }, /* mic */
6930 { 0x19, 0x99a3092f }, /* int-mic */
6931 { 0x21, 0x0121401f }, /* HP out */
6935 .chain_id = ALC662_FIXUP_SKU_IGNORE
6937 [ALC662_FIXUP_ASUS_MODE2] = {
6938 .type = ALC_FIXUP_PINS,
6939 .v.pins = (const struct alc_pincfg[]) {
6940 { 0x14, 0x99130110 }, /* speaker */
6941 { 0x18, 0x01a19820 }, /* mic */
6942 { 0x19, 0x99a3092f }, /* int-mic */
6943 { 0x1b, 0x0121401f }, /* HP out */
6947 .chain_id = ALC662_FIXUP_SKU_IGNORE
6949 [ALC662_FIXUP_ASUS_MODE3] = {
6950 .type = ALC_FIXUP_PINS,
6951 .v.pins = (const struct alc_pincfg[]) {
6952 { 0x14, 0x99130110 }, /* speaker */
6953 { 0x15, 0x0121441f }, /* HP */
6954 { 0x18, 0x01a19840 }, /* mic */
6955 { 0x19, 0x99a3094f }, /* int-mic */
6956 { 0x21, 0x01211420 }, /* HP2 */
6960 .chain_id = ALC662_FIXUP_SKU_IGNORE
6962 [ALC662_FIXUP_ASUS_MODE4] = {
6963 .type = ALC_FIXUP_PINS,
6964 .v.pins = (const struct alc_pincfg[]) {
6965 { 0x14, 0x99130110 }, /* speaker */
6966 { 0x16, 0x99130111 }, /* speaker */
6967 { 0x18, 0x01a19840 }, /* mic */
6968 { 0x19, 0x99a3094f }, /* int-mic */
6969 { 0x21, 0x0121441f }, /* HP */
6973 .chain_id = ALC662_FIXUP_SKU_IGNORE
6975 [ALC662_FIXUP_ASUS_MODE5] = {
6976 .type = ALC_FIXUP_PINS,
6977 .v.pins = (const struct alc_pincfg[]) {
6978 { 0x14, 0x99130110 }, /* speaker */
6979 { 0x15, 0x0121441f }, /* HP */
6980 { 0x16, 0x99130111 }, /* speaker */
6981 { 0x18, 0x01a19840 }, /* mic */
6982 { 0x19, 0x99a3094f }, /* int-mic */
6986 .chain_id = ALC662_FIXUP_SKU_IGNORE
6988 [ALC662_FIXUP_ASUS_MODE6] = {
6989 .type = ALC_FIXUP_PINS,
6990 .v.pins = (const struct alc_pincfg[]) {
6991 { 0x14, 0x99130110 }, /* speaker */
6992 { 0x15, 0x01211420 }, /* HP2 */
6993 { 0x18, 0x01a19840 }, /* mic */
6994 { 0x19, 0x99a3094f }, /* int-mic */
6995 { 0x1b, 0x0121441f }, /* HP */
6999 .chain_id = ALC662_FIXUP_SKU_IGNORE
7001 [ALC662_FIXUP_ASUS_MODE7] = {
7002 .type = ALC_FIXUP_PINS,
7003 .v.pins = (const struct alc_pincfg[]) {
7004 { 0x14, 0x99130110 }, /* speaker */
7005 { 0x17, 0x99130111 }, /* speaker */
7006 { 0x18, 0x01a19840 }, /* mic */
7007 { 0x19, 0x99a3094f }, /* int-mic */
7008 { 0x1b, 0x01214020 }, /* HP */
7009 { 0x21, 0x0121401f }, /* HP */
7013 .chain_id = ALC662_FIXUP_SKU_IGNORE
7015 [ALC662_FIXUP_ASUS_MODE8] = {
7016 .type = ALC_FIXUP_PINS,
7017 .v.pins = (const struct alc_pincfg[]) {
7018 { 0x14, 0x99130110 }, /* speaker */
7019 { 0x12, 0x99a30970 }, /* int-mic */
7020 { 0x15, 0x01214020 }, /* HP */
7021 { 0x17, 0x99130111 }, /* speaker */
7022 { 0x18, 0x01a19840 }, /* mic */
7023 { 0x21, 0x0121401f }, /* HP */
7027 .chain_id = ALC662_FIXUP_SKU_IGNORE
7029 [ALC662_FIXUP_NO_JACK_DETECT] = {
7030 .type = ALC_FIXUP_FUNC,
7031 .v.func = alc_fixup_no_jack_detect,
7033 [ALC662_FIXUP_ZOTAC_Z68] = {
7034 .type = ALC_FIXUP_PINS,
7035 .v.pins = (const struct alc_pincfg[]) {
7036 { 0x1b, 0x02214020 }, /* Front HP */
7040 [ALC662_FIXUP_INV_DMIC] = {
7041 .type = ALC_FIXUP_FUNC,
7042 .v.func = alc_fixup_inv_dmic_0x12,
7046 static const struct snd_pci_quirk alc662_fixup_tbl[] = {
7047 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
7048 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
7049 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
7050 SND_PCI_QUIRK(0x1025, 0x0349, "eMachines eM250", ALC662_FIXUP_INV_DMIC),
7051 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
7052 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
7053 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT),
7054 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
7055 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
7056 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
7057 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
7058 SND_PCI_QUIRK(0x19da, 0xa130, "Zotac Z68", ALC662_FIXUP_ZOTAC_Z68),
7059 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
7062 /* Below is a quirk table taken from the old code.
7063 * Basically the device should work as is without the fixup table.
7064 * If BIOS doesn't give a proper info, enable the corresponding
7067 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
7068 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
7069 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
7070 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
7071 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7072 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7073 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7074 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
7075 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
7076 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7077 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
7078 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
7079 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
7080 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
7081 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
7082 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7083 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
7084 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
7085 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7086 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
7087 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
7088 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7089 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
7090 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
7091 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
7092 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7093 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
7094 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
7095 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7096 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
7097 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7098 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7099 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
7100 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
7101 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
7102 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
7103 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
7104 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
7105 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
7106 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7107 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
7108 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
7109 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7110 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
7111 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
7112 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
7113 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
7114 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
7115 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7116 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
7121 static const struct alc_model_fixup alc662_fixup_models[] = {
7122 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
7123 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
7124 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
7125 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
7126 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
7127 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
7128 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
7129 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
7130 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
7131 {.id = ALC662_FIXUP_INV_DMIC, .name = "inv-dmic"},
7135 static void alc662_fill_coef(struct hda_codec *codec)
7139 coef = alc_get_coef0(codec);
7141 switch (codec->vendor_id) {
7143 if ((coef & 0x00f0) == 0x0030) {
7144 val = alc_read_coef_idx(codec, 0x4); /* EAPD Ctrl */
7145 alc_write_coef_idx(codec, 0x4, val & ~(1<<10));
7155 val = alc_read_coef_idx(codec, 0xd); /* EAPD Ctrl */
7156 alc_write_coef_idx(codec, 0xd, val | (1<<14));
7163 static int patch_alc662(struct hda_codec *codec)
7165 struct alc_spec *spec;
7168 err = alc_alloc_spec(codec, 0x0b);
7174 /* handle multiple HPs as is */
7175 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
7177 alc_fix_pll_init(codec, 0x20, 0x04, 15);
7179 spec->init_hook = alc662_fill_coef;
7180 alc662_fill_coef(codec);
7182 alc_pick_fixup(codec, alc662_fixup_models,
7183 alc662_fixup_tbl, alc662_fixups);
7184 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
7186 alc_auto_parse_customize_define(codec);
7188 if ((alc_get_coef0(codec) & (1 << 14)) &&
7189 codec->bus->pci->subsystem_vendor == 0x1025 &&
7190 spec->cdefine.platform_type == 1) {
7191 if (alc_codec_rename(codec, "ALC272X") < 0)
7195 /* automatic parse from the BIOS config */
7196 err = alc662_parse_auto_config(codec);
7200 if (!spec->no_analog && has_cdefine_beep(codec)) {
7201 err = snd_hda_attach_beep_device(codec, 0x1);
7204 switch (codec->vendor_id) {
7206 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
7211 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
7214 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
7219 codec->patch_ops = alc_patch_ops;
7220 spec->shutup = alc_eapd_shutup;
7222 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
7235 static int alc680_parse_auto_config(struct hda_codec *codec)
7237 return alc_parse_auto_config(codec, NULL, NULL);
7242 static int patch_alc680(struct hda_codec *codec)
7246 /* ALC680 has no aa-loopback mixer */
7247 err = alc_alloc_spec(codec, 0);
7251 /* automatic parse from the BIOS config */
7252 err = alc680_parse_auto_config(codec);
7258 codec->patch_ops = alc_patch_ops;
7266 static const struct hda_codec_preset snd_hda_preset_realtek[] = {
7267 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
7268 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
7269 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
7270 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
7271 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
7272 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
7273 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
7274 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
7275 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
7276 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
7277 { .id = 0x10ec0280, .name = "ALC280", .patch = patch_alc269 },
7278 { .id = 0x10ec0282, .name = "ALC282", .patch = patch_alc269 },
7279 { .id = 0x10ec0283, .name = "ALC283", .patch = patch_alc269 },
7280 { .id = 0x10ec0284, .name = "ALC284", .patch = patch_alc269 },
7281 { .id = 0x10ec0290, .name = "ALC290", .patch = patch_alc269 },
7282 { .id = 0x10ec0292, .name = "ALC292", .patch = patch_alc269 },
7283 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
7284 .patch = patch_alc861 },
7285 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
7286 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
7287 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
7288 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
7289 .patch = patch_alc882 },
7290 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
7291 .patch = patch_alc662 },
7292 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
7293 .patch = patch_alc662 },
7294 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
7295 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
7296 { .id = 0x10ec0668, .name = "ALC668", .patch = patch_alc662 },
7297 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
7298 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
7299 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
7300 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
7301 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
7302 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
7303 .patch = patch_alc882 },
7304 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
7305 .patch = patch_alc882 },
7306 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
7307 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
7308 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
7309 .patch = patch_alc882 },
7310 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
7311 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
7312 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
7313 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
7314 { .id = 0x10ec0900, .name = "ALC1150", .patch = patch_alc882 },
7318 MODULE_ALIAS("snd-hda-codec-id:10ec*");
7320 MODULE_LICENSE("GPL");
7321 MODULE_DESCRIPTION("Realtek HD-audio codec");
7323 static struct hda_codec_preset_list realtek_list = {
7324 .preset = snd_hda_preset_realtek,
7325 .owner = THIS_MODULE,
7328 static int __init patch_realtek_init(void)
7330 return snd_hda_add_codec_preset(&realtek_list);
7333 static void __exit patch_realtek_exit(void)
7335 snd_hda_delete_codec_preset(&realtek_list);
7338 module_init(patch_realtek_init)
7339 module_exit(patch_realtek_exit)