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 */
76 #define MAX_VOL_NIDS 0x40
78 /* make compatible with old code */
79 #define alc_apply_pincfgs snd_hda_apply_pincfgs
80 #define alc_apply_fixup snd_hda_apply_fixup
81 #define alc_pick_fixup snd_hda_pick_fixup
82 #define alc_fixup hda_fixup
83 #define alc_pincfg hda_pintbl
84 #define alc_model_fixup hda_model_fixup
86 #define ALC_FIXUP_PINS HDA_FIXUP_PINS
87 #define ALC_FIXUP_VERBS HDA_FIXUP_VERBS
88 #define ALC_FIXUP_FUNC HDA_FIXUP_FUNC
90 #define ALC_FIXUP_ACT_PRE_PROBE HDA_FIXUP_ACT_PRE_PROBE
91 #define ALC_FIXUP_ACT_PROBE HDA_FIXUP_ACT_PROBE
92 #define ALC_FIXUP_ACT_INIT HDA_FIXUP_ACT_INIT
93 #define ALC_FIXUP_ACT_BUILD HDA_FIXUP_ACT_BUILD
96 #define MAX_NID_PATH_DEPTH 5
98 /* Widget connection path
100 * For output, stored in the order of DAC -> ... -> pin,
101 * for input, pin -> ... -> ADC.
103 * idx[i] contains the source index number to select on of the widget path[i];
104 * e.g. idx[1] is the index of the DAC (path[0]) selected by path[1] widget
105 * multi[] indicates whether it's a selector widget with multi-connectors
106 * (i.e. the connection selection is mandatory)
107 * vol_ctl and mute_ctl contains the NIDs for the assigned mixers
111 hda_nid_t path[MAX_NID_PATH_DEPTH];
112 unsigned char idx[MAX_NID_PATH_DEPTH];
113 unsigned char multi[MAX_NID_PATH_DEPTH];
114 unsigned int ctls[2]; /* 0 = volume, 1 = mute */
118 enum { NID_PATH_VOL_CTL = 0, NID_PATH_MUTE_CTL = 1 };
121 struct hda_gen_spec gen;
123 /* codec parameterization */
124 const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */
125 unsigned int num_mixers;
126 const struct snd_kcontrol_new *cap_mixer; /* capture mixer */
127 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
129 char stream_name_analog[32]; /* analog PCM stream */
130 const struct hda_pcm_stream *stream_analog_playback;
131 const struct hda_pcm_stream *stream_analog_capture;
132 const struct hda_pcm_stream *stream_analog_alt_playback;
133 const struct hda_pcm_stream *stream_analog_alt_capture;
135 char stream_name_digital[32]; /* digital PCM stream */
136 const struct hda_pcm_stream *stream_digital_playback;
137 const struct hda_pcm_stream *stream_digital_capture;
140 struct hda_multi_out multiout; /* playback set-up
141 * max_channels, dacs must be set
142 * dig_out_nid and hp_nid are optional
144 hda_nid_t alt_dac_nid;
145 hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */
149 unsigned int num_adc_nids;
150 const hda_nid_t *adc_nids;
151 const hda_nid_t *capsrc_nids;
152 hda_nid_t dig_in_nid; /* digital-in NID; optional */
153 hda_nid_t mixer_nid; /* analog-mixer NID */
155 /* capture setup for dynamic dual-adc switch */
157 unsigned int cur_adc_stream_tag;
158 unsigned int cur_adc_format;
161 unsigned int num_mux_defs;
162 const struct hda_input_mux *input_mux;
163 unsigned int cur_mux[3];
164 hda_nid_t ext_mic_pin;
165 hda_nid_t dock_mic_pin;
166 hda_nid_t int_mic_pin;
169 const struct hda_channel_mode *channel_mode;
170 int num_channel_mode;
172 int const_channel_count; /* min. channel count (for speakers) */
173 int ext_channel_count; /* current channel count for multi-io */
175 /* PCM information */
176 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
178 /* dynamic controls, init_verbs and input_mux */
179 struct auto_pin_cfg autocfg;
180 struct alc_customize_define cdefine;
181 struct snd_array kctls;
182 struct hda_input_mux private_imux[3];
183 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
184 hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS];
185 hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS];
186 hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS];
187 unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS];
188 int int_mic_idx, ext_mic_idx, dock_mic_idx; /* for auto-mic */
189 hda_nid_t inv_dmic_pin;
193 hda_nid_t all_dacs[16];
196 struct snd_array paths;
199 void (*init_hook)(struct hda_codec *codec);
201 void (*power_hook)(struct hda_codec *codec);
203 void (*shutup)(struct hda_codec *codec);
204 void (*automute_hook)(struct hda_codec *codec);
206 /* for pin sensing */
207 unsigned int hp_jack_present:1;
208 unsigned int line_jack_present:1;
209 unsigned int master_mute:1;
210 unsigned int auto_mic:1;
211 unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */
212 unsigned int automute_speaker:1; /* automute speaker outputs */
213 unsigned int automute_lo:1; /* automute LO outputs */
214 unsigned int detect_hp:1; /* Headphone detection enabled */
215 unsigned int detect_lo:1; /* Line-out detection enabled */
216 unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */
217 unsigned int automute_lo_possible:1; /* there are line outs and HP */
218 unsigned int keep_vref_in_automute:1; /* Don't clear VREF in automute */
221 unsigned int no_analog :1; /* digital I/O only */
222 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
223 unsigned int single_input_src:1;
224 unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */
225 unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */
226 unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */
227 unsigned int inv_dmic_fixup:1; /* has inverted digital-mic workaround */
228 unsigned int inv_dmic_muted:1; /* R-ch of inv d-mic is muted? */
229 unsigned int no_primary_hp:1; /* Don't prefer HP pins to speaker pins */
231 /* auto-mute control */
233 hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS];
236 int codec_variant; /* flag for other variants */
238 /* for virtual master */
239 hda_nid_t vmaster_nid;
240 struct hda_vmaster_mute_hook vmaster_mute;
242 struct hda_loopback_check loopback;
244 struct hda_amp_list loopback_list[8];
249 unsigned int pll_coef_idx, pll_coef_bit;
254 struct alc_multi_io multi_io[4];
257 struct snd_array bind_ctls;
260 static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
261 int dir, unsigned int bits)
265 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
266 if (query_amp_caps(codec, nid, dir) & bits)
271 #define nid_has_mute(codec, nid, dir) \
272 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
273 #define nid_has_volume(codec, nid, dir) \
274 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
279 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
280 struct snd_ctl_elem_info *uinfo)
282 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
283 struct alc_spec *spec = codec->spec;
284 unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
285 if (mux_idx >= spec->num_mux_defs)
287 if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
289 return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
292 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
293 struct snd_ctl_elem_value *ucontrol)
295 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
296 struct alc_spec *spec = codec->spec;
297 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
299 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
303 static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
305 struct alc_spec *spec = codec->spec;
306 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
308 if (spec->cur_adc && spec->cur_adc != new_adc) {
309 /* stream is running, let's swap the current ADC */
310 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
311 spec->cur_adc = new_adc;
312 snd_hda_codec_setup_stream(codec, new_adc,
313 spec->cur_adc_stream_tag, 0,
314 spec->cur_adc_format);
320 static inline hda_nid_t get_capsrc(struct alc_spec *spec, int idx)
322 return spec->capsrc_nids ?
323 spec->capsrc_nids[idx] : spec->adc_nids[idx];
326 static void call_update_outputs(struct hda_codec *codec);
327 static void alc_inv_dmic_sync(struct hda_codec *codec, bool force);
329 /* for shared I/O, change the pin-control accordingly */
330 static void update_shared_mic_hp(struct hda_codec *codec, bool set_as_mic)
332 struct alc_spec *spec = codec->spec;
334 hda_nid_t pin = spec->autocfg.inputs[1].pin;
335 /* NOTE: this assumes that there are only two inputs, the
336 * first is the real internal mic and the second is HP/mic jack.
339 val = snd_hda_get_default_vref(codec, pin);
341 /* This pin does not have vref caps - let's enable vref on pin 0x18
342 instead, as suggested by Realtek */
343 if (val == AC_PINCTL_VREF_HIZ) {
344 const hda_nid_t vref_pin = 0x18;
345 /* Sanity check pin 0x18 */
346 if (get_wcaps_type(get_wcaps(codec, vref_pin)) == AC_WID_PIN &&
347 get_defcfg_connect(snd_hda_codec_get_pincfg(codec, vref_pin)) == AC_JACK_PORT_NONE) {
348 unsigned int vref_val = snd_hda_get_default_vref(codec, vref_pin);
349 if (vref_val != AC_PINCTL_VREF_HIZ)
350 snd_hda_set_pin_ctl(codec, vref_pin, PIN_IN | (set_as_mic ? vref_val : 0));
354 val = set_as_mic ? val | PIN_IN : PIN_HP;
355 snd_hda_set_pin_ctl(codec, pin, val);
357 spec->automute_speaker = !set_as_mic;
358 call_update_outputs(codec);
361 /* select the given imux item; either unmute exclusively or select the route */
362 static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
363 unsigned int idx, bool force)
365 struct alc_spec *spec = codec->spec;
366 const struct hda_input_mux *imux;
367 unsigned int mux_idx;
368 int i, type, num_conns;
371 if (!spec->input_mux)
374 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
375 imux = &spec->input_mux[mux_idx];
376 if (!imux->num_items && mux_idx > 0)
377 imux = &spec->input_mux[0];
378 if (!imux->num_items)
381 if (idx >= imux->num_items)
382 idx = imux->num_items - 1;
383 if (spec->cur_mux[adc_idx] == idx && !force)
385 spec->cur_mux[adc_idx] = idx;
387 if (spec->shared_mic_hp)
388 update_shared_mic_hp(codec, spec->cur_mux[adc_idx]);
390 if (spec->dyn_adc_switch) {
391 alc_dyn_adc_pcm_resetup(codec, idx);
392 adc_idx = spec->dyn_adc_idx[idx];
395 nid = get_capsrc(spec, adc_idx);
398 num_conns = snd_hda_get_num_conns(codec, nid);
402 type = get_wcaps_type(get_wcaps(codec, nid));
403 if (type == AC_WID_AUD_MIX) {
404 /* Matrix-mixer style (e.g. ALC882) */
405 int active = imux->items[idx].index;
406 for (i = 0; i < num_conns; i++) {
407 unsigned int v = (i == active) ? 0 : HDA_AMP_MUTE;
408 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, i,
412 /* MUX style (e.g. ALC880) */
413 snd_hda_codec_write_cache(codec, nid, 0,
414 AC_VERB_SET_CONNECT_SEL,
415 imux->items[idx].index);
417 alc_inv_dmic_sync(codec, true);
421 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
422 struct snd_ctl_elem_value *ucontrol)
424 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
425 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
426 return alc_mux_select(codec, adc_idx,
427 ucontrol->value.enumerated.item[0], false);
431 * set up the input pin config (depending on the given auto-pin type)
433 static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
436 unsigned int val = PIN_IN;
437 if (auto_pin_type == AUTO_PIN_MIC)
438 val |= snd_hda_get_default_vref(codec, nid);
439 snd_hda_set_pin_ctl(codec, nid, val);
443 * Append the given mixer and verb elements for the later use
444 * The mixer array is referred in build_controls(), and init_verbs are
447 static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
449 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
451 spec->mixers[spec->num_mixers++] = mix;
455 * GPIO setup tables, used in initialization
457 /* Enable GPIO mask and set output */
458 static const struct hda_verb alc_gpio1_init_verbs[] = {
459 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
460 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
461 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
465 static const struct hda_verb alc_gpio2_init_verbs[] = {
466 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
467 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
468 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
472 static const struct hda_verb alc_gpio3_init_verbs[] = {
473 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
474 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
475 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
480 * Fix hardware PLL issue
481 * On some codecs, the analog PLL gating control must be off while
482 * the default value is 1.
484 static void alc_fix_pll(struct hda_codec *codec)
486 struct alc_spec *spec = codec->spec;
491 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
493 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
494 AC_VERB_GET_PROC_COEF, 0);
495 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
497 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
498 val & ~(1 << spec->pll_coef_bit));
501 static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
502 unsigned int coef_idx, unsigned int coef_bit)
504 struct alc_spec *spec = codec->spec;
506 spec->pll_coef_idx = coef_idx;
507 spec->pll_coef_bit = coef_bit;
512 * Jack detections for HP auto-mute and mic-switch
515 /* check each pin in the given array; returns true if any of them is plugged */
516 static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
520 for (i = 0; i < num_pins; i++) {
521 hda_nid_t nid = pins[i];
524 present |= snd_hda_jack_detect(codec, nid);
529 /* standard HP/line-out auto-mute helper */
530 static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
531 bool mute, bool hp_out)
533 struct alc_spec *spec = codec->spec;
534 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
537 for (i = 0; i < num_pins; i++) {
538 hda_nid_t nid = pins[i];
542 /* don't reset VREF value in case it's controlling
543 * the amp (see alc861_fixup_asus_amp_vref_0f())
545 if (spec->keep_vref_in_automute) {
546 val = snd_hda_codec_read(codec, nid, 0,
547 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
552 snd_hda_set_pin_ctl(codec, nid, val);
556 /* Toggle outputs muting */
557 static void update_outputs(struct hda_codec *codec)
559 struct alc_spec *spec = codec->spec;
562 /* Control HP pins/amps depending on master_mute state;
563 * in general, HP pins/amps control should be enabled in all cases,
564 * but currently set only for master_mute, just to be safe
566 if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */
567 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
568 spec->autocfg.hp_pins, spec->master_mute, true);
570 if (!spec->automute_speaker)
573 on = spec->hp_jack_present | spec->line_jack_present;
574 on |= spec->master_mute;
575 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
576 spec->autocfg.speaker_pins, on, false);
578 /* toggle line-out mutes if needed, too */
579 /* if LO is a copy of either HP or Speaker, don't need to handle it */
580 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
581 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
583 if (!spec->automute_lo)
586 on = spec->hp_jack_present;
587 on |= spec->master_mute;
588 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
589 spec->autocfg.line_out_pins, on, false);
592 static void call_update_outputs(struct hda_codec *codec)
594 struct alc_spec *spec = codec->spec;
595 if (spec->automute_hook)
596 spec->automute_hook(codec);
598 update_outputs(codec);
601 /* standard HP-automute helper */
602 static void alc_hp_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
604 struct alc_spec *spec = codec->spec;
606 spec->hp_jack_present =
607 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
608 spec->autocfg.hp_pins);
609 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
611 call_update_outputs(codec);
614 /* standard line-out-automute helper */
615 static void alc_line_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
617 struct alc_spec *spec = codec->spec;
619 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
621 /* check LO jack only when it's different from HP */
622 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
625 spec->line_jack_present =
626 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
627 spec->autocfg.line_out_pins);
628 if (!spec->automute_speaker || !spec->detect_lo)
630 call_update_outputs(codec);
633 #define get_connection_index(codec, mux, nid) \
634 snd_hda_get_conn_index(codec, mux, nid, 0)
636 /* standard mic auto-switch helper */
637 static void alc_mic_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
639 struct alc_spec *spec = codec->spec;
640 hda_nid_t *pins = spec->imux_pins;
642 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
644 if (snd_BUG_ON(!spec->adc_nids))
646 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
649 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
650 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
651 else if (spec->dock_mic_idx >= 0 &&
652 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
653 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
655 alc_mux_select(codec, 0, spec->int_mic_idx, false);
658 /* update the master volume per volume-knob's unsol event */
659 static void alc_update_knob_master(struct hda_codec *codec, struct hda_jack_tbl *jack)
662 struct snd_kcontrol *kctl;
663 struct snd_ctl_elem_value *uctl;
665 kctl = snd_hda_find_mixer_ctl(codec, "Master Playback Volume");
668 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
671 val = snd_hda_codec_read(codec, jack->nid, 0,
672 AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
673 val &= HDA_AMP_VOLMASK;
674 uctl->value.integer.value[0] = val;
675 uctl->value.integer.value[1] = val;
676 kctl->put(kctl, uctl);
680 static void alc880_unsol_event(struct hda_codec *codec, unsigned int res)
682 /* For some reason, the res given from ALC880 is broken.
683 Here we adjust it properly. */
684 snd_hda_jack_unsol_event(codec, res >> 2);
687 /* call init functions of standard auto-mute helpers */
688 static void alc_inithook(struct hda_codec *codec)
690 alc_hp_automute(codec, NULL);
691 alc_line_automute(codec, NULL);
692 alc_mic_automute(codec, NULL);
695 /* additional initialization for ALC888 variants */
696 static void alc888_coef_init(struct hda_codec *codec)
700 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
701 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
702 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
703 if ((tmp & 0xf0) == 0x20)
705 snd_hda_codec_read(codec, 0x20, 0,
706 AC_VERB_SET_PROC_COEF, 0x830);
709 snd_hda_codec_read(codec, 0x20, 0,
710 AC_VERB_SET_PROC_COEF, 0x3030);
713 /* additional initialization for ALC889 variants */
714 static void alc889_coef_init(struct hda_codec *codec)
718 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
719 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
720 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
721 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
724 /* turn on/off EAPD control (only if available) */
725 static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
727 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
729 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
730 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
734 /* turn on/off EAPD controls of the codec */
735 static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
737 /* We currently only handle front, HP */
738 static hda_nid_t pins[] = {
739 0x0f, 0x10, 0x14, 0x15, 0
742 for (p = pins; *p; p++)
743 set_eapd(codec, *p, on);
746 /* generic shutup callback;
747 * just turning off EPAD and a little pause for avoiding pop-noise
749 static void alc_eapd_shutup(struct hda_codec *codec)
751 alc_auto_setup_eapd(codec, false);
755 /* generic EAPD initialization */
756 static void alc_auto_init_amp(struct hda_codec *codec, int type)
760 alc_auto_setup_eapd(codec, true);
763 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
766 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
769 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
771 case ALC_INIT_DEFAULT:
772 switch (codec->vendor_id) {
774 snd_hda_codec_write(codec, 0x1a, 0,
775 AC_VERB_SET_COEF_INDEX, 7);
776 tmp = snd_hda_codec_read(codec, 0x1a, 0,
777 AC_VERB_GET_PROC_COEF, 0);
778 snd_hda_codec_write(codec, 0x1a, 0,
779 AC_VERB_SET_COEF_INDEX, 7);
780 snd_hda_codec_write(codec, 0x1a, 0,
781 AC_VERB_SET_PROC_COEF,
790 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
791 alc889_coef_init(codec);
794 alc888_coef_init(codec);
796 #if 0 /* XXX: This may cause the silent output on speaker on some machines */
799 snd_hda_codec_write(codec, 0x20, 0,
800 AC_VERB_SET_COEF_INDEX, 7);
801 tmp = snd_hda_codec_read(codec, 0x20, 0,
802 AC_VERB_GET_PROC_COEF, 0);
803 snd_hda_codec_write(codec, 0x20, 0,
804 AC_VERB_SET_COEF_INDEX, 7);
805 snd_hda_codec_write(codec, 0x20, 0,
806 AC_VERB_SET_PROC_COEF,
816 * Auto-Mute mode mixer enum support
818 static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
819 struct snd_ctl_elem_info *uinfo)
821 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
822 struct alc_spec *spec = codec->spec;
823 static const char * const texts3[] = {
824 "Disabled", "Speaker Only", "Line Out+Speaker"
827 if (spec->automute_speaker_possible && spec->automute_lo_possible)
828 return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3);
829 return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
832 static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
833 struct snd_ctl_elem_value *ucontrol)
835 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
836 struct alc_spec *spec = codec->spec;
837 unsigned int val = 0;
838 if (spec->automute_speaker)
840 if (spec->automute_lo)
843 ucontrol->value.enumerated.item[0] = val;
847 static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
848 struct snd_ctl_elem_value *ucontrol)
850 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
851 struct alc_spec *spec = codec->spec;
853 switch (ucontrol->value.enumerated.item[0]) {
855 if (!spec->automute_speaker && !spec->automute_lo)
857 spec->automute_speaker = 0;
858 spec->automute_lo = 0;
861 if (spec->automute_speaker_possible) {
862 if (!spec->automute_lo && spec->automute_speaker)
864 spec->automute_speaker = 1;
865 spec->automute_lo = 0;
866 } else if (spec->automute_lo_possible) {
867 if (spec->automute_lo)
869 spec->automute_lo = 1;
874 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
876 if (spec->automute_speaker && spec->automute_lo)
878 spec->automute_speaker = 1;
879 spec->automute_lo = 1;
884 call_update_outputs(codec);
888 static const struct snd_kcontrol_new alc_automute_mode_enum = {
889 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
890 .name = "Auto-Mute Mode",
891 .info = alc_automute_mode_info,
892 .get = alc_automute_mode_get,
893 .put = alc_automute_mode_put,
896 static struct snd_kcontrol_new *
897 alc_kcontrol_new(struct alc_spec *spec, const char *name,
898 const struct snd_kcontrol_new *temp)
900 struct snd_kcontrol_new *knew = snd_array_new(&spec->kctls);
904 knew->name = kstrdup(name, GFP_KERNEL);
910 static int alc_add_automute_mode_enum(struct hda_codec *codec)
912 struct alc_spec *spec = codec->spec;
914 if (!alc_kcontrol_new(spec, "Auto-Mute Mode", &alc_automute_mode_enum))
920 * Check the availability of HP/line-out auto-mute;
921 * Set up appropriately if really supported
923 static int alc_init_automute(struct hda_codec *codec)
925 struct alc_spec *spec = codec->spec;
926 struct auto_pin_cfg *cfg = &spec->autocfg;
932 if (cfg->line_out_pins[0])
934 if (cfg->speaker_pins[0])
936 if (present < 2) /* need two different output types */
939 if (!cfg->speaker_pins[0] &&
940 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
941 memcpy(cfg->speaker_pins, cfg->line_out_pins,
942 sizeof(cfg->speaker_pins));
943 cfg->speaker_outs = cfg->line_outs;
946 if (!cfg->hp_pins[0] &&
947 cfg->line_out_type == AUTO_PIN_HP_OUT) {
948 memcpy(cfg->hp_pins, cfg->line_out_pins,
949 sizeof(cfg->hp_pins));
950 cfg->hp_outs = cfg->line_outs;
953 for (i = 0; i < cfg->hp_outs; i++) {
954 hda_nid_t nid = cfg->hp_pins[i];
955 if (!is_jack_detectable(codec, nid))
957 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
959 snd_hda_jack_detect_enable_callback(codec, nid, ALC_HP_EVENT,
964 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
965 if (cfg->speaker_outs)
966 for (i = 0; i < cfg->line_outs; i++) {
967 hda_nid_t nid = cfg->line_out_pins[i];
968 if (!is_jack_detectable(codec, nid))
970 snd_printdd("realtek: Enable Line-Out "
971 "auto-muting on NID 0x%x\n", nid);
972 snd_hda_jack_detect_enable_callback(codec, nid, ALC_FRONT_EVENT,
976 spec->automute_lo_possible = spec->detect_hp;
979 spec->automute_speaker_possible = cfg->speaker_outs &&
980 (spec->detect_hp || spec->detect_lo);
982 spec->automute_lo = spec->automute_lo_possible;
983 spec->automute_speaker = spec->automute_speaker_possible;
985 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
986 /* create a control for automute mode */
987 err = alc_add_automute_mode_enum(codec);
994 /* return the position of NID in the list, or -1 if not found */
995 static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
998 for (i = 0; i < nums; i++)
1004 /* check whether dynamic ADC-switching is available */
1005 static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
1007 struct alc_spec *spec = codec->spec;
1008 struct hda_input_mux *imux = &spec->private_imux[0];
1012 if (imux != spec->input_mux) /* no dynamic imux? */
1015 for (n = 0; n < spec->num_adc_nids; n++) {
1016 cap = spec->private_capsrc_nids[n];
1017 for (i = 0; i < imux->num_items; i++) {
1018 pin = spec->imux_pins[i];
1021 if (get_connection_index(codec, cap, pin) < 0)
1024 if (i >= imux->num_items)
1025 return true; /* no ADC-switch is needed */
1028 for (i = 0; i < imux->num_items; i++) {
1029 pin = spec->imux_pins[i];
1030 for (n = 0; n < spec->num_adc_nids; n++) {
1031 cap = spec->private_capsrc_nids[n];
1032 idx = get_connection_index(codec, cap, pin);
1034 imux->items[i].index = idx;
1035 spec->dyn_adc_idx[i] = n;
1041 snd_printdd("realtek: enabling ADC switching\n");
1042 spec->dyn_adc_switch = 1;
1046 /* check whether all auto-mic pins are valid; setup indices if OK */
1047 static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1049 struct alc_spec *spec = codec->spec;
1050 const struct hda_input_mux *imux;
1052 if (!spec->auto_mic)
1054 if (spec->auto_mic_valid_imux)
1055 return true; /* already checked */
1057 /* fill up imux indices */
1058 if (!alc_check_dyn_adc_switch(codec)) {
1063 imux = spec->input_mux;
1064 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1065 spec->imux_pins, imux->num_items);
1066 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1067 spec->imux_pins, imux->num_items);
1068 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1069 spec->imux_pins, imux->num_items);
1070 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1072 return false; /* no corresponding imux */
1075 snd_hda_jack_detect_enable_callback(codec, spec->ext_mic_pin,
1076 ALC_MIC_EVENT, alc_mic_automute);
1077 if (spec->dock_mic_pin)
1078 snd_hda_jack_detect_enable_callback(codec, spec->dock_mic_pin,
1082 spec->auto_mic_valid_imux = 1;
1088 * Check the availability of auto-mic switch;
1089 * Set up if really supported
1091 static int alc_init_auto_mic(struct hda_codec *codec)
1093 struct alc_spec *spec = codec->spec;
1094 struct auto_pin_cfg *cfg = &spec->autocfg;
1095 hda_nid_t fixed, ext, dock;
1098 if (spec->shared_mic_hp)
1099 return 0; /* no auto-mic for the shared I/O */
1101 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1103 fixed = ext = dock = 0;
1104 for (i = 0; i < cfg->num_inputs; i++) {
1105 hda_nid_t nid = cfg->inputs[i].pin;
1106 unsigned int defcfg;
1107 defcfg = snd_hda_codec_get_pincfg(codec, nid);
1108 switch (snd_hda_get_input_pin_attr(defcfg)) {
1109 case INPUT_PIN_ATTR_INT:
1111 return 0; /* already occupied */
1112 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1113 return 0; /* invalid type */
1116 case INPUT_PIN_ATTR_UNUSED:
1117 return 0; /* invalid entry */
1118 case INPUT_PIN_ATTR_DOCK:
1120 return 0; /* already occupied */
1121 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1122 return 0; /* invalid type */
1127 return 0; /* already occupied */
1128 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1129 return 0; /* invalid type */
1140 if (!is_jack_detectable(codec, ext))
1141 return 0; /* no unsol support */
1142 if (dock && !is_jack_detectable(codec, dock))
1143 return 0; /* no unsol support */
1145 /* check imux indices */
1146 spec->ext_mic_pin = ext;
1147 spec->int_mic_pin = fixed;
1148 spec->dock_mic_pin = dock;
1151 if (!alc_auto_mic_check_imux(codec))
1154 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1160 /* check the availabilities of auto-mute and auto-mic switches */
1161 static int alc_auto_check_switches(struct hda_codec *codec)
1165 err = alc_init_automute(codec);
1168 err = alc_init_auto_mic(codec);
1175 * Realtek SSID verification
1178 /* Could be any non-zero and even value. When used as fixup, tells
1179 * the driver to ignore any present sku defines.
1181 #define ALC_FIXUP_SKU_IGNORE (2)
1183 static void alc_fixup_sku_ignore(struct hda_codec *codec,
1184 const struct hda_fixup *fix, int action)
1186 struct alc_spec *spec = codec->spec;
1187 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
1188 spec->cdefine.fixup = 1;
1189 spec->cdefine.sku_cfg = ALC_FIXUP_SKU_IGNORE;
1193 static int alc_auto_parse_customize_define(struct hda_codec *codec)
1195 unsigned int ass, tmp, i;
1197 struct alc_spec *spec = codec->spec;
1199 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1201 if (spec->cdefine.fixup) {
1202 ass = spec->cdefine.sku_cfg;
1203 if (ass == ALC_FIXUP_SKU_IGNORE)
1208 ass = codec->subsystem_id & 0xffff;
1209 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
1213 if (codec->vendor_id == 0x10ec0260)
1215 ass = snd_hda_codec_get_pincfg(codec, nid);
1218 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1219 codec->chip_name, ass);
1225 for (i = 1; i < 16; i++) {
1229 if (((ass >> 16) & 0xf) != tmp)
1232 spec->cdefine.port_connectivity = ass >> 30;
1233 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1234 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1235 spec->cdefine.customization = ass >> 8;
1237 spec->cdefine.sku_cfg = ass;
1238 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1239 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1240 spec->cdefine.swap = (ass & 0x2) >> 1;
1241 spec->cdefine.override = ass & 0x1;
1243 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1244 nid, spec->cdefine.sku_cfg);
1245 snd_printd("SKU: port_connectivity=0x%x\n",
1246 spec->cdefine.port_connectivity);
1247 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1248 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1249 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1250 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1251 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1252 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1253 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1258 /* return true if the given NID is found in the list */
1259 static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1261 return find_idx_in_nid_list(nid, list, nums) >= 0;
1264 /* check subsystem ID and set up device-specific initialization;
1265 * return 1 if initialized, 0 if invalid SSID
1267 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1268 * 31 ~ 16 : Manufacture ID
1270 * 7 ~ 0 : Assembly ID
1271 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1273 static int alc_subsystem_id(struct hda_codec *codec,
1274 hda_nid_t porta, hda_nid_t porte,
1275 hda_nid_t portd, hda_nid_t porti)
1277 unsigned int ass, tmp, i;
1279 struct alc_spec *spec = codec->spec;
1281 if (spec->cdefine.fixup) {
1282 ass = spec->cdefine.sku_cfg;
1283 if (ass == ALC_FIXUP_SKU_IGNORE)
1288 ass = codec->subsystem_id & 0xffff;
1289 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1292 /* invalid SSID, check the special NID pin defcfg instead */
1294 * 31~30 : port connectivity
1297 * 19~16 : Check sum (15:1)
1302 if (codec->vendor_id == 0x10ec0260)
1304 ass = snd_hda_codec_get_pincfg(codec, nid);
1305 snd_printd("realtek: No valid SSID, "
1306 "checking pincfg 0x%08x for NID 0x%x\n",
1310 if ((ass >> 30) != 1) /* no physical connection */
1315 for (i = 1; i < 16; i++) {
1319 if (((ass >> 16) & 0xf) != tmp)
1322 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1323 ass & 0xffff, codec->vendor_id);
1327 * 2 : 0 --> Desktop, 1 --> Laptop
1328 * 3~5 : External Amplifier control
1331 tmp = (ass & 0x38) >> 3; /* external Amp control */
1334 spec->init_amp = ALC_INIT_GPIO1;
1337 spec->init_amp = ALC_INIT_GPIO2;
1340 spec->init_amp = ALC_INIT_GPIO3;
1344 spec->init_amp = ALC_INIT_DEFAULT;
1348 /* is laptop or Desktop and enable the function "Mute internal speaker
1349 * when the external headphone out jack is plugged"
1351 if (!(ass & 0x8000))
1354 * 10~8 : Jack location
1355 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1357 * 15 : 1 --> enable the function "Mute internal speaker
1358 * when the external headphone out jack is plugged"
1360 if (!spec->autocfg.hp_pins[0] &&
1361 !(spec->autocfg.line_out_pins[0] &&
1362 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
1364 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1375 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1376 spec->autocfg.line_outs))
1378 spec->autocfg.hp_pins[0] = nid;
1383 /* Check the validity of ALC subsystem-id
1384 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1385 static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
1387 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
1388 struct alc_spec *spec = codec->spec;
1389 snd_printd("realtek: "
1390 "Enable default setup for auto mode as fallback\n");
1391 spec->init_amp = ALC_INIT_DEFAULT;
1396 * COEF access helper functions
1398 static int alc_read_coef_idx(struct hda_codec *codec,
1399 unsigned int coef_idx)
1402 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1404 val = snd_hda_codec_read(codec, 0x20, 0,
1405 AC_VERB_GET_PROC_COEF, 0);
1409 static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1410 unsigned int coef_val)
1412 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1414 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1418 /* a special bypass for COEF 0; read the cached value at the second time */
1419 static unsigned int alc_get_coef0(struct hda_codec *codec)
1421 struct alc_spec *spec = codec->spec;
1423 spec->coef0 = alc_read_coef_idx(codec, 0);
1428 * Digital I/O handling
1431 /* set right pin controls for digital I/O */
1432 static void alc_auto_init_digital(struct hda_codec *codec)
1434 struct alc_spec *spec = codec->spec;
1438 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1439 pin = spec->autocfg.dig_out_pins[i];
1442 snd_hda_set_pin_ctl(codec, pin, PIN_OUT);
1444 dac = spec->multiout.dig_out_nid;
1446 dac = spec->slave_dig_outs[i - 1];
1447 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
1449 snd_hda_codec_write(codec, dac, 0,
1450 AC_VERB_SET_AMP_GAIN_MUTE,
1453 pin = spec->autocfg.dig_in_pin;
1455 snd_hda_set_pin_ctl(codec, pin, PIN_IN);
1458 /* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1459 static void alc_auto_parse_digital(struct hda_codec *codec)
1461 struct alc_spec *spec = codec->spec;
1465 /* support multiple SPDIFs; the secondary is set up as a slave */
1467 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1469 err = snd_hda_get_connections(codec,
1470 spec->autocfg.dig_out_pins[i],
1471 conn, ARRAY_SIZE(conn));
1474 dig_nid = conn[0]; /* assume the first element is audio-out */
1476 spec->multiout.dig_out_nid = dig_nid;
1477 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1479 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
1480 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
1482 spec->slave_dig_outs[nums - 1] = dig_nid;
1487 if (spec->autocfg.dig_in_pin) {
1488 dig_nid = codec->start_nid;
1489 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1490 unsigned int wcaps = get_wcaps(codec, dig_nid);
1491 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1493 if (!(wcaps & AC_WCAP_DIGITAL))
1495 if (!(wcaps & AC_WCAP_CONN_LIST))
1497 err = get_connection_index(codec, dig_nid,
1498 spec->autocfg.dig_in_pin);
1500 spec->dig_in_nid = dig_nid;
1508 * capture mixer elements
1510 static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1511 struct snd_ctl_elem_info *uinfo)
1513 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1514 struct alc_spec *spec = codec->spec;
1518 mutex_lock(&codec->control_mutex);
1519 if (spec->vol_in_capsrc)
1520 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1522 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1523 kcontrol->private_value = val;
1524 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
1525 mutex_unlock(&codec->control_mutex);
1529 static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1530 unsigned int size, unsigned int __user *tlv)
1532 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1533 struct alc_spec *spec = codec->spec;
1537 mutex_lock(&codec->control_mutex);
1538 if (spec->vol_in_capsrc)
1539 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1541 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1542 kcontrol->private_value = val;
1543 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
1544 mutex_unlock(&codec->control_mutex);
1548 typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1549 struct snd_ctl_elem_value *ucontrol);
1551 static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1552 struct snd_ctl_elem_value *ucontrol,
1553 getput_call_t func, bool is_put)
1555 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1556 struct alc_spec *spec = codec->spec;
1559 mutex_lock(&codec->control_mutex);
1560 if (is_put && spec->dyn_adc_switch) {
1561 for (i = 0; i < spec->num_adc_nids; i++) {
1562 kcontrol->private_value =
1563 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1565 err = func(kcontrol, ucontrol);
1570 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1571 if (spec->vol_in_capsrc)
1572 kcontrol->private_value =
1573 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1576 kcontrol->private_value =
1577 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1579 err = func(kcontrol, ucontrol);
1581 if (err >= 0 && is_put)
1582 alc_inv_dmic_sync(codec, false);
1584 mutex_unlock(&codec->control_mutex);
1588 static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1589 struct snd_ctl_elem_value *ucontrol)
1591 return alc_cap_getput_caller(kcontrol, ucontrol,
1592 snd_hda_mixer_amp_volume_get, false);
1595 static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1596 struct snd_ctl_elem_value *ucontrol)
1598 return alc_cap_getput_caller(kcontrol, ucontrol,
1599 snd_hda_mixer_amp_volume_put, true);
1602 /* capture mixer elements */
1603 #define alc_cap_sw_info snd_ctl_boolean_stereo_info
1605 static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1606 struct snd_ctl_elem_value *ucontrol)
1608 return alc_cap_getput_caller(kcontrol, ucontrol,
1609 snd_hda_mixer_amp_switch_get, false);
1612 static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1613 struct snd_ctl_elem_value *ucontrol)
1615 return alc_cap_getput_caller(kcontrol, ucontrol,
1616 snd_hda_mixer_amp_switch_put, true);
1619 #define _DEFINE_CAPMIX(num) \
1621 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1622 .name = "Capture Switch", \
1623 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1625 .info = alc_cap_sw_info, \
1626 .get = alc_cap_sw_get, \
1627 .put = alc_cap_sw_put, \
1630 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1631 .name = "Capture Volume", \
1632 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1633 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1634 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1636 .info = alc_cap_vol_info, \
1637 .get = alc_cap_vol_get, \
1638 .put = alc_cap_vol_put, \
1639 .tlv = { .c = alc_cap_vol_tlv }, \
1642 #define _DEFINE_CAPSRC(num) \
1644 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1645 /* .name = "Capture Source", */ \
1646 .name = "Input Source", \
1648 .info = alc_mux_enum_info, \
1649 .get = alc_mux_enum_get, \
1650 .put = alc_mux_enum_put, \
1653 #define DEFINE_CAPMIX(num) \
1654 static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
1655 _DEFINE_CAPMIX(num), \
1656 _DEFINE_CAPSRC(num), \
1660 #define DEFINE_CAPMIX_NOSRC(num) \
1661 static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
1662 _DEFINE_CAPMIX(num), \
1666 /* up to three ADCs */
1670 DEFINE_CAPMIX_NOSRC(1);
1671 DEFINE_CAPMIX_NOSRC(2);
1672 DEFINE_CAPMIX_NOSRC(3);
1675 * Inverted digital-mic handling
1677 * First off, it's a bit tricky. The "Inverted Internal Mic Capture Switch"
1678 * gives the additional mute only to the right channel of the digital mic
1679 * capture stream. This is a workaround for avoiding the almost silence
1680 * by summing the stereo stream from some (known to be ForteMedia)
1683 * The logic is to call alc_inv_dmic_sync() after each action (possibly)
1684 * modifying ADC amp. When the mute flag is set, it mutes the R-channel
1685 * without caching so that the cache can still keep the original value.
1686 * The cached value is then restored when the flag is set off or any other
1687 * than d-mic is used as the current input source.
1689 static void alc_inv_dmic_sync(struct hda_codec *codec, bool force)
1691 struct alc_spec *spec = codec->spec;
1694 if (!spec->inv_dmic_fixup)
1696 if (!spec->inv_dmic_muted && !force)
1698 for (i = 0; i < spec->num_adc_nids; i++) {
1699 int src = spec->dyn_adc_switch ? 0 : i;
1700 bool dmic_fixup = false;
1704 if (spec->inv_dmic_muted &&
1705 spec->imux_pins[spec->cur_mux[src]] == spec->inv_dmic_pin)
1707 if (!dmic_fixup && !force)
1709 if (spec->vol_in_capsrc) {
1710 nid = spec->capsrc_nids[i];
1711 parm = AC_AMP_SET_RIGHT | AC_AMP_SET_OUTPUT;
1714 nid = spec->adc_nids[i];
1715 parm = AC_AMP_SET_RIGHT | AC_AMP_SET_INPUT;
1718 /* we care only right channel */
1719 v = snd_hda_codec_amp_read(codec, nid, 1, dir, 0);
1720 if (v & 0x80) /* if already muted, we don't need to touch */
1722 if (dmic_fixup) /* add mute for d-mic */
1724 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
1729 static int alc_inv_dmic_sw_get(struct snd_kcontrol *kcontrol,
1730 struct snd_ctl_elem_value *ucontrol)
1732 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1733 struct alc_spec *spec = codec->spec;
1735 ucontrol->value.integer.value[0] = !spec->inv_dmic_muted;
1739 static int alc_inv_dmic_sw_put(struct snd_kcontrol *kcontrol,
1740 struct snd_ctl_elem_value *ucontrol)
1742 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1743 struct alc_spec *spec = codec->spec;
1744 unsigned int val = !ucontrol->value.integer.value[0];
1746 if (val == spec->inv_dmic_muted)
1748 spec->inv_dmic_muted = val;
1749 alc_inv_dmic_sync(codec, true);
1753 static const struct snd_kcontrol_new alc_inv_dmic_sw = {
1754 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1755 .info = snd_ctl_boolean_mono_info,
1756 .get = alc_inv_dmic_sw_get,
1757 .put = alc_inv_dmic_sw_put,
1760 static int alc_add_inv_dmic_mixer(struct hda_codec *codec, hda_nid_t nid)
1762 struct alc_spec *spec = codec->spec;
1764 if (!alc_kcontrol_new(spec, "Inverted Internal Mic Capture Switch",
1767 spec->inv_dmic_fixup = 1;
1768 spec->inv_dmic_muted = 0;
1769 spec->inv_dmic_pin = nid;
1773 /* typically the digital mic is put at node 0x12 */
1774 static void alc_fixup_inv_dmic_0x12(struct hda_codec *codec,
1775 const struct alc_fixup *fix, int action)
1777 if (action == ALC_FIXUP_ACT_PROBE)
1778 alc_add_inv_dmic_mixer(codec, 0x12);
1782 * virtual master controls
1786 * slave controls for virtual master
1788 static const char * const alc_slave_pfxs[] = {
1789 "Front", "Surround", "Center", "LFE", "Side",
1790 "Headphone", "Speaker", "Mono", "Line Out",
1791 "CLFE", "Bass Speaker", "PCM",
1796 * build control elements
1799 #define NID_MAPPING (-1)
1801 #define SUBDEV_SPEAKER_ (0 << 6)
1802 #define SUBDEV_HP_ (1 << 6)
1803 #define SUBDEV_LINE_ (2 << 6)
1804 #define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1805 #define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1806 #define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1808 static void alc_free_kctls(struct hda_codec *codec);
1810 #ifdef CONFIG_SND_HDA_INPUT_BEEP
1811 /* additional beep mixers; the actual parameters are overwritten at build */
1812 static const struct snd_kcontrol_new alc_beep_mixer[] = {
1813 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
1814 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
1819 static int __alc_build_controls(struct hda_codec *codec)
1821 struct alc_spec *spec = codec->spec;
1822 struct snd_kcontrol *kctl = NULL;
1823 const struct snd_kcontrol_new *knew;
1828 for (i = 0; i < spec->num_mixers; i++) {
1829 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1833 if (spec->cap_mixer) {
1834 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1838 if (spec->multiout.dig_out_nid) {
1839 err = snd_hda_create_dig_out_ctls(codec,
1840 spec->multiout.dig_out_nid,
1841 spec->multiout.dig_out_nid,
1842 spec->pcm_rec[1].pcm_type);
1845 if (!spec->no_analog) {
1846 err = snd_hda_create_spdif_share_sw(codec,
1850 spec->multiout.share_spdif = 1;
1853 if (spec->dig_in_nid) {
1854 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1859 #ifdef CONFIG_SND_HDA_INPUT_BEEP
1860 /* create beep controls if needed */
1861 if (spec->beep_amp) {
1862 const struct snd_kcontrol_new *knew;
1863 for (knew = alc_beep_mixer; knew->name; knew++) {
1864 struct snd_kcontrol *kctl;
1865 kctl = snd_ctl_new1(knew, codec);
1868 kctl->private_value = spec->beep_amp;
1869 err = snd_hda_ctl_add(codec, 0, kctl);
1876 /* if we have no master control, let's create it */
1877 if (!spec->no_analog &&
1878 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1879 unsigned int vmaster_tlv[4];
1880 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
1881 HDA_OUTPUT, vmaster_tlv);
1882 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1883 vmaster_tlv, alc_slave_pfxs,
1888 if (!spec->no_analog &&
1889 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1890 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
1891 NULL, alc_slave_pfxs,
1893 true, &spec->vmaster_mute.sw_kctl);
1898 /* assign Capture Source enums to NID */
1899 if (spec->capsrc_nids || spec->adc_nids) {
1900 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
1902 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1903 for (i = 0; kctl && i < kctl->count; i++) {
1904 err = snd_hda_add_nid(codec, kctl, i,
1905 get_capsrc(spec, i));
1910 if (spec->cap_mixer && spec->adc_nids) {
1911 const char *kname = kctl ? kctl->id.name : NULL;
1912 for (knew = spec->cap_mixer; knew->name; knew++) {
1913 if (kname && strcmp(knew->name, kname) == 0)
1915 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1916 for (i = 0; kctl && i < kctl->count; i++) {
1917 err = snd_hda_add_nid(codec, kctl, i,
1925 /* other nid->control mapping */
1926 for (i = 0; i < spec->num_mixers; i++) {
1927 for (knew = spec->mixers[i]; knew->name; knew++) {
1928 if (knew->iface != NID_MAPPING)
1930 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1933 u = knew->subdevice;
1934 for (j = 0; j < 4; j++, u >>= 8) {
1939 case SUBDEV_SPEAKER_:
1940 nid = spec->autocfg.speaker_pins[nid];
1943 nid = spec->autocfg.line_out_pins[nid];
1946 nid = spec->autocfg.hp_pins[nid];
1951 err = snd_hda_add_nid(codec, kctl, 0, nid);
1955 u = knew->private_value;
1956 for (j = 0; j < 4; j++, u >>= 8) {
1960 err = snd_hda_add_nid(codec, kctl, 0, nid);
1967 alc_free_kctls(codec); /* no longer needed */
1972 static int alc_build_jacks(struct hda_codec *codec)
1974 struct alc_spec *spec = codec->spec;
1976 if (spec->shared_mic_hp) {
1978 int nid = spec->autocfg.inputs[1].pin;
1979 err = snd_hda_jack_add_kctl(codec, nid, "Headphone Mic", 0);
1982 err = snd_hda_jack_detect_enable(codec, nid, 0);
1987 return snd_hda_jack_add_kctls(codec, &spec->autocfg);
1990 static int alc_build_controls(struct hda_codec *codec)
1992 int err = __alc_build_controls(codec);
1996 err = alc_build_jacks(codec);
1999 alc_apply_fixup(codec, ALC_FIXUP_ACT_BUILD);
2008 static void alc_init_special_input_src(struct hda_codec *codec);
2009 static void alc_auto_init_std(struct hda_codec *codec);
2011 static int alc_init(struct hda_codec *codec)
2013 struct alc_spec *spec = codec->spec;
2015 if (spec->init_hook)
2016 spec->init_hook(codec);
2019 alc_auto_init_amp(codec, spec->init_amp);
2021 snd_hda_gen_apply_verbs(codec);
2022 alc_init_special_input_src(codec);
2023 alc_auto_init_std(codec);
2025 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2027 hda_call_check_power_status(codec, 0x01);
2032 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2034 struct alc_spec *spec = codec->spec;
2035 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2040 * Analog playback callbacks
2042 static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
2043 struct hda_codec *codec,
2044 struct snd_pcm_substream *substream)
2046 struct alc_spec *spec = codec->spec;
2047 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2051 static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2052 struct hda_codec *codec,
2053 unsigned int stream_tag,
2054 unsigned int format,
2055 struct snd_pcm_substream *substream)
2057 struct alc_spec *spec = codec->spec;
2058 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2059 stream_tag, format, substream);
2062 static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2063 struct hda_codec *codec,
2064 struct snd_pcm_substream *substream)
2066 struct alc_spec *spec = codec->spec;
2067 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2073 static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2074 struct hda_codec *codec,
2075 struct snd_pcm_substream *substream)
2077 struct alc_spec *spec = codec->spec;
2078 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2081 static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2082 struct hda_codec *codec,
2083 unsigned int stream_tag,
2084 unsigned int format,
2085 struct snd_pcm_substream *substream)
2087 struct alc_spec *spec = codec->spec;
2088 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2089 stream_tag, format, substream);
2092 static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2093 struct hda_codec *codec,
2094 struct snd_pcm_substream *substream)
2096 struct alc_spec *spec = codec->spec;
2097 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2100 static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2101 struct hda_codec *codec,
2102 struct snd_pcm_substream *substream)
2104 struct alc_spec *spec = codec->spec;
2105 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2111 static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2112 struct hda_codec *codec,
2113 unsigned int stream_tag,
2114 unsigned int format,
2115 struct snd_pcm_substream *substream)
2117 struct alc_spec *spec = codec->spec;
2119 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
2120 stream_tag, 0, format);
2124 static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2125 struct hda_codec *codec,
2126 struct snd_pcm_substream *substream)
2128 struct alc_spec *spec = codec->spec;
2130 snd_hda_codec_cleanup_stream(codec,
2131 spec->adc_nids[substream->number + 1]);
2135 /* analog capture with dynamic dual-adc changes */
2136 static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2137 struct hda_codec *codec,
2138 unsigned int stream_tag,
2139 unsigned int format,
2140 struct snd_pcm_substream *substream)
2142 struct alc_spec *spec = codec->spec;
2143 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
2144 spec->cur_adc_stream_tag = stream_tag;
2145 spec->cur_adc_format = format;
2146 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2150 static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2151 struct hda_codec *codec,
2152 struct snd_pcm_substream *substream)
2154 struct alc_spec *spec = codec->spec;
2155 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2160 static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
2164 .nid = 0, /* fill later */
2166 .prepare = dyn_adc_capture_pcm_prepare,
2167 .cleanup = dyn_adc_capture_pcm_cleanup
2173 static const struct hda_pcm_stream alc_pcm_analog_playback = {
2177 /* NID is set in alc_build_pcms */
2179 .open = alc_playback_pcm_open,
2180 .prepare = alc_playback_pcm_prepare,
2181 .cleanup = alc_playback_pcm_cleanup
2185 static const struct hda_pcm_stream alc_pcm_analog_capture = {
2189 /* NID is set in alc_build_pcms */
2192 static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
2196 /* NID is set in alc_build_pcms */
2199 static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
2200 .substreams = 2, /* can be overridden */
2203 /* NID is set in alc_build_pcms */
2205 .prepare = alc_alt_capture_pcm_prepare,
2206 .cleanup = alc_alt_capture_pcm_cleanup
2210 static const struct hda_pcm_stream alc_pcm_digital_playback = {
2214 /* NID is set in alc_build_pcms */
2216 .open = alc_dig_playback_pcm_open,
2217 .close = alc_dig_playback_pcm_close,
2218 .prepare = alc_dig_playback_pcm_prepare,
2219 .cleanup = alc_dig_playback_pcm_cleanup
2223 static const struct hda_pcm_stream alc_pcm_digital_capture = {
2227 /* NID is set in alc_build_pcms */
2230 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
2231 static const struct hda_pcm_stream alc_pcm_null_stream = {
2237 static int alc_build_pcms(struct hda_codec *codec)
2239 struct alc_spec *spec = codec->spec;
2240 struct hda_pcm *info = spec->pcm_rec;
2241 const struct hda_pcm_stream *p;
2242 bool have_multi_adcs;
2245 codec->num_pcms = 1;
2246 codec->pcm_info = info;
2248 if (spec->no_analog)
2251 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2252 "%s Analog", codec->chip_name);
2253 info->name = spec->stream_name_analog;
2255 if (spec->multiout.num_dacs > 0) {
2256 p = spec->stream_analog_playback;
2258 p = &alc_pcm_analog_playback;
2259 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2260 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2261 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
2262 spec->multiout.max_channels;
2263 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
2264 spec->autocfg.line_outs == 2)
2265 info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap =
2268 if (spec->adc_nids) {
2269 p = spec->stream_analog_capture;
2271 if (spec->dyn_adc_switch)
2272 p = &dyn_adc_pcm_analog_capture;
2274 p = &alc_pcm_analog_capture;
2276 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2277 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2280 if (spec->channel_mode) {
2281 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2282 for (i = 0; i < spec->num_channel_mode; i++) {
2283 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2284 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2290 /* SPDIF for stream index #1 */
2291 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2292 snprintf(spec->stream_name_digital,
2293 sizeof(spec->stream_name_digital),
2294 "%s Digital", codec->chip_name);
2295 codec->num_pcms = 2;
2296 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
2297 info = spec->pcm_rec + 1;
2298 info->name = spec->stream_name_digital;
2299 if (spec->dig_out_type)
2300 info->pcm_type = spec->dig_out_type;
2302 info->pcm_type = HDA_PCM_TYPE_SPDIF;
2303 if (spec->multiout.dig_out_nid) {
2304 p = spec->stream_digital_playback;
2306 p = &alc_pcm_digital_playback;
2307 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2308 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2310 if (spec->dig_in_nid) {
2311 p = spec->stream_digital_capture;
2313 p = &alc_pcm_digital_capture;
2314 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2315 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2317 /* FIXME: do we need this for all Realtek codec models? */
2318 codec->spdif_status_reset = 1;
2321 if (spec->no_analog)
2324 /* If the use of more than one ADC is requested for the current
2325 * model, configure a second analog capture-only PCM.
2327 have_multi_adcs = (spec->num_adc_nids > 1) &&
2328 !spec->dyn_adc_switch && !spec->auto_mic &&
2329 (!spec->input_mux || spec->input_mux->num_items > 1);
2330 /* Additional Analaog capture for index #2 */
2331 if (spec->alt_dac_nid || have_multi_adcs) {
2332 codec->num_pcms = 3;
2333 info = spec->pcm_rec + 2;
2334 info->name = spec->stream_name_analog;
2335 if (spec->alt_dac_nid) {
2336 p = spec->stream_analog_alt_playback;
2338 p = &alc_pcm_analog_alt_playback;
2339 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2340 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2343 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2344 alc_pcm_null_stream;
2345 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2347 if (have_multi_adcs) {
2348 p = spec->stream_analog_alt_capture;
2350 p = &alc_pcm_analog_alt_capture;
2351 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2352 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2354 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2355 spec->num_adc_nids - 1;
2357 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2358 alc_pcm_null_stream;
2359 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
2366 static inline void alc_shutup(struct hda_codec *codec)
2368 struct alc_spec *spec = codec->spec;
2370 if (spec && spec->shutup)
2371 spec->shutup(codec);
2372 snd_hda_shutup_pins(codec);
2375 static void alc_free_kctls(struct hda_codec *codec)
2377 struct alc_spec *spec = codec->spec;
2379 if (spec->kctls.list) {
2380 struct snd_kcontrol_new *kctl = spec->kctls.list;
2382 for (i = 0; i < spec->kctls.used; i++)
2383 kfree(kctl[i].name);
2385 snd_array_free(&spec->kctls);
2388 static void alc_free_bind_ctls(struct hda_codec *codec)
2390 struct alc_spec *spec = codec->spec;
2391 if (spec->bind_ctls.list) {
2392 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2394 for (i = 0; i < spec->bind_ctls.used; i++)
2397 snd_array_free(&spec->bind_ctls);
2400 static void alc_free(struct hda_codec *codec)
2402 struct alc_spec *spec = codec->spec;
2407 alc_free_kctls(codec);
2408 alc_free_bind_ctls(codec);
2409 snd_array_free(&spec->paths);
2410 snd_hda_gen_free(&spec->gen);
2412 snd_hda_detach_beep_device(codec);
2416 static void alc_power_eapd(struct hda_codec *codec)
2418 alc_auto_setup_eapd(codec, false);
2421 static int alc_suspend(struct hda_codec *codec)
2423 struct alc_spec *spec = codec->spec;
2425 if (spec && spec->power_hook)
2426 spec->power_hook(codec);
2432 static int alc_resume(struct hda_codec *codec)
2434 msleep(150); /* to avoid pop noise */
2435 codec->patch_ops.init(codec);
2436 snd_hda_codec_resume_amp(codec);
2437 snd_hda_codec_resume_cache(codec);
2438 alc_inv_dmic_sync(codec, true);
2439 hda_call_check_power_status(codec, 0x01);
2446 static const struct hda_codec_ops alc_patch_ops = {
2447 .build_controls = alc_build_controls,
2448 .build_pcms = alc_build_pcms,
2451 .unsol_event = snd_hda_jack_unsol_event,
2453 .resume = alc_resume,
2456 .suspend = alc_suspend,
2457 .check_power_status = alc_check_power_status,
2459 .reboot_notify = alc_shutup,
2463 /* replace the codec chip_name with the given string */
2464 static int alc_codec_rename(struct hda_codec *codec, const char *name)
2466 kfree(codec->chip_name);
2467 codec->chip_name = kstrdup(name, GFP_KERNEL);
2468 if (!codec->chip_name) {
2476 * Rename codecs appropriately from COEF value
2478 struct alc_codec_rename_table {
2479 unsigned int vendor_id;
2480 unsigned short coef_mask;
2481 unsigned short coef_bits;
2485 static struct alc_codec_rename_table rename_tbl[] = {
2486 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2487 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2488 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2489 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2490 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2491 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2492 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
2493 { 0x10ec0269, 0x00f0, 0x0030, "ALC269VD" },
2494 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2495 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2496 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2497 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2498 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2499 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2500 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2501 { } /* terminator */
2504 static int alc_codec_rename_from_preset(struct hda_codec *codec)
2506 const struct alc_codec_rename_table *p;
2508 for (p = rename_tbl; p->vendor_id; p++) {
2509 if (p->vendor_id != codec->vendor_id)
2511 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
2512 return alc_codec_rename(codec, p->name);
2518 * Automatic parse of I/O pins from the BIOS configuration
2523 ALC_CTL_WIDGET_MUTE,
2528 static const struct snd_kcontrol_new alc_control_templates[] = {
2529 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2530 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2531 HDA_BIND_MUTE(NULL, 0, 0, 0),
2532 HDA_BIND_VOL(NULL, 0),
2533 HDA_BIND_SW(NULL, 0),
2536 /* add dynamic controls */
2537 static int add_control(struct alc_spec *spec, int type, const char *name,
2538 int cidx, unsigned long val)
2540 struct snd_kcontrol_new *knew;
2542 knew = alc_kcontrol_new(spec, name, &alc_control_templates[type]);
2546 if (get_amp_nid_(val))
2547 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
2548 knew->private_value = val;
2552 static int add_control_with_pfx(struct alc_spec *spec, int type,
2553 const char *pfx, const char *dir,
2554 const char *sfx, int cidx, unsigned long val)
2557 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
2558 return add_control(spec, type, name, cidx, val);
2561 #define add_pb_vol_ctrl(spec, type, pfx, val) \
2562 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2563 #define add_pb_sw_ctrl(spec, type, pfx, val) \
2564 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2565 #define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2566 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2567 #define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2568 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
2570 static const char * const channel_name[4] = {
2571 "Front", "Surround", "CLFE", "Side"
2574 static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2575 bool can_be_master, int *index)
2577 struct auto_pin_cfg *cfg = &spec->autocfg;
2580 if (cfg->line_outs == 1 && !spec->multi_ios &&
2581 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
2584 switch (cfg->line_out_type) {
2585 case AUTO_PIN_SPEAKER_OUT:
2586 if (cfg->line_outs == 1)
2588 if (cfg->line_outs == 2)
2589 return ch ? "Bass Speaker" : "Speaker";
2591 case AUTO_PIN_HP_OUT:
2592 /* for multi-io case, only the primary out */
2593 if (ch && spec->multi_ios)
2598 if (cfg->line_outs == 1 && !spec->multi_ios)
2602 if (ch >= ARRAY_SIZE(channel_name)) {
2607 return channel_name[ch];
2610 static bool parse_nid_path(struct hda_codec *codec, hda_nid_t from_nid,
2611 hda_nid_t to_nid, int with_aa_mix,
2612 struct nid_path *path);
2615 /* add the powersave loopback-list entry */
2616 static void add_loopback_list(struct alc_spec *spec, hda_nid_t mix, int idx)
2618 struct hda_amp_list *list;
2620 if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
2622 list = spec->loopback_list + spec->num_loopbacks;
2624 list->dir = HDA_INPUT;
2626 spec->num_loopbacks++;
2627 spec->loopback.amplist = spec->loopback_list;
2630 #define add_loopback_list(spec, mix, idx) /* NOP */
2633 /* create input playback/capture controls for the given pin */
2634 static int new_analog_input(struct hda_codec *codec, hda_nid_t pin,
2635 const char *ctlname, int ctlidx,
2638 struct alc_spec *spec = codec->spec;
2639 struct nid_path *path;
2642 if (!nid_has_volume(codec, mix_nid, HDA_INPUT) &&
2643 !nid_has_mute(codec, mix_nid, HDA_INPUT))
2644 return 0; /* no need for analog loopback */
2646 path = snd_array_new(&spec->paths);
2649 memset(path, 0, sizeof(*path));
2650 if (!parse_nid_path(codec, pin, mix_nid, 2, path))
2653 idx = path->idx[path->depth - 1];
2654 if (nid_has_volume(codec, mix_nid, HDA_INPUT)) {
2655 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
2656 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2661 if (nid_has_mute(codec, mix_nid, HDA_INPUT)) {
2662 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
2663 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2668 add_loopback_list(spec, mix_nid, idx);
2672 static int new_capture_source(struct hda_codec *codec, int adc_idx,
2673 hda_nid_t pin, int idx, const char *label)
2675 struct alc_spec *spec = codec->spec;
2676 struct hda_input_mux *imux = &spec->private_imux[0];
2677 struct nid_path *path;
2679 path = snd_array_new(&spec->paths);
2682 memset(path, 0, sizeof(*path));
2683 if (!parse_nid_path(codec, pin, spec->adc_nids[adc_idx], 2, path)) {
2684 snd_printd(KERN_ERR "invalid input path 0x%x -> 0x%x\n",
2685 pin, spec->adc_nids[adc_idx]);
2689 spec->imux_pins[imux->num_items] = pin;
2690 snd_hda_add_imux_item(imux, label, idx, NULL);
2694 static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
2696 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2697 return (pincap & AC_PINCAP_IN) != 0;
2700 /* check whether the given two widgets can be connected */
2701 static bool is_reachable_path(struct hda_codec *codec,
2702 hda_nid_t from_nid, hda_nid_t to_nid)
2704 if (!from_nid || !to_nid)
2706 return snd_hda_get_conn_index(codec, to_nid, from_nid, true) >= 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 if (is_reachable_path(codec, pin, mixer)) {
2791 err = new_analog_input(codec, pin,
2792 label, type_idx, mixer);
2798 for (c = 0; c < num_adcs; c++) {
2799 hda_nid_t cap = get_capsrc(spec, c);
2800 idx = get_connection_index(codec, cap, pin);
2802 err = new_capture_source(codec, c, pin, idx, label);
2810 spec->num_mux_defs = 1;
2811 spec->input_mux = imux;
2816 /* create a shared input with the headphone out */
2817 static int alc_auto_create_shared_input(struct hda_codec *codec)
2819 struct alc_spec *spec = codec->spec;
2820 struct auto_pin_cfg *cfg = &spec->autocfg;
2821 unsigned int defcfg;
2824 /* only one internal input pin? */
2825 if (cfg->num_inputs != 1)
2827 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2828 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2831 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
2832 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
2833 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
2834 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
2836 return 0; /* both not available */
2838 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2839 return 0; /* no input */
2841 cfg->inputs[1].pin = nid;
2842 cfg->inputs[1].type = AUTO_PIN_MIC;
2843 cfg->num_inputs = 2;
2844 spec->shared_mic_hp = 1;
2845 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
2849 static int get_pin_type(int line_out_type)
2851 if (line_out_type == AUTO_PIN_HP_OUT)
2857 static void alc_auto_init_analog_input(struct hda_codec *codec)
2859 struct alc_spec *spec = codec->spec;
2860 struct auto_pin_cfg *cfg = &spec->autocfg;
2863 for (i = 0; i < cfg->num_inputs; i++) {
2864 hda_nid_t nid = cfg->inputs[i].pin;
2865 if (alc_is_input_pin(codec, nid)) {
2866 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
2867 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
2868 snd_hda_codec_write(codec, nid, 0,
2869 AC_VERB_SET_AMP_GAIN_MUTE,
2874 /* mute all loopback inputs */
2875 if (spec->mixer_nid) {
2876 int nums = snd_hda_get_num_conns(codec, spec->mixer_nid);
2877 for (i = 0; i < nums; i++)
2878 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2879 AC_VERB_SET_AMP_GAIN_MUTE,
2884 static bool alc_is_dac_already_used(struct hda_codec *codec, hda_nid_t nid)
2886 struct alc_spec *spec = codec->spec;
2889 for (i = 0; i < spec->paths.used; i++) {
2890 struct nid_path *path = snd_array_elem(&spec->paths, i);
2891 if (path->path[0] == nid)
2897 /* look for an empty DAC slot */
2898 static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
2900 struct alc_spec *spec = codec->spec;
2903 for (i = 0; i < spec->num_all_dacs; i++) {
2904 hda_nid_t nid = spec->all_dacs[i];
2905 if (!nid || alc_is_dac_already_used(codec, nid))
2907 if (is_reachable_path(codec, nid, pin))
2913 /* called recursively */
2914 static bool __parse_nid_path(struct hda_codec *codec,
2915 hda_nid_t from_nid, hda_nid_t to_nid,
2916 int with_aa_mix, struct nid_path *path, int depth)
2918 struct alc_spec *spec = codec->spec;
2922 if (to_nid == spec->mixer_nid) {
2925 with_aa_mix = 2; /* mark aa-mix is included */
2928 nums = snd_hda_get_connections(codec, to_nid, conn, ARRAY_SIZE(conn));
2929 for (i = 0; i < nums; i++) {
2930 if (conn[i] != from_nid) {
2931 /* special case: when from_nid is 0,
2932 * try to find an empty DAC
2935 get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT ||
2936 alc_is_dac_already_used(codec, conn[i]))
2939 /* aa-mix is requested but not included? */
2940 if (!(spec->mixer_nid && with_aa_mix == 1))
2943 if (depth >= MAX_NID_PATH_DEPTH)
2945 for (i = 0; i < nums; i++) {
2947 type = get_wcaps_type(get_wcaps(codec, conn[i]));
2948 if (type == AC_WID_AUD_OUT || type == AC_WID_AUD_IN ||
2951 if (__parse_nid_path(codec, from_nid, conn[i],
2952 with_aa_mix, path, depth + 1))
2958 path->path[path->depth] = conn[i];
2959 path->idx[path->depth + 1] = i;
2960 if (nums > 1 && get_wcaps_type(get_wcaps(codec, to_nid)) != AC_WID_AUD_MIX)
2961 path->multi[path->depth + 1] = 1;
2966 /* parse the widget path from the given nid to the target nid;
2967 * when @from_nid is 0, try to find an empty DAC;
2968 * when @with_aa_mix is 0, paths with spec->mixer_nid are excluded.
2969 * when @with_aa_mix is 1, paths without spec->mixer_nid are excluded.
2970 * when @with_aa_mix is 2, no special handling about spec->mixer_nid.
2972 static bool parse_nid_path(struct hda_codec *codec, hda_nid_t from_nid,
2973 hda_nid_t to_nid, int with_aa_mix,
2974 struct nid_path *path)
2976 if (__parse_nid_path(codec, from_nid, to_nid, with_aa_mix, path, 1)) {
2977 path->path[path->depth] = to_nid;
2980 snd_printdd("path: depth=%d, %02x/%02x/%02x/%02x/%02x\n",
2981 path->depth, path->path[0], path->path[1],
2982 path->path[2], path->path[3], path->path[4]);
2989 static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
2991 struct alc_spec *spec = codec->spec;
2993 hda_nid_t nid_found = 0;
2995 for (i = 0; i < spec->num_all_dacs; i++) {
2996 hda_nid_t nid = spec->all_dacs[i];
2997 if (!nid || alc_is_dac_already_used(codec, nid))
2999 if (is_reachable_path(codec, nid, pin)) {
3008 static bool is_ctl_used(struct hda_codec *codec, unsigned int val, int type)
3010 struct alc_spec *spec = codec->spec;
3013 for (i = 0; i < spec->paths.used; i++) {
3014 struct nid_path *path = snd_array_elem(&spec->paths, i);
3015 if (path->ctls[type] == val)
3021 /* badness definition */
3023 /* No primary DAC is found for the main output */
3024 BAD_NO_PRIMARY_DAC = 0x10000,
3025 /* No DAC is found for the extra output */
3026 BAD_NO_DAC = 0x4000,
3027 /* No possible multi-ios */
3028 BAD_MULTI_IO = 0x103,
3029 /* No individual DAC for extra output */
3030 BAD_NO_EXTRA_DAC = 0x102,
3031 /* No individual DAC for extra surrounds */
3032 BAD_NO_EXTRA_SURR_DAC = 0x101,
3033 /* Primary DAC shared with main surrounds */
3034 BAD_SHARED_SURROUND = 0x100,
3035 /* Primary DAC shared with main CLFE */
3036 BAD_SHARED_CLFE = 0x10,
3037 /* Primary DAC shared with extra surrounds */
3038 BAD_SHARED_EXTRA_SURROUND = 0x10,
3039 /* Volume widget is shared */
3040 BAD_SHARED_VOL = 0x10,
3043 static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3044 struct nid_path *path);
3045 static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3046 struct nid_path *path);
3048 static bool add_new_out_path(struct hda_codec *codec, hda_nid_t pin,
3051 struct alc_spec *spec = codec->spec;
3052 struct nid_path *path;
3054 path = snd_array_new(&spec->paths);
3057 memset(path, 0, sizeof(*path));
3058 if (parse_nid_path(codec, dac, pin, 0, path))
3065 /* get the path pointing from the given dac to pin;
3066 * passing 0 to either @pin or @dac behaves as a wildcard
3068 static struct nid_path *get_out_path(struct hda_codec *codec, hda_nid_t pin,
3071 struct alc_spec *spec = codec->spec;
3074 for (i = 0; i < spec->paths.used; i++) {
3075 struct nid_path *path = snd_array_elem(&spec->paths, i);
3076 if (path->depth <= 0)
3078 if ((!dac || path->path[0] == dac) &&
3079 (!pin || path->path[path->depth - 1] == pin))
3085 /* look for widgets in the path between the given NIDs appropriate for
3086 * volume and mute controls, and assign the values to ctls[].
3088 * When no appropriate widget is found in the path, the badness value
3089 * is incremented depending on the situation. The function returns the
3090 * total badness for both volume and mute controls.
3092 static int assign_out_path_ctls(struct hda_codec *codec, hda_nid_t pin,
3095 struct nid_path *path = get_out_path(codec, pin, dac);
3101 return BAD_SHARED_VOL * 2;
3102 nid = alc_look_for_out_vol_nid(codec, path);
3104 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3105 if (is_ctl_used(codec, val, NID_PATH_VOL_CTL))
3106 badness += BAD_SHARED_VOL;
3108 path->ctls[NID_PATH_VOL_CTL] = val;
3110 badness += BAD_SHARED_VOL;
3111 nid = alc_look_for_out_mute_nid(codec, path);
3113 unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid));
3114 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT ||
3115 nid_has_mute(codec, nid, HDA_OUTPUT))
3116 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3118 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
3119 if (is_ctl_used(codec, val, NID_PATH_MUTE_CTL))
3120 badness += BAD_SHARED_VOL;
3122 path->ctls[NID_PATH_MUTE_CTL] = val;
3124 badness += BAD_SHARED_VOL;
3128 struct badness_table {
3129 int no_primary_dac; /* no primary DAC */
3130 int no_dac; /* no secondary DACs */
3131 int shared_primary; /* primary DAC is shared with main output */
3132 int shared_surr; /* secondary DAC shared with main or primary */
3133 int shared_clfe; /* third DAC shared with main or primary */
3134 int shared_surr_main; /* secondary DAC sahred with main/DAC0 */
3137 static struct badness_table main_out_badness = {
3138 .no_primary_dac = BAD_NO_PRIMARY_DAC,
3139 .no_dac = BAD_NO_DAC,
3140 .shared_primary = BAD_NO_PRIMARY_DAC,
3141 .shared_surr = BAD_SHARED_SURROUND,
3142 .shared_clfe = BAD_SHARED_CLFE,
3143 .shared_surr_main = BAD_SHARED_SURROUND,
3146 static struct badness_table extra_out_badness = {
3147 .no_primary_dac = BAD_NO_DAC,
3148 .no_dac = BAD_NO_DAC,
3149 .shared_primary = BAD_NO_EXTRA_DAC,
3150 .shared_surr = BAD_SHARED_EXTRA_SURROUND,
3151 .shared_clfe = BAD_SHARED_EXTRA_SURROUND,
3152 .shared_surr_main = BAD_NO_EXTRA_SURR_DAC,
3155 /* try to assign DACs to pins and return the resultant badness */
3156 static int alc_auto_fill_dacs(struct hda_codec *codec, int num_outs,
3157 const hda_nid_t *pins, hda_nid_t *dacs,
3158 const struct badness_table *bad)
3160 struct alc_spec *spec = codec->spec;
3161 struct auto_pin_cfg *cfg = &spec->autocfg;
3169 for (i = 0; i < num_outs; i++) {
3170 hda_nid_t pin = pins[i];
3172 dacs[i] = alc_auto_look_for_dac(codec, pin);
3173 if (!dacs[i] && !i) {
3174 for (j = 1; j < num_outs; j++) {
3175 if (is_reachable_path(codec, dacs[j], pin)) {
3184 if (is_reachable_path(codec, dacs[0], pin))
3186 else if (cfg->line_outs > i &&
3187 is_reachable_path(codec, spec->private_dac_nids[i], pin))
3188 dac = spec->private_dac_nids[i];
3191 badness += bad->shared_primary;
3193 badness += bad->shared_surr;
3195 badness += bad->shared_clfe;
3196 } else if (is_reachable_path(codec, spec->private_dac_nids[0], pin)) {
3197 dac = spec->private_dac_nids[0];
3198 badness += bad->shared_surr_main;
3200 badness += bad->no_primary_dac;
3202 badness += bad->no_dac;
3204 if (!add_new_out_path(codec, pin, dac))
3207 badness += assign_out_path_ctls(codec, pin, dac);
3213 static int alc_auto_fill_multi_ios(struct hda_codec *codec,
3214 hda_nid_t reference_pin,
3215 bool hardwired, int offset);
3217 static bool alc_map_singles(struct hda_codec *codec, int outs,
3218 const hda_nid_t *pins, hda_nid_t *dacs)
3222 for (i = 0; i < outs; i++) {
3226 dac = get_dac_if_single(codec, pins[i]);
3229 if (add_new_out_path(codec, pins[i], dac)) {
3237 /* fill in the dac_nids table from the parsed pin configuration */
3238 static int fill_and_eval_dacs(struct hda_codec *codec,
3239 bool fill_hardwired,
3240 bool fill_mio_first)
3242 struct alc_spec *spec = codec->spec;
3243 struct auto_pin_cfg *cfg = &spec->autocfg;
3244 int i, err, badness;
3246 /* set num_dacs once to full for alc_auto_look_for_dac() */
3247 spec->multiout.num_dacs = cfg->line_outs;
3248 spec->multiout.dac_nids = spec->private_dac_nids;
3249 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
3250 memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid));
3251 memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid));
3252 spec->multi_ios = 0;
3253 snd_array_free(&spec->paths);
3256 /* fill hard-wired DACs first */
3257 if (fill_hardwired) {
3260 mapped = alc_map_singles(codec, cfg->line_outs,
3262 spec->private_dac_nids);
3263 mapped |= alc_map_singles(codec, cfg->hp_outs,
3265 spec->multiout.hp_out_nid);
3266 mapped |= alc_map_singles(codec, cfg->speaker_outs,
3268 spec->multiout.extra_out_nid);
3269 if (fill_mio_first && cfg->line_outs == 1 &&
3270 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3271 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], true, 0);
3278 badness += alc_auto_fill_dacs(codec, cfg->line_outs, cfg->line_out_pins,
3279 spec->private_dac_nids,
3282 /* re-count num_dacs and squash invalid entries */
3283 spec->multiout.num_dacs = 0;
3284 for (i = 0; i < cfg->line_outs; i++) {
3285 if (spec->private_dac_nids[i])
3286 spec->multiout.num_dacs++;
3288 memmove(spec->private_dac_nids + i,
3289 spec->private_dac_nids + i + 1,
3290 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
3291 spec->private_dac_nids[cfg->line_outs - 1] = 0;
3295 if (fill_mio_first &&
3296 cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3297 /* try to fill multi-io first */
3298 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
3301 /* we don't count badness at this stage yet */
3304 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
3305 err = alc_auto_fill_dacs(codec, cfg->hp_outs, cfg->hp_pins,
3306 spec->multiout.hp_out_nid,
3307 &extra_out_badness);
3312 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3313 err = alc_auto_fill_dacs(codec, cfg->speaker_outs,
3315 spec->multiout.extra_out_nid,
3316 &extra_out_badness);
3321 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3322 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
3327 if (cfg->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3328 /* try multi-ios with HP + inputs */
3330 if (cfg->line_outs >= 3)
3332 err = alc_auto_fill_multi_ios(codec, cfg->hp_pins[0], false,
3339 if (spec->multi_ios == 2) {
3340 for (i = 0; i < 2; i++)
3341 spec->private_dac_nids[spec->multiout.num_dacs++] =
3342 spec->multi_io[i].dac;
3343 spec->ext_channel_count = 2;
3344 } else if (spec->multi_ios) {
3345 spec->multi_ios = 0;
3346 badness += BAD_MULTI_IO;
3352 #define DEBUG_BADNESS
3354 #ifdef DEBUG_BADNESS
3355 #define debug_badness snd_printdd
3357 #define debug_badness(...)
3360 static void debug_show_configs(struct alc_spec *spec, struct auto_pin_cfg *cfg)
3362 debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3363 cfg->line_out_pins[0], cfg->line_out_pins[1],
3364 cfg->line_out_pins[2], cfg->line_out_pins[2],
3365 spec->multiout.dac_nids[0],
3366 spec->multiout.dac_nids[1],
3367 spec->multiout.dac_nids[2],
3368 spec->multiout.dac_nids[3]);
3369 if (spec->multi_ios > 0)
3370 debug_badness("multi_ios(%d) = %x/%x : %x/%x\n",
3372 spec->multi_io[0].pin, spec->multi_io[1].pin,
3373 spec->multi_io[0].dac, spec->multi_io[1].dac);
3374 debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3375 cfg->hp_pins[0], cfg->hp_pins[1],
3376 cfg->hp_pins[2], cfg->hp_pins[2],
3377 spec->multiout.hp_out_nid[0],
3378 spec->multiout.hp_out_nid[1],
3379 spec->multiout.hp_out_nid[2],
3380 spec->multiout.hp_out_nid[3]);
3381 debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3382 cfg->speaker_pins[0], cfg->speaker_pins[1],
3383 cfg->speaker_pins[2], cfg->speaker_pins[3],
3384 spec->multiout.extra_out_nid[0],
3385 spec->multiout.extra_out_nid[1],
3386 spec->multiout.extra_out_nid[2],
3387 spec->multiout.extra_out_nid[3]);
3390 /* find all available DACs of the codec */
3391 static void alc_fill_all_nids(struct hda_codec *codec)
3393 struct alc_spec *spec = codec->spec;
3395 hda_nid_t nid = codec->start_nid;
3397 spec->num_all_dacs = 0;
3398 memset(spec->all_dacs, 0, sizeof(spec->all_dacs));
3399 for (i = 0; i < codec->num_nodes; i++, nid++) {
3400 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_OUT)
3402 if (spec->num_all_dacs >= ARRAY_SIZE(spec->all_dacs)) {
3403 snd_printk(KERN_ERR "hda: Too many DACs!\n");
3406 spec->all_dacs[spec->num_all_dacs++] = nid;
3410 static int alc_auto_fill_dac_nids(struct hda_codec *codec)
3412 struct alc_spec *spec = codec->spec;
3413 struct auto_pin_cfg *cfg = &spec->autocfg;
3414 struct auto_pin_cfg *best_cfg;
3415 int best_badness = INT_MAX;
3417 bool fill_hardwired = true, fill_mio_first = true;
3418 bool best_wired = true, best_mio = true;
3419 bool hp_spk_swapped = false;
3421 alc_fill_all_nids(codec);
3423 best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL);
3429 badness = fill_and_eval_dacs(codec, fill_hardwired,
3435 debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n",
3436 cfg->line_out_type, fill_hardwired, fill_mio_first,
3438 debug_show_configs(spec, cfg);
3439 if (badness < best_badness) {
3440 best_badness = badness;
3442 best_wired = fill_hardwired;
3443 best_mio = fill_mio_first;
3447 fill_mio_first = !fill_mio_first;
3448 if (!fill_mio_first)
3450 fill_hardwired = !fill_hardwired;
3451 if (!fill_hardwired)
3455 hp_spk_swapped = true;
3456 if (cfg->speaker_outs > 0 &&
3457 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3458 cfg->hp_outs = cfg->line_outs;
3459 memcpy(cfg->hp_pins, cfg->line_out_pins,
3460 sizeof(cfg->hp_pins));
3461 cfg->line_outs = cfg->speaker_outs;
3462 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3463 sizeof(cfg->speaker_pins));
3464 cfg->speaker_outs = 0;
3465 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3466 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
3467 fill_hardwired = true;
3470 if (cfg->hp_outs > 0 &&
3471 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3472 cfg->speaker_outs = cfg->line_outs;
3473 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3474 sizeof(cfg->speaker_pins));
3475 cfg->line_outs = cfg->hp_outs;
3476 memcpy(cfg->line_out_pins, cfg->hp_pins,
3477 sizeof(cfg->hp_pins));
3479 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3480 cfg->line_out_type = AUTO_PIN_HP_OUT;
3481 fill_hardwired = true;
3489 fill_and_eval_dacs(codec, best_wired, best_mio);
3491 debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n",
3492 cfg->line_out_type, best_wired, best_mio);
3493 debug_show_configs(spec, cfg);
3495 if (cfg->line_out_pins[0]) {
3496 struct nid_path *path = get_out_path(codec,
3497 cfg->line_out_pins[0],
3498 spec->multiout.dac_nids[0]);
3500 spec->vmaster_nid = alc_look_for_out_vol_nid(codec, path);
3507 /* replace the channels in the composed amp value with the given number */
3508 static unsigned int amp_val_replace_channels(unsigned int val, unsigned int chs)
3510 val &= ~(0x3U << 16);
3515 static int alc_auto_add_vol_ctl(struct hda_codec *codec,
3516 const char *pfx, int cidx,
3518 struct nid_path *path)
3523 val = path->ctls[NID_PATH_VOL_CTL];
3526 val = amp_val_replace_channels(val, chs);
3527 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx, val);
3530 /* return the channel bits suitable for the given path->ctls[] */
3531 static int get_default_ch_nums(struct hda_codec *codec, struct nid_path *path,
3534 int chs = 1; /* mono (left only) */
3536 hda_nid_t nid = get_amp_nid_(path->ctls[type]);
3537 if (nid && (get_wcaps(codec, nid) & AC_WCAP_STEREO))
3538 chs = 3; /* stereo */
3543 static int alc_auto_add_stereo_vol(struct hda_codec *codec,
3544 const char *pfx, int cidx,
3545 struct nid_path *path)
3547 int chs = get_default_ch_nums(codec, path, NID_PATH_VOL_CTL);
3548 return alc_auto_add_vol_ctl(codec, pfx, cidx, chs, path);
3551 /* create a mute-switch for the given mixer widget;
3552 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3554 static int alc_auto_add_sw_ctl(struct hda_codec *codec,
3555 const char *pfx, int cidx,
3557 struct nid_path *path)
3560 int type = ALC_CTL_WIDGET_MUTE;
3564 val = path->ctls[NID_PATH_MUTE_CTL];
3567 val = amp_val_replace_channels(val, chs);
3568 if (get_amp_direction_(val) == HDA_INPUT) {
3569 hda_nid_t nid = get_amp_nid_(val);
3570 int nums = snd_hda_get_num_conns(codec, nid);
3572 type = ALC_CTL_BIND_MUTE;
3576 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
3579 static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
3580 int cidx, struct nid_path *path)
3582 int chs = get_default_ch_nums(codec, path, NID_PATH_MUTE_CTL);
3583 return alc_auto_add_sw_ctl(codec, pfx, cidx, chs, path);
3586 static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3587 struct nid_path *path)
3591 for (i = path->depth - 1; i >= 0; i--) {
3592 if (nid_has_mute(codec, path->path[i], HDA_OUTPUT))
3593 return path->path[i];
3594 if (i != path->depth - 1 && i != 0 &&
3595 nid_has_mute(codec, path->path[i], HDA_INPUT))
3596 return path->path[i];
3601 static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3602 struct nid_path *path)
3606 for (i = path->depth - 1; i >= 0; i--) {
3607 if (nid_has_volume(codec, path->path[i], HDA_OUTPUT))
3608 return path->path[i];
3613 /* add playback controls from the parsed DAC table */
3614 static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
3615 const struct auto_pin_cfg *cfg)
3617 struct alc_spec *spec = codec->spec;
3618 int i, err, noutputs;
3620 noutputs = cfg->line_outs;
3621 if (spec->multi_ios > 0 && cfg->line_outs < 3)
3622 noutputs += spec->multi_ios;
3624 for (i = 0; i < noutputs; i++) {
3628 struct nid_path *path;
3630 dac = spec->multiout.dac_nids[i];
3633 if (i >= cfg->line_outs) {
3634 pin = spec->multi_io[i - 1].pin;
3636 name = channel_name[i];
3638 pin = cfg->line_out_pins[i];
3639 name = alc_get_line_out_pfx(spec, i, true, &index);
3642 path = get_out_path(codec, pin, dac);
3645 if (!name || !strcmp(name, "CLFE")) {
3647 err = alc_auto_add_vol_ctl(codec, "Center", 0, 1, path);
3650 err = alc_auto_add_vol_ctl(codec, "LFE", 0, 2, path);
3653 err = alc_auto_add_sw_ctl(codec, "Center", 0, 1, path);
3656 err = alc_auto_add_sw_ctl(codec, "LFE", 0, 2, path);
3660 err = alc_auto_add_stereo_vol(codec, name, index, path);
3663 err = alc_auto_add_stereo_sw(codec, name, index, path);
3671 static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
3672 hda_nid_t dac, const char *pfx,
3675 struct nid_path *path;
3678 path = get_out_path(codec, pin, dac);
3681 /* bind volume control will be created in the case of dac = 0 */
3683 err = alc_auto_add_stereo_vol(codec, pfx, cidx, path);
3687 err = alc_auto_add_stereo_sw(codec, pfx, cidx, path);
3693 static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3695 struct hda_ctl_ops *ops)
3697 struct alc_spec *spec = codec->spec;
3698 struct hda_bind_ctls **ctlp, *ctl;
3699 ctlp = snd_array_new(&spec->bind_ctls);
3702 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3709 /* add playback controls for speaker and HP outputs */
3710 static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3711 const hda_nid_t *pins,
3712 const hda_nid_t *dacs,
3715 struct alc_spec *spec = codec->spec;
3716 struct hda_bind_ctls *ctl;
3720 if (!num_pins || !pins[0])
3723 if (num_pins == 1) {
3724 hda_nid_t dac = *dacs;
3726 dac = spec->multiout.dac_nids[0];
3727 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
3730 for (i = 0; i < num_pins; i++) {
3732 if (dacs[num_pins - 1])
3733 dac = dacs[i]; /* with individual volumes */
3736 if (num_pins == 2 && i == 1 && !strcmp(pfx, "Speaker")) {
3737 err = alc_auto_create_extra_out(codec, pins[i], dac,
3739 } else if (num_pins >= 3) {
3740 snprintf(name, sizeof(name), "%s %s",
3741 pfx, channel_name[i]);
3742 err = alc_auto_create_extra_out(codec, pins[i], dac,
3745 err = alc_auto_create_extra_out(codec, pins[i], dac,
3751 if (dacs[num_pins - 1])
3754 /* Let's create a bind-controls for volumes */
3755 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3759 for (i = 0; i < num_pins; i++) {
3761 struct nid_path *path;
3762 if (!pins[i] || !dacs[i])
3764 path = get_out_path(codec, pins[i], dacs[i]);
3767 vol = alc_look_for_out_vol_nid(codec, path);
3770 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3773 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3774 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3781 static int alc_auto_create_hp_out(struct hda_codec *codec)
3783 struct alc_spec *spec = codec->spec;
3784 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3785 spec->autocfg.hp_pins,
3786 spec->multiout.hp_out_nid,
3790 static int alc_auto_create_speaker_out(struct hda_codec *codec)
3792 struct alc_spec *spec = codec->spec;
3793 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3794 spec->autocfg.speaker_pins,
3795 spec->multiout.extra_out_nid,
3799 /* check whether a control with the given (nid, dir, idx) was assigned */
3800 static bool is_ctl_associated(struct hda_codec *codec, hda_nid_t nid,
3803 struct alc_spec *spec = codec->spec;
3806 for (i = 0; i < spec->paths.used; i++) {
3807 struct nid_path *p = snd_array_elem(&spec->paths, i);
3810 for (type = 0; type < 2; type++) {
3811 unsigned int val = p->ctls[type];
3812 if (get_amp_nid_(val) == nid &&
3813 get_amp_direction_(val) == dir &&
3814 get_amp_index_(val) == idx)
3821 /* can have the amp-in capability? */
3822 static bool has_amp_in(struct hda_codec *codec, struct nid_path *path, int idx)
3824 hda_nid_t nid = path->path[idx];
3825 unsigned int caps = get_wcaps(codec, nid);
3826 unsigned int type = get_wcaps_type(caps);
3828 if (!(caps & AC_WCAP_IN_AMP))
3830 if (type == AC_WID_PIN && idx > 0) /* only for input pins */
3835 /* can have the amp-out capability? */
3836 static bool has_amp_out(struct hda_codec *codec, struct nid_path *path, int idx)
3838 hda_nid_t nid = path->path[idx];
3839 unsigned int caps = get_wcaps(codec, nid);
3840 unsigned int type = get_wcaps_type(caps);
3842 if (!(caps & AC_WCAP_OUT_AMP))
3844 if (type == AC_WID_PIN && !idx) /* only for output pins */
3849 /* check whether the given (nid,dir,idx) is active */
3850 static bool is_active_nid(struct hda_codec *codec, hda_nid_t nid,
3851 unsigned int idx, unsigned int dir)
3853 struct alc_spec *spec = codec->spec;
3856 for (n = 0; n < spec->paths.used; n++) {
3857 struct nid_path *path = snd_array_elem(&spec->paths, n);
3860 for (i = 0; i < path->depth; i++) {
3861 if (path->path[i] == nid) {
3862 if (dir == HDA_OUTPUT || path->idx[i] == idx)
3871 /* get the default amp value for the target state */
3872 static int get_amp_val_to_activate(struct hda_codec *codec, hda_nid_t nid,
3873 int dir, bool enable)
3876 unsigned int val = 0;
3878 caps = query_amp_caps(codec, nid, dir);
3879 if (caps & AC_AMPCAP_NUM_STEPS) {
3882 val = (caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT;
3884 if (caps & AC_AMPCAP_MUTE) {
3886 val |= HDA_AMP_MUTE;
3891 /* initialize the amp value (only at the first time) */
3892 static void init_amp(struct hda_codec *codec, hda_nid_t nid, int dir, int idx)
3894 int val = get_amp_val_to_activate(codec, nid, dir, false);
3895 snd_hda_codec_amp_init_stereo(codec, nid, dir, idx, 0xff, val);
3898 static void activate_amp(struct hda_codec *codec, hda_nid_t nid, int dir,
3899 int idx, bool enable)
3902 if (is_ctl_associated(codec, nid, dir, idx) ||
3903 is_active_nid(codec, nid, dir, idx))
3905 val = get_amp_val_to_activate(codec, nid, dir, enable);
3906 snd_hda_codec_amp_stereo(codec, nid, dir, idx, 0xff, val);
3909 static void activate_amp_out(struct hda_codec *codec, struct nid_path *path,
3912 hda_nid_t nid = path->path[i];
3913 init_amp(codec, nid, HDA_OUTPUT, 0);
3914 activate_amp(codec, nid, HDA_OUTPUT, 0, enable);
3917 static void activate_amp_in(struct hda_codec *codec, struct nid_path *path,
3920 struct alc_spec *spec = codec->spec;
3923 hda_nid_t nid = path->path[i];
3925 nums = snd_hda_get_connections(codec, nid, conn, ARRAY_SIZE(conn));
3926 for (n = 0; n < nums; n++)
3927 init_amp(codec, nid, HDA_INPUT, n);
3929 if (is_ctl_associated(codec, nid, HDA_INPUT, path->idx[i]))
3932 /* here is a little bit tricky in comparison with activate_amp_out();
3933 * when aa-mixer is available, we need to enable the path as well
3935 for (n = 0; n < nums; n++) {
3936 if (n != path->idx[i] && conn[n] != spec->mixer_nid)
3938 activate_amp(codec, nid, HDA_INPUT, n, enable);
3942 static void activate_path(struct hda_codec *codec, struct nid_path *path,
3947 if (path->active == enable)
3951 path->active = false;
3953 for (i = path->depth - 1; i >= 0; i--) {
3955 snd_hda_codec_write_cache(codec, path->path[i], 0,
3956 AC_VERB_SET_CONNECT_SEL,
3958 if (has_amp_in(codec, path, i))
3959 activate_amp_in(codec, path, i, enable);
3960 if (has_amp_out(codec, path, i))
3961 activate_amp_out(codec, path, i, enable);
3965 path->active = true;
3968 /* configure the path from the given dac to the pin as the proper output */
3969 static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
3970 hda_nid_t pin, int pin_type,
3973 struct nid_path *path;
3975 snd_hda_set_pin_ctl_cache(codec, pin, pin_type);
3976 path = get_out_path(codec, pin, dac);
3979 activate_path(codec, path, true);
3982 static void alc_auto_init_multi_out(struct hda_codec *codec)
3984 struct alc_spec *spec = codec->spec;
3985 int pin_type = get_pin_type(spec->autocfg.line_out_type);
3988 for (i = 0; i <= HDA_SIDE; i++) {
3989 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3991 alc_auto_set_output_and_unmute(codec, nid, pin_type,
3992 spec->multiout.dac_nids[i]);
3997 static void alc_auto_init_extra_out(struct hda_codec *codec)
3999 struct alc_spec *spec = codec->spec;
4003 for (i = 0; i < spec->autocfg.hp_outs; i++) {
4004 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
4006 pin = spec->autocfg.hp_pins[i];
4009 dac = spec->multiout.hp_out_nid[i];
4011 if (i > 0 && spec->multiout.hp_out_nid[0])
4012 dac = spec->multiout.hp_out_nid[0];
4014 dac = spec->multiout.dac_nids[0];
4016 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
4018 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
4019 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
4021 pin = spec->autocfg.speaker_pins[i];
4024 dac = spec->multiout.extra_out_nid[i];
4026 if (i > 0 && spec->multiout.extra_out_nid[0])
4027 dac = spec->multiout.extra_out_nid[0];
4029 dac = spec->multiout.dac_nids[0];
4031 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
4035 /* check whether the given pin can be a multi-io pin */
4036 static bool can_be_multiio_pin(struct hda_codec *codec,
4037 unsigned int location, hda_nid_t nid)
4039 unsigned int defcfg, caps;
4041 defcfg = snd_hda_codec_get_pincfg(codec, nid);
4042 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
4044 if (location && get_defcfg_location(defcfg) != location)
4046 caps = snd_hda_query_pin_caps(codec, nid);
4047 if (!(caps & AC_PINCAP_OUT))
4055 * When hardwired is set, try to fill ony hardwired pins, and returns
4056 * zero if any pins are filled, non-zero if nothing found.
4057 * When hardwired is off, try to fill possible input pins, and returns
4058 * the badness value.
4060 static int alc_auto_fill_multi_ios(struct hda_codec *codec,
4061 hda_nid_t reference_pin,
4062 bool hardwired, int offset)
4064 struct alc_spec *spec = codec->spec;
4065 struct auto_pin_cfg *cfg = &spec->autocfg;
4066 int type, i, j, dacs, num_pins, old_pins;
4067 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
4068 unsigned int location = get_defcfg_location(defcfg);
4071 old_pins = spec->multi_ios;
4076 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
4077 for (i = 0; i < cfg->num_inputs; i++) {
4078 if (cfg->inputs[i].type != type)
4080 if (can_be_multiio_pin(codec, location,
4081 cfg->inputs[i].pin))
4088 dacs = spec->multiout.num_dacs;
4089 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
4090 for (i = 0; i < cfg->num_inputs; i++) {
4091 hda_nid_t nid = cfg->inputs[i].pin;
4094 if (cfg->inputs[i].type != type)
4096 if (!can_be_multiio_pin(codec, location, nid))
4098 for (j = 0; j < spec->multi_ios; j++) {
4099 if (nid == spec->multi_io[j].pin)
4102 if (j < spec->multi_ios)
4105 if (offset && offset + spec->multi_ios < dacs) {
4106 dac = spec->private_dac_nids[offset + spec->multi_ios];
4107 if (!is_reachable_path(codec, dac, nid))
4111 dac = get_dac_if_single(codec, nid);
4113 dac = alc_auto_look_for_dac(codec, nid);
4118 if (!add_new_out_path(codec, nid, dac)) {
4122 spec->multi_io[spec->multi_ios].pin = nid;
4123 spec->multi_io[spec->multi_ios].dac = dac;
4125 if (spec->multi_ios >= 2)
4131 badness = BAD_MULTI_IO;
4132 if (old_pins == spec->multi_ios) {
4134 return 1; /* nothing found */
4136 return badness; /* no badness if nothing found */
4138 if (!hardwired && spec->multi_ios < 2) {
4139 /* cancel newly assigned paths */
4140 spec->paths.used -= spec->multi_ios - old_pins;
4141 spec->multi_ios = old_pins;
4145 /* assign volume and mute controls */
4146 for (i = old_pins; i < spec->multi_ios; i++)
4147 badness += assign_out_path_ctls(codec, spec->multi_io[i].pin,
4148 spec->multi_io[i].dac);
4153 static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
4154 struct snd_ctl_elem_info *uinfo)
4156 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4157 struct alc_spec *spec = codec->spec;
4159 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
4161 uinfo->value.enumerated.items = spec->multi_ios + 1;
4162 if (uinfo->value.enumerated.item > spec->multi_ios)
4163 uinfo->value.enumerated.item = spec->multi_ios;
4164 sprintf(uinfo->value.enumerated.name, "%dch",
4165 (uinfo->value.enumerated.item + 1) * 2);
4169 static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
4170 struct snd_ctl_elem_value *ucontrol)
4172 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4173 struct alc_spec *spec = codec->spec;
4174 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
4178 static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
4180 struct alc_spec *spec = codec->spec;
4181 hda_nid_t nid = spec->multi_io[idx].pin;
4182 struct nid_path *path;
4184 path = get_out_path(codec, nid, spec->multi_io[idx].dac);
4188 if (!spec->multi_io[idx].ctl_in)
4189 spec->multi_io[idx].ctl_in =
4190 snd_hda_codec_update_cache(codec, nid, 0,
4191 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4194 snd_hda_set_pin_ctl_cache(codec, nid, PIN_OUT);
4195 activate_path(codec, path, true);
4197 activate_path(codec, path, false);
4198 snd_hda_set_pin_ctl_cache(codec, nid,
4199 spec->multi_io[idx].ctl_in);
4204 static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
4205 struct snd_ctl_elem_value *ucontrol)
4207 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4208 struct alc_spec *spec = codec->spec;
4211 ch = ucontrol->value.enumerated.item[0];
4212 if (ch < 0 || ch > spec->multi_ios)
4214 if (ch == (spec->ext_channel_count - 1) / 2)
4216 spec->ext_channel_count = (ch + 1) * 2;
4217 for (i = 0; i < spec->multi_ios; i++)
4218 alc_set_multi_io(codec, i, i < ch);
4219 spec->multiout.max_channels = max(spec->ext_channel_count,
4220 spec->const_channel_count);
4221 if (spec->need_dac_fix)
4222 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
4226 static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
4227 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4228 .name = "Channel Mode",
4229 .info = alc_auto_ch_mode_info,
4230 .get = alc_auto_ch_mode_get,
4231 .put = alc_auto_ch_mode_put,
4234 static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
4236 struct alc_spec *spec = codec->spec;
4238 if (spec->multi_ios > 0) {
4239 if (!alc_kcontrol_new(spec, "Channel Mode",
4240 &alc_auto_channel_mode_enum))
4246 /* filter out invalid adc_nids (and capsrc_nids) that don't give all
4249 static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
4251 struct alc_spec *spec = codec->spec;
4252 const struct hda_input_mux *imux;
4253 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4254 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4257 imux = spec->input_mux;
4260 if (spec->dyn_adc_switch)
4265 for (n = 0; n < spec->num_adc_nids; n++) {
4266 hda_nid_t cap = spec->private_capsrc_nids[n];
4267 int num_conns = snd_hda_get_num_conns(codec, cap);
4268 for (i = 0; i < imux->num_items; i++) {
4269 hda_nid_t pin = spec->imux_pins[i];
4271 if (get_connection_index(codec, cap, pin) < 0)
4273 } else if (num_conns <= imux->items[i].index)
4276 if (i >= imux->num_items) {
4277 adc_nids[nums] = spec->private_adc_nids[n];
4278 capsrc_nids[nums++] = cap;
4282 /* check whether ADC-switch is possible */
4283 if (!alc_check_dyn_adc_switch(codec)) {
4284 if (spec->shared_mic_hp) {
4285 spec->shared_mic_hp = 0;
4286 spec->private_imux[0].num_items = 1;
4289 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
4290 " using fallback 0x%x\n",
4291 codec->chip_name, spec->private_adc_nids[0]);
4292 spec->num_adc_nids = 1;
4296 } else if (nums != spec->num_adc_nids) {
4297 memcpy(spec->private_adc_nids, adc_nids,
4298 nums * sizeof(hda_nid_t));
4299 memcpy(spec->private_capsrc_nids, capsrc_nids,
4300 nums * sizeof(hda_nid_t));
4301 spec->num_adc_nids = nums;
4305 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
4306 else if (spec->input_mux->num_items == 1 || spec->shared_mic_hp)
4307 spec->num_adc_nids = 1; /* reduce to a single ADC */
4311 * initialize ADC paths
4313 static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
4315 struct alc_spec *spec = codec->spec;
4318 nid = spec->adc_nids[adc_idx];
4320 if (nid_has_mute(codec, nid, HDA_INPUT)) {
4321 snd_hda_codec_write(codec, nid, 0,
4322 AC_VERB_SET_AMP_GAIN_MUTE,
4326 if (!spec->capsrc_nids)
4328 nid = spec->capsrc_nids[adc_idx];
4329 if (nid_has_mute(codec, nid, HDA_OUTPUT))
4330 snd_hda_codec_write(codec, nid, 0,
4331 AC_VERB_SET_AMP_GAIN_MUTE,
4335 static void alc_auto_init_input_src(struct hda_codec *codec)
4337 struct alc_spec *spec = codec->spec;
4340 for (c = 0; c < spec->num_adc_nids; c++)
4341 alc_auto_init_adc(codec, c);
4342 if (spec->dyn_adc_switch)
4345 nums = spec->num_adc_nids;
4346 for (c = 0; c < nums; c++)
4347 alc_mux_select(codec, c, spec->cur_mux[c], true);
4350 /* add mic boosts if needed */
4351 static int alc_auto_add_mic_boost(struct hda_codec *codec)
4353 struct alc_spec *spec = codec->spec;
4354 struct auto_pin_cfg *cfg = &spec->autocfg;
4358 const char *prev_label = NULL;
4360 for (i = 0; i < cfg->num_inputs; i++) {
4361 if (cfg->inputs[i].type > AUTO_PIN_MIC)
4363 nid = cfg->inputs[i].pin;
4364 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
4366 char boost_label[32];
4368 label = hda_get_autocfg_input_label(codec, cfg, i);
4369 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
4370 label = "Headphone Mic";
4371 if (prev_label && !strcmp(label, prev_label))
4377 snprintf(boost_label, sizeof(boost_label),
4378 "%s Boost Volume", label);
4379 err = add_control(spec, ALC_CTL_WIDGET_VOL,
4380 boost_label, type_idx,
4381 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
4389 /* select or unmute the given capsrc route */
4390 static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
4393 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
4394 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
4396 } else if (snd_hda_get_num_conns(codec, cap) > 1) {
4397 snd_hda_codec_write_cache(codec, cap, 0,
4398 AC_VERB_SET_CONNECT_SEL, idx);
4402 /* set the default connection to that pin */
4403 static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
4405 struct alc_spec *spec = codec->spec;
4410 for (i = 0; i < spec->num_adc_nids; i++) {
4411 hda_nid_t cap = get_capsrc(spec, i);
4414 idx = get_connection_index(codec, cap, pin);
4417 select_or_unmute_capsrc(codec, cap, idx);
4418 return i; /* return the found index */
4420 return -1; /* not found */
4423 /* initialize some special cases for input sources */
4424 static void alc_init_special_input_src(struct hda_codec *codec)
4426 struct alc_spec *spec = codec->spec;
4429 for (i = 0; i < spec->autocfg.num_inputs; i++)
4430 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
4433 /* assign appropriate capture mixers */
4434 static void set_capture_mixer(struct hda_codec *codec)
4436 struct alc_spec *spec = codec->spec;
4437 static const struct snd_kcontrol_new *caps[2][3] = {
4438 { alc_capture_mixer_nosrc1,
4439 alc_capture_mixer_nosrc2,
4440 alc_capture_mixer_nosrc3 },
4441 { alc_capture_mixer1,
4443 alc_capture_mixer3 },
4446 /* check whether either of ADC or MUX has a volume control */
4447 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
4448 if (!spec->capsrc_nids)
4449 return; /* no volume */
4450 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
4451 return; /* no volume in capsrc, too */
4452 spec->vol_in_capsrc = 1;
4455 if (spec->num_adc_nids > 0) {
4459 if (spec->input_mux && spec->input_mux->num_items > 1)
4461 if (spec->auto_mic) {
4464 } else if (spec->dyn_adc_switch)
4467 if (spec->num_adc_nids > 3)
4468 spec->num_adc_nids = 3;
4469 else if (!spec->num_adc_nids)
4471 num_adcs = spec->num_adc_nids;
4473 spec->cap_mixer = caps[mux][num_adcs - 1];
4478 * standard auto-parser initializations
4480 static void alc_auto_init_std(struct hda_codec *codec)
4482 alc_auto_init_multi_out(codec);
4483 alc_auto_init_extra_out(codec);
4484 alc_auto_init_analog_input(codec);
4485 alc_auto_init_input_src(codec);
4486 alc_auto_init_digital(codec);
4487 alc_inithook(codec);
4491 * Digital-beep handlers
4493 #ifdef CONFIG_SND_HDA_INPUT_BEEP
4494 #define set_beep_amp(spec, nid, idx, dir) \
4495 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4497 static const struct snd_pci_quirk beep_white_list[] = {
4498 SND_PCI_QUIRK(0x1043, 0x103c, "ASUS", 1),
4499 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
4500 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
4501 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
4502 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
4503 SND_PCI_QUIRK(0x1458, 0xa002, "GA-MA790X", 1),
4504 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
4508 static inline int has_cdefine_beep(struct hda_codec *codec)
4510 struct alc_spec *spec = codec->spec;
4511 const struct snd_pci_quirk *q;
4512 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
4515 return spec->cdefine.enable_pcbeep;
4518 #define set_beep_amp(spec, nid, idx, dir) /* NOP */
4519 #define has_cdefine_beep(codec) 0
4522 /* parse the BIOS configuration and set up the alc_spec */
4523 /* return 1 if successful, 0 if the proper config is not found,
4524 * or a negative error code
4526 static int alc_parse_auto_config(struct hda_codec *codec,
4527 const hda_nid_t *ignore_nids,
4528 const hda_nid_t *ssid_nids)
4530 struct alc_spec *spec = codec->spec;
4531 struct auto_pin_cfg *cfg = &spec->autocfg;
4534 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
4538 if (!cfg->line_outs) {
4539 if (cfg->dig_outs || cfg->dig_in_pin) {
4540 spec->multiout.max_channels = 2;
4541 spec->no_analog = 1;
4544 return 0; /* can't find valid BIOS pin config */
4547 if (!spec->no_primary_hp &&
4548 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
4549 cfg->line_outs <= cfg->hp_outs) {
4550 /* use HP as primary out */
4551 cfg->speaker_outs = cfg->line_outs;
4552 memcpy(cfg->speaker_pins, cfg->line_out_pins,
4553 sizeof(cfg->speaker_pins));
4554 cfg->line_outs = cfg->hp_outs;
4555 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
4557 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
4558 cfg->line_out_type = AUTO_PIN_HP_OUT;
4561 err = alc_auto_fill_dac_nids(codec);
4564 err = alc_auto_add_multi_channel_mode(codec);
4567 err = alc_auto_create_multi_out_ctls(codec, cfg);
4570 err = alc_auto_create_hp_out(codec);
4573 err = alc_auto_create_speaker_out(codec);
4576 err = alc_auto_create_shared_input(codec);
4579 err = alc_auto_create_input_ctls(codec);
4583 /* check the multiple speaker pins */
4584 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
4585 spec->const_channel_count = cfg->line_outs * 2;
4587 spec->const_channel_count = cfg->speaker_outs * 2;
4589 if (spec->multi_ios > 0)
4590 spec->multiout.max_channels = max(spec->ext_channel_count,
4591 spec->const_channel_count);
4593 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4596 alc_auto_parse_digital(codec);
4598 if (!spec->no_analog)
4599 alc_remove_invalid_adc_nids(codec);
4602 alc_ssid_check(codec, ssid_nids);
4604 if (!spec->no_analog) {
4605 err = alc_auto_check_switches(codec);
4608 err = alc_auto_add_mic_boost(codec);
4613 if (spec->kctls.list)
4614 add_mixer(spec, spec->kctls.list);
4616 if (!spec->no_analog && !spec->cap_mixer)
4617 set_capture_mixer(codec);
4622 /* common preparation job for alc_spec */
4623 static int alc_alloc_spec(struct hda_codec *codec, hda_nid_t mixer_nid)
4625 struct alc_spec *spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4631 codec->single_adc_amp = 1;
4632 spec->mixer_nid = mixer_nid;
4633 snd_hda_gen_init(&spec->gen);
4634 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
4635 snd_array_init(&spec->bind_ctls, sizeof(struct hda_bind_ctls *), 8);
4636 snd_array_init(&spec->paths, sizeof(struct nid_path), 8);
4638 err = alc_codec_rename_from_preset(codec);
4646 static int alc880_parse_auto_config(struct hda_codec *codec)
4648 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
4649 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4650 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
4659 ALC880_FIXUP_MEDION_RIM,
4662 ALC880_FIXUP_EAPD_COEF,
4663 ALC880_FIXUP_TCL_S700,
4664 ALC880_FIXUP_VOL_KNOB,
4665 ALC880_FIXUP_FUJITSU,
4667 ALC880_FIXUP_UNIWILL,
4668 ALC880_FIXUP_UNIWILL_DIG,
4670 ALC880_FIXUP_3ST_BASE,
4672 ALC880_FIXUP_3ST_DIG,
4673 ALC880_FIXUP_5ST_BASE,
4675 ALC880_FIXUP_5ST_DIG,
4676 ALC880_FIXUP_6ST_BASE,
4678 ALC880_FIXUP_6ST_DIG,
4681 /* enable the volume-knob widget support on NID 0x21 */
4682 static void alc880_fixup_vol_knob(struct hda_codec *codec,
4683 const struct alc_fixup *fix, int action)
4685 if (action == ALC_FIXUP_ACT_PROBE)
4686 snd_hda_jack_detect_enable_callback(codec, 0x21, ALC_DCVOL_EVENT, alc_update_knob_master);
4689 static const struct alc_fixup alc880_fixups[] = {
4690 [ALC880_FIXUP_GPIO1] = {
4691 .type = ALC_FIXUP_VERBS,
4692 .v.verbs = alc_gpio1_init_verbs,
4694 [ALC880_FIXUP_GPIO2] = {
4695 .type = ALC_FIXUP_VERBS,
4696 .v.verbs = alc_gpio2_init_verbs,
4698 [ALC880_FIXUP_MEDION_RIM] = {
4699 .type = ALC_FIXUP_VERBS,
4700 .v.verbs = (const struct hda_verb[]) {
4701 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4702 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4706 .chain_id = ALC880_FIXUP_GPIO2,
4708 [ALC880_FIXUP_LG] = {
4709 .type = ALC_FIXUP_PINS,
4710 .v.pins = (const struct alc_pincfg[]) {
4711 /* disable bogus unused pins */
4712 { 0x16, 0x411111f0 },
4713 { 0x18, 0x411111f0 },
4714 { 0x1a, 0x411111f0 },
4718 [ALC880_FIXUP_W810] = {
4719 .type = ALC_FIXUP_PINS,
4720 .v.pins = (const struct alc_pincfg[]) {
4721 /* disable bogus unused pins */
4722 { 0x17, 0x411111f0 },
4726 .chain_id = ALC880_FIXUP_GPIO2,
4728 [ALC880_FIXUP_EAPD_COEF] = {
4729 .type = ALC_FIXUP_VERBS,
4730 .v.verbs = (const struct hda_verb[]) {
4731 /* change to EAPD mode */
4732 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4733 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4737 [ALC880_FIXUP_TCL_S700] = {
4738 .type = ALC_FIXUP_VERBS,
4739 .v.verbs = (const struct hda_verb[]) {
4740 /* change to EAPD mode */
4741 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4742 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4746 .chain_id = ALC880_FIXUP_GPIO2,
4748 [ALC880_FIXUP_VOL_KNOB] = {
4749 .type = ALC_FIXUP_FUNC,
4750 .v.func = alc880_fixup_vol_knob,
4752 [ALC880_FIXUP_FUJITSU] = {
4753 /* override all pins as BIOS on old Amilo is broken */
4754 .type = ALC_FIXUP_PINS,
4755 .v.pins = (const struct alc_pincfg[]) {
4756 { 0x14, 0x0121411f }, /* HP */
4757 { 0x15, 0x99030120 }, /* speaker */
4758 { 0x16, 0x99030130 }, /* bass speaker */
4759 { 0x17, 0x411111f0 }, /* N/A */
4760 { 0x18, 0x411111f0 }, /* N/A */
4761 { 0x19, 0x01a19950 }, /* mic-in */
4762 { 0x1a, 0x411111f0 }, /* N/A */
4763 { 0x1b, 0x411111f0 }, /* N/A */
4764 { 0x1c, 0x411111f0 }, /* N/A */
4765 { 0x1d, 0x411111f0 }, /* N/A */
4766 { 0x1e, 0x01454140 }, /* SPDIF out */
4770 .chain_id = ALC880_FIXUP_VOL_KNOB,
4772 [ALC880_FIXUP_F1734] = {
4773 /* almost compatible with FUJITSU, but no bass and SPDIF */
4774 .type = ALC_FIXUP_PINS,
4775 .v.pins = (const struct alc_pincfg[]) {
4776 { 0x14, 0x0121411f }, /* HP */
4777 { 0x15, 0x99030120 }, /* speaker */
4778 { 0x16, 0x411111f0 }, /* N/A */
4779 { 0x17, 0x411111f0 }, /* N/A */
4780 { 0x18, 0x411111f0 }, /* N/A */
4781 { 0x19, 0x01a19950 }, /* mic-in */
4782 { 0x1a, 0x411111f0 }, /* N/A */
4783 { 0x1b, 0x411111f0 }, /* N/A */
4784 { 0x1c, 0x411111f0 }, /* N/A */
4785 { 0x1d, 0x411111f0 }, /* N/A */
4786 { 0x1e, 0x411111f0 }, /* N/A */
4790 .chain_id = ALC880_FIXUP_VOL_KNOB,
4792 [ALC880_FIXUP_UNIWILL] = {
4793 /* need to fix HP and speaker pins to be parsed correctly */
4794 .type = ALC_FIXUP_PINS,
4795 .v.pins = (const struct alc_pincfg[]) {
4796 { 0x14, 0x0121411f }, /* HP */
4797 { 0x15, 0x99030120 }, /* speaker */
4798 { 0x16, 0x99030130 }, /* bass speaker */
4802 [ALC880_FIXUP_UNIWILL_DIG] = {
4803 .type = ALC_FIXUP_PINS,
4804 .v.pins = (const struct alc_pincfg[]) {
4805 /* disable bogus unused pins */
4806 { 0x17, 0x411111f0 },
4807 { 0x19, 0x411111f0 },
4808 { 0x1b, 0x411111f0 },
4809 { 0x1f, 0x411111f0 },
4813 [ALC880_FIXUP_Z71V] = {
4814 .type = ALC_FIXUP_PINS,
4815 .v.pins = (const struct alc_pincfg[]) {
4816 /* set up the whole pins as BIOS is utterly broken */
4817 { 0x14, 0x99030120 }, /* speaker */
4818 { 0x15, 0x0121411f }, /* HP */
4819 { 0x16, 0x411111f0 }, /* N/A */
4820 { 0x17, 0x411111f0 }, /* N/A */
4821 { 0x18, 0x01a19950 }, /* mic-in */
4822 { 0x19, 0x411111f0 }, /* N/A */
4823 { 0x1a, 0x01813031 }, /* line-in */
4824 { 0x1b, 0x411111f0 }, /* N/A */
4825 { 0x1c, 0x411111f0 }, /* N/A */
4826 { 0x1d, 0x411111f0 }, /* N/A */
4827 { 0x1e, 0x0144111e }, /* SPDIF */
4831 [ALC880_FIXUP_3ST_BASE] = {
4832 .type = ALC_FIXUP_PINS,
4833 .v.pins = (const struct alc_pincfg[]) {
4834 { 0x14, 0x01014010 }, /* line-out */
4835 { 0x15, 0x411111f0 }, /* N/A */
4836 { 0x16, 0x411111f0 }, /* N/A */
4837 { 0x17, 0x411111f0 }, /* N/A */
4838 { 0x18, 0x01a19c30 }, /* mic-in */
4839 { 0x19, 0x0121411f }, /* HP */
4840 { 0x1a, 0x01813031 }, /* line-in */
4841 { 0x1b, 0x02a19c40 }, /* front-mic */
4842 { 0x1c, 0x411111f0 }, /* N/A */
4843 { 0x1d, 0x411111f0 }, /* N/A */
4844 /* 0x1e is filled in below */
4845 { 0x1f, 0x411111f0 }, /* N/A */
4849 [ALC880_FIXUP_3ST] = {
4850 .type = ALC_FIXUP_PINS,
4851 .v.pins = (const struct alc_pincfg[]) {
4852 { 0x1e, 0x411111f0 }, /* N/A */
4856 .chain_id = ALC880_FIXUP_3ST_BASE,
4858 [ALC880_FIXUP_3ST_DIG] = {
4859 .type = ALC_FIXUP_PINS,
4860 .v.pins = (const struct alc_pincfg[]) {
4861 { 0x1e, 0x0144111e }, /* SPDIF */
4865 .chain_id = ALC880_FIXUP_3ST_BASE,
4867 [ALC880_FIXUP_5ST_BASE] = {
4868 .type = ALC_FIXUP_PINS,
4869 .v.pins = (const struct alc_pincfg[]) {
4870 { 0x14, 0x01014010 }, /* front */
4871 { 0x15, 0x411111f0 }, /* N/A */
4872 { 0x16, 0x01011411 }, /* CLFE */
4873 { 0x17, 0x01016412 }, /* surr */
4874 { 0x18, 0x01a19c30 }, /* mic-in */
4875 { 0x19, 0x0121411f }, /* HP */
4876 { 0x1a, 0x01813031 }, /* line-in */
4877 { 0x1b, 0x02a19c40 }, /* front-mic */
4878 { 0x1c, 0x411111f0 }, /* N/A */
4879 { 0x1d, 0x411111f0 }, /* N/A */
4880 /* 0x1e is filled in below */
4881 { 0x1f, 0x411111f0 }, /* N/A */
4885 [ALC880_FIXUP_5ST] = {
4886 .type = ALC_FIXUP_PINS,
4887 .v.pins = (const struct alc_pincfg[]) {
4888 { 0x1e, 0x411111f0 }, /* N/A */
4892 .chain_id = ALC880_FIXUP_5ST_BASE,
4894 [ALC880_FIXUP_5ST_DIG] = {
4895 .type = ALC_FIXUP_PINS,
4896 .v.pins = (const struct alc_pincfg[]) {
4897 { 0x1e, 0x0144111e }, /* SPDIF */
4901 .chain_id = ALC880_FIXUP_5ST_BASE,
4903 [ALC880_FIXUP_6ST_BASE] = {
4904 .type = ALC_FIXUP_PINS,
4905 .v.pins = (const struct alc_pincfg[]) {
4906 { 0x14, 0x01014010 }, /* front */
4907 { 0x15, 0x01016412 }, /* surr */
4908 { 0x16, 0x01011411 }, /* CLFE */
4909 { 0x17, 0x01012414 }, /* side */
4910 { 0x18, 0x01a19c30 }, /* mic-in */
4911 { 0x19, 0x02a19c40 }, /* front-mic */
4912 { 0x1a, 0x01813031 }, /* line-in */
4913 { 0x1b, 0x0121411f }, /* HP */
4914 { 0x1c, 0x411111f0 }, /* N/A */
4915 { 0x1d, 0x411111f0 }, /* N/A */
4916 /* 0x1e is filled in below */
4917 { 0x1f, 0x411111f0 }, /* N/A */
4921 [ALC880_FIXUP_6ST] = {
4922 .type = ALC_FIXUP_PINS,
4923 .v.pins = (const struct alc_pincfg[]) {
4924 { 0x1e, 0x411111f0 }, /* N/A */
4928 .chain_id = ALC880_FIXUP_6ST_BASE,
4930 [ALC880_FIXUP_6ST_DIG] = {
4931 .type = ALC_FIXUP_PINS,
4932 .v.pins = (const struct alc_pincfg[]) {
4933 { 0x1e, 0x0144111e }, /* SPDIF */
4937 .chain_id = ALC880_FIXUP_6ST_BASE,
4941 static const struct snd_pci_quirk alc880_fixup_tbl[] = {
4942 SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_FIXUP_W810),
4943 SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_FIXUP_Z71V),
4944 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_FIXUP_GPIO1),
4945 SND_PCI_QUIRK(0x1558, 0x5401, "Clevo GPIO2", ALC880_FIXUP_GPIO2),
4946 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo", ALC880_FIXUP_EAPD_COEF),
4947 SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_FIXUP_UNIWILL_DIG),
4948 SND_PCI_QUIRK(0x1584, 0x9054, "Uniwill", ALC880_FIXUP_F1734),
4949 SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_FIXUP_UNIWILL),
4950 SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_FIXUP_VOL_KNOB),
4951 SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_FIXUP_W810),
4952 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
4953 SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_FIXUP_F1734),
4954 SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FIXUP_FUJITSU),
4955 SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_FIXUP_F1734),
4956 SND_PCI_QUIRK(0x1734, 0x10b0, "FSC Amilo Pi1556", ALC880_FIXUP_FUJITSU),
4957 SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_FIXUP_LG),
4958 SND_PCI_QUIRK(0x1854, 0x005f, "LG P1 Express", ALC880_FIXUP_LG),
4959 SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_FIXUP_LG),
4960 SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_FIXUP_TCL_S700),
4962 /* Below is the copied entries from alc880_quirks.c.
4963 * It's not quite sure whether BIOS sets the correct pin-config table
4964 * on these machines, thus they are kept to be compatible with
4965 * the old static quirks. Once when it's confirmed to work without
4966 * these overrides, it'd be better to remove.
4968 SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_FIXUP_5ST_DIG),
4969 SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_FIXUP_6ST),
4970 SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_FIXUP_3ST_DIG),
4971 SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_FIXUP_6ST_DIG),
4972 SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_FIXUP_6ST_DIG),
4973 SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_FIXUP_6ST_DIG),
4974 SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_FIXUP_3ST_DIG),
4975 SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_FIXUP_3ST),
4976 SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_FIXUP_6ST_DIG),
4977 SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_FIXUP_3ST),
4978 SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_FIXUP_3ST),
4979 SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_FIXUP_5ST),
4980 SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_FIXUP_5ST),
4981 SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_FIXUP_5ST),
4982 SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_FIXUP_6ST_DIG),
4983 SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_FIXUP_6ST_DIG),
4984 SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_FIXUP_6ST_DIG),
4985 SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_FIXUP_6ST_DIG),
4986 SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_FIXUP_5ST_DIG),
4987 SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_FIXUP_5ST_DIG),
4988 SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_FIXUP_5ST_DIG),
4989 SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_FIXUP_6ST_DIG), /* broken BIOS */
4990 SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_FIXUP_6ST_DIG),
4991 SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4992 SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4993 SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4994 SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4995 SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4996 SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4997 SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4998 SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4999 SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
5000 SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_FIXUP_5ST_DIG),
5002 SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_FIXUP_3ST),
5003 SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_FIXUP_5ST_DIG),
5004 SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_FIXUP_6ST_DIG),
5008 static const struct alc_model_fixup alc880_fixup_models[] = {
5009 {.id = ALC880_FIXUP_3ST, .name = "3stack"},
5010 {.id = ALC880_FIXUP_3ST_DIG, .name = "3stack-digout"},
5011 {.id = ALC880_FIXUP_5ST, .name = "5stack"},
5012 {.id = ALC880_FIXUP_5ST_DIG, .name = "5stack-digout"},
5013 {.id = ALC880_FIXUP_6ST, .name = "6stack"},
5014 {.id = ALC880_FIXUP_6ST_DIG, .name = "6stack-digout"},
5020 * OK, here we have finally the patch for ALC880
5022 static int patch_alc880(struct hda_codec *codec)
5024 struct alc_spec *spec;
5027 err = alc_alloc_spec(codec, 0x0b);
5032 spec->need_dac_fix = 1;
5034 alc_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl,
5036 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5038 /* automatic parse from the BIOS config */
5039 err = alc880_parse_auto_config(codec);
5043 if (!spec->no_analog) {
5044 err = snd_hda_attach_beep_device(codec, 0x1);
5047 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5050 codec->patch_ops = alc_patch_ops;
5051 codec->patch_ops.unsol_event = alc880_unsol_event;
5054 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5067 static int alc260_parse_auto_config(struct hda_codec *codec)
5069 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
5070 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
5071 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
5078 ALC260_FIXUP_HP_DC5750,
5079 ALC260_FIXUP_HP_PIN_0F,
5082 ALC260_FIXUP_GPIO1_TOGGLE,
5083 ALC260_FIXUP_REPLACER,
5084 ALC260_FIXUP_HP_B1900,
5088 static void alc260_gpio1_automute(struct hda_codec *codec)
5090 struct alc_spec *spec = codec->spec;
5091 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
5092 spec->hp_jack_present);
5095 static void alc260_fixup_gpio1_toggle(struct hda_codec *codec,
5096 const struct alc_fixup *fix, int action)
5098 struct alc_spec *spec = codec->spec;
5099 if (action == ALC_FIXUP_ACT_PROBE) {
5100 /* although the machine has only one output pin, we need to
5101 * toggle GPIO1 according to the jack state
5103 spec->automute_hook = alc260_gpio1_automute;
5104 spec->detect_hp = 1;
5105 spec->automute_speaker = 1;
5106 spec->autocfg.hp_pins[0] = 0x0f; /* copy it for automute */
5107 snd_hda_jack_detect_enable_callback(codec, 0x0f, ALC_HP_EVENT,
5109 snd_hda_gen_add_verbs(&spec->gen, alc_gpio1_init_verbs);
5113 static void alc260_fixup_kn1(struct hda_codec *codec,
5114 const struct alc_fixup *fix, int action)
5116 struct alc_spec *spec = codec->spec;
5117 static const struct alc_pincfg pincfgs[] = {
5118 { 0x0f, 0x02214000 }, /* HP/speaker */
5119 { 0x12, 0x90a60160 }, /* int mic */
5120 { 0x13, 0x02a19000 }, /* ext mic */
5121 { 0x18, 0x01446000 }, /* SPDIF out */
5122 /* disable bogus I/O pins */
5123 { 0x10, 0x411111f0 },
5124 { 0x11, 0x411111f0 },
5125 { 0x14, 0x411111f0 },
5126 { 0x15, 0x411111f0 },
5127 { 0x16, 0x411111f0 },
5128 { 0x17, 0x411111f0 },
5129 { 0x19, 0x411111f0 },
5134 case ALC_FIXUP_ACT_PRE_PROBE:
5135 alc_apply_pincfgs(codec, pincfgs);
5137 case ALC_FIXUP_ACT_PROBE:
5138 spec->init_amp = ALC_INIT_NONE;
5143 static const struct alc_fixup alc260_fixups[] = {
5144 [ALC260_FIXUP_HP_DC5750] = {
5145 .type = ALC_FIXUP_PINS,
5146 .v.pins = (const struct alc_pincfg[]) {
5147 { 0x11, 0x90130110 }, /* speaker */
5151 [ALC260_FIXUP_HP_PIN_0F] = {
5152 .type = ALC_FIXUP_PINS,
5153 .v.pins = (const struct alc_pincfg[]) {
5154 { 0x0f, 0x01214000 }, /* HP */
5158 [ALC260_FIXUP_COEF] = {
5159 .type = ALC_FIXUP_VERBS,
5160 .v.verbs = (const struct hda_verb[]) {
5161 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5162 { 0x20, AC_VERB_SET_PROC_COEF, 0x3040 },
5166 .chain_id = ALC260_FIXUP_HP_PIN_0F,
5168 [ALC260_FIXUP_GPIO1] = {
5169 .type = ALC_FIXUP_VERBS,
5170 .v.verbs = alc_gpio1_init_verbs,
5172 [ALC260_FIXUP_GPIO1_TOGGLE] = {
5173 .type = ALC_FIXUP_FUNC,
5174 .v.func = alc260_fixup_gpio1_toggle,
5176 .chain_id = ALC260_FIXUP_HP_PIN_0F,
5178 [ALC260_FIXUP_REPLACER] = {
5179 .type = ALC_FIXUP_VERBS,
5180 .v.verbs = (const struct hda_verb[]) {
5181 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5182 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5186 .chain_id = ALC260_FIXUP_GPIO1_TOGGLE,
5188 [ALC260_FIXUP_HP_B1900] = {
5189 .type = ALC_FIXUP_FUNC,
5190 .v.func = alc260_fixup_gpio1_toggle,
5192 .chain_id = ALC260_FIXUP_COEF,
5194 [ALC260_FIXUP_KN1] = {
5195 .type = ALC_FIXUP_FUNC,
5196 .v.func = alc260_fixup_kn1,
5200 static const struct snd_pci_quirk alc260_fixup_tbl[] = {
5201 SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_FIXUP_GPIO1),
5202 SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF),
5203 SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1),
5204 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750),
5205 SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900),
5206 SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1),
5207 SND_PCI_QUIRK(0x152d, 0x0729, "Quanta KN1", ALC260_FIXUP_KN1),
5208 SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER),
5209 SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_FIXUP_COEF),
5215 static int patch_alc260(struct hda_codec *codec)
5217 struct alc_spec *spec;
5220 err = alc_alloc_spec(codec, 0x07);
5226 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
5227 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5229 /* automatic parse from the BIOS config */
5230 err = alc260_parse_auto_config(codec);
5234 if (!spec->no_analog) {
5235 err = snd_hda_attach_beep_device(codec, 0x1);
5238 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
5241 codec->patch_ops = alc_patch_ops;
5242 spec->shutup = alc_eapd_shutup;
5244 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5255 * ALC882/883/885/888/889 support
5257 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
5258 * configuration. Each pin widget can choose any input DACs and a mixer.
5259 * Each ADC is connected from a mixer of all inputs. This makes possible
5260 * 6-channel independent captures.
5262 * In addition, an independent DAC for the multi-playback (not used in this
5270 ALC882_FIXUP_ABIT_AW9D_MAX,
5271 ALC882_FIXUP_LENOVO_Y530,
5272 ALC882_FIXUP_PB_M5210,
5273 ALC882_FIXUP_ACER_ASPIRE_7736,
5274 ALC882_FIXUP_ASUS_W90V,
5276 ALC889_FIXUP_VAIO_TT,
5277 ALC888_FIXUP_EEE1601,
5280 ALC883_FIXUP_ACER_EAPD,
5285 ALC882_FIXUP_ASUS_W2JC,
5286 ALC882_FIXUP_ACER_ASPIRE_4930G,
5287 ALC882_FIXUP_ACER_ASPIRE_8930G,
5288 ALC882_FIXUP_ASPIRE_8930G_VERBS,
5289 ALC885_FIXUP_MACPRO_GPIO,
5290 ALC889_FIXUP_DAC_ROUTE,
5291 ALC889_FIXUP_MBP_VREF,
5292 ALC889_FIXUP_IMAC91_VREF,
5293 ALC882_FIXUP_INV_DMIC,
5294 ALC882_FIXUP_NO_PRIMARY_HP,
5297 static void alc889_fixup_coef(struct hda_codec *codec,
5298 const struct alc_fixup *fix, int action)
5300 if (action != ALC_FIXUP_ACT_INIT)
5302 alc889_coef_init(codec);
5305 /* toggle speaker-output according to the hp-jack state */
5306 static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
5308 unsigned int gpiostate, gpiomask, gpiodir;
5310 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
5311 AC_VERB_GET_GPIO_DATA, 0);
5314 gpiostate |= (1 << pin);
5316 gpiostate &= ~(1 << pin);
5318 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
5319 AC_VERB_GET_GPIO_MASK, 0);
5320 gpiomask |= (1 << pin);
5322 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
5323 AC_VERB_GET_GPIO_DIRECTION, 0);
5324 gpiodir |= (1 << pin);
5327 snd_hda_codec_write(codec, codec->afg, 0,
5328 AC_VERB_SET_GPIO_MASK, gpiomask);
5329 snd_hda_codec_write(codec, codec->afg, 0,
5330 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
5334 snd_hda_codec_write(codec, codec->afg, 0,
5335 AC_VERB_SET_GPIO_DATA, gpiostate);
5338 /* set up GPIO at initialization */
5339 static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
5340 const struct alc_fixup *fix, int action)
5342 if (action != ALC_FIXUP_ACT_INIT)
5344 alc882_gpio_mute(codec, 0, 0);
5345 alc882_gpio_mute(codec, 1, 0);
5348 /* Fix the connection of some pins for ALC889:
5349 * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
5350 * work correctly (bko#42740)
5352 static void alc889_fixup_dac_route(struct hda_codec *codec,
5353 const struct alc_fixup *fix, int action)
5355 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
5356 /* fake the connections during parsing the tree */
5357 hda_nid_t conn1[2] = { 0x0c, 0x0d };
5358 hda_nid_t conn2[2] = { 0x0e, 0x0f };
5359 snd_hda_override_conn_list(codec, 0x14, 2, conn1);
5360 snd_hda_override_conn_list(codec, 0x15, 2, conn1);
5361 snd_hda_override_conn_list(codec, 0x18, 2, conn2);
5362 snd_hda_override_conn_list(codec, 0x1a, 2, conn2);
5363 } else if (action == ALC_FIXUP_ACT_PROBE) {
5364 /* restore the connections */
5365 hda_nid_t conn[5] = { 0x0c, 0x0d, 0x0e, 0x0f, 0x26 };
5366 snd_hda_override_conn_list(codec, 0x14, 5, conn);
5367 snd_hda_override_conn_list(codec, 0x15, 5, conn);
5368 snd_hda_override_conn_list(codec, 0x18, 5, conn);
5369 snd_hda_override_conn_list(codec, 0x1a, 5, conn);
5373 /* Set VREF on HP pin */
5374 static void alc889_fixup_mbp_vref(struct hda_codec *codec,
5375 const struct alc_fixup *fix, int action)
5377 struct alc_spec *spec = codec->spec;
5378 static hda_nid_t nids[2] = { 0x14, 0x15 };
5381 if (action != ALC_FIXUP_ACT_INIT)
5383 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5384 unsigned int val = snd_hda_codec_get_pincfg(codec, nids[i]);
5385 if (get_defcfg_device(val) != AC_JACK_HP_OUT)
5387 val = snd_hda_codec_read(codec, nids[i], 0,
5388 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5389 val |= AC_PINCTL_VREF_80;
5390 snd_hda_set_pin_ctl(codec, nids[i], val);
5391 spec->keep_vref_in_automute = 1;
5396 /* Set VREF on speaker pins on imac91 */
5397 static void alc889_fixup_imac91_vref(struct hda_codec *codec,
5398 const struct alc_fixup *fix, int action)
5400 struct alc_spec *spec = codec->spec;
5401 static hda_nid_t nids[2] = { 0x18, 0x1a };
5404 if (action != ALC_FIXUP_ACT_INIT)
5406 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5408 val = snd_hda_codec_read(codec, nids[i], 0,
5409 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5410 val |= AC_PINCTL_VREF_50;
5411 snd_hda_set_pin_ctl(codec, nids[i], val);
5413 spec->keep_vref_in_automute = 1;
5416 /* Don't take HP output as primary
5417 * strangely, the speaker output doesn't work on VAIO Z through DAC 0x05
5419 static void alc882_fixup_no_primary_hp(struct hda_codec *codec,
5420 const struct alc_fixup *fix, int action)
5422 struct alc_spec *spec = codec->spec;
5423 if (action == ALC_FIXUP_ACT_PRE_PROBE)
5424 spec->no_primary_hp = 1;
5427 static const struct alc_fixup alc882_fixups[] = {
5428 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
5429 .type = ALC_FIXUP_PINS,
5430 .v.pins = (const struct alc_pincfg[]) {
5431 { 0x15, 0x01080104 }, /* side */
5432 { 0x16, 0x01011012 }, /* rear */
5433 { 0x17, 0x01016011 }, /* clfe */
5437 [ALC882_FIXUP_LENOVO_Y530] = {
5438 .type = ALC_FIXUP_PINS,
5439 .v.pins = (const struct alc_pincfg[]) {
5440 { 0x15, 0x99130112 }, /* rear int speakers */
5441 { 0x16, 0x99130111 }, /* subwoofer */
5445 [ALC882_FIXUP_PB_M5210] = {
5446 .type = ALC_FIXUP_VERBS,
5447 .v.verbs = (const struct hda_verb[]) {
5448 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
5452 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
5453 .type = ALC_FIXUP_FUNC,
5454 .v.func = alc_fixup_sku_ignore,
5456 [ALC882_FIXUP_ASUS_W90V] = {
5457 .type = ALC_FIXUP_PINS,
5458 .v.pins = (const struct alc_pincfg[]) {
5459 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
5463 [ALC889_FIXUP_CD] = {
5464 .type = ALC_FIXUP_PINS,
5465 .v.pins = (const struct alc_pincfg[]) {
5466 { 0x1c, 0x993301f0 }, /* CD */
5470 [ALC889_FIXUP_VAIO_TT] = {
5471 .type = ALC_FIXUP_PINS,
5472 .v.pins = (const struct alc_pincfg[]) {
5473 { 0x17, 0x90170111 }, /* hidden surround speaker */
5477 [ALC888_FIXUP_EEE1601] = {
5478 .type = ALC_FIXUP_VERBS,
5479 .v.verbs = (const struct hda_verb[]) {
5480 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5481 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
5485 [ALC882_FIXUP_EAPD] = {
5486 .type = ALC_FIXUP_VERBS,
5487 .v.verbs = (const struct hda_verb[]) {
5488 /* change to EAPD mode */
5489 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5490 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
5494 [ALC883_FIXUP_EAPD] = {
5495 .type = ALC_FIXUP_VERBS,
5496 .v.verbs = (const struct hda_verb[]) {
5497 /* change to EAPD mode */
5498 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5499 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5503 [ALC883_FIXUP_ACER_EAPD] = {
5504 .type = ALC_FIXUP_VERBS,
5505 .v.verbs = (const struct hda_verb[]) {
5506 /* eanable EAPD on Acer laptops */
5507 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5508 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5512 [ALC882_FIXUP_GPIO1] = {
5513 .type = ALC_FIXUP_VERBS,
5514 .v.verbs = alc_gpio1_init_verbs,
5516 [ALC882_FIXUP_GPIO2] = {
5517 .type = ALC_FIXUP_VERBS,
5518 .v.verbs = alc_gpio2_init_verbs,
5520 [ALC882_FIXUP_GPIO3] = {
5521 .type = ALC_FIXUP_VERBS,
5522 .v.verbs = alc_gpio3_init_verbs,
5524 [ALC882_FIXUP_ASUS_W2JC] = {
5525 .type = ALC_FIXUP_VERBS,
5526 .v.verbs = alc_gpio1_init_verbs,
5528 .chain_id = ALC882_FIXUP_EAPD,
5530 [ALC889_FIXUP_COEF] = {
5531 .type = ALC_FIXUP_FUNC,
5532 .v.func = alc889_fixup_coef,
5534 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
5535 .type = ALC_FIXUP_PINS,
5536 .v.pins = (const struct alc_pincfg[]) {
5537 { 0x16, 0x99130111 }, /* CLFE speaker */
5538 { 0x17, 0x99130112 }, /* surround speaker */
5542 .chain_id = ALC882_FIXUP_GPIO1,
5544 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
5545 .type = ALC_FIXUP_PINS,
5546 .v.pins = (const struct alc_pincfg[]) {
5547 { 0x16, 0x99130111 }, /* CLFE speaker */
5548 { 0x1b, 0x99130112 }, /* surround speaker */
5552 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
5554 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
5555 /* additional init verbs for Acer Aspire 8930G */
5556 .type = ALC_FIXUP_VERBS,
5557 .v.verbs = (const struct hda_verb[]) {
5558 /* Enable all DACs */
5559 /* DAC DISABLE/MUTE 1? */
5560 /* setting bits 1-5 disables DAC nids 0x02-0x06
5561 * apparently. Init=0x38 */
5562 { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
5563 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5564 /* DAC DISABLE/MUTE 2? */
5565 /* some bit here disables the other DACs.
5567 { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
5568 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5570 * This laptop has a stereo digital microphone.
5571 * The mics are only 1cm apart which makes the stereo
5572 * useless. However, either the mic or the ALC889
5573 * makes the signal become a difference/sum signal
5574 * instead of standard stereo, which is annoying.
5575 * So instead we flip this bit which makes the
5576 * codec replicate the sum signal to both channels,
5577 * turning it into a normal mono mic.
5579 /* DMIC_CONTROL? Init value = 0x0001 */
5580 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5581 { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
5582 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5583 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5587 .chain_id = ALC882_FIXUP_GPIO1,
5589 [ALC885_FIXUP_MACPRO_GPIO] = {
5590 .type = ALC_FIXUP_FUNC,
5591 .v.func = alc885_fixup_macpro_gpio,
5593 [ALC889_FIXUP_DAC_ROUTE] = {
5594 .type = ALC_FIXUP_FUNC,
5595 .v.func = alc889_fixup_dac_route,
5597 [ALC889_FIXUP_MBP_VREF] = {
5598 .type = ALC_FIXUP_FUNC,
5599 .v.func = alc889_fixup_mbp_vref,
5601 .chain_id = ALC882_FIXUP_GPIO1,
5603 [ALC889_FIXUP_IMAC91_VREF] = {
5604 .type = ALC_FIXUP_FUNC,
5605 .v.func = alc889_fixup_imac91_vref,
5607 .chain_id = ALC882_FIXUP_GPIO1,
5609 [ALC882_FIXUP_INV_DMIC] = {
5610 .type = ALC_FIXUP_FUNC,
5611 .v.func = alc_fixup_inv_dmic_0x12,
5613 [ALC882_FIXUP_NO_PRIMARY_HP] = {
5614 .type = ALC_FIXUP_FUNC,
5615 .v.func = alc882_fixup_no_primary_hp,
5619 static const struct snd_pci_quirk alc882_fixup_tbl[] = {
5620 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
5621 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5622 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
5623 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5624 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
5625 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
5626 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
5627 ALC882_FIXUP_ACER_ASPIRE_4930G),
5628 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
5629 ALC882_FIXUP_ACER_ASPIRE_4930G),
5630 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
5631 ALC882_FIXUP_ACER_ASPIRE_8930G),
5632 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
5633 ALC882_FIXUP_ACER_ASPIRE_8930G),
5634 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
5635 ALC882_FIXUP_ACER_ASPIRE_4930G),
5636 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
5637 ALC882_FIXUP_ACER_ASPIRE_4930G),
5638 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
5639 ALC882_FIXUP_ACER_ASPIRE_4930G),
5640 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
5641 SND_PCI_QUIRK(0x1025, 0x021e, "Acer Aspire 5739G",
5642 ALC882_FIXUP_ACER_ASPIRE_4930G),
5643 SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE),
5644 SND_PCI_QUIRK(0x1025, 0x026b, "Acer Aspire 8940G", ALC882_FIXUP_ACER_ASPIRE_8930G),
5645 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
5646 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
5647 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
5648 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
5649 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
5650 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
5651 SND_PCI_QUIRK(0x104d, 0x905a, "Sony Vaio Z", ALC882_FIXUP_NO_PRIMARY_HP),
5653 /* All Apple entries are in codec SSIDs */
5654 SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC889_FIXUP_MBP_VREF),
5655 SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC889_FIXUP_MBP_VREF),
5656 SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
5657 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
5658 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
5659 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
5660 SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC889_FIXUP_MBP_VREF),
5661 SND_PCI_QUIRK(0x106b, 0x3000, "iMac", ALC889_FIXUP_MBP_VREF),
5662 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
5663 SND_PCI_QUIRK(0x106b, 0x3400, "MacBookAir 1,1", ALC889_FIXUP_MBP_VREF),
5664 SND_PCI_QUIRK(0x106b, 0x3500, "MacBookAir 2,1", ALC889_FIXUP_MBP_VREF),
5665 SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889_FIXUP_MBP_VREF),
5666 SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
5667 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
5668 SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC889_FIXUP_IMAC91_VREF),
5669 SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC889_FIXUP_IMAC91_VREF),
5670 SND_PCI_QUIRK(0x106b, 0x4100, "Macmini 3,1", ALC889_FIXUP_IMAC91_VREF),
5671 SND_PCI_QUIRK(0x106b, 0x4200, "Mac Pro 5,1", ALC885_FIXUP_MACPRO_GPIO),
5672 SND_PCI_QUIRK(0x106b, 0x4300, "iMac 9,1", ALC889_FIXUP_IMAC91_VREF),
5673 SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC889_FIXUP_IMAC91_VREF),
5674 SND_PCI_QUIRK(0x106b, 0x4900, "iMac 9,1 Aluminum", ALC889_FIXUP_IMAC91_VREF),
5675 SND_PCI_QUIRK(0x106b, 0x4a00, "Macbook 5,2", ALC889_FIXUP_IMAC91_VREF),
5677 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
5678 SND_PCI_QUIRK(0x1462, 0x7350, "MSI-7350", ALC889_FIXUP_CD),
5679 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
5680 SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte EP45-DS3", ALC889_FIXUP_CD),
5681 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
5682 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
5683 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
5684 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
5685 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
5689 static const struct alc_model_fixup alc882_fixup_models[] = {
5690 {.id = ALC882_FIXUP_ACER_ASPIRE_4930G, .name = "acer-aspire-4930g"},
5691 {.id = ALC882_FIXUP_ACER_ASPIRE_8930G, .name = "acer-aspire-8930g"},
5692 {.id = ALC883_FIXUP_ACER_EAPD, .name = "acer-aspire"},
5693 {.id = ALC882_FIXUP_INV_DMIC, .name = "inv-dmic"},
5694 {.id = ALC882_FIXUP_NO_PRIMARY_HP, .name = "no-primary-hp"},
5699 * BIOS auto configuration
5701 /* almost identical with ALC880 parser... */
5702 static int alc882_parse_auto_config(struct hda_codec *codec)
5704 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
5705 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5706 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
5711 static int patch_alc882(struct hda_codec *codec)
5713 struct alc_spec *spec;
5716 err = alc_alloc_spec(codec, 0x0b);
5722 switch (codec->vendor_id) {
5727 /* ALC883 and variants */
5728 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5732 alc_pick_fixup(codec, alc882_fixup_models, alc882_fixup_tbl,
5734 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5736 alc_auto_parse_customize_define(codec);
5738 /* automatic parse from the BIOS config */
5739 err = alc882_parse_auto_config(codec);
5743 if (!spec->no_analog && has_cdefine_beep(codec)) {
5744 err = snd_hda_attach_beep_device(codec, 0x1);
5747 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5750 codec->patch_ops = alc_patch_ops;
5752 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5765 static int alc262_parse_auto_config(struct hda_codec *codec)
5767 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
5768 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5769 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
5776 ALC262_FIXUP_FSC_H270,
5777 ALC262_FIXUP_HP_Z200,
5779 ALC262_FIXUP_LENOVO_3000,
5781 ALC262_FIXUP_BENQ_T31,
5782 ALC262_FIXUP_INV_DMIC,
5785 static const struct alc_fixup alc262_fixups[] = {
5786 [ALC262_FIXUP_FSC_H270] = {
5787 .type = ALC_FIXUP_PINS,
5788 .v.pins = (const struct alc_pincfg[]) {
5789 { 0x14, 0x99130110 }, /* speaker */
5790 { 0x15, 0x0221142f }, /* front HP */
5791 { 0x1b, 0x0121141f }, /* rear HP */
5795 [ALC262_FIXUP_HP_Z200] = {
5796 .type = ALC_FIXUP_PINS,
5797 .v.pins = (const struct alc_pincfg[]) {
5798 { 0x16, 0x99130120 }, /* internal speaker */
5802 [ALC262_FIXUP_TYAN] = {
5803 .type = ALC_FIXUP_PINS,
5804 .v.pins = (const struct alc_pincfg[]) {
5805 { 0x14, 0x1993e1f0 }, /* int AUX */
5809 [ALC262_FIXUP_LENOVO_3000] = {
5810 .type = ALC_FIXUP_VERBS,
5811 .v.verbs = (const struct hda_verb[]) {
5812 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
5816 .chain_id = ALC262_FIXUP_BENQ,
5818 [ALC262_FIXUP_BENQ] = {
5819 .type = ALC_FIXUP_VERBS,
5820 .v.verbs = (const struct hda_verb[]) {
5821 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5822 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5826 [ALC262_FIXUP_BENQ_T31] = {
5827 .type = ALC_FIXUP_VERBS,
5828 .v.verbs = (const struct hda_verb[]) {
5829 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5830 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5834 [ALC262_FIXUP_INV_DMIC] = {
5835 .type = ALC_FIXUP_FUNC,
5836 .v.func = alc_fixup_inv_dmic_0x12,
5840 static const struct snd_pci_quirk alc262_fixup_tbl[] = {
5841 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
5842 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
5843 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
5844 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
5845 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
5846 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
5847 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
5848 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
5852 static const struct alc_model_fixup alc262_fixup_models[] = {
5853 {.id = ALC262_FIXUP_INV_DMIC, .name = "inv-dmic"},
5859 static int patch_alc262(struct hda_codec *codec)
5861 struct alc_spec *spec;
5864 err = alc_alloc_spec(codec, 0x0b);
5871 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
5876 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5877 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
5878 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5879 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
5882 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5884 alc_pick_fixup(codec, alc262_fixup_models, alc262_fixup_tbl,
5886 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5888 alc_auto_parse_customize_define(codec);
5890 /* automatic parse from the BIOS config */
5891 err = alc262_parse_auto_config(codec);
5895 if (!spec->no_analog && has_cdefine_beep(codec)) {
5896 err = snd_hda_attach_beep_device(codec, 0x1);
5899 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5902 codec->patch_ops = alc_patch_ops;
5903 spec->shutup = alc_eapd_shutup;
5905 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5917 /* bind Beep switches of both NID 0x0f and 0x10 */
5918 static const struct hda_bind_ctls alc268_bind_beep_sw = {
5919 .ops = &snd_hda_bind_sw,
5921 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
5922 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
5927 static const struct snd_kcontrol_new alc268_beep_mixer[] = {
5928 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
5929 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
5933 /* set PCBEEP vol = 0, mute connections */
5934 static const struct hda_verb alc268_beep_init_verbs[] = {
5935 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5936 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5937 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5942 ALC268_FIXUP_INV_DMIC,
5943 ALC268_FIXUP_HP_EAPD,
5946 static const struct alc_fixup alc268_fixups[] = {
5947 [ALC268_FIXUP_INV_DMIC] = {
5948 .type = ALC_FIXUP_FUNC,
5949 .v.func = alc_fixup_inv_dmic_0x12,
5951 [ALC268_FIXUP_HP_EAPD] = {
5952 .type = ALC_FIXUP_VERBS,
5953 .v.verbs = (const struct hda_verb[]) {
5954 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 0},
5960 static const struct alc_model_fixup alc268_fixup_models[] = {
5961 {.id = ALC268_FIXUP_INV_DMIC, .name = "inv-dmic"},
5962 {.id = ALC268_FIXUP_HP_EAPD, .name = "hp-eapd"},
5966 static const struct snd_pci_quirk alc268_fixup_tbl[] = {
5967 /* below is codec SSID since multiple Toshiba laptops have the
5968 * same PCI SSID 1179:ff00
5970 SND_PCI_QUIRK(0x1179, 0xff06, "Toshiba P200", ALC268_FIXUP_HP_EAPD),
5975 * BIOS auto configuration
5977 static int alc268_parse_auto_config(struct hda_codec *codec)
5979 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5980 struct alc_spec *spec = codec->spec;
5981 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
5983 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
5984 add_mixer(spec, alc268_beep_mixer);
5985 snd_hda_gen_add_verbs(&spec->gen, alc268_beep_init_verbs);
5993 static int patch_alc268(struct hda_codec *codec)
5995 struct alc_spec *spec;
5996 int i, has_beep, err;
5998 /* ALC268 has no aa-loopback mixer */
5999 err = alc_alloc_spec(codec, 0);
6005 alc_pick_fixup(codec, alc268_fixup_models, alc268_fixup_tbl, alc268_fixups);
6006 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6008 /* automatic parse from the BIOS config */
6009 err = alc268_parse_auto_config(codec);
6014 for (i = 0; i < spec->num_mixers; i++) {
6015 if (spec->mixers[i] == alc268_beep_mixer) {
6022 err = snd_hda_attach_beep_device(codec, 0x1);
6025 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
6026 /* override the amp caps for beep generator */
6027 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
6028 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
6029 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
6030 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6031 (0 << AC_AMPCAP_MUTE_SHIFT));
6034 codec->patch_ops = alc_patch_ops;
6035 spec->shutup = alc_eapd_shutup;
6037 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6049 static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
6053 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
6054 /* NID is set in alc_build_pcms */
6056 .open = alc_playback_pcm_open,
6057 .prepare = alc_playback_pcm_prepare,
6058 .cleanup = alc_playback_pcm_cleanup
6062 static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
6066 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
6067 /* NID is set in alc_build_pcms */
6070 /* different alc269-variants */
6072 ALC269_TYPE_ALC269VA,
6073 ALC269_TYPE_ALC269VB,
6074 ALC269_TYPE_ALC269VC,
6075 ALC269_TYPE_ALC269VD,
6082 * BIOS auto configuration
6084 static int alc269_parse_auto_config(struct hda_codec *codec)
6086 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
6087 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
6088 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6089 struct alc_spec *spec = codec->spec;
6090 const hda_nid_t *ssids;
6092 switch (spec->codec_variant) {
6093 case ALC269_TYPE_ALC269VA:
6094 case ALC269_TYPE_ALC269VC:
6095 case ALC269_TYPE_ALC280:
6096 case ALC269_TYPE_ALC284:
6097 ssids = alc269va_ssids;
6099 case ALC269_TYPE_ALC269VB:
6100 case ALC269_TYPE_ALC269VD:
6101 case ALC269_TYPE_ALC282:
6102 ssids = alc269_ssids;
6105 ssids = alc269_ssids;
6109 return alc_parse_auto_config(codec, alc269_ignore, ssids);
6112 static void alc269vb_toggle_power_output(struct hda_codec *codec, int power_up)
6114 int val = alc_read_coef_idx(codec, 0x04);
6119 alc_write_coef_idx(codec, 0x04, val);
6122 static void alc269_shutup(struct hda_codec *codec)
6124 struct alc_spec *spec = codec->spec;
6126 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
6129 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
6130 alc269vb_toggle_power_output(codec, 0);
6131 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
6132 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
6138 static int alc269_resume(struct hda_codec *codec)
6140 struct alc_spec *spec = codec->spec;
6142 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
6143 alc269vb_toggle_power_output(codec, 0);
6144 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
6145 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
6149 codec->patch_ops.init(codec);
6151 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
6152 alc269vb_toggle_power_output(codec, 1);
6153 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
6154 (alc_get_coef0(codec) & 0x00ff) == 0x017) {
6158 snd_hda_codec_resume_amp(codec);
6159 snd_hda_codec_resume_cache(codec);
6160 hda_call_check_power_status(codec, 0x01);
6163 #endif /* CONFIG_PM */
6165 static void alc269_fixup_pincfg_no_hp_to_lineout(struct hda_codec *codec,
6166 const struct alc_fixup *fix, int action)
6168 struct alc_spec *spec = codec->spec;
6170 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6171 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
6174 static void alc269_fixup_hweq(struct hda_codec *codec,
6175 const struct alc_fixup *fix, int action)
6179 if (action != ALC_FIXUP_ACT_INIT)
6181 coef = alc_read_coef_idx(codec, 0x1e);
6182 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
6185 static void alc271_fixup_dmic(struct hda_codec *codec,
6186 const struct alc_fixup *fix, int action)
6188 static const struct hda_verb verbs[] = {
6189 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
6190 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
6195 if (strcmp(codec->chip_name, "ALC271X"))
6197 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
6198 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
6199 snd_hda_sequence_write(codec, verbs);
6202 static void alc269_fixup_pcm_44k(struct hda_codec *codec,
6203 const struct alc_fixup *fix, int action)
6205 struct alc_spec *spec = codec->spec;
6207 if (action != ALC_FIXUP_ACT_PROBE)
6210 /* Due to a hardware problem on Lenovo Ideadpad, we need to
6211 * fix the sample rate of analog I/O to 44.1kHz
6213 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
6214 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
6217 static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
6218 const struct alc_fixup *fix, int action)
6222 if (action != ALC_FIXUP_ACT_INIT)
6224 /* The digital-mic unit sends PDM (differential signal) instead of
6225 * the standard PCM, thus you can't record a valid mono stream as is.
6226 * Below is a workaround specific to ALC269 to control the dmic
6227 * signal source as mono.
6229 coef = alc_read_coef_idx(codec, 0x07);
6230 alc_write_coef_idx(codec, 0x07, coef | 0x80);
6233 static void alc269_quanta_automute(struct hda_codec *codec)
6235 update_outputs(codec);
6237 snd_hda_codec_write(codec, 0x20, 0,
6238 AC_VERB_SET_COEF_INDEX, 0x0c);
6239 snd_hda_codec_write(codec, 0x20, 0,
6240 AC_VERB_SET_PROC_COEF, 0x680);
6242 snd_hda_codec_write(codec, 0x20, 0,
6243 AC_VERB_SET_COEF_INDEX, 0x0c);
6244 snd_hda_codec_write(codec, 0x20, 0,
6245 AC_VERB_SET_PROC_COEF, 0x480);
6248 static void alc269_fixup_quanta_mute(struct hda_codec *codec,
6249 const struct alc_fixup *fix, int action)
6251 struct alc_spec *spec = codec->spec;
6252 if (action != ALC_FIXUP_ACT_PROBE)
6254 spec->automute_hook = alc269_quanta_automute;
6257 /* update mute-LED according to the speaker mute state via mic1 VREF pin */
6258 static void alc269_fixup_mic1_mute_hook(void *private_data, int enabled)
6260 struct hda_codec *codec = private_data;
6261 unsigned int pinval = AC_PINCTL_IN_EN + (enabled ?
6262 AC_PINCTL_VREF_HIZ : AC_PINCTL_VREF_80);
6263 snd_hda_set_pin_ctl_cache(codec, 0x18, pinval);
6266 static void alc269_fixup_mic1_mute(struct hda_codec *codec,
6267 const struct alc_fixup *fix, int action)
6269 struct alc_spec *spec = codec->spec;
6271 case ALC_FIXUP_ACT_BUILD:
6272 spec->vmaster_mute.hook = alc269_fixup_mic1_mute_hook;
6273 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
6275 case ALC_FIXUP_ACT_INIT:
6276 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
6281 /* update mute-LED according to the speaker mute state via mic2 VREF pin */
6282 static void alc269_fixup_mic2_mute_hook(void *private_data, int enabled)
6284 struct hda_codec *codec = private_data;
6285 unsigned int pinval = enabled ? 0x20 : 0x24;
6286 snd_hda_set_pin_ctl_cache(codec, 0x19, pinval);
6289 static void alc269_fixup_mic2_mute(struct hda_codec *codec,
6290 const struct alc_fixup *fix, int action)
6292 struct alc_spec *spec = codec->spec;
6294 case ALC_FIXUP_ACT_BUILD:
6295 spec->vmaster_mute.hook = alc269_fixup_mic2_mute_hook;
6296 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
6298 case ALC_FIXUP_ACT_INIT:
6299 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
6304 static void alc271_hp_gate_mic_jack(struct hda_codec *codec,
6305 const struct alc_fixup *fix,
6308 struct alc_spec *spec = codec->spec;
6310 if (action == ALC_FIXUP_ACT_PROBE)
6311 snd_hda_jack_set_gating_jack(codec, spec->ext_mic_pin,
6312 spec->autocfg.hp_pins[0]);
6316 ALC269_FIXUP_SONY_VAIO,
6317 ALC275_FIXUP_SONY_VAIO_GPIO2,
6318 ALC269_FIXUP_DELL_M101Z,
6319 ALC269_FIXUP_SKU_IGNORE,
6320 ALC269_FIXUP_ASUS_G73JW,
6321 ALC269_FIXUP_LENOVO_EAPD,
6322 ALC275_FIXUP_SONY_HWEQ,
6324 ALC269_FIXUP_PCM_44K,
6325 ALC269_FIXUP_STEREO_DMIC,
6326 ALC269_FIXUP_QUANTA_MUTE,
6327 ALC269_FIXUP_LIFEBOOK,
6330 ALC269VB_FIXUP_AMIC,
6331 ALC269VB_FIXUP_DMIC,
6332 ALC269_FIXUP_MIC1_MUTE_LED,
6333 ALC269_FIXUP_MIC2_MUTE_LED,
6334 ALC269_FIXUP_INV_DMIC,
6335 ALC269_FIXUP_LENOVO_DOCK,
6336 ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT,
6337 ALC271_FIXUP_AMIC_MIC2,
6338 ALC271_FIXUP_HP_GATE_MIC_JACK,
6341 static const struct alc_fixup alc269_fixups[] = {
6342 [ALC269_FIXUP_SONY_VAIO] = {
6343 .type = ALC_FIXUP_VERBS,
6344 .v.verbs = (const struct hda_verb[]) {
6345 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
6349 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
6350 .type = ALC_FIXUP_VERBS,
6351 .v.verbs = (const struct hda_verb[]) {
6352 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
6353 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
6354 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
6358 .chain_id = ALC269_FIXUP_SONY_VAIO
6360 [ALC269_FIXUP_DELL_M101Z] = {
6361 .type = ALC_FIXUP_VERBS,
6362 .v.verbs = (const struct hda_verb[]) {
6363 /* Enables internal speaker */
6364 {0x20, AC_VERB_SET_COEF_INDEX, 13},
6365 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
6369 [ALC269_FIXUP_SKU_IGNORE] = {
6370 .type = ALC_FIXUP_FUNC,
6371 .v.func = alc_fixup_sku_ignore,
6373 [ALC269_FIXUP_ASUS_G73JW] = {
6374 .type = ALC_FIXUP_PINS,
6375 .v.pins = (const struct alc_pincfg[]) {
6376 { 0x17, 0x99130111 }, /* subwoofer */
6380 [ALC269_FIXUP_LENOVO_EAPD] = {
6381 .type = ALC_FIXUP_VERBS,
6382 .v.verbs = (const struct hda_verb[]) {
6383 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6387 [ALC275_FIXUP_SONY_HWEQ] = {
6388 .type = ALC_FIXUP_FUNC,
6389 .v.func = alc269_fixup_hweq,
6391 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
6393 [ALC271_FIXUP_DMIC] = {
6394 .type = ALC_FIXUP_FUNC,
6395 .v.func = alc271_fixup_dmic,
6397 [ALC269_FIXUP_PCM_44K] = {
6398 .type = ALC_FIXUP_FUNC,
6399 .v.func = alc269_fixup_pcm_44k,
6401 .chain_id = ALC269_FIXUP_QUANTA_MUTE
6403 [ALC269_FIXUP_STEREO_DMIC] = {
6404 .type = ALC_FIXUP_FUNC,
6405 .v.func = alc269_fixup_stereo_dmic,
6407 [ALC269_FIXUP_QUANTA_MUTE] = {
6408 .type = ALC_FIXUP_FUNC,
6409 .v.func = alc269_fixup_quanta_mute,
6411 [ALC269_FIXUP_LIFEBOOK] = {
6412 .type = ALC_FIXUP_PINS,
6413 .v.pins = (const struct alc_pincfg[]) {
6414 { 0x1a, 0x2101103f }, /* dock line-out */
6415 { 0x1b, 0x23a11040 }, /* dock mic-in */
6419 .chain_id = ALC269_FIXUP_QUANTA_MUTE
6421 [ALC269_FIXUP_AMIC] = {
6422 .type = ALC_FIXUP_PINS,
6423 .v.pins = (const struct alc_pincfg[]) {
6424 { 0x14, 0x99130110 }, /* speaker */
6425 { 0x15, 0x0121401f }, /* HP out */
6426 { 0x18, 0x01a19c20 }, /* mic */
6427 { 0x19, 0x99a3092f }, /* int-mic */
6431 [ALC269_FIXUP_DMIC] = {
6432 .type = ALC_FIXUP_PINS,
6433 .v.pins = (const struct alc_pincfg[]) {
6434 { 0x12, 0x99a3092f }, /* int-mic */
6435 { 0x14, 0x99130110 }, /* speaker */
6436 { 0x15, 0x0121401f }, /* HP out */
6437 { 0x18, 0x01a19c20 }, /* mic */
6441 [ALC269VB_FIXUP_AMIC] = {
6442 .type = ALC_FIXUP_PINS,
6443 .v.pins = (const struct alc_pincfg[]) {
6444 { 0x14, 0x99130110 }, /* speaker */
6445 { 0x18, 0x01a19c20 }, /* mic */
6446 { 0x19, 0x99a3092f }, /* int-mic */
6447 { 0x21, 0x0121401f }, /* HP out */
6451 [ALC269VB_FIXUP_DMIC] = {
6452 .type = ALC_FIXUP_PINS,
6453 .v.pins = (const struct alc_pincfg[]) {
6454 { 0x12, 0x99a3092f }, /* int-mic */
6455 { 0x14, 0x99130110 }, /* speaker */
6456 { 0x18, 0x01a19c20 }, /* mic */
6457 { 0x21, 0x0121401f }, /* HP out */
6461 [ALC269_FIXUP_MIC1_MUTE_LED] = {
6462 .type = ALC_FIXUP_FUNC,
6463 .v.func = alc269_fixup_mic1_mute,
6465 [ALC269_FIXUP_MIC2_MUTE_LED] = {
6466 .type = ALC_FIXUP_FUNC,
6467 .v.func = alc269_fixup_mic2_mute,
6469 [ALC269_FIXUP_INV_DMIC] = {
6470 .type = ALC_FIXUP_FUNC,
6471 .v.func = alc_fixup_inv_dmic_0x12,
6473 [ALC269_FIXUP_LENOVO_DOCK] = {
6474 .type = ALC_FIXUP_PINS,
6475 .v.pins = (const struct alc_pincfg[]) {
6476 { 0x19, 0x23a11040 }, /* dock mic */
6477 { 0x1b, 0x2121103f }, /* dock headphone */
6481 .chain_id = ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT
6483 [ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT] = {
6484 .type = ALC_FIXUP_FUNC,
6485 .v.func = alc269_fixup_pincfg_no_hp_to_lineout,
6487 [ALC271_FIXUP_AMIC_MIC2] = {
6488 .type = ALC_FIXUP_PINS,
6489 .v.pins = (const struct alc_pincfg[]) {
6490 { 0x14, 0x99130110 }, /* speaker */
6491 { 0x19, 0x01a19c20 }, /* mic */
6492 { 0x1b, 0x99a7012f }, /* int-mic */
6493 { 0x21, 0x0121401f }, /* HP out */
6497 [ALC271_FIXUP_HP_GATE_MIC_JACK] = {
6498 .type = ALC_FIXUP_FUNC,
6499 .v.func = alc271_hp_gate_mic_jack,
6501 .chain_id = ALC271_FIXUP_AMIC_MIC2,
6505 static const struct snd_pci_quirk alc269_fixup_tbl[] = {
6506 SND_PCI_QUIRK(0x1025, 0x029b, "Acer 1810TZ", ALC269_FIXUP_INV_DMIC),
6507 SND_PCI_QUIRK(0x1025, 0x0349, "Acer AOD260", ALC269_FIXUP_INV_DMIC),
6508 SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_MIC2_MUTE_LED),
6509 SND_PCI_QUIRK(0x103c, 0x1972, "HP Pavilion 17", ALC269_FIXUP_MIC1_MUTE_LED),
6510 SND_PCI_QUIRK(0x1043, 0x1427, "Asus Zenbook UX31E", ALC269VB_FIXUP_DMIC),
6511 SND_PCI_QUIRK(0x1043, 0x1517, "Asus Zenbook UX31A", ALC269VB_FIXUP_DMIC),
6512 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
6513 SND_PCI_QUIRK(0x1043, 0x1b13, "Asus U41SV", ALC269_FIXUP_INV_DMIC),
6514 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
6515 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
6516 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
6517 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
6518 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
6519 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
6520 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6521 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6522 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
6523 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
6524 SND_PCI_QUIRK(0x1025, 0x0742, "Acer AO756", ALC271_FIXUP_HP_GATE_MIC_JACK),
6525 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
6526 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
6527 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
6528 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
6529 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
6530 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
6531 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
6532 SND_PCI_QUIRK(0x17aa, 0x21f6, "Thinkpad T530", ALC269_FIXUP_LENOVO_DOCK),
6533 SND_PCI_QUIRK(0x17aa, 0x21fa, "Thinkpad X230", ALC269_FIXUP_LENOVO_DOCK),
6534 SND_PCI_QUIRK(0x17aa, 0x21f3, "Thinkpad T430", ALC269_FIXUP_LENOVO_DOCK),
6535 SND_PCI_QUIRK(0x17aa, 0x21fb, "Thinkpad T430s", ALC269_FIXUP_LENOVO_DOCK),
6536 SND_PCI_QUIRK(0x17aa, 0x2203, "Thinkpad X230 Tablet", ALC269_FIXUP_LENOVO_DOCK),
6537 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_PCM_44K),
6538 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
6541 /* Below is a quirk table taken from the old code.
6542 * Basically the device should work as is without the fixup table.
6543 * If BIOS doesn't give a proper info, enable the corresponding
6546 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
6548 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
6549 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
6550 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
6551 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
6552 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
6553 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
6554 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
6555 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
6556 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
6557 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
6558 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
6559 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
6560 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
6561 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
6562 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
6563 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
6564 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
6565 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
6566 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
6567 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
6568 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
6569 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
6570 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
6571 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
6572 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
6573 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
6574 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
6575 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
6576 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
6577 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
6578 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
6579 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
6580 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
6581 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
6582 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
6583 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
6584 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
6585 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
6586 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
6591 static const struct alc_model_fixup alc269_fixup_models[] = {
6592 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
6593 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
6594 {.id = ALC269_FIXUP_STEREO_DMIC, .name = "alc269-dmic"},
6595 {.id = ALC271_FIXUP_DMIC, .name = "alc271-dmic"},
6596 {.id = ALC269_FIXUP_INV_DMIC, .name = "inv-dmic"},
6597 {.id = ALC269_FIXUP_LENOVO_DOCK, .name = "lenovo-dock"},
6602 static void alc269_fill_coef(struct hda_codec *codec)
6604 struct alc_spec *spec = codec->spec;
6607 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
6610 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
6611 alc_write_coef_idx(codec, 0xf, 0x960b);
6612 alc_write_coef_idx(codec, 0xe, 0x8817);
6615 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
6616 alc_write_coef_idx(codec, 0xf, 0x960b);
6617 alc_write_coef_idx(codec, 0xe, 0x8814);
6620 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
6621 val = alc_read_coef_idx(codec, 0x04);
6622 /* Power up output pin */
6623 alc_write_coef_idx(codec, 0x04, val | (1<<11));
6626 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
6627 val = alc_read_coef_idx(codec, 0xd);
6628 if ((val & 0x0c00) >> 10 != 0x1) {
6629 /* Capless ramp up clock control */
6630 alc_write_coef_idx(codec, 0xd, val | (1<<10));
6632 val = alc_read_coef_idx(codec, 0x17);
6633 if ((val & 0x01c0) >> 6 != 0x4) {
6634 /* Class D power on reset */
6635 alc_write_coef_idx(codec, 0x17, val | (1<<7));
6639 val = alc_read_coef_idx(codec, 0xd); /* Class D */
6640 alc_write_coef_idx(codec, 0xd, val | (1<<14));
6642 val = alc_read_coef_idx(codec, 0x4); /* HP */
6643 alc_write_coef_idx(codec, 0x4, val | (1<<11));
6648 static int patch_alc269(struct hda_codec *codec)
6650 struct alc_spec *spec;
6653 err = alc_alloc_spec(codec, 0x0b);
6659 alc_pick_fixup(codec, alc269_fixup_models,
6660 alc269_fixup_tbl, alc269_fixups);
6661 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6663 alc_auto_parse_customize_define(codec);
6665 switch (codec->vendor_id) {
6667 spec->codec_variant = ALC269_TYPE_ALC269VA;
6668 switch (alc_get_coef0(codec) & 0x00f0) {
6670 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
6671 spec->cdefine.platform_type == 1)
6672 err = alc_codec_rename(codec, "ALC271X");
6673 spec->codec_variant = ALC269_TYPE_ALC269VB;
6676 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
6677 codec->bus->pci->subsystem_device == 0x21f3)
6678 err = alc_codec_rename(codec, "ALC3202");
6679 spec->codec_variant = ALC269_TYPE_ALC269VC;
6682 spec->codec_variant = ALC269_TYPE_ALC269VD;
6685 alc_fix_pll_init(codec, 0x20, 0x04, 15);
6689 spec->init_hook = alc269_fill_coef;
6690 alc269_fill_coef(codec);
6695 spec->codec_variant = ALC269_TYPE_ALC280;
6699 spec->codec_variant = ALC269_TYPE_ALC282;
6703 spec->codec_variant = ALC269_TYPE_ALC284;
6707 /* automatic parse from the BIOS config */
6708 err = alc269_parse_auto_config(codec);
6712 if (!spec->no_analog && has_cdefine_beep(codec)) {
6713 err = snd_hda_attach_beep_device(codec, 0x1);
6716 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
6719 codec->patch_ops = alc_patch_ops;
6721 codec->patch_ops.resume = alc269_resume;
6723 spec->shutup = alc269_shutup;
6725 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6738 static int alc861_parse_auto_config(struct hda_codec *codec)
6740 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
6741 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
6742 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
6745 /* Pin config fixes */
6747 ALC861_FIXUP_FSC_AMILO_PI1505,
6748 ALC861_FIXUP_AMP_VREF_0F,
6749 ALC861_FIXUP_NO_JACK_DETECT,
6750 ALC861_FIXUP_ASUS_A6RP,
6753 /* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
6754 static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
6755 const struct alc_fixup *fix, int action)
6757 struct alc_spec *spec = codec->spec;
6760 if (action != ALC_FIXUP_ACT_INIT)
6762 val = snd_hda_codec_read(codec, 0x0f, 0,
6763 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
6764 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
6765 val |= AC_PINCTL_IN_EN;
6766 val |= AC_PINCTL_VREF_50;
6767 snd_hda_set_pin_ctl(codec, 0x0f, val);
6768 spec->keep_vref_in_automute = 1;
6771 /* suppress the jack-detection */
6772 static void alc_fixup_no_jack_detect(struct hda_codec *codec,
6773 const struct alc_fixup *fix, int action)
6775 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6776 codec->no_jack_detect = 1;
6779 static const struct alc_fixup alc861_fixups[] = {
6780 [ALC861_FIXUP_FSC_AMILO_PI1505] = {
6781 .type = ALC_FIXUP_PINS,
6782 .v.pins = (const struct alc_pincfg[]) {
6783 { 0x0b, 0x0221101f }, /* HP */
6784 { 0x0f, 0x90170310 }, /* speaker */
6788 [ALC861_FIXUP_AMP_VREF_0F] = {
6789 .type = ALC_FIXUP_FUNC,
6790 .v.func = alc861_fixup_asus_amp_vref_0f,
6792 [ALC861_FIXUP_NO_JACK_DETECT] = {
6793 .type = ALC_FIXUP_FUNC,
6794 .v.func = alc_fixup_no_jack_detect,
6796 [ALC861_FIXUP_ASUS_A6RP] = {
6797 .type = ALC_FIXUP_FUNC,
6798 .v.func = alc861_fixup_asus_amp_vref_0f,
6800 .chain_id = ALC861_FIXUP_NO_JACK_DETECT,
6804 static const struct snd_pci_quirk alc861_fixup_tbl[] = {
6805 SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP),
6806 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", ALC861_FIXUP_AMP_VREF_0F),
6807 SND_PCI_QUIRK(0x1462, 0x7254, "HP DX2200", ALC861_FIXUP_NO_JACK_DETECT),
6808 SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", ALC861_FIXUP_AMP_VREF_0F),
6809 SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", ALC861_FIXUP_AMP_VREF_0F),
6810 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", ALC861_FIXUP_FSC_AMILO_PI1505),
6816 static int patch_alc861(struct hda_codec *codec)
6818 struct alc_spec *spec;
6821 err = alc_alloc_spec(codec, 0x15);
6827 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
6828 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6830 /* automatic parse from the BIOS config */
6831 err = alc861_parse_auto_config(codec);
6835 if (!spec->no_analog) {
6836 err = snd_hda_attach_beep_device(codec, 0x23);
6839 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
6842 codec->patch_ops = alc_patch_ops;
6844 spec->power_hook = alc_power_eapd;
6847 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6861 * In addition, an independent DAC
6863 static int alc861vd_parse_auto_config(struct hda_codec *codec)
6865 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
6866 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6867 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
6871 ALC660VD_FIX_ASUS_GPIO1,
6872 ALC861VD_FIX_DALLAS,
6875 /* exclude VREF80 */
6876 static void alc861vd_fixup_dallas(struct hda_codec *codec,
6877 const struct alc_fixup *fix, int action)
6879 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
6880 snd_hda_override_pin_caps(codec, 0x18, 0x00000734);
6881 snd_hda_override_pin_caps(codec, 0x19, 0x0000073c);
6885 static const struct alc_fixup alc861vd_fixups[] = {
6886 [ALC660VD_FIX_ASUS_GPIO1] = {
6887 .type = ALC_FIXUP_VERBS,
6888 .v.verbs = (const struct hda_verb[]) {
6890 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6891 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
6892 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
6896 [ALC861VD_FIX_DALLAS] = {
6897 .type = ALC_FIXUP_FUNC,
6898 .v.func = alc861vd_fixup_dallas,
6902 static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
6903 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
6904 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
6905 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
6911 static int patch_alc861vd(struct hda_codec *codec)
6913 struct alc_spec *spec;
6916 err = alc_alloc_spec(codec, 0x0b);
6922 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
6923 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6925 /* automatic parse from the BIOS config */
6926 err = alc861vd_parse_auto_config(codec);
6930 if (!spec->no_analog) {
6931 err = snd_hda_attach_beep_device(codec, 0x23);
6934 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6937 codec->patch_ops = alc_patch_ops;
6939 spec->shutup = alc_eapd_shutup;
6941 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6953 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
6954 * configuration. Each pin widget can choose any input DACs and a mixer.
6955 * Each ADC is connected from a mixer of all inputs. This makes possible
6956 * 6-channel independent captures.
6958 * In addition, an independent DAC for the multi-playback (not used in this
6963 * BIOS auto configuration
6966 static int alc662_parse_auto_config(struct hda_codec *codec)
6968 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
6969 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
6970 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6971 const hda_nid_t *ssids;
6973 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
6974 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
6975 ssids = alc663_ssids;
6977 ssids = alc662_ssids;
6978 return alc_parse_auto_config(codec, alc662_ignore, ssids);
6981 static void alc272_fixup_mario(struct hda_codec *codec,
6982 const struct alc_fixup *fix, int action)
6984 if (action != ALC_FIXUP_ACT_PROBE)
6986 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
6987 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
6988 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
6989 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6990 (0 << AC_AMPCAP_MUTE_SHIFT)))
6992 "hda_codec: failed to override amp caps for NID 0x2\n");
6996 ALC662_FIXUP_ASPIRE,
6997 ALC662_FIXUP_IDEAPAD,
6999 ALC662_FIXUP_CZC_P10T,
7000 ALC662_FIXUP_SKU_IGNORE,
7001 ALC662_FIXUP_HP_RP5800,
7002 ALC662_FIXUP_ASUS_MODE1,
7003 ALC662_FIXUP_ASUS_MODE2,
7004 ALC662_FIXUP_ASUS_MODE3,
7005 ALC662_FIXUP_ASUS_MODE4,
7006 ALC662_FIXUP_ASUS_MODE5,
7007 ALC662_FIXUP_ASUS_MODE6,
7008 ALC662_FIXUP_ASUS_MODE7,
7009 ALC662_FIXUP_ASUS_MODE8,
7010 ALC662_FIXUP_NO_JACK_DETECT,
7011 ALC662_FIXUP_ZOTAC_Z68,
7012 ALC662_FIXUP_INV_DMIC,
7015 static const struct alc_fixup alc662_fixups[] = {
7016 [ALC662_FIXUP_ASPIRE] = {
7017 .type = ALC_FIXUP_PINS,
7018 .v.pins = (const struct alc_pincfg[]) {
7019 { 0x15, 0x99130112 }, /* subwoofer */
7023 [ALC662_FIXUP_IDEAPAD] = {
7024 .type = ALC_FIXUP_PINS,
7025 .v.pins = (const struct alc_pincfg[]) {
7026 { 0x17, 0x99130112 }, /* subwoofer */
7030 [ALC272_FIXUP_MARIO] = {
7031 .type = ALC_FIXUP_FUNC,
7032 .v.func = alc272_fixup_mario,
7034 [ALC662_FIXUP_CZC_P10T] = {
7035 .type = ALC_FIXUP_VERBS,
7036 .v.verbs = (const struct hda_verb[]) {
7037 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
7041 [ALC662_FIXUP_SKU_IGNORE] = {
7042 .type = ALC_FIXUP_FUNC,
7043 .v.func = alc_fixup_sku_ignore,
7045 [ALC662_FIXUP_HP_RP5800] = {
7046 .type = ALC_FIXUP_PINS,
7047 .v.pins = (const struct alc_pincfg[]) {
7048 { 0x14, 0x0221201f }, /* HP out */
7052 .chain_id = ALC662_FIXUP_SKU_IGNORE
7054 [ALC662_FIXUP_ASUS_MODE1] = {
7055 .type = ALC_FIXUP_PINS,
7056 .v.pins = (const struct alc_pincfg[]) {
7057 { 0x14, 0x99130110 }, /* speaker */
7058 { 0x18, 0x01a19c20 }, /* mic */
7059 { 0x19, 0x99a3092f }, /* int-mic */
7060 { 0x21, 0x0121401f }, /* HP out */
7064 .chain_id = ALC662_FIXUP_SKU_IGNORE
7066 [ALC662_FIXUP_ASUS_MODE2] = {
7067 .type = ALC_FIXUP_PINS,
7068 .v.pins = (const struct alc_pincfg[]) {
7069 { 0x14, 0x99130110 }, /* speaker */
7070 { 0x18, 0x01a19820 }, /* mic */
7071 { 0x19, 0x99a3092f }, /* int-mic */
7072 { 0x1b, 0x0121401f }, /* HP out */
7076 .chain_id = ALC662_FIXUP_SKU_IGNORE
7078 [ALC662_FIXUP_ASUS_MODE3] = {
7079 .type = ALC_FIXUP_PINS,
7080 .v.pins = (const struct alc_pincfg[]) {
7081 { 0x14, 0x99130110 }, /* speaker */
7082 { 0x15, 0x0121441f }, /* HP */
7083 { 0x18, 0x01a19840 }, /* mic */
7084 { 0x19, 0x99a3094f }, /* int-mic */
7085 { 0x21, 0x01211420 }, /* HP2 */
7089 .chain_id = ALC662_FIXUP_SKU_IGNORE
7091 [ALC662_FIXUP_ASUS_MODE4] = {
7092 .type = ALC_FIXUP_PINS,
7093 .v.pins = (const struct alc_pincfg[]) {
7094 { 0x14, 0x99130110 }, /* speaker */
7095 { 0x16, 0x99130111 }, /* speaker */
7096 { 0x18, 0x01a19840 }, /* mic */
7097 { 0x19, 0x99a3094f }, /* int-mic */
7098 { 0x21, 0x0121441f }, /* HP */
7102 .chain_id = ALC662_FIXUP_SKU_IGNORE
7104 [ALC662_FIXUP_ASUS_MODE5] = {
7105 .type = ALC_FIXUP_PINS,
7106 .v.pins = (const struct alc_pincfg[]) {
7107 { 0x14, 0x99130110 }, /* speaker */
7108 { 0x15, 0x0121441f }, /* HP */
7109 { 0x16, 0x99130111 }, /* speaker */
7110 { 0x18, 0x01a19840 }, /* mic */
7111 { 0x19, 0x99a3094f }, /* int-mic */
7115 .chain_id = ALC662_FIXUP_SKU_IGNORE
7117 [ALC662_FIXUP_ASUS_MODE6] = {
7118 .type = ALC_FIXUP_PINS,
7119 .v.pins = (const struct alc_pincfg[]) {
7120 { 0x14, 0x99130110 }, /* speaker */
7121 { 0x15, 0x01211420 }, /* HP2 */
7122 { 0x18, 0x01a19840 }, /* mic */
7123 { 0x19, 0x99a3094f }, /* int-mic */
7124 { 0x1b, 0x0121441f }, /* HP */
7128 .chain_id = ALC662_FIXUP_SKU_IGNORE
7130 [ALC662_FIXUP_ASUS_MODE7] = {
7131 .type = ALC_FIXUP_PINS,
7132 .v.pins = (const struct alc_pincfg[]) {
7133 { 0x14, 0x99130110 }, /* speaker */
7134 { 0x17, 0x99130111 }, /* speaker */
7135 { 0x18, 0x01a19840 }, /* mic */
7136 { 0x19, 0x99a3094f }, /* int-mic */
7137 { 0x1b, 0x01214020 }, /* HP */
7138 { 0x21, 0x0121401f }, /* HP */
7142 .chain_id = ALC662_FIXUP_SKU_IGNORE
7144 [ALC662_FIXUP_ASUS_MODE8] = {
7145 .type = ALC_FIXUP_PINS,
7146 .v.pins = (const struct alc_pincfg[]) {
7147 { 0x14, 0x99130110 }, /* speaker */
7148 { 0x12, 0x99a30970 }, /* int-mic */
7149 { 0x15, 0x01214020 }, /* HP */
7150 { 0x17, 0x99130111 }, /* speaker */
7151 { 0x18, 0x01a19840 }, /* mic */
7152 { 0x21, 0x0121401f }, /* HP */
7156 .chain_id = ALC662_FIXUP_SKU_IGNORE
7158 [ALC662_FIXUP_NO_JACK_DETECT] = {
7159 .type = ALC_FIXUP_FUNC,
7160 .v.func = alc_fixup_no_jack_detect,
7162 [ALC662_FIXUP_ZOTAC_Z68] = {
7163 .type = ALC_FIXUP_PINS,
7164 .v.pins = (const struct alc_pincfg[]) {
7165 { 0x1b, 0x02214020 }, /* Front HP */
7169 [ALC662_FIXUP_INV_DMIC] = {
7170 .type = ALC_FIXUP_FUNC,
7171 .v.func = alc_fixup_inv_dmic_0x12,
7175 static const struct snd_pci_quirk alc662_fixup_tbl[] = {
7176 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
7177 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
7178 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
7179 SND_PCI_QUIRK(0x1025, 0x0349, "eMachines eM250", ALC662_FIXUP_INV_DMIC),
7180 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
7181 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
7182 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT),
7183 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
7184 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
7185 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
7186 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
7187 SND_PCI_QUIRK(0x19da, 0xa130, "Zotac Z68", ALC662_FIXUP_ZOTAC_Z68),
7188 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
7191 /* Below is a quirk table taken from the old code.
7192 * Basically the device should work as is without the fixup table.
7193 * If BIOS doesn't give a proper info, enable the corresponding
7196 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
7197 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
7198 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
7199 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
7200 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7201 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7202 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7203 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
7204 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
7205 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7206 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
7207 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
7208 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
7209 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
7210 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
7211 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7212 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
7213 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
7214 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7215 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
7216 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
7217 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7218 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
7219 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
7220 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
7221 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7222 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
7223 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
7224 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7225 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
7226 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7227 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7228 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
7229 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
7230 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
7231 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
7232 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
7233 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
7234 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
7235 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7236 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
7237 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
7238 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7239 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
7240 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
7241 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
7242 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
7243 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
7244 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7245 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
7250 static const struct alc_model_fixup alc662_fixup_models[] = {
7251 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
7252 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
7253 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
7254 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
7255 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
7256 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
7257 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
7258 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
7259 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
7260 {.id = ALC662_FIXUP_INV_DMIC, .name = "inv-dmic"},
7264 static void alc662_fill_coef(struct hda_codec *codec)
7268 coef = alc_get_coef0(codec);
7270 switch (codec->vendor_id) {
7272 if ((coef & 0x00f0) == 0x0030) {
7273 val = alc_read_coef_idx(codec, 0x4); /* EAPD Ctrl */
7274 alc_write_coef_idx(codec, 0x4, val & ~(1<<10));
7284 val = alc_read_coef_idx(codec, 0xd); /* EAPD Ctrl */
7285 alc_write_coef_idx(codec, 0xd, val | (1<<14));
7292 static int patch_alc662(struct hda_codec *codec)
7294 struct alc_spec *spec;
7297 err = alc_alloc_spec(codec, 0x0b);
7303 /* handle multiple HPs as is */
7304 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
7306 alc_fix_pll_init(codec, 0x20, 0x04, 15);
7308 spec->init_hook = alc662_fill_coef;
7309 alc662_fill_coef(codec);
7311 alc_pick_fixup(codec, alc662_fixup_models,
7312 alc662_fixup_tbl, alc662_fixups);
7313 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
7315 alc_auto_parse_customize_define(codec);
7317 if ((alc_get_coef0(codec) & (1 << 14)) &&
7318 codec->bus->pci->subsystem_vendor == 0x1025 &&
7319 spec->cdefine.platform_type == 1) {
7320 if (alc_codec_rename(codec, "ALC272X") < 0)
7324 /* automatic parse from the BIOS config */
7325 err = alc662_parse_auto_config(codec);
7329 if (!spec->no_analog && has_cdefine_beep(codec)) {
7330 err = snd_hda_attach_beep_device(codec, 0x1);
7333 switch (codec->vendor_id) {
7335 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
7340 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
7343 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
7348 codec->patch_ops = alc_patch_ops;
7349 spec->shutup = alc_eapd_shutup;
7351 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
7364 static int alc680_parse_auto_config(struct hda_codec *codec)
7366 return alc_parse_auto_config(codec, NULL, NULL);
7371 static int patch_alc680(struct hda_codec *codec)
7375 /* ALC680 has no aa-loopback mixer */
7376 err = alc_alloc_spec(codec, 0);
7380 /* automatic parse from the BIOS config */
7381 err = alc680_parse_auto_config(codec);
7387 codec->patch_ops = alc_patch_ops;
7395 static const struct hda_codec_preset snd_hda_preset_realtek[] = {
7396 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
7397 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
7398 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
7399 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
7400 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
7401 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
7402 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
7403 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
7404 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
7405 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
7406 { .id = 0x10ec0280, .name = "ALC280", .patch = patch_alc269 },
7407 { .id = 0x10ec0282, .name = "ALC282", .patch = patch_alc269 },
7408 { .id = 0x10ec0283, .name = "ALC283", .patch = patch_alc269 },
7409 { .id = 0x10ec0284, .name = "ALC284", .patch = patch_alc269 },
7410 { .id = 0x10ec0290, .name = "ALC290", .patch = patch_alc269 },
7411 { .id = 0x10ec0292, .name = "ALC292", .patch = patch_alc269 },
7412 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
7413 .patch = patch_alc861 },
7414 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
7415 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
7416 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
7417 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
7418 .patch = patch_alc882 },
7419 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
7420 .patch = patch_alc662 },
7421 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
7422 .patch = patch_alc662 },
7423 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
7424 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
7425 { .id = 0x10ec0668, .name = "ALC668", .patch = patch_alc662 },
7426 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
7427 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
7428 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
7429 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
7430 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
7431 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
7432 .patch = patch_alc882 },
7433 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
7434 .patch = patch_alc882 },
7435 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
7436 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
7437 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
7438 .patch = patch_alc882 },
7439 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
7440 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
7441 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
7442 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
7443 { .id = 0x10ec0900, .name = "ALC1150", .patch = patch_alc882 },
7447 MODULE_ALIAS("snd-hda-codec-id:10ec*");
7449 MODULE_LICENSE("GPL");
7450 MODULE_DESCRIPTION("Realtek HD-audio codec");
7452 static struct hda_codec_preset_list realtek_list = {
7453 .preset = snd_hda_preset_realtek,
7454 .owner = THIS_MODULE,
7457 static int __init patch_realtek_init(void)
7459 return snd_hda_add_codec_preset(&realtek_list);
7462 static void __exit patch_realtek_exit(void)
7464 snd_hda_delete_codec_preset(&realtek_list);
7467 module_init(patch_realtek_init)
7468 module_exit(patch_realtek_exit)