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@physics.adelaide.edu.au>
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"
38 /* unsol event tags */
39 #define ALC_FRONT_EVENT 0x01
40 #define ALC_DCVOL_EVENT 0x02
41 #define ALC_HP_EVENT 0x04
42 #define ALC_MIC_EVENT 0x08
45 #define GPIO_MASK 0x03
47 /* extra amp-initialization sequence types */
56 struct alc_customize_define {
58 unsigned char port_connectivity;
59 unsigned char check_sum;
60 unsigned char customization;
61 unsigned char external_amp;
62 unsigned int enable_pcbeep:1;
63 unsigned int platform_type:1;
65 unsigned int override:1;
66 unsigned int fixup:1; /* Means that this sku is set by driver, not read from hw */
72 hda_nid_t pin; /* multi-io widget pin NID */
73 hda_nid_t dac; /* DAC to be connected */
74 unsigned int ctl_in; /* cached input-pin control value */
78 ALC_AUTOMUTE_PIN, /* change the pin control */
79 ALC_AUTOMUTE_AMP, /* mute/unmute the pin AMP */
80 ALC_AUTOMUTE_MIXER, /* mute/unmute mixer widget AMP */
83 #define MAX_VOL_NIDS 0x40
86 /* codec parameterization */
87 const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */
88 unsigned int num_mixers;
89 const struct snd_kcontrol_new *cap_mixer; /* capture mixer */
90 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
92 const struct hda_verb *init_verbs[10]; /* initialization verbs
96 unsigned int num_init_verbs;
98 char stream_name_analog[32]; /* analog PCM stream */
99 const struct hda_pcm_stream *stream_analog_playback;
100 const struct hda_pcm_stream *stream_analog_capture;
101 const struct hda_pcm_stream *stream_analog_alt_playback;
102 const struct hda_pcm_stream *stream_analog_alt_capture;
104 char stream_name_digital[32]; /* digital PCM stream */
105 const struct hda_pcm_stream *stream_digital_playback;
106 const struct hda_pcm_stream *stream_digital_capture;
109 struct hda_multi_out multiout; /* playback set-up
110 * max_channels, dacs must be set
111 * dig_out_nid and hp_nid are optional
113 hda_nid_t alt_dac_nid;
114 hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */
118 unsigned int num_adc_nids;
119 const hda_nid_t *adc_nids;
120 const hda_nid_t *capsrc_nids;
121 hda_nid_t dig_in_nid; /* digital-in NID; optional */
122 hda_nid_t mixer_nid; /* analog-mixer NID */
123 DECLARE_BITMAP(vol_ctls, MAX_VOL_NIDS << 1);
124 DECLARE_BITMAP(sw_ctls, MAX_VOL_NIDS << 1);
126 /* capture setup for dynamic dual-adc switch */
128 unsigned int cur_adc_stream_tag;
129 unsigned int cur_adc_format;
132 unsigned int num_mux_defs;
133 const struct hda_input_mux *input_mux;
134 unsigned int cur_mux[3];
135 hda_nid_t ext_mic_pin;
136 hda_nid_t dock_mic_pin;
137 hda_nid_t int_mic_pin;
140 const struct hda_channel_mode *channel_mode;
141 int num_channel_mode;
143 int const_channel_count;
144 int ext_channel_count;
146 /* PCM information */
147 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
149 /* dynamic controls, init_verbs and input_mux */
150 struct auto_pin_cfg autocfg;
151 struct alc_customize_define cdefine;
152 struct snd_array kctls;
153 struct hda_input_mux private_imux[3];
154 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
155 hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS];
156 hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS];
157 hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS];
158 unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS];
159 int int_mic_idx, ext_mic_idx, dock_mic_idx; /* for auto-mic */
162 void (*init_hook)(struct hda_codec *codec);
163 void (*unsol_event)(struct hda_codec *codec, unsigned int res);
164 #ifdef CONFIG_SND_HDA_POWER_SAVE
165 void (*power_hook)(struct hda_codec *codec);
167 void (*shutup)(struct hda_codec *codec);
168 void (*automute_hook)(struct hda_codec *codec);
170 /* for pin sensing */
171 unsigned int hp_jack_present:1;
172 unsigned int line_jack_present:1;
173 unsigned int master_mute:1;
174 unsigned int auto_mic:1;
175 unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */
176 unsigned int automute_speaker:1; /* automute speaker outputs */
177 unsigned int automute_lo:1; /* automute LO outputs */
178 unsigned int detect_hp:1; /* Headphone detection enabled */
179 unsigned int detect_lo:1; /* Line-out detection enabled */
180 unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */
181 unsigned int automute_lo_possible:1; /* there are line outs and HP */
182 unsigned int keep_vref_in_automute:1; /* Don't clear VREF in automute */
185 unsigned int no_analog :1; /* digital I/O only */
186 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
187 unsigned int single_input_src:1;
188 unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */
189 unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */
190 unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */
191 unsigned int no_primary_hp:1; /* Don't prefer HP pins to speaker pins */
193 /* auto-mute control */
195 hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS];
198 int codec_variant; /* flag for other variants */
200 /* for virtual master */
201 hda_nid_t vmaster_nid;
202 struct hda_vmaster_mute_hook vmaster_mute;
203 #ifdef CONFIG_SND_HDA_POWER_SAVE
204 struct hda_loopback_check loopback;
206 struct hda_amp_list loopback_list[8];
211 unsigned int pll_coef_idx, pll_coef_bit;
216 const struct alc_fixup *fixup_list;
217 const char *fixup_name;
221 struct alc_multi_io multi_io[4];
224 struct snd_array bind_ctls;
227 static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
228 int dir, unsigned int bits)
232 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
233 if (query_amp_caps(codec, nid, dir) & bits)
238 #define nid_has_mute(codec, nid, dir) \
239 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
240 #define nid_has_volume(codec, nid, dir) \
241 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
246 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
247 struct snd_ctl_elem_info *uinfo)
249 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
250 struct alc_spec *spec = codec->spec;
251 unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
252 if (mux_idx >= spec->num_mux_defs)
254 if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
256 return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
259 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
260 struct snd_ctl_elem_value *ucontrol)
262 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
263 struct alc_spec *spec = codec->spec;
264 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
266 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
270 static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
272 struct alc_spec *spec = codec->spec;
273 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
275 if (spec->cur_adc && spec->cur_adc != new_adc) {
276 /* stream is running, let's swap the current ADC */
277 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
278 spec->cur_adc = new_adc;
279 snd_hda_codec_setup_stream(codec, new_adc,
280 spec->cur_adc_stream_tag, 0,
281 spec->cur_adc_format);
287 static inline hda_nid_t get_capsrc(struct alc_spec *spec, int idx)
289 return spec->capsrc_nids ?
290 spec->capsrc_nids[idx] : spec->adc_nids[idx];
293 static void call_update_outputs(struct hda_codec *codec);
295 /* select the given imux item; either unmute exclusively or select the route */
296 static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
297 unsigned int idx, bool force)
299 struct alc_spec *spec = codec->spec;
300 const struct hda_input_mux *imux;
301 unsigned int mux_idx;
302 int i, type, num_conns;
305 if (!spec->input_mux)
308 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
309 imux = &spec->input_mux[mux_idx];
310 if (!imux->num_items && mux_idx > 0)
311 imux = &spec->input_mux[0];
312 if (!imux->num_items)
315 if (idx >= imux->num_items)
316 idx = imux->num_items - 1;
317 if (spec->cur_mux[adc_idx] == idx && !force)
319 spec->cur_mux[adc_idx] = idx;
321 /* for shared I/O, change the pin-control accordingly */
322 if (spec->shared_mic_hp) {
323 /* NOTE: this assumes that there are only two inputs, the
324 * first is the real internal mic and the second is HP jack.
326 snd_hda_codec_write(codec, spec->autocfg.inputs[1].pin, 0,
327 AC_VERB_SET_PIN_WIDGET_CONTROL,
328 spec->cur_mux[adc_idx] ?
329 PIN_VREF80 : PIN_HP);
330 spec->automute_speaker = !spec->cur_mux[adc_idx];
331 call_update_outputs(codec);
334 if (spec->dyn_adc_switch) {
335 alc_dyn_adc_pcm_resetup(codec, idx);
336 adc_idx = spec->dyn_adc_idx[idx];
339 nid = get_capsrc(spec, adc_idx);
342 num_conns = snd_hda_get_conn_list(codec, nid, NULL);
346 type = get_wcaps_type(get_wcaps(codec, nid));
347 if (type == AC_WID_AUD_MIX) {
348 /* Matrix-mixer style (e.g. ALC882) */
349 int active = imux->items[idx].index;
350 for (i = 0; i < num_conns; i++) {
351 unsigned int v = (i == active) ? 0 : HDA_AMP_MUTE;
352 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, i,
356 /* MUX style (e.g. ALC880) */
357 snd_hda_codec_write_cache(codec, nid, 0,
358 AC_VERB_SET_CONNECT_SEL,
359 imux->items[idx].index);
364 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
365 struct snd_ctl_elem_value *ucontrol)
367 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
368 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
369 return alc_mux_select(codec, adc_idx,
370 ucontrol->value.enumerated.item[0], false);
374 * set up the input pin config (depending on the given auto-pin type)
376 static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
379 unsigned int val = PIN_IN;
381 if (auto_pin_type == AUTO_PIN_MIC) {
384 oldval = snd_hda_codec_read(codec, nid, 0,
385 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
386 pincap = snd_hda_query_pin_caps(codec, nid);
387 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
388 /* if the default pin setup is vref50, we give it priority */
389 if ((pincap & AC_PINCAP_VREF_80) && oldval != PIN_VREF50)
391 else if (pincap & AC_PINCAP_VREF_50)
393 else if (pincap & AC_PINCAP_VREF_100)
395 else if (pincap & AC_PINCAP_VREF_GRD)
398 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val);
402 * Append the given mixer and verb elements for the later use
403 * The mixer array is referred in build_controls(), and init_verbs are
406 static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
408 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
410 spec->mixers[spec->num_mixers++] = mix;
413 static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
415 if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
417 spec->init_verbs[spec->num_init_verbs++] = verb;
421 * GPIO setup tables, used in initialization
423 /* Enable GPIO mask and set output */
424 static const struct hda_verb alc_gpio1_init_verbs[] = {
425 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
426 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
427 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
431 static const struct hda_verb alc_gpio2_init_verbs[] = {
432 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
433 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
434 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
438 static const struct hda_verb alc_gpio3_init_verbs[] = {
439 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
440 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
441 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
446 * Fix hardware PLL issue
447 * On some codecs, the analog PLL gating control must be off while
448 * the default value is 1.
450 static void alc_fix_pll(struct hda_codec *codec)
452 struct alc_spec *spec = codec->spec;
457 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
459 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
460 AC_VERB_GET_PROC_COEF, 0);
461 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
463 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
464 val & ~(1 << spec->pll_coef_bit));
467 static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
468 unsigned int coef_idx, unsigned int coef_bit)
470 struct alc_spec *spec = codec->spec;
472 spec->pll_coef_idx = coef_idx;
473 spec->pll_coef_bit = coef_bit;
478 * Jack detections for HP auto-mute and mic-switch
481 /* check each pin in the given array; returns true if any of them is plugged */
482 static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
486 for (i = 0; i < num_pins; i++) {
487 hda_nid_t nid = pins[i];
490 present |= snd_hda_jack_detect(codec, nid);
495 /* standard HP/line-out auto-mute helper */
496 static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
497 bool mute, bool hp_out)
499 struct alc_spec *spec = codec->spec;
500 unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0;
501 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
504 for (i = 0; i < num_pins; i++) {
505 hda_nid_t nid = pins[i];
509 switch (spec->automute_mode) {
510 case ALC_AUTOMUTE_PIN:
511 /* don't reset VREF value in case it's controlling
512 * the amp (see alc861_fixup_asus_amp_vref_0f())
514 if (spec->keep_vref_in_automute) {
515 val = snd_hda_codec_read(codec, nid, 0,
516 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
521 snd_hda_codec_write(codec, nid, 0,
522 AC_VERB_SET_PIN_WIDGET_CONTROL,
525 case ALC_AUTOMUTE_AMP:
526 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
527 HDA_AMP_MUTE, mute_bits);
529 case ALC_AUTOMUTE_MIXER:
530 nid = spec->automute_mixer_nid[i];
533 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
534 HDA_AMP_MUTE, mute_bits);
535 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1,
536 HDA_AMP_MUTE, mute_bits);
542 /* Toggle outputs muting */
543 static void update_outputs(struct hda_codec *codec)
545 struct alc_spec *spec = codec->spec;
548 /* Control HP pins/amps depending on master_mute state;
549 * in general, HP pins/amps control should be enabled in all cases,
550 * but currently set only for master_mute, just to be safe
552 if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */
553 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
554 spec->autocfg.hp_pins, spec->master_mute, true);
556 if (!spec->automute_speaker)
559 on = spec->hp_jack_present | spec->line_jack_present;
560 on |= spec->master_mute;
561 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
562 spec->autocfg.speaker_pins, on, false);
564 /* toggle line-out mutes if needed, too */
565 /* if LO is a copy of either HP or Speaker, don't need to handle it */
566 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
567 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
569 if (!spec->automute_lo)
572 on = spec->hp_jack_present;
573 on |= spec->master_mute;
574 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
575 spec->autocfg.line_out_pins, on, false);
578 static void call_update_outputs(struct hda_codec *codec)
580 struct alc_spec *spec = codec->spec;
581 if (spec->automute_hook)
582 spec->automute_hook(codec);
584 update_outputs(codec);
587 /* standard HP-automute helper */
588 static void alc_hp_automute(struct hda_codec *codec)
590 struct alc_spec *spec = codec->spec;
592 spec->hp_jack_present =
593 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
594 spec->autocfg.hp_pins);
595 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
597 call_update_outputs(codec);
600 /* standard line-out-automute helper */
601 static void alc_line_automute(struct hda_codec *codec)
603 struct alc_spec *spec = codec->spec;
605 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
607 /* check LO jack only when it's different from HP */
608 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
611 spec->line_jack_present =
612 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
613 spec->autocfg.line_out_pins);
614 if (!spec->automute_speaker || !spec->detect_lo)
616 call_update_outputs(codec);
619 #define get_connection_index(codec, mux, nid) \
620 snd_hda_get_conn_index(codec, mux, nid, 0)
622 /* standard mic auto-switch helper */
623 static void alc_mic_automute(struct hda_codec *codec)
625 struct alc_spec *spec = codec->spec;
626 hda_nid_t *pins = spec->imux_pins;
628 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
630 if (snd_BUG_ON(!spec->adc_nids))
632 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
635 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
636 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
637 else if (spec->dock_mic_idx >= 0 &&
638 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
639 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
641 alc_mux_select(codec, 0, spec->int_mic_idx, false);
644 /* handle the specified unsol action (ALC_XXX_EVENT) */
645 static void alc_exec_unsol_event(struct hda_codec *codec, int action)
649 alc_hp_automute(codec);
651 case ALC_FRONT_EVENT:
652 alc_line_automute(codec);
655 alc_mic_automute(codec);
658 snd_hda_jack_report_sync(codec);
661 /* update the master volume per volume-knob's unsol event */
662 static void alc_update_knob_master(struct hda_codec *codec, hda_nid_t nid)
665 struct snd_kcontrol *kctl;
666 struct snd_ctl_elem_value *uctl;
668 kctl = snd_hda_find_mixer_ctl(codec, "Master Playback Volume");
671 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
674 val = snd_hda_codec_read(codec, nid, 0,
675 AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
676 val &= HDA_AMP_VOLMASK;
677 uctl->value.integer.value[0] = val;
678 uctl->value.integer.value[1] = val;
679 kctl->put(kctl, uctl);
683 /* unsolicited event for HP jack sensing */
684 static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
688 if (codec->vendor_id == 0x10ec0880)
692 action = snd_hda_jack_get_action(codec, res);
693 if (action == ALC_DCVOL_EVENT) {
694 /* Execute the dc-vol event here as it requires the NID
695 * but we don't pass NID to alc_exec_unsol_event().
696 * Once when we convert all static quirks to the auto-parser,
697 * this can be integerated into there.
699 struct hda_jack_tbl *jack;
700 jack = snd_hda_jack_tbl_get_from_tag(codec, res);
702 alc_update_knob_master(codec, jack->nid);
705 alc_exec_unsol_event(codec, action);
708 /* call init functions of standard auto-mute helpers */
709 static void alc_inithook(struct hda_codec *codec)
711 alc_hp_automute(codec);
712 alc_line_automute(codec);
713 alc_mic_automute(codec);
716 /* additional initialization for ALC888 variants */
717 static void alc888_coef_init(struct hda_codec *codec)
721 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
722 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
723 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
724 if ((tmp & 0xf0) == 0x20)
726 snd_hda_codec_read(codec, 0x20, 0,
727 AC_VERB_SET_PROC_COEF, 0x830);
730 snd_hda_codec_read(codec, 0x20, 0,
731 AC_VERB_SET_PROC_COEF, 0x3030);
734 /* additional initialization for ALC889 variants */
735 static void alc889_coef_init(struct hda_codec *codec)
739 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
740 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
741 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
742 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
745 /* turn on/off EAPD control (only if available) */
746 static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
748 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
750 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
751 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
755 /* turn on/off EAPD controls of the codec */
756 static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
758 /* We currently only handle front, HP */
759 static hda_nid_t pins[] = {
760 0x0f, 0x10, 0x14, 0x15, 0
763 for (p = pins; *p; p++)
764 set_eapd(codec, *p, on);
767 /* generic shutup callback;
768 * just turning off EPAD and a little pause for avoiding pop-noise
770 static void alc_eapd_shutup(struct hda_codec *codec)
772 alc_auto_setup_eapd(codec, false);
776 /* generic EAPD initialization */
777 static void alc_auto_init_amp(struct hda_codec *codec, int type)
781 alc_auto_setup_eapd(codec, true);
784 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
787 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
790 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
792 case ALC_INIT_DEFAULT:
793 switch (codec->vendor_id) {
795 snd_hda_codec_write(codec, 0x1a, 0,
796 AC_VERB_SET_COEF_INDEX, 7);
797 tmp = snd_hda_codec_read(codec, 0x1a, 0,
798 AC_VERB_GET_PROC_COEF, 0);
799 snd_hda_codec_write(codec, 0x1a, 0,
800 AC_VERB_SET_COEF_INDEX, 7);
801 snd_hda_codec_write(codec, 0x1a, 0,
802 AC_VERB_SET_PROC_COEF,
811 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
812 alc889_coef_init(codec);
815 alc888_coef_init(codec);
817 #if 0 /* XXX: This may cause the silent output on speaker on some machines */
820 snd_hda_codec_write(codec, 0x20, 0,
821 AC_VERB_SET_COEF_INDEX, 7);
822 tmp = snd_hda_codec_read(codec, 0x20, 0,
823 AC_VERB_GET_PROC_COEF, 0);
824 snd_hda_codec_write(codec, 0x20, 0,
825 AC_VERB_SET_COEF_INDEX, 7);
826 snd_hda_codec_write(codec, 0x20, 0,
827 AC_VERB_SET_PROC_COEF,
837 * Auto-Mute mode mixer enum support
839 static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
840 struct snd_ctl_elem_info *uinfo)
842 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
843 struct alc_spec *spec = codec->spec;
844 static const char * const texts2[] = {
845 "Disabled", "Enabled"
847 static const char * const texts3[] = {
848 "Disabled", "Speaker Only", "Line Out+Speaker"
850 const char * const *texts;
852 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
854 if (spec->automute_speaker_possible && spec->automute_lo_possible) {
855 uinfo->value.enumerated.items = 3;
858 uinfo->value.enumerated.items = 2;
861 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
862 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
863 strcpy(uinfo->value.enumerated.name,
864 texts[uinfo->value.enumerated.item]);
868 static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
869 struct snd_ctl_elem_value *ucontrol)
871 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
872 struct alc_spec *spec = codec->spec;
873 unsigned int val = 0;
874 if (spec->automute_speaker)
876 if (spec->automute_lo)
879 ucontrol->value.enumerated.item[0] = val;
883 static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
884 struct snd_ctl_elem_value *ucontrol)
886 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
887 struct alc_spec *spec = codec->spec;
889 switch (ucontrol->value.enumerated.item[0]) {
891 if (!spec->automute_speaker && !spec->automute_lo)
893 spec->automute_speaker = 0;
894 spec->automute_lo = 0;
897 if (spec->automute_speaker_possible) {
898 if (!spec->automute_lo && spec->automute_speaker)
900 spec->automute_speaker = 1;
901 spec->automute_lo = 0;
902 } else if (spec->automute_lo_possible) {
903 if (spec->automute_lo)
905 spec->automute_lo = 1;
910 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
912 if (spec->automute_speaker && spec->automute_lo)
914 spec->automute_speaker = 1;
915 spec->automute_lo = 1;
920 call_update_outputs(codec);
924 static const struct snd_kcontrol_new alc_automute_mode_enum = {
925 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
926 .name = "Auto-Mute Mode",
927 .info = alc_automute_mode_info,
928 .get = alc_automute_mode_get,
929 .put = alc_automute_mode_put,
932 static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec)
934 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
935 return snd_array_new(&spec->kctls);
938 static int alc_add_automute_mode_enum(struct hda_codec *codec)
940 struct alc_spec *spec = codec->spec;
941 struct snd_kcontrol_new *knew;
943 knew = alc_kcontrol_new(spec);
946 *knew = alc_automute_mode_enum;
947 knew->name = kstrdup("Auto-Mute Mode", GFP_KERNEL);
954 * Check the availability of HP/line-out auto-mute;
955 * Set up appropriately if really supported
957 static void alc_init_automute(struct hda_codec *codec)
959 struct alc_spec *spec = codec->spec;
960 struct auto_pin_cfg *cfg = &spec->autocfg;
966 if (cfg->line_out_pins[0])
968 if (cfg->speaker_pins[0])
970 if (present < 2) /* need two different output types */
973 if (!cfg->speaker_pins[0] &&
974 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
975 memcpy(cfg->speaker_pins, cfg->line_out_pins,
976 sizeof(cfg->speaker_pins));
977 cfg->speaker_outs = cfg->line_outs;
980 if (!cfg->hp_pins[0] &&
981 cfg->line_out_type == AUTO_PIN_HP_OUT) {
982 memcpy(cfg->hp_pins, cfg->line_out_pins,
983 sizeof(cfg->hp_pins));
984 cfg->hp_outs = cfg->line_outs;
987 spec->automute_mode = ALC_AUTOMUTE_PIN;
989 for (i = 0; i < cfg->hp_outs; i++) {
990 hda_nid_t nid = cfg->hp_pins[i];
991 if (!is_jack_detectable(codec, nid))
993 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
995 snd_hda_jack_detect_enable(codec, nid, ALC_HP_EVENT);
999 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
1000 if (cfg->speaker_outs)
1001 for (i = 0; i < cfg->line_outs; i++) {
1002 hda_nid_t nid = cfg->line_out_pins[i];
1003 if (!is_jack_detectable(codec, nid))
1005 snd_printdd("realtek: Enable Line-Out "
1006 "auto-muting on NID 0x%x\n", nid);
1007 snd_hda_jack_detect_enable(codec, nid,
1009 spec->detect_lo = 1;
1011 spec->automute_lo_possible = spec->detect_hp;
1014 spec->automute_speaker_possible = cfg->speaker_outs &&
1015 (spec->detect_hp || spec->detect_lo);
1017 spec->automute_lo = spec->automute_lo_possible;
1018 spec->automute_speaker = spec->automute_speaker_possible;
1020 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
1021 /* create a control for automute mode */
1022 alc_add_automute_mode_enum(codec);
1023 spec->unsol_event = alc_sku_unsol_event;
1027 /* return the position of NID in the list, or -1 if not found */
1028 static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1031 for (i = 0; i < nums; i++)
1037 /* check whether dynamic ADC-switching is available */
1038 static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
1040 struct alc_spec *spec = codec->spec;
1041 struct hda_input_mux *imux = &spec->private_imux[0];
1045 if (imux != spec->input_mux) /* no dynamic imux? */
1048 for (n = 0; n < spec->num_adc_nids; n++) {
1049 cap = spec->private_capsrc_nids[n];
1050 for (i = 0; i < imux->num_items; i++) {
1051 pin = spec->imux_pins[i];
1054 if (get_connection_index(codec, cap, pin) < 0)
1057 if (i >= imux->num_items)
1058 return true; /* no ADC-switch is needed */
1061 for (i = 0; i < imux->num_items; i++) {
1062 pin = spec->imux_pins[i];
1063 for (n = 0; n < spec->num_adc_nids; n++) {
1064 cap = spec->private_capsrc_nids[n];
1065 idx = get_connection_index(codec, cap, pin);
1067 imux->items[i].index = idx;
1068 spec->dyn_adc_idx[i] = n;
1074 snd_printdd("realtek: enabling ADC switching\n");
1075 spec->dyn_adc_switch = 1;
1079 /* check whether all auto-mic pins are valid; setup indices if OK */
1080 static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1082 struct alc_spec *spec = codec->spec;
1083 const struct hda_input_mux *imux;
1085 if (!spec->auto_mic)
1087 if (spec->auto_mic_valid_imux)
1088 return true; /* already checked */
1090 /* fill up imux indices */
1091 if (!alc_check_dyn_adc_switch(codec)) {
1096 imux = spec->input_mux;
1097 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1098 spec->imux_pins, imux->num_items);
1099 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1100 spec->imux_pins, imux->num_items);
1101 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1102 spec->imux_pins, imux->num_items);
1103 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1105 return false; /* no corresponding imux */
1108 snd_hda_jack_detect_enable(codec, spec->ext_mic_pin, ALC_MIC_EVENT);
1109 if (spec->dock_mic_pin)
1110 snd_hda_jack_detect_enable(codec, spec->dock_mic_pin,
1113 spec->auto_mic_valid_imux = 1;
1119 * Check the availability of auto-mic switch;
1120 * Set up if really supported
1122 static void alc_init_auto_mic(struct hda_codec *codec)
1124 struct alc_spec *spec = codec->spec;
1125 struct auto_pin_cfg *cfg = &spec->autocfg;
1126 hda_nid_t fixed, ext, dock;
1129 if (spec->shared_mic_hp)
1130 return; /* no auto-mic for the shared I/O */
1132 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1134 fixed = ext = dock = 0;
1135 for (i = 0; i < cfg->num_inputs; i++) {
1136 hda_nid_t nid = cfg->inputs[i].pin;
1137 unsigned int defcfg;
1138 defcfg = snd_hda_codec_get_pincfg(codec, nid);
1139 switch (snd_hda_get_input_pin_attr(defcfg)) {
1140 case INPUT_PIN_ATTR_INT:
1142 return; /* already occupied */
1143 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1144 return; /* invalid type */
1147 case INPUT_PIN_ATTR_UNUSED:
1148 return; /* invalid entry */
1149 case INPUT_PIN_ATTR_DOCK:
1151 return; /* already occupied */
1152 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1153 return; /* invalid type */
1158 return; /* already occupied */
1159 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1160 return; /* invalid type */
1171 if (!is_jack_detectable(codec, ext))
1172 return; /* no unsol support */
1173 if (dock && !is_jack_detectable(codec, dock))
1174 return; /* no unsol support */
1176 /* check imux indices */
1177 spec->ext_mic_pin = ext;
1178 spec->int_mic_pin = fixed;
1179 spec->dock_mic_pin = dock;
1182 if (!alc_auto_mic_check_imux(codec))
1185 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1187 spec->unsol_event = alc_sku_unsol_event;
1190 /* check the availabilities of auto-mute and auto-mic switches */
1191 static void alc_auto_check_switches(struct hda_codec *codec)
1193 alc_init_automute(codec);
1194 alc_init_auto_mic(codec);
1198 * Realtek SSID verification
1201 /* Could be any non-zero and even value. When used as fixup, tells
1202 * the driver to ignore any present sku defines.
1204 #define ALC_FIXUP_SKU_IGNORE (2)
1206 static int alc_auto_parse_customize_define(struct hda_codec *codec)
1208 unsigned int ass, tmp, i;
1210 struct alc_spec *spec = codec->spec;
1212 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1214 if (spec->cdefine.fixup) {
1215 ass = spec->cdefine.sku_cfg;
1216 if (ass == ALC_FIXUP_SKU_IGNORE)
1221 ass = codec->subsystem_id & 0xffff;
1222 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
1226 if (codec->vendor_id == 0x10ec0260)
1228 ass = snd_hda_codec_get_pincfg(codec, nid);
1231 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1232 codec->chip_name, ass);
1238 for (i = 1; i < 16; i++) {
1242 if (((ass >> 16) & 0xf) != tmp)
1245 spec->cdefine.port_connectivity = ass >> 30;
1246 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1247 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1248 spec->cdefine.customization = ass >> 8;
1250 spec->cdefine.sku_cfg = ass;
1251 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1252 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1253 spec->cdefine.swap = (ass & 0x2) >> 1;
1254 spec->cdefine.override = ass & 0x1;
1256 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1257 nid, spec->cdefine.sku_cfg);
1258 snd_printd("SKU: port_connectivity=0x%x\n",
1259 spec->cdefine.port_connectivity);
1260 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1261 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1262 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1263 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1264 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1265 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1266 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1271 /* return true if the given NID is found in the list */
1272 static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1274 return find_idx_in_nid_list(nid, list, nums) >= 0;
1277 /* check subsystem ID and set up device-specific initialization;
1278 * return 1 if initialized, 0 if invalid SSID
1280 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1281 * 31 ~ 16 : Manufacture ID
1283 * 7 ~ 0 : Assembly ID
1284 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1286 static int alc_subsystem_id(struct hda_codec *codec,
1287 hda_nid_t porta, hda_nid_t porte,
1288 hda_nid_t portd, hda_nid_t porti)
1290 unsigned int ass, tmp, i;
1292 struct alc_spec *spec = codec->spec;
1294 if (spec->cdefine.fixup) {
1295 ass = spec->cdefine.sku_cfg;
1296 if (ass == ALC_FIXUP_SKU_IGNORE)
1301 ass = codec->subsystem_id & 0xffff;
1302 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1305 /* invalid SSID, check the special NID pin defcfg instead */
1307 * 31~30 : port connectivity
1310 * 19~16 : Check sum (15:1)
1315 if (codec->vendor_id == 0x10ec0260)
1317 ass = snd_hda_codec_get_pincfg(codec, nid);
1318 snd_printd("realtek: No valid SSID, "
1319 "checking pincfg 0x%08x for NID 0x%x\n",
1323 if ((ass >> 30) != 1) /* no physical connection */
1328 for (i = 1; i < 16; i++) {
1332 if (((ass >> 16) & 0xf) != tmp)
1335 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1336 ass & 0xffff, codec->vendor_id);
1340 * 2 : 0 --> Desktop, 1 --> Laptop
1341 * 3~5 : External Amplifier control
1344 tmp = (ass & 0x38) >> 3; /* external Amp control */
1347 spec->init_amp = ALC_INIT_GPIO1;
1350 spec->init_amp = ALC_INIT_GPIO2;
1353 spec->init_amp = ALC_INIT_GPIO3;
1357 spec->init_amp = ALC_INIT_DEFAULT;
1361 /* is laptop or Desktop and enable the function "Mute internal speaker
1362 * when the external headphone out jack is plugged"
1364 if (!(ass & 0x8000))
1367 * 10~8 : Jack location
1368 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1370 * 15 : 1 --> enable the function "Mute internal speaker
1371 * when the external headphone out jack is plugged"
1373 if (!spec->autocfg.hp_pins[0] &&
1374 !(spec->autocfg.line_out_pins[0] &&
1375 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
1377 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1388 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1389 spec->autocfg.line_outs))
1391 spec->autocfg.hp_pins[0] = nid;
1396 /* Check the validity of ALC subsystem-id
1397 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1398 static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
1400 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
1401 struct alc_spec *spec = codec->spec;
1402 snd_printd("realtek: "
1403 "Enable default setup for auto mode as fallback\n");
1404 spec->init_amp = ALC_INIT_DEFAULT;
1409 * Fix-up pin default configurations and add default verbs
1417 struct alc_model_fixup {
1428 const struct alc_pincfg *pins;
1429 const struct hda_verb *verbs;
1430 void (*func)(struct hda_codec *codec,
1431 const struct alc_fixup *fix,
1445 ALC_FIXUP_ACT_PRE_PROBE,
1446 ALC_FIXUP_ACT_PROBE,
1448 ALC_FIXUP_ACT_BUILD,
1451 static void alc_apply_pincfgs(struct hda_codec *codec,
1452 const struct alc_pincfg *cfg)
1454 for (; cfg->nid; cfg++)
1455 snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val);
1458 static void alc_apply_fixup(struct hda_codec *codec, int action)
1460 struct alc_spec *spec = codec->spec;
1461 int id = spec->fixup_id;
1462 #ifdef CONFIG_SND_DEBUG_VERBOSE
1463 const char *modelname = spec->fixup_name;
1467 if (!spec->fixup_list)
1471 const struct alc_fixup *fix = spec->fixup_list + id;
1472 const struct alc_pincfg *cfg;
1474 switch (fix->type) {
1476 if (action != ALC_FIXUP_ACT_PRE_PROBE || !fix->v.sku)
1478 snd_printdd(KERN_INFO "hda_codec: %s: "
1479 "Apply sku override for %s\n",
1480 codec->chip_name, modelname);
1481 spec->cdefine.sku_cfg = fix->v.sku;
1482 spec->cdefine.fixup = 1;
1484 case ALC_FIXUP_PINS:
1486 if (action != ALC_FIXUP_ACT_PRE_PROBE || !cfg)
1488 snd_printdd(KERN_INFO "hda_codec: %s: "
1489 "Apply pincfg for %s\n",
1490 codec->chip_name, modelname);
1491 alc_apply_pincfgs(codec, cfg);
1493 case ALC_FIXUP_VERBS:
1494 if (action != ALC_FIXUP_ACT_PROBE || !fix->v.verbs)
1496 snd_printdd(KERN_INFO "hda_codec: %s: "
1497 "Apply fix-verbs for %s\n",
1498 codec->chip_name, modelname);
1499 add_verb(codec->spec, fix->v.verbs);
1501 case ALC_FIXUP_FUNC:
1504 snd_printdd(KERN_INFO "hda_codec: %s: "
1505 "Apply fix-func for %s\n",
1506 codec->chip_name, modelname);
1507 fix->v.func(codec, fix, action);
1510 snd_printk(KERN_ERR "hda_codec: %s: "
1511 "Invalid fixup type %d\n",
1512 codec->chip_name, fix->type);
1523 static void alc_pick_fixup(struct hda_codec *codec,
1524 const struct alc_model_fixup *models,
1525 const struct snd_pci_quirk *quirk,
1526 const struct alc_fixup *fixlist)
1528 struct alc_spec *spec = codec->spec;
1529 const struct snd_pci_quirk *q;
1531 const char *name = NULL;
1533 /* when model=nofixup is given, don't pick up any fixups */
1534 if (codec->modelname && !strcmp(codec->modelname, "nofixup")) {
1535 spec->fixup_list = NULL;
1536 spec->fixup_id = -1;
1540 if (codec->modelname && models) {
1541 while (models->name) {
1542 if (!strcmp(codec->modelname, models->name)) {
1544 name = models->name;
1551 q = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1554 #ifdef CONFIG_SND_DEBUG_VERBOSE
1560 for (q = quirk; q->subvendor; q++) {
1561 unsigned int vendorid =
1562 q->subdevice | (q->subvendor << 16);
1563 if (vendorid == codec->subsystem_id) {
1565 #ifdef CONFIG_SND_DEBUG_VERBOSE
1573 spec->fixup_id = id;
1575 spec->fixup_list = fixlist;
1576 spec->fixup_name = name;
1581 * COEF access helper functions
1583 static int alc_read_coef_idx(struct hda_codec *codec,
1584 unsigned int coef_idx)
1587 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1589 val = snd_hda_codec_read(codec, 0x20, 0,
1590 AC_VERB_GET_PROC_COEF, 0);
1594 static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1595 unsigned int coef_val)
1597 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1599 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1603 /* a special bypass for COEF 0; read the cached value at the second time */
1604 static unsigned int alc_get_coef0(struct hda_codec *codec)
1606 struct alc_spec *spec = codec->spec;
1608 spec->coef0 = alc_read_coef_idx(codec, 0);
1613 * Digital I/O handling
1616 /* set right pin controls for digital I/O */
1617 static void alc_auto_init_digital(struct hda_codec *codec)
1619 struct alc_spec *spec = codec->spec;
1623 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1624 pin = spec->autocfg.dig_out_pins[i];
1627 snd_hda_codec_write(codec, pin, 0,
1628 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
1630 dac = spec->multiout.dig_out_nid;
1632 dac = spec->slave_dig_outs[i - 1];
1633 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
1635 snd_hda_codec_write(codec, dac, 0,
1636 AC_VERB_SET_AMP_GAIN_MUTE,
1639 pin = spec->autocfg.dig_in_pin;
1641 snd_hda_codec_write(codec, pin, 0,
1642 AC_VERB_SET_PIN_WIDGET_CONTROL,
1646 /* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1647 static void alc_auto_parse_digital(struct hda_codec *codec)
1649 struct alc_spec *spec = codec->spec;
1653 /* support multiple SPDIFs; the secondary is set up as a slave */
1655 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1657 err = snd_hda_get_connections(codec,
1658 spec->autocfg.dig_out_pins[i],
1659 conn, ARRAY_SIZE(conn));
1662 dig_nid = conn[0]; /* assume the first element is audio-out */
1664 spec->multiout.dig_out_nid = dig_nid;
1665 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1667 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
1668 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
1670 spec->slave_dig_outs[nums - 1] = dig_nid;
1675 if (spec->autocfg.dig_in_pin) {
1676 dig_nid = codec->start_nid;
1677 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1678 unsigned int wcaps = get_wcaps(codec, dig_nid);
1679 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1681 if (!(wcaps & AC_WCAP_DIGITAL))
1683 if (!(wcaps & AC_WCAP_CONN_LIST))
1685 err = get_connection_index(codec, dig_nid,
1686 spec->autocfg.dig_in_pin);
1688 spec->dig_in_nid = dig_nid;
1696 * capture mixer elements
1698 static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1699 struct snd_ctl_elem_info *uinfo)
1701 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1702 struct alc_spec *spec = codec->spec;
1706 mutex_lock(&codec->control_mutex);
1707 if (spec->vol_in_capsrc)
1708 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1710 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1711 kcontrol->private_value = val;
1712 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
1713 mutex_unlock(&codec->control_mutex);
1717 static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1718 unsigned int size, unsigned int __user *tlv)
1720 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1721 struct alc_spec *spec = codec->spec;
1725 mutex_lock(&codec->control_mutex);
1726 if (spec->vol_in_capsrc)
1727 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1729 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1730 kcontrol->private_value = val;
1731 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
1732 mutex_unlock(&codec->control_mutex);
1736 typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1737 struct snd_ctl_elem_value *ucontrol);
1739 static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1740 struct snd_ctl_elem_value *ucontrol,
1741 getput_call_t func, bool check_adc_switch)
1743 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1744 struct alc_spec *spec = codec->spec;
1747 mutex_lock(&codec->control_mutex);
1748 if (check_adc_switch && spec->dyn_adc_switch) {
1749 for (i = 0; i < spec->num_adc_nids; i++) {
1750 kcontrol->private_value =
1751 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1753 err = func(kcontrol, ucontrol);
1758 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1759 if (spec->vol_in_capsrc)
1760 kcontrol->private_value =
1761 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1764 kcontrol->private_value =
1765 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1767 err = func(kcontrol, ucontrol);
1770 mutex_unlock(&codec->control_mutex);
1774 static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1775 struct snd_ctl_elem_value *ucontrol)
1777 return alc_cap_getput_caller(kcontrol, ucontrol,
1778 snd_hda_mixer_amp_volume_get, false);
1781 static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1782 struct snd_ctl_elem_value *ucontrol)
1784 return alc_cap_getput_caller(kcontrol, ucontrol,
1785 snd_hda_mixer_amp_volume_put, true);
1788 /* capture mixer elements */
1789 #define alc_cap_sw_info snd_ctl_boolean_stereo_info
1791 static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1792 struct snd_ctl_elem_value *ucontrol)
1794 return alc_cap_getput_caller(kcontrol, ucontrol,
1795 snd_hda_mixer_amp_switch_get, false);
1798 static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1799 struct snd_ctl_elem_value *ucontrol)
1801 return alc_cap_getput_caller(kcontrol, ucontrol,
1802 snd_hda_mixer_amp_switch_put, true);
1805 #define _DEFINE_CAPMIX(num) \
1807 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1808 .name = "Capture Switch", \
1809 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1811 .info = alc_cap_sw_info, \
1812 .get = alc_cap_sw_get, \
1813 .put = alc_cap_sw_put, \
1816 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1817 .name = "Capture Volume", \
1818 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1819 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1820 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1822 .info = alc_cap_vol_info, \
1823 .get = alc_cap_vol_get, \
1824 .put = alc_cap_vol_put, \
1825 .tlv = { .c = alc_cap_vol_tlv }, \
1828 #define _DEFINE_CAPSRC(num) \
1830 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1831 /* .name = "Capture Source", */ \
1832 .name = "Input Source", \
1834 .info = alc_mux_enum_info, \
1835 .get = alc_mux_enum_get, \
1836 .put = alc_mux_enum_put, \
1839 #define DEFINE_CAPMIX(num) \
1840 static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
1841 _DEFINE_CAPMIX(num), \
1842 _DEFINE_CAPSRC(num), \
1846 #define DEFINE_CAPMIX_NOSRC(num) \
1847 static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
1848 _DEFINE_CAPMIX(num), \
1852 /* up to three ADCs */
1856 DEFINE_CAPMIX_NOSRC(1);
1857 DEFINE_CAPMIX_NOSRC(2);
1858 DEFINE_CAPMIX_NOSRC(3);
1861 * virtual master controls
1865 * slave controls for virtual master
1867 static const char * const alc_slave_pfxs[] = {
1868 "Front", "Surround", "Center", "LFE", "Side",
1869 "Headphone", "Speaker", "Mono", "Line Out",
1870 "CLFE", "Bass Speaker", "PCM",
1875 * build control elements
1878 #define NID_MAPPING (-1)
1880 #define SUBDEV_SPEAKER_ (0 << 6)
1881 #define SUBDEV_HP_ (1 << 6)
1882 #define SUBDEV_LINE_ (2 << 6)
1883 #define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1884 #define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1885 #define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1887 static void alc_free_kctls(struct hda_codec *codec);
1889 #ifdef CONFIG_SND_HDA_INPUT_BEEP
1890 /* additional beep mixers; the actual parameters are overwritten at build */
1891 static const struct snd_kcontrol_new alc_beep_mixer[] = {
1892 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
1893 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
1898 static int __alc_build_controls(struct hda_codec *codec)
1900 struct alc_spec *spec = codec->spec;
1901 struct snd_kcontrol *kctl = NULL;
1902 const struct snd_kcontrol_new *knew;
1907 for (i = 0; i < spec->num_mixers; i++) {
1908 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1912 if (spec->cap_mixer) {
1913 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1917 if (spec->multiout.dig_out_nid) {
1918 err = snd_hda_create_spdif_out_ctls(codec,
1919 spec->multiout.dig_out_nid,
1920 spec->multiout.dig_out_nid);
1923 if (!spec->no_analog) {
1924 err = snd_hda_create_spdif_share_sw(codec,
1928 spec->multiout.share_spdif = 1;
1931 if (spec->dig_in_nid) {
1932 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1937 #ifdef CONFIG_SND_HDA_INPUT_BEEP
1938 /* create beep controls if needed */
1939 if (spec->beep_amp) {
1940 const struct snd_kcontrol_new *knew;
1941 for (knew = alc_beep_mixer; knew->name; knew++) {
1942 struct snd_kcontrol *kctl;
1943 kctl = snd_ctl_new1(knew, codec);
1946 kctl->private_value = spec->beep_amp;
1947 err = snd_hda_ctl_add(codec, 0, kctl);
1954 /* if we have no master control, let's create it */
1955 if (!spec->no_analog &&
1956 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1957 unsigned int vmaster_tlv[4];
1958 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
1959 HDA_OUTPUT, vmaster_tlv);
1960 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1961 vmaster_tlv, alc_slave_pfxs,
1966 if (!spec->no_analog &&
1967 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1968 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
1969 NULL, alc_slave_pfxs,
1971 true, &spec->vmaster_mute.sw_kctl);
1976 /* assign Capture Source enums to NID */
1977 if (spec->capsrc_nids || spec->adc_nids) {
1978 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
1980 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1981 for (i = 0; kctl && i < kctl->count; i++) {
1982 err = snd_hda_add_nid(codec, kctl, i,
1983 get_capsrc(spec, i));
1988 if (spec->cap_mixer && spec->adc_nids) {
1989 const char *kname = kctl ? kctl->id.name : NULL;
1990 for (knew = spec->cap_mixer; knew->name; knew++) {
1991 if (kname && strcmp(knew->name, kname) == 0)
1993 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1994 for (i = 0; kctl && i < kctl->count; i++) {
1995 err = snd_hda_add_nid(codec, kctl, i,
2003 /* other nid->control mapping */
2004 for (i = 0; i < spec->num_mixers; i++) {
2005 for (knew = spec->mixers[i]; knew->name; knew++) {
2006 if (knew->iface != NID_MAPPING)
2008 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
2011 u = knew->subdevice;
2012 for (j = 0; j < 4; j++, u >>= 8) {
2017 case SUBDEV_SPEAKER_:
2018 nid = spec->autocfg.speaker_pins[nid];
2021 nid = spec->autocfg.line_out_pins[nid];
2024 nid = spec->autocfg.hp_pins[nid];
2029 err = snd_hda_add_nid(codec, kctl, 0, nid);
2033 u = knew->private_value;
2034 for (j = 0; j < 4; j++, u >>= 8) {
2038 err = snd_hda_add_nid(codec, kctl, 0, nid);
2045 alc_free_kctls(codec); /* no longer needed */
2050 static int alc_build_controls(struct hda_codec *codec)
2052 struct alc_spec *spec = codec->spec;
2053 int err = __alc_build_controls(codec);
2056 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
2059 alc_apply_fixup(codec, ALC_FIXUP_ACT_BUILD);
2068 static void alc_init_special_input_src(struct hda_codec *codec);
2069 static void alc_auto_init_std(struct hda_codec *codec);
2071 static int alc_init(struct hda_codec *codec)
2073 struct alc_spec *spec = codec->spec;
2076 if (spec->init_hook)
2077 spec->init_hook(codec);
2080 alc_auto_init_amp(codec, spec->init_amp);
2082 for (i = 0; i < spec->num_init_verbs; i++)
2083 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2084 alc_init_special_input_src(codec);
2085 alc_auto_init_std(codec);
2087 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2089 snd_hda_jack_report_sync(codec);
2091 hda_call_check_power_status(codec, 0x01);
2095 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2097 struct alc_spec *spec = codec->spec;
2099 if (spec->unsol_event)
2100 spec->unsol_event(codec, res);
2103 #ifdef CONFIG_SND_HDA_POWER_SAVE
2104 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2106 struct alc_spec *spec = codec->spec;
2107 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2112 * Analog playback callbacks
2114 static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
2115 struct hda_codec *codec,
2116 struct snd_pcm_substream *substream)
2118 struct alc_spec *spec = codec->spec;
2119 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2123 static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2124 struct hda_codec *codec,
2125 unsigned int stream_tag,
2126 unsigned int format,
2127 struct snd_pcm_substream *substream)
2129 struct alc_spec *spec = codec->spec;
2130 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2131 stream_tag, format, substream);
2134 static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2135 struct hda_codec *codec,
2136 struct snd_pcm_substream *substream)
2138 struct alc_spec *spec = codec->spec;
2139 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2145 static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2146 struct hda_codec *codec,
2147 struct snd_pcm_substream *substream)
2149 struct alc_spec *spec = codec->spec;
2150 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2153 static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2154 struct hda_codec *codec,
2155 unsigned int stream_tag,
2156 unsigned int format,
2157 struct snd_pcm_substream *substream)
2159 struct alc_spec *spec = codec->spec;
2160 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2161 stream_tag, format, substream);
2164 static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2165 struct hda_codec *codec,
2166 struct snd_pcm_substream *substream)
2168 struct alc_spec *spec = codec->spec;
2169 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2172 static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2173 struct hda_codec *codec,
2174 struct snd_pcm_substream *substream)
2176 struct alc_spec *spec = codec->spec;
2177 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2183 static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2184 struct hda_codec *codec,
2185 unsigned int stream_tag,
2186 unsigned int format,
2187 struct snd_pcm_substream *substream)
2189 struct alc_spec *spec = codec->spec;
2191 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
2192 stream_tag, 0, format);
2196 static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2197 struct hda_codec *codec,
2198 struct snd_pcm_substream *substream)
2200 struct alc_spec *spec = codec->spec;
2202 snd_hda_codec_cleanup_stream(codec,
2203 spec->adc_nids[substream->number + 1]);
2207 /* analog capture with dynamic dual-adc changes */
2208 static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2209 struct hda_codec *codec,
2210 unsigned int stream_tag,
2211 unsigned int format,
2212 struct snd_pcm_substream *substream)
2214 struct alc_spec *spec = codec->spec;
2215 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
2216 spec->cur_adc_stream_tag = stream_tag;
2217 spec->cur_adc_format = format;
2218 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2222 static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2223 struct hda_codec *codec,
2224 struct snd_pcm_substream *substream)
2226 struct alc_spec *spec = codec->spec;
2227 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2232 static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
2236 .nid = 0, /* fill later */
2238 .prepare = dyn_adc_capture_pcm_prepare,
2239 .cleanup = dyn_adc_capture_pcm_cleanup
2245 static const struct hda_pcm_stream alc_pcm_analog_playback = {
2249 /* NID is set in alc_build_pcms */
2251 .open = alc_playback_pcm_open,
2252 .prepare = alc_playback_pcm_prepare,
2253 .cleanup = alc_playback_pcm_cleanup
2257 static const struct hda_pcm_stream alc_pcm_analog_capture = {
2261 /* NID is set in alc_build_pcms */
2264 static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
2268 /* NID is set in alc_build_pcms */
2271 static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
2272 .substreams = 2, /* can be overridden */
2275 /* NID is set in alc_build_pcms */
2277 .prepare = alc_alt_capture_pcm_prepare,
2278 .cleanup = alc_alt_capture_pcm_cleanup
2282 static const struct hda_pcm_stream alc_pcm_digital_playback = {
2286 /* NID is set in alc_build_pcms */
2288 .open = alc_dig_playback_pcm_open,
2289 .close = alc_dig_playback_pcm_close,
2290 .prepare = alc_dig_playback_pcm_prepare,
2291 .cleanup = alc_dig_playback_pcm_cleanup
2295 static const struct hda_pcm_stream alc_pcm_digital_capture = {
2299 /* NID is set in alc_build_pcms */
2302 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
2303 static const struct hda_pcm_stream alc_pcm_null_stream = {
2309 static int alc_build_pcms(struct hda_codec *codec)
2311 struct alc_spec *spec = codec->spec;
2312 struct hda_pcm *info = spec->pcm_rec;
2313 const struct hda_pcm_stream *p;
2314 bool have_multi_adcs;
2317 codec->num_pcms = 1;
2318 codec->pcm_info = info;
2320 if (spec->no_analog)
2323 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2324 "%s Analog", codec->chip_name);
2325 info->name = spec->stream_name_analog;
2327 if (spec->multiout.num_dacs > 0) {
2328 p = spec->stream_analog_playback;
2330 p = &alc_pcm_analog_playback;
2331 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2332 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2334 if (spec->adc_nids) {
2335 p = spec->stream_analog_capture;
2337 if (spec->dyn_adc_switch)
2338 p = &dyn_adc_pcm_analog_capture;
2340 p = &alc_pcm_analog_capture;
2342 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2343 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2346 if (spec->channel_mode) {
2347 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2348 for (i = 0; i < spec->num_channel_mode; i++) {
2349 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2350 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2356 /* SPDIF for stream index #1 */
2357 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2358 snprintf(spec->stream_name_digital,
2359 sizeof(spec->stream_name_digital),
2360 "%s Digital", codec->chip_name);
2361 codec->num_pcms = 2;
2362 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
2363 info = spec->pcm_rec + 1;
2364 info->name = spec->stream_name_digital;
2365 if (spec->dig_out_type)
2366 info->pcm_type = spec->dig_out_type;
2368 info->pcm_type = HDA_PCM_TYPE_SPDIF;
2369 if (spec->multiout.dig_out_nid) {
2370 p = spec->stream_digital_playback;
2372 p = &alc_pcm_digital_playback;
2373 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2374 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2376 if (spec->dig_in_nid) {
2377 p = spec->stream_digital_capture;
2379 p = &alc_pcm_digital_capture;
2380 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2381 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2383 /* FIXME: do we need this for all Realtek codec models? */
2384 codec->spdif_status_reset = 1;
2387 if (spec->no_analog)
2390 /* If the use of more than one ADC is requested for the current
2391 * model, configure a second analog capture-only PCM.
2393 have_multi_adcs = (spec->num_adc_nids > 1) &&
2394 !spec->dyn_adc_switch && !spec->auto_mic &&
2395 (!spec->input_mux || spec->input_mux->num_items > 1);
2396 /* Additional Analaog capture for index #2 */
2397 if (spec->alt_dac_nid || have_multi_adcs) {
2398 codec->num_pcms = 3;
2399 info = spec->pcm_rec + 2;
2400 info->name = spec->stream_name_analog;
2401 if (spec->alt_dac_nid) {
2402 p = spec->stream_analog_alt_playback;
2404 p = &alc_pcm_analog_alt_playback;
2405 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2406 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2409 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2410 alc_pcm_null_stream;
2411 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2413 if (have_multi_adcs) {
2414 p = spec->stream_analog_alt_capture;
2416 p = &alc_pcm_analog_alt_capture;
2417 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2418 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2420 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2421 spec->num_adc_nids - 1;
2423 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2424 alc_pcm_null_stream;
2425 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
2432 static inline void alc_shutup(struct hda_codec *codec)
2434 struct alc_spec *spec = codec->spec;
2436 if (spec && spec->shutup)
2437 spec->shutup(codec);
2438 snd_hda_shutup_pins(codec);
2441 static void alc_free_kctls(struct hda_codec *codec)
2443 struct alc_spec *spec = codec->spec;
2445 if (spec->kctls.list) {
2446 struct snd_kcontrol_new *kctl = spec->kctls.list;
2448 for (i = 0; i < spec->kctls.used; i++)
2449 kfree(kctl[i].name);
2451 snd_array_free(&spec->kctls);
2454 static void alc_free_bind_ctls(struct hda_codec *codec)
2456 struct alc_spec *spec = codec->spec;
2457 if (spec->bind_ctls.list) {
2458 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2460 for (i = 0; i < spec->bind_ctls.used; i++)
2463 snd_array_free(&spec->bind_ctls);
2466 static void alc_free(struct hda_codec *codec)
2468 struct alc_spec *spec = codec->spec;
2474 alc_free_kctls(codec);
2475 alc_free_bind_ctls(codec);
2477 snd_hda_detach_beep_device(codec);
2480 #ifdef CONFIG_SND_HDA_POWER_SAVE
2481 static void alc_power_eapd(struct hda_codec *codec)
2483 alc_auto_setup_eapd(codec, false);
2486 static int alc_suspend(struct hda_codec *codec, pm_message_t state)
2488 struct alc_spec *spec = codec->spec;
2490 if (spec && spec->power_hook)
2491 spec->power_hook(codec);
2497 static int alc_resume(struct hda_codec *codec)
2499 msleep(150); /* to avoid pop noise */
2500 codec->patch_ops.init(codec);
2501 snd_hda_codec_resume_amp(codec);
2502 snd_hda_codec_resume_cache(codec);
2503 hda_call_check_power_status(codec, 0x01);
2510 static const struct hda_codec_ops alc_patch_ops = {
2511 .build_controls = alc_build_controls,
2512 .build_pcms = alc_build_pcms,
2515 .unsol_event = alc_unsol_event,
2517 .resume = alc_resume,
2519 #ifdef CONFIG_SND_HDA_POWER_SAVE
2520 .suspend = alc_suspend,
2521 .check_power_status = alc_check_power_status,
2523 .reboot_notify = alc_shutup,
2526 /* replace the codec chip_name with the given string */
2527 static int alc_codec_rename(struct hda_codec *codec, const char *name)
2529 kfree(codec->chip_name);
2530 codec->chip_name = kstrdup(name, GFP_KERNEL);
2531 if (!codec->chip_name) {
2539 * Rename codecs appropriately from COEF value
2541 struct alc_codec_rename_table {
2542 unsigned int vendor_id;
2543 unsigned short coef_mask;
2544 unsigned short coef_bits;
2548 static struct alc_codec_rename_table rename_tbl[] = {
2549 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2550 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2551 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2552 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2553 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2554 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2555 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
2556 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2557 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2558 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2559 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2560 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2561 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2562 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2563 { } /* terminator */
2566 static int alc_codec_rename_from_preset(struct hda_codec *codec)
2568 const struct alc_codec_rename_table *p;
2570 for (p = rename_tbl; p->vendor_id; p++) {
2571 if (p->vendor_id != codec->vendor_id)
2573 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
2574 return alc_codec_rename(codec, p->name);
2580 * Automatic parse of I/O pins from the BIOS configuration
2585 ALC_CTL_WIDGET_MUTE,
2590 static const struct snd_kcontrol_new alc_control_templates[] = {
2591 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2592 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2593 HDA_BIND_MUTE(NULL, 0, 0, 0),
2594 HDA_BIND_VOL(NULL, 0),
2595 HDA_BIND_SW(NULL, 0),
2598 /* add dynamic controls */
2599 static int add_control(struct alc_spec *spec, int type, const char *name,
2600 int cidx, unsigned long val)
2602 struct snd_kcontrol_new *knew;
2604 knew = alc_kcontrol_new(spec);
2607 *knew = alc_control_templates[type];
2608 knew->name = kstrdup(name, GFP_KERNEL);
2612 if (get_amp_nid_(val))
2613 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
2614 knew->private_value = val;
2618 static int add_control_with_pfx(struct alc_spec *spec, int type,
2619 const char *pfx, const char *dir,
2620 const char *sfx, int cidx, unsigned long val)
2623 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
2624 return add_control(spec, type, name, cidx, val);
2627 #define add_pb_vol_ctrl(spec, type, pfx, val) \
2628 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2629 #define add_pb_sw_ctrl(spec, type, pfx, val) \
2630 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2631 #define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2632 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2633 #define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2634 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
2636 static const char * const channel_name[4] = {
2637 "Front", "Surround", "CLFE", "Side"
2640 static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2641 bool can_be_master, int *index)
2643 struct auto_pin_cfg *cfg = &spec->autocfg;
2646 if (cfg->line_outs == 1 && !spec->multi_ios &&
2647 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
2650 switch (cfg->line_out_type) {
2651 case AUTO_PIN_SPEAKER_OUT:
2652 if (cfg->line_outs == 1)
2654 if (cfg->line_outs == 2)
2655 return ch ? "Bass Speaker" : "Speaker";
2657 case AUTO_PIN_HP_OUT:
2658 /* for multi-io case, only the primary out */
2659 if (ch && spec->multi_ios)
2664 if (cfg->line_outs == 1 && !spec->multi_ios)
2668 if (ch >= ARRAY_SIZE(channel_name)) {
2673 return channel_name[ch];
2676 #ifdef CONFIG_SND_HDA_POWER_SAVE
2677 /* add the powersave loopback-list entry */
2678 static void add_loopback_list(struct alc_spec *spec, hda_nid_t mix, int idx)
2680 struct hda_amp_list *list;
2682 if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
2684 list = spec->loopback_list + spec->num_loopbacks;
2686 list->dir = HDA_INPUT;
2688 spec->num_loopbacks++;
2689 spec->loopback.amplist = spec->loopback_list;
2692 #define add_loopback_list(spec, mix, idx) /* NOP */
2695 /* create input playback/capture controls for the given pin */
2696 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
2697 const char *ctlname, int ctlidx,
2698 int idx, hda_nid_t mix_nid)
2702 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
2703 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2706 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
2707 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2710 add_loopback_list(spec, mix_nid, idx);
2714 static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
2716 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2717 return (pincap & AC_PINCAP_IN) != 0;
2720 /* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
2721 static int alc_auto_fill_adc_caps(struct hda_codec *codec)
2723 struct alc_spec *spec = codec->spec;
2725 hda_nid_t *adc_nids = spec->private_adc_nids;
2726 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2727 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
2730 nid = codec->start_nid;
2731 for (i = 0; i < codec->num_nodes; i++, nid++) {
2733 const hda_nid_t *list;
2734 unsigned int caps = get_wcaps(codec, nid);
2735 int type = get_wcaps_type(caps);
2737 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2739 adc_nids[nums] = nid;
2740 cap_nids[nums] = nid;
2744 type = get_wcaps_type(get_wcaps(codec, src));
2745 if (type == AC_WID_PIN)
2747 if (type == AC_WID_AUD_SEL) {
2748 cap_nids[nums] = src;
2751 n = snd_hda_get_conn_list(codec, src, &list);
2753 cap_nids[nums] = src;
2759 if (++nums >= max_nums)
2762 spec->adc_nids = spec->private_adc_nids;
2763 spec->capsrc_nids = spec->private_capsrc_nids;
2764 spec->num_adc_nids = nums;
2768 /* create playback/capture controls for input pins */
2769 static int alc_auto_create_input_ctls(struct hda_codec *codec)
2771 struct alc_spec *spec = codec->spec;
2772 const struct auto_pin_cfg *cfg = &spec->autocfg;
2773 hda_nid_t mixer = spec->mixer_nid;
2774 struct hda_input_mux *imux = &spec->private_imux[0];
2776 int i, c, err, idx, type_idx = 0;
2777 const char *prev_label = NULL;
2779 num_adcs = alc_auto_fill_adc_caps(codec);
2783 for (i = 0; i < cfg->num_inputs; i++) {
2787 pin = cfg->inputs[i].pin;
2788 if (!alc_is_input_pin(codec, pin))
2791 label = hda_get_autocfg_input_label(codec, cfg, i);
2792 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
2793 label = "Headphone Mic";
2794 if (prev_label && !strcmp(label, prev_label))
2801 idx = get_connection_index(codec, mixer, pin);
2803 err = new_analog_input(spec, pin,
2811 for (c = 0; c < num_adcs; c++) {
2812 hda_nid_t cap = get_capsrc(spec, c);
2813 idx = get_connection_index(codec, cap, pin);
2815 spec->imux_pins[imux->num_items] = pin;
2816 snd_hda_add_imux_item(imux, label, idx, NULL);
2822 spec->num_mux_defs = 1;
2823 spec->input_mux = imux;
2828 /* create a shared input with the headphone out */
2829 static int alc_auto_create_shared_input(struct hda_codec *codec)
2831 struct alc_spec *spec = codec->spec;
2832 struct auto_pin_cfg *cfg = &spec->autocfg;
2833 unsigned int defcfg;
2836 /* only one internal input pin? */
2837 if (cfg->num_inputs != 1)
2839 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2840 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2843 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
2844 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
2845 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
2846 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
2848 return 0; /* both not available */
2850 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2851 return 0; /* no input */
2853 cfg->inputs[1].pin = nid;
2854 cfg->inputs[1].type = AUTO_PIN_MIC;
2855 cfg->num_inputs = 2;
2856 spec->shared_mic_hp = 1;
2857 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
2861 static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
2862 unsigned int pin_type)
2864 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2867 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2868 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2872 static int get_pin_type(int line_out_type)
2874 if (line_out_type == AUTO_PIN_HP_OUT)
2880 static void alc_auto_init_analog_input(struct hda_codec *codec)
2882 struct alc_spec *spec = codec->spec;
2883 struct auto_pin_cfg *cfg = &spec->autocfg;
2886 for (i = 0; i < cfg->num_inputs; i++) {
2887 hda_nid_t nid = cfg->inputs[i].pin;
2888 if (alc_is_input_pin(codec, nid)) {
2889 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
2890 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
2891 snd_hda_codec_write(codec, nid, 0,
2892 AC_VERB_SET_AMP_GAIN_MUTE,
2897 /* mute all loopback inputs */
2898 if (spec->mixer_nid) {
2899 int nums = snd_hda_get_conn_list(codec, spec->mixer_nid, NULL);
2900 for (i = 0; i < nums; i++)
2901 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2902 AC_VERB_SET_AMP_GAIN_MUTE,
2907 /* convert from MIX nid to DAC */
2908 static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid)
2913 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT)
2915 num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list));
2916 for (i = 0; i < num; i++) {
2917 if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT)
2923 /* go down to the selector widget before the mixer */
2924 static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin)
2927 int num = snd_hda_get_connections(codec, pin, srcs,
2930 get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL)
2935 /* get MIX nid connected to the given pin targeted to DAC */
2936 static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
2942 pin = alc_go_down_to_selector(codec, pin);
2943 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2944 for (i = 0; i < num; i++) {
2945 if (alc_auto_mix_to_dac(codec, mix[i]) == dac)
2951 /* select the connection from pin to DAC if needed */
2952 static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin,
2958 pin = alc_go_down_to_selector(codec, pin);
2959 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2962 for (i = 0; i < num; i++) {
2963 if (alc_auto_mix_to_dac(codec, mix[i]) == dac) {
2964 snd_hda_codec_update_cache(codec, pin, 0,
2965 AC_VERB_SET_CONNECT_SEL, i);
2972 static bool alc_is_dac_already_used(struct hda_codec *codec, hda_nid_t nid)
2974 struct alc_spec *spec = codec->spec;
2976 if (found_in_nid_list(nid, spec->multiout.dac_nids,
2977 ARRAY_SIZE(spec->private_dac_nids)) ||
2978 found_in_nid_list(nid, spec->multiout.hp_out_nid,
2979 ARRAY_SIZE(spec->multiout.hp_out_nid)) ||
2980 found_in_nid_list(nid, spec->multiout.extra_out_nid,
2981 ARRAY_SIZE(spec->multiout.extra_out_nid)))
2983 for (i = 0; i < spec->multi_ios; i++) {
2984 if (spec->multi_io[i].dac == nid)
2990 /* look for an empty DAC slot */
2991 static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
2996 pin = alc_go_down_to_selector(codec, pin);
2997 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
2998 for (i = 0; i < num; i++) {
2999 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
3002 if (!alc_is_dac_already_used(codec, nid))
3008 /* check whether the DAC is reachable from the pin */
3009 static bool alc_auto_is_dac_reachable(struct hda_codec *codec,
3010 hda_nid_t pin, hda_nid_t dac)
3017 pin = alc_go_down_to_selector(codec, pin);
3018 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
3019 for (i = 0; i < num; i++) {
3020 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
3027 static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
3029 struct alc_spec *spec = codec->spec;
3030 hda_nid_t sel = alc_go_down_to_selector(codec, pin);
3031 hda_nid_t nid, nid_found, srcs[5];
3032 int i, num = snd_hda_get_connections(codec, sel, srcs,
3035 return alc_auto_look_for_dac(codec, pin);
3037 for (i = 0; i < num; i++) {
3038 if (srcs[i] == spec->mixer_nid)
3040 nid = alc_auto_mix_to_dac(codec, srcs[i]);
3041 if (nid && !alc_is_dac_already_used(codec, nid)) {
3050 /* mark up volume and mute control NIDs: used during badness parsing and
3051 * at creating actual controls
3053 static inline unsigned int get_ctl_pos(unsigned int data)
3055 hda_nid_t nid = get_amp_nid_(data);
3057 if (snd_BUG_ON(nid >= MAX_VOL_NIDS))
3059 dir = get_amp_direction_(data);
3060 return (nid << 1) | dir;
3063 #define is_ctl_used(bits, data) \
3064 test_bit(get_ctl_pos(data), bits)
3065 #define mark_ctl_usage(bits, data) \
3066 set_bit(get_ctl_pos(data), bits)
3068 static void clear_vol_marks(struct hda_codec *codec)
3070 struct alc_spec *spec = codec->spec;
3071 memset(spec->vol_ctls, 0, sizeof(spec->vol_ctls));
3072 memset(spec->sw_ctls, 0, sizeof(spec->sw_ctls));
3075 /* badness definition */
3077 /* No primary DAC is found for the main output */
3078 BAD_NO_PRIMARY_DAC = 0x10000,
3079 /* No DAC is found for the extra output */
3080 BAD_NO_DAC = 0x4000,
3081 /* No possible multi-ios */
3082 BAD_MULTI_IO = 0x103,
3083 /* No individual DAC for extra output */
3084 BAD_NO_EXTRA_DAC = 0x102,
3085 /* No individual DAC for extra surrounds */
3086 BAD_NO_EXTRA_SURR_DAC = 0x101,
3087 /* Primary DAC shared with main surrounds */
3088 BAD_SHARED_SURROUND = 0x100,
3089 /* Primary DAC shared with main CLFE */
3090 BAD_SHARED_CLFE = 0x10,
3091 /* Primary DAC shared with extra surrounds */
3092 BAD_SHARED_EXTRA_SURROUND = 0x10,
3093 /* Volume widget is shared */
3094 BAD_SHARED_VOL = 0x10,
3097 static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3098 hda_nid_t pin, hda_nid_t dac);
3099 static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3100 hda_nid_t pin, hda_nid_t dac);
3102 static int eval_shared_vol_badness(struct hda_codec *codec, hda_nid_t pin,
3105 struct alc_spec *spec = codec->spec;
3110 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3112 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3113 if (is_ctl_used(spec->vol_ctls, nid))
3114 badness += BAD_SHARED_VOL;
3116 mark_ctl_usage(spec->vol_ctls, val);
3118 badness += BAD_SHARED_VOL;
3119 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3121 unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid));
3122 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT)
3123 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3125 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
3126 if (is_ctl_used(spec->sw_ctls, val))
3127 badness += BAD_SHARED_VOL;
3129 mark_ctl_usage(spec->sw_ctls, val);
3131 badness += BAD_SHARED_VOL;
3135 struct badness_table {
3136 int no_primary_dac; /* no primary DAC */
3137 int no_dac; /* no secondary DACs */
3138 int shared_primary; /* primary DAC is shared with main output */
3139 int shared_surr; /* secondary DAC shared with main or primary */
3140 int shared_clfe; /* third DAC shared with main or primary */
3141 int shared_surr_main; /* secondary DAC sahred with main/DAC0 */
3144 static struct badness_table main_out_badness = {
3145 .no_primary_dac = BAD_NO_PRIMARY_DAC,
3146 .no_dac = BAD_NO_DAC,
3147 .shared_primary = BAD_NO_PRIMARY_DAC,
3148 .shared_surr = BAD_SHARED_SURROUND,
3149 .shared_clfe = BAD_SHARED_CLFE,
3150 .shared_surr_main = BAD_SHARED_SURROUND,
3153 static struct badness_table extra_out_badness = {
3154 .no_primary_dac = BAD_NO_DAC,
3155 .no_dac = BAD_NO_DAC,
3156 .shared_primary = BAD_NO_EXTRA_DAC,
3157 .shared_surr = BAD_SHARED_EXTRA_SURROUND,
3158 .shared_clfe = BAD_SHARED_EXTRA_SURROUND,
3159 .shared_surr_main = BAD_NO_EXTRA_SURR_DAC,
3162 /* try to assign DACs to pins and return the resultant badness */
3163 static int alc_auto_fill_dacs(struct hda_codec *codec, int num_outs,
3164 const hda_nid_t *pins, hda_nid_t *dacs,
3165 const struct badness_table *bad)
3167 struct alc_spec *spec = codec->spec;
3168 struct auto_pin_cfg *cfg = &spec->autocfg;
3176 for (i = 0; i < num_outs; i++) {
3177 hda_nid_t pin = pins[i];
3179 dacs[i] = alc_auto_look_for_dac(codec, pin);
3180 if (!dacs[i] && !i) {
3181 for (j = 1; j < num_outs; j++) {
3182 if (alc_auto_is_dac_reachable(codec, pin, dacs[j])) {
3191 if (alc_auto_is_dac_reachable(codec, pin, dacs[0]))
3193 else if (cfg->line_outs > i &&
3194 alc_auto_is_dac_reachable(codec, pin,
3195 spec->private_dac_nids[i]))
3196 dac = spec->private_dac_nids[i];
3199 badness += bad->shared_primary;
3201 badness += bad->shared_surr;
3203 badness += bad->shared_clfe;
3204 } else if (alc_auto_is_dac_reachable(codec, pin,
3205 spec->private_dac_nids[0])) {
3206 dac = spec->private_dac_nids[0];
3207 badness += bad->shared_surr_main;
3209 badness += bad->no_primary_dac;
3211 badness += bad->no_dac;
3214 badness += eval_shared_vol_badness(codec, pin, dac);
3220 static int alc_auto_fill_multi_ios(struct hda_codec *codec,
3221 hda_nid_t reference_pin,
3222 bool hardwired, int offset);
3224 static bool alc_map_singles(struct hda_codec *codec, int outs,
3225 const hda_nid_t *pins, hda_nid_t *dacs)
3229 for (i = 0; i < outs; i++) {
3232 dacs[i] = get_dac_if_single(codec, pins[i]);
3239 /* fill in the dac_nids table from the parsed pin configuration */
3240 static int fill_and_eval_dacs(struct hda_codec *codec,
3241 bool fill_hardwired,
3242 bool fill_mio_first)
3244 struct alc_spec *spec = codec->spec;
3245 struct auto_pin_cfg *cfg = &spec->autocfg;
3246 int i, err, badness;
3248 /* set num_dacs once to full for alc_auto_look_for_dac() */
3249 spec->multiout.num_dacs = cfg->line_outs;
3250 spec->multiout.dac_nids = spec->private_dac_nids;
3251 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
3252 memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid));
3253 memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid));
3254 spec->multi_ios = 0;
3255 clear_vol_marks(codec);
3258 /* fill hard-wired DACs first */
3259 if (fill_hardwired) {
3262 mapped = alc_map_singles(codec, cfg->line_outs,
3264 spec->private_dac_nids);
3265 mapped |= alc_map_singles(codec, cfg->hp_outs,
3267 spec->multiout.hp_out_nid);
3268 mapped |= alc_map_singles(codec, cfg->speaker_outs,
3270 spec->multiout.extra_out_nid);
3271 if (fill_mio_first && cfg->line_outs == 1 &&
3272 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3273 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], true, 0);
3280 badness += alc_auto_fill_dacs(codec, cfg->line_outs, cfg->line_out_pins,
3281 spec->private_dac_nids,
3284 /* re-count num_dacs and squash invalid entries */
3285 spec->multiout.num_dacs = 0;
3286 for (i = 0; i < cfg->line_outs; i++) {
3287 if (spec->private_dac_nids[i])
3288 spec->multiout.num_dacs++;
3290 memmove(spec->private_dac_nids + i,
3291 spec->private_dac_nids + i + 1,
3292 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
3293 spec->private_dac_nids[cfg->line_outs - 1] = 0;
3297 if (fill_mio_first &&
3298 cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3299 /* try to fill multi-io first */
3300 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
3303 /* we don't count badness at this stage yet */
3306 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
3307 err = alc_auto_fill_dacs(codec, cfg->hp_outs, cfg->hp_pins,
3308 spec->multiout.hp_out_nid,
3309 &extra_out_badness);
3314 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3315 err = alc_auto_fill_dacs(codec, cfg->speaker_outs,
3317 spec->multiout.extra_out_nid,
3318 &extra_out_badness);
3323 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3324 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
3329 if (cfg->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3330 /* try multi-ios with HP + inputs */
3332 if (cfg->line_outs >= 3)
3334 err = alc_auto_fill_multi_ios(codec, cfg->hp_pins[0], false,
3341 if (spec->multi_ios == 2) {
3342 for (i = 0; i < 2; i++)
3343 spec->private_dac_nids[spec->multiout.num_dacs++] =
3344 spec->multi_io[i].dac;
3345 spec->ext_channel_count = 2;
3346 } else if (spec->multi_ios) {
3347 spec->multi_ios = 0;
3348 badness += BAD_MULTI_IO;
3354 #define DEBUG_BADNESS
3356 #ifdef DEBUG_BADNESS
3357 #define debug_badness snd_printdd
3359 #define debug_badness(...)
3362 static void debug_show_configs(struct alc_spec *spec, struct auto_pin_cfg *cfg)
3364 debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3365 cfg->line_out_pins[0], cfg->line_out_pins[1],
3366 cfg->line_out_pins[2], cfg->line_out_pins[2],
3367 spec->multiout.dac_nids[0],
3368 spec->multiout.dac_nids[1],
3369 spec->multiout.dac_nids[2],
3370 spec->multiout.dac_nids[3]);
3371 if (spec->multi_ios > 0)
3372 debug_badness("multi_ios(%d) = %x/%x : %x/%x\n",
3374 spec->multi_io[0].pin, spec->multi_io[1].pin,
3375 spec->multi_io[0].dac, spec->multi_io[1].dac);
3376 debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3377 cfg->hp_pins[0], cfg->hp_pins[1],
3378 cfg->hp_pins[2], cfg->hp_pins[2],
3379 spec->multiout.hp_out_nid[0],
3380 spec->multiout.hp_out_nid[1],
3381 spec->multiout.hp_out_nid[2],
3382 spec->multiout.hp_out_nid[3]);
3383 debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3384 cfg->speaker_pins[0], cfg->speaker_pins[1],
3385 cfg->speaker_pins[2], cfg->speaker_pins[3],
3386 spec->multiout.extra_out_nid[0],
3387 spec->multiout.extra_out_nid[1],
3388 spec->multiout.extra_out_nid[2],
3389 spec->multiout.extra_out_nid[3]);
3392 static int alc_auto_fill_dac_nids(struct hda_codec *codec)
3394 struct alc_spec *spec = codec->spec;
3395 struct auto_pin_cfg *cfg = &spec->autocfg;
3396 struct auto_pin_cfg *best_cfg;
3397 int best_badness = INT_MAX;
3399 bool fill_hardwired = true, fill_mio_first = true;
3400 bool best_wired = true, best_mio = true;
3401 bool hp_spk_swapped = false;
3403 best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL);
3409 badness = fill_and_eval_dacs(codec, fill_hardwired,
3415 debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n",
3416 cfg->line_out_type, fill_hardwired, fill_mio_first,
3418 debug_show_configs(spec, cfg);
3419 if (badness < best_badness) {
3420 best_badness = badness;
3422 best_wired = fill_hardwired;
3423 best_mio = fill_mio_first;
3427 fill_mio_first = !fill_mio_first;
3428 if (!fill_mio_first)
3430 fill_hardwired = !fill_hardwired;
3431 if (!fill_hardwired)
3435 hp_spk_swapped = true;
3436 if (cfg->speaker_outs > 0 &&
3437 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3438 cfg->hp_outs = cfg->line_outs;
3439 memcpy(cfg->hp_pins, cfg->line_out_pins,
3440 sizeof(cfg->hp_pins));
3441 cfg->line_outs = cfg->speaker_outs;
3442 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3443 sizeof(cfg->speaker_pins));
3444 cfg->speaker_outs = 0;
3445 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3446 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
3447 fill_hardwired = true;
3450 if (cfg->hp_outs > 0 &&
3451 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3452 cfg->speaker_outs = cfg->line_outs;
3453 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3454 sizeof(cfg->speaker_pins));
3455 cfg->line_outs = cfg->hp_outs;
3456 memcpy(cfg->line_out_pins, cfg->hp_pins,
3457 sizeof(cfg->hp_pins));
3459 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3460 cfg->line_out_type = AUTO_PIN_HP_OUT;
3461 fill_hardwired = true;
3469 fill_and_eval_dacs(codec, best_wired, best_mio);
3471 debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n",
3472 cfg->line_out_type, best_wired, best_mio);
3473 debug_show_configs(spec, cfg);
3475 if (cfg->line_out_pins[0])
3477 alc_look_for_out_vol_nid(codec, cfg->line_out_pins[0],
3478 spec->multiout.dac_nids[0]);
3480 /* clear the bitmap flags for creating controls */
3481 clear_vol_marks(codec);
3486 static int alc_auto_add_vol_ctl(struct hda_codec *codec,
3487 const char *pfx, int cidx,
3488 hda_nid_t nid, unsigned int chs)
3490 struct alc_spec *spec = codec->spec;
3494 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3495 if (is_ctl_used(spec->vol_ctls, val) && chs != 2) /* exclude LFE */
3497 mark_ctl_usage(spec->vol_ctls, val);
3498 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
3502 static int alc_auto_add_stereo_vol(struct hda_codec *codec,
3503 const char *pfx, int cidx,
3507 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3509 return alc_auto_add_vol_ctl(codec, pfx, cidx, nid, chs);
3512 /* create a mute-switch for the given mixer widget;
3513 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3515 static int alc_auto_add_sw_ctl(struct hda_codec *codec,
3516 const char *pfx, int cidx,
3517 hda_nid_t nid, unsigned int chs)
3519 struct alc_spec *spec = codec->spec;
3525 wid_type = get_wcaps_type(get_wcaps(codec, nid));
3526 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) {
3527 type = ALC_CTL_WIDGET_MUTE;
3528 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3529 } else if (snd_hda_get_conn_list(codec, nid, NULL) == 1) {
3530 type = ALC_CTL_WIDGET_MUTE;
3531 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
3533 type = ALC_CTL_BIND_MUTE;
3534 val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
3536 if (is_ctl_used(spec->sw_ctls, val) && chs != 2) /* exclude LFE */
3538 mark_ctl_usage(spec->sw_ctls, val);
3539 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
3542 static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
3543 int cidx, hda_nid_t nid)
3546 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3548 return alc_auto_add_sw_ctl(codec, pfx, cidx, nid, chs);
3551 static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3552 hda_nid_t pin, hda_nid_t dac)
3554 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3555 if (nid_has_mute(codec, pin, HDA_OUTPUT))
3557 else if (mix && nid_has_mute(codec, mix, HDA_INPUT))
3559 else if (nid_has_mute(codec, dac, HDA_OUTPUT))
3564 static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3565 hda_nid_t pin, hda_nid_t dac)
3567 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3568 if (nid_has_volume(codec, dac, HDA_OUTPUT))
3570 else if (nid_has_volume(codec, mix, HDA_OUTPUT))
3572 else if (nid_has_volume(codec, pin, HDA_OUTPUT))
3577 /* add playback controls from the parsed DAC table */
3578 static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
3579 const struct auto_pin_cfg *cfg)
3581 struct alc_spec *spec = codec->spec;
3582 int i, err, noutputs;
3584 noutputs = cfg->line_outs;
3585 if (spec->multi_ios > 0 && cfg->line_outs < 3)
3586 noutputs += spec->multi_ios;
3588 for (i = 0; i < noutputs; i++) {
3594 dac = spec->multiout.dac_nids[i];
3597 if (i >= cfg->line_outs) {
3598 pin = spec->multi_io[i - 1].pin;
3600 name = channel_name[i];
3602 pin = cfg->line_out_pins[i];
3603 name = alc_get_line_out_pfx(spec, i, true, &index);
3606 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3607 vol = alc_look_for_out_vol_nid(codec, pin, dac);
3608 if (!name || !strcmp(name, "CLFE")) {
3610 err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1);
3613 err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2);
3616 err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1);
3619 err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2);
3623 err = alc_auto_add_stereo_vol(codec, name, index, vol);
3626 err = alc_auto_add_stereo_sw(codec, name, index, sw);
3634 static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
3635 hda_nid_t dac, const char *pfx,
3638 struct alc_spec *spec = codec->spec;
3644 /* the corresponding DAC is already occupied */
3645 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
3646 return 0; /* no way */
3647 /* create a switch only */
3648 val = HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT);
3649 if (is_ctl_used(spec->sw_ctls, val))
3650 return 0; /* already created */
3651 mark_ctl_usage(spec->sw_ctls, val);
3652 return __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, cidx, val);
3655 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3656 vol = alc_look_for_out_vol_nid(codec, pin, dac);
3657 err = alc_auto_add_stereo_vol(codec, pfx, cidx, vol);
3660 err = alc_auto_add_stereo_sw(codec, pfx, cidx, sw);
3666 static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3668 struct hda_ctl_ops *ops)
3670 struct alc_spec *spec = codec->spec;
3671 struct hda_bind_ctls **ctlp, *ctl;
3672 snd_array_init(&spec->bind_ctls, sizeof(ctl), 8);
3673 ctlp = snd_array_new(&spec->bind_ctls);
3676 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3683 /* add playback controls for speaker and HP outputs */
3684 static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3685 const hda_nid_t *pins,
3686 const hda_nid_t *dacs,
3689 struct alc_spec *spec = codec->spec;
3690 struct hda_bind_ctls *ctl;
3694 if (!num_pins || !pins[0])
3697 if (num_pins == 1) {
3698 hda_nid_t dac = *dacs;
3700 dac = spec->multiout.dac_nids[0];
3701 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
3704 for (i = 0; i < num_pins; i++) {
3706 if (dacs[num_pins - 1])
3707 dac = dacs[i]; /* with individual volumes */
3710 if (num_pins == 2 && i == 1 && !strcmp(pfx, "Speaker")) {
3711 err = alc_auto_create_extra_out(codec, pins[i], dac,
3713 } else if (num_pins >= 3) {
3714 snprintf(name, sizeof(name), "%s %s",
3715 pfx, channel_name[i]);
3716 err = alc_auto_create_extra_out(codec, pins[i], dac,
3719 err = alc_auto_create_extra_out(codec, pins[i], dac,
3725 if (dacs[num_pins - 1])
3728 /* Let's create a bind-controls for volumes */
3729 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3733 for (i = 0; i < num_pins; i++) {
3735 if (!pins[i] || !dacs[i])
3737 vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]);
3740 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3743 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3744 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3751 static int alc_auto_create_hp_out(struct hda_codec *codec)
3753 struct alc_spec *spec = codec->spec;
3754 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3755 spec->autocfg.hp_pins,
3756 spec->multiout.hp_out_nid,
3760 static int alc_auto_create_speaker_out(struct hda_codec *codec)
3762 struct alc_spec *spec = codec->spec;
3763 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3764 spec->autocfg.speaker_pins,
3765 spec->multiout.extra_out_nid,
3769 static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
3770 hda_nid_t pin, int pin_type,
3774 hda_nid_t nid, mix = 0;
3775 hda_nid_t srcs[HDA_MAX_CONNECTIONS];
3777 alc_set_pin_output(codec, pin, pin_type);
3778 nid = alc_go_down_to_selector(codec, pin);
3779 num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
3780 for (i = 0; i < num; i++) {
3781 if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
3789 /* need the manual connection? */
3791 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
3792 /* unmute mixer widget inputs */
3793 if (nid_has_mute(codec, mix, HDA_INPUT)) {
3794 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3796 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3799 /* initialize volume */
3800 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3802 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3805 /* unmute DAC if it's not assigned to a mixer */
3806 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3807 if (nid == mix && nid_has_mute(codec, dac, HDA_OUTPUT))
3808 snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3812 static void alc_auto_init_multi_out(struct hda_codec *codec)
3814 struct alc_spec *spec = codec->spec;
3815 int pin_type = get_pin_type(spec->autocfg.line_out_type);
3818 for (i = 0; i <= HDA_SIDE; i++) {
3819 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3821 alc_auto_set_output_and_unmute(codec, nid, pin_type,
3822 spec->multiout.dac_nids[i]);
3826 static void alc_auto_init_extra_out(struct hda_codec *codec)
3828 struct alc_spec *spec = codec->spec;
3832 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3833 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3835 pin = spec->autocfg.hp_pins[i];
3838 dac = spec->multiout.hp_out_nid[i];
3840 if (i > 0 && spec->multiout.hp_out_nid[0])
3841 dac = spec->multiout.hp_out_nid[0];
3843 dac = spec->multiout.dac_nids[0];
3845 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
3847 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3848 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3850 pin = spec->autocfg.speaker_pins[i];
3853 dac = spec->multiout.extra_out_nid[i];
3855 if (i > 0 && spec->multiout.extra_out_nid[0])
3856 dac = spec->multiout.extra_out_nid[0];
3858 dac = spec->multiout.dac_nids[0];
3860 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
3864 /* check whether the given pin can be a multi-io pin */
3865 static bool can_be_multiio_pin(struct hda_codec *codec,
3866 unsigned int location, hda_nid_t nid)
3868 unsigned int defcfg, caps;
3870 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3871 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3873 if (location && get_defcfg_location(defcfg) != location)
3875 caps = snd_hda_query_pin_caps(codec, nid);
3876 if (!(caps & AC_PINCAP_OUT))
3884 * When hardwired is set, try to fill ony hardwired pins, and returns
3885 * zero if any pins are filled, non-zero if nothing found.
3886 * When hardwired is off, try to fill possible input pins, and returns
3887 * the badness value.
3889 static int alc_auto_fill_multi_ios(struct hda_codec *codec,
3890 hda_nid_t reference_pin,
3891 bool hardwired, int offset)
3893 struct alc_spec *spec = codec->spec;
3894 struct auto_pin_cfg *cfg = &spec->autocfg;
3895 int type, i, j, dacs, num_pins, old_pins;
3896 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
3897 unsigned int location = get_defcfg_location(defcfg);
3900 old_pins = spec->multi_ios;
3905 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3906 for (i = 0; i < cfg->num_inputs; i++) {
3907 if (cfg->inputs[i].type != type)
3909 if (can_be_multiio_pin(codec, location,
3910 cfg->inputs[i].pin))
3917 dacs = spec->multiout.num_dacs;
3918 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3919 for (i = 0; i < cfg->num_inputs; i++) {
3920 hda_nid_t nid = cfg->inputs[i].pin;
3923 if (cfg->inputs[i].type != type)
3925 if (!can_be_multiio_pin(codec, location, nid))
3927 for (j = 0; j < spec->multi_ios; j++) {
3928 if (nid == spec->multi_io[j].pin)
3931 if (j < spec->multi_ios)
3934 if (offset && offset + spec->multi_ios < dacs) {
3935 dac = spec->private_dac_nids[offset + spec->multi_ios];
3936 if (!alc_auto_is_dac_reachable(codec, nid, dac))
3940 dac = get_dac_if_single(codec, nid);
3942 dac = alc_auto_look_for_dac(codec, nid);
3947 spec->multi_io[spec->multi_ios].pin = nid;
3948 spec->multi_io[spec->multi_ios].dac = dac;
3950 if (spec->multi_ios >= 2)
3956 badness = BAD_MULTI_IO;
3957 if (old_pins == spec->multi_ios) {
3959 return 1; /* nothing found */
3961 return badness; /* no badness if nothing found */
3963 if (!hardwired && spec->multi_ios < 2) {
3964 spec->multi_ios = old_pins;
3971 static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
3972 struct snd_ctl_elem_info *uinfo)
3974 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3975 struct alc_spec *spec = codec->spec;
3977 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3979 uinfo->value.enumerated.items = spec->multi_ios + 1;
3980 if (uinfo->value.enumerated.item > spec->multi_ios)
3981 uinfo->value.enumerated.item = spec->multi_ios;
3982 sprintf(uinfo->value.enumerated.name, "%dch",
3983 (uinfo->value.enumerated.item + 1) * 2);
3987 static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
3988 struct snd_ctl_elem_value *ucontrol)
3990 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3991 struct alc_spec *spec = codec->spec;
3992 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
3996 static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
3998 struct alc_spec *spec = codec->spec;
3999 hda_nid_t nid = spec->multi_io[idx].pin;
4001 if (!spec->multi_io[idx].ctl_in)
4002 spec->multi_io[idx].ctl_in =
4003 snd_hda_codec_read(codec, nid, 0,
4004 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4006 snd_hda_codec_update_cache(codec, nid, 0,
4007 AC_VERB_SET_PIN_WIDGET_CONTROL,
4009 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
4010 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
4012 alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
4014 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
4015 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
4016 HDA_AMP_MUTE, HDA_AMP_MUTE);
4017 snd_hda_codec_update_cache(codec, nid, 0,
4018 AC_VERB_SET_PIN_WIDGET_CONTROL,
4019 spec->multi_io[idx].ctl_in);
4024 static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
4025 struct snd_ctl_elem_value *ucontrol)
4027 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4028 struct alc_spec *spec = codec->spec;
4031 ch = ucontrol->value.enumerated.item[0];
4032 if (ch < 0 || ch > spec->multi_ios)
4034 if (ch == (spec->ext_channel_count - 1) / 2)
4036 spec->ext_channel_count = (ch + 1) * 2;
4037 for (i = 0; i < spec->multi_ios; i++)
4038 alc_set_multi_io(codec, i, i < ch);
4039 spec->multiout.max_channels = spec->ext_channel_count;
4040 if (spec->need_dac_fix && !spec->const_channel_count)
4041 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
4045 static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
4046 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4047 .name = "Channel Mode",
4048 .info = alc_auto_ch_mode_info,
4049 .get = alc_auto_ch_mode_get,
4050 .put = alc_auto_ch_mode_put,
4053 static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
4055 struct alc_spec *spec = codec->spec;
4057 if (spec->multi_ios > 0) {
4058 struct snd_kcontrol_new *knew;
4060 knew = alc_kcontrol_new(spec);
4063 *knew = alc_auto_channel_mode_enum;
4064 knew->name = kstrdup("Channel Mode", GFP_KERNEL);
4071 /* filter out invalid adc_nids (and capsrc_nids) that don't give all
4074 static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
4076 struct alc_spec *spec = codec->spec;
4077 const struct hda_input_mux *imux;
4078 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4079 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4082 imux = spec->input_mux;
4085 if (spec->dyn_adc_switch)
4090 for (n = 0; n < spec->num_adc_nids; n++) {
4091 hda_nid_t cap = spec->private_capsrc_nids[n];
4092 int num_conns = snd_hda_get_conn_list(codec, cap, NULL);
4093 for (i = 0; i < imux->num_items; i++) {
4094 hda_nid_t pin = spec->imux_pins[i];
4096 if (get_connection_index(codec, cap, pin) < 0)
4098 } else if (num_conns <= imux->items[i].index)
4101 if (i >= imux->num_items) {
4102 adc_nids[nums] = spec->private_adc_nids[n];
4103 capsrc_nids[nums++] = cap;
4107 /* check whether ADC-switch is possible */
4108 if (!alc_check_dyn_adc_switch(codec)) {
4109 if (spec->shared_mic_hp) {
4110 spec->shared_mic_hp = 0;
4111 spec->private_imux[0].num_items = 1;
4114 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
4115 " using fallback 0x%x\n",
4116 codec->chip_name, spec->private_adc_nids[0]);
4117 spec->num_adc_nids = 1;
4121 } else if (nums != spec->num_adc_nids) {
4122 memcpy(spec->private_adc_nids, adc_nids,
4123 nums * sizeof(hda_nid_t));
4124 memcpy(spec->private_capsrc_nids, capsrc_nids,
4125 nums * sizeof(hda_nid_t));
4126 spec->num_adc_nids = nums;
4130 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
4131 else if (spec->input_mux->num_items == 1 || spec->shared_mic_hp)
4132 spec->num_adc_nids = 1; /* reduce to a single ADC */
4136 * initialize ADC paths
4138 static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
4140 struct alc_spec *spec = codec->spec;
4143 nid = spec->adc_nids[adc_idx];
4145 if (nid_has_mute(codec, nid, HDA_INPUT)) {
4146 snd_hda_codec_write(codec, nid, 0,
4147 AC_VERB_SET_AMP_GAIN_MUTE,
4151 if (!spec->capsrc_nids)
4153 nid = spec->capsrc_nids[adc_idx];
4154 if (nid_has_mute(codec, nid, HDA_OUTPUT))
4155 snd_hda_codec_write(codec, nid, 0,
4156 AC_VERB_SET_AMP_GAIN_MUTE,
4160 static void alc_auto_init_input_src(struct hda_codec *codec)
4162 struct alc_spec *spec = codec->spec;
4165 for (c = 0; c < spec->num_adc_nids; c++)
4166 alc_auto_init_adc(codec, c);
4167 if (spec->dyn_adc_switch)
4170 nums = spec->num_adc_nids;
4171 for (c = 0; c < nums; c++)
4172 alc_mux_select(codec, c, spec->cur_mux[c], true);
4175 /* add mic boosts if needed */
4176 static int alc_auto_add_mic_boost(struct hda_codec *codec)
4178 struct alc_spec *spec = codec->spec;
4179 struct auto_pin_cfg *cfg = &spec->autocfg;
4183 const char *prev_label = NULL;
4185 for (i = 0; i < cfg->num_inputs; i++) {
4186 if (cfg->inputs[i].type > AUTO_PIN_MIC)
4188 nid = cfg->inputs[i].pin;
4189 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
4191 char boost_label[32];
4193 label = hda_get_autocfg_input_label(codec, cfg, i);
4194 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
4195 label = "Headphone Mic";
4196 if (prev_label && !strcmp(label, prev_label))
4202 snprintf(boost_label, sizeof(boost_label),
4203 "%s Boost Volume", label);
4204 err = add_control(spec, ALC_CTL_WIDGET_VOL,
4205 boost_label, type_idx,
4206 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
4214 /* select or unmute the given capsrc route */
4215 static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
4218 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
4219 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
4221 } else if (snd_hda_get_conn_list(codec, cap, NULL) > 1) {
4222 snd_hda_codec_write_cache(codec, cap, 0,
4223 AC_VERB_SET_CONNECT_SEL, idx);
4227 /* set the default connection to that pin */
4228 static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
4230 struct alc_spec *spec = codec->spec;
4235 for (i = 0; i < spec->num_adc_nids; i++) {
4236 hda_nid_t cap = get_capsrc(spec, i);
4239 idx = get_connection_index(codec, cap, pin);
4242 select_or_unmute_capsrc(codec, cap, idx);
4243 return i; /* return the found index */
4245 return -1; /* not found */
4248 /* initialize some special cases for input sources */
4249 static void alc_init_special_input_src(struct hda_codec *codec)
4251 struct alc_spec *spec = codec->spec;
4254 for (i = 0; i < spec->autocfg.num_inputs; i++)
4255 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
4258 /* assign appropriate capture mixers */
4259 static void set_capture_mixer(struct hda_codec *codec)
4261 struct alc_spec *spec = codec->spec;
4262 static const struct snd_kcontrol_new *caps[2][3] = {
4263 { alc_capture_mixer_nosrc1,
4264 alc_capture_mixer_nosrc2,
4265 alc_capture_mixer_nosrc3 },
4266 { alc_capture_mixer1,
4268 alc_capture_mixer3 },
4271 /* check whether either of ADC or MUX has a volume control */
4272 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
4273 if (!spec->capsrc_nids)
4274 return; /* no volume */
4275 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
4276 return; /* no volume in capsrc, too */
4277 spec->vol_in_capsrc = 1;
4280 if (spec->num_adc_nids > 0) {
4284 if (spec->input_mux && spec->input_mux->num_items > 1)
4286 if (spec->auto_mic) {
4289 } else if (spec->dyn_adc_switch)
4292 if (spec->num_adc_nids > 3)
4293 spec->num_adc_nids = 3;
4294 else if (!spec->num_adc_nids)
4296 num_adcs = spec->num_adc_nids;
4298 spec->cap_mixer = caps[mux][num_adcs - 1];
4303 * standard auto-parser initializations
4305 static void alc_auto_init_std(struct hda_codec *codec)
4307 struct alc_spec *spec = codec->spec;
4308 alc_auto_init_multi_out(codec);
4309 alc_auto_init_extra_out(codec);
4310 alc_auto_init_analog_input(codec);
4311 alc_auto_init_input_src(codec);
4312 alc_auto_init_digital(codec);
4313 if (spec->unsol_event)
4314 alc_inithook(codec);
4318 * Digital-beep handlers
4320 #ifdef CONFIG_SND_HDA_INPUT_BEEP
4321 #define set_beep_amp(spec, nid, idx, dir) \
4322 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4324 static const struct snd_pci_quirk beep_white_list[] = {
4325 SND_PCI_QUIRK(0x1043, 0x103c, "ASUS", 1),
4326 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
4327 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
4328 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
4329 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
4330 SND_PCI_QUIRK(0x1458, 0xa002, "GA-MA790X", 1),
4331 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
4335 static inline int has_cdefine_beep(struct hda_codec *codec)
4337 struct alc_spec *spec = codec->spec;
4338 const struct snd_pci_quirk *q;
4339 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
4342 return spec->cdefine.enable_pcbeep;
4345 #define set_beep_amp(spec, nid, idx, dir) /* NOP */
4346 #define has_cdefine_beep(codec) 0
4349 /* parse the BIOS configuration and set up the alc_spec */
4350 /* return 1 if successful, 0 if the proper config is not found,
4351 * or a negative error code
4353 static int alc_parse_auto_config(struct hda_codec *codec,
4354 const hda_nid_t *ignore_nids,
4355 const hda_nid_t *ssid_nids)
4357 struct alc_spec *spec = codec->spec;
4358 struct auto_pin_cfg *cfg = &spec->autocfg;
4361 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
4365 if (!cfg->line_outs) {
4366 if (cfg->dig_outs || cfg->dig_in_pin) {
4367 spec->multiout.max_channels = 2;
4368 spec->no_analog = 1;
4371 return 0; /* can't find valid BIOS pin config */
4374 if (!spec->no_primary_hp &&
4375 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
4376 cfg->line_outs <= cfg->hp_outs) {
4377 /* use HP as primary out */
4378 cfg->speaker_outs = cfg->line_outs;
4379 memcpy(cfg->speaker_pins, cfg->line_out_pins,
4380 sizeof(cfg->speaker_pins));
4381 cfg->line_outs = cfg->hp_outs;
4382 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
4384 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
4385 cfg->line_out_type = AUTO_PIN_HP_OUT;
4388 err = alc_auto_fill_dac_nids(codec);
4391 err = alc_auto_add_multi_channel_mode(codec);
4394 err = alc_auto_create_multi_out_ctls(codec, cfg);
4397 err = alc_auto_create_hp_out(codec);
4400 err = alc_auto_create_speaker_out(codec);
4403 err = alc_auto_create_shared_input(codec);
4406 err = alc_auto_create_input_ctls(codec);
4410 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4413 alc_auto_parse_digital(codec);
4415 if (!spec->no_analog)
4416 alc_remove_invalid_adc_nids(codec);
4419 alc_ssid_check(codec, ssid_nids);
4421 if (!spec->no_analog) {
4422 alc_auto_check_switches(codec);
4423 err = alc_auto_add_mic_boost(codec);
4428 if (spec->kctls.list)
4429 add_mixer(spec, spec->kctls.list);
4431 if (!spec->no_analog && !spec->cap_mixer)
4432 set_capture_mixer(codec);
4437 static int alc880_parse_auto_config(struct hda_codec *codec)
4439 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
4440 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4441 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
4450 ALC880_FIXUP_MEDION_RIM,
4453 ALC880_FIXUP_EAPD_COEF,
4454 ALC880_FIXUP_TCL_S700,
4455 ALC880_FIXUP_VOL_KNOB,
4456 ALC880_FIXUP_FUJITSU,
4458 ALC880_FIXUP_UNIWILL,
4459 ALC880_FIXUP_UNIWILL_DIG,
4461 ALC880_FIXUP_3ST_BASE,
4463 ALC880_FIXUP_3ST_DIG,
4464 ALC880_FIXUP_5ST_BASE,
4466 ALC880_FIXUP_5ST_DIG,
4467 ALC880_FIXUP_6ST_BASE,
4469 ALC880_FIXUP_6ST_DIG,
4472 /* enable the volume-knob widget support on NID 0x21 */
4473 static void alc880_fixup_vol_knob(struct hda_codec *codec,
4474 const struct alc_fixup *fix, int action)
4476 if (action == ALC_FIXUP_ACT_PROBE)
4477 snd_hda_jack_detect_enable(codec, 0x21, ALC_DCVOL_EVENT);
4480 static const struct alc_fixup alc880_fixups[] = {
4481 [ALC880_FIXUP_GPIO1] = {
4482 .type = ALC_FIXUP_VERBS,
4483 .v.verbs = alc_gpio1_init_verbs,
4485 [ALC880_FIXUP_GPIO2] = {
4486 .type = ALC_FIXUP_VERBS,
4487 .v.verbs = alc_gpio2_init_verbs,
4489 [ALC880_FIXUP_MEDION_RIM] = {
4490 .type = ALC_FIXUP_VERBS,
4491 .v.verbs = (const struct hda_verb[]) {
4492 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4493 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4497 .chain_id = ALC880_FIXUP_GPIO2,
4499 [ALC880_FIXUP_LG] = {
4500 .type = ALC_FIXUP_PINS,
4501 .v.pins = (const struct alc_pincfg[]) {
4502 /* disable bogus unused pins */
4503 { 0x16, 0x411111f0 },
4504 { 0x18, 0x411111f0 },
4505 { 0x1a, 0x411111f0 },
4509 [ALC880_FIXUP_W810] = {
4510 .type = ALC_FIXUP_PINS,
4511 .v.pins = (const struct alc_pincfg[]) {
4512 /* disable bogus unused pins */
4513 { 0x17, 0x411111f0 },
4517 .chain_id = ALC880_FIXUP_GPIO2,
4519 [ALC880_FIXUP_EAPD_COEF] = {
4520 .type = ALC_FIXUP_VERBS,
4521 .v.verbs = (const struct hda_verb[]) {
4522 /* change to EAPD mode */
4523 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4524 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4528 [ALC880_FIXUP_TCL_S700] = {
4529 .type = ALC_FIXUP_VERBS,
4530 .v.verbs = (const struct hda_verb[]) {
4531 /* change to EAPD mode */
4532 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4533 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4537 .chain_id = ALC880_FIXUP_GPIO2,
4539 [ALC880_FIXUP_VOL_KNOB] = {
4540 .type = ALC_FIXUP_FUNC,
4541 .v.func = alc880_fixup_vol_knob,
4543 [ALC880_FIXUP_FUJITSU] = {
4544 /* override all pins as BIOS on old Amilo is broken */
4545 .type = ALC_FIXUP_PINS,
4546 .v.pins = (const struct alc_pincfg[]) {
4547 { 0x14, 0x0121411f }, /* HP */
4548 { 0x15, 0x99030120 }, /* speaker */
4549 { 0x16, 0x99030130 }, /* bass speaker */
4550 { 0x17, 0x411111f0 }, /* N/A */
4551 { 0x18, 0x411111f0 }, /* N/A */
4552 { 0x19, 0x01a19950 }, /* mic-in */
4553 { 0x1a, 0x411111f0 }, /* N/A */
4554 { 0x1b, 0x411111f0 }, /* N/A */
4555 { 0x1c, 0x411111f0 }, /* N/A */
4556 { 0x1d, 0x411111f0 }, /* N/A */
4557 { 0x1e, 0x01454140 }, /* SPDIF out */
4561 .chain_id = ALC880_FIXUP_VOL_KNOB,
4563 [ALC880_FIXUP_F1734] = {
4564 /* almost compatible with FUJITSU, but no bass and SPDIF */
4565 .type = ALC_FIXUP_PINS,
4566 .v.pins = (const struct alc_pincfg[]) {
4567 { 0x14, 0x0121411f }, /* HP */
4568 { 0x15, 0x99030120 }, /* speaker */
4569 { 0x16, 0x411111f0 }, /* N/A */
4570 { 0x17, 0x411111f0 }, /* N/A */
4571 { 0x18, 0x411111f0 }, /* N/A */
4572 { 0x19, 0x01a19950 }, /* mic-in */
4573 { 0x1a, 0x411111f0 }, /* N/A */
4574 { 0x1b, 0x411111f0 }, /* N/A */
4575 { 0x1c, 0x411111f0 }, /* N/A */
4576 { 0x1d, 0x411111f0 }, /* N/A */
4577 { 0x1e, 0x411111f0 }, /* N/A */
4581 .chain_id = ALC880_FIXUP_VOL_KNOB,
4583 [ALC880_FIXUP_UNIWILL] = {
4584 /* need to fix HP and speaker pins to be parsed correctly */
4585 .type = ALC_FIXUP_PINS,
4586 .v.pins = (const struct alc_pincfg[]) {
4587 { 0x14, 0x0121411f }, /* HP */
4588 { 0x15, 0x99030120 }, /* speaker */
4589 { 0x16, 0x99030130 }, /* bass speaker */
4593 [ALC880_FIXUP_UNIWILL_DIG] = {
4594 .type = ALC_FIXUP_PINS,
4595 .v.pins = (const struct alc_pincfg[]) {
4596 /* disable bogus unused pins */
4597 { 0x17, 0x411111f0 },
4598 { 0x19, 0x411111f0 },
4599 { 0x1b, 0x411111f0 },
4600 { 0x1f, 0x411111f0 },
4604 [ALC880_FIXUP_Z71V] = {
4605 .type = ALC_FIXUP_PINS,
4606 .v.pins = (const struct alc_pincfg[]) {
4607 /* set up the whole pins as BIOS is utterly broken */
4608 { 0x14, 0x99030120 }, /* speaker */
4609 { 0x15, 0x0121411f }, /* HP */
4610 { 0x16, 0x411111f0 }, /* N/A */
4611 { 0x17, 0x411111f0 }, /* N/A */
4612 { 0x18, 0x01a19950 }, /* mic-in */
4613 { 0x19, 0x411111f0 }, /* N/A */
4614 { 0x1a, 0x01813031 }, /* line-in */
4615 { 0x1b, 0x411111f0 }, /* N/A */
4616 { 0x1c, 0x411111f0 }, /* N/A */
4617 { 0x1d, 0x411111f0 }, /* N/A */
4618 { 0x1e, 0x0144111e }, /* SPDIF */
4622 [ALC880_FIXUP_3ST_BASE] = {
4623 .type = ALC_FIXUP_PINS,
4624 .v.pins = (const struct alc_pincfg[]) {
4625 { 0x14, 0x01014010 }, /* line-out */
4626 { 0x15, 0x411111f0 }, /* N/A */
4627 { 0x16, 0x411111f0 }, /* N/A */
4628 { 0x17, 0x411111f0 }, /* N/A */
4629 { 0x18, 0x01a19c30 }, /* mic-in */
4630 { 0x19, 0x0121411f }, /* HP */
4631 { 0x1a, 0x01813031 }, /* line-in */
4632 { 0x1b, 0x02a19c40 }, /* front-mic */
4633 { 0x1c, 0x411111f0 }, /* N/A */
4634 { 0x1d, 0x411111f0 }, /* N/A */
4635 /* 0x1e is filled in below */
4636 { 0x1f, 0x411111f0 }, /* N/A */
4640 [ALC880_FIXUP_3ST] = {
4641 .type = ALC_FIXUP_PINS,
4642 .v.pins = (const struct alc_pincfg[]) {
4643 { 0x1e, 0x411111f0 }, /* N/A */
4647 .chain_id = ALC880_FIXUP_3ST_BASE,
4649 [ALC880_FIXUP_3ST_DIG] = {
4650 .type = ALC_FIXUP_PINS,
4651 .v.pins = (const struct alc_pincfg[]) {
4652 { 0x1e, 0x0144111e }, /* SPDIF */
4656 .chain_id = ALC880_FIXUP_3ST_BASE,
4658 [ALC880_FIXUP_5ST_BASE] = {
4659 .type = ALC_FIXUP_PINS,
4660 .v.pins = (const struct alc_pincfg[]) {
4661 { 0x14, 0x01014010 }, /* front */
4662 { 0x15, 0x411111f0 }, /* N/A */
4663 { 0x16, 0x01011411 }, /* CLFE */
4664 { 0x17, 0x01016412 }, /* surr */
4665 { 0x18, 0x01a19c30 }, /* mic-in */
4666 { 0x19, 0x0121411f }, /* HP */
4667 { 0x1a, 0x01813031 }, /* line-in */
4668 { 0x1b, 0x02a19c40 }, /* front-mic */
4669 { 0x1c, 0x411111f0 }, /* N/A */
4670 { 0x1d, 0x411111f0 }, /* N/A */
4671 /* 0x1e is filled in below */
4672 { 0x1f, 0x411111f0 }, /* N/A */
4676 [ALC880_FIXUP_5ST] = {
4677 .type = ALC_FIXUP_PINS,
4678 .v.pins = (const struct alc_pincfg[]) {
4679 { 0x1e, 0x411111f0 }, /* N/A */
4683 .chain_id = ALC880_FIXUP_5ST_BASE,
4685 [ALC880_FIXUP_5ST_DIG] = {
4686 .type = ALC_FIXUP_PINS,
4687 .v.pins = (const struct alc_pincfg[]) {
4688 { 0x1e, 0x0144111e }, /* SPDIF */
4692 .chain_id = ALC880_FIXUP_5ST_BASE,
4694 [ALC880_FIXUP_6ST_BASE] = {
4695 .type = ALC_FIXUP_PINS,
4696 .v.pins = (const struct alc_pincfg[]) {
4697 { 0x14, 0x01014010 }, /* front */
4698 { 0x15, 0x01016412 }, /* surr */
4699 { 0x16, 0x01011411 }, /* CLFE */
4700 { 0x17, 0x01012414 }, /* side */
4701 { 0x18, 0x01a19c30 }, /* mic-in */
4702 { 0x19, 0x02a19c40 }, /* front-mic */
4703 { 0x1a, 0x01813031 }, /* line-in */
4704 { 0x1b, 0x0121411f }, /* HP */
4705 { 0x1c, 0x411111f0 }, /* N/A */
4706 { 0x1d, 0x411111f0 }, /* N/A */
4707 /* 0x1e is filled in below */
4708 { 0x1f, 0x411111f0 }, /* N/A */
4712 [ALC880_FIXUP_6ST] = {
4713 .type = ALC_FIXUP_PINS,
4714 .v.pins = (const struct alc_pincfg[]) {
4715 { 0x1e, 0x411111f0 }, /* N/A */
4719 .chain_id = ALC880_FIXUP_6ST_BASE,
4721 [ALC880_FIXUP_6ST_DIG] = {
4722 .type = ALC_FIXUP_PINS,
4723 .v.pins = (const struct alc_pincfg[]) {
4724 { 0x1e, 0x0144111e }, /* SPDIF */
4728 .chain_id = ALC880_FIXUP_6ST_BASE,
4732 static const struct snd_pci_quirk alc880_fixup_tbl[] = {
4733 SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_FIXUP_W810),
4734 SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_FIXUP_Z71V),
4735 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_FIXUP_GPIO1),
4736 SND_PCI_QUIRK(0x1558, 0x5401, "Clevo GPIO2", ALC880_FIXUP_GPIO2),
4737 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo", ALC880_FIXUP_EAPD_COEF),
4738 SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_FIXUP_UNIWILL_DIG),
4739 SND_PCI_QUIRK(0x1584, 0x9054, "Uniwill", ALC880_FIXUP_F1734),
4740 SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_FIXUP_UNIWILL),
4741 SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_FIXUP_VOL_KNOB),
4742 SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_FIXUP_W810),
4743 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
4744 SND_PCI_QUIRK(0x1631, 0xe011, "PB 13201056", ALC880_FIXUP_6ST),
4745 SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_FIXUP_F1734),
4746 SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FIXUP_FUJITSU),
4747 SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_FIXUP_F1734),
4748 SND_PCI_QUIRK(0x1734, 0x10b0, "FSC Amilo Pi1556", ALC880_FIXUP_FUJITSU),
4749 SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_FIXUP_LG),
4750 SND_PCI_QUIRK(0x1854, 0x005f, "LG P1 Express", ALC880_FIXUP_LG),
4751 SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_FIXUP_LG),
4752 SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_FIXUP_TCL_S700),
4754 /* Below is the copied entries from alc880_quirks.c.
4755 * It's not quite sure whether BIOS sets the correct pin-config table
4756 * on these machines, thus they are kept to be compatible with
4757 * the old static quirks. Once when it's confirmed to work without
4758 * these overrides, it'd be better to remove.
4760 SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_FIXUP_5ST_DIG),
4761 SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_FIXUP_6ST),
4762 SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_FIXUP_3ST_DIG),
4763 SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_FIXUP_6ST_DIG),
4764 SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_FIXUP_6ST_DIG),
4765 SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_FIXUP_6ST_DIG),
4766 SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_FIXUP_3ST_DIG),
4767 SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_FIXUP_3ST),
4768 SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_FIXUP_6ST_DIG),
4769 SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_FIXUP_3ST),
4770 SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_FIXUP_3ST),
4771 SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_FIXUP_5ST),
4772 SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_FIXUP_5ST),
4773 SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_FIXUP_5ST),
4774 SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_FIXUP_6ST_DIG),
4775 SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_FIXUP_6ST_DIG),
4776 SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_FIXUP_6ST_DIG),
4777 SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_FIXUP_6ST_DIG),
4778 SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_FIXUP_5ST_DIG),
4779 SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_FIXUP_5ST_DIG),
4780 SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_FIXUP_5ST_DIG),
4781 SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_FIXUP_6ST_DIG), /* broken BIOS */
4782 SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_FIXUP_6ST_DIG),
4783 SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4784 SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4785 SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4786 SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4787 SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4788 SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4789 SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4790 SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4791 SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4792 SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4794 SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_FIXUP_3ST),
4795 SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_FIXUP_5ST_DIG),
4796 SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_FIXUP_6ST_DIG),
4800 static const struct alc_model_fixup alc880_fixup_models[] = {
4801 {.id = ALC880_FIXUP_3ST, .name = "3stack"},
4802 {.id = ALC880_FIXUP_3ST_DIG, .name = "3stack-digout"},
4803 {.id = ALC880_FIXUP_5ST, .name = "5stack"},
4804 {.id = ALC880_FIXUP_5ST_DIG, .name = "5stack-digout"},
4805 {.id = ALC880_FIXUP_6ST, .name = "6stack"},
4806 {.id = ALC880_FIXUP_6ST_DIG, .name = "6stack-digout"},
4812 * OK, here we have finally the patch for ALC880
4814 static int patch_alc880(struct hda_codec *codec)
4816 struct alc_spec *spec;
4819 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4825 spec->mixer_nid = 0x0b;
4826 spec->need_dac_fix = 1;
4828 alc_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl,
4830 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4832 /* automatic parse from the BIOS config */
4833 err = alc880_parse_auto_config(codec);
4837 if (!spec->no_analog) {
4838 err = snd_hda_attach_beep_device(codec, 0x1);
4841 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4844 codec->patch_ops = alc_patch_ops;
4846 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4859 static int alc260_parse_auto_config(struct hda_codec *codec)
4861 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
4862 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
4863 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
4870 ALC260_FIXUP_HP_DC5750,
4871 ALC260_FIXUP_HP_PIN_0F,
4874 ALC260_FIXUP_GPIO1_TOGGLE,
4875 ALC260_FIXUP_REPLACER,
4876 ALC260_FIXUP_HP_B1900,
4880 static void alc260_gpio1_automute(struct hda_codec *codec)
4882 struct alc_spec *spec = codec->spec;
4883 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
4884 spec->hp_jack_present);
4887 static void alc260_fixup_gpio1_toggle(struct hda_codec *codec,
4888 const struct alc_fixup *fix, int action)
4890 struct alc_spec *spec = codec->spec;
4891 if (action == ALC_FIXUP_ACT_PROBE) {
4892 /* although the machine has only one output pin, we need to
4893 * toggle GPIO1 according to the jack state
4895 spec->automute_hook = alc260_gpio1_automute;
4896 spec->detect_hp = 1;
4897 spec->automute_speaker = 1;
4898 spec->autocfg.hp_pins[0] = 0x0f; /* copy it for automute */
4899 snd_hda_jack_detect_enable(codec, 0x0f, ALC_HP_EVENT);
4900 spec->unsol_event = alc_sku_unsol_event;
4901 add_verb(codec->spec, alc_gpio1_init_verbs);
4905 static void alc260_fixup_kn1(struct hda_codec *codec,
4906 const struct alc_fixup *fix, int action)
4908 struct alc_spec *spec = codec->spec;
4909 static const struct alc_pincfg pincfgs[] = {
4910 { 0x0f, 0x02214000 }, /* HP/speaker */
4911 { 0x12, 0x90a60160 }, /* int mic */
4912 { 0x13, 0x02a19000 }, /* ext mic */
4913 { 0x18, 0x01446000 }, /* SPDIF out */
4914 /* disable bogus I/O pins */
4915 { 0x10, 0x411111f0 },
4916 { 0x11, 0x411111f0 },
4917 { 0x14, 0x411111f0 },
4918 { 0x15, 0x411111f0 },
4919 { 0x16, 0x411111f0 },
4920 { 0x17, 0x411111f0 },
4921 { 0x19, 0x411111f0 },
4926 case ALC_FIXUP_ACT_PRE_PROBE:
4927 alc_apply_pincfgs(codec, pincfgs);
4929 case ALC_FIXUP_ACT_PROBE:
4930 spec->init_amp = ALC_INIT_NONE;
4935 static const struct alc_fixup alc260_fixups[] = {
4936 [ALC260_FIXUP_HP_DC5750] = {
4937 .type = ALC_FIXUP_PINS,
4938 .v.pins = (const struct alc_pincfg[]) {
4939 { 0x11, 0x90130110 }, /* speaker */
4943 [ALC260_FIXUP_HP_PIN_0F] = {
4944 .type = ALC_FIXUP_PINS,
4945 .v.pins = (const struct alc_pincfg[]) {
4946 { 0x0f, 0x01214000 }, /* HP */
4950 [ALC260_FIXUP_COEF] = {
4951 .type = ALC_FIXUP_VERBS,
4952 .v.verbs = (const struct hda_verb[]) {
4953 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4954 { 0x20, AC_VERB_SET_PROC_COEF, 0x3040 },
4958 .chain_id = ALC260_FIXUP_HP_PIN_0F,
4960 [ALC260_FIXUP_GPIO1] = {
4961 .type = ALC_FIXUP_VERBS,
4962 .v.verbs = alc_gpio1_init_verbs,
4964 [ALC260_FIXUP_GPIO1_TOGGLE] = {
4965 .type = ALC_FIXUP_FUNC,
4966 .v.func = alc260_fixup_gpio1_toggle,
4968 .chain_id = ALC260_FIXUP_HP_PIN_0F,
4970 [ALC260_FIXUP_REPLACER] = {
4971 .type = ALC_FIXUP_VERBS,
4972 .v.verbs = (const struct hda_verb[]) {
4973 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4974 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4978 .chain_id = ALC260_FIXUP_GPIO1_TOGGLE,
4980 [ALC260_FIXUP_HP_B1900] = {
4981 .type = ALC_FIXUP_FUNC,
4982 .v.func = alc260_fixup_gpio1_toggle,
4984 .chain_id = ALC260_FIXUP_COEF,
4986 [ALC260_FIXUP_KN1] = {
4987 .type = ALC_FIXUP_FUNC,
4988 .v.func = alc260_fixup_kn1,
4992 static const struct snd_pci_quirk alc260_fixup_tbl[] = {
4993 SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_FIXUP_GPIO1),
4994 SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF),
4995 SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1),
4996 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750),
4997 SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900),
4998 SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1),
4999 SND_PCI_QUIRK(0x152d, 0x0729, "Quanta KN1", ALC260_FIXUP_KN1),
5000 SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER),
5001 SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_FIXUP_COEF),
5007 static int patch_alc260(struct hda_codec *codec)
5009 struct alc_spec *spec;
5012 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5018 spec->mixer_nid = 0x07;
5020 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
5021 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5023 /* automatic parse from the BIOS config */
5024 err = alc260_parse_auto_config(codec);
5028 if (!spec->no_analog) {
5029 err = snd_hda_attach_beep_device(codec, 0x1);
5032 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
5035 codec->patch_ops = alc_patch_ops;
5036 spec->shutup = alc_eapd_shutup;
5038 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5049 * ALC882/883/885/888/889 support
5051 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
5052 * configuration. Each pin widget can choose any input DACs and a mixer.
5053 * Each ADC is connected from a mixer of all inputs. This makes possible
5054 * 6-channel independent captures.
5056 * In addition, an independent DAC for the multi-playback (not used in this
5064 ALC882_FIXUP_ABIT_AW9D_MAX,
5065 ALC882_FIXUP_LENOVO_Y530,
5066 ALC882_FIXUP_PB_M5210,
5067 ALC882_FIXUP_ACER_ASPIRE_7736,
5068 ALC882_FIXUP_ASUS_W90V,
5070 ALC889_FIXUP_VAIO_TT,
5071 ALC888_FIXUP_EEE1601,
5074 ALC883_FIXUP_ACER_EAPD,
5079 ALC882_FIXUP_ASUS_W2JC,
5080 ALC882_FIXUP_ACER_ASPIRE_4930G,
5081 ALC882_FIXUP_ACER_ASPIRE_8930G,
5082 ALC882_FIXUP_ASPIRE_8930G_VERBS,
5083 ALC885_FIXUP_MACPRO_GPIO,
5084 ALC889_FIXUP_DAC_ROUTE,
5085 ALC889_FIXUP_MBP_VREF,
5086 ALC889_FIXUP_IMAC91_VREF,
5087 ALC882_FIXUP_NO_PRIMARY_HP,
5090 static void alc889_fixup_coef(struct hda_codec *codec,
5091 const struct alc_fixup *fix, int action)
5093 if (action != ALC_FIXUP_ACT_INIT)
5095 alc889_coef_init(codec);
5098 /* toggle speaker-output according to the hp-jack state */
5099 static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
5101 unsigned int gpiostate, gpiomask, gpiodir;
5103 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
5104 AC_VERB_GET_GPIO_DATA, 0);
5107 gpiostate |= (1 << pin);
5109 gpiostate &= ~(1 << pin);
5111 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
5112 AC_VERB_GET_GPIO_MASK, 0);
5113 gpiomask |= (1 << pin);
5115 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
5116 AC_VERB_GET_GPIO_DIRECTION, 0);
5117 gpiodir |= (1 << pin);
5120 snd_hda_codec_write(codec, codec->afg, 0,
5121 AC_VERB_SET_GPIO_MASK, gpiomask);
5122 snd_hda_codec_write(codec, codec->afg, 0,
5123 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
5127 snd_hda_codec_write(codec, codec->afg, 0,
5128 AC_VERB_SET_GPIO_DATA, gpiostate);
5131 /* set up GPIO at initialization */
5132 static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
5133 const struct alc_fixup *fix, int action)
5135 if (action != ALC_FIXUP_ACT_INIT)
5137 alc882_gpio_mute(codec, 0, 0);
5138 alc882_gpio_mute(codec, 1, 0);
5141 /* Fix the connection of some pins for ALC889:
5142 * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
5143 * work correctly (bko#42740)
5145 static void alc889_fixup_dac_route(struct hda_codec *codec,
5146 const struct alc_fixup *fix, int action)
5148 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
5149 /* fake the connections during parsing the tree */
5150 hda_nid_t conn1[2] = { 0x0c, 0x0d };
5151 hda_nid_t conn2[2] = { 0x0e, 0x0f };
5152 snd_hda_override_conn_list(codec, 0x14, 2, conn1);
5153 snd_hda_override_conn_list(codec, 0x15, 2, conn1);
5154 snd_hda_override_conn_list(codec, 0x18, 2, conn2);
5155 snd_hda_override_conn_list(codec, 0x1a, 2, conn2);
5156 } else if (action == ALC_FIXUP_ACT_PROBE) {
5157 /* restore the connections */
5158 hda_nid_t conn[5] = { 0x0c, 0x0d, 0x0e, 0x0f, 0x26 };
5159 snd_hda_override_conn_list(codec, 0x14, 5, conn);
5160 snd_hda_override_conn_list(codec, 0x15, 5, conn);
5161 snd_hda_override_conn_list(codec, 0x18, 5, conn);
5162 snd_hda_override_conn_list(codec, 0x1a, 5, conn);
5166 /* Set VREF on HP pin */
5167 static void alc889_fixup_mbp_vref(struct hda_codec *codec,
5168 const struct alc_fixup *fix, int action)
5170 struct alc_spec *spec = codec->spec;
5171 static hda_nid_t nids[2] = { 0x14, 0x15 };
5174 if (action != ALC_FIXUP_ACT_INIT)
5176 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5177 unsigned int val = snd_hda_codec_get_pincfg(codec, nids[i]);
5178 if (get_defcfg_device(val) != AC_JACK_HP_OUT)
5180 val = snd_hda_codec_read(codec, nids[i], 0,
5181 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5182 val |= AC_PINCTL_VREF_80;
5183 snd_hda_codec_write(codec, nids[i], 0,
5184 AC_VERB_SET_PIN_WIDGET_CONTROL, val);
5185 spec->keep_vref_in_automute = 1;
5190 /* Set VREF on speaker pins on imac91 */
5191 static void alc889_fixup_imac91_vref(struct hda_codec *codec,
5192 const struct alc_fixup *fix, int action)
5194 struct alc_spec *spec = codec->spec;
5195 static hda_nid_t nids[2] = { 0x18, 0x1a };
5198 if (action != ALC_FIXUP_ACT_INIT)
5200 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5202 val = snd_hda_codec_read(codec, nids[i], 0,
5203 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5204 val |= AC_PINCTL_VREF_50;
5205 snd_hda_codec_write(codec, nids[i], 0,
5206 AC_VERB_SET_PIN_WIDGET_CONTROL, val);
5208 spec->keep_vref_in_automute = 1;
5211 /* Don't take HP output as primary
5212 * strangely, the speaker output doesn't work on VAIO Z through DAC 0x05
5214 static void alc882_fixup_no_primary_hp(struct hda_codec *codec,
5215 const struct alc_fixup *fix, int action)
5217 struct alc_spec *spec = codec->spec;
5218 if (action == ALC_FIXUP_ACT_PRE_PROBE)
5219 spec->no_primary_hp = 1;
5222 static const struct alc_fixup alc882_fixups[] = {
5223 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
5224 .type = ALC_FIXUP_PINS,
5225 .v.pins = (const struct alc_pincfg[]) {
5226 { 0x15, 0x01080104 }, /* side */
5227 { 0x16, 0x01011012 }, /* rear */
5228 { 0x17, 0x01016011 }, /* clfe */
5232 [ALC882_FIXUP_LENOVO_Y530] = {
5233 .type = ALC_FIXUP_PINS,
5234 .v.pins = (const struct alc_pincfg[]) {
5235 { 0x15, 0x99130112 }, /* rear int speakers */
5236 { 0x16, 0x99130111 }, /* subwoofer */
5240 [ALC882_FIXUP_PB_M5210] = {
5241 .type = ALC_FIXUP_VERBS,
5242 .v.verbs = (const struct hda_verb[]) {
5243 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
5247 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
5248 .type = ALC_FIXUP_SKU,
5249 .v.sku = ALC_FIXUP_SKU_IGNORE,
5251 [ALC882_FIXUP_ASUS_W90V] = {
5252 .type = ALC_FIXUP_PINS,
5253 .v.pins = (const struct alc_pincfg[]) {
5254 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
5258 [ALC889_FIXUP_CD] = {
5259 .type = ALC_FIXUP_PINS,
5260 .v.pins = (const struct alc_pincfg[]) {
5261 { 0x1c, 0x993301f0 }, /* CD */
5265 [ALC889_FIXUP_VAIO_TT] = {
5266 .type = ALC_FIXUP_PINS,
5267 .v.pins = (const struct alc_pincfg[]) {
5268 { 0x17, 0x90170111 }, /* hidden surround speaker */
5272 [ALC888_FIXUP_EEE1601] = {
5273 .type = ALC_FIXUP_VERBS,
5274 .v.verbs = (const struct hda_verb[]) {
5275 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5276 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
5280 [ALC882_FIXUP_EAPD] = {
5281 .type = ALC_FIXUP_VERBS,
5282 .v.verbs = (const struct hda_verb[]) {
5283 /* change to EAPD mode */
5284 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5285 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
5289 [ALC883_FIXUP_EAPD] = {
5290 .type = ALC_FIXUP_VERBS,
5291 .v.verbs = (const struct hda_verb[]) {
5292 /* change to EAPD mode */
5293 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5294 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5298 [ALC883_FIXUP_ACER_EAPD] = {
5299 .type = ALC_FIXUP_VERBS,
5300 .v.verbs = (const struct hda_verb[]) {
5301 /* eanable EAPD on Acer laptops */
5302 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5303 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5307 [ALC882_FIXUP_GPIO1] = {
5308 .type = ALC_FIXUP_VERBS,
5309 .v.verbs = alc_gpio1_init_verbs,
5311 [ALC882_FIXUP_GPIO2] = {
5312 .type = ALC_FIXUP_VERBS,
5313 .v.verbs = alc_gpio2_init_verbs,
5315 [ALC882_FIXUP_GPIO3] = {
5316 .type = ALC_FIXUP_VERBS,
5317 .v.verbs = alc_gpio3_init_verbs,
5319 [ALC882_FIXUP_ASUS_W2JC] = {
5320 .type = ALC_FIXUP_VERBS,
5321 .v.verbs = alc_gpio1_init_verbs,
5323 .chain_id = ALC882_FIXUP_EAPD,
5325 [ALC889_FIXUP_COEF] = {
5326 .type = ALC_FIXUP_FUNC,
5327 .v.func = alc889_fixup_coef,
5329 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
5330 .type = ALC_FIXUP_PINS,
5331 .v.pins = (const struct alc_pincfg[]) {
5332 { 0x16, 0x99130111 }, /* CLFE speaker */
5333 { 0x17, 0x99130112 }, /* surround speaker */
5337 .chain_id = ALC882_FIXUP_GPIO1,
5339 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
5340 .type = ALC_FIXUP_PINS,
5341 .v.pins = (const struct alc_pincfg[]) {
5342 { 0x16, 0x99130111 }, /* CLFE speaker */
5343 { 0x1b, 0x99130112 }, /* surround speaker */
5347 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
5349 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
5350 /* additional init verbs for Acer Aspire 8930G */
5351 .type = ALC_FIXUP_VERBS,
5352 .v.verbs = (const struct hda_verb[]) {
5353 /* Enable all DACs */
5354 /* DAC DISABLE/MUTE 1? */
5355 /* setting bits 1-5 disables DAC nids 0x02-0x06
5356 * apparently. Init=0x38 */
5357 { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
5358 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5359 /* DAC DISABLE/MUTE 2? */
5360 /* some bit here disables the other DACs.
5362 { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
5363 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5365 * This laptop has a stereo digital microphone.
5366 * The mics are only 1cm apart which makes the stereo
5367 * useless. However, either the mic or the ALC889
5368 * makes the signal become a difference/sum signal
5369 * instead of standard stereo, which is annoying.
5370 * So instead we flip this bit which makes the
5371 * codec replicate the sum signal to both channels,
5372 * turning it into a normal mono mic.
5374 /* DMIC_CONTROL? Init value = 0x0001 */
5375 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5376 { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
5377 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5378 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5382 .chain_id = ALC882_FIXUP_GPIO1,
5384 [ALC885_FIXUP_MACPRO_GPIO] = {
5385 .type = ALC_FIXUP_FUNC,
5386 .v.func = alc885_fixup_macpro_gpio,
5388 [ALC889_FIXUP_DAC_ROUTE] = {
5389 .type = ALC_FIXUP_FUNC,
5390 .v.func = alc889_fixup_dac_route,
5392 [ALC889_FIXUP_MBP_VREF] = {
5393 .type = ALC_FIXUP_FUNC,
5394 .v.func = alc889_fixup_mbp_vref,
5396 .chain_id = ALC882_FIXUP_GPIO1,
5398 [ALC889_FIXUP_IMAC91_VREF] = {
5399 .type = ALC_FIXUP_FUNC,
5400 .v.func = alc889_fixup_imac91_vref,
5402 .chain_id = ALC882_FIXUP_GPIO1,
5404 [ALC882_FIXUP_NO_PRIMARY_HP] = {
5405 .type = ALC_FIXUP_FUNC,
5406 .v.func = alc882_fixup_no_primary_hp,
5410 static const struct snd_pci_quirk alc882_fixup_tbl[] = {
5411 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
5412 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5413 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
5414 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5415 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
5416 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
5417 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
5418 ALC882_FIXUP_ACER_ASPIRE_4930G),
5419 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
5420 ALC882_FIXUP_ACER_ASPIRE_4930G),
5421 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
5422 ALC882_FIXUP_ACER_ASPIRE_8930G),
5423 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
5424 ALC882_FIXUP_ACER_ASPIRE_8930G),
5425 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
5426 ALC882_FIXUP_ACER_ASPIRE_4930G),
5427 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
5428 ALC882_FIXUP_ACER_ASPIRE_4930G),
5429 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
5430 ALC882_FIXUP_ACER_ASPIRE_4930G),
5431 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
5432 SND_PCI_QUIRK(0x1025, 0x021e, "Acer Aspire 5739G",
5433 ALC882_FIXUP_ACER_ASPIRE_4930G),
5434 SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE),
5435 SND_PCI_QUIRK(0x1025, 0x026b, "Acer Aspire 8940G", ALC882_FIXUP_ACER_ASPIRE_8930G),
5436 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
5437 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
5438 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
5439 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
5440 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
5441 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
5442 SND_PCI_QUIRK(0x104d, 0x905a, "Sony Vaio Z", ALC882_FIXUP_NO_PRIMARY_HP),
5443 SND_PCI_QUIRK(0x104d, 0x9043, "Sony Vaio VGC-LN51JGB", ALC882_FIXUP_NO_PRIMARY_HP),
5445 /* All Apple entries are in codec SSIDs */
5446 SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC889_FIXUP_MBP_VREF),
5447 SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC889_FIXUP_MBP_VREF),
5448 SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
5449 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
5450 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
5451 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
5452 SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC889_FIXUP_MBP_VREF),
5453 SND_PCI_QUIRK(0x106b, 0x3000, "iMac", ALC889_FIXUP_MBP_VREF),
5454 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
5455 SND_PCI_QUIRK(0x106b, 0x3400, "MacBookAir 1,1", ALC889_FIXUP_MBP_VREF),
5456 SND_PCI_QUIRK(0x106b, 0x3500, "MacBookAir 2,1", ALC889_FIXUP_MBP_VREF),
5457 SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889_FIXUP_MBP_VREF),
5458 SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
5459 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
5460 SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC889_FIXUP_IMAC91_VREF),
5461 SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC889_FIXUP_IMAC91_VREF),
5462 SND_PCI_QUIRK(0x106b, 0x4100, "Macmini 3,1", ALC889_FIXUP_IMAC91_VREF),
5463 SND_PCI_QUIRK(0x106b, 0x4200, "Mac Pro 5,1", ALC885_FIXUP_MACPRO_GPIO),
5464 SND_PCI_QUIRK(0x106b, 0x4300, "iMac 9,1", ALC889_FIXUP_IMAC91_VREF),
5465 SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC889_FIXUP_IMAC91_VREF),
5466 SND_PCI_QUIRK(0x106b, 0x4900, "iMac 9,1 Aluminum", ALC889_FIXUP_IMAC91_VREF),
5467 SND_PCI_QUIRK(0x106b, 0x4a00, "Macbook 5,2", ALC889_FIXUP_IMAC91_VREF),
5469 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
5470 SND_PCI_QUIRK(0x1462, 0x7350, "MSI-7350", ALC889_FIXUP_CD),
5471 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
5472 SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte EP45-DS3", ALC889_FIXUP_CD),
5473 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
5474 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
5475 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
5476 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
5477 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
5481 static const struct alc_model_fixup alc882_fixup_models[] = {
5482 {.id = ALC882_FIXUP_ACER_ASPIRE_4930G, .name = "acer-aspire-4930g"},
5483 {.id = ALC882_FIXUP_ACER_ASPIRE_8930G, .name = "acer-aspire-8930g"},
5484 {.id = ALC883_FIXUP_ACER_EAPD, .name = "acer-aspire"},
5485 {.id = ALC882_FIXUP_NO_PRIMARY_HP, .name = "no-primary-hp"},
5490 * BIOS auto configuration
5492 /* almost identical with ALC880 parser... */
5493 static int alc882_parse_auto_config(struct hda_codec *codec)
5495 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
5496 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5497 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
5502 static int patch_alc882(struct hda_codec *codec)
5504 struct alc_spec *spec;
5507 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5513 spec->mixer_nid = 0x0b;
5515 switch (codec->vendor_id) {
5520 /* ALC883 and variants */
5521 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5525 err = alc_codec_rename_from_preset(codec);
5529 alc_pick_fixup(codec, alc882_fixup_models, alc882_fixup_tbl,
5531 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5533 alc_auto_parse_customize_define(codec);
5535 /* automatic parse from the BIOS config */
5536 err = alc882_parse_auto_config(codec);
5540 if (!spec->no_analog && has_cdefine_beep(codec)) {
5541 err = snd_hda_attach_beep_device(codec, 0x1);
5544 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5547 codec->patch_ops = alc_patch_ops;
5549 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5562 static int alc262_parse_auto_config(struct hda_codec *codec)
5564 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
5565 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5566 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
5573 ALC262_FIXUP_FSC_H270,
5574 ALC262_FIXUP_HP_Z200,
5576 ALC262_FIXUP_LENOVO_3000,
5578 ALC262_FIXUP_BENQ_T31,
5581 static const struct alc_fixup alc262_fixups[] = {
5582 [ALC262_FIXUP_FSC_H270] = {
5583 .type = ALC_FIXUP_PINS,
5584 .v.pins = (const struct alc_pincfg[]) {
5585 { 0x14, 0x99130110 }, /* speaker */
5586 { 0x15, 0x0221142f }, /* front HP */
5587 { 0x1b, 0x0121141f }, /* rear HP */
5591 [ALC262_FIXUP_HP_Z200] = {
5592 .type = ALC_FIXUP_PINS,
5593 .v.pins = (const struct alc_pincfg[]) {
5594 { 0x16, 0x99130120 }, /* internal speaker */
5598 [ALC262_FIXUP_TYAN] = {
5599 .type = ALC_FIXUP_PINS,
5600 .v.pins = (const struct alc_pincfg[]) {
5601 { 0x14, 0x1993e1f0 }, /* int AUX */
5605 [ALC262_FIXUP_LENOVO_3000] = {
5606 .type = ALC_FIXUP_VERBS,
5607 .v.verbs = (const struct hda_verb[]) {
5608 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
5612 .chain_id = ALC262_FIXUP_BENQ,
5614 [ALC262_FIXUP_BENQ] = {
5615 .type = ALC_FIXUP_VERBS,
5616 .v.verbs = (const struct hda_verb[]) {
5617 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5618 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5622 [ALC262_FIXUP_BENQ_T31] = {
5623 .type = ALC_FIXUP_VERBS,
5624 .v.verbs = (const struct hda_verb[]) {
5625 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5626 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5632 static const struct snd_pci_quirk alc262_fixup_tbl[] = {
5633 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
5634 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
5635 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
5636 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
5637 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
5638 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
5639 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
5640 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
5647 static int patch_alc262(struct hda_codec *codec)
5649 struct alc_spec *spec;
5652 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5658 spec->mixer_nid = 0x0b;
5661 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
5666 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5667 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
5668 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5669 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
5672 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5674 alc_pick_fixup(codec, NULL, alc262_fixup_tbl, alc262_fixups);
5675 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5677 alc_auto_parse_customize_define(codec);
5679 /* automatic parse from the BIOS config */
5680 err = alc262_parse_auto_config(codec);
5684 if (!spec->no_analog && has_cdefine_beep(codec)) {
5685 err = snd_hda_attach_beep_device(codec, 0x1);
5688 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5691 codec->patch_ops = alc_patch_ops;
5692 spec->shutup = alc_eapd_shutup;
5694 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5706 /* bind Beep switches of both NID 0x0f and 0x10 */
5707 static const struct hda_bind_ctls alc268_bind_beep_sw = {
5708 .ops = &snd_hda_bind_sw,
5710 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
5711 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
5716 static const struct snd_kcontrol_new alc268_beep_mixer[] = {
5717 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
5718 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
5722 /* set PCBEEP vol = 0, mute connections */
5723 static const struct hda_verb alc268_beep_init_verbs[] = {
5724 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5725 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5726 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5731 * BIOS auto configuration
5733 static int alc268_parse_auto_config(struct hda_codec *codec)
5735 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5736 struct alc_spec *spec = codec->spec;
5737 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
5739 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
5740 add_mixer(spec, alc268_beep_mixer);
5741 add_verb(spec, alc268_beep_init_verbs);
5749 static int patch_alc268(struct hda_codec *codec)
5751 struct alc_spec *spec;
5752 int i, has_beep, err;
5754 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5760 /* ALC268 has no aa-loopback mixer */
5762 /* automatic parse from the BIOS config */
5763 err = alc268_parse_auto_config(codec);
5768 for (i = 0; i < spec->num_mixers; i++) {
5769 if (spec->mixers[i] == alc268_beep_mixer) {
5776 err = snd_hda_attach_beep_device(codec, 0x1);
5779 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
5780 /* override the amp caps for beep generator */
5781 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
5782 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
5783 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
5784 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5785 (0 << AC_AMPCAP_MUTE_SHIFT));
5788 codec->patch_ops = alc_patch_ops;
5789 spec->shutup = alc_eapd_shutup;
5801 static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
5805 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5806 /* NID is set in alc_build_pcms */
5808 .open = alc_playback_pcm_open,
5809 .prepare = alc_playback_pcm_prepare,
5810 .cleanup = alc_playback_pcm_cleanup
5814 static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
5818 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5819 /* NID is set in alc_build_pcms */
5822 /* different alc269-variants */
5824 ALC269_TYPE_ALC269VA,
5825 ALC269_TYPE_ALC269VB,
5826 ALC269_TYPE_ALC269VC,
5830 * BIOS auto configuration
5832 static int alc269_parse_auto_config(struct hda_codec *codec)
5834 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
5835 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
5836 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5837 struct alc_spec *spec = codec->spec;
5838 const hda_nid_t *ssids = spec->codec_variant == ALC269_TYPE_ALC269VA ?
5839 alc269va_ssids : alc269_ssids;
5841 return alc_parse_auto_config(codec, alc269_ignore, ssids);
5844 static void alc269_toggle_power_output(struct hda_codec *codec, int power_up)
5846 int val = alc_read_coef_idx(codec, 0x04);
5851 alc_write_coef_idx(codec, 0x04, val);
5854 static void alc269_shutup(struct hda_codec *codec)
5856 if ((alc_get_coef0(codec) & 0x00ff) == 0x017)
5857 alc269_toggle_power_output(codec, 0);
5858 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
5859 alc269_toggle_power_output(codec, 0);
5865 static int alc269_resume(struct hda_codec *codec)
5867 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
5868 alc269_toggle_power_output(codec, 0);
5872 codec->patch_ops.init(codec);
5874 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
5875 alc269_toggle_power_output(codec, 1);
5879 if ((alc_get_coef0(codec) & 0x00ff) == 0x018)
5880 alc269_toggle_power_output(codec, 1);
5882 snd_hda_codec_resume_amp(codec);
5883 snd_hda_codec_resume_cache(codec);
5884 hda_call_check_power_status(codec, 0x01);
5887 #endif /* CONFIG_PM */
5889 static void alc269_fixup_pincfg_no_hp_to_lineout(struct hda_codec *codec,
5890 const struct alc_fixup *fix, int action)
5892 struct alc_spec *spec = codec->spec;
5894 if (action == ALC_FIXUP_ACT_PRE_PROBE)
5895 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
5898 static void alc269_fixup_hweq(struct hda_codec *codec,
5899 const struct alc_fixup *fix, int action)
5903 if (action != ALC_FIXUP_ACT_INIT)
5905 coef = alc_read_coef_idx(codec, 0x1e);
5906 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
5909 static void alc271_fixup_dmic(struct hda_codec *codec,
5910 const struct alc_fixup *fix, int action)
5912 static const struct hda_verb verbs[] = {
5913 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
5914 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
5919 if (strcmp(codec->chip_name, "ALC271X"))
5921 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
5922 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
5923 snd_hda_sequence_write(codec, verbs);
5926 static void alc269_fixup_pcm_44k(struct hda_codec *codec,
5927 const struct alc_fixup *fix, int action)
5929 struct alc_spec *spec = codec->spec;
5931 if (action != ALC_FIXUP_ACT_PROBE)
5934 /* Due to a hardware problem on Lenovo Ideadpad, we need to
5935 * fix the sample rate of analog I/O to 44.1kHz
5937 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
5938 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
5941 static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
5942 const struct alc_fixup *fix, int action)
5946 if (action != ALC_FIXUP_ACT_INIT)
5948 /* The digital-mic unit sends PDM (differential signal) instead of
5949 * the standard PCM, thus you can't record a valid mono stream as is.
5950 * Below is a workaround specific to ALC269 to control the dmic
5951 * signal source as mono.
5953 coef = alc_read_coef_idx(codec, 0x07);
5954 alc_write_coef_idx(codec, 0x07, coef | 0x80);
5957 static void alc269_quanta_automute(struct hda_codec *codec)
5959 update_outputs(codec);
5961 snd_hda_codec_write(codec, 0x20, 0,
5962 AC_VERB_SET_COEF_INDEX, 0x0c);
5963 snd_hda_codec_write(codec, 0x20, 0,
5964 AC_VERB_SET_PROC_COEF, 0x680);
5966 snd_hda_codec_write(codec, 0x20, 0,
5967 AC_VERB_SET_COEF_INDEX, 0x0c);
5968 snd_hda_codec_write(codec, 0x20, 0,
5969 AC_VERB_SET_PROC_COEF, 0x480);
5972 static void alc269_fixup_quanta_mute(struct hda_codec *codec,
5973 const struct alc_fixup *fix, int action)
5975 struct alc_spec *spec = codec->spec;
5976 if (action != ALC_FIXUP_ACT_PROBE)
5978 spec->automute_hook = alc269_quanta_automute;
5981 /* update mute-LED according to the speaker mute state via mic2 VREF pin */
5982 static void alc269_fixup_mic2_mute_hook(void *private_data, int enabled)
5984 struct hda_codec *codec = private_data;
5985 unsigned int pinval = enabled ? 0x20 : 0x24;
5986 snd_hda_codec_update_cache(codec, 0x19, 0,
5987 AC_VERB_SET_PIN_WIDGET_CONTROL,
5991 static void alc269_fixup_mic2_mute(struct hda_codec *codec,
5992 const struct alc_fixup *fix, int action)
5994 struct alc_spec *spec = codec->spec;
5996 case ALC_FIXUP_ACT_BUILD:
5997 spec->vmaster_mute.hook = alc269_fixup_mic2_mute_hook;
5998 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
6000 case ALC_FIXUP_ACT_INIT:
6001 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
6007 ALC269_FIXUP_SONY_VAIO,
6008 ALC275_FIXUP_SONY_VAIO_GPIO2,
6009 ALC269_FIXUP_DELL_M101Z,
6010 ALC269_FIXUP_SKU_IGNORE,
6011 ALC269_FIXUP_ASUS_G73JW,
6012 ALC269_FIXUP_LENOVO_EAPD,
6013 ALC275_FIXUP_SONY_HWEQ,
6015 ALC269_FIXUP_PCM_44K,
6016 ALC269_FIXUP_STEREO_DMIC,
6017 ALC269_FIXUP_QUANTA_MUTE,
6018 ALC269_FIXUP_LIFEBOOK,
6021 ALC269VB_FIXUP_AMIC,
6022 ALC269VB_FIXUP_DMIC,
6023 ALC269_FIXUP_MIC2_MUTE_LED,
6024 ALC269_FIXUP_LENOVO_DOCK,
6025 ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT,
6028 static const struct alc_fixup alc269_fixups[] = {
6029 [ALC269_FIXUP_SONY_VAIO] = {
6030 .type = ALC_FIXUP_VERBS,
6031 .v.verbs = (const struct hda_verb[]) {
6032 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
6036 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
6037 .type = ALC_FIXUP_VERBS,
6038 .v.verbs = (const struct hda_verb[]) {
6039 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
6040 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
6041 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
6045 .chain_id = ALC269_FIXUP_SONY_VAIO
6047 [ALC269_FIXUP_DELL_M101Z] = {
6048 .type = ALC_FIXUP_VERBS,
6049 .v.verbs = (const struct hda_verb[]) {
6050 /* Enables internal speaker */
6051 {0x20, AC_VERB_SET_COEF_INDEX, 13},
6052 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
6056 [ALC269_FIXUP_SKU_IGNORE] = {
6057 .type = ALC_FIXUP_SKU,
6058 .v.sku = ALC_FIXUP_SKU_IGNORE,
6060 [ALC269_FIXUP_ASUS_G73JW] = {
6061 .type = ALC_FIXUP_PINS,
6062 .v.pins = (const struct alc_pincfg[]) {
6063 { 0x17, 0x99130111 }, /* subwoofer */
6067 [ALC269_FIXUP_LENOVO_EAPD] = {
6068 .type = ALC_FIXUP_VERBS,
6069 .v.verbs = (const struct hda_verb[]) {
6070 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6074 [ALC275_FIXUP_SONY_HWEQ] = {
6075 .type = ALC_FIXUP_FUNC,
6076 .v.func = alc269_fixup_hweq,
6078 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
6080 [ALC271_FIXUP_DMIC] = {
6081 .type = ALC_FIXUP_FUNC,
6082 .v.func = alc271_fixup_dmic,
6084 [ALC269_FIXUP_PCM_44K] = {
6085 .type = ALC_FIXUP_FUNC,
6086 .v.func = alc269_fixup_pcm_44k,
6088 .chain_id = ALC269_FIXUP_QUANTA_MUTE
6090 [ALC269_FIXUP_STEREO_DMIC] = {
6091 .type = ALC_FIXUP_FUNC,
6092 .v.func = alc269_fixup_stereo_dmic,
6094 [ALC269_FIXUP_QUANTA_MUTE] = {
6095 .type = ALC_FIXUP_FUNC,
6096 .v.func = alc269_fixup_quanta_mute,
6098 [ALC269_FIXUP_LIFEBOOK] = {
6099 .type = ALC_FIXUP_PINS,
6100 .v.pins = (const struct alc_pincfg[]) {
6101 { 0x1a, 0x2101103f }, /* dock line-out */
6102 { 0x1b, 0x23a11040 }, /* dock mic-in */
6106 .chain_id = ALC269_FIXUP_QUANTA_MUTE
6108 [ALC269_FIXUP_AMIC] = {
6109 .type = ALC_FIXUP_PINS,
6110 .v.pins = (const struct alc_pincfg[]) {
6111 { 0x14, 0x99130110 }, /* speaker */
6112 { 0x15, 0x0121401f }, /* HP out */
6113 { 0x18, 0x01a19c20 }, /* mic */
6114 { 0x19, 0x99a3092f }, /* int-mic */
6118 [ALC269_FIXUP_DMIC] = {
6119 .type = ALC_FIXUP_PINS,
6120 .v.pins = (const struct alc_pincfg[]) {
6121 { 0x12, 0x99a3092f }, /* int-mic */
6122 { 0x14, 0x99130110 }, /* speaker */
6123 { 0x15, 0x0121401f }, /* HP out */
6124 { 0x18, 0x01a19c20 }, /* mic */
6128 [ALC269VB_FIXUP_AMIC] = {
6129 .type = ALC_FIXUP_PINS,
6130 .v.pins = (const struct alc_pincfg[]) {
6131 { 0x14, 0x99130110 }, /* speaker */
6132 { 0x18, 0x01a19c20 }, /* mic */
6133 { 0x19, 0x99a3092f }, /* int-mic */
6134 { 0x21, 0x0121401f }, /* HP out */
6138 [ALC269VB_FIXUP_DMIC] = {
6139 .type = ALC_FIXUP_PINS,
6140 .v.pins = (const struct alc_pincfg[]) {
6141 { 0x12, 0x99a3092f }, /* int-mic */
6142 { 0x14, 0x99130110 }, /* speaker */
6143 { 0x18, 0x01a19c20 }, /* mic */
6144 { 0x21, 0x0121401f }, /* HP out */
6148 [ALC269_FIXUP_MIC2_MUTE_LED] = {
6149 .type = ALC_FIXUP_FUNC,
6150 .v.func = alc269_fixup_mic2_mute,
6152 [ALC269_FIXUP_LENOVO_DOCK] = {
6153 .type = ALC_FIXUP_PINS,
6154 .v.pins = (const struct alc_pincfg[]) {
6155 { 0x19, 0x23a11040 }, /* dock mic */
6156 { 0x1b, 0x2121103f }, /* dock headphone */
6160 .chain_id = ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT
6162 [ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT] = {
6163 .type = ALC_FIXUP_FUNC,
6164 .v.func = alc269_fixup_pincfg_no_hp_to_lineout,
6168 static const struct snd_pci_quirk alc269_fixup_tbl[] = {
6169 SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_MIC2_MUTE_LED),
6170 SND_PCI_QUIRK(0x1043, 0x1427, "Asus Zenbook UX31E", ALC269VB_FIXUP_DMIC),
6171 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
6172 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
6173 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
6174 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
6175 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
6176 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
6177 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
6178 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6179 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6180 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
6181 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
6182 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
6183 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
6184 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
6185 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
6186 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
6187 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
6188 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
6189 SND_PCI_QUIRK(0x17aa, 0x21f6, "Thinkpad T530", ALC269_FIXUP_LENOVO_DOCK),
6190 SND_PCI_QUIRK(0x17aa, 0x21fa, "Thinkpad X230", ALC269_FIXUP_LENOVO_DOCK),
6191 SND_PCI_QUIRK(0x17aa, 0x21f3, "Thinkpad T430", ALC269_FIXUP_LENOVO_DOCK),
6192 SND_PCI_QUIRK(0x17aa, 0x21fb, "Thinkpad T430s", ALC269_FIXUP_LENOVO_DOCK),
6193 SND_PCI_QUIRK(0x17aa, 0x2203, "Thinkpad X230 Tablet", ALC269_FIXUP_LENOVO_DOCK),
6194 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_PCM_44K),
6195 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
6198 /* Below is a quirk table taken from the old code.
6199 * Basically the device should work as is without the fixup table.
6200 * If BIOS doesn't give a proper info, enable the corresponding
6203 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
6205 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
6206 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
6207 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
6208 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
6209 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
6210 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
6211 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
6212 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
6213 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
6214 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
6215 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
6216 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
6217 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
6218 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
6219 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
6220 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
6221 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
6222 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
6223 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
6224 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
6225 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
6226 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
6227 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
6228 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
6229 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
6230 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
6231 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
6232 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
6233 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
6234 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
6235 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
6236 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
6237 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
6238 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
6239 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
6240 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
6241 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
6242 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
6243 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
6248 static const struct alc_model_fixup alc269_fixup_models[] = {
6249 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
6250 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
6251 {.id = ALC269_FIXUP_LENOVO_DOCK, .name = "lenovo-dock"},
6256 static void alc269_fill_coef(struct hda_codec *codec)
6258 struct alc_spec *spec = codec->spec;
6261 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
6264 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
6265 alc_write_coef_idx(codec, 0xf, 0x960b);
6266 alc_write_coef_idx(codec, 0xe, 0x8817);
6269 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
6270 alc_write_coef_idx(codec, 0xf, 0x960b);
6271 alc_write_coef_idx(codec, 0xe, 0x8814);
6274 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
6275 val = alc_read_coef_idx(codec, 0x04);
6276 /* Power up output pin */
6277 alc_write_coef_idx(codec, 0x04, val | (1<<11));
6280 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
6281 val = alc_read_coef_idx(codec, 0xd);
6282 if ((val & 0x0c00) >> 10 != 0x1) {
6283 /* Capless ramp up clock control */
6284 alc_write_coef_idx(codec, 0xd, val | (1<<10));
6286 val = alc_read_coef_idx(codec, 0x17);
6287 if ((val & 0x01c0) >> 6 != 0x4) {
6288 /* Class D power on reset */
6289 alc_write_coef_idx(codec, 0x17, val | (1<<7));
6293 val = alc_read_coef_idx(codec, 0xd); /* Class D */
6294 alc_write_coef_idx(codec, 0xd, val | (1<<14));
6296 val = alc_read_coef_idx(codec, 0x4); /* HP */
6297 alc_write_coef_idx(codec, 0x4, val | (1<<11));
6302 static int patch_alc269(struct hda_codec *codec)
6304 struct alc_spec *spec;
6307 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6313 spec->mixer_nid = 0x0b;
6315 err = alc_codec_rename_from_preset(codec);
6319 alc_pick_fixup(codec, alc269_fixup_models,
6320 alc269_fixup_tbl, alc269_fixups);
6321 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6323 alc_auto_parse_customize_define(codec);
6325 if (codec->vendor_id == 0x10ec0269) {
6326 spec->codec_variant = ALC269_TYPE_ALC269VA;
6327 switch (alc_get_coef0(codec) & 0x00f0) {
6329 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
6330 spec->cdefine.platform_type == 1)
6331 err = alc_codec_rename(codec, "ALC271X");
6332 spec->codec_variant = ALC269_TYPE_ALC269VB;
6335 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
6336 codec->bus->pci->subsystem_device == 0x21f3)
6337 err = alc_codec_rename(codec, "ALC3202");
6338 spec->codec_variant = ALC269_TYPE_ALC269VC;
6341 alc_fix_pll_init(codec, 0x20, 0x04, 15);
6345 spec->init_hook = alc269_fill_coef;
6346 alc269_fill_coef(codec);
6349 /* automatic parse from the BIOS config */
6350 err = alc269_parse_auto_config(codec);
6354 if (!spec->no_analog && has_cdefine_beep(codec)) {
6355 err = snd_hda_attach_beep_device(codec, 0x1);
6358 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
6361 codec->patch_ops = alc_patch_ops;
6363 codec->patch_ops.resume = alc269_resume;
6365 spec->shutup = alc269_shutup;
6367 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6380 static int alc861_parse_auto_config(struct hda_codec *codec)
6382 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
6383 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
6384 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
6387 /* Pin config fixes */
6389 ALC861_FIXUP_FSC_AMILO_PI1505,
6390 ALC861_FIXUP_AMP_VREF_0F,
6391 ALC861_FIXUP_NO_JACK_DETECT,
6392 ALC861_FIXUP_ASUS_A6RP,
6395 /* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
6396 static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
6397 const struct alc_fixup *fix, int action)
6399 struct alc_spec *spec = codec->spec;
6402 if (action != ALC_FIXUP_ACT_INIT)
6404 val = snd_hda_codec_read(codec, 0x0f, 0,
6405 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
6406 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
6407 val |= AC_PINCTL_IN_EN;
6408 val |= AC_PINCTL_VREF_50;
6409 snd_hda_codec_write(codec, 0x0f, 0,
6410 AC_VERB_SET_PIN_WIDGET_CONTROL, val);
6411 spec->keep_vref_in_automute = 1;
6414 /* suppress the jack-detection */
6415 static void alc_fixup_no_jack_detect(struct hda_codec *codec,
6416 const struct alc_fixup *fix, int action)
6418 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6419 codec->no_jack_detect = 1;
6422 static const struct alc_fixup alc861_fixups[] = {
6423 [ALC861_FIXUP_FSC_AMILO_PI1505] = {
6424 .type = ALC_FIXUP_PINS,
6425 .v.pins = (const struct alc_pincfg[]) {
6426 { 0x0b, 0x0221101f }, /* HP */
6427 { 0x0f, 0x90170310 }, /* speaker */
6431 [ALC861_FIXUP_AMP_VREF_0F] = {
6432 .type = ALC_FIXUP_FUNC,
6433 .v.func = alc861_fixup_asus_amp_vref_0f,
6435 [ALC861_FIXUP_NO_JACK_DETECT] = {
6436 .type = ALC_FIXUP_FUNC,
6437 .v.func = alc_fixup_no_jack_detect,
6439 [ALC861_FIXUP_ASUS_A6RP] = {
6440 .type = ALC_FIXUP_FUNC,
6441 .v.func = alc861_fixup_asus_amp_vref_0f,
6443 .chain_id = ALC861_FIXUP_NO_JACK_DETECT,
6447 static const struct snd_pci_quirk alc861_fixup_tbl[] = {
6448 SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP),
6449 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", ALC861_FIXUP_AMP_VREF_0F),
6450 SND_PCI_QUIRK(0x1462, 0x7254, "HP DX2200", ALC861_FIXUP_NO_JACK_DETECT),
6451 SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", ALC861_FIXUP_AMP_VREF_0F),
6452 SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", ALC861_FIXUP_AMP_VREF_0F),
6453 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", ALC861_FIXUP_FSC_AMILO_PI1505),
6459 static int patch_alc861(struct hda_codec *codec)
6461 struct alc_spec *spec;
6464 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6470 spec->mixer_nid = 0x15;
6472 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
6473 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6475 /* automatic parse from the BIOS config */
6476 err = alc861_parse_auto_config(codec);
6480 if (!spec->no_analog) {
6481 err = snd_hda_attach_beep_device(codec, 0x23);
6484 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
6487 codec->patch_ops = alc_patch_ops;
6488 #ifdef CONFIG_SND_HDA_POWER_SAVE
6489 spec->power_hook = alc_power_eapd;
6492 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6506 * In addition, an independent DAC
6508 static int alc861vd_parse_auto_config(struct hda_codec *codec)
6510 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
6511 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6512 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
6516 ALC660VD_FIX_ASUS_GPIO1,
6517 ALC861VD_FIX_DALLAS,
6520 /* exclude VREF80 */
6521 static void alc861vd_fixup_dallas(struct hda_codec *codec,
6522 const struct alc_fixup *fix, int action)
6524 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
6525 snd_hda_override_pin_caps(codec, 0x18, 0x00000734);
6526 snd_hda_override_pin_caps(codec, 0x19, 0x0000073c);
6530 static const struct alc_fixup alc861vd_fixups[] = {
6531 [ALC660VD_FIX_ASUS_GPIO1] = {
6532 .type = ALC_FIXUP_VERBS,
6533 .v.verbs = (const struct hda_verb[]) {
6535 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6536 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
6537 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
6541 [ALC861VD_FIX_DALLAS] = {
6542 .type = ALC_FIXUP_FUNC,
6543 .v.func = alc861vd_fixup_dallas,
6547 static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
6548 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
6549 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
6550 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
6554 static const struct hda_verb alc660vd_eapd_verbs[] = {
6555 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
6556 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
6562 static int patch_alc861vd(struct hda_codec *codec)
6564 struct alc_spec *spec;
6567 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6573 spec->mixer_nid = 0x0b;
6575 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
6576 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6578 /* automatic parse from the BIOS config */
6579 err = alc861vd_parse_auto_config(codec);
6583 if (codec->vendor_id == 0x10ec0660) {
6584 /* always turn on EAPD */
6585 add_verb(spec, alc660vd_eapd_verbs);
6588 if (!spec->no_analog) {
6589 err = snd_hda_attach_beep_device(codec, 0x23);
6592 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6595 codec->patch_ops = alc_patch_ops;
6597 spec->shutup = alc_eapd_shutup;
6599 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6611 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
6612 * configuration. Each pin widget can choose any input DACs and a mixer.
6613 * Each ADC is connected from a mixer of all inputs. This makes possible
6614 * 6-channel independent captures.
6616 * In addition, an independent DAC for the multi-playback (not used in this
6621 * BIOS auto configuration
6624 static int alc662_parse_auto_config(struct hda_codec *codec)
6626 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
6627 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
6628 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6629 const hda_nid_t *ssids;
6631 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
6632 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670 ||
6633 codec->vendor_id == 0x10ec0671)
6634 ssids = alc663_ssids;
6636 ssids = alc662_ssids;
6637 return alc_parse_auto_config(codec, alc662_ignore, ssids);
6640 static void alc272_fixup_mario(struct hda_codec *codec,
6641 const struct alc_fixup *fix, int action)
6643 if (action != ALC_FIXUP_ACT_PROBE)
6645 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
6646 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
6647 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
6648 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6649 (0 << AC_AMPCAP_MUTE_SHIFT)))
6651 "hda_codec: failed to override amp caps for NID 0x2\n");
6655 ALC662_FIXUP_ASPIRE,
6656 ALC662_FIXUP_IDEAPAD,
6658 ALC662_FIXUP_CZC_P10T,
6659 ALC662_FIXUP_SKU_IGNORE,
6660 ALC662_FIXUP_HP_RP5800,
6661 ALC662_FIXUP_ASUS_MODE1,
6662 ALC662_FIXUP_ASUS_MODE2,
6663 ALC662_FIXUP_ASUS_MODE3,
6664 ALC662_FIXUP_ASUS_MODE4,
6665 ALC662_FIXUP_ASUS_MODE5,
6666 ALC662_FIXUP_ASUS_MODE6,
6667 ALC662_FIXUP_ASUS_MODE7,
6668 ALC662_FIXUP_ASUS_MODE8,
6669 ALC662_FIXUP_NO_JACK_DETECT,
6670 ALC662_FIXUP_ZOTAC_Z68,
6673 static const struct alc_fixup alc662_fixups[] = {
6674 [ALC662_FIXUP_ASPIRE] = {
6675 .type = ALC_FIXUP_PINS,
6676 .v.pins = (const struct alc_pincfg[]) {
6677 { 0x15, 0x99130112 }, /* subwoofer */
6681 [ALC662_FIXUP_IDEAPAD] = {
6682 .type = ALC_FIXUP_PINS,
6683 .v.pins = (const struct alc_pincfg[]) {
6684 { 0x17, 0x99130112 }, /* subwoofer */
6688 [ALC272_FIXUP_MARIO] = {
6689 .type = ALC_FIXUP_FUNC,
6690 .v.func = alc272_fixup_mario,
6692 [ALC662_FIXUP_CZC_P10T] = {
6693 .type = ALC_FIXUP_VERBS,
6694 .v.verbs = (const struct hda_verb[]) {
6695 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6699 [ALC662_FIXUP_SKU_IGNORE] = {
6700 .type = ALC_FIXUP_SKU,
6701 .v.sku = ALC_FIXUP_SKU_IGNORE,
6703 [ALC662_FIXUP_HP_RP5800] = {
6704 .type = ALC_FIXUP_PINS,
6705 .v.pins = (const struct alc_pincfg[]) {
6706 { 0x14, 0x0221201f }, /* HP out */
6710 .chain_id = ALC662_FIXUP_SKU_IGNORE
6712 [ALC662_FIXUP_ASUS_MODE1] = {
6713 .type = ALC_FIXUP_PINS,
6714 .v.pins = (const struct alc_pincfg[]) {
6715 { 0x14, 0x99130110 }, /* speaker */
6716 { 0x18, 0x01a19c20 }, /* mic */
6717 { 0x19, 0x99a3092f }, /* int-mic */
6718 { 0x21, 0x0121401f }, /* HP out */
6722 .chain_id = ALC662_FIXUP_SKU_IGNORE
6724 [ALC662_FIXUP_ASUS_MODE2] = {
6725 .type = ALC_FIXUP_PINS,
6726 .v.pins = (const struct alc_pincfg[]) {
6727 { 0x14, 0x99130110 }, /* speaker */
6728 { 0x18, 0x01a19820 }, /* mic */
6729 { 0x19, 0x99a3092f }, /* int-mic */
6730 { 0x1b, 0x0121401f }, /* HP out */
6734 .chain_id = ALC662_FIXUP_SKU_IGNORE
6736 [ALC662_FIXUP_ASUS_MODE3] = {
6737 .type = ALC_FIXUP_PINS,
6738 .v.pins = (const struct alc_pincfg[]) {
6739 { 0x14, 0x99130110 }, /* speaker */
6740 { 0x15, 0x0121441f }, /* HP */
6741 { 0x18, 0x01a19840 }, /* mic */
6742 { 0x19, 0x99a3094f }, /* int-mic */
6743 { 0x21, 0x01211420 }, /* HP2 */
6747 .chain_id = ALC662_FIXUP_SKU_IGNORE
6749 [ALC662_FIXUP_ASUS_MODE4] = {
6750 .type = ALC_FIXUP_PINS,
6751 .v.pins = (const struct alc_pincfg[]) {
6752 { 0x14, 0x99130110 }, /* speaker */
6753 { 0x16, 0x99130111 }, /* speaker */
6754 { 0x18, 0x01a19840 }, /* mic */
6755 { 0x19, 0x99a3094f }, /* int-mic */
6756 { 0x21, 0x0121441f }, /* HP */
6760 .chain_id = ALC662_FIXUP_SKU_IGNORE
6762 [ALC662_FIXUP_ASUS_MODE5] = {
6763 .type = ALC_FIXUP_PINS,
6764 .v.pins = (const struct alc_pincfg[]) {
6765 { 0x14, 0x99130110 }, /* speaker */
6766 { 0x15, 0x0121441f }, /* HP */
6767 { 0x16, 0x99130111 }, /* speaker */
6768 { 0x18, 0x01a19840 }, /* mic */
6769 { 0x19, 0x99a3094f }, /* int-mic */
6773 .chain_id = ALC662_FIXUP_SKU_IGNORE
6775 [ALC662_FIXUP_ASUS_MODE6] = {
6776 .type = ALC_FIXUP_PINS,
6777 .v.pins = (const struct alc_pincfg[]) {
6778 { 0x14, 0x99130110 }, /* speaker */
6779 { 0x15, 0x01211420 }, /* HP2 */
6780 { 0x18, 0x01a19840 }, /* mic */
6781 { 0x19, 0x99a3094f }, /* int-mic */
6782 { 0x1b, 0x0121441f }, /* HP */
6786 .chain_id = ALC662_FIXUP_SKU_IGNORE
6788 [ALC662_FIXUP_ASUS_MODE7] = {
6789 .type = ALC_FIXUP_PINS,
6790 .v.pins = (const struct alc_pincfg[]) {
6791 { 0x14, 0x99130110 }, /* speaker */
6792 { 0x17, 0x99130111 }, /* speaker */
6793 { 0x18, 0x01a19840 }, /* mic */
6794 { 0x19, 0x99a3094f }, /* int-mic */
6795 { 0x1b, 0x01214020 }, /* HP */
6796 { 0x21, 0x0121401f }, /* HP */
6800 .chain_id = ALC662_FIXUP_SKU_IGNORE
6802 [ALC662_FIXUP_ASUS_MODE8] = {
6803 .type = ALC_FIXUP_PINS,
6804 .v.pins = (const struct alc_pincfg[]) {
6805 { 0x14, 0x99130110 }, /* speaker */
6806 { 0x12, 0x99a30970 }, /* int-mic */
6807 { 0x15, 0x01214020 }, /* HP */
6808 { 0x17, 0x99130111 }, /* speaker */
6809 { 0x18, 0x01a19840 }, /* mic */
6810 { 0x21, 0x0121401f }, /* HP */
6814 .chain_id = ALC662_FIXUP_SKU_IGNORE
6816 [ALC662_FIXUP_NO_JACK_DETECT] = {
6817 .type = ALC_FIXUP_FUNC,
6818 .v.func = alc_fixup_no_jack_detect,
6820 [ALC662_FIXUP_ZOTAC_Z68] = {
6821 .type = ALC_FIXUP_PINS,
6822 .v.pins = (const struct alc_pincfg[]) {
6823 { 0x1b, 0x02214020 }, /* Front HP */
6829 static const struct snd_pci_quirk alc662_fixup_tbl[] = {
6830 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
6831 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
6832 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
6833 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
6834 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
6835 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT),
6836 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
6837 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
6838 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
6839 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
6840 SND_PCI_QUIRK(0x19da, 0xa130, "Zotac Z68", ALC662_FIXUP_ZOTAC_Z68),
6841 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
6844 /* Below is a quirk table taken from the old code.
6845 * Basically the device should work as is without the fixup table.
6846 * If BIOS doesn't give a proper info, enable the corresponding
6849 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
6850 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
6851 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
6852 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
6853 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6854 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6855 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6856 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
6857 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
6858 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6859 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
6860 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
6861 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
6862 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
6863 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
6864 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6865 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
6866 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
6867 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6868 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6869 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6870 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6871 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
6872 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
6873 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
6874 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6875 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
6876 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6877 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6878 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
6879 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6880 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6881 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
6882 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
6883 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
6884 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
6885 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
6886 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
6887 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
6888 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6889 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
6890 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
6891 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6892 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
6893 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
6894 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
6895 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
6896 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
6897 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6898 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
6903 static const struct alc_model_fixup alc662_fixup_models[] = {
6904 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
6905 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
6906 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
6907 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
6908 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
6909 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
6910 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
6911 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
6912 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
6919 static int patch_alc662(struct hda_codec *codec)
6921 struct alc_spec *spec;
6924 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6930 spec->mixer_nid = 0x0b;
6932 /* handle multiple HPs as is */
6933 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
6935 alc_fix_pll_init(codec, 0x20, 0x04, 15);
6937 err = alc_codec_rename_from_preset(codec);
6941 if ((alc_get_coef0(codec) & (1 << 14)) &&
6942 codec->bus->pci->subsystem_vendor == 0x1025 &&
6943 spec->cdefine.platform_type == 1) {
6944 if (alc_codec_rename(codec, "ALC272X") < 0)
6948 alc_pick_fixup(codec, alc662_fixup_models,
6949 alc662_fixup_tbl, alc662_fixups);
6950 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6952 alc_auto_parse_customize_define(codec);
6954 /* automatic parse from the BIOS config */
6955 err = alc662_parse_auto_config(codec);
6959 if (!spec->no_analog && has_cdefine_beep(codec)) {
6960 err = snd_hda_attach_beep_device(codec, 0x1);
6963 switch (codec->vendor_id) {
6965 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6970 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
6973 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
6978 codec->patch_ops = alc_patch_ops;
6979 spec->shutup = alc_eapd_shutup;
6981 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6994 static int alc680_parse_auto_config(struct hda_codec *codec)
6996 return alc_parse_auto_config(codec, NULL, NULL);
7001 static int patch_alc680(struct hda_codec *codec)
7003 struct alc_spec *spec;
7006 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
7012 /* ALC680 has no aa-loopback mixer */
7014 /* automatic parse from the BIOS config */
7015 err = alc680_parse_auto_config(codec);
7021 codec->patch_ops = alc_patch_ops;
7029 static const struct hda_codec_preset snd_hda_preset_realtek[] = {
7030 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
7031 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
7032 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
7033 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
7034 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
7035 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
7036 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
7037 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
7038 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
7039 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
7040 { .id = 0x10ec0280, .name = "ALC280", .patch = patch_alc269 },
7041 { .id = 0x10ec0282, .name = "ALC282", .patch = patch_alc269 },
7042 { .id = 0x10ec0283, .name = "ALC283", .patch = patch_alc269 },
7043 { .id = 0x10ec0290, .name = "ALC290", .patch = patch_alc269 },
7044 { .id = 0x10ec0292, .name = "ALC292", .patch = patch_alc269 },
7045 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
7046 .patch = patch_alc861 },
7047 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
7048 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
7049 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
7050 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
7051 .patch = patch_alc882 },
7052 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
7053 .patch = patch_alc662 },
7054 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
7055 .patch = patch_alc662 },
7056 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
7057 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
7058 { .id = 0x10ec0668, .name = "ALC668", .patch = patch_alc662 },
7059 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
7060 { .id = 0x10ec0671, .name = "ALC671", .patch = patch_alc662 },
7061 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
7062 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
7063 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
7064 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
7065 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
7066 .patch = patch_alc882 },
7067 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
7068 .patch = patch_alc882 },
7069 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
7070 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
7071 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
7072 .patch = patch_alc882 },
7073 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
7074 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
7075 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
7076 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
7077 { .id = 0x10ec0900, .name = "ALC1150", .patch = patch_alc882 },
7081 MODULE_ALIAS("snd-hda-codec-id:10ec*");
7083 MODULE_LICENSE("GPL");
7084 MODULE_DESCRIPTION("Realtek HD-audio codec");
7086 static struct hda_codec_preset_list realtek_list = {
7087 .preset = snd_hda_preset_realtek,
7088 .owner = THIS_MODULE,
7091 static int __init patch_realtek_init(void)
7093 return snd_hda_add_codec_preset(&realtek_list);
7096 static void __exit patch_realtek_exit(void)
7098 snd_hda_delete_codec_preset(&realtek_list);
7101 module_init(patch_realtek_init)
7102 module_exit(patch_realtek_exit)