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() */
190 unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */
192 /* auto-mute control */
194 hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS];
197 int codec_variant; /* flag for other variants */
199 /* for virtual master */
200 hda_nid_t vmaster_nid;
201 #ifdef CONFIG_SND_HDA_POWER_SAVE
202 struct hda_loopback_check loopback;
207 unsigned int pll_coef_idx, pll_coef_bit;
212 const struct alc_fixup *fixup_list;
213 const char *fixup_name;
217 struct alc_multi_io multi_io[4];
220 struct snd_array bind_ctls;
223 #define ALC_MODEL_AUTO 0 /* common for all chips */
225 static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
226 int dir, unsigned int bits)
230 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
231 if (query_amp_caps(codec, nid, dir) & bits)
236 #define nid_has_mute(codec, nid, dir) \
237 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
238 #define nid_has_volume(codec, nid, dir) \
239 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
244 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
245 struct snd_ctl_elem_info *uinfo)
247 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
248 struct alc_spec *spec = codec->spec;
249 unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
250 if (mux_idx >= spec->num_mux_defs)
252 if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
254 return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
257 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
258 struct snd_ctl_elem_value *ucontrol)
260 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
261 struct alc_spec *spec = codec->spec;
262 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
264 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
268 static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
270 struct alc_spec *spec = codec->spec;
271 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
273 if (spec->cur_adc && spec->cur_adc != new_adc) {
274 /* stream is running, let's swap the current ADC */
275 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
276 spec->cur_adc = new_adc;
277 snd_hda_codec_setup_stream(codec, new_adc,
278 spec->cur_adc_stream_tag, 0,
279 spec->cur_adc_format);
285 static inline hda_nid_t get_capsrc(struct alc_spec *spec, int idx)
287 return spec->capsrc_nids ?
288 spec->capsrc_nids[idx] : spec->adc_nids[idx];
291 static void call_update_outputs(struct hda_codec *codec);
293 /* select the given imux item; either unmute exclusively or select the route */
294 static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
295 unsigned int idx, bool force)
297 struct alc_spec *spec = codec->spec;
298 const struct hda_input_mux *imux;
299 unsigned int mux_idx;
300 int i, type, num_conns;
303 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
304 imux = &spec->input_mux[mux_idx];
305 if (!imux->num_items && mux_idx > 0)
306 imux = &spec->input_mux[0];
307 if (!imux->num_items)
310 if (idx >= imux->num_items)
311 idx = imux->num_items - 1;
312 if (spec->cur_mux[adc_idx] == idx && !force)
314 spec->cur_mux[adc_idx] = idx;
316 /* for shared I/O, change the pin-control accordingly */
317 if (spec->shared_mic_hp) {
318 /* NOTE: this assumes that there are only two inputs, the
319 * first is the real internal mic and the second is HP jack.
321 snd_hda_codec_write(codec, spec->autocfg.inputs[1].pin, 0,
322 AC_VERB_SET_PIN_WIDGET_CONTROL,
323 spec->cur_mux[adc_idx] ?
324 PIN_VREF80 : PIN_HP);
325 spec->automute_speaker = !spec->cur_mux[adc_idx];
326 call_update_outputs(codec);
329 if (spec->dyn_adc_switch) {
330 alc_dyn_adc_pcm_resetup(codec, idx);
331 adc_idx = spec->dyn_adc_idx[idx];
334 nid = get_capsrc(spec, adc_idx);
337 num_conns = snd_hda_get_conn_list(codec, nid, NULL);
341 type = get_wcaps_type(get_wcaps(codec, nid));
342 if (type == AC_WID_AUD_MIX) {
343 /* Matrix-mixer style (e.g. ALC882) */
344 int active = imux->items[idx].index;
345 for (i = 0; i < num_conns; i++) {
346 unsigned int v = (i == active) ? 0 : HDA_AMP_MUTE;
347 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, i,
351 /* MUX style (e.g. ALC880) */
352 snd_hda_codec_write_cache(codec, nid, 0,
353 AC_VERB_SET_CONNECT_SEL,
354 imux->items[idx].index);
359 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
360 struct snd_ctl_elem_value *ucontrol)
362 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
363 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
364 return alc_mux_select(codec, adc_idx,
365 ucontrol->value.enumerated.item[0], false);
369 * set up the input pin config (depending on the given auto-pin type)
371 static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
374 unsigned int val = PIN_IN;
376 if (auto_pin_type == AUTO_PIN_MIC) {
379 oldval = snd_hda_codec_read(codec, nid, 0,
380 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
381 pincap = snd_hda_query_pin_caps(codec, nid);
382 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
383 /* if the default pin setup is vref50, we give it priority */
384 if ((pincap & AC_PINCAP_VREF_80) && oldval != PIN_VREF50)
386 else if (pincap & AC_PINCAP_VREF_50)
388 else if (pincap & AC_PINCAP_VREF_100)
390 else if (pincap & AC_PINCAP_VREF_GRD)
393 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val);
397 * Append the given mixer and verb elements for the later use
398 * The mixer array is referred in build_controls(), and init_verbs are
401 static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
403 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
405 spec->mixers[spec->num_mixers++] = mix;
408 static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
410 if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
412 spec->init_verbs[spec->num_init_verbs++] = verb;
416 * GPIO setup tables, used in initialization
418 /* Enable GPIO mask and set output */
419 static const struct hda_verb alc_gpio1_init_verbs[] = {
420 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
421 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
422 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
426 static const struct hda_verb alc_gpio2_init_verbs[] = {
427 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
428 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
429 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
433 static const struct hda_verb alc_gpio3_init_verbs[] = {
434 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
435 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
436 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
441 * Fix hardware PLL issue
442 * On some codecs, the analog PLL gating control must be off while
443 * the default value is 1.
445 static void alc_fix_pll(struct hda_codec *codec)
447 struct alc_spec *spec = codec->spec;
452 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
454 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
455 AC_VERB_GET_PROC_COEF, 0);
456 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
458 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
459 val & ~(1 << spec->pll_coef_bit));
462 static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
463 unsigned int coef_idx, unsigned int coef_bit)
465 struct alc_spec *spec = codec->spec;
467 spec->pll_coef_idx = coef_idx;
468 spec->pll_coef_bit = coef_bit;
473 * Jack detections for HP auto-mute and mic-switch
476 /* check each pin in the given array; returns true if any of them is plugged */
477 static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
481 for (i = 0; i < num_pins; i++) {
482 hda_nid_t nid = pins[i];
485 present |= snd_hda_jack_detect(codec, nid);
490 /* standard HP/line-out auto-mute helper */
491 static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
492 bool mute, bool hp_out)
494 struct alc_spec *spec = codec->spec;
495 unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0;
496 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
499 for (i = 0; i < num_pins; i++) {
500 hda_nid_t nid = pins[i];
504 switch (spec->automute_mode) {
505 case ALC_AUTOMUTE_PIN:
506 /* don't reset VREF value in case it's controlling
507 * the amp (see alc861_fixup_asus_amp_vref_0f())
509 if (spec->keep_vref_in_automute) {
510 val = snd_hda_codec_read(codec, nid, 0,
511 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
516 snd_hda_codec_write(codec, nid, 0,
517 AC_VERB_SET_PIN_WIDGET_CONTROL,
520 case ALC_AUTOMUTE_AMP:
521 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
522 HDA_AMP_MUTE, mute_bits);
524 case ALC_AUTOMUTE_MIXER:
525 nid = spec->automute_mixer_nid[i];
528 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
529 HDA_AMP_MUTE, mute_bits);
530 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1,
531 HDA_AMP_MUTE, mute_bits);
537 /* Toggle outputs muting */
538 static void update_outputs(struct hda_codec *codec)
540 struct alc_spec *spec = codec->spec;
543 /* Control HP pins/amps depending on master_mute state;
544 * in general, HP pins/amps control should be enabled in all cases,
545 * but currently set only for master_mute, just to be safe
547 if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */
548 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
549 spec->autocfg.hp_pins, spec->master_mute, true);
551 if (!spec->automute_speaker)
554 on = spec->hp_jack_present | spec->line_jack_present;
555 on |= spec->master_mute;
556 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
557 spec->autocfg.speaker_pins, on, false);
559 /* toggle line-out mutes if needed, too */
560 /* if LO is a copy of either HP or Speaker, don't need to handle it */
561 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
562 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
564 if (!spec->automute_lo)
567 on = spec->hp_jack_present;
568 on |= spec->master_mute;
569 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
570 spec->autocfg.line_out_pins, on, false);
573 static void call_update_outputs(struct hda_codec *codec)
575 struct alc_spec *spec = codec->spec;
576 if (spec->automute_hook)
577 spec->automute_hook(codec);
579 update_outputs(codec);
582 /* standard HP-automute helper */
583 static void alc_hp_automute(struct hda_codec *codec)
585 struct alc_spec *spec = codec->spec;
587 spec->hp_jack_present =
588 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
589 spec->autocfg.hp_pins);
590 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
592 call_update_outputs(codec);
595 /* standard line-out-automute helper */
596 static void alc_line_automute(struct hda_codec *codec)
598 struct alc_spec *spec = codec->spec;
600 /* check LO jack only when it's different from HP */
601 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
604 spec->line_jack_present =
605 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
606 spec->autocfg.line_out_pins);
607 if (!spec->automute_speaker || !spec->detect_lo)
609 call_update_outputs(codec);
612 #define get_connection_index(codec, mux, nid) \
613 snd_hda_get_conn_index(codec, mux, nid, 0)
615 /* standard mic auto-switch helper */
616 static void alc_mic_automute(struct hda_codec *codec)
618 struct alc_spec *spec = codec->spec;
619 hda_nid_t *pins = spec->imux_pins;
621 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
623 if (snd_BUG_ON(!spec->adc_nids))
625 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
628 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
629 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
630 else if (spec->dock_mic_idx >= 0 &&
631 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
632 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
634 alc_mux_select(codec, 0, spec->int_mic_idx, false);
637 /* handle the specified unsol action (ALC_XXX_EVENT) */
638 static void alc_exec_unsol_event(struct hda_codec *codec, int action)
642 alc_hp_automute(codec);
644 case ALC_FRONT_EVENT:
645 alc_line_automute(codec);
648 alc_mic_automute(codec);
651 snd_hda_jack_report_sync(codec);
654 /* unsolicited event for HP jack sensing */
655 static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
657 if (codec->vendor_id == 0x10ec0880)
661 res = snd_hda_jack_get_action(codec, res);
662 alc_exec_unsol_event(codec, res);
665 /* call init functions of standard auto-mute helpers */
666 static void alc_inithook(struct hda_codec *codec)
668 alc_hp_automute(codec);
669 alc_line_automute(codec);
670 alc_mic_automute(codec);
673 /* additional initialization for ALC888 variants */
674 static void alc888_coef_init(struct hda_codec *codec)
678 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
679 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
680 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
681 if ((tmp & 0xf0) == 0x20)
683 snd_hda_codec_read(codec, 0x20, 0,
684 AC_VERB_SET_PROC_COEF, 0x830);
687 snd_hda_codec_read(codec, 0x20, 0,
688 AC_VERB_SET_PROC_COEF, 0x3030);
691 /* additional initialization for ALC889 variants */
692 static void alc889_coef_init(struct hda_codec *codec)
696 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
697 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
698 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
699 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
702 /* turn on/off EAPD control (only if available) */
703 static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
705 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
707 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
708 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
712 /* turn on/off EAPD controls of the codec */
713 static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
715 /* We currently only handle front, HP */
716 static hda_nid_t pins[] = {
717 0x0f, 0x10, 0x14, 0x15, 0
720 for (p = pins; *p; p++)
721 set_eapd(codec, *p, on);
724 /* generic shutup callback;
725 * just turning off EPAD and a little pause for avoiding pop-noise
727 static void alc_eapd_shutup(struct hda_codec *codec)
729 alc_auto_setup_eapd(codec, false);
733 /* generic EAPD initialization */
734 static void alc_auto_init_amp(struct hda_codec *codec, int type)
738 alc_auto_setup_eapd(codec, true);
741 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
744 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
747 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
749 case ALC_INIT_DEFAULT:
750 switch (codec->vendor_id) {
752 snd_hda_codec_write(codec, 0x1a, 0,
753 AC_VERB_SET_COEF_INDEX, 7);
754 tmp = snd_hda_codec_read(codec, 0x1a, 0,
755 AC_VERB_GET_PROC_COEF, 0);
756 snd_hda_codec_write(codec, 0x1a, 0,
757 AC_VERB_SET_COEF_INDEX, 7);
758 snd_hda_codec_write(codec, 0x1a, 0,
759 AC_VERB_SET_PROC_COEF,
768 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
769 alc889_coef_init(codec);
772 alc888_coef_init(codec);
774 #if 0 /* XXX: This may cause the silent output on speaker on some machines */
777 snd_hda_codec_write(codec, 0x20, 0,
778 AC_VERB_SET_COEF_INDEX, 7);
779 tmp = snd_hda_codec_read(codec, 0x20, 0,
780 AC_VERB_GET_PROC_COEF, 0);
781 snd_hda_codec_write(codec, 0x20, 0,
782 AC_VERB_SET_COEF_INDEX, 7);
783 snd_hda_codec_write(codec, 0x20, 0,
784 AC_VERB_SET_PROC_COEF,
794 * Auto-Mute mode mixer enum support
796 static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
797 struct snd_ctl_elem_info *uinfo)
799 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
800 struct alc_spec *spec = codec->spec;
801 static const char * const texts2[] = {
802 "Disabled", "Enabled"
804 static const char * const texts3[] = {
805 "Disabled", "Speaker Only", "Line-Out+Speaker"
807 const char * const *texts;
809 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
811 if (spec->automute_speaker_possible && spec->automute_lo_possible) {
812 uinfo->value.enumerated.items = 3;
815 uinfo->value.enumerated.items = 2;
818 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
819 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
820 strcpy(uinfo->value.enumerated.name,
821 texts[uinfo->value.enumerated.item]);
825 static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
826 struct snd_ctl_elem_value *ucontrol)
828 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
829 struct alc_spec *spec = codec->spec;
830 unsigned int val = 0;
831 if (spec->automute_speaker)
833 if (spec->automute_lo)
836 ucontrol->value.enumerated.item[0] = val;
840 static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
841 struct snd_ctl_elem_value *ucontrol)
843 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
844 struct alc_spec *spec = codec->spec;
846 switch (ucontrol->value.enumerated.item[0]) {
848 if (!spec->automute_speaker && !spec->automute_lo)
850 spec->automute_speaker = 0;
851 spec->automute_lo = 0;
854 if (spec->automute_speaker_possible) {
855 if (!spec->automute_lo && spec->automute_speaker)
857 spec->automute_speaker = 1;
858 spec->automute_lo = 0;
859 } else if (spec->automute_lo_possible) {
860 if (spec->automute_lo)
862 spec->automute_lo = 1;
867 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
869 if (spec->automute_speaker && spec->automute_lo)
871 spec->automute_speaker = 1;
872 spec->automute_lo = 1;
877 call_update_outputs(codec);
881 static const struct snd_kcontrol_new alc_automute_mode_enum = {
882 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
883 .name = "Auto-Mute Mode",
884 .info = alc_automute_mode_info,
885 .get = alc_automute_mode_get,
886 .put = alc_automute_mode_put,
889 static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec)
891 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
892 return snd_array_new(&spec->kctls);
895 static int alc_add_automute_mode_enum(struct hda_codec *codec)
897 struct alc_spec *spec = codec->spec;
898 struct snd_kcontrol_new *knew;
900 knew = alc_kcontrol_new(spec);
903 *knew = alc_automute_mode_enum;
904 knew->name = kstrdup("Auto-Mute Mode", GFP_KERNEL);
911 * Check the availability of HP/line-out auto-mute;
912 * Set up appropriately if really supported
914 static void alc_init_automute(struct hda_codec *codec)
916 struct alc_spec *spec = codec->spec;
917 struct auto_pin_cfg *cfg = &spec->autocfg;
923 if (cfg->line_out_pins[0])
925 if (cfg->speaker_pins[0])
927 if (present < 2) /* need two different output types */
930 if (!cfg->speaker_pins[0] &&
931 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
932 memcpy(cfg->speaker_pins, cfg->line_out_pins,
933 sizeof(cfg->speaker_pins));
934 cfg->speaker_outs = cfg->line_outs;
937 if (!cfg->hp_pins[0] &&
938 cfg->line_out_type == AUTO_PIN_HP_OUT) {
939 memcpy(cfg->hp_pins, cfg->line_out_pins,
940 sizeof(cfg->hp_pins));
941 cfg->hp_outs = cfg->line_outs;
944 spec->automute_mode = ALC_AUTOMUTE_PIN;
946 for (i = 0; i < cfg->hp_outs; i++) {
947 hda_nid_t nid = cfg->hp_pins[i];
948 if (!is_jack_detectable(codec, nid))
950 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
952 snd_hda_jack_detect_enable(codec, nid, ALC_HP_EVENT);
956 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
957 if (cfg->speaker_outs)
958 for (i = 0; i < cfg->line_outs; i++) {
959 hda_nid_t nid = cfg->line_out_pins[i];
960 if (!is_jack_detectable(codec, nid))
962 snd_printdd("realtek: Enable Line-Out "
963 "auto-muting on NID 0x%x\n", nid);
964 snd_hda_jack_detect_enable(codec, nid,
968 spec->automute_lo_possible = spec->detect_hp;
971 spec->automute_speaker_possible = cfg->speaker_outs &&
972 (spec->detect_hp || spec->detect_lo);
974 spec->automute_lo = spec->automute_lo_possible;
975 spec->automute_speaker = spec->automute_speaker_possible;
977 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
978 /* create a control for automute mode */
979 alc_add_automute_mode_enum(codec);
980 spec->unsol_event = alc_sku_unsol_event;
984 /* return the position of NID in the list, or -1 if not found */
985 static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
988 for (i = 0; i < nums; i++)
994 /* check whether dynamic ADC-switching is available */
995 static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
997 struct alc_spec *spec = codec->spec;
998 struct hda_input_mux *imux = &spec->private_imux[0];
1002 if (imux != spec->input_mux) /* no dynamic imux? */
1005 for (n = 0; n < spec->num_adc_nids; n++) {
1006 cap = spec->private_capsrc_nids[n];
1007 for (i = 0; i < imux->num_items; i++) {
1008 pin = spec->imux_pins[i];
1011 if (get_connection_index(codec, cap, pin) < 0)
1014 if (i >= imux->num_items)
1015 return true; /* no ADC-switch is needed */
1018 for (i = 0; i < imux->num_items; i++) {
1019 pin = spec->imux_pins[i];
1020 for (n = 0; n < spec->num_adc_nids; n++) {
1021 cap = spec->private_capsrc_nids[n];
1022 idx = get_connection_index(codec, cap, pin);
1024 imux->items[i].index = idx;
1025 spec->dyn_adc_idx[i] = n;
1031 snd_printdd("realtek: enabling ADC switching\n");
1032 spec->dyn_adc_switch = 1;
1036 /* rebuild imux for matching with the given auto-mic pins (if not yet) */
1037 static bool alc_rebuild_imux_for_auto_mic(struct hda_codec *codec)
1039 struct alc_spec *spec = codec->spec;
1040 struct hda_input_mux *imux;
1041 static char * const texts[3] = {
1042 "Mic", "Internal Mic", "Dock Mic"
1046 if (!spec->auto_mic)
1048 imux = &spec->private_imux[0];
1049 if (spec->input_mux == imux)
1051 spec->imux_pins[0] = spec->ext_mic_pin;
1052 spec->imux_pins[1] = spec->int_mic_pin;
1053 spec->imux_pins[2] = spec->dock_mic_pin;
1054 for (i = 0; i < 3; i++) {
1055 strcpy(imux->items[i].label, texts[i]);
1056 if (spec->imux_pins[i]) {
1057 hda_nid_t pin = spec->imux_pins[i];
1059 for (c = 0; c < spec->num_adc_nids; c++) {
1060 hda_nid_t cap = get_capsrc(spec, c);
1061 int idx = get_connection_index(codec, cap, pin);
1063 imux->items[i].index = idx;
1067 imux->num_items = i + 1;
1070 spec->num_mux_defs = 1;
1071 spec->input_mux = imux;
1075 /* check whether all auto-mic pins are valid; setup indices if OK */
1076 static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1078 struct alc_spec *spec = codec->spec;
1079 const struct hda_input_mux *imux;
1081 if (!spec->auto_mic)
1083 if (spec->auto_mic_valid_imux)
1084 return true; /* already checked */
1086 /* fill up imux indices */
1087 if (!alc_check_dyn_adc_switch(codec)) {
1092 imux = spec->input_mux;
1093 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1094 spec->imux_pins, imux->num_items);
1095 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1096 spec->imux_pins, imux->num_items);
1097 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1098 spec->imux_pins, imux->num_items);
1099 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1101 return false; /* no corresponding imux */
1104 snd_hda_jack_detect_enable(codec, spec->ext_mic_pin, ALC_MIC_EVENT);
1105 if (spec->dock_mic_pin)
1106 snd_hda_jack_detect_enable(codec, spec->dock_mic_pin,
1109 spec->auto_mic_valid_imux = 1;
1115 * Check the availability of auto-mic switch;
1116 * Set up if really supported
1118 static void alc_init_auto_mic(struct hda_codec *codec)
1120 struct alc_spec *spec = codec->spec;
1121 struct auto_pin_cfg *cfg = &spec->autocfg;
1122 hda_nid_t fixed, ext, dock;
1125 if (spec->shared_mic_hp)
1126 return; /* no auto-mic for the shared I/O */
1128 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1130 fixed = ext = dock = 0;
1131 for (i = 0; i < cfg->num_inputs; i++) {
1132 hda_nid_t nid = cfg->inputs[i].pin;
1133 unsigned int defcfg;
1134 defcfg = snd_hda_codec_get_pincfg(codec, nid);
1135 switch (snd_hda_get_input_pin_attr(defcfg)) {
1136 case INPUT_PIN_ATTR_INT:
1138 return; /* already occupied */
1139 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1140 return; /* invalid type */
1143 case INPUT_PIN_ATTR_UNUSED:
1144 return; /* invalid entry */
1145 case INPUT_PIN_ATTR_DOCK:
1147 return; /* already occupied */
1148 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1149 return; /* invalid type */
1154 return; /* already occupied */
1155 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1156 return; /* invalid type */
1167 if (!is_jack_detectable(codec, ext))
1168 return; /* no unsol support */
1169 if (dock && !is_jack_detectable(codec, dock))
1170 return; /* no unsol support */
1172 /* check imux indices */
1173 spec->ext_mic_pin = ext;
1174 spec->int_mic_pin = fixed;
1175 spec->dock_mic_pin = dock;
1178 if (!alc_auto_mic_check_imux(codec))
1181 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1183 spec->unsol_event = alc_sku_unsol_event;
1186 /* check the availabilities of auto-mute and auto-mic switches */
1187 static void alc_auto_check_switches(struct hda_codec *codec)
1189 alc_init_automute(codec);
1190 alc_init_auto_mic(codec);
1194 * Realtek SSID verification
1197 /* Could be any non-zero and even value. When used as fixup, tells
1198 * the driver to ignore any present sku defines.
1200 #define ALC_FIXUP_SKU_IGNORE (2)
1202 static int alc_auto_parse_customize_define(struct hda_codec *codec)
1204 unsigned int ass, tmp, i;
1206 struct alc_spec *spec = codec->spec;
1208 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1210 if (spec->cdefine.fixup) {
1211 ass = spec->cdefine.sku_cfg;
1212 if (ass == ALC_FIXUP_SKU_IGNORE)
1217 ass = codec->subsystem_id & 0xffff;
1218 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
1222 if (codec->vendor_id == 0x10ec0260)
1224 ass = snd_hda_codec_get_pincfg(codec, nid);
1227 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1228 codec->chip_name, ass);
1234 for (i = 1; i < 16; i++) {
1238 if (((ass >> 16) & 0xf) != tmp)
1241 spec->cdefine.port_connectivity = ass >> 30;
1242 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1243 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1244 spec->cdefine.customization = ass >> 8;
1246 spec->cdefine.sku_cfg = ass;
1247 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1248 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1249 spec->cdefine.swap = (ass & 0x2) >> 1;
1250 spec->cdefine.override = ass & 0x1;
1252 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1253 nid, spec->cdefine.sku_cfg);
1254 snd_printd("SKU: port_connectivity=0x%x\n",
1255 spec->cdefine.port_connectivity);
1256 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1257 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1258 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1259 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1260 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1261 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1262 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1267 /* return true if the given NID is found in the list */
1268 static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1270 return find_idx_in_nid_list(nid, list, nums) >= 0;
1273 /* check subsystem ID and set up device-specific initialization;
1274 * return 1 if initialized, 0 if invalid SSID
1276 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1277 * 31 ~ 16 : Manufacture ID
1279 * 7 ~ 0 : Assembly ID
1280 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1282 static int alc_subsystem_id(struct hda_codec *codec,
1283 hda_nid_t porta, hda_nid_t porte,
1284 hda_nid_t portd, hda_nid_t porti)
1286 unsigned int ass, tmp, i;
1288 struct alc_spec *spec = codec->spec;
1290 if (spec->cdefine.fixup) {
1291 ass = spec->cdefine.sku_cfg;
1292 if (ass == ALC_FIXUP_SKU_IGNORE)
1297 ass = codec->subsystem_id & 0xffff;
1298 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1301 /* invalid SSID, check the special NID pin defcfg instead */
1303 * 31~30 : port connectivity
1306 * 19~16 : Check sum (15:1)
1311 if (codec->vendor_id == 0x10ec0260)
1313 ass = snd_hda_codec_get_pincfg(codec, nid);
1314 snd_printd("realtek: No valid SSID, "
1315 "checking pincfg 0x%08x for NID 0x%x\n",
1319 if ((ass >> 30) != 1) /* no physical connection */
1324 for (i = 1; i < 16; i++) {
1328 if (((ass >> 16) & 0xf) != tmp)
1331 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1332 ass & 0xffff, codec->vendor_id);
1336 * 2 : 0 --> Desktop, 1 --> Laptop
1337 * 3~5 : External Amplifier control
1340 tmp = (ass & 0x38) >> 3; /* external Amp control */
1343 spec->init_amp = ALC_INIT_GPIO1;
1346 spec->init_amp = ALC_INIT_GPIO2;
1349 spec->init_amp = ALC_INIT_GPIO3;
1353 spec->init_amp = ALC_INIT_DEFAULT;
1357 /* is laptop or Desktop and enable the function "Mute internal speaker
1358 * when the external headphone out jack is plugged"
1360 if (!(ass & 0x8000))
1363 * 10~8 : Jack location
1364 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1366 * 15 : 1 --> enable the function "Mute internal speaker
1367 * when the external headphone out jack is plugged"
1369 if (!spec->autocfg.hp_pins[0] &&
1370 !(spec->autocfg.line_out_pins[0] &&
1371 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
1373 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1384 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1385 spec->autocfg.line_outs))
1387 spec->autocfg.hp_pins[0] = nid;
1392 /* Check the validity of ALC subsystem-id
1393 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1394 static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
1396 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
1397 struct alc_spec *spec = codec->spec;
1398 snd_printd("realtek: "
1399 "Enable default setup for auto mode as fallback\n");
1400 spec->init_amp = ALC_INIT_DEFAULT;
1405 * Fix-up pin default configurations and add default verbs
1413 struct alc_model_fixup {
1424 const struct alc_pincfg *pins;
1425 const struct hda_verb *verbs;
1426 void (*func)(struct hda_codec *codec,
1427 const struct alc_fixup *fix,
1441 ALC_FIXUP_ACT_PRE_PROBE,
1442 ALC_FIXUP_ACT_PROBE,
1446 static void alc_apply_fixup(struct hda_codec *codec, int action)
1448 struct alc_spec *spec = codec->spec;
1449 int id = spec->fixup_id;
1450 #ifdef CONFIG_SND_DEBUG_VERBOSE
1451 const char *modelname = spec->fixup_name;
1455 if (!spec->fixup_list)
1459 const struct alc_fixup *fix = spec->fixup_list + id;
1460 const struct alc_pincfg *cfg;
1462 switch (fix->type) {
1464 if (action != ALC_FIXUP_ACT_PRE_PROBE || !fix->v.sku)
1466 snd_printdd(KERN_INFO "hda_codec: %s: "
1467 "Apply sku override for %s\n",
1468 codec->chip_name, modelname);
1469 spec->cdefine.sku_cfg = fix->v.sku;
1470 spec->cdefine.fixup = 1;
1472 case ALC_FIXUP_PINS:
1474 if (action != ALC_FIXUP_ACT_PRE_PROBE || !cfg)
1476 snd_printdd(KERN_INFO "hda_codec: %s: "
1477 "Apply pincfg for %s\n",
1478 codec->chip_name, modelname);
1479 for (; cfg->nid; cfg++)
1480 snd_hda_codec_set_pincfg(codec, cfg->nid,
1483 case ALC_FIXUP_VERBS:
1484 if (action != ALC_FIXUP_ACT_PROBE || !fix->v.verbs)
1486 snd_printdd(KERN_INFO "hda_codec: %s: "
1487 "Apply fix-verbs for %s\n",
1488 codec->chip_name, modelname);
1489 add_verb(codec->spec, fix->v.verbs);
1491 case ALC_FIXUP_FUNC:
1494 snd_printdd(KERN_INFO "hda_codec: %s: "
1495 "Apply fix-func for %s\n",
1496 codec->chip_name, modelname);
1497 fix->v.func(codec, fix, action);
1500 snd_printk(KERN_ERR "hda_codec: %s: "
1501 "Invalid fixup type %d\n",
1502 codec->chip_name, fix->type);
1513 static void alc_pick_fixup(struct hda_codec *codec,
1514 const struct alc_model_fixup *models,
1515 const struct snd_pci_quirk *quirk,
1516 const struct alc_fixup *fixlist)
1518 struct alc_spec *spec = codec->spec;
1519 const struct snd_pci_quirk *q;
1521 const char *name = NULL;
1523 if (codec->modelname && models) {
1524 while (models->name) {
1525 if (!strcmp(codec->modelname, models->name)) {
1527 name = models->name;
1534 q = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1537 #ifdef CONFIG_SND_DEBUG_VERBOSE
1543 for (q = quirk; q->subvendor; q++) {
1544 unsigned int vendorid =
1545 q->subdevice | (q->subvendor << 16);
1546 if (vendorid == codec->subsystem_id) {
1548 #ifdef CONFIG_SND_DEBUG_VERBOSE
1556 spec->fixup_id = id;
1558 spec->fixup_list = fixlist;
1559 spec->fixup_name = name;
1564 * COEF access helper functions
1566 static int alc_read_coef_idx(struct hda_codec *codec,
1567 unsigned int coef_idx)
1570 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1572 val = snd_hda_codec_read(codec, 0x20, 0,
1573 AC_VERB_GET_PROC_COEF, 0);
1577 static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1578 unsigned int coef_val)
1580 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1582 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1586 /* a special bypass for COEF 0; read the cached value at the second time */
1587 static unsigned int alc_get_coef0(struct hda_codec *codec)
1589 struct alc_spec *spec = codec->spec;
1591 spec->coef0 = alc_read_coef_idx(codec, 0);
1596 * Digital I/O handling
1599 /* set right pin controls for digital I/O */
1600 static void alc_auto_init_digital(struct hda_codec *codec)
1602 struct alc_spec *spec = codec->spec;
1606 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1607 pin = spec->autocfg.dig_out_pins[i];
1610 snd_hda_codec_write(codec, pin, 0,
1611 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
1613 dac = spec->multiout.dig_out_nid;
1615 dac = spec->slave_dig_outs[i - 1];
1616 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
1618 snd_hda_codec_write(codec, dac, 0,
1619 AC_VERB_SET_AMP_GAIN_MUTE,
1622 pin = spec->autocfg.dig_in_pin;
1624 snd_hda_codec_write(codec, pin, 0,
1625 AC_VERB_SET_PIN_WIDGET_CONTROL,
1629 /* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1630 static void alc_auto_parse_digital(struct hda_codec *codec)
1632 struct alc_spec *spec = codec->spec;
1636 /* support multiple SPDIFs; the secondary is set up as a slave */
1638 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1640 err = snd_hda_get_connections(codec,
1641 spec->autocfg.dig_out_pins[i],
1642 conn, ARRAY_SIZE(conn));
1645 dig_nid = conn[0]; /* assume the first element is audio-out */
1647 spec->multiout.dig_out_nid = dig_nid;
1648 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1650 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
1651 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
1653 spec->slave_dig_outs[nums - 1] = dig_nid;
1658 if (spec->autocfg.dig_in_pin) {
1659 dig_nid = codec->start_nid;
1660 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1661 unsigned int wcaps = get_wcaps(codec, dig_nid);
1662 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1664 if (!(wcaps & AC_WCAP_DIGITAL))
1666 if (!(wcaps & AC_WCAP_CONN_LIST))
1668 err = get_connection_index(codec, dig_nid,
1669 spec->autocfg.dig_in_pin);
1671 spec->dig_in_nid = dig_nid;
1679 * capture mixer elements
1681 static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1682 struct snd_ctl_elem_info *uinfo)
1684 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1685 struct alc_spec *spec = codec->spec;
1689 mutex_lock(&codec->control_mutex);
1690 if (spec->vol_in_capsrc)
1691 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1693 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1694 kcontrol->private_value = val;
1695 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
1696 mutex_unlock(&codec->control_mutex);
1700 static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1701 unsigned int size, unsigned int __user *tlv)
1703 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1704 struct alc_spec *spec = codec->spec;
1708 mutex_lock(&codec->control_mutex);
1709 if (spec->vol_in_capsrc)
1710 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1712 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1713 kcontrol->private_value = val;
1714 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
1715 mutex_unlock(&codec->control_mutex);
1719 typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1720 struct snd_ctl_elem_value *ucontrol);
1722 static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1723 struct snd_ctl_elem_value *ucontrol,
1724 getput_call_t func, bool check_adc_switch)
1726 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1727 struct alc_spec *spec = codec->spec;
1730 mutex_lock(&codec->control_mutex);
1731 if (check_adc_switch && spec->dyn_adc_switch) {
1732 for (i = 0; i < spec->num_adc_nids; i++) {
1733 kcontrol->private_value =
1734 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1736 err = func(kcontrol, ucontrol);
1741 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1742 if (spec->vol_in_capsrc)
1743 kcontrol->private_value =
1744 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1747 kcontrol->private_value =
1748 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1750 err = func(kcontrol, ucontrol);
1753 mutex_unlock(&codec->control_mutex);
1757 static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1758 struct snd_ctl_elem_value *ucontrol)
1760 return alc_cap_getput_caller(kcontrol, ucontrol,
1761 snd_hda_mixer_amp_volume_get, false);
1764 static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1765 struct snd_ctl_elem_value *ucontrol)
1767 return alc_cap_getput_caller(kcontrol, ucontrol,
1768 snd_hda_mixer_amp_volume_put, true);
1771 /* capture mixer elements */
1772 #define alc_cap_sw_info snd_ctl_boolean_stereo_info
1774 static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1775 struct snd_ctl_elem_value *ucontrol)
1777 return alc_cap_getput_caller(kcontrol, ucontrol,
1778 snd_hda_mixer_amp_switch_get, false);
1781 static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1782 struct snd_ctl_elem_value *ucontrol)
1784 return alc_cap_getput_caller(kcontrol, ucontrol,
1785 snd_hda_mixer_amp_switch_put, true);
1788 #define _DEFINE_CAPMIX(num) \
1790 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1791 .name = "Capture Switch", \
1792 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1794 .info = alc_cap_sw_info, \
1795 .get = alc_cap_sw_get, \
1796 .put = alc_cap_sw_put, \
1799 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1800 .name = "Capture Volume", \
1801 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1802 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1803 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1805 .info = alc_cap_vol_info, \
1806 .get = alc_cap_vol_get, \
1807 .put = alc_cap_vol_put, \
1808 .tlv = { .c = alc_cap_vol_tlv }, \
1811 #define _DEFINE_CAPSRC(num) \
1813 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1814 /* .name = "Capture Source", */ \
1815 .name = "Input Source", \
1817 .info = alc_mux_enum_info, \
1818 .get = alc_mux_enum_get, \
1819 .put = alc_mux_enum_put, \
1822 #define DEFINE_CAPMIX(num) \
1823 static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
1824 _DEFINE_CAPMIX(num), \
1825 _DEFINE_CAPSRC(num), \
1829 #define DEFINE_CAPMIX_NOSRC(num) \
1830 static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
1831 _DEFINE_CAPMIX(num), \
1835 /* up to three ADCs */
1839 DEFINE_CAPMIX_NOSRC(1);
1840 DEFINE_CAPMIX_NOSRC(2);
1841 DEFINE_CAPMIX_NOSRC(3);
1844 * virtual master controls
1848 * slave controls for virtual master
1850 static const char * const alc_slave_pfxs[] = {
1851 "Front", "Surround", "Center", "LFE", "Side",
1852 "Headphone", "Speaker", "Mono", "Line-Out",
1853 "CLFE", "Bass Speaker", "PCM",
1858 * build control elements
1861 #define NID_MAPPING (-1)
1863 #define SUBDEV_SPEAKER_ (0 << 6)
1864 #define SUBDEV_HP_ (1 << 6)
1865 #define SUBDEV_LINE_ (2 << 6)
1866 #define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1867 #define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1868 #define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1870 static void alc_free_kctls(struct hda_codec *codec);
1872 #ifdef CONFIG_SND_HDA_INPUT_BEEP
1873 /* additional beep mixers; the actual parameters are overwritten at build */
1874 static const struct snd_kcontrol_new alc_beep_mixer[] = {
1875 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
1876 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
1881 static int __alc_build_controls(struct hda_codec *codec)
1883 struct alc_spec *spec = codec->spec;
1884 struct snd_kcontrol *kctl = NULL;
1885 const struct snd_kcontrol_new *knew;
1890 for (i = 0; i < spec->num_mixers; i++) {
1891 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1895 if (spec->cap_mixer) {
1896 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1900 if (spec->multiout.dig_out_nid) {
1901 err = snd_hda_create_spdif_out_ctls(codec,
1902 spec->multiout.dig_out_nid,
1903 spec->multiout.dig_out_nid);
1906 if (!spec->no_analog) {
1907 err = snd_hda_create_spdif_share_sw(codec,
1911 spec->multiout.share_spdif = 1;
1914 if (spec->dig_in_nid) {
1915 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1920 #ifdef CONFIG_SND_HDA_INPUT_BEEP
1921 /* create beep controls if needed */
1922 if (spec->beep_amp) {
1923 const struct snd_kcontrol_new *knew;
1924 for (knew = alc_beep_mixer; knew->name; knew++) {
1925 struct snd_kcontrol *kctl;
1926 kctl = snd_ctl_new1(knew, codec);
1929 kctl->private_value = spec->beep_amp;
1930 err = snd_hda_ctl_add(codec, 0, kctl);
1937 /* if we have no master control, let's create it */
1938 if (!spec->no_analog &&
1939 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1940 unsigned int vmaster_tlv[4];
1941 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
1942 HDA_OUTPUT, vmaster_tlv);
1943 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1944 vmaster_tlv, alc_slave_pfxs,
1949 if (!spec->no_analog &&
1950 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1951 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1952 NULL, alc_slave_pfxs,
1958 /* assign Capture Source enums to NID */
1959 if (spec->capsrc_nids || spec->adc_nids) {
1960 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
1962 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1963 for (i = 0; kctl && i < kctl->count; i++) {
1964 err = snd_hda_add_nid(codec, kctl, i,
1965 get_capsrc(spec, i));
1970 if (spec->cap_mixer && spec->adc_nids) {
1971 const char *kname = kctl ? kctl->id.name : NULL;
1972 for (knew = spec->cap_mixer; knew->name; knew++) {
1973 if (kname && strcmp(knew->name, kname) == 0)
1975 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1976 for (i = 0; kctl && i < kctl->count; i++) {
1977 err = snd_hda_add_nid(codec, kctl, i,
1985 /* other nid->control mapping */
1986 for (i = 0; i < spec->num_mixers; i++) {
1987 for (knew = spec->mixers[i]; knew->name; knew++) {
1988 if (knew->iface != NID_MAPPING)
1990 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1993 u = knew->subdevice;
1994 for (j = 0; j < 4; j++, u >>= 8) {
1999 case SUBDEV_SPEAKER_:
2000 nid = spec->autocfg.speaker_pins[nid];
2003 nid = spec->autocfg.line_out_pins[nid];
2006 nid = spec->autocfg.hp_pins[nid];
2011 err = snd_hda_add_nid(codec, kctl, 0, nid);
2015 u = knew->private_value;
2016 for (j = 0; j < 4; j++, u >>= 8) {
2020 err = snd_hda_add_nid(codec, kctl, 0, nid);
2027 alc_free_kctls(codec); /* no longer needed */
2032 static int alc_build_controls(struct hda_codec *codec)
2034 struct alc_spec *spec = codec->spec;
2035 int err = __alc_build_controls(codec);
2038 return snd_hda_jack_add_kctls(codec, &spec->autocfg);
2046 static void alc_init_special_input_src(struct hda_codec *codec);
2048 static int alc_init(struct hda_codec *codec)
2050 struct alc_spec *spec = codec->spec;
2054 alc_auto_init_amp(codec, spec->init_amp);
2056 for (i = 0; i < spec->num_init_verbs; i++)
2057 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2058 alc_init_special_input_src(codec);
2060 if (spec->init_hook)
2061 spec->init_hook(codec);
2063 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2065 snd_hda_jack_report_sync(codec);
2067 hda_call_check_power_status(codec, 0x01);
2071 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2073 struct alc_spec *spec = codec->spec;
2075 if (spec->unsol_event)
2076 spec->unsol_event(codec, res);
2079 #ifdef CONFIG_SND_HDA_POWER_SAVE
2080 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2082 struct alc_spec *spec = codec->spec;
2083 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2088 * Analog playback callbacks
2090 static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
2091 struct hda_codec *codec,
2092 struct snd_pcm_substream *substream)
2094 struct alc_spec *spec = codec->spec;
2095 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2099 static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2100 struct hda_codec *codec,
2101 unsigned int stream_tag,
2102 unsigned int format,
2103 struct snd_pcm_substream *substream)
2105 struct alc_spec *spec = codec->spec;
2106 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2107 stream_tag, format, substream);
2110 static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2111 struct hda_codec *codec,
2112 struct snd_pcm_substream *substream)
2114 struct alc_spec *spec = codec->spec;
2115 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2121 static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2122 struct hda_codec *codec,
2123 struct snd_pcm_substream *substream)
2125 struct alc_spec *spec = codec->spec;
2126 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2129 static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2130 struct hda_codec *codec,
2131 unsigned int stream_tag,
2132 unsigned int format,
2133 struct snd_pcm_substream *substream)
2135 struct alc_spec *spec = codec->spec;
2136 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2137 stream_tag, format, substream);
2140 static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2141 struct hda_codec *codec,
2142 struct snd_pcm_substream *substream)
2144 struct alc_spec *spec = codec->spec;
2145 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2148 static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2149 struct hda_codec *codec,
2150 struct snd_pcm_substream *substream)
2152 struct alc_spec *spec = codec->spec;
2153 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2159 static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2160 struct hda_codec *codec,
2161 unsigned int stream_tag,
2162 unsigned int format,
2163 struct snd_pcm_substream *substream)
2165 struct alc_spec *spec = codec->spec;
2167 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
2168 stream_tag, 0, format);
2172 static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2173 struct hda_codec *codec,
2174 struct snd_pcm_substream *substream)
2176 struct alc_spec *spec = codec->spec;
2178 snd_hda_codec_cleanup_stream(codec,
2179 spec->adc_nids[substream->number + 1]);
2183 /* analog capture with dynamic dual-adc changes */
2184 static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2185 struct hda_codec *codec,
2186 unsigned int stream_tag,
2187 unsigned int format,
2188 struct snd_pcm_substream *substream)
2190 struct alc_spec *spec = codec->spec;
2191 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
2192 spec->cur_adc_stream_tag = stream_tag;
2193 spec->cur_adc_format = format;
2194 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2198 static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2199 struct hda_codec *codec,
2200 struct snd_pcm_substream *substream)
2202 struct alc_spec *spec = codec->spec;
2203 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2208 static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
2212 .nid = 0, /* fill later */
2214 .prepare = dyn_adc_capture_pcm_prepare,
2215 .cleanup = dyn_adc_capture_pcm_cleanup
2221 static const struct hda_pcm_stream alc_pcm_analog_playback = {
2225 /* NID is set in alc_build_pcms */
2227 .open = alc_playback_pcm_open,
2228 .prepare = alc_playback_pcm_prepare,
2229 .cleanup = alc_playback_pcm_cleanup
2233 static const struct hda_pcm_stream alc_pcm_analog_capture = {
2237 /* NID is set in alc_build_pcms */
2240 static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
2244 /* NID is set in alc_build_pcms */
2247 static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
2248 .substreams = 2, /* can be overridden */
2251 /* NID is set in alc_build_pcms */
2253 .prepare = alc_alt_capture_pcm_prepare,
2254 .cleanup = alc_alt_capture_pcm_cleanup
2258 static const struct hda_pcm_stream alc_pcm_digital_playback = {
2262 /* NID is set in alc_build_pcms */
2264 .open = alc_dig_playback_pcm_open,
2265 .close = alc_dig_playback_pcm_close,
2266 .prepare = alc_dig_playback_pcm_prepare,
2267 .cleanup = alc_dig_playback_pcm_cleanup
2271 static const struct hda_pcm_stream alc_pcm_digital_capture = {
2275 /* NID is set in alc_build_pcms */
2278 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
2279 static const struct hda_pcm_stream alc_pcm_null_stream = {
2285 static int alc_build_pcms(struct hda_codec *codec)
2287 struct alc_spec *spec = codec->spec;
2288 struct hda_pcm *info = spec->pcm_rec;
2289 const struct hda_pcm_stream *p;
2290 bool have_multi_adcs;
2293 codec->num_pcms = 1;
2294 codec->pcm_info = info;
2296 if (spec->no_analog)
2299 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2300 "%s Analog", codec->chip_name);
2301 info->name = spec->stream_name_analog;
2303 if (spec->multiout.num_dacs > 0) {
2304 p = spec->stream_analog_playback;
2306 p = &alc_pcm_analog_playback;
2307 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2308 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2310 if (spec->adc_nids) {
2311 p = spec->stream_analog_capture;
2313 if (spec->dyn_adc_switch)
2314 p = &dyn_adc_pcm_analog_capture;
2316 p = &alc_pcm_analog_capture;
2318 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2319 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2322 if (spec->channel_mode) {
2323 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2324 for (i = 0; i < spec->num_channel_mode; i++) {
2325 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2326 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2332 /* SPDIF for stream index #1 */
2333 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2334 snprintf(spec->stream_name_digital,
2335 sizeof(spec->stream_name_digital),
2336 "%s Digital", codec->chip_name);
2337 codec->num_pcms = 2;
2338 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
2339 info = spec->pcm_rec + 1;
2340 info->name = spec->stream_name_digital;
2341 if (spec->dig_out_type)
2342 info->pcm_type = spec->dig_out_type;
2344 info->pcm_type = HDA_PCM_TYPE_SPDIF;
2345 if (spec->multiout.dig_out_nid) {
2346 p = spec->stream_digital_playback;
2348 p = &alc_pcm_digital_playback;
2349 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2350 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2352 if (spec->dig_in_nid) {
2353 p = spec->stream_digital_capture;
2355 p = &alc_pcm_digital_capture;
2356 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2357 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2359 /* FIXME: do we need this for all Realtek codec models? */
2360 codec->spdif_status_reset = 1;
2363 if (spec->no_analog)
2366 /* If the use of more than one ADC is requested for the current
2367 * model, configure a second analog capture-only PCM.
2369 have_multi_adcs = (spec->num_adc_nids > 1) &&
2370 !spec->dyn_adc_switch && !spec->auto_mic &&
2371 (!spec->input_mux || spec->input_mux->num_items > 1);
2372 /* Additional Analaog capture for index #2 */
2373 if (spec->alt_dac_nid || have_multi_adcs) {
2374 codec->num_pcms = 3;
2375 info = spec->pcm_rec + 2;
2376 info->name = spec->stream_name_analog;
2377 if (spec->alt_dac_nid) {
2378 p = spec->stream_analog_alt_playback;
2380 p = &alc_pcm_analog_alt_playback;
2381 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2382 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2385 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2386 alc_pcm_null_stream;
2387 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2389 if (have_multi_adcs) {
2390 p = spec->stream_analog_alt_capture;
2392 p = &alc_pcm_analog_alt_capture;
2393 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2394 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2396 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2397 spec->num_adc_nids - 1;
2399 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2400 alc_pcm_null_stream;
2401 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
2408 static inline void alc_shutup(struct hda_codec *codec)
2410 struct alc_spec *spec = codec->spec;
2412 if (spec && spec->shutup)
2413 spec->shutup(codec);
2414 snd_hda_shutup_pins(codec);
2417 static void alc_free_kctls(struct hda_codec *codec)
2419 struct alc_spec *spec = codec->spec;
2421 if (spec->kctls.list) {
2422 struct snd_kcontrol_new *kctl = spec->kctls.list;
2424 for (i = 0; i < spec->kctls.used; i++)
2425 kfree(kctl[i].name);
2427 snd_array_free(&spec->kctls);
2430 static void alc_free_bind_ctls(struct hda_codec *codec)
2432 struct alc_spec *spec = codec->spec;
2433 if (spec->bind_ctls.list) {
2434 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2436 for (i = 0; i < spec->bind_ctls.used; i++)
2439 snd_array_free(&spec->bind_ctls);
2442 static void alc_free(struct hda_codec *codec)
2444 struct alc_spec *spec = codec->spec;
2450 alc_free_kctls(codec);
2451 alc_free_bind_ctls(codec);
2453 snd_hda_detach_beep_device(codec);
2456 #ifdef CONFIG_SND_HDA_POWER_SAVE
2457 static void alc_power_eapd(struct hda_codec *codec)
2459 alc_auto_setup_eapd(codec, false);
2462 static int alc_suspend(struct hda_codec *codec, pm_message_t state)
2464 struct alc_spec *spec = codec->spec;
2466 if (spec && spec->power_hook)
2467 spec->power_hook(codec);
2473 static int alc_resume(struct hda_codec *codec)
2475 msleep(150); /* to avoid pop noise */
2476 codec->patch_ops.init(codec);
2477 snd_hda_codec_resume_amp(codec);
2478 snd_hda_codec_resume_cache(codec);
2479 hda_call_check_power_status(codec, 0x01);
2486 static const struct hda_codec_ops alc_patch_ops = {
2487 .build_controls = alc_build_controls,
2488 .build_pcms = alc_build_pcms,
2491 .unsol_event = alc_unsol_event,
2493 .resume = alc_resume,
2495 #ifdef CONFIG_SND_HDA_POWER_SAVE
2496 .suspend = alc_suspend,
2497 .check_power_status = alc_check_power_status,
2499 .reboot_notify = alc_shutup,
2502 /* replace the codec chip_name with the given string */
2503 static int alc_codec_rename(struct hda_codec *codec, const char *name)
2505 kfree(codec->chip_name);
2506 codec->chip_name = kstrdup(name, GFP_KERNEL);
2507 if (!codec->chip_name) {
2515 * Rename codecs appropriately from COEF value
2517 struct alc_codec_rename_table {
2518 unsigned int vendor_id;
2519 unsigned short coef_mask;
2520 unsigned short coef_bits;
2524 static struct alc_codec_rename_table rename_tbl[] = {
2525 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2526 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2527 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2528 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2529 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2530 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2531 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
2532 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2533 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2534 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2535 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2536 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2537 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2538 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2539 { } /* terminator */
2542 static int alc_codec_rename_from_preset(struct hda_codec *codec)
2544 const struct alc_codec_rename_table *p;
2546 for (p = rename_tbl; p->vendor_id; p++) {
2547 if (p->vendor_id != codec->vendor_id)
2549 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
2550 return alc_codec_rename(codec, p->name);
2556 * Automatic parse of I/O pins from the BIOS configuration
2561 ALC_CTL_WIDGET_MUTE,
2566 static const struct snd_kcontrol_new alc_control_templates[] = {
2567 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2568 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2569 HDA_BIND_MUTE(NULL, 0, 0, 0),
2570 HDA_BIND_VOL(NULL, 0),
2571 HDA_BIND_SW(NULL, 0),
2574 /* add dynamic controls */
2575 static int add_control(struct alc_spec *spec, int type, const char *name,
2576 int cidx, unsigned long val)
2578 struct snd_kcontrol_new *knew;
2580 knew = alc_kcontrol_new(spec);
2583 *knew = alc_control_templates[type];
2584 knew->name = kstrdup(name, GFP_KERNEL);
2588 if (get_amp_nid_(val))
2589 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
2590 knew->private_value = val;
2594 static int add_control_with_pfx(struct alc_spec *spec, int type,
2595 const char *pfx, const char *dir,
2596 const char *sfx, int cidx, unsigned long val)
2599 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
2600 return add_control(spec, type, name, cidx, val);
2603 #define add_pb_vol_ctrl(spec, type, pfx, val) \
2604 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2605 #define add_pb_sw_ctrl(spec, type, pfx, val) \
2606 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2607 #define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2608 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2609 #define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2610 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
2612 static const char * const channel_name[4] = {
2613 "Front", "Surround", "CLFE", "Side"
2616 static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2617 bool can_be_master, int *index)
2619 struct auto_pin_cfg *cfg = &spec->autocfg;
2622 if (cfg->line_outs == 1 && !spec->multi_ios &&
2623 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
2626 switch (cfg->line_out_type) {
2627 case AUTO_PIN_SPEAKER_OUT:
2628 if (cfg->line_outs == 1)
2630 if (cfg->line_outs == 2)
2631 return ch ? "Bass Speaker" : "Speaker";
2633 case AUTO_PIN_HP_OUT:
2634 /* for multi-io case, only the primary out */
2635 if (ch && spec->multi_ios)
2640 if (cfg->line_outs == 1 && !spec->multi_ios)
2644 if (snd_BUG_ON(ch >= ARRAY_SIZE(channel_name)))
2647 return channel_name[ch];
2650 /* create input playback/capture controls for the given pin */
2651 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
2652 const char *ctlname, int ctlidx,
2653 int idx, hda_nid_t mix_nid)
2657 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
2658 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2661 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
2662 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2668 static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
2670 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2671 return (pincap & AC_PINCAP_IN) != 0;
2674 /* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
2675 static int alc_auto_fill_adc_caps(struct hda_codec *codec)
2677 struct alc_spec *spec = codec->spec;
2679 hda_nid_t *adc_nids = spec->private_adc_nids;
2680 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2681 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
2684 if (spec->shared_mic_hp)
2685 max_nums = 1; /* no multi streams with the shared HP/mic */
2687 nid = codec->start_nid;
2688 for (i = 0; i < codec->num_nodes; i++, nid++) {
2690 const hda_nid_t *list;
2691 unsigned int caps = get_wcaps(codec, nid);
2692 int type = get_wcaps_type(caps);
2694 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2696 adc_nids[nums] = nid;
2697 cap_nids[nums] = nid;
2701 type = get_wcaps_type(get_wcaps(codec, src));
2702 if (type == AC_WID_PIN)
2704 if (type == AC_WID_AUD_SEL) {
2705 cap_nids[nums] = src;
2708 n = snd_hda_get_conn_list(codec, src, &list);
2710 cap_nids[nums] = src;
2716 if (++nums >= max_nums)
2719 spec->adc_nids = spec->private_adc_nids;
2720 spec->capsrc_nids = spec->private_capsrc_nids;
2721 spec->num_adc_nids = nums;
2725 /* create playback/capture controls for input pins */
2726 static int alc_auto_create_input_ctls(struct hda_codec *codec)
2728 struct alc_spec *spec = codec->spec;
2729 const struct auto_pin_cfg *cfg = &spec->autocfg;
2730 hda_nid_t mixer = spec->mixer_nid;
2731 struct hda_input_mux *imux = &spec->private_imux[0];
2733 int i, c, err, idx, type_idx = 0;
2734 const char *prev_label = NULL;
2736 num_adcs = alc_auto_fill_adc_caps(codec);
2740 for (i = 0; i < cfg->num_inputs; i++) {
2744 pin = cfg->inputs[i].pin;
2745 if (!alc_is_input_pin(codec, pin))
2748 label = hda_get_autocfg_input_label(codec, cfg, i);
2749 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
2750 label = "Headphone Mic";
2751 if (prev_label && !strcmp(label, prev_label))
2758 idx = get_connection_index(codec, mixer, pin);
2760 err = new_analog_input(spec, pin,
2768 for (c = 0; c < num_adcs; c++) {
2769 hda_nid_t cap = get_capsrc(spec, c);
2770 idx = get_connection_index(codec, cap, pin);
2772 spec->imux_pins[imux->num_items] = pin;
2773 snd_hda_add_imux_item(imux, label, idx, NULL);
2779 spec->num_mux_defs = 1;
2780 spec->input_mux = imux;
2785 /* create a shared input with the headphone out */
2786 static int alc_auto_create_shared_input(struct hda_codec *codec)
2788 struct alc_spec *spec = codec->spec;
2789 struct auto_pin_cfg *cfg = &spec->autocfg;
2790 unsigned int defcfg;
2793 /* only one internal input pin? */
2794 if (cfg->num_inputs != 1)
2796 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2797 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2800 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
2801 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
2802 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
2803 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
2805 return 0; /* both not available */
2807 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2808 return 0; /* no input */
2810 cfg->inputs[1].pin = nid;
2811 cfg->inputs[1].type = AUTO_PIN_MIC;
2812 cfg->num_inputs = 2;
2813 spec->shared_mic_hp = 1;
2814 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
2818 static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
2819 unsigned int pin_type)
2821 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2824 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2825 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2829 static int get_pin_type(int line_out_type)
2831 if (line_out_type == AUTO_PIN_HP_OUT)
2837 static void alc_auto_init_analog_input(struct hda_codec *codec)
2839 struct alc_spec *spec = codec->spec;
2840 struct auto_pin_cfg *cfg = &spec->autocfg;
2843 for (i = 0; i < cfg->num_inputs; i++) {
2844 hda_nid_t nid = cfg->inputs[i].pin;
2845 if (alc_is_input_pin(codec, nid)) {
2846 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
2847 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
2848 snd_hda_codec_write(codec, nid, 0,
2849 AC_VERB_SET_AMP_GAIN_MUTE,
2854 /* mute all loopback inputs */
2855 if (spec->mixer_nid) {
2856 int nums = snd_hda_get_conn_list(codec, spec->mixer_nid, NULL);
2857 for (i = 0; i < nums; i++)
2858 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2859 AC_VERB_SET_AMP_GAIN_MUTE,
2864 /* convert from MIX nid to DAC */
2865 static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid)
2870 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT)
2872 num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list));
2873 for (i = 0; i < num; i++) {
2874 if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT)
2880 /* go down to the selector widget before the mixer */
2881 static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin)
2884 int num = snd_hda_get_connections(codec, pin, srcs,
2887 get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL)
2892 /* get MIX nid connected to the given pin targeted to DAC */
2893 static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
2899 pin = alc_go_down_to_selector(codec, pin);
2900 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2901 for (i = 0; i < num; i++) {
2902 if (alc_auto_mix_to_dac(codec, mix[i]) == dac)
2908 /* select the connection from pin to DAC if needed */
2909 static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin,
2915 pin = alc_go_down_to_selector(codec, pin);
2916 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2919 for (i = 0; i < num; i++) {
2920 if (alc_auto_mix_to_dac(codec, mix[i]) == dac) {
2921 snd_hda_codec_update_cache(codec, pin, 0,
2922 AC_VERB_SET_CONNECT_SEL, i);
2929 static bool alc_is_dac_already_used(struct hda_codec *codec, hda_nid_t nid)
2931 struct alc_spec *spec = codec->spec;
2933 if (found_in_nid_list(nid, spec->multiout.dac_nids,
2934 ARRAY_SIZE(spec->private_dac_nids)) ||
2935 found_in_nid_list(nid, spec->multiout.hp_out_nid,
2936 ARRAY_SIZE(spec->multiout.hp_out_nid)) ||
2937 found_in_nid_list(nid, spec->multiout.extra_out_nid,
2938 ARRAY_SIZE(spec->multiout.extra_out_nid)))
2940 for (i = 0; i < spec->multi_ios; i++) {
2941 if (spec->multi_io[i].dac == nid)
2947 /* look for an empty DAC slot */
2948 static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
2953 pin = alc_go_down_to_selector(codec, pin);
2954 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
2955 for (i = 0; i < num; i++) {
2956 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
2959 if (!alc_is_dac_already_used(codec, nid))
2965 /* check whether the DAC is reachable from the pin */
2966 static bool alc_auto_is_dac_reachable(struct hda_codec *codec,
2967 hda_nid_t pin, hda_nid_t dac)
2974 pin = alc_go_down_to_selector(codec, pin);
2975 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
2976 for (i = 0; i < num; i++) {
2977 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
2984 static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
2986 struct alc_spec *spec = codec->spec;
2987 hda_nid_t sel = alc_go_down_to_selector(codec, pin);
2988 hda_nid_t nid, nid_found, srcs[5];
2989 int i, num = snd_hda_get_connections(codec, sel, srcs,
2992 return alc_auto_look_for_dac(codec, pin);
2994 for (i = 0; i < num; i++) {
2995 if (srcs[i] == spec->mixer_nid)
2997 nid = alc_auto_mix_to_dac(codec, srcs[i]);
2998 if (nid && !alc_is_dac_already_used(codec, nid)) {
3007 /* mark up volume and mute control NIDs: used during badness parsing and
3008 * at creating actual controls
3010 static inline unsigned int get_ctl_pos(unsigned int data)
3012 hda_nid_t nid = get_amp_nid_(data);
3014 if (snd_BUG_ON(nid >= MAX_VOL_NIDS))
3016 dir = get_amp_direction_(data);
3017 return (nid << 1) | dir;
3020 #define is_ctl_used(bits, data) \
3021 test_bit(get_ctl_pos(data), bits)
3022 #define mark_ctl_usage(bits, data) \
3023 set_bit(get_ctl_pos(data), bits)
3025 static void clear_vol_marks(struct hda_codec *codec)
3027 struct alc_spec *spec = codec->spec;
3028 memset(spec->vol_ctls, 0, sizeof(spec->vol_ctls));
3029 memset(spec->sw_ctls, 0, sizeof(spec->sw_ctls));
3032 /* badness definition */
3034 /* No primary DAC is found for the main output */
3035 BAD_NO_PRIMARY_DAC = 0x10000,
3036 /* No DAC is found for the extra output */
3037 BAD_NO_DAC = 0x4000,
3038 /* No possible multi-ios */
3039 BAD_MULTI_IO = 0x103,
3040 /* No individual DAC for extra output */
3041 BAD_NO_EXTRA_DAC = 0x102,
3042 /* No individual DAC for extra surrounds */
3043 BAD_NO_EXTRA_SURR_DAC = 0x101,
3044 /* Primary DAC shared with main surrounds */
3045 BAD_SHARED_SURROUND = 0x100,
3046 /* Primary DAC shared with main CLFE */
3047 BAD_SHARED_CLFE = 0x10,
3048 /* Primary DAC shared with extra surrounds */
3049 BAD_SHARED_EXTRA_SURROUND = 0x10,
3050 /* Volume widget is shared */
3051 BAD_SHARED_VOL = 0x10,
3054 static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3055 hda_nid_t pin, hda_nid_t dac);
3056 static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3057 hda_nid_t pin, hda_nid_t dac);
3059 static int eval_shared_vol_badness(struct hda_codec *codec, hda_nid_t pin,
3062 struct alc_spec *spec = codec->spec;
3067 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3069 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3070 if (is_ctl_used(spec->vol_ctls, nid))
3071 badness += BAD_SHARED_VOL;
3073 mark_ctl_usage(spec->vol_ctls, val);
3075 badness += BAD_SHARED_VOL;
3076 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3078 unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid));
3079 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT)
3080 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3082 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
3083 if (is_ctl_used(spec->sw_ctls, val))
3084 badness += BAD_SHARED_VOL;
3086 mark_ctl_usage(spec->sw_ctls, val);
3088 badness += BAD_SHARED_VOL;
3092 struct badness_table {
3093 int no_primary_dac; /* no primary DAC */
3094 int no_dac; /* no secondary DACs */
3095 int shared_primary; /* primary DAC is shared with main output */
3096 int shared_surr; /* secondary DAC shared with main or primary */
3097 int shared_clfe; /* third DAC shared with main or primary */
3098 int shared_surr_main; /* secondary DAC sahred with main/DAC0 */
3101 static struct badness_table main_out_badness = {
3102 .no_primary_dac = BAD_NO_PRIMARY_DAC,
3103 .no_dac = BAD_NO_DAC,
3104 .shared_primary = BAD_NO_PRIMARY_DAC,
3105 .shared_surr = BAD_SHARED_SURROUND,
3106 .shared_clfe = BAD_SHARED_CLFE,
3107 .shared_surr_main = BAD_SHARED_SURROUND,
3110 static struct badness_table extra_out_badness = {
3111 .no_primary_dac = BAD_NO_DAC,
3112 .no_dac = BAD_NO_DAC,
3113 .shared_primary = BAD_NO_EXTRA_DAC,
3114 .shared_surr = BAD_SHARED_EXTRA_SURROUND,
3115 .shared_clfe = BAD_SHARED_EXTRA_SURROUND,
3116 .shared_surr_main = BAD_NO_EXTRA_SURR_DAC,
3119 /* try to assign DACs to pins and return the resultant badness */
3120 static int alc_auto_fill_dacs(struct hda_codec *codec, int num_outs,
3121 const hda_nid_t *pins, hda_nid_t *dacs,
3122 const struct badness_table *bad)
3124 struct alc_spec *spec = codec->spec;
3125 struct auto_pin_cfg *cfg = &spec->autocfg;
3133 for (i = 0; i < num_outs; i++) {
3134 hda_nid_t pin = pins[i];
3136 dacs[i] = alc_auto_look_for_dac(codec, pin);
3137 if (!dacs[i] && !i) {
3138 for (j = 1; j < num_outs; j++) {
3139 if (alc_auto_is_dac_reachable(codec, pin, dacs[j])) {
3148 if (alc_auto_is_dac_reachable(codec, pin, dacs[0]))
3150 else if (cfg->line_outs > i &&
3151 alc_auto_is_dac_reachable(codec, pin,
3152 spec->private_dac_nids[i]))
3153 dac = spec->private_dac_nids[i];
3156 badness += bad->shared_primary;
3158 badness += bad->shared_surr;
3160 badness += bad->shared_clfe;
3161 } else if (alc_auto_is_dac_reachable(codec, pin,
3162 spec->private_dac_nids[0])) {
3163 dac = spec->private_dac_nids[0];
3164 badness += bad->shared_surr_main;
3166 badness += bad->no_primary_dac;
3168 badness += bad->no_dac;
3171 badness += eval_shared_vol_badness(codec, pin, dac);
3177 static int alc_auto_fill_multi_ios(struct hda_codec *codec,
3178 hda_nid_t reference_pin,
3179 bool hardwired, int offset);
3181 static bool alc_map_singles(struct hda_codec *codec, int outs,
3182 const hda_nid_t *pins, hda_nid_t *dacs)
3186 for (i = 0; i < outs; i++) {
3189 dacs[i] = get_dac_if_single(codec, pins[i]);
3196 /* fill in the dac_nids table from the parsed pin configuration */
3197 static int fill_and_eval_dacs(struct hda_codec *codec,
3198 bool fill_hardwired,
3199 bool fill_mio_first)
3201 struct alc_spec *spec = codec->spec;
3202 struct auto_pin_cfg *cfg = &spec->autocfg;
3203 int i, err, badness;
3205 /* set num_dacs once to full for alc_auto_look_for_dac() */
3206 spec->multiout.num_dacs = cfg->line_outs;
3207 spec->multiout.dac_nids = spec->private_dac_nids;
3208 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
3209 memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid));
3210 memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid));
3211 spec->multi_ios = 0;
3212 clear_vol_marks(codec);
3215 /* fill hard-wired DACs first */
3216 if (fill_hardwired) {
3219 mapped = alc_map_singles(codec, cfg->line_outs,
3221 spec->private_dac_nids);
3222 mapped |= alc_map_singles(codec, cfg->hp_outs,
3224 spec->multiout.hp_out_nid);
3225 mapped |= alc_map_singles(codec, cfg->speaker_outs,
3227 spec->multiout.extra_out_nid);
3228 if (fill_mio_first && cfg->line_outs == 1 &&
3229 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3230 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], true, 0);
3237 badness += alc_auto_fill_dacs(codec, cfg->line_outs, cfg->line_out_pins,
3238 spec->private_dac_nids,
3241 /* re-count num_dacs and squash invalid entries */
3242 spec->multiout.num_dacs = 0;
3243 for (i = 0; i < cfg->line_outs; i++) {
3244 if (spec->private_dac_nids[i])
3245 spec->multiout.num_dacs++;
3247 memmove(spec->private_dac_nids + i,
3248 spec->private_dac_nids + i + 1,
3249 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
3250 spec->private_dac_nids[cfg->line_outs - 1] = 0;
3254 if (fill_mio_first &&
3255 cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3256 /* try to fill multi-io first */
3257 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
3260 /* we don't count badness at this stage yet */
3263 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
3264 err = alc_auto_fill_dacs(codec, cfg->hp_outs, cfg->hp_pins,
3265 spec->multiout.hp_out_nid,
3266 &extra_out_badness);
3271 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3272 err = alc_auto_fill_dacs(codec, cfg->speaker_outs,
3274 spec->multiout.extra_out_nid,
3275 &extra_out_badness);
3280 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3281 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
3286 if (cfg->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3287 /* try multi-ios with HP + inputs */
3288 err = alc_auto_fill_multi_ios(codec, cfg->hp_pins[0], false, 1);
3294 if (spec->multi_ios == 2) {
3295 for (i = 0; i < 2; i++)
3296 spec->private_dac_nids[spec->multiout.num_dacs++] =
3297 spec->multi_io[i].dac;
3298 spec->ext_channel_count = 2;
3299 } else if (spec->multi_ios) {
3300 spec->multi_ios = 0;
3301 badness += BAD_MULTI_IO;
3307 #define DEBUG_BADNESS
3309 #ifdef DEBUG_BADNESS
3310 #define debug_badness snd_printdd
3312 #define debug_badness(...)
3315 static void debug_show_configs(struct alc_spec *spec, struct auto_pin_cfg *cfg)
3317 debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3318 cfg->line_out_pins[0], cfg->line_out_pins[1],
3319 cfg->line_out_pins[2], cfg->line_out_pins[2],
3320 spec->multiout.dac_nids[0],
3321 spec->multiout.dac_nids[1],
3322 spec->multiout.dac_nids[2],
3323 spec->multiout.dac_nids[3]);
3324 if (spec->multi_ios > 0)
3325 debug_badness("multi_ios(%d) = %x/%x : %x/%x\n",
3327 spec->multi_io[0].pin, spec->multi_io[1].pin,
3328 spec->multi_io[0].dac, spec->multi_io[1].dac);
3329 debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3330 cfg->hp_pins[0], cfg->hp_pins[1],
3331 cfg->hp_pins[2], cfg->hp_pins[2],
3332 spec->multiout.hp_out_nid[0],
3333 spec->multiout.hp_out_nid[1],
3334 spec->multiout.hp_out_nid[2],
3335 spec->multiout.hp_out_nid[3]);
3336 debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3337 cfg->speaker_pins[0], cfg->speaker_pins[1],
3338 cfg->speaker_pins[2], cfg->speaker_pins[3],
3339 spec->multiout.extra_out_nid[0],
3340 spec->multiout.extra_out_nid[1],
3341 spec->multiout.extra_out_nid[2],
3342 spec->multiout.extra_out_nid[3]);
3345 static int alc_auto_fill_dac_nids(struct hda_codec *codec)
3347 struct alc_spec *spec = codec->spec;
3348 struct auto_pin_cfg *cfg = &spec->autocfg;
3349 struct auto_pin_cfg *best_cfg;
3350 int best_badness = INT_MAX;
3352 bool fill_hardwired = true, fill_mio_first = true;
3353 bool best_wired = true, best_mio = true;
3354 bool hp_spk_swapped = false;
3356 best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL);
3362 badness = fill_and_eval_dacs(codec, fill_hardwired,
3366 debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n",
3367 cfg->line_out_type, fill_hardwired, fill_mio_first,
3369 debug_show_configs(spec, cfg);
3370 if (badness < best_badness) {
3371 best_badness = badness;
3373 best_wired = fill_hardwired;
3374 best_mio = fill_mio_first;
3378 fill_mio_first = !fill_mio_first;
3379 if (!fill_mio_first)
3381 fill_hardwired = !fill_hardwired;
3382 if (!fill_hardwired)
3386 hp_spk_swapped = true;
3387 if (cfg->speaker_outs > 0 &&
3388 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3389 cfg->hp_outs = cfg->line_outs;
3390 memcpy(cfg->hp_pins, cfg->line_out_pins,
3391 sizeof(cfg->hp_pins));
3392 cfg->line_outs = cfg->speaker_outs;
3393 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3394 sizeof(cfg->speaker_pins));
3395 cfg->speaker_outs = 0;
3396 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3397 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
3398 fill_hardwired = true;
3401 if (cfg->hp_outs > 0 &&
3402 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3403 cfg->speaker_outs = cfg->line_outs;
3404 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3405 sizeof(cfg->speaker_pins));
3406 cfg->line_outs = cfg->hp_outs;
3407 memcpy(cfg->line_out_pins, cfg->hp_pins,
3408 sizeof(cfg->hp_pins));
3410 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3411 cfg->line_out_type = AUTO_PIN_HP_OUT;
3412 fill_hardwired = true;
3420 fill_and_eval_dacs(codec, best_wired, best_mio);
3422 debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n",
3423 cfg->line_out_type, best_wired, best_mio);
3424 debug_show_configs(spec, cfg);
3426 if (cfg->line_out_pins[0])
3428 alc_look_for_out_vol_nid(codec, cfg->line_out_pins[0],
3429 spec->multiout.dac_nids[0]);
3431 /* clear the bitmap flags for creating controls */
3432 clear_vol_marks(codec);
3437 static int alc_auto_add_vol_ctl(struct hda_codec *codec,
3438 const char *pfx, int cidx,
3439 hda_nid_t nid, unsigned int chs)
3441 struct alc_spec *spec = codec->spec;
3445 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3446 if (is_ctl_used(spec->vol_ctls, val) && chs != 2) /* exclude LFE */
3448 mark_ctl_usage(spec->vol_ctls, val);
3449 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
3453 static int alc_auto_add_stereo_vol(struct hda_codec *codec,
3454 const char *pfx, int cidx,
3458 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3460 return alc_auto_add_vol_ctl(codec, pfx, cidx, nid, chs);
3463 /* create a mute-switch for the given mixer widget;
3464 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3466 static int alc_auto_add_sw_ctl(struct hda_codec *codec,
3467 const char *pfx, int cidx,
3468 hda_nid_t nid, unsigned int chs)
3470 struct alc_spec *spec = codec->spec;
3476 wid_type = get_wcaps_type(get_wcaps(codec, nid));
3477 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) {
3478 type = ALC_CTL_WIDGET_MUTE;
3479 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3480 } else if (snd_hda_get_conn_list(codec, nid, NULL) == 1) {
3481 type = ALC_CTL_WIDGET_MUTE;
3482 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
3484 type = ALC_CTL_BIND_MUTE;
3485 val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
3487 if (is_ctl_used(spec->sw_ctls, val) && chs != 2) /* exclude LFE */
3489 mark_ctl_usage(spec->sw_ctls, val);
3490 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
3493 static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
3494 int cidx, hda_nid_t nid)
3497 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3499 return alc_auto_add_sw_ctl(codec, pfx, cidx, nid, chs);
3502 static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3503 hda_nid_t pin, hda_nid_t dac)
3505 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3506 if (nid_has_mute(codec, pin, HDA_OUTPUT))
3508 else if (mix && nid_has_mute(codec, mix, HDA_INPUT))
3510 else if (nid_has_mute(codec, dac, HDA_OUTPUT))
3515 static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3516 hda_nid_t pin, hda_nid_t dac)
3518 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3519 if (nid_has_volume(codec, dac, HDA_OUTPUT))
3521 else if (nid_has_volume(codec, mix, HDA_OUTPUT))
3523 else if (nid_has_volume(codec, pin, HDA_OUTPUT))
3528 /* add playback controls from the parsed DAC table */
3529 static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
3530 const struct auto_pin_cfg *cfg)
3532 struct alc_spec *spec = codec->spec;
3533 int i, err, noutputs;
3535 noutputs = cfg->line_outs;
3536 if (spec->multi_ios > 0 && cfg->line_outs < 3)
3537 noutputs += spec->multi_ios;
3539 for (i = 0; i < noutputs; i++) {
3545 dac = spec->multiout.dac_nids[i];
3548 if (i >= cfg->line_outs)
3549 pin = spec->multi_io[i - 1].pin;
3551 pin = cfg->line_out_pins[i];
3553 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3554 vol = alc_look_for_out_vol_nid(codec, pin, dac);
3555 name = alc_get_line_out_pfx(spec, i, true, &index);
3556 if (!name || !strcmp(name, "CLFE")) {
3558 err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1);
3561 err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2);
3564 err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1);
3567 err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2);
3571 err = alc_auto_add_stereo_vol(codec, name, index, vol);
3574 err = alc_auto_add_stereo_sw(codec, name, index, sw);
3582 static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
3583 hda_nid_t dac, const char *pfx,
3586 struct alc_spec *spec = codec->spec;
3592 /* the corresponding DAC is already occupied */
3593 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
3594 return 0; /* no way */
3595 /* create a switch only */
3596 val = HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT);
3597 if (is_ctl_used(spec->sw_ctls, val))
3598 return 0; /* already created */
3599 mark_ctl_usage(spec->sw_ctls, val);
3600 return __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, cidx, val);
3603 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3604 vol = alc_look_for_out_vol_nid(codec, pin, dac);
3605 err = alc_auto_add_stereo_vol(codec, pfx, cidx, vol);
3608 err = alc_auto_add_stereo_sw(codec, pfx, cidx, sw);
3614 static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3616 struct hda_ctl_ops *ops)
3618 struct alc_spec *spec = codec->spec;
3619 struct hda_bind_ctls **ctlp, *ctl;
3620 snd_array_init(&spec->bind_ctls, sizeof(ctl), 8);
3621 ctlp = snd_array_new(&spec->bind_ctls);
3624 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3631 /* add playback controls for speaker and HP outputs */
3632 static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3633 const hda_nid_t *pins,
3634 const hda_nid_t *dacs,
3637 struct alc_spec *spec = codec->spec;
3638 struct hda_bind_ctls *ctl;
3642 if (!num_pins || !pins[0])
3645 if (num_pins == 1) {
3646 hda_nid_t dac = *dacs;
3648 dac = spec->multiout.dac_nids[0];
3649 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
3652 if (dacs[num_pins - 1]) {
3653 /* OK, we have a multi-output system with individual volumes */
3654 for (i = 0; i < num_pins; i++) {
3655 if (num_pins >= 3) {
3656 snprintf(name, sizeof(name), "%s %s",
3657 pfx, channel_name[i]);
3658 err = alc_auto_create_extra_out(codec, pins[i], dacs[i],
3661 err = alc_auto_create_extra_out(codec, pins[i], dacs[i],
3670 /* Let's create a bind-controls */
3671 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_sw);
3675 for (i = 0; i < num_pins; i++) {
3676 if (get_wcaps(codec, pins[i]) & AC_WCAP_OUT_AMP)
3678 HDA_COMPOSE_AMP_VAL(pins[i], 3, 0, HDA_OUTPUT);
3681 snprintf(name, sizeof(name), "%s Playback Switch", pfx);
3682 err = add_control(spec, ALC_CTL_BIND_SW, name, 0, (long)ctl);
3687 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3691 for (i = 0; i < num_pins; i++) {
3693 if (!pins[i] || !dacs[i])
3695 vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]);
3698 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3701 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3702 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3709 static int alc_auto_create_hp_out(struct hda_codec *codec)
3711 struct alc_spec *spec = codec->spec;
3712 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3713 spec->autocfg.hp_pins,
3714 spec->multiout.hp_out_nid,
3718 static int alc_auto_create_speaker_out(struct hda_codec *codec)
3720 struct alc_spec *spec = codec->spec;
3721 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3722 spec->autocfg.speaker_pins,
3723 spec->multiout.extra_out_nid,
3727 static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
3728 hda_nid_t pin, int pin_type,
3732 hda_nid_t nid, mix = 0;
3733 hda_nid_t srcs[HDA_MAX_CONNECTIONS];
3735 alc_set_pin_output(codec, pin, pin_type);
3736 nid = alc_go_down_to_selector(codec, pin);
3737 num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
3738 for (i = 0; i < num; i++) {
3739 if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
3747 /* need the manual connection? */
3749 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
3750 /* unmute mixer widget inputs */
3751 if (nid_has_mute(codec, mix, HDA_INPUT)) {
3752 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3754 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3757 /* initialize volume */
3758 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3760 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3763 /* unmute DAC if it's not assigned to a mixer */
3764 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3765 if (nid == mix && nid_has_mute(codec, dac, HDA_OUTPUT))
3766 snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3770 static void alc_auto_init_multi_out(struct hda_codec *codec)
3772 struct alc_spec *spec = codec->spec;
3773 int pin_type = get_pin_type(spec->autocfg.line_out_type);
3776 for (i = 0; i <= HDA_SIDE; i++) {
3777 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3779 alc_auto_set_output_and_unmute(codec, nid, pin_type,
3780 spec->multiout.dac_nids[i]);
3784 static void alc_auto_init_extra_out(struct hda_codec *codec)
3786 struct alc_spec *spec = codec->spec;
3790 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3791 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3793 pin = spec->autocfg.hp_pins[i];
3796 dac = spec->multiout.hp_out_nid[i];
3798 if (i > 0 && spec->multiout.hp_out_nid[0])
3799 dac = spec->multiout.hp_out_nid[0];
3801 dac = spec->multiout.dac_nids[0];
3803 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
3805 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3806 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3808 pin = spec->autocfg.speaker_pins[i];
3811 dac = spec->multiout.extra_out_nid[i];
3813 if (i > 0 && spec->multiout.extra_out_nid[0])
3814 dac = spec->multiout.extra_out_nid[0];
3816 dac = spec->multiout.dac_nids[0];
3818 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
3822 /* check whether the given pin can be a multi-io pin */
3823 static bool can_be_multiio_pin(struct hda_codec *codec,
3824 unsigned int location, hda_nid_t nid)
3826 unsigned int defcfg, caps;
3828 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3829 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3831 if (location && get_defcfg_location(defcfg) != location)
3833 caps = snd_hda_query_pin_caps(codec, nid);
3834 if (!(caps & AC_PINCAP_OUT))
3842 * When hardwired is set, try to fill ony hardwired pins, and returns
3843 * zero if any pins are filled, non-zero if nothing found.
3844 * When hardwired is off, try to fill possible input pins, and returns
3845 * the badness value.
3847 static int alc_auto_fill_multi_ios(struct hda_codec *codec,
3848 hda_nid_t reference_pin,
3849 bool hardwired, int offset)
3851 struct alc_spec *spec = codec->spec;
3852 struct auto_pin_cfg *cfg = &spec->autocfg;
3853 int type, i, j, dacs, num_pins, old_pins;
3854 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
3855 unsigned int location = get_defcfg_location(defcfg);
3858 old_pins = spec->multi_ios;
3863 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3864 for (i = 0; i < cfg->num_inputs; i++) {
3865 if (cfg->inputs[i].type != type)
3867 if (can_be_multiio_pin(codec, location,
3868 cfg->inputs[i].pin))
3875 dacs = spec->multiout.num_dacs;
3876 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3877 for (i = 0; i < cfg->num_inputs; i++) {
3878 hda_nid_t nid = cfg->inputs[i].pin;
3881 if (cfg->inputs[i].type != type)
3883 if (!can_be_multiio_pin(codec, location, nid))
3885 for (j = 0; j < spec->multi_ios; j++) {
3886 if (nid == spec->multi_io[j].pin)
3889 if (j < spec->multi_ios)
3892 if (offset && offset + spec->multi_ios < dacs) {
3893 dac = spec->private_dac_nids[offset + spec->multi_ios];
3894 if (!alc_auto_is_dac_reachable(codec, nid, dac))
3898 dac = get_dac_if_single(codec, nid);
3900 dac = alc_auto_look_for_dac(codec, nid);
3905 spec->multi_io[spec->multi_ios].pin = nid;
3906 spec->multi_io[spec->multi_ios].dac = dac;
3908 if (spec->multi_ios >= 2)
3914 badness = BAD_MULTI_IO;
3915 if (old_pins == spec->multi_ios) {
3917 return 1; /* nothing found */
3919 return badness; /* no badness if nothing found */
3921 if (!hardwired && spec->multi_ios < 2) {
3922 spec->multi_ios = old_pins;
3929 static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
3930 struct snd_ctl_elem_info *uinfo)
3932 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3933 struct alc_spec *spec = codec->spec;
3935 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3937 uinfo->value.enumerated.items = spec->multi_ios + 1;
3938 if (uinfo->value.enumerated.item > spec->multi_ios)
3939 uinfo->value.enumerated.item = spec->multi_ios;
3940 sprintf(uinfo->value.enumerated.name, "%dch",
3941 (uinfo->value.enumerated.item + 1) * 2);
3945 static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
3946 struct snd_ctl_elem_value *ucontrol)
3948 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3949 struct alc_spec *spec = codec->spec;
3950 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
3954 static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
3956 struct alc_spec *spec = codec->spec;
3957 hda_nid_t nid = spec->multi_io[idx].pin;
3959 if (!spec->multi_io[idx].ctl_in)
3960 spec->multi_io[idx].ctl_in =
3961 snd_hda_codec_read(codec, nid, 0,
3962 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3964 snd_hda_codec_update_cache(codec, nid, 0,
3965 AC_VERB_SET_PIN_WIDGET_CONTROL,
3967 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3968 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3970 alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
3972 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3973 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3974 HDA_AMP_MUTE, HDA_AMP_MUTE);
3975 snd_hda_codec_update_cache(codec, nid, 0,
3976 AC_VERB_SET_PIN_WIDGET_CONTROL,
3977 spec->multi_io[idx].ctl_in);
3982 static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
3983 struct snd_ctl_elem_value *ucontrol)
3985 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3986 struct alc_spec *spec = codec->spec;
3989 ch = ucontrol->value.enumerated.item[0];
3990 if (ch < 0 || ch > spec->multi_ios)
3992 if (ch == (spec->ext_channel_count - 1) / 2)
3994 spec->ext_channel_count = (ch + 1) * 2;
3995 for (i = 0; i < spec->multi_ios; i++)
3996 alc_set_multi_io(codec, i, i < ch);
3997 spec->multiout.max_channels = spec->ext_channel_count;
3998 if (spec->need_dac_fix && !spec->const_channel_count)
3999 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
4003 static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
4004 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4005 .name = "Channel Mode",
4006 .info = alc_auto_ch_mode_info,
4007 .get = alc_auto_ch_mode_get,
4008 .put = alc_auto_ch_mode_put,
4011 static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
4013 struct alc_spec *spec = codec->spec;
4015 if (spec->multi_ios > 0) {
4016 struct snd_kcontrol_new *knew;
4018 knew = alc_kcontrol_new(spec);
4021 *knew = alc_auto_channel_mode_enum;
4022 knew->name = kstrdup("Channel Mode", GFP_KERNEL);
4029 /* filter out invalid adc_nids (and capsrc_nids) that don't give all
4032 static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
4034 struct alc_spec *spec = codec->spec;
4035 const struct hda_input_mux *imux;
4036 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4037 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4040 imux = spec->input_mux;
4043 if (spec->dyn_adc_switch)
4047 for (n = 0; n < spec->num_adc_nids; n++) {
4048 hda_nid_t cap = spec->private_capsrc_nids[n];
4049 int num_conns = snd_hda_get_conn_list(codec, cap, NULL);
4050 for (i = 0; i < imux->num_items; i++) {
4051 hda_nid_t pin = spec->imux_pins[i];
4053 if (get_connection_index(codec, cap, pin) < 0)
4055 } else if (num_conns <= imux->items[i].index)
4058 if (i >= imux->num_items) {
4059 adc_nids[nums] = spec->private_adc_nids[n];
4060 capsrc_nids[nums++] = cap;
4064 /* check whether ADC-switch is possible */
4065 if (!alc_check_dyn_adc_switch(codec)) {
4066 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
4067 " using fallback 0x%x\n",
4068 codec->chip_name, spec->private_adc_nids[0]);
4069 spec->num_adc_nids = 1;
4073 } else if (nums != spec->num_adc_nids) {
4074 memcpy(spec->private_adc_nids, adc_nids,
4075 nums * sizeof(hda_nid_t));
4076 memcpy(spec->private_capsrc_nids, capsrc_nids,
4077 nums * sizeof(hda_nid_t));
4078 spec->num_adc_nids = nums;
4082 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
4083 else if (spec->input_mux->num_items == 1)
4084 spec->num_adc_nids = 1; /* reduce to a single ADC */
4088 * initialize ADC paths
4090 static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
4092 struct alc_spec *spec = codec->spec;
4095 nid = spec->adc_nids[adc_idx];
4097 if (nid_has_mute(codec, nid, HDA_INPUT)) {
4098 snd_hda_codec_write(codec, nid, 0,
4099 AC_VERB_SET_AMP_GAIN_MUTE,
4103 if (!spec->capsrc_nids)
4105 nid = spec->capsrc_nids[adc_idx];
4106 if (nid_has_mute(codec, nid, HDA_OUTPUT))
4107 snd_hda_codec_write(codec, nid, 0,
4108 AC_VERB_SET_AMP_GAIN_MUTE,
4112 static void alc_auto_init_input_src(struct hda_codec *codec)
4114 struct alc_spec *spec = codec->spec;
4117 for (c = 0; c < spec->num_adc_nids; c++)
4118 alc_auto_init_adc(codec, c);
4119 if (spec->dyn_adc_switch)
4122 nums = spec->num_adc_nids;
4123 for (c = 0; c < nums; c++)
4124 alc_mux_select(codec, 0, spec->cur_mux[c], true);
4127 /* add mic boosts if needed */
4128 static int alc_auto_add_mic_boost(struct hda_codec *codec)
4130 struct alc_spec *spec = codec->spec;
4131 struct auto_pin_cfg *cfg = &spec->autocfg;
4135 const char *prev_label = NULL;
4137 for (i = 0; i < cfg->num_inputs; i++) {
4138 if (cfg->inputs[i].type > AUTO_PIN_MIC)
4140 nid = cfg->inputs[i].pin;
4141 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
4143 char boost_label[32];
4145 label = hda_get_autocfg_input_label(codec, cfg, i);
4146 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
4147 label = "Headphone Mic";
4148 if (prev_label && !strcmp(label, prev_label))
4154 snprintf(boost_label, sizeof(boost_label),
4155 "%s Boost Volume", label);
4156 err = add_control(spec, ALC_CTL_WIDGET_VOL,
4157 boost_label, type_idx,
4158 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
4166 /* select or unmute the given capsrc route */
4167 static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
4170 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
4171 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
4173 } else if (snd_hda_get_conn_list(codec, cap, NULL) > 1) {
4174 snd_hda_codec_write_cache(codec, cap, 0,
4175 AC_VERB_SET_CONNECT_SEL, idx);
4179 /* set the default connection to that pin */
4180 static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
4182 struct alc_spec *spec = codec->spec;
4187 for (i = 0; i < spec->num_adc_nids; i++) {
4188 hda_nid_t cap = get_capsrc(spec, i);
4191 idx = get_connection_index(codec, cap, pin);
4194 select_or_unmute_capsrc(codec, cap, idx);
4195 return i; /* return the found index */
4197 return -1; /* not found */
4200 /* initialize some special cases for input sources */
4201 static void alc_init_special_input_src(struct hda_codec *codec)
4203 struct alc_spec *spec = codec->spec;
4206 for (i = 0; i < spec->autocfg.num_inputs; i++)
4207 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
4210 /* assign appropriate capture mixers */
4211 static void set_capture_mixer(struct hda_codec *codec)
4213 struct alc_spec *spec = codec->spec;
4214 static const struct snd_kcontrol_new *caps[2][3] = {
4215 { alc_capture_mixer_nosrc1,
4216 alc_capture_mixer_nosrc2,
4217 alc_capture_mixer_nosrc3 },
4218 { alc_capture_mixer1,
4220 alc_capture_mixer3 },
4223 /* check whether either of ADC or MUX has a volume control */
4224 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
4225 if (!spec->capsrc_nids)
4226 return; /* no volume */
4227 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
4228 return; /* no volume in capsrc, too */
4229 spec->vol_in_capsrc = 1;
4232 if (spec->num_adc_nids > 0) {
4236 if (spec->input_mux && spec->input_mux->num_items > 1)
4238 if (spec->auto_mic) {
4241 } else if (spec->dyn_adc_switch)
4244 if (spec->num_adc_nids > 3)
4245 spec->num_adc_nids = 3;
4246 else if (!spec->num_adc_nids)
4248 num_adcs = spec->num_adc_nids;
4250 spec->cap_mixer = caps[mux][num_adcs - 1];
4255 * standard auto-parser initializations
4257 static void alc_auto_init_std(struct hda_codec *codec)
4259 struct alc_spec *spec = codec->spec;
4260 alc_auto_init_multi_out(codec);
4261 alc_auto_init_extra_out(codec);
4262 alc_auto_init_analog_input(codec);
4263 alc_auto_init_input_src(codec);
4264 alc_auto_init_digital(codec);
4265 if (spec->unsol_event)
4266 alc_inithook(codec);
4270 * Digital-beep handlers
4272 #ifdef CONFIG_SND_HDA_INPUT_BEEP
4273 #define set_beep_amp(spec, nid, idx, dir) \
4274 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4276 static const struct snd_pci_quirk beep_white_list[] = {
4277 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
4278 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
4279 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
4280 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
4281 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
4285 static inline int has_cdefine_beep(struct hda_codec *codec)
4287 struct alc_spec *spec = codec->spec;
4288 const struct snd_pci_quirk *q;
4289 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
4292 return spec->cdefine.enable_pcbeep;
4295 #define set_beep_amp(spec, nid, idx, dir) /* NOP */
4296 #define has_cdefine_beep(codec) 0
4299 /* parse the BIOS configuration and set up the alc_spec */
4300 /* return 1 if successful, 0 if the proper config is not found,
4301 * or a negative error code
4303 static int alc_parse_auto_config(struct hda_codec *codec,
4304 const hda_nid_t *ignore_nids,
4305 const hda_nid_t *ssid_nids)
4307 struct alc_spec *spec = codec->spec;
4308 struct auto_pin_cfg *cfg = &spec->autocfg;
4311 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
4315 if (!cfg->line_outs) {
4316 if (cfg->dig_outs || cfg->dig_in_pin) {
4317 spec->multiout.max_channels = 2;
4318 spec->no_analog = 1;
4321 return 0; /* can't find valid BIOS pin config */
4324 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
4325 cfg->line_outs <= cfg->hp_outs) {
4326 /* use HP as primary out */
4327 cfg->speaker_outs = cfg->line_outs;
4328 memcpy(cfg->speaker_pins, cfg->line_out_pins,
4329 sizeof(cfg->speaker_pins));
4330 cfg->line_outs = cfg->hp_outs;
4331 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
4333 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
4334 cfg->line_out_type = AUTO_PIN_HP_OUT;
4337 err = alc_auto_fill_dac_nids(codec);
4340 err = alc_auto_add_multi_channel_mode(codec);
4343 err = alc_auto_create_multi_out_ctls(codec, cfg);
4346 err = alc_auto_create_hp_out(codec);
4349 err = alc_auto_create_speaker_out(codec);
4352 err = alc_auto_create_shared_input(codec);
4355 err = alc_auto_create_input_ctls(codec);
4359 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4362 alc_auto_parse_digital(codec);
4364 if (!spec->no_analog)
4365 alc_remove_invalid_adc_nids(codec);
4368 alc_ssid_check(codec, ssid_nids);
4370 if (!spec->no_analog) {
4371 alc_auto_check_switches(codec);
4372 err = alc_auto_add_mic_boost(codec);
4377 if (spec->kctls.list)
4378 add_mixer(spec, spec->kctls.list);
4383 static int alc880_parse_auto_config(struct hda_codec *codec)
4385 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
4386 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4387 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
4390 #ifdef CONFIG_SND_HDA_POWER_SAVE
4391 static const struct hda_amp_list alc880_loopbacks[] = {
4392 { 0x0b, HDA_INPUT, 0 },
4393 { 0x0b, HDA_INPUT, 1 },
4394 { 0x0b, HDA_INPUT, 2 },
4395 { 0x0b, HDA_INPUT, 3 },
4396 { 0x0b, HDA_INPUT, 4 },
4406 ALC880_FIXUP_MEDION_RIM,
4409 ALC880_FIXUP_EAPD_COEF,
4410 ALC880_FIXUP_TCL_S700,
4413 static const struct alc_fixup alc880_fixups[] = {
4414 [ALC880_FIXUP_GPIO2] = {
4415 .type = ALC_FIXUP_VERBS,
4416 .v.verbs = alc_gpio2_init_verbs,
4418 [ALC880_FIXUP_MEDION_RIM] = {
4419 .type = ALC_FIXUP_VERBS,
4420 .v.verbs = (const struct hda_verb[]) {
4421 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4422 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4426 .chain_id = ALC880_FIXUP_GPIO2,
4428 [ALC880_FIXUP_LG] = {
4429 .type = ALC_FIXUP_PINS,
4430 .v.pins = (const struct alc_pincfg[]) {
4431 /* disable bogus unused pins */
4432 { 0x16, 0x411111f0 },
4433 { 0x18, 0x411111f0 },
4434 { 0x1a, 0x411111f0 },
4438 [ALC880_FIXUP_W810] = {
4439 .type = ALC_FIXUP_PINS,
4440 .v.pins = (const struct alc_pincfg[]) {
4441 /* disable bogus unused pins */
4442 { 0x17, 0x411111f0 },
4446 .chain_id = ALC880_FIXUP_GPIO2,
4448 [ALC880_FIXUP_EAPD_COEF] = {
4449 .type = ALC_FIXUP_VERBS,
4450 .v.verbs = (const struct hda_verb[]) {
4451 /* change to EAPD mode */
4452 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4453 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4457 [ALC880_FIXUP_TCL_S700] = {
4458 .type = ALC_FIXUP_VERBS,
4459 .v.verbs = (const struct hda_verb[]) {
4460 /* change to EAPD mode */
4461 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4462 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4466 .chain_id = ALC880_FIXUP_GPIO2,
4470 static const struct snd_pci_quirk alc880_fixup_tbl[] = {
4471 SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_FIXUP_W810),
4472 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo", ALC880_FIXUP_EAPD_COEF),
4473 SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_FIXUP_W810),
4474 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
4475 SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_FIXUP_LG),
4476 SND_PCI_QUIRK(0x1854, 0x005f, "LG P1 Express", ALC880_FIXUP_LG),
4477 SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_FIXUP_LG),
4478 SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_FIXUP_TCL_S700),
4486 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4487 #define alc_board_config \
4488 snd_hda_check_board_config
4489 #define alc_board_codec_sid_config \
4490 snd_hda_check_board_codec_sid_config
4491 #include "alc_quirks.c"
4493 #define alc_board_config(codec, nums, models, tbl) -1
4494 #define alc_board_codec_sid_config(codec, nums, models, tbl) -1
4495 #define setup_preset(codec, x) /* NOP */
4499 * OK, here we have finally the patch for ALC880
4501 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4502 #include "alc880_quirks.c"
4505 static int patch_alc880(struct hda_codec *codec)
4507 struct alc_spec *spec;
4511 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4517 spec->mixer_nid = 0x0b;
4518 spec->need_dac_fix = 1;
4520 board_config = alc_board_config(codec, ALC880_MODEL_LAST,
4521 alc880_models, alc880_cfg_tbl);
4522 if (board_config < 0) {
4523 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4525 board_config = ALC_MODEL_AUTO;
4528 if (board_config == ALC_MODEL_AUTO) {
4529 alc_pick_fixup(codec, NULL, alc880_fixup_tbl, alc880_fixups);
4530 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4533 if (board_config == ALC_MODEL_AUTO) {
4534 /* automatic parse from the BIOS config */
4535 err = alc880_parse_auto_config(codec);
4538 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4541 "hda_codec: Cannot set up configuration "
4542 "from BIOS. Using 3-stack mode...\n");
4543 board_config = ALC880_3ST;
4548 if (board_config != ALC_MODEL_AUTO) {
4549 spec->vmaster_nid = 0x0c;
4550 setup_preset(codec, &alc880_presets[board_config]);
4553 if (!spec->no_analog && !spec->adc_nids) {
4554 alc_auto_fill_adc_caps(codec);
4555 alc_rebuild_imux_for_auto_mic(codec);
4556 alc_remove_invalid_adc_nids(codec);
4559 if (!spec->no_analog && !spec->cap_mixer)
4560 set_capture_mixer(codec);
4562 if (!spec->no_analog) {
4563 err = snd_hda_attach_beep_device(codec, 0x1);
4566 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4569 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4571 codec->patch_ops = alc_patch_ops;
4572 if (board_config == ALC_MODEL_AUTO)
4573 spec->init_hook = alc_auto_init_std;
4575 codec->patch_ops.build_controls = __alc_build_controls;
4576 #ifdef CONFIG_SND_HDA_POWER_SAVE
4577 if (!spec->loopback.amplist)
4578 spec->loopback.amplist = alc880_loopbacks;
4592 static int alc260_parse_auto_config(struct hda_codec *codec)
4594 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
4595 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
4596 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
4599 #ifdef CONFIG_SND_HDA_POWER_SAVE
4600 static const struct hda_amp_list alc260_loopbacks[] = {
4601 { 0x07, HDA_INPUT, 0 },
4602 { 0x07, HDA_INPUT, 1 },
4603 { 0x07, HDA_INPUT, 2 },
4604 { 0x07, HDA_INPUT, 3 },
4605 { 0x07, HDA_INPUT, 4 },
4614 ALC260_FIXUP_HP_DC5750,
4615 ALC260_FIXUP_HP_PIN_0F,
4618 ALC260_FIXUP_GPIO1_TOGGLE,
4619 ALC260_FIXUP_REPLACER,
4620 ALC260_FIXUP_HP_B1900,
4623 static void alc260_gpio1_automute(struct hda_codec *codec)
4625 struct alc_spec *spec = codec->spec;
4626 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
4627 spec->hp_jack_present);
4630 static void alc260_fixup_gpio1_toggle(struct hda_codec *codec,
4631 const struct alc_fixup *fix, int action)
4633 struct alc_spec *spec = codec->spec;
4634 if (action == ALC_FIXUP_ACT_PROBE) {
4635 /* although the machine has only one output pin, we need to
4636 * toggle GPIO1 according to the jack state
4638 spec->automute_hook = alc260_gpio1_automute;
4639 spec->detect_hp = 1;
4640 spec->automute_speaker = 1;
4641 spec->autocfg.hp_pins[0] = 0x0f; /* copy it for automute */
4642 snd_hda_jack_detect_enable(codec, 0x0f, ALC_HP_EVENT);
4643 spec->unsol_event = alc_sku_unsol_event;
4644 add_verb(codec->spec, alc_gpio1_init_verbs);
4648 static const struct alc_fixup alc260_fixups[] = {
4649 [ALC260_FIXUP_HP_DC5750] = {
4650 .type = ALC_FIXUP_PINS,
4651 .v.pins = (const struct alc_pincfg[]) {
4652 { 0x11, 0x90130110 }, /* speaker */
4656 [ALC260_FIXUP_HP_PIN_0F] = {
4657 .type = ALC_FIXUP_PINS,
4658 .v.pins = (const struct alc_pincfg[]) {
4659 { 0x0f, 0x01214000 }, /* HP */
4663 [ALC260_FIXUP_COEF] = {
4664 .type = ALC_FIXUP_VERBS,
4665 .v.verbs = (const struct hda_verb[]) {
4666 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4667 { 0x20, AC_VERB_SET_PROC_COEF, 0x3040 },
4671 .chain_id = ALC260_FIXUP_HP_PIN_0F,
4673 [ALC260_FIXUP_GPIO1] = {
4674 .type = ALC_FIXUP_VERBS,
4675 .v.verbs = alc_gpio1_init_verbs,
4677 [ALC260_FIXUP_GPIO1_TOGGLE] = {
4678 .type = ALC_FIXUP_FUNC,
4679 .v.func = alc260_fixup_gpio1_toggle,
4681 .chain_id = ALC260_FIXUP_HP_PIN_0F,
4683 [ALC260_FIXUP_REPLACER] = {
4684 .type = ALC_FIXUP_VERBS,
4685 .v.verbs = (const struct hda_verb[]) {
4686 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4687 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4691 .chain_id = ALC260_FIXUP_GPIO1_TOGGLE,
4693 [ALC260_FIXUP_HP_B1900] = {
4694 .type = ALC_FIXUP_FUNC,
4695 .v.func = alc260_fixup_gpio1_toggle,
4697 .chain_id = ALC260_FIXUP_COEF,
4701 static const struct snd_pci_quirk alc260_fixup_tbl[] = {
4702 SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_FIXUP_GPIO1),
4703 SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF),
4704 SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1),
4705 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750),
4706 SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900),
4707 SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1),
4708 SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER),
4709 SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_FIXUP_COEF),
4715 static int patch_alc260(struct hda_codec *codec)
4717 struct alc_spec *spec;
4720 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4726 spec->mixer_nid = 0x07;
4728 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
4729 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4731 /* automatic parse from the BIOS config */
4732 err = alc260_parse_auto_config(codec);
4736 if (!spec->no_analog && !spec->adc_nids) {
4737 alc_auto_fill_adc_caps(codec);
4738 alc_rebuild_imux_for_auto_mic(codec);
4739 alc_remove_invalid_adc_nids(codec);
4742 if (!spec->no_analog && !spec->cap_mixer)
4743 set_capture_mixer(codec);
4745 if (!spec->no_analog) {
4746 err = snd_hda_attach_beep_device(codec, 0x1);
4749 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
4752 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4754 codec->patch_ops = alc_patch_ops;
4755 spec->init_hook = alc_auto_init_std;
4756 spec->shutup = alc_eapd_shutup;
4757 #ifdef CONFIG_SND_HDA_POWER_SAVE
4758 if (!spec->loopback.amplist)
4759 spec->loopback.amplist = alc260_loopbacks;
4771 * ALC882/883/885/888/889 support
4773 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
4774 * configuration. Each pin widget can choose any input DACs and a mixer.
4775 * Each ADC is connected from a mixer of all inputs. This makes possible
4776 * 6-channel independent captures.
4778 * In addition, an independent DAC for the multi-playback (not used in this
4781 #ifdef CONFIG_SND_HDA_POWER_SAVE
4782 #define alc882_loopbacks alc880_loopbacks
4789 ALC882_FIXUP_ABIT_AW9D_MAX,
4790 ALC882_FIXUP_LENOVO_Y530,
4791 ALC882_FIXUP_PB_M5210,
4792 ALC882_FIXUP_ACER_ASPIRE_7736,
4793 ALC882_FIXUP_ASUS_W90V,
4794 ALC889_FIXUP_VAIO_TT,
4795 ALC888_FIXUP_EEE1601,
4798 ALC883_FIXUP_ACER_EAPD,
4801 ALC882_FIXUP_ASUS_W2JC,
4802 ALC882_FIXUP_ACER_ASPIRE_4930G,
4803 ALC882_FIXUP_ACER_ASPIRE_8930G,
4804 ALC882_FIXUP_ASPIRE_8930G_VERBS,
4805 ALC885_FIXUP_MACPRO_GPIO,
4806 ALC889_FIXUP_DAC_ROUTE,
4809 static void alc889_fixup_coef(struct hda_codec *codec,
4810 const struct alc_fixup *fix, int action)
4812 if (action != ALC_FIXUP_ACT_INIT)
4814 alc889_coef_init(codec);
4817 /* toggle speaker-output according to the hp-jack state */
4818 static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
4820 unsigned int gpiostate, gpiomask, gpiodir;
4822 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
4823 AC_VERB_GET_GPIO_DATA, 0);
4826 gpiostate |= (1 << pin);
4828 gpiostate &= ~(1 << pin);
4830 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
4831 AC_VERB_GET_GPIO_MASK, 0);
4832 gpiomask |= (1 << pin);
4834 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
4835 AC_VERB_GET_GPIO_DIRECTION, 0);
4836 gpiodir |= (1 << pin);
4839 snd_hda_codec_write(codec, codec->afg, 0,
4840 AC_VERB_SET_GPIO_MASK, gpiomask);
4841 snd_hda_codec_write(codec, codec->afg, 0,
4842 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
4846 snd_hda_codec_write(codec, codec->afg, 0,
4847 AC_VERB_SET_GPIO_DATA, gpiostate);
4850 /* set up GPIO at initialization */
4851 static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
4852 const struct alc_fixup *fix, int action)
4854 if (action != ALC_FIXUP_ACT_INIT)
4856 alc882_gpio_mute(codec, 0, 0);
4857 alc882_gpio_mute(codec, 1, 0);
4860 /* Fix the connection of some pins for ALC889:
4861 * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
4862 * work correctly (bko#42740)
4864 static void alc889_fixup_dac_route(struct hda_codec *codec,
4865 const struct alc_fixup *fix, int action)
4867 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
4868 hda_nid_t conn1[2] = { 0x0c, 0x0d };
4869 hda_nid_t conn2[2] = { 0x0e, 0x0f };
4870 snd_hda_override_conn_list(codec, 0x14, 2, conn1);
4871 snd_hda_override_conn_list(codec, 0x15, 2, conn1);
4872 snd_hda_override_conn_list(codec, 0x18, 2, conn2);
4873 snd_hda_override_conn_list(codec, 0x1a, 2, conn2);
4877 static const struct alc_fixup alc882_fixups[] = {
4878 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
4879 .type = ALC_FIXUP_PINS,
4880 .v.pins = (const struct alc_pincfg[]) {
4881 { 0x15, 0x01080104 }, /* side */
4882 { 0x16, 0x01011012 }, /* rear */
4883 { 0x17, 0x01016011 }, /* clfe */
4887 [ALC882_FIXUP_LENOVO_Y530] = {
4888 .type = ALC_FIXUP_PINS,
4889 .v.pins = (const struct alc_pincfg[]) {
4890 { 0x15, 0x99130112 }, /* rear int speakers */
4891 { 0x16, 0x99130111 }, /* subwoofer */
4895 [ALC882_FIXUP_PB_M5210] = {
4896 .type = ALC_FIXUP_VERBS,
4897 .v.verbs = (const struct hda_verb[]) {
4898 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
4902 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
4903 .type = ALC_FIXUP_SKU,
4904 .v.sku = ALC_FIXUP_SKU_IGNORE,
4906 [ALC882_FIXUP_ASUS_W90V] = {
4907 .type = ALC_FIXUP_PINS,
4908 .v.pins = (const struct alc_pincfg[]) {
4909 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
4913 [ALC889_FIXUP_VAIO_TT] = {
4914 .type = ALC_FIXUP_PINS,
4915 .v.pins = (const struct alc_pincfg[]) {
4916 { 0x17, 0x90170111 }, /* hidden surround speaker */
4920 [ALC888_FIXUP_EEE1601] = {
4921 .type = ALC_FIXUP_VERBS,
4922 .v.verbs = (const struct hda_verb[]) {
4923 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
4924 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
4928 [ALC882_FIXUP_EAPD] = {
4929 .type = ALC_FIXUP_VERBS,
4930 .v.verbs = (const struct hda_verb[]) {
4931 /* change to EAPD mode */
4932 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4933 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4937 [ALC883_FIXUP_EAPD] = {
4938 .type = ALC_FIXUP_VERBS,
4939 .v.verbs = (const struct hda_verb[]) {
4940 /* change to EAPD mode */
4941 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4942 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4946 [ALC883_FIXUP_ACER_EAPD] = {
4947 .type = ALC_FIXUP_VERBS,
4948 .v.verbs = (const struct hda_verb[]) {
4949 /* eanable EAPD on Acer laptops */
4950 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4951 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4955 [ALC882_FIXUP_GPIO3] = {
4956 .type = ALC_FIXUP_VERBS,
4957 .v.verbs = alc_gpio3_init_verbs,
4959 [ALC882_FIXUP_ASUS_W2JC] = {
4960 .type = ALC_FIXUP_VERBS,
4961 .v.verbs = alc_gpio1_init_verbs,
4963 .chain_id = ALC882_FIXUP_EAPD,
4965 [ALC889_FIXUP_COEF] = {
4966 .type = ALC_FIXUP_FUNC,
4967 .v.func = alc889_fixup_coef,
4969 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
4970 .type = ALC_FIXUP_PINS,
4971 .v.pins = (const struct alc_pincfg[]) {
4972 { 0x16, 0x99130111 }, /* CLFE speaker */
4973 { 0x17, 0x99130112 }, /* surround speaker */
4977 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
4978 .type = ALC_FIXUP_PINS,
4979 .v.pins = (const struct alc_pincfg[]) {
4980 { 0x16, 0x99130111 }, /* CLFE speaker */
4981 { 0x1b, 0x99130112 }, /* surround speaker */
4985 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
4987 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
4988 /* additional init verbs for Acer Aspire 8930G */
4989 .type = ALC_FIXUP_VERBS,
4990 .v.verbs = (const struct hda_verb[]) {
4991 /* Enable all DACs */
4992 /* DAC DISABLE/MUTE 1? */
4993 /* setting bits 1-5 disables DAC nids 0x02-0x06
4994 * apparently. Init=0x38 */
4995 { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
4996 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
4997 /* DAC DISABLE/MUTE 2? */
4998 /* some bit here disables the other DACs.
5000 { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
5001 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5003 * This laptop has a stereo digital microphone.
5004 * The mics are only 1cm apart which makes the stereo
5005 * useless. However, either the mic or the ALC889
5006 * makes the signal become a difference/sum signal
5007 * instead of standard stereo, which is annoying.
5008 * So instead we flip this bit which makes the
5009 * codec replicate the sum signal to both channels,
5010 * turning it into a normal mono mic.
5012 /* DMIC_CONTROL? Init value = 0x0001 */
5013 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5014 { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
5015 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5016 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5020 [ALC885_FIXUP_MACPRO_GPIO] = {
5021 .type = ALC_FIXUP_FUNC,
5022 .v.func = alc885_fixup_macpro_gpio,
5024 [ALC889_FIXUP_DAC_ROUTE] = {
5025 .type = ALC_FIXUP_FUNC,
5026 .v.func = alc889_fixup_dac_route,
5030 static const struct snd_pci_quirk alc882_fixup_tbl[] = {
5031 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
5032 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5033 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
5034 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5035 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
5036 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
5037 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
5038 ALC882_FIXUP_ACER_ASPIRE_4930G),
5039 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
5040 ALC882_FIXUP_ACER_ASPIRE_4930G),
5041 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
5042 ALC882_FIXUP_ACER_ASPIRE_8930G),
5043 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
5044 ALC882_FIXUP_ACER_ASPIRE_8930G),
5045 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
5046 ALC882_FIXUP_ACER_ASPIRE_4930G),
5047 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
5048 ALC882_FIXUP_ACER_ASPIRE_4930G),
5049 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
5050 ALC882_FIXUP_ACER_ASPIRE_4930G),
5051 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
5052 SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE),
5053 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
5054 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
5055 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
5056 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
5057 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
5058 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
5060 /* All Apple entries are in codec SSIDs */
5061 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
5062 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
5063 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
5064 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
5065 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
5067 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
5068 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
5069 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
5070 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
5071 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
5072 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
5073 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
5078 * BIOS auto configuration
5080 /* almost identical with ALC880 parser... */
5081 static int alc882_parse_auto_config(struct hda_codec *codec)
5083 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
5084 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5085 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
5090 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
5091 #include "alc882_quirks.c"
5094 static int patch_alc882(struct hda_codec *codec)
5096 struct alc_spec *spec;
5097 int err, board_config;
5099 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5105 spec->mixer_nid = 0x0b;
5107 switch (codec->vendor_id) {
5112 /* ALC883 and variants */
5113 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5117 err = alc_codec_rename_from_preset(codec);
5121 board_config = alc_board_config(codec, ALC882_MODEL_LAST,
5122 alc882_models, NULL);
5123 if (board_config < 0)
5124 board_config = alc_board_codec_sid_config(codec,
5125 ALC882_MODEL_LAST, alc882_models, alc882_ssid_cfg_tbl);
5127 if (board_config < 0) {
5128 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5130 board_config = ALC_MODEL_AUTO;
5133 if (board_config == ALC_MODEL_AUTO) {
5134 alc_pick_fixup(codec, NULL, alc882_fixup_tbl, alc882_fixups);
5135 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5138 alc_auto_parse_customize_define(codec);
5140 if (board_config == ALC_MODEL_AUTO) {
5141 /* automatic parse from the BIOS config */
5142 err = alc882_parse_auto_config(codec);
5147 if (board_config != ALC_MODEL_AUTO) {
5148 setup_preset(codec, &alc882_presets[board_config]);
5149 spec->vmaster_nid = 0x0c;
5152 if (!spec->no_analog && !spec->adc_nids) {
5153 alc_auto_fill_adc_caps(codec);
5154 alc_rebuild_imux_for_auto_mic(codec);
5155 alc_remove_invalid_adc_nids(codec);
5158 if (!spec->no_analog && !spec->cap_mixer)
5159 set_capture_mixer(codec);
5161 if (!spec->no_analog && has_cdefine_beep(codec)) {
5162 err = snd_hda_attach_beep_device(codec, 0x1);
5165 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5168 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5170 codec->patch_ops = alc_patch_ops;
5171 if (board_config == ALC_MODEL_AUTO)
5172 spec->init_hook = alc_auto_init_std;
5174 codec->patch_ops.build_controls = __alc_build_controls;
5176 #ifdef CONFIG_SND_HDA_POWER_SAVE
5177 if (!spec->loopback.amplist)
5178 spec->loopback.amplist = alc882_loopbacks;
5192 static int alc262_parse_auto_config(struct hda_codec *codec)
5194 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
5195 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5196 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
5203 ALC262_FIXUP_FSC_H270,
5204 ALC262_FIXUP_HP_Z200,
5206 ALC262_FIXUP_LENOVO_3000,
5208 ALC262_FIXUP_BENQ_T31,
5211 static const struct alc_fixup alc262_fixups[] = {
5212 [ALC262_FIXUP_FSC_H270] = {
5213 .type = ALC_FIXUP_PINS,
5214 .v.pins = (const struct alc_pincfg[]) {
5215 { 0x14, 0x99130110 }, /* speaker */
5216 { 0x15, 0x0221142f }, /* front HP */
5217 { 0x1b, 0x0121141f }, /* rear HP */
5221 [ALC262_FIXUP_HP_Z200] = {
5222 .type = ALC_FIXUP_PINS,
5223 .v.pins = (const struct alc_pincfg[]) {
5224 { 0x16, 0x99130120 }, /* internal speaker */
5228 [ALC262_FIXUP_TYAN] = {
5229 .type = ALC_FIXUP_PINS,
5230 .v.pins = (const struct alc_pincfg[]) {
5231 { 0x14, 0x1993e1f0 }, /* int AUX */
5235 [ALC262_FIXUP_LENOVO_3000] = {
5236 .type = ALC_FIXUP_VERBS,
5237 .v.verbs = (const struct hda_verb[]) {
5238 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
5242 .chain_id = ALC262_FIXUP_BENQ,
5244 [ALC262_FIXUP_BENQ] = {
5245 .type = ALC_FIXUP_VERBS,
5246 .v.verbs = (const struct hda_verb[]) {
5247 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5248 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5252 [ALC262_FIXUP_BENQ_T31] = {
5253 .type = ALC_FIXUP_VERBS,
5254 .v.verbs = (const struct hda_verb[]) {
5255 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5256 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5262 static const struct snd_pci_quirk alc262_fixup_tbl[] = {
5263 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
5264 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
5265 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
5266 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
5267 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
5268 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
5269 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
5270 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
5275 #ifdef CONFIG_SND_HDA_POWER_SAVE
5276 #define alc262_loopbacks alc880_loopbacks
5281 static int patch_alc262(struct hda_codec *codec)
5283 struct alc_spec *spec;
5286 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5292 spec->mixer_nid = 0x0b;
5295 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
5300 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5301 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
5302 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5303 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
5306 alc_auto_parse_customize_define(codec);
5308 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5310 alc_pick_fixup(codec, NULL, alc262_fixup_tbl, alc262_fixups);
5311 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5313 /* automatic parse from the BIOS config */
5314 err = alc262_parse_auto_config(codec);
5318 if (!spec->no_analog && !spec->adc_nids) {
5319 alc_auto_fill_adc_caps(codec);
5320 alc_rebuild_imux_for_auto_mic(codec);
5321 alc_remove_invalid_adc_nids(codec);
5324 if (!spec->no_analog && !spec->cap_mixer)
5325 set_capture_mixer(codec);
5327 if (!spec->no_analog && has_cdefine_beep(codec)) {
5328 err = snd_hda_attach_beep_device(codec, 0x1);
5331 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5334 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5336 codec->patch_ops = alc_patch_ops;
5337 spec->init_hook = alc_auto_init_std;
5338 spec->shutup = alc_eapd_shutup;
5340 #ifdef CONFIG_SND_HDA_POWER_SAVE
5341 if (!spec->loopback.amplist)
5342 spec->loopback.amplist = alc262_loopbacks;
5355 /* bind Beep switches of both NID 0x0f and 0x10 */
5356 static const struct hda_bind_ctls alc268_bind_beep_sw = {
5357 .ops = &snd_hda_bind_sw,
5359 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
5360 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
5365 static const struct snd_kcontrol_new alc268_beep_mixer[] = {
5366 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
5367 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
5371 /* set PCBEEP vol = 0, mute connections */
5372 static const struct hda_verb alc268_beep_init_verbs[] = {
5373 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5374 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5375 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5380 * BIOS auto configuration
5382 static int alc268_parse_auto_config(struct hda_codec *codec)
5384 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5385 struct alc_spec *spec = codec->spec;
5386 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
5388 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
5389 add_mixer(spec, alc268_beep_mixer);
5390 add_verb(spec, alc268_beep_init_verbs);
5398 static int patch_alc268(struct hda_codec *codec)
5400 struct alc_spec *spec;
5401 int i, has_beep, err;
5403 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5409 /* ALC268 has no aa-loopback mixer */
5411 /* automatic parse from the BIOS config */
5412 err = alc268_parse_auto_config(codec);
5417 for (i = 0; i < spec->num_mixers; i++) {
5418 if (spec->mixers[i] == alc268_beep_mixer) {
5425 err = snd_hda_attach_beep_device(codec, 0x1);
5428 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
5429 /* override the amp caps for beep generator */
5430 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
5431 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
5432 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
5433 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5434 (0 << AC_AMPCAP_MUTE_SHIFT));
5437 if (!spec->no_analog && !spec->adc_nids) {
5438 alc_auto_fill_adc_caps(codec);
5439 alc_rebuild_imux_for_auto_mic(codec);
5440 alc_remove_invalid_adc_nids(codec);
5443 if (!spec->no_analog && !spec->cap_mixer)
5444 set_capture_mixer(codec);
5446 codec->patch_ops = alc_patch_ops;
5447 spec->init_hook = alc_auto_init_std;
5448 spec->shutup = alc_eapd_shutup;
5460 #ifdef CONFIG_SND_HDA_POWER_SAVE
5461 #define alc269_loopbacks alc880_loopbacks
5464 static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
5468 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5469 /* NID is set in alc_build_pcms */
5471 .open = alc_playback_pcm_open,
5472 .prepare = alc_playback_pcm_prepare,
5473 .cleanup = alc_playback_pcm_cleanup
5477 static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
5481 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5482 /* NID is set in alc_build_pcms */
5485 #ifdef CONFIG_SND_HDA_POWER_SAVE
5486 static int alc269_mic2_for_mute_led(struct hda_codec *codec)
5488 switch (codec->subsystem_id) {
5495 static int alc269_mic2_mute_check_ps(struct hda_codec *codec, hda_nid_t nid)
5497 /* update mute-LED according to the speaker mute state */
5498 if (nid == 0x01 || nid == 0x14) {
5500 if (snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0) &
5505 /* mic2 vref pin is used for mute LED control */
5506 snd_hda_codec_update_cache(codec, 0x19, 0,
5507 AC_VERB_SET_PIN_WIDGET_CONTROL,
5510 return alc_check_power_status(codec, nid);
5512 #endif /* CONFIG_SND_HDA_POWER_SAVE */
5514 /* different alc269-variants */
5516 ALC269_TYPE_ALC269VA,
5517 ALC269_TYPE_ALC269VB,
5518 ALC269_TYPE_ALC269VC,
5522 * BIOS auto configuration
5524 static int alc269_parse_auto_config(struct hda_codec *codec)
5526 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
5527 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
5528 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5529 struct alc_spec *spec = codec->spec;
5530 const hda_nid_t *ssids = spec->codec_variant == ALC269_TYPE_ALC269VA ?
5531 alc269va_ssids : alc269_ssids;
5533 return alc_parse_auto_config(codec, alc269_ignore, ssids);
5536 static void alc269_toggle_power_output(struct hda_codec *codec, int power_up)
5538 int val = alc_read_coef_idx(codec, 0x04);
5543 alc_write_coef_idx(codec, 0x04, val);
5546 static void alc269_shutup(struct hda_codec *codec)
5548 if ((alc_get_coef0(codec) & 0x00ff) == 0x017)
5549 alc269_toggle_power_output(codec, 0);
5550 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
5551 alc269_toggle_power_output(codec, 0);
5557 static int alc269_resume(struct hda_codec *codec)
5559 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
5560 alc269_toggle_power_output(codec, 0);
5564 codec->patch_ops.init(codec);
5566 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
5567 alc269_toggle_power_output(codec, 1);
5571 if ((alc_get_coef0(codec) & 0x00ff) == 0x018)
5572 alc269_toggle_power_output(codec, 1);
5574 snd_hda_codec_resume_amp(codec);
5575 snd_hda_codec_resume_cache(codec);
5576 hda_call_check_power_status(codec, 0x01);
5579 #endif /* CONFIG_PM */
5581 static void alc269_fixup_hweq(struct hda_codec *codec,
5582 const struct alc_fixup *fix, int action)
5586 if (action != ALC_FIXUP_ACT_INIT)
5588 coef = alc_read_coef_idx(codec, 0x1e);
5589 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
5592 static void alc271_fixup_dmic(struct hda_codec *codec,
5593 const struct alc_fixup *fix, int action)
5595 static const struct hda_verb verbs[] = {
5596 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
5597 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
5602 if (strcmp(codec->chip_name, "ALC271X"))
5604 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
5605 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
5606 snd_hda_sequence_write(codec, verbs);
5609 static void alc269_fixup_pcm_44k(struct hda_codec *codec,
5610 const struct alc_fixup *fix, int action)
5612 struct alc_spec *spec = codec->spec;
5614 if (action != ALC_FIXUP_ACT_PROBE)
5617 /* Due to a hardware problem on Lenovo Ideadpad, we need to
5618 * fix the sample rate of analog I/O to 44.1kHz
5620 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
5621 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
5624 static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
5625 const struct alc_fixup *fix, int action)
5629 if (action != ALC_FIXUP_ACT_INIT)
5631 /* The digital-mic unit sends PDM (differential signal) instead of
5632 * the standard PCM, thus you can't record a valid mono stream as is.
5633 * Below is a workaround specific to ALC269 to control the dmic
5634 * signal source as mono.
5636 coef = alc_read_coef_idx(codec, 0x07);
5637 alc_write_coef_idx(codec, 0x07, coef | 0x80);
5640 static void alc269_quanta_automute(struct hda_codec *codec)
5642 update_outputs(codec);
5644 snd_hda_codec_write(codec, 0x20, 0,
5645 AC_VERB_SET_COEF_INDEX, 0x0c);
5646 snd_hda_codec_write(codec, 0x20, 0,
5647 AC_VERB_SET_PROC_COEF, 0x680);
5649 snd_hda_codec_write(codec, 0x20, 0,
5650 AC_VERB_SET_COEF_INDEX, 0x0c);
5651 snd_hda_codec_write(codec, 0x20, 0,
5652 AC_VERB_SET_PROC_COEF, 0x480);
5655 static void alc269_fixup_quanta_mute(struct hda_codec *codec,
5656 const struct alc_fixup *fix, int action)
5658 struct alc_spec *spec = codec->spec;
5659 if (action != ALC_FIXUP_ACT_PROBE)
5661 spec->automute_hook = alc269_quanta_automute;
5665 ALC269_FIXUP_SONY_VAIO,
5666 ALC275_FIXUP_SONY_VAIO_GPIO2,
5667 ALC269_FIXUP_DELL_M101Z,
5668 ALC269_FIXUP_SKU_IGNORE,
5669 ALC269_FIXUP_ASUS_G73JW,
5670 ALC269_FIXUP_LENOVO_EAPD,
5671 ALC275_FIXUP_SONY_HWEQ,
5673 ALC269_FIXUP_PCM_44K,
5674 ALC269_FIXUP_STEREO_DMIC,
5675 ALC269_FIXUP_QUANTA_MUTE,
5676 ALC269_FIXUP_LIFEBOOK,
5679 ALC269VB_FIXUP_AMIC,
5680 ALC269VB_FIXUP_DMIC,
5683 static const struct alc_fixup alc269_fixups[] = {
5684 [ALC269_FIXUP_SONY_VAIO] = {
5685 .type = ALC_FIXUP_VERBS,
5686 .v.verbs = (const struct hda_verb[]) {
5687 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
5691 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
5692 .type = ALC_FIXUP_VERBS,
5693 .v.verbs = (const struct hda_verb[]) {
5694 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
5695 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
5696 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5700 .chain_id = ALC269_FIXUP_SONY_VAIO
5702 [ALC269_FIXUP_DELL_M101Z] = {
5703 .type = ALC_FIXUP_VERBS,
5704 .v.verbs = (const struct hda_verb[]) {
5705 /* Enables internal speaker */
5706 {0x20, AC_VERB_SET_COEF_INDEX, 13},
5707 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
5711 [ALC269_FIXUP_SKU_IGNORE] = {
5712 .type = ALC_FIXUP_SKU,
5713 .v.sku = ALC_FIXUP_SKU_IGNORE,
5715 [ALC269_FIXUP_ASUS_G73JW] = {
5716 .type = ALC_FIXUP_PINS,
5717 .v.pins = (const struct alc_pincfg[]) {
5718 { 0x17, 0x99130111 }, /* subwoofer */
5722 [ALC269_FIXUP_LENOVO_EAPD] = {
5723 .type = ALC_FIXUP_VERBS,
5724 .v.verbs = (const struct hda_verb[]) {
5725 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
5729 [ALC275_FIXUP_SONY_HWEQ] = {
5730 .type = ALC_FIXUP_FUNC,
5731 .v.func = alc269_fixup_hweq,
5733 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
5735 [ALC271_FIXUP_DMIC] = {
5736 .type = ALC_FIXUP_FUNC,
5737 .v.func = alc271_fixup_dmic,
5739 [ALC269_FIXUP_PCM_44K] = {
5740 .type = ALC_FIXUP_FUNC,
5741 .v.func = alc269_fixup_pcm_44k,
5743 [ALC269_FIXUP_STEREO_DMIC] = {
5744 .type = ALC_FIXUP_FUNC,
5745 .v.func = alc269_fixup_stereo_dmic,
5747 [ALC269_FIXUP_QUANTA_MUTE] = {
5748 .type = ALC_FIXUP_FUNC,
5749 .v.func = alc269_fixup_quanta_mute,
5751 [ALC269_FIXUP_LIFEBOOK] = {
5752 .type = ALC_FIXUP_PINS,
5753 .v.pins = (const struct alc_pincfg[]) {
5754 { 0x1a, 0x2101103f }, /* dock line-out */
5755 { 0x1b, 0x23a11040 }, /* dock mic-in */
5759 .chain_id = ALC269_FIXUP_QUANTA_MUTE
5761 [ALC269_FIXUP_AMIC] = {
5762 .type = ALC_FIXUP_PINS,
5763 .v.pins = (const struct alc_pincfg[]) {
5764 { 0x14, 0x99130110 }, /* speaker */
5765 { 0x15, 0x0121401f }, /* HP out */
5766 { 0x18, 0x01a19c20 }, /* mic */
5767 { 0x19, 0x99a3092f }, /* int-mic */
5771 [ALC269_FIXUP_DMIC] = {
5772 .type = ALC_FIXUP_PINS,
5773 .v.pins = (const struct alc_pincfg[]) {
5774 { 0x12, 0x99a3092f }, /* int-mic */
5775 { 0x14, 0x99130110 }, /* speaker */
5776 { 0x15, 0x0121401f }, /* HP out */
5777 { 0x18, 0x01a19c20 }, /* mic */
5781 [ALC269VB_FIXUP_AMIC] = {
5782 .type = ALC_FIXUP_PINS,
5783 .v.pins = (const struct alc_pincfg[]) {
5784 { 0x14, 0x99130110 }, /* speaker */
5785 { 0x18, 0x01a19c20 }, /* mic */
5786 { 0x19, 0x99a3092f }, /* int-mic */
5787 { 0x21, 0x0121401f }, /* HP out */
5791 [ALC269VB_FIXUP_DMIC] = {
5792 .type = ALC_FIXUP_PINS,
5793 .v.pins = (const struct alc_pincfg[]) {
5794 { 0x12, 0x99a3092f }, /* int-mic */
5795 { 0x14, 0x99130110 }, /* speaker */
5796 { 0x18, 0x01a19c20 }, /* mic */
5797 { 0x21, 0x0121401f }, /* HP out */
5803 static const struct snd_pci_quirk alc269_fixup_tbl[] = {
5804 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
5805 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
5806 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
5807 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
5808 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
5809 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
5810 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
5811 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
5812 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
5813 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
5814 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
5815 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
5816 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
5817 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
5818 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
5819 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
5820 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
5821 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
5822 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_QUANTA_MUTE),
5823 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K),
5824 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
5827 /* Below is a quirk table taken from the old code.
5828 * Basically the device should work as is without the fixup table.
5829 * If BIOS doesn't give a proper info, enable the corresponding
5832 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
5834 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
5835 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
5836 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
5837 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
5838 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
5839 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
5840 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
5841 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
5842 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
5843 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
5844 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
5845 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
5846 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
5847 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
5848 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
5849 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
5850 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
5851 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
5852 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
5853 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
5854 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
5855 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
5856 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
5857 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
5858 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
5859 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
5860 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
5861 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
5862 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
5863 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
5864 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
5865 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
5866 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
5867 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
5868 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
5869 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
5870 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
5871 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
5872 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
5877 static const struct alc_model_fixup alc269_fixup_models[] = {
5878 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
5879 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
5884 static int alc269_fill_coef(struct hda_codec *codec)
5888 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
5889 alc_write_coef_idx(codec, 0xf, 0x960b);
5890 alc_write_coef_idx(codec, 0xe, 0x8817);
5893 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
5894 alc_write_coef_idx(codec, 0xf, 0x960b);
5895 alc_write_coef_idx(codec, 0xe, 0x8814);
5898 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
5899 val = alc_read_coef_idx(codec, 0x04);
5900 /* Power up output pin */
5901 alc_write_coef_idx(codec, 0x04, val | (1<<11));
5904 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
5905 val = alc_read_coef_idx(codec, 0xd);
5906 if ((val & 0x0c00) >> 10 != 0x1) {
5907 /* Capless ramp up clock control */
5908 alc_write_coef_idx(codec, 0xd, val | (1<<10));
5910 val = alc_read_coef_idx(codec, 0x17);
5911 if ((val & 0x01c0) >> 6 != 0x4) {
5912 /* Class D power on reset */
5913 alc_write_coef_idx(codec, 0x17, val | (1<<7));
5917 val = alc_read_coef_idx(codec, 0xd); /* Class D */
5918 alc_write_coef_idx(codec, 0xd, val | (1<<14));
5920 val = alc_read_coef_idx(codec, 0x4); /* HP */
5921 alc_write_coef_idx(codec, 0x4, val | (1<<11));
5928 static int patch_alc269(struct hda_codec *codec)
5930 struct alc_spec *spec;
5933 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5939 spec->mixer_nid = 0x0b;
5941 alc_auto_parse_customize_define(codec);
5943 err = alc_codec_rename_from_preset(codec);
5947 if (codec->vendor_id == 0x10ec0269) {
5948 spec->codec_variant = ALC269_TYPE_ALC269VA;
5949 switch (alc_get_coef0(codec) & 0x00f0) {
5951 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
5952 spec->cdefine.platform_type == 1)
5953 err = alc_codec_rename(codec, "ALC271X");
5954 spec->codec_variant = ALC269_TYPE_ALC269VB;
5957 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
5958 codec->bus->pci->subsystem_device == 0x21f3)
5959 err = alc_codec_rename(codec, "ALC3202");
5960 spec->codec_variant = ALC269_TYPE_ALC269VC;
5963 alc_fix_pll_init(codec, 0x20, 0x04, 15);
5967 alc269_fill_coef(codec);
5970 alc_pick_fixup(codec, alc269_fixup_models,
5971 alc269_fixup_tbl, alc269_fixups);
5972 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5974 /* automatic parse from the BIOS config */
5975 err = alc269_parse_auto_config(codec);
5979 if (!spec->no_analog && !spec->adc_nids) {
5980 alc_auto_fill_adc_caps(codec);
5981 alc_rebuild_imux_for_auto_mic(codec);
5982 alc_remove_invalid_adc_nids(codec);
5985 if (!spec->no_analog && !spec->cap_mixer)
5986 set_capture_mixer(codec);
5988 if (!spec->no_analog && has_cdefine_beep(codec)) {
5989 err = snd_hda_attach_beep_device(codec, 0x1);
5992 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
5995 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5997 codec->patch_ops = alc_patch_ops;
5999 codec->patch_ops.resume = alc269_resume;
6001 spec->init_hook = alc_auto_init_std;
6002 spec->shutup = alc269_shutup;
6004 #ifdef CONFIG_SND_HDA_POWER_SAVE
6005 if (!spec->loopback.amplist)
6006 spec->loopback.amplist = alc269_loopbacks;
6007 if (alc269_mic2_for_mute_led(codec))
6008 codec->patch_ops.check_power_status = alc269_mic2_mute_check_ps;
6022 static int alc861_parse_auto_config(struct hda_codec *codec)
6024 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
6025 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
6026 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
6029 #ifdef CONFIG_SND_HDA_POWER_SAVE
6030 static const struct hda_amp_list alc861_loopbacks[] = {
6031 { 0x15, HDA_INPUT, 0 },
6032 { 0x15, HDA_INPUT, 1 },
6033 { 0x15, HDA_INPUT, 2 },
6034 { 0x15, HDA_INPUT, 3 },
6040 /* Pin config fixes */
6042 ALC861_FIXUP_FSC_AMILO_PI1505,
6043 ALC861_FIXUP_AMP_VREF_0F,
6044 ALC861_FIXUP_NO_JACK_DETECT,
6045 ALC861_FIXUP_ASUS_A6RP,
6048 /* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
6049 static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
6050 const struct alc_fixup *fix, int action)
6052 struct alc_spec *spec = codec->spec;
6055 if (action != ALC_FIXUP_ACT_INIT)
6057 val = snd_hda_codec_read(codec, 0x0f, 0,
6058 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
6059 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
6060 val |= AC_PINCTL_IN_EN;
6061 val |= AC_PINCTL_VREF_50;
6062 snd_hda_codec_write(codec, 0x0f, 0,
6063 AC_VERB_SET_PIN_WIDGET_CONTROL, val);
6064 spec->keep_vref_in_automute = 1;
6067 /* suppress the jack-detection */
6068 static void alc_fixup_no_jack_detect(struct hda_codec *codec,
6069 const struct alc_fixup *fix, int action)
6071 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6072 codec->no_jack_detect = 1;
6075 static const struct alc_fixup alc861_fixups[] = {
6076 [ALC861_FIXUP_FSC_AMILO_PI1505] = {
6077 .type = ALC_FIXUP_PINS,
6078 .v.pins = (const struct alc_pincfg[]) {
6079 { 0x0b, 0x0221101f }, /* HP */
6080 { 0x0f, 0x90170310 }, /* speaker */
6084 [ALC861_FIXUP_AMP_VREF_0F] = {
6085 .type = ALC_FIXUP_FUNC,
6086 .v.func = alc861_fixup_asus_amp_vref_0f,
6088 [ALC861_FIXUP_NO_JACK_DETECT] = {
6089 .type = ALC_FIXUP_FUNC,
6090 .v.func = alc_fixup_no_jack_detect,
6092 [ALC861_FIXUP_ASUS_A6RP] = {
6093 .type = ALC_FIXUP_FUNC,
6094 .v.func = alc861_fixup_asus_amp_vref_0f,
6096 .chain_id = ALC861_FIXUP_NO_JACK_DETECT,
6100 static const struct snd_pci_quirk alc861_fixup_tbl[] = {
6101 SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP),
6102 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", ALC861_FIXUP_AMP_VREF_0F),
6103 SND_PCI_QUIRK(0x1462, 0x7254, "HP DX2200", ALC861_FIXUP_NO_JACK_DETECT),
6104 SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", ALC861_FIXUP_AMP_VREF_0F),
6105 SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", ALC861_FIXUP_AMP_VREF_0F),
6106 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", ALC861_FIXUP_FSC_AMILO_PI1505),
6112 static int patch_alc861(struct hda_codec *codec)
6114 struct alc_spec *spec;
6117 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6123 spec->mixer_nid = 0x15;
6125 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
6126 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6128 /* automatic parse from the BIOS config */
6129 err = alc861_parse_auto_config(codec);
6133 if (!spec->no_analog && !spec->adc_nids) {
6134 alc_auto_fill_adc_caps(codec);
6135 alc_rebuild_imux_for_auto_mic(codec);
6136 alc_remove_invalid_adc_nids(codec);
6139 if (!spec->no_analog && !spec->cap_mixer)
6140 set_capture_mixer(codec);
6142 if (!spec->no_analog) {
6143 err = snd_hda_attach_beep_device(codec, 0x23);
6146 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
6149 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6151 codec->patch_ops = alc_patch_ops;
6152 spec->init_hook = alc_auto_init_std;
6153 #ifdef CONFIG_SND_HDA_POWER_SAVE
6154 spec->power_hook = alc_power_eapd;
6155 if (!spec->loopback.amplist)
6156 spec->loopback.amplist = alc861_loopbacks;
6171 * In addition, an independent DAC
6173 #ifdef CONFIG_SND_HDA_POWER_SAVE
6174 #define alc861vd_loopbacks alc880_loopbacks
6177 static int alc861vd_parse_auto_config(struct hda_codec *codec)
6179 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
6180 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6181 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
6185 ALC660VD_FIX_ASUS_GPIO1,
6186 ALC861VD_FIX_DALLAS,
6189 /* exclude VREF80 */
6190 static void alc861vd_fixup_dallas(struct hda_codec *codec,
6191 const struct alc_fixup *fix, int action)
6193 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
6194 snd_hda_override_pin_caps(codec, 0x18, 0x00001714);
6195 snd_hda_override_pin_caps(codec, 0x19, 0x0000171c);
6199 static const struct alc_fixup alc861vd_fixups[] = {
6200 [ALC660VD_FIX_ASUS_GPIO1] = {
6201 .type = ALC_FIXUP_VERBS,
6202 .v.verbs = (const struct hda_verb[]) {
6204 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6205 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
6206 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
6210 [ALC861VD_FIX_DALLAS] = {
6211 .type = ALC_FIXUP_FUNC,
6212 .v.func = alc861vd_fixup_dallas,
6216 static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
6217 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
6218 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
6219 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
6223 static const struct hda_verb alc660vd_eapd_verbs[] = {
6224 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
6225 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
6231 static int patch_alc861vd(struct hda_codec *codec)
6233 struct alc_spec *spec;
6236 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6242 spec->mixer_nid = 0x0b;
6244 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
6245 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6247 /* automatic parse from the BIOS config */
6248 err = alc861vd_parse_auto_config(codec);
6252 if (codec->vendor_id == 0x10ec0660) {
6253 /* always turn on EAPD */
6254 add_verb(spec, alc660vd_eapd_verbs);
6257 if (!spec->no_analog && !spec->adc_nids) {
6258 alc_auto_fill_adc_caps(codec);
6259 alc_rebuild_imux_for_auto_mic(codec);
6260 alc_remove_invalid_adc_nids(codec);
6263 if (!spec->no_analog && !spec->cap_mixer)
6264 set_capture_mixer(codec);
6266 if (!spec->no_analog) {
6267 err = snd_hda_attach_beep_device(codec, 0x23);
6270 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6273 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6275 codec->patch_ops = alc_patch_ops;
6277 spec->init_hook = alc_auto_init_std;
6278 spec->shutup = alc_eapd_shutup;
6279 #ifdef CONFIG_SND_HDA_POWER_SAVE
6280 if (!spec->loopback.amplist)
6281 spec->loopback.amplist = alc861vd_loopbacks;
6294 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
6295 * configuration. Each pin widget can choose any input DACs and a mixer.
6296 * Each ADC is connected from a mixer of all inputs. This makes possible
6297 * 6-channel independent captures.
6299 * In addition, an independent DAC for the multi-playback (not used in this
6302 #ifdef CONFIG_SND_HDA_POWER_SAVE
6303 #define alc662_loopbacks alc880_loopbacks
6307 * BIOS auto configuration
6310 static int alc662_parse_auto_config(struct hda_codec *codec)
6312 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
6313 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
6314 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6315 const hda_nid_t *ssids;
6317 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
6318 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
6319 ssids = alc663_ssids;
6321 ssids = alc662_ssids;
6322 return alc_parse_auto_config(codec, alc662_ignore, ssids);
6325 static void alc272_fixup_mario(struct hda_codec *codec,
6326 const struct alc_fixup *fix, int action)
6328 if (action != ALC_FIXUP_ACT_PROBE)
6330 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
6331 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
6332 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
6333 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6334 (0 << AC_AMPCAP_MUTE_SHIFT)))
6336 "hda_codec: failed to override amp caps for NID 0x2\n");
6340 ALC662_FIXUP_ASPIRE,
6341 ALC662_FIXUP_IDEAPAD,
6343 ALC662_FIXUP_CZC_P10T,
6344 ALC662_FIXUP_SKU_IGNORE,
6345 ALC662_FIXUP_HP_RP5800,
6346 ALC662_FIXUP_ASUS_MODE1,
6347 ALC662_FIXUP_ASUS_MODE2,
6348 ALC662_FIXUP_ASUS_MODE3,
6349 ALC662_FIXUP_ASUS_MODE4,
6350 ALC662_FIXUP_ASUS_MODE5,
6351 ALC662_FIXUP_ASUS_MODE6,
6352 ALC662_FIXUP_ASUS_MODE7,
6353 ALC662_FIXUP_ASUS_MODE8,
6354 ALC662_FIXUP_NO_JACK_DETECT,
6357 static const struct alc_fixup alc662_fixups[] = {
6358 [ALC662_FIXUP_ASPIRE] = {
6359 .type = ALC_FIXUP_PINS,
6360 .v.pins = (const struct alc_pincfg[]) {
6361 { 0x15, 0x99130112 }, /* subwoofer */
6365 [ALC662_FIXUP_IDEAPAD] = {
6366 .type = ALC_FIXUP_PINS,
6367 .v.pins = (const struct alc_pincfg[]) {
6368 { 0x17, 0x99130112 }, /* subwoofer */
6372 [ALC272_FIXUP_MARIO] = {
6373 .type = ALC_FIXUP_FUNC,
6374 .v.func = alc272_fixup_mario,
6376 [ALC662_FIXUP_CZC_P10T] = {
6377 .type = ALC_FIXUP_VERBS,
6378 .v.verbs = (const struct hda_verb[]) {
6379 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6383 [ALC662_FIXUP_SKU_IGNORE] = {
6384 .type = ALC_FIXUP_SKU,
6385 .v.sku = ALC_FIXUP_SKU_IGNORE,
6387 [ALC662_FIXUP_HP_RP5800] = {
6388 .type = ALC_FIXUP_PINS,
6389 .v.pins = (const struct alc_pincfg[]) {
6390 { 0x14, 0x0221201f }, /* HP out */
6394 .chain_id = ALC662_FIXUP_SKU_IGNORE
6396 [ALC662_FIXUP_ASUS_MODE1] = {
6397 .type = ALC_FIXUP_PINS,
6398 .v.pins = (const struct alc_pincfg[]) {
6399 { 0x14, 0x99130110 }, /* speaker */
6400 { 0x18, 0x01a19c20 }, /* mic */
6401 { 0x19, 0x99a3092f }, /* int-mic */
6402 { 0x21, 0x0121401f }, /* HP out */
6406 .chain_id = ALC662_FIXUP_SKU_IGNORE
6408 [ALC662_FIXUP_ASUS_MODE2] = {
6409 .type = ALC_FIXUP_PINS,
6410 .v.pins = (const struct alc_pincfg[]) {
6411 { 0x14, 0x99130110 }, /* speaker */
6412 { 0x18, 0x01a19820 }, /* mic */
6413 { 0x19, 0x99a3092f }, /* int-mic */
6414 { 0x1b, 0x0121401f }, /* HP out */
6418 .chain_id = ALC662_FIXUP_SKU_IGNORE
6420 [ALC662_FIXUP_ASUS_MODE3] = {
6421 .type = ALC_FIXUP_PINS,
6422 .v.pins = (const struct alc_pincfg[]) {
6423 { 0x14, 0x99130110 }, /* speaker */
6424 { 0x15, 0x0121441f }, /* HP */
6425 { 0x18, 0x01a19840 }, /* mic */
6426 { 0x19, 0x99a3094f }, /* int-mic */
6427 { 0x21, 0x01211420 }, /* HP2 */
6431 .chain_id = ALC662_FIXUP_SKU_IGNORE
6433 [ALC662_FIXUP_ASUS_MODE4] = {
6434 .type = ALC_FIXUP_PINS,
6435 .v.pins = (const struct alc_pincfg[]) {
6436 { 0x14, 0x99130110 }, /* speaker */
6437 { 0x16, 0x99130111 }, /* speaker */
6438 { 0x18, 0x01a19840 }, /* mic */
6439 { 0x19, 0x99a3094f }, /* int-mic */
6440 { 0x21, 0x0121441f }, /* HP */
6444 .chain_id = ALC662_FIXUP_SKU_IGNORE
6446 [ALC662_FIXUP_ASUS_MODE5] = {
6447 .type = ALC_FIXUP_PINS,
6448 .v.pins = (const struct alc_pincfg[]) {
6449 { 0x14, 0x99130110 }, /* speaker */
6450 { 0x15, 0x0121441f }, /* HP */
6451 { 0x16, 0x99130111 }, /* speaker */
6452 { 0x18, 0x01a19840 }, /* mic */
6453 { 0x19, 0x99a3094f }, /* int-mic */
6457 .chain_id = ALC662_FIXUP_SKU_IGNORE
6459 [ALC662_FIXUP_ASUS_MODE6] = {
6460 .type = ALC_FIXUP_PINS,
6461 .v.pins = (const struct alc_pincfg[]) {
6462 { 0x14, 0x99130110 }, /* speaker */
6463 { 0x15, 0x01211420 }, /* HP2 */
6464 { 0x18, 0x01a19840 }, /* mic */
6465 { 0x19, 0x99a3094f }, /* int-mic */
6466 { 0x1b, 0x0121441f }, /* HP */
6470 .chain_id = ALC662_FIXUP_SKU_IGNORE
6472 [ALC662_FIXUP_ASUS_MODE7] = {
6473 .type = ALC_FIXUP_PINS,
6474 .v.pins = (const struct alc_pincfg[]) {
6475 { 0x14, 0x99130110 }, /* speaker */
6476 { 0x17, 0x99130111 }, /* speaker */
6477 { 0x18, 0x01a19840 }, /* mic */
6478 { 0x19, 0x99a3094f }, /* int-mic */
6479 { 0x1b, 0x01214020 }, /* HP */
6480 { 0x21, 0x0121401f }, /* HP */
6484 .chain_id = ALC662_FIXUP_SKU_IGNORE
6486 [ALC662_FIXUP_ASUS_MODE8] = {
6487 .type = ALC_FIXUP_PINS,
6488 .v.pins = (const struct alc_pincfg[]) {
6489 { 0x14, 0x99130110 }, /* speaker */
6490 { 0x12, 0x99a30970 }, /* int-mic */
6491 { 0x15, 0x01214020 }, /* HP */
6492 { 0x17, 0x99130111 }, /* speaker */
6493 { 0x18, 0x01a19840 }, /* mic */
6494 { 0x21, 0x0121401f }, /* HP */
6498 .chain_id = ALC662_FIXUP_SKU_IGNORE
6500 [ALC662_FIXUP_NO_JACK_DETECT] = {
6501 .type = ALC_FIXUP_FUNC,
6502 .v.func = alc_fixup_no_jack_detect,
6506 static const struct snd_pci_quirk alc662_fixup_tbl[] = {
6507 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
6508 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
6509 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
6510 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
6511 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
6512 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT),
6513 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
6514 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
6515 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
6516 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
6517 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
6520 /* Below is a quirk table taken from the old code.
6521 * Basically the device should work as is without the fixup table.
6522 * If BIOS doesn't give a proper info, enable the corresponding
6525 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
6526 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
6527 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
6528 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
6529 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6530 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6531 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6532 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
6533 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
6534 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6535 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
6536 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
6537 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
6538 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
6539 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
6540 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6541 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
6542 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
6543 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6544 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6545 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6546 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6547 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
6548 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
6549 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
6550 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6551 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
6552 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6553 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6554 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
6555 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6556 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6557 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
6558 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
6559 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
6560 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
6561 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
6562 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
6563 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
6564 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6565 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
6566 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
6567 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6568 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
6569 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
6570 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
6571 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
6572 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
6573 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6574 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
6579 static const struct alc_model_fixup alc662_fixup_models[] = {
6580 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
6581 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
6582 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
6583 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
6584 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
6585 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
6586 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
6587 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
6588 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
6595 static int patch_alc662(struct hda_codec *codec)
6597 struct alc_spec *spec;
6600 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6606 spec->mixer_nid = 0x0b;
6608 /* handle multiple HPs as is */
6609 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
6611 alc_auto_parse_customize_define(codec);
6613 alc_fix_pll_init(codec, 0x20, 0x04, 15);
6615 err = alc_codec_rename_from_preset(codec);
6619 if ((alc_get_coef0(codec) & (1 << 14)) &&
6620 codec->bus->pci->subsystem_vendor == 0x1025 &&
6621 spec->cdefine.platform_type == 1) {
6622 if (alc_codec_rename(codec, "ALC272X") < 0)
6626 alc_pick_fixup(codec, alc662_fixup_models,
6627 alc662_fixup_tbl, alc662_fixups);
6628 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6629 /* automatic parse from the BIOS config */
6630 err = alc662_parse_auto_config(codec);
6634 if (!spec->no_analog && !spec->adc_nids) {
6635 alc_auto_fill_adc_caps(codec);
6636 alc_rebuild_imux_for_auto_mic(codec);
6637 alc_remove_invalid_adc_nids(codec);
6640 if (!spec->no_analog && !spec->cap_mixer)
6641 set_capture_mixer(codec);
6643 if (!spec->no_analog && has_cdefine_beep(codec)) {
6644 err = snd_hda_attach_beep_device(codec, 0x1);
6647 switch (codec->vendor_id) {
6649 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6654 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
6657 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
6662 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6664 codec->patch_ops = alc_patch_ops;
6665 spec->init_hook = alc_auto_init_std;
6666 spec->shutup = alc_eapd_shutup;
6668 #ifdef CONFIG_SND_HDA_POWER_SAVE
6669 if (!spec->loopback.amplist)
6670 spec->loopback.amplist = alc662_loopbacks;
6684 static int alc680_parse_auto_config(struct hda_codec *codec)
6686 return alc_parse_auto_config(codec, NULL, NULL);
6691 static int patch_alc680(struct hda_codec *codec)
6693 struct alc_spec *spec;
6696 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6702 /* ALC680 has no aa-loopback mixer */
6704 /* automatic parse from the BIOS config */
6705 err = alc680_parse_auto_config(codec);
6711 if (!spec->no_analog && !spec->cap_mixer)
6712 set_capture_mixer(codec);
6714 codec->patch_ops = alc_patch_ops;
6715 spec->init_hook = alc_auto_init_std;
6723 static const struct hda_codec_preset snd_hda_preset_realtek[] = {
6724 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
6725 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
6726 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
6727 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
6728 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
6729 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
6730 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
6731 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
6732 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
6733 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
6734 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
6735 .patch = patch_alc861 },
6736 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
6737 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
6738 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
6739 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
6740 .patch = patch_alc882 },
6741 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
6742 .patch = patch_alc662 },
6743 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
6744 .patch = patch_alc662 },
6745 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
6746 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
6747 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
6748 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
6749 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
6750 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
6751 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
6752 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
6753 .patch = patch_alc882 },
6754 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
6755 .patch = patch_alc882 },
6756 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
6757 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
6758 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
6759 .patch = patch_alc882 },
6760 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
6761 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
6762 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
6763 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
6767 MODULE_ALIAS("snd-hda-codec-id:10ec*");
6769 MODULE_LICENSE("GPL");
6770 MODULE_DESCRIPTION("Realtek HD-audio codec");
6772 static struct hda_codec_preset_list realtek_list = {
6773 .preset = snd_hda_preset_realtek,
6774 .owner = THIS_MODULE,
6777 static int __init patch_realtek_init(void)
6779 return snd_hda_add_codec_preset(&realtek_list);
6782 static void __exit patch_realtek_exit(void)
6784 snd_hda_delete_codec_preset(&realtek_list);
6787 module_init(patch_realtek_init)
6788 module_exit(patch_realtek_exit)