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 */
119 DECLARE_BITMAP(vol_ctls, 0x20 << 1);
120 DECLARE_BITMAP(sw_ctls, 0x20 << 1);
122 /* capture setup for dynamic dual-adc switch */
124 unsigned int cur_adc_stream_tag;
125 unsigned int cur_adc_format;
128 unsigned int num_mux_defs;
129 const struct hda_input_mux *input_mux;
130 unsigned int cur_mux[3];
131 hda_nid_t ext_mic_pin;
132 hda_nid_t dock_mic_pin;
133 hda_nid_t int_mic_pin;
136 const struct hda_channel_mode *channel_mode;
137 int num_channel_mode;
139 int const_channel_count;
140 int ext_channel_count;
142 /* PCM information */
143 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
145 /* dynamic controls, init_verbs and input_mux */
146 struct auto_pin_cfg autocfg;
147 struct alc_customize_define cdefine;
148 struct snd_array kctls;
149 struct hda_input_mux private_imux[3];
150 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
151 hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS];
152 hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS];
153 hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS];
154 unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS];
155 int int_mic_idx, ext_mic_idx, dock_mic_idx; /* for auto-mic */
158 void (*init_hook)(struct hda_codec *codec);
159 void (*unsol_event)(struct hda_codec *codec, unsigned int res);
160 #ifdef CONFIG_SND_HDA_POWER_SAVE
161 void (*power_hook)(struct hda_codec *codec);
163 void (*shutup)(struct hda_codec *codec);
164 void (*automute_hook)(struct hda_codec *codec);
166 /* for pin sensing */
167 unsigned int hp_jack_present:1;
168 unsigned int line_jack_present:1;
169 unsigned int master_mute:1;
170 unsigned int auto_mic:1;
171 unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */
172 unsigned int automute_speaker:1; /* automute speaker outputs */
173 unsigned int automute_lo:1; /* automute LO outputs */
174 unsigned int detect_hp:1; /* Headphone detection enabled */
175 unsigned int detect_lo:1; /* Line-out detection enabled */
176 unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */
177 unsigned int automute_lo_possible:1; /* there are line outs and HP */
180 unsigned int no_analog :1; /* digital I/O only */
181 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
182 unsigned int single_input_src:1;
183 unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */
184 unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */
186 /* auto-mute control */
188 hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS];
191 int codec_variant; /* flag for other variants */
193 /* for virtual master */
194 hda_nid_t vmaster_nid;
195 #ifdef CONFIG_SND_HDA_POWER_SAVE
196 struct hda_loopback_check loopback;
201 unsigned int pll_coef_idx, pll_coef_bit;
206 const struct alc_fixup *fixup_list;
207 const char *fixup_name;
211 struct alc_multi_io multi_io[4];
214 struct snd_array bind_ctls;
217 #define ALC_MODEL_AUTO 0 /* common for all chips */
219 static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
220 int dir, unsigned int bits)
224 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
225 if (query_amp_caps(codec, nid, dir) & bits)
230 #define nid_has_mute(codec, nid, dir) \
231 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
232 #define nid_has_volume(codec, nid, dir) \
233 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
238 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
239 struct snd_ctl_elem_info *uinfo)
241 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
242 struct alc_spec *spec = codec->spec;
243 unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
244 if (mux_idx >= spec->num_mux_defs)
246 if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
248 return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
251 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
252 struct snd_ctl_elem_value *ucontrol)
254 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
255 struct alc_spec *spec = codec->spec;
256 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
258 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
262 static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
264 struct alc_spec *spec = codec->spec;
265 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
267 if (spec->cur_adc && spec->cur_adc != new_adc) {
268 /* stream is running, let's swap the current ADC */
269 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
270 spec->cur_adc = new_adc;
271 snd_hda_codec_setup_stream(codec, new_adc,
272 spec->cur_adc_stream_tag, 0,
273 spec->cur_adc_format);
279 /* select the given imux item; either unmute exclusively or select the route */
280 static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
281 unsigned int idx, bool force)
283 struct alc_spec *spec = codec->spec;
284 const struct hda_input_mux *imux;
285 unsigned int mux_idx;
289 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
290 imux = &spec->input_mux[mux_idx];
291 if (!imux->num_items && mux_idx > 0)
292 imux = &spec->input_mux[0];
294 if (idx >= imux->num_items)
295 idx = imux->num_items - 1;
296 if (spec->cur_mux[adc_idx] == idx && !force)
298 spec->cur_mux[adc_idx] = idx;
300 if (spec->dyn_adc_switch) {
301 alc_dyn_adc_pcm_resetup(codec, idx);
302 adc_idx = spec->dyn_adc_idx[idx];
305 nid = spec->capsrc_nids ?
306 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
309 if (snd_hda_get_conn_list(codec, nid, NULL) <= 1)
312 type = get_wcaps_type(get_wcaps(codec, nid));
313 if (type == AC_WID_AUD_MIX) {
314 /* Matrix-mixer style (e.g. ALC882) */
315 for (i = 0; i < imux->num_items; i++) {
316 unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
317 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
318 imux->items[i].index,
322 /* MUX style (e.g. ALC880) */
323 snd_hda_codec_write_cache(codec, nid, 0,
324 AC_VERB_SET_CONNECT_SEL,
325 imux->items[idx].index);
330 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
331 struct snd_ctl_elem_value *ucontrol)
333 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
334 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
335 return alc_mux_select(codec, adc_idx,
336 ucontrol->value.enumerated.item[0], false);
340 * set up the input pin config (depending on the given auto-pin type)
342 static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
345 unsigned int val = PIN_IN;
347 if (auto_pin_type == AUTO_PIN_MIC) {
350 oldval = snd_hda_codec_read(codec, nid, 0,
351 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
352 pincap = snd_hda_query_pin_caps(codec, nid);
353 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
354 /* if the default pin setup is vref50, we give it priority */
355 if ((pincap & AC_PINCAP_VREF_80) && oldval != PIN_VREF50)
357 else if (pincap & AC_PINCAP_VREF_50)
359 else if (pincap & AC_PINCAP_VREF_100)
361 else if (pincap & AC_PINCAP_VREF_GRD)
364 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val);
368 * Append the given mixer and verb elements for the later use
369 * The mixer array is referred in build_controls(), and init_verbs are
372 static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
374 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
376 spec->mixers[spec->num_mixers++] = mix;
379 static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
381 if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
383 spec->init_verbs[spec->num_init_verbs++] = verb;
387 * GPIO setup tables, used in initialization
389 /* Enable GPIO mask and set output */
390 static const struct hda_verb alc_gpio1_init_verbs[] = {
391 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
392 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
393 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
397 static const struct hda_verb alc_gpio2_init_verbs[] = {
398 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
399 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
400 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
404 static const struct hda_verb alc_gpio3_init_verbs[] = {
405 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
406 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
407 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
412 * Fix hardware PLL issue
413 * On some codecs, the analog PLL gating control must be off while
414 * the default value is 1.
416 static void alc_fix_pll(struct hda_codec *codec)
418 struct alc_spec *spec = codec->spec;
423 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
425 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
426 AC_VERB_GET_PROC_COEF, 0);
427 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
429 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
430 val & ~(1 << spec->pll_coef_bit));
433 static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
434 unsigned int coef_idx, unsigned int coef_bit)
436 struct alc_spec *spec = codec->spec;
438 spec->pll_coef_idx = coef_idx;
439 spec->pll_coef_bit = coef_bit;
444 * Jack-reporting via input-jack layer
447 /* initialization of jacks; currently checks only a few known pins */
448 static int alc_init_jacks(struct hda_codec *codec)
450 #ifdef CONFIG_SND_HDA_INPUT_JACK
451 struct alc_spec *spec = codec->spec;
453 unsigned int hp_nid = spec->autocfg.hp_pins[0];
454 unsigned int mic_nid = spec->ext_mic_pin;
455 unsigned int dock_nid = spec->dock_mic_pin;
458 err = snd_hda_input_jack_add(codec, hp_nid,
459 SND_JACK_HEADPHONE, NULL);
462 snd_hda_input_jack_report(codec, hp_nid);
466 err = snd_hda_input_jack_add(codec, mic_nid,
467 SND_JACK_MICROPHONE, NULL);
470 snd_hda_input_jack_report(codec, mic_nid);
473 err = snd_hda_input_jack_add(codec, dock_nid,
474 SND_JACK_MICROPHONE, NULL);
477 snd_hda_input_jack_report(codec, dock_nid);
479 #endif /* CONFIG_SND_HDA_INPUT_JACK */
484 * Jack detections for HP auto-mute and mic-switch
487 /* check each pin in the given array; returns true if any of them is plugged */
488 static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
492 for (i = 0; i < num_pins; i++) {
493 hda_nid_t nid = pins[i];
496 snd_hda_input_jack_report(codec, nid);
497 present |= snd_hda_jack_detect(codec, nid);
502 /* standard HP/line-out auto-mute helper */
503 static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
504 bool mute, bool hp_out)
506 struct alc_spec *spec = codec->spec;
507 unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0;
508 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
511 for (i = 0; i < num_pins; i++) {
512 hda_nid_t nid = pins[i];
515 switch (spec->automute_mode) {
516 case ALC_AUTOMUTE_PIN:
517 snd_hda_codec_write(codec, nid, 0,
518 AC_VERB_SET_PIN_WIDGET_CONTROL,
521 case ALC_AUTOMUTE_AMP:
522 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
523 HDA_AMP_MUTE, mute_bits);
525 case ALC_AUTOMUTE_MIXER:
526 nid = spec->automute_mixer_nid[i];
529 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
530 HDA_AMP_MUTE, mute_bits);
531 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1,
532 HDA_AMP_MUTE, mute_bits);
538 /* Toggle outputs muting */
539 static void update_outputs(struct hda_codec *codec)
541 struct alc_spec *spec = codec->spec;
544 /* Control HP pins/amps depending on master_mute state;
545 * in general, HP pins/amps control should be enabled in all cases,
546 * but currently set only for master_mute, just to be safe
548 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
549 spec->autocfg.hp_pins, spec->master_mute, true);
551 if (!spec->automute_speaker)
554 on = spec->hp_jack_present | spec->line_jack_present;
555 on |= spec->master_mute;
556 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
557 spec->autocfg.speaker_pins, on, false);
559 /* toggle line-out mutes if needed, too */
560 /* if LO is a copy of either HP or Speaker, don't need to handle it */
561 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
562 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
564 if (!spec->automute_lo)
567 on = spec->hp_jack_present;
568 on |= spec->master_mute;
569 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
570 spec->autocfg.line_out_pins, on, false);
573 static void call_update_outputs(struct hda_codec *codec)
575 struct alc_spec *spec = codec->spec;
576 if (spec->automute_hook)
577 spec->automute_hook(codec);
579 update_outputs(codec);
582 /* standard HP-automute helper */
583 static void alc_hp_automute(struct hda_codec *codec)
585 struct alc_spec *spec = codec->spec;
587 spec->hp_jack_present =
588 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
589 spec->autocfg.hp_pins);
590 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
592 call_update_outputs(codec);
595 /* standard line-out-automute helper */
596 static void alc_line_automute(struct hda_codec *codec)
598 struct alc_spec *spec = codec->spec;
600 /* check LO jack only when it's different from HP */
601 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
604 spec->line_jack_present =
605 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
606 spec->autocfg.line_out_pins);
607 if (!spec->automute_speaker || !spec->detect_lo)
609 call_update_outputs(codec);
612 #define get_connection_index(codec, mux, nid) \
613 snd_hda_get_conn_index(codec, mux, nid, 0)
615 /* standard mic auto-switch helper */
616 static void alc_mic_automute(struct hda_codec *codec)
618 struct alc_spec *spec = codec->spec;
619 hda_nid_t *pins = spec->imux_pins;
621 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
623 if (snd_BUG_ON(!spec->adc_nids))
625 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
628 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
629 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
630 else if (spec->dock_mic_idx >= 0 &&
631 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
632 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
634 alc_mux_select(codec, 0, spec->int_mic_idx, false);
636 snd_hda_input_jack_report(codec, pins[spec->ext_mic_idx]);
637 if (spec->dock_mic_idx >= 0)
638 snd_hda_input_jack_report(codec, pins[spec->dock_mic_idx]);
641 /* unsolicited event for HP jack sensing */
642 static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
644 if (codec->vendor_id == 0x10ec0880)
650 alc_hp_automute(codec);
652 case ALC_FRONT_EVENT:
653 alc_line_automute(codec);
656 alc_mic_automute(codec);
661 /* call init functions of standard auto-mute helpers */
662 static void alc_inithook(struct hda_codec *codec)
664 alc_hp_automute(codec);
665 alc_line_automute(codec);
666 alc_mic_automute(codec);
669 /* additional initialization for ALC888 variants */
670 static void alc888_coef_init(struct hda_codec *codec)
674 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
675 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
676 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
677 if ((tmp & 0xf0) == 0x20)
679 snd_hda_codec_read(codec, 0x20, 0,
680 AC_VERB_SET_PROC_COEF, 0x830);
683 snd_hda_codec_read(codec, 0x20, 0,
684 AC_VERB_SET_PROC_COEF, 0x3030);
687 /* additional initialization for ALC889 variants */
688 static void alc889_coef_init(struct hda_codec *codec)
692 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
693 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
694 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
695 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
698 /* turn on/off EAPD control (only if available) */
699 static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
701 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
703 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
704 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
708 /* turn on/off EAPD controls of the codec */
709 static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
711 /* We currently only handle front, HP */
712 static hda_nid_t pins[] = {
713 0x0f, 0x10, 0x14, 0x15, 0
716 for (p = pins; *p; p++)
717 set_eapd(codec, *p, on);
720 /* generic shutup callback;
721 * just turning off EPAD and a little pause for avoiding pop-noise
723 static void alc_eapd_shutup(struct hda_codec *codec)
725 alc_auto_setup_eapd(codec, false);
729 /* generic EAPD initialization */
730 static void alc_auto_init_amp(struct hda_codec *codec, int type)
734 alc_auto_setup_eapd(codec, true);
737 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
740 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
743 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
745 case ALC_INIT_DEFAULT:
746 switch (codec->vendor_id) {
748 snd_hda_codec_write(codec, 0x1a, 0,
749 AC_VERB_SET_COEF_INDEX, 7);
750 tmp = snd_hda_codec_read(codec, 0x1a, 0,
751 AC_VERB_GET_PROC_COEF, 0);
752 snd_hda_codec_write(codec, 0x1a, 0,
753 AC_VERB_SET_COEF_INDEX, 7);
754 snd_hda_codec_write(codec, 0x1a, 0,
755 AC_VERB_SET_PROC_COEF,
764 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
765 alc889_coef_init(codec);
768 alc888_coef_init(codec);
770 #if 0 /* XXX: This may cause the silent output on speaker on some machines */
773 snd_hda_codec_write(codec, 0x20, 0,
774 AC_VERB_SET_COEF_INDEX, 7);
775 tmp = snd_hda_codec_read(codec, 0x20, 0,
776 AC_VERB_GET_PROC_COEF, 0);
777 snd_hda_codec_write(codec, 0x20, 0,
778 AC_VERB_SET_COEF_INDEX, 7);
779 snd_hda_codec_write(codec, 0x20, 0,
780 AC_VERB_SET_PROC_COEF,
790 * Auto-Mute mode mixer enum support
792 static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
793 struct snd_ctl_elem_info *uinfo)
795 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
796 struct alc_spec *spec = codec->spec;
797 static const char * const texts2[] = {
798 "Disabled", "Enabled"
800 static const char * const texts3[] = {
801 "Disabled", "Speaker Only", "Line-Out+Speaker"
803 const char * const *texts;
805 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
807 if (spec->automute_speaker_possible && spec->automute_lo_possible) {
808 uinfo->value.enumerated.items = 3;
811 uinfo->value.enumerated.items = 2;
814 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
815 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
816 strcpy(uinfo->value.enumerated.name,
817 texts[uinfo->value.enumerated.item]);
821 static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
822 struct snd_ctl_elem_value *ucontrol)
824 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
825 struct alc_spec *spec = codec->spec;
826 unsigned int val = 0;
827 if (spec->automute_speaker)
829 if (spec->automute_lo)
832 ucontrol->value.enumerated.item[0] = val;
836 static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
837 struct snd_ctl_elem_value *ucontrol)
839 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
840 struct alc_spec *spec = codec->spec;
842 switch (ucontrol->value.enumerated.item[0]) {
844 if (!spec->automute_speaker && !spec->automute_lo)
846 spec->automute_speaker = 0;
847 spec->automute_lo = 0;
850 if (spec->automute_speaker_possible) {
851 if (!spec->automute_lo && spec->automute_speaker)
853 spec->automute_speaker = 1;
854 spec->automute_lo = 0;
855 } else if (spec->automute_lo_possible) {
856 if (spec->automute_lo)
858 spec->automute_lo = 1;
863 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
865 if (spec->automute_speaker && spec->automute_lo)
867 spec->automute_speaker = 1;
868 spec->automute_lo = 1;
873 call_update_outputs(codec);
877 static const struct snd_kcontrol_new alc_automute_mode_enum = {
878 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
879 .name = "Auto-Mute Mode",
880 .info = alc_automute_mode_info,
881 .get = alc_automute_mode_get,
882 .put = alc_automute_mode_put,
885 static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec)
887 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
888 return snd_array_new(&spec->kctls);
891 static int alc_add_automute_mode_enum(struct hda_codec *codec)
893 struct alc_spec *spec = codec->spec;
894 struct snd_kcontrol_new *knew;
896 knew = alc_kcontrol_new(spec);
899 *knew = alc_automute_mode_enum;
900 knew->name = kstrdup("Auto-Mute Mode", GFP_KERNEL);
907 * Check the availability of HP/line-out auto-mute;
908 * Set up appropriately if really supported
910 static void alc_init_automute(struct hda_codec *codec)
912 struct alc_spec *spec = codec->spec;
913 struct auto_pin_cfg *cfg = &spec->autocfg;
919 if (cfg->line_out_pins[0])
921 if (cfg->speaker_pins[0])
923 if (present < 2) /* need two different output types */
926 if (!cfg->speaker_pins[0] &&
927 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
928 memcpy(cfg->speaker_pins, cfg->line_out_pins,
929 sizeof(cfg->speaker_pins));
930 cfg->speaker_outs = cfg->line_outs;
933 if (!cfg->hp_pins[0] &&
934 cfg->line_out_type == AUTO_PIN_HP_OUT) {
935 memcpy(cfg->hp_pins, cfg->line_out_pins,
936 sizeof(cfg->hp_pins));
937 cfg->hp_outs = cfg->line_outs;
940 spec->automute_mode = ALC_AUTOMUTE_PIN;
942 for (i = 0; i < cfg->hp_outs; i++) {
943 hda_nid_t nid = cfg->hp_pins[i];
944 if (!is_jack_detectable(codec, nid))
946 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
948 snd_hda_codec_write_cache(codec, nid, 0,
949 AC_VERB_SET_UNSOLICITED_ENABLE,
950 AC_USRSP_EN | ALC_HP_EVENT);
954 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
955 if (cfg->speaker_outs)
956 for (i = 0; i < cfg->line_outs; i++) {
957 hda_nid_t nid = cfg->line_out_pins[i];
958 if (!is_jack_detectable(codec, nid))
960 snd_printdd("realtek: Enable Line-Out "
961 "auto-muting on NID 0x%x\n", nid);
962 snd_hda_codec_write_cache(codec, nid, 0,
963 AC_VERB_SET_UNSOLICITED_ENABLE,
964 AC_USRSP_EN | ALC_FRONT_EVENT);
967 spec->automute_lo_possible = spec->detect_hp;
970 spec->automute_speaker_possible = cfg->speaker_outs &&
971 (spec->detect_hp || spec->detect_lo);
973 spec->automute_lo = spec->automute_lo_possible;
974 spec->automute_speaker = spec->automute_speaker_possible;
976 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
977 /* create a control for automute mode */
978 alc_add_automute_mode_enum(codec);
979 spec->unsol_event = alc_sku_unsol_event;
983 /* return the position of NID in the list, or -1 if not found */
984 static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
987 for (i = 0; i < nums; i++)
993 /* check whether dynamic ADC-switching is available */
994 static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
996 struct alc_spec *spec = codec->spec;
997 struct hda_input_mux *imux = &spec->private_imux[0];
1001 if (imux != spec->input_mux) /* no dynamic imux? */
1004 for (n = 0; n < spec->num_adc_nids; n++) {
1005 cap = spec->private_capsrc_nids[n];
1006 for (i = 0; i < imux->num_items; i++) {
1007 pin = spec->imux_pins[i];
1010 if (get_connection_index(codec, cap, pin) < 0)
1013 if (i >= imux->num_items)
1014 return true; /* no ADC-switch is needed */
1017 for (i = 0; i < imux->num_items; i++) {
1018 pin = spec->imux_pins[i];
1019 for (n = 0; n < spec->num_adc_nids; n++) {
1020 cap = spec->private_capsrc_nids[n];
1021 idx = get_connection_index(codec, cap, pin);
1023 imux->items[i].index = idx;
1024 spec->dyn_adc_idx[i] = n;
1030 snd_printdd("realtek: enabling ADC switching\n");
1031 spec->dyn_adc_switch = 1;
1035 /* rebuild imux for matching with the given auto-mic pins (if not yet) */
1036 static bool alc_rebuild_imux_for_auto_mic(struct hda_codec *codec)
1038 struct alc_spec *spec = codec->spec;
1039 struct hda_input_mux *imux;
1040 static char * const texts[3] = {
1041 "Mic", "Internal Mic", "Dock Mic"
1045 if (!spec->auto_mic)
1047 imux = &spec->private_imux[0];
1048 if (spec->input_mux == imux)
1050 spec->imux_pins[0] = spec->ext_mic_pin;
1051 spec->imux_pins[1] = spec->int_mic_pin;
1052 spec->imux_pins[2] = spec->dock_mic_pin;
1053 for (i = 0; i < 3; i++) {
1054 strcpy(imux->items[i].label, texts[i]);
1055 if (spec->imux_pins[i])
1056 imux->num_items = i + 1;
1058 spec->num_mux_defs = 1;
1059 spec->input_mux = imux;
1063 /* check whether all auto-mic pins are valid; setup indices if OK */
1064 static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1066 struct alc_spec *spec = codec->spec;
1067 const struct hda_input_mux *imux;
1069 if (!spec->auto_mic)
1071 if (spec->auto_mic_valid_imux)
1072 return true; /* already checked */
1074 /* fill up imux indices */
1075 if (!alc_check_dyn_adc_switch(codec)) {
1080 imux = spec->input_mux;
1081 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1082 spec->imux_pins, imux->num_items);
1083 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1084 spec->imux_pins, imux->num_items);
1085 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1086 spec->imux_pins, imux->num_items);
1087 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1089 return false; /* no corresponding imux */
1092 snd_hda_codec_write_cache(codec, spec->ext_mic_pin, 0,
1093 AC_VERB_SET_UNSOLICITED_ENABLE,
1094 AC_USRSP_EN | ALC_MIC_EVENT);
1095 if (spec->dock_mic_pin)
1096 snd_hda_codec_write_cache(codec, spec->dock_mic_pin, 0,
1097 AC_VERB_SET_UNSOLICITED_ENABLE,
1098 AC_USRSP_EN | ALC_MIC_EVENT);
1100 spec->auto_mic_valid_imux = 1;
1106 * Check the availability of auto-mic switch;
1107 * Set up if really supported
1109 static void alc_init_auto_mic(struct hda_codec *codec)
1111 struct alc_spec *spec = codec->spec;
1112 struct auto_pin_cfg *cfg = &spec->autocfg;
1113 hda_nid_t fixed, ext, dock;
1116 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1118 fixed = ext = dock = 0;
1119 for (i = 0; i < cfg->num_inputs; i++) {
1120 hda_nid_t nid = cfg->inputs[i].pin;
1121 unsigned int defcfg;
1122 defcfg = snd_hda_codec_get_pincfg(codec, nid);
1123 switch (snd_hda_get_input_pin_attr(defcfg)) {
1124 case INPUT_PIN_ATTR_INT:
1126 return; /* already occupied */
1127 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1128 return; /* invalid type */
1131 case INPUT_PIN_ATTR_UNUSED:
1132 return; /* invalid entry */
1133 case INPUT_PIN_ATTR_DOCK:
1135 return; /* already occupied */
1136 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1137 return; /* invalid type */
1142 return; /* already occupied */
1143 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1144 return; /* invalid type */
1155 if (!is_jack_detectable(codec, ext))
1156 return; /* no unsol support */
1157 if (dock && !is_jack_detectable(codec, dock))
1158 return; /* no unsol support */
1160 /* check imux indices */
1161 spec->ext_mic_pin = ext;
1162 spec->int_mic_pin = fixed;
1163 spec->dock_mic_pin = dock;
1166 if (!alc_auto_mic_check_imux(codec))
1169 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1171 spec->unsol_event = alc_sku_unsol_event;
1174 /* check the availabilities of auto-mute and auto-mic switches */
1175 static void alc_auto_check_switches(struct hda_codec *codec)
1177 alc_init_automute(codec);
1178 alc_init_auto_mic(codec);
1182 * Realtek SSID verification
1185 /* Could be any non-zero and even value. When used as fixup, tells
1186 * the driver to ignore any present sku defines.
1188 #define ALC_FIXUP_SKU_IGNORE (2)
1190 static int alc_auto_parse_customize_define(struct hda_codec *codec)
1192 unsigned int ass, tmp, i;
1194 struct alc_spec *spec = codec->spec;
1196 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1198 if (spec->cdefine.fixup) {
1199 ass = spec->cdefine.sku_cfg;
1200 if (ass == ALC_FIXUP_SKU_IGNORE)
1205 ass = codec->subsystem_id & 0xffff;
1206 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
1210 if (codec->vendor_id == 0x10ec0260)
1212 ass = snd_hda_codec_get_pincfg(codec, nid);
1215 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1216 codec->chip_name, ass);
1222 for (i = 1; i < 16; i++) {
1226 if (((ass >> 16) & 0xf) != tmp)
1229 spec->cdefine.port_connectivity = ass >> 30;
1230 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1231 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1232 spec->cdefine.customization = ass >> 8;
1234 spec->cdefine.sku_cfg = ass;
1235 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1236 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1237 spec->cdefine.swap = (ass & 0x2) >> 1;
1238 spec->cdefine.override = ass & 0x1;
1240 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1241 nid, spec->cdefine.sku_cfg);
1242 snd_printd("SKU: port_connectivity=0x%x\n",
1243 spec->cdefine.port_connectivity);
1244 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1245 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1246 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1247 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1248 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1249 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1250 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1255 /* return true if the given NID is found in the list */
1256 static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1258 return find_idx_in_nid_list(nid, list, nums) >= 0;
1261 /* check subsystem ID and set up device-specific initialization;
1262 * return 1 if initialized, 0 if invalid SSID
1264 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1265 * 31 ~ 16 : Manufacture ID
1267 * 7 ~ 0 : Assembly ID
1268 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1270 static int alc_subsystem_id(struct hda_codec *codec,
1271 hda_nid_t porta, hda_nid_t porte,
1272 hda_nid_t portd, hda_nid_t porti)
1274 unsigned int ass, tmp, i;
1276 struct alc_spec *spec = codec->spec;
1278 if (spec->cdefine.fixup) {
1279 ass = spec->cdefine.sku_cfg;
1280 if (ass == ALC_FIXUP_SKU_IGNORE)
1285 ass = codec->subsystem_id & 0xffff;
1286 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1289 /* invalid SSID, check the special NID pin defcfg instead */
1291 * 31~30 : port connectivity
1294 * 19~16 : Check sum (15:1)
1299 if (codec->vendor_id == 0x10ec0260)
1301 ass = snd_hda_codec_get_pincfg(codec, nid);
1302 snd_printd("realtek: No valid SSID, "
1303 "checking pincfg 0x%08x for NID 0x%x\n",
1307 if ((ass >> 30) != 1) /* no physical connection */
1312 for (i = 1; i < 16; i++) {
1316 if (((ass >> 16) & 0xf) != tmp)
1319 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1320 ass & 0xffff, codec->vendor_id);
1324 * 2 : 0 --> Desktop, 1 --> Laptop
1325 * 3~5 : External Amplifier control
1328 tmp = (ass & 0x38) >> 3; /* external Amp control */
1331 spec->init_amp = ALC_INIT_GPIO1;
1334 spec->init_amp = ALC_INIT_GPIO2;
1337 spec->init_amp = ALC_INIT_GPIO3;
1341 spec->init_amp = ALC_INIT_DEFAULT;
1345 /* is laptop or Desktop and enable the function "Mute internal speaker
1346 * when the external headphone out jack is plugged"
1348 if (!(ass & 0x8000))
1351 * 10~8 : Jack location
1352 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1354 * 15 : 1 --> enable the function "Mute internal speaker
1355 * when the external headphone out jack is plugged"
1357 if (!spec->autocfg.hp_pins[0] &&
1358 !(spec->autocfg.line_out_pins[0] &&
1359 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
1361 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1372 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1373 spec->autocfg.line_outs))
1375 spec->autocfg.hp_pins[0] = nid;
1380 /* Check the validity of ALC subsystem-id
1381 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1382 static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
1384 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
1385 struct alc_spec *spec = codec->spec;
1386 snd_printd("realtek: "
1387 "Enable default setup for auto mode as fallback\n");
1388 spec->init_amp = ALC_INIT_DEFAULT;
1393 * Fix-up pin default configurations and add default verbs
1401 struct alc_model_fixup {
1412 const struct alc_pincfg *pins;
1413 const struct hda_verb *verbs;
1414 void (*func)(struct hda_codec *codec,
1415 const struct alc_fixup *fix,
1429 ALC_FIXUP_ACT_PRE_PROBE,
1430 ALC_FIXUP_ACT_PROBE,
1434 static void alc_apply_fixup(struct hda_codec *codec, int action)
1436 struct alc_spec *spec = codec->spec;
1437 int id = spec->fixup_id;
1438 #ifdef CONFIG_SND_DEBUG_VERBOSE
1439 const char *modelname = spec->fixup_name;
1443 if (!spec->fixup_list)
1447 const struct alc_fixup *fix = spec->fixup_list + id;
1448 const struct alc_pincfg *cfg;
1450 switch (fix->type) {
1452 if (action != ALC_FIXUP_ACT_PRE_PROBE || !fix->v.sku)
1454 snd_printdd(KERN_INFO "hda_codec: %s: "
1455 "Apply sku override for %s\n",
1456 codec->chip_name, modelname);
1457 spec->cdefine.sku_cfg = fix->v.sku;
1458 spec->cdefine.fixup = 1;
1460 case ALC_FIXUP_PINS:
1462 if (action != ALC_FIXUP_ACT_PRE_PROBE || !cfg)
1464 snd_printdd(KERN_INFO "hda_codec: %s: "
1465 "Apply pincfg for %s\n",
1466 codec->chip_name, modelname);
1467 for (; cfg->nid; cfg++)
1468 snd_hda_codec_set_pincfg(codec, cfg->nid,
1471 case ALC_FIXUP_VERBS:
1472 if (action != ALC_FIXUP_ACT_PROBE || !fix->v.verbs)
1474 snd_printdd(KERN_INFO "hda_codec: %s: "
1475 "Apply fix-verbs for %s\n",
1476 codec->chip_name, modelname);
1477 add_verb(codec->spec, fix->v.verbs);
1479 case ALC_FIXUP_FUNC:
1482 snd_printdd(KERN_INFO "hda_codec: %s: "
1483 "Apply fix-func for %s\n",
1484 codec->chip_name, modelname);
1485 fix->v.func(codec, fix, action);
1488 snd_printk(KERN_ERR "hda_codec: %s: "
1489 "Invalid fixup type %d\n",
1490 codec->chip_name, fix->type);
1501 static void alc_pick_fixup(struct hda_codec *codec,
1502 const struct alc_model_fixup *models,
1503 const struct snd_pci_quirk *quirk,
1504 const struct alc_fixup *fixlist)
1506 struct alc_spec *spec = codec->spec;
1508 const char *name = NULL;
1510 if (codec->modelname && models) {
1511 while (models->name) {
1512 if (!strcmp(codec->modelname, models->name)) {
1514 name = models->name;
1521 quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1524 #ifdef CONFIG_SND_DEBUG_VERBOSE
1530 spec->fixup_id = id;
1532 spec->fixup_list = fixlist;
1533 spec->fixup_name = name;
1538 * COEF access helper functions
1540 static int alc_read_coef_idx(struct hda_codec *codec,
1541 unsigned int coef_idx)
1544 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1546 val = snd_hda_codec_read(codec, 0x20, 0,
1547 AC_VERB_GET_PROC_COEF, 0);
1551 static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1552 unsigned int coef_val)
1554 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1556 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1560 /* a special bypass for COEF 0; read the cached value at the second time */
1561 static unsigned int alc_get_coef0(struct hda_codec *codec)
1563 struct alc_spec *spec = codec->spec;
1565 spec->coef0 = alc_read_coef_idx(codec, 0);
1570 * Digital I/O handling
1573 /* set right pin controls for digital I/O */
1574 static void alc_auto_init_digital(struct hda_codec *codec)
1576 struct alc_spec *spec = codec->spec;
1580 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1581 pin = spec->autocfg.dig_out_pins[i];
1584 snd_hda_codec_write(codec, pin, 0,
1585 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
1587 dac = spec->multiout.dig_out_nid;
1589 dac = spec->slave_dig_outs[i - 1];
1590 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
1592 snd_hda_codec_write(codec, dac, 0,
1593 AC_VERB_SET_AMP_GAIN_MUTE,
1596 pin = spec->autocfg.dig_in_pin;
1598 snd_hda_codec_write(codec, pin, 0,
1599 AC_VERB_SET_PIN_WIDGET_CONTROL,
1603 /* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1604 static void alc_auto_parse_digital(struct hda_codec *codec)
1606 struct alc_spec *spec = codec->spec;
1610 /* support multiple SPDIFs; the secondary is set up as a slave */
1611 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1613 err = snd_hda_get_connections(codec,
1614 spec->autocfg.dig_out_pins[i],
1615 conn, ARRAY_SIZE(conn));
1618 dig_nid = conn[0]; /* assume the first element is audio-out */
1620 spec->multiout.dig_out_nid = dig_nid;
1621 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1623 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
1624 if (i >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
1626 spec->slave_dig_outs[i - 1] = dig_nid;
1630 if (spec->autocfg.dig_in_pin) {
1631 dig_nid = codec->start_nid;
1632 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1633 unsigned int wcaps = get_wcaps(codec, dig_nid);
1634 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1636 if (!(wcaps & AC_WCAP_DIGITAL))
1638 if (!(wcaps & AC_WCAP_CONN_LIST))
1640 err = get_connection_index(codec, dig_nid,
1641 spec->autocfg.dig_in_pin);
1643 spec->dig_in_nid = dig_nid;
1651 * capture mixer elements
1653 static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1654 struct snd_ctl_elem_info *uinfo)
1656 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1657 struct alc_spec *spec = codec->spec;
1661 mutex_lock(&codec->control_mutex);
1662 if (spec->vol_in_capsrc)
1663 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1665 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1666 kcontrol->private_value = val;
1667 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
1668 mutex_unlock(&codec->control_mutex);
1672 static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1673 unsigned int size, unsigned int __user *tlv)
1675 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1676 struct alc_spec *spec = codec->spec;
1680 mutex_lock(&codec->control_mutex);
1681 if (spec->vol_in_capsrc)
1682 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1684 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1685 kcontrol->private_value = val;
1686 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
1687 mutex_unlock(&codec->control_mutex);
1691 typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1692 struct snd_ctl_elem_value *ucontrol);
1694 static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1695 struct snd_ctl_elem_value *ucontrol,
1696 getput_call_t func, bool check_adc_switch)
1698 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1699 struct alc_spec *spec = codec->spec;
1702 mutex_lock(&codec->control_mutex);
1703 if (check_adc_switch && spec->dyn_adc_switch) {
1704 for (i = 0; i < spec->num_adc_nids; i++) {
1705 kcontrol->private_value =
1706 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1708 err = func(kcontrol, ucontrol);
1713 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1714 if (spec->vol_in_capsrc)
1715 kcontrol->private_value =
1716 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1719 kcontrol->private_value =
1720 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1722 err = func(kcontrol, ucontrol);
1725 mutex_unlock(&codec->control_mutex);
1729 static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1730 struct snd_ctl_elem_value *ucontrol)
1732 return alc_cap_getput_caller(kcontrol, ucontrol,
1733 snd_hda_mixer_amp_volume_get, false);
1736 static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1737 struct snd_ctl_elem_value *ucontrol)
1739 return alc_cap_getput_caller(kcontrol, ucontrol,
1740 snd_hda_mixer_amp_volume_put, true);
1743 /* capture mixer elements */
1744 #define alc_cap_sw_info snd_ctl_boolean_stereo_info
1746 static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1747 struct snd_ctl_elem_value *ucontrol)
1749 return alc_cap_getput_caller(kcontrol, ucontrol,
1750 snd_hda_mixer_amp_switch_get, false);
1753 static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1754 struct snd_ctl_elem_value *ucontrol)
1756 return alc_cap_getput_caller(kcontrol, ucontrol,
1757 snd_hda_mixer_amp_switch_put, true);
1760 #define _DEFINE_CAPMIX(num) \
1762 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1763 .name = "Capture Switch", \
1764 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1766 .info = alc_cap_sw_info, \
1767 .get = alc_cap_sw_get, \
1768 .put = alc_cap_sw_put, \
1771 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1772 .name = "Capture Volume", \
1773 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1774 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1775 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1777 .info = alc_cap_vol_info, \
1778 .get = alc_cap_vol_get, \
1779 .put = alc_cap_vol_put, \
1780 .tlv = { .c = alc_cap_vol_tlv }, \
1783 #define _DEFINE_CAPSRC(num) \
1785 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1786 /* .name = "Capture Source", */ \
1787 .name = "Input Source", \
1789 .info = alc_mux_enum_info, \
1790 .get = alc_mux_enum_get, \
1791 .put = alc_mux_enum_put, \
1794 #define DEFINE_CAPMIX(num) \
1795 static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
1796 _DEFINE_CAPMIX(num), \
1797 _DEFINE_CAPSRC(num), \
1801 #define DEFINE_CAPMIX_NOSRC(num) \
1802 static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
1803 _DEFINE_CAPMIX(num), \
1807 /* up to three ADCs */
1811 DEFINE_CAPMIX_NOSRC(1);
1812 DEFINE_CAPMIX_NOSRC(2);
1813 DEFINE_CAPMIX_NOSRC(3);
1816 * virtual master controls
1820 * slave controls for virtual master
1822 static const char * const alc_slave_vols[] = {
1823 "Front Playback Volume",
1824 "Surround Playback Volume",
1825 "Center Playback Volume",
1826 "LFE Playback Volume",
1827 "Side Playback Volume",
1828 "Headphone Playback Volume",
1829 "Speaker Playback Volume",
1830 "Mono Playback Volume",
1831 "Line-Out Playback Volume",
1832 "PCM Playback Volume",
1836 static const char * const alc_slave_sws[] = {
1837 "Front Playback Switch",
1838 "Surround Playback Switch",
1839 "Center Playback Switch",
1840 "LFE Playback Switch",
1841 "Side Playback Switch",
1842 "Headphone Playback Switch",
1843 "Speaker Playback Switch",
1844 "Mono Playback Switch",
1845 "IEC958 Playback Switch",
1846 "Line-Out Playback Switch",
1847 "PCM Playback Switch",
1852 * build control elements
1855 #define NID_MAPPING (-1)
1857 #define SUBDEV_SPEAKER_ (0 << 6)
1858 #define SUBDEV_HP_ (1 << 6)
1859 #define SUBDEV_LINE_ (2 << 6)
1860 #define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1861 #define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1862 #define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1864 static void alc_free_kctls(struct hda_codec *codec);
1866 #ifdef CONFIG_SND_HDA_INPUT_BEEP
1867 /* additional beep mixers; the actual parameters are overwritten at build */
1868 static const struct snd_kcontrol_new alc_beep_mixer[] = {
1869 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
1870 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
1875 static int alc_build_controls(struct hda_codec *codec)
1877 struct alc_spec *spec = codec->spec;
1878 struct snd_kcontrol *kctl = NULL;
1879 const struct snd_kcontrol_new *knew;
1884 for (i = 0; i < spec->num_mixers; i++) {
1885 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1889 if (spec->cap_mixer) {
1890 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1894 if (spec->multiout.dig_out_nid) {
1895 err = snd_hda_create_spdif_out_ctls(codec,
1896 spec->multiout.dig_out_nid,
1897 spec->multiout.dig_out_nid);
1900 if (!spec->no_analog) {
1901 err = snd_hda_create_spdif_share_sw(codec,
1905 spec->multiout.share_spdif = 1;
1908 if (spec->dig_in_nid) {
1909 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1914 #ifdef CONFIG_SND_HDA_INPUT_BEEP
1915 /* create beep controls if needed */
1916 if (spec->beep_amp) {
1917 const struct snd_kcontrol_new *knew;
1918 for (knew = alc_beep_mixer; knew->name; knew++) {
1919 struct snd_kcontrol *kctl;
1920 kctl = snd_ctl_new1(knew, codec);
1923 kctl->private_value = spec->beep_amp;
1924 err = snd_hda_ctl_add(codec, 0, kctl);
1931 /* if we have no master control, let's create it */
1932 if (!spec->no_analog &&
1933 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1934 unsigned int vmaster_tlv[4];
1935 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
1936 HDA_OUTPUT, vmaster_tlv);
1937 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1938 vmaster_tlv, alc_slave_vols);
1942 if (!spec->no_analog &&
1943 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1944 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1945 NULL, alc_slave_sws);
1950 /* assign Capture Source enums to NID */
1951 if (spec->capsrc_nids || spec->adc_nids) {
1952 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
1954 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1955 for (i = 0; kctl && i < kctl->count; i++) {
1956 const hda_nid_t *nids = spec->capsrc_nids;
1958 nids = spec->adc_nids;
1959 err = snd_hda_add_nid(codec, kctl, i, nids[i]);
1964 if (spec->cap_mixer && spec->adc_nids) {
1965 const char *kname = kctl ? kctl->id.name : NULL;
1966 for (knew = spec->cap_mixer; knew->name; knew++) {
1967 if (kname && strcmp(knew->name, kname) == 0)
1969 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1970 for (i = 0; kctl && i < kctl->count; i++) {
1971 err = snd_hda_add_nid(codec, kctl, i,
1979 /* other nid->control mapping */
1980 for (i = 0; i < spec->num_mixers; i++) {
1981 for (knew = spec->mixers[i]; knew->name; knew++) {
1982 if (knew->iface != NID_MAPPING)
1984 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1987 u = knew->subdevice;
1988 for (j = 0; j < 4; j++, u >>= 8) {
1993 case SUBDEV_SPEAKER_:
1994 nid = spec->autocfg.speaker_pins[nid];
1997 nid = spec->autocfg.line_out_pins[nid];
2000 nid = spec->autocfg.hp_pins[nid];
2005 err = snd_hda_add_nid(codec, kctl, 0, nid);
2009 u = knew->private_value;
2010 for (j = 0; j < 4; j++, u >>= 8) {
2014 err = snd_hda_add_nid(codec, kctl, 0, nid);
2021 alc_free_kctls(codec); /* no longer needed */
2031 static void alc_init_special_input_src(struct hda_codec *codec);
2033 static int alc_init(struct hda_codec *codec)
2035 struct alc_spec *spec = codec->spec;
2039 alc_auto_init_amp(codec, spec->init_amp);
2041 for (i = 0; i < spec->num_init_verbs; i++)
2042 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2043 alc_init_special_input_src(codec);
2045 if (spec->init_hook)
2046 spec->init_hook(codec);
2048 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2050 hda_call_check_power_status(codec, 0x01);
2054 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2056 struct alc_spec *spec = codec->spec;
2058 if (spec->unsol_event)
2059 spec->unsol_event(codec, res);
2062 #ifdef CONFIG_SND_HDA_POWER_SAVE
2063 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2065 struct alc_spec *spec = codec->spec;
2066 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2071 * Analog playback callbacks
2073 static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
2074 struct hda_codec *codec,
2075 struct snd_pcm_substream *substream)
2077 struct alc_spec *spec = codec->spec;
2078 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2082 static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2083 struct hda_codec *codec,
2084 unsigned int stream_tag,
2085 unsigned int format,
2086 struct snd_pcm_substream *substream)
2088 struct alc_spec *spec = codec->spec;
2089 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2090 stream_tag, format, substream);
2093 static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2094 struct hda_codec *codec,
2095 struct snd_pcm_substream *substream)
2097 struct alc_spec *spec = codec->spec;
2098 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2104 static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2105 struct hda_codec *codec,
2106 struct snd_pcm_substream *substream)
2108 struct alc_spec *spec = codec->spec;
2109 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2112 static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2113 struct hda_codec *codec,
2114 unsigned int stream_tag,
2115 unsigned int format,
2116 struct snd_pcm_substream *substream)
2118 struct alc_spec *spec = codec->spec;
2119 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2120 stream_tag, format, substream);
2123 static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2124 struct hda_codec *codec,
2125 struct snd_pcm_substream *substream)
2127 struct alc_spec *spec = codec->spec;
2128 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2131 static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2132 struct hda_codec *codec,
2133 struct snd_pcm_substream *substream)
2135 struct alc_spec *spec = codec->spec;
2136 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2142 static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2143 struct hda_codec *codec,
2144 unsigned int stream_tag,
2145 unsigned int format,
2146 struct snd_pcm_substream *substream)
2148 struct alc_spec *spec = codec->spec;
2150 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
2151 stream_tag, 0, format);
2155 static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2156 struct hda_codec *codec,
2157 struct snd_pcm_substream *substream)
2159 struct alc_spec *spec = codec->spec;
2161 snd_hda_codec_cleanup_stream(codec,
2162 spec->adc_nids[substream->number + 1]);
2166 /* analog capture with dynamic dual-adc changes */
2167 static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2168 struct hda_codec *codec,
2169 unsigned int stream_tag,
2170 unsigned int format,
2171 struct snd_pcm_substream *substream)
2173 struct alc_spec *spec = codec->spec;
2174 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
2175 spec->cur_adc_stream_tag = stream_tag;
2176 spec->cur_adc_format = format;
2177 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2181 static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2182 struct hda_codec *codec,
2183 struct snd_pcm_substream *substream)
2185 struct alc_spec *spec = codec->spec;
2186 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2191 static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
2195 .nid = 0, /* fill later */
2197 .prepare = dyn_adc_capture_pcm_prepare,
2198 .cleanup = dyn_adc_capture_pcm_cleanup
2204 static const struct hda_pcm_stream alc_pcm_analog_playback = {
2208 /* NID is set in alc_build_pcms */
2210 .open = alc_playback_pcm_open,
2211 .prepare = alc_playback_pcm_prepare,
2212 .cleanup = alc_playback_pcm_cleanup
2216 static const struct hda_pcm_stream alc_pcm_analog_capture = {
2220 /* NID is set in alc_build_pcms */
2223 static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
2227 /* NID is set in alc_build_pcms */
2230 static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
2231 .substreams = 2, /* can be overridden */
2234 /* NID is set in alc_build_pcms */
2236 .prepare = alc_alt_capture_pcm_prepare,
2237 .cleanup = alc_alt_capture_pcm_cleanup
2241 static const struct hda_pcm_stream alc_pcm_digital_playback = {
2245 /* NID is set in alc_build_pcms */
2247 .open = alc_dig_playback_pcm_open,
2248 .close = alc_dig_playback_pcm_close,
2249 .prepare = alc_dig_playback_pcm_prepare,
2250 .cleanup = alc_dig_playback_pcm_cleanup
2254 static const struct hda_pcm_stream alc_pcm_digital_capture = {
2258 /* NID is set in alc_build_pcms */
2261 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
2262 static const struct hda_pcm_stream alc_pcm_null_stream = {
2268 static int alc_build_pcms(struct hda_codec *codec)
2270 struct alc_spec *spec = codec->spec;
2271 struct hda_pcm *info = spec->pcm_rec;
2272 const struct hda_pcm_stream *p;
2275 codec->num_pcms = 1;
2276 codec->pcm_info = info;
2278 if (spec->no_analog)
2281 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2282 "%s Analog", codec->chip_name);
2283 info->name = spec->stream_name_analog;
2285 if (spec->multiout.dac_nids > 0) {
2286 p = spec->stream_analog_playback;
2288 p = &alc_pcm_analog_playback;
2289 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2290 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2292 if (spec->adc_nids) {
2293 p = spec->stream_analog_capture;
2295 if (spec->dyn_adc_switch)
2296 p = &dyn_adc_pcm_analog_capture;
2298 p = &alc_pcm_analog_capture;
2300 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2301 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2304 if (spec->channel_mode) {
2305 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2306 for (i = 0; i < spec->num_channel_mode; i++) {
2307 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2308 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2314 /* SPDIF for stream index #1 */
2315 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2316 snprintf(spec->stream_name_digital,
2317 sizeof(spec->stream_name_digital),
2318 "%s Digital", codec->chip_name);
2319 codec->num_pcms = 2;
2320 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
2321 info = spec->pcm_rec + 1;
2322 info->name = spec->stream_name_digital;
2323 if (spec->dig_out_type)
2324 info->pcm_type = spec->dig_out_type;
2326 info->pcm_type = HDA_PCM_TYPE_SPDIF;
2327 if (spec->multiout.dig_out_nid) {
2328 p = spec->stream_digital_playback;
2330 p = &alc_pcm_digital_playback;
2331 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2332 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2334 if (spec->dig_in_nid) {
2335 p = spec->stream_digital_capture;
2337 p = &alc_pcm_digital_capture;
2338 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2339 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2341 /* FIXME: do we need this for all Realtek codec models? */
2342 codec->spdif_status_reset = 1;
2345 if (spec->no_analog)
2348 /* If the use of more than one ADC is requested for the current
2349 * model, configure a second analog capture-only PCM.
2351 /* Additional Analaog capture for index #2 */
2352 if (spec->alt_dac_nid || spec->num_adc_nids > 1) {
2353 codec->num_pcms = 3;
2354 info = spec->pcm_rec + 2;
2355 info->name = spec->stream_name_analog;
2356 if (spec->alt_dac_nid) {
2357 p = spec->stream_analog_alt_playback;
2359 p = &alc_pcm_analog_alt_playback;
2360 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2361 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2364 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2365 alc_pcm_null_stream;
2366 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2368 if (spec->num_adc_nids > 1) {
2369 p = spec->stream_analog_alt_capture;
2371 p = &alc_pcm_analog_alt_capture;
2372 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2373 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2375 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2376 spec->num_adc_nids - 1;
2378 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2379 alc_pcm_null_stream;
2380 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
2387 static inline void alc_shutup(struct hda_codec *codec)
2389 struct alc_spec *spec = codec->spec;
2391 if (spec && spec->shutup)
2392 spec->shutup(codec);
2393 snd_hda_shutup_pins(codec);
2396 static void alc_free_kctls(struct hda_codec *codec)
2398 struct alc_spec *spec = codec->spec;
2400 if (spec->kctls.list) {
2401 struct snd_kcontrol_new *kctl = spec->kctls.list;
2403 for (i = 0; i < spec->kctls.used; i++)
2404 kfree(kctl[i].name);
2406 snd_array_free(&spec->kctls);
2409 static void alc_free_bind_ctls(struct hda_codec *codec)
2411 struct alc_spec *spec = codec->spec;
2412 if (spec->bind_ctls.list) {
2413 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2415 for (i = 0; i < spec->bind_ctls.used; i++)
2418 snd_array_free(&spec->bind_ctls);
2421 static void alc_free(struct hda_codec *codec)
2423 struct alc_spec *spec = codec->spec;
2429 snd_hda_input_jack_free(codec);
2430 alc_free_kctls(codec);
2431 alc_free_bind_ctls(codec);
2433 snd_hda_detach_beep_device(codec);
2436 #ifdef CONFIG_SND_HDA_POWER_SAVE
2437 static void alc_power_eapd(struct hda_codec *codec)
2439 alc_auto_setup_eapd(codec, false);
2442 static int alc_suspend(struct hda_codec *codec, pm_message_t state)
2444 struct alc_spec *spec = codec->spec;
2446 if (spec && spec->power_hook)
2447 spec->power_hook(codec);
2453 static int alc_resume(struct hda_codec *codec)
2455 msleep(150); /* to avoid pop noise */
2456 codec->patch_ops.init(codec);
2457 snd_hda_codec_resume_amp(codec);
2458 snd_hda_codec_resume_cache(codec);
2459 hda_call_check_power_status(codec, 0x01);
2466 static const struct hda_codec_ops alc_patch_ops = {
2467 .build_controls = alc_build_controls,
2468 .build_pcms = alc_build_pcms,
2471 .unsol_event = alc_unsol_event,
2473 .resume = alc_resume,
2475 #ifdef CONFIG_SND_HDA_POWER_SAVE
2476 .suspend = alc_suspend,
2477 .check_power_status = alc_check_power_status,
2479 .reboot_notify = alc_shutup,
2482 /* replace the codec chip_name with the given string */
2483 static int alc_codec_rename(struct hda_codec *codec, const char *name)
2485 kfree(codec->chip_name);
2486 codec->chip_name = kstrdup(name, GFP_KERNEL);
2487 if (!codec->chip_name) {
2495 * Rename codecs appropriately from COEF value
2497 struct alc_codec_rename_table {
2498 unsigned int vendor_id;
2499 unsigned short coef_mask;
2500 unsigned short coef_bits;
2504 static struct alc_codec_rename_table rename_tbl[] = {
2505 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2506 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2507 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2508 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2509 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2510 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2511 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
2512 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2513 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2514 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2515 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2516 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2517 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2518 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2519 { } /* terminator */
2522 static int alc_codec_rename_from_preset(struct hda_codec *codec)
2524 const struct alc_codec_rename_table *p;
2526 for (p = rename_tbl; p->vendor_id; p++) {
2527 if (p->vendor_id != codec->vendor_id)
2529 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
2530 return alc_codec_rename(codec, p->name);
2536 * Automatic parse of I/O pins from the BIOS configuration
2541 ALC_CTL_WIDGET_MUTE,
2546 static const struct snd_kcontrol_new alc_control_templates[] = {
2547 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2548 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2549 HDA_BIND_MUTE(NULL, 0, 0, 0),
2550 HDA_BIND_VOL(NULL, 0),
2551 HDA_BIND_SW(NULL, 0),
2554 /* add dynamic controls */
2555 static int add_control(struct alc_spec *spec, int type, const char *name,
2556 int cidx, unsigned long val)
2558 struct snd_kcontrol_new *knew;
2560 knew = alc_kcontrol_new(spec);
2563 *knew = alc_control_templates[type];
2564 knew->name = kstrdup(name, GFP_KERNEL);
2568 if (get_amp_nid_(val))
2569 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
2570 knew->private_value = val;
2574 static int add_control_with_pfx(struct alc_spec *spec, int type,
2575 const char *pfx, const char *dir,
2576 const char *sfx, int cidx, unsigned long val)
2579 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
2580 return add_control(spec, type, name, cidx, val);
2583 #define add_pb_vol_ctrl(spec, type, pfx, val) \
2584 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2585 #define add_pb_sw_ctrl(spec, type, pfx, val) \
2586 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2587 #define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2588 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2589 #define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2590 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
2592 static const char * const channel_name[4] = {
2593 "Front", "Surround", "CLFE", "Side"
2596 static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2597 bool can_be_master, int *index)
2599 struct auto_pin_cfg *cfg = &spec->autocfg;
2602 if (cfg->line_outs == 1 && !spec->multi_ios &&
2603 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
2606 switch (cfg->line_out_type) {
2607 case AUTO_PIN_SPEAKER_OUT:
2608 if (cfg->line_outs == 1)
2611 case AUTO_PIN_HP_OUT:
2612 /* for multi-io case, only the primary out */
2613 if (ch && spec->multi_ios)
2618 if (cfg->line_outs == 1 && !spec->multi_ios)
2622 if (snd_BUG_ON(ch >= ARRAY_SIZE(channel_name)))
2625 return channel_name[ch];
2628 /* create input playback/capture controls for the given pin */
2629 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
2630 const char *ctlname, int ctlidx,
2631 int idx, hda_nid_t mix_nid)
2635 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
2636 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2639 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
2640 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2646 static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
2648 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2649 return (pincap & AC_PINCAP_IN) != 0;
2652 /* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
2653 static int alc_auto_fill_adc_caps(struct hda_codec *codec)
2655 struct alc_spec *spec = codec->spec;
2657 hda_nid_t *adc_nids = spec->private_adc_nids;
2658 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2659 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
2660 bool indep_capsrc = false;
2663 nid = codec->start_nid;
2664 for (i = 0; i < codec->num_nodes; i++, nid++) {
2666 const hda_nid_t *list;
2667 unsigned int caps = get_wcaps(codec, nid);
2668 int type = get_wcaps_type(caps);
2670 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2672 adc_nids[nums] = nid;
2673 cap_nids[nums] = nid;
2677 type = get_wcaps_type(get_wcaps(codec, src));
2678 if (type == AC_WID_PIN)
2680 if (type == AC_WID_AUD_SEL) {
2681 cap_nids[nums] = src;
2682 indep_capsrc = true;
2685 n = snd_hda_get_conn_list(codec, src, &list);
2687 cap_nids[nums] = src;
2688 indep_capsrc = true;
2694 if (++nums >= max_nums)
2697 spec->adc_nids = spec->private_adc_nids;
2698 spec->capsrc_nids = spec->private_capsrc_nids;
2699 spec->num_adc_nids = nums;
2703 /* create playback/capture controls for input pins */
2704 static int alc_auto_create_input_ctls(struct hda_codec *codec)
2706 struct alc_spec *spec = codec->spec;
2707 const struct auto_pin_cfg *cfg = &spec->autocfg;
2708 hda_nid_t mixer = spec->mixer_nid;
2709 struct hda_input_mux *imux = &spec->private_imux[0];
2711 int i, c, err, idx, type_idx = 0;
2712 const char *prev_label = NULL;
2714 num_adcs = alc_auto_fill_adc_caps(codec);
2718 for (i = 0; i < cfg->num_inputs; i++) {
2722 pin = cfg->inputs[i].pin;
2723 if (!alc_is_input_pin(codec, pin))
2726 label = hda_get_autocfg_input_label(codec, cfg, i);
2727 if (prev_label && !strcmp(label, prev_label))
2734 idx = get_connection_index(codec, mixer, pin);
2736 err = new_analog_input(spec, pin,
2744 for (c = 0; c < num_adcs; c++) {
2745 hda_nid_t cap = spec->capsrc_nids ?
2746 spec->capsrc_nids[c] : spec->adc_nids[c];
2747 idx = get_connection_index(codec, cap, pin);
2749 spec->imux_pins[imux->num_items] = pin;
2750 snd_hda_add_imux_item(imux, label, idx, NULL);
2756 spec->num_mux_defs = 1;
2757 spec->input_mux = imux;
2762 static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
2763 unsigned int pin_type)
2765 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2768 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2769 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2773 static int get_pin_type(int line_out_type)
2775 if (line_out_type == AUTO_PIN_HP_OUT)
2781 static void alc_auto_init_analog_input(struct hda_codec *codec)
2783 struct alc_spec *spec = codec->spec;
2784 struct auto_pin_cfg *cfg = &spec->autocfg;
2787 for (i = 0; i < cfg->num_inputs; i++) {
2788 hda_nid_t nid = cfg->inputs[i].pin;
2789 if (alc_is_input_pin(codec, nid)) {
2790 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
2791 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
2792 snd_hda_codec_write(codec, nid, 0,
2793 AC_VERB_SET_AMP_GAIN_MUTE,
2798 /* mute all loopback inputs */
2799 if (spec->mixer_nid) {
2800 int nums = snd_hda_get_conn_list(codec, spec->mixer_nid, NULL);
2801 for (i = 0; i < nums; i++)
2802 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2803 AC_VERB_SET_AMP_GAIN_MUTE,
2808 /* convert from MIX nid to DAC */
2809 static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid)
2814 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT)
2816 num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list));
2817 for (i = 0; i < num; i++) {
2818 if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT)
2824 /* go down to the selector widget before the mixer */
2825 static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin)
2828 int num = snd_hda_get_connections(codec, pin, srcs,
2831 get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL)
2836 /* get MIX nid connected to the given pin targeted to DAC */
2837 static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
2843 pin = alc_go_down_to_selector(codec, pin);
2844 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2845 for (i = 0; i < num; i++) {
2846 if (alc_auto_mix_to_dac(codec, mix[i]) == dac)
2852 /* select the connection from pin to DAC if needed */
2853 static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin,
2859 pin = alc_go_down_to_selector(codec, pin);
2860 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2863 for (i = 0; i < num; i++) {
2864 if (alc_auto_mix_to_dac(codec, mix[i]) == dac) {
2865 snd_hda_codec_update_cache(codec, pin, 0,
2866 AC_VERB_SET_CONNECT_SEL, i);
2873 /* look for an empty DAC slot */
2874 static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
2876 struct alc_spec *spec = codec->spec;
2880 pin = alc_go_down_to_selector(codec, pin);
2881 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
2882 for (i = 0; i < num; i++) {
2883 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
2886 if (found_in_nid_list(nid, spec->multiout.dac_nids,
2887 spec->multiout.num_dacs))
2889 if (found_in_nid_list(nid, spec->multiout.hp_out_nid,
2890 ARRAY_SIZE(spec->multiout.hp_out_nid)))
2892 if (found_in_nid_list(nid, spec->multiout.extra_out_nid,
2893 ARRAY_SIZE(spec->multiout.extra_out_nid)))
2900 static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
2902 hda_nid_t sel = alc_go_down_to_selector(codec, pin);
2903 if (snd_hda_get_conn_list(codec, sel, NULL) == 1)
2904 return alc_auto_look_for_dac(codec, pin);
2908 static int alc_auto_fill_extra_dacs(struct hda_codec *codec, int num_outs,
2909 const hda_nid_t *pins, hda_nid_t *dacs)
2913 if (num_outs && !dacs[0]) {
2914 dacs[0] = alc_auto_look_for_dac(codec, pins[0]);
2919 for (i = 1; i < num_outs; i++)
2920 dacs[i] = get_dac_if_single(codec, pins[i]);
2921 for (i = 1; i < num_outs; i++) {
2923 dacs[i] = alc_auto_look_for_dac(codec, pins[i]);
2928 static int alc_auto_fill_multi_ios(struct hda_codec *codec,
2929 unsigned int location);
2931 /* fill in the dac_nids table from the parsed pin configuration */
2932 static int alc_auto_fill_dac_nids(struct hda_codec *codec)
2934 struct alc_spec *spec = codec->spec;
2935 const struct auto_pin_cfg *cfg = &spec->autocfg;
2936 bool redone = false;
2940 /* set num_dacs once to full for alc_auto_look_for_dac() */
2941 spec->multiout.num_dacs = cfg->line_outs;
2942 spec->multiout.hp_out_nid[0] = 0;
2943 spec->multiout.extra_out_nid[0] = 0;
2944 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
2945 spec->multiout.dac_nids = spec->private_dac_nids;
2947 /* fill hard-wired DACs first */
2949 for (i = 0; i < cfg->line_outs; i++)
2950 spec->private_dac_nids[i] =
2951 get_dac_if_single(codec, cfg->line_out_pins[i]);
2953 spec->multiout.hp_out_nid[0] =
2954 get_dac_if_single(codec, cfg->hp_pins[0]);
2955 if (cfg->speaker_outs)
2956 spec->multiout.extra_out_nid[0] =
2957 get_dac_if_single(codec, cfg->speaker_pins[0]);
2960 for (i = 0; i < cfg->line_outs; i++) {
2961 hda_nid_t pin = cfg->line_out_pins[i];
2962 if (spec->private_dac_nids[i])
2964 spec->private_dac_nids[i] = alc_auto_look_for_dac(codec, pin);
2965 if (!spec->private_dac_nids[i] && !redone) {
2966 /* if we can't find primary DACs, re-probe without
2967 * checking the hard-wired DACs
2974 /* re-count num_dacs and squash invalid entries */
2975 spec->multiout.num_dacs = 0;
2976 for (i = 0; i < cfg->line_outs; i++) {
2977 if (spec->private_dac_nids[i])
2978 spec->multiout.num_dacs++;
2980 memmove(spec->private_dac_nids + i,
2981 spec->private_dac_nids + i + 1,
2982 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
2985 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
2986 /* try to fill multi-io first */
2987 unsigned int location, defcfg;
2990 defcfg = snd_hda_codec_get_pincfg(codec, cfg->line_out_pins[0]);
2991 location = get_defcfg_location(defcfg);
2993 num_pins = alc_auto_fill_multi_ios(codec, location);
2995 spec->multi_ios = num_pins;
2996 spec->ext_channel_count = 2;
2997 spec->multiout.num_dacs = num_pins + 1;
3001 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
3002 alc_auto_fill_extra_dacs(codec, cfg->hp_outs, cfg->hp_pins,
3003 spec->multiout.hp_out_nid);
3004 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
3005 alc_auto_fill_extra_dacs(codec, cfg->speaker_outs, cfg->speaker_pins,
3006 spec->multiout.extra_out_nid);
3011 static inline unsigned int get_ctl_pos(unsigned int data)
3013 hda_nid_t nid = get_amp_nid_(data);
3014 unsigned int dir = get_amp_direction_(data);
3015 return (nid << 1) | dir;
3018 #define is_ctl_used(bits, data) \
3019 test_bit(get_ctl_pos(data), bits)
3020 #define mark_ctl_usage(bits, data) \
3021 set_bit(get_ctl_pos(data), bits)
3023 static int alc_auto_add_vol_ctl(struct hda_codec *codec,
3024 const char *pfx, int cidx,
3025 hda_nid_t nid, unsigned int chs)
3027 struct alc_spec *spec = codec->spec;
3031 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3032 if (is_ctl_used(spec->vol_ctls, val) && chs != 2) /* exclude LFE */
3034 mark_ctl_usage(spec->vol_ctls, val);
3035 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
3039 #define alc_auto_add_stereo_vol(codec, pfx, cidx, nid) \
3040 alc_auto_add_vol_ctl(codec, pfx, cidx, nid, 3)
3042 /* create a mute-switch for the given mixer widget;
3043 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3045 static int alc_auto_add_sw_ctl(struct hda_codec *codec,
3046 const char *pfx, int cidx,
3047 hda_nid_t nid, unsigned int chs)
3049 struct alc_spec *spec = codec->spec;
3055 wid_type = get_wcaps_type(get_wcaps(codec, nid));
3056 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) {
3057 type = ALC_CTL_WIDGET_MUTE;
3058 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3059 } else if (snd_hda_get_conn_list(codec, nid, NULL) == 1) {
3060 type = ALC_CTL_WIDGET_MUTE;
3061 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
3063 type = ALC_CTL_BIND_MUTE;
3064 val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
3066 if (is_ctl_used(spec->sw_ctls, val) && chs != 2) /* exclude LFE */
3068 mark_ctl_usage(spec->sw_ctls, val);
3069 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
3072 #define alc_auto_add_stereo_sw(codec, pfx, cidx, nid) \
3073 alc_auto_add_sw_ctl(codec, pfx, cidx, nid, 3)
3075 static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3076 hda_nid_t pin, hda_nid_t dac)
3078 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3079 if (nid_has_mute(codec, pin, HDA_OUTPUT))
3081 else if (mix && nid_has_mute(codec, mix, HDA_INPUT))
3083 else if (nid_has_mute(codec, dac, HDA_OUTPUT))
3088 static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3089 hda_nid_t pin, hda_nid_t dac)
3091 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3092 if (nid_has_volume(codec, dac, HDA_OUTPUT))
3094 else if (nid_has_volume(codec, mix, HDA_OUTPUT))
3096 else if (nid_has_volume(codec, pin, HDA_OUTPUT))
3101 /* add playback controls from the parsed DAC table */
3102 static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
3103 const struct auto_pin_cfg *cfg)
3105 struct alc_spec *spec = codec->spec;
3106 int i, err, noutputs;
3108 noutputs = cfg->line_outs;
3109 if (spec->multi_ios > 0)
3110 noutputs += spec->multi_ios;
3112 for (i = 0; i < noutputs; i++) {
3118 dac = spec->multiout.dac_nids[i];
3121 if (i >= cfg->line_outs)
3122 pin = spec->multi_io[i - 1].pin;
3124 pin = cfg->line_out_pins[i];
3126 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3127 vol = alc_look_for_out_vol_nid(codec, pin, dac);
3128 name = alc_get_line_out_pfx(spec, i, true, &index);
3129 if (!name || !strcmp(name, "CLFE")) {
3131 err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1);
3134 err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2);
3137 err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1);
3140 err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2);
3144 err = alc_auto_add_stereo_vol(codec, name, index, vol);
3147 err = alc_auto_add_stereo_sw(codec, name, index, sw);
3155 static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
3156 hda_nid_t dac, const char *pfx)
3158 struct alc_spec *spec = codec->spec;
3164 /* the corresponding DAC is already occupied */
3165 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
3166 return 0; /* no way */
3167 /* create a switch only */
3168 val = HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT);
3169 if (is_ctl_used(spec->sw_ctls, val))
3170 return 0; /* already created */
3171 mark_ctl_usage(spec->sw_ctls, val);
3172 return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, val);
3175 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3176 vol = alc_look_for_out_vol_nid(codec, pin, dac);
3177 err = alc_auto_add_stereo_vol(codec, pfx, 0, vol);
3180 err = alc_auto_add_stereo_sw(codec, pfx, 0, sw);
3186 static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3188 struct hda_ctl_ops *ops)
3190 struct alc_spec *spec = codec->spec;
3191 struct hda_bind_ctls **ctlp, *ctl;
3192 snd_array_init(&spec->bind_ctls, sizeof(ctl), 8);
3193 ctlp = snd_array_new(&spec->bind_ctls);
3196 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3203 /* add playback controls for speaker and HP outputs */
3204 static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3205 const hda_nid_t *pins,
3206 const hda_nid_t *dacs,
3209 struct alc_spec *spec = codec->spec;
3210 struct hda_bind_ctls *ctl;
3214 if (!num_pins || !pins[0])
3217 if (num_pins == 1) {
3218 hda_nid_t dac = *dacs;
3220 dac = spec->multiout.dac_nids[0];
3221 return alc_auto_create_extra_out(codec, *pins, dac, pfx);
3224 if (dacs[num_pins - 1]) {
3225 /* OK, we have a multi-output system with individual volumes */
3226 for (i = 0; i < num_pins; i++) {
3227 snprintf(name, sizeof(name), "%s %s",
3228 pfx, channel_name[i]);
3229 err = alc_auto_create_extra_out(codec, pins[i], dacs[i],
3237 /* Let's create a bind-controls */
3238 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_sw);
3242 for (i = 0; i < num_pins; i++) {
3243 if (get_wcaps(codec, pins[i]) & AC_WCAP_OUT_AMP)
3245 HDA_COMPOSE_AMP_VAL(pins[i], 3, 0, HDA_OUTPUT);
3248 snprintf(name, sizeof(name), "%s Playback Switch", pfx);
3249 err = add_control(spec, ALC_CTL_BIND_SW, name, 0, (long)ctl);
3254 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3258 for (i = 0; i < num_pins; i++) {
3260 if (!pins[i] || !dacs[i])
3262 vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]);
3265 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3268 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3269 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3276 static int alc_auto_create_hp_out(struct hda_codec *codec)
3278 struct alc_spec *spec = codec->spec;
3279 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3280 spec->autocfg.hp_pins,
3281 spec->multiout.hp_out_nid,
3285 static int alc_auto_create_speaker_out(struct hda_codec *codec)
3287 struct alc_spec *spec = codec->spec;
3288 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3289 spec->autocfg.speaker_pins,
3290 spec->multiout.extra_out_nid,
3294 static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
3295 hda_nid_t pin, int pin_type,
3299 hda_nid_t nid, mix = 0;
3300 hda_nid_t srcs[HDA_MAX_CONNECTIONS];
3302 alc_set_pin_output(codec, pin, pin_type);
3303 nid = alc_go_down_to_selector(codec, pin);
3304 num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
3305 for (i = 0; i < num; i++) {
3306 if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
3314 /* need the manual connection? */
3316 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
3317 /* unmute mixer widget inputs */
3318 if (nid_has_mute(codec, mix, HDA_INPUT)) {
3319 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3321 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3324 /* initialize volume */
3325 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3327 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3331 static void alc_auto_init_multi_out(struct hda_codec *codec)
3333 struct alc_spec *spec = codec->spec;
3334 int pin_type = get_pin_type(spec->autocfg.line_out_type);
3337 for (i = 0; i <= HDA_SIDE; i++) {
3338 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3340 alc_auto_set_output_and_unmute(codec, nid, pin_type,
3341 spec->multiout.dac_nids[i]);
3345 static void alc_auto_init_extra_out(struct hda_codec *codec)
3347 struct alc_spec *spec = codec->spec;
3351 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3352 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3354 pin = spec->autocfg.hp_pins[i];
3357 dac = spec->multiout.hp_out_nid[i];
3359 if (i > 0 && spec->multiout.hp_out_nid[0])
3360 dac = spec->multiout.hp_out_nid[0];
3362 dac = spec->multiout.dac_nids[0];
3364 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
3366 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3367 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3369 pin = spec->autocfg.speaker_pins[i];
3372 dac = spec->multiout.extra_out_nid[i];
3374 if (i > 0 && spec->multiout.extra_out_nid[0])
3375 dac = spec->multiout.extra_out_nid[0];
3377 dac = spec->multiout.dac_nids[0];
3379 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
3386 static int alc_auto_fill_multi_ios(struct hda_codec *codec,
3387 unsigned int location)
3389 struct alc_spec *spec = codec->spec;
3390 struct auto_pin_cfg *cfg = &spec->autocfg;
3391 hda_nid_t prime_dac = spec->private_dac_nids[0];
3392 int type, i, num_pins = 0;
3394 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3395 for (i = 0; i < cfg->num_inputs; i++) {
3396 hda_nid_t nid = cfg->inputs[i].pin;
3398 unsigned int defcfg, caps;
3399 if (cfg->inputs[i].type != type)
3401 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3402 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3404 if (location && get_defcfg_location(defcfg) != location)
3406 caps = snd_hda_query_pin_caps(codec, nid);
3407 if (!(caps & AC_PINCAP_OUT))
3409 dac = alc_auto_look_for_dac(codec, nid);
3412 spec->multi_io[num_pins].pin = nid;
3413 spec->multi_io[num_pins].dac = dac;
3415 spec->private_dac_nids[spec->multiout.num_dacs++] = dac;
3418 spec->multiout.num_dacs = 1;
3420 /* clear up again */
3421 memset(spec->private_dac_nids, 0,
3422 sizeof(spec->private_dac_nids));
3423 spec->private_dac_nids[0] = prime_dac;
3429 static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
3430 struct snd_ctl_elem_info *uinfo)
3432 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3433 struct alc_spec *spec = codec->spec;
3435 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3437 uinfo->value.enumerated.items = spec->multi_ios + 1;
3438 if (uinfo->value.enumerated.item > spec->multi_ios)
3439 uinfo->value.enumerated.item = spec->multi_ios;
3440 sprintf(uinfo->value.enumerated.name, "%dch",
3441 (uinfo->value.enumerated.item + 1) * 2);
3445 static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
3446 struct snd_ctl_elem_value *ucontrol)
3448 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3449 struct alc_spec *spec = codec->spec;
3450 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
3454 static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
3456 struct alc_spec *spec = codec->spec;
3457 hda_nid_t nid = spec->multi_io[idx].pin;
3459 if (!spec->multi_io[idx].ctl_in)
3460 spec->multi_io[idx].ctl_in =
3461 snd_hda_codec_read(codec, nid, 0,
3462 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3464 snd_hda_codec_update_cache(codec, nid, 0,
3465 AC_VERB_SET_PIN_WIDGET_CONTROL,
3467 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3468 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3470 alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
3472 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3473 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3474 HDA_AMP_MUTE, HDA_AMP_MUTE);
3475 snd_hda_codec_update_cache(codec, nid, 0,
3476 AC_VERB_SET_PIN_WIDGET_CONTROL,
3477 spec->multi_io[idx].ctl_in);
3482 static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
3483 struct snd_ctl_elem_value *ucontrol)
3485 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3486 struct alc_spec *spec = codec->spec;
3489 ch = ucontrol->value.enumerated.item[0];
3490 if (ch < 0 || ch > spec->multi_ios)
3492 if (ch == (spec->ext_channel_count - 1) / 2)
3494 spec->ext_channel_count = (ch + 1) * 2;
3495 for (i = 0; i < spec->multi_ios; i++)
3496 alc_set_multi_io(codec, i, i < ch);
3497 spec->multiout.max_channels = spec->ext_channel_count;
3498 if (spec->need_dac_fix && !spec->const_channel_count)
3499 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
3503 static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
3504 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3505 .name = "Channel Mode",
3506 .info = alc_auto_ch_mode_info,
3507 .get = alc_auto_ch_mode_get,
3508 .put = alc_auto_ch_mode_put,
3511 static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
3513 struct alc_spec *spec = codec->spec;
3515 if (spec->multi_ios > 0) {
3516 struct snd_kcontrol_new *knew;
3518 knew = alc_kcontrol_new(spec);
3521 *knew = alc_auto_channel_mode_enum;
3522 knew->name = kstrdup("Channel Mode", GFP_KERNEL);
3529 /* filter out invalid adc_nids (and capsrc_nids) that don't give all
3532 static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
3534 struct alc_spec *spec = codec->spec;
3535 const struct hda_input_mux *imux;
3536 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3537 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3540 imux = spec->input_mux;
3543 if (spec->dyn_adc_switch)
3547 for (n = 0; n < spec->num_adc_nids; n++) {
3548 hda_nid_t cap = spec->private_capsrc_nids[n];
3549 int num_conns = snd_hda_get_conn_list(codec, cap, NULL);
3550 for (i = 0; i < imux->num_items; i++) {
3551 hda_nid_t pin = spec->imux_pins[i];
3553 if (get_connection_index(codec, cap, pin) < 0)
3555 } else if (num_conns <= imux->items[i].index)
3558 if (i >= imux->num_items) {
3559 adc_nids[nums] = spec->private_adc_nids[n];
3560 capsrc_nids[nums++] = cap;
3564 /* check whether ADC-switch is possible */
3565 if (!alc_check_dyn_adc_switch(codec)) {
3566 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
3567 " using fallback 0x%x\n",
3568 codec->chip_name, spec->private_adc_nids[0]);
3569 spec->num_adc_nids = 1;
3573 } else if (nums != spec->num_adc_nids) {
3574 memcpy(spec->private_adc_nids, adc_nids,
3575 nums * sizeof(hda_nid_t));
3576 memcpy(spec->private_capsrc_nids, capsrc_nids,
3577 nums * sizeof(hda_nid_t));
3578 spec->num_adc_nids = nums;
3582 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
3583 else if (spec->input_mux->num_items == 1)
3584 spec->num_adc_nids = 1; /* reduce to a single ADC */
3588 * initialize ADC paths
3590 static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
3592 struct alc_spec *spec = codec->spec;
3595 nid = spec->adc_nids[adc_idx];
3597 if (nid_has_mute(codec, nid, HDA_INPUT)) {
3598 snd_hda_codec_write(codec, nid, 0,
3599 AC_VERB_SET_AMP_GAIN_MUTE,
3603 if (!spec->capsrc_nids)
3605 nid = spec->capsrc_nids[adc_idx];
3606 if (nid_has_mute(codec, nid, HDA_OUTPUT))
3607 snd_hda_codec_write(codec, nid, 0,
3608 AC_VERB_SET_AMP_GAIN_MUTE,
3612 static void alc_auto_init_input_src(struct hda_codec *codec)
3614 struct alc_spec *spec = codec->spec;
3617 for (c = 0; c < spec->num_adc_nids; c++)
3618 alc_auto_init_adc(codec, c);
3619 if (spec->dyn_adc_switch)
3622 nums = spec->num_adc_nids;
3623 for (c = 0; c < nums; c++)
3624 alc_mux_select(codec, 0, spec->cur_mux[c], true);
3627 /* add mic boosts if needed */
3628 static int alc_auto_add_mic_boost(struct hda_codec *codec)
3630 struct alc_spec *spec = codec->spec;
3631 struct auto_pin_cfg *cfg = &spec->autocfg;
3635 const char *prev_label = NULL;
3637 for (i = 0; i < cfg->num_inputs; i++) {
3638 if (cfg->inputs[i].type > AUTO_PIN_MIC)
3640 nid = cfg->inputs[i].pin;
3641 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
3643 char boost_label[32];
3645 label = hda_get_autocfg_input_label(codec, cfg, i);
3646 if (prev_label && !strcmp(label, prev_label))
3652 snprintf(boost_label, sizeof(boost_label),
3653 "%s Boost Volume", label);
3654 err = add_control(spec, ALC_CTL_WIDGET_VOL,
3655 boost_label, type_idx,
3656 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
3664 /* select or unmute the given capsrc route */
3665 static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
3668 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
3669 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
3671 } else if (snd_hda_get_conn_list(codec, cap, NULL) > 1) {
3672 snd_hda_codec_write_cache(codec, cap, 0,
3673 AC_VERB_SET_CONNECT_SEL, idx);
3677 /* set the default connection to that pin */
3678 static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
3680 struct alc_spec *spec = codec->spec;
3685 for (i = 0; i < spec->num_adc_nids; i++) {
3686 hda_nid_t cap = spec->capsrc_nids ?
3687 spec->capsrc_nids[i] : spec->adc_nids[i];
3690 idx = get_connection_index(codec, cap, pin);
3693 select_or_unmute_capsrc(codec, cap, idx);
3694 return i; /* return the found index */
3696 return -1; /* not found */
3699 /* initialize some special cases for input sources */
3700 static void alc_init_special_input_src(struct hda_codec *codec)
3702 struct alc_spec *spec = codec->spec;
3705 for (i = 0; i < spec->autocfg.num_inputs; i++)
3706 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
3709 /* assign appropriate capture mixers */
3710 static void set_capture_mixer(struct hda_codec *codec)
3712 struct alc_spec *spec = codec->spec;
3713 static const struct snd_kcontrol_new *caps[2][3] = {
3714 { alc_capture_mixer_nosrc1,
3715 alc_capture_mixer_nosrc2,
3716 alc_capture_mixer_nosrc3 },
3717 { alc_capture_mixer1,
3719 alc_capture_mixer3 },
3722 /* check whether either of ADC or MUX has a volume control */
3723 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
3724 if (!spec->capsrc_nids)
3725 return; /* no volume */
3726 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
3727 return; /* no volume in capsrc, too */
3728 spec->vol_in_capsrc = 1;
3731 if (spec->num_adc_nids > 0) {
3735 if (spec->input_mux && spec->input_mux->num_items > 1)
3737 if (spec->auto_mic) {
3740 } else if (spec->dyn_adc_switch)
3743 if (spec->num_adc_nids > 3)
3744 spec->num_adc_nids = 3;
3745 else if (!spec->num_adc_nids)
3747 num_adcs = spec->num_adc_nids;
3749 spec->cap_mixer = caps[mux][num_adcs - 1];
3754 * standard auto-parser initializations
3756 static void alc_auto_init_std(struct hda_codec *codec)
3758 struct alc_spec *spec = codec->spec;
3759 alc_auto_init_multi_out(codec);
3760 alc_auto_init_extra_out(codec);
3761 alc_auto_init_analog_input(codec);
3762 alc_auto_init_input_src(codec);
3763 alc_auto_init_digital(codec);
3764 if (spec->unsol_event)
3765 alc_inithook(codec);
3769 * Digital-beep handlers
3771 #ifdef CONFIG_SND_HDA_INPUT_BEEP
3772 #define set_beep_amp(spec, nid, idx, dir) \
3773 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
3775 static const struct snd_pci_quirk beep_white_list[] = {
3776 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
3777 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
3778 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
3779 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
3780 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
3784 static inline int has_cdefine_beep(struct hda_codec *codec)
3786 struct alc_spec *spec = codec->spec;
3787 const struct snd_pci_quirk *q;
3788 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
3791 return spec->cdefine.enable_pcbeep;
3794 #define set_beep_amp(spec, nid, idx, dir) /* NOP */
3795 #define has_cdefine_beep(codec) 0
3798 /* parse the BIOS configuration and set up the alc_spec */
3799 /* return 1 if successful, 0 if the proper config is not found,
3800 * or a negative error code
3802 static int alc_parse_auto_config(struct hda_codec *codec,
3803 const hda_nid_t *ignore_nids,
3804 const hda_nid_t *ssid_nids)
3806 struct alc_spec *spec = codec->spec;
3807 struct auto_pin_cfg *cfg = &spec->autocfg;
3810 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
3814 if (!cfg->line_outs) {
3815 if (cfg->dig_outs || cfg->dig_in_pin) {
3816 spec->multiout.max_channels = 2;
3817 spec->no_analog = 1;
3820 return 0; /* can't find valid BIOS pin config */
3823 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
3824 cfg->line_outs <= cfg->hp_outs) {
3825 /* use HP as primary out */
3826 cfg->speaker_outs = cfg->line_outs;
3827 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3828 sizeof(cfg->speaker_pins));
3829 cfg->line_outs = cfg->hp_outs;
3830 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
3832 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3833 cfg->line_out_type = AUTO_PIN_HP_OUT;
3836 err = alc_auto_fill_dac_nids(codec);
3839 err = alc_auto_add_multi_channel_mode(codec);
3842 err = alc_auto_create_multi_out_ctls(codec, cfg);
3845 err = alc_auto_create_hp_out(codec);
3848 err = alc_auto_create_speaker_out(codec);
3851 err = alc_auto_create_input_ctls(codec);
3855 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3858 alc_auto_parse_digital(codec);
3860 if (!spec->no_analog)
3861 alc_remove_invalid_adc_nids(codec);
3864 alc_ssid_check(codec, ssid_nids);
3866 if (!spec->no_analog) {
3867 alc_auto_check_switches(codec);
3868 err = alc_auto_add_mic_boost(codec);
3873 if (spec->kctls.list)
3874 add_mixer(spec, spec->kctls.list);
3879 static int alc880_parse_auto_config(struct hda_codec *codec)
3881 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
3882 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
3883 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
3886 #ifdef CONFIG_SND_HDA_POWER_SAVE
3887 static const struct hda_amp_list alc880_loopbacks[] = {
3888 { 0x0b, HDA_INPUT, 0 },
3889 { 0x0b, HDA_INPUT, 1 },
3890 { 0x0b, HDA_INPUT, 2 },
3891 { 0x0b, HDA_INPUT, 3 },
3892 { 0x0b, HDA_INPUT, 4 },
3900 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3901 #define alc_board_config \
3902 snd_hda_check_board_config
3903 #define alc_board_codec_sid_config \
3904 snd_hda_check_board_codec_sid_config
3905 #include "alc_quirks.c"
3907 #define alc_board_config(codec, nums, models, tbl) -1
3908 #define alc_board_codec_sid_config(codec, nums, models, tbl) -1
3909 #define setup_preset(codec, x) /* NOP */
3913 * OK, here we have finally the patch for ALC880
3915 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3916 #include "alc880_quirks.c"
3919 static int patch_alc880(struct hda_codec *codec)
3921 struct alc_spec *spec;
3925 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3931 spec->mixer_nid = 0x0b;
3932 spec->need_dac_fix = 1;
3934 board_config = alc_board_config(codec, ALC880_MODEL_LAST,
3935 alc880_models, alc880_cfg_tbl);
3936 if (board_config < 0) {
3937 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
3939 board_config = ALC_MODEL_AUTO;
3942 if (board_config == ALC_MODEL_AUTO) {
3943 /* automatic parse from the BIOS config */
3944 err = alc880_parse_auto_config(codec);
3947 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3950 "hda_codec: Cannot set up configuration "
3951 "from BIOS. Using 3-stack mode...\n");
3952 board_config = ALC880_3ST;
3957 if (board_config != ALC_MODEL_AUTO)
3958 setup_preset(codec, &alc880_presets[board_config]);
3960 if (!spec->no_analog && !spec->adc_nids) {
3961 alc_auto_fill_adc_caps(codec);
3962 alc_rebuild_imux_for_auto_mic(codec);
3963 alc_remove_invalid_adc_nids(codec);
3966 if (!spec->no_analog && !spec->cap_mixer)
3967 set_capture_mixer(codec);
3969 if (!spec->no_analog) {
3970 err = snd_hda_attach_beep_device(codec, 0x1);
3973 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
3976 spec->vmaster_nid = 0x0c;
3978 codec->patch_ops = alc_patch_ops;
3979 if (board_config == ALC_MODEL_AUTO)
3980 spec->init_hook = alc_auto_init_std;
3981 #ifdef CONFIG_SND_HDA_POWER_SAVE
3982 if (!spec->loopback.amplist)
3983 spec->loopback.amplist = alc880_loopbacks;
3997 static int alc260_parse_auto_config(struct hda_codec *codec)
3999 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
4000 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
4001 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
4004 #ifdef CONFIG_SND_HDA_POWER_SAVE
4005 static const struct hda_amp_list alc260_loopbacks[] = {
4006 { 0x07, HDA_INPUT, 0 },
4007 { 0x07, HDA_INPUT, 1 },
4008 { 0x07, HDA_INPUT, 2 },
4009 { 0x07, HDA_INPUT, 3 },
4010 { 0x07, HDA_INPUT, 4 },
4022 static const struct alc_fixup alc260_fixups[] = {
4023 [PINFIX_HP_DC5750] = {
4024 .type = ALC_FIXUP_PINS,
4025 .v.pins = (const struct alc_pincfg[]) {
4026 { 0x11, 0x90130110 }, /* speaker */
4032 static const struct snd_pci_quirk alc260_fixup_tbl[] = {
4033 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", PINFIX_HP_DC5750),
4039 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4040 #include "alc260_quirks.c"
4043 static int patch_alc260(struct hda_codec *codec)
4045 struct alc_spec *spec;
4046 int err, board_config;
4048 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4054 spec->mixer_nid = 0x07;
4056 board_config = alc_board_config(codec, ALC260_MODEL_LAST,
4057 alc260_models, alc260_cfg_tbl);
4058 if (board_config < 0) {
4059 snd_printd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4061 board_config = ALC_MODEL_AUTO;
4064 if (board_config == ALC_MODEL_AUTO) {
4065 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
4066 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4069 if (board_config == ALC_MODEL_AUTO) {
4070 /* automatic parse from the BIOS config */
4071 err = alc260_parse_auto_config(codec);
4074 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4077 "hda_codec: Cannot set up configuration "
4078 "from BIOS. Using base mode...\n");
4079 board_config = ALC260_BASIC;
4084 if (board_config != ALC_MODEL_AUTO)
4085 setup_preset(codec, &alc260_presets[board_config]);
4087 if (!spec->no_analog && !spec->adc_nids) {
4088 alc_auto_fill_adc_caps(codec);
4089 alc_rebuild_imux_for_auto_mic(codec);
4090 alc_remove_invalid_adc_nids(codec);
4093 if (!spec->no_analog && !spec->cap_mixer)
4094 set_capture_mixer(codec);
4096 if (!spec->no_analog) {
4097 err = snd_hda_attach_beep_device(codec, 0x1);
4100 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
4103 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4105 spec->vmaster_nid = 0x08;
4107 codec->patch_ops = alc_patch_ops;
4108 if (board_config == ALC_MODEL_AUTO)
4109 spec->init_hook = alc_auto_init_std;
4110 spec->shutup = alc_eapd_shutup;
4111 #ifdef CONFIG_SND_HDA_POWER_SAVE
4112 if (!spec->loopback.amplist)
4113 spec->loopback.amplist = alc260_loopbacks;
4125 * ALC882/883/885/888/889 support
4127 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
4128 * configuration. Each pin widget can choose any input DACs and a mixer.
4129 * Each ADC is connected from a mixer of all inputs. This makes possible
4130 * 6-channel independent captures.
4132 * In addition, an independent DAC for the multi-playback (not used in this
4135 #ifdef CONFIG_SND_HDA_POWER_SAVE
4136 #define alc882_loopbacks alc880_loopbacks
4143 PINFIX_ABIT_AW9D_MAX,
4146 PINFIX_ACER_ASPIRE_7736,
4150 static const struct alc_fixup alc882_fixups[] = {
4151 [PINFIX_ABIT_AW9D_MAX] = {
4152 .type = ALC_FIXUP_PINS,
4153 .v.pins = (const struct alc_pincfg[]) {
4154 { 0x15, 0x01080104 }, /* side */
4155 { 0x16, 0x01011012 }, /* rear */
4156 { 0x17, 0x01016011 }, /* clfe */
4160 [PINFIX_LENOVO_Y530] = {
4161 .type = ALC_FIXUP_PINS,
4162 .v.pins = (const struct alc_pincfg[]) {
4163 { 0x15, 0x99130112 }, /* rear int speakers */
4164 { 0x16, 0x99130111 }, /* subwoofer */
4168 [PINFIX_PB_M5210] = {
4169 .type = ALC_FIXUP_VERBS,
4170 .v.verbs = (const struct hda_verb[]) {
4171 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
4175 [PINFIX_ACER_ASPIRE_7736] = {
4176 .type = ALC_FIXUP_SKU,
4177 .v.sku = ALC_FIXUP_SKU_IGNORE,
4179 [PINFIX_ASUS_W90V] = {
4180 .type = ALC_FIXUP_PINS,
4181 .v.pins = (const struct alc_pincfg[]) {
4182 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
4188 static const struct snd_pci_quirk alc882_fixup_tbl[] = {
4189 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", PINFIX_PB_M5210),
4190 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", PINFIX_ASUS_W90V),
4191 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", PINFIX_LENOVO_Y530),
4192 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
4193 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", PINFIX_ACER_ASPIRE_7736),
4198 * BIOS auto configuration
4200 /* almost identical with ALC880 parser... */
4201 static int alc882_parse_auto_config(struct hda_codec *codec)
4203 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
4204 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4205 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
4210 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4211 #include "alc882_quirks.c"
4214 static int patch_alc882(struct hda_codec *codec)
4216 struct alc_spec *spec;
4217 int err, board_config;
4219 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4225 spec->mixer_nid = 0x0b;
4227 switch (codec->vendor_id) {
4232 /* ALC883 and variants */
4233 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
4237 err = alc_codec_rename_from_preset(codec);
4241 board_config = alc_board_config(codec, ALC882_MODEL_LAST,
4242 alc882_models, alc882_cfg_tbl);
4244 if (board_config < 0)
4245 board_config = alc_board_codec_sid_config(codec,
4246 ALC882_MODEL_LAST, alc882_models, alc882_ssid_cfg_tbl);
4248 if (board_config < 0) {
4249 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4251 board_config = ALC_MODEL_AUTO;
4254 if (board_config == ALC_MODEL_AUTO) {
4255 alc_pick_fixup(codec, NULL, alc882_fixup_tbl, alc882_fixups);
4256 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4259 alc_auto_parse_customize_define(codec);
4261 if (board_config == ALC_MODEL_AUTO) {
4262 /* automatic parse from the BIOS config */
4263 err = alc882_parse_auto_config(codec);
4266 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4269 "hda_codec: Cannot set up configuration "
4270 "from BIOS. Using base mode...\n");
4271 board_config = ALC882_3ST_DIG;
4276 if (board_config != ALC_MODEL_AUTO)
4277 setup_preset(codec, &alc882_presets[board_config]);
4279 if (!spec->no_analog && !spec->adc_nids) {
4280 alc_auto_fill_adc_caps(codec);
4281 alc_rebuild_imux_for_auto_mic(codec);
4282 alc_remove_invalid_adc_nids(codec);
4285 if (!spec->no_analog && !spec->cap_mixer)
4286 set_capture_mixer(codec);
4288 if (!spec->no_analog && has_cdefine_beep(codec)) {
4289 err = snd_hda_attach_beep_device(codec, 0x1);
4292 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4295 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4297 spec->vmaster_nid = 0x0c;
4299 codec->patch_ops = alc_patch_ops;
4300 if (board_config == ALC_MODEL_AUTO)
4301 spec->init_hook = alc_auto_init_std;
4303 alc_init_jacks(codec);
4304 #ifdef CONFIG_SND_HDA_POWER_SAVE
4305 if (!spec->loopback.amplist)
4306 spec->loopback.amplist = alc882_loopbacks;
4320 static int alc262_parse_auto_config(struct hda_codec *codec)
4322 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
4323 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4324 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
4335 static const struct alc_fixup alc262_fixups[] = {
4336 [PINFIX_FSC_H270] = {
4337 .type = ALC_FIXUP_PINS,
4338 .v.pins = (const struct alc_pincfg[]) {
4339 { 0x14, 0x99130110 }, /* speaker */
4340 { 0x15, 0x0221142f }, /* front HP */
4341 { 0x1b, 0x0121141f }, /* rear HP */
4345 [PINFIX_HP_Z200] = {
4346 .type = ALC_FIXUP_PINS,
4347 .v.pins = (const struct alc_pincfg[]) {
4348 { 0x16, 0x99130120 }, /* internal speaker */
4354 static const struct snd_pci_quirk alc262_fixup_tbl[] = {
4355 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", PINFIX_HP_Z200),
4356 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", PINFIX_FSC_H270),
4361 #ifdef CONFIG_SND_HDA_POWER_SAVE
4362 #define alc262_loopbacks alc880_loopbacks
4367 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4368 #include "alc262_quirks.c"
4371 static int patch_alc262(struct hda_codec *codec)
4373 struct alc_spec *spec;
4377 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4383 spec->mixer_nid = 0x0b;
4386 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
4391 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4392 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
4393 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4394 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
4397 alc_auto_parse_customize_define(codec);
4399 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
4401 board_config = alc_board_config(codec, ALC262_MODEL_LAST,
4402 alc262_models, alc262_cfg_tbl);
4404 if (board_config < 0) {
4405 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4407 board_config = ALC_MODEL_AUTO;
4410 if (board_config == ALC_MODEL_AUTO) {
4411 alc_pick_fixup(codec, NULL, alc262_fixup_tbl, alc262_fixups);
4412 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4415 if (board_config == ALC_MODEL_AUTO) {
4416 /* automatic parse from the BIOS config */
4417 err = alc262_parse_auto_config(codec);
4420 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4423 "hda_codec: Cannot set up configuration "
4424 "from BIOS. Using base mode...\n");
4425 board_config = ALC262_BASIC;
4430 if (board_config != ALC_MODEL_AUTO)
4431 setup_preset(codec, &alc262_presets[board_config]);
4433 if (!spec->no_analog && !spec->adc_nids) {
4434 alc_auto_fill_adc_caps(codec);
4435 alc_rebuild_imux_for_auto_mic(codec);
4436 alc_remove_invalid_adc_nids(codec);
4439 if (!spec->no_analog && !spec->cap_mixer)
4440 set_capture_mixer(codec);
4442 if (!spec->no_analog && has_cdefine_beep(codec)) {
4443 err = snd_hda_attach_beep_device(codec, 0x1);
4446 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4449 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4451 spec->vmaster_nid = 0x0c;
4453 codec->patch_ops = alc_patch_ops;
4454 if (board_config == ALC_MODEL_AUTO)
4455 spec->init_hook = alc_auto_init_std;
4456 spec->shutup = alc_eapd_shutup;
4458 alc_init_jacks(codec);
4459 #ifdef CONFIG_SND_HDA_POWER_SAVE
4460 if (!spec->loopback.amplist)
4461 spec->loopback.amplist = alc262_loopbacks;
4474 /* bind Beep switches of both NID 0x0f and 0x10 */
4475 static const struct hda_bind_ctls alc268_bind_beep_sw = {
4476 .ops = &snd_hda_bind_sw,
4478 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
4479 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
4484 static const struct snd_kcontrol_new alc268_beep_mixer[] = {
4485 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
4486 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
4490 /* set PCBEEP vol = 0, mute connections */
4491 static const struct hda_verb alc268_beep_init_verbs[] = {
4492 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4493 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4494 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4499 * BIOS auto configuration
4501 static int alc268_parse_auto_config(struct hda_codec *codec)
4503 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4504 struct alc_spec *spec = codec->spec;
4505 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
4507 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
4508 add_mixer(spec, alc268_beep_mixer);
4509 add_verb(spec, alc268_beep_init_verbs);
4517 static int patch_alc268(struct hda_codec *codec)
4519 struct alc_spec *spec;
4520 int i, has_beep, err;
4522 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4528 /* ALC268 has no aa-loopback mixer */
4530 /* automatic parse from the BIOS config */
4531 err = alc268_parse_auto_config(codec);
4536 for (i = 0; i < spec->num_mixers; i++) {
4537 if (spec->mixers[i] == alc268_beep_mixer) {
4544 err = snd_hda_attach_beep_device(codec, 0x1);
4547 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
4548 /* override the amp caps for beep generator */
4549 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
4550 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
4551 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
4552 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4553 (0 << AC_AMPCAP_MUTE_SHIFT));
4556 if (!spec->no_analog && !spec->adc_nids) {
4557 alc_auto_fill_adc_caps(codec);
4558 alc_rebuild_imux_for_auto_mic(codec);
4559 alc_remove_invalid_adc_nids(codec);
4562 if (!spec->no_analog && !spec->cap_mixer)
4563 set_capture_mixer(codec);
4565 spec->vmaster_nid = 0x02;
4567 codec->patch_ops = alc_patch_ops;
4568 spec->init_hook = alc_auto_init_std;
4569 spec->shutup = alc_eapd_shutup;
4571 alc_init_jacks(codec);
4583 #ifdef CONFIG_SND_HDA_POWER_SAVE
4584 #define alc269_loopbacks alc880_loopbacks
4587 static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
4591 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
4592 /* NID is set in alc_build_pcms */
4594 .open = alc_playback_pcm_open,
4595 .prepare = alc_playback_pcm_prepare,
4596 .cleanup = alc_playback_pcm_cleanup
4600 static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
4604 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
4605 /* NID is set in alc_build_pcms */
4608 #ifdef CONFIG_SND_HDA_POWER_SAVE
4609 static int alc269_mic2_for_mute_led(struct hda_codec *codec)
4611 switch (codec->subsystem_id) {
4618 static int alc269_mic2_mute_check_ps(struct hda_codec *codec, hda_nid_t nid)
4620 /* update mute-LED according to the speaker mute state */
4621 if (nid == 0x01 || nid == 0x14) {
4623 if (snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0) &
4628 /* mic2 vref pin is used for mute LED control */
4629 snd_hda_codec_update_cache(codec, 0x19, 0,
4630 AC_VERB_SET_PIN_WIDGET_CONTROL,
4633 return alc_check_power_status(codec, nid);
4635 #endif /* CONFIG_SND_HDA_POWER_SAVE */
4637 /* different alc269-variants */
4639 ALC269_TYPE_ALC269VA,
4640 ALC269_TYPE_ALC269VB,
4641 ALC269_TYPE_ALC269VC,
4645 * BIOS auto configuration
4647 static int alc269_parse_auto_config(struct hda_codec *codec)
4649 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
4650 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
4651 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4652 struct alc_spec *spec = codec->spec;
4653 const hda_nid_t *ssids = spec->codec_variant == ALC269_TYPE_ALC269VA ?
4654 alc269va_ssids : alc269_ssids;
4656 return alc_parse_auto_config(codec, alc269_ignore, ssids);
4659 static void alc269_toggle_power_output(struct hda_codec *codec, int power_up)
4661 int val = alc_read_coef_idx(codec, 0x04);
4666 alc_write_coef_idx(codec, 0x04, val);
4669 static void alc269_shutup(struct hda_codec *codec)
4671 if ((alc_get_coef0(codec) & 0x00ff) == 0x017)
4672 alc269_toggle_power_output(codec, 0);
4673 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
4674 alc269_toggle_power_output(codec, 0);
4680 static int alc269_resume(struct hda_codec *codec)
4682 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
4683 alc269_toggle_power_output(codec, 0);
4687 codec->patch_ops.init(codec);
4689 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
4690 alc269_toggle_power_output(codec, 1);
4694 if ((alc_get_coef0(codec) & 0x00ff) == 0x018)
4695 alc269_toggle_power_output(codec, 1);
4697 snd_hda_codec_resume_amp(codec);
4698 snd_hda_codec_resume_cache(codec);
4699 hda_call_check_power_status(codec, 0x01);
4702 #endif /* CONFIG_PM */
4704 static void alc269_fixup_hweq(struct hda_codec *codec,
4705 const struct alc_fixup *fix, int action)
4709 if (action != ALC_FIXUP_ACT_INIT)
4711 coef = alc_read_coef_idx(codec, 0x1e);
4712 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
4715 static void alc271_fixup_dmic(struct hda_codec *codec,
4716 const struct alc_fixup *fix, int action)
4718 static const struct hda_verb verbs[] = {
4719 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
4720 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
4725 if (strcmp(codec->chip_name, "ALC271X"))
4727 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
4728 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
4729 snd_hda_sequence_write(codec, verbs);
4732 static void alc269_fixup_pcm_44k(struct hda_codec *codec,
4733 const struct alc_fixup *fix, int action)
4735 struct alc_spec *spec = codec->spec;
4737 if (action != ALC_FIXUP_ACT_PROBE)
4740 /* Due to a hardware problem on Lenovo Ideadpad, we need to
4741 * fix the sample rate of analog I/O to 44.1kHz
4743 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
4744 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
4747 static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
4748 const struct alc_fixup *fix, int action)
4752 if (action != ALC_FIXUP_ACT_INIT)
4754 /* The digital-mic unit sends PDM (differential signal) instead of
4755 * the standard PCM, thus you can't record a valid mono stream as is.
4756 * Below is a workaround specific to ALC269 to control the dmic
4757 * signal source as mono.
4759 coef = alc_read_coef_idx(codec, 0x07);
4760 alc_write_coef_idx(codec, 0x07, coef | 0x80);
4763 static void alc269_quanta_automute(struct hda_codec *codec)
4765 update_outputs(codec);
4767 snd_hda_codec_write(codec, 0x20, 0,
4768 AC_VERB_SET_COEF_INDEX, 0x0c);
4769 snd_hda_codec_write(codec, 0x20, 0,
4770 AC_VERB_SET_PROC_COEF, 0x680);
4772 snd_hda_codec_write(codec, 0x20, 0,
4773 AC_VERB_SET_COEF_INDEX, 0x0c);
4774 snd_hda_codec_write(codec, 0x20, 0,
4775 AC_VERB_SET_PROC_COEF, 0x480);
4778 static void alc269_fixup_quanta_mute(struct hda_codec *codec,
4779 const struct alc_fixup *fix, int action)
4781 struct alc_spec *spec = codec->spec;
4782 if (action != ALC_FIXUP_ACT_PROBE)
4784 spec->automute_hook = alc269_quanta_automute;
4788 ALC269_FIXUP_SONY_VAIO,
4789 ALC275_FIXUP_SONY_VAIO_GPIO2,
4790 ALC269_FIXUP_DELL_M101Z,
4791 ALC269_FIXUP_SKU_IGNORE,
4792 ALC269_FIXUP_ASUS_G73JW,
4793 ALC269_FIXUP_LENOVO_EAPD,
4794 ALC275_FIXUP_SONY_HWEQ,
4796 ALC269_FIXUP_PCM_44K,
4797 ALC269_FIXUP_STEREO_DMIC,
4798 ALC269_FIXUP_QUANTA_MUTE,
4799 ALC269_FIXUP_LIFEBOOK,
4802 ALC269VB_FIXUP_AMIC,
4803 ALC269VB_FIXUP_DMIC,
4806 static const struct alc_fixup alc269_fixups[] = {
4807 [ALC269_FIXUP_SONY_VAIO] = {
4808 .type = ALC_FIXUP_VERBS,
4809 .v.verbs = (const struct hda_verb[]) {
4810 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
4814 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
4815 .type = ALC_FIXUP_VERBS,
4816 .v.verbs = (const struct hda_verb[]) {
4817 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
4818 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
4819 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
4823 .chain_id = ALC269_FIXUP_SONY_VAIO
4825 [ALC269_FIXUP_DELL_M101Z] = {
4826 .type = ALC_FIXUP_VERBS,
4827 .v.verbs = (const struct hda_verb[]) {
4828 /* Enables internal speaker */
4829 {0x20, AC_VERB_SET_COEF_INDEX, 13},
4830 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
4834 [ALC269_FIXUP_SKU_IGNORE] = {
4835 .type = ALC_FIXUP_SKU,
4836 .v.sku = ALC_FIXUP_SKU_IGNORE,
4838 [ALC269_FIXUP_ASUS_G73JW] = {
4839 .type = ALC_FIXUP_PINS,
4840 .v.pins = (const struct alc_pincfg[]) {
4841 { 0x17, 0x99130111 }, /* subwoofer */
4845 [ALC269_FIXUP_LENOVO_EAPD] = {
4846 .type = ALC_FIXUP_VERBS,
4847 .v.verbs = (const struct hda_verb[]) {
4848 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
4852 [ALC275_FIXUP_SONY_HWEQ] = {
4853 .type = ALC_FIXUP_FUNC,
4854 .v.func = alc269_fixup_hweq,
4856 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
4858 [ALC271_FIXUP_DMIC] = {
4859 .type = ALC_FIXUP_FUNC,
4860 .v.func = alc271_fixup_dmic,
4862 [ALC269_FIXUP_PCM_44K] = {
4863 .type = ALC_FIXUP_FUNC,
4864 .v.func = alc269_fixup_pcm_44k,
4866 [ALC269_FIXUP_STEREO_DMIC] = {
4867 .type = ALC_FIXUP_FUNC,
4868 .v.func = alc269_fixup_stereo_dmic,
4870 [ALC269_FIXUP_QUANTA_MUTE] = {
4871 .type = ALC_FIXUP_FUNC,
4872 .v.func = alc269_fixup_quanta_mute,
4874 [ALC269_FIXUP_LIFEBOOK] = {
4875 .type = ALC_FIXUP_PINS,
4876 .v.pins = (const struct alc_pincfg[]) {
4877 { 0x1a, 0x2101103f }, /* dock line-out */
4878 { 0x1b, 0x23a11040 }, /* dock mic-in */
4882 .chain_id = ALC269_FIXUP_QUANTA_MUTE
4884 [ALC269_FIXUP_AMIC] = {
4885 .type = ALC_FIXUP_PINS,
4886 .v.pins = (const struct alc_pincfg[]) {
4887 { 0x14, 0x99130110 }, /* speaker */
4888 { 0x15, 0x0121401f }, /* HP out */
4889 { 0x18, 0x01a19c20 }, /* mic */
4890 { 0x19, 0x99a3092f }, /* int-mic */
4894 [ALC269_FIXUP_DMIC] = {
4895 .type = ALC_FIXUP_PINS,
4896 .v.pins = (const struct alc_pincfg[]) {
4897 { 0x12, 0x99a3092f }, /* int-mic */
4898 { 0x14, 0x99130110 }, /* speaker */
4899 { 0x15, 0x0121401f }, /* HP out */
4900 { 0x18, 0x01a19c20 }, /* mic */
4904 [ALC269VB_FIXUP_AMIC] = {
4905 .type = ALC_FIXUP_PINS,
4906 .v.pins = (const struct alc_pincfg[]) {
4907 { 0x14, 0x99130110 }, /* speaker */
4908 { 0x18, 0x01a19c20 }, /* mic */
4909 { 0x19, 0x99a3092f }, /* int-mic */
4910 { 0x21, 0x0121401f }, /* HP out */
4914 [ALC269_FIXUP_DMIC] = {
4915 .type = ALC_FIXUP_PINS,
4916 .v.pins = (const struct alc_pincfg[]) {
4917 { 0x12, 0x99a3092f }, /* int-mic */
4918 { 0x14, 0x99130110 }, /* speaker */
4919 { 0x18, 0x01a19c20 }, /* mic */
4920 { 0x21, 0x0121401f }, /* HP out */
4926 static const struct snd_pci_quirk alc269_fixup_tbl[] = {
4927 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
4928 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
4929 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
4930 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
4931 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
4932 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
4933 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
4934 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
4935 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
4936 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
4937 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
4938 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
4939 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
4940 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
4941 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
4942 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
4943 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
4944 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
4945 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_QUANTA_MUTE),
4946 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K),
4947 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
4950 /* Below is a quirk table taken from the old code.
4951 * Basically the device should work as is without the fixup table.
4952 * If BIOS doesn't give a proper info, enable the corresponding
4955 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
4957 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
4958 SND_PCI_QUIRK(0x1043, 0x1113, "ASUS N63Jn", ALC269_FIXUP_AMIC),
4959 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
4960 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
4961 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
4962 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
4963 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
4964 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
4965 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
4966 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
4967 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
4968 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
4969 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
4970 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
4971 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
4972 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
4973 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
4974 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
4975 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
4976 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
4977 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
4978 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
4979 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
4980 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
4981 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
4982 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
4983 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
4984 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
4985 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
4986 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
4987 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
4988 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
4989 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
4990 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
4991 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
4992 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
4993 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
4994 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
4995 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
4996 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
5001 static const struct alc_model_fixup alc269_fixup_models[] = {
5002 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
5003 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
5008 static int alc269_fill_coef(struct hda_codec *codec)
5012 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
5013 alc_write_coef_idx(codec, 0xf, 0x960b);
5014 alc_write_coef_idx(codec, 0xe, 0x8817);
5017 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
5018 alc_write_coef_idx(codec, 0xf, 0x960b);
5019 alc_write_coef_idx(codec, 0xe, 0x8814);
5022 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
5023 val = alc_read_coef_idx(codec, 0x04);
5024 /* Power up output pin */
5025 alc_write_coef_idx(codec, 0x04, val | (1<<11));
5028 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
5029 val = alc_read_coef_idx(codec, 0xd);
5030 if ((val & 0x0c00) >> 10 != 0x1) {
5031 /* Capless ramp up clock control */
5032 alc_write_coef_idx(codec, 0xd, val | (1<<10));
5034 val = alc_read_coef_idx(codec, 0x17);
5035 if ((val & 0x01c0) >> 6 != 0x4) {
5036 /* Class D power on reset */
5037 alc_write_coef_idx(codec, 0x17, val | (1<<7));
5041 val = alc_read_coef_idx(codec, 0xd); /* Class D */
5042 alc_write_coef_idx(codec, 0xd, val | (1<<14));
5044 val = alc_read_coef_idx(codec, 0x4); /* HP */
5045 alc_write_coef_idx(codec, 0x4, val | (1<<11));
5052 static int patch_alc269(struct hda_codec *codec)
5054 struct alc_spec *spec;
5057 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5063 spec->mixer_nid = 0x0b;
5065 alc_auto_parse_customize_define(codec);
5067 err = alc_codec_rename_from_preset(codec);
5071 if (codec->vendor_id == 0x10ec0269) {
5072 spec->codec_variant = ALC269_TYPE_ALC269VA;
5073 switch (alc_get_coef0(codec) & 0x00f0) {
5075 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
5076 spec->cdefine.platform_type == 1)
5077 err = alc_codec_rename(codec, "ALC271X");
5078 spec->codec_variant = ALC269_TYPE_ALC269VB;
5081 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
5082 codec->bus->pci->subsystem_device == 0x21f3)
5083 err = alc_codec_rename(codec, "ALC3202");
5084 spec->codec_variant = ALC269_TYPE_ALC269VC;
5087 alc_fix_pll_init(codec, 0x20, 0x04, 15);
5091 alc269_fill_coef(codec);
5094 alc_pick_fixup(codec, alc269_fixup_models,
5095 alc269_fixup_tbl, alc269_fixups);
5096 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5098 /* automatic parse from the BIOS config */
5099 err = alc269_parse_auto_config(codec);
5103 if (!spec->no_analog && !spec->adc_nids) {
5104 alc_auto_fill_adc_caps(codec);
5105 alc_rebuild_imux_for_auto_mic(codec);
5106 alc_remove_invalid_adc_nids(codec);
5109 if (!spec->no_analog && !spec->cap_mixer)
5110 set_capture_mixer(codec);
5112 if (!spec->no_analog && has_cdefine_beep(codec)) {
5113 err = snd_hda_attach_beep_device(codec, 0x1);
5116 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
5119 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5121 spec->vmaster_nid = 0x02;
5123 codec->patch_ops = alc_patch_ops;
5125 codec->patch_ops.resume = alc269_resume;
5127 spec->init_hook = alc_auto_init_std;
5128 spec->shutup = alc269_shutup;
5130 alc_init_jacks(codec);
5131 #ifdef CONFIG_SND_HDA_POWER_SAVE
5132 if (!spec->loopback.amplist)
5133 spec->loopback.amplist = alc269_loopbacks;
5134 if (alc269_mic2_for_mute_led(codec))
5135 codec->patch_ops.check_power_status = alc269_mic2_mute_check_ps;
5149 static int alc861_parse_auto_config(struct hda_codec *codec)
5151 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
5152 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
5153 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
5156 #ifdef CONFIG_SND_HDA_POWER_SAVE
5157 static const struct hda_amp_list alc861_loopbacks[] = {
5158 { 0x15, HDA_INPUT, 0 },
5159 { 0x15, HDA_INPUT, 1 },
5160 { 0x15, HDA_INPUT, 2 },
5161 { 0x15, HDA_INPUT, 3 },
5167 /* Pin config fixes */
5169 PINFIX_FSC_AMILO_PI1505,
5172 static const struct alc_fixup alc861_fixups[] = {
5173 [PINFIX_FSC_AMILO_PI1505] = {
5174 .type = ALC_FIXUP_PINS,
5175 .v.pins = (const struct alc_pincfg[]) {
5176 { 0x0b, 0x0221101f }, /* HP */
5177 { 0x0f, 0x90170310 }, /* speaker */
5183 static const struct snd_pci_quirk alc861_fixup_tbl[] = {
5184 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", PINFIX_FSC_AMILO_PI1505),
5190 static int patch_alc861(struct hda_codec *codec)
5192 struct alc_spec *spec;
5195 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5201 spec->mixer_nid = 0x15;
5203 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
5204 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5206 /* automatic parse from the BIOS config */
5207 err = alc861_parse_auto_config(codec);
5211 if (!spec->no_analog && !spec->adc_nids) {
5212 alc_auto_fill_adc_caps(codec);
5213 alc_rebuild_imux_for_auto_mic(codec);
5214 alc_remove_invalid_adc_nids(codec);
5217 if (!spec->no_analog && !spec->cap_mixer)
5218 set_capture_mixer(codec);
5220 if (!spec->no_analog) {
5221 err = snd_hda_attach_beep_device(codec, 0x23);
5224 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
5227 spec->vmaster_nid = 0x03;
5229 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5231 codec->patch_ops = alc_patch_ops;
5232 spec->init_hook = alc_auto_init_std;
5233 #ifdef CONFIG_SND_HDA_POWER_SAVE
5234 spec->power_hook = alc_power_eapd;
5235 if (!spec->loopback.amplist)
5236 spec->loopback.amplist = alc861_loopbacks;
5251 * In addition, an independent DAC
5253 #ifdef CONFIG_SND_HDA_POWER_SAVE
5254 #define alc861vd_loopbacks alc880_loopbacks
5257 static int alc861vd_parse_auto_config(struct hda_codec *codec)
5259 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
5260 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5261 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
5265 ALC660VD_FIX_ASUS_GPIO1,
5266 ALC861VD_FIX_DALLAS,
5269 /* exclude VREF80 */
5270 static void alc861vd_fixup_dallas(struct hda_codec *codec,
5271 const struct alc_fixup *fix, int action)
5273 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
5274 snd_hda_override_pin_caps(codec, 0x18, 0x00001714);
5275 snd_hda_override_pin_caps(codec, 0x19, 0x0000171c);
5279 static const struct alc_fixup alc861vd_fixups[] = {
5280 [ALC660VD_FIX_ASUS_GPIO1] = {
5281 .type = ALC_FIXUP_VERBS,
5282 .v.verbs = (const struct hda_verb[]) {
5284 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
5285 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5286 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5290 [ALC861VD_FIX_DALLAS] = {
5291 .type = ALC_FIXUP_FUNC,
5292 .v.func = alc861vd_fixup_dallas,
5296 static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
5297 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
5298 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
5299 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
5303 static const struct hda_verb alc660vd_eapd_verbs[] = {
5304 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
5305 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
5311 static int patch_alc861vd(struct hda_codec *codec)
5313 struct alc_spec *spec;
5316 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5322 spec->mixer_nid = 0x0b;
5324 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
5325 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5327 /* automatic parse from the BIOS config */
5328 err = alc861vd_parse_auto_config(codec);
5332 if (codec->vendor_id == 0x10ec0660) {
5333 /* always turn on EAPD */
5334 add_verb(spec, alc660vd_eapd_verbs);
5337 if (!spec->no_analog && !spec->adc_nids) {
5338 alc_auto_fill_adc_caps(codec);
5339 alc_rebuild_imux_for_auto_mic(codec);
5340 alc_remove_invalid_adc_nids(codec);
5343 if (!spec->no_analog && !spec->cap_mixer)
5344 set_capture_mixer(codec);
5346 if (!spec->no_analog) {
5347 err = snd_hda_attach_beep_device(codec, 0x23);
5350 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5353 spec->vmaster_nid = 0x02;
5355 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5357 codec->patch_ops = alc_patch_ops;
5359 spec->init_hook = alc_auto_init_std;
5360 spec->shutup = alc_eapd_shutup;
5361 #ifdef CONFIG_SND_HDA_POWER_SAVE
5362 if (!spec->loopback.amplist)
5363 spec->loopback.amplist = alc861vd_loopbacks;
5376 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
5377 * configuration. Each pin widget can choose any input DACs and a mixer.
5378 * Each ADC is connected from a mixer of all inputs. This makes possible
5379 * 6-channel independent captures.
5381 * In addition, an independent DAC for the multi-playback (not used in this
5384 #ifdef CONFIG_SND_HDA_POWER_SAVE
5385 #define alc662_loopbacks alc880_loopbacks
5389 * BIOS auto configuration
5392 static int alc662_parse_auto_config(struct hda_codec *codec)
5394 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
5395 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
5396 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5397 const hda_nid_t *ssids;
5399 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
5400 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
5401 ssids = alc663_ssids;
5403 ssids = alc662_ssids;
5404 return alc_parse_auto_config(codec, alc662_ignore, ssids);
5407 static void alc272_fixup_mario(struct hda_codec *codec,
5408 const struct alc_fixup *fix, int action)
5410 if (action != ALC_FIXUP_ACT_PROBE)
5412 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
5413 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
5414 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
5415 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5416 (0 << AC_AMPCAP_MUTE_SHIFT)))
5418 "hda_codec: failed to override amp caps for NID 0x2\n");
5422 ALC662_FIXUP_ASPIRE,
5423 ALC662_FIXUP_IDEAPAD,
5425 ALC662_FIXUP_CZC_P10T,
5426 ALC662_FIXUP_SKU_IGNORE,
5427 ALC662_FIXUP_HP_RP5800,
5428 ALC662_FIXUP_ASUS_MODE1,
5429 ALC662_FIXUP_ASUS_MODE2,
5430 ALC662_FIXUP_ASUS_MODE3,
5431 ALC662_FIXUP_ASUS_MODE4,
5432 ALC662_FIXUP_ASUS_MODE5,
5433 ALC662_FIXUP_ASUS_MODE6,
5434 ALC662_FIXUP_ASUS_MODE7,
5435 ALC662_FIXUP_ASUS_MODE8,
5438 static const struct alc_fixup alc662_fixups[] = {
5439 [ALC662_FIXUP_ASPIRE] = {
5440 .type = ALC_FIXUP_PINS,
5441 .v.pins = (const struct alc_pincfg[]) {
5442 { 0x15, 0x99130112 }, /* subwoofer */
5446 [ALC662_FIXUP_IDEAPAD] = {
5447 .type = ALC_FIXUP_PINS,
5448 .v.pins = (const struct alc_pincfg[]) {
5449 { 0x17, 0x99130112 }, /* subwoofer */
5453 [ALC272_FIXUP_MARIO] = {
5454 .type = ALC_FIXUP_FUNC,
5455 .v.func = alc272_fixup_mario,
5457 [ALC662_FIXUP_CZC_P10T] = {
5458 .type = ALC_FIXUP_VERBS,
5459 .v.verbs = (const struct hda_verb[]) {
5460 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
5464 [ALC662_FIXUP_SKU_IGNORE] = {
5465 .type = ALC_FIXUP_SKU,
5466 .v.sku = ALC_FIXUP_SKU_IGNORE,
5468 [ALC662_FIXUP_HP_RP5800] = {
5469 .type = ALC_FIXUP_PINS,
5470 .v.pins = (const struct alc_pincfg[]) {
5471 { 0x14, 0x0221201f }, /* HP out */
5475 .chain_id = ALC662_FIXUP_SKU_IGNORE
5477 [ALC662_FIXUP_ASUS_MODE1] = {
5478 .type = ALC_FIXUP_PINS,
5479 .v.pins = (const struct alc_pincfg[]) {
5480 { 0x14, 0x99130110 }, /* speaker */
5481 { 0x18, 0x01a19c20 }, /* mic */
5482 { 0x19, 0x99a3092f }, /* int-mic */
5483 { 0x21, 0x0121401f }, /* HP out */
5487 .chain_id = ALC662_FIXUP_SKU_IGNORE
5489 [ALC662_FIXUP_ASUS_MODE2] = {
5490 .type = ALC_FIXUP_PINS,
5491 .v.pins = (const struct alc_pincfg[]) {
5492 { 0x14, 0x99130110 }, /* speaker */
5493 { 0x18, 0x01a19820 }, /* mic */
5494 { 0x19, 0x99a3092f }, /* int-mic */
5495 { 0x1b, 0x0121401f }, /* HP out */
5499 .chain_id = ALC662_FIXUP_SKU_IGNORE
5501 [ALC662_FIXUP_ASUS_MODE3] = {
5502 .type = ALC_FIXUP_PINS,
5503 .v.pins = (const struct alc_pincfg[]) {
5504 { 0x14, 0x99130110 }, /* speaker */
5505 { 0x15, 0x0121441f }, /* HP */
5506 { 0x18, 0x01a19840 }, /* mic */
5507 { 0x19, 0x99a3094f }, /* int-mic */
5508 { 0x21, 0x01211420 }, /* HP2 */
5512 .chain_id = ALC662_FIXUP_SKU_IGNORE
5514 [ALC662_FIXUP_ASUS_MODE4] = {
5515 .type = ALC_FIXUP_PINS,
5516 .v.pins = (const struct alc_pincfg[]) {
5517 { 0x14, 0x99130110 }, /* speaker */
5518 { 0x16, 0x99130111 }, /* speaker */
5519 { 0x18, 0x01a19840 }, /* mic */
5520 { 0x19, 0x99a3094f }, /* int-mic */
5521 { 0x21, 0x0121441f }, /* HP */
5525 .chain_id = ALC662_FIXUP_SKU_IGNORE
5527 [ALC662_FIXUP_ASUS_MODE5] = {
5528 .type = ALC_FIXUP_PINS,
5529 .v.pins = (const struct alc_pincfg[]) {
5530 { 0x14, 0x99130110 }, /* speaker */
5531 { 0x15, 0x0121441f }, /* HP */
5532 { 0x16, 0x99130111 }, /* speaker */
5533 { 0x18, 0x01a19840 }, /* mic */
5534 { 0x19, 0x99a3094f }, /* int-mic */
5538 .chain_id = ALC662_FIXUP_SKU_IGNORE
5540 [ALC662_FIXUP_ASUS_MODE6] = {
5541 .type = ALC_FIXUP_PINS,
5542 .v.pins = (const struct alc_pincfg[]) {
5543 { 0x14, 0x99130110 }, /* speaker */
5544 { 0x15, 0x01211420 }, /* HP2 */
5545 { 0x18, 0x01a19840 }, /* mic */
5546 { 0x19, 0x99a3094f }, /* int-mic */
5547 { 0x1b, 0x0121441f }, /* HP */
5551 .chain_id = ALC662_FIXUP_SKU_IGNORE
5553 [ALC662_FIXUP_ASUS_MODE7] = {
5554 .type = ALC_FIXUP_PINS,
5555 .v.pins = (const struct alc_pincfg[]) {
5556 { 0x14, 0x99130110 }, /* speaker */
5557 { 0x17, 0x99130111 }, /* speaker */
5558 { 0x18, 0x01a19840 }, /* mic */
5559 { 0x19, 0x99a3094f }, /* int-mic */
5560 { 0x1b, 0x01214020 }, /* HP */
5561 { 0x21, 0x0121401f }, /* HP */
5565 .chain_id = ALC662_FIXUP_SKU_IGNORE
5567 [ALC662_FIXUP_ASUS_MODE8] = {
5568 .type = ALC_FIXUP_PINS,
5569 .v.pins = (const struct alc_pincfg[]) {
5570 { 0x14, 0x99130110 }, /* speaker */
5571 { 0x12, 0x99a30970 }, /* int-mic */
5572 { 0x15, 0x01214020 }, /* HP */
5573 { 0x17, 0x99130111 }, /* speaker */
5574 { 0x18, 0x01a19840 }, /* mic */
5575 { 0x21, 0x0121401f }, /* HP */
5579 .chain_id = ALC662_FIXUP_SKU_IGNORE
5583 static const struct snd_pci_quirk alc662_fixup_tbl[] = {
5584 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
5585 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
5586 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
5587 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
5588 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
5589 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
5590 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
5591 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
5592 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
5593 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
5596 /* Below is a quirk table taken from the old code.
5597 * Basically the device should work as is without the fixup table.
5598 * If BIOS doesn't give a proper info, enable the corresponding
5601 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
5602 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
5603 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
5604 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
5605 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
5606 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5607 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
5608 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
5609 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
5610 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5611 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
5612 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
5613 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
5614 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
5615 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
5616 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5617 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
5618 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
5619 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5620 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
5621 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
5622 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5623 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
5624 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
5625 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
5626 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5627 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
5628 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
5629 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5630 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
5631 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5632 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5633 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
5634 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
5635 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
5636 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
5637 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
5638 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
5639 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
5640 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5641 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
5642 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
5643 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
5644 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
5645 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
5646 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
5647 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
5648 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
5649 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
5650 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
5655 static const struct alc_model_fixup alc662_fixup_models[] = {
5656 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
5657 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
5658 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
5659 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
5660 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
5661 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
5662 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
5663 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
5664 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
5671 static int patch_alc662(struct hda_codec *codec)
5673 struct alc_spec *spec;
5676 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5682 spec->mixer_nid = 0x0b;
5684 /* handle multiple HPs as is */
5685 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
5687 alc_auto_parse_customize_define(codec);
5689 alc_fix_pll_init(codec, 0x20, 0x04, 15);
5691 err = alc_codec_rename_from_preset(codec);
5695 if ((alc_get_coef0(codec) & (1 << 14)) &&
5696 codec->bus->pci->subsystem_vendor == 0x1025 &&
5697 spec->cdefine.platform_type == 1) {
5698 if (alc_codec_rename(codec, "ALC272X") < 0)
5702 alc_pick_fixup(codec, alc662_fixup_models,
5703 alc662_fixup_tbl, alc662_fixups);
5704 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5705 /* automatic parse from the BIOS config */
5706 err = alc662_parse_auto_config(codec);
5710 if (!spec->no_analog && !spec->adc_nids) {
5711 alc_auto_fill_adc_caps(codec);
5712 alc_rebuild_imux_for_auto_mic(codec);
5713 alc_remove_invalid_adc_nids(codec);
5716 if (!spec->no_analog && !spec->cap_mixer)
5717 set_capture_mixer(codec);
5719 if (!spec->no_analog && has_cdefine_beep(codec)) {
5720 err = snd_hda_attach_beep_device(codec, 0x1);
5723 switch (codec->vendor_id) {
5725 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5730 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
5733 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
5737 spec->vmaster_nid = 0x02;
5739 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5741 codec->patch_ops = alc_patch_ops;
5742 spec->init_hook = alc_auto_init_std;
5743 spec->shutup = alc_eapd_shutup;
5745 alc_init_jacks(codec);
5747 #ifdef CONFIG_SND_HDA_POWER_SAVE
5748 if (!spec->loopback.amplist)
5749 spec->loopback.amplist = alc662_loopbacks;
5763 static int alc680_parse_auto_config(struct hda_codec *codec)
5765 return alc_parse_auto_config(codec, NULL, NULL);
5770 static int patch_alc680(struct hda_codec *codec)
5772 struct alc_spec *spec;
5775 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5781 /* ALC680 has no aa-loopback mixer */
5783 /* automatic parse from the BIOS config */
5784 err = alc680_parse_auto_config(codec);
5790 if (!spec->no_analog && !spec->cap_mixer)
5791 set_capture_mixer(codec);
5793 spec->vmaster_nid = 0x02;
5795 codec->patch_ops = alc_patch_ops;
5796 spec->init_hook = alc_auto_init_std;
5804 static const struct hda_codec_preset snd_hda_preset_realtek[] = {
5805 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
5806 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
5807 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
5808 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
5809 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
5810 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
5811 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
5812 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
5813 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
5814 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
5815 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
5816 .patch = patch_alc861 },
5817 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
5818 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
5819 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
5820 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
5821 .patch = patch_alc882 },
5822 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
5823 .patch = patch_alc662 },
5824 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
5825 .patch = patch_alc662 },
5826 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
5827 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
5828 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
5829 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
5830 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
5831 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
5832 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
5833 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
5834 .patch = patch_alc882 },
5835 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
5836 .patch = patch_alc882 },
5837 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
5838 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
5839 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
5840 .patch = patch_alc882 },
5841 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
5842 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
5843 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
5844 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
5848 MODULE_ALIAS("snd-hda-codec-id:10ec*");
5850 MODULE_LICENSE("GPL");
5851 MODULE_DESCRIPTION("Realtek HD-audio codec");
5853 static struct hda_codec_preset_list realtek_list = {
5854 .preset = snd_hda_preset_realtek,
5855 .owner = THIS_MODULE,
5858 static int __init patch_realtek_init(void)
5860 return snd_hda_add_codec_preset(&realtek_list);
5863 static void __exit patch_realtek_exit(void)
5865 snd_hda_delete_codec_preset(&realtek_list);
5868 module_init(patch_realtek_init)
5869 module_exit(patch_realtek_exit)