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);
163 /* for pin sensing */
164 unsigned int jack_present: 1;
165 unsigned int line_jack_present:1;
166 unsigned int master_mute:1;
167 unsigned int auto_mic:1;
168 unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */
169 unsigned int automute:1; /* HP automute enabled */
170 unsigned int detect_line:1; /* Line-out detection enabled */
171 unsigned int automute_lines:1; /* automute line-out as well */
172 unsigned int automute_hp_lo:1; /* both HP and LO available */
175 unsigned int no_analog :1; /* digital I/O only */
176 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
177 unsigned int single_input_src:1;
178 unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */
180 /* auto-mute control */
182 hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS];
185 int codec_variant; /* flag for other variants */
187 /* for virtual master */
188 hda_nid_t vmaster_nid;
189 #ifdef CONFIG_SND_HDA_POWER_SAVE
190 struct hda_loopback_check loopback;
195 unsigned int pll_coef_idx, pll_coef_bit;
199 const struct alc_fixup *fixup_list;
200 const char *fixup_name;
204 struct alc_multi_io multi_io[4];
207 #define ALC_MODEL_AUTO 0 /* common for all chips */
209 static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
210 int dir, unsigned int bits)
214 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
215 if (query_amp_caps(codec, nid, dir) & bits)
220 #define nid_has_mute(codec, nid, dir) \
221 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
222 #define nid_has_volume(codec, nid, dir) \
223 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
228 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
229 struct snd_ctl_elem_info *uinfo)
231 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
232 struct alc_spec *spec = codec->spec;
233 unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
234 if (mux_idx >= spec->num_mux_defs)
236 if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
238 return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
241 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
242 struct snd_ctl_elem_value *ucontrol)
244 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
245 struct alc_spec *spec = codec->spec;
246 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
248 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
252 static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
254 struct alc_spec *spec = codec->spec;
255 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
257 if (spec->cur_adc && spec->cur_adc != new_adc) {
258 /* stream is running, let's swap the current ADC */
259 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
260 spec->cur_adc = new_adc;
261 snd_hda_codec_setup_stream(codec, new_adc,
262 spec->cur_adc_stream_tag, 0,
263 spec->cur_adc_format);
269 /* select the given imux item; either unmute exclusively or select the route */
270 static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
271 unsigned int idx, bool force)
273 struct alc_spec *spec = codec->spec;
274 const struct hda_input_mux *imux;
275 unsigned int mux_idx;
279 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
280 imux = &spec->input_mux[mux_idx];
281 if (!imux->num_items && mux_idx > 0)
282 imux = &spec->input_mux[0];
284 if (idx >= imux->num_items)
285 idx = imux->num_items - 1;
286 if (spec->cur_mux[adc_idx] == idx && !force)
288 spec->cur_mux[adc_idx] = idx;
290 if (spec->dyn_adc_switch) {
291 alc_dyn_adc_pcm_resetup(codec, idx);
292 adc_idx = spec->dyn_adc_idx[idx];
295 nid = spec->capsrc_nids ?
296 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
299 if (snd_hda_get_conn_list(codec, nid, NULL) <= 1)
302 type = get_wcaps_type(get_wcaps(codec, nid));
303 if (type == AC_WID_AUD_MIX) {
304 /* Matrix-mixer style (e.g. ALC882) */
305 for (i = 0; i < imux->num_items; i++) {
306 unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
307 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
308 imux->items[i].index,
312 /* MUX style (e.g. ALC880) */
313 snd_hda_codec_write_cache(codec, nid, 0,
314 AC_VERB_SET_CONNECT_SEL,
315 imux->items[idx].index);
320 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
321 struct snd_ctl_elem_value *ucontrol)
323 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
324 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
325 return alc_mux_select(codec, adc_idx,
326 ucontrol->value.enumerated.item[0], false);
330 * set up the input pin config (depending on the given auto-pin type)
332 static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
335 unsigned int val = PIN_IN;
337 if (auto_pin_type == AUTO_PIN_MIC) {
340 oldval = snd_hda_codec_read(codec, nid, 0,
341 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
342 pincap = snd_hda_query_pin_caps(codec, nid);
343 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
344 /* if the default pin setup is vref50, we give it priority */
345 if ((pincap & AC_PINCAP_VREF_80) && oldval != PIN_VREF50)
347 else if (pincap & AC_PINCAP_VREF_50)
349 else if (pincap & AC_PINCAP_VREF_100)
351 else if (pincap & AC_PINCAP_VREF_GRD)
354 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val);
358 * Append the given mixer and verb elements for the later use
359 * The mixer array is referred in build_controls(), and init_verbs are
362 static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
364 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
366 spec->mixers[spec->num_mixers++] = mix;
369 static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
371 if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
373 spec->init_verbs[spec->num_init_verbs++] = verb;
377 * GPIO setup tables, used in initialization
379 /* Enable GPIO mask and set output */
380 static const struct hda_verb alc_gpio1_init_verbs[] = {
381 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
382 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
383 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
387 static const struct hda_verb alc_gpio2_init_verbs[] = {
388 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
389 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
390 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
394 static const struct hda_verb alc_gpio3_init_verbs[] = {
395 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
396 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
397 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
402 * Fix hardware PLL issue
403 * On some codecs, the analog PLL gating control must be off while
404 * the default value is 1.
406 static void alc_fix_pll(struct hda_codec *codec)
408 struct alc_spec *spec = codec->spec;
413 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
415 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
416 AC_VERB_GET_PROC_COEF, 0);
417 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
419 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
420 val & ~(1 << spec->pll_coef_bit));
423 static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
424 unsigned int coef_idx, unsigned int coef_bit)
426 struct alc_spec *spec = codec->spec;
428 spec->pll_coef_idx = coef_idx;
429 spec->pll_coef_bit = coef_bit;
434 * Jack-reporting via input-jack layer
437 /* initialization of jacks; currently checks only a few known pins */
438 static int alc_init_jacks(struct hda_codec *codec)
440 #ifdef CONFIG_SND_HDA_INPUT_JACK
441 struct alc_spec *spec = codec->spec;
443 unsigned int hp_nid = spec->autocfg.hp_pins[0];
444 unsigned int mic_nid = spec->ext_mic_pin;
445 unsigned int dock_nid = spec->dock_mic_pin;
448 err = snd_hda_input_jack_add(codec, hp_nid,
449 SND_JACK_HEADPHONE, NULL);
452 snd_hda_input_jack_report(codec, hp_nid);
456 err = snd_hda_input_jack_add(codec, mic_nid,
457 SND_JACK_MICROPHONE, NULL);
460 snd_hda_input_jack_report(codec, mic_nid);
463 err = snd_hda_input_jack_add(codec, dock_nid,
464 SND_JACK_MICROPHONE, NULL);
467 snd_hda_input_jack_report(codec, dock_nid);
469 #endif /* CONFIG_SND_HDA_INPUT_JACK */
474 * Jack detections for HP auto-mute and mic-switch
477 /* check each pin in the given array; returns true if any of them is plugged */
478 static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
482 for (i = 0; i < num_pins; i++) {
483 hda_nid_t nid = pins[i];
486 snd_hda_input_jack_report(codec, nid);
487 present |= snd_hda_jack_detect(codec, nid);
492 /* standard HP/line-out auto-mute helper */
493 static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
494 bool mute, bool hp_out)
496 struct alc_spec *spec = codec->spec;
497 unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0;
498 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
501 for (i = 0; i < num_pins; i++) {
502 hda_nid_t nid = pins[i];
505 switch (spec->automute_mode) {
506 case ALC_AUTOMUTE_PIN:
507 snd_hda_codec_write(codec, nid, 0,
508 AC_VERB_SET_PIN_WIDGET_CONTROL,
511 case ALC_AUTOMUTE_AMP:
512 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
513 HDA_AMP_MUTE, mute_bits);
515 case ALC_AUTOMUTE_MIXER:
516 nid = spec->automute_mixer_nid[i];
519 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
520 HDA_AMP_MUTE, mute_bits);
521 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1,
522 HDA_AMP_MUTE, mute_bits);
528 /* Toggle internal speakers muting */
529 static void update_speakers(struct hda_codec *codec)
531 struct alc_spec *spec = codec->spec;
534 /* Control HP pins/amps depending on master_mute state;
535 * in general, HP pins/amps control should be enabled in all cases,
536 * but currently set only for master_mute, just to be safe
538 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
539 spec->autocfg.hp_pins, spec->master_mute, true);
544 on = spec->jack_present | spec->line_jack_present;
545 on |= spec->master_mute;
546 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
547 spec->autocfg.speaker_pins, on, false);
549 /* toggle line-out mutes if needed, too */
550 /* if LO is a copy of either HP or Speaker, don't need to handle it */
551 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
552 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
554 if (!spec->automute_lines || !spec->automute)
557 on = spec->jack_present;
558 on |= spec->master_mute;
559 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
560 spec->autocfg.line_out_pins, on, false);
563 /* standard HP-automute helper */
564 static void alc_hp_automute(struct hda_codec *codec)
566 struct alc_spec *spec = codec->spec;
571 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
572 spec->autocfg.hp_pins);
573 update_speakers(codec);
576 /* standard line-out-automute helper */
577 static void alc_line_automute(struct hda_codec *codec)
579 struct alc_spec *spec = codec->spec;
581 if (!spec->automute || !spec->detect_line)
583 spec->line_jack_present =
584 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
585 spec->autocfg.line_out_pins);
586 update_speakers(codec);
589 #define get_connection_index(codec, mux, nid) \
590 snd_hda_get_conn_index(codec, mux, nid, 0)
592 /* standard mic auto-switch helper */
593 static void alc_mic_automute(struct hda_codec *codec)
595 struct alc_spec *spec = codec->spec;
596 hda_nid_t *pins = spec->imux_pins;
598 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
600 if (snd_BUG_ON(!spec->adc_nids))
602 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
605 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
606 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
607 else if (spec->dock_mic_idx >= 0 &&
608 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
609 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
611 alc_mux_select(codec, 0, spec->int_mic_idx, false);
613 snd_hda_input_jack_report(codec, pins[spec->ext_mic_idx]);
614 if (spec->dock_mic_idx >= 0)
615 snd_hda_input_jack_report(codec, pins[spec->dock_mic_idx]);
618 /* unsolicited event for HP jack sensing */
619 static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
621 if (codec->vendor_id == 0x10ec0880)
627 alc_hp_automute(codec);
629 case ALC_FRONT_EVENT:
630 alc_line_automute(codec);
633 alc_mic_automute(codec);
638 /* call init functions of standard auto-mute helpers */
639 static void alc_inithook(struct hda_codec *codec)
641 alc_hp_automute(codec);
642 alc_line_automute(codec);
643 alc_mic_automute(codec);
646 /* additional initialization for ALC888 variants */
647 static void alc888_coef_init(struct hda_codec *codec)
651 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
652 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
653 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
654 if ((tmp & 0xf0) == 0x20)
656 snd_hda_codec_read(codec, 0x20, 0,
657 AC_VERB_SET_PROC_COEF, 0x830);
660 snd_hda_codec_read(codec, 0x20, 0,
661 AC_VERB_SET_PROC_COEF, 0x3030);
664 /* additional initialization for ALC889 variants */
665 static void alc889_coef_init(struct hda_codec *codec)
669 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
670 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
671 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
672 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
675 /* turn on/off EAPD control (only if available) */
676 static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
678 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
680 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
681 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
685 /* turn on/off EAPD controls of the codec */
686 static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
688 /* We currently only handle front, HP */
689 static hda_nid_t pins[] = {
690 0x0f, 0x10, 0x14, 0x15, 0
693 for (p = pins; *p; p++)
694 set_eapd(codec, *p, on);
697 /* generic shutup callback;
698 * just turning off EPAD and a little pause for avoiding pop-noise
700 static void alc_eapd_shutup(struct hda_codec *codec)
702 alc_auto_setup_eapd(codec, false);
706 /* generic EAPD initialization */
707 static void alc_auto_init_amp(struct hda_codec *codec, int type)
711 alc_auto_setup_eapd(codec, true);
714 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
717 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
720 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
722 case ALC_INIT_DEFAULT:
723 switch (codec->vendor_id) {
725 snd_hda_codec_write(codec, 0x1a, 0,
726 AC_VERB_SET_COEF_INDEX, 7);
727 tmp = snd_hda_codec_read(codec, 0x1a, 0,
728 AC_VERB_GET_PROC_COEF, 0);
729 snd_hda_codec_write(codec, 0x1a, 0,
730 AC_VERB_SET_COEF_INDEX, 7);
731 snd_hda_codec_write(codec, 0x1a, 0,
732 AC_VERB_SET_PROC_COEF,
741 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
742 alc889_coef_init(codec);
745 alc888_coef_init(codec);
747 #if 0 /* XXX: This may cause the silent output on speaker on some machines */
750 snd_hda_codec_write(codec, 0x20, 0,
751 AC_VERB_SET_COEF_INDEX, 7);
752 tmp = snd_hda_codec_read(codec, 0x20, 0,
753 AC_VERB_GET_PROC_COEF, 0);
754 snd_hda_codec_write(codec, 0x20, 0,
755 AC_VERB_SET_COEF_INDEX, 7);
756 snd_hda_codec_write(codec, 0x20, 0,
757 AC_VERB_SET_PROC_COEF,
767 * Auto-Mute mode mixer enum support
769 static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
770 struct snd_ctl_elem_info *uinfo)
772 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
773 struct alc_spec *spec = codec->spec;
774 static const char * const texts2[] = {
775 "Disabled", "Enabled"
777 static const char * const texts3[] = {
778 "Disabled", "Speaker Only", "Line-Out+Speaker"
780 const char * const *texts;
782 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
784 if (spec->automute_hp_lo) {
785 uinfo->value.enumerated.items = 3;
788 uinfo->value.enumerated.items = 2;
791 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
792 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
793 strcpy(uinfo->value.enumerated.name,
794 texts[uinfo->value.enumerated.item]);
798 static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
799 struct snd_ctl_elem_value *ucontrol)
801 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
802 struct alc_spec *spec = codec->spec;
806 else if (!spec->automute_lines)
810 ucontrol->value.enumerated.item[0] = val;
814 static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
815 struct snd_ctl_elem_value *ucontrol)
817 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
818 struct alc_spec *spec = codec->spec;
820 switch (ucontrol->value.enumerated.item[0]) {
827 if (spec->automute && !spec->automute_lines)
830 spec->automute_lines = 0;
833 if (!spec->automute_hp_lo)
835 if (spec->automute && spec->automute_lines)
838 spec->automute_lines = 1;
843 update_speakers(codec);
847 static const struct snd_kcontrol_new alc_automute_mode_enum = {
848 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
849 .name = "Auto-Mute Mode",
850 .info = alc_automute_mode_info,
851 .get = alc_automute_mode_get,
852 .put = alc_automute_mode_put,
855 static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec)
857 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
858 return snd_array_new(&spec->kctls);
861 static int alc_add_automute_mode_enum(struct hda_codec *codec)
863 struct alc_spec *spec = codec->spec;
864 struct snd_kcontrol_new *knew;
866 knew = alc_kcontrol_new(spec);
869 *knew = alc_automute_mode_enum;
870 knew->name = kstrdup("Auto-Mute Mode", GFP_KERNEL);
877 * Check the availability of HP/line-out auto-mute;
878 * Set up appropriately if really supported
880 static void alc_init_auto_hp(struct hda_codec *codec)
882 struct alc_spec *spec = codec->spec;
883 struct auto_pin_cfg *cfg = &spec->autocfg;
889 if (cfg->line_out_pins[0])
891 if (cfg->speaker_pins[0])
893 if (present < 2) /* need two different output types */
896 spec->automute_hp_lo = 1; /* both HP and LO automute */
898 if (!cfg->speaker_pins[0]) {
899 memcpy(cfg->speaker_pins, cfg->line_out_pins,
900 sizeof(cfg->speaker_pins));
901 cfg->speaker_outs = cfg->line_outs;
904 if (!cfg->hp_pins[0]) {
905 memcpy(cfg->hp_pins, cfg->line_out_pins,
906 sizeof(cfg->hp_pins));
907 cfg->hp_outs = cfg->line_outs;
910 for (i = 0; i < cfg->hp_outs; i++) {
911 hda_nid_t nid = cfg->hp_pins[i];
912 if (!is_jack_detectable(codec, nid))
914 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
916 snd_hda_codec_write_cache(codec, nid, 0,
917 AC_VERB_SET_UNSOLICITED_ENABLE,
918 AC_USRSP_EN | ALC_HP_EVENT);
920 spec->automute_mode = ALC_AUTOMUTE_PIN;
922 if (spec->automute && cfg->line_out_pins[0] &&
923 cfg->line_out_pins[0] != cfg->hp_pins[0] &&
924 cfg->line_out_pins[0] != cfg->speaker_pins[0]) {
925 for (i = 0; i < cfg->line_outs; i++) {
926 hda_nid_t nid = cfg->line_out_pins[i];
927 if (!is_jack_detectable(codec, nid))
929 snd_printdd("realtek: Enable Line-Out auto-muting "
930 "on NID 0x%x\n", nid);
931 snd_hda_codec_write_cache(codec, nid, 0,
932 AC_VERB_SET_UNSOLICITED_ENABLE,
933 AC_USRSP_EN | ALC_FRONT_EVENT);
934 spec->detect_line = 1;
936 spec->automute_lines = spec->detect_line;
939 if (spec->automute) {
940 /* create a control for automute mode */
941 alc_add_automute_mode_enum(codec);
942 spec->unsol_event = alc_sku_unsol_event;
946 /* return the position of NID in the list, or -1 if not found */
947 static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
950 for (i = 0; i < nums; i++)
956 /* check whether dynamic ADC-switching is available */
957 static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
959 struct alc_spec *spec = codec->spec;
960 struct hda_input_mux *imux = &spec->private_imux[0];
964 if (imux != spec->input_mux) /* no dynamic imux? */
967 for (n = 0; n < spec->num_adc_nids; n++) {
968 cap = spec->private_capsrc_nids[n];
969 for (i = 0; i < imux->num_items; i++) {
970 pin = spec->imux_pins[i];
973 if (get_connection_index(codec, cap, pin) < 0)
976 if (i >= imux->num_items)
977 return true; /* no ADC-switch is needed */
980 for (i = 0; i < imux->num_items; i++) {
981 pin = spec->imux_pins[i];
982 for (n = 0; n < spec->num_adc_nids; n++) {
983 cap = spec->private_capsrc_nids[n];
984 idx = get_connection_index(codec, cap, pin);
986 imux->items[i].index = idx;
987 spec->dyn_adc_idx[i] = n;
993 snd_printdd("realtek: enabling ADC switching\n");
994 spec->dyn_adc_switch = 1;
998 /* rebuild imux for matching with the given auto-mic pins (if not yet) */
999 static bool alc_rebuild_imux_for_auto_mic(struct hda_codec *codec)
1001 struct alc_spec *spec = codec->spec;
1002 struct hda_input_mux *imux;
1003 static char * const texts[3] = {
1004 "Mic", "Internal Mic", "Dock Mic"
1008 if (!spec->auto_mic)
1010 imux = &spec->private_imux[0];
1011 if (spec->input_mux == imux)
1013 spec->imux_pins[0] = spec->ext_mic_pin;
1014 spec->imux_pins[1] = spec->int_mic_pin;
1015 spec->imux_pins[2] = spec->dock_mic_pin;
1016 for (i = 0; i < 3; i++) {
1017 strcpy(imux->items[i].label, texts[i]);
1018 if (spec->imux_pins[i])
1019 imux->num_items = i + 1;
1021 spec->num_mux_defs = 1;
1022 spec->input_mux = imux;
1026 /* check whether all auto-mic pins are valid; setup indices if OK */
1027 static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1029 struct alc_spec *spec = codec->spec;
1030 const struct hda_input_mux *imux;
1032 if (!spec->auto_mic)
1034 if (spec->auto_mic_valid_imux)
1035 return true; /* already checked */
1037 /* fill up imux indices */
1038 if (!alc_check_dyn_adc_switch(codec)) {
1043 imux = spec->input_mux;
1044 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1045 spec->imux_pins, imux->num_items);
1046 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1047 spec->imux_pins, imux->num_items);
1048 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1049 spec->imux_pins, imux->num_items);
1050 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1052 return false; /* no corresponding imux */
1055 snd_hda_codec_write_cache(codec, spec->ext_mic_pin, 0,
1056 AC_VERB_SET_UNSOLICITED_ENABLE,
1057 AC_USRSP_EN | ALC_MIC_EVENT);
1058 if (spec->dock_mic_pin)
1059 snd_hda_codec_write_cache(codec, spec->dock_mic_pin, 0,
1060 AC_VERB_SET_UNSOLICITED_ENABLE,
1061 AC_USRSP_EN | ALC_MIC_EVENT);
1063 spec->auto_mic_valid_imux = 1;
1069 * Check the availability of auto-mic switch;
1070 * Set up if really supported
1072 static void alc_init_auto_mic(struct hda_codec *codec)
1074 struct alc_spec *spec = codec->spec;
1075 struct auto_pin_cfg *cfg = &spec->autocfg;
1076 hda_nid_t fixed, ext, dock;
1079 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1081 fixed = ext = dock = 0;
1082 for (i = 0; i < cfg->num_inputs; i++) {
1083 hda_nid_t nid = cfg->inputs[i].pin;
1084 unsigned int defcfg;
1085 defcfg = snd_hda_codec_get_pincfg(codec, nid);
1086 switch (snd_hda_get_input_pin_attr(defcfg)) {
1087 case INPUT_PIN_ATTR_INT:
1089 return; /* already occupied */
1090 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1091 return; /* invalid type */
1094 case INPUT_PIN_ATTR_UNUSED:
1095 return; /* invalid entry */
1096 case INPUT_PIN_ATTR_DOCK:
1098 return; /* already occupied */
1099 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1100 return; /* invalid type */
1105 return; /* already occupied */
1106 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1107 return; /* invalid type */
1118 if (!is_jack_detectable(codec, ext))
1119 return; /* no unsol support */
1120 if (dock && !is_jack_detectable(codec, dock))
1121 return; /* no unsol support */
1123 /* check imux indices */
1124 spec->ext_mic_pin = ext;
1125 spec->int_mic_pin = fixed;
1126 spec->dock_mic_pin = dock;
1129 if (!alc_auto_mic_check_imux(codec))
1132 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1134 spec->unsol_event = alc_sku_unsol_event;
1137 /* check the availabilities of auto-mute and auto-mic switches */
1138 static void alc_auto_check_switches(struct hda_codec *codec)
1140 alc_init_auto_hp(codec);
1141 alc_init_auto_mic(codec);
1145 * Realtek SSID verification
1148 /* Could be any non-zero and even value. When used as fixup, tells
1149 * the driver to ignore any present sku defines.
1151 #define ALC_FIXUP_SKU_IGNORE (2)
1153 static int alc_auto_parse_customize_define(struct hda_codec *codec)
1155 unsigned int ass, tmp, i;
1157 struct alc_spec *spec = codec->spec;
1159 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1161 if (spec->cdefine.fixup) {
1162 ass = spec->cdefine.sku_cfg;
1163 if (ass == ALC_FIXUP_SKU_IGNORE)
1168 ass = codec->subsystem_id & 0xffff;
1169 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
1173 if (codec->vendor_id == 0x10ec0260)
1175 ass = snd_hda_codec_get_pincfg(codec, nid);
1178 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1179 codec->chip_name, ass);
1185 for (i = 1; i < 16; i++) {
1189 if (((ass >> 16) & 0xf) != tmp)
1192 spec->cdefine.port_connectivity = ass >> 30;
1193 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1194 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1195 spec->cdefine.customization = ass >> 8;
1197 spec->cdefine.sku_cfg = ass;
1198 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1199 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1200 spec->cdefine.swap = (ass & 0x2) >> 1;
1201 spec->cdefine.override = ass & 0x1;
1203 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1204 nid, spec->cdefine.sku_cfg);
1205 snd_printd("SKU: port_connectivity=0x%x\n",
1206 spec->cdefine.port_connectivity);
1207 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1208 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1209 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1210 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1211 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1212 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1213 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1218 /* return true if the given NID is found in the list */
1219 static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1221 return find_idx_in_nid_list(nid, list, nums) >= 0;
1224 /* check subsystem ID and set up device-specific initialization;
1225 * return 1 if initialized, 0 if invalid SSID
1227 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1228 * 31 ~ 16 : Manufacture ID
1230 * 7 ~ 0 : Assembly ID
1231 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1233 static int alc_subsystem_id(struct hda_codec *codec,
1234 hda_nid_t porta, hda_nid_t porte,
1235 hda_nid_t portd, hda_nid_t porti)
1237 unsigned int ass, tmp, i;
1239 struct alc_spec *spec = codec->spec;
1241 if (spec->cdefine.fixup) {
1242 ass = spec->cdefine.sku_cfg;
1243 if (ass == ALC_FIXUP_SKU_IGNORE)
1248 ass = codec->subsystem_id & 0xffff;
1249 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1252 /* invalid SSID, check the special NID pin defcfg instead */
1254 * 31~30 : port connectivity
1257 * 19~16 : Check sum (15:1)
1262 if (codec->vendor_id == 0x10ec0260)
1264 ass = snd_hda_codec_get_pincfg(codec, nid);
1265 snd_printd("realtek: No valid SSID, "
1266 "checking pincfg 0x%08x for NID 0x%x\n",
1270 if ((ass >> 30) != 1) /* no physical connection */
1275 for (i = 1; i < 16; i++) {
1279 if (((ass >> 16) & 0xf) != tmp)
1282 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1283 ass & 0xffff, codec->vendor_id);
1287 * 2 : 0 --> Desktop, 1 --> Laptop
1288 * 3~5 : External Amplifier control
1291 tmp = (ass & 0x38) >> 3; /* external Amp control */
1294 spec->init_amp = ALC_INIT_GPIO1;
1297 spec->init_amp = ALC_INIT_GPIO2;
1300 spec->init_amp = ALC_INIT_GPIO3;
1304 spec->init_amp = ALC_INIT_DEFAULT;
1308 /* is laptop or Desktop and enable the function "Mute internal speaker
1309 * when the external headphone out jack is plugged"
1311 if (!(ass & 0x8000))
1314 * 10~8 : Jack location
1315 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1317 * 15 : 1 --> enable the function "Mute internal speaker
1318 * when the external headphone out jack is plugged"
1320 if (!spec->autocfg.hp_pins[0]) {
1322 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1333 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1334 spec->autocfg.line_outs))
1336 spec->autocfg.hp_pins[0] = nid;
1341 static void alc_ssid_check(struct hda_codec *codec,
1342 hda_nid_t porta, hda_nid_t porte,
1343 hda_nid_t portd, hda_nid_t porti)
1345 if (!alc_subsystem_id(codec, porta, porte, portd, porti)) {
1346 struct alc_spec *spec = codec->spec;
1347 snd_printd("realtek: "
1348 "Enable default setup for auto mode as fallback\n");
1349 spec->init_amp = ALC_INIT_DEFAULT;
1354 * Fix-up pin default configurations and add default verbs
1362 struct alc_model_fixup {
1373 const struct alc_pincfg *pins;
1374 const struct hda_verb *verbs;
1375 void (*func)(struct hda_codec *codec,
1376 const struct alc_fixup *fix,
1390 ALC_FIXUP_ACT_PRE_PROBE,
1391 ALC_FIXUP_ACT_PROBE,
1395 static void alc_apply_fixup(struct hda_codec *codec, int action)
1397 struct alc_spec *spec = codec->spec;
1398 int id = spec->fixup_id;
1399 #ifdef CONFIG_SND_DEBUG_VERBOSE
1400 const char *modelname = spec->fixup_name;
1404 if (!spec->fixup_list)
1408 const struct alc_fixup *fix = spec->fixup_list + id;
1409 const struct alc_pincfg *cfg;
1411 switch (fix->type) {
1413 if (action != ALC_FIXUP_ACT_PRE_PROBE || !fix->v.sku)
1415 snd_printdd(KERN_INFO "hda_codec: %s: "
1416 "Apply sku override for %s\n",
1417 codec->chip_name, modelname);
1418 spec->cdefine.sku_cfg = fix->v.sku;
1419 spec->cdefine.fixup = 1;
1421 case ALC_FIXUP_PINS:
1423 if (action != ALC_FIXUP_ACT_PRE_PROBE || !cfg)
1425 snd_printdd(KERN_INFO "hda_codec: %s: "
1426 "Apply pincfg for %s\n",
1427 codec->chip_name, modelname);
1428 for (; cfg->nid; cfg++)
1429 snd_hda_codec_set_pincfg(codec, cfg->nid,
1432 case ALC_FIXUP_VERBS:
1433 if (action != ALC_FIXUP_ACT_PROBE || !fix->v.verbs)
1435 snd_printdd(KERN_INFO "hda_codec: %s: "
1436 "Apply fix-verbs for %s\n",
1437 codec->chip_name, modelname);
1438 add_verb(codec->spec, fix->v.verbs);
1440 case ALC_FIXUP_FUNC:
1443 snd_printdd(KERN_INFO "hda_codec: %s: "
1444 "Apply fix-func for %s\n",
1445 codec->chip_name, modelname);
1446 fix->v.func(codec, fix, action);
1449 snd_printk(KERN_ERR "hda_codec: %s: "
1450 "Invalid fixup type %d\n",
1451 codec->chip_name, fix->type);
1462 static void alc_pick_fixup(struct hda_codec *codec,
1463 const struct alc_model_fixup *models,
1464 const struct snd_pci_quirk *quirk,
1465 const struct alc_fixup *fixlist)
1467 struct alc_spec *spec = codec->spec;
1469 const char *name = NULL;
1471 if (codec->modelname && models) {
1472 while (models->name) {
1473 if (!strcmp(codec->modelname, models->name)) {
1475 name = models->name;
1482 quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1485 #ifdef CONFIG_SND_DEBUG_VERBOSE
1491 spec->fixup_id = id;
1493 spec->fixup_list = fixlist;
1494 spec->fixup_name = name;
1499 * COEF access helper functions
1501 static int alc_read_coef_idx(struct hda_codec *codec,
1502 unsigned int coef_idx)
1505 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1507 val = snd_hda_codec_read(codec, 0x20, 0,
1508 AC_VERB_GET_PROC_COEF, 0);
1512 static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1513 unsigned int coef_val)
1515 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1517 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1522 * Digital I/O handling
1525 /* set right pin controls for digital I/O */
1526 static void alc_auto_init_digital(struct hda_codec *codec)
1528 struct alc_spec *spec = codec->spec;
1532 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1533 pin = spec->autocfg.dig_out_pins[i];
1536 snd_hda_codec_write(codec, pin, 0,
1537 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
1539 dac = spec->multiout.dig_out_nid;
1541 dac = spec->slave_dig_outs[i - 1];
1542 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
1544 snd_hda_codec_write(codec, dac, 0,
1545 AC_VERB_SET_AMP_GAIN_MUTE,
1548 pin = spec->autocfg.dig_in_pin;
1550 snd_hda_codec_write(codec, pin, 0,
1551 AC_VERB_SET_PIN_WIDGET_CONTROL,
1555 /* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1556 static void alc_auto_parse_digital(struct hda_codec *codec)
1558 struct alc_spec *spec = codec->spec;
1562 /* support multiple SPDIFs; the secondary is set up as a slave */
1563 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1565 err = snd_hda_get_connections(codec,
1566 spec->autocfg.dig_out_pins[i],
1567 conn, ARRAY_SIZE(conn));
1570 dig_nid = conn[0]; /* assume the first element is audio-out */
1572 spec->multiout.dig_out_nid = dig_nid;
1573 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1575 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
1576 if (i >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
1578 spec->slave_dig_outs[i - 1] = dig_nid;
1582 if (spec->autocfg.dig_in_pin) {
1583 dig_nid = codec->start_nid;
1584 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1585 unsigned int wcaps = get_wcaps(codec, dig_nid);
1586 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1588 if (!(wcaps & AC_WCAP_DIGITAL))
1590 if (!(wcaps & AC_WCAP_CONN_LIST))
1592 err = get_connection_index(codec, dig_nid,
1593 spec->autocfg.dig_in_pin);
1595 spec->dig_in_nid = dig_nid;
1603 * capture mixer elements
1605 static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1606 struct snd_ctl_elem_info *uinfo)
1608 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1609 struct alc_spec *spec = codec->spec;
1613 mutex_lock(&codec->control_mutex);
1614 if (spec->vol_in_capsrc)
1615 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1617 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1618 kcontrol->private_value = val;
1619 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
1620 mutex_unlock(&codec->control_mutex);
1624 static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1625 unsigned int size, unsigned int __user *tlv)
1627 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1628 struct alc_spec *spec = codec->spec;
1632 mutex_lock(&codec->control_mutex);
1633 if (spec->vol_in_capsrc)
1634 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1636 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1637 kcontrol->private_value = val;
1638 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
1639 mutex_unlock(&codec->control_mutex);
1643 typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1644 struct snd_ctl_elem_value *ucontrol);
1646 static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1647 struct snd_ctl_elem_value *ucontrol,
1648 getput_call_t func, bool check_adc_switch)
1650 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1651 struct alc_spec *spec = codec->spec;
1654 mutex_lock(&codec->control_mutex);
1655 if (check_adc_switch && spec->dyn_adc_switch) {
1656 for (i = 0; i < spec->num_adc_nids; i++) {
1657 kcontrol->private_value =
1658 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1660 err = func(kcontrol, ucontrol);
1665 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1666 if (spec->vol_in_capsrc)
1667 kcontrol->private_value =
1668 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1671 kcontrol->private_value =
1672 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1674 err = func(kcontrol, ucontrol);
1677 mutex_unlock(&codec->control_mutex);
1681 static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1682 struct snd_ctl_elem_value *ucontrol)
1684 return alc_cap_getput_caller(kcontrol, ucontrol,
1685 snd_hda_mixer_amp_volume_get, false);
1688 static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1689 struct snd_ctl_elem_value *ucontrol)
1691 return alc_cap_getput_caller(kcontrol, ucontrol,
1692 snd_hda_mixer_amp_volume_put, true);
1695 /* capture mixer elements */
1696 #define alc_cap_sw_info snd_ctl_boolean_stereo_info
1698 static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1699 struct snd_ctl_elem_value *ucontrol)
1701 return alc_cap_getput_caller(kcontrol, ucontrol,
1702 snd_hda_mixer_amp_switch_get, false);
1705 static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1706 struct snd_ctl_elem_value *ucontrol)
1708 return alc_cap_getput_caller(kcontrol, ucontrol,
1709 snd_hda_mixer_amp_switch_put, true);
1712 #define _DEFINE_CAPMIX(num) \
1714 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1715 .name = "Capture Switch", \
1716 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1718 .info = alc_cap_sw_info, \
1719 .get = alc_cap_sw_get, \
1720 .put = alc_cap_sw_put, \
1723 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1724 .name = "Capture Volume", \
1725 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1726 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1727 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1729 .info = alc_cap_vol_info, \
1730 .get = alc_cap_vol_get, \
1731 .put = alc_cap_vol_put, \
1732 .tlv = { .c = alc_cap_vol_tlv }, \
1735 #define _DEFINE_CAPSRC(num) \
1737 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1738 /* .name = "Capture Source", */ \
1739 .name = "Input Source", \
1741 .info = alc_mux_enum_info, \
1742 .get = alc_mux_enum_get, \
1743 .put = alc_mux_enum_put, \
1746 #define DEFINE_CAPMIX(num) \
1747 static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
1748 _DEFINE_CAPMIX(num), \
1749 _DEFINE_CAPSRC(num), \
1753 #define DEFINE_CAPMIX_NOSRC(num) \
1754 static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
1755 _DEFINE_CAPMIX(num), \
1759 /* up to three ADCs */
1763 DEFINE_CAPMIX_NOSRC(1);
1764 DEFINE_CAPMIX_NOSRC(2);
1765 DEFINE_CAPMIX_NOSRC(3);
1768 * virtual master controls
1772 * slave controls for virtual master
1774 static const char * const alc_slave_vols[] = {
1775 "Front Playback Volume",
1776 "Surround Playback Volume",
1777 "Center Playback Volume",
1778 "LFE Playback Volume",
1779 "Side Playback Volume",
1780 "Headphone Playback Volume",
1781 "Speaker Playback Volume",
1782 "Mono Playback Volume",
1783 "Line-Out Playback Volume",
1787 static const char * const alc_slave_sws[] = {
1788 "Front Playback Switch",
1789 "Surround Playback Switch",
1790 "Center Playback Switch",
1791 "LFE Playback Switch",
1792 "Side Playback Switch",
1793 "Headphone Playback Switch",
1794 "Speaker Playback Switch",
1795 "Mono Playback Switch",
1796 "IEC958 Playback Switch",
1797 "Line-Out Playback Switch",
1802 * build control elements
1805 #define NID_MAPPING (-1)
1807 #define SUBDEV_SPEAKER_ (0 << 6)
1808 #define SUBDEV_HP_ (1 << 6)
1809 #define SUBDEV_LINE_ (2 << 6)
1810 #define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1811 #define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1812 #define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1814 static void alc_free_kctls(struct hda_codec *codec);
1816 #ifdef CONFIG_SND_HDA_INPUT_BEEP
1817 /* additional beep mixers; the actual parameters are overwritten at build */
1818 static const struct snd_kcontrol_new alc_beep_mixer[] = {
1819 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
1820 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
1825 static int alc_build_controls(struct hda_codec *codec)
1827 struct alc_spec *spec = codec->spec;
1828 struct snd_kcontrol *kctl = NULL;
1829 const struct snd_kcontrol_new *knew;
1834 for (i = 0; i < spec->num_mixers; i++) {
1835 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1839 if (spec->cap_mixer) {
1840 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1844 if (spec->multiout.dig_out_nid) {
1845 err = snd_hda_create_spdif_out_ctls(codec,
1846 spec->multiout.dig_out_nid,
1847 spec->multiout.dig_out_nid);
1850 if (!spec->no_analog) {
1851 err = snd_hda_create_spdif_share_sw(codec,
1855 spec->multiout.share_spdif = 1;
1858 if (spec->dig_in_nid) {
1859 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1864 #ifdef CONFIG_SND_HDA_INPUT_BEEP
1865 /* create beep controls if needed */
1866 if (spec->beep_amp) {
1867 const struct snd_kcontrol_new *knew;
1868 for (knew = alc_beep_mixer; knew->name; knew++) {
1869 struct snd_kcontrol *kctl;
1870 kctl = snd_ctl_new1(knew, codec);
1873 kctl->private_value = spec->beep_amp;
1874 err = snd_hda_ctl_add(codec, 0, kctl);
1881 /* if we have no master control, let's create it */
1882 if (!spec->no_analog &&
1883 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1884 unsigned int vmaster_tlv[4];
1885 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
1886 HDA_OUTPUT, vmaster_tlv);
1887 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1888 vmaster_tlv, alc_slave_vols);
1892 if (!spec->no_analog &&
1893 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1894 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1895 NULL, alc_slave_sws);
1900 /* assign Capture Source enums to NID */
1901 if (spec->capsrc_nids || spec->adc_nids) {
1902 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
1904 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1905 for (i = 0; kctl && i < kctl->count; i++) {
1906 const hda_nid_t *nids = spec->capsrc_nids;
1908 nids = spec->adc_nids;
1909 err = snd_hda_add_nid(codec, kctl, i, nids[i]);
1914 if (spec->cap_mixer) {
1915 const char *kname = kctl ? kctl->id.name : NULL;
1916 for (knew = spec->cap_mixer; knew->name; knew++) {
1917 if (kname && strcmp(knew->name, kname) == 0)
1919 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1920 for (i = 0; kctl && i < kctl->count; i++) {
1921 err = snd_hda_add_nid(codec, kctl, i,
1929 /* other nid->control mapping */
1930 for (i = 0; i < spec->num_mixers; i++) {
1931 for (knew = spec->mixers[i]; knew->name; knew++) {
1932 if (knew->iface != NID_MAPPING)
1934 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1937 u = knew->subdevice;
1938 for (j = 0; j < 4; j++, u >>= 8) {
1943 case SUBDEV_SPEAKER_:
1944 nid = spec->autocfg.speaker_pins[nid];
1947 nid = spec->autocfg.line_out_pins[nid];
1950 nid = spec->autocfg.hp_pins[nid];
1955 err = snd_hda_add_nid(codec, kctl, 0, nid);
1959 u = knew->private_value;
1960 for (j = 0; j < 4; j++, u >>= 8) {
1964 err = snd_hda_add_nid(codec, kctl, 0, nid);
1971 alc_free_kctls(codec); /* no longer needed */
1981 static void alc_init_special_input_src(struct hda_codec *codec);
1983 static int alc_init(struct hda_codec *codec)
1985 struct alc_spec *spec = codec->spec;
1989 alc_auto_init_amp(codec, spec->init_amp);
1991 for (i = 0; i < spec->num_init_verbs; i++)
1992 snd_hda_sequence_write(codec, spec->init_verbs[i]);
1993 alc_init_special_input_src(codec);
1995 if (spec->init_hook)
1996 spec->init_hook(codec);
1998 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2000 hda_call_check_power_status(codec, 0x01);
2004 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2006 struct alc_spec *spec = codec->spec;
2008 if (spec->unsol_event)
2009 spec->unsol_event(codec, res);
2012 #ifdef CONFIG_SND_HDA_POWER_SAVE
2013 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2015 struct alc_spec *spec = codec->spec;
2016 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2021 * Analog playback callbacks
2023 static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
2024 struct hda_codec *codec,
2025 struct snd_pcm_substream *substream)
2027 struct alc_spec *spec = codec->spec;
2028 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2032 static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2033 struct hda_codec *codec,
2034 unsigned int stream_tag,
2035 unsigned int format,
2036 struct snd_pcm_substream *substream)
2038 struct alc_spec *spec = codec->spec;
2039 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2040 stream_tag, format, substream);
2043 static int alc_playback_pcm_cleanup(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_cleanup(codec, &spec->multiout);
2054 static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2055 struct hda_codec *codec,
2056 struct snd_pcm_substream *substream)
2058 struct alc_spec *spec = codec->spec;
2059 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2062 static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2063 struct hda_codec *codec,
2064 unsigned int stream_tag,
2065 unsigned int format,
2066 struct snd_pcm_substream *substream)
2068 struct alc_spec *spec = codec->spec;
2069 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2070 stream_tag, format, substream);
2073 static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2074 struct hda_codec *codec,
2075 struct snd_pcm_substream *substream)
2077 struct alc_spec *spec = codec->spec;
2078 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2081 static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2082 struct hda_codec *codec,
2083 struct snd_pcm_substream *substream)
2085 struct alc_spec *spec = codec->spec;
2086 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2092 static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2093 struct hda_codec *codec,
2094 unsigned int stream_tag,
2095 unsigned int format,
2096 struct snd_pcm_substream *substream)
2098 struct alc_spec *spec = codec->spec;
2100 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
2101 stream_tag, 0, format);
2105 static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2106 struct hda_codec *codec,
2107 struct snd_pcm_substream *substream)
2109 struct alc_spec *spec = codec->spec;
2111 snd_hda_codec_cleanup_stream(codec,
2112 spec->adc_nids[substream->number + 1]);
2116 /* analog capture with dynamic dual-adc changes */
2117 static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2118 struct hda_codec *codec,
2119 unsigned int stream_tag,
2120 unsigned int format,
2121 struct snd_pcm_substream *substream)
2123 struct alc_spec *spec = codec->spec;
2124 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
2125 spec->cur_adc_stream_tag = stream_tag;
2126 spec->cur_adc_format = format;
2127 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2131 static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2132 struct hda_codec *codec,
2133 struct snd_pcm_substream *substream)
2135 struct alc_spec *spec = codec->spec;
2136 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2141 static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
2145 .nid = 0, /* fill later */
2147 .prepare = dyn_adc_capture_pcm_prepare,
2148 .cleanup = dyn_adc_capture_pcm_cleanup
2154 static const struct hda_pcm_stream alc_pcm_analog_playback = {
2158 /* NID is set in alc_build_pcms */
2160 .open = alc_playback_pcm_open,
2161 .prepare = alc_playback_pcm_prepare,
2162 .cleanup = alc_playback_pcm_cleanup
2166 static const struct hda_pcm_stream alc_pcm_analog_capture = {
2170 /* NID is set in alc_build_pcms */
2173 static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
2177 /* NID is set in alc_build_pcms */
2180 static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
2181 .substreams = 2, /* can be overridden */
2184 /* NID is set in alc_build_pcms */
2186 .prepare = alc_alt_capture_pcm_prepare,
2187 .cleanup = alc_alt_capture_pcm_cleanup
2191 static const struct hda_pcm_stream alc_pcm_digital_playback = {
2195 /* NID is set in alc_build_pcms */
2197 .open = alc_dig_playback_pcm_open,
2198 .close = alc_dig_playback_pcm_close,
2199 .prepare = alc_dig_playback_pcm_prepare,
2200 .cleanup = alc_dig_playback_pcm_cleanup
2204 static const struct hda_pcm_stream alc_pcm_digital_capture = {
2208 /* NID is set in alc_build_pcms */
2211 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
2212 static const struct hda_pcm_stream alc_pcm_null_stream = {
2218 static int alc_build_pcms(struct hda_codec *codec)
2220 struct alc_spec *spec = codec->spec;
2221 struct hda_pcm *info = spec->pcm_rec;
2222 const struct hda_pcm_stream *p;
2225 codec->num_pcms = 1;
2226 codec->pcm_info = info;
2228 if (spec->no_analog)
2231 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2232 "%s Analog", codec->chip_name);
2233 info->name = spec->stream_name_analog;
2235 if (spec->multiout.dac_nids > 0) {
2236 p = spec->stream_analog_playback;
2238 p = &alc_pcm_analog_playback;
2239 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2240 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2242 if (spec->adc_nids) {
2243 p = spec->stream_analog_capture;
2245 if (spec->dyn_adc_switch)
2246 p = &dyn_adc_pcm_analog_capture;
2248 p = &alc_pcm_analog_capture;
2250 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2251 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2254 if (spec->channel_mode) {
2255 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2256 for (i = 0; i < spec->num_channel_mode; i++) {
2257 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2258 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2264 /* SPDIF for stream index #1 */
2265 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2266 snprintf(spec->stream_name_digital,
2267 sizeof(spec->stream_name_digital),
2268 "%s Digital", codec->chip_name);
2269 codec->num_pcms = 2;
2270 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
2271 info = spec->pcm_rec + 1;
2272 info->name = spec->stream_name_digital;
2273 if (spec->dig_out_type)
2274 info->pcm_type = spec->dig_out_type;
2276 info->pcm_type = HDA_PCM_TYPE_SPDIF;
2277 if (spec->multiout.dig_out_nid) {
2278 p = spec->stream_digital_playback;
2280 p = &alc_pcm_digital_playback;
2281 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2282 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2284 if (spec->dig_in_nid) {
2285 p = spec->stream_digital_capture;
2287 p = &alc_pcm_digital_capture;
2288 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2289 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2291 /* FIXME: do we need this for all Realtek codec models? */
2292 codec->spdif_status_reset = 1;
2295 if (spec->no_analog)
2298 /* If the use of more than one ADC is requested for the current
2299 * model, configure a second analog capture-only PCM.
2301 /* Additional Analaog capture for index #2 */
2302 if (spec->alt_dac_nid || spec->num_adc_nids > 1) {
2303 codec->num_pcms = 3;
2304 info = spec->pcm_rec + 2;
2305 info->name = spec->stream_name_analog;
2306 if (spec->alt_dac_nid) {
2307 p = spec->stream_analog_alt_playback;
2309 p = &alc_pcm_analog_alt_playback;
2310 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2311 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2314 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2315 alc_pcm_null_stream;
2316 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2318 if (spec->num_adc_nids > 1) {
2319 p = spec->stream_analog_alt_capture;
2321 p = &alc_pcm_analog_alt_capture;
2322 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2323 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2325 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2326 spec->num_adc_nids - 1;
2328 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2329 alc_pcm_null_stream;
2330 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
2337 static inline void alc_shutup(struct hda_codec *codec)
2339 struct alc_spec *spec = codec->spec;
2341 if (spec && spec->shutup)
2342 spec->shutup(codec);
2343 snd_hda_shutup_pins(codec);
2346 static void alc_free_kctls(struct hda_codec *codec)
2348 struct alc_spec *spec = codec->spec;
2350 if (spec->kctls.list) {
2351 struct snd_kcontrol_new *kctl = spec->kctls.list;
2353 for (i = 0; i < spec->kctls.used; i++)
2354 kfree(kctl[i].name);
2356 snd_array_free(&spec->kctls);
2359 static void alc_free(struct hda_codec *codec)
2361 struct alc_spec *spec = codec->spec;
2367 snd_hda_input_jack_free(codec);
2368 alc_free_kctls(codec);
2370 snd_hda_detach_beep_device(codec);
2373 #ifdef CONFIG_SND_HDA_POWER_SAVE
2374 static void alc_power_eapd(struct hda_codec *codec)
2376 alc_auto_setup_eapd(codec, false);
2379 static int alc_suspend(struct hda_codec *codec, pm_message_t state)
2381 struct alc_spec *spec = codec->spec;
2383 if (spec && spec->power_hook)
2384 spec->power_hook(codec);
2389 #ifdef SND_HDA_NEEDS_RESUME
2390 static int alc_resume(struct hda_codec *codec)
2392 msleep(150); /* to avoid pop noise */
2393 codec->patch_ops.init(codec);
2394 snd_hda_codec_resume_amp(codec);
2395 snd_hda_codec_resume_cache(codec);
2396 hda_call_check_power_status(codec, 0x01);
2403 static const struct hda_codec_ops alc_patch_ops = {
2404 .build_controls = alc_build_controls,
2405 .build_pcms = alc_build_pcms,
2408 .unsol_event = alc_unsol_event,
2409 #ifdef SND_HDA_NEEDS_RESUME
2410 .resume = alc_resume,
2412 #ifdef CONFIG_SND_HDA_POWER_SAVE
2413 .suspend = alc_suspend,
2414 .check_power_status = alc_check_power_status,
2416 .reboot_notify = alc_shutup,
2419 /* replace the codec chip_name with the given string */
2420 static int alc_codec_rename(struct hda_codec *codec, const char *name)
2422 kfree(codec->chip_name);
2423 codec->chip_name = kstrdup(name, GFP_KERNEL);
2424 if (!codec->chip_name) {
2432 * Automatic parse of I/O pins from the BIOS configuration
2437 ALC_CTL_WIDGET_MUTE,
2440 static const struct snd_kcontrol_new alc_control_templates[] = {
2441 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2442 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2443 HDA_BIND_MUTE(NULL, 0, 0, 0),
2446 /* add dynamic controls */
2447 static int add_control(struct alc_spec *spec, int type, const char *name,
2448 int cidx, unsigned long val)
2450 struct snd_kcontrol_new *knew;
2452 knew = alc_kcontrol_new(spec);
2455 *knew = alc_control_templates[type];
2456 knew->name = kstrdup(name, GFP_KERNEL);
2460 if (get_amp_nid_(val))
2461 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
2462 knew->private_value = val;
2466 static int add_control_with_pfx(struct alc_spec *spec, int type,
2467 const char *pfx, const char *dir,
2468 const char *sfx, int cidx, unsigned long val)
2471 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
2472 return add_control(spec, type, name, cidx, val);
2475 #define add_pb_vol_ctrl(spec, type, pfx, val) \
2476 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2477 #define add_pb_sw_ctrl(spec, type, pfx, val) \
2478 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2479 #define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2480 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2481 #define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2482 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
2484 static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2485 bool can_be_master, int *index)
2487 struct auto_pin_cfg *cfg = &spec->autocfg;
2488 static const char * const chname[4] = {
2489 "Front", "Surround", NULL /*CLFE*/, "Side"
2493 if (cfg->line_outs == 1 && !spec->multi_ios &&
2494 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
2497 switch (cfg->line_out_type) {
2498 case AUTO_PIN_SPEAKER_OUT:
2499 if (cfg->line_outs == 1)
2502 case AUTO_PIN_HP_OUT:
2503 /* for multi-io case, only the primary out */
2504 if (ch && spec->multi_ios)
2509 if (cfg->line_outs == 1 && !spec->multi_ios)
2516 /* create input playback/capture controls for the given pin */
2517 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
2518 const char *ctlname, int ctlidx,
2519 int idx, hda_nid_t mix_nid)
2523 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
2524 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2527 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
2528 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2534 static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
2536 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2537 return (pincap & AC_PINCAP_IN) != 0;
2540 /* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
2541 static int alc_auto_fill_adc_caps(struct hda_codec *codec)
2543 struct alc_spec *spec = codec->spec;
2545 hda_nid_t *adc_nids = spec->private_adc_nids;
2546 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2547 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
2548 bool indep_capsrc = false;
2551 nid = codec->start_nid;
2552 for (i = 0; i < codec->num_nodes; i++, nid++) {
2554 const hda_nid_t *list;
2555 unsigned int caps = get_wcaps(codec, nid);
2556 int type = get_wcaps_type(caps);
2558 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2560 adc_nids[nums] = nid;
2561 cap_nids[nums] = nid;
2565 type = get_wcaps_type(get_wcaps(codec, src));
2566 if (type == AC_WID_PIN)
2568 if (type == AC_WID_AUD_SEL) {
2569 cap_nids[nums] = src;
2570 indep_capsrc = true;
2573 n = snd_hda_get_conn_list(codec, src, &list);
2575 cap_nids[nums] = src;
2576 indep_capsrc = true;
2582 if (++nums >= max_nums)
2585 spec->adc_nids = spec->private_adc_nids;
2586 spec->capsrc_nids = spec->private_capsrc_nids;
2587 spec->num_adc_nids = nums;
2591 /* create playback/capture controls for input pins */
2592 static int alc_auto_create_input_ctls(struct hda_codec *codec)
2594 struct alc_spec *spec = codec->spec;
2595 const struct auto_pin_cfg *cfg = &spec->autocfg;
2596 hda_nid_t mixer = spec->mixer_nid;
2597 struct hda_input_mux *imux = &spec->private_imux[0];
2599 int i, c, err, idx, type_idx = 0;
2600 const char *prev_label = NULL;
2602 num_adcs = alc_auto_fill_adc_caps(codec);
2606 for (i = 0; i < cfg->num_inputs; i++) {
2610 pin = cfg->inputs[i].pin;
2611 if (!alc_is_input_pin(codec, pin))
2614 label = hda_get_autocfg_input_label(codec, cfg, i);
2615 if (prev_label && !strcmp(label, prev_label))
2622 idx = get_connection_index(codec, mixer, pin);
2624 err = new_analog_input(spec, pin,
2632 for (c = 0; c < num_adcs; c++) {
2633 hda_nid_t cap = spec->capsrc_nids ?
2634 spec->capsrc_nids[c] : spec->adc_nids[c];
2635 idx = get_connection_index(codec, cap, pin);
2637 spec->imux_pins[imux->num_items] = pin;
2638 snd_hda_add_imux_item(imux, label, idx, NULL);
2644 spec->num_mux_defs = 1;
2645 spec->input_mux = imux;
2650 static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
2651 unsigned int pin_type)
2653 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2656 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2657 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2661 static int get_pin_type(int line_out_type)
2663 if (line_out_type == AUTO_PIN_HP_OUT)
2669 static void alc_auto_init_analog_input(struct hda_codec *codec)
2671 struct alc_spec *spec = codec->spec;
2672 struct auto_pin_cfg *cfg = &spec->autocfg;
2675 for (i = 0; i < cfg->num_inputs; i++) {
2676 hda_nid_t nid = cfg->inputs[i].pin;
2677 if (alc_is_input_pin(codec, nid)) {
2678 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
2679 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
2680 snd_hda_codec_write(codec, nid, 0,
2681 AC_VERB_SET_AMP_GAIN_MUTE,
2686 /* mute all loopback inputs */
2687 if (spec->mixer_nid) {
2688 int nums = snd_hda_get_conn_list(codec, spec->mixer_nid, NULL);
2689 for (i = 0; i < nums; i++)
2690 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2691 AC_VERB_SET_AMP_GAIN_MUTE,
2696 /* convert from MIX nid to DAC */
2697 static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid)
2702 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT)
2704 num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list));
2705 for (i = 0; i < num; i++) {
2706 if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT)
2712 /* go down to the selector widget before the mixer */
2713 static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin)
2716 int num = snd_hda_get_connections(codec, pin, srcs,
2719 get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL)
2724 /* get MIX nid connected to the given pin targeted to DAC */
2725 static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
2731 pin = alc_go_down_to_selector(codec, pin);
2732 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2733 for (i = 0; i < num; i++) {
2734 if (alc_auto_mix_to_dac(codec, mix[i]) == dac)
2740 /* select the connection from pin to DAC if needed */
2741 static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin,
2747 pin = alc_go_down_to_selector(codec, pin);
2748 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2751 for (i = 0; i < num; i++) {
2752 if (alc_auto_mix_to_dac(codec, mix[i]) == dac) {
2753 snd_hda_codec_update_cache(codec, pin, 0,
2754 AC_VERB_SET_CONNECT_SEL, i);
2761 /* look for an empty DAC slot */
2762 static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
2764 struct alc_spec *spec = codec->spec;
2768 pin = alc_go_down_to_selector(codec, pin);
2769 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
2770 for (i = 0; i < num; i++) {
2771 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
2774 if (found_in_nid_list(nid, spec->multiout.dac_nids,
2775 spec->multiout.num_dacs))
2777 if (spec->multiout.hp_nid == nid)
2779 if (found_in_nid_list(nid, spec->multiout.extra_out_nid,
2780 ARRAY_SIZE(spec->multiout.extra_out_nid)))
2787 static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
2789 hda_nid_t sel = alc_go_down_to_selector(codec, pin);
2790 if (snd_hda_get_conn_list(codec, sel, NULL) == 1)
2791 return alc_auto_look_for_dac(codec, pin);
2795 /* fill in the dac_nids table from the parsed pin configuration */
2796 static int alc_auto_fill_dac_nids(struct hda_codec *codec)
2798 struct alc_spec *spec = codec->spec;
2799 const struct auto_pin_cfg *cfg = &spec->autocfg;
2800 bool redone = false;
2804 spec->multiout.num_dacs = 0;
2805 spec->multiout.hp_nid = 0;
2806 spec->multiout.extra_out_nid[0] = 0;
2807 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
2808 spec->multiout.dac_nids = spec->private_dac_nids;
2810 /* fill hard-wired DACs first */
2812 for (i = 0; i < cfg->line_outs; i++)
2813 spec->private_dac_nids[i] =
2814 get_dac_if_single(codec, cfg->line_out_pins[i]);
2816 spec->multiout.hp_nid =
2817 get_dac_if_single(codec, cfg->hp_pins[0]);
2818 if (cfg->speaker_outs)
2819 spec->multiout.extra_out_nid[0] =
2820 get_dac_if_single(codec, cfg->speaker_pins[0]);
2823 for (i = 0; i < cfg->line_outs; i++) {
2824 hda_nid_t pin = cfg->line_out_pins[i];
2825 if (spec->private_dac_nids[i])
2827 spec->private_dac_nids[i] = alc_auto_look_for_dac(codec, pin);
2828 if (!spec->private_dac_nids[i] && !redone) {
2829 /* if we can't find primary DACs, re-probe without
2830 * checking the hard-wired DACs
2837 for (i = 0; i < cfg->line_outs; i++) {
2838 if (spec->private_dac_nids[i])
2839 spec->multiout.num_dacs++;
2841 memmove(spec->private_dac_nids + i,
2842 spec->private_dac_nids + i + 1,
2843 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
2846 if (cfg->hp_outs && !spec->multiout.hp_nid)
2847 spec->multiout.hp_nid =
2848 alc_auto_look_for_dac(codec, cfg->hp_pins[0]);
2849 if (cfg->speaker_outs && !spec->multiout.extra_out_nid[0])
2850 spec->multiout.extra_out_nid[0] =
2851 alc_auto_look_for_dac(codec, cfg->speaker_pins[0]);
2856 static int alc_auto_add_vol_ctl(struct hda_codec *codec,
2857 const char *pfx, int cidx,
2858 hda_nid_t nid, unsigned int chs)
2862 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
2863 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
2866 #define alc_auto_add_stereo_vol(codec, pfx, cidx, nid) \
2867 alc_auto_add_vol_ctl(codec, pfx, cidx, nid, 3)
2869 /* create a mute-switch for the given mixer widget;
2870 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
2872 static int alc_auto_add_sw_ctl(struct hda_codec *codec,
2873 const char *pfx, int cidx,
2874 hda_nid_t nid, unsigned int chs)
2881 wid_type = get_wcaps_type(get_wcaps(codec, nid));
2882 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) {
2883 type = ALC_CTL_WIDGET_MUTE;
2884 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
2885 } else if (snd_hda_get_conn_list(codec, nid, NULL) == 1) {
2886 type = ALC_CTL_WIDGET_MUTE;
2887 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
2889 type = ALC_CTL_BIND_MUTE;
2890 val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
2892 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
2895 #define alc_auto_add_stereo_sw(codec, pfx, cidx, nid) \
2896 alc_auto_add_sw_ctl(codec, pfx, cidx, nid, 3)
2898 static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
2899 hda_nid_t pin, hda_nid_t dac)
2901 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
2902 if (nid_has_mute(codec, pin, HDA_OUTPUT))
2904 else if (mix && nid_has_mute(codec, mix, HDA_INPUT))
2906 else if (nid_has_mute(codec, dac, HDA_OUTPUT))
2911 static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
2912 hda_nid_t pin, hda_nid_t dac)
2914 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
2915 if (nid_has_volume(codec, dac, HDA_OUTPUT))
2917 else if (nid_has_volume(codec, mix, HDA_OUTPUT))
2919 else if (nid_has_volume(codec, pin, HDA_OUTPUT))
2924 /* add playback controls from the parsed DAC table */
2925 static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
2926 const struct auto_pin_cfg *cfg)
2928 struct alc_spec *spec = codec->spec;
2929 int i, err, noutputs;
2931 noutputs = cfg->line_outs;
2932 if (spec->multi_ios > 0)
2933 noutputs += spec->multi_ios;
2935 for (i = 0; i < noutputs; i++) {
2941 dac = spec->multiout.dac_nids[i];
2944 if (i >= cfg->line_outs)
2945 pin = spec->multi_io[i - 1].pin;
2947 pin = cfg->line_out_pins[i];
2949 sw = alc_look_for_out_mute_nid(codec, pin, dac);
2950 vol = alc_look_for_out_vol_nid(codec, pin, dac);
2951 name = alc_get_line_out_pfx(spec, i, true, &index);
2954 err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1);
2957 err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2);
2960 err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1);
2963 err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2);
2967 err = alc_auto_add_stereo_vol(codec, name, index, vol);
2970 err = alc_auto_add_stereo_sw(codec, name, index, sw);
2978 /* add playback controls for speaker and HP outputs */
2979 static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
2980 hda_nid_t dac, const char *pfx)
2982 struct alc_spec *spec = codec->spec;
2989 /* the corresponding DAC is already occupied */
2990 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
2991 return 0; /* no way */
2992 /* create a switch only */
2993 return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx,
2994 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2997 sw = alc_look_for_out_mute_nid(codec, pin, dac);
2998 vol = alc_look_for_out_vol_nid(codec, pin, dac);
2999 err = alc_auto_add_stereo_vol(codec, pfx, 0, vol);
3002 err = alc_auto_add_stereo_sw(codec, pfx, 0, sw);
3008 static int alc_auto_create_hp_out(struct hda_codec *codec)
3010 struct alc_spec *spec = codec->spec;
3011 return alc_auto_create_extra_out(codec, spec->autocfg.hp_pins[0],
3012 spec->multiout.hp_nid,
3016 static int alc_auto_create_speaker_out(struct hda_codec *codec)
3018 struct alc_spec *spec = codec->spec;
3019 return alc_auto_create_extra_out(codec, spec->autocfg.speaker_pins[0],
3020 spec->multiout.extra_out_nid[0],
3024 static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
3025 hda_nid_t pin, int pin_type,
3029 hda_nid_t nid, mix = 0;
3030 hda_nid_t srcs[HDA_MAX_CONNECTIONS];
3032 alc_set_pin_output(codec, pin, pin_type);
3033 nid = alc_go_down_to_selector(codec, pin);
3034 num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
3035 for (i = 0; i < num; i++) {
3036 if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
3044 /* need the manual connection? */
3046 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
3047 /* unmute mixer widget inputs */
3048 if (nid_has_mute(codec, mix, HDA_INPUT)) {
3049 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3051 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3054 /* initialize volume */
3055 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3057 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3061 static void alc_auto_init_multi_out(struct hda_codec *codec)
3063 struct alc_spec *spec = codec->spec;
3064 int pin_type = get_pin_type(spec->autocfg.line_out_type);
3067 for (i = 0; i <= HDA_SIDE; i++) {
3068 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3070 alc_auto_set_output_and_unmute(codec, nid, pin_type,
3071 spec->multiout.dac_nids[i]);
3075 static void alc_auto_init_extra_out(struct hda_codec *codec)
3077 struct alc_spec *spec = codec->spec;
3080 pin = spec->autocfg.hp_pins[0];
3082 alc_auto_set_output_and_unmute(codec, pin, PIN_HP,
3083 spec->multiout.hp_nid);
3084 pin = spec->autocfg.speaker_pins[0];
3086 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT,
3087 spec->multiout.extra_out_nid[0]);
3093 static int alc_auto_fill_multi_ios(struct hda_codec *codec,
3094 unsigned int location)
3096 struct alc_spec *spec = codec->spec;
3097 struct auto_pin_cfg *cfg = &spec->autocfg;
3098 int type, i, num_pins = 0;
3100 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3101 for (i = 0; i < cfg->num_inputs; i++) {
3102 hda_nid_t nid = cfg->inputs[i].pin;
3104 unsigned int defcfg, caps;
3105 if (cfg->inputs[i].type != type)
3107 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3108 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3110 if (location && get_defcfg_location(defcfg) != location)
3112 caps = snd_hda_query_pin_caps(codec, nid);
3113 if (!(caps & AC_PINCAP_OUT))
3115 dac = alc_auto_look_for_dac(codec, nid);
3118 spec->multi_io[num_pins].pin = nid;
3119 spec->multi_io[num_pins].dac = dac;
3121 spec->private_dac_nids[spec->multiout.num_dacs++] = dac;
3124 spec->multiout.num_dacs = 1;
3130 static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
3131 struct snd_ctl_elem_info *uinfo)
3133 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3134 struct alc_spec *spec = codec->spec;
3136 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3138 uinfo->value.enumerated.items = spec->multi_ios + 1;
3139 if (uinfo->value.enumerated.item > spec->multi_ios)
3140 uinfo->value.enumerated.item = spec->multi_ios;
3141 sprintf(uinfo->value.enumerated.name, "%dch",
3142 (uinfo->value.enumerated.item + 1) * 2);
3146 static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
3147 struct snd_ctl_elem_value *ucontrol)
3149 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3150 struct alc_spec *spec = codec->spec;
3151 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
3155 static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
3157 struct alc_spec *spec = codec->spec;
3158 hda_nid_t nid = spec->multi_io[idx].pin;
3160 if (!spec->multi_io[idx].ctl_in)
3161 spec->multi_io[idx].ctl_in =
3162 snd_hda_codec_read(codec, nid, 0,
3163 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3165 snd_hda_codec_update_cache(codec, nid, 0,
3166 AC_VERB_SET_PIN_WIDGET_CONTROL,
3168 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3169 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3171 alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
3173 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3174 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3175 HDA_AMP_MUTE, HDA_AMP_MUTE);
3176 snd_hda_codec_update_cache(codec, nid, 0,
3177 AC_VERB_SET_PIN_WIDGET_CONTROL,
3178 spec->multi_io[idx].ctl_in);
3183 static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
3184 struct snd_ctl_elem_value *ucontrol)
3186 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3187 struct alc_spec *spec = codec->spec;
3190 ch = ucontrol->value.enumerated.item[0];
3191 if (ch < 0 || ch > spec->multi_ios)
3193 if (ch == (spec->ext_channel_count - 1) / 2)
3195 spec->ext_channel_count = (ch + 1) * 2;
3196 for (i = 0; i < spec->multi_ios; i++)
3197 alc_set_multi_io(codec, i, i < ch);
3198 spec->multiout.max_channels = spec->ext_channel_count;
3202 static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
3203 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3204 .name = "Channel Mode",
3205 .info = alc_auto_ch_mode_info,
3206 .get = alc_auto_ch_mode_get,
3207 .put = alc_auto_ch_mode_put,
3210 static int alc_auto_add_multi_channel_mode(struct hda_codec *codec,
3211 int (*fill_dac)(struct hda_codec *))
3213 struct alc_spec *spec = codec->spec;
3214 struct auto_pin_cfg *cfg = &spec->autocfg;
3215 unsigned int location, defcfg;
3218 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT && cfg->hp_outs == 1) {
3219 /* use HP as primary out */
3220 cfg->speaker_outs = cfg->line_outs;
3221 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3222 sizeof(cfg->speaker_pins));
3223 cfg->line_outs = cfg->hp_outs;
3224 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
3226 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3227 cfg->line_out_type = AUTO_PIN_HP_OUT;
3231 if (cfg->line_outs != 1 ||
3232 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
3235 defcfg = snd_hda_codec_get_pincfg(codec, cfg->line_out_pins[0]);
3236 location = get_defcfg_location(defcfg);
3238 num_pins = alc_auto_fill_multi_ios(codec, location);
3240 struct snd_kcontrol_new *knew;
3242 knew = alc_kcontrol_new(spec);
3245 *knew = alc_auto_channel_mode_enum;
3246 knew->name = kstrdup("Channel Mode", GFP_KERNEL);
3250 spec->multi_ios = num_pins;
3251 spec->ext_channel_count = 2;
3252 spec->multiout.num_dacs = num_pins + 1;
3257 /* filter out invalid adc_nids (and capsrc_nids) that don't give all
3260 static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
3262 struct alc_spec *spec = codec->spec;
3263 const struct hda_input_mux *imux;
3264 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3265 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3268 imux = spec->input_mux;
3271 if (spec->dyn_adc_switch)
3275 for (n = 0; n < spec->num_adc_nids; n++) {
3276 hda_nid_t cap = spec->private_capsrc_nids[n];
3277 int num_conns = snd_hda_get_conn_list(codec, cap, NULL);
3278 for (i = 0; i < imux->num_items; i++) {
3279 hda_nid_t pin = spec->imux_pins[i];
3281 if (get_connection_index(codec, cap, pin) < 0)
3283 } else if (num_conns <= imux->items[i].index)
3286 if (i >= imux->num_items) {
3287 adc_nids[nums] = spec->private_adc_nids[n];
3288 capsrc_nids[nums++] = cap;
3292 /* check whether ADC-switch is possible */
3293 if (!alc_check_dyn_adc_switch(codec)) {
3294 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
3295 " using fallback 0x%x\n",
3296 codec->chip_name, spec->private_adc_nids[0]);
3297 spec->num_adc_nids = 1;
3301 } else if (nums != spec->num_adc_nids) {
3302 memcpy(spec->private_adc_nids, adc_nids,
3303 nums * sizeof(hda_nid_t));
3304 memcpy(spec->private_capsrc_nids, capsrc_nids,
3305 nums * sizeof(hda_nid_t));
3306 spec->num_adc_nids = nums;
3310 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
3311 else if (spec->input_mux->num_items == 1)
3312 spec->num_adc_nids = 1; /* reduce to a single ADC */
3316 * initialize ADC paths
3318 static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
3320 struct alc_spec *spec = codec->spec;
3323 nid = spec->adc_nids[adc_idx];
3325 if (nid_has_mute(codec, nid, HDA_INPUT)) {
3326 snd_hda_codec_write(codec, nid, 0,
3327 AC_VERB_SET_AMP_GAIN_MUTE,
3331 if (!spec->capsrc_nids)
3333 nid = spec->capsrc_nids[adc_idx];
3334 if (nid_has_mute(codec, nid, HDA_OUTPUT))
3335 snd_hda_codec_write(codec, nid, 0,
3336 AC_VERB_SET_AMP_GAIN_MUTE,
3340 static void alc_auto_init_input_src(struct hda_codec *codec)
3342 struct alc_spec *spec = codec->spec;
3345 for (c = 0; c < spec->num_adc_nids; c++)
3346 alc_auto_init_adc(codec, c);
3347 if (spec->dyn_adc_switch)
3350 nums = spec->num_adc_nids;
3351 for (c = 0; c < nums; c++)
3352 alc_mux_select(codec, 0, spec->cur_mux[c], true);
3355 /* add mic boosts if needed */
3356 static int alc_auto_add_mic_boost(struct hda_codec *codec)
3358 struct alc_spec *spec = codec->spec;
3359 struct auto_pin_cfg *cfg = &spec->autocfg;
3363 const char *prev_label = NULL;
3365 for (i = 0; i < cfg->num_inputs; i++) {
3366 if (cfg->inputs[i].type > AUTO_PIN_MIC)
3368 nid = cfg->inputs[i].pin;
3369 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
3371 char boost_label[32];
3373 label = hda_get_autocfg_input_label(codec, cfg, i);
3374 if (prev_label && !strcmp(label, prev_label))
3380 snprintf(boost_label, sizeof(boost_label),
3381 "%s Boost Volume", label);
3382 err = add_control(spec, ALC_CTL_WIDGET_VOL,
3383 boost_label, type_idx,
3384 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
3392 /* select or unmute the given capsrc route */
3393 static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
3396 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
3397 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
3399 } else if (snd_hda_get_conn_list(codec, cap, NULL) > 1) {
3400 snd_hda_codec_write_cache(codec, cap, 0,
3401 AC_VERB_SET_CONNECT_SEL, idx);
3405 /* set the default connection to that pin */
3406 static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
3408 struct alc_spec *spec = codec->spec;
3413 for (i = 0; i < spec->num_adc_nids; i++) {
3414 hda_nid_t cap = spec->capsrc_nids ?
3415 spec->capsrc_nids[i] : spec->adc_nids[i];
3418 idx = get_connection_index(codec, cap, pin);
3421 select_or_unmute_capsrc(codec, cap, idx);
3422 return i; /* return the found index */
3424 return -1; /* not found */
3427 /* initialize some special cases for input sources */
3428 static void alc_init_special_input_src(struct hda_codec *codec)
3430 struct alc_spec *spec = codec->spec;
3433 for (i = 0; i < spec->autocfg.num_inputs; i++)
3434 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
3437 /* assign appropriate capture mixers */
3438 static void set_capture_mixer(struct hda_codec *codec)
3440 struct alc_spec *spec = codec->spec;
3441 static const struct snd_kcontrol_new *caps[2][3] = {
3442 { alc_capture_mixer_nosrc1,
3443 alc_capture_mixer_nosrc2,
3444 alc_capture_mixer_nosrc3 },
3445 { alc_capture_mixer1,
3447 alc_capture_mixer3 },
3450 /* check whether either of ADC or MUX has a volume control */
3451 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
3452 if (!spec->capsrc_nids)
3453 return; /* no volume */
3454 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
3455 return; /* no volume in capsrc, too */
3456 spec->vol_in_capsrc = 1;
3459 if (spec->num_adc_nids > 0) {
3463 if (spec->input_mux && spec->input_mux->num_items > 1)
3465 if (spec->auto_mic) {
3468 } else if (spec->dyn_adc_switch)
3471 if (spec->num_adc_nids > 3)
3472 spec->num_adc_nids = 3;
3473 else if (!spec->num_adc_nids)
3475 num_adcs = spec->num_adc_nids;
3477 spec->cap_mixer = caps[mux][num_adcs - 1];
3482 * standard auto-parser initializations
3484 static void alc_auto_init_std(struct hda_codec *codec)
3486 struct alc_spec *spec = codec->spec;
3487 alc_auto_init_multi_out(codec);
3488 alc_auto_init_extra_out(codec);
3489 alc_auto_init_analog_input(codec);
3490 alc_auto_init_input_src(codec);
3491 alc_auto_init_digital(codec);
3492 if (spec->unsol_event)
3493 alc_inithook(codec);
3497 * Digital-beep handlers
3499 #ifdef CONFIG_SND_HDA_INPUT_BEEP
3500 #define set_beep_amp(spec, nid, idx, dir) \
3501 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
3503 static const struct snd_pci_quirk beep_white_list[] = {
3504 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
3505 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
3506 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
3507 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
3508 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
3512 static inline int has_cdefine_beep(struct hda_codec *codec)
3514 struct alc_spec *spec = codec->spec;
3515 const struct snd_pci_quirk *q;
3516 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
3519 return spec->cdefine.enable_pcbeep;
3522 #define set_beep_amp(spec, nid, idx, dir) /* NOP */
3523 #define has_cdefine_beep(codec) 0
3526 /* parse the BIOS configuration and set up the alc_spec */
3527 /* return 1 if successful, 0 if the proper config is not found,
3528 * or a negative error code
3530 static int alc880_parse_auto_config(struct hda_codec *codec)
3532 struct alc_spec *spec = codec->spec;
3534 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
3536 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
3540 if (!spec->autocfg.line_outs)
3541 return 0; /* can't find valid BIOS pin config */
3543 err = alc_auto_fill_dac_nids(codec);
3546 err = alc_auto_add_multi_channel_mode(codec, alc_auto_fill_dac_nids);
3549 err = alc_auto_create_multi_out_ctls(codec, &spec->autocfg);
3552 err = alc_auto_create_hp_out(codec);
3555 err = alc_auto_create_speaker_out(codec);
3558 err = alc_auto_create_input_ctls(codec);
3562 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3564 alc_auto_parse_digital(codec);
3566 if (spec->kctls.list)
3567 add_mixer(spec, spec->kctls.list);
3569 alc_remove_invalid_adc_nids(codec);
3571 alc_ssid_check(codec, 0x15, 0x1b, 0x14, 0);
3572 alc_auto_check_switches(codec);
3577 #ifdef CONFIG_SND_HDA_POWER_SAVE
3578 static const struct hda_amp_list alc880_loopbacks[] = {
3579 { 0x0b, HDA_INPUT, 0 },
3580 { 0x0b, HDA_INPUT, 1 },
3581 { 0x0b, HDA_INPUT, 2 },
3582 { 0x0b, HDA_INPUT, 3 },
3583 { 0x0b, HDA_INPUT, 4 },
3591 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3592 #define alc_board_config \
3593 snd_hda_check_board_config
3594 #define alc_board_codec_sid_config \
3595 snd_hda_check_board_codec_sid_config
3596 #include "alc_quirks.c"
3598 #define alc_board_config(codec, nums, models, tbl) -1
3599 #define alc_board_codec_sid_config(codec, nums, models, tbl) -1
3600 #define setup_preset(codec, x) /* NOP */
3604 * OK, here we have finally the patch for ALC880
3606 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3607 #include "alc880_quirks.c"
3610 static int patch_alc880(struct hda_codec *codec)
3612 struct alc_spec *spec;
3616 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3622 spec->mixer_nid = 0x0b;
3624 board_config = alc_board_config(codec, ALC880_MODEL_LAST,
3625 alc880_models, alc880_cfg_tbl);
3626 if (board_config < 0) {
3627 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
3629 board_config = ALC_MODEL_AUTO;
3632 if (board_config == ALC_MODEL_AUTO) {
3633 /* automatic parse from the BIOS config */
3634 err = alc880_parse_auto_config(codec);
3639 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3642 "hda_codec: Cannot set up configuration "
3643 "from BIOS. Using 3-stack mode...\n");
3644 board_config = ALC880_3ST;
3649 err = snd_hda_attach_beep_device(codec, 0x1);
3655 if (board_config != ALC_MODEL_AUTO)
3656 setup_preset(codec, &alc880_presets[board_config]);
3658 if (!spec->adc_nids && spec->input_mux) {
3659 alc_auto_fill_adc_caps(codec);
3660 alc_rebuild_imux_for_auto_mic(codec);
3661 alc_remove_invalid_adc_nids(codec);
3663 set_capture_mixer(codec);
3664 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
3666 spec->vmaster_nid = 0x0c;
3668 codec->patch_ops = alc_patch_ops;
3669 if (board_config == ALC_MODEL_AUTO)
3670 spec->init_hook = alc_auto_init_std;
3671 #ifdef CONFIG_SND_HDA_POWER_SAVE
3672 if (!spec->loopback.amplist)
3673 spec->loopback.amplist = alc880_loopbacks;
3684 /* convert from pin to volume-mixer widget */
3685 static hda_nid_t alc260_pin_to_vol_mix(hda_nid_t nid)
3687 if (nid >= 0x0f && nid <= 0x11)
3689 else if (nid >= 0x12 && nid <= 0x15)
3695 static int alc260_add_playback_controls(struct alc_spec *spec, hda_nid_t nid,
3696 const char *pfx, int *vol_bits)
3699 unsigned long vol_val, sw_val;
3702 nid_vol = alc260_pin_to_vol_mix(nid);
3709 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, chs, 0, HDA_OUTPUT);
3710 sw_val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3712 if (!(*vol_bits & (1 << nid_vol))) {
3713 /* first control for the volume widget */
3714 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx, vol_val);
3717 *vol_bits |= (1 << nid_vol);
3719 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, sw_val);
3725 /* add playback controls from the parsed DAC table */
3726 static int alc260_auto_create_multi_out_ctls(struct alc_spec *spec,
3727 const struct auto_pin_cfg *cfg)
3733 spec->multiout.num_dacs = 1;
3734 spec->multiout.dac_nids = spec->private_dac_nids;
3735 spec->private_dac_nids[0] = 0x02;
3737 nid = cfg->line_out_pins[0];
3741 pfx = alc_get_line_out_pfx(spec, 0, true, &index);
3742 err = alc260_add_playback_controls(spec, nid, pfx, &vols);
3747 nid = cfg->speaker_pins[0];
3749 err = alc260_add_playback_controls(spec, nid, "Speaker", &vols);
3754 nid = cfg->hp_pins[0];
3756 err = alc260_add_playback_controls(spec, nid, "Headphone",
3764 static void alc260_auto_set_output_and_unmute(struct hda_codec *codec,
3765 hda_nid_t nid, int pin_type,
3770 alc_set_pin_output(codec, nid, pin_type);
3771 /* need the manual connection? */
3773 int idx = nid - 0x12;
3774 snd_hda_codec_write(codec, idx + 0x0b, 0,
3775 AC_VERB_SET_CONNECT_SEL, sel_idx);
3778 mix = alc260_pin_to_vol_mix(nid);
3781 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3783 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3785 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3789 static void alc260_auto_init_multi_out(struct hda_codec *codec)
3791 struct alc_spec *spec = codec->spec;
3794 nid = spec->autocfg.line_out_pins[0];
3796 int pin_type = get_pin_type(spec->autocfg.line_out_type);
3797 alc260_auto_set_output_and_unmute(codec, nid, pin_type, 0);
3800 nid = spec->autocfg.speaker_pins[0];
3802 alc260_auto_set_output_and_unmute(codec, nid, PIN_OUT, 0);
3804 nid = spec->autocfg.hp_pins[0];
3806 alc260_auto_set_output_and_unmute(codec, nid, PIN_HP, 0);
3809 static int alc260_parse_auto_config(struct hda_codec *codec)
3811 struct alc_spec *spec = codec->spec;
3813 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
3815 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
3819 err = alc260_auto_create_multi_out_ctls(spec, &spec->autocfg);
3822 if (!spec->kctls.list)
3823 return 0; /* can't find valid BIOS pin config */
3824 err = alc_auto_create_input_ctls(codec);
3828 spec->multiout.max_channels = 2;
3830 alc_auto_parse_digital(codec);
3832 if (spec->kctls.list)
3833 add_mixer(spec, spec->kctls.list);
3835 alc_remove_invalid_adc_nids(codec);
3837 alc_ssid_check(codec, 0x10, 0x15, 0x0f, 0);
3838 alc_auto_check_switches(codec);
3843 /* additional initialization for auto-configuration model */
3844 static void alc260_auto_init(struct hda_codec *codec)
3846 struct alc_spec *spec = codec->spec;
3847 alc260_auto_init_multi_out(codec);
3848 alc_auto_init_analog_input(codec);
3849 alc_auto_init_input_src(codec);
3850 alc_auto_init_digital(codec);
3851 if (spec->unsol_event)
3852 alc_inithook(codec);
3855 #ifdef CONFIG_SND_HDA_POWER_SAVE
3856 static const struct hda_amp_list alc260_loopbacks[] = {
3857 { 0x07, HDA_INPUT, 0 },
3858 { 0x07, HDA_INPUT, 1 },
3859 { 0x07, HDA_INPUT, 2 },
3860 { 0x07, HDA_INPUT, 3 },
3861 { 0x07, HDA_INPUT, 4 },
3873 static const struct alc_fixup alc260_fixups[] = {
3874 [PINFIX_HP_DC5750] = {
3875 .type = ALC_FIXUP_PINS,
3876 .v.pins = (const struct alc_pincfg[]) {
3877 { 0x11, 0x90130110 }, /* speaker */
3883 static const struct snd_pci_quirk alc260_fixup_tbl[] = {
3884 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", PINFIX_HP_DC5750),
3890 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3891 #include "alc260_quirks.c"
3894 static int patch_alc260(struct hda_codec *codec)
3896 struct alc_spec *spec;
3897 int err, board_config;
3899 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3905 spec->mixer_nid = 0x07;
3907 board_config = alc_board_config(codec, ALC260_MODEL_LAST,
3908 alc260_models, alc260_cfg_tbl);
3909 if (board_config < 0) {
3910 snd_printd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
3912 board_config = ALC_MODEL_AUTO;
3915 if (board_config == ALC_MODEL_AUTO) {
3916 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
3917 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
3920 if (board_config == ALC_MODEL_AUTO) {
3921 /* automatic parse from the BIOS config */
3922 err = alc260_parse_auto_config(codec);
3927 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3930 "hda_codec: Cannot set up configuration "
3931 "from BIOS. Using base mode...\n");
3932 board_config = ALC260_BASIC;
3937 err = snd_hda_attach_beep_device(codec, 0x1);
3943 if (board_config != ALC_MODEL_AUTO)
3944 setup_preset(codec, &alc260_presets[board_config]);
3946 if (!spec->adc_nids && spec->input_mux) {
3947 alc_auto_fill_adc_caps(codec);
3948 alc_rebuild_imux_for_auto_mic(codec);
3949 alc_remove_invalid_adc_nids(codec);
3951 set_capture_mixer(codec);
3952 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
3954 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
3956 spec->vmaster_nid = 0x08;
3958 codec->patch_ops = alc_patch_ops;
3959 if (board_config == ALC_MODEL_AUTO)
3960 spec->init_hook = alc260_auto_init;
3961 spec->shutup = alc_eapd_shutup;
3962 #ifdef CONFIG_SND_HDA_POWER_SAVE
3963 if (!spec->loopback.amplist)
3964 spec->loopback.amplist = alc260_loopbacks;
3972 * ALC882/883/885/888/889 support
3974 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
3975 * configuration. Each pin widget can choose any input DACs and a mixer.
3976 * Each ADC is connected from a mixer of all inputs. This makes possible
3977 * 6-channel independent captures.
3979 * In addition, an independent DAC for the multi-playback (not used in this
3982 #ifdef CONFIG_SND_HDA_POWER_SAVE
3983 #define alc882_loopbacks alc880_loopbacks
3990 PINFIX_ABIT_AW9D_MAX,
3993 PINFIX_ACER_ASPIRE_7736,
3996 static const struct alc_fixup alc882_fixups[] = {
3997 [PINFIX_ABIT_AW9D_MAX] = {
3998 .type = ALC_FIXUP_PINS,
3999 .v.pins = (const struct alc_pincfg[]) {
4000 { 0x15, 0x01080104 }, /* side */
4001 { 0x16, 0x01011012 }, /* rear */
4002 { 0x17, 0x01016011 }, /* clfe */
4006 [PINFIX_LENOVO_Y530] = {
4007 .type = ALC_FIXUP_PINS,
4008 .v.pins = (const struct alc_pincfg[]) {
4009 { 0x15, 0x99130112 }, /* rear int speakers */
4010 { 0x16, 0x99130111 }, /* subwoofer */
4014 [PINFIX_PB_M5210] = {
4015 .type = ALC_FIXUP_VERBS,
4016 .v.verbs = (const struct hda_verb[]) {
4017 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
4021 [PINFIX_ACER_ASPIRE_7736] = {
4022 .type = ALC_FIXUP_SKU,
4023 .v.sku = ALC_FIXUP_SKU_IGNORE,
4027 static const struct snd_pci_quirk alc882_fixup_tbl[] = {
4028 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", PINFIX_PB_M5210),
4029 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", PINFIX_LENOVO_Y530),
4030 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
4031 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", PINFIX_ACER_ASPIRE_7736),
4036 * BIOS auto configuration
4038 /* almost identical with ALC880 parser... */
4039 static int alc882_parse_auto_config(struct hda_codec *codec)
4041 struct alc_spec *spec = codec->spec;
4042 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
4045 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
4049 if (!spec->autocfg.line_outs)
4050 return 0; /* can't find valid BIOS pin config */
4052 err = alc_auto_fill_dac_nids(codec);
4055 err = alc_auto_add_multi_channel_mode(codec, alc_auto_fill_dac_nids);
4058 err = alc_auto_create_multi_out_ctls(codec, &spec->autocfg);
4061 err = alc_auto_create_hp_out(codec);
4064 err = alc_auto_create_speaker_out(codec);
4067 err = alc_auto_create_input_ctls(codec);
4071 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4073 alc_auto_parse_digital(codec);
4075 if (spec->kctls.list)
4076 add_mixer(spec, spec->kctls.list);
4078 err = alc_auto_add_mic_boost(codec);
4082 alc_remove_invalid_adc_nids(codec);
4084 alc_ssid_check(codec, 0x15, 0x1b, 0x14, 0);
4085 alc_auto_check_switches(codec);
4087 return 1; /* config found */
4092 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4093 #include "alc882_quirks.c"
4096 static int patch_alc882(struct hda_codec *codec)
4098 struct alc_spec *spec;
4099 int err, board_config;
4101 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4107 spec->mixer_nid = 0x0b;
4109 switch (codec->vendor_id) {
4114 /* ALC883 and variants */
4115 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
4119 board_config = alc_board_config(codec, ALC882_MODEL_LAST,
4120 alc882_models, alc882_cfg_tbl);
4122 if (board_config < 0)
4123 board_config = alc_board_codec_sid_config(codec,
4124 ALC882_MODEL_LAST, alc882_models, alc882_ssid_cfg_tbl);
4126 if (board_config < 0) {
4127 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4129 board_config = ALC_MODEL_AUTO;
4132 if (board_config == ALC_MODEL_AUTO) {
4133 alc_pick_fixup(codec, NULL, alc882_fixup_tbl, alc882_fixups);
4134 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4137 alc_auto_parse_customize_define(codec);
4139 if (board_config == ALC_MODEL_AUTO) {
4140 /* automatic parse from the BIOS config */
4141 err = alc882_parse_auto_config(codec);
4146 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4149 "hda_codec: Cannot set up configuration "
4150 "from BIOS. Using base mode...\n");
4151 board_config = ALC882_3ST_DIG;
4156 if (has_cdefine_beep(codec)) {
4157 err = snd_hda_attach_beep_device(codec, 0x1);
4164 if (board_config != ALC_MODEL_AUTO)
4165 setup_preset(codec, &alc882_presets[board_config]);
4167 if (!spec->adc_nids && spec->input_mux) {
4168 alc_auto_fill_adc_caps(codec);
4169 alc_rebuild_imux_for_auto_mic(codec);
4170 alc_remove_invalid_adc_nids(codec);
4173 set_capture_mixer(codec);
4175 if (has_cdefine_beep(codec))
4176 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;
4200 /* We use two mixers depending on the output pin; 0x16 is a mono output
4201 * and thus it's bound with a different mixer.
4202 * This function returns which mixer amp should be used.
4204 static int alc262_check_volbit(hda_nid_t nid)
4208 else if (nid == 0x16)
4214 static int alc262_add_out_vol_ctl(struct alc_spec *spec, hda_nid_t nid,
4215 const char *pfx, int *vbits, int idx)
4220 vbit = alc262_check_volbit(nid);
4223 if (*vbits & vbit) /* a volume control for this mixer already there */
4227 val = HDA_COMPOSE_AMP_VAL(0x0e, 2, 0, HDA_OUTPUT);
4229 val = HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT);
4230 return __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx, idx, val);
4233 static int alc262_add_out_sw_ctl(struct alc_spec *spec, hda_nid_t nid,
4234 const char *pfx, int idx)
4241 val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT);
4243 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
4244 return __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, idx, val);
4247 /* add playback controls from the parsed DAC table */
4248 static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec,
4249 const struct auto_pin_cfg *cfg)
4255 spec->multiout.num_dacs = 1; /* only use one dac */
4256 spec->multiout.dac_nids = spec->private_dac_nids;
4257 spec->private_dac_nids[0] = 2;
4259 for (i = 0; i < 2; i++) {
4260 pfx = alc_get_line_out_pfx(spec, i, true, &index);
4263 err = alc262_add_out_sw_ctl(spec, cfg->line_out_pins[i], pfx,
4267 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
4268 err = alc262_add_out_sw_ctl(spec, cfg->speaker_pins[i],
4273 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
4274 err = alc262_add_out_sw_ctl(spec, cfg->hp_pins[i],
4281 vbits = alc262_check_volbit(cfg->line_out_pins[0]) |
4282 alc262_check_volbit(cfg->speaker_pins[0]) |
4283 alc262_check_volbit(cfg->hp_pins[0]);
4285 for (i = 0; i < 2; i++) {
4286 pfx = alc_get_line_out_pfx(spec, i, true, &index);
4289 err = alc262_add_out_vol_ctl(spec, cfg->line_out_pins[i], pfx,
4293 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
4294 err = alc262_add_out_vol_ctl(spec, cfg->speaker_pins[i],
4295 "Speaker", &vbits, i);
4299 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
4300 err = alc262_add_out_vol_ctl(spec, cfg->hp_pins[i],
4301 "Headphone", &vbits, i);
4310 * BIOS auto configuration
4312 static int alc262_parse_auto_config(struct hda_codec *codec)
4314 struct alc_spec *spec = codec->spec;
4316 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
4318 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
4322 if (!spec->autocfg.line_outs) {
4323 if (spec->autocfg.dig_outs || spec->autocfg.dig_in_pin) {
4324 spec->multiout.max_channels = 2;
4325 spec->no_analog = 1;
4328 return 0; /* can't find valid BIOS pin config */
4330 err = alc262_auto_create_multi_out_ctls(spec, &spec->autocfg);
4333 err = alc_auto_create_input_ctls(codec);
4337 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4340 alc_auto_parse_digital(codec);
4342 if (spec->kctls.list)
4343 add_mixer(spec, spec->kctls.list);
4345 err = alc_auto_add_mic_boost(codec);
4349 alc_remove_invalid_adc_nids(codec);
4351 alc_ssid_check(codec, 0x15, 0x1b, 0x14, 0);
4352 alc_auto_check_switches(codec);
4365 static const struct alc_fixup alc262_fixups[] = {
4366 [PINFIX_FSC_H270] = {
4367 .type = ALC_FIXUP_PINS,
4368 .v.pins = (const struct alc_pincfg[]) {
4369 { 0x14, 0x99130110 }, /* speaker */
4370 { 0x15, 0x0221142f }, /* front HP */
4371 { 0x1b, 0x0121141f }, /* rear HP */
4375 [PINFIX_HP_Z200] = {
4376 .type = ALC_FIXUP_PINS,
4377 .v.pins = (const struct alc_pincfg[]) {
4378 { 0x16, 0x99130120 }, /* internal speaker */
4384 static const struct snd_pci_quirk alc262_fixup_tbl[] = {
4385 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", PINFIX_HP_Z200),
4386 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", PINFIX_FSC_H270),
4391 #ifdef CONFIG_SND_HDA_POWER_SAVE
4392 #define alc262_loopbacks alc880_loopbacks
4397 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4398 #include "alc262_quirks.c"
4401 static int patch_alc262(struct hda_codec *codec)
4403 struct alc_spec *spec;
4407 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4413 spec->mixer_nid = 0x0b;
4416 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
4421 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4422 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
4423 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4424 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
4427 alc_auto_parse_customize_define(codec);
4429 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
4431 board_config = alc_board_config(codec, ALC262_MODEL_LAST,
4432 alc262_models, alc262_cfg_tbl);
4434 if (board_config < 0) {
4435 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4437 board_config = ALC_MODEL_AUTO;
4440 if (board_config == ALC_MODEL_AUTO) {
4441 alc_pick_fixup(codec, NULL, alc262_fixup_tbl, alc262_fixups);
4442 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4445 if (board_config == ALC_MODEL_AUTO) {
4446 /* automatic parse from the BIOS config */
4447 err = alc262_parse_auto_config(codec);
4452 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4455 "hda_codec: Cannot set up configuration "
4456 "from BIOS. Using base mode...\n");
4457 board_config = ALC262_BASIC;
4462 if (!spec->no_analog && has_cdefine_beep(codec)) {
4463 err = snd_hda_attach_beep_device(codec, 0x1);
4470 if (board_config != ALC_MODEL_AUTO)
4471 setup_preset(codec, &alc262_presets[board_config]);
4473 if (!spec->adc_nids && spec->input_mux) {
4474 alc_auto_fill_adc_caps(codec);
4475 alc_rebuild_imux_for_auto_mic(codec);
4476 alc_remove_invalid_adc_nids(codec);
4478 if (!spec->cap_mixer && !spec->no_analog)
4479 set_capture_mixer(codec);
4480 if (!spec->no_analog && has_cdefine_beep(codec))
4481 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4483 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4485 spec->vmaster_nid = 0x0c;
4487 codec->patch_ops = alc_patch_ops;
4488 if (board_config == ALC_MODEL_AUTO)
4489 spec->init_hook = alc_auto_init_std;
4490 spec->shutup = alc_eapd_shutup;
4492 alc_init_jacks(codec);
4493 #ifdef CONFIG_SND_HDA_POWER_SAVE
4494 if (!spec->loopback.amplist)
4495 spec->loopback.amplist = alc262_loopbacks;
4504 /* create input playback/capture controls for the given pin */
4505 static int alc268_new_analog_output(struct alc_spec *spec, hda_nid_t nid,
4506 const char *ctlname, int idx)
4517 case 0x1a: /* ALC259/269 only */
4518 case 0x1b: /* ALC259/269 only */
4519 case 0x21: /* ALC269vb has this pin, too */
4523 snd_printd(KERN_WARNING "hda_codec: "
4524 "ignoring pin 0x%x as unknown\n", nid);
4527 if (spec->multiout.dac_nids[0] != dac &&
4528 spec->multiout.dac_nids[1] != dac) {
4529 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname,
4530 HDA_COMPOSE_AMP_VAL(dac, 3, idx,
4534 spec->private_dac_nids[spec->multiout.num_dacs++] = dac;
4538 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname,
4539 HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_OUTPUT));
4541 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname,
4542 HDA_COMPOSE_AMP_VAL(nid, 2, idx, HDA_OUTPUT));
4548 /* add playback controls from the parsed DAC table */
4549 static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
4550 const struct auto_pin_cfg *cfg)
4555 spec->multiout.dac_nids = spec->private_dac_nids;
4557 nid = cfg->line_out_pins[0];
4561 name = alc_get_line_out_pfx(spec, 0, true, &index);
4562 err = alc268_new_analog_output(spec, nid, name, 0);
4567 nid = cfg->speaker_pins[0];
4569 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, "Speaker",
4570 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
4574 err = alc268_new_analog_output(spec, nid, "Speaker", 0);
4578 nid = cfg->hp_pins[0];
4580 err = alc268_new_analog_output(spec, nid, "Headphone", 0);
4585 nid = cfg->line_out_pins[1] | cfg->line_out_pins[2];
4587 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, "Mono",
4588 HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT));
4595 static void alc268_auto_set_output_and_unmute(struct hda_codec *codec,
4596 hda_nid_t nid, int pin_type)
4600 alc_set_pin_output(codec, nid, pin_type);
4601 if (snd_hda_get_conn_list(codec, nid, NULL) <= 1)
4603 if (nid == 0x14 || nid == 0x16)
4607 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
4610 static void alc268_auto_init_dac(struct hda_codec *codec, hda_nid_t nid)
4614 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4618 static void alc268_auto_init_multi_out(struct hda_codec *codec)
4620 struct alc_spec *spec = codec->spec;
4623 for (i = 0; i < spec->autocfg.line_outs; i++) {
4624 hda_nid_t nid = spec->autocfg.line_out_pins[i];
4625 int pin_type = get_pin_type(spec->autocfg.line_out_type);
4626 alc268_auto_set_output_and_unmute(codec, nid, pin_type);
4629 for (i = 0; i < spec->multiout.num_dacs; i++)
4630 alc268_auto_init_dac(codec, spec->multiout.dac_nids[i]);
4633 static void alc268_auto_init_hp_out(struct hda_codec *codec)
4635 struct alc_spec *spec = codec->spec;
4639 for (i = 0; i < spec->autocfg.hp_outs; i++) {
4640 pin = spec->autocfg.hp_pins[i];
4641 alc268_auto_set_output_and_unmute(codec, pin, PIN_HP);
4643 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
4644 pin = spec->autocfg.speaker_pins[i];
4645 alc268_auto_set_output_and_unmute(codec, pin, PIN_OUT);
4647 if (spec->autocfg.mono_out_pin)
4648 snd_hda_codec_write(codec, spec->autocfg.mono_out_pin, 0,
4649 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
4651 alc268_auto_init_dac(codec, spec->multiout.hp_nid);
4652 for (i = 0; i < ARRAY_SIZE(spec->multiout.extra_out_nid); i++)
4653 alc268_auto_init_dac(codec, spec->multiout.extra_out_nid[i]);
4656 static void alc268_auto_init_mono_speaker_out(struct hda_codec *codec)
4658 struct alc_spec *spec = codec->spec;
4659 hda_nid_t speaker_nid = spec->autocfg.speaker_pins[0];
4660 hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
4661 hda_nid_t line_nid = spec->autocfg.line_out_pins[0];
4662 unsigned int dac_vol1, dac_vol2;
4664 if (line_nid == 0x1d || speaker_nid == 0x1d) {
4665 snd_hda_codec_write(codec, speaker_nid, 0,
4666 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
4667 /* mute mixer inputs from 0x1d */
4668 snd_hda_codec_write(codec, 0x0f, 0,
4669 AC_VERB_SET_AMP_GAIN_MUTE,
4671 snd_hda_codec_write(codec, 0x10, 0,
4672 AC_VERB_SET_AMP_GAIN_MUTE,
4675 /* unmute mixer inputs from 0x1d */
4676 snd_hda_codec_write(codec, 0x0f, 0,
4677 AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
4678 snd_hda_codec_write(codec, 0x10, 0,
4679 AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
4682 dac_vol1 = dac_vol2 = 0xb000 | 0x40; /* set max volume */
4683 if (line_nid == 0x14)
4684 dac_vol2 = AMP_OUT_ZERO;
4685 else if (line_nid == 0x15)
4686 dac_vol1 = AMP_OUT_ZERO;
4688 dac_vol2 = AMP_OUT_ZERO;
4689 else if (hp_nid == 0x15)
4690 dac_vol1 = AMP_OUT_ZERO;
4691 if (line_nid != 0x16 || hp_nid != 0x16 ||
4692 spec->autocfg.line_out_pins[1] != 0x16 ||
4693 spec->autocfg.line_out_pins[2] != 0x16)
4694 dac_vol1 = dac_vol2 = AMP_OUT_ZERO;
4696 snd_hda_codec_write(codec, 0x02, 0,
4697 AC_VERB_SET_AMP_GAIN_MUTE, dac_vol1);
4698 snd_hda_codec_write(codec, 0x03, 0,
4699 AC_VERB_SET_AMP_GAIN_MUTE, dac_vol2);
4702 /* bind Beep switches of both NID 0x0f and 0x10 */
4703 static const struct hda_bind_ctls alc268_bind_beep_sw = {
4704 .ops = &snd_hda_bind_sw,
4706 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
4707 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
4712 static const struct snd_kcontrol_new alc268_beep_mixer[] = {
4713 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
4714 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
4718 /* set PCBEEP vol = 0, mute connections */
4719 static const struct hda_verb alc268_beep_init_verbs[] = {
4720 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4721 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4722 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4727 * BIOS auto configuration
4729 static int alc268_parse_auto_config(struct hda_codec *codec)
4731 struct alc_spec *spec = codec->spec;
4733 static const hda_nid_t alc268_ignore[] = { 0 };
4735 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
4739 if (!spec->autocfg.line_outs) {
4740 if (spec->autocfg.dig_outs || spec->autocfg.dig_in_pin) {
4741 spec->multiout.max_channels = 2;
4742 spec->no_analog = 1;
4745 return 0; /* can't find valid BIOS pin config */
4747 err = alc268_auto_create_multi_out_ctls(spec, &spec->autocfg);
4750 err = alc_auto_create_input_ctls(codec);
4754 spec->multiout.max_channels = 2;
4757 /* digital only support output */
4758 alc_auto_parse_digital(codec);
4759 if (spec->kctls.list)
4760 add_mixer(spec, spec->kctls.list);
4762 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
4763 add_mixer(spec, alc268_beep_mixer);
4764 add_verb(spec, alc268_beep_init_verbs);
4767 err = alc_auto_add_mic_boost(codec);
4771 alc_remove_invalid_adc_nids(codec);
4773 alc_ssid_check(codec, 0x15, 0x1b, 0x14, 0);
4774 alc_auto_check_switches(codec);
4779 /* init callback for auto-configuration model -- overriding the default init */
4780 static void alc268_auto_init(struct hda_codec *codec)
4782 struct alc_spec *spec = codec->spec;
4783 alc268_auto_init_multi_out(codec);
4784 alc268_auto_init_hp_out(codec);
4785 alc268_auto_init_mono_speaker_out(codec);
4786 alc_auto_init_analog_input(codec);
4787 alc_auto_init_input_src(codec);
4788 alc_auto_init_digital(codec);
4789 if (spec->unsol_event)
4790 alc_inithook(codec);
4795 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4796 #include "alc268_quirks.c"
4799 static int patch_alc268(struct hda_codec *codec)
4801 struct alc_spec *spec;
4803 int i, has_beep, err;
4805 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4811 /* ALC268 has no aa-loopback mixer */
4813 board_config = alc_board_config(codec, ALC268_MODEL_LAST,
4814 alc268_models, alc268_cfg_tbl);
4816 if (board_config < 0)
4817 board_config = alc_board_codec_sid_config(codec,
4818 ALC268_MODEL_LAST, alc268_models, alc268_ssid_cfg_tbl);
4820 if (board_config < 0) {
4821 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4823 board_config = ALC_MODEL_AUTO;
4826 if (board_config == ALC_MODEL_AUTO) {
4827 /* automatic parse from the BIOS config */
4828 err = alc268_parse_auto_config(codec);
4833 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4836 "hda_codec: Cannot set up configuration "
4837 "from BIOS. Using base mode...\n");
4838 board_config = ALC268_3ST;
4843 if (board_config != ALC_MODEL_AUTO)
4844 setup_preset(codec, &alc268_presets[board_config]);
4847 for (i = 0; i < spec->num_mixers; i++) {
4848 if (spec->mixers[i] == alc268_beep_mixer) {
4855 err = snd_hda_attach_beep_device(codec, 0x1);
4860 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
4861 /* override the amp caps for beep generator */
4862 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
4863 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
4864 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
4865 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4866 (0 << AC_AMPCAP_MUTE_SHIFT));
4869 if (!spec->no_analog && !spec->adc_nids && spec->input_mux) {
4870 alc_auto_fill_adc_caps(codec);
4871 alc_rebuild_imux_for_auto_mic(codec);
4872 alc_remove_invalid_adc_nids(codec);
4875 if (!spec->cap_mixer && !spec->no_analog)
4876 set_capture_mixer(codec);
4878 spec->vmaster_nid = 0x02;
4880 codec->patch_ops = alc_patch_ops;
4881 if (board_config == ALC_MODEL_AUTO)
4882 spec->init_hook = alc268_auto_init;
4883 spec->shutup = alc_eapd_shutup;
4885 alc_init_jacks(codec);
4893 #define alc269_auto_create_multi_out_ctls \
4894 alc268_auto_create_multi_out_ctls
4896 #ifdef CONFIG_SND_HDA_POWER_SAVE
4897 #define alc269_loopbacks alc880_loopbacks
4900 static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
4904 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
4905 /* NID is set in alc_build_pcms */
4907 .open = alc_playback_pcm_open,
4908 .prepare = alc_playback_pcm_prepare,
4909 .cleanup = alc_playback_pcm_cleanup
4913 static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
4917 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
4918 /* NID is set in alc_build_pcms */
4921 #ifdef CONFIG_SND_HDA_POWER_SAVE
4922 static int alc269_mic2_for_mute_led(struct hda_codec *codec)
4924 switch (codec->subsystem_id) {
4931 static int alc269_mic2_mute_check_ps(struct hda_codec *codec, hda_nid_t nid)
4933 /* update mute-LED according to the speaker mute state */
4934 if (nid == 0x01 || nid == 0x14) {
4936 if (snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0) &
4941 /* mic2 vref pin is used for mute LED control */
4942 snd_hda_codec_update_cache(codec, 0x19, 0,
4943 AC_VERB_SET_PIN_WIDGET_CONTROL,
4946 return alc_check_power_status(codec, nid);
4948 #endif /* CONFIG_SND_HDA_POWER_SAVE */
4950 /* different alc269-variants */
4952 ALC269_TYPE_ALC269VA,
4953 ALC269_TYPE_ALC269VB,
4954 ALC269_TYPE_ALC269VC,
4958 * BIOS auto configuration
4960 static int alc269_parse_auto_config(struct hda_codec *codec)
4962 struct alc_spec *spec = codec->spec;
4964 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
4966 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
4971 err = alc269_auto_create_multi_out_ctls(spec, &spec->autocfg);
4974 err = alc_auto_create_input_ctls(codec);
4978 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4980 alc_auto_parse_digital(codec);
4982 if (spec->kctls.list)
4983 add_mixer(spec, spec->kctls.list);
4985 alc_remove_invalid_adc_nids(codec);
4987 if (spec->codec_variant != ALC269_TYPE_ALC269VA)
4988 alc_ssid_check(codec, 0, 0x1b, 0x14, 0x21);
4990 alc_ssid_check(codec, 0x15, 0x1b, 0x14, 0);
4991 alc_auto_check_switches(codec);
4993 err = alc_auto_add_mic_boost(codec);
4997 if (!spec->cap_mixer && !spec->no_analog)
4998 set_capture_mixer(codec);
5003 #define alc269_auto_init_multi_out alc268_auto_init_multi_out
5004 #define alc269_auto_init_hp_out alc268_auto_init_hp_out
5007 /* init callback for auto-configuration model -- overriding the default init */
5008 static void alc269_auto_init(struct hda_codec *codec)
5010 struct alc_spec *spec = codec->spec;
5011 alc269_auto_init_multi_out(codec);
5012 alc269_auto_init_hp_out(codec);
5013 alc_auto_init_analog_input(codec);
5014 alc_auto_init_input_src(codec);
5015 alc_auto_init_digital(codec);
5016 if (spec->unsol_event)
5017 alc_inithook(codec);
5020 static void alc269_toggle_power_output(struct hda_codec *codec, int power_up)
5022 int val = alc_read_coef_idx(codec, 0x04);
5027 alc_write_coef_idx(codec, 0x04, val);
5030 static void alc269_shutup(struct hda_codec *codec)
5032 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x017)
5033 alc269_toggle_power_output(codec, 0);
5034 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x018) {
5035 alc269_toggle_power_output(codec, 0);
5040 #ifdef SND_HDA_NEEDS_RESUME
5041 static int alc269_resume(struct hda_codec *codec)
5043 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x018) {
5044 alc269_toggle_power_output(codec, 0);
5048 codec->patch_ops.init(codec);
5050 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x017) {
5051 alc269_toggle_power_output(codec, 1);
5055 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x018)
5056 alc269_toggle_power_output(codec, 1);
5058 snd_hda_codec_resume_amp(codec);
5059 snd_hda_codec_resume_cache(codec);
5060 hda_call_check_power_status(codec, 0x01);
5063 #endif /* SND_HDA_NEEDS_RESUME */
5065 static void alc269_fixup_hweq(struct hda_codec *codec,
5066 const struct alc_fixup *fix, int action)
5070 if (action != ALC_FIXUP_ACT_INIT)
5072 coef = alc_read_coef_idx(codec, 0x1e);
5073 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
5076 static void alc271_fixup_dmic(struct hda_codec *codec,
5077 const struct alc_fixup *fix, int action)
5079 static const struct hda_verb verbs[] = {
5080 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
5081 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
5086 if (strcmp(codec->chip_name, "ALC271X"))
5088 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
5089 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
5090 snd_hda_sequence_write(codec, verbs);
5094 ALC269_FIXUP_SONY_VAIO,
5095 ALC275_FIXUP_SONY_VAIO_GPIO2,
5096 ALC269_FIXUP_DELL_M101Z,
5097 ALC269_FIXUP_SKU_IGNORE,
5098 ALC269_FIXUP_ASUS_G73JW,
5099 ALC269_FIXUP_LENOVO_EAPD,
5100 ALC275_FIXUP_SONY_HWEQ,
5104 static const struct alc_fixup alc269_fixups[] = {
5105 [ALC269_FIXUP_SONY_VAIO] = {
5106 .type = ALC_FIXUP_VERBS,
5107 .v.verbs = (const struct hda_verb[]) {
5108 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
5112 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
5113 .type = ALC_FIXUP_VERBS,
5114 .v.verbs = (const struct hda_verb[]) {
5115 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
5116 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
5117 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5121 .chain_id = ALC269_FIXUP_SONY_VAIO
5123 [ALC269_FIXUP_DELL_M101Z] = {
5124 .type = ALC_FIXUP_VERBS,
5125 .v.verbs = (const struct hda_verb[]) {
5126 /* Enables internal speaker */
5127 {0x20, AC_VERB_SET_COEF_INDEX, 13},
5128 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
5132 [ALC269_FIXUP_SKU_IGNORE] = {
5133 .type = ALC_FIXUP_SKU,
5134 .v.sku = ALC_FIXUP_SKU_IGNORE,
5136 [ALC269_FIXUP_ASUS_G73JW] = {
5137 .type = ALC_FIXUP_PINS,
5138 .v.pins = (const struct alc_pincfg[]) {
5139 { 0x17, 0x99130111 }, /* subwoofer */
5143 [ALC269_FIXUP_LENOVO_EAPD] = {
5144 .type = ALC_FIXUP_VERBS,
5145 .v.verbs = (const struct hda_verb[]) {
5146 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
5150 [ALC275_FIXUP_SONY_HWEQ] = {
5151 .type = ALC_FIXUP_FUNC,
5152 .v.func = alc269_fixup_hweq,
5154 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
5156 [ALC271_FIXUP_DMIC] = {
5157 .type = ALC_FIXUP_FUNC,
5158 .v.func = alc271_fixup_dmic,
5162 static const struct snd_pci_quirk alc269_fixup_tbl[] = {
5163 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
5164 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
5165 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
5166 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
5167 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
5168 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
5169 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
5170 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
5171 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
5172 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
5173 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
5174 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
5175 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
5180 static int alc269_fill_coef(struct hda_codec *codec)
5184 if ((alc_read_coef_idx(codec, 0) & 0x00ff) < 0x015) {
5185 alc_write_coef_idx(codec, 0xf, 0x960b);
5186 alc_write_coef_idx(codec, 0xe, 0x8817);
5189 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x016) {
5190 alc_write_coef_idx(codec, 0xf, 0x960b);
5191 alc_write_coef_idx(codec, 0xe, 0x8814);
5194 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x017) {
5195 val = alc_read_coef_idx(codec, 0x04);
5196 /* Power up output pin */
5197 alc_write_coef_idx(codec, 0x04, val | (1<<11));
5200 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x018) {
5201 val = alc_read_coef_idx(codec, 0xd);
5202 if ((val & 0x0c00) >> 10 != 0x1) {
5203 /* Capless ramp up clock control */
5204 alc_write_coef_idx(codec, 0xd, val | (1<<10));
5206 val = alc_read_coef_idx(codec, 0x17);
5207 if ((val & 0x01c0) >> 6 != 0x4) {
5208 /* Class D power on reset */
5209 alc_write_coef_idx(codec, 0x17, val | (1<<7));
5213 val = alc_read_coef_idx(codec, 0xd); /* Class D */
5214 alc_write_coef_idx(codec, 0xd, val | (1<<14));
5216 val = alc_read_coef_idx(codec, 0x4); /* HP */
5217 alc_write_coef_idx(codec, 0x4, val | (1<<11));
5224 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
5225 #include "alc269_quirks.c"
5228 static int patch_alc269(struct hda_codec *codec)
5230 struct alc_spec *spec;
5231 int board_config, coef;
5234 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5240 spec->mixer_nid = 0x0b;
5242 alc_auto_parse_customize_define(codec);
5244 if (codec->vendor_id == 0x10ec0269) {
5245 spec->codec_variant = ALC269_TYPE_ALC269VA;
5246 coef = alc_read_coef_idx(codec, 0);
5247 if ((coef & 0x00f0) == 0x0010) {
5248 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
5249 spec->cdefine.platform_type == 1) {
5250 alc_codec_rename(codec, "ALC271X");
5251 } else if ((coef & 0xf000) == 0x2000) {
5252 alc_codec_rename(codec, "ALC259");
5253 } else if ((coef & 0xf000) == 0x3000) {
5254 alc_codec_rename(codec, "ALC258");
5255 } else if ((coef & 0xfff0) == 0x3010) {
5256 alc_codec_rename(codec, "ALC277");
5258 alc_codec_rename(codec, "ALC269VB");
5260 spec->codec_variant = ALC269_TYPE_ALC269VB;
5261 } else if ((coef & 0x00f0) == 0x0020) {
5263 alc_codec_rename(codec, "ALC259");
5264 else if (coef == 0x6023)
5265 alc_codec_rename(codec, "ALC281X");
5266 else if (codec->bus->pci->subsystem_vendor == 0x17aa &&
5267 codec->bus->pci->subsystem_device == 0x21f3)
5268 alc_codec_rename(codec, "ALC3202");
5270 alc_codec_rename(codec, "ALC269VC");
5271 spec->codec_variant = ALC269_TYPE_ALC269VC;
5273 alc_fix_pll_init(codec, 0x20, 0x04, 15);
5274 alc269_fill_coef(codec);
5277 board_config = alc_board_config(codec, ALC269_MODEL_LAST,
5278 alc269_models, alc269_cfg_tbl);
5280 if (board_config < 0) {
5281 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5283 board_config = ALC_MODEL_AUTO;
5286 if (board_config == ALC_MODEL_AUTO) {
5287 alc_pick_fixup(codec, NULL, alc269_fixup_tbl, alc269_fixups);
5288 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5291 if (board_config == ALC_MODEL_AUTO) {
5292 /* automatic parse from the BIOS config */
5293 err = alc269_parse_auto_config(codec);
5298 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
5301 "hda_codec: Cannot set up configuration "
5302 "from BIOS. Using base mode...\n");
5303 board_config = ALC269_BASIC;
5308 if (has_cdefine_beep(codec)) {
5309 err = snd_hda_attach_beep_device(codec, 0x1);
5316 if (board_config != ALC_MODEL_AUTO)
5317 setup_preset(codec, &alc269_presets[board_config]);
5320 if (board_config == ALC269_QUANTA_FL1) {
5321 /* Due to a hardware problem on Lenovo Ideadpad, we need to
5322 * fix the sample rate of analog I/O to 44.1kHz
5324 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
5325 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
5329 if (!spec->adc_nids) { /* wasn't filled automatically? use default */
5330 alc_auto_fill_adc_caps(codec);
5331 alc_rebuild_imux_for_auto_mic(codec);
5332 alc_remove_invalid_adc_nids(codec);
5335 if (!spec->cap_mixer)
5336 set_capture_mixer(codec);
5337 if (has_cdefine_beep(codec))
5338 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
5340 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5342 spec->vmaster_nid = 0x02;
5344 codec->patch_ops = alc_patch_ops;
5345 #ifdef SND_HDA_NEEDS_RESUME
5346 codec->patch_ops.resume = alc269_resume;
5348 if (board_config == ALC_MODEL_AUTO)
5349 spec->init_hook = alc269_auto_init;
5350 spec->shutup = alc269_shutup;
5352 alc_init_jacks(codec);
5353 #ifdef CONFIG_SND_HDA_POWER_SAVE
5354 if (!spec->loopback.amplist)
5355 spec->loopback.amplist = alc269_loopbacks;
5356 if (alc269_mic2_for_mute_led(codec))
5357 codec->patch_ops.check_power_status = alc269_mic2_mute_check_ps;
5367 static hda_nid_t alc861_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
5369 struct alc_spec *spec = codec->spec;
5370 hda_nid_t mix, srcs[5];
5373 if (snd_hda_get_connections(codec, pin, &mix, 1) != 1)
5375 num = snd_hda_get_connections(codec, mix, srcs, ARRAY_SIZE(srcs));
5378 for (i = 0; i < num; i++) {
5380 type = get_wcaps_type(get_wcaps(codec, srcs[i]));
5381 if (type != AC_WID_AUD_OUT)
5383 if (!found_in_nid_list(srcs[i], spec->multiout.dac_nids,
5384 spec->multiout.num_dacs))
5390 /* fill in the dac_nids table from the parsed pin configuration */
5391 static int alc861_auto_fill_dac_nids(struct hda_codec *codec)
5393 struct alc_spec *spec = codec->spec;
5394 const struct auto_pin_cfg *cfg = &spec->autocfg;
5398 spec->multiout.dac_nids = spec->private_dac_nids;
5399 for (i = 0; i < cfg->line_outs; i++) {
5400 nid = cfg->line_out_pins[i];
5401 dac = alc861_look_for_dac(codec, nid);
5404 spec->private_dac_nids[spec->multiout.num_dacs++] = dac;
5409 static int __alc861_create_out_sw(struct hda_codec *codec, const char *pfx,
5410 hda_nid_t nid, int idx, unsigned int chs)
5412 return __add_pb_sw_ctrl(codec->spec, ALC_CTL_WIDGET_MUTE, pfx, idx,
5413 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
5416 #define alc861_create_out_sw(codec, pfx, nid, chs) \
5417 __alc861_create_out_sw(codec, pfx, nid, 0, chs)
5419 /* add playback controls from the parsed DAC table */
5420 static int alc861_auto_create_multi_out_ctls(struct hda_codec *codec,
5421 const struct auto_pin_cfg *cfg)
5423 struct alc_spec *spec = codec->spec;
5425 int i, err, noutputs;
5427 noutputs = cfg->line_outs;
5428 if (spec->multi_ios > 0)
5429 noutputs += spec->multi_ios;
5431 for (i = 0; i < noutputs; i++) {
5434 nid = spec->multiout.dac_nids[i];
5437 name = alc_get_line_out_pfx(spec, i, true, &index);
5440 err = alc861_create_out_sw(codec, "Center", nid, 1);
5443 err = alc861_create_out_sw(codec, "LFE", nid, 2);
5447 err = __alc861_create_out_sw(codec, name, nid, index, 3);
5455 static int alc861_auto_create_hp_ctls(struct hda_codec *codec, hda_nid_t pin)
5457 struct alc_spec *spec = codec->spec;
5464 if ((pin >= 0x0b && pin <= 0x10) || pin == 0x1f || pin == 0x20) {
5465 nid = alc861_look_for_dac(codec, pin);
5467 err = alc861_create_out_sw(codec, "Headphone", nid, 3);
5470 spec->multiout.hp_nid = nid;
5476 static void alc861_auto_set_output_and_unmute(struct hda_codec *codec,
5478 int pin_type, hda_nid_t dac)
5480 hda_nid_t mix, srcs[5];
5483 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5485 snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
5487 if (snd_hda_get_connections(codec, nid, &mix, 1) != 1)
5489 num = snd_hda_get_connections(codec, mix, srcs, ARRAY_SIZE(srcs));
5492 for (i = 0; i < num; i++) {
5494 if (srcs[i] == dac || srcs[i] == 0x15)
5495 mute = AMP_IN_UNMUTE(i);
5497 mute = AMP_IN_MUTE(i);
5498 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
5503 static void alc861_auto_init_multi_out(struct hda_codec *codec)
5505 struct alc_spec *spec = codec->spec;
5508 for (i = 0; i < spec->autocfg.line_outs + spec->multi_ios; i++) {
5509 hda_nid_t nid = spec->autocfg.line_out_pins[i];
5510 int pin_type = get_pin_type(spec->autocfg.line_out_type);
5512 alc861_auto_set_output_and_unmute(codec, nid, pin_type,
5513 spec->multiout.dac_nids[i]);
5517 static void alc861_auto_init_hp_out(struct hda_codec *codec)
5519 struct alc_spec *spec = codec->spec;
5521 if (spec->autocfg.hp_outs)
5522 alc861_auto_set_output_and_unmute(codec,
5523 spec->autocfg.hp_pins[0],
5525 spec->multiout.hp_nid);
5526 if (spec->autocfg.speaker_outs)
5527 alc861_auto_set_output_and_unmute(codec,
5528 spec->autocfg.speaker_pins[0],
5530 spec->multiout.dac_nids[0]);
5533 /* parse the BIOS configuration and set up the alc_spec */
5534 /* return 1 if successful, 0 if the proper config is not found,
5535 * or a negative error code
5537 static int alc861_parse_auto_config(struct hda_codec *codec)
5539 struct alc_spec *spec = codec->spec;
5541 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
5543 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
5547 if (!spec->autocfg.line_outs)
5548 return 0; /* can't find valid BIOS pin config */
5550 err = alc861_auto_fill_dac_nids(codec);
5553 err = alc_auto_add_multi_channel_mode(codec, alc861_auto_fill_dac_nids);
5556 err = alc861_auto_create_multi_out_ctls(codec, &spec->autocfg);
5559 err = alc861_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
5562 err = alc_auto_create_input_ctls(codec);
5566 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5568 alc_auto_parse_digital(codec);
5570 if (spec->kctls.list)
5571 add_mixer(spec, spec->kctls.list);
5573 alc_remove_invalid_adc_nids(codec);
5575 alc_ssid_check(codec, 0x0e, 0x0f, 0x0b, 0);
5576 alc_auto_check_switches(codec);
5578 set_capture_mixer(codec);
5583 /* additional initialization for auto-configuration model */
5584 static void alc861_auto_init(struct hda_codec *codec)
5586 struct alc_spec *spec = codec->spec;
5587 alc861_auto_init_multi_out(codec);
5588 alc861_auto_init_hp_out(codec);
5589 alc_auto_init_analog_input(codec);
5590 alc_auto_init_digital(codec);
5591 if (spec->unsol_event)
5592 alc_inithook(codec);
5595 #ifdef CONFIG_SND_HDA_POWER_SAVE
5596 static const struct hda_amp_list alc861_loopbacks[] = {
5597 { 0x15, HDA_INPUT, 0 },
5598 { 0x15, HDA_INPUT, 1 },
5599 { 0x15, HDA_INPUT, 2 },
5600 { 0x15, HDA_INPUT, 3 },
5606 /* Pin config fixes */
5608 PINFIX_FSC_AMILO_PI1505,
5611 static const struct alc_fixup alc861_fixups[] = {
5612 [PINFIX_FSC_AMILO_PI1505] = {
5613 .type = ALC_FIXUP_PINS,
5614 .v.pins = (const struct alc_pincfg[]) {
5615 { 0x0b, 0x0221101f }, /* HP */
5616 { 0x0f, 0x90170310 }, /* speaker */
5622 static const struct snd_pci_quirk alc861_fixup_tbl[] = {
5623 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", PINFIX_FSC_AMILO_PI1505),
5629 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
5630 #include "alc861_quirks.c"
5633 static int patch_alc861(struct hda_codec *codec)
5635 struct alc_spec *spec;
5639 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5645 spec->mixer_nid = 0x15;
5647 board_config = alc_board_config(codec, ALC861_MODEL_LAST,
5648 alc861_models, alc861_cfg_tbl);
5650 if (board_config < 0) {
5651 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5653 board_config = ALC_MODEL_AUTO;
5656 if (board_config == ALC_MODEL_AUTO) {
5657 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
5658 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5661 if (board_config == ALC_MODEL_AUTO) {
5662 /* automatic parse from the BIOS config */
5663 err = alc861_parse_auto_config(codec);
5668 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
5671 "hda_codec: Cannot set up configuration "
5672 "from BIOS. Using base mode...\n");
5673 board_config = ALC861_3ST_DIG;
5678 err = snd_hda_attach_beep_device(codec, 0x23);
5684 if (board_config != ALC_MODEL_AUTO)
5685 setup_preset(codec, &alc861_presets[board_config]);
5687 if (!spec->adc_nids) {
5688 alc_auto_fill_adc_caps(codec);
5689 alc_rebuild_imux_for_auto_mic(codec);
5690 alc_remove_invalid_adc_nids(codec);
5693 if (!spec->cap_mixer)
5694 set_capture_mixer(codec);
5695 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
5697 spec->vmaster_nid = 0x03;
5699 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5701 codec->patch_ops = alc_patch_ops;
5702 if (board_config == ALC_MODEL_AUTO) {
5703 spec->init_hook = alc861_auto_init;
5704 #ifdef CONFIG_SND_HDA_POWER_SAVE
5705 spec->power_hook = alc_power_eapd;
5708 #ifdef CONFIG_SND_HDA_POWER_SAVE
5709 if (!spec->loopback.amplist)
5710 spec->loopback.amplist = alc861_loopbacks;
5721 * In addition, an independent DAC
5723 #ifdef CONFIG_SND_HDA_POWER_SAVE
5724 #define alc861vd_loopbacks alc880_loopbacks
5727 static int alc861vd_parse_auto_config(struct hda_codec *codec)
5729 struct alc_spec *spec = codec->spec;
5731 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
5733 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
5737 if (!spec->autocfg.line_outs)
5738 return 0; /* can't find valid BIOS pin config */
5740 err = alc_auto_fill_dac_nids(codec);
5743 err = alc_auto_add_multi_channel_mode(codec, alc_auto_fill_dac_nids);
5746 err = alc_auto_create_multi_out_ctls(codec, &spec->autocfg);
5749 err = alc_auto_create_hp_out(codec);
5752 err = alc_auto_create_speaker_out(codec);
5755 err = alc_auto_create_input_ctls(codec);
5759 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5761 alc_auto_parse_digital(codec);
5763 if (spec->kctls.list)
5764 add_mixer(spec, spec->kctls.list);
5766 alc_remove_invalid_adc_nids(codec);
5768 alc_ssid_check(codec, 0x15, 0x1b, 0x14, 0);
5769 alc_auto_check_switches(codec);
5771 err = alc_auto_add_mic_boost(codec);
5779 ALC660VD_FIX_ASUS_GPIO1
5783 static const struct alc_fixup alc861vd_fixups[] = {
5784 [ALC660VD_FIX_ASUS_GPIO1] = {
5785 .type = ALC_FIXUP_VERBS,
5786 .v.verbs = (const struct hda_verb[]) {
5787 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
5788 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5789 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5795 static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
5796 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
5800 static const struct hda_verb alc660vd_eapd_verbs[] = {
5801 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
5802 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
5808 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
5809 #include "alc861vd_quirks.c"
5812 static int patch_alc861vd(struct hda_codec *codec)
5814 struct alc_spec *spec;
5815 int err, board_config;
5817 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5823 spec->mixer_nid = 0x0b;
5825 board_config = alc_board_config(codec, ALC861VD_MODEL_LAST,
5826 alc861vd_models, alc861vd_cfg_tbl);
5828 if (board_config < 0) {
5829 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5831 board_config = ALC_MODEL_AUTO;
5834 if (board_config == ALC_MODEL_AUTO) {
5835 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
5836 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5839 if (board_config == ALC_MODEL_AUTO) {
5840 /* automatic parse from the BIOS config */
5841 err = alc861vd_parse_auto_config(codec);
5846 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
5849 "hda_codec: Cannot set up configuration "
5850 "from BIOS. Using base mode...\n");
5851 board_config = ALC861VD_3ST;
5856 err = snd_hda_attach_beep_device(codec, 0x23);
5862 if (board_config != ALC_MODEL_AUTO)
5863 setup_preset(codec, &alc861vd_presets[board_config]);
5865 if (codec->vendor_id == 0x10ec0660) {
5866 /* always turn on EAPD */
5867 add_verb(spec, alc660vd_eapd_verbs);
5870 if (!spec->adc_nids) {
5871 alc_auto_fill_adc_caps(codec);
5872 alc_rebuild_imux_for_auto_mic(codec);
5873 alc_remove_invalid_adc_nids(codec);
5876 set_capture_mixer(codec);
5877 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5879 spec->vmaster_nid = 0x02;
5881 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5883 codec->patch_ops = alc_patch_ops;
5885 if (board_config == ALC_MODEL_AUTO)
5886 spec->init_hook = alc_auto_init_std;
5887 spec->shutup = alc_eapd_shutup;
5888 #ifdef CONFIG_SND_HDA_POWER_SAVE
5889 if (!spec->loopback.amplist)
5890 spec->loopback.amplist = alc861vd_loopbacks;
5899 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
5900 * configuration. Each pin widget can choose any input DACs and a mixer.
5901 * Each ADC is connected from a mixer of all inputs. This makes possible
5902 * 6-channel independent captures.
5904 * In addition, an independent DAC for the multi-playback (not used in this
5907 #ifdef CONFIG_SND_HDA_POWER_SAVE
5908 #define alc662_loopbacks alc880_loopbacks
5912 * BIOS auto configuration
5915 static int alc662_parse_auto_config(struct hda_codec *codec)
5917 struct alc_spec *spec = codec->spec;
5919 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
5921 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
5925 if (!spec->autocfg.line_outs)
5926 return 0; /* can't find valid BIOS pin config */
5928 err = alc_auto_fill_dac_nids(codec);
5931 err = alc_auto_add_multi_channel_mode(codec, alc_auto_fill_dac_nids);
5934 err = alc_auto_create_multi_out_ctls(codec, &spec->autocfg);
5937 err = alc_auto_create_extra_out(codec,
5938 spec->autocfg.speaker_pins[0],
5939 spec->multiout.extra_out_nid[0],
5943 err = alc_auto_create_extra_out(codec, spec->autocfg.hp_pins[0],
5944 spec->multiout.hp_nid,
5948 err = alc_auto_create_input_ctls(codec);
5952 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5954 alc_auto_parse_digital(codec);
5956 if (spec->kctls.list)
5957 add_mixer(spec, spec->kctls.list);
5959 alc_remove_invalid_adc_nids(codec);
5961 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
5962 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
5963 alc_ssid_check(codec, 0x15, 0x1b, 0x14, 0x21);
5965 alc_ssid_check(codec, 0x15, 0x1b, 0x14, 0);
5966 alc_auto_check_switches(codec);
5968 err = alc_auto_add_mic_boost(codec);
5975 static void alc272_fixup_mario(struct hda_codec *codec,
5976 const struct alc_fixup *fix, int action)
5978 if (action != ALC_FIXUP_ACT_PROBE)
5980 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
5981 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
5982 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
5983 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5984 (0 << AC_AMPCAP_MUTE_SHIFT)))
5986 "hda_codec: failed to override amp caps for NID 0x2\n");
5990 ALC662_FIXUP_ASPIRE,
5991 ALC662_FIXUP_IDEAPAD,
5993 ALC662_FIXUP_CZC_P10T,
5994 ALC662_FIXUP_SKU_IGNORE,
5995 ALC662_FIXUP_HP_RP5800,
5998 static const struct alc_fixup alc662_fixups[] = {
5999 [ALC662_FIXUP_ASPIRE] = {
6000 .type = ALC_FIXUP_PINS,
6001 .v.pins = (const struct alc_pincfg[]) {
6002 { 0x15, 0x99130112 }, /* subwoofer */
6006 [ALC662_FIXUP_IDEAPAD] = {
6007 .type = ALC_FIXUP_PINS,
6008 .v.pins = (const struct alc_pincfg[]) {
6009 { 0x17, 0x99130112 }, /* subwoofer */
6013 [ALC272_FIXUP_MARIO] = {
6014 .type = ALC_FIXUP_FUNC,
6015 .v.func = alc272_fixup_mario,
6017 [ALC662_FIXUP_CZC_P10T] = {
6018 .type = ALC_FIXUP_VERBS,
6019 .v.verbs = (const struct hda_verb[]) {
6020 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6024 [ALC662_FIXUP_SKU_IGNORE] = {
6025 .type = ALC_FIXUP_SKU,
6026 .v.sku = ALC_FIXUP_SKU_IGNORE,
6028 [ALC662_FIXUP_HP_RP5800] = {
6029 .type = ALC_FIXUP_PINS,
6030 .v.pins = (const struct alc_pincfg[]) {
6031 { 0x14, 0x0221201f }, /* HP out */
6035 .chain_id = ALC662_FIXUP_SKU_IGNORE
6039 static const struct snd_pci_quirk alc662_fixup_tbl[] = {
6040 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
6041 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
6042 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
6043 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
6044 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
6045 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
6046 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
6047 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
6051 static const struct alc_model_fixup alc662_fixup_models[] = {
6052 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
6059 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
6060 #include "alc662_quirks.c"
6063 static int patch_alc662(struct hda_codec *codec)
6065 struct alc_spec *spec;
6066 int err, board_config;
6069 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6075 spec->mixer_nid = 0x0b;
6077 alc_auto_parse_customize_define(codec);
6079 alc_fix_pll_init(codec, 0x20, 0x04, 15);
6081 coef = alc_read_coef_idx(codec, 0);
6082 if (coef == 0x8020 || coef == 0x8011)
6083 alc_codec_rename(codec, "ALC661");
6084 else if (coef & (1 << 14) &&
6085 codec->bus->pci->subsystem_vendor == 0x1025 &&
6086 spec->cdefine.platform_type == 1)
6087 alc_codec_rename(codec, "ALC272X");
6088 else if (coef == 0x4011)
6089 alc_codec_rename(codec, "ALC656");
6091 board_config = alc_board_config(codec, ALC662_MODEL_LAST,
6092 alc662_models, alc662_cfg_tbl);
6093 if (board_config < 0) {
6094 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6096 board_config = ALC_MODEL_AUTO;
6099 if (board_config == ALC_MODEL_AUTO) {
6100 alc_pick_fixup(codec, alc662_fixup_models,
6101 alc662_fixup_tbl, alc662_fixups);
6102 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6103 /* automatic parse from the BIOS config */
6104 err = alc662_parse_auto_config(codec);
6109 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
6112 "hda_codec: Cannot set up configuration "
6113 "from BIOS. Using base mode...\n");
6114 board_config = ALC662_3ST_2ch_DIG;
6119 if (has_cdefine_beep(codec)) {
6120 err = snd_hda_attach_beep_device(codec, 0x1);
6127 if (board_config != ALC_MODEL_AUTO)
6128 setup_preset(codec, &alc662_presets[board_config]);
6130 if (!spec->adc_nids) {
6131 alc_auto_fill_adc_caps(codec);
6132 alc_rebuild_imux_for_auto_mic(codec);
6133 alc_remove_invalid_adc_nids(codec);
6136 if (!spec->cap_mixer)
6137 set_capture_mixer(codec);
6139 if (has_cdefine_beep(codec)) {
6140 switch (codec->vendor_id) {
6142 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6147 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
6150 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
6154 spec->vmaster_nid = 0x02;
6156 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6158 codec->patch_ops = alc_patch_ops;
6159 if (board_config == ALC_MODEL_AUTO)
6160 spec->init_hook = alc_auto_init_std;
6161 spec->shutup = alc_eapd_shutup;
6163 alc_init_jacks(codec);
6165 #ifdef CONFIG_SND_HDA_POWER_SAVE
6166 if (!spec->loopback.amplist)
6167 spec->loopback.amplist = alc662_loopbacks;
6173 static int patch_alc888(struct hda_codec *codec)
6175 if ((alc_read_coef_idx(codec, 0) & 0x00f0)==0x0030){
6176 kfree(codec->chip_name);
6177 if (codec->vendor_id == 0x10ec0887)
6178 codec->chip_name = kstrdup("ALC887-VD", GFP_KERNEL);
6180 codec->chip_name = kstrdup("ALC888-VD", GFP_KERNEL);
6181 if (!codec->chip_name) {
6185 return patch_alc662(codec);
6187 return patch_alc882(codec);
6190 static int patch_alc899(struct hda_codec *codec)
6192 if ((alc_read_coef_idx(codec, 0) & 0x2000) != 0x2000) {
6193 kfree(codec->chip_name);
6194 codec->chip_name = kstrdup("ALC898", GFP_KERNEL);
6196 return patch_alc882(codec);
6203 static int alc680_parse_auto_config(struct hda_codec *codec)
6205 struct alc_spec *spec = codec->spec;
6207 static const hda_nid_t alc680_ignore[] = { 0 };
6209 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
6214 if (!spec->autocfg.line_outs) {
6215 if (spec->autocfg.dig_outs || spec->autocfg.dig_in_pin) {
6216 spec->multiout.max_channels = 2;
6217 spec->no_analog = 1;
6220 return 0; /* can't find valid BIOS pin config */
6223 err = alc_auto_fill_dac_nids(codec);
6227 err = alc_auto_create_multi_out_ctls(codec, &spec->autocfg);
6231 err = alc_auto_create_hp_out(codec);
6235 err = alc_auto_create_speaker_out(codec);
6239 err = alc_auto_create_input_ctls(codec);
6243 spec->multiout.max_channels = 2;
6246 /* digital only support output */
6247 alc_auto_parse_digital(codec);
6248 if (spec->kctls.list)
6249 add_mixer(spec, spec->kctls.list);
6251 alc_remove_invalid_adc_nids(codec);
6253 alc_auto_check_switches(codec);
6255 err = alc_auto_add_mic_boost(codec);
6264 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
6265 #include "alc680_quirks.c"
6268 static int patch_alc680(struct hda_codec *codec)
6270 struct alc_spec *spec;
6274 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6280 /* ALC680 has no aa-loopback mixer */
6282 board_config = alc_board_config(codec, ALC680_MODEL_LAST,
6283 alc680_models, alc680_cfg_tbl);
6285 if (board_config < 0) {
6286 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6288 board_config = ALC_MODEL_AUTO;
6291 if (board_config == ALC_MODEL_AUTO) {
6292 /* automatic parse from the BIOS config */
6293 err = alc680_parse_auto_config(codec);
6298 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
6301 "hda_codec: Cannot set up configuration "
6302 "from BIOS. Using base mode...\n");
6303 board_config = ALC680_BASE;
6308 if (board_config != ALC_MODEL_AUTO) {
6309 setup_preset(codec, &alc680_presets[board_config]);
6310 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
6311 spec->stream_analog_capture = &alc680_pcm_analog_auto_capture;
6315 if (!spec->adc_nids) {
6316 alc_auto_fill_adc_caps(codec);
6317 alc_rebuild_imux_for_auto_mic(codec);
6318 alc_remove_invalid_adc_nids(codec);
6321 if (!spec->cap_mixer)
6322 set_capture_mixer(codec);
6324 spec->vmaster_nid = 0x02;
6326 codec->patch_ops = alc_patch_ops;
6327 if (board_config == ALC_MODEL_AUTO)
6328 spec->init_hook = alc_auto_init_std;
6336 static const struct hda_codec_preset snd_hda_preset_realtek[] = {
6337 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
6338 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
6339 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
6340 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
6341 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
6342 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
6343 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
6344 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
6345 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
6346 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
6347 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
6348 .patch = patch_alc861 },
6349 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
6350 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
6351 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
6352 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
6353 .patch = patch_alc882 },
6354 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
6355 .patch = patch_alc662 },
6356 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
6357 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
6358 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
6359 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
6360 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
6361 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
6362 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
6363 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
6364 .patch = patch_alc882 },
6365 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
6366 .patch = patch_alc882 },
6367 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
6368 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc888 },
6369 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
6370 .patch = patch_alc882 },
6371 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc888 },
6372 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
6373 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
6374 { .id = 0x10ec0899, .name = "ALC899", .patch = patch_alc899 },
6378 MODULE_ALIAS("snd-hda-codec-id:10ec*");
6380 MODULE_LICENSE("GPL");
6381 MODULE_DESCRIPTION("Realtek HD-audio codec");
6383 static struct hda_codec_preset_list realtek_list = {
6384 .preset = snd_hda_preset_realtek,
6385 .owner = THIS_MODULE,
6388 static int __init patch_realtek_init(void)
6390 return snd_hda_add_codec_preset(&realtek_list);
6393 static void __exit patch_realtek_exit(void)
6395 snd_hda_delete_codec_preset(&realtek_list);
6398 module_init(patch_realtek_init)
6399 module_exit(patch_realtek_exit)