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 <sound/core.h>
31 #include <sound/jack.h>
32 #include "hda_codec.h"
33 #include "hda_local.h"
36 /* unsol event tags */
37 #define ALC_FRONT_EVENT 0x01
38 #define ALC_DCVOL_EVENT 0x02
39 #define ALC_HP_EVENT 0x04
40 #define ALC_MIC_EVENT 0x08
43 #define GPIO_MASK 0x03
45 /* extra amp-initialization sequence types */
54 struct alc_customize_define {
56 unsigned char port_connectivity;
57 unsigned char check_sum;
58 unsigned char customization;
59 unsigned char external_amp;
60 unsigned int enable_pcbeep:1;
61 unsigned int platform_type:1;
63 unsigned int override:1;
64 unsigned int fixup:1; /* Means that this sku is set by driver, not read from hw */
70 hda_nid_t pin; /* multi-io widget pin NID */
71 hda_nid_t dac; /* DAC to be connected */
72 unsigned int ctl_in; /* cached input-pin control value */
76 ALC_AUTOMUTE_PIN, /* change the pin control */
77 ALC_AUTOMUTE_AMP, /* mute/unmute the pin AMP */
78 ALC_AUTOMUTE_MIXER, /* mute/unmute mixer widget AMP */
82 /* codec parameterization */
83 const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */
84 unsigned int num_mixers;
85 const struct snd_kcontrol_new *cap_mixer; /* capture mixer */
86 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
88 const struct hda_verb *init_verbs[10]; /* initialization verbs
92 unsigned int num_init_verbs;
94 char stream_name_analog[32]; /* analog PCM stream */
95 const struct hda_pcm_stream *stream_analog_playback;
96 const struct hda_pcm_stream *stream_analog_capture;
97 const struct hda_pcm_stream *stream_analog_alt_playback;
98 const struct hda_pcm_stream *stream_analog_alt_capture;
100 char stream_name_digital[32]; /* digital PCM stream */
101 const struct hda_pcm_stream *stream_digital_playback;
102 const struct hda_pcm_stream *stream_digital_capture;
105 struct hda_multi_out multiout; /* playback set-up
106 * max_channels, dacs must be set
107 * dig_out_nid and hp_nid are optional
109 hda_nid_t alt_dac_nid;
110 hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */
114 unsigned int num_adc_nids;
115 const hda_nid_t *adc_nids;
116 const hda_nid_t *capsrc_nids;
117 hda_nid_t dig_in_nid; /* digital-in NID; optional */
118 hda_nid_t mixer_nid; /* analog-mixer NID */
120 /* capture setup for dynamic dual-adc switch */
122 unsigned int cur_adc_stream_tag;
123 unsigned int cur_adc_format;
126 unsigned int num_mux_defs;
127 const struct hda_input_mux *input_mux;
128 unsigned int cur_mux[3];
129 hda_nid_t ext_mic_pin;
130 hda_nid_t dock_mic_pin;
131 hda_nid_t int_mic_pin;
134 const struct hda_channel_mode *channel_mode;
135 int num_channel_mode;
137 int const_channel_count;
138 int ext_channel_count;
140 /* PCM information */
141 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
143 /* dynamic controls, init_verbs and input_mux */
144 struct auto_pin_cfg autocfg;
145 struct alc_customize_define cdefine;
146 struct snd_array kctls;
147 struct hda_input_mux private_imux[3];
148 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
149 hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS];
150 hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS];
151 hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS];
152 unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS];
153 int int_mic_idx, ext_mic_idx, dock_mic_idx; /* for auto-mic */
156 void (*init_hook)(struct hda_codec *codec);
157 void (*unsol_event)(struct hda_codec *codec, unsigned int res);
158 #ifdef CONFIG_SND_HDA_POWER_SAVE
159 void (*power_hook)(struct hda_codec *codec);
161 void (*shutup)(struct hda_codec *codec);
162 void (*automute_hook)(struct hda_codec *codec);
164 /* for pin sensing */
165 unsigned int jack_present: 1;
166 unsigned int line_jack_present:1;
167 unsigned int master_mute:1;
168 unsigned int auto_mic:1;
169 unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */
170 unsigned int automute:1; /* HP automute enabled */
171 unsigned int detect_line:1; /* Line-out detection enabled */
172 unsigned int automute_lines:1; /* automute line-out as well; NOP when automute_hp_lo isn't set */
173 unsigned int automute_hp_lo:1; /* both HP and LO available */
176 unsigned int no_analog :1; /* digital I/O only */
177 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
178 unsigned int single_input_src:1;
179 unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */
180 unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */
182 /* auto-mute control */
184 hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS];
187 int codec_variant; /* flag for other variants */
189 /* for virtual master */
190 hda_nid_t vmaster_nid;
191 #ifdef CONFIG_SND_HDA_POWER_SAVE
192 struct hda_loopback_check loopback;
197 unsigned int pll_coef_idx, pll_coef_bit;
201 const struct alc_fixup *fixup_list;
202 const char *fixup_name;
206 struct alc_multi_io multi_io[4];
209 struct snd_array bind_ctls;
212 #define ALC_MODEL_AUTO 0 /* common for all chips */
214 static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
215 int dir, unsigned int bits)
219 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
220 if (query_amp_caps(codec, nid, dir) & bits)
225 #define nid_has_mute(codec, nid, dir) \
226 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
227 #define nid_has_volume(codec, nid, dir) \
228 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
233 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
234 struct snd_ctl_elem_info *uinfo)
236 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
237 struct alc_spec *spec = codec->spec;
238 unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
239 if (mux_idx >= spec->num_mux_defs)
241 if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
243 return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
246 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
247 struct snd_ctl_elem_value *ucontrol)
249 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
250 struct alc_spec *spec = codec->spec;
251 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
253 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
257 static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
259 struct alc_spec *spec = codec->spec;
260 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
262 if (spec->cur_adc && spec->cur_adc != new_adc) {
263 /* stream is running, let's swap the current ADC */
264 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
265 spec->cur_adc = new_adc;
266 snd_hda_codec_setup_stream(codec, new_adc,
267 spec->cur_adc_stream_tag, 0,
268 spec->cur_adc_format);
274 /* select the given imux item; either unmute exclusively or select the route */
275 static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
276 unsigned int idx, bool force)
278 struct alc_spec *spec = codec->spec;
279 const struct hda_input_mux *imux;
280 unsigned int mux_idx;
284 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
285 imux = &spec->input_mux[mux_idx];
286 if (!imux->num_items && mux_idx > 0)
287 imux = &spec->input_mux[0];
289 if (idx >= imux->num_items)
290 idx = imux->num_items - 1;
291 if (spec->cur_mux[adc_idx] == idx && !force)
293 spec->cur_mux[adc_idx] = idx;
295 if (spec->dyn_adc_switch) {
296 alc_dyn_adc_pcm_resetup(codec, idx);
297 adc_idx = spec->dyn_adc_idx[idx];
300 nid = spec->capsrc_nids ?
301 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
304 if (snd_hda_get_conn_list(codec, nid, NULL) <= 1)
307 type = get_wcaps_type(get_wcaps(codec, nid));
308 if (type == AC_WID_AUD_MIX) {
309 /* Matrix-mixer style (e.g. ALC882) */
310 for (i = 0; i < imux->num_items; i++) {
311 unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
312 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
313 imux->items[i].index,
317 /* MUX style (e.g. ALC880) */
318 snd_hda_codec_write_cache(codec, nid, 0,
319 AC_VERB_SET_CONNECT_SEL,
320 imux->items[idx].index);
325 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
326 struct snd_ctl_elem_value *ucontrol)
328 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
329 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
330 return alc_mux_select(codec, adc_idx,
331 ucontrol->value.enumerated.item[0], false);
335 * set up the input pin config (depending on the given auto-pin type)
337 static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
340 unsigned int val = PIN_IN;
342 if (auto_pin_type == AUTO_PIN_MIC) {
345 oldval = snd_hda_codec_read(codec, nid, 0,
346 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
347 pincap = snd_hda_query_pin_caps(codec, nid);
348 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
349 /* if the default pin setup is vref50, we give it priority */
350 if ((pincap & AC_PINCAP_VREF_80) && oldval != PIN_VREF50)
352 else if (pincap & AC_PINCAP_VREF_50)
354 else if (pincap & AC_PINCAP_VREF_100)
356 else if (pincap & AC_PINCAP_VREF_GRD)
359 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val);
363 * Append the given mixer and verb elements for the later use
364 * The mixer array is referred in build_controls(), and init_verbs are
367 static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
369 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
371 spec->mixers[spec->num_mixers++] = mix;
374 static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
376 if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
378 spec->init_verbs[spec->num_init_verbs++] = verb;
382 * GPIO setup tables, used in initialization
384 /* Enable GPIO mask and set output */
385 static const struct hda_verb alc_gpio1_init_verbs[] = {
386 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
387 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
388 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
392 static const struct hda_verb alc_gpio2_init_verbs[] = {
393 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
394 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
395 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
399 static const struct hda_verb alc_gpio3_init_verbs[] = {
400 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
401 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
402 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
407 * Fix hardware PLL issue
408 * On some codecs, the analog PLL gating control must be off while
409 * the default value is 1.
411 static void alc_fix_pll(struct hda_codec *codec)
413 struct alc_spec *spec = codec->spec;
418 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
420 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
421 AC_VERB_GET_PROC_COEF, 0);
422 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
424 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
425 val & ~(1 << spec->pll_coef_bit));
428 static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
429 unsigned int coef_idx, unsigned int coef_bit)
431 struct alc_spec *spec = codec->spec;
433 spec->pll_coef_idx = coef_idx;
434 spec->pll_coef_bit = coef_bit;
439 * Jack-reporting via input-jack layer
442 /* initialization of jacks; currently checks only a few known pins */
443 static int alc_init_jacks(struct hda_codec *codec)
445 #ifdef CONFIG_SND_HDA_INPUT_JACK
446 struct alc_spec *spec = codec->spec;
448 unsigned int hp_nid = spec->autocfg.hp_pins[0];
449 unsigned int mic_nid = spec->ext_mic_pin;
450 unsigned int dock_nid = spec->dock_mic_pin;
453 err = snd_hda_input_jack_add(codec, hp_nid,
454 SND_JACK_HEADPHONE, NULL);
457 snd_hda_input_jack_report(codec, hp_nid);
461 err = snd_hda_input_jack_add(codec, mic_nid,
462 SND_JACK_MICROPHONE, NULL);
465 snd_hda_input_jack_report(codec, mic_nid);
468 err = snd_hda_input_jack_add(codec, dock_nid,
469 SND_JACK_MICROPHONE, NULL);
472 snd_hda_input_jack_report(codec, dock_nid);
474 #endif /* CONFIG_SND_HDA_INPUT_JACK */
479 * Jack detections for HP auto-mute and mic-switch
482 /* check each pin in the given array; returns true if any of them is plugged */
483 static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
487 for (i = 0; i < num_pins; i++) {
488 hda_nid_t nid = pins[i];
491 snd_hda_input_jack_report(codec, nid);
492 present |= snd_hda_jack_detect(codec, nid);
497 /* standard HP/line-out auto-mute helper */
498 static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
499 bool mute, bool hp_out)
501 struct alc_spec *spec = codec->spec;
502 unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0;
503 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
506 for (i = 0; i < num_pins; i++) {
507 hda_nid_t nid = pins[i];
510 switch (spec->automute_mode) {
511 case ALC_AUTOMUTE_PIN:
512 snd_hda_codec_write(codec, nid, 0,
513 AC_VERB_SET_PIN_WIDGET_CONTROL,
516 case ALC_AUTOMUTE_AMP:
517 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
518 HDA_AMP_MUTE, mute_bits);
520 case ALC_AUTOMUTE_MIXER:
521 nid = spec->automute_mixer_nid[i];
524 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
525 HDA_AMP_MUTE, mute_bits);
526 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1,
527 HDA_AMP_MUTE, mute_bits);
533 /* Toggle internal speakers muting */
534 static void update_speakers(struct hda_codec *codec)
536 struct alc_spec *spec = codec->spec;
539 /* Control HP pins/amps depending on master_mute state;
540 * in general, HP pins/amps control should be enabled in all cases,
541 * but currently set only for master_mute, just to be safe
543 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
544 spec->autocfg.hp_pins, spec->master_mute, true);
549 on = spec->jack_present | spec->line_jack_present;
550 on |= spec->master_mute;
551 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
552 spec->autocfg.speaker_pins, on, false);
554 /* toggle line-out mutes if needed, too */
555 /* if LO is a copy of either HP or Speaker, don't need to handle it */
556 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
557 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
559 if (!spec->automute || (spec->automute_hp_lo && !spec->automute_lines))
562 on = spec->jack_present;
563 on |= spec->master_mute;
564 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
565 spec->autocfg.line_out_pins, on, false);
568 static void call_update_speakers(struct hda_codec *codec)
570 struct alc_spec *spec = codec->spec;
571 if (spec->automute_hook)
572 spec->automute_hook(codec);
574 update_speakers(codec);
577 /* standard HP-automute helper */
578 static void alc_hp_automute(struct hda_codec *codec)
580 struct alc_spec *spec = codec->spec;
583 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
584 spec->autocfg.hp_pins);
587 call_update_speakers(codec);
590 /* standard line-out-automute helper */
591 static void alc_line_automute(struct hda_codec *codec)
593 struct alc_spec *spec = codec->spec;
595 spec->line_jack_present =
596 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
597 spec->autocfg.line_out_pins);
598 if (!spec->automute || !spec->detect_line)
600 call_update_speakers(codec);
603 #define get_connection_index(codec, mux, nid) \
604 snd_hda_get_conn_index(codec, mux, nid, 0)
606 /* standard mic auto-switch helper */
607 static void alc_mic_automute(struct hda_codec *codec)
609 struct alc_spec *spec = codec->spec;
610 hda_nid_t *pins = spec->imux_pins;
612 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
614 if (snd_BUG_ON(!spec->adc_nids))
616 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
619 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
620 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
621 else if (spec->dock_mic_idx >= 0 &&
622 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
623 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
625 alc_mux_select(codec, 0, spec->int_mic_idx, false);
627 snd_hda_input_jack_report(codec, pins[spec->ext_mic_idx]);
628 if (spec->dock_mic_idx >= 0)
629 snd_hda_input_jack_report(codec, pins[spec->dock_mic_idx]);
632 /* unsolicited event for HP jack sensing */
633 static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
635 if (codec->vendor_id == 0x10ec0880)
641 alc_hp_automute(codec);
643 case ALC_FRONT_EVENT:
644 alc_line_automute(codec);
647 alc_mic_automute(codec);
652 /* call init functions of standard auto-mute helpers */
653 static void alc_inithook(struct hda_codec *codec)
655 alc_hp_automute(codec);
656 alc_line_automute(codec);
657 alc_mic_automute(codec);
660 /* additional initialization for ALC888 variants */
661 static void alc888_coef_init(struct hda_codec *codec)
665 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
666 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
667 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
668 if ((tmp & 0xf0) == 0x20)
670 snd_hda_codec_read(codec, 0x20, 0,
671 AC_VERB_SET_PROC_COEF, 0x830);
674 snd_hda_codec_read(codec, 0x20, 0,
675 AC_VERB_SET_PROC_COEF, 0x3030);
678 /* additional initialization for ALC889 variants */
679 static void alc889_coef_init(struct hda_codec *codec)
683 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
684 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
685 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
686 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
689 /* turn on/off EAPD control (only if available) */
690 static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
692 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
694 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
695 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
699 /* turn on/off EAPD controls of the codec */
700 static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
702 /* We currently only handle front, HP */
703 static hda_nid_t pins[] = {
704 0x0f, 0x10, 0x14, 0x15, 0
707 for (p = pins; *p; p++)
708 set_eapd(codec, *p, on);
711 /* generic shutup callback;
712 * just turning off EPAD and a little pause for avoiding pop-noise
714 static void alc_eapd_shutup(struct hda_codec *codec)
716 alc_auto_setup_eapd(codec, false);
720 /* generic EAPD initialization */
721 static void alc_auto_init_amp(struct hda_codec *codec, int type)
725 alc_auto_setup_eapd(codec, true);
728 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
731 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
734 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
736 case ALC_INIT_DEFAULT:
737 switch (codec->vendor_id) {
739 snd_hda_codec_write(codec, 0x1a, 0,
740 AC_VERB_SET_COEF_INDEX, 7);
741 tmp = snd_hda_codec_read(codec, 0x1a, 0,
742 AC_VERB_GET_PROC_COEF, 0);
743 snd_hda_codec_write(codec, 0x1a, 0,
744 AC_VERB_SET_COEF_INDEX, 7);
745 snd_hda_codec_write(codec, 0x1a, 0,
746 AC_VERB_SET_PROC_COEF,
755 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
756 alc889_coef_init(codec);
759 alc888_coef_init(codec);
761 #if 0 /* XXX: This may cause the silent output on speaker on some machines */
764 snd_hda_codec_write(codec, 0x20, 0,
765 AC_VERB_SET_COEF_INDEX, 7);
766 tmp = snd_hda_codec_read(codec, 0x20, 0,
767 AC_VERB_GET_PROC_COEF, 0);
768 snd_hda_codec_write(codec, 0x20, 0,
769 AC_VERB_SET_COEF_INDEX, 7);
770 snd_hda_codec_write(codec, 0x20, 0,
771 AC_VERB_SET_PROC_COEF,
781 * Auto-Mute mode mixer enum support
783 static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
784 struct snd_ctl_elem_info *uinfo)
786 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
787 struct alc_spec *spec = codec->spec;
788 static const char * const texts2[] = {
789 "Disabled", "Enabled"
791 static const char * const texts3[] = {
792 "Disabled", "Speaker Only", "Line-Out+Speaker"
794 const char * const *texts;
796 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
798 if (spec->automute_hp_lo) {
799 uinfo->value.enumerated.items = 3;
802 uinfo->value.enumerated.items = 2;
805 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
806 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
807 strcpy(uinfo->value.enumerated.name,
808 texts[uinfo->value.enumerated.item]);
812 static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
813 struct snd_ctl_elem_value *ucontrol)
815 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
816 struct alc_spec *spec = codec->spec;
820 else if (!spec->automute_hp_lo || !spec->automute_lines)
824 ucontrol->value.enumerated.item[0] = val;
828 static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
829 struct snd_ctl_elem_value *ucontrol)
831 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
832 struct alc_spec *spec = codec->spec;
834 switch (ucontrol->value.enumerated.item[0]) {
841 if (spec->automute &&
842 (!spec->automute_hp_lo || !spec->automute_lines))
845 spec->automute_lines = 0;
848 if (!spec->automute_hp_lo)
850 if (spec->automute && spec->automute_lines)
853 spec->automute_lines = 1;
858 call_update_speakers(codec);
862 static const struct snd_kcontrol_new alc_automute_mode_enum = {
863 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
864 .name = "Auto-Mute Mode",
865 .info = alc_automute_mode_info,
866 .get = alc_automute_mode_get,
867 .put = alc_automute_mode_put,
870 static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec)
872 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
873 return snd_array_new(&spec->kctls);
876 static int alc_add_automute_mode_enum(struct hda_codec *codec)
878 struct alc_spec *spec = codec->spec;
879 struct snd_kcontrol_new *knew;
881 knew = alc_kcontrol_new(spec);
884 *knew = alc_automute_mode_enum;
885 knew->name = kstrdup("Auto-Mute Mode", GFP_KERNEL);
892 * Check the availability of HP/line-out auto-mute;
893 * Set up appropriately if really supported
895 static void alc_init_auto_hp(struct hda_codec *codec)
897 struct alc_spec *spec = codec->spec;
898 struct auto_pin_cfg *cfg = &spec->autocfg;
904 if (cfg->line_out_pins[0])
906 if (cfg->speaker_pins[0])
908 if (present < 2) /* need two different output types */
911 spec->automute_hp_lo = 1; /* both HP and LO automute */
913 if (!cfg->speaker_pins[0] &&
914 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
915 memcpy(cfg->speaker_pins, cfg->line_out_pins,
916 sizeof(cfg->speaker_pins));
917 cfg->speaker_outs = cfg->line_outs;
920 if (!cfg->hp_pins[0] &&
921 cfg->line_out_type == AUTO_PIN_HP_OUT) {
922 memcpy(cfg->hp_pins, cfg->line_out_pins,
923 sizeof(cfg->hp_pins));
924 cfg->hp_outs = cfg->line_outs;
927 for (i = 0; i < cfg->hp_outs; i++) {
928 hda_nid_t nid = cfg->hp_pins[i];
929 if (!is_jack_detectable(codec, nid))
931 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
933 snd_hda_codec_write_cache(codec, nid, 0,
934 AC_VERB_SET_UNSOLICITED_ENABLE,
935 AC_USRSP_EN | ALC_HP_EVENT);
937 spec->automute_mode = ALC_AUTOMUTE_PIN;
939 if (spec->automute && cfg->line_out_pins[0] &&
940 cfg->speaker_pins[0] &&
941 cfg->line_out_pins[0] != cfg->hp_pins[0] &&
942 cfg->line_out_pins[0] != cfg->speaker_pins[0]) {
943 for (i = 0; i < cfg->line_outs; i++) {
944 hda_nid_t nid = cfg->line_out_pins[i];
945 if (!is_jack_detectable(codec, nid))
947 snd_printdd("realtek: Enable Line-Out auto-muting "
948 "on NID 0x%x\n", nid);
949 snd_hda_codec_write_cache(codec, nid, 0,
950 AC_VERB_SET_UNSOLICITED_ENABLE,
951 AC_USRSP_EN | ALC_FRONT_EVENT);
952 spec->detect_line = 1;
954 spec->automute_lines = spec->detect_line;
957 if (spec->automute) {
958 /* create a control for automute mode */
959 alc_add_automute_mode_enum(codec);
960 spec->unsol_event = alc_sku_unsol_event;
964 /* return the position of NID in the list, or -1 if not found */
965 static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
968 for (i = 0; i < nums; i++)
974 /* check whether dynamic ADC-switching is available */
975 static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
977 struct alc_spec *spec = codec->spec;
978 struct hda_input_mux *imux = &spec->private_imux[0];
982 if (imux != spec->input_mux) /* no dynamic imux? */
985 for (n = 0; n < spec->num_adc_nids; n++) {
986 cap = spec->private_capsrc_nids[n];
987 for (i = 0; i < imux->num_items; i++) {
988 pin = spec->imux_pins[i];
991 if (get_connection_index(codec, cap, pin) < 0)
994 if (i >= imux->num_items)
995 return true; /* no ADC-switch is needed */
998 for (i = 0; i < imux->num_items; i++) {
999 pin = spec->imux_pins[i];
1000 for (n = 0; n < spec->num_adc_nids; n++) {
1001 cap = spec->private_capsrc_nids[n];
1002 idx = get_connection_index(codec, cap, pin);
1004 imux->items[i].index = idx;
1005 spec->dyn_adc_idx[i] = n;
1011 snd_printdd("realtek: enabling ADC switching\n");
1012 spec->dyn_adc_switch = 1;
1016 /* rebuild imux for matching with the given auto-mic pins (if not yet) */
1017 static bool alc_rebuild_imux_for_auto_mic(struct hda_codec *codec)
1019 struct alc_spec *spec = codec->spec;
1020 struct hda_input_mux *imux;
1021 static char * const texts[3] = {
1022 "Mic", "Internal Mic", "Dock Mic"
1026 if (!spec->auto_mic)
1028 imux = &spec->private_imux[0];
1029 if (spec->input_mux == imux)
1031 spec->imux_pins[0] = spec->ext_mic_pin;
1032 spec->imux_pins[1] = spec->int_mic_pin;
1033 spec->imux_pins[2] = spec->dock_mic_pin;
1034 for (i = 0; i < 3; i++) {
1035 strcpy(imux->items[i].label, texts[i]);
1036 if (spec->imux_pins[i])
1037 imux->num_items = i + 1;
1039 spec->num_mux_defs = 1;
1040 spec->input_mux = imux;
1044 /* check whether all auto-mic pins are valid; setup indices if OK */
1045 static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1047 struct alc_spec *spec = codec->spec;
1048 const struct hda_input_mux *imux;
1050 if (!spec->auto_mic)
1052 if (spec->auto_mic_valid_imux)
1053 return true; /* already checked */
1055 /* fill up imux indices */
1056 if (!alc_check_dyn_adc_switch(codec)) {
1061 imux = spec->input_mux;
1062 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1063 spec->imux_pins, imux->num_items);
1064 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1065 spec->imux_pins, imux->num_items);
1066 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1067 spec->imux_pins, imux->num_items);
1068 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1070 return false; /* no corresponding imux */
1073 snd_hda_codec_write_cache(codec, spec->ext_mic_pin, 0,
1074 AC_VERB_SET_UNSOLICITED_ENABLE,
1075 AC_USRSP_EN | ALC_MIC_EVENT);
1076 if (spec->dock_mic_pin)
1077 snd_hda_codec_write_cache(codec, spec->dock_mic_pin, 0,
1078 AC_VERB_SET_UNSOLICITED_ENABLE,
1079 AC_USRSP_EN | ALC_MIC_EVENT);
1081 spec->auto_mic_valid_imux = 1;
1087 * Check the availability of auto-mic switch;
1088 * Set up if really supported
1090 static void alc_init_auto_mic(struct hda_codec *codec)
1092 struct alc_spec *spec = codec->spec;
1093 struct auto_pin_cfg *cfg = &spec->autocfg;
1094 hda_nid_t fixed, ext, dock;
1097 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1099 fixed = ext = dock = 0;
1100 for (i = 0; i < cfg->num_inputs; i++) {
1101 hda_nid_t nid = cfg->inputs[i].pin;
1102 unsigned int defcfg;
1103 defcfg = snd_hda_codec_get_pincfg(codec, nid);
1104 switch (snd_hda_get_input_pin_attr(defcfg)) {
1105 case INPUT_PIN_ATTR_INT:
1107 return; /* already occupied */
1108 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1109 return; /* invalid type */
1112 case INPUT_PIN_ATTR_UNUSED:
1113 return; /* invalid entry */
1114 case INPUT_PIN_ATTR_DOCK:
1116 return; /* already occupied */
1117 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1118 return; /* invalid type */
1123 return; /* already occupied */
1124 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1125 return; /* invalid type */
1136 if (!is_jack_detectable(codec, ext))
1137 return; /* no unsol support */
1138 if (dock && !is_jack_detectable(codec, dock))
1139 return; /* no unsol support */
1141 /* check imux indices */
1142 spec->ext_mic_pin = ext;
1143 spec->int_mic_pin = fixed;
1144 spec->dock_mic_pin = dock;
1147 if (!alc_auto_mic_check_imux(codec))
1150 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1152 spec->unsol_event = alc_sku_unsol_event;
1155 /* check the availabilities of auto-mute and auto-mic switches */
1156 static void alc_auto_check_switches(struct hda_codec *codec)
1158 alc_init_auto_hp(codec);
1159 alc_init_auto_mic(codec);
1163 * Realtek SSID verification
1166 /* Could be any non-zero and even value. When used as fixup, tells
1167 * the driver to ignore any present sku defines.
1169 #define ALC_FIXUP_SKU_IGNORE (2)
1171 static int alc_auto_parse_customize_define(struct hda_codec *codec)
1173 unsigned int ass, tmp, i;
1175 struct alc_spec *spec = codec->spec;
1177 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1179 if (spec->cdefine.fixup) {
1180 ass = spec->cdefine.sku_cfg;
1181 if (ass == ALC_FIXUP_SKU_IGNORE)
1186 ass = codec->subsystem_id & 0xffff;
1187 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
1191 if (codec->vendor_id == 0x10ec0260)
1193 ass = snd_hda_codec_get_pincfg(codec, nid);
1196 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1197 codec->chip_name, ass);
1203 for (i = 1; i < 16; i++) {
1207 if (((ass >> 16) & 0xf) != tmp)
1210 spec->cdefine.port_connectivity = ass >> 30;
1211 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1212 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1213 spec->cdefine.customization = ass >> 8;
1215 spec->cdefine.sku_cfg = ass;
1216 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1217 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1218 spec->cdefine.swap = (ass & 0x2) >> 1;
1219 spec->cdefine.override = ass & 0x1;
1221 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1222 nid, spec->cdefine.sku_cfg);
1223 snd_printd("SKU: port_connectivity=0x%x\n",
1224 spec->cdefine.port_connectivity);
1225 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1226 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1227 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1228 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1229 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1230 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1231 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1236 /* return true if the given NID is found in the list */
1237 static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1239 return find_idx_in_nid_list(nid, list, nums) >= 0;
1242 /* check subsystem ID and set up device-specific initialization;
1243 * return 1 if initialized, 0 if invalid SSID
1245 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1246 * 31 ~ 16 : Manufacture ID
1248 * 7 ~ 0 : Assembly ID
1249 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1251 static int alc_subsystem_id(struct hda_codec *codec,
1252 hda_nid_t porta, hda_nid_t porte,
1253 hda_nid_t portd, hda_nid_t porti)
1255 unsigned int ass, tmp, i;
1257 struct alc_spec *spec = codec->spec;
1259 if (spec->cdefine.fixup) {
1260 ass = spec->cdefine.sku_cfg;
1261 if (ass == ALC_FIXUP_SKU_IGNORE)
1266 ass = codec->subsystem_id & 0xffff;
1267 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1270 /* invalid SSID, check the special NID pin defcfg instead */
1272 * 31~30 : port connectivity
1275 * 19~16 : Check sum (15:1)
1280 if (codec->vendor_id == 0x10ec0260)
1282 ass = snd_hda_codec_get_pincfg(codec, nid);
1283 snd_printd("realtek: No valid SSID, "
1284 "checking pincfg 0x%08x for NID 0x%x\n",
1288 if ((ass >> 30) != 1) /* no physical connection */
1293 for (i = 1; i < 16; i++) {
1297 if (((ass >> 16) & 0xf) != tmp)
1300 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1301 ass & 0xffff, codec->vendor_id);
1305 * 2 : 0 --> Desktop, 1 --> Laptop
1306 * 3~5 : External Amplifier control
1309 tmp = (ass & 0x38) >> 3; /* external Amp control */
1312 spec->init_amp = ALC_INIT_GPIO1;
1315 spec->init_amp = ALC_INIT_GPIO2;
1318 spec->init_amp = ALC_INIT_GPIO3;
1322 spec->init_amp = ALC_INIT_DEFAULT;
1326 /* is laptop or Desktop and enable the function "Mute internal speaker
1327 * when the external headphone out jack is plugged"
1329 if (!(ass & 0x8000))
1332 * 10~8 : Jack location
1333 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1335 * 15 : 1 --> enable the function "Mute internal speaker
1336 * when the external headphone out jack is plugged"
1338 if (!spec->autocfg.hp_pins[0]) {
1340 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1351 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1352 spec->autocfg.line_outs))
1354 spec->autocfg.hp_pins[0] = nid;
1359 /* Check the validity of ALC subsystem-id
1360 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1361 static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
1363 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
1364 struct alc_spec *spec = codec->spec;
1365 snd_printd("realtek: "
1366 "Enable default setup for auto mode as fallback\n");
1367 spec->init_amp = ALC_INIT_DEFAULT;
1372 * Fix-up pin default configurations and add default verbs
1380 struct alc_model_fixup {
1391 const struct alc_pincfg *pins;
1392 const struct hda_verb *verbs;
1393 void (*func)(struct hda_codec *codec,
1394 const struct alc_fixup *fix,
1408 ALC_FIXUP_ACT_PRE_PROBE,
1409 ALC_FIXUP_ACT_PROBE,
1413 static void alc_apply_fixup(struct hda_codec *codec, int action)
1415 struct alc_spec *spec = codec->spec;
1416 int id = spec->fixup_id;
1417 #ifdef CONFIG_SND_DEBUG_VERBOSE
1418 const char *modelname = spec->fixup_name;
1422 if (!spec->fixup_list)
1426 const struct alc_fixup *fix = spec->fixup_list + id;
1427 const struct alc_pincfg *cfg;
1429 switch (fix->type) {
1431 if (action != ALC_FIXUP_ACT_PRE_PROBE || !fix->v.sku)
1433 snd_printdd(KERN_INFO "hda_codec: %s: "
1434 "Apply sku override for %s\n",
1435 codec->chip_name, modelname);
1436 spec->cdefine.sku_cfg = fix->v.sku;
1437 spec->cdefine.fixup = 1;
1439 case ALC_FIXUP_PINS:
1441 if (action != ALC_FIXUP_ACT_PRE_PROBE || !cfg)
1443 snd_printdd(KERN_INFO "hda_codec: %s: "
1444 "Apply pincfg for %s\n",
1445 codec->chip_name, modelname);
1446 for (; cfg->nid; cfg++)
1447 snd_hda_codec_set_pincfg(codec, cfg->nid,
1450 case ALC_FIXUP_VERBS:
1451 if (action != ALC_FIXUP_ACT_PROBE || !fix->v.verbs)
1453 snd_printdd(KERN_INFO "hda_codec: %s: "
1454 "Apply fix-verbs for %s\n",
1455 codec->chip_name, modelname);
1456 add_verb(codec->spec, fix->v.verbs);
1458 case ALC_FIXUP_FUNC:
1461 snd_printdd(KERN_INFO "hda_codec: %s: "
1462 "Apply fix-func for %s\n",
1463 codec->chip_name, modelname);
1464 fix->v.func(codec, fix, action);
1467 snd_printk(KERN_ERR "hda_codec: %s: "
1468 "Invalid fixup type %d\n",
1469 codec->chip_name, fix->type);
1480 static void alc_pick_fixup(struct hda_codec *codec,
1481 const struct alc_model_fixup *models,
1482 const struct snd_pci_quirk *quirk,
1483 const struct alc_fixup *fixlist)
1485 struct alc_spec *spec = codec->spec;
1487 const char *name = NULL;
1489 if (codec->modelname && models) {
1490 while (models->name) {
1491 if (!strcmp(codec->modelname, models->name)) {
1493 name = models->name;
1500 quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1503 #ifdef CONFIG_SND_DEBUG_VERBOSE
1509 spec->fixup_id = id;
1511 spec->fixup_list = fixlist;
1512 spec->fixup_name = name;
1517 * COEF access helper functions
1519 static int alc_read_coef_idx(struct hda_codec *codec,
1520 unsigned int coef_idx)
1523 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1525 val = snd_hda_codec_read(codec, 0x20, 0,
1526 AC_VERB_GET_PROC_COEF, 0);
1530 static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1531 unsigned int coef_val)
1533 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1535 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1540 * Digital I/O handling
1543 /* set right pin controls for digital I/O */
1544 static void alc_auto_init_digital(struct hda_codec *codec)
1546 struct alc_spec *spec = codec->spec;
1550 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1551 pin = spec->autocfg.dig_out_pins[i];
1554 snd_hda_codec_write(codec, pin, 0,
1555 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
1557 dac = spec->multiout.dig_out_nid;
1559 dac = spec->slave_dig_outs[i - 1];
1560 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
1562 snd_hda_codec_write(codec, dac, 0,
1563 AC_VERB_SET_AMP_GAIN_MUTE,
1566 pin = spec->autocfg.dig_in_pin;
1568 snd_hda_codec_write(codec, pin, 0,
1569 AC_VERB_SET_PIN_WIDGET_CONTROL,
1573 /* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1574 static void alc_auto_parse_digital(struct hda_codec *codec)
1576 struct alc_spec *spec = codec->spec;
1580 /* support multiple SPDIFs; the secondary is set up as a slave */
1581 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1583 err = snd_hda_get_connections(codec,
1584 spec->autocfg.dig_out_pins[i],
1585 conn, ARRAY_SIZE(conn));
1588 dig_nid = conn[0]; /* assume the first element is audio-out */
1590 spec->multiout.dig_out_nid = dig_nid;
1591 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1593 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
1594 if (i >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
1596 spec->slave_dig_outs[i - 1] = dig_nid;
1600 if (spec->autocfg.dig_in_pin) {
1601 dig_nid = codec->start_nid;
1602 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1603 unsigned int wcaps = get_wcaps(codec, dig_nid);
1604 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1606 if (!(wcaps & AC_WCAP_DIGITAL))
1608 if (!(wcaps & AC_WCAP_CONN_LIST))
1610 err = get_connection_index(codec, dig_nid,
1611 spec->autocfg.dig_in_pin);
1613 spec->dig_in_nid = dig_nid;
1621 * capture mixer elements
1623 static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1624 struct snd_ctl_elem_info *uinfo)
1626 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1627 struct alc_spec *spec = codec->spec;
1631 mutex_lock(&codec->control_mutex);
1632 if (spec->vol_in_capsrc)
1633 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1635 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1636 kcontrol->private_value = val;
1637 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
1638 mutex_unlock(&codec->control_mutex);
1642 static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1643 unsigned int size, unsigned int __user *tlv)
1645 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1646 struct alc_spec *spec = codec->spec;
1650 mutex_lock(&codec->control_mutex);
1651 if (spec->vol_in_capsrc)
1652 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1654 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1655 kcontrol->private_value = val;
1656 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
1657 mutex_unlock(&codec->control_mutex);
1661 typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1662 struct snd_ctl_elem_value *ucontrol);
1664 static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1665 struct snd_ctl_elem_value *ucontrol,
1666 getput_call_t func, bool check_adc_switch)
1668 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1669 struct alc_spec *spec = codec->spec;
1672 mutex_lock(&codec->control_mutex);
1673 if (check_adc_switch && spec->dyn_adc_switch) {
1674 for (i = 0; i < spec->num_adc_nids; i++) {
1675 kcontrol->private_value =
1676 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1678 err = func(kcontrol, ucontrol);
1683 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1684 if (spec->vol_in_capsrc)
1685 kcontrol->private_value =
1686 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1689 kcontrol->private_value =
1690 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1692 err = func(kcontrol, ucontrol);
1695 mutex_unlock(&codec->control_mutex);
1699 static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1700 struct snd_ctl_elem_value *ucontrol)
1702 return alc_cap_getput_caller(kcontrol, ucontrol,
1703 snd_hda_mixer_amp_volume_get, false);
1706 static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1707 struct snd_ctl_elem_value *ucontrol)
1709 return alc_cap_getput_caller(kcontrol, ucontrol,
1710 snd_hda_mixer_amp_volume_put, true);
1713 /* capture mixer elements */
1714 #define alc_cap_sw_info snd_ctl_boolean_stereo_info
1716 static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1717 struct snd_ctl_elem_value *ucontrol)
1719 return alc_cap_getput_caller(kcontrol, ucontrol,
1720 snd_hda_mixer_amp_switch_get, false);
1723 static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1724 struct snd_ctl_elem_value *ucontrol)
1726 return alc_cap_getput_caller(kcontrol, ucontrol,
1727 snd_hda_mixer_amp_switch_put, true);
1730 #define _DEFINE_CAPMIX(num) \
1732 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1733 .name = "Capture Switch", \
1734 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1736 .info = alc_cap_sw_info, \
1737 .get = alc_cap_sw_get, \
1738 .put = alc_cap_sw_put, \
1741 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1742 .name = "Capture Volume", \
1743 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1744 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1745 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1747 .info = alc_cap_vol_info, \
1748 .get = alc_cap_vol_get, \
1749 .put = alc_cap_vol_put, \
1750 .tlv = { .c = alc_cap_vol_tlv }, \
1753 #define _DEFINE_CAPSRC(num) \
1755 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1756 /* .name = "Capture Source", */ \
1757 .name = "Input Source", \
1759 .info = alc_mux_enum_info, \
1760 .get = alc_mux_enum_get, \
1761 .put = alc_mux_enum_put, \
1764 #define DEFINE_CAPMIX(num) \
1765 static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
1766 _DEFINE_CAPMIX(num), \
1767 _DEFINE_CAPSRC(num), \
1771 #define DEFINE_CAPMIX_NOSRC(num) \
1772 static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
1773 _DEFINE_CAPMIX(num), \
1777 /* up to three ADCs */
1781 DEFINE_CAPMIX_NOSRC(1);
1782 DEFINE_CAPMIX_NOSRC(2);
1783 DEFINE_CAPMIX_NOSRC(3);
1786 * virtual master controls
1790 * slave controls for virtual master
1792 static const char * const alc_slave_vols[] = {
1793 "Front Playback Volume",
1794 "Surround Playback Volume",
1795 "Center Playback Volume",
1796 "LFE Playback Volume",
1797 "Side Playback Volume",
1798 "Headphone Playback Volume",
1799 "Speaker Playback Volume",
1800 "Mono Playback Volume",
1801 "Line-Out Playback Volume",
1802 "PCM Playback Volume",
1806 static const char * const alc_slave_sws[] = {
1807 "Front Playback Switch",
1808 "Surround Playback Switch",
1809 "Center Playback Switch",
1810 "LFE Playback Switch",
1811 "Side Playback Switch",
1812 "Headphone Playback Switch",
1813 "Speaker Playback Switch",
1814 "Mono Playback Switch",
1815 "IEC958 Playback Switch",
1816 "Line-Out Playback Switch",
1817 "PCM Playback Switch",
1822 * build control elements
1825 #define NID_MAPPING (-1)
1827 #define SUBDEV_SPEAKER_ (0 << 6)
1828 #define SUBDEV_HP_ (1 << 6)
1829 #define SUBDEV_LINE_ (2 << 6)
1830 #define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1831 #define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1832 #define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1834 static void alc_free_kctls(struct hda_codec *codec);
1836 #ifdef CONFIG_SND_HDA_INPUT_BEEP
1837 /* additional beep mixers; the actual parameters are overwritten at build */
1838 static const struct snd_kcontrol_new alc_beep_mixer[] = {
1839 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
1840 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
1845 static int alc_build_controls(struct hda_codec *codec)
1847 struct alc_spec *spec = codec->spec;
1848 struct snd_kcontrol *kctl = NULL;
1849 const struct snd_kcontrol_new *knew;
1854 for (i = 0; i < spec->num_mixers; i++) {
1855 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1859 if (spec->cap_mixer) {
1860 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1864 if (spec->multiout.dig_out_nid) {
1865 err = snd_hda_create_spdif_out_ctls(codec,
1866 spec->multiout.dig_out_nid,
1867 spec->multiout.dig_out_nid);
1870 if (!spec->no_analog) {
1871 err = snd_hda_create_spdif_share_sw(codec,
1875 spec->multiout.share_spdif = 1;
1878 if (spec->dig_in_nid) {
1879 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1884 #ifdef CONFIG_SND_HDA_INPUT_BEEP
1885 /* create beep controls if needed */
1886 if (spec->beep_amp) {
1887 const struct snd_kcontrol_new *knew;
1888 for (knew = alc_beep_mixer; knew->name; knew++) {
1889 struct snd_kcontrol *kctl;
1890 kctl = snd_ctl_new1(knew, codec);
1893 kctl->private_value = spec->beep_amp;
1894 err = snd_hda_ctl_add(codec, 0, kctl);
1901 /* if we have no master control, let's create it */
1902 if (!spec->no_analog &&
1903 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1904 unsigned int vmaster_tlv[4];
1905 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
1906 HDA_OUTPUT, vmaster_tlv);
1907 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1908 vmaster_tlv, alc_slave_vols);
1912 if (!spec->no_analog &&
1913 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1914 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1915 NULL, alc_slave_sws);
1920 /* assign Capture Source enums to NID */
1921 if (spec->capsrc_nids || spec->adc_nids) {
1922 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
1924 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1925 for (i = 0; kctl && i < kctl->count; i++) {
1926 const hda_nid_t *nids = spec->capsrc_nids;
1928 nids = spec->adc_nids;
1929 err = snd_hda_add_nid(codec, kctl, i, nids[i]);
1934 if (spec->cap_mixer && spec->adc_nids) {
1935 const char *kname = kctl ? kctl->id.name : NULL;
1936 for (knew = spec->cap_mixer; knew->name; knew++) {
1937 if (kname && strcmp(knew->name, kname) == 0)
1939 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1940 for (i = 0; kctl && i < kctl->count; i++) {
1941 err = snd_hda_add_nid(codec, kctl, i,
1949 /* other nid->control mapping */
1950 for (i = 0; i < spec->num_mixers; i++) {
1951 for (knew = spec->mixers[i]; knew->name; knew++) {
1952 if (knew->iface != NID_MAPPING)
1954 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1957 u = knew->subdevice;
1958 for (j = 0; j < 4; j++, u >>= 8) {
1963 case SUBDEV_SPEAKER_:
1964 nid = spec->autocfg.speaker_pins[nid];
1967 nid = spec->autocfg.line_out_pins[nid];
1970 nid = spec->autocfg.hp_pins[nid];
1975 err = snd_hda_add_nid(codec, kctl, 0, nid);
1979 u = knew->private_value;
1980 for (j = 0; j < 4; j++, u >>= 8) {
1984 err = snd_hda_add_nid(codec, kctl, 0, nid);
1991 alc_free_kctls(codec); /* no longer needed */
2001 static void alc_init_special_input_src(struct hda_codec *codec);
2003 static int alc_init(struct hda_codec *codec)
2005 struct alc_spec *spec = codec->spec;
2009 alc_auto_init_amp(codec, spec->init_amp);
2011 for (i = 0; i < spec->num_init_verbs; i++)
2012 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2013 alc_init_special_input_src(codec);
2015 if (spec->init_hook)
2016 spec->init_hook(codec);
2018 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2020 hda_call_check_power_status(codec, 0x01);
2024 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2026 struct alc_spec *spec = codec->spec;
2028 if (spec->unsol_event)
2029 spec->unsol_event(codec, res);
2032 #ifdef CONFIG_SND_HDA_POWER_SAVE
2033 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2035 struct alc_spec *spec = codec->spec;
2036 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2041 * Analog playback callbacks
2043 static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
2044 struct hda_codec *codec,
2045 struct snd_pcm_substream *substream)
2047 struct alc_spec *spec = codec->spec;
2048 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2052 static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2053 struct hda_codec *codec,
2054 unsigned int stream_tag,
2055 unsigned int format,
2056 struct snd_pcm_substream *substream)
2058 struct alc_spec *spec = codec->spec;
2059 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2060 stream_tag, format, substream);
2063 static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2064 struct hda_codec *codec,
2065 struct snd_pcm_substream *substream)
2067 struct alc_spec *spec = codec->spec;
2068 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2074 static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2075 struct hda_codec *codec,
2076 struct snd_pcm_substream *substream)
2078 struct alc_spec *spec = codec->spec;
2079 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2082 static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2083 struct hda_codec *codec,
2084 unsigned int stream_tag,
2085 unsigned int format,
2086 struct snd_pcm_substream *substream)
2088 struct alc_spec *spec = codec->spec;
2089 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2090 stream_tag, format, substream);
2093 static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2094 struct hda_codec *codec,
2095 struct snd_pcm_substream *substream)
2097 struct alc_spec *spec = codec->spec;
2098 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2101 static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2102 struct hda_codec *codec,
2103 struct snd_pcm_substream *substream)
2105 struct alc_spec *spec = codec->spec;
2106 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2112 static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2113 struct hda_codec *codec,
2114 unsigned int stream_tag,
2115 unsigned int format,
2116 struct snd_pcm_substream *substream)
2118 struct alc_spec *spec = codec->spec;
2120 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
2121 stream_tag, 0, format);
2125 static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2126 struct hda_codec *codec,
2127 struct snd_pcm_substream *substream)
2129 struct alc_spec *spec = codec->spec;
2131 snd_hda_codec_cleanup_stream(codec,
2132 spec->adc_nids[substream->number + 1]);
2136 /* analog capture with dynamic dual-adc changes */
2137 static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2138 struct hda_codec *codec,
2139 unsigned int stream_tag,
2140 unsigned int format,
2141 struct snd_pcm_substream *substream)
2143 struct alc_spec *spec = codec->spec;
2144 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
2145 spec->cur_adc_stream_tag = stream_tag;
2146 spec->cur_adc_format = format;
2147 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2151 static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2152 struct hda_codec *codec,
2153 struct snd_pcm_substream *substream)
2155 struct alc_spec *spec = codec->spec;
2156 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2161 static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
2165 .nid = 0, /* fill later */
2167 .prepare = dyn_adc_capture_pcm_prepare,
2168 .cleanup = dyn_adc_capture_pcm_cleanup
2174 static const struct hda_pcm_stream alc_pcm_analog_playback = {
2178 /* NID is set in alc_build_pcms */
2180 .open = alc_playback_pcm_open,
2181 .prepare = alc_playback_pcm_prepare,
2182 .cleanup = alc_playback_pcm_cleanup
2186 static const struct hda_pcm_stream alc_pcm_analog_capture = {
2190 /* NID is set in alc_build_pcms */
2193 static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
2197 /* NID is set in alc_build_pcms */
2200 static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
2201 .substreams = 2, /* can be overridden */
2204 /* NID is set in alc_build_pcms */
2206 .prepare = alc_alt_capture_pcm_prepare,
2207 .cleanup = alc_alt_capture_pcm_cleanup
2211 static const struct hda_pcm_stream alc_pcm_digital_playback = {
2215 /* NID is set in alc_build_pcms */
2217 .open = alc_dig_playback_pcm_open,
2218 .close = alc_dig_playback_pcm_close,
2219 .prepare = alc_dig_playback_pcm_prepare,
2220 .cleanup = alc_dig_playback_pcm_cleanup
2224 static const struct hda_pcm_stream alc_pcm_digital_capture = {
2228 /* NID is set in alc_build_pcms */
2231 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
2232 static const struct hda_pcm_stream alc_pcm_null_stream = {
2238 static int alc_build_pcms(struct hda_codec *codec)
2240 struct alc_spec *spec = codec->spec;
2241 struct hda_pcm *info = spec->pcm_rec;
2242 const struct hda_pcm_stream *p;
2245 codec->num_pcms = 1;
2246 codec->pcm_info = info;
2248 if (spec->no_analog)
2251 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2252 "%s Analog", codec->chip_name);
2253 info->name = spec->stream_name_analog;
2255 if (spec->multiout.dac_nids > 0) {
2256 p = spec->stream_analog_playback;
2258 p = &alc_pcm_analog_playback;
2259 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2260 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2262 if (spec->adc_nids) {
2263 p = spec->stream_analog_capture;
2265 if (spec->dyn_adc_switch)
2266 p = &dyn_adc_pcm_analog_capture;
2268 p = &alc_pcm_analog_capture;
2270 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2271 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2274 if (spec->channel_mode) {
2275 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2276 for (i = 0; i < spec->num_channel_mode; i++) {
2277 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2278 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2284 /* SPDIF for stream index #1 */
2285 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2286 snprintf(spec->stream_name_digital,
2287 sizeof(spec->stream_name_digital),
2288 "%s Digital", codec->chip_name);
2289 codec->num_pcms = 2;
2290 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
2291 info = spec->pcm_rec + 1;
2292 info->name = spec->stream_name_digital;
2293 if (spec->dig_out_type)
2294 info->pcm_type = spec->dig_out_type;
2296 info->pcm_type = HDA_PCM_TYPE_SPDIF;
2297 if (spec->multiout.dig_out_nid) {
2298 p = spec->stream_digital_playback;
2300 p = &alc_pcm_digital_playback;
2301 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2302 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2304 if (spec->dig_in_nid) {
2305 p = spec->stream_digital_capture;
2307 p = &alc_pcm_digital_capture;
2308 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2309 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2311 /* FIXME: do we need this for all Realtek codec models? */
2312 codec->spdif_status_reset = 1;
2315 if (spec->no_analog)
2318 /* If the use of more than one ADC is requested for the current
2319 * model, configure a second analog capture-only PCM.
2321 /* Additional Analaog capture for index #2 */
2322 if (spec->alt_dac_nid || spec->num_adc_nids > 1) {
2323 codec->num_pcms = 3;
2324 info = spec->pcm_rec + 2;
2325 info->name = spec->stream_name_analog;
2326 if (spec->alt_dac_nid) {
2327 p = spec->stream_analog_alt_playback;
2329 p = &alc_pcm_analog_alt_playback;
2330 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2331 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2334 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2335 alc_pcm_null_stream;
2336 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2338 if (spec->num_adc_nids > 1) {
2339 p = spec->stream_analog_alt_capture;
2341 p = &alc_pcm_analog_alt_capture;
2342 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2343 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2345 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2346 spec->num_adc_nids - 1;
2348 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2349 alc_pcm_null_stream;
2350 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
2357 static inline void alc_shutup(struct hda_codec *codec)
2359 struct alc_spec *spec = codec->spec;
2361 if (spec && spec->shutup)
2362 spec->shutup(codec);
2363 snd_hda_shutup_pins(codec);
2366 static void alc_free_kctls(struct hda_codec *codec)
2368 struct alc_spec *spec = codec->spec;
2370 if (spec->kctls.list) {
2371 struct snd_kcontrol_new *kctl = spec->kctls.list;
2373 for (i = 0; i < spec->kctls.used; i++)
2374 kfree(kctl[i].name);
2376 snd_array_free(&spec->kctls);
2379 static void alc_free_bind_ctls(struct hda_codec *codec)
2381 struct alc_spec *spec = codec->spec;
2382 if (spec->bind_ctls.list) {
2383 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2385 for (i = 0; i < spec->bind_ctls.used; i++)
2388 snd_array_free(&spec->bind_ctls);
2391 static void alc_free(struct hda_codec *codec)
2393 struct alc_spec *spec = codec->spec;
2399 snd_hda_input_jack_free(codec);
2400 alc_free_kctls(codec);
2401 alc_free_bind_ctls(codec);
2403 snd_hda_detach_beep_device(codec);
2406 #ifdef CONFIG_SND_HDA_POWER_SAVE
2407 static void alc_power_eapd(struct hda_codec *codec)
2409 alc_auto_setup_eapd(codec, false);
2412 static int alc_suspend(struct hda_codec *codec, pm_message_t state)
2414 struct alc_spec *spec = codec->spec;
2416 if (spec && spec->power_hook)
2417 spec->power_hook(codec);
2423 static int alc_resume(struct hda_codec *codec)
2425 msleep(150); /* to avoid pop noise */
2426 codec->patch_ops.init(codec);
2427 snd_hda_codec_resume_amp(codec);
2428 snd_hda_codec_resume_cache(codec);
2429 hda_call_check_power_status(codec, 0x01);
2436 static const struct hda_codec_ops alc_patch_ops = {
2437 .build_controls = alc_build_controls,
2438 .build_pcms = alc_build_pcms,
2441 .unsol_event = alc_unsol_event,
2443 .resume = alc_resume,
2445 #ifdef CONFIG_SND_HDA_POWER_SAVE
2446 .suspend = alc_suspend,
2447 .check_power_status = alc_check_power_status,
2449 .reboot_notify = alc_shutup,
2452 /* replace the codec chip_name with the given string */
2453 static int alc_codec_rename(struct hda_codec *codec, const char *name)
2455 kfree(codec->chip_name);
2456 codec->chip_name = kstrdup(name, GFP_KERNEL);
2457 if (!codec->chip_name) {
2465 * Automatic parse of I/O pins from the BIOS configuration
2470 ALC_CTL_WIDGET_MUTE,
2475 static const struct snd_kcontrol_new alc_control_templates[] = {
2476 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2477 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2478 HDA_BIND_MUTE(NULL, 0, 0, 0),
2479 HDA_BIND_VOL(NULL, 0),
2480 HDA_BIND_SW(NULL, 0),
2483 /* add dynamic controls */
2484 static int add_control(struct alc_spec *spec, int type, const char *name,
2485 int cidx, unsigned long val)
2487 struct snd_kcontrol_new *knew;
2489 knew = alc_kcontrol_new(spec);
2492 *knew = alc_control_templates[type];
2493 knew->name = kstrdup(name, GFP_KERNEL);
2497 if (get_amp_nid_(val))
2498 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
2499 knew->private_value = val;
2503 static int add_control_with_pfx(struct alc_spec *spec, int type,
2504 const char *pfx, const char *dir,
2505 const char *sfx, int cidx, unsigned long val)
2508 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
2509 return add_control(spec, type, name, cidx, val);
2512 #define add_pb_vol_ctrl(spec, type, pfx, val) \
2513 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2514 #define add_pb_sw_ctrl(spec, type, pfx, val) \
2515 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2516 #define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2517 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2518 #define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2519 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
2521 static const char * const channel_name[4] = {
2522 "Front", "Surround", "CLFE", "Side"
2525 static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2526 bool can_be_master, int *index)
2528 struct auto_pin_cfg *cfg = &spec->autocfg;
2531 if (cfg->line_outs == 1 && !spec->multi_ios &&
2532 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
2535 switch (cfg->line_out_type) {
2536 case AUTO_PIN_SPEAKER_OUT:
2537 if (cfg->line_outs == 1)
2540 case AUTO_PIN_HP_OUT:
2541 /* for multi-io case, only the primary out */
2542 if (ch && spec->multi_ios)
2547 if (cfg->line_outs == 1 && !spec->multi_ios)
2551 if (snd_BUG_ON(ch >= ARRAY_SIZE(channel_name)))
2554 return channel_name[ch];
2557 /* create input playback/capture controls for the given pin */
2558 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
2559 const char *ctlname, int ctlidx,
2560 int idx, hda_nid_t mix_nid)
2564 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
2565 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2568 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
2569 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2575 static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
2577 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2578 return (pincap & AC_PINCAP_IN) != 0;
2581 /* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
2582 static int alc_auto_fill_adc_caps(struct hda_codec *codec)
2584 struct alc_spec *spec = codec->spec;
2586 hda_nid_t *adc_nids = spec->private_adc_nids;
2587 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2588 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
2589 bool indep_capsrc = false;
2592 nid = codec->start_nid;
2593 for (i = 0; i < codec->num_nodes; i++, nid++) {
2595 const hda_nid_t *list;
2596 unsigned int caps = get_wcaps(codec, nid);
2597 int type = get_wcaps_type(caps);
2599 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2601 adc_nids[nums] = nid;
2602 cap_nids[nums] = nid;
2606 type = get_wcaps_type(get_wcaps(codec, src));
2607 if (type == AC_WID_PIN)
2609 if (type == AC_WID_AUD_SEL) {
2610 cap_nids[nums] = src;
2611 indep_capsrc = true;
2614 n = snd_hda_get_conn_list(codec, src, &list);
2616 cap_nids[nums] = src;
2617 indep_capsrc = true;
2623 if (++nums >= max_nums)
2626 spec->adc_nids = spec->private_adc_nids;
2627 spec->capsrc_nids = spec->private_capsrc_nids;
2628 spec->num_adc_nids = nums;
2632 /* create playback/capture controls for input pins */
2633 static int alc_auto_create_input_ctls(struct hda_codec *codec)
2635 struct alc_spec *spec = codec->spec;
2636 const struct auto_pin_cfg *cfg = &spec->autocfg;
2637 hda_nid_t mixer = spec->mixer_nid;
2638 struct hda_input_mux *imux = &spec->private_imux[0];
2640 int i, c, err, idx, type_idx = 0;
2641 const char *prev_label = NULL;
2643 num_adcs = alc_auto_fill_adc_caps(codec);
2647 for (i = 0; i < cfg->num_inputs; i++) {
2651 pin = cfg->inputs[i].pin;
2652 if (!alc_is_input_pin(codec, pin))
2655 label = hda_get_autocfg_input_label(codec, cfg, i);
2656 if (prev_label && !strcmp(label, prev_label))
2663 idx = get_connection_index(codec, mixer, pin);
2665 err = new_analog_input(spec, pin,
2673 for (c = 0; c < num_adcs; c++) {
2674 hda_nid_t cap = spec->capsrc_nids ?
2675 spec->capsrc_nids[c] : spec->adc_nids[c];
2676 idx = get_connection_index(codec, cap, pin);
2678 spec->imux_pins[imux->num_items] = pin;
2679 snd_hda_add_imux_item(imux, label, idx, NULL);
2685 spec->num_mux_defs = 1;
2686 spec->input_mux = imux;
2691 static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
2692 unsigned int pin_type)
2694 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2697 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2698 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2702 static int get_pin_type(int line_out_type)
2704 if (line_out_type == AUTO_PIN_HP_OUT)
2710 static void alc_auto_init_analog_input(struct hda_codec *codec)
2712 struct alc_spec *spec = codec->spec;
2713 struct auto_pin_cfg *cfg = &spec->autocfg;
2716 for (i = 0; i < cfg->num_inputs; i++) {
2717 hda_nid_t nid = cfg->inputs[i].pin;
2718 if (alc_is_input_pin(codec, nid)) {
2719 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
2720 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
2721 snd_hda_codec_write(codec, nid, 0,
2722 AC_VERB_SET_AMP_GAIN_MUTE,
2727 /* mute all loopback inputs */
2728 if (spec->mixer_nid) {
2729 int nums = snd_hda_get_conn_list(codec, spec->mixer_nid, NULL);
2730 for (i = 0; i < nums; i++)
2731 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2732 AC_VERB_SET_AMP_GAIN_MUTE,
2737 /* convert from MIX nid to DAC */
2738 static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid)
2743 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT)
2745 num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list));
2746 for (i = 0; i < num; i++) {
2747 if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT)
2753 /* go down to the selector widget before the mixer */
2754 static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin)
2757 int num = snd_hda_get_connections(codec, pin, srcs,
2760 get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL)
2765 /* get MIX nid connected to the given pin targeted to DAC */
2766 static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
2772 pin = alc_go_down_to_selector(codec, pin);
2773 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2774 for (i = 0; i < num; i++) {
2775 if (alc_auto_mix_to_dac(codec, mix[i]) == dac)
2781 /* select the connection from pin to DAC if needed */
2782 static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin,
2788 pin = alc_go_down_to_selector(codec, pin);
2789 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2792 for (i = 0; i < num; i++) {
2793 if (alc_auto_mix_to_dac(codec, mix[i]) == dac) {
2794 snd_hda_codec_update_cache(codec, pin, 0,
2795 AC_VERB_SET_CONNECT_SEL, i);
2802 /* look for an empty DAC slot */
2803 static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
2805 struct alc_spec *spec = codec->spec;
2809 pin = alc_go_down_to_selector(codec, pin);
2810 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
2811 for (i = 0; i < num; i++) {
2812 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
2815 if (found_in_nid_list(nid, spec->multiout.dac_nids,
2816 spec->multiout.num_dacs))
2818 if (found_in_nid_list(nid, spec->multiout.hp_out_nid,
2819 ARRAY_SIZE(spec->multiout.hp_out_nid)))
2821 if (found_in_nid_list(nid, spec->multiout.extra_out_nid,
2822 ARRAY_SIZE(spec->multiout.extra_out_nid)))
2829 static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
2831 hda_nid_t sel = alc_go_down_to_selector(codec, pin);
2832 if (snd_hda_get_conn_list(codec, sel, NULL) == 1)
2833 return alc_auto_look_for_dac(codec, pin);
2837 static int alc_auto_fill_extra_dacs(struct hda_codec *codec, int num_outs,
2838 const hda_nid_t *pins, hda_nid_t *dacs)
2842 if (num_outs && !dacs[0]) {
2843 dacs[0] = alc_auto_look_for_dac(codec, pins[0]);
2848 for (i = 1; i < num_outs; i++)
2849 dacs[i] = get_dac_if_single(codec, pins[i]);
2850 for (i = 1; i < num_outs; i++) {
2852 dacs[i] = alc_auto_look_for_dac(codec, pins[i]);
2857 static int alc_auto_fill_multi_ios(struct hda_codec *codec,
2858 unsigned int location);
2860 /* fill in the dac_nids table from the parsed pin configuration */
2861 static int alc_auto_fill_dac_nids(struct hda_codec *codec)
2863 struct alc_spec *spec = codec->spec;
2864 const struct auto_pin_cfg *cfg = &spec->autocfg;
2865 bool redone = false;
2869 /* set num_dacs once to full for alc_auto_look_for_dac() */
2870 spec->multiout.num_dacs = cfg->line_outs;
2871 spec->multiout.hp_out_nid[0] = 0;
2872 spec->multiout.extra_out_nid[0] = 0;
2873 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
2874 spec->multiout.dac_nids = spec->private_dac_nids;
2876 /* fill hard-wired DACs first */
2878 for (i = 0; i < cfg->line_outs; i++)
2879 spec->private_dac_nids[i] =
2880 get_dac_if_single(codec, cfg->line_out_pins[i]);
2882 spec->multiout.hp_out_nid[0] =
2883 get_dac_if_single(codec, cfg->hp_pins[0]);
2884 if (cfg->speaker_outs)
2885 spec->multiout.extra_out_nid[0] =
2886 get_dac_if_single(codec, cfg->speaker_pins[0]);
2889 for (i = 0; i < cfg->line_outs; i++) {
2890 hda_nid_t pin = cfg->line_out_pins[i];
2891 if (spec->private_dac_nids[i])
2893 spec->private_dac_nids[i] = alc_auto_look_for_dac(codec, pin);
2894 if (!spec->private_dac_nids[i] && !redone) {
2895 /* if we can't find primary DACs, re-probe without
2896 * checking the hard-wired DACs
2903 /* re-count num_dacs and squash invalid entries */
2904 spec->multiout.num_dacs = 0;
2905 for (i = 0; i < cfg->line_outs; i++) {
2906 if (spec->private_dac_nids[i])
2907 spec->multiout.num_dacs++;
2909 memmove(spec->private_dac_nids + i,
2910 spec->private_dac_nids + i + 1,
2911 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
2914 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
2915 /* try to fill multi-io first */
2916 unsigned int location, defcfg;
2919 defcfg = snd_hda_codec_get_pincfg(codec, cfg->line_out_pins[0]);
2920 location = get_defcfg_location(defcfg);
2922 num_pins = alc_auto_fill_multi_ios(codec, location);
2924 spec->multi_ios = num_pins;
2925 spec->ext_channel_count = 2;
2926 spec->multiout.num_dacs = num_pins + 1;
2930 alc_auto_fill_extra_dacs(codec, cfg->hp_outs, cfg->hp_pins,
2931 spec->multiout.hp_out_nid);
2932 alc_auto_fill_extra_dacs(codec, cfg->speaker_outs, cfg->speaker_pins,
2933 spec->multiout.extra_out_nid);
2938 static int alc_auto_add_vol_ctl(struct hda_codec *codec,
2939 const char *pfx, int cidx,
2940 hda_nid_t nid, unsigned int chs)
2944 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
2945 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
2948 #define alc_auto_add_stereo_vol(codec, pfx, cidx, nid) \
2949 alc_auto_add_vol_ctl(codec, pfx, cidx, nid, 3)
2951 /* create a mute-switch for the given mixer widget;
2952 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
2954 static int alc_auto_add_sw_ctl(struct hda_codec *codec,
2955 const char *pfx, int cidx,
2956 hda_nid_t nid, unsigned int chs)
2963 wid_type = get_wcaps_type(get_wcaps(codec, nid));
2964 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) {
2965 type = ALC_CTL_WIDGET_MUTE;
2966 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
2967 } else if (snd_hda_get_conn_list(codec, nid, NULL) == 1) {
2968 type = ALC_CTL_WIDGET_MUTE;
2969 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
2971 type = ALC_CTL_BIND_MUTE;
2972 val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
2974 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
2977 #define alc_auto_add_stereo_sw(codec, pfx, cidx, nid) \
2978 alc_auto_add_sw_ctl(codec, pfx, cidx, nid, 3)
2980 static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
2981 hda_nid_t pin, hda_nid_t dac)
2983 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
2984 if (nid_has_mute(codec, pin, HDA_OUTPUT))
2986 else if (mix && nid_has_mute(codec, mix, HDA_INPUT))
2988 else if (nid_has_mute(codec, dac, HDA_OUTPUT))
2993 static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
2994 hda_nid_t pin, hda_nid_t dac)
2996 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
2997 if (nid_has_volume(codec, dac, HDA_OUTPUT))
2999 else if (nid_has_volume(codec, mix, HDA_OUTPUT))
3001 else if (nid_has_volume(codec, pin, HDA_OUTPUT))
3006 /* add playback controls from the parsed DAC table */
3007 static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
3008 const struct auto_pin_cfg *cfg)
3010 struct alc_spec *spec = codec->spec;
3011 int i, err, noutputs;
3013 noutputs = cfg->line_outs;
3014 if (spec->multi_ios > 0)
3015 noutputs += spec->multi_ios;
3017 for (i = 0; i < noutputs; i++) {
3023 dac = spec->multiout.dac_nids[i];
3026 if (i >= cfg->line_outs)
3027 pin = spec->multi_io[i - 1].pin;
3029 pin = cfg->line_out_pins[i];
3031 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3032 vol = alc_look_for_out_vol_nid(codec, pin, dac);
3033 name = alc_get_line_out_pfx(spec, i, true, &index);
3034 if (!name || !strcmp(name, "CLFE")) {
3036 err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1);
3039 err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2);
3042 err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1);
3045 err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2);
3049 err = alc_auto_add_stereo_vol(codec, name, index, vol);
3052 err = alc_auto_add_stereo_sw(codec, name, index, sw);
3060 static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
3061 hda_nid_t dac, const char *pfx)
3063 struct alc_spec *spec = codec->spec;
3068 /* the corresponding DAC is already occupied */
3069 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
3070 return 0; /* no way */
3071 /* create a switch only */
3072 return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx,
3073 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3076 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3077 vol = alc_look_for_out_vol_nid(codec, pin, dac);
3078 err = alc_auto_add_stereo_vol(codec, pfx, 0, vol);
3081 err = alc_auto_add_stereo_sw(codec, pfx, 0, sw);
3087 static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3089 struct hda_ctl_ops *ops)
3091 struct alc_spec *spec = codec->spec;
3092 struct hda_bind_ctls **ctlp, *ctl;
3093 snd_array_init(&spec->bind_ctls, sizeof(ctl), 8);
3094 ctlp = snd_array_new(&spec->bind_ctls);
3097 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3104 /* add playback controls for speaker and HP outputs */
3105 static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3106 const hda_nid_t *pins,
3107 const hda_nid_t *dacs,
3110 struct alc_spec *spec = codec->spec;
3111 struct hda_bind_ctls *ctl;
3115 if (!num_pins || !pins[0])
3119 return alc_auto_create_extra_out(codec, *pins, *dacs, pfx);
3121 if (dacs[num_pins - 1]) {
3122 /* OK, we have a multi-output system with individual volumes */
3123 for (i = 0; i < num_pins; i++) {
3124 snprintf(name, sizeof(name), "%s %s",
3125 pfx, channel_name[i]);
3126 err = alc_auto_create_extra_out(codec, pins[i], dacs[i],
3134 /* Let's create a bind-controls */
3135 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_sw);
3139 for (i = 0; i < num_pins; i++) {
3140 if (get_wcaps(codec, pins[i]) & AC_WCAP_OUT_AMP)
3142 HDA_COMPOSE_AMP_VAL(pins[i], 3, 0, HDA_OUTPUT);
3145 snprintf(name, sizeof(name), "%s Playback Switch", pfx);
3146 err = add_control(spec, ALC_CTL_BIND_SW, name, 0, (long)ctl);
3151 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3155 for (i = 0; i < num_pins; i++) {
3157 if (!pins[i] || !dacs[i])
3159 vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]);
3162 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3165 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3166 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3173 static int alc_auto_create_hp_out(struct hda_codec *codec)
3175 struct alc_spec *spec = codec->spec;
3176 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3177 spec->autocfg.hp_pins,
3178 spec->multiout.hp_out_nid,
3182 static int alc_auto_create_speaker_out(struct hda_codec *codec)
3184 struct alc_spec *spec = codec->spec;
3185 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3186 spec->autocfg.speaker_pins,
3187 spec->multiout.extra_out_nid,
3191 static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
3192 hda_nid_t pin, int pin_type,
3196 hda_nid_t nid, mix = 0;
3197 hda_nid_t srcs[HDA_MAX_CONNECTIONS];
3199 alc_set_pin_output(codec, pin, pin_type);
3200 nid = alc_go_down_to_selector(codec, pin);
3201 num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
3202 for (i = 0; i < num; i++) {
3203 if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
3211 /* need the manual connection? */
3213 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
3214 /* unmute mixer widget inputs */
3215 if (nid_has_mute(codec, mix, HDA_INPUT)) {
3216 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3218 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3221 /* initialize volume */
3222 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3224 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3228 static void alc_auto_init_multi_out(struct hda_codec *codec)
3230 struct alc_spec *spec = codec->spec;
3231 int pin_type = get_pin_type(spec->autocfg.line_out_type);
3234 for (i = 0; i <= HDA_SIDE; i++) {
3235 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3237 alc_auto_set_output_and_unmute(codec, nid, pin_type,
3238 spec->multiout.dac_nids[i]);
3242 static void alc_auto_init_extra_out(struct hda_codec *codec)
3244 struct alc_spec *spec = codec->spec;
3248 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3249 pin = spec->autocfg.hp_pins[i];
3252 dac = spec->multiout.hp_out_nid[i];
3254 if (i > 0 && spec->multiout.hp_out_nid[0])
3255 dac = spec->multiout.hp_out_nid[0];
3257 dac = spec->multiout.dac_nids[0];
3259 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
3261 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3262 pin = spec->autocfg.speaker_pins[i];
3265 dac = spec->multiout.extra_out_nid[i];
3267 if (i > 0 && spec->multiout.extra_out_nid[0])
3268 dac = spec->multiout.extra_out_nid[0];
3270 dac = spec->multiout.dac_nids[0];
3272 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
3279 static int alc_auto_fill_multi_ios(struct hda_codec *codec,
3280 unsigned int location)
3282 struct alc_spec *spec = codec->spec;
3283 struct auto_pin_cfg *cfg = &spec->autocfg;
3284 hda_nid_t prime_dac = spec->private_dac_nids[0];
3285 int type, i, num_pins = 0;
3287 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3288 for (i = 0; i < cfg->num_inputs; i++) {
3289 hda_nid_t nid = cfg->inputs[i].pin;
3291 unsigned int defcfg, caps;
3292 if (cfg->inputs[i].type != type)
3294 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3295 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3297 if (location && get_defcfg_location(defcfg) != location)
3299 caps = snd_hda_query_pin_caps(codec, nid);
3300 if (!(caps & AC_PINCAP_OUT))
3302 dac = alc_auto_look_for_dac(codec, nid);
3305 spec->multi_io[num_pins].pin = nid;
3306 spec->multi_io[num_pins].dac = dac;
3308 spec->private_dac_nids[spec->multiout.num_dacs++] = dac;
3311 spec->multiout.num_dacs = 1;
3313 /* clear up again */
3314 memset(spec->private_dac_nids, 0,
3315 sizeof(spec->private_dac_nids));
3316 spec->private_dac_nids[0] = prime_dac;
3322 static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
3323 struct snd_ctl_elem_info *uinfo)
3325 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3326 struct alc_spec *spec = codec->spec;
3328 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3330 uinfo->value.enumerated.items = spec->multi_ios + 1;
3331 if (uinfo->value.enumerated.item > spec->multi_ios)
3332 uinfo->value.enumerated.item = spec->multi_ios;
3333 sprintf(uinfo->value.enumerated.name, "%dch",
3334 (uinfo->value.enumerated.item + 1) * 2);
3338 static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
3339 struct snd_ctl_elem_value *ucontrol)
3341 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3342 struct alc_spec *spec = codec->spec;
3343 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
3347 static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
3349 struct alc_spec *spec = codec->spec;
3350 hda_nid_t nid = spec->multi_io[idx].pin;
3352 if (!spec->multi_io[idx].ctl_in)
3353 spec->multi_io[idx].ctl_in =
3354 snd_hda_codec_read(codec, nid, 0,
3355 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3357 snd_hda_codec_update_cache(codec, nid, 0,
3358 AC_VERB_SET_PIN_WIDGET_CONTROL,
3360 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3361 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3363 alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
3365 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3366 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3367 HDA_AMP_MUTE, HDA_AMP_MUTE);
3368 snd_hda_codec_update_cache(codec, nid, 0,
3369 AC_VERB_SET_PIN_WIDGET_CONTROL,
3370 spec->multi_io[idx].ctl_in);
3375 static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
3376 struct snd_ctl_elem_value *ucontrol)
3378 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3379 struct alc_spec *spec = codec->spec;
3382 ch = ucontrol->value.enumerated.item[0];
3383 if (ch < 0 || ch > spec->multi_ios)
3385 if (ch == (spec->ext_channel_count - 1) / 2)
3387 spec->ext_channel_count = (ch + 1) * 2;
3388 for (i = 0; i < spec->multi_ios; i++)
3389 alc_set_multi_io(codec, i, i < ch);
3390 spec->multiout.max_channels = spec->ext_channel_count;
3391 if (spec->need_dac_fix && !spec->const_channel_count)
3392 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
3396 static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
3397 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3398 .name = "Channel Mode",
3399 .info = alc_auto_ch_mode_info,
3400 .get = alc_auto_ch_mode_get,
3401 .put = alc_auto_ch_mode_put,
3404 static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
3406 struct alc_spec *spec = codec->spec;
3408 if (spec->multi_ios > 0) {
3409 struct snd_kcontrol_new *knew;
3411 knew = alc_kcontrol_new(spec);
3414 *knew = alc_auto_channel_mode_enum;
3415 knew->name = kstrdup("Channel Mode", GFP_KERNEL);
3422 /* filter out invalid adc_nids (and capsrc_nids) that don't give all
3425 static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
3427 struct alc_spec *spec = codec->spec;
3428 const struct hda_input_mux *imux;
3429 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3430 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3433 imux = spec->input_mux;
3436 if (spec->dyn_adc_switch)
3440 for (n = 0; n < spec->num_adc_nids; n++) {
3441 hda_nid_t cap = spec->private_capsrc_nids[n];
3442 int num_conns = snd_hda_get_conn_list(codec, cap, NULL);
3443 for (i = 0; i < imux->num_items; i++) {
3444 hda_nid_t pin = spec->imux_pins[i];
3446 if (get_connection_index(codec, cap, pin) < 0)
3448 } else if (num_conns <= imux->items[i].index)
3451 if (i >= imux->num_items) {
3452 adc_nids[nums] = spec->private_adc_nids[n];
3453 capsrc_nids[nums++] = cap;
3457 /* check whether ADC-switch is possible */
3458 if (!alc_check_dyn_adc_switch(codec)) {
3459 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
3460 " using fallback 0x%x\n",
3461 codec->chip_name, spec->private_adc_nids[0]);
3462 spec->num_adc_nids = 1;
3466 } else if (nums != spec->num_adc_nids) {
3467 memcpy(spec->private_adc_nids, adc_nids,
3468 nums * sizeof(hda_nid_t));
3469 memcpy(spec->private_capsrc_nids, capsrc_nids,
3470 nums * sizeof(hda_nid_t));
3471 spec->num_adc_nids = nums;
3475 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
3476 else if (spec->input_mux->num_items == 1)
3477 spec->num_adc_nids = 1; /* reduce to a single ADC */
3481 * initialize ADC paths
3483 static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
3485 struct alc_spec *spec = codec->spec;
3488 nid = spec->adc_nids[adc_idx];
3490 if (nid_has_mute(codec, nid, HDA_INPUT)) {
3491 snd_hda_codec_write(codec, nid, 0,
3492 AC_VERB_SET_AMP_GAIN_MUTE,
3496 if (!spec->capsrc_nids)
3498 nid = spec->capsrc_nids[adc_idx];
3499 if (nid_has_mute(codec, nid, HDA_OUTPUT))
3500 snd_hda_codec_write(codec, nid, 0,
3501 AC_VERB_SET_AMP_GAIN_MUTE,
3505 static void alc_auto_init_input_src(struct hda_codec *codec)
3507 struct alc_spec *spec = codec->spec;
3510 for (c = 0; c < spec->num_adc_nids; c++)
3511 alc_auto_init_adc(codec, c);
3512 if (spec->dyn_adc_switch)
3515 nums = spec->num_adc_nids;
3516 for (c = 0; c < nums; c++)
3517 alc_mux_select(codec, 0, spec->cur_mux[c], true);
3520 /* add mic boosts if needed */
3521 static int alc_auto_add_mic_boost(struct hda_codec *codec)
3523 struct alc_spec *spec = codec->spec;
3524 struct auto_pin_cfg *cfg = &spec->autocfg;
3528 const char *prev_label = NULL;
3530 for (i = 0; i < cfg->num_inputs; i++) {
3531 if (cfg->inputs[i].type > AUTO_PIN_MIC)
3533 nid = cfg->inputs[i].pin;
3534 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
3536 char boost_label[32];
3538 label = hda_get_autocfg_input_label(codec, cfg, i);
3539 if (prev_label && !strcmp(label, prev_label))
3545 snprintf(boost_label, sizeof(boost_label),
3546 "%s Boost Volume", label);
3547 err = add_control(spec, ALC_CTL_WIDGET_VOL,
3548 boost_label, type_idx,
3549 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
3557 /* select or unmute the given capsrc route */
3558 static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
3561 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
3562 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
3564 } else if (snd_hda_get_conn_list(codec, cap, NULL) > 1) {
3565 snd_hda_codec_write_cache(codec, cap, 0,
3566 AC_VERB_SET_CONNECT_SEL, idx);
3570 /* set the default connection to that pin */
3571 static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
3573 struct alc_spec *spec = codec->spec;
3578 for (i = 0; i < spec->num_adc_nids; i++) {
3579 hda_nid_t cap = spec->capsrc_nids ?
3580 spec->capsrc_nids[i] : spec->adc_nids[i];
3583 idx = get_connection_index(codec, cap, pin);
3586 select_or_unmute_capsrc(codec, cap, idx);
3587 return i; /* return the found index */
3589 return -1; /* not found */
3592 /* initialize some special cases for input sources */
3593 static void alc_init_special_input_src(struct hda_codec *codec)
3595 struct alc_spec *spec = codec->spec;
3598 for (i = 0; i < spec->autocfg.num_inputs; i++)
3599 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
3602 /* assign appropriate capture mixers */
3603 static void set_capture_mixer(struct hda_codec *codec)
3605 struct alc_spec *spec = codec->spec;
3606 static const struct snd_kcontrol_new *caps[2][3] = {
3607 { alc_capture_mixer_nosrc1,
3608 alc_capture_mixer_nosrc2,
3609 alc_capture_mixer_nosrc3 },
3610 { alc_capture_mixer1,
3612 alc_capture_mixer3 },
3615 /* check whether either of ADC or MUX has a volume control */
3616 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
3617 if (!spec->capsrc_nids)
3618 return; /* no volume */
3619 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
3620 return; /* no volume in capsrc, too */
3621 spec->vol_in_capsrc = 1;
3624 if (spec->num_adc_nids > 0) {
3628 if (spec->input_mux && spec->input_mux->num_items > 1)
3630 if (spec->auto_mic) {
3633 } else if (spec->dyn_adc_switch)
3636 if (spec->num_adc_nids > 3)
3637 spec->num_adc_nids = 3;
3638 else if (!spec->num_adc_nids)
3640 num_adcs = spec->num_adc_nids;
3642 spec->cap_mixer = caps[mux][num_adcs - 1];
3647 * standard auto-parser initializations
3649 static void alc_auto_init_std(struct hda_codec *codec)
3651 struct alc_spec *spec = codec->spec;
3652 alc_auto_init_multi_out(codec);
3653 alc_auto_init_extra_out(codec);
3654 alc_auto_init_analog_input(codec);
3655 alc_auto_init_input_src(codec);
3656 alc_auto_init_digital(codec);
3657 if (spec->unsol_event)
3658 alc_inithook(codec);
3662 * Digital-beep handlers
3664 #ifdef CONFIG_SND_HDA_INPUT_BEEP
3665 #define set_beep_amp(spec, nid, idx, dir) \
3666 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
3668 static const struct snd_pci_quirk beep_white_list[] = {
3669 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
3670 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
3671 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
3672 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
3673 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
3677 static inline int has_cdefine_beep(struct hda_codec *codec)
3679 struct alc_spec *spec = codec->spec;
3680 const struct snd_pci_quirk *q;
3681 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
3684 return spec->cdefine.enable_pcbeep;
3687 #define set_beep_amp(spec, nid, idx, dir) /* NOP */
3688 #define has_cdefine_beep(codec) 0
3691 /* parse the BIOS configuration and set up the alc_spec */
3692 /* return 1 if successful, 0 if the proper config is not found,
3693 * or a negative error code
3695 static int alc_parse_auto_config(struct hda_codec *codec,
3696 const hda_nid_t *ignore_nids,
3697 const hda_nid_t *ssid_nids)
3699 struct alc_spec *spec = codec->spec;
3700 struct auto_pin_cfg *cfg = &spec->autocfg;
3703 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
3707 if (!cfg->line_outs) {
3708 if (cfg->dig_outs || cfg->dig_in_pin) {
3709 spec->multiout.max_channels = 2;
3710 spec->no_analog = 1;
3713 return 0; /* can't find valid BIOS pin config */
3716 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT && cfg->hp_outs > 0) {
3717 /* use HP as primary out */
3718 cfg->speaker_outs = cfg->line_outs;
3719 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3720 sizeof(cfg->speaker_pins));
3721 cfg->line_outs = cfg->hp_outs;
3722 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
3724 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3725 cfg->line_out_type = AUTO_PIN_HP_OUT;
3728 err = alc_auto_fill_dac_nids(codec);
3731 err = alc_auto_add_multi_channel_mode(codec);
3734 err = alc_auto_create_multi_out_ctls(codec, cfg);
3737 err = alc_auto_create_hp_out(codec);
3740 err = alc_auto_create_speaker_out(codec);
3743 err = alc_auto_create_input_ctls(codec);
3747 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3750 alc_auto_parse_digital(codec);
3752 if (!spec->no_analog)
3753 alc_remove_invalid_adc_nids(codec);
3756 alc_ssid_check(codec, ssid_nids);
3758 if (!spec->no_analog) {
3759 alc_auto_check_switches(codec);
3760 err = alc_auto_add_mic_boost(codec);
3765 if (spec->kctls.list)
3766 add_mixer(spec, spec->kctls.list);
3771 static int alc880_parse_auto_config(struct hda_codec *codec)
3773 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
3774 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
3775 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
3778 #ifdef CONFIG_SND_HDA_POWER_SAVE
3779 static const struct hda_amp_list alc880_loopbacks[] = {
3780 { 0x0b, HDA_INPUT, 0 },
3781 { 0x0b, HDA_INPUT, 1 },
3782 { 0x0b, HDA_INPUT, 2 },
3783 { 0x0b, HDA_INPUT, 3 },
3784 { 0x0b, HDA_INPUT, 4 },
3792 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3793 #define alc_board_config \
3794 snd_hda_check_board_config
3795 #define alc_board_codec_sid_config \
3796 snd_hda_check_board_codec_sid_config
3797 #include "alc_quirks.c"
3799 #define alc_board_config(codec, nums, models, tbl) -1
3800 #define alc_board_codec_sid_config(codec, nums, models, tbl) -1
3801 #define setup_preset(codec, x) /* NOP */
3805 * OK, here we have finally the patch for ALC880
3807 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3808 #include "alc880_quirks.c"
3811 static int patch_alc880(struct hda_codec *codec)
3813 struct alc_spec *spec;
3817 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3823 spec->mixer_nid = 0x0b;
3824 spec->need_dac_fix = 1;
3826 board_config = alc_board_config(codec, ALC880_MODEL_LAST,
3827 alc880_models, alc880_cfg_tbl);
3828 if (board_config < 0) {
3829 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
3831 board_config = ALC_MODEL_AUTO;
3834 if (board_config == ALC_MODEL_AUTO) {
3835 /* automatic parse from the BIOS config */
3836 err = alc880_parse_auto_config(codec);
3841 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3844 "hda_codec: Cannot set up configuration "
3845 "from BIOS. Using 3-stack mode...\n");
3846 board_config = ALC880_3ST;
3851 if (board_config != ALC_MODEL_AUTO)
3852 setup_preset(codec, &alc880_presets[board_config]);
3854 if (!spec->no_analog && !spec->adc_nids) {
3855 alc_auto_fill_adc_caps(codec);
3856 alc_rebuild_imux_for_auto_mic(codec);
3857 alc_remove_invalid_adc_nids(codec);
3860 if (!spec->no_analog && !spec->cap_mixer)
3861 set_capture_mixer(codec);
3863 if (!spec->no_analog) {
3864 err = snd_hda_attach_beep_device(codec, 0x1);
3869 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
3872 spec->vmaster_nid = 0x0c;
3874 codec->patch_ops = alc_patch_ops;
3875 if (board_config == ALC_MODEL_AUTO)
3876 spec->init_hook = alc_auto_init_std;
3877 #ifdef CONFIG_SND_HDA_POWER_SAVE
3878 if (!spec->loopback.amplist)
3879 spec->loopback.amplist = alc880_loopbacks;
3889 static int alc260_parse_auto_config(struct hda_codec *codec)
3891 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
3892 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
3893 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
3896 #ifdef CONFIG_SND_HDA_POWER_SAVE
3897 static const struct hda_amp_list alc260_loopbacks[] = {
3898 { 0x07, HDA_INPUT, 0 },
3899 { 0x07, HDA_INPUT, 1 },
3900 { 0x07, HDA_INPUT, 2 },
3901 { 0x07, HDA_INPUT, 3 },
3902 { 0x07, HDA_INPUT, 4 },
3914 static const struct alc_fixup alc260_fixups[] = {
3915 [PINFIX_HP_DC5750] = {
3916 .type = ALC_FIXUP_PINS,
3917 .v.pins = (const struct alc_pincfg[]) {
3918 { 0x11, 0x90130110 }, /* speaker */
3924 static const struct snd_pci_quirk alc260_fixup_tbl[] = {
3925 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", PINFIX_HP_DC5750),
3931 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3932 #include "alc260_quirks.c"
3935 static int patch_alc260(struct hda_codec *codec)
3937 struct alc_spec *spec;
3938 int err, board_config;
3940 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3946 spec->mixer_nid = 0x07;
3948 board_config = alc_board_config(codec, ALC260_MODEL_LAST,
3949 alc260_models, alc260_cfg_tbl);
3950 if (board_config < 0) {
3951 snd_printd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
3953 board_config = ALC_MODEL_AUTO;
3956 if (board_config == ALC_MODEL_AUTO) {
3957 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
3958 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
3961 if (board_config == ALC_MODEL_AUTO) {
3962 /* automatic parse from the BIOS config */
3963 err = alc260_parse_auto_config(codec);
3968 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3971 "hda_codec: Cannot set up configuration "
3972 "from BIOS. Using base mode...\n");
3973 board_config = ALC260_BASIC;
3978 if (board_config != ALC_MODEL_AUTO)
3979 setup_preset(codec, &alc260_presets[board_config]);
3981 if (!spec->no_analog && !spec->adc_nids) {
3982 alc_auto_fill_adc_caps(codec);
3983 alc_rebuild_imux_for_auto_mic(codec);
3984 alc_remove_invalid_adc_nids(codec);
3987 if (!spec->no_analog && !spec->cap_mixer)
3988 set_capture_mixer(codec);
3990 if (!spec->no_analog) {
3991 err = snd_hda_attach_beep_device(codec, 0x1);
3996 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
3999 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4001 spec->vmaster_nid = 0x08;
4003 codec->patch_ops = alc_patch_ops;
4004 if (board_config == ALC_MODEL_AUTO)
4005 spec->init_hook = alc_auto_init_std;
4006 spec->shutup = alc_eapd_shutup;
4007 #ifdef CONFIG_SND_HDA_POWER_SAVE
4008 if (!spec->loopback.amplist)
4009 spec->loopback.amplist = alc260_loopbacks;
4017 * ALC882/883/885/888/889 support
4019 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
4020 * configuration. Each pin widget can choose any input DACs and a mixer.
4021 * Each ADC is connected from a mixer of all inputs. This makes possible
4022 * 6-channel independent captures.
4024 * In addition, an independent DAC for the multi-playback (not used in this
4027 #ifdef CONFIG_SND_HDA_POWER_SAVE
4028 #define alc882_loopbacks alc880_loopbacks
4035 PINFIX_ABIT_AW9D_MAX,
4038 PINFIX_ACER_ASPIRE_7736,
4041 static const struct alc_fixup alc882_fixups[] = {
4042 [PINFIX_ABIT_AW9D_MAX] = {
4043 .type = ALC_FIXUP_PINS,
4044 .v.pins = (const struct alc_pincfg[]) {
4045 { 0x15, 0x01080104 }, /* side */
4046 { 0x16, 0x01011012 }, /* rear */
4047 { 0x17, 0x01016011 }, /* clfe */
4051 [PINFIX_LENOVO_Y530] = {
4052 .type = ALC_FIXUP_PINS,
4053 .v.pins = (const struct alc_pincfg[]) {
4054 { 0x15, 0x99130112 }, /* rear int speakers */
4055 { 0x16, 0x99130111 }, /* subwoofer */
4059 [PINFIX_PB_M5210] = {
4060 .type = ALC_FIXUP_VERBS,
4061 .v.verbs = (const struct hda_verb[]) {
4062 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
4066 [PINFIX_ACER_ASPIRE_7736] = {
4067 .type = ALC_FIXUP_SKU,
4068 .v.sku = ALC_FIXUP_SKU_IGNORE,
4072 static const struct snd_pci_quirk alc882_fixup_tbl[] = {
4073 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", PINFIX_PB_M5210),
4074 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", PINFIX_LENOVO_Y530),
4075 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
4076 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", PINFIX_ACER_ASPIRE_7736),
4081 * BIOS auto configuration
4083 /* almost identical with ALC880 parser... */
4084 static int alc882_parse_auto_config(struct hda_codec *codec)
4086 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
4087 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4088 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
4093 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4094 #include "alc882_quirks.c"
4097 static int patch_alc882(struct hda_codec *codec)
4099 struct alc_spec *spec;
4100 int err, board_config;
4102 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4108 spec->mixer_nid = 0x0b;
4110 switch (codec->vendor_id) {
4115 /* ALC883 and variants */
4116 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
4120 board_config = alc_board_config(codec, ALC882_MODEL_LAST,
4121 alc882_models, alc882_cfg_tbl);
4123 if (board_config < 0)
4124 board_config = alc_board_codec_sid_config(codec,
4125 ALC882_MODEL_LAST, alc882_models, alc882_ssid_cfg_tbl);
4127 if (board_config < 0) {
4128 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4130 board_config = ALC_MODEL_AUTO;
4133 if (board_config == ALC_MODEL_AUTO) {
4134 alc_pick_fixup(codec, NULL, alc882_fixup_tbl, alc882_fixups);
4135 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4138 alc_auto_parse_customize_define(codec);
4140 if (board_config == ALC_MODEL_AUTO) {
4141 /* automatic parse from the BIOS config */
4142 err = alc882_parse_auto_config(codec);
4147 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4150 "hda_codec: Cannot set up configuration "
4151 "from BIOS. Using base mode...\n");
4152 board_config = ALC882_3ST_DIG;
4157 if (board_config != ALC_MODEL_AUTO)
4158 setup_preset(codec, &alc882_presets[board_config]);
4160 if (!spec->no_analog && !spec->adc_nids) {
4161 alc_auto_fill_adc_caps(codec);
4162 alc_rebuild_imux_for_auto_mic(codec);
4163 alc_remove_invalid_adc_nids(codec);
4166 if (!spec->no_analog && !spec->cap_mixer)
4167 set_capture_mixer(codec);
4169 if (!spec->no_analog && has_cdefine_beep(codec)) {
4170 err = snd_hda_attach_beep_device(codec, 0x1);
4175 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4178 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4180 spec->vmaster_nid = 0x0c;
4182 codec->patch_ops = alc_patch_ops;
4183 if (board_config == ALC_MODEL_AUTO)
4184 spec->init_hook = alc_auto_init_std;
4186 alc_init_jacks(codec);
4187 #ifdef CONFIG_SND_HDA_POWER_SAVE
4188 if (!spec->loopback.amplist)
4189 spec->loopback.amplist = alc882_loopbacks;
4199 static int alc262_parse_auto_config(struct hda_codec *codec)
4201 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
4202 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4203 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
4214 static const struct alc_fixup alc262_fixups[] = {
4215 [PINFIX_FSC_H270] = {
4216 .type = ALC_FIXUP_PINS,
4217 .v.pins = (const struct alc_pincfg[]) {
4218 { 0x14, 0x99130110 }, /* speaker */
4219 { 0x15, 0x0221142f }, /* front HP */
4220 { 0x1b, 0x0121141f }, /* rear HP */
4224 [PINFIX_HP_Z200] = {
4225 .type = ALC_FIXUP_PINS,
4226 .v.pins = (const struct alc_pincfg[]) {
4227 { 0x16, 0x99130120 }, /* internal speaker */
4233 static const struct snd_pci_quirk alc262_fixup_tbl[] = {
4234 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", PINFIX_HP_Z200),
4235 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", PINFIX_FSC_H270),
4240 #ifdef CONFIG_SND_HDA_POWER_SAVE
4241 #define alc262_loopbacks alc880_loopbacks
4246 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4247 #include "alc262_quirks.c"
4250 static int patch_alc262(struct hda_codec *codec)
4252 struct alc_spec *spec;
4256 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4262 spec->mixer_nid = 0x0b;
4265 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
4270 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4271 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
4272 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4273 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
4276 alc_auto_parse_customize_define(codec);
4278 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
4280 board_config = alc_board_config(codec, ALC262_MODEL_LAST,
4281 alc262_models, alc262_cfg_tbl);
4283 if (board_config < 0) {
4284 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4286 board_config = ALC_MODEL_AUTO;
4289 if (board_config == ALC_MODEL_AUTO) {
4290 alc_pick_fixup(codec, NULL, alc262_fixup_tbl, alc262_fixups);
4291 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4294 if (board_config == ALC_MODEL_AUTO) {
4295 /* automatic parse from the BIOS config */
4296 err = alc262_parse_auto_config(codec);
4301 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4304 "hda_codec: Cannot set up configuration "
4305 "from BIOS. Using base mode...\n");
4306 board_config = ALC262_BASIC;
4311 if (board_config != ALC_MODEL_AUTO)
4312 setup_preset(codec, &alc262_presets[board_config]);
4314 if (!spec->no_analog && !spec->adc_nids) {
4315 alc_auto_fill_adc_caps(codec);
4316 alc_rebuild_imux_for_auto_mic(codec);
4317 alc_remove_invalid_adc_nids(codec);
4320 if (!spec->no_analog && !spec->cap_mixer)
4321 set_capture_mixer(codec);
4323 if (!spec->no_analog && has_cdefine_beep(codec)) {
4324 err = snd_hda_attach_beep_device(codec, 0x1);
4329 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4332 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4334 spec->vmaster_nid = 0x0c;
4336 codec->patch_ops = alc_patch_ops;
4337 if (board_config == ALC_MODEL_AUTO)
4338 spec->init_hook = alc_auto_init_std;
4339 spec->shutup = alc_eapd_shutup;
4341 alc_init_jacks(codec);
4342 #ifdef CONFIG_SND_HDA_POWER_SAVE
4343 if (!spec->loopback.amplist)
4344 spec->loopback.amplist = alc262_loopbacks;
4353 /* bind Beep switches of both NID 0x0f and 0x10 */
4354 static const struct hda_bind_ctls alc268_bind_beep_sw = {
4355 .ops = &snd_hda_bind_sw,
4357 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
4358 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
4363 static const struct snd_kcontrol_new alc268_beep_mixer[] = {
4364 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
4365 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
4369 /* set PCBEEP vol = 0, mute connections */
4370 static const struct hda_verb alc268_beep_init_verbs[] = {
4371 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4372 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4373 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4378 * BIOS auto configuration
4380 static int alc268_parse_auto_config(struct hda_codec *codec)
4382 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4383 struct alc_spec *spec = codec->spec;
4384 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
4386 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
4387 add_mixer(spec, alc268_beep_mixer);
4388 add_verb(spec, alc268_beep_init_verbs);
4396 static int patch_alc268(struct hda_codec *codec)
4398 struct alc_spec *spec;
4399 int i, has_beep, err;
4401 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4407 /* ALC268 has no aa-loopback mixer */
4409 /* automatic parse from the BIOS config */
4410 err = alc268_parse_auto_config(codec);
4417 for (i = 0; i < spec->num_mixers; i++) {
4418 if (spec->mixers[i] == alc268_beep_mixer) {
4425 err = snd_hda_attach_beep_device(codec, 0x1);
4430 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
4431 /* override the amp caps for beep generator */
4432 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
4433 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
4434 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
4435 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4436 (0 << AC_AMPCAP_MUTE_SHIFT));
4439 if (!spec->no_analog && !spec->adc_nids) {
4440 alc_auto_fill_adc_caps(codec);
4441 alc_rebuild_imux_for_auto_mic(codec);
4442 alc_remove_invalid_adc_nids(codec);
4445 if (!spec->no_analog && !spec->cap_mixer)
4446 set_capture_mixer(codec);
4448 spec->vmaster_nid = 0x02;
4450 codec->patch_ops = alc_patch_ops;
4451 spec->init_hook = alc_auto_init_std;
4452 spec->shutup = alc_eapd_shutup;
4454 alc_init_jacks(codec);
4462 #ifdef CONFIG_SND_HDA_POWER_SAVE
4463 #define alc269_loopbacks alc880_loopbacks
4466 static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
4470 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
4471 /* NID is set in alc_build_pcms */
4473 .open = alc_playback_pcm_open,
4474 .prepare = alc_playback_pcm_prepare,
4475 .cleanup = alc_playback_pcm_cleanup
4479 static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
4483 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
4484 /* NID is set in alc_build_pcms */
4487 #ifdef CONFIG_SND_HDA_POWER_SAVE
4488 static int alc269_mic2_for_mute_led(struct hda_codec *codec)
4490 switch (codec->subsystem_id) {
4497 static int alc269_mic2_mute_check_ps(struct hda_codec *codec, hda_nid_t nid)
4499 /* update mute-LED according to the speaker mute state */
4500 if (nid == 0x01 || nid == 0x14) {
4502 if (snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0) &
4507 /* mic2 vref pin is used for mute LED control */
4508 snd_hda_codec_update_cache(codec, 0x19, 0,
4509 AC_VERB_SET_PIN_WIDGET_CONTROL,
4512 return alc_check_power_status(codec, nid);
4514 #endif /* CONFIG_SND_HDA_POWER_SAVE */
4516 /* different alc269-variants */
4518 ALC269_TYPE_ALC269VA,
4519 ALC269_TYPE_ALC269VB,
4520 ALC269_TYPE_ALC269VC,
4524 * BIOS auto configuration
4526 static int alc269_parse_auto_config(struct hda_codec *codec)
4528 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
4529 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
4530 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4531 struct alc_spec *spec = codec->spec;
4532 const hda_nid_t *ssids = spec->codec_variant == ALC269_TYPE_ALC269VA ?
4533 alc269va_ssids : alc269_ssids;
4535 return alc_parse_auto_config(codec, alc269_ignore, ssids);
4538 static void alc269_toggle_power_output(struct hda_codec *codec, int power_up)
4540 int val = alc_read_coef_idx(codec, 0x04);
4545 alc_write_coef_idx(codec, 0x04, val);
4548 static void alc269_shutup(struct hda_codec *codec)
4550 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x017)
4551 alc269_toggle_power_output(codec, 0);
4552 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x018) {
4553 alc269_toggle_power_output(codec, 0);
4559 static int alc269_resume(struct hda_codec *codec)
4561 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x018) {
4562 alc269_toggle_power_output(codec, 0);
4566 codec->patch_ops.init(codec);
4568 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x017) {
4569 alc269_toggle_power_output(codec, 1);
4573 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x018)
4574 alc269_toggle_power_output(codec, 1);
4576 snd_hda_codec_resume_amp(codec);
4577 snd_hda_codec_resume_cache(codec);
4578 hda_call_check_power_status(codec, 0x01);
4581 #endif /* CONFIG_PM */
4583 static void alc269_fixup_hweq(struct hda_codec *codec,
4584 const struct alc_fixup *fix, int action)
4588 if (action != ALC_FIXUP_ACT_INIT)
4590 coef = alc_read_coef_idx(codec, 0x1e);
4591 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
4594 static void alc271_fixup_dmic(struct hda_codec *codec,
4595 const struct alc_fixup *fix, int action)
4597 static const struct hda_verb verbs[] = {
4598 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
4599 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
4604 if (strcmp(codec->chip_name, "ALC271X"))
4606 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
4607 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
4608 snd_hda_sequence_write(codec, verbs);
4611 static void alc269_fixup_pcm_44k(struct hda_codec *codec,
4612 const struct alc_fixup *fix, int action)
4614 struct alc_spec *spec = codec->spec;
4616 if (action != ALC_FIXUP_ACT_PROBE)
4619 /* Due to a hardware problem on Lenovo Ideadpad, we need to
4620 * fix the sample rate of analog I/O to 44.1kHz
4622 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
4623 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
4626 static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
4627 const struct alc_fixup *fix, int action)
4631 if (action != ALC_FIXUP_ACT_INIT)
4633 /* The digital-mic unit sends PDM (differential signal) instead of
4634 * the standard PCM, thus you can't record a valid mono stream as is.
4635 * Below is a workaround specific to ALC269 to control the dmic
4636 * signal source as mono.
4638 coef = alc_read_coef_idx(codec, 0x07);
4639 alc_write_coef_idx(codec, 0x07, coef | 0x80);
4642 static void alc269_quanta_automute(struct hda_codec *codec)
4644 update_speakers(codec);
4646 snd_hda_codec_write(codec, 0x20, 0,
4647 AC_VERB_SET_COEF_INDEX, 0x0c);
4648 snd_hda_codec_write(codec, 0x20, 0,
4649 AC_VERB_SET_PROC_COEF, 0x680);
4651 snd_hda_codec_write(codec, 0x20, 0,
4652 AC_VERB_SET_COEF_INDEX, 0x0c);
4653 snd_hda_codec_write(codec, 0x20, 0,
4654 AC_VERB_SET_PROC_COEF, 0x480);
4657 static void alc269_fixup_quanta_mute(struct hda_codec *codec,
4658 const struct alc_fixup *fix, int action)
4660 struct alc_spec *spec = codec->spec;
4661 if (action != ALC_FIXUP_ACT_PROBE)
4663 spec->automute_hook = alc269_quanta_automute;
4667 ALC269_FIXUP_SONY_VAIO,
4668 ALC275_FIXUP_SONY_VAIO_GPIO2,
4669 ALC269_FIXUP_DELL_M101Z,
4670 ALC269_FIXUP_SKU_IGNORE,
4671 ALC269_FIXUP_ASUS_G73JW,
4672 ALC269_FIXUP_LENOVO_EAPD,
4673 ALC275_FIXUP_SONY_HWEQ,
4675 ALC269_FIXUP_PCM_44K,
4676 ALC269_FIXUP_STEREO_DMIC,
4677 ALC269_FIXUP_QUANTA_MUTE,
4678 ALC269_FIXUP_LIFEBOOK,
4681 ALC269VB_FIXUP_AMIC,
4682 ALC269VB_FIXUP_DMIC,
4685 static const struct alc_fixup alc269_fixups[] = {
4686 [ALC269_FIXUP_SONY_VAIO] = {
4687 .type = ALC_FIXUP_VERBS,
4688 .v.verbs = (const struct hda_verb[]) {
4689 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
4693 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
4694 .type = ALC_FIXUP_VERBS,
4695 .v.verbs = (const struct hda_verb[]) {
4696 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
4697 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
4698 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
4702 .chain_id = ALC269_FIXUP_SONY_VAIO
4704 [ALC269_FIXUP_DELL_M101Z] = {
4705 .type = ALC_FIXUP_VERBS,
4706 .v.verbs = (const struct hda_verb[]) {
4707 /* Enables internal speaker */
4708 {0x20, AC_VERB_SET_COEF_INDEX, 13},
4709 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
4713 [ALC269_FIXUP_SKU_IGNORE] = {
4714 .type = ALC_FIXUP_SKU,
4715 .v.sku = ALC_FIXUP_SKU_IGNORE,
4717 [ALC269_FIXUP_ASUS_G73JW] = {
4718 .type = ALC_FIXUP_PINS,
4719 .v.pins = (const struct alc_pincfg[]) {
4720 { 0x17, 0x99130111 }, /* subwoofer */
4724 [ALC269_FIXUP_LENOVO_EAPD] = {
4725 .type = ALC_FIXUP_VERBS,
4726 .v.verbs = (const struct hda_verb[]) {
4727 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
4731 [ALC275_FIXUP_SONY_HWEQ] = {
4732 .type = ALC_FIXUP_FUNC,
4733 .v.func = alc269_fixup_hweq,
4735 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
4737 [ALC271_FIXUP_DMIC] = {
4738 .type = ALC_FIXUP_FUNC,
4739 .v.func = alc271_fixup_dmic,
4741 [ALC269_FIXUP_PCM_44K] = {
4742 .type = ALC_FIXUP_FUNC,
4743 .v.func = alc269_fixup_pcm_44k,
4745 [ALC269_FIXUP_STEREO_DMIC] = {
4746 .type = ALC_FIXUP_FUNC,
4747 .v.func = alc269_fixup_stereo_dmic,
4749 [ALC269_FIXUP_QUANTA_MUTE] = {
4750 .type = ALC_FIXUP_FUNC,
4751 .v.func = alc269_fixup_quanta_mute,
4753 [ALC269_FIXUP_LIFEBOOK] = {
4754 .type = ALC_FIXUP_PINS,
4755 .v.pins = (const struct alc_pincfg[]) {
4756 { 0x1a, 0x2101103f }, /* dock line-out */
4757 { 0x1b, 0x23a11040 }, /* dock mic-in */
4761 .chain_id = ALC269_FIXUP_QUANTA_MUTE
4763 [ALC269_FIXUP_AMIC] = {
4764 .type = ALC_FIXUP_PINS,
4765 .v.pins = (const struct alc_pincfg[]) {
4766 { 0x14, 0x99130110 }, /* speaker */
4767 { 0x15, 0x0121401f }, /* HP out */
4768 { 0x18, 0x01a19c20 }, /* mic */
4769 { 0x19, 0x99a3092f }, /* int-mic */
4773 [ALC269_FIXUP_DMIC] = {
4774 .type = ALC_FIXUP_PINS,
4775 .v.pins = (const struct alc_pincfg[]) {
4776 { 0x12, 0x99a3092f }, /* int-mic */
4777 { 0x14, 0x99130110 }, /* speaker */
4778 { 0x15, 0x0121401f }, /* HP out */
4779 { 0x18, 0x01a19c20 }, /* mic */
4783 [ALC269VB_FIXUP_AMIC] = {
4784 .type = ALC_FIXUP_PINS,
4785 .v.pins = (const struct alc_pincfg[]) {
4786 { 0x14, 0x99130110 }, /* speaker */
4787 { 0x18, 0x01a19c20 }, /* mic */
4788 { 0x19, 0x99a3092f }, /* int-mic */
4789 { 0x21, 0x0121401f }, /* HP out */
4793 [ALC269_FIXUP_DMIC] = {
4794 .type = ALC_FIXUP_PINS,
4795 .v.pins = (const struct alc_pincfg[]) {
4796 { 0x12, 0x99a3092f }, /* int-mic */
4797 { 0x14, 0x99130110 }, /* speaker */
4798 { 0x18, 0x01a19c20 }, /* mic */
4799 { 0x21, 0x0121401f }, /* HP out */
4805 static const struct snd_pci_quirk alc269_fixup_tbl[] = {
4806 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
4807 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
4808 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
4809 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
4810 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
4811 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
4812 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
4813 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
4814 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
4815 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
4816 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
4817 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
4818 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
4819 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
4820 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
4821 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
4822 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
4823 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
4824 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_QUANTA_MUTE),
4825 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K),
4826 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
4829 /* Below is a quirk table taken from the old code.
4830 * Basically the device should work as is without the fixup table.
4831 * If BIOS doesn't give a proper info, enable the corresponding
4834 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
4836 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
4837 SND_PCI_QUIRK(0x1043, 0x1113, "ASUS N63Jn", ALC269_FIXUP_AMIC),
4838 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
4839 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
4840 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
4841 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
4842 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
4843 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
4844 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
4845 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
4846 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
4847 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
4848 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
4849 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
4850 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
4851 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
4852 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
4853 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
4854 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
4855 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
4856 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
4857 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
4858 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
4859 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
4860 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
4861 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
4862 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
4863 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
4864 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
4865 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
4866 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
4867 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
4868 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
4869 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
4870 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
4871 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
4872 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
4873 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
4874 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
4875 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
4880 static const struct alc_model_fixup alc269_fixup_models[] = {
4881 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
4882 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
4887 static int alc269_fill_coef(struct hda_codec *codec)
4891 if ((alc_read_coef_idx(codec, 0) & 0x00ff) < 0x015) {
4892 alc_write_coef_idx(codec, 0xf, 0x960b);
4893 alc_write_coef_idx(codec, 0xe, 0x8817);
4896 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x016) {
4897 alc_write_coef_idx(codec, 0xf, 0x960b);
4898 alc_write_coef_idx(codec, 0xe, 0x8814);
4901 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x017) {
4902 val = alc_read_coef_idx(codec, 0x04);
4903 /* Power up output pin */
4904 alc_write_coef_idx(codec, 0x04, val | (1<<11));
4907 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x018) {
4908 val = alc_read_coef_idx(codec, 0xd);
4909 if ((val & 0x0c00) >> 10 != 0x1) {
4910 /* Capless ramp up clock control */
4911 alc_write_coef_idx(codec, 0xd, val | (1<<10));
4913 val = alc_read_coef_idx(codec, 0x17);
4914 if ((val & 0x01c0) >> 6 != 0x4) {
4915 /* Class D power on reset */
4916 alc_write_coef_idx(codec, 0x17, val | (1<<7));
4920 val = alc_read_coef_idx(codec, 0xd); /* Class D */
4921 alc_write_coef_idx(codec, 0xd, val | (1<<14));
4923 val = alc_read_coef_idx(codec, 0x4); /* HP */
4924 alc_write_coef_idx(codec, 0x4, val | (1<<11));
4931 static int patch_alc269(struct hda_codec *codec)
4933 struct alc_spec *spec;
4936 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4942 spec->mixer_nid = 0x0b;
4944 alc_auto_parse_customize_define(codec);
4946 if (codec->vendor_id == 0x10ec0269) {
4948 spec->codec_variant = ALC269_TYPE_ALC269VA;
4949 coef = alc_read_coef_idx(codec, 0);
4950 if ((coef & 0x00f0) == 0x0010) {
4951 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
4952 spec->cdefine.platform_type == 1) {
4953 alc_codec_rename(codec, "ALC271X");
4954 } else if ((coef & 0xf000) == 0x2000) {
4955 alc_codec_rename(codec, "ALC259");
4956 } else if ((coef & 0xf000) == 0x3000) {
4957 alc_codec_rename(codec, "ALC258");
4958 } else if ((coef & 0xfff0) == 0x3010) {
4959 alc_codec_rename(codec, "ALC277");
4961 alc_codec_rename(codec, "ALC269VB");
4963 spec->codec_variant = ALC269_TYPE_ALC269VB;
4964 } else if ((coef & 0x00f0) == 0x0020) {
4966 alc_codec_rename(codec, "ALC259");
4967 else if (coef == 0x6023)
4968 alc_codec_rename(codec, "ALC281X");
4969 else if (codec->bus->pci->subsystem_vendor == 0x17aa &&
4970 codec->bus->pci->subsystem_device == 0x21f3)
4971 alc_codec_rename(codec, "ALC3202");
4973 alc_codec_rename(codec, "ALC269VC");
4974 spec->codec_variant = ALC269_TYPE_ALC269VC;
4976 alc_fix_pll_init(codec, 0x20, 0x04, 15);
4977 alc269_fill_coef(codec);
4980 alc_pick_fixup(codec, alc269_fixup_models,
4981 alc269_fixup_tbl, alc269_fixups);
4982 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4984 /* automatic parse from the BIOS config */
4985 err = alc269_parse_auto_config(codec);
4991 if (!spec->no_analog && !spec->adc_nids) {
4992 alc_auto_fill_adc_caps(codec);
4993 alc_rebuild_imux_for_auto_mic(codec);
4994 alc_remove_invalid_adc_nids(codec);
4997 if (!spec->no_analog && !spec->cap_mixer)
4998 set_capture_mixer(codec);
5000 if (!spec->no_analog && has_cdefine_beep(codec)) {
5001 err = snd_hda_attach_beep_device(codec, 0x1);
5006 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
5009 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5011 spec->vmaster_nid = 0x02;
5013 codec->patch_ops = alc_patch_ops;
5015 codec->patch_ops.resume = alc269_resume;
5017 spec->init_hook = alc_auto_init_std;
5018 spec->shutup = alc269_shutup;
5020 alc_init_jacks(codec);
5021 #ifdef CONFIG_SND_HDA_POWER_SAVE
5022 if (!spec->loopback.amplist)
5023 spec->loopback.amplist = alc269_loopbacks;
5024 if (alc269_mic2_for_mute_led(codec))
5025 codec->patch_ops.check_power_status = alc269_mic2_mute_check_ps;
5035 static int alc861_parse_auto_config(struct hda_codec *codec)
5037 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
5038 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
5039 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
5042 #ifdef CONFIG_SND_HDA_POWER_SAVE
5043 static const struct hda_amp_list alc861_loopbacks[] = {
5044 { 0x15, HDA_INPUT, 0 },
5045 { 0x15, HDA_INPUT, 1 },
5046 { 0x15, HDA_INPUT, 2 },
5047 { 0x15, HDA_INPUT, 3 },
5053 /* Pin config fixes */
5055 PINFIX_FSC_AMILO_PI1505,
5058 static const struct alc_fixup alc861_fixups[] = {
5059 [PINFIX_FSC_AMILO_PI1505] = {
5060 .type = ALC_FIXUP_PINS,
5061 .v.pins = (const struct alc_pincfg[]) {
5062 { 0x0b, 0x0221101f }, /* HP */
5063 { 0x0f, 0x90170310 }, /* speaker */
5069 static const struct snd_pci_quirk alc861_fixup_tbl[] = {
5070 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", PINFIX_FSC_AMILO_PI1505),
5076 static int patch_alc861(struct hda_codec *codec)
5078 struct alc_spec *spec;
5081 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5087 spec->mixer_nid = 0x15;
5089 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
5090 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5092 /* automatic parse from the BIOS config */
5093 err = alc861_parse_auto_config(codec);
5099 if (!spec->no_analog && !spec->adc_nids) {
5100 alc_auto_fill_adc_caps(codec);
5101 alc_rebuild_imux_for_auto_mic(codec);
5102 alc_remove_invalid_adc_nids(codec);
5105 if (!spec->no_analog && !spec->cap_mixer)
5106 set_capture_mixer(codec);
5108 if (!spec->no_analog) {
5109 err = snd_hda_attach_beep_device(codec, 0x23);
5114 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
5117 spec->vmaster_nid = 0x03;
5119 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5121 codec->patch_ops = alc_patch_ops;
5122 spec->init_hook = alc_auto_init_std;
5123 #ifdef CONFIG_SND_HDA_POWER_SAVE
5124 spec->power_hook = alc_power_eapd;
5125 if (!spec->loopback.amplist)
5126 spec->loopback.amplist = alc861_loopbacks;
5137 * In addition, an independent DAC
5139 #ifdef CONFIG_SND_HDA_POWER_SAVE
5140 #define alc861vd_loopbacks alc880_loopbacks
5143 static int alc861vd_parse_auto_config(struct hda_codec *codec)
5145 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
5146 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5147 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
5151 ALC660VD_FIX_ASUS_GPIO1,
5152 ALC861VD_FIX_DALLAS,
5155 /* exclude VREF80 */
5156 static void alc861vd_fixup_dallas(struct hda_codec *codec,
5157 const struct alc_fixup *fix, int action)
5159 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
5160 snd_hda_override_pin_caps(codec, 0x18, 0x00001714);
5161 snd_hda_override_pin_caps(codec, 0x19, 0x0000171c);
5165 static const struct alc_fixup alc861vd_fixups[] = {
5166 [ALC660VD_FIX_ASUS_GPIO1] = {
5167 .type = ALC_FIXUP_VERBS,
5168 .v.verbs = (const struct hda_verb[]) {
5170 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
5171 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5172 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5176 [ALC861VD_FIX_DALLAS] = {
5177 .type = ALC_FIXUP_FUNC,
5178 .v.func = alc861vd_fixup_dallas,
5182 static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
5183 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
5184 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
5185 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
5189 static const struct hda_verb alc660vd_eapd_verbs[] = {
5190 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
5191 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
5197 static int patch_alc861vd(struct hda_codec *codec)
5199 struct alc_spec *spec;
5202 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5208 spec->mixer_nid = 0x0b;
5210 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
5211 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5213 /* automatic parse from the BIOS config */
5214 err = alc861vd_parse_auto_config(codec);
5220 if (codec->vendor_id == 0x10ec0660) {
5221 /* always turn on EAPD */
5222 add_verb(spec, alc660vd_eapd_verbs);
5225 if (!spec->no_analog && !spec->adc_nids) {
5226 alc_auto_fill_adc_caps(codec);
5227 alc_rebuild_imux_for_auto_mic(codec);
5228 alc_remove_invalid_adc_nids(codec);
5231 if (!spec->no_analog && !spec->cap_mixer)
5232 set_capture_mixer(codec);
5234 if (!spec->no_analog) {
5235 err = snd_hda_attach_beep_device(codec, 0x23);
5240 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5243 spec->vmaster_nid = 0x02;
5245 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5247 codec->patch_ops = alc_patch_ops;
5249 spec->init_hook = alc_auto_init_std;
5250 spec->shutup = alc_eapd_shutup;
5251 #ifdef CONFIG_SND_HDA_POWER_SAVE
5252 if (!spec->loopback.amplist)
5253 spec->loopback.amplist = alc861vd_loopbacks;
5262 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
5263 * configuration. Each pin widget can choose any input DACs and a mixer.
5264 * Each ADC is connected from a mixer of all inputs. This makes possible
5265 * 6-channel independent captures.
5267 * In addition, an independent DAC for the multi-playback (not used in this
5270 #ifdef CONFIG_SND_HDA_POWER_SAVE
5271 #define alc662_loopbacks alc880_loopbacks
5275 * BIOS auto configuration
5278 static int alc662_parse_auto_config(struct hda_codec *codec)
5280 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
5281 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
5282 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5283 const hda_nid_t *ssids;
5285 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
5286 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
5287 ssids = alc663_ssids;
5289 ssids = alc662_ssids;
5290 return alc_parse_auto_config(codec, alc662_ignore, ssids);
5293 static void alc272_fixup_mario(struct hda_codec *codec,
5294 const struct alc_fixup *fix, int action)
5296 if (action != ALC_FIXUP_ACT_PROBE)
5298 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
5299 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
5300 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
5301 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5302 (0 << AC_AMPCAP_MUTE_SHIFT)))
5304 "hda_codec: failed to override amp caps for NID 0x2\n");
5308 ALC662_FIXUP_ASPIRE,
5309 ALC662_FIXUP_IDEAPAD,
5311 ALC662_FIXUP_CZC_P10T,
5312 ALC662_FIXUP_SKU_IGNORE,
5313 ALC662_FIXUP_HP_RP5800,
5314 ALC662_FIXUP_ASUS_MODE1,
5315 ALC662_FIXUP_ASUS_MODE2,
5316 ALC662_FIXUP_ASUS_MODE3,
5317 ALC662_FIXUP_ASUS_MODE4,
5318 ALC662_FIXUP_ASUS_MODE5,
5319 ALC662_FIXUP_ASUS_MODE6,
5320 ALC662_FIXUP_ASUS_MODE7,
5321 ALC662_FIXUP_ASUS_MODE8,
5324 static const struct alc_fixup alc662_fixups[] = {
5325 [ALC662_FIXUP_ASPIRE] = {
5326 .type = ALC_FIXUP_PINS,
5327 .v.pins = (const struct alc_pincfg[]) {
5328 { 0x15, 0x99130112 }, /* subwoofer */
5332 [ALC662_FIXUP_IDEAPAD] = {
5333 .type = ALC_FIXUP_PINS,
5334 .v.pins = (const struct alc_pincfg[]) {
5335 { 0x17, 0x99130112 }, /* subwoofer */
5339 [ALC272_FIXUP_MARIO] = {
5340 .type = ALC_FIXUP_FUNC,
5341 .v.func = alc272_fixup_mario,
5343 [ALC662_FIXUP_CZC_P10T] = {
5344 .type = ALC_FIXUP_VERBS,
5345 .v.verbs = (const struct hda_verb[]) {
5346 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
5350 [ALC662_FIXUP_SKU_IGNORE] = {
5351 .type = ALC_FIXUP_SKU,
5352 .v.sku = ALC_FIXUP_SKU_IGNORE,
5354 [ALC662_FIXUP_HP_RP5800] = {
5355 .type = ALC_FIXUP_PINS,
5356 .v.pins = (const struct alc_pincfg[]) {
5357 { 0x14, 0x0221201f }, /* HP out */
5361 .chain_id = ALC662_FIXUP_SKU_IGNORE
5363 [ALC662_FIXUP_ASUS_MODE1] = {
5364 .type = ALC_FIXUP_PINS,
5365 .v.pins = (const struct alc_pincfg[]) {
5366 { 0x14, 0x99130110 }, /* speaker */
5367 { 0x18, 0x01a19c20 }, /* mic */
5368 { 0x19, 0x99a3092f }, /* int-mic */
5369 { 0x21, 0x0121401f }, /* HP out */
5373 .chain_id = ALC662_FIXUP_SKU_IGNORE
5375 [ALC662_FIXUP_ASUS_MODE2] = {
5376 .type = ALC_FIXUP_PINS,
5377 .v.pins = (const struct alc_pincfg[]) {
5378 { 0x14, 0x99130110 }, /* speaker */
5379 { 0x18, 0x01a19820 }, /* mic */
5380 { 0x19, 0x99a3092f }, /* int-mic */
5381 { 0x1b, 0x0121401f }, /* HP out */
5385 .chain_id = ALC662_FIXUP_SKU_IGNORE
5387 [ALC662_FIXUP_ASUS_MODE3] = {
5388 .type = ALC_FIXUP_PINS,
5389 .v.pins = (const struct alc_pincfg[]) {
5390 { 0x14, 0x99130110 }, /* speaker */
5391 { 0x15, 0x0121441f }, /* HP */
5392 { 0x18, 0x01a19840 }, /* mic */
5393 { 0x19, 0x99a3094f }, /* int-mic */
5394 { 0x21, 0x01211420 }, /* HP2 */
5398 .chain_id = ALC662_FIXUP_SKU_IGNORE
5400 [ALC662_FIXUP_ASUS_MODE4] = {
5401 .type = ALC_FIXUP_PINS,
5402 .v.pins = (const struct alc_pincfg[]) {
5403 { 0x14, 0x99130110 }, /* speaker */
5404 { 0x16, 0x99130111 }, /* speaker */
5405 { 0x18, 0x01a19840 }, /* mic */
5406 { 0x19, 0x99a3094f }, /* int-mic */
5407 { 0x21, 0x0121441f }, /* HP */
5411 .chain_id = ALC662_FIXUP_SKU_IGNORE
5413 [ALC662_FIXUP_ASUS_MODE5] = {
5414 .type = ALC_FIXUP_PINS,
5415 .v.pins = (const struct alc_pincfg[]) {
5416 { 0x14, 0x99130110 }, /* speaker */
5417 { 0x15, 0x0121441f }, /* HP */
5418 { 0x16, 0x99130111 }, /* speaker */
5419 { 0x18, 0x01a19840 }, /* mic */
5420 { 0x19, 0x99a3094f }, /* int-mic */
5424 .chain_id = ALC662_FIXUP_SKU_IGNORE
5426 [ALC662_FIXUP_ASUS_MODE6] = {
5427 .type = ALC_FIXUP_PINS,
5428 .v.pins = (const struct alc_pincfg[]) {
5429 { 0x14, 0x99130110 }, /* speaker */
5430 { 0x15, 0x01211420 }, /* HP2 */
5431 { 0x18, 0x01a19840 }, /* mic */
5432 { 0x19, 0x99a3094f }, /* int-mic */
5433 { 0x1b, 0x0121441f }, /* HP */
5437 .chain_id = ALC662_FIXUP_SKU_IGNORE
5439 [ALC662_FIXUP_ASUS_MODE7] = {
5440 .type = ALC_FIXUP_PINS,
5441 .v.pins = (const struct alc_pincfg[]) {
5442 { 0x14, 0x99130110 }, /* speaker */
5443 { 0x17, 0x99130111 }, /* speaker */
5444 { 0x18, 0x01a19840 }, /* mic */
5445 { 0x19, 0x99a3094f }, /* int-mic */
5446 { 0x1b, 0x01214020 }, /* HP */
5447 { 0x21, 0x0121401f }, /* HP */
5451 .chain_id = ALC662_FIXUP_SKU_IGNORE
5453 [ALC662_FIXUP_ASUS_MODE8] = {
5454 .type = ALC_FIXUP_PINS,
5455 .v.pins = (const struct alc_pincfg[]) {
5456 { 0x14, 0x99130110 }, /* speaker */
5457 { 0x12, 0x99a30970 }, /* int-mic */
5458 { 0x15, 0x01214020 }, /* HP */
5459 { 0x17, 0x99130111 }, /* speaker */
5460 { 0x18, 0x01a19840 }, /* mic */
5461 { 0x21, 0x0121401f }, /* HP */
5465 .chain_id = ALC662_FIXUP_SKU_IGNORE
5469 static const struct snd_pci_quirk alc662_fixup_tbl[] = {
5470 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
5471 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
5472 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
5473 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
5474 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
5475 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
5476 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
5477 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
5478 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
5479 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
5482 /* Below is a quirk table taken from the old code.
5483 * Basically the device should work as is without the fixup table.
5484 * If BIOS doesn't give a proper info, enable the corresponding
5487 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
5488 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
5489 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
5490 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
5491 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
5492 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5493 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
5494 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
5495 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
5496 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5497 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
5498 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
5499 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
5500 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
5501 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
5502 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5503 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
5504 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
5505 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5506 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
5507 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
5508 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5509 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
5510 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
5511 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
5512 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5513 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
5514 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
5515 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5516 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
5517 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5518 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5519 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
5520 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
5521 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
5522 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
5523 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
5524 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
5525 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
5526 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5527 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
5528 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
5529 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
5530 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
5531 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
5532 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
5533 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
5534 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
5535 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
5536 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
5541 static const struct alc_model_fixup alc662_fixup_models[] = {
5542 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
5543 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
5544 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
5545 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
5546 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
5547 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
5548 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
5549 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
5550 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
5557 static int patch_alc662(struct hda_codec *codec)
5559 struct alc_spec *spec;
5563 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5569 spec->mixer_nid = 0x0b;
5571 /* handle multiple HPs as is */
5572 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
5574 alc_auto_parse_customize_define(codec);
5576 alc_fix_pll_init(codec, 0x20, 0x04, 15);
5578 coef = alc_read_coef_idx(codec, 0);
5579 if (coef == 0x8020 || coef == 0x8011)
5580 alc_codec_rename(codec, "ALC661");
5581 else if (coef & (1 << 14) &&
5582 codec->bus->pci->subsystem_vendor == 0x1025 &&
5583 spec->cdefine.platform_type == 1)
5584 alc_codec_rename(codec, "ALC272X");
5585 else if (coef == 0x4011)
5586 alc_codec_rename(codec, "ALC656");
5588 alc_pick_fixup(codec, alc662_fixup_models,
5589 alc662_fixup_tbl, alc662_fixups);
5590 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5591 /* automatic parse from the BIOS config */
5592 err = alc662_parse_auto_config(codec);
5598 if (!spec->no_analog && !spec->adc_nids) {
5599 alc_auto_fill_adc_caps(codec);
5600 alc_rebuild_imux_for_auto_mic(codec);
5601 alc_remove_invalid_adc_nids(codec);
5604 if (!spec->no_analog && !spec->cap_mixer)
5605 set_capture_mixer(codec);
5607 if (!spec->no_analog && has_cdefine_beep(codec)) {
5608 err = snd_hda_attach_beep_device(codec, 0x1);
5613 switch (codec->vendor_id) {
5615 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5620 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
5623 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
5627 spec->vmaster_nid = 0x02;
5629 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5631 codec->patch_ops = alc_patch_ops;
5632 spec->init_hook = alc_auto_init_std;
5633 spec->shutup = alc_eapd_shutup;
5635 alc_init_jacks(codec);
5637 #ifdef CONFIG_SND_HDA_POWER_SAVE
5638 if (!spec->loopback.amplist)
5639 spec->loopback.amplist = alc662_loopbacks;
5645 static int patch_alc888(struct hda_codec *codec)
5647 if ((alc_read_coef_idx(codec, 0) & 0x00f0)==0x0030){
5648 kfree(codec->chip_name);
5649 if (codec->vendor_id == 0x10ec0887)
5650 codec->chip_name = kstrdup("ALC887-VD", GFP_KERNEL);
5652 codec->chip_name = kstrdup("ALC888-VD", GFP_KERNEL);
5653 if (!codec->chip_name) {
5657 return patch_alc662(codec);
5659 return patch_alc882(codec);
5662 static int patch_alc899(struct hda_codec *codec)
5664 if ((alc_read_coef_idx(codec, 0) & 0x2000) != 0x2000) {
5665 kfree(codec->chip_name);
5666 codec->chip_name = kstrdup("ALC898", GFP_KERNEL);
5668 return patch_alc882(codec);
5675 static int alc680_parse_auto_config(struct hda_codec *codec)
5677 return alc_parse_auto_config(codec, NULL, NULL);
5682 static int patch_alc680(struct hda_codec *codec)
5684 struct alc_spec *spec;
5687 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5693 /* ALC680 has no aa-loopback mixer */
5695 /* automatic parse from the BIOS config */
5696 err = alc680_parse_auto_config(codec);
5702 if (!spec->no_analog && !spec->cap_mixer)
5703 set_capture_mixer(codec);
5705 spec->vmaster_nid = 0x02;
5707 codec->patch_ops = alc_patch_ops;
5708 spec->init_hook = alc_auto_init_std;
5716 static const struct hda_codec_preset snd_hda_preset_realtek[] = {
5717 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
5718 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
5719 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
5720 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
5721 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
5722 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
5723 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
5724 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
5725 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
5726 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
5727 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
5728 .patch = patch_alc861 },
5729 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
5730 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
5731 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
5732 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
5733 .patch = patch_alc882 },
5734 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
5735 .patch = patch_alc662 },
5736 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
5737 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
5738 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
5739 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
5740 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
5741 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
5742 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
5743 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
5744 .patch = patch_alc882 },
5745 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
5746 .patch = patch_alc882 },
5747 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
5748 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc888 },
5749 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
5750 .patch = patch_alc882 },
5751 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc888 },
5752 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
5753 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
5754 { .id = 0x10ec0899, .name = "ALC899", .patch = patch_alc899 },
5758 MODULE_ALIAS("snd-hda-codec-id:10ec*");
5760 MODULE_LICENSE("GPL");
5761 MODULE_DESCRIPTION("Realtek HD-audio codec");
5763 static struct hda_codec_preset_list realtek_list = {
5764 .preset = snd_hda_preset_realtek,
5765 .owner = THIS_MODULE,
5768 static int __init patch_realtek_init(void)
5770 return snd_hda_add_codec_preset(&realtek_list);
5773 static void __exit patch_realtek_exit(void)
5775 snd_hda_delete_codec_preset(&realtek_list);
5778 module_init(patch_realtek_init)
5779 module_exit(patch_realtek_exit)