2 * Universal Interface for Intel High Definition Audio Codec
4 * HD audio interface patch for Realtek ALC codecs
6 * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
7 * PeiSen Hou <pshou@realtek.com.tw>
8 * Takashi Iwai <tiwai@suse.de>
9 * Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
11 * This driver is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This driver is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include <linux/init.h>
27 #include <linux/delay.h>
28 #include <linux/slab.h>
29 #include <linux/pci.h>
30 #include <linux/module.h>
31 #include <sound/core.h>
32 #include <sound/jack.h>
33 #include "hda_codec.h"
34 #include "hda_local.h"
37 /* unsol event tags */
38 #define ALC_FRONT_EVENT 0x01
39 #define ALC_DCVOL_EVENT 0x02
40 #define ALC_HP_EVENT 0x04
41 #define ALC_MIC_EVENT 0x08
44 #define GPIO_MASK 0x03
46 /* extra amp-initialization sequence types */
55 struct alc_customize_define {
57 unsigned char port_connectivity;
58 unsigned char check_sum;
59 unsigned char customization;
60 unsigned char external_amp;
61 unsigned int enable_pcbeep:1;
62 unsigned int platform_type:1;
64 unsigned int override:1;
65 unsigned int fixup:1; /* Means that this sku is set by driver, not read from hw */
71 hda_nid_t pin; /* multi-io widget pin NID */
72 hda_nid_t dac; /* DAC to be connected */
73 unsigned int ctl_in; /* cached input-pin control value */
77 ALC_AUTOMUTE_PIN, /* change the pin control */
78 ALC_AUTOMUTE_AMP, /* mute/unmute the pin AMP */
79 ALC_AUTOMUTE_MIXER, /* mute/unmute mixer widget AMP */
83 /* codec parameterization */
84 const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */
85 unsigned int num_mixers;
86 const struct snd_kcontrol_new *cap_mixer; /* capture mixer */
87 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
89 const struct hda_verb *init_verbs[10]; /* initialization verbs
93 unsigned int num_init_verbs;
95 char stream_name_analog[32]; /* analog PCM stream */
96 const struct hda_pcm_stream *stream_analog_playback;
97 const struct hda_pcm_stream *stream_analog_capture;
98 const struct hda_pcm_stream *stream_analog_alt_playback;
99 const struct hda_pcm_stream *stream_analog_alt_capture;
101 char stream_name_digital[32]; /* digital PCM stream */
102 const struct hda_pcm_stream *stream_digital_playback;
103 const struct hda_pcm_stream *stream_digital_capture;
106 struct hda_multi_out multiout; /* playback set-up
107 * max_channels, dacs must be set
108 * dig_out_nid and hp_nid are optional
110 hda_nid_t alt_dac_nid;
111 hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */
115 unsigned int num_adc_nids;
116 const hda_nid_t *adc_nids;
117 const hda_nid_t *capsrc_nids;
118 hda_nid_t dig_in_nid; /* digital-in NID; optional */
119 hda_nid_t mixer_nid; /* analog-mixer NID */
120 DECLARE_BITMAP(vol_ctls, 0x20 << 1);
121 DECLARE_BITMAP(sw_ctls, 0x20 << 1);
123 /* capture setup for dynamic dual-adc switch */
125 unsigned int cur_adc_stream_tag;
126 unsigned int cur_adc_format;
129 unsigned int num_mux_defs;
130 const struct hda_input_mux *input_mux;
131 unsigned int cur_mux[3];
132 hda_nid_t ext_mic_pin;
133 hda_nid_t dock_mic_pin;
134 hda_nid_t int_mic_pin;
137 const struct hda_channel_mode *channel_mode;
138 int num_channel_mode;
140 int const_channel_count;
141 int ext_channel_count;
143 /* PCM information */
144 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
146 /* dynamic controls, init_verbs and input_mux */
147 struct auto_pin_cfg autocfg;
148 struct alc_customize_define cdefine;
149 struct snd_array kctls;
150 struct hda_input_mux private_imux[3];
151 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
152 hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS];
153 hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS];
154 hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS];
155 unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS];
156 int int_mic_idx, ext_mic_idx, dock_mic_idx; /* for auto-mic */
159 void (*init_hook)(struct hda_codec *codec);
160 void (*unsol_event)(struct hda_codec *codec, unsigned int res);
161 #ifdef CONFIG_SND_HDA_POWER_SAVE
162 void (*power_hook)(struct hda_codec *codec);
164 void (*shutup)(struct hda_codec *codec);
165 void (*automute_hook)(struct hda_codec *codec);
167 /* for pin sensing */
168 unsigned int hp_jack_present:1;
169 unsigned int line_jack_present:1;
170 unsigned int master_mute:1;
171 unsigned int auto_mic:1;
172 unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */
173 unsigned int automute_speaker:1; /* automute speaker outputs */
174 unsigned int automute_lo:1; /* automute LO outputs */
175 unsigned int detect_hp:1; /* Headphone detection enabled */
176 unsigned int detect_lo:1; /* Line-out detection enabled */
177 unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */
178 unsigned int automute_lo_possible:1; /* there are line outs and HP */
181 unsigned int no_analog :1; /* digital I/O only */
182 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
183 unsigned int single_input_src:1;
184 unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */
185 unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */
186 unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */
188 /* auto-mute control */
190 hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS];
193 int codec_variant; /* flag for other variants */
195 /* for virtual master */
196 hda_nid_t vmaster_nid;
197 #ifdef CONFIG_SND_HDA_POWER_SAVE
198 struct hda_loopback_check loopback;
203 unsigned int pll_coef_idx, pll_coef_bit;
208 const struct alc_fixup *fixup_list;
209 const char *fixup_name;
213 struct alc_multi_io multi_io[4];
216 struct snd_array bind_ctls;
219 #define ALC_MODEL_AUTO 0 /* common for all chips */
221 static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
222 int dir, unsigned int bits)
226 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
227 if (query_amp_caps(codec, nid, dir) & bits)
232 #define nid_has_mute(codec, nid, dir) \
233 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
234 #define nid_has_volume(codec, nid, dir) \
235 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
240 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
241 struct snd_ctl_elem_info *uinfo)
243 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
244 struct alc_spec *spec = codec->spec;
245 unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
246 if (mux_idx >= spec->num_mux_defs)
248 if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
250 return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
253 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
254 struct snd_ctl_elem_value *ucontrol)
256 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
257 struct alc_spec *spec = codec->spec;
258 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
260 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
264 static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
266 struct alc_spec *spec = codec->spec;
267 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
269 if (spec->cur_adc && spec->cur_adc != new_adc) {
270 /* stream is running, let's swap the current ADC */
271 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
272 spec->cur_adc = new_adc;
273 snd_hda_codec_setup_stream(codec, new_adc,
274 spec->cur_adc_stream_tag, 0,
275 spec->cur_adc_format);
281 static inline hda_nid_t get_capsrc(struct alc_spec *spec, int idx)
283 return spec->capsrc_nids ?
284 spec->capsrc_nids[idx] : spec->adc_nids[idx];
287 static void call_update_outputs(struct hda_codec *codec);
289 /* select the given imux item; either unmute exclusively or select the route */
290 static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
291 unsigned int idx, bool force)
293 struct alc_spec *spec = codec->spec;
294 const struct hda_input_mux *imux;
295 unsigned int mux_idx;
296 int i, type, num_conns;
299 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
300 imux = &spec->input_mux[mux_idx];
301 if (!imux->num_items && mux_idx > 0)
302 imux = &spec->input_mux[0];
303 if (!imux->num_items)
306 if (idx >= imux->num_items)
307 idx = imux->num_items - 1;
308 if (spec->cur_mux[adc_idx] == idx && !force)
310 spec->cur_mux[adc_idx] = idx;
312 /* for shared I/O, change the pin-control accordingly */
313 if (spec->shared_mic_hp) {
314 /* NOTE: this assumes that there are only two inputs, the
315 * first is the real internal mic and the second is HP jack.
317 snd_hda_codec_write(codec, spec->autocfg.inputs[1].pin, 0,
318 AC_VERB_SET_PIN_WIDGET_CONTROL,
319 spec->cur_mux[adc_idx] ?
320 PIN_VREF80 : PIN_HP);
321 spec->automute_speaker = !spec->cur_mux[adc_idx];
322 call_update_outputs(codec);
325 if (spec->dyn_adc_switch) {
326 alc_dyn_adc_pcm_resetup(codec, idx);
327 adc_idx = spec->dyn_adc_idx[idx];
330 nid = get_capsrc(spec, adc_idx);
333 num_conns = snd_hda_get_conn_list(codec, nid, NULL);
337 type = get_wcaps_type(get_wcaps(codec, nid));
338 if (type == AC_WID_AUD_MIX) {
339 /* Matrix-mixer style (e.g. ALC882) */
340 int active = imux->items[idx].index;
341 for (i = 0; i < num_conns; i++) {
342 unsigned int v = (i == active) ? 0 : HDA_AMP_MUTE;
343 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, i,
347 /* MUX style (e.g. ALC880) */
348 snd_hda_codec_write_cache(codec, nid, 0,
349 AC_VERB_SET_CONNECT_SEL,
350 imux->items[idx].index);
355 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
356 struct snd_ctl_elem_value *ucontrol)
358 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
359 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
360 return alc_mux_select(codec, adc_idx,
361 ucontrol->value.enumerated.item[0], false);
365 * set up the input pin config (depending on the given auto-pin type)
367 static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
370 unsigned int val = PIN_IN;
372 if (auto_pin_type == AUTO_PIN_MIC) {
375 oldval = snd_hda_codec_read(codec, nid, 0,
376 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
377 pincap = snd_hda_query_pin_caps(codec, nid);
378 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
379 /* if the default pin setup is vref50, we give it priority */
380 if ((pincap & AC_PINCAP_VREF_80) && oldval != PIN_VREF50)
382 else if (pincap & AC_PINCAP_VREF_50)
384 else if (pincap & AC_PINCAP_VREF_100)
386 else if (pincap & AC_PINCAP_VREF_GRD)
389 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val);
393 * Append the given mixer and verb elements for the later use
394 * The mixer array is referred in build_controls(), and init_verbs are
397 static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
399 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
401 spec->mixers[spec->num_mixers++] = mix;
404 static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
406 if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
408 spec->init_verbs[spec->num_init_verbs++] = verb;
412 * GPIO setup tables, used in initialization
414 /* Enable GPIO mask and set output */
415 static const struct hda_verb alc_gpio1_init_verbs[] = {
416 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
417 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
418 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
422 static const struct hda_verb alc_gpio2_init_verbs[] = {
423 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
424 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
425 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
429 static const struct hda_verb alc_gpio3_init_verbs[] = {
430 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
431 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
432 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
437 * Fix hardware PLL issue
438 * On some codecs, the analog PLL gating control must be off while
439 * the default value is 1.
441 static void alc_fix_pll(struct hda_codec *codec)
443 struct alc_spec *spec = codec->spec;
448 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
450 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
451 AC_VERB_GET_PROC_COEF, 0);
452 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
454 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
455 val & ~(1 << spec->pll_coef_bit));
458 static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
459 unsigned int coef_idx, unsigned int coef_bit)
461 struct alc_spec *spec = codec->spec;
463 spec->pll_coef_idx = coef_idx;
464 spec->pll_coef_bit = coef_bit;
469 * Jack-reporting via input-jack layer
472 /* initialization of jacks; currently checks only a few known pins */
473 static int alc_init_jacks(struct hda_codec *codec)
475 #ifdef CONFIG_SND_HDA_INPUT_JACK
476 struct alc_spec *spec = codec->spec;
478 unsigned int hp_nid = spec->autocfg.hp_pins[0];
479 unsigned int mic_nid = spec->ext_mic_pin;
480 unsigned int dock_nid = spec->dock_mic_pin;
483 err = snd_hda_input_jack_add(codec, hp_nid,
484 SND_JACK_HEADPHONE, NULL);
487 snd_hda_input_jack_report(codec, hp_nid);
491 err = snd_hda_input_jack_add(codec, mic_nid,
492 SND_JACK_MICROPHONE, NULL);
495 snd_hda_input_jack_report(codec, mic_nid);
498 err = snd_hda_input_jack_add(codec, dock_nid,
499 SND_JACK_MICROPHONE, NULL);
502 snd_hda_input_jack_report(codec, dock_nid);
504 #endif /* CONFIG_SND_HDA_INPUT_JACK */
509 * Jack detections for HP auto-mute and mic-switch
512 /* check each pin in the given array; returns true if any of them is plugged */
513 static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
517 for (i = 0; i < num_pins; i++) {
518 hda_nid_t nid = pins[i];
521 snd_hda_input_jack_report(codec, nid);
522 present |= snd_hda_jack_detect(codec, nid);
527 /* standard HP/line-out auto-mute helper */
528 static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
529 bool mute, bool hp_out)
531 struct alc_spec *spec = codec->spec;
532 unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0;
533 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
536 for (i = 0; i < num_pins; i++) {
537 hda_nid_t nid = pins[i];
540 switch (spec->automute_mode) {
541 case ALC_AUTOMUTE_PIN:
542 snd_hda_codec_write(codec, nid, 0,
543 AC_VERB_SET_PIN_WIDGET_CONTROL,
546 case ALC_AUTOMUTE_AMP:
547 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
548 HDA_AMP_MUTE, mute_bits);
550 case ALC_AUTOMUTE_MIXER:
551 nid = spec->automute_mixer_nid[i];
554 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
555 HDA_AMP_MUTE, mute_bits);
556 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1,
557 HDA_AMP_MUTE, mute_bits);
563 /* Toggle outputs muting */
564 static void update_outputs(struct hda_codec *codec)
566 struct alc_spec *spec = codec->spec;
569 /* Control HP pins/amps depending on master_mute state;
570 * in general, HP pins/amps control should be enabled in all cases,
571 * but currently set only for master_mute, just to be safe
573 if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */
574 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
575 spec->autocfg.hp_pins, spec->master_mute, true);
577 if (!spec->automute_speaker)
580 on = spec->hp_jack_present | spec->line_jack_present;
581 on |= spec->master_mute;
582 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
583 spec->autocfg.speaker_pins, on, false);
585 /* toggle line-out mutes if needed, too */
586 /* if LO is a copy of either HP or Speaker, don't need to handle it */
587 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
588 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
590 if (!spec->automute_lo)
593 on = spec->hp_jack_present;
594 on |= spec->master_mute;
595 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
596 spec->autocfg.line_out_pins, on, false);
599 static void call_update_outputs(struct hda_codec *codec)
601 struct alc_spec *spec = codec->spec;
602 if (spec->automute_hook)
603 spec->automute_hook(codec);
605 update_outputs(codec);
608 /* standard HP-automute helper */
609 static void alc_hp_automute(struct hda_codec *codec)
611 struct alc_spec *spec = codec->spec;
613 spec->hp_jack_present =
614 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
615 spec->autocfg.hp_pins);
616 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
618 call_update_outputs(codec);
621 /* standard line-out-automute helper */
622 static void alc_line_automute(struct hda_codec *codec)
624 struct alc_spec *spec = codec->spec;
626 /* check LO jack only when it's different from HP */
627 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
630 spec->line_jack_present =
631 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
632 spec->autocfg.line_out_pins);
633 if (!spec->automute_speaker || !spec->detect_lo)
635 call_update_outputs(codec);
638 #define get_connection_index(codec, mux, nid) \
639 snd_hda_get_conn_index(codec, mux, nid, 0)
641 /* standard mic auto-switch helper */
642 static void alc_mic_automute(struct hda_codec *codec)
644 struct alc_spec *spec = codec->spec;
645 hda_nid_t *pins = spec->imux_pins;
647 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
649 if (snd_BUG_ON(!spec->adc_nids))
651 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
654 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
655 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
656 else if (spec->dock_mic_idx >= 0 &&
657 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
658 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
660 alc_mux_select(codec, 0, spec->int_mic_idx, false);
662 snd_hda_input_jack_report(codec, pins[spec->ext_mic_idx]);
663 if (spec->dock_mic_idx >= 0)
664 snd_hda_input_jack_report(codec, pins[spec->dock_mic_idx]);
667 /* unsolicited event for HP jack sensing */
668 static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
670 if (codec->vendor_id == 0x10ec0880)
676 alc_hp_automute(codec);
678 case ALC_FRONT_EVENT:
679 alc_line_automute(codec);
682 alc_mic_automute(codec);
687 /* call init functions of standard auto-mute helpers */
688 static void alc_inithook(struct hda_codec *codec)
690 alc_hp_automute(codec);
691 alc_line_automute(codec);
692 alc_mic_automute(codec);
695 /* additional initialization for ALC888 variants */
696 static void alc888_coef_init(struct hda_codec *codec)
700 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
701 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
702 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
703 if ((tmp & 0xf0) == 0x20)
705 snd_hda_codec_read(codec, 0x20, 0,
706 AC_VERB_SET_PROC_COEF, 0x830);
709 snd_hda_codec_read(codec, 0x20, 0,
710 AC_VERB_SET_PROC_COEF, 0x3030);
713 /* additional initialization for ALC889 variants */
714 static void alc889_coef_init(struct hda_codec *codec)
718 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
719 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
720 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
721 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
724 /* turn on/off EAPD control (only if available) */
725 static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
727 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
729 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
730 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
734 /* turn on/off EAPD controls of the codec */
735 static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
737 /* We currently only handle front, HP */
738 static hda_nid_t pins[] = {
739 0x0f, 0x10, 0x14, 0x15, 0
742 for (p = pins; *p; p++)
743 set_eapd(codec, *p, on);
746 /* generic shutup callback;
747 * just turning off EPAD and a little pause for avoiding pop-noise
749 static void alc_eapd_shutup(struct hda_codec *codec)
751 alc_auto_setup_eapd(codec, false);
755 /* generic EAPD initialization */
756 static void alc_auto_init_amp(struct hda_codec *codec, int type)
760 alc_auto_setup_eapd(codec, true);
763 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
766 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
769 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
771 case ALC_INIT_DEFAULT:
772 switch (codec->vendor_id) {
774 snd_hda_codec_write(codec, 0x1a, 0,
775 AC_VERB_SET_COEF_INDEX, 7);
776 tmp = snd_hda_codec_read(codec, 0x1a, 0,
777 AC_VERB_GET_PROC_COEF, 0);
778 snd_hda_codec_write(codec, 0x1a, 0,
779 AC_VERB_SET_COEF_INDEX, 7);
780 snd_hda_codec_write(codec, 0x1a, 0,
781 AC_VERB_SET_PROC_COEF,
790 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
791 alc889_coef_init(codec);
794 alc888_coef_init(codec);
796 #if 0 /* XXX: This may cause the silent output on speaker on some machines */
799 snd_hda_codec_write(codec, 0x20, 0,
800 AC_VERB_SET_COEF_INDEX, 7);
801 tmp = snd_hda_codec_read(codec, 0x20, 0,
802 AC_VERB_GET_PROC_COEF, 0);
803 snd_hda_codec_write(codec, 0x20, 0,
804 AC_VERB_SET_COEF_INDEX, 7);
805 snd_hda_codec_write(codec, 0x20, 0,
806 AC_VERB_SET_PROC_COEF,
816 * Auto-Mute mode mixer enum support
818 static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
819 struct snd_ctl_elem_info *uinfo)
821 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
822 struct alc_spec *spec = codec->spec;
823 static const char * const texts2[] = {
824 "Disabled", "Enabled"
826 static const char * const texts3[] = {
827 "Disabled", "Speaker Only", "Line-Out+Speaker"
829 const char * const *texts;
831 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
833 if (spec->automute_speaker_possible && spec->automute_lo_possible) {
834 uinfo->value.enumerated.items = 3;
837 uinfo->value.enumerated.items = 2;
840 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
841 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
842 strcpy(uinfo->value.enumerated.name,
843 texts[uinfo->value.enumerated.item]);
847 static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
848 struct snd_ctl_elem_value *ucontrol)
850 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
851 struct alc_spec *spec = codec->spec;
852 unsigned int val = 0;
853 if (spec->automute_speaker)
855 if (spec->automute_lo)
858 ucontrol->value.enumerated.item[0] = val;
862 static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
863 struct snd_ctl_elem_value *ucontrol)
865 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
866 struct alc_spec *spec = codec->spec;
868 switch (ucontrol->value.enumerated.item[0]) {
870 if (!spec->automute_speaker && !spec->automute_lo)
872 spec->automute_speaker = 0;
873 spec->automute_lo = 0;
876 if (spec->automute_speaker_possible) {
877 if (!spec->automute_lo && spec->automute_speaker)
879 spec->automute_speaker = 1;
880 spec->automute_lo = 0;
881 } else if (spec->automute_lo_possible) {
882 if (spec->automute_lo)
884 spec->automute_lo = 1;
889 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
891 if (spec->automute_speaker && spec->automute_lo)
893 spec->automute_speaker = 1;
894 spec->automute_lo = 1;
899 call_update_outputs(codec);
903 static const struct snd_kcontrol_new alc_automute_mode_enum = {
904 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
905 .name = "Auto-Mute Mode",
906 .info = alc_automute_mode_info,
907 .get = alc_automute_mode_get,
908 .put = alc_automute_mode_put,
911 static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec)
913 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
914 return snd_array_new(&spec->kctls);
917 static int alc_add_automute_mode_enum(struct hda_codec *codec)
919 struct alc_spec *spec = codec->spec;
920 struct snd_kcontrol_new *knew;
922 knew = alc_kcontrol_new(spec);
925 *knew = alc_automute_mode_enum;
926 knew->name = kstrdup("Auto-Mute Mode", GFP_KERNEL);
933 * Check the availability of HP/line-out auto-mute;
934 * Set up appropriately if really supported
936 static void alc_init_automute(struct hda_codec *codec)
938 struct alc_spec *spec = codec->spec;
939 struct auto_pin_cfg *cfg = &spec->autocfg;
945 if (cfg->line_out_pins[0])
947 if (cfg->speaker_pins[0])
949 if (present < 2) /* need two different output types */
952 if (!cfg->speaker_pins[0] &&
953 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
954 memcpy(cfg->speaker_pins, cfg->line_out_pins,
955 sizeof(cfg->speaker_pins));
956 cfg->speaker_outs = cfg->line_outs;
959 if (!cfg->hp_pins[0] &&
960 cfg->line_out_type == AUTO_PIN_HP_OUT) {
961 memcpy(cfg->hp_pins, cfg->line_out_pins,
962 sizeof(cfg->hp_pins));
963 cfg->hp_outs = cfg->line_outs;
966 spec->automute_mode = ALC_AUTOMUTE_PIN;
968 for (i = 0; i < cfg->hp_outs; i++) {
969 hda_nid_t nid = cfg->hp_pins[i];
970 if (!is_jack_detectable(codec, nid))
972 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
974 snd_hda_codec_write_cache(codec, nid, 0,
975 AC_VERB_SET_UNSOLICITED_ENABLE,
976 AC_USRSP_EN | ALC_HP_EVENT);
980 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
981 if (cfg->speaker_outs)
982 for (i = 0; i < cfg->line_outs; i++) {
983 hda_nid_t nid = cfg->line_out_pins[i];
984 if (!is_jack_detectable(codec, nid))
986 snd_printdd("realtek: Enable Line-Out "
987 "auto-muting on NID 0x%x\n", nid);
988 snd_hda_codec_write_cache(codec, nid, 0,
989 AC_VERB_SET_UNSOLICITED_ENABLE,
990 AC_USRSP_EN | ALC_FRONT_EVENT);
993 spec->automute_lo_possible = spec->detect_hp;
996 spec->automute_speaker_possible = cfg->speaker_outs &&
997 (spec->detect_hp || spec->detect_lo);
999 spec->automute_lo = spec->automute_lo_possible;
1000 spec->automute_speaker = spec->automute_speaker_possible;
1002 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
1003 /* create a control for automute mode */
1004 alc_add_automute_mode_enum(codec);
1005 spec->unsol_event = alc_sku_unsol_event;
1009 /* return the position of NID in the list, or -1 if not found */
1010 static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1013 for (i = 0; i < nums; i++)
1019 /* check whether dynamic ADC-switching is available */
1020 static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
1022 struct alc_spec *spec = codec->spec;
1023 struct hda_input_mux *imux = &spec->private_imux[0];
1027 if (imux != spec->input_mux) /* no dynamic imux? */
1030 for (n = 0; n < spec->num_adc_nids; n++) {
1031 cap = spec->private_capsrc_nids[n];
1032 for (i = 0; i < imux->num_items; i++) {
1033 pin = spec->imux_pins[i];
1036 if (get_connection_index(codec, cap, pin) < 0)
1039 if (i >= imux->num_items)
1040 return true; /* no ADC-switch is needed */
1043 for (i = 0; i < imux->num_items; i++) {
1044 pin = spec->imux_pins[i];
1045 for (n = 0; n < spec->num_adc_nids; n++) {
1046 cap = spec->private_capsrc_nids[n];
1047 idx = get_connection_index(codec, cap, pin);
1049 imux->items[i].index = idx;
1050 spec->dyn_adc_idx[i] = n;
1056 snd_printdd("realtek: enabling ADC switching\n");
1057 spec->dyn_adc_switch = 1;
1061 /* rebuild imux for matching with the given auto-mic pins (if not yet) */
1062 static bool alc_rebuild_imux_for_auto_mic(struct hda_codec *codec)
1064 struct alc_spec *spec = codec->spec;
1065 struct hda_input_mux *imux;
1066 static char * const texts[3] = {
1067 "Mic", "Internal Mic", "Dock Mic"
1071 if (!spec->auto_mic)
1073 imux = &spec->private_imux[0];
1074 if (spec->input_mux == imux)
1076 spec->imux_pins[0] = spec->ext_mic_pin;
1077 spec->imux_pins[1] = spec->int_mic_pin;
1078 spec->imux_pins[2] = spec->dock_mic_pin;
1079 for (i = 0; i < 3; i++) {
1080 strcpy(imux->items[i].label, texts[i]);
1081 if (spec->imux_pins[i]) {
1082 hda_nid_t pin = spec->imux_pins[i];
1084 for (c = 0; c < spec->num_adc_nids; c++) {
1085 hda_nid_t cap = get_capsrc(spec, c);
1086 int idx = get_connection_index(codec, cap, pin);
1088 imux->items[i].index = idx;
1092 imux->num_items = i + 1;
1095 spec->num_mux_defs = 1;
1096 spec->input_mux = imux;
1100 /* check whether all auto-mic pins are valid; setup indices if OK */
1101 static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1103 struct alc_spec *spec = codec->spec;
1104 const struct hda_input_mux *imux;
1106 if (!spec->auto_mic)
1108 if (spec->auto_mic_valid_imux)
1109 return true; /* already checked */
1111 /* fill up imux indices */
1112 if (!alc_check_dyn_adc_switch(codec)) {
1117 imux = spec->input_mux;
1118 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1119 spec->imux_pins, imux->num_items);
1120 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1121 spec->imux_pins, imux->num_items);
1122 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1123 spec->imux_pins, imux->num_items);
1124 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1126 return false; /* no corresponding imux */
1129 snd_hda_codec_write_cache(codec, spec->ext_mic_pin, 0,
1130 AC_VERB_SET_UNSOLICITED_ENABLE,
1131 AC_USRSP_EN | ALC_MIC_EVENT);
1132 if (spec->dock_mic_pin)
1133 snd_hda_codec_write_cache(codec, spec->dock_mic_pin, 0,
1134 AC_VERB_SET_UNSOLICITED_ENABLE,
1135 AC_USRSP_EN | ALC_MIC_EVENT);
1137 spec->auto_mic_valid_imux = 1;
1143 * Check the availability of auto-mic switch;
1144 * Set up if really supported
1146 static void alc_init_auto_mic(struct hda_codec *codec)
1148 struct alc_spec *spec = codec->spec;
1149 struct auto_pin_cfg *cfg = &spec->autocfg;
1150 hda_nid_t fixed, ext, dock;
1153 if (spec->shared_mic_hp)
1154 return; /* no auto-mic for the shared I/O */
1156 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1158 fixed = ext = dock = 0;
1159 for (i = 0; i < cfg->num_inputs; i++) {
1160 hda_nid_t nid = cfg->inputs[i].pin;
1161 unsigned int defcfg;
1162 defcfg = snd_hda_codec_get_pincfg(codec, nid);
1163 switch (snd_hda_get_input_pin_attr(defcfg)) {
1164 case INPUT_PIN_ATTR_INT:
1166 return; /* already occupied */
1167 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1168 return; /* invalid type */
1171 case INPUT_PIN_ATTR_UNUSED:
1172 return; /* invalid entry */
1173 case INPUT_PIN_ATTR_DOCK:
1175 return; /* already occupied */
1176 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1177 return; /* invalid type */
1182 return; /* already occupied */
1183 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1184 return; /* invalid type */
1195 if (!is_jack_detectable(codec, ext))
1196 return; /* no unsol support */
1197 if (dock && !is_jack_detectable(codec, dock))
1198 return; /* no unsol support */
1200 /* check imux indices */
1201 spec->ext_mic_pin = ext;
1202 spec->int_mic_pin = fixed;
1203 spec->dock_mic_pin = dock;
1206 if (!alc_auto_mic_check_imux(codec))
1209 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1211 spec->unsol_event = alc_sku_unsol_event;
1214 /* check the availabilities of auto-mute and auto-mic switches */
1215 static void alc_auto_check_switches(struct hda_codec *codec)
1217 alc_init_automute(codec);
1218 alc_init_auto_mic(codec);
1222 * Realtek SSID verification
1225 /* Could be any non-zero and even value. When used as fixup, tells
1226 * the driver to ignore any present sku defines.
1228 #define ALC_FIXUP_SKU_IGNORE (2)
1230 static int alc_auto_parse_customize_define(struct hda_codec *codec)
1232 unsigned int ass, tmp, i;
1234 struct alc_spec *spec = codec->spec;
1236 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1238 if (spec->cdefine.fixup) {
1239 ass = spec->cdefine.sku_cfg;
1240 if (ass == ALC_FIXUP_SKU_IGNORE)
1245 ass = codec->subsystem_id & 0xffff;
1246 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
1250 if (codec->vendor_id == 0x10ec0260)
1252 ass = snd_hda_codec_get_pincfg(codec, nid);
1255 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1256 codec->chip_name, ass);
1262 for (i = 1; i < 16; i++) {
1266 if (((ass >> 16) & 0xf) != tmp)
1269 spec->cdefine.port_connectivity = ass >> 30;
1270 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1271 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1272 spec->cdefine.customization = ass >> 8;
1274 spec->cdefine.sku_cfg = ass;
1275 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1276 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1277 spec->cdefine.swap = (ass & 0x2) >> 1;
1278 spec->cdefine.override = ass & 0x1;
1280 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1281 nid, spec->cdefine.sku_cfg);
1282 snd_printd("SKU: port_connectivity=0x%x\n",
1283 spec->cdefine.port_connectivity);
1284 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1285 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1286 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1287 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1288 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1289 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1290 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1295 /* return true if the given NID is found in the list */
1296 static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1298 return find_idx_in_nid_list(nid, list, nums) >= 0;
1301 /* check subsystem ID and set up device-specific initialization;
1302 * return 1 if initialized, 0 if invalid SSID
1304 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1305 * 31 ~ 16 : Manufacture ID
1307 * 7 ~ 0 : Assembly ID
1308 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1310 static int alc_subsystem_id(struct hda_codec *codec,
1311 hda_nid_t porta, hda_nid_t porte,
1312 hda_nid_t portd, hda_nid_t porti)
1314 unsigned int ass, tmp, i;
1316 struct alc_spec *spec = codec->spec;
1318 if (spec->cdefine.fixup) {
1319 ass = spec->cdefine.sku_cfg;
1320 if (ass == ALC_FIXUP_SKU_IGNORE)
1325 ass = codec->subsystem_id & 0xffff;
1326 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1329 /* invalid SSID, check the special NID pin defcfg instead */
1331 * 31~30 : port connectivity
1334 * 19~16 : Check sum (15:1)
1339 if (codec->vendor_id == 0x10ec0260)
1341 ass = snd_hda_codec_get_pincfg(codec, nid);
1342 snd_printd("realtek: No valid SSID, "
1343 "checking pincfg 0x%08x for NID 0x%x\n",
1347 if ((ass >> 30) != 1) /* no physical connection */
1352 for (i = 1; i < 16; i++) {
1356 if (((ass >> 16) & 0xf) != tmp)
1359 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1360 ass & 0xffff, codec->vendor_id);
1364 * 2 : 0 --> Desktop, 1 --> Laptop
1365 * 3~5 : External Amplifier control
1368 tmp = (ass & 0x38) >> 3; /* external Amp control */
1371 spec->init_amp = ALC_INIT_GPIO1;
1374 spec->init_amp = ALC_INIT_GPIO2;
1377 spec->init_amp = ALC_INIT_GPIO3;
1381 spec->init_amp = ALC_INIT_DEFAULT;
1385 /* is laptop or Desktop and enable the function "Mute internal speaker
1386 * when the external headphone out jack is plugged"
1388 if (!(ass & 0x8000))
1391 * 10~8 : Jack location
1392 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1394 * 15 : 1 --> enable the function "Mute internal speaker
1395 * when the external headphone out jack is plugged"
1397 if (!spec->autocfg.hp_pins[0] &&
1398 !(spec->autocfg.line_out_pins[0] &&
1399 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
1401 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1412 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1413 spec->autocfg.line_outs))
1415 spec->autocfg.hp_pins[0] = nid;
1420 /* Check the validity of ALC subsystem-id
1421 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1422 static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
1424 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
1425 struct alc_spec *spec = codec->spec;
1426 snd_printd("realtek: "
1427 "Enable default setup for auto mode as fallback\n");
1428 spec->init_amp = ALC_INIT_DEFAULT;
1433 * Fix-up pin default configurations and add default verbs
1441 struct alc_model_fixup {
1452 const struct alc_pincfg *pins;
1453 const struct hda_verb *verbs;
1454 void (*func)(struct hda_codec *codec,
1455 const struct alc_fixup *fix,
1469 ALC_FIXUP_ACT_PRE_PROBE,
1470 ALC_FIXUP_ACT_PROBE,
1474 static void alc_apply_fixup(struct hda_codec *codec, int action)
1476 struct alc_spec *spec = codec->spec;
1477 int id = spec->fixup_id;
1478 #ifdef CONFIG_SND_DEBUG_VERBOSE
1479 const char *modelname = spec->fixup_name;
1483 if (!spec->fixup_list)
1487 const struct alc_fixup *fix = spec->fixup_list + id;
1488 const struct alc_pincfg *cfg;
1490 switch (fix->type) {
1492 if (action != ALC_FIXUP_ACT_PRE_PROBE || !fix->v.sku)
1494 snd_printdd(KERN_INFO "hda_codec: %s: "
1495 "Apply sku override for %s\n",
1496 codec->chip_name, modelname);
1497 spec->cdefine.sku_cfg = fix->v.sku;
1498 spec->cdefine.fixup = 1;
1500 case ALC_FIXUP_PINS:
1502 if (action != ALC_FIXUP_ACT_PRE_PROBE || !cfg)
1504 snd_printdd(KERN_INFO "hda_codec: %s: "
1505 "Apply pincfg for %s\n",
1506 codec->chip_name, modelname);
1507 for (; cfg->nid; cfg++)
1508 snd_hda_codec_set_pincfg(codec, cfg->nid,
1511 case ALC_FIXUP_VERBS:
1512 if (action != ALC_FIXUP_ACT_PROBE || !fix->v.verbs)
1514 snd_printdd(KERN_INFO "hda_codec: %s: "
1515 "Apply fix-verbs for %s\n",
1516 codec->chip_name, modelname);
1517 add_verb(codec->spec, fix->v.verbs);
1519 case ALC_FIXUP_FUNC:
1522 snd_printdd(KERN_INFO "hda_codec: %s: "
1523 "Apply fix-func for %s\n",
1524 codec->chip_name, modelname);
1525 fix->v.func(codec, fix, action);
1528 snd_printk(KERN_ERR "hda_codec: %s: "
1529 "Invalid fixup type %d\n",
1530 codec->chip_name, fix->type);
1541 static void alc_pick_fixup(struct hda_codec *codec,
1542 const struct alc_model_fixup *models,
1543 const struct snd_pci_quirk *quirk,
1544 const struct alc_fixup *fixlist)
1546 struct alc_spec *spec = codec->spec;
1547 const struct snd_pci_quirk *q;
1549 const char *name = NULL;
1551 if (codec->modelname && models) {
1552 while (models->name) {
1553 if (!strcmp(codec->modelname, models->name)) {
1555 name = models->name;
1562 q = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1565 #ifdef CONFIG_SND_DEBUG_VERBOSE
1571 for (q = quirk; q->subvendor; q++) {
1572 unsigned int vendorid =
1573 q->subdevice | (q->subvendor << 16);
1574 if (vendorid == codec->subsystem_id) {
1576 #ifdef CONFIG_SND_DEBUG_VERBOSE
1584 spec->fixup_id = id;
1586 spec->fixup_list = fixlist;
1587 spec->fixup_name = name;
1592 * COEF access helper functions
1594 static int alc_read_coef_idx(struct hda_codec *codec,
1595 unsigned int coef_idx)
1598 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1600 val = snd_hda_codec_read(codec, 0x20, 0,
1601 AC_VERB_GET_PROC_COEF, 0);
1605 static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1606 unsigned int coef_val)
1608 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1610 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1614 /* a special bypass for COEF 0; read the cached value at the second time */
1615 static unsigned int alc_get_coef0(struct hda_codec *codec)
1617 struct alc_spec *spec = codec->spec;
1619 spec->coef0 = alc_read_coef_idx(codec, 0);
1624 * Digital I/O handling
1627 /* set right pin controls for digital I/O */
1628 static void alc_auto_init_digital(struct hda_codec *codec)
1630 struct alc_spec *spec = codec->spec;
1634 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1635 pin = spec->autocfg.dig_out_pins[i];
1638 snd_hda_codec_write(codec, pin, 0,
1639 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
1641 dac = spec->multiout.dig_out_nid;
1643 dac = spec->slave_dig_outs[i - 1];
1644 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
1646 snd_hda_codec_write(codec, dac, 0,
1647 AC_VERB_SET_AMP_GAIN_MUTE,
1650 pin = spec->autocfg.dig_in_pin;
1652 snd_hda_codec_write(codec, pin, 0,
1653 AC_VERB_SET_PIN_WIDGET_CONTROL,
1657 /* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1658 static void alc_auto_parse_digital(struct hda_codec *codec)
1660 struct alc_spec *spec = codec->spec;
1664 /* support multiple SPDIFs; the secondary is set up as a slave */
1666 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1668 err = snd_hda_get_connections(codec,
1669 spec->autocfg.dig_out_pins[i],
1670 conn, ARRAY_SIZE(conn));
1673 dig_nid = conn[0]; /* assume the first element is audio-out */
1675 spec->multiout.dig_out_nid = dig_nid;
1676 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1678 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
1679 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
1681 spec->slave_dig_outs[nums - 1] = dig_nid;
1686 if (spec->autocfg.dig_in_pin) {
1687 dig_nid = codec->start_nid;
1688 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1689 unsigned int wcaps = get_wcaps(codec, dig_nid);
1690 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1692 if (!(wcaps & AC_WCAP_DIGITAL))
1694 if (!(wcaps & AC_WCAP_CONN_LIST))
1696 err = get_connection_index(codec, dig_nid,
1697 spec->autocfg.dig_in_pin);
1699 spec->dig_in_nid = dig_nid;
1707 * capture mixer elements
1709 static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1710 struct snd_ctl_elem_info *uinfo)
1712 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1713 struct alc_spec *spec = codec->spec;
1717 mutex_lock(&codec->control_mutex);
1718 if (spec->vol_in_capsrc)
1719 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1721 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1722 kcontrol->private_value = val;
1723 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
1724 mutex_unlock(&codec->control_mutex);
1728 static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1729 unsigned int size, unsigned int __user *tlv)
1731 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1732 struct alc_spec *spec = codec->spec;
1736 mutex_lock(&codec->control_mutex);
1737 if (spec->vol_in_capsrc)
1738 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1740 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1741 kcontrol->private_value = val;
1742 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
1743 mutex_unlock(&codec->control_mutex);
1747 typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1748 struct snd_ctl_elem_value *ucontrol);
1750 static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1751 struct snd_ctl_elem_value *ucontrol,
1752 getput_call_t func, bool check_adc_switch)
1754 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1755 struct alc_spec *spec = codec->spec;
1758 mutex_lock(&codec->control_mutex);
1759 if (check_adc_switch && spec->dyn_adc_switch) {
1760 for (i = 0; i < spec->num_adc_nids; i++) {
1761 kcontrol->private_value =
1762 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1764 err = func(kcontrol, ucontrol);
1769 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1770 if (spec->vol_in_capsrc)
1771 kcontrol->private_value =
1772 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1775 kcontrol->private_value =
1776 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1778 err = func(kcontrol, ucontrol);
1781 mutex_unlock(&codec->control_mutex);
1785 static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1786 struct snd_ctl_elem_value *ucontrol)
1788 return alc_cap_getput_caller(kcontrol, ucontrol,
1789 snd_hda_mixer_amp_volume_get, false);
1792 static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1793 struct snd_ctl_elem_value *ucontrol)
1795 return alc_cap_getput_caller(kcontrol, ucontrol,
1796 snd_hda_mixer_amp_volume_put, true);
1799 /* capture mixer elements */
1800 #define alc_cap_sw_info snd_ctl_boolean_stereo_info
1802 static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1803 struct snd_ctl_elem_value *ucontrol)
1805 return alc_cap_getput_caller(kcontrol, ucontrol,
1806 snd_hda_mixer_amp_switch_get, false);
1809 static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1810 struct snd_ctl_elem_value *ucontrol)
1812 return alc_cap_getput_caller(kcontrol, ucontrol,
1813 snd_hda_mixer_amp_switch_put, true);
1816 #define _DEFINE_CAPMIX(num) \
1818 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1819 .name = "Capture Switch", \
1820 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1822 .info = alc_cap_sw_info, \
1823 .get = alc_cap_sw_get, \
1824 .put = alc_cap_sw_put, \
1827 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1828 .name = "Capture Volume", \
1829 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1830 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1831 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1833 .info = alc_cap_vol_info, \
1834 .get = alc_cap_vol_get, \
1835 .put = alc_cap_vol_put, \
1836 .tlv = { .c = alc_cap_vol_tlv }, \
1839 #define _DEFINE_CAPSRC(num) \
1841 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1842 /* .name = "Capture Source", */ \
1843 .name = "Input Source", \
1845 .info = alc_mux_enum_info, \
1846 .get = alc_mux_enum_get, \
1847 .put = alc_mux_enum_put, \
1850 #define DEFINE_CAPMIX(num) \
1851 static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
1852 _DEFINE_CAPMIX(num), \
1853 _DEFINE_CAPSRC(num), \
1857 #define DEFINE_CAPMIX_NOSRC(num) \
1858 static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
1859 _DEFINE_CAPMIX(num), \
1863 /* up to three ADCs */
1867 DEFINE_CAPMIX_NOSRC(1);
1868 DEFINE_CAPMIX_NOSRC(2);
1869 DEFINE_CAPMIX_NOSRC(3);
1872 * virtual master controls
1876 * slave controls for virtual master
1878 static const char * const alc_slave_vols[] = {
1879 "Front Playback Volume",
1880 "Surround Playback Volume",
1881 "Center Playback Volume",
1882 "LFE Playback Volume",
1883 "Side Playback Volume",
1884 "Headphone Playback Volume",
1885 "Speaker Playback Volume",
1886 "Mono Playback Volume",
1887 "Line-Out Playback Volume",
1888 "PCM Playback Volume",
1892 static const char * const alc_slave_sws[] = {
1893 "Front Playback Switch",
1894 "Surround Playback Switch",
1895 "Center Playback Switch",
1896 "LFE Playback Switch",
1897 "Side Playback Switch",
1898 "Headphone Playback Switch",
1899 "Speaker Playback Switch",
1900 "Mono Playback Switch",
1901 "IEC958 Playback Switch",
1902 "Line-Out Playback Switch",
1903 "PCM Playback Switch",
1908 * build control elements
1911 #define NID_MAPPING (-1)
1913 #define SUBDEV_SPEAKER_ (0 << 6)
1914 #define SUBDEV_HP_ (1 << 6)
1915 #define SUBDEV_LINE_ (2 << 6)
1916 #define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1917 #define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1918 #define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1920 static void alc_free_kctls(struct hda_codec *codec);
1922 #ifdef CONFIG_SND_HDA_INPUT_BEEP
1923 /* additional beep mixers; the actual parameters are overwritten at build */
1924 static const struct snd_kcontrol_new alc_beep_mixer[] = {
1925 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
1926 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
1931 static int alc_build_controls(struct hda_codec *codec)
1933 struct alc_spec *spec = codec->spec;
1934 struct snd_kcontrol *kctl = NULL;
1935 const struct snd_kcontrol_new *knew;
1940 for (i = 0; i < spec->num_mixers; i++) {
1941 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1945 if (spec->cap_mixer) {
1946 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1950 if (spec->multiout.dig_out_nid) {
1951 err = snd_hda_create_spdif_out_ctls(codec,
1952 spec->multiout.dig_out_nid,
1953 spec->multiout.dig_out_nid);
1956 if (!spec->no_analog) {
1957 err = snd_hda_create_spdif_share_sw(codec,
1961 spec->multiout.share_spdif = 1;
1964 if (spec->dig_in_nid) {
1965 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1970 #ifdef CONFIG_SND_HDA_INPUT_BEEP
1971 /* create beep controls if needed */
1972 if (spec->beep_amp) {
1973 const struct snd_kcontrol_new *knew;
1974 for (knew = alc_beep_mixer; knew->name; knew++) {
1975 struct snd_kcontrol *kctl;
1976 kctl = snd_ctl_new1(knew, codec);
1979 kctl->private_value = spec->beep_amp;
1980 err = snd_hda_ctl_add(codec, 0, kctl);
1987 /* if we have no master control, let's create it */
1988 if (!spec->no_analog &&
1989 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1990 unsigned int vmaster_tlv[4];
1991 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
1992 HDA_OUTPUT, vmaster_tlv);
1993 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1994 vmaster_tlv, alc_slave_vols);
1998 if (!spec->no_analog &&
1999 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
2000 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
2001 NULL, alc_slave_sws);
2006 /* assign Capture Source enums to NID */
2007 if (spec->capsrc_nids || spec->adc_nids) {
2008 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
2010 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
2011 for (i = 0; kctl && i < kctl->count; i++) {
2012 err = snd_hda_add_nid(codec, kctl, i,
2013 get_capsrc(spec, i));
2018 if (spec->cap_mixer && spec->adc_nids) {
2019 const char *kname = kctl ? kctl->id.name : NULL;
2020 for (knew = spec->cap_mixer; knew->name; knew++) {
2021 if (kname && strcmp(knew->name, kname) == 0)
2023 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
2024 for (i = 0; kctl && i < kctl->count; i++) {
2025 err = snd_hda_add_nid(codec, kctl, i,
2033 /* other nid->control mapping */
2034 for (i = 0; i < spec->num_mixers; i++) {
2035 for (knew = spec->mixers[i]; knew->name; knew++) {
2036 if (knew->iface != NID_MAPPING)
2038 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
2041 u = knew->subdevice;
2042 for (j = 0; j < 4; j++, u >>= 8) {
2047 case SUBDEV_SPEAKER_:
2048 nid = spec->autocfg.speaker_pins[nid];
2051 nid = spec->autocfg.line_out_pins[nid];
2054 nid = spec->autocfg.hp_pins[nid];
2059 err = snd_hda_add_nid(codec, kctl, 0, nid);
2063 u = knew->private_value;
2064 for (j = 0; j < 4; j++, u >>= 8) {
2068 err = snd_hda_add_nid(codec, kctl, 0, nid);
2075 alc_free_kctls(codec); /* no longer needed */
2085 static void alc_init_special_input_src(struct hda_codec *codec);
2087 static int alc_init(struct hda_codec *codec)
2089 struct alc_spec *spec = codec->spec;
2093 alc_auto_init_amp(codec, spec->init_amp);
2095 for (i = 0; i < spec->num_init_verbs; i++)
2096 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2097 alc_init_special_input_src(codec);
2099 if (spec->init_hook)
2100 spec->init_hook(codec);
2102 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2104 hda_call_check_power_status(codec, 0x01);
2108 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2110 struct alc_spec *spec = codec->spec;
2112 if (spec->unsol_event)
2113 spec->unsol_event(codec, res);
2116 #ifdef CONFIG_SND_HDA_POWER_SAVE
2117 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2119 struct alc_spec *spec = codec->spec;
2120 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2125 * Analog playback callbacks
2127 static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
2128 struct hda_codec *codec,
2129 struct snd_pcm_substream *substream)
2131 struct alc_spec *spec = codec->spec;
2132 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2136 static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2137 struct hda_codec *codec,
2138 unsigned int stream_tag,
2139 unsigned int format,
2140 struct snd_pcm_substream *substream)
2142 struct alc_spec *spec = codec->spec;
2143 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2144 stream_tag, format, substream);
2147 static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2148 struct hda_codec *codec,
2149 struct snd_pcm_substream *substream)
2151 struct alc_spec *spec = codec->spec;
2152 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2158 static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2159 struct hda_codec *codec,
2160 struct snd_pcm_substream *substream)
2162 struct alc_spec *spec = codec->spec;
2163 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2166 static int alc_dig_playback_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 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2174 stream_tag, format, substream);
2177 static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2178 struct hda_codec *codec,
2179 struct snd_pcm_substream *substream)
2181 struct alc_spec *spec = codec->spec;
2182 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2185 static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2186 struct hda_codec *codec,
2187 struct snd_pcm_substream *substream)
2189 struct alc_spec *spec = codec->spec;
2190 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2196 static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2197 struct hda_codec *codec,
2198 unsigned int stream_tag,
2199 unsigned int format,
2200 struct snd_pcm_substream *substream)
2202 struct alc_spec *spec = codec->spec;
2204 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
2205 stream_tag, 0, format);
2209 static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2210 struct hda_codec *codec,
2211 struct snd_pcm_substream *substream)
2213 struct alc_spec *spec = codec->spec;
2215 snd_hda_codec_cleanup_stream(codec,
2216 spec->adc_nids[substream->number + 1]);
2220 /* analog capture with dynamic dual-adc changes */
2221 static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2222 struct hda_codec *codec,
2223 unsigned int stream_tag,
2224 unsigned int format,
2225 struct snd_pcm_substream *substream)
2227 struct alc_spec *spec = codec->spec;
2228 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
2229 spec->cur_adc_stream_tag = stream_tag;
2230 spec->cur_adc_format = format;
2231 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2235 static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2236 struct hda_codec *codec,
2237 struct snd_pcm_substream *substream)
2239 struct alc_spec *spec = codec->spec;
2240 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2245 static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
2249 .nid = 0, /* fill later */
2251 .prepare = dyn_adc_capture_pcm_prepare,
2252 .cleanup = dyn_adc_capture_pcm_cleanup
2258 static const struct hda_pcm_stream alc_pcm_analog_playback = {
2262 /* NID is set in alc_build_pcms */
2264 .open = alc_playback_pcm_open,
2265 .prepare = alc_playback_pcm_prepare,
2266 .cleanup = alc_playback_pcm_cleanup
2270 static const struct hda_pcm_stream alc_pcm_analog_capture = {
2274 /* NID is set in alc_build_pcms */
2277 static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
2281 /* NID is set in alc_build_pcms */
2284 static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
2285 .substreams = 2, /* can be overridden */
2288 /* NID is set in alc_build_pcms */
2290 .prepare = alc_alt_capture_pcm_prepare,
2291 .cleanup = alc_alt_capture_pcm_cleanup
2295 static const struct hda_pcm_stream alc_pcm_digital_playback = {
2299 /* NID is set in alc_build_pcms */
2301 .open = alc_dig_playback_pcm_open,
2302 .close = alc_dig_playback_pcm_close,
2303 .prepare = alc_dig_playback_pcm_prepare,
2304 .cleanup = alc_dig_playback_pcm_cleanup
2308 static const struct hda_pcm_stream alc_pcm_digital_capture = {
2312 /* NID is set in alc_build_pcms */
2315 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
2316 static const struct hda_pcm_stream alc_pcm_null_stream = {
2322 static int alc_build_pcms(struct hda_codec *codec)
2324 struct alc_spec *spec = codec->spec;
2325 struct hda_pcm *info = spec->pcm_rec;
2326 const struct hda_pcm_stream *p;
2327 bool have_multi_adcs;
2330 codec->num_pcms = 1;
2331 codec->pcm_info = info;
2333 if (spec->no_analog)
2336 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2337 "%s Analog", codec->chip_name);
2338 info->name = spec->stream_name_analog;
2340 if (spec->multiout.dac_nids > 0) {
2341 p = spec->stream_analog_playback;
2343 p = &alc_pcm_analog_playback;
2344 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2345 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2347 if (spec->adc_nids) {
2348 p = spec->stream_analog_capture;
2350 if (spec->dyn_adc_switch)
2351 p = &dyn_adc_pcm_analog_capture;
2353 p = &alc_pcm_analog_capture;
2355 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2356 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2359 if (spec->channel_mode) {
2360 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2361 for (i = 0; i < spec->num_channel_mode; i++) {
2362 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2363 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2369 /* SPDIF for stream index #1 */
2370 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2371 snprintf(spec->stream_name_digital,
2372 sizeof(spec->stream_name_digital),
2373 "%s Digital", codec->chip_name);
2374 codec->num_pcms = 2;
2375 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
2376 info = spec->pcm_rec + 1;
2377 info->name = spec->stream_name_digital;
2378 if (spec->dig_out_type)
2379 info->pcm_type = spec->dig_out_type;
2381 info->pcm_type = HDA_PCM_TYPE_SPDIF;
2382 if (spec->multiout.dig_out_nid) {
2383 p = spec->stream_digital_playback;
2385 p = &alc_pcm_digital_playback;
2386 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2387 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2389 if (spec->dig_in_nid) {
2390 p = spec->stream_digital_capture;
2392 p = &alc_pcm_digital_capture;
2393 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2394 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2396 /* FIXME: do we need this for all Realtek codec models? */
2397 codec->spdif_status_reset = 1;
2400 if (spec->no_analog)
2403 /* If the use of more than one ADC is requested for the current
2404 * model, configure a second analog capture-only PCM.
2406 have_multi_adcs = (spec->num_adc_nids > 1) &&
2407 !spec->dyn_adc_switch && !spec->auto_mic &&
2408 (!spec->input_mux || spec->input_mux->num_items > 1);
2409 /* Additional Analaog capture for index #2 */
2410 if (spec->alt_dac_nid || have_multi_adcs) {
2411 codec->num_pcms = 3;
2412 info = spec->pcm_rec + 2;
2413 info->name = spec->stream_name_analog;
2414 if (spec->alt_dac_nid) {
2415 p = spec->stream_analog_alt_playback;
2417 p = &alc_pcm_analog_alt_playback;
2418 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2419 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2422 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2423 alc_pcm_null_stream;
2424 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2426 if (have_multi_adcs) {
2427 p = spec->stream_analog_alt_capture;
2429 p = &alc_pcm_analog_alt_capture;
2430 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2431 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2433 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2434 spec->num_adc_nids - 1;
2436 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2437 alc_pcm_null_stream;
2438 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
2445 static inline void alc_shutup(struct hda_codec *codec)
2447 struct alc_spec *spec = codec->spec;
2449 if (spec && spec->shutup)
2450 spec->shutup(codec);
2451 snd_hda_shutup_pins(codec);
2454 static void alc_free_kctls(struct hda_codec *codec)
2456 struct alc_spec *spec = codec->spec;
2458 if (spec->kctls.list) {
2459 struct snd_kcontrol_new *kctl = spec->kctls.list;
2461 for (i = 0; i < spec->kctls.used; i++)
2462 kfree(kctl[i].name);
2464 snd_array_free(&spec->kctls);
2467 static void alc_free_bind_ctls(struct hda_codec *codec)
2469 struct alc_spec *spec = codec->spec;
2470 if (spec->bind_ctls.list) {
2471 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2473 for (i = 0; i < spec->bind_ctls.used; i++)
2476 snd_array_free(&spec->bind_ctls);
2479 static void alc_free(struct hda_codec *codec)
2481 struct alc_spec *spec = codec->spec;
2487 snd_hda_input_jack_free(codec);
2488 alc_free_kctls(codec);
2489 alc_free_bind_ctls(codec);
2491 snd_hda_detach_beep_device(codec);
2494 #ifdef CONFIG_SND_HDA_POWER_SAVE
2495 static void alc_power_eapd(struct hda_codec *codec)
2497 alc_auto_setup_eapd(codec, false);
2500 static int alc_suspend(struct hda_codec *codec, pm_message_t state)
2502 struct alc_spec *spec = codec->spec;
2504 if (spec && spec->power_hook)
2505 spec->power_hook(codec);
2511 static int alc_resume(struct hda_codec *codec)
2513 msleep(150); /* to avoid pop noise */
2514 codec->patch_ops.init(codec);
2515 snd_hda_codec_resume_amp(codec);
2516 snd_hda_codec_resume_cache(codec);
2517 hda_call_check_power_status(codec, 0x01);
2524 static const struct hda_codec_ops alc_patch_ops = {
2525 .build_controls = alc_build_controls,
2526 .build_pcms = alc_build_pcms,
2529 .unsol_event = alc_unsol_event,
2531 .resume = alc_resume,
2533 #ifdef CONFIG_SND_HDA_POWER_SAVE
2534 .suspend = alc_suspend,
2535 .check_power_status = alc_check_power_status,
2537 .reboot_notify = alc_shutup,
2540 /* replace the codec chip_name with the given string */
2541 static int alc_codec_rename(struct hda_codec *codec, const char *name)
2543 kfree(codec->chip_name);
2544 codec->chip_name = kstrdup(name, GFP_KERNEL);
2545 if (!codec->chip_name) {
2553 * Rename codecs appropriately from COEF value
2555 struct alc_codec_rename_table {
2556 unsigned int vendor_id;
2557 unsigned short coef_mask;
2558 unsigned short coef_bits;
2562 static struct alc_codec_rename_table rename_tbl[] = {
2563 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2564 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2565 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2566 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2567 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2568 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2569 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
2570 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2571 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2572 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2573 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2574 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2575 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2576 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2577 { } /* terminator */
2580 static int alc_codec_rename_from_preset(struct hda_codec *codec)
2582 const struct alc_codec_rename_table *p;
2584 for (p = rename_tbl; p->vendor_id; p++) {
2585 if (p->vendor_id != codec->vendor_id)
2587 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
2588 return alc_codec_rename(codec, p->name);
2594 * Automatic parse of I/O pins from the BIOS configuration
2599 ALC_CTL_WIDGET_MUTE,
2604 static const struct snd_kcontrol_new alc_control_templates[] = {
2605 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2606 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2607 HDA_BIND_MUTE(NULL, 0, 0, 0),
2608 HDA_BIND_VOL(NULL, 0),
2609 HDA_BIND_SW(NULL, 0),
2612 /* add dynamic controls */
2613 static int add_control(struct alc_spec *spec, int type, const char *name,
2614 int cidx, unsigned long val)
2616 struct snd_kcontrol_new *knew;
2618 knew = alc_kcontrol_new(spec);
2621 *knew = alc_control_templates[type];
2622 knew->name = kstrdup(name, GFP_KERNEL);
2626 if (get_amp_nid_(val))
2627 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
2628 knew->private_value = val;
2632 static int add_control_with_pfx(struct alc_spec *spec, int type,
2633 const char *pfx, const char *dir,
2634 const char *sfx, int cidx, unsigned long val)
2637 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
2638 return add_control(spec, type, name, cidx, val);
2641 #define add_pb_vol_ctrl(spec, type, pfx, val) \
2642 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2643 #define add_pb_sw_ctrl(spec, type, pfx, val) \
2644 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2645 #define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2646 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2647 #define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2648 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
2650 static const char * const channel_name[4] = {
2651 "Front", "Surround", "CLFE", "Side"
2654 static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2655 bool can_be_master, int *index)
2657 struct auto_pin_cfg *cfg = &spec->autocfg;
2660 if (cfg->line_outs == 1 && !spec->multi_ios &&
2661 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
2664 switch (cfg->line_out_type) {
2665 case AUTO_PIN_SPEAKER_OUT:
2666 if (cfg->line_outs == 1)
2668 if (cfg->line_outs == 2)
2669 return ch ? "Bass Speaker" : "Speaker";
2671 case AUTO_PIN_HP_OUT:
2672 /* for multi-io case, only the primary out */
2673 if (ch && spec->multi_ios)
2678 if (cfg->line_outs == 1 && !spec->multi_ios)
2682 if (snd_BUG_ON(ch >= ARRAY_SIZE(channel_name)))
2685 return channel_name[ch];
2688 /* create input playback/capture controls for the given pin */
2689 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
2690 const char *ctlname, int ctlidx,
2691 int idx, hda_nid_t mix_nid)
2695 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
2696 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2699 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
2700 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2706 static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
2708 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2709 return (pincap & AC_PINCAP_IN) != 0;
2712 /* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
2713 static int alc_auto_fill_adc_caps(struct hda_codec *codec)
2715 struct alc_spec *spec = codec->spec;
2717 hda_nid_t *adc_nids = spec->private_adc_nids;
2718 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2719 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
2722 if (spec->shared_mic_hp)
2723 max_nums = 1; /* no multi streams with the shared HP/mic */
2725 nid = codec->start_nid;
2726 for (i = 0; i < codec->num_nodes; i++, nid++) {
2728 const hda_nid_t *list;
2729 unsigned int caps = get_wcaps(codec, nid);
2730 int type = get_wcaps_type(caps);
2732 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2734 adc_nids[nums] = nid;
2735 cap_nids[nums] = nid;
2739 type = get_wcaps_type(get_wcaps(codec, src));
2740 if (type == AC_WID_PIN)
2742 if (type == AC_WID_AUD_SEL) {
2743 cap_nids[nums] = src;
2746 n = snd_hda_get_conn_list(codec, src, &list);
2748 cap_nids[nums] = src;
2754 if (++nums >= max_nums)
2757 spec->adc_nids = spec->private_adc_nids;
2758 spec->capsrc_nids = spec->private_capsrc_nids;
2759 spec->num_adc_nids = nums;
2763 /* create playback/capture controls for input pins */
2764 static int alc_auto_create_input_ctls(struct hda_codec *codec)
2766 struct alc_spec *spec = codec->spec;
2767 const struct auto_pin_cfg *cfg = &spec->autocfg;
2768 hda_nid_t mixer = spec->mixer_nid;
2769 struct hda_input_mux *imux = &spec->private_imux[0];
2771 int i, c, err, idx, type_idx = 0;
2772 const char *prev_label = NULL;
2774 num_adcs = alc_auto_fill_adc_caps(codec);
2778 for (i = 0; i < cfg->num_inputs; i++) {
2782 pin = cfg->inputs[i].pin;
2783 if (!alc_is_input_pin(codec, pin))
2786 label = hda_get_autocfg_input_label(codec, cfg, i);
2787 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
2788 label = "Headphone Mic";
2789 if (prev_label && !strcmp(label, prev_label))
2796 idx = get_connection_index(codec, mixer, pin);
2798 err = new_analog_input(spec, pin,
2806 for (c = 0; c < num_adcs; c++) {
2807 hda_nid_t cap = get_capsrc(spec, c);
2808 idx = get_connection_index(codec, cap, pin);
2810 spec->imux_pins[imux->num_items] = pin;
2811 snd_hda_add_imux_item(imux, label, idx, NULL);
2817 spec->num_mux_defs = 1;
2818 spec->input_mux = imux;
2823 /* create a shared input with the headphone out */
2824 static int alc_auto_create_shared_input(struct hda_codec *codec)
2826 struct alc_spec *spec = codec->spec;
2827 struct auto_pin_cfg *cfg = &spec->autocfg;
2828 unsigned int defcfg;
2831 /* only one internal input pin? */
2832 if (cfg->num_inputs != 1)
2834 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2835 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2838 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
2839 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
2840 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
2841 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
2843 return 0; /* both not available */
2845 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2846 return 0; /* no input */
2848 cfg->inputs[1].pin = nid;
2849 cfg->inputs[1].type = AUTO_PIN_MIC;
2850 cfg->num_inputs = 2;
2851 spec->shared_mic_hp = 1;
2852 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
2856 static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
2857 unsigned int pin_type)
2859 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2862 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2863 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2867 static int get_pin_type(int line_out_type)
2869 if (line_out_type == AUTO_PIN_HP_OUT)
2875 static void alc_auto_init_analog_input(struct hda_codec *codec)
2877 struct alc_spec *spec = codec->spec;
2878 struct auto_pin_cfg *cfg = &spec->autocfg;
2881 for (i = 0; i < cfg->num_inputs; i++) {
2882 hda_nid_t nid = cfg->inputs[i].pin;
2883 if (alc_is_input_pin(codec, nid)) {
2884 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
2885 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
2886 snd_hda_codec_write(codec, nid, 0,
2887 AC_VERB_SET_AMP_GAIN_MUTE,
2892 /* mute all loopback inputs */
2893 if (spec->mixer_nid) {
2894 int nums = snd_hda_get_conn_list(codec, spec->mixer_nid, NULL);
2895 for (i = 0; i < nums; i++)
2896 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2897 AC_VERB_SET_AMP_GAIN_MUTE,
2902 /* convert from MIX nid to DAC */
2903 static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid)
2908 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT)
2910 num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list));
2911 for (i = 0; i < num; i++) {
2912 if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT)
2918 /* go down to the selector widget before the mixer */
2919 static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin)
2922 int num = snd_hda_get_connections(codec, pin, srcs,
2925 get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL)
2930 /* get MIX nid connected to the given pin targeted to DAC */
2931 static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
2937 pin = alc_go_down_to_selector(codec, pin);
2938 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2939 for (i = 0; i < num; i++) {
2940 if (alc_auto_mix_to_dac(codec, mix[i]) == dac)
2946 /* select the connection from pin to DAC if needed */
2947 static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin,
2953 pin = alc_go_down_to_selector(codec, pin);
2954 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2957 for (i = 0; i < num; i++) {
2958 if (alc_auto_mix_to_dac(codec, mix[i]) == dac) {
2959 snd_hda_codec_update_cache(codec, pin, 0,
2960 AC_VERB_SET_CONNECT_SEL, i);
2967 /* look for an empty DAC slot */
2968 static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
2970 struct alc_spec *spec = codec->spec;
2974 pin = alc_go_down_to_selector(codec, pin);
2975 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
2976 for (i = 0; i < num; i++) {
2977 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
2980 if (found_in_nid_list(nid, spec->multiout.dac_nids,
2981 ARRAY_SIZE(spec->private_dac_nids)))
2983 if (found_in_nid_list(nid, spec->multiout.hp_out_nid,
2984 ARRAY_SIZE(spec->multiout.hp_out_nid)))
2986 if (found_in_nid_list(nid, spec->multiout.extra_out_nid,
2987 ARRAY_SIZE(spec->multiout.extra_out_nid)))
2994 /* check whether the DAC is reachable from the pin */
2995 static bool alc_auto_is_dac_reachable(struct hda_codec *codec,
2996 hda_nid_t pin, hda_nid_t dac)
3001 pin = alc_go_down_to_selector(codec, pin);
3002 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
3003 for (i = 0; i < num; i++) {
3004 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
3011 static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
3013 hda_nid_t sel = alc_go_down_to_selector(codec, pin);
3014 if (snd_hda_get_conn_list(codec, sel, NULL) == 1)
3015 return alc_auto_look_for_dac(codec, pin);
3019 /* return 0 if no possible DAC is found, 1 if one or more found */
3020 static int alc_auto_fill_extra_dacs(struct hda_codec *codec, int num_outs,
3021 const hda_nid_t *pins, hda_nid_t *dacs)
3025 if (num_outs && !dacs[0]) {
3026 dacs[0] = alc_auto_look_for_dac(codec, pins[0]);
3031 for (i = 1; i < num_outs; i++)
3032 dacs[i] = get_dac_if_single(codec, pins[i]);
3033 for (i = 1; i < num_outs; i++) {
3035 dacs[i] = alc_auto_look_for_dac(codec, pins[i]);
3040 static int alc_auto_fill_multi_ios(struct hda_codec *codec,
3041 unsigned int location, int offset);
3042 static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3043 hda_nid_t pin, hda_nid_t dac);
3045 /* fill in the dac_nids table from the parsed pin configuration */
3046 static int alc_auto_fill_dac_nids(struct hda_codec *codec)
3048 struct alc_spec *spec = codec->spec;
3049 struct auto_pin_cfg *cfg = &spec->autocfg;
3050 unsigned int location, defcfg;
3052 bool redone = false;
3056 /* set num_dacs once to full for alc_auto_look_for_dac() */
3057 spec->multiout.num_dacs = cfg->line_outs;
3058 spec->multiout.hp_out_nid[0] = 0;
3059 spec->multiout.extra_out_nid[0] = 0;
3060 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
3061 spec->multiout.dac_nids = spec->private_dac_nids;
3062 spec->multi_ios = 0;
3064 /* fill hard-wired DACs first */
3066 for (i = 0; i < cfg->line_outs; i++)
3067 spec->private_dac_nids[i] =
3068 get_dac_if_single(codec, cfg->line_out_pins[i]);
3070 spec->multiout.hp_out_nid[0] =
3071 get_dac_if_single(codec, cfg->hp_pins[0]);
3072 if (cfg->speaker_outs)
3073 spec->multiout.extra_out_nid[0] =
3074 get_dac_if_single(codec, cfg->speaker_pins[0]);
3077 for (i = 0; i < cfg->line_outs; i++) {
3078 hda_nid_t pin = cfg->line_out_pins[i];
3079 if (spec->private_dac_nids[i])
3081 spec->private_dac_nids[i] = alc_auto_look_for_dac(codec, pin);
3082 if (!spec->private_dac_nids[i] && !redone) {
3083 /* if we can't find primary DACs, re-probe without
3084 * checking the hard-wired DACs
3091 /* re-count num_dacs and squash invalid entries */
3092 spec->multiout.num_dacs = 0;
3093 for (i = 0; i < cfg->line_outs; i++) {
3094 if (spec->private_dac_nids[i])
3095 spec->multiout.num_dacs++;
3097 memmove(spec->private_dac_nids + i,
3098 spec->private_dac_nids + i + 1,
3099 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
3100 spec->private_dac_nids[cfg->line_outs - 1] = 0;
3104 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3105 /* try to fill multi-io first */
3106 defcfg = snd_hda_codec_get_pincfg(codec, cfg->line_out_pins[0]);
3107 location = get_defcfg_location(defcfg);
3109 num_pins = alc_auto_fill_multi_ios(codec, location, 0);
3111 spec->multi_ios = num_pins;
3112 spec->ext_channel_count = 2;
3113 spec->multiout.num_dacs = num_pins + 1;
3117 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
3118 alc_auto_fill_extra_dacs(codec, cfg->hp_outs, cfg->hp_pins,
3119 spec->multiout.hp_out_nid);
3120 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3121 int err = alc_auto_fill_extra_dacs(codec, cfg->speaker_outs,
3123 spec->multiout.extra_out_nid);
3124 /* if no speaker volume is assigned, try again as the primary
3127 if (!err && cfg->speaker_outs > 0 &&
3128 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3129 cfg->hp_outs = cfg->line_outs;
3130 memcpy(cfg->hp_pins, cfg->line_out_pins,
3131 sizeof(cfg->hp_pins));
3132 cfg->line_outs = cfg->speaker_outs;
3133 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3134 sizeof(cfg->speaker_pins));
3135 cfg->speaker_outs = 0;
3136 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3137 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
3143 if (!spec->multi_ios &&
3144 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
3146 /* try multi-ios with HP + inputs */
3147 defcfg = snd_hda_codec_get_pincfg(codec, cfg->hp_pins[0]);
3148 location = get_defcfg_location(defcfg);
3150 num_pins = alc_auto_fill_multi_ios(codec, location, 1);
3152 spec->multi_ios = num_pins;
3153 spec->ext_channel_count = 2;
3154 spec->multiout.num_dacs = num_pins + 1;
3158 if (cfg->line_out_pins[0])
3160 alc_look_for_out_vol_nid(codec, cfg->line_out_pins[0],
3161 spec->multiout.dac_nids[0]);
3165 static inline unsigned int get_ctl_pos(unsigned int data)
3167 hda_nid_t nid = get_amp_nid_(data);
3168 unsigned int dir = get_amp_direction_(data);
3169 return (nid << 1) | dir;
3172 #define is_ctl_used(bits, data) \
3173 test_bit(get_ctl_pos(data), bits)
3174 #define mark_ctl_usage(bits, data) \
3175 set_bit(get_ctl_pos(data), bits)
3177 static int alc_auto_add_vol_ctl(struct hda_codec *codec,
3178 const char *pfx, int cidx,
3179 hda_nid_t nid, unsigned int chs)
3181 struct alc_spec *spec = codec->spec;
3185 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3186 if (is_ctl_used(spec->vol_ctls, val) && chs != 2) /* exclude LFE */
3188 mark_ctl_usage(spec->vol_ctls, val);
3189 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
3193 static int alc_auto_add_stereo_vol(struct hda_codec *codec,
3194 const char *pfx, int cidx,
3198 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3200 return alc_auto_add_vol_ctl(codec, pfx, cidx, nid, chs);
3203 /* create a mute-switch for the given mixer widget;
3204 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3206 static int alc_auto_add_sw_ctl(struct hda_codec *codec,
3207 const char *pfx, int cidx,
3208 hda_nid_t nid, unsigned int chs)
3210 struct alc_spec *spec = codec->spec;
3216 wid_type = get_wcaps_type(get_wcaps(codec, nid));
3217 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) {
3218 type = ALC_CTL_WIDGET_MUTE;
3219 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3220 } else if (snd_hda_get_conn_list(codec, nid, NULL) == 1) {
3221 type = ALC_CTL_WIDGET_MUTE;
3222 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
3224 type = ALC_CTL_BIND_MUTE;
3225 val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
3227 if (is_ctl_used(spec->sw_ctls, val) && chs != 2) /* exclude LFE */
3229 mark_ctl_usage(spec->sw_ctls, val);
3230 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
3233 static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
3234 int cidx, hda_nid_t nid)
3237 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3239 return alc_auto_add_sw_ctl(codec, pfx, cidx, nid, chs);
3242 static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3243 hda_nid_t pin, hda_nid_t dac)
3245 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3246 if (nid_has_mute(codec, pin, HDA_OUTPUT))
3248 else if (mix && nid_has_mute(codec, mix, HDA_INPUT))
3250 else if (nid_has_mute(codec, dac, HDA_OUTPUT))
3255 static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3256 hda_nid_t pin, hda_nid_t dac)
3258 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3259 if (nid_has_volume(codec, dac, HDA_OUTPUT))
3261 else if (nid_has_volume(codec, mix, HDA_OUTPUT))
3263 else if (nid_has_volume(codec, pin, HDA_OUTPUT))
3268 /* add playback controls from the parsed DAC table */
3269 static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
3270 const struct auto_pin_cfg *cfg)
3272 struct alc_spec *spec = codec->spec;
3273 int i, err, noutputs;
3275 noutputs = cfg->line_outs;
3276 if (spec->multi_ios > 0)
3277 noutputs += spec->multi_ios;
3279 for (i = 0; i < noutputs; i++) {
3285 dac = spec->multiout.dac_nids[i];
3288 if (i >= cfg->line_outs)
3289 pin = spec->multi_io[i - 1].pin;
3291 pin = cfg->line_out_pins[i];
3293 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3294 vol = alc_look_for_out_vol_nid(codec, pin, dac);
3295 name = alc_get_line_out_pfx(spec, i, true, &index);
3296 if (!name || !strcmp(name, "CLFE")) {
3298 err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1);
3301 err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2);
3304 err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1);
3307 err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2);
3311 err = alc_auto_add_stereo_vol(codec, name, index, vol);
3314 err = alc_auto_add_stereo_sw(codec, name, index, sw);
3322 static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
3323 hda_nid_t dac, const char *pfx,
3326 struct alc_spec *spec = codec->spec;
3332 /* the corresponding DAC is already occupied */
3333 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
3334 return 0; /* no way */
3335 /* create a switch only */
3336 val = HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT);
3337 if (is_ctl_used(spec->sw_ctls, val))
3338 return 0; /* already created */
3339 mark_ctl_usage(spec->sw_ctls, val);
3340 return __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, cidx, val);
3343 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3344 vol = alc_look_for_out_vol_nid(codec, pin, dac);
3345 err = alc_auto_add_stereo_vol(codec, pfx, cidx, vol);
3348 err = alc_auto_add_stereo_sw(codec, pfx, cidx, sw);
3354 static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3356 struct hda_ctl_ops *ops)
3358 struct alc_spec *spec = codec->spec;
3359 struct hda_bind_ctls **ctlp, *ctl;
3360 snd_array_init(&spec->bind_ctls, sizeof(ctl), 8);
3361 ctlp = snd_array_new(&spec->bind_ctls);
3364 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3371 /* add playback controls for speaker and HP outputs */
3372 static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3373 const hda_nid_t *pins,
3374 const hda_nid_t *dacs,
3377 struct alc_spec *spec = codec->spec;
3378 struct hda_bind_ctls *ctl;
3382 if (!num_pins || !pins[0])
3385 if (num_pins == 1) {
3386 hda_nid_t dac = *dacs;
3388 dac = spec->multiout.dac_nids[0];
3389 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
3392 if (dacs[num_pins - 1]) {
3393 /* OK, we have a multi-output system with individual volumes */
3394 for (i = 0; i < num_pins; i++) {
3395 if (num_pins >= 3) {
3396 snprintf(name, sizeof(name), "%s %s",
3397 pfx, channel_name[i]);
3398 err = alc_auto_create_extra_out(codec, pins[i], dacs[i],
3401 err = alc_auto_create_extra_out(codec, pins[i], dacs[i],
3410 /* Let's create a bind-controls */
3411 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_sw);
3415 for (i = 0; i < num_pins; i++) {
3416 if (get_wcaps(codec, pins[i]) & AC_WCAP_OUT_AMP)
3418 HDA_COMPOSE_AMP_VAL(pins[i], 3, 0, HDA_OUTPUT);
3421 snprintf(name, sizeof(name), "%s Playback Switch", pfx);
3422 err = add_control(spec, ALC_CTL_BIND_SW, name, 0, (long)ctl);
3427 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3431 for (i = 0; i < num_pins; i++) {
3433 if (!pins[i] || !dacs[i])
3435 vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]);
3438 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3441 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3442 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3449 static int alc_auto_create_hp_out(struct hda_codec *codec)
3451 struct alc_spec *spec = codec->spec;
3452 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3453 spec->autocfg.hp_pins,
3454 spec->multiout.hp_out_nid,
3458 static int alc_auto_create_speaker_out(struct hda_codec *codec)
3460 struct alc_spec *spec = codec->spec;
3461 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3462 spec->autocfg.speaker_pins,
3463 spec->multiout.extra_out_nid,
3467 static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
3468 hda_nid_t pin, int pin_type,
3472 hda_nid_t nid, mix = 0;
3473 hda_nid_t srcs[HDA_MAX_CONNECTIONS];
3475 alc_set_pin_output(codec, pin, pin_type);
3476 nid = alc_go_down_to_selector(codec, pin);
3477 num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
3478 for (i = 0; i < num; i++) {
3479 if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
3487 /* need the manual connection? */
3489 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
3490 /* unmute mixer widget inputs */
3491 if (nid_has_mute(codec, mix, HDA_INPUT)) {
3492 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3494 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3497 /* initialize volume */
3498 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3500 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3503 /* unmute DAC if it's not assigned to a mixer */
3504 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3505 if (nid == mix && nid_has_mute(codec, dac, HDA_OUTPUT))
3506 snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3510 static void alc_auto_init_multi_out(struct hda_codec *codec)
3512 struct alc_spec *spec = codec->spec;
3513 int pin_type = get_pin_type(spec->autocfg.line_out_type);
3516 for (i = 0; i <= HDA_SIDE; i++) {
3517 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3519 alc_auto_set_output_and_unmute(codec, nid, pin_type,
3520 spec->multiout.dac_nids[i]);
3524 static void alc_auto_init_extra_out(struct hda_codec *codec)
3526 struct alc_spec *spec = codec->spec;
3530 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3531 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3533 pin = spec->autocfg.hp_pins[i];
3536 dac = spec->multiout.hp_out_nid[i];
3538 if (i > 0 && spec->multiout.hp_out_nid[0])
3539 dac = spec->multiout.hp_out_nid[0];
3541 dac = spec->multiout.dac_nids[0];
3543 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
3545 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3546 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3548 pin = spec->autocfg.speaker_pins[i];
3551 dac = spec->multiout.extra_out_nid[i];
3553 if (i > 0 && spec->multiout.extra_out_nid[0])
3554 dac = spec->multiout.extra_out_nid[0];
3556 dac = spec->multiout.dac_nids[0];
3558 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
3565 static int alc_auto_fill_multi_ios(struct hda_codec *codec,
3566 unsigned int location,
3569 struct alc_spec *spec = codec->spec;
3570 struct auto_pin_cfg *cfg = &spec->autocfg;
3571 hda_nid_t prime_dac = spec->private_dac_nids[0];
3572 int type, i, dacs, num_pins = 0;
3574 dacs = spec->multiout.num_dacs;
3575 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3576 for (i = 0; i < cfg->num_inputs; i++) {
3577 hda_nid_t nid = cfg->inputs[i].pin;
3579 unsigned int defcfg, caps;
3580 if (cfg->inputs[i].type != type)
3582 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3583 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3585 if (location && get_defcfg_location(defcfg) != location)
3587 caps = snd_hda_query_pin_caps(codec, nid);
3588 if (!(caps & AC_PINCAP_OUT))
3590 if (offset && offset + num_pins < dacs) {
3591 dac = spec->private_dac_nids[offset + num_pins];
3592 if (!alc_auto_is_dac_reachable(codec, nid, dac))
3596 dac = alc_auto_look_for_dac(codec, nid);
3599 spec->multi_io[num_pins].pin = nid;
3600 spec->multi_io[num_pins].dac = dac;
3602 spec->private_dac_nids[spec->multiout.num_dacs++] = dac;
3605 spec->multiout.num_dacs = dacs;
3607 /* clear up again */
3608 memset(spec->private_dac_nids + dacs, 0,
3609 sizeof(hda_nid_t) * (AUTO_CFG_MAX_OUTS - dacs));
3610 spec->private_dac_nids[0] = prime_dac;
3616 static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
3617 struct snd_ctl_elem_info *uinfo)
3619 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3620 struct alc_spec *spec = codec->spec;
3622 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3624 uinfo->value.enumerated.items = spec->multi_ios + 1;
3625 if (uinfo->value.enumerated.item > spec->multi_ios)
3626 uinfo->value.enumerated.item = spec->multi_ios;
3627 sprintf(uinfo->value.enumerated.name, "%dch",
3628 (uinfo->value.enumerated.item + 1) * 2);
3632 static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
3633 struct snd_ctl_elem_value *ucontrol)
3635 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3636 struct alc_spec *spec = codec->spec;
3637 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
3641 static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
3643 struct alc_spec *spec = codec->spec;
3644 hda_nid_t nid = spec->multi_io[idx].pin;
3646 if (!spec->multi_io[idx].ctl_in)
3647 spec->multi_io[idx].ctl_in =
3648 snd_hda_codec_read(codec, nid, 0,
3649 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3651 snd_hda_codec_update_cache(codec, nid, 0,
3652 AC_VERB_SET_PIN_WIDGET_CONTROL,
3654 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3655 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3657 alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
3659 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3660 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3661 HDA_AMP_MUTE, HDA_AMP_MUTE);
3662 snd_hda_codec_update_cache(codec, nid, 0,
3663 AC_VERB_SET_PIN_WIDGET_CONTROL,
3664 spec->multi_io[idx].ctl_in);
3669 static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
3670 struct snd_ctl_elem_value *ucontrol)
3672 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3673 struct alc_spec *spec = codec->spec;
3676 ch = ucontrol->value.enumerated.item[0];
3677 if (ch < 0 || ch > spec->multi_ios)
3679 if (ch == (spec->ext_channel_count - 1) / 2)
3681 spec->ext_channel_count = (ch + 1) * 2;
3682 for (i = 0; i < spec->multi_ios; i++)
3683 alc_set_multi_io(codec, i, i < ch);
3684 spec->multiout.max_channels = spec->ext_channel_count;
3685 if (spec->need_dac_fix && !spec->const_channel_count)
3686 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
3690 static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
3691 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3692 .name = "Channel Mode",
3693 .info = alc_auto_ch_mode_info,
3694 .get = alc_auto_ch_mode_get,
3695 .put = alc_auto_ch_mode_put,
3698 static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
3700 struct alc_spec *spec = codec->spec;
3702 if (spec->multi_ios > 0) {
3703 struct snd_kcontrol_new *knew;
3705 knew = alc_kcontrol_new(spec);
3708 *knew = alc_auto_channel_mode_enum;
3709 knew->name = kstrdup("Channel Mode", GFP_KERNEL);
3716 /* filter out invalid adc_nids (and capsrc_nids) that don't give all
3719 static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
3721 struct alc_spec *spec = codec->spec;
3722 const struct hda_input_mux *imux;
3723 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3724 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3727 imux = spec->input_mux;
3730 if (spec->dyn_adc_switch)
3734 for (n = 0; n < spec->num_adc_nids; n++) {
3735 hda_nid_t cap = spec->private_capsrc_nids[n];
3736 int num_conns = snd_hda_get_conn_list(codec, cap, NULL);
3737 for (i = 0; i < imux->num_items; i++) {
3738 hda_nid_t pin = spec->imux_pins[i];
3740 if (get_connection_index(codec, cap, pin) < 0)
3742 } else if (num_conns <= imux->items[i].index)
3745 if (i >= imux->num_items) {
3746 adc_nids[nums] = spec->private_adc_nids[n];
3747 capsrc_nids[nums++] = cap;
3751 /* check whether ADC-switch is possible */
3752 if (!alc_check_dyn_adc_switch(codec)) {
3753 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
3754 " using fallback 0x%x\n",
3755 codec->chip_name, spec->private_adc_nids[0]);
3756 spec->num_adc_nids = 1;
3760 } else if (nums != spec->num_adc_nids) {
3761 memcpy(spec->private_adc_nids, adc_nids,
3762 nums * sizeof(hda_nid_t));
3763 memcpy(spec->private_capsrc_nids, capsrc_nids,
3764 nums * sizeof(hda_nid_t));
3765 spec->num_adc_nids = nums;
3769 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
3770 else if (spec->input_mux->num_items == 1)
3771 spec->num_adc_nids = 1; /* reduce to a single ADC */
3775 * initialize ADC paths
3777 static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
3779 struct alc_spec *spec = codec->spec;
3782 nid = spec->adc_nids[adc_idx];
3784 if (nid_has_mute(codec, nid, HDA_INPUT)) {
3785 snd_hda_codec_write(codec, nid, 0,
3786 AC_VERB_SET_AMP_GAIN_MUTE,
3790 if (!spec->capsrc_nids)
3792 nid = spec->capsrc_nids[adc_idx];
3793 if (nid_has_mute(codec, nid, HDA_OUTPUT))
3794 snd_hda_codec_write(codec, nid, 0,
3795 AC_VERB_SET_AMP_GAIN_MUTE,
3799 static void alc_auto_init_input_src(struct hda_codec *codec)
3801 struct alc_spec *spec = codec->spec;
3804 for (c = 0; c < spec->num_adc_nids; c++)
3805 alc_auto_init_adc(codec, c);
3806 if (spec->dyn_adc_switch)
3809 nums = spec->num_adc_nids;
3810 for (c = 0; c < nums; c++)
3811 alc_mux_select(codec, 0, spec->cur_mux[c], true);
3814 /* add mic boosts if needed */
3815 static int alc_auto_add_mic_boost(struct hda_codec *codec)
3817 struct alc_spec *spec = codec->spec;
3818 struct auto_pin_cfg *cfg = &spec->autocfg;
3822 const char *prev_label = NULL;
3824 for (i = 0; i < cfg->num_inputs; i++) {
3825 if (cfg->inputs[i].type > AUTO_PIN_MIC)
3827 nid = cfg->inputs[i].pin;
3828 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
3830 char boost_label[32];
3832 label = hda_get_autocfg_input_label(codec, cfg, i);
3833 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
3834 label = "Headphone Mic";
3835 if (prev_label && !strcmp(label, prev_label))
3841 snprintf(boost_label, sizeof(boost_label),
3842 "%s Boost Volume", label);
3843 err = add_control(spec, ALC_CTL_WIDGET_VOL,
3844 boost_label, type_idx,
3845 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
3853 /* select or unmute the given capsrc route */
3854 static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
3857 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
3858 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
3860 } else if (snd_hda_get_conn_list(codec, cap, NULL) > 1) {
3861 snd_hda_codec_write_cache(codec, cap, 0,
3862 AC_VERB_SET_CONNECT_SEL, idx);
3866 /* set the default connection to that pin */
3867 static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
3869 struct alc_spec *spec = codec->spec;
3874 for (i = 0; i < spec->num_adc_nids; i++) {
3875 hda_nid_t cap = get_capsrc(spec, i);
3878 idx = get_connection_index(codec, cap, pin);
3881 select_or_unmute_capsrc(codec, cap, idx);
3882 return i; /* return the found index */
3884 return -1; /* not found */
3887 /* initialize some special cases for input sources */
3888 static void alc_init_special_input_src(struct hda_codec *codec)
3890 struct alc_spec *spec = codec->spec;
3893 for (i = 0; i < spec->autocfg.num_inputs; i++)
3894 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
3897 /* assign appropriate capture mixers */
3898 static void set_capture_mixer(struct hda_codec *codec)
3900 struct alc_spec *spec = codec->spec;
3901 static const struct snd_kcontrol_new *caps[2][3] = {
3902 { alc_capture_mixer_nosrc1,
3903 alc_capture_mixer_nosrc2,
3904 alc_capture_mixer_nosrc3 },
3905 { alc_capture_mixer1,
3907 alc_capture_mixer3 },
3910 /* check whether either of ADC or MUX has a volume control */
3911 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
3912 if (!spec->capsrc_nids)
3913 return; /* no volume */
3914 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
3915 return; /* no volume in capsrc, too */
3916 spec->vol_in_capsrc = 1;
3919 if (spec->num_adc_nids > 0) {
3923 if (spec->input_mux && spec->input_mux->num_items > 1)
3925 if (spec->auto_mic) {
3928 } else if (spec->dyn_adc_switch)
3931 if (spec->num_adc_nids > 3)
3932 spec->num_adc_nids = 3;
3933 else if (!spec->num_adc_nids)
3935 num_adcs = spec->num_adc_nids;
3937 spec->cap_mixer = caps[mux][num_adcs - 1];
3942 * standard auto-parser initializations
3944 static void alc_auto_init_std(struct hda_codec *codec)
3946 struct alc_spec *spec = codec->spec;
3947 alc_auto_init_multi_out(codec);
3948 alc_auto_init_extra_out(codec);
3949 alc_auto_init_analog_input(codec);
3950 alc_auto_init_input_src(codec);
3951 alc_auto_init_digital(codec);
3952 if (spec->unsol_event)
3953 alc_inithook(codec);
3957 * Digital-beep handlers
3959 #ifdef CONFIG_SND_HDA_INPUT_BEEP
3960 #define set_beep_amp(spec, nid, idx, dir) \
3961 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
3963 static const struct snd_pci_quirk beep_white_list[] = {
3964 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
3965 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
3966 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
3967 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
3968 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
3972 static inline int has_cdefine_beep(struct hda_codec *codec)
3974 struct alc_spec *spec = codec->spec;
3975 const struct snd_pci_quirk *q;
3976 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
3979 return spec->cdefine.enable_pcbeep;
3982 #define set_beep_amp(spec, nid, idx, dir) /* NOP */
3983 #define has_cdefine_beep(codec) 0
3986 /* parse the BIOS configuration and set up the alc_spec */
3987 /* return 1 if successful, 0 if the proper config is not found,
3988 * or a negative error code
3990 static int alc_parse_auto_config(struct hda_codec *codec,
3991 const hda_nid_t *ignore_nids,
3992 const hda_nid_t *ssid_nids)
3994 struct alc_spec *spec = codec->spec;
3995 struct auto_pin_cfg *cfg = &spec->autocfg;
3998 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
4002 if (!cfg->line_outs) {
4003 if (cfg->dig_outs || cfg->dig_in_pin) {
4004 spec->multiout.max_channels = 2;
4005 spec->no_analog = 1;
4008 return 0; /* can't find valid BIOS pin config */
4011 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
4012 cfg->line_outs <= cfg->hp_outs) {
4013 /* use HP as primary out */
4014 cfg->speaker_outs = cfg->line_outs;
4015 memcpy(cfg->speaker_pins, cfg->line_out_pins,
4016 sizeof(cfg->speaker_pins));
4017 cfg->line_outs = cfg->hp_outs;
4018 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
4020 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
4021 cfg->line_out_type = AUTO_PIN_HP_OUT;
4024 err = alc_auto_fill_dac_nids(codec);
4027 err = alc_auto_add_multi_channel_mode(codec);
4030 err = alc_auto_create_multi_out_ctls(codec, cfg);
4033 err = alc_auto_create_hp_out(codec);
4036 err = alc_auto_create_speaker_out(codec);
4039 err = alc_auto_create_shared_input(codec);
4042 err = alc_auto_create_input_ctls(codec);
4046 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4049 alc_auto_parse_digital(codec);
4051 if (!spec->no_analog)
4052 alc_remove_invalid_adc_nids(codec);
4055 alc_ssid_check(codec, ssid_nids);
4057 if (!spec->no_analog) {
4058 alc_auto_check_switches(codec);
4059 err = alc_auto_add_mic_boost(codec);
4064 if (spec->kctls.list)
4065 add_mixer(spec, spec->kctls.list);
4070 static int alc880_parse_auto_config(struct hda_codec *codec)
4072 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
4073 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4074 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
4077 #ifdef CONFIG_SND_HDA_POWER_SAVE
4078 static const struct hda_amp_list alc880_loopbacks[] = {
4079 { 0x0b, HDA_INPUT, 0 },
4080 { 0x0b, HDA_INPUT, 1 },
4081 { 0x0b, HDA_INPUT, 2 },
4082 { 0x0b, HDA_INPUT, 3 },
4083 { 0x0b, HDA_INPUT, 4 },
4093 ALC880_FIXUP_MEDION_RIM,
4096 static const struct alc_fixup alc880_fixups[] = {
4097 [ALC880_FIXUP_GPIO2] = {
4098 .type = ALC_FIXUP_VERBS,
4099 .v.verbs = alc_gpio2_init_verbs,
4101 [ALC880_FIXUP_MEDION_RIM] = {
4102 .type = ALC_FIXUP_VERBS,
4103 .v.verbs = (const struct hda_verb[]) {
4104 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4105 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4109 .chain_id = ALC880_FIXUP_GPIO2,
4113 static const struct snd_pci_quirk alc880_fixup_tbl[] = {
4114 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
4122 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4123 #define alc_board_config \
4124 snd_hda_check_board_config
4125 #define alc_board_codec_sid_config \
4126 snd_hda_check_board_codec_sid_config
4127 #include "alc_quirks.c"
4129 #define alc_board_config(codec, nums, models, tbl) -1
4130 #define alc_board_codec_sid_config(codec, nums, models, tbl) -1
4131 #define setup_preset(codec, x) /* NOP */
4135 * OK, here we have finally the patch for ALC880
4137 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4138 #include "alc880_quirks.c"
4141 static int patch_alc880(struct hda_codec *codec)
4143 struct alc_spec *spec;
4147 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4153 spec->mixer_nid = 0x0b;
4154 spec->need_dac_fix = 1;
4156 board_config = alc_board_config(codec, ALC880_MODEL_LAST,
4157 alc880_models, alc880_cfg_tbl);
4158 if (board_config < 0) {
4159 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4161 board_config = ALC_MODEL_AUTO;
4164 if (board_config == ALC_MODEL_AUTO) {
4165 alc_pick_fixup(codec, NULL, alc880_fixup_tbl, alc880_fixups);
4166 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4169 if (board_config == ALC_MODEL_AUTO) {
4170 /* automatic parse from the BIOS config */
4171 err = alc880_parse_auto_config(codec);
4174 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4177 "hda_codec: Cannot set up configuration "
4178 "from BIOS. Using 3-stack mode...\n");
4179 board_config = ALC880_3ST;
4184 if (board_config != ALC_MODEL_AUTO) {
4185 spec->vmaster_nid = 0x0c;
4186 setup_preset(codec, &alc880_presets[board_config]);
4189 if (!spec->no_analog && !spec->adc_nids) {
4190 alc_auto_fill_adc_caps(codec);
4191 alc_rebuild_imux_for_auto_mic(codec);
4192 alc_remove_invalid_adc_nids(codec);
4195 if (!spec->no_analog && !spec->cap_mixer)
4196 set_capture_mixer(codec);
4198 if (!spec->no_analog) {
4199 err = snd_hda_attach_beep_device(codec, 0x1);
4202 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4205 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4207 codec->patch_ops = alc_patch_ops;
4208 if (board_config == ALC_MODEL_AUTO)
4209 spec->init_hook = alc_auto_init_std;
4210 #ifdef CONFIG_SND_HDA_POWER_SAVE
4211 if (!spec->loopback.amplist)
4212 spec->loopback.amplist = alc880_loopbacks;
4226 static int alc260_parse_auto_config(struct hda_codec *codec)
4228 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
4229 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
4230 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
4233 #ifdef CONFIG_SND_HDA_POWER_SAVE
4234 static const struct hda_amp_list alc260_loopbacks[] = {
4235 { 0x07, HDA_INPUT, 0 },
4236 { 0x07, HDA_INPUT, 1 },
4237 { 0x07, HDA_INPUT, 2 },
4238 { 0x07, HDA_INPUT, 3 },
4239 { 0x07, HDA_INPUT, 4 },
4251 static const struct alc_fixup alc260_fixups[] = {
4252 [PINFIX_HP_DC5750] = {
4253 .type = ALC_FIXUP_PINS,
4254 .v.pins = (const struct alc_pincfg[]) {
4255 { 0x11, 0x90130110 }, /* speaker */
4261 static const struct snd_pci_quirk alc260_fixup_tbl[] = {
4262 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", PINFIX_HP_DC5750),
4268 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4269 #include "alc260_quirks.c"
4272 static int patch_alc260(struct hda_codec *codec)
4274 struct alc_spec *spec;
4275 int err, board_config;
4277 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4283 spec->mixer_nid = 0x07;
4285 board_config = alc_board_config(codec, ALC260_MODEL_LAST,
4286 alc260_models, alc260_cfg_tbl);
4287 if (board_config < 0) {
4288 snd_printd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4290 board_config = ALC_MODEL_AUTO;
4293 if (board_config == ALC_MODEL_AUTO) {
4294 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
4295 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4298 if (board_config == ALC_MODEL_AUTO) {
4299 /* automatic parse from the BIOS config */
4300 err = alc260_parse_auto_config(codec);
4303 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4306 "hda_codec: Cannot set up configuration "
4307 "from BIOS. Using base mode...\n");
4308 board_config = ALC260_BASIC;
4313 if (board_config != ALC_MODEL_AUTO) {
4314 setup_preset(codec, &alc260_presets[board_config]);
4315 spec->vmaster_nid = 0x08;
4318 if (!spec->no_analog && !spec->adc_nids) {
4319 alc_auto_fill_adc_caps(codec);
4320 alc_rebuild_imux_for_auto_mic(codec);
4321 alc_remove_invalid_adc_nids(codec);
4324 if (!spec->no_analog && !spec->cap_mixer)
4325 set_capture_mixer(codec);
4327 if (!spec->no_analog) {
4328 err = snd_hda_attach_beep_device(codec, 0x1);
4331 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
4334 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4336 codec->patch_ops = alc_patch_ops;
4337 if (board_config == ALC_MODEL_AUTO)
4338 spec->init_hook = alc_auto_init_std;
4339 spec->shutup = alc_eapd_shutup;
4340 #ifdef CONFIG_SND_HDA_POWER_SAVE
4341 if (!spec->loopback.amplist)
4342 spec->loopback.amplist = alc260_loopbacks;
4354 * ALC882/883/885/888/889 support
4356 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
4357 * configuration. Each pin widget can choose any input DACs and a mixer.
4358 * Each ADC is connected from a mixer of all inputs. This makes possible
4359 * 6-channel independent captures.
4361 * In addition, an independent DAC for the multi-playback (not used in this
4364 #ifdef CONFIG_SND_HDA_POWER_SAVE
4365 #define alc882_loopbacks alc880_loopbacks
4372 ALC882_FIXUP_ABIT_AW9D_MAX,
4373 ALC882_FIXUP_LENOVO_Y530,
4374 ALC882_FIXUP_PB_M5210,
4375 ALC882_FIXUP_ACER_ASPIRE_7736,
4376 ALC882_FIXUP_ASUS_W90V,
4377 ALC889_FIXUP_VAIO_TT,
4378 ALC888_FIXUP_EEE1601,
4381 ALC883_FIXUP_ACER_EAPD,
4384 ALC882_FIXUP_ASUS_W2JC,
4385 ALC882_FIXUP_ACER_ASPIRE_4930G,
4386 ALC882_FIXUP_ACER_ASPIRE_8930G,
4387 ALC882_FIXUP_ASPIRE_8930G_VERBS,
4388 ALC885_FIXUP_MACPRO_GPIO,
4391 static void alc889_fixup_coef(struct hda_codec *codec,
4392 const struct alc_fixup *fix, int action)
4394 if (action != ALC_FIXUP_ACT_INIT)
4396 alc889_coef_init(codec);
4399 /* toggle speaker-output according to the hp-jack state */
4400 static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
4402 unsigned int gpiostate, gpiomask, gpiodir;
4404 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
4405 AC_VERB_GET_GPIO_DATA, 0);
4408 gpiostate |= (1 << pin);
4410 gpiostate &= ~(1 << pin);
4412 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
4413 AC_VERB_GET_GPIO_MASK, 0);
4414 gpiomask |= (1 << pin);
4416 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
4417 AC_VERB_GET_GPIO_DIRECTION, 0);
4418 gpiodir |= (1 << pin);
4421 snd_hda_codec_write(codec, codec->afg, 0,
4422 AC_VERB_SET_GPIO_MASK, gpiomask);
4423 snd_hda_codec_write(codec, codec->afg, 0,
4424 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
4428 snd_hda_codec_write(codec, codec->afg, 0,
4429 AC_VERB_SET_GPIO_DATA, gpiostate);
4432 /* set up GPIO at initialization */
4433 static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
4434 const struct alc_fixup *fix, int action)
4436 if (action != ALC_FIXUP_ACT_INIT)
4438 alc882_gpio_mute(codec, 0, 0);
4439 alc882_gpio_mute(codec, 1, 0);
4442 static const struct alc_fixup alc882_fixups[] = {
4443 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
4444 .type = ALC_FIXUP_PINS,
4445 .v.pins = (const struct alc_pincfg[]) {
4446 { 0x15, 0x01080104 }, /* side */
4447 { 0x16, 0x01011012 }, /* rear */
4448 { 0x17, 0x01016011 }, /* clfe */
4452 [ALC882_FIXUP_LENOVO_Y530] = {
4453 .type = ALC_FIXUP_PINS,
4454 .v.pins = (const struct alc_pincfg[]) {
4455 { 0x15, 0x99130112 }, /* rear int speakers */
4456 { 0x16, 0x99130111 }, /* subwoofer */
4460 [ALC882_FIXUP_PB_M5210] = {
4461 .type = ALC_FIXUP_VERBS,
4462 .v.verbs = (const struct hda_verb[]) {
4463 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
4467 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
4468 .type = ALC_FIXUP_SKU,
4469 .v.sku = ALC_FIXUP_SKU_IGNORE,
4471 [ALC882_FIXUP_ASUS_W90V] = {
4472 .type = ALC_FIXUP_PINS,
4473 .v.pins = (const struct alc_pincfg[]) {
4474 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
4478 [ALC889_FIXUP_VAIO_TT] = {
4479 .type = ALC_FIXUP_PINS,
4480 .v.pins = (const struct alc_pincfg[]) {
4481 { 0x17, 0x90170111 }, /* hidden surround speaker */
4485 [ALC888_FIXUP_EEE1601] = {
4486 .type = ALC_FIXUP_VERBS,
4487 .v.verbs = (const struct hda_verb[]) {
4488 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
4489 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
4493 [ALC882_FIXUP_EAPD] = {
4494 .type = ALC_FIXUP_VERBS,
4495 .v.verbs = (const struct hda_verb[]) {
4496 /* change to EAPD mode */
4497 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4498 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4502 [ALC883_FIXUP_EAPD] = {
4503 .type = ALC_FIXUP_VERBS,
4504 .v.verbs = (const struct hda_verb[]) {
4505 /* change to EAPD mode */
4506 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4507 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4511 [ALC883_FIXUP_ACER_EAPD] = {
4512 .type = ALC_FIXUP_VERBS,
4513 .v.verbs = (const struct hda_verb[]) {
4514 /* eanable EAPD on Acer laptops */
4515 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4516 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4520 [ALC882_FIXUP_GPIO3] = {
4521 .type = ALC_FIXUP_VERBS,
4522 .v.verbs = alc_gpio3_init_verbs,
4524 [ALC882_FIXUP_ASUS_W2JC] = {
4525 .type = ALC_FIXUP_VERBS,
4526 .v.verbs = alc_gpio1_init_verbs,
4528 .chain_id = ALC882_FIXUP_EAPD,
4530 [ALC889_FIXUP_COEF] = {
4531 .type = ALC_FIXUP_FUNC,
4532 .v.func = alc889_fixup_coef,
4534 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
4535 .type = ALC_FIXUP_PINS,
4536 .v.pins = (const struct alc_pincfg[]) {
4537 { 0x16, 0x99130111 }, /* CLFE speaker */
4538 { 0x17, 0x99130112 }, /* surround speaker */
4542 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
4543 .type = ALC_FIXUP_PINS,
4544 .v.pins = (const struct alc_pincfg[]) {
4545 { 0x16, 0x99130111 }, /* CLFE speaker */
4546 { 0x1b, 0x99130112 }, /* surround speaker */
4550 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
4552 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
4553 /* additional init verbs for Acer Aspire 8930G */
4554 .type = ALC_FIXUP_VERBS,
4555 .v.verbs = (const struct hda_verb[]) {
4556 /* Enable all DACs */
4557 /* DAC DISABLE/MUTE 1? */
4558 /* setting bits 1-5 disables DAC nids 0x02-0x06
4559 * apparently. Init=0x38 */
4560 { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
4561 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
4562 /* DAC DISABLE/MUTE 2? */
4563 /* some bit here disables the other DACs.
4565 { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
4566 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
4568 * This laptop has a stereo digital microphone.
4569 * The mics are only 1cm apart which makes the stereo
4570 * useless. However, either the mic or the ALC889
4571 * makes the signal become a difference/sum signal
4572 * instead of standard stereo, which is annoying.
4573 * So instead we flip this bit which makes the
4574 * codec replicate the sum signal to both channels,
4575 * turning it into a normal mono mic.
4577 /* DMIC_CONTROL? Init value = 0x0001 */
4578 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
4579 { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
4580 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4581 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4585 [ALC885_FIXUP_MACPRO_GPIO] = {
4586 .type = ALC_FIXUP_FUNC,
4587 .v.func = alc885_fixup_macpro_gpio,
4591 static const struct snd_pci_quirk alc882_fixup_tbl[] = {
4592 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
4593 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
4594 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
4595 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
4596 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
4597 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
4598 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
4599 ALC882_FIXUP_ACER_ASPIRE_4930G),
4600 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
4601 ALC882_FIXUP_ACER_ASPIRE_4930G),
4602 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
4603 ALC882_FIXUP_ACER_ASPIRE_8930G),
4604 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
4605 ALC882_FIXUP_ACER_ASPIRE_8930G),
4606 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
4607 ALC882_FIXUP_ACER_ASPIRE_4930G),
4608 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
4609 ALC882_FIXUP_ACER_ASPIRE_4930G),
4610 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
4611 ALC882_FIXUP_ACER_ASPIRE_4930G),
4612 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
4613 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
4614 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
4615 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
4616 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
4617 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
4618 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
4620 /* All Apple entries are in codec SSIDs */
4621 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
4622 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
4623 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
4624 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
4625 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
4627 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
4628 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
4629 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
4630 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
4631 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
4632 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
4633 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
4638 * BIOS auto configuration
4640 /* almost identical with ALC880 parser... */
4641 static int alc882_parse_auto_config(struct hda_codec *codec)
4643 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
4644 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4645 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
4650 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4651 #include "alc882_quirks.c"
4654 static int patch_alc882(struct hda_codec *codec)
4656 struct alc_spec *spec;
4657 int err, board_config;
4659 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4665 spec->mixer_nid = 0x0b;
4667 switch (codec->vendor_id) {
4672 /* ALC883 and variants */
4673 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
4677 err = alc_codec_rename_from_preset(codec);
4681 board_config = alc_board_config(codec, ALC882_MODEL_LAST,
4682 alc882_models, NULL);
4683 if (board_config < 0)
4684 board_config = alc_board_codec_sid_config(codec,
4685 ALC882_MODEL_LAST, alc882_models, alc882_ssid_cfg_tbl);
4687 if (board_config < 0) {
4688 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4690 board_config = ALC_MODEL_AUTO;
4693 if (board_config == ALC_MODEL_AUTO) {
4694 alc_pick_fixup(codec, NULL, alc882_fixup_tbl, alc882_fixups);
4695 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4698 alc_auto_parse_customize_define(codec);
4700 if (board_config == ALC_MODEL_AUTO) {
4701 /* automatic parse from the BIOS config */
4702 err = alc882_parse_auto_config(codec);
4707 if (board_config != ALC_MODEL_AUTO) {
4708 setup_preset(codec, &alc882_presets[board_config]);
4709 spec->vmaster_nid = 0x0c;
4712 if (!spec->no_analog && !spec->adc_nids) {
4713 alc_auto_fill_adc_caps(codec);
4714 alc_rebuild_imux_for_auto_mic(codec);
4715 alc_remove_invalid_adc_nids(codec);
4718 if (!spec->no_analog && !spec->cap_mixer)
4719 set_capture_mixer(codec);
4721 if (!spec->no_analog && has_cdefine_beep(codec)) {
4722 err = snd_hda_attach_beep_device(codec, 0x1);
4725 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4728 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4730 codec->patch_ops = alc_patch_ops;
4731 if (board_config == ALC_MODEL_AUTO)
4732 spec->init_hook = alc_auto_init_std;
4734 alc_init_jacks(codec);
4735 #ifdef CONFIG_SND_HDA_POWER_SAVE
4736 if (!spec->loopback.amplist)
4737 spec->loopback.amplist = alc882_loopbacks;
4751 static int alc262_parse_auto_config(struct hda_codec *codec)
4753 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
4754 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4755 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
4762 ALC262_FIXUP_FSC_H270,
4763 ALC262_FIXUP_HP_Z200,
4765 ALC262_FIXUP_TOSHIBA_RX1,
4766 ALC262_FIXUP_LENOVO_3000,
4768 ALC262_FIXUP_BENQ_T31,
4771 static const struct alc_fixup alc262_fixups[] = {
4772 [ALC262_FIXUP_FSC_H270] = {
4773 .type = ALC_FIXUP_PINS,
4774 .v.pins = (const struct alc_pincfg[]) {
4775 { 0x14, 0x99130110 }, /* speaker */
4776 { 0x15, 0x0221142f }, /* front HP */
4777 { 0x1b, 0x0121141f }, /* rear HP */
4781 [ALC262_FIXUP_HP_Z200] = {
4782 .type = ALC_FIXUP_PINS,
4783 .v.pins = (const struct alc_pincfg[]) {
4784 { 0x16, 0x99130120 }, /* internal speaker */
4788 [ALC262_FIXUP_TYAN] = {
4789 .type = ALC_FIXUP_PINS,
4790 .v.pins = (const struct alc_pincfg[]) {
4791 { 0x14, 0x1993e1f0 }, /* int AUX */
4795 [ALC262_FIXUP_TOSHIBA_RX1] = {
4796 .type = ALC_FIXUP_PINS,
4797 .v.pins = (const struct alc_pincfg[]) {
4798 { 0x14, 0x90170110 }, /* speaker */
4799 { 0x15, 0x0421101f }, /* HP */
4800 { 0x1a, 0x40f000f0 }, /* N/A */
4801 { 0x1b, 0x40f000f0 }, /* N/A */
4802 { 0x1e, 0x40f000f0 }, /* N/A */
4805 [ALC262_FIXUP_LENOVO_3000] = {
4806 .type = ALC_FIXUP_VERBS,
4807 .v.verbs = (const struct hda_verb[]) {
4808 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
4812 .chain_id = ALC262_FIXUP_BENQ,
4814 [ALC262_FIXUP_BENQ] = {
4815 .type = ALC_FIXUP_VERBS,
4816 .v.verbs = (const struct hda_verb[]) {
4817 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4818 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4822 [ALC262_FIXUP_BENQ_T31] = {
4823 .type = ALC_FIXUP_VERBS,
4824 .v.verbs = (const struct hda_verb[]) {
4825 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4826 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4832 static const struct snd_pci_quirk alc262_fixup_tbl[] = {
4833 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
4834 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
4835 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
4836 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
4837 SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1",
4838 ALC262_FIXUP_TOSHIBA_RX1),
4839 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
4840 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
4841 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
4842 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
4847 #ifdef CONFIG_SND_HDA_POWER_SAVE
4848 #define alc262_loopbacks alc880_loopbacks
4853 static int patch_alc262(struct hda_codec *codec)
4855 struct alc_spec *spec;
4858 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4864 spec->mixer_nid = 0x0b;
4867 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
4872 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4873 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
4874 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4875 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
4878 alc_auto_parse_customize_define(codec);
4880 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
4882 alc_pick_fixup(codec, NULL, alc262_fixup_tbl, alc262_fixups);
4883 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4885 /* automatic parse from the BIOS config */
4886 err = alc262_parse_auto_config(codec);
4890 if (!spec->no_analog && !spec->adc_nids) {
4891 alc_auto_fill_adc_caps(codec);
4892 alc_rebuild_imux_for_auto_mic(codec);
4893 alc_remove_invalid_adc_nids(codec);
4896 if (!spec->no_analog && !spec->cap_mixer)
4897 set_capture_mixer(codec);
4899 if (!spec->no_analog && has_cdefine_beep(codec)) {
4900 err = snd_hda_attach_beep_device(codec, 0x1);
4903 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4906 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4908 codec->patch_ops = alc_patch_ops;
4909 spec->init_hook = alc_auto_init_std;
4910 spec->shutup = alc_eapd_shutup;
4912 alc_init_jacks(codec);
4913 #ifdef CONFIG_SND_HDA_POWER_SAVE
4914 if (!spec->loopback.amplist)
4915 spec->loopback.amplist = alc262_loopbacks;
4928 /* bind Beep switches of both NID 0x0f and 0x10 */
4929 static const struct hda_bind_ctls alc268_bind_beep_sw = {
4930 .ops = &snd_hda_bind_sw,
4932 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
4933 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
4938 static const struct snd_kcontrol_new alc268_beep_mixer[] = {
4939 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
4940 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
4944 /* set PCBEEP vol = 0, mute connections */
4945 static const struct hda_verb alc268_beep_init_verbs[] = {
4946 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4947 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4948 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4953 * BIOS auto configuration
4955 static int alc268_parse_auto_config(struct hda_codec *codec)
4957 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4958 struct alc_spec *spec = codec->spec;
4959 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
4961 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
4962 add_mixer(spec, alc268_beep_mixer);
4963 add_verb(spec, alc268_beep_init_verbs);
4971 static int patch_alc268(struct hda_codec *codec)
4973 struct alc_spec *spec;
4974 int i, has_beep, err;
4976 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4982 /* ALC268 has no aa-loopback mixer */
4984 /* automatic parse from the BIOS config */
4985 err = alc268_parse_auto_config(codec);
4990 for (i = 0; i < spec->num_mixers; i++) {
4991 if (spec->mixers[i] == alc268_beep_mixer) {
4998 err = snd_hda_attach_beep_device(codec, 0x1);
5001 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
5002 /* override the amp caps for beep generator */
5003 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
5004 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
5005 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
5006 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5007 (0 << AC_AMPCAP_MUTE_SHIFT));
5010 if (!spec->no_analog && !spec->adc_nids) {
5011 alc_auto_fill_adc_caps(codec);
5012 alc_rebuild_imux_for_auto_mic(codec);
5013 alc_remove_invalid_adc_nids(codec);
5016 if (!spec->no_analog && !spec->cap_mixer)
5017 set_capture_mixer(codec);
5019 codec->patch_ops = alc_patch_ops;
5020 spec->init_hook = alc_auto_init_std;
5021 spec->shutup = alc_eapd_shutup;
5023 alc_init_jacks(codec);
5035 #ifdef CONFIG_SND_HDA_POWER_SAVE
5036 #define alc269_loopbacks alc880_loopbacks
5039 static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
5043 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5044 /* NID is set in alc_build_pcms */
5046 .open = alc_playback_pcm_open,
5047 .prepare = alc_playback_pcm_prepare,
5048 .cleanup = alc_playback_pcm_cleanup
5052 static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
5056 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5057 /* NID is set in alc_build_pcms */
5060 #ifdef CONFIG_SND_HDA_POWER_SAVE
5061 static int alc269_mic2_for_mute_led(struct hda_codec *codec)
5063 switch (codec->subsystem_id) {
5070 static int alc269_mic2_mute_check_ps(struct hda_codec *codec, hda_nid_t nid)
5072 /* update mute-LED according to the speaker mute state */
5073 if (nid == 0x01 || nid == 0x14) {
5075 if (snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0) &
5080 /* mic2 vref pin is used for mute LED control */
5081 snd_hda_codec_update_cache(codec, 0x19, 0,
5082 AC_VERB_SET_PIN_WIDGET_CONTROL,
5085 return alc_check_power_status(codec, nid);
5087 #endif /* CONFIG_SND_HDA_POWER_SAVE */
5089 /* different alc269-variants */
5091 ALC269_TYPE_ALC269VA,
5092 ALC269_TYPE_ALC269VB,
5093 ALC269_TYPE_ALC269VC,
5097 * BIOS auto configuration
5099 static int alc269_parse_auto_config(struct hda_codec *codec)
5101 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
5102 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
5103 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5104 struct alc_spec *spec = codec->spec;
5105 const hda_nid_t *ssids = spec->codec_variant == ALC269_TYPE_ALC269VA ?
5106 alc269va_ssids : alc269_ssids;
5108 return alc_parse_auto_config(codec, alc269_ignore, ssids);
5111 static void alc269_toggle_power_output(struct hda_codec *codec, int power_up)
5113 int val = alc_read_coef_idx(codec, 0x04);
5118 alc_write_coef_idx(codec, 0x04, val);
5121 static void alc269_shutup(struct hda_codec *codec)
5123 if ((alc_get_coef0(codec) & 0x00ff) == 0x017)
5124 alc269_toggle_power_output(codec, 0);
5125 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
5126 alc269_toggle_power_output(codec, 0);
5132 static int alc269_resume(struct hda_codec *codec)
5134 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
5135 alc269_toggle_power_output(codec, 0);
5139 codec->patch_ops.init(codec);
5141 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
5142 alc269_toggle_power_output(codec, 1);
5146 if ((alc_get_coef0(codec) & 0x00ff) == 0x018)
5147 alc269_toggle_power_output(codec, 1);
5149 snd_hda_codec_resume_amp(codec);
5150 snd_hda_codec_resume_cache(codec);
5151 hda_call_check_power_status(codec, 0x01);
5154 #endif /* CONFIG_PM */
5156 static void alc269_fixup_hweq(struct hda_codec *codec,
5157 const struct alc_fixup *fix, int action)
5161 if (action != ALC_FIXUP_ACT_INIT)
5163 coef = alc_read_coef_idx(codec, 0x1e);
5164 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
5167 static void alc271_fixup_dmic(struct hda_codec *codec,
5168 const struct alc_fixup *fix, int action)
5170 static const struct hda_verb verbs[] = {
5171 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
5172 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
5177 if (strcmp(codec->chip_name, "ALC271X"))
5179 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
5180 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
5181 snd_hda_sequence_write(codec, verbs);
5184 static void alc269_fixup_pcm_44k(struct hda_codec *codec,
5185 const struct alc_fixup *fix, int action)
5187 struct alc_spec *spec = codec->spec;
5189 if (action != ALC_FIXUP_ACT_PROBE)
5192 /* Due to a hardware problem on Lenovo Ideadpad, we need to
5193 * fix the sample rate of analog I/O to 44.1kHz
5195 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
5196 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
5199 static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
5200 const struct alc_fixup *fix, int action)
5204 if (action != ALC_FIXUP_ACT_INIT)
5206 /* The digital-mic unit sends PDM (differential signal) instead of
5207 * the standard PCM, thus you can't record a valid mono stream as is.
5208 * Below is a workaround specific to ALC269 to control the dmic
5209 * signal source as mono.
5211 coef = alc_read_coef_idx(codec, 0x07);
5212 alc_write_coef_idx(codec, 0x07, coef | 0x80);
5215 static void alc269_quanta_automute(struct hda_codec *codec)
5217 update_outputs(codec);
5219 snd_hda_codec_write(codec, 0x20, 0,
5220 AC_VERB_SET_COEF_INDEX, 0x0c);
5221 snd_hda_codec_write(codec, 0x20, 0,
5222 AC_VERB_SET_PROC_COEF, 0x680);
5224 snd_hda_codec_write(codec, 0x20, 0,
5225 AC_VERB_SET_COEF_INDEX, 0x0c);
5226 snd_hda_codec_write(codec, 0x20, 0,
5227 AC_VERB_SET_PROC_COEF, 0x480);
5230 static void alc269_fixup_quanta_mute(struct hda_codec *codec,
5231 const struct alc_fixup *fix, int action)
5233 struct alc_spec *spec = codec->spec;
5234 if (action != ALC_FIXUP_ACT_PROBE)
5236 spec->automute_hook = alc269_quanta_automute;
5240 ALC269_FIXUP_SONY_VAIO,
5241 ALC275_FIXUP_SONY_VAIO_GPIO2,
5242 ALC269_FIXUP_DELL_M101Z,
5243 ALC269_FIXUP_SKU_IGNORE,
5244 ALC269_FIXUP_ASUS_G73JW,
5245 ALC269_FIXUP_LENOVO_EAPD,
5246 ALC275_FIXUP_SONY_HWEQ,
5248 ALC269_FIXUP_PCM_44K,
5249 ALC269_FIXUP_STEREO_DMIC,
5250 ALC269_FIXUP_QUANTA_MUTE,
5251 ALC269_FIXUP_LIFEBOOK,
5254 ALC269VB_FIXUP_AMIC,
5255 ALC269VB_FIXUP_DMIC,
5258 static const struct alc_fixup alc269_fixups[] = {
5259 [ALC269_FIXUP_SONY_VAIO] = {
5260 .type = ALC_FIXUP_VERBS,
5261 .v.verbs = (const struct hda_verb[]) {
5262 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
5266 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
5267 .type = ALC_FIXUP_VERBS,
5268 .v.verbs = (const struct hda_verb[]) {
5269 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
5270 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
5271 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5275 .chain_id = ALC269_FIXUP_SONY_VAIO
5277 [ALC269_FIXUP_DELL_M101Z] = {
5278 .type = ALC_FIXUP_VERBS,
5279 .v.verbs = (const struct hda_verb[]) {
5280 /* Enables internal speaker */
5281 {0x20, AC_VERB_SET_COEF_INDEX, 13},
5282 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
5286 [ALC269_FIXUP_SKU_IGNORE] = {
5287 .type = ALC_FIXUP_SKU,
5288 .v.sku = ALC_FIXUP_SKU_IGNORE,
5290 [ALC269_FIXUP_ASUS_G73JW] = {
5291 .type = ALC_FIXUP_PINS,
5292 .v.pins = (const struct alc_pincfg[]) {
5293 { 0x17, 0x99130111 }, /* subwoofer */
5297 [ALC269_FIXUP_LENOVO_EAPD] = {
5298 .type = ALC_FIXUP_VERBS,
5299 .v.verbs = (const struct hda_verb[]) {
5300 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
5304 [ALC275_FIXUP_SONY_HWEQ] = {
5305 .type = ALC_FIXUP_FUNC,
5306 .v.func = alc269_fixup_hweq,
5308 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
5310 [ALC271_FIXUP_DMIC] = {
5311 .type = ALC_FIXUP_FUNC,
5312 .v.func = alc271_fixup_dmic,
5314 [ALC269_FIXUP_PCM_44K] = {
5315 .type = ALC_FIXUP_FUNC,
5316 .v.func = alc269_fixup_pcm_44k,
5318 [ALC269_FIXUP_STEREO_DMIC] = {
5319 .type = ALC_FIXUP_FUNC,
5320 .v.func = alc269_fixup_stereo_dmic,
5322 [ALC269_FIXUP_QUANTA_MUTE] = {
5323 .type = ALC_FIXUP_FUNC,
5324 .v.func = alc269_fixup_quanta_mute,
5326 [ALC269_FIXUP_LIFEBOOK] = {
5327 .type = ALC_FIXUP_PINS,
5328 .v.pins = (const struct alc_pincfg[]) {
5329 { 0x1a, 0x2101103f }, /* dock line-out */
5330 { 0x1b, 0x23a11040 }, /* dock mic-in */
5334 .chain_id = ALC269_FIXUP_QUANTA_MUTE
5336 [ALC269_FIXUP_AMIC] = {
5337 .type = ALC_FIXUP_PINS,
5338 .v.pins = (const struct alc_pincfg[]) {
5339 { 0x14, 0x99130110 }, /* speaker */
5340 { 0x15, 0x0121401f }, /* HP out */
5341 { 0x18, 0x01a19c20 }, /* mic */
5342 { 0x19, 0x99a3092f }, /* int-mic */
5346 [ALC269_FIXUP_DMIC] = {
5347 .type = ALC_FIXUP_PINS,
5348 .v.pins = (const struct alc_pincfg[]) {
5349 { 0x12, 0x99a3092f }, /* int-mic */
5350 { 0x14, 0x99130110 }, /* speaker */
5351 { 0x15, 0x0121401f }, /* HP out */
5352 { 0x18, 0x01a19c20 }, /* mic */
5356 [ALC269VB_FIXUP_AMIC] = {
5357 .type = ALC_FIXUP_PINS,
5358 .v.pins = (const struct alc_pincfg[]) {
5359 { 0x14, 0x99130110 }, /* speaker */
5360 { 0x18, 0x01a19c20 }, /* mic */
5361 { 0x19, 0x99a3092f }, /* int-mic */
5362 { 0x21, 0x0121401f }, /* HP out */
5366 [ALC269_FIXUP_DMIC] = {
5367 .type = ALC_FIXUP_PINS,
5368 .v.pins = (const struct alc_pincfg[]) {
5369 { 0x12, 0x99a3092f }, /* int-mic */
5370 { 0x14, 0x99130110 }, /* speaker */
5371 { 0x18, 0x01a19c20 }, /* mic */
5372 { 0x21, 0x0121401f }, /* HP out */
5378 static const struct snd_pci_quirk alc269_fixup_tbl[] = {
5379 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
5380 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
5381 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
5382 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
5383 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
5384 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
5385 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
5386 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
5387 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
5388 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
5389 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
5390 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
5391 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
5392 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
5393 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
5394 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
5395 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
5396 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
5397 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_QUANTA_MUTE),
5398 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K),
5399 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
5402 /* Below is a quirk table taken from the old code.
5403 * Basically the device should work as is without the fixup table.
5404 * If BIOS doesn't give a proper info, enable the corresponding
5407 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
5409 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
5410 SND_PCI_QUIRK(0x1043, 0x1113, "ASUS N63Jn", ALC269_FIXUP_AMIC),
5411 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
5412 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
5413 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
5414 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
5415 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
5416 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
5417 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
5418 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
5419 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
5420 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
5421 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
5422 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
5423 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
5424 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
5425 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
5426 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
5427 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
5428 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
5429 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
5430 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
5431 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
5432 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
5433 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
5434 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
5435 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
5436 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
5437 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
5438 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
5439 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
5440 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
5441 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
5442 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
5443 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
5444 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
5445 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
5446 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
5447 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
5448 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
5453 static const struct alc_model_fixup alc269_fixup_models[] = {
5454 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
5455 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
5460 static int alc269_fill_coef(struct hda_codec *codec)
5464 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
5465 alc_write_coef_idx(codec, 0xf, 0x960b);
5466 alc_write_coef_idx(codec, 0xe, 0x8817);
5469 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
5470 alc_write_coef_idx(codec, 0xf, 0x960b);
5471 alc_write_coef_idx(codec, 0xe, 0x8814);
5474 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
5475 val = alc_read_coef_idx(codec, 0x04);
5476 /* Power up output pin */
5477 alc_write_coef_idx(codec, 0x04, val | (1<<11));
5480 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
5481 val = alc_read_coef_idx(codec, 0xd);
5482 if ((val & 0x0c00) >> 10 != 0x1) {
5483 /* Capless ramp up clock control */
5484 alc_write_coef_idx(codec, 0xd, val | (1<<10));
5486 val = alc_read_coef_idx(codec, 0x17);
5487 if ((val & 0x01c0) >> 6 != 0x4) {
5488 /* Class D power on reset */
5489 alc_write_coef_idx(codec, 0x17, val | (1<<7));
5493 val = alc_read_coef_idx(codec, 0xd); /* Class D */
5494 alc_write_coef_idx(codec, 0xd, val | (1<<14));
5496 val = alc_read_coef_idx(codec, 0x4); /* HP */
5497 alc_write_coef_idx(codec, 0x4, val | (1<<11));
5504 static int patch_alc269(struct hda_codec *codec)
5506 struct alc_spec *spec;
5509 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5515 spec->mixer_nid = 0x0b;
5517 alc_auto_parse_customize_define(codec);
5519 err = alc_codec_rename_from_preset(codec);
5523 if (codec->vendor_id == 0x10ec0269) {
5524 spec->codec_variant = ALC269_TYPE_ALC269VA;
5525 switch (alc_get_coef0(codec) & 0x00f0) {
5527 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
5528 spec->cdefine.platform_type == 1)
5529 err = alc_codec_rename(codec, "ALC271X");
5530 spec->codec_variant = ALC269_TYPE_ALC269VB;
5533 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
5534 codec->bus->pci->subsystem_device == 0x21f3)
5535 err = alc_codec_rename(codec, "ALC3202");
5536 spec->codec_variant = ALC269_TYPE_ALC269VC;
5539 alc_fix_pll_init(codec, 0x20, 0x04, 15);
5543 alc269_fill_coef(codec);
5546 alc_pick_fixup(codec, alc269_fixup_models,
5547 alc269_fixup_tbl, alc269_fixups);
5548 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5550 /* automatic parse from the BIOS config */
5551 err = alc269_parse_auto_config(codec);
5555 if (!spec->no_analog && !spec->adc_nids) {
5556 alc_auto_fill_adc_caps(codec);
5557 alc_rebuild_imux_for_auto_mic(codec);
5558 alc_remove_invalid_adc_nids(codec);
5561 if (!spec->no_analog && !spec->cap_mixer)
5562 set_capture_mixer(codec);
5564 if (!spec->no_analog && has_cdefine_beep(codec)) {
5565 err = snd_hda_attach_beep_device(codec, 0x1);
5568 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
5571 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5573 codec->patch_ops = alc_patch_ops;
5575 codec->patch_ops.resume = alc269_resume;
5577 spec->init_hook = alc_auto_init_std;
5578 spec->shutup = alc269_shutup;
5580 alc_init_jacks(codec);
5581 #ifdef CONFIG_SND_HDA_POWER_SAVE
5582 if (!spec->loopback.amplist)
5583 spec->loopback.amplist = alc269_loopbacks;
5584 if (alc269_mic2_for_mute_led(codec))
5585 codec->patch_ops.check_power_status = alc269_mic2_mute_check_ps;
5599 static int alc861_parse_auto_config(struct hda_codec *codec)
5601 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
5602 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
5603 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
5606 #ifdef CONFIG_SND_HDA_POWER_SAVE
5607 static const struct hda_amp_list alc861_loopbacks[] = {
5608 { 0x15, HDA_INPUT, 0 },
5609 { 0x15, HDA_INPUT, 1 },
5610 { 0x15, HDA_INPUT, 2 },
5611 { 0x15, HDA_INPUT, 3 },
5617 /* Pin config fixes */
5619 PINFIX_FSC_AMILO_PI1505,
5622 static const struct alc_fixup alc861_fixups[] = {
5623 [PINFIX_FSC_AMILO_PI1505] = {
5624 .type = ALC_FIXUP_PINS,
5625 .v.pins = (const struct alc_pincfg[]) {
5626 { 0x0b, 0x0221101f }, /* HP */
5627 { 0x0f, 0x90170310 }, /* speaker */
5633 static const struct snd_pci_quirk alc861_fixup_tbl[] = {
5634 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", PINFIX_FSC_AMILO_PI1505),
5640 static int patch_alc861(struct hda_codec *codec)
5642 struct alc_spec *spec;
5645 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5651 spec->mixer_nid = 0x15;
5653 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
5654 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5656 /* automatic parse from the BIOS config */
5657 err = alc861_parse_auto_config(codec);
5661 if (!spec->no_analog && !spec->adc_nids) {
5662 alc_auto_fill_adc_caps(codec);
5663 alc_rebuild_imux_for_auto_mic(codec);
5664 alc_remove_invalid_adc_nids(codec);
5667 if (!spec->no_analog && !spec->cap_mixer)
5668 set_capture_mixer(codec);
5670 if (!spec->no_analog) {
5671 err = snd_hda_attach_beep_device(codec, 0x23);
5674 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
5677 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5679 codec->patch_ops = alc_patch_ops;
5680 spec->init_hook = alc_auto_init_std;
5681 #ifdef CONFIG_SND_HDA_POWER_SAVE
5682 spec->power_hook = alc_power_eapd;
5683 if (!spec->loopback.amplist)
5684 spec->loopback.amplist = alc861_loopbacks;
5699 * In addition, an independent DAC
5701 #ifdef CONFIG_SND_HDA_POWER_SAVE
5702 #define alc861vd_loopbacks alc880_loopbacks
5705 static int alc861vd_parse_auto_config(struct hda_codec *codec)
5707 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
5708 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5709 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
5713 ALC660VD_FIX_ASUS_GPIO1,
5714 ALC861VD_FIX_DALLAS,
5717 /* exclude VREF80 */
5718 static void alc861vd_fixup_dallas(struct hda_codec *codec,
5719 const struct alc_fixup *fix, int action)
5721 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
5722 snd_hda_override_pin_caps(codec, 0x18, 0x00001714);
5723 snd_hda_override_pin_caps(codec, 0x19, 0x0000171c);
5727 static const struct alc_fixup alc861vd_fixups[] = {
5728 [ALC660VD_FIX_ASUS_GPIO1] = {
5729 .type = ALC_FIXUP_VERBS,
5730 .v.verbs = (const struct hda_verb[]) {
5732 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
5733 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5734 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5738 [ALC861VD_FIX_DALLAS] = {
5739 .type = ALC_FIXUP_FUNC,
5740 .v.func = alc861vd_fixup_dallas,
5744 static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
5745 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
5746 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
5747 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
5751 static const struct hda_verb alc660vd_eapd_verbs[] = {
5752 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
5753 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
5759 static int patch_alc861vd(struct hda_codec *codec)
5761 struct alc_spec *spec;
5764 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5770 spec->mixer_nid = 0x0b;
5772 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
5773 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5775 /* automatic parse from the BIOS config */
5776 err = alc861vd_parse_auto_config(codec);
5780 if (codec->vendor_id == 0x10ec0660) {
5781 /* always turn on EAPD */
5782 add_verb(spec, alc660vd_eapd_verbs);
5785 if (!spec->no_analog && !spec->adc_nids) {
5786 alc_auto_fill_adc_caps(codec);
5787 alc_rebuild_imux_for_auto_mic(codec);
5788 alc_remove_invalid_adc_nids(codec);
5791 if (!spec->no_analog && !spec->cap_mixer)
5792 set_capture_mixer(codec);
5794 if (!spec->no_analog) {
5795 err = snd_hda_attach_beep_device(codec, 0x23);
5798 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5801 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5803 codec->patch_ops = alc_patch_ops;
5805 spec->init_hook = alc_auto_init_std;
5806 spec->shutup = alc_eapd_shutup;
5807 #ifdef CONFIG_SND_HDA_POWER_SAVE
5808 if (!spec->loopback.amplist)
5809 spec->loopback.amplist = alc861vd_loopbacks;
5822 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
5823 * configuration. Each pin widget can choose any input DACs and a mixer.
5824 * Each ADC is connected from a mixer of all inputs. This makes possible
5825 * 6-channel independent captures.
5827 * In addition, an independent DAC for the multi-playback (not used in this
5830 #ifdef CONFIG_SND_HDA_POWER_SAVE
5831 #define alc662_loopbacks alc880_loopbacks
5835 * BIOS auto configuration
5838 static int alc662_parse_auto_config(struct hda_codec *codec)
5840 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
5841 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
5842 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5843 const hda_nid_t *ssids;
5845 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
5846 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
5847 ssids = alc663_ssids;
5849 ssids = alc662_ssids;
5850 return alc_parse_auto_config(codec, alc662_ignore, ssids);
5853 static void alc272_fixup_mario(struct hda_codec *codec,
5854 const struct alc_fixup *fix, int action)
5856 if (action != ALC_FIXUP_ACT_PROBE)
5858 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
5859 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
5860 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
5861 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5862 (0 << AC_AMPCAP_MUTE_SHIFT)))
5864 "hda_codec: failed to override amp caps for NID 0x2\n");
5868 ALC662_FIXUP_ASPIRE,
5869 ALC662_FIXUP_IDEAPAD,
5871 ALC662_FIXUP_CZC_P10T,
5872 ALC662_FIXUP_SKU_IGNORE,
5873 ALC662_FIXUP_HP_RP5800,
5874 ALC662_FIXUP_ASUS_MODE1,
5875 ALC662_FIXUP_ASUS_MODE2,
5876 ALC662_FIXUP_ASUS_MODE3,
5877 ALC662_FIXUP_ASUS_MODE4,
5878 ALC662_FIXUP_ASUS_MODE5,
5879 ALC662_FIXUP_ASUS_MODE6,
5880 ALC662_FIXUP_ASUS_MODE7,
5881 ALC662_FIXUP_ASUS_MODE8,
5884 static const struct alc_fixup alc662_fixups[] = {
5885 [ALC662_FIXUP_ASPIRE] = {
5886 .type = ALC_FIXUP_PINS,
5887 .v.pins = (const struct alc_pincfg[]) {
5888 { 0x15, 0x99130112 }, /* subwoofer */
5892 [ALC662_FIXUP_IDEAPAD] = {
5893 .type = ALC_FIXUP_PINS,
5894 .v.pins = (const struct alc_pincfg[]) {
5895 { 0x17, 0x99130112 }, /* subwoofer */
5899 [ALC272_FIXUP_MARIO] = {
5900 .type = ALC_FIXUP_FUNC,
5901 .v.func = alc272_fixup_mario,
5903 [ALC662_FIXUP_CZC_P10T] = {
5904 .type = ALC_FIXUP_VERBS,
5905 .v.verbs = (const struct hda_verb[]) {
5906 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
5910 [ALC662_FIXUP_SKU_IGNORE] = {
5911 .type = ALC_FIXUP_SKU,
5912 .v.sku = ALC_FIXUP_SKU_IGNORE,
5914 [ALC662_FIXUP_HP_RP5800] = {
5915 .type = ALC_FIXUP_PINS,
5916 .v.pins = (const struct alc_pincfg[]) {
5917 { 0x14, 0x0221201f }, /* HP out */
5921 .chain_id = ALC662_FIXUP_SKU_IGNORE
5923 [ALC662_FIXUP_ASUS_MODE1] = {
5924 .type = ALC_FIXUP_PINS,
5925 .v.pins = (const struct alc_pincfg[]) {
5926 { 0x14, 0x99130110 }, /* speaker */
5927 { 0x18, 0x01a19c20 }, /* mic */
5928 { 0x19, 0x99a3092f }, /* int-mic */
5929 { 0x21, 0x0121401f }, /* HP out */
5933 .chain_id = ALC662_FIXUP_SKU_IGNORE
5935 [ALC662_FIXUP_ASUS_MODE2] = {
5936 .type = ALC_FIXUP_PINS,
5937 .v.pins = (const struct alc_pincfg[]) {
5938 { 0x14, 0x99130110 }, /* speaker */
5939 { 0x18, 0x01a19820 }, /* mic */
5940 { 0x19, 0x99a3092f }, /* int-mic */
5941 { 0x1b, 0x0121401f }, /* HP out */
5945 .chain_id = ALC662_FIXUP_SKU_IGNORE
5947 [ALC662_FIXUP_ASUS_MODE3] = {
5948 .type = ALC_FIXUP_PINS,
5949 .v.pins = (const struct alc_pincfg[]) {
5950 { 0x14, 0x99130110 }, /* speaker */
5951 { 0x15, 0x0121441f }, /* HP */
5952 { 0x18, 0x01a19840 }, /* mic */
5953 { 0x19, 0x99a3094f }, /* int-mic */
5954 { 0x21, 0x01211420 }, /* HP2 */
5958 .chain_id = ALC662_FIXUP_SKU_IGNORE
5960 [ALC662_FIXUP_ASUS_MODE4] = {
5961 .type = ALC_FIXUP_PINS,
5962 .v.pins = (const struct alc_pincfg[]) {
5963 { 0x14, 0x99130110 }, /* speaker */
5964 { 0x16, 0x99130111 }, /* speaker */
5965 { 0x18, 0x01a19840 }, /* mic */
5966 { 0x19, 0x99a3094f }, /* int-mic */
5967 { 0x21, 0x0121441f }, /* HP */
5971 .chain_id = ALC662_FIXUP_SKU_IGNORE
5973 [ALC662_FIXUP_ASUS_MODE5] = {
5974 .type = ALC_FIXUP_PINS,
5975 .v.pins = (const struct alc_pincfg[]) {
5976 { 0x14, 0x99130110 }, /* speaker */
5977 { 0x15, 0x0121441f }, /* HP */
5978 { 0x16, 0x99130111 }, /* speaker */
5979 { 0x18, 0x01a19840 }, /* mic */
5980 { 0x19, 0x99a3094f }, /* int-mic */
5984 .chain_id = ALC662_FIXUP_SKU_IGNORE
5986 [ALC662_FIXUP_ASUS_MODE6] = {
5987 .type = ALC_FIXUP_PINS,
5988 .v.pins = (const struct alc_pincfg[]) {
5989 { 0x14, 0x99130110 }, /* speaker */
5990 { 0x15, 0x01211420 }, /* HP2 */
5991 { 0x18, 0x01a19840 }, /* mic */
5992 { 0x19, 0x99a3094f }, /* int-mic */
5993 { 0x1b, 0x0121441f }, /* HP */
5997 .chain_id = ALC662_FIXUP_SKU_IGNORE
5999 [ALC662_FIXUP_ASUS_MODE7] = {
6000 .type = ALC_FIXUP_PINS,
6001 .v.pins = (const struct alc_pincfg[]) {
6002 { 0x14, 0x99130110 }, /* speaker */
6003 { 0x17, 0x99130111 }, /* speaker */
6004 { 0x18, 0x01a19840 }, /* mic */
6005 { 0x19, 0x99a3094f }, /* int-mic */
6006 { 0x1b, 0x01214020 }, /* HP */
6007 { 0x21, 0x0121401f }, /* HP */
6011 .chain_id = ALC662_FIXUP_SKU_IGNORE
6013 [ALC662_FIXUP_ASUS_MODE8] = {
6014 .type = ALC_FIXUP_PINS,
6015 .v.pins = (const struct alc_pincfg[]) {
6016 { 0x14, 0x99130110 }, /* speaker */
6017 { 0x12, 0x99a30970 }, /* int-mic */
6018 { 0x15, 0x01214020 }, /* HP */
6019 { 0x17, 0x99130111 }, /* speaker */
6020 { 0x18, 0x01a19840 }, /* mic */
6021 { 0x21, 0x0121401f }, /* HP */
6025 .chain_id = ALC662_FIXUP_SKU_IGNORE
6029 static const struct snd_pci_quirk alc662_fixup_tbl[] = {
6030 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
6031 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
6032 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
6033 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
6034 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
6035 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
6036 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
6037 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
6038 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
6039 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
6042 /* Below is a quirk table taken from the old code.
6043 * Basically the device should work as is without the fixup table.
6044 * If BIOS doesn't give a proper info, enable the corresponding
6047 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
6048 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
6049 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
6050 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
6051 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6052 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6053 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6054 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
6055 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
6056 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6057 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
6058 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
6059 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
6060 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
6061 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
6062 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6063 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
6064 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
6065 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6066 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6067 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6068 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6069 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
6070 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
6071 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
6072 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6073 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
6074 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6075 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6076 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
6077 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6078 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6079 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
6080 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
6081 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
6082 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
6083 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
6084 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
6085 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
6086 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6087 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
6088 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
6089 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6090 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
6091 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
6092 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
6093 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
6094 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
6095 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6096 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
6101 static const struct alc_model_fixup alc662_fixup_models[] = {
6102 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
6103 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
6104 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
6105 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
6106 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
6107 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
6108 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
6109 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
6110 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
6117 static int patch_alc662(struct hda_codec *codec)
6119 struct alc_spec *spec;
6122 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6128 spec->mixer_nid = 0x0b;
6130 /* handle multiple HPs as is */
6131 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
6133 alc_auto_parse_customize_define(codec);
6135 alc_fix_pll_init(codec, 0x20, 0x04, 15);
6137 err = alc_codec_rename_from_preset(codec);
6141 if ((alc_get_coef0(codec) & (1 << 14)) &&
6142 codec->bus->pci->subsystem_vendor == 0x1025 &&
6143 spec->cdefine.platform_type == 1) {
6144 if (alc_codec_rename(codec, "ALC272X") < 0)
6148 alc_pick_fixup(codec, alc662_fixup_models,
6149 alc662_fixup_tbl, alc662_fixups);
6150 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6151 /* automatic parse from the BIOS config */
6152 err = alc662_parse_auto_config(codec);
6156 if (!spec->no_analog && !spec->adc_nids) {
6157 alc_auto_fill_adc_caps(codec);
6158 alc_rebuild_imux_for_auto_mic(codec);
6159 alc_remove_invalid_adc_nids(codec);
6162 if (!spec->no_analog && !spec->cap_mixer)
6163 set_capture_mixer(codec);
6165 if (!spec->no_analog && has_cdefine_beep(codec)) {
6166 err = snd_hda_attach_beep_device(codec, 0x1);
6169 switch (codec->vendor_id) {
6171 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6176 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
6179 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
6184 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6186 codec->patch_ops = alc_patch_ops;
6187 spec->init_hook = alc_auto_init_std;
6188 spec->shutup = alc_eapd_shutup;
6190 alc_init_jacks(codec);
6192 #ifdef CONFIG_SND_HDA_POWER_SAVE
6193 if (!spec->loopback.amplist)
6194 spec->loopback.amplist = alc662_loopbacks;
6208 static int alc680_parse_auto_config(struct hda_codec *codec)
6210 return alc_parse_auto_config(codec, NULL, NULL);
6215 static int patch_alc680(struct hda_codec *codec)
6217 struct alc_spec *spec;
6220 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6226 /* ALC680 has no aa-loopback mixer */
6228 /* automatic parse from the BIOS config */
6229 err = alc680_parse_auto_config(codec);
6235 if (!spec->no_analog && !spec->cap_mixer)
6236 set_capture_mixer(codec);
6238 codec->patch_ops = alc_patch_ops;
6239 spec->init_hook = alc_auto_init_std;
6247 static const struct hda_codec_preset snd_hda_preset_realtek[] = {
6248 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
6249 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
6250 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
6251 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
6252 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
6253 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
6254 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
6255 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
6256 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
6257 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
6258 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
6259 .patch = patch_alc861 },
6260 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
6261 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
6262 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
6263 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
6264 .patch = patch_alc882 },
6265 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
6266 .patch = patch_alc662 },
6267 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
6268 .patch = patch_alc662 },
6269 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
6270 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
6271 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
6272 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
6273 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
6274 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
6275 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
6276 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
6277 .patch = patch_alc882 },
6278 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
6279 .patch = patch_alc882 },
6280 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
6281 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
6282 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
6283 .patch = patch_alc882 },
6284 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
6285 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
6286 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
6287 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
6291 MODULE_ALIAS("snd-hda-codec-id:10ec*");
6293 MODULE_LICENSE("GPL");
6294 MODULE_DESCRIPTION("Realtek HD-audio codec");
6296 static struct hda_codec_preset_list realtek_list = {
6297 .preset = snd_hda_preset_realtek,
6298 .owner = THIS_MODULE,
6301 static int __init patch_realtek_init(void)
6303 return snd_hda_add_codec_preset(&realtek_list);
6306 static void __exit patch_realtek_exit(void)
6308 snd_hda_delete_codec_preset(&realtek_list);
6311 module_init(patch_realtek_init)
6312 module_exit(patch_realtek_exit)