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 "CLFE Playback Volume",
1859 "Bass Speaker Playback Volume",
1860 "PCM Playback Volume",
1864 static const char * const alc_slave_sws[] = {
1865 "Front Playback Switch",
1866 "Surround Playback Switch",
1867 "Center Playback Switch",
1868 "LFE Playback Switch",
1869 "Side Playback Switch",
1870 "Headphone Playback Switch",
1871 "Speaker Playback Switch",
1872 "Mono Playback Switch",
1873 "IEC958 Playback Switch",
1874 "Line-Out Playback Switch",
1875 "CLFE Playback Switch",
1876 "Bass Speaker Playback Switch",
1877 "PCM Playback Switch",
1882 * build control elements
1885 #define NID_MAPPING (-1)
1887 #define SUBDEV_SPEAKER_ (0 << 6)
1888 #define SUBDEV_HP_ (1 << 6)
1889 #define SUBDEV_LINE_ (2 << 6)
1890 #define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1891 #define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1892 #define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1894 static void alc_free_kctls(struct hda_codec *codec);
1896 #ifdef CONFIG_SND_HDA_INPUT_BEEP
1897 /* additional beep mixers; the actual parameters are overwritten at build */
1898 static const struct snd_kcontrol_new alc_beep_mixer[] = {
1899 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
1900 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
1905 static int __alc_build_controls(struct hda_codec *codec)
1907 struct alc_spec *spec = codec->spec;
1908 struct snd_kcontrol *kctl = NULL;
1909 const struct snd_kcontrol_new *knew;
1914 for (i = 0; i < spec->num_mixers; i++) {
1915 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1919 if (spec->cap_mixer) {
1920 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1924 if (spec->multiout.dig_out_nid) {
1925 err = snd_hda_create_spdif_out_ctls(codec,
1926 spec->multiout.dig_out_nid,
1927 spec->multiout.dig_out_nid);
1930 if (!spec->no_analog) {
1931 err = snd_hda_create_spdif_share_sw(codec,
1935 spec->multiout.share_spdif = 1;
1938 if (spec->dig_in_nid) {
1939 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1944 #ifdef CONFIG_SND_HDA_INPUT_BEEP
1945 /* create beep controls if needed */
1946 if (spec->beep_amp) {
1947 const struct snd_kcontrol_new *knew;
1948 for (knew = alc_beep_mixer; knew->name; knew++) {
1949 struct snd_kcontrol *kctl;
1950 kctl = snd_ctl_new1(knew, codec);
1953 kctl->private_value = spec->beep_amp;
1954 err = snd_hda_ctl_add(codec, 0, kctl);
1961 /* if we have no master control, let's create it */
1962 if (!spec->no_analog &&
1963 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1964 unsigned int vmaster_tlv[4];
1965 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
1966 HDA_OUTPUT, vmaster_tlv);
1967 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1968 vmaster_tlv, alc_slave_vols);
1972 if (!spec->no_analog &&
1973 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1974 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1975 NULL, alc_slave_sws);
1980 /* assign Capture Source enums to NID */
1981 if (spec->capsrc_nids || spec->adc_nids) {
1982 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
1984 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1985 for (i = 0; kctl && i < kctl->count; i++) {
1986 err = snd_hda_add_nid(codec, kctl, i,
1987 get_capsrc(spec, i));
1992 if (spec->cap_mixer && spec->adc_nids) {
1993 const char *kname = kctl ? kctl->id.name : NULL;
1994 for (knew = spec->cap_mixer; knew->name; knew++) {
1995 if (kname && strcmp(knew->name, kname) == 0)
1997 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1998 for (i = 0; kctl && i < kctl->count; i++) {
1999 err = snd_hda_add_nid(codec, kctl, i,
2007 /* other nid->control mapping */
2008 for (i = 0; i < spec->num_mixers; i++) {
2009 for (knew = spec->mixers[i]; knew->name; knew++) {
2010 if (knew->iface != NID_MAPPING)
2012 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
2015 u = knew->subdevice;
2016 for (j = 0; j < 4; j++, u >>= 8) {
2021 case SUBDEV_SPEAKER_:
2022 nid = spec->autocfg.speaker_pins[nid];
2025 nid = spec->autocfg.line_out_pins[nid];
2028 nid = spec->autocfg.hp_pins[nid];
2033 err = snd_hda_add_nid(codec, kctl, 0, nid);
2037 u = knew->private_value;
2038 for (j = 0; j < 4; j++, u >>= 8) {
2042 err = snd_hda_add_nid(codec, kctl, 0, nid);
2049 alc_free_kctls(codec); /* no longer needed */
2054 static int alc_build_controls(struct hda_codec *codec)
2056 struct alc_spec *spec = codec->spec;
2057 int err = __alc_build_controls(codec);
2060 return snd_hda_jack_add_kctls(codec, &spec->autocfg);
2068 static void alc_init_special_input_src(struct hda_codec *codec);
2070 static int alc_init(struct hda_codec *codec)
2072 struct alc_spec *spec = codec->spec;
2076 alc_auto_init_amp(codec, spec->init_amp);
2078 for (i = 0; i < spec->num_init_verbs; i++)
2079 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2080 alc_init_special_input_src(codec);
2082 if (spec->init_hook)
2083 spec->init_hook(codec);
2085 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2087 snd_hda_jack_report_sync(codec);
2089 hda_call_check_power_status(codec, 0x01);
2093 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2095 struct alc_spec *spec = codec->spec;
2097 if (spec->unsol_event)
2098 spec->unsol_event(codec, res);
2101 #ifdef CONFIG_SND_HDA_POWER_SAVE
2102 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2104 struct alc_spec *spec = codec->spec;
2105 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2110 * Analog playback callbacks
2112 static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
2113 struct hda_codec *codec,
2114 struct snd_pcm_substream *substream)
2116 struct alc_spec *spec = codec->spec;
2117 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2121 static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2122 struct hda_codec *codec,
2123 unsigned int stream_tag,
2124 unsigned int format,
2125 struct snd_pcm_substream *substream)
2127 struct alc_spec *spec = codec->spec;
2128 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2129 stream_tag, format, substream);
2132 static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2133 struct hda_codec *codec,
2134 struct snd_pcm_substream *substream)
2136 struct alc_spec *spec = codec->spec;
2137 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2143 static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2144 struct hda_codec *codec,
2145 struct snd_pcm_substream *substream)
2147 struct alc_spec *spec = codec->spec;
2148 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2151 static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2152 struct hda_codec *codec,
2153 unsigned int stream_tag,
2154 unsigned int format,
2155 struct snd_pcm_substream *substream)
2157 struct alc_spec *spec = codec->spec;
2158 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2159 stream_tag, format, substream);
2162 static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2163 struct hda_codec *codec,
2164 struct snd_pcm_substream *substream)
2166 struct alc_spec *spec = codec->spec;
2167 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2170 static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2171 struct hda_codec *codec,
2172 struct snd_pcm_substream *substream)
2174 struct alc_spec *spec = codec->spec;
2175 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2181 static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2182 struct hda_codec *codec,
2183 unsigned int stream_tag,
2184 unsigned int format,
2185 struct snd_pcm_substream *substream)
2187 struct alc_spec *spec = codec->spec;
2189 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
2190 stream_tag, 0, format);
2194 static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2195 struct hda_codec *codec,
2196 struct snd_pcm_substream *substream)
2198 struct alc_spec *spec = codec->spec;
2200 snd_hda_codec_cleanup_stream(codec,
2201 spec->adc_nids[substream->number + 1]);
2205 /* analog capture with dynamic dual-adc changes */
2206 static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2207 struct hda_codec *codec,
2208 unsigned int stream_tag,
2209 unsigned int format,
2210 struct snd_pcm_substream *substream)
2212 struct alc_spec *spec = codec->spec;
2213 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
2214 spec->cur_adc_stream_tag = stream_tag;
2215 spec->cur_adc_format = format;
2216 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2220 static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2221 struct hda_codec *codec,
2222 struct snd_pcm_substream *substream)
2224 struct alc_spec *spec = codec->spec;
2225 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2230 static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
2234 .nid = 0, /* fill later */
2236 .prepare = dyn_adc_capture_pcm_prepare,
2237 .cleanup = dyn_adc_capture_pcm_cleanup
2243 static const struct hda_pcm_stream alc_pcm_analog_playback = {
2247 /* NID is set in alc_build_pcms */
2249 .open = alc_playback_pcm_open,
2250 .prepare = alc_playback_pcm_prepare,
2251 .cleanup = alc_playback_pcm_cleanup
2255 static const struct hda_pcm_stream alc_pcm_analog_capture = {
2259 /* NID is set in alc_build_pcms */
2262 static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
2266 /* NID is set in alc_build_pcms */
2269 static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
2270 .substreams = 2, /* can be overridden */
2273 /* NID is set in alc_build_pcms */
2275 .prepare = alc_alt_capture_pcm_prepare,
2276 .cleanup = alc_alt_capture_pcm_cleanup
2280 static const struct hda_pcm_stream alc_pcm_digital_playback = {
2284 /* NID is set in alc_build_pcms */
2286 .open = alc_dig_playback_pcm_open,
2287 .close = alc_dig_playback_pcm_close,
2288 .prepare = alc_dig_playback_pcm_prepare,
2289 .cleanup = alc_dig_playback_pcm_cleanup
2293 static const struct hda_pcm_stream alc_pcm_digital_capture = {
2297 /* NID is set in alc_build_pcms */
2300 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
2301 static const struct hda_pcm_stream alc_pcm_null_stream = {
2307 static int alc_build_pcms(struct hda_codec *codec)
2309 struct alc_spec *spec = codec->spec;
2310 struct hda_pcm *info = spec->pcm_rec;
2311 const struct hda_pcm_stream *p;
2312 bool have_multi_adcs;
2315 codec->num_pcms = 1;
2316 codec->pcm_info = info;
2318 if (spec->no_analog)
2321 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2322 "%s Analog", codec->chip_name);
2323 info->name = spec->stream_name_analog;
2325 if (spec->multiout.num_dacs > 0) {
2326 p = spec->stream_analog_playback;
2328 p = &alc_pcm_analog_playback;
2329 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2330 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2332 if (spec->adc_nids) {
2333 p = spec->stream_analog_capture;
2335 if (spec->dyn_adc_switch)
2336 p = &dyn_adc_pcm_analog_capture;
2338 p = &alc_pcm_analog_capture;
2340 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2341 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2344 if (spec->channel_mode) {
2345 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2346 for (i = 0; i < spec->num_channel_mode; i++) {
2347 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2348 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2354 /* SPDIF for stream index #1 */
2355 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2356 snprintf(spec->stream_name_digital,
2357 sizeof(spec->stream_name_digital),
2358 "%s Digital", codec->chip_name);
2359 codec->num_pcms = 2;
2360 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
2361 info = spec->pcm_rec + 1;
2362 info->name = spec->stream_name_digital;
2363 if (spec->dig_out_type)
2364 info->pcm_type = spec->dig_out_type;
2366 info->pcm_type = HDA_PCM_TYPE_SPDIF;
2367 if (spec->multiout.dig_out_nid) {
2368 p = spec->stream_digital_playback;
2370 p = &alc_pcm_digital_playback;
2371 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2372 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2374 if (spec->dig_in_nid) {
2375 p = spec->stream_digital_capture;
2377 p = &alc_pcm_digital_capture;
2378 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2379 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2381 /* FIXME: do we need this for all Realtek codec models? */
2382 codec->spdif_status_reset = 1;
2385 if (spec->no_analog)
2388 /* If the use of more than one ADC is requested for the current
2389 * model, configure a second analog capture-only PCM.
2391 have_multi_adcs = (spec->num_adc_nids > 1) &&
2392 !spec->dyn_adc_switch && !spec->auto_mic &&
2393 (!spec->input_mux || spec->input_mux->num_items > 1);
2394 /* Additional Analaog capture for index #2 */
2395 if (spec->alt_dac_nid || have_multi_adcs) {
2396 codec->num_pcms = 3;
2397 info = spec->pcm_rec + 2;
2398 info->name = spec->stream_name_analog;
2399 if (spec->alt_dac_nid) {
2400 p = spec->stream_analog_alt_playback;
2402 p = &alc_pcm_analog_alt_playback;
2403 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2404 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2407 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2408 alc_pcm_null_stream;
2409 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2411 if (have_multi_adcs) {
2412 p = spec->stream_analog_alt_capture;
2414 p = &alc_pcm_analog_alt_capture;
2415 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2416 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2418 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2419 spec->num_adc_nids - 1;
2421 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2422 alc_pcm_null_stream;
2423 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
2430 static inline void alc_shutup(struct hda_codec *codec)
2432 struct alc_spec *spec = codec->spec;
2434 if (spec && spec->shutup)
2435 spec->shutup(codec);
2436 snd_hda_shutup_pins(codec);
2439 static void alc_free_kctls(struct hda_codec *codec)
2441 struct alc_spec *spec = codec->spec;
2443 if (spec->kctls.list) {
2444 struct snd_kcontrol_new *kctl = spec->kctls.list;
2446 for (i = 0; i < spec->kctls.used; i++)
2447 kfree(kctl[i].name);
2449 snd_array_free(&spec->kctls);
2452 static void alc_free_bind_ctls(struct hda_codec *codec)
2454 struct alc_spec *spec = codec->spec;
2455 if (spec->bind_ctls.list) {
2456 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2458 for (i = 0; i < spec->bind_ctls.used; i++)
2461 snd_array_free(&spec->bind_ctls);
2464 static void alc_free(struct hda_codec *codec)
2466 struct alc_spec *spec = codec->spec;
2472 alc_free_kctls(codec);
2473 alc_free_bind_ctls(codec);
2475 snd_hda_detach_beep_device(codec);
2478 #ifdef CONFIG_SND_HDA_POWER_SAVE
2479 static void alc_power_eapd(struct hda_codec *codec)
2481 alc_auto_setup_eapd(codec, false);
2484 static int alc_suspend(struct hda_codec *codec, pm_message_t state)
2486 struct alc_spec *spec = codec->spec;
2488 if (spec && spec->power_hook)
2489 spec->power_hook(codec);
2495 static int alc_resume(struct hda_codec *codec)
2497 msleep(150); /* to avoid pop noise */
2498 codec->patch_ops.init(codec);
2499 snd_hda_codec_resume_amp(codec);
2500 snd_hda_codec_resume_cache(codec);
2501 hda_call_check_power_status(codec, 0x01);
2508 static const struct hda_codec_ops alc_patch_ops = {
2509 .build_controls = alc_build_controls,
2510 .build_pcms = alc_build_pcms,
2513 .unsol_event = alc_unsol_event,
2515 .resume = alc_resume,
2517 #ifdef CONFIG_SND_HDA_POWER_SAVE
2518 .suspend = alc_suspend,
2519 .check_power_status = alc_check_power_status,
2521 .reboot_notify = alc_shutup,
2524 /* replace the codec chip_name with the given string */
2525 static int alc_codec_rename(struct hda_codec *codec, const char *name)
2527 kfree(codec->chip_name);
2528 codec->chip_name = kstrdup(name, GFP_KERNEL);
2529 if (!codec->chip_name) {
2537 * Rename codecs appropriately from COEF value
2539 struct alc_codec_rename_table {
2540 unsigned int vendor_id;
2541 unsigned short coef_mask;
2542 unsigned short coef_bits;
2546 static struct alc_codec_rename_table rename_tbl[] = {
2547 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2548 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2549 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2550 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2551 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2552 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2553 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
2554 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2555 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2556 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2557 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2558 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2559 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2560 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2561 { } /* terminator */
2564 static int alc_codec_rename_from_preset(struct hda_codec *codec)
2566 const struct alc_codec_rename_table *p;
2568 for (p = rename_tbl; p->vendor_id; p++) {
2569 if (p->vendor_id != codec->vendor_id)
2571 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
2572 return alc_codec_rename(codec, p->name);
2578 * Automatic parse of I/O pins from the BIOS configuration
2583 ALC_CTL_WIDGET_MUTE,
2588 static const struct snd_kcontrol_new alc_control_templates[] = {
2589 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2590 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2591 HDA_BIND_MUTE(NULL, 0, 0, 0),
2592 HDA_BIND_VOL(NULL, 0),
2593 HDA_BIND_SW(NULL, 0),
2596 /* add dynamic controls */
2597 static int add_control(struct alc_spec *spec, int type, const char *name,
2598 int cidx, unsigned long val)
2600 struct snd_kcontrol_new *knew;
2602 knew = alc_kcontrol_new(spec);
2605 *knew = alc_control_templates[type];
2606 knew->name = kstrdup(name, GFP_KERNEL);
2610 if (get_amp_nid_(val))
2611 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
2612 knew->private_value = val;
2616 static int add_control_with_pfx(struct alc_spec *spec, int type,
2617 const char *pfx, const char *dir,
2618 const char *sfx, int cidx, unsigned long val)
2621 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
2622 return add_control(spec, type, name, cidx, val);
2625 #define add_pb_vol_ctrl(spec, type, pfx, val) \
2626 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2627 #define add_pb_sw_ctrl(spec, type, pfx, val) \
2628 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2629 #define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2630 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2631 #define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2632 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
2634 static const char * const channel_name[4] = {
2635 "Front", "Surround", "CLFE", "Side"
2638 static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2639 bool can_be_master, int *index)
2641 struct auto_pin_cfg *cfg = &spec->autocfg;
2644 if (cfg->line_outs == 1 && !spec->multi_ios &&
2645 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
2648 switch (cfg->line_out_type) {
2649 case AUTO_PIN_SPEAKER_OUT:
2650 if (cfg->line_outs == 1)
2652 if (cfg->line_outs == 2)
2653 return ch ? "Bass Speaker" : "Speaker";
2655 case AUTO_PIN_HP_OUT:
2656 /* for multi-io case, only the primary out */
2657 if (ch && spec->multi_ios)
2662 if (cfg->line_outs == 1 && !spec->multi_ios)
2666 if (snd_BUG_ON(ch >= ARRAY_SIZE(channel_name)))
2669 return channel_name[ch];
2672 /* create input playback/capture controls for the given pin */
2673 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
2674 const char *ctlname, int ctlidx,
2675 int idx, hda_nid_t mix_nid)
2679 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
2680 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2683 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
2684 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2690 static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
2692 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2693 return (pincap & AC_PINCAP_IN) != 0;
2696 /* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
2697 static int alc_auto_fill_adc_caps(struct hda_codec *codec)
2699 struct alc_spec *spec = codec->spec;
2701 hda_nid_t *adc_nids = spec->private_adc_nids;
2702 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2703 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
2706 if (spec->shared_mic_hp)
2707 max_nums = 1; /* no multi streams with the shared HP/mic */
2709 nid = codec->start_nid;
2710 for (i = 0; i < codec->num_nodes; i++, nid++) {
2712 const hda_nid_t *list;
2713 unsigned int caps = get_wcaps(codec, nid);
2714 int type = get_wcaps_type(caps);
2716 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2718 adc_nids[nums] = nid;
2719 cap_nids[nums] = nid;
2723 type = get_wcaps_type(get_wcaps(codec, src));
2724 if (type == AC_WID_PIN)
2726 if (type == AC_WID_AUD_SEL) {
2727 cap_nids[nums] = src;
2730 n = snd_hda_get_conn_list(codec, src, &list);
2732 cap_nids[nums] = src;
2738 if (++nums >= max_nums)
2741 spec->adc_nids = spec->private_adc_nids;
2742 spec->capsrc_nids = spec->private_capsrc_nids;
2743 spec->num_adc_nids = nums;
2747 /* create playback/capture controls for input pins */
2748 static int alc_auto_create_input_ctls(struct hda_codec *codec)
2750 struct alc_spec *spec = codec->spec;
2751 const struct auto_pin_cfg *cfg = &spec->autocfg;
2752 hda_nid_t mixer = spec->mixer_nid;
2753 struct hda_input_mux *imux = &spec->private_imux[0];
2755 int i, c, err, idx, type_idx = 0;
2756 const char *prev_label = NULL;
2758 num_adcs = alc_auto_fill_adc_caps(codec);
2762 for (i = 0; i < cfg->num_inputs; i++) {
2766 pin = cfg->inputs[i].pin;
2767 if (!alc_is_input_pin(codec, pin))
2770 label = hda_get_autocfg_input_label(codec, cfg, i);
2771 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
2772 label = "Headphone Mic";
2773 if (prev_label && !strcmp(label, prev_label))
2780 idx = get_connection_index(codec, mixer, pin);
2782 err = new_analog_input(spec, pin,
2790 for (c = 0; c < num_adcs; c++) {
2791 hda_nid_t cap = get_capsrc(spec, c);
2792 idx = get_connection_index(codec, cap, pin);
2794 spec->imux_pins[imux->num_items] = pin;
2795 snd_hda_add_imux_item(imux, label, idx, NULL);
2801 spec->num_mux_defs = 1;
2802 spec->input_mux = imux;
2807 /* create a shared input with the headphone out */
2808 static int alc_auto_create_shared_input(struct hda_codec *codec)
2810 struct alc_spec *spec = codec->spec;
2811 struct auto_pin_cfg *cfg = &spec->autocfg;
2812 unsigned int defcfg;
2815 /* only one internal input pin? */
2816 if (cfg->num_inputs != 1)
2818 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2819 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2822 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
2823 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
2824 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
2825 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
2827 return 0; /* both not available */
2829 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2830 return 0; /* no input */
2832 cfg->inputs[1].pin = nid;
2833 cfg->inputs[1].type = AUTO_PIN_MIC;
2834 cfg->num_inputs = 2;
2835 spec->shared_mic_hp = 1;
2836 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
2840 static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
2841 unsigned int pin_type)
2843 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2846 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2847 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2851 static int get_pin_type(int line_out_type)
2853 if (line_out_type == AUTO_PIN_HP_OUT)
2859 static void alc_auto_init_analog_input(struct hda_codec *codec)
2861 struct alc_spec *spec = codec->spec;
2862 struct auto_pin_cfg *cfg = &spec->autocfg;
2865 for (i = 0; i < cfg->num_inputs; i++) {
2866 hda_nid_t nid = cfg->inputs[i].pin;
2867 if (alc_is_input_pin(codec, nid)) {
2868 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
2869 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
2870 snd_hda_codec_write(codec, nid, 0,
2871 AC_VERB_SET_AMP_GAIN_MUTE,
2876 /* mute all loopback inputs */
2877 if (spec->mixer_nid) {
2878 int nums = snd_hda_get_conn_list(codec, spec->mixer_nid, NULL);
2879 for (i = 0; i < nums; i++)
2880 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2881 AC_VERB_SET_AMP_GAIN_MUTE,
2886 /* convert from MIX nid to DAC */
2887 static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid)
2892 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT)
2894 num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list));
2895 for (i = 0; i < num; i++) {
2896 if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT)
2902 /* go down to the selector widget before the mixer */
2903 static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin)
2906 int num = snd_hda_get_connections(codec, pin, srcs,
2909 get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL)
2914 /* get MIX nid connected to the given pin targeted to DAC */
2915 static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
2921 pin = alc_go_down_to_selector(codec, pin);
2922 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2923 for (i = 0; i < num; i++) {
2924 if (alc_auto_mix_to_dac(codec, mix[i]) == dac)
2930 /* select the connection from pin to DAC if needed */
2931 static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin,
2937 pin = alc_go_down_to_selector(codec, pin);
2938 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2941 for (i = 0; i < num; i++) {
2942 if (alc_auto_mix_to_dac(codec, mix[i]) == dac) {
2943 snd_hda_codec_update_cache(codec, pin, 0,
2944 AC_VERB_SET_CONNECT_SEL, i);
2951 /* look for an empty DAC slot */
2952 static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
2954 struct alc_spec *spec = codec->spec;
2958 pin = alc_go_down_to_selector(codec, pin);
2959 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
2960 for (i = 0; i < num; i++) {
2961 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
2964 if (found_in_nid_list(nid, spec->multiout.dac_nids,
2965 ARRAY_SIZE(spec->private_dac_nids)))
2967 if (found_in_nid_list(nid, spec->multiout.hp_out_nid,
2968 ARRAY_SIZE(spec->multiout.hp_out_nid)))
2970 if (found_in_nid_list(nid, spec->multiout.extra_out_nid,
2971 ARRAY_SIZE(spec->multiout.extra_out_nid)))
2978 /* check whether the DAC is reachable from the pin */
2979 static bool alc_auto_is_dac_reachable(struct hda_codec *codec,
2980 hda_nid_t pin, hda_nid_t dac)
2985 pin = alc_go_down_to_selector(codec, pin);
2986 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
2987 for (i = 0; i < num; i++) {
2988 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
2995 static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
2997 hda_nid_t sel = alc_go_down_to_selector(codec, pin);
2998 if (snd_hda_get_conn_list(codec, sel, NULL) == 1)
2999 return alc_auto_look_for_dac(codec, pin);
3003 /* return 0 if no possible DAC is found, 1 if one or more found */
3004 static int alc_auto_fill_extra_dacs(struct hda_codec *codec, int num_outs,
3005 const hda_nid_t *pins, hda_nid_t *dacs)
3009 if (num_outs && !dacs[0]) {
3010 dacs[0] = alc_auto_look_for_dac(codec, pins[0]);
3015 for (i = 1; i < num_outs; i++)
3016 dacs[i] = get_dac_if_single(codec, pins[i]);
3017 for (i = 1; i < num_outs; i++) {
3019 dacs[i] = alc_auto_look_for_dac(codec, pins[i]);
3024 static int alc_auto_fill_multi_ios(struct hda_codec *codec,
3025 unsigned int location, int offset);
3026 static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3027 hda_nid_t pin, hda_nid_t dac);
3029 /* fill in the dac_nids table from the parsed pin configuration */
3030 static int alc_auto_fill_dac_nids(struct hda_codec *codec)
3032 struct alc_spec *spec = codec->spec;
3033 struct auto_pin_cfg *cfg = &spec->autocfg;
3034 unsigned int location, defcfg;
3036 bool redone = false;
3040 /* set num_dacs once to full for alc_auto_look_for_dac() */
3041 spec->multiout.num_dacs = cfg->line_outs;
3042 spec->multiout.hp_out_nid[0] = 0;
3043 spec->multiout.extra_out_nid[0] = 0;
3044 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
3045 spec->multiout.dac_nids = spec->private_dac_nids;
3046 spec->multi_ios = 0;
3048 /* fill hard-wired DACs first */
3050 for (i = 0; i < cfg->line_outs; i++)
3051 spec->private_dac_nids[i] =
3052 get_dac_if_single(codec, cfg->line_out_pins[i]);
3054 spec->multiout.hp_out_nid[0] =
3055 get_dac_if_single(codec, cfg->hp_pins[0]);
3056 if (cfg->speaker_outs)
3057 spec->multiout.extra_out_nid[0] =
3058 get_dac_if_single(codec, cfg->speaker_pins[0]);
3061 for (i = 0; i < cfg->line_outs; i++) {
3062 hda_nid_t pin = cfg->line_out_pins[i];
3063 if (spec->private_dac_nids[i])
3065 spec->private_dac_nids[i] = alc_auto_look_for_dac(codec, pin);
3066 if (!spec->private_dac_nids[i] && !redone) {
3067 /* if we can't find primary DACs, re-probe without
3068 * checking the hard-wired DACs
3075 /* re-count num_dacs and squash invalid entries */
3076 spec->multiout.num_dacs = 0;
3077 for (i = 0; i < cfg->line_outs; i++) {
3078 if (spec->private_dac_nids[i])
3079 spec->multiout.num_dacs++;
3081 memmove(spec->private_dac_nids + i,
3082 spec->private_dac_nids + i + 1,
3083 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
3084 spec->private_dac_nids[cfg->line_outs - 1] = 0;
3088 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3089 /* try to fill multi-io first */
3090 defcfg = snd_hda_codec_get_pincfg(codec, cfg->line_out_pins[0]);
3091 location = get_defcfg_location(defcfg);
3093 num_pins = alc_auto_fill_multi_ios(codec, location, 0);
3095 spec->multi_ios = num_pins;
3096 spec->ext_channel_count = 2;
3097 spec->multiout.num_dacs = num_pins + 1;
3101 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
3102 alc_auto_fill_extra_dacs(codec, cfg->hp_outs, cfg->hp_pins,
3103 spec->multiout.hp_out_nid);
3104 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3105 int err = alc_auto_fill_extra_dacs(codec, cfg->speaker_outs,
3107 spec->multiout.extra_out_nid);
3108 /* if no speaker volume is assigned, try again as the primary
3111 if (!err && cfg->speaker_outs > 0 &&
3112 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3113 cfg->hp_outs = cfg->line_outs;
3114 memcpy(cfg->hp_pins, cfg->line_out_pins,
3115 sizeof(cfg->hp_pins));
3116 cfg->line_outs = cfg->speaker_outs;
3117 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3118 sizeof(cfg->speaker_pins));
3119 cfg->speaker_outs = 0;
3120 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3121 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
3127 if (!spec->multi_ios &&
3128 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
3130 /* try multi-ios with HP + inputs */
3131 defcfg = snd_hda_codec_get_pincfg(codec, cfg->hp_pins[0]);
3132 location = get_defcfg_location(defcfg);
3134 num_pins = alc_auto_fill_multi_ios(codec, location, 1);
3136 spec->multi_ios = num_pins;
3137 spec->ext_channel_count = 2;
3138 spec->multiout.num_dacs = num_pins + 1;
3142 if (cfg->line_out_pins[0])
3144 alc_look_for_out_vol_nid(codec, cfg->line_out_pins[0],
3145 spec->multiout.dac_nids[0]);
3149 static inline unsigned int get_ctl_pos(unsigned int data)
3151 hda_nid_t nid = get_amp_nid_(data);
3152 unsigned int dir = get_amp_direction_(data);
3153 return (nid << 1) | dir;
3156 #define is_ctl_used(bits, data) \
3157 test_bit(get_ctl_pos(data), bits)
3158 #define mark_ctl_usage(bits, data) \
3159 set_bit(get_ctl_pos(data), bits)
3161 static int alc_auto_add_vol_ctl(struct hda_codec *codec,
3162 const char *pfx, int cidx,
3163 hda_nid_t nid, unsigned int chs)
3165 struct alc_spec *spec = codec->spec;
3169 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3170 if (is_ctl_used(spec->vol_ctls, val) && chs != 2) /* exclude LFE */
3172 mark_ctl_usage(spec->vol_ctls, val);
3173 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
3177 static int alc_auto_add_stereo_vol(struct hda_codec *codec,
3178 const char *pfx, int cidx,
3182 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3184 return alc_auto_add_vol_ctl(codec, pfx, cidx, nid, chs);
3187 /* create a mute-switch for the given mixer widget;
3188 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3190 static int alc_auto_add_sw_ctl(struct hda_codec *codec,
3191 const char *pfx, int cidx,
3192 hda_nid_t nid, unsigned int chs)
3194 struct alc_spec *spec = codec->spec;
3200 wid_type = get_wcaps_type(get_wcaps(codec, nid));
3201 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) {
3202 type = ALC_CTL_WIDGET_MUTE;
3203 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3204 } else if (snd_hda_get_conn_list(codec, nid, NULL) == 1) {
3205 type = ALC_CTL_WIDGET_MUTE;
3206 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
3208 type = ALC_CTL_BIND_MUTE;
3209 val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
3211 if (is_ctl_used(spec->sw_ctls, val) && chs != 2) /* exclude LFE */
3213 mark_ctl_usage(spec->sw_ctls, val);
3214 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
3217 static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
3218 int cidx, hda_nid_t nid)
3221 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3223 return alc_auto_add_sw_ctl(codec, pfx, cidx, nid, chs);
3226 static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3227 hda_nid_t pin, hda_nid_t dac)
3229 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3230 if (nid_has_mute(codec, pin, HDA_OUTPUT))
3232 else if (mix && nid_has_mute(codec, mix, HDA_INPUT))
3234 else if (nid_has_mute(codec, dac, HDA_OUTPUT))
3239 static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3240 hda_nid_t pin, hda_nid_t dac)
3242 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3243 if (nid_has_volume(codec, dac, HDA_OUTPUT))
3245 else if (nid_has_volume(codec, mix, HDA_OUTPUT))
3247 else if (nid_has_volume(codec, pin, HDA_OUTPUT))
3252 /* add playback controls from the parsed DAC table */
3253 static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
3254 const struct auto_pin_cfg *cfg)
3256 struct alc_spec *spec = codec->spec;
3257 int i, err, noutputs;
3259 noutputs = cfg->line_outs;
3260 if (spec->multi_ios > 0 && cfg->line_outs < 3)
3261 noutputs += spec->multi_ios;
3263 for (i = 0; i < noutputs; i++) {
3269 dac = spec->multiout.dac_nids[i];
3272 if (i >= cfg->line_outs)
3273 pin = spec->multi_io[i - 1].pin;
3275 pin = cfg->line_out_pins[i];
3277 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3278 vol = alc_look_for_out_vol_nid(codec, pin, dac);
3279 name = alc_get_line_out_pfx(spec, i, true, &index);
3280 if (!name || !strcmp(name, "CLFE")) {
3282 err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1);
3285 err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2);
3288 err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1);
3291 err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2);
3295 err = alc_auto_add_stereo_vol(codec, name, index, vol);
3298 err = alc_auto_add_stereo_sw(codec, name, index, sw);
3306 static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
3307 hda_nid_t dac, const char *pfx,
3310 struct alc_spec *spec = codec->spec;
3316 /* the corresponding DAC is already occupied */
3317 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
3318 return 0; /* no way */
3319 /* create a switch only */
3320 val = HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT);
3321 if (is_ctl_used(spec->sw_ctls, val))
3322 return 0; /* already created */
3323 mark_ctl_usage(spec->sw_ctls, val);
3324 return __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, cidx, val);
3327 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3328 vol = alc_look_for_out_vol_nid(codec, pin, dac);
3329 err = alc_auto_add_stereo_vol(codec, pfx, cidx, vol);
3332 err = alc_auto_add_stereo_sw(codec, pfx, cidx, sw);
3338 static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3340 struct hda_ctl_ops *ops)
3342 struct alc_spec *spec = codec->spec;
3343 struct hda_bind_ctls **ctlp, *ctl;
3344 snd_array_init(&spec->bind_ctls, sizeof(ctl), 8);
3345 ctlp = snd_array_new(&spec->bind_ctls);
3348 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3355 /* add playback controls for speaker and HP outputs */
3356 static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3357 const hda_nid_t *pins,
3358 const hda_nid_t *dacs,
3361 struct alc_spec *spec = codec->spec;
3362 struct hda_bind_ctls *ctl;
3366 if (!num_pins || !pins[0])
3369 if (num_pins == 1) {
3370 hda_nid_t dac = *dacs;
3372 dac = spec->multiout.dac_nids[0];
3373 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
3376 if (dacs[num_pins - 1]) {
3377 /* OK, we have a multi-output system with individual volumes */
3378 for (i = 0; i < num_pins; i++) {
3379 if (num_pins >= 3) {
3380 snprintf(name, sizeof(name), "%s %s",
3381 pfx, channel_name[i]);
3382 err = alc_auto_create_extra_out(codec, pins[i], dacs[i],
3385 err = alc_auto_create_extra_out(codec, pins[i], dacs[i],
3394 /* Let's create a bind-controls */
3395 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_sw);
3399 for (i = 0; i < num_pins; i++) {
3400 if (get_wcaps(codec, pins[i]) & AC_WCAP_OUT_AMP)
3402 HDA_COMPOSE_AMP_VAL(pins[i], 3, 0, HDA_OUTPUT);
3405 snprintf(name, sizeof(name), "%s Playback Switch", pfx);
3406 err = add_control(spec, ALC_CTL_BIND_SW, name, 0, (long)ctl);
3411 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3415 for (i = 0; i < num_pins; i++) {
3417 if (!pins[i] || !dacs[i])
3419 vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]);
3422 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3425 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3426 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3433 static int alc_auto_create_hp_out(struct hda_codec *codec)
3435 struct alc_spec *spec = codec->spec;
3436 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3437 spec->autocfg.hp_pins,
3438 spec->multiout.hp_out_nid,
3442 static int alc_auto_create_speaker_out(struct hda_codec *codec)
3444 struct alc_spec *spec = codec->spec;
3445 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3446 spec->autocfg.speaker_pins,
3447 spec->multiout.extra_out_nid,
3451 static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
3452 hda_nid_t pin, int pin_type,
3456 hda_nid_t nid, mix = 0;
3457 hda_nid_t srcs[HDA_MAX_CONNECTIONS];
3459 alc_set_pin_output(codec, pin, pin_type);
3460 nid = alc_go_down_to_selector(codec, pin);
3461 num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
3462 for (i = 0; i < num; i++) {
3463 if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
3471 /* need the manual connection? */
3473 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
3474 /* unmute mixer widget inputs */
3475 if (nid_has_mute(codec, mix, HDA_INPUT)) {
3476 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3478 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3481 /* initialize volume */
3482 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3484 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3487 /* unmute DAC if it's not assigned to a mixer */
3488 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3489 if (nid == mix && nid_has_mute(codec, dac, HDA_OUTPUT))
3490 snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3494 static void alc_auto_init_multi_out(struct hda_codec *codec)
3496 struct alc_spec *spec = codec->spec;
3497 int pin_type = get_pin_type(spec->autocfg.line_out_type);
3500 for (i = 0; i <= HDA_SIDE; i++) {
3501 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3503 alc_auto_set_output_and_unmute(codec, nid, pin_type,
3504 spec->multiout.dac_nids[i]);
3508 static void alc_auto_init_extra_out(struct hda_codec *codec)
3510 struct alc_spec *spec = codec->spec;
3514 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3515 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3517 pin = spec->autocfg.hp_pins[i];
3520 dac = spec->multiout.hp_out_nid[i];
3522 if (i > 0 && spec->multiout.hp_out_nid[0])
3523 dac = spec->multiout.hp_out_nid[0];
3525 dac = spec->multiout.dac_nids[0];
3527 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
3529 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3530 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3532 pin = spec->autocfg.speaker_pins[i];
3535 dac = spec->multiout.extra_out_nid[i];
3537 if (i > 0 && spec->multiout.extra_out_nid[0])
3538 dac = spec->multiout.extra_out_nid[0];
3540 dac = spec->multiout.dac_nids[0];
3542 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
3549 static int alc_auto_fill_multi_ios(struct hda_codec *codec,
3550 unsigned int location,
3553 struct alc_spec *spec = codec->spec;
3554 struct auto_pin_cfg *cfg = &spec->autocfg;
3555 hda_nid_t prime_dac = spec->private_dac_nids[0];
3556 int type, i, dacs, num_pins = 0;
3558 dacs = spec->multiout.num_dacs;
3559 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3560 for (i = 0; i < cfg->num_inputs; i++) {
3561 hda_nid_t nid = cfg->inputs[i].pin;
3563 unsigned int defcfg, caps;
3564 if (cfg->inputs[i].type != type)
3566 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3567 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3569 if (location && get_defcfg_location(defcfg) != location)
3571 caps = snd_hda_query_pin_caps(codec, nid);
3572 if (!(caps & AC_PINCAP_OUT))
3574 if (offset && offset + num_pins < dacs) {
3575 dac = spec->private_dac_nids[offset + num_pins];
3576 if (!alc_auto_is_dac_reachable(codec, nid, dac))
3580 dac = alc_auto_look_for_dac(codec, nid);
3583 spec->multi_io[num_pins].pin = nid;
3584 spec->multi_io[num_pins].dac = dac;
3586 spec->private_dac_nids[spec->multiout.num_dacs++] = dac;
3589 spec->multiout.num_dacs = dacs;
3591 /* clear up again */
3592 memset(spec->private_dac_nids + dacs, 0,
3593 sizeof(hda_nid_t) * (AUTO_CFG_MAX_OUTS - dacs));
3594 spec->private_dac_nids[0] = prime_dac;
3600 static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
3601 struct snd_ctl_elem_info *uinfo)
3603 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3604 struct alc_spec *spec = codec->spec;
3606 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3608 uinfo->value.enumerated.items = spec->multi_ios + 1;
3609 if (uinfo->value.enumerated.item > spec->multi_ios)
3610 uinfo->value.enumerated.item = spec->multi_ios;
3611 sprintf(uinfo->value.enumerated.name, "%dch",
3612 (uinfo->value.enumerated.item + 1) * 2);
3616 static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
3617 struct snd_ctl_elem_value *ucontrol)
3619 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3620 struct alc_spec *spec = codec->spec;
3621 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
3625 static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
3627 struct alc_spec *spec = codec->spec;
3628 hda_nid_t nid = spec->multi_io[idx].pin;
3630 if (!spec->multi_io[idx].ctl_in)
3631 spec->multi_io[idx].ctl_in =
3632 snd_hda_codec_read(codec, nid, 0,
3633 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3635 snd_hda_codec_update_cache(codec, nid, 0,
3636 AC_VERB_SET_PIN_WIDGET_CONTROL,
3638 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3639 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3641 alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
3643 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3644 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3645 HDA_AMP_MUTE, HDA_AMP_MUTE);
3646 snd_hda_codec_update_cache(codec, nid, 0,
3647 AC_VERB_SET_PIN_WIDGET_CONTROL,
3648 spec->multi_io[idx].ctl_in);
3653 static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
3654 struct snd_ctl_elem_value *ucontrol)
3656 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3657 struct alc_spec *spec = codec->spec;
3660 ch = ucontrol->value.enumerated.item[0];
3661 if (ch < 0 || ch > spec->multi_ios)
3663 if (ch == (spec->ext_channel_count - 1) / 2)
3665 spec->ext_channel_count = (ch + 1) * 2;
3666 for (i = 0; i < spec->multi_ios; i++)
3667 alc_set_multi_io(codec, i, i < ch);
3668 spec->multiout.max_channels = spec->ext_channel_count;
3669 if (spec->need_dac_fix && !spec->const_channel_count)
3670 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
3674 static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
3675 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3676 .name = "Channel Mode",
3677 .info = alc_auto_ch_mode_info,
3678 .get = alc_auto_ch_mode_get,
3679 .put = alc_auto_ch_mode_put,
3682 static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
3684 struct alc_spec *spec = codec->spec;
3686 if (spec->multi_ios > 0) {
3687 struct snd_kcontrol_new *knew;
3689 knew = alc_kcontrol_new(spec);
3692 *knew = alc_auto_channel_mode_enum;
3693 knew->name = kstrdup("Channel Mode", GFP_KERNEL);
3700 /* filter out invalid adc_nids (and capsrc_nids) that don't give all
3703 static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
3705 struct alc_spec *spec = codec->spec;
3706 const struct hda_input_mux *imux;
3707 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3708 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3711 imux = spec->input_mux;
3714 if (spec->dyn_adc_switch)
3718 for (n = 0; n < spec->num_adc_nids; n++) {
3719 hda_nid_t cap = spec->private_capsrc_nids[n];
3720 int num_conns = snd_hda_get_conn_list(codec, cap, NULL);
3721 for (i = 0; i < imux->num_items; i++) {
3722 hda_nid_t pin = spec->imux_pins[i];
3724 if (get_connection_index(codec, cap, pin) < 0)
3726 } else if (num_conns <= imux->items[i].index)
3729 if (i >= imux->num_items) {
3730 adc_nids[nums] = spec->private_adc_nids[n];
3731 capsrc_nids[nums++] = cap;
3735 /* check whether ADC-switch is possible */
3736 if (!alc_check_dyn_adc_switch(codec)) {
3737 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
3738 " using fallback 0x%x\n",
3739 codec->chip_name, spec->private_adc_nids[0]);
3740 spec->num_adc_nids = 1;
3744 } else if (nums != spec->num_adc_nids) {
3745 memcpy(spec->private_adc_nids, adc_nids,
3746 nums * sizeof(hda_nid_t));
3747 memcpy(spec->private_capsrc_nids, capsrc_nids,
3748 nums * sizeof(hda_nid_t));
3749 spec->num_adc_nids = nums;
3753 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
3754 else if (spec->input_mux->num_items == 1)
3755 spec->num_adc_nids = 1; /* reduce to a single ADC */
3759 * initialize ADC paths
3761 static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
3763 struct alc_spec *spec = codec->spec;
3766 nid = spec->adc_nids[adc_idx];
3768 if (nid_has_mute(codec, nid, HDA_INPUT)) {
3769 snd_hda_codec_write(codec, nid, 0,
3770 AC_VERB_SET_AMP_GAIN_MUTE,
3774 if (!spec->capsrc_nids)
3776 nid = spec->capsrc_nids[adc_idx];
3777 if (nid_has_mute(codec, nid, HDA_OUTPUT))
3778 snd_hda_codec_write(codec, nid, 0,
3779 AC_VERB_SET_AMP_GAIN_MUTE,
3783 static void alc_auto_init_input_src(struct hda_codec *codec)
3785 struct alc_spec *spec = codec->spec;
3788 for (c = 0; c < spec->num_adc_nids; c++)
3789 alc_auto_init_adc(codec, c);
3790 if (spec->dyn_adc_switch)
3793 nums = spec->num_adc_nids;
3794 for (c = 0; c < nums; c++)
3795 alc_mux_select(codec, 0, spec->cur_mux[c], true);
3798 /* add mic boosts if needed */
3799 static int alc_auto_add_mic_boost(struct hda_codec *codec)
3801 struct alc_spec *spec = codec->spec;
3802 struct auto_pin_cfg *cfg = &spec->autocfg;
3806 const char *prev_label = NULL;
3808 for (i = 0; i < cfg->num_inputs; i++) {
3809 if (cfg->inputs[i].type > AUTO_PIN_MIC)
3811 nid = cfg->inputs[i].pin;
3812 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
3814 char boost_label[32];
3816 label = hda_get_autocfg_input_label(codec, cfg, i);
3817 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
3818 label = "Headphone Mic";
3819 if (prev_label && !strcmp(label, prev_label))
3825 snprintf(boost_label, sizeof(boost_label),
3826 "%s Boost Volume", label);
3827 err = add_control(spec, ALC_CTL_WIDGET_VOL,
3828 boost_label, type_idx,
3829 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
3837 /* select or unmute the given capsrc route */
3838 static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
3841 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
3842 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
3844 } else if (snd_hda_get_conn_list(codec, cap, NULL) > 1) {
3845 snd_hda_codec_write_cache(codec, cap, 0,
3846 AC_VERB_SET_CONNECT_SEL, idx);
3850 /* set the default connection to that pin */
3851 static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
3853 struct alc_spec *spec = codec->spec;
3858 for (i = 0; i < spec->num_adc_nids; i++) {
3859 hda_nid_t cap = get_capsrc(spec, i);
3862 idx = get_connection_index(codec, cap, pin);
3865 select_or_unmute_capsrc(codec, cap, idx);
3866 return i; /* return the found index */
3868 return -1; /* not found */
3871 /* initialize some special cases for input sources */
3872 static void alc_init_special_input_src(struct hda_codec *codec)
3874 struct alc_spec *spec = codec->spec;
3877 for (i = 0; i < spec->autocfg.num_inputs; i++)
3878 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
3881 /* assign appropriate capture mixers */
3882 static void set_capture_mixer(struct hda_codec *codec)
3884 struct alc_spec *spec = codec->spec;
3885 static const struct snd_kcontrol_new *caps[2][3] = {
3886 { alc_capture_mixer_nosrc1,
3887 alc_capture_mixer_nosrc2,
3888 alc_capture_mixer_nosrc3 },
3889 { alc_capture_mixer1,
3891 alc_capture_mixer3 },
3894 /* check whether either of ADC or MUX has a volume control */
3895 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
3896 if (!spec->capsrc_nids)
3897 return; /* no volume */
3898 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
3899 return; /* no volume in capsrc, too */
3900 spec->vol_in_capsrc = 1;
3903 if (spec->num_adc_nids > 0) {
3907 if (spec->input_mux && spec->input_mux->num_items > 1)
3909 if (spec->auto_mic) {
3912 } else if (spec->dyn_adc_switch)
3915 if (spec->num_adc_nids > 3)
3916 spec->num_adc_nids = 3;
3917 else if (!spec->num_adc_nids)
3919 num_adcs = spec->num_adc_nids;
3921 spec->cap_mixer = caps[mux][num_adcs - 1];
3926 * standard auto-parser initializations
3928 static void alc_auto_init_std(struct hda_codec *codec)
3930 struct alc_spec *spec = codec->spec;
3931 alc_auto_init_multi_out(codec);
3932 alc_auto_init_extra_out(codec);
3933 alc_auto_init_analog_input(codec);
3934 alc_auto_init_input_src(codec);
3935 alc_auto_init_digital(codec);
3936 if (spec->unsol_event)
3937 alc_inithook(codec);
3941 * Digital-beep handlers
3943 #ifdef CONFIG_SND_HDA_INPUT_BEEP
3944 #define set_beep_amp(spec, nid, idx, dir) \
3945 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
3947 static const struct snd_pci_quirk beep_white_list[] = {
3948 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
3949 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
3950 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
3951 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
3952 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
3956 static inline int has_cdefine_beep(struct hda_codec *codec)
3958 struct alc_spec *spec = codec->spec;
3959 const struct snd_pci_quirk *q;
3960 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
3963 return spec->cdefine.enable_pcbeep;
3966 #define set_beep_amp(spec, nid, idx, dir) /* NOP */
3967 #define has_cdefine_beep(codec) 0
3970 /* parse the BIOS configuration and set up the alc_spec */
3971 /* return 1 if successful, 0 if the proper config is not found,
3972 * or a negative error code
3974 static int alc_parse_auto_config(struct hda_codec *codec,
3975 const hda_nid_t *ignore_nids,
3976 const hda_nid_t *ssid_nids)
3978 struct alc_spec *spec = codec->spec;
3979 struct auto_pin_cfg *cfg = &spec->autocfg;
3982 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
3986 if (!cfg->line_outs) {
3987 if (cfg->dig_outs || cfg->dig_in_pin) {
3988 spec->multiout.max_channels = 2;
3989 spec->no_analog = 1;
3992 return 0; /* can't find valid BIOS pin config */
3995 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
3996 cfg->line_outs <= cfg->hp_outs) {
3997 /* use HP as primary out */
3998 cfg->speaker_outs = cfg->line_outs;
3999 memcpy(cfg->speaker_pins, cfg->line_out_pins,
4000 sizeof(cfg->speaker_pins));
4001 cfg->line_outs = cfg->hp_outs;
4002 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
4004 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
4005 cfg->line_out_type = AUTO_PIN_HP_OUT;
4008 err = alc_auto_fill_dac_nids(codec);
4011 err = alc_auto_add_multi_channel_mode(codec);
4014 err = alc_auto_create_multi_out_ctls(codec, cfg);
4017 err = alc_auto_create_hp_out(codec);
4020 err = alc_auto_create_speaker_out(codec);
4023 err = alc_auto_create_shared_input(codec);
4026 err = alc_auto_create_input_ctls(codec);
4030 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4033 alc_auto_parse_digital(codec);
4035 if (!spec->no_analog)
4036 alc_remove_invalid_adc_nids(codec);
4039 alc_ssid_check(codec, ssid_nids);
4041 if (!spec->no_analog) {
4042 alc_auto_check_switches(codec);
4043 err = alc_auto_add_mic_boost(codec);
4048 if (spec->kctls.list)
4049 add_mixer(spec, spec->kctls.list);
4054 static int alc880_parse_auto_config(struct hda_codec *codec)
4056 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
4057 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4058 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
4061 #ifdef CONFIG_SND_HDA_POWER_SAVE
4062 static const struct hda_amp_list alc880_loopbacks[] = {
4063 { 0x0b, HDA_INPUT, 0 },
4064 { 0x0b, HDA_INPUT, 1 },
4065 { 0x0b, HDA_INPUT, 2 },
4066 { 0x0b, HDA_INPUT, 3 },
4067 { 0x0b, HDA_INPUT, 4 },
4077 ALC880_FIXUP_MEDION_RIM,
4080 static const struct alc_fixup alc880_fixups[] = {
4081 [ALC880_FIXUP_GPIO2] = {
4082 .type = ALC_FIXUP_VERBS,
4083 .v.verbs = alc_gpio2_init_verbs,
4085 [ALC880_FIXUP_MEDION_RIM] = {
4086 .type = ALC_FIXUP_VERBS,
4087 .v.verbs = (const struct hda_verb[]) {
4088 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4089 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4093 .chain_id = ALC880_FIXUP_GPIO2,
4097 static const struct snd_pci_quirk alc880_fixup_tbl[] = {
4098 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
4106 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4107 #define alc_board_config \
4108 snd_hda_check_board_config
4109 #define alc_board_codec_sid_config \
4110 snd_hda_check_board_codec_sid_config
4111 #include "alc_quirks.c"
4113 #define alc_board_config(codec, nums, models, tbl) -1
4114 #define alc_board_codec_sid_config(codec, nums, models, tbl) -1
4115 #define setup_preset(codec, x) /* NOP */
4119 * OK, here we have finally the patch for ALC880
4121 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4122 #include "alc880_quirks.c"
4125 static int patch_alc880(struct hda_codec *codec)
4127 struct alc_spec *spec;
4131 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4137 spec->mixer_nid = 0x0b;
4138 spec->need_dac_fix = 1;
4140 board_config = alc_board_config(codec, ALC880_MODEL_LAST,
4141 alc880_models, alc880_cfg_tbl);
4142 if (board_config < 0) {
4143 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4145 board_config = ALC_MODEL_AUTO;
4148 if (board_config == ALC_MODEL_AUTO) {
4149 alc_pick_fixup(codec, NULL, alc880_fixup_tbl, alc880_fixups);
4150 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4153 if (board_config == ALC_MODEL_AUTO) {
4154 /* automatic parse from the BIOS config */
4155 err = alc880_parse_auto_config(codec);
4158 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4161 "hda_codec: Cannot set up configuration "
4162 "from BIOS. Using 3-stack mode...\n");
4163 board_config = ALC880_3ST;
4168 if (board_config != ALC_MODEL_AUTO) {
4169 spec->vmaster_nid = 0x0c;
4170 setup_preset(codec, &alc880_presets[board_config]);
4173 if (!spec->no_analog && !spec->adc_nids) {
4174 alc_auto_fill_adc_caps(codec);
4175 alc_rebuild_imux_for_auto_mic(codec);
4176 alc_remove_invalid_adc_nids(codec);
4179 if (!spec->no_analog && !spec->cap_mixer)
4180 set_capture_mixer(codec);
4182 if (!spec->no_analog) {
4183 err = snd_hda_attach_beep_device(codec, 0x1);
4186 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4189 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4191 codec->patch_ops = alc_patch_ops;
4192 if (board_config == ALC_MODEL_AUTO)
4193 spec->init_hook = alc_auto_init_std;
4195 codec->patch_ops.build_controls = __alc_build_controls;
4196 #ifdef CONFIG_SND_HDA_POWER_SAVE
4197 if (!spec->loopback.amplist)
4198 spec->loopback.amplist = alc880_loopbacks;
4212 static int alc260_parse_auto_config(struct hda_codec *codec)
4214 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
4215 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
4216 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
4219 #ifdef CONFIG_SND_HDA_POWER_SAVE
4220 static const struct hda_amp_list alc260_loopbacks[] = {
4221 { 0x07, HDA_INPUT, 0 },
4222 { 0x07, HDA_INPUT, 1 },
4223 { 0x07, HDA_INPUT, 2 },
4224 { 0x07, HDA_INPUT, 3 },
4225 { 0x07, HDA_INPUT, 4 },
4237 static const struct alc_fixup alc260_fixups[] = {
4238 [PINFIX_HP_DC5750] = {
4239 .type = ALC_FIXUP_PINS,
4240 .v.pins = (const struct alc_pincfg[]) {
4241 { 0x11, 0x90130110 }, /* speaker */
4247 static const struct snd_pci_quirk alc260_fixup_tbl[] = {
4248 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", PINFIX_HP_DC5750),
4254 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4255 #include "alc260_quirks.c"
4258 static int patch_alc260(struct hda_codec *codec)
4260 struct alc_spec *spec;
4261 int err, board_config;
4263 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4269 spec->mixer_nid = 0x07;
4271 board_config = alc_board_config(codec, ALC260_MODEL_LAST,
4272 alc260_models, alc260_cfg_tbl);
4273 if (board_config < 0) {
4274 snd_printd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4276 board_config = ALC_MODEL_AUTO;
4279 if (board_config == ALC_MODEL_AUTO) {
4280 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
4281 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4284 if (board_config == ALC_MODEL_AUTO) {
4285 /* automatic parse from the BIOS config */
4286 err = alc260_parse_auto_config(codec);
4289 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4292 "hda_codec: Cannot set up configuration "
4293 "from BIOS. Using base mode...\n");
4294 board_config = ALC260_BASIC;
4299 if (board_config != ALC_MODEL_AUTO) {
4300 setup_preset(codec, &alc260_presets[board_config]);
4301 spec->vmaster_nid = 0x08;
4304 if (!spec->no_analog && !spec->adc_nids) {
4305 alc_auto_fill_adc_caps(codec);
4306 alc_rebuild_imux_for_auto_mic(codec);
4307 alc_remove_invalid_adc_nids(codec);
4310 if (!spec->no_analog && !spec->cap_mixer)
4311 set_capture_mixer(codec);
4313 if (!spec->no_analog) {
4314 err = snd_hda_attach_beep_device(codec, 0x1);
4317 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
4320 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4322 codec->patch_ops = alc_patch_ops;
4323 if (board_config == ALC_MODEL_AUTO)
4324 spec->init_hook = alc_auto_init_std;
4326 codec->patch_ops.build_controls = __alc_build_controls;
4327 spec->shutup = alc_eapd_shutup;
4328 #ifdef CONFIG_SND_HDA_POWER_SAVE
4329 if (!spec->loopback.amplist)
4330 spec->loopback.amplist = alc260_loopbacks;
4342 * ALC882/883/885/888/889 support
4344 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
4345 * configuration. Each pin widget can choose any input DACs and a mixer.
4346 * Each ADC is connected from a mixer of all inputs. This makes possible
4347 * 6-channel independent captures.
4349 * In addition, an independent DAC for the multi-playback (not used in this
4352 #ifdef CONFIG_SND_HDA_POWER_SAVE
4353 #define alc882_loopbacks alc880_loopbacks
4360 ALC882_FIXUP_ABIT_AW9D_MAX,
4361 ALC882_FIXUP_LENOVO_Y530,
4362 ALC882_FIXUP_PB_M5210,
4363 ALC882_FIXUP_ACER_ASPIRE_7736,
4364 ALC882_FIXUP_ASUS_W90V,
4365 ALC889_FIXUP_VAIO_TT,
4366 ALC888_FIXUP_EEE1601,
4369 ALC883_FIXUP_ACER_EAPD,
4372 ALC882_FIXUP_ASUS_W2JC,
4373 ALC882_FIXUP_ACER_ASPIRE_4930G,
4374 ALC882_FIXUP_ACER_ASPIRE_8930G,
4375 ALC882_FIXUP_ASPIRE_8930G_VERBS,
4376 ALC885_FIXUP_MACPRO_GPIO,
4377 ALC889_FIXUP_DAC_ROUTE,
4380 static void alc889_fixup_coef(struct hda_codec *codec,
4381 const struct alc_fixup *fix, int action)
4383 if (action != ALC_FIXUP_ACT_INIT)
4385 alc889_coef_init(codec);
4388 /* toggle speaker-output according to the hp-jack state */
4389 static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
4391 unsigned int gpiostate, gpiomask, gpiodir;
4393 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
4394 AC_VERB_GET_GPIO_DATA, 0);
4397 gpiostate |= (1 << pin);
4399 gpiostate &= ~(1 << pin);
4401 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
4402 AC_VERB_GET_GPIO_MASK, 0);
4403 gpiomask |= (1 << pin);
4405 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
4406 AC_VERB_GET_GPIO_DIRECTION, 0);
4407 gpiodir |= (1 << pin);
4410 snd_hda_codec_write(codec, codec->afg, 0,
4411 AC_VERB_SET_GPIO_MASK, gpiomask);
4412 snd_hda_codec_write(codec, codec->afg, 0,
4413 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
4417 snd_hda_codec_write(codec, codec->afg, 0,
4418 AC_VERB_SET_GPIO_DATA, gpiostate);
4421 /* set up GPIO at initialization */
4422 static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
4423 const struct alc_fixup *fix, int action)
4425 if (action != ALC_FIXUP_ACT_INIT)
4427 alc882_gpio_mute(codec, 0, 0);
4428 alc882_gpio_mute(codec, 1, 0);
4431 /* Fix the connection of some pins for ALC889:
4432 * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
4433 * work correctly (bko#42740)
4435 static void alc889_fixup_dac_route(struct hda_codec *codec,
4436 const struct alc_fixup *fix, int action)
4438 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
4439 hda_nid_t conn1[2] = { 0x0c, 0x0d };
4440 hda_nid_t conn2[2] = { 0x0e, 0x0f };
4441 snd_hda_override_conn_list(codec, 0x14, 2, conn1);
4442 snd_hda_override_conn_list(codec, 0x15, 2, conn1);
4443 snd_hda_override_conn_list(codec, 0x18, 2, conn2);
4444 snd_hda_override_conn_list(codec, 0x1a, 2, conn2);
4448 static const struct alc_fixup alc882_fixups[] = {
4449 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
4450 .type = ALC_FIXUP_PINS,
4451 .v.pins = (const struct alc_pincfg[]) {
4452 { 0x15, 0x01080104 }, /* side */
4453 { 0x16, 0x01011012 }, /* rear */
4454 { 0x17, 0x01016011 }, /* clfe */
4458 [ALC882_FIXUP_LENOVO_Y530] = {
4459 .type = ALC_FIXUP_PINS,
4460 .v.pins = (const struct alc_pincfg[]) {
4461 { 0x15, 0x99130112 }, /* rear int speakers */
4462 { 0x16, 0x99130111 }, /* subwoofer */
4466 [ALC882_FIXUP_PB_M5210] = {
4467 .type = ALC_FIXUP_VERBS,
4468 .v.verbs = (const struct hda_verb[]) {
4469 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
4473 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
4474 .type = ALC_FIXUP_SKU,
4475 .v.sku = ALC_FIXUP_SKU_IGNORE,
4477 [ALC882_FIXUP_ASUS_W90V] = {
4478 .type = ALC_FIXUP_PINS,
4479 .v.pins = (const struct alc_pincfg[]) {
4480 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
4484 [ALC889_FIXUP_VAIO_TT] = {
4485 .type = ALC_FIXUP_PINS,
4486 .v.pins = (const struct alc_pincfg[]) {
4487 { 0x17, 0x90170111 }, /* hidden surround speaker */
4491 [ALC888_FIXUP_EEE1601] = {
4492 .type = ALC_FIXUP_VERBS,
4493 .v.verbs = (const struct hda_verb[]) {
4494 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
4495 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
4499 [ALC882_FIXUP_EAPD] = {
4500 .type = ALC_FIXUP_VERBS,
4501 .v.verbs = (const struct hda_verb[]) {
4502 /* change to EAPD mode */
4503 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4504 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4508 [ALC883_FIXUP_EAPD] = {
4509 .type = ALC_FIXUP_VERBS,
4510 .v.verbs = (const struct hda_verb[]) {
4511 /* change to EAPD mode */
4512 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4513 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4517 [ALC883_FIXUP_ACER_EAPD] = {
4518 .type = ALC_FIXUP_VERBS,
4519 .v.verbs = (const struct hda_verb[]) {
4520 /* eanable EAPD on Acer laptops */
4521 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4522 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4526 [ALC882_FIXUP_GPIO3] = {
4527 .type = ALC_FIXUP_VERBS,
4528 .v.verbs = alc_gpio3_init_verbs,
4530 [ALC882_FIXUP_ASUS_W2JC] = {
4531 .type = ALC_FIXUP_VERBS,
4532 .v.verbs = alc_gpio1_init_verbs,
4534 .chain_id = ALC882_FIXUP_EAPD,
4536 [ALC889_FIXUP_COEF] = {
4537 .type = ALC_FIXUP_FUNC,
4538 .v.func = alc889_fixup_coef,
4540 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
4541 .type = ALC_FIXUP_PINS,
4542 .v.pins = (const struct alc_pincfg[]) {
4543 { 0x16, 0x99130111 }, /* CLFE speaker */
4544 { 0x17, 0x99130112 }, /* surround speaker */
4548 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
4549 .type = ALC_FIXUP_PINS,
4550 .v.pins = (const struct alc_pincfg[]) {
4551 { 0x16, 0x99130111 }, /* CLFE speaker */
4552 { 0x1b, 0x99130112 }, /* surround speaker */
4556 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
4558 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
4559 /* additional init verbs for Acer Aspire 8930G */
4560 .type = ALC_FIXUP_VERBS,
4561 .v.verbs = (const struct hda_verb[]) {
4562 /* Enable all DACs */
4563 /* DAC DISABLE/MUTE 1? */
4564 /* setting bits 1-5 disables DAC nids 0x02-0x06
4565 * apparently. Init=0x38 */
4566 { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
4567 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
4568 /* DAC DISABLE/MUTE 2? */
4569 /* some bit here disables the other DACs.
4571 { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
4572 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
4574 * This laptop has a stereo digital microphone.
4575 * The mics are only 1cm apart which makes the stereo
4576 * useless. However, either the mic or the ALC889
4577 * makes the signal become a difference/sum signal
4578 * instead of standard stereo, which is annoying.
4579 * So instead we flip this bit which makes the
4580 * codec replicate the sum signal to both channels,
4581 * turning it into a normal mono mic.
4583 /* DMIC_CONTROL? Init value = 0x0001 */
4584 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
4585 { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
4586 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4587 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4591 [ALC885_FIXUP_MACPRO_GPIO] = {
4592 .type = ALC_FIXUP_FUNC,
4593 .v.func = alc885_fixup_macpro_gpio,
4595 [ALC889_FIXUP_DAC_ROUTE] = {
4596 .type = ALC_FIXUP_FUNC,
4597 .v.func = alc889_fixup_dac_route,
4601 static const struct snd_pci_quirk alc882_fixup_tbl[] = {
4602 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
4603 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
4604 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
4605 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
4606 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
4607 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
4608 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
4609 ALC882_FIXUP_ACER_ASPIRE_4930G),
4610 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
4611 ALC882_FIXUP_ACER_ASPIRE_4930G),
4612 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
4613 ALC882_FIXUP_ACER_ASPIRE_8930G),
4614 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
4615 ALC882_FIXUP_ACER_ASPIRE_8930G),
4616 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
4617 ALC882_FIXUP_ACER_ASPIRE_4930G),
4618 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
4619 ALC882_FIXUP_ACER_ASPIRE_4930G),
4620 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
4621 ALC882_FIXUP_ACER_ASPIRE_4930G),
4622 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
4623 SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE),
4624 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
4625 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
4626 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
4627 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
4628 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
4629 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
4631 /* All Apple entries are in codec SSIDs */
4632 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
4633 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
4634 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
4635 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
4636 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
4638 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
4639 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
4640 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
4641 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
4642 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
4643 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
4644 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
4649 * BIOS auto configuration
4651 /* almost identical with ALC880 parser... */
4652 static int alc882_parse_auto_config(struct hda_codec *codec)
4654 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
4655 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4656 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
4661 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4662 #include "alc882_quirks.c"
4665 static int patch_alc882(struct hda_codec *codec)
4667 struct alc_spec *spec;
4668 int err, board_config;
4670 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4676 spec->mixer_nid = 0x0b;
4678 switch (codec->vendor_id) {
4683 /* ALC883 and variants */
4684 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
4688 err = alc_codec_rename_from_preset(codec);
4692 board_config = alc_board_config(codec, ALC882_MODEL_LAST,
4693 alc882_models, NULL);
4694 if (board_config < 0)
4695 board_config = alc_board_codec_sid_config(codec,
4696 ALC882_MODEL_LAST, alc882_models, alc882_ssid_cfg_tbl);
4698 if (board_config < 0) {
4699 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4701 board_config = ALC_MODEL_AUTO;
4704 if (board_config == ALC_MODEL_AUTO) {
4705 alc_pick_fixup(codec, NULL, alc882_fixup_tbl, alc882_fixups);
4706 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4709 alc_auto_parse_customize_define(codec);
4711 if (board_config == ALC_MODEL_AUTO) {
4712 /* automatic parse from the BIOS config */
4713 err = alc882_parse_auto_config(codec);
4718 if (board_config != ALC_MODEL_AUTO) {
4719 setup_preset(codec, &alc882_presets[board_config]);
4720 spec->vmaster_nid = 0x0c;
4723 if (!spec->no_analog && !spec->adc_nids) {
4724 alc_auto_fill_adc_caps(codec);
4725 alc_rebuild_imux_for_auto_mic(codec);
4726 alc_remove_invalid_adc_nids(codec);
4729 if (!spec->no_analog && !spec->cap_mixer)
4730 set_capture_mixer(codec);
4732 if (!spec->no_analog && has_cdefine_beep(codec)) {
4733 err = snd_hda_attach_beep_device(codec, 0x1);
4736 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4739 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4741 codec->patch_ops = alc_patch_ops;
4742 if (board_config == ALC_MODEL_AUTO)
4743 spec->init_hook = alc_auto_init_std;
4745 codec->patch_ops.build_controls = __alc_build_controls;
4747 #ifdef CONFIG_SND_HDA_POWER_SAVE
4748 if (!spec->loopback.amplist)
4749 spec->loopback.amplist = alc882_loopbacks;
4763 static int alc262_parse_auto_config(struct hda_codec *codec)
4765 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
4766 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4767 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
4774 ALC262_FIXUP_FSC_H270,
4775 ALC262_FIXUP_HP_Z200,
4777 ALC262_FIXUP_LENOVO_3000,
4779 ALC262_FIXUP_BENQ_T31,
4782 static const struct alc_fixup alc262_fixups[] = {
4783 [ALC262_FIXUP_FSC_H270] = {
4784 .type = ALC_FIXUP_PINS,
4785 .v.pins = (const struct alc_pincfg[]) {
4786 { 0x14, 0x99130110 }, /* speaker */
4787 { 0x15, 0x0221142f }, /* front HP */
4788 { 0x1b, 0x0121141f }, /* rear HP */
4792 [ALC262_FIXUP_HP_Z200] = {
4793 .type = ALC_FIXUP_PINS,
4794 .v.pins = (const struct alc_pincfg[]) {
4795 { 0x16, 0x99130120 }, /* internal speaker */
4799 [ALC262_FIXUP_TYAN] = {
4800 .type = ALC_FIXUP_PINS,
4801 .v.pins = (const struct alc_pincfg[]) {
4802 { 0x14, 0x1993e1f0 }, /* int AUX */
4806 [ALC262_FIXUP_LENOVO_3000] = {
4807 .type = ALC_FIXUP_VERBS,
4808 .v.verbs = (const struct hda_verb[]) {
4809 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
4813 .chain_id = ALC262_FIXUP_BENQ,
4815 [ALC262_FIXUP_BENQ] = {
4816 .type = ALC_FIXUP_VERBS,
4817 .v.verbs = (const struct hda_verb[]) {
4818 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4819 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4823 [ALC262_FIXUP_BENQ_T31] = {
4824 .type = ALC_FIXUP_VERBS,
4825 .v.verbs = (const struct hda_verb[]) {
4826 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4827 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4833 static const struct snd_pci_quirk alc262_fixup_tbl[] = {
4834 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
4835 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
4836 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
4837 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
4838 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
4839 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
4840 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
4841 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
4846 #ifdef CONFIG_SND_HDA_POWER_SAVE
4847 #define alc262_loopbacks alc880_loopbacks
4852 static int patch_alc262(struct hda_codec *codec)
4854 struct alc_spec *spec;
4857 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4863 spec->mixer_nid = 0x0b;
4866 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
4871 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4872 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
4873 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4874 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
4877 alc_auto_parse_customize_define(codec);
4879 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
4881 alc_pick_fixup(codec, NULL, alc262_fixup_tbl, alc262_fixups);
4882 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4884 /* automatic parse from the BIOS config */
4885 err = alc262_parse_auto_config(codec);
4889 if (!spec->no_analog && !spec->adc_nids) {
4890 alc_auto_fill_adc_caps(codec);
4891 alc_rebuild_imux_for_auto_mic(codec);
4892 alc_remove_invalid_adc_nids(codec);
4895 if (!spec->no_analog && !spec->cap_mixer)
4896 set_capture_mixer(codec);
4898 if (!spec->no_analog && has_cdefine_beep(codec)) {
4899 err = snd_hda_attach_beep_device(codec, 0x1);
4902 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4905 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4907 codec->patch_ops = alc_patch_ops;
4908 spec->init_hook = alc_auto_init_std;
4909 spec->shutup = alc_eapd_shutup;
4911 #ifdef CONFIG_SND_HDA_POWER_SAVE
4912 if (!spec->loopback.amplist)
4913 spec->loopback.amplist = alc262_loopbacks;
4926 /* bind Beep switches of both NID 0x0f and 0x10 */
4927 static const struct hda_bind_ctls alc268_bind_beep_sw = {
4928 .ops = &snd_hda_bind_sw,
4930 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
4931 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
4936 static const struct snd_kcontrol_new alc268_beep_mixer[] = {
4937 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
4938 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
4942 /* set PCBEEP vol = 0, mute connections */
4943 static const struct hda_verb alc268_beep_init_verbs[] = {
4944 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4945 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4946 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4951 * BIOS auto configuration
4953 static int alc268_parse_auto_config(struct hda_codec *codec)
4955 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4956 struct alc_spec *spec = codec->spec;
4957 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
4959 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
4960 add_mixer(spec, alc268_beep_mixer);
4961 add_verb(spec, alc268_beep_init_verbs);
4969 static int patch_alc268(struct hda_codec *codec)
4971 struct alc_spec *spec;
4972 int i, has_beep, err;
4974 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4980 /* ALC268 has no aa-loopback mixer */
4982 /* automatic parse from the BIOS config */
4983 err = alc268_parse_auto_config(codec);
4988 for (i = 0; i < spec->num_mixers; i++) {
4989 if (spec->mixers[i] == alc268_beep_mixer) {
4996 err = snd_hda_attach_beep_device(codec, 0x1);
4999 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
5000 /* override the amp caps for beep generator */
5001 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
5002 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
5003 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
5004 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5005 (0 << AC_AMPCAP_MUTE_SHIFT));
5008 if (!spec->no_analog && !spec->adc_nids) {
5009 alc_auto_fill_adc_caps(codec);
5010 alc_rebuild_imux_for_auto_mic(codec);
5011 alc_remove_invalid_adc_nids(codec);
5014 if (!spec->no_analog && !spec->cap_mixer)
5015 set_capture_mixer(codec);
5017 codec->patch_ops = alc_patch_ops;
5018 spec->init_hook = alc_auto_init_std;
5019 spec->shutup = alc_eapd_shutup;
5031 #ifdef CONFIG_SND_HDA_POWER_SAVE
5032 #define alc269_loopbacks alc880_loopbacks
5035 static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
5039 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5040 /* NID is set in alc_build_pcms */
5042 .open = alc_playback_pcm_open,
5043 .prepare = alc_playback_pcm_prepare,
5044 .cleanup = alc_playback_pcm_cleanup
5048 static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
5052 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5053 /* NID is set in alc_build_pcms */
5056 #ifdef CONFIG_SND_HDA_POWER_SAVE
5057 static int alc269_mic2_for_mute_led(struct hda_codec *codec)
5059 switch (codec->subsystem_id) {
5066 static int alc269_mic2_mute_check_ps(struct hda_codec *codec, hda_nid_t nid)
5068 /* update mute-LED according to the speaker mute state */
5069 if (nid == 0x01 || nid == 0x14) {
5071 if (snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0) &
5076 /* mic2 vref pin is used for mute LED control */
5077 snd_hda_codec_update_cache(codec, 0x19, 0,
5078 AC_VERB_SET_PIN_WIDGET_CONTROL,
5081 return alc_check_power_status(codec, nid);
5083 #endif /* CONFIG_SND_HDA_POWER_SAVE */
5085 /* different alc269-variants */
5087 ALC269_TYPE_ALC269VA,
5088 ALC269_TYPE_ALC269VB,
5089 ALC269_TYPE_ALC269VC,
5093 * BIOS auto configuration
5095 static int alc269_parse_auto_config(struct hda_codec *codec)
5097 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
5098 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
5099 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5100 struct alc_spec *spec = codec->spec;
5101 const hda_nid_t *ssids = spec->codec_variant == ALC269_TYPE_ALC269VA ?
5102 alc269va_ssids : alc269_ssids;
5104 return alc_parse_auto_config(codec, alc269_ignore, ssids);
5107 static void alc269_toggle_power_output(struct hda_codec *codec, int power_up)
5109 int val = alc_read_coef_idx(codec, 0x04);
5114 alc_write_coef_idx(codec, 0x04, val);
5117 static void alc269_shutup(struct hda_codec *codec)
5119 if ((alc_get_coef0(codec) & 0x00ff) == 0x017)
5120 alc269_toggle_power_output(codec, 0);
5121 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
5122 alc269_toggle_power_output(codec, 0);
5128 static int alc269_resume(struct hda_codec *codec)
5130 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
5131 alc269_toggle_power_output(codec, 0);
5135 codec->patch_ops.init(codec);
5137 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
5138 alc269_toggle_power_output(codec, 1);
5142 if ((alc_get_coef0(codec) & 0x00ff) == 0x018)
5143 alc269_toggle_power_output(codec, 1);
5145 snd_hda_codec_resume_amp(codec);
5146 snd_hda_codec_resume_cache(codec);
5147 hda_call_check_power_status(codec, 0x01);
5150 #endif /* CONFIG_PM */
5152 static void alc269_fixup_hweq(struct hda_codec *codec,
5153 const struct alc_fixup *fix, int action)
5157 if (action != ALC_FIXUP_ACT_INIT)
5159 coef = alc_read_coef_idx(codec, 0x1e);
5160 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
5163 static void alc271_fixup_dmic(struct hda_codec *codec,
5164 const struct alc_fixup *fix, int action)
5166 static const struct hda_verb verbs[] = {
5167 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
5168 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
5173 if (strcmp(codec->chip_name, "ALC271X"))
5175 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
5176 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
5177 snd_hda_sequence_write(codec, verbs);
5180 static void alc269_fixup_pcm_44k(struct hda_codec *codec,
5181 const struct alc_fixup *fix, int action)
5183 struct alc_spec *spec = codec->spec;
5185 if (action != ALC_FIXUP_ACT_PROBE)
5188 /* Due to a hardware problem on Lenovo Ideadpad, we need to
5189 * fix the sample rate of analog I/O to 44.1kHz
5191 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
5192 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
5195 static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
5196 const struct alc_fixup *fix, int action)
5200 if (action != ALC_FIXUP_ACT_INIT)
5202 /* The digital-mic unit sends PDM (differential signal) instead of
5203 * the standard PCM, thus you can't record a valid mono stream as is.
5204 * Below is a workaround specific to ALC269 to control the dmic
5205 * signal source as mono.
5207 coef = alc_read_coef_idx(codec, 0x07);
5208 alc_write_coef_idx(codec, 0x07, coef | 0x80);
5211 static void alc269_quanta_automute(struct hda_codec *codec)
5213 update_outputs(codec);
5215 snd_hda_codec_write(codec, 0x20, 0,
5216 AC_VERB_SET_COEF_INDEX, 0x0c);
5217 snd_hda_codec_write(codec, 0x20, 0,
5218 AC_VERB_SET_PROC_COEF, 0x680);
5220 snd_hda_codec_write(codec, 0x20, 0,
5221 AC_VERB_SET_COEF_INDEX, 0x0c);
5222 snd_hda_codec_write(codec, 0x20, 0,
5223 AC_VERB_SET_PROC_COEF, 0x480);
5226 static void alc269_fixup_quanta_mute(struct hda_codec *codec,
5227 const struct alc_fixup *fix, int action)
5229 struct alc_spec *spec = codec->spec;
5230 if (action != ALC_FIXUP_ACT_PROBE)
5232 spec->automute_hook = alc269_quanta_automute;
5236 ALC269_FIXUP_SONY_VAIO,
5237 ALC275_FIXUP_SONY_VAIO_GPIO2,
5238 ALC269_FIXUP_DELL_M101Z,
5239 ALC269_FIXUP_SKU_IGNORE,
5240 ALC269_FIXUP_ASUS_G73JW,
5241 ALC269_FIXUP_LENOVO_EAPD,
5242 ALC275_FIXUP_SONY_HWEQ,
5244 ALC269_FIXUP_PCM_44K,
5245 ALC269_FIXUP_STEREO_DMIC,
5246 ALC269_FIXUP_QUANTA_MUTE,
5247 ALC269_FIXUP_LIFEBOOK,
5250 ALC269VB_FIXUP_AMIC,
5251 ALC269VB_FIXUP_DMIC,
5254 static const struct alc_fixup alc269_fixups[] = {
5255 [ALC269_FIXUP_SONY_VAIO] = {
5256 .type = ALC_FIXUP_VERBS,
5257 .v.verbs = (const struct hda_verb[]) {
5258 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
5262 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
5263 .type = ALC_FIXUP_VERBS,
5264 .v.verbs = (const struct hda_verb[]) {
5265 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
5266 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
5267 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5271 .chain_id = ALC269_FIXUP_SONY_VAIO
5273 [ALC269_FIXUP_DELL_M101Z] = {
5274 .type = ALC_FIXUP_VERBS,
5275 .v.verbs = (const struct hda_verb[]) {
5276 /* Enables internal speaker */
5277 {0x20, AC_VERB_SET_COEF_INDEX, 13},
5278 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
5282 [ALC269_FIXUP_SKU_IGNORE] = {
5283 .type = ALC_FIXUP_SKU,
5284 .v.sku = ALC_FIXUP_SKU_IGNORE,
5286 [ALC269_FIXUP_ASUS_G73JW] = {
5287 .type = ALC_FIXUP_PINS,
5288 .v.pins = (const struct alc_pincfg[]) {
5289 { 0x17, 0x99130111 }, /* subwoofer */
5293 [ALC269_FIXUP_LENOVO_EAPD] = {
5294 .type = ALC_FIXUP_VERBS,
5295 .v.verbs = (const struct hda_verb[]) {
5296 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
5300 [ALC275_FIXUP_SONY_HWEQ] = {
5301 .type = ALC_FIXUP_FUNC,
5302 .v.func = alc269_fixup_hweq,
5304 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
5306 [ALC271_FIXUP_DMIC] = {
5307 .type = ALC_FIXUP_FUNC,
5308 .v.func = alc271_fixup_dmic,
5310 [ALC269_FIXUP_PCM_44K] = {
5311 .type = ALC_FIXUP_FUNC,
5312 .v.func = alc269_fixup_pcm_44k,
5314 [ALC269_FIXUP_STEREO_DMIC] = {
5315 .type = ALC_FIXUP_FUNC,
5316 .v.func = alc269_fixup_stereo_dmic,
5318 [ALC269_FIXUP_QUANTA_MUTE] = {
5319 .type = ALC_FIXUP_FUNC,
5320 .v.func = alc269_fixup_quanta_mute,
5322 [ALC269_FIXUP_LIFEBOOK] = {
5323 .type = ALC_FIXUP_PINS,
5324 .v.pins = (const struct alc_pincfg[]) {
5325 { 0x1a, 0x2101103f }, /* dock line-out */
5326 { 0x1b, 0x23a11040 }, /* dock mic-in */
5330 .chain_id = ALC269_FIXUP_QUANTA_MUTE
5332 [ALC269_FIXUP_AMIC] = {
5333 .type = ALC_FIXUP_PINS,
5334 .v.pins = (const struct alc_pincfg[]) {
5335 { 0x14, 0x99130110 }, /* speaker */
5336 { 0x15, 0x0121401f }, /* HP out */
5337 { 0x18, 0x01a19c20 }, /* mic */
5338 { 0x19, 0x99a3092f }, /* int-mic */
5342 [ALC269_FIXUP_DMIC] = {
5343 .type = ALC_FIXUP_PINS,
5344 .v.pins = (const struct alc_pincfg[]) {
5345 { 0x12, 0x99a3092f }, /* int-mic */
5346 { 0x14, 0x99130110 }, /* speaker */
5347 { 0x15, 0x0121401f }, /* HP out */
5348 { 0x18, 0x01a19c20 }, /* mic */
5352 [ALC269VB_FIXUP_AMIC] = {
5353 .type = ALC_FIXUP_PINS,
5354 .v.pins = (const struct alc_pincfg[]) {
5355 { 0x14, 0x99130110 }, /* speaker */
5356 { 0x18, 0x01a19c20 }, /* mic */
5357 { 0x19, 0x99a3092f }, /* int-mic */
5358 { 0x21, 0x0121401f }, /* HP out */
5362 [ALC269VB_FIXUP_DMIC] = {
5363 .type = ALC_FIXUP_PINS,
5364 .v.pins = (const struct alc_pincfg[]) {
5365 { 0x12, 0x99a3092f }, /* int-mic */
5366 { 0x14, 0x99130110 }, /* speaker */
5367 { 0x18, 0x01a19c20 }, /* mic */
5368 { 0x21, 0x0121401f }, /* HP out */
5374 static const struct snd_pci_quirk alc269_fixup_tbl[] = {
5375 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
5376 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
5377 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
5378 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
5379 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
5380 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
5381 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
5382 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
5383 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
5384 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
5385 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
5386 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
5387 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
5388 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
5389 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
5390 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
5391 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
5392 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
5393 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_QUANTA_MUTE),
5394 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K),
5395 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
5398 /* Below is a quirk table taken from the old code.
5399 * Basically the device should work as is without the fixup table.
5400 * If BIOS doesn't give a proper info, enable the corresponding
5403 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
5405 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
5406 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
5407 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
5408 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
5409 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
5410 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
5411 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
5412 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
5413 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
5414 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
5415 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
5416 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
5417 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
5418 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
5419 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
5420 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
5421 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
5422 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
5423 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
5424 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
5425 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
5426 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
5427 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
5428 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
5429 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
5430 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
5431 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
5432 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
5433 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
5434 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
5435 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
5436 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
5437 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
5438 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
5439 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
5440 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
5441 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
5442 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
5443 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
5448 static const struct alc_model_fixup alc269_fixup_models[] = {
5449 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
5450 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
5455 static int alc269_fill_coef(struct hda_codec *codec)
5459 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
5460 alc_write_coef_idx(codec, 0xf, 0x960b);
5461 alc_write_coef_idx(codec, 0xe, 0x8817);
5464 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
5465 alc_write_coef_idx(codec, 0xf, 0x960b);
5466 alc_write_coef_idx(codec, 0xe, 0x8814);
5469 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
5470 val = alc_read_coef_idx(codec, 0x04);
5471 /* Power up output pin */
5472 alc_write_coef_idx(codec, 0x04, val | (1<<11));
5475 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
5476 val = alc_read_coef_idx(codec, 0xd);
5477 if ((val & 0x0c00) >> 10 != 0x1) {
5478 /* Capless ramp up clock control */
5479 alc_write_coef_idx(codec, 0xd, val | (1<<10));
5481 val = alc_read_coef_idx(codec, 0x17);
5482 if ((val & 0x01c0) >> 6 != 0x4) {
5483 /* Class D power on reset */
5484 alc_write_coef_idx(codec, 0x17, val | (1<<7));
5488 val = alc_read_coef_idx(codec, 0xd); /* Class D */
5489 alc_write_coef_idx(codec, 0xd, val | (1<<14));
5491 val = alc_read_coef_idx(codec, 0x4); /* HP */
5492 alc_write_coef_idx(codec, 0x4, val | (1<<11));
5499 static int patch_alc269(struct hda_codec *codec)
5501 struct alc_spec *spec;
5504 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5510 spec->mixer_nid = 0x0b;
5512 alc_auto_parse_customize_define(codec);
5514 err = alc_codec_rename_from_preset(codec);
5518 if (codec->vendor_id == 0x10ec0269) {
5519 spec->codec_variant = ALC269_TYPE_ALC269VA;
5520 switch (alc_get_coef0(codec) & 0x00f0) {
5522 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
5523 spec->cdefine.platform_type == 1)
5524 err = alc_codec_rename(codec, "ALC271X");
5525 spec->codec_variant = ALC269_TYPE_ALC269VB;
5528 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
5529 codec->bus->pci->subsystem_device == 0x21f3)
5530 err = alc_codec_rename(codec, "ALC3202");
5531 spec->codec_variant = ALC269_TYPE_ALC269VC;
5534 alc_fix_pll_init(codec, 0x20, 0x04, 15);
5538 alc269_fill_coef(codec);
5541 alc_pick_fixup(codec, alc269_fixup_models,
5542 alc269_fixup_tbl, alc269_fixups);
5543 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5545 /* automatic parse from the BIOS config */
5546 err = alc269_parse_auto_config(codec);
5550 if (!spec->no_analog && !spec->adc_nids) {
5551 alc_auto_fill_adc_caps(codec);
5552 alc_rebuild_imux_for_auto_mic(codec);
5553 alc_remove_invalid_adc_nids(codec);
5556 if (!spec->no_analog && !spec->cap_mixer)
5557 set_capture_mixer(codec);
5559 if (!spec->no_analog && has_cdefine_beep(codec)) {
5560 err = snd_hda_attach_beep_device(codec, 0x1);
5563 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
5566 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5568 codec->patch_ops = alc_patch_ops;
5570 codec->patch_ops.resume = alc269_resume;
5572 spec->init_hook = alc_auto_init_std;
5573 spec->shutup = alc269_shutup;
5575 #ifdef CONFIG_SND_HDA_POWER_SAVE
5576 if (!spec->loopback.amplist)
5577 spec->loopback.amplist = alc269_loopbacks;
5578 if (alc269_mic2_for_mute_led(codec))
5579 codec->patch_ops.check_power_status = alc269_mic2_mute_check_ps;
5593 static int alc861_parse_auto_config(struct hda_codec *codec)
5595 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
5596 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
5597 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
5600 #ifdef CONFIG_SND_HDA_POWER_SAVE
5601 static const struct hda_amp_list alc861_loopbacks[] = {
5602 { 0x15, HDA_INPUT, 0 },
5603 { 0x15, HDA_INPUT, 1 },
5604 { 0x15, HDA_INPUT, 2 },
5605 { 0x15, HDA_INPUT, 3 },
5611 /* Pin config fixes */
5613 PINFIX_FSC_AMILO_PI1505,
5617 /* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
5618 static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
5619 const struct alc_fixup *fix, int action)
5621 struct alc_spec *spec = codec->spec;
5624 if (action != ALC_FIXUP_ACT_INIT)
5626 val = snd_hda_codec_read(codec, 0x0f, 0,
5627 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5628 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
5629 val |= AC_PINCTL_IN_EN;
5630 val |= AC_PINCTL_VREF_50;
5631 snd_hda_codec_write(codec, 0x0f, 0,
5632 AC_VERB_SET_PIN_WIDGET_CONTROL, val);
5633 spec->keep_vref_in_automute = 1;
5636 static const struct alc_fixup alc861_fixups[] = {
5637 [PINFIX_FSC_AMILO_PI1505] = {
5638 .type = ALC_FIXUP_PINS,
5639 .v.pins = (const struct alc_pincfg[]) {
5640 { 0x0b, 0x0221101f }, /* HP */
5641 { 0x0f, 0x90170310 }, /* speaker */
5645 [PINFIX_ASUS_A6RP] = {
5646 .type = ALC_FIXUP_FUNC,
5647 .v.func = alc861_fixup_asus_amp_vref_0f,
5651 static const struct snd_pci_quirk alc861_fixup_tbl[] = {
5652 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", PINFIX_ASUS_A6RP),
5653 SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", PINFIX_ASUS_A6RP),
5654 SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", PINFIX_ASUS_A6RP),
5655 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", PINFIX_FSC_AMILO_PI1505),
5661 static int patch_alc861(struct hda_codec *codec)
5663 struct alc_spec *spec;
5666 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5672 spec->mixer_nid = 0x15;
5674 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
5675 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5677 /* automatic parse from the BIOS config */
5678 err = alc861_parse_auto_config(codec);
5682 if (!spec->no_analog && !spec->adc_nids) {
5683 alc_auto_fill_adc_caps(codec);
5684 alc_rebuild_imux_for_auto_mic(codec);
5685 alc_remove_invalid_adc_nids(codec);
5688 if (!spec->no_analog && !spec->cap_mixer)
5689 set_capture_mixer(codec);
5691 if (!spec->no_analog) {
5692 err = snd_hda_attach_beep_device(codec, 0x23);
5695 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
5698 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5700 codec->patch_ops = alc_patch_ops;
5701 spec->init_hook = alc_auto_init_std;
5702 #ifdef CONFIG_SND_HDA_POWER_SAVE
5703 spec->power_hook = alc_power_eapd;
5704 if (!spec->loopback.amplist)
5705 spec->loopback.amplist = alc861_loopbacks;
5720 * In addition, an independent DAC
5722 #ifdef CONFIG_SND_HDA_POWER_SAVE
5723 #define alc861vd_loopbacks alc880_loopbacks
5726 static int alc861vd_parse_auto_config(struct hda_codec *codec)
5728 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
5729 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5730 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
5734 ALC660VD_FIX_ASUS_GPIO1,
5735 ALC861VD_FIX_DALLAS,
5738 /* exclude VREF80 */
5739 static void alc861vd_fixup_dallas(struct hda_codec *codec,
5740 const struct alc_fixup *fix, int action)
5742 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
5743 snd_hda_override_pin_caps(codec, 0x18, 0x00001714);
5744 snd_hda_override_pin_caps(codec, 0x19, 0x0000171c);
5748 static const struct alc_fixup alc861vd_fixups[] = {
5749 [ALC660VD_FIX_ASUS_GPIO1] = {
5750 .type = ALC_FIXUP_VERBS,
5751 .v.verbs = (const struct hda_verb[]) {
5753 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
5754 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5755 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5759 [ALC861VD_FIX_DALLAS] = {
5760 .type = ALC_FIXUP_FUNC,
5761 .v.func = alc861vd_fixup_dallas,
5765 static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
5766 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
5767 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
5768 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
5772 static const struct hda_verb alc660vd_eapd_verbs[] = {
5773 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
5774 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
5780 static int patch_alc861vd(struct hda_codec *codec)
5782 struct alc_spec *spec;
5785 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5791 spec->mixer_nid = 0x0b;
5793 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
5794 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5796 /* automatic parse from the BIOS config */
5797 err = alc861vd_parse_auto_config(codec);
5801 if (codec->vendor_id == 0x10ec0660) {
5802 /* always turn on EAPD */
5803 add_verb(spec, alc660vd_eapd_verbs);
5806 if (!spec->no_analog && !spec->adc_nids) {
5807 alc_auto_fill_adc_caps(codec);
5808 alc_rebuild_imux_for_auto_mic(codec);
5809 alc_remove_invalid_adc_nids(codec);
5812 if (!spec->no_analog && !spec->cap_mixer)
5813 set_capture_mixer(codec);
5815 if (!spec->no_analog) {
5816 err = snd_hda_attach_beep_device(codec, 0x23);
5819 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5822 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5824 codec->patch_ops = alc_patch_ops;
5826 spec->init_hook = alc_auto_init_std;
5827 spec->shutup = alc_eapd_shutup;
5828 #ifdef CONFIG_SND_HDA_POWER_SAVE
5829 if (!spec->loopback.amplist)
5830 spec->loopback.amplist = alc861vd_loopbacks;
5843 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
5844 * configuration. Each pin widget can choose any input DACs and a mixer.
5845 * Each ADC is connected from a mixer of all inputs. This makes possible
5846 * 6-channel independent captures.
5848 * In addition, an independent DAC for the multi-playback (not used in this
5851 #ifdef CONFIG_SND_HDA_POWER_SAVE
5852 #define alc662_loopbacks alc880_loopbacks
5856 * BIOS auto configuration
5859 static int alc662_parse_auto_config(struct hda_codec *codec)
5861 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
5862 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
5863 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5864 const hda_nid_t *ssids;
5866 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
5867 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
5868 ssids = alc663_ssids;
5870 ssids = alc662_ssids;
5871 return alc_parse_auto_config(codec, alc662_ignore, ssids);
5874 static void alc272_fixup_mario(struct hda_codec *codec,
5875 const struct alc_fixup *fix, int action)
5877 if (action != ALC_FIXUP_ACT_PROBE)
5879 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
5880 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
5881 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
5882 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5883 (0 << AC_AMPCAP_MUTE_SHIFT)))
5885 "hda_codec: failed to override amp caps for NID 0x2\n");
5889 ALC662_FIXUP_ASPIRE,
5890 ALC662_FIXUP_IDEAPAD,
5892 ALC662_FIXUP_CZC_P10T,
5893 ALC662_FIXUP_SKU_IGNORE,
5894 ALC662_FIXUP_HP_RP5800,
5895 ALC662_FIXUP_ASUS_MODE1,
5896 ALC662_FIXUP_ASUS_MODE2,
5897 ALC662_FIXUP_ASUS_MODE3,
5898 ALC662_FIXUP_ASUS_MODE4,
5899 ALC662_FIXUP_ASUS_MODE5,
5900 ALC662_FIXUP_ASUS_MODE6,
5901 ALC662_FIXUP_ASUS_MODE7,
5902 ALC662_FIXUP_ASUS_MODE8,
5905 static const struct alc_fixup alc662_fixups[] = {
5906 [ALC662_FIXUP_ASPIRE] = {
5907 .type = ALC_FIXUP_PINS,
5908 .v.pins = (const struct alc_pincfg[]) {
5909 { 0x15, 0x99130112 }, /* subwoofer */
5913 [ALC662_FIXUP_IDEAPAD] = {
5914 .type = ALC_FIXUP_PINS,
5915 .v.pins = (const struct alc_pincfg[]) {
5916 { 0x17, 0x99130112 }, /* subwoofer */
5920 [ALC272_FIXUP_MARIO] = {
5921 .type = ALC_FIXUP_FUNC,
5922 .v.func = alc272_fixup_mario,
5924 [ALC662_FIXUP_CZC_P10T] = {
5925 .type = ALC_FIXUP_VERBS,
5926 .v.verbs = (const struct hda_verb[]) {
5927 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
5931 [ALC662_FIXUP_SKU_IGNORE] = {
5932 .type = ALC_FIXUP_SKU,
5933 .v.sku = ALC_FIXUP_SKU_IGNORE,
5935 [ALC662_FIXUP_HP_RP5800] = {
5936 .type = ALC_FIXUP_PINS,
5937 .v.pins = (const struct alc_pincfg[]) {
5938 { 0x14, 0x0221201f }, /* HP out */
5942 .chain_id = ALC662_FIXUP_SKU_IGNORE
5944 [ALC662_FIXUP_ASUS_MODE1] = {
5945 .type = ALC_FIXUP_PINS,
5946 .v.pins = (const struct alc_pincfg[]) {
5947 { 0x14, 0x99130110 }, /* speaker */
5948 { 0x18, 0x01a19c20 }, /* mic */
5949 { 0x19, 0x99a3092f }, /* int-mic */
5950 { 0x21, 0x0121401f }, /* HP out */
5954 .chain_id = ALC662_FIXUP_SKU_IGNORE
5956 [ALC662_FIXUP_ASUS_MODE2] = {
5957 .type = ALC_FIXUP_PINS,
5958 .v.pins = (const struct alc_pincfg[]) {
5959 { 0x14, 0x99130110 }, /* speaker */
5960 { 0x18, 0x01a19820 }, /* mic */
5961 { 0x19, 0x99a3092f }, /* int-mic */
5962 { 0x1b, 0x0121401f }, /* HP out */
5966 .chain_id = ALC662_FIXUP_SKU_IGNORE
5968 [ALC662_FIXUP_ASUS_MODE3] = {
5969 .type = ALC_FIXUP_PINS,
5970 .v.pins = (const struct alc_pincfg[]) {
5971 { 0x14, 0x99130110 }, /* speaker */
5972 { 0x15, 0x0121441f }, /* HP */
5973 { 0x18, 0x01a19840 }, /* mic */
5974 { 0x19, 0x99a3094f }, /* int-mic */
5975 { 0x21, 0x01211420 }, /* HP2 */
5979 .chain_id = ALC662_FIXUP_SKU_IGNORE
5981 [ALC662_FIXUP_ASUS_MODE4] = {
5982 .type = ALC_FIXUP_PINS,
5983 .v.pins = (const struct alc_pincfg[]) {
5984 { 0x14, 0x99130110 }, /* speaker */
5985 { 0x16, 0x99130111 }, /* speaker */
5986 { 0x18, 0x01a19840 }, /* mic */
5987 { 0x19, 0x99a3094f }, /* int-mic */
5988 { 0x21, 0x0121441f }, /* HP */
5992 .chain_id = ALC662_FIXUP_SKU_IGNORE
5994 [ALC662_FIXUP_ASUS_MODE5] = {
5995 .type = ALC_FIXUP_PINS,
5996 .v.pins = (const struct alc_pincfg[]) {
5997 { 0x14, 0x99130110 }, /* speaker */
5998 { 0x15, 0x0121441f }, /* HP */
5999 { 0x16, 0x99130111 }, /* speaker */
6000 { 0x18, 0x01a19840 }, /* mic */
6001 { 0x19, 0x99a3094f }, /* int-mic */
6005 .chain_id = ALC662_FIXUP_SKU_IGNORE
6007 [ALC662_FIXUP_ASUS_MODE6] = {
6008 .type = ALC_FIXUP_PINS,
6009 .v.pins = (const struct alc_pincfg[]) {
6010 { 0x14, 0x99130110 }, /* speaker */
6011 { 0x15, 0x01211420 }, /* HP2 */
6012 { 0x18, 0x01a19840 }, /* mic */
6013 { 0x19, 0x99a3094f }, /* int-mic */
6014 { 0x1b, 0x0121441f }, /* HP */
6018 .chain_id = ALC662_FIXUP_SKU_IGNORE
6020 [ALC662_FIXUP_ASUS_MODE7] = {
6021 .type = ALC_FIXUP_PINS,
6022 .v.pins = (const struct alc_pincfg[]) {
6023 { 0x14, 0x99130110 }, /* speaker */
6024 { 0x17, 0x99130111 }, /* speaker */
6025 { 0x18, 0x01a19840 }, /* mic */
6026 { 0x19, 0x99a3094f }, /* int-mic */
6027 { 0x1b, 0x01214020 }, /* HP */
6028 { 0x21, 0x0121401f }, /* HP */
6032 .chain_id = ALC662_FIXUP_SKU_IGNORE
6034 [ALC662_FIXUP_ASUS_MODE8] = {
6035 .type = ALC_FIXUP_PINS,
6036 .v.pins = (const struct alc_pincfg[]) {
6037 { 0x14, 0x99130110 }, /* speaker */
6038 { 0x12, 0x99a30970 }, /* int-mic */
6039 { 0x15, 0x01214020 }, /* HP */
6040 { 0x17, 0x99130111 }, /* speaker */
6041 { 0x18, 0x01a19840 }, /* mic */
6042 { 0x21, 0x0121401f }, /* HP */
6046 .chain_id = ALC662_FIXUP_SKU_IGNORE
6050 static const struct snd_pci_quirk alc662_fixup_tbl[] = {
6051 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
6052 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
6053 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
6054 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
6055 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
6056 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
6057 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
6058 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
6059 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
6060 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
6063 /* Below is a quirk table taken from the old code.
6064 * Basically the device should work as is without the fixup table.
6065 * If BIOS doesn't give a proper info, enable the corresponding
6068 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
6069 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
6070 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
6071 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
6072 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6073 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6074 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6075 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
6076 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
6077 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6078 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
6079 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
6080 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
6081 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
6082 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
6083 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6084 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
6085 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
6086 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6087 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6088 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6089 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6090 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
6091 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
6092 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
6093 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6094 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
6095 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6096 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6097 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
6098 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6099 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6100 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
6101 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
6102 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
6103 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
6104 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
6105 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
6106 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
6107 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6108 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
6109 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
6110 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6111 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
6112 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
6113 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
6114 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
6115 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
6116 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6117 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
6122 static const struct alc_model_fixup alc662_fixup_models[] = {
6123 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
6124 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
6125 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
6126 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
6127 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
6128 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
6129 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
6130 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
6131 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
6138 static int patch_alc662(struct hda_codec *codec)
6140 struct alc_spec *spec;
6143 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6149 spec->mixer_nid = 0x0b;
6151 /* handle multiple HPs as is */
6152 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
6154 alc_auto_parse_customize_define(codec);
6156 alc_fix_pll_init(codec, 0x20, 0x04, 15);
6158 err = alc_codec_rename_from_preset(codec);
6162 if ((alc_get_coef0(codec) & (1 << 14)) &&
6163 codec->bus->pci->subsystem_vendor == 0x1025 &&
6164 spec->cdefine.platform_type == 1) {
6165 if (alc_codec_rename(codec, "ALC272X") < 0)
6169 alc_pick_fixup(codec, alc662_fixup_models,
6170 alc662_fixup_tbl, alc662_fixups);
6171 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6172 /* automatic parse from the BIOS config */
6173 err = alc662_parse_auto_config(codec);
6177 if (!spec->no_analog && !spec->adc_nids) {
6178 alc_auto_fill_adc_caps(codec);
6179 alc_rebuild_imux_for_auto_mic(codec);
6180 alc_remove_invalid_adc_nids(codec);
6183 if (!spec->no_analog && !spec->cap_mixer)
6184 set_capture_mixer(codec);
6186 if (!spec->no_analog && has_cdefine_beep(codec)) {
6187 err = snd_hda_attach_beep_device(codec, 0x1);
6190 switch (codec->vendor_id) {
6192 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6197 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
6200 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
6205 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6207 codec->patch_ops = alc_patch_ops;
6208 spec->init_hook = alc_auto_init_std;
6209 spec->shutup = alc_eapd_shutup;
6211 #ifdef CONFIG_SND_HDA_POWER_SAVE
6212 if (!spec->loopback.amplist)
6213 spec->loopback.amplist = alc662_loopbacks;
6227 static int alc680_parse_auto_config(struct hda_codec *codec)
6229 return alc_parse_auto_config(codec, NULL, NULL);
6234 static int patch_alc680(struct hda_codec *codec)
6236 struct alc_spec *spec;
6239 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6245 /* ALC680 has no aa-loopback mixer */
6247 /* automatic parse from the BIOS config */
6248 err = alc680_parse_auto_config(codec);
6254 if (!spec->no_analog && !spec->cap_mixer)
6255 set_capture_mixer(codec);
6257 codec->patch_ops = alc_patch_ops;
6258 spec->init_hook = alc_auto_init_std;
6266 static const struct hda_codec_preset snd_hda_preset_realtek[] = {
6267 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
6268 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
6269 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
6270 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
6271 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
6272 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
6273 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
6274 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
6275 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
6276 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
6277 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
6278 .patch = patch_alc861 },
6279 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
6280 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
6281 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
6282 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
6283 .patch = patch_alc882 },
6284 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
6285 .patch = patch_alc662 },
6286 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
6287 .patch = patch_alc662 },
6288 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
6289 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
6290 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
6291 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
6292 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
6293 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
6294 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
6295 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
6296 .patch = patch_alc882 },
6297 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
6298 .patch = patch_alc882 },
6299 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
6300 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
6301 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
6302 .patch = patch_alc882 },
6303 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
6304 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
6305 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
6306 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
6310 MODULE_ALIAS("snd-hda-codec-id:10ec*");
6312 MODULE_LICENSE("GPL");
6313 MODULE_DESCRIPTION("Realtek HD-audio codec");
6315 static struct hda_codec_preset_list realtek_list = {
6316 .preset = snd_hda_preset_realtek,
6317 .owner = THIS_MODULE,
6320 static int __init patch_realtek_init(void)
6322 return snd_hda_add_codec_preset(&realtek_list);
6325 static void __exit patch_realtek_exit(void)
6327 snd_hda_delete_codec_preset(&realtek_list);
6330 module_init(patch_realtek_init)
6331 module_exit(patch_realtek_exit)