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 #define ALC_MODEL_AUTO 0 /* common for all chips */
210 static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
211 int dir, unsigned int bits)
215 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
216 if (query_amp_caps(codec, nid, dir) & bits)
221 #define nid_has_mute(codec, nid, dir) \
222 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
223 #define nid_has_volume(codec, nid, dir) \
224 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
229 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
230 struct snd_ctl_elem_info *uinfo)
232 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
233 struct alc_spec *spec = codec->spec;
234 unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
235 if (mux_idx >= spec->num_mux_defs)
237 if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
239 return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
242 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
243 struct snd_ctl_elem_value *ucontrol)
245 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
246 struct alc_spec *spec = codec->spec;
247 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
249 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
253 static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
255 struct alc_spec *spec = codec->spec;
256 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
258 if (spec->cur_adc && spec->cur_adc != new_adc) {
259 /* stream is running, let's swap the current ADC */
260 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
261 spec->cur_adc = new_adc;
262 snd_hda_codec_setup_stream(codec, new_adc,
263 spec->cur_adc_stream_tag, 0,
264 spec->cur_adc_format);
270 /* select the given imux item; either unmute exclusively or select the route */
271 static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
272 unsigned int idx, bool force)
274 struct alc_spec *spec = codec->spec;
275 const struct hda_input_mux *imux;
276 unsigned int mux_idx;
280 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
281 imux = &spec->input_mux[mux_idx];
282 if (!imux->num_items && mux_idx > 0)
283 imux = &spec->input_mux[0];
285 if (idx >= imux->num_items)
286 idx = imux->num_items - 1;
287 if (spec->cur_mux[adc_idx] == idx && !force)
289 spec->cur_mux[adc_idx] = idx;
291 if (spec->dyn_adc_switch) {
292 alc_dyn_adc_pcm_resetup(codec, idx);
293 adc_idx = spec->dyn_adc_idx[idx];
296 nid = spec->capsrc_nids ?
297 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
300 if (snd_hda_get_conn_list(codec, nid, NULL) <= 1)
303 type = get_wcaps_type(get_wcaps(codec, nid));
304 if (type == AC_WID_AUD_MIX) {
305 /* Matrix-mixer style (e.g. ALC882) */
306 for (i = 0; i < imux->num_items; i++) {
307 unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
308 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
309 imux->items[i].index,
313 /* MUX style (e.g. ALC880) */
314 snd_hda_codec_write_cache(codec, nid, 0,
315 AC_VERB_SET_CONNECT_SEL,
316 imux->items[idx].index);
321 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
322 struct snd_ctl_elem_value *ucontrol)
324 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
325 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
326 return alc_mux_select(codec, adc_idx,
327 ucontrol->value.enumerated.item[0], false);
331 * set up the input pin config (depending on the given auto-pin type)
333 static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
336 unsigned int val = PIN_IN;
338 if (auto_pin_type == AUTO_PIN_MIC) {
341 oldval = snd_hda_codec_read(codec, nid, 0,
342 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
343 pincap = snd_hda_query_pin_caps(codec, nid);
344 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
345 /* if the default pin setup is vref50, we give it priority */
346 if ((pincap & AC_PINCAP_VREF_80) && oldval != PIN_VREF50)
348 else if (pincap & AC_PINCAP_VREF_50)
350 else if (pincap & AC_PINCAP_VREF_100)
352 else if (pincap & AC_PINCAP_VREF_GRD)
355 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val);
359 * Append the given mixer and verb elements for the later use
360 * The mixer array is referred in build_controls(), and init_verbs are
363 static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
365 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
367 spec->mixers[spec->num_mixers++] = mix;
370 static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
372 if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
374 spec->init_verbs[spec->num_init_verbs++] = verb;
378 * GPIO setup tables, used in initialization
380 /* Enable GPIO mask and set output */
381 static const struct hda_verb alc_gpio1_init_verbs[] = {
382 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
383 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
384 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
388 static const struct hda_verb alc_gpio2_init_verbs[] = {
389 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
390 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
391 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
395 static const struct hda_verb alc_gpio3_init_verbs[] = {
396 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
397 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
398 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
403 * Fix hardware PLL issue
404 * On some codecs, the analog PLL gating control must be off while
405 * the default value is 1.
407 static void alc_fix_pll(struct hda_codec *codec)
409 struct alc_spec *spec = codec->spec;
414 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
416 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
417 AC_VERB_GET_PROC_COEF, 0);
418 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
420 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
421 val & ~(1 << spec->pll_coef_bit));
424 static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
425 unsigned int coef_idx, unsigned int coef_bit)
427 struct alc_spec *spec = codec->spec;
429 spec->pll_coef_idx = coef_idx;
430 spec->pll_coef_bit = coef_bit;
435 * Jack-reporting via input-jack layer
438 /* initialization of jacks; currently checks only a few known pins */
439 static int alc_init_jacks(struct hda_codec *codec)
441 #ifdef CONFIG_SND_HDA_INPUT_JACK
442 struct alc_spec *spec = codec->spec;
444 unsigned int hp_nid = spec->autocfg.hp_pins[0];
445 unsigned int mic_nid = spec->ext_mic_pin;
446 unsigned int dock_nid = spec->dock_mic_pin;
449 err = snd_hda_input_jack_add(codec, hp_nid,
450 SND_JACK_HEADPHONE, NULL);
453 snd_hda_input_jack_report(codec, hp_nid);
457 err = snd_hda_input_jack_add(codec, mic_nid,
458 SND_JACK_MICROPHONE, NULL);
461 snd_hda_input_jack_report(codec, mic_nid);
464 err = snd_hda_input_jack_add(codec, dock_nid,
465 SND_JACK_MICROPHONE, NULL);
468 snd_hda_input_jack_report(codec, dock_nid);
470 #endif /* CONFIG_SND_HDA_INPUT_JACK */
475 * Jack detections for HP auto-mute and mic-switch
478 /* check each pin in the given array; returns true if any of them is plugged */
479 static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
483 for (i = 0; i < num_pins; i++) {
484 hda_nid_t nid = pins[i];
487 snd_hda_input_jack_report(codec, nid);
488 present |= snd_hda_jack_detect(codec, nid);
493 /* standard HP/line-out auto-mute helper */
494 static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
495 bool mute, bool hp_out)
497 struct alc_spec *spec = codec->spec;
498 unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0;
499 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
502 for (i = 0; i < num_pins; i++) {
503 hda_nid_t nid = pins[i];
506 switch (spec->automute_mode) {
507 case ALC_AUTOMUTE_PIN:
508 snd_hda_codec_write(codec, nid, 0,
509 AC_VERB_SET_PIN_WIDGET_CONTROL,
512 case ALC_AUTOMUTE_AMP:
513 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
514 HDA_AMP_MUTE, mute_bits);
516 case ALC_AUTOMUTE_MIXER:
517 nid = spec->automute_mixer_nid[i];
520 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
521 HDA_AMP_MUTE, mute_bits);
522 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1,
523 HDA_AMP_MUTE, mute_bits);
529 /* Toggle internal speakers muting */
530 static void update_speakers(struct hda_codec *codec)
532 struct alc_spec *spec = codec->spec;
535 /* Control HP pins/amps depending on master_mute state;
536 * in general, HP pins/amps control should be enabled in all cases,
537 * but currently set only for master_mute, just to be safe
539 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
540 spec->autocfg.hp_pins, spec->master_mute, true);
545 on = spec->jack_present | spec->line_jack_present;
546 on |= spec->master_mute;
547 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
548 spec->autocfg.speaker_pins, on, false);
550 /* toggle line-out mutes if needed, too */
551 /* if LO is a copy of either HP or Speaker, don't need to handle it */
552 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
553 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
555 if (!spec->automute_lines || !spec->automute)
558 on = spec->jack_present;
559 on |= spec->master_mute;
560 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
561 spec->autocfg.line_out_pins, on, false);
564 static void call_update_speakers(struct hda_codec *codec)
566 struct alc_spec *spec = codec->spec;
567 if (spec->automute_hook)
568 spec->automute_hook(codec);
570 update_speakers(codec);
573 /* standard HP-automute helper */
574 static void alc_hp_automute(struct hda_codec *codec)
576 struct alc_spec *spec = codec->spec;
581 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
582 spec->autocfg.hp_pins);
583 call_update_speakers(codec);
586 /* standard line-out-automute helper */
587 static void alc_line_automute(struct hda_codec *codec)
589 struct alc_spec *spec = codec->spec;
591 if (!spec->automute || !spec->detect_line)
593 spec->line_jack_present =
594 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
595 spec->autocfg.line_out_pins);
596 call_update_speakers(codec);
599 #define get_connection_index(codec, mux, nid) \
600 snd_hda_get_conn_index(codec, mux, nid, 0)
602 /* standard mic auto-switch helper */
603 static void alc_mic_automute(struct hda_codec *codec)
605 struct alc_spec *spec = codec->spec;
606 hda_nid_t *pins = spec->imux_pins;
608 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
610 if (snd_BUG_ON(!spec->adc_nids))
612 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
615 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
616 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
617 else if (spec->dock_mic_idx >= 0 &&
618 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
619 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
621 alc_mux_select(codec, 0, spec->int_mic_idx, false);
623 snd_hda_input_jack_report(codec, pins[spec->ext_mic_idx]);
624 if (spec->dock_mic_idx >= 0)
625 snd_hda_input_jack_report(codec, pins[spec->dock_mic_idx]);
628 /* unsolicited event for HP jack sensing */
629 static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
631 if (codec->vendor_id == 0x10ec0880)
637 alc_hp_automute(codec);
639 case ALC_FRONT_EVENT:
640 alc_line_automute(codec);
643 alc_mic_automute(codec);
648 /* call init functions of standard auto-mute helpers */
649 static void alc_inithook(struct hda_codec *codec)
651 alc_hp_automute(codec);
652 alc_line_automute(codec);
653 alc_mic_automute(codec);
656 /* additional initialization for ALC888 variants */
657 static void alc888_coef_init(struct hda_codec *codec)
661 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
662 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
663 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
664 if ((tmp & 0xf0) == 0x20)
666 snd_hda_codec_read(codec, 0x20, 0,
667 AC_VERB_SET_PROC_COEF, 0x830);
670 snd_hda_codec_read(codec, 0x20, 0,
671 AC_VERB_SET_PROC_COEF, 0x3030);
674 /* additional initialization for ALC889 variants */
675 static void alc889_coef_init(struct hda_codec *codec)
679 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
680 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
681 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
682 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
685 /* turn on/off EAPD control (only if available) */
686 static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
688 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
690 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
691 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
695 /* turn on/off EAPD controls of the codec */
696 static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
698 /* We currently only handle front, HP */
699 static hda_nid_t pins[] = {
700 0x0f, 0x10, 0x14, 0x15, 0
703 for (p = pins; *p; p++)
704 set_eapd(codec, *p, on);
707 /* generic shutup callback;
708 * just turning off EPAD and a little pause for avoiding pop-noise
710 static void alc_eapd_shutup(struct hda_codec *codec)
712 alc_auto_setup_eapd(codec, false);
716 /* generic EAPD initialization */
717 static void alc_auto_init_amp(struct hda_codec *codec, int type)
721 alc_auto_setup_eapd(codec, true);
724 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
727 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
730 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
732 case ALC_INIT_DEFAULT:
733 switch (codec->vendor_id) {
735 snd_hda_codec_write(codec, 0x1a, 0,
736 AC_VERB_SET_COEF_INDEX, 7);
737 tmp = snd_hda_codec_read(codec, 0x1a, 0,
738 AC_VERB_GET_PROC_COEF, 0);
739 snd_hda_codec_write(codec, 0x1a, 0,
740 AC_VERB_SET_COEF_INDEX, 7);
741 snd_hda_codec_write(codec, 0x1a, 0,
742 AC_VERB_SET_PROC_COEF,
751 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
752 alc889_coef_init(codec);
755 alc888_coef_init(codec);
757 #if 0 /* XXX: This may cause the silent output on speaker on some machines */
760 snd_hda_codec_write(codec, 0x20, 0,
761 AC_VERB_SET_COEF_INDEX, 7);
762 tmp = snd_hda_codec_read(codec, 0x20, 0,
763 AC_VERB_GET_PROC_COEF, 0);
764 snd_hda_codec_write(codec, 0x20, 0,
765 AC_VERB_SET_COEF_INDEX, 7);
766 snd_hda_codec_write(codec, 0x20, 0,
767 AC_VERB_SET_PROC_COEF,
777 * Auto-Mute mode mixer enum support
779 static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
780 struct snd_ctl_elem_info *uinfo)
782 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
783 struct alc_spec *spec = codec->spec;
784 static const char * const texts2[] = {
785 "Disabled", "Enabled"
787 static const char * const texts3[] = {
788 "Disabled", "Speaker Only", "Line-Out+Speaker"
790 const char * const *texts;
792 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
794 if (spec->automute_hp_lo) {
795 uinfo->value.enumerated.items = 3;
798 uinfo->value.enumerated.items = 2;
801 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
802 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
803 strcpy(uinfo->value.enumerated.name,
804 texts[uinfo->value.enumerated.item]);
808 static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
809 struct snd_ctl_elem_value *ucontrol)
811 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
812 struct alc_spec *spec = codec->spec;
816 else if (!spec->automute_lines)
820 ucontrol->value.enumerated.item[0] = val;
824 static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
825 struct snd_ctl_elem_value *ucontrol)
827 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
828 struct alc_spec *spec = codec->spec;
830 switch (ucontrol->value.enumerated.item[0]) {
837 if (spec->automute && !spec->automute_lines)
840 spec->automute_lines = 0;
843 if (!spec->automute_hp_lo)
845 if (spec->automute && spec->automute_lines)
848 spec->automute_lines = 1;
853 call_update_speakers(codec);
857 static const struct snd_kcontrol_new alc_automute_mode_enum = {
858 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
859 .name = "Auto-Mute Mode",
860 .info = alc_automute_mode_info,
861 .get = alc_automute_mode_get,
862 .put = alc_automute_mode_put,
865 static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec)
867 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
868 return snd_array_new(&spec->kctls);
871 static int alc_add_automute_mode_enum(struct hda_codec *codec)
873 struct alc_spec *spec = codec->spec;
874 struct snd_kcontrol_new *knew;
876 knew = alc_kcontrol_new(spec);
879 *knew = alc_automute_mode_enum;
880 knew->name = kstrdup("Auto-Mute Mode", GFP_KERNEL);
887 * Check the availability of HP/line-out auto-mute;
888 * Set up appropriately if really supported
890 static void alc_init_auto_hp(struct hda_codec *codec)
892 struct alc_spec *spec = codec->spec;
893 struct auto_pin_cfg *cfg = &spec->autocfg;
899 if (cfg->line_out_pins[0])
901 if (cfg->speaker_pins[0])
903 if (present < 2) /* need two different output types */
906 spec->automute_hp_lo = 1; /* both HP and LO automute */
908 if (!cfg->speaker_pins[0] &&
909 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
910 memcpy(cfg->speaker_pins, cfg->line_out_pins,
911 sizeof(cfg->speaker_pins));
912 cfg->speaker_outs = cfg->line_outs;
915 if (!cfg->hp_pins[0] &&
916 cfg->line_out_type == AUTO_PIN_HP_OUT) {
917 memcpy(cfg->hp_pins, cfg->line_out_pins,
918 sizeof(cfg->hp_pins));
919 cfg->hp_outs = cfg->line_outs;
922 for (i = 0; i < cfg->hp_outs; i++) {
923 hda_nid_t nid = cfg->hp_pins[i];
924 if (!is_jack_detectable(codec, nid))
926 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
928 snd_hda_codec_write_cache(codec, nid, 0,
929 AC_VERB_SET_UNSOLICITED_ENABLE,
930 AC_USRSP_EN | ALC_HP_EVENT);
932 spec->automute_mode = ALC_AUTOMUTE_PIN;
934 if (spec->automute && cfg->line_out_pins[0] &&
935 cfg->speaker_pins[0] &&
936 cfg->line_out_pins[0] != cfg->hp_pins[0] &&
937 cfg->line_out_pins[0] != cfg->speaker_pins[0]) {
938 for (i = 0; i < cfg->line_outs; i++) {
939 hda_nid_t nid = cfg->line_out_pins[i];
940 if (!is_jack_detectable(codec, nid))
942 snd_printdd("realtek: Enable Line-Out auto-muting "
943 "on NID 0x%x\n", nid);
944 snd_hda_codec_write_cache(codec, nid, 0,
945 AC_VERB_SET_UNSOLICITED_ENABLE,
946 AC_USRSP_EN | ALC_FRONT_EVENT);
947 spec->detect_line = 1;
949 spec->automute_lines = spec->detect_line;
952 if (spec->automute) {
953 /* create a control for automute mode */
954 alc_add_automute_mode_enum(codec);
955 spec->unsol_event = alc_sku_unsol_event;
959 /* return the position of NID in the list, or -1 if not found */
960 static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
963 for (i = 0; i < nums; i++)
969 /* check whether dynamic ADC-switching is available */
970 static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
972 struct alc_spec *spec = codec->spec;
973 struct hda_input_mux *imux = &spec->private_imux[0];
977 if (imux != spec->input_mux) /* no dynamic imux? */
980 for (n = 0; n < spec->num_adc_nids; n++) {
981 cap = spec->private_capsrc_nids[n];
982 for (i = 0; i < imux->num_items; i++) {
983 pin = spec->imux_pins[i];
986 if (get_connection_index(codec, cap, pin) < 0)
989 if (i >= imux->num_items)
990 return true; /* no ADC-switch is needed */
993 for (i = 0; i < imux->num_items; i++) {
994 pin = spec->imux_pins[i];
995 for (n = 0; n < spec->num_adc_nids; n++) {
996 cap = spec->private_capsrc_nids[n];
997 idx = get_connection_index(codec, cap, pin);
999 imux->items[i].index = idx;
1000 spec->dyn_adc_idx[i] = n;
1006 snd_printdd("realtek: enabling ADC switching\n");
1007 spec->dyn_adc_switch = 1;
1011 /* rebuild imux for matching with the given auto-mic pins (if not yet) */
1012 static bool alc_rebuild_imux_for_auto_mic(struct hda_codec *codec)
1014 struct alc_spec *spec = codec->spec;
1015 struct hda_input_mux *imux;
1016 static char * const texts[3] = {
1017 "Mic", "Internal Mic", "Dock Mic"
1021 if (!spec->auto_mic)
1023 imux = &spec->private_imux[0];
1024 if (spec->input_mux == imux)
1026 spec->imux_pins[0] = spec->ext_mic_pin;
1027 spec->imux_pins[1] = spec->int_mic_pin;
1028 spec->imux_pins[2] = spec->dock_mic_pin;
1029 for (i = 0; i < 3; i++) {
1030 strcpy(imux->items[i].label, texts[i]);
1031 if (spec->imux_pins[i])
1032 imux->num_items = i + 1;
1034 spec->num_mux_defs = 1;
1035 spec->input_mux = imux;
1039 /* check whether all auto-mic pins are valid; setup indices if OK */
1040 static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1042 struct alc_spec *spec = codec->spec;
1043 const struct hda_input_mux *imux;
1045 if (!spec->auto_mic)
1047 if (spec->auto_mic_valid_imux)
1048 return true; /* already checked */
1050 /* fill up imux indices */
1051 if (!alc_check_dyn_adc_switch(codec)) {
1056 imux = spec->input_mux;
1057 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1058 spec->imux_pins, imux->num_items);
1059 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1060 spec->imux_pins, imux->num_items);
1061 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1062 spec->imux_pins, imux->num_items);
1063 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1065 return false; /* no corresponding imux */
1068 snd_hda_codec_write_cache(codec, spec->ext_mic_pin, 0,
1069 AC_VERB_SET_UNSOLICITED_ENABLE,
1070 AC_USRSP_EN | ALC_MIC_EVENT);
1071 if (spec->dock_mic_pin)
1072 snd_hda_codec_write_cache(codec, spec->dock_mic_pin, 0,
1073 AC_VERB_SET_UNSOLICITED_ENABLE,
1074 AC_USRSP_EN | ALC_MIC_EVENT);
1076 spec->auto_mic_valid_imux = 1;
1082 * Check the availability of auto-mic switch;
1083 * Set up if really supported
1085 static void alc_init_auto_mic(struct hda_codec *codec)
1087 struct alc_spec *spec = codec->spec;
1088 struct auto_pin_cfg *cfg = &spec->autocfg;
1089 hda_nid_t fixed, ext, dock;
1092 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1094 fixed = ext = dock = 0;
1095 for (i = 0; i < cfg->num_inputs; i++) {
1096 hda_nid_t nid = cfg->inputs[i].pin;
1097 unsigned int defcfg;
1098 defcfg = snd_hda_codec_get_pincfg(codec, nid);
1099 switch (snd_hda_get_input_pin_attr(defcfg)) {
1100 case INPUT_PIN_ATTR_INT:
1102 return; /* already occupied */
1103 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1104 return; /* invalid type */
1107 case INPUT_PIN_ATTR_UNUSED:
1108 return; /* invalid entry */
1109 case INPUT_PIN_ATTR_DOCK:
1111 return; /* already occupied */
1112 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1113 return; /* invalid type */
1118 return; /* already occupied */
1119 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1120 return; /* invalid type */
1131 if (!is_jack_detectable(codec, ext))
1132 return; /* no unsol support */
1133 if (dock && !is_jack_detectable(codec, dock))
1134 return; /* no unsol support */
1136 /* check imux indices */
1137 spec->ext_mic_pin = ext;
1138 spec->int_mic_pin = fixed;
1139 spec->dock_mic_pin = dock;
1142 if (!alc_auto_mic_check_imux(codec))
1145 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1147 spec->unsol_event = alc_sku_unsol_event;
1150 /* check the availabilities of auto-mute and auto-mic switches */
1151 static void alc_auto_check_switches(struct hda_codec *codec)
1153 alc_init_auto_hp(codec);
1154 alc_init_auto_mic(codec);
1158 * Realtek SSID verification
1161 /* Could be any non-zero and even value. When used as fixup, tells
1162 * the driver to ignore any present sku defines.
1164 #define ALC_FIXUP_SKU_IGNORE (2)
1166 static int alc_auto_parse_customize_define(struct hda_codec *codec)
1168 unsigned int ass, tmp, i;
1170 struct alc_spec *spec = codec->spec;
1172 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1174 if (spec->cdefine.fixup) {
1175 ass = spec->cdefine.sku_cfg;
1176 if (ass == ALC_FIXUP_SKU_IGNORE)
1181 ass = codec->subsystem_id & 0xffff;
1182 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
1186 if (codec->vendor_id == 0x10ec0260)
1188 ass = snd_hda_codec_get_pincfg(codec, nid);
1191 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1192 codec->chip_name, ass);
1198 for (i = 1; i < 16; i++) {
1202 if (((ass >> 16) & 0xf) != tmp)
1205 spec->cdefine.port_connectivity = ass >> 30;
1206 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1207 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1208 spec->cdefine.customization = ass >> 8;
1210 spec->cdefine.sku_cfg = ass;
1211 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1212 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1213 spec->cdefine.swap = (ass & 0x2) >> 1;
1214 spec->cdefine.override = ass & 0x1;
1216 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1217 nid, spec->cdefine.sku_cfg);
1218 snd_printd("SKU: port_connectivity=0x%x\n",
1219 spec->cdefine.port_connectivity);
1220 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1221 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1222 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1223 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1224 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1225 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1226 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1231 /* return true if the given NID is found in the list */
1232 static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1234 return find_idx_in_nid_list(nid, list, nums) >= 0;
1237 /* check subsystem ID and set up device-specific initialization;
1238 * return 1 if initialized, 0 if invalid SSID
1240 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1241 * 31 ~ 16 : Manufacture ID
1243 * 7 ~ 0 : Assembly ID
1244 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1246 static int alc_subsystem_id(struct hda_codec *codec,
1247 hda_nid_t porta, hda_nid_t porte,
1248 hda_nid_t portd, hda_nid_t porti)
1250 unsigned int ass, tmp, i;
1252 struct alc_spec *spec = codec->spec;
1254 if (spec->cdefine.fixup) {
1255 ass = spec->cdefine.sku_cfg;
1256 if (ass == ALC_FIXUP_SKU_IGNORE)
1261 ass = codec->subsystem_id & 0xffff;
1262 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1265 /* invalid SSID, check the special NID pin defcfg instead */
1267 * 31~30 : port connectivity
1270 * 19~16 : Check sum (15:1)
1275 if (codec->vendor_id == 0x10ec0260)
1277 ass = snd_hda_codec_get_pincfg(codec, nid);
1278 snd_printd("realtek: No valid SSID, "
1279 "checking pincfg 0x%08x for NID 0x%x\n",
1283 if ((ass >> 30) != 1) /* no physical connection */
1288 for (i = 1; i < 16; i++) {
1292 if (((ass >> 16) & 0xf) != tmp)
1295 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1296 ass & 0xffff, codec->vendor_id);
1300 * 2 : 0 --> Desktop, 1 --> Laptop
1301 * 3~5 : External Amplifier control
1304 tmp = (ass & 0x38) >> 3; /* external Amp control */
1307 spec->init_amp = ALC_INIT_GPIO1;
1310 spec->init_amp = ALC_INIT_GPIO2;
1313 spec->init_amp = ALC_INIT_GPIO3;
1317 spec->init_amp = ALC_INIT_DEFAULT;
1321 /* is laptop or Desktop and enable the function "Mute internal speaker
1322 * when the external headphone out jack is plugged"
1324 if (!(ass & 0x8000))
1327 * 10~8 : Jack location
1328 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1330 * 15 : 1 --> enable the function "Mute internal speaker
1331 * when the external headphone out jack is plugged"
1333 if (!spec->autocfg.hp_pins[0]) {
1335 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1346 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1347 spec->autocfg.line_outs))
1349 spec->autocfg.hp_pins[0] = nid;
1354 /* Check the validity of ALC subsystem-id
1355 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1356 static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
1358 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
1359 struct alc_spec *spec = codec->spec;
1360 snd_printd("realtek: "
1361 "Enable default setup for auto mode as fallback\n");
1362 spec->init_amp = ALC_INIT_DEFAULT;
1367 * Fix-up pin default configurations and add default verbs
1375 struct alc_model_fixup {
1386 const struct alc_pincfg *pins;
1387 const struct hda_verb *verbs;
1388 void (*func)(struct hda_codec *codec,
1389 const struct alc_fixup *fix,
1403 ALC_FIXUP_ACT_PRE_PROBE,
1404 ALC_FIXUP_ACT_PROBE,
1408 static void alc_apply_fixup(struct hda_codec *codec, int action)
1410 struct alc_spec *spec = codec->spec;
1411 int id = spec->fixup_id;
1412 #ifdef CONFIG_SND_DEBUG_VERBOSE
1413 const char *modelname = spec->fixup_name;
1417 if (!spec->fixup_list)
1421 const struct alc_fixup *fix = spec->fixup_list + id;
1422 const struct alc_pincfg *cfg;
1424 switch (fix->type) {
1426 if (action != ALC_FIXUP_ACT_PRE_PROBE || !fix->v.sku)
1428 snd_printdd(KERN_INFO "hda_codec: %s: "
1429 "Apply sku override for %s\n",
1430 codec->chip_name, modelname);
1431 spec->cdefine.sku_cfg = fix->v.sku;
1432 spec->cdefine.fixup = 1;
1434 case ALC_FIXUP_PINS:
1436 if (action != ALC_FIXUP_ACT_PRE_PROBE || !cfg)
1438 snd_printdd(KERN_INFO "hda_codec: %s: "
1439 "Apply pincfg for %s\n",
1440 codec->chip_name, modelname);
1441 for (; cfg->nid; cfg++)
1442 snd_hda_codec_set_pincfg(codec, cfg->nid,
1445 case ALC_FIXUP_VERBS:
1446 if (action != ALC_FIXUP_ACT_PROBE || !fix->v.verbs)
1448 snd_printdd(KERN_INFO "hda_codec: %s: "
1449 "Apply fix-verbs for %s\n",
1450 codec->chip_name, modelname);
1451 add_verb(codec->spec, fix->v.verbs);
1453 case ALC_FIXUP_FUNC:
1456 snd_printdd(KERN_INFO "hda_codec: %s: "
1457 "Apply fix-func for %s\n",
1458 codec->chip_name, modelname);
1459 fix->v.func(codec, fix, action);
1462 snd_printk(KERN_ERR "hda_codec: %s: "
1463 "Invalid fixup type %d\n",
1464 codec->chip_name, fix->type);
1475 static void alc_pick_fixup(struct hda_codec *codec,
1476 const struct alc_model_fixup *models,
1477 const struct snd_pci_quirk *quirk,
1478 const struct alc_fixup *fixlist)
1480 struct alc_spec *spec = codec->spec;
1482 const char *name = NULL;
1484 if (codec->modelname && models) {
1485 while (models->name) {
1486 if (!strcmp(codec->modelname, models->name)) {
1488 name = models->name;
1495 quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1498 #ifdef CONFIG_SND_DEBUG_VERBOSE
1504 spec->fixup_id = id;
1506 spec->fixup_list = fixlist;
1507 spec->fixup_name = name;
1512 * COEF access helper functions
1514 static int alc_read_coef_idx(struct hda_codec *codec,
1515 unsigned int coef_idx)
1518 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1520 val = snd_hda_codec_read(codec, 0x20, 0,
1521 AC_VERB_GET_PROC_COEF, 0);
1525 static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1526 unsigned int coef_val)
1528 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1530 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1535 * Digital I/O handling
1538 /* set right pin controls for digital I/O */
1539 static void alc_auto_init_digital(struct hda_codec *codec)
1541 struct alc_spec *spec = codec->spec;
1545 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1546 pin = spec->autocfg.dig_out_pins[i];
1549 snd_hda_codec_write(codec, pin, 0,
1550 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
1552 dac = spec->multiout.dig_out_nid;
1554 dac = spec->slave_dig_outs[i - 1];
1555 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
1557 snd_hda_codec_write(codec, dac, 0,
1558 AC_VERB_SET_AMP_GAIN_MUTE,
1561 pin = spec->autocfg.dig_in_pin;
1563 snd_hda_codec_write(codec, pin, 0,
1564 AC_VERB_SET_PIN_WIDGET_CONTROL,
1568 /* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1569 static void alc_auto_parse_digital(struct hda_codec *codec)
1571 struct alc_spec *spec = codec->spec;
1575 /* support multiple SPDIFs; the secondary is set up as a slave */
1576 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1578 err = snd_hda_get_connections(codec,
1579 spec->autocfg.dig_out_pins[i],
1580 conn, ARRAY_SIZE(conn));
1583 dig_nid = conn[0]; /* assume the first element is audio-out */
1585 spec->multiout.dig_out_nid = dig_nid;
1586 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1588 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
1589 if (i >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
1591 spec->slave_dig_outs[i - 1] = dig_nid;
1595 if (spec->autocfg.dig_in_pin) {
1596 dig_nid = codec->start_nid;
1597 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1598 unsigned int wcaps = get_wcaps(codec, dig_nid);
1599 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1601 if (!(wcaps & AC_WCAP_DIGITAL))
1603 if (!(wcaps & AC_WCAP_CONN_LIST))
1605 err = get_connection_index(codec, dig_nid,
1606 spec->autocfg.dig_in_pin);
1608 spec->dig_in_nid = dig_nid;
1616 * capture mixer elements
1618 static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1619 struct snd_ctl_elem_info *uinfo)
1621 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1622 struct alc_spec *spec = codec->spec;
1626 mutex_lock(&codec->control_mutex);
1627 if (spec->vol_in_capsrc)
1628 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1630 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1631 kcontrol->private_value = val;
1632 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
1633 mutex_unlock(&codec->control_mutex);
1637 static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1638 unsigned int size, unsigned int __user *tlv)
1640 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1641 struct alc_spec *spec = codec->spec;
1645 mutex_lock(&codec->control_mutex);
1646 if (spec->vol_in_capsrc)
1647 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1649 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1650 kcontrol->private_value = val;
1651 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
1652 mutex_unlock(&codec->control_mutex);
1656 typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1657 struct snd_ctl_elem_value *ucontrol);
1659 static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1660 struct snd_ctl_elem_value *ucontrol,
1661 getput_call_t func, bool check_adc_switch)
1663 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1664 struct alc_spec *spec = codec->spec;
1667 mutex_lock(&codec->control_mutex);
1668 if (check_adc_switch && spec->dyn_adc_switch) {
1669 for (i = 0; i < spec->num_adc_nids; i++) {
1670 kcontrol->private_value =
1671 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1673 err = func(kcontrol, ucontrol);
1678 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1679 if (spec->vol_in_capsrc)
1680 kcontrol->private_value =
1681 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1684 kcontrol->private_value =
1685 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1687 err = func(kcontrol, ucontrol);
1690 mutex_unlock(&codec->control_mutex);
1694 static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1695 struct snd_ctl_elem_value *ucontrol)
1697 return alc_cap_getput_caller(kcontrol, ucontrol,
1698 snd_hda_mixer_amp_volume_get, false);
1701 static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1702 struct snd_ctl_elem_value *ucontrol)
1704 return alc_cap_getput_caller(kcontrol, ucontrol,
1705 snd_hda_mixer_amp_volume_put, true);
1708 /* capture mixer elements */
1709 #define alc_cap_sw_info snd_ctl_boolean_stereo_info
1711 static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1712 struct snd_ctl_elem_value *ucontrol)
1714 return alc_cap_getput_caller(kcontrol, ucontrol,
1715 snd_hda_mixer_amp_switch_get, false);
1718 static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1719 struct snd_ctl_elem_value *ucontrol)
1721 return alc_cap_getput_caller(kcontrol, ucontrol,
1722 snd_hda_mixer_amp_switch_put, true);
1725 #define _DEFINE_CAPMIX(num) \
1727 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1728 .name = "Capture Switch", \
1729 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1731 .info = alc_cap_sw_info, \
1732 .get = alc_cap_sw_get, \
1733 .put = alc_cap_sw_put, \
1736 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1737 .name = "Capture Volume", \
1738 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1739 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1740 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1742 .info = alc_cap_vol_info, \
1743 .get = alc_cap_vol_get, \
1744 .put = alc_cap_vol_put, \
1745 .tlv = { .c = alc_cap_vol_tlv }, \
1748 #define _DEFINE_CAPSRC(num) \
1750 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1751 /* .name = "Capture Source", */ \
1752 .name = "Input Source", \
1754 .info = alc_mux_enum_info, \
1755 .get = alc_mux_enum_get, \
1756 .put = alc_mux_enum_put, \
1759 #define DEFINE_CAPMIX(num) \
1760 static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
1761 _DEFINE_CAPMIX(num), \
1762 _DEFINE_CAPSRC(num), \
1766 #define DEFINE_CAPMIX_NOSRC(num) \
1767 static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
1768 _DEFINE_CAPMIX(num), \
1772 /* up to three ADCs */
1776 DEFINE_CAPMIX_NOSRC(1);
1777 DEFINE_CAPMIX_NOSRC(2);
1778 DEFINE_CAPMIX_NOSRC(3);
1781 * virtual master controls
1785 * slave controls for virtual master
1787 static const char * const alc_slave_vols[] = {
1788 "Front Playback Volume",
1789 "Surround Playback Volume",
1790 "Center Playback Volume",
1791 "LFE Playback Volume",
1792 "Side Playback Volume",
1793 "Headphone Playback Volume",
1794 "Speaker Playback Volume",
1795 "Mono Playback Volume",
1796 "Line-Out Playback Volume",
1800 static const char * const alc_slave_sws[] = {
1801 "Front Playback Switch",
1802 "Surround Playback Switch",
1803 "Center Playback Switch",
1804 "LFE Playback Switch",
1805 "Side Playback Switch",
1806 "Headphone Playback Switch",
1807 "Speaker Playback Switch",
1808 "Mono Playback Switch",
1809 "IEC958 Playback Switch",
1810 "Line-Out Playback Switch",
1815 * build control elements
1818 #define NID_MAPPING (-1)
1820 #define SUBDEV_SPEAKER_ (0 << 6)
1821 #define SUBDEV_HP_ (1 << 6)
1822 #define SUBDEV_LINE_ (2 << 6)
1823 #define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1824 #define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1825 #define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1827 static void alc_free_kctls(struct hda_codec *codec);
1829 #ifdef CONFIG_SND_HDA_INPUT_BEEP
1830 /* additional beep mixers; the actual parameters are overwritten at build */
1831 static const struct snd_kcontrol_new alc_beep_mixer[] = {
1832 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
1833 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
1838 static int alc_build_controls(struct hda_codec *codec)
1840 struct alc_spec *spec = codec->spec;
1841 struct snd_kcontrol *kctl = NULL;
1842 const struct snd_kcontrol_new *knew;
1847 for (i = 0; i < spec->num_mixers; i++) {
1848 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1852 if (spec->cap_mixer) {
1853 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1857 if (spec->multiout.dig_out_nid) {
1858 err = snd_hda_create_spdif_out_ctls(codec,
1859 spec->multiout.dig_out_nid,
1860 spec->multiout.dig_out_nid);
1863 if (!spec->no_analog) {
1864 err = snd_hda_create_spdif_share_sw(codec,
1868 spec->multiout.share_spdif = 1;
1871 if (spec->dig_in_nid) {
1872 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1877 #ifdef CONFIG_SND_HDA_INPUT_BEEP
1878 /* create beep controls if needed */
1879 if (spec->beep_amp) {
1880 const struct snd_kcontrol_new *knew;
1881 for (knew = alc_beep_mixer; knew->name; knew++) {
1882 struct snd_kcontrol *kctl;
1883 kctl = snd_ctl_new1(knew, codec);
1886 kctl->private_value = spec->beep_amp;
1887 err = snd_hda_ctl_add(codec, 0, kctl);
1894 /* if we have no master control, let's create it */
1895 if (!spec->no_analog &&
1896 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1897 unsigned int vmaster_tlv[4];
1898 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
1899 HDA_OUTPUT, vmaster_tlv);
1900 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1901 vmaster_tlv, alc_slave_vols);
1905 if (!spec->no_analog &&
1906 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1907 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1908 NULL, alc_slave_sws);
1913 /* assign Capture Source enums to NID */
1914 if (spec->capsrc_nids || spec->adc_nids) {
1915 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
1917 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1918 for (i = 0; kctl && i < kctl->count; i++) {
1919 const hda_nid_t *nids = spec->capsrc_nids;
1921 nids = spec->adc_nids;
1922 err = snd_hda_add_nid(codec, kctl, i, nids[i]);
1927 if (spec->cap_mixer && spec->adc_nids) {
1928 const char *kname = kctl ? kctl->id.name : NULL;
1929 for (knew = spec->cap_mixer; knew->name; knew++) {
1930 if (kname && strcmp(knew->name, kname) == 0)
1932 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1933 for (i = 0; kctl && i < kctl->count; i++) {
1934 err = snd_hda_add_nid(codec, kctl, i,
1942 /* other nid->control mapping */
1943 for (i = 0; i < spec->num_mixers; i++) {
1944 for (knew = spec->mixers[i]; knew->name; knew++) {
1945 if (knew->iface != NID_MAPPING)
1947 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1950 u = knew->subdevice;
1951 for (j = 0; j < 4; j++, u >>= 8) {
1956 case SUBDEV_SPEAKER_:
1957 nid = spec->autocfg.speaker_pins[nid];
1960 nid = spec->autocfg.line_out_pins[nid];
1963 nid = spec->autocfg.hp_pins[nid];
1968 err = snd_hda_add_nid(codec, kctl, 0, nid);
1972 u = knew->private_value;
1973 for (j = 0; j < 4; j++, u >>= 8) {
1977 err = snd_hda_add_nid(codec, kctl, 0, nid);
1984 alc_free_kctls(codec); /* no longer needed */
1994 static void alc_init_special_input_src(struct hda_codec *codec);
1996 static int alc_init(struct hda_codec *codec)
1998 struct alc_spec *spec = codec->spec;
2002 alc_auto_init_amp(codec, spec->init_amp);
2004 for (i = 0; i < spec->num_init_verbs; i++)
2005 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2006 alc_init_special_input_src(codec);
2008 if (spec->init_hook)
2009 spec->init_hook(codec);
2011 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2013 hda_call_check_power_status(codec, 0x01);
2017 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2019 struct alc_spec *spec = codec->spec;
2021 if (spec->unsol_event)
2022 spec->unsol_event(codec, res);
2025 #ifdef CONFIG_SND_HDA_POWER_SAVE
2026 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2028 struct alc_spec *spec = codec->spec;
2029 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2034 * Analog playback callbacks
2036 static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
2037 struct hda_codec *codec,
2038 struct snd_pcm_substream *substream)
2040 struct alc_spec *spec = codec->spec;
2041 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2045 static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2046 struct hda_codec *codec,
2047 unsigned int stream_tag,
2048 unsigned int format,
2049 struct snd_pcm_substream *substream)
2051 struct alc_spec *spec = codec->spec;
2052 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2053 stream_tag, format, substream);
2056 static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2057 struct hda_codec *codec,
2058 struct snd_pcm_substream *substream)
2060 struct alc_spec *spec = codec->spec;
2061 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2067 static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2068 struct hda_codec *codec,
2069 struct snd_pcm_substream *substream)
2071 struct alc_spec *spec = codec->spec;
2072 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2075 static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2076 struct hda_codec *codec,
2077 unsigned int stream_tag,
2078 unsigned int format,
2079 struct snd_pcm_substream *substream)
2081 struct alc_spec *spec = codec->spec;
2082 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2083 stream_tag, format, substream);
2086 static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2087 struct hda_codec *codec,
2088 struct snd_pcm_substream *substream)
2090 struct alc_spec *spec = codec->spec;
2091 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2094 static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2095 struct hda_codec *codec,
2096 struct snd_pcm_substream *substream)
2098 struct alc_spec *spec = codec->spec;
2099 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2105 static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2106 struct hda_codec *codec,
2107 unsigned int stream_tag,
2108 unsigned int format,
2109 struct snd_pcm_substream *substream)
2111 struct alc_spec *spec = codec->spec;
2113 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
2114 stream_tag, 0, format);
2118 static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2119 struct hda_codec *codec,
2120 struct snd_pcm_substream *substream)
2122 struct alc_spec *spec = codec->spec;
2124 snd_hda_codec_cleanup_stream(codec,
2125 spec->adc_nids[substream->number + 1]);
2129 /* analog capture with dynamic dual-adc changes */
2130 static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2131 struct hda_codec *codec,
2132 unsigned int stream_tag,
2133 unsigned int format,
2134 struct snd_pcm_substream *substream)
2136 struct alc_spec *spec = codec->spec;
2137 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
2138 spec->cur_adc_stream_tag = stream_tag;
2139 spec->cur_adc_format = format;
2140 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2144 static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2145 struct hda_codec *codec,
2146 struct snd_pcm_substream *substream)
2148 struct alc_spec *spec = codec->spec;
2149 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2154 static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
2158 .nid = 0, /* fill later */
2160 .prepare = dyn_adc_capture_pcm_prepare,
2161 .cleanup = dyn_adc_capture_pcm_cleanup
2167 static const struct hda_pcm_stream alc_pcm_analog_playback = {
2171 /* NID is set in alc_build_pcms */
2173 .open = alc_playback_pcm_open,
2174 .prepare = alc_playback_pcm_prepare,
2175 .cleanup = alc_playback_pcm_cleanup
2179 static const struct hda_pcm_stream alc_pcm_analog_capture = {
2183 /* NID is set in alc_build_pcms */
2186 static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
2190 /* NID is set in alc_build_pcms */
2193 static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
2194 .substreams = 2, /* can be overridden */
2197 /* NID is set in alc_build_pcms */
2199 .prepare = alc_alt_capture_pcm_prepare,
2200 .cleanup = alc_alt_capture_pcm_cleanup
2204 static const struct hda_pcm_stream alc_pcm_digital_playback = {
2208 /* NID is set in alc_build_pcms */
2210 .open = alc_dig_playback_pcm_open,
2211 .close = alc_dig_playback_pcm_close,
2212 .prepare = alc_dig_playback_pcm_prepare,
2213 .cleanup = alc_dig_playback_pcm_cleanup
2217 static const struct hda_pcm_stream alc_pcm_digital_capture = {
2221 /* NID is set in alc_build_pcms */
2224 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
2225 static const struct hda_pcm_stream alc_pcm_null_stream = {
2231 static int alc_build_pcms(struct hda_codec *codec)
2233 struct alc_spec *spec = codec->spec;
2234 struct hda_pcm *info = spec->pcm_rec;
2235 const struct hda_pcm_stream *p;
2238 codec->num_pcms = 1;
2239 codec->pcm_info = info;
2241 if (spec->no_analog)
2244 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2245 "%s Analog", codec->chip_name);
2246 info->name = spec->stream_name_analog;
2248 if (spec->multiout.dac_nids > 0) {
2249 p = spec->stream_analog_playback;
2251 p = &alc_pcm_analog_playback;
2252 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2253 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2255 if (spec->adc_nids) {
2256 p = spec->stream_analog_capture;
2258 if (spec->dyn_adc_switch)
2259 p = &dyn_adc_pcm_analog_capture;
2261 p = &alc_pcm_analog_capture;
2263 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2264 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2267 if (spec->channel_mode) {
2268 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2269 for (i = 0; i < spec->num_channel_mode; i++) {
2270 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2271 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2277 /* SPDIF for stream index #1 */
2278 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2279 snprintf(spec->stream_name_digital,
2280 sizeof(spec->stream_name_digital),
2281 "%s Digital", codec->chip_name);
2282 codec->num_pcms = 2;
2283 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
2284 info = spec->pcm_rec + 1;
2285 info->name = spec->stream_name_digital;
2286 if (spec->dig_out_type)
2287 info->pcm_type = spec->dig_out_type;
2289 info->pcm_type = HDA_PCM_TYPE_SPDIF;
2290 if (spec->multiout.dig_out_nid) {
2291 p = spec->stream_digital_playback;
2293 p = &alc_pcm_digital_playback;
2294 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2295 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2297 if (spec->dig_in_nid) {
2298 p = spec->stream_digital_capture;
2300 p = &alc_pcm_digital_capture;
2301 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2302 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2304 /* FIXME: do we need this for all Realtek codec models? */
2305 codec->spdif_status_reset = 1;
2308 if (spec->no_analog)
2311 /* If the use of more than one ADC is requested for the current
2312 * model, configure a second analog capture-only PCM.
2314 /* Additional Analaog capture for index #2 */
2315 if (spec->alt_dac_nid || spec->num_adc_nids > 1) {
2316 codec->num_pcms = 3;
2317 info = spec->pcm_rec + 2;
2318 info->name = spec->stream_name_analog;
2319 if (spec->alt_dac_nid) {
2320 p = spec->stream_analog_alt_playback;
2322 p = &alc_pcm_analog_alt_playback;
2323 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2324 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2327 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2328 alc_pcm_null_stream;
2329 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2331 if (spec->num_adc_nids > 1) {
2332 p = spec->stream_analog_alt_capture;
2334 p = &alc_pcm_analog_alt_capture;
2335 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2336 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2338 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2339 spec->num_adc_nids - 1;
2341 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2342 alc_pcm_null_stream;
2343 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
2350 static inline void alc_shutup(struct hda_codec *codec)
2352 struct alc_spec *spec = codec->spec;
2354 if (spec && spec->shutup)
2355 spec->shutup(codec);
2356 snd_hda_shutup_pins(codec);
2359 static void alc_free_kctls(struct hda_codec *codec)
2361 struct alc_spec *spec = codec->spec;
2363 if (spec->kctls.list) {
2364 struct snd_kcontrol_new *kctl = spec->kctls.list;
2366 for (i = 0; i < spec->kctls.used; i++)
2367 kfree(kctl[i].name);
2369 snd_array_free(&spec->kctls);
2372 static void alc_free(struct hda_codec *codec)
2374 struct alc_spec *spec = codec->spec;
2380 snd_hda_input_jack_free(codec);
2381 alc_free_kctls(codec);
2383 snd_hda_detach_beep_device(codec);
2386 #ifdef CONFIG_SND_HDA_POWER_SAVE
2387 static void alc_power_eapd(struct hda_codec *codec)
2389 alc_auto_setup_eapd(codec, false);
2392 static int alc_suspend(struct hda_codec *codec, pm_message_t state)
2394 struct alc_spec *spec = codec->spec;
2396 if (spec && spec->power_hook)
2397 spec->power_hook(codec);
2403 static int alc_resume(struct hda_codec *codec)
2405 msleep(150); /* to avoid pop noise */
2406 codec->patch_ops.init(codec);
2407 snd_hda_codec_resume_amp(codec);
2408 snd_hda_codec_resume_cache(codec);
2409 hda_call_check_power_status(codec, 0x01);
2416 static const struct hda_codec_ops alc_patch_ops = {
2417 .build_controls = alc_build_controls,
2418 .build_pcms = alc_build_pcms,
2421 .unsol_event = alc_unsol_event,
2423 .resume = alc_resume,
2425 #ifdef CONFIG_SND_HDA_POWER_SAVE
2426 .suspend = alc_suspend,
2427 .check_power_status = alc_check_power_status,
2429 .reboot_notify = alc_shutup,
2432 /* replace the codec chip_name with the given string */
2433 static int alc_codec_rename(struct hda_codec *codec, const char *name)
2435 kfree(codec->chip_name);
2436 codec->chip_name = kstrdup(name, GFP_KERNEL);
2437 if (!codec->chip_name) {
2445 * Automatic parse of I/O pins from the BIOS configuration
2450 ALC_CTL_WIDGET_MUTE,
2453 static const struct snd_kcontrol_new alc_control_templates[] = {
2454 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2455 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2456 HDA_BIND_MUTE(NULL, 0, 0, 0),
2459 /* add dynamic controls */
2460 static int add_control(struct alc_spec *spec, int type, const char *name,
2461 int cidx, unsigned long val)
2463 struct snd_kcontrol_new *knew;
2465 knew = alc_kcontrol_new(spec);
2468 *knew = alc_control_templates[type];
2469 knew->name = kstrdup(name, GFP_KERNEL);
2473 if (get_amp_nid_(val))
2474 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
2475 knew->private_value = val;
2479 static int add_control_with_pfx(struct alc_spec *spec, int type,
2480 const char *pfx, const char *dir,
2481 const char *sfx, int cidx, unsigned long val)
2484 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
2485 return add_control(spec, type, name, cidx, val);
2488 #define add_pb_vol_ctrl(spec, type, pfx, val) \
2489 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2490 #define add_pb_sw_ctrl(spec, type, pfx, val) \
2491 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2492 #define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2493 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2494 #define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2495 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
2497 static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2498 bool can_be_master, int *index)
2500 struct auto_pin_cfg *cfg = &spec->autocfg;
2501 static const char * const chname[4] = {
2502 "Front", "Surround", NULL /*CLFE*/, "Side"
2506 if (cfg->line_outs == 1 && !spec->multi_ios &&
2507 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
2510 switch (cfg->line_out_type) {
2511 case AUTO_PIN_SPEAKER_OUT:
2512 if (cfg->line_outs == 1)
2515 case AUTO_PIN_HP_OUT:
2516 /* for multi-io case, only the primary out */
2517 if (ch && spec->multi_ios)
2522 if (cfg->line_outs == 1 && !spec->multi_ios)
2529 /* create input playback/capture controls for the given pin */
2530 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
2531 const char *ctlname, int ctlidx,
2532 int idx, hda_nid_t mix_nid)
2536 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
2537 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2540 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
2541 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2547 static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
2549 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2550 return (pincap & AC_PINCAP_IN) != 0;
2553 /* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
2554 static int alc_auto_fill_adc_caps(struct hda_codec *codec)
2556 struct alc_spec *spec = codec->spec;
2558 hda_nid_t *adc_nids = spec->private_adc_nids;
2559 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2560 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
2561 bool indep_capsrc = false;
2564 nid = codec->start_nid;
2565 for (i = 0; i < codec->num_nodes; i++, nid++) {
2567 const hda_nid_t *list;
2568 unsigned int caps = get_wcaps(codec, nid);
2569 int type = get_wcaps_type(caps);
2571 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2573 adc_nids[nums] = nid;
2574 cap_nids[nums] = nid;
2578 type = get_wcaps_type(get_wcaps(codec, src));
2579 if (type == AC_WID_PIN)
2581 if (type == AC_WID_AUD_SEL) {
2582 cap_nids[nums] = src;
2583 indep_capsrc = true;
2586 n = snd_hda_get_conn_list(codec, src, &list);
2588 cap_nids[nums] = src;
2589 indep_capsrc = true;
2595 if (++nums >= max_nums)
2598 spec->adc_nids = spec->private_adc_nids;
2599 spec->capsrc_nids = spec->private_capsrc_nids;
2600 spec->num_adc_nids = nums;
2604 /* create playback/capture controls for input pins */
2605 static int alc_auto_create_input_ctls(struct hda_codec *codec)
2607 struct alc_spec *spec = codec->spec;
2608 const struct auto_pin_cfg *cfg = &spec->autocfg;
2609 hda_nid_t mixer = spec->mixer_nid;
2610 struct hda_input_mux *imux = &spec->private_imux[0];
2612 int i, c, err, idx, type_idx = 0;
2613 const char *prev_label = NULL;
2615 num_adcs = alc_auto_fill_adc_caps(codec);
2619 for (i = 0; i < cfg->num_inputs; i++) {
2623 pin = cfg->inputs[i].pin;
2624 if (!alc_is_input_pin(codec, pin))
2627 label = hda_get_autocfg_input_label(codec, cfg, i);
2628 if (prev_label && !strcmp(label, prev_label))
2635 idx = get_connection_index(codec, mixer, pin);
2637 err = new_analog_input(spec, pin,
2645 for (c = 0; c < num_adcs; c++) {
2646 hda_nid_t cap = spec->capsrc_nids ?
2647 spec->capsrc_nids[c] : spec->adc_nids[c];
2648 idx = get_connection_index(codec, cap, pin);
2650 spec->imux_pins[imux->num_items] = pin;
2651 snd_hda_add_imux_item(imux, label, idx, NULL);
2657 spec->num_mux_defs = 1;
2658 spec->input_mux = imux;
2663 static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
2664 unsigned int pin_type)
2666 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2669 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2670 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2674 static int get_pin_type(int line_out_type)
2676 if (line_out_type == AUTO_PIN_HP_OUT)
2682 static void alc_auto_init_analog_input(struct hda_codec *codec)
2684 struct alc_spec *spec = codec->spec;
2685 struct auto_pin_cfg *cfg = &spec->autocfg;
2688 for (i = 0; i < cfg->num_inputs; i++) {
2689 hda_nid_t nid = cfg->inputs[i].pin;
2690 if (alc_is_input_pin(codec, nid)) {
2691 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
2692 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
2693 snd_hda_codec_write(codec, nid, 0,
2694 AC_VERB_SET_AMP_GAIN_MUTE,
2699 /* mute all loopback inputs */
2700 if (spec->mixer_nid) {
2701 int nums = snd_hda_get_conn_list(codec, spec->mixer_nid, NULL);
2702 for (i = 0; i < nums; i++)
2703 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2704 AC_VERB_SET_AMP_GAIN_MUTE,
2709 /* convert from MIX nid to DAC */
2710 static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid)
2715 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT)
2717 num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list));
2718 for (i = 0; i < num; i++) {
2719 if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT)
2725 /* go down to the selector widget before the mixer */
2726 static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin)
2729 int num = snd_hda_get_connections(codec, pin, srcs,
2732 get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL)
2737 /* get MIX nid connected to the given pin targeted to DAC */
2738 static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
2744 pin = alc_go_down_to_selector(codec, pin);
2745 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2746 for (i = 0; i < num; i++) {
2747 if (alc_auto_mix_to_dac(codec, mix[i]) == dac)
2753 /* select the connection from pin to DAC if needed */
2754 static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin,
2760 pin = alc_go_down_to_selector(codec, pin);
2761 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2764 for (i = 0; i < num; i++) {
2765 if (alc_auto_mix_to_dac(codec, mix[i]) == dac) {
2766 snd_hda_codec_update_cache(codec, pin, 0,
2767 AC_VERB_SET_CONNECT_SEL, i);
2774 /* look for an empty DAC slot */
2775 static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
2777 struct alc_spec *spec = codec->spec;
2781 pin = alc_go_down_to_selector(codec, pin);
2782 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
2783 for (i = 0; i < num; i++) {
2784 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
2787 if (found_in_nid_list(nid, spec->multiout.dac_nids,
2788 spec->multiout.num_dacs))
2790 if (spec->multiout.hp_nid == nid)
2792 if (found_in_nid_list(nid, spec->multiout.extra_out_nid,
2793 ARRAY_SIZE(spec->multiout.extra_out_nid)))
2800 static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
2802 hda_nid_t sel = alc_go_down_to_selector(codec, pin);
2803 if (snd_hda_get_conn_list(codec, sel, NULL) == 1)
2804 return alc_auto_look_for_dac(codec, pin);
2808 /* fill in the dac_nids table from the parsed pin configuration */
2809 static int alc_auto_fill_dac_nids(struct hda_codec *codec)
2811 struct alc_spec *spec = codec->spec;
2812 const struct auto_pin_cfg *cfg = &spec->autocfg;
2813 bool redone = false;
2817 /* set num_dacs once to full for alc_auto_look_for_dac() */
2818 spec->multiout.num_dacs = cfg->line_outs;
2819 spec->multiout.hp_nid = 0;
2820 spec->multiout.extra_out_nid[0] = 0;
2821 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
2822 spec->multiout.dac_nids = spec->private_dac_nids;
2824 /* fill hard-wired DACs first */
2826 for (i = 0; i < cfg->line_outs; i++)
2827 spec->private_dac_nids[i] =
2828 get_dac_if_single(codec, cfg->line_out_pins[i]);
2830 spec->multiout.hp_nid =
2831 get_dac_if_single(codec, cfg->hp_pins[0]);
2832 if (cfg->speaker_outs)
2833 spec->multiout.extra_out_nid[0] =
2834 get_dac_if_single(codec, cfg->speaker_pins[0]);
2837 for (i = 0; i < cfg->line_outs; i++) {
2838 hda_nid_t pin = cfg->line_out_pins[i];
2839 if (spec->private_dac_nids[i])
2841 spec->private_dac_nids[i] = alc_auto_look_for_dac(codec, pin);
2842 if (!spec->private_dac_nids[i] && !redone) {
2843 /* if we can't find primary DACs, re-probe without
2844 * checking the hard-wired DACs
2851 /* re-count num_dacs and squash invalid entries */
2852 spec->multiout.num_dacs = 0;
2853 for (i = 0; i < cfg->line_outs; i++) {
2854 if (spec->private_dac_nids[i])
2855 spec->multiout.num_dacs++;
2857 memmove(spec->private_dac_nids + i,
2858 spec->private_dac_nids + i + 1,
2859 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
2862 if (cfg->hp_outs && !spec->multiout.hp_nid)
2863 spec->multiout.hp_nid =
2864 alc_auto_look_for_dac(codec, cfg->hp_pins[0]);
2865 if (cfg->speaker_outs && !spec->multiout.extra_out_nid[0])
2866 spec->multiout.extra_out_nid[0] =
2867 alc_auto_look_for_dac(codec, cfg->speaker_pins[0]);
2872 static int alc_auto_add_vol_ctl(struct hda_codec *codec,
2873 const char *pfx, int cidx,
2874 hda_nid_t nid, unsigned int chs)
2878 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
2879 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
2882 #define alc_auto_add_stereo_vol(codec, pfx, cidx, nid) \
2883 alc_auto_add_vol_ctl(codec, pfx, cidx, nid, 3)
2885 /* create a mute-switch for the given mixer widget;
2886 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
2888 static int alc_auto_add_sw_ctl(struct hda_codec *codec,
2889 const char *pfx, int cidx,
2890 hda_nid_t nid, unsigned int chs)
2897 wid_type = get_wcaps_type(get_wcaps(codec, nid));
2898 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) {
2899 type = ALC_CTL_WIDGET_MUTE;
2900 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
2901 } else if (snd_hda_get_conn_list(codec, nid, NULL) == 1) {
2902 type = ALC_CTL_WIDGET_MUTE;
2903 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
2905 type = ALC_CTL_BIND_MUTE;
2906 val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
2908 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
2911 #define alc_auto_add_stereo_sw(codec, pfx, cidx, nid) \
2912 alc_auto_add_sw_ctl(codec, pfx, cidx, nid, 3)
2914 static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
2915 hda_nid_t pin, hda_nid_t dac)
2917 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
2918 if (nid_has_mute(codec, pin, HDA_OUTPUT))
2920 else if (mix && nid_has_mute(codec, mix, HDA_INPUT))
2922 else if (nid_has_mute(codec, dac, HDA_OUTPUT))
2927 static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
2928 hda_nid_t pin, hda_nid_t dac)
2930 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
2931 if (nid_has_volume(codec, dac, HDA_OUTPUT))
2933 else if (nid_has_volume(codec, mix, HDA_OUTPUT))
2935 else if (nid_has_volume(codec, pin, HDA_OUTPUT))
2940 /* add playback controls from the parsed DAC table */
2941 static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
2942 const struct auto_pin_cfg *cfg)
2944 struct alc_spec *spec = codec->spec;
2945 int i, err, noutputs;
2947 noutputs = cfg->line_outs;
2948 if (spec->multi_ios > 0)
2949 noutputs += spec->multi_ios;
2951 for (i = 0; i < noutputs; i++) {
2957 dac = spec->multiout.dac_nids[i];
2960 if (i >= cfg->line_outs)
2961 pin = spec->multi_io[i - 1].pin;
2963 pin = cfg->line_out_pins[i];
2965 sw = alc_look_for_out_mute_nid(codec, pin, dac);
2966 vol = alc_look_for_out_vol_nid(codec, pin, dac);
2967 name = alc_get_line_out_pfx(spec, i, true, &index);
2970 err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1);
2973 err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2);
2976 err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1);
2979 err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2);
2983 err = alc_auto_add_stereo_vol(codec, name, index, vol);
2986 err = alc_auto_add_stereo_sw(codec, name, index, sw);
2994 /* add playback controls for speaker and HP outputs */
2995 static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
2996 hda_nid_t dac, const char *pfx)
2998 struct alc_spec *spec = codec->spec;
3005 /* the corresponding DAC is already occupied */
3006 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
3007 return 0; /* no way */
3008 /* create a switch only */
3009 return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx,
3010 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3013 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3014 vol = alc_look_for_out_vol_nid(codec, pin, dac);
3015 err = alc_auto_add_stereo_vol(codec, pfx, 0, vol);
3018 err = alc_auto_add_stereo_sw(codec, pfx, 0, sw);
3024 static int alc_auto_create_hp_out(struct hda_codec *codec)
3026 struct alc_spec *spec = codec->spec;
3027 return alc_auto_create_extra_out(codec, spec->autocfg.hp_pins[0],
3028 spec->multiout.hp_nid,
3032 static int alc_auto_create_speaker_out(struct hda_codec *codec)
3034 struct alc_spec *spec = codec->spec;
3035 return alc_auto_create_extra_out(codec, spec->autocfg.speaker_pins[0],
3036 spec->multiout.extra_out_nid[0],
3040 static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
3041 hda_nid_t pin, int pin_type,
3045 hda_nid_t nid, mix = 0;
3046 hda_nid_t srcs[HDA_MAX_CONNECTIONS];
3048 alc_set_pin_output(codec, pin, pin_type);
3049 nid = alc_go_down_to_selector(codec, pin);
3050 num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
3051 for (i = 0; i < num; i++) {
3052 if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
3060 /* need the manual connection? */
3062 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
3063 /* unmute mixer widget inputs */
3064 if (nid_has_mute(codec, mix, HDA_INPUT)) {
3065 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3067 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3070 /* initialize volume */
3071 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3073 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3077 static void alc_auto_init_multi_out(struct hda_codec *codec)
3079 struct alc_spec *spec = codec->spec;
3080 int pin_type = get_pin_type(spec->autocfg.line_out_type);
3083 for (i = 0; i <= HDA_SIDE; i++) {
3084 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3086 alc_auto_set_output_and_unmute(codec, nid, pin_type,
3087 spec->multiout.dac_nids[i]);
3091 static void alc_auto_init_extra_out(struct hda_codec *codec)
3093 struct alc_spec *spec = codec->spec;
3096 pin = spec->autocfg.hp_pins[0];
3098 alc_auto_set_output_and_unmute(codec, pin, PIN_HP,
3099 spec->multiout.hp_nid);
3100 pin = spec->autocfg.speaker_pins[0];
3102 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT,
3103 spec->multiout.extra_out_nid[0]);
3109 static int alc_auto_fill_multi_ios(struct hda_codec *codec,
3110 unsigned int location)
3112 struct alc_spec *spec = codec->spec;
3113 struct auto_pin_cfg *cfg = &spec->autocfg;
3114 int type, i, num_pins = 0;
3116 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3117 for (i = 0; i < cfg->num_inputs; i++) {
3118 hda_nid_t nid = cfg->inputs[i].pin;
3120 unsigned int defcfg, caps;
3121 if (cfg->inputs[i].type != type)
3123 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3124 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3126 if (location && get_defcfg_location(defcfg) != location)
3128 caps = snd_hda_query_pin_caps(codec, nid);
3129 if (!(caps & AC_PINCAP_OUT))
3131 dac = alc_auto_look_for_dac(codec, nid);
3134 spec->multi_io[num_pins].pin = nid;
3135 spec->multi_io[num_pins].dac = dac;
3137 spec->private_dac_nids[spec->multiout.num_dacs++] = dac;
3140 spec->multiout.num_dacs = 1;
3146 static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
3147 struct snd_ctl_elem_info *uinfo)
3149 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3150 struct alc_spec *spec = codec->spec;
3152 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3154 uinfo->value.enumerated.items = spec->multi_ios + 1;
3155 if (uinfo->value.enumerated.item > spec->multi_ios)
3156 uinfo->value.enumerated.item = spec->multi_ios;
3157 sprintf(uinfo->value.enumerated.name, "%dch",
3158 (uinfo->value.enumerated.item + 1) * 2);
3162 static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
3163 struct snd_ctl_elem_value *ucontrol)
3165 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3166 struct alc_spec *spec = codec->spec;
3167 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
3171 static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
3173 struct alc_spec *spec = codec->spec;
3174 hda_nid_t nid = spec->multi_io[idx].pin;
3176 if (!spec->multi_io[idx].ctl_in)
3177 spec->multi_io[idx].ctl_in =
3178 snd_hda_codec_read(codec, nid, 0,
3179 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3181 snd_hda_codec_update_cache(codec, nid, 0,
3182 AC_VERB_SET_PIN_WIDGET_CONTROL,
3184 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3185 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3187 alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
3189 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3190 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3191 HDA_AMP_MUTE, HDA_AMP_MUTE);
3192 snd_hda_codec_update_cache(codec, nid, 0,
3193 AC_VERB_SET_PIN_WIDGET_CONTROL,
3194 spec->multi_io[idx].ctl_in);
3199 static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
3200 struct snd_ctl_elem_value *ucontrol)
3202 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3203 struct alc_spec *spec = codec->spec;
3206 ch = ucontrol->value.enumerated.item[0];
3207 if (ch < 0 || ch > spec->multi_ios)
3209 if (ch == (spec->ext_channel_count - 1) / 2)
3211 spec->ext_channel_count = (ch + 1) * 2;
3212 for (i = 0; i < spec->multi_ios; i++)
3213 alc_set_multi_io(codec, i, i < ch);
3214 spec->multiout.max_channels = spec->ext_channel_count;
3215 if (spec->need_dac_fix && !spec->const_channel_count)
3216 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
3220 static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
3221 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3222 .name = "Channel Mode",
3223 .info = alc_auto_ch_mode_info,
3224 .get = alc_auto_ch_mode_get,
3225 .put = alc_auto_ch_mode_put,
3228 static int alc_auto_add_multi_channel_mode(struct hda_codec *codec,
3229 int (*fill_dac)(struct hda_codec *))
3231 struct alc_spec *spec = codec->spec;
3232 struct auto_pin_cfg *cfg = &spec->autocfg;
3233 unsigned int location, defcfg;
3236 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT && cfg->hp_outs == 1) {
3237 /* use HP as primary out */
3238 cfg->speaker_outs = cfg->line_outs;
3239 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3240 sizeof(cfg->speaker_pins));
3241 cfg->line_outs = cfg->hp_outs;
3242 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
3244 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3245 cfg->line_out_type = AUTO_PIN_HP_OUT;
3249 if (cfg->line_outs != 1 ||
3250 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
3253 defcfg = snd_hda_codec_get_pincfg(codec, cfg->line_out_pins[0]);
3254 location = get_defcfg_location(defcfg);
3256 num_pins = alc_auto_fill_multi_ios(codec, location);
3258 struct snd_kcontrol_new *knew;
3260 knew = alc_kcontrol_new(spec);
3263 *knew = alc_auto_channel_mode_enum;
3264 knew->name = kstrdup("Channel Mode", GFP_KERNEL);
3268 spec->multi_ios = num_pins;
3269 spec->ext_channel_count = 2;
3270 spec->multiout.num_dacs = num_pins + 1;
3275 /* filter out invalid adc_nids (and capsrc_nids) that don't give all
3278 static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
3280 struct alc_spec *spec = codec->spec;
3281 const struct hda_input_mux *imux;
3282 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3283 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3286 imux = spec->input_mux;
3289 if (spec->dyn_adc_switch)
3293 for (n = 0; n < spec->num_adc_nids; n++) {
3294 hda_nid_t cap = spec->private_capsrc_nids[n];
3295 int num_conns = snd_hda_get_conn_list(codec, cap, NULL);
3296 for (i = 0; i < imux->num_items; i++) {
3297 hda_nid_t pin = spec->imux_pins[i];
3299 if (get_connection_index(codec, cap, pin) < 0)
3301 } else if (num_conns <= imux->items[i].index)
3304 if (i >= imux->num_items) {
3305 adc_nids[nums] = spec->private_adc_nids[n];
3306 capsrc_nids[nums++] = cap;
3310 /* check whether ADC-switch is possible */
3311 if (!alc_check_dyn_adc_switch(codec)) {
3312 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
3313 " using fallback 0x%x\n",
3314 codec->chip_name, spec->private_adc_nids[0]);
3315 spec->num_adc_nids = 1;
3319 } else if (nums != spec->num_adc_nids) {
3320 memcpy(spec->private_adc_nids, adc_nids,
3321 nums * sizeof(hda_nid_t));
3322 memcpy(spec->private_capsrc_nids, capsrc_nids,
3323 nums * sizeof(hda_nid_t));
3324 spec->num_adc_nids = nums;
3328 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
3329 else if (spec->input_mux->num_items == 1)
3330 spec->num_adc_nids = 1; /* reduce to a single ADC */
3334 * initialize ADC paths
3336 static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
3338 struct alc_spec *spec = codec->spec;
3341 nid = spec->adc_nids[adc_idx];
3343 if (nid_has_mute(codec, nid, HDA_INPUT)) {
3344 snd_hda_codec_write(codec, nid, 0,
3345 AC_VERB_SET_AMP_GAIN_MUTE,
3349 if (!spec->capsrc_nids)
3351 nid = spec->capsrc_nids[adc_idx];
3352 if (nid_has_mute(codec, nid, HDA_OUTPUT))
3353 snd_hda_codec_write(codec, nid, 0,
3354 AC_VERB_SET_AMP_GAIN_MUTE,
3358 static void alc_auto_init_input_src(struct hda_codec *codec)
3360 struct alc_spec *spec = codec->spec;
3363 for (c = 0; c < spec->num_adc_nids; c++)
3364 alc_auto_init_adc(codec, c);
3365 if (spec->dyn_adc_switch)
3368 nums = spec->num_adc_nids;
3369 for (c = 0; c < nums; c++)
3370 alc_mux_select(codec, 0, spec->cur_mux[c], true);
3373 /* add mic boosts if needed */
3374 static int alc_auto_add_mic_boost(struct hda_codec *codec)
3376 struct alc_spec *spec = codec->spec;
3377 struct auto_pin_cfg *cfg = &spec->autocfg;
3381 const char *prev_label = NULL;
3383 for (i = 0; i < cfg->num_inputs; i++) {
3384 if (cfg->inputs[i].type > AUTO_PIN_MIC)
3386 nid = cfg->inputs[i].pin;
3387 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
3389 char boost_label[32];
3391 label = hda_get_autocfg_input_label(codec, cfg, i);
3392 if (prev_label && !strcmp(label, prev_label))
3398 snprintf(boost_label, sizeof(boost_label),
3399 "%s Boost Volume", label);
3400 err = add_control(spec, ALC_CTL_WIDGET_VOL,
3401 boost_label, type_idx,
3402 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
3410 /* select or unmute the given capsrc route */
3411 static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
3414 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
3415 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
3417 } else if (snd_hda_get_conn_list(codec, cap, NULL) > 1) {
3418 snd_hda_codec_write_cache(codec, cap, 0,
3419 AC_VERB_SET_CONNECT_SEL, idx);
3423 /* set the default connection to that pin */
3424 static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
3426 struct alc_spec *spec = codec->spec;
3431 for (i = 0; i < spec->num_adc_nids; i++) {
3432 hda_nid_t cap = spec->capsrc_nids ?
3433 spec->capsrc_nids[i] : spec->adc_nids[i];
3436 idx = get_connection_index(codec, cap, pin);
3439 select_or_unmute_capsrc(codec, cap, idx);
3440 return i; /* return the found index */
3442 return -1; /* not found */
3445 /* initialize some special cases for input sources */
3446 static void alc_init_special_input_src(struct hda_codec *codec)
3448 struct alc_spec *spec = codec->spec;
3451 for (i = 0; i < spec->autocfg.num_inputs; i++)
3452 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
3455 /* assign appropriate capture mixers */
3456 static void set_capture_mixer(struct hda_codec *codec)
3458 struct alc_spec *spec = codec->spec;
3459 static const struct snd_kcontrol_new *caps[2][3] = {
3460 { alc_capture_mixer_nosrc1,
3461 alc_capture_mixer_nosrc2,
3462 alc_capture_mixer_nosrc3 },
3463 { alc_capture_mixer1,
3465 alc_capture_mixer3 },
3468 /* check whether either of ADC or MUX has a volume control */
3469 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
3470 if (!spec->capsrc_nids)
3471 return; /* no volume */
3472 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
3473 return; /* no volume in capsrc, too */
3474 spec->vol_in_capsrc = 1;
3477 if (spec->num_adc_nids > 0) {
3481 if (spec->input_mux && spec->input_mux->num_items > 1)
3483 if (spec->auto_mic) {
3486 } else if (spec->dyn_adc_switch)
3489 if (spec->num_adc_nids > 3)
3490 spec->num_adc_nids = 3;
3491 else if (!spec->num_adc_nids)
3493 num_adcs = spec->num_adc_nids;
3495 spec->cap_mixer = caps[mux][num_adcs - 1];
3500 * standard auto-parser initializations
3502 static void alc_auto_init_std(struct hda_codec *codec)
3504 struct alc_spec *spec = codec->spec;
3505 alc_auto_init_multi_out(codec);
3506 alc_auto_init_extra_out(codec);
3507 alc_auto_init_analog_input(codec);
3508 alc_auto_init_input_src(codec);
3509 alc_auto_init_digital(codec);
3510 if (spec->unsol_event)
3511 alc_inithook(codec);
3515 * Digital-beep handlers
3517 #ifdef CONFIG_SND_HDA_INPUT_BEEP
3518 #define set_beep_amp(spec, nid, idx, dir) \
3519 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
3521 static const struct snd_pci_quirk beep_white_list[] = {
3522 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
3523 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
3524 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
3525 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
3526 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
3530 static inline int has_cdefine_beep(struct hda_codec *codec)
3532 struct alc_spec *spec = codec->spec;
3533 const struct snd_pci_quirk *q;
3534 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
3537 return spec->cdefine.enable_pcbeep;
3540 #define set_beep_amp(spec, nid, idx, dir) /* NOP */
3541 #define has_cdefine_beep(codec) 0
3544 /* parse the BIOS configuration and set up the alc_spec */
3545 /* return 1 if successful, 0 if the proper config is not found,
3546 * or a negative error code
3548 static int alc_parse_auto_config(struct hda_codec *codec,
3549 const hda_nid_t *ignore_nids,
3550 const hda_nid_t *ssid_nids)
3552 struct alc_spec *spec = codec->spec;
3555 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
3559 if (!spec->autocfg.line_outs) {
3560 if (spec->autocfg.dig_outs || spec->autocfg.dig_in_pin) {
3561 spec->multiout.max_channels = 2;
3562 spec->no_analog = 1;
3565 return 0; /* can't find valid BIOS pin config */
3567 err = alc_auto_fill_dac_nids(codec);
3570 err = alc_auto_add_multi_channel_mode(codec, alc_auto_fill_dac_nids);
3573 err = alc_auto_create_multi_out_ctls(codec, &spec->autocfg);
3576 err = alc_auto_create_hp_out(codec);
3579 err = alc_auto_create_speaker_out(codec);
3582 err = alc_auto_create_input_ctls(codec);
3586 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3589 alc_auto_parse_digital(codec);
3591 if (!spec->no_analog)
3592 alc_remove_invalid_adc_nids(codec);
3595 alc_ssid_check(codec, ssid_nids);
3597 if (!spec->no_analog) {
3598 alc_auto_check_switches(codec);
3599 err = alc_auto_add_mic_boost(codec);
3604 if (spec->kctls.list)
3605 add_mixer(spec, spec->kctls.list);
3610 static int alc880_parse_auto_config(struct hda_codec *codec)
3612 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
3613 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
3614 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
3617 #ifdef CONFIG_SND_HDA_POWER_SAVE
3618 static const struct hda_amp_list alc880_loopbacks[] = {
3619 { 0x0b, HDA_INPUT, 0 },
3620 { 0x0b, HDA_INPUT, 1 },
3621 { 0x0b, HDA_INPUT, 2 },
3622 { 0x0b, HDA_INPUT, 3 },
3623 { 0x0b, HDA_INPUT, 4 },
3631 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3632 #define alc_board_config \
3633 snd_hda_check_board_config
3634 #define alc_board_codec_sid_config \
3635 snd_hda_check_board_codec_sid_config
3636 #include "alc_quirks.c"
3638 #define alc_board_config(codec, nums, models, tbl) -1
3639 #define alc_board_codec_sid_config(codec, nums, models, tbl) -1
3640 #define setup_preset(codec, x) /* NOP */
3644 * OK, here we have finally the patch for ALC880
3646 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3647 #include "alc880_quirks.c"
3650 static int patch_alc880(struct hda_codec *codec)
3652 struct alc_spec *spec;
3656 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3662 spec->mixer_nid = 0x0b;
3663 spec->need_dac_fix = 1;
3665 board_config = alc_board_config(codec, ALC880_MODEL_LAST,
3666 alc880_models, alc880_cfg_tbl);
3667 if (board_config < 0) {
3668 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
3670 board_config = ALC_MODEL_AUTO;
3673 if (board_config == ALC_MODEL_AUTO) {
3674 /* automatic parse from the BIOS config */
3675 err = alc880_parse_auto_config(codec);
3680 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3683 "hda_codec: Cannot set up configuration "
3684 "from BIOS. Using 3-stack mode...\n");
3685 board_config = ALC880_3ST;
3690 if (board_config != ALC_MODEL_AUTO)
3691 setup_preset(codec, &alc880_presets[board_config]);
3693 if (!spec->no_analog && !spec->adc_nids) {
3694 alc_auto_fill_adc_caps(codec);
3695 alc_rebuild_imux_for_auto_mic(codec);
3696 alc_remove_invalid_adc_nids(codec);
3699 if (!spec->no_analog && !spec->cap_mixer)
3700 set_capture_mixer(codec);
3702 if (!spec->no_analog) {
3703 err = snd_hda_attach_beep_device(codec, 0x1);
3708 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
3711 spec->vmaster_nid = 0x0c;
3713 codec->patch_ops = alc_patch_ops;
3714 if (board_config == ALC_MODEL_AUTO)
3715 spec->init_hook = alc_auto_init_std;
3716 #ifdef CONFIG_SND_HDA_POWER_SAVE
3717 if (!spec->loopback.amplist)
3718 spec->loopback.amplist = alc880_loopbacks;
3728 static int alc260_parse_auto_config(struct hda_codec *codec)
3730 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
3731 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
3732 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
3735 #ifdef CONFIG_SND_HDA_POWER_SAVE
3736 static const struct hda_amp_list alc260_loopbacks[] = {
3737 { 0x07, HDA_INPUT, 0 },
3738 { 0x07, HDA_INPUT, 1 },
3739 { 0x07, HDA_INPUT, 2 },
3740 { 0x07, HDA_INPUT, 3 },
3741 { 0x07, HDA_INPUT, 4 },
3753 static const struct alc_fixup alc260_fixups[] = {
3754 [PINFIX_HP_DC5750] = {
3755 .type = ALC_FIXUP_PINS,
3756 .v.pins = (const struct alc_pincfg[]) {
3757 { 0x11, 0x90130110 }, /* speaker */
3763 static const struct snd_pci_quirk alc260_fixup_tbl[] = {
3764 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", PINFIX_HP_DC5750),
3770 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3771 #include "alc260_quirks.c"
3774 static int patch_alc260(struct hda_codec *codec)
3776 struct alc_spec *spec;
3777 int err, board_config;
3779 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3785 spec->mixer_nid = 0x07;
3787 board_config = alc_board_config(codec, ALC260_MODEL_LAST,
3788 alc260_models, alc260_cfg_tbl);
3789 if (board_config < 0) {
3790 snd_printd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
3792 board_config = ALC_MODEL_AUTO;
3795 if (board_config == ALC_MODEL_AUTO) {
3796 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
3797 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
3800 if (board_config == ALC_MODEL_AUTO) {
3801 /* automatic parse from the BIOS config */
3802 err = alc260_parse_auto_config(codec);
3807 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3810 "hda_codec: Cannot set up configuration "
3811 "from BIOS. Using base mode...\n");
3812 board_config = ALC260_BASIC;
3817 if (board_config != ALC_MODEL_AUTO)
3818 setup_preset(codec, &alc260_presets[board_config]);
3820 if (!spec->no_analog && !spec->adc_nids) {
3821 alc_auto_fill_adc_caps(codec);
3822 alc_rebuild_imux_for_auto_mic(codec);
3823 alc_remove_invalid_adc_nids(codec);
3826 if (!spec->no_analog && !spec->cap_mixer)
3827 set_capture_mixer(codec);
3829 if (!spec->no_analog) {
3830 err = snd_hda_attach_beep_device(codec, 0x1);
3835 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
3838 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
3840 spec->vmaster_nid = 0x08;
3842 codec->patch_ops = alc_patch_ops;
3843 if (board_config == ALC_MODEL_AUTO)
3844 spec->init_hook = alc_auto_init_std;
3845 spec->shutup = alc_eapd_shutup;
3846 #ifdef CONFIG_SND_HDA_POWER_SAVE
3847 if (!spec->loopback.amplist)
3848 spec->loopback.amplist = alc260_loopbacks;
3856 * ALC882/883/885/888/889 support
3858 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
3859 * configuration. Each pin widget can choose any input DACs and a mixer.
3860 * Each ADC is connected from a mixer of all inputs. This makes possible
3861 * 6-channel independent captures.
3863 * In addition, an independent DAC for the multi-playback (not used in this
3866 #ifdef CONFIG_SND_HDA_POWER_SAVE
3867 #define alc882_loopbacks alc880_loopbacks
3874 PINFIX_ABIT_AW9D_MAX,
3877 PINFIX_ACER_ASPIRE_7736,
3880 static const struct alc_fixup alc882_fixups[] = {
3881 [PINFIX_ABIT_AW9D_MAX] = {
3882 .type = ALC_FIXUP_PINS,
3883 .v.pins = (const struct alc_pincfg[]) {
3884 { 0x15, 0x01080104 }, /* side */
3885 { 0x16, 0x01011012 }, /* rear */
3886 { 0x17, 0x01016011 }, /* clfe */
3890 [PINFIX_LENOVO_Y530] = {
3891 .type = ALC_FIXUP_PINS,
3892 .v.pins = (const struct alc_pincfg[]) {
3893 { 0x15, 0x99130112 }, /* rear int speakers */
3894 { 0x16, 0x99130111 }, /* subwoofer */
3898 [PINFIX_PB_M5210] = {
3899 .type = ALC_FIXUP_VERBS,
3900 .v.verbs = (const struct hda_verb[]) {
3901 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
3905 [PINFIX_ACER_ASPIRE_7736] = {
3906 .type = ALC_FIXUP_SKU,
3907 .v.sku = ALC_FIXUP_SKU_IGNORE,
3911 static const struct snd_pci_quirk alc882_fixup_tbl[] = {
3912 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", PINFIX_PB_M5210),
3913 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", PINFIX_LENOVO_Y530),
3914 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
3915 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", PINFIX_ACER_ASPIRE_7736),
3920 * BIOS auto configuration
3922 /* almost identical with ALC880 parser... */
3923 static int alc882_parse_auto_config(struct hda_codec *codec)
3925 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
3926 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
3927 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
3932 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3933 #include "alc882_quirks.c"
3936 static int patch_alc882(struct hda_codec *codec)
3938 struct alc_spec *spec;
3939 int err, board_config;
3941 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3947 spec->mixer_nid = 0x0b;
3949 switch (codec->vendor_id) {
3954 /* ALC883 and variants */
3955 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
3959 board_config = alc_board_config(codec, ALC882_MODEL_LAST,
3960 alc882_models, alc882_cfg_tbl);
3962 if (board_config < 0)
3963 board_config = alc_board_codec_sid_config(codec,
3964 ALC882_MODEL_LAST, alc882_models, alc882_ssid_cfg_tbl);
3966 if (board_config < 0) {
3967 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
3969 board_config = ALC_MODEL_AUTO;
3972 if (board_config == ALC_MODEL_AUTO) {
3973 alc_pick_fixup(codec, NULL, alc882_fixup_tbl, alc882_fixups);
3974 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
3977 alc_auto_parse_customize_define(codec);
3979 if (board_config == ALC_MODEL_AUTO) {
3980 /* automatic parse from the BIOS config */
3981 err = alc882_parse_auto_config(codec);
3986 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3989 "hda_codec: Cannot set up configuration "
3990 "from BIOS. Using base mode...\n");
3991 board_config = ALC882_3ST_DIG;
3996 if (board_config != ALC_MODEL_AUTO)
3997 setup_preset(codec, &alc882_presets[board_config]);
3999 if (!spec->no_analog && !spec->adc_nids) {
4000 alc_auto_fill_adc_caps(codec);
4001 alc_rebuild_imux_for_auto_mic(codec);
4002 alc_remove_invalid_adc_nids(codec);
4005 if (!spec->no_analog && !spec->cap_mixer)
4006 set_capture_mixer(codec);
4008 if (!spec->no_analog && has_cdefine_beep(codec)) {
4009 err = snd_hda_attach_beep_device(codec, 0x1);
4014 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4017 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4019 spec->vmaster_nid = 0x0c;
4021 codec->patch_ops = alc_patch_ops;
4022 if (board_config == ALC_MODEL_AUTO)
4023 spec->init_hook = alc_auto_init_std;
4025 alc_init_jacks(codec);
4026 #ifdef CONFIG_SND_HDA_POWER_SAVE
4027 if (!spec->loopback.amplist)
4028 spec->loopback.amplist = alc882_loopbacks;
4038 static int alc262_parse_auto_config(struct hda_codec *codec)
4040 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
4041 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4042 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
4053 static const struct alc_fixup alc262_fixups[] = {
4054 [PINFIX_FSC_H270] = {
4055 .type = ALC_FIXUP_PINS,
4056 .v.pins = (const struct alc_pincfg[]) {
4057 { 0x14, 0x99130110 }, /* speaker */
4058 { 0x15, 0x0221142f }, /* front HP */
4059 { 0x1b, 0x0121141f }, /* rear HP */
4063 [PINFIX_HP_Z200] = {
4064 .type = ALC_FIXUP_PINS,
4065 .v.pins = (const struct alc_pincfg[]) {
4066 { 0x16, 0x99130120 }, /* internal speaker */
4072 static const struct snd_pci_quirk alc262_fixup_tbl[] = {
4073 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", PINFIX_HP_Z200),
4074 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", PINFIX_FSC_H270),
4079 #ifdef CONFIG_SND_HDA_POWER_SAVE
4080 #define alc262_loopbacks alc880_loopbacks
4085 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4086 #include "alc262_quirks.c"
4089 static int patch_alc262(struct hda_codec *codec)
4091 struct alc_spec *spec;
4095 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4101 spec->mixer_nid = 0x0b;
4104 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
4109 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4110 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
4111 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4112 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
4115 alc_auto_parse_customize_define(codec);
4117 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
4119 board_config = alc_board_config(codec, ALC262_MODEL_LAST,
4120 alc262_models, alc262_cfg_tbl);
4122 if (board_config < 0) {
4123 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4125 board_config = ALC_MODEL_AUTO;
4128 if (board_config == ALC_MODEL_AUTO) {
4129 alc_pick_fixup(codec, NULL, alc262_fixup_tbl, alc262_fixups);
4130 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4133 if (board_config == ALC_MODEL_AUTO) {
4134 /* automatic parse from the BIOS config */
4135 err = alc262_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 = ALC262_BASIC;
4150 if (board_config != ALC_MODEL_AUTO)
4151 setup_preset(codec, &alc262_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;
4178 spec->shutup = alc_eapd_shutup;
4180 alc_init_jacks(codec);
4181 #ifdef CONFIG_SND_HDA_POWER_SAVE
4182 if (!spec->loopback.amplist)
4183 spec->loopback.amplist = alc262_loopbacks;
4192 /* bind Beep switches of both NID 0x0f and 0x10 */
4193 static const struct hda_bind_ctls alc268_bind_beep_sw = {
4194 .ops = &snd_hda_bind_sw,
4196 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
4197 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
4202 static const struct snd_kcontrol_new alc268_beep_mixer[] = {
4203 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
4204 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
4208 /* set PCBEEP vol = 0, mute connections */
4209 static const struct hda_verb alc268_beep_init_verbs[] = {
4210 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4211 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4212 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4217 * BIOS auto configuration
4219 static int alc268_parse_auto_config(struct hda_codec *codec)
4221 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4222 struct alc_spec *spec = codec->spec;
4223 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
4225 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
4226 add_mixer(spec, alc268_beep_mixer);
4227 add_verb(spec, alc268_beep_init_verbs);
4235 static int patch_alc268(struct hda_codec *codec)
4237 struct alc_spec *spec;
4238 int i, has_beep, err;
4240 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4246 /* ALC268 has no aa-loopback mixer */
4248 /* automatic parse from the BIOS config */
4249 err = alc268_parse_auto_config(codec);
4256 for (i = 0; i < spec->num_mixers; i++) {
4257 if (spec->mixers[i] == alc268_beep_mixer) {
4264 err = snd_hda_attach_beep_device(codec, 0x1);
4269 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
4270 /* override the amp caps for beep generator */
4271 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
4272 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
4273 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
4274 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4275 (0 << AC_AMPCAP_MUTE_SHIFT));
4278 if (!spec->no_analog && !spec->adc_nids) {
4279 alc_auto_fill_adc_caps(codec);
4280 alc_rebuild_imux_for_auto_mic(codec);
4281 alc_remove_invalid_adc_nids(codec);
4284 if (!spec->no_analog && !spec->cap_mixer)
4285 set_capture_mixer(codec);
4287 spec->vmaster_nid = 0x02;
4289 codec->patch_ops = alc_patch_ops;
4290 spec->init_hook = alc_auto_init_std;
4291 spec->shutup = alc_eapd_shutup;
4293 alc_init_jacks(codec);
4301 #ifdef CONFIG_SND_HDA_POWER_SAVE
4302 #define alc269_loopbacks alc880_loopbacks
4305 static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
4309 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
4310 /* NID is set in alc_build_pcms */
4312 .open = alc_playback_pcm_open,
4313 .prepare = alc_playback_pcm_prepare,
4314 .cleanup = alc_playback_pcm_cleanup
4318 static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
4322 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
4323 /* NID is set in alc_build_pcms */
4326 #ifdef CONFIG_SND_HDA_POWER_SAVE
4327 static int alc269_mic2_for_mute_led(struct hda_codec *codec)
4329 switch (codec->subsystem_id) {
4336 static int alc269_mic2_mute_check_ps(struct hda_codec *codec, hda_nid_t nid)
4338 /* update mute-LED according to the speaker mute state */
4339 if (nid == 0x01 || nid == 0x14) {
4341 if (snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0) &
4346 /* mic2 vref pin is used for mute LED control */
4347 snd_hda_codec_update_cache(codec, 0x19, 0,
4348 AC_VERB_SET_PIN_WIDGET_CONTROL,
4351 return alc_check_power_status(codec, nid);
4353 #endif /* CONFIG_SND_HDA_POWER_SAVE */
4355 /* different alc269-variants */
4357 ALC269_TYPE_ALC269VA,
4358 ALC269_TYPE_ALC269VB,
4359 ALC269_TYPE_ALC269VC,
4363 * BIOS auto configuration
4365 static int alc269_parse_auto_config(struct hda_codec *codec)
4367 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
4368 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
4369 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4370 struct alc_spec *spec = codec->spec;
4371 const hda_nid_t *ssids = spec->codec_variant == ALC269_TYPE_ALC269VA ?
4372 alc269va_ssids : alc269_ssids;
4374 return alc_parse_auto_config(codec, alc269_ignore, ssids);
4377 static void alc269_toggle_power_output(struct hda_codec *codec, int power_up)
4379 int val = alc_read_coef_idx(codec, 0x04);
4384 alc_write_coef_idx(codec, 0x04, val);
4387 static void alc269_shutup(struct hda_codec *codec)
4389 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x017)
4390 alc269_toggle_power_output(codec, 0);
4391 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x018) {
4392 alc269_toggle_power_output(codec, 0);
4398 static int alc269_resume(struct hda_codec *codec)
4400 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x018) {
4401 alc269_toggle_power_output(codec, 0);
4405 codec->patch_ops.init(codec);
4407 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x017) {
4408 alc269_toggle_power_output(codec, 1);
4412 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x018)
4413 alc269_toggle_power_output(codec, 1);
4415 snd_hda_codec_resume_amp(codec);
4416 snd_hda_codec_resume_cache(codec);
4417 hda_call_check_power_status(codec, 0x01);
4420 #endif /* CONFIG_PM */
4422 static void alc269_fixup_hweq(struct hda_codec *codec,
4423 const struct alc_fixup *fix, int action)
4427 if (action != ALC_FIXUP_ACT_INIT)
4429 coef = alc_read_coef_idx(codec, 0x1e);
4430 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
4433 static void alc271_fixup_dmic(struct hda_codec *codec,
4434 const struct alc_fixup *fix, int action)
4436 static const struct hda_verb verbs[] = {
4437 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
4438 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
4443 if (strcmp(codec->chip_name, "ALC271X"))
4445 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
4446 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
4447 snd_hda_sequence_write(codec, verbs);
4450 static void alc269_fixup_pcm_44k(struct hda_codec *codec,
4451 const struct alc_fixup *fix, int action)
4453 struct alc_spec *spec = codec->spec;
4455 if (action != ALC_FIXUP_ACT_PROBE)
4458 /* Due to a hardware problem on Lenovo Ideadpad, we need to
4459 * fix the sample rate of analog I/O to 44.1kHz
4461 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
4462 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
4465 static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
4466 const struct alc_fixup *fix, int action)
4470 if (action != ALC_FIXUP_ACT_INIT)
4472 /* The digital-mic unit sends PDM (differential signal) instead of
4473 * the standard PCM, thus you can't record a valid mono stream as is.
4474 * Below is a workaround specific to ALC269 to control the dmic
4475 * signal source as mono.
4477 coef = alc_read_coef_idx(codec, 0x07);
4478 alc_write_coef_idx(codec, 0x07, coef | 0x80);
4481 static void alc269_quanta_automute(struct hda_codec *codec)
4483 update_speakers(codec);
4485 snd_hda_codec_write(codec, 0x20, 0,
4486 AC_VERB_SET_COEF_INDEX, 0x0c);
4487 snd_hda_codec_write(codec, 0x20, 0,
4488 AC_VERB_SET_PROC_COEF, 0x680);
4490 snd_hda_codec_write(codec, 0x20, 0,
4491 AC_VERB_SET_COEF_INDEX, 0x0c);
4492 snd_hda_codec_write(codec, 0x20, 0,
4493 AC_VERB_SET_PROC_COEF, 0x480);
4496 static void alc269_fixup_quanta_mute(struct hda_codec *codec,
4497 const struct alc_fixup *fix, int action)
4499 struct alc_spec *spec = codec->spec;
4500 if (action != ALC_FIXUP_ACT_PROBE)
4502 spec->automute_hook = alc269_quanta_automute;
4506 ALC269_FIXUP_SONY_VAIO,
4507 ALC275_FIXUP_SONY_VAIO_GPIO2,
4508 ALC269_FIXUP_DELL_M101Z,
4509 ALC269_FIXUP_SKU_IGNORE,
4510 ALC269_FIXUP_ASUS_G73JW,
4511 ALC269_FIXUP_LENOVO_EAPD,
4512 ALC275_FIXUP_SONY_HWEQ,
4514 ALC269_FIXUP_PCM_44K,
4515 ALC269_FIXUP_STEREO_DMIC,
4516 ALC269_FIXUP_QUANTA_MUTE,
4517 ALC269_FIXUP_LIFEBOOK,
4520 static const struct alc_fixup alc269_fixups[] = {
4521 [ALC269_FIXUP_SONY_VAIO] = {
4522 .type = ALC_FIXUP_VERBS,
4523 .v.verbs = (const struct hda_verb[]) {
4524 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
4528 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
4529 .type = ALC_FIXUP_VERBS,
4530 .v.verbs = (const struct hda_verb[]) {
4531 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
4532 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
4533 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
4537 .chain_id = ALC269_FIXUP_SONY_VAIO
4539 [ALC269_FIXUP_DELL_M101Z] = {
4540 .type = ALC_FIXUP_VERBS,
4541 .v.verbs = (const struct hda_verb[]) {
4542 /* Enables internal speaker */
4543 {0x20, AC_VERB_SET_COEF_INDEX, 13},
4544 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
4548 [ALC269_FIXUP_SKU_IGNORE] = {
4549 .type = ALC_FIXUP_SKU,
4550 .v.sku = ALC_FIXUP_SKU_IGNORE,
4552 [ALC269_FIXUP_ASUS_G73JW] = {
4553 .type = ALC_FIXUP_PINS,
4554 .v.pins = (const struct alc_pincfg[]) {
4555 { 0x17, 0x99130111 }, /* subwoofer */
4559 [ALC269_FIXUP_LENOVO_EAPD] = {
4560 .type = ALC_FIXUP_VERBS,
4561 .v.verbs = (const struct hda_verb[]) {
4562 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
4566 [ALC275_FIXUP_SONY_HWEQ] = {
4567 .type = ALC_FIXUP_FUNC,
4568 .v.func = alc269_fixup_hweq,
4570 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
4572 [ALC271_FIXUP_DMIC] = {
4573 .type = ALC_FIXUP_FUNC,
4574 .v.func = alc271_fixup_dmic,
4576 [ALC269_FIXUP_PCM_44K] = {
4577 .type = ALC_FIXUP_FUNC,
4578 .v.func = alc269_fixup_pcm_44k,
4580 [ALC269_FIXUP_STEREO_DMIC] = {
4581 .type = ALC_FIXUP_FUNC,
4582 .v.func = alc269_fixup_stereo_dmic,
4584 [ALC269_FIXUP_QUANTA_MUTE] = {
4585 .type = ALC_FIXUP_FUNC,
4586 .v.func = alc269_fixup_quanta_mute,
4588 [ALC269_FIXUP_LIFEBOOK] = {
4589 .type = ALC_FIXUP_PINS,
4590 .v.pins = (const struct alc_pincfg[]) {
4591 { 0x1a, 0x2101103f }, /* dock line-out */
4592 { 0x1b, 0x23a11040 }, /* dock mic-in */
4596 .chain_id = ALC269_FIXUP_QUANTA_MUTE
4600 static const struct snd_pci_quirk alc269_fixup_tbl[] = {
4601 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
4602 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
4603 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
4604 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
4605 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
4606 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
4607 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
4608 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
4609 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
4610 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
4611 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
4612 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
4613 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
4614 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
4615 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
4616 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
4617 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
4618 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
4619 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_QUANTA_MUTE),
4620 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K),
4621 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
4626 static int alc269_fill_coef(struct hda_codec *codec)
4630 if ((alc_read_coef_idx(codec, 0) & 0x00ff) < 0x015) {
4631 alc_write_coef_idx(codec, 0xf, 0x960b);
4632 alc_write_coef_idx(codec, 0xe, 0x8817);
4635 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x016) {
4636 alc_write_coef_idx(codec, 0xf, 0x960b);
4637 alc_write_coef_idx(codec, 0xe, 0x8814);
4640 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x017) {
4641 val = alc_read_coef_idx(codec, 0x04);
4642 /* Power up output pin */
4643 alc_write_coef_idx(codec, 0x04, val | (1<<11));
4646 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x018) {
4647 val = alc_read_coef_idx(codec, 0xd);
4648 if ((val & 0x0c00) >> 10 != 0x1) {
4649 /* Capless ramp up clock control */
4650 alc_write_coef_idx(codec, 0xd, val | (1<<10));
4652 val = alc_read_coef_idx(codec, 0x17);
4653 if ((val & 0x01c0) >> 6 != 0x4) {
4654 /* Class D power on reset */
4655 alc_write_coef_idx(codec, 0x17, val | (1<<7));
4659 val = alc_read_coef_idx(codec, 0xd); /* Class D */
4660 alc_write_coef_idx(codec, 0xd, val | (1<<14));
4662 val = alc_read_coef_idx(codec, 0x4); /* HP */
4663 alc_write_coef_idx(codec, 0x4, val | (1<<11));
4670 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4671 #include "alc269_quirks.c"
4674 static int patch_alc269(struct hda_codec *codec)
4676 struct alc_spec *spec;
4677 int board_config, coef;
4680 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4686 spec->mixer_nid = 0x0b;
4688 alc_auto_parse_customize_define(codec);
4690 if (codec->vendor_id == 0x10ec0269) {
4691 spec->codec_variant = ALC269_TYPE_ALC269VA;
4692 coef = alc_read_coef_idx(codec, 0);
4693 if ((coef & 0x00f0) == 0x0010) {
4694 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
4695 spec->cdefine.platform_type == 1) {
4696 alc_codec_rename(codec, "ALC271X");
4697 } else if ((coef & 0xf000) == 0x2000) {
4698 alc_codec_rename(codec, "ALC259");
4699 } else if ((coef & 0xf000) == 0x3000) {
4700 alc_codec_rename(codec, "ALC258");
4701 } else if ((coef & 0xfff0) == 0x3010) {
4702 alc_codec_rename(codec, "ALC277");
4704 alc_codec_rename(codec, "ALC269VB");
4706 spec->codec_variant = ALC269_TYPE_ALC269VB;
4707 } else if ((coef & 0x00f0) == 0x0020) {
4709 alc_codec_rename(codec, "ALC259");
4710 else if (coef == 0x6023)
4711 alc_codec_rename(codec, "ALC281X");
4712 else if (codec->bus->pci->subsystem_vendor == 0x17aa &&
4713 codec->bus->pci->subsystem_device == 0x21f3)
4714 alc_codec_rename(codec, "ALC3202");
4716 alc_codec_rename(codec, "ALC269VC");
4717 spec->codec_variant = ALC269_TYPE_ALC269VC;
4719 alc_fix_pll_init(codec, 0x20, 0x04, 15);
4720 alc269_fill_coef(codec);
4723 board_config = alc_board_config(codec, ALC269_MODEL_LAST,
4724 alc269_models, alc269_cfg_tbl);
4726 if (board_config < 0) {
4727 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4729 board_config = ALC_MODEL_AUTO;
4732 if (board_config == ALC_MODEL_AUTO) {
4733 alc_pick_fixup(codec, NULL, alc269_fixup_tbl, alc269_fixups);
4734 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4737 if (board_config == ALC_MODEL_AUTO) {
4738 /* automatic parse from the BIOS config */
4739 err = alc269_parse_auto_config(codec);
4744 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4747 "hda_codec: Cannot set up configuration "
4748 "from BIOS. Using base mode...\n");
4749 board_config = ALC269_BASIC;
4754 if (board_config != ALC_MODEL_AUTO)
4755 setup_preset(codec, &alc269_presets[board_config]);
4757 if (!spec->no_analog && !spec->adc_nids) {
4758 alc_auto_fill_adc_caps(codec);
4759 alc_rebuild_imux_for_auto_mic(codec);
4760 alc_remove_invalid_adc_nids(codec);
4763 if (!spec->no_analog && !spec->cap_mixer)
4764 set_capture_mixer(codec);
4766 if (!spec->no_analog && has_cdefine_beep(codec)) {
4767 err = snd_hda_attach_beep_device(codec, 0x1);
4772 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
4775 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4777 spec->vmaster_nid = 0x02;
4779 codec->patch_ops = alc_patch_ops;
4781 codec->patch_ops.resume = alc269_resume;
4783 if (board_config == ALC_MODEL_AUTO)
4784 spec->init_hook = alc_auto_init_std;
4785 spec->shutup = alc269_shutup;
4787 alc_init_jacks(codec);
4788 #ifdef CONFIG_SND_HDA_POWER_SAVE
4789 if (!spec->loopback.amplist)
4790 spec->loopback.amplist = alc269_loopbacks;
4791 if (alc269_mic2_for_mute_led(codec))
4792 codec->patch_ops.check_power_status = alc269_mic2_mute_check_ps;
4802 static int alc861_parse_auto_config(struct hda_codec *codec)
4804 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
4805 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
4806 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
4809 #ifdef CONFIG_SND_HDA_POWER_SAVE
4810 static const struct hda_amp_list alc861_loopbacks[] = {
4811 { 0x15, HDA_INPUT, 0 },
4812 { 0x15, HDA_INPUT, 1 },
4813 { 0x15, HDA_INPUT, 2 },
4814 { 0x15, HDA_INPUT, 3 },
4820 /* Pin config fixes */
4822 PINFIX_FSC_AMILO_PI1505,
4825 static const struct alc_fixup alc861_fixups[] = {
4826 [PINFIX_FSC_AMILO_PI1505] = {
4827 .type = ALC_FIXUP_PINS,
4828 .v.pins = (const struct alc_pincfg[]) {
4829 { 0x0b, 0x0221101f }, /* HP */
4830 { 0x0f, 0x90170310 }, /* speaker */
4836 static const struct snd_pci_quirk alc861_fixup_tbl[] = {
4837 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", PINFIX_FSC_AMILO_PI1505),
4843 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4844 #include "alc861_quirks.c"
4847 static int patch_alc861(struct hda_codec *codec)
4849 struct alc_spec *spec;
4853 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4859 spec->mixer_nid = 0x15;
4861 board_config = alc_board_config(codec, ALC861_MODEL_LAST,
4862 alc861_models, alc861_cfg_tbl);
4864 if (board_config < 0) {
4865 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4867 board_config = ALC_MODEL_AUTO;
4870 if (board_config == ALC_MODEL_AUTO) {
4871 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
4872 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4875 if (board_config == ALC_MODEL_AUTO) {
4876 /* automatic parse from the BIOS config */
4877 err = alc861_parse_auto_config(codec);
4882 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4885 "hda_codec: Cannot set up configuration "
4886 "from BIOS. Using base mode...\n");
4887 board_config = ALC861_3ST_DIG;
4892 if (board_config != ALC_MODEL_AUTO)
4893 setup_preset(codec, &alc861_presets[board_config]);
4895 if (!spec->no_analog && !spec->adc_nids) {
4896 alc_auto_fill_adc_caps(codec);
4897 alc_rebuild_imux_for_auto_mic(codec);
4898 alc_remove_invalid_adc_nids(codec);
4901 if (!spec->no_analog && !spec->cap_mixer)
4902 set_capture_mixer(codec);
4904 if (!spec->no_analog) {
4905 err = snd_hda_attach_beep_device(codec, 0x23);
4910 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
4913 spec->vmaster_nid = 0x03;
4915 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4917 codec->patch_ops = alc_patch_ops;
4918 if (board_config == ALC_MODEL_AUTO) {
4919 spec->init_hook = alc_auto_init_std;
4920 #ifdef CONFIG_SND_HDA_POWER_SAVE
4921 spec->power_hook = alc_power_eapd;
4924 #ifdef CONFIG_SND_HDA_POWER_SAVE
4925 if (!spec->loopback.amplist)
4926 spec->loopback.amplist = alc861_loopbacks;
4937 * In addition, an independent DAC
4939 #ifdef CONFIG_SND_HDA_POWER_SAVE
4940 #define alc861vd_loopbacks alc880_loopbacks
4943 static int alc861vd_parse_auto_config(struct hda_codec *codec)
4945 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
4946 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4947 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
4951 ALC660VD_FIX_ASUS_GPIO1
4955 static const struct alc_fixup alc861vd_fixups[] = {
4956 [ALC660VD_FIX_ASUS_GPIO1] = {
4957 .type = ALC_FIXUP_VERBS,
4958 .v.verbs = (const struct hda_verb[]) {
4959 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
4960 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
4961 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
4967 static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
4968 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
4972 static const struct hda_verb alc660vd_eapd_verbs[] = {
4973 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
4974 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
4980 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4981 #include "alc861vd_quirks.c"
4984 static int patch_alc861vd(struct hda_codec *codec)
4986 struct alc_spec *spec;
4987 int err, board_config;
4989 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4995 spec->mixer_nid = 0x0b;
4997 board_config = alc_board_config(codec, ALC861VD_MODEL_LAST,
4998 alc861vd_models, alc861vd_cfg_tbl);
5000 if (board_config < 0) {
5001 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5003 board_config = ALC_MODEL_AUTO;
5006 if (board_config == ALC_MODEL_AUTO) {
5007 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
5008 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5011 if (board_config == ALC_MODEL_AUTO) {
5012 /* automatic parse from the BIOS config */
5013 err = alc861vd_parse_auto_config(codec);
5018 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
5021 "hda_codec: Cannot set up configuration "
5022 "from BIOS. Using base mode...\n");
5023 board_config = ALC861VD_3ST;
5028 if (board_config != ALC_MODEL_AUTO)
5029 setup_preset(codec, &alc861vd_presets[board_config]);
5031 if (codec->vendor_id == 0x10ec0660) {
5032 /* always turn on EAPD */
5033 add_verb(spec, alc660vd_eapd_verbs);
5036 if (!spec->no_analog && !spec->adc_nids) {
5037 alc_auto_fill_adc_caps(codec);
5038 alc_rebuild_imux_for_auto_mic(codec);
5039 alc_remove_invalid_adc_nids(codec);
5042 if (!spec->no_analog && !spec->cap_mixer)
5043 set_capture_mixer(codec);
5045 if (!spec->no_analog) {
5046 err = snd_hda_attach_beep_device(codec, 0x23);
5051 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5054 spec->vmaster_nid = 0x02;
5056 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5058 codec->patch_ops = alc_patch_ops;
5060 if (board_config == ALC_MODEL_AUTO)
5061 spec->init_hook = alc_auto_init_std;
5062 spec->shutup = alc_eapd_shutup;
5063 #ifdef CONFIG_SND_HDA_POWER_SAVE
5064 if (!spec->loopback.amplist)
5065 spec->loopback.amplist = alc861vd_loopbacks;
5074 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
5075 * configuration. Each pin widget can choose any input DACs and a mixer.
5076 * Each ADC is connected from a mixer of all inputs. This makes possible
5077 * 6-channel independent captures.
5079 * In addition, an independent DAC for the multi-playback (not used in this
5082 #ifdef CONFIG_SND_HDA_POWER_SAVE
5083 #define alc662_loopbacks alc880_loopbacks
5087 * BIOS auto configuration
5090 static int alc662_parse_auto_config(struct hda_codec *codec)
5092 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
5093 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
5094 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5095 const hda_nid_t *ssids;
5097 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
5098 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
5099 ssids = alc663_ssids;
5101 ssids = alc662_ssids;
5102 return alc_parse_auto_config(codec, alc662_ignore, ssids);
5105 static void alc272_fixup_mario(struct hda_codec *codec,
5106 const struct alc_fixup *fix, int action)
5108 if (action != ALC_FIXUP_ACT_PROBE)
5110 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
5111 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
5112 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
5113 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5114 (0 << AC_AMPCAP_MUTE_SHIFT)))
5116 "hda_codec: failed to override amp caps for NID 0x2\n");
5120 ALC662_FIXUP_ASPIRE,
5121 ALC662_FIXUP_IDEAPAD,
5123 ALC662_FIXUP_CZC_P10T,
5124 ALC662_FIXUP_SKU_IGNORE,
5125 ALC662_FIXUP_HP_RP5800,
5129 static const struct alc_fixup alc662_fixups[] = {
5130 [ALC662_FIXUP_ASPIRE] = {
5131 .type = ALC_FIXUP_PINS,
5132 .v.pins = (const struct alc_pincfg[]) {
5133 { 0x15, 0x99130112 }, /* subwoofer */
5137 [ALC662_FIXUP_IDEAPAD] = {
5138 .type = ALC_FIXUP_PINS,
5139 .v.pins = (const struct alc_pincfg[]) {
5140 { 0x17, 0x99130112 }, /* subwoofer */
5144 [ALC272_FIXUP_MARIO] = {
5145 .type = ALC_FIXUP_FUNC,
5146 .v.func = alc272_fixup_mario,
5148 [ALC662_FIXUP_CZC_P10T] = {
5149 .type = ALC_FIXUP_VERBS,
5150 .v.verbs = (const struct hda_verb[]) {
5151 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
5155 [ALC662_FIXUP_SKU_IGNORE] = {
5156 .type = ALC_FIXUP_SKU,
5157 .v.sku = ALC_FIXUP_SKU_IGNORE,
5159 [ALC662_FIXUP_HP_RP5800] = {
5160 .type = ALC_FIXUP_PINS,
5161 .v.pins = (const struct alc_pincfg[]) {
5162 { 0x14, 0x0221201f }, /* HP out */
5166 .chain_id = ALC662_FIXUP_SKU_IGNORE
5168 [ALC662_FIXUP_ECS] = {
5169 .type = ALC_FIXUP_PINS,
5170 .v.pins = (const struct alc_pincfg[]) {
5171 { 0x14, 0x99130110 }, /* speaker */
5172 { 0x18, 0x01a19820 }, /* mic */
5173 { 0x19, 0x99a3092f }, /* int-mic */
5174 { 0x1b, 0x0121401f }, /* HP out */
5180 static const struct snd_pci_quirk alc662_fixup_tbl[] = {
5181 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ECS),
5182 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
5183 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
5184 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
5185 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
5186 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ECS),
5187 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
5188 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
5189 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
5190 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
5194 static const struct alc_model_fixup alc662_fixup_models[] = {
5195 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
5202 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
5203 #include "alc662_quirks.c"
5206 static int patch_alc662(struct hda_codec *codec)
5208 struct alc_spec *spec;
5209 int err, board_config;
5212 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5218 spec->mixer_nid = 0x0b;
5220 alc_auto_parse_customize_define(codec);
5222 alc_fix_pll_init(codec, 0x20, 0x04, 15);
5224 coef = alc_read_coef_idx(codec, 0);
5225 if (coef == 0x8020 || coef == 0x8011)
5226 alc_codec_rename(codec, "ALC661");
5227 else if (coef & (1 << 14) &&
5228 codec->bus->pci->subsystem_vendor == 0x1025 &&
5229 spec->cdefine.platform_type == 1)
5230 alc_codec_rename(codec, "ALC272X");
5231 else if (coef == 0x4011)
5232 alc_codec_rename(codec, "ALC656");
5234 board_config = alc_board_config(codec, ALC662_MODEL_LAST,
5235 alc662_models, alc662_cfg_tbl);
5236 if (board_config < 0) {
5237 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5239 board_config = ALC_MODEL_AUTO;
5242 if (board_config == ALC_MODEL_AUTO) {
5243 alc_pick_fixup(codec, alc662_fixup_models,
5244 alc662_fixup_tbl, alc662_fixups);
5245 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5246 /* automatic parse from the BIOS config */
5247 err = alc662_parse_auto_config(codec);
5252 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
5255 "hda_codec: Cannot set up configuration "
5256 "from BIOS. Using base mode...\n");
5257 board_config = ALC662_3ST_2ch_DIG;
5262 if (board_config != ALC_MODEL_AUTO)
5263 setup_preset(codec, &alc662_presets[board_config]);
5265 if (!spec->no_analog && !spec->adc_nids) {
5266 alc_auto_fill_adc_caps(codec);
5267 alc_rebuild_imux_for_auto_mic(codec);
5268 alc_remove_invalid_adc_nids(codec);
5271 if (!spec->no_analog && !spec->cap_mixer)
5272 set_capture_mixer(codec);
5274 if (!spec->no_analog && has_cdefine_beep(codec)) {
5275 err = snd_hda_attach_beep_device(codec, 0x1);
5280 switch (codec->vendor_id) {
5282 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5287 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
5290 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
5294 spec->vmaster_nid = 0x02;
5296 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5298 codec->patch_ops = alc_patch_ops;
5299 if (board_config == ALC_MODEL_AUTO)
5300 spec->init_hook = alc_auto_init_std;
5301 spec->shutup = alc_eapd_shutup;
5303 alc_init_jacks(codec);
5305 #ifdef CONFIG_SND_HDA_POWER_SAVE
5306 if (!spec->loopback.amplist)
5307 spec->loopback.amplist = alc662_loopbacks;
5313 static int patch_alc888(struct hda_codec *codec)
5315 if ((alc_read_coef_idx(codec, 0) & 0x00f0)==0x0030){
5316 kfree(codec->chip_name);
5317 if (codec->vendor_id == 0x10ec0887)
5318 codec->chip_name = kstrdup("ALC887-VD", GFP_KERNEL);
5320 codec->chip_name = kstrdup("ALC888-VD", GFP_KERNEL);
5321 if (!codec->chip_name) {
5325 return patch_alc662(codec);
5327 return patch_alc882(codec);
5330 static int patch_alc899(struct hda_codec *codec)
5332 if ((alc_read_coef_idx(codec, 0) & 0x2000) != 0x2000) {
5333 kfree(codec->chip_name);
5334 codec->chip_name = kstrdup("ALC898", GFP_KERNEL);
5336 return patch_alc882(codec);
5343 static int alc680_parse_auto_config(struct hda_codec *codec)
5345 return alc_parse_auto_config(codec, NULL, NULL);
5350 static int patch_alc680(struct hda_codec *codec)
5352 struct alc_spec *spec;
5355 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5361 /* ALC680 has no aa-loopback mixer */
5363 /* automatic parse from the BIOS config */
5364 err = alc680_parse_auto_config(codec);
5370 if (!spec->no_analog && !spec->cap_mixer)
5371 set_capture_mixer(codec);
5373 spec->vmaster_nid = 0x02;
5375 codec->patch_ops = alc_patch_ops;
5376 spec->init_hook = alc_auto_init_std;
5384 static const struct hda_codec_preset snd_hda_preset_realtek[] = {
5385 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
5386 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
5387 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
5388 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
5389 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
5390 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
5391 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
5392 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
5393 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
5394 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
5395 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
5396 .patch = patch_alc861 },
5397 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
5398 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
5399 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
5400 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
5401 .patch = patch_alc882 },
5402 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
5403 .patch = patch_alc662 },
5404 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
5405 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
5406 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
5407 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
5408 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
5409 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
5410 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
5411 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
5412 .patch = patch_alc882 },
5413 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
5414 .patch = patch_alc882 },
5415 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
5416 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc888 },
5417 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
5418 .patch = patch_alc882 },
5419 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc888 },
5420 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
5421 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
5422 { .id = 0x10ec0899, .name = "ALC899", .patch = patch_alc899 },
5426 MODULE_ALIAS("snd-hda-codec-id:10ec*");
5428 MODULE_LICENSE("GPL");
5429 MODULE_DESCRIPTION("Realtek HD-audio codec");
5431 static struct hda_codec_preset_list realtek_list = {
5432 .preset = snd_hda_preset_realtek,
5433 .owner = THIS_MODULE,
5436 static int __init patch_realtek_init(void)
5438 return snd_hda_add_codec_preset(&realtek_list);
5441 static void __exit patch_realtek_exit(void)
5443 snd_hda_delete_codec_preset(&realtek_list);
5446 module_init(patch_realtek_init)
5447 module_exit(patch_realtek_exit)