2 * Universal Interface for Intel High Definition Audio Codec
4 * HD audio interface patch for Realtek ALC codecs
6 * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
7 * PeiSen Hou <pshou@realtek.com.tw>
8 * Takashi Iwai <tiwai@suse.de>
9 * Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
11 * This driver is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This driver is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include <linux/init.h>
27 #include <linux/delay.h>
28 #include <linux/slab.h>
29 #include <linux/pci.h>
30 #include <linux/module.h>
31 #include <sound/core.h>
32 #include <sound/jack.h>
33 #include "hda_codec.h"
34 #include "hda_local.h"
37 /* unsol event tags */
38 #define ALC_FRONT_EVENT 0x01
39 #define ALC_DCVOL_EVENT 0x02
40 #define ALC_HP_EVENT 0x04
41 #define ALC_MIC_EVENT 0x08
44 #define GPIO_MASK 0x03
46 /* extra amp-initialization sequence types */
55 struct alc_customize_define {
57 unsigned char port_connectivity;
58 unsigned char check_sum;
59 unsigned char customization;
60 unsigned char external_amp;
61 unsigned int enable_pcbeep:1;
62 unsigned int platform_type:1;
64 unsigned int override:1;
65 unsigned int fixup:1; /* Means that this sku is set by driver, not read from hw */
71 hda_nid_t pin; /* multi-io widget pin NID */
72 hda_nid_t dac; /* DAC to be connected */
73 unsigned int ctl_in; /* cached input-pin control value */
77 ALC_AUTOMUTE_PIN, /* change the pin control */
78 ALC_AUTOMUTE_AMP, /* mute/unmute the pin AMP */
79 ALC_AUTOMUTE_MIXER, /* mute/unmute mixer widget AMP */
83 /* codec parameterization */
84 const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */
85 unsigned int num_mixers;
86 const struct snd_kcontrol_new *cap_mixer; /* capture mixer */
87 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
89 const struct hda_verb *init_verbs[10]; /* initialization verbs
93 unsigned int num_init_verbs;
95 char stream_name_analog[32]; /* analog PCM stream */
96 const struct hda_pcm_stream *stream_analog_playback;
97 const struct hda_pcm_stream *stream_analog_capture;
98 const struct hda_pcm_stream *stream_analog_alt_playback;
99 const struct hda_pcm_stream *stream_analog_alt_capture;
101 char stream_name_digital[32]; /* digital PCM stream */
102 const struct hda_pcm_stream *stream_digital_playback;
103 const struct hda_pcm_stream *stream_digital_capture;
106 struct hda_multi_out multiout; /* playback set-up
107 * max_channels, dacs must be set
108 * dig_out_nid and hp_nid are optional
110 hda_nid_t alt_dac_nid;
111 hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */
115 unsigned int num_adc_nids;
116 const hda_nid_t *adc_nids;
117 const hda_nid_t *capsrc_nids;
118 hda_nid_t dig_in_nid; /* digital-in NID; optional */
119 hda_nid_t mixer_nid; /* analog-mixer NID */
120 DECLARE_BITMAP(vol_ctls, 0x20 << 1);
121 DECLARE_BITMAP(sw_ctls, 0x20 << 1);
123 /* capture setup for dynamic dual-adc switch */
125 unsigned int cur_adc_stream_tag;
126 unsigned int cur_adc_format;
129 unsigned int num_mux_defs;
130 const struct hda_input_mux *input_mux;
131 unsigned int cur_mux[3];
132 hda_nid_t ext_mic_pin;
133 hda_nid_t dock_mic_pin;
134 hda_nid_t int_mic_pin;
137 const struct hda_channel_mode *channel_mode;
138 int num_channel_mode;
140 int const_channel_count;
141 int ext_channel_count;
143 /* PCM information */
144 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
146 /* dynamic controls, init_verbs and input_mux */
147 struct auto_pin_cfg autocfg;
148 struct alc_customize_define cdefine;
149 struct snd_array kctls;
150 struct hda_input_mux private_imux[3];
151 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
152 hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS];
153 hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS];
154 hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS];
155 unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS];
156 int int_mic_idx, ext_mic_idx, dock_mic_idx; /* for auto-mic */
159 void (*init_hook)(struct hda_codec *codec);
160 void (*unsol_event)(struct hda_codec *codec, unsigned int res);
161 #ifdef CONFIG_SND_HDA_POWER_SAVE
162 void (*power_hook)(struct hda_codec *codec);
164 void (*shutup)(struct hda_codec *codec);
165 void (*automute_hook)(struct hda_codec *codec);
167 /* for pin sensing */
168 unsigned int hp_jack_present:1;
169 unsigned int line_jack_present:1;
170 unsigned int master_mute:1;
171 unsigned int auto_mic:1;
172 unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */
173 unsigned int automute_speaker:1; /* automute speaker outputs */
174 unsigned int automute_lo:1; /* automute LO outputs */
175 unsigned int detect_hp:1; /* Headphone detection enabled */
176 unsigned int detect_lo:1; /* Line-out detection enabled */
177 unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */
178 unsigned int automute_lo_possible:1; /* there are line outs and HP */
179 unsigned int keep_vref_in_automute:1; /* Don't clear VREF in automute */
182 unsigned int no_analog :1; /* digital I/O only */
183 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
184 unsigned int single_input_src:1;
185 unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */
186 unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */
188 /* auto-mute control */
190 hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS];
193 int codec_variant; /* flag for other variants */
195 /* for virtual master */
196 hda_nid_t vmaster_nid;
197 #ifdef CONFIG_SND_HDA_POWER_SAVE
198 struct hda_loopback_check loopback;
203 unsigned int pll_coef_idx, pll_coef_bit;
208 const struct alc_fixup *fixup_list;
209 const char *fixup_name;
213 struct alc_multi_io multi_io[4];
216 struct snd_array bind_ctls;
219 #define ALC_MODEL_AUTO 0 /* common for all chips */
221 static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
222 int dir, unsigned int bits)
226 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
227 if (query_amp_caps(codec, nid, dir) & bits)
232 #define nid_has_mute(codec, nid, dir) \
233 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
234 #define nid_has_volume(codec, nid, dir) \
235 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
240 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
241 struct snd_ctl_elem_info *uinfo)
243 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
244 struct alc_spec *spec = codec->spec;
245 unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
246 if (mux_idx >= spec->num_mux_defs)
248 if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
250 return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
253 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
254 struct snd_ctl_elem_value *ucontrol)
256 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
257 struct alc_spec *spec = codec->spec;
258 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
260 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
264 static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
266 struct alc_spec *spec = codec->spec;
267 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
269 if (spec->cur_adc && spec->cur_adc != new_adc) {
270 /* stream is running, let's swap the current ADC */
271 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
272 spec->cur_adc = new_adc;
273 snd_hda_codec_setup_stream(codec, new_adc,
274 spec->cur_adc_stream_tag, 0,
275 spec->cur_adc_format);
281 static inline hda_nid_t get_capsrc(struct alc_spec *spec, int idx)
283 return spec->capsrc_nids ?
284 spec->capsrc_nids[idx] : spec->adc_nids[idx];
287 /* select the given imux item; either unmute exclusively or select the route */
288 static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
289 unsigned int idx, bool force)
291 struct alc_spec *spec = codec->spec;
292 const struct hda_input_mux *imux;
293 unsigned int mux_idx;
294 int i, type, num_conns;
297 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
298 imux = &spec->input_mux[mux_idx];
299 if (!imux->num_items && mux_idx > 0)
300 imux = &spec->input_mux[0];
301 if (!imux->num_items)
304 if (idx >= imux->num_items)
305 idx = imux->num_items - 1;
306 if (spec->cur_mux[adc_idx] == idx && !force)
308 spec->cur_mux[adc_idx] = idx;
310 if (spec->dyn_adc_switch) {
311 alc_dyn_adc_pcm_resetup(codec, idx);
312 adc_idx = spec->dyn_adc_idx[idx];
315 nid = get_capsrc(spec, adc_idx);
318 num_conns = snd_hda_get_conn_list(codec, nid, NULL);
322 type = get_wcaps_type(get_wcaps(codec, nid));
323 if (type == AC_WID_AUD_MIX) {
324 /* Matrix-mixer style (e.g. ALC882) */
325 int active = imux->items[idx].index;
326 for (i = 0; i < num_conns; i++) {
327 unsigned int v = (i == active) ? 0 : HDA_AMP_MUTE;
328 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, i,
332 /* MUX style (e.g. ALC880) */
333 snd_hda_codec_write_cache(codec, nid, 0,
334 AC_VERB_SET_CONNECT_SEL,
335 imux->items[idx].index);
340 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
341 struct snd_ctl_elem_value *ucontrol)
343 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
344 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
345 return alc_mux_select(codec, adc_idx,
346 ucontrol->value.enumerated.item[0], false);
350 * set up the input pin config (depending on the given auto-pin type)
352 static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
355 unsigned int val = PIN_IN;
357 if (auto_pin_type == AUTO_PIN_MIC) {
360 oldval = snd_hda_codec_read(codec, nid, 0,
361 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
362 pincap = snd_hda_query_pin_caps(codec, nid);
363 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
364 /* if the default pin setup is vref50, we give it priority */
365 if ((pincap & AC_PINCAP_VREF_80) && oldval != PIN_VREF50)
367 else if (pincap & AC_PINCAP_VREF_50)
369 else if (pincap & AC_PINCAP_VREF_100)
371 else if (pincap & AC_PINCAP_VREF_GRD)
374 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val);
378 * Append the given mixer and verb elements for the later use
379 * The mixer array is referred in build_controls(), and init_verbs are
382 static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
384 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
386 spec->mixers[spec->num_mixers++] = mix;
389 static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
391 if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
393 spec->init_verbs[spec->num_init_verbs++] = verb;
397 * GPIO setup tables, used in initialization
399 /* Enable GPIO mask and set output */
400 static const struct hda_verb alc_gpio1_init_verbs[] = {
401 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
402 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
403 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
407 static const struct hda_verb alc_gpio2_init_verbs[] = {
408 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
409 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
410 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
414 static const struct hda_verb alc_gpio3_init_verbs[] = {
415 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
416 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
417 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
422 * Fix hardware PLL issue
423 * On some codecs, the analog PLL gating control must be off while
424 * the default value is 1.
426 static void alc_fix_pll(struct hda_codec *codec)
428 struct alc_spec *spec = codec->spec;
433 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
435 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
436 AC_VERB_GET_PROC_COEF, 0);
437 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
439 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
440 val & ~(1 << spec->pll_coef_bit));
443 static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
444 unsigned int coef_idx, unsigned int coef_bit)
446 struct alc_spec *spec = codec->spec;
448 spec->pll_coef_idx = coef_idx;
449 spec->pll_coef_bit = coef_bit;
454 * Jack-reporting via input-jack layer
457 /* initialization of jacks; currently checks only a few known pins */
458 static int alc_init_jacks(struct hda_codec *codec)
460 #ifdef CONFIG_SND_HDA_INPUT_JACK
461 struct alc_spec *spec = codec->spec;
463 unsigned int hp_nid = spec->autocfg.hp_pins[0];
464 unsigned int mic_nid = spec->ext_mic_pin;
465 unsigned int dock_nid = spec->dock_mic_pin;
468 err = snd_hda_input_jack_add(codec, hp_nid,
469 SND_JACK_HEADPHONE, NULL);
472 snd_hda_input_jack_report(codec, hp_nid);
476 err = snd_hda_input_jack_add(codec, mic_nid,
477 SND_JACK_MICROPHONE, NULL);
480 snd_hda_input_jack_report(codec, mic_nid);
483 err = snd_hda_input_jack_add(codec, dock_nid,
484 SND_JACK_MICROPHONE, NULL);
487 snd_hda_input_jack_report(codec, dock_nid);
489 #endif /* CONFIG_SND_HDA_INPUT_JACK */
494 * Jack detections for HP auto-mute and mic-switch
497 /* check each pin in the given array; returns true if any of them is plugged */
498 static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
502 for (i = 0; i < num_pins; i++) {
503 hda_nid_t nid = pins[i];
506 snd_hda_input_jack_report(codec, nid);
507 present |= snd_hda_jack_detect(codec, nid);
512 /* standard HP/line-out auto-mute helper */
513 static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
514 bool mute, bool hp_out)
516 struct alc_spec *spec = codec->spec;
517 unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0;
518 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
521 for (i = 0; i < num_pins; i++) {
522 hda_nid_t nid = pins[i];
526 switch (spec->automute_mode) {
527 case ALC_AUTOMUTE_PIN:
528 /* don't reset VREF value in case it's controlling
529 * the amp (see alc861_fixup_asus_amp_vref_0f())
531 if (spec->keep_vref_in_automute) {
532 val = snd_hda_codec_read(codec, nid, 0,
533 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
538 snd_hda_codec_write(codec, nid, 0,
539 AC_VERB_SET_PIN_WIDGET_CONTROL,
542 case ALC_AUTOMUTE_AMP:
543 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
544 HDA_AMP_MUTE, mute_bits);
546 case ALC_AUTOMUTE_MIXER:
547 nid = spec->automute_mixer_nid[i];
550 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
551 HDA_AMP_MUTE, mute_bits);
552 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1,
553 HDA_AMP_MUTE, mute_bits);
559 /* Toggle outputs muting */
560 static void update_outputs(struct hda_codec *codec)
562 struct alc_spec *spec = codec->spec;
565 /* Control HP pins/amps depending on master_mute state;
566 * in general, HP pins/amps control should be enabled in all cases,
567 * but currently set only for master_mute, just to be safe
569 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
570 spec->autocfg.hp_pins, spec->master_mute, true);
572 if (!spec->automute_speaker)
575 on = spec->hp_jack_present | spec->line_jack_present;
576 on |= spec->master_mute;
577 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
578 spec->autocfg.speaker_pins, on, false);
580 /* toggle line-out mutes if needed, too */
581 /* if LO is a copy of either HP or Speaker, don't need to handle it */
582 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
583 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
585 if (!spec->automute_lo)
588 on = spec->hp_jack_present;
589 on |= spec->master_mute;
590 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
591 spec->autocfg.line_out_pins, on, false);
594 static void call_update_outputs(struct hda_codec *codec)
596 struct alc_spec *spec = codec->spec;
597 if (spec->automute_hook)
598 spec->automute_hook(codec);
600 update_outputs(codec);
603 /* standard HP-automute helper */
604 static void alc_hp_automute(struct hda_codec *codec)
606 struct alc_spec *spec = codec->spec;
608 spec->hp_jack_present =
609 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
610 spec->autocfg.hp_pins);
611 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
613 call_update_outputs(codec);
616 /* standard line-out-automute helper */
617 static void alc_line_automute(struct hda_codec *codec)
619 struct alc_spec *spec = codec->spec;
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)
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);
657 snd_hda_input_jack_report(codec, pins[spec->ext_mic_idx]);
658 if (spec->dock_mic_idx >= 0)
659 snd_hda_input_jack_report(codec, pins[spec->dock_mic_idx]);
662 /* unsolicited event for HP jack sensing */
663 static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
665 if (codec->vendor_id == 0x10ec0880)
671 alc_hp_automute(codec);
673 case ALC_FRONT_EVENT:
674 alc_line_automute(codec);
677 alc_mic_automute(codec);
682 /* call init functions of standard auto-mute helpers */
683 static void alc_inithook(struct hda_codec *codec)
685 alc_hp_automute(codec);
686 alc_line_automute(codec);
687 alc_mic_automute(codec);
690 /* additional initialization for ALC888 variants */
691 static void alc888_coef_init(struct hda_codec *codec)
695 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
696 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
697 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
698 if ((tmp & 0xf0) == 0x20)
700 snd_hda_codec_read(codec, 0x20, 0,
701 AC_VERB_SET_PROC_COEF, 0x830);
704 snd_hda_codec_read(codec, 0x20, 0,
705 AC_VERB_SET_PROC_COEF, 0x3030);
708 /* additional initialization for ALC889 variants */
709 static void alc889_coef_init(struct hda_codec *codec)
713 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
714 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
715 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
716 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
719 /* turn on/off EAPD control (only if available) */
720 static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
722 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
724 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
725 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
729 /* turn on/off EAPD controls of the codec */
730 static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
732 /* We currently only handle front, HP */
733 static hda_nid_t pins[] = {
734 0x0f, 0x10, 0x14, 0x15, 0
737 for (p = pins; *p; p++)
738 set_eapd(codec, *p, on);
741 /* generic shutup callback;
742 * just turning off EPAD and a little pause for avoiding pop-noise
744 static void alc_eapd_shutup(struct hda_codec *codec)
746 alc_auto_setup_eapd(codec, false);
750 /* generic EAPD initialization */
751 static void alc_auto_init_amp(struct hda_codec *codec, int type)
755 alc_auto_setup_eapd(codec, true);
758 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
761 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
764 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
766 case ALC_INIT_DEFAULT:
767 switch (codec->vendor_id) {
769 snd_hda_codec_write(codec, 0x1a, 0,
770 AC_VERB_SET_COEF_INDEX, 7);
771 tmp = snd_hda_codec_read(codec, 0x1a, 0,
772 AC_VERB_GET_PROC_COEF, 0);
773 snd_hda_codec_write(codec, 0x1a, 0,
774 AC_VERB_SET_COEF_INDEX, 7);
775 snd_hda_codec_write(codec, 0x1a, 0,
776 AC_VERB_SET_PROC_COEF,
785 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
786 alc889_coef_init(codec);
789 alc888_coef_init(codec);
791 #if 0 /* XXX: This may cause the silent output on speaker on some machines */
794 snd_hda_codec_write(codec, 0x20, 0,
795 AC_VERB_SET_COEF_INDEX, 7);
796 tmp = snd_hda_codec_read(codec, 0x20, 0,
797 AC_VERB_GET_PROC_COEF, 0);
798 snd_hda_codec_write(codec, 0x20, 0,
799 AC_VERB_SET_COEF_INDEX, 7);
800 snd_hda_codec_write(codec, 0x20, 0,
801 AC_VERB_SET_PROC_COEF,
811 * Auto-Mute mode mixer enum support
813 static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
814 struct snd_ctl_elem_info *uinfo)
816 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
817 struct alc_spec *spec = codec->spec;
818 static const char * const texts2[] = {
819 "Disabled", "Enabled"
821 static const char * const texts3[] = {
822 "Disabled", "Speaker Only", "Line-Out+Speaker"
824 const char * const *texts;
826 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
828 if (spec->automute_speaker_possible && spec->automute_lo_possible) {
829 uinfo->value.enumerated.items = 3;
832 uinfo->value.enumerated.items = 2;
835 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
836 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
837 strcpy(uinfo->value.enumerated.name,
838 texts[uinfo->value.enumerated.item]);
842 static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
843 struct snd_ctl_elem_value *ucontrol)
845 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
846 struct alc_spec *spec = codec->spec;
847 unsigned int val = 0;
848 if (spec->automute_speaker)
850 if (spec->automute_lo)
853 ucontrol->value.enumerated.item[0] = val;
857 static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
858 struct snd_ctl_elem_value *ucontrol)
860 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
861 struct alc_spec *spec = codec->spec;
863 switch (ucontrol->value.enumerated.item[0]) {
865 if (!spec->automute_speaker && !spec->automute_lo)
867 spec->automute_speaker = 0;
868 spec->automute_lo = 0;
871 if (spec->automute_speaker_possible) {
872 if (!spec->automute_lo && spec->automute_speaker)
874 spec->automute_speaker = 1;
875 spec->automute_lo = 0;
876 } else if (spec->automute_lo_possible) {
877 if (spec->automute_lo)
879 spec->automute_lo = 1;
884 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
886 if (spec->automute_speaker && spec->automute_lo)
888 spec->automute_speaker = 1;
889 spec->automute_lo = 1;
894 call_update_outputs(codec);
898 static const struct snd_kcontrol_new alc_automute_mode_enum = {
899 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
900 .name = "Auto-Mute Mode",
901 .info = alc_automute_mode_info,
902 .get = alc_automute_mode_get,
903 .put = alc_automute_mode_put,
906 static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec)
908 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
909 return snd_array_new(&spec->kctls);
912 static int alc_add_automute_mode_enum(struct hda_codec *codec)
914 struct alc_spec *spec = codec->spec;
915 struct snd_kcontrol_new *knew;
917 knew = alc_kcontrol_new(spec);
920 *knew = alc_automute_mode_enum;
921 knew->name = kstrdup("Auto-Mute Mode", GFP_KERNEL);
928 * Check the availability of HP/line-out auto-mute;
929 * Set up appropriately if really supported
931 static void alc_init_automute(struct hda_codec *codec)
933 struct alc_spec *spec = codec->spec;
934 struct auto_pin_cfg *cfg = &spec->autocfg;
940 if (cfg->line_out_pins[0])
942 if (cfg->speaker_pins[0])
944 if (present < 2) /* need two different output types */
947 if (!cfg->speaker_pins[0] &&
948 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
949 memcpy(cfg->speaker_pins, cfg->line_out_pins,
950 sizeof(cfg->speaker_pins));
951 cfg->speaker_outs = cfg->line_outs;
954 if (!cfg->hp_pins[0] &&
955 cfg->line_out_type == AUTO_PIN_HP_OUT) {
956 memcpy(cfg->hp_pins, cfg->line_out_pins,
957 sizeof(cfg->hp_pins));
958 cfg->hp_outs = cfg->line_outs;
961 spec->automute_mode = ALC_AUTOMUTE_PIN;
963 for (i = 0; i < cfg->hp_outs; i++) {
964 hda_nid_t nid = cfg->hp_pins[i];
965 if (!is_jack_detectable(codec, nid))
967 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
969 snd_hda_codec_write_cache(codec, nid, 0,
970 AC_VERB_SET_UNSOLICITED_ENABLE,
971 AC_USRSP_EN | ALC_HP_EVENT);
975 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
976 if (cfg->speaker_outs)
977 for (i = 0; i < cfg->line_outs; i++) {
978 hda_nid_t nid = cfg->line_out_pins[i];
979 if (!is_jack_detectable(codec, nid))
981 snd_printdd("realtek: Enable Line-Out "
982 "auto-muting on NID 0x%x\n", nid);
983 snd_hda_codec_write_cache(codec, nid, 0,
984 AC_VERB_SET_UNSOLICITED_ENABLE,
985 AC_USRSP_EN | ALC_FRONT_EVENT);
988 spec->automute_lo_possible = spec->detect_hp;
991 spec->automute_speaker_possible = cfg->speaker_outs &&
992 (spec->detect_hp || spec->detect_lo);
994 spec->automute_lo = spec->automute_lo_possible;
995 spec->automute_speaker = spec->automute_speaker_possible;
997 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
998 /* create a control for automute mode */
999 alc_add_automute_mode_enum(codec);
1000 spec->unsol_event = alc_sku_unsol_event;
1004 /* return the position of NID in the list, or -1 if not found */
1005 static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1008 for (i = 0; i < nums; i++)
1014 /* check whether dynamic ADC-switching is available */
1015 static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
1017 struct alc_spec *spec = codec->spec;
1018 struct hda_input_mux *imux = &spec->private_imux[0];
1022 if (imux != spec->input_mux) /* no dynamic imux? */
1025 for (n = 0; n < spec->num_adc_nids; n++) {
1026 cap = spec->private_capsrc_nids[n];
1027 for (i = 0; i < imux->num_items; i++) {
1028 pin = spec->imux_pins[i];
1031 if (get_connection_index(codec, cap, pin) < 0)
1034 if (i >= imux->num_items)
1035 return true; /* no ADC-switch is needed */
1038 for (i = 0; i < imux->num_items; i++) {
1039 pin = spec->imux_pins[i];
1040 for (n = 0; n < spec->num_adc_nids; n++) {
1041 cap = spec->private_capsrc_nids[n];
1042 idx = get_connection_index(codec, cap, pin);
1044 imux->items[i].index = idx;
1045 spec->dyn_adc_idx[i] = n;
1051 snd_printdd("realtek: enabling ADC switching\n");
1052 spec->dyn_adc_switch = 1;
1056 /* rebuild imux for matching with the given auto-mic pins (if not yet) */
1057 static bool alc_rebuild_imux_for_auto_mic(struct hda_codec *codec)
1059 struct alc_spec *spec = codec->spec;
1060 struct hda_input_mux *imux;
1061 static char * const texts[3] = {
1062 "Mic", "Internal Mic", "Dock Mic"
1066 if (!spec->auto_mic)
1068 imux = &spec->private_imux[0];
1069 if (spec->input_mux == imux)
1071 spec->imux_pins[0] = spec->ext_mic_pin;
1072 spec->imux_pins[1] = spec->int_mic_pin;
1073 spec->imux_pins[2] = spec->dock_mic_pin;
1074 for (i = 0; i < 3; i++) {
1075 strcpy(imux->items[i].label, texts[i]);
1076 if (spec->imux_pins[i]) {
1077 hda_nid_t pin = spec->imux_pins[i];
1079 for (c = 0; c < spec->num_adc_nids; c++) {
1080 hda_nid_t cap = get_capsrc(spec, c);
1081 int idx = get_connection_index(codec, cap, pin);
1083 imux->items[i].index = idx;
1087 imux->num_items = i + 1;
1090 spec->num_mux_defs = 1;
1091 spec->input_mux = imux;
1095 /* check whether all auto-mic pins are valid; setup indices if OK */
1096 static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1098 struct alc_spec *spec = codec->spec;
1099 const struct hda_input_mux *imux;
1101 if (!spec->auto_mic)
1103 if (spec->auto_mic_valid_imux)
1104 return true; /* already checked */
1106 /* fill up imux indices */
1107 if (!alc_check_dyn_adc_switch(codec)) {
1112 imux = spec->input_mux;
1113 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1114 spec->imux_pins, imux->num_items);
1115 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1116 spec->imux_pins, imux->num_items);
1117 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1118 spec->imux_pins, imux->num_items);
1119 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1121 return false; /* no corresponding imux */
1124 snd_hda_codec_write_cache(codec, spec->ext_mic_pin, 0,
1125 AC_VERB_SET_UNSOLICITED_ENABLE,
1126 AC_USRSP_EN | ALC_MIC_EVENT);
1127 if (spec->dock_mic_pin)
1128 snd_hda_codec_write_cache(codec, spec->dock_mic_pin, 0,
1129 AC_VERB_SET_UNSOLICITED_ENABLE,
1130 AC_USRSP_EN | ALC_MIC_EVENT);
1132 spec->auto_mic_valid_imux = 1;
1138 * Check the availability of auto-mic switch;
1139 * Set up if really supported
1141 static void alc_init_auto_mic(struct hda_codec *codec)
1143 struct alc_spec *spec = codec->spec;
1144 struct auto_pin_cfg *cfg = &spec->autocfg;
1145 hda_nid_t fixed, ext, dock;
1148 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1150 fixed = ext = dock = 0;
1151 for (i = 0; i < cfg->num_inputs; i++) {
1152 hda_nid_t nid = cfg->inputs[i].pin;
1153 unsigned int defcfg;
1154 defcfg = snd_hda_codec_get_pincfg(codec, nid);
1155 switch (snd_hda_get_input_pin_attr(defcfg)) {
1156 case INPUT_PIN_ATTR_INT:
1158 return; /* already occupied */
1159 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1160 return; /* invalid type */
1163 case INPUT_PIN_ATTR_UNUSED:
1164 return; /* invalid entry */
1165 case INPUT_PIN_ATTR_DOCK:
1167 return; /* already occupied */
1168 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1169 return; /* invalid type */
1174 return; /* already occupied */
1175 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1176 return; /* invalid type */
1187 if (!is_jack_detectable(codec, ext))
1188 return; /* no unsol support */
1189 if (dock && !is_jack_detectable(codec, dock))
1190 return; /* no unsol support */
1192 /* check imux indices */
1193 spec->ext_mic_pin = ext;
1194 spec->int_mic_pin = fixed;
1195 spec->dock_mic_pin = dock;
1198 if (!alc_auto_mic_check_imux(codec))
1201 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1203 spec->unsol_event = alc_sku_unsol_event;
1206 /* check the availabilities of auto-mute and auto-mic switches */
1207 static void alc_auto_check_switches(struct hda_codec *codec)
1209 alc_init_automute(codec);
1210 alc_init_auto_mic(codec);
1214 * Realtek SSID verification
1217 /* Could be any non-zero and even value. When used as fixup, tells
1218 * the driver to ignore any present sku defines.
1220 #define ALC_FIXUP_SKU_IGNORE (2)
1222 static int alc_auto_parse_customize_define(struct hda_codec *codec)
1224 unsigned int ass, tmp, i;
1226 struct alc_spec *spec = codec->spec;
1228 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1230 if (spec->cdefine.fixup) {
1231 ass = spec->cdefine.sku_cfg;
1232 if (ass == ALC_FIXUP_SKU_IGNORE)
1237 ass = codec->subsystem_id & 0xffff;
1238 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
1242 if (codec->vendor_id == 0x10ec0260)
1244 ass = snd_hda_codec_get_pincfg(codec, nid);
1247 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1248 codec->chip_name, ass);
1254 for (i = 1; i < 16; i++) {
1258 if (((ass >> 16) & 0xf) != tmp)
1261 spec->cdefine.port_connectivity = ass >> 30;
1262 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1263 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1264 spec->cdefine.customization = ass >> 8;
1266 spec->cdefine.sku_cfg = ass;
1267 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1268 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1269 spec->cdefine.swap = (ass & 0x2) >> 1;
1270 spec->cdefine.override = ass & 0x1;
1272 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1273 nid, spec->cdefine.sku_cfg);
1274 snd_printd("SKU: port_connectivity=0x%x\n",
1275 spec->cdefine.port_connectivity);
1276 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1277 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1278 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1279 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1280 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1281 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1282 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1287 /* return true if the given NID is found in the list */
1288 static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1290 return find_idx_in_nid_list(nid, list, nums) >= 0;
1293 /* check subsystem ID and set up device-specific initialization;
1294 * return 1 if initialized, 0 if invalid SSID
1296 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1297 * 31 ~ 16 : Manufacture ID
1299 * 7 ~ 0 : Assembly ID
1300 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1302 static int alc_subsystem_id(struct hda_codec *codec,
1303 hda_nid_t porta, hda_nid_t porte,
1304 hda_nid_t portd, hda_nid_t porti)
1306 unsigned int ass, tmp, i;
1308 struct alc_spec *spec = codec->spec;
1310 if (spec->cdefine.fixup) {
1311 ass = spec->cdefine.sku_cfg;
1312 if (ass == ALC_FIXUP_SKU_IGNORE)
1317 ass = codec->subsystem_id & 0xffff;
1318 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1321 /* invalid SSID, check the special NID pin defcfg instead */
1323 * 31~30 : port connectivity
1326 * 19~16 : Check sum (15:1)
1331 if (codec->vendor_id == 0x10ec0260)
1333 ass = snd_hda_codec_get_pincfg(codec, nid);
1334 snd_printd("realtek: No valid SSID, "
1335 "checking pincfg 0x%08x for NID 0x%x\n",
1339 if ((ass >> 30) != 1) /* no physical connection */
1344 for (i = 1; i < 16; i++) {
1348 if (((ass >> 16) & 0xf) != tmp)
1351 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1352 ass & 0xffff, codec->vendor_id);
1356 * 2 : 0 --> Desktop, 1 --> Laptop
1357 * 3~5 : External Amplifier control
1360 tmp = (ass & 0x38) >> 3; /* external Amp control */
1363 spec->init_amp = ALC_INIT_GPIO1;
1366 spec->init_amp = ALC_INIT_GPIO2;
1369 spec->init_amp = ALC_INIT_GPIO3;
1373 spec->init_amp = ALC_INIT_DEFAULT;
1377 /* is laptop or Desktop and enable the function "Mute internal speaker
1378 * when the external headphone out jack is plugged"
1380 if (!(ass & 0x8000))
1383 * 10~8 : Jack location
1384 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1386 * 15 : 1 --> enable the function "Mute internal speaker
1387 * when the external headphone out jack is plugged"
1389 if (!spec->autocfg.hp_pins[0] &&
1390 !(spec->autocfg.line_out_pins[0] &&
1391 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
1393 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1404 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1405 spec->autocfg.line_outs))
1407 spec->autocfg.hp_pins[0] = nid;
1412 /* Check the validity of ALC subsystem-id
1413 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1414 static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
1416 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
1417 struct alc_spec *spec = codec->spec;
1418 snd_printd("realtek: "
1419 "Enable default setup for auto mode as fallback\n");
1420 spec->init_amp = ALC_INIT_DEFAULT;
1425 * Fix-up pin default configurations and add default verbs
1433 struct alc_model_fixup {
1444 const struct alc_pincfg *pins;
1445 const struct hda_verb *verbs;
1446 void (*func)(struct hda_codec *codec,
1447 const struct alc_fixup *fix,
1461 ALC_FIXUP_ACT_PRE_PROBE,
1462 ALC_FIXUP_ACT_PROBE,
1466 static void alc_apply_fixup(struct hda_codec *codec, int action)
1468 struct alc_spec *spec = codec->spec;
1469 int id = spec->fixup_id;
1470 #ifdef CONFIG_SND_DEBUG_VERBOSE
1471 const char *modelname = spec->fixup_name;
1475 if (!spec->fixup_list)
1479 const struct alc_fixup *fix = spec->fixup_list + id;
1480 const struct alc_pincfg *cfg;
1482 switch (fix->type) {
1484 if (action != ALC_FIXUP_ACT_PRE_PROBE || !fix->v.sku)
1486 snd_printdd(KERN_INFO "hda_codec: %s: "
1487 "Apply sku override for %s\n",
1488 codec->chip_name, modelname);
1489 spec->cdefine.sku_cfg = fix->v.sku;
1490 spec->cdefine.fixup = 1;
1492 case ALC_FIXUP_PINS:
1494 if (action != ALC_FIXUP_ACT_PRE_PROBE || !cfg)
1496 snd_printdd(KERN_INFO "hda_codec: %s: "
1497 "Apply pincfg for %s\n",
1498 codec->chip_name, modelname);
1499 for (; cfg->nid; cfg++)
1500 snd_hda_codec_set_pincfg(codec, cfg->nid,
1503 case ALC_FIXUP_VERBS:
1504 if (action != ALC_FIXUP_ACT_PROBE || !fix->v.verbs)
1506 snd_printdd(KERN_INFO "hda_codec: %s: "
1507 "Apply fix-verbs for %s\n",
1508 codec->chip_name, modelname);
1509 add_verb(codec->spec, fix->v.verbs);
1511 case ALC_FIXUP_FUNC:
1514 snd_printdd(KERN_INFO "hda_codec: %s: "
1515 "Apply fix-func for %s\n",
1516 codec->chip_name, modelname);
1517 fix->v.func(codec, fix, action);
1520 snd_printk(KERN_ERR "hda_codec: %s: "
1521 "Invalid fixup type %d\n",
1522 codec->chip_name, fix->type);
1533 static void alc_pick_fixup(struct hda_codec *codec,
1534 const struct alc_model_fixup *models,
1535 const struct snd_pci_quirk *quirk,
1536 const struct alc_fixup *fixlist)
1538 struct alc_spec *spec = codec->spec;
1540 const char *name = NULL;
1542 if (codec->modelname && models) {
1543 while (models->name) {
1544 if (!strcmp(codec->modelname, models->name)) {
1546 name = models->name;
1553 quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1556 #ifdef CONFIG_SND_DEBUG_VERBOSE
1562 spec->fixup_id = id;
1564 spec->fixup_list = fixlist;
1565 spec->fixup_name = name;
1570 * COEF access helper functions
1572 static int alc_read_coef_idx(struct hda_codec *codec,
1573 unsigned int coef_idx)
1576 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1578 val = snd_hda_codec_read(codec, 0x20, 0,
1579 AC_VERB_GET_PROC_COEF, 0);
1583 static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1584 unsigned int coef_val)
1586 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1588 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1592 /* a special bypass for COEF 0; read the cached value at the second time */
1593 static unsigned int alc_get_coef0(struct hda_codec *codec)
1595 struct alc_spec *spec = codec->spec;
1597 spec->coef0 = alc_read_coef_idx(codec, 0);
1602 * Digital I/O handling
1605 /* set right pin controls for digital I/O */
1606 static void alc_auto_init_digital(struct hda_codec *codec)
1608 struct alc_spec *spec = codec->spec;
1612 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1613 pin = spec->autocfg.dig_out_pins[i];
1616 snd_hda_codec_write(codec, pin, 0,
1617 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
1619 dac = spec->multiout.dig_out_nid;
1621 dac = spec->slave_dig_outs[i - 1];
1622 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
1624 snd_hda_codec_write(codec, dac, 0,
1625 AC_VERB_SET_AMP_GAIN_MUTE,
1628 pin = spec->autocfg.dig_in_pin;
1630 snd_hda_codec_write(codec, pin, 0,
1631 AC_VERB_SET_PIN_WIDGET_CONTROL,
1635 /* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1636 static void alc_auto_parse_digital(struct hda_codec *codec)
1638 struct alc_spec *spec = codec->spec;
1642 /* support multiple SPDIFs; the secondary is set up as a slave */
1644 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1646 err = snd_hda_get_connections(codec,
1647 spec->autocfg.dig_out_pins[i],
1648 conn, ARRAY_SIZE(conn));
1651 dig_nid = conn[0]; /* assume the first element is audio-out */
1653 spec->multiout.dig_out_nid = dig_nid;
1654 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1656 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
1657 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
1659 spec->slave_dig_outs[nums - 1] = dig_nid;
1664 if (spec->autocfg.dig_in_pin) {
1665 dig_nid = codec->start_nid;
1666 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1667 unsigned int wcaps = get_wcaps(codec, dig_nid);
1668 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1670 if (!(wcaps & AC_WCAP_DIGITAL))
1672 if (!(wcaps & AC_WCAP_CONN_LIST))
1674 err = get_connection_index(codec, dig_nid,
1675 spec->autocfg.dig_in_pin);
1677 spec->dig_in_nid = dig_nid;
1685 * capture mixer elements
1687 static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1688 struct snd_ctl_elem_info *uinfo)
1690 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1691 struct alc_spec *spec = codec->spec;
1695 mutex_lock(&codec->control_mutex);
1696 if (spec->vol_in_capsrc)
1697 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1699 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1700 kcontrol->private_value = val;
1701 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
1702 mutex_unlock(&codec->control_mutex);
1706 static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1707 unsigned int size, unsigned int __user *tlv)
1709 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1710 struct alc_spec *spec = codec->spec;
1714 mutex_lock(&codec->control_mutex);
1715 if (spec->vol_in_capsrc)
1716 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1718 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1719 kcontrol->private_value = val;
1720 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
1721 mutex_unlock(&codec->control_mutex);
1725 typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1726 struct snd_ctl_elem_value *ucontrol);
1728 static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1729 struct snd_ctl_elem_value *ucontrol,
1730 getput_call_t func, bool check_adc_switch)
1732 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1733 struct alc_spec *spec = codec->spec;
1736 mutex_lock(&codec->control_mutex);
1737 if (check_adc_switch && spec->dyn_adc_switch) {
1738 for (i = 0; i < spec->num_adc_nids; i++) {
1739 kcontrol->private_value =
1740 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1742 err = func(kcontrol, ucontrol);
1747 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1748 if (spec->vol_in_capsrc)
1749 kcontrol->private_value =
1750 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1753 kcontrol->private_value =
1754 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1756 err = func(kcontrol, ucontrol);
1759 mutex_unlock(&codec->control_mutex);
1763 static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1764 struct snd_ctl_elem_value *ucontrol)
1766 return alc_cap_getput_caller(kcontrol, ucontrol,
1767 snd_hda_mixer_amp_volume_get, false);
1770 static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1771 struct snd_ctl_elem_value *ucontrol)
1773 return alc_cap_getput_caller(kcontrol, ucontrol,
1774 snd_hda_mixer_amp_volume_put, true);
1777 /* capture mixer elements */
1778 #define alc_cap_sw_info snd_ctl_boolean_stereo_info
1780 static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1781 struct snd_ctl_elem_value *ucontrol)
1783 return alc_cap_getput_caller(kcontrol, ucontrol,
1784 snd_hda_mixer_amp_switch_get, false);
1787 static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1788 struct snd_ctl_elem_value *ucontrol)
1790 return alc_cap_getput_caller(kcontrol, ucontrol,
1791 snd_hda_mixer_amp_switch_put, true);
1794 #define _DEFINE_CAPMIX(num) \
1796 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1797 .name = "Capture Switch", \
1798 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1800 .info = alc_cap_sw_info, \
1801 .get = alc_cap_sw_get, \
1802 .put = alc_cap_sw_put, \
1805 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1806 .name = "Capture Volume", \
1807 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1808 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1809 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1811 .info = alc_cap_vol_info, \
1812 .get = alc_cap_vol_get, \
1813 .put = alc_cap_vol_put, \
1814 .tlv = { .c = alc_cap_vol_tlv }, \
1817 #define _DEFINE_CAPSRC(num) \
1819 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1820 /* .name = "Capture Source", */ \
1821 .name = "Input Source", \
1823 .info = alc_mux_enum_info, \
1824 .get = alc_mux_enum_get, \
1825 .put = alc_mux_enum_put, \
1828 #define DEFINE_CAPMIX(num) \
1829 static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
1830 _DEFINE_CAPMIX(num), \
1831 _DEFINE_CAPSRC(num), \
1835 #define DEFINE_CAPMIX_NOSRC(num) \
1836 static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
1837 _DEFINE_CAPMIX(num), \
1841 /* up to three ADCs */
1845 DEFINE_CAPMIX_NOSRC(1);
1846 DEFINE_CAPMIX_NOSRC(2);
1847 DEFINE_CAPMIX_NOSRC(3);
1850 * virtual master controls
1854 * slave controls for virtual master
1856 static const char * const alc_slave_vols[] = {
1857 "Front Playback Volume",
1858 "Surround Playback Volume",
1859 "Center Playback Volume",
1860 "LFE Playback Volume",
1861 "Side Playback Volume",
1862 "Headphone Playback Volume",
1863 "Speaker Playback Volume",
1864 "Mono Playback Volume",
1865 "Line-Out Playback Volume",
1866 "PCM Playback Volume",
1870 static const char * const alc_slave_sws[] = {
1871 "Front Playback Switch",
1872 "Surround Playback Switch",
1873 "Center Playback Switch",
1874 "LFE Playback Switch",
1875 "Side Playback Switch",
1876 "Headphone Playback Switch",
1877 "Speaker Playback Switch",
1878 "Mono Playback Switch",
1879 "IEC958 Playback Switch",
1880 "Line-Out Playback Switch",
1881 "PCM Playback Switch",
1886 * build control elements
1889 #define NID_MAPPING (-1)
1891 #define SUBDEV_SPEAKER_ (0 << 6)
1892 #define SUBDEV_HP_ (1 << 6)
1893 #define SUBDEV_LINE_ (2 << 6)
1894 #define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1895 #define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1896 #define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1898 static void alc_free_kctls(struct hda_codec *codec);
1900 #ifdef CONFIG_SND_HDA_INPUT_BEEP
1901 /* additional beep mixers; the actual parameters are overwritten at build */
1902 static const struct snd_kcontrol_new alc_beep_mixer[] = {
1903 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
1904 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
1909 static int alc_build_controls(struct hda_codec *codec)
1911 struct alc_spec *spec = codec->spec;
1912 struct snd_kcontrol *kctl = NULL;
1913 const struct snd_kcontrol_new *knew;
1918 for (i = 0; i < spec->num_mixers; i++) {
1919 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1923 if (spec->cap_mixer) {
1924 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1928 if (spec->multiout.dig_out_nid) {
1929 err = snd_hda_create_spdif_out_ctls(codec,
1930 spec->multiout.dig_out_nid,
1931 spec->multiout.dig_out_nid);
1934 if (!spec->no_analog) {
1935 err = snd_hda_create_spdif_share_sw(codec,
1939 spec->multiout.share_spdif = 1;
1942 if (spec->dig_in_nid) {
1943 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1948 #ifdef CONFIG_SND_HDA_INPUT_BEEP
1949 /* create beep controls if needed */
1950 if (spec->beep_amp) {
1951 const struct snd_kcontrol_new *knew;
1952 for (knew = alc_beep_mixer; knew->name; knew++) {
1953 struct snd_kcontrol *kctl;
1954 kctl = snd_ctl_new1(knew, codec);
1957 kctl->private_value = spec->beep_amp;
1958 err = snd_hda_ctl_add(codec, 0, kctl);
1965 /* if we have no master control, let's create it */
1966 if (!spec->no_analog &&
1967 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1968 unsigned int vmaster_tlv[4];
1969 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
1970 HDA_OUTPUT, vmaster_tlv);
1971 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1972 vmaster_tlv, alc_slave_vols);
1976 if (!spec->no_analog &&
1977 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1978 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1979 NULL, alc_slave_sws);
1984 /* assign Capture Source enums to NID */
1985 if (spec->capsrc_nids || spec->adc_nids) {
1986 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
1988 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1989 for (i = 0; kctl && i < kctl->count; i++) {
1990 err = snd_hda_add_nid(codec, kctl, i,
1991 get_capsrc(spec, i));
1996 if (spec->cap_mixer && spec->adc_nids) {
1997 const char *kname = kctl ? kctl->id.name : NULL;
1998 for (knew = spec->cap_mixer; knew->name; knew++) {
1999 if (kname && strcmp(knew->name, kname) == 0)
2001 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
2002 for (i = 0; kctl && i < kctl->count; i++) {
2003 err = snd_hda_add_nid(codec, kctl, i,
2011 /* other nid->control mapping */
2012 for (i = 0; i < spec->num_mixers; i++) {
2013 for (knew = spec->mixers[i]; knew->name; knew++) {
2014 if (knew->iface != NID_MAPPING)
2016 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
2019 u = knew->subdevice;
2020 for (j = 0; j < 4; j++, u >>= 8) {
2025 case SUBDEV_SPEAKER_:
2026 nid = spec->autocfg.speaker_pins[nid];
2029 nid = spec->autocfg.line_out_pins[nid];
2032 nid = spec->autocfg.hp_pins[nid];
2037 err = snd_hda_add_nid(codec, kctl, 0, nid);
2041 u = knew->private_value;
2042 for (j = 0; j < 4; j++, u >>= 8) {
2046 err = snd_hda_add_nid(codec, kctl, 0, nid);
2053 alc_free_kctls(codec); /* no longer needed */
2063 static void alc_init_special_input_src(struct hda_codec *codec);
2065 static int alc_init(struct hda_codec *codec)
2067 struct alc_spec *spec = codec->spec;
2071 alc_auto_init_amp(codec, spec->init_amp);
2073 for (i = 0; i < spec->num_init_verbs; i++)
2074 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2075 alc_init_special_input_src(codec);
2077 if (spec->init_hook)
2078 spec->init_hook(codec);
2080 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2082 hda_call_check_power_status(codec, 0x01);
2086 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2088 struct alc_spec *spec = codec->spec;
2090 if (spec->unsol_event)
2091 spec->unsol_event(codec, res);
2094 #ifdef CONFIG_SND_HDA_POWER_SAVE
2095 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2097 struct alc_spec *spec = codec->spec;
2098 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2103 * Analog playback callbacks
2105 static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
2106 struct hda_codec *codec,
2107 struct snd_pcm_substream *substream)
2109 struct alc_spec *spec = codec->spec;
2110 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2114 static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2115 struct hda_codec *codec,
2116 unsigned int stream_tag,
2117 unsigned int format,
2118 struct snd_pcm_substream *substream)
2120 struct alc_spec *spec = codec->spec;
2121 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2122 stream_tag, format, substream);
2125 static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2126 struct hda_codec *codec,
2127 struct snd_pcm_substream *substream)
2129 struct alc_spec *spec = codec->spec;
2130 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2136 static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2137 struct hda_codec *codec,
2138 struct snd_pcm_substream *substream)
2140 struct alc_spec *spec = codec->spec;
2141 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2144 static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2145 struct hda_codec *codec,
2146 unsigned int stream_tag,
2147 unsigned int format,
2148 struct snd_pcm_substream *substream)
2150 struct alc_spec *spec = codec->spec;
2151 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2152 stream_tag, format, substream);
2155 static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2156 struct hda_codec *codec,
2157 struct snd_pcm_substream *substream)
2159 struct alc_spec *spec = codec->spec;
2160 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2163 static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2164 struct hda_codec *codec,
2165 struct snd_pcm_substream *substream)
2167 struct alc_spec *spec = codec->spec;
2168 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2174 static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2175 struct hda_codec *codec,
2176 unsigned int stream_tag,
2177 unsigned int format,
2178 struct snd_pcm_substream *substream)
2180 struct alc_spec *spec = codec->spec;
2182 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
2183 stream_tag, 0, format);
2187 static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2188 struct hda_codec *codec,
2189 struct snd_pcm_substream *substream)
2191 struct alc_spec *spec = codec->spec;
2193 snd_hda_codec_cleanup_stream(codec,
2194 spec->adc_nids[substream->number + 1]);
2198 /* analog capture with dynamic dual-adc changes */
2199 static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2200 struct hda_codec *codec,
2201 unsigned int stream_tag,
2202 unsigned int format,
2203 struct snd_pcm_substream *substream)
2205 struct alc_spec *spec = codec->spec;
2206 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
2207 spec->cur_adc_stream_tag = stream_tag;
2208 spec->cur_adc_format = format;
2209 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2213 static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2214 struct hda_codec *codec,
2215 struct snd_pcm_substream *substream)
2217 struct alc_spec *spec = codec->spec;
2218 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2223 static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
2227 .nid = 0, /* fill later */
2229 .prepare = dyn_adc_capture_pcm_prepare,
2230 .cleanup = dyn_adc_capture_pcm_cleanup
2236 static const struct hda_pcm_stream alc_pcm_analog_playback = {
2240 /* NID is set in alc_build_pcms */
2242 .open = alc_playback_pcm_open,
2243 .prepare = alc_playback_pcm_prepare,
2244 .cleanup = alc_playback_pcm_cleanup
2248 static const struct hda_pcm_stream alc_pcm_analog_capture = {
2252 /* NID is set in alc_build_pcms */
2255 static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
2259 /* NID is set in alc_build_pcms */
2262 static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
2263 .substreams = 2, /* can be overridden */
2266 /* NID is set in alc_build_pcms */
2268 .prepare = alc_alt_capture_pcm_prepare,
2269 .cleanup = alc_alt_capture_pcm_cleanup
2273 static const struct hda_pcm_stream alc_pcm_digital_playback = {
2277 /* NID is set in alc_build_pcms */
2279 .open = alc_dig_playback_pcm_open,
2280 .close = alc_dig_playback_pcm_close,
2281 .prepare = alc_dig_playback_pcm_prepare,
2282 .cleanup = alc_dig_playback_pcm_cleanup
2286 static const struct hda_pcm_stream alc_pcm_digital_capture = {
2290 /* NID is set in alc_build_pcms */
2293 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
2294 static const struct hda_pcm_stream alc_pcm_null_stream = {
2300 static int alc_build_pcms(struct hda_codec *codec)
2302 struct alc_spec *spec = codec->spec;
2303 struct hda_pcm *info = spec->pcm_rec;
2304 const struct hda_pcm_stream *p;
2305 bool have_multi_adcs;
2308 codec->num_pcms = 1;
2309 codec->pcm_info = info;
2311 if (spec->no_analog)
2314 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2315 "%s Analog", codec->chip_name);
2316 info->name = spec->stream_name_analog;
2318 if (spec->multiout.dac_nids > 0) {
2319 p = spec->stream_analog_playback;
2321 p = &alc_pcm_analog_playback;
2322 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2323 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2325 if (spec->adc_nids) {
2326 p = spec->stream_analog_capture;
2328 if (spec->dyn_adc_switch)
2329 p = &dyn_adc_pcm_analog_capture;
2331 p = &alc_pcm_analog_capture;
2333 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2334 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2337 if (spec->channel_mode) {
2338 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2339 for (i = 0; i < spec->num_channel_mode; i++) {
2340 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2341 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2347 /* SPDIF for stream index #1 */
2348 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2349 snprintf(spec->stream_name_digital,
2350 sizeof(spec->stream_name_digital),
2351 "%s Digital", codec->chip_name);
2352 codec->num_pcms = 2;
2353 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
2354 info = spec->pcm_rec + 1;
2355 info->name = spec->stream_name_digital;
2356 if (spec->dig_out_type)
2357 info->pcm_type = spec->dig_out_type;
2359 info->pcm_type = HDA_PCM_TYPE_SPDIF;
2360 if (spec->multiout.dig_out_nid) {
2361 p = spec->stream_digital_playback;
2363 p = &alc_pcm_digital_playback;
2364 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2365 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2367 if (spec->dig_in_nid) {
2368 p = spec->stream_digital_capture;
2370 p = &alc_pcm_digital_capture;
2371 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2372 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2374 /* FIXME: do we need this for all Realtek codec models? */
2375 codec->spdif_status_reset = 1;
2378 if (spec->no_analog)
2381 /* If the use of more than one ADC is requested for the current
2382 * model, configure a second analog capture-only PCM.
2384 have_multi_adcs = (spec->num_adc_nids > 1) &&
2385 !spec->dyn_adc_switch && !spec->auto_mic &&
2386 (!spec->input_mux || spec->input_mux->num_items > 1);
2387 /* Additional Analaog capture for index #2 */
2388 if (spec->alt_dac_nid || have_multi_adcs) {
2389 codec->num_pcms = 3;
2390 info = spec->pcm_rec + 2;
2391 info->name = spec->stream_name_analog;
2392 if (spec->alt_dac_nid) {
2393 p = spec->stream_analog_alt_playback;
2395 p = &alc_pcm_analog_alt_playback;
2396 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2397 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2400 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2401 alc_pcm_null_stream;
2402 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2404 if (have_multi_adcs) {
2405 p = spec->stream_analog_alt_capture;
2407 p = &alc_pcm_analog_alt_capture;
2408 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2409 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2411 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2412 spec->num_adc_nids - 1;
2414 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2415 alc_pcm_null_stream;
2416 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
2423 static inline void alc_shutup(struct hda_codec *codec)
2425 struct alc_spec *spec = codec->spec;
2427 if (spec && spec->shutup)
2428 spec->shutup(codec);
2429 snd_hda_shutup_pins(codec);
2432 static void alc_free_kctls(struct hda_codec *codec)
2434 struct alc_spec *spec = codec->spec;
2436 if (spec->kctls.list) {
2437 struct snd_kcontrol_new *kctl = spec->kctls.list;
2439 for (i = 0; i < spec->kctls.used; i++)
2440 kfree(kctl[i].name);
2442 snd_array_free(&spec->kctls);
2445 static void alc_free_bind_ctls(struct hda_codec *codec)
2447 struct alc_spec *spec = codec->spec;
2448 if (spec->bind_ctls.list) {
2449 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2451 for (i = 0; i < spec->bind_ctls.used; i++)
2454 snd_array_free(&spec->bind_ctls);
2457 static void alc_free(struct hda_codec *codec)
2459 struct alc_spec *spec = codec->spec;
2465 snd_hda_input_jack_free(codec);
2466 alc_free_kctls(codec);
2467 alc_free_bind_ctls(codec);
2469 snd_hda_detach_beep_device(codec);
2472 #ifdef CONFIG_SND_HDA_POWER_SAVE
2473 static void alc_power_eapd(struct hda_codec *codec)
2475 alc_auto_setup_eapd(codec, false);
2478 static int alc_suspend(struct hda_codec *codec, pm_message_t state)
2480 struct alc_spec *spec = codec->spec;
2482 if (spec && spec->power_hook)
2483 spec->power_hook(codec);
2489 static int alc_resume(struct hda_codec *codec)
2491 msleep(150); /* to avoid pop noise */
2492 codec->patch_ops.init(codec);
2493 snd_hda_codec_resume_amp(codec);
2494 snd_hda_codec_resume_cache(codec);
2495 hda_call_check_power_status(codec, 0x01);
2502 static const struct hda_codec_ops alc_patch_ops = {
2503 .build_controls = alc_build_controls,
2504 .build_pcms = alc_build_pcms,
2507 .unsol_event = alc_unsol_event,
2509 .resume = alc_resume,
2511 #ifdef CONFIG_SND_HDA_POWER_SAVE
2512 .suspend = alc_suspend,
2513 .check_power_status = alc_check_power_status,
2515 .reboot_notify = alc_shutup,
2518 /* replace the codec chip_name with the given string */
2519 static int alc_codec_rename(struct hda_codec *codec, const char *name)
2521 kfree(codec->chip_name);
2522 codec->chip_name = kstrdup(name, GFP_KERNEL);
2523 if (!codec->chip_name) {
2531 * Rename codecs appropriately from COEF value
2533 struct alc_codec_rename_table {
2534 unsigned int vendor_id;
2535 unsigned short coef_mask;
2536 unsigned short coef_bits;
2540 static struct alc_codec_rename_table rename_tbl[] = {
2541 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2542 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2543 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2544 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2545 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2546 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2547 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
2548 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2549 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2550 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2551 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2552 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2553 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2554 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2555 { } /* terminator */
2558 static int alc_codec_rename_from_preset(struct hda_codec *codec)
2560 const struct alc_codec_rename_table *p;
2562 for (p = rename_tbl; p->vendor_id; p++) {
2563 if (p->vendor_id != codec->vendor_id)
2565 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
2566 return alc_codec_rename(codec, p->name);
2572 * Automatic parse of I/O pins from the BIOS configuration
2577 ALC_CTL_WIDGET_MUTE,
2582 static const struct snd_kcontrol_new alc_control_templates[] = {
2583 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2584 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2585 HDA_BIND_MUTE(NULL, 0, 0, 0),
2586 HDA_BIND_VOL(NULL, 0),
2587 HDA_BIND_SW(NULL, 0),
2590 /* add dynamic controls */
2591 static int add_control(struct alc_spec *spec, int type, const char *name,
2592 int cidx, unsigned long val)
2594 struct snd_kcontrol_new *knew;
2596 knew = alc_kcontrol_new(spec);
2599 *knew = alc_control_templates[type];
2600 knew->name = kstrdup(name, GFP_KERNEL);
2604 if (get_amp_nid_(val))
2605 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
2606 knew->private_value = val;
2610 static int add_control_with_pfx(struct alc_spec *spec, int type,
2611 const char *pfx, const char *dir,
2612 const char *sfx, int cidx, unsigned long val)
2615 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
2616 return add_control(spec, type, name, cidx, val);
2619 #define add_pb_vol_ctrl(spec, type, pfx, val) \
2620 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2621 #define add_pb_sw_ctrl(spec, type, pfx, val) \
2622 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2623 #define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2624 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2625 #define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2626 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
2628 static const char * const channel_name[4] = {
2629 "Front", "Surround", "CLFE", "Side"
2632 static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2633 bool can_be_master, int *index)
2635 struct auto_pin_cfg *cfg = &spec->autocfg;
2638 if (cfg->line_outs == 1 && !spec->multi_ios &&
2639 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
2642 switch (cfg->line_out_type) {
2643 case AUTO_PIN_SPEAKER_OUT:
2644 if (cfg->line_outs == 1)
2646 if (cfg->line_outs == 2)
2647 return ch ? "Bass Speaker" : "Speaker";
2649 case AUTO_PIN_HP_OUT:
2650 /* for multi-io case, only the primary out */
2651 if (ch && spec->multi_ios)
2656 if (cfg->line_outs == 1 && !spec->multi_ios)
2660 if (snd_BUG_ON(ch >= ARRAY_SIZE(channel_name)))
2663 return channel_name[ch];
2666 /* create input playback/capture controls for the given pin */
2667 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
2668 const char *ctlname, int ctlidx,
2669 int idx, hda_nid_t mix_nid)
2673 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
2674 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2677 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
2678 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2684 static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
2686 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2687 return (pincap & AC_PINCAP_IN) != 0;
2690 /* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
2691 static int alc_auto_fill_adc_caps(struct hda_codec *codec)
2693 struct alc_spec *spec = codec->spec;
2695 hda_nid_t *adc_nids = spec->private_adc_nids;
2696 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2697 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
2700 nid = codec->start_nid;
2701 for (i = 0; i < codec->num_nodes; i++, nid++) {
2703 const hda_nid_t *list;
2704 unsigned int caps = get_wcaps(codec, nid);
2705 int type = get_wcaps_type(caps);
2707 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2709 adc_nids[nums] = nid;
2710 cap_nids[nums] = nid;
2714 type = get_wcaps_type(get_wcaps(codec, src));
2715 if (type == AC_WID_PIN)
2717 if (type == AC_WID_AUD_SEL) {
2718 cap_nids[nums] = src;
2721 n = snd_hda_get_conn_list(codec, src, &list);
2723 cap_nids[nums] = src;
2729 if (++nums >= max_nums)
2732 spec->adc_nids = spec->private_adc_nids;
2733 spec->capsrc_nids = spec->private_capsrc_nids;
2734 spec->num_adc_nids = nums;
2738 /* create playback/capture controls for input pins */
2739 static int alc_auto_create_input_ctls(struct hda_codec *codec)
2741 struct alc_spec *spec = codec->spec;
2742 const struct auto_pin_cfg *cfg = &spec->autocfg;
2743 hda_nid_t mixer = spec->mixer_nid;
2744 struct hda_input_mux *imux = &spec->private_imux[0];
2746 int i, c, err, idx, type_idx = 0;
2747 const char *prev_label = NULL;
2749 num_adcs = alc_auto_fill_adc_caps(codec);
2753 for (i = 0; i < cfg->num_inputs; i++) {
2757 pin = cfg->inputs[i].pin;
2758 if (!alc_is_input_pin(codec, pin))
2761 label = hda_get_autocfg_input_label(codec, cfg, i);
2762 if (prev_label && !strcmp(label, prev_label))
2769 idx = get_connection_index(codec, mixer, pin);
2771 err = new_analog_input(spec, pin,
2779 for (c = 0; c < num_adcs; c++) {
2780 hda_nid_t cap = get_capsrc(spec, c);
2781 idx = get_connection_index(codec, cap, pin);
2783 spec->imux_pins[imux->num_items] = pin;
2784 snd_hda_add_imux_item(imux, label, idx, NULL);
2790 spec->num_mux_defs = 1;
2791 spec->input_mux = imux;
2796 static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
2797 unsigned int pin_type)
2799 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2802 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2803 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2807 static int get_pin_type(int line_out_type)
2809 if (line_out_type == AUTO_PIN_HP_OUT)
2815 static void alc_auto_init_analog_input(struct hda_codec *codec)
2817 struct alc_spec *spec = codec->spec;
2818 struct auto_pin_cfg *cfg = &spec->autocfg;
2821 for (i = 0; i < cfg->num_inputs; i++) {
2822 hda_nid_t nid = cfg->inputs[i].pin;
2823 if (alc_is_input_pin(codec, nid)) {
2824 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
2825 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
2826 snd_hda_codec_write(codec, nid, 0,
2827 AC_VERB_SET_AMP_GAIN_MUTE,
2832 /* mute all loopback inputs */
2833 if (spec->mixer_nid) {
2834 int nums = snd_hda_get_conn_list(codec, spec->mixer_nid, NULL);
2835 for (i = 0; i < nums; i++)
2836 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2837 AC_VERB_SET_AMP_GAIN_MUTE,
2842 /* convert from MIX nid to DAC */
2843 static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid)
2848 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT)
2850 num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list));
2851 for (i = 0; i < num; i++) {
2852 if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT)
2858 /* go down to the selector widget before the mixer */
2859 static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin)
2862 int num = snd_hda_get_connections(codec, pin, srcs,
2865 get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL)
2870 /* get MIX nid connected to the given pin targeted to DAC */
2871 static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
2877 pin = alc_go_down_to_selector(codec, pin);
2878 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2879 for (i = 0; i < num; i++) {
2880 if (alc_auto_mix_to_dac(codec, mix[i]) == dac)
2886 /* select the connection from pin to DAC if needed */
2887 static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin,
2893 pin = alc_go_down_to_selector(codec, pin);
2894 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2897 for (i = 0; i < num; i++) {
2898 if (alc_auto_mix_to_dac(codec, mix[i]) == dac) {
2899 snd_hda_codec_update_cache(codec, pin, 0,
2900 AC_VERB_SET_CONNECT_SEL, i);
2907 /* look for an empty DAC slot */
2908 static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
2910 struct alc_spec *spec = codec->spec;
2914 pin = alc_go_down_to_selector(codec, pin);
2915 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
2916 for (i = 0; i < num; i++) {
2917 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
2920 if (found_in_nid_list(nid, spec->multiout.dac_nids,
2921 ARRAY_SIZE(spec->private_dac_nids)))
2923 if (found_in_nid_list(nid, spec->multiout.hp_out_nid,
2924 ARRAY_SIZE(spec->multiout.hp_out_nid)))
2926 if (found_in_nid_list(nid, spec->multiout.extra_out_nid,
2927 ARRAY_SIZE(spec->multiout.extra_out_nid)))
2934 static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
2936 hda_nid_t sel = alc_go_down_to_selector(codec, pin);
2937 if (snd_hda_get_conn_list(codec, sel, NULL) == 1)
2938 return alc_auto_look_for_dac(codec, pin);
2942 /* return 0 if no possible DAC is found, 1 if one or more found */
2943 static int alc_auto_fill_extra_dacs(struct hda_codec *codec, int num_outs,
2944 const hda_nid_t *pins, hda_nid_t *dacs)
2948 if (num_outs && !dacs[0]) {
2949 dacs[0] = alc_auto_look_for_dac(codec, pins[0]);
2954 for (i = 1; i < num_outs; i++)
2955 dacs[i] = get_dac_if_single(codec, pins[i]);
2956 for (i = 1; i < num_outs; i++) {
2958 dacs[i] = alc_auto_look_for_dac(codec, pins[i]);
2963 static int alc_auto_fill_multi_ios(struct hda_codec *codec,
2964 unsigned int location);
2966 /* fill in the dac_nids table from the parsed pin configuration */
2967 static int alc_auto_fill_dac_nids(struct hda_codec *codec)
2969 struct alc_spec *spec = codec->spec;
2970 struct auto_pin_cfg *cfg = &spec->autocfg;
2971 bool redone = false;
2975 /* set num_dacs once to full for alc_auto_look_for_dac() */
2976 spec->multiout.num_dacs = cfg->line_outs;
2977 spec->multiout.hp_out_nid[0] = 0;
2978 spec->multiout.extra_out_nid[0] = 0;
2979 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
2980 spec->multiout.dac_nids = spec->private_dac_nids;
2981 spec->multi_ios = 0;
2983 /* fill hard-wired DACs first */
2985 for (i = 0; i < cfg->line_outs; i++)
2986 spec->private_dac_nids[i] =
2987 get_dac_if_single(codec, cfg->line_out_pins[i]);
2989 spec->multiout.hp_out_nid[0] =
2990 get_dac_if_single(codec, cfg->hp_pins[0]);
2991 if (cfg->speaker_outs)
2992 spec->multiout.extra_out_nid[0] =
2993 get_dac_if_single(codec, cfg->speaker_pins[0]);
2996 for (i = 0; i < cfg->line_outs; i++) {
2997 hda_nid_t pin = cfg->line_out_pins[i];
2998 if (spec->private_dac_nids[i])
3000 spec->private_dac_nids[i] = alc_auto_look_for_dac(codec, pin);
3001 if (!spec->private_dac_nids[i] && !redone) {
3002 /* if we can't find primary DACs, re-probe without
3003 * checking the hard-wired DACs
3010 /* re-count num_dacs and squash invalid entries */
3011 spec->multiout.num_dacs = 0;
3012 for (i = 0; i < cfg->line_outs; i++) {
3013 if (spec->private_dac_nids[i])
3014 spec->multiout.num_dacs++;
3016 memmove(spec->private_dac_nids + i,
3017 spec->private_dac_nids + i + 1,
3018 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
3019 spec->private_dac_nids[cfg->line_outs - 1] = 0;
3023 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3024 /* try to fill multi-io first */
3025 unsigned int location, defcfg;
3028 defcfg = snd_hda_codec_get_pincfg(codec, cfg->line_out_pins[0]);
3029 location = get_defcfg_location(defcfg);
3031 num_pins = alc_auto_fill_multi_ios(codec, location);
3033 spec->multi_ios = num_pins;
3034 spec->ext_channel_count = 2;
3035 spec->multiout.num_dacs = num_pins + 1;
3039 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
3040 alc_auto_fill_extra_dacs(codec, cfg->hp_outs, cfg->hp_pins,
3041 spec->multiout.hp_out_nid);
3042 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3043 int err = alc_auto_fill_extra_dacs(codec, cfg->speaker_outs,
3045 spec->multiout.extra_out_nid);
3046 /* if no speaker volume is assigned, try again as the primary
3049 if (!err && cfg->speaker_outs > 0 &&
3050 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3051 cfg->hp_outs = cfg->line_outs;
3052 memcpy(cfg->hp_pins, cfg->line_out_pins,
3053 sizeof(cfg->hp_pins));
3054 cfg->line_outs = cfg->speaker_outs;
3055 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3056 sizeof(cfg->speaker_pins));
3057 cfg->speaker_outs = 0;
3058 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3059 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
3068 static inline unsigned int get_ctl_pos(unsigned int data)
3070 hda_nid_t nid = get_amp_nid_(data);
3071 unsigned int dir = get_amp_direction_(data);
3072 return (nid << 1) | dir;
3075 #define is_ctl_used(bits, data) \
3076 test_bit(get_ctl_pos(data), bits)
3077 #define mark_ctl_usage(bits, data) \
3078 set_bit(get_ctl_pos(data), bits)
3080 static int alc_auto_add_vol_ctl(struct hda_codec *codec,
3081 const char *pfx, int cidx,
3082 hda_nid_t nid, unsigned int chs)
3084 struct alc_spec *spec = codec->spec;
3088 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3089 if (is_ctl_used(spec->vol_ctls, val) && chs != 2) /* exclude LFE */
3091 mark_ctl_usage(spec->vol_ctls, val);
3092 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
3096 #define alc_auto_add_stereo_vol(codec, pfx, cidx, nid) \
3097 alc_auto_add_vol_ctl(codec, pfx, cidx, nid, 3)
3099 /* create a mute-switch for the given mixer widget;
3100 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3102 static int alc_auto_add_sw_ctl(struct hda_codec *codec,
3103 const char *pfx, int cidx,
3104 hda_nid_t nid, unsigned int chs)
3106 struct alc_spec *spec = codec->spec;
3112 wid_type = get_wcaps_type(get_wcaps(codec, nid));
3113 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) {
3114 type = ALC_CTL_WIDGET_MUTE;
3115 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3116 } else if (snd_hda_get_conn_list(codec, nid, NULL) == 1) {
3117 type = ALC_CTL_WIDGET_MUTE;
3118 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
3120 type = ALC_CTL_BIND_MUTE;
3121 val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
3123 if (is_ctl_used(spec->sw_ctls, val) && chs != 2) /* exclude LFE */
3125 mark_ctl_usage(spec->sw_ctls, val);
3126 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
3129 #define alc_auto_add_stereo_sw(codec, pfx, cidx, nid) \
3130 alc_auto_add_sw_ctl(codec, pfx, cidx, nid, 3)
3132 static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3133 hda_nid_t pin, hda_nid_t dac)
3135 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3136 if (nid_has_mute(codec, pin, HDA_OUTPUT))
3138 else if (mix && nid_has_mute(codec, mix, HDA_INPUT))
3140 else if (nid_has_mute(codec, dac, HDA_OUTPUT))
3145 static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3146 hda_nid_t pin, hda_nid_t dac)
3148 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3149 if (nid_has_volume(codec, dac, HDA_OUTPUT))
3151 else if (nid_has_volume(codec, mix, HDA_OUTPUT))
3153 else if (nid_has_volume(codec, pin, HDA_OUTPUT))
3158 /* add playback controls from the parsed DAC table */
3159 static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
3160 const struct auto_pin_cfg *cfg)
3162 struct alc_spec *spec = codec->spec;
3163 int i, err, noutputs;
3165 noutputs = cfg->line_outs;
3166 if (spec->multi_ios > 0)
3167 noutputs += spec->multi_ios;
3169 for (i = 0; i < noutputs; i++) {
3175 dac = spec->multiout.dac_nids[i];
3178 if (i >= cfg->line_outs)
3179 pin = spec->multi_io[i - 1].pin;
3181 pin = cfg->line_out_pins[i];
3183 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3184 vol = alc_look_for_out_vol_nid(codec, pin, dac);
3185 name = alc_get_line_out_pfx(spec, i, true, &index);
3186 if (!name || !strcmp(name, "CLFE")) {
3188 err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1);
3191 err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2);
3194 err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1);
3197 err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2);
3201 err = alc_auto_add_stereo_vol(codec, name, index, vol);
3204 err = alc_auto_add_stereo_sw(codec, name, index, sw);
3212 static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
3213 hda_nid_t dac, const char *pfx,
3216 struct alc_spec *spec = codec->spec;
3222 /* the corresponding DAC is already occupied */
3223 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
3224 return 0; /* no way */
3225 /* create a switch only */
3226 val = HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT);
3227 if (is_ctl_used(spec->sw_ctls, val))
3228 return 0; /* already created */
3229 mark_ctl_usage(spec->sw_ctls, val);
3230 return __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, cidx, val);
3233 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3234 vol = alc_look_for_out_vol_nid(codec, pin, dac);
3235 err = alc_auto_add_stereo_vol(codec, pfx, cidx, vol);
3238 err = alc_auto_add_stereo_sw(codec, pfx, cidx, sw);
3244 static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3246 struct hda_ctl_ops *ops)
3248 struct alc_spec *spec = codec->spec;
3249 struct hda_bind_ctls **ctlp, *ctl;
3250 snd_array_init(&spec->bind_ctls, sizeof(ctl), 8);
3251 ctlp = snd_array_new(&spec->bind_ctls);
3254 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3261 /* add playback controls for speaker and HP outputs */
3262 static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3263 const hda_nid_t *pins,
3264 const hda_nid_t *dacs,
3267 struct alc_spec *spec = codec->spec;
3268 struct hda_bind_ctls *ctl;
3272 if (!num_pins || !pins[0])
3275 if (num_pins == 1) {
3276 hda_nid_t dac = *dacs;
3278 dac = spec->multiout.dac_nids[0];
3279 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
3282 if (dacs[num_pins - 1]) {
3283 /* OK, we have a multi-output system with individual volumes */
3284 for (i = 0; i < num_pins; i++) {
3285 if (num_pins >= 3) {
3286 snprintf(name, sizeof(name), "%s %s",
3287 pfx, channel_name[i]);
3288 err = alc_auto_create_extra_out(codec, pins[i], dacs[i],
3291 err = alc_auto_create_extra_out(codec, pins[i], dacs[i],
3300 /* Let's create a bind-controls */
3301 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_sw);
3305 for (i = 0; i < num_pins; i++) {
3306 if (get_wcaps(codec, pins[i]) & AC_WCAP_OUT_AMP)
3308 HDA_COMPOSE_AMP_VAL(pins[i], 3, 0, HDA_OUTPUT);
3311 snprintf(name, sizeof(name), "%s Playback Switch", pfx);
3312 err = add_control(spec, ALC_CTL_BIND_SW, name, 0, (long)ctl);
3317 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3321 for (i = 0; i < num_pins; i++) {
3323 if (!pins[i] || !dacs[i])
3325 vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]);
3328 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3331 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3332 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3339 static int alc_auto_create_hp_out(struct hda_codec *codec)
3341 struct alc_spec *spec = codec->spec;
3342 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3343 spec->autocfg.hp_pins,
3344 spec->multiout.hp_out_nid,
3348 static int alc_auto_create_speaker_out(struct hda_codec *codec)
3350 struct alc_spec *spec = codec->spec;
3351 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3352 spec->autocfg.speaker_pins,
3353 spec->multiout.extra_out_nid,
3357 static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
3358 hda_nid_t pin, int pin_type,
3362 hda_nid_t nid, mix = 0;
3363 hda_nid_t srcs[HDA_MAX_CONNECTIONS];
3365 alc_set_pin_output(codec, pin, pin_type);
3366 nid = alc_go_down_to_selector(codec, pin);
3367 num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
3368 for (i = 0; i < num; i++) {
3369 if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
3377 /* need the manual connection? */
3379 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
3380 /* unmute mixer widget inputs */
3381 if (nid_has_mute(codec, mix, HDA_INPUT)) {
3382 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3384 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3387 /* initialize volume */
3388 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3390 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3393 /* unmute DAC if it's not assigned to a mixer */
3394 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3395 if (nid == mix && nid_has_mute(codec, dac, HDA_OUTPUT))
3396 snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3400 static void alc_auto_init_multi_out(struct hda_codec *codec)
3402 struct alc_spec *spec = codec->spec;
3403 int pin_type = get_pin_type(spec->autocfg.line_out_type);
3406 for (i = 0; i <= HDA_SIDE; i++) {
3407 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3409 alc_auto_set_output_and_unmute(codec, nid, pin_type,
3410 spec->multiout.dac_nids[i]);
3414 static void alc_auto_init_extra_out(struct hda_codec *codec)
3416 struct alc_spec *spec = codec->spec;
3420 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3421 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3423 pin = spec->autocfg.hp_pins[i];
3426 dac = spec->multiout.hp_out_nid[i];
3428 if (i > 0 && spec->multiout.hp_out_nid[0])
3429 dac = spec->multiout.hp_out_nid[0];
3431 dac = spec->multiout.dac_nids[0];
3433 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
3435 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3436 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3438 pin = spec->autocfg.speaker_pins[i];
3441 dac = spec->multiout.extra_out_nid[i];
3443 if (i > 0 && spec->multiout.extra_out_nid[0])
3444 dac = spec->multiout.extra_out_nid[0];
3446 dac = spec->multiout.dac_nids[0];
3448 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
3455 static int alc_auto_fill_multi_ios(struct hda_codec *codec,
3456 unsigned int location)
3458 struct alc_spec *spec = codec->spec;
3459 struct auto_pin_cfg *cfg = &spec->autocfg;
3460 hda_nid_t prime_dac = spec->private_dac_nids[0];
3461 int type, i, num_pins = 0;
3463 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3464 for (i = 0; i < cfg->num_inputs; i++) {
3465 hda_nid_t nid = cfg->inputs[i].pin;
3467 unsigned int defcfg, caps;
3468 if (cfg->inputs[i].type != type)
3470 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3471 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3473 if (location && get_defcfg_location(defcfg) != location)
3475 caps = snd_hda_query_pin_caps(codec, nid);
3476 if (!(caps & AC_PINCAP_OUT))
3478 dac = alc_auto_look_for_dac(codec, nid);
3481 spec->multi_io[num_pins].pin = nid;
3482 spec->multi_io[num_pins].dac = dac;
3484 spec->private_dac_nids[spec->multiout.num_dacs++] = dac;
3487 spec->multiout.num_dacs = 1;
3489 /* clear up again */
3490 memset(spec->private_dac_nids, 0,
3491 sizeof(spec->private_dac_nids));
3492 spec->private_dac_nids[0] = prime_dac;
3498 static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
3499 struct snd_ctl_elem_info *uinfo)
3501 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3502 struct alc_spec *spec = codec->spec;
3504 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3506 uinfo->value.enumerated.items = spec->multi_ios + 1;
3507 if (uinfo->value.enumerated.item > spec->multi_ios)
3508 uinfo->value.enumerated.item = spec->multi_ios;
3509 sprintf(uinfo->value.enumerated.name, "%dch",
3510 (uinfo->value.enumerated.item + 1) * 2);
3514 static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
3515 struct snd_ctl_elem_value *ucontrol)
3517 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3518 struct alc_spec *spec = codec->spec;
3519 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
3523 static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
3525 struct alc_spec *spec = codec->spec;
3526 hda_nid_t nid = spec->multi_io[idx].pin;
3528 if (!spec->multi_io[idx].ctl_in)
3529 spec->multi_io[idx].ctl_in =
3530 snd_hda_codec_read(codec, nid, 0,
3531 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3533 snd_hda_codec_update_cache(codec, nid, 0,
3534 AC_VERB_SET_PIN_WIDGET_CONTROL,
3536 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3537 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3539 alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
3541 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3542 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3543 HDA_AMP_MUTE, HDA_AMP_MUTE);
3544 snd_hda_codec_update_cache(codec, nid, 0,
3545 AC_VERB_SET_PIN_WIDGET_CONTROL,
3546 spec->multi_io[idx].ctl_in);
3551 static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
3552 struct snd_ctl_elem_value *ucontrol)
3554 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3555 struct alc_spec *spec = codec->spec;
3558 ch = ucontrol->value.enumerated.item[0];
3559 if (ch < 0 || ch > spec->multi_ios)
3561 if (ch == (spec->ext_channel_count - 1) / 2)
3563 spec->ext_channel_count = (ch + 1) * 2;
3564 for (i = 0; i < spec->multi_ios; i++)
3565 alc_set_multi_io(codec, i, i < ch);
3566 spec->multiout.max_channels = spec->ext_channel_count;
3567 if (spec->need_dac_fix && !spec->const_channel_count)
3568 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
3572 static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
3573 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3574 .name = "Channel Mode",
3575 .info = alc_auto_ch_mode_info,
3576 .get = alc_auto_ch_mode_get,
3577 .put = alc_auto_ch_mode_put,
3580 static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
3582 struct alc_spec *spec = codec->spec;
3584 if (spec->multi_ios > 0) {
3585 struct snd_kcontrol_new *knew;
3587 knew = alc_kcontrol_new(spec);
3590 *knew = alc_auto_channel_mode_enum;
3591 knew->name = kstrdup("Channel Mode", GFP_KERNEL);
3598 /* filter out invalid adc_nids (and capsrc_nids) that don't give all
3601 static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
3603 struct alc_spec *spec = codec->spec;
3604 const struct hda_input_mux *imux;
3605 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3606 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3609 imux = spec->input_mux;
3612 if (spec->dyn_adc_switch)
3616 for (n = 0; n < spec->num_adc_nids; n++) {
3617 hda_nid_t cap = spec->private_capsrc_nids[n];
3618 int num_conns = snd_hda_get_conn_list(codec, cap, NULL);
3619 for (i = 0; i < imux->num_items; i++) {
3620 hda_nid_t pin = spec->imux_pins[i];
3622 if (get_connection_index(codec, cap, pin) < 0)
3624 } else if (num_conns <= imux->items[i].index)
3627 if (i >= imux->num_items) {
3628 adc_nids[nums] = spec->private_adc_nids[n];
3629 capsrc_nids[nums++] = cap;
3633 /* check whether ADC-switch is possible */
3634 if (!alc_check_dyn_adc_switch(codec)) {
3635 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
3636 " using fallback 0x%x\n",
3637 codec->chip_name, spec->private_adc_nids[0]);
3638 spec->num_adc_nids = 1;
3642 } else if (nums != spec->num_adc_nids) {
3643 memcpy(spec->private_adc_nids, adc_nids,
3644 nums * sizeof(hda_nid_t));
3645 memcpy(spec->private_capsrc_nids, capsrc_nids,
3646 nums * sizeof(hda_nid_t));
3647 spec->num_adc_nids = nums;
3651 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
3652 else if (spec->input_mux->num_items == 1)
3653 spec->num_adc_nids = 1; /* reduce to a single ADC */
3657 * initialize ADC paths
3659 static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
3661 struct alc_spec *spec = codec->spec;
3664 nid = spec->adc_nids[adc_idx];
3666 if (nid_has_mute(codec, nid, HDA_INPUT)) {
3667 snd_hda_codec_write(codec, nid, 0,
3668 AC_VERB_SET_AMP_GAIN_MUTE,
3672 if (!spec->capsrc_nids)
3674 nid = spec->capsrc_nids[adc_idx];
3675 if (nid_has_mute(codec, nid, HDA_OUTPUT))
3676 snd_hda_codec_write(codec, nid, 0,
3677 AC_VERB_SET_AMP_GAIN_MUTE,
3681 static void alc_auto_init_input_src(struct hda_codec *codec)
3683 struct alc_spec *spec = codec->spec;
3686 for (c = 0; c < spec->num_adc_nids; c++)
3687 alc_auto_init_adc(codec, c);
3688 if (spec->dyn_adc_switch)
3691 nums = spec->num_adc_nids;
3692 for (c = 0; c < nums; c++)
3693 alc_mux_select(codec, 0, spec->cur_mux[c], true);
3696 /* add mic boosts if needed */
3697 static int alc_auto_add_mic_boost(struct hda_codec *codec)
3699 struct alc_spec *spec = codec->spec;
3700 struct auto_pin_cfg *cfg = &spec->autocfg;
3704 const char *prev_label = NULL;
3706 for (i = 0; i < cfg->num_inputs; i++) {
3707 if (cfg->inputs[i].type > AUTO_PIN_MIC)
3709 nid = cfg->inputs[i].pin;
3710 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
3712 char boost_label[32];
3714 label = hda_get_autocfg_input_label(codec, cfg, i);
3715 if (prev_label && !strcmp(label, prev_label))
3721 snprintf(boost_label, sizeof(boost_label),
3722 "%s Boost Volume", label);
3723 err = add_control(spec, ALC_CTL_WIDGET_VOL,
3724 boost_label, type_idx,
3725 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
3733 /* select or unmute the given capsrc route */
3734 static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
3737 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
3738 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
3740 } else if (snd_hda_get_conn_list(codec, cap, NULL) > 1) {
3741 snd_hda_codec_write_cache(codec, cap, 0,
3742 AC_VERB_SET_CONNECT_SEL, idx);
3746 /* set the default connection to that pin */
3747 static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
3749 struct alc_spec *spec = codec->spec;
3754 for (i = 0; i < spec->num_adc_nids; i++) {
3755 hda_nid_t cap = get_capsrc(spec, i);
3758 idx = get_connection_index(codec, cap, pin);
3761 select_or_unmute_capsrc(codec, cap, idx);
3762 return i; /* return the found index */
3764 return -1; /* not found */
3767 /* initialize some special cases for input sources */
3768 static void alc_init_special_input_src(struct hda_codec *codec)
3770 struct alc_spec *spec = codec->spec;
3773 for (i = 0; i < spec->autocfg.num_inputs; i++)
3774 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
3777 /* assign appropriate capture mixers */
3778 static void set_capture_mixer(struct hda_codec *codec)
3780 struct alc_spec *spec = codec->spec;
3781 static const struct snd_kcontrol_new *caps[2][3] = {
3782 { alc_capture_mixer_nosrc1,
3783 alc_capture_mixer_nosrc2,
3784 alc_capture_mixer_nosrc3 },
3785 { alc_capture_mixer1,
3787 alc_capture_mixer3 },
3790 /* check whether either of ADC or MUX has a volume control */
3791 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
3792 if (!spec->capsrc_nids)
3793 return; /* no volume */
3794 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
3795 return; /* no volume in capsrc, too */
3796 spec->vol_in_capsrc = 1;
3799 if (spec->num_adc_nids > 0) {
3803 if (spec->input_mux && spec->input_mux->num_items > 1)
3805 if (spec->auto_mic) {
3808 } else if (spec->dyn_adc_switch)
3811 if (spec->num_adc_nids > 3)
3812 spec->num_adc_nids = 3;
3813 else if (!spec->num_adc_nids)
3815 num_adcs = spec->num_adc_nids;
3817 spec->cap_mixer = caps[mux][num_adcs - 1];
3822 * standard auto-parser initializations
3824 static void alc_auto_init_std(struct hda_codec *codec)
3826 struct alc_spec *spec = codec->spec;
3827 alc_auto_init_multi_out(codec);
3828 alc_auto_init_extra_out(codec);
3829 alc_auto_init_analog_input(codec);
3830 alc_auto_init_input_src(codec);
3831 alc_auto_init_digital(codec);
3832 if (spec->unsol_event)
3833 alc_inithook(codec);
3837 * Digital-beep handlers
3839 #ifdef CONFIG_SND_HDA_INPUT_BEEP
3840 #define set_beep_amp(spec, nid, idx, dir) \
3841 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
3843 static const struct snd_pci_quirk beep_white_list[] = {
3844 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
3845 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
3846 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
3847 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
3848 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
3852 static inline int has_cdefine_beep(struct hda_codec *codec)
3854 struct alc_spec *spec = codec->spec;
3855 const struct snd_pci_quirk *q;
3856 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
3859 return spec->cdefine.enable_pcbeep;
3862 #define set_beep_amp(spec, nid, idx, dir) /* NOP */
3863 #define has_cdefine_beep(codec) 0
3866 /* parse the BIOS configuration and set up the alc_spec */
3867 /* return 1 if successful, 0 if the proper config is not found,
3868 * or a negative error code
3870 static int alc_parse_auto_config(struct hda_codec *codec,
3871 const hda_nid_t *ignore_nids,
3872 const hda_nid_t *ssid_nids)
3874 struct alc_spec *spec = codec->spec;
3875 struct auto_pin_cfg *cfg = &spec->autocfg;
3878 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
3882 if (!cfg->line_outs) {
3883 if (cfg->dig_outs || cfg->dig_in_pin) {
3884 spec->multiout.max_channels = 2;
3885 spec->no_analog = 1;
3888 return 0; /* can't find valid BIOS pin config */
3891 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
3892 cfg->line_outs <= cfg->hp_outs) {
3893 /* use HP as primary out */
3894 cfg->speaker_outs = cfg->line_outs;
3895 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3896 sizeof(cfg->speaker_pins));
3897 cfg->line_outs = cfg->hp_outs;
3898 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
3900 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3901 cfg->line_out_type = AUTO_PIN_HP_OUT;
3904 err = alc_auto_fill_dac_nids(codec);
3907 err = alc_auto_add_multi_channel_mode(codec);
3910 err = alc_auto_create_multi_out_ctls(codec, cfg);
3913 err = alc_auto_create_hp_out(codec);
3916 err = alc_auto_create_speaker_out(codec);
3919 err = alc_auto_create_input_ctls(codec);
3923 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3926 alc_auto_parse_digital(codec);
3928 if (!spec->no_analog)
3929 alc_remove_invalid_adc_nids(codec);
3932 alc_ssid_check(codec, ssid_nids);
3934 if (!spec->no_analog) {
3935 alc_auto_check_switches(codec);
3936 err = alc_auto_add_mic_boost(codec);
3941 if (spec->kctls.list)
3942 add_mixer(spec, spec->kctls.list);
3947 static int alc880_parse_auto_config(struct hda_codec *codec)
3949 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
3950 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
3951 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
3954 #ifdef CONFIG_SND_HDA_POWER_SAVE
3955 static const struct hda_amp_list alc880_loopbacks[] = {
3956 { 0x0b, HDA_INPUT, 0 },
3957 { 0x0b, HDA_INPUT, 1 },
3958 { 0x0b, HDA_INPUT, 2 },
3959 { 0x0b, HDA_INPUT, 3 },
3960 { 0x0b, HDA_INPUT, 4 },
3968 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3969 #define alc_board_config \
3970 snd_hda_check_board_config
3971 #define alc_board_codec_sid_config \
3972 snd_hda_check_board_codec_sid_config
3973 #include "alc_quirks.c"
3975 #define alc_board_config(codec, nums, models, tbl) -1
3976 #define alc_board_codec_sid_config(codec, nums, models, tbl) -1
3977 #define setup_preset(codec, x) /* NOP */
3981 * OK, here we have finally the patch for ALC880
3983 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3984 #include "alc880_quirks.c"
3987 static int patch_alc880(struct hda_codec *codec)
3989 struct alc_spec *spec;
3993 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3999 spec->mixer_nid = 0x0b;
4000 spec->need_dac_fix = 1;
4002 board_config = alc_board_config(codec, ALC880_MODEL_LAST,
4003 alc880_models, alc880_cfg_tbl);
4004 if (board_config < 0) {
4005 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4007 board_config = ALC_MODEL_AUTO;
4010 if (board_config == ALC_MODEL_AUTO) {
4011 /* automatic parse from the BIOS config */
4012 err = alc880_parse_auto_config(codec);
4015 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4018 "hda_codec: Cannot set up configuration "
4019 "from BIOS. Using 3-stack mode...\n");
4020 board_config = ALC880_3ST;
4025 if (board_config != ALC_MODEL_AUTO)
4026 setup_preset(codec, &alc880_presets[board_config]);
4028 if (!spec->no_analog && !spec->adc_nids) {
4029 alc_auto_fill_adc_caps(codec);
4030 alc_rebuild_imux_for_auto_mic(codec);
4031 alc_remove_invalid_adc_nids(codec);
4034 if (!spec->no_analog && !spec->cap_mixer)
4035 set_capture_mixer(codec);
4037 if (!spec->no_analog) {
4038 err = snd_hda_attach_beep_device(codec, 0x1);
4041 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4044 spec->vmaster_nid = 0x0c;
4046 codec->patch_ops = alc_patch_ops;
4047 if (board_config == ALC_MODEL_AUTO)
4048 spec->init_hook = alc_auto_init_std;
4049 #ifdef CONFIG_SND_HDA_POWER_SAVE
4050 if (!spec->loopback.amplist)
4051 spec->loopback.amplist = alc880_loopbacks;
4065 static int alc260_parse_auto_config(struct hda_codec *codec)
4067 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
4068 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
4069 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
4072 #ifdef CONFIG_SND_HDA_POWER_SAVE
4073 static const struct hda_amp_list alc260_loopbacks[] = {
4074 { 0x07, HDA_INPUT, 0 },
4075 { 0x07, HDA_INPUT, 1 },
4076 { 0x07, HDA_INPUT, 2 },
4077 { 0x07, HDA_INPUT, 3 },
4078 { 0x07, HDA_INPUT, 4 },
4090 static const struct alc_fixup alc260_fixups[] = {
4091 [PINFIX_HP_DC5750] = {
4092 .type = ALC_FIXUP_PINS,
4093 .v.pins = (const struct alc_pincfg[]) {
4094 { 0x11, 0x90130110 }, /* speaker */
4100 static const struct snd_pci_quirk alc260_fixup_tbl[] = {
4101 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", PINFIX_HP_DC5750),
4107 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4108 #include "alc260_quirks.c"
4111 static int patch_alc260(struct hda_codec *codec)
4113 struct alc_spec *spec;
4114 int err, board_config;
4116 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4122 spec->mixer_nid = 0x07;
4124 board_config = alc_board_config(codec, ALC260_MODEL_LAST,
4125 alc260_models, alc260_cfg_tbl);
4126 if (board_config < 0) {
4127 snd_printd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4129 board_config = ALC_MODEL_AUTO;
4132 if (board_config == ALC_MODEL_AUTO) {
4133 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
4134 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4137 if (board_config == ALC_MODEL_AUTO) {
4138 /* automatic parse from the BIOS config */
4139 err = alc260_parse_auto_config(codec);
4142 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4145 "hda_codec: Cannot set up configuration "
4146 "from BIOS. Using base mode...\n");
4147 board_config = ALC260_BASIC;
4152 if (board_config != ALC_MODEL_AUTO)
4153 setup_preset(codec, &alc260_presets[board_config]);
4155 if (!spec->no_analog && !spec->adc_nids) {
4156 alc_auto_fill_adc_caps(codec);
4157 alc_rebuild_imux_for_auto_mic(codec);
4158 alc_remove_invalid_adc_nids(codec);
4161 if (!spec->no_analog && !spec->cap_mixer)
4162 set_capture_mixer(codec);
4164 if (!spec->no_analog) {
4165 err = snd_hda_attach_beep_device(codec, 0x1);
4168 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
4171 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4173 spec->vmaster_nid = 0x08;
4175 codec->patch_ops = alc_patch_ops;
4176 if (board_config == ALC_MODEL_AUTO)
4177 spec->init_hook = alc_auto_init_std;
4178 spec->shutup = alc_eapd_shutup;
4179 #ifdef CONFIG_SND_HDA_POWER_SAVE
4180 if (!spec->loopback.amplist)
4181 spec->loopback.amplist = alc260_loopbacks;
4193 * ALC882/883/885/888/889 support
4195 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
4196 * configuration. Each pin widget can choose any input DACs and a mixer.
4197 * Each ADC is connected from a mixer of all inputs. This makes possible
4198 * 6-channel independent captures.
4200 * In addition, an independent DAC for the multi-playback (not used in this
4203 #ifdef CONFIG_SND_HDA_POWER_SAVE
4204 #define alc882_loopbacks alc880_loopbacks
4211 PINFIX_ABIT_AW9D_MAX,
4214 PINFIX_ACER_ASPIRE_7736,
4216 ALC889_FIXUP_DAC_ROUTE,
4219 /* Fix the connection of some pins for ALC889:
4220 * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
4221 * work correctly (bko#42740)
4223 static void alc889_fixup_dac_route(struct hda_codec *codec,
4224 const struct alc_fixup *fix, int action)
4226 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
4227 hda_nid_t conn1[2] = { 0x0c, 0x0d };
4228 hda_nid_t conn2[2] = { 0x0e, 0x0f };
4229 snd_hda_override_conn_list(codec, 0x14, 2, conn1);
4230 snd_hda_override_conn_list(codec, 0x15, 2, conn1);
4231 snd_hda_override_conn_list(codec, 0x18, 2, conn2);
4232 snd_hda_override_conn_list(codec, 0x1a, 2, conn2);
4236 static const struct alc_fixup alc882_fixups[] = {
4237 [PINFIX_ABIT_AW9D_MAX] = {
4238 .type = ALC_FIXUP_PINS,
4239 .v.pins = (const struct alc_pincfg[]) {
4240 { 0x15, 0x01080104 }, /* side */
4241 { 0x16, 0x01011012 }, /* rear */
4242 { 0x17, 0x01016011 }, /* clfe */
4246 [PINFIX_LENOVO_Y530] = {
4247 .type = ALC_FIXUP_PINS,
4248 .v.pins = (const struct alc_pincfg[]) {
4249 { 0x15, 0x99130112 }, /* rear int speakers */
4250 { 0x16, 0x99130111 }, /* subwoofer */
4254 [PINFIX_PB_M5210] = {
4255 .type = ALC_FIXUP_VERBS,
4256 .v.verbs = (const struct hda_verb[]) {
4257 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
4261 [PINFIX_ACER_ASPIRE_7736] = {
4262 .type = ALC_FIXUP_SKU,
4263 .v.sku = ALC_FIXUP_SKU_IGNORE,
4265 [PINFIX_ASUS_W90V] = {
4266 .type = ALC_FIXUP_PINS,
4267 .v.pins = (const struct alc_pincfg[]) {
4268 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
4272 [ALC889_FIXUP_DAC_ROUTE] = {
4273 .type = ALC_FIXUP_FUNC,
4274 .v.func = alc889_fixup_dac_route,
4278 static const struct snd_pci_quirk alc882_fixup_tbl[] = {
4279 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", PINFIX_PB_M5210),
4280 SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE),
4281 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", PINFIX_ASUS_W90V),
4282 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", PINFIX_LENOVO_Y530),
4283 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
4284 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", PINFIX_ACER_ASPIRE_7736),
4289 * BIOS auto configuration
4291 /* almost identical with ALC880 parser... */
4292 static int alc882_parse_auto_config(struct hda_codec *codec)
4294 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
4295 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4296 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
4301 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4302 #include "alc882_quirks.c"
4305 static int patch_alc882(struct hda_codec *codec)
4307 struct alc_spec *spec;
4308 int err, board_config;
4310 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4316 spec->mixer_nid = 0x0b;
4318 switch (codec->vendor_id) {
4323 /* ALC883 and variants */
4324 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
4328 err = alc_codec_rename_from_preset(codec);
4332 board_config = alc_board_config(codec, ALC882_MODEL_LAST,
4333 alc882_models, alc882_cfg_tbl);
4335 if (board_config < 0)
4336 board_config = alc_board_codec_sid_config(codec,
4337 ALC882_MODEL_LAST, alc882_models, alc882_ssid_cfg_tbl);
4339 if (board_config < 0) {
4340 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4342 board_config = ALC_MODEL_AUTO;
4345 if (board_config == ALC_MODEL_AUTO) {
4346 alc_pick_fixup(codec, NULL, alc882_fixup_tbl, alc882_fixups);
4347 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4350 alc_auto_parse_customize_define(codec);
4352 if (board_config == ALC_MODEL_AUTO) {
4353 /* automatic parse from the BIOS config */
4354 err = alc882_parse_auto_config(codec);
4357 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4360 "hda_codec: Cannot set up configuration "
4361 "from BIOS. Using base mode...\n");
4362 board_config = ALC882_3ST_DIG;
4367 if (board_config != ALC_MODEL_AUTO)
4368 setup_preset(codec, &alc882_presets[board_config]);
4370 if (!spec->no_analog && !spec->adc_nids) {
4371 alc_auto_fill_adc_caps(codec);
4372 alc_rebuild_imux_for_auto_mic(codec);
4373 alc_remove_invalid_adc_nids(codec);
4376 if (!spec->no_analog && !spec->cap_mixer)
4377 set_capture_mixer(codec);
4379 if (!spec->no_analog && has_cdefine_beep(codec)) {
4380 err = snd_hda_attach_beep_device(codec, 0x1);
4383 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4386 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4388 spec->vmaster_nid = 0x0c;
4390 codec->patch_ops = alc_patch_ops;
4391 if (board_config == ALC_MODEL_AUTO)
4392 spec->init_hook = alc_auto_init_std;
4394 alc_init_jacks(codec);
4395 #ifdef CONFIG_SND_HDA_POWER_SAVE
4396 if (!spec->loopback.amplist)
4397 spec->loopback.amplist = alc882_loopbacks;
4411 static int alc262_parse_auto_config(struct hda_codec *codec)
4413 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
4414 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4415 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
4426 static const struct alc_fixup alc262_fixups[] = {
4427 [PINFIX_FSC_H270] = {
4428 .type = ALC_FIXUP_PINS,
4429 .v.pins = (const struct alc_pincfg[]) {
4430 { 0x14, 0x99130110 }, /* speaker */
4431 { 0x15, 0x0221142f }, /* front HP */
4432 { 0x1b, 0x0121141f }, /* rear HP */
4436 [PINFIX_HP_Z200] = {
4437 .type = ALC_FIXUP_PINS,
4438 .v.pins = (const struct alc_pincfg[]) {
4439 { 0x16, 0x99130120 }, /* internal speaker */
4445 static const struct snd_pci_quirk alc262_fixup_tbl[] = {
4446 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", PINFIX_HP_Z200),
4447 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", PINFIX_FSC_H270),
4452 #ifdef CONFIG_SND_HDA_POWER_SAVE
4453 #define alc262_loopbacks alc880_loopbacks
4458 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4459 #include "alc262_quirks.c"
4462 static int patch_alc262(struct hda_codec *codec)
4464 struct alc_spec *spec;
4468 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4474 spec->mixer_nid = 0x0b;
4477 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
4482 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4483 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
4484 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4485 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
4488 alc_auto_parse_customize_define(codec);
4490 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
4492 board_config = alc_board_config(codec, ALC262_MODEL_LAST,
4493 alc262_models, alc262_cfg_tbl);
4495 if (board_config < 0) {
4496 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4498 board_config = ALC_MODEL_AUTO;
4501 if (board_config == ALC_MODEL_AUTO) {
4502 alc_pick_fixup(codec, NULL, alc262_fixup_tbl, alc262_fixups);
4503 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4506 if (board_config == ALC_MODEL_AUTO) {
4507 /* automatic parse from the BIOS config */
4508 err = alc262_parse_auto_config(codec);
4511 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4514 "hda_codec: Cannot set up configuration "
4515 "from BIOS. Using base mode...\n");
4516 board_config = ALC262_BASIC;
4521 if (board_config != ALC_MODEL_AUTO)
4522 setup_preset(codec, &alc262_presets[board_config]);
4524 if (!spec->no_analog && !spec->adc_nids) {
4525 alc_auto_fill_adc_caps(codec);
4526 alc_rebuild_imux_for_auto_mic(codec);
4527 alc_remove_invalid_adc_nids(codec);
4530 if (!spec->no_analog && !spec->cap_mixer)
4531 set_capture_mixer(codec);
4533 if (!spec->no_analog && has_cdefine_beep(codec)) {
4534 err = snd_hda_attach_beep_device(codec, 0x1);
4537 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4540 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4542 spec->vmaster_nid = 0x0c;
4544 codec->patch_ops = alc_patch_ops;
4545 if (board_config == ALC_MODEL_AUTO)
4546 spec->init_hook = alc_auto_init_std;
4547 spec->shutup = alc_eapd_shutup;
4549 alc_init_jacks(codec);
4550 #ifdef CONFIG_SND_HDA_POWER_SAVE
4551 if (!spec->loopback.amplist)
4552 spec->loopback.amplist = alc262_loopbacks;
4565 /* bind Beep switches of both NID 0x0f and 0x10 */
4566 static const struct hda_bind_ctls alc268_bind_beep_sw = {
4567 .ops = &snd_hda_bind_sw,
4569 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
4570 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
4575 static const struct snd_kcontrol_new alc268_beep_mixer[] = {
4576 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
4577 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
4581 /* set PCBEEP vol = 0, mute connections */
4582 static const struct hda_verb alc268_beep_init_verbs[] = {
4583 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4584 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4585 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4590 * BIOS auto configuration
4592 static int alc268_parse_auto_config(struct hda_codec *codec)
4594 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4595 struct alc_spec *spec = codec->spec;
4596 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
4598 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
4599 add_mixer(spec, alc268_beep_mixer);
4600 add_verb(spec, alc268_beep_init_verbs);
4608 static int patch_alc268(struct hda_codec *codec)
4610 struct alc_spec *spec;
4611 int i, has_beep, err;
4613 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4619 /* ALC268 has no aa-loopback mixer */
4621 /* automatic parse from the BIOS config */
4622 err = alc268_parse_auto_config(codec);
4627 for (i = 0; i < spec->num_mixers; i++) {
4628 if (spec->mixers[i] == alc268_beep_mixer) {
4635 err = snd_hda_attach_beep_device(codec, 0x1);
4638 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
4639 /* override the amp caps for beep generator */
4640 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
4641 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
4642 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
4643 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4644 (0 << AC_AMPCAP_MUTE_SHIFT));
4647 if (!spec->no_analog && !spec->adc_nids) {
4648 alc_auto_fill_adc_caps(codec);
4649 alc_rebuild_imux_for_auto_mic(codec);
4650 alc_remove_invalid_adc_nids(codec);
4653 if (!spec->no_analog && !spec->cap_mixer)
4654 set_capture_mixer(codec);
4656 spec->vmaster_nid = 0x02;
4658 codec->patch_ops = alc_patch_ops;
4659 spec->init_hook = alc_auto_init_std;
4660 spec->shutup = alc_eapd_shutup;
4662 alc_init_jacks(codec);
4674 #ifdef CONFIG_SND_HDA_POWER_SAVE
4675 #define alc269_loopbacks alc880_loopbacks
4678 static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
4682 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
4683 /* NID is set in alc_build_pcms */
4685 .open = alc_playback_pcm_open,
4686 .prepare = alc_playback_pcm_prepare,
4687 .cleanup = alc_playback_pcm_cleanup
4691 static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
4695 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
4696 /* NID is set in alc_build_pcms */
4699 #ifdef CONFIG_SND_HDA_POWER_SAVE
4700 static int alc269_mic2_for_mute_led(struct hda_codec *codec)
4702 switch (codec->subsystem_id) {
4709 static int alc269_mic2_mute_check_ps(struct hda_codec *codec, hda_nid_t nid)
4711 /* update mute-LED according to the speaker mute state */
4712 if (nid == 0x01 || nid == 0x14) {
4714 if (snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0) &
4719 /* mic2 vref pin is used for mute LED control */
4720 snd_hda_codec_update_cache(codec, 0x19, 0,
4721 AC_VERB_SET_PIN_WIDGET_CONTROL,
4724 return alc_check_power_status(codec, nid);
4726 #endif /* CONFIG_SND_HDA_POWER_SAVE */
4728 /* different alc269-variants */
4730 ALC269_TYPE_ALC269VA,
4731 ALC269_TYPE_ALC269VB,
4732 ALC269_TYPE_ALC269VC,
4736 * BIOS auto configuration
4738 static int alc269_parse_auto_config(struct hda_codec *codec)
4740 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
4741 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
4742 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4743 struct alc_spec *spec = codec->spec;
4744 const hda_nid_t *ssids = spec->codec_variant == ALC269_TYPE_ALC269VA ?
4745 alc269va_ssids : alc269_ssids;
4747 return alc_parse_auto_config(codec, alc269_ignore, ssids);
4750 static void alc269_toggle_power_output(struct hda_codec *codec, int power_up)
4752 int val = alc_read_coef_idx(codec, 0x04);
4757 alc_write_coef_idx(codec, 0x04, val);
4760 static void alc269_shutup(struct hda_codec *codec)
4762 if ((alc_get_coef0(codec) & 0x00ff) == 0x017)
4763 alc269_toggle_power_output(codec, 0);
4764 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
4765 alc269_toggle_power_output(codec, 0);
4771 static int alc269_resume(struct hda_codec *codec)
4773 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
4774 alc269_toggle_power_output(codec, 0);
4778 codec->patch_ops.init(codec);
4780 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
4781 alc269_toggle_power_output(codec, 1);
4785 if ((alc_get_coef0(codec) & 0x00ff) == 0x018)
4786 alc269_toggle_power_output(codec, 1);
4788 snd_hda_codec_resume_amp(codec);
4789 snd_hda_codec_resume_cache(codec);
4790 hda_call_check_power_status(codec, 0x01);
4793 #endif /* CONFIG_PM */
4795 static void alc269_fixup_hweq(struct hda_codec *codec,
4796 const struct alc_fixup *fix, int action)
4800 if (action != ALC_FIXUP_ACT_INIT)
4802 coef = alc_read_coef_idx(codec, 0x1e);
4803 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
4806 static void alc271_fixup_dmic(struct hda_codec *codec,
4807 const struct alc_fixup *fix, int action)
4809 static const struct hda_verb verbs[] = {
4810 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
4811 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
4816 if (strcmp(codec->chip_name, "ALC271X"))
4818 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
4819 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
4820 snd_hda_sequence_write(codec, verbs);
4823 static void alc269_fixup_pcm_44k(struct hda_codec *codec,
4824 const struct alc_fixup *fix, int action)
4826 struct alc_spec *spec = codec->spec;
4828 if (action != ALC_FIXUP_ACT_PROBE)
4831 /* Due to a hardware problem on Lenovo Ideadpad, we need to
4832 * fix the sample rate of analog I/O to 44.1kHz
4834 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
4835 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
4838 static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
4839 const struct alc_fixup *fix, int action)
4843 if (action != ALC_FIXUP_ACT_INIT)
4845 /* The digital-mic unit sends PDM (differential signal) instead of
4846 * the standard PCM, thus you can't record a valid mono stream as is.
4847 * Below is a workaround specific to ALC269 to control the dmic
4848 * signal source as mono.
4850 coef = alc_read_coef_idx(codec, 0x07);
4851 alc_write_coef_idx(codec, 0x07, coef | 0x80);
4854 static void alc269_quanta_automute(struct hda_codec *codec)
4856 update_outputs(codec);
4858 snd_hda_codec_write(codec, 0x20, 0,
4859 AC_VERB_SET_COEF_INDEX, 0x0c);
4860 snd_hda_codec_write(codec, 0x20, 0,
4861 AC_VERB_SET_PROC_COEF, 0x680);
4863 snd_hda_codec_write(codec, 0x20, 0,
4864 AC_VERB_SET_COEF_INDEX, 0x0c);
4865 snd_hda_codec_write(codec, 0x20, 0,
4866 AC_VERB_SET_PROC_COEF, 0x480);
4869 static void alc269_fixup_quanta_mute(struct hda_codec *codec,
4870 const struct alc_fixup *fix, int action)
4872 struct alc_spec *spec = codec->spec;
4873 if (action != ALC_FIXUP_ACT_PROBE)
4875 spec->automute_hook = alc269_quanta_automute;
4879 ALC269_FIXUP_SONY_VAIO,
4880 ALC275_FIXUP_SONY_VAIO_GPIO2,
4881 ALC269_FIXUP_DELL_M101Z,
4882 ALC269_FIXUP_SKU_IGNORE,
4883 ALC269_FIXUP_ASUS_G73JW,
4884 ALC269_FIXUP_LENOVO_EAPD,
4885 ALC275_FIXUP_SONY_HWEQ,
4887 ALC269_FIXUP_PCM_44K,
4888 ALC269_FIXUP_STEREO_DMIC,
4889 ALC269_FIXUP_QUANTA_MUTE,
4890 ALC269_FIXUP_LIFEBOOK,
4893 ALC269VB_FIXUP_AMIC,
4894 ALC269VB_FIXUP_DMIC,
4897 static const struct alc_fixup alc269_fixups[] = {
4898 [ALC269_FIXUP_SONY_VAIO] = {
4899 .type = ALC_FIXUP_VERBS,
4900 .v.verbs = (const struct hda_verb[]) {
4901 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
4905 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
4906 .type = ALC_FIXUP_VERBS,
4907 .v.verbs = (const struct hda_verb[]) {
4908 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
4909 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
4910 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
4914 .chain_id = ALC269_FIXUP_SONY_VAIO
4916 [ALC269_FIXUP_DELL_M101Z] = {
4917 .type = ALC_FIXUP_VERBS,
4918 .v.verbs = (const struct hda_verb[]) {
4919 /* Enables internal speaker */
4920 {0x20, AC_VERB_SET_COEF_INDEX, 13},
4921 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
4925 [ALC269_FIXUP_SKU_IGNORE] = {
4926 .type = ALC_FIXUP_SKU,
4927 .v.sku = ALC_FIXUP_SKU_IGNORE,
4929 [ALC269_FIXUP_ASUS_G73JW] = {
4930 .type = ALC_FIXUP_PINS,
4931 .v.pins = (const struct alc_pincfg[]) {
4932 { 0x17, 0x99130111 }, /* subwoofer */
4936 [ALC269_FIXUP_LENOVO_EAPD] = {
4937 .type = ALC_FIXUP_VERBS,
4938 .v.verbs = (const struct hda_verb[]) {
4939 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
4943 [ALC275_FIXUP_SONY_HWEQ] = {
4944 .type = ALC_FIXUP_FUNC,
4945 .v.func = alc269_fixup_hweq,
4947 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
4949 [ALC271_FIXUP_DMIC] = {
4950 .type = ALC_FIXUP_FUNC,
4951 .v.func = alc271_fixup_dmic,
4953 [ALC269_FIXUP_PCM_44K] = {
4954 .type = ALC_FIXUP_FUNC,
4955 .v.func = alc269_fixup_pcm_44k,
4957 [ALC269_FIXUP_STEREO_DMIC] = {
4958 .type = ALC_FIXUP_FUNC,
4959 .v.func = alc269_fixup_stereo_dmic,
4961 [ALC269_FIXUP_QUANTA_MUTE] = {
4962 .type = ALC_FIXUP_FUNC,
4963 .v.func = alc269_fixup_quanta_mute,
4965 [ALC269_FIXUP_LIFEBOOK] = {
4966 .type = ALC_FIXUP_PINS,
4967 .v.pins = (const struct alc_pincfg[]) {
4968 { 0x1a, 0x2101103f }, /* dock line-out */
4969 { 0x1b, 0x23a11040 }, /* dock mic-in */
4973 .chain_id = ALC269_FIXUP_QUANTA_MUTE
4975 [ALC269_FIXUP_AMIC] = {
4976 .type = ALC_FIXUP_PINS,
4977 .v.pins = (const struct alc_pincfg[]) {
4978 { 0x14, 0x99130110 }, /* speaker */
4979 { 0x15, 0x0121401f }, /* HP out */
4980 { 0x18, 0x01a19c20 }, /* mic */
4981 { 0x19, 0x99a3092f }, /* int-mic */
4985 [ALC269_FIXUP_DMIC] = {
4986 .type = ALC_FIXUP_PINS,
4987 .v.pins = (const struct alc_pincfg[]) {
4988 { 0x12, 0x99a3092f }, /* int-mic */
4989 { 0x14, 0x99130110 }, /* speaker */
4990 { 0x15, 0x0121401f }, /* HP out */
4991 { 0x18, 0x01a19c20 }, /* mic */
4995 [ALC269VB_FIXUP_AMIC] = {
4996 .type = ALC_FIXUP_PINS,
4997 .v.pins = (const struct alc_pincfg[]) {
4998 { 0x14, 0x99130110 }, /* speaker */
4999 { 0x18, 0x01a19c20 }, /* mic */
5000 { 0x19, 0x99a3092f }, /* int-mic */
5001 { 0x21, 0x0121401f }, /* HP out */
5005 [ALC269_FIXUP_DMIC] = {
5006 .type = ALC_FIXUP_PINS,
5007 .v.pins = (const struct alc_pincfg[]) {
5008 { 0x12, 0x99a3092f }, /* int-mic */
5009 { 0x14, 0x99130110 }, /* speaker */
5010 { 0x18, 0x01a19c20 }, /* mic */
5011 { 0x21, 0x0121401f }, /* HP out */
5017 static const struct snd_pci_quirk alc269_fixup_tbl[] = {
5018 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
5019 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
5020 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
5021 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
5022 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
5023 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
5024 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
5025 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
5026 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
5027 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
5028 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
5029 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
5030 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
5031 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
5032 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
5033 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
5034 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
5035 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
5036 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_QUANTA_MUTE),
5037 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K),
5038 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
5041 /* Below is a quirk table taken from the old code.
5042 * Basically the device should work as is without the fixup table.
5043 * If BIOS doesn't give a proper info, enable the corresponding
5046 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
5048 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
5049 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
5050 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
5051 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
5052 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
5053 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
5054 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
5055 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
5056 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
5057 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
5058 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
5059 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
5060 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
5061 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
5062 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
5063 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
5064 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
5065 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
5066 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
5067 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
5068 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
5069 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
5070 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
5071 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
5072 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
5073 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
5074 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
5075 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
5076 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
5077 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
5078 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
5079 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
5080 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
5081 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
5082 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
5083 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
5084 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
5085 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
5086 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
5091 static const struct alc_model_fixup alc269_fixup_models[] = {
5092 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
5093 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
5098 static int alc269_fill_coef(struct hda_codec *codec)
5102 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
5103 alc_write_coef_idx(codec, 0xf, 0x960b);
5104 alc_write_coef_idx(codec, 0xe, 0x8817);
5107 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
5108 alc_write_coef_idx(codec, 0xf, 0x960b);
5109 alc_write_coef_idx(codec, 0xe, 0x8814);
5112 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
5113 val = alc_read_coef_idx(codec, 0x04);
5114 /* Power up output pin */
5115 alc_write_coef_idx(codec, 0x04, val | (1<<11));
5118 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
5119 val = alc_read_coef_idx(codec, 0xd);
5120 if ((val & 0x0c00) >> 10 != 0x1) {
5121 /* Capless ramp up clock control */
5122 alc_write_coef_idx(codec, 0xd, val | (1<<10));
5124 val = alc_read_coef_idx(codec, 0x17);
5125 if ((val & 0x01c0) >> 6 != 0x4) {
5126 /* Class D power on reset */
5127 alc_write_coef_idx(codec, 0x17, val | (1<<7));
5131 val = alc_read_coef_idx(codec, 0xd); /* Class D */
5132 alc_write_coef_idx(codec, 0xd, val | (1<<14));
5134 val = alc_read_coef_idx(codec, 0x4); /* HP */
5135 alc_write_coef_idx(codec, 0x4, val | (1<<11));
5142 static int patch_alc269(struct hda_codec *codec)
5144 struct alc_spec *spec;
5147 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5153 spec->mixer_nid = 0x0b;
5155 alc_auto_parse_customize_define(codec);
5157 err = alc_codec_rename_from_preset(codec);
5161 if (codec->vendor_id == 0x10ec0269) {
5162 spec->codec_variant = ALC269_TYPE_ALC269VA;
5163 switch (alc_get_coef0(codec) & 0x00f0) {
5165 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
5166 spec->cdefine.platform_type == 1)
5167 err = alc_codec_rename(codec, "ALC271X");
5168 spec->codec_variant = ALC269_TYPE_ALC269VB;
5171 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
5172 codec->bus->pci->subsystem_device == 0x21f3)
5173 err = alc_codec_rename(codec, "ALC3202");
5174 spec->codec_variant = ALC269_TYPE_ALC269VC;
5177 alc_fix_pll_init(codec, 0x20, 0x04, 15);
5181 alc269_fill_coef(codec);
5184 alc_pick_fixup(codec, alc269_fixup_models,
5185 alc269_fixup_tbl, alc269_fixups);
5186 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5188 /* automatic parse from the BIOS config */
5189 err = alc269_parse_auto_config(codec);
5193 if (!spec->no_analog && !spec->adc_nids) {
5194 alc_auto_fill_adc_caps(codec);
5195 alc_rebuild_imux_for_auto_mic(codec);
5196 alc_remove_invalid_adc_nids(codec);
5199 if (!spec->no_analog && !spec->cap_mixer)
5200 set_capture_mixer(codec);
5202 if (!spec->no_analog && has_cdefine_beep(codec)) {
5203 err = snd_hda_attach_beep_device(codec, 0x1);
5206 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
5209 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5211 spec->vmaster_nid = 0x02;
5213 codec->patch_ops = alc_patch_ops;
5215 codec->patch_ops.resume = alc269_resume;
5217 spec->init_hook = alc_auto_init_std;
5218 spec->shutup = alc269_shutup;
5220 alc_init_jacks(codec);
5221 #ifdef CONFIG_SND_HDA_POWER_SAVE
5222 if (!spec->loopback.amplist)
5223 spec->loopback.amplist = alc269_loopbacks;
5224 if (alc269_mic2_for_mute_led(codec))
5225 codec->patch_ops.check_power_status = alc269_mic2_mute_check_ps;
5239 static int alc861_parse_auto_config(struct hda_codec *codec)
5241 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
5242 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
5243 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
5246 #ifdef CONFIG_SND_HDA_POWER_SAVE
5247 static const struct hda_amp_list alc861_loopbacks[] = {
5248 { 0x15, HDA_INPUT, 0 },
5249 { 0x15, HDA_INPUT, 1 },
5250 { 0x15, HDA_INPUT, 2 },
5251 { 0x15, HDA_INPUT, 3 },
5257 /* Pin config fixes */
5259 PINFIX_FSC_AMILO_PI1505,
5263 /* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
5264 static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
5265 const struct alc_fixup *fix, int action)
5267 struct alc_spec *spec = codec->spec;
5270 if (action != ALC_FIXUP_ACT_INIT)
5272 val = snd_hda_codec_read(codec, 0x0f, 0,
5273 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5274 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
5275 val |= AC_PINCTL_IN_EN;
5276 val |= AC_PINCTL_VREF_50;
5277 snd_hda_codec_write(codec, 0x0f, 0,
5278 AC_VERB_SET_PIN_WIDGET_CONTROL, val);
5279 spec->keep_vref_in_automute = 1;
5282 static const struct alc_fixup alc861_fixups[] = {
5283 [PINFIX_FSC_AMILO_PI1505] = {
5284 .type = ALC_FIXUP_PINS,
5285 .v.pins = (const struct alc_pincfg[]) {
5286 { 0x0b, 0x0221101f }, /* HP */
5287 { 0x0f, 0x90170310 }, /* speaker */
5291 [PINFIX_ASUS_A6RP] = {
5292 .type = ALC_FIXUP_FUNC,
5293 .v.func = alc861_fixup_asus_amp_vref_0f,
5297 static const struct snd_pci_quirk alc861_fixup_tbl[] = {
5298 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", PINFIX_ASUS_A6RP),
5299 SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", PINFIX_ASUS_A6RP),
5300 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", PINFIX_FSC_AMILO_PI1505),
5306 static int patch_alc861(struct hda_codec *codec)
5308 struct alc_spec *spec;
5311 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5317 spec->mixer_nid = 0x15;
5319 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
5320 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5322 /* automatic parse from the BIOS config */
5323 err = alc861_parse_auto_config(codec);
5327 if (!spec->no_analog && !spec->adc_nids) {
5328 alc_auto_fill_adc_caps(codec);
5329 alc_rebuild_imux_for_auto_mic(codec);
5330 alc_remove_invalid_adc_nids(codec);
5333 if (!spec->no_analog && !spec->cap_mixer)
5334 set_capture_mixer(codec);
5336 if (!spec->no_analog) {
5337 err = snd_hda_attach_beep_device(codec, 0x23);
5340 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
5343 spec->vmaster_nid = 0x03;
5345 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5347 codec->patch_ops = alc_patch_ops;
5348 spec->init_hook = alc_auto_init_std;
5349 #ifdef CONFIG_SND_HDA_POWER_SAVE
5350 spec->power_hook = alc_power_eapd;
5351 if (!spec->loopback.amplist)
5352 spec->loopback.amplist = alc861_loopbacks;
5367 * In addition, an independent DAC
5369 #ifdef CONFIG_SND_HDA_POWER_SAVE
5370 #define alc861vd_loopbacks alc880_loopbacks
5373 static int alc861vd_parse_auto_config(struct hda_codec *codec)
5375 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
5376 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5377 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
5381 ALC660VD_FIX_ASUS_GPIO1,
5382 ALC861VD_FIX_DALLAS,
5385 /* exclude VREF80 */
5386 static void alc861vd_fixup_dallas(struct hda_codec *codec,
5387 const struct alc_fixup *fix, int action)
5389 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
5390 snd_hda_override_pin_caps(codec, 0x18, 0x00001714);
5391 snd_hda_override_pin_caps(codec, 0x19, 0x0000171c);
5395 static const struct alc_fixup alc861vd_fixups[] = {
5396 [ALC660VD_FIX_ASUS_GPIO1] = {
5397 .type = ALC_FIXUP_VERBS,
5398 .v.verbs = (const struct hda_verb[]) {
5400 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
5401 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5402 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5406 [ALC861VD_FIX_DALLAS] = {
5407 .type = ALC_FIXUP_FUNC,
5408 .v.func = alc861vd_fixup_dallas,
5412 static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
5413 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
5414 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
5415 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
5419 static const struct hda_verb alc660vd_eapd_verbs[] = {
5420 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
5421 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
5427 static int patch_alc861vd(struct hda_codec *codec)
5429 struct alc_spec *spec;
5432 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5438 spec->mixer_nid = 0x0b;
5440 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
5441 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5443 /* automatic parse from the BIOS config */
5444 err = alc861vd_parse_auto_config(codec);
5448 if (codec->vendor_id == 0x10ec0660) {
5449 /* always turn on EAPD */
5450 add_verb(spec, alc660vd_eapd_verbs);
5453 if (!spec->no_analog && !spec->adc_nids) {
5454 alc_auto_fill_adc_caps(codec);
5455 alc_rebuild_imux_for_auto_mic(codec);
5456 alc_remove_invalid_adc_nids(codec);
5459 if (!spec->no_analog && !spec->cap_mixer)
5460 set_capture_mixer(codec);
5462 if (!spec->no_analog) {
5463 err = snd_hda_attach_beep_device(codec, 0x23);
5466 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5469 spec->vmaster_nid = 0x02;
5471 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5473 codec->patch_ops = alc_patch_ops;
5475 spec->init_hook = alc_auto_init_std;
5476 spec->shutup = alc_eapd_shutup;
5477 #ifdef CONFIG_SND_HDA_POWER_SAVE
5478 if (!spec->loopback.amplist)
5479 spec->loopback.amplist = alc861vd_loopbacks;
5492 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
5493 * configuration. Each pin widget can choose any input DACs and a mixer.
5494 * Each ADC is connected from a mixer of all inputs. This makes possible
5495 * 6-channel independent captures.
5497 * In addition, an independent DAC for the multi-playback (not used in this
5500 #ifdef CONFIG_SND_HDA_POWER_SAVE
5501 #define alc662_loopbacks alc880_loopbacks
5505 * BIOS auto configuration
5508 static int alc662_parse_auto_config(struct hda_codec *codec)
5510 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
5511 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
5512 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5513 const hda_nid_t *ssids;
5515 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
5516 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
5517 ssids = alc663_ssids;
5519 ssids = alc662_ssids;
5520 return alc_parse_auto_config(codec, alc662_ignore, ssids);
5523 static void alc272_fixup_mario(struct hda_codec *codec,
5524 const struct alc_fixup *fix, int action)
5526 if (action != ALC_FIXUP_ACT_PROBE)
5528 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
5529 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
5530 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
5531 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5532 (0 << AC_AMPCAP_MUTE_SHIFT)))
5534 "hda_codec: failed to override amp caps for NID 0x2\n");
5538 ALC662_FIXUP_ASPIRE,
5539 ALC662_FIXUP_IDEAPAD,
5541 ALC662_FIXUP_CZC_P10T,
5542 ALC662_FIXUP_SKU_IGNORE,
5543 ALC662_FIXUP_HP_RP5800,
5544 ALC662_FIXUP_ASUS_MODE1,
5545 ALC662_FIXUP_ASUS_MODE2,
5546 ALC662_FIXUP_ASUS_MODE3,
5547 ALC662_FIXUP_ASUS_MODE4,
5548 ALC662_FIXUP_ASUS_MODE5,
5549 ALC662_FIXUP_ASUS_MODE6,
5550 ALC662_FIXUP_ASUS_MODE7,
5551 ALC662_FIXUP_ASUS_MODE8,
5554 static const struct alc_fixup alc662_fixups[] = {
5555 [ALC662_FIXUP_ASPIRE] = {
5556 .type = ALC_FIXUP_PINS,
5557 .v.pins = (const struct alc_pincfg[]) {
5558 { 0x15, 0x99130112 }, /* subwoofer */
5562 [ALC662_FIXUP_IDEAPAD] = {
5563 .type = ALC_FIXUP_PINS,
5564 .v.pins = (const struct alc_pincfg[]) {
5565 { 0x17, 0x99130112 }, /* subwoofer */
5569 [ALC272_FIXUP_MARIO] = {
5570 .type = ALC_FIXUP_FUNC,
5571 .v.func = alc272_fixup_mario,
5573 [ALC662_FIXUP_CZC_P10T] = {
5574 .type = ALC_FIXUP_VERBS,
5575 .v.verbs = (const struct hda_verb[]) {
5576 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
5580 [ALC662_FIXUP_SKU_IGNORE] = {
5581 .type = ALC_FIXUP_SKU,
5582 .v.sku = ALC_FIXUP_SKU_IGNORE,
5584 [ALC662_FIXUP_HP_RP5800] = {
5585 .type = ALC_FIXUP_PINS,
5586 .v.pins = (const struct alc_pincfg[]) {
5587 { 0x14, 0x0221201f }, /* HP out */
5591 .chain_id = ALC662_FIXUP_SKU_IGNORE
5593 [ALC662_FIXUP_ASUS_MODE1] = {
5594 .type = ALC_FIXUP_PINS,
5595 .v.pins = (const struct alc_pincfg[]) {
5596 { 0x14, 0x99130110 }, /* speaker */
5597 { 0x18, 0x01a19c20 }, /* mic */
5598 { 0x19, 0x99a3092f }, /* int-mic */
5599 { 0x21, 0x0121401f }, /* HP out */
5603 .chain_id = ALC662_FIXUP_SKU_IGNORE
5605 [ALC662_FIXUP_ASUS_MODE2] = {
5606 .type = ALC_FIXUP_PINS,
5607 .v.pins = (const struct alc_pincfg[]) {
5608 { 0x14, 0x99130110 }, /* speaker */
5609 { 0x18, 0x01a19820 }, /* mic */
5610 { 0x19, 0x99a3092f }, /* int-mic */
5611 { 0x1b, 0x0121401f }, /* HP out */
5615 .chain_id = ALC662_FIXUP_SKU_IGNORE
5617 [ALC662_FIXUP_ASUS_MODE3] = {
5618 .type = ALC_FIXUP_PINS,
5619 .v.pins = (const struct alc_pincfg[]) {
5620 { 0x14, 0x99130110 }, /* speaker */
5621 { 0x15, 0x0121441f }, /* HP */
5622 { 0x18, 0x01a19840 }, /* mic */
5623 { 0x19, 0x99a3094f }, /* int-mic */
5624 { 0x21, 0x01211420 }, /* HP2 */
5628 .chain_id = ALC662_FIXUP_SKU_IGNORE
5630 [ALC662_FIXUP_ASUS_MODE4] = {
5631 .type = ALC_FIXUP_PINS,
5632 .v.pins = (const struct alc_pincfg[]) {
5633 { 0x14, 0x99130110 }, /* speaker */
5634 { 0x16, 0x99130111 }, /* speaker */
5635 { 0x18, 0x01a19840 }, /* mic */
5636 { 0x19, 0x99a3094f }, /* int-mic */
5637 { 0x21, 0x0121441f }, /* HP */
5641 .chain_id = ALC662_FIXUP_SKU_IGNORE
5643 [ALC662_FIXUP_ASUS_MODE5] = {
5644 .type = ALC_FIXUP_PINS,
5645 .v.pins = (const struct alc_pincfg[]) {
5646 { 0x14, 0x99130110 }, /* speaker */
5647 { 0x15, 0x0121441f }, /* HP */
5648 { 0x16, 0x99130111 }, /* speaker */
5649 { 0x18, 0x01a19840 }, /* mic */
5650 { 0x19, 0x99a3094f }, /* int-mic */
5654 .chain_id = ALC662_FIXUP_SKU_IGNORE
5656 [ALC662_FIXUP_ASUS_MODE6] = {
5657 .type = ALC_FIXUP_PINS,
5658 .v.pins = (const struct alc_pincfg[]) {
5659 { 0x14, 0x99130110 }, /* speaker */
5660 { 0x15, 0x01211420 }, /* HP2 */
5661 { 0x18, 0x01a19840 }, /* mic */
5662 { 0x19, 0x99a3094f }, /* int-mic */
5663 { 0x1b, 0x0121441f }, /* HP */
5667 .chain_id = ALC662_FIXUP_SKU_IGNORE
5669 [ALC662_FIXUP_ASUS_MODE7] = {
5670 .type = ALC_FIXUP_PINS,
5671 .v.pins = (const struct alc_pincfg[]) {
5672 { 0x14, 0x99130110 }, /* speaker */
5673 { 0x17, 0x99130111 }, /* speaker */
5674 { 0x18, 0x01a19840 }, /* mic */
5675 { 0x19, 0x99a3094f }, /* int-mic */
5676 { 0x1b, 0x01214020 }, /* HP */
5677 { 0x21, 0x0121401f }, /* HP */
5681 .chain_id = ALC662_FIXUP_SKU_IGNORE
5683 [ALC662_FIXUP_ASUS_MODE8] = {
5684 .type = ALC_FIXUP_PINS,
5685 .v.pins = (const struct alc_pincfg[]) {
5686 { 0x14, 0x99130110 }, /* speaker */
5687 { 0x12, 0x99a30970 }, /* int-mic */
5688 { 0x15, 0x01214020 }, /* HP */
5689 { 0x17, 0x99130111 }, /* speaker */
5690 { 0x18, 0x01a19840 }, /* mic */
5691 { 0x21, 0x0121401f }, /* HP */
5695 .chain_id = ALC662_FIXUP_SKU_IGNORE
5699 static const struct snd_pci_quirk alc662_fixup_tbl[] = {
5700 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
5701 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
5702 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
5703 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
5704 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
5705 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
5706 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
5707 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
5708 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
5709 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
5712 /* Below is a quirk table taken from the old code.
5713 * Basically the device should work as is without the fixup table.
5714 * If BIOS doesn't give a proper info, enable the corresponding
5717 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
5718 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
5719 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
5720 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
5721 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
5722 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5723 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
5724 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
5725 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
5726 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5727 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
5728 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
5729 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
5730 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
5731 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
5732 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5733 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
5734 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
5735 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5736 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
5737 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
5738 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5739 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
5740 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
5741 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
5742 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5743 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
5744 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
5745 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5746 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
5747 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5748 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5749 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
5750 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
5751 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
5752 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
5753 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
5754 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
5755 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
5756 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5757 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
5758 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
5759 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
5760 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
5761 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
5762 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
5763 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
5764 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
5765 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
5766 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
5771 static const struct alc_model_fixup alc662_fixup_models[] = {
5772 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
5773 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
5774 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
5775 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
5776 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
5777 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
5778 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
5779 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
5780 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
5787 static int patch_alc662(struct hda_codec *codec)
5789 struct alc_spec *spec;
5792 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5798 spec->mixer_nid = 0x0b;
5800 /* handle multiple HPs as is */
5801 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
5803 alc_auto_parse_customize_define(codec);
5805 alc_fix_pll_init(codec, 0x20, 0x04, 15);
5807 err = alc_codec_rename_from_preset(codec);
5811 if ((alc_get_coef0(codec) & (1 << 14)) &&
5812 codec->bus->pci->subsystem_vendor == 0x1025 &&
5813 spec->cdefine.platform_type == 1) {
5814 if (alc_codec_rename(codec, "ALC272X") < 0)
5818 alc_pick_fixup(codec, alc662_fixup_models,
5819 alc662_fixup_tbl, alc662_fixups);
5820 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5821 /* automatic parse from the BIOS config */
5822 err = alc662_parse_auto_config(codec);
5826 if (!spec->no_analog && !spec->adc_nids) {
5827 alc_auto_fill_adc_caps(codec);
5828 alc_rebuild_imux_for_auto_mic(codec);
5829 alc_remove_invalid_adc_nids(codec);
5832 if (!spec->no_analog && !spec->cap_mixer)
5833 set_capture_mixer(codec);
5835 if (!spec->no_analog && has_cdefine_beep(codec)) {
5836 err = snd_hda_attach_beep_device(codec, 0x1);
5839 switch (codec->vendor_id) {
5841 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5846 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
5849 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
5853 spec->vmaster_nid = 0x02;
5855 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5857 codec->patch_ops = alc_patch_ops;
5858 spec->init_hook = alc_auto_init_std;
5859 spec->shutup = alc_eapd_shutup;
5861 alc_init_jacks(codec);
5863 #ifdef CONFIG_SND_HDA_POWER_SAVE
5864 if (!spec->loopback.amplist)
5865 spec->loopback.amplist = alc662_loopbacks;
5879 static int alc680_parse_auto_config(struct hda_codec *codec)
5881 return alc_parse_auto_config(codec, NULL, NULL);
5886 static int patch_alc680(struct hda_codec *codec)
5888 struct alc_spec *spec;
5891 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5897 /* ALC680 has no aa-loopback mixer */
5899 /* automatic parse from the BIOS config */
5900 err = alc680_parse_auto_config(codec);
5906 if (!spec->no_analog && !spec->cap_mixer)
5907 set_capture_mixer(codec);
5909 spec->vmaster_nid = 0x02;
5911 codec->patch_ops = alc_patch_ops;
5912 spec->init_hook = alc_auto_init_std;
5920 static const struct hda_codec_preset snd_hda_preset_realtek[] = {
5921 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
5922 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
5923 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
5924 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
5925 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
5926 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
5927 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
5928 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
5929 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
5930 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
5931 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
5932 .patch = patch_alc861 },
5933 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
5934 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
5935 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
5936 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
5937 .patch = patch_alc882 },
5938 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
5939 .patch = patch_alc662 },
5940 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
5941 .patch = patch_alc662 },
5942 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
5943 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
5944 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
5945 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
5946 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
5947 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
5948 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
5949 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
5950 .patch = patch_alc882 },
5951 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
5952 .patch = patch_alc882 },
5953 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
5954 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
5955 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
5956 .patch = patch_alc882 },
5957 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
5958 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
5959 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
5960 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
5964 MODULE_ALIAS("snd-hda-codec-id:10ec*");
5966 MODULE_LICENSE("GPL");
5967 MODULE_DESCRIPTION("Realtek HD-audio codec");
5969 static struct hda_codec_preset_list realtek_list = {
5970 .preset = snd_hda_preset_realtek,
5971 .owner = THIS_MODULE,
5974 static int __init patch_realtek_init(void)
5976 return snd_hda_add_codec_preset(&realtek_list);
5979 static void __exit patch_realtek_exit(void)
5981 snd_hda_delete_codec_preset(&realtek_list);
5984 module_init(patch_realtek_init)
5985 module_exit(patch_realtek_exit)