ALSA: hda - Fix the wrong pincaps set in ALC861VD dallas/hp fixup
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / sound / pci / hda / patch_realtek.c
blob6ee34593774a4d155cd595ab96bbc7318f2dc6d9
1 /*
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@just42.net>
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"
35 #include "hda_auto_parser.h"
36 #include "hda_beep.h"
37 #include "hda_jack.h"
39 /* unsol event tags */
40 #define ALC_FRONT_EVENT 0x01
41 #define ALC_DCVOL_EVENT 0x02
42 #define ALC_HP_EVENT 0x04
43 #define ALC_MIC_EVENT 0x08
45 /* for GPIO Poll */
46 #define GPIO_MASK 0x03
48 /* extra amp-initialization sequence types */
49 enum {
50 ALC_INIT_NONE,
51 ALC_INIT_DEFAULT,
52 ALC_INIT_GPIO1,
53 ALC_INIT_GPIO2,
54 ALC_INIT_GPIO3,
57 struct alc_customize_define {
58 unsigned int sku_cfg;
59 unsigned char port_connectivity;
60 unsigned char check_sum;
61 unsigned char customization;
62 unsigned char external_amp;
63 unsigned int enable_pcbeep:1;
64 unsigned int platform_type:1;
65 unsigned int swap:1;
66 unsigned int override:1;
67 unsigned int fixup:1; /* Means that this sku is set by driver, not read from hw */
70 struct alc_multi_io {
71 hda_nid_t pin; /* multi-io widget pin NID */
72 hda_nid_t dac; /* DAC to be connected */
73 unsigned int ctl_in; /* cached input-pin control value */
76 enum {
77 ALC_AUTOMUTE_PIN, /* change the pin control */
78 ALC_AUTOMUTE_AMP, /* mute/unmute the pin AMP */
79 ALC_AUTOMUTE_MIXER, /* mute/unmute mixer widget AMP */
82 #define MAX_VOL_NIDS 0x40
84 /* make compatible with old code */
85 #define alc_apply_pincfgs snd_hda_apply_pincfgs
86 #define alc_apply_fixup snd_hda_apply_fixup
87 #define alc_pick_fixup snd_hda_pick_fixup
88 #define alc_fixup hda_fixup
89 #define alc_pincfg hda_pintbl
90 #define alc_model_fixup hda_model_fixup
92 #define ALC_FIXUP_PINS HDA_FIXUP_PINS
93 #define ALC_FIXUP_VERBS HDA_FIXUP_VERBS
94 #define ALC_FIXUP_FUNC HDA_FIXUP_FUNC
96 #define ALC_FIXUP_ACT_PRE_PROBE HDA_FIXUP_ACT_PRE_PROBE
97 #define ALC_FIXUP_ACT_PROBE HDA_FIXUP_ACT_PROBE
98 #define ALC_FIXUP_ACT_INIT HDA_FIXUP_ACT_INIT
99 #define ALC_FIXUP_ACT_BUILD HDA_FIXUP_ACT_BUILD
102 struct alc_spec {
103 struct hda_gen_spec gen;
105 /* codec parameterization */
106 const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */
107 unsigned int num_mixers;
108 const struct snd_kcontrol_new *cap_mixer; /* capture mixer */
109 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
111 char stream_name_analog[32]; /* analog PCM stream */
112 const struct hda_pcm_stream *stream_analog_playback;
113 const struct hda_pcm_stream *stream_analog_capture;
114 const struct hda_pcm_stream *stream_analog_alt_playback;
115 const struct hda_pcm_stream *stream_analog_alt_capture;
117 char stream_name_digital[32]; /* digital PCM stream */
118 const struct hda_pcm_stream *stream_digital_playback;
119 const struct hda_pcm_stream *stream_digital_capture;
121 /* playback */
122 struct hda_multi_out multiout; /* playback set-up
123 * max_channels, dacs must be set
124 * dig_out_nid and hp_nid are optional
126 hda_nid_t alt_dac_nid;
127 hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */
128 int dig_out_type;
130 /* capture */
131 unsigned int num_adc_nids;
132 const hda_nid_t *adc_nids;
133 const hda_nid_t *capsrc_nids;
134 hda_nid_t dig_in_nid; /* digital-in NID; optional */
135 hda_nid_t mixer_nid; /* analog-mixer NID */
136 DECLARE_BITMAP(vol_ctls, MAX_VOL_NIDS << 1);
137 DECLARE_BITMAP(sw_ctls, MAX_VOL_NIDS << 1);
139 /* capture setup for dynamic dual-adc switch */
140 hda_nid_t cur_adc;
141 unsigned int cur_adc_stream_tag;
142 unsigned int cur_adc_format;
144 /* capture source */
145 unsigned int num_mux_defs;
146 const struct hda_input_mux *input_mux;
147 unsigned int cur_mux[3];
148 hda_nid_t ext_mic_pin;
149 hda_nid_t dock_mic_pin;
150 hda_nid_t int_mic_pin;
152 /* channel model */
153 const struct hda_channel_mode *channel_mode;
154 int num_channel_mode;
155 int need_dac_fix;
156 int const_channel_count; /* min. channel count (for speakers) */
157 int ext_channel_count; /* current channel count for multi-io */
159 /* PCM information */
160 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
162 /* dynamic controls, init_verbs and input_mux */
163 struct auto_pin_cfg autocfg;
164 struct alc_customize_define cdefine;
165 struct snd_array kctls;
166 struct hda_input_mux private_imux[3];
167 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
168 hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS];
169 hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS];
170 hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS];
171 unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS];
172 int int_mic_idx, ext_mic_idx, dock_mic_idx; /* for auto-mic */
173 hda_nid_t inv_dmic_pin;
175 /* hooks */
176 void (*init_hook)(struct hda_codec *codec);
177 #ifdef CONFIG_PM
178 void (*power_hook)(struct hda_codec *codec);
179 #endif
180 void (*shutup)(struct hda_codec *codec);
181 void (*automute_hook)(struct hda_codec *codec);
183 /* for pin sensing */
184 unsigned int hp_jack_present:1;
185 unsigned int line_jack_present:1;
186 unsigned int master_mute:1;
187 unsigned int auto_mic:1;
188 unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */
189 unsigned int automute_speaker:1; /* automute speaker outputs */
190 unsigned int automute_lo:1; /* automute LO outputs */
191 unsigned int detect_hp:1; /* Headphone detection enabled */
192 unsigned int detect_lo:1; /* Line-out detection enabled */
193 unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */
194 unsigned int automute_lo_possible:1; /* there are line outs and HP */
195 unsigned int keep_vref_in_automute:1; /* Don't clear VREF in automute */
197 /* other flags */
198 unsigned int no_analog :1; /* digital I/O only */
199 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
200 unsigned int single_input_src:1;
201 unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */
202 unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */
203 unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */
204 unsigned int inv_dmic_fixup:1; /* has inverted digital-mic workaround */
205 unsigned int inv_dmic_muted:1; /* R-ch of inv d-mic is muted? */
206 unsigned int no_primary_hp:1; /* Don't prefer HP pins to speaker pins */
208 /* auto-mute control */
209 int automute_mode;
210 hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS];
212 int init_amp;
213 int codec_variant; /* flag for other variants */
215 /* for virtual master */
216 hda_nid_t vmaster_nid;
217 struct hda_vmaster_mute_hook vmaster_mute;
218 #ifdef CONFIG_PM
219 struct hda_loopback_check loopback;
220 int num_loopbacks;
221 struct hda_amp_list loopback_list[8];
222 #endif
224 /* for PLL fix */
225 hda_nid_t pll_nid;
226 unsigned int pll_coef_idx, pll_coef_bit;
227 unsigned int coef0;
229 /* multi-io */
230 int multi_ios;
231 struct alc_multi_io multi_io[4];
233 /* bind volumes */
234 struct snd_array bind_ctls;
237 static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
238 int dir, unsigned int bits)
240 if (!nid)
241 return false;
242 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
243 if (query_amp_caps(codec, nid, dir) & bits)
244 return true;
245 return false;
248 #define nid_has_mute(codec, nid, dir) \
249 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
250 #define nid_has_volume(codec, nid, dir) \
251 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
254 * input MUX handling
256 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
257 struct snd_ctl_elem_info *uinfo)
259 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
260 struct alc_spec *spec = codec->spec;
261 unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
262 if (mux_idx >= spec->num_mux_defs)
263 mux_idx = 0;
264 if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
265 mux_idx = 0;
266 return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
269 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
270 struct snd_ctl_elem_value *ucontrol)
272 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
273 struct alc_spec *spec = codec->spec;
274 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
276 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
277 return 0;
280 static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
282 struct alc_spec *spec = codec->spec;
283 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
285 if (spec->cur_adc && spec->cur_adc != new_adc) {
286 /* stream is running, let's swap the current ADC */
287 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
288 spec->cur_adc = new_adc;
289 snd_hda_codec_setup_stream(codec, new_adc,
290 spec->cur_adc_stream_tag, 0,
291 spec->cur_adc_format);
292 return true;
294 return false;
297 static inline hda_nid_t get_capsrc(struct alc_spec *spec, int idx)
299 return spec->capsrc_nids ?
300 spec->capsrc_nids[idx] : spec->adc_nids[idx];
303 static void call_update_outputs(struct hda_codec *codec);
304 static void alc_inv_dmic_sync(struct hda_codec *codec, bool force);
306 /* for shared I/O, change the pin-control accordingly */
307 static void update_shared_mic_hp(struct hda_codec *codec, bool set_as_mic)
309 struct alc_spec *spec = codec->spec;
310 unsigned int val;
311 hda_nid_t pin = spec->autocfg.inputs[1].pin;
312 /* NOTE: this assumes that there are only two inputs, the
313 * first is the real internal mic and the second is HP/mic jack.
316 val = snd_hda_get_default_vref(codec, pin);
318 /* This pin does not have vref caps - let's enable vref on pin 0x18
319 instead, as suggested by Realtek */
320 if (val == AC_PINCTL_VREF_HIZ) {
321 const hda_nid_t vref_pin = 0x18;
322 /* Sanity check pin 0x18 */
323 if (get_wcaps_type(get_wcaps(codec, vref_pin)) == AC_WID_PIN &&
324 get_defcfg_connect(snd_hda_codec_get_pincfg(codec, vref_pin)) == AC_JACK_PORT_NONE) {
325 unsigned int vref_val = snd_hda_get_default_vref(codec, vref_pin);
326 if (vref_val != AC_PINCTL_VREF_HIZ)
327 snd_hda_set_pin_ctl(codec, vref_pin, PIN_IN | (set_as_mic ? vref_val : 0));
331 val = set_as_mic ? val | PIN_IN : PIN_HP;
332 snd_hda_set_pin_ctl(codec, pin, val);
334 spec->automute_speaker = !set_as_mic;
335 call_update_outputs(codec);
338 /* select the given imux item; either unmute exclusively or select the route */
339 static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
340 unsigned int idx, bool force)
342 struct alc_spec *spec = codec->spec;
343 const struct hda_input_mux *imux;
344 unsigned int mux_idx;
345 int i, type, num_conns;
346 hda_nid_t nid;
348 if (!spec->input_mux)
349 return 0;
351 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
352 imux = &spec->input_mux[mux_idx];
353 if (!imux->num_items && mux_idx > 0)
354 imux = &spec->input_mux[0];
355 if (!imux->num_items)
356 return 0;
358 if (idx >= imux->num_items)
359 idx = imux->num_items - 1;
360 if (spec->cur_mux[adc_idx] == idx && !force)
361 return 0;
362 spec->cur_mux[adc_idx] = idx;
364 if (spec->shared_mic_hp)
365 update_shared_mic_hp(codec, spec->cur_mux[adc_idx]);
367 if (spec->dyn_adc_switch) {
368 alc_dyn_adc_pcm_resetup(codec, idx);
369 adc_idx = spec->dyn_adc_idx[idx];
372 nid = get_capsrc(spec, adc_idx);
374 /* no selection? */
375 num_conns = snd_hda_get_num_conns(codec, nid);
376 if (num_conns <= 1)
377 return 1;
379 type = get_wcaps_type(get_wcaps(codec, nid));
380 if (type == AC_WID_AUD_MIX) {
381 /* Matrix-mixer style (e.g. ALC882) */
382 int active = imux->items[idx].index;
383 for (i = 0; i < num_conns; i++) {
384 unsigned int v = (i == active) ? 0 : HDA_AMP_MUTE;
385 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, i,
386 HDA_AMP_MUTE, v);
388 } else {
389 /* MUX style (e.g. ALC880) */
390 snd_hda_codec_write_cache(codec, nid, 0,
391 AC_VERB_SET_CONNECT_SEL,
392 imux->items[idx].index);
394 alc_inv_dmic_sync(codec, true);
395 return 1;
398 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
399 struct snd_ctl_elem_value *ucontrol)
401 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
402 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
403 return alc_mux_select(codec, adc_idx,
404 ucontrol->value.enumerated.item[0], false);
408 * set up the input pin config (depending on the given auto-pin type)
410 static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
411 int auto_pin_type)
413 unsigned int val = PIN_IN;
414 if (auto_pin_type == AUTO_PIN_MIC)
415 val |= snd_hda_get_default_vref(codec, nid);
416 snd_hda_set_pin_ctl(codec, nid, val);
420 * Append the given mixer and verb elements for the later use
421 * The mixer array is referred in build_controls(), and init_verbs are
422 * called in init().
424 static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
426 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
427 return;
428 spec->mixers[spec->num_mixers++] = mix;
432 * GPIO setup tables, used in initialization
434 /* Enable GPIO mask and set output */
435 static const struct hda_verb alc_gpio1_init_verbs[] = {
436 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
437 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
438 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
442 static const struct hda_verb alc_gpio2_init_verbs[] = {
443 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
444 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
445 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
449 static const struct hda_verb alc_gpio3_init_verbs[] = {
450 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
451 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
452 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
457 * Fix hardware PLL issue
458 * On some codecs, the analog PLL gating control must be off while
459 * the default value is 1.
461 static void alc_fix_pll(struct hda_codec *codec)
463 struct alc_spec *spec = codec->spec;
464 unsigned int val;
466 if (!spec->pll_nid)
467 return;
468 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
469 spec->pll_coef_idx);
470 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
471 AC_VERB_GET_PROC_COEF, 0);
472 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
473 spec->pll_coef_idx);
474 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
475 val & ~(1 << spec->pll_coef_bit));
478 static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
479 unsigned int coef_idx, unsigned int coef_bit)
481 struct alc_spec *spec = codec->spec;
482 spec->pll_nid = nid;
483 spec->pll_coef_idx = coef_idx;
484 spec->pll_coef_bit = coef_bit;
485 alc_fix_pll(codec);
489 * Jack detections for HP auto-mute and mic-switch
492 /* check each pin in the given array; returns true if any of them is plugged */
493 static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
495 int i, present = 0;
497 for (i = 0; i < num_pins; i++) {
498 hda_nid_t nid = pins[i];
499 if (!nid)
500 break;
501 present |= snd_hda_jack_detect(codec, nid);
503 return present;
506 /* standard HP/line-out auto-mute helper */
507 static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
508 bool mute, bool hp_out)
510 struct alc_spec *spec = codec->spec;
511 unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0;
512 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
513 int i;
515 for (i = 0; i < num_pins; i++) {
516 hda_nid_t nid = pins[i];
517 unsigned int val;
518 if (!nid)
519 break;
520 switch (spec->automute_mode) {
521 case ALC_AUTOMUTE_PIN:
522 /* don't reset VREF value in case it's controlling
523 * the amp (see alc861_fixup_asus_amp_vref_0f())
525 if (spec->keep_vref_in_automute) {
526 val = snd_hda_codec_read(codec, nid, 0,
527 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
528 val &= ~PIN_HP;
529 } else
530 val = 0;
531 val |= pin_bits;
532 snd_hda_set_pin_ctl(codec, nid, val);
533 break;
534 case ALC_AUTOMUTE_AMP:
535 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
536 HDA_AMP_MUTE, mute_bits);
537 break;
538 case ALC_AUTOMUTE_MIXER:
539 nid = spec->automute_mixer_nid[i];
540 if (!nid)
541 break;
542 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
543 HDA_AMP_MUTE, mute_bits);
544 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1,
545 HDA_AMP_MUTE, mute_bits);
546 break;
551 /* Toggle outputs muting */
552 static void update_outputs(struct hda_codec *codec)
554 struct alc_spec *spec = codec->spec;
555 int on;
557 /* Control HP pins/amps depending on master_mute state;
558 * in general, HP pins/amps control should be enabled in all cases,
559 * but currently set only for master_mute, just to be safe
561 if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */
562 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
563 spec->autocfg.hp_pins, spec->master_mute, true);
565 if (!spec->automute_speaker)
566 on = 0;
567 else
568 on = spec->hp_jack_present | spec->line_jack_present;
569 on |= spec->master_mute;
570 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
571 spec->autocfg.speaker_pins, on, false);
573 /* toggle line-out mutes if needed, too */
574 /* if LO is a copy of either HP or Speaker, don't need to handle it */
575 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
576 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
577 return;
578 if (!spec->automute_lo)
579 on = 0;
580 else
581 on = spec->hp_jack_present;
582 on |= spec->master_mute;
583 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
584 spec->autocfg.line_out_pins, on, false);
587 static void call_update_outputs(struct hda_codec *codec)
589 struct alc_spec *spec = codec->spec;
590 if (spec->automute_hook)
591 spec->automute_hook(codec);
592 else
593 update_outputs(codec);
596 /* standard HP-automute helper */
597 static void alc_hp_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
599 struct alc_spec *spec = codec->spec;
601 spec->hp_jack_present =
602 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
603 spec->autocfg.hp_pins);
604 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
605 return;
606 call_update_outputs(codec);
609 /* standard line-out-automute helper */
610 static void alc_line_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
612 struct alc_spec *spec = codec->spec;
614 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
615 return;
616 /* check LO jack only when it's different from HP */
617 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
618 return;
620 spec->line_jack_present =
621 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
622 spec->autocfg.line_out_pins);
623 if (!spec->automute_speaker || !spec->detect_lo)
624 return;
625 call_update_outputs(codec);
628 #define get_connection_index(codec, mux, nid) \
629 snd_hda_get_conn_index(codec, mux, nid, 0)
631 /* standard mic auto-switch helper */
632 static void alc_mic_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
634 struct alc_spec *spec = codec->spec;
635 hda_nid_t *pins = spec->imux_pins;
637 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
638 return;
639 if (snd_BUG_ON(!spec->adc_nids))
640 return;
641 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
642 return;
644 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
645 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
646 else if (spec->dock_mic_idx >= 0 &&
647 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
648 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
649 else
650 alc_mux_select(codec, 0, spec->int_mic_idx, false);
653 /* update the master volume per volume-knob's unsol event */
654 static void alc_update_knob_master(struct hda_codec *codec, struct hda_jack_tbl *jack)
656 unsigned int val;
657 struct snd_kcontrol *kctl;
658 struct snd_ctl_elem_value *uctl;
660 kctl = snd_hda_find_mixer_ctl(codec, "Master Playback Volume");
661 if (!kctl)
662 return;
663 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
664 if (!uctl)
665 return;
666 val = snd_hda_codec_read(codec, jack->nid, 0,
667 AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
668 val &= HDA_AMP_VOLMASK;
669 uctl->value.integer.value[0] = val;
670 uctl->value.integer.value[1] = val;
671 kctl->put(kctl, uctl);
672 kfree(uctl);
675 static void alc880_unsol_event(struct hda_codec *codec, unsigned int res)
677 /* For some reason, the res given from ALC880 is broken.
678 Here we adjust it properly. */
679 snd_hda_jack_unsol_event(codec, res >> 2);
682 /* call init functions of standard auto-mute helpers */
683 static void alc_inithook(struct hda_codec *codec)
685 alc_hp_automute(codec, NULL);
686 alc_line_automute(codec, NULL);
687 alc_mic_automute(codec, NULL);
690 /* additional initialization for ALC888 variants */
691 static void alc888_coef_init(struct hda_codec *codec)
693 unsigned int tmp;
695 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
696 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
697 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
698 if ((tmp & 0xf0) == 0x20)
699 /* alc888S-VC */
700 snd_hda_codec_read(codec, 0x20, 0,
701 AC_VERB_SET_PROC_COEF, 0x830);
702 else
703 /* alc888-VB */
704 snd_hda_codec_read(codec, 0x20, 0,
705 AC_VERB_SET_PROC_COEF, 0x3030);
708 /* additional initialization for ALC889 variants */
709 static void alc889_coef_init(struct hda_codec *codec)
711 unsigned int tmp;
713 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
714 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
715 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
716 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
719 /* turn on/off EAPD control (only if available) */
720 static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
722 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
723 return;
724 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
725 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
726 on ? 2 : 0);
729 /* turn on/off EAPD controls of the codec */
730 static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
732 /* We currently only handle front, HP */
733 static hda_nid_t pins[] = {
734 0x0f, 0x10, 0x14, 0x15, 0
736 hda_nid_t *p;
737 for (p = pins; *p; p++)
738 set_eapd(codec, *p, on);
741 /* generic shutup callback;
742 * just turning off EPAD and a little pause for avoiding pop-noise
744 static void alc_eapd_shutup(struct hda_codec *codec)
746 alc_auto_setup_eapd(codec, false);
747 msleep(200);
750 /* generic EAPD initialization */
751 static void alc_auto_init_amp(struct hda_codec *codec, int type)
753 unsigned int tmp;
755 alc_auto_setup_eapd(codec, true);
756 switch (type) {
757 case ALC_INIT_GPIO1:
758 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
759 break;
760 case ALC_INIT_GPIO2:
761 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
762 break;
763 case ALC_INIT_GPIO3:
764 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
765 break;
766 case ALC_INIT_DEFAULT:
767 switch (codec->vendor_id) {
768 case 0x10ec0260:
769 snd_hda_codec_write(codec, 0x1a, 0,
770 AC_VERB_SET_COEF_INDEX, 7);
771 tmp = snd_hda_codec_read(codec, 0x1a, 0,
772 AC_VERB_GET_PROC_COEF, 0);
773 snd_hda_codec_write(codec, 0x1a, 0,
774 AC_VERB_SET_COEF_INDEX, 7);
775 snd_hda_codec_write(codec, 0x1a, 0,
776 AC_VERB_SET_PROC_COEF,
777 tmp | 0x2010);
778 break;
779 case 0x10ec0262:
780 case 0x10ec0880:
781 case 0x10ec0882:
782 case 0x10ec0883:
783 case 0x10ec0885:
784 case 0x10ec0887:
785 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
786 alc889_coef_init(codec);
787 break;
788 case 0x10ec0888:
789 alc888_coef_init(codec);
790 break;
791 #if 0 /* XXX: This may cause the silent output on speaker on some machines */
792 case 0x10ec0267:
793 case 0x10ec0268:
794 snd_hda_codec_write(codec, 0x20, 0,
795 AC_VERB_SET_COEF_INDEX, 7);
796 tmp = snd_hda_codec_read(codec, 0x20, 0,
797 AC_VERB_GET_PROC_COEF, 0);
798 snd_hda_codec_write(codec, 0x20, 0,
799 AC_VERB_SET_COEF_INDEX, 7);
800 snd_hda_codec_write(codec, 0x20, 0,
801 AC_VERB_SET_PROC_COEF,
802 tmp | 0x3000);
803 break;
804 #endif /* XXX */
806 break;
811 * Auto-Mute mode mixer enum support
813 static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
814 struct snd_ctl_elem_info *uinfo)
816 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
817 struct alc_spec *spec = codec->spec;
818 static const char * const texts3[] = {
819 "Disabled", "Speaker Only", "Line Out+Speaker"
822 if (spec->automute_speaker_possible && spec->automute_lo_possible)
823 return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3);
824 return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
827 static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
828 struct snd_ctl_elem_value *ucontrol)
830 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
831 struct alc_spec *spec = codec->spec;
832 unsigned int val = 0;
833 if (spec->automute_speaker)
834 val++;
835 if (spec->automute_lo)
836 val++;
838 ucontrol->value.enumerated.item[0] = val;
839 return 0;
842 static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
843 struct snd_ctl_elem_value *ucontrol)
845 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
846 struct alc_spec *spec = codec->spec;
848 switch (ucontrol->value.enumerated.item[0]) {
849 case 0:
850 if (!spec->automute_speaker && !spec->automute_lo)
851 return 0;
852 spec->automute_speaker = 0;
853 spec->automute_lo = 0;
854 break;
855 case 1:
856 if (spec->automute_speaker_possible) {
857 if (!spec->automute_lo && spec->automute_speaker)
858 return 0;
859 spec->automute_speaker = 1;
860 spec->automute_lo = 0;
861 } else if (spec->automute_lo_possible) {
862 if (spec->automute_lo)
863 return 0;
864 spec->automute_lo = 1;
865 } else
866 return -EINVAL;
867 break;
868 case 2:
869 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
870 return -EINVAL;
871 if (spec->automute_speaker && spec->automute_lo)
872 return 0;
873 spec->automute_speaker = 1;
874 spec->automute_lo = 1;
875 break;
876 default:
877 return -EINVAL;
879 call_update_outputs(codec);
880 return 1;
883 static const struct snd_kcontrol_new alc_automute_mode_enum = {
884 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
885 .name = "Auto-Mute Mode",
886 .info = alc_automute_mode_info,
887 .get = alc_automute_mode_get,
888 .put = alc_automute_mode_put,
891 static struct snd_kcontrol_new *
892 alc_kcontrol_new(struct alc_spec *spec, const char *name,
893 const struct snd_kcontrol_new *temp)
895 struct snd_kcontrol_new *knew = snd_array_new(&spec->kctls);
896 if (!knew)
897 return NULL;
898 *knew = *temp;
899 knew->name = kstrdup(name, GFP_KERNEL);
900 if (!knew->name)
901 return NULL;
902 return knew;
905 static int alc_add_automute_mode_enum(struct hda_codec *codec)
907 struct alc_spec *spec = codec->spec;
909 if (!alc_kcontrol_new(spec, "Auto-Mute Mode", &alc_automute_mode_enum))
910 return -ENOMEM;
911 return 0;
915 * Check the availability of HP/line-out auto-mute;
916 * Set up appropriately if really supported
918 static int alc_init_automute(struct hda_codec *codec)
920 struct alc_spec *spec = codec->spec;
921 struct auto_pin_cfg *cfg = &spec->autocfg;
922 int present = 0;
923 int i, err;
925 if (cfg->hp_pins[0])
926 present++;
927 if (cfg->line_out_pins[0])
928 present++;
929 if (cfg->speaker_pins[0])
930 present++;
931 if (present < 2) /* need two different output types */
932 return 0;
934 if (!cfg->speaker_pins[0] &&
935 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
936 memcpy(cfg->speaker_pins, cfg->line_out_pins,
937 sizeof(cfg->speaker_pins));
938 cfg->speaker_outs = cfg->line_outs;
941 if (!cfg->hp_pins[0] &&
942 cfg->line_out_type == AUTO_PIN_HP_OUT) {
943 memcpy(cfg->hp_pins, cfg->line_out_pins,
944 sizeof(cfg->hp_pins));
945 cfg->hp_outs = cfg->line_outs;
948 spec->automute_mode = ALC_AUTOMUTE_PIN;
950 for (i = 0; i < cfg->hp_outs; i++) {
951 hda_nid_t nid = cfg->hp_pins[i];
952 if (!is_jack_detectable(codec, nid))
953 continue;
954 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
955 nid);
956 snd_hda_jack_detect_enable_callback(codec, nid, ALC_HP_EVENT,
957 alc_hp_automute);
958 spec->detect_hp = 1;
961 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
962 if (cfg->speaker_outs)
963 for (i = 0; i < cfg->line_outs; i++) {
964 hda_nid_t nid = cfg->line_out_pins[i];
965 if (!is_jack_detectable(codec, nid))
966 continue;
967 snd_printdd("realtek: Enable Line-Out "
968 "auto-muting on NID 0x%x\n", nid);
969 snd_hda_jack_detect_enable_callback(codec, nid, ALC_FRONT_EVENT,
970 alc_line_automute);
971 spec->detect_lo = 1;
973 spec->automute_lo_possible = spec->detect_hp;
976 spec->automute_speaker_possible = cfg->speaker_outs &&
977 (spec->detect_hp || spec->detect_lo);
979 spec->automute_lo = spec->automute_lo_possible;
980 spec->automute_speaker = spec->automute_speaker_possible;
982 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
983 /* create a control for automute mode */
984 err = alc_add_automute_mode_enum(codec);
985 if (err < 0)
986 return err;
988 return 0;
991 /* return the position of NID in the list, or -1 if not found */
992 static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
994 int i;
995 for (i = 0; i < nums; i++)
996 if (list[i] == nid)
997 return i;
998 return -1;
1001 /* check whether dynamic ADC-switching is available */
1002 static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
1004 struct alc_spec *spec = codec->spec;
1005 struct hda_input_mux *imux = &spec->private_imux[0];
1006 int i, n, idx;
1007 hda_nid_t cap, pin;
1009 if (imux != spec->input_mux) /* no dynamic imux? */
1010 return false;
1012 for (n = 0; n < spec->num_adc_nids; n++) {
1013 cap = spec->private_capsrc_nids[n];
1014 for (i = 0; i < imux->num_items; i++) {
1015 pin = spec->imux_pins[i];
1016 if (!pin)
1017 return false;
1018 if (get_connection_index(codec, cap, pin) < 0)
1019 break;
1021 if (i >= imux->num_items)
1022 return true; /* no ADC-switch is needed */
1025 for (i = 0; i < imux->num_items; i++) {
1026 pin = spec->imux_pins[i];
1027 for (n = 0; n < spec->num_adc_nids; n++) {
1028 cap = spec->private_capsrc_nids[n];
1029 idx = get_connection_index(codec, cap, pin);
1030 if (idx >= 0) {
1031 imux->items[i].index = idx;
1032 spec->dyn_adc_idx[i] = n;
1033 break;
1038 snd_printdd("realtek: enabling ADC switching\n");
1039 spec->dyn_adc_switch = 1;
1040 return true;
1043 /* check whether all auto-mic pins are valid; setup indices if OK */
1044 static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1046 struct alc_spec *spec = codec->spec;
1047 const struct hda_input_mux *imux;
1049 if (!spec->auto_mic)
1050 return false;
1051 if (spec->auto_mic_valid_imux)
1052 return true; /* already checked */
1054 /* fill up imux indices */
1055 if (!alc_check_dyn_adc_switch(codec)) {
1056 spec->auto_mic = 0;
1057 return false;
1060 imux = spec->input_mux;
1061 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1062 spec->imux_pins, imux->num_items);
1063 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1064 spec->imux_pins, imux->num_items);
1065 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1066 spec->imux_pins, imux->num_items);
1067 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1068 spec->auto_mic = 0;
1069 return false; /* no corresponding imux */
1072 snd_hda_jack_detect_enable_callback(codec, spec->ext_mic_pin,
1073 ALC_MIC_EVENT, alc_mic_automute);
1074 if (spec->dock_mic_pin)
1075 snd_hda_jack_detect_enable_callback(codec, spec->dock_mic_pin,
1076 ALC_MIC_EVENT,
1077 alc_mic_automute);
1079 spec->auto_mic_valid_imux = 1;
1080 spec->auto_mic = 1;
1081 return true;
1085 * Check the availability of auto-mic switch;
1086 * Set up if really supported
1088 static int alc_init_auto_mic(struct hda_codec *codec)
1090 struct alc_spec *spec = codec->spec;
1091 struct auto_pin_cfg *cfg = &spec->autocfg;
1092 hda_nid_t fixed, ext, dock;
1093 int i;
1095 if (spec->shared_mic_hp)
1096 return 0; /* no auto-mic for the shared I/O */
1098 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1100 fixed = ext = dock = 0;
1101 for (i = 0; i < cfg->num_inputs; i++) {
1102 hda_nid_t nid = cfg->inputs[i].pin;
1103 unsigned int defcfg;
1104 defcfg = snd_hda_codec_get_pincfg(codec, nid);
1105 switch (snd_hda_get_input_pin_attr(defcfg)) {
1106 case INPUT_PIN_ATTR_INT:
1107 if (fixed)
1108 return 0; /* already occupied */
1109 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1110 return 0; /* invalid type */
1111 fixed = nid;
1112 break;
1113 case INPUT_PIN_ATTR_UNUSED:
1114 return 0; /* invalid entry */
1115 case INPUT_PIN_ATTR_DOCK:
1116 if (dock)
1117 return 0; /* already occupied */
1118 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1119 return 0; /* invalid type */
1120 dock = nid;
1121 break;
1122 default:
1123 if (ext)
1124 return 0; /* already occupied */
1125 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1126 return 0; /* invalid type */
1127 ext = nid;
1128 break;
1131 if (!ext && dock) {
1132 ext = dock;
1133 dock = 0;
1135 if (!ext || !fixed)
1136 return 0;
1137 if (!is_jack_detectable(codec, ext))
1138 return 0; /* no unsol support */
1139 if (dock && !is_jack_detectable(codec, dock))
1140 return 0; /* no unsol support */
1142 /* check imux indices */
1143 spec->ext_mic_pin = ext;
1144 spec->int_mic_pin = fixed;
1145 spec->dock_mic_pin = dock;
1147 spec->auto_mic = 1;
1148 if (!alc_auto_mic_check_imux(codec))
1149 return 0;
1151 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1152 ext, fixed, dock);
1154 return 0;
1157 /* check the availabilities of auto-mute and auto-mic switches */
1158 static int alc_auto_check_switches(struct hda_codec *codec)
1160 int err;
1162 err = alc_init_automute(codec);
1163 if (err < 0)
1164 return err;
1165 err = alc_init_auto_mic(codec);
1166 if (err < 0)
1167 return err;
1168 return 0;
1172 * Realtek SSID verification
1175 /* Could be any non-zero and even value. When used as fixup, tells
1176 * the driver to ignore any present sku defines.
1178 #define ALC_FIXUP_SKU_IGNORE (2)
1180 static void alc_fixup_sku_ignore(struct hda_codec *codec,
1181 const struct hda_fixup *fix, int action)
1183 struct alc_spec *spec = codec->spec;
1184 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
1185 spec->cdefine.fixup = 1;
1186 spec->cdefine.sku_cfg = ALC_FIXUP_SKU_IGNORE;
1190 static int alc_auto_parse_customize_define(struct hda_codec *codec)
1192 unsigned int ass, tmp, i;
1193 unsigned nid = 0;
1194 struct alc_spec *spec = codec->spec;
1196 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1198 if (spec->cdefine.fixup) {
1199 ass = spec->cdefine.sku_cfg;
1200 if (ass == ALC_FIXUP_SKU_IGNORE)
1201 return -1;
1202 goto do_sku;
1205 ass = codec->subsystem_id & 0xffff;
1206 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
1207 goto do_sku;
1209 nid = 0x1d;
1210 if (codec->vendor_id == 0x10ec0260)
1211 nid = 0x17;
1212 ass = snd_hda_codec_get_pincfg(codec, nid);
1214 if (!(ass & 1)) {
1215 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1216 codec->chip_name, ass);
1217 return -1;
1220 /* check sum */
1221 tmp = 0;
1222 for (i = 1; i < 16; i++) {
1223 if ((ass >> i) & 1)
1224 tmp++;
1226 if (((ass >> 16) & 0xf) != tmp)
1227 return -1;
1229 spec->cdefine.port_connectivity = ass >> 30;
1230 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1231 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1232 spec->cdefine.customization = ass >> 8;
1233 do_sku:
1234 spec->cdefine.sku_cfg = ass;
1235 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1236 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1237 spec->cdefine.swap = (ass & 0x2) >> 1;
1238 spec->cdefine.override = ass & 0x1;
1240 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1241 nid, spec->cdefine.sku_cfg);
1242 snd_printd("SKU: port_connectivity=0x%x\n",
1243 spec->cdefine.port_connectivity);
1244 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1245 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1246 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1247 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1248 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1249 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1250 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1252 return 0;
1255 /* return true if the given NID is found in the list */
1256 static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1258 return find_idx_in_nid_list(nid, list, nums) >= 0;
1261 /* check subsystem ID and set up device-specific initialization;
1262 * return 1 if initialized, 0 if invalid SSID
1264 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1265 * 31 ~ 16 : Manufacture ID
1266 * 15 ~ 8 : SKU ID
1267 * 7 ~ 0 : Assembly ID
1268 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1270 static int alc_subsystem_id(struct hda_codec *codec,
1271 hda_nid_t porta, hda_nid_t porte,
1272 hda_nid_t portd, hda_nid_t porti)
1274 unsigned int ass, tmp, i;
1275 unsigned nid;
1276 struct alc_spec *spec = codec->spec;
1278 if (spec->cdefine.fixup) {
1279 ass = spec->cdefine.sku_cfg;
1280 if (ass == ALC_FIXUP_SKU_IGNORE)
1281 return 0;
1282 goto do_sku;
1285 ass = codec->subsystem_id & 0xffff;
1286 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1287 goto do_sku;
1289 /* invalid SSID, check the special NID pin defcfg instead */
1291 * 31~30 : port connectivity
1292 * 29~21 : reserve
1293 * 20 : PCBEEP input
1294 * 19~16 : Check sum (15:1)
1295 * 15~1 : Custom
1296 * 0 : override
1298 nid = 0x1d;
1299 if (codec->vendor_id == 0x10ec0260)
1300 nid = 0x17;
1301 ass = snd_hda_codec_get_pincfg(codec, nid);
1302 snd_printd("realtek: No valid SSID, "
1303 "checking pincfg 0x%08x for NID 0x%x\n",
1304 ass, nid);
1305 if (!(ass & 1))
1306 return 0;
1307 if ((ass >> 30) != 1) /* no physical connection */
1308 return 0;
1310 /* check sum */
1311 tmp = 0;
1312 for (i = 1; i < 16; i++) {
1313 if ((ass >> i) & 1)
1314 tmp++;
1316 if (((ass >> 16) & 0xf) != tmp)
1317 return 0;
1318 do_sku:
1319 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1320 ass & 0xffff, codec->vendor_id);
1322 * 0 : override
1323 * 1 : Swap Jack
1324 * 2 : 0 --> Desktop, 1 --> Laptop
1325 * 3~5 : External Amplifier control
1326 * 7~6 : Reserved
1328 tmp = (ass & 0x38) >> 3; /* external Amp control */
1329 switch (tmp) {
1330 case 1:
1331 spec->init_amp = ALC_INIT_GPIO1;
1332 break;
1333 case 3:
1334 spec->init_amp = ALC_INIT_GPIO2;
1335 break;
1336 case 7:
1337 spec->init_amp = ALC_INIT_GPIO3;
1338 break;
1339 case 5:
1340 default:
1341 spec->init_amp = ALC_INIT_DEFAULT;
1342 break;
1345 /* is laptop or Desktop and enable the function "Mute internal speaker
1346 * when the external headphone out jack is plugged"
1348 if (!(ass & 0x8000))
1349 return 1;
1351 * 10~8 : Jack location
1352 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1353 * 14~13: Resvered
1354 * 15 : 1 --> enable the function "Mute internal speaker
1355 * when the external headphone out jack is plugged"
1357 if (!spec->autocfg.hp_pins[0] &&
1358 !(spec->autocfg.line_out_pins[0] &&
1359 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
1360 hda_nid_t nid;
1361 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1362 if (tmp == 0)
1363 nid = porta;
1364 else if (tmp == 1)
1365 nid = porte;
1366 else if (tmp == 2)
1367 nid = portd;
1368 else if (tmp == 3)
1369 nid = porti;
1370 else
1371 return 1;
1372 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1373 spec->autocfg.line_outs))
1374 return 1;
1375 spec->autocfg.hp_pins[0] = nid;
1377 return 1;
1380 /* Check the validity of ALC subsystem-id
1381 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1382 static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
1384 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
1385 struct alc_spec *spec = codec->spec;
1386 snd_printd("realtek: "
1387 "Enable default setup for auto mode as fallback\n");
1388 spec->init_amp = ALC_INIT_DEFAULT;
1393 * COEF access helper functions
1395 static int alc_read_coef_idx(struct hda_codec *codec,
1396 unsigned int coef_idx)
1398 unsigned int val;
1399 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1400 coef_idx);
1401 val = snd_hda_codec_read(codec, 0x20, 0,
1402 AC_VERB_GET_PROC_COEF, 0);
1403 return val;
1406 static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1407 unsigned int coef_val)
1409 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1410 coef_idx);
1411 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1412 coef_val);
1415 /* a special bypass for COEF 0; read the cached value at the second time */
1416 static unsigned int alc_get_coef0(struct hda_codec *codec)
1418 struct alc_spec *spec = codec->spec;
1419 if (!spec->coef0)
1420 spec->coef0 = alc_read_coef_idx(codec, 0);
1421 return spec->coef0;
1425 * Digital I/O handling
1428 /* set right pin controls for digital I/O */
1429 static void alc_auto_init_digital(struct hda_codec *codec)
1431 struct alc_spec *spec = codec->spec;
1432 int i;
1433 hda_nid_t pin, dac;
1435 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1436 pin = spec->autocfg.dig_out_pins[i];
1437 if (!pin)
1438 continue;
1439 snd_hda_set_pin_ctl(codec, pin, PIN_OUT);
1440 if (!i)
1441 dac = spec->multiout.dig_out_nid;
1442 else
1443 dac = spec->slave_dig_outs[i - 1];
1444 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
1445 continue;
1446 snd_hda_codec_write(codec, dac, 0,
1447 AC_VERB_SET_AMP_GAIN_MUTE,
1448 AMP_OUT_UNMUTE);
1450 pin = spec->autocfg.dig_in_pin;
1451 if (pin)
1452 snd_hda_set_pin_ctl(codec, pin, PIN_IN);
1455 /* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1456 static void alc_auto_parse_digital(struct hda_codec *codec)
1458 struct alc_spec *spec = codec->spec;
1459 int i, err, nums;
1460 hda_nid_t dig_nid;
1462 /* support multiple SPDIFs; the secondary is set up as a slave */
1463 nums = 0;
1464 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1465 hda_nid_t conn[4];
1466 err = snd_hda_get_connections(codec,
1467 spec->autocfg.dig_out_pins[i],
1468 conn, ARRAY_SIZE(conn));
1469 if (err <= 0)
1470 continue;
1471 dig_nid = conn[0]; /* assume the first element is audio-out */
1472 if (!nums) {
1473 spec->multiout.dig_out_nid = dig_nid;
1474 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1475 } else {
1476 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
1477 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
1478 break;
1479 spec->slave_dig_outs[nums - 1] = dig_nid;
1481 nums++;
1484 if (spec->autocfg.dig_in_pin) {
1485 dig_nid = codec->start_nid;
1486 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1487 unsigned int wcaps = get_wcaps(codec, dig_nid);
1488 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1489 continue;
1490 if (!(wcaps & AC_WCAP_DIGITAL))
1491 continue;
1492 if (!(wcaps & AC_WCAP_CONN_LIST))
1493 continue;
1494 err = get_connection_index(codec, dig_nid,
1495 spec->autocfg.dig_in_pin);
1496 if (err >= 0) {
1497 spec->dig_in_nid = dig_nid;
1498 break;
1505 * capture mixer elements
1507 static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1508 struct snd_ctl_elem_info *uinfo)
1510 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1511 struct alc_spec *spec = codec->spec;
1512 unsigned long val;
1513 int err;
1515 mutex_lock(&codec->control_mutex);
1516 if (spec->vol_in_capsrc)
1517 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1518 else
1519 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1520 kcontrol->private_value = val;
1521 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
1522 mutex_unlock(&codec->control_mutex);
1523 return err;
1526 static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1527 unsigned int size, unsigned int __user *tlv)
1529 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1530 struct alc_spec *spec = codec->spec;
1531 unsigned long val;
1532 int err;
1534 mutex_lock(&codec->control_mutex);
1535 if (spec->vol_in_capsrc)
1536 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1537 else
1538 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1539 kcontrol->private_value = val;
1540 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
1541 mutex_unlock(&codec->control_mutex);
1542 return err;
1545 typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1546 struct snd_ctl_elem_value *ucontrol);
1548 static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1549 struct snd_ctl_elem_value *ucontrol,
1550 getput_call_t func, bool is_put)
1552 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1553 struct alc_spec *spec = codec->spec;
1554 int i, err = 0;
1556 mutex_lock(&codec->control_mutex);
1557 if (is_put && spec->dyn_adc_switch) {
1558 for (i = 0; i < spec->num_adc_nids; i++) {
1559 kcontrol->private_value =
1560 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1561 3, 0, HDA_INPUT);
1562 err = func(kcontrol, ucontrol);
1563 if (err < 0)
1564 goto error;
1566 } else {
1567 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1568 if (spec->vol_in_capsrc)
1569 kcontrol->private_value =
1570 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1571 3, 0, HDA_OUTPUT);
1572 else
1573 kcontrol->private_value =
1574 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1575 3, 0, HDA_INPUT);
1576 err = func(kcontrol, ucontrol);
1578 if (err >= 0 && is_put)
1579 alc_inv_dmic_sync(codec, false);
1580 error:
1581 mutex_unlock(&codec->control_mutex);
1582 return err;
1585 static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1586 struct snd_ctl_elem_value *ucontrol)
1588 return alc_cap_getput_caller(kcontrol, ucontrol,
1589 snd_hda_mixer_amp_volume_get, false);
1592 static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1593 struct snd_ctl_elem_value *ucontrol)
1595 return alc_cap_getput_caller(kcontrol, ucontrol,
1596 snd_hda_mixer_amp_volume_put, true);
1599 /* capture mixer elements */
1600 #define alc_cap_sw_info snd_ctl_boolean_stereo_info
1602 static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1603 struct snd_ctl_elem_value *ucontrol)
1605 return alc_cap_getput_caller(kcontrol, ucontrol,
1606 snd_hda_mixer_amp_switch_get, false);
1609 static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1610 struct snd_ctl_elem_value *ucontrol)
1612 return alc_cap_getput_caller(kcontrol, ucontrol,
1613 snd_hda_mixer_amp_switch_put, true);
1616 #define _DEFINE_CAPMIX(num) \
1618 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1619 .name = "Capture Switch", \
1620 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1621 .count = num, \
1622 .info = alc_cap_sw_info, \
1623 .get = alc_cap_sw_get, \
1624 .put = alc_cap_sw_put, \
1625 }, \
1627 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1628 .name = "Capture Volume", \
1629 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1630 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1631 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1632 .count = num, \
1633 .info = alc_cap_vol_info, \
1634 .get = alc_cap_vol_get, \
1635 .put = alc_cap_vol_put, \
1636 .tlv = { .c = alc_cap_vol_tlv }, \
1639 #define _DEFINE_CAPSRC(num) \
1641 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1642 /* .name = "Capture Source", */ \
1643 .name = "Input Source", \
1644 .count = num, \
1645 .info = alc_mux_enum_info, \
1646 .get = alc_mux_enum_get, \
1647 .put = alc_mux_enum_put, \
1650 #define DEFINE_CAPMIX(num) \
1651 static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
1652 _DEFINE_CAPMIX(num), \
1653 _DEFINE_CAPSRC(num), \
1654 { } /* end */ \
1657 #define DEFINE_CAPMIX_NOSRC(num) \
1658 static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
1659 _DEFINE_CAPMIX(num), \
1660 { } /* end */ \
1663 /* up to three ADCs */
1664 DEFINE_CAPMIX(1);
1665 DEFINE_CAPMIX(2);
1666 DEFINE_CAPMIX(3);
1667 DEFINE_CAPMIX_NOSRC(1);
1668 DEFINE_CAPMIX_NOSRC(2);
1669 DEFINE_CAPMIX_NOSRC(3);
1672 * Inverted digital-mic handling
1674 * First off, it's a bit tricky. The "Inverted Internal Mic Capture Switch"
1675 * gives the additional mute only to the right channel of the digital mic
1676 * capture stream. This is a workaround for avoiding the almost silence
1677 * by summing the stereo stream from some (known to be ForteMedia)
1678 * digital mic unit.
1680 * The logic is to call alc_inv_dmic_sync() after each action (possibly)
1681 * modifying ADC amp. When the mute flag is set, it mutes the R-channel
1682 * without caching so that the cache can still keep the original value.
1683 * The cached value is then restored when the flag is set off or any other
1684 * than d-mic is used as the current input source.
1686 static void alc_inv_dmic_sync(struct hda_codec *codec, bool force)
1688 struct alc_spec *spec = codec->spec;
1689 int i;
1691 if (!spec->inv_dmic_fixup)
1692 return;
1693 if (!spec->inv_dmic_muted && !force)
1694 return;
1695 for (i = 0; i < spec->num_adc_nids; i++) {
1696 int src = spec->dyn_adc_switch ? 0 : i;
1697 bool dmic_fixup = false;
1698 hda_nid_t nid;
1699 int parm, dir, v;
1701 if (spec->inv_dmic_muted &&
1702 spec->imux_pins[spec->cur_mux[src]] == spec->inv_dmic_pin)
1703 dmic_fixup = true;
1704 if (!dmic_fixup && !force)
1705 continue;
1706 if (spec->vol_in_capsrc) {
1707 nid = spec->capsrc_nids[i];
1708 parm = AC_AMP_SET_RIGHT | AC_AMP_SET_OUTPUT;
1709 dir = HDA_OUTPUT;
1710 } else {
1711 nid = spec->adc_nids[i];
1712 parm = AC_AMP_SET_RIGHT | AC_AMP_SET_INPUT;
1713 dir = HDA_INPUT;
1715 /* we care only right channel */
1716 v = snd_hda_codec_amp_read(codec, nid, 1, dir, 0);
1717 if (v & 0x80) /* if already muted, we don't need to touch */
1718 continue;
1719 if (dmic_fixup) /* add mute for d-mic */
1720 v |= 0x80;
1721 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
1722 parm | v);
1726 static int alc_inv_dmic_sw_get(struct snd_kcontrol *kcontrol,
1727 struct snd_ctl_elem_value *ucontrol)
1729 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1730 struct alc_spec *spec = codec->spec;
1732 ucontrol->value.integer.value[0] = !spec->inv_dmic_muted;
1733 return 0;
1736 static int alc_inv_dmic_sw_put(struct snd_kcontrol *kcontrol,
1737 struct snd_ctl_elem_value *ucontrol)
1739 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1740 struct alc_spec *spec = codec->spec;
1741 unsigned int val = !ucontrol->value.integer.value[0];
1743 if (val == spec->inv_dmic_muted)
1744 return 0;
1745 spec->inv_dmic_muted = val;
1746 alc_inv_dmic_sync(codec, true);
1747 return 0;
1750 static const struct snd_kcontrol_new alc_inv_dmic_sw = {
1751 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1752 .info = snd_ctl_boolean_mono_info,
1753 .get = alc_inv_dmic_sw_get,
1754 .put = alc_inv_dmic_sw_put,
1757 static int alc_add_inv_dmic_mixer(struct hda_codec *codec, hda_nid_t nid)
1759 struct alc_spec *spec = codec->spec;
1761 if (!alc_kcontrol_new(spec, "Inverted Internal Mic Capture Switch",
1762 &alc_inv_dmic_sw))
1763 return -ENOMEM;
1764 spec->inv_dmic_fixup = 1;
1765 spec->inv_dmic_muted = 0;
1766 spec->inv_dmic_pin = nid;
1767 return 0;
1770 /* typically the digital mic is put at node 0x12 */
1771 static void alc_fixup_inv_dmic_0x12(struct hda_codec *codec,
1772 const struct alc_fixup *fix, int action)
1774 if (action == ALC_FIXUP_ACT_PROBE)
1775 alc_add_inv_dmic_mixer(codec, 0x12);
1779 * virtual master controls
1783 * slave controls for virtual master
1785 static const char * const alc_slave_pfxs[] = {
1786 "Front", "Surround", "Center", "LFE", "Side",
1787 "Headphone", "Speaker", "Mono", "Line Out",
1788 "CLFE", "Bass Speaker", "PCM",
1789 NULL,
1793 * build control elements
1796 #define NID_MAPPING (-1)
1798 #define SUBDEV_SPEAKER_ (0 << 6)
1799 #define SUBDEV_HP_ (1 << 6)
1800 #define SUBDEV_LINE_ (2 << 6)
1801 #define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1802 #define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1803 #define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1805 static void alc_free_kctls(struct hda_codec *codec);
1807 #ifdef CONFIG_SND_HDA_INPUT_BEEP
1808 /* additional beep mixers; the actual parameters are overwritten at build */
1809 static const struct snd_kcontrol_new alc_beep_mixer[] = {
1810 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
1811 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
1812 { } /* end */
1814 #endif
1816 static int __alc_build_controls(struct hda_codec *codec)
1818 struct alc_spec *spec = codec->spec;
1819 struct snd_kcontrol *kctl = NULL;
1820 const struct snd_kcontrol_new *knew;
1821 int i, j, err;
1822 unsigned int u;
1823 hda_nid_t nid;
1825 for (i = 0; i < spec->num_mixers; i++) {
1826 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1827 if (err < 0)
1828 return err;
1830 if (spec->cap_mixer) {
1831 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1832 if (err < 0)
1833 return err;
1835 if (spec->multiout.dig_out_nid) {
1836 err = snd_hda_create_dig_out_ctls(codec,
1837 spec->multiout.dig_out_nid,
1838 spec->multiout.dig_out_nid,
1839 spec->pcm_rec[1].pcm_type);
1840 if (err < 0)
1841 return err;
1842 if (!spec->no_analog) {
1843 err = snd_hda_create_spdif_share_sw(codec,
1844 &spec->multiout);
1845 if (err < 0)
1846 return err;
1847 spec->multiout.share_spdif = 1;
1850 if (spec->dig_in_nid) {
1851 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1852 if (err < 0)
1853 return err;
1856 #ifdef CONFIG_SND_HDA_INPUT_BEEP
1857 /* create beep controls if needed */
1858 if (spec->beep_amp) {
1859 const struct snd_kcontrol_new *knew;
1860 for (knew = alc_beep_mixer; knew->name; knew++) {
1861 struct snd_kcontrol *kctl;
1862 kctl = snd_ctl_new1(knew, codec);
1863 if (!kctl)
1864 return -ENOMEM;
1865 kctl->private_value = spec->beep_amp;
1866 err = snd_hda_ctl_add(codec, 0, kctl);
1867 if (err < 0)
1868 return err;
1871 #endif
1873 /* if we have no master control, let's create it */
1874 if (!spec->no_analog &&
1875 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1876 unsigned int vmaster_tlv[4];
1877 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
1878 HDA_OUTPUT, vmaster_tlv);
1879 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1880 vmaster_tlv, alc_slave_pfxs,
1881 "Playback Volume");
1882 if (err < 0)
1883 return err;
1885 if (!spec->no_analog &&
1886 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1887 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
1888 NULL, alc_slave_pfxs,
1889 "Playback Switch",
1890 true, &spec->vmaster_mute.sw_kctl);
1891 if (err < 0)
1892 return err;
1895 /* assign Capture Source enums to NID */
1896 if (spec->capsrc_nids || spec->adc_nids) {
1897 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
1898 if (!kctl)
1899 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1900 for (i = 0; kctl && i < kctl->count; i++) {
1901 err = snd_hda_add_nid(codec, kctl, i,
1902 get_capsrc(spec, i));
1903 if (err < 0)
1904 return err;
1907 if (spec->cap_mixer && spec->adc_nids) {
1908 const char *kname = kctl ? kctl->id.name : NULL;
1909 for (knew = spec->cap_mixer; knew->name; knew++) {
1910 if (kname && strcmp(knew->name, kname) == 0)
1911 continue;
1912 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1913 for (i = 0; kctl && i < kctl->count; i++) {
1914 err = snd_hda_add_nid(codec, kctl, i,
1915 spec->adc_nids[i]);
1916 if (err < 0)
1917 return err;
1922 /* other nid->control mapping */
1923 for (i = 0; i < spec->num_mixers; i++) {
1924 for (knew = spec->mixers[i]; knew->name; knew++) {
1925 if (knew->iface != NID_MAPPING)
1926 continue;
1927 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1928 if (kctl == NULL)
1929 continue;
1930 u = knew->subdevice;
1931 for (j = 0; j < 4; j++, u >>= 8) {
1932 nid = u & 0x3f;
1933 if (nid == 0)
1934 continue;
1935 switch (u & 0xc0) {
1936 case SUBDEV_SPEAKER_:
1937 nid = spec->autocfg.speaker_pins[nid];
1938 break;
1939 case SUBDEV_LINE_:
1940 nid = spec->autocfg.line_out_pins[nid];
1941 break;
1942 case SUBDEV_HP_:
1943 nid = spec->autocfg.hp_pins[nid];
1944 break;
1945 default:
1946 continue;
1948 err = snd_hda_add_nid(codec, kctl, 0, nid);
1949 if (err < 0)
1950 return err;
1952 u = knew->private_value;
1953 for (j = 0; j < 4; j++, u >>= 8) {
1954 nid = u & 0xff;
1955 if (nid == 0)
1956 continue;
1957 err = snd_hda_add_nid(codec, kctl, 0, nid);
1958 if (err < 0)
1959 return err;
1964 alc_free_kctls(codec); /* no longer needed */
1966 return 0;
1969 static int alc_build_jacks(struct hda_codec *codec)
1971 struct alc_spec *spec = codec->spec;
1973 if (spec->shared_mic_hp) {
1974 int err;
1975 int nid = spec->autocfg.inputs[1].pin;
1976 err = snd_hda_jack_add_kctl(codec, nid, "Headphone Mic", 0);
1977 if (err < 0)
1978 return err;
1979 err = snd_hda_jack_detect_enable(codec, nid, 0);
1980 if (err < 0)
1981 return err;
1984 return snd_hda_jack_add_kctls(codec, &spec->autocfg);
1987 static int alc_build_controls(struct hda_codec *codec)
1989 int err = __alc_build_controls(codec);
1990 if (err < 0)
1991 return err;
1993 err = alc_build_jacks(codec);
1994 if (err < 0)
1995 return err;
1996 alc_apply_fixup(codec, ALC_FIXUP_ACT_BUILD);
1997 return 0;
2002 * Common callbacks
2005 static void alc_init_special_input_src(struct hda_codec *codec);
2006 static void alc_auto_init_std(struct hda_codec *codec);
2008 static int alc_init(struct hda_codec *codec)
2010 struct alc_spec *spec = codec->spec;
2012 if (spec->init_hook)
2013 spec->init_hook(codec);
2015 alc_fix_pll(codec);
2016 alc_auto_init_amp(codec, spec->init_amp);
2018 snd_hda_gen_apply_verbs(codec);
2019 alc_init_special_input_src(codec);
2020 alc_auto_init_std(codec);
2022 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2024 hda_call_check_power_status(codec, 0x01);
2025 return 0;
2028 #ifdef CONFIG_PM
2029 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2031 struct alc_spec *spec = codec->spec;
2032 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2034 #endif
2037 * Analog playback callbacks
2039 static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
2040 struct hda_codec *codec,
2041 struct snd_pcm_substream *substream)
2043 struct alc_spec *spec = codec->spec;
2044 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2045 hinfo);
2048 static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2049 struct hda_codec *codec,
2050 unsigned int stream_tag,
2051 unsigned int format,
2052 struct snd_pcm_substream *substream)
2054 struct alc_spec *spec = codec->spec;
2055 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2056 stream_tag, format, substream);
2059 static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2060 struct hda_codec *codec,
2061 struct snd_pcm_substream *substream)
2063 struct alc_spec *spec = codec->spec;
2064 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2068 * Digital out
2070 static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2071 struct hda_codec *codec,
2072 struct snd_pcm_substream *substream)
2074 struct alc_spec *spec = codec->spec;
2075 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2078 static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2079 struct hda_codec *codec,
2080 unsigned int stream_tag,
2081 unsigned int format,
2082 struct snd_pcm_substream *substream)
2084 struct alc_spec *spec = codec->spec;
2085 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2086 stream_tag, format, substream);
2089 static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2090 struct hda_codec *codec,
2091 struct snd_pcm_substream *substream)
2093 struct alc_spec *spec = codec->spec;
2094 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2097 static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2098 struct hda_codec *codec,
2099 struct snd_pcm_substream *substream)
2101 struct alc_spec *spec = codec->spec;
2102 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2106 * Analog capture
2108 static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2109 struct hda_codec *codec,
2110 unsigned int stream_tag,
2111 unsigned int format,
2112 struct snd_pcm_substream *substream)
2114 struct alc_spec *spec = codec->spec;
2116 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
2117 stream_tag, 0, format);
2118 return 0;
2121 static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2122 struct hda_codec *codec,
2123 struct snd_pcm_substream *substream)
2125 struct alc_spec *spec = codec->spec;
2127 snd_hda_codec_cleanup_stream(codec,
2128 spec->adc_nids[substream->number + 1]);
2129 return 0;
2132 /* analog capture with dynamic dual-adc changes */
2133 static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2134 struct hda_codec *codec,
2135 unsigned int stream_tag,
2136 unsigned int format,
2137 struct snd_pcm_substream *substream)
2139 struct alc_spec *spec = codec->spec;
2140 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
2141 spec->cur_adc_stream_tag = stream_tag;
2142 spec->cur_adc_format = format;
2143 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2144 return 0;
2147 static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2148 struct hda_codec *codec,
2149 struct snd_pcm_substream *substream)
2151 struct alc_spec *spec = codec->spec;
2152 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2153 spec->cur_adc = 0;
2154 return 0;
2157 static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
2158 .substreams = 1,
2159 .channels_min = 2,
2160 .channels_max = 2,
2161 .nid = 0, /* fill later */
2162 .ops = {
2163 .prepare = dyn_adc_capture_pcm_prepare,
2164 .cleanup = dyn_adc_capture_pcm_cleanup
2170 static const struct hda_pcm_stream alc_pcm_analog_playback = {
2171 .substreams = 1,
2172 .channels_min = 2,
2173 .channels_max = 8,
2174 /* NID is set in alc_build_pcms */
2175 .ops = {
2176 .open = alc_playback_pcm_open,
2177 .prepare = alc_playback_pcm_prepare,
2178 .cleanup = alc_playback_pcm_cleanup
2182 static const struct hda_pcm_stream alc_pcm_analog_capture = {
2183 .substreams = 1,
2184 .channels_min = 2,
2185 .channels_max = 2,
2186 /* NID is set in alc_build_pcms */
2189 static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
2190 .substreams = 1,
2191 .channels_min = 2,
2192 .channels_max = 2,
2193 /* NID is set in alc_build_pcms */
2196 static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
2197 .substreams = 2, /* can be overridden */
2198 .channels_min = 2,
2199 .channels_max = 2,
2200 /* NID is set in alc_build_pcms */
2201 .ops = {
2202 .prepare = alc_alt_capture_pcm_prepare,
2203 .cleanup = alc_alt_capture_pcm_cleanup
2207 static const struct hda_pcm_stream alc_pcm_digital_playback = {
2208 .substreams = 1,
2209 .channels_min = 2,
2210 .channels_max = 2,
2211 /* NID is set in alc_build_pcms */
2212 .ops = {
2213 .open = alc_dig_playback_pcm_open,
2214 .close = alc_dig_playback_pcm_close,
2215 .prepare = alc_dig_playback_pcm_prepare,
2216 .cleanup = alc_dig_playback_pcm_cleanup
2220 static const struct hda_pcm_stream alc_pcm_digital_capture = {
2221 .substreams = 1,
2222 .channels_min = 2,
2223 .channels_max = 2,
2224 /* NID is set in alc_build_pcms */
2227 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
2228 static const struct hda_pcm_stream alc_pcm_null_stream = {
2229 .substreams = 0,
2230 .channels_min = 0,
2231 .channels_max = 0,
2234 static int alc_build_pcms(struct hda_codec *codec)
2236 struct alc_spec *spec = codec->spec;
2237 struct hda_pcm *info = spec->pcm_rec;
2238 const struct hda_pcm_stream *p;
2239 bool have_multi_adcs;
2240 int i;
2242 codec->num_pcms = 1;
2243 codec->pcm_info = info;
2245 if (spec->no_analog)
2246 goto skip_analog;
2248 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2249 "%s Analog", codec->chip_name);
2250 info->name = spec->stream_name_analog;
2252 if (spec->multiout.num_dacs > 0) {
2253 p = spec->stream_analog_playback;
2254 if (!p)
2255 p = &alc_pcm_analog_playback;
2256 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2257 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2258 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
2259 spec->multiout.max_channels;
2260 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
2261 spec->autocfg.line_outs == 2)
2262 info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap =
2263 snd_pcm_2_1_chmaps;
2265 if (spec->adc_nids) {
2266 p = spec->stream_analog_capture;
2267 if (!p) {
2268 if (spec->dyn_adc_switch)
2269 p = &dyn_adc_pcm_analog_capture;
2270 else
2271 p = &alc_pcm_analog_capture;
2273 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2274 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2277 if (spec->channel_mode) {
2278 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2279 for (i = 0; i < spec->num_channel_mode; i++) {
2280 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2281 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2286 skip_analog:
2287 /* SPDIF for stream index #1 */
2288 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2289 snprintf(spec->stream_name_digital,
2290 sizeof(spec->stream_name_digital),
2291 "%s Digital", codec->chip_name);
2292 codec->num_pcms = 2;
2293 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
2294 info = spec->pcm_rec + 1;
2295 info->name = spec->stream_name_digital;
2296 if (spec->dig_out_type)
2297 info->pcm_type = spec->dig_out_type;
2298 else
2299 info->pcm_type = HDA_PCM_TYPE_SPDIF;
2300 if (spec->multiout.dig_out_nid) {
2301 p = spec->stream_digital_playback;
2302 if (!p)
2303 p = &alc_pcm_digital_playback;
2304 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2305 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2307 if (spec->dig_in_nid) {
2308 p = spec->stream_digital_capture;
2309 if (!p)
2310 p = &alc_pcm_digital_capture;
2311 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2312 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2314 /* FIXME: do we need this for all Realtek codec models? */
2315 codec->spdif_status_reset = 1;
2318 if (spec->no_analog)
2319 return 0;
2321 /* If the use of more than one ADC is requested for the current
2322 * model, configure a second analog capture-only PCM.
2324 have_multi_adcs = (spec->num_adc_nids > 1) &&
2325 !spec->dyn_adc_switch && !spec->auto_mic &&
2326 (!spec->input_mux || spec->input_mux->num_items > 1);
2327 /* Additional Analaog capture for index #2 */
2328 if (spec->alt_dac_nid || have_multi_adcs) {
2329 codec->num_pcms = 3;
2330 info = spec->pcm_rec + 2;
2331 info->name = spec->stream_name_analog;
2332 if (spec->alt_dac_nid) {
2333 p = spec->stream_analog_alt_playback;
2334 if (!p)
2335 p = &alc_pcm_analog_alt_playback;
2336 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2337 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2338 spec->alt_dac_nid;
2339 } else {
2340 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2341 alc_pcm_null_stream;
2342 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2344 if (have_multi_adcs) {
2345 p = spec->stream_analog_alt_capture;
2346 if (!p)
2347 p = &alc_pcm_analog_alt_capture;
2348 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2349 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2350 spec->adc_nids[1];
2351 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2352 spec->num_adc_nids - 1;
2353 } else {
2354 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2355 alc_pcm_null_stream;
2356 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
2360 return 0;
2363 static inline void alc_shutup(struct hda_codec *codec)
2365 struct alc_spec *spec = codec->spec;
2367 if (spec && spec->shutup)
2368 spec->shutup(codec);
2369 snd_hda_shutup_pins(codec);
2372 static void alc_free_kctls(struct hda_codec *codec)
2374 struct alc_spec *spec = codec->spec;
2376 if (spec->kctls.list) {
2377 struct snd_kcontrol_new *kctl = spec->kctls.list;
2378 int i;
2379 for (i = 0; i < spec->kctls.used; i++)
2380 kfree(kctl[i].name);
2382 snd_array_free(&spec->kctls);
2385 static void alc_free_bind_ctls(struct hda_codec *codec)
2387 struct alc_spec *spec = codec->spec;
2388 if (spec->bind_ctls.list) {
2389 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2390 int i;
2391 for (i = 0; i < spec->bind_ctls.used; i++)
2392 kfree(ctl[i]);
2394 snd_array_free(&spec->bind_ctls);
2397 static void alc_free(struct hda_codec *codec)
2399 struct alc_spec *spec = codec->spec;
2401 if (!spec)
2402 return;
2404 alc_free_kctls(codec);
2405 alc_free_bind_ctls(codec);
2406 snd_hda_gen_free(&spec->gen);
2407 kfree(spec);
2408 snd_hda_detach_beep_device(codec);
2411 #ifdef CONFIG_PM
2412 static void alc_power_eapd(struct hda_codec *codec)
2414 alc_auto_setup_eapd(codec, false);
2417 static int alc_suspend(struct hda_codec *codec)
2419 struct alc_spec *spec = codec->spec;
2420 alc_shutup(codec);
2421 if (spec && spec->power_hook)
2422 spec->power_hook(codec);
2423 return 0;
2425 #endif
2427 #ifdef CONFIG_PM
2428 static int alc_resume(struct hda_codec *codec)
2430 msleep(150); /* to avoid pop noise */
2431 codec->patch_ops.init(codec);
2432 snd_hda_codec_resume_amp(codec);
2433 snd_hda_codec_resume_cache(codec);
2434 alc_inv_dmic_sync(codec, true);
2435 hda_call_check_power_status(codec, 0x01);
2436 return 0;
2438 #endif
2442 static const struct hda_codec_ops alc_patch_ops = {
2443 .build_controls = alc_build_controls,
2444 .build_pcms = alc_build_pcms,
2445 .init = alc_init,
2446 .free = alc_free,
2447 .unsol_event = snd_hda_jack_unsol_event,
2448 #ifdef CONFIG_PM
2449 .resume = alc_resume,
2450 #endif
2451 #ifdef CONFIG_PM
2452 .suspend = alc_suspend,
2453 .check_power_status = alc_check_power_status,
2454 #endif
2455 .reboot_notify = alc_shutup,
2459 /* replace the codec chip_name with the given string */
2460 static int alc_codec_rename(struct hda_codec *codec, const char *name)
2462 kfree(codec->chip_name);
2463 codec->chip_name = kstrdup(name, GFP_KERNEL);
2464 if (!codec->chip_name) {
2465 alc_free(codec);
2466 return -ENOMEM;
2468 return 0;
2472 * Rename codecs appropriately from COEF value
2474 struct alc_codec_rename_table {
2475 unsigned int vendor_id;
2476 unsigned short coef_mask;
2477 unsigned short coef_bits;
2478 const char *name;
2481 static struct alc_codec_rename_table rename_tbl[] = {
2482 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2483 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2484 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2485 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2486 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2487 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2488 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
2489 { 0x10ec0269, 0x00f0, 0x0030, "ALC269VD" },
2490 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2491 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2492 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2493 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2494 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2495 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2496 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2497 { } /* terminator */
2500 static int alc_codec_rename_from_preset(struct hda_codec *codec)
2502 const struct alc_codec_rename_table *p;
2504 for (p = rename_tbl; p->vendor_id; p++) {
2505 if (p->vendor_id != codec->vendor_id)
2506 continue;
2507 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
2508 return alc_codec_rename(codec, p->name);
2510 return 0;
2514 * Automatic parse of I/O pins from the BIOS configuration
2517 enum {
2518 ALC_CTL_WIDGET_VOL,
2519 ALC_CTL_WIDGET_MUTE,
2520 ALC_CTL_BIND_MUTE,
2521 ALC_CTL_BIND_VOL,
2522 ALC_CTL_BIND_SW,
2524 static const struct snd_kcontrol_new alc_control_templates[] = {
2525 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2526 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2527 HDA_BIND_MUTE(NULL, 0, 0, 0),
2528 HDA_BIND_VOL(NULL, 0),
2529 HDA_BIND_SW(NULL, 0),
2532 /* add dynamic controls */
2533 static int add_control(struct alc_spec *spec, int type, const char *name,
2534 int cidx, unsigned long val)
2536 struct snd_kcontrol_new *knew;
2538 knew = alc_kcontrol_new(spec, name, &alc_control_templates[type]);
2539 if (!knew)
2540 return -ENOMEM;
2541 knew->index = cidx;
2542 if (get_amp_nid_(val))
2543 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
2544 knew->private_value = val;
2545 return 0;
2548 static int add_control_with_pfx(struct alc_spec *spec, int type,
2549 const char *pfx, const char *dir,
2550 const char *sfx, int cidx, unsigned long val)
2552 char name[32];
2553 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
2554 return add_control(spec, type, name, cidx, val);
2557 #define add_pb_vol_ctrl(spec, type, pfx, val) \
2558 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2559 #define add_pb_sw_ctrl(spec, type, pfx, val) \
2560 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2561 #define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2562 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2563 #define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2564 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
2566 static const char * const channel_name[4] = {
2567 "Front", "Surround", "CLFE", "Side"
2570 static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2571 bool can_be_master, int *index)
2573 struct auto_pin_cfg *cfg = &spec->autocfg;
2575 *index = 0;
2576 if (cfg->line_outs == 1 && !spec->multi_ios &&
2577 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
2578 return "Master";
2580 switch (cfg->line_out_type) {
2581 case AUTO_PIN_SPEAKER_OUT:
2582 if (cfg->line_outs == 1)
2583 return "Speaker";
2584 if (cfg->line_outs == 2)
2585 return ch ? "Bass Speaker" : "Speaker";
2586 break;
2587 case AUTO_PIN_HP_OUT:
2588 /* for multi-io case, only the primary out */
2589 if (ch && spec->multi_ios)
2590 break;
2591 *index = ch;
2592 return "Headphone";
2593 default:
2594 if (cfg->line_outs == 1 && !spec->multi_ios)
2595 return "PCM";
2596 break;
2598 if (ch >= ARRAY_SIZE(channel_name)) {
2599 snd_BUG();
2600 return "PCM";
2603 return channel_name[ch];
2606 #ifdef CONFIG_PM
2607 /* add the powersave loopback-list entry */
2608 static void add_loopback_list(struct alc_spec *spec, hda_nid_t mix, int idx)
2610 struct hda_amp_list *list;
2612 if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
2613 return;
2614 list = spec->loopback_list + spec->num_loopbacks;
2615 list->nid = mix;
2616 list->dir = HDA_INPUT;
2617 list->idx = idx;
2618 spec->num_loopbacks++;
2619 spec->loopback.amplist = spec->loopback_list;
2621 #else
2622 #define add_loopback_list(spec, mix, idx) /* NOP */
2623 #endif
2625 /* create input playback/capture controls for the given pin */
2626 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
2627 const char *ctlname, int ctlidx,
2628 int idx, hda_nid_t mix_nid)
2630 int err;
2632 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
2633 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2634 if (err < 0)
2635 return err;
2636 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
2637 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2638 if (err < 0)
2639 return err;
2640 add_loopback_list(spec, mix_nid, idx);
2641 return 0;
2644 static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
2646 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2647 return (pincap & AC_PINCAP_IN) != 0;
2650 /* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
2651 static int alc_auto_fill_adc_caps(struct hda_codec *codec)
2653 struct alc_spec *spec = codec->spec;
2654 hda_nid_t nid;
2655 hda_nid_t *adc_nids = spec->private_adc_nids;
2656 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2657 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
2658 int i, nums = 0;
2660 nid = codec->start_nid;
2661 for (i = 0; i < codec->num_nodes; i++, nid++) {
2662 hda_nid_t src;
2663 unsigned int caps = get_wcaps(codec, nid);
2664 int type = get_wcaps_type(caps);
2666 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2667 continue;
2668 adc_nids[nums] = nid;
2669 cap_nids[nums] = nid;
2670 src = nid;
2671 for (;;) {
2672 int n;
2673 type = get_wcaps_type(get_wcaps(codec, src));
2674 if (type == AC_WID_PIN)
2675 break;
2676 if (type == AC_WID_AUD_SEL) {
2677 cap_nids[nums] = src;
2678 break;
2680 n = snd_hda_get_num_conns(codec, src);
2681 if (n > 1) {
2682 cap_nids[nums] = src;
2683 break;
2684 } else if (n != 1)
2685 break;
2686 if (snd_hda_get_connections(codec, src, &src, 1) != 1)
2687 break;
2689 if (++nums >= max_nums)
2690 break;
2692 spec->adc_nids = spec->private_adc_nids;
2693 spec->capsrc_nids = spec->private_capsrc_nids;
2694 spec->num_adc_nids = nums;
2695 return nums;
2698 /* create playback/capture controls for input pins */
2699 static int alc_auto_create_input_ctls(struct hda_codec *codec)
2701 struct alc_spec *spec = codec->spec;
2702 const struct auto_pin_cfg *cfg = &spec->autocfg;
2703 hda_nid_t mixer = spec->mixer_nid;
2704 struct hda_input_mux *imux = &spec->private_imux[0];
2705 int num_adcs;
2706 int i, c, err, idx, type_idx = 0;
2707 const char *prev_label = NULL;
2709 num_adcs = alc_auto_fill_adc_caps(codec);
2710 if (num_adcs < 0)
2711 return 0;
2713 for (i = 0; i < cfg->num_inputs; i++) {
2714 hda_nid_t pin;
2715 const char *label;
2717 pin = cfg->inputs[i].pin;
2718 if (!alc_is_input_pin(codec, pin))
2719 continue;
2721 label = hda_get_autocfg_input_label(codec, cfg, i);
2722 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
2723 label = "Headphone Mic";
2724 if (prev_label && !strcmp(label, prev_label))
2725 type_idx++;
2726 else
2727 type_idx = 0;
2728 prev_label = label;
2730 if (mixer) {
2731 idx = get_connection_index(codec, mixer, pin);
2732 if (idx >= 0) {
2733 err = new_analog_input(spec, pin,
2734 label, type_idx,
2735 idx, mixer);
2736 if (err < 0)
2737 return err;
2741 for (c = 0; c < num_adcs; c++) {
2742 hda_nid_t cap = get_capsrc(spec, c);
2743 idx = get_connection_index(codec, cap, pin);
2744 if (idx >= 0) {
2745 spec->imux_pins[imux->num_items] = pin;
2746 snd_hda_add_imux_item(imux, label, idx, NULL);
2747 break;
2752 spec->num_mux_defs = 1;
2753 spec->input_mux = imux;
2755 return 0;
2758 /* create a shared input with the headphone out */
2759 static int alc_auto_create_shared_input(struct hda_codec *codec)
2761 struct alc_spec *spec = codec->spec;
2762 struct auto_pin_cfg *cfg = &spec->autocfg;
2763 unsigned int defcfg;
2764 hda_nid_t nid;
2766 /* only one internal input pin? */
2767 if (cfg->num_inputs != 1)
2768 return 0;
2769 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2770 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2771 return 0;
2773 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
2774 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
2775 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
2776 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
2777 else
2778 return 0; /* both not available */
2780 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2781 return 0; /* no input */
2783 cfg->inputs[1].pin = nid;
2784 cfg->inputs[1].type = AUTO_PIN_MIC;
2785 cfg->num_inputs = 2;
2786 spec->shared_mic_hp = 1;
2787 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
2788 return 0;
2791 static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
2792 unsigned int pin_type)
2794 snd_hda_set_pin_ctl(codec, nid, pin_type);
2795 /* unmute pin */
2796 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2797 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2798 AMP_OUT_UNMUTE);
2801 static int get_pin_type(int line_out_type)
2803 if (line_out_type == AUTO_PIN_HP_OUT)
2804 return PIN_HP;
2805 else
2806 return PIN_OUT;
2809 static void alc_auto_init_analog_input(struct hda_codec *codec)
2811 struct alc_spec *spec = codec->spec;
2812 struct auto_pin_cfg *cfg = &spec->autocfg;
2813 int i;
2815 for (i = 0; i < cfg->num_inputs; i++) {
2816 hda_nid_t nid = cfg->inputs[i].pin;
2817 if (alc_is_input_pin(codec, nid)) {
2818 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
2819 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
2820 snd_hda_codec_write(codec, nid, 0,
2821 AC_VERB_SET_AMP_GAIN_MUTE,
2822 AMP_OUT_MUTE);
2826 /* mute all loopback inputs */
2827 if (spec->mixer_nid) {
2828 int nums = snd_hda_get_num_conns(codec, spec->mixer_nid);
2829 for (i = 0; i < nums; i++)
2830 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2831 AC_VERB_SET_AMP_GAIN_MUTE,
2832 AMP_IN_MUTE(i));
2836 /* convert from MIX nid to DAC */
2837 static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid)
2839 hda_nid_t list[5];
2840 int i, num;
2842 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT)
2843 return nid;
2844 num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list));
2845 for (i = 0; i < num; i++) {
2846 if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT)
2847 return list[i];
2849 return 0;
2852 /* go down to the selector widget before the mixer */
2853 static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin)
2855 hda_nid_t srcs[5];
2856 int num = snd_hda_get_connections(codec, pin, srcs,
2857 ARRAY_SIZE(srcs));
2858 if (num != 1 ||
2859 get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL)
2860 return pin;
2861 return srcs[0];
2864 /* get MIX nid connected to the given pin targeted to DAC */
2865 static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
2866 hda_nid_t dac)
2868 hda_nid_t mix[5];
2869 int i, num;
2871 pin = alc_go_down_to_selector(codec, pin);
2872 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2873 for (i = 0; i < num; i++) {
2874 if (alc_auto_mix_to_dac(codec, mix[i]) == dac)
2875 return mix[i];
2877 return 0;
2880 /* select the connection from pin to DAC if needed */
2881 static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin,
2882 hda_nid_t dac)
2884 hda_nid_t mix[5];
2885 int i, num;
2887 pin = alc_go_down_to_selector(codec, pin);
2888 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2889 if (num < 2)
2890 return 0;
2891 for (i = 0; i < num; i++) {
2892 if (alc_auto_mix_to_dac(codec, mix[i]) == dac) {
2893 snd_hda_codec_update_cache(codec, pin, 0,
2894 AC_VERB_SET_CONNECT_SEL, i);
2895 return 0;
2898 return 0;
2901 static bool alc_is_dac_already_used(struct hda_codec *codec, hda_nid_t nid)
2903 struct alc_spec *spec = codec->spec;
2904 int i;
2905 if (found_in_nid_list(nid, spec->multiout.dac_nids,
2906 ARRAY_SIZE(spec->private_dac_nids)) ||
2907 found_in_nid_list(nid, spec->multiout.hp_out_nid,
2908 ARRAY_SIZE(spec->multiout.hp_out_nid)) ||
2909 found_in_nid_list(nid, spec->multiout.extra_out_nid,
2910 ARRAY_SIZE(spec->multiout.extra_out_nid)))
2911 return true;
2912 for (i = 0; i < spec->multi_ios; i++) {
2913 if (spec->multi_io[i].dac == nid)
2914 return true;
2916 return false;
2919 /* look for an empty DAC slot */
2920 static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
2922 hda_nid_t srcs[5];
2923 int i, num;
2925 pin = alc_go_down_to_selector(codec, pin);
2926 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
2927 for (i = 0; i < num; i++) {
2928 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
2929 if (!nid)
2930 continue;
2931 if (!alc_is_dac_already_used(codec, nid))
2932 return nid;
2934 return 0;
2937 /* check whether the DAC is reachable from the pin */
2938 static bool alc_auto_is_dac_reachable(struct hda_codec *codec,
2939 hda_nid_t pin, hda_nid_t dac)
2941 hda_nid_t srcs[5];
2942 int i, num;
2944 if (!pin || !dac)
2945 return false;
2946 pin = alc_go_down_to_selector(codec, pin);
2947 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
2948 for (i = 0; i < num; i++) {
2949 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
2950 if (nid == dac)
2951 return true;
2953 return false;
2956 static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
2958 struct alc_spec *spec = codec->spec;
2959 hda_nid_t sel = alc_go_down_to_selector(codec, pin);
2960 hda_nid_t nid, nid_found, srcs[5];
2961 int i, num = snd_hda_get_connections(codec, sel, srcs,
2962 ARRAY_SIZE(srcs));
2963 if (num == 1)
2964 return alc_auto_look_for_dac(codec, pin);
2965 nid_found = 0;
2966 for (i = 0; i < num; i++) {
2967 if (srcs[i] == spec->mixer_nid)
2968 continue;
2969 nid = alc_auto_mix_to_dac(codec, srcs[i]);
2970 if (nid && !alc_is_dac_already_used(codec, nid)) {
2971 if (nid_found)
2972 return 0;
2973 nid_found = nid;
2976 return nid_found;
2979 /* mark up volume and mute control NIDs: used during badness parsing and
2980 * at creating actual controls
2982 static inline unsigned int get_ctl_pos(unsigned int data)
2984 hda_nid_t nid = get_amp_nid_(data);
2985 unsigned int dir;
2986 if (snd_BUG_ON(nid >= MAX_VOL_NIDS))
2987 return 0;
2988 dir = get_amp_direction_(data);
2989 return (nid << 1) | dir;
2992 #define is_ctl_used(bits, data) \
2993 test_bit(get_ctl_pos(data), bits)
2994 #define mark_ctl_usage(bits, data) \
2995 set_bit(get_ctl_pos(data), bits)
2997 static void clear_vol_marks(struct hda_codec *codec)
2999 struct alc_spec *spec = codec->spec;
3000 memset(spec->vol_ctls, 0, sizeof(spec->vol_ctls));
3001 memset(spec->sw_ctls, 0, sizeof(spec->sw_ctls));
3004 /* badness definition */
3005 enum {
3006 /* No primary DAC is found for the main output */
3007 BAD_NO_PRIMARY_DAC = 0x10000,
3008 /* No DAC is found for the extra output */
3009 BAD_NO_DAC = 0x4000,
3010 /* No possible multi-ios */
3011 BAD_MULTI_IO = 0x103,
3012 /* No individual DAC for extra output */
3013 BAD_NO_EXTRA_DAC = 0x102,
3014 /* No individual DAC for extra surrounds */
3015 BAD_NO_EXTRA_SURR_DAC = 0x101,
3016 /* Primary DAC shared with main surrounds */
3017 BAD_SHARED_SURROUND = 0x100,
3018 /* Primary DAC shared with main CLFE */
3019 BAD_SHARED_CLFE = 0x10,
3020 /* Primary DAC shared with extra surrounds */
3021 BAD_SHARED_EXTRA_SURROUND = 0x10,
3022 /* Volume widget is shared */
3023 BAD_SHARED_VOL = 0x10,
3026 static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3027 hda_nid_t pin, hda_nid_t dac);
3028 static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3029 hda_nid_t pin, hda_nid_t dac);
3031 static int eval_shared_vol_badness(struct hda_codec *codec, hda_nid_t pin,
3032 hda_nid_t dac)
3034 struct alc_spec *spec = codec->spec;
3035 hda_nid_t nid;
3036 unsigned int val;
3037 int badness = 0;
3039 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3040 if (nid) {
3041 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3042 if (is_ctl_used(spec->vol_ctls, nid))
3043 badness += BAD_SHARED_VOL;
3044 else
3045 mark_ctl_usage(spec->vol_ctls, val);
3046 } else
3047 badness += BAD_SHARED_VOL;
3048 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3049 if (nid) {
3050 unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid));
3051 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT)
3052 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3053 else
3054 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
3055 if (is_ctl_used(spec->sw_ctls, val))
3056 badness += BAD_SHARED_VOL;
3057 else
3058 mark_ctl_usage(spec->sw_ctls, val);
3059 } else
3060 badness += BAD_SHARED_VOL;
3061 return badness;
3064 struct badness_table {
3065 int no_primary_dac; /* no primary DAC */
3066 int no_dac; /* no secondary DACs */
3067 int shared_primary; /* primary DAC is shared with main output */
3068 int shared_surr; /* secondary DAC shared with main or primary */
3069 int shared_clfe; /* third DAC shared with main or primary */
3070 int shared_surr_main; /* secondary DAC sahred with main/DAC0 */
3073 static struct badness_table main_out_badness = {
3074 .no_primary_dac = BAD_NO_PRIMARY_DAC,
3075 .no_dac = BAD_NO_DAC,
3076 .shared_primary = BAD_NO_PRIMARY_DAC,
3077 .shared_surr = BAD_SHARED_SURROUND,
3078 .shared_clfe = BAD_SHARED_CLFE,
3079 .shared_surr_main = BAD_SHARED_SURROUND,
3082 static struct badness_table extra_out_badness = {
3083 .no_primary_dac = BAD_NO_DAC,
3084 .no_dac = BAD_NO_DAC,
3085 .shared_primary = BAD_NO_EXTRA_DAC,
3086 .shared_surr = BAD_SHARED_EXTRA_SURROUND,
3087 .shared_clfe = BAD_SHARED_EXTRA_SURROUND,
3088 .shared_surr_main = BAD_NO_EXTRA_SURR_DAC,
3091 /* try to assign DACs to pins and return the resultant badness */
3092 static int alc_auto_fill_dacs(struct hda_codec *codec, int num_outs,
3093 const hda_nid_t *pins, hda_nid_t *dacs,
3094 const struct badness_table *bad)
3096 struct alc_spec *spec = codec->spec;
3097 struct auto_pin_cfg *cfg = &spec->autocfg;
3098 int i, j;
3099 int badness = 0;
3100 hda_nid_t dac;
3102 if (!num_outs)
3103 return 0;
3105 for (i = 0; i < num_outs; i++) {
3106 hda_nid_t pin = pins[i];
3107 if (!dacs[i])
3108 dacs[i] = alc_auto_look_for_dac(codec, pin);
3109 if (!dacs[i] && !i) {
3110 for (j = 1; j < num_outs; j++) {
3111 if (alc_auto_is_dac_reachable(codec, pin, dacs[j])) {
3112 dacs[0] = dacs[j];
3113 dacs[j] = 0;
3114 break;
3118 dac = dacs[i];
3119 if (!dac) {
3120 if (alc_auto_is_dac_reachable(codec, pin, dacs[0]))
3121 dac = dacs[0];
3122 else if (cfg->line_outs > i &&
3123 alc_auto_is_dac_reachable(codec, pin,
3124 spec->private_dac_nids[i]))
3125 dac = spec->private_dac_nids[i];
3126 if (dac) {
3127 if (!i)
3128 badness += bad->shared_primary;
3129 else if (i == 1)
3130 badness += bad->shared_surr;
3131 else
3132 badness += bad->shared_clfe;
3133 } else if (alc_auto_is_dac_reachable(codec, pin,
3134 spec->private_dac_nids[0])) {
3135 dac = spec->private_dac_nids[0];
3136 badness += bad->shared_surr_main;
3137 } else if (!i)
3138 badness += bad->no_primary_dac;
3139 else
3140 badness += bad->no_dac;
3142 if (dac)
3143 badness += eval_shared_vol_badness(codec, pin, dac);
3146 return badness;
3149 static int alc_auto_fill_multi_ios(struct hda_codec *codec,
3150 hda_nid_t reference_pin,
3151 bool hardwired, int offset);
3153 static bool alc_map_singles(struct hda_codec *codec, int outs,
3154 const hda_nid_t *pins, hda_nid_t *dacs)
3156 int i;
3157 bool found = false;
3158 for (i = 0; i < outs; i++) {
3159 if (dacs[i])
3160 continue;
3161 dacs[i] = get_dac_if_single(codec, pins[i]);
3162 if (dacs[i])
3163 found = true;
3165 return found;
3168 /* fill in the dac_nids table from the parsed pin configuration */
3169 static int fill_and_eval_dacs(struct hda_codec *codec,
3170 bool fill_hardwired,
3171 bool fill_mio_first)
3173 struct alc_spec *spec = codec->spec;
3174 struct auto_pin_cfg *cfg = &spec->autocfg;
3175 int i, err, badness;
3177 /* set num_dacs once to full for alc_auto_look_for_dac() */
3178 spec->multiout.num_dacs = cfg->line_outs;
3179 spec->multiout.dac_nids = spec->private_dac_nids;
3180 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
3181 memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid));
3182 memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid));
3183 spec->multi_ios = 0;
3184 clear_vol_marks(codec);
3185 badness = 0;
3187 /* fill hard-wired DACs first */
3188 if (fill_hardwired) {
3189 bool mapped;
3190 do {
3191 mapped = alc_map_singles(codec, cfg->line_outs,
3192 cfg->line_out_pins,
3193 spec->private_dac_nids);
3194 mapped |= alc_map_singles(codec, cfg->hp_outs,
3195 cfg->hp_pins,
3196 spec->multiout.hp_out_nid);
3197 mapped |= alc_map_singles(codec, cfg->speaker_outs,
3198 cfg->speaker_pins,
3199 spec->multiout.extra_out_nid);
3200 if (fill_mio_first && cfg->line_outs == 1 &&
3201 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3202 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], true, 0);
3203 if (!err)
3204 mapped = true;
3206 } while (mapped);
3209 badness += alc_auto_fill_dacs(codec, cfg->line_outs, cfg->line_out_pins,
3210 spec->private_dac_nids,
3211 &main_out_badness);
3213 /* re-count num_dacs and squash invalid entries */
3214 spec->multiout.num_dacs = 0;
3215 for (i = 0; i < cfg->line_outs; i++) {
3216 if (spec->private_dac_nids[i])
3217 spec->multiout.num_dacs++;
3218 else {
3219 memmove(spec->private_dac_nids + i,
3220 spec->private_dac_nids + i + 1,
3221 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
3222 spec->private_dac_nids[cfg->line_outs - 1] = 0;
3226 if (fill_mio_first &&
3227 cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3228 /* try to fill multi-io first */
3229 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
3230 if (err < 0)
3231 return err;
3232 /* we don't count badness at this stage yet */
3235 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
3236 err = alc_auto_fill_dacs(codec, cfg->hp_outs, cfg->hp_pins,
3237 spec->multiout.hp_out_nid,
3238 &extra_out_badness);
3239 if (err < 0)
3240 return err;
3241 badness += err;
3243 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3244 err = alc_auto_fill_dacs(codec, cfg->speaker_outs,
3245 cfg->speaker_pins,
3246 spec->multiout.extra_out_nid,
3247 &extra_out_badness);
3248 if (err < 0)
3249 return err;
3250 badness += err;
3252 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3253 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
3254 if (err < 0)
3255 return err;
3256 badness += err;
3258 if (cfg->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3259 /* try multi-ios with HP + inputs */
3260 int offset = 0;
3261 if (cfg->line_outs >= 3)
3262 offset = 1;
3263 err = alc_auto_fill_multi_ios(codec, cfg->hp_pins[0], false,
3264 offset);
3265 if (err < 0)
3266 return err;
3267 badness += err;
3270 if (spec->multi_ios == 2) {
3271 for (i = 0; i < 2; i++)
3272 spec->private_dac_nids[spec->multiout.num_dacs++] =
3273 spec->multi_io[i].dac;
3274 spec->ext_channel_count = 2;
3275 } else if (spec->multi_ios) {
3276 spec->multi_ios = 0;
3277 badness += BAD_MULTI_IO;
3280 return badness;
3283 #define DEBUG_BADNESS
3285 #ifdef DEBUG_BADNESS
3286 #define debug_badness snd_printdd
3287 #else
3288 #define debug_badness(...)
3289 #endif
3291 static void debug_show_configs(struct alc_spec *spec, struct auto_pin_cfg *cfg)
3293 debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3294 cfg->line_out_pins[0], cfg->line_out_pins[1],
3295 cfg->line_out_pins[2], cfg->line_out_pins[2],
3296 spec->multiout.dac_nids[0],
3297 spec->multiout.dac_nids[1],
3298 spec->multiout.dac_nids[2],
3299 spec->multiout.dac_nids[3]);
3300 if (spec->multi_ios > 0)
3301 debug_badness("multi_ios(%d) = %x/%x : %x/%x\n",
3302 spec->multi_ios,
3303 spec->multi_io[0].pin, spec->multi_io[1].pin,
3304 spec->multi_io[0].dac, spec->multi_io[1].dac);
3305 debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3306 cfg->hp_pins[0], cfg->hp_pins[1],
3307 cfg->hp_pins[2], cfg->hp_pins[2],
3308 spec->multiout.hp_out_nid[0],
3309 spec->multiout.hp_out_nid[1],
3310 spec->multiout.hp_out_nid[2],
3311 spec->multiout.hp_out_nid[3]);
3312 debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3313 cfg->speaker_pins[0], cfg->speaker_pins[1],
3314 cfg->speaker_pins[2], cfg->speaker_pins[3],
3315 spec->multiout.extra_out_nid[0],
3316 spec->multiout.extra_out_nid[1],
3317 spec->multiout.extra_out_nid[2],
3318 spec->multiout.extra_out_nid[3]);
3321 static int alc_auto_fill_dac_nids(struct hda_codec *codec)
3323 struct alc_spec *spec = codec->spec;
3324 struct auto_pin_cfg *cfg = &spec->autocfg;
3325 struct auto_pin_cfg *best_cfg;
3326 int best_badness = INT_MAX;
3327 int badness;
3328 bool fill_hardwired = true, fill_mio_first = true;
3329 bool best_wired = true, best_mio = true;
3330 bool hp_spk_swapped = false;
3332 best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL);
3333 if (!best_cfg)
3334 return -ENOMEM;
3335 *best_cfg = *cfg;
3337 for (;;) {
3338 badness = fill_and_eval_dacs(codec, fill_hardwired,
3339 fill_mio_first);
3340 if (badness < 0) {
3341 kfree(best_cfg);
3342 return badness;
3344 debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n",
3345 cfg->line_out_type, fill_hardwired, fill_mio_first,
3346 badness);
3347 debug_show_configs(spec, cfg);
3348 if (badness < best_badness) {
3349 best_badness = badness;
3350 *best_cfg = *cfg;
3351 best_wired = fill_hardwired;
3352 best_mio = fill_mio_first;
3354 if (!badness)
3355 break;
3356 fill_mio_first = !fill_mio_first;
3357 if (!fill_mio_first)
3358 continue;
3359 fill_hardwired = !fill_hardwired;
3360 if (!fill_hardwired)
3361 continue;
3362 if (hp_spk_swapped)
3363 break;
3364 hp_spk_swapped = true;
3365 if (cfg->speaker_outs > 0 &&
3366 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3367 cfg->hp_outs = cfg->line_outs;
3368 memcpy(cfg->hp_pins, cfg->line_out_pins,
3369 sizeof(cfg->hp_pins));
3370 cfg->line_outs = cfg->speaker_outs;
3371 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3372 sizeof(cfg->speaker_pins));
3373 cfg->speaker_outs = 0;
3374 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3375 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
3376 fill_hardwired = true;
3377 continue;
3379 if (cfg->hp_outs > 0 &&
3380 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3381 cfg->speaker_outs = cfg->line_outs;
3382 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3383 sizeof(cfg->speaker_pins));
3384 cfg->line_outs = cfg->hp_outs;
3385 memcpy(cfg->line_out_pins, cfg->hp_pins,
3386 sizeof(cfg->hp_pins));
3387 cfg->hp_outs = 0;
3388 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3389 cfg->line_out_type = AUTO_PIN_HP_OUT;
3390 fill_hardwired = true;
3391 continue;
3393 break;
3396 if (badness) {
3397 *cfg = *best_cfg;
3398 fill_and_eval_dacs(codec, best_wired, best_mio);
3400 debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n",
3401 cfg->line_out_type, best_wired, best_mio);
3402 debug_show_configs(spec, cfg);
3404 if (cfg->line_out_pins[0])
3405 spec->vmaster_nid =
3406 alc_look_for_out_vol_nid(codec, cfg->line_out_pins[0],
3407 spec->multiout.dac_nids[0]);
3409 /* clear the bitmap flags for creating controls */
3410 clear_vol_marks(codec);
3411 kfree(best_cfg);
3412 return 0;
3415 static int alc_auto_add_vol_ctl(struct hda_codec *codec,
3416 const char *pfx, int cidx,
3417 hda_nid_t nid, unsigned int chs)
3419 struct alc_spec *spec = codec->spec;
3420 unsigned int val;
3421 if (!nid)
3422 return 0;
3423 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3424 if (is_ctl_used(spec->vol_ctls, val) && chs != 2) /* exclude LFE */
3425 return 0;
3426 mark_ctl_usage(spec->vol_ctls, val);
3427 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
3428 val);
3431 static int alc_auto_add_stereo_vol(struct hda_codec *codec,
3432 const char *pfx, int cidx,
3433 hda_nid_t nid)
3435 int chs = 1;
3436 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3437 chs = 3;
3438 return alc_auto_add_vol_ctl(codec, pfx, cidx, nid, chs);
3441 /* create a mute-switch for the given mixer widget;
3442 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3444 static int alc_auto_add_sw_ctl(struct hda_codec *codec,
3445 const char *pfx, int cidx,
3446 hda_nid_t nid, unsigned int chs)
3448 struct alc_spec *spec = codec->spec;
3449 int wid_type;
3450 int type;
3451 unsigned long val;
3452 if (!nid)
3453 return 0;
3454 wid_type = get_wcaps_type(get_wcaps(codec, nid));
3455 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) {
3456 type = ALC_CTL_WIDGET_MUTE;
3457 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3458 } else if (snd_hda_get_num_conns(codec, nid) == 1) {
3459 type = ALC_CTL_WIDGET_MUTE;
3460 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
3461 } else {
3462 type = ALC_CTL_BIND_MUTE;
3463 val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
3465 if (is_ctl_used(spec->sw_ctls, val) && chs != 2) /* exclude LFE */
3466 return 0;
3467 mark_ctl_usage(spec->sw_ctls, val);
3468 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
3471 static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
3472 int cidx, hda_nid_t nid)
3474 int chs = 1;
3475 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3476 chs = 3;
3477 return alc_auto_add_sw_ctl(codec, pfx, cidx, nid, chs);
3480 static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3481 hda_nid_t pin, hda_nid_t dac)
3483 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3484 if (nid_has_mute(codec, pin, HDA_OUTPUT))
3485 return pin;
3486 else if (mix && nid_has_mute(codec, mix, HDA_INPUT))
3487 return mix;
3488 else if (nid_has_mute(codec, dac, HDA_OUTPUT))
3489 return dac;
3490 return 0;
3493 static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3494 hda_nid_t pin, hda_nid_t dac)
3496 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3497 if (nid_has_volume(codec, dac, HDA_OUTPUT))
3498 return dac;
3499 else if (nid_has_volume(codec, mix, HDA_OUTPUT))
3500 return mix;
3501 else if (nid_has_volume(codec, pin, HDA_OUTPUT))
3502 return pin;
3503 return 0;
3506 /* add playback controls from the parsed DAC table */
3507 static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
3508 const struct auto_pin_cfg *cfg)
3510 struct alc_spec *spec = codec->spec;
3511 int i, err, noutputs;
3513 noutputs = cfg->line_outs;
3514 if (spec->multi_ios > 0 && cfg->line_outs < 3)
3515 noutputs += spec->multi_ios;
3517 for (i = 0; i < noutputs; i++) {
3518 const char *name;
3519 int index;
3520 hda_nid_t dac, pin;
3521 hda_nid_t sw, vol;
3523 dac = spec->multiout.dac_nids[i];
3524 if (!dac)
3525 continue;
3526 if (i >= cfg->line_outs) {
3527 pin = spec->multi_io[i - 1].pin;
3528 index = 0;
3529 name = channel_name[i];
3530 } else {
3531 pin = cfg->line_out_pins[i];
3532 name = alc_get_line_out_pfx(spec, i, true, &index);
3535 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3536 vol = alc_look_for_out_vol_nid(codec, pin, dac);
3537 if (!name || !strcmp(name, "CLFE")) {
3538 /* Center/LFE */
3539 err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1);
3540 if (err < 0)
3541 return err;
3542 err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2);
3543 if (err < 0)
3544 return err;
3545 err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1);
3546 if (err < 0)
3547 return err;
3548 err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2);
3549 if (err < 0)
3550 return err;
3551 } else {
3552 err = alc_auto_add_stereo_vol(codec, name, index, vol);
3553 if (err < 0)
3554 return err;
3555 err = alc_auto_add_stereo_sw(codec, name, index, sw);
3556 if (err < 0)
3557 return err;
3560 return 0;
3563 static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
3564 hda_nid_t dac, const char *pfx,
3565 int cidx)
3567 struct alc_spec *spec = codec->spec;
3568 hda_nid_t sw, vol;
3569 int err;
3571 if (!dac) {
3572 unsigned int val;
3573 /* the corresponding DAC is already occupied */
3574 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
3575 return 0; /* no way */
3576 /* create a switch only */
3577 val = HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT);
3578 if (is_ctl_used(spec->sw_ctls, val))
3579 return 0; /* already created */
3580 mark_ctl_usage(spec->sw_ctls, val);
3581 return __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, cidx, val);
3584 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3585 vol = alc_look_for_out_vol_nid(codec, pin, dac);
3586 err = alc_auto_add_stereo_vol(codec, pfx, cidx, vol);
3587 if (err < 0)
3588 return err;
3589 err = alc_auto_add_stereo_sw(codec, pfx, cidx, sw);
3590 if (err < 0)
3591 return err;
3592 return 0;
3595 static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3596 unsigned int nums,
3597 struct hda_ctl_ops *ops)
3599 struct alc_spec *spec = codec->spec;
3600 struct hda_bind_ctls **ctlp, *ctl;
3601 ctlp = snd_array_new(&spec->bind_ctls);
3602 if (!ctlp)
3603 return NULL;
3604 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3605 *ctlp = ctl;
3606 if (ctl)
3607 ctl->ops = ops;
3608 return ctl;
3611 /* add playback controls for speaker and HP outputs */
3612 static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3613 const hda_nid_t *pins,
3614 const hda_nid_t *dacs,
3615 const char *pfx)
3617 struct alc_spec *spec = codec->spec;
3618 struct hda_bind_ctls *ctl;
3619 char name[32];
3620 int i, n, err;
3622 if (!num_pins || !pins[0])
3623 return 0;
3625 if (num_pins == 1) {
3626 hda_nid_t dac = *dacs;
3627 if (!dac)
3628 dac = spec->multiout.dac_nids[0];
3629 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
3632 for (i = 0; i < num_pins; i++) {
3633 hda_nid_t dac;
3634 if (dacs[num_pins - 1])
3635 dac = dacs[i]; /* with individual volumes */
3636 else
3637 dac = 0;
3638 if (num_pins == 2 && i == 1 && !strcmp(pfx, "Speaker")) {
3639 err = alc_auto_create_extra_out(codec, pins[i], dac,
3640 "Bass Speaker", 0);
3641 } else if (num_pins >= 3) {
3642 snprintf(name, sizeof(name), "%s %s",
3643 pfx, channel_name[i]);
3644 err = alc_auto_create_extra_out(codec, pins[i], dac,
3645 name, 0);
3646 } else {
3647 err = alc_auto_create_extra_out(codec, pins[i], dac,
3648 pfx, i);
3650 if (err < 0)
3651 return err;
3653 if (dacs[num_pins - 1])
3654 return 0;
3656 /* Let's create a bind-controls for volumes */
3657 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3658 if (!ctl)
3659 return -ENOMEM;
3660 n = 0;
3661 for (i = 0; i < num_pins; i++) {
3662 hda_nid_t vol;
3663 if (!pins[i] || !dacs[i])
3664 continue;
3665 vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]);
3666 if (vol)
3667 ctl->values[n++] =
3668 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3670 if (n) {
3671 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3672 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3673 if (err < 0)
3674 return err;
3676 return 0;
3679 static int alc_auto_create_hp_out(struct hda_codec *codec)
3681 struct alc_spec *spec = codec->spec;
3682 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3683 spec->autocfg.hp_pins,
3684 spec->multiout.hp_out_nid,
3685 "Headphone");
3688 static int alc_auto_create_speaker_out(struct hda_codec *codec)
3690 struct alc_spec *spec = codec->spec;
3691 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3692 spec->autocfg.speaker_pins,
3693 spec->multiout.extra_out_nid,
3694 "Speaker");
3697 static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
3698 hda_nid_t pin, int pin_type,
3699 hda_nid_t dac)
3701 int i, num;
3702 hda_nid_t nid, mix = 0;
3703 hda_nid_t srcs[HDA_MAX_CONNECTIONS];
3705 alc_set_pin_output(codec, pin, pin_type);
3706 nid = alc_go_down_to_selector(codec, pin);
3707 num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
3708 for (i = 0; i < num; i++) {
3709 if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
3710 continue;
3711 mix = srcs[i];
3712 break;
3714 if (!mix)
3715 return;
3717 /* need the manual connection? */
3718 if (num > 1)
3719 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
3720 /* unmute mixer widget inputs */
3721 if (nid_has_mute(codec, mix, HDA_INPUT)) {
3722 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3723 AMP_IN_UNMUTE(0));
3724 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3725 AMP_IN_UNMUTE(1));
3727 /* initialize volume */
3728 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3729 if (nid)
3730 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3731 AMP_OUT_ZERO);
3733 /* unmute DAC if it's not assigned to a mixer */
3734 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3735 if (nid == mix && nid_has_mute(codec, dac, HDA_OUTPUT))
3736 snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3737 AMP_OUT_ZERO);
3740 static void alc_auto_init_multi_out(struct hda_codec *codec)
3742 struct alc_spec *spec = codec->spec;
3743 int pin_type = get_pin_type(spec->autocfg.line_out_type);
3744 int i;
3746 for (i = 0; i <= HDA_SIDE; i++) {
3747 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3748 if (nid)
3749 alc_auto_set_output_and_unmute(codec, nid, pin_type,
3750 spec->multiout.dac_nids[i]);
3754 static void alc_auto_init_extra_out(struct hda_codec *codec)
3756 struct alc_spec *spec = codec->spec;
3757 int i;
3758 hda_nid_t pin, dac;
3760 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3761 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3762 break;
3763 pin = spec->autocfg.hp_pins[i];
3764 if (!pin)
3765 break;
3766 dac = spec->multiout.hp_out_nid[i];
3767 if (!dac) {
3768 if (i > 0 && spec->multiout.hp_out_nid[0])
3769 dac = spec->multiout.hp_out_nid[0];
3770 else
3771 dac = spec->multiout.dac_nids[0];
3773 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
3775 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3776 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3777 break;
3778 pin = spec->autocfg.speaker_pins[i];
3779 if (!pin)
3780 break;
3781 dac = spec->multiout.extra_out_nid[i];
3782 if (!dac) {
3783 if (i > 0 && spec->multiout.extra_out_nid[0])
3784 dac = spec->multiout.extra_out_nid[0];
3785 else
3786 dac = spec->multiout.dac_nids[0];
3788 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
3792 /* check whether the given pin can be a multi-io pin */
3793 static bool can_be_multiio_pin(struct hda_codec *codec,
3794 unsigned int location, hda_nid_t nid)
3796 unsigned int defcfg, caps;
3798 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3799 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3800 return false;
3801 if (location && get_defcfg_location(defcfg) != location)
3802 return false;
3803 caps = snd_hda_query_pin_caps(codec, nid);
3804 if (!(caps & AC_PINCAP_OUT))
3805 return false;
3806 return true;
3810 * multi-io helper
3812 * When hardwired is set, try to fill ony hardwired pins, and returns
3813 * zero if any pins are filled, non-zero if nothing found.
3814 * When hardwired is off, try to fill possible input pins, and returns
3815 * the badness value.
3817 static int alc_auto_fill_multi_ios(struct hda_codec *codec,
3818 hda_nid_t reference_pin,
3819 bool hardwired, int offset)
3821 struct alc_spec *spec = codec->spec;
3822 struct auto_pin_cfg *cfg = &spec->autocfg;
3823 int type, i, j, dacs, num_pins, old_pins;
3824 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
3825 unsigned int location = get_defcfg_location(defcfg);
3826 int badness = 0;
3828 old_pins = spec->multi_ios;
3829 if (old_pins >= 2)
3830 goto end_fill;
3832 num_pins = 0;
3833 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3834 for (i = 0; i < cfg->num_inputs; i++) {
3835 if (cfg->inputs[i].type != type)
3836 continue;
3837 if (can_be_multiio_pin(codec, location,
3838 cfg->inputs[i].pin))
3839 num_pins++;
3842 if (num_pins < 2)
3843 goto end_fill;
3845 dacs = spec->multiout.num_dacs;
3846 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3847 for (i = 0; i < cfg->num_inputs; i++) {
3848 hda_nid_t nid = cfg->inputs[i].pin;
3849 hda_nid_t dac = 0;
3851 if (cfg->inputs[i].type != type)
3852 continue;
3853 if (!can_be_multiio_pin(codec, location, nid))
3854 continue;
3855 for (j = 0; j < spec->multi_ios; j++) {
3856 if (nid == spec->multi_io[j].pin)
3857 break;
3859 if (j < spec->multi_ios)
3860 continue;
3862 if (offset && offset + spec->multi_ios < dacs) {
3863 dac = spec->private_dac_nids[offset + spec->multi_ios];
3864 if (!alc_auto_is_dac_reachable(codec, nid, dac))
3865 dac = 0;
3867 if (hardwired)
3868 dac = get_dac_if_single(codec, nid);
3869 else if (!dac)
3870 dac = alc_auto_look_for_dac(codec, nid);
3871 if (!dac) {
3872 badness++;
3873 continue;
3875 spec->multi_io[spec->multi_ios].pin = nid;
3876 spec->multi_io[spec->multi_ios].dac = dac;
3877 spec->multi_ios++;
3878 if (spec->multi_ios >= 2)
3879 break;
3882 end_fill:
3883 if (badness)
3884 badness = BAD_MULTI_IO;
3885 if (old_pins == spec->multi_ios) {
3886 if (hardwired)
3887 return 1; /* nothing found */
3888 else
3889 return badness; /* no badness if nothing found */
3891 if (!hardwired && spec->multi_ios < 2) {
3892 spec->multi_ios = old_pins;
3893 return badness;
3896 return 0;
3899 static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
3900 struct snd_ctl_elem_info *uinfo)
3902 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3903 struct alc_spec *spec = codec->spec;
3905 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3906 uinfo->count = 1;
3907 uinfo->value.enumerated.items = spec->multi_ios + 1;
3908 if (uinfo->value.enumerated.item > spec->multi_ios)
3909 uinfo->value.enumerated.item = spec->multi_ios;
3910 sprintf(uinfo->value.enumerated.name, "%dch",
3911 (uinfo->value.enumerated.item + 1) * 2);
3912 return 0;
3915 static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
3916 struct snd_ctl_elem_value *ucontrol)
3918 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3919 struct alc_spec *spec = codec->spec;
3920 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
3921 return 0;
3924 static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
3926 struct alc_spec *spec = codec->spec;
3927 hda_nid_t nid = spec->multi_io[idx].pin;
3929 if (!spec->multi_io[idx].ctl_in)
3930 spec->multi_io[idx].ctl_in =
3931 snd_hda_codec_read(codec, nid, 0,
3932 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3933 if (output) {
3934 snd_hda_set_pin_ctl_cache(codec, nid, PIN_OUT);
3935 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3936 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3937 HDA_AMP_MUTE, 0);
3938 alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
3939 } else {
3940 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3941 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3942 HDA_AMP_MUTE, HDA_AMP_MUTE);
3943 snd_hda_set_pin_ctl_cache(codec, nid,
3944 spec->multi_io[idx].ctl_in);
3946 return 0;
3949 static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
3950 struct snd_ctl_elem_value *ucontrol)
3952 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3953 struct alc_spec *spec = codec->spec;
3954 int i, ch;
3956 ch = ucontrol->value.enumerated.item[0];
3957 if (ch < 0 || ch > spec->multi_ios)
3958 return -EINVAL;
3959 if (ch == (spec->ext_channel_count - 1) / 2)
3960 return 0;
3961 spec->ext_channel_count = (ch + 1) * 2;
3962 for (i = 0; i < spec->multi_ios; i++)
3963 alc_set_multi_io(codec, i, i < ch);
3964 spec->multiout.max_channels = max(spec->ext_channel_count,
3965 spec->const_channel_count);
3966 if (spec->need_dac_fix)
3967 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
3968 return 1;
3971 static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
3972 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3973 .name = "Channel Mode",
3974 .info = alc_auto_ch_mode_info,
3975 .get = alc_auto_ch_mode_get,
3976 .put = alc_auto_ch_mode_put,
3979 static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
3981 struct alc_spec *spec = codec->spec;
3983 if (spec->multi_ios > 0) {
3984 if (!alc_kcontrol_new(spec, "Channel Mode",
3985 &alc_auto_channel_mode_enum))
3986 return -ENOMEM;
3988 return 0;
3991 /* filter out invalid adc_nids (and capsrc_nids) that don't give all
3992 * active input pins
3994 static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
3996 struct alc_spec *spec = codec->spec;
3997 const struct hda_input_mux *imux;
3998 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3999 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4000 int i, n, nums;
4002 imux = spec->input_mux;
4003 if (!imux)
4004 return;
4005 if (spec->dyn_adc_switch)
4006 return;
4008 again:
4009 nums = 0;
4010 for (n = 0; n < spec->num_adc_nids; n++) {
4011 hda_nid_t cap = spec->private_capsrc_nids[n];
4012 int num_conns = snd_hda_get_num_conns(codec, cap);
4013 for (i = 0; i < imux->num_items; i++) {
4014 hda_nid_t pin = spec->imux_pins[i];
4015 if (pin) {
4016 if (get_connection_index(codec, cap, pin) < 0)
4017 break;
4018 } else if (num_conns <= imux->items[i].index)
4019 break;
4021 if (i >= imux->num_items) {
4022 adc_nids[nums] = spec->private_adc_nids[n];
4023 capsrc_nids[nums++] = cap;
4026 if (!nums) {
4027 /* check whether ADC-switch is possible */
4028 if (!alc_check_dyn_adc_switch(codec)) {
4029 if (spec->shared_mic_hp) {
4030 spec->shared_mic_hp = 0;
4031 spec->private_imux[0].num_items = 1;
4032 goto again;
4034 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
4035 " using fallback 0x%x\n",
4036 codec->chip_name, spec->private_adc_nids[0]);
4037 spec->num_adc_nids = 1;
4038 spec->auto_mic = 0;
4039 return;
4041 } else if (nums != spec->num_adc_nids) {
4042 memcpy(spec->private_adc_nids, adc_nids,
4043 nums * sizeof(hda_nid_t));
4044 memcpy(spec->private_capsrc_nids, capsrc_nids,
4045 nums * sizeof(hda_nid_t));
4046 spec->num_adc_nids = nums;
4049 if (spec->auto_mic)
4050 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
4051 else if (spec->input_mux->num_items == 1 || spec->shared_mic_hp)
4052 spec->num_adc_nids = 1; /* reduce to a single ADC */
4056 * initialize ADC paths
4058 static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
4060 struct alc_spec *spec = codec->spec;
4061 hda_nid_t nid;
4063 nid = spec->adc_nids[adc_idx];
4064 /* mute ADC */
4065 if (nid_has_mute(codec, nid, HDA_INPUT)) {
4066 snd_hda_codec_write(codec, nid, 0,
4067 AC_VERB_SET_AMP_GAIN_MUTE,
4068 AMP_IN_MUTE(0));
4069 return;
4071 if (!spec->capsrc_nids)
4072 return;
4073 nid = spec->capsrc_nids[adc_idx];
4074 if (nid_has_mute(codec, nid, HDA_OUTPUT))
4075 snd_hda_codec_write(codec, nid, 0,
4076 AC_VERB_SET_AMP_GAIN_MUTE,
4077 AMP_OUT_MUTE);
4080 static void alc_auto_init_input_src(struct hda_codec *codec)
4082 struct alc_spec *spec = codec->spec;
4083 int c, nums;
4085 for (c = 0; c < spec->num_adc_nids; c++)
4086 alc_auto_init_adc(codec, c);
4087 if (spec->dyn_adc_switch)
4088 nums = 1;
4089 else
4090 nums = spec->num_adc_nids;
4091 for (c = 0; c < nums; c++)
4092 alc_mux_select(codec, c, spec->cur_mux[c], true);
4095 /* add mic boosts if needed */
4096 static int alc_auto_add_mic_boost(struct hda_codec *codec)
4098 struct alc_spec *spec = codec->spec;
4099 struct auto_pin_cfg *cfg = &spec->autocfg;
4100 int i, err;
4101 int type_idx = 0;
4102 hda_nid_t nid;
4103 const char *prev_label = NULL;
4105 for (i = 0; i < cfg->num_inputs; i++) {
4106 if (cfg->inputs[i].type > AUTO_PIN_MIC)
4107 break;
4108 nid = cfg->inputs[i].pin;
4109 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
4110 const char *label;
4111 char boost_label[32];
4113 label = hda_get_autocfg_input_label(codec, cfg, i);
4114 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
4115 label = "Headphone Mic";
4116 if (prev_label && !strcmp(label, prev_label))
4117 type_idx++;
4118 else
4119 type_idx = 0;
4120 prev_label = label;
4122 snprintf(boost_label, sizeof(boost_label),
4123 "%s Boost Volume", label);
4124 err = add_control(spec, ALC_CTL_WIDGET_VOL,
4125 boost_label, type_idx,
4126 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
4127 if (err < 0)
4128 return err;
4131 return 0;
4134 /* select or unmute the given capsrc route */
4135 static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
4136 int idx)
4138 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
4139 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
4140 HDA_AMP_MUTE, 0);
4141 } else if (snd_hda_get_num_conns(codec, cap) > 1) {
4142 snd_hda_codec_write_cache(codec, cap, 0,
4143 AC_VERB_SET_CONNECT_SEL, idx);
4147 /* set the default connection to that pin */
4148 static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
4150 struct alc_spec *spec = codec->spec;
4151 int i;
4153 if (!pin)
4154 return 0;
4155 for (i = 0; i < spec->num_adc_nids; i++) {
4156 hda_nid_t cap = get_capsrc(spec, i);
4157 int idx;
4159 idx = get_connection_index(codec, cap, pin);
4160 if (idx < 0)
4161 continue;
4162 select_or_unmute_capsrc(codec, cap, idx);
4163 return i; /* return the found index */
4165 return -1; /* not found */
4168 /* initialize some special cases for input sources */
4169 static void alc_init_special_input_src(struct hda_codec *codec)
4171 struct alc_spec *spec = codec->spec;
4172 int i;
4174 for (i = 0; i < spec->autocfg.num_inputs; i++)
4175 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
4178 /* assign appropriate capture mixers */
4179 static void set_capture_mixer(struct hda_codec *codec)
4181 struct alc_spec *spec = codec->spec;
4182 static const struct snd_kcontrol_new *caps[2][3] = {
4183 { alc_capture_mixer_nosrc1,
4184 alc_capture_mixer_nosrc2,
4185 alc_capture_mixer_nosrc3 },
4186 { alc_capture_mixer1,
4187 alc_capture_mixer2,
4188 alc_capture_mixer3 },
4191 /* check whether either of ADC or MUX has a volume control */
4192 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
4193 if (!spec->capsrc_nids)
4194 return; /* no volume */
4195 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
4196 return; /* no volume in capsrc, too */
4197 spec->vol_in_capsrc = 1;
4200 if (spec->num_adc_nids > 0) {
4201 int mux = 0;
4202 int num_adcs = 0;
4204 if (spec->input_mux && spec->input_mux->num_items > 1)
4205 mux = 1;
4206 if (spec->auto_mic) {
4207 num_adcs = 1;
4208 mux = 0;
4209 } else if (spec->dyn_adc_switch)
4210 num_adcs = 1;
4211 if (!num_adcs) {
4212 if (spec->num_adc_nids > 3)
4213 spec->num_adc_nids = 3;
4214 else if (!spec->num_adc_nids)
4215 return;
4216 num_adcs = spec->num_adc_nids;
4218 spec->cap_mixer = caps[mux][num_adcs - 1];
4223 * standard auto-parser initializations
4225 static void alc_auto_init_std(struct hda_codec *codec)
4227 alc_auto_init_multi_out(codec);
4228 alc_auto_init_extra_out(codec);
4229 alc_auto_init_analog_input(codec);
4230 alc_auto_init_input_src(codec);
4231 alc_auto_init_digital(codec);
4232 alc_inithook(codec);
4236 * Digital-beep handlers
4238 #ifdef CONFIG_SND_HDA_INPUT_BEEP
4239 #define set_beep_amp(spec, nid, idx, dir) \
4240 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4242 static const struct snd_pci_quirk beep_white_list[] = {
4243 SND_PCI_QUIRK(0x1043, 0x103c, "ASUS", 1),
4244 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
4245 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
4246 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
4247 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
4248 SND_PCI_QUIRK(0x1458, 0xa002, "GA-MA790X", 1),
4249 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
4253 static inline int has_cdefine_beep(struct hda_codec *codec)
4255 struct alc_spec *spec = codec->spec;
4256 const struct snd_pci_quirk *q;
4257 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
4258 if (q)
4259 return q->value;
4260 return spec->cdefine.enable_pcbeep;
4262 #else
4263 #define set_beep_amp(spec, nid, idx, dir) /* NOP */
4264 #define has_cdefine_beep(codec) 0
4265 #endif
4267 /* parse the BIOS configuration and set up the alc_spec */
4268 /* return 1 if successful, 0 if the proper config is not found,
4269 * or a negative error code
4271 static int alc_parse_auto_config(struct hda_codec *codec,
4272 const hda_nid_t *ignore_nids,
4273 const hda_nid_t *ssid_nids)
4275 struct alc_spec *spec = codec->spec;
4276 struct auto_pin_cfg *cfg = &spec->autocfg;
4277 int err;
4279 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
4280 spec->parse_flags);
4281 if (err < 0)
4282 return err;
4283 if (!cfg->line_outs) {
4284 if (cfg->dig_outs || cfg->dig_in_pin) {
4285 spec->multiout.max_channels = 2;
4286 spec->no_analog = 1;
4287 goto dig_only;
4289 return 0; /* can't find valid BIOS pin config */
4292 if (!spec->no_primary_hp &&
4293 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
4294 cfg->line_outs <= cfg->hp_outs) {
4295 /* use HP as primary out */
4296 cfg->speaker_outs = cfg->line_outs;
4297 memcpy(cfg->speaker_pins, cfg->line_out_pins,
4298 sizeof(cfg->speaker_pins));
4299 cfg->line_outs = cfg->hp_outs;
4300 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
4301 cfg->hp_outs = 0;
4302 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
4303 cfg->line_out_type = AUTO_PIN_HP_OUT;
4306 err = alc_auto_fill_dac_nids(codec);
4307 if (err < 0)
4308 return err;
4309 err = alc_auto_add_multi_channel_mode(codec);
4310 if (err < 0)
4311 return err;
4312 err = alc_auto_create_multi_out_ctls(codec, cfg);
4313 if (err < 0)
4314 return err;
4315 err = alc_auto_create_hp_out(codec);
4316 if (err < 0)
4317 return err;
4318 err = alc_auto_create_speaker_out(codec);
4319 if (err < 0)
4320 return err;
4321 err = alc_auto_create_shared_input(codec);
4322 if (err < 0)
4323 return err;
4324 err = alc_auto_create_input_ctls(codec);
4325 if (err < 0)
4326 return err;
4328 /* check the multiple speaker pins */
4329 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
4330 spec->const_channel_count = cfg->line_outs * 2;
4331 else
4332 spec->const_channel_count = cfg->speaker_outs * 2;
4334 if (spec->multi_ios > 0)
4335 spec->multiout.max_channels = max(spec->ext_channel_count,
4336 spec->const_channel_count);
4337 else
4338 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4340 dig_only:
4341 alc_auto_parse_digital(codec);
4343 if (!spec->no_analog)
4344 alc_remove_invalid_adc_nids(codec);
4346 if (ssid_nids)
4347 alc_ssid_check(codec, ssid_nids);
4349 if (!spec->no_analog) {
4350 err = alc_auto_check_switches(codec);
4351 if (err < 0)
4352 return err;
4353 err = alc_auto_add_mic_boost(codec);
4354 if (err < 0)
4355 return err;
4358 if (spec->kctls.list)
4359 add_mixer(spec, spec->kctls.list);
4361 if (!spec->no_analog && !spec->cap_mixer)
4362 set_capture_mixer(codec);
4364 return 1;
4367 /* common preparation job for alc_spec */
4368 static int alc_alloc_spec(struct hda_codec *codec, hda_nid_t mixer_nid)
4370 struct alc_spec *spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4371 int err;
4373 if (!spec)
4374 return -ENOMEM;
4375 codec->spec = spec;
4376 codec->single_adc_amp = 1;
4377 spec->mixer_nid = mixer_nid;
4378 snd_hda_gen_init(&spec->gen);
4379 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
4380 snd_array_init(&spec->bind_ctls, sizeof(struct hda_bind_ctls *), 8);
4382 err = alc_codec_rename_from_preset(codec);
4383 if (err < 0) {
4384 kfree(spec);
4385 return err;
4387 return 0;
4390 static int alc880_parse_auto_config(struct hda_codec *codec)
4392 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
4393 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4394 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
4398 * ALC880 fix-ups
4400 enum {
4401 ALC880_FIXUP_GPIO1,
4402 ALC880_FIXUP_GPIO2,
4403 ALC880_FIXUP_MEDION_RIM,
4404 ALC880_FIXUP_LG,
4405 ALC880_FIXUP_W810,
4406 ALC880_FIXUP_EAPD_COEF,
4407 ALC880_FIXUP_TCL_S700,
4408 ALC880_FIXUP_VOL_KNOB,
4409 ALC880_FIXUP_FUJITSU,
4410 ALC880_FIXUP_F1734,
4411 ALC880_FIXUP_UNIWILL,
4412 ALC880_FIXUP_UNIWILL_DIG,
4413 ALC880_FIXUP_Z71V,
4414 ALC880_FIXUP_3ST_BASE,
4415 ALC880_FIXUP_3ST,
4416 ALC880_FIXUP_3ST_DIG,
4417 ALC880_FIXUP_5ST_BASE,
4418 ALC880_FIXUP_5ST,
4419 ALC880_FIXUP_5ST_DIG,
4420 ALC880_FIXUP_6ST_BASE,
4421 ALC880_FIXUP_6ST,
4422 ALC880_FIXUP_6ST_DIG,
4425 /* enable the volume-knob widget support on NID 0x21 */
4426 static void alc880_fixup_vol_knob(struct hda_codec *codec,
4427 const struct alc_fixup *fix, int action)
4429 if (action == ALC_FIXUP_ACT_PROBE)
4430 snd_hda_jack_detect_enable_callback(codec, 0x21, ALC_DCVOL_EVENT, alc_update_knob_master);
4433 static const struct alc_fixup alc880_fixups[] = {
4434 [ALC880_FIXUP_GPIO1] = {
4435 .type = ALC_FIXUP_VERBS,
4436 .v.verbs = alc_gpio1_init_verbs,
4438 [ALC880_FIXUP_GPIO2] = {
4439 .type = ALC_FIXUP_VERBS,
4440 .v.verbs = alc_gpio2_init_verbs,
4442 [ALC880_FIXUP_MEDION_RIM] = {
4443 .type = ALC_FIXUP_VERBS,
4444 .v.verbs = (const struct hda_verb[]) {
4445 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4446 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4449 .chained = true,
4450 .chain_id = ALC880_FIXUP_GPIO2,
4452 [ALC880_FIXUP_LG] = {
4453 .type = ALC_FIXUP_PINS,
4454 .v.pins = (const struct alc_pincfg[]) {
4455 /* disable bogus unused pins */
4456 { 0x16, 0x411111f0 },
4457 { 0x18, 0x411111f0 },
4458 { 0x1a, 0x411111f0 },
4462 [ALC880_FIXUP_W810] = {
4463 .type = ALC_FIXUP_PINS,
4464 .v.pins = (const struct alc_pincfg[]) {
4465 /* disable bogus unused pins */
4466 { 0x17, 0x411111f0 },
4469 .chained = true,
4470 .chain_id = ALC880_FIXUP_GPIO2,
4472 [ALC880_FIXUP_EAPD_COEF] = {
4473 .type = ALC_FIXUP_VERBS,
4474 .v.verbs = (const struct hda_verb[]) {
4475 /* change to EAPD mode */
4476 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4477 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4481 [ALC880_FIXUP_TCL_S700] = {
4482 .type = ALC_FIXUP_VERBS,
4483 .v.verbs = (const struct hda_verb[]) {
4484 /* change to EAPD mode */
4485 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4486 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4489 .chained = true,
4490 .chain_id = ALC880_FIXUP_GPIO2,
4492 [ALC880_FIXUP_VOL_KNOB] = {
4493 .type = ALC_FIXUP_FUNC,
4494 .v.func = alc880_fixup_vol_knob,
4496 [ALC880_FIXUP_FUJITSU] = {
4497 /* override all pins as BIOS on old Amilo is broken */
4498 .type = ALC_FIXUP_PINS,
4499 .v.pins = (const struct alc_pincfg[]) {
4500 { 0x14, 0x0121411f }, /* HP */
4501 { 0x15, 0x99030120 }, /* speaker */
4502 { 0x16, 0x99030130 }, /* bass speaker */
4503 { 0x17, 0x411111f0 }, /* N/A */
4504 { 0x18, 0x411111f0 }, /* N/A */
4505 { 0x19, 0x01a19950 }, /* mic-in */
4506 { 0x1a, 0x411111f0 }, /* N/A */
4507 { 0x1b, 0x411111f0 }, /* N/A */
4508 { 0x1c, 0x411111f0 }, /* N/A */
4509 { 0x1d, 0x411111f0 }, /* N/A */
4510 { 0x1e, 0x01454140 }, /* SPDIF out */
4513 .chained = true,
4514 .chain_id = ALC880_FIXUP_VOL_KNOB,
4516 [ALC880_FIXUP_F1734] = {
4517 /* almost compatible with FUJITSU, but no bass and SPDIF */
4518 .type = ALC_FIXUP_PINS,
4519 .v.pins = (const struct alc_pincfg[]) {
4520 { 0x14, 0x0121411f }, /* HP */
4521 { 0x15, 0x99030120 }, /* speaker */
4522 { 0x16, 0x411111f0 }, /* N/A */
4523 { 0x17, 0x411111f0 }, /* N/A */
4524 { 0x18, 0x411111f0 }, /* N/A */
4525 { 0x19, 0x01a19950 }, /* mic-in */
4526 { 0x1a, 0x411111f0 }, /* N/A */
4527 { 0x1b, 0x411111f0 }, /* N/A */
4528 { 0x1c, 0x411111f0 }, /* N/A */
4529 { 0x1d, 0x411111f0 }, /* N/A */
4530 { 0x1e, 0x411111f0 }, /* N/A */
4533 .chained = true,
4534 .chain_id = ALC880_FIXUP_VOL_KNOB,
4536 [ALC880_FIXUP_UNIWILL] = {
4537 /* need to fix HP and speaker pins to be parsed correctly */
4538 .type = ALC_FIXUP_PINS,
4539 .v.pins = (const struct alc_pincfg[]) {
4540 { 0x14, 0x0121411f }, /* HP */
4541 { 0x15, 0x99030120 }, /* speaker */
4542 { 0x16, 0x99030130 }, /* bass speaker */
4546 [ALC880_FIXUP_UNIWILL_DIG] = {
4547 .type = ALC_FIXUP_PINS,
4548 .v.pins = (const struct alc_pincfg[]) {
4549 /* disable bogus unused pins */
4550 { 0x17, 0x411111f0 },
4551 { 0x19, 0x411111f0 },
4552 { 0x1b, 0x411111f0 },
4553 { 0x1f, 0x411111f0 },
4557 [ALC880_FIXUP_Z71V] = {
4558 .type = ALC_FIXUP_PINS,
4559 .v.pins = (const struct alc_pincfg[]) {
4560 /* set up the whole pins as BIOS is utterly broken */
4561 { 0x14, 0x99030120 }, /* speaker */
4562 { 0x15, 0x0121411f }, /* HP */
4563 { 0x16, 0x411111f0 }, /* N/A */
4564 { 0x17, 0x411111f0 }, /* N/A */
4565 { 0x18, 0x01a19950 }, /* mic-in */
4566 { 0x19, 0x411111f0 }, /* N/A */
4567 { 0x1a, 0x01813031 }, /* line-in */
4568 { 0x1b, 0x411111f0 }, /* N/A */
4569 { 0x1c, 0x411111f0 }, /* N/A */
4570 { 0x1d, 0x411111f0 }, /* N/A */
4571 { 0x1e, 0x0144111e }, /* SPDIF */
4575 [ALC880_FIXUP_3ST_BASE] = {
4576 .type = ALC_FIXUP_PINS,
4577 .v.pins = (const struct alc_pincfg[]) {
4578 { 0x14, 0x01014010 }, /* line-out */
4579 { 0x15, 0x411111f0 }, /* N/A */
4580 { 0x16, 0x411111f0 }, /* N/A */
4581 { 0x17, 0x411111f0 }, /* N/A */
4582 { 0x18, 0x01a19c30 }, /* mic-in */
4583 { 0x19, 0x0121411f }, /* HP */
4584 { 0x1a, 0x01813031 }, /* line-in */
4585 { 0x1b, 0x02a19c40 }, /* front-mic */
4586 { 0x1c, 0x411111f0 }, /* N/A */
4587 { 0x1d, 0x411111f0 }, /* N/A */
4588 /* 0x1e is filled in below */
4589 { 0x1f, 0x411111f0 }, /* N/A */
4593 [ALC880_FIXUP_3ST] = {
4594 .type = ALC_FIXUP_PINS,
4595 .v.pins = (const struct alc_pincfg[]) {
4596 { 0x1e, 0x411111f0 }, /* N/A */
4599 .chained = true,
4600 .chain_id = ALC880_FIXUP_3ST_BASE,
4602 [ALC880_FIXUP_3ST_DIG] = {
4603 .type = ALC_FIXUP_PINS,
4604 .v.pins = (const struct alc_pincfg[]) {
4605 { 0x1e, 0x0144111e }, /* SPDIF */
4608 .chained = true,
4609 .chain_id = ALC880_FIXUP_3ST_BASE,
4611 [ALC880_FIXUP_5ST_BASE] = {
4612 .type = ALC_FIXUP_PINS,
4613 .v.pins = (const struct alc_pincfg[]) {
4614 { 0x14, 0x01014010 }, /* front */
4615 { 0x15, 0x411111f0 }, /* N/A */
4616 { 0x16, 0x01011411 }, /* CLFE */
4617 { 0x17, 0x01016412 }, /* surr */
4618 { 0x18, 0x01a19c30 }, /* mic-in */
4619 { 0x19, 0x0121411f }, /* HP */
4620 { 0x1a, 0x01813031 }, /* line-in */
4621 { 0x1b, 0x02a19c40 }, /* front-mic */
4622 { 0x1c, 0x411111f0 }, /* N/A */
4623 { 0x1d, 0x411111f0 }, /* N/A */
4624 /* 0x1e is filled in below */
4625 { 0x1f, 0x411111f0 }, /* N/A */
4629 [ALC880_FIXUP_5ST] = {
4630 .type = ALC_FIXUP_PINS,
4631 .v.pins = (const struct alc_pincfg[]) {
4632 { 0x1e, 0x411111f0 }, /* N/A */
4635 .chained = true,
4636 .chain_id = ALC880_FIXUP_5ST_BASE,
4638 [ALC880_FIXUP_5ST_DIG] = {
4639 .type = ALC_FIXUP_PINS,
4640 .v.pins = (const struct alc_pincfg[]) {
4641 { 0x1e, 0x0144111e }, /* SPDIF */
4644 .chained = true,
4645 .chain_id = ALC880_FIXUP_5ST_BASE,
4647 [ALC880_FIXUP_6ST_BASE] = {
4648 .type = ALC_FIXUP_PINS,
4649 .v.pins = (const struct alc_pincfg[]) {
4650 { 0x14, 0x01014010 }, /* front */
4651 { 0x15, 0x01016412 }, /* surr */
4652 { 0x16, 0x01011411 }, /* CLFE */
4653 { 0x17, 0x01012414 }, /* side */
4654 { 0x18, 0x01a19c30 }, /* mic-in */
4655 { 0x19, 0x02a19c40 }, /* front-mic */
4656 { 0x1a, 0x01813031 }, /* line-in */
4657 { 0x1b, 0x0121411f }, /* HP */
4658 { 0x1c, 0x411111f0 }, /* N/A */
4659 { 0x1d, 0x411111f0 }, /* N/A */
4660 /* 0x1e is filled in below */
4661 { 0x1f, 0x411111f0 }, /* N/A */
4665 [ALC880_FIXUP_6ST] = {
4666 .type = ALC_FIXUP_PINS,
4667 .v.pins = (const struct alc_pincfg[]) {
4668 { 0x1e, 0x411111f0 }, /* N/A */
4671 .chained = true,
4672 .chain_id = ALC880_FIXUP_6ST_BASE,
4674 [ALC880_FIXUP_6ST_DIG] = {
4675 .type = ALC_FIXUP_PINS,
4676 .v.pins = (const struct alc_pincfg[]) {
4677 { 0x1e, 0x0144111e }, /* SPDIF */
4680 .chained = true,
4681 .chain_id = ALC880_FIXUP_6ST_BASE,
4685 static const struct snd_pci_quirk alc880_fixup_tbl[] = {
4686 SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_FIXUP_W810),
4687 SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_FIXUP_Z71V),
4688 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_FIXUP_GPIO1),
4689 SND_PCI_QUIRK(0x1558, 0x5401, "Clevo GPIO2", ALC880_FIXUP_GPIO2),
4690 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo", ALC880_FIXUP_EAPD_COEF),
4691 SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_FIXUP_UNIWILL_DIG),
4692 SND_PCI_QUIRK(0x1584, 0x9054, "Uniwill", ALC880_FIXUP_F1734),
4693 SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_FIXUP_UNIWILL),
4694 SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_FIXUP_VOL_KNOB),
4695 SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_FIXUP_W810),
4696 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
4697 SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_FIXUP_F1734),
4698 SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FIXUP_FUJITSU),
4699 SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_FIXUP_F1734),
4700 SND_PCI_QUIRK(0x1734, 0x10b0, "FSC Amilo Pi1556", ALC880_FIXUP_FUJITSU),
4701 SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_FIXUP_LG),
4702 SND_PCI_QUIRK(0x1854, 0x005f, "LG P1 Express", ALC880_FIXUP_LG),
4703 SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_FIXUP_LG),
4704 SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_FIXUP_TCL_S700),
4706 /* Below is the copied entries from alc880_quirks.c.
4707 * It's not quite sure whether BIOS sets the correct pin-config table
4708 * on these machines, thus they are kept to be compatible with
4709 * the old static quirks. Once when it's confirmed to work without
4710 * these overrides, it'd be better to remove.
4712 SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_FIXUP_5ST_DIG),
4713 SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_FIXUP_6ST),
4714 SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_FIXUP_3ST_DIG),
4715 SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_FIXUP_6ST_DIG),
4716 SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_FIXUP_6ST_DIG),
4717 SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_FIXUP_6ST_DIG),
4718 SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_FIXUP_3ST_DIG),
4719 SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_FIXUP_3ST),
4720 SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_FIXUP_6ST_DIG),
4721 SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_FIXUP_3ST),
4722 SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_FIXUP_3ST),
4723 SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_FIXUP_5ST),
4724 SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_FIXUP_5ST),
4725 SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_FIXUP_5ST),
4726 SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_FIXUP_6ST_DIG),
4727 SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_FIXUP_6ST_DIG),
4728 SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_FIXUP_6ST_DIG),
4729 SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_FIXUP_6ST_DIG),
4730 SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_FIXUP_5ST_DIG),
4731 SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_FIXUP_5ST_DIG),
4732 SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_FIXUP_5ST_DIG),
4733 SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_FIXUP_6ST_DIG), /* broken BIOS */
4734 SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_FIXUP_6ST_DIG),
4735 SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4736 SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4737 SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4738 SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4739 SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4740 SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4741 SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4742 SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4743 SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4744 SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4745 /* default Intel */
4746 SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_FIXUP_3ST),
4747 SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_FIXUP_5ST_DIG),
4748 SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_FIXUP_6ST_DIG),
4752 static const struct alc_model_fixup alc880_fixup_models[] = {
4753 {.id = ALC880_FIXUP_3ST, .name = "3stack"},
4754 {.id = ALC880_FIXUP_3ST_DIG, .name = "3stack-digout"},
4755 {.id = ALC880_FIXUP_5ST, .name = "5stack"},
4756 {.id = ALC880_FIXUP_5ST_DIG, .name = "5stack-digout"},
4757 {.id = ALC880_FIXUP_6ST, .name = "6stack"},
4758 {.id = ALC880_FIXUP_6ST_DIG, .name = "6stack-digout"},
4764 * OK, here we have finally the patch for ALC880
4766 static int patch_alc880(struct hda_codec *codec)
4768 struct alc_spec *spec;
4769 int err;
4771 err = alc_alloc_spec(codec, 0x0b);
4772 if (err < 0)
4773 return err;
4775 spec = codec->spec;
4776 spec->need_dac_fix = 1;
4778 alc_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl,
4779 alc880_fixups);
4780 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4782 /* automatic parse from the BIOS config */
4783 err = alc880_parse_auto_config(codec);
4784 if (err < 0)
4785 goto error;
4787 if (!spec->no_analog) {
4788 err = snd_hda_attach_beep_device(codec, 0x1);
4789 if (err < 0)
4790 goto error;
4791 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4794 codec->patch_ops = alc_patch_ops;
4795 codec->patch_ops.unsol_event = alc880_unsol_event;
4798 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4800 return 0;
4802 error:
4803 alc_free(codec);
4804 return err;
4809 * ALC260 support
4811 static int alc260_parse_auto_config(struct hda_codec *codec)
4813 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
4814 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
4815 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
4819 * Pin config fixes
4821 enum {
4822 ALC260_FIXUP_HP_DC5750,
4823 ALC260_FIXUP_HP_PIN_0F,
4824 ALC260_FIXUP_COEF,
4825 ALC260_FIXUP_GPIO1,
4826 ALC260_FIXUP_GPIO1_TOGGLE,
4827 ALC260_FIXUP_REPLACER,
4828 ALC260_FIXUP_HP_B1900,
4829 ALC260_FIXUP_KN1,
4832 static void alc260_gpio1_automute(struct hda_codec *codec)
4834 struct alc_spec *spec = codec->spec;
4835 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
4836 spec->hp_jack_present);
4839 static void alc260_fixup_gpio1_toggle(struct hda_codec *codec,
4840 const struct alc_fixup *fix, int action)
4842 struct alc_spec *spec = codec->spec;
4843 if (action == ALC_FIXUP_ACT_PROBE) {
4844 /* although the machine has only one output pin, we need to
4845 * toggle GPIO1 according to the jack state
4847 spec->automute_hook = alc260_gpio1_automute;
4848 spec->detect_hp = 1;
4849 spec->automute_speaker = 1;
4850 spec->autocfg.hp_pins[0] = 0x0f; /* copy it for automute */
4851 snd_hda_jack_detect_enable_callback(codec, 0x0f, ALC_HP_EVENT,
4852 alc_hp_automute);
4853 snd_hda_gen_add_verbs(&spec->gen, alc_gpio1_init_verbs);
4857 static void alc260_fixup_kn1(struct hda_codec *codec,
4858 const struct alc_fixup *fix, int action)
4860 struct alc_spec *spec = codec->spec;
4861 static const struct alc_pincfg pincfgs[] = {
4862 { 0x0f, 0x02214000 }, /* HP/speaker */
4863 { 0x12, 0x90a60160 }, /* int mic */
4864 { 0x13, 0x02a19000 }, /* ext mic */
4865 { 0x18, 0x01446000 }, /* SPDIF out */
4866 /* disable bogus I/O pins */
4867 { 0x10, 0x411111f0 },
4868 { 0x11, 0x411111f0 },
4869 { 0x14, 0x411111f0 },
4870 { 0x15, 0x411111f0 },
4871 { 0x16, 0x411111f0 },
4872 { 0x17, 0x411111f0 },
4873 { 0x19, 0x411111f0 },
4877 switch (action) {
4878 case ALC_FIXUP_ACT_PRE_PROBE:
4879 alc_apply_pincfgs(codec, pincfgs);
4880 break;
4881 case ALC_FIXUP_ACT_PROBE:
4882 spec->init_amp = ALC_INIT_NONE;
4883 break;
4887 static const struct alc_fixup alc260_fixups[] = {
4888 [ALC260_FIXUP_HP_DC5750] = {
4889 .type = ALC_FIXUP_PINS,
4890 .v.pins = (const struct alc_pincfg[]) {
4891 { 0x11, 0x90130110 }, /* speaker */
4895 [ALC260_FIXUP_HP_PIN_0F] = {
4896 .type = ALC_FIXUP_PINS,
4897 .v.pins = (const struct alc_pincfg[]) {
4898 { 0x0f, 0x01214000 }, /* HP */
4902 [ALC260_FIXUP_COEF] = {
4903 .type = ALC_FIXUP_VERBS,
4904 .v.verbs = (const struct hda_verb[]) {
4905 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4906 { 0x20, AC_VERB_SET_PROC_COEF, 0x3040 },
4909 .chained = true,
4910 .chain_id = ALC260_FIXUP_HP_PIN_0F,
4912 [ALC260_FIXUP_GPIO1] = {
4913 .type = ALC_FIXUP_VERBS,
4914 .v.verbs = alc_gpio1_init_verbs,
4916 [ALC260_FIXUP_GPIO1_TOGGLE] = {
4917 .type = ALC_FIXUP_FUNC,
4918 .v.func = alc260_fixup_gpio1_toggle,
4919 .chained = true,
4920 .chain_id = ALC260_FIXUP_HP_PIN_0F,
4922 [ALC260_FIXUP_REPLACER] = {
4923 .type = ALC_FIXUP_VERBS,
4924 .v.verbs = (const struct hda_verb[]) {
4925 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4926 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4929 .chained = true,
4930 .chain_id = ALC260_FIXUP_GPIO1_TOGGLE,
4932 [ALC260_FIXUP_HP_B1900] = {
4933 .type = ALC_FIXUP_FUNC,
4934 .v.func = alc260_fixup_gpio1_toggle,
4935 .chained = true,
4936 .chain_id = ALC260_FIXUP_COEF,
4938 [ALC260_FIXUP_KN1] = {
4939 .type = ALC_FIXUP_FUNC,
4940 .v.func = alc260_fixup_kn1,
4944 static const struct snd_pci_quirk alc260_fixup_tbl[] = {
4945 SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_FIXUP_GPIO1),
4946 SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF),
4947 SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1),
4948 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750),
4949 SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900),
4950 SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1),
4951 SND_PCI_QUIRK(0x152d, 0x0729, "Quanta KN1", ALC260_FIXUP_KN1),
4952 SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER),
4953 SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_FIXUP_COEF),
4959 static int patch_alc260(struct hda_codec *codec)
4961 struct alc_spec *spec;
4962 int err;
4964 err = alc_alloc_spec(codec, 0x07);
4965 if (err < 0)
4966 return err;
4968 spec = codec->spec;
4970 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
4971 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4973 /* automatic parse from the BIOS config */
4974 err = alc260_parse_auto_config(codec);
4975 if (err < 0)
4976 goto error;
4978 if (!spec->no_analog) {
4979 err = snd_hda_attach_beep_device(codec, 0x1);
4980 if (err < 0)
4981 goto error;
4982 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
4985 codec->patch_ops = alc_patch_ops;
4986 spec->shutup = alc_eapd_shutup;
4988 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4990 return 0;
4992 error:
4993 alc_free(codec);
4994 return err;
4999 * ALC882/883/885/888/889 support
5001 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
5002 * configuration. Each pin widget can choose any input DACs and a mixer.
5003 * Each ADC is connected from a mixer of all inputs. This makes possible
5004 * 6-channel independent captures.
5006 * In addition, an independent DAC for the multi-playback (not used in this
5007 * driver yet).
5011 * Pin config fixes
5013 enum {
5014 ALC882_FIXUP_ABIT_AW9D_MAX,
5015 ALC882_FIXUP_LENOVO_Y530,
5016 ALC882_FIXUP_PB_M5210,
5017 ALC882_FIXUP_ACER_ASPIRE_7736,
5018 ALC882_FIXUP_ASUS_W90V,
5019 ALC889_FIXUP_CD,
5020 ALC889_FIXUP_VAIO_TT,
5021 ALC888_FIXUP_EEE1601,
5022 ALC882_FIXUP_EAPD,
5023 ALC883_FIXUP_EAPD,
5024 ALC883_FIXUP_ACER_EAPD,
5025 ALC882_FIXUP_GPIO1,
5026 ALC882_FIXUP_GPIO2,
5027 ALC882_FIXUP_GPIO3,
5028 ALC889_FIXUP_COEF,
5029 ALC882_FIXUP_ASUS_W2JC,
5030 ALC882_FIXUP_ACER_ASPIRE_4930G,
5031 ALC882_FIXUP_ACER_ASPIRE_8930G,
5032 ALC882_FIXUP_ASPIRE_8930G_VERBS,
5033 ALC885_FIXUP_MACPRO_GPIO,
5034 ALC889_FIXUP_DAC_ROUTE,
5035 ALC889_FIXUP_MBP_VREF,
5036 ALC889_FIXUP_IMAC91_VREF,
5037 ALC882_FIXUP_INV_DMIC,
5038 ALC882_FIXUP_NO_PRIMARY_HP,
5041 static void alc889_fixup_coef(struct hda_codec *codec,
5042 const struct alc_fixup *fix, int action)
5044 if (action != ALC_FIXUP_ACT_INIT)
5045 return;
5046 alc889_coef_init(codec);
5049 /* toggle speaker-output according to the hp-jack state */
5050 static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
5052 unsigned int gpiostate, gpiomask, gpiodir;
5054 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
5055 AC_VERB_GET_GPIO_DATA, 0);
5057 if (!muted)
5058 gpiostate |= (1 << pin);
5059 else
5060 gpiostate &= ~(1 << pin);
5062 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
5063 AC_VERB_GET_GPIO_MASK, 0);
5064 gpiomask |= (1 << pin);
5066 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
5067 AC_VERB_GET_GPIO_DIRECTION, 0);
5068 gpiodir |= (1 << pin);
5071 snd_hda_codec_write(codec, codec->afg, 0,
5072 AC_VERB_SET_GPIO_MASK, gpiomask);
5073 snd_hda_codec_write(codec, codec->afg, 0,
5074 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
5076 msleep(1);
5078 snd_hda_codec_write(codec, codec->afg, 0,
5079 AC_VERB_SET_GPIO_DATA, gpiostate);
5082 /* set up GPIO at initialization */
5083 static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
5084 const struct alc_fixup *fix, int action)
5086 if (action != ALC_FIXUP_ACT_INIT)
5087 return;
5088 alc882_gpio_mute(codec, 0, 0);
5089 alc882_gpio_mute(codec, 1, 0);
5092 /* Fix the connection of some pins for ALC889:
5093 * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
5094 * work correctly (bko#42740)
5096 static void alc889_fixup_dac_route(struct hda_codec *codec,
5097 const struct alc_fixup *fix, int action)
5099 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
5100 /* fake the connections during parsing the tree */
5101 hda_nid_t conn1[2] = { 0x0c, 0x0d };
5102 hda_nid_t conn2[2] = { 0x0e, 0x0f };
5103 snd_hda_override_conn_list(codec, 0x14, 2, conn1);
5104 snd_hda_override_conn_list(codec, 0x15, 2, conn1);
5105 snd_hda_override_conn_list(codec, 0x18, 2, conn2);
5106 snd_hda_override_conn_list(codec, 0x1a, 2, conn2);
5107 } else if (action == ALC_FIXUP_ACT_PROBE) {
5108 /* restore the connections */
5109 hda_nid_t conn[5] = { 0x0c, 0x0d, 0x0e, 0x0f, 0x26 };
5110 snd_hda_override_conn_list(codec, 0x14, 5, conn);
5111 snd_hda_override_conn_list(codec, 0x15, 5, conn);
5112 snd_hda_override_conn_list(codec, 0x18, 5, conn);
5113 snd_hda_override_conn_list(codec, 0x1a, 5, conn);
5117 /* Set VREF on HP pin */
5118 static void alc889_fixup_mbp_vref(struct hda_codec *codec,
5119 const struct alc_fixup *fix, int action)
5121 struct alc_spec *spec = codec->spec;
5122 static hda_nid_t nids[2] = { 0x14, 0x15 };
5123 int i;
5125 if (action != ALC_FIXUP_ACT_INIT)
5126 return;
5127 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5128 unsigned int val = snd_hda_codec_get_pincfg(codec, nids[i]);
5129 if (get_defcfg_device(val) != AC_JACK_HP_OUT)
5130 continue;
5131 val = snd_hda_codec_read(codec, nids[i], 0,
5132 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5133 val |= AC_PINCTL_VREF_80;
5134 snd_hda_set_pin_ctl(codec, nids[i], val);
5135 spec->keep_vref_in_automute = 1;
5136 break;
5140 /* Set VREF on speaker pins on imac91 */
5141 static void alc889_fixup_imac91_vref(struct hda_codec *codec,
5142 const struct alc_fixup *fix, int action)
5144 struct alc_spec *spec = codec->spec;
5145 static hda_nid_t nids[2] = { 0x18, 0x1a };
5146 int i;
5148 if (action != ALC_FIXUP_ACT_INIT)
5149 return;
5150 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5151 unsigned int val;
5152 val = snd_hda_codec_read(codec, nids[i], 0,
5153 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5154 val |= AC_PINCTL_VREF_50;
5155 snd_hda_set_pin_ctl(codec, nids[i], val);
5157 spec->keep_vref_in_automute = 1;
5160 /* Don't take HP output as primary
5161 * strangely, the speaker output doesn't work on VAIO Z through DAC 0x05
5163 static void alc882_fixup_no_primary_hp(struct hda_codec *codec,
5164 const struct alc_fixup *fix, int action)
5166 struct alc_spec *spec = codec->spec;
5167 if (action == ALC_FIXUP_ACT_PRE_PROBE)
5168 spec->no_primary_hp = 1;
5171 static const struct alc_fixup alc882_fixups[] = {
5172 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
5173 .type = ALC_FIXUP_PINS,
5174 .v.pins = (const struct alc_pincfg[]) {
5175 { 0x15, 0x01080104 }, /* side */
5176 { 0x16, 0x01011012 }, /* rear */
5177 { 0x17, 0x01016011 }, /* clfe */
5181 [ALC882_FIXUP_LENOVO_Y530] = {
5182 .type = ALC_FIXUP_PINS,
5183 .v.pins = (const struct alc_pincfg[]) {
5184 { 0x15, 0x99130112 }, /* rear int speakers */
5185 { 0x16, 0x99130111 }, /* subwoofer */
5189 [ALC882_FIXUP_PB_M5210] = {
5190 .type = ALC_FIXUP_VERBS,
5191 .v.verbs = (const struct hda_verb[]) {
5192 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
5196 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
5197 .type = ALC_FIXUP_FUNC,
5198 .v.func = alc_fixup_sku_ignore,
5200 [ALC882_FIXUP_ASUS_W90V] = {
5201 .type = ALC_FIXUP_PINS,
5202 .v.pins = (const struct alc_pincfg[]) {
5203 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
5207 [ALC889_FIXUP_CD] = {
5208 .type = ALC_FIXUP_PINS,
5209 .v.pins = (const struct alc_pincfg[]) {
5210 { 0x1c, 0x993301f0 }, /* CD */
5214 [ALC889_FIXUP_VAIO_TT] = {
5215 .type = ALC_FIXUP_PINS,
5216 .v.pins = (const struct alc_pincfg[]) {
5217 { 0x17, 0x90170111 }, /* hidden surround speaker */
5221 [ALC888_FIXUP_EEE1601] = {
5222 .type = ALC_FIXUP_VERBS,
5223 .v.verbs = (const struct hda_verb[]) {
5224 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5225 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
5229 [ALC882_FIXUP_EAPD] = {
5230 .type = ALC_FIXUP_VERBS,
5231 .v.verbs = (const struct hda_verb[]) {
5232 /* change to EAPD mode */
5233 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5234 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
5238 [ALC883_FIXUP_EAPD] = {
5239 .type = ALC_FIXUP_VERBS,
5240 .v.verbs = (const struct hda_verb[]) {
5241 /* change to EAPD mode */
5242 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5243 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5247 [ALC883_FIXUP_ACER_EAPD] = {
5248 .type = ALC_FIXUP_VERBS,
5249 .v.verbs = (const struct hda_verb[]) {
5250 /* eanable EAPD on Acer laptops */
5251 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5252 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5256 [ALC882_FIXUP_GPIO1] = {
5257 .type = ALC_FIXUP_VERBS,
5258 .v.verbs = alc_gpio1_init_verbs,
5260 [ALC882_FIXUP_GPIO2] = {
5261 .type = ALC_FIXUP_VERBS,
5262 .v.verbs = alc_gpio2_init_verbs,
5264 [ALC882_FIXUP_GPIO3] = {
5265 .type = ALC_FIXUP_VERBS,
5266 .v.verbs = alc_gpio3_init_verbs,
5268 [ALC882_FIXUP_ASUS_W2JC] = {
5269 .type = ALC_FIXUP_VERBS,
5270 .v.verbs = alc_gpio1_init_verbs,
5271 .chained = true,
5272 .chain_id = ALC882_FIXUP_EAPD,
5274 [ALC889_FIXUP_COEF] = {
5275 .type = ALC_FIXUP_FUNC,
5276 .v.func = alc889_fixup_coef,
5278 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
5279 .type = ALC_FIXUP_PINS,
5280 .v.pins = (const struct alc_pincfg[]) {
5281 { 0x16, 0x99130111 }, /* CLFE speaker */
5282 { 0x17, 0x99130112 }, /* surround speaker */
5285 .chained = true,
5286 .chain_id = ALC882_FIXUP_GPIO1,
5288 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
5289 .type = ALC_FIXUP_PINS,
5290 .v.pins = (const struct alc_pincfg[]) {
5291 { 0x16, 0x99130111 }, /* CLFE speaker */
5292 { 0x1b, 0x99130112 }, /* surround speaker */
5295 .chained = true,
5296 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
5298 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
5299 /* additional init verbs for Acer Aspire 8930G */
5300 .type = ALC_FIXUP_VERBS,
5301 .v.verbs = (const struct hda_verb[]) {
5302 /* Enable all DACs */
5303 /* DAC DISABLE/MUTE 1? */
5304 /* setting bits 1-5 disables DAC nids 0x02-0x06
5305 * apparently. Init=0x38 */
5306 { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
5307 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5308 /* DAC DISABLE/MUTE 2? */
5309 /* some bit here disables the other DACs.
5310 * Init=0x4900 */
5311 { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
5312 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5313 /* DMIC fix
5314 * This laptop has a stereo digital microphone.
5315 * The mics are only 1cm apart which makes the stereo
5316 * useless. However, either the mic or the ALC889
5317 * makes the signal become a difference/sum signal
5318 * instead of standard stereo, which is annoying.
5319 * So instead we flip this bit which makes the
5320 * codec replicate the sum signal to both channels,
5321 * turning it into a normal mono mic.
5323 /* DMIC_CONTROL? Init value = 0x0001 */
5324 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5325 { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
5326 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5327 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5330 .chained = true,
5331 .chain_id = ALC882_FIXUP_GPIO1,
5333 [ALC885_FIXUP_MACPRO_GPIO] = {
5334 .type = ALC_FIXUP_FUNC,
5335 .v.func = alc885_fixup_macpro_gpio,
5337 [ALC889_FIXUP_DAC_ROUTE] = {
5338 .type = ALC_FIXUP_FUNC,
5339 .v.func = alc889_fixup_dac_route,
5341 [ALC889_FIXUP_MBP_VREF] = {
5342 .type = ALC_FIXUP_FUNC,
5343 .v.func = alc889_fixup_mbp_vref,
5344 .chained = true,
5345 .chain_id = ALC882_FIXUP_GPIO1,
5347 [ALC889_FIXUP_IMAC91_VREF] = {
5348 .type = ALC_FIXUP_FUNC,
5349 .v.func = alc889_fixup_imac91_vref,
5350 .chained = true,
5351 .chain_id = ALC882_FIXUP_GPIO1,
5353 [ALC882_FIXUP_INV_DMIC] = {
5354 .type = ALC_FIXUP_FUNC,
5355 .v.func = alc_fixup_inv_dmic_0x12,
5357 [ALC882_FIXUP_NO_PRIMARY_HP] = {
5358 .type = ALC_FIXUP_FUNC,
5359 .v.func = alc882_fixup_no_primary_hp,
5363 static const struct snd_pci_quirk alc882_fixup_tbl[] = {
5364 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
5365 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5366 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
5367 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5368 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
5369 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
5370 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
5371 ALC882_FIXUP_ACER_ASPIRE_4930G),
5372 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
5373 ALC882_FIXUP_ACER_ASPIRE_4930G),
5374 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
5375 ALC882_FIXUP_ACER_ASPIRE_8930G),
5376 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
5377 ALC882_FIXUP_ACER_ASPIRE_8930G),
5378 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
5379 ALC882_FIXUP_ACER_ASPIRE_4930G),
5380 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
5381 ALC882_FIXUP_ACER_ASPIRE_4930G),
5382 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
5383 ALC882_FIXUP_ACER_ASPIRE_4930G),
5384 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
5385 SND_PCI_QUIRK(0x1025, 0x021e, "Acer Aspire 5739G",
5386 ALC882_FIXUP_ACER_ASPIRE_4930G),
5387 SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE),
5388 SND_PCI_QUIRK(0x1025, 0x026b, "Acer Aspire 8940G", ALC882_FIXUP_ACER_ASPIRE_8930G),
5389 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
5390 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
5391 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
5392 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
5393 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
5394 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
5395 SND_PCI_QUIRK(0x104d, 0x905a, "Sony Vaio Z", ALC882_FIXUP_NO_PRIMARY_HP),
5397 /* All Apple entries are in codec SSIDs */
5398 SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC889_FIXUP_MBP_VREF),
5399 SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC889_FIXUP_MBP_VREF),
5400 SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
5401 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
5402 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
5403 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
5404 SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC889_FIXUP_MBP_VREF),
5405 SND_PCI_QUIRK(0x106b, 0x3000, "iMac", ALC889_FIXUP_MBP_VREF),
5406 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
5407 SND_PCI_QUIRK(0x106b, 0x3400, "MacBookAir 1,1", ALC889_FIXUP_MBP_VREF),
5408 SND_PCI_QUIRK(0x106b, 0x3500, "MacBookAir 2,1", ALC889_FIXUP_MBP_VREF),
5409 SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889_FIXUP_MBP_VREF),
5410 SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
5411 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
5412 SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC889_FIXUP_IMAC91_VREF),
5413 SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC889_FIXUP_IMAC91_VREF),
5414 SND_PCI_QUIRK(0x106b, 0x4100, "Macmini 3,1", ALC889_FIXUP_IMAC91_VREF),
5415 SND_PCI_QUIRK(0x106b, 0x4200, "Mac Pro 5,1", ALC885_FIXUP_MACPRO_GPIO),
5416 SND_PCI_QUIRK(0x106b, 0x4300, "iMac 9,1", ALC889_FIXUP_IMAC91_VREF),
5417 SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC889_FIXUP_IMAC91_VREF),
5418 SND_PCI_QUIRK(0x106b, 0x4900, "iMac 9,1 Aluminum", ALC889_FIXUP_IMAC91_VREF),
5419 SND_PCI_QUIRK(0x106b, 0x4a00, "Macbook 5,2", ALC889_FIXUP_IMAC91_VREF),
5421 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
5422 SND_PCI_QUIRK(0x1462, 0x7350, "MSI-7350", ALC889_FIXUP_CD),
5423 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
5424 SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte EP45-DS3", ALC889_FIXUP_CD),
5425 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
5426 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
5427 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
5428 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
5429 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
5433 static const struct alc_model_fixup alc882_fixup_models[] = {
5434 {.id = ALC882_FIXUP_ACER_ASPIRE_4930G, .name = "acer-aspire-4930g"},
5435 {.id = ALC882_FIXUP_ACER_ASPIRE_8930G, .name = "acer-aspire-8930g"},
5436 {.id = ALC883_FIXUP_ACER_EAPD, .name = "acer-aspire"},
5437 {.id = ALC882_FIXUP_INV_DMIC, .name = "inv-dmic"},
5438 {.id = ALC882_FIXUP_NO_PRIMARY_HP, .name = "no-primary-hp"},
5443 * BIOS auto configuration
5445 /* almost identical with ALC880 parser... */
5446 static int alc882_parse_auto_config(struct hda_codec *codec)
5448 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
5449 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5450 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
5455 static int patch_alc882(struct hda_codec *codec)
5457 struct alc_spec *spec;
5458 int err;
5460 err = alc_alloc_spec(codec, 0x0b);
5461 if (err < 0)
5462 return err;
5464 spec = codec->spec;
5466 switch (codec->vendor_id) {
5467 case 0x10ec0882:
5468 case 0x10ec0885:
5469 break;
5470 default:
5471 /* ALC883 and variants */
5472 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5473 break;
5476 alc_pick_fixup(codec, alc882_fixup_models, alc882_fixup_tbl,
5477 alc882_fixups);
5478 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5480 alc_auto_parse_customize_define(codec);
5482 /* automatic parse from the BIOS config */
5483 err = alc882_parse_auto_config(codec);
5484 if (err < 0)
5485 goto error;
5487 if (!spec->no_analog && has_cdefine_beep(codec)) {
5488 err = snd_hda_attach_beep_device(codec, 0x1);
5489 if (err < 0)
5490 goto error;
5491 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5494 codec->patch_ops = alc_patch_ops;
5496 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5498 return 0;
5500 error:
5501 alc_free(codec);
5502 return err;
5507 * ALC262 support
5509 static int alc262_parse_auto_config(struct hda_codec *codec)
5511 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
5512 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5513 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
5517 * Pin config fixes
5519 enum {
5520 ALC262_FIXUP_FSC_H270,
5521 ALC262_FIXUP_HP_Z200,
5522 ALC262_FIXUP_TYAN,
5523 ALC262_FIXUP_LENOVO_3000,
5524 ALC262_FIXUP_BENQ,
5525 ALC262_FIXUP_BENQ_T31,
5526 ALC262_FIXUP_INV_DMIC,
5529 static const struct alc_fixup alc262_fixups[] = {
5530 [ALC262_FIXUP_FSC_H270] = {
5531 .type = ALC_FIXUP_PINS,
5532 .v.pins = (const struct alc_pincfg[]) {
5533 { 0x14, 0x99130110 }, /* speaker */
5534 { 0x15, 0x0221142f }, /* front HP */
5535 { 0x1b, 0x0121141f }, /* rear HP */
5539 [ALC262_FIXUP_HP_Z200] = {
5540 .type = ALC_FIXUP_PINS,
5541 .v.pins = (const struct alc_pincfg[]) {
5542 { 0x16, 0x99130120 }, /* internal speaker */
5546 [ALC262_FIXUP_TYAN] = {
5547 .type = ALC_FIXUP_PINS,
5548 .v.pins = (const struct alc_pincfg[]) {
5549 { 0x14, 0x1993e1f0 }, /* int AUX */
5553 [ALC262_FIXUP_LENOVO_3000] = {
5554 .type = ALC_FIXUP_VERBS,
5555 .v.verbs = (const struct hda_verb[]) {
5556 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
5559 .chained = true,
5560 .chain_id = ALC262_FIXUP_BENQ,
5562 [ALC262_FIXUP_BENQ] = {
5563 .type = ALC_FIXUP_VERBS,
5564 .v.verbs = (const struct hda_verb[]) {
5565 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5566 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5570 [ALC262_FIXUP_BENQ_T31] = {
5571 .type = ALC_FIXUP_VERBS,
5572 .v.verbs = (const struct hda_verb[]) {
5573 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5574 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5578 [ALC262_FIXUP_INV_DMIC] = {
5579 .type = ALC_FIXUP_FUNC,
5580 .v.func = alc_fixup_inv_dmic_0x12,
5584 static const struct snd_pci_quirk alc262_fixup_tbl[] = {
5585 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
5586 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
5587 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
5588 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
5589 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
5590 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
5591 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
5592 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
5596 static const struct alc_model_fixup alc262_fixup_models[] = {
5597 {.id = ALC262_FIXUP_INV_DMIC, .name = "inv-dmic"},
5603 static int patch_alc262(struct hda_codec *codec)
5605 struct alc_spec *spec;
5606 int err;
5608 err = alc_alloc_spec(codec, 0x0b);
5609 if (err < 0)
5610 return err;
5612 spec = codec->spec;
5614 #if 0
5615 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
5616 * under-run
5619 int tmp;
5620 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5621 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
5622 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5623 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
5625 #endif
5626 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5628 alc_pick_fixup(codec, alc262_fixup_models, alc262_fixup_tbl,
5629 alc262_fixups);
5630 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5632 alc_auto_parse_customize_define(codec);
5634 /* automatic parse from the BIOS config */
5635 err = alc262_parse_auto_config(codec);
5636 if (err < 0)
5637 goto error;
5639 if (!spec->no_analog && has_cdefine_beep(codec)) {
5640 err = snd_hda_attach_beep_device(codec, 0x1);
5641 if (err < 0)
5642 goto error;
5643 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5646 codec->patch_ops = alc_patch_ops;
5647 spec->shutup = alc_eapd_shutup;
5649 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5651 return 0;
5653 error:
5654 alc_free(codec);
5655 return err;
5659 * ALC268
5661 /* bind Beep switches of both NID 0x0f and 0x10 */
5662 static const struct hda_bind_ctls alc268_bind_beep_sw = {
5663 .ops = &snd_hda_bind_sw,
5664 .values = {
5665 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
5666 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
5671 static const struct snd_kcontrol_new alc268_beep_mixer[] = {
5672 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
5673 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
5677 /* set PCBEEP vol = 0, mute connections */
5678 static const struct hda_verb alc268_beep_init_verbs[] = {
5679 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5680 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5681 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5685 enum {
5686 ALC268_FIXUP_INV_DMIC,
5687 ALC268_FIXUP_HP_EAPD,
5690 static const struct alc_fixup alc268_fixups[] = {
5691 [ALC268_FIXUP_INV_DMIC] = {
5692 .type = ALC_FIXUP_FUNC,
5693 .v.func = alc_fixup_inv_dmic_0x12,
5695 [ALC268_FIXUP_HP_EAPD] = {
5696 .type = ALC_FIXUP_VERBS,
5697 .v.verbs = (const struct hda_verb[]) {
5698 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 0},
5704 static const struct alc_model_fixup alc268_fixup_models[] = {
5705 {.id = ALC268_FIXUP_INV_DMIC, .name = "inv-dmic"},
5706 {.id = ALC268_FIXUP_HP_EAPD, .name = "hp-eapd"},
5710 static const struct snd_pci_quirk alc268_fixup_tbl[] = {
5711 /* below is codec SSID since multiple Toshiba laptops have the
5712 * same PCI SSID 1179:ff00
5714 SND_PCI_QUIRK(0x1179, 0xff06, "Toshiba P200", ALC268_FIXUP_HP_EAPD),
5719 * BIOS auto configuration
5721 static int alc268_parse_auto_config(struct hda_codec *codec)
5723 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5724 struct alc_spec *spec = codec->spec;
5725 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
5726 if (err > 0) {
5727 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
5728 add_mixer(spec, alc268_beep_mixer);
5729 snd_hda_gen_add_verbs(&spec->gen, alc268_beep_init_verbs);
5732 return err;
5737 static int patch_alc268(struct hda_codec *codec)
5739 struct alc_spec *spec;
5740 int i, has_beep, err;
5742 /* ALC268 has no aa-loopback mixer */
5743 err = alc_alloc_spec(codec, 0);
5744 if (err < 0)
5745 return err;
5747 spec = codec->spec;
5749 alc_pick_fixup(codec, alc268_fixup_models, alc268_fixup_tbl, alc268_fixups);
5750 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5752 /* automatic parse from the BIOS config */
5753 err = alc268_parse_auto_config(codec);
5754 if (err < 0)
5755 goto error;
5757 has_beep = 0;
5758 for (i = 0; i < spec->num_mixers; i++) {
5759 if (spec->mixers[i] == alc268_beep_mixer) {
5760 has_beep = 1;
5761 break;
5765 if (has_beep) {
5766 err = snd_hda_attach_beep_device(codec, 0x1);
5767 if (err < 0)
5768 goto error;
5769 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
5770 /* override the amp caps for beep generator */
5771 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
5772 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
5773 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
5774 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5775 (0 << AC_AMPCAP_MUTE_SHIFT));
5778 codec->patch_ops = alc_patch_ops;
5779 spec->shutup = alc_eapd_shutup;
5781 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5783 return 0;
5785 error:
5786 alc_free(codec);
5787 return err;
5791 * ALC269
5793 static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
5794 .substreams = 1,
5795 .channels_min = 2,
5796 .channels_max = 8,
5797 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5798 /* NID is set in alc_build_pcms */
5799 .ops = {
5800 .open = alc_playback_pcm_open,
5801 .prepare = alc_playback_pcm_prepare,
5802 .cleanup = alc_playback_pcm_cleanup
5806 static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
5807 .substreams = 1,
5808 .channels_min = 2,
5809 .channels_max = 2,
5810 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5811 /* NID is set in alc_build_pcms */
5814 /* different alc269-variants */
5815 enum {
5816 ALC269_TYPE_ALC269VA,
5817 ALC269_TYPE_ALC269VB,
5818 ALC269_TYPE_ALC269VC,
5819 ALC269_TYPE_ALC269VD,
5823 * BIOS auto configuration
5825 static int alc269_parse_auto_config(struct hda_codec *codec)
5827 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
5828 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
5829 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5830 struct alc_spec *spec = codec->spec;
5831 const hda_nid_t *ssids;
5833 switch (spec->codec_variant) {
5834 case ALC269_TYPE_ALC269VA:
5835 case ALC269_TYPE_ALC269VC:
5836 ssids = alc269va_ssids;
5837 break;
5838 case ALC269_TYPE_ALC269VB:
5839 case ALC269_TYPE_ALC269VD:
5840 ssids = alc269_ssids;
5841 break;
5842 default:
5843 ssids = alc269_ssids;
5844 break;
5847 return alc_parse_auto_config(codec, alc269_ignore, ssids);
5850 static void alc269vb_toggle_power_output(struct hda_codec *codec, int power_up)
5852 int val = alc_read_coef_idx(codec, 0x04);
5853 if (power_up)
5854 val |= 1 << 11;
5855 else
5856 val &= ~(1 << 11);
5857 alc_write_coef_idx(codec, 0x04, val);
5860 static void alc269_shutup(struct hda_codec *codec)
5862 struct alc_spec *spec = codec->spec;
5864 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
5865 return;
5867 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
5868 alc269vb_toggle_power_output(codec, 0);
5869 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
5870 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
5871 msleep(150);
5875 #ifdef CONFIG_PM
5876 static int alc269_resume(struct hda_codec *codec)
5878 struct alc_spec *spec = codec->spec;
5880 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
5881 alc269vb_toggle_power_output(codec, 0);
5882 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
5883 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
5884 msleep(150);
5887 codec->patch_ops.init(codec);
5889 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
5890 alc269vb_toggle_power_output(codec, 1);
5891 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
5892 (alc_get_coef0(codec) & 0x00ff) == 0x017) {
5893 msleep(200);
5896 snd_hda_codec_resume_amp(codec);
5897 snd_hda_codec_resume_cache(codec);
5898 hda_call_check_power_status(codec, 0x01);
5899 return 0;
5901 #endif /* CONFIG_PM */
5903 static void alc269_fixup_pincfg_no_hp_to_lineout(struct hda_codec *codec,
5904 const struct alc_fixup *fix, int action)
5906 struct alc_spec *spec = codec->spec;
5908 if (action == ALC_FIXUP_ACT_PRE_PROBE)
5909 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
5912 static void alc269_fixup_hweq(struct hda_codec *codec,
5913 const struct alc_fixup *fix, int action)
5915 int coef;
5917 if (action != ALC_FIXUP_ACT_INIT)
5918 return;
5919 coef = alc_read_coef_idx(codec, 0x1e);
5920 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
5923 static void alc271_fixup_dmic(struct hda_codec *codec,
5924 const struct alc_fixup *fix, int action)
5926 static const struct hda_verb verbs[] = {
5927 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
5928 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
5931 unsigned int cfg;
5933 if (strcmp(codec->chip_name, "ALC271X"))
5934 return;
5935 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
5936 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
5937 snd_hda_sequence_write(codec, verbs);
5940 static void alc269_fixup_pcm_44k(struct hda_codec *codec,
5941 const struct alc_fixup *fix, int action)
5943 struct alc_spec *spec = codec->spec;
5945 if (action != ALC_FIXUP_ACT_PROBE)
5946 return;
5948 /* Due to a hardware problem on Lenovo Ideadpad, we need to
5949 * fix the sample rate of analog I/O to 44.1kHz
5951 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
5952 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
5955 static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
5956 const struct alc_fixup *fix, int action)
5958 int coef;
5960 if (action != ALC_FIXUP_ACT_INIT)
5961 return;
5962 /* The digital-mic unit sends PDM (differential signal) instead of
5963 * the standard PCM, thus you can't record a valid mono stream as is.
5964 * Below is a workaround specific to ALC269 to control the dmic
5965 * signal source as mono.
5967 coef = alc_read_coef_idx(codec, 0x07);
5968 alc_write_coef_idx(codec, 0x07, coef | 0x80);
5971 static void alc269_quanta_automute(struct hda_codec *codec)
5973 update_outputs(codec);
5975 snd_hda_codec_write(codec, 0x20, 0,
5976 AC_VERB_SET_COEF_INDEX, 0x0c);
5977 snd_hda_codec_write(codec, 0x20, 0,
5978 AC_VERB_SET_PROC_COEF, 0x680);
5980 snd_hda_codec_write(codec, 0x20, 0,
5981 AC_VERB_SET_COEF_INDEX, 0x0c);
5982 snd_hda_codec_write(codec, 0x20, 0,
5983 AC_VERB_SET_PROC_COEF, 0x480);
5986 static void alc269_fixup_quanta_mute(struct hda_codec *codec,
5987 const struct alc_fixup *fix, int action)
5989 struct alc_spec *spec = codec->spec;
5990 if (action != ALC_FIXUP_ACT_PROBE)
5991 return;
5992 spec->automute_hook = alc269_quanta_automute;
5995 /* update mute-LED according to the speaker mute state via mic2 VREF pin */
5996 static void alc269_fixup_mic2_mute_hook(void *private_data, int enabled)
5998 struct hda_codec *codec = private_data;
5999 unsigned int pinval = enabled ? 0x20 : 0x24;
6000 snd_hda_set_pin_ctl_cache(codec, 0x19, pinval);
6003 static void alc269_fixup_mic2_mute(struct hda_codec *codec,
6004 const struct alc_fixup *fix, int action)
6006 struct alc_spec *spec = codec->spec;
6007 switch (action) {
6008 case ALC_FIXUP_ACT_BUILD:
6009 spec->vmaster_mute.hook = alc269_fixup_mic2_mute_hook;
6010 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
6011 /* fallthru */
6012 case ALC_FIXUP_ACT_INIT:
6013 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
6014 break;
6018 static void alc271_hp_gate_mic_jack(struct hda_codec *codec,
6019 const struct alc_fixup *fix,
6020 int action)
6022 struct alc_spec *spec = codec->spec;
6024 if (action == ALC_FIXUP_ACT_PROBE)
6025 snd_hda_jack_set_gating_jack(codec, spec->ext_mic_pin,
6026 spec->autocfg.hp_pins[0]);
6029 enum {
6030 ALC269_FIXUP_SONY_VAIO,
6031 ALC275_FIXUP_SONY_VAIO_GPIO2,
6032 ALC269_FIXUP_DELL_M101Z,
6033 ALC269_FIXUP_SKU_IGNORE,
6034 ALC269_FIXUP_ASUS_G73JW,
6035 ALC269_FIXUP_LENOVO_EAPD,
6036 ALC275_FIXUP_SONY_HWEQ,
6037 ALC271_FIXUP_DMIC,
6038 ALC269_FIXUP_PCM_44K,
6039 ALC269_FIXUP_STEREO_DMIC,
6040 ALC269_FIXUP_QUANTA_MUTE,
6041 ALC269_FIXUP_LIFEBOOK,
6042 ALC269_FIXUP_AMIC,
6043 ALC269_FIXUP_DMIC,
6044 ALC269VB_FIXUP_AMIC,
6045 ALC269VB_FIXUP_DMIC,
6046 ALC269_FIXUP_MIC2_MUTE_LED,
6047 ALC269_FIXUP_INV_DMIC,
6048 ALC269_FIXUP_LENOVO_DOCK,
6049 ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT,
6050 ALC271_FIXUP_AMIC_MIC2,
6051 ALC271_FIXUP_HP_GATE_MIC_JACK,
6054 static const struct alc_fixup alc269_fixups[] = {
6055 [ALC269_FIXUP_SONY_VAIO] = {
6056 .type = ALC_FIXUP_VERBS,
6057 .v.verbs = (const struct hda_verb[]) {
6058 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
6062 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
6063 .type = ALC_FIXUP_VERBS,
6064 .v.verbs = (const struct hda_verb[]) {
6065 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
6066 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
6067 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
6070 .chained = true,
6071 .chain_id = ALC269_FIXUP_SONY_VAIO
6073 [ALC269_FIXUP_DELL_M101Z] = {
6074 .type = ALC_FIXUP_VERBS,
6075 .v.verbs = (const struct hda_verb[]) {
6076 /* Enables internal speaker */
6077 {0x20, AC_VERB_SET_COEF_INDEX, 13},
6078 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
6082 [ALC269_FIXUP_SKU_IGNORE] = {
6083 .type = ALC_FIXUP_FUNC,
6084 .v.func = alc_fixup_sku_ignore,
6086 [ALC269_FIXUP_ASUS_G73JW] = {
6087 .type = ALC_FIXUP_PINS,
6088 .v.pins = (const struct alc_pincfg[]) {
6089 { 0x17, 0x99130111 }, /* subwoofer */
6093 [ALC269_FIXUP_LENOVO_EAPD] = {
6094 .type = ALC_FIXUP_VERBS,
6095 .v.verbs = (const struct hda_verb[]) {
6096 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6100 [ALC275_FIXUP_SONY_HWEQ] = {
6101 .type = ALC_FIXUP_FUNC,
6102 .v.func = alc269_fixup_hweq,
6103 .chained = true,
6104 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
6106 [ALC271_FIXUP_DMIC] = {
6107 .type = ALC_FIXUP_FUNC,
6108 .v.func = alc271_fixup_dmic,
6110 [ALC269_FIXUP_PCM_44K] = {
6111 .type = ALC_FIXUP_FUNC,
6112 .v.func = alc269_fixup_pcm_44k,
6113 .chained = true,
6114 .chain_id = ALC269_FIXUP_QUANTA_MUTE
6116 [ALC269_FIXUP_STEREO_DMIC] = {
6117 .type = ALC_FIXUP_FUNC,
6118 .v.func = alc269_fixup_stereo_dmic,
6120 [ALC269_FIXUP_QUANTA_MUTE] = {
6121 .type = ALC_FIXUP_FUNC,
6122 .v.func = alc269_fixup_quanta_mute,
6124 [ALC269_FIXUP_LIFEBOOK] = {
6125 .type = ALC_FIXUP_PINS,
6126 .v.pins = (const struct alc_pincfg[]) {
6127 { 0x1a, 0x2101103f }, /* dock line-out */
6128 { 0x1b, 0x23a11040 }, /* dock mic-in */
6131 .chained = true,
6132 .chain_id = ALC269_FIXUP_QUANTA_MUTE
6134 [ALC269_FIXUP_AMIC] = {
6135 .type = ALC_FIXUP_PINS,
6136 .v.pins = (const struct alc_pincfg[]) {
6137 { 0x14, 0x99130110 }, /* speaker */
6138 { 0x15, 0x0121401f }, /* HP out */
6139 { 0x18, 0x01a19c20 }, /* mic */
6140 { 0x19, 0x99a3092f }, /* int-mic */
6144 [ALC269_FIXUP_DMIC] = {
6145 .type = ALC_FIXUP_PINS,
6146 .v.pins = (const struct alc_pincfg[]) {
6147 { 0x12, 0x99a3092f }, /* int-mic */
6148 { 0x14, 0x99130110 }, /* speaker */
6149 { 0x15, 0x0121401f }, /* HP out */
6150 { 0x18, 0x01a19c20 }, /* mic */
6154 [ALC269VB_FIXUP_AMIC] = {
6155 .type = ALC_FIXUP_PINS,
6156 .v.pins = (const struct alc_pincfg[]) {
6157 { 0x14, 0x99130110 }, /* speaker */
6158 { 0x18, 0x01a19c20 }, /* mic */
6159 { 0x19, 0x99a3092f }, /* int-mic */
6160 { 0x21, 0x0121401f }, /* HP out */
6164 [ALC269VB_FIXUP_DMIC] = {
6165 .type = ALC_FIXUP_PINS,
6166 .v.pins = (const struct alc_pincfg[]) {
6167 { 0x12, 0x99a3092f }, /* int-mic */
6168 { 0x14, 0x99130110 }, /* speaker */
6169 { 0x18, 0x01a19c20 }, /* mic */
6170 { 0x21, 0x0121401f }, /* HP out */
6174 [ALC269_FIXUP_MIC2_MUTE_LED] = {
6175 .type = ALC_FIXUP_FUNC,
6176 .v.func = alc269_fixup_mic2_mute,
6178 [ALC269_FIXUP_INV_DMIC] = {
6179 .type = ALC_FIXUP_FUNC,
6180 .v.func = alc_fixup_inv_dmic_0x12,
6182 [ALC269_FIXUP_LENOVO_DOCK] = {
6183 .type = ALC_FIXUP_PINS,
6184 .v.pins = (const struct alc_pincfg[]) {
6185 { 0x19, 0x23a11040 }, /* dock mic */
6186 { 0x1b, 0x2121103f }, /* dock headphone */
6189 .chained = true,
6190 .chain_id = ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT
6192 [ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT] = {
6193 .type = ALC_FIXUP_FUNC,
6194 .v.func = alc269_fixup_pincfg_no_hp_to_lineout,
6196 [ALC271_FIXUP_AMIC_MIC2] = {
6197 .type = ALC_FIXUP_PINS,
6198 .v.pins = (const struct alc_pincfg[]) {
6199 { 0x14, 0x99130110 }, /* speaker */
6200 { 0x19, 0x01a19c20 }, /* mic */
6201 { 0x1b, 0x99a7012f }, /* int-mic */
6202 { 0x21, 0x0121401f }, /* HP out */
6206 [ALC271_FIXUP_HP_GATE_MIC_JACK] = {
6207 .type = ALC_FIXUP_FUNC,
6208 .v.func = alc271_hp_gate_mic_jack,
6209 .chained = true,
6210 .chain_id = ALC271_FIXUP_AMIC_MIC2,
6214 static const struct snd_pci_quirk alc269_fixup_tbl[] = {
6215 SND_PCI_QUIRK(0x1025, 0x029b, "Acer 1810TZ", ALC269_FIXUP_INV_DMIC),
6216 SND_PCI_QUIRK(0x1025, 0x0349, "Acer AOD260", ALC269_FIXUP_INV_DMIC),
6217 SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_MIC2_MUTE_LED),
6218 SND_PCI_QUIRK(0x1043, 0x1427, "Asus Zenbook UX31E", ALC269VB_FIXUP_DMIC),
6219 SND_PCI_QUIRK(0x1043, 0x1517, "Asus Zenbook UX31A", ALC269VB_FIXUP_DMIC),
6220 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
6221 SND_PCI_QUIRK(0x1043, 0x1b13, "Asus U41SV", ALC269_FIXUP_INV_DMIC),
6222 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
6223 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
6224 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
6225 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
6226 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
6227 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
6228 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6229 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6230 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
6231 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
6232 SND_PCI_QUIRK(0x1025, 0x0742, "Acer AO756", ALC271_FIXUP_HP_GATE_MIC_JACK),
6233 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
6234 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
6235 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
6236 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
6237 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
6238 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
6239 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
6240 SND_PCI_QUIRK(0x17aa, 0x21f6, "Thinkpad T530", ALC269_FIXUP_LENOVO_DOCK),
6241 SND_PCI_QUIRK(0x17aa, 0x21fa, "Thinkpad X230", ALC269_FIXUP_LENOVO_DOCK),
6242 SND_PCI_QUIRK(0x17aa, 0x21f3, "Thinkpad T430", ALC269_FIXUP_LENOVO_DOCK),
6243 SND_PCI_QUIRK(0x17aa, 0x21fb, "Thinkpad T430s", ALC269_FIXUP_LENOVO_DOCK),
6244 SND_PCI_QUIRK(0x17aa, 0x2203, "Thinkpad X230 Tablet", ALC269_FIXUP_LENOVO_DOCK),
6245 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_PCM_44K),
6246 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
6248 #if 0
6249 /* Below is a quirk table taken from the old code.
6250 * Basically the device should work as is without the fixup table.
6251 * If BIOS doesn't give a proper info, enable the corresponding
6252 * fixup entry.
6254 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
6255 ALC269_FIXUP_AMIC),
6256 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
6257 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
6258 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
6259 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
6260 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
6261 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
6262 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
6263 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
6264 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
6265 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
6266 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
6267 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
6268 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
6269 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
6270 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
6271 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
6272 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
6273 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
6274 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
6275 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
6276 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
6277 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
6278 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
6279 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
6280 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
6281 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
6282 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
6283 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
6284 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
6285 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
6286 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
6287 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
6288 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
6289 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
6290 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
6291 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
6292 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
6293 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
6294 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
6295 #endif
6299 static const struct alc_model_fixup alc269_fixup_models[] = {
6300 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
6301 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
6302 {.id = ALC269_FIXUP_STEREO_DMIC, .name = "alc269-dmic"},
6303 {.id = ALC271_FIXUP_DMIC, .name = "alc271-dmic"},
6304 {.id = ALC269_FIXUP_INV_DMIC, .name = "inv-dmic"},
6305 {.id = ALC269_FIXUP_LENOVO_DOCK, .name = "lenovo-dock"},
6310 static void alc269_fill_coef(struct hda_codec *codec)
6312 struct alc_spec *spec = codec->spec;
6313 int val;
6315 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
6316 return;
6318 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
6319 alc_write_coef_idx(codec, 0xf, 0x960b);
6320 alc_write_coef_idx(codec, 0xe, 0x8817);
6323 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
6324 alc_write_coef_idx(codec, 0xf, 0x960b);
6325 alc_write_coef_idx(codec, 0xe, 0x8814);
6328 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
6329 val = alc_read_coef_idx(codec, 0x04);
6330 /* Power up output pin */
6331 alc_write_coef_idx(codec, 0x04, val | (1<<11));
6334 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
6335 val = alc_read_coef_idx(codec, 0xd);
6336 if ((val & 0x0c00) >> 10 != 0x1) {
6337 /* Capless ramp up clock control */
6338 alc_write_coef_idx(codec, 0xd, val | (1<<10));
6340 val = alc_read_coef_idx(codec, 0x17);
6341 if ((val & 0x01c0) >> 6 != 0x4) {
6342 /* Class D power on reset */
6343 alc_write_coef_idx(codec, 0x17, val | (1<<7));
6347 val = alc_read_coef_idx(codec, 0xd); /* Class D */
6348 alc_write_coef_idx(codec, 0xd, val | (1<<14));
6350 val = alc_read_coef_idx(codec, 0x4); /* HP */
6351 alc_write_coef_idx(codec, 0x4, val | (1<<11));
6356 static int patch_alc269(struct hda_codec *codec)
6358 struct alc_spec *spec;
6359 int err;
6361 err = alc_alloc_spec(codec, 0x0b);
6362 if (err < 0)
6363 return err;
6365 spec = codec->spec;
6367 alc_pick_fixup(codec, alc269_fixup_models,
6368 alc269_fixup_tbl, alc269_fixups);
6369 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6371 alc_auto_parse_customize_define(codec);
6373 if (codec->vendor_id == 0x10ec0269) {
6374 spec->codec_variant = ALC269_TYPE_ALC269VA;
6375 switch (alc_get_coef0(codec) & 0x00f0) {
6376 case 0x0010:
6377 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
6378 spec->cdefine.platform_type == 1)
6379 err = alc_codec_rename(codec, "ALC271X");
6380 spec->codec_variant = ALC269_TYPE_ALC269VB;
6381 break;
6382 case 0x0020:
6383 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
6384 codec->bus->pci->subsystem_device == 0x21f3)
6385 err = alc_codec_rename(codec, "ALC3202");
6386 spec->codec_variant = ALC269_TYPE_ALC269VC;
6387 break;
6388 case 0x0030:
6389 spec->codec_variant = ALC269_TYPE_ALC269VD;
6390 break;
6391 default:
6392 alc_fix_pll_init(codec, 0x20, 0x04, 15);
6394 if (err < 0)
6395 goto error;
6396 spec->init_hook = alc269_fill_coef;
6397 alc269_fill_coef(codec);
6400 /* automatic parse from the BIOS config */
6401 err = alc269_parse_auto_config(codec);
6402 if (err < 0)
6403 goto error;
6405 if (!spec->no_analog && has_cdefine_beep(codec)) {
6406 err = snd_hda_attach_beep_device(codec, 0x1);
6407 if (err < 0)
6408 goto error;
6409 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
6412 codec->patch_ops = alc_patch_ops;
6413 #ifdef CONFIG_PM
6414 codec->patch_ops.resume = alc269_resume;
6415 #endif
6416 spec->shutup = alc269_shutup;
6418 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6420 return 0;
6422 error:
6423 alc_free(codec);
6424 return err;
6428 * ALC861
6431 static int alc861_parse_auto_config(struct hda_codec *codec)
6433 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
6434 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
6435 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
6438 /* Pin config fixes */
6439 enum {
6440 ALC861_FIXUP_FSC_AMILO_PI1505,
6441 ALC861_FIXUP_AMP_VREF_0F,
6442 ALC861_FIXUP_NO_JACK_DETECT,
6443 ALC861_FIXUP_ASUS_A6RP,
6446 /* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
6447 static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
6448 const struct alc_fixup *fix, int action)
6450 struct alc_spec *spec = codec->spec;
6451 unsigned int val;
6453 if (action != ALC_FIXUP_ACT_INIT)
6454 return;
6455 val = snd_hda_codec_read(codec, 0x0f, 0,
6456 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
6457 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
6458 val |= AC_PINCTL_IN_EN;
6459 val |= AC_PINCTL_VREF_50;
6460 snd_hda_set_pin_ctl(codec, 0x0f, val);
6461 spec->keep_vref_in_automute = 1;
6464 /* suppress the jack-detection */
6465 static void alc_fixup_no_jack_detect(struct hda_codec *codec,
6466 const struct alc_fixup *fix, int action)
6468 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6469 codec->no_jack_detect = 1;
6472 static const struct alc_fixup alc861_fixups[] = {
6473 [ALC861_FIXUP_FSC_AMILO_PI1505] = {
6474 .type = ALC_FIXUP_PINS,
6475 .v.pins = (const struct alc_pincfg[]) {
6476 { 0x0b, 0x0221101f }, /* HP */
6477 { 0x0f, 0x90170310 }, /* speaker */
6481 [ALC861_FIXUP_AMP_VREF_0F] = {
6482 .type = ALC_FIXUP_FUNC,
6483 .v.func = alc861_fixup_asus_amp_vref_0f,
6485 [ALC861_FIXUP_NO_JACK_DETECT] = {
6486 .type = ALC_FIXUP_FUNC,
6487 .v.func = alc_fixup_no_jack_detect,
6489 [ALC861_FIXUP_ASUS_A6RP] = {
6490 .type = ALC_FIXUP_FUNC,
6491 .v.func = alc861_fixup_asus_amp_vref_0f,
6492 .chained = true,
6493 .chain_id = ALC861_FIXUP_NO_JACK_DETECT,
6497 static const struct snd_pci_quirk alc861_fixup_tbl[] = {
6498 SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP),
6499 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", ALC861_FIXUP_AMP_VREF_0F),
6500 SND_PCI_QUIRK(0x1462, 0x7254, "HP DX2200", ALC861_FIXUP_NO_JACK_DETECT),
6501 SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", ALC861_FIXUP_AMP_VREF_0F),
6502 SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", ALC861_FIXUP_AMP_VREF_0F),
6503 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", ALC861_FIXUP_FSC_AMILO_PI1505),
6509 static int patch_alc861(struct hda_codec *codec)
6511 struct alc_spec *spec;
6512 int err;
6514 err = alc_alloc_spec(codec, 0x15);
6515 if (err < 0)
6516 return err;
6518 spec = codec->spec;
6520 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
6521 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6523 /* automatic parse from the BIOS config */
6524 err = alc861_parse_auto_config(codec);
6525 if (err < 0)
6526 goto error;
6528 if (!spec->no_analog) {
6529 err = snd_hda_attach_beep_device(codec, 0x23);
6530 if (err < 0)
6531 goto error;
6532 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
6535 codec->patch_ops = alc_patch_ops;
6536 #ifdef CONFIG_PM
6537 spec->power_hook = alc_power_eapd;
6538 #endif
6540 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6542 return 0;
6544 error:
6545 alc_free(codec);
6546 return err;
6550 * ALC861-VD support
6552 * Based on ALC882
6554 * In addition, an independent DAC
6556 static int alc861vd_parse_auto_config(struct hda_codec *codec)
6558 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
6559 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6560 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
6563 enum {
6564 ALC660VD_FIX_ASUS_GPIO1,
6565 ALC861VD_FIX_DALLAS,
6568 /* exclude VREF80 */
6569 static void alc861vd_fixup_dallas(struct hda_codec *codec,
6570 const struct alc_fixup *fix, int action)
6572 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
6573 snd_hda_override_pin_caps(codec, 0x18, 0x00000734);
6574 snd_hda_override_pin_caps(codec, 0x19, 0x0000073c);
6578 static const struct alc_fixup alc861vd_fixups[] = {
6579 [ALC660VD_FIX_ASUS_GPIO1] = {
6580 .type = ALC_FIXUP_VERBS,
6581 .v.verbs = (const struct hda_verb[]) {
6582 /* reset GPIO1 */
6583 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6584 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
6585 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
6589 [ALC861VD_FIX_DALLAS] = {
6590 .type = ALC_FIXUP_FUNC,
6591 .v.func = alc861vd_fixup_dallas,
6595 static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
6596 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
6597 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
6598 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
6604 static int patch_alc861vd(struct hda_codec *codec)
6606 struct alc_spec *spec;
6607 int err;
6609 err = alc_alloc_spec(codec, 0x0b);
6610 if (err < 0)
6611 return err;
6613 spec = codec->spec;
6615 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
6616 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6618 /* automatic parse from the BIOS config */
6619 err = alc861vd_parse_auto_config(codec);
6620 if (err < 0)
6621 goto error;
6623 if (!spec->no_analog) {
6624 err = snd_hda_attach_beep_device(codec, 0x23);
6625 if (err < 0)
6626 goto error;
6627 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6630 codec->patch_ops = alc_patch_ops;
6632 spec->shutup = alc_eapd_shutup;
6634 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6636 return 0;
6638 error:
6639 alc_free(codec);
6640 return err;
6644 * ALC662 support
6646 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
6647 * configuration. Each pin widget can choose any input DACs and a mixer.
6648 * Each ADC is connected from a mixer of all inputs. This makes possible
6649 * 6-channel independent captures.
6651 * In addition, an independent DAC for the multi-playback (not used in this
6652 * driver yet).
6656 * BIOS auto configuration
6659 static int alc662_parse_auto_config(struct hda_codec *codec)
6661 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
6662 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
6663 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6664 const hda_nid_t *ssids;
6666 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
6667 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
6668 ssids = alc663_ssids;
6669 else
6670 ssids = alc662_ssids;
6671 return alc_parse_auto_config(codec, alc662_ignore, ssids);
6674 static void alc272_fixup_mario(struct hda_codec *codec,
6675 const struct alc_fixup *fix, int action)
6677 if (action != ALC_FIXUP_ACT_PROBE)
6678 return;
6679 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
6680 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
6681 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
6682 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6683 (0 << AC_AMPCAP_MUTE_SHIFT)))
6684 printk(KERN_WARNING
6685 "hda_codec: failed to override amp caps for NID 0x2\n");
6688 enum {
6689 ALC662_FIXUP_ASPIRE,
6690 ALC662_FIXUP_IDEAPAD,
6691 ALC272_FIXUP_MARIO,
6692 ALC662_FIXUP_CZC_P10T,
6693 ALC662_FIXUP_SKU_IGNORE,
6694 ALC662_FIXUP_HP_RP5800,
6695 ALC662_FIXUP_ASUS_MODE1,
6696 ALC662_FIXUP_ASUS_MODE2,
6697 ALC662_FIXUP_ASUS_MODE3,
6698 ALC662_FIXUP_ASUS_MODE4,
6699 ALC662_FIXUP_ASUS_MODE5,
6700 ALC662_FIXUP_ASUS_MODE6,
6701 ALC662_FIXUP_ASUS_MODE7,
6702 ALC662_FIXUP_ASUS_MODE8,
6703 ALC662_FIXUP_NO_JACK_DETECT,
6704 ALC662_FIXUP_ZOTAC_Z68,
6705 ALC662_FIXUP_INV_DMIC,
6708 static const struct alc_fixup alc662_fixups[] = {
6709 [ALC662_FIXUP_ASPIRE] = {
6710 .type = ALC_FIXUP_PINS,
6711 .v.pins = (const struct alc_pincfg[]) {
6712 { 0x15, 0x99130112 }, /* subwoofer */
6716 [ALC662_FIXUP_IDEAPAD] = {
6717 .type = ALC_FIXUP_PINS,
6718 .v.pins = (const struct alc_pincfg[]) {
6719 { 0x17, 0x99130112 }, /* subwoofer */
6723 [ALC272_FIXUP_MARIO] = {
6724 .type = ALC_FIXUP_FUNC,
6725 .v.func = alc272_fixup_mario,
6727 [ALC662_FIXUP_CZC_P10T] = {
6728 .type = ALC_FIXUP_VERBS,
6729 .v.verbs = (const struct hda_verb[]) {
6730 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6734 [ALC662_FIXUP_SKU_IGNORE] = {
6735 .type = ALC_FIXUP_FUNC,
6736 .v.func = alc_fixup_sku_ignore,
6738 [ALC662_FIXUP_HP_RP5800] = {
6739 .type = ALC_FIXUP_PINS,
6740 .v.pins = (const struct alc_pincfg[]) {
6741 { 0x14, 0x0221201f }, /* HP out */
6744 .chained = true,
6745 .chain_id = ALC662_FIXUP_SKU_IGNORE
6747 [ALC662_FIXUP_ASUS_MODE1] = {
6748 .type = ALC_FIXUP_PINS,
6749 .v.pins = (const struct alc_pincfg[]) {
6750 { 0x14, 0x99130110 }, /* speaker */
6751 { 0x18, 0x01a19c20 }, /* mic */
6752 { 0x19, 0x99a3092f }, /* int-mic */
6753 { 0x21, 0x0121401f }, /* HP out */
6756 .chained = true,
6757 .chain_id = ALC662_FIXUP_SKU_IGNORE
6759 [ALC662_FIXUP_ASUS_MODE2] = {
6760 .type = ALC_FIXUP_PINS,
6761 .v.pins = (const struct alc_pincfg[]) {
6762 { 0x14, 0x99130110 }, /* speaker */
6763 { 0x18, 0x01a19820 }, /* mic */
6764 { 0x19, 0x99a3092f }, /* int-mic */
6765 { 0x1b, 0x0121401f }, /* HP out */
6768 .chained = true,
6769 .chain_id = ALC662_FIXUP_SKU_IGNORE
6771 [ALC662_FIXUP_ASUS_MODE3] = {
6772 .type = ALC_FIXUP_PINS,
6773 .v.pins = (const struct alc_pincfg[]) {
6774 { 0x14, 0x99130110 }, /* speaker */
6775 { 0x15, 0x0121441f }, /* HP */
6776 { 0x18, 0x01a19840 }, /* mic */
6777 { 0x19, 0x99a3094f }, /* int-mic */
6778 { 0x21, 0x01211420 }, /* HP2 */
6781 .chained = true,
6782 .chain_id = ALC662_FIXUP_SKU_IGNORE
6784 [ALC662_FIXUP_ASUS_MODE4] = {
6785 .type = ALC_FIXUP_PINS,
6786 .v.pins = (const struct alc_pincfg[]) {
6787 { 0x14, 0x99130110 }, /* speaker */
6788 { 0x16, 0x99130111 }, /* speaker */
6789 { 0x18, 0x01a19840 }, /* mic */
6790 { 0x19, 0x99a3094f }, /* int-mic */
6791 { 0x21, 0x0121441f }, /* HP */
6794 .chained = true,
6795 .chain_id = ALC662_FIXUP_SKU_IGNORE
6797 [ALC662_FIXUP_ASUS_MODE5] = {
6798 .type = ALC_FIXUP_PINS,
6799 .v.pins = (const struct alc_pincfg[]) {
6800 { 0x14, 0x99130110 }, /* speaker */
6801 { 0x15, 0x0121441f }, /* HP */
6802 { 0x16, 0x99130111 }, /* speaker */
6803 { 0x18, 0x01a19840 }, /* mic */
6804 { 0x19, 0x99a3094f }, /* int-mic */
6807 .chained = true,
6808 .chain_id = ALC662_FIXUP_SKU_IGNORE
6810 [ALC662_FIXUP_ASUS_MODE6] = {
6811 .type = ALC_FIXUP_PINS,
6812 .v.pins = (const struct alc_pincfg[]) {
6813 { 0x14, 0x99130110 }, /* speaker */
6814 { 0x15, 0x01211420 }, /* HP2 */
6815 { 0x18, 0x01a19840 }, /* mic */
6816 { 0x19, 0x99a3094f }, /* int-mic */
6817 { 0x1b, 0x0121441f }, /* HP */
6820 .chained = true,
6821 .chain_id = ALC662_FIXUP_SKU_IGNORE
6823 [ALC662_FIXUP_ASUS_MODE7] = {
6824 .type = ALC_FIXUP_PINS,
6825 .v.pins = (const struct alc_pincfg[]) {
6826 { 0x14, 0x99130110 }, /* speaker */
6827 { 0x17, 0x99130111 }, /* speaker */
6828 { 0x18, 0x01a19840 }, /* mic */
6829 { 0x19, 0x99a3094f }, /* int-mic */
6830 { 0x1b, 0x01214020 }, /* HP */
6831 { 0x21, 0x0121401f }, /* HP */
6834 .chained = true,
6835 .chain_id = ALC662_FIXUP_SKU_IGNORE
6837 [ALC662_FIXUP_ASUS_MODE8] = {
6838 .type = ALC_FIXUP_PINS,
6839 .v.pins = (const struct alc_pincfg[]) {
6840 { 0x14, 0x99130110 }, /* speaker */
6841 { 0x12, 0x99a30970 }, /* int-mic */
6842 { 0x15, 0x01214020 }, /* HP */
6843 { 0x17, 0x99130111 }, /* speaker */
6844 { 0x18, 0x01a19840 }, /* mic */
6845 { 0x21, 0x0121401f }, /* HP */
6848 .chained = true,
6849 .chain_id = ALC662_FIXUP_SKU_IGNORE
6851 [ALC662_FIXUP_NO_JACK_DETECT] = {
6852 .type = ALC_FIXUP_FUNC,
6853 .v.func = alc_fixup_no_jack_detect,
6855 [ALC662_FIXUP_ZOTAC_Z68] = {
6856 .type = ALC_FIXUP_PINS,
6857 .v.pins = (const struct alc_pincfg[]) {
6858 { 0x1b, 0x02214020 }, /* Front HP */
6862 [ALC662_FIXUP_INV_DMIC] = {
6863 .type = ALC_FIXUP_FUNC,
6864 .v.func = alc_fixup_inv_dmic_0x12,
6868 static const struct snd_pci_quirk alc662_fixup_tbl[] = {
6869 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
6870 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
6871 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
6872 SND_PCI_QUIRK(0x1025, 0x0349, "eMachines eM250", ALC662_FIXUP_INV_DMIC),
6873 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
6874 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
6875 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT),
6876 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
6877 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
6878 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
6879 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
6880 SND_PCI_QUIRK(0x19da, 0xa130, "Zotac Z68", ALC662_FIXUP_ZOTAC_Z68),
6881 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
6883 #if 0
6884 /* Below is a quirk table taken from the old code.
6885 * Basically the device should work as is without the fixup table.
6886 * If BIOS doesn't give a proper info, enable the corresponding
6887 * fixup entry.
6889 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
6890 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
6891 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
6892 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
6893 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6894 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6895 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6896 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
6897 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
6898 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6899 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
6900 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
6901 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
6902 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
6903 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
6904 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6905 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
6906 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
6907 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6908 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6909 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6910 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6911 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
6912 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
6913 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
6914 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6915 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
6916 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6917 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6918 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
6919 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6920 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6921 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
6922 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
6923 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
6924 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
6925 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
6926 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
6927 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
6928 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6929 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
6930 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
6931 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6932 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
6933 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
6934 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
6935 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
6936 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
6937 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6938 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
6939 #endif
6943 static const struct alc_model_fixup alc662_fixup_models[] = {
6944 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
6945 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
6946 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
6947 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
6948 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
6949 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
6950 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
6951 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
6952 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
6953 {.id = ALC662_FIXUP_INV_DMIC, .name = "inv-dmic"},
6957 static void alc662_fill_coef(struct hda_codec *codec)
6959 int val, coef;
6961 coef = alc_get_coef0(codec);
6963 switch (codec->vendor_id) {
6964 case 0x10ec0662:
6965 if ((coef & 0x00f0) == 0x0030) {
6966 val = alc_read_coef_idx(codec, 0x4); /* EAPD Ctrl */
6967 alc_write_coef_idx(codec, 0x4, val & ~(1<<10));
6969 break;
6970 case 0x10ec0272:
6971 case 0x10ec0273:
6972 case 0x10ec0663:
6973 case 0x10ec0665:
6974 case 0x10ec0670:
6975 case 0x10ec0671:
6976 case 0x10ec0672:
6977 val = alc_read_coef_idx(codec, 0xd); /* EAPD Ctrl */
6978 alc_write_coef_idx(codec, 0xd, val | (1<<14));
6979 break;
6985 static int patch_alc662(struct hda_codec *codec)
6987 struct alc_spec *spec;
6988 int err;
6990 err = alc_alloc_spec(codec, 0x0b);
6991 if (err < 0)
6992 return err;
6994 spec = codec->spec;
6996 /* handle multiple HPs as is */
6997 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
6999 alc_fix_pll_init(codec, 0x20, 0x04, 15);
7001 spec->init_hook = alc662_fill_coef;
7002 alc662_fill_coef(codec);
7004 alc_pick_fixup(codec, alc662_fixup_models,
7005 alc662_fixup_tbl, alc662_fixups);
7006 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
7008 alc_auto_parse_customize_define(codec);
7010 if ((alc_get_coef0(codec) & (1 << 14)) &&
7011 codec->bus->pci->subsystem_vendor == 0x1025 &&
7012 spec->cdefine.platform_type == 1) {
7013 if (alc_codec_rename(codec, "ALC272X") < 0)
7014 goto error;
7017 /* automatic parse from the BIOS config */
7018 err = alc662_parse_auto_config(codec);
7019 if (err < 0)
7020 goto error;
7022 if (!spec->no_analog && has_cdefine_beep(codec)) {
7023 err = snd_hda_attach_beep_device(codec, 0x1);
7024 if (err < 0)
7025 goto error;
7026 switch (codec->vendor_id) {
7027 case 0x10ec0662:
7028 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
7029 break;
7030 case 0x10ec0272:
7031 case 0x10ec0663:
7032 case 0x10ec0665:
7033 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
7034 break;
7035 case 0x10ec0273:
7036 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
7037 break;
7041 codec->patch_ops = alc_patch_ops;
7042 spec->shutup = alc_eapd_shutup;
7044 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
7046 return 0;
7048 error:
7049 alc_free(codec);
7050 return err;
7054 * ALC680 support
7057 static int alc680_parse_auto_config(struct hda_codec *codec)
7059 return alc_parse_auto_config(codec, NULL, NULL);
7064 static int patch_alc680(struct hda_codec *codec)
7066 int err;
7068 /* ALC680 has no aa-loopback mixer */
7069 err = alc_alloc_spec(codec, 0);
7070 if (err < 0)
7071 return err;
7073 /* automatic parse from the BIOS config */
7074 err = alc680_parse_auto_config(codec);
7075 if (err < 0) {
7076 alc_free(codec);
7077 return err;
7080 codec->patch_ops = alc_patch_ops;
7082 return 0;
7086 * patch entries
7088 static const struct hda_codec_preset snd_hda_preset_realtek[] = {
7089 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
7090 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
7091 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
7092 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
7093 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
7094 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
7095 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
7096 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
7097 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
7098 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
7099 { .id = 0x10ec0280, .name = "ALC280", .patch = patch_alc269 },
7100 { .id = 0x10ec0282, .name = "ALC282", .patch = patch_alc269 },
7101 { .id = 0x10ec0283, .name = "ALC283", .patch = patch_alc269 },
7102 { .id = 0x10ec0290, .name = "ALC290", .patch = patch_alc269 },
7103 { .id = 0x10ec0292, .name = "ALC292", .patch = patch_alc269 },
7104 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
7105 .patch = patch_alc861 },
7106 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
7107 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
7108 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
7109 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
7110 .patch = patch_alc882 },
7111 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
7112 .patch = patch_alc662 },
7113 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
7114 .patch = patch_alc662 },
7115 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
7116 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
7117 { .id = 0x10ec0668, .name = "ALC668", .patch = patch_alc662 },
7118 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
7119 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
7120 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
7121 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
7122 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
7123 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
7124 .patch = patch_alc882 },
7125 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
7126 .patch = patch_alc882 },
7127 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
7128 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
7129 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
7130 .patch = patch_alc882 },
7131 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
7132 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
7133 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
7134 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
7135 { .id = 0x10ec0900, .name = "ALC1150", .patch = patch_alc882 },
7136 {} /* terminator */
7139 MODULE_ALIAS("snd-hda-codec-id:10ec*");
7141 MODULE_LICENSE("GPL");
7142 MODULE_DESCRIPTION("Realtek HD-audio codec");
7144 static struct hda_codec_preset_list realtek_list = {
7145 .preset = snd_hda_preset_realtek,
7146 .owner = THIS_MODULE,
7149 static int __init patch_realtek_init(void)
7151 return snd_hda_add_codec_preset(&realtek_list);
7154 static void __exit patch_realtek_exit(void)
7156 snd_hda_delete_codec_preset(&realtek_list);
7159 module_init(patch_realtek_init)
7160 module_exit(patch_realtek_exit)