2 * Universal Interface for Intel High Definition Audio Codec
4 * HD audio interface patch for Realtek ALC codecs
6 * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
7 * PeiSen Hou <pshou@realtek.com.tw>
8 * Takashi Iwai <tiwai@suse.de>
9 * Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
11 * This driver is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This driver is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include <linux/init.h>
27 #include <linux/delay.h>
28 #include <linux/slab.h>
29 #include <linux/pci.h>
30 #include <sound/core.h>
31 #include <sound/jack.h>
32 #include "hda_codec.h"
33 #include "hda_local.h"
36 /* unsol event tags */
37 #define ALC_FRONT_EVENT 0x01
38 #define ALC_DCVOL_EVENT 0x02
39 #define ALC_HP_EVENT 0x04
40 #define ALC_MIC_EVENT 0x08
43 #define GPIO_MASK 0x03
45 /* extra amp-initialization sequence types */
54 struct alc_customize_define {
56 unsigned char port_connectivity;
57 unsigned char check_sum;
58 unsigned char customization;
59 unsigned char external_amp;
60 unsigned int enable_pcbeep:1;
61 unsigned int platform_type:1;
63 unsigned int override:1;
64 unsigned int fixup:1; /* Means that this sku is set by driver, not read from hw */
70 hda_nid_t pin; /* multi-io widget pin NID */
71 hda_nid_t dac; /* DAC to be connected */
72 unsigned int ctl_in; /* cached input-pin control value */
76 ALC_AUTOMUTE_PIN, /* change the pin control */
77 ALC_AUTOMUTE_AMP, /* mute/unmute the pin AMP */
78 ALC_AUTOMUTE_MIXER, /* mute/unmute mixer widget AMP */
82 /* codec parameterization */
83 const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */
84 unsigned int num_mixers;
85 const struct snd_kcontrol_new *cap_mixer; /* capture mixer */
86 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
88 const struct hda_verb *init_verbs[10]; /* initialization verbs
92 unsigned int num_init_verbs;
94 char stream_name_analog[32]; /* analog PCM stream */
95 const struct hda_pcm_stream *stream_analog_playback;
96 const struct hda_pcm_stream *stream_analog_capture;
97 const struct hda_pcm_stream *stream_analog_alt_playback;
98 const struct hda_pcm_stream *stream_analog_alt_capture;
100 char stream_name_digital[32]; /* digital PCM stream */
101 const struct hda_pcm_stream *stream_digital_playback;
102 const struct hda_pcm_stream *stream_digital_capture;
105 struct hda_multi_out multiout; /* playback set-up
106 * max_channels, dacs must be set
107 * dig_out_nid and hp_nid are optional
109 hda_nid_t alt_dac_nid;
110 hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */
114 unsigned int num_adc_nids;
115 const hda_nid_t *adc_nids;
116 const hda_nid_t *capsrc_nids;
117 hda_nid_t dig_in_nid; /* digital-in NID; optional */
118 hda_nid_t mixer_nid; /* analog-mixer NID */
120 /* capture setup for dynamic dual-adc switch */
122 unsigned int cur_adc_stream_tag;
123 unsigned int cur_adc_format;
126 unsigned int num_mux_defs;
127 const struct hda_input_mux *input_mux;
128 unsigned int cur_mux[3];
129 hda_nid_t ext_mic_pin;
130 hda_nid_t dock_mic_pin;
131 hda_nid_t int_mic_pin;
134 const struct hda_channel_mode *channel_mode;
135 int num_channel_mode;
137 int const_channel_count;
138 int ext_channel_count;
140 /* PCM information */
141 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
143 /* dynamic controls, init_verbs and input_mux */
144 struct auto_pin_cfg autocfg;
145 struct alc_customize_define cdefine;
146 struct snd_array kctls;
147 struct hda_input_mux private_imux[3];
148 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
149 hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS];
150 hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS];
151 hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS];
152 unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS];
153 int int_mic_idx, ext_mic_idx, dock_mic_idx; /* for auto-mic */
156 void (*init_hook)(struct hda_codec *codec);
157 void (*unsol_event)(struct hda_codec *codec, unsigned int res);
158 #ifdef CONFIG_SND_HDA_POWER_SAVE
159 void (*power_hook)(struct hda_codec *codec);
161 void (*shutup)(struct hda_codec *codec);
162 void (*automute_hook)(struct hda_codec *codec);
164 /* for pin sensing */
165 unsigned int jack_present: 1;
166 unsigned int line_jack_present:1;
167 unsigned int master_mute:1;
168 unsigned int auto_mic:1;
169 unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */
170 unsigned int automute:1; /* HP automute enabled */
171 unsigned int detect_line:1; /* Line-out detection enabled */
172 unsigned int automute_lines:1; /* automute line-out as well */
173 unsigned int automute_hp_lo:1; /* both HP and LO available */
176 unsigned int no_analog :1; /* digital I/O only */
177 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
178 unsigned int single_input_src:1;
179 unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */
181 /* auto-mute control */
183 hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS];
186 int codec_variant; /* flag for other variants */
188 /* for virtual master */
189 hda_nid_t vmaster_nid;
190 #ifdef CONFIG_SND_HDA_POWER_SAVE
191 struct hda_loopback_check loopback;
196 unsigned int pll_coef_idx, pll_coef_bit;
200 const struct alc_fixup *fixup_list;
201 const char *fixup_name;
205 struct alc_multi_io multi_io[4];
208 struct snd_array bind_ctls;
211 #define ALC_MODEL_AUTO 0 /* common for all chips */
213 static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
214 int dir, unsigned int bits)
218 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
219 if (query_amp_caps(codec, nid, dir) & bits)
224 #define nid_has_mute(codec, nid, dir) \
225 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
226 #define nid_has_volume(codec, nid, dir) \
227 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
232 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
233 struct snd_ctl_elem_info *uinfo)
235 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
236 struct alc_spec *spec = codec->spec;
237 unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
238 if (mux_idx >= spec->num_mux_defs)
240 if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
242 return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
245 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
246 struct snd_ctl_elem_value *ucontrol)
248 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
249 struct alc_spec *spec = codec->spec;
250 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
252 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
256 static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
258 struct alc_spec *spec = codec->spec;
259 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
261 if (spec->cur_adc && spec->cur_adc != new_adc) {
262 /* stream is running, let's swap the current ADC */
263 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
264 spec->cur_adc = new_adc;
265 snd_hda_codec_setup_stream(codec, new_adc,
266 spec->cur_adc_stream_tag, 0,
267 spec->cur_adc_format);
273 /* select the given imux item; either unmute exclusively or select the route */
274 static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
275 unsigned int idx, bool force)
277 struct alc_spec *spec = codec->spec;
278 const struct hda_input_mux *imux;
279 unsigned int mux_idx;
283 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
284 imux = &spec->input_mux[mux_idx];
285 if (!imux->num_items && mux_idx > 0)
286 imux = &spec->input_mux[0];
288 if (idx >= imux->num_items)
289 idx = imux->num_items - 1;
290 if (spec->cur_mux[adc_idx] == idx && !force)
292 spec->cur_mux[adc_idx] = idx;
294 if (spec->dyn_adc_switch) {
295 alc_dyn_adc_pcm_resetup(codec, idx);
296 adc_idx = spec->dyn_adc_idx[idx];
299 nid = spec->capsrc_nids ?
300 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
303 if (snd_hda_get_conn_list(codec, nid, NULL) <= 1)
306 type = get_wcaps_type(get_wcaps(codec, nid));
307 if (type == AC_WID_AUD_MIX) {
308 /* Matrix-mixer style (e.g. ALC882) */
309 for (i = 0; i < imux->num_items; i++) {
310 unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
311 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
312 imux->items[i].index,
316 /* MUX style (e.g. ALC880) */
317 snd_hda_codec_write_cache(codec, nid, 0,
318 AC_VERB_SET_CONNECT_SEL,
319 imux->items[idx].index);
324 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
325 struct snd_ctl_elem_value *ucontrol)
327 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
328 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
329 return alc_mux_select(codec, adc_idx,
330 ucontrol->value.enumerated.item[0], false);
334 * set up the input pin config (depending on the given auto-pin type)
336 static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
339 unsigned int val = PIN_IN;
341 if (auto_pin_type == AUTO_PIN_MIC) {
344 oldval = snd_hda_codec_read(codec, nid, 0,
345 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
346 pincap = snd_hda_query_pin_caps(codec, nid);
347 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
348 /* if the default pin setup is vref50, we give it priority */
349 if ((pincap & AC_PINCAP_VREF_80) && oldval != PIN_VREF50)
351 else if (pincap & AC_PINCAP_VREF_50)
353 else if (pincap & AC_PINCAP_VREF_100)
355 else if (pincap & AC_PINCAP_VREF_GRD)
358 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val);
362 * Append the given mixer and verb elements for the later use
363 * The mixer array is referred in build_controls(), and init_verbs are
366 static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
368 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
370 spec->mixers[spec->num_mixers++] = mix;
373 static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
375 if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
377 spec->init_verbs[spec->num_init_verbs++] = verb;
381 * GPIO setup tables, used in initialization
383 /* Enable GPIO mask and set output */
384 static const struct hda_verb alc_gpio1_init_verbs[] = {
385 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
386 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
387 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
391 static const struct hda_verb alc_gpio2_init_verbs[] = {
392 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
393 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
394 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
398 static const struct hda_verb alc_gpio3_init_verbs[] = {
399 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
400 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
401 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
406 * Fix hardware PLL issue
407 * On some codecs, the analog PLL gating control must be off while
408 * the default value is 1.
410 static void alc_fix_pll(struct hda_codec *codec)
412 struct alc_spec *spec = codec->spec;
417 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
419 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
420 AC_VERB_GET_PROC_COEF, 0);
421 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
423 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
424 val & ~(1 << spec->pll_coef_bit));
427 static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
428 unsigned int coef_idx, unsigned int coef_bit)
430 struct alc_spec *spec = codec->spec;
432 spec->pll_coef_idx = coef_idx;
433 spec->pll_coef_bit = coef_bit;
438 * Jack-reporting via input-jack layer
441 /* initialization of jacks; currently checks only a few known pins */
442 static int alc_init_jacks(struct hda_codec *codec)
444 #ifdef CONFIG_SND_HDA_INPUT_JACK
445 struct alc_spec *spec = codec->spec;
447 unsigned int hp_nid = spec->autocfg.hp_pins[0];
448 unsigned int mic_nid = spec->ext_mic_pin;
449 unsigned int dock_nid = spec->dock_mic_pin;
452 err = snd_hda_input_jack_add(codec, hp_nid,
453 SND_JACK_HEADPHONE, NULL);
456 snd_hda_input_jack_report(codec, hp_nid);
460 err = snd_hda_input_jack_add(codec, mic_nid,
461 SND_JACK_MICROPHONE, NULL);
464 snd_hda_input_jack_report(codec, mic_nid);
467 err = snd_hda_input_jack_add(codec, dock_nid,
468 SND_JACK_MICROPHONE, NULL);
471 snd_hda_input_jack_report(codec, dock_nid);
473 #endif /* CONFIG_SND_HDA_INPUT_JACK */
478 * Jack detections for HP auto-mute and mic-switch
481 /* check each pin in the given array; returns true if any of them is plugged */
482 static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
486 for (i = 0; i < num_pins; i++) {
487 hda_nid_t nid = pins[i];
490 snd_hda_input_jack_report(codec, nid);
491 present |= snd_hda_jack_detect(codec, nid);
496 /* standard HP/line-out auto-mute helper */
497 static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
498 bool mute, bool hp_out)
500 struct alc_spec *spec = codec->spec;
501 unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0;
502 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
505 for (i = 0; i < num_pins; i++) {
506 hda_nid_t nid = pins[i];
509 switch (spec->automute_mode) {
510 case ALC_AUTOMUTE_PIN:
511 snd_hda_codec_write(codec, nid, 0,
512 AC_VERB_SET_PIN_WIDGET_CONTROL,
515 case ALC_AUTOMUTE_AMP:
516 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
517 HDA_AMP_MUTE, mute_bits);
519 case ALC_AUTOMUTE_MIXER:
520 nid = spec->automute_mixer_nid[i];
523 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
524 HDA_AMP_MUTE, mute_bits);
525 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1,
526 HDA_AMP_MUTE, mute_bits);
532 /* Toggle internal speakers muting */
533 static void update_speakers(struct hda_codec *codec)
535 struct alc_spec *spec = codec->spec;
538 /* Control HP pins/amps depending on master_mute state;
539 * in general, HP pins/amps control should be enabled in all cases,
540 * but currently set only for master_mute, just to be safe
542 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
543 spec->autocfg.hp_pins, spec->master_mute, true);
548 on = spec->jack_present | spec->line_jack_present;
549 on |= spec->master_mute;
550 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
551 spec->autocfg.speaker_pins, on, false);
553 /* toggle line-out mutes if needed, too */
554 /* if LO is a copy of either HP or Speaker, don't need to handle it */
555 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
556 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
558 if (!spec->automute_lines || !spec->automute)
561 on = spec->jack_present;
562 on |= spec->master_mute;
563 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
564 spec->autocfg.line_out_pins, on, false);
567 static void call_update_speakers(struct hda_codec *codec)
569 struct alc_spec *spec = codec->spec;
570 if (spec->automute_hook)
571 spec->automute_hook(codec);
573 update_speakers(codec);
576 /* standard HP-automute helper */
577 static void alc_hp_automute(struct hda_codec *codec)
579 struct alc_spec *spec = codec->spec;
582 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
583 spec->autocfg.hp_pins);
586 call_update_speakers(codec);
589 /* standard line-out-automute helper */
590 static void alc_line_automute(struct hda_codec *codec)
592 struct alc_spec *spec = codec->spec;
594 spec->line_jack_present =
595 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
596 spec->autocfg.line_out_pins);
597 if (!spec->automute || !spec->detect_line)
599 call_update_speakers(codec);
602 #define get_connection_index(codec, mux, nid) \
603 snd_hda_get_conn_index(codec, mux, nid, 0)
605 /* standard mic auto-switch helper */
606 static void alc_mic_automute(struct hda_codec *codec)
608 struct alc_spec *spec = codec->spec;
609 hda_nid_t *pins = spec->imux_pins;
611 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
613 if (snd_BUG_ON(!spec->adc_nids))
615 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
618 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
619 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
620 else if (spec->dock_mic_idx >= 0 &&
621 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
622 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
624 alc_mux_select(codec, 0, spec->int_mic_idx, false);
626 snd_hda_input_jack_report(codec, pins[spec->ext_mic_idx]);
627 if (spec->dock_mic_idx >= 0)
628 snd_hda_input_jack_report(codec, pins[spec->dock_mic_idx]);
631 /* unsolicited event for HP jack sensing */
632 static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
634 if (codec->vendor_id == 0x10ec0880)
640 alc_hp_automute(codec);
642 case ALC_FRONT_EVENT:
643 alc_line_automute(codec);
646 alc_mic_automute(codec);
651 /* call init functions of standard auto-mute helpers */
652 static void alc_inithook(struct hda_codec *codec)
654 alc_hp_automute(codec);
655 alc_line_automute(codec);
656 alc_mic_automute(codec);
659 /* additional initialization for ALC888 variants */
660 static void alc888_coef_init(struct hda_codec *codec)
664 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
665 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
666 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
667 if ((tmp & 0xf0) == 0x20)
669 snd_hda_codec_read(codec, 0x20, 0,
670 AC_VERB_SET_PROC_COEF, 0x830);
673 snd_hda_codec_read(codec, 0x20, 0,
674 AC_VERB_SET_PROC_COEF, 0x3030);
677 /* additional initialization for ALC889 variants */
678 static void alc889_coef_init(struct hda_codec *codec)
682 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
683 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
684 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
685 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
688 /* turn on/off EAPD control (only if available) */
689 static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
691 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
693 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
694 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
698 /* turn on/off EAPD controls of the codec */
699 static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
701 /* We currently only handle front, HP */
702 static hda_nid_t pins[] = {
703 0x0f, 0x10, 0x14, 0x15, 0
706 for (p = pins; *p; p++)
707 set_eapd(codec, *p, on);
710 /* generic shutup callback;
711 * just turning off EPAD and a little pause for avoiding pop-noise
713 static void alc_eapd_shutup(struct hda_codec *codec)
715 alc_auto_setup_eapd(codec, false);
719 /* generic EAPD initialization */
720 static void alc_auto_init_amp(struct hda_codec *codec, int type)
724 alc_auto_setup_eapd(codec, true);
727 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
730 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
733 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
735 case ALC_INIT_DEFAULT:
736 switch (codec->vendor_id) {
738 snd_hda_codec_write(codec, 0x1a, 0,
739 AC_VERB_SET_COEF_INDEX, 7);
740 tmp = snd_hda_codec_read(codec, 0x1a, 0,
741 AC_VERB_GET_PROC_COEF, 0);
742 snd_hda_codec_write(codec, 0x1a, 0,
743 AC_VERB_SET_COEF_INDEX, 7);
744 snd_hda_codec_write(codec, 0x1a, 0,
745 AC_VERB_SET_PROC_COEF,
754 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
755 alc889_coef_init(codec);
758 alc888_coef_init(codec);
760 #if 0 /* XXX: This may cause the silent output on speaker on some machines */
763 snd_hda_codec_write(codec, 0x20, 0,
764 AC_VERB_SET_COEF_INDEX, 7);
765 tmp = snd_hda_codec_read(codec, 0x20, 0,
766 AC_VERB_GET_PROC_COEF, 0);
767 snd_hda_codec_write(codec, 0x20, 0,
768 AC_VERB_SET_COEF_INDEX, 7);
769 snd_hda_codec_write(codec, 0x20, 0,
770 AC_VERB_SET_PROC_COEF,
780 * Auto-Mute mode mixer enum support
782 static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
783 struct snd_ctl_elem_info *uinfo)
785 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
786 struct alc_spec *spec = codec->spec;
787 static const char * const texts2[] = {
788 "Disabled", "Enabled"
790 static const char * const texts3[] = {
791 "Disabled", "Speaker Only", "Line-Out+Speaker"
793 const char * const *texts;
795 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
797 if (spec->automute_hp_lo) {
798 uinfo->value.enumerated.items = 3;
801 uinfo->value.enumerated.items = 2;
804 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
805 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
806 strcpy(uinfo->value.enumerated.name,
807 texts[uinfo->value.enumerated.item]);
811 static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
812 struct snd_ctl_elem_value *ucontrol)
814 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
815 struct alc_spec *spec = codec->spec;
819 else if (!spec->automute_lines)
823 ucontrol->value.enumerated.item[0] = val;
827 static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
828 struct snd_ctl_elem_value *ucontrol)
830 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
831 struct alc_spec *spec = codec->spec;
833 switch (ucontrol->value.enumerated.item[0]) {
840 if (spec->automute && !spec->automute_lines)
843 spec->automute_lines = 0;
846 if (!spec->automute_hp_lo)
848 if (spec->automute && spec->automute_lines)
851 spec->automute_lines = 1;
856 call_update_speakers(codec);
860 static const struct snd_kcontrol_new alc_automute_mode_enum = {
861 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
862 .name = "Auto-Mute Mode",
863 .info = alc_automute_mode_info,
864 .get = alc_automute_mode_get,
865 .put = alc_automute_mode_put,
868 static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec)
870 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
871 return snd_array_new(&spec->kctls);
874 static int alc_add_automute_mode_enum(struct hda_codec *codec)
876 struct alc_spec *spec = codec->spec;
877 struct snd_kcontrol_new *knew;
879 knew = alc_kcontrol_new(spec);
882 *knew = alc_automute_mode_enum;
883 knew->name = kstrdup("Auto-Mute Mode", GFP_KERNEL);
890 * Check the availability of HP/line-out auto-mute;
891 * Set up appropriately if really supported
893 static void alc_init_auto_hp(struct hda_codec *codec)
895 struct alc_spec *spec = codec->spec;
896 struct auto_pin_cfg *cfg = &spec->autocfg;
902 if (cfg->line_out_pins[0])
904 if (cfg->speaker_pins[0])
906 if (present < 2) /* need two different output types */
909 spec->automute_hp_lo = 1; /* both HP and LO automute */
911 if (!cfg->speaker_pins[0] &&
912 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
913 memcpy(cfg->speaker_pins, cfg->line_out_pins,
914 sizeof(cfg->speaker_pins));
915 cfg->speaker_outs = cfg->line_outs;
918 if (!cfg->hp_pins[0] &&
919 cfg->line_out_type == AUTO_PIN_HP_OUT) {
920 memcpy(cfg->hp_pins, cfg->line_out_pins,
921 sizeof(cfg->hp_pins));
922 cfg->hp_outs = cfg->line_outs;
925 for (i = 0; i < cfg->hp_outs; i++) {
926 hda_nid_t nid = cfg->hp_pins[i];
927 if (!is_jack_detectable(codec, nid))
929 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
931 snd_hda_codec_write_cache(codec, nid, 0,
932 AC_VERB_SET_UNSOLICITED_ENABLE,
933 AC_USRSP_EN | ALC_HP_EVENT);
935 spec->automute_mode = ALC_AUTOMUTE_PIN;
937 if (spec->automute && cfg->line_out_pins[0] &&
938 cfg->speaker_pins[0] &&
939 cfg->line_out_pins[0] != cfg->hp_pins[0] &&
940 cfg->line_out_pins[0] != cfg->speaker_pins[0]) {
941 for (i = 0; i < cfg->line_outs; i++) {
942 hda_nid_t nid = cfg->line_out_pins[i];
943 if (!is_jack_detectable(codec, nid))
945 snd_printdd("realtek: Enable Line-Out auto-muting "
946 "on NID 0x%x\n", nid);
947 snd_hda_codec_write_cache(codec, nid, 0,
948 AC_VERB_SET_UNSOLICITED_ENABLE,
949 AC_USRSP_EN | ALC_FRONT_EVENT);
950 spec->detect_line = 1;
952 spec->automute_lines = spec->detect_line;
955 if (spec->automute) {
956 /* create a control for automute mode */
957 alc_add_automute_mode_enum(codec);
958 spec->unsol_event = alc_sku_unsol_event;
962 /* return the position of NID in the list, or -1 if not found */
963 static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
966 for (i = 0; i < nums; i++)
972 /* check whether dynamic ADC-switching is available */
973 static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
975 struct alc_spec *spec = codec->spec;
976 struct hda_input_mux *imux = &spec->private_imux[0];
980 if (imux != spec->input_mux) /* no dynamic imux? */
983 for (n = 0; n < spec->num_adc_nids; n++) {
984 cap = spec->private_capsrc_nids[n];
985 for (i = 0; i < imux->num_items; i++) {
986 pin = spec->imux_pins[i];
989 if (get_connection_index(codec, cap, pin) < 0)
992 if (i >= imux->num_items)
993 return true; /* no ADC-switch is needed */
996 for (i = 0; i < imux->num_items; i++) {
997 pin = spec->imux_pins[i];
998 for (n = 0; n < spec->num_adc_nids; n++) {
999 cap = spec->private_capsrc_nids[n];
1000 idx = get_connection_index(codec, cap, pin);
1002 imux->items[i].index = idx;
1003 spec->dyn_adc_idx[i] = n;
1009 snd_printdd("realtek: enabling ADC switching\n");
1010 spec->dyn_adc_switch = 1;
1014 /* rebuild imux for matching with the given auto-mic pins (if not yet) */
1015 static bool alc_rebuild_imux_for_auto_mic(struct hda_codec *codec)
1017 struct alc_spec *spec = codec->spec;
1018 struct hda_input_mux *imux;
1019 static char * const texts[3] = {
1020 "Mic", "Internal Mic", "Dock Mic"
1024 if (!spec->auto_mic)
1026 imux = &spec->private_imux[0];
1027 if (spec->input_mux == imux)
1029 spec->imux_pins[0] = spec->ext_mic_pin;
1030 spec->imux_pins[1] = spec->int_mic_pin;
1031 spec->imux_pins[2] = spec->dock_mic_pin;
1032 for (i = 0; i < 3; i++) {
1033 strcpy(imux->items[i].label, texts[i]);
1034 if (spec->imux_pins[i])
1035 imux->num_items = i + 1;
1037 spec->num_mux_defs = 1;
1038 spec->input_mux = imux;
1042 /* check whether all auto-mic pins are valid; setup indices if OK */
1043 static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1045 struct alc_spec *spec = codec->spec;
1046 const struct hda_input_mux *imux;
1048 if (!spec->auto_mic)
1050 if (spec->auto_mic_valid_imux)
1051 return true; /* already checked */
1053 /* fill up imux indices */
1054 if (!alc_check_dyn_adc_switch(codec)) {
1059 imux = spec->input_mux;
1060 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1061 spec->imux_pins, imux->num_items);
1062 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1063 spec->imux_pins, imux->num_items);
1064 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1065 spec->imux_pins, imux->num_items);
1066 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1068 return false; /* no corresponding imux */
1071 snd_hda_codec_write_cache(codec, spec->ext_mic_pin, 0,
1072 AC_VERB_SET_UNSOLICITED_ENABLE,
1073 AC_USRSP_EN | ALC_MIC_EVENT);
1074 if (spec->dock_mic_pin)
1075 snd_hda_codec_write_cache(codec, spec->dock_mic_pin, 0,
1076 AC_VERB_SET_UNSOLICITED_ENABLE,
1077 AC_USRSP_EN | ALC_MIC_EVENT);
1079 spec->auto_mic_valid_imux = 1;
1085 * Check the availability of auto-mic switch;
1086 * Set up if really supported
1088 static void alc_init_auto_mic(struct hda_codec *codec)
1090 struct alc_spec *spec = codec->spec;
1091 struct auto_pin_cfg *cfg = &spec->autocfg;
1092 hda_nid_t fixed, ext, dock;
1095 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1097 fixed = ext = dock = 0;
1098 for (i = 0; i < cfg->num_inputs; i++) {
1099 hda_nid_t nid = cfg->inputs[i].pin;
1100 unsigned int defcfg;
1101 defcfg = snd_hda_codec_get_pincfg(codec, nid);
1102 switch (snd_hda_get_input_pin_attr(defcfg)) {
1103 case INPUT_PIN_ATTR_INT:
1105 return; /* already occupied */
1106 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1107 return; /* invalid type */
1110 case INPUT_PIN_ATTR_UNUSED:
1111 return; /* invalid entry */
1112 case INPUT_PIN_ATTR_DOCK:
1114 return; /* already occupied */
1115 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1116 return; /* invalid type */
1121 return; /* already occupied */
1122 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1123 return; /* invalid type */
1134 if (!is_jack_detectable(codec, ext))
1135 return; /* no unsol support */
1136 if (dock && !is_jack_detectable(codec, dock))
1137 return; /* no unsol support */
1139 /* check imux indices */
1140 spec->ext_mic_pin = ext;
1141 spec->int_mic_pin = fixed;
1142 spec->dock_mic_pin = dock;
1145 if (!alc_auto_mic_check_imux(codec))
1148 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1150 spec->unsol_event = alc_sku_unsol_event;
1153 /* check the availabilities of auto-mute and auto-mic switches */
1154 static void alc_auto_check_switches(struct hda_codec *codec)
1156 alc_init_auto_hp(codec);
1157 alc_init_auto_mic(codec);
1161 * Realtek SSID verification
1164 /* Could be any non-zero and even value. When used as fixup, tells
1165 * the driver to ignore any present sku defines.
1167 #define ALC_FIXUP_SKU_IGNORE (2)
1169 static int alc_auto_parse_customize_define(struct hda_codec *codec)
1171 unsigned int ass, tmp, i;
1173 struct alc_spec *spec = codec->spec;
1175 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1177 if (spec->cdefine.fixup) {
1178 ass = spec->cdefine.sku_cfg;
1179 if (ass == ALC_FIXUP_SKU_IGNORE)
1184 ass = codec->subsystem_id & 0xffff;
1185 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
1189 if (codec->vendor_id == 0x10ec0260)
1191 ass = snd_hda_codec_get_pincfg(codec, nid);
1194 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1195 codec->chip_name, ass);
1201 for (i = 1; i < 16; i++) {
1205 if (((ass >> 16) & 0xf) != tmp)
1208 spec->cdefine.port_connectivity = ass >> 30;
1209 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1210 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1211 spec->cdefine.customization = ass >> 8;
1213 spec->cdefine.sku_cfg = ass;
1214 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1215 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1216 spec->cdefine.swap = (ass & 0x2) >> 1;
1217 spec->cdefine.override = ass & 0x1;
1219 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1220 nid, spec->cdefine.sku_cfg);
1221 snd_printd("SKU: port_connectivity=0x%x\n",
1222 spec->cdefine.port_connectivity);
1223 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1224 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1225 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1226 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1227 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1228 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1229 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1234 /* return true if the given NID is found in the list */
1235 static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1237 return find_idx_in_nid_list(nid, list, nums) >= 0;
1240 /* check subsystem ID and set up device-specific initialization;
1241 * return 1 if initialized, 0 if invalid SSID
1243 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1244 * 31 ~ 16 : Manufacture ID
1246 * 7 ~ 0 : Assembly ID
1247 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1249 static int alc_subsystem_id(struct hda_codec *codec,
1250 hda_nid_t porta, hda_nid_t porte,
1251 hda_nid_t portd, hda_nid_t porti)
1253 unsigned int ass, tmp, i;
1255 struct alc_spec *spec = codec->spec;
1257 if (spec->cdefine.fixup) {
1258 ass = spec->cdefine.sku_cfg;
1259 if (ass == ALC_FIXUP_SKU_IGNORE)
1264 ass = codec->subsystem_id & 0xffff;
1265 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1268 /* invalid SSID, check the special NID pin defcfg instead */
1270 * 31~30 : port connectivity
1273 * 19~16 : Check sum (15:1)
1278 if (codec->vendor_id == 0x10ec0260)
1280 ass = snd_hda_codec_get_pincfg(codec, nid);
1281 snd_printd("realtek: No valid SSID, "
1282 "checking pincfg 0x%08x for NID 0x%x\n",
1286 if ((ass >> 30) != 1) /* no physical connection */
1291 for (i = 1; i < 16; i++) {
1295 if (((ass >> 16) & 0xf) != tmp)
1298 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1299 ass & 0xffff, codec->vendor_id);
1303 * 2 : 0 --> Desktop, 1 --> Laptop
1304 * 3~5 : External Amplifier control
1307 tmp = (ass & 0x38) >> 3; /* external Amp control */
1310 spec->init_amp = ALC_INIT_GPIO1;
1313 spec->init_amp = ALC_INIT_GPIO2;
1316 spec->init_amp = ALC_INIT_GPIO3;
1320 spec->init_amp = ALC_INIT_DEFAULT;
1324 /* is laptop or Desktop and enable the function "Mute internal speaker
1325 * when the external headphone out jack is plugged"
1327 if (!(ass & 0x8000))
1330 * 10~8 : Jack location
1331 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1333 * 15 : 1 --> enable the function "Mute internal speaker
1334 * when the external headphone out jack is plugged"
1336 if (!spec->autocfg.hp_pins[0]) {
1338 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1349 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1350 spec->autocfg.line_outs))
1352 spec->autocfg.hp_pins[0] = nid;
1357 /* Check the validity of ALC subsystem-id
1358 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1359 static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
1361 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
1362 struct alc_spec *spec = codec->spec;
1363 snd_printd("realtek: "
1364 "Enable default setup for auto mode as fallback\n");
1365 spec->init_amp = ALC_INIT_DEFAULT;
1370 * Fix-up pin default configurations and add default verbs
1378 struct alc_model_fixup {
1389 const struct alc_pincfg *pins;
1390 const struct hda_verb *verbs;
1391 void (*func)(struct hda_codec *codec,
1392 const struct alc_fixup *fix,
1406 ALC_FIXUP_ACT_PRE_PROBE,
1407 ALC_FIXUP_ACT_PROBE,
1411 static void alc_apply_fixup(struct hda_codec *codec, int action)
1413 struct alc_spec *spec = codec->spec;
1414 int id = spec->fixup_id;
1415 #ifdef CONFIG_SND_DEBUG_VERBOSE
1416 const char *modelname = spec->fixup_name;
1420 if (!spec->fixup_list)
1424 const struct alc_fixup *fix = spec->fixup_list + id;
1425 const struct alc_pincfg *cfg;
1427 switch (fix->type) {
1429 if (action != ALC_FIXUP_ACT_PRE_PROBE || !fix->v.sku)
1431 snd_printdd(KERN_INFO "hda_codec: %s: "
1432 "Apply sku override for %s\n",
1433 codec->chip_name, modelname);
1434 spec->cdefine.sku_cfg = fix->v.sku;
1435 spec->cdefine.fixup = 1;
1437 case ALC_FIXUP_PINS:
1439 if (action != ALC_FIXUP_ACT_PRE_PROBE || !cfg)
1441 snd_printdd(KERN_INFO "hda_codec: %s: "
1442 "Apply pincfg for %s\n",
1443 codec->chip_name, modelname);
1444 for (; cfg->nid; cfg++)
1445 snd_hda_codec_set_pincfg(codec, cfg->nid,
1448 case ALC_FIXUP_VERBS:
1449 if (action != ALC_FIXUP_ACT_PROBE || !fix->v.verbs)
1451 snd_printdd(KERN_INFO "hda_codec: %s: "
1452 "Apply fix-verbs for %s\n",
1453 codec->chip_name, modelname);
1454 add_verb(codec->spec, fix->v.verbs);
1456 case ALC_FIXUP_FUNC:
1459 snd_printdd(KERN_INFO "hda_codec: %s: "
1460 "Apply fix-func for %s\n",
1461 codec->chip_name, modelname);
1462 fix->v.func(codec, fix, action);
1465 snd_printk(KERN_ERR "hda_codec: %s: "
1466 "Invalid fixup type %d\n",
1467 codec->chip_name, fix->type);
1478 static void alc_pick_fixup(struct hda_codec *codec,
1479 const struct alc_model_fixup *models,
1480 const struct snd_pci_quirk *quirk,
1481 const struct alc_fixup *fixlist)
1483 struct alc_spec *spec = codec->spec;
1485 const char *name = NULL;
1487 if (codec->modelname && models) {
1488 while (models->name) {
1489 if (!strcmp(codec->modelname, models->name)) {
1491 name = models->name;
1498 quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1501 #ifdef CONFIG_SND_DEBUG_VERBOSE
1507 spec->fixup_id = id;
1509 spec->fixup_list = fixlist;
1510 spec->fixup_name = name;
1515 * COEF access helper functions
1517 static int alc_read_coef_idx(struct hda_codec *codec,
1518 unsigned int coef_idx)
1521 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1523 val = snd_hda_codec_read(codec, 0x20, 0,
1524 AC_VERB_GET_PROC_COEF, 0);
1528 static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1529 unsigned int coef_val)
1531 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1533 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1538 * Digital I/O handling
1541 /* set right pin controls for digital I/O */
1542 static void alc_auto_init_digital(struct hda_codec *codec)
1544 struct alc_spec *spec = codec->spec;
1548 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1549 pin = spec->autocfg.dig_out_pins[i];
1552 snd_hda_codec_write(codec, pin, 0,
1553 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
1555 dac = spec->multiout.dig_out_nid;
1557 dac = spec->slave_dig_outs[i - 1];
1558 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
1560 snd_hda_codec_write(codec, dac, 0,
1561 AC_VERB_SET_AMP_GAIN_MUTE,
1564 pin = spec->autocfg.dig_in_pin;
1566 snd_hda_codec_write(codec, pin, 0,
1567 AC_VERB_SET_PIN_WIDGET_CONTROL,
1571 /* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1572 static void alc_auto_parse_digital(struct hda_codec *codec)
1574 struct alc_spec *spec = codec->spec;
1578 /* support multiple SPDIFs; the secondary is set up as a slave */
1579 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1581 err = snd_hda_get_connections(codec,
1582 spec->autocfg.dig_out_pins[i],
1583 conn, ARRAY_SIZE(conn));
1586 dig_nid = conn[0]; /* assume the first element is audio-out */
1588 spec->multiout.dig_out_nid = dig_nid;
1589 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1591 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
1592 if (i >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
1594 spec->slave_dig_outs[i - 1] = dig_nid;
1598 if (spec->autocfg.dig_in_pin) {
1599 dig_nid = codec->start_nid;
1600 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1601 unsigned int wcaps = get_wcaps(codec, dig_nid);
1602 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1604 if (!(wcaps & AC_WCAP_DIGITAL))
1606 if (!(wcaps & AC_WCAP_CONN_LIST))
1608 err = get_connection_index(codec, dig_nid,
1609 spec->autocfg.dig_in_pin);
1611 spec->dig_in_nid = dig_nid;
1619 * capture mixer elements
1621 static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1622 struct snd_ctl_elem_info *uinfo)
1624 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1625 struct alc_spec *spec = codec->spec;
1629 mutex_lock(&codec->control_mutex);
1630 if (spec->vol_in_capsrc)
1631 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1633 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1634 kcontrol->private_value = val;
1635 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
1636 mutex_unlock(&codec->control_mutex);
1640 static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1641 unsigned int size, unsigned int __user *tlv)
1643 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1644 struct alc_spec *spec = codec->spec;
1648 mutex_lock(&codec->control_mutex);
1649 if (spec->vol_in_capsrc)
1650 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1652 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1653 kcontrol->private_value = val;
1654 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
1655 mutex_unlock(&codec->control_mutex);
1659 typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1660 struct snd_ctl_elem_value *ucontrol);
1662 static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1663 struct snd_ctl_elem_value *ucontrol,
1664 getput_call_t func, bool check_adc_switch)
1666 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1667 struct alc_spec *spec = codec->spec;
1670 mutex_lock(&codec->control_mutex);
1671 if (check_adc_switch && spec->dyn_adc_switch) {
1672 for (i = 0; i < spec->num_adc_nids; i++) {
1673 kcontrol->private_value =
1674 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1676 err = func(kcontrol, ucontrol);
1681 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1682 if (spec->vol_in_capsrc)
1683 kcontrol->private_value =
1684 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1687 kcontrol->private_value =
1688 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1690 err = func(kcontrol, ucontrol);
1693 mutex_unlock(&codec->control_mutex);
1697 static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1698 struct snd_ctl_elem_value *ucontrol)
1700 return alc_cap_getput_caller(kcontrol, ucontrol,
1701 snd_hda_mixer_amp_volume_get, false);
1704 static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1705 struct snd_ctl_elem_value *ucontrol)
1707 return alc_cap_getput_caller(kcontrol, ucontrol,
1708 snd_hda_mixer_amp_volume_put, true);
1711 /* capture mixer elements */
1712 #define alc_cap_sw_info snd_ctl_boolean_stereo_info
1714 static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1715 struct snd_ctl_elem_value *ucontrol)
1717 return alc_cap_getput_caller(kcontrol, ucontrol,
1718 snd_hda_mixer_amp_switch_get, false);
1721 static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1722 struct snd_ctl_elem_value *ucontrol)
1724 return alc_cap_getput_caller(kcontrol, ucontrol,
1725 snd_hda_mixer_amp_switch_put, true);
1728 #define _DEFINE_CAPMIX(num) \
1730 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1731 .name = "Capture Switch", \
1732 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1734 .info = alc_cap_sw_info, \
1735 .get = alc_cap_sw_get, \
1736 .put = alc_cap_sw_put, \
1739 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1740 .name = "Capture Volume", \
1741 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1742 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1743 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1745 .info = alc_cap_vol_info, \
1746 .get = alc_cap_vol_get, \
1747 .put = alc_cap_vol_put, \
1748 .tlv = { .c = alc_cap_vol_tlv }, \
1751 #define _DEFINE_CAPSRC(num) \
1753 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1754 /* .name = "Capture Source", */ \
1755 .name = "Input Source", \
1757 .info = alc_mux_enum_info, \
1758 .get = alc_mux_enum_get, \
1759 .put = alc_mux_enum_put, \
1762 #define DEFINE_CAPMIX(num) \
1763 static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
1764 _DEFINE_CAPMIX(num), \
1765 _DEFINE_CAPSRC(num), \
1769 #define DEFINE_CAPMIX_NOSRC(num) \
1770 static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
1771 _DEFINE_CAPMIX(num), \
1775 /* up to three ADCs */
1779 DEFINE_CAPMIX_NOSRC(1);
1780 DEFINE_CAPMIX_NOSRC(2);
1781 DEFINE_CAPMIX_NOSRC(3);
1784 * virtual master controls
1788 * slave controls for virtual master
1790 static const char * const alc_slave_vols[] = {
1791 "Front Playback Volume",
1792 "Surround Playback Volume",
1793 "Center Playback Volume",
1794 "LFE Playback Volume",
1795 "Side Playback Volume",
1796 "Headphone Playback Volume",
1797 "Speaker Playback Volume",
1798 "Mono Playback Volume",
1799 "Line-Out Playback Volume",
1800 "PCM Playback Volume",
1804 static const char * const alc_slave_sws[] = {
1805 "Front Playback Switch",
1806 "Surround Playback Switch",
1807 "Center Playback Switch",
1808 "LFE Playback Switch",
1809 "Side Playback Switch",
1810 "Headphone Playback Switch",
1811 "Speaker Playback Switch",
1812 "Mono Playback Switch",
1813 "IEC958 Playback Switch",
1814 "Line-Out Playback Switch",
1815 "PCM Playback Switch",
1820 * build control elements
1823 #define NID_MAPPING (-1)
1825 #define SUBDEV_SPEAKER_ (0 << 6)
1826 #define SUBDEV_HP_ (1 << 6)
1827 #define SUBDEV_LINE_ (2 << 6)
1828 #define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1829 #define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1830 #define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1832 static void alc_free_kctls(struct hda_codec *codec);
1834 #ifdef CONFIG_SND_HDA_INPUT_BEEP
1835 /* additional beep mixers; the actual parameters are overwritten at build */
1836 static const struct snd_kcontrol_new alc_beep_mixer[] = {
1837 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
1838 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
1843 static int alc_build_controls(struct hda_codec *codec)
1845 struct alc_spec *spec = codec->spec;
1846 struct snd_kcontrol *kctl = NULL;
1847 const struct snd_kcontrol_new *knew;
1852 for (i = 0; i < spec->num_mixers; i++) {
1853 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1857 if (spec->cap_mixer) {
1858 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1862 if (spec->multiout.dig_out_nid) {
1863 err = snd_hda_create_spdif_out_ctls(codec,
1864 spec->multiout.dig_out_nid,
1865 spec->multiout.dig_out_nid);
1868 if (!spec->no_analog) {
1869 err = snd_hda_create_spdif_share_sw(codec,
1873 spec->multiout.share_spdif = 1;
1876 if (spec->dig_in_nid) {
1877 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1882 #ifdef CONFIG_SND_HDA_INPUT_BEEP
1883 /* create beep controls if needed */
1884 if (spec->beep_amp) {
1885 const struct snd_kcontrol_new *knew;
1886 for (knew = alc_beep_mixer; knew->name; knew++) {
1887 struct snd_kcontrol *kctl;
1888 kctl = snd_ctl_new1(knew, codec);
1891 kctl->private_value = spec->beep_amp;
1892 err = snd_hda_ctl_add(codec, 0, kctl);
1899 /* if we have no master control, let's create it */
1900 if (!spec->no_analog &&
1901 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1902 unsigned int vmaster_tlv[4];
1903 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
1904 HDA_OUTPUT, vmaster_tlv);
1905 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1906 vmaster_tlv, alc_slave_vols);
1910 if (!spec->no_analog &&
1911 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1912 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1913 NULL, alc_slave_sws);
1918 /* assign Capture Source enums to NID */
1919 if (spec->capsrc_nids || spec->adc_nids) {
1920 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
1922 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1923 for (i = 0; kctl && i < kctl->count; i++) {
1924 const hda_nid_t *nids = spec->capsrc_nids;
1926 nids = spec->adc_nids;
1927 err = snd_hda_add_nid(codec, kctl, i, nids[i]);
1932 if (spec->cap_mixer && spec->adc_nids) {
1933 const char *kname = kctl ? kctl->id.name : NULL;
1934 for (knew = spec->cap_mixer; knew->name; knew++) {
1935 if (kname && strcmp(knew->name, kname) == 0)
1937 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1938 for (i = 0; kctl && i < kctl->count; i++) {
1939 err = snd_hda_add_nid(codec, kctl, i,
1947 /* other nid->control mapping */
1948 for (i = 0; i < spec->num_mixers; i++) {
1949 for (knew = spec->mixers[i]; knew->name; knew++) {
1950 if (knew->iface != NID_MAPPING)
1952 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1955 u = knew->subdevice;
1956 for (j = 0; j < 4; j++, u >>= 8) {
1961 case SUBDEV_SPEAKER_:
1962 nid = spec->autocfg.speaker_pins[nid];
1965 nid = spec->autocfg.line_out_pins[nid];
1968 nid = spec->autocfg.hp_pins[nid];
1973 err = snd_hda_add_nid(codec, kctl, 0, nid);
1977 u = knew->private_value;
1978 for (j = 0; j < 4; j++, u >>= 8) {
1982 err = snd_hda_add_nid(codec, kctl, 0, nid);
1989 alc_free_kctls(codec); /* no longer needed */
1999 static void alc_init_special_input_src(struct hda_codec *codec);
2001 static int alc_init(struct hda_codec *codec)
2003 struct alc_spec *spec = codec->spec;
2007 alc_auto_init_amp(codec, spec->init_amp);
2009 for (i = 0; i < spec->num_init_verbs; i++)
2010 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2011 alc_init_special_input_src(codec);
2013 if (spec->init_hook)
2014 spec->init_hook(codec);
2016 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2018 hda_call_check_power_status(codec, 0x01);
2022 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2024 struct alc_spec *spec = codec->spec;
2026 if (spec->unsol_event)
2027 spec->unsol_event(codec, res);
2030 #ifdef CONFIG_SND_HDA_POWER_SAVE
2031 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2033 struct alc_spec *spec = codec->spec;
2034 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2039 * Analog playback callbacks
2041 static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
2042 struct hda_codec *codec,
2043 struct snd_pcm_substream *substream)
2045 struct alc_spec *spec = codec->spec;
2046 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2050 static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2051 struct hda_codec *codec,
2052 unsigned int stream_tag,
2053 unsigned int format,
2054 struct snd_pcm_substream *substream)
2056 struct alc_spec *spec = codec->spec;
2057 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2058 stream_tag, format, substream);
2061 static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2062 struct hda_codec *codec,
2063 struct snd_pcm_substream *substream)
2065 struct alc_spec *spec = codec->spec;
2066 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2072 static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2073 struct hda_codec *codec,
2074 struct snd_pcm_substream *substream)
2076 struct alc_spec *spec = codec->spec;
2077 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2080 static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2081 struct hda_codec *codec,
2082 unsigned int stream_tag,
2083 unsigned int format,
2084 struct snd_pcm_substream *substream)
2086 struct alc_spec *spec = codec->spec;
2087 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2088 stream_tag, format, substream);
2091 static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2092 struct hda_codec *codec,
2093 struct snd_pcm_substream *substream)
2095 struct alc_spec *spec = codec->spec;
2096 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2099 static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2100 struct hda_codec *codec,
2101 struct snd_pcm_substream *substream)
2103 struct alc_spec *spec = codec->spec;
2104 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2110 static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2111 struct hda_codec *codec,
2112 unsigned int stream_tag,
2113 unsigned int format,
2114 struct snd_pcm_substream *substream)
2116 struct alc_spec *spec = codec->spec;
2118 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
2119 stream_tag, 0, format);
2123 static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2124 struct hda_codec *codec,
2125 struct snd_pcm_substream *substream)
2127 struct alc_spec *spec = codec->spec;
2129 snd_hda_codec_cleanup_stream(codec,
2130 spec->adc_nids[substream->number + 1]);
2134 /* analog capture with dynamic dual-adc changes */
2135 static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2136 struct hda_codec *codec,
2137 unsigned int stream_tag,
2138 unsigned int format,
2139 struct snd_pcm_substream *substream)
2141 struct alc_spec *spec = codec->spec;
2142 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
2143 spec->cur_adc_stream_tag = stream_tag;
2144 spec->cur_adc_format = format;
2145 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2149 static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2150 struct hda_codec *codec,
2151 struct snd_pcm_substream *substream)
2153 struct alc_spec *spec = codec->spec;
2154 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2159 static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
2163 .nid = 0, /* fill later */
2165 .prepare = dyn_adc_capture_pcm_prepare,
2166 .cleanup = dyn_adc_capture_pcm_cleanup
2172 static const struct hda_pcm_stream alc_pcm_analog_playback = {
2176 /* NID is set in alc_build_pcms */
2178 .open = alc_playback_pcm_open,
2179 .prepare = alc_playback_pcm_prepare,
2180 .cleanup = alc_playback_pcm_cleanup
2184 static const struct hda_pcm_stream alc_pcm_analog_capture = {
2188 /* NID is set in alc_build_pcms */
2191 static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
2195 /* NID is set in alc_build_pcms */
2198 static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
2199 .substreams = 2, /* can be overridden */
2202 /* NID is set in alc_build_pcms */
2204 .prepare = alc_alt_capture_pcm_prepare,
2205 .cleanup = alc_alt_capture_pcm_cleanup
2209 static const struct hda_pcm_stream alc_pcm_digital_playback = {
2213 /* NID is set in alc_build_pcms */
2215 .open = alc_dig_playback_pcm_open,
2216 .close = alc_dig_playback_pcm_close,
2217 .prepare = alc_dig_playback_pcm_prepare,
2218 .cleanup = alc_dig_playback_pcm_cleanup
2222 static const struct hda_pcm_stream alc_pcm_digital_capture = {
2226 /* NID is set in alc_build_pcms */
2229 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
2230 static const struct hda_pcm_stream alc_pcm_null_stream = {
2236 static int alc_build_pcms(struct hda_codec *codec)
2238 struct alc_spec *spec = codec->spec;
2239 struct hda_pcm *info = spec->pcm_rec;
2240 const struct hda_pcm_stream *p;
2243 codec->num_pcms = 1;
2244 codec->pcm_info = info;
2246 if (spec->no_analog)
2249 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2250 "%s Analog", codec->chip_name);
2251 info->name = spec->stream_name_analog;
2253 if (spec->multiout.dac_nids > 0) {
2254 p = spec->stream_analog_playback;
2256 p = &alc_pcm_analog_playback;
2257 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2258 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2260 if (spec->adc_nids) {
2261 p = spec->stream_analog_capture;
2263 if (spec->dyn_adc_switch)
2264 p = &dyn_adc_pcm_analog_capture;
2266 p = &alc_pcm_analog_capture;
2268 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2269 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2272 if (spec->channel_mode) {
2273 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2274 for (i = 0; i < spec->num_channel_mode; i++) {
2275 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2276 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2282 /* SPDIF for stream index #1 */
2283 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2284 snprintf(spec->stream_name_digital,
2285 sizeof(spec->stream_name_digital),
2286 "%s Digital", codec->chip_name);
2287 codec->num_pcms = 2;
2288 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
2289 info = spec->pcm_rec + 1;
2290 info->name = spec->stream_name_digital;
2291 if (spec->dig_out_type)
2292 info->pcm_type = spec->dig_out_type;
2294 info->pcm_type = HDA_PCM_TYPE_SPDIF;
2295 if (spec->multiout.dig_out_nid) {
2296 p = spec->stream_digital_playback;
2298 p = &alc_pcm_digital_playback;
2299 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2300 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2302 if (spec->dig_in_nid) {
2303 p = spec->stream_digital_capture;
2305 p = &alc_pcm_digital_capture;
2306 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2307 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2309 /* FIXME: do we need this for all Realtek codec models? */
2310 codec->spdif_status_reset = 1;
2313 if (spec->no_analog)
2316 /* If the use of more than one ADC is requested for the current
2317 * model, configure a second analog capture-only PCM.
2319 /* Additional Analaog capture for index #2 */
2320 if (spec->alt_dac_nid || spec->num_adc_nids > 1) {
2321 codec->num_pcms = 3;
2322 info = spec->pcm_rec + 2;
2323 info->name = spec->stream_name_analog;
2324 if (spec->alt_dac_nid) {
2325 p = spec->stream_analog_alt_playback;
2327 p = &alc_pcm_analog_alt_playback;
2328 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2329 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2332 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2333 alc_pcm_null_stream;
2334 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2336 if (spec->num_adc_nids > 1) {
2337 p = spec->stream_analog_alt_capture;
2339 p = &alc_pcm_analog_alt_capture;
2340 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2341 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2343 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2344 spec->num_adc_nids - 1;
2346 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2347 alc_pcm_null_stream;
2348 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
2355 static inline void alc_shutup(struct hda_codec *codec)
2357 struct alc_spec *spec = codec->spec;
2359 if (spec && spec->shutup)
2360 spec->shutup(codec);
2361 snd_hda_shutup_pins(codec);
2364 static void alc_free_kctls(struct hda_codec *codec)
2366 struct alc_spec *spec = codec->spec;
2368 if (spec->kctls.list) {
2369 struct snd_kcontrol_new *kctl = spec->kctls.list;
2371 for (i = 0; i < spec->kctls.used; i++)
2372 kfree(kctl[i].name);
2374 snd_array_free(&spec->kctls);
2377 static void alc_free_bind_ctls(struct hda_codec *codec)
2379 struct alc_spec *spec = codec->spec;
2380 if (spec->bind_ctls.list) {
2381 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2383 for (i = 0; i < spec->bind_ctls.used; i++)
2386 snd_array_free(&spec->bind_ctls);
2389 static void alc_free(struct hda_codec *codec)
2391 struct alc_spec *spec = codec->spec;
2397 snd_hda_input_jack_free(codec);
2398 alc_free_kctls(codec);
2399 alc_free_bind_ctls(codec);
2401 snd_hda_detach_beep_device(codec);
2404 #ifdef CONFIG_SND_HDA_POWER_SAVE
2405 static void alc_power_eapd(struct hda_codec *codec)
2407 alc_auto_setup_eapd(codec, false);
2410 static int alc_suspend(struct hda_codec *codec, pm_message_t state)
2412 struct alc_spec *spec = codec->spec;
2414 if (spec && spec->power_hook)
2415 spec->power_hook(codec);
2421 static int alc_resume(struct hda_codec *codec)
2423 msleep(150); /* to avoid pop noise */
2424 codec->patch_ops.init(codec);
2425 snd_hda_codec_resume_amp(codec);
2426 snd_hda_codec_resume_cache(codec);
2427 hda_call_check_power_status(codec, 0x01);
2434 static const struct hda_codec_ops alc_patch_ops = {
2435 .build_controls = alc_build_controls,
2436 .build_pcms = alc_build_pcms,
2439 .unsol_event = alc_unsol_event,
2441 .resume = alc_resume,
2443 #ifdef CONFIG_SND_HDA_POWER_SAVE
2444 .suspend = alc_suspend,
2445 .check_power_status = alc_check_power_status,
2447 .reboot_notify = alc_shutup,
2450 /* replace the codec chip_name with the given string */
2451 static int alc_codec_rename(struct hda_codec *codec, const char *name)
2453 kfree(codec->chip_name);
2454 codec->chip_name = kstrdup(name, GFP_KERNEL);
2455 if (!codec->chip_name) {
2463 * Automatic parse of I/O pins from the BIOS configuration
2468 ALC_CTL_WIDGET_MUTE,
2473 static const struct snd_kcontrol_new alc_control_templates[] = {
2474 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2475 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2476 HDA_BIND_MUTE(NULL, 0, 0, 0),
2477 HDA_BIND_VOL(NULL, 0),
2478 HDA_BIND_SW(NULL, 0),
2481 /* add dynamic controls */
2482 static int add_control(struct alc_spec *spec, int type, const char *name,
2483 int cidx, unsigned long val)
2485 struct snd_kcontrol_new *knew;
2487 knew = alc_kcontrol_new(spec);
2490 *knew = alc_control_templates[type];
2491 knew->name = kstrdup(name, GFP_KERNEL);
2495 if (get_amp_nid_(val))
2496 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
2497 knew->private_value = val;
2501 static int add_control_with_pfx(struct alc_spec *spec, int type,
2502 const char *pfx, const char *dir,
2503 const char *sfx, int cidx, unsigned long val)
2506 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
2507 return add_control(spec, type, name, cidx, val);
2510 #define add_pb_vol_ctrl(spec, type, pfx, val) \
2511 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2512 #define add_pb_sw_ctrl(spec, type, pfx, val) \
2513 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2514 #define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2515 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2516 #define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2517 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
2519 static const char * const channel_name[4] = {
2520 "Front", "Surround", "CLFE", "Side"
2523 static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2524 bool can_be_master, int *index)
2526 struct auto_pin_cfg *cfg = &spec->autocfg;
2529 if (cfg->line_outs == 1 && !spec->multi_ios &&
2530 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
2533 switch (cfg->line_out_type) {
2534 case AUTO_PIN_SPEAKER_OUT:
2535 if (cfg->line_outs == 1)
2538 case AUTO_PIN_HP_OUT:
2539 /* for multi-io case, only the primary out */
2540 if (ch && spec->multi_ios)
2545 if (cfg->line_outs == 1 && !spec->multi_ios)
2549 if (snd_BUG_ON(ch >= ARRAY_SIZE(channel_name)))
2552 return channel_name[ch];
2555 /* create input playback/capture controls for the given pin */
2556 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
2557 const char *ctlname, int ctlidx,
2558 int idx, hda_nid_t mix_nid)
2562 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
2563 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2566 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
2567 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2573 static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
2575 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2576 return (pincap & AC_PINCAP_IN) != 0;
2579 /* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
2580 static int alc_auto_fill_adc_caps(struct hda_codec *codec)
2582 struct alc_spec *spec = codec->spec;
2584 hda_nid_t *adc_nids = spec->private_adc_nids;
2585 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2586 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
2587 bool indep_capsrc = false;
2590 nid = codec->start_nid;
2591 for (i = 0; i < codec->num_nodes; i++, nid++) {
2593 const hda_nid_t *list;
2594 unsigned int caps = get_wcaps(codec, nid);
2595 int type = get_wcaps_type(caps);
2597 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2599 adc_nids[nums] = nid;
2600 cap_nids[nums] = nid;
2604 type = get_wcaps_type(get_wcaps(codec, src));
2605 if (type == AC_WID_PIN)
2607 if (type == AC_WID_AUD_SEL) {
2608 cap_nids[nums] = src;
2609 indep_capsrc = true;
2612 n = snd_hda_get_conn_list(codec, src, &list);
2614 cap_nids[nums] = src;
2615 indep_capsrc = true;
2621 if (++nums >= max_nums)
2624 spec->adc_nids = spec->private_adc_nids;
2625 spec->capsrc_nids = spec->private_capsrc_nids;
2626 spec->num_adc_nids = nums;
2630 /* create playback/capture controls for input pins */
2631 static int alc_auto_create_input_ctls(struct hda_codec *codec)
2633 struct alc_spec *spec = codec->spec;
2634 const struct auto_pin_cfg *cfg = &spec->autocfg;
2635 hda_nid_t mixer = spec->mixer_nid;
2636 struct hda_input_mux *imux = &spec->private_imux[0];
2638 int i, c, err, idx, type_idx = 0;
2639 const char *prev_label = NULL;
2641 num_adcs = alc_auto_fill_adc_caps(codec);
2645 for (i = 0; i < cfg->num_inputs; i++) {
2649 pin = cfg->inputs[i].pin;
2650 if (!alc_is_input_pin(codec, pin))
2653 label = hda_get_autocfg_input_label(codec, cfg, i);
2654 if (prev_label && !strcmp(label, prev_label))
2661 idx = get_connection_index(codec, mixer, pin);
2663 err = new_analog_input(spec, pin,
2671 for (c = 0; c < num_adcs; c++) {
2672 hda_nid_t cap = spec->capsrc_nids ?
2673 spec->capsrc_nids[c] : spec->adc_nids[c];
2674 idx = get_connection_index(codec, cap, pin);
2676 spec->imux_pins[imux->num_items] = pin;
2677 snd_hda_add_imux_item(imux, label, idx, NULL);
2683 spec->num_mux_defs = 1;
2684 spec->input_mux = imux;
2689 static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
2690 unsigned int pin_type)
2692 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2695 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2696 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2700 static int get_pin_type(int line_out_type)
2702 if (line_out_type == AUTO_PIN_HP_OUT)
2708 static void alc_auto_init_analog_input(struct hda_codec *codec)
2710 struct alc_spec *spec = codec->spec;
2711 struct auto_pin_cfg *cfg = &spec->autocfg;
2714 for (i = 0; i < cfg->num_inputs; i++) {
2715 hda_nid_t nid = cfg->inputs[i].pin;
2716 if (alc_is_input_pin(codec, nid)) {
2717 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
2718 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
2719 snd_hda_codec_write(codec, nid, 0,
2720 AC_VERB_SET_AMP_GAIN_MUTE,
2725 /* mute all loopback inputs */
2726 if (spec->mixer_nid) {
2727 int nums = snd_hda_get_conn_list(codec, spec->mixer_nid, NULL);
2728 for (i = 0; i < nums; i++)
2729 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2730 AC_VERB_SET_AMP_GAIN_MUTE,
2735 /* convert from MIX nid to DAC */
2736 static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid)
2741 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT)
2743 num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list));
2744 for (i = 0; i < num; i++) {
2745 if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT)
2751 /* go down to the selector widget before the mixer */
2752 static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin)
2755 int num = snd_hda_get_connections(codec, pin, srcs,
2758 get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL)
2763 /* get MIX nid connected to the given pin targeted to DAC */
2764 static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
2770 pin = alc_go_down_to_selector(codec, pin);
2771 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2772 for (i = 0; i < num; i++) {
2773 if (alc_auto_mix_to_dac(codec, mix[i]) == dac)
2779 /* select the connection from pin to DAC if needed */
2780 static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin,
2786 pin = alc_go_down_to_selector(codec, pin);
2787 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2790 for (i = 0; i < num; i++) {
2791 if (alc_auto_mix_to_dac(codec, mix[i]) == dac) {
2792 snd_hda_codec_update_cache(codec, pin, 0,
2793 AC_VERB_SET_CONNECT_SEL, i);
2800 /* look for an empty DAC slot */
2801 static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
2803 struct alc_spec *spec = codec->spec;
2807 pin = alc_go_down_to_selector(codec, pin);
2808 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
2809 for (i = 0; i < num; i++) {
2810 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
2813 if (found_in_nid_list(nid, spec->multiout.dac_nids,
2814 spec->multiout.num_dacs))
2816 if (spec->multiout.hp_out_nid[0] == nid)
2818 if (found_in_nid_list(nid, spec->multiout.extra_out_nid,
2819 ARRAY_SIZE(spec->multiout.extra_out_nid)))
2826 static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
2828 hda_nid_t sel = alc_go_down_to_selector(codec, pin);
2829 if (snd_hda_get_conn_list(codec, sel, NULL) == 1)
2830 return alc_auto_look_for_dac(codec, pin);
2834 /* fill in the dac_nids table from the parsed pin configuration */
2835 static int alc_auto_fill_dac_nids(struct hda_codec *codec)
2837 struct alc_spec *spec = codec->spec;
2838 const struct auto_pin_cfg *cfg = &spec->autocfg;
2839 bool redone = false;
2843 /* set num_dacs once to full for alc_auto_look_for_dac() */
2844 spec->multiout.num_dacs = cfg->line_outs;
2845 spec->multiout.hp_out_nid[0] = 0;
2846 spec->multiout.extra_out_nid[0] = 0;
2847 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
2848 spec->multiout.dac_nids = spec->private_dac_nids;
2850 /* fill hard-wired DACs first */
2852 for (i = 0; i < cfg->line_outs; i++)
2853 spec->private_dac_nids[i] =
2854 get_dac_if_single(codec, cfg->line_out_pins[i]);
2856 spec->multiout.hp_out_nid[0] =
2857 get_dac_if_single(codec, cfg->hp_pins[0]);
2858 if (cfg->speaker_outs)
2859 spec->multiout.extra_out_nid[0] =
2860 get_dac_if_single(codec, cfg->speaker_pins[0]);
2863 for (i = 0; i < cfg->line_outs; i++) {
2864 hda_nid_t pin = cfg->line_out_pins[i];
2865 if (spec->private_dac_nids[i])
2867 spec->private_dac_nids[i] = alc_auto_look_for_dac(codec, pin);
2868 if (!spec->private_dac_nids[i] && !redone) {
2869 /* if we can't find primary DACs, re-probe without
2870 * checking the hard-wired DACs
2877 /* re-count num_dacs and squash invalid entries */
2878 spec->multiout.num_dacs = 0;
2879 for (i = 0; i < cfg->line_outs; i++) {
2880 if (spec->private_dac_nids[i])
2881 spec->multiout.num_dacs++;
2883 memmove(spec->private_dac_nids + i,
2884 spec->private_dac_nids + i + 1,
2885 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
2888 if (cfg->hp_outs && !spec->multiout.hp_out_nid[0])
2889 spec->multiout.hp_out_nid[0] =
2890 alc_auto_look_for_dac(codec, cfg->hp_pins[0]);
2891 if (cfg->speaker_outs && !spec->multiout.extra_out_nid[0])
2892 spec->multiout.extra_out_nid[0] =
2893 alc_auto_look_for_dac(codec, cfg->speaker_pins[0]);
2898 /* fill in the dac_nids table for surround speakers, etc */
2899 static int alc_auto_fill_extra_dacs(struct hda_codec *codec)
2901 struct alc_spec *spec = codec->spec;
2902 const struct auto_pin_cfg *cfg = &spec->autocfg;
2905 if (cfg->speaker_outs < 2 || !spec->multiout.extra_out_nid[0])
2908 for (i = 1; i < cfg->speaker_outs; i++)
2909 spec->multiout.extra_out_nid[i] =
2910 get_dac_if_single(codec, cfg->speaker_pins[i]);
2911 for (i = 1; i < cfg->speaker_outs; i++) {
2912 if (spec->multiout.extra_out_nid[i])
2914 spec->multiout.extra_out_nid[i] =
2915 alc_auto_look_for_dac(codec, cfg->speaker_pins[0]);
2920 static int alc_auto_add_vol_ctl(struct hda_codec *codec,
2921 const char *pfx, int cidx,
2922 hda_nid_t nid, unsigned int chs)
2926 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
2927 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
2930 #define alc_auto_add_stereo_vol(codec, pfx, cidx, nid) \
2931 alc_auto_add_vol_ctl(codec, pfx, cidx, nid, 3)
2933 /* create a mute-switch for the given mixer widget;
2934 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
2936 static int alc_auto_add_sw_ctl(struct hda_codec *codec,
2937 const char *pfx, int cidx,
2938 hda_nid_t nid, unsigned int chs)
2945 wid_type = get_wcaps_type(get_wcaps(codec, nid));
2946 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) {
2947 type = ALC_CTL_WIDGET_MUTE;
2948 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
2949 } else if (snd_hda_get_conn_list(codec, nid, NULL) == 1) {
2950 type = ALC_CTL_WIDGET_MUTE;
2951 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
2953 type = ALC_CTL_BIND_MUTE;
2954 val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
2956 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
2959 #define alc_auto_add_stereo_sw(codec, pfx, cidx, nid) \
2960 alc_auto_add_sw_ctl(codec, pfx, cidx, nid, 3)
2962 static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
2963 hda_nid_t pin, hda_nid_t dac)
2965 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
2966 if (nid_has_mute(codec, pin, HDA_OUTPUT))
2968 else if (mix && nid_has_mute(codec, mix, HDA_INPUT))
2970 else if (nid_has_mute(codec, dac, HDA_OUTPUT))
2975 static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
2976 hda_nid_t pin, hda_nid_t dac)
2978 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
2979 if (nid_has_volume(codec, dac, HDA_OUTPUT))
2981 else if (nid_has_volume(codec, mix, HDA_OUTPUT))
2983 else if (nid_has_volume(codec, pin, HDA_OUTPUT))
2988 /* add playback controls from the parsed DAC table */
2989 static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
2990 const struct auto_pin_cfg *cfg)
2992 struct alc_spec *spec = codec->spec;
2993 int i, err, noutputs;
2995 noutputs = cfg->line_outs;
2996 if (spec->multi_ios > 0)
2997 noutputs += spec->multi_ios;
2999 for (i = 0; i < noutputs; i++) {
3005 dac = spec->multiout.dac_nids[i];
3008 if (i >= cfg->line_outs)
3009 pin = spec->multi_io[i - 1].pin;
3011 pin = cfg->line_out_pins[i];
3013 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3014 vol = alc_look_for_out_vol_nid(codec, pin, dac);
3015 name = alc_get_line_out_pfx(spec, i, true, &index);
3018 err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1);
3021 err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2);
3024 err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1);
3027 err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2);
3031 err = alc_auto_add_stereo_vol(codec, name, index, vol);
3034 err = alc_auto_add_stereo_sw(codec, name, index, sw);
3042 static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
3043 hda_nid_t dac, const char *pfx)
3045 struct alc_spec *spec = codec->spec;
3050 /* the corresponding DAC is already occupied */
3051 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
3052 return 0; /* no way */
3053 /* create a switch only */
3054 return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx,
3055 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3058 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3059 vol = alc_look_for_out_vol_nid(codec, pin, dac);
3060 err = alc_auto_add_stereo_vol(codec, pfx, 0, vol);
3063 err = alc_auto_add_stereo_sw(codec, pfx, 0, sw);
3069 static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3071 struct hda_ctl_ops *ops)
3073 struct alc_spec *spec = codec->spec;
3074 struct hda_bind_ctls **ctlp, *ctl;
3075 snd_array_init(&spec->bind_ctls, sizeof(ctl), 8);
3076 ctlp = snd_array_new(&spec->bind_ctls);
3079 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3086 /* add playback controls for speaker and HP outputs */
3087 static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3088 const hda_nid_t *pins,
3089 const hda_nid_t *dacs,
3092 struct alc_spec *spec = codec->spec;
3093 struct hda_bind_ctls *ctl;
3097 if (!num_pins || !pins[0])
3101 return alc_auto_create_extra_out(codec, *pins, *dacs, pfx);
3103 if (dacs[num_pins - 1]) {
3104 /* OK, we have a multi-output system with individual volumes */
3105 for (i = 0; i < num_pins; i++) {
3106 snprintf(name, sizeof(name), "%s %s",
3107 pfx, channel_name[i]);
3108 err = alc_auto_create_extra_out(codec, pins[i], dacs[i],
3116 /* Let's create a bind-controls */
3117 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_sw);
3121 for (i = 0; i < num_pins; i++) {
3122 if (get_wcaps(codec, pins[i]) & AC_WCAP_OUT_AMP)
3124 HDA_COMPOSE_AMP_VAL(pins[i], 3, 0, HDA_OUTPUT);
3127 snprintf(name, sizeof(name), "%s Playback Switch", pfx);
3128 err = add_control(spec, ALC_CTL_BIND_SW, name, 0, (long)ctl);
3133 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3137 for (i = 0; i < num_pins; i++) {
3139 if (!pins[i] || !dacs[i])
3141 vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]);
3144 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3147 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3148 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3155 static int alc_auto_create_hp_out(struct hda_codec *codec)
3157 struct alc_spec *spec = codec->spec;
3158 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3159 spec->autocfg.hp_pins,
3160 spec->multiout.hp_out_nid,
3164 static int alc_auto_create_speaker_out(struct hda_codec *codec)
3166 struct alc_spec *spec = codec->spec;
3167 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3168 spec->autocfg.speaker_pins,
3169 spec->multiout.extra_out_nid,
3173 static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
3174 hda_nid_t pin, int pin_type,
3178 hda_nid_t nid, mix = 0;
3179 hda_nid_t srcs[HDA_MAX_CONNECTIONS];
3181 alc_set_pin_output(codec, pin, pin_type);
3182 nid = alc_go_down_to_selector(codec, pin);
3183 num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
3184 for (i = 0; i < num; i++) {
3185 if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
3193 /* need the manual connection? */
3195 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
3196 /* unmute mixer widget inputs */
3197 if (nid_has_mute(codec, mix, HDA_INPUT)) {
3198 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3200 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3203 /* initialize volume */
3204 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3206 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3210 static void alc_auto_init_multi_out(struct hda_codec *codec)
3212 struct alc_spec *spec = codec->spec;
3213 int pin_type = get_pin_type(spec->autocfg.line_out_type);
3216 for (i = 0; i <= HDA_SIDE; i++) {
3217 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3219 alc_auto_set_output_and_unmute(codec, nid, pin_type,
3220 spec->multiout.dac_nids[i]);
3224 static void alc_auto_init_extra_out(struct hda_codec *codec)
3226 struct alc_spec *spec = codec->spec;
3230 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3231 pin = spec->autocfg.hp_pins[i];
3234 dac = spec->multiout.hp_out_nid[i];
3236 if (i > 0 && spec->multiout.hp_out_nid[0])
3237 dac = spec->multiout.hp_out_nid[0];
3239 dac = spec->multiout.dac_nids[0];
3241 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
3243 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3244 pin = spec->autocfg.speaker_pins[i];
3247 dac = spec->multiout.extra_out_nid[i];
3249 if (i > 0 && spec->multiout.extra_out_nid[0])
3250 dac = spec->multiout.extra_out_nid[0];
3252 dac = spec->multiout.dac_nids[0];
3254 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
3261 static int alc_auto_fill_multi_ios(struct hda_codec *codec,
3262 unsigned int location)
3264 struct alc_spec *spec = codec->spec;
3265 struct auto_pin_cfg *cfg = &spec->autocfg;
3266 int type, i, num_pins = 0;
3268 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3269 for (i = 0; i < cfg->num_inputs; i++) {
3270 hda_nid_t nid = cfg->inputs[i].pin;
3272 unsigned int defcfg, caps;
3273 if (cfg->inputs[i].type != type)
3275 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3276 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3278 if (location && get_defcfg_location(defcfg) != location)
3280 caps = snd_hda_query_pin_caps(codec, nid);
3281 if (!(caps & AC_PINCAP_OUT))
3283 dac = alc_auto_look_for_dac(codec, nid);
3286 spec->multi_io[num_pins].pin = nid;
3287 spec->multi_io[num_pins].dac = dac;
3289 spec->private_dac_nids[spec->multiout.num_dacs++] = dac;
3292 spec->multiout.num_dacs = 1;
3298 static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
3299 struct snd_ctl_elem_info *uinfo)
3301 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3302 struct alc_spec *spec = codec->spec;
3304 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3306 uinfo->value.enumerated.items = spec->multi_ios + 1;
3307 if (uinfo->value.enumerated.item > spec->multi_ios)
3308 uinfo->value.enumerated.item = spec->multi_ios;
3309 sprintf(uinfo->value.enumerated.name, "%dch",
3310 (uinfo->value.enumerated.item + 1) * 2);
3314 static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
3315 struct snd_ctl_elem_value *ucontrol)
3317 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3318 struct alc_spec *spec = codec->spec;
3319 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
3323 static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
3325 struct alc_spec *spec = codec->spec;
3326 hda_nid_t nid = spec->multi_io[idx].pin;
3328 if (!spec->multi_io[idx].ctl_in)
3329 spec->multi_io[idx].ctl_in =
3330 snd_hda_codec_read(codec, nid, 0,
3331 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3333 snd_hda_codec_update_cache(codec, nid, 0,
3334 AC_VERB_SET_PIN_WIDGET_CONTROL,
3336 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3337 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3339 alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
3341 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3342 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3343 HDA_AMP_MUTE, HDA_AMP_MUTE);
3344 snd_hda_codec_update_cache(codec, nid, 0,
3345 AC_VERB_SET_PIN_WIDGET_CONTROL,
3346 spec->multi_io[idx].ctl_in);
3351 static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
3352 struct snd_ctl_elem_value *ucontrol)
3354 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3355 struct alc_spec *spec = codec->spec;
3358 ch = ucontrol->value.enumerated.item[0];
3359 if (ch < 0 || ch > spec->multi_ios)
3361 if (ch == (spec->ext_channel_count - 1) / 2)
3363 spec->ext_channel_count = (ch + 1) * 2;
3364 for (i = 0; i < spec->multi_ios; i++)
3365 alc_set_multi_io(codec, i, i < ch);
3366 spec->multiout.max_channels = spec->ext_channel_count;
3367 if (spec->need_dac_fix && !spec->const_channel_count)
3368 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
3372 static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
3373 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3374 .name = "Channel Mode",
3375 .info = alc_auto_ch_mode_info,
3376 .get = alc_auto_ch_mode_get,
3377 .put = alc_auto_ch_mode_put,
3380 static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
3382 struct alc_spec *spec = codec->spec;
3383 struct auto_pin_cfg *cfg = &spec->autocfg;
3384 unsigned int location, defcfg;
3387 if (cfg->line_outs != 1 ||
3388 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
3391 defcfg = snd_hda_codec_get_pincfg(codec, cfg->line_out_pins[0]);
3392 location = get_defcfg_location(defcfg);
3394 num_pins = alc_auto_fill_multi_ios(codec, location);
3396 struct snd_kcontrol_new *knew;
3398 knew = alc_kcontrol_new(spec);
3401 *knew = alc_auto_channel_mode_enum;
3402 knew->name = kstrdup("Channel Mode", GFP_KERNEL);
3406 spec->multi_ios = num_pins;
3407 spec->ext_channel_count = 2;
3408 spec->multiout.num_dacs = num_pins + 1;
3413 /* filter out invalid adc_nids (and capsrc_nids) that don't give all
3416 static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
3418 struct alc_spec *spec = codec->spec;
3419 const struct hda_input_mux *imux;
3420 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3421 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3424 imux = spec->input_mux;
3427 if (spec->dyn_adc_switch)
3431 for (n = 0; n < spec->num_adc_nids; n++) {
3432 hda_nid_t cap = spec->private_capsrc_nids[n];
3433 int num_conns = snd_hda_get_conn_list(codec, cap, NULL);
3434 for (i = 0; i < imux->num_items; i++) {
3435 hda_nid_t pin = spec->imux_pins[i];
3437 if (get_connection_index(codec, cap, pin) < 0)
3439 } else if (num_conns <= imux->items[i].index)
3442 if (i >= imux->num_items) {
3443 adc_nids[nums] = spec->private_adc_nids[n];
3444 capsrc_nids[nums++] = cap;
3448 /* check whether ADC-switch is possible */
3449 if (!alc_check_dyn_adc_switch(codec)) {
3450 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
3451 " using fallback 0x%x\n",
3452 codec->chip_name, spec->private_adc_nids[0]);
3453 spec->num_adc_nids = 1;
3457 } else if (nums != spec->num_adc_nids) {
3458 memcpy(spec->private_adc_nids, adc_nids,
3459 nums * sizeof(hda_nid_t));
3460 memcpy(spec->private_capsrc_nids, capsrc_nids,
3461 nums * sizeof(hda_nid_t));
3462 spec->num_adc_nids = nums;
3466 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
3467 else if (spec->input_mux->num_items == 1)
3468 spec->num_adc_nids = 1; /* reduce to a single ADC */
3472 * initialize ADC paths
3474 static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
3476 struct alc_spec *spec = codec->spec;
3479 nid = spec->adc_nids[adc_idx];
3481 if (nid_has_mute(codec, nid, HDA_INPUT)) {
3482 snd_hda_codec_write(codec, nid, 0,
3483 AC_VERB_SET_AMP_GAIN_MUTE,
3487 if (!spec->capsrc_nids)
3489 nid = spec->capsrc_nids[adc_idx];
3490 if (nid_has_mute(codec, nid, HDA_OUTPUT))
3491 snd_hda_codec_write(codec, nid, 0,
3492 AC_VERB_SET_AMP_GAIN_MUTE,
3496 static void alc_auto_init_input_src(struct hda_codec *codec)
3498 struct alc_spec *spec = codec->spec;
3501 for (c = 0; c < spec->num_adc_nids; c++)
3502 alc_auto_init_adc(codec, c);
3503 if (spec->dyn_adc_switch)
3506 nums = spec->num_adc_nids;
3507 for (c = 0; c < nums; c++)
3508 alc_mux_select(codec, 0, spec->cur_mux[c], true);
3511 /* add mic boosts if needed */
3512 static int alc_auto_add_mic_boost(struct hda_codec *codec)
3514 struct alc_spec *spec = codec->spec;
3515 struct auto_pin_cfg *cfg = &spec->autocfg;
3519 const char *prev_label = NULL;
3521 for (i = 0; i < cfg->num_inputs; i++) {
3522 if (cfg->inputs[i].type > AUTO_PIN_MIC)
3524 nid = cfg->inputs[i].pin;
3525 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
3527 char boost_label[32];
3529 label = hda_get_autocfg_input_label(codec, cfg, i);
3530 if (prev_label && !strcmp(label, prev_label))
3536 snprintf(boost_label, sizeof(boost_label),
3537 "%s Boost Volume", label);
3538 err = add_control(spec, ALC_CTL_WIDGET_VOL,
3539 boost_label, type_idx,
3540 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
3548 /* select or unmute the given capsrc route */
3549 static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
3552 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
3553 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
3555 } else if (snd_hda_get_conn_list(codec, cap, NULL) > 1) {
3556 snd_hda_codec_write_cache(codec, cap, 0,
3557 AC_VERB_SET_CONNECT_SEL, idx);
3561 /* set the default connection to that pin */
3562 static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
3564 struct alc_spec *spec = codec->spec;
3569 for (i = 0; i < spec->num_adc_nids; i++) {
3570 hda_nid_t cap = spec->capsrc_nids ?
3571 spec->capsrc_nids[i] : spec->adc_nids[i];
3574 idx = get_connection_index(codec, cap, pin);
3577 select_or_unmute_capsrc(codec, cap, idx);
3578 return i; /* return the found index */
3580 return -1; /* not found */
3583 /* initialize some special cases for input sources */
3584 static void alc_init_special_input_src(struct hda_codec *codec)
3586 struct alc_spec *spec = codec->spec;
3589 for (i = 0; i < spec->autocfg.num_inputs; i++)
3590 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
3593 /* assign appropriate capture mixers */
3594 static void set_capture_mixer(struct hda_codec *codec)
3596 struct alc_spec *spec = codec->spec;
3597 static const struct snd_kcontrol_new *caps[2][3] = {
3598 { alc_capture_mixer_nosrc1,
3599 alc_capture_mixer_nosrc2,
3600 alc_capture_mixer_nosrc3 },
3601 { alc_capture_mixer1,
3603 alc_capture_mixer3 },
3606 /* check whether either of ADC or MUX has a volume control */
3607 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
3608 if (!spec->capsrc_nids)
3609 return; /* no volume */
3610 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
3611 return; /* no volume in capsrc, too */
3612 spec->vol_in_capsrc = 1;
3615 if (spec->num_adc_nids > 0) {
3619 if (spec->input_mux && spec->input_mux->num_items > 1)
3621 if (spec->auto_mic) {
3624 } else if (spec->dyn_adc_switch)
3627 if (spec->num_adc_nids > 3)
3628 spec->num_adc_nids = 3;
3629 else if (!spec->num_adc_nids)
3631 num_adcs = spec->num_adc_nids;
3633 spec->cap_mixer = caps[mux][num_adcs - 1];
3638 * standard auto-parser initializations
3640 static void alc_auto_init_std(struct hda_codec *codec)
3642 struct alc_spec *spec = codec->spec;
3643 alc_auto_init_multi_out(codec);
3644 alc_auto_init_extra_out(codec);
3645 alc_auto_init_analog_input(codec);
3646 alc_auto_init_input_src(codec);
3647 alc_auto_init_digital(codec);
3648 if (spec->unsol_event)
3649 alc_inithook(codec);
3653 * Digital-beep handlers
3655 #ifdef CONFIG_SND_HDA_INPUT_BEEP
3656 #define set_beep_amp(spec, nid, idx, dir) \
3657 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
3659 static const struct snd_pci_quirk beep_white_list[] = {
3660 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
3661 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
3662 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
3663 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
3664 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
3668 static inline int has_cdefine_beep(struct hda_codec *codec)
3670 struct alc_spec *spec = codec->spec;
3671 const struct snd_pci_quirk *q;
3672 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
3675 return spec->cdefine.enable_pcbeep;
3678 #define set_beep_amp(spec, nid, idx, dir) /* NOP */
3679 #define has_cdefine_beep(codec) 0
3682 /* parse the BIOS configuration and set up the alc_spec */
3683 /* return 1 if successful, 0 if the proper config is not found,
3684 * or a negative error code
3686 static int alc_parse_auto_config(struct hda_codec *codec,
3687 const hda_nid_t *ignore_nids,
3688 const hda_nid_t *ssid_nids)
3690 struct alc_spec *spec = codec->spec;
3691 struct auto_pin_cfg *cfg = &spec->autocfg;
3694 err = snd_hda_parse_pin_def_config(codec, cfg, ignore_nids);
3697 if (!cfg->line_outs) {
3698 if (cfg->dig_outs || cfg->dig_in_pin) {
3699 spec->multiout.max_channels = 2;
3700 spec->no_analog = 1;
3703 return 0; /* can't find valid BIOS pin config */
3706 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT && cfg->hp_outs > 0) {
3707 /* use HP as primary out */
3708 cfg->speaker_outs = cfg->line_outs;
3709 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3710 sizeof(cfg->speaker_pins));
3711 cfg->line_outs = cfg->hp_outs;
3712 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
3714 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3715 cfg->line_out_type = AUTO_PIN_HP_OUT;
3718 err = alc_auto_fill_dac_nids(codec);
3721 err = alc_auto_add_multi_channel_mode(codec);
3724 err = alc_auto_fill_extra_dacs(codec);
3727 err = alc_auto_create_multi_out_ctls(codec, cfg);
3730 err = alc_auto_create_hp_out(codec);
3733 err = alc_auto_create_speaker_out(codec);
3736 err = alc_auto_create_input_ctls(codec);
3740 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3743 alc_auto_parse_digital(codec);
3745 if (!spec->no_analog)
3746 alc_remove_invalid_adc_nids(codec);
3749 alc_ssid_check(codec, ssid_nids);
3751 if (!spec->no_analog) {
3752 alc_auto_check_switches(codec);
3753 err = alc_auto_add_mic_boost(codec);
3758 if (spec->kctls.list)
3759 add_mixer(spec, spec->kctls.list);
3764 static int alc880_parse_auto_config(struct hda_codec *codec)
3766 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
3767 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
3768 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
3771 #ifdef CONFIG_SND_HDA_POWER_SAVE
3772 static const struct hda_amp_list alc880_loopbacks[] = {
3773 { 0x0b, HDA_INPUT, 0 },
3774 { 0x0b, HDA_INPUT, 1 },
3775 { 0x0b, HDA_INPUT, 2 },
3776 { 0x0b, HDA_INPUT, 3 },
3777 { 0x0b, HDA_INPUT, 4 },
3785 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3786 #define alc_board_config \
3787 snd_hda_check_board_config
3788 #define alc_board_codec_sid_config \
3789 snd_hda_check_board_codec_sid_config
3790 #include "alc_quirks.c"
3792 #define alc_board_config(codec, nums, models, tbl) -1
3793 #define alc_board_codec_sid_config(codec, nums, models, tbl) -1
3794 #define setup_preset(codec, x) /* NOP */
3798 * OK, here we have finally the patch for ALC880
3800 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3801 #include "alc880_quirks.c"
3804 static int patch_alc880(struct hda_codec *codec)
3806 struct alc_spec *spec;
3810 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3816 spec->mixer_nid = 0x0b;
3817 spec->need_dac_fix = 1;
3819 board_config = alc_board_config(codec, ALC880_MODEL_LAST,
3820 alc880_models, alc880_cfg_tbl);
3821 if (board_config < 0) {
3822 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
3824 board_config = ALC_MODEL_AUTO;
3827 if (board_config == ALC_MODEL_AUTO) {
3828 /* automatic parse from the BIOS config */
3829 err = alc880_parse_auto_config(codec);
3834 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3837 "hda_codec: Cannot set up configuration "
3838 "from BIOS. Using 3-stack mode...\n");
3839 board_config = ALC880_3ST;
3844 if (board_config != ALC_MODEL_AUTO)
3845 setup_preset(codec, &alc880_presets[board_config]);
3847 if (!spec->no_analog && !spec->adc_nids) {
3848 alc_auto_fill_adc_caps(codec);
3849 alc_rebuild_imux_for_auto_mic(codec);
3850 alc_remove_invalid_adc_nids(codec);
3853 if (!spec->no_analog && !spec->cap_mixer)
3854 set_capture_mixer(codec);
3856 if (!spec->no_analog) {
3857 err = snd_hda_attach_beep_device(codec, 0x1);
3862 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
3865 spec->vmaster_nid = 0x0c;
3867 codec->patch_ops = alc_patch_ops;
3868 if (board_config == ALC_MODEL_AUTO)
3869 spec->init_hook = alc_auto_init_std;
3870 #ifdef CONFIG_SND_HDA_POWER_SAVE
3871 if (!spec->loopback.amplist)
3872 spec->loopback.amplist = alc880_loopbacks;
3882 static int alc260_parse_auto_config(struct hda_codec *codec)
3884 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
3885 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
3886 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
3889 #ifdef CONFIG_SND_HDA_POWER_SAVE
3890 static const struct hda_amp_list alc260_loopbacks[] = {
3891 { 0x07, HDA_INPUT, 0 },
3892 { 0x07, HDA_INPUT, 1 },
3893 { 0x07, HDA_INPUT, 2 },
3894 { 0x07, HDA_INPUT, 3 },
3895 { 0x07, HDA_INPUT, 4 },
3907 static const struct alc_fixup alc260_fixups[] = {
3908 [PINFIX_HP_DC5750] = {
3909 .type = ALC_FIXUP_PINS,
3910 .v.pins = (const struct alc_pincfg[]) {
3911 { 0x11, 0x90130110 }, /* speaker */
3917 static const struct snd_pci_quirk alc260_fixup_tbl[] = {
3918 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", PINFIX_HP_DC5750),
3924 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3925 #include "alc260_quirks.c"
3928 static int patch_alc260(struct hda_codec *codec)
3930 struct alc_spec *spec;
3931 int err, board_config;
3933 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3939 spec->mixer_nid = 0x07;
3941 board_config = alc_board_config(codec, ALC260_MODEL_LAST,
3942 alc260_models, alc260_cfg_tbl);
3943 if (board_config < 0) {
3944 snd_printd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
3946 board_config = ALC_MODEL_AUTO;
3949 if (board_config == ALC_MODEL_AUTO) {
3950 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
3951 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
3954 if (board_config == ALC_MODEL_AUTO) {
3955 /* automatic parse from the BIOS config */
3956 err = alc260_parse_auto_config(codec);
3961 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3964 "hda_codec: Cannot set up configuration "
3965 "from BIOS. Using base mode...\n");
3966 board_config = ALC260_BASIC;
3971 if (board_config != ALC_MODEL_AUTO)
3972 setup_preset(codec, &alc260_presets[board_config]);
3974 if (!spec->no_analog && !spec->adc_nids) {
3975 alc_auto_fill_adc_caps(codec);
3976 alc_rebuild_imux_for_auto_mic(codec);
3977 alc_remove_invalid_adc_nids(codec);
3980 if (!spec->no_analog && !spec->cap_mixer)
3981 set_capture_mixer(codec);
3983 if (!spec->no_analog) {
3984 err = snd_hda_attach_beep_device(codec, 0x1);
3989 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
3992 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
3994 spec->vmaster_nid = 0x08;
3996 codec->patch_ops = alc_patch_ops;
3997 if (board_config == ALC_MODEL_AUTO)
3998 spec->init_hook = alc_auto_init_std;
3999 spec->shutup = alc_eapd_shutup;
4000 #ifdef CONFIG_SND_HDA_POWER_SAVE
4001 if (!spec->loopback.amplist)
4002 spec->loopback.amplist = alc260_loopbacks;
4010 * ALC882/883/885/888/889 support
4012 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
4013 * configuration. Each pin widget can choose any input DACs and a mixer.
4014 * Each ADC is connected from a mixer of all inputs. This makes possible
4015 * 6-channel independent captures.
4017 * In addition, an independent DAC for the multi-playback (not used in this
4020 #ifdef CONFIG_SND_HDA_POWER_SAVE
4021 #define alc882_loopbacks alc880_loopbacks
4028 PINFIX_ABIT_AW9D_MAX,
4031 PINFIX_ACER_ASPIRE_7736,
4034 static const struct alc_fixup alc882_fixups[] = {
4035 [PINFIX_ABIT_AW9D_MAX] = {
4036 .type = ALC_FIXUP_PINS,
4037 .v.pins = (const struct alc_pincfg[]) {
4038 { 0x15, 0x01080104 }, /* side */
4039 { 0x16, 0x01011012 }, /* rear */
4040 { 0x17, 0x01016011 }, /* clfe */
4044 [PINFIX_LENOVO_Y530] = {
4045 .type = ALC_FIXUP_PINS,
4046 .v.pins = (const struct alc_pincfg[]) {
4047 { 0x15, 0x99130112 }, /* rear int speakers */
4048 { 0x16, 0x99130111 }, /* subwoofer */
4052 [PINFIX_PB_M5210] = {
4053 .type = ALC_FIXUP_VERBS,
4054 .v.verbs = (const struct hda_verb[]) {
4055 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
4059 [PINFIX_ACER_ASPIRE_7736] = {
4060 .type = ALC_FIXUP_SKU,
4061 .v.sku = ALC_FIXUP_SKU_IGNORE,
4065 static const struct snd_pci_quirk alc882_fixup_tbl[] = {
4066 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", PINFIX_PB_M5210),
4067 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", PINFIX_LENOVO_Y530),
4068 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
4069 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", PINFIX_ACER_ASPIRE_7736),
4074 * BIOS auto configuration
4076 /* almost identical with ALC880 parser... */
4077 static int alc882_parse_auto_config(struct hda_codec *codec)
4079 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
4080 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4081 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
4086 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4087 #include "alc882_quirks.c"
4090 static int patch_alc882(struct hda_codec *codec)
4092 struct alc_spec *spec;
4093 int err, board_config;
4095 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4101 spec->mixer_nid = 0x0b;
4103 switch (codec->vendor_id) {
4108 /* ALC883 and variants */
4109 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
4113 board_config = alc_board_config(codec, ALC882_MODEL_LAST,
4114 alc882_models, alc882_cfg_tbl);
4116 if (board_config < 0)
4117 board_config = alc_board_codec_sid_config(codec,
4118 ALC882_MODEL_LAST, alc882_models, alc882_ssid_cfg_tbl);
4120 if (board_config < 0) {
4121 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4123 board_config = ALC_MODEL_AUTO;
4126 if (board_config == ALC_MODEL_AUTO) {
4127 alc_pick_fixup(codec, NULL, alc882_fixup_tbl, alc882_fixups);
4128 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4131 alc_auto_parse_customize_define(codec);
4133 if (board_config == ALC_MODEL_AUTO) {
4134 /* automatic parse from the BIOS config */
4135 err = alc882_parse_auto_config(codec);
4140 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4143 "hda_codec: Cannot set up configuration "
4144 "from BIOS. Using base mode...\n");
4145 board_config = ALC882_3ST_DIG;
4150 if (board_config != ALC_MODEL_AUTO)
4151 setup_preset(codec, &alc882_presets[board_config]);
4153 if (!spec->no_analog && !spec->adc_nids) {
4154 alc_auto_fill_adc_caps(codec);
4155 alc_rebuild_imux_for_auto_mic(codec);
4156 alc_remove_invalid_adc_nids(codec);
4159 if (!spec->no_analog && !spec->cap_mixer)
4160 set_capture_mixer(codec);
4162 if (!spec->no_analog && has_cdefine_beep(codec)) {
4163 err = snd_hda_attach_beep_device(codec, 0x1);
4168 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4171 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4173 spec->vmaster_nid = 0x0c;
4175 codec->patch_ops = alc_patch_ops;
4176 if (board_config == ALC_MODEL_AUTO)
4177 spec->init_hook = alc_auto_init_std;
4179 alc_init_jacks(codec);
4180 #ifdef CONFIG_SND_HDA_POWER_SAVE
4181 if (!spec->loopback.amplist)
4182 spec->loopback.amplist = alc882_loopbacks;
4192 static int alc262_parse_auto_config(struct hda_codec *codec)
4194 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
4195 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4196 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
4207 static const struct alc_fixup alc262_fixups[] = {
4208 [PINFIX_FSC_H270] = {
4209 .type = ALC_FIXUP_PINS,
4210 .v.pins = (const struct alc_pincfg[]) {
4211 { 0x14, 0x99130110 }, /* speaker */
4212 { 0x15, 0x0221142f }, /* front HP */
4213 { 0x1b, 0x0121141f }, /* rear HP */
4217 [PINFIX_HP_Z200] = {
4218 .type = ALC_FIXUP_PINS,
4219 .v.pins = (const struct alc_pincfg[]) {
4220 { 0x16, 0x99130120 }, /* internal speaker */
4226 static const struct snd_pci_quirk alc262_fixup_tbl[] = {
4227 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", PINFIX_HP_Z200),
4228 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", PINFIX_FSC_H270),
4233 #ifdef CONFIG_SND_HDA_POWER_SAVE
4234 #define alc262_loopbacks alc880_loopbacks
4239 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4240 #include "alc262_quirks.c"
4243 static int patch_alc262(struct hda_codec *codec)
4245 struct alc_spec *spec;
4249 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4255 spec->mixer_nid = 0x0b;
4258 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
4263 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4264 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
4265 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4266 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
4269 alc_auto_parse_customize_define(codec);
4271 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
4273 board_config = alc_board_config(codec, ALC262_MODEL_LAST,
4274 alc262_models, alc262_cfg_tbl);
4276 if (board_config < 0) {
4277 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4279 board_config = ALC_MODEL_AUTO;
4282 if (board_config == ALC_MODEL_AUTO) {
4283 alc_pick_fixup(codec, NULL, alc262_fixup_tbl, alc262_fixups);
4284 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4287 if (board_config == ALC_MODEL_AUTO) {
4288 /* automatic parse from the BIOS config */
4289 err = alc262_parse_auto_config(codec);
4294 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4297 "hda_codec: Cannot set up configuration "
4298 "from BIOS. Using base mode...\n");
4299 board_config = ALC262_BASIC;
4304 if (board_config != ALC_MODEL_AUTO)
4305 setup_preset(codec, &alc262_presets[board_config]);
4307 if (!spec->no_analog && !spec->adc_nids) {
4308 alc_auto_fill_adc_caps(codec);
4309 alc_rebuild_imux_for_auto_mic(codec);
4310 alc_remove_invalid_adc_nids(codec);
4313 if (!spec->no_analog && !spec->cap_mixer)
4314 set_capture_mixer(codec);
4316 if (!spec->no_analog && has_cdefine_beep(codec)) {
4317 err = snd_hda_attach_beep_device(codec, 0x1);
4322 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4325 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4327 spec->vmaster_nid = 0x0c;
4329 codec->patch_ops = alc_patch_ops;
4330 if (board_config == ALC_MODEL_AUTO)
4331 spec->init_hook = alc_auto_init_std;
4332 spec->shutup = alc_eapd_shutup;
4334 alc_init_jacks(codec);
4335 #ifdef CONFIG_SND_HDA_POWER_SAVE
4336 if (!spec->loopback.amplist)
4337 spec->loopback.amplist = alc262_loopbacks;
4346 /* bind Beep switches of both NID 0x0f and 0x10 */
4347 static const struct hda_bind_ctls alc268_bind_beep_sw = {
4348 .ops = &snd_hda_bind_sw,
4350 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
4351 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
4356 static const struct snd_kcontrol_new alc268_beep_mixer[] = {
4357 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
4358 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
4362 /* set PCBEEP vol = 0, mute connections */
4363 static const struct hda_verb alc268_beep_init_verbs[] = {
4364 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4365 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4366 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4371 * BIOS auto configuration
4373 static int alc268_parse_auto_config(struct hda_codec *codec)
4375 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4376 struct alc_spec *spec = codec->spec;
4377 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
4379 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
4380 add_mixer(spec, alc268_beep_mixer);
4381 add_verb(spec, alc268_beep_init_verbs);
4389 static int patch_alc268(struct hda_codec *codec)
4391 struct alc_spec *spec;
4392 int i, has_beep, err;
4394 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4400 /* ALC268 has no aa-loopback mixer */
4402 /* automatic parse from the BIOS config */
4403 err = alc268_parse_auto_config(codec);
4410 for (i = 0; i < spec->num_mixers; i++) {
4411 if (spec->mixers[i] == alc268_beep_mixer) {
4418 err = snd_hda_attach_beep_device(codec, 0x1);
4423 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
4424 /* override the amp caps for beep generator */
4425 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
4426 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
4427 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
4428 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4429 (0 << AC_AMPCAP_MUTE_SHIFT));
4432 if (!spec->no_analog && !spec->adc_nids) {
4433 alc_auto_fill_adc_caps(codec);
4434 alc_rebuild_imux_for_auto_mic(codec);
4435 alc_remove_invalid_adc_nids(codec);
4438 if (!spec->no_analog && !spec->cap_mixer)
4439 set_capture_mixer(codec);
4441 spec->vmaster_nid = 0x02;
4443 codec->patch_ops = alc_patch_ops;
4444 spec->init_hook = alc_auto_init_std;
4445 spec->shutup = alc_eapd_shutup;
4447 alc_init_jacks(codec);
4455 #ifdef CONFIG_SND_HDA_POWER_SAVE
4456 #define alc269_loopbacks alc880_loopbacks
4459 static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
4463 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
4464 /* NID is set in alc_build_pcms */
4466 .open = alc_playback_pcm_open,
4467 .prepare = alc_playback_pcm_prepare,
4468 .cleanup = alc_playback_pcm_cleanup
4472 static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
4476 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
4477 /* NID is set in alc_build_pcms */
4480 #ifdef CONFIG_SND_HDA_POWER_SAVE
4481 static int alc269_mic2_for_mute_led(struct hda_codec *codec)
4483 switch (codec->subsystem_id) {
4490 static int alc269_mic2_mute_check_ps(struct hda_codec *codec, hda_nid_t nid)
4492 /* update mute-LED according to the speaker mute state */
4493 if (nid == 0x01 || nid == 0x14) {
4495 if (snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0) &
4500 /* mic2 vref pin is used for mute LED control */
4501 snd_hda_codec_update_cache(codec, 0x19, 0,
4502 AC_VERB_SET_PIN_WIDGET_CONTROL,
4505 return alc_check_power_status(codec, nid);
4507 #endif /* CONFIG_SND_HDA_POWER_SAVE */
4509 /* different alc269-variants */
4511 ALC269_TYPE_ALC269VA,
4512 ALC269_TYPE_ALC269VB,
4513 ALC269_TYPE_ALC269VC,
4517 * BIOS auto configuration
4519 static int alc269_parse_auto_config(struct hda_codec *codec)
4521 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
4522 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
4523 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4524 struct alc_spec *spec = codec->spec;
4525 const hda_nid_t *ssids = spec->codec_variant == ALC269_TYPE_ALC269VA ?
4526 alc269va_ssids : alc269_ssids;
4528 return alc_parse_auto_config(codec, alc269_ignore, ssids);
4531 static void alc269_toggle_power_output(struct hda_codec *codec, int power_up)
4533 int val = alc_read_coef_idx(codec, 0x04);
4538 alc_write_coef_idx(codec, 0x04, val);
4541 static void alc269_shutup(struct hda_codec *codec)
4543 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x017)
4544 alc269_toggle_power_output(codec, 0);
4545 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x018) {
4546 alc269_toggle_power_output(codec, 0);
4552 static int alc269_resume(struct hda_codec *codec)
4554 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x018) {
4555 alc269_toggle_power_output(codec, 0);
4559 codec->patch_ops.init(codec);
4561 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x017) {
4562 alc269_toggle_power_output(codec, 1);
4566 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x018)
4567 alc269_toggle_power_output(codec, 1);
4569 snd_hda_codec_resume_amp(codec);
4570 snd_hda_codec_resume_cache(codec);
4571 hda_call_check_power_status(codec, 0x01);
4574 #endif /* CONFIG_PM */
4576 static void alc269_fixup_hweq(struct hda_codec *codec,
4577 const struct alc_fixup *fix, int action)
4581 if (action != ALC_FIXUP_ACT_INIT)
4583 coef = alc_read_coef_idx(codec, 0x1e);
4584 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
4587 static void alc271_fixup_dmic(struct hda_codec *codec,
4588 const struct alc_fixup *fix, int action)
4590 static const struct hda_verb verbs[] = {
4591 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
4592 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
4597 if (strcmp(codec->chip_name, "ALC271X"))
4599 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
4600 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
4601 snd_hda_sequence_write(codec, verbs);
4604 static void alc269_fixup_pcm_44k(struct hda_codec *codec,
4605 const struct alc_fixup *fix, int action)
4607 struct alc_spec *spec = codec->spec;
4609 if (action != ALC_FIXUP_ACT_PROBE)
4612 /* Due to a hardware problem on Lenovo Ideadpad, we need to
4613 * fix the sample rate of analog I/O to 44.1kHz
4615 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
4616 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
4619 static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
4620 const struct alc_fixup *fix, int action)
4624 if (action != ALC_FIXUP_ACT_INIT)
4626 /* The digital-mic unit sends PDM (differential signal) instead of
4627 * the standard PCM, thus you can't record a valid mono stream as is.
4628 * Below is a workaround specific to ALC269 to control the dmic
4629 * signal source as mono.
4631 coef = alc_read_coef_idx(codec, 0x07);
4632 alc_write_coef_idx(codec, 0x07, coef | 0x80);
4635 static void alc269_quanta_automute(struct hda_codec *codec)
4637 update_speakers(codec);
4639 snd_hda_codec_write(codec, 0x20, 0,
4640 AC_VERB_SET_COEF_INDEX, 0x0c);
4641 snd_hda_codec_write(codec, 0x20, 0,
4642 AC_VERB_SET_PROC_COEF, 0x680);
4644 snd_hda_codec_write(codec, 0x20, 0,
4645 AC_VERB_SET_COEF_INDEX, 0x0c);
4646 snd_hda_codec_write(codec, 0x20, 0,
4647 AC_VERB_SET_PROC_COEF, 0x480);
4650 static void alc269_fixup_quanta_mute(struct hda_codec *codec,
4651 const struct alc_fixup *fix, int action)
4653 struct alc_spec *spec = codec->spec;
4654 if (action != ALC_FIXUP_ACT_PROBE)
4656 spec->automute_hook = alc269_quanta_automute;
4660 ALC269_FIXUP_SONY_VAIO,
4661 ALC275_FIXUP_SONY_VAIO_GPIO2,
4662 ALC269_FIXUP_DELL_M101Z,
4663 ALC269_FIXUP_SKU_IGNORE,
4664 ALC269_FIXUP_ASUS_G73JW,
4665 ALC269_FIXUP_LENOVO_EAPD,
4666 ALC275_FIXUP_SONY_HWEQ,
4668 ALC269_FIXUP_PCM_44K,
4669 ALC269_FIXUP_STEREO_DMIC,
4670 ALC269_FIXUP_QUANTA_MUTE,
4671 ALC269_FIXUP_LIFEBOOK,
4674 static const struct alc_fixup alc269_fixups[] = {
4675 [ALC269_FIXUP_SONY_VAIO] = {
4676 .type = ALC_FIXUP_VERBS,
4677 .v.verbs = (const struct hda_verb[]) {
4678 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
4682 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
4683 .type = ALC_FIXUP_VERBS,
4684 .v.verbs = (const struct hda_verb[]) {
4685 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
4686 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
4687 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
4691 .chain_id = ALC269_FIXUP_SONY_VAIO
4693 [ALC269_FIXUP_DELL_M101Z] = {
4694 .type = ALC_FIXUP_VERBS,
4695 .v.verbs = (const struct hda_verb[]) {
4696 /* Enables internal speaker */
4697 {0x20, AC_VERB_SET_COEF_INDEX, 13},
4698 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
4702 [ALC269_FIXUP_SKU_IGNORE] = {
4703 .type = ALC_FIXUP_SKU,
4704 .v.sku = ALC_FIXUP_SKU_IGNORE,
4706 [ALC269_FIXUP_ASUS_G73JW] = {
4707 .type = ALC_FIXUP_PINS,
4708 .v.pins = (const struct alc_pincfg[]) {
4709 { 0x17, 0x99130111 }, /* subwoofer */
4713 [ALC269_FIXUP_LENOVO_EAPD] = {
4714 .type = ALC_FIXUP_VERBS,
4715 .v.verbs = (const struct hda_verb[]) {
4716 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
4720 [ALC275_FIXUP_SONY_HWEQ] = {
4721 .type = ALC_FIXUP_FUNC,
4722 .v.func = alc269_fixup_hweq,
4724 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
4726 [ALC271_FIXUP_DMIC] = {
4727 .type = ALC_FIXUP_FUNC,
4728 .v.func = alc271_fixup_dmic,
4730 [ALC269_FIXUP_PCM_44K] = {
4731 .type = ALC_FIXUP_FUNC,
4732 .v.func = alc269_fixup_pcm_44k,
4734 [ALC269_FIXUP_STEREO_DMIC] = {
4735 .type = ALC_FIXUP_FUNC,
4736 .v.func = alc269_fixup_stereo_dmic,
4738 [ALC269_FIXUP_QUANTA_MUTE] = {
4739 .type = ALC_FIXUP_FUNC,
4740 .v.func = alc269_fixup_quanta_mute,
4742 [ALC269_FIXUP_LIFEBOOK] = {
4743 .type = ALC_FIXUP_PINS,
4744 .v.pins = (const struct alc_pincfg[]) {
4745 { 0x1a, 0x2101103f }, /* dock line-out */
4746 { 0x1b, 0x23a11040 }, /* dock mic-in */
4750 .chain_id = ALC269_FIXUP_QUANTA_MUTE
4754 static const struct snd_pci_quirk alc269_fixup_tbl[] = {
4755 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
4756 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
4757 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
4758 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
4759 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
4760 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
4761 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
4762 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
4763 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
4764 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
4765 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
4766 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
4767 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
4768 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
4769 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
4770 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
4771 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
4772 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
4773 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_QUANTA_MUTE),
4774 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K),
4775 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
4780 static int alc269_fill_coef(struct hda_codec *codec)
4784 if ((alc_read_coef_idx(codec, 0) & 0x00ff) < 0x015) {
4785 alc_write_coef_idx(codec, 0xf, 0x960b);
4786 alc_write_coef_idx(codec, 0xe, 0x8817);
4789 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x016) {
4790 alc_write_coef_idx(codec, 0xf, 0x960b);
4791 alc_write_coef_idx(codec, 0xe, 0x8814);
4794 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x017) {
4795 val = alc_read_coef_idx(codec, 0x04);
4796 /* Power up output pin */
4797 alc_write_coef_idx(codec, 0x04, val | (1<<11));
4800 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x018) {
4801 val = alc_read_coef_idx(codec, 0xd);
4802 if ((val & 0x0c00) >> 10 != 0x1) {
4803 /* Capless ramp up clock control */
4804 alc_write_coef_idx(codec, 0xd, val | (1<<10));
4806 val = alc_read_coef_idx(codec, 0x17);
4807 if ((val & 0x01c0) >> 6 != 0x4) {
4808 /* Class D power on reset */
4809 alc_write_coef_idx(codec, 0x17, val | (1<<7));
4813 val = alc_read_coef_idx(codec, 0xd); /* Class D */
4814 alc_write_coef_idx(codec, 0xd, val | (1<<14));
4816 val = alc_read_coef_idx(codec, 0x4); /* HP */
4817 alc_write_coef_idx(codec, 0x4, val | (1<<11));
4824 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4825 #include "alc269_quirks.c"
4828 static int patch_alc269(struct hda_codec *codec)
4830 struct alc_spec *spec;
4831 int board_config, coef;
4834 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4840 spec->mixer_nid = 0x0b;
4842 alc_auto_parse_customize_define(codec);
4844 if (codec->vendor_id == 0x10ec0269) {
4845 spec->codec_variant = ALC269_TYPE_ALC269VA;
4846 coef = alc_read_coef_idx(codec, 0);
4847 if ((coef & 0x00f0) == 0x0010) {
4848 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
4849 spec->cdefine.platform_type == 1) {
4850 alc_codec_rename(codec, "ALC271X");
4851 } else if ((coef & 0xf000) == 0x2000) {
4852 alc_codec_rename(codec, "ALC259");
4853 } else if ((coef & 0xf000) == 0x3000) {
4854 alc_codec_rename(codec, "ALC258");
4855 } else if ((coef & 0xfff0) == 0x3010) {
4856 alc_codec_rename(codec, "ALC277");
4858 alc_codec_rename(codec, "ALC269VB");
4860 spec->codec_variant = ALC269_TYPE_ALC269VB;
4861 } else if ((coef & 0x00f0) == 0x0020) {
4863 alc_codec_rename(codec, "ALC259");
4864 else if (coef == 0x6023)
4865 alc_codec_rename(codec, "ALC281X");
4866 else if (codec->bus->pci->subsystem_vendor == 0x17aa &&
4867 codec->bus->pci->subsystem_device == 0x21f3)
4868 alc_codec_rename(codec, "ALC3202");
4870 alc_codec_rename(codec, "ALC269VC");
4871 spec->codec_variant = ALC269_TYPE_ALC269VC;
4873 alc_fix_pll_init(codec, 0x20, 0x04, 15);
4874 alc269_fill_coef(codec);
4877 board_config = alc_board_config(codec, ALC269_MODEL_LAST,
4878 alc269_models, alc269_cfg_tbl);
4880 if (board_config < 0) {
4881 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4883 board_config = ALC_MODEL_AUTO;
4886 if (board_config == ALC_MODEL_AUTO) {
4887 alc_pick_fixup(codec, NULL, alc269_fixup_tbl, alc269_fixups);
4888 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4891 if (board_config == ALC_MODEL_AUTO) {
4892 /* automatic parse from the BIOS config */
4893 err = alc269_parse_auto_config(codec);
4898 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4901 "hda_codec: Cannot set up configuration "
4902 "from BIOS. Using base mode...\n");
4903 board_config = ALC269_BASIC;
4908 if (board_config != ALC_MODEL_AUTO)
4909 setup_preset(codec, &alc269_presets[board_config]);
4911 if (!spec->no_analog && !spec->adc_nids) {
4912 alc_auto_fill_adc_caps(codec);
4913 alc_rebuild_imux_for_auto_mic(codec);
4914 alc_remove_invalid_adc_nids(codec);
4917 if (!spec->no_analog && !spec->cap_mixer)
4918 set_capture_mixer(codec);
4920 if (!spec->no_analog && has_cdefine_beep(codec)) {
4921 err = snd_hda_attach_beep_device(codec, 0x1);
4926 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
4929 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4931 spec->vmaster_nid = 0x02;
4933 codec->patch_ops = alc_patch_ops;
4935 codec->patch_ops.resume = alc269_resume;
4937 if (board_config == ALC_MODEL_AUTO)
4938 spec->init_hook = alc_auto_init_std;
4939 spec->shutup = alc269_shutup;
4941 alc_init_jacks(codec);
4942 #ifdef CONFIG_SND_HDA_POWER_SAVE
4943 if (!spec->loopback.amplist)
4944 spec->loopback.amplist = alc269_loopbacks;
4945 if (alc269_mic2_for_mute_led(codec))
4946 codec->patch_ops.check_power_status = alc269_mic2_mute_check_ps;
4956 static int alc861_parse_auto_config(struct hda_codec *codec)
4958 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
4959 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
4960 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
4963 #ifdef CONFIG_SND_HDA_POWER_SAVE
4964 static const struct hda_amp_list alc861_loopbacks[] = {
4965 { 0x15, HDA_INPUT, 0 },
4966 { 0x15, HDA_INPUT, 1 },
4967 { 0x15, HDA_INPUT, 2 },
4968 { 0x15, HDA_INPUT, 3 },
4974 /* Pin config fixes */
4976 PINFIX_FSC_AMILO_PI1505,
4979 static const struct alc_fixup alc861_fixups[] = {
4980 [PINFIX_FSC_AMILO_PI1505] = {
4981 .type = ALC_FIXUP_PINS,
4982 .v.pins = (const struct alc_pincfg[]) {
4983 { 0x0b, 0x0221101f }, /* HP */
4984 { 0x0f, 0x90170310 }, /* speaker */
4990 static const struct snd_pci_quirk alc861_fixup_tbl[] = {
4991 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", PINFIX_FSC_AMILO_PI1505),
4997 static int patch_alc861(struct hda_codec *codec)
4999 struct alc_spec *spec;
5002 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5008 spec->mixer_nid = 0x15;
5010 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
5011 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5013 /* automatic parse from the BIOS config */
5014 err = alc861_parse_auto_config(codec);
5020 if (!spec->no_analog && !spec->adc_nids) {
5021 alc_auto_fill_adc_caps(codec);
5022 alc_rebuild_imux_for_auto_mic(codec);
5023 alc_remove_invalid_adc_nids(codec);
5026 if (!spec->no_analog && !spec->cap_mixer)
5027 set_capture_mixer(codec);
5029 if (!spec->no_analog) {
5030 err = snd_hda_attach_beep_device(codec, 0x23);
5035 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
5038 spec->vmaster_nid = 0x03;
5040 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5042 codec->patch_ops = alc_patch_ops;
5043 spec->init_hook = alc_auto_init_std;
5044 #ifdef CONFIG_SND_HDA_POWER_SAVE
5045 spec->power_hook = alc_power_eapd;
5046 if (!spec->loopback.amplist)
5047 spec->loopback.amplist = alc861_loopbacks;
5058 * In addition, an independent DAC
5060 #ifdef CONFIG_SND_HDA_POWER_SAVE
5061 #define alc861vd_loopbacks alc880_loopbacks
5064 static int alc861vd_parse_auto_config(struct hda_codec *codec)
5066 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
5067 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5068 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
5072 ALC660VD_FIX_ASUS_GPIO1,
5073 ALC861VD_FIX_DALLAS,
5076 /* exclude VREF80 */
5077 static void alc861vd_fixup_dallas(struct hda_codec *codec,
5078 const struct alc_fixup *fix, int action)
5080 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
5081 snd_hda_override_pin_caps(codec, 0x18, 0x00001714);
5082 snd_hda_override_pin_caps(codec, 0x19, 0x0000171c);
5086 static const struct alc_fixup alc861vd_fixups[] = {
5087 [ALC660VD_FIX_ASUS_GPIO1] = {
5088 .type = ALC_FIXUP_VERBS,
5089 .v.verbs = (const struct hda_verb[]) {
5091 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
5092 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5093 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5097 [ALC861VD_FIX_DALLAS] = {
5098 .type = ALC_FIXUP_FUNC,
5099 .v.func = alc861vd_fixup_dallas,
5103 static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
5104 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
5105 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
5106 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
5110 static const struct hda_verb alc660vd_eapd_verbs[] = {
5111 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
5112 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
5118 static int patch_alc861vd(struct hda_codec *codec)
5120 struct alc_spec *spec;
5123 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5129 spec->mixer_nid = 0x0b;
5131 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
5132 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5134 /* automatic parse from the BIOS config */
5135 err = alc861vd_parse_auto_config(codec);
5141 if (codec->vendor_id == 0x10ec0660) {
5142 /* always turn on EAPD */
5143 add_verb(spec, alc660vd_eapd_verbs);
5146 if (!spec->no_analog && !spec->adc_nids) {
5147 alc_auto_fill_adc_caps(codec);
5148 alc_rebuild_imux_for_auto_mic(codec);
5149 alc_remove_invalid_adc_nids(codec);
5152 if (!spec->no_analog && !spec->cap_mixer)
5153 set_capture_mixer(codec);
5155 if (!spec->no_analog) {
5156 err = snd_hda_attach_beep_device(codec, 0x23);
5161 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5164 spec->vmaster_nid = 0x02;
5166 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5168 codec->patch_ops = alc_patch_ops;
5170 spec->init_hook = alc_auto_init_std;
5171 spec->shutup = alc_eapd_shutup;
5172 #ifdef CONFIG_SND_HDA_POWER_SAVE
5173 if (!spec->loopback.amplist)
5174 spec->loopback.amplist = alc861vd_loopbacks;
5183 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
5184 * configuration. Each pin widget can choose any input DACs and a mixer.
5185 * Each ADC is connected from a mixer of all inputs. This makes possible
5186 * 6-channel independent captures.
5188 * In addition, an independent DAC for the multi-playback (not used in this
5191 #ifdef CONFIG_SND_HDA_POWER_SAVE
5192 #define alc662_loopbacks alc880_loopbacks
5196 * BIOS auto configuration
5199 static int alc662_parse_auto_config(struct hda_codec *codec)
5201 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
5202 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
5203 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5204 const hda_nid_t *ssids;
5206 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
5207 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
5208 ssids = alc663_ssids;
5210 ssids = alc662_ssids;
5211 return alc_parse_auto_config(codec, alc662_ignore, ssids);
5214 static void alc272_fixup_mario(struct hda_codec *codec,
5215 const struct alc_fixup *fix, int action)
5217 if (action != ALC_FIXUP_ACT_PROBE)
5219 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
5220 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
5221 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
5222 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5223 (0 << AC_AMPCAP_MUTE_SHIFT)))
5225 "hda_codec: failed to override amp caps for NID 0x2\n");
5229 ALC662_FIXUP_ASPIRE,
5230 ALC662_FIXUP_IDEAPAD,
5232 ALC662_FIXUP_CZC_P10T,
5233 ALC662_FIXUP_SKU_IGNORE,
5234 ALC662_FIXUP_HP_RP5800,
5238 static const struct alc_fixup alc662_fixups[] = {
5239 [ALC662_FIXUP_ASPIRE] = {
5240 .type = ALC_FIXUP_PINS,
5241 .v.pins = (const struct alc_pincfg[]) {
5242 { 0x15, 0x99130112 }, /* subwoofer */
5246 [ALC662_FIXUP_IDEAPAD] = {
5247 .type = ALC_FIXUP_PINS,
5248 .v.pins = (const struct alc_pincfg[]) {
5249 { 0x17, 0x99130112 }, /* subwoofer */
5253 [ALC272_FIXUP_MARIO] = {
5254 .type = ALC_FIXUP_FUNC,
5255 .v.func = alc272_fixup_mario,
5257 [ALC662_FIXUP_CZC_P10T] = {
5258 .type = ALC_FIXUP_VERBS,
5259 .v.verbs = (const struct hda_verb[]) {
5260 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
5264 [ALC662_FIXUP_SKU_IGNORE] = {
5265 .type = ALC_FIXUP_SKU,
5266 .v.sku = ALC_FIXUP_SKU_IGNORE,
5268 [ALC662_FIXUP_HP_RP5800] = {
5269 .type = ALC_FIXUP_PINS,
5270 .v.pins = (const struct alc_pincfg[]) {
5271 { 0x14, 0x0221201f }, /* HP out */
5275 .chain_id = ALC662_FIXUP_SKU_IGNORE
5277 [ALC662_FIXUP_ECS] = {
5278 .type = ALC_FIXUP_PINS,
5279 .v.pins = (const struct alc_pincfg[]) {
5280 { 0x14, 0x99130110 }, /* speaker */
5281 { 0x18, 0x01a19820 }, /* mic */
5282 { 0x19, 0x99a3092f }, /* int-mic */
5283 { 0x1b, 0x0121401f }, /* HP out */
5289 static const struct snd_pci_quirk alc662_fixup_tbl[] = {
5290 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ECS),
5291 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
5292 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
5293 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
5294 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
5295 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ECS),
5296 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
5297 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
5298 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
5299 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
5303 static const struct alc_model_fixup alc662_fixup_models[] = {
5304 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
5311 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
5312 #include "alc662_quirks.c"
5315 static int patch_alc662(struct hda_codec *codec)
5317 struct alc_spec *spec;
5318 int err, board_config;
5321 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5327 spec->mixer_nid = 0x0b;
5329 alc_auto_parse_customize_define(codec);
5331 alc_fix_pll_init(codec, 0x20, 0x04, 15);
5333 coef = alc_read_coef_idx(codec, 0);
5334 if (coef == 0x8020 || coef == 0x8011)
5335 alc_codec_rename(codec, "ALC661");
5336 else if (coef & (1 << 14) &&
5337 codec->bus->pci->subsystem_vendor == 0x1025 &&
5338 spec->cdefine.platform_type == 1)
5339 alc_codec_rename(codec, "ALC272X");
5340 else if (coef == 0x4011)
5341 alc_codec_rename(codec, "ALC656");
5343 board_config = alc_board_config(codec, ALC662_MODEL_LAST,
5344 alc662_models, alc662_cfg_tbl);
5345 if (board_config < 0) {
5346 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5348 board_config = ALC_MODEL_AUTO;
5351 if (board_config == ALC_MODEL_AUTO) {
5352 alc_pick_fixup(codec, alc662_fixup_models,
5353 alc662_fixup_tbl, alc662_fixups);
5354 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5355 /* automatic parse from the BIOS config */
5356 err = alc662_parse_auto_config(codec);
5361 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
5364 "hda_codec: Cannot set up configuration "
5365 "from BIOS. Using base mode...\n");
5366 board_config = ALC662_3ST_2ch_DIG;
5371 if (board_config != ALC_MODEL_AUTO)
5372 setup_preset(codec, &alc662_presets[board_config]);
5374 if (!spec->no_analog && !spec->adc_nids) {
5375 alc_auto_fill_adc_caps(codec);
5376 alc_rebuild_imux_for_auto_mic(codec);
5377 alc_remove_invalid_adc_nids(codec);
5380 if (!spec->no_analog && !spec->cap_mixer)
5381 set_capture_mixer(codec);
5383 if (!spec->no_analog && has_cdefine_beep(codec)) {
5384 err = snd_hda_attach_beep_device(codec, 0x1);
5389 switch (codec->vendor_id) {
5391 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5396 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
5399 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
5403 spec->vmaster_nid = 0x02;
5405 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5407 codec->patch_ops = alc_patch_ops;
5408 if (board_config == ALC_MODEL_AUTO)
5409 spec->init_hook = alc_auto_init_std;
5410 spec->shutup = alc_eapd_shutup;
5412 alc_init_jacks(codec);
5414 #ifdef CONFIG_SND_HDA_POWER_SAVE
5415 if (!spec->loopback.amplist)
5416 spec->loopback.amplist = alc662_loopbacks;
5422 static int patch_alc888(struct hda_codec *codec)
5424 if ((alc_read_coef_idx(codec, 0) & 0x00f0)==0x0030){
5425 kfree(codec->chip_name);
5426 if (codec->vendor_id == 0x10ec0887)
5427 codec->chip_name = kstrdup("ALC887-VD", GFP_KERNEL);
5429 codec->chip_name = kstrdup("ALC888-VD", GFP_KERNEL);
5430 if (!codec->chip_name) {
5434 return patch_alc662(codec);
5436 return patch_alc882(codec);
5439 static int patch_alc899(struct hda_codec *codec)
5441 if ((alc_read_coef_idx(codec, 0) & 0x2000) != 0x2000) {
5442 kfree(codec->chip_name);
5443 codec->chip_name = kstrdup("ALC898", GFP_KERNEL);
5445 return patch_alc882(codec);
5452 static int alc680_parse_auto_config(struct hda_codec *codec)
5454 return alc_parse_auto_config(codec, NULL, NULL);
5459 static int patch_alc680(struct hda_codec *codec)
5461 struct alc_spec *spec;
5464 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5470 /* ALC680 has no aa-loopback mixer */
5472 /* automatic parse from the BIOS config */
5473 err = alc680_parse_auto_config(codec);
5479 if (!spec->no_analog && !spec->cap_mixer)
5480 set_capture_mixer(codec);
5482 spec->vmaster_nid = 0x02;
5484 codec->patch_ops = alc_patch_ops;
5485 spec->init_hook = alc_auto_init_std;
5493 static const struct hda_codec_preset snd_hda_preset_realtek[] = {
5494 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
5495 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
5496 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
5497 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
5498 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
5499 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
5500 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
5501 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
5502 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
5503 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
5504 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
5505 .patch = patch_alc861 },
5506 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
5507 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
5508 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
5509 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
5510 .patch = patch_alc882 },
5511 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
5512 .patch = patch_alc662 },
5513 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
5514 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
5515 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
5516 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
5517 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
5518 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
5519 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
5520 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
5521 .patch = patch_alc882 },
5522 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
5523 .patch = patch_alc882 },
5524 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
5525 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc888 },
5526 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
5527 .patch = patch_alc882 },
5528 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc888 },
5529 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
5530 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
5531 { .id = 0x10ec0899, .name = "ALC899", .patch = patch_alc899 },
5535 MODULE_ALIAS("snd-hda-codec-id:10ec*");
5537 MODULE_LICENSE("GPL");
5538 MODULE_DESCRIPTION("Realtek HD-audio codec");
5540 static struct hda_codec_preset_list realtek_list = {
5541 .preset = snd_hda_preset_realtek,
5542 .owner = THIS_MODULE,
5545 static int __init patch_realtek_init(void)
5547 return snd_hda_add_codec_preset(&realtek_list);
5550 static void __exit patch_realtek_exit(void)
5552 snd_hda_delete_codec_preset(&realtek_list);
5555 module_init(patch_realtek_init)
5556 module_exit(patch_realtek_exit)