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 <linux/module.h>
31 #include <sound/core.h>
32 #include <sound/jack.h>
33 #include "hda_codec.h"
34 #include "hda_local.h"
38 /* unsol event tags */
39 #define ALC_FRONT_EVENT 0x01
40 #define ALC_DCVOL_EVENT 0x02
41 #define ALC_HP_EVENT 0x04
42 #define ALC_MIC_EVENT 0x08
45 #define GPIO_MASK 0x03
47 /* extra amp-initialization sequence types */
56 struct alc_customize_define {
58 unsigned char port_connectivity;
59 unsigned char check_sum;
60 unsigned char customization;
61 unsigned char external_amp;
62 unsigned int enable_pcbeep:1;
63 unsigned int platform_type:1;
65 unsigned int override:1;
66 unsigned int fixup:1; /* Means that this sku is set by driver, not read from hw */
72 hda_nid_t pin; /* multi-io widget pin NID */
73 hda_nid_t dac; /* DAC to be connected */
74 unsigned int ctl_in; /* cached input-pin control value */
78 ALC_AUTOMUTE_PIN, /* change the pin control */
79 ALC_AUTOMUTE_AMP, /* mute/unmute the pin AMP */
80 ALC_AUTOMUTE_MIXER, /* mute/unmute mixer widget AMP */
83 #define MAX_VOL_NIDS 0x40
86 /* codec parameterization */
87 const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */
88 unsigned int num_mixers;
89 const struct snd_kcontrol_new *cap_mixer; /* capture mixer */
90 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
92 const struct hda_verb *init_verbs[10]; /* initialization verbs
96 unsigned int num_init_verbs;
98 char stream_name_analog[32]; /* analog PCM stream */
99 const struct hda_pcm_stream *stream_analog_playback;
100 const struct hda_pcm_stream *stream_analog_capture;
101 const struct hda_pcm_stream *stream_analog_alt_playback;
102 const struct hda_pcm_stream *stream_analog_alt_capture;
104 char stream_name_digital[32]; /* digital PCM stream */
105 const struct hda_pcm_stream *stream_digital_playback;
106 const struct hda_pcm_stream *stream_digital_capture;
109 struct hda_multi_out multiout; /* playback set-up
110 * max_channels, dacs must be set
111 * dig_out_nid and hp_nid are optional
113 hda_nid_t alt_dac_nid;
114 hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */
118 unsigned int num_adc_nids;
119 const hda_nid_t *adc_nids;
120 const hda_nid_t *capsrc_nids;
121 hda_nid_t dig_in_nid; /* digital-in NID; optional */
122 hda_nid_t mixer_nid; /* analog-mixer NID */
123 DECLARE_BITMAP(vol_ctls, MAX_VOL_NIDS << 1);
124 DECLARE_BITMAP(sw_ctls, MAX_VOL_NIDS << 1);
126 /* capture setup for dynamic dual-adc switch */
128 unsigned int cur_adc_stream_tag;
129 unsigned int cur_adc_format;
132 unsigned int num_mux_defs;
133 const struct hda_input_mux *input_mux;
134 unsigned int cur_mux[3];
135 hda_nid_t ext_mic_pin;
136 hda_nid_t dock_mic_pin;
137 hda_nid_t int_mic_pin;
140 const struct hda_channel_mode *channel_mode;
141 int num_channel_mode;
143 int const_channel_count;
144 int ext_channel_count;
146 /* PCM information */
147 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
149 /* dynamic controls, init_verbs and input_mux */
150 struct auto_pin_cfg autocfg;
151 struct alc_customize_define cdefine;
152 struct snd_array kctls;
153 struct hda_input_mux private_imux[3];
154 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
155 hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS];
156 hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS];
157 hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS];
158 unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS];
159 int int_mic_idx, ext_mic_idx, dock_mic_idx; /* for auto-mic */
162 void (*init_hook)(struct hda_codec *codec);
163 void (*unsol_event)(struct hda_codec *codec, unsigned int res);
164 #ifdef CONFIG_SND_HDA_POWER_SAVE
165 void (*power_hook)(struct hda_codec *codec);
167 void (*shutup)(struct hda_codec *codec);
168 void (*automute_hook)(struct hda_codec *codec);
170 /* for pin sensing */
171 unsigned int hp_jack_present:1;
172 unsigned int line_jack_present:1;
173 unsigned int master_mute:1;
174 unsigned int auto_mic:1;
175 unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */
176 unsigned int automute_speaker:1; /* automute speaker outputs */
177 unsigned int automute_lo:1; /* automute LO outputs */
178 unsigned int detect_hp:1; /* Headphone detection enabled */
179 unsigned int detect_lo:1; /* Line-out detection enabled */
180 unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */
181 unsigned int automute_lo_possible:1; /* there are line outs and HP */
182 unsigned int keep_vref_in_automute:1; /* Don't clear VREF in automute */
185 unsigned int no_analog :1; /* digital I/O only */
186 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
187 unsigned int single_input_src:1;
188 unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */
189 unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */
191 /* auto-mute control */
193 hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS];
196 int codec_variant; /* flag for other variants */
198 /* for virtual master */
199 hda_nid_t vmaster_nid;
200 #ifdef CONFIG_SND_HDA_POWER_SAVE
201 struct hda_loopback_check loopback;
206 unsigned int pll_coef_idx, pll_coef_bit;
211 const struct alc_fixup *fixup_list;
212 const char *fixup_name;
216 struct alc_multi_io multi_io[4];
219 struct snd_array bind_ctls;
222 #define ALC_MODEL_AUTO 0 /* common for all chips */
224 static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
225 int dir, unsigned int bits)
229 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
230 if (query_amp_caps(codec, nid, dir) & bits)
235 #define nid_has_mute(codec, nid, dir) \
236 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
237 #define nid_has_volume(codec, nid, dir) \
238 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
243 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
244 struct snd_ctl_elem_info *uinfo)
246 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
247 struct alc_spec *spec = codec->spec;
248 unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
249 if (mux_idx >= spec->num_mux_defs)
251 if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
253 return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
256 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
257 struct snd_ctl_elem_value *ucontrol)
259 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
260 struct alc_spec *spec = codec->spec;
261 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
263 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
267 static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
269 struct alc_spec *spec = codec->spec;
270 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
272 if (spec->cur_adc && spec->cur_adc != new_adc) {
273 /* stream is running, let's swap the current ADC */
274 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
275 spec->cur_adc = new_adc;
276 snd_hda_codec_setup_stream(codec, new_adc,
277 spec->cur_adc_stream_tag, 0,
278 spec->cur_adc_format);
284 static inline hda_nid_t get_capsrc(struct alc_spec *spec, int idx)
286 return spec->capsrc_nids ?
287 spec->capsrc_nids[idx] : spec->adc_nids[idx];
290 /* select the given imux item; either unmute exclusively or select the route */
291 static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
292 unsigned int idx, bool force)
294 struct alc_spec *spec = codec->spec;
295 const struct hda_input_mux *imux;
296 unsigned int mux_idx;
297 int i, type, num_conns;
300 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
301 imux = &spec->input_mux[mux_idx];
302 if (!imux->num_items && mux_idx > 0)
303 imux = &spec->input_mux[0];
304 if (!imux->num_items)
307 if (idx >= imux->num_items)
308 idx = imux->num_items - 1;
309 if (spec->cur_mux[adc_idx] == idx && !force)
311 spec->cur_mux[adc_idx] = idx;
313 if (spec->dyn_adc_switch) {
314 alc_dyn_adc_pcm_resetup(codec, idx);
315 adc_idx = spec->dyn_adc_idx[idx];
318 nid = get_capsrc(spec, adc_idx);
321 num_conns = snd_hda_get_conn_list(codec, nid, NULL);
325 type = get_wcaps_type(get_wcaps(codec, nid));
326 if (type == AC_WID_AUD_MIX) {
327 /* Matrix-mixer style (e.g. ALC882) */
328 int active = imux->items[idx].index;
329 for (i = 0; i < num_conns; i++) {
330 unsigned int v = (i == active) ? 0 : HDA_AMP_MUTE;
331 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, i,
335 /* MUX style (e.g. ALC880) */
336 snd_hda_codec_write_cache(codec, nid, 0,
337 AC_VERB_SET_CONNECT_SEL,
338 imux->items[idx].index);
343 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
344 struct snd_ctl_elem_value *ucontrol)
346 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
347 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
348 return alc_mux_select(codec, adc_idx,
349 ucontrol->value.enumerated.item[0], false);
353 * set up the input pin config (depending on the given auto-pin type)
355 static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
358 unsigned int val = PIN_IN;
360 if (auto_pin_type == AUTO_PIN_MIC) {
363 oldval = snd_hda_codec_read(codec, nid, 0,
364 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
365 pincap = snd_hda_query_pin_caps(codec, nid);
366 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
367 /* if the default pin setup is vref50, we give it priority */
368 if ((pincap & AC_PINCAP_VREF_80) && oldval != PIN_VREF50)
370 else if (pincap & AC_PINCAP_VREF_50)
372 else if (pincap & AC_PINCAP_VREF_100)
374 else if (pincap & AC_PINCAP_VREF_GRD)
377 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val);
381 * Append the given mixer and verb elements for the later use
382 * The mixer array is referred in build_controls(), and init_verbs are
385 static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
387 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
389 spec->mixers[spec->num_mixers++] = mix;
392 static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
394 if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
396 spec->init_verbs[spec->num_init_verbs++] = verb;
400 * GPIO setup tables, used in initialization
402 /* Enable GPIO mask and set output */
403 static const struct hda_verb alc_gpio1_init_verbs[] = {
404 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
405 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
406 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
410 static const struct hda_verb alc_gpio2_init_verbs[] = {
411 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
412 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
413 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
417 static const struct hda_verb alc_gpio3_init_verbs[] = {
418 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
419 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
420 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
425 * Fix hardware PLL issue
426 * On some codecs, the analog PLL gating control must be off while
427 * the default value is 1.
429 static void alc_fix_pll(struct hda_codec *codec)
431 struct alc_spec *spec = codec->spec;
436 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
438 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
439 AC_VERB_GET_PROC_COEF, 0);
440 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
442 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
443 val & ~(1 << spec->pll_coef_bit));
446 static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
447 unsigned int coef_idx, unsigned int coef_bit)
449 struct alc_spec *spec = codec->spec;
451 spec->pll_coef_idx = coef_idx;
452 spec->pll_coef_bit = coef_bit;
457 * Jack detections for HP auto-mute and mic-switch
460 /* check each pin in the given array; returns true if any of them is plugged */
461 static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
465 for (i = 0; i < num_pins; i++) {
466 hda_nid_t nid = pins[i];
469 present |= snd_hda_jack_detect(codec, nid);
474 /* standard HP/line-out auto-mute helper */
475 static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
476 bool mute, bool hp_out)
478 struct alc_spec *spec = codec->spec;
479 unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0;
480 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
483 for (i = 0; i < num_pins; i++) {
484 hda_nid_t nid = pins[i];
488 switch (spec->automute_mode) {
489 case ALC_AUTOMUTE_PIN:
490 /* don't reset VREF value in case it's controlling
491 * the amp (see alc861_fixup_asus_amp_vref_0f())
493 if (spec->keep_vref_in_automute) {
494 val = snd_hda_codec_read(codec, nid, 0,
495 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
500 snd_hda_codec_write(codec, nid, 0,
501 AC_VERB_SET_PIN_WIDGET_CONTROL,
504 case ALC_AUTOMUTE_AMP:
505 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
506 HDA_AMP_MUTE, mute_bits);
508 case ALC_AUTOMUTE_MIXER:
509 nid = spec->automute_mixer_nid[i];
512 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
513 HDA_AMP_MUTE, mute_bits);
514 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1,
515 HDA_AMP_MUTE, mute_bits);
521 /* Toggle outputs muting */
522 static void update_outputs(struct hda_codec *codec)
524 struct alc_spec *spec = codec->spec;
527 /* Control HP pins/amps depending on master_mute state;
528 * in general, HP pins/amps control should be enabled in all cases,
529 * but currently set only for master_mute, just to be safe
531 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
532 spec->autocfg.hp_pins, spec->master_mute, true);
534 if (!spec->automute_speaker)
537 on = spec->hp_jack_present | spec->line_jack_present;
538 on |= spec->master_mute;
539 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
540 spec->autocfg.speaker_pins, on, false);
542 /* toggle line-out mutes if needed, too */
543 /* if LO is a copy of either HP or Speaker, don't need to handle it */
544 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
545 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
547 if (!spec->automute_lo)
550 on = spec->hp_jack_present;
551 on |= spec->master_mute;
552 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
553 spec->autocfg.line_out_pins, on, false);
556 static void call_update_outputs(struct hda_codec *codec)
558 struct alc_spec *spec = codec->spec;
559 if (spec->automute_hook)
560 spec->automute_hook(codec);
562 update_outputs(codec);
565 /* standard HP-automute helper */
566 static void alc_hp_automute(struct hda_codec *codec)
568 struct alc_spec *spec = codec->spec;
570 spec->hp_jack_present =
571 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
572 spec->autocfg.hp_pins);
573 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
575 call_update_outputs(codec);
578 /* standard line-out-automute helper */
579 static void alc_line_automute(struct hda_codec *codec)
581 struct alc_spec *spec = codec->spec;
583 /* check LO jack only when it's different from HP */
584 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
587 spec->line_jack_present =
588 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
589 spec->autocfg.line_out_pins);
590 if (!spec->automute_speaker || !spec->detect_lo)
592 call_update_outputs(codec);
595 #define get_connection_index(codec, mux, nid) \
596 snd_hda_get_conn_index(codec, mux, nid, 0)
598 /* standard mic auto-switch helper */
599 static void alc_mic_automute(struct hda_codec *codec)
601 struct alc_spec *spec = codec->spec;
602 hda_nid_t *pins = spec->imux_pins;
604 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
606 if (snd_BUG_ON(!spec->adc_nids))
608 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
611 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
612 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
613 else if (spec->dock_mic_idx >= 0 &&
614 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
615 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
617 alc_mux_select(codec, 0, spec->int_mic_idx, false);
620 /* handle the specified unsol action (ALC_XXX_EVENT) */
621 static void alc_exec_unsol_event(struct hda_codec *codec, int action)
625 alc_hp_automute(codec);
627 case ALC_FRONT_EVENT:
628 alc_line_automute(codec);
631 alc_mic_automute(codec);
634 snd_hda_jack_report_sync(codec);
637 /* unsolicited event for HP jack sensing */
638 static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
640 struct alc_spec *spec = codec->spec;
641 if (codec->vendor_id == 0x10ec0880)
645 res = snd_hda_jack_get_action(codec, res);
646 alc_exec_unsol_event(codec, res);
649 /* call init functions of standard auto-mute helpers */
650 static void alc_inithook(struct hda_codec *codec)
652 alc_hp_automute(codec);
653 alc_line_automute(codec);
654 alc_mic_automute(codec);
657 /* additional initialization for ALC888 variants */
658 static void alc888_coef_init(struct hda_codec *codec)
662 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
663 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
664 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
665 if ((tmp & 0xf0) == 0x20)
667 snd_hda_codec_read(codec, 0x20, 0,
668 AC_VERB_SET_PROC_COEF, 0x830);
671 snd_hda_codec_read(codec, 0x20, 0,
672 AC_VERB_SET_PROC_COEF, 0x3030);
675 /* additional initialization for ALC889 variants */
676 static void alc889_coef_init(struct hda_codec *codec)
680 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
681 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
682 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
683 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
686 /* turn on/off EAPD control (only if available) */
687 static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
689 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
691 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
692 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
696 /* turn on/off EAPD controls of the codec */
697 static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
699 /* We currently only handle front, HP */
700 static hda_nid_t pins[] = {
701 0x0f, 0x10, 0x14, 0x15, 0
704 for (p = pins; *p; p++)
705 set_eapd(codec, *p, on);
708 /* generic shutup callback;
709 * just turning off EPAD and a little pause for avoiding pop-noise
711 static void alc_eapd_shutup(struct hda_codec *codec)
713 alc_auto_setup_eapd(codec, false);
717 /* generic EAPD initialization */
718 static void alc_auto_init_amp(struct hda_codec *codec, int type)
722 alc_auto_setup_eapd(codec, true);
725 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
728 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
731 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
733 case ALC_INIT_DEFAULT:
734 switch (codec->vendor_id) {
736 snd_hda_codec_write(codec, 0x1a, 0,
737 AC_VERB_SET_COEF_INDEX, 7);
738 tmp = snd_hda_codec_read(codec, 0x1a, 0,
739 AC_VERB_GET_PROC_COEF, 0);
740 snd_hda_codec_write(codec, 0x1a, 0,
741 AC_VERB_SET_COEF_INDEX, 7);
742 snd_hda_codec_write(codec, 0x1a, 0,
743 AC_VERB_SET_PROC_COEF,
752 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
753 alc889_coef_init(codec);
756 alc888_coef_init(codec);
758 #if 0 /* XXX: This may cause the silent output on speaker on some machines */
761 snd_hda_codec_write(codec, 0x20, 0,
762 AC_VERB_SET_COEF_INDEX, 7);
763 tmp = snd_hda_codec_read(codec, 0x20, 0,
764 AC_VERB_GET_PROC_COEF, 0);
765 snd_hda_codec_write(codec, 0x20, 0,
766 AC_VERB_SET_COEF_INDEX, 7);
767 snd_hda_codec_write(codec, 0x20, 0,
768 AC_VERB_SET_PROC_COEF,
778 * Auto-Mute mode mixer enum support
780 static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
781 struct snd_ctl_elem_info *uinfo)
783 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
784 struct alc_spec *spec = codec->spec;
785 static const char * const texts2[] = {
786 "Disabled", "Enabled"
788 static const char * const texts3[] = {
789 "Disabled", "Speaker Only", "Line-Out+Speaker"
791 const char * const *texts;
793 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
795 if (spec->automute_speaker_possible && spec->automute_lo_possible) {
796 uinfo->value.enumerated.items = 3;
799 uinfo->value.enumerated.items = 2;
802 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
803 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
804 strcpy(uinfo->value.enumerated.name,
805 texts[uinfo->value.enumerated.item]);
809 static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
810 struct snd_ctl_elem_value *ucontrol)
812 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
813 struct alc_spec *spec = codec->spec;
814 unsigned int val = 0;
815 if (spec->automute_speaker)
817 if (spec->automute_lo)
820 ucontrol->value.enumerated.item[0] = val;
824 static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
825 struct snd_ctl_elem_value *ucontrol)
827 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
828 struct alc_spec *spec = codec->spec;
830 switch (ucontrol->value.enumerated.item[0]) {
832 if (!spec->automute_speaker && !spec->automute_lo)
834 spec->automute_speaker = 0;
835 spec->automute_lo = 0;
838 if (spec->automute_speaker_possible) {
839 if (!spec->automute_lo && spec->automute_speaker)
841 spec->automute_speaker = 1;
842 spec->automute_lo = 0;
843 } else if (spec->automute_lo_possible) {
844 if (spec->automute_lo)
846 spec->automute_lo = 1;
851 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
853 if (spec->automute_speaker && spec->automute_lo)
855 spec->automute_speaker = 1;
856 spec->automute_lo = 1;
861 call_update_outputs(codec);
865 static const struct snd_kcontrol_new alc_automute_mode_enum = {
866 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
867 .name = "Auto-Mute Mode",
868 .info = alc_automute_mode_info,
869 .get = alc_automute_mode_get,
870 .put = alc_automute_mode_put,
873 static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec)
875 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
876 return snd_array_new(&spec->kctls);
879 static int alc_add_automute_mode_enum(struct hda_codec *codec)
881 struct alc_spec *spec = codec->spec;
882 struct snd_kcontrol_new *knew;
884 knew = alc_kcontrol_new(spec);
887 *knew = alc_automute_mode_enum;
888 knew->name = kstrdup("Auto-Mute Mode", GFP_KERNEL);
895 * Check the availability of HP/line-out auto-mute;
896 * Set up appropriately if really supported
898 static void alc_init_automute(struct hda_codec *codec)
900 struct alc_spec *spec = codec->spec;
901 struct auto_pin_cfg *cfg = &spec->autocfg;
907 if (cfg->line_out_pins[0])
909 if (cfg->speaker_pins[0])
911 if (present < 2) /* need two different output types */
914 if (!cfg->speaker_pins[0] &&
915 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
916 memcpy(cfg->speaker_pins, cfg->line_out_pins,
917 sizeof(cfg->speaker_pins));
918 cfg->speaker_outs = cfg->line_outs;
921 if (!cfg->hp_pins[0] &&
922 cfg->line_out_type == AUTO_PIN_HP_OUT) {
923 memcpy(cfg->hp_pins, cfg->line_out_pins,
924 sizeof(cfg->hp_pins));
925 cfg->hp_outs = cfg->line_outs;
928 spec->automute_mode = ALC_AUTOMUTE_PIN;
930 for (i = 0; i < cfg->hp_outs; i++) {
931 hda_nid_t nid = cfg->hp_pins[i];
932 if (!is_jack_detectable(codec, nid))
934 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
936 snd_hda_jack_detect_enable(codec, nid, ALC_HP_EVENT);
940 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
941 if (cfg->speaker_outs)
942 for (i = 0; i < cfg->line_outs; i++) {
943 hda_nid_t nid = cfg->line_out_pins[i];
944 if (!is_jack_detectable(codec, nid))
946 snd_printdd("realtek: Enable Line-Out "
947 "auto-muting on NID 0x%x\n", nid);
948 snd_hda_jack_detect_enable(codec, nid,
952 spec->automute_lo_possible = spec->detect_hp;
955 spec->automute_speaker_possible = cfg->speaker_outs &&
956 (spec->detect_hp || spec->detect_lo);
958 spec->automute_lo = spec->automute_lo_possible;
959 spec->automute_speaker = spec->automute_speaker_possible;
961 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
962 /* create a control for automute mode */
963 alc_add_automute_mode_enum(codec);
964 spec->unsol_event = alc_sku_unsol_event;
968 /* return the position of NID in the list, or -1 if not found */
969 static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
972 for (i = 0; i < nums; i++)
978 /* check whether dynamic ADC-switching is available */
979 static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
981 struct alc_spec *spec = codec->spec;
982 struct hda_input_mux *imux = &spec->private_imux[0];
986 if (imux != spec->input_mux) /* no dynamic imux? */
989 for (n = 0; n < spec->num_adc_nids; n++) {
990 cap = spec->private_capsrc_nids[n];
991 for (i = 0; i < imux->num_items; i++) {
992 pin = spec->imux_pins[i];
995 if (get_connection_index(codec, cap, pin) < 0)
998 if (i >= imux->num_items)
999 return true; /* no ADC-switch is needed */
1002 for (i = 0; i < imux->num_items; i++) {
1003 pin = spec->imux_pins[i];
1004 for (n = 0; n < spec->num_adc_nids; n++) {
1005 cap = spec->private_capsrc_nids[n];
1006 idx = get_connection_index(codec, cap, pin);
1008 imux->items[i].index = idx;
1009 spec->dyn_adc_idx[i] = n;
1015 snd_printdd("realtek: enabling ADC switching\n");
1016 spec->dyn_adc_switch = 1;
1020 /* rebuild imux for matching with the given auto-mic pins (if not yet) */
1021 static bool alc_rebuild_imux_for_auto_mic(struct hda_codec *codec)
1023 struct alc_spec *spec = codec->spec;
1024 struct hda_input_mux *imux;
1025 static char * const texts[3] = {
1026 "Mic", "Internal Mic", "Dock Mic"
1030 if (!spec->auto_mic)
1032 imux = &spec->private_imux[0];
1033 if (spec->input_mux == imux)
1035 spec->imux_pins[0] = spec->ext_mic_pin;
1036 spec->imux_pins[1] = spec->int_mic_pin;
1037 spec->imux_pins[2] = spec->dock_mic_pin;
1038 for (i = 0; i < 3; i++) {
1039 strcpy(imux->items[i].label, texts[i]);
1040 if (spec->imux_pins[i]) {
1041 hda_nid_t pin = spec->imux_pins[i];
1043 for (c = 0; c < spec->num_adc_nids; c++) {
1044 hda_nid_t cap = get_capsrc(spec, c);
1045 int idx = get_connection_index(codec, cap, pin);
1047 imux->items[i].index = idx;
1051 imux->num_items = i + 1;
1054 spec->num_mux_defs = 1;
1055 spec->input_mux = imux;
1059 /* check whether all auto-mic pins are valid; setup indices if OK */
1060 static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1062 struct alc_spec *spec = codec->spec;
1063 const struct hda_input_mux *imux;
1065 if (!spec->auto_mic)
1067 if (spec->auto_mic_valid_imux)
1068 return true; /* already checked */
1070 /* fill up imux indices */
1071 if (!alc_check_dyn_adc_switch(codec)) {
1076 imux = spec->input_mux;
1077 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1078 spec->imux_pins, imux->num_items);
1079 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1080 spec->imux_pins, imux->num_items);
1081 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1082 spec->imux_pins, imux->num_items);
1083 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1085 return false; /* no corresponding imux */
1088 snd_hda_jack_detect_enable(codec, spec->ext_mic_pin, ALC_MIC_EVENT);
1089 if (spec->dock_mic_pin)
1090 snd_hda_jack_detect_enable(codec, spec->dock_mic_pin,
1093 spec->auto_mic_valid_imux = 1;
1099 * Check the availability of auto-mic switch;
1100 * Set up if really supported
1102 static void alc_init_auto_mic(struct hda_codec *codec)
1104 struct alc_spec *spec = codec->spec;
1105 struct auto_pin_cfg *cfg = &spec->autocfg;
1106 hda_nid_t fixed, ext, dock;
1109 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1111 fixed = ext = dock = 0;
1112 for (i = 0; i < cfg->num_inputs; i++) {
1113 hda_nid_t nid = cfg->inputs[i].pin;
1114 unsigned int defcfg;
1115 defcfg = snd_hda_codec_get_pincfg(codec, nid);
1116 switch (snd_hda_get_input_pin_attr(defcfg)) {
1117 case INPUT_PIN_ATTR_INT:
1119 return; /* already occupied */
1120 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1121 return; /* invalid type */
1124 case INPUT_PIN_ATTR_UNUSED:
1125 return; /* invalid entry */
1126 case INPUT_PIN_ATTR_DOCK:
1128 return; /* already occupied */
1129 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1130 return; /* invalid type */
1135 return; /* already occupied */
1136 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1137 return; /* invalid type */
1148 if (!is_jack_detectable(codec, ext))
1149 return; /* no unsol support */
1150 if (dock && !is_jack_detectable(codec, dock))
1151 return; /* no unsol support */
1153 /* check imux indices */
1154 spec->ext_mic_pin = ext;
1155 spec->int_mic_pin = fixed;
1156 spec->dock_mic_pin = dock;
1159 if (!alc_auto_mic_check_imux(codec))
1162 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1164 spec->unsol_event = alc_sku_unsol_event;
1167 /* check the availabilities of auto-mute and auto-mic switches */
1168 static void alc_auto_check_switches(struct hda_codec *codec)
1170 alc_init_automute(codec);
1171 alc_init_auto_mic(codec);
1175 * Realtek SSID verification
1178 /* Could be any non-zero and even value. When used as fixup, tells
1179 * the driver to ignore any present sku defines.
1181 #define ALC_FIXUP_SKU_IGNORE (2)
1183 static int alc_auto_parse_customize_define(struct hda_codec *codec)
1185 unsigned int ass, tmp, i;
1187 struct alc_spec *spec = codec->spec;
1189 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1191 if (spec->cdefine.fixup) {
1192 ass = spec->cdefine.sku_cfg;
1193 if (ass == ALC_FIXUP_SKU_IGNORE)
1198 ass = codec->subsystem_id & 0xffff;
1199 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
1203 if (codec->vendor_id == 0x10ec0260)
1205 ass = snd_hda_codec_get_pincfg(codec, nid);
1208 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1209 codec->chip_name, ass);
1215 for (i = 1; i < 16; i++) {
1219 if (((ass >> 16) & 0xf) != tmp)
1222 spec->cdefine.port_connectivity = ass >> 30;
1223 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1224 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1225 spec->cdefine.customization = ass >> 8;
1227 spec->cdefine.sku_cfg = ass;
1228 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1229 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1230 spec->cdefine.swap = (ass & 0x2) >> 1;
1231 spec->cdefine.override = ass & 0x1;
1233 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1234 nid, spec->cdefine.sku_cfg);
1235 snd_printd("SKU: port_connectivity=0x%x\n",
1236 spec->cdefine.port_connectivity);
1237 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1238 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1239 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1240 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1241 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1242 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1243 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1248 /* return true if the given NID is found in the list */
1249 static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1251 return find_idx_in_nid_list(nid, list, nums) >= 0;
1254 /* check subsystem ID and set up device-specific initialization;
1255 * return 1 if initialized, 0 if invalid SSID
1257 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1258 * 31 ~ 16 : Manufacture ID
1260 * 7 ~ 0 : Assembly ID
1261 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1263 static int alc_subsystem_id(struct hda_codec *codec,
1264 hda_nid_t porta, hda_nid_t porte,
1265 hda_nid_t portd, hda_nid_t porti)
1267 unsigned int ass, tmp, i;
1269 struct alc_spec *spec = codec->spec;
1271 if (spec->cdefine.fixup) {
1272 ass = spec->cdefine.sku_cfg;
1273 if (ass == ALC_FIXUP_SKU_IGNORE)
1278 ass = codec->subsystem_id & 0xffff;
1279 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1282 /* invalid SSID, check the special NID pin defcfg instead */
1284 * 31~30 : port connectivity
1287 * 19~16 : Check sum (15:1)
1292 if (codec->vendor_id == 0x10ec0260)
1294 ass = snd_hda_codec_get_pincfg(codec, nid);
1295 snd_printd("realtek: No valid SSID, "
1296 "checking pincfg 0x%08x for NID 0x%x\n",
1300 if ((ass >> 30) != 1) /* no physical connection */
1305 for (i = 1; i < 16; i++) {
1309 if (((ass >> 16) & 0xf) != tmp)
1312 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1313 ass & 0xffff, codec->vendor_id);
1317 * 2 : 0 --> Desktop, 1 --> Laptop
1318 * 3~5 : External Amplifier control
1321 tmp = (ass & 0x38) >> 3; /* external Amp control */
1324 spec->init_amp = ALC_INIT_GPIO1;
1327 spec->init_amp = ALC_INIT_GPIO2;
1330 spec->init_amp = ALC_INIT_GPIO3;
1334 spec->init_amp = ALC_INIT_DEFAULT;
1338 /* is laptop or Desktop and enable the function "Mute internal speaker
1339 * when the external headphone out jack is plugged"
1341 if (!(ass & 0x8000))
1344 * 10~8 : Jack location
1345 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1347 * 15 : 1 --> enable the function "Mute internal speaker
1348 * when the external headphone out jack is plugged"
1350 if (!spec->autocfg.hp_pins[0] &&
1351 !(spec->autocfg.line_out_pins[0] &&
1352 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
1354 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1365 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1366 spec->autocfg.line_outs))
1368 spec->autocfg.hp_pins[0] = nid;
1373 /* Check the validity of ALC subsystem-id
1374 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1375 static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
1377 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
1378 struct alc_spec *spec = codec->spec;
1379 snd_printd("realtek: "
1380 "Enable default setup for auto mode as fallback\n");
1381 spec->init_amp = ALC_INIT_DEFAULT;
1386 * Fix-up pin default configurations and add default verbs
1394 struct alc_model_fixup {
1405 const struct alc_pincfg *pins;
1406 const struct hda_verb *verbs;
1407 void (*func)(struct hda_codec *codec,
1408 const struct alc_fixup *fix,
1422 ALC_FIXUP_ACT_PRE_PROBE,
1423 ALC_FIXUP_ACT_PROBE,
1427 static void alc_apply_fixup(struct hda_codec *codec, int action)
1429 struct alc_spec *spec = codec->spec;
1430 int id = spec->fixup_id;
1431 #ifdef CONFIG_SND_DEBUG_VERBOSE
1432 const char *modelname = spec->fixup_name;
1436 if (!spec->fixup_list)
1440 const struct alc_fixup *fix = spec->fixup_list + id;
1441 const struct alc_pincfg *cfg;
1443 switch (fix->type) {
1445 if (action != ALC_FIXUP_ACT_PRE_PROBE || !fix->v.sku)
1447 snd_printdd(KERN_INFO "hda_codec: %s: "
1448 "Apply sku override for %s\n",
1449 codec->chip_name, modelname);
1450 spec->cdefine.sku_cfg = fix->v.sku;
1451 spec->cdefine.fixup = 1;
1453 case ALC_FIXUP_PINS:
1455 if (action != ALC_FIXUP_ACT_PRE_PROBE || !cfg)
1457 snd_printdd(KERN_INFO "hda_codec: %s: "
1458 "Apply pincfg for %s\n",
1459 codec->chip_name, modelname);
1460 for (; cfg->nid; cfg++)
1461 snd_hda_codec_set_pincfg(codec, cfg->nid,
1464 case ALC_FIXUP_VERBS:
1465 if (action != ALC_FIXUP_ACT_PROBE || !fix->v.verbs)
1467 snd_printdd(KERN_INFO "hda_codec: %s: "
1468 "Apply fix-verbs for %s\n",
1469 codec->chip_name, modelname);
1470 add_verb(codec->spec, fix->v.verbs);
1472 case ALC_FIXUP_FUNC:
1475 snd_printdd(KERN_INFO "hda_codec: %s: "
1476 "Apply fix-func for %s\n",
1477 codec->chip_name, modelname);
1478 fix->v.func(codec, fix, action);
1481 snd_printk(KERN_ERR "hda_codec: %s: "
1482 "Invalid fixup type %d\n",
1483 codec->chip_name, fix->type);
1494 static void alc_pick_fixup(struct hda_codec *codec,
1495 const struct alc_model_fixup *models,
1496 const struct snd_pci_quirk *quirk,
1497 const struct alc_fixup *fixlist)
1499 struct alc_spec *spec = codec->spec;
1501 const char *name = NULL;
1503 if (codec->modelname && models) {
1504 while (models->name) {
1505 if (!strcmp(codec->modelname, models->name)) {
1507 name = models->name;
1514 quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1517 #ifdef CONFIG_SND_DEBUG_VERBOSE
1523 spec->fixup_id = id;
1525 spec->fixup_list = fixlist;
1526 spec->fixup_name = name;
1531 * COEF access helper functions
1533 static int alc_read_coef_idx(struct hda_codec *codec,
1534 unsigned int coef_idx)
1537 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1539 val = snd_hda_codec_read(codec, 0x20, 0,
1540 AC_VERB_GET_PROC_COEF, 0);
1544 static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1545 unsigned int coef_val)
1547 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1549 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1553 /* a special bypass for COEF 0; read the cached value at the second time */
1554 static unsigned int alc_get_coef0(struct hda_codec *codec)
1556 struct alc_spec *spec = codec->spec;
1558 spec->coef0 = alc_read_coef_idx(codec, 0);
1563 * Digital I/O handling
1566 /* set right pin controls for digital I/O */
1567 static void alc_auto_init_digital(struct hda_codec *codec)
1569 struct alc_spec *spec = codec->spec;
1573 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1574 pin = spec->autocfg.dig_out_pins[i];
1577 snd_hda_codec_write(codec, pin, 0,
1578 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
1580 dac = spec->multiout.dig_out_nid;
1582 dac = spec->slave_dig_outs[i - 1];
1583 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
1585 snd_hda_codec_write(codec, dac, 0,
1586 AC_VERB_SET_AMP_GAIN_MUTE,
1589 pin = spec->autocfg.dig_in_pin;
1591 snd_hda_codec_write(codec, pin, 0,
1592 AC_VERB_SET_PIN_WIDGET_CONTROL,
1596 /* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1597 static void alc_auto_parse_digital(struct hda_codec *codec)
1599 struct alc_spec *spec = codec->spec;
1603 /* support multiple SPDIFs; the secondary is set up as a slave */
1605 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1607 err = snd_hda_get_connections(codec,
1608 spec->autocfg.dig_out_pins[i],
1609 conn, ARRAY_SIZE(conn));
1612 dig_nid = conn[0]; /* assume the first element is audio-out */
1614 spec->multiout.dig_out_nid = dig_nid;
1615 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1617 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
1618 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
1620 spec->slave_dig_outs[nums - 1] = dig_nid;
1625 if (spec->autocfg.dig_in_pin) {
1626 dig_nid = codec->start_nid;
1627 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1628 unsigned int wcaps = get_wcaps(codec, dig_nid);
1629 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1631 if (!(wcaps & AC_WCAP_DIGITAL))
1633 if (!(wcaps & AC_WCAP_CONN_LIST))
1635 err = get_connection_index(codec, dig_nid,
1636 spec->autocfg.dig_in_pin);
1638 spec->dig_in_nid = dig_nid;
1646 * capture mixer elements
1648 static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1649 struct snd_ctl_elem_info *uinfo)
1651 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1652 struct alc_spec *spec = codec->spec;
1656 mutex_lock(&codec->control_mutex);
1657 if (spec->vol_in_capsrc)
1658 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1660 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1661 kcontrol->private_value = val;
1662 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
1663 mutex_unlock(&codec->control_mutex);
1667 static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1668 unsigned int size, unsigned int __user *tlv)
1670 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1671 struct alc_spec *spec = codec->spec;
1675 mutex_lock(&codec->control_mutex);
1676 if (spec->vol_in_capsrc)
1677 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1679 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1680 kcontrol->private_value = val;
1681 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
1682 mutex_unlock(&codec->control_mutex);
1686 typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1687 struct snd_ctl_elem_value *ucontrol);
1689 static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1690 struct snd_ctl_elem_value *ucontrol,
1691 getput_call_t func, bool check_adc_switch)
1693 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1694 struct alc_spec *spec = codec->spec;
1697 mutex_lock(&codec->control_mutex);
1698 if (check_adc_switch && spec->dyn_adc_switch) {
1699 for (i = 0; i < spec->num_adc_nids; i++) {
1700 kcontrol->private_value =
1701 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1703 err = func(kcontrol, ucontrol);
1708 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1709 if (spec->vol_in_capsrc)
1710 kcontrol->private_value =
1711 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1714 kcontrol->private_value =
1715 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1717 err = func(kcontrol, ucontrol);
1720 mutex_unlock(&codec->control_mutex);
1724 static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1725 struct snd_ctl_elem_value *ucontrol)
1727 return alc_cap_getput_caller(kcontrol, ucontrol,
1728 snd_hda_mixer_amp_volume_get, false);
1731 static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1732 struct snd_ctl_elem_value *ucontrol)
1734 return alc_cap_getput_caller(kcontrol, ucontrol,
1735 snd_hda_mixer_amp_volume_put, true);
1738 /* capture mixer elements */
1739 #define alc_cap_sw_info snd_ctl_boolean_stereo_info
1741 static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1742 struct snd_ctl_elem_value *ucontrol)
1744 return alc_cap_getput_caller(kcontrol, ucontrol,
1745 snd_hda_mixer_amp_switch_get, false);
1748 static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1749 struct snd_ctl_elem_value *ucontrol)
1751 return alc_cap_getput_caller(kcontrol, ucontrol,
1752 snd_hda_mixer_amp_switch_put, true);
1755 #define _DEFINE_CAPMIX(num) \
1757 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1758 .name = "Capture Switch", \
1759 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1761 .info = alc_cap_sw_info, \
1762 .get = alc_cap_sw_get, \
1763 .put = alc_cap_sw_put, \
1766 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1767 .name = "Capture Volume", \
1768 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1769 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1770 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1772 .info = alc_cap_vol_info, \
1773 .get = alc_cap_vol_get, \
1774 .put = alc_cap_vol_put, \
1775 .tlv = { .c = alc_cap_vol_tlv }, \
1778 #define _DEFINE_CAPSRC(num) \
1780 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1781 /* .name = "Capture Source", */ \
1782 .name = "Input Source", \
1784 .info = alc_mux_enum_info, \
1785 .get = alc_mux_enum_get, \
1786 .put = alc_mux_enum_put, \
1789 #define DEFINE_CAPMIX(num) \
1790 static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
1791 _DEFINE_CAPMIX(num), \
1792 _DEFINE_CAPSRC(num), \
1796 #define DEFINE_CAPMIX_NOSRC(num) \
1797 static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
1798 _DEFINE_CAPMIX(num), \
1802 /* up to three ADCs */
1806 DEFINE_CAPMIX_NOSRC(1);
1807 DEFINE_CAPMIX_NOSRC(2);
1808 DEFINE_CAPMIX_NOSRC(3);
1811 * virtual master controls
1815 * slave controls for virtual master
1817 static const char * const alc_slave_vols[] = {
1818 "Front Playback Volume",
1819 "Surround Playback Volume",
1820 "Center Playback Volume",
1821 "LFE Playback Volume",
1822 "Side Playback Volume",
1823 "Headphone Playback Volume",
1824 "Speaker Playback Volume",
1825 "Mono Playback Volume",
1826 "Line-Out Playback Volume",
1827 "PCM Playback Volume",
1831 static const char * const alc_slave_sws[] = {
1832 "Front Playback Switch",
1833 "Surround Playback Switch",
1834 "Center Playback Switch",
1835 "LFE Playback Switch",
1836 "Side Playback Switch",
1837 "Headphone Playback Switch",
1838 "Speaker Playback Switch",
1839 "Mono Playback Switch",
1840 "IEC958 Playback Switch",
1841 "Line-Out Playback Switch",
1842 "PCM Playback Switch",
1847 * build control elements
1850 #define NID_MAPPING (-1)
1852 #define SUBDEV_SPEAKER_ (0 << 6)
1853 #define SUBDEV_HP_ (1 << 6)
1854 #define SUBDEV_LINE_ (2 << 6)
1855 #define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1856 #define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1857 #define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1859 static void alc_free_kctls(struct hda_codec *codec);
1861 #ifdef CONFIG_SND_HDA_INPUT_BEEP
1862 /* additional beep mixers; the actual parameters are overwritten at build */
1863 static const struct snd_kcontrol_new alc_beep_mixer[] = {
1864 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
1865 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
1870 static int __alc_build_controls(struct hda_codec *codec)
1872 struct alc_spec *spec = codec->spec;
1873 struct snd_kcontrol *kctl = NULL;
1874 const struct snd_kcontrol_new *knew;
1879 for (i = 0; i < spec->num_mixers; i++) {
1880 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1884 if (spec->cap_mixer) {
1885 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1889 if (spec->multiout.dig_out_nid) {
1890 err = snd_hda_create_spdif_out_ctls(codec,
1891 spec->multiout.dig_out_nid,
1892 spec->multiout.dig_out_nid);
1895 if (!spec->no_analog) {
1896 err = snd_hda_create_spdif_share_sw(codec,
1900 spec->multiout.share_spdif = 1;
1903 if (spec->dig_in_nid) {
1904 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1909 #ifdef CONFIG_SND_HDA_INPUT_BEEP
1910 /* create beep controls if needed */
1911 if (spec->beep_amp) {
1912 const struct snd_kcontrol_new *knew;
1913 for (knew = alc_beep_mixer; knew->name; knew++) {
1914 struct snd_kcontrol *kctl;
1915 kctl = snd_ctl_new1(knew, codec);
1918 kctl->private_value = spec->beep_amp;
1919 err = snd_hda_ctl_add(codec, 0, kctl);
1926 /* if we have no master control, let's create it */
1927 if (!spec->no_analog &&
1928 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1929 unsigned int vmaster_tlv[4];
1930 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
1931 HDA_OUTPUT, vmaster_tlv);
1932 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1933 vmaster_tlv, alc_slave_vols);
1937 if (!spec->no_analog &&
1938 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1939 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1940 NULL, alc_slave_sws);
1945 /* assign Capture Source enums to NID */
1946 if (spec->capsrc_nids || spec->adc_nids) {
1947 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
1949 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1950 for (i = 0; kctl && i < kctl->count; i++) {
1951 err = snd_hda_add_nid(codec, kctl, i,
1952 get_capsrc(spec, i));
1957 if (spec->cap_mixer && spec->adc_nids) {
1958 const char *kname = kctl ? kctl->id.name : NULL;
1959 for (knew = spec->cap_mixer; knew->name; knew++) {
1960 if (kname && strcmp(knew->name, kname) == 0)
1962 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1963 for (i = 0; kctl && i < kctl->count; i++) {
1964 err = snd_hda_add_nid(codec, kctl, i,
1972 /* other nid->control mapping */
1973 for (i = 0; i < spec->num_mixers; i++) {
1974 for (knew = spec->mixers[i]; knew->name; knew++) {
1975 if (knew->iface != NID_MAPPING)
1977 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1980 u = knew->subdevice;
1981 for (j = 0; j < 4; j++, u >>= 8) {
1986 case SUBDEV_SPEAKER_:
1987 nid = spec->autocfg.speaker_pins[nid];
1990 nid = spec->autocfg.line_out_pins[nid];
1993 nid = spec->autocfg.hp_pins[nid];
1998 err = snd_hda_add_nid(codec, kctl, 0, nid);
2002 u = knew->private_value;
2003 for (j = 0; j < 4; j++, u >>= 8) {
2007 err = snd_hda_add_nid(codec, kctl, 0, nid);
2014 alc_free_kctls(codec); /* no longer needed */
2019 static int alc_build_controls(struct hda_codec *codec)
2021 struct alc_spec *spec = codec->spec;
2022 int err = __alc_build_controls(codec);
2025 return snd_hda_jack_add_kctls(codec, &spec->autocfg);
2033 static void alc_init_special_input_src(struct hda_codec *codec);
2034 static int alc269_fill_coef(struct hda_codec *codec);
2036 static int alc_init(struct hda_codec *codec)
2038 struct alc_spec *spec = codec->spec;
2041 if (codec->vendor_id == 0x10ec0269)
2042 alc269_fill_coef(codec);
2045 alc_auto_init_amp(codec, spec->init_amp);
2047 for (i = 0; i < spec->num_init_verbs; i++)
2048 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2049 alc_init_special_input_src(codec);
2051 if (spec->init_hook)
2052 spec->init_hook(codec);
2054 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2056 snd_hda_jack_report_sync(codec);
2058 hda_call_check_power_status(codec, 0x01);
2062 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2064 struct alc_spec *spec = codec->spec;
2066 if (spec->unsol_event)
2067 spec->unsol_event(codec, res);
2070 #ifdef CONFIG_SND_HDA_POWER_SAVE
2071 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2073 struct alc_spec *spec = codec->spec;
2074 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2079 * Analog playback callbacks
2081 static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
2082 struct hda_codec *codec,
2083 struct snd_pcm_substream *substream)
2085 struct alc_spec *spec = codec->spec;
2086 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2090 static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2091 struct hda_codec *codec,
2092 unsigned int stream_tag,
2093 unsigned int format,
2094 struct snd_pcm_substream *substream)
2096 struct alc_spec *spec = codec->spec;
2097 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2098 stream_tag, format, substream);
2101 static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2102 struct hda_codec *codec,
2103 struct snd_pcm_substream *substream)
2105 struct alc_spec *spec = codec->spec;
2106 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2112 static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2113 struct hda_codec *codec,
2114 struct snd_pcm_substream *substream)
2116 struct alc_spec *spec = codec->spec;
2117 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2120 static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2121 struct hda_codec *codec,
2122 unsigned int stream_tag,
2123 unsigned int format,
2124 struct snd_pcm_substream *substream)
2126 struct alc_spec *spec = codec->spec;
2127 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2128 stream_tag, format, substream);
2131 static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2132 struct hda_codec *codec,
2133 struct snd_pcm_substream *substream)
2135 struct alc_spec *spec = codec->spec;
2136 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2139 static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2140 struct hda_codec *codec,
2141 struct snd_pcm_substream *substream)
2143 struct alc_spec *spec = codec->spec;
2144 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2150 static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2151 struct hda_codec *codec,
2152 unsigned int stream_tag,
2153 unsigned int format,
2154 struct snd_pcm_substream *substream)
2156 struct alc_spec *spec = codec->spec;
2158 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
2159 stream_tag, 0, format);
2163 static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2164 struct hda_codec *codec,
2165 struct snd_pcm_substream *substream)
2167 struct alc_spec *spec = codec->spec;
2169 snd_hda_codec_cleanup_stream(codec,
2170 spec->adc_nids[substream->number + 1]);
2174 /* analog capture with dynamic dual-adc changes */
2175 static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2176 struct hda_codec *codec,
2177 unsigned int stream_tag,
2178 unsigned int format,
2179 struct snd_pcm_substream *substream)
2181 struct alc_spec *spec = codec->spec;
2182 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
2183 spec->cur_adc_stream_tag = stream_tag;
2184 spec->cur_adc_format = format;
2185 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2189 static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2190 struct hda_codec *codec,
2191 struct snd_pcm_substream *substream)
2193 struct alc_spec *spec = codec->spec;
2194 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2199 static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
2203 .nid = 0, /* fill later */
2205 .prepare = dyn_adc_capture_pcm_prepare,
2206 .cleanup = dyn_adc_capture_pcm_cleanup
2212 static const struct hda_pcm_stream alc_pcm_analog_playback = {
2216 /* NID is set in alc_build_pcms */
2218 .open = alc_playback_pcm_open,
2219 .prepare = alc_playback_pcm_prepare,
2220 .cleanup = alc_playback_pcm_cleanup
2224 static const struct hda_pcm_stream alc_pcm_analog_capture = {
2228 /* NID is set in alc_build_pcms */
2231 static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
2235 /* NID is set in alc_build_pcms */
2238 static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
2239 .substreams = 2, /* can be overridden */
2242 /* NID is set in alc_build_pcms */
2244 .prepare = alc_alt_capture_pcm_prepare,
2245 .cleanup = alc_alt_capture_pcm_cleanup
2249 static const struct hda_pcm_stream alc_pcm_digital_playback = {
2253 /* NID is set in alc_build_pcms */
2255 .open = alc_dig_playback_pcm_open,
2256 .close = alc_dig_playback_pcm_close,
2257 .prepare = alc_dig_playback_pcm_prepare,
2258 .cleanup = alc_dig_playback_pcm_cleanup
2262 static const struct hda_pcm_stream alc_pcm_digital_capture = {
2266 /* NID is set in alc_build_pcms */
2269 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
2270 static const struct hda_pcm_stream alc_pcm_null_stream = {
2276 static int alc_build_pcms(struct hda_codec *codec)
2278 struct alc_spec *spec = codec->spec;
2279 struct hda_pcm *info = spec->pcm_rec;
2280 const struct hda_pcm_stream *p;
2281 bool have_multi_adcs;
2284 codec->num_pcms = 1;
2285 codec->pcm_info = info;
2287 if (spec->no_analog)
2290 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2291 "%s Analog", codec->chip_name);
2292 info->name = spec->stream_name_analog;
2294 if (spec->multiout.dac_nids > 0) {
2295 p = spec->stream_analog_playback;
2297 p = &alc_pcm_analog_playback;
2298 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2299 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2301 if (spec->adc_nids) {
2302 p = spec->stream_analog_capture;
2304 if (spec->dyn_adc_switch)
2305 p = &dyn_adc_pcm_analog_capture;
2307 p = &alc_pcm_analog_capture;
2309 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2310 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2313 if (spec->channel_mode) {
2314 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2315 for (i = 0; i < spec->num_channel_mode; i++) {
2316 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2317 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2323 /* SPDIF for stream index #1 */
2324 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2325 snprintf(spec->stream_name_digital,
2326 sizeof(spec->stream_name_digital),
2327 "%s Digital", codec->chip_name);
2328 codec->num_pcms = 2;
2329 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
2330 info = spec->pcm_rec + 1;
2331 info->name = spec->stream_name_digital;
2332 if (spec->dig_out_type)
2333 info->pcm_type = spec->dig_out_type;
2335 info->pcm_type = HDA_PCM_TYPE_SPDIF;
2336 if (spec->multiout.dig_out_nid) {
2337 p = spec->stream_digital_playback;
2339 p = &alc_pcm_digital_playback;
2340 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2341 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2343 if (spec->dig_in_nid) {
2344 p = spec->stream_digital_capture;
2346 p = &alc_pcm_digital_capture;
2347 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2348 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2350 /* FIXME: do we need this for all Realtek codec models? */
2351 codec->spdif_status_reset = 1;
2354 if (spec->no_analog)
2357 /* If the use of more than one ADC is requested for the current
2358 * model, configure a second analog capture-only PCM.
2360 have_multi_adcs = (spec->num_adc_nids > 1) &&
2361 !spec->dyn_adc_switch && !spec->auto_mic &&
2362 (!spec->input_mux || spec->input_mux->num_items > 1);
2363 /* Additional Analaog capture for index #2 */
2364 if (spec->alt_dac_nid || have_multi_adcs) {
2365 codec->num_pcms = 3;
2366 info = spec->pcm_rec + 2;
2367 info->name = spec->stream_name_analog;
2368 if (spec->alt_dac_nid) {
2369 p = spec->stream_analog_alt_playback;
2371 p = &alc_pcm_analog_alt_playback;
2372 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2373 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2376 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2377 alc_pcm_null_stream;
2378 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2380 if (have_multi_adcs) {
2381 p = spec->stream_analog_alt_capture;
2383 p = &alc_pcm_analog_alt_capture;
2384 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2385 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2387 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2388 spec->num_adc_nids - 1;
2390 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2391 alc_pcm_null_stream;
2392 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
2399 static inline void alc_shutup(struct hda_codec *codec)
2401 struct alc_spec *spec = codec->spec;
2403 if (spec && spec->shutup)
2404 spec->shutup(codec);
2405 snd_hda_shutup_pins(codec);
2408 static void alc_free_kctls(struct hda_codec *codec)
2410 struct alc_spec *spec = codec->spec;
2412 if (spec->kctls.list) {
2413 struct snd_kcontrol_new *kctl = spec->kctls.list;
2415 for (i = 0; i < spec->kctls.used; i++)
2416 kfree(kctl[i].name);
2418 snd_array_free(&spec->kctls);
2421 static void alc_free_bind_ctls(struct hda_codec *codec)
2423 struct alc_spec *spec = codec->spec;
2424 if (spec->bind_ctls.list) {
2425 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2427 for (i = 0; i < spec->bind_ctls.used; i++)
2430 snd_array_free(&spec->bind_ctls);
2433 static void alc_free(struct hda_codec *codec)
2435 struct alc_spec *spec = codec->spec;
2441 alc_free_kctls(codec);
2442 alc_free_bind_ctls(codec);
2444 snd_hda_detach_beep_device(codec);
2447 #ifdef CONFIG_SND_HDA_POWER_SAVE
2448 static void alc_power_eapd(struct hda_codec *codec)
2450 alc_auto_setup_eapd(codec, false);
2453 static int alc_suspend(struct hda_codec *codec, pm_message_t state)
2455 struct alc_spec *spec = codec->spec;
2457 if (spec && spec->power_hook)
2458 spec->power_hook(codec);
2464 static int alc_resume(struct hda_codec *codec)
2466 msleep(150); /* to avoid pop noise */
2467 codec->patch_ops.init(codec);
2468 snd_hda_codec_resume_amp(codec);
2469 snd_hda_codec_resume_cache(codec);
2470 hda_call_check_power_status(codec, 0x01);
2477 static const struct hda_codec_ops alc_patch_ops = {
2478 .build_controls = alc_build_controls,
2479 .build_pcms = alc_build_pcms,
2482 .unsol_event = alc_unsol_event,
2484 .resume = alc_resume,
2486 #ifdef CONFIG_SND_HDA_POWER_SAVE
2487 .suspend = alc_suspend,
2488 .check_power_status = alc_check_power_status,
2490 .reboot_notify = alc_shutup,
2493 /* replace the codec chip_name with the given string */
2494 static int alc_codec_rename(struct hda_codec *codec, const char *name)
2496 kfree(codec->chip_name);
2497 codec->chip_name = kstrdup(name, GFP_KERNEL);
2498 if (!codec->chip_name) {
2506 * Rename codecs appropriately from COEF value
2508 struct alc_codec_rename_table {
2509 unsigned int vendor_id;
2510 unsigned short coef_mask;
2511 unsigned short coef_bits;
2515 static struct alc_codec_rename_table rename_tbl[] = {
2516 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2517 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2518 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2519 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2520 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2521 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2522 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
2523 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2524 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2525 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2526 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2527 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2528 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2529 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2530 { } /* terminator */
2533 static int alc_codec_rename_from_preset(struct hda_codec *codec)
2535 const struct alc_codec_rename_table *p;
2537 for (p = rename_tbl; p->vendor_id; p++) {
2538 if (p->vendor_id != codec->vendor_id)
2540 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
2541 return alc_codec_rename(codec, p->name);
2547 * Automatic parse of I/O pins from the BIOS configuration
2552 ALC_CTL_WIDGET_MUTE,
2557 static const struct snd_kcontrol_new alc_control_templates[] = {
2558 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2559 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2560 HDA_BIND_MUTE(NULL, 0, 0, 0),
2561 HDA_BIND_VOL(NULL, 0),
2562 HDA_BIND_SW(NULL, 0),
2565 /* add dynamic controls */
2566 static int add_control(struct alc_spec *spec, int type, const char *name,
2567 int cidx, unsigned long val)
2569 struct snd_kcontrol_new *knew;
2571 knew = alc_kcontrol_new(spec);
2574 *knew = alc_control_templates[type];
2575 knew->name = kstrdup(name, GFP_KERNEL);
2579 if (get_amp_nid_(val))
2580 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
2581 knew->private_value = val;
2585 static int add_control_with_pfx(struct alc_spec *spec, int type,
2586 const char *pfx, const char *dir,
2587 const char *sfx, int cidx, unsigned long val)
2590 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
2591 return add_control(spec, type, name, cidx, val);
2594 #define add_pb_vol_ctrl(spec, type, pfx, val) \
2595 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2596 #define add_pb_sw_ctrl(spec, type, pfx, val) \
2597 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2598 #define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2599 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2600 #define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2601 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
2603 static const char * const channel_name[4] = {
2604 "Front", "Surround", "CLFE", "Side"
2607 static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2608 bool can_be_master, int *index)
2610 struct auto_pin_cfg *cfg = &spec->autocfg;
2613 if (cfg->line_outs == 1 && !spec->multi_ios &&
2614 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
2617 switch (cfg->line_out_type) {
2618 case AUTO_PIN_SPEAKER_OUT:
2619 if (cfg->line_outs == 1)
2621 if (cfg->line_outs == 2)
2622 return ch ? "Bass Speaker" : "Speaker";
2624 case AUTO_PIN_HP_OUT:
2625 /* for multi-io case, only the primary out */
2626 if (ch && spec->multi_ios)
2631 if (cfg->line_outs == 1 && !spec->multi_ios)
2635 if (snd_BUG_ON(ch >= ARRAY_SIZE(channel_name)))
2638 return channel_name[ch];
2641 /* create input playback/capture controls for the given pin */
2642 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
2643 const char *ctlname, int ctlidx,
2644 int idx, hda_nid_t mix_nid)
2648 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
2649 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2652 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
2653 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2659 static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
2661 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2662 return (pincap & AC_PINCAP_IN) != 0;
2665 /* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
2666 static int alc_auto_fill_adc_caps(struct hda_codec *codec)
2668 struct alc_spec *spec = codec->spec;
2670 hda_nid_t *adc_nids = spec->private_adc_nids;
2671 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2672 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
2675 nid = codec->start_nid;
2676 for (i = 0; i < codec->num_nodes; i++, nid++) {
2678 const hda_nid_t *list;
2679 unsigned int caps = get_wcaps(codec, nid);
2680 int type = get_wcaps_type(caps);
2682 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2684 adc_nids[nums] = nid;
2685 cap_nids[nums] = nid;
2689 type = get_wcaps_type(get_wcaps(codec, src));
2690 if (type == AC_WID_PIN)
2692 if (type == AC_WID_AUD_SEL) {
2693 cap_nids[nums] = src;
2696 n = snd_hda_get_conn_list(codec, src, &list);
2698 cap_nids[nums] = src;
2704 if (++nums >= max_nums)
2707 spec->adc_nids = spec->private_adc_nids;
2708 spec->capsrc_nids = spec->private_capsrc_nids;
2709 spec->num_adc_nids = nums;
2713 /* create playback/capture controls for input pins */
2714 static int alc_auto_create_input_ctls(struct hda_codec *codec)
2716 struct alc_spec *spec = codec->spec;
2717 const struct auto_pin_cfg *cfg = &spec->autocfg;
2718 hda_nid_t mixer = spec->mixer_nid;
2719 struct hda_input_mux *imux = &spec->private_imux[0];
2721 int i, c, err, idx, type_idx = 0;
2722 const char *prev_label = NULL;
2724 num_adcs = alc_auto_fill_adc_caps(codec);
2728 for (i = 0; i < cfg->num_inputs; i++) {
2732 pin = cfg->inputs[i].pin;
2733 if (!alc_is_input_pin(codec, pin))
2736 label = hda_get_autocfg_input_label(codec, cfg, i);
2737 if (prev_label && !strcmp(label, prev_label))
2744 idx = get_connection_index(codec, mixer, pin);
2746 err = new_analog_input(spec, pin,
2754 for (c = 0; c < num_adcs; c++) {
2755 hda_nid_t cap = get_capsrc(spec, c);
2756 idx = get_connection_index(codec, cap, pin);
2758 spec->imux_pins[imux->num_items] = pin;
2759 snd_hda_add_imux_item(imux, label, idx, NULL);
2765 spec->num_mux_defs = 1;
2766 spec->input_mux = imux;
2771 static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
2772 unsigned int pin_type)
2774 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2777 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2778 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2782 static int get_pin_type(int line_out_type)
2784 if (line_out_type == AUTO_PIN_HP_OUT)
2790 static void alc_auto_init_analog_input(struct hda_codec *codec)
2792 struct alc_spec *spec = codec->spec;
2793 struct auto_pin_cfg *cfg = &spec->autocfg;
2796 for (i = 0; i < cfg->num_inputs; i++) {
2797 hda_nid_t nid = cfg->inputs[i].pin;
2798 if (alc_is_input_pin(codec, nid)) {
2799 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
2800 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
2801 snd_hda_codec_write(codec, nid, 0,
2802 AC_VERB_SET_AMP_GAIN_MUTE,
2807 /* mute all loopback inputs */
2808 if (spec->mixer_nid) {
2809 int nums = snd_hda_get_conn_list(codec, spec->mixer_nid, NULL);
2810 for (i = 0; i < nums; i++)
2811 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2812 AC_VERB_SET_AMP_GAIN_MUTE,
2817 /* convert from MIX nid to DAC */
2818 static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid)
2823 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT)
2825 num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list));
2826 for (i = 0; i < num; i++) {
2827 if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT)
2833 /* go down to the selector widget before the mixer */
2834 static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin)
2837 int num = snd_hda_get_connections(codec, pin, srcs,
2840 get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL)
2845 /* get MIX nid connected to the given pin targeted to DAC */
2846 static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
2852 pin = alc_go_down_to_selector(codec, pin);
2853 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2854 for (i = 0; i < num; i++) {
2855 if (alc_auto_mix_to_dac(codec, mix[i]) == dac)
2861 /* select the connection from pin to DAC if needed */
2862 static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin,
2868 pin = alc_go_down_to_selector(codec, pin);
2869 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2872 for (i = 0; i < num; i++) {
2873 if (alc_auto_mix_to_dac(codec, mix[i]) == dac) {
2874 snd_hda_codec_update_cache(codec, pin, 0,
2875 AC_VERB_SET_CONNECT_SEL, i);
2882 /* look for an empty DAC slot */
2883 static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
2885 struct alc_spec *spec = codec->spec;
2889 pin = alc_go_down_to_selector(codec, pin);
2890 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
2891 for (i = 0; i < num; i++) {
2892 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
2895 if (found_in_nid_list(nid, spec->multiout.dac_nids,
2896 ARRAY_SIZE(spec->private_dac_nids)))
2898 if (found_in_nid_list(nid, spec->multiout.hp_out_nid,
2899 ARRAY_SIZE(spec->multiout.hp_out_nid)))
2901 if (found_in_nid_list(nid, spec->multiout.extra_out_nid,
2902 ARRAY_SIZE(spec->multiout.extra_out_nid)))
2909 static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
2911 hda_nid_t sel = alc_go_down_to_selector(codec, pin);
2912 if (snd_hda_get_conn_list(codec, sel, NULL) == 1)
2913 return alc_auto_look_for_dac(codec, pin);
2917 /* return 0 if no possible DAC is found, 1 if one or more found */
2918 static int alc_auto_fill_extra_dacs(struct hda_codec *codec, int num_outs,
2919 const hda_nid_t *pins, hda_nid_t *dacs)
2923 if (num_outs && !dacs[0]) {
2924 dacs[0] = alc_auto_look_for_dac(codec, pins[0]);
2929 for (i = 1; i < num_outs; i++)
2930 dacs[i] = get_dac_if_single(codec, pins[i]);
2931 for (i = 1; i < num_outs; i++) {
2933 dacs[i] = alc_auto_look_for_dac(codec, pins[i]);
2938 static int alc_auto_fill_multi_ios(struct hda_codec *codec,
2939 unsigned int location);
2940 static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
2941 hda_nid_t pin, hda_nid_t dac);
2943 /* fill in the dac_nids table from the parsed pin configuration */
2944 static int alc_auto_fill_dac_nids(struct hda_codec *codec)
2946 struct alc_spec *spec = codec->spec;
2947 struct auto_pin_cfg *cfg = &spec->autocfg;
2948 bool redone = false;
2952 /* set num_dacs once to full for alc_auto_look_for_dac() */
2953 spec->multiout.num_dacs = cfg->line_outs;
2954 spec->multiout.hp_out_nid[0] = 0;
2955 spec->multiout.extra_out_nid[0] = 0;
2956 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
2957 spec->multiout.dac_nids = spec->private_dac_nids;
2958 spec->multi_ios = 0;
2960 /* fill hard-wired DACs first */
2962 for (i = 0; i < cfg->line_outs; i++)
2963 spec->private_dac_nids[i] =
2964 get_dac_if_single(codec, cfg->line_out_pins[i]);
2966 spec->multiout.hp_out_nid[0] =
2967 get_dac_if_single(codec, cfg->hp_pins[0]);
2968 if (cfg->speaker_outs)
2969 spec->multiout.extra_out_nid[0] =
2970 get_dac_if_single(codec, cfg->speaker_pins[0]);
2973 for (i = 0; i < cfg->line_outs; i++) {
2974 hda_nid_t pin = cfg->line_out_pins[i];
2975 if (spec->private_dac_nids[i])
2977 spec->private_dac_nids[i] = alc_auto_look_for_dac(codec, pin);
2978 if (!spec->private_dac_nids[i] && !redone) {
2979 /* if we can't find primary DACs, re-probe without
2980 * checking the hard-wired DACs
2987 /* re-count num_dacs and squash invalid entries */
2988 spec->multiout.num_dacs = 0;
2989 for (i = 0; i < cfg->line_outs; i++) {
2990 if (spec->private_dac_nids[i])
2991 spec->multiout.num_dacs++;
2993 memmove(spec->private_dac_nids + i,
2994 spec->private_dac_nids + i + 1,
2995 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
2996 spec->private_dac_nids[cfg->line_outs - 1] = 0;
3000 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3001 /* try to fill multi-io first */
3002 unsigned int location, defcfg;
3005 defcfg = snd_hda_codec_get_pincfg(codec, cfg->line_out_pins[0]);
3006 location = get_defcfg_location(defcfg);
3008 num_pins = alc_auto_fill_multi_ios(codec, location);
3010 spec->multi_ios = num_pins;
3011 spec->ext_channel_count = 2;
3012 spec->multiout.num_dacs = num_pins + 1;
3016 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
3017 alc_auto_fill_extra_dacs(codec, cfg->hp_outs, cfg->hp_pins,
3018 spec->multiout.hp_out_nid);
3019 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3020 int err = alc_auto_fill_extra_dacs(codec, cfg->speaker_outs,
3022 spec->multiout.extra_out_nid);
3023 /* if no speaker volume is assigned, try again as the primary
3026 if (!err && cfg->speaker_outs > 0 &&
3027 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3028 cfg->hp_outs = cfg->line_outs;
3029 memcpy(cfg->hp_pins, cfg->line_out_pins,
3030 sizeof(cfg->hp_pins));
3031 cfg->line_outs = cfg->speaker_outs;
3032 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3033 sizeof(cfg->speaker_pins));
3034 cfg->speaker_outs = 0;
3035 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3036 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
3042 if (cfg->line_out_pins[0])
3044 alc_look_for_out_vol_nid(codec, cfg->line_out_pins[0],
3045 spec->multiout.dac_nids[0]);
3050 static inline unsigned int get_ctl_pos(unsigned int data)
3052 hda_nid_t nid = get_amp_nid_(data);
3054 if (snd_BUG_ON(nid >= MAX_VOL_NIDS))
3056 dir = get_amp_direction_(data);
3057 return (nid << 1) | dir;
3060 #define is_ctl_used(bits, data) \
3061 test_bit(get_ctl_pos(data), bits)
3062 #define mark_ctl_usage(bits, data) \
3063 set_bit(get_ctl_pos(data), bits)
3065 static int alc_auto_add_vol_ctl(struct hda_codec *codec,
3066 const char *pfx, int cidx,
3067 hda_nid_t nid, unsigned int chs)
3069 struct alc_spec *spec = codec->spec;
3073 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3074 if (is_ctl_used(spec->vol_ctls, val) && chs != 2) /* exclude LFE */
3076 mark_ctl_usage(spec->vol_ctls, val);
3077 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
3081 #define alc_auto_add_stereo_vol(codec, pfx, cidx, nid) \
3082 alc_auto_add_vol_ctl(codec, pfx, cidx, nid, 3)
3084 /* create a mute-switch for the given mixer widget;
3085 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3087 static int alc_auto_add_sw_ctl(struct hda_codec *codec,
3088 const char *pfx, int cidx,
3089 hda_nid_t nid, unsigned int chs)
3091 struct alc_spec *spec = codec->spec;
3097 wid_type = get_wcaps_type(get_wcaps(codec, nid));
3098 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) {
3099 type = ALC_CTL_WIDGET_MUTE;
3100 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3101 } else if (snd_hda_get_conn_list(codec, nid, NULL) == 1) {
3102 type = ALC_CTL_WIDGET_MUTE;
3103 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
3105 type = ALC_CTL_BIND_MUTE;
3106 val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
3108 if (is_ctl_used(spec->sw_ctls, val) && chs != 2) /* exclude LFE */
3110 mark_ctl_usage(spec->sw_ctls, val);
3111 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
3114 #define alc_auto_add_stereo_sw(codec, pfx, cidx, nid) \
3115 alc_auto_add_sw_ctl(codec, pfx, cidx, nid, 3)
3117 static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3118 hda_nid_t pin, hda_nid_t dac)
3120 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3121 if (nid_has_mute(codec, pin, HDA_OUTPUT))
3123 else if (mix && nid_has_mute(codec, mix, HDA_INPUT))
3125 else if (nid_has_mute(codec, dac, HDA_OUTPUT))
3130 static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3131 hda_nid_t pin, hda_nid_t dac)
3133 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3134 if (nid_has_volume(codec, dac, HDA_OUTPUT))
3136 else if (nid_has_volume(codec, mix, HDA_OUTPUT))
3138 else if (nid_has_volume(codec, pin, HDA_OUTPUT))
3143 /* add playback controls from the parsed DAC table */
3144 static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
3145 const struct auto_pin_cfg *cfg)
3147 struct alc_spec *spec = codec->spec;
3148 int i, err, noutputs;
3150 noutputs = cfg->line_outs;
3151 if (spec->multi_ios > 0)
3152 noutputs += spec->multi_ios;
3154 for (i = 0; i < noutputs; i++) {
3160 dac = spec->multiout.dac_nids[i];
3163 if (i >= cfg->line_outs)
3164 pin = spec->multi_io[i - 1].pin;
3166 pin = cfg->line_out_pins[i];
3168 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3169 vol = alc_look_for_out_vol_nid(codec, pin, dac);
3170 name = alc_get_line_out_pfx(spec, i, true, &index);
3171 if (!name || !strcmp(name, "CLFE")) {
3173 err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1);
3176 err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2);
3179 err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1);
3182 err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2);
3186 err = alc_auto_add_stereo_vol(codec, name, index, vol);
3189 err = alc_auto_add_stereo_sw(codec, name, index, sw);
3197 static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
3198 hda_nid_t dac, const char *pfx,
3201 struct alc_spec *spec = codec->spec;
3207 /* the corresponding DAC is already occupied */
3208 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
3209 return 0; /* no way */
3210 /* create a switch only */
3211 val = HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT);
3212 if (is_ctl_used(spec->sw_ctls, val))
3213 return 0; /* already created */
3214 mark_ctl_usage(spec->sw_ctls, val);
3215 return __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, cidx, val);
3218 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3219 vol = alc_look_for_out_vol_nid(codec, pin, dac);
3220 err = alc_auto_add_stereo_vol(codec, pfx, cidx, vol);
3223 err = alc_auto_add_stereo_sw(codec, pfx, cidx, sw);
3229 static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3231 struct hda_ctl_ops *ops)
3233 struct alc_spec *spec = codec->spec;
3234 struct hda_bind_ctls **ctlp, *ctl;
3235 snd_array_init(&spec->bind_ctls, sizeof(ctl), 8);
3236 ctlp = snd_array_new(&spec->bind_ctls);
3239 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3246 /* add playback controls for speaker and HP outputs */
3247 static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3248 const hda_nid_t *pins,
3249 const hda_nid_t *dacs,
3252 struct alc_spec *spec = codec->spec;
3253 struct hda_bind_ctls *ctl;
3257 if (!num_pins || !pins[0])
3260 if (num_pins == 1) {
3261 hda_nid_t dac = *dacs;
3263 dac = spec->multiout.dac_nids[0];
3264 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
3267 if (dacs[num_pins - 1]) {
3268 /* OK, we have a multi-output system with individual volumes */
3269 for (i = 0; i < num_pins; i++) {
3270 if (num_pins >= 3) {
3271 snprintf(name, sizeof(name), "%s %s",
3272 pfx, channel_name[i]);
3273 err = alc_auto_create_extra_out(codec, pins[i], dacs[i],
3276 err = alc_auto_create_extra_out(codec, pins[i], dacs[i],
3285 /* Let's create a bind-controls */
3286 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_sw);
3290 for (i = 0; i < num_pins; i++) {
3291 if (get_wcaps(codec, pins[i]) & AC_WCAP_OUT_AMP)
3293 HDA_COMPOSE_AMP_VAL(pins[i], 3, 0, HDA_OUTPUT);
3296 snprintf(name, sizeof(name), "%s Playback Switch", pfx);
3297 err = add_control(spec, ALC_CTL_BIND_SW, name, 0, (long)ctl);
3302 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3306 for (i = 0; i < num_pins; i++) {
3308 if (!pins[i] || !dacs[i])
3310 vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]);
3313 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3316 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3317 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3324 static int alc_auto_create_hp_out(struct hda_codec *codec)
3326 struct alc_spec *spec = codec->spec;
3327 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3328 spec->autocfg.hp_pins,
3329 spec->multiout.hp_out_nid,
3333 static int alc_auto_create_speaker_out(struct hda_codec *codec)
3335 struct alc_spec *spec = codec->spec;
3336 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3337 spec->autocfg.speaker_pins,
3338 spec->multiout.extra_out_nid,
3342 static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
3343 hda_nid_t pin, int pin_type,
3347 hda_nid_t nid, mix = 0;
3348 hda_nid_t srcs[HDA_MAX_CONNECTIONS];
3350 alc_set_pin_output(codec, pin, pin_type);
3351 nid = alc_go_down_to_selector(codec, pin);
3352 num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
3353 for (i = 0; i < num; i++) {
3354 if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
3362 /* need the manual connection? */
3364 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
3365 /* unmute mixer widget inputs */
3366 if (nid_has_mute(codec, mix, HDA_INPUT)) {
3367 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3369 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3372 /* initialize volume */
3373 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3375 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3378 /* unmute DAC if it's not assigned to a mixer */
3379 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3380 if (nid == mix && nid_has_mute(codec, dac, HDA_OUTPUT))
3381 snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3385 static void alc_auto_init_multi_out(struct hda_codec *codec)
3387 struct alc_spec *spec = codec->spec;
3388 int pin_type = get_pin_type(spec->autocfg.line_out_type);
3391 for (i = 0; i <= HDA_SIDE; i++) {
3392 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3394 alc_auto_set_output_and_unmute(codec, nid, pin_type,
3395 spec->multiout.dac_nids[i]);
3399 static void alc_auto_init_extra_out(struct hda_codec *codec)
3401 struct alc_spec *spec = codec->spec;
3405 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3406 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3408 pin = spec->autocfg.hp_pins[i];
3411 dac = spec->multiout.hp_out_nid[i];
3413 if (i > 0 && spec->multiout.hp_out_nid[0])
3414 dac = spec->multiout.hp_out_nid[0];
3416 dac = spec->multiout.dac_nids[0];
3418 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
3420 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3421 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3423 pin = spec->autocfg.speaker_pins[i];
3426 dac = spec->multiout.extra_out_nid[i];
3428 if (i > 0 && spec->multiout.extra_out_nid[0])
3429 dac = spec->multiout.extra_out_nid[0];
3431 dac = spec->multiout.dac_nids[0];
3433 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
3440 static int alc_auto_fill_multi_ios(struct hda_codec *codec,
3441 unsigned int location)
3443 struct alc_spec *spec = codec->spec;
3444 struct auto_pin_cfg *cfg = &spec->autocfg;
3445 hda_nid_t prime_dac = spec->private_dac_nids[0];
3446 int type, i, num_pins = 0;
3448 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3449 for (i = 0; i < cfg->num_inputs; i++) {
3450 hda_nid_t nid = cfg->inputs[i].pin;
3452 unsigned int defcfg, caps;
3453 if (cfg->inputs[i].type != type)
3455 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3456 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3458 if (location && get_defcfg_location(defcfg) != location)
3460 caps = snd_hda_query_pin_caps(codec, nid);
3461 if (!(caps & AC_PINCAP_OUT))
3463 dac = alc_auto_look_for_dac(codec, nid);
3466 spec->multi_io[num_pins].pin = nid;
3467 spec->multi_io[num_pins].dac = dac;
3469 spec->private_dac_nids[spec->multiout.num_dacs++] = dac;
3472 spec->multiout.num_dacs = 1;
3474 /* clear up again */
3475 memset(spec->private_dac_nids, 0,
3476 sizeof(spec->private_dac_nids));
3477 spec->private_dac_nids[0] = prime_dac;
3483 static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
3484 struct snd_ctl_elem_info *uinfo)
3486 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3487 struct alc_spec *spec = codec->spec;
3489 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3491 uinfo->value.enumerated.items = spec->multi_ios + 1;
3492 if (uinfo->value.enumerated.item > spec->multi_ios)
3493 uinfo->value.enumerated.item = spec->multi_ios;
3494 sprintf(uinfo->value.enumerated.name, "%dch",
3495 (uinfo->value.enumerated.item + 1) * 2);
3499 static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
3500 struct snd_ctl_elem_value *ucontrol)
3502 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3503 struct alc_spec *spec = codec->spec;
3504 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
3508 static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
3510 struct alc_spec *spec = codec->spec;
3511 hda_nid_t nid = spec->multi_io[idx].pin;
3513 if (!spec->multi_io[idx].ctl_in)
3514 spec->multi_io[idx].ctl_in =
3515 snd_hda_codec_read(codec, nid, 0,
3516 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3518 snd_hda_codec_update_cache(codec, nid, 0,
3519 AC_VERB_SET_PIN_WIDGET_CONTROL,
3521 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3522 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3524 alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
3526 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3527 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3528 HDA_AMP_MUTE, HDA_AMP_MUTE);
3529 snd_hda_codec_update_cache(codec, nid, 0,
3530 AC_VERB_SET_PIN_WIDGET_CONTROL,
3531 spec->multi_io[idx].ctl_in);
3536 static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
3537 struct snd_ctl_elem_value *ucontrol)
3539 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3540 struct alc_spec *spec = codec->spec;
3543 ch = ucontrol->value.enumerated.item[0];
3544 if (ch < 0 || ch > spec->multi_ios)
3546 if (ch == (spec->ext_channel_count - 1) / 2)
3548 spec->ext_channel_count = (ch + 1) * 2;
3549 for (i = 0; i < spec->multi_ios; i++)
3550 alc_set_multi_io(codec, i, i < ch);
3551 spec->multiout.max_channels = spec->ext_channel_count;
3552 if (spec->need_dac_fix && !spec->const_channel_count)
3553 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
3557 static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
3558 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3559 .name = "Channel Mode",
3560 .info = alc_auto_ch_mode_info,
3561 .get = alc_auto_ch_mode_get,
3562 .put = alc_auto_ch_mode_put,
3565 static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
3567 struct alc_spec *spec = codec->spec;
3569 if (spec->multi_ios > 0) {
3570 struct snd_kcontrol_new *knew;
3572 knew = alc_kcontrol_new(spec);
3575 *knew = alc_auto_channel_mode_enum;
3576 knew->name = kstrdup("Channel Mode", GFP_KERNEL);
3583 /* filter out invalid adc_nids (and capsrc_nids) that don't give all
3586 static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
3588 struct alc_spec *spec = codec->spec;
3589 const struct hda_input_mux *imux;
3590 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3591 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3594 imux = spec->input_mux;
3597 if (spec->dyn_adc_switch)
3601 for (n = 0; n < spec->num_adc_nids; n++) {
3602 hda_nid_t cap = spec->private_capsrc_nids[n];
3603 int num_conns = snd_hda_get_conn_list(codec, cap, NULL);
3604 for (i = 0; i < imux->num_items; i++) {
3605 hda_nid_t pin = spec->imux_pins[i];
3607 if (get_connection_index(codec, cap, pin) < 0)
3609 } else if (num_conns <= imux->items[i].index)
3612 if (i >= imux->num_items) {
3613 adc_nids[nums] = spec->private_adc_nids[n];
3614 capsrc_nids[nums++] = cap;
3618 /* check whether ADC-switch is possible */
3619 if (!alc_check_dyn_adc_switch(codec)) {
3620 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
3621 " using fallback 0x%x\n",
3622 codec->chip_name, spec->private_adc_nids[0]);
3623 spec->num_adc_nids = 1;
3627 } else if (nums != spec->num_adc_nids) {
3628 memcpy(spec->private_adc_nids, adc_nids,
3629 nums * sizeof(hda_nid_t));
3630 memcpy(spec->private_capsrc_nids, capsrc_nids,
3631 nums * sizeof(hda_nid_t));
3632 spec->num_adc_nids = nums;
3636 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
3637 else if (spec->input_mux->num_items == 1)
3638 spec->num_adc_nids = 1; /* reduce to a single ADC */
3642 * initialize ADC paths
3644 static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
3646 struct alc_spec *spec = codec->spec;
3649 nid = spec->adc_nids[adc_idx];
3651 if (nid_has_mute(codec, nid, HDA_INPUT)) {
3652 snd_hda_codec_write(codec, nid, 0,
3653 AC_VERB_SET_AMP_GAIN_MUTE,
3657 if (!spec->capsrc_nids)
3659 nid = spec->capsrc_nids[adc_idx];
3660 if (nid_has_mute(codec, nid, HDA_OUTPUT))
3661 snd_hda_codec_write(codec, nid, 0,
3662 AC_VERB_SET_AMP_GAIN_MUTE,
3666 static void alc_auto_init_input_src(struct hda_codec *codec)
3668 struct alc_spec *spec = codec->spec;
3671 for (c = 0; c < spec->num_adc_nids; c++)
3672 alc_auto_init_adc(codec, c);
3673 if (spec->dyn_adc_switch)
3676 nums = spec->num_adc_nids;
3677 for (c = 0; c < nums; c++)
3678 alc_mux_select(codec, c, spec->cur_mux[c], true);
3681 /* add mic boosts if needed */
3682 static int alc_auto_add_mic_boost(struct hda_codec *codec)
3684 struct alc_spec *spec = codec->spec;
3685 struct auto_pin_cfg *cfg = &spec->autocfg;
3689 const char *prev_label = NULL;
3691 for (i = 0; i < cfg->num_inputs; i++) {
3692 if (cfg->inputs[i].type > AUTO_PIN_MIC)
3694 nid = cfg->inputs[i].pin;
3695 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
3697 char boost_label[32];
3699 label = hda_get_autocfg_input_label(codec, cfg, i);
3700 if (prev_label && !strcmp(label, prev_label))
3706 snprintf(boost_label, sizeof(boost_label),
3707 "%s Boost Volume", label);
3708 err = add_control(spec, ALC_CTL_WIDGET_VOL,
3709 boost_label, type_idx,
3710 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
3718 /* select or unmute the given capsrc route */
3719 static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
3722 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
3723 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
3725 } else if (snd_hda_get_conn_list(codec, cap, NULL) > 1) {
3726 snd_hda_codec_write_cache(codec, cap, 0,
3727 AC_VERB_SET_CONNECT_SEL, idx);
3731 /* set the default connection to that pin */
3732 static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
3734 struct alc_spec *spec = codec->spec;
3739 for (i = 0; i < spec->num_adc_nids; i++) {
3740 hda_nid_t cap = get_capsrc(spec, i);
3743 idx = get_connection_index(codec, cap, pin);
3746 select_or_unmute_capsrc(codec, cap, idx);
3747 return i; /* return the found index */
3749 return -1; /* not found */
3752 /* initialize some special cases for input sources */
3753 static void alc_init_special_input_src(struct hda_codec *codec)
3755 struct alc_spec *spec = codec->spec;
3758 for (i = 0; i < spec->autocfg.num_inputs; i++)
3759 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
3762 /* assign appropriate capture mixers */
3763 static void set_capture_mixer(struct hda_codec *codec)
3765 struct alc_spec *spec = codec->spec;
3766 static const struct snd_kcontrol_new *caps[2][3] = {
3767 { alc_capture_mixer_nosrc1,
3768 alc_capture_mixer_nosrc2,
3769 alc_capture_mixer_nosrc3 },
3770 { alc_capture_mixer1,
3772 alc_capture_mixer3 },
3775 /* check whether either of ADC or MUX has a volume control */
3776 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
3777 if (!spec->capsrc_nids)
3778 return; /* no volume */
3779 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
3780 return; /* no volume in capsrc, too */
3781 spec->vol_in_capsrc = 1;
3784 if (spec->num_adc_nids > 0) {
3788 if (spec->input_mux && spec->input_mux->num_items > 1)
3790 if (spec->auto_mic) {
3793 } else if (spec->dyn_adc_switch)
3796 if (spec->num_adc_nids > 3)
3797 spec->num_adc_nids = 3;
3798 else if (!spec->num_adc_nids)
3800 num_adcs = spec->num_adc_nids;
3802 spec->cap_mixer = caps[mux][num_adcs - 1];
3807 * standard auto-parser initializations
3809 static void alc_auto_init_std(struct hda_codec *codec)
3811 struct alc_spec *spec = codec->spec;
3812 alc_auto_init_multi_out(codec);
3813 alc_auto_init_extra_out(codec);
3814 alc_auto_init_analog_input(codec);
3815 alc_auto_init_input_src(codec);
3816 alc_auto_init_digital(codec);
3817 if (spec->unsol_event)
3818 alc_inithook(codec);
3822 * Digital-beep handlers
3824 #ifdef CONFIG_SND_HDA_INPUT_BEEP
3825 #define set_beep_amp(spec, nid, idx, dir) \
3826 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
3828 static const struct snd_pci_quirk beep_white_list[] = {
3829 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
3830 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
3831 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
3832 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
3833 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
3837 static inline int has_cdefine_beep(struct hda_codec *codec)
3839 struct alc_spec *spec = codec->spec;
3840 const struct snd_pci_quirk *q;
3841 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
3844 return spec->cdefine.enable_pcbeep;
3847 #define set_beep_amp(spec, nid, idx, dir) /* NOP */
3848 #define has_cdefine_beep(codec) 0
3851 /* parse the BIOS configuration and set up the alc_spec */
3852 /* return 1 if successful, 0 if the proper config is not found,
3853 * or a negative error code
3855 static int alc_parse_auto_config(struct hda_codec *codec,
3856 const hda_nid_t *ignore_nids,
3857 const hda_nid_t *ssid_nids)
3859 struct alc_spec *spec = codec->spec;
3860 struct auto_pin_cfg *cfg = &spec->autocfg;
3863 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
3867 if (!cfg->line_outs) {
3868 if (cfg->dig_outs || cfg->dig_in_pin) {
3869 spec->multiout.max_channels = 2;
3870 spec->no_analog = 1;
3873 return 0; /* can't find valid BIOS pin config */
3876 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
3877 cfg->line_outs <= cfg->hp_outs) {
3878 /* use HP as primary out */
3879 cfg->speaker_outs = cfg->line_outs;
3880 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3881 sizeof(cfg->speaker_pins));
3882 cfg->line_outs = cfg->hp_outs;
3883 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
3885 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3886 cfg->line_out_type = AUTO_PIN_HP_OUT;
3889 err = alc_auto_fill_dac_nids(codec);
3892 err = alc_auto_add_multi_channel_mode(codec);
3895 err = alc_auto_create_multi_out_ctls(codec, cfg);
3898 err = alc_auto_create_hp_out(codec);
3901 err = alc_auto_create_speaker_out(codec);
3904 err = alc_auto_create_input_ctls(codec);
3908 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3911 alc_auto_parse_digital(codec);
3913 if (!spec->no_analog)
3914 alc_remove_invalid_adc_nids(codec);
3917 alc_ssid_check(codec, ssid_nids);
3919 if (!spec->no_analog) {
3920 alc_auto_check_switches(codec);
3921 err = alc_auto_add_mic_boost(codec);
3926 if (spec->kctls.list)
3927 add_mixer(spec, spec->kctls.list);
3932 static int alc880_parse_auto_config(struct hda_codec *codec)
3934 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
3935 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
3936 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
3939 #ifdef CONFIG_SND_HDA_POWER_SAVE
3940 static const struct hda_amp_list alc880_loopbacks[] = {
3941 { 0x0b, HDA_INPUT, 0 },
3942 { 0x0b, HDA_INPUT, 1 },
3943 { 0x0b, HDA_INPUT, 2 },
3944 { 0x0b, HDA_INPUT, 3 },
3945 { 0x0b, HDA_INPUT, 4 },
3953 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3954 #define alc_board_config \
3955 snd_hda_check_board_config
3956 #define alc_board_codec_sid_config \
3957 snd_hda_check_board_codec_sid_config
3958 #include "alc_quirks.c"
3960 #define alc_board_config(codec, nums, models, tbl) -1
3961 #define alc_board_codec_sid_config(codec, nums, models, tbl) -1
3962 #define setup_preset(codec, x) /* NOP */
3966 * OK, here we have finally the patch for ALC880
3968 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3969 #include "alc880_quirks.c"
3972 static int patch_alc880(struct hda_codec *codec)
3974 struct alc_spec *spec;
3978 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3984 spec->mixer_nid = 0x0b;
3985 spec->need_dac_fix = 1;
3987 board_config = alc_board_config(codec, ALC880_MODEL_LAST,
3988 alc880_models, alc880_cfg_tbl);
3989 if (board_config < 0) {
3990 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
3992 board_config = ALC_MODEL_AUTO;
3995 if (board_config == ALC_MODEL_AUTO) {
3996 /* automatic parse from the BIOS config */
3997 err = alc880_parse_auto_config(codec);
4000 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4003 "hda_codec: Cannot set up configuration "
4004 "from BIOS. Using 3-stack mode...\n");
4005 board_config = ALC880_3ST;
4010 if (board_config != ALC_MODEL_AUTO) {
4011 spec->vmaster_nid = 0x0c;
4012 setup_preset(codec, &alc880_presets[board_config]);
4015 if (!spec->no_analog && !spec->adc_nids) {
4016 alc_auto_fill_adc_caps(codec);
4017 alc_rebuild_imux_for_auto_mic(codec);
4018 alc_remove_invalid_adc_nids(codec);
4021 if (!spec->no_analog && !spec->cap_mixer)
4022 set_capture_mixer(codec);
4024 if (!spec->no_analog) {
4025 err = snd_hda_attach_beep_device(codec, 0x1);
4028 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4031 codec->patch_ops = alc_patch_ops;
4032 if (board_config == ALC_MODEL_AUTO)
4033 spec->init_hook = alc_auto_init_std;
4035 codec->patch_ops.build_controls = __alc_build_controls;
4036 #ifdef CONFIG_SND_HDA_POWER_SAVE
4037 if (!spec->loopback.amplist)
4038 spec->loopback.amplist = alc880_loopbacks;
4052 static int alc260_parse_auto_config(struct hda_codec *codec)
4054 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
4055 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
4056 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
4059 #ifdef CONFIG_SND_HDA_POWER_SAVE
4060 static const struct hda_amp_list alc260_loopbacks[] = {
4061 { 0x07, HDA_INPUT, 0 },
4062 { 0x07, HDA_INPUT, 1 },
4063 { 0x07, HDA_INPUT, 2 },
4064 { 0x07, HDA_INPUT, 3 },
4065 { 0x07, HDA_INPUT, 4 },
4077 static const struct alc_fixup alc260_fixups[] = {
4078 [PINFIX_HP_DC5750] = {
4079 .type = ALC_FIXUP_PINS,
4080 .v.pins = (const struct alc_pincfg[]) {
4081 { 0x11, 0x90130110 }, /* speaker */
4087 static const struct snd_pci_quirk alc260_fixup_tbl[] = {
4088 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", PINFIX_HP_DC5750),
4094 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4095 #include "alc260_quirks.c"
4098 static int patch_alc260(struct hda_codec *codec)
4100 struct alc_spec *spec;
4101 int err, board_config;
4103 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4109 spec->mixer_nid = 0x07;
4111 board_config = alc_board_config(codec, ALC260_MODEL_LAST,
4112 alc260_models, alc260_cfg_tbl);
4113 if (board_config < 0) {
4114 snd_printd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4116 board_config = ALC_MODEL_AUTO;
4119 if (board_config == ALC_MODEL_AUTO) {
4120 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
4121 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4124 if (board_config == ALC_MODEL_AUTO) {
4125 /* automatic parse from the BIOS config */
4126 err = alc260_parse_auto_config(codec);
4129 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4132 "hda_codec: Cannot set up configuration "
4133 "from BIOS. Using base mode...\n");
4134 board_config = ALC260_BASIC;
4139 if (board_config != ALC_MODEL_AUTO) {
4140 setup_preset(codec, &alc260_presets[board_config]);
4141 spec->vmaster_nid = 0x08;
4144 if (!spec->no_analog && !spec->adc_nids) {
4145 alc_auto_fill_adc_caps(codec);
4146 alc_rebuild_imux_for_auto_mic(codec);
4147 alc_remove_invalid_adc_nids(codec);
4150 if (!spec->no_analog && !spec->cap_mixer)
4151 set_capture_mixer(codec);
4153 if (!spec->no_analog) {
4154 err = snd_hda_attach_beep_device(codec, 0x1);
4157 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
4160 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4162 codec->patch_ops = alc_patch_ops;
4163 if (board_config == ALC_MODEL_AUTO)
4164 spec->init_hook = alc_auto_init_std;
4166 codec->patch_ops.build_controls = __alc_build_controls;
4167 spec->shutup = alc_eapd_shutup;
4168 #ifdef CONFIG_SND_HDA_POWER_SAVE
4169 if (!spec->loopback.amplist)
4170 spec->loopback.amplist = alc260_loopbacks;
4182 * ALC882/883/885/888/889 support
4184 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
4185 * configuration. Each pin widget can choose any input DACs and a mixer.
4186 * Each ADC is connected from a mixer of all inputs. This makes possible
4187 * 6-channel independent captures.
4189 * In addition, an independent DAC for the multi-playback (not used in this
4192 #ifdef CONFIG_SND_HDA_POWER_SAVE
4193 #define alc882_loopbacks alc880_loopbacks
4200 PINFIX_ABIT_AW9D_MAX,
4203 PINFIX_ACER_ASPIRE_7736,
4205 ALC889_FIXUP_DAC_ROUTE,
4208 /* Fix the connection of some pins for ALC889:
4209 * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
4210 * work correctly (bko#42740)
4212 static void alc889_fixup_dac_route(struct hda_codec *codec,
4213 const struct alc_fixup *fix, int action)
4215 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
4216 /* fake the connections during parsing the tree */
4217 hda_nid_t conn1[2] = { 0x0c, 0x0d };
4218 hda_nid_t conn2[2] = { 0x0e, 0x0f };
4219 snd_hda_override_conn_list(codec, 0x14, 2, conn1);
4220 snd_hda_override_conn_list(codec, 0x15, 2, conn1);
4221 snd_hda_override_conn_list(codec, 0x18, 2, conn2);
4222 snd_hda_override_conn_list(codec, 0x1a, 2, conn2);
4223 } else if (action == ALC_FIXUP_ACT_PROBE) {
4224 /* restore the connections */
4225 hda_nid_t conn[5] = { 0x0c, 0x0d, 0x0e, 0x0f, 0x26 };
4226 snd_hda_override_conn_list(codec, 0x14, 5, conn);
4227 snd_hda_override_conn_list(codec, 0x15, 5, conn);
4228 snd_hda_override_conn_list(codec, 0x18, 5, conn);
4229 snd_hda_override_conn_list(codec, 0x1a, 5, conn);
4233 static const struct alc_fixup alc882_fixups[] = {
4234 [PINFIX_ABIT_AW9D_MAX] = {
4235 .type = ALC_FIXUP_PINS,
4236 .v.pins = (const struct alc_pincfg[]) {
4237 { 0x15, 0x01080104 }, /* side */
4238 { 0x16, 0x01011012 }, /* rear */
4239 { 0x17, 0x01016011 }, /* clfe */
4243 [PINFIX_LENOVO_Y530] = {
4244 .type = ALC_FIXUP_PINS,
4245 .v.pins = (const struct alc_pincfg[]) {
4246 { 0x15, 0x99130112 }, /* rear int speakers */
4247 { 0x16, 0x99130111 }, /* subwoofer */
4251 [PINFIX_PB_M5210] = {
4252 .type = ALC_FIXUP_VERBS,
4253 .v.verbs = (const struct hda_verb[]) {
4254 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
4258 [PINFIX_ACER_ASPIRE_7736] = {
4259 .type = ALC_FIXUP_SKU,
4260 .v.sku = ALC_FIXUP_SKU_IGNORE,
4262 [PINFIX_ASUS_W90V] = {
4263 .type = ALC_FIXUP_PINS,
4264 .v.pins = (const struct alc_pincfg[]) {
4265 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
4269 [ALC889_FIXUP_DAC_ROUTE] = {
4270 .type = ALC_FIXUP_FUNC,
4271 .v.func = alc889_fixup_dac_route,
4275 static const struct snd_pci_quirk alc882_fixup_tbl[] = {
4276 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", PINFIX_PB_M5210),
4277 SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE),
4278 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", PINFIX_ASUS_W90V),
4279 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", PINFIX_LENOVO_Y530),
4280 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
4281 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", PINFIX_ACER_ASPIRE_7736),
4286 * BIOS auto configuration
4288 /* almost identical with ALC880 parser... */
4289 static int alc882_parse_auto_config(struct hda_codec *codec)
4291 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
4292 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4293 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
4298 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4299 #include "alc882_quirks.c"
4302 static int patch_alc882(struct hda_codec *codec)
4304 struct alc_spec *spec;
4305 int err, board_config;
4307 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4313 spec->mixer_nid = 0x0b;
4315 switch (codec->vendor_id) {
4320 /* ALC883 and variants */
4321 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
4325 err = alc_codec_rename_from_preset(codec);
4329 board_config = alc_board_config(codec, ALC882_MODEL_LAST,
4330 alc882_models, alc882_cfg_tbl);
4332 if (board_config < 0)
4333 board_config = alc_board_codec_sid_config(codec,
4334 ALC882_MODEL_LAST, alc882_models, alc882_ssid_cfg_tbl);
4336 if (board_config < 0) {
4337 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4339 board_config = ALC_MODEL_AUTO;
4342 if (board_config == ALC_MODEL_AUTO) {
4343 alc_pick_fixup(codec, NULL, alc882_fixup_tbl, alc882_fixups);
4344 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4347 alc_auto_parse_customize_define(codec);
4349 if (board_config == ALC_MODEL_AUTO) {
4350 /* automatic parse from the BIOS config */
4351 err = alc882_parse_auto_config(codec);
4354 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4357 "hda_codec: Cannot set up configuration "
4358 "from BIOS. Using base mode...\n");
4359 board_config = ALC882_3ST_DIG;
4364 if (board_config != ALC_MODEL_AUTO) {
4365 setup_preset(codec, &alc882_presets[board_config]);
4366 spec->vmaster_nid = 0x0c;
4369 if (!spec->no_analog && !spec->adc_nids) {
4370 alc_auto_fill_adc_caps(codec);
4371 alc_rebuild_imux_for_auto_mic(codec);
4372 alc_remove_invalid_adc_nids(codec);
4375 if (!spec->no_analog && !spec->cap_mixer)
4376 set_capture_mixer(codec);
4378 if (!spec->no_analog && has_cdefine_beep(codec)) {
4379 err = snd_hda_attach_beep_device(codec, 0x1);
4382 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4385 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4387 codec->patch_ops = alc_patch_ops;
4388 if (board_config == ALC_MODEL_AUTO)
4389 spec->init_hook = alc_auto_init_std;
4391 codec->patch_ops.build_controls = __alc_build_controls;
4393 #ifdef CONFIG_SND_HDA_POWER_SAVE
4394 if (!spec->loopback.amplist)
4395 spec->loopback.amplist = alc882_loopbacks;
4409 static int alc262_parse_auto_config(struct hda_codec *codec)
4411 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
4412 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4413 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
4424 static const struct alc_fixup alc262_fixups[] = {
4425 [PINFIX_FSC_H270] = {
4426 .type = ALC_FIXUP_PINS,
4427 .v.pins = (const struct alc_pincfg[]) {
4428 { 0x14, 0x99130110 }, /* speaker */
4429 { 0x15, 0x0221142f }, /* front HP */
4430 { 0x1b, 0x0121141f }, /* rear HP */
4434 [PINFIX_HP_Z200] = {
4435 .type = ALC_FIXUP_PINS,
4436 .v.pins = (const struct alc_pincfg[]) {
4437 { 0x16, 0x99130120 }, /* internal speaker */
4443 static const struct snd_pci_quirk alc262_fixup_tbl[] = {
4444 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", PINFIX_HP_Z200),
4445 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", PINFIX_FSC_H270),
4450 #ifdef CONFIG_SND_HDA_POWER_SAVE
4451 #define alc262_loopbacks alc880_loopbacks
4456 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4457 #include "alc262_quirks.c"
4460 static int patch_alc262(struct hda_codec *codec)
4462 struct alc_spec *spec;
4466 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4472 spec->mixer_nid = 0x0b;
4475 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
4480 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4481 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
4482 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4483 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
4486 alc_auto_parse_customize_define(codec);
4488 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
4490 board_config = alc_board_config(codec, ALC262_MODEL_LAST,
4491 alc262_models, alc262_cfg_tbl);
4493 if (board_config < 0) {
4494 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4496 board_config = ALC_MODEL_AUTO;
4499 if (board_config == ALC_MODEL_AUTO) {
4500 alc_pick_fixup(codec, NULL, alc262_fixup_tbl, alc262_fixups);
4501 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4504 if (board_config == ALC_MODEL_AUTO) {
4505 /* automatic parse from the BIOS config */
4506 err = alc262_parse_auto_config(codec);
4509 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4512 "hda_codec: Cannot set up configuration "
4513 "from BIOS. Using base mode...\n");
4514 board_config = ALC262_BASIC;
4519 if (board_config != ALC_MODEL_AUTO) {
4520 setup_preset(codec, &alc262_presets[board_config]);
4521 spec->vmaster_nid = 0x0c;
4524 if (!spec->no_analog && !spec->adc_nids) {
4525 alc_auto_fill_adc_caps(codec);
4526 alc_rebuild_imux_for_auto_mic(codec);
4527 alc_remove_invalid_adc_nids(codec);
4530 if (!spec->no_analog && !spec->cap_mixer)
4531 set_capture_mixer(codec);
4533 if (!spec->no_analog && has_cdefine_beep(codec)) {
4534 err = snd_hda_attach_beep_device(codec, 0x1);
4537 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4540 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4542 codec->patch_ops = alc_patch_ops;
4543 if (board_config == ALC_MODEL_AUTO)
4544 spec->init_hook = alc_auto_init_std;
4545 spec->shutup = alc_eapd_shutup;
4547 #ifdef CONFIG_SND_HDA_POWER_SAVE
4548 if (!spec->loopback.amplist)
4549 spec->loopback.amplist = alc262_loopbacks;
4562 /* bind Beep switches of both NID 0x0f and 0x10 */
4563 static const struct hda_bind_ctls alc268_bind_beep_sw = {
4564 .ops = &snd_hda_bind_sw,
4566 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
4567 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
4572 static const struct snd_kcontrol_new alc268_beep_mixer[] = {
4573 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
4574 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
4578 /* set PCBEEP vol = 0, mute connections */
4579 static const struct hda_verb alc268_beep_init_verbs[] = {
4580 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4581 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4582 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4587 * BIOS auto configuration
4589 static int alc268_parse_auto_config(struct hda_codec *codec)
4591 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4592 struct alc_spec *spec = codec->spec;
4593 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
4595 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
4596 add_mixer(spec, alc268_beep_mixer);
4597 add_verb(spec, alc268_beep_init_verbs);
4605 static int patch_alc268(struct hda_codec *codec)
4607 struct alc_spec *spec;
4608 int i, has_beep, err;
4610 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4616 /* ALC268 has no aa-loopback mixer */
4618 /* automatic parse from the BIOS config */
4619 err = alc268_parse_auto_config(codec);
4624 for (i = 0; i < spec->num_mixers; i++) {
4625 if (spec->mixers[i] == alc268_beep_mixer) {
4632 err = snd_hda_attach_beep_device(codec, 0x1);
4635 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
4636 /* override the amp caps for beep generator */
4637 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
4638 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
4639 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
4640 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4641 (0 << AC_AMPCAP_MUTE_SHIFT));
4644 if (!spec->no_analog && !spec->adc_nids) {
4645 alc_auto_fill_adc_caps(codec);
4646 alc_rebuild_imux_for_auto_mic(codec);
4647 alc_remove_invalid_adc_nids(codec);
4650 if (!spec->no_analog && !spec->cap_mixer)
4651 set_capture_mixer(codec);
4653 codec->patch_ops = alc_patch_ops;
4654 spec->init_hook = alc_auto_init_std;
4655 spec->shutup = alc_eapd_shutup;
4667 #ifdef CONFIG_SND_HDA_POWER_SAVE
4668 #define alc269_loopbacks alc880_loopbacks
4671 static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
4675 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
4676 /* NID is set in alc_build_pcms */
4678 .open = alc_playback_pcm_open,
4679 .prepare = alc_playback_pcm_prepare,
4680 .cleanup = alc_playback_pcm_cleanup
4684 static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
4688 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
4689 /* NID is set in alc_build_pcms */
4692 #ifdef CONFIG_SND_HDA_POWER_SAVE
4693 static int alc269_mic2_for_mute_led(struct hda_codec *codec)
4695 switch (codec->subsystem_id) {
4702 static int alc269_mic2_mute_check_ps(struct hda_codec *codec, hda_nid_t nid)
4704 /* update mute-LED according to the speaker mute state */
4705 if (nid == 0x01 || nid == 0x14) {
4707 if (snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0) &
4712 /* mic2 vref pin is used for mute LED control */
4713 snd_hda_codec_update_cache(codec, 0x19, 0,
4714 AC_VERB_SET_PIN_WIDGET_CONTROL,
4717 return alc_check_power_status(codec, nid);
4719 #endif /* CONFIG_SND_HDA_POWER_SAVE */
4721 /* different alc269-variants */
4723 ALC269_TYPE_ALC269VA,
4724 ALC269_TYPE_ALC269VB,
4725 ALC269_TYPE_ALC269VC,
4729 * BIOS auto configuration
4731 static int alc269_parse_auto_config(struct hda_codec *codec)
4733 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
4734 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
4735 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4736 struct alc_spec *spec = codec->spec;
4737 const hda_nid_t *ssids = spec->codec_variant == ALC269_TYPE_ALC269VA ?
4738 alc269va_ssids : alc269_ssids;
4740 return alc_parse_auto_config(codec, alc269_ignore, ssids);
4743 static void alc269_toggle_power_output(struct hda_codec *codec, int power_up)
4745 int val = alc_read_coef_idx(codec, 0x04);
4750 alc_write_coef_idx(codec, 0x04, val);
4753 static void alc269_shutup(struct hda_codec *codec)
4755 if ((alc_get_coef0(codec) & 0x00ff) == 0x017)
4756 alc269_toggle_power_output(codec, 0);
4757 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
4758 alc269_toggle_power_output(codec, 0);
4764 static int alc269_resume(struct hda_codec *codec)
4766 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
4767 alc269_toggle_power_output(codec, 0);
4771 codec->patch_ops.init(codec);
4773 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
4774 alc269_toggle_power_output(codec, 1);
4778 if ((alc_get_coef0(codec) & 0x00ff) == 0x018)
4779 alc269_toggle_power_output(codec, 1);
4781 snd_hda_codec_resume_amp(codec);
4782 snd_hda_codec_resume_cache(codec);
4783 hda_call_check_power_status(codec, 0x01);
4786 #endif /* CONFIG_PM */
4788 static void alc269_fixup_hweq(struct hda_codec *codec,
4789 const struct alc_fixup *fix, int action)
4793 if (action != ALC_FIXUP_ACT_INIT)
4795 coef = alc_read_coef_idx(codec, 0x1e);
4796 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
4799 static void alc271_fixup_dmic(struct hda_codec *codec,
4800 const struct alc_fixup *fix, int action)
4802 static const struct hda_verb verbs[] = {
4803 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
4804 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
4809 if (strcmp(codec->chip_name, "ALC271X"))
4811 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
4812 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
4813 snd_hda_sequence_write(codec, verbs);
4816 static void alc269_fixup_pcm_44k(struct hda_codec *codec,
4817 const struct alc_fixup *fix, int action)
4819 struct alc_spec *spec = codec->spec;
4821 if (action != ALC_FIXUP_ACT_PROBE)
4824 /* Due to a hardware problem on Lenovo Ideadpad, we need to
4825 * fix the sample rate of analog I/O to 44.1kHz
4827 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
4828 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
4831 static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
4832 const struct alc_fixup *fix, int action)
4836 if (action != ALC_FIXUP_ACT_INIT)
4838 /* The digital-mic unit sends PDM (differential signal) instead of
4839 * the standard PCM, thus you can't record a valid mono stream as is.
4840 * Below is a workaround specific to ALC269 to control the dmic
4841 * signal source as mono.
4843 coef = alc_read_coef_idx(codec, 0x07);
4844 alc_write_coef_idx(codec, 0x07, coef | 0x80);
4847 static void alc269_quanta_automute(struct hda_codec *codec)
4849 update_outputs(codec);
4851 snd_hda_codec_write(codec, 0x20, 0,
4852 AC_VERB_SET_COEF_INDEX, 0x0c);
4853 snd_hda_codec_write(codec, 0x20, 0,
4854 AC_VERB_SET_PROC_COEF, 0x680);
4856 snd_hda_codec_write(codec, 0x20, 0,
4857 AC_VERB_SET_COEF_INDEX, 0x0c);
4858 snd_hda_codec_write(codec, 0x20, 0,
4859 AC_VERB_SET_PROC_COEF, 0x480);
4862 static void alc269_fixup_quanta_mute(struct hda_codec *codec,
4863 const struct alc_fixup *fix, int action)
4865 struct alc_spec *spec = codec->spec;
4866 if (action != ALC_FIXUP_ACT_PROBE)
4868 spec->automute_hook = alc269_quanta_automute;
4872 ALC269_FIXUP_SONY_VAIO,
4873 ALC275_FIXUP_SONY_VAIO_GPIO2,
4874 ALC269_FIXUP_DELL_M101Z,
4875 ALC269_FIXUP_SKU_IGNORE,
4876 ALC269_FIXUP_ASUS_G73JW,
4877 ALC269_FIXUP_LENOVO_EAPD,
4878 ALC275_FIXUP_SONY_HWEQ,
4880 ALC269_FIXUP_PCM_44K,
4881 ALC269_FIXUP_STEREO_DMIC,
4882 ALC269_FIXUP_QUANTA_MUTE,
4883 ALC269_FIXUP_LIFEBOOK,
4886 ALC269VB_FIXUP_AMIC,
4887 ALC269VB_FIXUP_DMIC,
4890 static const struct alc_fixup alc269_fixups[] = {
4891 [ALC269_FIXUP_SONY_VAIO] = {
4892 .type = ALC_FIXUP_VERBS,
4893 .v.verbs = (const struct hda_verb[]) {
4894 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
4898 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
4899 .type = ALC_FIXUP_VERBS,
4900 .v.verbs = (const struct hda_verb[]) {
4901 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
4902 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
4903 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
4907 .chain_id = ALC269_FIXUP_SONY_VAIO
4909 [ALC269_FIXUP_DELL_M101Z] = {
4910 .type = ALC_FIXUP_VERBS,
4911 .v.verbs = (const struct hda_verb[]) {
4912 /* Enables internal speaker */
4913 {0x20, AC_VERB_SET_COEF_INDEX, 13},
4914 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
4918 [ALC269_FIXUP_SKU_IGNORE] = {
4919 .type = ALC_FIXUP_SKU,
4920 .v.sku = ALC_FIXUP_SKU_IGNORE,
4922 [ALC269_FIXUP_ASUS_G73JW] = {
4923 .type = ALC_FIXUP_PINS,
4924 .v.pins = (const struct alc_pincfg[]) {
4925 { 0x17, 0x99130111 }, /* subwoofer */
4929 [ALC269_FIXUP_LENOVO_EAPD] = {
4930 .type = ALC_FIXUP_VERBS,
4931 .v.verbs = (const struct hda_verb[]) {
4932 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
4936 [ALC275_FIXUP_SONY_HWEQ] = {
4937 .type = ALC_FIXUP_FUNC,
4938 .v.func = alc269_fixup_hweq,
4940 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
4942 [ALC271_FIXUP_DMIC] = {
4943 .type = ALC_FIXUP_FUNC,
4944 .v.func = alc271_fixup_dmic,
4946 [ALC269_FIXUP_PCM_44K] = {
4947 .type = ALC_FIXUP_FUNC,
4948 .v.func = alc269_fixup_pcm_44k,
4950 [ALC269_FIXUP_STEREO_DMIC] = {
4951 .type = ALC_FIXUP_FUNC,
4952 .v.func = alc269_fixup_stereo_dmic,
4954 [ALC269_FIXUP_QUANTA_MUTE] = {
4955 .type = ALC_FIXUP_FUNC,
4956 .v.func = alc269_fixup_quanta_mute,
4958 [ALC269_FIXUP_LIFEBOOK] = {
4959 .type = ALC_FIXUP_PINS,
4960 .v.pins = (const struct alc_pincfg[]) {
4961 { 0x1a, 0x2101103f }, /* dock line-out */
4962 { 0x1b, 0x23a11040 }, /* dock mic-in */
4966 .chain_id = ALC269_FIXUP_QUANTA_MUTE
4968 [ALC269_FIXUP_AMIC] = {
4969 .type = ALC_FIXUP_PINS,
4970 .v.pins = (const struct alc_pincfg[]) {
4971 { 0x14, 0x99130110 }, /* speaker */
4972 { 0x15, 0x0121401f }, /* HP out */
4973 { 0x18, 0x01a19c20 }, /* mic */
4974 { 0x19, 0x99a3092f }, /* int-mic */
4978 [ALC269_FIXUP_DMIC] = {
4979 .type = ALC_FIXUP_PINS,
4980 .v.pins = (const struct alc_pincfg[]) {
4981 { 0x12, 0x99a3092f }, /* int-mic */
4982 { 0x14, 0x99130110 }, /* speaker */
4983 { 0x15, 0x0121401f }, /* HP out */
4984 { 0x18, 0x01a19c20 }, /* mic */
4988 [ALC269VB_FIXUP_AMIC] = {
4989 .type = ALC_FIXUP_PINS,
4990 .v.pins = (const struct alc_pincfg[]) {
4991 { 0x14, 0x99130110 }, /* speaker */
4992 { 0x18, 0x01a19c20 }, /* mic */
4993 { 0x19, 0x99a3092f }, /* int-mic */
4994 { 0x21, 0x0121401f }, /* HP out */
4998 [ALC269_FIXUP_DMIC] = {
4999 .type = ALC_FIXUP_PINS,
5000 .v.pins = (const struct alc_pincfg[]) {
5001 { 0x12, 0x99a3092f }, /* int-mic */
5002 { 0x14, 0x99130110 }, /* speaker */
5003 { 0x18, 0x01a19c20 }, /* mic */
5004 { 0x21, 0x0121401f }, /* HP out */
5010 static const struct snd_pci_quirk alc269_fixup_tbl[] = {
5011 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
5012 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
5013 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
5014 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
5015 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
5016 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
5017 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
5018 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
5019 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
5020 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
5021 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
5022 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
5023 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
5024 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
5025 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
5026 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
5027 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
5028 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
5029 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_QUANTA_MUTE),
5030 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K),
5031 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
5034 /* Below is a quirk table taken from the old code.
5035 * Basically the device should work as is without the fixup table.
5036 * If BIOS doesn't give a proper info, enable the corresponding
5039 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
5041 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
5042 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
5043 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
5044 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
5045 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
5046 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
5047 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
5048 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
5049 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
5050 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
5051 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
5052 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
5053 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
5054 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
5055 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
5056 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
5057 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
5058 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
5059 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
5060 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
5061 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
5062 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
5063 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
5064 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
5065 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
5066 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
5067 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
5068 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
5069 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
5070 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
5071 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
5072 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
5073 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
5074 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
5075 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
5076 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
5077 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
5078 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
5079 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
5084 static const struct alc_model_fixup alc269_fixup_models[] = {
5085 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
5086 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
5091 static int alc269_fill_coef(struct hda_codec *codec)
5093 struct alc_spec *spec = codec->spec;
5096 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
5099 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
5100 alc_write_coef_idx(codec, 0xf, 0x960b);
5101 alc_write_coef_idx(codec, 0xe, 0x8817);
5104 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
5105 alc_write_coef_idx(codec, 0xf, 0x960b);
5106 alc_write_coef_idx(codec, 0xe, 0x8814);
5109 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
5110 val = alc_read_coef_idx(codec, 0x04);
5111 /* Power up output pin */
5112 alc_write_coef_idx(codec, 0x04, val | (1<<11));
5115 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
5116 val = alc_read_coef_idx(codec, 0xd);
5117 if ((val & 0x0c00) >> 10 != 0x1) {
5118 /* Capless ramp up clock control */
5119 alc_write_coef_idx(codec, 0xd, val | (1<<10));
5121 val = alc_read_coef_idx(codec, 0x17);
5122 if ((val & 0x01c0) >> 6 != 0x4) {
5123 /* Class D power on reset */
5124 alc_write_coef_idx(codec, 0x17, val | (1<<7));
5128 val = alc_read_coef_idx(codec, 0xd); /* Class D */
5129 alc_write_coef_idx(codec, 0xd, val | (1<<14));
5131 val = alc_read_coef_idx(codec, 0x4); /* HP */
5132 alc_write_coef_idx(codec, 0x4, val | (1<<11));
5139 static int patch_alc269(struct hda_codec *codec)
5141 struct alc_spec *spec;
5144 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5150 spec->mixer_nid = 0x0b;
5152 alc_auto_parse_customize_define(codec);
5154 err = alc_codec_rename_from_preset(codec);
5158 if (codec->vendor_id == 0x10ec0269) {
5159 spec->codec_variant = ALC269_TYPE_ALC269VA;
5160 switch (alc_get_coef0(codec) & 0x00f0) {
5162 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
5163 spec->cdefine.platform_type == 1)
5164 err = alc_codec_rename(codec, "ALC271X");
5165 spec->codec_variant = ALC269_TYPE_ALC269VB;
5168 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
5169 codec->bus->pci->subsystem_device == 0x21f3)
5170 err = alc_codec_rename(codec, "ALC3202");
5171 spec->codec_variant = ALC269_TYPE_ALC269VC;
5174 alc_fix_pll_init(codec, 0x20, 0x04, 15);
5178 alc269_fill_coef(codec);
5181 alc_pick_fixup(codec, alc269_fixup_models,
5182 alc269_fixup_tbl, alc269_fixups);
5183 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5185 /* automatic parse from the BIOS config */
5186 err = alc269_parse_auto_config(codec);
5190 if (!spec->no_analog && !spec->adc_nids) {
5191 alc_auto_fill_adc_caps(codec);
5192 alc_rebuild_imux_for_auto_mic(codec);
5193 alc_remove_invalid_adc_nids(codec);
5196 if (!spec->no_analog && !spec->cap_mixer)
5197 set_capture_mixer(codec);
5199 if (!spec->no_analog && has_cdefine_beep(codec)) {
5200 err = snd_hda_attach_beep_device(codec, 0x1);
5203 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
5206 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5208 codec->patch_ops = alc_patch_ops;
5210 codec->patch_ops.resume = alc269_resume;
5212 spec->init_hook = alc_auto_init_std;
5213 spec->shutup = alc269_shutup;
5215 #ifdef CONFIG_SND_HDA_POWER_SAVE
5216 if (!spec->loopback.amplist)
5217 spec->loopback.amplist = alc269_loopbacks;
5218 if (alc269_mic2_for_mute_led(codec))
5219 codec->patch_ops.check_power_status = alc269_mic2_mute_check_ps;
5233 static int alc861_parse_auto_config(struct hda_codec *codec)
5235 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
5236 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
5237 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
5240 #ifdef CONFIG_SND_HDA_POWER_SAVE
5241 static const struct hda_amp_list alc861_loopbacks[] = {
5242 { 0x15, HDA_INPUT, 0 },
5243 { 0x15, HDA_INPUT, 1 },
5244 { 0x15, HDA_INPUT, 2 },
5245 { 0x15, HDA_INPUT, 3 },
5251 /* Pin config fixes */
5253 PINFIX_FSC_AMILO_PI1505,
5257 /* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
5258 static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
5259 const struct alc_fixup *fix, int action)
5261 struct alc_spec *spec = codec->spec;
5264 if (action != ALC_FIXUP_ACT_INIT)
5266 val = snd_hda_codec_read(codec, 0x0f, 0,
5267 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5268 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
5269 val |= AC_PINCTL_IN_EN;
5270 val |= AC_PINCTL_VREF_50;
5271 snd_hda_codec_write(codec, 0x0f, 0,
5272 AC_VERB_SET_PIN_WIDGET_CONTROL, val);
5273 spec->keep_vref_in_automute = 1;
5276 static const struct alc_fixup alc861_fixups[] = {
5277 [PINFIX_FSC_AMILO_PI1505] = {
5278 .type = ALC_FIXUP_PINS,
5279 .v.pins = (const struct alc_pincfg[]) {
5280 { 0x0b, 0x0221101f }, /* HP */
5281 { 0x0f, 0x90170310 }, /* speaker */
5285 [PINFIX_ASUS_A6RP] = {
5286 .type = ALC_FIXUP_FUNC,
5287 .v.func = alc861_fixup_asus_amp_vref_0f,
5291 static const struct snd_pci_quirk alc861_fixup_tbl[] = {
5292 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", PINFIX_ASUS_A6RP),
5293 SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", PINFIX_ASUS_A6RP),
5294 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", PINFIX_FSC_AMILO_PI1505),
5300 static int patch_alc861(struct hda_codec *codec)
5302 struct alc_spec *spec;
5305 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5311 spec->mixer_nid = 0x15;
5313 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
5314 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5316 /* automatic parse from the BIOS config */
5317 err = alc861_parse_auto_config(codec);
5321 if (!spec->no_analog && !spec->adc_nids) {
5322 alc_auto_fill_adc_caps(codec);
5323 alc_rebuild_imux_for_auto_mic(codec);
5324 alc_remove_invalid_adc_nids(codec);
5327 if (!spec->no_analog && !spec->cap_mixer)
5328 set_capture_mixer(codec);
5330 if (!spec->no_analog) {
5331 err = snd_hda_attach_beep_device(codec, 0x23);
5334 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
5337 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5339 codec->patch_ops = alc_patch_ops;
5340 spec->init_hook = alc_auto_init_std;
5341 #ifdef CONFIG_SND_HDA_POWER_SAVE
5342 spec->power_hook = alc_power_eapd;
5343 if (!spec->loopback.amplist)
5344 spec->loopback.amplist = alc861_loopbacks;
5359 * In addition, an independent DAC
5361 #ifdef CONFIG_SND_HDA_POWER_SAVE
5362 #define alc861vd_loopbacks alc880_loopbacks
5365 static int alc861vd_parse_auto_config(struct hda_codec *codec)
5367 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
5368 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5369 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
5373 ALC660VD_FIX_ASUS_GPIO1,
5374 ALC861VD_FIX_DALLAS,
5377 /* exclude VREF80 */
5378 static void alc861vd_fixup_dallas(struct hda_codec *codec,
5379 const struct alc_fixup *fix, int action)
5381 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
5382 snd_hda_override_pin_caps(codec, 0x18, 0x00001714);
5383 snd_hda_override_pin_caps(codec, 0x19, 0x0000171c);
5387 static const struct alc_fixup alc861vd_fixups[] = {
5388 [ALC660VD_FIX_ASUS_GPIO1] = {
5389 .type = ALC_FIXUP_VERBS,
5390 .v.verbs = (const struct hda_verb[]) {
5392 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
5393 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5394 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5398 [ALC861VD_FIX_DALLAS] = {
5399 .type = ALC_FIXUP_FUNC,
5400 .v.func = alc861vd_fixup_dallas,
5404 static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
5405 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
5406 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
5407 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
5411 static const struct hda_verb alc660vd_eapd_verbs[] = {
5412 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
5413 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
5419 static int patch_alc861vd(struct hda_codec *codec)
5421 struct alc_spec *spec;
5424 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5430 spec->mixer_nid = 0x0b;
5432 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
5433 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5435 /* automatic parse from the BIOS config */
5436 err = alc861vd_parse_auto_config(codec);
5440 if (codec->vendor_id == 0x10ec0660) {
5441 /* always turn on EAPD */
5442 add_verb(spec, alc660vd_eapd_verbs);
5445 if (!spec->no_analog && !spec->adc_nids) {
5446 alc_auto_fill_adc_caps(codec);
5447 alc_rebuild_imux_for_auto_mic(codec);
5448 alc_remove_invalid_adc_nids(codec);
5451 if (!spec->no_analog && !spec->cap_mixer)
5452 set_capture_mixer(codec);
5454 if (!spec->no_analog) {
5455 err = snd_hda_attach_beep_device(codec, 0x23);
5458 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5461 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5463 codec->patch_ops = alc_patch_ops;
5465 spec->init_hook = alc_auto_init_std;
5466 spec->shutup = alc_eapd_shutup;
5467 #ifdef CONFIG_SND_HDA_POWER_SAVE
5468 if (!spec->loopback.amplist)
5469 spec->loopback.amplist = alc861vd_loopbacks;
5482 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
5483 * configuration. Each pin widget can choose any input DACs and a mixer.
5484 * Each ADC is connected from a mixer of all inputs. This makes possible
5485 * 6-channel independent captures.
5487 * In addition, an independent DAC for the multi-playback (not used in this
5490 #ifdef CONFIG_SND_HDA_POWER_SAVE
5491 #define alc662_loopbacks alc880_loopbacks
5495 * BIOS auto configuration
5498 static int alc662_parse_auto_config(struct hda_codec *codec)
5500 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
5501 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
5502 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5503 const hda_nid_t *ssids;
5505 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
5506 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
5507 ssids = alc663_ssids;
5509 ssids = alc662_ssids;
5510 return alc_parse_auto_config(codec, alc662_ignore, ssids);
5513 static void alc272_fixup_mario(struct hda_codec *codec,
5514 const struct alc_fixup *fix, int action)
5516 if (action != ALC_FIXUP_ACT_PROBE)
5518 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
5519 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
5520 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
5521 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5522 (0 << AC_AMPCAP_MUTE_SHIFT)))
5524 "hda_codec: failed to override amp caps for NID 0x2\n");
5528 ALC662_FIXUP_ASPIRE,
5529 ALC662_FIXUP_IDEAPAD,
5531 ALC662_FIXUP_CZC_P10T,
5532 ALC662_FIXUP_SKU_IGNORE,
5533 ALC662_FIXUP_HP_RP5800,
5534 ALC662_FIXUP_ASUS_MODE1,
5535 ALC662_FIXUP_ASUS_MODE2,
5536 ALC662_FIXUP_ASUS_MODE3,
5537 ALC662_FIXUP_ASUS_MODE4,
5538 ALC662_FIXUP_ASUS_MODE5,
5539 ALC662_FIXUP_ASUS_MODE6,
5540 ALC662_FIXUP_ASUS_MODE7,
5541 ALC662_FIXUP_ASUS_MODE8,
5544 static const struct alc_fixup alc662_fixups[] = {
5545 [ALC662_FIXUP_ASPIRE] = {
5546 .type = ALC_FIXUP_PINS,
5547 .v.pins = (const struct alc_pincfg[]) {
5548 { 0x15, 0x99130112 }, /* subwoofer */
5552 [ALC662_FIXUP_IDEAPAD] = {
5553 .type = ALC_FIXUP_PINS,
5554 .v.pins = (const struct alc_pincfg[]) {
5555 { 0x17, 0x99130112 }, /* subwoofer */
5559 [ALC272_FIXUP_MARIO] = {
5560 .type = ALC_FIXUP_FUNC,
5561 .v.func = alc272_fixup_mario,
5563 [ALC662_FIXUP_CZC_P10T] = {
5564 .type = ALC_FIXUP_VERBS,
5565 .v.verbs = (const struct hda_verb[]) {
5566 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
5570 [ALC662_FIXUP_SKU_IGNORE] = {
5571 .type = ALC_FIXUP_SKU,
5572 .v.sku = ALC_FIXUP_SKU_IGNORE,
5574 [ALC662_FIXUP_HP_RP5800] = {
5575 .type = ALC_FIXUP_PINS,
5576 .v.pins = (const struct alc_pincfg[]) {
5577 { 0x14, 0x0221201f }, /* HP out */
5581 .chain_id = ALC662_FIXUP_SKU_IGNORE
5583 [ALC662_FIXUP_ASUS_MODE1] = {
5584 .type = ALC_FIXUP_PINS,
5585 .v.pins = (const struct alc_pincfg[]) {
5586 { 0x14, 0x99130110 }, /* speaker */
5587 { 0x18, 0x01a19c20 }, /* mic */
5588 { 0x19, 0x99a3092f }, /* int-mic */
5589 { 0x21, 0x0121401f }, /* HP out */
5593 .chain_id = ALC662_FIXUP_SKU_IGNORE
5595 [ALC662_FIXUP_ASUS_MODE2] = {
5596 .type = ALC_FIXUP_PINS,
5597 .v.pins = (const struct alc_pincfg[]) {
5598 { 0x14, 0x99130110 }, /* speaker */
5599 { 0x18, 0x01a19820 }, /* mic */
5600 { 0x19, 0x99a3092f }, /* int-mic */
5601 { 0x1b, 0x0121401f }, /* HP out */
5605 .chain_id = ALC662_FIXUP_SKU_IGNORE
5607 [ALC662_FIXUP_ASUS_MODE3] = {
5608 .type = ALC_FIXUP_PINS,
5609 .v.pins = (const struct alc_pincfg[]) {
5610 { 0x14, 0x99130110 }, /* speaker */
5611 { 0x15, 0x0121441f }, /* HP */
5612 { 0x18, 0x01a19840 }, /* mic */
5613 { 0x19, 0x99a3094f }, /* int-mic */
5614 { 0x21, 0x01211420 }, /* HP2 */
5618 .chain_id = ALC662_FIXUP_SKU_IGNORE
5620 [ALC662_FIXUP_ASUS_MODE4] = {
5621 .type = ALC_FIXUP_PINS,
5622 .v.pins = (const struct alc_pincfg[]) {
5623 { 0x14, 0x99130110 }, /* speaker */
5624 { 0x16, 0x99130111 }, /* speaker */
5625 { 0x18, 0x01a19840 }, /* mic */
5626 { 0x19, 0x99a3094f }, /* int-mic */
5627 { 0x21, 0x0121441f }, /* HP */
5631 .chain_id = ALC662_FIXUP_SKU_IGNORE
5633 [ALC662_FIXUP_ASUS_MODE5] = {
5634 .type = ALC_FIXUP_PINS,
5635 .v.pins = (const struct alc_pincfg[]) {
5636 { 0x14, 0x99130110 }, /* speaker */
5637 { 0x15, 0x0121441f }, /* HP */
5638 { 0x16, 0x99130111 }, /* speaker */
5639 { 0x18, 0x01a19840 }, /* mic */
5640 { 0x19, 0x99a3094f }, /* int-mic */
5644 .chain_id = ALC662_FIXUP_SKU_IGNORE
5646 [ALC662_FIXUP_ASUS_MODE6] = {
5647 .type = ALC_FIXUP_PINS,
5648 .v.pins = (const struct alc_pincfg[]) {
5649 { 0x14, 0x99130110 }, /* speaker */
5650 { 0x15, 0x01211420 }, /* HP2 */
5651 { 0x18, 0x01a19840 }, /* mic */
5652 { 0x19, 0x99a3094f }, /* int-mic */
5653 { 0x1b, 0x0121441f }, /* HP */
5657 .chain_id = ALC662_FIXUP_SKU_IGNORE
5659 [ALC662_FIXUP_ASUS_MODE7] = {
5660 .type = ALC_FIXUP_PINS,
5661 .v.pins = (const struct alc_pincfg[]) {
5662 { 0x14, 0x99130110 }, /* speaker */
5663 { 0x17, 0x99130111 }, /* speaker */
5664 { 0x18, 0x01a19840 }, /* mic */
5665 { 0x19, 0x99a3094f }, /* int-mic */
5666 { 0x1b, 0x01214020 }, /* HP */
5667 { 0x21, 0x0121401f }, /* HP */
5671 .chain_id = ALC662_FIXUP_SKU_IGNORE
5673 [ALC662_FIXUP_ASUS_MODE8] = {
5674 .type = ALC_FIXUP_PINS,
5675 .v.pins = (const struct alc_pincfg[]) {
5676 { 0x14, 0x99130110 }, /* speaker */
5677 { 0x12, 0x99a30970 }, /* int-mic */
5678 { 0x15, 0x01214020 }, /* HP */
5679 { 0x17, 0x99130111 }, /* speaker */
5680 { 0x18, 0x01a19840 }, /* mic */
5681 { 0x21, 0x0121401f }, /* HP */
5685 .chain_id = ALC662_FIXUP_SKU_IGNORE
5689 static const struct snd_pci_quirk alc662_fixup_tbl[] = {
5690 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
5691 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
5692 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
5693 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
5694 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
5695 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
5696 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
5697 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
5698 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
5699 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
5702 /* Below is a quirk table taken from the old code.
5703 * Basically the device should work as is without the fixup table.
5704 * If BIOS doesn't give a proper info, enable the corresponding
5707 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
5708 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
5709 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
5710 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
5711 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
5712 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5713 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
5714 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
5715 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
5716 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5717 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
5718 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
5719 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
5720 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
5721 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
5722 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5723 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
5724 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
5725 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5726 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
5727 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
5728 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5729 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
5730 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
5731 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
5732 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5733 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
5734 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
5735 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5736 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
5737 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5738 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5739 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
5740 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
5741 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
5742 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
5743 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
5744 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
5745 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
5746 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5747 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
5748 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
5749 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
5750 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
5751 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
5752 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
5753 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
5754 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
5755 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
5756 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
5761 static const struct alc_model_fixup alc662_fixup_models[] = {
5762 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
5763 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
5764 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
5765 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
5766 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
5767 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
5768 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
5769 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
5770 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
5777 static int patch_alc662(struct hda_codec *codec)
5779 struct alc_spec *spec;
5782 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5788 spec->mixer_nid = 0x0b;
5790 /* handle multiple HPs as is */
5791 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
5793 alc_auto_parse_customize_define(codec);
5795 alc_fix_pll_init(codec, 0x20, 0x04, 15);
5797 err = alc_codec_rename_from_preset(codec);
5801 if ((alc_get_coef0(codec) & (1 << 14)) &&
5802 codec->bus->pci->subsystem_vendor == 0x1025 &&
5803 spec->cdefine.platform_type == 1) {
5804 if (alc_codec_rename(codec, "ALC272X") < 0)
5808 alc_pick_fixup(codec, alc662_fixup_models,
5809 alc662_fixup_tbl, alc662_fixups);
5810 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5811 /* automatic parse from the BIOS config */
5812 err = alc662_parse_auto_config(codec);
5816 if (!spec->no_analog && !spec->adc_nids) {
5817 alc_auto_fill_adc_caps(codec);
5818 alc_rebuild_imux_for_auto_mic(codec);
5819 alc_remove_invalid_adc_nids(codec);
5822 if (!spec->no_analog && !spec->cap_mixer)
5823 set_capture_mixer(codec);
5825 if (!spec->no_analog && has_cdefine_beep(codec)) {
5826 err = snd_hda_attach_beep_device(codec, 0x1);
5829 switch (codec->vendor_id) {
5831 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5836 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
5839 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
5844 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5846 codec->patch_ops = alc_patch_ops;
5847 spec->init_hook = alc_auto_init_std;
5848 spec->shutup = alc_eapd_shutup;
5850 #ifdef CONFIG_SND_HDA_POWER_SAVE
5851 if (!spec->loopback.amplist)
5852 spec->loopback.amplist = alc662_loopbacks;
5866 static int alc680_parse_auto_config(struct hda_codec *codec)
5868 return alc_parse_auto_config(codec, NULL, NULL);
5873 static int patch_alc680(struct hda_codec *codec)
5875 struct alc_spec *spec;
5878 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5884 /* ALC680 has no aa-loopback mixer */
5886 /* automatic parse from the BIOS config */
5887 err = alc680_parse_auto_config(codec);
5893 if (!spec->no_analog && !spec->cap_mixer)
5894 set_capture_mixer(codec);
5896 codec->patch_ops = alc_patch_ops;
5897 spec->init_hook = alc_auto_init_std;
5905 static const struct hda_codec_preset snd_hda_preset_realtek[] = {
5906 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
5907 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
5908 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
5909 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
5910 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
5911 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
5912 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
5913 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
5914 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
5915 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
5916 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
5917 .patch = patch_alc861 },
5918 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
5919 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
5920 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
5921 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
5922 .patch = patch_alc882 },
5923 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
5924 .patch = patch_alc662 },
5925 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
5926 .patch = patch_alc662 },
5927 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
5928 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
5929 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
5930 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
5931 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
5932 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
5933 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
5934 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
5935 .patch = patch_alc882 },
5936 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
5937 .patch = patch_alc882 },
5938 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
5939 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
5940 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
5941 .patch = patch_alc882 },
5942 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
5943 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
5944 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
5945 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
5949 MODULE_ALIAS("snd-hda-codec-id:10ec*");
5951 MODULE_LICENSE("GPL");
5952 MODULE_DESCRIPTION("Realtek HD-audio codec");
5954 static struct hda_codec_preset_list realtek_list = {
5955 .preset = snd_hda_preset_realtek,
5956 .owner = THIS_MODULE,
5959 static int __init patch_realtek_init(void)
5961 return snd_hda_add_codec_preset(&realtek_list);
5964 static void __exit patch_realtek_exit(void)
5966 snd_hda_delete_codec_preset(&realtek_list);
5969 module_init(patch_realtek_init)
5970 module_exit(patch_realtek_exit)