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);
439 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
441 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
442 val & ~(1 << spec->pll_coef_bit));
445 static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
446 unsigned int coef_idx, unsigned int coef_bit)
448 struct alc_spec *spec = codec->spec;
450 spec->pll_coef_idx = coef_idx;
451 spec->pll_coef_bit = coef_bit;
456 * Jack-reporting via input-jack layer
459 /* initialization of jacks; currently checks only a few known pins */
460 static int alc_init_jacks(struct hda_codec *codec)
462 #ifdef CONFIG_SND_HDA_INPUT_JACK
463 struct alc_spec *spec = codec->spec;
465 unsigned int hp_nid = spec->autocfg.hp_pins[0];
466 unsigned int mic_nid = spec->ext_mic_pin;
467 unsigned int dock_nid = spec->dock_mic_pin;
470 err = snd_hda_input_jack_add(codec, hp_nid,
471 SND_JACK_HEADPHONE, NULL);
474 snd_hda_input_jack_report(codec, hp_nid);
478 err = snd_hda_input_jack_add(codec, mic_nid,
479 SND_JACK_MICROPHONE, NULL);
482 snd_hda_input_jack_report(codec, mic_nid);
485 err = snd_hda_input_jack_add(codec, dock_nid,
486 SND_JACK_MICROPHONE, NULL);
489 snd_hda_input_jack_report(codec, dock_nid);
491 #endif /* CONFIG_SND_HDA_INPUT_JACK */
496 * Jack detections for HP auto-mute and mic-switch
499 /* check each pin in the given array; returns true if any of them is plugged */
500 static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
504 for (i = 0; i < num_pins; i++) {
505 hda_nid_t nid = pins[i];
508 snd_hda_input_jack_report(codec, nid);
509 present |= snd_hda_jack_detect(codec, nid);
514 /* standard HP/line-out auto-mute helper */
515 static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
516 bool mute, bool hp_out)
518 struct alc_spec *spec = codec->spec;
519 unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0;
520 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
523 for (i = 0; i < num_pins; i++) {
524 hda_nid_t nid = pins[i];
528 switch (spec->automute_mode) {
529 case ALC_AUTOMUTE_PIN:
530 /* don't reset VREF value in case it's controlling
531 * the amp (see alc861_fixup_asus_amp_vref_0f())
533 if (spec->keep_vref_in_automute) {
534 val = snd_hda_codec_read(codec, nid, 0,
535 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
540 snd_hda_codec_write(codec, nid, 0,
541 AC_VERB_SET_PIN_WIDGET_CONTROL,
544 case ALC_AUTOMUTE_AMP:
545 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
546 HDA_AMP_MUTE, mute_bits);
548 case ALC_AUTOMUTE_MIXER:
549 nid = spec->automute_mixer_nid[i];
552 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
553 HDA_AMP_MUTE, mute_bits);
554 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1,
555 HDA_AMP_MUTE, mute_bits);
561 /* Toggle outputs muting */
562 static void update_outputs(struct hda_codec *codec)
564 struct alc_spec *spec = codec->spec;
567 /* Control HP pins/amps depending on master_mute state;
568 * in general, HP pins/amps control should be enabled in all cases,
569 * but currently set only for master_mute, just to be safe
571 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
572 spec->autocfg.hp_pins, spec->master_mute, true);
574 if (!spec->automute_speaker)
577 on = spec->hp_jack_present | spec->line_jack_present;
578 on |= spec->master_mute;
579 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
580 spec->autocfg.speaker_pins, on, false);
582 /* toggle line-out mutes if needed, too */
583 /* if LO is a copy of either HP or Speaker, don't need to handle it */
584 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
585 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
587 if (!spec->automute_lo)
590 on = spec->hp_jack_present;
591 on |= spec->master_mute;
592 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
593 spec->autocfg.line_out_pins, on, false);
596 static void call_update_outputs(struct hda_codec *codec)
598 struct alc_spec *spec = codec->spec;
599 if (spec->automute_hook)
600 spec->automute_hook(codec);
602 update_outputs(codec);
605 /* standard HP-automute helper */
606 static void alc_hp_automute(struct hda_codec *codec)
608 struct alc_spec *spec = codec->spec;
610 spec->hp_jack_present =
611 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
612 spec->autocfg.hp_pins);
613 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
615 call_update_outputs(codec);
618 /* standard line-out-automute helper */
619 static void alc_line_automute(struct hda_codec *codec)
621 struct alc_spec *spec = codec->spec;
623 /* check LO jack only when it's different from HP */
624 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
627 spec->line_jack_present =
628 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
629 spec->autocfg.line_out_pins);
630 if (!spec->automute_speaker || !spec->detect_lo)
632 call_update_outputs(codec);
635 #define get_connection_index(codec, mux, nid) \
636 snd_hda_get_conn_index(codec, mux, nid, 0)
638 /* standard mic auto-switch helper */
639 static void alc_mic_automute(struct hda_codec *codec)
641 struct alc_spec *spec = codec->spec;
642 hda_nid_t *pins = spec->imux_pins;
644 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
646 if (snd_BUG_ON(!spec->adc_nids))
648 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
651 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
652 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
653 else if (spec->dock_mic_idx >= 0 &&
654 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
655 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
657 alc_mux_select(codec, 0, spec->int_mic_idx, false);
659 snd_hda_input_jack_report(codec, pins[spec->ext_mic_idx]);
660 if (spec->dock_mic_idx >= 0)
661 snd_hda_input_jack_report(codec, pins[spec->dock_mic_idx]);
664 /* unsolicited event for HP jack sensing */
665 static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
667 if (codec->vendor_id == 0x10ec0880)
673 alc_hp_automute(codec);
675 case ALC_FRONT_EVENT:
676 alc_line_automute(codec);
679 alc_mic_automute(codec);
684 /* call init functions of standard auto-mute helpers */
685 static void alc_inithook(struct hda_codec *codec)
687 alc_hp_automute(codec);
688 alc_line_automute(codec);
689 alc_mic_automute(codec);
692 /* additional initialization for ALC888 variants */
693 static void alc888_coef_init(struct hda_codec *codec)
697 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
698 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
699 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
700 if ((tmp & 0xf0) == 0x20)
702 snd_hda_codec_read(codec, 0x20, 0,
703 AC_VERB_SET_PROC_COEF, 0x830);
706 snd_hda_codec_read(codec, 0x20, 0,
707 AC_VERB_SET_PROC_COEF, 0x3030);
710 /* additional initialization for ALC889 variants */
711 static void alc889_coef_init(struct hda_codec *codec)
715 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
716 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
717 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
718 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
721 /* turn on/off EAPD control (only if available) */
722 static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
724 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
726 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
727 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
731 /* turn on/off EAPD controls of the codec */
732 static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
734 /* We currently only handle front, HP */
735 static hda_nid_t pins[] = {
736 0x0f, 0x10, 0x14, 0x15, 0
739 for (p = pins; *p; p++)
740 set_eapd(codec, *p, on);
743 /* generic shutup callback;
744 * just turning off EPAD and a little pause for avoiding pop-noise
746 static void alc_eapd_shutup(struct hda_codec *codec)
748 alc_auto_setup_eapd(codec, false);
752 /* generic EAPD initialization */
753 static void alc_auto_init_amp(struct hda_codec *codec, int type)
757 alc_auto_setup_eapd(codec, true);
760 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
763 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
766 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
768 case ALC_INIT_DEFAULT:
769 switch (codec->vendor_id) {
771 snd_hda_codec_write(codec, 0x1a, 0,
772 AC_VERB_SET_COEF_INDEX, 7);
773 tmp = snd_hda_codec_read(codec, 0x1a, 0,
774 AC_VERB_GET_PROC_COEF, 0);
775 snd_hda_codec_write(codec, 0x1a, 0,
776 AC_VERB_SET_COEF_INDEX, 7);
777 snd_hda_codec_write(codec, 0x1a, 0,
778 AC_VERB_SET_PROC_COEF,
787 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
788 alc889_coef_init(codec);
791 alc888_coef_init(codec);
793 #if 0 /* XXX: This may cause the silent output on speaker on some machines */
796 snd_hda_codec_write(codec, 0x20, 0,
797 AC_VERB_SET_COEF_INDEX, 7);
798 tmp = snd_hda_codec_read(codec, 0x20, 0,
799 AC_VERB_GET_PROC_COEF, 0);
800 snd_hda_codec_write(codec, 0x20, 0,
801 AC_VERB_SET_COEF_INDEX, 7);
802 snd_hda_codec_write(codec, 0x20, 0,
803 AC_VERB_SET_PROC_COEF,
813 * Auto-Mute mode mixer enum support
815 static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
816 struct snd_ctl_elem_info *uinfo)
818 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
819 struct alc_spec *spec = codec->spec;
820 static const char * const texts2[] = {
821 "Disabled", "Enabled"
823 static const char * const texts3[] = {
824 "Disabled", "Speaker Only", "Line-Out+Speaker"
826 const char * const *texts;
828 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
830 if (spec->automute_speaker_possible && spec->automute_lo_possible) {
831 uinfo->value.enumerated.items = 3;
834 uinfo->value.enumerated.items = 2;
837 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
838 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
839 strcpy(uinfo->value.enumerated.name,
840 texts[uinfo->value.enumerated.item]);
844 static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
845 struct snd_ctl_elem_value *ucontrol)
847 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
848 struct alc_spec *spec = codec->spec;
849 unsigned int val = 0;
850 if (spec->automute_speaker)
852 if (spec->automute_lo)
855 ucontrol->value.enumerated.item[0] = val;
859 static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
860 struct snd_ctl_elem_value *ucontrol)
862 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
863 struct alc_spec *spec = codec->spec;
865 switch (ucontrol->value.enumerated.item[0]) {
867 if (!spec->automute_speaker && !spec->automute_lo)
869 spec->automute_speaker = 0;
870 spec->automute_lo = 0;
873 if (spec->automute_speaker_possible) {
874 if (!spec->automute_lo && spec->automute_speaker)
876 spec->automute_speaker = 1;
877 spec->automute_lo = 0;
878 } else if (spec->automute_lo_possible) {
879 if (spec->automute_lo)
881 spec->automute_lo = 1;
886 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
888 if (spec->automute_speaker && spec->automute_lo)
890 spec->automute_speaker = 1;
891 spec->automute_lo = 1;
896 call_update_outputs(codec);
900 static const struct snd_kcontrol_new alc_automute_mode_enum = {
901 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
902 .name = "Auto-Mute Mode",
903 .info = alc_automute_mode_info,
904 .get = alc_automute_mode_get,
905 .put = alc_automute_mode_put,
908 static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec)
910 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
911 return snd_array_new(&spec->kctls);
914 static int alc_add_automute_mode_enum(struct hda_codec *codec)
916 struct alc_spec *spec = codec->spec;
917 struct snd_kcontrol_new *knew;
919 knew = alc_kcontrol_new(spec);
922 *knew = alc_automute_mode_enum;
923 knew->name = kstrdup("Auto-Mute Mode", GFP_KERNEL);
930 * Check the availability of HP/line-out auto-mute;
931 * Set up appropriately if really supported
933 static void alc_init_automute(struct hda_codec *codec)
935 struct alc_spec *spec = codec->spec;
936 struct auto_pin_cfg *cfg = &spec->autocfg;
942 if (cfg->line_out_pins[0])
944 if (cfg->speaker_pins[0])
946 if (present < 2) /* need two different output types */
949 if (!cfg->speaker_pins[0] &&
950 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
951 memcpy(cfg->speaker_pins, cfg->line_out_pins,
952 sizeof(cfg->speaker_pins));
953 cfg->speaker_outs = cfg->line_outs;
956 if (!cfg->hp_pins[0] &&
957 cfg->line_out_type == AUTO_PIN_HP_OUT) {
958 memcpy(cfg->hp_pins, cfg->line_out_pins,
959 sizeof(cfg->hp_pins));
960 cfg->hp_outs = cfg->line_outs;
963 spec->automute_mode = ALC_AUTOMUTE_PIN;
965 for (i = 0; i < cfg->hp_outs; i++) {
966 hda_nid_t nid = cfg->hp_pins[i];
967 if (!is_jack_detectable(codec, nid))
969 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
971 snd_hda_codec_write_cache(codec, nid, 0,
972 AC_VERB_SET_UNSOLICITED_ENABLE,
973 AC_USRSP_EN | ALC_HP_EVENT);
977 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
978 if (cfg->speaker_outs)
979 for (i = 0; i < cfg->line_outs; i++) {
980 hda_nid_t nid = cfg->line_out_pins[i];
981 if (!is_jack_detectable(codec, nid))
983 snd_printdd("realtek: Enable Line-Out "
984 "auto-muting on NID 0x%x\n", nid);
985 snd_hda_codec_write_cache(codec, nid, 0,
986 AC_VERB_SET_UNSOLICITED_ENABLE,
987 AC_USRSP_EN | ALC_FRONT_EVENT);
990 spec->automute_lo_possible = spec->detect_hp;
993 spec->automute_speaker_possible = cfg->speaker_outs &&
994 (spec->detect_hp || spec->detect_lo);
996 spec->automute_lo = spec->automute_lo_possible;
997 spec->automute_speaker = spec->automute_speaker_possible;
999 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
1000 /* create a control for automute mode */
1001 alc_add_automute_mode_enum(codec);
1002 spec->unsol_event = alc_sku_unsol_event;
1006 /* return the position of NID in the list, or -1 if not found */
1007 static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1010 for (i = 0; i < nums; i++)
1016 /* check whether dynamic ADC-switching is available */
1017 static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
1019 struct alc_spec *spec = codec->spec;
1020 struct hda_input_mux *imux = &spec->private_imux[0];
1024 if (imux != spec->input_mux) /* no dynamic imux? */
1027 for (n = 0; n < spec->num_adc_nids; n++) {
1028 cap = spec->private_capsrc_nids[n];
1029 for (i = 0; i < imux->num_items; i++) {
1030 pin = spec->imux_pins[i];
1033 if (get_connection_index(codec, cap, pin) < 0)
1036 if (i >= imux->num_items)
1037 return true; /* no ADC-switch is needed */
1040 for (i = 0; i < imux->num_items; i++) {
1041 pin = spec->imux_pins[i];
1042 for (n = 0; n < spec->num_adc_nids; n++) {
1043 cap = spec->private_capsrc_nids[n];
1044 idx = get_connection_index(codec, cap, pin);
1046 imux->items[i].index = idx;
1047 spec->dyn_adc_idx[i] = n;
1053 snd_printdd("realtek: enabling ADC switching\n");
1054 spec->dyn_adc_switch = 1;
1058 /* rebuild imux for matching with the given auto-mic pins (if not yet) */
1059 static bool alc_rebuild_imux_for_auto_mic(struct hda_codec *codec)
1061 struct alc_spec *spec = codec->spec;
1062 struct hda_input_mux *imux;
1063 static char * const texts[3] = {
1064 "Mic", "Internal Mic", "Dock Mic"
1068 if (!spec->auto_mic)
1070 imux = &spec->private_imux[0];
1071 if (spec->input_mux == imux)
1073 spec->imux_pins[0] = spec->ext_mic_pin;
1074 spec->imux_pins[1] = spec->int_mic_pin;
1075 spec->imux_pins[2] = spec->dock_mic_pin;
1076 for (i = 0; i < 3; i++) {
1077 strcpy(imux->items[i].label, texts[i]);
1078 if (spec->imux_pins[i]) {
1079 hda_nid_t pin = spec->imux_pins[i];
1081 for (c = 0; c < spec->num_adc_nids; c++) {
1082 hda_nid_t cap = get_capsrc(spec, c);
1083 int idx = get_connection_index(codec, cap, pin);
1085 imux->items[i].index = idx;
1089 imux->num_items = i + 1;
1092 spec->num_mux_defs = 1;
1093 spec->input_mux = imux;
1097 /* check whether all auto-mic pins are valid; setup indices if OK */
1098 static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1100 struct alc_spec *spec = codec->spec;
1101 const struct hda_input_mux *imux;
1103 if (!spec->auto_mic)
1105 if (spec->auto_mic_valid_imux)
1106 return true; /* already checked */
1108 /* fill up imux indices */
1109 if (!alc_check_dyn_adc_switch(codec)) {
1114 imux = spec->input_mux;
1115 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1116 spec->imux_pins, imux->num_items);
1117 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1118 spec->imux_pins, imux->num_items);
1119 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1120 spec->imux_pins, imux->num_items);
1121 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1123 return false; /* no corresponding imux */
1126 snd_hda_codec_write_cache(codec, spec->ext_mic_pin, 0,
1127 AC_VERB_SET_UNSOLICITED_ENABLE,
1128 AC_USRSP_EN | ALC_MIC_EVENT);
1129 if (spec->dock_mic_pin)
1130 snd_hda_codec_write_cache(codec, spec->dock_mic_pin, 0,
1131 AC_VERB_SET_UNSOLICITED_ENABLE,
1132 AC_USRSP_EN | ALC_MIC_EVENT);
1134 spec->auto_mic_valid_imux = 1;
1140 * Check the availability of auto-mic switch;
1141 * Set up if really supported
1143 static void alc_init_auto_mic(struct hda_codec *codec)
1145 struct alc_spec *spec = codec->spec;
1146 struct auto_pin_cfg *cfg = &spec->autocfg;
1147 hda_nid_t fixed, ext, dock;
1150 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1152 fixed = ext = dock = 0;
1153 for (i = 0; i < cfg->num_inputs; i++) {
1154 hda_nid_t nid = cfg->inputs[i].pin;
1155 unsigned int defcfg;
1156 defcfg = snd_hda_codec_get_pincfg(codec, nid);
1157 switch (snd_hda_get_input_pin_attr(defcfg)) {
1158 case INPUT_PIN_ATTR_INT:
1160 return; /* already occupied */
1161 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1162 return; /* invalid type */
1165 case INPUT_PIN_ATTR_UNUSED:
1166 return; /* invalid entry */
1167 case INPUT_PIN_ATTR_DOCK:
1169 return; /* already occupied */
1170 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1171 return; /* invalid type */
1176 return; /* already occupied */
1177 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1178 return; /* invalid type */
1189 if (!is_jack_detectable(codec, ext))
1190 return; /* no unsol support */
1191 if (dock && !is_jack_detectable(codec, dock))
1192 return; /* no unsol support */
1194 /* check imux indices */
1195 spec->ext_mic_pin = ext;
1196 spec->int_mic_pin = fixed;
1197 spec->dock_mic_pin = dock;
1200 if (!alc_auto_mic_check_imux(codec))
1203 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1205 spec->unsol_event = alc_sku_unsol_event;
1208 /* check the availabilities of auto-mute and auto-mic switches */
1209 static void alc_auto_check_switches(struct hda_codec *codec)
1211 alc_init_automute(codec);
1212 alc_init_auto_mic(codec);
1216 * Realtek SSID verification
1219 /* Could be any non-zero and even value. When used as fixup, tells
1220 * the driver to ignore any present sku defines.
1222 #define ALC_FIXUP_SKU_IGNORE (2)
1224 static int alc_auto_parse_customize_define(struct hda_codec *codec)
1226 unsigned int ass, tmp, i;
1228 struct alc_spec *spec = codec->spec;
1230 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1232 if (spec->cdefine.fixup) {
1233 ass = spec->cdefine.sku_cfg;
1234 if (ass == ALC_FIXUP_SKU_IGNORE)
1239 ass = codec->subsystem_id & 0xffff;
1240 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
1244 if (codec->vendor_id == 0x10ec0260)
1246 ass = snd_hda_codec_get_pincfg(codec, nid);
1249 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1250 codec->chip_name, ass);
1256 for (i = 1; i < 16; i++) {
1260 if (((ass >> 16) & 0xf) != tmp)
1263 spec->cdefine.port_connectivity = ass >> 30;
1264 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1265 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1266 spec->cdefine.customization = ass >> 8;
1268 spec->cdefine.sku_cfg = ass;
1269 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1270 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1271 spec->cdefine.swap = (ass & 0x2) >> 1;
1272 spec->cdefine.override = ass & 0x1;
1274 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1275 nid, spec->cdefine.sku_cfg);
1276 snd_printd("SKU: port_connectivity=0x%x\n",
1277 spec->cdefine.port_connectivity);
1278 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1279 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1280 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1281 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1282 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1283 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1284 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1289 /* return true if the given NID is found in the list */
1290 static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1292 return find_idx_in_nid_list(nid, list, nums) >= 0;
1295 /* check subsystem ID and set up device-specific initialization;
1296 * return 1 if initialized, 0 if invalid SSID
1298 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1299 * 31 ~ 16 : Manufacture ID
1301 * 7 ~ 0 : Assembly ID
1302 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1304 static int alc_subsystem_id(struct hda_codec *codec,
1305 hda_nid_t porta, hda_nid_t porte,
1306 hda_nid_t portd, hda_nid_t porti)
1308 unsigned int ass, tmp, i;
1310 struct alc_spec *spec = codec->spec;
1312 if (spec->cdefine.fixup) {
1313 ass = spec->cdefine.sku_cfg;
1314 if (ass == ALC_FIXUP_SKU_IGNORE)
1319 ass = codec->subsystem_id & 0xffff;
1320 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1323 /* invalid SSID, check the special NID pin defcfg instead */
1325 * 31~30 : port connectivity
1328 * 19~16 : Check sum (15:1)
1333 if (codec->vendor_id == 0x10ec0260)
1335 ass = snd_hda_codec_get_pincfg(codec, nid);
1336 snd_printd("realtek: No valid SSID, "
1337 "checking pincfg 0x%08x for NID 0x%x\n",
1341 if ((ass >> 30) != 1) /* no physical connection */
1346 for (i = 1; i < 16; i++) {
1350 if (((ass >> 16) & 0xf) != tmp)
1353 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1354 ass & 0xffff, codec->vendor_id);
1358 * 2 : 0 --> Desktop, 1 --> Laptop
1359 * 3~5 : External Amplifier control
1362 tmp = (ass & 0x38) >> 3; /* external Amp control */
1365 spec->init_amp = ALC_INIT_GPIO1;
1368 spec->init_amp = ALC_INIT_GPIO2;
1371 spec->init_amp = ALC_INIT_GPIO3;
1375 spec->init_amp = ALC_INIT_DEFAULT;
1379 /* is laptop or Desktop and enable the function "Mute internal speaker
1380 * when the external headphone out jack is plugged"
1382 if (!(ass & 0x8000))
1385 * 10~8 : Jack location
1386 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1388 * 15 : 1 --> enable the function "Mute internal speaker
1389 * when the external headphone out jack is plugged"
1391 if (!spec->autocfg.hp_pins[0] &&
1392 !(spec->autocfg.line_out_pins[0] &&
1393 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
1395 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1406 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1407 spec->autocfg.line_outs))
1409 spec->autocfg.hp_pins[0] = nid;
1414 /* Check the validity of ALC subsystem-id
1415 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1416 static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
1418 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
1419 struct alc_spec *spec = codec->spec;
1420 snd_printd("realtek: "
1421 "Enable default setup for auto mode as fallback\n");
1422 spec->init_amp = ALC_INIT_DEFAULT;
1427 * Fix-up pin default configurations and add default verbs
1435 struct alc_model_fixup {
1446 const struct alc_pincfg *pins;
1447 const struct hda_verb *verbs;
1448 void (*func)(struct hda_codec *codec,
1449 const struct alc_fixup *fix,
1463 ALC_FIXUP_ACT_PRE_PROBE,
1464 ALC_FIXUP_ACT_PROBE,
1468 static void alc_apply_fixup(struct hda_codec *codec, int action)
1470 struct alc_spec *spec = codec->spec;
1471 int id = spec->fixup_id;
1472 #ifdef CONFIG_SND_DEBUG_VERBOSE
1473 const char *modelname = spec->fixup_name;
1477 if (!spec->fixup_list)
1481 const struct alc_fixup *fix = spec->fixup_list + id;
1482 const struct alc_pincfg *cfg;
1484 switch (fix->type) {
1486 if (action != ALC_FIXUP_ACT_PRE_PROBE || !fix->v.sku)
1488 snd_printdd(KERN_INFO "hda_codec: %s: "
1489 "Apply sku override for %s\n",
1490 codec->chip_name, modelname);
1491 spec->cdefine.sku_cfg = fix->v.sku;
1492 spec->cdefine.fixup = 1;
1494 case ALC_FIXUP_PINS:
1496 if (action != ALC_FIXUP_ACT_PRE_PROBE || !cfg)
1498 snd_printdd(KERN_INFO "hda_codec: %s: "
1499 "Apply pincfg for %s\n",
1500 codec->chip_name, modelname);
1501 for (; cfg->nid; cfg++)
1502 snd_hda_codec_set_pincfg(codec, cfg->nid,
1505 case ALC_FIXUP_VERBS:
1506 if (action != ALC_FIXUP_ACT_PROBE || !fix->v.verbs)
1508 snd_printdd(KERN_INFO "hda_codec: %s: "
1509 "Apply fix-verbs for %s\n",
1510 codec->chip_name, modelname);
1511 add_verb(codec->spec, fix->v.verbs);
1513 case ALC_FIXUP_FUNC:
1516 snd_printdd(KERN_INFO "hda_codec: %s: "
1517 "Apply fix-func for %s\n",
1518 codec->chip_name, modelname);
1519 fix->v.func(codec, fix, action);
1522 snd_printk(KERN_ERR "hda_codec: %s: "
1523 "Invalid fixup type %d\n",
1524 codec->chip_name, fix->type);
1535 static void alc_pick_fixup(struct hda_codec *codec,
1536 const struct alc_model_fixup *models,
1537 const struct snd_pci_quirk *quirk,
1538 const struct alc_fixup *fixlist)
1540 struct alc_spec *spec = codec->spec;
1542 const char *name = NULL;
1544 if (codec->modelname && models) {
1545 while (models->name) {
1546 if (!strcmp(codec->modelname, models->name)) {
1548 name = models->name;
1555 quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1558 #ifdef CONFIG_SND_DEBUG_VERBOSE
1564 spec->fixup_id = id;
1566 spec->fixup_list = fixlist;
1567 spec->fixup_name = name;
1572 * COEF access helper functions
1574 static int alc_read_coef_idx(struct hda_codec *codec,
1575 unsigned int coef_idx)
1578 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1580 val = snd_hda_codec_read(codec, 0x20, 0,
1581 AC_VERB_GET_PROC_COEF, 0);
1585 static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1586 unsigned int coef_val)
1588 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1590 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1594 /* a special bypass for COEF 0; read the cached value at the second time */
1595 static unsigned int alc_get_coef0(struct hda_codec *codec)
1597 struct alc_spec *spec = codec->spec;
1599 spec->coef0 = alc_read_coef_idx(codec, 0);
1604 * Digital I/O handling
1607 /* set right pin controls for digital I/O */
1608 static void alc_auto_init_digital(struct hda_codec *codec)
1610 struct alc_spec *spec = codec->spec;
1614 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1615 pin = spec->autocfg.dig_out_pins[i];
1618 snd_hda_codec_write(codec, pin, 0,
1619 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
1621 dac = spec->multiout.dig_out_nid;
1623 dac = spec->slave_dig_outs[i - 1];
1624 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
1626 snd_hda_codec_write(codec, dac, 0,
1627 AC_VERB_SET_AMP_GAIN_MUTE,
1630 pin = spec->autocfg.dig_in_pin;
1632 snd_hda_codec_write(codec, pin, 0,
1633 AC_VERB_SET_PIN_WIDGET_CONTROL,
1637 /* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1638 static void alc_auto_parse_digital(struct hda_codec *codec)
1640 struct alc_spec *spec = codec->spec;
1644 /* support multiple SPDIFs; the secondary is set up as a slave */
1646 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1648 err = snd_hda_get_connections(codec,
1649 spec->autocfg.dig_out_pins[i],
1650 conn, ARRAY_SIZE(conn));
1653 dig_nid = conn[0]; /* assume the first element is audio-out */
1655 spec->multiout.dig_out_nid = dig_nid;
1656 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1658 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
1659 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
1661 spec->slave_dig_outs[nums - 1] = dig_nid;
1666 if (spec->autocfg.dig_in_pin) {
1667 dig_nid = codec->start_nid;
1668 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1669 unsigned int wcaps = get_wcaps(codec, dig_nid);
1670 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1672 if (!(wcaps & AC_WCAP_DIGITAL))
1674 if (!(wcaps & AC_WCAP_CONN_LIST))
1676 err = get_connection_index(codec, dig_nid,
1677 spec->autocfg.dig_in_pin);
1679 spec->dig_in_nid = dig_nid;
1687 * capture mixer elements
1689 static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1690 struct snd_ctl_elem_info *uinfo)
1692 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1693 struct alc_spec *spec = codec->spec;
1697 mutex_lock(&codec->control_mutex);
1698 if (spec->vol_in_capsrc)
1699 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1701 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1702 kcontrol->private_value = val;
1703 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
1704 mutex_unlock(&codec->control_mutex);
1708 static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1709 unsigned int size, unsigned int __user *tlv)
1711 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1712 struct alc_spec *spec = codec->spec;
1716 mutex_lock(&codec->control_mutex);
1717 if (spec->vol_in_capsrc)
1718 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1720 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1721 kcontrol->private_value = val;
1722 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
1723 mutex_unlock(&codec->control_mutex);
1727 typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1728 struct snd_ctl_elem_value *ucontrol);
1730 static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1731 struct snd_ctl_elem_value *ucontrol,
1732 getput_call_t func, bool check_adc_switch)
1734 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1735 struct alc_spec *spec = codec->spec;
1738 mutex_lock(&codec->control_mutex);
1739 if (check_adc_switch && spec->dyn_adc_switch) {
1740 for (i = 0; i < spec->num_adc_nids; i++) {
1741 kcontrol->private_value =
1742 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1744 err = func(kcontrol, ucontrol);
1749 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1750 if (spec->vol_in_capsrc)
1751 kcontrol->private_value =
1752 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1755 kcontrol->private_value =
1756 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1758 err = func(kcontrol, ucontrol);
1761 mutex_unlock(&codec->control_mutex);
1765 static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1766 struct snd_ctl_elem_value *ucontrol)
1768 return alc_cap_getput_caller(kcontrol, ucontrol,
1769 snd_hda_mixer_amp_volume_get, false);
1772 static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1773 struct snd_ctl_elem_value *ucontrol)
1775 return alc_cap_getput_caller(kcontrol, ucontrol,
1776 snd_hda_mixer_amp_volume_put, true);
1779 /* capture mixer elements */
1780 #define alc_cap_sw_info snd_ctl_boolean_stereo_info
1782 static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1783 struct snd_ctl_elem_value *ucontrol)
1785 return alc_cap_getput_caller(kcontrol, ucontrol,
1786 snd_hda_mixer_amp_switch_get, false);
1789 static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1790 struct snd_ctl_elem_value *ucontrol)
1792 return alc_cap_getput_caller(kcontrol, ucontrol,
1793 snd_hda_mixer_amp_switch_put, true);
1796 #define _DEFINE_CAPMIX(num) \
1798 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1799 .name = "Capture Switch", \
1800 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1802 .info = alc_cap_sw_info, \
1803 .get = alc_cap_sw_get, \
1804 .put = alc_cap_sw_put, \
1807 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1808 .name = "Capture Volume", \
1809 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1810 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1811 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1813 .info = alc_cap_vol_info, \
1814 .get = alc_cap_vol_get, \
1815 .put = alc_cap_vol_put, \
1816 .tlv = { .c = alc_cap_vol_tlv }, \
1819 #define _DEFINE_CAPSRC(num) \
1821 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1822 /* .name = "Capture Source", */ \
1823 .name = "Input Source", \
1825 .info = alc_mux_enum_info, \
1826 .get = alc_mux_enum_get, \
1827 .put = alc_mux_enum_put, \
1830 #define DEFINE_CAPMIX(num) \
1831 static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
1832 _DEFINE_CAPMIX(num), \
1833 _DEFINE_CAPSRC(num), \
1837 #define DEFINE_CAPMIX_NOSRC(num) \
1838 static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
1839 _DEFINE_CAPMIX(num), \
1843 /* up to three ADCs */
1847 DEFINE_CAPMIX_NOSRC(1);
1848 DEFINE_CAPMIX_NOSRC(2);
1849 DEFINE_CAPMIX_NOSRC(3);
1852 * virtual master controls
1856 * slave controls for virtual master
1858 static const char * const alc_slave_vols[] = {
1859 "Front Playback Volume",
1860 "Surround Playback Volume",
1861 "Center Playback Volume",
1862 "LFE Playback Volume",
1863 "Side Playback Volume",
1864 "Headphone Playback Volume",
1865 "Speaker Playback Volume",
1866 "Mono Playback Volume",
1867 "Line-Out Playback Volume",
1868 "PCM Playback Volume",
1872 static const char * const alc_slave_sws[] = {
1873 "Front Playback Switch",
1874 "Surround Playback Switch",
1875 "Center Playback Switch",
1876 "LFE Playback Switch",
1877 "Side Playback Switch",
1878 "Headphone Playback Switch",
1879 "Speaker Playback Switch",
1880 "Mono Playback Switch",
1881 "IEC958 Playback Switch",
1882 "Line-Out Playback Switch",
1883 "PCM Playback Switch",
1888 * build control elements
1891 #define NID_MAPPING (-1)
1893 #define SUBDEV_SPEAKER_ (0 << 6)
1894 #define SUBDEV_HP_ (1 << 6)
1895 #define SUBDEV_LINE_ (2 << 6)
1896 #define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1897 #define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1898 #define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1900 static void alc_free_kctls(struct hda_codec *codec);
1902 #ifdef CONFIG_SND_HDA_INPUT_BEEP
1903 /* additional beep mixers; the actual parameters are overwritten at build */
1904 static const struct snd_kcontrol_new alc_beep_mixer[] = {
1905 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
1906 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
1911 static int alc_build_controls(struct hda_codec *codec)
1913 struct alc_spec *spec = codec->spec;
1914 struct snd_kcontrol *kctl = NULL;
1915 const struct snd_kcontrol_new *knew;
1920 for (i = 0; i < spec->num_mixers; i++) {
1921 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1925 if (spec->cap_mixer) {
1926 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1930 if (spec->multiout.dig_out_nid) {
1931 err = snd_hda_create_spdif_out_ctls(codec,
1932 spec->multiout.dig_out_nid,
1933 spec->multiout.dig_out_nid);
1936 if (!spec->no_analog) {
1937 err = snd_hda_create_spdif_share_sw(codec,
1941 spec->multiout.share_spdif = 1;
1944 if (spec->dig_in_nid) {
1945 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1950 #ifdef CONFIG_SND_HDA_INPUT_BEEP
1951 /* create beep controls if needed */
1952 if (spec->beep_amp) {
1953 const struct snd_kcontrol_new *knew;
1954 for (knew = alc_beep_mixer; knew->name; knew++) {
1955 struct snd_kcontrol *kctl;
1956 kctl = snd_ctl_new1(knew, codec);
1959 kctl->private_value = spec->beep_amp;
1960 err = snd_hda_ctl_add(codec, 0, kctl);
1967 /* if we have no master control, let's create it */
1968 if (!spec->no_analog &&
1969 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1970 unsigned int vmaster_tlv[4];
1971 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
1972 HDA_OUTPUT, vmaster_tlv);
1973 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1974 vmaster_tlv, alc_slave_vols);
1978 if (!spec->no_analog &&
1979 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1980 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1981 NULL, alc_slave_sws);
1986 /* assign Capture Source enums to NID */
1987 if (spec->capsrc_nids || spec->adc_nids) {
1988 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
1990 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1991 for (i = 0; kctl && i < kctl->count; i++) {
1992 err = snd_hda_add_nid(codec, kctl, i,
1993 get_capsrc(spec, i));
1998 if (spec->cap_mixer && spec->adc_nids) {
1999 const char *kname = kctl ? kctl->id.name : NULL;
2000 for (knew = spec->cap_mixer; knew->name; knew++) {
2001 if (kname && strcmp(knew->name, kname) == 0)
2003 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
2004 for (i = 0; kctl && i < kctl->count; i++) {
2005 err = snd_hda_add_nid(codec, kctl, i,
2013 /* other nid->control mapping */
2014 for (i = 0; i < spec->num_mixers; i++) {
2015 for (knew = spec->mixers[i]; knew->name; knew++) {
2016 if (knew->iface != NID_MAPPING)
2018 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
2021 u = knew->subdevice;
2022 for (j = 0; j < 4; j++, u >>= 8) {
2027 case SUBDEV_SPEAKER_:
2028 nid = spec->autocfg.speaker_pins[nid];
2031 nid = spec->autocfg.line_out_pins[nid];
2034 nid = spec->autocfg.hp_pins[nid];
2039 err = snd_hda_add_nid(codec, kctl, 0, nid);
2043 u = knew->private_value;
2044 for (j = 0; j < 4; j++, u >>= 8) {
2048 err = snd_hda_add_nid(codec, kctl, 0, nid);
2055 alc_free_kctls(codec); /* no longer needed */
2065 static void alc_init_special_input_src(struct hda_codec *codec);
2067 static int alc_init(struct hda_codec *codec)
2069 struct alc_spec *spec = codec->spec;
2073 alc_auto_init_amp(codec, spec->init_amp);
2075 for (i = 0; i < spec->num_init_verbs; i++)
2076 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2077 alc_init_special_input_src(codec);
2079 if (spec->init_hook)
2080 spec->init_hook(codec);
2082 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2084 hda_call_check_power_status(codec, 0x01);
2088 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2090 struct alc_spec *spec = codec->spec;
2092 if (spec->unsol_event)
2093 spec->unsol_event(codec, res);
2096 #ifdef CONFIG_SND_HDA_POWER_SAVE
2097 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2099 struct alc_spec *spec = codec->spec;
2100 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2105 * Analog playback callbacks
2107 static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
2108 struct hda_codec *codec,
2109 struct snd_pcm_substream *substream)
2111 struct alc_spec *spec = codec->spec;
2112 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2116 static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2117 struct hda_codec *codec,
2118 unsigned int stream_tag,
2119 unsigned int format,
2120 struct snd_pcm_substream *substream)
2122 struct alc_spec *spec = codec->spec;
2123 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2124 stream_tag, format, substream);
2127 static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2128 struct hda_codec *codec,
2129 struct snd_pcm_substream *substream)
2131 struct alc_spec *spec = codec->spec;
2132 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2138 static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2139 struct hda_codec *codec,
2140 struct snd_pcm_substream *substream)
2142 struct alc_spec *spec = codec->spec;
2143 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2146 static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2147 struct hda_codec *codec,
2148 unsigned int stream_tag,
2149 unsigned int format,
2150 struct snd_pcm_substream *substream)
2152 struct alc_spec *spec = codec->spec;
2153 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2154 stream_tag, format, substream);
2157 static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2158 struct hda_codec *codec,
2159 struct snd_pcm_substream *substream)
2161 struct alc_spec *spec = codec->spec;
2162 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2165 static int alc_dig_playback_pcm_close(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_close(codec, &spec->multiout);
2176 static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2177 struct hda_codec *codec,
2178 unsigned int stream_tag,
2179 unsigned int format,
2180 struct snd_pcm_substream *substream)
2182 struct alc_spec *spec = codec->spec;
2184 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
2185 stream_tag, 0, format);
2189 static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2190 struct hda_codec *codec,
2191 struct snd_pcm_substream *substream)
2193 struct alc_spec *spec = codec->spec;
2195 snd_hda_codec_cleanup_stream(codec,
2196 spec->adc_nids[substream->number + 1]);
2200 /* analog capture with dynamic dual-adc changes */
2201 static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2202 struct hda_codec *codec,
2203 unsigned int stream_tag,
2204 unsigned int format,
2205 struct snd_pcm_substream *substream)
2207 struct alc_spec *spec = codec->spec;
2208 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
2209 spec->cur_adc_stream_tag = stream_tag;
2210 spec->cur_adc_format = format;
2211 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2215 static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2216 struct hda_codec *codec,
2217 struct snd_pcm_substream *substream)
2219 struct alc_spec *spec = codec->spec;
2220 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2225 static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
2229 .nid = 0, /* fill later */
2231 .prepare = dyn_adc_capture_pcm_prepare,
2232 .cleanup = dyn_adc_capture_pcm_cleanup
2238 static const struct hda_pcm_stream alc_pcm_analog_playback = {
2242 /* NID is set in alc_build_pcms */
2244 .open = alc_playback_pcm_open,
2245 .prepare = alc_playback_pcm_prepare,
2246 .cleanup = alc_playback_pcm_cleanup
2250 static const struct hda_pcm_stream alc_pcm_analog_capture = {
2254 /* NID is set in alc_build_pcms */
2257 static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
2261 /* NID is set in alc_build_pcms */
2264 static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
2265 .substreams = 2, /* can be overridden */
2268 /* NID is set in alc_build_pcms */
2270 .prepare = alc_alt_capture_pcm_prepare,
2271 .cleanup = alc_alt_capture_pcm_cleanup
2275 static const struct hda_pcm_stream alc_pcm_digital_playback = {
2279 /* NID is set in alc_build_pcms */
2281 .open = alc_dig_playback_pcm_open,
2282 .close = alc_dig_playback_pcm_close,
2283 .prepare = alc_dig_playback_pcm_prepare,
2284 .cleanup = alc_dig_playback_pcm_cleanup
2288 static const struct hda_pcm_stream alc_pcm_digital_capture = {
2292 /* NID is set in alc_build_pcms */
2295 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
2296 static const struct hda_pcm_stream alc_pcm_null_stream = {
2302 static int alc_build_pcms(struct hda_codec *codec)
2304 struct alc_spec *spec = codec->spec;
2305 struct hda_pcm *info = spec->pcm_rec;
2306 const struct hda_pcm_stream *p;
2307 bool have_multi_adcs;
2310 codec->num_pcms = 1;
2311 codec->pcm_info = info;
2313 if (spec->no_analog)
2316 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2317 "%s Analog", codec->chip_name);
2318 info->name = spec->stream_name_analog;
2320 if (spec->multiout.dac_nids > 0) {
2321 p = spec->stream_analog_playback;
2323 p = &alc_pcm_analog_playback;
2324 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2325 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2327 if (spec->adc_nids) {
2328 p = spec->stream_analog_capture;
2330 if (spec->dyn_adc_switch)
2331 p = &dyn_adc_pcm_analog_capture;
2333 p = &alc_pcm_analog_capture;
2335 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2336 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2339 if (spec->channel_mode) {
2340 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2341 for (i = 0; i < spec->num_channel_mode; i++) {
2342 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2343 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2349 /* SPDIF for stream index #1 */
2350 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2351 snprintf(spec->stream_name_digital,
2352 sizeof(spec->stream_name_digital),
2353 "%s Digital", codec->chip_name);
2354 codec->num_pcms = 2;
2355 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
2356 info = spec->pcm_rec + 1;
2357 info->name = spec->stream_name_digital;
2358 if (spec->dig_out_type)
2359 info->pcm_type = spec->dig_out_type;
2361 info->pcm_type = HDA_PCM_TYPE_SPDIF;
2362 if (spec->multiout.dig_out_nid) {
2363 p = spec->stream_digital_playback;
2365 p = &alc_pcm_digital_playback;
2366 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2367 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2369 if (spec->dig_in_nid) {
2370 p = spec->stream_digital_capture;
2372 p = &alc_pcm_digital_capture;
2373 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2374 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2376 /* FIXME: do we need this for all Realtek codec models? */
2377 codec->spdif_status_reset = 1;
2380 if (spec->no_analog)
2383 /* If the use of more than one ADC is requested for the current
2384 * model, configure a second analog capture-only PCM.
2386 have_multi_adcs = (spec->num_adc_nids > 1) &&
2387 !spec->dyn_adc_switch && !spec->auto_mic &&
2388 (!spec->input_mux || spec->input_mux->num_items > 1);
2389 /* Additional Analaog capture for index #2 */
2390 if (spec->alt_dac_nid || have_multi_adcs) {
2391 codec->num_pcms = 3;
2392 info = spec->pcm_rec + 2;
2393 info->name = spec->stream_name_analog;
2394 if (spec->alt_dac_nid) {
2395 p = spec->stream_analog_alt_playback;
2397 p = &alc_pcm_analog_alt_playback;
2398 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2399 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2402 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2403 alc_pcm_null_stream;
2404 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2406 if (have_multi_adcs) {
2407 p = spec->stream_analog_alt_capture;
2409 p = &alc_pcm_analog_alt_capture;
2410 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2411 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2413 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2414 spec->num_adc_nids - 1;
2416 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2417 alc_pcm_null_stream;
2418 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
2425 static inline void alc_shutup(struct hda_codec *codec)
2427 struct alc_spec *spec = codec->spec;
2429 if (spec && spec->shutup)
2430 spec->shutup(codec);
2431 snd_hda_shutup_pins(codec);
2434 static void alc_free_kctls(struct hda_codec *codec)
2436 struct alc_spec *spec = codec->spec;
2438 if (spec->kctls.list) {
2439 struct snd_kcontrol_new *kctl = spec->kctls.list;
2441 for (i = 0; i < spec->kctls.used; i++)
2442 kfree(kctl[i].name);
2444 snd_array_free(&spec->kctls);
2447 static void alc_free_bind_ctls(struct hda_codec *codec)
2449 struct alc_spec *spec = codec->spec;
2450 if (spec->bind_ctls.list) {
2451 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2453 for (i = 0; i < spec->bind_ctls.used; i++)
2456 snd_array_free(&spec->bind_ctls);
2459 static void alc_free(struct hda_codec *codec)
2461 struct alc_spec *spec = codec->spec;
2467 snd_hda_input_jack_free(codec);
2468 alc_free_kctls(codec);
2469 alc_free_bind_ctls(codec);
2471 snd_hda_detach_beep_device(codec);
2474 #ifdef CONFIG_SND_HDA_POWER_SAVE
2475 static void alc_power_eapd(struct hda_codec *codec)
2477 alc_auto_setup_eapd(codec, false);
2480 static int alc_suspend(struct hda_codec *codec, pm_message_t state)
2482 struct alc_spec *spec = codec->spec;
2484 if (spec && spec->power_hook)
2485 spec->power_hook(codec);
2491 static int alc_resume(struct hda_codec *codec)
2493 msleep(150); /* to avoid pop noise */
2494 codec->patch_ops.init(codec);
2495 snd_hda_codec_resume_amp(codec);
2496 snd_hda_codec_resume_cache(codec);
2497 hda_call_check_power_status(codec, 0x01);
2504 static const struct hda_codec_ops alc_patch_ops = {
2505 .build_controls = alc_build_controls,
2506 .build_pcms = alc_build_pcms,
2509 .unsol_event = alc_unsol_event,
2511 .resume = alc_resume,
2513 #ifdef CONFIG_SND_HDA_POWER_SAVE
2514 .suspend = alc_suspend,
2515 .check_power_status = alc_check_power_status,
2517 .reboot_notify = alc_shutup,
2520 /* replace the codec chip_name with the given string */
2521 static int alc_codec_rename(struct hda_codec *codec, const char *name)
2523 kfree(codec->chip_name);
2524 codec->chip_name = kstrdup(name, GFP_KERNEL);
2525 if (!codec->chip_name) {
2533 * Rename codecs appropriately from COEF value
2535 struct alc_codec_rename_table {
2536 unsigned int vendor_id;
2537 unsigned short coef_mask;
2538 unsigned short coef_bits;
2542 static struct alc_codec_rename_table rename_tbl[] = {
2543 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2544 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2545 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2546 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2547 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2548 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2549 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
2550 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2551 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2552 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2553 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2554 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2555 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2556 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2557 { } /* terminator */
2560 static int alc_codec_rename_from_preset(struct hda_codec *codec)
2562 const struct alc_codec_rename_table *p;
2564 for (p = rename_tbl; p->vendor_id; p++) {
2565 if (p->vendor_id != codec->vendor_id)
2567 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
2568 return alc_codec_rename(codec, p->name);
2574 * Automatic parse of I/O pins from the BIOS configuration
2579 ALC_CTL_WIDGET_MUTE,
2584 static const struct snd_kcontrol_new alc_control_templates[] = {
2585 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2586 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2587 HDA_BIND_MUTE(NULL, 0, 0, 0),
2588 HDA_BIND_VOL(NULL, 0),
2589 HDA_BIND_SW(NULL, 0),
2592 /* add dynamic controls */
2593 static int add_control(struct alc_spec *spec, int type, const char *name,
2594 int cidx, unsigned long val)
2596 struct snd_kcontrol_new *knew;
2598 knew = alc_kcontrol_new(spec);
2601 *knew = alc_control_templates[type];
2602 knew->name = kstrdup(name, GFP_KERNEL);
2606 if (get_amp_nid_(val))
2607 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
2608 knew->private_value = val;
2612 static int add_control_with_pfx(struct alc_spec *spec, int type,
2613 const char *pfx, const char *dir,
2614 const char *sfx, int cidx, unsigned long val)
2617 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
2618 return add_control(spec, type, name, cidx, val);
2621 #define add_pb_vol_ctrl(spec, type, pfx, val) \
2622 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2623 #define add_pb_sw_ctrl(spec, type, pfx, val) \
2624 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2625 #define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2626 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2627 #define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2628 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
2630 static const char * const channel_name[4] = {
2631 "Front", "Surround", "CLFE", "Side"
2634 static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2635 bool can_be_master, int *index)
2637 struct auto_pin_cfg *cfg = &spec->autocfg;
2640 if (cfg->line_outs == 1 && !spec->multi_ios &&
2641 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
2644 switch (cfg->line_out_type) {
2645 case AUTO_PIN_SPEAKER_OUT:
2646 if (cfg->line_outs == 1)
2648 if (cfg->line_outs == 2)
2649 return ch ? "Bass Speaker" : "Speaker";
2651 case AUTO_PIN_HP_OUT:
2652 /* for multi-io case, only the primary out */
2653 if (ch && spec->multi_ios)
2658 if (cfg->line_outs == 1 && !spec->multi_ios)
2662 if (snd_BUG_ON(ch >= ARRAY_SIZE(channel_name)))
2665 return channel_name[ch];
2668 /* create input playback/capture controls for the given pin */
2669 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
2670 const char *ctlname, int ctlidx,
2671 int idx, hda_nid_t mix_nid)
2675 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
2676 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2679 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
2680 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2686 static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
2688 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2689 return (pincap & AC_PINCAP_IN) != 0;
2692 /* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
2693 static int alc_auto_fill_adc_caps(struct hda_codec *codec)
2695 struct alc_spec *spec = codec->spec;
2697 hda_nid_t *adc_nids = spec->private_adc_nids;
2698 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2699 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
2702 nid = codec->start_nid;
2703 for (i = 0; i < codec->num_nodes; i++, nid++) {
2705 const hda_nid_t *list;
2706 unsigned int caps = get_wcaps(codec, nid);
2707 int type = get_wcaps_type(caps);
2709 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2711 adc_nids[nums] = nid;
2712 cap_nids[nums] = nid;
2716 type = get_wcaps_type(get_wcaps(codec, src));
2717 if (type == AC_WID_PIN)
2719 if (type == AC_WID_AUD_SEL) {
2720 cap_nids[nums] = src;
2723 n = snd_hda_get_conn_list(codec, src, &list);
2725 cap_nids[nums] = src;
2731 if (++nums >= max_nums)
2734 spec->adc_nids = spec->private_adc_nids;
2735 spec->capsrc_nids = spec->private_capsrc_nids;
2736 spec->num_adc_nids = nums;
2740 /* create playback/capture controls for input pins */
2741 static int alc_auto_create_input_ctls(struct hda_codec *codec)
2743 struct alc_spec *spec = codec->spec;
2744 const struct auto_pin_cfg *cfg = &spec->autocfg;
2745 hda_nid_t mixer = spec->mixer_nid;
2746 struct hda_input_mux *imux = &spec->private_imux[0];
2748 int i, c, err, idx, type_idx = 0;
2749 const char *prev_label = NULL;
2751 num_adcs = alc_auto_fill_adc_caps(codec);
2755 for (i = 0; i < cfg->num_inputs; i++) {
2759 pin = cfg->inputs[i].pin;
2760 if (!alc_is_input_pin(codec, pin))
2763 label = hda_get_autocfg_input_label(codec, cfg, i);
2764 if (prev_label && !strcmp(label, prev_label))
2771 idx = get_connection_index(codec, mixer, pin);
2773 err = new_analog_input(spec, pin,
2781 for (c = 0; c < num_adcs; c++) {
2782 hda_nid_t cap = get_capsrc(spec, c);
2783 idx = get_connection_index(codec, cap, pin);
2785 spec->imux_pins[imux->num_items] = pin;
2786 snd_hda_add_imux_item(imux, label, idx, NULL);
2792 spec->num_mux_defs = 1;
2793 spec->input_mux = imux;
2798 static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
2799 unsigned int pin_type)
2801 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2804 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2805 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2809 static int get_pin_type(int line_out_type)
2811 if (line_out_type == AUTO_PIN_HP_OUT)
2817 static void alc_auto_init_analog_input(struct hda_codec *codec)
2819 struct alc_spec *spec = codec->spec;
2820 struct auto_pin_cfg *cfg = &spec->autocfg;
2823 for (i = 0; i < cfg->num_inputs; i++) {
2824 hda_nid_t nid = cfg->inputs[i].pin;
2825 if (alc_is_input_pin(codec, nid)) {
2826 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
2827 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
2828 snd_hda_codec_write(codec, nid, 0,
2829 AC_VERB_SET_AMP_GAIN_MUTE,
2834 /* mute all loopback inputs */
2835 if (spec->mixer_nid) {
2836 int nums = snd_hda_get_conn_list(codec, spec->mixer_nid, NULL);
2837 for (i = 0; i < nums; i++)
2838 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2839 AC_VERB_SET_AMP_GAIN_MUTE,
2844 /* convert from MIX nid to DAC */
2845 static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid)
2850 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT)
2852 num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list));
2853 for (i = 0; i < num; i++) {
2854 if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT)
2860 /* go down to the selector widget before the mixer */
2861 static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin)
2864 int num = snd_hda_get_connections(codec, pin, srcs,
2867 get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL)
2872 /* get MIX nid connected to the given pin targeted to DAC */
2873 static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
2879 pin = alc_go_down_to_selector(codec, pin);
2880 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2881 for (i = 0; i < num; i++) {
2882 if (alc_auto_mix_to_dac(codec, mix[i]) == dac)
2888 /* select the connection from pin to DAC if needed */
2889 static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin,
2895 pin = alc_go_down_to_selector(codec, pin);
2896 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2899 for (i = 0; i < num; i++) {
2900 if (alc_auto_mix_to_dac(codec, mix[i]) == dac) {
2901 snd_hda_codec_update_cache(codec, pin, 0,
2902 AC_VERB_SET_CONNECT_SEL, i);
2909 /* look for an empty DAC slot */
2910 static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
2912 struct alc_spec *spec = codec->spec;
2916 pin = alc_go_down_to_selector(codec, pin);
2917 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
2918 for (i = 0; i < num; i++) {
2919 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
2922 if (found_in_nid_list(nid, spec->multiout.dac_nids,
2923 ARRAY_SIZE(spec->private_dac_nids)))
2925 if (found_in_nid_list(nid, spec->multiout.hp_out_nid,
2926 ARRAY_SIZE(spec->multiout.hp_out_nid)))
2928 if (found_in_nid_list(nid, spec->multiout.extra_out_nid,
2929 ARRAY_SIZE(spec->multiout.extra_out_nid)))
2936 static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
2938 hda_nid_t sel = alc_go_down_to_selector(codec, pin);
2939 if (snd_hda_get_conn_list(codec, sel, NULL) == 1)
2940 return alc_auto_look_for_dac(codec, pin);
2944 /* return 0 if no possible DAC is found, 1 if one or more found */
2945 static int alc_auto_fill_extra_dacs(struct hda_codec *codec, int num_outs,
2946 const hda_nid_t *pins, hda_nid_t *dacs)
2950 if (num_outs && !dacs[0]) {
2951 dacs[0] = alc_auto_look_for_dac(codec, pins[0]);
2956 for (i = 1; i < num_outs; i++)
2957 dacs[i] = get_dac_if_single(codec, pins[i]);
2958 for (i = 1; i < num_outs; i++) {
2960 dacs[i] = alc_auto_look_for_dac(codec, pins[i]);
2965 static int alc_auto_fill_multi_ios(struct hda_codec *codec,
2966 unsigned int location);
2968 /* fill in the dac_nids table from the parsed pin configuration */
2969 static int alc_auto_fill_dac_nids(struct hda_codec *codec)
2971 struct alc_spec *spec = codec->spec;
2972 struct auto_pin_cfg *cfg = &spec->autocfg;
2973 bool redone = false;
2977 /* set num_dacs once to full for alc_auto_look_for_dac() */
2978 spec->multiout.num_dacs = cfg->line_outs;
2979 spec->multiout.hp_out_nid[0] = 0;
2980 spec->multiout.extra_out_nid[0] = 0;
2981 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
2982 spec->multiout.dac_nids = spec->private_dac_nids;
2983 spec->multi_ios = 0;
2985 /* fill hard-wired DACs first */
2987 for (i = 0; i < cfg->line_outs; i++)
2988 spec->private_dac_nids[i] =
2989 get_dac_if_single(codec, cfg->line_out_pins[i]);
2991 spec->multiout.hp_out_nid[0] =
2992 get_dac_if_single(codec, cfg->hp_pins[0]);
2993 if (cfg->speaker_outs)
2994 spec->multiout.extra_out_nid[0] =
2995 get_dac_if_single(codec, cfg->speaker_pins[0]);
2998 for (i = 0; i < cfg->line_outs; i++) {
2999 hda_nid_t pin = cfg->line_out_pins[i];
3000 if (spec->private_dac_nids[i])
3002 spec->private_dac_nids[i] = alc_auto_look_for_dac(codec, pin);
3003 if (!spec->private_dac_nids[i] && !redone) {
3004 /* if we can't find primary DACs, re-probe without
3005 * checking the hard-wired DACs
3012 /* re-count num_dacs and squash invalid entries */
3013 spec->multiout.num_dacs = 0;
3014 for (i = 0; i < cfg->line_outs; i++) {
3015 if (spec->private_dac_nids[i])
3016 spec->multiout.num_dacs++;
3018 memmove(spec->private_dac_nids + i,
3019 spec->private_dac_nids + i + 1,
3020 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
3021 spec->private_dac_nids[cfg->line_outs - 1] = 0;
3025 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3026 /* try to fill multi-io first */
3027 unsigned int location, defcfg;
3030 defcfg = snd_hda_codec_get_pincfg(codec, cfg->line_out_pins[0]);
3031 location = get_defcfg_location(defcfg);
3033 num_pins = alc_auto_fill_multi_ios(codec, location);
3035 spec->multi_ios = num_pins;
3036 spec->ext_channel_count = 2;
3037 spec->multiout.num_dacs = num_pins + 1;
3041 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
3042 alc_auto_fill_extra_dacs(codec, cfg->hp_outs, cfg->hp_pins,
3043 spec->multiout.hp_out_nid);
3044 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3045 int err = alc_auto_fill_extra_dacs(codec, cfg->speaker_outs,
3047 spec->multiout.extra_out_nid);
3048 /* if no speaker volume is assigned, try again as the primary
3051 if (!err && cfg->speaker_outs > 0 &&
3052 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3053 cfg->hp_outs = cfg->line_outs;
3054 memcpy(cfg->hp_pins, cfg->line_out_pins,
3055 sizeof(cfg->hp_pins));
3056 cfg->line_outs = cfg->speaker_outs;
3057 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3058 sizeof(cfg->speaker_pins));
3059 cfg->speaker_outs = 0;
3060 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3061 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
3070 static inline unsigned int get_ctl_pos(unsigned int data)
3072 hda_nid_t nid = get_amp_nid_(data);
3074 if (snd_BUG_ON(nid >= MAX_VOL_NIDS))
3076 dir = get_amp_direction_(data);
3077 return (nid << 1) | dir;
3080 #define is_ctl_used(bits, data) \
3081 test_bit(get_ctl_pos(data), bits)
3082 #define mark_ctl_usage(bits, data) \
3083 set_bit(get_ctl_pos(data), bits)
3085 static int alc_auto_add_vol_ctl(struct hda_codec *codec,
3086 const char *pfx, int cidx,
3087 hda_nid_t nid, unsigned int chs)
3089 struct alc_spec *spec = codec->spec;
3093 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3094 if (is_ctl_used(spec->vol_ctls, val) && chs != 2) /* exclude LFE */
3096 mark_ctl_usage(spec->vol_ctls, val);
3097 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
3101 #define alc_auto_add_stereo_vol(codec, pfx, cidx, nid) \
3102 alc_auto_add_vol_ctl(codec, pfx, cidx, nid, 3)
3104 /* create a mute-switch for the given mixer widget;
3105 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3107 static int alc_auto_add_sw_ctl(struct hda_codec *codec,
3108 const char *pfx, int cidx,
3109 hda_nid_t nid, unsigned int chs)
3111 struct alc_spec *spec = codec->spec;
3117 wid_type = get_wcaps_type(get_wcaps(codec, nid));
3118 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) {
3119 type = ALC_CTL_WIDGET_MUTE;
3120 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3121 } else if (snd_hda_get_conn_list(codec, nid, NULL) == 1) {
3122 type = ALC_CTL_WIDGET_MUTE;
3123 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
3125 type = ALC_CTL_BIND_MUTE;
3126 val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
3128 if (is_ctl_used(spec->sw_ctls, val) && chs != 2) /* exclude LFE */
3130 mark_ctl_usage(spec->sw_ctls, val);
3131 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
3134 #define alc_auto_add_stereo_sw(codec, pfx, cidx, nid) \
3135 alc_auto_add_sw_ctl(codec, pfx, cidx, nid, 3)
3137 static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3138 hda_nid_t pin, hda_nid_t dac)
3140 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3141 if (nid_has_mute(codec, pin, HDA_OUTPUT))
3143 else if (mix && nid_has_mute(codec, mix, HDA_INPUT))
3145 else if (nid_has_mute(codec, dac, HDA_OUTPUT))
3150 static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3151 hda_nid_t pin, hda_nid_t dac)
3153 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3154 if (nid_has_volume(codec, dac, HDA_OUTPUT))
3156 else if (nid_has_volume(codec, mix, HDA_OUTPUT))
3158 else if (nid_has_volume(codec, pin, HDA_OUTPUT))
3163 /* add playback controls from the parsed DAC table */
3164 static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
3165 const struct auto_pin_cfg *cfg)
3167 struct alc_spec *spec = codec->spec;
3168 int i, err, noutputs;
3170 noutputs = cfg->line_outs;
3171 if (spec->multi_ios > 0)
3172 noutputs += spec->multi_ios;
3174 for (i = 0; i < noutputs; i++) {
3180 dac = spec->multiout.dac_nids[i];
3183 if (i >= cfg->line_outs)
3184 pin = spec->multi_io[i - 1].pin;
3186 pin = cfg->line_out_pins[i];
3188 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3189 vol = alc_look_for_out_vol_nid(codec, pin, dac);
3190 name = alc_get_line_out_pfx(spec, i, true, &index);
3191 if (!name || !strcmp(name, "CLFE")) {
3193 err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1);
3196 err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2);
3199 err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1);
3202 err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2);
3206 err = alc_auto_add_stereo_vol(codec, name, index, vol);
3209 err = alc_auto_add_stereo_sw(codec, name, index, sw);
3217 static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
3218 hda_nid_t dac, const char *pfx,
3221 struct alc_spec *spec = codec->spec;
3227 /* the corresponding DAC is already occupied */
3228 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
3229 return 0; /* no way */
3230 /* create a switch only */
3231 val = HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT);
3232 if (is_ctl_used(spec->sw_ctls, val))
3233 return 0; /* already created */
3234 mark_ctl_usage(spec->sw_ctls, val);
3235 return __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, cidx, val);
3238 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3239 vol = alc_look_for_out_vol_nid(codec, pin, dac);
3240 err = alc_auto_add_stereo_vol(codec, pfx, cidx, vol);
3243 err = alc_auto_add_stereo_sw(codec, pfx, cidx, sw);
3249 static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3251 struct hda_ctl_ops *ops)
3253 struct alc_spec *spec = codec->spec;
3254 struct hda_bind_ctls **ctlp, *ctl;
3255 snd_array_init(&spec->bind_ctls, sizeof(ctl), 8);
3256 ctlp = snd_array_new(&spec->bind_ctls);
3259 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3266 /* add playback controls for speaker and HP outputs */
3267 static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3268 const hda_nid_t *pins,
3269 const hda_nid_t *dacs,
3272 struct alc_spec *spec = codec->spec;
3273 struct hda_bind_ctls *ctl;
3277 if (!num_pins || !pins[0])
3280 if (num_pins == 1) {
3281 hda_nid_t dac = *dacs;
3283 dac = spec->multiout.dac_nids[0];
3284 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
3287 if (dacs[num_pins - 1]) {
3288 /* OK, we have a multi-output system with individual volumes */
3289 for (i = 0; i < num_pins; i++) {
3290 if (num_pins >= 3) {
3291 snprintf(name, sizeof(name), "%s %s",
3292 pfx, channel_name[i]);
3293 err = alc_auto_create_extra_out(codec, pins[i], dacs[i],
3296 err = alc_auto_create_extra_out(codec, pins[i], dacs[i],
3305 /* Let's create a bind-controls */
3306 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_sw);
3310 for (i = 0; i < num_pins; i++) {
3311 if (get_wcaps(codec, pins[i]) & AC_WCAP_OUT_AMP)
3313 HDA_COMPOSE_AMP_VAL(pins[i], 3, 0, HDA_OUTPUT);
3316 snprintf(name, sizeof(name), "%s Playback Switch", pfx);
3317 err = add_control(spec, ALC_CTL_BIND_SW, name, 0, (long)ctl);
3322 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3326 for (i = 0; i < num_pins; i++) {
3328 if (!pins[i] || !dacs[i])
3330 vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]);
3333 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3336 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3337 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3344 static int alc_auto_create_hp_out(struct hda_codec *codec)
3346 struct alc_spec *spec = codec->spec;
3347 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3348 spec->autocfg.hp_pins,
3349 spec->multiout.hp_out_nid,
3353 static int alc_auto_create_speaker_out(struct hda_codec *codec)
3355 struct alc_spec *spec = codec->spec;
3356 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3357 spec->autocfg.speaker_pins,
3358 spec->multiout.extra_out_nid,
3362 static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
3363 hda_nid_t pin, int pin_type,
3367 hda_nid_t nid, mix = 0;
3368 hda_nid_t srcs[HDA_MAX_CONNECTIONS];
3370 alc_set_pin_output(codec, pin, pin_type);
3371 nid = alc_go_down_to_selector(codec, pin);
3372 num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
3373 for (i = 0; i < num; i++) {
3374 if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
3382 /* need the manual connection? */
3384 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
3385 /* unmute mixer widget inputs */
3386 if (nid_has_mute(codec, mix, HDA_INPUT)) {
3387 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3389 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3392 /* initialize volume */
3393 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3395 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3398 /* unmute DAC if it's not assigned to a mixer */
3399 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3400 if (nid == mix && nid_has_mute(codec, dac, HDA_OUTPUT))
3401 snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3405 static void alc_auto_init_multi_out(struct hda_codec *codec)
3407 struct alc_spec *spec = codec->spec;
3408 int pin_type = get_pin_type(spec->autocfg.line_out_type);
3411 for (i = 0; i <= HDA_SIDE; i++) {
3412 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3414 alc_auto_set_output_and_unmute(codec, nid, pin_type,
3415 spec->multiout.dac_nids[i]);
3419 static void alc_auto_init_extra_out(struct hda_codec *codec)
3421 struct alc_spec *spec = codec->spec;
3425 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3426 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3428 pin = spec->autocfg.hp_pins[i];
3431 dac = spec->multiout.hp_out_nid[i];
3433 if (i > 0 && spec->multiout.hp_out_nid[0])
3434 dac = spec->multiout.hp_out_nid[0];
3436 dac = spec->multiout.dac_nids[0];
3438 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
3440 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3441 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3443 pin = spec->autocfg.speaker_pins[i];
3446 dac = spec->multiout.extra_out_nid[i];
3448 if (i > 0 && spec->multiout.extra_out_nid[0])
3449 dac = spec->multiout.extra_out_nid[0];
3451 dac = spec->multiout.dac_nids[0];
3453 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
3460 static int alc_auto_fill_multi_ios(struct hda_codec *codec,
3461 unsigned int location)
3463 struct alc_spec *spec = codec->spec;
3464 struct auto_pin_cfg *cfg = &spec->autocfg;
3465 hda_nid_t prime_dac = spec->private_dac_nids[0];
3466 int type, i, num_pins = 0;
3468 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3469 for (i = 0; i < cfg->num_inputs; i++) {
3470 hda_nid_t nid = cfg->inputs[i].pin;
3472 unsigned int defcfg, caps;
3473 if (cfg->inputs[i].type != type)
3475 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3476 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3478 if (location && get_defcfg_location(defcfg) != location)
3480 caps = snd_hda_query_pin_caps(codec, nid);
3481 if (!(caps & AC_PINCAP_OUT))
3483 dac = alc_auto_look_for_dac(codec, nid);
3486 spec->multi_io[num_pins].pin = nid;
3487 spec->multi_io[num_pins].dac = dac;
3489 spec->private_dac_nids[spec->multiout.num_dacs++] = dac;
3492 spec->multiout.num_dacs = 1;
3494 /* clear up again */
3495 memset(spec->private_dac_nids, 0,
3496 sizeof(spec->private_dac_nids));
3497 spec->private_dac_nids[0] = prime_dac;
3503 static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
3504 struct snd_ctl_elem_info *uinfo)
3506 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3507 struct alc_spec *spec = codec->spec;
3509 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3511 uinfo->value.enumerated.items = spec->multi_ios + 1;
3512 if (uinfo->value.enumerated.item > spec->multi_ios)
3513 uinfo->value.enumerated.item = spec->multi_ios;
3514 sprintf(uinfo->value.enumerated.name, "%dch",
3515 (uinfo->value.enumerated.item + 1) * 2);
3519 static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
3520 struct snd_ctl_elem_value *ucontrol)
3522 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3523 struct alc_spec *spec = codec->spec;
3524 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
3528 static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
3530 struct alc_spec *spec = codec->spec;
3531 hda_nid_t nid = spec->multi_io[idx].pin;
3533 if (!spec->multi_io[idx].ctl_in)
3534 spec->multi_io[idx].ctl_in =
3535 snd_hda_codec_read(codec, nid, 0,
3536 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3538 snd_hda_codec_update_cache(codec, nid, 0,
3539 AC_VERB_SET_PIN_WIDGET_CONTROL,
3541 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3542 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3544 alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
3546 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3547 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3548 HDA_AMP_MUTE, HDA_AMP_MUTE);
3549 snd_hda_codec_update_cache(codec, nid, 0,
3550 AC_VERB_SET_PIN_WIDGET_CONTROL,
3551 spec->multi_io[idx].ctl_in);
3556 static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
3557 struct snd_ctl_elem_value *ucontrol)
3559 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3560 struct alc_spec *spec = codec->spec;
3563 ch = ucontrol->value.enumerated.item[0];
3564 if (ch < 0 || ch > spec->multi_ios)
3566 if (ch == (spec->ext_channel_count - 1) / 2)
3568 spec->ext_channel_count = (ch + 1) * 2;
3569 for (i = 0; i < spec->multi_ios; i++)
3570 alc_set_multi_io(codec, i, i < ch);
3571 spec->multiout.max_channels = spec->ext_channel_count;
3572 if (spec->need_dac_fix && !spec->const_channel_count)
3573 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
3577 static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
3578 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3579 .name = "Channel Mode",
3580 .info = alc_auto_ch_mode_info,
3581 .get = alc_auto_ch_mode_get,
3582 .put = alc_auto_ch_mode_put,
3585 static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
3587 struct alc_spec *spec = codec->spec;
3589 if (spec->multi_ios > 0) {
3590 struct snd_kcontrol_new *knew;
3592 knew = alc_kcontrol_new(spec);
3595 *knew = alc_auto_channel_mode_enum;
3596 knew->name = kstrdup("Channel Mode", GFP_KERNEL);
3603 /* filter out invalid adc_nids (and capsrc_nids) that don't give all
3606 static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
3608 struct alc_spec *spec = codec->spec;
3609 const struct hda_input_mux *imux;
3610 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3611 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3614 imux = spec->input_mux;
3617 if (spec->dyn_adc_switch)
3621 for (n = 0; n < spec->num_adc_nids; n++) {
3622 hda_nid_t cap = spec->private_capsrc_nids[n];
3623 int num_conns = snd_hda_get_conn_list(codec, cap, NULL);
3624 for (i = 0; i < imux->num_items; i++) {
3625 hda_nid_t pin = spec->imux_pins[i];
3627 if (get_connection_index(codec, cap, pin) < 0)
3629 } else if (num_conns <= imux->items[i].index)
3632 if (i >= imux->num_items) {
3633 adc_nids[nums] = spec->private_adc_nids[n];
3634 capsrc_nids[nums++] = cap;
3638 /* check whether ADC-switch is possible */
3639 if (!alc_check_dyn_adc_switch(codec)) {
3640 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
3641 " using fallback 0x%x\n",
3642 codec->chip_name, spec->private_adc_nids[0]);
3643 spec->num_adc_nids = 1;
3647 } else if (nums != spec->num_adc_nids) {
3648 memcpy(spec->private_adc_nids, adc_nids,
3649 nums * sizeof(hda_nid_t));
3650 memcpy(spec->private_capsrc_nids, capsrc_nids,
3651 nums * sizeof(hda_nid_t));
3652 spec->num_adc_nids = nums;
3656 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
3657 else if (spec->input_mux->num_items == 1)
3658 spec->num_adc_nids = 1; /* reduce to a single ADC */
3662 * initialize ADC paths
3664 static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
3666 struct alc_spec *spec = codec->spec;
3669 nid = spec->adc_nids[adc_idx];
3671 if (nid_has_mute(codec, nid, HDA_INPUT)) {
3672 snd_hda_codec_write(codec, nid, 0,
3673 AC_VERB_SET_AMP_GAIN_MUTE,
3677 if (!spec->capsrc_nids)
3679 nid = spec->capsrc_nids[adc_idx];
3680 if (nid_has_mute(codec, nid, HDA_OUTPUT))
3681 snd_hda_codec_write(codec, nid, 0,
3682 AC_VERB_SET_AMP_GAIN_MUTE,
3686 static void alc_auto_init_input_src(struct hda_codec *codec)
3688 struct alc_spec *spec = codec->spec;
3691 for (c = 0; c < spec->num_adc_nids; c++)
3692 alc_auto_init_adc(codec, c);
3693 if (spec->dyn_adc_switch)
3696 nums = spec->num_adc_nids;
3697 for (c = 0; c < nums; c++)
3698 alc_mux_select(codec, 0, spec->cur_mux[c], true);
3701 /* add mic boosts if needed */
3702 static int alc_auto_add_mic_boost(struct hda_codec *codec)
3704 struct alc_spec *spec = codec->spec;
3705 struct auto_pin_cfg *cfg = &spec->autocfg;
3709 const char *prev_label = NULL;
3711 for (i = 0; i < cfg->num_inputs; i++) {
3712 if (cfg->inputs[i].type > AUTO_PIN_MIC)
3714 nid = cfg->inputs[i].pin;
3715 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
3717 char boost_label[32];
3719 label = hda_get_autocfg_input_label(codec, cfg, i);
3720 if (prev_label && !strcmp(label, prev_label))
3726 snprintf(boost_label, sizeof(boost_label),
3727 "%s Boost Volume", label);
3728 err = add_control(spec, ALC_CTL_WIDGET_VOL,
3729 boost_label, type_idx,
3730 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
3738 /* select or unmute the given capsrc route */
3739 static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
3742 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
3743 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
3745 } else if (snd_hda_get_conn_list(codec, cap, NULL) > 1) {
3746 snd_hda_codec_write_cache(codec, cap, 0,
3747 AC_VERB_SET_CONNECT_SEL, idx);
3751 /* set the default connection to that pin */
3752 static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
3754 struct alc_spec *spec = codec->spec;
3759 for (i = 0; i < spec->num_adc_nids; i++) {
3760 hda_nid_t cap = get_capsrc(spec, i);
3763 idx = get_connection_index(codec, cap, pin);
3766 select_or_unmute_capsrc(codec, cap, idx);
3767 return i; /* return the found index */
3769 return -1; /* not found */
3772 /* initialize some special cases for input sources */
3773 static void alc_init_special_input_src(struct hda_codec *codec)
3775 struct alc_spec *spec = codec->spec;
3778 for (i = 0; i < spec->autocfg.num_inputs; i++)
3779 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
3782 /* assign appropriate capture mixers */
3783 static void set_capture_mixer(struct hda_codec *codec)
3785 struct alc_spec *spec = codec->spec;
3786 static const struct snd_kcontrol_new *caps[2][3] = {
3787 { alc_capture_mixer_nosrc1,
3788 alc_capture_mixer_nosrc2,
3789 alc_capture_mixer_nosrc3 },
3790 { alc_capture_mixer1,
3792 alc_capture_mixer3 },
3795 /* check whether either of ADC or MUX has a volume control */
3796 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
3797 if (!spec->capsrc_nids)
3798 return; /* no volume */
3799 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
3800 return; /* no volume in capsrc, too */
3801 spec->vol_in_capsrc = 1;
3804 if (spec->num_adc_nids > 0) {
3808 if (spec->input_mux && spec->input_mux->num_items > 1)
3810 if (spec->auto_mic) {
3813 } else if (spec->dyn_adc_switch)
3816 if (spec->num_adc_nids > 3)
3817 spec->num_adc_nids = 3;
3818 else if (!spec->num_adc_nids)
3820 num_adcs = spec->num_adc_nids;
3822 spec->cap_mixer = caps[mux][num_adcs - 1];
3827 * standard auto-parser initializations
3829 static void alc_auto_init_std(struct hda_codec *codec)
3831 struct alc_spec *spec = codec->spec;
3832 alc_auto_init_multi_out(codec);
3833 alc_auto_init_extra_out(codec);
3834 alc_auto_init_analog_input(codec);
3835 alc_auto_init_input_src(codec);
3836 alc_auto_init_digital(codec);
3837 if (spec->unsol_event)
3838 alc_inithook(codec);
3842 * Digital-beep handlers
3844 #ifdef CONFIG_SND_HDA_INPUT_BEEP
3845 #define set_beep_amp(spec, nid, idx, dir) \
3846 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
3848 static const struct snd_pci_quirk beep_white_list[] = {
3849 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
3850 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
3851 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
3852 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
3853 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
3857 static inline int has_cdefine_beep(struct hda_codec *codec)
3859 struct alc_spec *spec = codec->spec;
3860 const struct snd_pci_quirk *q;
3861 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
3864 return spec->cdefine.enable_pcbeep;
3867 #define set_beep_amp(spec, nid, idx, dir) /* NOP */
3868 #define has_cdefine_beep(codec) 0
3871 /* parse the BIOS configuration and set up the alc_spec */
3872 /* return 1 if successful, 0 if the proper config is not found,
3873 * or a negative error code
3875 static int alc_parse_auto_config(struct hda_codec *codec,
3876 const hda_nid_t *ignore_nids,
3877 const hda_nid_t *ssid_nids)
3879 struct alc_spec *spec = codec->spec;
3880 struct auto_pin_cfg *cfg = &spec->autocfg;
3883 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
3887 if (!cfg->line_outs) {
3888 if (cfg->dig_outs || cfg->dig_in_pin) {
3889 spec->multiout.max_channels = 2;
3890 spec->no_analog = 1;
3893 return 0; /* can't find valid BIOS pin config */
3896 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
3897 cfg->line_outs <= cfg->hp_outs) {
3898 /* use HP as primary out */
3899 cfg->speaker_outs = cfg->line_outs;
3900 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3901 sizeof(cfg->speaker_pins));
3902 cfg->line_outs = cfg->hp_outs;
3903 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
3905 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3906 cfg->line_out_type = AUTO_PIN_HP_OUT;
3909 err = alc_auto_fill_dac_nids(codec);
3912 err = alc_auto_add_multi_channel_mode(codec);
3915 err = alc_auto_create_multi_out_ctls(codec, cfg);
3918 err = alc_auto_create_hp_out(codec);
3921 err = alc_auto_create_speaker_out(codec);
3924 err = alc_auto_create_input_ctls(codec);
3928 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3931 alc_auto_parse_digital(codec);
3933 if (!spec->no_analog)
3934 alc_remove_invalid_adc_nids(codec);
3937 alc_ssid_check(codec, ssid_nids);
3939 if (!spec->no_analog) {
3940 alc_auto_check_switches(codec);
3941 err = alc_auto_add_mic_boost(codec);
3946 if (spec->kctls.list)
3947 add_mixer(spec, spec->kctls.list);
3952 static int alc880_parse_auto_config(struct hda_codec *codec)
3954 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
3955 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
3956 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
3959 #ifdef CONFIG_SND_HDA_POWER_SAVE
3960 static const struct hda_amp_list alc880_loopbacks[] = {
3961 { 0x0b, HDA_INPUT, 0 },
3962 { 0x0b, HDA_INPUT, 1 },
3963 { 0x0b, HDA_INPUT, 2 },
3964 { 0x0b, HDA_INPUT, 3 },
3965 { 0x0b, HDA_INPUT, 4 },
3973 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3974 #define alc_board_config \
3975 snd_hda_check_board_config
3976 #define alc_board_codec_sid_config \
3977 snd_hda_check_board_codec_sid_config
3978 #include "alc_quirks.c"
3980 #define alc_board_config(codec, nums, models, tbl) -1
3981 #define alc_board_codec_sid_config(codec, nums, models, tbl) -1
3982 #define setup_preset(codec, x) /* NOP */
3986 * OK, here we have finally the patch for ALC880
3988 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3989 #include "alc880_quirks.c"
3992 static int patch_alc880(struct hda_codec *codec)
3994 struct alc_spec *spec;
3998 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4004 spec->mixer_nid = 0x0b;
4005 spec->need_dac_fix = 1;
4007 board_config = alc_board_config(codec, ALC880_MODEL_LAST,
4008 alc880_models, alc880_cfg_tbl);
4009 if (board_config < 0) {
4010 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4012 board_config = ALC_MODEL_AUTO;
4015 if (board_config == ALC_MODEL_AUTO) {
4016 /* automatic parse from the BIOS config */
4017 err = alc880_parse_auto_config(codec);
4020 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4023 "hda_codec: Cannot set up configuration "
4024 "from BIOS. Using 3-stack mode...\n");
4025 board_config = ALC880_3ST;
4030 if (board_config != ALC_MODEL_AUTO)
4031 setup_preset(codec, &alc880_presets[board_config]);
4033 if (!spec->no_analog && !spec->adc_nids) {
4034 alc_auto_fill_adc_caps(codec);
4035 alc_rebuild_imux_for_auto_mic(codec);
4036 alc_remove_invalid_adc_nids(codec);
4039 if (!spec->no_analog && !spec->cap_mixer)
4040 set_capture_mixer(codec);
4042 if (!spec->no_analog) {
4043 err = snd_hda_attach_beep_device(codec, 0x1);
4046 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4049 spec->vmaster_nid = 0x0c;
4051 codec->patch_ops = alc_patch_ops;
4052 if (board_config == ALC_MODEL_AUTO)
4053 spec->init_hook = alc_auto_init_std;
4054 #ifdef CONFIG_SND_HDA_POWER_SAVE
4055 if (!spec->loopback.amplist)
4056 spec->loopback.amplist = alc880_loopbacks;
4070 static int alc260_parse_auto_config(struct hda_codec *codec)
4072 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
4073 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
4074 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
4077 #ifdef CONFIG_SND_HDA_POWER_SAVE
4078 static const struct hda_amp_list alc260_loopbacks[] = {
4079 { 0x07, HDA_INPUT, 0 },
4080 { 0x07, HDA_INPUT, 1 },
4081 { 0x07, HDA_INPUT, 2 },
4082 { 0x07, HDA_INPUT, 3 },
4083 { 0x07, HDA_INPUT, 4 },
4095 static const struct alc_fixup alc260_fixups[] = {
4096 [PINFIX_HP_DC5750] = {
4097 .type = ALC_FIXUP_PINS,
4098 .v.pins = (const struct alc_pincfg[]) {
4099 { 0x11, 0x90130110 }, /* speaker */
4105 static const struct snd_pci_quirk alc260_fixup_tbl[] = {
4106 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", PINFIX_HP_DC5750),
4112 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4113 #include "alc260_quirks.c"
4116 static int patch_alc260(struct hda_codec *codec)
4118 struct alc_spec *spec;
4119 int err, board_config;
4121 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4127 spec->mixer_nid = 0x07;
4129 board_config = alc_board_config(codec, ALC260_MODEL_LAST,
4130 alc260_models, alc260_cfg_tbl);
4131 if (board_config < 0) {
4132 snd_printd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4134 board_config = ALC_MODEL_AUTO;
4137 if (board_config == ALC_MODEL_AUTO) {
4138 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
4139 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4142 if (board_config == ALC_MODEL_AUTO) {
4143 /* automatic parse from the BIOS config */
4144 err = alc260_parse_auto_config(codec);
4147 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4150 "hda_codec: Cannot set up configuration "
4151 "from BIOS. Using base mode...\n");
4152 board_config = ALC260_BASIC;
4157 if (board_config != ALC_MODEL_AUTO)
4158 setup_preset(codec, &alc260_presets[board_config]);
4160 if (!spec->no_analog && !spec->adc_nids) {
4161 alc_auto_fill_adc_caps(codec);
4162 alc_rebuild_imux_for_auto_mic(codec);
4163 alc_remove_invalid_adc_nids(codec);
4166 if (!spec->no_analog && !spec->cap_mixer)
4167 set_capture_mixer(codec);
4169 if (!spec->no_analog) {
4170 err = snd_hda_attach_beep_device(codec, 0x1);
4173 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
4176 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4178 spec->vmaster_nid = 0x08;
4180 codec->patch_ops = alc_patch_ops;
4181 if (board_config == ALC_MODEL_AUTO)
4182 spec->init_hook = alc_auto_init_std;
4183 spec->shutup = alc_eapd_shutup;
4184 #ifdef CONFIG_SND_HDA_POWER_SAVE
4185 if (!spec->loopback.amplist)
4186 spec->loopback.amplist = alc260_loopbacks;
4198 * ALC882/883/885/888/889 support
4200 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
4201 * configuration. Each pin widget can choose any input DACs and a mixer.
4202 * Each ADC is connected from a mixer of all inputs. This makes possible
4203 * 6-channel independent captures.
4205 * In addition, an independent DAC for the multi-playback (not used in this
4208 #ifdef CONFIG_SND_HDA_POWER_SAVE
4209 #define alc882_loopbacks alc880_loopbacks
4216 PINFIX_ABIT_AW9D_MAX,
4219 PINFIX_ACER_ASPIRE_7736,
4221 ALC889_FIXUP_DAC_ROUTE,
4224 /* Fix the connection of some pins for ALC889:
4225 * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
4226 * work correctly (bko#42740)
4228 static void alc889_fixup_dac_route(struct hda_codec *codec,
4229 const struct alc_fixup *fix, int action)
4231 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
4232 /* fake the connections during parsing the tree */
4233 hda_nid_t conn1[2] = { 0x0c, 0x0d };
4234 hda_nid_t conn2[2] = { 0x0e, 0x0f };
4235 snd_hda_override_conn_list(codec, 0x14, 2, conn1);
4236 snd_hda_override_conn_list(codec, 0x15, 2, conn1);
4237 snd_hda_override_conn_list(codec, 0x18, 2, conn2);
4238 snd_hda_override_conn_list(codec, 0x1a, 2, conn2);
4239 } else if (action == ALC_FIXUP_ACT_PROBE) {
4240 /* restore the connections */
4241 hda_nid_t conn[5] = { 0x0c, 0x0d, 0x0e, 0x0f, 0x26 };
4242 snd_hda_override_conn_list(codec, 0x14, 5, conn);
4243 snd_hda_override_conn_list(codec, 0x15, 5, conn);
4244 snd_hda_override_conn_list(codec, 0x18, 5, conn);
4245 snd_hda_override_conn_list(codec, 0x1a, 5, conn);
4249 static const struct alc_fixup alc882_fixups[] = {
4250 [PINFIX_ABIT_AW9D_MAX] = {
4251 .type = ALC_FIXUP_PINS,
4252 .v.pins = (const struct alc_pincfg[]) {
4253 { 0x15, 0x01080104 }, /* side */
4254 { 0x16, 0x01011012 }, /* rear */
4255 { 0x17, 0x01016011 }, /* clfe */
4259 [PINFIX_LENOVO_Y530] = {
4260 .type = ALC_FIXUP_PINS,
4261 .v.pins = (const struct alc_pincfg[]) {
4262 { 0x15, 0x99130112 }, /* rear int speakers */
4263 { 0x16, 0x99130111 }, /* subwoofer */
4267 [PINFIX_PB_M5210] = {
4268 .type = ALC_FIXUP_VERBS,
4269 .v.verbs = (const struct hda_verb[]) {
4270 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
4274 [PINFIX_ACER_ASPIRE_7736] = {
4275 .type = ALC_FIXUP_SKU,
4276 .v.sku = ALC_FIXUP_SKU_IGNORE,
4278 [PINFIX_ASUS_W90V] = {
4279 .type = ALC_FIXUP_PINS,
4280 .v.pins = (const struct alc_pincfg[]) {
4281 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
4285 [ALC889_FIXUP_DAC_ROUTE] = {
4286 .type = ALC_FIXUP_FUNC,
4287 .v.func = alc889_fixup_dac_route,
4291 static const struct snd_pci_quirk alc882_fixup_tbl[] = {
4292 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", PINFIX_PB_M5210),
4293 SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE),
4294 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", PINFIX_ASUS_W90V),
4295 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", PINFIX_LENOVO_Y530),
4296 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
4297 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", PINFIX_ACER_ASPIRE_7736),
4302 * BIOS auto configuration
4304 /* almost identical with ALC880 parser... */
4305 static int alc882_parse_auto_config(struct hda_codec *codec)
4307 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
4308 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4309 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
4314 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4315 #include "alc882_quirks.c"
4318 static int patch_alc882(struct hda_codec *codec)
4320 struct alc_spec *spec;
4321 int err, board_config;
4323 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4329 spec->mixer_nid = 0x0b;
4331 switch (codec->vendor_id) {
4336 /* ALC883 and variants */
4337 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
4341 err = alc_codec_rename_from_preset(codec);
4345 board_config = alc_board_config(codec, ALC882_MODEL_LAST,
4346 alc882_models, alc882_cfg_tbl);
4348 if (board_config < 0)
4349 board_config = alc_board_codec_sid_config(codec,
4350 ALC882_MODEL_LAST, alc882_models, alc882_ssid_cfg_tbl);
4352 if (board_config < 0) {
4353 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4355 board_config = ALC_MODEL_AUTO;
4358 if (board_config == ALC_MODEL_AUTO) {
4359 alc_pick_fixup(codec, NULL, alc882_fixup_tbl, alc882_fixups);
4360 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4363 alc_auto_parse_customize_define(codec);
4365 if (board_config == ALC_MODEL_AUTO) {
4366 /* automatic parse from the BIOS config */
4367 err = alc882_parse_auto_config(codec);
4370 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4373 "hda_codec: Cannot set up configuration "
4374 "from BIOS. Using base mode...\n");
4375 board_config = ALC882_3ST_DIG;
4380 if (board_config != ALC_MODEL_AUTO)
4381 setup_preset(codec, &alc882_presets[board_config]);
4383 if (!spec->no_analog && !spec->adc_nids) {
4384 alc_auto_fill_adc_caps(codec);
4385 alc_rebuild_imux_for_auto_mic(codec);
4386 alc_remove_invalid_adc_nids(codec);
4389 if (!spec->no_analog && !spec->cap_mixer)
4390 set_capture_mixer(codec);
4392 if (!spec->no_analog && has_cdefine_beep(codec)) {
4393 err = snd_hda_attach_beep_device(codec, 0x1);
4396 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4399 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4401 spec->vmaster_nid = 0x0c;
4403 codec->patch_ops = alc_patch_ops;
4404 if (board_config == ALC_MODEL_AUTO)
4405 spec->init_hook = alc_auto_init_std;
4407 alc_init_jacks(codec);
4408 #ifdef CONFIG_SND_HDA_POWER_SAVE
4409 if (!spec->loopback.amplist)
4410 spec->loopback.amplist = alc882_loopbacks;
4424 static int alc262_parse_auto_config(struct hda_codec *codec)
4426 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
4427 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4428 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
4439 static const struct alc_fixup alc262_fixups[] = {
4440 [PINFIX_FSC_H270] = {
4441 .type = ALC_FIXUP_PINS,
4442 .v.pins = (const struct alc_pincfg[]) {
4443 { 0x14, 0x99130110 }, /* speaker */
4444 { 0x15, 0x0221142f }, /* front HP */
4445 { 0x1b, 0x0121141f }, /* rear HP */
4449 [PINFIX_HP_Z200] = {
4450 .type = ALC_FIXUP_PINS,
4451 .v.pins = (const struct alc_pincfg[]) {
4452 { 0x16, 0x99130120 }, /* internal speaker */
4458 static const struct snd_pci_quirk alc262_fixup_tbl[] = {
4459 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", PINFIX_HP_Z200),
4460 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", PINFIX_FSC_H270),
4465 #ifdef CONFIG_SND_HDA_POWER_SAVE
4466 #define alc262_loopbacks alc880_loopbacks
4471 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4472 #include "alc262_quirks.c"
4475 static int patch_alc262(struct hda_codec *codec)
4477 struct alc_spec *spec;
4481 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4487 spec->mixer_nid = 0x0b;
4490 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
4495 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4496 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
4497 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4498 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
4501 alc_auto_parse_customize_define(codec);
4503 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
4505 board_config = alc_board_config(codec, ALC262_MODEL_LAST,
4506 alc262_models, alc262_cfg_tbl);
4508 if (board_config < 0) {
4509 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4511 board_config = ALC_MODEL_AUTO;
4514 if (board_config == ALC_MODEL_AUTO) {
4515 alc_pick_fixup(codec, NULL, alc262_fixup_tbl, alc262_fixups);
4516 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4519 if (board_config == ALC_MODEL_AUTO) {
4520 /* automatic parse from the BIOS config */
4521 err = alc262_parse_auto_config(codec);
4524 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4527 "hda_codec: Cannot set up configuration "
4528 "from BIOS. Using base mode...\n");
4529 board_config = ALC262_BASIC;
4534 if (board_config != ALC_MODEL_AUTO)
4535 setup_preset(codec, &alc262_presets[board_config]);
4537 if (!spec->no_analog && !spec->adc_nids) {
4538 alc_auto_fill_adc_caps(codec);
4539 alc_rebuild_imux_for_auto_mic(codec);
4540 alc_remove_invalid_adc_nids(codec);
4543 if (!spec->no_analog && !spec->cap_mixer)
4544 set_capture_mixer(codec);
4546 if (!spec->no_analog && has_cdefine_beep(codec)) {
4547 err = snd_hda_attach_beep_device(codec, 0x1);
4550 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4553 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4555 spec->vmaster_nid = 0x0c;
4557 codec->patch_ops = alc_patch_ops;
4558 if (board_config == ALC_MODEL_AUTO)
4559 spec->init_hook = alc_auto_init_std;
4560 spec->shutup = alc_eapd_shutup;
4562 alc_init_jacks(codec);
4563 #ifdef CONFIG_SND_HDA_POWER_SAVE
4564 if (!spec->loopback.amplist)
4565 spec->loopback.amplist = alc262_loopbacks;
4578 /* bind Beep switches of both NID 0x0f and 0x10 */
4579 static const struct hda_bind_ctls alc268_bind_beep_sw = {
4580 .ops = &snd_hda_bind_sw,
4582 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
4583 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
4588 static const struct snd_kcontrol_new alc268_beep_mixer[] = {
4589 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
4590 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
4594 /* set PCBEEP vol = 0, mute connections */
4595 static const struct hda_verb alc268_beep_init_verbs[] = {
4596 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4597 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4598 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4603 * BIOS auto configuration
4605 static int alc268_parse_auto_config(struct hda_codec *codec)
4607 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4608 struct alc_spec *spec = codec->spec;
4609 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
4611 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
4612 add_mixer(spec, alc268_beep_mixer);
4613 add_verb(spec, alc268_beep_init_verbs);
4621 static int patch_alc268(struct hda_codec *codec)
4623 struct alc_spec *spec;
4624 int i, has_beep, err;
4626 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4632 /* ALC268 has no aa-loopback mixer */
4634 /* automatic parse from the BIOS config */
4635 err = alc268_parse_auto_config(codec);
4640 for (i = 0; i < spec->num_mixers; i++) {
4641 if (spec->mixers[i] == alc268_beep_mixer) {
4648 err = snd_hda_attach_beep_device(codec, 0x1);
4651 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
4652 /* override the amp caps for beep generator */
4653 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
4654 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
4655 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
4656 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4657 (0 << AC_AMPCAP_MUTE_SHIFT));
4660 if (!spec->no_analog && !spec->adc_nids) {
4661 alc_auto_fill_adc_caps(codec);
4662 alc_rebuild_imux_for_auto_mic(codec);
4663 alc_remove_invalid_adc_nids(codec);
4666 if (!spec->no_analog && !spec->cap_mixer)
4667 set_capture_mixer(codec);
4669 spec->vmaster_nid = 0x02;
4671 codec->patch_ops = alc_patch_ops;
4672 spec->init_hook = alc_auto_init_std;
4673 spec->shutup = alc_eapd_shutup;
4675 alc_init_jacks(codec);
4687 #ifdef CONFIG_SND_HDA_POWER_SAVE
4688 #define alc269_loopbacks alc880_loopbacks
4691 static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
4695 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
4696 /* NID is set in alc_build_pcms */
4698 .open = alc_playback_pcm_open,
4699 .prepare = alc_playback_pcm_prepare,
4700 .cleanup = alc_playback_pcm_cleanup
4704 static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
4708 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
4709 /* NID is set in alc_build_pcms */
4712 #ifdef CONFIG_SND_HDA_POWER_SAVE
4713 static int alc269_mic2_for_mute_led(struct hda_codec *codec)
4715 switch (codec->subsystem_id) {
4722 static int alc269_mic2_mute_check_ps(struct hda_codec *codec, hda_nid_t nid)
4724 /* update mute-LED according to the speaker mute state */
4725 if (nid == 0x01 || nid == 0x14) {
4727 if (snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0) &
4732 /* mic2 vref pin is used for mute LED control */
4733 snd_hda_codec_update_cache(codec, 0x19, 0,
4734 AC_VERB_SET_PIN_WIDGET_CONTROL,
4737 return alc_check_power_status(codec, nid);
4739 #endif /* CONFIG_SND_HDA_POWER_SAVE */
4741 /* different alc269-variants */
4743 ALC269_TYPE_ALC269VA,
4744 ALC269_TYPE_ALC269VB,
4745 ALC269_TYPE_ALC269VC,
4749 * BIOS auto configuration
4751 static int alc269_parse_auto_config(struct hda_codec *codec)
4753 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
4754 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
4755 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4756 struct alc_spec *spec = codec->spec;
4757 const hda_nid_t *ssids = spec->codec_variant == ALC269_TYPE_ALC269VA ?
4758 alc269va_ssids : alc269_ssids;
4760 return alc_parse_auto_config(codec, alc269_ignore, ssids);
4763 static void alc269_toggle_power_output(struct hda_codec *codec, int power_up)
4765 int val = alc_read_coef_idx(codec, 0x04);
4770 alc_write_coef_idx(codec, 0x04, val);
4773 static void alc269_shutup(struct hda_codec *codec)
4775 if ((alc_get_coef0(codec) & 0x00ff) == 0x017)
4776 alc269_toggle_power_output(codec, 0);
4777 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
4778 alc269_toggle_power_output(codec, 0);
4784 static int alc269_resume(struct hda_codec *codec)
4786 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
4787 alc269_toggle_power_output(codec, 0);
4791 codec->patch_ops.init(codec);
4793 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
4794 alc269_toggle_power_output(codec, 1);
4798 if ((alc_get_coef0(codec) & 0x00ff) == 0x018)
4799 alc269_toggle_power_output(codec, 1);
4801 snd_hda_codec_resume_amp(codec);
4802 snd_hda_codec_resume_cache(codec);
4803 hda_call_check_power_status(codec, 0x01);
4806 #endif /* CONFIG_PM */
4808 static void alc269_fixup_hweq(struct hda_codec *codec,
4809 const struct alc_fixup *fix, int action)
4813 if (action != ALC_FIXUP_ACT_INIT)
4815 coef = alc_read_coef_idx(codec, 0x1e);
4816 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
4819 static void alc271_fixup_dmic(struct hda_codec *codec,
4820 const struct alc_fixup *fix, int action)
4822 static const struct hda_verb verbs[] = {
4823 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
4824 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
4829 if (strcmp(codec->chip_name, "ALC271X"))
4831 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
4832 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
4833 snd_hda_sequence_write(codec, verbs);
4836 static void alc269_fixup_pcm_44k(struct hda_codec *codec,
4837 const struct alc_fixup *fix, int action)
4839 struct alc_spec *spec = codec->spec;
4841 if (action != ALC_FIXUP_ACT_PROBE)
4844 /* Due to a hardware problem on Lenovo Ideadpad, we need to
4845 * fix the sample rate of analog I/O to 44.1kHz
4847 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
4848 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
4851 static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
4852 const struct alc_fixup *fix, int action)
4856 if (action != ALC_FIXUP_ACT_INIT)
4858 /* The digital-mic unit sends PDM (differential signal) instead of
4859 * the standard PCM, thus you can't record a valid mono stream as is.
4860 * Below is a workaround specific to ALC269 to control the dmic
4861 * signal source as mono.
4863 coef = alc_read_coef_idx(codec, 0x07);
4864 alc_write_coef_idx(codec, 0x07, coef | 0x80);
4867 static void alc269_quanta_automute(struct hda_codec *codec)
4869 update_outputs(codec);
4871 snd_hda_codec_write(codec, 0x20, 0,
4872 AC_VERB_SET_COEF_INDEX, 0x0c);
4873 snd_hda_codec_write(codec, 0x20, 0,
4874 AC_VERB_SET_PROC_COEF, 0x680);
4876 snd_hda_codec_write(codec, 0x20, 0,
4877 AC_VERB_SET_COEF_INDEX, 0x0c);
4878 snd_hda_codec_write(codec, 0x20, 0,
4879 AC_VERB_SET_PROC_COEF, 0x480);
4882 static void alc269_fixup_quanta_mute(struct hda_codec *codec,
4883 const struct alc_fixup *fix, int action)
4885 struct alc_spec *spec = codec->spec;
4886 if (action != ALC_FIXUP_ACT_PROBE)
4888 spec->automute_hook = alc269_quanta_automute;
4892 ALC269_FIXUP_SONY_VAIO,
4893 ALC275_FIXUP_SONY_VAIO_GPIO2,
4894 ALC269_FIXUP_DELL_M101Z,
4895 ALC269_FIXUP_SKU_IGNORE,
4896 ALC269_FIXUP_ASUS_G73JW,
4897 ALC269_FIXUP_LENOVO_EAPD,
4898 ALC275_FIXUP_SONY_HWEQ,
4900 ALC269_FIXUP_PCM_44K,
4901 ALC269_FIXUP_STEREO_DMIC,
4902 ALC269_FIXUP_QUANTA_MUTE,
4903 ALC269_FIXUP_LIFEBOOK,
4906 ALC269VB_FIXUP_AMIC,
4907 ALC269VB_FIXUP_DMIC,
4910 static const struct alc_fixup alc269_fixups[] = {
4911 [ALC269_FIXUP_SONY_VAIO] = {
4912 .type = ALC_FIXUP_VERBS,
4913 .v.verbs = (const struct hda_verb[]) {
4914 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
4918 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
4919 .type = ALC_FIXUP_VERBS,
4920 .v.verbs = (const struct hda_verb[]) {
4921 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
4922 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
4923 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
4927 .chain_id = ALC269_FIXUP_SONY_VAIO
4929 [ALC269_FIXUP_DELL_M101Z] = {
4930 .type = ALC_FIXUP_VERBS,
4931 .v.verbs = (const struct hda_verb[]) {
4932 /* Enables internal speaker */
4933 {0x20, AC_VERB_SET_COEF_INDEX, 13},
4934 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
4938 [ALC269_FIXUP_SKU_IGNORE] = {
4939 .type = ALC_FIXUP_SKU,
4940 .v.sku = ALC_FIXUP_SKU_IGNORE,
4942 [ALC269_FIXUP_ASUS_G73JW] = {
4943 .type = ALC_FIXUP_PINS,
4944 .v.pins = (const struct alc_pincfg[]) {
4945 { 0x17, 0x99130111 }, /* subwoofer */
4949 [ALC269_FIXUP_LENOVO_EAPD] = {
4950 .type = ALC_FIXUP_VERBS,
4951 .v.verbs = (const struct hda_verb[]) {
4952 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
4956 [ALC275_FIXUP_SONY_HWEQ] = {
4957 .type = ALC_FIXUP_FUNC,
4958 .v.func = alc269_fixup_hweq,
4960 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
4962 [ALC271_FIXUP_DMIC] = {
4963 .type = ALC_FIXUP_FUNC,
4964 .v.func = alc271_fixup_dmic,
4966 [ALC269_FIXUP_PCM_44K] = {
4967 .type = ALC_FIXUP_FUNC,
4968 .v.func = alc269_fixup_pcm_44k,
4970 [ALC269_FIXUP_STEREO_DMIC] = {
4971 .type = ALC_FIXUP_FUNC,
4972 .v.func = alc269_fixup_stereo_dmic,
4974 [ALC269_FIXUP_QUANTA_MUTE] = {
4975 .type = ALC_FIXUP_FUNC,
4976 .v.func = alc269_fixup_quanta_mute,
4978 [ALC269_FIXUP_LIFEBOOK] = {
4979 .type = ALC_FIXUP_PINS,
4980 .v.pins = (const struct alc_pincfg[]) {
4981 { 0x1a, 0x2101103f }, /* dock line-out */
4982 { 0x1b, 0x23a11040 }, /* dock mic-in */
4986 .chain_id = ALC269_FIXUP_QUANTA_MUTE
4988 [ALC269_FIXUP_AMIC] = {
4989 .type = ALC_FIXUP_PINS,
4990 .v.pins = (const struct alc_pincfg[]) {
4991 { 0x14, 0x99130110 }, /* speaker */
4992 { 0x15, 0x0121401f }, /* HP out */
4993 { 0x18, 0x01a19c20 }, /* mic */
4994 { 0x19, 0x99a3092f }, /* int-mic */
4998 [ALC269_FIXUP_DMIC] = {
4999 .type = ALC_FIXUP_PINS,
5000 .v.pins = (const struct alc_pincfg[]) {
5001 { 0x12, 0x99a3092f }, /* int-mic */
5002 { 0x14, 0x99130110 }, /* speaker */
5003 { 0x15, 0x0121401f }, /* HP out */
5004 { 0x18, 0x01a19c20 }, /* mic */
5008 [ALC269VB_FIXUP_AMIC] = {
5009 .type = ALC_FIXUP_PINS,
5010 .v.pins = (const struct alc_pincfg[]) {
5011 { 0x14, 0x99130110 }, /* speaker */
5012 { 0x18, 0x01a19c20 }, /* mic */
5013 { 0x19, 0x99a3092f }, /* int-mic */
5014 { 0x21, 0x0121401f }, /* HP out */
5018 [ALC269_FIXUP_DMIC] = {
5019 .type = ALC_FIXUP_PINS,
5020 .v.pins = (const struct alc_pincfg[]) {
5021 { 0x12, 0x99a3092f }, /* int-mic */
5022 { 0x14, 0x99130110 }, /* speaker */
5023 { 0x18, 0x01a19c20 }, /* mic */
5024 { 0x21, 0x0121401f }, /* HP out */
5030 static const struct snd_pci_quirk alc269_fixup_tbl[] = {
5031 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
5032 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
5033 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
5034 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
5035 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
5036 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
5037 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
5038 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
5039 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
5040 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
5041 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
5042 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
5043 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
5044 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
5045 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
5046 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
5047 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
5048 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
5049 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_QUANTA_MUTE),
5050 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K),
5051 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
5054 /* Below is a quirk table taken from the old code.
5055 * Basically the device should work as is without the fixup table.
5056 * If BIOS doesn't give a proper info, enable the corresponding
5059 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
5061 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
5062 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
5063 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
5064 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
5065 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
5066 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
5067 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
5068 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
5069 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
5070 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
5071 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
5072 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
5073 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
5074 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
5075 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
5076 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
5077 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
5078 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
5079 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
5080 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
5081 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
5082 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
5083 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
5084 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
5085 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
5086 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
5087 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
5088 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
5089 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
5090 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
5091 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
5092 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
5093 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
5094 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
5095 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
5096 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
5097 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
5098 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
5099 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
5104 static const struct alc_model_fixup alc269_fixup_models[] = {
5105 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
5106 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
5111 static int alc269_fill_coef(struct hda_codec *codec)
5115 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
5116 alc_write_coef_idx(codec, 0xf, 0x960b);
5117 alc_write_coef_idx(codec, 0xe, 0x8817);
5120 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
5121 alc_write_coef_idx(codec, 0xf, 0x960b);
5122 alc_write_coef_idx(codec, 0xe, 0x8814);
5125 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
5126 val = alc_read_coef_idx(codec, 0x04);
5127 /* Power up output pin */
5128 alc_write_coef_idx(codec, 0x04, val | (1<<11));
5131 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
5132 val = alc_read_coef_idx(codec, 0xd);
5133 if ((val & 0x0c00) >> 10 != 0x1) {
5134 /* Capless ramp up clock control */
5135 alc_write_coef_idx(codec, 0xd, val | (1<<10));
5137 val = alc_read_coef_idx(codec, 0x17);
5138 if ((val & 0x01c0) >> 6 != 0x4) {
5139 /* Class D power on reset */
5140 alc_write_coef_idx(codec, 0x17, val | (1<<7));
5144 val = alc_read_coef_idx(codec, 0xd); /* Class D */
5145 alc_write_coef_idx(codec, 0xd, val | (1<<14));
5147 val = alc_read_coef_idx(codec, 0x4); /* HP */
5148 alc_write_coef_idx(codec, 0x4, val | (1<<11));
5155 static int patch_alc269(struct hda_codec *codec)
5157 struct alc_spec *spec;
5160 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5166 spec->mixer_nid = 0x0b;
5168 alc_auto_parse_customize_define(codec);
5170 err = alc_codec_rename_from_preset(codec);
5174 if (codec->vendor_id == 0x10ec0269) {
5175 spec->codec_variant = ALC269_TYPE_ALC269VA;
5176 switch (alc_get_coef0(codec) & 0x00f0) {
5178 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
5179 spec->cdefine.platform_type == 1)
5180 err = alc_codec_rename(codec, "ALC271X");
5181 spec->codec_variant = ALC269_TYPE_ALC269VB;
5184 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
5185 codec->bus->pci->subsystem_device == 0x21f3)
5186 err = alc_codec_rename(codec, "ALC3202");
5187 spec->codec_variant = ALC269_TYPE_ALC269VC;
5190 alc_fix_pll_init(codec, 0x20, 0x04, 15);
5194 alc269_fill_coef(codec);
5197 alc_pick_fixup(codec, alc269_fixup_models,
5198 alc269_fixup_tbl, alc269_fixups);
5199 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5201 /* automatic parse from the BIOS config */
5202 err = alc269_parse_auto_config(codec);
5206 if (!spec->no_analog && !spec->adc_nids) {
5207 alc_auto_fill_adc_caps(codec);
5208 alc_rebuild_imux_for_auto_mic(codec);
5209 alc_remove_invalid_adc_nids(codec);
5212 if (!spec->no_analog && !spec->cap_mixer)
5213 set_capture_mixer(codec);
5215 if (!spec->no_analog && has_cdefine_beep(codec)) {
5216 err = snd_hda_attach_beep_device(codec, 0x1);
5219 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
5222 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5224 spec->vmaster_nid = 0x02;
5226 codec->patch_ops = alc_patch_ops;
5228 codec->patch_ops.resume = alc269_resume;
5230 spec->init_hook = alc_auto_init_std;
5231 spec->shutup = alc269_shutup;
5233 alc_init_jacks(codec);
5234 #ifdef CONFIG_SND_HDA_POWER_SAVE
5235 if (!spec->loopback.amplist)
5236 spec->loopback.amplist = alc269_loopbacks;
5237 if (alc269_mic2_for_mute_led(codec))
5238 codec->patch_ops.check_power_status = alc269_mic2_mute_check_ps;
5252 static int alc861_parse_auto_config(struct hda_codec *codec)
5254 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
5255 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
5256 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
5259 #ifdef CONFIG_SND_HDA_POWER_SAVE
5260 static const struct hda_amp_list alc861_loopbacks[] = {
5261 { 0x15, HDA_INPUT, 0 },
5262 { 0x15, HDA_INPUT, 1 },
5263 { 0x15, HDA_INPUT, 2 },
5264 { 0x15, HDA_INPUT, 3 },
5270 /* Pin config fixes */
5272 PINFIX_FSC_AMILO_PI1505,
5276 /* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
5277 static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
5278 const struct alc_fixup *fix, int action)
5280 struct alc_spec *spec = codec->spec;
5283 if (action != ALC_FIXUP_ACT_INIT)
5285 val = snd_hda_codec_read(codec, 0x0f, 0,
5286 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5287 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
5288 val |= AC_PINCTL_IN_EN;
5289 val |= AC_PINCTL_VREF_50;
5290 snd_hda_codec_write(codec, 0x0f, 0,
5291 AC_VERB_SET_PIN_WIDGET_CONTROL, val);
5292 spec->keep_vref_in_automute = 1;
5295 static const struct alc_fixup alc861_fixups[] = {
5296 [PINFIX_FSC_AMILO_PI1505] = {
5297 .type = ALC_FIXUP_PINS,
5298 .v.pins = (const struct alc_pincfg[]) {
5299 { 0x0b, 0x0221101f }, /* HP */
5300 { 0x0f, 0x90170310 }, /* speaker */
5304 [PINFIX_ASUS_A6RP] = {
5305 .type = ALC_FIXUP_FUNC,
5306 .v.func = alc861_fixup_asus_amp_vref_0f,
5310 static const struct snd_pci_quirk alc861_fixup_tbl[] = {
5311 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", PINFIX_ASUS_A6RP),
5312 SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", PINFIX_ASUS_A6RP),
5313 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", PINFIX_FSC_AMILO_PI1505),
5319 static int patch_alc861(struct hda_codec *codec)
5321 struct alc_spec *spec;
5324 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5330 spec->mixer_nid = 0x15;
5332 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
5333 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5335 /* automatic parse from the BIOS config */
5336 err = alc861_parse_auto_config(codec);
5340 if (!spec->no_analog && !spec->adc_nids) {
5341 alc_auto_fill_adc_caps(codec);
5342 alc_rebuild_imux_for_auto_mic(codec);
5343 alc_remove_invalid_adc_nids(codec);
5346 if (!spec->no_analog && !spec->cap_mixer)
5347 set_capture_mixer(codec);
5349 if (!spec->no_analog) {
5350 err = snd_hda_attach_beep_device(codec, 0x23);
5353 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
5356 spec->vmaster_nid = 0x03;
5358 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5360 codec->patch_ops = alc_patch_ops;
5361 spec->init_hook = alc_auto_init_std;
5362 #ifdef CONFIG_SND_HDA_POWER_SAVE
5363 spec->power_hook = alc_power_eapd;
5364 if (!spec->loopback.amplist)
5365 spec->loopback.amplist = alc861_loopbacks;
5380 * In addition, an independent DAC
5382 #ifdef CONFIG_SND_HDA_POWER_SAVE
5383 #define alc861vd_loopbacks alc880_loopbacks
5386 static int alc861vd_parse_auto_config(struct hda_codec *codec)
5388 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
5389 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5390 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
5394 ALC660VD_FIX_ASUS_GPIO1,
5395 ALC861VD_FIX_DALLAS,
5398 /* exclude VREF80 */
5399 static void alc861vd_fixup_dallas(struct hda_codec *codec,
5400 const struct alc_fixup *fix, int action)
5402 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
5403 snd_hda_override_pin_caps(codec, 0x18, 0x00001714);
5404 snd_hda_override_pin_caps(codec, 0x19, 0x0000171c);
5408 static const struct alc_fixup alc861vd_fixups[] = {
5409 [ALC660VD_FIX_ASUS_GPIO1] = {
5410 .type = ALC_FIXUP_VERBS,
5411 .v.verbs = (const struct hda_verb[]) {
5413 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
5414 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5415 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5419 [ALC861VD_FIX_DALLAS] = {
5420 .type = ALC_FIXUP_FUNC,
5421 .v.func = alc861vd_fixup_dallas,
5425 static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
5426 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
5427 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
5428 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
5432 static const struct hda_verb alc660vd_eapd_verbs[] = {
5433 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
5434 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
5440 static int patch_alc861vd(struct hda_codec *codec)
5442 struct alc_spec *spec;
5445 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5451 spec->mixer_nid = 0x0b;
5453 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
5454 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5456 /* automatic parse from the BIOS config */
5457 err = alc861vd_parse_auto_config(codec);
5461 if (codec->vendor_id == 0x10ec0660) {
5462 /* always turn on EAPD */
5463 add_verb(spec, alc660vd_eapd_verbs);
5466 if (!spec->no_analog && !spec->adc_nids) {
5467 alc_auto_fill_adc_caps(codec);
5468 alc_rebuild_imux_for_auto_mic(codec);
5469 alc_remove_invalid_adc_nids(codec);
5472 if (!spec->no_analog && !spec->cap_mixer)
5473 set_capture_mixer(codec);
5475 if (!spec->no_analog) {
5476 err = snd_hda_attach_beep_device(codec, 0x23);
5479 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5482 spec->vmaster_nid = 0x02;
5484 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5486 codec->patch_ops = alc_patch_ops;
5488 spec->init_hook = alc_auto_init_std;
5489 spec->shutup = alc_eapd_shutup;
5490 #ifdef CONFIG_SND_HDA_POWER_SAVE
5491 if (!spec->loopback.amplist)
5492 spec->loopback.amplist = alc861vd_loopbacks;
5505 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
5506 * configuration. Each pin widget can choose any input DACs and a mixer.
5507 * Each ADC is connected from a mixer of all inputs. This makes possible
5508 * 6-channel independent captures.
5510 * In addition, an independent DAC for the multi-playback (not used in this
5513 #ifdef CONFIG_SND_HDA_POWER_SAVE
5514 #define alc662_loopbacks alc880_loopbacks
5518 * BIOS auto configuration
5521 static int alc662_parse_auto_config(struct hda_codec *codec)
5523 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
5524 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
5525 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5526 const hda_nid_t *ssids;
5528 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
5529 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
5530 ssids = alc663_ssids;
5532 ssids = alc662_ssids;
5533 return alc_parse_auto_config(codec, alc662_ignore, ssids);
5536 static void alc272_fixup_mario(struct hda_codec *codec,
5537 const struct alc_fixup *fix, int action)
5539 if (action != ALC_FIXUP_ACT_PROBE)
5541 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
5542 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
5543 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
5544 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5545 (0 << AC_AMPCAP_MUTE_SHIFT)))
5547 "hda_codec: failed to override amp caps for NID 0x2\n");
5551 ALC662_FIXUP_ASPIRE,
5552 ALC662_FIXUP_IDEAPAD,
5554 ALC662_FIXUP_CZC_P10T,
5555 ALC662_FIXUP_SKU_IGNORE,
5556 ALC662_FIXUP_HP_RP5800,
5557 ALC662_FIXUP_ASUS_MODE1,
5558 ALC662_FIXUP_ASUS_MODE2,
5559 ALC662_FIXUP_ASUS_MODE3,
5560 ALC662_FIXUP_ASUS_MODE4,
5561 ALC662_FIXUP_ASUS_MODE5,
5562 ALC662_FIXUP_ASUS_MODE6,
5563 ALC662_FIXUP_ASUS_MODE7,
5564 ALC662_FIXUP_ASUS_MODE8,
5567 static const struct alc_fixup alc662_fixups[] = {
5568 [ALC662_FIXUP_ASPIRE] = {
5569 .type = ALC_FIXUP_PINS,
5570 .v.pins = (const struct alc_pincfg[]) {
5571 { 0x15, 0x99130112 }, /* subwoofer */
5575 [ALC662_FIXUP_IDEAPAD] = {
5576 .type = ALC_FIXUP_PINS,
5577 .v.pins = (const struct alc_pincfg[]) {
5578 { 0x17, 0x99130112 }, /* subwoofer */
5582 [ALC272_FIXUP_MARIO] = {
5583 .type = ALC_FIXUP_FUNC,
5584 .v.func = alc272_fixup_mario,
5586 [ALC662_FIXUP_CZC_P10T] = {
5587 .type = ALC_FIXUP_VERBS,
5588 .v.verbs = (const struct hda_verb[]) {
5589 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
5593 [ALC662_FIXUP_SKU_IGNORE] = {
5594 .type = ALC_FIXUP_SKU,
5595 .v.sku = ALC_FIXUP_SKU_IGNORE,
5597 [ALC662_FIXUP_HP_RP5800] = {
5598 .type = ALC_FIXUP_PINS,
5599 .v.pins = (const struct alc_pincfg[]) {
5600 { 0x14, 0x0221201f }, /* HP out */
5604 .chain_id = ALC662_FIXUP_SKU_IGNORE
5606 [ALC662_FIXUP_ASUS_MODE1] = {
5607 .type = ALC_FIXUP_PINS,
5608 .v.pins = (const struct alc_pincfg[]) {
5609 { 0x14, 0x99130110 }, /* speaker */
5610 { 0x18, 0x01a19c20 }, /* mic */
5611 { 0x19, 0x99a3092f }, /* int-mic */
5612 { 0x21, 0x0121401f }, /* HP out */
5616 .chain_id = ALC662_FIXUP_SKU_IGNORE
5618 [ALC662_FIXUP_ASUS_MODE2] = {
5619 .type = ALC_FIXUP_PINS,
5620 .v.pins = (const struct alc_pincfg[]) {
5621 { 0x14, 0x99130110 }, /* speaker */
5622 { 0x18, 0x01a19820 }, /* mic */
5623 { 0x19, 0x99a3092f }, /* int-mic */
5624 { 0x1b, 0x0121401f }, /* HP out */
5628 .chain_id = ALC662_FIXUP_SKU_IGNORE
5630 [ALC662_FIXUP_ASUS_MODE3] = {
5631 .type = ALC_FIXUP_PINS,
5632 .v.pins = (const struct alc_pincfg[]) {
5633 { 0x14, 0x99130110 }, /* speaker */
5634 { 0x15, 0x0121441f }, /* HP */
5635 { 0x18, 0x01a19840 }, /* mic */
5636 { 0x19, 0x99a3094f }, /* int-mic */
5637 { 0x21, 0x01211420 }, /* HP2 */
5641 .chain_id = ALC662_FIXUP_SKU_IGNORE
5643 [ALC662_FIXUP_ASUS_MODE4] = {
5644 .type = ALC_FIXUP_PINS,
5645 .v.pins = (const struct alc_pincfg[]) {
5646 { 0x14, 0x99130110 }, /* speaker */
5647 { 0x16, 0x99130111 }, /* speaker */
5648 { 0x18, 0x01a19840 }, /* mic */
5649 { 0x19, 0x99a3094f }, /* int-mic */
5650 { 0x21, 0x0121441f }, /* HP */
5654 .chain_id = ALC662_FIXUP_SKU_IGNORE
5656 [ALC662_FIXUP_ASUS_MODE5] = {
5657 .type = ALC_FIXUP_PINS,
5658 .v.pins = (const struct alc_pincfg[]) {
5659 { 0x14, 0x99130110 }, /* speaker */
5660 { 0x15, 0x0121441f }, /* HP */
5661 { 0x16, 0x99130111 }, /* speaker */
5662 { 0x18, 0x01a19840 }, /* mic */
5663 { 0x19, 0x99a3094f }, /* int-mic */
5667 .chain_id = ALC662_FIXUP_SKU_IGNORE
5669 [ALC662_FIXUP_ASUS_MODE6] = {
5670 .type = ALC_FIXUP_PINS,
5671 .v.pins = (const struct alc_pincfg[]) {
5672 { 0x14, 0x99130110 }, /* speaker */
5673 { 0x15, 0x01211420 }, /* HP2 */
5674 { 0x18, 0x01a19840 }, /* mic */
5675 { 0x19, 0x99a3094f }, /* int-mic */
5676 { 0x1b, 0x0121441f }, /* HP */
5680 .chain_id = ALC662_FIXUP_SKU_IGNORE
5682 [ALC662_FIXUP_ASUS_MODE7] = {
5683 .type = ALC_FIXUP_PINS,
5684 .v.pins = (const struct alc_pincfg[]) {
5685 { 0x14, 0x99130110 }, /* speaker */
5686 { 0x17, 0x99130111 }, /* speaker */
5687 { 0x18, 0x01a19840 }, /* mic */
5688 { 0x19, 0x99a3094f }, /* int-mic */
5689 { 0x1b, 0x01214020 }, /* HP */
5690 { 0x21, 0x0121401f }, /* HP */
5694 .chain_id = ALC662_FIXUP_SKU_IGNORE
5696 [ALC662_FIXUP_ASUS_MODE8] = {
5697 .type = ALC_FIXUP_PINS,
5698 .v.pins = (const struct alc_pincfg[]) {
5699 { 0x14, 0x99130110 }, /* speaker */
5700 { 0x12, 0x99a30970 }, /* int-mic */
5701 { 0x15, 0x01214020 }, /* HP */
5702 { 0x17, 0x99130111 }, /* speaker */
5703 { 0x18, 0x01a19840 }, /* mic */
5704 { 0x21, 0x0121401f }, /* HP */
5708 .chain_id = ALC662_FIXUP_SKU_IGNORE
5712 static const struct snd_pci_quirk alc662_fixup_tbl[] = {
5713 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
5714 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
5715 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
5716 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
5717 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
5718 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
5719 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
5720 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
5721 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
5722 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
5725 /* Below is a quirk table taken from the old code.
5726 * Basically the device should work as is without the fixup table.
5727 * If BIOS doesn't give a proper info, enable the corresponding
5730 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
5731 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
5732 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
5733 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
5734 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
5735 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5736 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
5737 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
5738 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
5739 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5740 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
5741 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
5742 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
5743 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
5744 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
5745 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5746 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
5747 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
5748 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5749 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
5750 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
5751 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5752 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
5753 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
5754 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
5755 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5756 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
5757 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
5758 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5759 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
5760 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5761 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5762 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
5763 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
5764 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
5765 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
5766 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
5767 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
5768 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
5769 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5770 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
5771 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
5772 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
5773 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
5774 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
5775 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
5776 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
5777 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
5778 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
5779 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
5784 static const struct alc_model_fixup alc662_fixup_models[] = {
5785 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
5786 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
5787 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
5788 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
5789 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
5790 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
5791 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
5792 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
5793 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
5800 static int patch_alc662(struct hda_codec *codec)
5802 struct alc_spec *spec;
5805 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5811 spec->mixer_nid = 0x0b;
5813 /* handle multiple HPs as is */
5814 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
5816 alc_auto_parse_customize_define(codec);
5818 alc_fix_pll_init(codec, 0x20, 0x04, 15);
5820 err = alc_codec_rename_from_preset(codec);
5824 if ((alc_get_coef0(codec) & (1 << 14)) &&
5825 codec->bus->pci->subsystem_vendor == 0x1025 &&
5826 spec->cdefine.platform_type == 1) {
5827 if (alc_codec_rename(codec, "ALC272X") < 0)
5831 alc_pick_fixup(codec, alc662_fixup_models,
5832 alc662_fixup_tbl, alc662_fixups);
5833 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5834 /* automatic parse from the BIOS config */
5835 err = alc662_parse_auto_config(codec);
5839 if (!spec->no_analog && !spec->adc_nids) {
5840 alc_auto_fill_adc_caps(codec);
5841 alc_rebuild_imux_for_auto_mic(codec);
5842 alc_remove_invalid_adc_nids(codec);
5845 if (!spec->no_analog && !spec->cap_mixer)
5846 set_capture_mixer(codec);
5848 if (!spec->no_analog && has_cdefine_beep(codec)) {
5849 err = snd_hda_attach_beep_device(codec, 0x1);
5852 switch (codec->vendor_id) {
5854 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5859 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
5862 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
5866 spec->vmaster_nid = 0x02;
5868 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5870 codec->patch_ops = alc_patch_ops;
5871 spec->init_hook = alc_auto_init_std;
5872 spec->shutup = alc_eapd_shutup;
5874 alc_init_jacks(codec);
5876 #ifdef CONFIG_SND_HDA_POWER_SAVE
5877 if (!spec->loopback.amplist)
5878 spec->loopback.amplist = alc662_loopbacks;
5892 static int alc680_parse_auto_config(struct hda_codec *codec)
5894 return alc_parse_auto_config(codec, NULL, NULL);
5899 static int patch_alc680(struct hda_codec *codec)
5901 struct alc_spec *spec;
5904 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5910 /* ALC680 has no aa-loopback mixer */
5912 /* automatic parse from the BIOS config */
5913 err = alc680_parse_auto_config(codec);
5919 if (!spec->no_analog && !spec->cap_mixer)
5920 set_capture_mixer(codec);
5922 spec->vmaster_nid = 0x02;
5924 codec->patch_ops = alc_patch_ops;
5925 spec->init_hook = alc_auto_init_std;
5933 static const struct hda_codec_preset snd_hda_preset_realtek[] = {
5934 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
5935 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
5936 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
5937 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
5938 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
5939 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
5940 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
5941 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
5942 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
5943 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
5944 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
5945 .patch = patch_alc861 },
5946 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
5947 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
5948 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
5949 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
5950 .patch = patch_alc882 },
5951 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
5952 .patch = patch_alc662 },
5953 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
5954 .patch = patch_alc662 },
5955 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
5956 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
5957 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
5958 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
5959 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
5960 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
5961 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
5962 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
5963 .patch = patch_alc882 },
5964 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
5965 .patch = patch_alc882 },
5966 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
5967 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
5968 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
5969 .patch = patch_alc882 },
5970 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
5971 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
5972 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
5973 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
5977 MODULE_ALIAS("snd-hda-codec-id:10ec*");
5979 MODULE_LICENSE("GPL");
5980 MODULE_DESCRIPTION("Realtek HD-audio codec");
5982 static struct hda_codec_preset_list realtek_list = {
5983 .preset = snd_hda_preset_realtek,
5984 .owner = THIS_MODULE,
5987 static int __init patch_realtek_init(void)
5989 return snd_hda_add_codec_preset(&realtek_list);
5992 static void __exit patch_realtek_exit(void)
5994 snd_hda_delete_codec_preset(&realtek_list);
5997 module_init(patch_realtek_init)
5998 module_exit(patch_realtek_exit)