2 * Universal Interface for Intel High Definition Audio Codec
4 * HD audio interface patch for Realtek ALC codecs
6 * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
7 * PeiSen Hou <pshou@realtek.com.tw>
8 * Takashi Iwai <tiwai@suse.de>
9 * Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
11 * This driver is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This driver is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include <linux/init.h>
27 #include <linux/delay.h>
28 #include <linux/slab.h>
29 #include <linux/pci.h>
30 #include <linux/module.h>
31 #include <sound/core.h>
32 #include <sound/jack.h>
33 #include "hda_codec.h"
34 #include "hda_local.h"
38 /* unsol event tags */
39 #define ALC_FRONT_EVENT 0x01
40 #define ALC_DCVOL_EVENT 0x02
41 #define ALC_HP_EVENT 0x04
42 #define ALC_MIC_EVENT 0x08
45 #define GPIO_MASK 0x03
47 /* extra amp-initialization sequence types */
56 struct alc_customize_define {
58 unsigned char port_connectivity;
59 unsigned char check_sum;
60 unsigned char customization;
61 unsigned char external_amp;
62 unsigned int enable_pcbeep:1;
63 unsigned int platform_type:1;
65 unsigned int override:1;
66 unsigned int fixup:1; /* Means that this sku is set by driver, not read from hw */
72 hda_nid_t pin; /* multi-io widget pin NID */
73 hda_nid_t dac; /* DAC to be connected */
74 unsigned int ctl_in; /* cached input-pin control value */
78 ALC_AUTOMUTE_PIN, /* change the pin control */
79 ALC_AUTOMUTE_AMP, /* mute/unmute the pin AMP */
80 ALC_AUTOMUTE_MIXER, /* mute/unmute mixer widget AMP */
84 /* codec parameterization */
85 const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */
86 unsigned int num_mixers;
87 const struct snd_kcontrol_new *cap_mixer; /* capture mixer */
88 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
90 const struct hda_verb *init_verbs[10]; /* initialization verbs
94 unsigned int num_init_verbs;
96 char stream_name_analog[32]; /* analog PCM stream */
97 const struct hda_pcm_stream *stream_analog_playback;
98 const struct hda_pcm_stream *stream_analog_capture;
99 const struct hda_pcm_stream *stream_analog_alt_playback;
100 const struct hda_pcm_stream *stream_analog_alt_capture;
102 char stream_name_digital[32]; /* digital PCM stream */
103 const struct hda_pcm_stream *stream_digital_playback;
104 const struct hda_pcm_stream *stream_digital_capture;
107 struct hda_multi_out multiout; /* playback set-up
108 * max_channels, dacs must be set
109 * dig_out_nid and hp_nid are optional
111 hda_nid_t alt_dac_nid;
112 hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */
116 unsigned int num_adc_nids;
117 const hda_nid_t *adc_nids;
118 const hda_nid_t *capsrc_nids;
119 hda_nid_t dig_in_nid; /* digital-in NID; optional */
120 hda_nid_t mixer_nid; /* analog-mixer NID */
121 DECLARE_BITMAP(vol_ctls, 0x20 << 1);
122 DECLARE_BITMAP(sw_ctls, 0x20 << 1);
124 /* capture setup for dynamic dual-adc switch */
126 unsigned int cur_adc_stream_tag;
127 unsigned int cur_adc_format;
130 unsigned int num_mux_defs;
131 const struct hda_input_mux *input_mux;
132 unsigned int cur_mux[3];
133 hda_nid_t ext_mic_pin;
134 hda_nid_t dock_mic_pin;
135 hda_nid_t int_mic_pin;
138 const struct hda_channel_mode *channel_mode;
139 int num_channel_mode;
141 int const_channel_count;
142 int ext_channel_count;
144 /* PCM information */
145 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
147 /* dynamic controls, init_verbs and input_mux */
148 struct auto_pin_cfg autocfg;
149 struct alc_customize_define cdefine;
150 struct snd_array kctls;
151 struct hda_input_mux private_imux[3];
152 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
153 hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS];
154 hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS];
155 hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS];
156 unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS];
157 int int_mic_idx, ext_mic_idx, dock_mic_idx; /* for auto-mic */
160 void (*init_hook)(struct hda_codec *codec);
161 void (*unsol_event)(struct hda_codec *codec, unsigned int res);
162 #ifdef CONFIG_SND_HDA_POWER_SAVE
163 void (*power_hook)(struct hda_codec *codec);
165 void (*shutup)(struct hda_codec *codec);
166 void (*automute_hook)(struct hda_codec *codec);
168 /* for pin sensing */
169 unsigned int hp_jack_present:1;
170 unsigned int line_jack_present:1;
171 unsigned int master_mute:1;
172 unsigned int auto_mic:1;
173 unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */
174 unsigned int automute_speaker:1; /* automute speaker outputs */
175 unsigned int automute_lo:1; /* automute LO outputs */
176 unsigned int detect_hp:1; /* Headphone detection enabled */
177 unsigned int detect_lo:1; /* Line-out detection enabled */
178 unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */
179 unsigned int automute_lo_possible:1; /* there are line outs and HP */
180 unsigned int keep_vref_in_automute:1; /* Don't clear VREF in automute */
183 unsigned int no_analog :1; /* digital I/O only */
184 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
185 unsigned int single_input_src:1;
186 unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */
187 unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */
188 unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */
190 /* auto-mute control */
192 hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS];
195 int codec_variant; /* flag for other variants */
197 /* for virtual master */
198 hda_nid_t vmaster_nid;
199 #ifdef CONFIG_SND_HDA_POWER_SAVE
200 struct hda_loopback_check loopback;
205 unsigned int pll_coef_idx, pll_coef_bit;
210 const struct alc_fixup *fixup_list;
211 const char *fixup_name;
215 struct alc_multi_io multi_io[4];
218 struct snd_array bind_ctls;
221 #define ALC_MODEL_AUTO 0 /* common for all chips */
223 static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
224 int dir, unsigned int bits)
228 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
229 if (query_amp_caps(codec, nid, dir) & bits)
234 #define nid_has_mute(codec, nid, dir) \
235 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
236 #define nid_has_volume(codec, nid, dir) \
237 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
242 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
243 struct snd_ctl_elem_info *uinfo)
245 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
246 struct alc_spec *spec = codec->spec;
247 unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
248 if (mux_idx >= spec->num_mux_defs)
250 if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
252 return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
255 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
256 struct snd_ctl_elem_value *ucontrol)
258 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
259 struct alc_spec *spec = codec->spec;
260 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
262 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
266 static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
268 struct alc_spec *spec = codec->spec;
269 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
271 if (spec->cur_adc && spec->cur_adc != new_adc) {
272 /* stream is running, let's swap the current ADC */
273 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
274 spec->cur_adc = new_adc;
275 snd_hda_codec_setup_stream(codec, new_adc,
276 spec->cur_adc_stream_tag, 0,
277 spec->cur_adc_format);
283 static inline hda_nid_t get_capsrc(struct alc_spec *spec, int idx)
285 return spec->capsrc_nids ?
286 spec->capsrc_nids[idx] : spec->adc_nids[idx];
289 static void call_update_outputs(struct hda_codec *codec);
291 /* select the given imux item; either unmute exclusively or select the route */
292 static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
293 unsigned int idx, bool force)
295 struct alc_spec *spec = codec->spec;
296 const struct hda_input_mux *imux;
297 unsigned int mux_idx;
298 int i, type, num_conns;
301 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
302 imux = &spec->input_mux[mux_idx];
303 if (!imux->num_items && mux_idx > 0)
304 imux = &spec->input_mux[0];
305 if (!imux->num_items)
308 if (idx >= imux->num_items)
309 idx = imux->num_items - 1;
310 if (spec->cur_mux[adc_idx] == idx && !force)
312 spec->cur_mux[adc_idx] = idx;
314 /* for shared I/O, change the pin-control accordingly */
315 if (spec->shared_mic_hp) {
316 /* NOTE: this assumes that there are only two inputs, the
317 * first is the real internal mic and the second is HP jack.
319 snd_hda_codec_write(codec, spec->autocfg.inputs[1].pin, 0,
320 AC_VERB_SET_PIN_WIDGET_CONTROL,
321 spec->cur_mux[adc_idx] ?
322 PIN_VREF80 : PIN_HP);
323 spec->automute_speaker = !spec->cur_mux[adc_idx];
324 call_update_outputs(codec);
327 if (spec->dyn_adc_switch) {
328 alc_dyn_adc_pcm_resetup(codec, idx);
329 adc_idx = spec->dyn_adc_idx[idx];
332 nid = get_capsrc(spec, adc_idx);
335 num_conns = snd_hda_get_conn_list(codec, nid, NULL);
339 type = get_wcaps_type(get_wcaps(codec, nid));
340 if (type == AC_WID_AUD_MIX) {
341 /* Matrix-mixer style (e.g. ALC882) */
342 int active = imux->items[idx].index;
343 for (i = 0; i < num_conns; i++) {
344 unsigned int v = (i == active) ? 0 : HDA_AMP_MUTE;
345 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, i,
349 /* MUX style (e.g. ALC880) */
350 snd_hda_codec_write_cache(codec, nid, 0,
351 AC_VERB_SET_CONNECT_SEL,
352 imux->items[idx].index);
357 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
358 struct snd_ctl_elem_value *ucontrol)
360 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
361 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
362 return alc_mux_select(codec, adc_idx,
363 ucontrol->value.enumerated.item[0], false);
367 * set up the input pin config (depending on the given auto-pin type)
369 static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
372 unsigned int val = PIN_IN;
374 if (auto_pin_type == AUTO_PIN_MIC) {
377 oldval = snd_hda_codec_read(codec, nid, 0,
378 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
379 pincap = snd_hda_query_pin_caps(codec, nid);
380 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
381 /* if the default pin setup is vref50, we give it priority */
382 if ((pincap & AC_PINCAP_VREF_80) && oldval != PIN_VREF50)
384 else if (pincap & AC_PINCAP_VREF_50)
386 else if (pincap & AC_PINCAP_VREF_100)
388 else if (pincap & AC_PINCAP_VREF_GRD)
391 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val);
395 * Append the given mixer and verb elements for the later use
396 * The mixer array is referred in build_controls(), and init_verbs are
399 static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
401 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
403 spec->mixers[spec->num_mixers++] = mix;
406 static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
408 if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
410 spec->init_verbs[spec->num_init_verbs++] = verb;
414 * GPIO setup tables, used in initialization
416 /* Enable GPIO mask and set output */
417 static const struct hda_verb alc_gpio1_init_verbs[] = {
418 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
419 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
420 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
424 static const struct hda_verb alc_gpio2_init_verbs[] = {
425 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
426 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
427 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
431 static const struct hda_verb alc_gpio3_init_verbs[] = {
432 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
433 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
434 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
439 * Fix hardware PLL issue
440 * On some codecs, the analog PLL gating control must be off while
441 * the default value is 1.
443 static void alc_fix_pll(struct hda_codec *codec)
445 struct alc_spec *spec = codec->spec;
450 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
452 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
453 AC_VERB_GET_PROC_COEF, 0);
454 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
456 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
457 val & ~(1 << spec->pll_coef_bit));
460 static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
461 unsigned int coef_idx, unsigned int coef_bit)
463 struct alc_spec *spec = codec->spec;
465 spec->pll_coef_idx = coef_idx;
466 spec->pll_coef_bit = coef_bit;
471 * Jack detections for HP auto-mute and mic-switch
474 /* check each pin in the given array; returns true if any of them is plugged */
475 static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
479 for (i = 0; i < num_pins; i++) {
480 hda_nid_t nid = pins[i];
483 present |= snd_hda_jack_detect(codec, nid);
488 /* standard HP/line-out auto-mute helper */
489 static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
490 bool mute, bool hp_out)
492 struct alc_spec *spec = codec->spec;
493 unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0;
494 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
497 for (i = 0; i < num_pins; i++) {
498 hda_nid_t nid = pins[i];
502 switch (spec->automute_mode) {
503 case ALC_AUTOMUTE_PIN:
504 /* don't reset VREF value in case it's controlling
505 * the amp (see alc861_fixup_asus_amp_vref_0f())
507 if (spec->keep_vref_in_automute) {
508 val = snd_hda_codec_read(codec, nid, 0,
509 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
514 snd_hda_codec_write(codec, nid, 0,
515 AC_VERB_SET_PIN_WIDGET_CONTROL,
518 case ALC_AUTOMUTE_AMP:
519 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
520 HDA_AMP_MUTE, mute_bits);
522 case ALC_AUTOMUTE_MIXER:
523 nid = spec->automute_mixer_nid[i];
526 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
527 HDA_AMP_MUTE, mute_bits);
528 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1,
529 HDA_AMP_MUTE, mute_bits);
535 /* Toggle outputs muting */
536 static void update_outputs(struct hda_codec *codec)
538 struct alc_spec *spec = codec->spec;
541 /* Control HP pins/amps depending on master_mute state;
542 * in general, HP pins/amps control should be enabled in all cases,
543 * but currently set only for master_mute, just to be safe
545 if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */
546 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
547 spec->autocfg.hp_pins, spec->master_mute, true);
549 if (!spec->automute_speaker)
552 on = spec->hp_jack_present | spec->line_jack_present;
553 on |= spec->master_mute;
554 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
555 spec->autocfg.speaker_pins, on, false);
557 /* toggle line-out mutes if needed, too */
558 /* if LO is a copy of either HP or Speaker, don't need to handle it */
559 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
560 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
562 if (!spec->automute_lo)
565 on = spec->hp_jack_present;
566 on |= spec->master_mute;
567 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
568 spec->autocfg.line_out_pins, on, false);
571 static void call_update_outputs(struct hda_codec *codec)
573 struct alc_spec *spec = codec->spec;
574 if (spec->automute_hook)
575 spec->automute_hook(codec);
577 update_outputs(codec);
580 /* standard HP-automute helper */
581 static void alc_hp_automute(struct hda_codec *codec)
583 struct alc_spec *spec = codec->spec;
585 spec->hp_jack_present =
586 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
587 spec->autocfg.hp_pins);
588 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
590 call_update_outputs(codec);
593 /* standard line-out-automute helper */
594 static void alc_line_automute(struct hda_codec *codec)
596 struct alc_spec *spec = codec->spec;
598 /* check LO jack only when it's different from HP */
599 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
602 spec->line_jack_present =
603 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
604 spec->autocfg.line_out_pins);
605 if (!spec->automute_speaker || !spec->detect_lo)
607 call_update_outputs(codec);
610 #define get_connection_index(codec, mux, nid) \
611 snd_hda_get_conn_index(codec, mux, nid, 0)
613 /* standard mic auto-switch helper */
614 static void alc_mic_automute(struct hda_codec *codec)
616 struct alc_spec *spec = codec->spec;
617 hda_nid_t *pins = spec->imux_pins;
619 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
621 if (snd_BUG_ON(!spec->adc_nids))
623 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
626 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
627 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
628 else if (spec->dock_mic_idx >= 0 &&
629 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
630 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
632 alc_mux_select(codec, 0, spec->int_mic_idx, false);
635 /* handle the specified unsol action (ALC_XXX_EVENT) */
636 static void alc_exec_unsol_event(struct hda_codec *codec, int action)
640 alc_hp_automute(codec);
642 case ALC_FRONT_EVENT:
643 alc_line_automute(codec);
646 alc_mic_automute(codec);
649 snd_hda_jack_report_sync(codec);
652 /* unsolicited event for HP jack sensing */
653 static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
655 if (codec->vendor_id == 0x10ec0880)
659 res = snd_hda_jack_get_action(codec, res);
660 alc_exec_unsol_event(codec, res);
663 /* call init functions of standard auto-mute helpers */
664 static void alc_inithook(struct hda_codec *codec)
666 alc_hp_automute(codec);
667 alc_line_automute(codec);
668 alc_mic_automute(codec);
671 /* additional initialization for ALC888 variants */
672 static void alc888_coef_init(struct hda_codec *codec)
676 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
677 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
678 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
679 if ((tmp & 0xf0) == 0x20)
681 snd_hda_codec_read(codec, 0x20, 0,
682 AC_VERB_SET_PROC_COEF, 0x830);
685 snd_hda_codec_read(codec, 0x20, 0,
686 AC_VERB_SET_PROC_COEF, 0x3030);
689 /* additional initialization for ALC889 variants */
690 static void alc889_coef_init(struct hda_codec *codec)
694 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
695 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
696 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
697 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
700 /* turn on/off EAPD control (only if available) */
701 static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
703 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
705 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
706 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
710 /* turn on/off EAPD controls of the codec */
711 static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
713 /* We currently only handle front, HP */
714 static hda_nid_t pins[] = {
715 0x0f, 0x10, 0x14, 0x15, 0
718 for (p = pins; *p; p++)
719 set_eapd(codec, *p, on);
722 /* generic shutup callback;
723 * just turning off EPAD and a little pause for avoiding pop-noise
725 static void alc_eapd_shutup(struct hda_codec *codec)
727 alc_auto_setup_eapd(codec, false);
731 /* generic EAPD initialization */
732 static void alc_auto_init_amp(struct hda_codec *codec, int type)
736 alc_auto_setup_eapd(codec, true);
739 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
742 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
745 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
747 case ALC_INIT_DEFAULT:
748 switch (codec->vendor_id) {
750 snd_hda_codec_write(codec, 0x1a, 0,
751 AC_VERB_SET_COEF_INDEX, 7);
752 tmp = snd_hda_codec_read(codec, 0x1a, 0,
753 AC_VERB_GET_PROC_COEF, 0);
754 snd_hda_codec_write(codec, 0x1a, 0,
755 AC_VERB_SET_COEF_INDEX, 7);
756 snd_hda_codec_write(codec, 0x1a, 0,
757 AC_VERB_SET_PROC_COEF,
766 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
767 alc889_coef_init(codec);
770 alc888_coef_init(codec);
772 #if 0 /* XXX: This may cause the silent output on speaker on some machines */
775 snd_hda_codec_write(codec, 0x20, 0,
776 AC_VERB_SET_COEF_INDEX, 7);
777 tmp = snd_hda_codec_read(codec, 0x20, 0,
778 AC_VERB_GET_PROC_COEF, 0);
779 snd_hda_codec_write(codec, 0x20, 0,
780 AC_VERB_SET_COEF_INDEX, 7);
781 snd_hda_codec_write(codec, 0x20, 0,
782 AC_VERB_SET_PROC_COEF,
792 * Auto-Mute mode mixer enum support
794 static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
795 struct snd_ctl_elem_info *uinfo)
797 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
798 struct alc_spec *spec = codec->spec;
799 static const char * const texts2[] = {
800 "Disabled", "Enabled"
802 static const char * const texts3[] = {
803 "Disabled", "Speaker Only", "Line-Out+Speaker"
805 const char * const *texts;
807 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
809 if (spec->automute_speaker_possible && spec->automute_lo_possible) {
810 uinfo->value.enumerated.items = 3;
813 uinfo->value.enumerated.items = 2;
816 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
817 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
818 strcpy(uinfo->value.enumerated.name,
819 texts[uinfo->value.enumerated.item]);
823 static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
824 struct snd_ctl_elem_value *ucontrol)
826 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
827 struct alc_spec *spec = codec->spec;
828 unsigned int val = 0;
829 if (spec->automute_speaker)
831 if (spec->automute_lo)
834 ucontrol->value.enumerated.item[0] = val;
838 static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
839 struct snd_ctl_elem_value *ucontrol)
841 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
842 struct alc_spec *spec = codec->spec;
844 switch (ucontrol->value.enumerated.item[0]) {
846 if (!spec->automute_speaker && !spec->automute_lo)
848 spec->automute_speaker = 0;
849 spec->automute_lo = 0;
852 if (spec->automute_speaker_possible) {
853 if (!spec->automute_lo && spec->automute_speaker)
855 spec->automute_speaker = 1;
856 spec->automute_lo = 0;
857 } else if (spec->automute_lo_possible) {
858 if (spec->automute_lo)
860 spec->automute_lo = 1;
865 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
867 if (spec->automute_speaker && spec->automute_lo)
869 spec->automute_speaker = 1;
870 spec->automute_lo = 1;
875 call_update_outputs(codec);
879 static const struct snd_kcontrol_new alc_automute_mode_enum = {
880 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
881 .name = "Auto-Mute Mode",
882 .info = alc_automute_mode_info,
883 .get = alc_automute_mode_get,
884 .put = alc_automute_mode_put,
887 static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec)
889 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
890 return snd_array_new(&spec->kctls);
893 static int alc_add_automute_mode_enum(struct hda_codec *codec)
895 struct alc_spec *spec = codec->spec;
896 struct snd_kcontrol_new *knew;
898 knew = alc_kcontrol_new(spec);
901 *knew = alc_automute_mode_enum;
902 knew->name = kstrdup("Auto-Mute Mode", GFP_KERNEL);
909 * Check the availability of HP/line-out auto-mute;
910 * Set up appropriately if really supported
912 static void alc_init_automute(struct hda_codec *codec)
914 struct alc_spec *spec = codec->spec;
915 struct auto_pin_cfg *cfg = &spec->autocfg;
921 if (cfg->line_out_pins[0])
923 if (cfg->speaker_pins[0])
925 if (present < 2) /* need two different output types */
928 if (!cfg->speaker_pins[0] &&
929 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
930 memcpy(cfg->speaker_pins, cfg->line_out_pins,
931 sizeof(cfg->speaker_pins));
932 cfg->speaker_outs = cfg->line_outs;
935 if (!cfg->hp_pins[0] &&
936 cfg->line_out_type == AUTO_PIN_HP_OUT) {
937 memcpy(cfg->hp_pins, cfg->line_out_pins,
938 sizeof(cfg->hp_pins));
939 cfg->hp_outs = cfg->line_outs;
942 spec->automute_mode = ALC_AUTOMUTE_PIN;
944 for (i = 0; i < cfg->hp_outs; i++) {
945 hda_nid_t nid = cfg->hp_pins[i];
946 if (!is_jack_detectable(codec, nid))
948 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
950 snd_hda_jack_detect_enable(codec, nid, ALC_HP_EVENT);
954 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
955 if (cfg->speaker_outs)
956 for (i = 0; i < cfg->line_outs; i++) {
957 hda_nid_t nid = cfg->line_out_pins[i];
958 if (!is_jack_detectable(codec, nid))
960 snd_printdd("realtek: Enable Line-Out "
961 "auto-muting on NID 0x%x\n", nid);
962 snd_hda_jack_detect_enable(codec, nid,
966 spec->automute_lo_possible = spec->detect_hp;
969 spec->automute_speaker_possible = cfg->speaker_outs &&
970 (spec->detect_hp || spec->detect_lo);
972 spec->automute_lo = spec->automute_lo_possible;
973 spec->automute_speaker = spec->automute_speaker_possible;
975 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
976 /* create a control for automute mode */
977 alc_add_automute_mode_enum(codec);
978 spec->unsol_event = alc_sku_unsol_event;
982 /* return the position of NID in the list, or -1 if not found */
983 static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
986 for (i = 0; i < nums; i++)
992 /* check whether dynamic ADC-switching is available */
993 static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
995 struct alc_spec *spec = codec->spec;
996 struct hda_input_mux *imux = &spec->private_imux[0];
1000 if (imux != spec->input_mux) /* no dynamic imux? */
1003 for (n = 0; n < spec->num_adc_nids; n++) {
1004 cap = spec->private_capsrc_nids[n];
1005 for (i = 0; i < imux->num_items; i++) {
1006 pin = spec->imux_pins[i];
1009 if (get_connection_index(codec, cap, pin) < 0)
1012 if (i >= imux->num_items)
1013 return true; /* no ADC-switch is needed */
1016 for (i = 0; i < imux->num_items; i++) {
1017 pin = spec->imux_pins[i];
1018 for (n = 0; n < spec->num_adc_nids; n++) {
1019 cap = spec->private_capsrc_nids[n];
1020 idx = get_connection_index(codec, cap, pin);
1022 imux->items[i].index = idx;
1023 spec->dyn_adc_idx[i] = n;
1029 snd_printdd("realtek: enabling ADC switching\n");
1030 spec->dyn_adc_switch = 1;
1034 /* rebuild imux for matching with the given auto-mic pins (if not yet) */
1035 static bool alc_rebuild_imux_for_auto_mic(struct hda_codec *codec)
1037 struct alc_spec *spec = codec->spec;
1038 struct hda_input_mux *imux;
1039 static char * const texts[3] = {
1040 "Mic", "Internal Mic", "Dock Mic"
1044 if (!spec->auto_mic)
1046 imux = &spec->private_imux[0];
1047 if (spec->input_mux == imux)
1049 spec->imux_pins[0] = spec->ext_mic_pin;
1050 spec->imux_pins[1] = spec->int_mic_pin;
1051 spec->imux_pins[2] = spec->dock_mic_pin;
1052 for (i = 0; i < 3; i++) {
1053 strcpy(imux->items[i].label, texts[i]);
1054 if (spec->imux_pins[i]) {
1055 hda_nid_t pin = spec->imux_pins[i];
1057 for (c = 0; c < spec->num_adc_nids; c++) {
1058 hda_nid_t cap = get_capsrc(spec, c);
1059 int idx = get_connection_index(codec, cap, pin);
1061 imux->items[i].index = idx;
1065 imux->num_items = i + 1;
1068 spec->num_mux_defs = 1;
1069 spec->input_mux = imux;
1073 /* check whether all auto-mic pins are valid; setup indices if OK */
1074 static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1076 struct alc_spec *spec = codec->spec;
1077 const struct hda_input_mux *imux;
1079 if (!spec->auto_mic)
1081 if (spec->auto_mic_valid_imux)
1082 return true; /* already checked */
1084 /* fill up imux indices */
1085 if (!alc_check_dyn_adc_switch(codec)) {
1090 imux = spec->input_mux;
1091 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1092 spec->imux_pins, imux->num_items);
1093 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1094 spec->imux_pins, imux->num_items);
1095 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1096 spec->imux_pins, imux->num_items);
1097 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1099 return false; /* no corresponding imux */
1102 snd_hda_jack_detect_enable(codec, spec->ext_mic_pin, ALC_MIC_EVENT);
1103 if (spec->dock_mic_pin)
1104 snd_hda_jack_detect_enable(codec, spec->dock_mic_pin,
1107 spec->auto_mic_valid_imux = 1;
1113 * Check the availability of auto-mic switch;
1114 * Set up if really supported
1116 static void alc_init_auto_mic(struct hda_codec *codec)
1118 struct alc_spec *spec = codec->spec;
1119 struct auto_pin_cfg *cfg = &spec->autocfg;
1120 hda_nid_t fixed, ext, dock;
1123 if (spec->shared_mic_hp)
1124 return; /* no auto-mic for the shared I/O */
1126 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1128 fixed = ext = dock = 0;
1129 for (i = 0; i < cfg->num_inputs; i++) {
1130 hda_nid_t nid = cfg->inputs[i].pin;
1131 unsigned int defcfg;
1132 defcfg = snd_hda_codec_get_pincfg(codec, nid);
1133 switch (snd_hda_get_input_pin_attr(defcfg)) {
1134 case INPUT_PIN_ATTR_INT:
1136 return; /* already occupied */
1137 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1138 return; /* invalid type */
1141 case INPUT_PIN_ATTR_UNUSED:
1142 return; /* invalid entry */
1143 case INPUT_PIN_ATTR_DOCK:
1145 return; /* already occupied */
1146 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1147 return; /* invalid type */
1152 return; /* already occupied */
1153 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1154 return; /* invalid type */
1165 if (!is_jack_detectable(codec, ext))
1166 return; /* no unsol support */
1167 if (dock && !is_jack_detectable(codec, dock))
1168 return; /* no unsol support */
1170 /* check imux indices */
1171 spec->ext_mic_pin = ext;
1172 spec->int_mic_pin = fixed;
1173 spec->dock_mic_pin = dock;
1176 if (!alc_auto_mic_check_imux(codec))
1179 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1181 spec->unsol_event = alc_sku_unsol_event;
1184 /* check the availabilities of auto-mute and auto-mic switches */
1185 static void alc_auto_check_switches(struct hda_codec *codec)
1187 alc_init_automute(codec);
1188 alc_init_auto_mic(codec);
1192 * Realtek SSID verification
1195 /* Could be any non-zero and even value. When used as fixup, tells
1196 * the driver to ignore any present sku defines.
1198 #define ALC_FIXUP_SKU_IGNORE (2)
1200 static int alc_auto_parse_customize_define(struct hda_codec *codec)
1202 unsigned int ass, tmp, i;
1204 struct alc_spec *spec = codec->spec;
1206 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1208 if (spec->cdefine.fixup) {
1209 ass = spec->cdefine.sku_cfg;
1210 if (ass == ALC_FIXUP_SKU_IGNORE)
1215 ass = codec->subsystem_id & 0xffff;
1216 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
1220 if (codec->vendor_id == 0x10ec0260)
1222 ass = snd_hda_codec_get_pincfg(codec, nid);
1225 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1226 codec->chip_name, ass);
1232 for (i = 1; i < 16; i++) {
1236 if (((ass >> 16) & 0xf) != tmp)
1239 spec->cdefine.port_connectivity = ass >> 30;
1240 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1241 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1242 spec->cdefine.customization = ass >> 8;
1244 spec->cdefine.sku_cfg = ass;
1245 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1246 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1247 spec->cdefine.swap = (ass & 0x2) >> 1;
1248 spec->cdefine.override = ass & 0x1;
1250 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1251 nid, spec->cdefine.sku_cfg);
1252 snd_printd("SKU: port_connectivity=0x%x\n",
1253 spec->cdefine.port_connectivity);
1254 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1255 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1256 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1257 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1258 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1259 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1260 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1265 /* return true if the given NID is found in the list */
1266 static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1268 return find_idx_in_nid_list(nid, list, nums) >= 0;
1271 /* check subsystem ID and set up device-specific initialization;
1272 * return 1 if initialized, 0 if invalid SSID
1274 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1275 * 31 ~ 16 : Manufacture ID
1277 * 7 ~ 0 : Assembly ID
1278 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1280 static int alc_subsystem_id(struct hda_codec *codec,
1281 hda_nid_t porta, hda_nid_t porte,
1282 hda_nid_t portd, hda_nid_t porti)
1284 unsigned int ass, tmp, i;
1286 struct alc_spec *spec = codec->spec;
1288 if (spec->cdefine.fixup) {
1289 ass = spec->cdefine.sku_cfg;
1290 if (ass == ALC_FIXUP_SKU_IGNORE)
1295 ass = codec->subsystem_id & 0xffff;
1296 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1299 /* invalid SSID, check the special NID pin defcfg instead */
1301 * 31~30 : port connectivity
1304 * 19~16 : Check sum (15:1)
1309 if (codec->vendor_id == 0x10ec0260)
1311 ass = snd_hda_codec_get_pincfg(codec, nid);
1312 snd_printd("realtek: No valid SSID, "
1313 "checking pincfg 0x%08x for NID 0x%x\n",
1317 if ((ass >> 30) != 1) /* no physical connection */
1322 for (i = 1; i < 16; i++) {
1326 if (((ass >> 16) & 0xf) != tmp)
1329 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1330 ass & 0xffff, codec->vendor_id);
1334 * 2 : 0 --> Desktop, 1 --> Laptop
1335 * 3~5 : External Amplifier control
1338 tmp = (ass & 0x38) >> 3; /* external Amp control */
1341 spec->init_amp = ALC_INIT_GPIO1;
1344 spec->init_amp = ALC_INIT_GPIO2;
1347 spec->init_amp = ALC_INIT_GPIO3;
1351 spec->init_amp = ALC_INIT_DEFAULT;
1355 /* is laptop or Desktop and enable the function "Mute internal speaker
1356 * when the external headphone out jack is plugged"
1358 if (!(ass & 0x8000))
1361 * 10~8 : Jack location
1362 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1364 * 15 : 1 --> enable the function "Mute internal speaker
1365 * when the external headphone out jack is plugged"
1367 if (!spec->autocfg.hp_pins[0] &&
1368 !(spec->autocfg.line_out_pins[0] &&
1369 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
1371 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1382 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1383 spec->autocfg.line_outs))
1385 spec->autocfg.hp_pins[0] = nid;
1390 /* Check the validity of ALC subsystem-id
1391 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1392 static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
1394 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
1395 struct alc_spec *spec = codec->spec;
1396 snd_printd("realtek: "
1397 "Enable default setup for auto mode as fallback\n");
1398 spec->init_amp = ALC_INIT_DEFAULT;
1403 * Fix-up pin default configurations and add default verbs
1411 struct alc_model_fixup {
1422 const struct alc_pincfg *pins;
1423 const struct hda_verb *verbs;
1424 void (*func)(struct hda_codec *codec,
1425 const struct alc_fixup *fix,
1439 ALC_FIXUP_ACT_PRE_PROBE,
1440 ALC_FIXUP_ACT_PROBE,
1444 static void alc_apply_fixup(struct hda_codec *codec, int action)
1446 struct alc_spec *spec = codec->spec;
1447 int id = spec->fixup_id;
1448 #ifdef CONFIG_SND_DEBUG_VERBOSE
1449 const char *modelname = spec->fixup_name;
1453 if (!spec->fixup_list)
1457 const struct alc_fixup *fix = spec->fixup_list + id;
1458 const struct alc_pincfg *cfg;
1460 switch (fix->type) {
1462 if (action != ALC_FIXUP_ACT_PRE_PROBE || !fix->v.sku)
1464 snd_printdd(KERN_INFO "hda_codec: %s: "
1465 "Apply sku override for %s\n",
1466 codec->chip_name, modelname);
1467 spec->cdefine.sku_cfg = fix->v.sku;
1468 spec->cdefine.fixup = 1;
1470 case ALC_FIXUP_PINS:
1472 if (action != ALC_FIXUP_ACT_PRE_PROBE || !cfg)
1474 snd_printdd(KERN_INFO "hda_codec: %s: "
1475 "Apply pincfg for %s\n",
1476 codec->chip_name, modelname);
1477 for (; cfg->nid; cfg++)
1478 snd_hda_codec_set_pincfg(codec, cfg->nid,
1481 case ALC_FIXUP_VERBS:
1482 if (action != ALC_FIXUP_ACT_PROBE || !fix->v.verbs)
1484 snd_printdd(KERN_INFO "hda_codec: %s: "
1485 "Apply fix-verbs for %s\n",
1486 codec->chip_name, modelname);
1487 add_verb(codec->spec, fix->v.verbs);
1489 case ALC_FIXUP_FUNC:
1492 snd_printdd(KERN_INFO "hda_codec: %s: "
1493 "Apply fix-func for %s\n",
1494 codec->chip_name, modelname);
1495 fix->v.func(codec, fix, action);
1498 snd_printk(KERN_ERR "hda_codec: %s: "
1499 "Invalid fixup type %d\n",
1500 codec->chip_name, fix->type);
1511 static void alc_pick_fixup(struct hda_codec *codec,
1512 const struct alc_model_fixup *models,
1513 const struct snd_pci_quirk *quirk,
1514 const struct alc_fixup *fixlist)
1516 struct alc_spec *spec = codec->spec;
1517 const struct snd_pci_quirk *q;
1519 const char *name = NULL;
1521 if (codec->modelname && models) {
1522 while (models->name) {
1523 if (!strcmp(codec->modelname, models->name)) {
1525 name = models->name;
1532 q = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1535 #ifdef CONFIG_SND_DEBUG_VERBOSE
1541 for (q = quirk; q->subvendor; q++) {
1542 unsigned int vendorid =
1543 q->subdevice | (q->subvendor << 16);
1544 if (vendorid == codec->subsystem_id) {
1546 #ifdef CONFIG_SND_DEBUG_VERBOSE
1554 spec->fixup_id = id;
1556 spec->fixup_list = fixlist;
1557 spec->fixup_name = name;
1562 * COEF access helper functions
1564 static int alc_read_coef_idx(struct hda_codec *codec,
1565 unsigned int coef_idx)
1568 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1570 val = snd_hda_codec_read(codec, 0x20, 0,
1571 AC_VERB_GET_PROC_COEF, 0);
1575 static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1576 unsigned int coef_val)
1578 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1580 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1584 /* a special bypass for COEF 0; read the cached value at the second time */
1585 static unsigned int alc_get_coef0(struct hda_codec *codec)
1587 struct alc_spec *spec = codec->spec;
1589 spec->coef0 = alc_read_coef_idx(codec, 0);
1594 * Digital I/O handling
1597 /* set right pin controls for digital I/O */
1598 static void alc_auto_init_digital(struct hda_codec *codec)
1600 struct alc_spec *spec = codec->spec;
1604 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1605 pin = spec->autocfg.dig_out_pins[i];
1608 snd_hda_codec_write(codec, pin, 0,
1609 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
1611 dac = spec->multiout.dig_out_nid;
1613 dac = spec->slave_dig_outs[i - 1];
1614 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
1616 snd_hda_codec_write(codec, dac, 0,
1617 AC_VERB_SET_AMP_GAIN_MUTE,
1620 pin = spec->autocfg.dig_in_pin;
1622 snd_hda_codec_write(codec, pin, 0,
1623 AC_VERB_SET_PIN_WIDGET_CONTROL,
1627 /* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1628 static void alc_auto_parse_digital(struct hda_codec *codec)
1630 struct alc_spec *spec = codec->spec;
1634 /* support multiple SPDIFs; the secondary is set up as a slave */
1636 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1638 err = snd_hda_get_connections(codec,
1639 spec->autocfg.dig_out_pins[i],
1640 conn, ARRAY_SIZE(conn));
1643 dig_nid = conn[0]; /* assume the first element is audio-out */
1645 spec->multiout.dig_out_nid = dig_nid;
1646 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1648 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
1649 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
1651 spec->slave_dig_outs[nums - 1] = dig_nid;
1656 if (spec->autocfg.dig_in_pin) {
1657 dig_nid = codec->start_nid;
1658 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1659 unsigned int wcaps = get_wcaps(codec, dig_nid);
1660 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1662 if (!(wcaps & AC_WCAP_DIGITAL))
1664 if (!(wcaps & AC_WCAP_CONN_LIST))
1666 err = get_connection_index(codec, dig_nid,
1667 spec->autocfg.dig_in_pin);
1669 spec->dig_in_nid = dig_nid;
1677 * capture mixer elements
1679 static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1680 struct snd_ctl_elem_info *uinfo)
1682 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1683 struct alc_spec *spec = codec->spec;
1687 mutex_lock(&codec->control_mutex);
1688 if (spec->vol_in_capsrc)
1689 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1691 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1692 kcontrol->private_value = val;
1693 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
1694 mutex_unlock(&codec->control_mutex);
1698 static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1699 unsigned int size, unsigned int __user *tlv)
1701 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1702 struct alc_spec *spec = codec->spec;
1706 mutex_lock(&codec->control_mutex);
1707 if (spec->vol_in_capsrc)
1708 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1710 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1711 kcontrol->private_value = val;
1712 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
1713 mutex_unlock(&codec->control_mutex);
1717 typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1718 struct snd_ctl_elem_value *ucontrol);
1720 static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1721 struct snd_ctl_elem_value *ucontrol,
1722 getput_call_t func, bool check_adc_switch)
1724 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1725 struct alc_spec *spec = codec->spec;
1728 mutex_lock(&codec->control_mutex);
1729 if (check_adc_switch && spec->dyn_adc_switch) {
1730 for (i = 0; i < spec->num_adc_nids; i++) {
1731 kcontrol->private_value =
1732 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1734 err = func(kcontrol, ucontrol);
1739 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1740 if (spec->vol_in_capsrc)
1741 kcontrol->private_value =
1742 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1745 kcontrol->private_value =
1746 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1748 err = func(kcontrol, ucontrol);
1751 mutex_unlock(&codec->control_mutex);
1755 static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1756 struct snd_ctl_elem_value *ucontrol)
1758 return alc_cap_getput_caller(kcontrol, ucontrol,
1759 snd_hda_mixer_amp_volume_get, false);
1762 static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1763 struct snd_ctl_elem_value *ucontrol)
1765 return alc_cap_getput_caller(kcontrol, ucontrol,
1766 snd_hda_mixer_amp_volume_put, true);
1769 /* capture mixer elements */
1770 #define alc_cap_sw_info snd_ctl_boolean_stereo_info
1772 static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1773 struct snd_ctl_elem_value *ucontrol)
1775 return alc_cap_getput_caller(kcontrol, ucontrol,
1776 snd_hda_mixer_amp_switch_get, false);
1779 static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1780 struct snd_ctl_elem_value *ucontrol)
1782 return alc_cap_getput_caller(kcontrol, ucontrol,
1783 snd_hda_mixer_amp_switch_put, true);
1786 #define _DEFINE_CAPMIX(num) \
1788 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1789 .name = "Capture Switch", \
1790 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1792 .info = alc_cap_sw_info, \
1793 .get = alc_cap_sw_get, \
1794 .put = alc_cap_sw_put, \
1797 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1798 .name = "Capture Volume", \
1799 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1800 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1801 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1803 .info = alc_cap_vol_info, \
1804 .get = alc_cap_vol_get, \
1805 .put = alc_cap_vol_put, \
1806 .tlv = { .c = alc_cap_vol_tlv }, \
1809 #define _DEFINE_CAPSRC(num) \
1811 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1812 /* .name = "Capture Source", */ \
1813 .name = "Input Source", \
1815 .info = alc_mux_enum_info, \
1816 .get = alc_mux_enum_get, \
1817 .put = alc_mux_enum_put, \
1820 #define DEFINE_CAPMIX(num) \
1821 static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
1822 _DEFINE_CAPMIX(num), \
1823 _DEFINE_CAPSRC(num), \
1827 #define DEFINE_CAPMIX_NOSRC(num) \
1828 static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
1829 _DEFINE_CAPMIX(num), \
1833 /* up to three ADCs */
1837 DEFINE_CAPMIX_NOSRC(1);
1838 DEFINE_CAPMIX_NOSRC(2);
1839 DEFINE_CAPMIX_NOSRC(3);
1842 * virtual master controls
1846 * slave controls for virtual master
1848 static const char * const alc_slave_vols[] = {
1849 "Front Playback Volume",
1850 "Surround Playback Volume",
1851 "Center Playback Volume",
1852 "LFE Playback Volume",
1853 "Side Playback Volume",
1854 "Headphone Playback Volume",
1855 "Speaker Playback Volume",
1856 "Mono Playback Volume",
1857 "Line-Out Playback Volume",
1858 "PCM Playback Volume",
1862 static const char * const alc_slave_sws[] = {
1863 "Front Playback Switch",
1864 "Surround Playback Switch",
1865 "Center Playback Switch",
1866 "LFE Playback Switch",
1867 "Side Playback Switch",
1868 "Headphone Playback Switch",
1869 "Speaker Playback Switch",
1870 "Mono Playback Switch",
1871 "IEC958 Playback Switch",
1872 "Line-Out Playback Switch",
1873 "PCM Playback Switch",
1878 * build control elements
1881 #define NID_MAPPING (-1)
1883 #define SUBDEV_SPEAKER_ (0 << 6)
1884 #define SUBDEV_HP_ (1 << 6)
1885 #define SUBDEV_LINE_ (2 << 6)
1886 #define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1887 #define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1888 #define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1890 static void alc_free_kctls(struct hda_codec *codec);
1892 #ifdef CONFIG_SND_HDA_INPUT_BEEP
1893 /* additional beep mixers; the actual parameters are overwritten at build */
1894 static const struct snd_kcontrol_new alc_beep_mixer[] = {
1895 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
1896 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
1901 static int __alc_build_controls(struct hda_codec *codec)
1903 struct alc_spec *spec = codec->spec;
1904 struct snd_kcontrol *kctl = NULL;
1905 const struct snd_kcontrol_new *knew;
1910 for (i = 0; i < spec->num_mixers; i++) {
1911 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1915 if (spec->cap_mixer) {
1916 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1920 if (spec->multiout.dig_out_nid) {
1921 err = snd_hda_create_spdif_out_ctls(codec,
1922 spec->multiout.dig_out_nid,
1923 spec->multiout.dig_out_nid);
1926 if (!spec->no_analog) {
1927 err = snd_hda_create_spdif_share_sw(codec,
1931 spec->multiout.share_spdif = 1;
1934 if (spec->dig_in_nid) {
1935 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1940 #ifdef CONFIG_SND_HDA_INPUT_BEEP
1941 /* create beep controls if needed */
1942 if (spec->beep_amp) {
1943 const struct snd_kcontrol_new *knew;
1944 for (knew = alc_beep_mixer; knew->name; knew++) {
1945 struct snd_kcontrol *kctl;
1946 kctl = snd_ctl_new1(knew, codec);
1949 kctl->private_value = spec->beep_amp;
1950 err = snd_hda_ctl_add(codec, 0, kctl);
1957 /* if we have no master control, let's create it */
1958 if (!spec->no_analog &&
1959 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1960 unsigned int vmaster_tlv[4];
1961 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
1962 HDA_OUTPUT, vmaster_tlv);
1963 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1964 vmaster_tlv, alc_slave_vols);
1968 if (!spec->no_analog &&
1969 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1970 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1971 NULL, alc_slave_sws);
1976 /* assign Capture Source enums to NID */
1977 if (spec->capsrc_nids || spec->adc_nids) {
1978 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
1980 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1981 for (i = 0; kctl && i < kctl->count; i++) {
1982 err = snd_hda_add_nid(codec, kctl, i,
1983 get_capsrc(spec, i));
1988 if (spec->cap_mixer && spec->adc_nids) {
1989 const char *kname = kctl ? kctl->id.name : NULL;
1990 for (knew = spec->cap_mixer; knew->name; knew++) {
1991 if (kname && strcmp(knew->name, kname) == 0)
1993 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1994 for (i = 0; kctl && i < kctl->count; i++) {
1995 err = snd_hda_add_nid(codec, kctl, i,
2003 /* other nid->control mapping */
2004 for (i = 0; i < spec->num_mixers; i++) {
2005 for (knew = spec->mixers[i]; knew->name; knew++) {
2006 if (knew->iface != NID_MAPPING)
2008 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
2011 u = knew->subdevice;
2012 for (j = 0; j < 4; j++, u >>= 8) {
2017 case SUBDEV_SPEAKER_:
2018 nid = spec->autocfg.speaker_pins[nid];
2021 nid = spec->autocfg.line_out_pins[nid];
2024 nid = spec->autocfg.hp_pins[nid];
2029 err = snd_hda_add_nid(codec, kctl, 0, nid);
2033 u = knew->private_value;
2034 for (j = 0; j < 4; j++, u >>= 8) {
2038 err = snd_hda_add_nid(codec, kctl, 0, nid);
2045 alc_free_kctls(codec); /* no longer needed */
2050 static int alc_build_controls(struct hda_codec *codec)
2052 struct alc_spec *spec = codec->spec;
2053 int err = __alc_build_controls(codec);
2056 return snd_hda_jack_add_kctls(codec, &spec->autocfg);
2064 static void alc_init_special_input_src(struct hda_codec *codec);
2066 static int alc_init(struct hda_codec *codec)
2068 struct alc_spec *spec = codec->spec;
2072 alc_auto_init_amp(codec, spec->init_amp);
2074 for (i = 0; i < spec->num_init_verbs; i++)
2075 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2076 alc_init_special_input_src(codec);
2078 if (spec->init_hook)
2079 spec->init_hook(codec);
2081 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2083 snd_hda_jack_report_sync(codec);
2085 hda_call_check_power_status(codec, 0x01);
2089 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2091 struct alc_spec *spec = codec->spec;
2093 if (spec->unsol_event)
2094 spec->unsol_event(codec, res);
2097 #ifdef CONFIG_SND_HDA_POWER_SAVE
2098 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2100 struct alc_spec *spec = codec->spec;
2101 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2106 * Analog playback callbacks
2108 static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
2109 struct hda_codec *codec,
2110 struct snd_pcm_substream *substream)
2112 struct alc_spec *spec = codec->spec;
2113 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2117 static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2118 struct hda_codec *codec,
2119 unsigned int stream_tag,
2120 unsigned int format,
2121 struct snd_pcm_substream *substream)
2123 struct alc_spec *spec = codec->spec;
2124 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2125 stream_tag, format, substream);
2128 static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2129 struct hda_codec *codec,
2130 struct snd_pcm_substream *substream)
2132 struct alc_spec *spec = codec->spec;
2133 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2139 static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2140 struct hda_codec *codec,
2141 struct snd_pcm_substream *substream)
2143 struct alc_spec *spec = codec->spec;
2144 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2147 static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2148 struct hda_codec *codec,
2149 unsigned int stream_tag,
2150 unsigned int format,
2151 struct snd_pcm_substream *substream)
2153 struct alc_spec *spec = codec->spec;
2154 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2155 stream_tag, format, substream);
2158 static int alc_dig_playback_pcm_cleanup(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_cleanup(codec, &spec->multiout);
2166 static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2167 struct hda_codec *codec,
2168 struct snd_pcm_substream *substream)
2170 struct alc_spec *spec = codec->spec;
2171 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2177 static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2178 struct hda_codec *codec,
2179 unsigned int stream_tag,
2180 unsigned int format,
2181 struct snd_pcm_substream *substream)
2183 struct alc_spec *spec = codec->spec;
2185 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
2186 stream_tag, 0, format);
2190 static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2191 struct hda_codec *codec,
2192 struct snd_pcm_substream *substream)
2194 struct alc_spec *spec = codec->spec;
2196 snd_hda_codec_cleanup_stream(codec,
2197 spec->adc_nids[substream->number + 1]);
2201 /* analog capture with dynamic dual-adc changes */
2202 static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2203 struct hda_codec *codec,
2204 unsigned int stream_tag,
2205 unsigned int format,
2206 struct snd_pcm_substream *substream)
2208 struct alc_spec *spec = codec->spec;
2209 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
2210 spec->cur_adc_stream_tag = stream_tag;
2211 spec->cur_adc_format = format;
2212 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2216 static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2217 struct hda_codec *codec,
2218 struct snd_pcm_substream *substream)
2220 struct alc_spec *spec = codec->spec;
2221 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2226 static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
2230 .nid = 0, /* fill later */
2232 .prepare = dyn_adc_capture_pcm_prepare,
2233 .cleanup = dyn_adc_capture_pcm_cleanup
2239 static const struct hda_pcm_stream alc_pcm_analog_playback = {
2243 /* NID is set in alc_build_pcms */
2245 .open = alc_playback_pcm_open,
2246 .prepare = alc_playback_pcm_prepare,
2247 .cleanup = alc_playback_pcm_cleanup
2251 static const struct hda_pcm_stream alc_pcm_analog_capture = {
2255 /* NID is set in alc_build_pcms */
2258 static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
2262 /* NID is set in alc_build_pcms */
2265 static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
2266 .substreams = 2, /* can be overridden */
2269 /* NID is set in alc_build_pcms */
2271 .prepare = alc_alt_capture_pcm_prepare,
2272 .cleanup = alc_alt_capture_pcm_cleanup
2276 static const struct hda_pcm_stream alc_pcm_digital_playback = {
2280 /* NID is set in alc_build_pcms */
2282 .open = alc_dig_playback_pcm_open,
2283 .close = alc_dig_playback_pcm_close,
2284 .prepare = alc_dig_playback_pcm_prepare,
2285 .cleanup = alc_dig_playback_pcm_cleanup
2289 static const struct hda_pcm_stream alc_pcm_digital_capture = {
2293 /* NID is set in alc_build_pcms */
2296 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
2297 static const struct hda_pcm_stream alc_pcm_null_stream = {
2303 static int alc_build_pcms(struct hda_codec *codec)
2305 struct alc_spec *spec = codec->spec;
2306 struct hda_pcm *info = spec->pcm_rec;
2307 const struct hda_pcm_stream *p;
2308 bool have_multi_adcs;
2311 codec->num_pcms = 1;
2312 codec->pcm_info = info;
2314 if (spec->no_analog)
2317 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2318 "%s Analog", codec->chip_name);
2319 info->name = spec->stream_name_analog;
2321 if (spec->multiout.dac_nids > 0) {
2322 p = spec->stream_analog_playback;
2324 p = &alc_pcm_analog_playback;
2325 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2326 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2328 if (spec->adc_nids) {
2329 p = spec->stream_analog_capture;
2331 if (spec->dyn_adc_switch)
2332 p = &dyn_adc_pcm_analog_capture;
2334 p = &alc_pcm_analog_capture;
2336 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2337 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2340 if (spec->channel_mode) {
2341 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2342 for (i = 0; i < spec->num_channel_mode; i++) {
2343 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2344 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2350 /* SPDIF for stream index #1 */
2351 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2352 snprintf(spec->stream_name_digital,
2353 sizeof(spec->stream_name_digital),
2354 "%s Digital", codec->chip_name);
2355 codec->num_pcms = 2;
2356 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
2357 info = spec->pcm_rec + 1;
2358 info->name = spec->stream_name_digital;
2359 if (spec->dig_out_type)
2360 info->pcm_type = spec->dig_out_type;
2362 info->pcm_type = HDA_PCM_TYPE_SPDIF;
2363 if (spec->multiout.dig_out_nid) {
2364 p = spec->stream_digital_playback;
2366 p = &alc_pcm_digital_playback;
2367 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2368 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2370 if (spec->dig_in_nid) {
2371 p = spec->stream_digital_capture;
2373 p = &alc_pcm_digital_capture;
2374 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2375 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2377 /* FIXME: do we need this for all Realtek codec models? */
2378 codec->spdif_status_reset = 1;
2381 if (spec->no_analog)
2384 /* If the use of more than one ADC is requested for the current
2385 * model, configure a second analog capture-only PCM.
2387 have_multi_adcs = (spec->num_adc_nids > 1) &&
2388 !spec->dyn_adc_switch && !spec->auto_mic &&
2389 (!spec->input_mux || spec->input_mux->num_items > 1);
2390 /* Additional Analaog capture for index #2 */
2391 if (spec->alt_dac_nid || have_multi_adcs) {
2392 codec->num_pcms = 3;
2393 info = spec->pcm_rec + 2;
2394 info->name = spec->stream_name_analog;
2395 if (spec->alt_dac_nid) {
2396 p = spec->stream_analog_alt_playback;
2398 p = &alc_pcm_analog_alt_playback;
2399 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2400 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2403 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2404 alc_pcm_null_stream;
2405 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2407 if (have_multi_adcs) {
2408 p = spec->stream_analog_alt_capture;
2410 p = &alc_pcm_analog_alt_capture;
2411 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2412 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2414 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2415 spec->num_adc_nids - 1;
2417 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2418 alc_pcm_null_stream;
2419 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
2426 static inline void alc_shutup(struct hda_codec *codec)
2428 struct alc_spec *spec = codec->spec;
2430 if (spec && spec->shutup)
2431 spec->shutup(codec);
2432 snd_hda_shutup_pins(codec);
2435 static void alc_free_kctls(struct hda_codec *codec)
2437 struct alc_spec *spec = codec->spec;
2439 if (spec->kctls.list) {
2440 struct snd_kcontrol_new *kctl = spec->kctls.list;
2442 for (i = 0; i < spec->kctls.used; i++)
2443 kfree(kctl[i].name);
2445 snd_array_free(&spec->kctls);
2448 static void alc_free_bind_ctls(struct hda_codec *codec)
2450 struct alc_spec *spec = codec->spec;
2451 if (spec->bind_ctls.list) {
2452 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2454 for (i = 0; i < spec->bind_ctls.used; i++)
2457 snd_array_free(&spec->bind_ctls);
2460 static void alc_free(struct hda_codec *codec)
2462 struct alc_spec *spec = codec->spec;
2468 alc_free_kctls(codec);
2469 alc_free_bind_ctls(codec);
2471 snd_hda_detach_beep_device(codec);
2474 #ifdef CONFIG_SND_HDA_POWER_SAVE
2475 static void alc_power_eapd(struct hda_codec *codec)
2477 alc_auto_setup_eapd(codec, false);
2480 static int alc_suspend(struct hda_codec *codec, pm_message_t state)
2482 struct alc_spec *spec = codec->spec;
2484 if (spec && spec->power_hook)
2485 spec->power_hook(codec);
2491 static int alc_resume(struct hda_codec *codec)
2493 msleep(150); /* to avoid pop noise */
2494 codec->patch_ops.init(codec);
2495 snd_hda_codec_resume_amp(codec);
2496 snd_hda_codec_resume_cache(codec);
2497 hda_call_check_power_status(codec, 0x01);
2504 static const struct hda_codec_ops alc_patch_ops = {
2505 .build_controls = alc_build_controls,
2506 .build_pcms = alc_build_pcms,
2509 .unsol_event = alc_unsol_event,
2511 .resume = alc_resume,
2513 #ifdef CONFIG_SND_HDA_POWER_SAVE
2514 .suspend = alc_suspend,
2515 .check_power_status = alc_check_power_status,
2517 .reboot_notify = alc_shutup,
2520 /* replace the codec chip_name with the given string */
2521 static int alc_codec_rename(struct hda_codec *codec, const char *name)
2523 kfree(codec->chip_name);
2524 codec->chip_name = kstrdup(name, GFP_KERNEL);
2525 if (!codec->chip_name) {
2533 * Rename codecs appropriately from COEF value
2535 struct alc_codec_rename_table {
2536 unsigned int vendor_id;
2537 unsigned short coef_mask;
2538 unsigned short coef_bits;
2542 static struct alc_codec_rename_table rename_tbl[] = {
2543 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2544 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2545 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2546 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2547 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2548 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2549 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
2550 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2551 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2552 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2553 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2554 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2555 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2556 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2557 { } /* terminator */
2560 static int alc_codec_rename_from_preset(struct hda_codec *codec)
2562 const struct alc_codec_rename_table *p;
2564 for (p = rename_tbl; p->vendor_id; p++) {
2565 if (p->vendor_id != codec->vendor_id)
2567 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
2568 return alc_codec_rename(codec, p->name);
2574 * Automatic parse of I/O pins from the BIOS configuration
2579 ALC_CTL_WIDGET_MUTE,
2584 static const struct snd_kcontrol_new alc_control_templates[] = {
2585 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2586 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2587 HDA_BIND_MUTE(NULL, 0, 0, 0),
2588 HDA_BIND_VOL(NULL, 0),
2589 HDA_BIND_SW(NULL, 0),
2592 /* add dynamic controls */
2593 static int add_control(struct alc_spec *spec, int type, const char *name,
2594 int cidx, unsigned long val)
2596 struct snd_kcontrol_new *knew;
2598 knew = alc_kcontrol_new(spec);
2601 *knew = alc_control_templates[type];
2602 knew->name = kstrdup(name, GFP_KERNEL);
2606 if (get_amp_nid_(val))
2607 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
2608 knew->private_value = val;
2612 static int add_control_with_pfx(struct alc_spec *spec, int type,
2613 const char *pfx, const char *dir,
2614 const char *sfx, int cidx, unsigned long val)
2617 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
2618 return add_control(spec, type, name, cidx, val);
2621 #define add_pb_vol_ctrl(spec, type, pfx, val) \
2622 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2623 #define add_pb_sw_ctrl(spec, type, pfx, val) \
2624 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2625 #define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2626 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2627 #define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2628 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
2630 static const char * const channel_name[4] = {
2631 "Front", "Surround", "CLFE", "Side"
2634 static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2635 bool can_be_master, int *index)
2637 struct auto_pin_cfg *cfg = &spec->autocfg;
2640 if (cfg->line_outs == 1 && !spec->multi_ios &&
2641 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
2644 switch (cfg->line_out_type) {
2645 case AUTO_PIN_SPEAKER_OUT:
2646 if (cfg->line_outs == 1)
2648 if (cfg->line_outs == 2)
2649 return ch ? "Bass Speaker" : "Speaker";
2651 case AUTO_PIN_HP_OUT:
2652 /* for multi-io case, only the primary out */
2653 if (ch && spec->multi_ios)
2658 if (cfg->line_outs == 1 && !spec->multi_ios)
2662 if (snd_BUG_ON(ch >= ARRAY_SIZE(channel_name)))
2665 return channel_name[ch];
2668 /* create input playback/capture controls for the given pin */
2669 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
2670 const char *ctlname, int ctlidx,
2671 int idx, hda_nid_t mix_nid)
2675 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
2676 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2679 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
2680 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2686 static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
2688 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2689 return (pincap & AC_PINCAP_IN) != 0;
2692 /* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
2693 static int alc_auto_fill_adc_caps(struct hda_codec *codec)
2695 struct alc_spec *spec = codec->spec;
2697 hda_nid_t *adc_nids = spec->private_adc_nids;
2698 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2699 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
2702 if (spec->shared_mic_hp)
2703 max_nums = 1; /* no multi streams with the shared HP/mic */
2705 nid = codec->start_nid;
2706 for (i = 0; i < codec->num_nodes; i++, nid++) {
2708 const hda_nid_t *list;
2709 unsigned int caps = get_wcaps(codec, nid);
2710 int type = get_wcaps_type(caps);
2712 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2714 adc_nids[nums] = nid;
2715 cap_nids[nums] = nid;
2719 type = get_wcaps_type(get_wcaps(codec, src));
2720 if (type == AC_WID_PIN)
2722 if (type == AC_WID_AUD_SEL) {
2723 cap_nids[nums] = src;
2726 n = snd_hda_get_conn_list(codec, src, &list);
2728 cap_nids[nums] = src;
2734 if (++nums >= max_nums)
2737 spec->adc_nids = spec->private_adc_nids;
2738 spec->capsrc_nids = spec->private_capsrc_nids;
2739 spec->num_adc_nids = nums;
2743 /* create playback/capture controls for input pins */
2744 static int alc_auto_create_input_ctls(struct hda_codec *codec)
2746 struct alc_spec *spec = codec->spec;
2747 const struct auto_pin_cfg *cfg = &spec->autocfg;
2748 hda_nid_t mixer = spec->mixer_nid;
2749 struct hda_input_mux *imux = &spec->private_imux[0];
2751 int i, c, err, idx, type_idx = 0;
2752 const char *prev_label = NULL;
2754 num_adcs = alc_auto_fill_adc_caps(codec);
2758 for (i = 0; i < cfg->num_inputs; i++) {
2762 pin = cfg->inputs[i].pin;
2763 if (!alc_is_input_pin(codec, pin))
2766 label = hda_get_autocfg_input_label(codec, cfg, i);
2767 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
2768 label = "Headphone Mic";
2769 if (prev_label && !strcmp(label, prev_label))
2776 idx = get_connection_index(codec, mixer, pin);
2778 err = new_analog_input(spec, pin,
2786 for (c = 0; c < num_adcs; c++) {
2787 hda_nid_t cap = get_capsrc(spec, c);
2788 idx = get_connection_index(codec, cap, pin);
2790 spec->imux_pins[imux->num_items] = pin;
2791 snd_hda_add_imux_item(imux, label, idx, NULL);
2797 spec->num_mux_defs = 1;
2798 spec->input_mux = imux;
2803 /* create a shared input with the headphone out */
2804 static int alc_auto_create_shared_input(struct hda_codec *codec)
2806 struct alc_spec *spec = codec->spec;
2807 struct auto_pin_cfg *cfg = &spec->autocfg;
2808 unsigned int defcfg;
2811 /* only one internal input pin? */
2812 if (cfg->num_inputs != 1)
2814 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2815 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2818 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
2819 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
2820 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
2821 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
2823 return 0; /* both not available */
2825 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2826 return 0; /* no input */
2828 cfg->inputs[1].pin = nid;
2829 cfg->inputs[1].type = AUTO_PIN_MIC;
2830 cfg->num_inputs = 2;
2831 spec->shared_mic_hp = 1;
2832 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
2836 static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
2837 unsigned int pin_type)
2839 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2842 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2843 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2847 static int get_pin_type(int line_out_type)
2849 if (line_out_type == AUTO_PIN_HP_OUT)
2855 static void alc_auto_init_analog_input(struct hda_codec *codec)
2857 struct alc_spec *spec = codec->spec;
2858 struct auto_pin_cfg *cfg = &spec->autocfg;
2861 for (i = 0; i < cfg->num_inputs; i++) {
2862 hda_nid_t nid = cfg->inputs[i].pin;
2863 if (alc_is_input_pin(codec, nid)) {
2864 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
2865 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
2866 snd_hda_codec_write(codec, nid, 0,
2867 AC_VERB_SET_AMP_GAIN_MUTE,
2872 /* mute all loopback inputs */
2873 if (spec->mixer_nid) {
2874 int nums = snd_hda_get_conn_list(codec, spec->mixer_nid, NULL);
2875 for (i = 0; i < nums; i++)
2876 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2877 AC_VERB_SET_AMP_GAIN_MUTE,
2882 /* convert from MIX nid to DAC */
2883 static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid)
2888 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT)
2890 num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list));
2891 for (i = 0; i < num; i++) {
2892 if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT)
2898 /* go down to the selector widget before the mixer */
2899 static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin)
2902 int num = snd_hda_get_connections(codec, pin, srcs,
2905 get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL)
2910 /* get MIX nid connected to the given pin targeted to DAC */
2911 static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
2917 pin = alc_go_down_to_selector(codec, pin);
2918 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2919 for (i = 0; i < num; i++) {
2920 if (alc_auto_mix_to_dac(codec, mix[i]) == dac)
2926 /* select the connection from pin to DAC if needed */
2927 static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin,
2933 pin = alc_go_down_to_selector(codec, pin);
2934 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2937 for (i = 0; i < num; i++) {
2938 if (alc_auto_mix_to_dac(codec, mix[i]) == dac) {
2939 snd_hda_codec_update_cache(codec, pin, 0,
2940 AC_VERB_SET_CONNECT_SEL, i);
2947 /* look for an empty DAC slot */
2948 static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
2950 struct alc_spec *spec = codec->spec;
2954 pin = alc_go_down_to_selector(codec, pin);
2955 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
2956 for (i = 0; i < num; i++) {
2957 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
2960 if (found_in_nid_list(nid, spec->multiout.dac_nids,
2961 ARRAY_SIZE(spec->private_dac_nids)))
2963 if (found_in_nid_list(nid, spec->multiout.hp_out_nid,
2964 ARRAY_SIZE(spec->multiout.hp_out_nid)))
2966 if (found_in_nid_list(nid, spec->multiout.extra_out_nid,
2967 ARRAY_SIZE(spec->multiout.extra_out_nid)))
2974 /* check whether the DAC is reachable from the pin */
2975 static bool alc_auto_is_dac_reachable(struct hda_codec *codec,
2976 hda_nid_t pin, hda_nid_t dac)
2981 pin = alc_go_down_to_selector(codec, pin);
2982 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
2983 for (i = 0; i < num; i++) {
2984 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
2991 static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
2993 hda_nid_t sel = alc_go_down_to_selector(codec, pin);
2994 if (snd_hda_get_conn_list(codec, sel, NULL) == 1)
2995 return alc_auto_look_for_dac(codec, pin);
2999 /* return 0 if no possible DAC is found, 1 if one or more found */
3000 static int alc_auto_fill_extra_dacs(struct hda_codec *codec, int num_outs,
3001 const hda_nid_t *pins, hda_nid_t *dacs)
3005 if (num_outs && !dacs[0]) {
3006 dacs[0] = alc_auto_look_for_dac(codec, pins[0]);
3011 for (i = 1; i < num_outs; i++)
3012 dacs[i] = get_dac_if_single(codec, pins[i]);
3013 for (i = 1; i < num_outs; i++) {
3015 dacs[i] = alc_auto_look_for_dac(codec, pins[i]);
3020 static int alc_auto_fill_multi_ios(struct hda_codec *codec,
3021 unsigned int location, int offset);
3022 static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3023 hda_nid_t pin, hda_nid_t dac);
3025 /* fill in the dac_nids table from the parsed pin configuration */
3026 static int alc_auto_fill_dac_nids(struct hda_codec *codec)
3028 struct alc_spec *spec = codec->spec;
3029 struct auto_pin_cfg *cfg = &spec->autocfg;
3030 unsigned int location, defcfg;
3032 bool redone = false;
3036 /* set num_dacs once to full for alc_auto_look_for_dac() */
3037 spec->multiout.num_dacs = cfg->line_outs;
3038 spec->multiout.hp_out_nid[0] = 0;
3039 spec->multiout.extra_out_nid[0] = 0;
3040 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
3041 spec->multiout.dac_nids = spec->private_dac_nids;
3042 spec->multi_ios = 0;
3044 /* fill hard-wired DACs first */
3046 for (i = 0; i < cfg->line_outs; i++)
3047 spec->private_dac_nids[i] =
3048 get_dac_if_single(codec, cfg->line_out_pins[i]);
3050 spec->multiout.hp_out_nid[0] =
3051 get_dac_if_single(codec, cfg->hp_pins[0]);
3052 if (cfg->speaker_outs)
3053 spec->multiout.extra_out_nid[0] =
3054 get_dac_if_single(codec, cfg->speaker_pins[0]);
3057 for (i = 0; i < cfg->line_outs; i++) {
3058 hda_nid_t pin = cfg->line_out_pins[i];
3059 if (spec->private_dac_nids[i])
3061 spec->private_dac_nids[i] = alc_auto_look_for_dac(codec, pin);
3062 if (!spec->private_dac_nids[i] && !redone) {
3063 /* if we can't find primary DACs, re-probe without
3064 * checking the hard-wired DACs
3071 /* re-count num_dacs and squash invalid entries */
3072 spec->multiout.num_dacs = 0;
3073 for (i = 0; i < cfg->line_outs; i++) {
3074 if (spec->private_dac_nids[i])
3075 spec->multiout.num_dacs++;
3077 memmove(spec->private_dac_nids + i,
3078 spec->private_dac_nids + i + 1,
3079 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
3080 spec->private_dac_nids[cfg->line_outs - 1] = 0;
3084 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3085 /* try to fill multi-io first */
3086 defcfg = snd_hda_codec_get_pincfg(codec, cfg->line_out_pins[0]);
3087 location = get_defcfg_location(defcfg);
3089 num_pins = alc_auto_fill_multi_ios(codec, location, 0);
3091 spec->multi_ios = num_pins;
3092 spec->ext_channel_count = 2;
3093 spec->multiout.num_dacs = num_pins + 1;
3097 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
3098 alc_auto_fill_extra_dacs(codec, cfg->hp_outs, cfg->hp_pins,
3099 spec->multiout.hp_out_nid);
3100 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3101 int err = alc_auto_fill_extra_dacs(codec, cfg->speaker_outs,
3103 spec->multiout.extra_out_nid);
3104 /* if no speaker volume is assigned, try again as the primary
3107 if (!err && cfg->speaker_outs > 0 &&
3108 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3109 cfg->hp_outs = cfg->line_outs;
3110 memcpy(cfg->hp_pins, cfg->line_out_pins,
3111 sizeof(cfg->hp_pins));
3112 cfg->line_outs = cfg->speaker_outs;
3113 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3114 sizeof(cfg->speaker_pins));
3115 cfg->speaker_outs = 0;
3116 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3117 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
3123 if (!spec->multi_ios &&
3124 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
3126 /* try multi-ios with HP + inputs */
3127 defcfg = snd_hda_codec_get_pincfg(codec, cfg->hp_pins[0]);
3128 location = get_defcfg_location(defcfg);
3130 num_pins = alc_auto_fill_multi_ios(codec, location, 1);
3132 spec->multi_ios = num_pins;
3133 spec->ext_channel_count = 2;
3134 spec->multiout.num_dacs = num_pins + 1;
3138 if (cfg->line_out_pins[0])
3140 alc_look_for_out_vol_nid(codec, cfg->line_out_pins[0],
3141 spec->multiout.dac_nids[0]);
3145 static inline unsigned int get_ctl_pos(unsigned int data)
3147 hda_nid_t nid = get_amp_nid_(data);
3148 unsigned int dir = get_amp_direction_(data);
3149 return (nid << 1) | dir;
3152 #define is_ctl_used(bits, data) \
3153 test_bit(get_ctl_pos(data), bits)
3154 #define mark_ctl_usage(bits, data) \
3155 set_bit(get_ctl_pos(data), bits)
3157 static int alc_auto_add_vol_ctl(struct hda_codec *codec,
3158 const char *pfx, int cidx,
3159 hda_nid_t nid, unsigned int chs)
3161 struct alc_spec *spec = codec->spec;
3165 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3166 if (is_ctl_used(spec->vol_ctls, val) && chs != 2) /* exclude LFE */
3168 mark_ctl_usage(spec->vol_ctls, val);
3169 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
3173 static int alc_auto_add_stereo_vol(struct hda_codec *codec,
3174 const char *pfx, int cidx,
3178 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3180 return alc_auto_add_vol_ctl(codec, pfx, cidx, nid, chs);
3183 /* create a mute-switch for the given mixer widget;
3184 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3186 static int alc_auto_add_sw_ctl(struct hda_codec *codec,
3187 const char *pfx, int cidx,
3188 hda_nid_t nid, unsigned int chs)
3190 struct alc_spec *spec = codec->spec;
3196 wid_type = get_wcaps_type(get_wcaps(codec, nid));
3197 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) {
3198 type = ALC_CTL_WIDGET_MUTE;
3199 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3200 } else if (snd_hda_get_conn_list(codec, nid, NULL) == 1) {
3201 type = ALC_CTL_WIDGET_MUTE;
3202 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
3204 type = ALC_CTL_BIND_MUTE;
3205 val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
3207 if (is_ctl_used(spec->sw_ctls, val) && chs != 2) /* exclude LFE */
3209 mark_ctl_usage(spec->sw_ctls, val);
3210 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
3213 static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
3214 int cidx, hda_nid_t nid)
3217 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3219 return alc_auto_add_sw_ctl(codec, pfx, cidx, nid, chs);
3222 static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3223 hda_nid_t pin, hda_nid_t dac)
3225 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3226 if (nid_has_mute(codec, pin, HDA_OUTPUT))
3228 else if (mix && nid_has_mute(codec, mix, HDA_INPUT))
3230 else if (nid_has_mute(codec, dac, HDA_OUTPUT))
3235 static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3236 hda_nid_t pin, hda_nid_t dac)
3238 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3239 if (nid_has_volume(codec, dac, HDA_OUTPUT))
3241 else if (nid_has_volume(codec, mix, HDA_OUTPUT))
3243 else if (nid_has_volume(codec, pin, HDA_OUTPUT))
3248 /* add playback controls from the parsed DAC table */
3249 static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
3250 const struct auto_pin_cfg *cfg)
3252 struct alc_spec *spec = codec->spec;
3253 int i, err, noutputs;
3255 noutputs = cfg->line_outs;
3256 if (spec->multi_ios > 0 && cfg->line_outs < 3)
3257 noutputs += spec->multi_ios;
3259 for (i = 0; i < noutputs; i++) {
3265 dac = spec->multiout.dac_nids[i];
3268 if (i >= cfg->line_outs)
3269 pin = spec->multi_io[i - 1].pin;
3271 pin = cfg->line_out_pins[i];
3273 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3274 vol = alc_look_for_out_vol_nid(codec, pin, dac);
3275 name = alc_get_line_out_pfx(spec, i, true, &index);
3276 if (!name || !strcmp(name, "CLFE")) {
3278 err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1);
3281 err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2);
3284 err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1);
3287 err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2);
3291 err = alc_auto_add_stereo_vol(codec, name, index, vol);
3294 err = alc_auto_add_stereo_sw(codec, name, index, sw);
3302 static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
3303 hda_nid_t dac, const char *pfx,
3306 struct alc_spec *spec = codec->spec;
3312 /* the corresponding DAC is already occupied */
3313 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
3314 return 0; /* no way */
3315 /* create a switch only */
3316 val = HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT);
3317 if (is_ctl_used(spec->sw_ctls, val))
3318 return 0; /* already created */
3319 mark_ctl_usage(spec->sw_ctls, val);
3320 return __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, cidx, val);
3323 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3324 vol = alc_look_for_out_vol_nid(codec, pin, dac);
3325 err = alc_auto_add_stereo_vol(codec, pfx, cidx, vol);
3328 err = alc_auto_add_stereo_sw(codec, pfx, cidx, sw);
3334 static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3336 struct hda_ctl_ops *ops)
3338 struct alc_spec *spec = codec->spec;
3339 struct hda_bind_ctls **ctlp, *ctl;
3340 snd_array_init(&spec->bind_ctls, sizeof(ctl), 8);
3341 ctlp = snd_array_new(&spec->bind_ctls);
3344 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3351 /* add playback controls for speaker and HP outputs */
3352 static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3353 const hda_nid_t *pins,
3354 const hda_nid_t *dacs,
3357 struct alc_spec *spec = codec->spec;
3358 struct hda_bind_ctls *ctl;
3362 if (!num_pins || !pins[0])
3365 if (num_pins == 1) {
3366 hda_nid_t dac = *dacs;
3368 dac = spec->multiout.dac_nids[0];
3369 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
3372 if (dacs[num_pins - 1]) {
3373 /* OK, we have a multi-output system with individual volumes */
3374 for (i = 0; i < num_pins; i++) {
3375 if (num_pins >= 3) {
3376 snprintf(name, sizeof(name), "%s %s",
3377 pfx, channel_name[i]);
3378 err = alc_auto_create_extra_out(codec, pins[i], dacs[i],
3381 err = alc_auto_create_extra_out(codec, pins[i], dacs[i],
3390 /* Let's create a bind-controls */
3391 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_sw);
3395 for (i = 0; i < num_pins; i++) {
3396 if (get_wcaps(codec, pins[i]) & AC_WCAP_OUT_AMP)
3398 HDA_COMPOSE_AMP_VAL(pins[i], 3, 0, HDA_OUTPUT);
3401 snprintf(name, sizeof(name), "%s Playback Switch", pfx);
3402 err = add_control(spec, ALC_CTL_BIND_SW, name, 0, (long)ctl);
3407 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3411 for (i = 0; i < num_pins; i++) {
3413 if (!pins[i] || !dacs[i])
3415 vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]);
3418 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3421 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3422 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3429 static int alc_auto_create_hp_out(struct hda_codec *codec)
3431 struct alc_spec *spec = codec->spec;
3432 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3433 spec->autocfg.hp_pins,
3434 spec->multiout.hp_out_nid,
3438 static int alc_auto_create_speaker_out(struct hda_codec *codec)
3440 struct alc_spec *spec = codec->spec;
3441 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3442 spec->autocfg.speaker_pins,
3443 spec->multiout.extra_out_nid,
3447 static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
3448 hda_nid_t pin, int pin_type,
3452 hda_nid_t nid, mix = 0;
3453 hda_nid_t srcs[HDA_MAX_CONNECTIONS];
3455 alc_set_pin_output(codec, pin, pin_type);
3456 nid = alc_go_down_to_selector(codec, pin);
3457 num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
3458 for (i = 0; i < num; i++) {
3459 if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
3467 /* need the manual connection? */
3469 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
3470 /* unmute mixer widget inputs */
3471 if (nid_has_mute(codec, mix, HDA_INPUT)) {
3472 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3474 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3477 /* initialize volume */
3478 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3480 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3483 /* unmute DAC if it's not assigned to a mixer */
3484 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3485 if (nid == mix && nid_has_mute(codec, dac, HDA_OUTPUT))
3486 snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3490 static void alc_auto_init_multi_out(struct hda_codec *codec)
3492 struct alc_spec *spec = codec->spec;
3493 int pin_type = get_pin_type(spec->autocfg.line_out_type);
3496 for (i = 0; i <= HDA_SIDE; i++) {
3497 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3499 alc_auto_set_output_and_unmute(codec, nid, pin_type,
3500 spec->multiout.dac_nids[i]);
3504 static void alc_auto_init_extra_out(struct hda_codec *codec)
3506 struct alc_spec *spec = codec->spec;
3510 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3511 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3513 pin = spec->autocfg.hp_pins[i];
3516 dac = spec->multiout.hp_out_nid[i];
3518 if (i > 0 && spec->multiout.hp_out_nid[0])
3519 dac = spec->multiout.hp_out_nid[0];
3521 dac = spec->multiout.dac_nids[0];
3523 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
3525 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3526 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3528 pin = spec->autocfg.speaker_pins[i];
3531 dac = spec->multiout.extra_out_nid[i];
3533 if (i > 0 && spec->multiout.extra_out_nid[0])
3534 dac = spec->multiout.extra_out_nid[0];
3536 dac = spec->multiout.dac_nids[0];
3538 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
3545 static int alc_auto_fill_multi_ios(struct hda_codec *codec,
3546 unsigned int location,
3549 struct alc_spec *spec = codec->spec;
3550 struct auto_pin_cfg *cfg = &spec->autocfg;
3551 hda_nid_t prime_dac = spec->private_dac_nids[0];
3552 int type, i, dacs, num_pins = 0;
3554 dacs = spec->multiout.num_dacs;
3555 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3556 for (i = 0; i < cfg->num_inputs; i++) {
3557 hda_nid_t nid = cfg->inputs[i].pin;
3559 unsigned int defcfg, caps;
3560 if (cfg->inputs[i].type != type)
3562 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3563 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3565 if (location && get_defcfg_location(defcfg) != location)
3567 caps = snd_hda_query_pin_caps(codec, nid);
3568 if (!(caps & AC_PINCAP_OUT))
3570 if (offset && offset + num_pins < dacs) {
3571 dac = spec->private_dac_nids[offset + num_pins];
3572 if (!alc_auto_is_dac_reachable(codec, nid, dac))
3576 dac = alc_auto_look_for_dac(codec, nid);
3579 spec->multi_io[num_pins].pin = nid;
3580 spec->multi_io[num_pins].dac = dac;
3582 spec->private_dac_nids[spec->multiout.num_dacs++] = dac;
3585 spec->multiout.num_dacs = dacs;
3587 /* clear up again */
3588 memset(spec->private_dac_nids + dacs, 0,
3589 sizeof(hda_nid_t) * (AUTO_CFG_MAX_OUTS - dacs));
3590 spec->private_dac_nids[0] = prime_dac;
3596 static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
3597 struct snd_ctl_elem_info *uinfo)
3599 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3600 struct alc_spec *spec = codec->spec;
3602 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3604 uinfo->value.enumerated.items = spec->multi_ios + 1;
3605 if (uinfo->value.enumerated.item > spec->multi_ios)
3606 uinfo->value.enumerated.item = spec->multi_ios;
3607 sprintf(uinfo->value.enumerated.name, "%dch",
3608 (uinfo->value.enumerated.item + 1) * 2);
3612 static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
3613 struct snd_ctl_elem_value *ucontrol)
3615 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3616 struct alc_spec *spec = codec->spec;
3617 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
3621 static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
3623 struct alc_spec *spec = codec->spec;
3624 hda_nid_t nid = spec->multi_io[idx].pin;
3626 if (!spec->multi_io[idx].ctl_in)
3627 spec->multi_io[idx].ctl_in =
3628 snd_hda_codec_read(codec, nid, 0,
3629 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3631 snd_hda_codec_update_cache(codec, nid, 0,
3632 AC_VERB_SET_PIN_WIDGET_CONTROL,
3634 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3635 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3637 alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
3639 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3640 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3641 HDA_AMP_MUTE, HDA_AMP_MUTE);
3642 snd_hda_codec_update_cache(codec, nid, 0,
3643 AC_VERB_SET_PIN_WIDGET_CONTROL,
3644 spec->multi_io[idx].ctl_in);
3649 static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
3650 struct snd_ctl_elem_value *ucontrol)
3652 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3653 struct alc_spec *spec = codec->spec;
3656 ch = ucontrol->value.enumerated.item[0];
3657 if (ch < 0 || ch > spec->multi_ios)
3659 if (ch == (spec->ext_channel_count - 1) / 2)
3661 spec->ext_channel_count = (ch + 1) * 2;
3662 for (i = 0; i < spec->multi_ios; i++)
3663 alc_set_multi_io(codec, i, i < ch);
3664 spec->multiout.max_channels = spec->ext_channel_count;
3665 if (spec->need_dac_fix && !spec->const_channel_count)
3666 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
3670 static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
3671 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3672 .name = "Channel Mode",
3673 .info = alc_auto_ch_mode_info,
3674 .get = alc_auto_ch_mode_get,
3675 .put = alc_auto_ch_mode_put,
3678 static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
3680 struct alc_spec *spec = codec->spec;
3682 if (spec->multi_ios > 0) {
3683 struct snd_kcontrol_new *knew;
3685 knew = alc_kcontrol_new(spec);
3688 *knew = alc_auto_channel_mode_enum;
3689 knew->name = kstrdup("Channel Mode", GFP_KERNEL);
3696 /* filter out invalid adc_nids (and capsrc_nids) that don't give all
3699 static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
3701 struct alc_spec *spec = codec->spec;
3702 const struct hda_input_mux *imux;
3703 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3704 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3707 imux = spec->input_mux;
3710 if (spec->dyn_adc_switch)
3714 for (n = 0; n < spec->num_adc_nids; n++) {
3715 hda_nid_t cap = spec->private_capsrc_nids[n];
3716 int num_conns = snd_hda_get_conn_list(codec, cap, NULL);
3717 for (i = 0; i < imux->num_items; i++) {
3718 hda_nid_t pin = spec->imux_pins[i];
3720 if (get_connection_index(codec, cap, pin) < 0)
3722 } else if (num_conns <= imux->items[i].index)
3725 if (i >= imux->num_items) {
3726 adc_nids[nums] = spec->private_adc_nids[n];
3727 capsrc_nids[nums++] = cap;
3731 /* check whether ADC-switch is possible */
3732 if (!alc_check_dyn_adc_switch(codec)) {
3733 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
3734 " using fallback 0x%x\n",
3735 codec->chip_name, spec->private_adc_nids[0]);
3736 spec->num_adc_nids = 1;
3740 } else if (nums != spec->num_adc_nids) {
3741 memcpy(spec->private_adc_nids, adc_nids,
3742 nums * sizeof(hda_nid_t));
3743 memcpy(spec->private_capsrc_nids, capsrc_nids,
3744 nums * sizeof(hda_nid_t));
3745 spec->num_adc_nids = nums;
3749 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
3750 else if (spec->input_mux->num_items == 1)
3751 spec->num_adc_nids = 1; /* reduce to a single ADC */
3755 * initialize ADC paths
3757 static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
3759 struct alc_spec *spec = codec->spec;
3762 nid = spec->adc_nids[adc_idx];
3764 if (nid_has_mute(codec, nid, HDA_INPUT)) {
3765 snd_hda_codec_write(codec, nid, 0,
3766 AC_VERB_SET_AMP_GAIN_MUTE,
3770 if (!spec->capsrc_nids)
3772 nid = spec->capsrc_nids[adc_idx];
3773 if (nid_has_mute(codec, nid, HDA_OUTPUT))
3774 snd_hda_codec_write(codec, nid, 0,
3775 AC_VERB_SET_AMP_GAIN_MUTE,
3779 static void alc_auto_init_input_src(struct hda_codec *codec)
3781 struct alc_spec *spec = codec->spec;
3784 for (c = 0; c < spec->num_adc_nids; c++)
3785 alc_auto_init_adc(codec, c);
3786 if (spec->dyn_adc_switch)
3789 nums = spec->num_adc_nids;
3790 for (c = 0; c < nums; c++)
3791 alc_mux_select(codec, 0, spec->cur_mux[c], true);
3794 /* add mic boosts if needed */
3795 static int alc_auto_add_mic_boost(struct hda_codec *codec)
3797 struct alc_spec *spec = codec->spec;
3798 struct auto_pin_cfg *cfg = &spec->autocfg;
3802 const char *prev_label = NULL;
3804 for (i = 0; i < cfg->num_inputs; i++) {
3805 if (cfg->inputs[i].type > AUTO_PIN_MIC)
3807 nid = cfg->inputs[i].pin;
3808 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
3810 char boost_label[32];
3812 label = hda_get_autocfg_input_label(codec, cfg, i);
3813 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
3814 label = "Headphone Mic";
3815 if (prev_label && !strcmp(label, prev_label))
3821 snprintf(boost_label, sizeof(boost_label),
3822 "%s Boost Volume", label);
3823 err = add_control(spec, ALC_CTL_WIDGET_VOL,
3824 boost_label, type_idx,
3825 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
3833 /* select or unmute the given capsrc route */
3834 static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
3837 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
3838 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
3840 } else if (snd_hda_get_conn_list(codec, cap, NULL) > 1) {
3841 snd_hda_codec_write_cache(codec, cap, 0,
3842 AC_VERB_SET_CONNECT_SEL, idx);
3846 /* set the default connection to that pin */
3847 static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
3849 struct alc_spec *spec = codec->spec;
3854 for (i = 0; i < spec->num_adc_nids; i++) {
3855 hda_nid_t cap = get_capsrc(spec, i);
3858 idx = get_connection_index(codec, cap, pin);
3861 select_or_unmute_capsrc(codec, cap, idx);
3862 return i; /* return the found index */
3864 return -1; /* not found */
3867 /* initialize some special cases for input sources */
3868 static void alc_init_special_input_src(struct hda_codec *codec)
3870 struct alc_spec *spec = codec->spec;
3873 for (i = 0; i < spec->autocfg.num_inputs; i++)
3874 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
3877 /* assign appropriate capture mixers */
3878 static void set_capture_mixer(struct hda_codec *codec)
3880 struct alc_spec *spec = codec->spec;
3881 static const struct snd_kcontrol_new *caps[2][3] = {
3882 { alc_capture_mixer_nosrc1,
3883 alc_capture_mixer_nosrc2,
3884 alc_capture_mixer_nosrc3 },
3885 { alc_capture_mixer1,
3887 alc_capture_mixer3 },
3890 /* check whether either of ADC or MUX has a volume control */
3891 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
3892 if (!spec->capsrc_nids)
3893 return; /* no volume */
3894 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
3895 return; /* no volume in capsrc, too */
3896 spec->vol_in_capsrc = 1;
3899 if (spec->num_adc_nids > 0) {
3903 if (spec->input_mux && spec->input_mux->num_items > 1)
3905 if (spec->auto_mic) {
3908 } else if (spec->dyn_adc_switch)
3911 if (spec->num_adc_nids > 3)
3912 spec->num_adc_nids = 3;
3913 else if (!spec->num_adc_nids)
3915 num_adcs = spec->num_adc_nids;
3917 spec->cap_mixer = caps[mux][num_adcs - 1];
3922 * standard auto-parser initializations
3924 static void alc_auto_init_std(struct hda_codec *codec)
3926 struct alc_spec *spec = codec->spec;
3927 alc_auto_init_multi_out(codec);
3928 alc_auto_init_extra_out(codec);
3929 alc_auto_init_analog_input(codec);
3930 alc_auto_init_input_src(codec);
3931 alc_auto_init_digital(codec);
3932 if (spec->unsol_event)
3933 alc_inithook(codec);
3937 * Digital-beep handlers
3939 #ifdef CONFIG_SND_HDA_INPUT_BEEP
3940 #define set_beep_amp(spec, nid, idx, dir) \
3941 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
3943 static const struct snd_pci_quirk beep_white_list[] = {
3944 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
3945 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
3946 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
3947 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
3948 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
3952 static inline int has_cdefine_beep(struct hda_codec *codec)
3954 struct alc_spec *spec = codec->spec;
3955 const struct snd_pci_quirk *q;
3956 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
3959 return spec->cdefine.enable_pcbeep;
3962 #define set_beep_amp(spec, nid, idx, dir) /* NOP */
3963 #define has_cdefine_beep(codec) 0
3966 /* parse the BIOS configuration and set up the alc_spec */
3967 /* return 1 if successful, 0 if the proper config is not found,
3968 * or a negative error code
3970 static int alc_parse_auto_config(struct hda_codec *codec,
3971 const hda_nid_t *ignore_nids,
3972 const hda_nid_t *ssid_nids)
3974 struct alc_spec *spec = codec->spec;
3975 struct auto_pin_cfg *cfg = &spec->autocfg;
3978 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
3982 if (!cfg->line_outs) {
3983 if (cfg->dig_outs || cfg->dig_in_pin) {
3984 spec->multiout.max_channels = 2;
3985 spec->no_analog = 1;
3988 return 0; /* can't find valid BIOS pin config */
3991 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
3992 cfg->line_outs <= cfg->hp_outs) {
3993 /* use HP as primary out */
3994 cfg->speaker_outs = cfg->line_outs;
3995 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3996 sizeof(cfg->speaker_pins));
3997 cfg->line_outs = cfg->hp_outs;
3998 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
4000 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
4001 cfg->line_out_type = AUTO_PIN_HP_OUT;
4004 err = alc_auto_fill_dac_nids(codec);
4007 err = alc_auto_add_multi_channel_mode(codec);
4010 err = alc_auto_create_multi_out_ctls(codec, cfg);
4013 err = alc_auto_create_hp_out(codec);
4016 err = alc_auto_create_speaker_out(codec);
4019 err = alc_auto_create_shared_input(codec);
4022 err = alc_auto_create_input_ctls(codec);
4026 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4029 alc_auto_parse_digital(codec);
4031 if (!spec->no_analog)
4032 alc_remove_invalid_adc_nids(codec);
4035 alc_ssid_check(codec, ssid_nids);
4037 if (!spec->no_analog) {
4038 alc_auto_check_switches(codec);
4039 err = alc_auto_add_mic_boost(codec);
4044 if (spec->kctls.list)
4045 add_mixer(spec, spec->kctls.list);
4050 static int alc880_parse_auto_config(struct hda_codec *codec)
4052 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
4053 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4054 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
4057 #ifdef CONFIG_SND_HDA_POWER_SAVE
4058 static const struct hda_amp_list alc880_loopbacks[] = {
4059 { 0x0b, HDA_INPUT, 0 },
4060 { 0x0b, HDA_INPUT, 1 },
4061 { 0x0b, HDA_INPUT, 2 },
4062 { 0x0b, HDA_INPUT, 3 },
4063 { 0x0b, HDA_INPUT, 4 },
4073 ALC880_FIXUP_MEDION_RIM,
4076 static const struct alc_fixup alc880_fixups[] = {
4077 [ALC880_FIXUP_GPIO2] = {
4078 .type = ALC_FIXUP_VERBS,
4079 .v.verbs = alc_gpio2_init_verbs,
4081 [ALC880_FIXUP_MEDION_RIM] = {
4082 .type = ALC_FIXUP_VERBS,
4083 .v.verbs = (const struct hda_verb[]) {
4084 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4085 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4089 .chain_id = ALC880_FIXUP_GPIO2,
4093 static const struct snd_pci_quirk alc880_fixup_tbl[] = {
4094 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
4102 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4103 #define alc_board_config \
4104 snd_hda_check_board_config
4105 #define alc_board_codec_sid_config \
4106 snd_hda_check_board_codec_sid_config
4107 #include "alc_quirks.c"
4109 #define alc_board_config(codec, nums, models, tbl) -1
4110 #define alc_board_codec_sid_config(codec, nums, models, tbl) -1
4111 #define setup_preset(codec, x) /* NOP */
4115 * OK, here we have finally the patch for ALC880
4117 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4118 #include "alc880_quirks.c"
4121 static int patch_alc880(struct hda_codec *codec)
4123 struct alc_spec *spec;
4127 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4133 spec->mixer_nid = 0x0b;
4134 spec->need_dac_fix = 1;
4136 board_config = alc_board_config(codec, ALC880_MODEL_LAST,
4137 alc880_models, alc880_cfg_tbl);
4138 if (board_config < 0) {
4139 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4141 board_config = ALC_MODEL_AUTO;
4144 if (board_config == ALC_MODEL_AUTO) {
4145 alc_pick_fixup(codec, NULL, alc880_fixup_tbl, alc880_fixups);
4146 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4149 if (board_config == ALC_MODEL_AUTO) {
4150 /* automatic parse from the BIOS config */
4151 err = alc880_parse_auto_config(codec);
4154 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4157 "hda_codec: Cannot set up configuration "
4158 "from BIOS. Using 3-stack mode...\n");
4159 board_config = ALC880_3ST;
4164 if (board_config != ALC_MODEL_AUTO) {
4165 spec->vmaster_nid = 0x0c;
4166 setup_preset(codec, &alc880_presets[board_config]);
4169 if (!spec->no_analog && !spec->adc_nids) {
4170 alc_auto_fill_adc_caps(codec);
4171 alc_rebuild_imux_for_auto_mic(codec);
4172 alc_remove_invalid_adc_nids(codec);
4175 if (!spec->no_analog && !spec->cap_mixer)
4176 set_capture_mixer(codec);
4178 if (!spec->no_analog) {
4179 err = snd_hda_attach_beep_device(codec, 0x1);
4182 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4185 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4187 codec->patch_ops = alc_patch_ops;
4188 if (board_config == ALC_MODEL_AUTO)
4189 spec->init_hook = alc_auto_init_std;
4191 codec->patch_ops.build_controls = __alc_build_controls;
4192 #ifdef CONFIG_SND_HDA_POWER_SAVE
4193 if (!spec->loopback.amplist)
4194 spec->loopback.amplist = alc880_loopbacks;
4208 static int alc260_parse_auto_config(struct hda_codec *codec)
4210 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
4211 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
4212 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
4215 #ifdef CONFIG_SND_HDA_POWER_SAVE
4216 static const struct hda_amp_list alc260_loopbacks[] = {
4217 { 0x07, HDA_INPUT, 0 },
4218 { 0x07, HDA_INPUT, 1 },
4219 { 0x07, HDA_INPUT, 2 },
4220 { 0x07, HDA_INPUT, 3 },
4221 { 0x07, HDA_INPUT, 4 },
4233 static const struct alc_fixup alc260_fixups[] = {
4234 [PINFIX_HP_DC5750] = {
4235 .type = ALC_FIXUP_PINS,
4236 .v.pins = (const struct alc_pincfg[]) {
4237 { 0x11, 0x90130110 }, /* speaker */
4243 static const struct snd_pci_quirk alc260_fixup_tbl[] = {
4244 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", PINFIX_HP_DC5750),
4250 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4251 #include "alc260_quirks.c"
4254 static int patch_alc260(struct hda_codec *codec)
4256 struct alc_spec *spec;
4257 int err, board_config;
4259 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4265 spec->mixer_nid = 0x07;
4267 board_config = alc_board_config(codec, ALC260_MODEL_LAST,
4268 alc260_models, alc260_cfg_tbl);
4269 if (board_config < 0) {
4270 snd_printd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4272 board_config = ALC_MODEL_AUTO;
4275 if (board_config == ALC_MODEL_AUTO) {
4276 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
4277 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4280 if (board_config == ALC_MODEL_AUTO) {
4281 /* automatic parse from the BIOS config */
4282 err = alc260_parse_auto_config(codec);
4285 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4288 "hda_codec: Cannot set up configuration "
4289 "from BIOS. Using base mode...\n");
4290 board_config = ALC260_BASIC;
4295 if (board_config != ALC_MODEL_AUTO) {
4296 setup_preset(codec, &alc260_presets[board_config]);
4297 spec->vmaster_nid = 0x08;
4300 if (!spec->no_analog && !spec->adc_nids) {
4301 alc_auto_fill_adc_caps(codec);
4302 alc_rebuild_imux_for_auto_mic(codec);
4303 alc_remove_invalid_adc_nids(codec);
4306 if (!spec->no_analog && !spec->cap_mixer)
4307 set_capture_mixer(codec);
4309 if (!spec->no_analog) {
4310 err = snd_hda_attach_beep_device(codec, 0x1);
4313 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
4316 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4318 codec->patch_ops = alc_patch_ops;
4319 if (board_config == ALC_MODEL_AUTO)
4320 spec->init_hook = alc_auto_init_std;
4322 codec->patch_ops.build_controls = __alc_build_controls;
4323 spec->shutup = alc_eapd_shutup;
4324 #ifdef CONFIG_SND_HDA_POWER_SAVE
4325 if (!spec->loopback.amplist)
4326 spec->loopback.amplist = alc260_loopbacks;
4338 * ALC882/883/885/888/889 support
4340 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
4341 * configuration. Each pin widget can choose any input DACs and a mixer.
4342 * Each ADC is connected from a mixer of all inputs. This makes possible
4343 * 6-channel independent captures.
4345 * In addition, an independent DAC for the multi-playback (not used in this
4348 #ifdef CONFIG_SND_HDA_POWER_SAVE
4349 #define alc882_loopbacks alc880_loopbacks
4356 ALC882_FIXUP_ABIT_AW9D_MAX,
4357 ALC882_FIXUP_LENOVO_Y530,
4358 ALC882_FIXUP_PB_M5210,
4359 ALC882_FIXUP_ACER_ASPIRE_7736,
4360 ALC882_FIXUP_ASUS_W90V,
4361 ALC889_FIXUP_VAIO_TT,
4362 ALC888_FIXUP_EEE1601,
4365 ALC883_FIXUP_ACER_EAPD,
4368 ALC882_FIXUP_ASUS_W2JC,
4369 ALC882_FIXUP_ACER_ASPIRE_4930G,
4370 ALC882_FIXUP_ACER_ASPIRE_8930G,
4371 ALC882_FIXUP_ASPIRE_8930G_VERBS,
4372 ALC885_FIXUP_MACPRO_GPIO,
4375 static void alc889_fixup_coef(struct hda_codec *codec,
4376 const struct alc_fixup *fix, int action)
4378 if (action != ALC_FIXUP_ACT_INIT)
4380 alc889_coef_init(codec);
4383 /* toggle speaker-output according to the hp-jack state */
4384 static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
4386 unsigned int gpiostate, gpiomask, gpiodir;
4388 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
4389 AC_VERB_GET_GPIO_DATA, 0);
4392 gpiostate |= (1 << pin);
4394 gpiostate &= ~(1 << pin);
4396 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
4397 AC_VERB_GET_GPIO_MASK, 0);
4398 gpiomask |= (1 << pin);
4400 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
4401 AC_VERB_GET_GPIO_DIRECTION, 0);
4402 gpiodir |= (1 << pin);
4405 snd_hda_codec_write(codec, codec->afg, 0,
4406 AC_VERB_SET_GPIO_MASK, gpiomask);
4407 snd_hda_codec_write(codec, codec->afg, 0,
4408 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
4412 snd_hda_codec_write(codec, codec->afg, 0,
4413 AC_VERB_SET_GPIO_DATA, gpiostate);
4416 /* set up GPIO at initialization */
4417 static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
4418 const struct alc_fixup *fix, int action)
4420 if (action != ALC_FIXUP_ACT_INIT)
4422 alc882_gpio_mute(codec, 0, 0);
4423 alc882_gpio_mute(codec, 1, 0);
4426 static const struct alc_fixup alc882_fixups[] = {
4427 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
4428 .type = ALC_FIXUP_PINS,
4429 .v.pins = (const struct alc_pincfg[]) {
4430 { 0x15, 0x01080104 }, /* side */
4431 { 0x16, 0x01011012 }, /* rear */
4432 { 0x17, 0x01016011 }, /* clfe */
4436 [ALC882_FIXUP_LENOVO_Y530] = {
4437 .type = ALC_FIXUP_PINS,
4438 .v.pins = (const struct alc_pincfg[]) {
4439 { 0x15, 0x99130112 }, /* rear int speakers */
4440 { 0x16, 0x99130111 }, /* subwoofer */
4444 [ALC882_FIXUP_PB_M5210] = {
4445 .type = ALC_FIXUP_VERBS,
4446 .v.verbs = (const struct hda_verb[]) {
4447 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
4451 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
4452 .type = ALC_FIXUP_SKU,
4453 .v.sku = ALC_FIXUP_SKU_IGNORE,
4455 [ALC882_FIXUP_ASUS_W90V] = {
4456 .type = ALC_FIXUP_PINS,
4457 .v.pins = (const struct alc_pincfg[]) {
4458 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
4462 [ALC889_FIXUP_VAIO_TT] = {
4463 .type = ALC_FIXUP_PINS,
4464 .v.pins = (const struct alc_pincfg[]) {
4465 { 0x17, 0x90170111 }, /* hidden surround speaker */
4469 [ALC888_FIXUP_EEE1601] = {
4470 .type = ALC_FIXUP_VERBS,
4471 .v.verbs = (const struct hda_verb[]) {
4472 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
4473 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
4477 [ALC882_FIXUP_EAPD] = {
4478 .type = ALC_FIXUP_VERBS,
4479 .v.verbs = (const struct hda_verb[]) {
4480 /* change to EAPD mode */
4481 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4482 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4486 [ALC883_FIXUP_EAPD] = {
4487 .type = ALC_FIXUP_VERBS,
4488 .v.verbs = (const struct hda_verb[]) {
4489 /* change to EAPD mode */
4490 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4491 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4495 [ALC883_FIXUP_ACER_EAPD] = {
4496 .type = ALC_FIXUP_VERBS,
4497 .v.verbs = (const struct hda_verb[]) {
4498 /* eanable EAPD on Acer laptops */
4499 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4500 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4504 [ALC882_FIXUP_GPIO3] = {
4505 .type = ALC_FIXUP_VERBS,
4506 .v.verbs = alc_gpio3_init_verbs,
4508 [ALC882_FIXUP_ASUS_W2JC] = {
4509 .type = ALC_FIXUP_VERBS,
4510 .v.verbs = alc_gpio1_init_verbs,
4512 .chain_id = ALC882_FIXUP_EAPD,
4514 [ALC889_FIXUP_COEF] = {
4515 .type = ALC_FIXUP_FUNC,
4516 .v.func = alc889_fixup_coef,
4518 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
4519 .type = ALC_FIXUP_PINS,
4520 .v.pins = (const struct alc_pincfg[]) {
4521 { 0x16, 0x99130111 }, /* CLFE speaker */
4522 { 0x17, 0x99130112 }, /* surround speaker */
4526 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
4527 .type = ALC_FIXUP_PINS,
4528 .v.pins = (const struct alc_pincfg[]) {
4529 { 0x16, 0x99130111 }, /* CLFE speaker */
4530 { 0x1b, 0x99130112 }, /* surround speaker */
4534 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
4536 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
4537 /* additional init verbs for Acer Aspire 8930G */
4538 .type = ALC_FIXUP_VERBS,
4539 .v.verbs = (const struct hda_verb[]) {
4540 /* Enable all DACs */
4541 /* DAC DISABLE/MUTE 1? */
4542 /* setting bits 1-5 disables DAC nids 0x02-0x06
4543 * apparently. Init=0x38 */
4544 { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
4545 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
4546 /* DAC DISABLE/MUTE 2? */
4547 /* some bit here disables the other DACs.
4549 { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
4550 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
4552 * This laptop has a stereo digital microphone.
4553 * The mics are only 1cm apart which makes the stereo
4554 * useless. However, either the mic or the ALC889
4555 * makes the signal become a difference/sum signal
4556 * instead of standard stereo, which is annoying.
4557 * So instead we flip this bit which makes the
4558 * codec replicate the sum signal to both channels,
4559 * turning it into a normal mono mic.
4561 /* DMIC_CONTROL? Init value = 0x0001 */
4562 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
4563 { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
4564 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4565 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4569 [ALC885_FIXUP_MACPRO_GPIO] = {
4570 .type = ALC_FIXUP_FUNC,
4571 .v.func = alc885_fixup_macpro_gpio,
4575 static const struct snd_pci_quirk alc882_fixup_tbl[] = {
4576 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
4577 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
4578 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
4579 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
4580 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
4581 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
4582 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
4583 ALC882_FIXUP_ACER_ASPIRE_4930G),
4584 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
4585 ALC882_FIXUP_ACER_ASPIRE_4930G),
4586 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
4587 ALC882_FIXUP_ACER_ASPIRE_8930G),
4588 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
4589 ALC882_FIXUP_ACER_ASPIRE_8930G),
4590 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
4591 ALC882_FIXUP_ACER_ASPIRE_4930G),
4592 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
4593 ALC882_FIXUP_ACER_ASPIRE_4930G),
4594 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
4595 ALC882_FIXUP_ACER_ASPIRE_4930G),
4596 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
4597 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
4598 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
4599 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
4600 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
4601 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
4602 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
4604 /* All Apple entries are in codec SSIDs */
4605 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
4606 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
4607 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
4608 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
4609 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
4611 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
4612 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
4613 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
4614 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
4615 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
4616 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
4617 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
4622 * BIOS auto configuration
4624 /* almost identical with ALC880 parser... */
4625 static int alc882_parse_auto_config(struct hda_codec *codec)
4627 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
4628 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4629 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
4634 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4635 #include "alc882_quirks.c"
4638 static int patch_alc882(struct hda_codec *codec)
4640 struct alc_spec *spec;
4641 int err, board_config;
4643 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4649 spec->mixer_nid = 0x0b;
4651 switch (codec->vendor_id) {
4656 /* ALC883 and variants */
4657 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
4661 err = alc_codec_rename_from_preset(codec);
4665 board_config = alc_board_config(codec, ALC882_MODEL_LAST,
4666 alc882_models, NULL);
4667 if (board_config < 0)
4668 board_config = alc_board_codec_sid_config(codec,
4669 ALC882_MODEL_LAST, alc882_models, alc882_ssid_cfg_tbl);
4671 if (board_config < 0) {
4672 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4674 board_config = ALC_MODEL_AUTO;
4677 if (board_config == ALC_MODEL_AUTO) {
4678 alc_pick_fixup(codec, NULL, alc882_fixup_tbl, alc882_fixups);
4679 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4682 alc_auto_parse_customize_define(codec);
4684 if (board_config == ALC_MODEL_AUTO) {
4685 /* automatic parse from the BIOS config */
4686 err = alc882_parse_auto_config(codec);
4691 if (board_config != ALC_MODEL_AUTO) {
4692 setup_preset(codec, &alc882_presets[board_config]);
4693 spec->vmaster_nid = 0x0c;
4696 if (!spec->no_analog && !spec->adc_nids) {
4697 alc_auto_fill_adc_caps(codec);
4698 alc_rebuild_imux_for_auto_mic(codec);
4699 alc_remove_invalid_adc_nids(codec);
4702 if (!spec->no_analog && !spec->cap_mixer)
4703 set_capture_mixer(codec);
4705 if (!spec->no_analog && has_cdefine_beep(codec)) {
4706 err = snd_hda_attach_beep_device(codec, 0x1);
4709 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4712 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4714 codec->patch_ops = alc_patch_ops;
4715 if (board_config == ALC_MODEL_AUTO)
4716 spec->init_hook = alc_auto_init_std;
4718 codec->patch_ops.build_controls = __alc_build_controls;
4720 #ifdef CONFIG_SND_HDA_POWER_SAVE
4721 if (!spec->loopback.amplist)
4722 spec->loopback.amplist = alc882_loopbacks;
4736 static int alc262_parse_auto_config(struct hda_codec *codec)
4738 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
4739 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4740 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
4747 ALC262_FIXUP_FSC_H270,
4748 ALC262_FIXUP_HP_Z200,
4750 ALC262_FIXUP_LENOVO_3000,
4752 ALC262_FIXUP_BENQ_T31,
4755 static const struct alc_fixup alc262_fixups[] = {
4756 [ALC262_FIXUP_FSC_H270] = {
4757 .type = ALC_FIXUP_PINS,
4758 .v.pins = (const struct alc_pincfg[]) {
4759 { 0x14, 0x99130110 }, /* speaker */
4760 { 0x15, 0x0221142f }, /* front HP */
4761 { 0x1b, 0x0121141f }, /* rear HP */
4765 [ALC262_FIXUP_HP_Z200] = {
4766 .type = ALC_FIXUP_PINS,
4767 .v.pins = (const struct alc_pincfg[]) {
4768 { 0x16, 0x99130120 }, /* internal speaker */
4772 [ALC262_FIXUP_TYAN] = {
4773 .type = ALC_FIXUP_PINS,
4774 .v.pins = (const struct alc_pincfg[]) {
4775 { 0x14, 0x1993e1f0 }, /* int AUX */
4779 [ALC262_FIXUP_LENOVO_3000] = {
4780 .type = ALC_FIXUP_VERBS,
4781 .v.verbs = (const struct hda_verb[]) {
4782 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
4786 .chain_id = ALC262_FIXUP_BENQ,
4788 [ALC262_FIXUP_BENQ] = {
4789 .type = ALC_FIXUP_VERBS,
4790 .v.verbs = (const struct hda_verb[]) {
4791 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4792 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4796 [ALC262_FIXUP_BENQ_T31] = {
4797 .type = ALC_FIXUP_VERBS,
4798 .v.verbs = (const struct hda_verb[]) {
4799 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4800 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4806 static const struct snd_pci_quirk alc262_fixup_tbl[] = {
4807 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
4808 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
4809 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
4810 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
4811 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
4812 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
4813 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
4814 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
4819 #ifdef CONFIG_SND_HDA_POWER_SAVE
4820 #define alc262_loopbacks alc880_loopbacks
4825 static int patch_alc262(struct hda_codec *codec)
4827 struct alc_spec *spec;
4830 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4836 spec->mixer_nid = 0x0b;
4839 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
4844 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4845 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
4846 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4847 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
4850 alc_auto_parse_customize_define(codec);
4852 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
4854 alc_pick_fixup(codec, NULL, alc262_fixup_tbl, alc262_fixups);
4855 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4857 /* automatic parse from the BIOS config */
4858 err = alc262_parse_auto_config(codec);
4862 if (!spec->no_analog && !spec->adc_nids) {
4863 alc_auto_fill_adc_caps(codec);
4864 alc_rebuild_imux_for_auto_mic(codec);
4865 alc_remove_invalid_adc_nids(codec);
4868 if (!spec->no_analog && !spec->cap_mixer)
4869 set_capture_mixer(codec);
4871 if (!spec->no_analog && has_cdefine_beep(codec)) {
4872 err = snd_hda_attach_beep_device(codec, 0x1);
4875 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4878 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4880 codec->patch_ops = alc_patch_ops;
4881 spec->init_hook = alc_auto_init_std;
4882 spec->shutup = alc_eapd_shutup;
4884 #ifdef CONFIG_SND_HDA_POWER_SAVE
4885 if (!spec->loopback.amplist)
4886 spec->loopback.amplist = alc262_loopbacks;
4899 /* bind Beep switches of both NID 0x0f and 0x10 */
4900 static const struct hda_bind_ctls alc268_bind_beep_sw = {
4901 .ops = &snd_hda_bind_sw,
4903 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
4904 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
4909 static const struct snd_kcontrol_new alc268_beep_mixer[] = {
4910 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
4911 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
4915 /* set PCBEEP vol = 0, mute connections */
4916 static const struct hda_verb alc268_beep_init_verbs[] = {
4917 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4918 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4919 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4924 * BIOS auto configuration
4926 static int alc268_parse_auto_config(struct hda_codec *codec)
4928 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4929 struct alc_spec *spec = codec->spec;
4930 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
4932 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
4933 add_mixer(spec, alc268_beep_mixer);
4934 add_verb(spec, alc268_beep_init_verbs);
4942 static int patch_alc268(struct hda_codec *codec)
4944 struct alc_spec *spec;
4945 int i, has_beep, err;
4947 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4953 /* ALC268 has no aa-loopback mixer */
4955 /* automatic parse from the BIOS config */
4956 err = alc268_parse_auto_config(codec);
4961 for (i = 0; i < spec->num_mixers; i++) {
4962 if (spec->mixers[i] == alc268_beep_mixer) {
4969 err = snd_hda_attach_beep_device(codec, 0x1);
4972 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
4973 /* override the amp caps for beep generator */
4974 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
4975 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
4976 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
4977 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4978 (0 << AC_AMPCAP_MUTE_SHIFT));
4981 if (!spec->no_analog && !spec->adc_nids) {
4982 alc_auto_fill_adc_caps(codec);
4983 alc_rebuild_imux_for_auto_mic(codec);
4984 alc_remove_invalid_adc_nids(codec);
4987 if (!spec->no_analog && !spec->cap_mixer)
4988 set_capture_mixer(codec);
4990 codec->patch_ops = alc_patch_ops;
4991 spec->init_hook = alc_auto_init_std;
4992 spec->shutup = alc_eapd_shutup;
5004 #ifdef CONFIG_SND_HDA_POWER_SAVE
5005 #define alc269_loopbacks alc880_loopbacks
5008 static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
5012 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5013 /* NID is set in alc_build_pcms */
5015 .open = alc_playback_pcm_open,
5016 .prepare = alc_playback_pcm_prepare,
5017 .cleanup = alc_playback_pcm_cleanup
5021 static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
5025 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5026 /* NID is set in alc_build_pcms */
5029 #ifdef CONFIG_SND_HDA_POWER_SAVE
5030 static int alc269_mic2_for_mute_led(struct hda_codec *codec)
5032 switch (codec->subsystem_id) {
5039 static int alc269_mic2_mute_check_ps(struct hda_codec *codec, hda_nid_t nid)
5041 /* update mute-LED according to the speaker mute state */
5042 if (nid == 0x01 || nid == 0x14) {
5044 if (snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0) &
5049 /* mic2 vref pin is used for mute LED control */
5050 snd_hda_codec_update_cache(codec, 0x19, 0,
5051 AC_VERB_SET_PIN_WIDGET_CONTROL,
5054 return alc_check_power_status(codec, nid);
5056 #endif /* CONFIG_SND_HDA_POWER_SAVE */
5058 /* different alc269-variants */
5060 ALC269_TYPE_ALC269VA,
5061 ALC269_TYPE_ALC269VB,
5062 ALC269_TYPE_ALC269VC,
5066 * BIOS auto configuration
5068 static int alc269_parse_auto_config(struct hda_codec *codec)
5070 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
5071 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
5072 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5073 struct alc_spec *spec = codec->spec;
5074 const hda_nid_t *ssids = spec->codec_variant == ALC269_TYPE_ALC269VA ?
5075 alc269va_ssids : alc269_ssids;
5077 return alc_parse_auto_config(codec, alc269_ignore, ssids);
5080 static void alc269_toggle_power_output(struct hda_codec *codec, int power_up)
5082 int val = alc_read_coef_idx(codec, 0x04);
5087 alc_write_coef_idx(codec, 0x04, val);
5090 static void alc269_shutup(struct hda_codec *codec)
5092 if ((alc_get_coef0(codec) & 0x00ff) == 0x017)
5093 alc269_toggle_power_output(codec, 0);
5094 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
5095 alc269_toggle_power_output(codec, 0);
5101 static int alc269_resume(struct hda_codec *codec)
5103 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
5104 alc269_toggle_power_output(codec, 0);
5108 codec->patch_ops.init(codec);
5110 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
5111 alc269_toggle_power_output(codec, 1);
5115 if ((alc_get_coef0(codec) & 0x00ff) == 0x018)
5116 alc269_toggle_power_output(codec, 1);
5118 snd_hda_codec_resume_amp(codec);
5119 snd_hda_codec_resume_cache(codec);
5120 hda_call_check_power_status(codec, 0x01);
5123 #endif /* CONFIG_PM */
5125 static void alc269_fixup_hweq(struct hda_codec *codec,
5126 const struct alc_fixup *fix, int action)
5130 if (action != ALC_FIXUP_ACT_INIT)
5132 coef = alc_read_coef_idx(codec, 0x1e);
5133 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
5136 static void alc271_fixup_dmic(struct hda_codec *codec,
5137 const struct alc_fixup *fix, int action)
5139 static const struct hda_verb verbs[] = {
5140 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
5141 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
5146 if (strcmp(codec->chip_name, "ALC271X"))
5148 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
5149 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
5150 snd_hda_sequence_write(codec, verbs);
5153 static void alc269_fixup_pcm_44k(struct hda_codec *codec,
5154 const struct alc_fixup *fix, int action)
5156 struct alc_spec *spec = codec->spec;
5158 if (action != ALC_FIXUP_ACT_PROBE)
5161 /* Due to a hardware problem on Lenovo Ideadpad, we need to
5162 * fix the sample rate of analog I/O to 44.1kHz
5164 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
5165 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
5168 static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
5169 const struct alc_fixup *fix, int action)
5173 if (action != ALC_FIXUP_ACT_INIT)
5175 /* The digital-mic unit sends PDM (differential signal) instead of
5176 * the standard PCM, thus you can't record a valid mono stream as is.
5177 * Below is a workaround specific to ALC269 to control the dmic
5178 * signal source as mono.
5180 coef = alc_read_coef_idx(codec, 0x07);
5181 alc_write_coef_idx(codec, 0x07, coef | 0x80);
5184 static void alc269_quanta_automute(struct hda_codec *codec)
5186 update_outputs(codec);
5188 snd_hda_codec_write(codec, 0x20, 0,
5189 AC_VERB_SET_COEF_INDEX, 0x0c);
5190 snd_hda_codec_write(codec, 0x20, 0,
5191 AC_VERB_SET_PROC_COEF, 0x680);
5193 snd_hda_codec_write(codec, 0x20, 0,
5194 AC_VERB_SET_COEF_INDEX, 0x0c);
5195 snd_hda_codec_write(codec, 0x20, 0,
5196 AC_VERB_SET_PROC_COEF, 0x480);
5199 static void alc269_fixup_quanta_mute(struct hda_codec *codec,
5200 const struct alc_fixup *fix, int action)
5202 struct alc_spec *spec = codec->spec;
5203 if (action != ALC_FIXUP_ACT_PROBE)
5205 spec->automute_hook = alc269_quanta_automute;
5209 ALC269_FIXUP_SONY_VAIO,
5210 ALC275_FIXUP_SONY_VAIO_GPIO2,
5211 ALC269_FIXUP_DELL_M101Z,
5212 ALC269_FIXUP_SKU_IGNORE,
5213 ALC269_FIXUP_ASUS_G73JW,
5214 ALC269_FIXUP_LENOVO_EAPD,
5215 ALC275_FIXUP_SONY_HWEQ,
5217 ALC269_FIXUP_PCM_44K,
5218 ALC269_FIXUP_STEREO_DMIC,
5219 ALC269_FIXUP_QUANTA_MUTE,
5220 ALC269_FIXUP_LIFEBOOK,
5223 ALC269VB_FIXUP_AMIC,
5224 ALC269VB_FIXUP_DMIC,
5227 static const struct alc_fixup alc269_fixups[] = {
5228 [ALC269_FIXUP_SONY_VAIO] = {
5229 .type = ALC_FIXUP_VERBS,
5230 .v.verbs = (const struct hda_verb[]) {
5231 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
5235 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
5236 .type = ALC_FIXUP_VERBS,
5237 .v.verbs = (const struct hda_verb[]) {
5238 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
5239 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
5240 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5244 .chain_id = ALC269_FIXUP_SONY_VAIO
5246 [ALC269_FIXUP_DELL_M101Z] = {
5247 .type = ALC_FIXUP_VERBS,
5248 .v.verbs = (const struct hda_verb[]) {
5249 /* Enables internal speaker */
5250 {0x20, AC_VERB_SET_COEF_INDEX, 13},
5251 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
5255 [ALC269_FIXUP_SKU_IGNORE] = {
5256 .type = ALC_FIXUP_SKU,
5257 .v.sku = ALC_FIXUP_SKU_IGNORE,
5259 [ALC269_FIXUP_ASUS_G73JW] = {
5260 .type = ALC_FIXUP_PINS,
5261 .v.pins = (const struct alc_pincfg[]) {
5262 { 0x17, 0x99130111 }, /* subwoofer */
5266 [ALC269_FIXUP_LENOVO_EAPD] = {
5267 .type = ALC_FIXUP_VERBS,
5268 .v.verbs = (const struct hda_verb[]) {
5269 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
5273 [ALC275_FIXUP_SONY_HWEQ] = {
5274 .type = ALC_FIXUP_FUNC,
5275 .v.func = alc269_fixup_hweq,
5277 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
5279 [ALC271_FIXUP_DMIC] = {
5280 .type = ALC_FIXUP_FUNC,
5281 .v.func = alc271_fixup_dmic,
5283 [ALC269_FIXUP_PCM_44K] = {
5284 .type = ALC_FIXUP_FUNC,
5285 .v.func = alc269_fixup_pcm_44k,
5287 [ALC269_FIXUP_STEREO_DMIC] = {
5288 .type = ALC_FIXUP_FUNC,
5289 .v.func = alc269_fixup_stereo_dmic,
5291 [ALC269_FIXUP_QUANTA_MUTE] = {
5292 .type = ALC_FIXUP_FUNC,
5293 .v.func = alc269_fixup_quanta_mute,
5295 [ALC269_FIXUP_LIFEBOOK] = {
5296 .type = ALC_FIXUP_PINS,
5297 .v.pins = (const struct alc_pincfg[]) {
5298 { 0x1a, 0x2101103f }, /* dock line-out */
5299 { 0x1b, 0x23a11040 }, /* dock mic-in */
5303 .chain_id = ALC269_FIXUP_QUANTA_MUTE
5305 [ALC269_FIXUP_AMIC] = {
5306 .type = ALC_FIXUP_PINS,
5307 .v.pins = (const struct alc_pincfg[]) {
5308 { 0x14, 0x99130110 }, /* speaker */
5309 { 0x15, 0x0121401f }, /* HP out */
5310 { 0x18, 0x01a19c20 }, /* mic */
5311 { 0x19, 0x99a3092f }, /* int-mic */
5315 [ALC269_FIXUP_DMIC] = {
5316 .type = ALC_FIXUP_PINS,
5317 .v.pins = (const struct alc_pincfg[]) {
5318 { 0x12, 0x99a3092f }, /* int-mic */
5319 { 0x14, 0x99130110 }, /* speaker */
5320 { 0x15, 0x0121401f }, /* HP out */
5321 { 0x18, 0x01a19c20 }, /* mic */
5325 [ALC269VB_FIXUP_AMIC] = {
5326 .type = ALC_FIXUP_PINS,
5327 .v.pins = (const struct alc_pincfg[]) {
5328 { 0x14, 0x99130110 }, /* speaker */
5329 { 0x18, 0x01a19c20 }, /* mic */
5330 { 0x19, 0x99a3092f }, /* int-mic */
5331 { 0x21, 0x0121401f }, /* HP out */
5335 [ALC269VB_FIXUP_DMIC] = {
5336 .type = ALC_FIXUP_PINS,
5337 .v.pins = (const struct alc_pincfg[]) {
5338 { 0x12, 0x99a3092f }, /* int-mic */
5339 { 0x14, 0x99130110 }, /* speaker */
5340 { 0x18, 0x01a19c20 }, /* mic */
5341 { 0x21, 0x0121401f }, /* HP out */
5347 static const struct snd_pci_quirk alc269_fixup_tbl[] = {
5348 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
5349 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
5350 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
5351 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
5352 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
5353 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
5354 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
5355 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
5356 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
5357 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
5358 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
5359 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
5360 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
5361 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
5362 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
5363 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
5364 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
5365 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
5366 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_QUANTA_MUTE),
5367 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K),
5368 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
5371 /* Below is a quirk table taken from the old code.
5372 * Basically the device should work as is without the fixup table.
5373 * If BIOS doesn't give a proper info, enable the corresponding
5376 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
5378 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
5379 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
5380 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
5381 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
5382 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
5383 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
5384 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
5385 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
5386 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
5387 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
5388 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
5389 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
5390 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
5391 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
5392 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
5393 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
5394 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
5395 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
5396 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
5397 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
5398 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
5399 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
5400 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
5401 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
5402 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
5403 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
5404 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
5405 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
5406 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
5407 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
5408 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
5409 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
5410 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
5411 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
5412 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
5413 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
5414 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
5415 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
5416 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
5421 static const struct alc_model_fixup alc269_fixup_models[] = {
5422 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
5423 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
5428 static int alc269_fill_coef(struct hda_codec *codec)
5432 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
5433 alc_write_coef_idx(codec, 0xf, 0x960b);
5434 alc_write_coef_idx(codec, 0xe, 0x8817);
5437 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
5438 alc_write_coef_idx(codec, 0xf, 0x960b);
5439 alc_write_coef_idx(codec, 0xe, 0x8814);
5442 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
5443 val = alc_read_coef_idx(codec, 0x04);
5444 /* Power up output pin */
5445 alc_write_coef_idx(codec, 0x04, val | (1<<11));
5448 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
5449 val = alc_read_coef_idx(codec, 0xd);
5450 if ((val & 0x0c00) >> 10 != 0x1) {
5451 /* Capless ramp up clock control */
5452 alc_write_coef_idx(codec, 0xd, val | (1<<10));
5454 val = alc_read_coef_idx(codec, 0x17);
5455 if ((val & 0x01c0) >> 6 != 0x4) {
5456 /* Class D power on reset */
5457 alc_write_coef_idx(codec, 0x17, val | (1<<7));
5461 val = alc_read_coef_idx(codec, 0xd); /* Class D */
5462 alc_write_coef_idx(codec, 0xd, val | (1<<14));
5464 val = alc_read_coef_idx(codec, 0x4); /* HP */
5465 alc_write_coef_idx(codec, 0x4, val | (1<<11));
5472 static int patch_alc269(struct hda_codec *codec)
5474 struct alc_spec *spec;
5477 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5483 spec->mixer_nid = 0x0b;
5485 alc_auto_parse_customize_define(codec);
5487 err = alc_codec_rename_from_preset(codec);
5491 if (codec->vendor_id == 0x10ec0269) {
5492 spec->codec_variant = ALC269_TYPE_ALC269VA;
5493 switch (alc_get_coef0(codec) & 0x00f0) {
5495 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
5496 spec->cdefine.platform_type == 1)
5497 err = alc_codec_rename(codec, "ALC271X");
5498 spec->codec_variant = ALC269_TYPE_ALC269VB;
5501 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
5502 codec->bus->pci->subsystem_device == 0x21f3)
5503 err = alc_codec_rename(codec, "ALC3202");
5504 spec->codec_variant = ALC269_TYPE_ALC269VC;
5507 alc_fix_pll_init(codec, 0x20, 0x04, 15);
5511 alc269_fill_coef(codec);
5514 alc_pick_fixup(codec, alc269_fixup_models,
5515 alc269_fixup_tbl, alc269_fixups);
5516 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5518 /* automatic parse from the BIOS config */
5519 err = alc269_parse_auto_config(codec);
5523 if (!spec->no_analog && !spec->adc_nids) {
5524 alc_auto_fill_adc_caps(codec);
5525 alc_rebuild_imux_for_auto_mic(codec);
5526 alc_remove_invalid_adc_nids(codec);
5529 if (!spec->no_analog && !spec->cap_mixer)
5530 set_capture_mixer(codec);
5532 if (!spec->no_analog && has_cdefine_beep(codec)) {
5533 err = snd_hda_attach_beep_device(codec, 0x1);
5536 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
5539 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5541 codec->patch_ops = alc_patch_ops;
5543 codec->patch_ops.resume = alc269_resume;
5545 spec->init_hook = alc_auto_init_std;
5546 spec->shutup = alc269_shutup;
5548 #ifdef CONFIG_SND_HDA_POWER_SAVE
5549 if (!spec->loopback.amplist)
5550 spec->loopback.amplist = alc269_loopbacks;
5551 if (alc269_mic2_for_mute_led(codec))
5552 codec->patch_ops.check_power_status = alc269_mic2_mute_check_ps;
5566 static int alc861_parse_auto_config(struct hda_codec *codec)
5568 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
5569 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
5570 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
5573 #ifdef CONFIG_SND_HDA_POWER_SAVE
5574 static const struct hda_amp_list alc861_loopbacks[] = {
5575 { 0x15, HDA_INPUT, 0 },
5576 { 0x15, HDA_INPUT, 1 },
5577 { 0x15, HDA_INPUT, 2 },
5578 { 0x15, HDA_INPUT, 3 },
5584 /* Pin config fixes */
5586 PINFIX_FSC_AMILO_PI1505,
5590 /* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
5591 static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
5592 const struct alc_fixup *fix, int action)
5594 struct alc_spec *spec = codec->spec;
5597 if (action != ALC_FIXUP_ACT_INIT)
5599 val = snd_hda_codec_read(codec, 0x0f, 0,
5600 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5601 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
5602 val |= AC_PINCTL_IN_EN;
5603 val |= AC_PINCTL_VREF_50;
5604 snd_hda_codec_write(codec, 0x0f, 0,
5605 AC_VERB_SET_PIN_WIDGET_CONTROL, val);
5606 spec->keep_vref_in_automute = 1;
5609 static const struct alc_fixup alc861_fixups[] = {
5610 [PINFIX_FSC_AMILO_PI1505] = {
5611 .type = ALC_FIXUP_PINS,
5612 .v.pins = (const struct alc_pincfg[]) {
5613 { 0x0b, 0x0221101f }, /* HP */
5614 { 0x0f, 0x90170310 }, /* speaker */
5618 [PINFIX_ASUS_A6RP] = {
5619 .type = ALC_FIXUP_FUNC,
5620 .v.func = alc861_fixup_asus_amp_vref_0f,
5624 static const struct snd_pci_quirk alc861_fixup_tbl[] = {
5625 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", PINFIX_ASUS_A6RP),
5626 SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", PINFIX_ASUS_A6RP),
5627 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", PINFIX_FSC_AMILO_PI1505),
5633 static int patch_alc861(struct hda_codec *codec)
5635 struct alc_spec *spec;
5638 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5644 spec->mixer_nid = 0x15;
5646 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
5647 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5649 /* automatic parse from the BIOS config */
5650 err = alc861_parse_auto_config(codec);
5654 if (!spec->no_analog && !spec->adc_nids) {
5655 alc_auto_fill_adc_caps(codec);
5656 alc_rebuild_imux_for_auto_mic(codec);
5657 alc_remove_invalid_adc_nids(codec);
5660 if (!spec->no_analog && !spec->cap_mixer)
5661 set_capture_mixer(codec);
5663 if (!spec->no_analog) {
5664 err = snd_hda_attach_beep_device(codec, 0x23);
5667 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
5670 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5672 codec->patch_ops = alc_patch_ops;
5673 spec->init_hook = alc_auto_init_std;
5674 #ifdef CONFIG_SND_HDA_POWER_SAVE
5675 spec->power_hook = alc_power_eapd;
5676 if (!spec->loopback.amplist)
5677 spec->loopback.amplist = alc861_loopbacks;
5692 * In addition, an independent DAC
5694 #ifdef CONFIG_SND_HDA_POWER_SAVE
5695 #define alc861vd_loopbacks alc880_loopbacks
5698 static int alc861vd_parse_auto_config(struct hda_codec *codec)
5700 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
5701 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5702 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
5706 ALC660VD_FIX_ASUS_GPIO1,
5707 ALC861VD_FIX_DALLAS,
5710 /* exclude VREF80 */
5711 static void alc861vd_fixup_dallas(struct hda_codec *codec,
5712 const struct alc_fixup *fix, int action)
5714 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
5715 snd_hda_override_pin_caps(codec, 0x18, 0x00001714);
5716 snd_hda_override_pin_caps(codec, 0x19, 0x0000171c);
5720 static const struct alc_fixup alc861vd_fixups[] = {
5721 [ALC660VD_FIX_ASUS_GPIO1] = {
5722 .type = ALC_FIXUP_VERBS,
5723 .v.verbs = (const struct hda_verb[]) {
5725 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
5726 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5727 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5731 [ALC861VD_FIX_DALLAS] = {
5732 .type = ALC_FIXUP_FUNC,
5733 .v.func = alc861vd_fixup_dallas,
5737 static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
5738 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
5739 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
5740 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
5744 static const struct hda_verb alc660vd_eapd_verbs[] = {
5745 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
5746 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
5752 static int patch_alc861vd(struct hda_codec *codec)
5754 struct alc_spec *spec;
5757 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5763 spec->mixer_nid = 0x0b;
5765 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
5766 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5768 /* automatic parse from the BIOS config */
5769 err = alc861vd_parse_auto_config(codec);
5773 if (codec->vendor_id == 0x10ec0660) {
5774 /* always turn on EAPD */
5775 add_verb(spec, alc660vd_eapd_verbs);
5778 if (!spec->no_analog && !spec->adc_nids) {
5779 alc_auto_fill_adc_caps(codec);
5780 alc_rebuild_imux_for_auto_mic(codec);
5781 alc_remove_invalid_adc_nids(codec);
5784 if (!spec->no_analog && !spec->cap_mixer)
5785 set_capture_mixer(codec);
5787 if (!spec->no_analog) {
5788 err = snd_hda_attach_beep_device(codec, 0x23);
5791 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5794 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5796 codec->patch_ops = alc_patch_ops;
5798 spec->init_hook = alc_auto_init_std;
5799 spec->shutup = alc_eapd_shutup;
5800 #ifdef CONFIG_SND_HDA_POWER_SAVE
5801 if (!spec->loopback.amplist)
5802 spec->loopback.amplist = alc861vd_loopbacks;
5815 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
5816 * configuration. Each pin widget can choose any input DACs and a mixer.
5817 * Each ADC is connected from a mixer of all inputs. This makes possible
5818 * 6-channel independent captures.
5820 * In addition, an independent DAC for the multi-playback (not used in this
5823 #ifdef CONFIG_SND_HDA_POWER_SAVE
5824 #define alc662_loopbacks alc880_loopbacks
5828 * BIOS auto configuration
5831 static int alc662_parse_auto_config(struct hda_codec *codec)
5833 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
5834 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
5835 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5836 const hda_nid_t *ssids;
5838 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
5839 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
5840 ssids = alc663_ssids;
5842 ssids = alc662_ssids;
5843 return alc_parse_auto_config(codec, alc662_ignore, ssids);
5846 static void alc272_fixup_mario(struct hda_codec *codec,
5847 const struct alc_fixup *fix, int action)
5849 if (action != ALC_FIXUP_ACT_PROBE)
5851 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
5852 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
5853 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
5854 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5855 (0 << AC_AMPCAP_MUTE_SHIFT)))
5857 "hda_codec: failed to override amp caps for NID 0x2\n");
5861 ALC662_FIXUP_ASPIRE,
5862 ALC662_FIXUP_IDEAPAD,
5864 ALC662_FIXUP_CZC_P10T,
5865 ALC662_FIXUP_SKU_IGNORE,
5866 ALC662_FIXUP_HP_RP5800,
5867 ALC662_FIXUP_ASUS_MODE1,
5868 ALC662_FIXUP_ASUS_MODE2,
5869 ALC662_FIXUP_ASUS_MODE3,
5870 ALC662_FIXUP_ASUS_MODE4,
5871 ALC662_FIXUP_ASUS_MODE5,
5872 ALC662_FIXUP_ASUS_MODE6,
5873 ALC662_FIXUP_ASUS_MODE7,
5874 ALC662_FIXUP_ASUS_MODE8,
5877 static const struct alc_fixup alc662_fixups[] = {
5878 [ALC662_FIXUP_ASPIRE] = {
5879 .type = ALC_FIXUP_PINS,
5880 .v.pins = (const struct alc_pincfg[]) {
5881 { 0x15, 0x99130112 }, /* subwoofer */
5885 [ALC662_FIXUP_IDEAPAD] = {
5886 .type = ALC_FIXUP_PINS,
5887 .v.pins = (const struct alc_pincfg[]) {
5888 { 0x17, 0x99130112 }, /* subwoofer */
5892 [ALC272_FIXUP_MARIO] = {
5893 .type = ALC_FIXUP_FUNC,
5894 .v.func = alc272_fixup_mario,
5896 [ALC662_FIXUP_CZC_P10T] = {
5897 .type = ALC_FIXUP_VERBS,
5898 .v.verbs = (const struct hda_verb[]) {
5899 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
5903 [ALC662_FIXUP_SKU_IGNORE] = {
5904 .type = ALC_FIXUP_SKU,
5905 .v.sku = ALC_FIXUP_SKU_IGNORE,
5907 [ALC662_FIXUP_HP_RP5800] = {
5908 .type = ALC_FIXUP_PINS,
5909 .v.pins = (const struct alc_pincfg[]) {
5910 { 0x14, 0x0221201f }, /* HP out */
5914 .chain_id = ALC662_FIXUP_SKU_IGNORE
5916 [ALC662_FIXUP_ASUS_MODE1] = {
5917 .type = ALC_FIXUP_PINS,
5918 .v.pins = (const struct alc_pincfg[]) {
5919 { 0x14, 0x99130110 }, /* speaker */
5920 { 0x18, 0x01a19c20 }, /* mic */
5921 { 0x19, 0x99a3092f }, /* int-mic */
5922 { 0x21, 0x0121401f }, /* HP out */
5926 .chain_id = ALC662_FIXUP_SKU_IGNORE
5928 [ALC662_FIXUP_ASUS_MODE2] = {
5929 .type = ALC_FIXUP_PINS,
5930 .v.pins = (const struct alc_pincfg[]) {
5931 { 0x14, 0x99130110 }, /* speaker */
5932 { 0x18, 0x01a19820 }, /* mic */
5933 { 0x19, 0x99a3092f }, /* int-mic */
5934 { 0x1b, 0x0121401f }, /* HP out */
5938 .chain_id = ALC662_FIXUP_SKU_IGNORE
5940 [ALC662_FIXUP_ASUS_MODE3] = {
5941 .type = ALC_FIXUP_PINS,
5942 .v.pins = (const struct alc_pincfg[]) {
5943 { 0x14, 0x99130110 }, /* speaker */
5944 { 0x15, 0x0121441f }, /* HP */
5945 { 0x18, 0x01a19840 }, /* mic */
5946 { 0x19, 0x99a3094f }, /* int-mic */
5947 { 0x21, 0x01211420 }, /* HP2 */
5951 .chain_id = ALC662_FIXUP_SKU_IGNORE
5953 [ALC662_FIXUP_ASUS_MODE4] = {
5954 .type = ALC_FIXUP_PINS,
5955 .v.pins = (const struct alc_pincfg[]) {
5956 { 0x14, 0x99130110 }, /* speaker */
5957 { 0x16, 0x99130111 }, /* speaker */
5958 { 0x18, 0x01a19840 }, /* mic */
5959 { 0x19, 0x99a3094f }, /* int-mic */
5960 { 0x21, 0x0121441f }, /* HP */
5964 .chain_id = ALC662_FIXUP_SKU_IGNORE
5966 [ALC662_FIXUP_ASUS_MODE5] = {
5967 .type = ALC_FIXUP_PINS,
5968 .v.pins = (const struct alc_pincfg[]) {
5969 { 0x14, 0x99130110 }, /* speaker */
5970 { 0x15, 0x0121441f }, /* HP */
5971 { 0x16, 0x99130111 }, /* speaker */
5972 { 0x18, 0x01a19840 }, /* mic */
5973 { 0x19, 0x99a3094f }, /* int-mic */
5977 .chain_id = ALC662_FIXUP_SKU_IGNORE
5979 [ALC662_FIXUP_ASUS_MODE6] = {
5980 .type = ALC_FIXUP_PINS,
5981 .v.pins = (const struct alc_pincfg[]) {
5982 { 0x14, 0x99130110 }, /* speaker */
5983 { 0x15, 0x01211420 }, /* HP2 */
5984 { 0x18, 0x01a19840 }, /* mic */
5985 { 0x19, 0x99a3094f }, /* int-mic */
5986 { 0x1b, 0x0121441f }, /* HP */
5990 .chain_id = ALC662_FIXUP_SKU_IGNORE
5992 [ALC662_FIXUP_ASUS_MODE7] = {
5993 .type = ALC_FIXUP_PINS,
5994 .v.pins = (const struct alc_pincfg[]) {
5995 { 0x14, 0x99130110 }, /* speaker */
5996 { 0x17, 0x99130111 }, /* speaker */
5997 { 0x18, 0x01a19840 }, /* mic */
5998 { 0x19, 0x99a3094f }, /* int-mic */
5999 { 0x1b, 0x01214020 }, /* HP */
6000 { 0x21, 0x0121401f }, /* HP */
6004 .chain_id = ALC662_FIXUP_SKU_IGNORE
6006 [ALC662_FIXUP_ASUS_MODE8] = {
6007 .type = ALC_FIXUP_PINS,
6008 .v.pins = (const struct alc_pincfg[]) {
6009 { 0x14, 0x99130110 }, /* speaker */
6010 { 0x12, 0x99a30970 }, /* int-mic */
6011 { 0x15, 0x01214020 }, /* HP */
6012 { 0x17, 0x99130111 }, /* speaker */
6013 { 0x18, 0x01a19840 }, /* mic */
6014 { 0x21, 0x0121401f }, /* HP */
6018 .chain_id = ALC662_FIXUP_SKU_IGNORE
6022 static const struct snd_pci_quirk alc662_fixup_tbl[] = {
6023 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
6024 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
6025 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
6026 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
6027 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
6028 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
6029 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
6030 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
6031 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
6032 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
6035 /* Below is a quirk table taken from the old code.
6036 * Basically the device should work as is without the fixup table.
6037 * If BIOS doesn't give a proper info, enable the corresponding
6040 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
6041 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
6042 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
6043 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
6044 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6045 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6046 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6047 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
6048 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
6049 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6050 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
6051 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
6052 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
6053 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
6054 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
6055 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6056 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
6057 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
6058 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6059 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6060 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6061 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6062 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
6063 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
6064 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
6065 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6066 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
6067 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6068 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6069 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
6070 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6071 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6072 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
6073 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
6074 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
6075 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
6076 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
6077 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
6078 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
6079 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6080 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
6081 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
6082 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6083 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
6084 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
6085 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
6086 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
6087 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
6088 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6089 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
6094 static const struct alc_model_fixup alc662_fixup_models[] = {
6095 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
6096 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
6097 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
6098 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
6099 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
6100 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
6101 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
6102 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
6103 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
6110 static int patch_alc662(struct hda_codec *codec)
6112 struct alc_spec *spec;
6115 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6121 spec->mixer_nid = 0x0b;
6123 /* handle multiple HPs as is */
6124 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
6126 alc_auto_parse_customize_define(codec);
6128 alc_fix_pll_init(codec, 0x20, 0x04, 15);
6130 err = alc_codec_rename_from_preset(codec);
6134 if ((alc_get_coef0(codec) & (1 << 14)) &&
6135 codec->bus->pci->subsystem_vendor == 0x1025 &&
6136 spec->cdefine.platform_type == 1) {
6137 if (alc_codec_rename(codec, "ALC272X") < 0)
6141 alc_pick_fixup(codec, alc662_fixup_models,
6142 alc662_fixup_tbl, alc662_fixups);
6143 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6144 /* automatic parse from the BIOS config */
6145 err = alc662_parse_auto_config(codec);
6149 if (!spec->no_analog && !spec->adc_nids) {
6150 alc_auto_fill_adc_caps(codec);
6151 alc_rebuild_imux_for_auto_mic(codec);
6152 alc_remove_invalid_adc_nids(codec);
6155 if (!spec->no_analog && !spec->cap_mixer)
6156 set_capture_mixer(codec);
6158 if (!spec->no_analog && has_cdefine_beep(codec)) {
6159 err = snd_hda_attach_beep_device(codec, 0x1);
6162 switch (codec->vendor_id) {
6164 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6169 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
6172 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
6177 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6179 codec->patch_ops = alc_patch_ops;
6180 spec->init_hook = alc_auto_init_std;
6181 spec->shutup = alc_eapd_shutup;
6183 #ifdef CONFIG_SND_HDA_POWER_SAVE
6184 if (!spec->loopback.amplist)
6185 spec->loopback.amplist = alc662_loopbacks;
6199 static int alc680_parse_auto_config(struct hda_codec *codec)
6201 return alc_parse_auto_config(codec, NULL, NULL);
6206 static int patch_alc680(struct hda_codec *codec)
6208 struct alc_spec *spec;
6211 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6217 /* ALC680 has no aa-loopback mixer */
6219 /* automatic parse from the BIOS config */
6220 err = alc680_parse_auto_config(codec);
6226 if (!spec->no_analog && !spec->cap_mixer)
6227 set_capture_mixer(codec);
6229 codec->patch_ops = alc_patch_ops;
6230 spec->init_hook = alc_auto_init_std;
6238 static const struct hda_codec_preset snd_hda_preset_realtek[] = {
6239 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
6240 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
6241 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
6242 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
6243 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
6244 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
6245 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
6246 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
6247 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
6248 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
6249 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
6250 .patch = patch_alc861 },
6251 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
6252 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
6253 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
6254 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
6255 .patch = patch_alc882 },
6256 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
6257 .patch = patch_alc662 },
6258 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
6259 .patch = patch_alc662 },
6260 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
6261 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
6262 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
6263 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
6264 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
6265 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
6266 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
6267 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
6268 .patch = patch_alc882 },
6269 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
6270 .patch = patch_alc882 },
6271 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
6272 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
6273 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
6274 .patch = patch_alc882 },
6275 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
6276 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
6277 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
6278 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
6282 MODULE_ALIAS("snd-hda-codec-id:10ec*");
6284 MODULE_LICENSE("GPL");
6285 MODULE_DESCRIPTION("Realtek HD-audio codec");
6287 static struct hda_codec_preset_list realtek_list = {
6288 .preset = snd_hda_preset_realtek,
6289 .owner = THIS_MODULE,
6292 static int __init patch_realtek_init(void)
6294 return snd_hda_add_codec_preset(&realtek_list);
6297 static void __exit patch_realtek_exit(void)
6299 snd_hda_delete_codec_preset(&realtek_list);
6302 module_init(patch_realtek_init)
6303 module_exit(patch_realtek_exit)