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 */
82 #define MAX_VOL_NIDS 0x40
85 /* codec parameterization */
86 const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */
87 unsigned int num_mixers;
88 const struct snd_kcontrol_new *cap_mixer; /* capture mixer */
89 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
91 const struct hda_verb *init_verbs[10]; /* initialization verbs
95 unsigned int num_init_verbs;
97 char stream_name_analog[32]; /* analog PCM stream */
98 const struct hda_pcm_stream *stream_analog_playback;
99 const struct hda_pcm_stream *stream_analog_capture;
100 const struct hda_pcm_stream *stream_analog_alt_playback;
101 const struct hda_pcm_stream *stream_analog_alt_capture;
103 char stream_name_digital[32]; /* digital PCM stream */
104 const struct hda_pcm_stream *stream_digital_playback;
105 const struct hda_pcm_stream *stream_digital_capture;
108 struct hda_multi_out multiout; /* playback set-up
109 * max_channels, dacs must be set
110 * dig_out_nid and hp_nid are optional
112 hda_nid_t alt_dac_nid;
113 hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */
117 unsigned int num_adc_nids;
118 const hda_nid_t *adc_nids;
119 const hda_nid_t *capsrc_nids;
120 hda_nid_t dig_in_nid; /* digital-in NID; optional */
121 hda_nid_t mixer_nid; /* analog-mixer NID */
122 DECLARE_BITMAP(vol_ctls, MAX_VOL_NIDS << 1);
123 DECLARE_BITMAP(sw_ctls, MAX_VOL_NIDS << 1);
125 /* capture setup for dynamic dual-adc switch */
127 unsigned int cur_adc_stream_tag;
128 unsigned int cur_adc_format;
131 unsigned int num_mux_defs;
132 const struct hda_input_mux *input_mux;
133 unsigned int cur_mux[3];
134 hda_nid_t ext_mic_pin;
135 hda_nid_t dock_mic_pin;
136 hda_nid_t int_mic_pin;
139 const struct hda_channel_mode *channel_mode;
140 int num_channel_mode;
142 int const_channel_count;
143 int ext_channel_count;
145 /* PCM information */
146 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
148 /* dynamic controls, init_verbs and input_mux */
149 struct auto_pin_cfg autocfg;
150 struct alc_customize_define cdefine;
151 struct snd_array kctls;
152 struct hda_input_mux private_imux[3];
153 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
154 hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS];
155 hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS];
156 hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS];
157 unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS];
158 int int_mic_idx, ext_mic_idx, dock_mic_idx; /* for auto-mic */
161 void (*init_hook)(struct hda_codec *codec);
162 void (*unsol_event)(struct hda_codec *codec, unsigned int res);
163 #ifdef CONFIG_SND_HDA_POWER_SAVE
164 void (*power_hook)(struct hda_codec *codec);
166 void (*shutup)(struct hda_codec *codec);
167 void (*automute_hook)(struct hda_codec *codec);
169 /* for pin sensing */
170 unsigned int hp_jack_present:1;
171 unsigned int line_jack_present:1;
172 unsigned int master_mute:1;
173 unsigned int auto_mic:1;
174 unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */
175 unsigned int automute_speaker:1; /* automute speaker outputs */
176 unsigned int automute_lo:1; /* automute LO outputs */
177 unsigned int detect_hp:1; /* Headphone detection enabled */
178 unsigned int detect_lo:1; /* Line-out detection enabled */
179 unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */
180 unsigned int automute_lo_possible:1; /* there are line outs and HP */
181 unsigned int keep_vref_in_automute:1; /* Don't clear VREF in automute */
184 unsigned int no_analog :1; /* digital I/O only */
185 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
186 unsigned int single_input_src:1;
187 unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */
188 unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */
190 /* auto-mute control */
192 hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS];
195 int codec_variant; /* flag for other variants */
197 /* for virtual master */
198 hda_nid_t vmaster_nid;
199 #ifdef CONFIG_SND_HDA_POWER_SAVE
200 struct hda_loopback_check loopback;
205 unsigned int pll_coef_idx, pll_coef_bit;
210 const struct alc_fixup *fixup_list;
211 const char *fixup_name;
215 struct alc_multi_io multi_io[4];
218 struct snd_array bind_ctls;
221 #define ALC_MODEL_AUTO 0 /* common for all chips */
223 static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
224 int dir, unsigned int bits)
228 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
229 if (query_amp_caps(codec, nid, dir) & bits)
234 #define nid_has_mute(codec, nid, dir) \
235 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
236 #define nid_has_volume(codec, nid, dir) \
237 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
242 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
243 struct snd_ctl_elem_info *uinfo)
245 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
246 struct alc_spec *spec = codec->spec;
247 unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
248 if (mux_idx >= spec->num_mux_defs)
250 if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
252 return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
255 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
256 struct snd_ctl_elem_value *ucontrol)
258 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
259 struct alc_spec *spec = codec->spec;
260 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
262 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
266 static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
268 struct alc_spec *spec = codec->spec;
269 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
271 if (spec->cur_adc && spec->cur_adc != new_adc) {
272 /* stream is running, let's swap the current ADC */
273 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
274 spec->cur_adc = new_adc;
275 snd_hda_codec_setup_stream(codec, new_adc,
276 spec->cur_adc_stream_tag, 0,
277 spec->cur_adc_format);
283 static inline hda_nid_t get_capsrc(struct alc_spec *spec, int idx)
285 return spec->capsrc_nids ?
286 spec->capsrc_nids[idx] : spec->adc_nids[idx];
289 /* select the given imux item; either unmute exclusively or select the route */
290 static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
291 unsigned int idx, bool force)
293 struct alc_spec *spec = codec->spec;
294 const struct hda_input_mux *imux;
295 unsigned int mux_idx;
296 int i, type, num_conns;
299 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
300 imux = &spec->input_mux[mux_idx];
301 if (!imux->num_items && mux_idx > 0)
302 imux = &spec->input_mux[0];
303 if (!imux->num_items)
306 if (idx >= imux->num_items)
307 idx = imux->num_items - 1;
308 if (spec->cur_mux[adc_idx] == idx && !force)
310 spec->cur_mux[adc_idx] = idx;
312 if (spec->dyn_adc_switch) {
313 alc_dyn_adc_pcm_resetup(codec, idx);
314 adc_idx = spec->dyn_adc_idx[idx];
317 nid = get_capsrc(spec, adc_idx);
320 num_conns = snd_hda_get_conn_list(codec, nid, NULL);
324 type = get_wcaps_type(get_wcaps(codec, nid));
325 if (type == AC_WID_AUD_MIX) {
326 /* Matrix-mixer style (e.g. ALC882) */
327 int active = imux->items[idx].index;
328 for (i = 0; i < num_conns; i++) {
329 unsigned int v = (i == active) ? 0 : HDA_AMP_MUTE;
330 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, i,
334 /* MUX style (e.g. ALC880) */
335 snd_hda_codec_write_cache(codec, nid, 0,
336 AC_VERB_SET_CONNECT_SEL,
337 imux->items[idx].index);
342 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
343 struct snd_ctl_elem_value *ucontrol)
345 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
346 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
347 return alc_mux_select(codec, adc_idx,
348 ucontrol->value.enumerated.item[0], false);
352 * set up the input pin config (depending on the given auto-pin type)
354 static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
357 unsigned int val = PIN_IN;
359 if (auto_pin_type == AUTO_PIN_MIC) {
362 oldval = snd_hda_codec_read(codec, nid, 0,
363 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
364 pincap = snd_hda_query_pin_caps(codec, nid);
365 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
366 /* if the default pin setup is vref50, we give it priority */
367 if ((pincap & AC_PINCAP_VREF_80) && oldval != PIN_VREF50)
369 else if (pincap & AC_PINCAP_VREF_50)
371 else if (pincap & AC_PINCAP_VREF_100)
373 else if (pincap & AC_PINCAP_VREF_GRD)
376 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val);
380 * Append the given mixer and verb elements for the later use
381 * The mixer array is referred in build_controls(), and init_verbs are
384 static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
386 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
388 spec->mixers[spec->num_mixers++] = mix;
391 static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
393 if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
395 spec->init_verbs[spec->num_init_verbs++] = verb;
399 * GPIO setup tables, used in initialization
401 /* Enable GPIO mask and set output */
402 static const struct hda_verb alc_gpio1_init_verbs[] = {
403 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
404 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
405 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
409 static const struct hda_verb alc_gpio2_init_verbs[] = {
410 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
411 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
412 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
416 static const struct hda_verb alc_gpio3_init_verbs[] = {
417 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
418 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
419 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
424 * Fix hardware PLL issue
425 * On some codecs, the analog PLL gating control must be off while
426 * the default value is 1.
428 static void alc_fix_pll(struct hda_codec *codec)
430 struct alc_spec *spec = codec->spec;
435 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
437 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
438 AC_VERB_GET_PROC_COEF, 0);
441 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
443 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
444 val & ~(1 << spec->pll_coef_bit));
447 static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
448 unsigned int coef_idx, unsigned int coef_bit)
450 struct alc_spec *spec = codec->spec;
452 spec->pll_coef_idx = coef_idx;
453 spec->pll_coef_bit = coef_bit;
458 * Jack-reporting via input-jack layer
461 /* initialization of jacks; currently checks only a few known pins */
462 static int alc_init_jacks(struct hda_codec *codec)
464 #ifdef CONFIG_SND_HDA_INPUT_JACK
465 struct alc_spec *spec = codec->spec;
467 unsigned int hp_nid = spec->autocfg.hp_pins[0];
468 unsigned int mic_nid = spec->ext_mic_pin;
469 unsigned int dock_nid = spec->dock_mic_pin;
472 err = snd_hda_input_jack_add(codec, hp_nid,
473 SND_JACK_HEADPHONE, NULL);
476 snd_hda_input_jack_report(codec, hp_nid);
480 err = snd_hda_input_jack_add(codec, mic_nid,
481 SND_JACK_MICROPHONE, NULL);
484 snd_hda_input_jack_report(codec, mic_nid);
487 err = snd_hda_input_jack_add(codec, dock_nid,
488 SND_JACK_MICROPHONE, NULL);
491 snd_hda_input_jack_report(codec, dock_nid);
493 #endif /* CONFIG_SND_HDA_INPUT_JACK */
498 * Jack detections for HP auto-mute and mic-switch
501 /* check each pin in the given array; returns true if any of them is plugged */
502 static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
506 for (i = 0; i < num_pins; i++) {
507 hda_nid_t nid = pins[i];
510 snd_hda_input_jack_report(codec, nid);
511 present |= snd_hda_jack_detect(codec, nid);
516 /* standard HP/line-out auto-mute helper */
517 static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
518 bool mute, bool hp_out)
520 struct alc_spec *spec = codec->spec;
521 unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0;
522 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
525 for (i = 0; i < num_pins; i++) {
526 hda_nid_t nid = pins[i];
530 switch (spec->automute_mode) {
531 case ALC_AUTOMUTE_PIN:
532 /* don't reset VREF value in case it's controlling
533 * the amp (see alc861_fixup_asus_amp_vref_0f())
535 if (spec->keep_vref_in_automute) {
536 val = snd_hda_codec_read(codec, nid, 0,
537 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
542 snd_hda_codec_write(codec, nid, 0,
543 AC_VERB_SET_PIN_WIDGET_CONTROL,
546 case ALC_AUTOMUTE_AMP:
547 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
548 HDA_AMP_MUTE, mute_bits);
550 case ALC_AUTOMUTE_MIXER:
551 nid = spec->automute_mixer_nid[i];
554 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
555 HDA_AMP_MUTE, mute_bits);
556 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1,
557 HDA_AMP_MUTE, mute_bits);
563 /* Toggle outputs muting */
564 static void update_outputs(struct hda_codec *codec)
566 struct alc_spec *spec = codec->spec;
569 /* Control HP pins/amps depending on master_mute state;
570 * in general, HP pins/amps control should be enabled in all cases,
571 * but currently set only for master_mute, just to be safe
573 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
574 spec->autocfg.hp_pins, spec->master_mute, true);
576 if (!spec->automute_speaker)
579 on = spec->hp_jack_present | spec->line_jack_present;
580 on |= spec->master_mute;
581 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
582 spec->autocfg.speaker_pins, on, false);
584 /* toggle line-out mutes if needed, too */
585 /* if LO is a copy of either HP or Speaker, don't need to handle it */
586 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
587 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
589 if (!spec->automute_lo)
592 on = spec->hp_jack_present;
593 on |= spec->master_mute;
594 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
595 spec->autocfg.line_out_pins, on, false);
598 static void call_update_outputs(struct hda_codec *codec)
600 struct alc_spec *spec = codec->spec;
601 if (spec->automute_hook)
602 spec->automute_hook(codec);
604 update_outputs(codec);
607 /* standard HP-automute helper */
608 static void alc_hp_automute(struct hda_codec *codec)
610 struct alc_spec *spec = codec->spec;
612 spec->hp_jack_present =
613 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
614 spec->autocfg.hp_pins);
615 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
617 call_update_outputs(codec);
620 /* standard line-out-automute helper */
621 static void alc_line_automute(struct hda_codec *codec)
623 struct alc_spec *spec = codec->spec;
625 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
627 /* check LO jack only when it's different from HP */
628 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
631 spec->line_jack_present =
632 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
633 spec->autocfg.line_out_pins);
634 if (!spec->automute_speaker || !spec->detect_lo)
636 call_update_outputs(codec);
639 #define get_connection_index(codec, mux, nid) \
640 snd_hda_get_conn_index(codec, mux, nid, 0)
642 /* standard mic auto-switch helper */
643 static void alc_mic_automute(struct hda_codec *codec)
645 struct alc_spec *spec = codec->spec;
646 hda_nid_t *pins = spec->imux_pins;
648 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
650 if (snd_BUG_ON(!spec->adc_nids))
652 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
655 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
656 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
657 else if (spec->dock_mic_idx >= 0 &&
658 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
659 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
661 alc_mux_select(codec, 0, spec->int_mic_idx, false);
663 snd_hda_input_jack_report(codec, pins[spec->ext_mic_idx]);
664 if (spec->dock_mic_idx >= 0)
665 snd_hda_input_jack_report(codec, pins[spec->dock_mic_idx]);
668 /* unsolicited event for HP jack sensing */
669 static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
671 if (codec->vendor_id == 0x10ec0880)
677 alc_hp_automute(codec);
679 case ALC_FRONT_EVENT:
680 alc_line_automute(codec);
683 alc_mic_automute(codec);
688 /* call init functions of standard auto-mute helpers */
689 static void alc_inithook(struct hda_codec *codec)
691 alc_hp_automute(codec);
692 alc_line_automute(codec);
693 alc_mic_automute(codec);
696 /* additional initialization for ALC888 variants */
697 static void alc888_coef_init(struct hda_codec *codec)
701 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
702 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
703 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
704 if ((tmp & 0xf0) == 0x20)
706 snd_hda_codec_read(codec, 0x20, 0,
707 AC_VERB_SET_PROC_COEF, 0x830);
710 snd_hda_codec_read(codec, 0x20, 0,
711 AC_VERB_SET_PROC_COEF, 0x3030);
714 /* additional initialization for ALC889 variants */
715 static void alc889_coef_init(struct hda_codec *codec)
719 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
720 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
721 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
722 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
725 /* turn on/off EAPD control (only if available) */
726 static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
728 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
730 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
731 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
735 /* turn on/off EAPD controls of the codec */
736 static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
738 /* We currently only handle front, HP */
739 static hda_nid_t pins[] = {
740 0x0f, 0x10, 0x14, 0x15, 0
743 for (p = pins; *p; p++)
744 set_eapd(codec, *p, on);
747 /* generic shutup callback;
748 * just turning off EPAD and a little pause for avoiding pop-noise
750 static void alc_eapd_shutup(struct hda_codec *codec)
752 alc_auto_setup_eapd(codec, false);
756 /* generic EAPD initialization */
757 static void alc_auto_init_amp(struct hda_codec *codec, int type)
761 alc_auto_setup_eapd(codec, true);
764 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
767 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
770 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
772 case ALC_INIT_DEFAULT:
773 switch (codec->vendor_id) {
775 snd_hda_codec_write(codec, 0x1a, 0,
776 AC_VERB_SET_COEF_INDEX, 7);
777 tmp = snd_hda_codec_read(codec, 0x1a, 0,
778 AC_VERB_GET_PROC_COEF, 0);
779 snd_hda_codec_write(codec, 0x1a, 0,
780 AC_VERB_SET_COEF_INDEX, 7);
781 snd_hda_codec_write(codec, 0x1a, 0,
782 AC_VERB_SET_PROC_COEF,
791 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
792 alc889_coef_init(codec);
795 alc888_coef_init(codec);
797 #if 0 /* XXX: This may cause the silent output on speaker on some machines */
800 snd_hda_codec_write(codec, 0x20, 0,
801 AC_VERB_SET_COEF_INDEX, 7);
802 tmp = snd_hda_codec_read(codec, 0x20, 0,
803 AC_VERB_GET_PROC_COEF, 0);
804 snd_hda_codec_write(codec, 0x20, 0,
805 AC_VERB_SET_COEF_INDEX, 7);
806 snd_hda_codec_write(codec, 0x20, 0,
807 AC_VERB_SET_PROC_COEF,
817 * Auto-Mute mode mixer enum support
819 static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
820 struct snd_ctl_elem_info *uinfo)
822 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
823 struct alc_spec *spec = codec->spec;
824 static const char * const texts2[] = {
825 "Disabled", "Enabled"
827 static const char * const texts3[] = {
828 "Disabled", "Speaker Only", "Line-Out+Speaker"
830 const char * const *texts;
832 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
834 if (spec->automute_speaker_possible && spec->automute_lo_possible) {
835 uinfo->value.enumerated.items = 3;
838 uinfo->value.enumerated.items = 2;
841 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
842 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
843 strcpy(uinfo->value.enumerated.name,
844 texts[uinfo->value.enumerated.item]);
848 static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
849 struct snd_ctl_elem_value *ucontrol)
851 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
852 struct alc_spec *spec = codec->spec;
853 unsigned int val = 0;
854 if (spec->automute_speaker)
856 if (spec->automute_lo)
859 ucontrol->value.enumerated.item[0] = val;
863 static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
864 struct snd_ctl_elem_value *ucontrol)
866 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
867 struct alc_spec *spec = codec->spec;
869 switch (ucontrol->value.enumerated.item[0]) {
871 if (!spec->automute_speaker && !spec->automute_lo)
873 spec->automute_speaker = 0;
874 spec->automute_lo = 0;
877 if (spec->automute_speaker_possible) {
878 if (!spec->automute_lo && spec->automute_speaker)
880 spec->automute_speaker = 1;
881 spec->automute_lo = 0;
882 } else if (spec->automute_lo_possible) {
883 if (spec->automute_lo)
885 spec->automute_lo = 1;
890 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
892 if (spec->automute_speaker && spec->automute_lo)
894 spec->automute_speaker = 1;
895 spec->automute_lo = 1;
900 call_update_outputs(codec);
904 static const struct snd_kcontrol_new alc_automute_mode_enum = {
905 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
906 .name = "Auto-Mute Mode",
907 .info = alc_automute_mode_info,
908 .get = alc_automute_mode_get,
909 .put = alc_automute_mode_put,
912 static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec)
914 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
915 return snd_array_new(&spec->kctls);
918 static int alc_add_automute_mode_enum(struct hda_codec *codec)
920 struct alc_spec *spec = codec->spec;
921 struct snd_kcontrol_new *knew;
923 knew = alc_kcontrol_new(spec);
926 *knew = alc_automute_mode_enum;
927 knew->name = kstrdup("Auto-Mute Mode", GFP_KERNEL);
934 * Check the availability of HP/line-out auto-mute;
935 * Set up appropriately if really supported
937 static void alc_init_automute(struct hda_codec *codec)
939 struct alc_spec *spec = codec->spec;
940 struct auto_pin_cfg *cfg = &spec->autocfg;
946 if (cfg->line_out_pins[0])
948 if (cfg->speaker_pins[0])
950 if (present < 2) /* need two different output types */
953 if (!cfg->speaker_pins[0] &&
954 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
955 memcpy(cfg->speaker_pins, cfg->line_out_pins,
956 sizeof(cfg->speaker_pins));
957 cfg->speaker_outs = cfg->line_outs;
960 if (!cfg->hp_pins[0] &&
961 cfg->line_out_type == AUTO_PIN_HP_OUT) {
962 memcpy(cfg->hp_pins, cfg->line_out_pins,
963 sizeof(cfg->hp_pins));
964 cfg->hp_outs = cfg->line_outs;
967 spec->automute_mode = ALC_AUTOMUTE_PIN;
969 for (i = 0; i < cfg->hp_outs; i++) {
970 hda_nid_t nid = cfg->hp_pins[i];
971 if (!is_jack_detectable(codec, nid))
973 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
975 snd_hda_codec_write_cache(codec, nid, 0,
976 AC_VERB_SET_UNSOLICITED_ENABLE,
977 AC_USRSP_EN | ALC_HP_EVENT);
981 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
982 if (cfg->speaker_outs)
983 for (i = 0; i < cfg->line_outs; i++) {
984 hda_nid_t nid = cfg->line_out_pins[i];
985 if (!is_jack_detectable(codec, nid))
987 snd_printdd("realtek: Enable Line-Out "
988 "auto-muting on NID 0x%x\n", nid);
989 snd_hda_codec_write_cache(codec, nid, 0,
990 AC_VERB_SET_UNSOLICITED_ENABLE,
991 AC_USRSP_EN | ALC_FRONT_EVENT);
994 spec->automute_lo_possible = spec->detect_hp;
997 spec->automute_speaker_possible = cfg->speaker_outs &&
998 (spec->detect_hp || spec->detect_lo);
1000 spec->automute_lo = spec->automute_lo_possible;
1001 spec->automute_speaker = spec->automute_speaker_possible;
1003 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
1004 /* create a control for automute mode */
1005 alc_add_automute_mode_enum(codec);
1006 spec->unsol_event = alc_sku_unsol_event;
1010 /* return the position of NID in the list, or -1 if not found */
1011 static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1014 for (i = 0; i < nums; i++)
1020 /* check whether dynamic ADC-switching is available */
1021 static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
1023 struct alc_spec *spec = codec->spec;
1024 struct hda_input_mux *imux = &spec->private_imux[0];
1028 if (imux != spec->input_mux) /* no dynamic imux? */
1031 for (n = 0; n < spec->num_adc_nids; n++) {
1032 cap = spec->private_capsrc_nids[n];
1033 for (i = 0; i < imux->num_items; i++) {
1034 pin = spec->imux_pins[i];
1037 if (get_connection_index(codec, cap, pin) < 0)
1040 if (i >= imux->num_items)
1041 return true; /* no ADC-switch is needed */
1044 for (i = 0; i < imux->num_items; i++) {
1045 pin = spec->imux_pins[i];
1046 for (n = 0; n < spec->num_adc_nids; n++) {
1047 cap = spec->private_capsrc_nids[n];
1048 idx = get_connection_index(codec, cap, pin);
1050 imux->items[i].index = idx;
1051 spec->dyn_adc_idx[i] = n;
1057 snd_printdd("realtek: enabling ADC switching\n");
1058 spec->dyn_adc_switch = 1;
1062 /* rebuild imux for matching with the given auto-mic pins (if not yet) */
1063 static bool alc_rebuild_imux_for_auto_mic(struct hda_codec *codec)
1065 struct alc_spec *spec = codec->spec;
1066 struct hda_input_mux *imux;
1067 static char * const texts[3] = {
1068 "Mic", "Internal Mic", "Dock Mic"
1072 if (!spec->auto_mic)
1074 imux = &spec->private_imux[0];
1075 if (spec->input_mux == imux)
1077 spec->imux_pins[0] = spec->ext_mic_pin;
1078 spec->imux_pins[1] = spec->int_mic_pin;
1079 spec->imux_pins[2] = spec->dock_mic_pin;
1080 for (i = 0; i < 3; i++) {
1081 strcpy(imux->items[i].label, texts[i]);
1082 if (spec->imux_pins[i]) {
1083 hda_nid_t pin = spec->imux_pins[i];
1085 for (c = 0; c < spec->num_adc_nids; c++) {
1086 hda_nid_t cap = get_capsrc(spec, c);
1087 int idx = get_connection_index(codec, cap, pin);
1089 imux->items[i].index = idx;
1093 imux->num_items = i + 1;
1096 spec->num_mux_defs = 1;
1097 spec->input_mux = imux;
1101 /* check whether all auto-mic pins are valid; setup indices if OK */
1102 static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1104 struct alc_spec *spec = codec->spec;
1105 const struct hda_input_mux *imux;
1107 if (!spec->auto_mic)
1109 if (spec->auto_mic_valid_imux)
1110 return true; /* already checked */
1112 /* fill up imux indices */
1113 if (!alc_check_dyn_adc_switch(codec)) {
1118 imux = spec->input_mux;
1119 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1120 spec->imux_pins, imux->num_items);
1121 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1122 spec->imux_pins, imux->num_items);
1123 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1124 spec->imux_pins, imux->num_items);
1125 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1127 return false; /* no corresponding imux */
1130 snd_hda_codec_write_cache(codec, spec->ext_mic_pin, 0,
1131 AC_VERB_SET_UNSOLICITED_ENABLE,
1132 AC_USRSP_EN | ALC_MIC_EVENT);
1133 if (spec->dock_mic_pin)
1134 snd_hda_codec_write_cache(codec, spec->dock_mic_pin, 0,
1135 AC_VERB_SET_UNSOLICITED_ENABLE,
1136 AC_USRSP_EN | ALC_MIC_EVENT);
1138 spec->auto_mic_valid_imux = 1;
1144 * Check the availability of auto-mic switch;
1145 * Set up if really supported
1147 static void alc_init_auto_mic(struct hda_codec *codec)
1149 struct alc_spec *spec = codec->spec;
1150 struct auto_pin_cfg *cfg = &spec->autocfg;
1151 hda_nid_t fixed, ext, dock;
1154 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1156 fixed = ext = dock = 0;
1157 for (i = 0; i < cfg->num_inputs; i++) {
1158 hda_nid_t nid = cfg->inputs[i].pin;
1159 unsigned int defcfg;
1160 defcfg = snd_hda_codec_get_pincfg(codec, nid);
1161 switch (snd_hda_get_input_pin_attr(defcfg)) {
1162 case INPUT_PIN_ATTR_INT:
1164 return; /* already occupied */
1165 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1166 return; /* invalid type */
1169 case INPUT_PIN_ATTR_UNUSED:
1170 return; /* invalid entry */
1171 case INPUT_PIN_ATTR_DOCK:
1173 return; /* already occupied */
1174 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1175 return; /* invalid type */
1180 return; /* already occupied */
1181 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1182 return; /* invalid type */
1193 if (!is_jack_detectable(codec, ext))
1194 return; /* no unsol support */
1195 if (dock && !is_jack_detectable(codec, dock))
1196 return; /* no unsol support */
1198 /* check imux indices */
1199 spec->ext_mic_pin = ext;
1200 spec->int_mic_pin = fixed;
1201 spec->dock_mic_pin = dock;
1204 if (!alc_auto_mic_check_imux(codec))
1207 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1209 spec->unsol_event = alc_sku_unsol_event;
1212 /* check the availabilities of auto-mute and auto-mic switches */
1213 static void alc_auto_check_switches(struct hda_codec *codec)
1215 alc_init_automute(codec);
1216 alc_init_auto_mic(codec);
1220 * Realtek SSID verification
1223 /* Could be any non-zero and even value. When used as fixup, tells
1224 * the driver to ignore any present sku defines.
1226 #define ALC_FIXUP_SKU_IGNORE (2)
1228 static int alc_auto_parse_customize_define(struct hda_codec *codec)
1230 unsigned int ass, tmp, i;
1232 struct alc_spec *spec = codec->spec;
1234 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1236 if (spec->cdefine.fixup) {
1237 ass = spec->cdefine.sku_cfg;
1238 if (ass == ALC_FIXUP_SKU_IGNORE)
1243 ass = codec->subsystem_id & 0xffff;
1244 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
1248 if (codec->vendor_id == 0x10ec0260)
1250 ass = snd_hda_codec_get_pincfg(codec, nid);
1253 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1254 codec->chip_name, ass);
1260 for (i = 1; i < 16; i++) {
1264 if (((ass >> 16) & 0xf) != tmp)
1267 spec->cdefine.port_connectivity = ass >> 30;
1268 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1269 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1270 spec->cdefine.customization = ass >> 8;
1272 spec->cdefine.sku_cfg = ass;
1273 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1274 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1275 spec->cdefine.swap = (ass & 0x2) >> 1;
1276 spec->cdefine.override = ass & 0x1;
1278 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1279 nid, spec->cdefine.sku_cfg);
1280 snd_printd("SKU: port_connectivity=0x%x\n",
1281 spec->cdefine.port_connectivity);
1282 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1283 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1284 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1285 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1286 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1287 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1288 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1293 /* return true if the given NID is found in the list */
1294 static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1296 return find_idx_in_nid_list(nid, list, nums) >= 0;
1299 /* check subsystem ID and set up device-specific initialization;
1300 * return 1 if initialized, 0 if invalid SSID
1302 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1303 * 31 ~ 16 : Manufacture ID
1305 * 7 ~ 0 : Assembly ID
1306 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1308 static int alc_subsystem_id(struct hda_codec *codec,
1309 hda_nid_t porta, hda_nid_t porte,
1310 hda_nid_t portd, hda_nid_t porti)
1312 unsigned int ass, tmp, i;
1314 struct alc_spec *spec = codec->spec;
1316 if (spec->cdefine.fixup) {
1317 ass = spec->cdefine.sku_cfg;
1318 if (ass == ALC_FIXUP_SKU_IGNORE)
1323 ass = codec->subsystem_id & 0xffff;
1324 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1327 /* invalid SSID, check the special NID pin defcfg instead */
1329 * 31~30 : port connectivity
1332 * 19~16 : Check sum (15:1)
1337 if (codec->vendor_id == 0x10ec0260)
1339 ass = snd_hda_codec_get_pincfg(codec, nid);
1340 snd_printd("realtek: No valid SSID, "
1341 "checking pincfg 0x%08x for NID 0x%x\n",
1345 if ((ass >> 30) != 1) /* no physical connection */
1350 for (i = 1; i < 16; i++) {
1354 if (((ass >> 16) & 0xf) != tmp)
1357 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1358 ass & 0xffff, codec->vendor_id);
1362 * 2 : 0 --> Desktop, 1 --> Laptop
1363 * 3~5 : External Amplifier control
1366 tmp = (ass & 0x38) >> 3; /* external Amp control */
1369 spec->init_amp = ALC_INIT_GPIO1;
1372 spec->init_amp = ALC_INIT_GPIO2;
1375 spec->init_amp = ALC_INIT_GPIO3;
1379 spec->init_amp = ALC_INIT_DEFAULT;
1383 /* is laptop or Desktop and enable the function "Mute internal speaker
1384 * when the external headphone out jack is plugged"
1386 if (!(ass & 0x8000))
1389 * 10~8 : Jack location
1390 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1392 * 15 : 1 --> enable the function "Mute internal speaker
1393 * when the external headphone out jack is plugged"
1395 if (!spec->autocfg.hp_pins[0] &&
1396 !(spec->autocfg.line_out_pins[0] &&
1397 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
1399 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1410 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1411 spec->autocfg.line_outs))
1413 spec->autocfg.hp_pins[0] = nid;
1418 /* Check the validity of ALC subsystem-id
1419 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1420 static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
1422 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
1423 struct alc_spec *spec = codec->spec;
1424 snd_printd("realtek: "
1425 "Enable default setup for auto mode as fallback\n");
1426 spec->init_amp = ALC_INIT_DEFAULT;
1431 * Fix-up pin default configurations and add default verbs
1439 struct alc_model_fixup {
1450 const struct alc_pincfg *pins;
1451 const struct hda_verb *verbs;
1452 void (*func)(struct hda_codec *codec,
1453 const struct alc_fixup *fix,
1467 ALC_FIXUP_ACT_PRE_PROBE,
1468 ALC_FIXUP_ACT_PROBE,
1472 static void alc_apply_fixup(struct hda_codec *codec, int action)
1474 struct alc_spec *spec = codec->spec;
1475 int id = spec->fixup_id;
1476 #ifdef CONFIG_SND_DEBUG_VERBOSE
1477 const char *modelname = spec->fixup_name;
1481 if (!spec->fixup_list)
1485 const struct alc_fixup *fix = spec->fixup_list + id;
1486 const struct alc_pincfg *cfg;
1488 switch (fix->type) {
1490 if (action != ALC_FIXUP_ACT_PRE_PROBE || !fix->v.sku)
1492 snd_printdd(KERN_INFO "hda_codec: %s: "
1493 "Apply sku override for %s\n",
1494 codec->chip_name, modelname);
1495 spec->cdefine.sku_cfg = fix->v.sku;
1496 spec->cdefine.fixup = 1;
1498 case ALC_FIXUP_PINS:
1500 if (action != ALC_FIXUP_ACT_PRE_PROBE || !cfg)
1502 snd_printdd(KERN_INFO "hda_codec: %s: "
1503 "Apply pincfg for %s\n",
1504 codec->chip_name, modelname);
1505 for (; cfg->nid; cfg++)
1506 snd_hda_codec_set_pincfg(codec, cfg->nid,
1509 case ALC_FIXUP_VERBS:
1510 if (action != ALC_FIXUP_ACT_PROBE || !fix->v.verbs)
1512 snd_printdd(KERN_INFO "hda_codec: %s: "
1513 "Apply fix-verbs for %s\n",
1514 codec->chip_name, modelname);
1515 add_verb(codec->spec, fix->v.verbs);
1517 case ALC_FIXUP_FUNC:
1520 snd_printdd(KERN_INFO "hda_codec: %s: "
1521 "Apply fix-func for %s\n",
1522 codec->chip_name, modelname);
1523 fix->v.func(codec, fix, action);
1526 snd_printk(KERN_ERR "hda_codec: %s: "
1527 "Invalid fixup type %d\n",
1528 codec->chip_name, fix->type);
1539 static void alc_pick_fixup(struct hda_codec *codec,
1540 const struct alc_model_fixup *models,
1541 const struct snd_pci_quirk *quirk,
1542 const struct alc_fixup *fixlist)
1544 struct alc_spec *spec = codec->spec;
1546 const char *name = NULL;
1548 if (codec->modelname && models) {
1549 while (models->name) {
1550 if (!strcmp(codec->modelname, models->name)) {
1552 name = models->name;
1559 quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1562 #ifdef CONFIG_SND_DEBUG_VERBOSE
1568 spec->fixup_id = id;
1570 spec->fixup_list = fixlist;
1571 spec->fixup_name = name;
1576 * COEF access helper functions
1578 static int alc_read_coef_idx(struct hda_codec *codec,
1579 unsigned int coef_idx)
1582 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1584 val = snd_hda_codec_read(codec, 0x20, 0,
1585 AC_VERB_GET_PROC_COEF, 0);
1589 static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1590 unsigned int coef_val)
1592 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1594 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1598 /* a special bypass for COEF 0; read the cached value at the second time */
1599 static unsigned int alc_get_coef0(struct hda_codec *codec)
1601 struct alc_spec *spec = codec->spec;
1603 spec->coef0 = alc_read_coef_idx(codec, 0);
1608 * Digital I/O handling
1611 /* set right pin controls for digital I/O */
1612 static void alc_auto_init_digital(struct hda_codec *codec)
1614 struct alc_spec *spec = codec->spec;
1618 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1619 pin = spec->autocfg.dig_out_pins[i];
1622 snd_hda_codec_write(codec, pin, 0,
1623 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
1625 dac = spec->multiout.dig_out_nid;
1627 dac = spec->slave_dig_outs[i - 1];
1628 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
1630 snd_hda_codec_write(codec, dac, 0,
1631 AC_VERB_SET_AMP_GAIN_MUTE,
1634 pin = spec->autocfg.dig_in_pin;
1636 snd_hda_codec_write(codec, pin, 0,
1637 AC_VERB_SET_PIN_WIDGET_CONTROL,
1641 /* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1642 static void alc_auto_parse_digital(struct hda_codec *codec)
1644 struct alc_spec *spec = codec->spec;
1648 /* support multiple SPDIFs; the secondary is set up as a slave */
1650 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1652 err = snd_hda_get_connections(codec,
1653 spec->autocfg.dig_out_pins[i],
1654 conn, ARRAY_SIZE(conn));
1657 dig_nid = conn[0]; /* assume the first element is audio-out */
1659 spec->multiout.dig_out_nid = dig_nid;
1660 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1662 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
1663 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
1665 spec->slave_dig_outs[nums - 1] = dig_nid;
1670 if (spec->autocfg.dig_in_pin) {
1671 dig_nid = codec->start_nid;
1672 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1673 unsigned int wcaps = get_wcaps(codec, dig_nid);
1674 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1676 if (!(wcaps & AC_WCAP_DIGITAL))
1678 if (!(wcaps & AC_WCAP_CONN_LIST))
1680 err = get_connection_index(codec, dig_nid,
1681 spec->autocfg.dig_in_pin);
1683 spec->dig_in_nid = dig_nid;
1691 * capture mixer elements
1693 static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1694 struct snd_ctl_elem_info *uinfo)
1696 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1697 struct alc_spec *spec = codec->spec;
1701 mutex_lock(&codec->control_mutex);
1702 if (spec->vol_in_capsrc)
1703 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1705 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1706 kcontrol->private_value = val;
1707 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
1708 mutex_unlock(&codec->control_mutex);
1712 static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1713 unsigned int size, unsigned int __user *tlv)
1715 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1716 struct alc_spec *spec = codec->spec;
1720 mutex_lock(&codec->control_mutex);
1721 if (spec->vol_in_capsrc)
1722 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1724 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1725 kcontrol->private_value = val;
1726 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
1727 mutex_unlock(&codec->control_mutex);
1731 typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1732 struct snd_ctl_elem_value *ucontrol);
1734 static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1735 struct snd_ctl_elem_value *ucontrol,
1736 getput_call_t func, bool check_adc_switch)
1738 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1739 struct alc_spec *spec = codec->spec;
1742 mutex_lock(&codec->control_mutex);
1743 if (check_adc_switch && spec->dyn_adc_switch) {
1744 for (i = 0; i < spec->num_adc_nids; i++) {
1745 kcontrol->private_value =
1746 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1748 err = func(kcontrol, ucontrol);
1753 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1754 if (spec->vol_in_capsrc)
1755 kcontrol->private_value =
1756 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1759 kcontrol->private_value =
1760 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1762 err = func(kcontrol, ucontrol);
1765 mutex_unlock(&codec->control_mutex);
1769 static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1770 struct snd_ctl_elem_value *ucontrol)
1772 return alc_cap_getput_caller(kcontrol, ucontrol,
1773 snd_hda_mixer_amp_volume_get, false);
1776 static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1777 struct snd_ctl_elem_value *ucontrol)
1779 return alc_cap_getput_caller(kcontrol, ucontrol,
1780 snd_hda_mixer_amp_volume_put, true);
1783 /* capture mixer elements */
1784 #define alc_cap_sw_info snd_ctl_boolean_stereo_info
1786 static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1787 struct snd_ctl_elem_value *ucontrol)
1789 return alc_cap_getput_caller(kcontrol, ucontrol,
1790 snd_hda_mixer_amp_switch_get, false);
1793 static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1794 struct snd_ctl_elem_value *ucontrol)
1796 return alc_cap_getput_caller(kcontrol, ucontrol,
1797 snd_hda_mixer_amp_switch_put, true);
1800 #define _DEFINE_CAPMIX(num) \
1802 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1803 .name = "Capture Switch", \
1804 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1806 .info = alc_cap_sw_info, \
1807 .get = alc_cap_sw_get, \
1808 .put = alc_cap_sw_put, \
1811 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1812 .name = "Capture Volume", \
1813 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1814 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1815 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1817 .info = alc_cap_vol_info, \
1818 .get = alc_cap_vol_get, \
1819 .put = alc_cap_vol_put, \
1820 .tlv = { .c = alc_cap_vol_tlv }, \
1823 #define _DEFINE_CAPSRC(num) \
1825 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1826 /* .name = "Capture Source", */ \
1827 .name = "Input Source", \
1829 .info = alc_mux_enum_info, \
1830 .get = alc_mux_enum_get, \
1831 .put = alc_mux_enum_put, \
1834 #define DEFINE_CAPMIX(num) \
1835 static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
1836 _DEFINE_CAPMIX(num), \
1837 _DEFINE_CAPSRC(num), \
1841 #define DEFINE_CAPMIX_NOSRC(num) \
1842 static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
1843 _DEFINE_CAPMIX(num), \
1847 /* up to three ADCs */
1851 DEFINE_CAPMIX_NOSRC(1);
1852 DEFINE_CAPMIX_NOSRC(2);
1853 DEFINE_CAPMIX_NOSRC(3);
1856 * virtual master controls
1860 * slave controls for virtual master
1862 static const char * const alc_slave_vols[] = {
1863 "Front Playback Volume",
1864 "Surround Playback Volume",
1865 "Center Playback Volume",
1866 "LFE Playback Volume",
1867 "Side Playback Volume",
1868 "Headphone Playback Volume",
1869 "Speaker Playback Volume",
1870 "Mono Playback Volume",
1871 "Line-Out Playback Volume",
1872 "PCM Playback Volume",
1876 static const char * const alc_slave_sws[] = {
1877 "Front Playback Switch",
1878 "Surround Playback Switch",
1879 "Center Playback Switch",
1880 "LFE Playback Switch",
1881 "Side Playback Switch",
1882 "Headphone Playback Switch",
1883 "Speaker Playback Switch",
1884 "Mono Playback Switch",
1885 "IEC958 Playback Switch",
1886 "Line-Out Playback Switch",
1887 "PCM Playback Switch",
1892 * build control elements
1895 #define NID_MAPPING (-1)
1897 #define SUBDEV_SPEAKER_ (0 << 6)
1898 #define SUBDEV_HP_ (1 << 6)
1899 #define SUBDEV_LINE_ (2 << 6)
1900 #define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1901 #define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1902 #define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1904 static void alc_free_kctls(struct hda_codec *codec);
1906 #ifdef CONFIG_SND_HDA_INPUT_BEEP
1907 /* additional beep mixers; the actual parameters are overwritten at build */
1908 static const struct snd_kcontrol_new alc_beep_mixer[] = {
1909 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
1910 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
1915 static int alc_build_controls(struct hda_codec *codec)
1917 struct alc_spec *spec = codec->spec;
1918 struct snd_kcontrol *kctl = NULL;
1919 const struct snd_kcontrol_new *knew;
1924 for (i = 0; i < spec->num_mixers; i++) {
1925 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1929 if (spec->cap_mixer) {
1930 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1934 if (spec->multiout.dig_out_nid) {
1935 err = snd_hda_create_spdif_out_ctls(codec,
1936 spec->multiout.dig_out_nid,
1937 spec->multiout.dig_out_nid);
1940 if (!spec->no_analog) {
1941 err = snd_hda_create_spdif_share_sw(codec,
1945 spec->multiout.share_spdif = 1;
1948 if (spec->dig_in_nid) {
1949 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1954 #ifdef CONFIG_SND_HDA_INPUT_BEEP
1955 /* create beep controls if needed */
1956 if (spec->beep_amp) {
1957 const struct snd_kcontrol_new *knew;
1958 for (knew = alc_beep_mixer; knew->name; knew++) {
1959 struct snd_kcontrol *kctl;
1960 kctl = snd_ctl_new1(knew, codec);
1963 kctl->private_value = spec->beep_amp;
1964 err = snd_hda_ctl_add(codec, 0, kctl);
1971 /* if we have no master control, let's create it */
1972 if (!spec->no_analog &&
1973 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1974 unsigned int vmaster_tlv[4];
1975 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
1976 HDA_OUTPUT, vmaster_tlv);
1977 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1978 vmaster_tlv, alc_slave_vols);
1982 if (!spec->no_analog &&
1983 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1984 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1985 NULL, alc_slave_sws);
1990 /* assign Capture Source enums to NID */
1991 if (spec->capsrc_nids || spec->adc_nids) {
1992 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
1994 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1995 for (i = 0; kctl && i < kctl->count; i++) {
1996 err = snd_hda_add_nid(codec, kctl, i,
1997 get_capsrc(spec, i));
2002 if (spec->cap_mixer && spec->adc_nids) {
2003 const char *kname = kctl ? kctl->id.name : NULL;
2004 for (knew = spec->cap_mixer; knew->name; knew++) {
2005 if (kname && strcmp(knew->name, kname) == 0)
2007 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
2008 for (i = 0; kctl && i < kctl->count; i++) {
2009 err = snd_hda_add_nid(codec, kctl, i,
2017 /* other nid->control mapping */
2018 for (i = 0; i < spec->num_mixers; i++) {
2019 for (knew = spec->mixers[i]; knew->name; knew++) {
2020 if (knew->iface != NID_MAPPING)
2022 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
2025 u = knew->subdevice;
2026 for (j = 0; j < 4; j++, u >>= 8) {
2031 case SUBDEV_SPEAKER_:
2032 nid = spec->autocfg.speaker_pins[nid];
2035 nid = spec->autocfg.line_out_pins[nid];
2038 nid = spec->autocfg.hp_pins[nid];
2043 err = snd_hda_add_nid(codec, kctl, 0, nid);
2047 u = knew->private_value;
2048 for (j = 0; j < 4; j++, u >>= 8) {
2052 err = snd_hda_add_nid(codec, kctl, 0, nid);
2059 alc_free_kctls(codec); /* no longer needed */
2069 static void alc_init_special_input_src(struct hda_codec *codec);
2070 static int alc269_fill_coef(struct hda_codec *codec);
2072 static int alc_init(struct hda_codec *codec)
2074 struct alc_spec *spec = codec->spec;
2077 if (codec->vendor_id == 0x10ec0269)
2078 alc269_fill_coef(codec);
2081 alc_auto_init_amp(codec, spec->init_amp);
2083 for (i = 0; i < spec->num_init_verbs; i++)
2084 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2085 alc_init_special_input_src(codec);
2087 if (spec->init_hook)
2088 spec->init_hook(codec);
2090 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2092 hda_call_check_power_status(codec, 0x01);
2096 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2098 struct alc_spec *spec = codec->spec;
2100 if (spec->unsol_event)
2101 spec->unsol_event(codec, res);
2104 #ifdef CONFIG_SND_HDA_POWER_SAVE
2105 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2107 struct alc_spec *spec = codec->spec;
2108 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2113 * Analog playback callbacks
2115 static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
2116 struct hda_codec *codec,
2117 struct snd_pcm_substream *substream)
2119 struct alc_spec *spec = codec->spec;
2120 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2124 static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2125 struct hda_codec *codec,
2126 unsigned int stream_tag,
2127 unsigned int format,
2128 struct snd_pcm_substream *substream)
2130 struct alc_spec *spec = codec->spec;
2131 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2132 stream_tag, format, substream);
2135 static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2136 struct hda_codec *codec,
2137 struct snd_pcm_substream *substream)
2139 struct alc_spec *spec = codec->spec;
2140 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2146 static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2147 struct hda_codec *codec,
2148 struct snd_pcm_substream *substream)
2150 struct alc_spec *spec = codec->spec;
2151 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2154 static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2155 struct hda_codec *codec,
2156 unsigned int stream_tag,
2157 unsigned int format,
2158 struct snd_pcm_substream *substream)
2160 struct alc_spec *spec = codec->spec;
2161 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2162 stream_tag, format, substream);
2165 static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2166 struct hda_codec *codec,
2167 struct snd_pcm_substream *substream)
2169 struct alc_spec *spec = codec->spec;
2170 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2173 static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2174 struct hda_codec *codec,
2175 struct snd_pcm_substream *substream)
2177 struct alc_spec *spec = codec->spec;
2178 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2184 static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2185 struct hda_codec *codec,
2186 unsigned int stream_tag,
2187 unsigned int format,
2188 struct snd_pcm_substream *substream)
2190 struct alc_spec *spec = codec->spec;
2192 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
2193 stream_tag, 0, format);
2197 static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2198 struct hda_codec *codec,
2199 struct snd_pcm_substream *substream)
2201 struct alc_spec *spec = codec->spec;
2203 snd_hda_codec_cleanup_stream(codec,
2204 spec->adc_nids[substream->number + 1]);
2208 /* analog capture with dynamic dual-adc changes */
2209 static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2210 struct hda_codec *codec,
2211 unsigned int stream_tag,
2212 unsigned int format,
2213 struct snd_pcm_substream *substream)
2215 struct alc_spec *spec = codec->spec;
2216 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
2217 spec->cur_adc_stream_tag = stream_tag;
2218 spec->cur_adc_format = format;
2219 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2223 static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2224 struct hda_codec *codec,
2225 struct snd_pcm_substream *substream)
2227 struct alc_spec *spec = codec->spec;
2228 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2233 static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
2237 .nid = 0, /* fill later */
2239 .prepare = dyn_adc_capture_pcm_prepare,
2240 .cleanup = dyn_adc_capture_pcm_cleanup
2246 static const struct hda_pcm_stream alc_pcm_analog_playback = {
2250 /* NID is set in alc_build_pcms */
2252 .open = alc_playback_pcm_open,
2253 .prepare = alc_playback_pcm_prepare,
2254 .cleanup = alc_playback_pcm_cleanup
2258 static const struct hda_pcm_stream alc_pcm_analog_capture = {
2262 /* NID is set in alc_build_pcms */
2265 static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
2269 /* NID is set in alc_build_pcms */
2272 static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
2273 .substreams = 2, /* can be overridden */
2276 /* NID is set in alc_build_pcms */
2278 .prepare = alc_alt_capture_pcm_prepare,
2279 .cleanup = alc_alt_capture_pcm_cleanup
2283 static const struct hda_pcm_stream alc_pcm_digital_playback = {
2287 /* NID is set in alc_build_pcms */
2289 .open = alc_dig_playback_pcm_open,
2290 .close = alc_dig_playback_pcm_close,
2291 .prepare = alc_dig_playback_pcm_prepare,
2292 .cleanup = alc_dig_playback_pcm_cleanup
2296 static const struct hda_pcm_stream alc_pcm_digital_capture = {
2300 /* NID is set in alc_build_pcms */
2303 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
2304 static const struct hda_pcm_stream alc_pcm_null_stream = {
2310 static int alc_build_pcms(struct hda_codec *codec)
2312 struct alc_spec *spec = codec->spec;
2313 struct hda_pcm *info = spec->pcm_rec;
2314 const struct hda_pcm_stream *p;
2315 bool have_multi_adcs;
2318 codec->num_pcms = 1;
2319 codec->pcm_info = info;
2321 if (spec->no_analog)
2324 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2325 "%s Analog", codec->chip_name);
2326 info->name = spec->stream_name_analog;
2328 if (spec->multiout.dac_nids > 0) {
2329 p = spec->stream_analog_playback;
2331 p = &alc_pcm_analog_playback;
2332 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2333 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2335 if (spec->adc_nids) {
2336 p = spec->stream_analog_capture;
2338 if (spec->dyn_adc_switch)
2339 p = &dyn_adc_pcm_analog_capture;
2341 p = &alc_pcm_analog_capture;
2343 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2344 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2347 if (spec->channel_mode) {
2348 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2349 for (i = 0; i < spec->num_channel_mode; i++) {
2350 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2351 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2357 /* SPDIF for stream index #1 */
2358 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2359 snprintf(spec->stream_name_digital,
2360 sizeof(spec->stream_name_digital),
2361 "%s Digital", codec->chip_name);
2362 codec->num_pcms = 2;
2363 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
2364 info = spec->pcm_rec + 1;
2365 info->name = spec->stream_name_digital;
2366 if (spec->dig_out_type)
2367 info->pcm_type = spec->dig_out_type;
2369 info->pcm_type = HDA_PCM_TYPE_SPDIF;
2370 if (spec->multiout.dig_out_nid) {
2371 p = spec->stream_digital_playback;
2373 p = &alc_pcm_digital_playback;
2374 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2375 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2377 if (spec->dig_in_nid) {
2378 p = spec->stream_digital_capture;
2380 p = &alc_pcm_digital_capture;
2381 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2382 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2384 /* FIXME: do we need this for all Realtek codec models? */
2385 codec->spdif_status_reset = 1;
2388 if (spec->no_analog)
2391 /* If the use of more than one ADC is requested for the current
2392 * model, configure a second analog capture-only PCM.
2394 have_multi_adcs = (spec->num_adc_nids > 1) &&
2395 !spec->dyn_adc_switch && !spec->auto_mic &&
2396 (!spec->input_mux || spec->input_mux->num_items > 1);
2397 /* Additional Analaog capture for index #2 */
2398 if (spec->alt_dac_nid || have_multi_adcs) {
2399 codec->num_pcms = 3;
2400 info = spec->pcm_rec + 2;
2401 info->name = spec->stream_name_analog;
2402 if (spec->alt_dac_nid) {
2403 p = spec->stream_analog_alt_playback;
2405 p = &alc_pcm_analog_alt_playback;
2406 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2407 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2410 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2411 alc_pcm_null_stream;
2412 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2414 if (have_multi_adcs) {
2415 p = spec->stream_analog_alt_capture;
2417 p = &alc_pcm_analog_alt_capture;
2418 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2419 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2421 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2422 spec->num_adc_nids - 1;
2424 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2425 alc_pcm_null_stream;
2426 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
2433 static inline void alc_shutup(struct hda_codec *codec)
2435 struct alc_spec *spec = codec->spec;
2437 if (spec && spec->shutup)
2438 spec->shutup(codec);
2439 snd_hda_shutup_pins(codec);
2442 static void alc_free_kctls(struct hda_codec *codec)
2444 struct alc_spec *spec = codec->spec;
2446 if (spec->kctls.list) {
2447 struct snd_kcontrol_new *kctl = spec->kctls.list;
2449 for (i = 0; i < spec->kctls.used; i++)
2450 kfree(kctl[i].name);
2452 snd_array_free(&spec->kctls);
2455 static void alc_free_bind_ctls(struct hda_codec *codec)
2457 struct alc_spec *spec = codec->spec;
2458 if (spec->bind_ctls.list) {
2459 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2461 for (i = 0; i < spec->bind_ctls.used; i++)
2464 snd_array_free(&spec->bind_ctls);
2467 static void alc_free(struct hda_codec *codec)
2469 struct alc_spec *spec = codec->spec;
2475 snd_hda_input_jack_free(codec);
2476 alc_free_kctls(codec);
2477 alc_free_bind_ctls(codec);
2479 snd_hda_detach_beep_device(codec);
2482 #ifdef CONFIG_SND_HDA_POWER_SAVE
2483 static void alc_power_eapd(struct hda_codec *codec)
2485 alc_auto_setup_eapd(codec, false);
2488 static int alc_suspend(struct hda_codec *codec, pm_message_t state)
2490 struct alc_spec *spec = codec->spec;
2492 if (spec && spec->power_hook)
2493 spec->power_hook(codec);
2499 static int alc_resume(struct hda_codec *codec)
2501 msleep(150); /* to avoid pop noise */
2502 codec->patch_ops.init(codec);
2503 snd_hda_codec_resume_amp(codec);
2504 snd_hda_codec_resume_cache(codec);
2505 hda_call_check_power_status(codec, 0x01);
2512 static const struct hda_codec_ops alc_patch_ops = {
2513 .build_controls = alc_build_controls,
2514 .build_pcms = alc_build_pcms,
2517 .unsol_event = alc_unsol_event,
2519 .resume = alc_resume,
2521 #ifdef CONFIG_SND_HDA_POWER_SAVE
2522 .suspend = alc_suspend,
2523 .check_power_status = alc_check_power_status,
2525 .reboot_notify = alc_shutup,
2528 /* replace the codec chip_name with the given string */
2529 static int alc_codec_rename(struct hda_codec *codec, const char *name)
2531 kfree(codec->chip_name);
2532 codec->chip_name = kstrdup(name, GFP_KERNEL);
2533 if (!codec->chip_name) {
2541 * Rename codecs appropriately from COEF value
2543 struct alc_codec_rename_table {
2544 unsigned int vendor_id;
2545 unsigned short coef_mask;
2546 unsigned short coef_bits;
2550 static struct alc_codec_rename_table rename_tbl[] = {
2551 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2552 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2553 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2554 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2555 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2556 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2557 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
2558 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2559 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2560 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2561 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2562 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2563 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2564 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2565 { } /* terminator */
2568 static int alc_codec_rename_from_preset(struct hda_codec *codec)
2570 const struct alc_codec_rename_table *p;
2572 for (p = rename_tbl; p->vendor_id; p++) {
2573 if (p->vendor_id != codec->vendor_id)
2575 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
2576 return alc_codec_rename(codec, p->name);
2582 * Automatic parse of I/O pins from the BIOS configuration
2587 ALC_CTL_WIDGET_MUTE,
2592 static const struct snd_kcontrol_new alc_control_templates[] = {
2593 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2594 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2595 HDA_BIND_MUTE(NULL, 0, 0, 0),
2596 HDA_BIND_VOL(NULL, 0),
2597 HDA_BIND_SW(NULL, 0),
2600 /* add dynamic controls */
2601 static int add_control(struct alc_spec *spec, int type, const char *name,
2602 int cidx, unsigned long val)
2604 struct snd_kcontrol_new *knew;
2606 knew = alc_kcontrol_new(spec);
2609 *knew = alc_control_templates[type];
2610 knew->name = kstrdup(name, GFP_KERNEL);
2614 if (get_amp_nid_(val))
2615 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
2616 knew->private_value = val;
2620 static int add_control_with_pfx(struct alc_spec *spec, int type,
2621 const char *pfx, const char *dir,
2622 const char *sfx, int cidx, unsigned long val)
2625 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
2626 return add_control(spec, type, name, cidx, val);
2629 #define add_pb_vol_ctrl(spec, type, pfx, val) \
2630 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2631 #define add_pb_sw_ctrl(spec, type, pfx, val) \
2632 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2633 #define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2634 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2635 #define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2636 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
2638 static const char * const channel_name[4] = {
2639 "Front", "Surround", "CLFE", "Side"
2642 static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2643 bool can_be_master, int *index)
2645 struct auto_pin_cfg *cfg = &spec->autocfg;
2648 if (cfg->line_outs == 1 && !spec->multi_ios &&
2649 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
2652 switch (cfg->line_out_type) {
2653 case AUTO_PIN_SPEAKER_OUT:
2654 if (cfg->line_outs == 1)
2656 if (cfg->line_outs == 2)
2657 return ch ? "Bass Speaker" : "Speaker";
2659 case AUTO_PIN_HP_OUT:
2660 /* for multi-io case, only the primary out */
2661 if (ch && spec->multi_ios)
2666 if (cfg->line_outs == 1 && !spec->multi_ios)
2670 if (ch >= ARRAY_SIZE(channel_name)) {
2675 return channel_name[ch];
2678 /* create input playback/capture controls for the given pin */
2679 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
2680 const char *ctlname, int ctlidx,
2681 int idx, hda_nid_t mix_nid)
2685 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
2686 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2689 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
2690 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2696 static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
2698 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2699 return (pincap & AC_PINCAP_IN) != 0;
2702 /* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
2703 static int alc_auto_fill_adc_caps(struct hda_codec *codec)
2705 struct alc_spec *spec = codec->spec;
2707 hda_nid_t *adc_nids = spec->private_adc_nids;
2708 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2709 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
2712 nid = codec->start_nid;
2713 for (i = 0; i < codec->num_nodes; i++, nid++) {
2715 const hda_nid_t *list;
2716 unsigned int caps = get_wcaps(codec, nid);
2717 int type = get_wcaps_type(caps);
2719 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2721 adc_nids[nums] = nid;
2722 cap_nids[nums] = nid;
2726 type = get_wcaps_type(get_wcaps(codec, src));
2727 if (type == AC_WID_PIN)
2729 if (type == AC_WID_AUD_SEL) {
2730 cap_nids[nums] = src;
2733 n = snd_hda_get_conn_list(codec, src, &list);
2735 cap_nids[nums] = src;
2741 if (++nums >= max_nums)
2744 spec->adc_nids = spec->private_adc_nids;
2745 spec->capsrc_nids = spec->private_capsrc_nids;
2746 spec->num_adc_nids = nums;
2750 /* create playback/capture controls for input pins */
2751 static int alc_auto_create_input_ctls(struct hda_codec *codec)
2753 struct alc_spec *spec = codec->spec;
2754 const struct auto_pin_cfg *cfg = &spec->autocfg;
2755 hda_nid_t mixer = spec->mixer_nid;
2756 struct hda_input_mux *imux = &spec->private_imux[0];
2758 int i, c, err, idx, type_idx = 0;
2759 const char *prev_label = NULL;
2761 num_adcs = alc_auto_fill_adc_caps(codec);
2765 for (i = 0; i < cfg->num_inputs; i++) {
2769 pin = cfg->inputs[i].pin;
2770 if (!alc_is_input_pin(codec, pin))
2773 label = hda_get_autocfg_input_label(codec, cfg, i);
2774 if (prev_label && !strcmp(label, prev_label))
2781 idx = get_connection_index(codec, mixer, pin);
2783 err = new_analog_input(spec, pin,
2791 for (c = 0; c < num_adcs; c++) {
2792 hda_nid_t cap = get_capsrc(spec, c);
2793 idx = get_connection_index(codec, cap, pin);
2795 spec->imux_pins[imux->num_items] = pin;
2796 snd_hda_add_imux_item(imux, label, idx, NULL);
2802 spec->num_mux_defs = 1;
2803 spec->input_mux = imux;
2808 static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
2809 unsigned int pin_type)
2811 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2814 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2815 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2819 static int get_pin_type(int line_out_type)
2821 if (line_out_type == AUTO_PIN_HP_OUT)
2827 static void alc_auto_init_analog_input(struct hda_codec *codec)
2829 struct alc_spec *spec = codec->spec;
2830 struct auto_pin_cfg *cfg = &spec->autocfg;
2833 for (i = 0; i < cfg->num_inputs; i++) {
2834 hda_nid_t nid = cfg->inputs[i].pin;
2835 if (alc_is_input_pin(codec, nid)) {
2836 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
2837 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
2838 snd_hda_codec_write(codec, nid, 0,
2839 AC_VERB_SET_AMP_GAIN_MUTE,
2844 /* mute all loopback inputs */
2845 if (spec->mixer_nid) {
2846 int nums = snd_hda_get_conn_list(codec, spec->mixer_nid, NULL);
2847 for (i = 0; i < nums; i++)
2848 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2849 AC_VERB_SET_AMP_GAIN_MUTE,
2854 /* convert from MIX nid to DAC */
2855 static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid)
2860 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT)
2862 num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list));
2863 for (i = 0; i < num; i++) {
2864 if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT)
2870 /* go down to the selector widget before the mixer */
2871 static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin)
2874 int num = snd_hda_get_connections(codec, pin, srcs,
2877 get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL)
2882 /* get MIX nid connected to the given pin targeted to DAC */
2883 static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
2889 pin = alc_go_down_to_selector(codec, pin);
2890 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2891 for (i = 0; i < num; i++) {
2892 if (alc_auto_mix_to_dac(codec, mix[i]) == dac)
2898 /* select the connection from pin to DAC if needed */
2899 static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin,
2905 pin = alc_go_down_to_selector(codec, pin);
2906 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2909 for (i = 0; i < num; i++) {
2910 if (alc_auto_mix_to_dac(codec, mix[i]) == dac) {
2911 snd_hda_codec_update_cache(codec, pin, 0,
2912 AC_VERB_SET_CONNECT_SEL, i);
2919 /* look for an empty DAC slot */
2920 static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
2922 struct alc_spec *spec = codec->spec;
2926 pin = alc_go_down_to_selector(codec, pin);
2927 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
2928 for (i = 0; i < num; i++) {
2929 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
2932 if (found_in_nid_list(nid, spec->multiout.dac_nids,
2933 ARRAY_SIZE(spec->private_dac_nids)))
2935 if (found_in_nid_list(nid, spec->multiout.hp_out_nid,
2936 ARRAY_SIZE(spec->multiout.hp_out_nid)))
2938 if (found_in_nid_list(nid, spec->multiout.extra_out_nid,
2939 ARRAY_SIZE(spec->multiout.extra_out_nid)))
2946 static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
2948 hda_nid_t sel = alc_go_down_to_selector(codec, pin);
2949 if (snd_hda_get_conn_list(codec, sel, NULL) == 1)
2950 return alc_auto_look_for_dac(codec, pin);
2954 /* return 0 if no possible DAC is found, 1 if one or more found */
2955 static int alc_auto_fill_extra_dacs(struct hda_codec *codec, int num_outs,
2956 const hda_nid_t *pins, hda_nid_t *dacs)
2960 if (num_outs && !dacs[0]) {
2961 dacs[0] = alc_auto_look_for_dac(codec, pins[0]);
2966 for (i = 1; i < num_outs; i++)
2967 dacs[i] = get_dac_if_single(codec, pins[i]);
2968 for (i = 1; i < num_outs; i++) {
2970 dacs[i] = alc_auto_look_for_dac(codec, pins[i]);
2975 static int alc_auto_fill_multi_ios(struct hda_codec *codec,
2976 unsigned int location);
2978 /* fill in the dac_nids table from the parsed pin configuration */
2979 static int alc_auto_fill_dac_nids(struct hda_codec *codec)
2981 struct alc_spec *spec = codec->spec;
2982 struct auto_pin_cfg *cfg = &spec->autocfg;
2983 bool redone = false;
2987 /* set num_dacs once to full for alc_auto_look_for_dac() */
2988 spec->multiout.num_dacs = cfg->line_outs;
2989 spec->multiout.hp_out_nid[0] = 0;
2990 spec->multiout.extra_out_nid[0] = 0;
2991 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
2992 spec->multiout.dac_nids = spec->private_dac_nids;
2993 spec->multi_ios = 0;
2995 /* fill hard-wired DACs first */
2997 for (i = 0; i < cfg->line_outs; i++)
2998 spec->private_dac_nids[i] =
2999 get_dac_if_single(codec, cfg->line_out_pins[i]);
3001 spec->multiout.hp_out_nid[0] =
3002 get_dac_if_single(codec, cfg->hp_pins[0]);
3003 if (cfg->speaker_outs)
3004 spec->multiout.extra_out_nid[0] =
3005 get_dac_if_single(codec, cfg->speaker_pins[0]);
3008 for (i = 0; i < cfg->line_outs; i++) {
3009 hda_nid_t pin = cfg->line_out_pins[i];
3010 if (spec->private_dac_nids[i])
3012 spec->private_dac_nids[i] = alc_auto_look_for_dac(codec, pin);
3013 if (!spec->private_dac_nids[i] && !redone) {
3014 /* if we can't find primary DACs, re-probe without
3015 * checking the hard-wired DACs
3022 /* re-count num_dacs and squash invalid entries */
3023 spec->multiout.num_dacs = 0;
3024 for (i = 0; i < cfg->line_outs; i++) {
3025 if (spec->private_dac_nids[i])
3026 spec->multiout.num_dacs++;
3028 memmove(spec->private_dac_nids + i,
3029 spec->private_dac_nids + i + 1,
3030 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
3031 spec->private_dac_nids[cfg->line_outs - 1] = 0;
3035 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3036 /* try to fill multi-io first */
3037 unsigned int location, defcfg;
3040 defcfg = snd_hda_codec_get_pincfg(codec, cfg->line_out_pins[0]);
3041 location = get_defcfg_location(defcfg);
3043 num_pins = alc_auto_fill_multi_ios(codec, location);
3045 spec->multi_ios = num_pins;
3046 spec->ext_channel_count = 2;
3047 spec->multiout.num_dacs = num_pins + 1;
3051 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
3052 alc_auto_fill_extra_dacs(codec, cfg->hp_outs, cfg->hp_pins,
3053 spec->multiout.hp_out_nid);
3054 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3055 int err = alc_auto_fill_extra_dacs(codec, cfg->speaker_outs,
3057 spec->multiout.extra_out_nid);
3058 /* if no speaker volume is assigned, try again as the primary
3061 if (!err && cfg->speaker_outs > 0 &&
3062 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3063 cfg->hp_outs = cfg->line_outs;
3064 memcpy(cfg->hp_pins, cfg->line_out_pins,
3065 sizeof(cfg->hp_pins));
3066 cfg->line_outs = cfg->speaker_outs;
3067 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3068 sizeof(cfg->speaker_pins));
3069 cfg->speaker_outs = 0;
3070 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3071 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
3080 static inline unsigned int get_ctl_pos(unsigned int data)
3082 hda_nid_t nid = get_amp_nid_(data);
3084 if (snd_BUG_ON(nid >= MAX_VOL_NIDS))
3086 dir = get_amp_direction_(data);
3087 return (nid << 1) | dir;
3090 #define is_ctl_used(bits, data) \
3091 test_bit(get_ctl_pos(data), bits)
3092 #define mark_ctl_usage(bits, data) \
3093 set_bit(get_ctl_pos(data), bits)
3095 static int alc_auto_add_vol_ctl(struct hda_codec *codec,
3096 const char *pfx, int cidx,
3097 hda_nid_t nid, unsigned int chs)
3099 struct alc_spec *spec = codec->spec;
3103 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3104 if (is_ctl_used(spec->vol_ctls, val) && chs != 2) /* exclude LFE */
3106 mark_ctl_usage(spec->vol_ctls, val);
3107 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
3111 #define alc_auto_add_stereo_vol(codec, pfx, cidx, nid) \
3112 alc_auto_add_vol_ctl(codec, pfx, cidx, nid, 3)
3114 /* create a mute-switch for the given mixer widget;
3115 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3117 static int alc_auto_add_sw_ctl(struct hda_codec *codec,
3118 const char *pfx, int cidx,
3119 hda_nid_t nid, unsigned int chs)
3121 struct alc_spec *spec = codec->spec;
3127 wid_type = get_wcaps_type(get_wcaps(codec, nid));
3128 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) {
3129 type = ALC_CTL_WIDGET_MUTE;
3130 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3131 } else if (snd_hda_get_conn_list(codec, nid, NULL) == 1) {
3132 type = ALC_CTL_WIDGET_MUTE;
3133 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
3135 type = ALC_CTL_BIND_MUTE;
3136 val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
3138 if (is_ctl_used(spec->sw_ctls, val) && chs != 2) /* exclude LFE */
3140 mark_ctl_usage(spec->sw_ctls, val);
3141 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
3144 #define alc_auto_add_stereo_sw(codec, pfx, cidx, nid) \
3145 alc_auto_add_sw_ctl(codec, pfx, cidx, nid, 3)
3147 static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3148 hda_nid_t pin, hda_nid_t dac)
3150 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3151 if (nid_has_mute(codec, pin, HDA_OUTPUT))
3153 else if (mix && nid_has_mute(codec, mix, HDA_INPUT))
3155 else if (nid_has_mute(codec, dac, HDA_OUTPUT))
3160 static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3161 hda_nid_t pin, hda_nid_t dac)
3163 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3164 if (nid_has_volume(codec, dac, HDA_OUTPUT))
3166 else if (nid_has_volume(codec, mix, HDA_OUTPUT))
3168 else if (nid_has_volume(codec, pin, HDA_OUTPUT))
3173 /* add playback controls from the parsed DAC table */
3174 static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
3175 const struct auto_pin_cfg *cfg)
3177 struct alc_spec *spec = codec->spec;
3178 int i, err, noutputs;
3180 noutputs = cfg->line_outs;
3181 if (spec->multi_ios > 0)
3182 noutputs += spec->multi_ios;
3184 for (i = 0; i < noutputs; i++) {
3190 dac = spec->multiout.dac_nids[i];
3193 if (i >= cfg->line_outs)
3194 pin = spec->multi_io[i - 1].pin;
3196 pin = cfg->line_out_pins[i];
3198 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3199 vol = alc_look_for_out_vol_nid(codec, pin, dac);
3200 name = alc_get_line_out_pfx(spec, i, true, &index);
3201 if (!name || !strcmp(name, "CLFE")) {
3203 err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1);
3206 err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2);
3209 err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1);
3212 err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2);
3216 err = alc_auto_add_stereo_vol(codec, name, index, vol);
3219 err = alc_auto_add_stereo_sw(codec, name, index, sw);
3227 static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
3228 hda_nid_t dac, const char *pfx,
3231 struct alc_spec *spec = codec->spec;
3237 /* the corresponding DAC is already occupied */
3238 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
3239 return 0; /* no way */
3240 /* create a switch only */
3241 val = HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT);
3242 if (is_ctl_used(spec->sw_ctls, val))
3243 return 0; /* already created */
3244 mark_ctl_usage(spec->sw_ctls, val);
3245 return __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, cidx, val);
3248 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3249 vol = alc_look_for_out_vol_nid(codec, pin, dac);
3250 err = alc_auto_add_stereo_vol(codec, pfx, cidx, vol);
3253 err = alc_auto_add_stereo_sw(codec, pfx, cidx, sw);
3259 static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3261 struct hda_ctl_ops *ops)
3263 struct alc_spec *spec = codec->spec;
3264 struct hda_bind_ctls **ctlp, *ctl;
3265 snd_array_init(&spec->bind_ctls, sizeof(ctl), 8);
3266 ctlp = snd_array_new(&spec->bind_ctls);
3269 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3276 /* add playback controls for speaker and HP outputs */
3277 static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3278 const hda_nid_t *pins,
3279 const hda_nid_t *dacs,
3282 struct alc_spec *spec = codec->spec;
3283 struct hda_bind_ctls *ctl;
3287 if (!num_pins || !pins[0])
3290 if (num_pins == 1) {
3291 hda_nid_t dac = *dacs;
3293 dac = spec->multiout.dac_nids[0];
3294 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
3297 if (dacs[num_pins - 1]) {
3298 /* OK, we have a multi-output system with individual volumes */
3299 for (i = 0; i < num_pins; i++) {
3300 if (num_pins >= 3) {
3301 snprintf(name, sizeof(name), "%s %s",
3302 pfx, channel_name[i]);
3303 err = alc_auto_create_extra_out(codec, pins[i], dacs[i],
3306 err = alc_auto_create_extra_out(codec, pins[i], dacs[i],
3315 /* Let's create a bind-controls */
3316 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_sw);
3320 for (i = 0; i < num_pins; i++) {
3321 if (get_wcaps(codec, pins[i]) & AC_WCAP_OUT_AMP)
3323 HDA_COMPOSE_AMP_VAL(pins[i], 3, 0, HDA_OUTPUT);
3326 snprintf(name, sizeof(name), "%s Playback Switch", pfx);
3327 err = add_control(spec, ALC_CTL_BIND_SW, name, 0, (long)ctl);
3332 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3336 for (i = 0; i < num_pins; i++) {
3338 if (!pins[i] || !dacs[i])
3340 vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]);
3343 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3346 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3347 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3354 static int alc_auto_create_hp_out(struct hda_codec *codec)
3356 struct alc_spec *spec = codec->spec;
3357 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3358 spec->autocfg.hp_pins,
3359 spec->multiout.hp_out_nid,
3363 static int alc_auto_create_speaker_out(struct hda_codec *codec)
3365 struct alc_spec *spec = codec->spec;
3366 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3367 spec->autocfg.speaker_pins,
3368 spec->multiout.extra_out_nid,
3372 static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
3373 hda_nid_t pin, int pin_type,
3377 hda_nid_t nid, mix = 0;
3378 hda_nid_t srcs[HDA_MAX_CONNECTIONS];
3380 alc_set_pin_output(codec, pin, pin_type);
3381 nid = alc_go_down_to_selector(codec, pin);
3382 num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
3383 for (i = 0; i < num; i++) {
3384 if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
3392 /* need the manual connection? */
3394 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
3395 /* unmute mixer widget inputs */
3396 if (nid_has_mute(codec, mix, HDA_INPUT)) {
3397 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3399 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3402 /* initialize volume */
3403 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3405 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3408 /* unmute DAC if it's not assigned to a mixer */
3409 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3410 if (nid == mix && nid_has_mute(codec, dac, HDA_OUTPUT))
3411 snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3415 static void alc_auto_init_multi_out(struct hda_codec *codec)
3417 struct alc_spec *spec = codec->spec;
3418 int pin_type = get_pin_type(spec->autocfg.line_out_type);
3421 for (i = 0; i <= HDA_SIDE; i++) {
3422 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3424 alc_auto_set_output_and_unmute(codec, nid, pin_type,
3425 spec->multiout.dac_nids[i]);
3429 static void alc_auto_init_extra_out(struct hda_codec *codec)
3431 struct alc_spec *spec = codec->spec;
3435 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3436 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3438 pin = spec->autocfg.hp_pins[i];
3441 dac = spec->multiout.hp_out_nid[i];
3443 if (i > 0 && spec->multiout.hp_out_nid[0])
3444 dac = spec->multiout.hp_out_nid[0];
3446 dac = spec->multiout.dac_nids[0];
3448 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
3450 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3451 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3453 pin = spec->autocfg.speaker_pins[i];
3456 dac = spec->multiout.extra_out_nid[i];
3458 if (i > 0 && spec->multiout.extra_out_nid[0])
3459 dac = spec->multiout.extra_out_nid[0];
3461 dac = spec->multiout.dac_nids[0];
3463 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
3470 static int alc_auto_fill_multi_ios(struct hda_codec *codec,
3471 unsigned int location)
3473 struct alc_spec *spec = codec->spec;
3474 struct auto_pin_cfg *cfg = &spec->autocfg;
3475 hda_nid_t prime_dac = spec->private_dac_nids[0];
3476 int type, i, num_pins = 0;
3478 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3479 for (i = 0; i < cfg->num_inputs; i++) {
3480 hda_nid_t nid = cfg->inputs[i].pin;
3482 unsigned int defcfg, caps;
3483 if (cfg->inputs[i].type != type)
3485 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3486 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3488 if (location && get_defcfg_location(defcfg) != location)
3490 caps = snd_hda_query_pin_caps(codec, nid);
3491 if (!(caps & AC_PINCAP_OUT))
3493 dac = alc_auto_look_for_dac(codec, nid);
3496 spec->multi_io[num_pins].pin = nid;
3497 spec->multi_io[num_pins].dac = dac;
3499 spec->private_dac_nids[spec->multiout.num_dacs++] = dac;
3502 spec->multiout.num_dacs = 1;
3504 /* clear up again */
3505 memset(spec->private_dac_nids, 0,
3506 sizeof(spec->private_dac_nids));
3507 spec->private_dac_nids[0] = prime_dac;
3513 static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
3514 struct snd_ctl_elem_info *uinfo)
3516 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3517 struct alc_spec *spec = codec->spec;
3519 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3521 uinfo->value.enumerated.items = spec->multi_ios + 1;
3522 if (uinfo->value.enumerated.item > spec->multi_ios)
3523 uinfo->value.enumerated.item = spec->multi_ios;
3524 sprintf(uinfo->value.enumerated.name, "%dch",
3525 (uinfo->value.enumerated.item + 1) * 2);
3529 static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
3530 struct snd_ctl_elem_value *ucontrol)
3532 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3533 struct alc_spec *spec = codec->spec;
3534 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
3538 static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
3540 struct alc_spec *spec = codec->spec;
3541 hda_nid_t nid = spec->multi_io[idx].pin;
3543 if (!spec->multi_io[idx].ctl_in)
3544 spec->multi_io[idx].ctl_in =
3545 snd_hda_codec_read(codec, nid, 0,
3546 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3548 snd_hda_codec_update_cache(codec, nid, 0,
3549 AC_VERB_SET_PIN_WIDGET_CONTROL,
3551 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3552 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3554 alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
3556 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3557 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3558 HDA_AMP_MUTE, HDA_AMP_MUTE);
3559 snd_hda_codec_update_cache(codec, nid, 0,
3560 AC_VERB_SET_PIN_WIDGET_CONTROL,
3561 spec->multi_io[idx].ctl_in);
3566 static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
3567 struct snd_ctl_elem_value *ucontrol)
3569 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3570 struct alc_spec *spec = codec->spec;
3573 ch = ucontrol->value.enumerated.item[0];
3574 if (ch < 0 || ch > spec->multi_ios)
3576 if (ch == (spec->ext_channel_count - 1) / 2)
3578 spec->ext_channel_count = (ch + 1) * 2;
3579 for (i = 0; i < spec->multi_ios; i++)
3580 alc_set_multi_io(codec, i, i < ch);
3581 spec->multiout.max_channels = spec->ext_channel_count;
3582 if (spec->need_dac_fix && !spec->const_channel_count)
3583 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
3587 static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
3588 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3589 .name = "Channel Mode",
3590 .info = alc_auto_ch_mode_info,
3591 .get = alc_auto_ch_mode_get,
3592 .put = alc_auto_ch_mode_put,
3595 static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
3597 struct alc_spec *spec = codec->spec;
3599 if (spec->multi_ios > 0) {
3600 struct snd_kcontrol_new *knew;
3602 knew = alc_kcontrol_new(spec);
3605 *knew = alc_auto_channel_mode_enum;
3606 knew->name = kstrdup("Channel Mode", GFP_KERNEL);
3613 /* filter out invalid adc_nids (and capsrc_nids) that don't give all
3616 static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
3618 struct alc_spec *spec = codec->spec;
3619 const struct hda_input_mux *imux;
3620 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3621 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3624 imux = spec->input_mux;
3627 if (spec->dyn_adc_switch)
3631 for (n = 0; n < spec->num_adc_nids; n++) {
3632 hda_nid_t cap = spec->private_capsrc_nids[n];
3633 int num_conns = snd_hda_get_conn_list(codec, cap, NULL);
3634 for (i = 0; i < imux->num_items; i++) {
3635 hda_nid_t pin = spec->imux_pins[i];
3637 if (get_connection_index(codec, cap, pin) < 0)
3639 } else if (num_conns <= imux->items[i].index)
3642 if (i >= imux->num_items) {
3643 adc_nids[nums] = spec->private_adc_nids[n];
3644 capsrc_nids[nums++] = cap;
3648 /* check whether ADC-switch is possible */
3649 if (!alc_check_dyn_adc_switch(codec)) {
3650 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
3651 " using fallback 0x%x\n",
3652 codec->chip_name, spec->private_adc_nids[0]);
3653 spec->num_adc_nids = 1;
3657 } else if (nums != spec->num_adc_nids) {
3658 memcpy(spec->private_adc_nids, adc_nids,
3659 nums * sizeof(hda_nid_t));
3660 memcpy(spec->private_capsrc_nids, capsrc_nids,
3661 nums * sizeof(hda_nid_t));
3662 spec->num_adc_nids = nums;
3666 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
3667 else if (spec->input_mux->num_items == 1)
3668 spec->num_adc_nids = 1; /* reduce to a single ADC */
3672 * initialize ADC paths
3674 static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
3676 struct alc_spec *spec = codec->spec;
3679 nid = spec->adc_nids[adc_idx];
3681 if (nid_has_mute(codec, nid, HDA_INPUT)) {
3682 snd_hda_codec_write(codec, nid, 0,
3683 AC_VERB_SET_AMP_GAIN_MUTE,
3687 if (!spec->capsrc_nids)
3689 nid = spec->capsrc_nids[adc_idx];
3690 if (nid_has_mute(codec, nid, HDA_OUTPUT))
3691 snd_hda_codec_write(codec, nid, 0,
3692 AC_VERB_SET_AMP_GAIN_MUTE,
3696 static void alc_auto_init_input_src(struct hda_codec *codec)
3698 struct alc_spec *spec = codec->spec;
3701 for (c = 0; c < spec->num_adc_nids; c++)
3702 alc_auto_init_adc(codec, c);
3703 if (spec->dyn_adc_switch)
3706 nums = spec->num_adc_nids;
3707 for (c = 0; c < nums; c++)
3708 alc_mux_select(codec, c, spec->cur_mux[c], true);
3711 /* add mic boosts if needed */
3712 static int alc_auto_add_mic_boost(struct hda_codec *codec)
3714 struct alc_spec *spec = codec->spec;
3715 struct auto_pin_cfg *cfg = &spec->autocfg;
3719 const char *prev_label = NULL;
3721 for (i = 0; i < cfg->num_inputs; i++) {
3722 if (cfg->inputs[i].type > AUTO_PIN_MIC)
3724 nid = cfg->inputs[i].pin;
3725 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
3727 char boost_label[32];
3729 label = hda_get_autocfg_input_label(codec, cfg, i);
3730 if (prev_label && !strcmp(label, prev_label))
3736 snprintf(boost_label, sizeof(boost_label),
3737 "%s Boost Volume", label);
3738 err = add_control(spec, ALC_CTL_WIDGET_VOL,
3739 boost_label, type_idx,
3740 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
3748 /* select or unmute the given capsrc route */
3749 static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
3752 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
3753 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
3755 } else if (snd_hda_get_conn_list(codec, cap, NULL) > 1) {
3756 snd_hda_codec_write_cache(codec, cap, 0,
3757 AC_VERB_SET_CONNECT_SEL, idx);
3761 /* set the default connection to that pin */
3762 static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
3764 struct alc_spec *spec = codec->spec;
3769 for (i = 0; i < spec->num_adc_nids; i++) {
3770 hda_nid_t cap = get_capsrc(spec, i);
3773 idx = get_connection_index(codec, cap, pin);
3776 select_or_unmute_capsrc(codec, cap, idx);
3777 return i; /* return the found index */
3779 return -1; /* not found */
3782 /* initialize some special cases for input sources */
3783 static void alc_init_special_input_src(struct hda_codec *codec)
3785 struct alc_spec *spec = codec->spec;
3788 for (i = 0; i < spec->autocfg.num_inputs; i++)
3789 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
3792 /* assign appropriate capture mixers */
3793 static void set_capture_mixer(struct hda_codec *codec)
3795 struct alc_spec *spec = codec->spec;
3796 static const struct snd_kcontrol_new *caps[2][3] = {
3797 { alc_capture_mixer_nosrc1,
3798 alc_capture_mixer_nosrc2,
3799 alc_capture_mixer_nosrc3 },
3800 { alc_capture_mixer1,
3802 alc_capture_mixer3 },
3805 /* check whether either of ADC or MUX has a volume control */
3806 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
3807 if (!spec->capsrc_nids)
3808 return; /* no volume */
3809 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
3810 return; /* no volume in capsrc, too */
3811 spec->vol_in_capsrc = 1;
3814 if (spec->num_adc_nids > 0) {
3818 if (spec->input_mux && spec->input_mux->num_items > 1)
3820 if (spec->auto_mic) {
3823 } else if (spec->dyn_adc_switch)
3826 if (spec->num_adc_nids > 3)
3827 spec->num_adc_nids = 3;
3828 else if (!spec->num_adc_nids)
3830 num_adcs = spec->num_adc_nids;
3832 spec->cap_mixer = caps[mux][num_adcs - 1];
3837 * standard auto-parser initializations
3839 static void alc_auto_init_std(struct hda_codec *codec)
3841 struct alc_spec *spec = codec->spec;
3842 alc_auto_init_multi_out(codec);
3843 alc_auto_init_extra_out(codec);
3844 alc_auto_init_analog_input(codec);
3845 alc_auto_init_input_src(codec);
3846 alc_auto_init_digital(codec);
3847 if (spec->unsol_event)
3848 alc_inithook(codec);
3852 * Digital-beep handlers
3854 #ifdef CONFIG_SND_HDA_INPUT_BEEP
3855 #define set_beep_amp(spec, nid, idx, dir) \
3856 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
3858 static const struct snd_pci_quirk beep_white_list[] = {
3859 SND_PCI_QUIRK(0x1043, 0x103c, "ASUS", 1),
3860 SND_PCI_QUIRK(0x1043, 0x115d, "ASUS", 1),
3861 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
3862 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
3863 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
3864 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
3865 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
3869 static inline int has_cdefine_beep(struct hda_codec *codec)
3871 struct alc_spec *spec = codec->spec;
3872 const struct snd_pci_quirk *q;
3873 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
3876 return spec->cdefine.enable_pcbeep;
3879 #define set_beep_amp(spec, nid, idx, dir) /* NOP */
3880 #define has_cdefine_beep(codec) 0
3883 /* parse the BIOS configuration and set up the alc_spec */
3884 /* return 1 if successful, 0 if the proper config is not found,
3885 * or a negative error code
3887 static int alc_parse_auto_config(struct hda_codec *codec,
3888 const hda_nid_t *ignore_nids,
3889 const hda_nid_t *ssid_nids)
3891 struct alc_spec *spec = codec->spec;
3892 struct auto_pin_cfg *cfg = &spec->autocfg;
3895 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
3899 if (!cfg->line_outs) {
3900 if (cfg->dig_outs || cfg->dig_in_pin) {
3901 spec->multiout.max_channels = 2;
3902 spec->no_analog = 1;
3905 return 0; /* can't find valid BIOS pin config */
3908 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
3909 cfg->line_outs <= cfg->hp_outs) {
3910 /* use HP as primary out */
3911 cfg->speaker_outs = cfg->line_outs;
3912 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3913 sizeof(cfg->speaker_pins));
3914 cfg->line_outs = cfg->hp_outs;
3915 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
3917 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3918 cfg->line_out_type = AUTO_PIN_HP_OUT;
3921 err = alc_auto_fill_dac_nids(codec);
3924 err = alc_auto_add_multi_channel_mode(codec);
3927 err = alc_auto_create_multi_out_ctls(codec, cfg);
3930 err = alc_auto_create_hp_out(codec);
3933 err = alc_auto_create_speaker_out(codec);
3936 err = alc_auto_create_input_ctls(codec);
3940 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3943 alc_auto_parse_digital(codec);
3945 if (!spec->no_analog)
3946 alc_remove_invalid_adc_nids(codec);
3949 alc_ssid_check(codec, ssid_nids);
3951 if (!spec->no_analog) {
3952 alc_auto_check_switches(codec);
3953 err = alc_auto_add_mic_boost(codec);
3958 if (spec->kctls.list)
3959 add_mixer(spec, spec->kctls.list);
3964 static int alc880_parse_auto_config(struct hda_codec *codec)
3966 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
3967 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
3968 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
3971 #ifdef CONFIG_SND_HDA_POWER_SAVE
3972 static const struct hda_amp_list alc880_loopbacks[] = {
3973 { 0x0b, HDA_INPUT, 0 },
3974 { 0x0b, HDA_INPUT, 1 },
3975 { 0x0b, HDA_INPUT, 2 },
3976 { 0x0b, HDA_INPUT, 3 },
3977 { 0x0b, HDA_INPUT, 4 },
3985 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3986 #define alc_board_config \
3987 snd_hda_check_board_config
3988 #define alc_board_codec_sid_config \
3989 snd_hda_check_board_codec_sid_config
3990 #include "alc_quirks.c"
3992 #define alc_board_config(codec, nums, models, tbl) -1
3993 #define alc_board_codec_sid_config(codec, nums, models, tbl) -1
3994 #define setup_preset(codec, x) /* NOP */
3998 * OK, here we have finally the patch for ALC880
4000 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4001 #include "alc880_quirks.c"
4004 static int patch_alc880(struct hda_codec *codec)
4006 struct alc_spec *spec;
4010 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4016 spec->mixer_nid = 0x0b;
4017 spec->need_dac_fix = 1;
4019 board_config = alc_board_config(codec, ALC880_MODEL_LAST,
4020 alc880_models, alc880_cfg_tbl);
4021 if (board_config < 0) {
4022 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4024 board_config = ALC_MODEL_AUTO;
4027 if (board_config == ALC_MODEL_AUTO) {
4028 /* automatic parse from the BIOS config */
4029 err = alc880_parse_auto_config(codec);
4032 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4035 "hda_codec: Cannot set up configuration "
4036 "from BIOS. Using 3-stack mode...\n");
4037 board_config = ALC880_3ST;
4042 if (board_config != ALC_MODEL_AUTO)
4043 setup_preset(codec, &alc880_presets[board_config]);
4045 if (!spec->no_analog && !spec->adc_nids) {
4046 alc_auto_fill_adc_caps(codec);
4047 alc_rebuild_imux_for_auto_mic(codec);
4048 alc_remove_invalid_adc_nids(codec);
4051 if (!spec->no_analog && !spec->cap_mixer)
4052 set_capture_mixer(codec);
4054 if (!spec->no_analog) {
4055 err = snd_hda_attach_beep_device(codec, 0x1);
4058 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4061 spec->vmaster_nid = 0x0c;
4063 codec->patch_ops = alc_patch_ops;
4064 if (board_config == ALC_MODEL_AUTO)
4065 spec->init_hook = alc_auto_init_std;
4066 #ifdef CONFIG_SND_HDA_POWER_SAVE
4067 if (!spec->loopback.amplist)
4068 spec->loopback.amplist = alc880_loopbacks;
4082 static int alc260_parse_auto_config(struct hda_codec *codec)
4084 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
4085 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
4086 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
4089 #ifdef CONFIG_SND_HDA_POWER_SAVE
4090 static const struct hda_amp_list alc260_loopbacks[] = {
4091 { 0x07, HDA_INPUT, 0 },
4092 { 0x07, HDA_INPUT, 1 },
4093 { 0x07, HDA_INPUT, 2 },
4094 { 0x07, HDA_INPUT, 3 },
4095 { 0x07, HDA_INPUT, 4 },
4107 static const struct alc_fixup alc260_fixups[] = {
4108 [PINFIX_HP_DC5750] = {
4109 .type = ALC_FIXUP_PINS,
4110 .v.pins = (const struct alc_pincfg[]) {
4111 { 0x11, 0x90130110 }, /* speaker */
4117 static const struct snd_pci_quirk alc260_fixup_tbl[] = {
4118 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", PINFIX_HP_DC5750),
4124 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4125 #include "alc260_quirks.c"
4128 static int patch_alc260(struct hda_codec *codec)
4130 struct alc_spec *spec;
4131 int err, board_config;
4133 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4139 spec->mixer_nid = 0x07;
4141 board_config = alc_board_config(codec, ALC260_MODEL_LAST,
4142 alc260_models, alc260_cfg_tbl);
4143 if (board_config < 0) {
4144 snd_printd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4146 board_config = ALC_MODEL_AUTO;
4149 if (board_config == ALC_MODEL_AUTO) {
4150 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
4151 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4154 if (board_config == ALC_MODEL_AUTO) {
4155 /* automatic parse from the BIOS config */
4156 err = alc260_parse_auto_config(codec);
4159 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4162 "hda_codec: Cannot set up configuration "
4163 "from BIOS. Using base mode...\n");
4164 board_config = ALC260_BASIC;
4169 if (board_config != ALC_MODEL_AUTO)
4170 setup_preset(codec, &alc260_presets[board_config]);
4172 if (!spec->no_analog && !spec->adc_nids) {
4173 alc_auto_fill_adc_caps(codec);
4174 alc_rebuild_imux_for_auto_mic(codec);
4175 alc_remove_invalid_adc_nids(codec);
4178 if (!spec->no_analog && !spec->cap_mixer)
4179 set_capture_mixer(codec);
4181 if (!spec->no_analog) {
4182 err = snd_hda_attach_beep_device(codec, 0x1);
4185 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
4188 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4190 spec->vmaster_nid = 0x08;
4192 codec->patch_ops = alc_patch_ops;
4193 if (board_config == ALC_MODEL_AUTO)
4194 spec->init_hook = alc_auto_init_std;
4195 spec->shutup = alc_eapd_shutup;
4196 #ifdef CONFIG_SND_HDA_POWER_SAVE
4197 if (!spec->loopback.amplist)
4198 spec->loopback.amplist = alc260_loopbacks;
4210 * ALC882/883/885/888/889 support
4212 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
4213 * configuration. Each pin widget can choose any input DACs and a mixer.
4214 * Each ADC is connected from a mixer of all inputs. This makes possible
4215 * 6-channel independent captures.
4217 * In addition, an independent DAC for the multi-playback (not used in this
4220 #ifdef CONFIG_SND_HDA_POWER_SAVE
4221 #define alc882_loopbacks alc880_loopbacks
4228 PINFIX_ABIT_AW9D_MAX,
4231 PINFIX_ACER_ASPIRE_7736,
4233 ALC889_FIXUP_DAC_ROUTE,
4236 /* Fix the connection of some pins for ALC889:
4237 * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
4238 * work correctly (bko#42740)
4240 static void alc889_fixup_dac_route(struct hda_codec *codec,
4241 const struct alc_fixup *fix, int action)
4243 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
4244 /* fake the connections during parsing the tree */
4245 hda_nid_t conn1[2] = { 0x0c, 0x0d };
4246 hda_nid_t conn2[2] = { 0x0e, 0x0f };
4247 snd_hda_override_conn_list(codec, 0x14, 2, conn1);
4248 snd_hda_override_conn_list(codec, 0x15, 2, conn1);
4249 snd_hda_override_conn_list(codec, 0x18, 2, conn2);
4250 snd_hda_override_conn_list(codec, 0x1a, 2, conn2);
4251 } else if (action == ALC_FIXUP_ACT_PROBE) {
4252 /* restore the connections */
4253 hda_nid_t conn[5] = { 0x0c, 0x0d, 0x0e, 0x0f, 0x26 };
4254 snd_hda_override_conn_list(codec, 0x14, 5, conn);
4255 snd_hda_override_conn_list(codec, 0x15, 5, conn);
4256 snd_hda_override_conn_list(codec, 0x18, 5, conn);
4257 snd_hda_override_conn_list(codec, 0x1a, 5, conn);
4261 static const struct alc_fixup alc882_fixups[] = {
4262 [PINFIX_ABIT_AW9D_MAX] = {
4263 .type = ALC_FIXUP_PINS,
4264 .v.pins = (const struct alc_pincfg[]) {
4265 { 0x15, 0x01080104 }, /* side */
4266 { 0x16, 0x01011012 }, /* rear */
4267 { 0x17, 0x01016011 }, /* clfe */
4271 [PINFIX_LENOVO_Y530] = {
4272 .type = ALC_FIXUP_PINS,
4273 .v.pins = (const struct alc_pincfg[]) {
4274 { 0x15, 0x99130112 }, /* rear int speakers */
4275 { 0x16, 0x99130111 }, /* subwoofer */
4279 [PINFIX_PB_M5210] = {
4280 .type = ALC_FIXUP_VERBS,
4281 .v.verbs = (const struct hda_verb[]) {
4282 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
4286 [PINFIX_ACER_ASPIRE_7736] = {
4287 .type = ALC_FIXUP_SKU,
4288 .v.sku = ALC_FIXUP_SKU_IGNORE,
4290 [PINFIX_ASUS_W90V] = {
4291 .type = ALC_FIXUP_PINS,
4292 .v.pins = (const struct alc_pincfg[]) {
4293 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
4297 [ALC889_FIXUP_DAC_ROUTE] = {
4298 .type = ALC_FIXUP_FUNC,
4299 .v.func = alc889_fixup_dac_route,
4303 static const struct snd_pci_quirk alc882_fixup_tbl[] = {
4304 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", PINFIX_PB_M5210),
4305 SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE),
4306 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", PINFIX_ASUS_W90V),
4307 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", PINFIX_LENOVO_Y530),
4308 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
4309 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", PINFIX_ACER_ASPIRE_7736),
4314 * BIOS auto configuration
4316 /* almost identical with ALC880 parser... */
4317 static int alc882_parse_auto_config(struct hda_codec *codec)
4319 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
4320 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4321 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
4326 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4327 #include "alc882_quirks.c"
4330 static int patch_alc882(struct hda_codec *codec)
4332 struct alc_spec *spec;
4333 int err, board_config;
4335 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4341 spec->mixer_nid = 0x0b;
4343 switch (codec->vendor_id) {
4348 /* ALC883 and variants */
4349 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
4353 err = alc_codec_rename_from_preset(codec);
4357 board_config = alc_board_config(codec, ALC882_MODEL_LAST,
4358 alc882_models, alc882_cfg_tbl);
4360 if (board_config < 0)
4361 board_config = alc_board_codec_sid_config(codec,
4362 ALC882_MODEL_LAST, alc882_models, alc882_ssid_cfg_tbl);
4364 if (board_config < 0) {
4365 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4367 board_config = ALC_MODEL_AUTO;
4370 if (board_config == ALC_MODEL_AUTO) {
4371 alc_pick_fixup(codec, NULL, alc882_fixup_tbl, alc882_fixups);
4372 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4375 alc_auto_parse_customize_define(codec);
4377 if (board_config == ALC_MODEL_AUTO) {
4378 /* automatic parse from the BIOS config */
4379 err = alc882_parse_auto_config(codec);
4382 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4385 "hda_codec: Cannot set up configuration "
4386 "from BIOS. Using base mode...\n");
4387 board_config = ALC882_3ST_DIG;
4392 if (board_config != ALC_MODEL_AUTO)
4393 setup_preset(codec, &alc882_presets[board_config]);
4395 if (!spec->no_analog && !spec->adc_nids) {
4396 alc_auto_fill_adc_caps(codec);
4397 alc_rebuild_imux_for_auto_mic(codec);
4398 alc_remove_invalid_adc_nids(codec);
4401 if (!spec->no_analog && !spec->cap_mixer)
4402 set_capture_mixer(codec);
4404 if (!spec->no_analog && has_cdefine_beep(codec)) {
4405 err = snd_hda_attach_beep_device(codec, 0x1);
4408 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4411 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4413 spec->vmaster_nid = 0x0c;
4415 codec->patch_ops = alc_patch_ops;
4416 if (board_config == ALC_MODEL_AUTO)
4417 spec->init_hook = alc_auto_init_std;
4419 alc_init_jacks(codec);
4420 #ifdef CONFIG_SND_HDA_POWER_SAVE
4421 if (!spec->loopback.amplist)
4422 spec->loopback.amplist = alc882_loopbacks;
4436 static int alc262_parse_auto_config(struct hda_codec *codec)
4438 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
4439 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4440 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
4451 static const struct alc_fixup alc262_fixups[] = {
4452 [PINFIX_FSC_H270] = {
4453 .type = ALC_FIXUP_PINS,
4454 .v.pins = (const struct alc_pincfg[]) {
4455 { 0x14, 0x99130110 }, /* speaker */
4456 { 0x15, 0x0221142f }, /* front HP */
4457 { 0x1b, 0x0121141f }, /* rear HP */
4461 [PINFIX_HP_Z200] = {
4462 .type = ALC_FIXUP_PINS,
4463 .v.pins = (const struct alc_pincfg[]) {
4464 { 0x16, 0x99130120 }, /* internal speaker */
4470 static const struct snd_pci_quirk alc262_fixup_tbl[] = {
4471 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", PINFIX_HP_Z200),
4472 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", PINFIX_FSC_H270),
4477 #ifdef CONFIG_SND_HDA_POWER_SAVE
4478 #define alc262_loopbacks alc880_loopbacks
4483 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4484 #include "alc262_quirks.c"
4487 static int patch_alc262(struct hda_codec *codec)
4489 struct alc_spec *spec;
4493 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4499 spec->mixer_nid = 0x0b;
4502 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
4507 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4508 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
4509 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4510 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
4513 alc_auto_parse_customize_define(codec);
4515 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
4517 board_config = alc_board_config(codec, ALC262_MODEL_LAST,
4518 alc262_models, alc262_cfg_tbl);
4520 if (board_config < 0) {
4521 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4523 board_config = ALC_MODEL_AUTO;
4526 if (board_config == ALC_MODEL_AUTO) {
4527 alc_pick_fixup(codec, NULL, alc262_fixup_tbl, alc262_fixups);
4528 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4531 if (board_config == ALC_MODEL_AUTO) {
4532 /* automatic parse from the BIOS config */
4533 err = alc262_parse_auto_config(codec);
4536 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4539 "hda_codec: Cannot set up configuration "
4540 "from BIOS. Using base mode...\n");
4541 board_config = ALC262_BASIC;
4546 if (board_config != ALC_MODEL_AUTO)
4547 setup_preset(codec, &alc262_presets[board_config]);
4549 if (!spec->no_analog && !spec->adc_nids) {
4550 alc_auto_fill_adc_caps(codec);
4551 alc_rebuild_imux_for_auto_mic(codec);
4552 alc_remove_invalid_adc_nids(codec);
4555 if (!spec->no_analog && !spec->cap_mixer)
4556 set_capture_mixer(codec);
4558 if (!spec->no_analog && has_cdefine_beep(codec)) {
4559 err = snd_hda_attach_beep_device(codec, 0x1);
4562 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4565 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4567 spec->vmaster_nid = 0x0c;
4569 codec->patch_ops = alc_patch_ops;
4570 if (board_config == ALC_MODEL_AUTO)
4571 spec->init_hook = alc_auto_init_std;
4572 spec->shutup = alc_eapd_shutup;
4574 alc_init_jacks(codec);
4575 #ifdef CONFIG_SND_HDA_POWER_SAVE
4576 if (!spec->loopback.amplist)
4577 spec->loopback.amplist = alc262_loopbacks;
4590 /* bind Beep switches of both NID 0x0f and 0x10 */
4591 static const struct hda_bind_ctls alc268_bind_beep_sw = {
4592 .ops = &snd_hda_bind_sw,
4594 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
4595 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
4600 static const struct snd_kcontrol_new alc268_beep_mixer[] = {
4601 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
4602 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
4606 /* set PCBEEP vol = 0, mute connections */
4607 static const struct hda_verb alc268_beep_init_verbs[] = {
4608 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4609 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4610 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4615 * BIOS auto configuration
4617 static int alc268_parse_auto_config(struct hda_codec *codec)
4619 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4620 struct alc_spec *spec = codec->spec;
4621 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
4623 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
4624 add_mixer(spec, alc268_beep_mixer);
4625 add_verb(spec, alc268_beep_init_verbs);
4633 static int patch_alc268(struct hda_codec *codec)
4635 struct alc_spec *spec;
4636 int i, has_beep, err;
4638 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4644 /* ALC268 has no aa-loopback mixer */
4646 /* automatic parse from the BIOS config */
4647 err = alc268_parse_auto_config(codec);
4652 for (i = 0; i < spec->num_mixers; i++) {
4653 if (spec->mixers[i] == alc268_beep_mixer) {
4660 err = snd_hda_attach_beep_device(codec, 0x1);
4663 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
4664 /* override the amp caps for beep generator */
4665 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
4666 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
4667 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
4668 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4669 (0 << AC_AMPCAP_MUTE_SHIFT));
4672 if (!spec->no_analog && !spec->adc_nids) {
4673 alc_auto_fill_adc_caps(codec);
4674 alc_rebuild_imux_for_auto_mic(codec);
4675 alc_remove_invalid_adc_nids(codec);
4678 if (!spec->no_analog && !spec->cap_mixer)
4679 set_capture_mixer(codec);
4681 spec->vmaster_nid = 0x02;
4683 codec->patch_ops = alc_patch_ops;
4684 spec->init_hook = alc_auto_init_std;
4685 spec->shutup = alc_eapd_shutup;
4687 alc_init_jacks(codec);
4699 #ifdef CONFIG_SND_HDA_POWER_SAVE
4700 #define alc269_loopbacks alc880_loopbacks
4703 static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
4707 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
4708 /* NID is set in alc_build_pcms */
4710 .open = alc_playback_pcm_open,
4711 .prepare = alc_playback_pcm_prepare,
4712 .cleanup = alc_playback_pcm_cleanup
4716 static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
4720 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
4721 /* NID is set in alc_build_pcms */
4724 #ifdef CONFIG_SND_HDA_POWER_SAVE
4725 static int alc269_mic2_for_mute_led(struct hda_codec *codec)
4727 switch (codec->subsystem_id) {
4734 static int alc269_mic2_mute_check_ps(struct hda_codec *codec, hda_nid_t nid)
4736 /* update mute-LED according to the speaker mute state */
4737 if (nid == 0x01 || nid == 0x14) {
4739 if (snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0) &
4744 /* mic2 vref pin is used for mute LED control */
4745 snd_hda_codec_update_cache(codec, 0x19, 0,
4746 AC_VERB_SET_PIN_WIDGET_CONTROL,
4749 return alc_check_power_status(codec, nid);
4751 #endif /* CONFIG_SND_HDA_POWER_SAVE */
4753 /* different alc269-variants */
4755 ALC269_TYPE_ALC269VA,
4756 ALC269_TYPE_ALC269VB,
4757 ALC269_TYPE_ALC269VC,
4761 * BIOS auto configuration
4763 static int alc269_parse_auto_config(struct hda_codec *codec)
4765 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
4766 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
4767 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4768 struct alc_spec *spec = codec->spec;
4769 const hda_nid_t *ssids = spec->codec_variant == ALC269_TYPE_ALC269VA ?
4770 alc269va_ssids : alc269_ssids;
4772 return alc_parse_auto_config(codec, alc269_ignore, ssids);
4775 static void alc269_toggle_power_output(struct hda_codec *codec, int power_up)
4777 int val = alc_read_coef_idx(codec, 0x04);
4784 alc_write_coef_idx(codec, 0x04, val);
4787 static void alc269_shutup(struct hda_codec *codec)
4789 if ((alc_get_coef0(codec) & 0x00ff) == 0x017)
4790 alc269_toggle_power_output(codec, 0);
4791 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
4792 alc269_toggle_power_output(codec, 0);
4798 static int alc269_resume(struct hda_codec *codec)
4800 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
4801 alc269_toggle_power_output(codec, 0);
4805 codec->patch_ops.init(codec);
4807 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
4808 alc269_toggle_power_output(codec, 1);
4812 if ((alc_get_coef0(codec) & 0x00ff) == 0x018)
4813 alc269_toggle_power_output(codec, 1);
4815 snd_hda_codec_resume_amp(codec);
4816 snd_hda_codec_resume_cache(codec);
4817 hda_call_check_power_status(codec, 0x01);
4820 #endif /* CONFIG_PM */
4822 static void alc269_fixup_pincfg_no_hp_to_lineout(struct hda_codec *codec,
4823 const struct alc_fixup *fix, int action)
4825 struct alc_spec *spec = codec->spec;
4827 if (action == ALC_FIXUP_ACT_PRE_PROBE)
4828 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
4831 static void alc269_fixup_hweq(struct hda_codec *codec,
4832 const struct alc_fixup *fix, int action)
4836 if (action != ALC_FIXUP_ACT_INIT)
4838 coef = alc_read_coef_idx(codec, 0x1e);
4839 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
4842 static void alc271_fixup_dmic(struct hda_codec *codec,
4843 const struct alc_fixup *fix, int action)
4845 static const struct hda_verb verbs[] = {
4846 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
4847 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
4852 if (strcmp(codec->chip_name, "ALC271X"))
4854 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
4855 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
4856 snd_hda_sequence_write(codec, verbs);
4859 static void alc269_fixup_pcm_44k(struct hda_codec *codec,
4860 const struct alc_fixup *fix, int action)
4862 struct alc_spec *spec = codec->spec;
4864 if (action != ALC_FIXUP_ACT_PROBE)
4867 /* Due to a hardware problem on Lenovo Ideadpad, we need to
4868 * fix the sample rate of analog I/O to 44.1kHz
4870 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
4871 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
4874 static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
4875 const struct alc_fixup *fix, int action)
4879 if (action != ALC_FIXUP_ACT_INIT)
4881 /* The digital-mic unit sends PDM (differential signal) instead of
4882 * the standard PCM, thus you can't record a valid mono stream as is.
4883 * Below is a workaround specific to ALC269 to control the dmic
4884 * signal source as mono.
4886 coef = alc_read_coef_idx(codec, 0x07);
4887 alc_write_coef_idx(codec, 0x07, coef | 0x80);
4890 static void alc269_quanta_automute(struct hda_codec *codec)
4892 update_outputs(codec);
4894 snd_hda_codec_write(codec, 0x20, 0,
4895 AC_VERB_SET_COEF_INDEX, 0x0c);
4896 snd_hda_codec_write(codec, 0x20, 0,
4897 AC_VERB_SET_PROC_COEF, 0x680);
4899 snd_hda_codec_write(codec, 0x20, 0,
4900 AC_VERB_SET_COEF_INDEX, 0x0c);
4901 snd_hda_codec_write(codec, 0x20, 0,
4902 AC_VERB_SET_PROC_COEF, 0x480);
4905 static void alc269_fixup_quanta_mute(struct hda_codec *codec,
4906 const struct alc_fixup *fix, int action)
4908 struct alc_spec *spec = codec->spec;
4909 if (action != ALC_FIXUP_ACT_PROBE)
4911 spec->automute_hook = alc269_quanta_automute;
4915 ALC269_FIXUP_SONY_VAIO,
4916 ALC275_FIXUP_SONY_VAIO_GPIO2,
4917 ALC269_FIXUP_DELL_M101Z,
4918 ALC269_FIXUP_SKU_IGNORE,
4919 ALC269_FIXUP_ASUS_G73JW,
4920 ALC269_FIXUP_LENOVO_EAPD,
4921 ALC275_FIXUP_SONY_HWEQ,
4923 ALC269_FIXUP_PCM_44K,
4924 ALC269_FIXUP_STEREO_DMIC,
4925 ALC269_FIXUP_QUANTA_MUTE,
4926 ALC269_FIXUP_LIFEBOOK,
4927 ALC269_FIXUP_LIFEBOOK_EXTMIC,
4930 ALC269VB_FIXUP_AMIC,
4931 ALC269VB_FIXUP_DMIC,
4932 ALC269_FIXUP_LENOVO_DOCK,
4933 ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT,
4936 static const struct alc_fixup alc269_fixups[] = {
4937 [ALC269_FIXUP_SONY_VAIO] = {
4938 .type = ALC_FIXUP_VERBS,
4939 .v.verbs = (const struct hda_verb[]) {
4940 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
4944 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
4945 .type = ALC_FIXUP_VERBS,
4946 .v.verbs = (const struct hda_verb[]) {
4947 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
4948 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
4949 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
4953 .chain_id = ALC269_FIXUP_SONY_VAIO
4955 [ALC269_FIXUP_DELL_M101Z] = {
4956 .type = ALC_FIXUP_VERBS,
4957 .v.verbs = (const struct hda_verb[]) {
4958 /* Enables internal speaker */
4959 {0x20, AC_VERB_SET_COEF_INDEX, 13},
4960 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
4964 [ALC269_FIXUP_SKU_IGNORE] = {
4965 .type = ALC_FIXUP_SKU,
4966 .v.sku = ALC_FIXUP_SKU_IGNORE,
4968 [ALC269_FIXUP_ASUS_G73JW] = {
4969 .type = ALC_FIXUP_PINS,
4970 .v.pins = (const struct alc_pincfg[]) {
4971 { 0x17, 0x99130111 }, /* subwoofer */
4975 [ALC269_FIXUP_LENOVO_EAPD] = {
4976 .type = ALC_FIXUP_VERBS,
4977 .v.verbs = (const struct hda_verb[]) {
4978 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
4982 [ALC275_FIXUP_SONY_HWEQ] = {
4983 .type = ALC_FIXUP_FUNC,
4984 .v.func = alc269_fixup_hweq,
4986 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
4988 [ALC271_FIXUP_DMIC] = {
4989 .type = ALC_FIXUP_FUNC,
4990 .v.func = alc271_fixup_dmic,
4992 [ALC269_FIXUP_PCM_44K] = {
4993 .type = ALC_FIXUP_FUNC,
4994 .v.func = alc269_fixup_pcm_44k,
4996 .chain_id = ALC269_FIXUP_QUANTA_MUTE
4998 [ALC269_FIXUP_STEREO_DMIC] = {
4999 .type = ALC_FIXUP_FUNC,
5000 .v.func = alc269_fixup_stereo_dmic,
5002 [ALC269_FIXUP_QUANTA_MUTE] = {
5003 .type = ALC_FIXUP_FUNC,
5004 .v.func = alc269_fixup_quanta_mute,
5006 [ALC269_FIXUP_LIFEBOOK] = {
5007 .type = ALC_FIXUP_PINS,
5008 .v.pins = (const struct alc_pincfg[]) {
5009 { 0x1a, 0x2101103f }, /* dock line-out */
5010 { 0x1b, 0x23a11040 }, /* dock mic-in */
5014 .chain_id = ALC269_FIXUP_QUANTA_MUTE
5016 [ALC269_FIXUP_LIFEBOOK_EXTMIC] = {
5017 .type = ALC_FIXUP_PINS,
5018 .v.pins = (const struct alc_pincfg[]) {
5019 { 0x19, 0x01a1903c }, /* headset mic, with jack detect */
5023 [ALC269_FIXUP_AMIC] = {
5024 .type = ALC_FIXUP_PINS,
5025 .v.pins = (const struct alc_pincfg[]) {
5026 { 0x14, 0x99130110 }, /* speaker */
5027 { 0x15, 0x0121401f }, /* HP out */
5028 { 0x18, 0x01a19c20 }, /* mic */
5029 { 0x19, 0x99a3092f }, /* int-mic */
5033 [ALC269_FIXUP_DMIC] = {
5034 .type = ALC_FIXUP_PINS,
5035 .v.pins = (const struct alc_pincfg[]) {
5036 { 0x12, 0x99a3092f }, /* int-mic */
5037 { 0x14, 0x99130110 }, /* speaker */
5038 { 0x15, 0x0121401f }, /* HP out */
5039 { 0x18, 0x01a19c20 }, /* mic */
5043 [ALC269VB_FIXUP_AMIC] = {
5044 .type = ALC_FIXUP_PINS,
5045 .v.pins = (const struct alc_pincfg[]) {
5046 { 0x14, 0x99130110 }, /* speaker */
5047 { 0x18, 0x01a19c20 }, /* mic */
5048 { 0x19, 0x99a3092f }, /* int-mic */
5049 { 0x21, 0x0121401f }, /* HP out */
5053 [ALC269_FIXUP_DMIC] = {
5054 .type = ALC_FIXUP_PINS,
5055 .v.pins = (const struct alc_pincfg[]) {
5056 { 0x12, 0x99a3092f }, /* int-mic */
5057 { 0x14, 0x99130110 }, /* speaker */
5058 { 0x18, 0x01a19c20 }, /* mic */
5059 { 0x21, 0x0121401f }, /* HP out */
5063 [ALC269_FIXUP_LENOVO_DOCK] = {
5064 .type = ALC_FIXUP_PINS,
5065 .v.pins = (const struct alc_pincfg[]) {
5066 { 0x19, 0x23a11040 }, /* dock mic */
5067 { 0x1b, 0x2121103f }, /* dock headphone */
5071 .chain_id = ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT
5073 [ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT] = {
5074 .type = ALC_FIXUP_FUNC,
5075 .v.func = alc269_fixup_pincfg_no_hp_to_lineout,
5079 static const struct snd_pci_quirk alc269_fixup_tbl[] = {
5080 SND_PCI_QUIRK(0x1043, 0x1427, "Asus Zenbook UX31E", ALC269VB_FIXUP_DMIC),
5081 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
5082 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
5083 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
5084 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
5085 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
5086 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
5087 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
5088 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
5089 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
5090 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
5091 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
5092 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
5093 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
5094 SND_PCI_QUIRK(0x10cf, 0x1845, "Lifebook U904", ALC269_FIXUP_LIFEBOOK_EXTMIC),
5095 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
5096 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
5097 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
5098 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
5099 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
5100 SND_PCI_QUIRK(0x17aa, 0x21f6, "Thinkpad T530", ALC269_FIXUP_LENOVO_DOCK),
5101 SND_PCI_QUIRK(0x17aa, 0x21fa, "Thinkpad X230", ALC269_FIXUP_LENOVO_DOCK),
5102 SND_PCI_QUIRK(0x17aa, 0x21f3, "Thinkpad T430", ALC269_FIXUP_LENOVO_DOCK),
5103 SND_PCI_QUIRK(0x17aa, 0x21fb, "Thinkpad T430s", ALC269_FIXUP_LENOVO_DOCK),
5104 SND_PCI_QUIRK(0x17aa, 0x2203, "Thinkpad X230 Tablet", ALC269_FIXUP_LENOVO_DOCK),
5105 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_PCM_44K),
5106 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
5109 /* Below is a quirk table taken from the old code.
5110 * Basically the device should work as is without the fixup table.
5111 * If BIOS doesn't give a proper info, enable the corresponding
5114 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
5116 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
5117 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
5118 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
5119 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
5120 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
5121 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
5122 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
5123 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
5124 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
5125 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
5126 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
5127 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
5128 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
5129 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
5130 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
5131 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
5132 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
5133 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
5134 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
5135 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
5136 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
5137 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
5138 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
5139 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
5140 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
5141 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
5142 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
5143 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
5144 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
5145 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
5146 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
5147 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
5148 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
5149 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
5150 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
5151 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
5152 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
5153 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
5154 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
5159 static const struct alc_model_fixup alc269_fixup_models[] = {
5160 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
5161 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
5162 {.id = ALC269_FIXUP_LENOVO_DOCK, .name = "lenovo-dock"},
5167 static int alc269_fill_coef(struct hda_codec *codec)
5169 struct alc_spec *spec = codec->spec;
5172 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
5174 /* ALC271X doesn't seem to support these COEFs (bko#52181) */
5175 if (!strcmp(codec->chip_name, "ALC271X"))
5178 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
5179 alc_write_coef_idx(codec, 0xf, 0x960b);
5180 alc_write_coef_idx(codec, 0xe, 0x8817);
5183 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
5184 alc_write_coef_idx(codec, 0xf, 0x960b);
5185 alc_write_coef_idx(codec, 0xe, 0x8814);
5188 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
5189 val = alc_read_coef_idx(codec, 0x04);
5190 /* Power up output pin */
5192 alc_write_coef_idx(codec, 0x04, val | (1<<11));
5195 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
5196 val = alc_read_coef_idx(codec, 0xd);
5197 if (val != -1 && (val & 0x0c00) >> 10 != 0x1) {
5198 /* Capless ramp up clock control */
5199 alc_write_coef_idx(codec, 0xd, val | (1<<10));
5201 val = alc_read_coef_idx(codec, 0x17);
5202 if (val != -1 && (val & 0x01c0) >> 6 != 0x4) {
5203 /* Class D power on reset */
5204 alc_write_coef_idx(codec, 0x17, val | (1<<7));
5208 val = alc_read_coef_idx(codec, 0xd); /* Class D */
5210 alc_write_coef_idx(codec, 0xd, val | (1<<14));
5212 val = alc_read_coef_idx(codec, 0x4); /* HP */
5214 alc_write_coef_idx(codec, 0x4, val | (1<<11));
5221 static int patch_alc269(struct hda_codec *codec)
5223 struct alc_spec *spec;
5226 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5232 spec->mixer_nid = 0x0b;
5234 alc_auto_parse_customize_define(codec);
5236 err = alc_codec_rename_from_preset(codec);
5240 if (codec->vendor_id == 0x10ec0269) {
5241 spec->codec_variant = ALC269_TYPE_ALC269VA;
5242 switch (alc_get_coef0(codec) & 0x00f0) {
5244 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
5245 spec->cdefine.platform_type == 1)
5246 err = alc_codec_rename(codec, "ALC271X");
5247 spec->codec_variant = ALC269_TYPE_ALC269VB;
5250 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
5251 codec->bus->pci->subsystem_device == 0x21f3)
5252 err = alc_codec_rename(codec, "ALC3202");
5253 spec->codec_variant = ALC269_TYPE_ALC269VC;
5256 alc_fix_pll_init(codec, 0x20, 0x04, 15);
5260 alc269_fill_coef(codec);
5263 alc_pick_fixup(codec, alc269_fixup_models,
5264 alc269_fixup_tbl, alc269_fixups);
5265 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5267 /* automatic parse from the BIOS config */
5268 err = alc269_parse_auto_config(codec);
5272 if (!spec->no_analog && !spec->adc_nids) {
5273 alc_auto_fill_adc_caps(codec);
5274 alc_rebuild_imux_for_auto_mic(codec);
5275 alc_remove_invalid_adc_nids(codec);
5278 if (!spec->no_analog && !spec->cap_mixer)
5279 set_capture_mixer(codec);
5281 if (!spec->no_analog && has_cdefine_beep(codec)) {
5282 err = snd_hda_attach_beep_device(codec, 0x1);
5285 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
5288 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5290 spec->vmaster_nid = 0x02;
5292 codec->patch_ops = alc_patch_ops;
5294 codec->patch_ops.resume = alc269_resume;
5296 spec->init_hook = alc_auto_init_std;
5297 spec->shutup = alc269_shutup;
5299 alc_init_jacks(codec);
5300 #ifdef CONFIG_SND_HDA_POWER_SAVE
5301 if (!spec->loopback.amplist)
5302 spec->loopback.amplist = alc269_loopbacks;
5303 if (alc269_mic2_for_mute_led(codec))
5304 codec->patch_ops.check_power_status = alc269_mic2_mute_check_ps;
5318 static int alc861_parse_auto_config(struct hda_codec *codec)
5320 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
5321 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
5322 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
5325 #ifdef CONFIG_SND_HDA_POWER_SAVE
5326 static const struct hda_amp_list alc861_loopbacks[] = {
5327 { 0x15, HDA_INPUT, 0 },
5328 { 0x15, HDA_INPUT, 1 },
5329 { 0x15, HDA_INPUT, 2 },
5330 { 0x15, HDA_INPUT, 3 },
5336 /* Pin config fixes */
5338 ALC861_FIXUP_FSC_AMILO_PI1505,
5339 ALC861_FIXUP_AMP_VREF_0F,
5340 ALC861_FIXUP_NO_JACK_DETECT,
5341 ALC861_FIXUP_ASUS_A6RP,
5344 /* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
5345 static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
5346 const struct alc_fixup *fix, int action)
5348 struct alc_spec *spec = codec->spec;
5351 if (action != ALC_FIXUP_ACT_INIT)
5353 val = snd_hda_codec_read(codec, 0x0f, 0,
5354 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5355 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
5356 val |= AC_PINCTL_IN_EN;
5357 val |= AC_PINCTL_VREF_50;
5358 snd_hda_codec_write(codec, 0x0f, 0,
5359 AC_VERB_SET_PIN_WIDGET_CONTROL, val);
5360 spec->keep_vref_in_automute = 1;
5363 /* suppress the jack-detection */
5364 static void alc_fixup_no_jack_detect(struct hda_codec *codec,
5365 const struct alc_fixup *fix, int action)
5367 if (action == ALC_FIXUP_ACT_PRE_PROBE)
5368 codec->no_jack_detect = 1;
5371 static const struct alc_fixup alc861_fixups[] = {
5372 [ALC861_FIXUP_FSC_AMILO_PI1505] = {
5373 .type = ALC_FIXUP_PINS,
5374 .v.pins = (const struct alc_pincfg[]) {
5375 { 0x0b, 0x0221101f }, /* HP */
5376 { 0x0f, 0x90170310 }, /* speaker */
5380 [ALC861_FIXUP_AMP_VREF_0F] = {
5381 .type = ALC_FIXUP_FUNC,
5382 .v.func = alc861_fixup_asus_amp_vref_0f,
5384 [ALC861_FIXUP_NO_JACK_DETECT] = {
5385 .type = ALC_FIXUP_FUNC,
5386 .v.func = alc_fixup_no_jack_detect,
5388 [ALC861_FIXUP_ASUS_A6RP] = {
5389 .type = ALC_FIXUP_FUNC,
5390 .v.func = alc861_fixup_asus_amp_vref_0f,
5392 .chain_id = ALC861_FIXUP_NO_JACK_DETECT,
5396 static const struct snd_pci_quirk alc861_fixup_tbl[] = {
5397 SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP),
5398 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", ALC861_FIXUP_AMP_VREF_0F),
5399 SND_PCI_QUIRK(0x1462, 0x7254, "HP DX2200", ALC861_FIXUP_NO_JACK_DETECT),
5400 SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", ALC861_FIXUP_AMP_VREF_0F),
5401 SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", ALC861_FIXUP_AMP_VREF_0F),
5402 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", ALC861_FIXUP_FSC_AMILO_PI1505),
5408 static int patch_alc861(struct hda_codec *codec)
5410 struct alc_spec *spec;
5413 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5419 spec->mixer_nid = 0x15;
5421 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
5422 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5424 /* automatic parse from the BIOS config */
5425 err = alc861_parse_auto_config(codec);
5429 if (!spec->no_analog && !spec->adc_nids) {
5430 alc_auto_fill_adc_caps(codec);
5431 alc_rebuild_imux_for_auto_mic(codec);
5432 alc_remove_invalid_adc_nids(codec);
5435 if (!spec->no_analog && !spec->cap_mixer)
5436 set_capture_mixer(codec);
5438 if (!spec->no_analog) {
5439 err = snd_hda_attach_beep_device(codec, 0x23);
5442 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
5445 spec->vmaster_nid = 0x03;
5447 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5449 codec->patch_ops = alc_patch_ops;
5450 spec->init_hook = alc_auto_init_std;
5451 #ifdef CONFIG_SND_HDA_POWER_SAVE
5452 spec->power_hook = alc_power_eapd;
5453 if (!spec->loopback.amplist)
5454 spec->loopback.amplist = alc861_loopbacks;
5469 * In addition, an independent DAC
5471 #ifdef CONFIG_SND_HDA_POWER_SAVE
5472 #define alc861vd_loopbacks alc880_loopbacks
5475 static int alc861vd_parse_auto_config(struct hda_codec *codec)
5477 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
5478 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5479 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
5483 ALC660VD_FIX_ASUS_GPIO1,
5484 ALC861VD_FIX_DALLAS,
5487 /* exclude VREF80 */
5488 static void alc861vd_fixup_dallas(struct hda_codec *codec,
5489 const struct alc_fixup *fix, int action)
5491 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
5492 snd_hda_override_pin_caps(codec, 0x18, 0x00000734);
5493 snd_hda_override_pin_caps(codec, 0x19, 0x0000073c);
5497 static const struct alc_fixup alc861vd_fixups[] = {
5498 [ALC660VD_FIX_ASUS_GPIO1] = {
5499 .type = ALC_FIXUP_VERBS,
5500 .v.verbs = (const struct hda_verb[]) {
5502 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
5503 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5504 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5508 [ALC861VD_FIX_DALLAS] = {
5509 .type = ALC_FIXUP_FUNC,
5510 .v.func = alc861vd_fixup_dallas,
5514 static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
5515 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
5516 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
5517 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
5521 static const struct hda_verb alc660vd_eapd_verbs[] = {
5522 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
5523 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
5529 static int patch_alc861vd(struct hda_codec *codec)
5531 struct alc_spec *spec;
5534 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5540 spec->mixer_nid = 0x0b;
5542 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
5543 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5545 /* automatic parse from the BIOS config */
5546 err = alc861vd_parse_auto_config(codec);
5550 if (codec->vendor_id == 0x10ec0660) {
5551 /* always turn on EAPD */
5552 add_verb(spec, alc660vd_eapd_verbs);
5555 if (!spec->no_analog && !spec->adc_nids) {
5556 alc_auto_fill_adc_caps(codec);
5557 alc_rebuild_imux_for_auto_mic(codec);
5558 alc_remove_invalid_adc_nids(codec);
5561 if (!spec->no_analog && !spec->cap_mixer)
5562 set_capture_mixer(codec);
5564 if (!spec->no_analog) {
5565 err = snd_hda_attach_beep_device(codec, 0x23);
5568 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5571 spec->vmaster_nid = 0x02;
5573 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5575 codec->patch_ops = alc_patch_ops;
5577 spec->init_hook = alc_auto_init_std;
5578 spec->shutup = alc_eapd_shutup;
5579 #ifdef CONFIG_SND_HDA_POWER_SAVE
5580 if (!spec->loopback.amplist)
5581 spec->loopback.amplist = alc861vd_loopbacks;
5594 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
5595 * configuration. Each pin widget can choose any input DACs and a mixer.
5596 * Each ADC is connected from a mixer of all inputs. This makes possible
5597 * 6-channel independent captures.
5599 * In addition, an independent DAC for the multi-playback (not used in this
5602 #ifdef CONFIG_SND_HDA_POWER_SAVE
5603 #define alc662_loopbacks alc880_loopbacks
5607 * BIOS auto configuration
5610 static int alc662_parse_auto_config(struct hda_codec *codec)
5612 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
5613 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
5614 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5615 const hda_nid_t *ssids;
5617 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
5618 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670 ||
5619 codec->vendor_id == 0x10ec0671)
5620 ssids = alc663_ssids;
5622 ssids = alc662_ssids;
5623 return alc_parse_auto_config(codec, alc662_ignore, ssids);
5626 static void alc272_fixup_mario(struct hda_codec *codec,
5627 const struct alc_fixup *fix, int action)
5629 if (action != ALC_FIXUP_ACT_PROBE)
5631 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
5632 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
5633 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
5634 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5635 (0 << AC_AMPCAP_MUTE_SHIFT)))
5637 "hda_codec: failed to override amp caps for NID 0x2\n");
5641 ALC662_FIXUP_ASPIRE,
5642 ALC662_FIXUP_IDEAPAD,
5644 ALC662_FIXUP_CZC_P10T,
5645 ALC662_FIXUP_SKU_IGNORE,
5646 ALC662_FIXUP_HP_RP5800,
5647 ALC662_FIXUP_ASUS_MODE1,
5648 ALC662_FIXUP_ASUS_MODE2,
5649 ALC662_FIXUP_ASUS_MODE3,
5650 ALC662_FIXUP_ASUS_MODE4,
5651 ALC662_FIXUP_ASUS_MODE5,
5652 ALC662_FIXUP_ASUS_MODE6,
5653 ALC662_FIXUP_ASUS_MODE7,
5654 ALC662_FIXUP_ASUS_MODE8,
5655 ALC662_FIXUP_NO_JACK_DETECT,
5656 ALC662_FIXUP_ZOTAC_Z68,
5659 static const struct alc_fixup alc662_fixups[] = {
5660 [ALC662_FIXUP_ASPIRE] = {
5661 .type = ALC_FIXUP_PINS,
5662 .v.pins = (const struct alc_pincfg[]) {
5663 { 0x15, 0x99130112 }, /* subwoofer */
5667 [ALC662_FIXUP_IDEAPAD] = {
5668 .type = ALC_FIXUP_PINS,
5669 .v.pins = (const struct alc_pincfg[]) {
5670 { 0x17, 0x99130112 }, /* subwoofer */
5674 [ALC272_FIXUP_MARIO] = {
5675 .type = ALC_FIXUP_FUNC,
5676 .v.func = alc272_fixup_mario,
5678 [ALC662_FIXUP_CZC_P10T] = {
5679 .type = ALC_FIXUP_VERBS,
5680 .v.verbs = (const struct hda_verb[]) {
5681 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
5685 [ALC662_FIXUP_SKU_IGNORE] = {
5686 .type = ALC_FIXUP_SKU,
5687 .v.sku = ALC_FIXUP_SKU_IGNORE,
5689 [ALC662_FIXUP_HP_RP5800] = {
5690 .type = ALC_FIXUP_PINS,
5691 .v.pins = (const struct alc_pincfg[]) {
5692 { 0x14, 0x0221201f }, /* HP out */
5696 .chain_id = ALC662_FIXUP_SKU_IGNORE
5698 [ALC662_FIXUP_ASUS_MODE1] = {
5699 .type = ALC_FIXUP_PINS,
5700 .v.pins = (const struct alc_pincfg[]) {
5701 { 0x14, 0x99130110 }, /* speaker */
5702 { 0x18, 0x01a19c20 }, /* mic */
5703 { 0x19, 0x99a3092f }, /* int-mic */
5704 { 0x21, 0x0121401f }, /* HP out */
5708 .chain_id = ALC662_FIXUP_SKU_IGNORE
5710 [ALC662_FIXUP_ASUS_MODE2] = {
5711 .type = ALC_FIXUP_PINS,
5712 .v.pins = (const struct alc_pincfg[]) {
5713 { 0x14, 0x99130110 }, /* speaker */
5714 { 0x18, 0x01a19820 }, /* mic */
5715 { 0x19, 0x99a3092f }, /* int-mic */
5716 { 0x1b, 0x0121401f }, /* HP out */
5720 .chain_id = ALC662_FIXUP_SKU_IGNORE
5722 [ALC662_FIXUP_ASUS_MODE3] = {
5723 .type = ALC_FIXUP_PINS,
5724 .v.pins = (const struct alc_pincfg[]) {
5725 { 0x14, 0x99130110 }, /* speaker */
5726 { 0x15, 0x0121441f }, /* HP */
5727 { 0x18, 0x01a19840 }, /* mic */
5728 { 0x19, 0x99a3094f }, /* int-mic */
5729 { 0x21, 0x01211420 }, /* HP2 */
5733 .chain_id = ALC662_FIXUP_SKU_IGNORE
5735 [ALC662_FIXUP_ASUS_MODE4] = {
5736 .type = ALC_FIXUP_PINS,
5737 .v.pins = (const struct alc_pincfg[]) {
5738 { 0x14, 0x99130110 }, /* speaker */
5739 { 0x16, 0x99130111 }, /* speaker */
5740 { 0x18, 0x01a19840 }, /* mic */
5741 { 0x19, 0x99a3094f }, /* int-mic */
5742 { 0x21, 0x0121441f }, /* HP */
5746 .chain_id = ALC662_FIXUP_SKU_IGNORE
5748 [ALC662_FIXUP_ASUS_MODE5] = {
5749 .type = ALC_FIXUP_PINS,
5750 .v.pins = (const struct alc_pincfg[]) {
5751 { 0x14, 0x99130110 }, /* speaker */
5752 { 0x15, 0x0121441f }, /* HP */
5753 { 0x16, 0x99130111 }, /* speaker */
5754 { 0x18, 0x01a19840 }, /* mic */
5755 { 0x19, 0x99a3094f }, /* int-mic */
5759 .chain_id = ALC662_FIXUP_SKU_IGNORE
5761 [ALC662_FIXUP_ASUS_MODE6] = {
5762 .type = ALC_FIXUP_PINS,
5763 .v.pins = (const struct alc_pincfg[]) {
5764 { 0x14, 0x99130110 }, /* speaker */
5765 { 0x15, 0x01211420 }, /* HP2 */
5766 { 0x18, 0x01a19840 }, /* mic */
5767 { 0x19, 0x99a3094f }, /* int-mic */
5768 { 0x1b, 0x0121441f }, /* HP */
5772 .chain_id = ALC662_FIXUP_SKU_IGNORE
5774 [ALC662_FIXUP_ASUS_MODE7] = {
5775 .type = ALC_FIXUP_PINS,
5776 .v.pins = (const struct alc_pincfg[]) {
5777 { 0x14, 0x99130110 }, /* speaker */
5778 { 0x17, 0x99130111 }, /* speaker */
5779 { 0x18, 0x01a19840 }, /* mic */
5780 { 0x19, 0x99a3094f }, /* int-mic */
5781 { 0x1b, 0x01214020 }, /* HP */
5782 { 0x21, 0x0121401f }, /* HP */
5786 .chain_id = ALC662_FIXUP_SKU_IGNORE
5788 [ALC662_FIXUP_ASUS_MODE8] = {
5789 .type = ALC_FIXUP_PINS,
5790 .v.pins = (const struct alc_pincfg[]) {
5791 { 0x14, 0x99130110 }, /* speaker */
5792 { 0x12, 0x99a30970 }, /* int-mic */
5793 { 0x15, 0x01214020 }, /* HP */
5794 { 0x17, 0x99130111 }, /* speaker */
5795 { 0x18, 0x01a19840 }, /* mic */
5796 { 0x21, 0x0121401f }, /* HP */
5800 .chain_id = ALC662_FIXUP_SKU_IGNORE
5802 [ALC662_FIXUP_NO_JACK_DETECT] = {
5803 .type = ALC_FIXUP_FUNC,
5804 .v.func = alc_fixup_no_jack_detect,
5806 [ALC662_FIXUP_ZOTAC_Z68] = {
5807 .type = ALC_FIXUP_PINS,
5808 .v.pins = (const struct alc_pincfg[]) {
5809 { 0x1b, 0x02214020 }, /* Front HP */
5815 static const struct snd_pci_quirk alc662_fixup_tbl[] = {
5816 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
5817 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
5818 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
5819 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
5820 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
5821 SND_PCI_QUIRK(0x1043, 0x1477, "ASUS N56VZ", ALC662_FIXUP_ASUS_MODE4),
5822 SND_PCI_QUIRK(0x1043, 0x1bf3, "ASUS N76VZ", ALC662_FIXUP_ASUS_MODE4),
5823 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT),
5824 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
5825 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
5826 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
5827 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
5828 SND_PCI_QUIRK(0x19da, 0xa130, "Zotac Z68", ALC662_FIXUP_ZOTAC_Z68),
5829 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
5832 /* Below is a quirk table taken from the old code.
5833 * Basically the device should work as is without the fixup table.
5834 * If BIOS doesn't give a proper info, enable the corresponding
5837 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
5838 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
5839 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
5840 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
5841 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
5842 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5843 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
5844 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
5845 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
5846 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5847 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
5848 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
5849 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
5850 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
5851 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
5852 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5853 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
5854 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
5855 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5856 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
5857 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
5858 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5859 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
5860 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
5861 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
5862 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5863 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
5864 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
5865 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5866 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
5867 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5868 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5869 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
5870 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
5871 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
5872 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
5873 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
5874 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
5875 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
5876 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5877 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
5878 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
5879 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
5880 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
5881 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
5882 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
5883 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
5884 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
5885 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
5886 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
5891 static const struct alc_model_fixup alc662_fixup_models[] = {
5892 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
5893 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
5894 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
5895 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
5896 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
5897 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
5898 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
5899 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
5900 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
5907 static int patch_alc662(struct hda_codec *codec)
5909 struct alc_spec *spec;
5912 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5918 spec->mixer_nid = 0x0b;
5920 /* handle multiple HPs as is */
5921 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
5923 alc_auto_parse_customize_define(codec);
5925 alc_fix_pll_init(codec, 0x20, 0x04, 15);
5927 err = alc_codec_rename_from_preset(codec);
5931 if ((alc_get_coef0(codec) & (1 << 14)) &&
5932 codec->bus->pci->subsystem_vendor == 0x1025 &&
5933 spec->cdefine.platform_type == 1) {
5934 if (alc_codec_rename(codec, "ALC272X") < 0)
5938 alc_pick_fixup(codec, alc662_fixup_models,
5939 alc662_fixup_tbl, alc662_fixups);
5940 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5941 /* automatic parse from the BIOS config */
5942 err = alc662_parse_auto_config(codec);
5946 if (!spec->no_analog && !spec->adc_nids) {
5947 alc_auto_fill_adc_caps(codec);
5948 alc_rebuild_imux_for_auto_mic(codec);
5949 alc_remove_invalid_adc_nids(codec);
5952 if (!spec->no_analog && !spec->cap_mixer)
5953 set_capture_mixer(codec);
5955 if (!spec->no_analog && has_cdefine_beep(codec)) {
5956 err = snd_hda_attach_beep_device(codec, 0x1);
5959 switch (codec->vendor_id) {
5961 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5967 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
5970 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
5974 spec->vmaster_nid = 0x02;
5976 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5978 codec->patch_ops = alc_patch_ops;
5979 spec->init_hook = alc_auto_init_std;
5980 spec->shutup = alc_eapd_shutup;
5982 alc_init_jacks(codec);
5984 #ifdef CONFIG_SND_HDA_POWER_SAVE
5985 if (!spec->loopback.amplist)
5986 spec->loopback.amplist = alc662_loopbacks;
6000 static int alc680_parse_auto_config(struct hda_codec *codec)
6002 return alc_parse_auto_config(codec, NULL, NULL);
6007 static int patch_alc680(struct hda_codec *codec)
6009 struct alc_spec *spec;
6012 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6018 /* ALC680 has no aa-loopback mixer */
6020 /* automatic parse from the BIOS config */
6021 err = alc680_parse_auto_config(codec);
6027 if (!spec->no_analog && !spec->cap_mixer)
6028 set_capture_mixer(codec);
6030 spec->vmaster_nid = 0x02;
6032 codec->patch_ops = alc_patch_ops;
6033 spec->init_hook = alc_auto_init_std;
6041 static const struct hda_codec_preset snd_hda_preset_realtek[] = {
6042 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
6043 { .id = 0x10ec0231, .name = "ALC231", .patch = patch_alc269 },
6044 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
6045 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
6046 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
6047 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
6048 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
6049 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
6050 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
6051 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
6052 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
6053 { .id = 0x10ec0280, .name = "ALC280", .patch = patch_alc269 },
6054 { .id = 0x10ec0282, .name = "ALC282", .patch = patch_alc269 },
6055 { .id = 0x10ec0283, .name = "ALC283", .patch = patch_alc269 },
6056 { .id = 0x10ec0290, .name = "ALC290", .patch = patch_alc269 },
6057 { .id = 0x10ec0292, .name = "ALC292", .patch = patch_alc269 },
6058 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
6059 .patch = patch_alc861 },
6060 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
6061 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
6062 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
6063 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
6064 .patch = patch_alc882 },
6065 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
6066 .patch = patch_alc662 },
6067 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
6068 .patch = patch_alc662 },
6069 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
6070 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
6071 { .id = 0x10ec0668, .name = "ALC668", .patch = patch_alc662 },
6072 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
6073 { .id = 0x10ec0671, .name = "ALC671", .patch = patch_alc662 },
6074 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
6075 { .id = 0x10ec0867, .name = "ALC891", .patch = patch_alc882 },
6076 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
6077 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
6078 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
6079 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
6080 .patch = patch_alc882 },
6081 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
6082 .patch = patch_alc882 },
6083 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
6084 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
6085 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
6086 .patch = patch_alc882 },
6087 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
6088 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
6089 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
6090 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
6091 { .id = 0x10ec0900, .name = "ALC1150", .patch = patch_alc882 },
6095 MODULE_ALIAS("snd-hda-codec-id:10ec*");
6097 MODULE_LICENSE("GPL");
6098 MODULE_DESCRIPTION("Realtek HD-audio codec");
6100 static struct hda_codec_preset_list realtek_list = {
6101 .preset = snd_hda_preset_realtek,
6102 .owner = THIS_MODULE,
6105 static int __init patch_realtek_init(void)
6107 return snd_hda_add_codec_preset(&realtek_list);
6110 static void __exit patch_realtek_exit(void)
6112 snd_hda_delete_codec_preset(&realtek_list);
6115 module_init(patch_realtek_init)
6116 module_exit(patch_realtek_exit)