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"
38 /* unsol event tags */
39 #define ALC_FRONT_EVENT 0x01
40 #define ALC_DCVOL_EVENT 0x02
41 #define ALC_HP_EVENT 0x04
42 #define ALC_MIC_EVENT 0x08
45 #define GPIO_MASK 0x03
47 /* extra amp-initialization sequence types */
56 struct alc_customize_define {
58 unsigned char port_connectivity;
59 unsigned char check_sum;
60 unsigned char customization;
61 unsigned char external_amp;
62 unsigned int enable_pcbeep:1;
63 unsigned int platform_type:1;
65 unsigned int override:1;
66 unsigned int fixup:1; /* Means that this sku is set by driver, not read from hw */
72 hda_nid_t pin; /* multi-io widget pin NID */
73 hda_nid_t dac; /* DAC to be connected */
74 unsigned int ctl_in; /* cached input-pin control value */
78 ALC_AUTOMUTE_PIN, /* change the pin control */
79 ALC_AUTOMUTE_AMP, /* mute/unmute the pin AMP */
80 ALC_AUTOMUTE_MIXER, /* mute/unmute mixer widget AMP */
84 /* codec parameterization */
85 const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */
86 unsigned int num_mixers;
87 const struct snd_kcontrol_new *cap_mixer; /* capture mixer */
88 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
90 const struct hda_verb *init_verbs[10]; /* initialization verbs
94 unsigned int num_init_verbs;
96 char stream_name_analog[32]; /* analog PCM stream */
97 const struct hda_pcm_stream *stream_analog_playback;
98 const struct hda_pcm_stream *stream_analog_capture;
99 const struct hda_pcm_stream *stream_analog_alt_playback;
100 const struct hda_pcm_stream *stream_analog_alt_capture;
102 char stream_name_digital[32]; /* digital PCM stream */
103 const struct hda_pcm_stream *stream_digital_playback;
104 const struct hda_pcm_stream *stream_digital_capture;
107 struct hda_multi_out multiout; /* playback set-up
108 * max_channels, dacs must be set
109 * dig_out_nid and hp_nid are optional
111 hda_nid_t alt_dac_nid;
112 hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */
116 unsigned int num_adc_nids;
117 const hda_nid_t *adc_nids;
118 const hda_nid_t *capsrc_nids;
119 hda_nid_t dig_in_nid; /* digital-in NID; optional */
120 hda_nid_t mixer_nid; /* analog-mixer NID */
121 DECLARE_BITMAP(vol_ctls, 0x20 << 1);
122 DECLARE_BITMAP(sw_ctls, 0x20 << 1);
124 /* capture setup for dynamic dual-adc switch */
126 unsigned int cur_adc_stream_tag;
127 unsigned int cur_adc_format;
130 unsigned int num_mux_defs;
131 const struct hda_input_mux *input_mux;
132 unsigned int cur_mux[3];
133 hda_nid_t ext_mic_pin;
134 hda_nid_t dock_mic_pin;
135 hda_nid_t int_mic_pin;
138 const struct hda_channel_mode *channel_mode;
139 int num_channel_mode;
141 int const_channel_count;
142 int ext_channel_count;
144 /* PCM information */
145 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
147 /* dynamic controls, init_verbs and input_mux */
148 struct auto_pin_cfg autocfg;
149 struct alc_customize_define cdefine;
150 struct snd_array kctls;
151 struct hda_input_mux private_imux[3];
152 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
153 hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS];
154 hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS];
155 hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS];
156 unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS];
157 int int_mic_idx, ext_mic_idx, dock_mic_idx; /* for auto-mic */
160 void (*init_hook)(struct hda_codec *codec);
161 void (*unsol_event)(struct hda_codec *codec, unsigned int res);
162 #ifdef CONFIG_SND_HDA_POWER_SAVE
163 void (*power_hook)(struct hda_codec *codec);
165 void (*shutup)(struct hda_codec *codec);
166 void (*automute_hook)(struct hda_codec *codec);
168 /* for pin sensing */
169 unsigned int hp_jack_present:1;
170 unsigned int line_jack_present:1;
171 unsigned int master_mute:1;
172 unsigned int auto_mic:1;
173 unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */
174 unsigned int automute_speaker:1; /* automute speaker outputs */
175 unsigned int automute_lo:1; /* automute LO outputs */
176 unsigned int detect_hp:1; /* Headphone detection enabled */
177 unsigned int detect_lo:1; /* Line-out detection enabled */
178 unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */
179 unsigned int automute_lo_possible:1; /* there are line outs and HP */
182 unsigned int no_analog :1; /* digital I/O only */
183 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
184 unsigned int single_input_src:1;
185 unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */
186 unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */
187 unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */
188 unsigned int use_jack_tbl:1; /* 1 for model=auto */
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 void call_update_outputs(struct hda_codec *codec);
285 /* select the given imux item; either unmute exclusively or select the route */
286 static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
287 unsigned int idx, bool force)
289 struct alc_spec *spec = codec->spec;
290 const struct hda_input_mux *imux;
291 unsigned int mux_idx;
292 int i, type, num_conns;
295 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
296 imux = &spec->input_mux[mux_idx];
297 if (!imux->num_items && mux_idx > 0)
298 imux = &spec->input_mux[0];
300 if (idx >= imux->num_items)
301 idx = imux->num_items - 1;
302 if (spec->cur_mux[adc_idx] == idx && !force)
304 spec->cur_mux[adc_idx] = idx;
306 /* for shared I/O, change the pin-control accordingly */
307 if (spec->shared_mic_hp) {
308 /* NOTE: this assumes that there are only two inputs, the
309 * first is the real internal mic and the second is HP jack.
311 snd_hda_codec_write(codec, spec->autocfg.inputs[1].pin, 0,
312 AC_VERB_SET_PIN_WIDGET_CONTROL,
313 spec->cur_mux[adc_idx] ?
314 PIN_VREF80 : PIN_HP);
315 spec->automute_speaker = !spec->cur_mux[adc_idx];
316 call_update_outputs(codec);
319 if (spec->dyn_adc_switch) {
320 alc_dyn_adc_pcm_resetup(codec, idx);
321 adc_idx = spec->dyn_adc_idx[idx];
324 nid = spec->capsrc_nids ?
325 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
328 num_conns = snd_hda_get_conn_list(codec, nid, NULL);
332 type = get_wcaps_type(get_wcaps(codec, nid));
333 if (type == AC_WID_AUD_MIX) {
334 /* Matrix-mixer style (e.g. ALC882) */
335 int active = imux->items[idx].index;
336 for (i = 0; i < num_conns; i++) {
337 unsigned int v = (i == active) ? 0 : HDA_AMP_MUTE;
338 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, i,
342 /* MUX style (e.g. ALC880) */
343 snd_hda_codec_write_cache(codec, nid, 0,
344 AC_VERB_SET_CONNECT_SEL,
345 imux->items[idx].index);
350 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
351 struct snd_ctl_elem_value *ucontrol)
353 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
354 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
355 return alc_mux_select(codec, adc_idx,
356 ucontrol->value.enumerated.item[0], false);
360 * set up the input pin config (depending on the given auto-pin type)
362 static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
365 unsigned int val = PIN_IN;
367 if (auto_pin_type == AUTO_PIN_MIC) {
370 oldval = snd_hda_codec_read(codec, nid, 0,
371 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
372 pincap = snd_hda_query_pin_caps(codec, nid);
373 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
374 /* if the default pin setup is vref50, we give it priority */
375 if ((pincap & AC_PINCAP_VREF_80) && oldval != PIN_VREF50)
377 else if (pincap & AC_PINCAP_VREF_50)
379 else if (pincap & AC_PINCAP_VREF_100)
381 else if (pincap & AC_PINCAP_VREF_GRD)
384 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val);
388 * Append the given mixer and verb elements for the later use
389 * The mixer array is referred in build_controls(), and init_verbs are
392 static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
394 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
396 spec->mixers[spec->num_mixers++] = mix;
399 static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
401 if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
403 spec->init_verbs[spec->num_init_verbs++] = verb;
407 * GPIO setup tables, used in initialization
409 /* Enable GPIO mask and set output */
410 static const struct hda_verb alc_gpio1_init_verbs[] = {
411 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
412 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
413 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
417 static const struct hda_verb alc_gpio2_init_verbs[] = {
418 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
419 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
420 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
424 static const struct hda_verb alc_gpio3_init_verbs[] = {
425 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
426 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
427 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
432 * Fix hardware PLL issue
433 * On some codecs, the analog PLL gating control must be off while
434 * the default value is 1.
436 static void alc_fix_pll(struct hda_codec *codec)
438 struct alc_spec *spec = codec->spec;
443 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
445 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
446 AC_VERB_GET_PROC_COEF, 0);
447 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
449 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
450 val & ~(1 << spec->pll_coef_bit));
453 static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
454 unsigned int coef_idx, unsigned int coef_bit)
456 struct alc_spec *spec = codec->spec;
458 spec->pll_coef_idx = coef_idx;
459 spec->pll_coef_bit = coef_bit;
464 * Jack detections for HP auto-mute and mic-switch
467 /* check each pin in the given array; returns true if any of them is plugged */
468 static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
472 for (i = 0; i < num_pins; i++) {
473 hda_nid_t nid = pins[i];
476 present |= snd_hda_jack_detect(codec, nid);
481 /* standard HP/line-out auto-mute helper */
482 static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
483 bool mute, bool hp_out)
485 struct alc_spec *spec = codec->spec;
486 unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0;
487 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
490 for (i = 0; i < num_pins; i++) {
491 hda_nid_t nid = pins[i];
494 switch (spec->automute_mode) {
495 case ALC_AUTOMUTE_PIN:
496 snd_hda_codec_write(codec, nid, 0,
497 AC_VERB_SET_PIN_WIDGET_CONTROL,
500 case ALC_AUTOMUTE_AMP:
501 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
502 HDA_AMP_MUTE, mute_bits);
504 case ALC_AUTOMUTE_MIXER:
505 nid = spec->automute_mixer_nid[i];
508 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
509 HDA_AMP_MUTE, mute_bits);
510 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1,
511 HDA_AMP_MUTE, mute_bits);
517 /* Toggle outputs muting */
518 static void update_outputs(struct hda_codec *codec)
520 struct alc_spec *spec = codec->spec;
523 /* Control HP pins/amps depending on master_mute state;
524 * in general, HP pins/amps control should be enabled in all cases,
525 * but currently set only for master_mute, just to be safe
527 if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */
528 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
529 spec->autocfg.hp_pins, spec->master_mute, true);
531 if (!spec->automute_speaker)
534 on = spec->hp_jack_present | spec->line_jack_present;
535 on |= spec->master_mute;
536 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
537 spec->autocfg.speaker_pins, on, false);
539 /* toggle line-out mutes if needed, too */
540 /* if LO is a copy of either HP or Speaker, don't need to handle it */
541 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
542 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
544 if (!spec->automute_lo)
547 on = spec->hp_jack_present;
548 on |= spec->master_mute;
549 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
550 spec->autocfg.line_out_pins, on, false);
553 static void call_update_outputs(struct hda_codec *codec)
555 struct alc_spec *spec = codec->spec;
556 if (spec->automute_hook)
557 spec->automute_hook(codec);
559 update_outputs(codec);
562 /* standard HP-automute helper */
563 static void alc_hp_automute(struct hda_codec *codec)
565 struct alc_spec *spec = codec->spec;
567 spec->hp_jack_present =
568 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
569 spec->autocfg.hp_pins);
570 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
572 call_update_outputs(codec);
575 /* standard line-out-automute helper */
576 static void alc_line_automute(struct hda_codec *codec)
578 struct alc_spec *spec = codec->spec;
580 /* check LO jack only when it's different from HP */
581 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
584 spec->line_jack_present =
585 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
586 spec->autocfg.line_out_pins);
587 if (!spec->automute_speaker || !spec->detect_lo)
589 call_update_outputs(codec);
592 #define get_connection_index(codec, mux, nid) \
593 snd_hda_get_conn_index(codec, mux, nid, 0)
595 /* standard mic auto-switch helper */
596 static void alc_mic_automute(struct hda_codec *codec)
598 struct alc_spec *spec = codec->spec;
599 hda_nid_t *pins = spec->imux_pins;
601 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
603 if (snd_BUG_ON(!spec->adc_nids))
605 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
608 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
609 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
610 else if (spec->dock_mic_idx >= 0 &&
611 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
612 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
614 alc_mux_select(codec, 0, spec->int_mic_idx, false);
617 /* unsolicited event for HP jack sensing */
618 static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
620 struct alc_spec *spec = codec->spec;
621 if (codec->vendor_id == 0x10ec0880)
625 if (spec->use_jack_tbl)
626 res = snd_hda_jack_get_action(codec, res);
629 alc_hp_automute(codec);
631 case ALC_FRONT_EVENT:
632 alc_line_automute(codec);
635 alc_mic_automute(codec);
638 snd_hda_jack_report_sync(codec);
641 /* call init functions of standard auto-mute helpers */
642 static void alc_inithook(struct hda_codec *codec)
644 alc_hp_automute(codec);
645 alc_line_automute(codec);
646 alc_mic_automute(codec);
649 /* additional initialization for ALC888 variants */
650 static void alc888_coef_init(struct hda_codec *codec)
654 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
655 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
656 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
657 if ((tmp & 0xf0) == 0x20)
659 snd_hda_codec_read(codec, 0x20, 0,
660 AC_VERB_SET_PROC_COEF, 0x830);
663 snd_hda_codec_read(codec, 0x20, 0,
664 AC_VERB_SET_PROC_COEF, 0x3030);
667 /* additional initialization for ALC889 variants */
668 static void alc889_coef_init(struct hda_codec *codec)
672 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
673 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
674 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
675 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
678 /* turn on/off EAPD control (only if available) */
679 static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
681 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
683 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
684 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
688 /* turn on/off EAPD controls of the codec */
689 static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
691 /* We currently only handle front, HP */
692 static hda_nid_t pins[] = {
693 0x0f, 0x10, 0x14, 0x15, 0
696 for (p = pins; *p; p++)
697 set_eapd(codec, *p, on);
700 /* generic shutup callback;
701 * just turning off EPAD and a little pause for avoiding pop-noise
703 static void alc_eapd_shutup(struct hda_codec *codec)
705 alc_auto_setup_eapd(codec, false);
709 /* generic EAPD initialization */
710 static void alc_auto_init_amp(struct hda_codec *codec, int type)
714 alc_auto_setup_eapd(codec, true);
717 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
720 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
723 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
725 case ALC_INIT_DEFAULT:
726 switch (codec->vendor_id) {
728 snd_hda_codec_write(codec, 0x1a, 0,
729 AC_VERB_SET_COEF_INDEX, 7);
730 tmp = snd_hda_codec_read(codec, 0x1a, 0,
731 AC_VERB_GET_PROC_COEF, 0);
732 snd_hda_codec_write(codec, 0x1a, 0,
733 AC_VERB_SET_COEF_INDEX, 7);
734 snd_hda_codec_write(codec, 0x1a, 0,
735 AC_VERB_SET_PROC_COEF,
744 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
745 alc889_coef_init(codec);
748 alc888_coef_init(codec);
750 #if 0 /* XXX: This may cause the silent output on speaker on some machines */
753 snd_hda_codec_write(codec, 0x20, 0,
754 AC_VERB_SET_COEF_INDEX, 7);
755 tmp = snd_hda_codec_read(codec, 0x20, 0,
756 AC_VERB_GET_PROC_COEF, 0);
757 snd_hda_codec_write(codec, 0x20, 0,
758 AC_VERB_SET_COEF_INDEX, 7);
759 snd_hda_codec_write(codec, 0x20, 0,
760 AC_VERB_SET_PROC_COEF,
770 * Auto-Mute mode mixer enum support
772 static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
773 struct snd_ctl_elem_info *uinfo)
775 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
776 struct alc_spec *spec = codec->spec;
777 static const char * const texts2[] = {
778 "Disabled", "Enabled"
780 static const char * const texts3[] = {
781 "Disabled", "Speaker Only", "Line-Out+Speaker"
783 const char * const *texts;
785 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
787 if (spec->automute_speaker_possible && spec->automute_lo_possible) {
788 uinfo->value.enumerated.items = 3;
791 uinfo->value.enumerated.items = 2;
794 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
795 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
796 strcpy(uinfo->value.enumerated.name,
797 texts[uinfo->value.enumerated.item]);
801 static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
802 struct snd_ctl_elem_value *ucontrol)
804 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
805 struct alc_spec *spec = codec->spec;
806 unsigned int val = 0;
807 if (spec->automute_speaker)
809 if (spec->automute_lo)
812 ucontrol->value.enumerated.item[0] = val;
816 static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
817 struct snd_ctl_elem_value *ucontrol)
819 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
820 struct alc_spec *spec = codec->spec;
822 switch (ucontrol->value.enumerated.item[0]) {
824 if (!spec->automute_speaker && !spec->automute_lo)
826 spec->automute_speaker = 0;
827 spec->automute_lo = 0;
830 if (spec->automute_speaker_possible) {
831 if (!spec->automute_lo && spec->automute_speaker)
833 spec->automute_speaker = 1;
834 spec->automute_lo = 0;
835 } else if (spec->automute_lo_possible) {
836 if (spec->automute_lo)
838 spec->automute_lo = 1;
843 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
845 if (spec->automute_speaker && spec->automute_lo)
847 spec->automute_speaker = 1;
848 spec->automute_lo = 1;
853 call_update_outputs(codec);
857 static const struct snd_kcontrol_new alc_automute_mode_enum = {
858 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
859 .name = "Auto-Mute Mode",
860 .info = alc_automute_mode_info,
861 .get = alc_automute_mode_get,
862 .put = alc_automute_mode_put,
865 static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec)
867 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
868 return snd_array_new(&spec->kctls);
871 static int alc_add_automute_mode_enum(struct hda_codec *codec)
873 struct alc_spec *spec = codec->spec;
874 struct snd_kcontrol_new *knew;
876 knew = alc_kcontrol_new(spec);
879 *knew = alc_automute_mode_enum;
880 knew->name = kstrdup("Auto-Mute Mode", GFP_KERNEL);
887 * Check the availability of HP/line-out auto-mute;
888 * Set up appropriately if really supported
890 static void alc_init_automute(struct hda_codec *codec)
892 struct alc_spec *spec = codec->spec;
893 struct auto_pin_cfg *cfg = &spec->autocfg;
899 if (cfg->line_out_pins[0])
901 if (cfg->speaker_pins[0])
903 if (present < 2) /* need two different output types */
906 if (!cfg->speaker_pins[0] &&
907 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
908 memcpy(cfg->speaker_pins, cfg->line_out_pins,
909 sizeof(cfg->speaker_pins));
910 cfg->speaker_outs = cfg->line_outs;
913 if (!cfg->hp_pins[0] &&
914 cfg->line_out_type == AUTO_PIN_HP_OUT) {
915 memcpy(cfg->hp_pins, cfg->line_out_pins,
916 sizeof(cfg->hp_pins));
917 cfg->hp_outs = cfg->line_outs;
920 spec->automute_mode = ALC_AUTOMUTE_PIN;
922 for (i = 0; i < cfg->hp_outs; i++) {
923 hda_nid_t nid = cfg->hp_pins[i];
924 if (!is_jack_detectable(codec, nid))
926 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
928 snd_hda_jack_detect_enable(codec, nid, ALC_HP_EVENT);
932 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
933 if (cfg->speaker_outs)
934 for (i = 0; i < cfg->line_outs; i++) {
935 hda_nid_t nid = cfg->line_out_pins[i];
936 if (!is_jack_detectable(codec, nid))
938 snd_printdd("realtek: Enable Line-Out "
939 "auto-muting on NID 0x%x\n", nid);
940 snd_hda_jack_detect_enable(codec, nid,
944 spec->automute_lo_possible = spec->detect_hp;
947 spec->automute_speaker_possible = cfg->speaker_outs &&
948 (spec->detect_hp || spec->detect_lo);
950 spec->automute_lo = spec->automute_lo_possible;
951 spec->automute_speaker = spec->automute_speaker_possible;
953 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
954 /* create a control for automute mode */
955 alc_add_automute_mode_enum(codec);
956 spec->unsol_event = alc_sku_unsol_event;
960 /* return the position of NID in the list, or -1 if not found */
961 static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
964 for (i = 0; i < nums; i++)
970 /* check whether dynamic ADC-switching is available */
971 static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
973 struct alc_spec *spec = codec->spec;
974 struct hda_input_mux *imux = &spec->private_imux[0];
978 if (imux != spec->input_mux) /* no dynamic imux? */
981 for (n = 0; n < spec->num_adc_nids; n++) {
982 cap = spec->private_capsrc_nids[n];
983 for (i = 0; i < imux->num_items; i++) {
984 pin = spec->imux_pins[i];
987 if (get_connection_index(codec, cap, pin) < 0)
990 if (i >= imux->num_items)
991 return true; /* no ADC-switch is needed */
994 for (i = 0; i < imux->num_items; i++) {
995 pin = spec->imux_pins[i];
996 for (n = 0; n < spec->num_adc_nids; n++) {
997 cap = spec->private_capsrc_nids[n];
998 idx = get_connection_index(codec, cap, pin);
1000 imux->items[i].index = idx;
1001 spec->dyn_adc_idx[i] = n;
1007 snd_printdd("realtek: enabling ADC switching\n");
1008 spec->dyn_adc_switch = 1;
1012 /* rebuild imux for matching with the given auto-mic pins (if not yet) */
1013 static bool alc_rebuild_imux_for_auto_mic(struct hda_codec *codec)
1015 struct alc_spec *spec = codec->spec;
1016 struct hda_input_mux *imux;
1017 static char * const texts[3] = {
1018 "Mic", "Internal Mic", "Dock Mic"
1022 if (!spec->auto_mic)
1024 imux = &spec->private_imux[0];
1025 if (spec->input_mux == imux)
1027 spec->imux_pins[0] = spec->ext_mic_pin;
1028 spec->imux_pins[1] = spec->int_mic_pin;
1029 spec->imux_pins[2] = spec->dock_mic_pin;
1030 for (i = 0; i < 3; i++) {
1031 strcpy(imux->items[i].label, texts[i]);
1032 if (spec->imux_pins[i])
1033 imux->num_items = i + 1;
1035 spec->num_mux_defs = 1;
1036 spec->input_mux = imux;
1040 /* check whether all auto-mic pins are valid; setup indices if OK */
1041 static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1043 struct alc_spec *spec = codec->spec;
1044 const struct hda_input_mux *imux;
1046 if (!spec->auto_mic)
1048 if (spec->auto_mic_valid_imux)
1049 return true; /* already checked */
1051 /* fill up imux indices */
1052 if (!alc_check_dyn_adc_switch(codec)) {
1057 imux = spec->input_mux;
1058 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1059 spec->imux_pins, imux->num_items);
1060 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1061 spec->imux_pins, imux->num_items);
1062 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1063 spec->imux_pins, imux->num_items);
1064 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1066 return false; /* no corresponding imux */
1069 snd_hda_jack_detect_enable(codec, spec->ext_mic_pin, ALC_MIC_EVENT);
1070 if (spec->dock_mic_pin)
1071 snd_hda_jack_detect_enable(codec, spec->dock_mic_pin,
1074 spec->auto_mic_valid_imux = 1;
1080 * Check the availability of auto-mic switch;
1081 * Set up if really supported
1083 static void alc_init_auto_mic(struct hda_codec *codec)
1085 struct alc_spec *spec = codec->spec;
1086 struct auto_pin_cfg *cfg = &spec->autocfg;
1087 hda_nid_t fixed, ext, dock;
1090 if (spec->shared_mic_hp)
1091 return; /* no auto-mic for the shared I/O */
1093 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1095 fixed = ext = dock = 0;
1096 for (i = 0; i < cfg->num_inputs; i++) {
1097 hda_nid_t nid = cfg->inputs[i].pin;
1098 unsigned int defcfg;
1099 defcfg = snd_hda_codec_get_pincfg(codec, nid);
1100 switch (snd_hda_get_input_pin_attr(defcfg)) {
1101 case INPUT_PIN_ATTR_INT:
1103 return; /* already occupied */
1104 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1105 return; /* invalid type */
1108 case INPUT_PIN_ATTR_UNUSED:
1109 return; /* invalid entry */
1110 case INPUT_PIN_ATTR_DOCK:
1112 return; /* already occupied */
1113 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1114 return; /* invalid type */
1119 return; /* already occupied */
1120 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1121 return; /* invalid type */
1132 if (!is_jack_detectable(codec, ext))
1133 return; /* no unsol support */
1134 if (dock && !is_jack_detectable(codec, dock))
1135 return; /* no unsol support */
1137 /* check imux indices */
1138 spec->ext_mic_pin = ext;
1139 spec->int_mic_pin = fixed;
1140 spec->dock_mic_pin = dock;
1143 if (!alc_auto_mic_check_imux(codec))
1146 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1148 spec->unsol_event = alc_sku_unsol_event;
1151 /* check the availabilities of auto-mute and auto-mic switches */
1152 static void alc_auto_check_switches(struct hda_codec *codec)
1154 alc_init_automute(codec);
1155 alc_init_auto_mic(codec);
1159 * Realtek SSID verification
1162 /* Could be any non-zero and even value. When used as fixup, tells
1163 * the driver to ignore any present sku defines.
1165 #define ALC_FIXUP_SKU_IGNORE (2)
1167 static int alc_auto_parse_customize_define(struct hda_codec *codec)
1169 unsigned int ass, tmp, i;
1171 struct alc_spec *spec = codec->spec;
1173 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1175 if (spec->cdefine.fixup) {
1176 ass = spec->cdefine.sku_cfg;
1177 if (ass == ALC_FIXUP_SKU_IGNORE)
1182 ass = codec->subsystem_id & 0xffff;
1183 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
1187 if (codec->vendor_id == 0x10ec0260)
1189 ass = snd_hda_codec_get_pincfg(codec, nid);
1192 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1193 codec->chip_name, ass);
1199 for (i = 1; i < 16; i++) {
1203 if (((ass >> 16) & 0xf) != tmp)
1206 spec->cdefine.port_connectivity = ass >> 30;
1207 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1208 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1209 spec->cdefine.customization = ass >> 8;
1211 spec->cdefine.sku_cfg = ass;
1212 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1213 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1214 spec->cdefine.swap = (ass & 0x2) >> 1;
1215 spec->cdefine.override = ass & 0x1;
1217 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1218 nid, spec->cdefine.sku_cfg);
1219 snd_printd("SKU: port_connectivity=0x%x\n",
1220 spec->cdefine.port_connectivity);
1221 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1222 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1223 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1224 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1225 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1226 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1227 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1232 /* return true if the given NID is found in the list */
1233 static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1235 return find_idx_in_nid_list(nid, list, nums) >= 0;
1238 /* check subsystem ID and set up device-specific initialization;
1239 * return 1 if initialized, 0 if invalid SSID
1241 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1242 * 31 ~ 16 : Manufacture ID
1244 * 7 ~ 0 : Assembly ID
1245 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1247 static int alc_subsystem_id(struct hda_codec *codec,
1248 hda_nid_t porta, hda_nid_t porte,
1249 hda_nid_t portd, hda_nid_t porti)
1251 unsigned int ass, tmp, i;
1253 struct alc_spec *spec = codec->spec;
1255 if (spec->cdefine.fixup) {
1256 ass = spec->cdefine.sku_cfg;
1257 if (ass == ALC_FIXUP_SKU_IGNORE)
1262 ass = codec->subsystem_id & 0xffff;
1263 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1266 /* invalid SSID, check the special NID pin defcfg instead */
1268 * 31~30 : port connectivity
1271 * 19~16 : Check sum (15:1)
1276 if (codec->vendor_id == 0x10ec0260)
1278 ass = snd_hda_codec_get_pincfg(codec, nid);
1279 snd_printd("realtek: No valid SSID, "
1280 "checking pincfg 0x%08x for NID 0x%x\n",
1284 if ((ass >> 30) != 1) /* no physical connection */
1289 for (i = 1; i < 16; i++) {
1293 if (((ass >> 16) & 0xf) != tmp)
1296 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1297 ass & 0xffff, codec->vendor_id);
1301 * 2 : 0 --> Desktop, 1 --> Laptop
1302 * 3~5 : External Amplifier control
1305 tmp = (ass & 0x38) >> 3; /* external Amp control */
1308 spec->init_amp = ALC_INIT_GPIO1;
1311 spec->init_amp = ALC_INIT_GPIO2;
1314 spec->init_amp = ALC_INIT_GPIO3;
1318 spec->init_amp = ALC_INIT_DEFAULT;
1322 /* is laptop or Desktop and enable the function "Mute internal speaker
1323 * when the external headphone out jack is plugged"
1325 if (!(ass & 0x8000))
1328 * 10~8 : Jack location
1329 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1331 * 15 : 1 --> enable the function "Mute internal speaker
1332 * when the external headphone out jack is plugged"
1334 if (!spec->autocfg.hp_pins[0] &&
1335 !(spec->autocfg.line_out_pins[0] &&
1336 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
1338 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1349 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1350 spec->autocfg.line_outs))
1352 spec->autocfg.hp_pins[0] = nid;
1357 /* Check the validity of ALC subsystem-id
1358 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1359 static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
1361 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
1362 struct alc_spec *spec = codec->spec;
1363 snd_printd("realtek: "
1364 "Enable default setup for auto mode as fallback\n");
1365 spec->init_amp = ALC_INIT_DEFAULT;
1370 * Fix-up pin default configurations and add default verbs
1378 struct alc_model_fixup {
1389 const struct alc_pincfg *pins;
1390 const struct hda_verb *verbs;
1391 void (*func)(struct hda_codec *codec,
1392 const struct alc_fixup *fix,
1406 ALC_FIXUP_ACT_PRE_PROBE,
1407 ALC_FIXUP_ACT_PROBE,
1411 static void alc_apply_fixup(struct hda_codec *codec, int action)
1413 struct alc_spec *spec = codec->spec;
1414 int id = spec->fixup_id;
1415 #ifdef CONFIG_SND_DEBUG_VERBOSE
1416 const char *modelname = spec->fixup_name;
1420 if (!spec->fixup_list)
1424 const struct alc_fixup *fix = spec->fixup_list + id;
1425 const struct alc_pincfg *cfg;
1427 switch (fix->type) {
1429 if (action != ALC_FIXUP_ACT_PRE_PROBE || !fix->v.sku)
1431 snd_printdd(KERN_INFO "hda_codec: %s: "
1432 "Apply sku override for %s\n",
1433 codec->chip_name, modelname);
1434 spec->cdefine.sku_cfg = fix->v.sku;
1435 spec->cdefine.fixup = 1;
1437 case ALC_FIXUP_PINS:
1439 if (action != ALC_FIXUP_ACT_PRE_PROBE || !cfg)
1441 snd_printdd(KERN_INFO "hda_codec: %s: "
1442 "Apply pincfg for %s\n",
1443 codec->chip_name, modelname);
1444 for (; cfg->nid; cfg++)
1445 snd_hda_codec_set_pincfg(codec, cfg->nid,
1448 case ALC_FIXUP_VERBS:
1449 if (action != ALC_FIXUP_ACT_PROBE || !fix->v.verbs)
1451 snd_printdd(KERN_INFO "hda_codec: %s: "
1452 "Apply fix-verbs for %s\n",
1453 codec->chip_name, modelname);
1454 add_verb(codec->spec, fix->v.verbs);
1456 case ALC_FIXUP_FUNC:
1459 snd_printdd(KERN_INFO "hda_codec: %s: "
1460 "Apply fix-func for %s\n",
1461 codec->chip_name, modelname);
1462 fix->v.func(codec, fix, action);
1465 snd_printk(KERN_ERR "hda_codec: %s: "
1466 "Invalid fixup type %d\n",
1467 codec->chip_name, fix->type);
1478 static void alc_pick_fixup(struct hda_codec *codec,
1479 const struct alc_model_fixup *models,
1480 const struct snd_pci_quirk *quirk,
1481 const struct alc_fixup *fixlist)
1483 struct alc_spec *spec = codec->spec;
1484 const struct snd_pci_quirk *q;
1486 const char *name = NULL;
1488 if (codec->modelname && models) {
1489 while (models->name) {
1490 if (!strcmp(codec->modelname, models->name)) {
1492 name = models->name;
1499 q = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1502 #ifdef CONFIG_SND_DEBUG_VERBOSE
1508 for (q = quirk; q->subvendor; q++) {
1509 unsigned int vendorid =
1510 q->subdevice | (q->subvendor << 16);
1511 if (vendorid == codec->subsystem_id) {
1513 #ifdef CONFIG_SND_DEBUG_VERBOSE
1521 spec->fixup_id = id;
1523 spec->fixup_list = fixlist;
1524 spec->fixup_name = name;
1529 * COEF access helper functions
1531 static int alc_read_coef_idx(struct hda_codec *codec,
1532 unsigned int coef_idx)
1535 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1537 val = snd_hda_codec_read(codec, 0x20, 0,
1538 AC_VERB_GET_PROC_COEF, 0);
1542 static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1543 unsigned int coef_val)
1545 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1547 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1551 /* a special bypass for COEF 0; read the cached value at the second time */
1552 static unsigned int alc_get_coef0(struct hda_codec *codec)
1554 struct alc_spec *spec = codec->spec;
1556 spec->coef0 = alc_read_coef_idx(codec, 0);
1561 * Digital I/O handling
1564 /* set right pin controls for digital I/O */
1565 static void alc_auto_init_digital(struct hda_codec *codec)
1567 struct alc_spec *spec = codec->spec;
1571 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1572 pin = spec->autocfg.dig_out_pins[i];
1575 snd_hda_codec_write(codec, pin, 0,
1576 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
1578 dac = spec->multiout.dig_out_nid;
1580 dac = spec->slave_dig_outs[i - 1];
1581 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
1583 snd_hda_codec_write(codec, dac, 0,
1584 AC_VERB_SET_AMP_GAIN_MUTE,
1587 pin = spec->autocfg.dig_in_pin;
1589 snd_hda_codec_write(codec, pin, 0,
1590 AC_VERB_SET_PIN_WIDGET_CONTROL,
1594 /* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1595 static void alc_auto_parse_digital(struct hda_codec *codec)
1597 struct alc_spec *spec = codec->spec;
1601 /* support multiple SPDIFs; the secondary is set up as a slave */
1603 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1605 err = snd_hda_get_connections(codec,
1606 spec->autocfg.dig_out_pins[i],
1607 conn, ARRAY_SIZE(conn));
1610 dig_nid = conn[0]; /* assume the first element is audio-out */
1612 spec->multiout.dig_out_nid = dig_nid;
1613 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1615 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
1616 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
1618 spec->slave_dig_outs[nums - 1] = dig_nid;
1623 if (spec->autocfg.dig_in_pin) {
1624 dig_nid = codec->start_nid;
1625 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1626 unsigned int wcaps = get_wcaps(codec, dig_nid);
1627 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1629 if (!(wcaps & AC_WCAP_DIGITAL))
1631 if (!(wcaps & AC_WCAP_CONN_LIST))
1633 err = get_connection_index(codec, dig_nid,
1634 spec->autocfg.dig_in_pin);
1636 spec->dig_in_nid = dig_nid;
1644 * capture mixer elements
1646 static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1647 struct snd_ctl_elem_info *uinfo)
1649 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1650 struct alc_spec *spec = codec->spec;
1654 mutex_lock(&codec->control_mutex);
1655 if (spec->vol_in_capsrc)
1656 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1658 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1659 kcontrol->private_value = val;
1660 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
1661 mutex_unlock(&codec->control_mutex);
1665 static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1666 unsigned int size, unsigned int __user *tlv)
1668 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1669 struct alc_spec *spec = codec->spec;
1673 mutex_lock(&codec->control_mutex);
1674 if (spec->vol_in_capsrc)
1675 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1677 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1678 kcontrol->private_value = val;
1679 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
1680 mutex_unlock(&codec->control_mutex);
1684 typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1685 struct snd_ctl_elem_value *ucontrol);
1687 static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1688 struct snd_ctl_elem_value *ucontrol,
1689 getput_call_t func, bool check_adc_switch)
1691 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1692 struct alc_spec *spec = codec->spec;
1695 mutex_lock(&codec->control_mutex);
1696 if (check_adc_switch && spec->dyn_adc_switch) {
1697 for (i = 0; i < spec->num_adc_nids; i++) {
1698 kcontrol->private_value =
1699 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1701 err = func(kcontrol, ucontrol);
1706 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1707 if (spec->vol_in_capsrc)
1708 kcontrol->private_value =
1709 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1712 kcontrol->private_value =
1713 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1715 err = func(kcontrol, ucontrol);
1718 mutex_unlock(&codec->control_mutex);
1722 static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1723 struct snd_ctl_elem_value *ucontrol)
1725 return alc_cap_getput_caller(kcontrol, ucontrol,
1726 snd_hda_mixer_amp_volume_get, false);
1729 static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1730 struct snd_ctl_elem_value *ucontrol)
1732 return alc_cap_getput_caller(kcontrol, ucontrol,
1733 snd_hda_mixer_amp_volume_put, true);
1736 /* capture mixer elements */
1737 #define alc_cap_sw_info snd_ctl_boolean_stereo_info
1739 static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1740 struct snd_ctl_elem_value *ucontrol)
1742 return alc_cap_getput_caller(kcontrol, ucontrol,
1743 snd_hda_mixer_amp_switch_get, false);
1746 static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1747 struct snd_ctl_elem_value *ucontrol)
1749 return alc_cap_getput_caller(kcontrol, ucontrol,
1750 snd_hda_mixer_amp_switch_put, true);
1753 #define _DEFINE_CAPMIX(num) \
1755 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1756 .name = "Capture Switch", \
1757 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1759 .info = alc_cap_sw_info, \
1760 .get = alc_cap_sw_get, \
1761 .put = alc_cap_sw_put, \
1764 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1765 .name = "Capture Volume", \
1766 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1767 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1768 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1770 .info = alc_cap_vol_info, \
1771 .get = alc_cap_vol_get, \
1772 .put = alc_cap_vol_put, \
1773 .tlv = { .c = alc_cap_vol_tlv }, \
1776 #define _DEFINE_CAPSRC(num) \
1778 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1779 /* .name = "Capture Source", */ \
1780 .name = "Input Source", \
1782 .info = alc_mux_enum_info, \
1783 .get = alc_mux_enum_get, \
1784 .put = alc_mux_enum_put, \
1787 #define DEFINE_CAPMIX(num) \
1788 static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
1789 _DEFINE_CAPMIX(num), \
1790 _DEFINE_CAPSRC(num), \
1794 #define DEFINE_CAPMIX_NOSRC(num) \
1795 static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
1796 _DEFINE_CAPMIX(num), \
1800 /* up to three ADCs */
1804 DEFINE_CAPMIX_NOSRC(1);
1805 DEFINE_CAPMIX_NOSRC(2);
1806 DEFINE_CAPMIX_NOSRC(3);
1809 * virtual master controls
1813 * slave controls for virtual master
1815 static const char * const alc_slave_vols[] = {
1816 "Front Playback Volume",
1817 "Surround Playback Volume",
1818 "Center Playback Volume",
1819 "LFE Playback Volume",
1820 "Side Playback Volume",
1821 "Headphone Playback Volume",
1822 "Speaker Playback Volume",
1823 "Mono Playback Volume",
1824 "Line-Out Playback Volume",
1825 "PCM Playback Volume",
1829 static const char * const alc_slave_sws[] = {
1830 "Front Playback Switch",
1831 "Surround Playback Switch",
1832 "Center Playback Switch",
1833 "LFE Playback Switch",
1834 "Side Playback Switch",
1835 "Headphone Playback Switch",
1836 "Speaker Playback Switch",
1837 "Mono Playback Switch",
1838 "IEC958 Playback Switch",
1839 "Line-Out Playback Switch",
1840 "PCM Playback Switch",
1845 * build control elements
1848 #define NID_MAPPING (-1)
1850 #define SUBDEV_SPEAKER_ (0 << 6)
1851 #define SUBDEV_HP_ (1 << 6)
1852 #define SUBDEV_LINE_ (2 << 6)
1853 #define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1854 #define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1855 #define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1857 static void alc_free_kctls(struct hda_codec *codec);
1859 #ifdef CONFIG_SND_HDA_INPUT_BEEP
1860 /* additional beep mixers; the actual parameters are overwritten at build */
1861 static const struct snd_kcontrol_new alc_beep_mixer[] = {
1862 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
1863 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
1868 static int alc_build_controls(struct hda_codec *codec)
1870 struct alc_spec *spec = codec->spec;
1871 struct snd_kcontrol *kctl = NULL;
1872 const struct snd_kcontrol_new *knew;
1877 for (i = 0; i < spec->num_mixers; i++) {
1878 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1882 if (spec->cap_mixer) {
1883 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1887 if (spec->multiout.dig_out_nid) {
1888 err = snd_hda_create_spdif_out_ctls(codec,
1889 spec->multiout.dig_out_nid,
1890 spec->multiout.dig_out_nid);
1893 if (!spec->no_analog) {
1894 err = snd_hda_create_spdif_share_sw(codec,
1898 spec->multiout.share_spdif = 1;
1901 if (spec->dig_in_nid) {
1902 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1907 #ifdef CONFIG_SND_HDA_INPUT_BEEP
1908 /* create beep controls if needed */
1909 if (spec->beep_amp) {
1910 const struct snd_kcontrol_new *knew;
1911 for (knew = alc_beep_mixer; knew->name; knew++) {
1912 struct snd_kcontrol *kctl;
1913 kctl = snd_ctl_new1(knew, codec);
1916 kctl->private_value = spec->beep_amp;
1917 err = snd_hda_ctl_add(codec, 0, kctl);
1924 /* if we have no master control, let's create it */
1925 if (!spec->no_analog &&
1926 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1927 unsigned int vmaster_tlv[4];
1928 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
1929 HDA_OUTPUT, vmaster_tlv);
1930 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1931 vmaster_tlv, alc_slave_vols);
1935 if (!spec->no_analog &&
1936 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1937 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1938 NULL, alc_slave_sws);
1943 /* assign Capture Source enums to NID */
1944 if (spec->capsrc_nids || spec->adc_nids) {
1945 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
1947 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1948 for (i = 0; kctl && i < kctl->count; i++) {
1949 const hda_nid_t *nids = spec->capsrc_nids;
1951 nids = spec->adc_nids;
1952 err = snd_hda_add_nid(codec, kctl, i, nids[i]);
1957 if (spec->cap_mixer && spec->adc_nids) {
1958 const char *kname = kctl ? kctl->id.name : NULL;
1959 for (knew = spec->cap_mixer; knew->name; knew++) {
1960 if (kname && strcmp(knew->name, kname) == 0)
1962 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1963 for (i = 0; kctl && i < kctl->count; i++) {
1964 err = snd_hda_add_nid(codec, kctl, i,
1972 /* other nid->control mapping */
1973 for (i = 0; i < spec->num_mixers; i++) {
1974 for (knew = spec->mixers[i]; knew->name; knew++) {
1975 if (knew->iface != NID_MAPPING)
1977 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1980 u = knew->subdevice;
1981 for (j = 0; j < 4; j++, u >>= 8) {
1986 case SUBDEV_SPEAKER_:
1987 nid = spec->autocfg.speaker_pins[nid];
1990 nid = spec->autocfg.line_out_pins[nid];
1993 nid = spec->autocfg.hp_pins[nid];
1998 err = snd_hda_add_nid(codec, kctl, 0, nid);
2002 u = knew->private_value;
2003 for (j = 0; j < 4; j++, u >>= 8) {
2007 err = snd_hda_add_nid(codec, kctl, 0, nid);
2014 alc_free_kctls(codec); /* no longer needed */
2016 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
2028 static void alc_init_special_input_src(struct hda_codec *codec);
2030 static int alc_init(struct hda_codec *codec)
2032 struct alc_spec *spec = codec->spec;
2036 alc_auto_init_amp(codec, spec->init_amp);
2038 for (i = 0; i < spec->num_init_verbs; i++)
2039 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2040 alc_init_special_input_src(codec);
2042 if (spec->init_hook)
2043 spec->init_hook(codec);
2045 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2047 snd_hda_jack_report_sync(codec);
2049 hda_call_check_power_status(codec, 0x01);
2053 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2055 struct alc_spec *spec = codec->spec;
2057 if (spec->unsol_event)
2058 spec->unsol_event(codec, res);
2061 #ifdef CONFIG_SND_HDA_POWER_SAVE
2062 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2064 struct alc_spec *spec = codec->spec;
2065 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2070 * Analog playback callbacks
2072 static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
2073 struct hda_codec *codec,
2074 struct snd_pcm_substream *substream)
2076 struct alc_spec *spec = codec->spec;
2077 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2081 static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2082 struct hda_codec *codec,
2083 unsigned int stream_tag,
2084 unsigned int format,
2085 struct snd_pcm_substream *substream)
2087 struct alc_spec *spec = codec->spec;
2088 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2089 stream_tag, format, substream);
2092 static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2093 struct hda_codec *codec,
2094 struct snd_pcm_substream *substream)
2096 struct alc_spec *spec = codec->spec;
2097 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2103 static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2104 struct hda_codec *codec,
2105 struct snd_pcm_substream *substream)
2107 struct alc_spec *spec = codec->spec;
2108 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2111 static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2112 struct hda_codec *codec,
2113 unsigned int stream_tag,
2114 unsigned int format,
2115 struct snd_pcm_substream *substream)
2117 struct alc_spec *spec = codec->spec;
2118 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2119 stream_tag, format, substream);
2122 static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2123 struct hda_codec *codec,
2124 struct snd_pcm_substream *substream)
2126 struct alc_spec *spec = codec->spec;
2127 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2130 static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2131 struct hda_codec *codec,
2132 struct snd_pcm_substream *substream)
2134 struct alc_spec *spec = codec->spec;
2135 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2141 static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2142 struct hda_codec *codec,
2143 unsigned int stream_tag,
2144 unsigned int format,
2145 struct snd_pcm_substream *substream)
2147 struct alc_spec *spec = codec->spec;
2149 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
2150 stream_tag, 0, format);
2154 static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2155 struct hda_codec *codec,
2156 struct snd_pcm_substream *substream)
2158 struct alc_spec *spec = codec->spec;
2160 snd_hda_codec_cleanup_stream(codec,
2161 spec->adc_nids[substream->number + 1]);
2165 /* analog capture with dynamic dual-adc changes */
2166 static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2167 struct hda_codec *codec,
2168 unsigned int stream_tag,
2169 unsigned int format,
2170 struct snd_pcm_substream *substream)
2172 struct alc_spec *spec = codec->spec;
2173 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
2174 spec->cur_adc_stream_tag = stream_tag;
2175 spec->cur_adc_format = format;
2176 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2180 static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2181 struct hda_codec *codec,
2182 struct snd_pcm_substream *substream)
2184 struct alc_spec *spec = codec->spec;
2185 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2190 static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
2194 .nid = 0, /* fill later */
2196 .prepare = dyn_adc_capture_pcm_prepare,
2197 .cleanup = dyn_adc_capture_pcm_cleanup
2203 static const struct hda_pcm_stream alc_pcm_analog_playback = {
2207 /* NID is set in alc_build_pcms */
2209 .open = alc_playback_pcm_open,
2210 .prepare = alc_playback_pcm_prepare,
2211 .cleanup = alc_playback_pcm_cleanup
2215 static const struct hda_pcm_stream alc_pcm_analog_capture = {
2219 /* NID is set in alc_build_pcms */
2222 static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
2226 /* NID is set in alc_build_pcms */
2229 static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
2230 .substreams = 2, /* can be overridden */
2233 /* NID is set in alc_build_pcms */
2235 .prepare = alc_alt_capture_pcm_prepare,
2236 .cleanup = alc_alt_capture_pcm_cleanup
2240 static const struct hda_pcm_stream alc_pcm_digital_playback = {
2244 /* NID is set in alc_build_pcms */
2246 .open = alc_dig_playback_pcm_open,
2247 .close = alc_dig_playback_pcm_close,
2248 .prepare = alc_dig_playback_pcm_prepare,
2249 .cleanup = alc_dig_playback_pcm_cleanup
2253 static const struct hda_pcm_stream alc_pcm_digital_capture = {
2257 /* NID is set in alc_build_pcms */
2260 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
2261 static const struct hda_pcm_stream alc_pcm_null_stream = {
2267 static int alc_build_pcms(struct hda_codec *codec)
2269 struct alc_spec *spec = codec->spec;
2270 struct hda_pcm *info = spec->pcm_rec;
2271 const struct hda_pcm_stream *p;
2272 bool have_multi_adcs;
2275 codec->num_pcms = 1;
2276 codec->pcm_info = info;
2278 if (spec->no_analog)
2281 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2282 "%s Analog", codec->chip_name);
2283 info->name = spec->stream_name_analog;
2285 if (spec->multiout.dac_nids > 0) {
2286 p = spec->stream_analog_playback;
2288 p = &alc_pcm_analog_playback;
2289 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2290 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2292 if (spec->adc_nids) {
2293 p = spec->stream_analog_capture;
2295 if (spec->dyn_adc_switch)
2296 p = &dyn_adc_pcm_analog_capture;
2298 p = &alc_pcm_analog_capture;
2300 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2301 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2304 if (spec->channel_mode) {
2305 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2306 for (i = 0; i < spec->num_channel_mode; i++) {
2307 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2308 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2314 /* SPDIF for stream index #1 */
2315 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2316 snprintf(spec->stream_name_digital,
2317 sizeof(spec->stream_name_digital),
2318 "%s Digital", codec->chip_name);
2319 codec->num_pcms = 2;
2320 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
2321 info = spec->pcm_rec + 1;
2322 info->name = spec->stream_name_digital;
2323 if (spec->dig_out_type)
2324 info->pcm_type = spec->dig_out_type;
2326 info->pcm_type = HDA_PCM_TYPE_SPDIF;
2327 if (spec->multiout.dig_out_nid) {
2328 p = spec->stream_digital_playback;
2330 p = &alc_pcm_digital_playback;
2331 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2332 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2334 if (spec->dig_in_nid) {
2335 p = spec->stream_digital_capture;
2337 p = &alc_pcm_digital_capture;
2338 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2339 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2341 /* FIXME: do we need this for all Realtek codec models? */
2342 codec->spdif_status_reset = 1;
2345 if (spec->no_analog)
2348 /* If the use of more than one ADC is requested for the current
2349 * model, configure a second analog capture-only PCM.
2351 have_multi_adcs = (spec->num_adc_nids > 1) &&
2352 !spec->dyn_adc_switch && !spec->auto_mic &&
2353 (!spec->input_mux || spec->input_mux->num_items > 1);
2354 /* Additional Analaog capture for index #2 */
2355 if (spec->alt_dac_nid || have_multi_adcs) {
2356 codec->num_pcms = 3;
2357 info = spec->pcm_rec + 2;
2358 info->name = spec->stream_name_analog;
2359 if (spec->alt_dac_nid) {
2360 p = spec->stream_analog_alt_playback;
2362 p = &alc_pcm_analog_alt_playback;
2363 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2364 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2367 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2368 alc_pcm_null_stream;
2369 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2371 if (have_multi_adcs) {
2372 p = spec->stream_analog_alt_capture;
2374 p = &alc_pcm_analog_alt_capture;
2375 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2376 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2378 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2379 spec->num_adc_nids - 1;
2381 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2382 alc_pcm_null_stream;
2383 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
2390 static inline void alc_shutup(struct hda_codec *codec)
2392 struct alc_spec *spec = codec->spec;
2394 if (spec && spec->shutup)
2395 spec->shutup(codec);
2396 snd_hda_shutup_pins(codec);
2399 static void alc_free_kctls(struct hda_codec *codec)
2401 struct alc_spec *spec = codec->spec;
2403 if (spec->kctls.list) {
2404 struct snd_kcontrol_new *kctl = spec->kctls.list;
2406 for (i = 0; i < spec->kctls.used; i++)
2407 kfree(kctl[i].name);
2409 snd_array_free(&spec->kctls);
2412 static void alc_free_bind_ctls(struct hda_codec *codec)
2414 struct alc_spec *spec = codec->spec;
2415 if (spec->bind_ctls.list) {
2416 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2418 for (i = 0; i < spec->bind_ctls.used; i++)
2421 snd_array_free(&spec->bind_ctls);
2424 static void alc_free(struct hda_codec *codec)
2426 struct alc_spec *spec = codec->spec;
2432 alc_free_kctls(codec);
2433 alc_free_bind_ctls(codec);
2435 snd_hda_detach_beep_device(codec);
2438 #ifdef CONFIG_SND_HDA_POWER_SAVE
2439 static void alc_power_eapd(struct hda_codec *codec)
2441 alc_auto_setup_eapd(codec, false);
2444 static int alc_suspend(struct hda_codec *codec, pm_message_t state)
2446 struct alc_spec *spec = codec->spec;
2448 if (spec && spec->power_hook)
2449 spec->power_hook(codec);
2455 static int alc_resume(struct hda_codec *codec)
2457 msleep(150); /* to avoid pop noise */
2458 codec->patch_ops.init(codec);
2459 snd_hda_codec_resume_amp(codec);
2460 snd_hda_codec_resume_cache(codec);
2461 hda_call_check_power_status(codec, 0x01);
2468 static const struct hda_codec_ops alc_patch_ops = {
2469 .build_controls = alc_build_controls,
2470 .build_pcms = alc_build_pcms,
2473 .unsol_event = alc_unsol_event,
2475 .resume = alc_resume,
2477 #ifdef CONFIG_SND_HDA_POWER_SAVE
2478 .suspend = alc_suspend,
2479 .check_power_status = alc_check_power_status,
2481 .reboot_notify = alc_shutup,
2484 /* replace the codec chip_name with the given string */
2485 static int alc_codec_rename(struct hda_codec *codec, const char *name)
2487 kfree(codec->chip_name);
2488 codec->chip_name = kstrdup(name, GFP_KERNEL);
2489 if (!codec->chip_name) {
2497 * Rename codecs appropriately from COEF value
2499 struct alc_codec_rename_table {
2500 unsigned int vendor_id;
2501 unsigned short coef_mask;
2502 unsigned short coef_bits;
2506 static struct alc_codec_rename_table rename_tbl[] = {
2507 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2508 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2509 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2510 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2511 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2512 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2513 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
2514 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2515 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2516 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2517 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2518 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2519 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2520 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2521 { } /* terminator */
2524 static int alc_codec_rename_from_preset(struct hda_codec *codec)
2526 const struct alc_codec_rename_table *p;
2528 for (p = rename_tbl; p->vendor_id; p++) {
2529 if (p->vendor_id != codec->vendor_id)
2531 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
2532 return alc_codec_rename(codec, p->name);
2538 * Automatic parse of I/O pins from the BIOS configuration
2543 ALC_CTL_WIDGET_MUTE,
2548 static const struct snd_kcontrol_new alc_control_templates[] = {
2549 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2550 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2551 HDA_BIND_MUTE(NULL, 0, 0, 0),
2552 HDA_BIND_VOL(NULL, 0),
2553 HDA_BIND_SW(NULL, 0),
2556 /* add dynamic controls */
2557 static int add_control(struct alc_spec *spec, int type, const char *name,
2558 int cidx, unsigned long val)
2560 struct snd_kcontrol_new *knew;
2562 knew = alc_kcontrol_new(spec);
2565 *knew = alc_control_templates[type];
2566 knew->name = kstrdup(name, GFP_KERNEL);
2570 if (get_amp_nid_(val))
2571 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
2572 knew->private_value = val;
2576 static int add_control_with_pfx(struct alc_spec *spec, int type,
2577 const char *pfx, const char *dir,
2578 const char *sfx, int cidx, unsigned long val)
2581 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
2582 return add_control(spec, type, name, cidx, val);
2585 #define add_pb_vol_ctrl(spec, type, pfx, val) \
2586 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2587 #define add_pb_sw_ctrl(spec, type, pfx, val) \
2588 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2589 #define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2590 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2591 #define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2592 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
2594 static const char * const channel_name[4] = {
2595 "Front", "Surround", "CLFE", "Side"
2598 static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2599 bool can_be_master, int *index)
2601 struct auto_pin_cfg *cfg = &spec->autocfg;
2604 if (cfg->line_outs == 1 && !spec->multi_ios &&
2605 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
2608 switch (cfg->line_out_type) {
2609 case AUTO_PIN_SPEAKER_OUT:
2610 if (cfg->line_outs == 1)
2613 case AUTO_PIN_HP_OUT:
2614 /* for multi-io case, only the primary out */
2615 if (ch && spec->multi_ios)
2620 if (cfg->line_outs == 1 && !spec->multi_ios)
2624 if (snd_BUG_ON(ch >= ARRAY_SIZE(channel_name)))
2627 return channel_name[ch];
2630 /* create input playback/capture controls for the given pin */
2631 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
2632 const char *ctlname, int ctlidx,
2633 int idx, hda_nid_t mix_nid)
2637 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
2638 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2641 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
2642 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2648 static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
2650 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2651 return (pincap & AC_PINCAP_IN) != 0;
2654 /* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
2655 static int alc_auto_fill_adc_caps(struct hda_codec *codec)
2657 struct alc_spec *spec = codec->spec;
2659 hda_nid_t *adc_nids = spec->private_adc_nids;
2660 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2661 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
2664 if (spec->shared_mic_hp)
2665 max_nums = 1; /* no multi streams with the shared HP/mic */
2667 nid = codec->start_nid;
2668 for (i = 0; i < codec->num_nodes; i++, nid++) {
2670 const hda_nid_t *list;
2671 unsigned int caps = get_wcaps(codec, nid);
2672 int type = get_wcaps_type(caps);
2674 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2676 adc_nids[nums] = nid;
2677 cap_nids[nums] = nid;
2681 type = get_wcaps_type(get_wcaps(codec, src));
2682 if (type == AC_WID_PIN)
2684 if (type == AC_WID_AUD_SEL) {
2685 cap_nids[nums] = src;
2688 n = snd_hda_get_conn_list(codec, src, &list);
2690 cap_nids[nums] = src;
2696 if (++nums >= max_nums)
2699 spec->adc_nids = spec->private_adc_nids;
2700 spec->capsrc_nids = spec->private_capsrc_nids;
2701 spec->num_adc_nids = nums;
2705 /* create playback/capture controls for input pins */
2706 static int alc_auto_create_input_ctls(struct hda_codec *codec)
2708 struct alc_spec *spec = codec->spec;
2709 const struct auto_pin_cfg *cfg = &spec->autocfg;
2710 hda_nid_t mixer = spec->mixer_nid;
2711 struct hda_input_mux *imux = &spec->private_imux[0];
2713 int i, c, err, idx, type_idx = 0;
2714 const char *prev_label = NULL;
2716 num_adcs = alc_auto_fill_adc_caps(codec);
2720 for (i = 0; i < cfg->num_inputs; i++) {
2724 pin = cfg->inputs[i].pin;
2725 if (!alc_is_input_pin(codec, pin))
2728 label = hda_get_autocfg_input_label(codec, cfg, i);
2729 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
2730 label = "Headphone Mic";
2731 if (prev_label && !strcmp(label, prev_label))
2738 idx = get_connection_index(codec, mixer, pin);
2740 err = new_analog_input(spec, pin,
2748 for (c = 0; c < num_adcs; c++) {
2749 hda_nid_t cap = spec->capsrc_nids ?
2750 spec->capsrc_nids[c] : spec->adc_nids[c];
2751 idx = get_connection_index(codec, cap, pin);
2753 spec->imux_pins[imux->num_items] = pin;
2754 snd_hda_add_imux_item(imux, label, idx, NULL);
2760 spec->num_mux_defs = 1;
2761 spec->input_mux = imux;
2766 /* create a shared input with the headphone out */
2767 static int alc_auto_create_shared_input(struct hda_codec *codec)
2769 struct alc_spec *spec = codec->spec;
2770 struct auto_pin_cfg *cfg = &spec->autocfg;
2771 unsigned int defcfg;
2774 /* only one internal input pin? */
2775 if (cfg->num_inputs != 1)
2777 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2778 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2781 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
2782 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
2783 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
2784 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
2786 return 0; /* both not available */
2788 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2789 return 0; /* no input */
2791 cfg->inputs[1].pin = nid;
2792 cfg->inputs[1].type = AUTO_PIN_MIC;
2793 cfg->num_inputs = 2;
2794 spec->shared_mic_hp = 1;
2795 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
2799 static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
2800 unsigned int pin_type)
2802 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2805 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2806 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2810 static int get_pin_type(int line_out_type)
2812 if (line_out_type == AUTO_PIN_HP_OUT)
2818 static void alc_auto_init_analog_input(struct hda_codec *codec)
2820 struct alc_spec *spec = codec->spec;
2821 struct auto_pin_cfg *cfg = &spec->autocfg;
2824 for (i = 0; i < cfg->num_inputs; i++) {
2825 hda_nid_t nid = cfg->inputs[i].pin;
2826 if (alc_is_input_pin(codec, nid)) {
2827 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
2828 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
2829 snd_hda_codec_write(codec, nid, 0,
2830 AC_VERB_SET_AMP_GAIN_MUTE,
2835 /* mute all loopback inputs */
2836 if (spec->mixer_nid) {
2837 int nums = snd_hda_get_conn_list(codec, spec->mixer_nid, NULL);
2838 for (i = 0; i < nums; i++)
2839 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2840 AC_VERB_SET_AMP_GAIN_MUTE,
2845 /* convert from MIX nid to DAC */
2846 static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid)
2851 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT)
2853 num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list));
2854 for (i = 0; i < num; i++) {
2855 if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT)
2861 /* go down to the selector widget before the mixer */
2862 static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin)
2865 int num = snd_hda_get_connections(codec, pin, srcs,
2868 get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL)
2873 /* get MIX nid connected to the given pin targeted to DAC */
2874 static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
2880 pin = alc_go_down_to_selector(codec, pin);
2881 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2882 for (i = 0; i < num; i++) {
2883 if (alc_auto_mix_to_dac(codec, mix[i]) == dac)
2889 /* select the connection from pin to DAC if needed */
2890 static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin,
2896 pin = alc_go_down_to_selector(codec, pin);
2897 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2900 for (i = 0; i < num; i++) {
2901 if (alc_auto_mix_to_dac(codec, mix[i]) == dac) {
2902 snd_hda_codec_update_cache(codec, pin, 0,
2903 AC_VERB_SET_CONNECT_SEL, i);
2910 /* look for an empty DAC slot */
2911 static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
2913 struct alc_spec *spec = codec->spec;
2917 pin = alc_go_down_to_selector(codec, pin);
2918 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
2919 for (i = 0; i < num; i++) {
2920 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
2923 if (found_in_nid_list(nid, spec->multiout.dac_nids,
2924 spec->multiout.num_dacs))
2926 if (found_in_nid_list(nid, spec->multiout.hp_out_nid,
2927 ARRAY_SIZE(spec->multiout.hp_out_nid)))
2929 if (found_in_nid_list(nid, spec->multiout.extra_out_nid,
2930 ARRAY_SIZE(spec->multiout.extra_out_nid)))
2937 /* check whether the DAC is reachable from the pin */
2938 static bool alc_auto_is_dac_reachable(struct hda_codec *codec,
2939 hda_nid_t pin, hda_nid_t dac)
2944 pin = alc_go_down_to_selector(codec, pin);
2945 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
2946 for (i = 0; i < num; i++) {
2947 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
2954 static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
2956 hda_nid_t sel = alc_go_down_to_selector(codec, pin);
2957 if (snd_hda_get_conn_list(codec, sel, NULL) == 1)
2958 return alc_auto_look_for_dac(codec, pin);
2962 static int alc_auto_fill_extra_dacs(struct hda_codec *codec, int num_outs,
2963 const hda_nid_t *pins, hda_nid_t *dacs)
2967 if (num_outs && !dacs[0]) {
2968 dacs[0] = alc_auto_look_for_dac(codec, pins[0]);
2973 for (i = 1; i < num_outs; i++)
2974 dacs[i] = get_dac_if_single(codec, pins[i]);
2975 for (i = 1; i < num_outs; i++) {
2977 dacs[i] = alc_auto_look_for_dac(codec, pins[i]);
2982 static int alc_auto_fill_multi_ios(struct hda_codec *codec,
2983 unsigned int location, int offset);
2985 /* fill in the dac_nids table from the parsed pin configuration */
2986 static int alc_auto_fill_dac_nids(struct hda_codec *codec)
2988 struct alc_spec *spec = codec->spec;
2989 const struct auto_pin_cfg *cfg = &spec->autocfg;
2990 unsigned int location, defcfg;
2992 bool redone = false;
2996 /* set num_dacs once to full for alc_auto_look_for_dac() */
2997 spec->multiout.num_dacs = cfg->line_outs;
2998 spec->multiout.hp_out_nid[0] = 0;
2999 spec->multiout.extra_out_nid[0] = 0;
3000 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
3001 spec->multiout.dac_nids = spec->private_dac_nids;
3003 /* fill hard-wired DACs first */
3005 for (i = 0; i < cfg->line_outs; i++)
3006 spec->private_dac_nids[i] =
3007 get_dac_if_single(codec, cfg->line_out_pins[i]);
3009 spec->multiout.hp_out_nid[0] =
3010 get_dac_if_single(codec, cfg->hp_pins[0]);
3011 if (cfg->speaker_outs)
3012 spec->multiout.extra_out_nid[0] =
3013 get_dac_if_single(codec, cfg->speaker_pins[0]);
3016 for (i = 0; i < cfg->line_outs; i++) {
3017 hda_nid_t pin = cfg->line_out_pins[i];
3018 if (spec->private_dac_nids[i])
3020 spec->private_dac_nids[i] = alc_auto_look_for_dac(codec, pin);
3021 if (!spec->private_dac_nids[i] && !redone) {
3022 /* if we can't find primary DACs, re-probe without
3023 * checking the hard-wired DACs
3030 /* re-count num_dacs and squash invalid entries */
3031 spec->multiout.num_dacs = 0;
3032 for (i = 0; i < cfg->line_outs; i++) {
3033 if (spec->private_dac_nids[i])
3034 spec->multiout.num_dacs++;
3036 memmove(spec->private_dac_nids + i,
3037 spec->private_dac_nids + i + 1,
3038 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
3041 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3042 /* try to fill multi-io first */
3043 defcfg = snd_hda_codec_get_pincfg(codec, cfg->line_out_pins[0]);
3044 location = get_defcfg_location(defcfg);
3046 num_pins = alc_auto_fill_multi_ios(codec, location, 0);
3048 spec->multi_ios = num_pins;
3049 spec->ext_channel_count = 2;
3050 spec->multiout.num_dacs = num_pins + 1;
3054 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
3055 alc_auto_fill_extra_dacs(codec, cfg->hp_outs, cfg->hp_pins,
3056 spec->multiout.hp_out_nid);
3057 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
3058 alc_auto_fill_extra_dacs(codec, cfg->speaker_outs, cfg->speaker_pins,
3059 spec->multiout.extra_out_nid);
3061 if (!spec->multi_ios &&
3062 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
3064 /* try multi-ios with HP + inputs */
3065 defcfg = snd_hda_codec_get_pincfg(codec, cfg->hp_pins[0]);
3066 location = get_defcfg_location(defcfg);
3068 num_pins = alc_auto_fill_multi_ios(codec, location, 1);
3070 spec->multi_ios = num_pins;
3071 spec->ext_channel_count = 2;
3072 spec->multiout.num_dacs = num_pins + 1;
3079 static inline unsigned int get_ctl_pos(unsigned int data)
3081 hda_nid_t nid = get_amp_nid_(data);
3082 unsigned int dir = get_amp_direction_(data);
3083 return (nid << 1) | dir;
3086 #define is_ctl_used(bits, data) \
3087 test_bit(get_ctl_pos(data), bits)
3088 #define mark_ctl_usage(bits, data) \
3089 set_bit(get_ctl_pos(data), bits)
3091 static int alc_auto_add_vol_ctl(struct hda_codec *codec,
3092 const char *pfx, int cidx,
3093 hda_nid_t nid, unsigned int chs)
3095 struct alc_spec *spec = codec->spec;
3099 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3100 if (is_ctl_used(spec->vol_ctls, val) && chs != 2) /* exclude LFE */
3102 mark_ctl_usage(spec->vol_ctls, val);
3103 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
3107 static int alc_auto_add_stereo_vol(struct hda_codec *codec,
3108 const char *pfx, int cidx,
3112 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3114 return alc_auto_add_vol_ctl(codec, pfx, cidx, nid, chs);
3117 /* create a mute-switch for the given mixer widget;
3118 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3120 static int alc_auto_add_sw_ctl(struct hda_codec *codec,
3121 const char *pfx, int cidx,
3122 hda_nid_t nid, unsigned int chs)
3124 struct alc_spec *spec = codec->spec;
3130 wid_type = get_wcaps_type(get_wcaps(codec, nid));
3131 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) {
3132 type = ALC_CTL_WIDGET_MUTE;
3133 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3134 } else if (snd_hda_get_conn_list(codec, nid, NULL) == 1) {
3135 type = ALC_CTL_WIDGET_MUTE;
3136 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
3138 type = ALC_CTL_BIND_MUTE;
3139 val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
3141 if (is_ctl_used(spec->sw_ctls, val) && chs != 2) /* exclude LFE */
3143 mark_ctl_usage(spec->sw_ctls, val);
3144 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
3147 static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
3148 int cidx, hda_nid_t nid)
3151 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3153 return alc_auto_add_sw_ctl(codec, pfx, cidx, nid, chs);
3156 static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3157 hda_nid_t pin, hda_nid_t dac)
3159 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3160 if (nid_has_mute(codec, pin, HDA_OUTPUT))
3162 else if (mix && nid_has_mute(codec, mix, HDA_INPUT))
3164 else if (nid_has_mute(codec, dac, HDA_OUTPUT))
3169 static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3170 hda_nid_t pin, hda_nid_t dac)
3172 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3173 if (nid_has_volume(codec, dac, HDA_OUTPUT))
3175 else if (nid_has_volume(codec, mix, HDA_OUTPUT))
3177 else if (nid_has_volume(codec, pin, HDA_OUTPUT))
3182 /* add playback controls from the parsed DAC table */
3183 static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
3184 const struct auto_pin_cfg *cfg)
3186 struct alc_spec *spec = codec->spec;
3187 int i, err, noutputs;
3189 noutputs = cfg->line_outs;
3190 if (spec->multi_ios > 0)
3191 noutputs += spec->multi_ios;
3193 for (i = 0; i < noutputs; i++) {
3199 dac = spec->multiout.dac_nids[i];
3202 if (i >= cfg->line_outs)
3203 pin = spec->multi_io[i - 1].pin;
3205 pin = cfg->line_out_pins[i];
3207 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3208 vol = alc_look_for_out_vol_nid(codec, pin, dac);
3209 name = alc_get_line_out_pfx(spec, i, true, &index);
3210 if (!name || !strcmp(name, "CLFE")) {
3212 err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1);
3215 err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2);
3218 err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1);
3221 err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2);
3225 err = alc_auto_add_stereo_vol(codec, name, index, vol);
3228 err = alc_auto_add_stereo_sw(codec, name, index, sw);
3236 static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
3237 hda_nid_t dac, const char *pfx)
3239 struct alc_spec *spec = codec->spec;
3245 /* the corresponding DAC is already occupied */
3246 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
3247 return 0; /* no way */
3248 /* create a switch only */
3249 val = HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT);
3250 if (is_ctl_used(spec->sw_ctls, val))
3251 return 0; /* already created */
3252 mark_ctl_usage(spec->sw_ctls, val);
3253 return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, val);
3256 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3257 vol = alc_look_for_out_vol_nid(codec, pin, dac);
3258 err = alc_auto_add_stereo_vol(codec, pfx, 0, vol);
3261 err = alc_auto_add_stereo_sw(codec, pfx, 0, sw);
3267 static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3269 struct hda_ctl_ops *ops)
3271 struct alc_spec *spec = codec->spec;
3272 struct hda_bind_ctls **ctlp, *ctl;
3273 snd_array_init(&spec->bind_ctls, sizeof(ctl), 8);
3274 ctlp = snd_array_new(&spec->bind_ctls);
3277 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3284 /* add playback controls for speaker and HP outputs */
3285 static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3286 const hda_nid_t *pins,
3287 const hda_nid_t *dacs,
3290 struct alc_spec *spec = codec->spec;
3291 struct hda_bind_ctls *ctl;
3295 if (!num_pins || !pins[0])
3298 if (num_pins == 1) {
3299 hda_nid_t dac = *dacs;
3301 dac = spec->multiout.dac_nids[0];
3302 return alc_auto_create_extra_out(codec, *pins, dac, pfx);
3305 if (dacs[num_pins - 1]) {
3306 /* OK, we have a multi-output system with individual volumes */
3307 for (i = 0; i < num_pins; i++) {
3308 snprintf(name, sizeof(name), "%s %s",
3309 pfx, channel_name[i]);
3310 err = alc_auto_create_extra_out(codec, pins[i], dacs[i],
3318 /* Let's create a bind-controls */
3319 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_sw);
3323 for (i = 0; i < num_pins; i++) {
3324 if (get_wcaps(codec, pins[i]) & AC_WCAP_OUT_AMP)
3326 HDA_COMPOSE_AMP_VAL(pins[i], 3, 0, HDA_OUTPUT);
3329 snprintf(name, sizeof(name), "%s Playback Switch", pfx);
3330 err = add_control(spec, ALC_CTL_BIND_SW, name, 0, (long)ctl);
3335 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3339 for (i = 0; i < num_pins; i++) {
3341 if (!pins[i] || !dacs[i])
3343 vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]);
3346 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3349 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3350 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3357 static int alc_auto_create_hp_out(struct hda_codec *codec)
3359 struct alc_spec *spec = codec->spec;
3360 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3361 spec->autocfg.hp_pins,
3362 spec->multiout.hp_out_nid,
3366 static int alc_auto_create_speaker_out(struct hda_codec *codec)
3368 struct alc_spec *spec = codec->spec;
3369 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3370 spec->autocfg.speaker_pins,
3371 spec->multiout.extra_out_nid,
3375 static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
3376 hda_nid_t pin, int pin_type,
3380 hda_nid_t nid, mix = 0;
3381 hda_nid_t srcs[HDA_MAX_CONNECTIONS];
3383 alc_set_pin_output(codec, pin, pin_type);
3384 nid = alc_go_down_to_selector(codec, pin);
3385 num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
3386 for (i = 0; i < num; i++) {
3387 if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
3395 /* need the manual connection? */
3397 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
3398 /* unmute mixer widget inputs */
3399 if (nid_has_mute(codec, mix, HDA_INPUT)) {
3400 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3402 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3405 /* initialize volume */
3406 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3408 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3411 /* unmute DAC if it's not assigned to a mixer */
3412 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3413 if (nid == mix && nid_has_mute(codec, dac, HDA_OUTPUT))
3414 snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3418 static void alc_auto_init_multi_out(struct hda_codec *codec)
3420 struct alc_spec *spec = codec->spec;
3421 int pin_type = get_pin_type(spec->autocfg.line_out_type);
3424 for (i = 0; i <= HDA_SIDE; i++) {
3425 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3427 alc_auto_set_output_and_unmute(codec, nid, pin_type,
3428 spec->multiout.dac_nids[i]);
3432 static void alc_auto_init_extra_out(struct hda_codec *codec)
3434 struct alc_spec *spec = codec->spec;
3438 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3439 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3441 pin = spec->autocfg.hp_pins[i];
3444 dac = spec->multiout.hp_out_nid[i];
3446 if (i > 0 && spec->multiout.hp_out_nid[0])
3447 dac = spec->multiout.hp_out_nid[0];
3449 dac = spec->multiout.dac_nids[0];
3451 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
3453 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3454 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3456 pin = spec->autocfg.speaker_pins[i];
3459 dac = spec->multiout.extra_out_nid[i];
3461 if (i > 0 && spec->multiout.extra_out_nid[0])
3462 dac = spec->multiout.extra_out_nid[0];
3464 dac = spec->multiout.dac_nids[0];
3466 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
3473 static int alc_auto_fill_multi_ios(struct hda_codec *codec,
3474 unsigned int location,
3477 struct alc_spec *spec = codec->spec;
3478 struct auto_pin_cfg *cfg = &spec->autocfg;
3479 hda_nid_t prime_dac = spec->private_dac_nids[0];
3480 int type, i, dacs, num_pins = 0;
3482 dacs = spec->multiout.num_dacs;
3483 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3484 for (i = 0; i < cfg->num_inputs; i++) {
3485 hda_nid_t nid = cfg->inputs[i].pin;
3487 unsigned int defcfg, caps;
3488 if (cfg->inputs[i].type != type)
3490 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3491 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3493 if (location && get_defcfg_location(defcfg) != location)
3495 caps = snd_hda_query_pin_caps(codec, nid);
3496 if (!(caps & AC_PINCAP_OUT))
3498 if (offset && offset + num_pins < dacs) {
3499 dac = spec->private_dac_nids[offset + num_pins];
3500 if (!alc_auto_is_dac_reachable(codec, nid, dac))
3504 dac = alc_auto_look_for_dac(codec, nid);
3507 spec->multi_io[num_pins].pin = nid;
3508 spec->multi_io[num_pins].dac = dac;
3510 spec->private_dac_nids[spec->multiout.num_dacs++] = dac;
3513 spec->multiout.num_dacs = dacs;
3515 /* clear up again */
3516 memset(spec->private_dac_nids + dacs, 0,
3517 sizeof(hda_nid_t) * (AUTO_CFG_MAX_OUTS - dacs));
3518 spec->private_dac_nids[0] = prime_dac;
3524 static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
3525 struct snd_ctl_elem_info *uinfo)
3527 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3528 struct alc_spec *spec = codec->spec;
3530 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3532 uinfo->value.enumerated.items = spec->multi_ios + 1;
3533 if (uinfo->value.enumerated.item > spec->multi_ios)
3534 uinfo->value.enumerated.item = spec->multi_ios;
3535 sprintf(uinfo->value.enumerated.name, "%dch",
3536 (uinfo->value.enumerated.item + 1) * 2);
3540 static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
3541 struct snd_ctl_elem_value *ucontrol)
3543 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3544 struct alc_spec *spec = codec->spec;
3545 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
3549 static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
3551 struct alc_spec *spec = codec->spec;
3552 hda_nid_t nid = spec->multi_io[idx].pin;
3554 if (!spec->multi_io[idx].ctl_in)
3555 spec->multi_io[idx].ctl_in =
3556 snd_hda_codec_read(codec, nid, 0,
3557 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3559 snd_hda_codec_update_cache(codec, nid, 0,
3560 AC_VERB_SET_PIN_WIDGET_CONTROL,
3562 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3563 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3565 alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
3567 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3568 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3569 HDA_AMP_MUTE, HDA_AMP_MUTE);
3570 snd_hda_codec_update_cache(codec, nid, 0,
3571 AC_VERB_SET_PIN_WIDGET_CONTROL,
3572 spec->multi_io[idx].ctl_in);
3577 static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
3578 struct snd_ctl_elem_value *ucontrol)
3580 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3581 struct alc_spec *spec = codec->spec;
3584 ch = ucontrol->value.enumerated.item[0];
3585 if (ch < 0 || ch > spec->multi_ios)
3587 if (ch == (spec->ext_channel_count - 1) / 2)
3589 spec->ext_channel_count = (ch + 1) * 2;
3590 for (i = 0; i < spec->multi_ios; i++)
3591 alc_set_multi_io(codec, i, i < ch);
3592 spec->multiout.max_channels = spec->ext_channel_count;
3593 if (spec->need_dac_fix && !spec->const_channel_count)
3594 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
3598 static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
3599 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3600 .name = "Channel Mode",
3601 .info = alc_auto_ch_mode_info,
3602 .get = alc_auto_ch_mode_get,
3603 .put = alc_auto_ch_mode_put,
3606 static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
3608 struct alc_spec *spec = codec->spec;
3610 if (spec->multi_ios > 0) {
3611 struct snd_kcontrol_new *knew;
3613 knew = alc_kcontrol_new(spec);
3616 *knew = alc_auto_channel_mode_enum;
3617 knew->name = kstrdup("Channel Mode", GFP_KERNEL);
3624 /* filter out invalid adc_nids (and capsrc_nids) that don't give all
3627 static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
3629 struct alc_spec *spec = codec->spec;
3630 const struct hda_input_mux *imux;
3631 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3632 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3635 imux = spec->input_mux;
3638 if (spec->dyn_adc_switch)
3642 for (n = 0; n < spec->num_adc_nids; n++) {
3643 hda_nid_t cap = spec->private_capsrc_nids[n];
3644 int num_conns = snd_hda_get_conn_list(codec, cap, NULL);
3645 for (i = 0; i < imux->num_items; i++) {
3646 hda_nid_t pin = spec->imux_pins[i];
3648 if (get_connection_index(codec, cap, pin) < 0)
3650 } else if (num_conns <= imux->items[i].index)
3653 if (i >= imux->num_items) {
3654 adc_nids[nums] = spec->private_adc_nids[n];
3655 capsrc_nids[nums++] = cap;
3659 /* check whether ADC-switch is possible */
3660 if (!alc_check_dyn_adc_switch(codec)) {
3661 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
3662 " using fallback 0x%x\n",
3663 codec->chip_name, spec->private_adc_nids[0]);
3664 spec->num_adc_nids = 1;
3668 } else if (nums != spec->num_adc_nids) {
3669 memcpy(spec->private_adc_nids, adc_nids,
3670 nums * sizeof(hda_nid_t));
3671 memcpy(spec->private_capsrc_nids, capsrc_nids,
3672 nums * sizeof(hda_nid_t));
3673 spec->num_adc_nids = nums;
3677 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
3678 else if (spec->input_mux->num_items == 1)
3679 spec->num_adc_nids = 1; /* reduce to a single ADC */
3683 * initialize ADC paths
3685 static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
3687 struct alc_spec *spec = codec->spec;
3690 nid = spec->adc_nids[adc_idx];
3692 if (nid_has_mute(codec, nid, HDA_INPUT)) {
3693 snd_hda_codec_write(codec, nid, 0,
3694 AC_VERB_SET_AMP_GAIN_MUTE,
3698 if (!spec->capsrc_nids)
3700 nid = spec->capsrc_nids[adc_idx];
3701 if (nid_has_mute(codec, nid, HDA_OUTPUT))
3702 snd_hda_codec_write(codec, nid, 0,
3703 AC_VERB_SET_AMP_GAIN_MUTE,
3707 static void alc_auto_init_input_src(struct hda_codec *codec)
3709 struct alc_spec *spec = codec->spec;
3712 for (c = 0; c < spec->num_adc_nids; c++)
3713 alc_auto_init_adc(codec, c);
3714 if (spec->dyn_adc_switch)
3717 nums = spec->num_adc_nids;
3718 for (c = 0; c < nums; c++)
3719 alc_mux_select(codec, 0, spec->cur_mux[c], true);
3722 /* add mic boosts if needed */
3723 static int alc_auto_add_mic_boost(struct hda_codec *codec)
3725 struct alc_spec *spec = codec->spec;
3726 struct auto_pin_cfg *cfg = &spec->autocfg;
3730 const char *prev_label = NULL;
3732 for (i = 0; i < cfg->num_inputs; i++) {
3733 if (cfg->inputs[i].type > AUTO_PIN_MIC)
3735 nid = cfg->inputs[i].pin;
3736 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
3738 char boost_label[32];
3740 label = hda_get_autocfg_input_label(codec, cfg, i);
3741 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
3742 label = "Headphone Mic";
3743 if (prev_label && !strcmp(label, prev_label))
3749 snprintf(boost_label, sizeof(boost_label),
3750 "%s Boost Volume", label);
3751 err = add_control(spec, ALC_CTL_WIDGET_VOL,
3752 boost_label, type_idx,
3753 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
3761 /* select or unmute the given capsrc route */
3762 static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
3765 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
3766 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
3768 } else if (snd_hda_get_conn_list(codec, cap, NULL) > 1) {
3769 snd_hda_codec_write_cache(codec, cap, 0,
3770 AC_VERB_SET_CONNECT_SEL, idx);
3774 /* set the default connection to that pin */
3775 static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
3777 struct alc_spec *spec = codec->spec;
3782 for (i = 0; i < spec->num_adc_nids; i++) {
3783 hda_nid_t cap = spec->capsrc_nids ?
3784 spec->capsrc_nids[i] : spec->adc_nids[i];
3787 idx = get_connection_index(codec, cap, pin);
3790 select_or_unmute_capsrc(codec, cap, idx);
3791 return i; /* return the found index */
3793 return -1; /* not found */
3796 /* initialize some special cases for input sources */
3797 static void alc_init_special_input_src(struct hda_codec *codec)
3799 struct alc_spec *spec = codec->spec;
3802 for (i = 0; i < spec->autocfg.num_inputs; i++)
3803 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
3806 /* assign appropriate capture mixers */
3807 static void set_capture_mixer(struct hda_codec *codec)
3809 struct alc_spec *spec = codec->spec;
3810 static const struct snd_kcontrol_new *caps[2][3] = {
3811 { alc_capture_mixer_nosrc1,
3812 alc_capture_mixer_nosrc2,
3813 alc_capture_mixer_nosrc3 },
3814 { alc_capture_mixer1,
3816 alc_capture_mixer3 },
3819 /* check whether either of ADC or MUX has a volume control */
3820 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
3821 if (!spec->capsrc_nids)
3822 return; /* no volume */
3823 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
3824 return; /* no volume in capsrc, too */
3825 spec->vol_in_capsrc = 1;
3828 if (spec->num_adc_nids > 0) {
3832 if (spec->input_mux && spec->input_mux->num_items > 1)
3834 if (spec->auto_mic) {
3837 } else if (spec->dyn_adc_switch)
3840 if (spec->num_adc_nids > 3)
3841 spec->num_adc_nids = 3;
3842 else if (!spec->num_adc_nids)
3844 num_adcs = spec->num_adc_nids;
3846 spec->cap_mixer = caps[mux][num_adcs - 1];
3851 * standard auto-parser initializations
3853 static void alc_auto_init_std(struct hda_codec *codec)
3855 struct alc_spec *spec = codec->spec;
3856 spec->use_jack_tbl = 1;
3857 alc_auto_init_multi_out(codec);
3858 alc_auto_init_extra_out(codec);
3859 alc_auto_init_analog_input(codec);
3860 alc_auto_init_input_src(codec);
3861 alc_auto_init_digital(codec);
3862 if (spec->unsol_event)
3863 alc_inithook(codec);
3867 * Digital-beep handlers
3869 #ifdef CONFIG_SND_HDA_INPUT_BEEP
3870 #define set_beep_amp(spec, nid, idx, dir) \
3871 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
3873 static const struct snd_pci_quirk beep_white_list[] = {
3874 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
3875 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
3876 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
3877 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
3878 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
3882 static inline int has_cdefine_beep(struct hda_codec *codec)
3884 struct alc_spec *spec = codec->spec;
3885 const struct snd_pci_quirk *q;
3886 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
3889 return spec->cdefine.enable_pcbeep;
3892 #define set_beep_amp(spec, nid, idx, dir) /* NOP */
3893 #define has_cdefine_beep(codec) 0
3896 /* parse the BIOS configuration and set up the alc_spec */
3897 /* return 1 if successful, 0 if the proper config is not found,
3898 * or a negative error code
3900 static int alc_parse_auto_config(struct hda_codec *codec,
3901 const hda_nid_t *ignore_nids,
3902 const hda_nid_t *ssid_nids)
3904 struct alc_spec *spec = codec->spec;
3905 struct auto_pin_cfg *cfg = &spec->autocfg;
3908 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
3912 if (!cfg->line_outs) {
3913 if (cfg->dig_outs || cfg->dig_in_pin) {
3914 spec->multiout.max_channels = 2;
3915 spec->no_analog = 1;
3918 return 0; /* can't find valid BIOS pin config */
3921 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
3922 cfg->line_outs <= cfg->hp_outs) {
3923 /* use HP as primary out */
3924 cfg->speaker_outs = cfg->line_outs;
3925 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3926 sizeof(cfg->speaker_pins));
3927 cfg->line_outs = cfg->hp_outs;
3928 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
3930 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3931 cfg->line_out_type = AUTO_PIN_HP_OUT;
3934 err = alc_auto_fill_dac_nids(codec);
3937 err = alc_auto_add_multi_channel_mode(codec);
3940 err = alc_auto_create_multi_out_ctls(codec, cfg);
3943 err = alc_auto_create_hp_out(codec);
3946 err = alc_auto_create_speaker_out(codec);
3949 err = alc_auto_create_shared_input(codec);
3952 err = alc_auto_create_input_ctls(codec);
3956 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3959 alc_auto_parse_digital(codec);
3961 if (!spec->no_analog)
3962 alc_remove_invalid_adc_nids(codec);
3965 alc_ssid_check(codec, ssid_nids);
3967 if (!spec->no_analog) {
3968 alc_auto_check_switches(codec);
3969 err = alc_auto_add_mic_boost(codec);
3974 if (spec->kctls.list)
3975 add_mixer(spec, spec->kctls.list);
3980 static int alc880_parse_auto_config(struct hda_codec *codec)
3982 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
3983 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
3984 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
3987 #ifdef CONFIG_SND_HDA_POWER_SAVE
3988 static const struct hda_amp_list alc880_loopbacks[] = {
3989 { 0x0b, HDA_INPUT, 0 },
3990 { 0x0b, HDA_INPUT, 1 },
3991 { 0x0b, HDA_INPUT, 2 },
3992 { 0x0b, HDA_INPUT, 3 },
3993 { 0x0b, HDA_INPUT, 4 },
4003 ALC880_FIXUP_MEDION_RIM,
4006 static const struct alc_fixup alc880_fixups[] = {
4007 [ALC880_FIXUP_GPIO2] = {
4008 .type = ALC_FIXUP_VERBS,
4009 .v.verbs = alc_gpio2_init_verbs,
4011 [ALC880_FIXUP_MEDION_RIM] = {
4012 .type = ALC_FIXUP_VERBS,
4013 .v.verbs = (const struct hda_verb[]) {
4014 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4015 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4019 .chain_id = ALC880_FIXUP_GPIO2,
4023 static const struct snd_pci_quirk alc880_fixup_tbl[] = {
4024 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
4032 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4033 #define alc_board_config \
4034 snd_hda_check_board_config
4035 #define alc_board_codec_sid_config \
4036 snd_hda_check_board_codec_sid_config
4037 #include "alc_quirks.c"
4039 #define alc_board_config(codec, nums, models, tbl) -1
4040 #define alc_board_codec_sid_config(codec, nums, models, tbl) -1
4041 #define setup_preset(codec, x) /* NOP */
4045 * OK, here we have finally the patch for ALC880
4047 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4048 #include "alc880_quirks.c"
4051 static int patch_alc880(struct hda_codec *codec)
4053 struct alc_spec *spec;
4057 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4063 spec->mixer_nid = 0x0b;
4064 spec->need_dac_fix = 1;
4066 board_config = alc_board_config(codec, ALC880_MODEL_LAST,
4067 alc880_models, alc880_cfg_tbl);
4068 if (board_config < 0) {
4069 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4071 board_config = ALC_MODEL_AUTO;
4074 if (board_config == ALC_MODEL_AUTO) {
4075 alc_pick_fixup(codec, NULL, alc880_fixup_tbl, alc880_fixups);
4076 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4079 if (board_config == ALC_MODEL_AUTO) {
4080 /* automatic parse from the BIOS config */
4081 err = alc880_parse_auto_config(codec);
4084 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4087 "hda_codec: Cannot set up configuration "
4088 "from BIOS. Using 3-stack mode...\n");
4089 board_config = ALC880_3ST;
4094 if (board_config != ALC_MODEL_AUTO)
4095 setup_preset(codec, &alc880_presets[board_config]);
4097 if (!spec->no_analog && !spec->adc_nids) {
4098 alc_auto_fill_adc_caps(codec);
4099 alc_rebuild_imux_for_auto_mic(codec);
4100 alc_remove_invalid_adc_nids(codec);
4103 if (!spec->no_analog && !spec->cap_mixer)
4104 set_capture_mixer(codec);
4106 if (!spec->no_analog) {
4107 err = snd_hda_attach_beep_device(codec, 0x1);
4110 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4113 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4115 spec->vmaster_nid = 0x0c;
4117 codec->patch_ops = alc_patch_ops;
4118 if (board_config == ALC_MODEL_AUTO)
4119 spec->init_hook = alc_auto_init_std;
4120 #ifdef CONFIG_SND_HDA_POWER_SAVE
4121 if (!spec->loopback.amplist)
4122 spec->loopback.amplist = alc880_loopbacks;
4136 static int alc260_parse_auto_config(struct hda_codec *codec)
4138 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
4139 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
4140 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
4143 #ifdef CONFIG_SND_HDA_POWER_SAVE
4144 static const struct hda_amp_list alc260_loopbacks[] = {
4145 { 0x07, HDA_INPUT, 0 },
4146 { 0x07, HDA_INPUT, 1 },
4147 { 0x07, HDA_INPUT, 2 },
4148 { 0x07, HDA_INPUT, 3 },
4149 { 0x07, HDA_INPUT, 4 },
4161 static const struct alc_fixup alc260_fixups[] = {
4162 [PINFIX_HP_DC5750] = {
4163 .type = ALC_FIXUP_PINS,
4164 .v.pins = (const struct alc_pincfg[]) {
4165 { 0x11, 0x90130110 }, /* speaker */
4171 static const struct snd_pci_quirk alc260_fixup_tbl[] = {
4172 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", PINFIX_HP_DC5750),
4178 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4179 #include "alc260_quirks.c"
4182 static int patch_alc260(struct hda_codec *codec)
4184 struct alc_spec *spec;
4185 int err, board_config;
4187 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4193 spec->mixer_nid = 0x07;
4195 board_config = alc_board_config(codec, ALC260_MODEL_LAST,
4196 alc260_models, alc260_cfg_tbl);
4197 if (board_config < 0) {
4198 snd_printd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4200 board_config = ALC_MODEL_AUTO;
4203 if (board_config == ALC_MODEL_AUTO) {
4204 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
4205 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4208 if (board_config == ALC_MODEL_AUTO) {
4209 /* automatic parse from the BIOS config */
4210 err = alc260_parse_auto_config(codec);
4213 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4216 "hda_codec: Cannot set up configuration "
4217 "from BIOS. Using base mode...\n");
4218 board_config = ALC260_BASIC;
4223 if (board_config != ALC_MODEL_AUTO)
4224 setup_preset(codec, &alc260_presets[board_config]);
4226 if (!spec->no_analog && !spec->adc_nids) {
4227 alc_auto_fill_adc_caps(codec);
4228 alc_rebuild_imux_for_auto_mic(codec);
4229 alc_remove_invalid_adc_nids(codec);
4232 if (!spec->no_analog && !spec->cap_mixer)
4233 set_capture_mixer(codec);
4235 if (!spec->no_analog) {
4236 err = snd_hda_attach_beep_device(codec, 0x1);
4239 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
4242 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4244 spec->vmaster_nid = 0x08;
4246 codec->patch_ops = alc_patch_ops;
4247 if (board_config == ALC_MODEL_AUTO)
4248 spec->init_hook = alc_auto_init_std;
4249 spec->shutup = alc_eapd_shutup;
4250 #ifdef CONFIG_SND_HDA_POWER_SAVE
4251 if (!spec->loopback.amplist)
4252 spec->loopback.amplist = alc260_loopbacks;
4264 * ALC882/883/885/888/889 support
4266 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
4267 * configuration. Each pin widget can choose any input DACs and a mixer.
4268 * Each ADC is connected from a mixer of all inputs. This makes possible
4269 * 6-channel independent captures.
4271 * In addition, an independent DAC for the multi-playback (not used in this
4274 #ifdef CONFIG_SND_HDA_POWER_SAVE
4275 #define alc882_loopbacks alc880_loopbacks
4282 ALC882_FIXUP_ABIT_AW9D_MAX,
4283 ALC882_FIXUP_LENOVO_Y530,
4284 ALC882_FIXUP_PB_M5210,
4285 ALC882_FIXUP_ACER_ASPIRE_7736,
4286 ALC882_FIXUP_ASUS_W90V,
4287 ALC889_FIXUP_VAIO_TT,
4288 ALC888_FIXUP_EEE1601,
4291 ALC883_FIXUP_ACER_EAPD,
4294 ALC882_FIXUP_ASUS_W2JC,
4295 ALC882_FIXUP_ACER_ASPIRE_4930G,
4296 ALC882_FIXUP_ACER_ASPIRE_8930G,
4297 ALC882_FIXUP_ASPIRE_8930G_VERBS,
4298 ALC885_FIXUP_MACPRO_GPIO,
4301 static void alc889_fixup_coef(struct hda_codec *codec,
4302 const struct alc_fixup *fix, int action)
4304 if (action != ALC_FIXUP_ACT_INIT)
4306 alc889_coef_init(codec);
4309 /* toggle speaker-output according to the hp-jack state */
4310 static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
4312 unsigned int gpiostate, gpiomask, gpiodir;
4314 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
4315 AC_VERB_GET_GPIO_DATA, 0);
4318 gpiostate |= (1 << pin);
4320 gpiostate &= ~(1 << pin);
4322 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
4323 AC_VERB_GET_GPIO_MASK, 0);
4324 gpiomask |= (1 << pin);
4326 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
4327 AC_VERB_GET_GPIO_DIRECTION, 0);
4328 gpiodir |= (1 << pin);
4331 snd_hda_codec_write(codec, codec->afg, 0,
4332 AC_VERB_SET_GPIO_MASK, gpiomask);
4333 snd_hda_codec_write(codec, codec->afg, 0,
4334 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
4338 snd_hda_codec_write(codec, codec->afg, 0,
4339 AC_VERB_SET_GPIO_DATA, gpiostate);
4342 /* set up GPIO at initialization */
4343 static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
4344 const struct alc_fixup *fix, int action)
4346 if (action != ALC_FIXUP_ACT_INIT)
4348 alc882_gpio_mute(codec, 0, 0);
4349 alc882_gpio_mute(codec, 1, 0);
4352 static const struct alc_fixup alc882_fixups[] = {
4353 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
4354 .type = ALC_FIXUP_PINS,
4355 .v.pins = (const struct alc_pincfg[]) {
4356 { 0x15, 0x01080104 }, /* side */
4357 { 0x16, 0x01011012 }, /* rear */
4358 { 0x17, 0x01016011 }, /* clfe */
4362 [ALC882_FIXUP_LENOVO_Y530] = {
4363 .type = ALC_FIXUP_PINS,
4364 .v.pins = (const struct alc_pincfg[]) {
4365 { 0x15, 0x99130112 }, /* rear int speakers */
4366 { 0x16, 0x99130111 }, /* subwoofer */
4370 [ALC882_FIXUP_PB_M5210] = {
4371 .type = ALC_FIXUP_VERBS,
4372 .v.verbs = (const struct hda_verb[]) {
4373 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
4377 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
4378 .type = ALC_FIXUP_SKU,
4379 .v.sku = ALC_FIXUP_SKU_IGNORE,
4381 [ALC882_FIXUP_ASUS_W90V] = {
4382 .type = ALC_FIXUP_PINS,
4383 .v.pins = (const struct alc_pincfg[]) {
4384 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
4388 [ALC889_FIXUP_VAIO_TT] = {
4389 .type = ALC_FIXUP_PINS,
4390 .v.pins = (const struct alc_pincfg[]) {
4391 { 0x17, 0x90170111 }, /* hidden surround speaker */
4395 [ALC888_FIXUP_EEE1601] = {
4396 .type = ALC_FIXUP_VERBS,
4397 .v.verbs = (const struct hda_verb[]) {
4398 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
4399 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
4403 [ALC882_FIXUP_EAPD] = {
4404 .type = ALC_FIXUP_VERBS,
4405 .v.verbs = (const struct hda_verb[]) {
4406 /* change to EAPD mode */
4407 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4408 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4412 [ALC883_FIXUP_EAPD] = {
4413 .type = ALC_FIXUP_VERBS,
4414 .v.verbs = (const struct hda_verb[]) {
4415 /* change to EAPD mode */
4416 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4417 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4421 [ALC883_FIXUP_ACER_EAPD] = {
4422 .type = ALC_FIXUP_VERBS,
4423 .v.verbs = (const struct hda_verb[]) {
4424 /* eanable EAPD on Acer laptops */
4425 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4426 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4430 [ALC882_FIXUP_GPIO3] = {
4431 .type = ALC_FIXUP_VERBS,
4432 .v.verbs = alc_gpio3_init_verbs,
4434 [ALC882_FIXUP_ASUS_W2JC] = {
4435 .type = ALC_FIXUP_VERBS,
4436 .v.verbs = alc_gpio1_init_verbs,
4438 .chain_id = ALC882_FIXUP_EAPD,
4440 [ALC889_FIXUP_COEF] = {
4441 .type = ALC_FIXUP_FUNC,
4442 .v.func = alc889_fixup_coef,
4444 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
4445 .type = ALC_FIXUP_PINS,
4446 .v.pins = (const struct alc_pincfg[]) {
4447 { 0x16, 0x99130111 }, /* CLFE speaker */
4448 { 0x17, 0x99130112 }, /* surround speaker */
4452 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
4453 .type = ALC_FIXUP_PINS,
4454 .v.pins = (const struct alc_pincfg[]) {
4455 { 0x16, 0x99130111 }, /* CLFE speaker */
4456 { 0x1b, 0x99130112 }, /* surround speaker */
4460 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
4462 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
4463 /* additional init verbs for Acer Aspire 8930G */
4464 .type = ALC_FIXUP_VERBS,
4465 .v.verbs = (const struct hda_verb[]) {
4466 /* Enable all DACs */
4467 /* DAC DISABLE/MUTE 1? */
4468 /* setting bits 1-5 disables DAC nids 0x02-0x06
4469 * apparently. Init=0x38 */
4470 { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
4471 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
4472 /* DAC DISABLE/MUTE 2? */
4473 /* some bit here disables the other DACs.
4475 { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
4476 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
4478 * This laptop has a stereo digital microphone.
4479 * The mics are only 1cm apart which makes the stereo
4480 * useless. However, either the mic or the ALC889
4481 * makes the signal become a difference/sum signal
4482 * instead of standard stereo, which is annoying.
4483 * So instead we flip this bit which makes the
4484 * codec replicate the sum signal to both channels,
4485 * turning it into a normal mono mic.
4487 /* DMIC_CONTROL? Init value = 0x0001 */
4488 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
4489 { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
4490 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4491 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4495 [ALC885_FIXUP_MACPRO_GPIO] = {
4496 .type = ALC_FIXUP_FUNC,
4497 .v.func = alc885_fixup_macpro_gpio,
4501 static const struct snd_pci_quirk alc882_fixup_tbl[] = {
4502 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
4503 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
4504 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
4505 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
4506 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
4507 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
4508 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
4509 ALC882_FIXUP_ACER_ASPIRE_4930G),
4510 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
4511 ALC882_FIXUP_ACER_ASPIRE_4930G),
4512 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
4513 ALC882_FIXUP_ACER_ASPIRE_8930G),
4514 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
4515 ALC882_FIXUP_ACER_ASPIRE_8930G),
4516 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
4517 ALC882_FIXUP_ACER_ASPIRE_4930G),
4518 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
4519 ALC882_FIXUP_ACER_ASPIRE_4930G),
4520 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
4521 ALC882_FIXUP_ACER_ASPIRE_4930G),
4522 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
4523 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
4524 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
4525 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
4526 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
4527 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
4528 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
4530 /* All Apple entries are in codec SSIDs */
4531 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
4532 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
4533 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
4534 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
4535 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
4537 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
4538 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
4539 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
4540 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
4541 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
4542 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
4543 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
4548 * BIOS auto configuration
4550 /* almost identical with ALC880 parser... */
4551 static int alc882_parse_auto_config(struct hda_codec *codec)
4553 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
4554 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4555 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
4560 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4561 #include "alc882_quirks.c"
4564 static int patch_alc882(struct hda_codec *codec)
4566 struct alc_spec *spec;
4567 int err, board_config;
4569 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4575 spec->mixer_nid = 0x0b;
4577 switch (codec->vendor_id) {
4582 /* ALC883 and variants */
4583 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
4587 err = alc_codec_rename_from_preset(codec);
4591 board_config = alc_board_config(codec, ALC882_MODEL_LAST,
4592 alc882_models, NULL);
4593 if (board_config < 0)
4594 board_config = alc_board_codec_sid_config(codec,
4595 ALC882_MODEL_LAST, alc882_models, alc882_ssid_cfg_tbl);
4597 if (board_config < 0) {
4598 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4600 board_config = ALC_MODEL_AUTO;
4603 if (board_config == ALC_MODEL_AUTO) {
4604 alc_pick_fixup(codec, NULL, alc882_fixup_tbl, alc882_fixups);
4605 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4608 alc_auto_parse_customize_define(codec);
4610 if (board_config == ALC_MODEL_AUTO) {
4611 /* automatic parse from the BIOS config */
4612 err = alc882_parse_auto_config(codec);
4617 if (board_config != ALC_MODEL_AUTO)
4618 setup_preset(codec, &alc882_presets[board_config]);
4620 if (!spec->no_analog && !spec->adc_nids) {
4621 alc_auto_fill_adc_caps(codec);
4622 alc_rebuild_imux_for_auto_mic(codec);
4623 alc_remove_invalid_adc_nids(codec);
4626 if (!spec->no_analog && !spec->cap_mixer)
4627 set_capture_mixer(codec);
4629 if (!spec->no_analog && has_cdefine_beep(codec)) {
4630 err = snd_hda_attach_beep_device(codec, 0x1);
4633 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4636 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4638 spec->vmaster_nid = 0x0c;
4640 codec->patch_ops = alc_patch_ops;
4641 if (board_config == ALC_MODEL_AUTO)
4642 spec->init_hook = alc_auto_init_std;
4644 #ifdef CONFIG_SND_HDA_POWER_SAVE
4645 if (!spec->loopback.amplist)
4646 spec->loopback.amplist = alc882_loopbacks;
4660 static int alc262_parse_auto_config(struct hda_codec *codec)
4662 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
4663 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4664 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
4671 ALC262_FIXUP_FSC_H270,
4672 ALC262_FIXUP_HP_Z200,
4674 ALC262_FIXUP_TOSHIBA_RX1,
4675 ALC262_FIXUP_LENOVO_3000,
4677 ALC262_FIXUP_BENQ_T31,
4680 static const struct alc_fixup alc262_fixups[] = {
4681 [ALC262_FIXUP_FSC_H270] = {
4682 .type = ALC_FIXUP_PINS,
4683 .v.pins = (const struct alc_pincfg[]) {
4684 { 0x14, 0x99130110 }, /* speaker */
4685 { 0x15, 0x0221142f }, /* front HP */
4686 { 0x1b, 0x0121141f }, /* rear HP */
4690 [ALC262_FIXUP_HP_Z200] = {
4691 .type = ALC_FIXUP_PINS,
4692 .v.pins = (const struct alc_pincfg[]) {
4693 { 0x16, 0x99130120 }, /* internal speaker */
4697 [ALC262_FIXUP_TYAN] = {
4698 .type = ALC_FIXUP_PINS,
4699 .v.pins = (const struct alc_pincfg[]) {
4700 { 0x14, 0x1993e1f0 }, /* int AUX */
4704 [ALC262_FIXUP_TOSHIBA_RX1] = {
4705 .type = ALC_FIXUP_PINS,
4706 .v.pins = (const struct alc_pincfg[]) {
4707 { 0x14, 0x90170110 }, /* speaker */
4708 { 0x15, 0x0421101f }, /* HP */
4709 { 0x1a, 0x40f000f0 }, /* N/A */
4710 { 0x1b, 0x40f000f0 }, /* N/A */
4711 { 0x1e, 0x40f000f0 }, /* N/A */
4714 [ALC262_FIXUP_LENOVO_3000] = {
4715 .type = ALC_FIXUP_VERBS,
4716 .v.verbs = (const struct hda_verb[]) {
4717 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
4721 .chain_id = ALC262_FIXUP_BENQ,
4723 [ALC262_FIXUP_BENQ] = {
4724 .type = ALC_FIXUP_VERBS,
4725 .v.verbs = (const struct hda_verb[]) {
4726 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4727 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4731 [ALC262_FIXUP_BENQ_T31] = {
4732 .type = ALC_FIXUP_VERBS,
4733 .v.verbs = (const struct hda_verb[]) {
4734 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4735 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4741 static const struct snd_pci_quirk alc262_fixup_tbl[] = {
4742 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
4743 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
4744 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
4745 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
4746 SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1",
4747 ALC262_FIXUP_TOSHIBA_RX1),
4748 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
4749 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
4750 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
4751 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
4756 #ifdef CONFIG_SND_HDA_POWER_SAVE
4757 #define alc262_loopbacks alc880_loopbacks
4762 static int patch_alc262(struct hda_codec *codec)
4764 struct alc_spec *spec;
4767 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4773 spec->mixer_nid = 0x0b;
4776 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
4781 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4782 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
4783 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4784 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
4787 alc_auto_parse_customize_define(codec);
4789 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
4791 alc_pick_fixup(codec, NULL, alc262_fixup_tbl, alc262_fixups);
4792 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4794 /* automatic parse from the BIOS config */
4795 err = alc262_parse_auto_config(codec);
4799 if (!spec->no_analog && !spec->adc_nids) {
4800 alc_auto_fill_adc_caps(codec);
4801 alc_rebuild_imux_for_auto_mic(codec);
4802 alc_remove_invalid_adc_nids(codec);
4805 if (!spec->no_analog && !spec->cap_mixer)
4806 set_capture_mixer(codec);
4808 if (!spec->no_analog && has_cdefine_beep(codec)) {
4809 err = snd_hda_attach_beep_device(codec, 0x1);
4812 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4815 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4817 spec->vmaster_nid = 0x0c;
4819 codec->patch_ops = alc_patch_ops;
4820 spec->init_hook = alc_auto_init_std;
4821 spec->shutup = alc_eapd_shutup;
4823 #ifdef CONFIG_SND_HDA_POWER_SAVE
4824 if (!spec->loopback.amplist)
4825 spec->loopback.amplist = alc262_loopbacks;
4838 /* bind Beep switches of both NID 0x0f and 0x10 */
4839 static const struct hda_bind_ctls alc268_bind_beep_sw = {
4840 .ops = &snd_hda_bind_sw,
4842 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
4843 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
4848 static const struct snd_kcontrol_new alc268_beep_mixer[] = {
4849 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
4850 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
4854 /* set PCBEEP vol = 0, mute connections */
4855 static const struct hda_verb alc268_beep_init_verbs[] = {
4856 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4857 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4858 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4863 * BIOS auto configuration
4865 static int alc268_parse_auto_config(struct hda_codec *codec)
4867 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4868 struct alc_spec *spec = codec->spec;
4869 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
4871 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
4872 add_mixer(spec, alc268_beep_mixer);
4873 add_verb(spec, alc268_beep_init_verbs);
4881 static int patch_alc268(struct hda_codec *codec)
4883 struct alc_spec *spec;
4884 int i, has_beep, err;
4886 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4892 /* ALC268 has no aa-loopback mixer */
4894 /* automatic parse from the BIOS config */
4895 err = alc268_parse_auto_config(codec);
4900 for (i = 0; i < spec->num_mixers; i++) {
4901 if (spec->mixers[i] == alc268_beep_mixer) {
4908 err = snd_hda_attach_beep_device(codec, 0x1);
4911 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
4912 /* override the amp caps for beep generator */
4913 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
4914 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
4915 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
4916 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4917 (0 << AC_AMPCAP_MUTE_SHIFT));
4920 if (!spec->no_analog && !spec->adc_nids) {
4921 alc_auto_fill_adc_caps(codec);
4922 alc_rebuild_imux_for_auto_mic(codec);
4923 alc_remove_invalid_adc_nids(codec);
4926 if (!spec->no_analog && !spec->cap_mixer)
4927 set_capture_mixer(codec);
4929 spec->vmaster_nid = 0x02;
4931 codec->patch_ops = alc_patch_ops;
4932 spec->init_hook = alc_auto_init_std;
4933 spec->shutup = alc_eapd_shutup;
4945 #ifdef CONFIG_SND_HDA_POWER_SAVE
4946 #define alc269_loopbacks alc880_loopbacks
4949 static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
4953 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
4954 /* NID is set in alc_build_pcms */
4956 .open = alc_playback_pcm_open,
4957 .prepare = alc_playback_pcm_prepare,
4958 .cleanup = alc_playback_pcm_cleanup
4962 static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
4966 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
4967 /* NID is set in alc_build_pcms */
4970 #ifdef CONFIG_SND_HDA_POWER_SAVE
4971 static int alc269_mic2_for_mute_led(struct hda_codec *codec)
4973 switch (codec->subsystem_id) {
4980 static int alc269_mic2_mute_check_ps(struct hda_codec *codec, hda_nid_t nid)
4982 /* update mute-LED according to the speaker mute state */
4983 if (nid == 0x01 || nid == 0x14) {
4985 if (snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0) &
4990 /* mic2 vref pin is used for mute LED control */
4991 snd_hda_codec_update_cache(codec, 0x19, 0,
4992 AC_VERB_SET_PIN_WIDGET_CONTROL,
4995 return alc_check_power_status(codec, nid);
4997 #endif /* CONFIG_SND_HDA_POWER_SAVE */
4999 /* different alc269-variants */
5001 ALC269_TYPE_ALC269VA,
5002 ALC269_TYPE_ALC269VB,
5003 ALC269_TYPE_ALC269VC,
5007 * BIOS auto configuration
5009 static int alc269_parse_auto_config(struct hda_codec *codec)
5011 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
5012 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
5013 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5014 struct alc_spec *spec = codec->spec;
5015 const hda_nid_t *ssids = spec->codec_variant == ALC269_TYPE_ALC269VA ?
5016 alc269va_ssids : alc269_ssids;
5018 return alc_parse_auto_config(codec, alc269_ignore, ssids);
5021 static void alc269_toggle_power_output(struct hda_codec *codec, int power_up)
5023 int val = alc_read_coef_idx(codec, 0x04);
5028 alc_write_coef_idx(codec, 0x04, val);
5031 static void alc269_shutup(struct hda_codec *codec)
5033 if ((alc_get_coef0(codec) & 0x00ff) == 0x017)
5034 alc269_toggle_power_output(codec, 0);
5035 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
5036 alc269_toggle_power_output(codec, 0);
5042 static int alc269_resume(struct hda_codec *codec)
5044 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
5045 alc269_toggle_power_output(codec, 0);
5049 codec->patch_ops.init(codec);
5051 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
5052 alc269_toggle_power_output(codec, 1);
5056 if ((alc_get_coef0(codec) & 0x00ff) == 0x018)
5057 alc269_toggle_power_output(codec, 1);
5059 snd_hda_codec_resume_amp(codec);
5060 snd_hda_codec_resume_cache(codec);
5061 hda_call_check_power_status(codec, 0x01);
5064 #endif /* CONFIG_PM */
5066 static void alc269_fixup_hweq(struct hda_codec *codec,
5067 const struct alc_fixup *fix, int action)
5071 if (action != ALC_FIXUP_ACT_INIT)
5073 coef = alc_read_coef_idx(codec, 0x1e);
5074 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
5077 static void alc271_fixup_dmic(struct hda_codec *codec,
5078 const struct alc_fixup *fix, int action)
5080 static const struct hda_verb verbs[] = {
5081 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
5082 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
5087 if (strcmp(codec->chip_name, "ALC271X"))
5089 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
5090 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
5091 snd_hda_sequence_write(codec, verbs);
5094 static void alc269_fixup_pcm_44k(struct hda_codec *codec,
5095 const struct alc_fixup *fix, int action)
5097 struct alc_spec *spec = codec->spec;
5099 if (action != ALC_FIXUP_ACT_PROBE)
5102 /* Due to a hardware problem on Lenovo Ideadpad, we need to
5103 * fix the sample rate of analog I/O to 44.1kHz
5105 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
5106 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
5109 static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
5110 const struct alc_fixup *fix, int action)
5114 if (action != ALC_FIXUP_ACT_INIT)
5116 /* The digital-mic unit sends PDM (differential signal) instead of
5117 * the standard PCM, thus you can't record a valid mono stream as is.
5118 * Below is a workaround specific to ALC269 to control the dmic
5119 * signal source as mono.
5121 coef = alc_read_coef_idx(codec, 0x07);
5122 alc_write_coef_idx(codec, 0x07, coef | 0x80);
5125 static void alc269_quanta_automute(struct hda_codec *codec)
5127 update_outputs(codec);
5129 snd_hda_codec_write(codec, 0x20, 0,
5130 AC_VERB_SET_COEF_INDEX, 0x0c);
5131 snd_hda_codec_write(codec, 0x20, 0,
5132 AC_VERB_SET_PROC_COEF, 0x680);
5134 snd_hda_codec_write(codec, 0x20, 0,
5135 AC_VERB_SET_COEF_INDEX, 0x0c);
5136 snd_hda_codec_write(codec, 0x20, 0,
5137 AC_VERB_SET_PROC_COEF, 0x480);
5140 static void alc269_fixup_quanta_mute(struct hda_codec *codec,
5141 const struct alc_fixup *fix, int action)
5143 struct alc_spec *spec = codec->spec;
5144 if (action != ALC_FIXUP_ACT_PROBE)
5146 spec->automute_hook = alc269_quanta_automute;
5150 ALC269_FIXUP_SONY_VAIO,
5151 ALC275_FIXUP_SONY_VAIO_GPIO2,
5152 ALC269_FIXUP_DELL_M101Z,
5153 ALC269_FIXUP_SKU_IGNORE,
5154 ALC269_FIXUP_ASUS_G73JW,
5155 ALC269_FIXUP_LENOVO_EAPD,
5156 ALC275_FIXUP_SONY_HWEQ,
5158 ALC269_FIXUP_PCM_44K,
5159 ALC269_FIXUP_STEREO_DMIC,
5160 ALC269_FIXUP_QUANTA_MUTE,
5161 ALC269_FIXUP_LIFEBOOK,
5164 ALC269VB_FIXUP_AMIC,
5165 ALC269VB_FIXUP_DMIC,
5168 static const struct alc_fixup alc269_fixups[] = {
5169 [ALC269_FIXUP_SONY_VAIO] = {
5170 .type = ALC_FIXUP_VERBS,
5171 .v.verbs = (const struct hda_verb[]) {
5172 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
5176 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
5177 .type = ALC_FIXUP_VERBS,
5178 .v.verbs = (const struct hda_verb[]) {
5179 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
5180 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
5181 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5185 .chain_id = ALC269_FIXUP_SONY_VAIO
5187 [ALC269_FIXUP_DELL_M101Z] = {
5188 .type = ALC_FIXUP_VERBS,
5189 .v.verbs = (const struct hda_verb[]) {
5190 /* Enables internal speaker */
5191 {0x20, AC_VERB_SET_COEF_INDEX, 13},
5192 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
5196 [ALC269_FIXUP_SKU_IGNORE] = {
5197 .type = ALC_FIXUP_SKU,
5198 .v.sku = ALC_FIXUP_SKU_IGNORE,
5200 [ALC269_FIXUP_ASUS_G73JW] = {
5201 .type = ALC_FIXUP_PINS,
5202 .v.pins = (const struct alc_pincfg[]) {
5203 { 0x17, 0x99130111 }, /* subwoofer */
5207 [ALC269_FIXUP_LENOVO_EAPD] = {
5208 .type = ALC_FIXUP_VERBS,
5209 .v.verbs = (const struct hda_verb[]) {
5210 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
5214 [ALC275_FIXUP_SONY_HWEQ] = {
5215 .type = ALC_FIXUP_FUNC,
5216 .v.func = alc269_fixup_hweq,
5218 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
5220 [ALC271_FIXUP_DMIC] = {
5221 .type = ALC_FIXUP_FUNC,
5222 .v.func = alc271_fixup_dmic,
5224 [ALC269_FIXUP_PCM_44K] = {
5225 .type = ALC_FIXUP_FUNC,
5226 .v.func = alc269_fixup_pcm_44k,
5228 [ALC269_FIXUP_STEREO_DMIC] = {
5229 .type = ALC_FIXUP_FUNC,
5230 .v.func = alc269_fixup_stereo_dmic,
5232 [ALC269_FIXUP_QUANTA_MUTE] = {
5233 .type = ALC_FIXUP_FUNC,
5234 .v.func = alc269_fixup_quanta_mute,
5236 [ALC269_FIXUP_LIFEBOOK] = {
5237 .type = ALC_FIXUP_PINS,
5238 .v.pins = (const struct alc_pincfg[]) {
5239 { 0x1a, 0x2101103f }, /* dock line-out */
5240 { 0x1b, 0x23a11040 }, /* dock mic-in */
5244 .chain_id = ALC269_FIXUP_QUANTA_MUTE
5246 [ALC269_FIXUP_AMIC] = {
5247 .type = ALC_FIXUP_PINS,
5248 .v.pins = (const struct alc_pincfg[]) {
5249 { 0x14, 0x99130110 }, /* speaker */
5250 { 0x15, 0x0121401f }, /* HP out */
5251 { 0x18, 0x01a19c20 }, /* mic */
5252 { 0x19, 0x99a3092f }, /* int-mic */
5256 [ALC269_FIXUP_DMIC] = {
5257 .type = ALC_FIXUP_PINS,
5258 .v.pins = (const struct alc_pincfg[]) {
5259 { 0x12, 0x99a3092f }, /* int-mic */
5260 { 0x14, 0x99130110 }, /* speaker */
5261 { 0x15, 0x0121401f }, /* HP out */
5262 { 0x18, 0x01a19c20 }, /* mic */
5266 [ALC269VB_FIXUP_AMIC] = {
5267 .type = ALC_FIXUP_PINS,
5268 .v.pins = (const struct alc_pincfg[]) {
5269 { 0x14, 0x99130110 }, /* speaker */
5270 { 0x18, 0x01a19c20 }, /* mic */
5271 { 0x19, 0x99a3092f }, /* int-mic */
5272 { 0x21, 0x0121401f }, /* HP out */
5276 [ALC269_FIXUP_DMIC] = {
5277 .type = ALC_FIXUP_PINS,
5278 .v.pins = (const struct alc_pincfg[]) {
5279 { 0x12, 0x99a3092f }, /* int-mic */
5280 { 0x14, 0x99130110 }, /* speaker */
5281 { 0x18, 0x01a19c20 }, /* mic */
5282 { 0x21, 0x0121401f }, /* HP out */
5288 static const struct snd_pci_quirk alc269_fixup_tbl[] = {
5289 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
5290 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
5291 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
5292 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
5293 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
5294 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
5295 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
5296 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
5297 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
5298 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
5299 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
5300 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
5301 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
5302 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
5303 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
5304 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
5305 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
5306 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
5307 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_QUANTA_MUTE),
5308 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K),
5309 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
5312 /* Below is a quirk table taken from the old code.
5313 * Basically the device should work as is without the fixup table.
5314 * If BIOS doesn't give a proper info, enable the corresponding
5317 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
5319 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
5320 SND_PCI_QUIRK(0x1043, 0x1113, "ASUS N63Jn", ALC269_FIXUP_AMIC),
5321 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
5322 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
5323 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
5324 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
5325 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
5326 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
5327 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
5328 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
5329 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
5330 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
5331 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
5332 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
5333 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
5334 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
5335 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
5336 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
5337 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
5338 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
5339 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
5340 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
5341 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
5342 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
5343 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
5344 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
5345 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
5346 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
5347 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
5348 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
5349 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
5350 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
5351 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
5352 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
5353 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
5354 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
5355 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
5356 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
5357 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
5358 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
5363 static const struct alc_model_fixup alc269_fixup_models[] = {
5364 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
5365 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
5370 static int alc269_fill_coef(struct hda_codec *codec)
5374 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
5375 alc_write_coef_idx(codec, 0xf, 0x960b);
5376 alc_write_coef_idx(codec, 0xe, 0x8817);
5379 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
5380 alc_write_coef_idx(codec, 0xf, 0x960b);
5381 alc_write_coef_idx(codec, 0xe, 0x8814);
5384 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
5385 val = alc_read_coef_idx(codec, 0x04);
5386 /* Power up output pin */
5387 alc_write_coef_idx(codec, 0x04, val | (1<<11));
5390 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
5391 val = alc_read_coef_idx(codec, 0xd);
5392 if ((val & 0x0c00) >> 10 != 0x1) {
5393 /* Capless ramp up clock control */
5394 alc_write_coef_idx(codec, 0xd, val | (1<<10));
5396 val = alc_read_coef_idx(codec, 0x17);
5397 if ((val & 0x01c0) >> 6 != 0x4) {
5398 /* Class D power on reset */
5399 alc_write_coef_idx(codec, 0x17, val | (1<<7));
5403 val = alc_read_coef_idx(codec, 0xd); /* Class D */
5404 alc_write_coef_idx(codec, 0xd, val | (1<<14));
5406 val = alc_read_coef_idx(codec, 0x4); /* HP */
5407 alc_write_coef_idx(codec, 0x4, val | (1<<11));
5414 static int patch_alc269(struct hda_codec *codec)
5416 struct alc_spec *spec;
5419 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5425 spec->mixer_nid = 0x0b;
5427 alc_auto_parse_customize_define(codec);
5429 err = alc_codec_rename_from_preset(codec);
5433 if (codec->vendor_id == 0x10ec0269) {
5434 spec->codec_variant = ALC269_TYPE_ALC269VA;
5435 switch (alc_get_coef0(codec) & 0x00f0) {
5437 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
5438 spec->cdefine.platform_type == 1)
5439 err = alc_codec_rename(codec, "ALC271X");
5440 spec->codec_variant = ALC269_TYPE_ALC269VB;
5443 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
5444 codec->bus->pci->subsystem_device == 0x21f3)
5445 err = alc_codec_rename(codec, "ALC3202");
5446 spec->codec_variant = ALC269_TYPE_ALC269VC;
5449 alc_fix_pll_init(codec, 0x20, 0x04, 15);
5453 alc269_fill_coef(codec);
5456 alc_pick_fixup(codec, alc269_fixup_models,
5457 alc269_fixup_tbl, alc269_fixups);
5458 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5460 /* automatic parse from the BIOS config */
5461 err = alc269_parse_auto_config(codec);
5465 if (!spec->no_analog && !spec->adc_nids) {
5466 alc_auto_fill_adc_caps(codec);
5467 alc_rebuild_imux_for_auto_mic(codec);
5468 alc_remove_invalid_adc_nids(codec);
5471 if (!spec->no_analog && !spec->cap_mixer)
5472 set_capture_mixer(codec);
5474 if (!spec->no_analog && has_cdefine_beep(codec)) {
5475 err = snd_hda_attach_beep_device(codec, 0x1);
5478 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
5481 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5483 spec->vmaster_nid = 0x02;
5485 codec->patch_ops = alc_patch_ops;
5487 codec->patch_ops.resume = alc269_resume;
5489 spec->init_hook = alc_auto_init_std;
5490 spec->shutup = alc269_shutup;
5492 #ifdef CONFIG_SND_HDA_POWER_SAVE
5493 if (!spec->loopback.amplist)
5494 spec->loopback.amplist = alc269_loopbacks;
5495 if (alc269_mic2_for_mute_led(codec))
5496 codec->patch_ops.check_power_status = alc269_mic2_mute_check_ps;
5510 static int alc861_parse_auto_config(struct hda_codec *codec)
5512 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
5513 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
5514 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
5517 #ifdef CONFIG_SND_HDA_POWER_SAVE
5518 static const struct hda_amp_list alc861_loopbacks[] = {
5519 { 0x15, HDA_INPUT, 0 },
5520 { 0x15, HDA_INPUT, 1 },
5521 { 0x15, HDA_INPUT, 2 },
5522 { 0x15, HDA_INPUT, 3 },
5528 /* Pin config fixes */
5530 PINFIX_FSC_AMILO_PI1505,
5533 static const struct alc_fixup alc861_fixups[] = {
5534 [PINFIX_FSC_AMILO_PI1505] = {
5535 .type = ALC_FIXUP_PINS,
5536 .v.pins = (const struct alc_pincfg[]) {
5537 { 0x0b, 0x0221101f }, /* HP */
5538 { 0x0f, 0x90170310 }, /* speaker */
5544 static const struct snd_pci_quirk alc861_fixup_tbl[] = {
5545 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", PINFIX_FSC_AMILO_PI1505),
5551 static int patch_alc861(struct hda_codec *codec)
5553 struct alc_spec *spec;
5556 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5562 spec->mixer_nid = 0x15;
5564 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
5565 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5567 /* automatic parse from the BIOS config */
5568 err = alc861_parse_auto_config(codec);
5572 if (!spec->no_analog && !spec->adc_nids) {
5573 alc_auto_fill_adc_caps(codec);
5574 alc_rebuild_imux_for_auto_mic(codec);
5575 alc_remove_invalid_adc_nids(codec);
5578 if (!spec->no_analog && !spec->cap_mixer)
5579 set_capture_mixer(codec);
5581 if (!spec->no_analog) {
5582 err = snd_hda_attach_beep_device(codec, 0x23);
5585 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
5588 spec->vmaster_nid = 0x03;
5590 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5592 codec->patch_ops = alc_patch_ops;
5593 spec->init_hook = alc_auto_init_std;
5594 #ifdef CONFIG_SND_HDA_POWER_SAVE
5595 spec->power_hook = alc_power_eapd;
5596 if (!spec->loopback.amplist)
5597 spec->loopback.amplist = alc861_loopbacks;
5612 * In addition, an independent DAC
5614 #ifdef CONFIG_SND_HDA_POWER_SAVE
5615 #define alc861vd_loopbacks alc880_loopbacks
5618 static int alc861vd_parse_auto_config(struct hda_codec *codec)
5620 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
5621 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5622 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
5626 ALC660VD_FIX_ASUS_GPIO1,
5627 ALC861VD_FIX_DALLAS,
5630 /* exclude VREF80 */
5631 static void alc861vd_fixup_dallas(struct hda_codec *codec,
5632 const struct alc_fixup *fix, int action)
5634 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
5635 snd_hda_override_pin_caps(codec, 0x18, 0x00001714);
5636 snd_hda_override_pin_caps(codec, 0x19, 0x0000171c);
5640 static const struct alc_fixup alc861vd_fixups[] = {
5641 [ALC660VD_FIX_ASUS_GPIO1] = {
5642 .type = ALC_FIXUP_VERBS,
5643 .v.verbs = (const struct hda_verb[]) {
5645 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
5646 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5647 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5651 [ALC861VD_FIX_DALLAS] = {
5652 .type = ALC_FIXUP_FUNC,
5653 .v.func = alc861vd_fixup_dallas,
5657 static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
5658 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
5659 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
5660 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
5664 static const struct hda_verb alc660vd_eapd_verbs[] = {
5665 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
5666 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
5672 static int patch_alc861vd(struct hda_codec *codec)
5674 struct alc_spec *spec;
5677 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5683 spec->mixer_nid = 0x0b;
5685 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
5686 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5688 /* automatic parse from the BIOS config */
5689 err = alc861vd_parse_auto_config(codec);
5693 if (codec->vendor_id == 0x10ec0660) {
5694 /* always turn on EAPD */
5695 add_verb(spec, alc660vd_eapd_verbs);
5698 if (!spec->no_analog && !spec->adc_nids) {
5699 alc_auto_fill_adc_caps(codec);
5700 alc_rebuild_imux_for_auto_mic(codec);
5701 alc_remove_invalid_adc_nids(codec);
5704 if (!spec->no_analog && !spec->cap_mixer)
5705 set_capture_mixer(codec);
5707 if (!spec->no_analog) {
5708 err = snd_hda_attach_beep_device(codec, 0x23);
5711 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5714 spec->vmaster_nid = 0x02;
5716 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5718 codec->patch_ops = alc_patch_ops;
5720 spec->init_hook = alc_auto_init_std;
5721 spec->shutup = alc_eapd_shutup;
5722 #ifdef CONFIG_SND_HDA_POWER_SAVE
5723 if (!spec->loopback.amplist)
5724 spec->loopback.amplist = alc861vd_loopbacks;
5737 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
5738 * configuration. Each pin widget can choose any input DACs and a mixer.
5739 * Each ADC is connected from a mixer of all inputs. This makes possible
5740 * 6-channel independent captures.
5742 * In addition, an independent DAC for the multi-playback (not used in this
5745 #ifdef CONFIG_SND_HDA_POWER_SAVE
5746 #define alc662_loopbacks alc880_loopbacks
5750 * BIOS auto configuration
5753 static int alc662_parse_auto_config(struct hda_codec *codec)
5755 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
5756 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
5757 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5758 const hda_nid_t *ssids;
5760 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
5761 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
5762 ssids = alc663_ssids;
5764 ssids = alc662_ssids;
5765 return alc_parse_auto_config(codec, alc662_ignore, ssids);
5768 static void alc272_fixup_mario(struct hda_codec *codec,
5769 const struct alc_fixup *fix, int action)
5771 if (action != ALC_FIXUP_ACT_PROBE)
5773 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
5774 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
5775 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
5776 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5777 (0 << AC_AMPCAP_MUTE_SHIFT)))
5779 "hda_codec: failed to override amp caps for NID 0x2\n");
5783 ALC662_FIXUP_ASPIRE,
5784 ALC662_FIXUP_IDEAPAD,
5786 ALC662_FIXUP_CZC_P10T,
5787 ALC662_FIXUP_SKU_IGNORE,
5788 ALC662_FIXUP_HP_RP5800,
5789 ALC662_FIXUP_ASUS_MODE1,
5790 ALC662_FIXUP_ASUS_MODE2,
5791 ALC662_FIXUP_ASUS_MODE3,
5792 ALC662_FIXUP_ASUS_MODE4,
5793 ALC662_FIXUP_ASUS_MODE5,
5794 ALC662_FIXUP_ASUS_MODE6,
5795 ALC662_FIXUP_ASUS_MODE7,
5796 ALC662_FIXUP_ASUS_MODE8,
5799 static const struct alc_fixup alc662_fixups[] = {
5800 [ALC662_FIXUP_ASPIRE] = {
5801 .type = ALC_FIXUP_PINS,
5802 .v.pins = (const struct alc_pincfg[]) {
5803 { 0x15, 0x99130112 }, /* subwoofer */
5807 [ALC662_FIXUP_IDEAPAD] = {
5808 .type = ALC_FIXUP_PINS,
5809 .v.pins = (const struct alc_pincfg[]) {
5810 { 0x17, 0x99130112 }, /* subwoofer */
5814 [ALC272_FIXUP_MARIO] = {
5815 .type = ALC_FIXUP_FUNC,
5816 .v.func = alc272_fixup_mario,
5818 [ALC662_FIXUP_CZC_P10T] = {
5819 .type = ALC_FIXUP_VERBS,
5820 .v.verbs = (const struct hda_verb[]) {
5821 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
5825 [ALC662_FIXUP_SKU_IGNORE] = {
5826 .type = ALC_FIXUP_SKU,
5827 .v.sku = ALC_FIXUP_SKU_IGNORE,
5829 [ALC662_FIXUP_HP_RP5800] = {
5830 .type = ALC_FIXUP_PINS,
5831 .v.pins = (const struct alc_pincfg[]) {
5832 { 0x14, 0x0221201f }, /* HP out */
5836 .chain_id = ALC662_FIXUP_SKU_IGNORE
5838 [ALC662_FIXUP_ASUS_MODE1] = {
5839 .type = ALC_FIXUP_PINS,
5840 .v.pins = (const struct alc_pincfg[]) {
5841 { 0x14, 0x99130110 }, /* speaker */
5842 { 0x18, 0x01a19c20 }, /* mic */
5843 { 0x19, 0x99a3092f }, /* int-mic */
5844 { 0x21, 0x0121401f }, /* HP out */
5848 .chain_id = ALC662_FIXUP_SKU_IGNORE
5850 [ALC662_FIXUP_ASUS_MODE2] = {
5851 .type = ALC_FIXUP_PINS,
5852 .v.pins = (const struct alc_pincfg[]) {
5853 { 0x14, 0x99130110 }, /* speaker */
5854 { 0x18, 0x01a19820 }, /* mic */
5855 { 0x19, 0x99a3092f }, /* int-mic */
5856 { 0x1b, 0x0121401f }, /* HP out */
5860 .chain_id = ALC662_FIXUP_SKU_IGNORE
5862 [ALC662_FIXUP_ASUS_MODE3] = {
5863 .type = ALC_FIXUP_PINS,
5864 .v.pins = (const struct alc_pincfg[]) {
5865 { 0x14, 0x99130110 }, /* speaker */
5866 { 0x15, 0x0121441f }, /* HP */
5867 { 0x18, 0x01a19840 }, /* mic */
5868 { 0x19, 0x99a3094f }, /* int-mic */
5869 { 0x21, 0x01211420 }, /* HP2 */
5873 .chain_id = ALC662_FIXUP_SKU_IGNORE
5875 [ALC662_FIXUP_ASUS_MODE4] = {
5876 .type = ALC_FIXUP_PINS,
5877 .v.pins = (const struct alc_pincfg[]) {
5878 { 0x14, 0x99130110 }, /* speaker */
5879 { 0x16, 0x99130111 }, /* speaker */
5880 { 0x18, 0x01a19840 }, /* mic */
5881 { 0x19, 0x99a3094f }, /* int-mic */
5882 { 0x21, 0x0121441f }, /* HP */
5886 .chain_id = ALC662_FIXUP_SKU_IGNORE
5888 [ALC662_FIXUP_ASUS_MODE5] = {
5889 .type = ALC_FIXUP_PINS,
5890 .v.pins = (const struct alc_pincfg[]) {
5891 { 0x14, 0x99130110 }, /* speaker */
5892 { 0x15, 0x0121441f }, /* HP */
5893 { 0x16, 0x99130111 }, /* speaker */
5894 { 0x18, 0x01a19840 }, /* mic */
5895 { 0x19, 0x99a3094f }, /* int-mic */
5899 .chain_id = ALC662_FIXUP_SKU_IGNORE
5901 [ALC662_FIXUP_ASUS_MODE6] = {
5902 .type = ALC_FIXUP_PINS,
5903 .v.pins = (const struct alc_pincfg[]) {
5904 { 0x14, 0x99130110 }, /* speaker */
5905 { 0x15, 0x01211420 }, /* HP2 */
5906 { 0x18, 0x01a19840 }, /* mic */
5907 { 0x19, 0x99a3094f }, /* int-mic */
5908 { 0x1b, 0x0121441f }, /* HP */
5912 .chain_id = ALC662_FIXUP_SKU_IGNORE
5914 [ALC662_FIXUP_ASUS_MODE7] = {
5915 .type = ALC_FIXUP_PINS,
5916 .v.pins = (const struct alc_pincfg[]) {
5917 { 0x14, 0x99130110 }, /* speaker */
5918 { 0x17, 0x99130111 }, /* speaker */
5919 { 0x18, 0x01a19840 }, /* mic */
5920 { 0x19, 0x99a3094f }, /* int-mic */
5921 { 0x1b, 0x01214020 }, /* HP */
5922 { 0x21, 0x0121401f }, /* HP */
5926 .chain_id = ALC662_FIXUP_SKU_IGNORE
5928 [ALC662_FIXUP_ASUS_MODE8] = {
5929 .type = ALC_FIXUP_PINS,
5930 .v.pins = (const struct alc_pincfg[]) {
5931 { 0x14, 0x99130110 }, /* speaker */
5932 { 0x12, 0x99a30970 }, /* int-mic */
5933 { 0x15, 0x01214020 }, /* HP */
5934 { 0x17, 0x99130111 }, /* speaker */
5935 { 0x18, 0x01a19840 }, /* mic */
5936 { 0x21, 0x0121401f }, /* HP */
5940 .chain_id = ALC662_FIXUP_SKU_IGNORE
5944 static const struct snd_pci_quirk alc662_fixup_tbl[] = {
5945 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
5946 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
5947 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
5948 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
5949 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
5950 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
5951 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
5952 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
5953 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
5954 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
5957 /* Below is a quirk table taken from the old code.
5958 * Basically the device should work as is without the fixup table.
5959 * If BIOS doesn't give a proper info, enable the corresponding
5962 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
5963 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
5964 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
5965 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
5966 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
5967 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5968 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
5969 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
5970 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
5971 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5972 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
5973 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
5974 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
5975 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
5976 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
5977 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5978 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
5979 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
5980 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5981 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
5982 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
5983 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5984 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
5985 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
5986 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
5987 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5988 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
5989 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
5990 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5991 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
5992 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5993 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5994 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
5995 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
5996 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
5997 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
5998 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
5999 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
6000 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
6001 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6002 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
6003 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
6004 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6005 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
6006 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
6007 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
6008 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
6009 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
6010 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6011 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
6016 static const struct alc_model_fixup alc662_fixup_models[] = {
6017 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
6018 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
6019 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
6020 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
6021 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
6022 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
6023 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
6024 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
6025 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
6032 static int patch_alc662(struct hda_codec *codec)
6034 struct alc_spec *spec;
6037 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6043 spec->mixer_nid = 0x0b;
6045 /* handle multiple HPs as is */
6046 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
6048 alc_auto_parse_customize_define(codec);
6050 alc_fix_pll_init(codec, 0x20, 0x04, 15);
6052 err = alc_codec_rename_from_preset(codec);
6056 if ((alc_get_coef0(codec) & (1 << 14)) &&
6057 codec->bus->pci->subsystem_vendor == 0x1025 &&
6058 spec->cdefine.platform_type == 1) {
6059 if (alc_codec_rename(codec, "ALC272X") < 0)
6063 alc_pick_fixup(codec, alc662_fixup_models,
6064 alc662_fixup_tbl, alc662_fixups);
6065 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6066 /* automatic parse from the BIOS config */
6067 err = alc662_parse_auto_config(codec);
6071 if (!spec->no_analog && !spec->adc_nids) {
6072 alc_auto_fill_adc_caps(codec);
6073 alc_rebuild_imux_for_auto_mic(codec);
6074 alc_remove_invalid_adc_nids(codec);
6077 if (!spec->no_analog && !spec->cap_mixer)
6078 set_capture_mixer(codec);
6080 if (!spec->no_analog && has_cdefine_beep(codec)) {
6081 err = snd_hda_attach_beep_device(codec, 0x1);
6084 switch (codec->vendor_id) {
6086 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6091 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
6094 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
6098 spec->vmaster_nid = 0x02;
6100 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6102 codec->patch_ops = alc_patch_ops;
6103 spec->init_hook = alc_auto_init_std;
6104 spec->shutup = alc_eapd_shutup;
6106 #ifdef CONFIG_SND_HDA_POWER_SAVE
6107 if (!spec->loopback.amplist)
6108 spec->loopback.amplist = alc662_loopbacks;
6122 static int alc680_parse_auto_config(struct hda_codec *codec)
6124 return alc_parse_auto_config(codec, NULL, NULL);
6129 static int patch_alc680(struct hda_codec *codec)
6131 struct alc_spec *spec;
6134 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6140 /* ALC680 has no aa-loopback mixer */
6142 /* automatic parse from the BIOS config */
6143 err = alc680_parse_auto_config(codec);
6149 if (!spec->no_analog && !spec->cap_mixer)
6150 set_capture_mixer(codec);
6152 spec->vmaster_nid = 0x02;
6154 codec->patch_ops = alc_patch_ops;
6155 spec->init_hook = alc_auto_init_std;
6163 static const struct hda_codec_preset snd_hda_preset_realtek[] = {
6164 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
6165 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
6166 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
6167 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
6168 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
6169 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
6170 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
6171 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
6172 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
6173 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
6174 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
6175 .patch = patch_alc861 },
6176 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
6177 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
6178 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
6179 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
6180 .patch = patch_alc882 },
6181 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
6182 .patch = patch_alc662 },
6183 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
6184 .patch = patch_alc662 },
6185 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
6186 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
6187 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
6188 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
6189 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
6190 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
6191 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
6192 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
6193 .patch = patch_alc882 },
6194 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
6195 .patch = patch_alc882 },
6196 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
6197 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
6198 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
6199 .patch = patch_alc882 },
6200 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
6201 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
6202 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
6203 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
6207 MODULE_ALIAS("snd-hda-codec-id:10ec*");
6209 MODULE_LICENSE("GPL");
6210 MODULE_DESCRIPTION("Realtek HD-audio codec");
6212 static struct hda_codec_preset_list realtek_list = {
6213 .preset = snd_hda_preset_realtek,
6214 .owner = THIS_MODULE,
6217 static int __init patch_realtek_init(void)
6219 return snd_hda_add_codec_preset(&realtek_list);
6222 static void __exit patch_realtek_exit(void)
6224 snd_hda_delete_codec_preset(&realtek_list);
6227 module_init(patch_realtek_init)
6228 module_exit(patch_realtek_exit)