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"
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
46 #define GPIO_MASK 0x03
48 /* extra amp-initialization sequence types */
57 struct alc_customize_define
{
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;
66 unsigned int override
:1;
67 unsigned int fixup
:1; /* Means that this sku is set by driver, not read from hw */
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 */
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
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
;
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 */
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 */
141 unsigned int cur_adc_stream_tag
;
142 unsigned int cur_adc_format
;
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
;
153 const struct hda_channel_mode
*channel_mode
;
154 int num_channel_mode
;
156 int const_channel_count
;
157 int ext_channel_count
;
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
;
176 void (*init_hook
)(struct hda_codec
*codec
);
178 void (*power_hook
)(struct hda_codec
*codec
);
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 */
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 */
210 hda_nid_t automute_mixer_nid
[AUTO_CFG_MAX_OUTS
];
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
;
219 struct hda_loopback_check loopback
;
221 struct hda_amp_list loopback_list
[8];
226 unsigned int pll_coef_idx
, pll_coef_bit
;
231 struct alc_multi_io multi_io
[4];
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
)
242 if (get_wcaps(codec
, nid
) & (1 << (dir
+ 1)))
243 if (query_amp_caps(codec
, nid
, dir
) & bits
)
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)
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
)
264 if (!spec
->input_mux
[mux_idx
].num_items
&& 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
];
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
);
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
;
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
;
348 if (!spec
->input_mux
)
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
)
358 if (idx
>= imux
->num_items
)
359 idx
= imux
->num_items
- 1;
360 if (spec
->cur_mux
[adc_idx
] == idx
&& !force
)
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
);
375 num_conns
= snd_hda_get_num_conns(codec
, nid
);
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
,
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);
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
,
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
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
)))
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
;
468 snd_hda_codec_write(codec
, spec
->pll_nid
, 0, AC_VERB_SET_COEF_INDEX
,
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
,
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
;
483 spec
->pll_coef_idx
= coef_idx
;
484 spec
->pll_coef_bit
= coef_bit
;
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
)
497 for (i
= 0; i
< num_pins
; i
++) {
498 hda_nid_t nid
= pins
[i
];
501 present
|= snd_hda_jack_detect(codec
, nid
);
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
);
515 for (i
= 0; i
< num_pins
; i
++) {
516 hda_nid_t nid
= pins
[i
];
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);
532 snd_hda_set_pin_ctl(codec
, nid
, val
);
534 case ALC_AUTOMUTE_AMP
:
535 snd_hda_codec_amp_stereo(codec
, nid
, HDA_OUTPUT
, 0,
536 HDA_AMP_MUTE
, mute_bits
);
538 case ALC_AUTOMUTE_MIXER
:
539 nid
= spec
->automute_mixer_nid
[i
];
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
);
551 /* Toggle outputs muting */
552 static void update_outputs(struct hda_codec
*codec
)
554 struct alc_spec
*spec
= codec
->spec
;
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
)
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])
578 if (!spec
->automute_lo
)
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
);
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
))
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
)
616 /* check LO jack only when it's different from HP */
617 if (spec
->autocfg
.line_out_pins
[0] == spec
->autocfg
.hp_pins
[0])
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
)
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
)
639 if (snd_BUG_ON(!spec
->adc_nids
))
641 if (snd_BUG_ON(spec
->int_mic_idx
< 0 || spec
->ext_mic_idx
< 0))
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);
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
)
657 struct snd_kcontrol
*kctl
;
658 struct snd_ctl_elem_value
*uctl
;
660 kctl
= snd_hda_find_mixer_ctl(codec
, "Master Playback Volume");
663 uctl
= kzalloc(sizeof(*uctl
), GFP_KERNEL
);
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
);
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
)
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)
700 snd_hda_codec_read(codec
, 0x20, 0,
701 AC_VERB_SET_PROC_COEF
, 0x830);
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
)
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
)
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
,
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
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);
750 /* generic EAPD initialization */
751 static void alc_auto_init_amp(struct hda_codec
*codec
, int type
)
755 alc_auto_setup_eapd(codec
, true);
758 snd_hda_sequence_write(codec
, alc_gpio1_init_verbs
);
761 snd_hda_sequence_write(codec
, alc_gpio2_init_verbs
);
764 snd_hda_sequence_write(codec
, alc_gpio3_init_verbs
);
766 case ALC_INIT_DEFAULT
:
767 switch (codec
->vendor_id
) {
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
,
785 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
786 alc889_coef_init(codec
);
789 alc888_coef_init(codec
);
791 #if 0 /* XXX: This may cause the silent output on speaker on some machines */
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
,
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 texts2
[] = {
819 "Disabled", "Enabled"
821 static const char * const texts3
[] = {
822 "Disabled", "Speaker Only", "Line Out+Speaker"
824 const char * const *texts
;
826 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
828 if (spec
->automute_speaker_possible
&& spec
->automute_lo_possible
) {
829 uinfo
->value
.enumerated
.items
= 3;
832 uinfo
->value
.enumerated
.items
= 2;
835 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
)
836 uinfo
->value
.enumerated
.item
= uinfo
->value
.enumerated
.items
- 1;
837 strcpy(uinfo
->value
.enumerated
.name
,
838 texts
[uinfo
->value
.enumerated
.item
]);
842 static int alc_automute_mode_get(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
;
847 unsigned int val
= 0;
848 if (spec
->automute_speaker
)
850 if (spec
->automute_lo
)
853 ucontrol
->value
.enumerated
.item
[0] = val
;
857 static int alc_automute_mode_put(struct snd_kcontrol
*kcontrol
,
858 struct snd_ctl_elem_value
*ucontrol
)
860 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
861 struct alc_spec
*spec
= codec
->spec
;
863 switch (ucontrol
->value
.enumerated
.item
[0]) {
865 if (!spec
->automute_speaker
&& !spec
->automute_lo
)
867 spec
->automute_speaker
= 0;
868 spec
->automute_lo
= 0;
871 if (spec
->automute_speaker_possible
) {
872 if (!spec
->automute_lo
&& spec
->automute_speaker
)
874 spec
->automute_speaker
= 1;
875 spec
->automute_lo
= 0;
876 } else if (spec
->automute_lo_possible
) {
877 if (spec
->automute_lo
)
879 spec
->automute_lo
= 1;
884 if (!spec
->automute_lo_possible
|| !spec
->automute_speaker_possible
)
886 if (spec
->automute_speaker
&& spec
->automute_lo
)
888 spec
->automute_speaker
= 1;
889 spec
->automute_lo
= 1;
894 call_update_outputs(codec
);
898 static const struct snd_kcontrol_new alc_automute_mode_enum
= {
899 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
900 .name
= "Auto-Mute Mode",
901 .info
= alc_automute_mode_info
,
902 .get
= alc_automute_mode_get
,
903 .put
= alc_automute_mode_put
,
906 static struct snd_kcontrol_new
*
907 alc_kcontrol_new(struct alc_spec
*spec
, const char *name
,
908 const struct snd_kcontrol_new
*temp
)
910 struct snd_kcontrol_new
*knew
= snd_array_new(&spec
->kctls
);
914 knew
->name
= kstrdup(name
, GFP_KERNEL
);
920 static int alc_add_automute_mode_enum(struct hda_codec
*codec
)
922 struct alc_spec
*spec
= codec
->spec
;
924 if (!alc_kcontrol_new(spec
, "Auto-Mute Mode", &alc_automute_mode_enum
))
930 * Check the availability of HP/line-out auto-mute;
931 * Set up appropriately if really supported
933 static int alc_init_automute(struct hda_codec
*codec
)
935 struct alc_spec
*spec
= codec
->spec
;
936 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
942 if (cfg
->line_out_pins
[0])
944 if (cfg
->speaker_pins
[0])
946 if (present
< 2) /* need two different output types */
949 if (!cfg
->speaker_pins
[0] &&
950 cfg
->line_out_type
== AUTO_PIN_SPEAKER_OUT
) {
951 memcpy(cfg
->speaker_pins
, cfg
->line_out_pins
,
952 sizeof(cfg
->speaker_pins
));
953 cfg
->speaker_outs
= cfg
->line_outs
;
956 if (!cfg
->hp_pins
[0] &&
957 cfg
->line_out_type
== AUTO_PIN_HP_OUT
) {
958 memcpy(cfg
->hp_pins
, cfg
->line_out_pins
,
959 sizeof(cfg
->hp_pins
));
960 cfg
->hp_outs
= cfg
->line_outs
;
963 spec
->automute_mode
= ALC_AUTOMUTE_PIN
;
965 for (i
= 0; i
< cfg
->hp_outs
; i
++) {
966 hda_nid_t nid
= cfg
->hp_pins
[i
];
967 if (!is_jack_detectable(codec
, nid
))
969 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
971 snd_hda_jack_detect_enable_callback(codec
, nid
, ALC_HP_EVENT
,
976 if (cfg
->line_out_type
== AUTO_PIN_LINE_OUT
&& cfg
->line_outs
) {
977 if (cfg
->speaker_outs
)
978 for (i
= 0; i
< cfg
->line_outs
; i
++) {
979 hda_nid_t nid
= cfg
->line_out_pins
[i
];
980 if (!is_jack_detectable(codec
, nid
))
982 snd_printdd("realtek: Enable Line-Out "
983 "auto-muting on NID 0x%x\n", nid
);
984 snd_hda_jack_detect_enable_callback(codec
, nid
, ALC_FRONT_EVENT
,
988 spec
->automute_lo_possible
= spec
->detect_hp
;
991 spec
->automute_speaker_possible
= cfg
->speaker_outs
&&
992 (spec
->detect_hp
|| spec
->detect_lo
);
994 spec
->automute_lo
= spec
->automute_lo_possible
;
995 spec
->automute_speaker
= spec
->automute_speaker_possible
;
997 if (spec
->automute_speaker_possible
|| spec
->automute_lo_possible
) {
998 /* create a control for automute mode */
999 err
= alc_add_automute_mode_enum(codec
);
1006 /* return the position of NID in the list, or -1 if not found */
1007 static int find_idx_in_nid_list(hda_nid_t nid
, const hda_nid_t
*list
, int nums
)
1010 for (i
= 0; i
< nums
; i
++)
1016 /* check whether dynamic ADC-switching is available */
1017 static bool alc_check_dyn_adc_switch(struct hda_codec
*codec
)
1019 struct alc_spec
*spec
= codec
->spec
;
1020 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
1024 if (imux
!= spec
->input_mux
) /* no dynamic imux? */
1027 for (n
= 0; n
< spec
->num_adc_nids
; n
++) {
1028 cap
= spec
->private_capsrc_nids
[n
];
1029 for (i
= 0; i
< imux
->num_items
; i
++) {
1030 pin
= spec
->imux_pins
[i
];
1033 if (get_connection_index(codec
, cap
, pin
) < 0)
1036 if (i
>= imux
->num_items
)
1037 return true; /* no ADC-switch is needed */
1040 for (i
= 0; i
< imux
->num_items
; i
++) {
1041 pin
= spec
->imux_pins
[i
];
1042 for (n
= 0; n
< spec
->num_adc_nids
; n
++) {
1043 cap
= spec
->private_capsrc_nids
[n
];
1044 idx
= get_connection_index(codec
, cap
, pin
);
1046 imux
->items
[i
].index
= idx
;
1047 spec
->dyn_adc_idx
[i
] = n
;
1053 snd_printdd("realtek: enabling ADC switching\n");
1054 spec
->dyn_adc_switch
= 1;
1058 /* check whether all auto-mic pins are valid; setup indices if OK */
1059 static bool alc_auto_mic_check_imux(struct hda_codec
*codec
)
1061 struct alc_spec
*spec
= codec
->spec
;
1062 const struct hda_input_mux
*imux
;
1064 if (!spec
->auto_mic
)
1066 if (spec
->auto_mic_valid_imux
)
1067 return true; /* already checked */
1069 /* fill up imux indices */
1070 if (!alc_check_dyn_adc_switch(codec
)) {
1075 imux
= spec
->input_mux
;
1076 spec
->ext_mic_idx
= find_idx_in_nid_list(spec
->ext_mic_pin
,
1077 spec
->imux_pins
, imux
->num_items
);
1078 spec
->int_mic_idx
= find_idx_in_nid_list(spec
->int_mic_pin
,
1079 spec
->imux_pins
, imux
->num_items
);
1080 spec
->dock_mic_idx
= find_idx_in_nid_list(spec
->dock_mic_pin
,
1081 spec
->imux_pins
, imux
->num_items
);
1082 if (spec
->ext_mic_idx
< 0 || spec
->int_mic_idx
< 0) {
1084 return false; /* no corresponding imux */
1087 snd_hda_jack_detect_enable_callback(codec
, spec
->ext_mic_pin
,
1088 ALC_MIC_EVENT
, alc_mic_automute
);
1089 if (spec
->dock_mic_pin
)
1090 snd_hda_jack_detect_enable_callback(codec
, spec
->dock_mic_pin
,
1094 spec
->auto_mic_valid_imux
= 1;
1100 * Check the availability of auto-mic switch;
1101 * Set up if really supported
1103 static int alc_init_auto_mic(struct hda_codec
*codec
)
1105 struct alc_spec
*spec
= codec
->spec
;
1106 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
1107 hda_nid_t fixed
, ext
, dock
;
1110 if (spec
->shared_mic_hp
)
1111 return 0; /* no auto-mic for the shared I/O */
1113 spec
->ext_mic_idx
= spec
->int_mic_idx
= spec
->dock_mic_idx
= -1;
1115 fixed
= ext
= dock
= 0;
1116 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
1117 hda_nid_t nid
= cfg
->inputs
[i
].pin
;
1118 unsigned int defcfg
;
1119 defcfg
= snd_hda_codec_get_pincfg(codec
, nid
);
1120 switch (snd_hda_get_input_pin_attr(defcfg
)) {
1121 case INPUT_PIN_ATTR_INT
:
1123 return 0; /* already occupied */
1124 if (cfg
->inputs
[i
].type
!= AUTO_PIN_MIC
)
1125 return 0; /* invalid type */
1128 case INPUT_PIN_ATTR_UNUSED
:
1129 return 0; /* invalid entry */
1130 case INPUT_PIN_ATTR_DOCK
:
1132 return 0; /* already occupied */
1133 if (cfg
->inputs
[i
].type
> AUTO_PIN_LINE_IN
)
1134 return 0; /* invalid type */
1139 return 0; /* already occupied */
1140 if (cfg
->inputs
[i
].type
!= AUTO_PIN_MIC
)
1141 return 0; /* invalid type */
1152 if (!is_jack_detectable(codec
, ext
))
1153 return 0; /* no unsol support */
1154 if (dock
&& !is_jack_detectable(codec
, dock
))
1155 return 0; /* no unsol support */
1157 /* check imux indices */
1158 spec
->ext_mic_pin
= ext
;
1159 spec
->int_mic_pin
= fixed
;
1160 spec
->dock_mic_pin
= dock
;
1163 if (!alc_auto_mic_check_imux(codec
))
1166 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1172 /* check the availabilities of auto-mute and auto-mic switches */
1173 static int alc_auto_check_switches(struct hda_codec
*codec
)
1177 err
= alc_init_automute(codec
);
1180 err
= alc_init_auto_mic(codec
);
1187 * Realtek SSID verification
1190 /* Could be any non-zero and even value. When used as fixup, tells
1191 * the driver to ignore any present sku defines.
1193 #define ALC_FIXUP_SKU_IGNORE (2)
1195 static void alc_fixup_sku_ignore(struct hda_codec
*codec
,
1196 const struct hda_fixup
*fix
, int action
)
1198 struct alc_spec
*spec
= codec
->spec
;
1199 if (action
== HDA_FIXUP_ACT_PRE_PROBE
) {
1200 spec
->cdefine
.fixup
= 1;
1201 spec
->cdefine
.sku_cfg
= ALC_FIXUP_SKU_IGNORE
;
1205 static int alc_auto_parse_customize_define(struct hda_codec
*codec
)
1207 unsigned int ass
, tmp
, i
;
1209 struct alc_spec
*spec
= codec
->spec
;
1211 spec
->cdefine
.enable_pcbeep
= 1; /* assume always enabled */
1213 if (spec
->cdefine
.fixup
) {
1214 ass
= spec
->cdefine
.sku_cfg
;
1215 if (ass
== ALC_FIXUP_SKU_IGNORE
)
1220 ass
= codec
->subsystem_id
& 0xffff;
1221 if (ass
!= codec
->bus
->pci
->subsystem_device
&& (ass
& 1))
1225 if (codec
->vendor_id
== 0x10ec0260)
1227 ass
= snd_hda_codec_get_pincfg(codec
, nid
);
1230 printk(KERN_INFO
"hda_codec: %s: SKU not ready 0x%08x\n",
1231 codec
->chip_name
, ass
);
1237 for (i
= 1; i
< 16; i
++) {
1241 if (((ass
>> 16) & 0xf) != tmp
)
1244 spec
->cdefine
.port_connectivity
= ass
>> 30;
1245 spec
->cdefine
.enable_pcbeep
= (ass
& 0x100000) >> 20;
1246 spec
->cdefine
.check_sum
= (ass
>> 16) & 0xf;
1247 spec
->cdefine
.customization
= ass
>> 8;
1249 spec
->cdefine
.sku_cfg
= ass
;
1250 spec
->cdefine
.external_amp
= (ass
& 0x38) >> 3;
1251 spec
->cdefine
.platform_type
= (ass
& 0x4) >> 2;
1252 spec
->cdefine
.swap
= (ass
& 0x2) >> 1;
1253 spec
->cdefine
.override
= ass
& 0x1;
1255 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1256 nid
, spec
->cdefine
.sku_cfg
);
1257 snd_printd("SKU: port_connectivity=0x%x\n",
1258 spec
->cdefine
.port_connectivity
);
1259 snd_printd("SKU: enable_pcbeep=0x%x\n", spec
->cdefine
.enable_pcbeep
);
1260 snd_printd("SKU: check_sum=0x%08x\n", spec
->cdefine
.check_sum
);
1261 snd_printd("SKU: customization=0x%08x\n", spec
->cdefine
.customization
);
1262 snd_printd("SKU: external_amp=0x%x\n", spec
->cdefine
.external_amp
);
1263 snd_printd("SKU: platform_type=0x%x\n", spec
->cdefine
.platform_type
);
1264 snd_printd("SKU: swap=0x%x\n", spec
->cdefine
.swap
);
1265 snd_printd("SKU: override=0x%x\n", spec
->cdefine
.override
);
1270 /* return true if the given NID is found in the list */
1271 static bool found_in_nid_list(hda_nid_t nid
, const hda_nid_t
*list
, int nums
)
1273 return find_idx_in_nid_list(nid
, list
, nums
) >= 0;
1276 /* check subsystem ID and set up device-specific initialization;
1277 * return 1 if initialized, 0 if invalid SSID
1279 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1280 * 31 ~ 16 : Manufacture ID
1282 * 7 ~ 0 : Assembly ID
1283 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1285 static int alc_subsystem_id(struct hda_codec
*codec
,
1286 hda_nid_t porta
, hda_nid_t porte
,
1287 hda_nid_t portd
, hda_nid_t porti
)
1289 unsigned int ass
, tmp
, i
;
1291 struct alc_spec
*spec
= codec
->spec
;
1293 if (spec
->cdefine
.fixup
) {
1294 ass
= spec
->cdefine
.sku_cfg
;
1295 if (ass
== ALC_FIXUP_SKU_IGNORE
)
1300 ass
= codec
->subsystem_id
& 0xffff;
1301 if ((ass
!= codec
->bus
->pci
->subsystem_device
) && (ass
& 1))
1304 /* invalid SSID, check the special NID pin defcfg instead */
1306 * 31~30 : port connectivity
1309 * 19~16 : Check sum (15:1)
1314 if (codec
->vendor_id
== 0x10ec0260)
1316 ass
= snd_hda_codec_get_pincfg(codec
, nid
);
1317 snd_printd("realtek: No valid SSID, "
1318 "checking pincfg 0x%08x for NID 0x%x\n",
1322 if ((ass
>> 30) != 1) /* no physical connection */
1327 for (i
= 1; i
< 16; i
++) {
1331 if (((ass
>> 16) & 0xf) != tmp
)
1334 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1335 ass
& 0xffff, codec
->vendor_id
);
1339 * 2 : 0 --> Desktop, 1 --> Laptop
1340 * 3~5 : External Amplifier control
1343 tmp
= (ass
& 0x38) >> 3; /* external Amp control */
1346 spec
->init_amp
= ALC_INIT_GPIO1
;
1349 spec
->init_amp
= ALC_INIT_GPIO2
;
1352 spec
->init_amp
= ALC_INIT_GPIO3
;
1356 spec
->init_amp
= ALC_INIT_DEFAULT
;
1360 /* is laptop or Desktop and enable the function "Mute internal speaker
1361 * when the external headphone out jack is plugged"
1363 if (!(ass
& 0x8000))
1366 * 10~8 : Jack location
1367 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1369 * 15 : 1 --> enable the function "Mute internal speaker
1370 * when the external headphone out jack is plugged"
1372 if (!spec
->autocfg
.hp_pins
[0] &&
1373 !(spec
->autocfg
.line_out_pins
[0] &&
1374 spec
->autocfg
.line_out_type
== AUTO_PIN_HP_OUT
)) {
1376 tmp
= (ass
>> 11) & 0x3; /* HP to chassis */
1387 if (found_in_nid_list(nid
, spec
->autocfg
.line_out_pins
,
1388 spec
->autocfg
.line_outs
))
1390 spec
->autocfg
.hp_pins
[0] = nid
;
1395 /* Check the validity of ALC subsystem-id
1396 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1397 static void alc_ssid_check(struct hda_codec
*codec
, const hda_nid_t
*ports
)
1399 if (!alc_subsystem_id(codec
, ports
[0], ports
[1], ports
[2], ports
[3])) {
1400 struct alc_spec
*spec
= codec
->spec
;
1401 snd_printd("realtek: "
1402 "Enable default setup for auto mode as fallback\n");
1403 spec
->init_amp
= ALC_INIT_DEFAULT
;
1408 * COEF access helper functions
1410 static int alc_read_coef_idx(struct hda_codec
*codec
,
1411 unsigned int coef_idx
)
1414 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_COEF_INDEX
,
1416 val
= snd_hda_codec_read(codec
, 0x20, 0,
1417 AC_VERB_GET_PROC_COEF
, 0);
1421 static void alc_write_coef_idx(struct hda_codec
*codec
, unsigned int coef_idx
,
1422 unsigned int coef_val
)
1424 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_COEF_INDEX
,
1426 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_PROC_COEF
,
1430 /* a special bypass for COEF 0; read the cached value at the second time */
1431 static unsigned int alc_get_coef0(struct hda_codec
*codec
)
1433 struct alc_spec
*spec
= codec
->spec
;
1435 spec
->coef0
= alc_read_coef_idx(codec
, 0);
1440 * Digital I/O handling
1443 /* set right pin controls for digital I/O */
1444 static void alc_auto_init_digital(struct hda_codec
*codec
)
1446 struct alc_spec
*spec
= codec
->spec
;
1450 for (i
= 0; i
< spec
->autocfg
.dig_outs
; i
++) {
1451 pin
= spec
->autocfg
.dig_out_pins
[i
];
1454 snd_hda_set_pin_ctl(codec
, pin
, PIN_OUT
);
1456 dac
= spec
->multiout
.dig_out_nid
;
1458 dac
= spec
->slave_dig_outs
[i
- 1];
1459 if (!dac
|| !(get_wcaps(codec
, dac
) & AC_WCAP_OUT_AMP
))
1461 snd_hda_codec_write(codec
, dac
, 0,
1462 AC_VERB_SET_AMP_GAIN_MUTE
,
1465 pin
= spec
->autocfg
.dig_in_pin
;
1467 snd_hda_set_pin_ctl(codec
, pin
, PIN_IN
);
1470 /* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1471 static void alc_auto_parse_digital(struct hda_codec
*codec
)
1473 struct alc_spec
*spec
= codec
->spec
;
1477 /* support multiple SPDIFs; the secondary is set up as a slave */
1479 for (i
= 0; i
< spec
->autocfg
.dig_outs
; i
++) {
1481 err
= snd_hda_get_connections(codec
,
1482 spec
->autocfg
.dig_out_pins
[i
],
1483 conn
, ARRAY_SIZE(conn
));
1486 dig_nid
= conn
[0]; /* assume the first element is audio-out */
1488 spec
->multiout
.dig_out_nid
= dig_nid
;
1489 spec
->dig_out_type
= spec
->autocfg
.dig_out_type
[0];
1491 spec
->multiout
.slave_dig_outs
= spec
->slave_dig_outs
;
1492 if (nums
>= ARRAY_SIZE(spec
->slave_dig_outs
) - 1)
1494 spec
->slave_dig_outs
[nums
- 1] = dig_nid
;
1499 if (spec
->autocfg
.dig_in_pin
) {
1500 dig_nid
= codec
->start_nid
;
1501 for (i
= 0; i
< codec
->num_nodes
; i
++, dig_nid
++) {
1502 unsigned int wcaps
= get_wcaps(codec
, dig_nid
);
1503 if (get_wcaps_type(wcaps
) != AC_WID_AUD_IN
)
1505 if (!(wcaps
& AC_WCAP_DIGITAL
))
1507 if (!(wcaps
& AC_WCAP_CONN_LIST
))
1509 err
= get_connection_index(codec
, dig_nid
,
1510 spec
->autocfg
.dig_in_pin
);
1512 spec
->dig_in_nid
= dig_nid
;
1520 * capture mixer elements
1522 static int alc_cap_vol_info(struct snd_kcontrol
*kcontrol
,
1523 struct snd_ctl_elem_info
*uinfo
)
1525 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1526 struct alc_spec
*spec
= codec
->spec
;
1530 mutex_lock(&codec
->control_mutex
);
1531 if (spec
->vol_in_capsrc
)
1532 val
= HDA_COMPOSE_AMP_VAL(spec
->capsrc_nids
[0], 3, 0, HDA_OUTPUT
);
1534 val
= HDA_COMPOSE_AMP_VAL(spec
->adc_nids
[0], 3, 0, HDA_INPUT
);
1535 kcontrol
->private_value
= val
;
1536 err
= snd_hda_mixer_amp_volume_info(kcontrol
, uinfo
);
1537 mutex_unlock(&codec
->control_mutex
);
1541 static int alc_cap_vol_tlv(struct snd_kcontrol
*kcontrol
, int op_flag
,
1542 unsigned int size
, unsigned int __user
*tlv
)
1544 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1545 struct alc_spec
*spec
= codec
->spec
;
1549 mutex_lock(&codec
->control_mutex
);
1550 if (spec
->vol_in_capsrc
)
1551 val
= HDA_COMPOSE_AMP_VAL(spec
->capsrc_nids
[0], 3, 0, HDA_OUTPUT
);
1553 val
= HDA_COMPOSE_AMP_VAL(spec
->adc_nids
[0], 3, 0, HDA_INPUT
);
1554 kcontrol
->private_value
= val
;
1555 err
= snd_hda_mixer_amp_tlv(kcontrol
, op_flag
, size
, tlv
);
1556 mutex_unlock(&codec
->control_mutex
);
1560 typedef int (*getput_call_t
)(struct snd_kcontrol
*kcontrol
,
1561 struct snd_ctl_elem_value
*ucontrol
);
1563 static int alc_cap_getput_caller(struct snd_kcontrol
*kcontrol
,
1564 struct snd_ctl_elem_value
*ucontrol
,
1565 getput_call_t func
, bool is_put
)
1567 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1568 struct alc_spec
*spec
= codec
->spec
;
1571 mutex_lock(&codec
->control_mutex
);
1572 if (is_put
&& spec
->dyn_adc_switch
) {
1573 for (i
= 0; i
< spec
->num_adc_nids
; i
++) {
1574 kcontrol
->private_value
=
1575 HDA_COMPOSE_AMP_VAL(spec
->adc_nids
[i
],
1577 err
= func(kcontrol
, ucontrol
);
1582 i
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
1583 if (spec
->vol_in_capsrc
)
1584 kcontrol
->private_value
=
1585 HDA_COMPOSE_AMP_VAL(spec
->capsrc_nids
[i
],
1588 kcontrol
->private_value
=
1589 HDA_COMPOSE_AMP_VAL(spec
->adc_nids
[i
],
1591 err
= func(kcontrol
, ucontrol
);
1593 if (err
>= 0 && is_put
)
1594 alc_inv_dmic_sync(codec
, false);
1596 mutex_unlock(&codec
->control_mutex
);
1600 static int alc_cap_vol_get(struct snd_kcontrol
*kcontrol
,
1601 struct snd_ctl_elem_value
*ucontrol
)
1603 return alc_cap_getput_caller(kcontrol
, ucontrol
,
1604 snd_hda_mixer_amp_volume_get
, false);
1607 static int alc_cap_vol_put(struct snd_kcontrol
*kcontrol
,
1608 struct snd_ctl_elem_value
*ucontrol
)
1610 return alc_cap_getput_caller(kcontrol
, ucontrol
,
1611 snd_hda_mixer_amp_volume_put
, true);
1614 /* capture mixer elements */
1615 #define alc_cap_sw_info snd_ctl_boolean_stereo_info
1617 static int alc_cap_sw_get(struct snd_kcontrol
*kcontrol
,
1618 struct snd_ctl_elem_value
*ucontrol
)
1620 return alc_cap_getput_caller(kcontrol
, ucontrol
,
1621 snd_hda_mixer_amp_switch_get
, false);
1624 static int alc_cap_sw_put(struct snd_kcontrol
*kcontrol
,
1625 struct snd_ctl_elem_value
*ucontrol
)
1627 return alc_cap_getput_caller(kcontrol
, ucontrol
,
1628 snd_hda_mixer_amp_switch_put
, true);
1631 #define _DEFINE_CAPMIX(num) \
1633 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1634 .name = "Capture Switch", \
1635 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1637 .info = alc_cap_sw_info, \
1638 .get = alc_cap_sw_get, \
1639 .put = alc_cap_sw_put, \
1642 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1643 .name = "Capture Volume", \
1644 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1645 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1646 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1648 .info = alc_cap_vol_info, \
1649 .get = alc_cap_vol_get, \
1650 .put = alc_cap_vol_put, \
1651 .tlv = { .c = alc_cap_vol_tlv }, \
1654 #define _DEFINE_CAPSRC(num) \
1656 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1657 /* .name = "Capture Source", */ \
1658 .name = "Input Source", \
1660 .info = alc_mux_enum_info, \
1661 .get = alc_mux_enum_get, \
1662 .put = alc_mux_enum_put, \
1665 #define DEFINE_CAPMIX(num) \
1666 static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
1667 _DEFINE_CAPMIX(num), \
1668 _DEFINE_CAPSRC(num), \
1672 #define DEFINE_CAPMIX_NOSRC(num) \
1673 static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
1674 _DEFINE_CAPMIX(num), \
1678 /* up to three ADCs */
1682 DEFINE_CAPMIX_NOSRC(1);
1683 DEFINE_CAPMIX_NOSRC(2);
1684 DEFINE_CAPMIX_NOSRC(3);
1687 * Inverted digital-mic handling
1689 * First off, it's a bit tricky. The "Inverted Internal Mic Capture Switch"
1690 * gives the additional mute only to the right channel of the digital mic
1691 * capture stream. This is a workaround for avoiding the almost silence
1692 * by summing the stereo stream from some (known to be ForteMedia)
1695 * The logic is to call alc_inv_dmic_sync() after each action (possibly)
1696 * modifying ADC amp. When the mute flag is set, it mutes the R-channel
1697 * without caching so that the cache can still keep the original value.
1698 * The cached value is then restored when the flag is set off or any other
1699 * than d-mic is used as the current input source.
1701 static void alc_inv_dmic_sync(struct hda_codec
*codec
, bool force
)
1703 struct alc_spec
*spec
= codec
->spec
;
1706 if (!spec
->inv_dmic_fixup
)
1708 if (!spec
->inv_dmic_muted
&& !force
)
1710 for (i
= 0; i
< spec
->num_adc_nids
; i
++) {
1711 int src
= spec
->dyn_adc_switch
? 0 : i
;
1712 bool dmic_fixup
= false;
1716 if (spec
->inv_dmic_muted
&&
1717 spec
->imux_pins
[spec
->cur_mux
[src
]] == spec
->inv_dmic_pin
)
1719 if (!dmic_fixup
&& !force
)
1721 if (spec
->vol_in_capsrc
) {
1722 nid
= spec
->capsrc_nids
[i
];
1723 parm
= AC_AMP_SET_RIGHT
| AC_AMP_SET_OUTPUT
;
1726 nid
= spec
->adc_nids
[i
];
1727 parm
= AC_AMP_SET_RIGHT
| AC_AMP_SET_INPUT
;
1730 /* we care only right channel */
1731 v
= snd_hda_codec_amp_read(codec
, nid
, 1, dir
, 0);
1732 if (v
& 0x80) /* if already muted, we don't need to touch */
1734 if (dmic_fixup
) /* add mute for d-mic */
1736 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
1741 static int alc_inv_dmic_sw_get(struct snd_kcontrol
*kcontrol
,
1742 struct snd_ctl_elem_value
*ucontrol
)
1744 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1745 struct alc_spec
*spec
= codec
->spec
;
1747 ucontrol
->value
.integer
.value
[0] = !spec
->inv_dmic_muted
;
1751 static int alc_inv_dmic_sw_put(struct snd_kcontrol
*kcontrol
,
1752 struct snd_ctl_elem_value
*ucontrol
)
1754 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1755 struct alc_spec
*spec
= codec
->spec
;
1756 unsigned int val
= !ucontrol
->value
.integer
.value
[0];
1758 if (val
== spec
->inv_dmic_muted
)
1760 spec
->inv_dmic_muted
= val
;
1761 alc_inv_dmic_sync(codec
, true);
1765 static const struct snd_kcontrol_new alc_inv_dmic_sw
= {
1766 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1767 .info
= snd_ctl_boolean_mono_info
,
1768 .get
= alc_inv_dmic_sw_get
,
1769 .put
= alc_inv_dmic_sw_put
,
1772 static int alc_add_inv_dmic_mixer(struct hda_codec
*codec
, hda_nid_t nid
)
1774 struct alc_spec
*spec
= codec
->spec
;
1776 if (!alc_kcontrol_new(spec
, "Inverted Internal Mic Capture Switch",
1779 spec
->inv_dmic_fixup
= 1;
1780 spec
->inv_dmic_muted
= 0;
1781 spec
->inv_dmic_pin
= nid
;
1785 /* typically the digital mic is put at node 0x12 */
1786 static void alc_fixup_inv_dmic_0x12(struct hda_codec
*codec
,
1787 const struct alc_fixup
*fix
, int action
)
1789 if (action
== ALC_FIXUP_ACT_PROBE
)
1790 alc_add_inv_dmic_mixer(codec
, 0x12);
1794 * virtual master controls
1798 * slave controls for virtual master
1800 static const char * const alc_slave_pfxs
[] = {
1801 "Front", "Surround", "Center", "LFE", "Side",
1802 "Headphone", "Speaker", "Mono", "Line Out",
1803 "CLFE", "Bass Speaker", "PCM",
1808 * build control elements
1811 #define NID_MAPPING (-1)
1813 #define SUBDEV_SPEAKER_ (0 << 6)
1814 #define SUBDEV_HP_ (1 << 6)
1815 #define SUBDEV_LINE_ (2 << 6)
1816 #define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1817 #define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1818 #define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1820 static void alc_free_kctls(struct hda_codec
*codec
);
1822 #ifdef CONFIG_SND_HDA_INPUT_BEEP
1823 /* additional beep mixers; the actual parameters are overwritten at build */
1824 static const struct snd_kcontrol_new alc_beep_mixer
[] = {
1825 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT
),
1826 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT
),
1831 static int __alc_build_controls(struct hda_codec
*codec
)
1833 struct alc_spec
*spec
= codec
->spec
;
1834 struct snd_kcontrol
*kctl
= NULL
;
1835 const struct snd_kcontrol_new
*knew
;
1840 for (i
= 0; i
< spec
->num_mixers
; i
++) {
1841 err
= snd_hda_add_new_ctls(codec
, spec
->mixers
[i
]);
1845 if (spec
->cap_mixer
) {
1846 err
= snd_hda_add_new_ctls(codec
, spec
->cap_mixer
);
1850 if (spec
->multiout
.dig_out_nid
) {
1851 err
= snd_hda_create_dig_out_ctls(codec
,
1852 spec
->multiout
.dig_out_nid
,
1853 spec
->multiout
.dig_out_nid
,
1854 spec
->pcm_rec
[1].pcm_type
);
1857 if (!spec
->no_analog
) {
1858 err
= snd_hda_create_spdif_share_sw(codec
,
1862 spec
->multiout
.share_spdif
= 1;
1865 if (spec
->dig_in_nid
) {
1866 err
= snd_hda_create_spdif_in_ctls(codec
, spec
->dig_in_nid
);
1871 #ifdef CONFIG_SND_HDA_INPUT_BEEP
1872 /* create beep controls if needed */
1873 if (spec
->beep_amp
) {
1874 const struct snd_kcontrol_new
*knew
;
1875 for (knew
= alc_beep_mixer
; knew
->name
; knew
++) {
1876 struct snd_kcontrol
*kctl
;
1877 kctl
= snd_ctl_new1(knew
, codec
);
1880 kctl
->private_value
= spec
->beep_amp
;
1881 err
= snd_hda_ctl_add(codec
, 0, kctl
);
1888 /* if we have no master control, let's create it */
1889 if (!spec
->no_analog
&&
1890 !snd_hda_find_mixer_ctl(codec
, "Master Playback Volume")) {
1891 unsigned int vmaster_tlv
[4];
1892 snd_hda_set_vmaster_tlv(codec
, spec
->vmaster_nid
,
1893 HDA_OUTPUT
, vmaster_tlv
);
1894 err
= snd_hda_add_vmaster(codec
, "Master Playback Volume",
1895 vmaster_tlv
, alc_slave_pfxs
,
1900 if (!spec
->no_analog
&&
1901 !snd_hda_find_mixer_ctl(codec
, "Master Playback Switch")) {
1902 err
= __snd_hda_add_vmaster(codec
, "Master Playback Switch",
1903 NULL
, alc_slave_pfxs
,
1905 true, &spec
->vmaster_mute
.sw_kctl
);
1910 /* assign Capture Source enums to NID */
1911 if (spec
->capsrc_nids
|| spec
->adc_nids
) {
1912 kctl
= snd_hda_find_mixer_ctl(codec
, "Capture Source");
1914 kctl
= snd_hda_find_mixer_ctl(codec
, "Input Source");
1915 for (i
= 0; kctl
&& i
< kctl
->count
; i
++) {
1916 err
= snd_hda_add_nid(codec
, kctl
, i
,
1917 get_capsrc(spec
, i
));
1922 if (spec
->cap_mixer
&& spec
->adc_nids
) {
1923 const char *kname
= kctl
? kctl
->id
.name
: NULL
;
1924 for (knew
= spec
->cap_mixer
; knew
->name
; knew
++) {
1925 if (kname
&& strcmp(knew
->name
, kname
) == 0)
1927 kctl
= snd_hda_find_mixer_ctl(codec
, knew
->name
);
1928 for (i
= 0; kctl
&& i
< kctl
->count
; i
++) {
1929 err
= snd_hda_add_nid(codec
, kctl
, i
,
1937 /* other nid->control mapping */
1938 for (i
= 0; i
< spec
->num_mixers
; i
++) {
1939 for (knew
= spec
->mixers
[i
]; knew
->name
; knew
++) {
1940 if (knew
->iface
!= NID_MAPPING
)
1942 kctl
= snd_hda_find_mixer_ctl(codec
, knew
->name
);
1945 u
= knew
->subdevice
;
1946 for (j
= 0; j
< 4; j
++, u
>>= 8) {
1951 case SUBDEV_SPEAKER_
:
1952 nid
= spec
->autocfg
.speaker_pins
[nid
];
1955 nid
= spec
->autocfg
.line_out_pins
[nid
];
1958 nid
= spec
->autocfg
.hp_pins
[nid
];
1963 err
= snd_hda_add_nid(codec
, kctl
, 0, nid
);
1967 u
= knew
->private_value
;
1968 for (j
= 0; j
< 4; j
++, u
>>= 8) {
1972 err
= snd_hda_add_nid(codec
, kctl
, 0, nid
);
1979 alc_free_kctls(codec
); /* no longer needed */
1984 static int alc_build_jacks(struct hda_codec
*codec
)
1986 struct alc_spec
*spec
= codec
->spec
;
1988 if (spec
->shared_mic_hp
) {
1990 int nid
= spec
->autocfg
.inputs
[1].pin
;
1991 err
= snd_hda_jack_add_kctl(codec
, nid
, "Headphone Mic", 0);
1994 err
= snd_hda_jack_detect_enable(codec
, nid
, 0);
1999 return snd_hda_jack_add_kctls(codec
, &spec
->autocfg
);
2002 static int alc_build_controls(struct hda_codec
*codec
)
2004 int err
= __alc_build_controls(codec
);
2008 err
= alc_build_jacks(codec
);
2011 alc_apply_fixup(codec
, ALC_FIXUP_ACT_BUILD
);
2020 static void alc_init_special_input_src(struct hda_codec
*codec
);
2021 static void alc_auto_init_std(struct hda_codec
*codec
);
2023 static int alc_init(struct hda_codec
*codec
)
2025 struct alc_spec
*spec
= codec
->spec
;
2027 if (spec
->init_hook
)
2028 spec
->init_hook(codec
);
2031 alc_auto_init_amp(codec
, spec
->init_amp
);
2033 snd_hda_gen_apply_verbs(codec
);
2034 alc_init_special_input_src(codec
);
2035 alc_auto_init_std(codec
);
2037 alc_apply_fixup(codec
, ALC_FIXUP_ACT_INIT
);
2039 hda_call_check_power_status(codec
, 0x01);
2044 static int alc_check_power_status(struct hda_codec
*codec
, hda_nid_t nid
)
2046 struct alc_spec
*spec
= codec
->spec
;
2047 return snd_hda_check_amp_list_power(codec
, &spec
->loopback
, nid
);
2052 * Analog playback callbacks
2054 static int alc_playback_pcm_open(struct hda_pcm_stream
*hinfo
,
2055 struct hda_codec
*codec
,
2056 struct snd_pcm_substream
*substream
)
2058 struct alc_spec
*spec
= codec
->spec
;
2059 return snd_hda_multi_out_analog_open(codec
, &spec
->multiout
, substream
,
2063 static int alc_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
2064 struct hda_codec
*codec
,
2065 unsigned int stream_tag
,
2066 unsigned int format
,
2067 struct snd_pcm_substream
*substream
)
2069 struct alc_spec
*spec
= codec
->spec
;
2070 return snd_hda_multi_out_analog_prepare(codec
, &spec
->multiout
,
2071 stream_tag
, format
, substream
);
2074 static int alc_playback_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
2075 struct hda_codec
*codec
,
2076 struct snd_pcm_substream
*substream
)
2078 struct alc_spec
*spec
= codec
->spec
;
2079 return snd_hda_multi_out_analog_cleanup(codec
, &spec
->multiout
);
2085 static int alc_dig_playback_pcm_open(struct hda_pcm_stream
*hinfo
,
2086 struct hda_codec
*codec
,
2087 struct snd_pcm_substream
*substream
)
2089 struct alc_spec
*spec
= codec
->spec
;
2090 return snd_hda_multi_out_dig_open(codec
, &spec
->multiout
);
2093 static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
2094 struct hda_codec
*codec
,
2095 unsigned int stream_tag
,
2096 unsigned int format
,
2097 struct snd_pcm_substream
*substream
)
2099 struct alc_spec
*spec
= codec
->spec
;
2100 return snd_hda_multi_out_dig_prepare(codec
, &spec
->multiout
,
2101 stream_tag
, format
, substream
);
2104 static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
2105 struct hda_codec
*codec
,
2106 struct snd_pcm_substream
*substream
)
2108 struct alc_spec
*spec
= codec
->spec
;
2109 return snd_hda_multi_out_dig_cleanup(codec
, &spec
->multiout
);
2112 static int alc_dig_playback_pcm_close(struct hda_pcm_stream
*hinfo
,
2113 struct hda_codec
*codec
,
2114 struct snd_pcm_substream
*substream
)
2116 struct alc_spec
*spec
= codec
->spec
;
2117 return snd_hda_multi_out_dig_close(codec
, &spec
->multiout
);
2123 static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream
*hinfo
,
2124 struct hda_codec
*codec
,
2125 unsigned int stream_tag
,
2126 unsigned int format
,
2127 struct snd_pcm_substream
*substream
)
2129 struct alc_spec
*spec
= codec
->spec
;
2131 snd_hda_codec_setup_stream(codec
, spec
->adc_nids
[substream
->number
+ 1],
2132 stream_tag
, 0, format
);
2136 static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
2137 struct hda_codec
*codec
,
2138 struct snd_pcm_substream
*substream
)
2140 struct alc_spec
*spec
= codec
->spec
;
2142 snd_hda_codec_cleanup_stream(codec
,
2143 spec
->adc_nids
[substream
->number
+ 1]);
2147 /* analog capture with dynamic dual-adc changes */
2148 static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream
*hinfo
,
2149 struct hda_codec
*codec
,
2150 unsigned int stream_tag
,
2151 unsigned int format
,
2152 struct snd_pcm_substream
*substream
)
2154 struct alc_spec
*spec
= codec
->spec
;
2155 spec
->cur_adc
= spec
->adc_nids
[spec
->dyn_adc_idx
[spec
->cur_mux
[0]]];
2156 spec
->cur_adc_stream_tag
= stream_tag
;
2157 spec
->cur_adc_format
= format
;
2158 snd_hda_codec_setup_stream(codec
, spec
->cur_adc
, stream_tag
, 0, format
);
2162 static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
2163 struct hda_codec
*codec
,
2164 struct snd_pcm_substream
*substream
)
2166 struct alc_spec
*spec
= codec
->spec
;
2167 snd_hda_codec_cleanup_stream(codec
, spec
->cur_adc
);
2172 static const struct hda_pcm_stream dyn_adc_pcm_analog_capture
= {
2176 .nid
= 0, /* fill later */
2178 .prepare
= dyn_adc_capture_pcm_prepare
,
2179 .cleanup
= dyn_adc_capture_pcm_cleanup
2185 static const struct hda_pcm_stream alc_pcm_analog_playback
= {
2189 /* NID is set in alc_build_pcms */
2191 .open
= alc_playback_pcm_open
,
2192 .prepare
= alc_playback_pcm_prepare
,
2193 .cleanup
= alc_playback_pcm_cleanup
2197 static const struct hda_pcm_stream alc_pcm_analog_capture
= {
2201 /* NID is set in alc_build_pcms */
2204 static const struct hda_pcm_stream alc_pcm_analog_alt_playback
= {
2208 /* NID is set in alc_build_pcms */
2211 static const struct hda_pcm_stream alc_pcm_analog_alt_capture
= {
2212 .substreams
= 2, /* can be overridden */
2215 /* NID is set in alc_build_pcms */
2217 .prepare
= alc_alt_capture_pcm_prepare
,
2218 .cleanup
= alc_alt_capture_pcm_cleanup
2222 static const struct hda_pcm_stream alc_pcm_digital_playback
= {
2226 /* NID is set in alc_build_pcms */
2228 .open
= alc_dig_playback_pcm_open
,
2229 .close
= alc_dig_playback_pcm_close
,
2230 .prepare
= alc_dig_playback_pcm_prepare
,
2231 .cleanup
= alc_dig_playback_pcm_cleanup
2235 static const struct hda_pcm_stream alc_pcm_digital_capture
= {
2239 /* NID is set in alc_build_pcms */
2242 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
2243 static const struct hda_pcm_stream alc_pcm_null_stream
= {
2249 static int alc_build_pcms(struct hda_codec
*codec
)
2251 struct alc_spec
*spec
= codec
->spec
;
2252 struct hda_pcm
*info
= spec
->pcm_rec
;
2253 const struct hda_pcm_stream
*p
;
2254 bool have_multi_adcs
;
2257 codec
->num_pcms
= 1;
2258 codec
->pcm_info
= info
;
2260 if (spec
->no_analog
)
2263 snprintf(spec
->stream_name_analog
, sizeof(spec
->stream_name_analog
),
2264 "%s Analog", codec
->chip_name
);
2265 info
->name
= spec
->stream_name_analog
;
2267 if (spec
->multiout
.num_dacs
> 0) {
2268 p
= spec
->stream_analog_playback
;
2270 p
= &alc_pcm_analog_playback
;
2271 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] = *p
;
2272 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
= spec
->multiout
.dac_nids
[0];
2273 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].channels_max
=
2274 spec
->multiout
.max_channels
;
2275 if (spec
->autocfg
.line_out_type
== AUTO_PIN_SPEAKER_OUT
&&
2276 spec
->autocfg
.line_outs
== 2)
2277 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].chmap
=
2280 if (spec
->adc_nids
) {
2281 p
= spec
->stream_analog_capture
;
2283 if (spec
->dyn_adc_switch
)
2284 p
= &dyn_adc_pcm_analog_capture
;
2286 p
= &alc_pcm_analog_capture
;
2288 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] = *p
;
2289 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
= spec
->adc_nids
[0];
2292 if (spec
->channel_mode
) {
2293 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].channels_max
= 0;
2294 for (i
= 0; i
< spec
->num_channel_mode
; i
++) {
2295 if (spec
->channel_mode
[i
].channels
> info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].channels_max
) {
2296 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].channels_max
= spec
->channel_mode
[i
].channels
;
2302 /* SPDIF for stream index #1 */
2303 if (spec
->multiout
.dig_out_nid
|| spec
->dig_in_nid
) {
2304 snprintf(spec
->stream_name_digital
,
2305 sizeof(spec
->stream_name_digital
),
2306 "%s Digital", codec
->chip_name
);
2307 codec
->num_pcms
= 2;
2308 codec
->slave_dig_outs
= spec
->multiout
.slave_dig_outs
;
2309 info
= spec
->pcm_rec
+ 1;
2310 info
->name
= spec
->stream_name_digital
;
2311 if (spec
->dig_out_type
)
2312 info
->pcm_type
= spec
->dig_out_type
;
2314 info
->pcm_type
= HDA_PCM_TYPE_SPDIF
;
2315 if (spec
->multiout
.dig_out_nid
) {
2316 p
= spec
->stream_digital_playback
;
2318 p
= &alc_pcm_digital_playback
;
2319 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] = *p
;
2320 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
= spec
->multiout
.dig_out_nid
;
2322 if (spec
->dig_in_nid
) {
2323 p
= spec
->stream_digital_capture
;
2325 p
= &alc_pcm_digital_capture
;
2326 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] = *p
;
2327 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
= spec
->dig_in_nid
;
2329 /* FIXME: do we need this for all Realtek codec models? */
2330 codec
->spdif_status_reset
= 1;
2333 if (spec
->no_analog
)
2336 /* If the use of more than one ADC is requested for the current
2337 * model, configure a second analog capture-only PCM.
2339 have_multi_adcs
= (spec
->num_adc_nids
> 1) &&
2340 !spec
->dyn_adc_switch
&& !spec
->auto_mic
&&
2341 (!spec
->input_mux
|| spec
->input_mux
->num_items
> 1);
2342 /* Additional Analaog capture for index #2 */
2343 if (spec
->alt_dac_nid
|| have_multi_adcs
) {
2344 codec
->num_pcms
= 3;
2345 info
= spec
->pcm_rec
+ 2;
2346 info
->name
= spec
->stream_name_analog
;
2347 if (spec
->alt_dac_nid
) {
2348 p
= spec
->stream_analog_alt_playback
;
2350 p
= &alc_pcm_analog_alt_playback
;
2351 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] = *p
;
2352 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
=
2355 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] =
2356 alc_pcm_null_stream
;
2357 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
= 0;
2359 if (have_multi_adcs
) {
2360 p
= spec
->stream_analog_alt_capture
;
2362 p
= &alc_pcm_analog_alt_capture
;
2363 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] = *p
;
2364 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
=
2366 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].substreams
=
2367 spec
->num_adc_nids
- 1;
2369 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] =
2370 alc_pcm_null_stream
;
2371 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
= 0;
2378 static inline void alc_shutup(struct hda_codec
*codec
)
2380 struct alc_spec
*spec
= codec
->spec
;
2382 if (spec
&& spec
->shutup
)
2383 spec
->shutup(codec
);
2384 snd_hda_shutup_pins(codec
);
2387 static void alc_free_kctls(struct hda_codec
*codec
)
2389 struct alc_spec
*spec
= codec
->spec
;
2391 if (spec
->kctls
.list
) {
2392 struct snd_kcontrol_new
*kctl
= spec
->kctls
.list
;
2394 for (i
= 0; i
< spec
->kctls
.used
; i
++)
2395 kfree(kctl
[i
].name
);
2397 snd_array_free(&spec
->kctls
);
2400 static void alc_free_bind_ctls(struct hda_codec
*codec
)
2402 struct alc_spec
*spec
= codec
->spec
;
2403 if (spec
->bind_ctls
.list
) {
2404 struct hda_bind_ctls
**ctl
= spec
->bind_ctls
.list
;
2406 for (i
= 0; i
< spec
->bind_ctls
.used
; i
++)
2409 snd_array_free(&spec
->bind_ctls
);
2412 static void alc_free(struct hda_codec
*codec
)
2414 struct alc_spec
*spec
= codec
->spec
;
2419 alc_free_kctls(codec
);
2420 alc_free_bind_ctls(codec
);
2421 snd_hda_gen_free(&spec
->gen
);
2423 snd_hda_detach_beep_device(codec
);
2427 static void alc_power_eapd(struct hda_codec
*codec
)
2429 alc_auto_setup_eapd(codec
, false);
2432 static int alc_suspend(struct hda_codec
*codec
)
2434 struct alc_spec
*spec
= codec
->spec
;
2436 if (spec
&& spec
->power_hook
)
2437 spec
->power_hook(codec
);
2443 static int alc_resume(struct hda_codec
*codec
)
2445 msleep(150); /* to avoid pop noise */
2446 codec
->patch_ops
.init(codec
);
2447 snd_hda_codec_resume_amp(codec
);
2448 snd_hda_codec_resume_cache(codec
);
2449 alc_inv_dmic_sync(codec
, true);
2450 hda_call_check_power_status(codec
, 0x01);
2457 static const struct hda_codec_ops alc_patch_ops
= {
2458 .build_controls
= alc_build_controls
,
2459 .build_pcms
= alc_build_pcms
,
2462 .unsol_event
= snd_hda_jack_unsol_event
,
2464 .resume
= alc_resume
,
2467 .suspend
= alc_suspend
,
2468 .check_power_status
= alc_check_power_status
,
2470 .reboot_notify
= alc_shutup
,
2474 /* replace the codec chip_name with the given string */
2475 static int alc_codec_rename(struct hda_codec
*codec
, const char *name
)
2477 kfree(codec
->chip_name
);
2478 codec
->chip_name
= kstrdup(name
, GFP_KERNEL
);
2479 if (!codec
->chip_name
) {
2487 * Rename codecs appropriately from COEF value
2489 struct alc_codec_rename_table
{
2490 unsigned int vendor_id
;
2491 unsigned short coef_mask
;
2492 unsigned short coef_bits
;
2496 static struct alc_codec_rename_table rename_tbl
[] = {
2497 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2498 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2499 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2500 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2501 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2502 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2503 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
2504 { 0x10ec0269, 0x00f0, 0x0030, "ALC269VD" },
2505 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2506 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2507 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2508 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2509 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2510 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2511 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2512 { } /* terminator */
2515 static int alc_codec_rename_from_preset(struct hda_codec
*codec
)
2517 const struct alc_codec_rename_table
*p
;
2519 for (p
= rename_tbl
; p
->vendor_id
; p
++) {
2520 if (p
->vendor_id
!= codec
->vendor_id
)
2522 if ((alc_get_coef0(codec
) & p
->coef_mask
) == p
->coef_bits
)
2523 return alc_codec_rename(codec
, p
->name
);
2529 * Automatic parse of I/O pins from the BIOS configuration
2534 ALC_CTL_WIDGET_MUTE
,
2539 static const struct snd_kcontrol_new alc_control_templates
[] = {
2540 HDA_CODEC_VOLUME(NULL
, 0, 0, 0),
2541 HDA_CODEC_MUTE(NULL
, 0, 0, 0),
2542 HDA_BIND_MUTE(NULL
, 0, 0, 0),
2543 HDA_BIND_VOL(NULL
, 0),
2544 HDA_BIND_SW(NULL
, 0),
2547 /* add dynamic controls */
2548 static int add_control(struct alc_spec
*spec
, int type
, const char *name
,
2549 int cidx
, unsigned long val
)
2551 struct snd_kcontrol_new
*knew
;
2553 knew
= alc_kcontrol_new(spec
, name
, &alc_control_templates
[type
]);
2557 if (get_amp_nid_(val
))
2558 knew
->subdevice
= HDA_SUBDEV_AMP_FLAG
;
2559 knew
->private_value
= val
;
2563 static int add_control_with_pfx(struct alc_spec
*spec
, int type
,
2564 const char *pfx
, const char *dir
,
2565 const char *sfx
, int cidx
, unsigned long val
)
2568 snprintf(name
, sizeof(name
), "%s %s %s", pfx
, dir
, sfx
);
2569 return add_control(spec
, type
, name
, cidx
, val
);
2572 #define add_pb_vol_ctrl(spec, type, pfx, val) \
2573 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2574 #define add_pb_sw_ctrl(spec, type, pfx, val) \
2575 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2576 #define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2577 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2578 #define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2579 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
2581 static const char * const channel_name
[4] = {
2582 "Front", "Surround", "CLFE", "Side"
2585 static const char *alc_get_line_out_pfx(struct alc_spec
*spec
, int ch
,
2586 bool can_be_master
, int *index
)
2588 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
2591 if (cfg
->line_outs
== 1 && !spec
->multi_ios
&&
2592 !cfg
->hp_outs
&& !cfg
->speaker_outs
&& can_be_master
)
2595 switch (cfg
->line_out_type
) {
2596 case AUTO_PIN_SPEAKER_OUT
:
2597 if (cfg
->line_outs
== 1)
2599 if (cfg
->line_outs
== 2)
2600 return ch
? "Bass Speaker" : "Speaker";
2602 case AUTO_PIN_HP_OUT
:
2603 /* for multi-io case, only the primary out */
2604 if (ch
&& spec
->multi_ios
)
2609 if (cfg
->line_outs
== 1 && !spec
->multi_ios
)
2613 if (ch
>= ARRAY_SIZE(channel_name
)) {
2618 return channel_name
[ch
];
2622 /* add the powersave loopback-list entry */
2623 static void add_loopback_list(struct alc_spec
*spec
, hda_nid_t mix
, int idx
)
2625 struct hda_amp_list
*list
;
2627 if (spec
->num_loopbacks
>= ARRAY_SIZE(spec
->loopback_list
) - 1)
2629 list
= spec
->loopback_list
+ spec
->num_loopbacks
;
2631 list
->dir
= HDA_INPUT
;
2633 spec
->num_loopbacks
++;
2634 spec
->loopback
.amplist
= spec
->loopback_list
;
2637 #define add_loopback_list(spec, mix, idx) /* NOP */
2640 /* create input playback/capture controls for the given pin */
2641 static int new_analog_input(struct alc_spec
*spec
, hda_nid_t pin
,
2642 const char *ctlname
, int ctlidx
,
2643 int idx
, hda_nid_t mix_nid
)
2647 err
= __add_pb_vol_ctrl(spec
, ALC_CTL_WIDGET_VOL
, ctlname
, ctlidx
,
2648 HDA_COMPOSE_AMP_VAL(mix_nid
, 3, idx
, HDA_INPUT
));
2651 err
= __add_pb_sw_ctrl(spec
, ALC_CTL_WIDGET_MUTE
, ctlname
, ctlidx
,
2652 HDA_COMPOSE_AMP_VAL(mix_nid
, 3, idx
, HDA_INPUT
));
2655 add_loopback_list(spec
, mix_nid
, idx
);
2659 static int alc_is_input_pin(struct hda_codec
*codec
, hda_nid_t nid
)
2661 unsigned int pincap
= snd_hda_query_pin_caps(codec
, nid
);
2662 return (pincap
& AC_PINCAP_IN
) != 0;
2665 /* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
2666 static int alc_auto_fill_adc_caps(struct hda_codec
*codec
)
2668 struct alc_spec
*spec
= codec
->spec
;
2670 hda_nid_t
*adc_nids
= spec
->private_adc_nids
;
2671 hda_nid_t
*cap_nids
= spec
->private_capsrc_nids
;
2672 int max_nums
= ARRAY_SIZE(spec
->private_adc_nids
);
2675 nid
= codec
->start_nid
;
2676 for (i
= 0; i
< codec
->num_nodes
; i
++, nid
++) {
2678 unsigned int caps
= get_wcaps(codec
, nid
);
2679 int type
= get_wcaps_type(caps
);
2681 if (type
!= AC_WID_AUD_IN
|| (caps
& AC_WCAP_DIGITAL
))
2683 adc_nids
[nums
] = nid
;
2684 cap_nids
[nums
] = nid
;
2688 type
= get_wcaps_type(get_wcaps(codec
, src
));
2689 if (type
== AC_WID_PIN
)
2691 if (type
== AC_WID_AUD_SEL
) {
2692 cap_nids
[nums
] = src
;
2695 n
= snd_hda_get_num_conns(codec
, src
);
2697 cap_nids
[nums
] = src
;
2701 if (snd_hda_get_connections(codec
, src
, &src
, 1) != 1)
2704 if (++nums
>= max_nums
)
2707 spec
->adc_nids
= spec
->private_adc_nids
;
2708 spec
->capsrc_nids
= spec
->private_capsrc_nids
;
2709 spec
->num_adc_nids
= nums
;
2713 /* create playback/capture controls for input pins */
2714 static int alc_auto_create_input_ctls(struct hda_codec
*codec
)
2716 struct alc_spec
*spec
= codec
->spec
;
2717 const struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
2718 hda_nid_t mixer
= spec
->mixer_nid
;
2719 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
2721 int i
, c
, err
, idx
, type_idx
= 0;
2722 const char *prev_label
= NULL
;
2724 num_adcs
= alc_auto_fill_adc_caps(codec
);
2728 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
2732 pin
= cfg
->inputs
[i
].pin
;
2733 if (!alc_is_input_pin(codec
, pin
))
2736 label
= hda_get_autocfg_input_label(codec
, cfg
, i
);
2737 if (spec
->shared_mic_hp
&& !strcmp(label
, "Misc"))
2738 label
= "Headphone Mic";
2739 if (prev_label
&& !strcmp(label
, prev_label
))
2746 idx
= get_connection_index(codec
, mixer
, pin
);
2748 err
= new_analog_input(spec
, pin
,
2756 for (c
= 0; c
< num_adcs
; c
++) {
2757 hda_nid_t cap
= get_capsrc(spec
, c
);
2758 idx
= get_connection_index(codec
, cap
, pin
);
2760 spec
->imux_pins
[imux
->num_items
] = pin
;
2761 snd_hda_add_imux_item(imux
, label
, idx
, NULL
);
2767 spec
->num_mux_defs
= 1;
2768 spec
->input_mux
= imux
;
2773 /* create a shared input with the headphone out */
2774 static int alc_auto_create_shared_input(struct hda_codec
*codec
)
2776 struct alc_spec
*spec
= codec
->spec
;
2777 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
2778 unsigned int defcfg
;
2781 /* only one internal input pin? */
2782 if (cfg
->num_inputs
!= 1)
2784 defcfg
= snd_hda_codec_get_pincfg(codec
, cfg
->inputs
[0].pin
);
2785 if (snd_hda_get_input_pin_attr(defcfg
) != INPUT_PIN_ATTR_INT
)
2788 if (cfg
->hp_outs
== 1 && cfg
->line_out_type
== AUTO_PIN_SPEAKER_OUT
)
2789 nid
= cfg
->hp_pins
[0]; /* OK, we have a single HP-out */
2790 else if (cfg
->line_outs
== 1 && cfg
->line_out_type
== AUTO_PIN_HP_OUT
)
2791 nid
= cfg
->line_out_pins
[0]; /* OK, we have a single line-out */
2793 return 0; /* both not available */
2795 if (!(snd_hda_query_pin_caps(codec
, nid
) & AC_PINCAP_IN
))
2796 return 0; /* no input */
2798 cfg
->inputs
[1].pin
= nid
;
2799 cfg
->inputs
[1].type
= AUTO_PIN_MIC
;
2800 cfg
->num_inputs
= 2;
2801 spec
->shared_mic_hp
= 1;
2802 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid
);
2806 static void alc_set_pin_output(struct hda_codec
*codec
, hda_nid_t nid
,
2807 unsigned int pin_type
)
2809 snd_hda_set_pin_ctl(codec
, nid
, pin_type
);
2811 if (nid_has_mute(codec
, nid
, HDA_OUTPUT
))
2812 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
2816 static int get_pin_type(int line_out_type
)
2818 if (line_out_type
== AUTO_PIN_HP_OUT
)
2824 static void alc_auto_init_analog_input(struct hda_codec
*codec
)
2826 struct alc_spec
*spec
= codec
->spec
;
2827 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
2830 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
2831 hda_nid_t nid
= cfg
->inputs
[i
].pin
;
2832 if (alc_is_input_pin(codec
, nid
)) {
2833 alc_set_input_pin(codec
, nid
, cfg
->inputs
[i
].type
);
2834 if (get_wcaps(codec
, nid
) & AC_WCAP_OUT_AMP
)
2835 snd_hda_codec_write(codec
, nid
, 0,
2836 AC_VERB_SET_AMP_GAIN_MUTE
,
2841 /* mute all loopback inputs */
2842 if (spec
->mixer_nid
) {
2843 int nums
= snd_hda_get_num_conns(codec
, spec
->mixer_nid
);
2844 for (i
= 0; i
< nums
; i
++)
2845 snd_hda_codec_write(codec
, spec
->mixer_nid
, 0,
2846 AC_VERB_SET_AMP_GAIN_MUTE
,
2851 /* convert from MIX nid to DAC */
2852 static hda_nid_t
alc_auto_mix_to_dac(struct hda_codec
*codec
, hda_nid_t nid
)
2857 if (get_wcaps_type(get_wcaps(codec
, nid
)) == AC_WID_AUD_OUT
)
2859 num
= snd_hda_get_connections(codec
, nid
, list
, ARRAY_SIZE(list
));
2860 for (i
= 0; i
< num
; i
++) {
2861 if (get_wcaps_type(get_wcaps(codec
, list
[i
])) == AC_WID_AUD_OUT
)
2867 /* go down to the selector widget before the mixer */
2868 static hda_nid_t
alc_go_down_to_selector(struct hda_codec
*codec
, hda_nid_t pin
)
2871 int num
= snd_hda_get_connections(codec
, pin
, srcs
,
2874 get_wcaps_type(get_wcaps(codec
, srcs
[0])) != AC_WID_AUD_SEL
)
2879 /* get MIX nid connected to the given pin targeted to DAC */
2880 static hda_nid_t
alc_auto_dac_to_mix(struct hda_codec
*codec
, hda_nid_t pin
,
2886 pin
= alc_go_down_to_selector(codec
, pin
);
2887 num
= snd_hda_get_connections(codec
, pin
, mix
, ARRAY_SIZE(mix
));
2888 for (i
= 0; i
< num
; i
++) {
2889 if (alc_auto_mix_to_dac(codec
, mix
[i
]) == dac
)
2895 /* select the connection from pin to DAC if needed */
2896 static int alc_auto_select_dac(struct hda_codec
*codec
, hda_nid_t pin
,
2902 pin
= alc_go_down_to_selector(codec
, pin
);
2903 num
= snd_hda_get_connections(codec
, pin
, mix
, ARRAY_SIZE(mix
));
2906 for (i
= 0; i
< num
; i
++) {
2907 if (alc_auto_mix_to_dac(codec
, mix
[i
]) == dac
) {
2908 snd_hda_codec_update_cache(codec
, pin
, 0,
2909 AC_VERB_SET_CONNECT_SEL
, i
);
2916 static bool alc_is_dac_already_used(struct hda_codec
*codec
, hda_nid_t nid
)
2918 struct alc_spec
*spec
= codec
->spec
;
2920 if (found_in_nid_list(nid
, spec
->multiout
.dac_nids
,
2921 ARRAY_SIZE(spec
->private_dac_nids
)) ||
2922 found_in_nid_list(nid
, spec
->multiout
.hp_out_nid
,
2923 ARRAY_SIZE(spec
->multiout
.hp_out_nid
)) ||
2924 found_in_nid_list(nid
, spec
->multiout
.extra_out_nid
,
2925 ARRAY_SIZE(spec
->multiout
.extra_out_nid
)))
2927 for (i
= 0; i
< spec
->multi_ios
; i
++) {
2928 if (spec
->multi_io
[i
].dac
== nid
)
2934 /* look for an empty DAC slot */
2935 static hda_nid_t
alc_auto_look_for_dac(struct hda_codec
*codec
, hda_nid_t pin
)
2940 pin
= alc_go_down_to_selector(codec
, pin
);
2941 num
= snd_hda_get_connections(codec
, pin
, srcs
, ARRAY_SIZE(srcs
));
2942 for (i
= 0; i
< num
; i
++) {
2943 hda_nid_t nid
= alc_auto_mix_to_dac(codec
, srcs
[i
]);
2946 if (!alc_is_dac_already_used(codec
, nid
))
2952 /* check whether the DAC is reachable from the pin */
2953 static bool alc_auto_is_dac_reachable(struct hda_codec
*codec
,
2954 hda_nid_t pin
, hda_nid_t dac
)
2961 pin
= alc_go_down_to_selector(codec
, pin
);
2962 num
= snd_hda_get_connections(codec
, pin
, srcs
, ARRAY_SIZE(srcs
));
2963 for (i
= 0; i
< num
; i
++) {
2964 hda_nid_t nid
= alc_auto_mix_to_dac(codec
, srcs
[i
]);
2971 static hda_nid_t
get_dac_if_single(struct hda_codec
*codec
, hda_nid_t pin
)
2973 struct alc_spec
*spec
= codec
->spec
;
2974 hda_nid_t sel
= alc_go_down_to_selector(codec
, pin
);
2975 hda_nid_t nid
, nid_found
, srcs
[5];
2976 int i
, num
= snd_hda_get_connections(codec
, sel
, srcs
,
2979 return alc_auto_look_for_dac(codec
, pin
);
2981 for (i
= 0; i
< num
; i
++) {
2982 if (srcs
[i
] == spec
->mixer_nid
)
2984 nid
= alc_auto_mix_to_dac(codec
, srcs
[i
]);
2985 if (nid
&& !alc_is_dac_already_used(codec
, nid
)) {
2994 /* mark up volume and mute control NIDs: used during badness parsing and
2995 * at creating actual controls
2997 static inline unsigned int get_ctl_pos(unsigned int data
)
2999 hda_nid_t nid
= get_amp_nid_(data
);
3001 if (snd_BUG_ON(nid
>= MAX_VOL_NIDS
))
3003 dir
= get_amp_direction_(data
);
3004 return (nid
<< 1) | dir
;
3007 #define is_ctl_used(bits, data) \
3008 test_bit(get_ctl_pos(data), bits)
3009 #define mark_ctl_usage(bits, data) \
3010 set_bit(get_ctl_pos(data), bits)
3012 static void clear_vol_marks(struct hda_codec
*codec
)
3014 struct alc_spec
*spec
= codec
->spec
;
3015 memset(spec
->vol_ctls
, 0, sizeof(spec
->vol_ctls
));
3016 memset(spec
->sw_ctls
, 0, sizeof(spec
->sw_ctls
));
3019 /* badness definition */
3021 /* No primary DAC is found for the main output */
3022 BAD_NO_PRIMARY_DAC
= 0x10000,
3023 /* No DAC is found for the extra output */
3024 BAD_NO_DAC
= 0x4000,
3025 /* No possible multi-ios */
3026 BAD_MULTI_IO
= 0x103,
3027 /* No individual DAC for extra output */
3028 BAD_NO_EXTRA_DAC
= 0x102,
3029 /* No individual DAC for extra surrounds */
3030 BAD_NO_EXTRA_SURR_DAC
= 0x101,
3031 /* Primary DAC shared with main surrounds */
3032 BAD_SHARED_SURROUND
= 0x100,
3033 /* Primary DAC shared with main CLFE */
3034 BAD_SHARED_CLFE
= 0x10,
3035 /* Primary DAC shared with extra surrounds */
3036 BAD_SHARED_EXTRA_SURROUND
= 0x10,
3037 /* Volume widget is shared */
3038 BAD_SHARED_VOL
= 0x10,
3041 static hda_nid_t
alc_look_for_out_mute_nid(struct hda_codec
*codec
,
3042 hda_nid_t pin
, hda_nid_t dac
);
3043 static hda_nid_t
alc_look_for_out_vol_nid(struct hda_codec
*codec
,
3044 hda_nid_t pin
, hda_nid_t dac
);
3046 static int eval_shared_vol_badness(struct hda_codec
*codec
, hda_nid_t pin
,
3049 struct alc_spec
*spec
= codec
->spec
;
3054 nid
= alc_look_for_out_vol_nid(codec
, pin
, dac
);
3056 val
= HDA_COMPOSE_AMP_VAL(nid
, 3, 0, HDA_OUTPUT
);
3057 if (is_ctl_used(spec
->vol_ctls
, nid
))
3058 badness
+= BAD_SHARED_VOL
;
3060 mark_ctl_usage(spec
->vol_ctls
, val
);
3062 badness
+= BAD_SHARED_VOL
;
3063 nid
= alc_look_for_out_mute_nid(codec
, pin
, dac
);
3065 unsigned int wid_type
= get_wcaps_type(get_wcaps(codec
, nid
));
3066 if (wid_type
== AC_WID_PIN
|| wid_type
== AC_WID_AUD_OUT
)
3067 val
= HDA_COMPOSE_AMP_VAL(nid
, 3, 0, HDA_OUTPUT
);
3069 val
= HDA_COMPOSE_AMP_VAL(nid
, 3, 0, HDA_INPUT
);
3070 if (is_ctl_used(spec
->sw_ctls
, val
))
3071 badness
+= BAD_SHARED_VOL
;
3073 mark_ctl_usage(spec
->sw_ctls
, val
);
3075 badness
+= BAD_SHARED_VOL
;
3079 struct badness_table
{
3080 int no_primary_dac
; /* no primary DAC */
3081 int no_dac
; /* no secondary DACs */
3082 int shared_primary
; /* primary DAC is shared with main output */
3083 int shared_surr
; /* secondary DAC shared with main or primary */
3084 int shared_clfe
; /* third DAC shared with main or primary */
3085 int shared_surr_main
; /* secondary DAC sahred with main/DAC0 */
3088 static struct badness_table main_out_badness
= {
3089 .no_primary_dac
= BAD_NO_PRIMARY_DAC
,
3090 .no_dac
= BAD_NO_DAC
,
3091 .shared_primary
= BAD_NO_PRIMARY_DAC
,
3092 .shared_surr
= BAD_SHARED_SURROUND
,
3093 .shared_clfe
= BAD_SHARED_CLFE
,
3094 .shared_surr_main
= BAD_SHARED_SURROUND
,
3097 static struct badness_table extra_out_badness
= {
3098 .no_primary_dac
= BAD_NO_DAC
,
3099 .no_dac
= BAD_NO_DAC
,
3100 .shared_primary
= BAD_NO_EXTRA_DAC
,
3101 .shared_surr
= BAD_SHARED_EXTRA_SURROUND
,
3102 .shared_clfe
= BAD_SHARED_EXTRA_SURROUND
,
3103 .shared_surr_main
= BAD_NO_EXTRA_SURR_DAC
,
3106 /* try to assign DACs to pins and return the resultant badness */
3107 static int alc_auto_fill_dacs(struct hda_codec
*codec
, int num_outs
,
3108 const hda_nid_t
*pins
, hda_nid_t
*dacs
,
3109 const struct badness_table
*bad
)
3111 struct alc_spec
*spec
= codec
->spec
;
3112 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
3120 for (i
= 0; i
< num_outs
; i
++) {
3121 hda_nid_t pin
= pins
[i
];
3123 dacs
[i
] = alc_auto_look_for_dac(codec
, pin
);
3124 if (!dacs
[i
] && !i
) {
3125 for (j
= 1; j
< num_outs
; j
++) {
3126 if (alc_auto_is_dac_reachable(codec
, pin
, dacs
[j
])) {
3135 if (alc_auto_is_dac_reachable(codec
, pin
, dacs
[0]))
3137 else if (cfg
->line_outs
> i
&&
3138 alc_auto_is_dac_reachable(codec
, pin
,
3139 spec
->private_dac_nids
[i
]))
3140 dac
= spec
->private_dac_nids
[i
];
3143 badness
+= bad
->shared_primary
;
3145 badness
+= bad
->shared_surr
;
3147 badness
+= bad
->shared_clfe
;
3148 } else if (alc_auto_is_dac_reachable(codec
, pin
,
3149 spec
->private_dac_nids
[0])) {
3150 dac
= spec
->private_dac_nids
[0];
3151 badness
+= bad
->shared_surr_main
;
3153 badness
+= bad
->no_primary_dac
;
3155 badness
+= bad
->no_dac
;
3158 badness
+= eval_shared_vol_badness(codec
, pin
, dac
);
3164 static int alc_auto_fill_multi_ios(struct hda_codec
*codec
,
3165 hda_nid_t reference_pin
,
3166 bool hardwired
, int offset
);
3168 static bool alc_map_singles(struct hda_codec
*codec
, int outs
,
3169 const hda_nid_t
*pins
, hda_nid_t
*dacs
)
3173 for (i
= 0; i
< outs
; i
++) {
3176 dacs
[i
] = get_dac_if_single(codec
, pins
[i
]);
3183 /* fill in the dac_nids table from the parsed pin configuration */
3184 static int fill_and_eval_dacs(struct hda_codec
*codec
,
3185 bool fill_hardwired
,
3186 bool fill_mio_first
)
3188 struct alc_spec
*spec
= codec
->spec
;
3189 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
3190 int i
, err
, badness
;
3192 /* set num_dacs once to full for alc_auto_look_for_dac() */
3193 spec
->multiout
.num_dacs
= cfg
->line_outs
;
3194 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
3195 memset(spec
->private_dac_nids
, 0, sizeof(spec
->private_dac_nids
));
3196 memset(spec
->multiout
.hp_out_nid
, 0, sizeof(spec
->multiout
.hp_out_nid
));
3197 memset(spec
->multiout
.extra_out_nid
, 0, sizeof(spec
->multiout
.extra_out_nid
));
3198 spec
->multi_ios
= 0;
3199 clear_vol_marks(codec
);
3202 /* fill hard-wired DACs first */
3203 if (fill_hardwired
) {
3206 mapped
= alc_map_singles(codec
, cfg
->line_outs
,
3208 spec
->private_dac_nids
);
3209 mapped
|= alc_map_singles(codec
, cfg
->hp_outs
,
3211 spec
->multiout
.hp_out_nid
);
3212 mapped
|= alc_map_singles(codec
, cfg
->speaker_outs
,
3214 spec
->multiout
.extra_out_nid
);
3215 if (fill_mio_first
&& cfg
->line_outs
== 1 &&
3216 cfg
->line_out_type
!= AUTO_PIN_SPEAKER_OUT
) {
3217 err
= alc_auto_fill_multi_ios(codec
, cfg
->line_out_pins
[0], true, 0);
3224 badness
+= alc_auto_fill_dacs(codec
, cfg
->line_outs
, cfg
->line_out_pins
,
3225 spec
->private_dac_nids
,
3228 /* re-count num_dacs and squash invalid entries */
3229 spec
->multiout
.num_dacs
= 0;
3230 for (i
= 0; i
< cfg
->line_outs
; i
++) {
3231 if (spec
->private_dac_nids
[i
])
3232 spec
->multiout
.num_dacs
++;
3234 memmove(spec
->private_dac_nids
+ i
,
3235 spec
->private_dac_nids
+ i
+ 1,
3236 sizeof(hda_nid_t
) * (cfg
->line_outs
- i
- 1));
3237 spec
->private_dac_nids
[cfg
->line_outs
- 1] = 0;
3241 if (fill_mio_first
&&
3242 cfg
->line_outs
== 1 && cfg
->line_out_type
!= AUTO_PIN_SPEAKER_OUT
) {
3243 /* try to fill multi-io first */
3244 err
= alc_auto_fill_multi_ios(codec
, cfg
->line_out_pins
[0], false, 0);
3247 /* we don't count badness at this stage yet */
3250 if (cfg
->line_out_type
!= AUTO_PIN_HP_OUT
) {
3251 err
= alc_auto_fill_dacs(codec
, cfg
->hp_outs
, cfg
->hp_pins
,
3252 spec
->multiout
.hp_out_nid
,
3253 &extra_out_badness
);
3258 if (cfg
->line_out_type
!= AUTO_PIN_SPEAKER_OUT
) {
3259 err
= alc_auto_fill_dacs(codec
, cfg
->speaker_outs
,
3261 spec
->multiout
.extra_out_nid
,
3262 &extra_out_badness
);
3267 if (cfg
->line_outs
== 1 && cfg
->line_out_type
!= AUTO_PIN_SPEAKER_OUT
) {
3268 err
= alc_auto_fill_multi_ios(codec
, cfg
->line_out_pins
[0], false, 0);
3273 if (cfg
->hp_outs
&& cfg
->line_out_type
== AUTO_PIN_SPEAKER_OUT
) {
3274 /* try multi-ios with HP + inputs */
3276 if (cfg
->line_outs
>= 3)
3278 err
= alc_auto_fill_multi_ios(codec
, cfg
->hp_pins
[0], false,
3285 if (spec
->multi_ios
== 2) {
3286 for (i
= 0; i
< 2; i
++)
3287 spec
->private_dac_nids
[spec
->multiout
.num_dacs
++] =
3288 spec
->multi_io
[i
].dac
;
3289 spec
->ext_channel_count
= 2;
3290 } else if (spec
->multi_ios
) {
3291 spec
->multi_ios
= 0;
3292 badness
+= BAD_MULTI_IO
;
3298 #define DEBUG_BADNESS
3300 #ifdef DEBUG_BADNESS
3301 #define debug_badness snd_printdd
3303 #define debug_badness(...)
3306 static void debug_show_configs(struct alc_spec
*spec
, struct auto_pin_cfg
*cfg
)
3308 debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3309 cfg
->line_out_pins
[0], cfg
->line_out_pins
[1],
3310 cfg
->line_out_pins
[2], cfg
->line_out_pins
[2],
3311 spec
->multiout
.dac_nids
[0],
3312 spec
->multiout
.dac_nids
[1],
3313 spec
->multiout
.dac_nids
[2],
3314 spec
->multiout
.dac_nids
[3]);
3315 if (spec
->multi_ios
> 0)
3316 debug_badness("multi_ios(%d) = %x/%x : %x/%x\n",
3318 spec
->multi_io
[0].pin
, spec
->multi_io
[1].pin
,
3319 spec
->multi_io
[0].dac
, spec
->multi_io
[1].dac
);
3320 debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3321 cfg
->hp_pins
[0], cfg
->hp_pins
[1],
3322 cfg
->hp_pins
[2], cfg
->hp_pins
[2],
3323 spec
->multiout
.hp_out_nid
[0],
3324 spec
->multiout
.hp_out_nid
[1],
3325 spec
->multiout
.hp_out_nid
[2],
3326 spec
->multiout
.hp_out_nid
[3]);
3327 debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3328 cfg
->speaker_pins
[0], cfg
->speaker_pins
[1],
3329 cfg
->speaker_pins
[2], cfg
->speaker_pins
[3],
3330 spec
->multiout
.extra_out_nid
[0],
3331 spec
->multiout
.extra_out_nid
[1],
3332 spec
->multiout
.extra_out_nid
[2],
3333 spec
->multiout
.extra_out_nid
[3]);
3336 static int alc_auto_fill_dac_nids(struct hda_codec
*codec
)
3338 struct alc_spec
*spec
= codec
->spec
;
3339 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
3340 struct auto_pin_cfg
*best_cfg
;
3341 int best_badness
= INT_MAX
;
3343 bool fill_hardwired
= true, fill_mio_first
= true;
3344 bool best_wired
= true, best_mio
= true;
3345 bool hp_spk_swapped
= false;
3347 best_cfg
= kmalloc(sizeof(*best_cfg
), GFP_KERNEL
);
3353 badness
= fill_and_eval_dacs(codec
, fill_hardwired
,
3359 debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n",
3360 cfg
->line_out_type
, fill_hardwired
, fill_mio_first
,
3362 debug_show_configs(spec
, cfg
);
3363 if (badness
< best_badness
) {
3364 best_badness
= badness
;
3366 best_wired
= fill_hardwired
;
3367 best_mio
= fill_mio_first
;
3371 fill_mio_first
= !fill_mio_first
;
3372 if (!fill_mio_first
)
3374 fill_hardwired
= !fill_hardwired
;
3375 if (!fill_hardwired
)
3379 hp_spk_swapped
= true;
3380 if (cfg
->speaker_outs
> 0 &&
3381 cfg
->line_out_type
== AUTO_PIN_HP_OUT
) {
3382 cfg
->hp_outs
= cfg
->line_outs
;
3383 memcpy(cfg
->hp_pins
, cfg
->line_out_pins
,
3384 sizeof(cfg
->hp_pins
));
3385 cfg
->line_outs
= cfg
->speaker_outs
;
3386 memcpy(cfg
->line_out_pins
, cfg
->speaker_pins
,
3387 sizeof(cfg
->speaker_pins
));
3388 cfg
->speaker_outs
= 0;
3389 memset(cfg
->speaker_pins
, 0, sizeof(cfg
->speaker_pins
));
3390 cfg
->line_out_type
= AUTO_PIN_SPEAKER_OUT
;
3391 fill_hardwired
= true;
3394 if (cfg
->hp_outs
> 0 &&
3395 cfg
->line_out_type
== AUTO_PIN_SPEAKER_OUT
) {
3396 cfg
->speaker_outs
= cfg
->line_outs
;
3397 memcpy(cfg
->speaker_pins
, cfg
->line_out_pins
,
3398 sizeof(cfg
->speaker_pins
));
3399 cfg
->line_outs
= cfg
->hp_outs
;
3400 memcpy(cfg
->line_out_pins
, cfg
->hp_pins
,
3401 sizeof(cfg
->hp_pins
));
3403 memset(cfg
->hp_pins
, 0, sizeof(cfg
->hp_pins
));
3404 cfg
->line_out_type
= AUTO_PIN_HP_OUT
;
3405 fill_hardwired
= true;
3413 fill_and_eval_dacs(codec
, best_wired
, best_mio
);
3415 debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n",
3416 cfg
->line_out_type
, best_wired
, best_mio
);
3417 debug_show_configs(spec
, cfg
);
3419 if (cfg
->line_out_pins
[0])
3421 alc_look_for_out_vol_nid(codec
, cfg
->line_out_pins
[0],
3422 spec
->multiout
.dac_nids
[0]);
3424 /* clear the bitmap flags for creating controls */
3425 clear_vol_marks(codec
);
3430 static int alc_auto_add_vol_ctl(struct hda_codec
*codec
,
3431 const char *pfx
, int cidx
,
3432 hda_nid_t nid
, unsigned int chs
)
3434 struct alc_spec
*spec
= codec
->spec
;
3438 val
= HDA_COMPOSE_AMP_VAL(nid
, chs
, 0, HDA_OUTPUT
);
3439 if (is_ctl_used(spec
->vol_ctls
, val
) && chs
!= 2) /* exclude LFE */
3441 mark_ctl_usage(spec
->vol_ctls
, val
);
3442 return __add_pb_vol_ctrl(codec
->spec
, ALC_CTL_WIDGET_VOL
, pfx
, cidx
,
3446 static int alc_auto_add_stereo_vol(struct hda_codec
*codec
,
3447 const char *pfx
, int cidx
,
3451 if (get_wcaps(codec
, nid
) & AC_WCAP_STEREO
)
3453 return alc_auto_add_vol_ctl(codec
, pfx
, cidx
, nid
, chs
);
3456 /* create a mute-switch for the given mixer widget;
3457 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3459 static int alc_auto_add_sw_ctl(struct hda_codec
*codec
,
3460 const char *pfx
, int cidx
,
3461 hda_nid_t nid
, unsigned int chs
)
3463 struct alc_spec
*spec
= codec
->spec
;
3469 wid_type
= get_wcaps_type(get_wcaps(codec
, nid
));
3470 if (wid_type
== AC_WID_PIN
|| wid_type
== AC_WID_AUD_OUT
) {
3471 type
= ALC_CTL_WIDGET_MUTE
;
3472 val
= HDA_COMPOSE_AMP_VAL(nid
, chs
, 0, HDA_OUTPUT
);
3473 } else if (snd_hda_get_num_conns(codec
, nid
) == 1) {
3474 type
= ALC_CTL_WIDGET_MUTE
;
3475 val
= HDA_COMPOSE_AMP_VAL(nid
, chs
, 0, HDA_INPUT
);
3477 type
= ALC_CTL_BIND_MUTE
;
3478 val
= HDA_COMPOSE_AMP_VAL(nid
, chs
, 2, HDA_INPUT
);
3480 if (is_ctl_used(spec
->sw_ctls
, val
) && chs
!= 2) /* exclude LFE */
3482 mark_ctl_usage(spec
->sw_ctls
, val
);
3483 return __add_pb_sw_ctrl(codec
->spec
, type
, pfx
, cidx
, val
);
3486 static int alc_auto_add_stereo_sw(struct hda_codec
*codec
, const char *pfx
,
3487 int cidx
, hda_nid_t nid
)
3490 if (get_wcaps(codec
, nid
) & AC_WCAP_STEREO
)
3492 return alc_auto_add_sw_ctl(codec
, pfx
, cidx
, nid
, chs
);
3495 static hda_nid_t
alc_look_for_out_mute_nid(struct hda_codec
*codec
,
3496 hda_nid_t pin
, hda_nid_t dac
)
3498 hda_nid_t mix
= alc_auto_dac_to_mix(codec
, pin
, dac
);
3499 if (nid_has_mute(codec
, pin
, HDA_OUTPUT
))
3501 else if (mix
&& nid_has_mute(codec
, mix
, HDA_INPUT
))
3503 else if (nid_has_mute(codec
, dac
, HDA_OUTPUT
))
3508 static hda_nid_t
alc_look_for_out_vol_nid(struct hda_codec
*codec
,
3509 hda_nid_t pin
, hda_nid_t dac
)
3511 hda_nid_t mix
= alc_auto_dac_to_mix(codec
, pin
, dac
);
3512 if (nid_has_volume(codec
, dac
, HDA_OUTPUT
))
3514 else if (nid_has_volume(codec
, mix
, HDA_OUTPUT
))
3516 else if (nid_has_volume(codec
, pin
, HDA_OUTPUT
))
3521 /* add playback controls from the parsed DAC table */
3522 static int alc_auto_create_multi_out_ctls(struct hda_codec
*codec
,
3523 const struct auto_pin_cfg
*cfg
)
3525 struct alc_spec
*spec
= codec
->spec
;
3526 int i
, err
, noutputs
;
3528 noutputs
= cfg
->line_outs
;
3529 if (spec
->multi_ios
> 0 && cfg
->line_outs
< 3)
3530 noutputs
+= spec
->multi_ios
;
3532 for (i
= 0; i
< noutputs
; i
++) {
3538 dac
= spec
->multiout
.dac_nids
[i
];
3541 if (i
>= cfg
->line_outs
) {
3542 pin
= spec
->multi_io
[i
- 1].pin
;
3544 name
= channel_name
[i
];
3546 pin
= cfg
->line_out_pins
[i
];
3547 name
= alc_get_line_out_pfx(spec
, i
, true, &index
);
3550 sw
= alc_look_for_out_mute_nid(codec
, pin
, dac
);
3551 vol
= alc_look_for_out_vol_nid(codec
, pin
, dac
);
3552 if (!name
|| !strcmp(name
, "CLFE")) {
3554 err
= alc_auto_add_vol_ctl(codec
, "Center", 0, vol
, 1);
3557 err
= alc_auto_add_vol_ctl(codec
, "LFE", 0, vol
, 2);
3560 err
= alc_auto_add_sw_ctl(codec
, "Center", 0, sw
, 1);
3563 err
= alc_auto_add_sw_ctl(codec
, "LFE", 0, sw
, 2);
3567 err
= alc_auto_add_stereo_vol(codec
, name
, index
, vol
);
3570 err
= alc_auto_add_stereo_sw(codec
, name
, index
, sw
);
3578 static int alc_auto_create_extra_out(struct hda_codec
*codec
, hda_nid_t pin
,
3579 hda_nid_t dac
, const char *pfx
,
3582 struct alc_spec
*spec
= codec
->spec
;
3588 /* the corresponding DAC is already occupied */
3589 if (!(get_wcaps(codec
, pin
) & AC_WCAP_OUT_AMP
))
3590 return 0; /* no way */
3591 /* create a switch only */
3592 val
= HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
);
3593 if (is_ctl_used(spec
->sw_ctls
, val
))
3594 return 0; /* already created */
3595 mark_ctl_usage(spec
->sw_ctls
, val
);
3596 return __add_pb_sw_ctrl(spec
, ALC_CTL_WIDGET_MUTE
, pfx
, cidx
, val
);
3599 sw
= alc_look_for_out_mute_nid(codec
, pin
, dac
);
3600 vol
= alc_look_for_out_vol_nid(codec
, pin
, dac
);
3601 err
= alc_auto_add_stereo_vol(codec
, pfx
, cidx
, vol
);
3604 err
= alc_auto_add_stereo_sw(codec
, pfx
, cidx
, sw
);
3610 static struct hda_bind_ctls
*new_bind_ctl(struct hda_codec
*codec
,
3612 struct hda_ctl_ops
*ops
)
3614 struct alc_spec
*spec
= codec
->spec
;
3615 struct hda_bind_ctls
**ctlp
, *ctl
;
3616 ctlp
= snd_array_new(&spec
->bind_ctls
);
3619 ctl
= kzalloc(sizeof(*ctl
) + sizeof(long) * (nums
+ 1), GFP_KERNEL
);
3626 /* add playback controls for speaker and HP outputs */
3627 static int alc_auto_create_extra_outs(struct hda_codec
*codec
, int num_pins
,
3628 const hda_nid_t
*pins
,
3629 const hda_nid_t
*dacs
,
3632 struct alc_spec
*spec
= codec
->spec
;
3633 struct hda_bind_ctls
*ctl
;
3637 if (!num_pins
|| !pins
[0])
3640 if (num_pins
== 1) {
3641 hda_nid_t dac
= *dacs
;
3643 dac
= spec
->multiout
.dac_nids
[0];
3644 return alc_auto_create_extra_out(codec
, *pins
, dac
, pfx
, 0);
3647 for (i
= 0; i
< num_pins
; i
++) {
3649 if (dacs
[num_pins
- 1])
3650 dac
= dacs
[i
]; /* with individual volumes */
3653 if (num_pins
== 2 && i
== 1 && !strcmp(pfx
, "Speaker")) {
3654 err
= alc_auto_create_extra_out(codec
, pins
[i
], dac
,
3656 } else if (num_pins
>= 3) {
3657 snprintf(name
, sizeof(name
), "%s %s",
3658 pfx
, channel_name
[i
]);
3659 err
= alc_auto_create_extra_out(codec
, pins
[i
], dac
,
3662 err
= alc_auto_create_extra_out(codec
, pins
[i
], dac
,
3668 if (dacs
[num_pins
- 1])
3671 /* Let's create a bind-controls for volumes */
3672 ctl
= new_bind_ctl(codec
, num_pins
, &snd_hda_bind_vol
);
3676 for (i
= 0; i
< num_pins
; i
++) {
3678 if (!pins
[i
] || !dacs
[i
])
3680 vol
= alc_look_for_out_vol_nid(codec
, pins
[i
], dacs
[i
]);
3683 HDA_COMPOSE_AMP_VAL(vol
, 3, 0, HDA_OUTPUT
);
3686 snprintf(name
, sizeof(name
), "%s Playback Volume", pfx
);
3687 err
= add_control(spec
, ALC_CTL_BIND_VOL
, name
, 0, (long)ctl
);
3694 static int alc_auto_create_hp_out(struct hda_codec
*codec
)
3696 struct alc_spec
*spec
= codec
->spec
;
3697 return alc_auto_create_extra_outs(codec
, spec
->autocfg
.hp_outs
,
3698 spec
->autocfg
.hp_pins
,
3699 spec
->multiout
.hp_out_nid
,
3703 static int alc_auto_create_speaker_out(struct hda_codec
*codec
)
3705 struct alc_spec
*spec
= codec
->spec
;
3706 return alc_auto_create_extra_outs(codec
, spec
->autocfg
.speaker_outs
,
3707 spec
->autocfg
.speaker_pins
,
3708 spec
->multiout
.extra_out_nid
,
3712 static void alc_auto_set_output_and_unmute(struct hda_codec
*codec
,
3713 hda_nid_t pin
, int pin_type
,
3717 hda_nid_t nid
, mix
= 0;
3718 hda_nid_t srcs
[HDA_MAX_CONNECTIONS
];
3720 alc_set_pin_output(codec
, pin
, pin_type
);
3721 nid
= alc_go_down_to_selector(codec
, pin
);
3722 num
= snd_hda_get_connections(codec
, nid
, srcs
, ARRAY_SIZE(srcs
));
3723 for (i
= 0; i
< num
; i
++) {
3724 if (alc_auto_mix_to_dac(codec
, srcs
[i
]) != dac
)
3732 /* need the manual connection? */
3734 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_CONNECT_SEL
, i
);
3735 /* unmute mixer widget inputs */
3736 if (nid_has_mute(codec
, mix
, HDA_INPUT
)) {
3737 snd_hda_codec_write(codec
, mix
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
3739 snd_hda_codec_write(codec
, mix
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
3742 /* initialize volume */
3743 nid
= alc_look_for_out_vol_nid(codec
, pin
, dac
);
3745 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
3748 /* unmute DAC if it's not assigned to a mixer */
3749 nid
= alc_look_for_out_mute_nid(codec
, pin
, dac
);
3750 if (nid
== mix
&& nid_has_mute(codec
, dac
, HDA_OUTPUT
))
3751 snd_hda_codec_write(codec
, dac
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
3755 static void alc_auto_init_multi_out(struct hda_codec
*codec
)
3757 struct alc_spec
*spec
= codec
->spec
;
3758 int pin_type
= get_pin_type(spec
->autocfg
.line_out_type
);
3761 for (i
= 0; i
<= HDA_SIDE
; i
++) {
3762 hda_nid_t nid
= spec
->autocfg
.line_out_pins
[i
];
3764 alc_auto_set_output_and_unmute(codec
, nid
, pin_type
,
3765 spec
->multiout
.dac_nids
[i
]);
3769 static void alc_auto_init_extra_out(struct hda_codec
*codec
)
3771 struct alc_spec
*spec
= codec
->spec
;
3775 for (i
= 0; i
< spec
->autocfg
.hp_outs
; i
++) {
3776 if (spec
->autocfg
.line_out_type
== AUTO_PIN_HP_OUT
)
3778 pin
= spec
->autocfg
.hp_pins
[i
];
3781 dac
= spec
->multiout
.hp_out_nid
[i
];
3783 if (i
> 0 && spec
->multiout
.hp_out_nid
[0])
3784 dac
= spec
->multiout
.hp_out_nid
[0];
3786 dac
= spec
->multiout
.dac_nids
[0];
3788 alc_auto_set_output_and_unmute(codec
, pin
, PIN_HP
, dac
);
3790 for (i
= 0; i
< spec
->autocfg
.speaker_outs
; i
++) {
3791 if (spec
->autocfg
.line_out_type
== AUTO_PIN_SPEAKER_OUT
)
3793 pin
= spec
->autocfg
.speaker_pins
[i
];
3796 dac
= spec
->multiout
.extra_out_nid
[i
];
3798 if (i
> 0 && spec
->multiout
.extra_out_nid
[0])
3799 dac
= spec
->multiout
.extra_out_nid
[0];
3801 dac
= spec
->multiout
.dac_nids
[0];
3803 alc_auto_set_output_and_unmute(codec
, pin
, PIN_OUT
, dac
);
3807 /* check whether the given pin can be a multi-io pin */
3808 static bool can_be_multiio_pin(struct hda_codec
*codec
,
3809 unsigned int location
, hda_nid_t nid
)
3811 unsigned int defcfg
, caps
;
3813 defcfg
= snd_hda_codec_get_pincfg(codec
, nid
);
3814 if (get_defcfg_connect(defcfg
) != AC_JACK_PORT_COMPLEX
)
3816 if (location
&& get_defcfg_location(defcfg
) != location
)
3818 caps
= snd_hda_query_pin_caps(codec
, nid
);
3819 if (!(caps
& AC_PINCAP_OUT
))
3827 * When hardwired is set, try to fill ony hardwired pins, and returns
3828 * zero if any pins are filled, non-zero if nothing found.
3829 * When hardwired is off, try to fill possible input pins, and returns
3830 * the badness value.
3832 static int alc_auto_fill_multi_ios(struct hda_codec
*codec
,
3833 hda_nid_t reference_pin
,
3834 bool hardwired
, int offset
)
3836 struct alc_spec
*spec
= codec
->spec
;
3837 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
3838 int type
, i
, j
, dacs
, num_pins
, old_pins
;
3839 unsigned int defcfg
= snd_hda_codec_get_pincfg(codec
, reference_pin
);
3840 unsigned int location
= get_defcfg_location(defcfg
);
3843 old_pins
= spec
->multi_ios
;
3848 for (type
= AUTO_PIN_LINE_IN
; type
>= AUTO_PIN_MIC
; type
--) {
3849 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
3850 if (cfg
->inputs
[i
].type
!= type
)
3852 if (can_be_multiio_pin(codec
, location
,
3853 cfg
->inputs
[i
].pin
))
3860 dacs
= spec
->multiout
.num_dacs
;
3861 for (type
= AUTO_PIN_LINE_IN
; type
>= AUTO_PIN_MIC
; type
--) {
3862 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
3863 hda_nid_t nid
= cfg
->inputs
[i
].pin
;
3866 if (cfg
->inputs
[i
].type
!= type
)
3868 if (!can_be_multiio_pin(codec
, location
, nid
))
3870 for (j
= 0; j
< spec
->multi_ios
; j
++) {
3871 if (nid
== spec
->multi_io
[j
].pin
)
3874 if (j
< spec
->multi_ios
)
3877 if (offset
&& offset
+ spec
->multi_ios
< dacs
) {
3878 dac
= spec
->private_dac_nids
[offset
+ spec
->multi_ios
];
3879 if (!alc_auto_is_dac_reachable(codec
, nid
, dac
))
3883 dac
= get_dac_if_single(codec
, nid
);
3885 dac
= alc_auto_look_for_dac(codec
, nid
);
3890 spec
->multi_io
[spec
->multi_ios
].pin
= nid
;
3891 spec
->multi_io
[spec
->multi_ios
].dac
= dac
;
3893 if (spec
->multi_ios
>= 2)
3899 badness
= BAD_MULTI_IO
;
3900 if (old_pins
== spec
->multi_ios
) {
3902 return 1; /* nothing found */
3904 return badness
; /* no badness if nothing found */
3906 if (!hardwired
&& spec
->multi_ios
< 2) {
3907 spec
->multi_ios
= old_pins
;
3914 static int alc_auto_ch_mode_info(struct snd_kcontrol
*kcontrol
,
3915 struct snd_ctl_elem_info
*uinfo
)
3917 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3918 struct alc_spec
*spec
= codec
->spec
;
3920 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
3922 uinfo
->value
.enumerated
.items
= spec
->multi_ios
+ 1;
3923 if (uinfo
->value
.enumerated
.item
> spec
->multi_ios
)
3924 uinfo
->value
.enumerated
.item
= spec
->multi_ios
;
3925 sprintf(uinfo
->value
.enumerated
.name
, "%dch",
3926 (uinfo
->value
.enumerated
.item
+ 1) * 2);
3930 static int alc_auto_ch_mode_get(struct snd_kcontrol
*kcontrol
,
3931 struct snd_ctl_elem_value
*ucontrol
)
3933 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3934 struct alc_spec
*spec
= codec
->spec
;
3935 ucontrol
->value
.enumerated
.item
[0] = (spec
->ext_channel_count
- 1) / 2;
3939 static int alc_set_multi_io(struct hda_codec
*codec
, int idx
, bool output
)
3941 struct alc_spec
*spec
= codec
->spec
;
3942 hda_nid_t nid
= spec
->multi_io
[idx
].pin
;
3944 if (!spec
->multi_io
[idx
].ctl_in
)
3945 spec
->multi_io
[idx
].ctl_in
=
3946 snd_hda_codec_read(codec
, nid
, 0,
3947 AC_VERB_GET_PIN_WIDGET_CONTROL
, 0);
3949 snd_hda_set_pin_ctl_cache(codec
, nid
, PIN_OUT
);
3950 if (get_wcaps(codec
, nid
) & AC_WCAP_OUT_AMP
)
3951 snd_hda_codec_amp_stereo(codec
, nid
, HDA_OUTPUT
, 0,
3953 alc_auto_select_dac(codec
, nid
, spec
->multi_io
[idx
].dac
);
3955 if (get_wcaps(codec
, nid
) & AC_WCAP_OUT_AMP
)
3956 snd_hda_codec_amp_stereo(codec
, nid
, HDA_OUTPUT
, 0,
3957 HDA_AMP_MUTE
, HDA_AMP_MUTE
);
3958 snd_hda_set_pin_ctl_cache(codec
, nid
,
3959 spec
->multi_io
[idx
].ctl_in
);
3964 static int alc_auto_ch_mode_put(struct snd_kcontrol
*kcontrol
,
3965 struct snd_ctl_elem_value
*ucontrol
)
3967 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3968 struct alc_spec
*spec
= codec
->spec
;
3971 ch
= ucontrol
->value
.enumerated
.item
[0];
3972 if (ch
< 0 || ch
> spec
->multi_ios
)
3974 if (ch
== (spec
->ext_channel_count
- 1) / 2)
3976 spec
->ext_channel_count
= (ch
+ 1) * 2;
3977 for (i
= 0; i
< spec
->multi_ios
; i
++)
3978 alc_set_multi_io(codec
, i
, i
< ch
);
3979 spec
->multiout
.max_channels
= spec
->ext_channel_count
;
3980 if (spec
->need_dac_fix
&& !spec
->const_channel_count
)
3981 spec
->multiout
.num_dacs
= spec
->multiout
.max_channels
/ 2;
3985 static const struct snd_kcontrol_new alc_auto_channel_mode_enum
= {
3986 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
3987 .name
= "Channel Mode",
3988 .info
= alc_auto_ch_mode_info
,
3989 .get
= alc_auto_ch_mode_get
,
3990 .put
= alc_auto_ch_mode_put
,
3993 static int alc_auto_add_multi_channel_mode(struct hda_codec
*codec
)
3995 struct alc_spec
*spec
= codec
->spec
;
3997 if (spec
->multi_ios
> 0) {
3998 if (!alc_kcontrol_new(spec
, "Channel Mode",
3999 &alc_auto_channel_mode_enum
))
4005 /* filter out invalid adc_nids (and capsrc_nids) that don't give all
4008 static void alc_remove_invalid_adc_nids(struct hda_codec
*codec
)
4010 struct alc_spec
*spec
= codec
->spec
;
4011 const struct hda_input_mux
*imux
;
4012 hda_nid_t adc_nids
[ARRAY_SIZE(spec
->private_adc_nids
)];
4013 hda_nid_t capsrc_nids
[ARRAY_SIZE(spec
->private_adc_nids
)];
4016 imux
= spec
->input_mux
;
4019 if (spec
->dyn_adc_switch
)
4024 for (n
= 0; n
< spec
->num_adc_nids
; n
++) {
4025 hda_nid_t cap
= spec
->private_capsrc_nids
[n
];
4026 int num_conns
= snd_hda_get_num_conns(codec
, cap
);
4027 for (i
= 0; i
< imux
->num_items
; i
++) {
4028 hda_nid_t pin
= spec
->imux_pins
[i
];
4030 if (get_connection_index(codec
, cap
, pin
) < 0)
4032 } else if (num_conns
<= imux
->items
[i
].index
)
4035 if (i
>= imux
->num_items
) {
4036 adc_nids
[nums
] = spec
->private_adc_nids
[n
];
4037 capsrc_nids
[nums
++] = cap
;
4041 /* check whether ADC-switch is possible */
4042 if (!alc_check_dyn_adc_switch(codec
)) {
4043 if (spec
->shared_mic_hp
) {
4044 spec
->shared_mic_hp
= 0;
4045 spec
->private_imux
[0].num_items
= 1;
4048 printk(KERN_WARNING
"hda_codec: %s: no valid ADC found;"
4049 " using fallback 0x%x\n",
4050 codec
->chip_name
, spec
->private_adc_nids
[0]);
4051 spec
->num_adc_nids
= 1;
4055 } else if (nums
!= spec
->num_adc_nids
) {
4056 memcpy(spec
->private_adc_nids
, adc_nids
,
4057 nums
* sizeof(hda_nid_t
));
4058 memcpy(spec
->private_capsrc_nids
, capsrc_nids
,
4059 nums
* sizeof(hda_nid_t
));
4060 spec
->num_adc_nids
= nums
;
4064 alc_auto_mic_check_imux(codec
); /* check auto-mic setups */
4065 else if (spec
->input_mux
->num_items
== 1 || spec
->shared_mic_hp
)
4066 spec
->num_adc_nids
= 1; /* reduce to a single ADC */
4070 * initialize ADC paths
4072 static void alc_auto_init_adc(struct hda_codec
*codec
, int adc_idx
)
4074 struct alc_spec
*spec
= codec
->spec
;
4077 nid
= spec
->adc_nids
[adc_idx
];
4079 if (nid_has_mute(codec
, nid
, HDA_INPUT
)) {
4080 snd_hda_codec_write(codec
, nid
, 0,
4081 AC_VERB_SET_AMP_GAIN_MUTE
,
4085 if (!spec
->capsrc_nids
)
4087 nid
= spec
->capsrc_nids
[adc_idx
];
4088 if (nid_has_mute(codec
, nid
, HDA_OUTPUT
))
4089 snd_hda_codec_write(codec
, nid
, 0,
4090 AC_VERB_SET_AMP_GAIN_MUTE
,
4094 static void alc_auto_init_input_src(struct hda_codec
*codec
)
4096 struct alc_spec
*spec
= codec
->spec
;
4099 for (c
= 0; c
< spec
->num_adc_nids
; c
++)
4100 alc_auto_init_adc(codec
, c
);
4101 if (spec
->dyn_adc_switch
)
4104 nums
= spec
->num_adc_nids
;
4105 for (c
= 0; c
< nums
; c
++)
4106 alc_mux_select(codec
, c
, spec
->cur_mux
[c
], true);
4109 /* add mic boosts if needed */
4110 static int alc_auto_add_mic_boost(struct hda_codec
*codec
)
4112 struct alc_spec
*spec
= codec
->spec
;
4113 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
4117 const char *prev_label
= NULL
;
4119 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
4120 if (cfg
->inputs
[i
].type
> AUTO_PIN_MIC
)
4122 nid
= cfg
->inputs
[i
].pin
;
4123 if (get_wcaps(codec
, nid
) & AC_WCAP_IN_AMP
) {
4125 char boost_label
[32];
4127 label
= hda_get_autocfg_input_label(codec
, cfg
, i
);
4128 if (spec
->shared_mic_hp
&& !strcmp(label
, "Misc"))
4129 label
= "Headphone Mic";
4130 if (prev_label
&& !strcmp(label
, prev_label
))
4136 snprintf(boost_label
, sizeof(boost_label
),
4137 "%s Boost Volume", label
);
4138 err
= add_control(spec
, ALC_CTL_WIDGET_VOL
,
4139 boost_label
, type_idx
,
4140 HDA_COMPOSE_AMP_VAL(nid
, 3, 0, HDA_INPUT
));
4148 /* select or unmute the given capsrc route */
4149 static void select_or_unmute_capsrc(struct hda_codec
*codec
, hda_nid_t cap
,
4152 if (get_wcaps_type(get_wcaps(codec
, cap
)) == AC_WID_AUD_MIX
) {
4153 snd_hda_codec_amp_stereo(codec
, cap
, HDA_INPUT
, idx
,
4155 } else if (snd_hda_get_num_conns(codec
, cap
) > 1) {
4156 snd_hda_codec_write_cache(codec
, cap
, 0,
4157 AC_VERB_SET_CONNECT_SEL
, idx
);
4161 /* set the default connection to that pin */
4162 static int init_capsrc_for_pin(struct hda_codec
*codec
, hda_nid_t pin
)
4164 struct alc_spec
*spec
= codec
->spec
;
4169 for (i
= 0; i
< spec
->num_adc_nids
; i
++) {
4170 hda_nid_t cap
= get_capsrc(spec
, i
);
4173 idx
= get_connection_index(codec
, cap
, pin
);
4176 select_or_unmute_capsrc(codec
, cap
, idx
);
4177 return i
; /* return the found index */
4179 return -1; /* not found */
4182 /* initialize some special cases for input sources */
4183 static void alc_init_special_input_src(struct hda_codec
*codec
)
4185 struct alc_spec
*spec
= codec
->spec
;
4188 for (i
= 0; i
< spec
->autocfg
.num_inputs
; i
++)
4189 init_capsrc_for_pin(codec
, spec
->autocfg
.inputs
[i
].pin
);
4192 /* assign appropriate capture mixers */
4193 static void set_capture_mixer(struct hda_codec
*codec
)
4195 struct alc_spec
*spec
= codec
->spec
;
4196 static const struct snd_kcontrol_new
*caps
[2][3] = {
4197 { alc_capture_mixer_nosrc1
,
4198 alc_capture_mixer_nosrc2
,
4199 alc_capture_mixer_nosrc3
},
4200 { alc_capture_mixer1
,
4202 alc_capture_mixer3
},
4205 /* check whether either of ADC or MUX has a volume control */
4206 if (!nid_has_volume(codec
, spec
->adc_nids
[0], HDA_INPUT
)) {
4207 if (!spec
->capsrc_nids
)
4208 return; /* no volume */
4209 if (!nid_has_volume(codec
, spec
->capsrc_nids
[0], HDA_OUTPUT
))
4210 return; /* no volume in capsrc, too */
4211 spec
->vol_in_capsrc
= 1;
4214 if (spec
->num_adc_nids
> 0) {
4218 if (spec
->input_mux
&& spec
->input_mux
->num_items
> 1)
4220 if (spec
->auto_mic
) {
4223 } else if (spec
->dyn_adc_switch
)
4226 if (spec
->num_adc_nids
> 3)
4227 spec
->num_adc_nids
= 3;
4228 else if (!spec
->num_adc_nids
)
4230 num_adcs
= spec
->num_adc_nids
;
4232 spec
->cap_mixer
= caps
[mux
][num_adcs
- 1];
4237 * standard auto-parser initializations
4239 static void alc_auto_init_std(struct hda_codec
*codec
)
4241 alc_auto_init_multi_out(codec
);
4242 alc_auto_init_extra_out(codec
);
4243 alc_auto_init_analog_input(codec
);
4244 alc_auto_init_input_src(codec
);
4245 alc_auto_init_digital(codec
);
4246 alc_inithook(codec
);
4250 * Digital-beep handlers
4252 #ifdef CONFIG_SND_HDA_INPUT_BEEP
4253 #define set_beep_amp(spec, nid, idx, dir) \
4254 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4256 static const struct snd_pci_quirk beep_white_list
[] = {
4257 SND_PCI_QUIRK(0x1043, 0x103c, "ASUS", 1),
4258 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
4259 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
4260 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
4261 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
4262 SND_PCI_QUIRK(0x1458, 0xa002, "GA-MA790X", 1),
4263 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
4267 static inline int has_cdefine_beep(struct hda_codec
*codec
)
4269 struct alc_spec
*spec
= codec
->spec
;
4270 const struct snd_pci_quirk
*q
;
4271 q
= snd_pci_quirk_lookup(codec
->bus
->pci
, beep_white_list
);
4274 return spec
->cdefine
.enable_pcbeep
;
4277 #define set_beep_amp(spec, nid, idx, dir) /* NOP */
4278 #define has_cdefine_beep(codec) 0
4281 /* parse the BIOS configuration and set up the alc_spec */
4282 /* return 1 if successful, 0 if the proper config is not found,
4283 * or a negative error code
4285 static int alc_parse_auto_config(struct hda_codec
*codec
,
4286 const hda_nid_t
*ignore_nids
,
4287 const hda_nid_t
*ssid_nids
)
4289 struct alc_spec
*spec
= codec
->spec
;
4290 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
4293 err
= snd_hda_parse_pin_defcfg(codec
, cfg
, ignore_nids
,
4297 if (!cfg
->line_outs
) {
4298 if (cfg
->dig_outs
|| cfg
->dig_in_pin
) {
4299 spec
->multiout
.max_channels
= 2;
4300 spec
->no_analog
= 1;
4303 return 0; /* can't find valid BIOS pin config */
4306 if (!spec
->no_primary_hp
&&
4307 cfg
->line_out_type
== AUTO_PIN_SPEAKER_OUT
&&
4308 cfg
->line_outs
<= cfg
->hp_outs
) {
4309 /* use HP as primary out */
4310 cfg
->speaker_outs
= cfg
->line_outs
;
4311 memcpy(cfg
->speaker_pins
, cfg
->line_out_pins
,
4312 sizeof(cfg
->speaker_pins
));
4313 cfg
->line_outs
= cfg
->hp_outs
;
4314 memcpy(cfg
->line_out_pins
, cfg
->hp_pins
, sizeof(cfg
->hp_pins
));
4316 memset(cfg
->hp_pins
, 0, sizeof(cfg
->hp_pins
));
4317 cfg
->line_out_type
= AUTO_PIN_HP_OUT
;
4320 err
= alc_auto_fill_dac_nids(codec
);
4323 err
= alc_auto_add_multi_channel_mode(codec
);
4326 err
= alc_auto_create_multi_out_ctls(codec
, cfg
);
4329 err
= alc_auto_create_hp_out(codec
);
4332 err
= alc_auto_create_speaker_out(codec
);
4335 err
= alc_auto_create_shared_input(codec
);
4338 err
= alc_auto_create_input_ctls(codec
);
4342 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
4345 alc_auto_parse_digital(codec
);
4347 if (!spec
->no_analog
)
4348 alc_remove_invalid_adc_nids(codec
);
4351 alc_ssid_check(codec
, ssid_nids
);
4353 if (!spec
->no_analog
) {
4354 err
= alc_auto_check_switches(codec
);
4357 err
= alc_auto_add_mic_boost(codec
);
4362 if (spec
->kctls
.list
)
4363 add_mixer(spec
, spec
->kctls
.list
);
4365 if (!spec
->no_analog
&& !spec
->cap_mixer
)
4366 set_capture_mixer(codec
);
4371 /* common preparation job for alc_spec */
4372 static int alc_alloc_spec(struct hda_codec
*codec
, hda_nid_t mixer_nid
)
4374 struct alc_spec
*spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
4380 spec
->mixer_nid
= mixer_nid
;
4381 snd_hda_gen_init(&spec
->gen
);
4382 snd_array_init(&spec
->kctls
, sizeof(struct snd_kcontrol_new
), 32);
4383 snd_array_init(&spec
->bind_ctls
, sizeof(struct hda_bind_ctls
*), 8);
4385 err
= alc_codec_rename_from_preset(codec
);
4393 static int alc880_parse_auto_config(struct hda_codec
*codec
)
4395 static const hda_nid_t alc880_ignore
[] = { 0x1d, 0 };
4396 static const hda_nid_t alc880_ssids
[] = { 0x15, 0x1b, 0x14, 0 };
4397 return alc_parse_auto_config(codec
, alc880_ignore
, alc880_ssids
);
4406 ALC880_FIXUP_MEDION_RIM
,
4409 ALC880_FIXUP_EAPD_COEF
,
4410 ALC880_FIXUP_TCL_S700
,
4411 ALC880_FIXUP_VOL_KNOB
,
4412 ALC880_FIXUP_FUJITSU
,
4414 ALC880_FIXUP_UNIWILL
,
4415 ALC880_FIXUP_UNIWILL_DIG
,
4417 ALC880_FIXUP_3ST_BASE
,
4419 ALC880_FIXUP_3ST_DIG
,
4420 ALC880_FIXUP_5ST_BASE
,
4422 ALC880_FIXUP_5ST_DIG
,
4423 ALC880_FIXUP_6ST_BASE
,
4425 ALC880_FIXUP_6ST_DIG
,
4428 /* enable the volume-knob widget support on NID 0x21 */
4429 static void alc880_fixup_vol_knob(struct hda_codec
*codec
,
4430 const struct alc_fixup
*fix
, int action
)
4432 if (action
== ALC_FIXUP_ACT_PROBE
)
4433 snd_hda_jack_detect_enable_callback(codec
, 0x21, ALC_DCVOL_EVENT
, alc_update_knob_master
);
4436 static const struct alc_fixup alc880_fixups
[] = {
4437 [ALC880_FIXUP_GPIO1
] = {
4438 .type
= ALC_FIXUP_VERBS
,
4439 .v
.verbs
= alc_gpio1_init_verbs
,
4441 [ALC880_FIXUP_GPIO2
] = {
4442 .type
= ALC_FIXUP_VERBS
,
4443 .v
.verbs
= alc_gpio2_init_verbs
,
4445 [ALC880_FIXUP_MEDION_RIM
] = {
4446 .type
= ALC_FIXUP_VERBS
,
4447 .v
.verbs
= (const struct hda_verb
[]) {
4448 { 0x20, AC_VERB_SET_COEF_INDEX
, 0x07 },
4449 { 0x20, AC_VERB_SET_PROC_COEF
, 0x3060 },
4453 .chain_id
= ALC880_FIXUP_GPIO2
,
4455 [ALC880_FIXUP_LG
] = {
4456 .type
= ALC_FIXUP_PINS
,
4457 .v
.pins
= (const struct alc_pincfg
[]) {
4458 /* disable bogus unused pins */
4459 { 0x16, 0x411111f0 },
4460 { 0x18, 0x411111f0 },
4461 { 0x1a, 0x411111f0 },
4465 [ALC880_FIXUP_W810
] = {
4466 .type
= ALC_FIXUP_PINS
,
4467 .v
.pins
= (const struct alc_pincfg
[]) {
4468 /* disable bogus unused pins */
4469 { 0x17, 0x411111f0 },
4473 .chain_id
= ALC880_FIXUP_GPIO2
,
4475 [ALC880_FIXUP_EAPD_COEF
] = {
4476 .type
= ALC_FIXUP_VERBS
,
4477 .v
.verbs
= (const struct hda_verb
[]) {
4478 /* change to EAPD mode */
4479 { 0x20, AC_VERB_SET_COEF_INDEX
, 0x07 },
4480 { 0x20, AC_VERB_SET_PROC_COEF
, 0x3060 },
4484 [ALC880_FIXUP_TCL_S700
] = {
4485 .type
= ALC_FIXUP_VERBS
,
4486 .v
.verbs
= (const struct hda_verb
[]) {
4487 /* change to EAPD mode */
4488 { 0x20, AC_VERB_SET_COEF_INDEX
, 0x07 },
4489 { 0x20, AC_VERB_SET_PROC_COEF
, 0x3070 },
4493 .chain_id
= ALC880_FIXUP_GPIO2
,
4495 [ALC880_FIXUP_VOL_KNOB
] = {
4496 .type
= ALC_FIXUP_FUNC
,
4497 .v
.func
= alc880_fixup_vol_knob
,
4499 [ALC880_FIXUP_FUJITSU
] = {
4500 /* override all pins as BIOS on old Amilo is broken */
4501 .type
= ALC_FIXUP_PINS
,
4502 .v
.pins
= (const struct alc_pincfg
[]) {
4503 { 0x14, 0x0121411f }, /* HP */
4504 { 0x15, 0x99030120 }, /* speaker */
4505 { 0x16, 0x99030130 }, /* bass speaker */
4506 { 0x17, 0x411111f0 }, /* N/A */
4507 { 0x18, 0x411111f0 }, /* N/A */
4508 { 0x19, 0x01a19950 }, /* mic-in */
4509 { 0x1a, 0x411111f0 }, /* N/A */
4510 { 0x1b, 0x411111f0 }, /* N/A */
4511 { 0x1c, 0x411111f0 }, /* N/A */
4512 { 0x1d, 0x411111f0 }, /* N/A */
4513 { 0x1e, 0x01454140 }, /* SPDIF out */
4517 .chain_id
= ALC880_FIXUP_VOL_KNOB
,
4519 [ALC880_FIXUP_F1734
] = {
4520 /* almost compatible with FUJITSU, but no bass and SPDIF */
4521 .type
= ALC_FIXUP_PINS
,
4522 .v
.pins
= (const struct alc_pincfg
[]) {
4523 { 0x14, 0x0121411f }, /* HP */
4524 { 0x15, 0x99030120 }, /* speaker */
4525 { 0x16, 0x411111f0 }, /* N/A */
4526 { 0x17, 0x411111f0 }, /* N/A */
4527 { 0x18, 0x411111f0 }, /* N/A */
4528 { 0x19, 0x01a19950 }, /* mic-in */
4529 { 0x1a, 0x411111f0 }, /* N/A */
4530 { 0x1b, 0x411111f0 }, /* N/A */
4531 { 0x1c, 0x411111f0 }, /* N/A */
4532 { 0x1d, 0x411111f0 }, /* N/A */
4533 { 0x1e, 0x411111f0 }, /* N/A */
4537 .chain_id
= ALC880_FIXUP_VOL_KNOB
,
4539 [ALC880_FIXUP_UNIWILL
] = {
4540 /* need to fix HP and speaker pins to be parsed correctly */
4541 .type
= ALC_FIXUP_PINS
,
4542 .v
.pins
= (const struct alc_pincfg
[]) {
4543 { 0x14, 0x0121411f }, /* HP */
4544 { 0x15, 0x99030120 }, /* speaker */
4545 { 0x16, 0x99030130 }, /* bass speaker */
4549 [ALC880_FIXUP_UNIWILL_DIG
] = {
4550 .type
= ALC_FIXUP_PINS
,
4551 .v
.pins
= (const struct alc_pincfg
[]) {
4552 /* disable bogus unused pins */
4553 { 0x17, 0x411111f0 },
4554 { 0x19, 0x411111f0 },
4555 { 0x1b, 0x411111f0 },
4556 { 0x1f, 0x411111f0 },
4560 [ALC880_FIXUP_Z71V
] = {
4561 .type
= ALC_FIXUP_PINS
,
4562 .v
.pins
= (const struct alc_pincfg
[]) {
4563 /* set up the whole pins as BIOS is utterly broken */
4564 { 0x14, 0x99030120 }, /* speaker */
4565 { 0x15, 0x0121411f }, /* HP */
4566 { 0x16, 0x411111f0 }, /* N/A */
4567 { 0x17, 0x411111f0 }, /* N/A */
4568 { 0x18, 0x01a19950 }, /* mic-in */
4569 { 0x19, 0x411111f0 }, /* N/A */
4570 { 0x1a, 0x01813031 }, /* line-in */
4571 { 0x1b, 0x411111f0 }, /* N/A */
4572 { 0x1c, 0x411111f0 }, /* N/A */
4573 { 0x1d, 0x411111f0 }, /* N/A */
4574 { 0x1e, 0x0144111e }, /* SPDIF */
4578 [ALC880_FIXUP_3ST_BASE
] = {
4579 .type
= ALC_FIXUP_PINS
,
4580 .v
.pins
= (const struct alc_pincfg
[]) {
4581 { 0x14, 0x01014010 }, /* line-out */
4582 { 0x15, 0x411111f0 }, /* N/A */
4583 { 0x16, 0x411111f0 }, /* N/A */
4584 { 0x17, 0x411111f0 }, /* N/A */
4585 { 0x18, 0x01a19c30 }, /* mic-in */
4586 { 0x19, 0x0121411f }, /* HP */
4587 { 0x1a, 0x01813031 }, /* line-in */
4588 { 0x1b, 0x02a19c40 }, /* front-mic */
4589 { 0x1c, 0x411111f0 }, /* N/A */
4590 { 0x1d, 0x411111f0 }, /* N/A */
4591 /* 0x1e is filled in below */
4592 { 0x1f, 0x411111f0 }, /* N/A */
4596 [ALC880_FIXUP_3ST
] = {
4597 .type
= ALC_FIXUP_PINS
,
4598 .v
.pins
= (const struct alc_pincfg
[]) {
4599 { 0x1e, 0x411111f0 }, /* N/A */
4603 .chain_id
= ALC880_FIXUP_3ST_BASE
,
4605 [ALC880_FIXUP_3ST_DIG
] = {
4606 .type
= ALC_FIXUP_PINS
,
4607 .v
.pins
= (const struct alc_pincfg
[]) {
4608 { 0x1e, 0x0144111e }, /* SPDIF */
4612 .chain_id
= ALC880_FIXUP_3ST_BASE
,
4614 [ALC880_FIXUP_5ST_BASE
] = {
4615 .type
= ALC_FIXUP_PINS
,
4616 .v
.pins
= (const struct alc_pincfg
[]) {
4617 { 0x14, 0x01014010 }, /* front */
4618 { 0x15, 0x411111f0 }, /* N/A */
4619 { 0x16, 0x01011411 }, /* CLFE */
4620 { 0x17, 0x01016412 }, /* surr */
4621 { 0x18, 0x01a19c30 }, /* mic-in */
4622 { 0x19, 0x0121411f }, /* HP */
4623 { 0x1a, 0x01813031 }, /* line-in */
4624 { 0x1b, 0x02a19c40 }, /* front-mic */
4625 { 0x1c, 0x411111f0 }, /* N/A */
4626 { 0x1d, 0x411111f0 }, /* N/A */
4627 /* 0x1e is filled in below */
4628 { 0x1f, 0x411111f0 }, /* N/A */
4632 [ALC880_FIXUP_5ST
] = {
4633 .type
= ALC_FIXUP_PINS
,
4634 .v
.pins
= (const struct alc_pincfg
[]) {
4635 { 0x1e, 0x411111f0 }, /* N/A */
4639 .chain_id
= ALC880_FIXUP_5ST_BASE
,
4641 [ALC880_FIXUP_5ST_DIG
] = {
4642 .type
= ALC_FIXUP_PINS
,
4643 .v
.pins
= (const struct alc_pincfg
[]) {
4644 { 0x1e, 0x0144111e }, /* SPDIF */
4648 .chain_id
= ALC880_FIXUP_5ST_BASE
,
4650 [ALC880_FIXUP_6ST_BASE
] = {
4651 .type
= ALC_FIXUP_PINS
,
4652 .v
.pins
= (const struct alc_pincfg
[]) {
4653 { 0x14, 0x01014010 }, /* front */
4654 { 0x15, 0x01016412 }, /* surr */
4655 { 0x16, 0x01011411 }, /* CLFE */
4656 { 0x17, 0x01012414 }, /* side */
4657 { 0x18, 0x01a19c30 }, /* mic-in */
4658 { 0x19, 0x02a19c40 }, /* front-mic */
4659 { 0x1a, 0x01813031 }, /* line-in */
4660 { 0x1b, 0x0121411f }, /* HP */
4661 { 0x1c, 0x411111f0 }, /* N/A */
4662 { 0x1d, 0x411111f0 }, /* N/A */
4663 /* 0x1e is filled in below */
4664 { 0x1f, 0x411111f0 }, /* N/A */
4668 [ALC880_FIXUP_6ST
] = {
4669 .type
= ALC_FIXUP_PINS
,
4670 .v
.pins
= (const struct alc_pincfg
[]) {
4671 { 0x1e, 0x411111f0 }, /* N/A */
4675 .chain_id
= ALC880_FIXUP_6ST_BASE
,
4677 [ALC880_FIXUP_6ST_DIG
] = {
4678 .type
= ALC_FIXUP_PINS
,
4679 .v
.pins
= (const struct alc_pincfg
[]) {
4680 { 0x1e, 0x0144111e }, /* SPDIF */
4684 .chain_id
= ALC880_FIXUP_6ST_BASE
,
4688 static const struct snd_pci_quirk alc880_fixup_tbl
[] = {
4689 SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_FIXUP_W810
),
4690 SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_FIXUP_Z71V
),
4691 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_FIXUP_GPIO1
),
4692 SND_PCI_QUIRK(0x1558, 0x5401, "Clevo GPIO2", ALC880_FIXUP_GPIO2
),
4693 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo", ALC880_FIXUP_EAPD_COEF
),
4694 SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_FIXUP_UNIWILL_DIG
),
4695 SND_PCI_QUIRK(0x1584, 0x9054, "Uniwill", ALC880_FIXUP_F1734
),
4696 SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_FIXUP_UNIWILL
),
4697 SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_FIXUP_VOL_KNOB
),
4698 SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_FIXUP_W810
),
4699 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM
),
4700 SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_FIXUP_F1734
),
4701 SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FIXUP_FUJITSU
),
4702 SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_FIXUP_F1734
),
4703 SND_PCI_QUIRK(0x1734, 0x10b0, "FSC Amilo Pi1556", ALC880_FIXUP_FUJITSU
),
4704 SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_FIXUP_LG
),
4705 SND_PCI_QUIRK(0x1854, 0x005f, "LG P1 Express", ALC880_FIXUP_LG
),
4706 SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_FIXUP_LG
),
4707 SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_FIXUP_TCL_S700
),
4709 /* Below is the copied entries from alc880_quirks.c.
4710 * It's not quite sure whether BIOS sets the correct pin-config table
4711 * on these machines, thus they are kept to be compatible with
4712 * the old static quirks. Once when it's confirmed to work without
4713 * these overrides, it'd be better to remove.
4715 SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_FIXUP_5ST_DIG
),
4716 SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_FIXUP_6ST
),
4717 SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_FIXUP_3ST_DIG
),
4718 SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_FIXUP_6ST_DIG
),
4719 SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_FIXUP_6ST_DIG
),
4720 SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_FIXUP_6ST_DIG
),
4721 SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_FIXUP_3ST_DIG
),
4722 SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_FIXUP_3ST
),
4723 SND_PCI_QUIRK(0x1039, 0x1234, NULL
, ALC880_FIXUP_6ST_DIG
),
4724 SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_FIXUP_3ST
),
4725 SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_FIXUP_3ST
),
4726 SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_FIXUP_5ST
),
4727 SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_FIXUP_5ST
),
4728 SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_FIXUP_5ST
),
4729 SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_FIXUP_6ST_DIG
),
4730 SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_FIXUP_6ST_DIG
),
4731 SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_FIXUP_6ST_DIG
),
4732 SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_FIXUP_6ST_DIG
),
4733 SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_FIXUP_5ST_DIG
),
4734 SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_FIXUP_5ST_DIG
),
4735 SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_FIXUP_5ST_DIG
),
4736 SND_PCI_QUIRK(0x2668, 0x8086, NULL
, ALC880_FIXUP_6ST_DIG
), /* broken BIOS */
4737 SND_PCI_QUIRK(0x8086, 0x2668, NULL
, ALC880_FIXUP_6ST_DIG
),
4738 SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_FIXUP_5ST_DIG
),
4739 SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_FIXUP_5ST_DIG
),
4740 SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_FIXUP_5ST_DIG
),
4741 SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_FIXUP_3ST_DIG
),
4742 SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_FIXUP_5ST_DIG
),
4743 SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_FIXUP_3ST_DIG
),
4744 SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_FIXUP_3ST_DIG
),
4745 SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_FIXUP_5ST_DIG
),
4746 SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_FIXUP_5ST_DIG
),
4747 SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_FIXUP_5ST_DIG
),
4749 SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_FIXUP_3ST
),
4750 SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_FIXUP_5ST_DIG
),
4751 SND_PCI_QUIRK(0xe803, 0x1019, NULL
, ALC880_FIXUP_6ST_DIG
),
4755 static const struct alc_model_fixup alc880_fixup_models
[] = {
4756 {.id
= ALC880_FIXUP_3ST
, .name
= "3stack"},
4757 {.id
= ALC880_FIXUP_3ST_DIG
, .name
= "3stack-digout"},
4758 {.id
= ALC880_FIXUP_5ST
, .name
= "5stack"},
4759 {.id
= ALC880_FIXUP_5ST_DIG
, .name
= "5stack-digout"},
4760 {.id
= ALC880_FIXUP_6ST
, .name
= "6stack"},
4761 {.id
= ALC880_FIXUP_6ST_DIG
, .name
= "6stack-digout"},
4767 * OK, here we have finally the patch for ALC880
4769 static int patch_alc880(struct hda_codec
*codec
)
4771 struct alc_spec
*spec
;
4774 err
= alc_alloc_spec(codec
, 0x0b);
4779 spec
->need_dac_fix
= 1;
4781 alc_pick_fixup(codec
, alc880_fixup_models
, alc880_fixup_tbl
,
4783 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
4785 /* automatic parse from the BIOS config */
4786 err
= alc880_parse_auto_config(codec
);
4790 if (!spec
->no_analog
) {
4791 err
= snd_hda_attach_beep_device(codec
, 0x1);
4794 set_beep_amp(spec
, 0x0b, 0x05, HDA_INPUT
);
4797 codec
->patch_ops
= alc_patch_ops
;
4798 codec
->patch_ops
.unsol_event
= alc880_unsol_event
;
4801 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
4814 static int alc260_parse_auto_config(struct hda_codec
*codec
)
4816 static const hda_nid_t alc260_ignore
[] = { 0x17, 0 };
4817 static const hda_nid_t alc260_ssids
[] = { 0x10, 0x15, 0x0f, 0 };
4818 return alc_parse_auto_config(codec
, alc260_ignore
, alc260_ssids
);
4825 ALC260_FIXUP_HP_DC5750
,
4826 ALC260_FIXUP_HP_PIN_0F
,
4829 ALC260_FIXUP_GPIO1_TOGGLE
,
4830 ALC260_FIXUP_REPLACER
,
4831 ALC260_FIXUP_HP_B1900
,
4835 static void alc260_gpio1_automute(struct hda_codec
*codec
)
4837 struct alc_spec
*spec
= codec
->spec
;
4838 snd_hda_codec_write(codec
, 0x01, 0, AC_VERB_SET_GPIO_DATA
,
4839 spec
->hp_jack_present
);
4842 static void alc260_fixup_gpio1_toggle(struct hda_codec
*codec
,
4843 const struct alc_fixup
*fix
, int action
)
4845 struct alc_spec
*spec
= codec
->spec
;
4846 if (action
== ALC_FIXUP_ACT_PROBE
) {
4847 /* although the machine has only one output pin, we need to
4848 * toggle GPIO1 according to the jack state
4850 spec
->automute_hook
= alc260_gpio1_automute
;
4851 spec
->detect_hp
= 1;
4852 spec
->automute_speaker
= 1;
4853 spec
->autocfg
.hp_pins
[0] = 0x0f; /* copy it for automute */
4854 snd_hda_jack_detect_enable_callback(codec
, 0x0f, ALC_HP_EVENT
,
4856 snd_hda_gen_add_verbs(&spec
->gen
, alc_gpio1_init_verbs
);
4860 static void alc260_fixup_kn1(struct hda_codec
*codec
,
4861 const struct alc_fixup
*fix
, int action
)
4863 struct alc_spec
*spec
= codec
->spec
;
4864 static const struct alc_pincfg pincfgs
[] = {
4865 { 0x0f, 0x02214000 }, /* HP/speaker */
4866 { 0x12, 0x90a60160 }, /* int mic */
4867 { 0x13, 0x02a19000 }, /* ext mic */
4868 { 0x18, 0x01446000 }, /* SPDIF out */
4869 /* disable bogus I/O pins */
4870 { 0x10, 0x411111f0 },
4871 { 0x11, 0x411111f0 },
4872 { 0x14, 0x411111f0 },
4873 { 0x15, 0x411111f0 },
4874 { 0x16, 0x411111f0 },
4875 { 0x17, 0x411111f0 },
4876 { 0x19, 0x411111f0 },
4881 case ALC_FIXUP_ACT_PRE_PROBE
:
4882 alc_apply_pincfgs(codec
, pincfgs
);
4884 case ALC_FIXUP_ACT_PROBE
:
4885 spec
->init_amp
= ALC_INIT_NONE
;
4890 static const struct alc_fixup alc260_fixups
[] = {
4891 [ALC260_FIXUP_HP_DC5750
] = {
4892 .type
= ALC_FIXUP_PINS
,
4893 .v
.pins
= (const struct alc_pincfg
[]) {
4894 { 0x11, 0x90130110 }, /* speaker */
4898 [ALC260_FIXUP_HP_PIN_0F
] = {
4899 .type
= ALC_FIXUP_PINS
,
4900 .v
.pins
= (const struct alc_pincfg
[]) {
4901 { 0x0f, 0x01214000 }, /* HP */
4905 [ALC260_FIXUP_COEF
] = {
4906 .type
= ALC_FIXUP_VERBS
,
4907 .v
.verbs
= (const struct hda_verb
[]) {
4908 { 0x20, AC_VERB_SET_COEF_INDEX
, 0x07 },
4909 { 0x20, AC_VERB_SET_PROC_COEF
, 0x3040 },
4913 .chain_id
= ALC260_FIXUP_HP_PIN_0F
,
4915 [ALC260_FIXUP_GPIO1
] = {
4916 .type
= ALC_FIXUP_VERBS
,
4917 .v
.verbs
= alc_gpio1_init_verbs
,
4919 [ALC260_FIXUP_GPIO1_TOGGLE
] = {
4920 .type
= ALC_FIXUP_FUNC
,
4921 .v
.func
= alc260_fixup_gpio1_toggle
,
4923 .chain_id
= ALC260_FIXUP_HP_PIN_0F
,
4925 [ALC260_FIXUP_REPLACER
] = {
4926 .type
= ALC_FIXUP_VERBS
,
4927 .v
.verbs
= (const struct hda_verb
[]) {
4928 { 0x20, AC_VERB_SET_COEF_INDEX
, 0x07 },
4929 { 0x20, AC_VERB_SET_PROC_COEF
, 0x3050 },
4933 .chain_id
= ALC260_FIXUP_GPIO1_TOGGLE
,
4935 [ALC260_FIXUP_HP_B1900
] = {
4936 .type
= ALC_FIXUP_FUNC
,
4937 .v
.func
= alc260_fixup_gpio1_toggle
,
4939 .chain_id
= ALC260_FIXUP_COEF
,
4941 [ALC260_FIXUP_KN1
] = {
4942 .type
= ALC_FIXUP_FUNC
,
4943 .v
.func
= alc260_fixup_kn1
,
4947 static const struct snd_pci_quirk alc260_fixup_tbl
[] = {
4948 SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_FIXUP_GPIO1
),
4949 SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF
),
4950 SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1
),
4951 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750
),
4952 SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900
),
4953 SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1
),
4954 SND_PCI_QUIRK(0x152d, 0x0729, "Quanta KN1", ALC260_FIXUP_KN1
),
4955 SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER
),
4956 SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_FIXUP_COEF
),
4962 static int patch_alc260(struct hda_codec
*codec
)
4964 struct alc_spec
*spec
;
4967 err
= alc_alloc_spec(codec
, 0x07);
4973 alc_pick_fixup(codec
, NULL
, alc260_fixup_tbl
, alc260_fixups
);
4974 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
4976 /* automatic parse from the BIOS config */
4977 err
= alc260_parse_auto_config(codec
);
4981 if (!spec
->no_analog
) {
4982 err
= snd_hda_attach_beep_device(codec
, 0x1);
4985 set_beep_amp(spec
, 0x07, 0x05, HDA_INPUT
);
4988 codec
->patch_ops
= alc_patch_ops
;
4989 spec
->shutup
= alc_eapd_shutup
;
4991 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
5002 * ALC882/883/885/888/889 support
5004 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
5005 * configuration. Each pin widget can choose any input DACs and a mixer.
5006 * Each ADC is connected from a mixer of all inputs. This makes possible
5007 * 6-channel independent captures.
5009 * In addition, an independent DAC for the multi-playback (not used in this
5017 ALC882_FIXUP_ABIT_AW9D_MAX
,
5018 ALC882_FIXUP_LENOVO_Y530
,
5019 ALC882_FIXUP_PB_M5210
,
5020 ALC882_FIXUP_ACER_ASPIRE_7736
,
5021 ALC882_FIXUP_ASUS_W90V
,
5023 ALC889_FIXUP_VAIO_TT
,
5024 ALC888_FIXUP_EEE1601
,
5027 ALC883_FIXUP_ACER_EAPD
,
5032 ALC882_FIXUP_ASUS_W2JC
,
5033 ALC882_FIXUP_ACER_ASPIRE_4930G
,
5034 ALC882_FIXUP_ACER_ASPIRE_8930G
,
5035 ALC882_FIXUP_ASPIRE_8930G_VERBS
,
5036 ALC885_FIXUP_MACPRO_GPIO
,
5037 ALC889_FIXUP_DAC_ROUTE
,
5038 ALC889_FIXUP_MBP_VREF
,
5039 ALC889_FIXUP_IMAC91_VREF
,
5040 ALC882_FIXUP_INV_DMIC
,
5041 ALC882_FIXUP_NO_PRIMARY_HP
,
5044 static void alc889_fixup_coef(struct hda_codec
*codec
,
5045 const struct alc_fixup
*fix
, int action
)
5047 if (action
!= ALC_FIXUP_ACT_INIT
)
5049 alc889_coef_init(codec
);
5052 /* toggle speaker-output according to the hp-jack state */
5053 static void alc882_gpio_mute(struct hda_codec
*codec
, int pin
, int muted
)
5055 unsigned int gpiostate
, gpiomask
, gpiodir
;
5057 gpiostate
= snd_hda_codec_read(codec
, codec
->afg
, 0,
5058 AC_VERB_GET_GPIO_DATA
, 0);
5061 gpiostate
|= (1 << pin
);
5063 gpiostate
&= ~(1 << pin
);
5065 gpiomask
= snd_hda_codec_read(codec
, codec
->afg
, 0,
5066 AC_VERB_GET_GPIO_MASK
, 0);
5067 gpiomask
|= (1 << pin
);
5069 gpiodir
= snd_hda_codec_read(codec
, codec
->afg
, 0,
5070 AC_VERB_GET_GPIO_DIRECTION
, 0);
5071 gpiodir
|= (1 << pin
);
5074 snd_hda_codec_write(codec
, codec
->afg
, 0,
5075 AC_VERB_SET_GPIO_MASK
, gpiomask
);
5076 snd_hda_codec_write(codec
, codec
->afg
, 0,
5077 AC_VERB_SET_GPIO_DIRECTION
, gpiodir
);
5081 snd_hda_codec_write(codec
, codec
->afg
, 0,
5082 AC_VERB_SET_GPIO_DATA
, gpiostate
);
5085 /* set up GPIO at initialization */
5086 static void alc885_fixup_macpro_gpio(struct hda_codec
*codec
,
5087 const struct alc_fixup
*fix
, int action
)
5089 if (action
!= ALC_FIXUP_ACT_INIT
)
5091 alc882_gpio_mute(codec
, 0, 0);
5092 alc882_gpio_mute(codec
, 1, 0);
5095 /* Fix the connection of some pins for ALC889:
5096 * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
5097 * work correctly (bko#42740)
5099 static void alc889_fixup_dac_route(struct hda_codec
*codec
,
5100 const struct alc_fixup
*fix
, int action
)
5102 if (action
== ALC_FIXUP_ACT_PRE_PROBE
) {
5103 /* fake the connections during parsing the tree */
5104 hda_nid_t conn1
[2] = { 0x0c, 0x0d };
5105 hda_nid_t conn2
[2] = { 0x0e, 0x0f };
5106 snd_hda_override_conn_list(codec
, 0x14, 2, conn1
);
5107 snd_hda_override_conn_list(codec
, 0x15, 2, conn1
);
5108 snd_hda_override_conn_list(codec
, 0x18, 2, conn2
);
5109 snd_hda_override_conn_list(codec
, 0x1a, 2, conn2
);
5110 } else if (action
== ALC_FIXUP_ACT_PROBE
) {
5111 /* restore the connections */
5112 hda_nid_t conn
[5] = { 0x0c, 0x0d, 0x0e, 0x0f, 0x26 };
5113 snd_hda_override_conn_list(codec
, 0x14, 5, conn
);
5114 snd_hda_override_conn_list(codec
, 0x15, 5, conn
);
5115 snd_hda_override_conn_list(codec
, 0x18, 5, conn
);
5116 snd_hda_override_conn_list(codec
, 0x1a, 5, conn
);
5120 /* Set VREF on HP pin */
5121 static void alc889_fixup_mbp_vref(struct hda_codec
*codec
,
5122 const struct alc_fixup
*fix
, int action
)
5124 struct alc_spec
*spec
= codec
->spec
;
5125 static hda_nid_t nids
[2] = { 0x14, 0x15 };
5128 if (action
!= ALC_FIXUP_ACT_INIT
)
5130 for (i
= 0; i
< ARRAY_SIZE(nids
); i
++) {
5131 unsigned int val
= snd_hda_codec_get_pincfg(codec
, nids
[i
]);
5132 if (get_defcfg_device(val
) != AC_JACK_HP_OUT
)
5134 val
= snd_hda_codec_read(codec
, nids
[i
], 0,
5135 AC_VERB_GET_PIN_WIDGET_CONTROL
, 0);
5136 val
|= AC_PINCTL_VREF_80
;
5137 snd_hda_set_pin_ctl(codec
, nids
[i
], val
);
5138 spec
->keep_vref_in_automute
= 1;
5143 /* Set VREF on speaker pins on imac91 */
5144 static void alc889_fixup_imac91_vref(struct hda_codec
*codec
,
5145 const struct alc_fixup
*fix
, int action
)
5147 struct alc_spec
*spec
= codec
->spec
;
5148 static hda_nid_t nids
[2] = { 0x18, 0x1a };
5151 if (action
!= ALC_FIXUP_ACT_INIT
)
5153 for (i
= 0; i
< ARRAY_SIZE(nids
); i
++) {
5155 val
= snd_hda_codec_read(codec
, nids
[i
], 0,
5156 AC_VERB_GET_PIN_WIDGET_CONTROL
, 0);
5157 val
|= AC_PINCTL_VREF_50
;
5158 snd_hda_set_pin_ctl(codec
, nids
[i
], val
);
5160 spec
->keep_vref_in_automute
= 1;
5163 /* Don't take HP output as primary
5164 * strangely, the speaker output doesn't work on VAIO Z through DAC 0x05
5166 static void alc882_fixup_no_primary_hp(struct hda_codec
*codec
,
5167 const struct alc_fixup
*fix
, int action
)
5169 struct alc_spec
*spec
= codec
->spec
;
5170 if (action
== ALC_FIXUP_ACT_PRE_PROBE
)
5171 spec
->no_primary_hp
= 1;
5174 static const struct alc_fixup alc882_fixups
[] = {
5175 [ALC882_FIXUP_ABIT_AW9D_MAX
] = {
5176 .type
= ALC_FIXUP_PINS
,
5177 .v
.pins
= (const struct alc_pincfg
[]) {
5178 { 0x15, 0x01080104 }, /* side */
5179 { 0x16, 0x01011012 }, /* rear */
5180 { 0x17, 0x01016011 }, /* clfe */
5184 [ALC882_FIXUP_LENOVO_Y530
] = {
5185 .type
= ALC_FIXUP_PINS
,
5186 .v
.pins
= (const struct alc_pincfg
[]) {
5187 { 0x15, 0x99130112 }, /* rear int speakers */
5188 { 0x16, 0x99130111 }, /* subwoofer */
5192 [ALC882_FIXUP_PB_M5210
] = {
5193 .type
= ALC_FIXUP_VERBS
,
5194 .v
.verbs
= (const struct hda_verb
[]) {
5195 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_VREF50
},
5199 [ALC882_FIXUP_ACER_ASPIRE_7736
] = {
5200 .type
= ALC_FIXUP_FUNC
,
5201 .v
.func
= alc_fixup_sku_ignore
,
5203 [ALC882_FIXUP_ASUS_W90V
] = {
5204 .type
= ALC_FIXUP_PINS
,
5205 .v
.pins
= (const struct alc_pincfg
[]) {
5206 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
5210 [ALC889_FIXUP_CD
] = {
5211 .type
= ALC_FIXUP_PINS
,
5212 .v
.pins
= (const struct alc_pincfg
[]) {
5213 { 0x1c, 0x993301f0 }, /* CD */
5217 [ALC889_FIXUP_VAIO_TT
] = {
5218 .type
= ALC_FIXUP_PINS
,
5219 .v
.pins
= (const struct alc_pincfg
[]) {
5220 { 0x17, 0x90170111 }, /* hidden surround speaker */
5224 [ALC888_FIXUP_EEE1601
] = {
5225 .type
= ALC_FIXUP_VERBS
,
5226 .v
.verbs
= (const struct hda_verb
[]) {
5227 { 0x20, AC_VERB_SET_COEF_INDEX
, 0x0b },
5228 { 0x20, AC_VERB_SET_PROC_COEF
, 0x0838 },
5232 [ALC882_FIXUP_EAPD
] = {
5233 .type
= ALC_FIXUP_VERBS
,
5234 .v
.verbs
= (const struct hda_verb
[]) {
5235 /* change to EAPD mode */
5236 { 0x20, AC_VERB_SET_COEF_INDEX
, 0x07 },
5237 { 0x20, AC_VERB_SET_PROC_COEF
, 0x3060 },
5241 [ALC883_FIXUP_EAPD
] = {
5242 .type
= ALC_FIXUP_VERBS
,
5243 .v
.verbs
= (const struct hda_verb
[]) {
5244 /* change to EAPD mode */
5245 { 0x20, AC_VERB_SET_COEF_INDEX
, 0x07 },
5246 { 0x20, AC_VERB_SET_PROC_COEF
, 0x3070 },
5250 [ALC883_FIXUP_ACER_EAPD
] = {
5251 .type
= ALC_FIXUP_VERBS
,
5252 .v
.verbs
= (const struct hda_verb
[]) {
5253 /* eanable EAPD on Acer laptops */
5254 { 0x20, AC_VERB_SET_COEF_INDEX
, 0x07 },
5255 { 0x20, AC_VERB_SET_PROC_COEF
, 0x3050 },
5259 [ALC882_FIXUP_GPIO1
] = {
5260 .type
= ALC_FIXUP_VERBS
,
5261 .v
.verbs
= alc_gpio1_init_verbs
,
5263 [ALC882_FIXUP_GPIO2
] = {
5264 .type
= ALC_FIXUP_VERBS
,
5265 .v
.verbs
= alc_gpio2_init_verbs
,
5267 [ALC882_FIXUP_GPIO3
] = {
5268 .type
= ALC_FIXUP_VERBS
,
5269 .v
.verbs
= alc_gpio3_init_verbs
,
5271 [ALC882_FIXUP_ASUS_W2JC
] = {
5272 .type
= ALC_FIXUP_VERBS
,
5273 .v
.verbs
= alc_gpio1_init_verbs
,
5275 .chain_id
= ALC882_FIXUP_EAPD
,
5277 [ALC889_FIXUP_COEF
] = {
5278 .type
= ALC_FIXUP_FUNC
,
5279 .v
.func
= alc889_fixup_coef
,
5281 [ALC882_FIXUP_ACER_ASPIRE_4930G
] = {
5282 .type
= ALC_FIXUP_PINS
,
5283 .v
.pins
= (const struct alc_pincfg
[]) {
5284 { 0x16, 0x99130111 }, /* CLFE speaker */
5285 { 0x17, 0x99130112 }, /* surround speaker */
5289 .chain_id
= ALC882_FIXUP_GPIO1
,
5291 [ALC882_FIXUP_ACER_ASPIRE_8930G
] = {
5292 .type
= ALC_FIXUP_PINS
,
5293 .v
.pins
= (const struct alc_pincfg
[]) {
5294 { 0x16, 0x99130111 }, /* CLFE speaker */
5295 { 0x1b, 0x99130112 }, /* surround speaker */
5299 .chain_id
= ALC882_FIXUP_ASPIRE_8930G_VERBS
,
5301 [ALC882_FIXUP_ASPIRE_8930G_VERBS
] = {
5302 /* additional init verbs for Acer Aspire 8930G */
5303 .type
= ALC_FIXUP_VERBS
,
5304 .v
.verbs
= (const struct hda_verb
[]) {
5305 /* Enable all DACs */
5306 /* DAC DISABLE/MUTE 1? */
5307 /* setting bits 1-5 disables DAC nids 0x02-0x06
5308 * apparently. Init=0x38 */
5309 { 0x20, AC_VERB_SET_COEF_INDEX
, 0x03 },
5310 { 0x20, AC_VERB_SET_PROC_COEF
, 0x0000 },
5311 /* DAC DISABLE/MUTE 2? */
5312 /* some bit here disables the other DACs.
5314 { 0x20, AC_VERB_SET_COEF_INDEX
, 0x08 },
5315 { 0x20, AC_VERB_SET_PROC_COEF
, 0x0000 },
5317 * This laptop has a stereo digital microphone.
5318 * The mics are only 1cm apart which makes the stereo
5319 * useless. However, either the mic or the ALC889
5320 * makes the signal become a difference/sum signal
5321 * instead of standard stereo, which is annoying.
5322 * So instead we flip this bit which makes the
5323 * codec replicate the sum signal to both channels,
5324 * turning it into a normal mono mic.
5326 /* DMIC_CONTROL? Init value = 0x0001 */
5327 { 0x20, AC_VERB_SET_COEF_INDEX
, 0x0b },
5328 { 0x20, AC_VERB_SET_PROC_COEF
, 0x0003 },
5329 { 0x20, AC_VERB_SET_COEF_INDEX
, 0x07 },
5330 { 0x20, AC_VERB_SET_PROC_COEF
, 0x3050 },
5334 .chain_id
= ALC882_FIXUP_GPIO1
,
5336 [ALC885_FIXUP_MACPRO_GPIO
] = {
5337 .type
= ALC_FIXUP_FUNC
,
5338 .v
.func
= alc885_fixup_macpro_gpio
,
5340 [ALC889_FIXUP_DAC_ROUTE
] = {
5341 .type
= ALC_FIXUP_FUNC
,
5342 .v
.func
= alc889_fixup_dac_route
,
5344 [ALC889_FIXUP_MBP_VREF
] = {
5345 .type
= ALC_FIXUP_FUNC
,
5346 .v
.func
= alc889_fixup_mbp_vref
,
5348 .chain_id
= ALC882_FIXUP_GPIO1
,
5350 [ALC889_FIXUP_IMAC91_VREF
] = {
5351 .type
= ALC_FIXUP_FUNC
,
5352 .v
.func
= alc889_fixup_imac91_vref
,
5354 .chain_id
= ALC882_FIXUP_GPIO1
,
5356 [ALC882_FIXUP_INV_DMIC
] = {
5357 .type
= ALC_FIXUP_FUNC
,
5358 .v
.func
= alc_fixup_inv_dmic_0x12
,
5360 [ALC882_FIXUP_NO_PRIMARY_HP
] = {
5361 .type
= ALC_FIXUP_FUNC
,
5362 .v
.func
= alc882_fixup_no_primary_hp
,
5366 static const struct snd_pci_quirk alc882_fixup_tbl
[] = {
5367 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD
),
5368 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD
),
5369 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD
),
5370 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD
),
5371 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD
),
5372 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD
),
5373 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
5374 ALC882_FIXUP_ACER_ASPIRE_4930G
),
5375 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
5376 ALC882_FIXUP_ACER_ASPIRE_4930G
),
5377 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
5378 ALC882_FIXUP_ACER_ASPIRE_8930G
),
5379 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
5380 ALC882_FIXUP_ACER_ASPIRE_8930G
),
5381 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
5382 ALC882_FIXUP_ACER_ASPIRE_4930G
),
5383 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
5384 ALC882_FIXUP_ACER_ASPIRE_4930G
),
5385 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
5386 ALC882_FIXUP_ACER_ASPIRE_4930G
),
5387 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210
),
5388 SND_PCI_QUIRK(0x1025, 0x021e, "Acer Aspire 5739G",
5389 ALC882_FIXUP_ACER_ASPIRE_4930G
),
5390 SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE
),
5391 SND_PCI_QUIRK(0x1025, 0x026b, "Acer Aspire 8940G", ALC882_FIXUP_ACER_ASPIRE_8930G
),
5392 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736
),
5393 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD
),
5394 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V
),
5395 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC
),
5396 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601
),
5397 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT
),
5398 SND_PCI_QUIRK(0x104d, 0x905a, "Sony Vaio Z", ALC882_FIXUP_NO_PRIMARY_HP
),
5400 /* All Apple entries are in codec SSIDs */
5401 SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC889_FIXUP_MBP_VREF
),
5402 SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC889_FIXUP_MBP_VREF
),
5403 SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF
),
5404 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO
),
5405 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO
),
5406 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO
),
5407 SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC889_FIXUP_MBP_VREF
),
5408 SND_PCI_QUIRK(0x106b, 0x3000, "iMac", ALC889_FIXUP_MBP_VREF
),
5409 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD
),
5410 SND_PCI_QUIRK(0x106b, 0x3400, "MacBookAir 1,1", ALC889_FIXUP_MBP_VREF
),
5411 SND_PCI_QUIRK(0x106b, 0x3500, "MacBookAir 2,1", ALC889_FIXUP_MBP_VREF
),
5412 SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889_FIXUP_MBP_VREF
),
5413 SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF
),
5414 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO
),
5415 SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC889_FIXUP_IMAC91_VREF
),
5416 SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC889_FIXUP_IMAC91_VREF
),
5417 SND_PCI_QUIRK(0x106b, 0x4100, "Macmini 3,1", ALC889_FIXUP_IMAC91_VREF
),
5418 SND_PCI_QUIRK(0x106b, 0x4200, "Mac Pro 5,1", ALC885_FIXUP_MACPRO_GPIO
),
5419 SND_PCI_QUIRK(0x106b, 0x4300, "iMac 9,1", ALC889_FIXUP_IMAC91_VREF
),
5420 SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC889_FIXUP_IMAC91_VREF
),
5421 SND_PCI_QUIRK(0x106b, 0x4900, "iMac 9,1 Aluminum", ALC889_FIXUP_IMAC91_VREF
),
5422 SND_PCI_QUIRK(0x106b, 0x4a00, "Macbook 5,2", ALC889_FIXUP_IMAC91_VREF
),
5424 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD
),
5425 SND_PCI_QUIRK(0x1462, 0x7350, "MSI-7350", ALC889_FIXUP_CD
),
5426 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3
),
5427 SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte EP45-DS3", ALC889_FIXUP_CD
),
5428 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX
),
5429 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD
),
5430 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD
),
5431 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530
),
5432 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF
),
5436 static const struct alc_model_fixup alc882_fixup_models
[] = {
5437 {.id
= ALC882_FIXUP_ACER_ASPIRE_4930G
, .name
= "acer-aspire-4930g"},
5438 {.id
= ALC882_FIXUP_ACER_ASPIRE_8930G
, .name
= "acer-aspire-8930g"},
5439 {.id
= ALC883_FIXUP_ACER_EAPD
, .name
= "acer-aspire"},
5440 {.id
= ALC882_FIXUP_INV_DMIC
, .name
= "inv-dmic"},
5441 {.id
= ALC882_FIXUP_NO_PRIMARY_HP
, .name
= "no-primary-hp"},
5446 * BIOS auto configuration
5448 /* almost identical with ALC880 parser... */
5449 static int alc882_parse_auto_config(struct hda_codec
*codec
)
5451 static const hda_nid_t alc882_ignore
[] = { 0x1d, 0 };
5452 static const hda_nid_t alc882_ssids
[] = { 0x15, 0x1b, 0x14, 0 };
5453 return alc_parse_auto_config(codec
, alc882_ignore
, alc882_ssids
);
5458 static int patch_alc882(struct hda_codec
*codec
)
5460 struct alc_spec
*spec
;
5463 err
= alc_alloc_spec(codec
, 0x0b);
5469 switch (codec
->vendor_id
) {
5474 /* ALC883 and variants */
5475 alc_fix_pll_init(codec
, 0x20, 0x0a, 10);
5479 alc_pick_fixup(codec
, alc882_fixup_models
, alc882_fixup_tbl
,
5481 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
5483 alc_auto_parse_customize_define(codec
);
5485 /* automatic parse from the BIOS config */
5486 err
= alc882_parse_auto_config(codec
);
5490 if (!spec
->no_analog
&& has_cdefine_beep(codec
)) {
5491 err
= snd_hda_attach_beep_device(codec
, 0x1);
5494 set_beep_amp(spec
, 0x0b, 0x05, HDA_INPUT
);
5497 codec
->patch_ops
= alc_patch_ops
;
5499 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
5512 static int alc262_parse_auto_config(struct hda_codec
*codec
)
5514 static const hda_nid_t alc262_ignore
[] = { 0x1d, 0 };
5515 static const hda_nid_t alc262_ssids
[] = { 0x15, 0x1b, 0x14, 0 };
5516 return alc_parse_auto_config(codec
, alc262_ignore
, alc262_ssids
);
5523 ALC262_FIXUP_FSC_H270
,
5524 ALC262_FIXUP_HP_Z200
,
5526 ALC262_FIXUP_LENOVO_3000
,
5528 ALC262_FIXUP_BENQ_T31
,
5529 ALC262_FIXUP_INV_DMIC
,
5532 static const struct alc_fixup alc262_fixups
[] = {
5533 [ALC262_FIXUP_FSC_H270
] = {
5534 .type
= ALC_FIXUP_PINS
,
5535 .v
.pins
= (const struct alc_pincfg
[]) {
5536 { 0x14, 0x99130110 }, /* speaker */
5537 { 0x15, 0x0221142f }, /* front HP */
5538 { 0x1b, 0x0121141f }, /* rear HP */
5542 [ALC262_FIXUP_HP_Z200
] = {
5543 .type
= ALC_FIXUP_PINS
,
5544 .v
.pins
= (const struct alc_pincfg
[]) {
5545 { 0x16, 0x99130120 }, /* internal speaker */
5549 [ALC262_FIXUP_TYAN
] = {
5550 .type
= ALC_FIXUP_PINS
,
5551 .v
.pins
= (const struct alc_pincfg
[]) {
5552 { 0x14, 0x1993e1f0 }, /* int AUX */
5556 [ALC262_FIXUP_LENOVO_3000
] = {
5557 .type
= ALC_FIXUP_VERBS
,
5558 .v
.verbs
= (const struct hda_verb
[]) {
5559 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_VREF50
},
5563 .chain_id
= ALC262_FIXUP_BENQ
,
5565 [ALC262_FIXUP_BENQ
] = {
5566 .type
= ALC_FIXUP_VERBS
,
5567 .v
.verbs
= (const struct hda_verb
[]) {
5568 { 0x20, AC_VERB_SET_COEF_INDEX
, 0x07 },
5569 { 0x20, AC_VERB_SET_PROC_COEF
, 0x3070 },
5573 [ALC262_FIXUP_BENQ_T31
] = {
5574 .type
= ALC_FIXUP_VERBS
,
5575 .v
.verbs
= (const struct hda_verb
[]) {
5576 { 0x20, AC_VERB_SET_COEF_INDEX
, 0x07 },
5577 { 0x20, AC_VERB_SET_PROC_COEF
, 0x3050 },
5581 [ALC262_FIXUP_INV_DMIC
] = {
5582 .type
= ALC_FIXUP_FUNC
,
5583 .v
.func
= alc_fixup_inv_dmic_0x12
,
5587 static const struct snd_pci_quirk alc262_fixup_tbl
[] = {
5588 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200
),
5589 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ
),
5590 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ
),
5591 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN
),
5592 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270
),
5593 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000
),
5594 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ
),
5595 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31
),
5599 static const struct alc_model_fixup alc262_fixup_models
[] = {
5600 {.id
= ALC262_FIXUP_INV_DMIC
, .name
= "inv-dmic"},
5606 static int patch_alc262(struct hda_codec
*codec
)
5608 struct alc_spec
*spec
;
5611 err
= alc_alloc_spec(codec
, 0x0b);
5618 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
5623 snd_hda_codec_write(codec
, 0x1a, 0, AC_VERB_SET_COEF_INDEX
, 7);
5624 tmp
= snd_hda_codec_read(codec
, 0x20, 0, AC_VERB_GET_PROC_COEF
, 0);
5625 snd_hda_codec_write(codec
, 0x1a, 0, AC_VERB_SET_COEF_INDEX
, 7);
5626 snd_hda_codec_write(codec
, 0x1a, 0, AC_VERB_SET_PROC_COEF
, tmp
| 0x80);
5629 alc_fix_pll_init(codec
, 0x20, 0x0a, 10);
5631 alc_pick_fixup(codec
, alc262_fixup_models
, alc262_fixup_tbl
,
5633 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
5635 alc_auto_parse_customize_define(codec
);
5637 /* automatic parse from the BIOS config */
5638 err
= alc262_parse_auto_config(codec
);
5642 if (!spec
->no_analog
&& has_cdefine_beep(codec
)) {
5643 err
= snd_hda_attach_beep_device(codec
, 0x1);
5646 set_beep_amp(spec
, 0x0b, 0x05, HDA_INPUT
);
5649 codec
->patch_ops
= alc_patch_ops
;
5650 spec
->shutup
= alc_eapd_shutup
;
5652 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
5664 /* bind Beep switches of both NID 0x0f and 0x10 */
5665 static const struct hda_bind_ctls alc268_bind_beep_sw
= {
5666 .ops
= &snd_hda_bind_sw
,
5668 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT
),
5669 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT
),
5674 static const struct snd_kcontrol_new alc268_beep_mixer
[] = {
5675 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT
),
5676 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw
),
5680 /* set PCBEEP vol = 0, mute connections */
5681 static const struct hda_verb alc268_beep_init_verbs
[] = {
5682 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
5683 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(1)},
5684 {0x10, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(1)},
5689 ALC268_FIXUP_INV_DMIC
,
5690 ALC268_FIXUP_HP_EAPD
,
5693 static const struct alc_fixup alc268_fixups
[] = {
5694 [ALC268_FIXUP_INV_DMIC
] = {
5695 .type
= ALC_FIXUP_FUNC
,
5696 .v
.func
= alc_fixup_inv_dmic_0x12
,
5698 [ALC268_FIXUP_HP_EAPD
] = {
5699 .type
= ALC_FIXUP_VERBS
,
5700 .v
.verbs
= (const struct hda_verb
[]) {
5701 {0x15, AC_VERB_SET_EAPD_BTLENABLE
, 0},
5707 static const struct alc_model_fixup alc268_fixup_models
[] = {
5708 {.id
= ALC268_FIXUP_INV_DMIC
, .name
= "inv-dmic"},
5709 {.id
= ALC268_FIXUP_HP_EAPD
, .name
= "hp-eapd"},
5713 static const struct snd_pci_quirk alc268_fixup_tbl
[] = {
5714 /* below is codec SSID since multiple Toshiba laptops have the
5715 * same PCI SSID 1179:ff00
5717 SND_PCI_QUIRK(0x1179, 0xff06, "Toshiba P200", ALC268_FIXUP_HP_EAPD
),
5722 * BIOS auto configuration
5724 static int alc268_parse_auto_config(struct hda_codec
*codec
)
5726 static const hda_nid_t alc268_ssids
[] = { 0x15, 0x1b, 0x14, 0 };
5727 struct alc_spec
*spec
= codec
->spec
;
5728 int err
= alc_parse_auto_config(codec
, NULL
, alc268_ssids
);
5730 if (!spec
->no_analog
&& spec
->autocfg
.speaker_pins
[0] != 0x1d) {
5731 add_mixer(spec
, alc268_beep_mixer
);
5732 snd_hda_gen_add_verbs(&spec
->gen
, alc268_beep_init_verbs
);
5740 static int patch_alc268(struct hda_codec
*codec
)
5742 struct alc_spec
*spec
;
5743 int i
, has_beep
, err
;
5745 /* ALC268 has no aa-loopback mixer */
5746 err
= alc_alloc_spec(codec
, 0);
5752 alc_pick_fixup(codec
, alc268_fixup_models
, alc268_fixup_tbl
, alc268_fixups
);
5753 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
5755 /* automatic parse from the BIOS config */
5756 err
= alc268_parse_auto_config(codec
);
5761 for (i
= 0; i
< spec
->num_mixers
; i
++) {
5762 if (spec
->mixers
[i
] == alc268_beep_mixer
) {
5769 err
= snd_hda_attach_beep_device(codec
, 0x1);
5772 if (!query_amp_caps(codec
, 0x1d, HDA_INPUT
))
5773 /* override the amp caps for beep generator */
5774 snd_hda_override_amp_caps(codec
, 0x1d, HDA_INPUT
,
5775 (0x0c << AC_AMPCAP_OFFSET_SHIFT
) |
5776 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT
) |
5777 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT
) |
5778 (0 << AC_AMPCAP_MUTE_SHIFT
));
5781 codec
->patch_ops
= alc_patch_ops
;
5782 spec
->shutup
= alc_eapd_shutup
;
5784 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
5796 static const struct hda_pcm_stream alc269_44k_pcm_analog_playback
= {
5800 .rates
= SNDRV_PCM_RATE_44100
, /* fixed rate */
5801 /* NID is set in alc_build_pcms */
5803 .open
= alc_playback_pcm_open
,
5804 .prepare
= alc_playback_pcm_prepare
,
5805 .cleanup
= alc_playback_pcm_cleanup
5809 static const struct hda_pcm_stream alc269_44k_pcm_analog_capture
= {
5813 .rates
= SNDRV_PCM_RATE_44100
, /* fixed rate */
5814 /* NID is set in alc_build_pcms */
5817 /* different alc269-variants */
5819 ALC269_TYPE_ALC269VA
,
5820 ALC269_TYPE_ALC269VB
,
5821 ALC269_TYPE_ALC269VC
,
5822 ALC269_TYPE_ALC269VD
,
5826 * BIOS auto configuration
5828 static int alc269_parse_auto_config(struct hda_codec
*codec
)
5830 static const hda_nid_t alc269_ignore
[] = { 0x1d, 0 };
5831 static const hda_nid_t alc269_ssids
[] = { 0, 0x1b, 0x14, 0x21 };
5832 static const hda_nid_t alc269va_ssids
[] = { 0x15, 0x1b, 0x14, 0 };
5833 struct alc_spec
*spec
= codec
->spec
;
5834 const hda_nid_t
*ssids
;
5836 switch (spec
->codec_variant
) {
5837 case ALC269_TYPE_ALC269VA
:
5838 case ALC269_TYPE_ALC269VC
:
5839 ssids
= alc269va_ssids
;
5841 case ALC269_TYPE_ALC269VB
:
5842 case ALC269_TYPE_ALC269VD
:
5843 ssids
= alc269_ssids
;
5846 ssids
= alc269_ssids
;
5850 return alc_parse_auto_config(codec
, alc269_ignore
, ssids
);
5853 static void alc269vb_toggle_power_output(struct hda_codec
*codec
, int power_up
)
5855 int val
= alc_read_coef_idx(codec
, 0x04);
5860 alc_write_coef_idx(codec
, 0x04, val
);
5863 static void alc269_shutup(struct hda_codec
*codec
)
5865 struct alc_spec
*spec
= codec
->spec
;
5867 if (spec
->codec_variant
!= ALC269_TYPE_ALC269VB
)
5870 if (spec
->codec_variant
== ALC269_TYPE_ALC269VB
)
5871 alc269vb_toggle_power_output(codec
, 0);
5872 if (spec
->codec_variant
== ALC269_TYPE_ALC269VB
&&
5873 (alc_get_coef0(codec
) & 0x00ff) == 0x018) {
5879 static int alc269_resume(struct hda_codec
*codec
)
5881 struct alc_spec
*spec
= codec
->spec
;
5883 if (spec
->codec_variant
== ALC269_TYPE_ALC269VB
)
5884 alc269vb_toggle_power_output(codec
, 0);
5885 if (spec
->codec_variant
== ALC269_TYPE_ALC269VB
&&
5886 (alc_get_coef0(codec
) & 0x00ff) == 0x018) {
5890 codec
->patch_ops
.init(codec
);
5892 if (spec
->codec_variant
== ALC269_TYPE_ALC269VB
)
5893 alc269vb_toggle_power_output(codec
, 1);
5894 if (spec
->codec_variant
== ALC269_TYPE_ALC269VB
&&
5895 (alc_get_coef0(codec
) & 0x00ff) == 0x017) {
5899 snd_hda_codec_resume_amp(codec
);
5900 snd_hda_codec_resume_cache(codec
);
5901 hda_call_check_power_status(codec
, 0x01);
5904 #endif /* CONFIG_PM */
5906 static void alc269_fixup_pincfg_no_hp_to_lineout(struct hda_codec
*codec
,
5907 const struct alc_fixup
*fix
, int action
)
5909 struct alc_spec
*spec
= codec
->spec
;
5911 if (action
== ALC_FIXUP_ACT_PRE_PROBE
)
5912 spec
->parse_flags
= HDA_PINCFG_NO_HP_FIXUP
;
5915 static void alc269_fixup_hweq(struct hda_codec
*codec
,
5916 const struct alc_fixup
*fix
, int action
)
5920 if (action
!= ALC_FIXUP_ACT_INIT
)
5922 coef
= alc_read_coef_idx(codec
, 0x1e);
5923 alc_write_coef_idx(codec
, 0x1e, coef
| 0x80);
5926 static void alc271_fixup_dmic(struct hda_codec
*codec
,
5927 const struct alc_fixup
*fix
, int action
)
5929 static const struct hda_verb verbs
[] = {
5930 {0x20, AC_VERB_SET_COEF_INDEX
, 0x0d},
5931 {0x20, AC_VERB_SET_PROC_COEF
, 0x4000},
5936 if (strcmp(codec
->chip_name
, "ALC271X"))
5938 cfg
= snd_hda_codec_get_pincfg(codec
, 0x12);
5939 if (get_defcfg_connect(cfg
) == AC_JACK_PORT_FIXED
)
5940 snd_hda_sequence_write(codec
, verbs
);
5943 static void alc269_fixup_pcm_44k(struct hda_codec
*codec
,
5944 const struct alc_fixup
*fix
, int action
)
5946 struct alc_spec
*spec
= codec
->spec
;
5948 if (action
!= ALC_FIXUP_ACT_PROBE
)
5951 /* Due to a hardware problem on Lenovo Ideadpad, we need to
5952 * fix the sample rate of analog I/O to 44.1kHz
5954 spec
->stream_analog_playback
= &alc269_44k_pcm_analog_playback
;
5955 spec
->stream_analog_capture
= &alc269_44k_pcm_analog_capture
;
5958 static void alc269_fixup_stereo_dmic(struct hda_codec
*codec
,
5959 const struct alc_fixup
*fix
, int action
)
5963 if (action
!= ALC_FIXUP_ACT_INIT
)
5965 /* The digital-mic unit sends PDM (differential signal) instead of
5966 * the standard PCM, thus you can't record a valid mono stream as is.
5967 * Below is a workaround specific to ALC269 to control the dmic
5968 * signal source as mono.
5970 coef
= alc_read_coef_idx(codec
, 0x07);
5971 alc_write_coef_idx(codec
, 0x07, coef
| 0x80);
5974 static void alc269_quanta_automute(struct hda_codec
*codec
)
5976 update_outputs(codec
);
5978 snd_hda_codec_write(codec
, 0x20, 0,
5979 AC_VERB_SET_COEF_INDEX
, 0x0c);
5980 snd_hda_codec_write(codec
, 0x20, 0,
5981 AC_VERB_SET_PROC_COEF
, 0x680);
5983 snd_hda_codec_write(codec
, 0x20, 0,
5984 AC_VERB_SET_COEF_INDEX
, 0x0c);
5985 snd_hda_codec_write(codec
, 0x20, 0,
5986 AC_VERB_SET_PROC_COEF
, 0x480);
5989 static void alc269_fixup_quanta_mute(struct hda_codec
*codec
,
5990 const struct alc_fixup
*fix
, int action
)
5992 struct alc_spec
*spec
= codec
->spec
;
5993 if (action
!= ALC_FIXUP_ACT_PROBE
)
5995 spec
->automute_hook
= alc269_quanta_automute
;
5998 /* update mute-LED according to the speaker mute state via mic2 VREF pin */
5999 static void alc269_fixup_mic2_mute_hook(void *private_data
, int enabled
)
6001 struct hda_codec
*codec
= private_data
;
6002 unsigned int pinval
= enabled
? 0x20 : 0x24;
6003 snd_hda_set_pin_ctl_cache(codec
, 0x19, pinval
);
6006 static void alc269_fixup_mic2_mute(struct hda_codec
*codec
,
6007 const struct alc_fixup
*fix
, int action
)
6009 struct alc_spec
*spec
= codec
->spec
;
6011 case ALC_FIXUP_ACT_BUILD
:
6012 spec
->vmaster_mute
.hook
= alc269_fixup_mic2_mute_hook
;
6013 snd_hda_add_vmaster_hook(codec
, &spec
->vmaster_mute
, true);
6015 case ALC_FIXUP_ACT_INIT
:
6016 snd_hda_sync_vmaster_hook(&spec
->vmaster_mute
);
6021 static void alc271_hp_gate_mic_jack(struct hda_codec
*codec
,
6022 const struct alc_fixup
*fix
,
6025 struct alc_spec
*spec
= codec
->spec
;
6027 if (action
== ALC_FIXUP_ACT_PROBE
)
6028 snd_hda_jack_set_gating_jack(codec
, spec
->ext_mic_pin
,
6029 spec
->autocfg
.hp_pins
[0]);
6033 ALC269_FIXUP_SONY_VAIO
,
6034 ALC275_FIXUP_SONY_VAIO_GPIO2
,
6035 ALC269_FIXUP_DELL_M101Z
,
6036 ALC269_FIXUP_SKU_IGNORE
,
6037 ALC269_FIXUP_ASUS_G73JW
,
6038 ALC269_FIXUP_LENOVO_EAPD
,
6039 ALC275_FIXUP_SONY_HWEQ
,
6041 ALC269_FIXUP_PCM_44K
,
6042 ALC269_FIXUP_STEREO_DMIC
,
6043 ALC269_FIXUP_QUANTA_MUTE
,
6044 ALC269_FIXUP_LIFEBOOK
,
6047 ALC269VB_FIXUP_AMIC
,
6048 ALC269VB_FIXUP_DMIC
,
6049 ALC269_FIXUP_MIC2_MUTE_LED
,
6050 ALC269_FIXUP_INV_DMIC
,
6051 ALC269_FIXUP_LENOVO_DOCK
,
6052 ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT
,
6053 ALC271_FIXUP_AMIC_MIC2
,
6054 ALC271_FIXUP_HP_GATE_MIC_JACK
,
6057 static const struct alc_fixup alc269_fixups
[] = {
6058 [ALC269_FIXUP_SONY_VAIO
] = {
6059 .type
= ALC_FIXUP_VERBS
,
6060 .v
.verbs
= (const struct hda_verb
[]) {
6061 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_VREFGRD
},
6065 [ALC275_FIXUP_SONY_VAIO_GPIO2
] = {
6066 .type
= ALC_FIXUP_VERBS
,
6067 .v
.verbs
= (const struct hda_verb
[]) {
6068 {0x01, AC_VERB_SET_GPIO_MASK
, 0x04},
6069 {0x01, AC_VERB_SET_GPIO_DIRECTION
, 0x04},
6070 {0x01, AC_VERB_SET_GPIO_DATA
, 0x00},
6074 .chain_id
= ALC269_FIXUP_SONY_VAIO
6076 [ALC269_FIXUP_DELL_M101Z
] = {
6077 .type
= ALC_FIXUP_VERBS
,
6078 .v
.verbs
= (const struct hda_verb
[]) {
6079 /* Enables internal speaker */
6080 {0x20, AC_VERB_SET_COEF_INDEX
, 13},
6081 {0x20, AC_VERB_SET_PROC_COEF
, 0x4040},
6085 [ALC269_FIXUP_SKU_IGNORE
] = {
6086 .type
= ALC_FIXUP_FUNC
,
6087 .v
.func
= alc_fixup_sku_ignore
,
6089 [ALC269_FIXUP_ASUS_G73JW
] = {
6090 .type
= ALC_FIXUP_PINS
,
6091 .v
.pins
= (const struct alc_pincfg
[]) {
6092 { 0x17, 0x99130111 }, /* subwoofer */
6096 [ALC269_FIXUP_LENOVO_EAPD
] = {
6097 .type
= ALC_FIXUP_VERBS
,
6098 .v
.verbs
= (const struct hda_verb
[]) {
6099 {0x14, AC_VERB_SET_EAPD_BTLENABLE
, 0},
6103 [ALC275_FIXUP_SONY_HWEQ
] = {
6104 .type
= ALC_FIXUP_FUNC
,
6105 .v
.func
= alc269_fixup_hweq
,
6107 .chain_id
= ALC275_FIXUP_SONY_VAIO_GPIO2
6109 [ALC271_FIXUP_DMIC
] = {
6110 .type
= ALC_FIXUP_FUNC
,
6111 .v
.func
= alc271_fixup_dmic
,
6113 [ALC269_FIXUP_PCM_44K
] = {
6114 .type
= ALC_FIXUP_FUNC
,
6115 .v
.func
= alc269_fixup_pcm_44k
,
6117 .chain_id
= ALC269_FIXUP_QUANTA_MUTE
6119 [ALC269_FIXUP_STEREO_DMIC
] = {
6120 .type
= ALC_FIXUP_FUNC
,
6121 .v
.func
= alc269_fixup_stereo_dmic
,
6123 [ALC269_FIXUP_QUANTA_MUTE
] = {
6124 .type
= ALC_FIXUP_FUNC
,
6125 .v
.func
= alc269_fixup_quanta_mute
,
6127 [ALC269_FIXUP_LIFEBOOK
] = {
6128 .type
= ALC_FIXUP_PINS
,
6129 .v
.pins
= (const struct alc_pincfg
[]) {
6130 { 0x1a, 0x2101103f }, /* dock line-out */
6131 { 0x1b, 0x23a11040 }, /* dock mic-in */
6135 .chain_id
= ALC269_FIXUP_QUANTA_MUTE
6137 [ALC269_FIXUP_AMIC
] = {
6138 .type
= ALC_FIXUP_PINS
,
6139 .v
.pins
= (const struct alc_pincfg
[]) {
6140 { 0x14, 0x99130110 }, /* speaker */
6141 { 0x15, 0x0121401f }, /* HP out */
6142 { 0x18, 0x01a19c20 }, /* mic */
6143 { 0x19, 0x99a3092f }, /* int-mic */
6147 [ALC269_FIXUP_DMIC
] = {
6148 .type
= ALC_FIXUP_PINS
,
6149 .v
.pins
= (const struct alc_pincfg
[]) {
6150 { 0x12, 0x99a3092f }, /* int-mic */
6151 { 0x14, 0x99130110 }, /* speaker */
6152 { 0x15, 0x0121401f }, /* HP out */
6153 { 0x18, 0x01a19c20 }, /* mic */
6157 [ALC269VB_FIXUP_AMIC
] = {
6158 .type
= ALC_FIXUP_PINS
,
6159 .v
.pins
= (const struct alc_pincfg
[]) {
6160 { 0x14, 0x99130110 }, /* speaker */
6161 { 0x18, 0x01a19c20 }, /* mic */
6162 { 0x19, 0x99a3092f }, /* int-mic */
6163 { 0x21, 0x0121401f }, /* HP out */
6167 [ALC269VB_FIXUP_DMIC
] = {
6168 .type
= ALC_FIXUP_PINS
,
6169 .v
.pins
= (const struct alc_pincfg
[]) {
6170 { 0x12, 0x99a3092f }, /* int-mic */
6171 { 0x14, 0x99130110 }, /* speaker */
6172 { 0x18, 0x01a19c20 }, /* mic */
6173 { 0x21, 0x0121401f }, /* HP out */
6177 [ALC269_FIXUP_MIC2_MUTE_LED
] = {
6178 .type
= ALC_FIXUP_FUNC
,
6179 .v
.func
= alc269_fixup_mic2_mute
,
6181 [ALC269_FIXUP_INV_DMIC
] = {
6182 .type
= ALC_FIXUP_FUNC
,
6183 .v
.func
= alc_fixup_inv_dmic_0x12
,
6185 [ALC269_FIXUP_LENOVO_DOCK
] = {
6186 .type
= ALC_FIXUP_PINS
,
6187 .v
.pins
= (const struct alc_pincfg
[]) {
6188 { 0x19, 0x23a11040 }, /* dock mic */
6189 { 0x1b, 0x2121103f }, /* dock headphone */
6193 .chain_id
= ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT
6195 [ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT
] = {
6196 .type
= ALC_FIXUP_FUNC
,
6197 .v
.func
= alc269_fixup_pincfg_no_hp_to_lineout
,
6199 [ALC271_FIXUP_AMIC_MIC2
] = {
6200 .type
= ALC_FIXUP_PINS
,
6201 .v
.pins
= (const struct alc_pincfg
[]) {
6202 { 0x14, 0x99130110 }, /* speaker */
6203 { 0x19, 0x01a19c20 }, /* mic */
6204 { 0x1b, 0x99a7012f }, /* int-mic */
6205 { 0x21, 0x0121401f }, /* HP out */
6209 [ALC271_FIXUP_HP_GATE_MIC_JACK
] = {
6210 .type
= ALC_FIXUP_FUNC
,
6211 .v
.func
= alc271_hp_gate_mic_jack
,
6213 .chain_id
= ALC271_FIXUP_AMIC_MIC2
,
6217 static const struct snd_pci_quirk alc269_fixup_tbl
[] = {
6218 SND_PCI_QUIRK(0x1025, 0x029b, "Acer 1810TZ", ALC269_FIXUP_INV_DMIC
),
6219 SND_PCI_QUIRK(0x1025, 0x0349, "Acer AOD260", ALC269_FIXUP_INV_DMIC
),
6220 SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_MIC2_MUTE_LED
),
6221 SND_PCI_QUIRK(0x1043, 0x1427, "Asus Zenbook UX31E", ALC269VB_FIXUP_DMIC
),
6222 SND_PCI_QUIRK(0x1043, 0x1517, "Asus Zenbook UX31A", ALC269VB_FIXUP_DMIC
),
6223 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW
),
6224 SND_PCI_QUIRK(0x1043, 0x1b13, "Asus U41SV", ALC269_FIXUP_INV_DMIC
),
6225 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC
),
6226 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC
),
6227 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC
),
6228 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC
),
6229 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC
),
6230 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2
),
6231 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ
),
6232 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ
),
6233 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO
),
6234 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z
),
6235 SND_PCI_QUIRK(0x1025, 0x0742, "Acer AO756", ALC271_FIXUP_HP_GATE_MIC_JACK
),
6236 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC
),
6237 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK
),
6238 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE
),
6239 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE
),
6240 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE
),
6241 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE
),
6242 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE
),
6243 SND_PCI_QUIRK(0x17aa, 0x21f6, "Thinkpad T530", ALC269_FIXUP_LENOVO_DOCK
),
6244 SND_PCI_QUIRK(0x17aa, 0x21fa, "Thinkpad X230", ALC269_FIXUP_LENOVO_DOCK
),
6245 SND_PCI_QUIRK(0x17aa, 0x21f3, "Thinkpad T430", ALC269_FIXUP_LENOVO_DOCK
),
6246 SND_PCI_QUIRK(0x17aa, 0x21fb, "Thinkpad T430s", ALC269_FIXUP_LENOVO_DOCK
),
6247 SND_PCI_QUIRK(0x17aa, 0x2203, "Thinkpad X230 Tablet", ALC269_FIXUP_LENOVO_DOCK
),
6248 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_PCM_44K
),
6249 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD
),
6252 /* Below is a quirk table taken from the old code.
6253 * Basically the device should work as is without the fixup table.
6254 * If BIOS doesn't give a proper info, enable the corresponding
6257 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
6259 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC
),
6260 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC
),
6261 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC
),
6262 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC
),
6263 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC
),
6264 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC
),
6265 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC
),
6266 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC
),
6267 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC
),
6268 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC
),
6269 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC
),
6270 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC
),
6271 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC
),
6272 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC
),
6273 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC
),
6274 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC
),
6275 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC
),
6276 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC
),
6277 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC
),
6278 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC
),
6279 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC
),
6280 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC
),
6281 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC
),
6282 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC
),
6283 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC
),
6284 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC
),
6285 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC
),
6286 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC
),
6287 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC
),
6288 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC
),
6289 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC
),
6290 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC
),
6291 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC
),
6292 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC
),
6293 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC
),
6294 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC
),
6295 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC
),
6296 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC
),
6297 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC
),
6302 static const struct alc_model_fixup alc269_fixup_models
[] = {
6303 {.id
= ALC269_FIXUP_AMIC
, .name
= "laptop-amic"},
6304 {.id
= ALC269_FIXUP_DMIC
, .name
= "laptop-dmic"},
6305 {.id
= ALC269_FIXUP_STEREO_DMIC
, .name
= "alc269-dmic"},
6306 {.id
= ALC271_FIXUP_DMIC
, .name
= "alc271-dmic"},
6307 {.id
= ALC269_FIXUP_INV_DMIC
, .name
= "inv-dmic"},
6308 {.id
= ALC269_FIXUP_LENOVO_DOCK
, .name
= "lenovo-dock"},
6313 static void alc269_fill_coef(struct hda_codec
*codec
)
6315 struct alc_spec
*spec
= codec
->spec
;
6318 if (spec
->codec_variant
!= ALC269_TYPE_ALC269VB
)
6321 if ((alc_get_coef0(codec
) & 0x00ff) < 0x015) {
6322 alc_write_coef_idx(codec
, 0xf, 0x960b);
6323 alc_write_coef_idx(codec
, 0xe, 0x8817);
6326 if ((alc_get_coef0(codec
) & 0x00ff) == 0x016) {
6327 alc_write_coef_idx(codec
, 0xf, 0x960b);
6328 alc_write_coef_idx(codec
, 0xe, 0x8814);
6331 if ((alc_get_coef0(codec
) & 0x00ff) == 0x017) {
6332 val
= alc_read_coef_idx(codec
, 0x04);
6333 /* Power up output pin */
6334 alc_write_coef_idx(codec
, 0x04, val
| (1<<11));
6337 if ((alc_get_coef0(codec
) & 0x00ff) == 0x018) {
6338 val
= alc_read_coef_idx(codec
, 0xd);
6339 if ((val
& 0x0c00) >> 10 != 0x1) {
6340 /* Capless ramp up clock control */
6341 alc_write_coef_idx(codec
, 0xd, val
| (1<<10));
6343 val
= alc_read_coef_idx(codec
, 0x17);
6344 if ((val
& 0x01c0) >> 6 != 0x4) {
6345 /* Class D power on reset */
6346 alc_write_coef_idx(codec
, 0x17, val
| (1<<7));
6350 val
= alc_read_coef_idx(codec
, 0xd); /* Class D */
6351 alc_write_coef_idx(codec
, 0xd, val
| (1<<14));
6353 val
= alc_read_coef_idx(codec
, 0x4); /* HP */
6354 alc_write_coef_idx(codec
, 0x4, val
| (1<<11));
6359 static int patch_alc269(struct hda_codec
*codec
)
6361 struct alc_spec
*spec
;
6364 err
= alc_alloc_spec(codec
, 0x0b);
6370 alc_pick_fixup(codec
, alc269_fixup_models
,
6371 alc269_fixup_tbl
, alc269_fixups
);
6372 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
6374 alc_auto_parse_customize_define(codec
);
6376 if (codec
->vendor_id
== 0x10ec0269) {
6377 spec
->codec_variant
= ALC269_TYPE_ALC269VA
;
6378 switch (alc_get_coef0(codec
) & 0x00f0) {
6380 if (codec
->bus
->pci
->subsystem_vendor
== 0x1025 &&
6381 spec
->cdefine
.platform_type
== 1)
6382 err
= alc_codec_rename(codec
, "ALC271X");
6383 spec
->codec_variant
= ALC269_TYPE_ALC269VB
;
6386 if (codec
->bus
->pci
->subsystem_vendor
== 0x17aa &&
6387 codec
->bus
->pci
->subsystem_device
== 0x21f3)
6388 err
= alc_codec_rename(codec
, "ALC3202");
6389 spec
->codec_variant
= ALC269_TYPE_ALC269VC
;
6392 spec
->codec_variant
= ALC269_TYPE_ALC269VD
;
6395 alc_fix_pll_init(codec
, 0x20, 0x04, 15);
6399 spec
->init_hook
= alc269_fill_coef
;
6400 alc269_fill_coef(codec
);
6403 /* automatic parse from the BIOS config */
6404 err
= alc269_parse_auto_config(codec
);
6408 if (!spec
->no_analog
&& has_cdefine_beep(codec
)) {
6409 err
= snd_hda_attach_beep_device(codec
, 0x1);
6412 set_beep_amp(spec
, 0x0b, 0x04, HDA_INPUT
);
6415 codec
->patch_ops
= alc_patch_ops
;
6417 codec
->patch_ops
.resume
= alc269_resume
;
6419 spec
->shutup
= alc269_shutup
;
6421 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
6434 static int alc861_parse_auto_config(struct hda_codec
*codec
)
6436 static const hda_nid_t alc861_ignore
[] = { 0x1d, 0 };
6437 static const hda_nid_t alc861_ssids
[] = { 0x0e, 0x0f, 0x0b, 0 };
6438 return alc_parse_auto_config(codec
, alc861_ignore
, alc861_ssids
);
6441 /* Pin config fixes */
6443 ALC861_FIXUP_FSC_AMILO_PI1505
,
6444 ALC861_FIXUP_AMP_VREF_0F
,
6445 ALC861_FIXUP_NO_JACK_DETECT
,
6446 ALC861_FIXUP_ASUS_A6RP
,
6449 /* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
6450 static void alc861_fixup_asus_amp_vref_0f(struct hda_codec
*codec
,
6451 const struct alc_fixup
*fix
, int action
)
6453 struct alc_spec
*spec
= codec
->spec
;
6456 if (action
!= ALC_FIXUP_ACT_INIT
)
6458 val
= snd_hda_codec_read(codec
, 0x0f, 0,
6459 AC_VERB_GET_PIN_WIDGET_CONTROL
, 0);
6460 if (!(val
& (AC_PINCTL_IN_EN
| AC_PINCTL_OUT_EN
)))
6461 val
|= AC_PINCTL_IN_EN
;
6462 val
|= AC_PINCTL_VREF_50
;
6463 snd_hda_set_pin_ctl(codec
, 0x0f, val
);
6464 spec
->keep_vref_in_automute
= 1;
6467 /* suppress the jack-detection */
6468 static void alc_fixup_no_jack_detect(struct hda_codec
*codec
,
6469 const struct alc_fixup
*fix
, int action
)
6471 if (action
== ALC_FIXUP_ACT_PRE_PROBE
)
6472 codec
->no_jack_detect
= 1;
6475 static const struct alc_fixup alc861_fixups
[] = {
6476 [ALC861_FIXUP_FSC_AMILO_PI1505
] = {
6477 .type
= ALC_FIXUP_PINS
,
6478 .v
.pins
= (const struct alc_pincfg
[]) {
6479 { 0x0b, 0x0221101f }, /* HP */
6480 { 0x0f, 0x90170310 }, /* speaker */
6484 [ALC861_FIXUP_AMP_VREF_0F
] = {
6485 .type
= ALC_FIXUP_FUNC
,
6486 .v
.func
= alc861_fixup_asus_amp_vref_0f
,
6488 [ALC861_FIXUP_NO_JACK_DETECT
] = {
6489 .type
= ALC_FIXUP_FUNC
,
6490 .v
.func
= alc_fixup_no_jack_detect
,
6492 [ALC861_FIXUP_ASUS_A6RP
] = {
6493 .type
= ALC_FIXUP_FUNC
,
6494 .v
.func
= alc861_fixup_asus_amp_vref_0f
,
6496 .chain_id
= ALC861_FIXUP_NO_JACK_DETECT
,
6500 static const struct snd_pci_quirk alc861_fixup_tbl
[] = {
6501 SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP
),
6502 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", ALC861_FIXUP_AMP_VREF_0F
),
6503 SND_PCI_QUIRK(0x1462, 0x7254, "HP DX2200", ALC861_FIXUP_NO_JACK_DETECT
),
6504 SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", ALC861_FIXUP_AMP_VREF_0F
),
6505 SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", ALC861_FIXUP_AMP_VREF_0F
),
6506 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", ALC861_FIXUP_FSC_AMILO_PI1505
),
6512 static int patch_alc861(struct hda_codec
*codec
)
6514 struct alc_spec
*spec
;
6517 err
= alc_alloc_spec(codec
, 0x15);
6523 alc_pick_fixup(codec
, NULL
, alc861_fixup_tbl
, alc861_fixups
);
6524 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
6526 /* automatic parse from the BIOS config */
6527 err
= alc861_parse_auto_config(codec
);
6531 if (!spec
->no_analog
) {
6532 err
= snd_hda_attach_beep_device(codec
, 0x23);
6535 set_beep_amp(spec
, 0x23, 0, HDA_OUTPUT
);
6538 codec
->patch_ops
= alc_patch_ops
;
6540 spec
->power_hook
= alc_power_eapd
;
6543 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
6557 * In addition, an independent DAC
6559 static int alc861vd_parse_auto_config(struct hda_codec
*codec
)
6561 static const hda_nid_t alc861vd_ignore
[] = { 0x1d, 0 };
6562 static const hda_nid_t alc861vd_ssids
[] = { 0x15, 0x1b, 0x14, 0 };
6563 return alc_parse_auto_config(codec
, alc861vd_ignore
, alc861vd_ssids
);
6567 ALC660VD_FIX_ASUS_GPIO1
,
6568 ALC861VD_FIX_DALLAS
,
6571 /* exclude VREF80 */
6572 static void alc861vd_fixup_dallas(struct hda_codec
*codec
,
6573 const struct alc_fixup
*fix
, int action
)
6575 if (action
== ALC_FIXUP_ACT_PRE_PROBE
) {
6576 snd_hda_override_pin_caps(codec
, 0x18, 0x00001714);
6577 snd_hda_override_pin_caps(codec
, 0x19, 0x0000171c);
6581 static const struct alc_fixup alc861vd_fixups
[] = {
6582 [ALC660VD_FIX_ASUS_GPIO1
] = {
6583 .type
= ALC_FIXUP_VERBS
,
6584 .v
.verbs
= (const struct hda_verb
[]) {
6586 {0x01, AC_VERB_SET_GPIO_MASK
, 0x03},
6587 {0x01, AC_VERB_SET_GPIO_DIRECTION
, 0x01},
6588 {0x01, AC_VERB_SET_GPIO_DATA
, 0x01},
6592 [ALC861VD_FIX_DALLAS
] = {
6593 .type
= ALC_FIXUP_FUNC
,
6594 .v
.func
= alc861vd_fixup_dallas
,
6598 static const struct snd_pci_quirk alc861vd_fixup_tbl
[] = {
6599 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS
),
6600 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1
),
6601 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS
),
6607 static int patch_alc861vd(struct hda_codec
*codec
)
6609 struct alc_spec
*spec
;
6612 err
= alc_alloc_spec(codec
, 0x0b);
6618 alc_pick_fixup(codec
, NULL
, alc861vd_fixup_tbl
, alc861vd_fixups
);
6619 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
6621 /* automatic parse from the BIOS config */
6622 err
= alc861vd_parse_auto_config(codec
);
6626 if (!spec
->no_analog
) {
6627 err
= snd_hda_attach_beep_device(codec
, 0x23);
6630 set_beep_amp(spec
, 0x0b, 0x05, HDA_INPUT
);
6633 codec
->patch_ops
= alc_patch_ops
;
6635 spec
->shutup
= alc_eapd_shutup
;
6637 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
6649 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
6650 * configuration. Each pin widget can choose any input DACs and a mixer.
6651 * Each ADC is connected from a mixer of all inputs. This makes possible
6652 * 6-channel independent captures.
6654 * In addition, an independent DAC for the multi-playback (not used in this
6659 * BIOS auto configuration
6662 static int alc662_parse_auto_config(struct hda_codec
*codec
)
6664 static const hda_nid_t alc662_ignore
[] = { 0x1d, 0 };
6665 static const hda_nid_t alc663_ssids
[] = { 0x15, 0x1b, 0x14, 0x21 };
6666 static const hda_nid_t alc662_ssids
[] = { 0x15, 0x1b, 0x14, 0 };
6667 const hda_nid_t
*ssids
;
6669 if (codec
->vendor_id
== 0x10ec0272 || codec
->vendor_id
== 0x10ec0663 ||
6670 codec
->vendor_id
== 0x10ec0665 || codec
->vendor_id
== 0x10ec0670)
6671 ssids
= alc663_ssids
;
6673 ssids
= alc662_ssids
;
6674 return alc_parse_auto_config(codec
, alc662_ignore
, ssids
);
6677 static void alc272_fixup_mario(struct hda_codec
*codec
,
6678 const struct alc_fixup
*fix
, int action
)
6680 if (action
!= ALC_FIXUP_ACT_PROBE
)
6682 if (snd_hda_override_amp_caps(codec
, 0x2, HDA_OUTPUT
,
6683 (0x3b << AC_AMPCAP_OFFSET_SHIFT
) |
6684 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT
) |
6685 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT
) |
6686 (0 << AC_AMPCAP_MUTE_SHIFT
)))
6688 "hda_codec: failed to override amp caps for NID 0x2\n");
6692 ALC662_FIXUP_ASPIRE
,
6693 ALC662_FIXUP_IDEAPAD
,
6695 ALC662_FIXUP_CZC_P10T
,
6696 ALC662_FIXUP_SKU_IGNORE
,
6697 ALC662_FIXUP_HP_RP5800
,
6698 ALC662_FIXUP_ASUS_MODE1
,
6699 ALC662_FIXUP_ASUS_MODE2
,
6700 ALC662_FIXUP_ASUS_MODE3
,
6701 ALC662_FIXUP_ASUS_MODE4
,
6702 ALC662_FIXUP_ASUS_MODE5
,
6703 ALC662_FIXUP_ASUS_MODE6
,
6704 ALC662_FIXUP_ASUS_MODE7
,
6705 ALC662_FIXUP_ASUS_MODE8
,
6706 ALC662_FIXUP_NO_JACK_DETECT
,
6707 ALC662_FIXUP_ZOTAC_Z68
,
6708 ALC662_FIXUP_INV_DMIC
,
6711 static const struct alc_fixup alc662_fixups
[] = {
6712 [ALC662_FIXUP_ASPIRE
] = {
6713 .type
= ALC_FIXUP_PINS
,
6714 .v
.pins
= (const struct alc_pincfg
[]) {
6715 { 0x15, 0x99130112 }, /* subwoofer */
6719 [ALC662_FIXUP_IDEAPAD
] = {
6720 .type
= ALC_FIXUP_PINS
,
6721 .v
.pins
= (const struct alc_pincfg
[]) {
6722 { 0x17, 0x99130112 }, /* subwoofer */
6726 [ALC272_FIXUP_MARIO
] = {
6727 .type
= ALC_FIXUP_FUNC
,
6728 .v
.func
= alc272_fixup_mario
,
6730 [ALC662_FIXUP_CZC_P10T
] = {
6731 .type
= ALC_FIXUP_VERBS
,
6732 .v
.verbs
= (const struct hda_verb
[]) {
6733 {0x14, AC_VERB_SET_EAPD_BTLENABLE
, 0},
6737 [ALC662_FIXUP_SKU_IGNORE
] = {
6738 .type
= ALC_FIXUP_FUNC
,
6739 .v
.func
= alc_fixup_sku_ignore
,
6741 [ALC662_FIXUP_HP_RP5800
] = {
6742 .type
= ALC_FIXUP_PINS
,
6743 .v
.pins
= (const struct alc_pincfg
[]) {
6744 { 0x14, 0x0221201f }, /* HP out */
6748 .chain_id
= ALC662_FIXUP_SKU_IGNORE
6750 [ALC662_FIXUP_ASUS_MODE1
] = {
6751 .type
= ALC_FIXUP_PINS
,
6752 .v
.pins
= (const struct alc_pincfg
[]) {
6753 { 0x14, 0x99130110 }, /* speaker */
6754 { 0x18, 0x01a19c20 }, /* mic */
6755 { 0x19, 0x99a3092f }, /* int-mic */
6756 { 0x21, 0x0121401f }, /* HP out */
6760 .chain_id
= ALC662_FIXUP_SKU_IGNORE
6762 [ALC662_FIXUP_ASUS_MODE2
] = {
6763 .type
= ALC_FIXUP_PINS
,
6764 .v
.pins
= (const struct alc_pincfg
[]) {
6765 { 0x14, 0x99130110 }, /* speaker */
6766 { 0x18, 0x01a19820 }, /* mic */
6767 { 0x19, 0x99a3092f }, /* int-mic */
6768 { 0x1b, 0x0121401f }, /* HP out */
6772 .chain_id
= ALC662_FIXUP_SKU_IGNORE
6774 [ALC662_FIXUP_ASUS_MODE3
] = {
6775 .type
= ALC_FIXUP_PINS
,
6776 .v
.pins
= (const struct alc_pincfg
[]) {
6777 { 0x14, 0x99130110 }, /* speaker */
6778 { 0x15, 0x0121441f }, /* HP */
6779 { 0x18, 0x01a19840 }, /* mic */
6780 { 0x19, 0x99a3094f }, /* int-mic */
6781 { 0x21, 0x01211420 }, /* HP2 */
6785 .chain_id
= ALC662_FIXUP_SKU_IGNORE
6787 [ALC662_FIXUP_ASUS_MODE4
] = {
6788 .type
= ALC_FIXUP_PINS
,
6789 .v
.pins
= (const struct alc_pincfg
[]) {
6790 { 0x14, 0x99130110 }, /* speaker */
6791 { 0x16, 0x99130111 }, /* speaker */
6792 { 0x18, 0x01a19840 }, /* mic */
6793 { 0x19, 0x99a3094f }, /* int-mic */
6794 { 0x21, 0x0121441f }, /* HP */
6798 .chain_id
= ALC662_FIXUP_SKU_IGNORE
6800 [ALC662_FIXUP_ASUS_MODE5
] = {
6801 .type
= ALC_FIXUP_PINS
,
6802 .v
.pins
= (const struct alc_pincfg
[]) {
6803 { 0x14, 0x99130110 }, /* speaker */
6804 { 0x15, 0x0121441f }, /* HP */
6805 { 0x16, 0x99130111 }, /* speaker */
6806 { 0x18, 0x01a19840 }, /* mic */
6807 { 0x19, 0x99a3094f }, /* int-mic */
6811 .chain_id
= ALC662_FIXUP_SKU_IGNORE
6813 [ALC662_FIXUP_ASUS_MODE6
] = {
6814 .type
= ALC_FIXUP_PINS
,
6815 .v
.pins
= (const struct alc_pincfg
[]) {
6816 { 0x14, 0x99130110 }, /* speaker */
6817 { 0x15, 0x01211420 }, /* HP2 */
6818 { 0x18, 0x01a19840 }, /* mic */
6819 { 0x19, 0x99a3094f }, /* int-mic */
6820 { 0x1b, 0x0121441f }, /* HP */
6824 .chain_id
= ALC662_FIXUP_SKU_IGNORE
6826 [ALC662_FIXUP_ASUS_MODE7
] = {
6827 .type
= ALC_FIXUP_PINS
,
6828 .v
.pins
= (const struct alc_pincfg
[]) {
6829 { 0x14, 0x99130110 }, /* speaker */
6830 { 0x17, 0x99130111 }, /* speaker */
6831 { 0x18, 0x01a19840 }, /* mic */
6832 { 0x19, 0x99a3094f }, /* int-mic */
6833 { 0x1b, 0x01214020 }, /* HP */
6834 { 0x21, 0x0121401f }, /* HP */
6838 .chain_id
= ALC662_FIXUP_SKU_IGNORE
6840 [ALC662_FIXUP_ASUS_MODE8
] = {
6841 .type
= ALC_FIXUP_PINS
,
6842 .v
.pins
= (const struct alc_pincfg
[]) {
6843 { 0x14, 0x99130110 }, /* speaker */
6844 { 0x12, 0x99a30970 }, /* int-mic */
6845 { 0x15, 0x01214020 }, /* HP */
6846 { 0x17, 0x99130111 }, /* speaker */
6847 { 0x18, 0x01a19840 }, /* mic */
6848 { 0x21, 0x0121401f }, /* HP */
6852 .chain_id
= ALC662_FIXUP_SKU_IGNORE
6854 [ALC662_FIXUP_NO_JACK_DETECT
] = {
6855 .type
= ALC_FIXUP_FUNC
,
6856 .v
.func
= alc_fixup_no_jack_detect
,
6858 [ALC662_FIXUP_ZOTAC_Z68
] = {
6859 .type
= ALC_FIXUP_PINS
,
6860 .v
.pins
= (const struct alc_pincfg
[]) {
6861 { 0x1b, 0x02214020 }, /* Front HP */
6865 [ALC662_FIXUP_INV_DMIC
] = {
6866 .type
= ALC_FIXUP_FUNC
,
6867 .v
.func
= alc_fixup_inv_dmic_0x12
,
6871 static const struct snd_pci_quirk alc662_fixup_tbl
[] = {
6872 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2
),
6873 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE
),
6874 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE
),
6875 SND_PCI_QUIRK(0x1025, 0x0349, "eMachines eM250", ALC662_FIXUP_INV_DMIC
),
6876 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE
),
6877 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800
),
6878 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT
),
6879 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2
),
6880 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD
),
6881 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD
),
6882 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD
),
6883 SND_PCI_QUIRK(0x19da, 0xa130, "Zotac Z68", ALC662_FIXUP_ZOTAC_Z68
),
6884 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T
),
6887 /* Below is a quirk table taken from the old code.
6888 * Basically the device should work as is without the fixup table.
6889 * If BIOS doesn't give a proper info, enable the corresponding
6892 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1
),
6893 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3
),
6894 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1
),
6895 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3
),
6896 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1
),
6897 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2
),
6898 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1
),
6899 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1
),
6900 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1
),
6901 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2
),
6902 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7
),
6903 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7
),
6904 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8
),
6905 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3
),
6906 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1
),
6907 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2
),
6908 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2
),
6909 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1
),
6910 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2
),
6911 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6
),
6912 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6
),
6913 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2
),
6914 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1
),
6915 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3
),
6916 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2
),
6917 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2
),
6918 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5
),
6919 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6
),
6920 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2
),
6921 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1
),
6922 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2
),
6923 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2
),
6924 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3
),
6925 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3
),
6926 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1
),
6927 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1
),
6928 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1
),
6929 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1
),
6930 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1
),
6931 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2
),
6932 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2
),
6933 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1
),
6934 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1
),
6935 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3
),
6936 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1
),
6937 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1
),
6938 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1
),
6939 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2
),
6940 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1
),
6941 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4
),
6946 static const struct alc_model_fixup alc662_fixup_models
[] = {
6947 {.id
= ALC272_FIXUP_MARIO
, .name
= "mario"},
6948 {.id
= ALC662_FIXUP_ASUS_MODE1
, .name
= "asus-mode1"},
6949 {.id
= ALC662_FIXUP_ASUS_MODE2
, .name
= "asus-mode2"},
6950 {.id
= ALC662_FIXUP_ASUS_MODE3
, .name
= "asus-mode3"},
6951 {.id
= ALC662_FIXUP_ASUS_MODE4
, .name
= "asus-mode4"},
6952 {.id
= ALC662_FIXUP_ASUS_MODE5
, .name
= "asus-mode5"},
6953 {.id
= ALC662_FIXUP_ASUS_MODE6
, .name
= "asus-mode6"},
6954 {.id
= ALC662_FIXUP_ASUS_MODE7
, .name
= "asus-mode7"},
6955 {.id
= ALC662_FIXUP_ASUS_MODE8
, .name
= "asus-mode8"},
6956 {.id
= ALC662_FIXUP_INV_DMIC
, .name
= "inv-dmic"},
6960 static void alc662_fill_coef(struct hda_codec
*codec
)
6964 coef
= alc_get_coef0(codec
);
6966 switch (codec
->vendor_id
) {
6968 if ((coef
& 0x00f0) == 0x0030) {
6969 val
= alc_read_coef_idx(codec
, 0x4); /* EAPD Ctrl */
6970 alc_write_coef_idx(codec
, 0x4, val
& ~(1<<10));
6980 val
= alc_read_coef_idx(codec
, 0xd); /* EAPD Ctrl */
6981 alc_write_coef_idx(codec
, 0xd, val
| (1<<14));
6988 static int patch_alc662(struct hda_codec
*codec
)
6990 struct alc_spec
*spec
;
6993 err
= alc_alloc_spec(codec
, 0x0b);
6999 /* handle multiple HPs as is */
7000 spec
->parse_flags
= HDA_PINCFG_NO_HP_FIXUP
;
7002 alc_fix_pll_init(codec
, 0x20, 0x04, 15);
7004 spec
->init_hook
= alc662_fill_coef
;
7005 alc662_fill_coef(codec
);
7007 alc_pick_fixup(codec
, alc662_fixup_models
,
7008 alc662_fixup_tbl
, alc662_fixups
);
7009 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
7011 alc_auto_parse_customize_define(codec
);
7013 if ((alc_get_coef0(codec
) & (1 << 14)) &&
7014 codec
->bus
->pci
->subsystem_vendor
== 0x1025 &&
7015 spec
->cdefine
.platform_type
== 1) {
7016 if (alc_codec_rename(codec
, "ALC272X") < 0)
7020 /* automatic parse from the BIOS config */
7021 err
= alc662_parse_auto_config(codec
);
7025 if (!spec
->no_analog
&& has_cdefine_beep(codec
)) {
7026 err
= snd_hda_attach_beep_device(codec
, 0x1);
7029 switch (codec
->vendor_id
) {
7031 set_beep_amp(spec
, 0x0b, 0x05, HDA_INPUT
);
7036 set_beep_amp(spec
, 0x0b, 0x04, HDA_INPUT
);
7039 set_beep_amp(spec
, 0x0b, 0x03, HDA_INPUT
);
7044 codec
->patch_ops
= alc_patch_ops
;
7045 spec
->shutup
= alc_eapd_shutup
;
7047 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
7060 static int alc680_parse_auto_config(struct hda_codec
*codec
)
7062 return alc_parse_auto_config(codec
, NULL
, NULL
);
7067 static int patch_alc680(struct hda_codec
*codec
)
7071 /* ALC680 has no aa-loopback mixer */
7072 err
= alc_alloc_spec(codec
, 0);
7076 /* automatic parse from the BIOS config */
7077 err
= alc680_parse_auto_config(codec
);
7083 codec
->patch_ops
= alc_patch_ops
;
7091 static const struct hda_codec_preset snd_hda_preset_realtek
[] = {
7092 { .id
= 0x10ec0221, .name
= "ALC221", .patch
= patch_alc269
},
7093 { .id
= 0x10ec0260, .name
= "ALC260", .patch
= patch_alc260
},
7094 { .id
= 0x10ec0262, .name
= "ALC262", .patch
= patch_alc262
},
7095 { .id
= 0x10ec0267, .name
= "ALC267", .patch
= patch_alc268
},
7096 { .id
= 0x10ec0268, .name
= "ALC268", .patch
= patch_alc268
},
7097 { .id
= 0x10ec0269, .name
= "ALC269", .patch
= patch_alc269
},
7098 { .id
= 0x10ec0270, .name
= "ALC270", .patch
= patch_alc269
},
7099 { .id
= 0x10ec0272, .name
= "ALC272", .patch
= patch_alc662
},
7100 { .id
= 0x10ec0275, .name
= "ALC275", .patch
= patch_alc269
},
7101 { .id
= 0x10ec0276, .name
= "ALC276", .patch
= patch_alc269
},
7102 { .id
= 0x10ec0280, .name
= "ALC280", .patch
= patch_alc269
},
7103 { .id
= 0x10ec0282, .name
= "ALC282", .patch
= patch_alc269
},
7104 { .id
= 0x10ec0283, .name
= "ALC283", .patch
= patch_alc269
},
7105 { .id
= 0x10ec0290, .name
= "ALC290", .patch
= patch_alc269
},
7106 { .id
= 0x10ec0292, .name
= "ALC292", .patch
= patch_alc269
},
7107 { .id
= 0x10ec0861, .rev
= 0x100340, .name
= "ALC660",
7108 .patch
= patch_alc861
},
7109 { .id
= 0x10ec0660, .name
= "ALC660-VD", .patch
= patch_alc861vd
},
7110 { .id
= 0x10ec0861, .name
= "ALC861", .patch
= patch_alc861
},
7111 { .id
= 0x10ec0862, .name
= "ALC861-VD", .patch
= patch_alc861vd
},
7112 { .id
= 0x10ec0662, .rev
= 0x100002, .name
= "ALC662 rev2",
7113 .patch
= patch_alc882
},
7114 { .id
= 0x10ec0662, .rev
= 0x100101, .name
= "ALC662 rev1",
7115 .patch
= patch_alc662
},
7116 { .id
= 0x10ec0662, .rev
= 0x100300, .name
= "ALC662 rev3",
7117 .patch
= patch_alc662
},
7118 { .id
= 0x10ec0663, .name
= "ALC663", .patch
= patch_alc662
},
7119 { .id
= 0x10ec0665, .name
= "ALC665", .patch
= patch_alc662
},
7120 { .id
= 0x10ec0668, .name
= "ALC668", .patch
= patch_alc662
},
7121 { .id
= 0x10ec0670, .name
= "ALC670", .patch
= patch_alc662
},
7122 { .id
= 0x10ec0680, .name
= "ALC680", .patch
= patch_alc680
},
7123 { .id
= 0x10ec0880, .name
= "ALC880", .patch
= patch_alc880
},
7124 { .id
= 0x10ec0882, .name
= "ALC882", .patch
= patch_alc882
},
7125 { .id
= 0x10ec0883, .name
= "ALC883", .patch
= patch_alc882
},
7126 { .id
= 0x10ec0885, .rev
= 0x100101, .name
= "ALC889A",
7127 .patch
= patch_alc882
},
7128 { .id
= 0x10ec0885, .rev
= 0x100103, .name
= "ALC889A",
7129 .patch
= patch_alc882
},
7130 { .id
= 0x10ec0885, .name
= "ALC885", .patch
= patch_alc882
},
7131 { .id
= 0x10ec0887, .name
= "ALC887", .patch
= patch_alc882
},
7132 { .id
= 0x10ec0888, .rev
= 0x100101, .name
= "ALC1200",
7133 .patch
= patch_alc882
},
7134 { .id
= 0x10ec0888, .name
= "ALC888", .patch
= patch_alc882
},
7135 { .id
= 0x10ec0889, .name
= "ALC889", .patch
= patch_alc882
},
7136 { .id
= 0x10ec0892, .name
= "ALC892", .patch
= patch_alc662
},
7137 { .id
= 0x10ec0899, .name
= "ALC898", .patch
= patch_alc882
},
7138 { .id
= 0x10ec0900, .name
= "ALC1150", .patch
= patch_alc882
},
7142 MODULE_ALIAS("snd-hda-codec-id:10ec*");
7144 MODULE_LICENSE("GPL");
7145 MODULE_DESCRIPTION("Realtek HD-audio codec");
7147 static struct hda_codec_preset_list realtek_list
= {
7148 .preset
= snd_hda_preset_realtek
,
7149 .owner
= THIS_MODULE
,
7152 static int __init
patch_realtek_init(void)
7154 return snd_hda_add_codec_preset(&realtek_list
);
7157 static void __exit
patch_realtek_exit(void)
7159 snd_hda_delete_codec_preset(&realtek_list
);
7162 module_init(patch_realtek_init
)
7163 module_exit(patch_realtek_exit
)