2 * Universal Interface for Intel High Definition Audio Codec
4 * HD audio interface patch for Realtek ALC codecs
6 * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
7 * PeiSen Hou <pshou@realtek.com.tw>
8 * Takashi Iwai <tiwai@suse.de>
9 * Jonathan Woithe <jwoithe@just42.net>
11 * This driver is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This driver is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include <linux/init.h>
27 #include <linux/delay.h>
28 #include <linux/slab.h>
29 #include <linux/pci.h>
30 #include <linux/module.h>
31 #include <sound/core.h>
32 #include <sound/jack.h>
33 #include "hda_codec.h"
34 #include "hda_local.h"
35 #include "hda_auto_parser.h"
39 /* unsol event tags */
40 #define ALC_FRONT_EVENT 0x01
41 #define ALC_DCVOL_EVENT 0x02
42 #define ALC_HP_EVENT 0x04
43 #define ALC_MIC_EVENT 0x08
46 #define GPIO_MASK 0x03
48 /* extra amp-initialization sequence types */
57 struct alc_customize_define {
59 unsigned char port_connectivity;
60 unsigned char check_sum;
61 unsigned char customization;
62 unsigned char external_amp;
63 unsigned int enable_pcbeep:1;
64 unsigned int platform_type:1;
66 unsigned int override:1;
67 unsigned int fixup:1; /* Means that this sku is set by driver, not read from hw */
71 hda_nid_t pin; /* multi-io widget pin NID */
72 hda_nid_t dac; /* DAC to be connected */
73 unsigned int ctl_in; /* cached input-pin control value */
77 ALC_AUTOMUTE_PIN, /* change the pin control */
78 ALC_AUTOMUTE_AMP, /* mute/unmute the pin AMP */
79 ALC_AUTOMUTE_MIXER, /* mute/unmute mixer widget AMP */
82 #define MAX_VOL_NIDS 0x40
84 /* make compatible with old code */
85 #define alc_apply_pincfgs snd_hda_apply_pincfgs
86 #define alc_apply_fixup snd_hda_apply_fixup
87 #define alc_pick_fixup snd_hda_pick_fixup
88 #define alc_fixup hda_fixup
89 #define alc_pincfg hda_pintbl
90 #define alc_model_fixup hda_model_fixup
92 #define ALC_FIXUP_PINS HDA_FIXUP_PINS
93 #define ALC_FIXUP_VERBS HDA_FIXUP_VERBS
94 #define ALC_FIXUP_FUNC HDA_FIXUP_FUNC
96 #define ALC_FIXUP_ACT_PRE_PROBE HDA_FIXUP_ACT_PRE_PROBE
97 #define ALC_FIXUP_ACT_PROBE HDA_FIXUP_ACT_PROBE
98 #define ALC_FIXUP_ACT_INIT HDA_FIXUP_ACT_INIT
99 #define ALC_FIXUP_ACT_BUILD HDA_FIXUP_ACT_BUILD
102 #define MAX_NID_PATH_DEPTH 5
104 /* Widget connection path
106 * For output, stored in the order of DAC -> ... -> pin,
107 * for input, pin -> ... -> ADC.
109 * idx[i] contains the source index number to select on of the widget path[i];
110 * e.g. idx[1] is the index of the DAC (path[0]) selected by path[1] widget
111 * multi[] indicates whether it's a selector widget with multi-connectors
112 * (i.e. the connection selection is mandatory)
113 * vol_ctl and mute_ctl contains the NIDs for the assigned mixers
117 hda_nid_t path[MAX_NID_PATH_DEPTH];
118 unsigned char idx[MAX_NID_PATH_DEPTH];
119 unsigned char multi[MAX_NID_PATH_DEPTH];
120 unsigned int ctls[2]; /* 0 = volume, 1 = mute */
123 enum { NID_PATH_VOL_CTL = 0, NID_PATH_MUTE_CTL = 1 };
126 struct hda_gen_spec gen;
128 /* codec parameterization */
129 const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */
130 unsigned int num_mixers;
131 const struct snd_kcontrol_new *cap_mixer; /* capture mixer */
132 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
134 char stream_name_analog[32]; /* analog PCM stream */
135 const struct hda_pcm_stream *stream_analog_playback;
136 const struct hda_pcm_stream *stream_analog_capture;
137 const struct hda_pcm_stream *stream_analog_alt_playback;
138 const struct hda_pcm_stream *stream_analog_alt_capture;
140 char stream_name_digital[32]; /* digital PCM stream */
141 const struct hda_pcm_stream *stream_digital_playback;
142 const struct hda_pcm_stream *stream_digital_capture;
145 struct hda_multi_out multiout; /* playback set-up
146 * max_channels, dacs must be set
147 * dig_out_nid and hp_nid are optional
149 hda_nid_t alt_dac_nid;
150 hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */
154 unsigned int num_adc_nids;
155 const hda_nid_t *adc_nids;
156 const hda_nid_t *capsrc_nids;
157 hda_nid_t dig_in_nid; /* digital-in NID; optional */
158 hda_nid_t mixer_nid; /* analog-mixer NID */
160 /* capture setup for dynamic dual-adc switch */
162 unsigned int cur_adc_stream_tag;
163 unsigned int cur_adc_format;
166 unsigned int num_mux_defs;
167 const struct hda_input_mux *input_mux;
168 unsigned int cur_mux[3];
169 hda_nid_t ext_mic_pin;
170 hda_nid_t dock_mic_pin;
171 hda_nid_t int_mic_pin;
174 const struct hda_channel_mode *channel_mode;
175 int num_channel_mode;
177 int const_channel_count; /* min. channel count (for speakers) */
178 int ext_channel_count; /* current channel count for multi-io */
180 /* PCM information */
181 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
183 /* dynamic controls, init_verbs and input_mux */
184 struct auto_pin_cfg autocfg;
185 struct alc_customize_define cdefine;
186 struct snd_array kctls;
187 struct hda_input_mux private_imux[3];
188 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
189 hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS];
190 hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS];
191 hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS];
192 unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS];
193 int int_mic_idx, ext_mic_idx, dock_mic_idx; /* for auto-mic */
194 hda_nid_t inv_dmic_pin;
198 hda_nid_t all_dacs[16];
201 struct snd_array out_path;
204 struct snd_array in_path;
207 void (*init_hook)(struct hda_codec *codec);
209 void (*power_hook)(struct hda_codec *codec);
211 void (*shutup)(struct hda_codec *codec);
212 void (*automute_hook)(struct hda_codec *codec);
214 /* for pin sensing */
215 unsigned int hp_jack_present:1;
216 unsigned int line_jack_present:1;
217 unsigned int master_mute:1;
218 unsigned int auto_mic:1;
219 unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */
220 unsigned int automute_speaker:1; /* automute speaker outputs */
221 unsigned int automute_lo:1; /* automute LO outputs */
222 unsigned int detect_hp:1; /* Headphone detection enabled */
223 unsigned int detect_lo:1; /* Line-out detection enabled */
224 unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */
225 unsigned int automute_lo_possible:1; /* there are line outs and HP */
226 unsigned int keep_vref_in_automute:1; /* Don't clear VREF in automute */
229 unsigned int no_analog :1; /* digital I/O only */
230 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
231 unsigned int single_input_src:1;
232 unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */
233 unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */
234 unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */
235 unsigned int inv_dmic_fixup:1; /* has inverted digital-mic workaround */
236 unsigned int inv_dmic_muted:1; /* R-ch of inv d-mic is muted? */
237 unsigned int no_primary_hp:1; /* Don't prefer HP pins to speaker pins */
239 /* auto-mute control */
241 hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS];
244 int codec_variant; /* flag for other variants */
246 /* for virtual master */
247 hda_nid_t vmaster_nid;
248 struct hda_vmaster_mute_hook vmaster_mute;
250 struct hda_loopback_check loopback;
252 struct hda_amp_list loopback_list[8];
257 unsigned int pll_coef_idx, pll_coef_bit;
262 struct alc_multi_io multi_io[4];
265 struct snd_array bind_ctls;
268 static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
269 int dir, unsigned int bits)
273 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
274 if (query_amp_caps(codec, nid, dir) & bits)
279 #define nid_has_mute(codec, nid, dir) \
280 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
281 #define nid_has_volume(codec, nid, dir) \
282 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
287 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
288 struct snd_ctl_elem_info *uinfo)
290 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
291 struct alc_spec *spec = codec->spec;
292 unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
293 if (mux_idx >= spec->num_mux_defs)
295 if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
297 return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
300 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
301 struct snd_ctl_elem_value *ucontrol)
303 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
304 struct alc_spec *spec = codec->spec;
305 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
307 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
311 static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
313 struct alc_spec *spec = codec->spec;
314 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
316 if (spec->cur_adc && spec->cur_adc != new_adc) {
317 /* stream is running, let's swap the current ADC */
318 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
319 spec->cur_adc = new_adc;
320 snd_hda_codec_setup_stream(codec, new_adc,
321 spec->cur_adc_stream_tag, 0,
322 spec->cur_adc_format);
328 static inline hda_nid_t get_capsrc(struct alc_spec *spec, int idx)
330 return spec->capsrc_nids ?
331 spec->capsrc_nids[idx] : spec->adc_nids[idx];
334 static void call_update_outputs(struct hda_codec *codec);
335 static void alc_inv_dmic_sync(struct hda_codec *codec, bool force);
337 /* for shared I/O, change the pin-control accordingly */
338 static void update_shared_mic_hp(struct hda_codec *codec, bool set_as_mic)
340 struct alc_spec *spec = codec->spec;
342 hda_nid_t pin = spec->autocfg.inputs[1].pin;
343 /* NOTE: this assumes that there are only two inputs, the
344 * first is the real internal mic and the second is HP/mic jack.
347 val = snd_hda_get_default_vref(codec, pin);
349 /* This pin does not have vref caps - let's enable vref on pin 0x18
350 instead, as suggested by Realtek */
351 if (val == AC_PINCTL_VREF_HIZ) {
352 const hda_nid_t vref_pin = 0x18;
353 /* Sanity check pin 0x18 */
354 if (get_wcaps_type(get_wcaps(codec, vref_pin)) == AC_WID_PIN &&
355 get_defcfg_connect(snd_hda_codec_get_pincfg(codec, vref_pin)) == AC_JACK_PORT_NONE) {
356 unsigned int vref_val = snd_hda_get_default_vref(codec, vref_pin);
357 if (vref_val != AC_PINCTL_VREF_HIZ)
358 snd_hda_set_pin_ctl(codec, vref_pin, PIN_IN | (set_as_mic ? vref_val : 0));
362 val = set_as_mic ? val | PIN_IN : PIN_HP;
363 snd_hda_set_pin_ctl(codec, pin, val);
365 spec->automute_speaker = !set_as_mic;
366 call_update_outputs(codec);
369 /* select the given imux item; either unmute exclusively or select the route */
370 static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
371 unsigned int idx, bool force)
373 struct alc_spec *spec = codec->spec;
374 const struct hda_input_mux *imux;
375 unsigned int mux_idx;
376 int i, type, num_conns;
379 if (!spec->input_mux)
382 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
383 imux = &spec->input_mux[mux_idx];
384 if (!imux->num_items && mux_idx > 0)
385 imux = &spec->input_mux[0];
386 if (!imux->num_items)
389 if (idx >= imux->num_items)
390 idx = imux->num_items - 1;
391 if (spec->cur_mux[adc_idx] == idx && !force)
393 spec->cur_mux[adc_idx] = idx;
395 if (spec->shared_mic_hp)
396 update_shared_mic_hp(codec, spec->cur_mux[adc_idx]);
398 if (spec->dyn_adc_switch) {
399 alc_dyn_adc_pcm_resetup(codec, idx);
400 adc_idx = spec->dyn_adc_idx[idx];
403 nid = get_capsrc(spec, adc_idx);
406 num_conns = snd_hda_get_num_conns(codec, nid);
410 type = get_wcaps_type(get_wcaps(codec, nid));
411 if (type == AC_WID_AUD_MIX) {
412 /* Matrix-mixer style (e.g. ALC882) */
413 int active = imux->items[idx].index;
414 for (i = 0; i < num_conns; i++) {
415 unsigned int v = (i == active) ? 0 : HDA_AMP_MUTE;
416 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, i,
420 /* MUX style (e.g. ALC880) */
421 snd_hda_codec_write_cache(codec, nid, 0,
422 AC_VERB_SET_CONNECT_SEL,
423 imux->items[idx].index);
425 alc_inv_dmic_sync(codec, true);
429 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
430 struct snd_ctl_elem_value *ucontrol)
432 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
433 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
434 return alc_mux_select(codec, adc_idx,
435 ucontrol->value.enumerated.item[0], false);
439 * set up the input pin config (depending on the given auto-pin type)
441 static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
444 unsigned int val = PIN_IN;
445 if (auto_pin_type == AUTO_PIN_MIC)
446 val |= snd_hda_get_default_vref(codec, nid);
447 snd_hda_set_pin_ctl(codec, nid, val);
451 * Append the given mixer and verb elements for the later use
452 * The mixer array is referred in build_controls(), and init_verbs are
455 static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
457 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
459 spec->mixers[spec->num_mixers++] = mix;
463 * GPIO setup tables, used in initialization
465 /* Enable GPIO mask and set output */
466 static const struct hda_verb alc_gpio1_init_verbs[] = {
467 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
468 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
469 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
473 static const struct hda_verb alc_gpio2_init_verbs[] = {
474 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
475 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
476 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
480 static const struct hda_verb alc_gpio3_init_verbs[] = {
481 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
482 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
483 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
488 * Fix hardware PLL issue
489 * On some codecs, the analog PLL gating control must be off while
490 * the default value is 1.
492 static void alc_fix_pll(struct hda_codec *codec)
494 struct alc_spec *spec = codec->spec;
499 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
501 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
502 AC_VERB_GET_PROC_COEF, 0);
503 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
505 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
506 val & ~(1 << spec->pll_coef_bit));
509 static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
510 unsigned int coef_idx, unsigned int coef_bit)
512 struct alc_spec *spec = codec->spec;
514 spec->pll_coef_idx = coef_idx;
515 spec->pll_coef_bit = coef_bit;
520 * Jack detections for HP auto-mute and mic-switch
523 /* check each pin in the given array; returns true if any of them is plugged */
524 static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
528 for (i = 0; i < num_pins; i++) {
529 hda_nid_t nid = pins[i];
532 present |= snd_hda_jack_detect(codec, nid);
537 /* standard HP/line-out auto-mute helper */
538 static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
539 bool mute, bool hp_out)
541 struct alc_spec *spec = codec->spec;
542 unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0;
543 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
546 for (i = 0; i < num_pins; i++) {
547 hda_nid_t nid = pins[i];
551 switch (spec->automute_mode) {
552 case ALC_AUTOMUTE_PIN:
553 /* don't reset VREF value in case it's controlling
554 * the amp (see alc861_fixup_asus_amp_vref_0f())
556 if (spec->keep_vref_in_automute) {
557 val = snd_hda_codec_read(codec, nid, 0,
558 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
563 snd_hda_set_pin_ctl(codec, nid, val);
565 case ALC_AUTOMUTE_AMP:
566 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
567 HDA_AMP_MUTE, mute_bits);
569 case ALC_AUTOMUTE_MIXER:
570 nid = spec->automute_mixer_nid[i];
573 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
574 HDA_AMP_MUTE, mute_bits);
575 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1,
576 HDA_AMP_MUTE, mute_bits);
582 /* Toggle outputs muting */
583 static void update_outputs(struct hda_codec *codec)
585 struct alc_spec *spec = codec->spec;
588 /* Control HP pins/amps depending on master_mute state;
589 * in general, HP pins/amps control should be enabled in all cases,
590 * but currently set only for master_mute, just to be safe
592 if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */
593 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
594 spec->autocfg.hp_pins, spec->master_mute, true);
596 if (!spec->automute_speaker)
599 on = spec->hp_jack_present | spec->line_jack_present;
600 on |= spec->master_mute;
601 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
602 spec->autocfg.speaker_pins, on, false);
604 /* toggle line-out mutes if needed, too */
605 /* if LO is a copy of either HP or Speaker, don't need to handle it */
606 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
607 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
609 if (!spec->automute_lo)
612 on = spec->hp_jack_present;
613 on |= spec->master_mute;
614 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
615 spec->autocfg.line_out_pins, on, false);
618 static void call_update_outputs(struct hda_codec *codec)
620 struct alc_spec *spec = codec->spec;
621 if (spec->automute_hook)
622 spec->automute_hook(codec);
624 update_outputs(codec);
627 /* standard HP-automute helper */
628 static void alc_hp_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
630 struct alc_spec *spec = codec->spec;
632 spec->hp_jack_present =
633 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
634 spec->autocfg.hp_pins);
635 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
637 call_update_outputs(codec);
640 /* standard line-out-automute helper */
641 static void alc_line_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
643 struct alc_spec *spec = codec->spec;
645 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
647 /* check LO jack only when it's different from HP */
648 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
651 spec->line_jack_present =
652 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
653 spec->autocfg.line_out_pins);
654 if (!spec->automute_speaker || !spec->detect_lo)
656 call_update_outputs(codec);
659 #define get_connection_index(codec, mux, nid) \
660 snd_hda_get_conn_index(codec, mux, nid, 0)
662 /* standard mic auto-switch helper */
663 static void alc_mic_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
665 struct alc_spec *spec = codec->spec;
666 hda_nid_t *pins = spec->imux_pins;
668 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
670 if (snd_BUG_ON(!spec->adc_nids))
672 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
675 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
676 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
677 else if (spec->dock_mic_idx >= 0 &&
678 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
679 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
681 alc_mux_select(codec, 0, spec->int_mic_idx, false);
684 /* update the master volume per volume-knob's unsol event */
685 static void alc_update_knob_master(struct hda_codec *codec, struct hda_jack_tbl *jack)
688 struct snd_kcontrol *kctl;
689 struct snd_ctl_elem_value *uctl;
691 kctl = snd_hda_find_mixer_ctl(codec, "Master Playback Volume");
694 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
697 val = snd_hda_codec_read(codec, jack->nid, 0,
698 AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
699 val &= HDA_AMP_VOLMASK;
700 uctl->value.integer.value[0] = val;
701 uctl->value.integer.value[1] = val;
702 kctl->put(kctl, uctl);
706 static void alc880_unsol_event(struct hda_codec *codec, unsigned int res)
708 /* For some reason, the res given from ALC880 is broken.
709 Here we adjust it properly. */
710 snd_hda_jack_unsol_event(codec, res >> 2);
713 /* call init functions of standard auto-mute helpers */
714 static void alc_inithook(struct hda_codec *codec)
716 alc_hp_automute(codec, NULL);
717 alc_line_automute(codec, NULL);
718 alc_mic_automute(codec, NULL);
721 /* additional initialization for ALC888 variants */
722 static void alc888_coef_init(struct hda_codec *codec)
726 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
727 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
728 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
729 if ((tmp & 0xf0) == 0x20)
731 snd_hda_codec_read(codec, 0x20, 0,
732 AC_VERB_SET_PROC_COEF, 0x830);
735 snd_hda_codec_read(codec, 0x20, 0,
736 AC_VERB_SET_PROC_COEF, 0x3030);
739 /* additional initialization for ALC889 variants */
740 static void alc889_coef_init(struct hda_codec *codec)
744 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
745 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
746 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
747 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
750 /* turn on/off EAPD control (only if available) */
751 static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
753 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
755 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
756 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
760 /* turn on/off EAPD controls of the codec */
761 static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
763 /* We currently only handle front, HP */
764 static hda_nid_t pins[] = {
765 0x0f, 0x10, 0x14, 0x15, 0
768 for (p = pins; *p; p++)
769 set_eapd(codec, *p, on);
772 /* generic shutup callback;
773 * just turning off EPAD and a little pause for avoiding pop-noise
775 static void alc_eapd_shutup(struct hda_codec *codec)
777 alc_auto_setup_eapd(codec, false);
781 /* generic EAPD initialization */
782 static void alc_auto_init_amp(struct hda_codec *codec, int type)
786 alc_auto_setup_eapd(codec, true);
789 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
792 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
795 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
797 case ALC_INIT_DEFAULT:
798 switch (codec->vendor_id) {
800 snd_hda_codec_write(codec, 0x1a, 0,
801 AC_VERB_SET_COEF_INDEX, 7);
802 tmp = snd_hda_codec_read(codec, 0x1a, 0,
803 AC_VERB_GET_PROC_COEF, 0);
804 snd_hda_codec_write(codec, 0x1a, 0,
805 AC_VERB_SET_COEF_INDEX, 7);
806 snd_hda_codec_write(codec, 0x1a, 0,
807 AC_VERB_SET_PROC_COEF,
816 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
817 alc889_coef_init(codec);
820 alc888_coef_init(codec);
822 #if 0 /* XXX: This may cause the silent output on speaker on some machines */
825 snd_hda_codec_write(codec, 0x20, 0,
826 AC_VERB_SET_COEF_INDEX, 7);
827 tmp = snd_hda_codec_read(codec, 0x20, 0,
828 AC_VERB_GET_PROC_COEF, 0);
829 snd_hda_codec_write(codec, 0x20, 0,
830 AC_VERB_SET_COEF_INDEX, 7);
831 snd_hda_codec_write(codec, 0x20, 0,
832 AC_VERB_SET_PROC_COEF,
842 * Auto-Mute mode mixer enum support
844 static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
845 struct snd_ctl_elem_info *uinfo)
847 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
848 struct alc_spec *spec = codec->spec;
849 static const char * const texts3[] = {
850 "Disabled", "Speaker Only", "Line Out+Speaker"
853 if (spec->automute_speaker_possible && spec->automute_lo_possible)
854 return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3);
855 return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
858 static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
859 struct snd_ctl_elem_value *ucontrol)
861 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
862 struct alc_spec *spec = codec->spec;
863 unsigned int val = 0;
864 if (spec->automute_speaker)
866 if (spec->automute_lo)
869 ucontrol->value.enumerated.item[0] = val;
873 static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
874 struct snd_ctl_elem_value *ucontrol)
876 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
877 struct alc_spec *spec = codec->spec;
879 switch (ucontrol->value.enumerated.item[0]) {
881 if (!spec->automute_speaker && !spec->automute_lo)
883 spec->automute_speaker = 0;
884 spec->automute_lo = 0;
887 if (spec->automute_speaker_possible) {
888 if (!spec->automute_lo && spec->automute_speaker)
890 spec->automute_speaker = 1;
891 spec->automute_lo = 0;
892 } else if (spec->automute_lo_possible) {
893 if (spec->automute_lo)
895 spec->automute_lo = 1;
900 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
902 if (spec->automute_speaker && spec->automute_lo)
904 spec->automute_speaker = 1;
905 spec->automute_lo = 1;
910 call_update_outputs(codec);
914 static const struct snd_kcontrol_new alc_automute_mode_enum = {
915 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
916 .name = "Auto-Mute Mode",
917 .info = alc_automute_mode_info,
918 .get = alc_automute_mode_get,
919 .put = alc_automute_mode_put,
922 static struct snd_kcontrol_new *
923 alc_kcontrol_new(struct alc_spec *spec, const char *name,
924 const struct snd_kcontrol_new *temp)
926 struct snd_kcontrol_new *knew = snd_array_new(&spec->kctls);
930 knew->name = kstrdup(name, GFP_KERNEL);
936 static int alc_add_automute_mode_enum(struct hda_codec *codec)
938 struct alc_spec *spec = codec->spec;
940 if (!alc_kcontrol_new(spec, "Auto-Mute Mode", &alc_automute_mode_enum))
946 * Check the availability of HP/line-out auto-mute;
947 * Set up appropriately if really supported
949 static int alc_init_automute(struct hda_codec *codec)
951 struct alc_spec *spec = codec->spec;
952 struct auto_pin_cfg *cfg = &spec->autocfg;
958 if (cfg->line_out_pins[0])
960 if (cfg->speaker_pins[0])
962 if (present < 2) /* need two different output types */
965 if (!cfg->speaker_pins[0] &&
966 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
967 memcpy(cfg->speaker_pins, cfg->line_out_pins,
968 sizeof(cfg->speaker_pins));
969 cfg->speaker_outs = cfg->line_outs;
972 if (!cfg->hp_pins[0] &&
973 cfg->line_out_type == AUTO_PIN_HP_OUT) {
974 memcpy(cfg->hp_pins, cfg->line_out_pins,
975 sizeof(cfg->hp_pins));
976 cfg->hp_outs = cfg->line_outs;
979 spec->automute_mode = ALC_AUTOMUTE_PIN;
981 for (i = 0; i < cfg->hp_outs; i++) {
982 hda_nid_t nid = cfg->hp_pins[i];
983 if (!is_jack_detectable(codec, nid))
985 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
987 snd_hda_jack_detect_enable_callback(codec, nid, ALC_HP_EVENT,
992 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
993 if (cfg->speaker_outs)
994 for (i = 0; i < cfg->line_outs; i++) {
995 hda_nid_t nid = cfg->line_out_pins[i];
996 if (!is_jack_detectable(codec, nid))
998 snd_printdd("realtek: Enable Line-Out "
999 "auto-muting on NID 0x%x\n", nid);
1000 snd_hda_jack_detect_enable_callback(codec, nid, ALC_FRONT_EVENT,
1002 spec->detect_lo = 1;
1004 spec->automute_lo_possible = spec->detect_hp;
1007 spec->automute_speaker_possible = cfg->speaker_outs &&
1008 (spec->detect_hp || spec->detect_lo);
1010 spec->automute_lo = spec->automute_lo_possible;
1011 spec->automute_speaker = spec->automute_speaker_possible;
1013 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
1014 /* create a control for automute mode */
1015 err = alc_add_automute_mode_enum(codec);
1022 /* return the position of NID in the list, or -1 if not found */
1023 static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1026 for (i = 0; i < nums; i++)
1032 /* check whether dynamic ADC-switching is available */
1033 static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
1035 struct alc_spec *spec = codec->spec;
1036 struct hda_input_mux *imux = &spec->private_imux[0];
1040 if (imux != spec->input_mux) /* no dynamic imux? */
1043 for (n = 0; n < spec->num_adc_nids; n++) {
1044 cap = spec->private_capsrc_nids[n];
1045 for (i = 0; i < imux->num_items; i++) {
1046 pin = spec->imux_pins[i];
1049 if (get_connection_index(codec, cap, pin) < 0)
1052 if (i >= imux->num_items)
1053 return true; /* no ADC-switch is needed */
1056 for (i = 0; i < imux->num_items; i++) {
1057 pin = spec->imux_pins[i];
1058 for (n = 0; n < spec->num_adc_nids; n++) {
1059 cap = spec->private_capsrc_nids[n];
1060 idx = get_connection_index(codec, cap, pin);
1062 imux->items[i].index = idx;
1063 spec->dyn_adc_idx[i] = n;
1069 snd_printdd("realtek: enabling ADC switching\n");
1070 spec->dyn_adc_switch = 1;
1074 /* check whether all auto-mic pins are valid; setup indices if OK */
1075 static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1077 struct alc_spec *spec = codec->spec;
1078 const struct hda_input_mux *imux;
1080 if (!spec->auto_mic)
1082 if (spec->auto_mic_valid_imux)
1083 return true; /* already checked */
1085 /* fill up imux indices */
1086 if (!alc_check_dyn_adc_switch(codec)) {
1091 imux = spec->input_mux;
1092 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1093 spec->imux_pins, imux->num_items);
1094 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1095 spec->imux_pins, imux->num_items);
1096 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1097 spec->imux_pins, imux->num_items);
1098 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1100 return false; /* no corresponding imux */
1103 snd_hda_jack_detect_enable_callback(codec, spec->ext_mic_pin,
1104 ALC_MIC_EVENT, alc_mic_automute);
1105 if (spec->dock_mic_pin)
1106 snd_hda_jack_detect_enable_callback(codec, spec->dock_mic_pin,
1110 spec->auto_mic_valid_imux = 1;
1116 * Check the availability of auto-mic switch;
1117 * Set up if really supported
1119 static int alc_init_auto_mic(struct hda_codec *codec)
1121 struct alc_spec *spec = codec->spec;
1122 struct auto_pin_cfg *cfg = &spec->autocfg;
1123 hda_nid_t fixed, ext, dock;
1126 if (spec->shared_mic_hp)
1127 return 0; /* no auto-mic for the shared I/O */
1129 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1131 fixed = ext = dock = 0;
1132 for (i = 0; i < cfg->num_inputs; i++) {
1133 hda_nid_t nid = cfg->inputs[i].pin;
1134 unsigned int defcfg;
1135 defcfg = snd_hda_codec_get_pincfg(codec, nid);
1136 switch (snd_hda_get_input_pin_attr(defcfg)) {
1137 case INPUT_PIN_ATTR_INT:
1139 return 0; /* already occupied */
1140 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1141 return 0; /* invalid type */
1144 case INPUT_PIN_ATTR_UNUSED:
1145 return 0; /* invalid entry */
1146 case INPUT_PIN_ATTR_DOCK:
1148 return 0; /* already occupied */
1149 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1150 return 0; /* invalid type */
1155 return 0; /* already occupied */
1156 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1157 return 0; /* invalid type */
1168 if (!is_jack_detectable(codec, ext))
1169 return 0; /* no unsol support */
1170 if (dock && !is_jack_detectable(codec, dock))
1171 return 0; /* no unsol support */
1173 /* check imux indices */
1174 spec->ext_mic_pin = ext;
1175 spec->int_mic_pin = fixed;
1176 spec->dock_mic_pin = dock;
1179 if (!alc_auto_mic_check_imux(codec))
1182 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1188 /* check the availabilities of auto-mute and auto-mic switches */
1189 static int alc_auto_check_switches(struct hda_codec *codec)
1193 err = alc_init_automute(codec);
1196 err = alc_init_auto_mic(codec);
1203 * Realtek SSID verification
1206 /* Could be any non-zero and even value. When used as fixup, tells
1207 * the driver to ignore any present sku defines.
1209 #define ALC_FIXUP_SKU_IGNORE (2)
1211 static void alc_fixup_sku_ignore(struct hda_codec *codec,
1212 const struct hda_fixup *fix, int action)
1214 struct alc_spec *spec = codec->spec;
1215 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
1216 spec->cdefine.fixup = 1;
1217 spec->cdefine.sku_cfg = ALC_FIXUP_SKU_IGNORE;
1221 static int alc_auto_parse_customize_define(struct hda_codec *codec)
1223 unsigned int ass, tmp, i;
1225 struct alc_spec *spec = codec->spec;
1227 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1229 if (spec->cdefine.fixup) {
1230 ass = spec->cdefine.sku_cfg;
1231 if (ass == ALC_FIXUP_SKU_IGNORE)
1236 ass = codec->subsystem_id & 0xffff;
1237 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
1241 if (codec->vendor_id == 0x10ec0260)
1243 ass = snd_hda_codec_get_pincfg(codec, nid);
1246 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1247 codec->chip_name, ass);
1253 for (i = 1; i < 16; i++) {
1257 if (((ass >> 16) & 0xf) != tmp)
1260 spec->cdefine.port_connectivity = ass >> 30;
1261 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1262 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1263 spec->cdefine.customization = ass >> 8;
1265 spec->cdefine.sku_cfg = ass;
1266 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1267 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1268 spec->cdefine.swap = (ass & 0x2) >> 1;
1269 spec->cdefine.override = ass & 0x1;
1271 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1272 nid, spec->cdefine.sku_cfg);
1273 snd_printd("SKU: port_connectivity=0x%x\n",
1274 spec->cdefine.port_connectivity);
1275 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1276 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1277 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1278 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1279 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1280 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1281 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1286 /* return true if the given NID is found in the list */
1287 static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1289 return find_idx_in_nid_list(nid, list, nums) >= 0;
1292 /* check subsystem ID and set up device-specific initialization;
1293 * return 1 if initialized, 0 if invalid SSID
1295 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1296 * 31 ~ 16 : Manufacture ID
1298 * 7 ~ 0 : Assembly ID
1299 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1301 static int alc_subsystem_id(struct hda_codec *codec,
1302 hda_nid_t porta, hda_nid_t porte,
1303 hda_nid_t portd, hda_nid_t porti)
1305 unsigned int ass, tmp, i;
1307 struct alc_spec *spec = codec->spec;
1309 if (spec->cdefine.fixup) {
1310 ass = spec->cdefine.sku_cfg;
1311 if (ass == ALC_FIXUP_SKU_IGNORE)
1316 ass = codec->subsystem_id & 0xffff;
1317 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1320 /* invalid SSID, check the special NID pin defcfg instead */
1322 * 31~30 : port connectivity
1325 * 19~16 : Check sum (15:1)
1330 if (codec->vendor_id == 0x10ec0260)
1332 ass = snd_hda_codec_get_pincfg(codec, nid);
1333 snd_printd("realtek: No valid SSID, "
1334 "checking pincfg 0x%08x for NID 0x%x\n",
1338 if ((ass >> 30) != 1) /* no physical connection */
1343 for (i = 1; i < 16; i++) {
1347 if (((ass >> 16) & 0xf) != tmp)
1350 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1351 ass & 0xffff, codec->vendor_id);
1355 * 2 : 0 --> Desktop, 1 --> Laptop
1356 * 3~5 : External Amplifier control
1359 tmp = (ass & 0x38) >> 3; /* external Amp control */
1362 spec->init_amp = ALC_INIT_GPIO1;
1365 spec->init_amp = ALC_INIT_GPIO2;
1368 spec->init_amp = ALC_INIT_GPIO3;
1372 spec->init_amp = ALC_INIT_DEFAULT;
1376 /* is laptop or Desktop and enable the function "Mute internal speaker
1377 * when the external headphone out jack is plugged"
1379 if (!(ass & 0x8000))
1382 * 10~8 : Jack location
1383 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1385 * 15 : 1 --> enable the function "Mute internal speaker
1386 * when the external headphone out jack is plugged"
1388 if (!spec->autocfg.hp_pins[0] &&
1389 !(spec->autocfg.line_out_pins[0] &&
1390 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
1392 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1403 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1404 spec->autocfg.line_outs))
1406 spec->autocfg.hp_pins[0] = nid;
1411 /* Check the validity of ALC subsystem-id
1412 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1413 static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
1415 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
1416 struct alc_spec *spec = codec->spec;
1417 snd_printd("realtek: "
1418 "Enable default setup for auto mode as fallback\n");
1419 spec->init_amp = ALC_INIT_DEFAULT;
1424 * COEF access helper functions
1426 static int alc_read_coef_idx(struct hda_codec *codec,
1427 unsigned int coef_idx)
1430 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1432 val = snd_hda_codec_read(codec, 0x20, 0,
1433 AC_VERB_GET_PROC_COEF, 0);
1437 static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1438 unsigned int coef_val)
1440 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1442 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1446 /* a special bypass for COEF 0; read the cached value at the second time */
1447 static unsigned int alc_get_coef0(struct hda_codec *codec)
1449 struct alc_spec *spec = codec->spec;
1451 spec->coef0 = alc_read_coef_idx(codec, 0);
1456 * Digital I/O handling
1459 /* set right pin controls for digital I/O */
1460 static void alc_auto_init_digital(struct hda_codec *codec)
1462 struct alc_spec *spec = codec->spec;
1466 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1467 pin = spec->autocfg.dig_out_pins[i];
1470 snd_hda_set_pin_ctl(codec, pin, PIN_OUT);
1472 dac = spec->multiout.dig_out_nid;
1474 dac = spec->slave_dig_outs[i - 1];
1475 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
1477 snd_hda_codec_write(codec, dac, 0,
1478 AC_VERB_SET_AMP_GAIN_MUTE,
1481 pin = spec->autocfg.dig_in_pin;
1483 snd_hda_set_pin_ctl(codec, pin, PIN_IN);
1486 /* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1487 static void alc_auto_parse_digital(struct hda_codec *codec)
1489 struct alc_spec *spec = codec->spec;
1493 /* support multiple SPDIFs; the secondary is set up as a slave */
1495 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1497 err = snd_hda_get_connections(codec,
1498 spec->autocfg.dig_out_pins[i],
1499 conn, ARRAY_SIZE(conn));
1502 dig_nid = conn[0]; /* assume the first element is audio-out */
1504 spec->multiout.dig_out_nid = dig_nid;
1505 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1507 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
1508 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
1510 spec->slave_dig_outs[nums - 1] = dig_nid;
1515 if (spec->autocfg.dig_in_pin) {
1516 dig_nid = codec->start_nid;
1517 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1518 unsigned int wcaps = get_wcaps(codec, dig_nid);
1519 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1521 if (!(wcaps & AC_WCAP_DIGITAL))
1523 if (!(wcaps & AC_WCAP_CONN_LIST))
1525 err = get_connection_index(codec, dig_nid,
1526 spec->autocfg.dig_in_pin);
1528 spec->dig_in_nid = dig_nid;
1536 * capture mixer elements
1538 static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1539 struct snd_ctl_elem_info *uinfo)
1541 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1542 struct alc_spec *spec = codec->spec;
1546 mutex_lock(&codec->control_mutex);
1547 if (spec->vol_in_capsrc)
1548 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1550 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1551 kcontrol->private_value = val;
1552 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
1553 mutex_unlock(&codec->control_mutex);
1557 static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1558 unsigned int size, unsigned int __user *tlv)
1560 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1561 struct alc_spec *spec = codec->spec;
1565 mutex_lock(&codec->control_mutex);
1566 if (spec->vol_in_capsrc)
1567 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1569 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1570 kcontrol->private_value = val;
1571 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
1572 mutex_unlock(&codec->control_mutex);
1576 typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1577 struct snd_ctl_elem_value *ucontrol);
1579 static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1580 struct snd_ctl_elem_value *ucontrol,
1581 getput_call_t func, bool is_put)
1583 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1584 struct alc_spec *spec = codec->spec;
1587 mutex_lock(&codec->control_mutex);
1588 if (is_put && spec->dyn_adc_switch) {
1589 for (i = 0; i < spec->num_adc_nids; i++) {
1590 kcontrol->private_value =
1591 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1593 err = func(kcontrol, ucontrol);
1598 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1599 if (spec->vol_in_capsrc)
1600 kcontrol->private_value =
1601 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1604 kcontrol->private_value =
1605 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1607 err = func(kcontrol, ucontrol);
1609 if (err >= 0 && is_put)
1610 alc_inv_dmic_sync(codec, false);
1612 mutex_unlock(&codec->control_mutex);
1616 static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1617 struct snd_ctl_elem_value *ucontrol)
1619 return alc_cap_getput_caller(kcontrol, ucontrol,
1620 snd_hda_mixer_amp_volume_get, false);
1623 static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1624 struct snd_ctl_elem_value *ucontrol)
1626 return alc_cap_getput_caller(kcontrol, ucontrol,
1627 snd_hda_mixer_amp_volume_put, true);
1630 /* capture mixer elements */
1631 #define alc_cap_sw_info snd_ctl_boolean_stereo_info
1633 static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1634 struct snd_ctl_elem_value *ucontrol)
1636 return alc_cap_getput_caller(kcontrol, ucontrol,
1637 snd_hda_mixer_amp_switch_get, false);
1640 static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1641 struct snd_ctl_elem_value *ucontrol)
1643 return alc_cap_getput_caller(kcontrol, ucontrol,
1644 snd_hda_mixer_amp_switch_put, true);
1647 #define _DEFINE_CAPMIX(num) \
1649 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1650 .name = "Capture Switch", \
1651 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1653 .info = alc_cap_sw_info, \
1654 .get = alc_cap_sw_get, \
1655 .put = alc_cap_sw_put, \
1658 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1659 .name = "Capture Volume", \
1660 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1661 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1662 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1664 .info = alc_cap_vol_info, \
1665 .get = alc_cap_vol_get, \
1666 .put = alc_cap_vol_put, \
1667 .tlv = { .c = alc_cap_vol_tlv }, \
1670 #define _DEFINE_CAPSRC(num) \
1672 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1673 /* .name = "Capture Source", */ \
1674 .name = "Input Source", \
1676 .info = alc_mux_enum_info, \
1677 .get = alc_mux_enum_get, \
1678 .put = alc_mux_enum_put, \
1681 #define DEFINE_CAPMIX(num) \
1682 static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
1683 _DEFINE_CAPMIX(num), \
1684 _DEFINE_CAPSRC(num), \
1688 #define DEFINE_CAPMIX_NOSRC(num) \
1689 static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
1690 _DEFINE_CAPMIX(num), \
1694 /* up to three ADCs */
1698 DEFINE_CAPMIX_NOSRC(1);
1699 DEFINE_CAPMIX_NOSRC(2);
1700 DEFINE_CAPMIX_NOSRC(3);
1703 * Inverted digital-mic handling
1705 * First off, it's a bit tricky. The "Inverted Internal Mic Capture Switch"
1706 * gives the additional mute only to the right channel of the digital mic
1707 * capture stream. This is a workaround for avoiding the almost silence
1708 * by summing the stereo stream from some (known to be ForteMedia)
1711 * The logic is to call alc_inv_dmic_sync() after each action (possibly)
1712 * modifying ADC amp. When the mute flag is set, it mutes the R-channel
1713 * without caching so that the cache can still keep the original value.
1714 * The cached value is then restored when the flag is set off or any other
1715 * than d-mic is used as the current input source.
1717 static void alc_inv_dmic_sync(struct hda_codec *codec, bool force)
1719 struct alc_spec *spec = codec->spec;
1722 if (!spec->inv_dmic_fixup)
1724 if (!spec->inv_dmic_muted && !force)
1726 for (i = 0; i < spec->num_adc_nids; i++) {
1727 int src = spec->dyn_adc_switch ? 0 : i;
1728 bool dmic_fixup = false;
1732 if (spec->inv_dmic_muted &&
1733 spec->imux_pins[spec->cur_mux[src]] == spec->inv_dmic_pin)
1735 if (!dmic_fixup && !force)
1737 if (spec->vol_in_capsrc) {
1738 nid = spec->capsrc_nids[i];
1739 parm = AC_AMP_SET_RIGHT | AC_AMP_SET_OUTPUT;
1742 nid = spec->adc_nids[i];
1743 parm = AC_AMP_SET_RIGHT | AC_AMP_SET_INPUT;
1746 /* we care only right channel */
1747 v = snd_hda_codec_amp_read(codec, nid, 1, dir, 0);
1748 if (v & 0x80) /* if already muted, we don't need to touch */
1750 if (dmic_fixup) /* add mute for d-mic */
1752 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
1757 static int alc_inv_dmic_sw_get(struct snd_kcontrol *kcontrol,
1758 struct snd_ctl_elem_value *ucontrol)
1760 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1761 struct alc_spec *spec = codec->spec;
1763 ucontrol->value.integer.value[0] = !spec->inv_dmic_muted;
1767 static int alc_inv_dmic_sw_put(struct snd_kcontrol *kcontrol,
1768 struct snd_ctl_elem_value *ucontrol)
1770 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1771 struct alc_spec *spec = codec->spec;
1772 unsigned int val = !ucontrol->value.integer.value[0];
1774 if (val == spec->inv_dmic_muted)
1776 spec->inv_dmic_muted = val;
1777 alc_inv_dmic_sync(codec, true);
1781 static const struct snd_kcontrol_new alc_inv_dmic_sw = {
1782 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1783 .info = snd_ctl_boolean_mono_info,
1784 .get = alc_inv_dmic_sw_get,
1785 .put = alc_inv_dmic_sw_put,
1788 static int alc_add_inv_dmic_mixer(struct hda_codec *codec, hda_nid_t nid)
1790 struct alc_spec *spec = codec->spec;
1792 if (!alc_kcontrol_new(spec, "Inverted Internal Mic Capture Switch",
1795 spec->inv_dmic_fixup = 1;
1796 spec->inv_dmic_muted = 0;
1797 spec->inv_dmic_pin = nid;
1801 /* typically the digital mic is put at node 0x12 */
1802 static void alc_fixup_inv_dmic_0x12(struct hda_codec *codec,
1803 const struct alc_fixup *fix, int action)
1805 if (action == ALC_FIXUP_ACT_PROBE)
1806 alc_add_inv_dmic_mixer(codec, 0x12);
1810 * virtual master controls
1814 * slave controls for virtual master
1816 static const char * const alc_slave_pfxs[] = {
1817 "Front", "Surround", "Center", "LFE", "Side",
1818 "Headphone", "Speaker", "Mono", "Line Out",
1819 "CLFE", "Bass Speaker", "PCM",
1824 * build control elements
1827 #define NID_MAPPING (-1)
1829 #define SUBDEV_SPEAKER_ (0 << 6)
1830 #define SUBDEV_HP_ (1 << 6)
1831 #define SUBDEV_LINE_ (2 << 6)
1832 #define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1833 #define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1834 #define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1836 static void alc_free_kctls(struct hda_codec *codec);
1838 #ifdef CONFIG_SND_HDA_INPUT_BEEP
1839 /* additional beep mixers; the actual parameters are overwritten at build */
1840 static const struct snd_kcontrol_new alc_beep_mixer[] = {
1841 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
1842 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
1847 static int __alc_build_controls(struct hda_codec *codec)
1849 struct alc_spec *spec = codec->spec;
1850 struct snd_kcontrol *kctl = NULL;
1851 const struct snd_kcontrol_new *knew;
1856 for (i = 0; i < spec->num_mixers; i++) {
1857 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1861 if (spec->cap_mixer) {
1862 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1866 if (spec->multiout.dig_out_nid) {
1867 err = snd_hda_create_dig_out_ctls(codec,
1868 spec->multiout.dig_out_nid,
1869 spec->multiout.dig_out_nid,
1870 spec->pcm_rec[1].pcm_type);
1873 if (!spec->no_analog) {
1874 err = snd_hda_create_spdif_share_sw(codec,
1878 spec->multiout.share_spdif = 1;
1881 if (spec->dig_in_nid) {
1882 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1887 #ifdef CONFIG_SND_HDA_INPUT_BEEP
1888 /* create beep controls if needed */
1889 if (spec->beep_amp) {
1890 const struct snd_kcontrol_new *knew;
1891 for (knew = alc_beep_mixer; knew->name; knew++) {
1892 struct snd_kcontrol *kctl;
1893 kctl = snd_ctl_new1(knew, codec);
1896 kctl->private_value = spec->beep_amp;
1897 err = snd_hda_ctl_add(codec, 0, kctl);
1904 /* if we have no master control, let's create it */
1905 if (!spec->no_analog &&
1906 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1907 unsigned int vmaster_tlv[4];
1908 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
1909 HDA_OUTPUT, vmaster_tlv);
1910 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1911 vmaster_tlv, alc_slave_pfxs,
1916 if (!spec->no_analog &&
1917 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1918 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
1919 NULL, alc_slave_pfxs,
1921 true, &spec->vmaster_mute.sw_kctl);
1926 /* assign Capture Source enums to NID */
1927 if (spec->capsrc_nids || spec->adc_nids) {
1928 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
1930 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1931 for (i = 0; kctl && i < kctl->count; i++) {
1932 err = snd_hda_add_nid(codec, kctl, i,
1933 get_capsrc(spec, i));
1938 if (spec->cap_mixer && spec->adc_nids) {
1939 const char *kname = kctl ? kctl->id.name : NULL;
1940 for (knew = spec->cap_mixer; knew->name; knew++) {
1941 if (kname && strcmp(knew->name, kname) == 0)
1943 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1944 for (i = 0; kctl && i < kctl->count; i++) {
1945 err = snd_hda_add_nid(codec, kctl, i,
1953 /* other nid->control mapping */
1954 for (i = 0; i < spec->num_mixers; i++) {
1955 for (knew = spec->mixers[i]; knew->name; knew++) {
1956 if (knew->iface != NID_MAPPING)
1958 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1961 u = knew->subdevice;
1962 for (j = 0; j < 4; j++, u >>= 8) {
1967 case SUBDEV_SPEAKER_:
1968 nid = spec->autocfg.speaker_pins[nid];
1971 nid = spec->autocfg.line_out_pins[nid];
1974 nid = spec->autocfg.hp_pins[nid];
1979 err = snd_hda_add_nid(codec, kctl, 0, nid);
1983 u = knew->private_value;
1984 for (j = 0; j < 4; j++, u >>= 8) {
1988 err = snd_hda_add_nid(codec, kctl, 0, nid);
1995 alc_free_kctls(codec); /* no longer needed */
2000 static int alc_build_jacks(struct hda_codec *codec)
2002 struct alc_spec *spec = codec->spec;
2004 if (spec->shared_mic_hp) {
2006 int nid = spec->autocfg.inputs[1].pin;
2007 err = snd_hda_jack_add_kctl(codec, nid, "Headphone Mic", 0);
2010 err = snd_hda_jack_detect_enable(codec, nid, 0);
2015 return snd_hda_jack_add_kctls(codec, &spec->autocfg);
2018 static int alc_build_controls(struct hda_codec *codec)
2020 int err = __alc_build_controls(codec);
2024 err = alc_build_jacks(codec);
2027 alc_apply_fixup(codec, ALC_FIXUP_ACT_BUILD);
2036 static void alc_init_special_input_src(struct hda_codec *codec);
2037 static void alc_auto_init_std(struct hda_codec *codec);
2039 static int alc_init(struct hda_codec *codec)
2041 struct alc_spec *spec = codec->spec;
2043 if (spec->init_hook)
2044 spec->init_hook(codec);
2047 alc_auto_init_amp(codec, spec->init_amp);
2049 snd_hda_gen_apply_verbs(codec);
2050 alc_init_special_input_src(codec);
2051 alc_auto_init_std(codec);
2053 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2055 hda_call_check_power_status(codec, 0x01);
2060 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2062 struct alc_spec *spec = codec->spec;
2063 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2068 * Analog playback callbacks
2070 static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
2071 struct hda_codec *codec,
2072 struct snd_pcm_substream *substream)
2074 struct alc_spec *spec = codec->spec;
2075 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2079 static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2080 struct hda_codec *codec,
2081 unsigned int stream_tag,
2082 unsigned int format,
2083 struct snd_pcm_substream *substream)
2085 struct alc_spec *spec = codec->spec;
2086 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2087 stream_tag, format, substream);
2090 static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2091 struct hda_codec *codec,
2092 struct snd_pcm_substream *substream)
2094 struct alc_spec *spec = codec->spec;
2095 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2101 static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2102 struct hda_codec *codec,
2103 struct snd_pcm_substream *substream)
2105 struct alc_spec *spec = codec->spec;
2106 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2109 static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2110 struct hda_codec *codec,
2111 unsigned int stream_tag,
2112 unsigned int format,
2113 struct snd_pcm_substream *substream)
2115 struct alc_spec *spec = codec->spec;
2116 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2117 stream_tag, format, substream);
2120 static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2121 struct hda_codec *codec,
2122 struct snd_pcm_substream *substream)
2124 struct alc_spec *spec = codec->spec;
2125 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2128 static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2129 struct hda_codec *codec,
2130 struct snd_pcm_substream *substream)
2132 struct alc_spec *spec = codec->spec;
2133 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2139 static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2140 struct hda_codec *codec,
2141 unsigned int stream_tag,
2142 unsigned int format,
2143 struct snd_pcm_substream *substream)
2145 struct alc_spec *spec = codec->spec;
2147 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
2148 stream_tag, 0, format);
2152 static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2153 struct hda_codec *codec,
2154 struct snd_pcm_substream *substream)
2156 struct alc_spec *spec = codec->spec;
2158 snd_hda_codec_cleanup_stream(codec,
2159 spec->adc_nids[substream->number + 1]);
2163 /* analog capture with dynamic dual-adc changes */
2164 static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2165 struct hda_codec *codec,
2166 unsigned int stream_tag,
2167 unsigned int format,
2168 struct snd_pcm_substream *substream)
2170 struct alc_spec *spec = codec->spec;
2171 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
2172 spec->cur_adc_stream_tag = stream_tag;
2173 spec->cur_adc_format = format;
2174 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2178 static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2179 struct hda_codec *codec,
2180 struct snd_pcm_substream *substream)
2182 struct alc_spec *spec = codec->spec;
2183 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2188 static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
2192 .nid = 0, /* fill later */
2194 .prepare = dyn_adc_capture_pcm_prepare,
2195 .cleanup = dyn_adc_capture_pcm_cleanup
2201 static const struct hda_pcm_stream alc_pcm_analog_playback = {
2205 /* NID is set in alc_build_pcms */
2207 .open = alc_playback_pcm_open,
2208 .prepare = alc_playback_pcm_prepare,
2209 .cleanup = alc_playback_pcm_cleanup
2213 static const struct hda_pcm_stream alc_pcm_analog_capture = {
2217 /* NID is set in alc_build_pcms */
2220 static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
2224 /* NID is set in alc_build_pcms */
2227 static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
2228 .substreams = 2, /* can be overridden */
2231 /* NID is set in alc_build_pcms */
2233 .prepare = alc_alt_capture_pcm_prepare,
2234 .cleanup = alc_alt_capture_pcm_cleanup
2238 static const struct hda_pcm_stream alc_pcm_digital_playback = {
2242 /* NID is set in alc_build_pcms */
2244 .open = alc_dig_playback_pcm_open,
2245 .close = alc_dig_playback_pcm_close,
2246 .prepare = alc_dig_playback_pcm_prepare,
2247 .cleanup = alc_dig_playback_pcm_cleanup
2251 static const struct hda_pcm_stream alc_pcm_digital_capture = {
2255 /* NID is set in alc_build_pcms */
2258 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
2259 static const struct hda_pcm_stream alc_pcm_null_stream = {
2265 static int alc_build_pcms(struct hda_codec *codec)
2267 struct alc_spec *spec = codec->spec;
2268 struct hda_pcm *info = spec->pcm_rec;
2269 const struct hda_pcm_stream *p;
2270 bool have_multi_adcs;
2273 codec->num_pcms = 1;
2274 codec->pcm_info = info;
2276 if (spec->no_analog)
2279 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2280 "%s Analog", codec->chip_name);
2281 info->name = spec->stream_name_analog;
2283 if (spec->multiout.num_dacs > 0) {
2284 p = spec->stream_analog_playback;
2286 p = &alc_pcm_analog_playback;
2287 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2288 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2289 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
2290 spec->multiout.max_channels;
2291 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
2292 spec->autocfg.line_outs == 2)
2293 info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap =
2296 if (spec->adc_nids) {
2297 p = spec->stream_analog_capture;
2299 if (spec->dyn_adc_switch)
2300 p = &dyn_adc_pcm_analog_capture;
2302 p = &alc_pcm_analog_capture;
2304 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2305 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2308 if (spec->channel_mode) {
2309 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2310 for (i = 0; i < spec->num_channel_mode; i++) {
2311 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2312 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2318 /* SPDIF for stream index #1 */
2319 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2320 snprintf(spec->stream_name_digital,
2321 sizeof(spec->stream_name_digital),
2322 "%s Digital", codec->chip_name);
2323 codec->num_pcms = 2;
2324 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
2325 info = spec->pcm_rec + 1;
2326 info->name = spec->stream_name_digital;
2327 if (spec->dig_out_type)
2328 info->pcm_type = spec->dig_out_type;
2330 info->pcm_type = HDA_PCM_TYPE_SPDIF;
2331 if (spec->multiout.dig_out_nid) {
2332 p = spec->stream_digital_playback;
2334 p = &alc_pcm_digital_playback;
2335 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2336 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2338 if (spec->dig_in_nid) {
2339 p = spec->stream_digital_capture;
2341 p = &alc_pcm_digital_capture;
2342 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2343 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2345 /* FIXME: do we need this for all Realtek codec models? */
2346 codec->spdif_status_reset = 1;
2349 if (spec->no_analog)
2352 /* If the use of more than one ADC is requested for the current
2353 * model, configure a second analog capture-only PCM.
2355 have_multi_adcs = (spec->num_adc_nids > 1) &&
2356 !spec->dyn_adc_switch && !spec->auto_mic &&
2357 (!spec->input_mux || spec->input_mux->num_items > 1);
2358 /* Additional Analaog capture for index #2 */
2359 if (spec->alt_dac_nid || have_multi_adcs) {
2360 codec->num_pcms = 3;
2361 info = spec->pcm_rec + 2;
2362 info->name = spec->stream_name_analog;
2363 if (spec->alt_dac_nid) {
2364 p = spec->stream_analog_alt_playback;
2366 p = &alc_pcm_analog_alt_playback;
2367 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2368 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2371 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2372 alc_pcm_null_stream;
2373 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2375 if (have_multi_adcs) {
2376 p = spec->stream_analog_alt_capture;
2378 p = &alc_pcm_analog_alt_capture;
2379 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2380 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2382 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2383 spec->num_adc_nids - 1;
2385 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2386 alc_pcm_null_stream;
2387 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
2394 static inline void alc_shutup(struct hda_codec *codec)
2396 struct alc_spec *spec = codec->spec;
2398 if (spec && spec->shutup)
2399 spec->shutup(codec);
2400 snd_hda_shutup_pins(codec);
2403 static void alc_free_kctls(struct hda_codec *codec)
2405 struct alc_spec *spec = codec->spec;
2407 if (spec->kctls.list) {
2408 struct snd_kcontrol_new *kctl = spec->kctls.list;
2410 for (i = 0; i < spec->kctls.used; i++)
2411 kfree(kctl[i].name);
2413 snd_array_free(&spec->kctls);
2416 static void alc_free_bind_ctls(struct hda_codec *codec)
2418 struct alc_spec *spec = codec->spec;
2419 if (spec->bind_ctls.list) {
2420 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2422 for (i = 0; i < spec->bind_ctls.used; i++)
2425 snd_array_free(&spec->bind_ctls);
2428 static void alc_free(struct hda_codec *codec)
2430 struct alc_spec *spec = codec->spec;
2435 alc_free_kctls(codec);
2436 alc_free_bind_ctls(codec);
2437 snd_array_free(&spec->out_path);
2438 snd_array_free(&spec->in_path);
2439 snd_hda_gen_free(&spec->gen);
2441 snd_hda_detach_beep_device(codec);
2445 static void alc_power_eapd(struct hda_codec *codec)
2447 alc_auto_setup_eapd(codec, false);
2450 static int alc_suspend(struct hda_codec *codec)
2452 struct alc_spec *spec = codec->spec;
2454 if (spec && spec->power_hook)
2455 spec->power_hook(codec);
2461 static int alc_resume(struct hda_codec *codec)
2463 msleep(150); /* to avoid pop noise */
2464 codec->patch_ops.init(codec);
2465 snd_hda_codec_resume_amp(codec);
2466 snd_hda_codec_resume_cache(codec);
2467 alc_inv_dmic_sync(codec, true);
2468 hda_call_check_power_status(codec, 0x01);
2475 static const struct hda_codec_ops alc_patch_ops = {
2476 .build_controls = alc_build_controls,
2477 .build_pcms = alc_build_pcms,
2480 .unsol_event = snd_hda_jack_unsol_event,
2482 .resume = alc_resume,
2485 .suspend = alc_suspend,
2486 .check_power_status = alc_check_power_status,
2488 .reboot_notify = alc_shutup,
2492 /* replace the codec chip_name with the given string */
2493 static int alc_codec_rename(struct hda_codec *codec, const char *name)
2495 kfree(codec->chip_name);
2496 codec->chip_name = kstrdup(name, GFP_KERNEL);
2497 if (!codec->chip_name) {
2505 * Rename codecs appropriately from COEF value
2507 struct alc_codec_rename_table {
2508 unsigned int vendor_id;
2509 unsigned short coef_mask;
2510 unsigned short coef_bits;
2514 static struct alc_codec_rename_table rename_tbl[] = {
2515 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2516 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2517 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2518 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2519 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2520 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2521 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
2522 { 0x10ec0269, 0x00f0, 0x0030, "ALC269VD" },
2523 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2524 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2525 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2526 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2527 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2528 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2529 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2530 { } /* terminator */
2533 static int alc_codec_rename_from_preset(struct hda_codec *codec)
2535 const struct alc_codec_rename_table *p;
2537 for (p = rename_tbl; p->vendor_id; p++) {
2538 if (p->vendor_id != codec->vendor_id)
2540 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
2541 return alc_codec_rename(codec, p->name);
2547 * Automatic parse of I/O pins from the BIOS configuration
2552 ALC_CTL_WIDGET_MUTE,
2557 static const struct snd_kcontrol_new alc_control_templates[] = {
2558 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2559 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2560 HDA_BIND_MUTE(NULL, 0, 0, 0),
2561 HDA_BIND_VOL(NULL, 0),
2562 HDA_BIND_SW(NULL, 0),
2565 /* add dynamic controls */
2566 static int add_control(struct alc_spec *spec, int type, const char *name,
2567 int cidx, unsigned long val)
2569 struct snd_kcontrol_new *knew;
2571 knew = alc_kcontrol_new(spec, name, &alc_control_templates[type]);
2575 if (get_amp_nid_(val))
2576 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
2577 knew->private_value = val;
2581 static int add_control_with_pfx(struct alc_spec *spec, int type,
2582 const char *pfx, const char *dir,
2583 const char *sfx, int cidx, unsigned long val)
2586 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
2587 return add_control(spec, type, name, cidx, val);
2590 #define add_pb_vol_ctrl(spec, type, pfx, val) \
2591 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2592 #define add_pb_sw_ctrl(spec, type, pfx, val) \
2593 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2594 #define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2595 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2596 #define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2597 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
2599 static const char * const channel_name[4] = {
2600 "Front", "Surround", "CLFE", "Side"
2603 static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2604 bool can_be_master, int *index)
2606 struct auto_pin_cfg *cfg = &spec->autocfg;
2609 if (cfg->line_outs == 1 && !spec->multi_ios &&
2610 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
2613 switch (cfg->line_out_type) {
2614 case AUTO_PIN_SPEAKER_OUT:
2615 if (cfg->line_outs == 1)
2617 if (cfg->line_outs == 2)
2618 return ch ? "Bass Speaker" : "Speaker";
2620 case AUTO_PIN_HP_OUT:
2621 /* for multi-io case, only the primary out */
2622 if (ch && spec->multi_ios)
2627 if (cfg->line_outs == 1 && !spec->multi_ios)
2631 if (ch >= ARRAY_SIZE(channel_name)) {
2636 return channel_name[ch];
2639 static bool parse_nid_path(struct hda_codec *codec, hda_nid_t from_nid,
2640 hda_nid_t to_nid, int with_aa_mix,
2641 struct nid_path *path);
2644 /* add the powersave loopback-list entry */
2645 static void add_loopback_list(struct alc_spec *spec, hda_nid_t mix, int idx)
2647 struct hda_amp_list *list;
2649 if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
2651 list = spec->loopback_list + spec->num_loopbacks;
2653 list->dir = HDA_INPUT;
2655 spec->num_loopbacks++;
2656 spec->loopback.amplist = spec->loopback_list;
2659 #define add_loopback_list(spec, mix, idx) /* NOP */
2662 /* create input playback/capture controls for the given pin */
2663 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
2664 const char *ctlname, int ctlidx,
2665 int idx, hda_nid_t mix_nid)
2669 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
2670 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2673 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
2674 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2677 add_loopback_list(spec, mix_nid, idx);
2681 static int new_capture_source(struct hda_codec *codec, int adc_idx,
2682 hda_nid_t pin, int idx, const char *label)
2684 struct alc_spec *spec = codec->spec;
2685 struct hda_input_mux *imux = &spec->private_imux[0];
2686 struct nid_path *path;
2688 path = snd_array_new(&spec->in_path);
2691 memset(path, 0, sizeof(*path));
2692 if (!parse_nid_path(codec, pin, spec->adc_nids[adc_idx], 2, path)) {
2693 snd_printd(KERN_ERR "invalid input path 0x%x -> 0x%x\n",
2694 pin, spec->adc_nids[adc_idx]);
2698 spec->imux_pins[imux->num_items] = pin;
2699 snd_hda_add_imux_item(imux, label, idx, NULL);
2703 static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
2705 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2706 return (pincap & AC_PINCAP_IN) != 0;
2709 /* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
2710 static int alc_auto_fill_adc_caps(struct hda_codec *codec)
2712 struct alc_spec *spec = codec->spec;
2714 hda_nid_t *adc_nids = spec->private_adc_nids;
2715 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2716 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
2719 nid = codec->start_nid;
2720 for (i = 0; i < codec->num_nodes; i++, nid++) {
2722 unsigned int caps = get_wcaps(codec, nid);
2723 int type = get_wcaps_type(caps);
2725 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2727 adc_nids[nums] = nid;
2728 cap_nids[nums] = nid;
2732 type = get_wcaps_type(get_wcaps(codec, src));
2733 if (type == AC_WID_PIN)
2735 if (type == AC_WID_AUD_SEL) {
2736 cap_nids[nums] = src;
2739 n = snd_hda_get_num_conns(codec, src);
2741 cap_nids[nums] = src;
2745 if (snd_hda_get_connections(codec, src, &src, 1) != 1)
2748 if (++nums >= max_nums)
2751 spec->adc_nids = spec->private_adc_nids;
2752 spec->capsrc_nids = spec->private_capsrc_nids;
2753 spec->num_adc_nids = nums;
2757 /* create playback/capture controls for input pins */
2758 static int alc_auto_create_input_ctls(struct hda_codec *codec)
2760 struct alc_spec *spec = codec->spec;
2761 const struct auto_pin_cfg *cfg = &spec->autocfg;
2762 hda_nid_t mixer = spec->mixer_nid;
2763 struct hda_input_mux *imux = &spec->private_imux[0];
2765 int i, c, err, idx, type_idx = 0;
2766 const char *prev_label = NULL;
2768 num_adcs = alc_auto_fill_adc_caps(codec);
2772 for (i = 0; i < cfg->num_inputs; i++) {
2776 pin = cfg->inputs[i].pin;
2777 if (!alc_is_input_pin(codec, pin))
2780 label = hda_get_autocfg_input_label(codec, cfg, i);
2781 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
2782 label = "Headphone Mic";
2783 if (prev_label && !strcmp(label, prev_label))
2790 idx = get_connection_index(codec, mixer, pin);
2792 err = new_analog_input(spec, pin,
2800 for (c = 0; c < num_adcs; c++) {
2801 hda_nid_t cap = get_capsrc(spec, c);
2802 idx = get_connection_index(codec, cap, pin);
2804 err = new_capture_source(codec, c, pin, idx, label);
2812 spec->num_mux_defs = 1;
2813 spec->input_mux = imux;
2818 /* create a shared input with the headphone out */
2819 static int alc_auto_create_shared_input(struct hda_codec *codec)
2821 struct alc_spec *spec = codec->spec;
2822 struct auto_pin_cfg *cfg = &spec->autocfg;
2823 unsigned int defcfg;
2826 /* only one internal input pin? */
2827 if (cfg->num_inputs != 1)
2829 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2830 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2833 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
2834 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
2835 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
2836 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
2838 return 0; /* both not available */
2840 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2841 return 0; /* no input */
2843 cfg->inputs[1].pin = nid;
2844 cfg->inputs[1].type = AUTO_PIN_MIC;
2845 cfg->num_inputs = 2;
2846 spec->shared_mic_hp = 1;
2847 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
2851 static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
2852 unsigned int pin_type)
2854 snd_hda_set_pin_ctl(codec, nid, pin_type);
2856 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2857 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2861 static int get_pin_type(int line_out_type)
2863 if (line_out_type == AUTO_PIN_HP_OUT)
2869 static void alc_auto_init_analog_input(struct hda_codec *codec)
2871 struct alc_spec *spec = codec->spec;
2872 struct auto_pin_cfg *cfg = &spec->autocfg;
2875 for (i = 0; i < cfg->num_inputs; i++) {
2876 hda_nid_t nid = cfg->inputs[i].pin;
2877 if (alc_is_input_pin(codec, nid)) {
2878 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
2879 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
2880 snd_hda_codec_write(codec, nid, 0,
2881 AC_VERB_SET_AMP_GAIN_MUTE,
2886 /* mute all loopback inputs */
2887 if (spec->mixer_nid) {
2888 int nums = snd_hda_get_num_conns(codec, spec->mixer_nid);
2889 for (i = 0; i < nums; i++)
2890 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2891 AC_VERB_SET_AMP_GAIN_MUTE,
2896 static bool alc_is_dac_already_used(struct hda_codec *codec, hda_nid_t nid)
2898 struct alc_spec *spec = codec->spec;
2901 for (i = 0; i < spec->out_path.used; i++) {
2902 struct nid_path *path = snd_array_elem(&spec->out_path, i);
2903 if (path->path[0] == nid)
2909 /* check whether the DAC is reachable from the pin */
2910 static bool alc_auto_is_dac_reachable(struct hda_codec *codec,
2911 hda_nid_t pin, hda_nid_t dac)
2915 return snd_hda_get_conn_index(codec, pin, dac, true) >= 0;
2918 /* look for an empty DAC slot */
2919 static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
2921 struct alc_spec *spec = codec->spec;
2924 for (i = 0; i < spec->num_all_dacs; i++) {
2925 hda_nid_t nid = spec->all_dacs[i];
2926 if (!nid || alc_is_dac_already_used(codec, nid))
2928 if (alc_auto_is_dac_reachable(codec, pin, nid))
2934 /* called recursively */
2935 static bool __parse_nid_path(struct hda_codec *codec,
2936 hda_nid_t from_nid, hda_nid_t to_nid,
2937 int with_aa_mix, struct nid_path *path, int depth)
2939 struct alc_spec *spec = codec->spec;
2943 if (to_nid == spec->mixer_nid) {
2946 with_aa_mix = 2; /* mark aa-mix is included */
2949 nums = snd_hda_get_connections(codec, to_nid, conn, ARRAY_SIZE(conn));
2950 for (i = 0; i < nums; i++) {
2951 if (conn[i] != from_nid) {
2952 /* special case: when from_nid is 0,
2953 * try to find an empty DAC
2956 get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT ||
2957 alc_is_dac_already_used(codec, conn[i]))
2960 /* aa-mix is requested but not included? */
2961 if (!(spec->mixer_nid && with_aa_mix == 1))
2964 if (depth >= MAX_NID_PATH_DEPTH)
2966 for (i = 0; i < nums; i++) {
2968 type = get_wcaps_type(get_wcaps(codec, conn[i]));
2969 if (type == AC_WID_AUD_OUT || type == AC_WID_AUD_IN ||
2972 if (__parse_nid_path(codec, from_nid, conn[i],
2973 with_aa_mix, path, depth + 1))
2979 path->path[path->depth] = conn[i];
2980 path->idx[path->depth + 1] = i;
2981 if (nums > 1 && get_wcaps_type(get_wcaps(codec, to_nid)) != AC_WID_AUD_MIX)
2982 path->multi[path->depth + 1] = 1;
2987 /* parse the widget path from the given nid to the target nid;
2988 * when @from_nid is 0, try to find an empty DAC;
2989 * when @with_aa_mix is 0, paths with spec->mixer_nid are excluded.
2990 * when @with_aa_mix is 1, paths without spec->mixer_nid are excluded.
2991 * when @with_aa_mix is 2, no special handling about spec->mixer_nid.
2993 static bool parse_nid_path(struct hda_codec *codec, hda_nid_t from_nid,
2994 hda_nid_t to_nid, int with_aa_mix,
2995 struct nid_path *path)
2997 if (__parse_nid_path(codec, from_nid, to_nid, with_aa_mix, path, 1)) {
2998 path->path[path->depth] = to_nid;
3001 snd_printdd("path: depth=%d, %02x/%02x/%02x/%02x/%02x\n",
3002 path->depth, path->path[0], path->path[1],
3003 path->path[2], path->path[3], path->path[4]);
3010 static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
3012 struct alc_spec *spec = codec->spec;
3014 hda_nid_t nid_found = 0;
3016 for (i = 0; i < spec->num_all_dacs; i++) {
3017 hda_nid_t nid = spec->all_dacs[i];
3018 if (!nid || alc_is_dac_already_used(codec, nid))
3020 if (alc_auto_is_dac_reachable(codec, pin, nid)) {
3029 static bool is_ctl_used(struct hda_codec *codec, unsigned int val, int type)
3031 struct alc_spec *spec = codec->spec;
3034 for (i = 0; i < spec->out_path.used; i++) {
3035 struct nid_path *path = snd_array_elem(&spec->out_path, i);
3036 if (path->ctls[type] == val)
3042 /* badness definition */
3044 /* No primary DAC is found for the main output */
3045 BAD_NO_PRIMARY_DAC = 0x10000,
3046 /* No DAC is found for the extra output */
3047 BAD_NO_DAC = 0x4000,
3048 /* No possible multi-ios */
3049 BAD_MULTI_IO = 0x103,
3050 /* No individual DAC for extra output */
3051 BAD_NO_EXTRA_DAC = 0x102,
3052 /* No individual DAC for extra surrounds */
3053 BAD_NO_EXTRA_SURR_DAC = 0x101,
3054 /* Primary DAC shared with main surrounds */
3055 BAD_SHARED_SURROUND = 0x100,
3056 /* Primary DAC shared with main CLFE */
3057 BAD_SHARED_CLFE = 0x10,
3058 /* Primary DAC shared with extra surrounds */
3059 BAD_SHARED_EXTRA_SURROUND = 0x10,
3060 /* Volume widget is shared */
3061 BAD_SHARED_VOL = 0x10,
3064 static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3065 struct nid_path *path);
3066 static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3067 struct nid_path *path);
3069 static bool add_new_out_path(struct hda_codec *codec, hda_nid_t pin,
3072 struct alc_spec *spec = codec->spec;
3073 struct nid_path *path;
3075 path = snd_array_new(&spec->out_path);
3078 memset(path, 0, sizeof(*path));
3079 if (parse_nid_path(codec, dac, pin, 0, path))
3082 spec->out_path.used--;
3086 /* get the path pointing from the given dac to pin;
3087 * passing 0 to either @pin or @dac behaves as a wildcard
3089 static struct nid_path *get_out_path(struct hda_codec *codec, hda_nid_t pin,
3092 struct alc_spec *spec = codec->spec;
3095 for (i = 0; i < spec->out_path.used; i++) {
3096 struct nid_path *path = snd_array_elem(&spec->out_path, i);
3097 if (path->depth <= 0)
3099 if ((!dac || path->path[0] == dac) &&
3100 (!pin || path->path[path->depth - 1] == pin))
3106 /* look for widgets in the path between the given NIDs appropriate for
3107 * volume and mute controls, and assign the values to ctls[].
3109 * When no appropriate widget is found in the path, the badness value
3110 * is incremented depending on the situation. The function returns the
3111 * total badness for both volume and mute controls.
3113 static int assign_out_path_ctls(struct hda_codec *codec, hda_nid_t pin,
3116 struct nid_path *path = get_out_path(codec, pin, dac);
3122 return BAD_SHARED_VOL * 2;
3123 nid = alc_look_for_out_vol_nid(codec, path);
3125 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3126 if (is_ctl_used(codec, val, NID_PATH_VOL_CTL))
3127 badness += BAD_SHARED_VOL;
3129 path->ctls[NID_PATH_VOL_CTL] = val;
3131 badness += BAD_SHARED_VOL;
3132 nid = alc_look_for_out_mute_nid(codec, path);
3134 unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid));
3135 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT ||
3136 nid_has_mute(codec, nid, HDA_OUTPUT))
3137 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3139 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
3140 if (is_ctl_used(codec, val, NID_PATH_MUTE_CTL))
3141 badness += BAD_SHARED_VOL;
3143 path->ctls[NID_PATH_MUTE_CTL] = val;
3145 badness += BAD_SHARED_VOL;
3149 struct badness_table {
3150 int no_primary_dac; /* no primary DAC */
3151 int no_dac; /* no secondary DACs */
3152 int shared_primary; /* primary DAC is shared with main output */
3153 int shared_surr; /* secondary DAC shared with main or primary */
3154 int shared_clfe; /* third DAC shared with main or primary */
3155 int shared_surr_main; /* secondary DAC sahred with main/DAC0 */
3158 static struct badness_table main_out_badness = {
3159 .no_primary_dac = BAD_NO_PRIMARY_DAC,
3160 .no_dac = BAD_NO_DAC,
3161 .shared_primary = BAD_NO_PRIMARY_DAC,
3162 .shared_surr = BAD_SHARED_SURROUND,
3163 .shared_clfe = BAD_SHARED_CLFE,
3164 .shared_surr_main = BAD_SHARED_SURROUND,
3167 static struct badness_table extra_out_badness = {
3168 .no_primary_dac = BAD_NO_DAC,
3169 .no_dac = BAD_NO_DAC,
3170 .shared_primary = BAD_NO_EXTRA_DAC,
3171 .shared_surr = BAD_SHARED_EXTRA_SURROUND,
3172 .shared_clfe = BAD_SHARED_EXTRA_SURROUND,
3173 .shared_surr_main = BAD_NO_EXTRA_SURR_DAC,
3176 /* try to assign DACs to pins and return the resultant badness */
3177 static int alc_auto_fill_dacs(struct hda_codec *codec, int num_outs,
3178 const hda_nid_t *pins, hda_nid_t *dacs,
3179 const struct badness_table *bad)
3181 struct alc_spec *spec = codec->spec;
3182 struct auto_pin_cfg *cfg = &spec->autocfg;
3190 for (i = 0; i < num_outs; i++) {
3191 hda_nid_t pin = pins[i];
3193 dacs[i] = alc_auto_look_for_dac(codec, pin);
3194 if (!dacs[i] && !i) {
3195 for (j = 1; j < num_outs; j++) {
3196 if (alc_auto_is_dac_reachable(codec, pin, dacs[j])) {
3205 if (alc_auto_is_dac_reachable(codec, pin, dacs[0]))
3207 else if (cfg->line_outs > i &&
3208 alc_auto_is_dac_reachable(codec, pin,
3209 spec->private_dac_nids[i]))
3210 dac = spec->private_dac_nids[i];
3213 badness += bad->shared_primary;
3215 badness += bad->shared_surr;
3217 badness += bad->shared_clfe;
3218 } else if (alc_auto_is_dac_reachable(codec, pin,
3219 spec->private_dac_nids[0])) {
3220 dac = spec->private_dac_nids[0];
3221 badness += bad->shared_surr_main;
3223 badness += bad->no_primary_dac;
3225 badness += bad->no_dac;
3227 if (!add_new_out_path(codec, pin, dac))
3230 badness += assign_out_path_ctls(codec, pin, dac);
3236 static int alc_auto_fill_multi_ios(struct hda_codec *codec,
3237 hda_nid_t reference_pin,
3238 bool hardwired, int offset);
3240 static bool alc_map_singles(struct hda_codec *codec, int outs,
3241 const hda_nid_t *pins, hda_nid_t *dacs)
3245 for (i = 0; i < outs; i++) {
3249 dac = get_dac_if_single(codec, pins[i]);
3252 if (add_new_out_path(codec, pins[i], dac)) {
3260 /* fill in the dac_nids table from the parsed pin configuration */
3261 static int fill_and_eval_dacs(struct hda_codec *codec,
3262 bool fill_hardwired,
3263 bool fill_mio_first)
3265 struct alc_spec *spec = codec->spec;
3266 struct auto_pin_cfg *cfg = &spec->autocfg;
3267 int i, err, badness;
3269 /* set num_dacs once to full for alc_auto_look_for_dac() */
3270 spec->multiout.num_dacs = cfg->line_outs;
3271 spec->multiout.dac_nids = spec->private_dac_nids;
3272 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
3273 memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid));
3274 memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid));
3275 spec->multi_ios = 0;
3276 snd_array_free(&spec->out_path);
3279 /* fill hard-wired DACs first */
3280 if (fill_hardwired) {
3283 mapped = alc_map_singles(codec, cfg->line_outs,
3285 spec->private_dac_nids);
3286 mapped |= alc_map_singles(codec, cfg->hp_outs,
3288 spec->multiout.hp_out_nid);
3289 mapped |= alc_map_singles(codec, cfg->speaker_outs,
3291 spec->multiout.extra_out_nid);
3292 if (fill_mio_first && cfg->line_outs == 1 &&
3293 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3294 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], true, 0);
3301 badness += alc_auto_fill_dacs(codec, cfg->line_outs, cfg->line_out_pins,
3302 spec->private_dac_nids,
3305 /* re-count num_dacs and squash invalid entries */
3306 spec->multiout.num_dacs = 0;
3307 for (i = 0; i < cfg->line_outs; i++) {
3308 if (spec->private_dac_nids[i])
3309 spec->multiout.num_dacs++;
3311 memmove(spec->private_dac_nids + i,
3312 spec->private_dac_nids + i + 1,
3313 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
3314 spec->private_dac_nids[cfg->line_outs - 1] = 0;
3318 if (fill_mio_first &&
3319 cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3320 /* try to fill multi-io first */
3321 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
3324 /* we don't count badness at this stage yet */
3327 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
3328 err = alc_auto_fill_dacs(codec, cfg->hp_outs, cfg->hp_pins,
3329 spec->multiout.hp_out_nid,
3330 &extra_out_badness);
3335 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3336 err = alc_auto_fill_dacs(codec, cfg->speaker_outs,
3338 spec->multiout.extra_out_nid,
3339 &extra_out_badness);
3344 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3345 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
3350 if (cfg->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3351 /* try multi-ios with HP + inputs */
3353 if (cfg->line_outs >= 3)
3355 err = alc_auto_fill_multi_ios(codec, cfg->hp_pins[0], false,
3362 if (spec->multi_ios == 2) {
3363 for (i = 0; i < 2; i++)
3364 spec->private_dac_nids[spec->multiout.num_dacs++] =
3365 spec->multi_io[i].dac;
3366 spec->ext_channel_count = 2;
3367 } else if (spec->multi_ios) {
3368 spec->multi_ios = 0;
3369 badness += BAD_MULTI_IO;
3375 #define DEBUG_BADNESS
3377 #ifdef DEBUG_BADNESS
3378 #define debug_badness snd_printdd
3380 #define debug_badness(...)
3383 static void debug_show_configs(struct alc_spec *spec, struct auto_pin_cfg *cfg)
3385 debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3386 cfg->line_out_pins[0], cfg->line_out_pins[1],
3387 cfg->line_out_pins[2], cfg->line_out_pins[2],
3388 spec->multiout.dac_nids[0],
3389 spec->multiout.dac_nids[1],
3390 spec->multiout.dac_nids[2],
3391 spec->multiout.dac_nids[3]);
3392 if (spec->multi_ios > 0)
3393 debug_badness("multi_ios(%d) = %x/%x : %x/%x\n",
3395 spec->multi_io[0].pin, spec->multi_io[1].pin,
3396 spec->multi_io[0].dac, spec->multi_io[1].dac);
3397 debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3398 cfg->hp_pins[0], cfg->hp_pins[1],
3399 cfg->hp_pins[2], cfg->hp_pins[2],
3400 spec->multiout.hp_out_nid[0],
3401 spec->multiout.hp_out_nid[1],
3402 spec->multiout.hp_out_nid[2],
3403 spec->multiout.hp_out_nid[3]);
3404 debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3405 cfg->speaker_pins[0], cfg->speaker_pins[1],
3406 cfg->speaker_pins[2], cfg->speaker_pins[3],
3407 spec->multiout.extra_out_nid[0],
3408 spec->multiout.extra_out_nid[1],
3409 spec->multiout.extra_out_nid[2],
3410 spec->multiout.extra_out_nid[3]);
3413 /* find all available DACs of the codec */
3414 static void alc_fill_all_nids(struct hda_codec *codec)
3416 struct alc_spec *spec = codec->spec;
3418 hda_nid_t nid = codec->start_nid;
3420 spec->num_all_dacs = 0;
3421 memset(spec->all_dacs, 0, sizeof(spec->all_dacs));
3422 for (i = 0; i < codec->num_nodes; i++, nid++) {
3423 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_OUT)
3425 if (spec->num_all_dacs >= ARRAY_SIZE(spec->all_dacs)) {
3426 snd_printk(KERN_ERR "hda: Too many DACs!\n");
3429 spec->all_dacs[spec->num_all_dacs++] = nid;
3433 static int alc_auto_fill_dac_nids(struct hda_codec *codec)
3435 struct alc_spec *spec = codec->spec;
3436 struct auto_pin_cfg *cfg = &spec->autocfg;
3437 struct auto_pin_cfg *best_cfg;
3438 int best_badness = INT_MAX;
3440 bool fill_hardwired = true, fill_mio_first = true;
3441 bool best_wired = true, best_mio = true;
3442 bool hp_spk_swapped = false;
3444 alc_fill_all_nids(codec);
3446 best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL);
3452 badness = fill_and_eval_dacs(codec, fill_hardwired,
3458 debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n",
3459 cfg->line_out_type, fill_hardwired, fill_mio_first,
3461 debug_show_configs(spec, cfg);
3462 if (badness < best_badness) {
3463 best_badness = badness;
3465 best_wired = fill_hardwired;
3466 best_mio = fill_mio_first;
3470 fill_mio_first = !fill_mio_first;
3471 if (!fill_mio_first)
3473 fill_hardwired = !fill_hardwired;
3474 if (!fill_hardwired)
3478 hp_spk_swapped = true;
3479 if (cfg->speaker_outs > 0 &&
3480 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3481 cfg->hp_outs = cfg->line_outs;
3482 memcpy(cfg->hp_pins, cfg->line_out_pins,
3483 sizeof(cfg->hp_pins));
3484 cfg->line_outs = cfg->speaker_outs;
3485 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3486 sizeof(cfg->speaker_pins));
3487 cfg->speaker_outs = 0;
3488 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3489 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
3490 fill_hardwired = true;
3493 if (cfg->hp_outs > 0 &&
3494 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3495 cfg->speaker_outs = cfg->line_outs;
3496 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3497 sizeof(cfg->speaker_pins));
3498 cfg->line_outs = cfg->hp_outs;
3499 memcpy(cfg->line_out_pins, cfg->hp_pins,
3500 sizeof(cfg->hp_pins));
3502 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3503 cfg->line_out_type = AUTO_PIN_HP_OUT;
3504 fill_hardwired = true;
3512 fill_and_eval_dacs(codec, best_wired, best_mio);
3514 debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n",
3515 cfg->line_out_type, best_wired, best_mio);
3516 debug_show_configs(spec, cfg);
3518 if (cfg->line_out_pins[0]) {
3519 struct nid_path *path = get_out_path(codec,
3520 cfg->line_out_pins[0],
3521 spec->multiout.dac_nids[0]);
3523 spec->vmaster_nid = alc_look_for_out_vol_nid(codec, path);
3530 /* replace the channels in the composed amp value with the given number */
3531 static unsigned int amp_val_replace_channels(unsigned int val, unsigned int chs)
3533 val &= ~(0x3U << 16);
3538 static int alc_auto_add_vol_ctl(struct hda_codec *codec,
3539 const char *pfx, int cidx,
3541 struct nid_path *path)
3546 val = path->ctls[NID_PATH_VOL_CTL];
3549 val = amp_val_replace_channels(val, chs);
3550 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx, val);
3553 /* return the channel bits suitable for the given path->ctls[] */
3554 static int get_default_ch_nums(struct hda_codec *codec, struct nid_path *path,
3557 int chs = 1; /* mono (left only) */
3559 hda_nid_t nid = get_amp_nid_(path->ctls[type]);
3560 if (nid && (get_wcaps(codec, nid) & AC_WCAP_STEREO))
3561 chs = 3; /* stereo */
3566 static int alc_auto_add_stereo_vol(struct hda_codec *codec,
3567 const char *pfx, int cidx,
3568 struct nid_path *path)
3570 int chs = get_default_ch_nums(codec, path, NID_PATH_VOL_CTL);
3571 return alc_auto_add_vol_ctl(codec, pfx, cidx, chs, path);
3574 /* create a mute-switch for the given mixer widget;
3575 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3577 static int alc_auto_add_sw_ctl(struct hda_codec *codec,
3578 const char *pfx, int cidx,
3580 struct nid_path *path)
3583 int type = ALC_CTL_WIDGET_MUTE;
3587 val = path->ctls[NID_PATH_MUTE_CTL];
3590 val = amp_val_replace_channels(val, chs);
3591 if (get_amp_direction_(val) == HDA_INPUT) {
3592 hda_nid_t nid = get_amp_nid_(val);
3593 if (snd_hda_get_num_conns(codec, nid) > 1) {
3594 type = ALC_CTL_BIND_MUTE;
3595 val |= 2 << 19; /* FIXME: fixed two widgets, so far */
3598 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
3601 static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
3602 int cidx, struct nid_path *path)
3604 int chs = get_default_ch_nums(codec, path, NID_PATH_MUTE_CTL);
3605 return alc_auto_add_sw_ctl(codec, pfx, cidx, chs, path);
3608 static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3609 struct nid_path *path)
3613 for (i = path->depth - 1; i >= 0; i--) {
3614 if (nid_has_mute(codec, path->path[i], HDA_OUTPUT))
3615 return path->path[i];
3616 if (i != path->depth - 1 && i != 0 &&
3617 nid_has_mute(codec, path->path[i], HDA_INPUT))
3618 return path->path[i];
3623 static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3624 struct nid_path *path)
3628 for (i = path->depth - 1; i >= 0; i--) {
3629 if (nid_has_volume(codec, path->path[i], HDA_OUTPUT))
3630 return path->path[i];
3635 /* add playback controls from the parsed DAC table */
3636 static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
3637 const struct auto_pin_cfg *cfg)
3639 struct alc_spec *spec = codec->spec;
3640 int i, err, noutputs;
3642 noutputs = cfg->line_outs;
3643 if (spec->multi_ios > 0 && cfg->line_outs < 3)
3644 noutputs += spec->multi_ios;
3646 for (i = 0; i < noutputs; i++) {
3650 struct nid_path *path;
3652 dac = spec->multiout.dac_nids[i];
3655 if (i >= cfg->line_outs) {
3656 pin = spec->multi_io[i - 1].pin;
3658 name = channel_name[i];
3660 pin = cfg->line_out_pins[i];
3661 name = alc_get_line_out_pfx(spec, i, true, &index);
3664 path = get_out_path(codec, pin, dac);
3667 if (!name || !strcmp(name, "CLFE")) {
3669 err = alc_auto_add_vol_ctl(codec, "Center", 0, 1, path);
3672 err = alc_auto_add_vol_ctl(codec, "LFE", 0, 2, path);
3675 err = alc_auto_add_sw_ctl(codec, "Center", 0, 1, path);
3678 err = alc_auto_add_sw_ctl(codec, "LFE", 0, 2, path);
3682 err = alc_auto_add_stereo_vol(codec, name, index, path);
3685 err = alc_auto_add_stereo_sw(codec, name, index, path);
3693 static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
3694 hda_nid_t dac, const char *pfx,
3697 struct nid_path *path;
3700 path = get_out_path(codec, pin, dac);
3703 /* bind volume control will be created in the case of dac = 0 */
3705 err = alc_auto_add_stereo_vol(codec, pfx, cidx, path);
3709 err = alc_auto_add_stereo_sw(codec, pfx, cidx, path);
3715 static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3717 struct hda_ctl_ops *ops)
3719 struct alc_spec *spec = codec->spec;
3720 struct hda_bind_ctls **ctlp, *ctl;
3721 ctlp = snd_array_new(&spec->bind_ctls);
3724 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3731 /* add playback controls for speaker and HP outputs */
3732 static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3733 const hda_nid_t *pins,
3734 const hda_nid_t *dacs,
3737 struct alc_spec *spec = codec->spec;
3738 struct hda_bind_ctls *ctl;
3742 if (!num_pins || !pins[0])
3745 if (num_pins == 1) {
3746 hda_nid_t dac = *dacs;
3748 dac = spec->multiout.dac_nids[0];
3749 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
3752 for (i = 0; i < num_pins; i++) {
3754 if (dacs[num_pins - 1])
3755 dac = dacs[i]; /* with individual volumes */
3758 if (num_pins == 2 && i == 1 && !strcmp(pfx, "Speaker")) {
3759 err = alc_auto_create_extra_out(codec, pins[i], dac,
3761 } else if (num_pins >= 3) {
3762 snprintf(name, sizeof(name), "%s %s",
3763 pfx, channel_name[i]);
3764 err = alc_auto_create_extra_out(codec, pins[i], dac,
3767 err = alc_auto_create_extra_out(codec, pins[i], dac,
3773 if (dacs[num_pins - 1])
3776 /* Let's create a bind-controls for volumes */
3777 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3781 for (i = 0; i < num_pins; i++) {
3783 struct nid_path *path;
3784 if (!pins[i] || !dacs[i])
3786 path = get_out_path(codec, pins[i], dacs[i]);
3789 vol = alc_look_for_out_vol_nid(codec, path);
3792 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3795 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3796 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3803 static int alc_auto_create_hp_out(struct hda_codec *codec)
3805 struct alc_spec *spec = codec->spec;
3806 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3807 spec->autocfg.hp_pins,
3808 spec->multiout.hp_out_nid,
3812 static int alc_auto_create_speaker_out(struct hda_codec *codec)
3814 struct alc_spec *spec = codec->spec;
3815 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3816 spec->autocfg.speaker_pins,
3817 spec->multiout.extra_out_nid,
3821 /* is a volume or mute control already present? */
3822 static bool __is_out_ctl_present(struct hda_codec *codec,
3823 struct nid_path *exclude_path,
3824 hda_nid_t nid, int dir, int types)
3826 struct alc_spec *spec = codec->spec;
3829 for (i = 0; i < spec->out_path.used; i++) {
3830 struct nid_path *p = snd_array_elem(&spec->out_path, i);
3831 if (p == exclude_path || p->depth <= 0)
3833 for (type = 0; type < 2; type++) {
3834 if (types & (1 << type)) {
3835 unsigned int val = p->ctls[type];
3836 if (get_amp_nid_(val) == nid &&
3837 get_amp_direction_(val) == dir)
3845 #define is_out_ctl_present(codec, path, nid, dir) \
3846 __is_out_ctl_present(codec, path, nid, dir, 3) /* check both types */
3847 #define is_out_vol_ctl_present(codec, nid, dir) \
3848 __is_out_ctl_present(codec, NULL, nid, dir, 1 << NID_PATH_VOL_CTL)
3849 #define is_out_mute_ctl_present(codec, nid, dir) \
3850 __is_out_ctl_present(codec, NULL, nid, dir, 1 << NID_PATH_MUTE_CTL)
3852 static int get_default_amp_val(struct hda_codec *codec, hda_nid_t nid, int dir)
3854 unsigned int caps, offset;
3855 unsigned int val = 0;
3857 caps = query_amp_caps(codec, nid, dir);
3858 if (caps & AC_AMPCAP_NUM_STEPS) {
3859 offset = (caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT;
3860 /* if a volume control is assigned, set the lowest level
3861 * as default; otherwise set to 0dB
3863 if (is_out_vol_ctl_present(codec, nid, dir))
3868 if (caps & AC_AMPCAP_MUTE) {
3869 /* if a mute control is assigned, mute as default */
3870 if (is_out_mute_ctl_present(codec, nid, dir))
3871 val |= HDA_AMP_MUTE;
3876 /* configure the path from the given dac to the pin as the proper output */
3877 static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
3878 hda_nid_t pin, int pin_type,
3879 hda_nid_t dac, bool force)
3882 struct nid_path *path;
3884 alc_set_pin_output(codec, pin, pin_type);
3885 path = get_out_path(codec, pin, dac);
3889 for (i = path->depth - 1; i >= 0; i--) {
3890 hda_nid_t nid = path->path[i];
3892 snd_hda_codec_write(codec, nid, 0,
3893 AC_VERB_SET_CONNECT_SEL,
3896 if (i != 0 && i != path->depth - 1 &&
3897 (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) &&
3898 (force || !is_out_ctl_present(codec, path, nid,
3900 val = get_default_amp_val(codec, nid, HDA_INPUT);
3901 snd_hda_codec_write(codec, nid, 0,
3902 AC_VERB_SET_AMP_GAIN_MUTE,
3903 AMP_IN_UNMUTE(0) | val);
3904 snd_hda_codec_write(codec, nid, 0,
3905 AC_VERB_SET_AMP_GAIN_MUTE,
3906 AMP_IN_UNMUTE(1) | val);
3908 if ((get_wcaps(codec, nid) & AC_WCAP_OUT_AMP) &&
3909 (force || !is_out_ctl_present(codec, path, nid,
3911 val = get_default_amp_val(codec, nid, HDA_OUTPUT);
3912 snd_hda_codec_write(codec, nid, 0,
3913 AC_VERB_SET_AMP_GAIN_MUTE,
3914 AMP_OUT_UNMUTE | val);
3919 static void alc_auto_init_multi_out(struct hda_codec *codec)
3921 struct alc_spec *spec = codec->spec;
3922 int pin_type = get_pin_type(spec->autocfg.line_out_type);
3925 for (i = 0; i <= HDA_SIDE; i++) {
3926 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3928 alc_auto_set_output_and_unmute(codec, nid, pin_type,
3929 spec->multiout.dac_nids[i], true);
3934 static void alc_auto_init_extra_out(struct hda_codec *codec)
3936 struct alc_spec *spec = codec->spec;
3940 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3941 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3943 pin = spec->autocfg.hp_pins[i];
3946 dac = spec->multiout.hp_out_nid[i];
3948 if (i > 0 && spec->multiout.hp_out_nid[0])
3949 dac = spec->multiout.hp_out_nid[0];
3951 dac = spec->multiout.dac_nids[0];
3953 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac, true);
3955 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3956 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3958 pin = spec->autocfg.speaker_pins[i];
3961 dac = spec->multiout.extra_out_nid[i];
3963 if (i > 0 && spec->multiout.extra_out_nid[0])
3964 dac = spec->multiout.extra_out_nid[0];
3966 dac = spec->multiout.dac_nids[0];
3968 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac, true);
3972 /* check whether the given pin can be a multi-io pin */
3973 static bool can_be_multiio_pin(struct hda_codec *codec,
3974 unsigned int location, hda_nid_t nid)
3976 unsigned int defcfg, caps;
3978 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3979 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3981 if (location && get_defcfg_location(defcfg) != location)
3983 caps = snd_hda_query_pin_caps(codec, nid);
3984 if (!(caps & AC_PINCAP_OUT))
3992 * When hardwired is set, try to fill ony hardwired pins, and returns
3993 * zero if any pins are filled, non-zero if nothing found.
3994 * When hardwired is off, try to fill possible input pins, and returns
3995 * the badness value.
3997 static int alc_auto_fill_multi_ios(struct hda_codec *codec,
3998 hda_nid_t reference_pin,
3999 bool hardwired, int offset)
4001 struct alc_spec *spec = codec->spec;
4002 struct auto_pin_cfg *cfg = &spec->autocfg;
4003 int type, i, j, dacs, num_pins, old_pins;
4004 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
4005 unsigned int location = get_defcfg_location(defcfg);
4008 old_pins = spec->multi_ios;
4013 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
4014 for (i = 0; i < cfg->num_inputs; i++) {
4015 if (cfg->inputs[i].type != type)
4017 if (can_be_multiio_pin(codec, location,
4018 cfg->inputs[i].pin))
4025 dacs = spec->multiout.num_dacs;
4026 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
4027 for (i = 0; i < cfg->num_inputs; i++) {
4028 hda_nid_t nid = cfg->inputs[i].pin;
4031 if (cfg->inputs[i].type != type)
4033 if (!can_be_multiio_pin(codec, location, nid))
4035 for (j = 0; j < spec->multi_ios; j++) {
4036 if (nid == spec->multi_io[j].pin)
4039 if (j < spec->multi_ios)
4042 if (offset && offset + spec->multi_ios < dacs) {
4043 dac = spec->private_dac_nids[offset + spec->multi_ios];
4044 if (!alc_auto_is_dac_reachable(codec, nid, dac))
4048 dac = get_dac_if_single(codec, nid);
4050 dac = alc_auto_look_for_dac(codec, nid);
4055 if (!add_new_out_path(codec, nid, dac)) {
4059 spec->multi_io[spec->multi_ios].pin = nid;
4060 spec->multi_io[spec->multi_ios].dac = dac;
4062 if (spec->multi_ios >= 2)
4068 badness = BAD_MULTI_IO;
4069 if (old_pins == spec->multi_ios) {
4071 return 1; /* nothing found */
4073 return badness; /* no badness if nothing found */
4075 if (!hardwired && spec->multi_ios < 2) {
4076 /* cancel newly assigned paths */
4077 spec->out_path.used -= spec->multi_ios - old_pins;
4078 spec->multi_ios = old_pins;
4082 /* assign volume and mute controls */
4083 for (i = old_pins; i < spec->multi_ios; i++)
4084 badness += assign_out_path_ctls(codec, spec->multi_io[i].pin,
4085 spec->multi_io[i].dac);
4090 static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
4091 struct snd_ctl_elem_info *uinfo)
4093 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4094 struct alc_spec *spec = codec->spec;
4096 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
4098 uinfo->value.enumerated.items = spec->multi_ios + 1;
4099 if (uinfo->value.enumerated.item > spec->multi_ios)
4100 uinfo->value.enumerated.item = spec->multi_ios;
4101 sprintf(uinfo->value.enumerated.name, "%dch",
4102 (uinfo->value.enumerated.item + 1) * 2);
4106 static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
4107 struct snd_ctl_elem_value *ucontrol)
4109 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4110 struct alc_spec *spec = codec->spec;
4111 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
4115 static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
4117 struct alc_spec *spec = codec->spec;
4118 hda_nid_t nid = spec->multi_io[idx].pin;
4120 if (!spec->multi_io[idx].ctl_in)
4121 spec->multi_io[idx].ctl_in =
4122 snd_hda_codec_read(codec, nid, 0,
4123 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4125 snd_hda_set_pin_ctl_cache(codec, nid, PIN_OUT);
4126 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
4127 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
4129 alc_auto_set_output_and_unmute(codec, nid, PIN_OUT,
4130 spec->multi_io[idx].dac, false);
4132 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
4133 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
4134 HDA_AMP_MUTE, HDA_AMP_MUTE);
4135 snd_hda_set_pin_ctl_cache(codec, nid,
4136 spec->multi_io[idx].ctl_in);
4141 static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
4142 struct snd_ctl_elem_value *ucontrol)
4144 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4145 struct alc_spec *spec = codec->spec;
4148 ch = ucontrol->value.enumerated.item[0];
4149 if (ch < 0 || ch > spec->multi_ios)
4151 if (ch == (spec->ext_channel_count - 1) / 2)
4153 spec->ext_channel_count = (ch + 1) * 2;
4154 for (i = 0; i < spec->multi_ios; i++)
4155 alc_set_multi_io(codec, i, i < ch);
4156 spec->multiout.max_channels = max(spec->ext_channel_count,
4157 spec->const_channel_count);
4158 if (spec->need_dac_fix)
4159 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
4163 static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
4164 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4165 .name = "Channel Mode",
4166 .info = alc_auto_ch_mode_info,
4167 .get = alc_auto_ch_mode_get,
4168 .put = alc_auto_ch_mode_put,
4171 static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
4173 struct alc_spec *spec = codec->spec;
4175 if (spec->multi_ios > 0) {
4176 if (!alc_kcontrol_new(spec, "Channel Mode",
4177 &alc_auto_channel_mode_enum))
4183 /* filter out invalid adc_nids (and capsrc_nids) that don't give all
4186 static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
4188 struct alc_spec *spec = codec->spec;
4189 const struct hda_input_mux *imux;
4190 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4191 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4194 imux = spec->input_mux;
4197 if (spec->dyn_adc_switch)
4202 for (n = 0; n < spec->num_adc_nids; n++) {
4203 hda_nid_t cap = spec->private_capsrc_nids[n];
4204 int num_conns = snd_hda_get_num_conns(codec, cap);
4205 for (i = 0; i < imux->num_items; i++) {
4206 hda_nid_t pin = spec->imux_pins[i];
4208 if (get_connection_index(codec, cap, pin) < 0)
4210 } else if (num_conns <= imux->items[i].index)
4213 if (i >= imux->num_items) {
4214 adc_nids[nums] = spec->private_adc_nids[n];
4215 capsrc_nids[nums++] = cap;
4219 /* check whether ADC-switch is possible */
4220 if (!alc_check_dyn_adc_switch(codec)) {
4221 if (spec->shared_mic_hp) {
4222 spec->shared_mic_hp = 0;
4223 spec->private_imux[0].num_items = 1;
4226 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
4227 " using fallback 0x%x\n",
4228 codec->chip_name, spec->private_adc_nids[0]);
4229 spec->num_adc_nids = 1;
4233 } else if (nums != spec->num_adc_nids) {
4234 memcpy(spec->private_adc_nids, adc_nids,
4235 nums * sizeof(hda_nid_t));
4236 memcpy(spec->private_capsrc_nids, capsrc_nids,
4237 nums * sizeof(hda_nid_t));
4238 spec->num_adc_nids = nums;
4242 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
4243 else if (spec->input_mux->num_items == 1 || spec->shared_mic_hp)
4244 spec->num_adc_nids = 1; /* reduce to a single ADC */
4248 * initialize ADC paths
4250 static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
4252 struct alc_spec *spec = codec->spec;
4255 nid = spec->adc_nids[adc_idx];
4257 if (nid_has_mute(codec, nid, HDA_INPUT)) {
4258 snd_hda_codec_write(codec, nid, 0,
4259 AC_VERB_SET_AMP_GAIN_MUTE,
4263 if (!spec->capsrc_nids)
4265 nid = spec->capsrc_nids[adc_idx];
4266 if (nid_has_mute(codec, nid, HDA_OUTPUT))
4267 snd_hda_codec_write(codec, nid, 0,
4268 AC_VERB_SET_AMP_GAIN_MUTE,
4272 static void alc_auto_init_input_src(struct hda_codec *codec)
4274 struct alc_spec *spec = codec->spec;
4277 for (c = 0; c < spec->num_adc_nids; c++)
4278 alc_auto_init_adc(codec, c);
4279 if (spec->dyn_adc_switch)
4282 nums = spec->num_adc_nids;
4283 for (c = 0; c < nums; c++)
4284 alc_mux_select(codec, c, spec->cur_mux[c], true);
4287 /* add mic boosts if needed */
4288 static int alc_auto_add_mic_boost(struct hda_codec *codec)
4290 struct alc_spec *spec = codec->spec;
4291 struct auto_pin_cfg *cfg = &spec->autocfg;
4295 const char *prev_label = NULL;
4297 for (i = 0; i < cfg->num_inputs; i++) {
4298 if (cfg->inputs[i].type > AUTO_PIN_MIC)
4300 nid = cfg->inputs[i].pin;
4301 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
4303 char boost_label[32];
4305 label = hda_get_autocfg_input_label(codec, cfg, i);
4306 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
4307 label = "Headphone Mic";
4308 if (prev_label && !strcmp(label, prev_label))
4314 snprintf(boost_label, sizeof(boost_label),
4315 "%s Boost Volume", label);
4316 err = add_control(spec, ALC_CTL_WIDGET_VOL,
4317 boost_label, type_idx,
4318 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
4326 /* select or unmute the given capsrc route */
4327 static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
4330 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
4331 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
4333 } else if (snd_hda_get_num_conns(codec, cap) > 1) {
4334 snd_hda_codec_write_cache(codec, cap, 0,
4335 AC_VERB_SET_CONNECT_SEL, idx);
4339 /* set the default connection to that pin */
4340 static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
4342 struct alc_spec *spec = codec->spec;
4347 for (i = 0; i < spec->num_adc_nids; i++) {
4348 hda_nid_t cap = get_capsrc(spec, i);
4351 idx = get_connection_index(codec, cap, pin);
4354 select_or_unmute_capsrc(codec, cap, idx);
4355 return i; /* return the found index */
4357 return -1; /* not found */
4360 /* initialize some special cases for input sources */
4361 static void alc_init_special_input_src(struct hda_codec *codec)
4363 struct alc_spec *spec = codec->spec;
4366 for (i = 0; i < spec->autocfg.num_inputs; i++)
4367 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
4370 /* assign appropriate capture mixers */
4371 static void set_capture_mixer(struct hda_codec *codec)
4373 struct alc_spec *spec = codec->spec;
4374 static const struct snd_kcontrol_new *caps[2][3] = {
4375 { alc_capture_mixer_nosrc1,
4376 alc_capture_mixer_nosrc2,
4377 alc_capture_mixer_nosrc3 },
4378 { alc_capture_mixer1,
4380 alc_capture_mixer3 },
4383 /* check whether either of ADC or MUX has a volume control */
4384 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
4385 if (!spec->capsrc_nids)
4386 return; /* no volume */
4387 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
4388 return; /* no volume in capsrc, too */
4389 spec->vol_in_capsrc = 1;
4392 if (spec->num_adc_nids > 0) {
4396 if (spec->input_mux && spec->input_mux->num_items > 1)
4398 if (spec->auto_mic) {
4401 } else if (spec->dyn_adc_switch)
4404 if (spec->num_adc_nids > 3)
4405 spec->num_adc_nids = 3;
4406 else if (!spec->num_adc_nids)
4408 num_adcs = spec->num_adc_nids;
4410 spec->cap_mixer = caps[mux][num_adcs - 1];
4415 * standard auto-parser initializations
4417 static void alc_auto_init_std(struct hda_codec *codec)
4419 alc_auto_init_multi_out(codec);
4420 alc_auto_init_extra_out(codec);
4421 alc_auto_init_analog_input(codec);
4422 alc_auto_init_input_src(codec);
4423 alc_auto_init_digital(codec);
4424 alc_inithook(codec);
4428 * Digital-beep handlers
4430 #ifdef CONFIG_SND_HDA_INPUT_BEEP
4431 #define set_beep_amp(spec, nid, idx, dir) \
4432 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4434 static const struct snd_pci_quirk beep_white_list[] = {
4435 SND_PCI_QUIRK(0x1043, 0x103c, "ASUS", 1),
4436 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
4437 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
4438 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
4439 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
4440 SND_PCI_QUIRK(0x1458, 0xa002, "GA-MA790X", 1),
4441 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
4445 static inline int has_cdefine_beep(struct hda_codec *codec)
4447 struct alc_spec *spec = codec->spec;
4448 const struct snd_pci_quirk *q;
4449 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
4452 return spec->cdefine.enable_pcbeep;
4455 #define set_beep_amp(spec, nid, idx, dir) /* NOP */
4456 #define has_cdefine_beep(codec) 0
4459 /* parse the BIOS configuration and set up the alc_spec */
4460 /* return 1 if successful, 0 if the proper config is not found,
4461 * or a negative error code
4463 static int alc_parse_auto_config(struct hda_codec *codec,
4464 const hda_nid_t *ignore_nids,
4465 const hda_nid_t *ssid_nids)
4467 struct alc_spec *spec = codec->spec;
4468 struct auto_pin_cfg *cfg = &spec->autocfg;
4471 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
4475 if (!cfg->line_outs) {
4476 if (cfg->dig_outs || cfg->dig_in_pin) {
4477 spec->multiout.max_channels = 2;
4478 spec->no_analog = 1;
4481 return 0; /* can't find valid BIOS pin config */
4484 if (!spec->no_primary_hp &&
4485 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
4486 cfg->line_outs <= cfg->hp_outs) {
4487 /* use HP as primary out */
4488 cfg->speaker_outs = cfg->line_outs;
4489 memcpy(cfg->speaker_pins, cfg->line_out_pins,
4490 sizeof(cfg->speaker_pins));
4491 cfg->line_outs = cfg->hp_outs;
4492 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
4494 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
4495 cfg->line_out_type = AUTO_PIN_HP_OUT;
4498 err = alc_auto_fill_dac_nids(codec);
4501 err = alc_auto_add_multi_channel_mode(codec);
4504 err = alc_auto_create_multi_out_ctls(codec, cfg);
4507 err = alc_auto_create_hp_out(codec);
4510 err = alc_auto_create_speaker_out(codec);
4513 err = alc_auto_create_shared_input(codec);
4516 err = alc_auto_create_input_ctls(codec);
4520 /* check the multiple speaker pins */
4521 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
4522 spec->const_channel_count = cfg->line_outs * 2;
4524 spec->const_channel_count = cfg->speaker_outs * 2;
4526 if (spec->multi_ios > 0)
4527 spec->multiout.max_channels = max(spec->ext_channel_count,
4528 spec->const_channel_count);
4530 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4533 alc_auto_parse_digital(codec);
4535 if (!spec->no_analog)
4536 alc_remove_invalid_adc_nids(codec);
4539 alc_ssid_check(codec, ssid_nids);
4541 if (!spec->no_analog) {
4542 err = alc_auto_check_switches(codec);
4545 err = alc_auto_add_mic_boost(codec);
4550 if (spec->kctls.list)
4551 add_mixer(spec, spec->kctls.list);
4553 if (!spec->no_analog && !spec->cap_mixer)
4554 set_capture_mixer(codec);
4559 /* common preparation job for alc_spec */
4560 static int alc_alloc_spec(struct hda_codec *codec, hda_nid_t mixer_nid)
4562 struct alc_spec *spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4568 codec->single_adc_amp = 1;
4569 spec->mixer_nid = mixer_nid;
4570 snd_hda_gen_init(&spec->gen);
4571 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
4572 snd_array_init(&spec->bind_ctls, sizeof(struct hda_bind_ctls *), 8);
4573 snd_array_init(&spec->out_path, sizeof(struct nid_path), 8);
4574 snd_array_init(&spec->in_path, sizeof(struct nid_path), 8);
4576 err = alc_codec_rename_from_preset(codec);
4584 static int alc880_parse_auto_config(struct hda_codec *codec)
4586 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
4587 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4588 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
4597 ALC880_FIXUP_MEDION_RIM,
4600 ALC880_FIXUP_EAPD_COEF,
4601 ALC880_FIXUP_TCL_S700,
4602 ALC880_FIXUP_VOL_KNOB,
4603 ALC880_FIXUP_FUJITSU,
4605 ALC880_FIXUP_UNIWILL,
4606 ALC880_FIXUP_UNIWILL_DIG,
4608 ALC880_FIXUP_3ST_BASE,
4610 ALC880_FIXUP_3ST_DIG,
4611 ALC880_FIXUP_5ST_BASE,
4613 ALC880_FIXUP_5ST_DIG,
4614 ALC880_FIXUP_6ST_BASE,
4616 ALC880_FIXUP_6ST_DIG,
4619 /* enable the volume-knob widget support on NID 0x21 */
4620 static void alc880_fixup_vol_knob(struct hda_codec *codec,
4621 const struct alc_fixup *fix, int action)
4623 if (action == ALC_FIXUP_ACT_PROBE)
4624 snd_hda_jack_detect_enable_callback(codec, 0x21, ALC_DCVOL_EVENT, alc_update_knob_master);
4627 static const struct alc_fixup alc880_fixups[] = {
4628 [ALC880_FIXUP_GPIO1] = {
4629 .type = ALC_FIXUP_VERBS,
4630 .v.verbs = alc_gpio1_init_verbs,
4632 [ALC880_FIXUP_GPIO2] = {
4633 .type = ALC_FIXUP_VERBS,
4634 .v.verbs = alc_gpio2_init_verbs,
4636 [ALC880_FIXUP_MEDION_RIM] = {
4637 .type = ALC_FIXUP_VERBS,
4638 .v.verbs = (const struct hda_verb[]) {
4639 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4640 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4644 .chain_id = ALC880_FIXUP_GPIO2,
4646 [ALC880_FIXUP_LG] = {
4647 .type = ALC_FIXUP_PINS,
4648 .v.pins = (const struct alc_pincfg[]) {
4649 /* disable bogus unused pins */
4650 { 0x16, 0x411111f0 },
4651 { 0x18, 0x411111f0 },
4652 { 0x1a, 0x411111f0 },
4656 [ALC880_FIXUP_W810] = {
4657 .type = ALC_FIXUP_PINS,
4658 .v.pins = (const struct alc_pincfg[]) {
4659 /* disable bogus unused pins */
4660 { 0x17, 0x411111f0 },
4664 .chain_id = ALC880_FIXUP_GPIO2,
4666 [ALC880_FIXUP_EAPD_COEF] = {
4667 .type = ALC_FIXUP_VERBS,
4668 .v.verbs = (const struct hda_verb[]) {
4669 /* change to EAPD mode */
4670 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4671 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4675 [ALC880_FIXUP_TCL_S700] = {
4676 .type = ALC_FIXUP_VERBS,
4677 .v.verbs = (const struct hda_verb[]) {
4678 /* change to EAPD mode */
4679 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4680 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4684 .chain_id = ALC880_FIXUP_GPIO2,
4686 [ALC880_FIXUP_VOL_KNOB] = {
4687 .type = ALC_FIXUP_FUNC,
4688 .v.func = alc880_fixup_vol_knob,
4690 [ALC880_FIXUP_FUJITSU] = {
4691 /* override all pins as BIOS on old Amilo is broken */
4692 .type = ALC_FIXUP_PINS,
4693 .v.pins = (const struct alc_pincfg[]) {
4694 { 0x14, 0x0121411f }, /* HP */
4695 { 0x15, 0x99030120 }, /* speaker */
4696 { 0x16, 0x99030130 }, /* bass speaker */
4697 { 0x17, 0x411111f0 }, /* N/A */
4698 { 0x18, 0x411111f0 }, /* N/A */
4699 { 0x19, 0x01a19950 }, /* mic-in */
4700 { 0x1a, 0x411111f0 }, /* N/A */
4701 { 0x1b, 0x411111f0 }, /* N/A */
4702 { 0x1c, 0x411111f0 }, /* N/A */
4703 { 0x1d, 0x411111f0 }, /* N/A */
4704 { 0x1e, 0x01454140 }, /* SPDIF out */
4708 .chain_id = ALC880_FIXUP_VOL_KNOB,
4710 [ALC880_FIXUP_F1734] = {
4711 /* almost compatible with FUJITSU, but no bass and SPDIF */
4712 .type = ALC_FIXUP_PINS,
4713 .v.pins = (const struct alc_pincfg[]) {
4714 { 0x14, 0x0121411f }, /* HP */
4715 { 0x15, 0x99030120 }, /* speaker */
4716 { 0x16, 0x411111f0 }, /* N/A */
4717 { 0x17, 0x411111f0 }, /* N/A */
4718 { 0x18, 0x411111f0 }, /* N/A */
4719 { 0x19, 0x01a19950 }, /* mic-in */
4720 { 0x1a, 0x411111f0 }, /* N/A */
4721 { 0x1b, 0x411111f0 }, /* N/A */
4722 { 0x1c, 0x411111f0 }, /* N/A */
4723 { 0x1d, 0x411111f0 }, /* N/A */
4724 { 0x1e, 0x411111f0 }, /* N/A */
4728 .chain_id = ALC880_FIXUP_VOL_KNOB,
4730 [ALC880_FIXUP_UNIWILL] = {
4731 /* need to fix HP and speaker pins to be parsed correctly */
4732 .type = ALC_FIXUP_PINS,
4733 .v.pins = (const struct alc_pincfg[]) {
4734 { 0x14, 0x0121411f }, /* HP */
4735 { 0x15, 0x99030120 }, /* speaker */
4736 { 0x16, 0x99030130 }, /* bass speaker */
4740 [ALC880_FIXUP_UNIWILL_DIG] = {
4741 .type = ALC_FIXUP_PINS,
4742 .v.pins = (const struct alc_pincfg[]) {
4743 /* disable bogus unused pins */
4744 { 0x17, 0x411111f0 },
4745 { 0x19, 0x411111f0 },
4746 { 0x1b, 0x411111f0 },
4747 { 0x1f, 0x411111f0 },
4751 [ALC880_FIXUP_Z71V] = {
4752 .type = ALC_FIXUP_PINS,
4753 .v.pins = (const struct alc_pincfg[]) {
4754 /* set up the whole pins as BIOS is utterly broken */
4755 { 0x14, 0x99030120 }, /* speaker */
4756 { 0x15, 0x0121411f }, /* HP */
4757 { 0x16, 0x411111f0 }, /* N/A */
4758 { 0x17, 0x411111f0 }, /* N/A */
4759 { 0x18, 0x01a19950 }, /* mic-in */
4760 { 0x19, 0x411111f0 }, /* N/A */
4761 { 0x1a, 0x01813031 }, /* line-in */
4762 { 0x1b, 0x411111f0 }, /* N/A */
4763 { 0x1c, 0x411111f0 }, /* N/A */
4764 { 0x1d, 0x411111f0 }, /* N/A */
4765 { 0x1e, 0x0144111e }, /* SPDIF */
4769 [ALC880_FIXUP_3ST_BASE] = {
4770 .type = ALC_FIXUP_PINS,
4771 .v.pins = (const struct alc_pincfg[]) {
4772 { 0x14, 0x01014010 }, /* line-out */
4773 { 0x15, 0x411111f0 }, /* N/A */
4774 { 0x16, 0x411111f0 }, /* N/A */
4775 { 0x17, 0x411111f0 }, /* N/A */
4776 { 0x18, 0x01a19c30 }, /* mic-in */
4777 { 0x19, 0x0121411f }, /* HP */
4778 { 0x1a, 0x01813031 }, /* line-in */
4779 { 0x1b, 0x02a19c40 }, /* front-mic */
4780 { 0x1c, 0x411111f0 }, /* N/A */
4781 { 0x1d, 0x411111f0 }, /* N/A */
4782 /* 0x1e is filled in below */
4783 { 0x1f, 0x411111f0 }, /* N/A */
4787 [ALC880_FIXUP_3ST] = {
4788 .type = ALC_FIXUP_PINS,
4789 .v.pins = (const struct alc_pincfg[]) {
4790 { 0x1e, 0x411111f0 }, /* N/A */
4794 .chain_id = ALC880_FIXUP_3ST_BASE,
4796 [ALC880_FIXUP_3ST_DIG] = {
4797 .type = ALC_FIXUP_PINS,
4798 .v.pins = (const struct alc_pincfg[]) {
4799 { 0x1e, 0x0144111e }, /* SPDIF */
4803 .chain_id = ALC880_FIXUP_3ST_BASE,
4805 [ALC880_FIXUP_5ST_BASE] = {
4806 .type = ALC_FIXUP_PINS,
4807 .v.pins = (const struct alc_pincfg[]) {
4808 { 0x14, 0x01014010 }, /* front */
4809 { 0x15, 0x411111f0 }, /* N/A */
4810 { 0x16, 0x01011411 }, /* CLFE */
4811 { 0x17, 0x01016412 }, /* surr */
4812 { 0x18, 0x01a19c30 }, /* mic-in */
4813 { 0x19, 0x0121411f }, /* HP */
4814 { 0x1a, 0x01813031 }, /* line-in */
4815 { 0x1b, 0x02a19c40 }, /* front-mic */
4816 { 0x1c, 0x411111f0 }, /* N/A */
4817 { 0x1d, 0x411111f0 }, /* N/A */
4818 /* 0x1e is filled in below */
4819 { 0x1f, 0x411111f0 }, /* N/A */
4823 [ALC880_FIXUP_5ST] = {
4824 .type = ALC_FIXUP_PINS,
4825 .v.pins = (const struct alc_pincfg[]) {
4826 { 0x1e, 0x411111f0 }, /* N/A */
4830 .chain_id = ALC880_FIXUP_5ST_BASE,
4832 [ALC880_FIXUP_5ST_DIG] = {
4833 .type = ALC_FIXUP_PINS,
4834 .v.pins = (const struct alc_pincfg[]) {
4835 { 0x1e, 0x0144111e }, /* SPDIF */
4839 .chain_id = ALC880_FIXUP_5ST_BASE,
4841 [ALC880_FIXUP_6ST_BASE] = {
4842 .type = ALC_FIXUP_PINS,
4843 .v.pins = (const struct alc_pincfg[]) {
4844 { 0x14, 0x01014010 }, /* front */
4845 { 0x15, 0x01016412 }, /* surr */
4846 { 0x16, 0x01011411 }, /* CLFE */
4847 { 0x17, 0x01012414 }, /* side */
4848 { 0x18, 0x01a19c30 }, /* mic-in */
4849 { 0x19, 0x02a19c40 }, /* front-mic */
4850 { 0x1a, 0x01813031 }, /* line-in */
4851 { 0x1b, 0x0121411f }, /* HP */
4852 { 0x1c, 0x411111f0 }, /* N/A */
4853 { 0x1d, 0x411111f0 }, /* N/A */
4854 /* 0x1e is filled in below */
4855 { 0x1f, 0x411111f0 }, /* N/A */
4859 [ALC880_FIXUP_6ST] = {
4860 .type = ALC_FIXUP_PINS,
4861 .v.pins = (const struct alc_pincfg[]) {
4862 { 0x1e, 0x411111f0 }, /* N/A */
4866 .chain_id = ALC880_FIXUP_6ST_BASE,
4868 [ALC880_FIXUP_6ST_DIG] = {
4869 .type = ALC_FIXUP_PINS,
4870 .v.pins = (const struct alc_pincfg[]) {
4871 { 0x1e, 0x0144111e }, /* SPDIF */
4875 .chain_id = ALC880_FIXUP_6ST_BASE,
4879 static const struct snd_pci_quirk alc880_fixup_tbl[] = {
4880 SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_FIXUP_W810),
4881 SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_FIXUP_Z71V),
4882 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_FIXUP_GPIO1),
4883 SND_PCI_QUIRK(0x1558, 0x5401, "Clevo GPIO2", ALC880_FIXUP_GPIO2),
4884 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo", ALC880_FIXUP_EAPD_COEF),
4885 SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_FIXUP_UNIWILL_DIG),
4886 SND_PCI_QUIRK(0x1584, 0x9054, "Uniwill", ALC880_FIXUP_F1734),
4887 SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_FIXUP_UNIWILL),
4888 SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_FIXUP_VOL_KNOB),
4889 SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_FIXUP_W810),
4890 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
4891 SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_FIXUP_F1734),
4892 SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FIXUP_FUJITSU),
4893 SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_FIXUP_F1734),
4894 SND_PCI_QUIRK(0x1734, 0x10b0, "FSC Amilo Pi1556", ALC880_FIXUP_FUJITSU),
4895 SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_FIXUP_LG),
4896 SND_PCI_QUIRK(0x1854, 0x005f, "LG P1 Express", ALC880_FIXUP_LG),
4897 SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_FIXUP_LG),
4898 SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_FIXUP_TCL_S700),
4900 /* Below is the copied entries from alc880_quirks.c.
4901 * It's not quite sure whether BIOS sets the correct pin-config table
4902 * on these machines, thus they are kept to be compatible with
4903 * the old static quirks. Once when it's confirmed to work without
4904 * these overrides, it'd be better to remove.
4906 SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_FIXUP_5ST_DIG),
4907 SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_FIXUP_6ST),
4908 SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_FIXUP_3ST_DIG),
4909 SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_FIXUP_6ST_DIG),
4910 SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_FIXUP_6ST_DIG),
4911 SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_FIXUP_6ST_DIG),
4912 SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_FIXUP_3ST_DIG),
4913 SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_FIXUP_3ST),
4914 SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_FIXUP_6ST_DIG),
4915 SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_FIXUP_3ST),
4916 SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_FIXUP_3ST),
4917 SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_FIXUP_5ST),
4918 SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_FIXUP_5ST),
4919 SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_FIXUP_5ST),
4920 SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_FIXUP_6ST_DIG),
4921 SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_FIXUP_6ST_DIG),
4922 SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_FIXUP_6ST_DIG),
4923 SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_FIXUP_6ST_DIG),
4924 SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_FIXUP_5ST_DIG),
4925 SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_FIXUP_5ST_DIG),
4926 SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_FIXUP_5ST_DIG),
4927 SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_FIXUP_6ST_DIG), /* broken BIOS */
4928 SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_FIXUP_6ST_DIG),
4929 SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4930 SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4931 SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4932 SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4933 SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4934 SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4935 SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4936 SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4937 SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4938 SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4940 SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_FIXUP_3ST),
4941 SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_FIXUP_5ST_DIG),
4942 SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_FIXUP_6ST_DIG),
4946 static const struct alc_model_fixup alc880_fixup_models[] = {
4947 {.id = ALC880_FIXUP_3ST, .name = "3stack"},
4948 {.id = ALC880_FIXUP_3ST_DIG, .name = "3stack-digout"},
4949 {.id = ALC880_FIXUP_5ST, .name = "5stack"},
4950 {.id = ALC880_FIXUP_5ST_DIG, .name = "5stack-digout"},
4951 {.id = ALC880_FIXUP_6ST, .name = "6stack"},
4952 {.id = ALC880_FIXUP_6ST_DIG, .name = "6stack-digout"},
4958 * OK, here we have finally the patch for ALC880
4960 static int patch_alc880(struct hda_codec *codec)
4962 struct alc_spec *spec;
4965 err = alc_alloc_spec(codec, 0x0b);
4970 spec->need_dac_fix = 1;
4972 alc_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl,
4974 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4976 /* automatic parse from the BIOS config */
4977 err = alc880_parse_auto_config(codec);
4981 if (!spec->no_analog) {
4982 err = snd_hda_attach_beep_device(codec, 0x1);
4985 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4988 codec->patch_ops = alc_patch_ops;
4989 codec->patch_ops.unsol_event = alc880_unsol_event;
4992 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5005 static int alc260_parse_auto_config(struct hda_codec *codec)
5007 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
5008 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
5009 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
5016 ALC260_FIXUP_HP_DC5750,
5017 ALC260_FIXUP_HP_PIN_0F,
5020 ALC260_FIXUP_GPIO1_TOGGLE,
5021 ALC260_FIXUP_REPLACER,
5022 ALC260_FIXUP_HP_B1900,
5026 static void alc260_gpio1_automute(struct hda_codec *codec)
5028 struct alc_spec *spec = codec->spec;
5029 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
5030 spec->hp_jack_present);
5033 static void alc260_fixup_gpio1_toggle(struct hda_codec *codec,
5034 const struct alc_fixup *fix, int action)
5036 struct alc_spec *spec = codec->spec;
5037 if (action == ALC_FIXUP_ACT_PROBE) {
5038 /* although the machine has only one output pin, we need to
5039 * toggle GPIO1 according to the jack state
5041 spec->automute_hook = alc260_gpio1_automute;
5042 spec->detect_hp = 1;
5043 spec->automute_speaker = 1;
5044 spec->autocfg.hp_pins[0] = 0x0f; /* copy it for automute */
5045 snd_hda_jack_detect_enable_callback(codec, 0x0f, ALC_HP_EVENT,
5047 snd_hda_gen_add_verbs(&spec->gen, alc_gpio1_init_verbs);
5051 static void alc260_fixup_kn1(struct hda_codec *codec,
5052 const struct alc_fixup *fix, int action)
5054 struct alc_spec *spec = codec->spec;
5055 static const struct alc_pincfg pincfgs[] = {
5056 { 0x0f, 0x02214000 }, /* HP/speaker */
5057 { 0x12, 0x90a60160 }, /* int mic */
5058 { 0x13, 0x02a19000 }, /* ext mic */
5059 { 0x18, 0x01446000 }, /* SPDIF out */
5060 /* disable bogus I/O pins */
5061 { 0x10, 0x411111f0 },
5062 { 0x11, 0x411111f0 },
5063 { 0x14, 0x411111f0 },
5064 { 0x15, 0x411111f0 },
5065 { 0x16, 0x411111f0 },
5066 { 0x17, 0x411111f0 },
5067 { 0x19, 0x411111f0 },
5072 case ALC_FIXUP_ACT_PRE_PROBE:
5073 alc_apply_pincfgs(codec, pincfgs);
5075 case ALC_FIXUP_ACT_PROBE:
5076 spec->init_amp = ALC_INIT_NONE;
5081 static const struct alc_fixup alc260_fixups[] = {
5082 [ALC260_FIXUP_HP_DC5750] = {
5083 .type = ALC_FIXUP_PINS,
5084 .v.pins = (const struct alc_pincfg[]) {
5085 { 0x11, 0x90130110 }, /* speaker */
5089 [ALC260_FIXUP_HP_PIN_0F] = {
5090 .type = ALC_FIXUP_PINS,
5091 .v.pins = (const struct alc_pincfg[]) {
5092 { 0x0f, 0x01214000 }, /* HP */
5096 [ALC260_FIXUP_COEF] = {
5097 .type = ALC_FIXUP_VERBS,
5098 .v.verbs = (const struct hda_verb[]) {
5099 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5100 { 0x20, AC_VERB_SET_PROC_COEF, 0x3040 },
5104 .chain_id = ALC260_FIXUP_HP_PIN_0F,
5106 [ALC260_FIXUP_GPIO1] = {
5107 .type = ALC_FIXUP_VERBS,
5108 .v.verbs = alc_gpio1_init_verbs,
5110 [ALC260_FIXUP_GPIO1_TOGGLE] = {
5111 .type = ALC_FIXUP_FUNC,
5112 .v.func = alc260_fixup_gpio1_toggle,
5114 .chain_id = ALC260_FIXUP_HP_PIN_0F,
5116 [ALC260_FIXUP_REPLACER] = {
5117 .type = ALC_FIXUP_VERBS,
5118 .v.verbs = (const struct hda_verb[]) {
5119 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5120 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5124 .chain_id = ALC260_FIXUP_GPIO1_TOGGLE,
5126 [ALC260_FIXUP_HP_B1900] = {
5127 .type = ALC_FIXUP_FUNC,
5128 .v.func = alc260_fixup_gpio1_toggle,
5130 .chain_id = ALC260_FIXUP_COEF,
5132 [ALC260_FIXUP_KN1] = {
5133 .type = ALC_FIXUP_FUNC,
5134 .v.func = alc260_fixup_kn1,
5138 static const struct snd_pci_quirk alc260_fixup_tbl[] = {
5139 SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_FIXUP_GPIO1),
5140 SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF),
5141 SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1),
5142 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750),
5143 SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900),
5144 SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1),
5145 SND_PCI_QUIRK(0x152d, 0x0729, "Quanta KN1", ALC260_FIXUP_KN1),
5146 SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER),
5147 SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_FIXUP_COEF),
5153 static int patch_alc260(struct hda_codec *codec)
5155 struct alc_spec *spec;
5158 err = alc_alloc_spec(codec, 0x07);
5164 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
5165 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5167 /* automatic parse from the BIOS config */
5168 err = alc260_parse_auto_config(codec);
5172 if (!spec->no_analog) {
5173 err = snd_hda_attach_beep_device(codec, 0x1);
5176 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
5179 codec->patch_ops = alc_patch_ops;
5180 spec->shutup = alc_eapd_shutup;
5182 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5193 * ALC882/883/885/888/889 support
5195 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
5196 * configuration. Each pin widget can choose any input DACs and a mixer.
5197 * Each ADC is connected from a mixer of all inputs. This makes possible
5198 * 6-channel independent captures.
5200 * In addition, an independent DAC for the multi-playback (not used in this
5208 ALC882_FIXUP_ABIT_AW9D_MAX,
5209 ALC882_FIXUP_LENOVO_Y530,
5210 ALC882_FIXUP_PB_M5210,
5211 ALC882_FIXUP_ACER_ASPIRE_7736,
5212 ALC882_FIXUP_ASUS_W90V,
5214 ALC889_FIXUP_VAIO_TT,
5215 ALC888_FIXUP_EEE1601,
5218 ALC883_FIXUP_ACER_EAPD,
5223 ALC882_FIXUP_ASUS_W2JC,
5224 ALC882_FIXUP_ACER_ASPIRE_4930G,
5225 ALC882_FIXUP_ACER_ASPIRE_8930G,
5226 ALC882_FIXUP_ASPIRE_8930G_VERBS,
5227 ALC885_FIXUP_MACPRO_GPIO,
5228 ALC889_FIXUP_DAC_ROUTE,
5229 ALC889_FIXUP_MBP_VREF,
5230 ALC889_FIXUP_IMAC91_VREF,
5231 ALC882_FIXUP_INV_DMIC,
5232 ALC882_FIXUP_NO_PRIMARY_HP,
5235 static void alc889_fixup_coef(struct hda_codec *codec,
5236 const struct alc_fixup *fix, int action)
5238 if (action != ALC_FIXUP_ACT_INIT)
5240 alc889_coef_init(codec);
5243 /* toggle speaker-output according to the hp-jack state */
5244 static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
5246 unsigned int gpiostate, gpiomask, gpiodir;
5248 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
5249 AC_VERB_GET_GPIO_DATA, 0);
5252 gpiostate |= (1 << pin);
5254 gpiostate &= ~(1 << pin);
5256 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
5257 AC_VERB_GET_GPIO_MASK, 0);
5258 gpiomask |= (1 << pin);
5260 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
5261 AC_VERB_GET_GPIO_DIRECTION, 0);
5262 gpiodir |= (1 << pin);
5265 snd_hda_codec_write(codec, codec->afg, 0,
5266 AC_VERB_SET_GPIO_MASK, gpiomask);
5267 snd_hda_codec_write(codec, codec->afg, 0,
5268 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
5272 snd_hda_codec_write(codec, codec->afg, 0,
5273 AC_VERB_SET_GPIO_DATA, gpiostate);
5276 /* set up GPIO at initialization */
5277 static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
5278 const struct alc_fixup *fix, int action)
5280 if (action != ALC_FIXUP_ACT_INIT)
5282 alc882_gpio_mute(codec, 0, 0);
5283 alc882_gpio_mute(codec, 1, 0);
5286 /* Fix the connection of some pins for ALC889:
5287 * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
5288 * work correctly (bko#42740)
5290 static void alc889_fixup_dac_route(struct hda_codec *codec,
5291 const struct alc_fixup *fix, int action)
5293 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
5294 /* fake the connections during parsing the tree */
5295 hda_nid_t conn1[2] = { 0x0c, 0x0d };
5296 hda_nid_t conn2[2] = { 0x0e, 0x0f };
5297 snd_hda_override_conn_list(codec, 0x14, 2, conn1);
5298 snd_hda_override_conn_list(codec, 0x15, 2, conn1);
5299 snd_hda_override_conn_list(codec, 0x18, 2, conn2);
5300 snd_hda_override_conn_list(codec, 0x1a, 2, conn2);
5301 } else if (action == ALC_FIXUP_ACT_PROBE) {
5302 /* restore the connections */
5303 hda_nid_t conn[5] = { 0x0c, 0x0d, 0x0e, 0x0f, 0x26 };
5304 snd_hda_override_conn_list(codec, 0x14, 5, conn);
5305 snd_hda_override_conn_list(codec, 0x15, 5, conn);
5306 snd_hda_override_conn_list(codec, 0x18, 5, conn);
5307 snd_hda_override_conn_list(codec, 0x1a, 5, conn);
5311 /* Set VREF on HP pin */
5312 static void alc889_fixup_mbp_vref(struct hda_codec *codec,
5313 const struct alc_fixup *fix, int action)
5315 struct alc_spec *spec = codec->spec;
5316 static hda_nid_t nids[2] = { 0x14, 0x15 };
5319 if (action != ALC_FIXUP_ACT_INIT)
5321 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5322 unsigned int val = snd_hda_codec_get_pincfg(codec, nids[i]);
5323 if (get_defcfg_device(val) != AC_JACK_HP_OUT)
5325 val = snd_hda_codec_read(codec, nids[i], 0,
5326 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5327 val |= AC_PINCTL_VREF_80;
5328 snd_hda_set_pin_ctl(codec, nids[i], val);
5329 spec->keep_vref_in_automute = 1;
5334 /* Set VREF on speaker pins on imac91 */
5335 static void alc889_fixup_imac91_vref(struct hda_codec *codec,
5336 const struct alc_fixup *fix, int action)
5338 struct alc_spec *spec = codec->spec;
5339 static hda_nid_t nids[2] = { 0x18, 0x1a };
5342 if (action != ALC_FIXUP_ACT_INIT)
5344 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5346 val = snd_hda_codec_read(codec, nids[i], 0,
5347 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5348 val |= AC_PINCTL_VREF_50;
5349 snd_hda_set_pin_ctl(codec, nids[i], val);
5351 spec->keep_vref_in_automute = 1;
5354 /* Don't take HP output as primary
5355 * strangely, the speaker output doesn't work on VAIO Z through DAC 0x05
5357 static void alc882_fixup_no_primary_hp(struct hda_codec *codec,
5358 const struct alc_fixup *fix, int action)
5360 struct alc_spec *spec = codec->spec;
5361 if (action == ALC_FIXUP_ACT_PRE_PROBE)
5362 spec->no_primary_hp = 1;
5365 static const struct alc_fixup alc882_fixups[] = {
5366 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
5367 .type = ALC_FIXUP_PINS,
5368 .v.pins = (const struct alc_pincfg[]) {
5369 { 0x15, 0x01080104 }, /* side */
5370 { 0x16, 0x01011012 }, /* rear */
5371 { 0x17, 0x01016011 }, /* clfe */
5375 [ALC882_FIXUP_LENOVO_Y530] = {
5376 .type = ALC_FIXUP_PINS,
5377 .v.pins = (const struct alc_pincfg[]) {
5378 { 0x15, 0x99130112 }, /* rear int speakers */
5379 { 0x16, 0x99130111 }, /* subwoofer */
5383 [ALC882_FIXUP_PB_M5210] = {
5384 .type = ALC_FIXUP_VERBS,
5385 .v.verbs = (const struct hda_verb[]) {
5386 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
5390 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
5391 .type = ALC_FIXUP_FUNC,
5392 .v.func = alc_fixup_sku_ignore,
5394 [ALC882_FIXUP_ASUS_W90V] = {
5395 .type = ALC_FIXUP_PINS,
5396 .v.pins = (const struct alc_pincfg[]) {
5397 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
5401 [ALC889_FIXUP_CD] = {
5402 .type = ALC_FIXUP_PINS,
5403 .v.pins = (const struct alc_pincfg[]) {
5404 { 0x1c, 0x993301f0 }, /* CD */
5408 [ALC889_FIXUP_VAIO_TT] = {
5409 .type = ALC_FIXUP_PINS,
5410 .v.pins = (const struct alc_pincfg[]) {
5411 { 0x17, 0x90170111 }, /* hidden surround speaker */
5415 [ALC888_FIXUP_EEE1601] = {
5416 .type = ALC_FIXUP_VERBS,
5417 .v.verbs = (const struct hda_verb[]) {
5418 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5419 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
5423 [ALC882_FIXUP_EAPD] = {
5424 .type = ALC_FIXUP_VERBS,
5425 .v.verbs = (const struct hda_verb[]) {
5426 /* change to EAPD mode */
5427 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5428 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
5432 [ALC883_FIXUP_EAPD] = {
5433 .type = ALC_FIXUP_VERBS,
5434 .v.verbs = (const struct hda_verb[]) {
5435 /* change to EAPD mode */
5436 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5437 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5441 [ALC883_FIXUP_ACER_EAPD] = {
5442 .type = ALC_FIXUP_VERBS,
5443 .v.verbs = (const struct hda_verb[]) {
5444 /* eanable EAPD on Acer laptops */
5445 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5446 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5450 [ALC882_FIXUP_GPIO1] = {
5451 .type = ALC_FIXUP_VERBS,
5452 .v.verbs = alc_gpio1_init_verbs,
5454 [ALC882_FIXUP_GPIO2] = {
5455 .type = ALC_FIXUP_VERBS,
5456 .v.verbs = alc_gpio2_init_verbs,
5458 [ALC882_FIXUP_GPIO3] = {
5459 .type = ALC_FIXUP_VERBS,
5460 .v.verbs = alc_gpio3_init_verbs,
5462 [ALC882_FIXUP_ASUS_W2JC] = {
5463 .type = ALC_FIXUP_VERBS,
5464 .v.verbs = alc_gpio1_init_verbs,
5466 .chain_id = ALC882_FIXUP_EAPD,
5468 [ALC889_FIXUP_COEF] = {
5469 .type = ALC_FIXUP_FUNC,
5470 .v.func = alc889_fixup_coef,
5472 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
5473 .type = ALC_FIXUP_PINS,
5474 .v.pins = (const struct alc_pincfg[]) {
5475 { 0x16, 0x99130111 }, /* CLFE speaker */
5476 { 0x17, 0x99130112 }, /* surround speaker */
5480 .chain_id = ALC882_FIXUP_GPIO1,
5482 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
5483 .type = ALC_FIXUP_PINS,
5484 .v.pins = (const struct alc_pincfg[]) {
5485 { 0x16, 0x99130111 }, /* CLFE speaker */
5486 { 0x1b, 0x99130112 }, /* surround speaker */
5490 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
5492 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
5493 /* additional init verbs for Acer Aspire 8930G */
5494 .type = ALC_FIXUP_VERBS,
5495 .v.verbs = (const struct hda_verb[]) {
5496 /* Enable all DACs */
5497 /* DAC DISABLE/MUTE 1? */
5498 /* setting bits 1-5 disables DAC nids 0x02-0x06
5499 * apparently. Init=0x38 */
5500 { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
5501 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5502 /* DAC DISABLE/MUTE 2? */
5503 /* some bit here disables the other DACs.
5505 { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
5506 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5508 * This laptop has a stereo digital microphone.
5509 * The mics are only 1cm apart which makes the stereo
5510 * useless. However, either the mic or the ALC889
5511 * makes the signal become a difference/sum signal
5512 * instead of standard stereo, which is annoying.
5513 * So instead we flip this bit which makes the
5514 * codec replicate the sum signal to both channels,
5515 * turning it into a normal mono mic.
5517 /* DMIC_CONTROL? Init value = 0x0001 */
5518 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5519 { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
5520 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5521 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5525 .chain_id = ALC882_FIXUP_GPIO1,
5527 [ALC885_FIXUP_MACPRO_GPIO] = {
5528 .type = ALC_FIXUP_FUNC,
5529 .v.func = alc885_fixup_macpro_gpio,
5531 [ALC889_FIXUP_DAC_ROUTE] = {
5532 .type = ALC_FIXUP_FUNC,
5533 .v.func = alc889_fixup_dac_route,
5535 [ALC889_FIXUP_MBP_VREF] = {
5536 .type = ALC_FIXUP_FUNC,
5537 .v.func = alc889_fixup_mbp_vref,
5539 .chain_id = ALC882_FIXUP_GPIO1,
5541 [ALC889_FIXUP_IMAC91_VREF] = {
5542 .type = ALC_FIXUP_FUNC,
5543 .v.func = alc889_fixup_imac91_vref,
5545 .chain_id = ALC882_FIXUP_GPIO1,
5547 [ALC882_FIXUP_INV_DMIC] = {
5548 .type = ALC_FIXUP_FUNC,
5549 .v.func = alc_fixup_inv_dmic_0x12,
5551 [ALC882_FIXUP_NO_PRIMARY_HP] = {
5552 .type = ALC_FIXUP_FUNC,
5553 .v.func = alc882_fixup_no_primary_hp,
5557 static const struct snd_pci_quirk alc882_fixup_tbl[] = {
5558 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
5559 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5560 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
5561 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5562 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
5563 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
5564 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
5565 ALC882_FIXUP_ACER_ASPIRE_4930G),
5566 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
5567 ALC882_FIXUP_ACER_ASPIRE_4930G),
5568 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
5569 ALC882_FIXUP_ACER_ASPIRE_8930G),
5570 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
5571 ALC882_FIXUP_ACER_ASPIRE_8930G),
5572 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
5573 ALC882_FIXUP_ACER_ASPIRE_4930G),
5574 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
5575 ALC882_FIXUP_ACER_ASPIRE_4930G),
5576 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
5577 ALC882_FIXUP_ACER_ASPIRE_4930G),
5578 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
5579 SND_PCI_QUIRK(0x1025, 0x021e, "Acer Aspire 5739G",
5580 ALC882_FIXUP_ACER_ASPIRE_4930G),
5581 SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE),
5582 SND_PCI_QUIRK(0x1025, 0x026b, "Acer Aspire 8940G", ALC882_FIXUP_ACER_ASPIRE_8930G),
5583 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
5584 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
5585 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
5586 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
5587 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
5588 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
5589 SND_PCI_QUIRK(0x104d, 0x905a, "Sony Vaio Z", ALC882_FIXUP_NO_PRIMARY_HP),
5591 /* All Apple entries are in codec SSIDs */
5592 SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC889_FIXUP_MBP_VREF),
5593 SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC889_FIXUP_MBP_VREF),
5594 SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
5595 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
5596 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
5597 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
5598 SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC889_FIXUP_MBP_VREF),
5599 SND_PCI_QUIRK(0x106b, 0x3000, "iMac", ALC889_FIXUP_MBP_VREF),
5600 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
5601 SND_PCI_QUIRK(0x106b, 0x3400, "MacBookAir 1,1", ALC889_FIXUP_MBP_VREF),
5602 SND_PCI_QUIRK(0x106b, 0x3500, "MacBookAir 2,1", ALC889_FIXUP_MBP_VREF),
5603 SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889_FIXUP_MBP_VREF),
5604 SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
5605 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
5606 SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC889_FIXUP_IMAC91_VREF),
5607 SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC889_FIXUP_IMAC91_VREF),
5608 SND_PCI_QUIRK(0x106b, 0x4100, "Macmini 3,1", ALC889_FIXUP_IMAC91_VREF),
5609 SND_PCI_QUIRK(0x106b, 0x4200, "Mac Pro 5,1", ALC885_FIXUP_MACPRO_GPIO),
5610 SND_PCI_QUIRK(0x106b, 0x4300, "iMac 9,1", ALC889_FIXUP_IMAC91_VREF),
5611 SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC889_FIXUP_IMAC91_VREF),
5612 SND_PCI_QUIRK(0x106b, 0x4900, "iMac 9,1 Aluminum", ALC889_FIXUP_IMAC91_VREF),
5613 SND_PCI_QUIRK(0x106b, 0x4a00, "Macbook 5,2", ALC889_FIXUP_IMAC91_VREF),
5615 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
5616 SND_PCI_QUIRK(0x1462, 0x7350, "MSI-7350", ALC889_FIXUP_CD),
5617 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
5618 SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte EP45-DS3", ALC889_FIXUP_CD),
5619 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
5620 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
5621 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
5622 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
5623 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
5627 static const struct alc_model_fixup alc882_fixup_models[] = {
5628 {.id = ALC882_FIXUP_ACER_ASPIRE_4930G, .name = "acer-aspire-4930g"},
5629 {.id = ALC882_FIXUP_ACER_ASPIRE_8930G, .name = "acer-aspire-8930g"},
5630 {.id = ALC883_FIXUP_ACER_EAPD, .name = "acer-aspire"},
5631 {.id = ALC882_FIXUP_INV_DMIC, .name = "inv-dmic"},
5632 {.id = ALC882_FIXUP_NO_PRIMARY_HP, .name = "no-primary-hp"},
5637 * BIOS auto configuration
5639 /* almost identical with ALC880 parser... */
5640 static int alc882_parse_auto_config(struct hda_codec *codec)
5642 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
5643 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5644 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
5649 static int patch_alc882(struct hda_codec *codec)
5651 struct alc_spec *spec;
5654 err = alc_alloc_spec(codec, 0x0b);
5660 switch (codec->vendor_id) {
5665 /* ALC883 and variants */
5666 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5670 alc_pick_fixup(codec, alc882_fixup_models, alc882_fixup_tbl,
5672 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5674 alc_auto_parse_customize_define(codec);
5676 /* automatic parse from the BIOS config */
5677 err = alc882_parse_auto_config(codec);
5681 if (!spec->no_analog && has_cdefine_beep(codec)) {
5682 err = snd_hda_attach_beep_device(codec, 0x1);
5685 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5688 codec->patch_ops = alc_patch_ops;
5690 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5703 static int alc262_parse_auto_config(struct hda_codec *codec)
5705 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
5706 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5707 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
5714 ALC262_FIXUP_FSC_H270,
5715 ALC262_FIXUP_HP_Z200,
5717 ALC262_FIXUP_LENOVO_3000,
5719 ALC262_FIXUP_BENQ_T31,
5720 ALC262_FIXUP_INV_DMIC,
5723 static const struct alc_fixup alc262_fixups[] = {
5724 [ALC262_FIXUP_FSC_H270] = {
5725 .type = ALC_FIXUP_PINS,
5726 .v.pins = (const struct alc_pincfg[]) {
5727 { 0x14, 0x99130110 }, /* speaker */
5728 { 0x15, 0x0221142f }, /* front HP */
5729 { 0x1b, 0x0121141f }, /* rear HP */
5733 [ALC262_FIXUP_HP_Z200] = {
5734 .type = ALC_FIXUP_PINS,
5735 .v.pins = (const struct alc_pincfg[]) {
5736 { 0x16, 0x99130120 }, /* internal speaker */
5740 [ALC262_FIXUP_TYAN] = {
5741 .type = ALC_FIXUP_PINS,
5742 .v.pins = (const struct alc_pincfg[]) {
5743 { 0x14, 0x1993e1f0 }, /* int AUX */
5747 [ALC262_FIXUP_LENOVO_3000] = {
5748 .type = ALC_FIXUP_VERBS,
5749 .v.verbs = (const struct hda_verb[]) {
5750 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
5754 .chain_id = ALC262_FIXUP_BENQ,
5756 [ALC262_FIXUP_BENQ] = {
5757 .type = ALC_FIXUP_VERBS,
5758 .v.verbs = (const struct hda_verb[]) {
5759 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5760 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5764 [ALC262_FIXUP_BENQ_T31] = {
5765 .type = ALC_FIXUP_VERBS,
5766 .v.verbs = (const struct hda_verb[]) {
5767 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5768 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5772 [ALC262_FIXUP_INV_DMIC] = {
5773 .type = ALC_FIXUP_FUNC,
5774 .v.func = alc_fixup_inv_dmic_0x12,
5778 static const struct snd_pci_quirk alc262_fixup_tbl[] = {
5779 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
5780 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
5781 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
5782 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
5783 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
5784 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
5785 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
5786 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
5790 static const struct alc_model_fixup alc262_fixup_models[] = {
5791 {.id = ALC262_FIXUP_INV_DMIC, .name = "inv-dmic"},
5797 static int patch_alc262(struct hda_codec *codec)
5799 struct alc_spec *spec;
5802 err = alc_alloc_spec(codec, 0x0b);
5809 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
5814 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5815 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
5816 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5817 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
5820 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5822 alc_pick_fixup(codec, alc262_fixup_models, alc262_fixup_tbl,
5824 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5826 alc_auto_parse_customize_define(codec);
5828 /* automatic parse from the BIOS config */
5829 err = alc262_parse_auto_config(codec);
5833 if (!spec->no_analog && has_cdefine_beep(codec)) {
5834 err = snd_hda_attach_beep_device(codec, 0x1);
5837 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5840 codec->patch_ops = alc_patch_ops;
5841 spec->shutup = alc_eapd_shutup;
5843 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5855 /* bind Beep switches of both NID 0x0f and 0x10 */
5856 static const struct hda_bind_ctls alc268_bind_beep_sw = {
5857 .ops = &snd_hda_bind_sw,
5859 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
5860 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
5865 static const struct snd_kcontrol_new alc268_beep_mixer[] = {
5866 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
5867 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
5871 /* set PCBEEP vol = 0, mute connections */
5872 static const struct hda_verb alc268_beep_init_verbs[] = {
5873 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5874 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5875 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5880 ALC268_FIXUP_INV_DMIC,
5881 ALC268_FIXUP_HP_EAPD,
5884 static const struct alc_fixup alc268_fixups[] = {
5885 [ALC268_FIXUP_INV_DMIC] = {
5886 .type = ALC_FIXUP_FUNC,
5887 .v.func = alc_fixup_inv_dmic_0x12,
5889 [ALC268_FIXUP_HP_EAPD] = {
5890 .type = ALC_FIXUP_VERBS,
5891 .v.verbs = (const struct hda_verb[]) {
5892 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 0},
5898 static const struct alc_model_fixup alc268_fixup_models[] = {
5899 {.id = ALC268_FIXUP_INV_DMIC, .name = "inv-dmic"},
5900 {.id = ALC268_FIXUP_HP_EAPD, .name = "hp-eapd"},
5904 static const struct snd_pci_quirk alc268_fixup_tbl[] = {
5905 /* below is codec SSID since multiple Toshiba laptops have the
5906 * same PCI SSID 1179:ff00
5908 SND_PCI_QUIRK(0x1179, 0xff06, "Toshiba P200", ALC268_FIXUP_HP_EAPD),
5913 * BIOS auto configuration
5915 static int alc268_parse_auto_config(struct hda_codec *codec)
5917 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5918 struct alc_spec *spec = codec->spec;
5919 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
5921 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
5922 add_mixer(spec, alc268_beep_mixer);
5923 snd_hda_gen_add_verbs(&spec->gen, alc268_beep_init_verbs);
5931 static int patch_alc268(struct hda_codec *codec)
5933 struct alc_spec *spec;
5934 int i, has_beep, err;
5936 /* ALC268 has no aa-loopback mixer */
5937 err = alc_alloc_spec(codec, 0);
5943 alc_pick_fixup(codec, alc268_fixup_models, alc268_fixup_tbl, alc268_fixups);
5944 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5946 /* automatic parse from the BIOS config */
5947 err = alc268_parse_auto_config(codec);
5952 for (i = 0; i < spec->num_mixers; i++) {
5953 if (spec->mixers[i] == alc268_beep_mixer) {
5960 err = snd_hda_attach_beep_device(codec, 0x1);
5963 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
5964 /* override the amp caps for beep generator */
5965 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
5966 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
5967 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
5968 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5969 (0 << AC_AMPCAP_MUTE_SHIFT));
5972 codec->patch_ops = alc_patch_ops;
5973 spec->shutup = alc_eapd_shutup;
5975 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5987 static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
5991 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5992 /* NID is set in alc_build_pcms */
5994 .open = alc_playback_pcm_open,
5995 .prepare = alc_playback_pcm_prepare,
5996 .cleanup = alc_playback_pcm_cleanup
6000 static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
6004 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
6005 /* NID is set in alc_build_pcms */
6008 /* different alc269-variants */
6010 ALC269_TYPE_ALC269VA,
6011 ALC269_TYPE_ALC269VB,
6012 ALC269_TYPE_ALC269VC,
6013 ALC269_TYPE_ALC269VD,
6020 * BIOS auto configuration
6022 static int alc269_parse_auto_config(struct hda_codec *codec)
6024 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
6025 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
6026 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6027 struct alc_spec *spec = codec->spec;
6028 const hda_nid_t *ssids;
6030 switch (spec->codec_variant) {
6031 case ALC269_TYPE_ALC269VA:
6032 case ALC269_TYPE_ALC269VC:
6033 case ALC269_TYPE_ALC280:
6034 case ALC269_TYPE_ALC284:
6035 ssids = alc269va_ssids;
6037 case ALC269_TYPE_ALC269VB:
6038 case ALC269_TYPE_ALC269VD:
6039 case ALC269_TYPE_ALC282:
6040 ssids = alc269_ssids;
6043 ssids = alc269_ssids;
6047 return alc_parse_auto_config(codec, alc269_ignore, ssids);
6050 static void alc269vb_toggle_power_output(struct hda_codec *codec, int power_up)
6052 int val = alc_read_coef_idx(codec, 0x04);
6057 alc_write_coef_idx(codec, 0x04, val);
6060 static void alc269_shutup(struct hda_codec *codec)
6062 struct alc_spec *spec = codec->spec;
6064 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
6067 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
6068 alc269vb_toggle_power_output(codec, 0);
6069 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
6070 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
6076 static int alc269_resume(struct hda_codec *codec)
6078 struct alc_spec *spec = codec->spec;
6080 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
6081 alc269vb_toggle_power_output(codec, 0);
6082 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
6083 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
6087 codec->patch_ops.init(codec);
6089 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
6090 alc269vb_toggle_power_output(codec, 1);
6091 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
6092 (alc_get_coef0(codec) & 0x00ff) == 0x017) {
6096 snd_hda_codec_resume_amp(codec);
6097 snd_hda_codec_resume_cache(codec);
6098 hda_call_check_power_status(codec, 0x01);
6101 #endif /* CONFIG_PM */
6103 static void alc269_fixup_pincfg_no_hp_to_lineout(struct hda_codec *codec,
6104 const struct alc_fixup *fix, int action)
6106 struct alc_spec *spec = codec->spec;
6108 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6109 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
6112 static void alc269_fixup_hweq(struct hda_codec *codec,
6113 const struct alc_fixup *fix, int action)
6117 if (action != ALC_FIXUP_ACT_INIT)
6119 coef = alc_read_coef_idx(codec, 0x1e);
6120 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
6123 static void alc271_fixup_dmic(struct hda_codec *codec,
6124 const struct alc_fixup *fix, int action)
6126 static const struct hda_verb verbs[] = {
6127 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
6128 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
6133 if (strcmp(codec->chip_name, "ALC271X"))
6135 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
6136 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
6137 snd_hda_sequence_write(codec, verbs);
6140 static void alc269_fixup_pcm_44k(struct hda_codec *codec,
6141 const struct alc_fixup *fix, int action)
6143 struct alc_spec *spec = codec->spec;
6145 if (action != ALC_FIXUP_ACT_PROBE)
6148 /* Due to a hardware problem on Lenovo Ideadpad, we need to
6149 * fix the sample rate of analog I/O to 44.1kHz
6151 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
6152 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
6155 static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
6156 const struct alc_fixup *fix, int action)
6160 if (action != ALC_FIXUP_ACT_INIT)
6162 /* The digital-mic unit sends PDM (differential signal) instead of
6163 * the standard PCM, thus you can't record a valid mono stream as is.
6164 * Below is a workaround specific to ALC269 to control the dmic
6165 * signal source as mono.
6167 coef = alc_read_coef_idx(codec, 0x07);
6168 alc_write_coef_idx(codec, 0x07, coef | 0x80);
6171 static void alc269_quanta_automute(struct hda_codec *codec)
6173 update_outputs(codec);
6175 snd_hda_codec_write(codec, 0x20, 0,
6176 AC_VERB_SET_COEF_INDEX, 0x0c);
6177 snd_hda_codec_write(codec, 0x20, 0,
6178 AC_VERB_SET_PROC_COEF, 0x680);
6180 snd_hda_codec_write(codec, 0x20, 0,
6181 AC_VERB_SET_COEF_INDEX, 0x0c);
6182 snd_hda_codec_write(codec, 0x20, 0,
6183 AC_VERB_SET_PROC_COEF, 0x480);
6186 static void alc269_fixup_quanta_mute(struct hda_codec *codec,
6187 const struct alc_fixup *fix, int action)
6189 struct alc_spec *spec = codec->spec;
6190 if (action != ALC_FIXUP_ACT_PROBE)
6192 spec->automute_hook = alc269_quanta_automute;
6195 /* update mute-LED according to the speaker mute state via mic1 VREF pin */
6196 static void alc269_fixup_mic1_mute_hook(void *private_data, int enabled)
6198 struct hda_codec *codec = private_data;
6199 unsigned int pinval = AC_PINCTL_IN_EN + (enabled ?
6200 AC_PINCTL_VREF_HIZ : AC_PINCTL_VREF_80);
6201 snd_hda_set_pin_ctl_cache(codec, 0x18, pinval);
6204 static void alc269_fixup_mic1_mute(struct hda_codec *codec,
6205 const struct alc_fixup *fix, int action)
6207 struct alc_spec *spec = codec->spec;
6209 case ALC_FIXUP_ACT_BUILD:
6210 spec->vmaster_mute.hook = alc269_fixup_mic1_mute_hook;
6211 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
6213 case ALC_FIXUP_ACT_INIT:
6214 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
6219 /* update mute-LED according to the speaker mute state via mic2 VREF pin */
6220 static void alc269_fixup_mic2_mute_hook(void *private_data, int enabled)
6222 struct hda_codec *codec = private_data;
6223 unsigned int pinval = enabled ? 0x20 : 0x24;
6224 snd_hda_set_pin_ctl_cache(codec, 0x19, pinval);
6227 static void alc269_fixup_mic2_mute(struct hda_codec *codec,
6228 const struct alc_fixup *fix, int action)
6230 struct alc_spec *spec = codec->spec;
6232 case ALC_FIXUP_ACT_BUILD:
6233 spec->vmaster_mute.hook = alc269_fixup_mic2_mute_hook;
6234 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
6236 case ALC_FIXUP_ACT_INIT:
6237 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
6242 static void alc271_hp_gate_mic_jack(struct hda_codec *codec,
6243 const struct alc_fixup *fix,
6246 struct alc_spec *spec = codec->spec;
6248 if (action == ALC_FIXUP_ACT_PROBE)
6249 snd_hda_jack_set_gating_jack(codec, spec->ext_mic_pin,
6250 spec->autocfg.hp_pins[0]);
6254 ALC269_FIXUP_SONY_VAIO,
6255 ALC275_FIXUP_SONY_VAIO_GPIO2,
6256 ALC269_FIXUP_DELL_M101Z,
6257 ALC269_FIXUP_SKU_IGNORE,
6258 ALC269_FIXUP_ASUS_G73JW,
6259 ALC269_FIXUP_LENOVO_EAPD,
6260 ALC275_FIXUP_SONY_HWEQ,
6262 ALC269_FIXUP_PCM_44K,
6263 ALC269_FIXUP_STEREO_DMIC,
6264 ALC269_FIXUP_QUANTA_MUTE,
6265 ALC269_FIXUP_LIFEBOOK,
6268 ALC269VB_FIXUP_AMIC,
6269 ALC269VB_FIXUP_DMIC,
6270 ALC269_FIXUP_MIC1_MUTE_LED,
6271 ALC269_FIXUP_MIC2_MUTE_LED,
6272 ALC269_FIXUP_INV_DMIC,
6273 ALC269_FIXUP_LENOVO_DOCK,
6274 ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT,
6275 ALC271_FIXUP_AMIC_MIC2,
6276 ALC271_FIXUP_HP_GATE_MIC_JACK,
6279 static const struct alc_fixup alc269_fixups[] = {
6280 [ALC269_FIXUP_SONY_VAIO] = {
6281 .type = ALC_FIXUP_VERBS,
6282 .v.verbs = (const struct hda_verb[]) {
6283 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
6287 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
6288 .type = ALC_FIXUP_VERBS,
6289 .v.verbs = (const struct hda_verb[]) {
6290 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
6291 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
6292 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
6296 .chain_id = ALC269_FIXUP_SONY_VAIO
6298 [ALC269_FIXUP_DELL_M101Z] = {
6299 .type = ALC_FIXUP_VERBS,
6300 .v.verbs = (const struct hda_verb[]) {
6301 /* Enables internal speaker */
6302 {0x20, AC_VERB_SET_COEF_INDEX, 13},
6303 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
6307 [ALC269_FIXUP_SKU_IGNORE] = {
6308 .type = ALC_FIXUP_FUNC,
6309 .v.func = alc_fixup_sku_ignore,
6311 [ALC269_FIXUP_ASUS_G73JW] = {
6312 .type = ALC_FIXUP_PINS,
6313 .v.pins = (const struct alc_pincfg[]) {
6314 { 0x17, 0x99130111 }, /* subwoofer */
6318 [ALC269_FIXUP_LENOVO_EAPD] = {
6319 .type = ALC_FIXUP_VERBS,
6320 .v.verbs = (const struct hda_verb[]) {
6321 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6325 [ALC275_FIXUP_SONY_HWEQ] = {
6326 .type = ALC_FIXUP_FUNC,
6327 .v.func = alc269_fixup_hweq,
6329 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
6331 [ALC271_FIXUP_DMIC] = {
6332 .type = ALC_FIXUP_FUNC,
6333 .v.func = alc271_fixup_dmic,
6335 [ALC269_FIXUP_PCM_44K] = {
6336 .type = ALC_FIXUP_FUNC,
6337 .v.func = alc269_fixup_pcm_44k,
6339 .chain_id = ALC269_FIXUP_QUANTA_MUTE
6341 [ALC269_FIXUP_STEREO_DMIC] = {
6342 .type = ALC_FIXUP_FUNC,
6343 .v.func = alc269_fixup_stereo_dmic,
6345 [ALC269_FIXUP_QUANTA_MUTE] = {
6346 .type = ALC_FIXUP_FUNC,
6347 .v.func = alc269_fixup_quanta_mute,
6349 [ALC269_FIXUP_LIFEBOOK] = {
6350 .type = ALC_FIXUP_PINS,
6351 .v.pins = (const struct alc_pincfg[]) {
6352 { 0x1a, 0x2101103f }, /* dock line-out */
6353 { 0x1b, 0x23a11040 }, /* dock mic-in */
6357 .chain_id = ALC269_FIXUP_QUANTA_MUTE
6359 [ALC269_FIXUP_AMIC] = {
6360 .type = ALC_FIXUP_PINS,
6361 .v.pins = (const struct alc_pincfg[]) {
6362 { 0x14, 0x99130110 }, /* speaker */
6363 { 0x15, 0x0121401f }, /* HP out */
6364 { 0x18, 0x01a19c20 }, /* mic */
6365 { 0x19, 0x99a3092f }, /* int-mic */
6369 [ALC269_FIXUP_DMIC] = {
6370 .type = ALC_FIXUP_PINS,
6371 .v.pins = (const struct alc_pincfg[]) {
6372 { 0x12, 0x99a3092f }, /* int-mic */
6373 { 0x14, 0x99130110 }, /* speaker */
6374 { 0x15, 0x0121401f }, /* HP out */
6375 { 0x18, 0x01a19c20 }, /* mic */
6379 [ALC269VB_FIXUP_AMIC] = {
6380 .type = ALC_FIXUP_PINS,
6381 .v.pins = (const struct alc_pincfg[]) {
6382 { 0x14, 0x99130110 }, /* speaker */
6383 { 0x18, 0x01a19c20 }, /* mic */
6384 { 0x19, 0x99a3092f }, /* int-mic */
6385 { 0x21, 0x0121401f }, /* HP out */
6389 [ALC269VB_FIXUP_DMIC] = {
6390 .type = ALC_FIXUP_PINS,
6391 .v.pins = (const struct alc_pincfg[]) {
6392 { 0x12, 0x99a3092f }, /* int-mic */
6393 { 0x14, 0x99130110 }, /* speaker */
6394 { 0x18, 0x01a19c20 }, /* mic */
6395 { 0x21, 0x0121401f }, /* HP out */
6399 [ALC269_FIXUP_MIC1_MUTE_LED] = {
6400 .type = ALC_FIXUP_FUNC,
6401 .v.func = alc269_fixup_mic1_mute,
6403 [ALC269_FIXUP_MIC2_MUTE_LED] = {
6404 .type = ALC_FIXUP_FUNC,
6405 .v.func = alc269_fixup_mic2_mute,
6407 [ALC269_FIXUP_INV_DMIC] = {
6408 .type = ALC_FIXUP_FUNC,
6409 .v.func = alc_fixup_inv_dmic_0x12,
6411 [ALC269_FIXUP_LENOVO_DOCK] = {
6412 .type = ALC_FIXUP_PINS,
6413 .v.pins = (const struct alc_pincfg[]) {
6414 { 0x19, 0x23a11040 }, /* dock mic */
6415 { 0x1b, 0x2121103f }, /* dock headphone */
6419 .chain_id = ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT
6421 [ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT] = {
6422 .type = ALC_FIXUP_FUNC,
6423 .v.func = alc269_fixup_pincfg_no_hp_to_lineout,
6425 [ALC271_FIXUP_AMIC_MIC2] = {
6426 .type = ALC_FIXUP_PINS,
6427 .v.pins = (const struct alc_pincfg[]) {
6428 { 0x14, 0x99130110 }, /* speaker */
6429 { 0x19, 0x01a19c20 }, /* mic */
6430 { 0x1b, 0x99a7012f }, /* int-mic */
6431 { 0x21, 0x0121401f }, /* HP out */
6435 [ALC271_FIXUP_HP_GATE_MIC_JACK] = {
6436 .type = ALC_FIXUP_FUNC,
6437 .v.func = alc271_hp_gate_mic_jack,
6439 .chain_id = ALC271_FIXUP_AMIC_MIC2,
6443 static const struct snd_pci_quirk alc269_fixup_tbl[] = {
6444 SND_PCI_QUIRK(0x1025, 0x029b, "Acer 1810TZ", ALC269_FIXUP_INV_DMIC),
6445 SND_PCI_QUIRK(0x1025, 0x0349, "Acer AOD260", ALC269_FIXUP_INV_DMIC),
6446 SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_MIC2_MUTE_LED),
6447 SND_PCI_QUIRK(0x103c, 0x1972, "HP Pavilion 17", ALC269_FIXUP_MIC1_MUTE_LED),
6448 SND_PCI_QUIRK(0x1043, 0x1427, "Asus Zenbook UX31E", ALC269VB_FIXUP_DMIC),
6449 SND_PCI_QUIRK(0x1043, 0x1517, "Asus Zenbook UX31A", ALC269VB_FIXUP_DMIC),
6450 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
6451 SND_PCI_QUIRK(0x1043, 0x1b13, "Asus U41SV", ALC269_FIXUP_INV_DMIC),
6452 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
6453 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
6454 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
6455 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
6456 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
6457 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
6458 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6459 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6460 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
6461 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
6462 SND_PCI_QUIRK(0x1025, 0x0742, "Acer AO756", ALC271_FIXUP_HP_GATE_MIC_JACK),
6463 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
6464 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
6465 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
6466 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
6467 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
6468 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
6469 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
6470 SND_PCI_QUIRK(0x17aa, 0x21f6, "Thinkpad T530", ALC269_FIXUP_LENOVO_DOCK),
6471 SND_PCI_QUIRK(0x17aa, 0x21fa, "Thinkpad X230", ALC269_FIXUP_LENOVO_DOCK),
6472 SND_PCI_QUIRK(0x17aa, 0x21f3, "Thinkpad T430", ALC269_FIXUP_LENOVO_DOCK),
6473 SND_PCI_QUIRK(0x17aa, 0x21fb, "Thinkpad T430s", ALC269_FIXUP_LENOVO_DOCK),
6474 SND_PCI_QUIRK(0x17aa, 0x2203, "Thinkpad X230 Tablet", ALC269_FIXUP_LENOVO_DOCK),
6475 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_PCM_44K),
6476 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
6479 /* Below is a quirk table taken from the old code.
6480 * Basically the device should work as is without the fixup table.
6481 * If BIOS doesn't give a proper info, enable the corresponding
6484 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
6486 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
6487 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
6488 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
6489 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
6490 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
6491 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
6492 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
6493 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
6494 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
6495 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
6496 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
6497 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
6498 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
6499 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
6500 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
6501 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
6502 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
6503 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
6504 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
6505 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
6506 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
6507 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
6508 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
6509 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
6510 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
6511 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
6512 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
6513 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
6514 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
6515 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
6516 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
6517 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
6518 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
6519 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
6520 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
6521 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
6522 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
6523 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
6524 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
6529 static const struct alc_model_fixup alc269_fixup_models[] = {
6530 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
6531 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
6532 {.id = ALC269_FIXUP_STEREO_DMIC, .name = "alc269-dmic"},
6533 {.id = ALC271_FIXUP_DMIC, .name = "alc271-dmic"},
6534 {.id = ALC269_FIXUP_INV_DMIC, .name = "inv-dmic"},
6535 {.id = ALC269_FIXUP_LENOVO_DOCK, .name = "lenovo-dock"},
6540 static void alc269_fill_coef(struct hda_codec *codec)
6542 struct alc_spec *spec = codec->spec;
6545 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
6548 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
6549 alc_write_coef_idx(codec, 0xf, 0x960b);
6550 alc_write_coef_idx(codec, 0xe, 0x8817);
6553 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
6554 alc_write_coef_idx(codec, 0xf, 0x960b);
6555 alc_write_coef_idx(codec, 0xe, 0x8814);
6558 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
6559 val = alc_read_coef_idx(codec, 0x04);
6560 /* Power up output pin */
6561 alc_write_coef_idx(codec, 0x04, val | (1<<11));
6564 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
6565 val = alc_read_coef_idx(codec, 0xd);
6566 if ((val & 0x0c00) >> 10 != 0x1) {
6567 /* Capless ramp up clock control */
6568 alc_write_coef_idx(codec, 0xd, val | (1<<10));
6570 val = alc_read_coef_idx(codec, 0x17);
6571 if ((val & 0x01c0) >> 6 != 0x4) {
6572 /* Class D power on reset */
6573 alc_write_coef_idx(codec, 0x17, val | (1<<7));
6577 val = alc_read_coef_idx(codec, 0xd); /* Class D */
6578 alc_write_coef_idx(codec, 0xd, val | (1<<14));
6580 val = alc_read_coef_idx(codec, 0x4); /* HP */
6581 alc_write_coef_idx(codec, 0x4, val | (1<<11));
6586 static int patch_alc269(struct hda_codec *codec)
6588 struct alc_spec *spec;
6591 err = alc_alloc_spec(codec, 0x0b);
6597 alc_pick_fixup(codec, alc269_fixup_models,
6598 alc269_fixup_tbl, alc269_fixups);
6599 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6601 alc_auto_parse_customize_define(codec);
6603 switch (codec->vendor_id) {
6605 spec->codec_variant = ALC269_TYPE_ALC269VA;
6606 switch (alc_get_coef0(codec) & 0x00f0) {
6608 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
6609 spec->cdefine.platform_type == 1)
6610 err = alc_codec_rename(codec, "ALC271X");
6611 spec->codec_variant = ALC269_TYPE_ALC269VB;
6614 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
6615 codec->bus->pci->subsystem_device == 0x21f3)
6616 err = alc_codec_rename(codec, "ALC3202");
6617 spec->codec_variant = ALC269_TYPE_ALC269VC;
6620 spec->codec_variant = ALC269_TYPE_ALC269VD;
6623 alc_fix_pll_init(codec, 0x20, 0x04, 15);
6627 spec->init_hook = alc269_fill_coef;
6628 alc269_fill_coef(codec);
6633 spec->codec_variant = ALC269_TYPE_ALC280;
6637 spec->codec_variant = ALC269_TYPE_ALC282;
6641 spec->codec_variant = ALC269_TYPE_ALC284;
6645 /* automatic parse from the BIOS config */
6646 err = alc269_parse_auto_config(codec);
6650 if (!spec->no_analog && has_cdefine_beep(codec)) {
6651 err = snd_hda_attach_beep_device(codec, 0x1);
6654 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
6657 codec->patch_ops = alc_patch_ops;
6659 codec->patch_ops.resume = alc269_resume;
6661 spec->shutup = alc269_shutup;
6663 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6676 static int alc861_parse_auto_config(struct hda_codec *codec)
6678 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
6679 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
6680 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
6683 /* Pin config fixes */
6685 ALC861_FIXUP_FSC_AMILO_PI1505,
6686 ALC861_FIXUP_AMP_VREF_0F,
6687 ALC861_FIXUP_NO_JACK_DETECT,
6688 ALC861_FIXUP_ASUS_A6RP,
6691 /* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
6692 static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
6693 const struct alc_fixup *fix, int action)
6695 struct alc_spec *spec = codec->spec;
6698 if (action != ALC_FIXUP_ACT_INIT)
6700 val = snd_hda_codec_read(codec, 0x0f, 0,
6701 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
6702 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
6703 val |= AC_PINCTL_IN_EN;
6704 val |= AC_PINCTL_VREF_50;
6705 snd_hda_set_pin_ctl(codec, 0x0f, val);
6706 spec->keep_vref_in_automute = 1;
6709 /* suppress the jack-detection */
6710 static void alc_fixup_no_jack_detect(struct hda_codec *codec,
6711 const struct alc_fixup *fix, int action)
6713 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6714 codec->no_jack_detect = 1;
6717 static const struct alc_fixup alc861_fixups[] = {
6718 [ALC861_FIXUP_FSC_AMILO_PI1505] = {
6719 .type = ALC_FIXUP_PINS,
6720 .v.pins = (const struct alc_pincfg[]) {
6721 { 0x0b, 0x0221101f }, /* HP */
6722 { 0x0f, 0x90170310 }, /* speaker */
6726 [ALC861_FIXUP_AMP_VREF_0F] = {
6727 .type = ALC_FIXUP_FUNC,
6728 .v.func = alc861_fixup_asus_amp_vref_0f,
6730 [ALC861_FIXUP_NO_JACK_DETECT] = {
6731 .type = ALC_FIXUP_FUNC,
6732 .v.func = alc_fixup_no_jack_detect,
6734 [ALC861_FIXUP_ASUS_A6RP] = {
6735 .type = ALC_FIXUP_FUNC,
6736 .v.func = alc861_fixup_asus_amp_vref_0f,
6738 .chain_id = ALC861_FIXUP_NO_JACK_DETECT,
6742 static const struct snd_pci_quirk alc861_fixup_tbl[] = {
6743 SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP),
6744 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", ALC861_FIXUP_AMP_VREF_0F),
6745 SND_PCI_QUIRK(0x1462, 0x7254, "HP DX2200", ALC861_FIXUP_NO_JACK_DETECT),
6746 SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", ALC861_FIXUP_AMP_VREF_0F),
6747 SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", ALC861_FIXUP_AMP_VREF_0F),
6748 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", ALC861_FIXUP_FSC_AMILO_PI1505),
6754 static int patch_alc861(struct hda_codec *codec)
6756 struct alc_spec *spec;
6759 err = alc_alloc_spec(codec, 0x15);
6765 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
6766 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6768 /* automatic parse from the BIOS config */
6769 err = alc861_parse_auto_config(codec);
6773 if (!spec->no_analog) {
6774 err = snd_hda_attach_beep_device(codec, 0x23);
6777 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
6780 codec->patch_ops = alc_patch_ops;
6782 spec->power_hook = alc_power_eapd;
6785 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6799 * In addition, an independent DAC
6801 static int alc861vd_parse_auto_config(struct hda_codec *codec)
6803 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
6804 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6805 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
6809 ALC660VD_FIX_ASUS_GPIO1,
6810 ALC861VD_FIX_DALLAS,
6813 /* exclude VREF80 */
6814 static void alc861vd_fixup_dallas(struct hda_codec *codec,
6815 const struct alc_fixup *fix, int action)
6817 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
6818 snd_hda_override_pin_caps(codec, 0x18, 0x00000734);
6819 snd_hda_override_pin_caps(codec, 0x19, 0x0000073c);
6823 static const struct alc_fixup alc861vd_fixups[] = {
6824 [ALC660VD_FIX_ASUS_GPIO1] = {
6825 .type = ALC_FIXUP_VERBS,
6826 .v.verbs = (const struct hda_verb[]) {
6828 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6829 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
6830 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
6834 [ALC861VD_FIX_DALLAS] = {
6835 .type = ALC_FIXUP_FUNC,
6836 .v.func = alc861vd_fixup_dallas,
6840 static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
6841 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
6842 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
6843 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
6849 static int patch_alc861vd(struct hda_codec *codec)
6851 struct alc_spec *spec;
6854 err = alc_alloc_spec(codec, 0x0b);
6860 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
6861 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6863 /* automatic parse from the BIOS config */
6864 err = alc861vd_parse_auto_config(codec);
6868 if (!spec->no_analog) {
6869 err = snd_hda_attach_beep_device(codec, 0x23);
6872 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6875 codec->patch_ops = alc_patch_ops;
6877 spec->shutup = alc_eapd_shutup;
6879 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6891 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
6892 * configuration. Each pin widget can choose any input DACs and a mixer.
6893 * Each ADC is connected from a mixer of all inputs. This makes possible
6894 * 6-channel independent captures.
6896 * In addition, an independent DAC for the multi-playback (not used in this
6901 * BIOS auto configuration
6904 static int alc662_parse_auto_config(struct hda_codec *codec)
6906 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
6907 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
6908 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6909 const hda_nid_t *ssids;
6911 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
6912 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
6913 ssids = alc663_ssids;
6915 ssids = alc662_ssids;
6916 return alc_parse_auto_config(codec, alc662_ignore, ssids);
6919 static void alc272_fixup_mario(struct hda_codec *codec,
6920 const struct alc_fixup *fix, int action)
6922 if (action != ALC_FIXUP_ACT_PROBE)
6924 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
6925 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
6926 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
6927 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6928 (0 << AC_AMPCAP_MUTE_SHIFT)))
6930 "hda_codec: failed to override amp caps for NID 0x2\n");
6934 ALC662_FIXUP_ASPIRE,
6935 ALC662_FIXUP_IDEAPAD,
6937 ALC662_FIXUP_CZC_P10T,
6938 ALC662_FIXUP_SKU_IGNORE,
6939 ALC662_FIXUP_HP_RP5800,
6940 ALC662_FIXUP_ASUS_MODE1,
6941 ALC662_FIXUP_ASUS_MODE2,
6942 ALC662_FIXUP_ASUS_MODE3,
6943 ALC662_FIXUP_ASUS_MODE4,
6944 ALC662_FIXUP_ASUS_MODE5,
6945 ALC662_FIXUP_ASUS_MODE6,
6946 ALC662_FIXUP_ASUS_MODE7,
6947 ALC662_FIXUP_ASUS_MODE8,
6948 ALC662_FIXUP_NO_JACK_DETECT,
6949 ALC662_FIXUP_ZOTAC_Z68,
6950 ALC662_FIXUP_INV_DMIC,
6953 static const struct alc_fixup alc662_fixups[] = {
6954 [ALC662_FIXUP_ASPIRE] = {
6955 .type = ALC_FIXUP_PINS,
6956 .v.pins = (const struct alc_pincfg[]) {
6957 { 0x15, 0x99130112 }, /* subwoofer */
6961 [ALC662_FIXUP_IDEAPAD] = {
6962 .type = ALC_FIXUP_PINS,
6963 .v.pins = (const struct alc_pincfg[]) {
6964 { 0x17, 0x99130112 }, /* subwoofer */
6968 [ALC272_FIXUP_MARIO] = {
6969 .type = ALC_FIXUP_FUNC,
6970 .v.func = alc272_fixup_mario,
6972 [ALC662_FIXUP_CZC_P10T] = {
6973 .type = ALC_FIXUP_VERBS,
6974 .v.verbs = (const struct hda_verb[]) {
6975 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6979 [ALC662_FIXUP_SKU_IGNORE] = {
6980 .type = ALC_FIXUP_FUNC,
6981 .v.func = alc_fixup_sku_ignore,
6983 [ALC662_FIXUP_HP_RP5800] = {
6984 .type = ALC_FIXUP_PINS,
6985 .v.pins = (const struct alc_pincfg[]) {
6986 { 0x14, 0x0221201f }, /* HP out */
6990 .chain_id = ALC662_FIXUP_SKU_IGNORE
6992 [ALC662_FIXUP_ASUS_MODE1] = {
6993 .type = ALC_FIXUP_PINS,
6994 .v.pins = (const struct alc_pincfg[]) {
6995 { 0x14, 0x99130110 }, /* speaker */
6996 { 0x18, 0x01a19c20 }, /* mic */
6997 { 0x19, 0x99a3092f }, /* int-mic */
6998 { 0x21, 0x0121401f }, /* HP out */
7002 .chain_id = ALC662_FIXUP_SKU_IGNORE
7004 [ALC662_FIXUP_ASUS_MODE2] = {
7005 .type = ALC_FIXUP_PINS,
7006 .v.pins = (const struct alc_pincfg[]) {
7007 { 0x14, 0x99130110 }, /* speaker */
7008 { 0x18, 0x01a19820 }, /* mic */
7009 { 0x19, 0x99a3092f }, /* int-mic */
7010 { 0x1b, 0x0121401f }, /* HP out */
7014 .chain_id = ALC662_FIXUP_SKU_IGNORE
7016 [ALC662_FIXUP_ASUS_MODE3] = {
7017 .type = ALC_FIXUP_PINS,
7018 .v.pins = (const struct alc_pincfg[]) {
7019 { 0x14, 0x99130110 }, /* speaker */
7020 { 0x15, 0x0121441f }, /* HP */
7021 { 0x18, 0x01a19840 }, /* mic */
7022 { 0x19, 0x99a3094f }, /* int-mic */
7023 { 0x21, 0x01211420 }, /* HP2 */
7027 .chain_id = ALC662_FIXUP_SKU_IGNORE
7029 [ALC662_FIXUP_ASUS_MODE4] = {
7030 .type = ALC_FIXUP_PINS,
7031 .v.pins = (const struct alc_pincfg[]) {
7032 { 0x14, 0x99130110 }, /* speaker */
7033 { 0x16, 0x99130111 }, /* speaker */
7034 { 0x18, 0x01a19840 }, /* mic */
7035 { 0x19, 0x99a3094f }, /* int-mic */
7036 { 0x21, 0x0121441f }, /* HP */
7040 .chain_id = ALC662_FIXUP_SKU_IGNORE
7042 [ALC662_FIXUP_ASUS_MODE5] = {
7043 .type = ALC_FIXUP_PINS,
7044 .v.pins = (const struct alc_pincfg[]) {
7045 { 0x14, 0x99130110 }, /* speaker */
7046 { 0x15, 0x0121441f }, /* HP */
7047 { 0x16, 0x99130111 }, /* speaker */
7048 { 0x18, 0x01a19840 }, /* mic */
7049 { 0x19, 0x99a3094f }, /* int-mic */
7053 .chain_id = ALC662_FIXUP_SKU_IGNORE
7055 [ALC662_FIXUP_ASUS_MODE6] = {
7056 .type = ALC_FIXUP_PINS,
7057 .v.pins = (const struct alc_pincfg[]) {
7058 { 0x14, 0x99130110 }, /* speaker */
7059 { 0x15, 0x01211420 }, /* HP2 */
7060 { 0x18, 0x01a19840 }, /* mic */
7061 { 0x19, 0x99a3094f }, /* int-mic */
7062 { 0x1b, 0x0121441f }, /* HP */
7066 .chain_id = ALC662_FIXUP_SKU_IGNORE
7068 [ALC662_FIXUP_ASUS_MODE7] = {
7069 .type = ALC_FIXUP_PINS,
7070 .v.pins = (const struct alc_pincfg[]) {
7071 { 0x14, 0x99130110 }, /* speaker */
7072 { 0x17, 0x99130111 }, /* speaker */
7073 { 0x18, 0x01a19840 }, /* mic */
7074 { 0x19, 0x99a3094f }, /* int-mic */
7075 { 0x1b, 0x01214020 }, /* HP */
7076 { 0x21, 0x0121401f }, /* HP */
7080 .chain_id = ALC662_FIXUP_SKU_IGNORE
7082 [ALC662_FIXUP_ASUS_MODE8] = {
7083 .type = ALC_FIXUP_PINS,
7084 .v.pins = (const struct alc_pincfg[]) {
7085 { 0x14, 0x99130110 }, /* speaker */
7086 { 0x12, 0x99a30970 }, /* int-mic */
7087 { 0x15, 0x01214020 }, /* HP */
7088 { 0x17, 0x99130111 }, /* speaker */
7089 { 0x18, 0x01a19840 }, /* mic */
7090 { 0x21, 0x0121401f }, /* HP */
7094 .chain_id = ALC662_FIXUP_SKU_IGNORE
7096 [ALC662_FIXUP_NO_JACK_DETECT] = {
7097 .type = ALC_FIXUP_FUNC,
7098 .v.func = alc_fixup_no_jack_detect,
7100 [ALC662_FIXUP_ZOTAC_Z68] = {
7101 .type = ALC_FIXUP_PINS,
7102 .v.pins = (const struct alc_pincfg[]) {
7103 { 0x1b, 0x02214020 }, /* Front HP */
7107 [ALC662_FIXUP_INV_DMIC] = {
7108 .type = ALC_FIXUP_FUNC,
7109 .v.func = alc_fixup_inv_dmic_0x12,
7113 static const struct snd_pci_quirk alc662_fixup_tbl[] = {
7114 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
7115 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
7116 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
7117 SND_PCI_QUIRK(0x1025, 0x0349, "eMachines eM250", ALC662_FIXUP_INV_DMIC),
7118 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
7119 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
7120 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT),
7121 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
7122 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
7123 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
7124 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
7125 SND_PCI_QUIRK(0x19da, 0xa130, "Zotac Z68", ALC662_FIXUP_ZOTAC_Z68),
7126 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
7129 /* Below is a quirk table taken from the old code.
7130 * Basically the device should work as is without the fixup table.
7131 * If BIOS doesn't give a proper info, enable the corresponding
7134 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
7135 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
7136 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
7137 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
7138 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7139 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7140 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7141 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
7142 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
7143 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7144 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
7145 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
7146 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
7147 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
7148 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
7149 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7150 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
7151 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
7152 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7153 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
7154 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
7155 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7156 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
7157 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
7158 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
7159 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7160 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
7161 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
7162 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7163 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
7164 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7165 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7166 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
7167 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
7168 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
7169 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
7170 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
7171 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
7172 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
7173 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7174 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
7175 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
7176 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7177 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
7178 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
7179 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
7180 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
7181 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
7182 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7183 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
7188 static const struct alc_model_fixup alc662_fixup_models[] = {
7189 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
7190 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
7191 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
7192 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
7193 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
7194 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
7195 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
7196 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
7197 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
7198 {.id = ALC662_FIXUP_INV_DMIC, .name = "inv-dmic"},
7202 static void alc662_fill_coef(struct hda_codec *codec)
7206 coef = alc_get_coef0(codec);
7208 switch (codec->vendor_id) {
7210 if ((coef & 0x00f0) == 0x0030) {
7211 val = alc_read_coef_idx(codec, 0x4); /* EAPD Ctrl */
7212 alc_write_coef_idx(codec, 0x4, val & ~(1<<10));
7222 val = alc_read_coef_idx(codec, 0xd); /* EAPD Ctrl */
7223 alc_write_coef_idx(codec, 0xd, val | (1<<14));
7230 static int patch_alc662(struct hda_codec *codec)
7232 struct alc_spec *spec;
7235 err = alc_alloc_spec(codec, 0x0b);
7241 /* handle multiple HPs as is */
7242 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
7244 alc_fix_pll_init(codec, 0x20, 0x04, 15);
7246 spec->init_hook = alc662_fill_coef;
7247 alc662_fill_coef(codec);
7249 alc_pick_fixup(codec, alc662_fixup_models,
7250 alc662_fixup_tbl, alc662_fixups);
7251 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
7253 alc_auto_parse_customize_define(codec);
7255 if ((alc_get_coef0(codec) & (1 << 14)) &&
7256 codec->bus->pci->subsystem_vendor == 0x1025 &&
7257 spec->cdefine.platform_type == 1) {
7258 if (alc_codec_rename(codec, "ALC272X") < 0)
7262 /* automatic parse from the BIOS config */
7263 err = alc662_parse_auto_config(codec);
7267 if (!spec->no_analog && has_cdefine_beep(codec)) {
7268 err = snd_hda_attach_beep_device(codec, 0x1);
7271 switch (codec->vendor_id) {
7273 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
7278 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
7281 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
7286 codec->patch_ops = alc_patch_ops;
7287 spec->shutup = alc_eapd_shutup;
7289 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
7302 static int alc680_parse_auto_config(struct hda_codec *codec)
7304 return alc_parse_auto_config(codec, NULL, NULL);
7309 static int patch_alc680(struct hda_codec *codec)
7313 /* ALC680 has no aa-loopback mixer */
7314 err = alc_alloc_spec(codec, 0);
7318 /* automatic parse from the BIOS config */
7319 err = alc680_parse_auto_config(codec);
7325 codec->patch_ops = alc_patch_ops;
7333 static const struct hda_codec_preset snd_hda_preset_realtek[] = {
7334 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
7335 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
7336 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
7337 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
7338 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
7339 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
7340 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
7341 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
7342 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
7343 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
7344 { .id = 0x10ec0280, .name = "ALC280", .patch = patch_alc269 },
7345 { .id = 0x10ec0282, .name = "ALC282", .patch = patch_alc269 },
7346 { .id = 0x10ec0283, .name = "ALC283", .patch = patch_alc269 },
7347 { .id = 0x10ec0284, .name = "ALC284", .patch = patch_alc269 },
7348 { .id = 0x10ec0290, .name = "ALC290", .patch = patch_alc269 },
7349 { .id = 0x10ec0292, .name = "ALC292", .patch = patch_alc269 },
7350 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
7351 .patch = patch_alc861 },
7352 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
7353 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
7354 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
7355 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
7356 .patch = patch_alc882 },
7357 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
7358 .patch = patch_alc662 },
7359 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
7360 .patch = patch_alc662 },
7361 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
7362 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
7363 { .id = 0x10ec0668, .name = "ALC668", .patch = patch_alc662 },
7364 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
7365 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
7366 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
7367 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
7368 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
7369 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
7370 .patch = patch_alc882 },
7371 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
7372 .patch = patch_alc882 },
7373 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
7374 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
7375 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
7376 .patch = patch_alc882 },
7377 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
7378 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
7379 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
7380 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
7381 { .id = 0x10ec0900, .name = "ALC1150", .patch = patch_alc882 },
7385 MODULE_ALIAS("snd-hda-codec-id:10ec*");
7387 MODULE_LICENSE("GPL");
7388 MODULE_DESCRIPTION("Realtek HD-audio codec");
7390 static struct hda_codec_preset_list realtek_list = {
7391 .preset = snd_hda_preset_realtek,
7392 .owner = THIS_MODULE,
7395 static int __init patch_realtek_init(void)
7397 return snd_hda_add_codec_preset(&realtek_list);
7400 static void __exit patch_realtek_exit(void)
7402 snd_hda_delete_codec_preset(&realtek_list);
7405 module_init(patch_realtek_init)
7406 module_exit(patch_realtek_exit)