2 * Universal Interface for Intel High Definition Audio Codec
4 * HD audio interface patch for Realtek ALC codecs
6 * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
7 * PeiSen Hou <pshou@realtek.com.tw>
8 * Takashi Iwai <tiwai@suse.de>
9 * Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
11 * This driver is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This driver is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include <linux/init.h>
27 #include <linux/delay.h>
28 #include <linux/slab.h>
29 #include <linux/pci.h>
30 #include <linux/module.h>
31 #include <sound/core.h>
32 #include <sound/jack.h>
33 #include "hda_codec.h"
34 #include "hda_local.h"
38 /* unsol event tags */
39 #define ALC_FRONT_EVENT 0x01
40 #define ALC_DCVOL_EVENT 0x02
41 #define ALC_HP_EVENT 0x04
42 #define ALC_MIC_EVENT 0x08
45 #define GPIO_MASK 0x03
47 /* extra amp-initialization sequence types */
56 struct alc_customize_define
{
58 unsigned char port_connectivity
;
59 unsigned char check_sum
;
60 unsigned char customization
;
61 unsigned char external_amp
;
62 unsigned int enable_pcbeep
:1;
63 unsigned int platform_type
:1;
65 unsigned int override
:1;
66 unsigned int fixup
:1; /* Means that this sku is set by driver, not read from hw */
72 hda_nid_t pin
; /* multi-io widget pin NID */
73 hda_nid_t dac
; /* DAC to be connected */
74 unsigned int ctl_in
; /* cached input-pin control value */
78 ALC_AUTOMUTE_PIN
, /* change the pin control */
79 ALC_AUTOMUTE_AMP
, /* mute/unmute the pin AMP */
80 ALC_AUTOMUTE_MIXER
, /* mute/unmute mixer widget AMP */
83 #define MAX_VOL_NIDS 0x40
86 /* codec parameterization */
87 const struct snd_kcontrol_new
*mixers
[5]; /* mixer arrays */
88 unsigned int num_mixers
;
89 const struct snd_kcontrol_new
*cap_mixer
; /* capture mixer */
90 unsigned int beep_amp
; /* beep amp value, set via set_beep_amp() */
92 const struct hda_verb
*init_verbs
[10]; /* initialization verbs
96 unsigned int num_init_verbs
;
98 char stream_name_analog
[32]; /* analog PCM stream */
99 const struct hda_pcm_stream
*stream_analog_playback
;
100 const struct hda_pcm_stream
*stream_analog_capture
;
101 const struct hda_pcm_stream
*stream_analog_alt_playback
;
102 const struct hda_pcm_stream
*stream_analog_alt_capture
;
104 char stream_name_digital
[32]; /* digital PCM stream */
105 const struct hda_pcm_stream
*stream_digital_playback
;
106 const struct hda_pcm_stream
*stream_digital_capture
;
109 struct hda_multi_out multiout
; /* playback set-up
110 * max_channels, dacs must be set
111 * dig_out_nid and hp_nid are optional
113 hda_nid_t alt_dac_nid
;
114 hda_nid_t slave_dig_outs
[3]; /* optional - for auto-parsing */
118 unsigned int num_adc_nids
;
119 const hda_nid_t
*adc_nids
;
120 const hda_nid_t
*capsrc_nids
;
121 hda_nid_t dig_in_nid
; /* digital-in NID; optional */
122 hda_nid_t mixer_nid
; /* analog-mixer NID */
123 DECLARE_BITMAP(vol_ctls
, MAX_VOL_NIDS
<< 1);
124 DECLARE_BITMAP(sw_ctls
, MAX_VOL_NIDS
<< 1);
126 /* capture setup for dynamic dual-adc switch */
128 unsigned int cur_adc_stream_tag
;
129 unsigned int cur_adc_format
;
132 unsigned int num_mux_defs
;
133 const struct hda_input_mux
*input_mux
;
134 unsigned int cur_mux
[3];
135 hda_nid_t ext_mic_pin
;
136 hda_nid_t dock_mic_pin
;
137 hda_nid_t int_mic_pin
;
140 const struct hda_channel_mode
*channel_mode
;
141 int num_channel_mode
;
143 int const_channel_count
;
144 int ext_channel_count
;
146 /* PCM information */
147 struct hda_pcm pcm_rec
[3]; /* used in alc_build_pcms() */
149 /* dynamic controls, init_verbs and input_mux */
150 struct auto_pin_cfg autocfg
;
151 struct alc_customize_define cdefine
;
152 struct snd_array kctls
;
153 struct hda_input_mux private_imux
[3];
154 hda_nid_t private_dac_nids
[AUTO_CFG_MAX_OUTS
];
155 hda_nid_t private_adc_nids
[AUTO_CFG_MAX_OUTS
];
156 hda_nid_t private_capsrc_nids
[AUTO_CFG_MAX_OUTS
];
157 hda_nid_t imux_pins
[HDA_MAX_NUM_INPUTS
];
158 unsigned int dyn_adc_idx
[HDA_MAX_NUM_INPUTS
];
159 int int_mic_idx
, ext_mic_idx
, dock_mic_idx
; /* for auto-mic */
162 void (*init_hook
)(struct hda_codec
*codec
);
163 void (*unsol_event
)(struct hda_codec
*codec
, unsigned int res
);
164 #ifdef CONFIG_SND_HDA_POWER_SAVE
165 void (*power_hook
)(struct hda_codec
*codec
);
167 void (*shutup
)(struct hda_codec
*codec
);
168 void (*automute_hook
)(struct hda_codec
*codec
);
170 /* for pin sensing */
171 unsigned int hp_jack_present
:1;
172 unsigned int line_jack_present
:1;
173 unsigned int master_mute
:1;
174 unsigned int auto_mic
:1;
175 unsigned int auto_mic_valid_imux
:1; /* valid imux for auto-mic */
176 unsigned int automute_speaker
:1; /* automute speaker outputs */
177 unsigned int automute_lo
:1; /* automute LO outputs */
178 unsigned int detect_hp
:1; /* Headphone detection enabled */
179 unsigned int detect_lo
:1; /* Line-out detection enabled */
180 unsigned int automute_speaker_possible
:1; /* there are speakers and either LO or HP */
181 unsigned int automute_lo_possible
:1; /* there are line outs and HP */
182 unsigned int keep_vref_in_automute
:1; /* Don't clear VREF in automute */
185 unsigned int no_analog
:1; /* digital I/O only */
186 unsigned int dyn_adc_switch
:1; /* switch ADCs (for ALC275) */
187 unsigned int single_input_src
:1;
188 unsigned int vol_in_capsrc
:1; /* use capsrc volume (ADC has no vol) */
189 unsigned int parse_flags
; /* passed to snd_hda_parse_pin_defcfg() */
190 unsigned int shared_mic_hp
:1; /* HP/Mic-in sharing */
192 /* auto-mute control */
194 hda_nid_t automute_mixer_nid
[AUTO_CFG_MAX_OUTS
];
197 int codec_variant
; /* flag for other variants */
199 /* for virtual master */
200 hda_nid_t vmaster_nid
;
201 #ifdef CONFIG_SND_HDA_POWER_SAVE
202 struct hda_loopback_check loopback
;
207 unsigned int pll_coef_idx
, pll_coef_bit
;
212 const struct alc_fixup
*fixup_list
;
213 const char *fixup_name
;
217 struct alc_multi_io multi_io
[4];
220 struct snd_array bind_ctls
;
223 #define ALC_MODEL_AUTO 0 /* common for all chips */
225 static bool check_amp_caps(struct hda_codec
*codec
, hda_nid_t nid
,
226 int dir
, unsigned int bits
)
230 if (get_wcaps(codec
, nid
) & (1 << (dir
+ 1)))
231 if (query_amp_caps(codec
, nid
, dir
) & bits
)
236 #define nid_has_mute(codec, nid, dir) \
237 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
238 #define nid_has_volume(codec, nid, dir) \
239 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
244 static int alc_mux_enum_info(struct snd_kcontrol
*kcontrol
,
245 struct snd_ctl_elem_info
*uinfo
)
247 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
248 struct alc_spec
*spec
= codec
->spec
;
249 unsigned int mux_idx
= snd_ctl_get_ioffidx(kcontrol
, &uinfo
->id
);
250 if (mux_idx
>= spec
->num_mux_defs
)
252 if (!spec
->input_mux
[mux_idx
].num_items
&& mux_idx
> 0)
254 return snd_hda_input_mux_info(&spec
->input_mux
[mux_idx
], uinfo
);
257 static int alc_mux_enum_get(struct snd_kcontrol
*kcontrol
,
258 struct snd_ctl_elem_value
*ucontrol
)
260 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
261 struct alc_spec
*spec
= codec
->spec
;
262 unsigned int adc_idx
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
264 ucontrol
->value
.enumerated
.item
[0] = spec
->cur_mux
[adc_idx
];
268 static bool alc_dyn_adc_pcm_resetup(struct hda_codec
*codec
, int cur
)
270 struct alc_spec
*spec
= codec
->spec
;
271 hda_nid_t new_adc
= spec
->adc_nids
[spec
->dyn_adc_idx
[cur
]];
273 if (spec
->cur_adc
&& spec
->cur_adc
!= new_adc
) {
274 /* stream is running, let's swap the current ADC */
275 __snd_hda_codec_cleanup_stream(codec
, spec
->cur_adc
, 1);
276 spec
->cur_adc
= new_adc
;
277 snd_hda_codec_setup_stream(codec
, new_adc
,
278 spec
->cur_adc_stream_tag
, 0,
279 spec
->cur_adc_format
);
285 static inline hda_nid_t
get_capsrc(struct alc_spec
*spec
, int idx
)
287 return spec
->capsrc_nids
?
288 spec
->capsrc_nids
[idx
] : spec
->adc_nids
[idx
];
291 static void call_update_outputs(struct hda_codec
*codec
);
293 /* select the given imux item; either unmute exclusively or select the route */
294 static int alc_mux_select(struct hda_codec
*codec
, unsigned int adc_idx
,
295 unsigned int idx
, bool force
)
297 struct alc_spec
*spec
= codec
->spec
;
298 const struct hda_input_mux
*imux
;
299 unsigned int mux_idx
;
300 int i
, type
, num_conns
;
303 mux_idx
= adc_idx
>= spec
->num_mux_defs
? 0 : adc_idx
;
304 imux
= &spec
->input_mux
[mux_idx
];
305 if (!imux
->num_items
&& mux_idx
> 0)
306 imux
= &spec
->input_mux
[0];
307 if (!imux
->num_items
)
310 if (idx
>= imux
->num_items
)
311 idx
= imux
->num_items
- 1;
312 if (spec
->cur_mux
[adc_idx
] == idx
&& !force
)
314 spec
->cur_mux
[adc_idx
] = idx
;
316 /* for shared I/O, change the pin-control accordingly */
317 if (spec
->shared_mic_hp
) {
318 /* NOTE: this assumes that there are only two inputs, the
319 * first is the real internal mic and the second is HP jack.
321 snd_hda_codec_write(codec
, spec
->autocfg
.inputs
[1].pin
, 0,
322 AC_VERB_SET_PIN_WIDGET_CONTROL
,
323 spec
->cur_mux
[adc_idx
] ?
324 PIN_VREF80
: PIN_HP
);
325 spec
->automute_speaker
= !spec
->cur_mux
[adc_idx
];
326 call_update_outputs(codec
);
329 if (spec
->dyn_adc_switch
) {
330 alc_dyn_adc_pcm_resetup(codec
, idx
);
331 adc_idx
= spec
->dyn_adc_idx
[idx
];
334 nid
= get_capsrc(spec
, adc_idx
);
337 num_conns
= snd_hda_get_conn_list(codec
, nid
, NULL
);
341 type
= get_wcaps_type(get_wcaps(codec
, nid
));
342 if (type
== AC_WID_AUD_MIX
) {
343 /* Matrix-mixer style (e.g. ALC882) */
344 int active
= imux
->items
[idx
].index
;
345 for (i
= 0; i
< num_conns
; i
++) {
346 unsigned int v
= (i
== active
) ? 0 : HDA_AMP_MUTE
;
347 snd_hda_codec_amp_stereo(codec
, nid
, HDA_INPUT
, i
,
351 /* MUX style (e.g. ALC880) */
352 snd_hda_codec_write_cache(codec
, nid
, 0,
353 AC_VERB_SET_CONNECT_SEL
,
354 imux
->items
[idx
].index
);
359 static int alc_mux_enum_put(struct snd_kcontrol
*kcontrol
,
360 struct snd_ctl_elem_value
*ucontrol
)
362 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
363 unsigned int adc_idx
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
364 return alc_mux_select(codec
, adc_idx
,
365 ucontrol
->value
.enumerated
.item
[0], false);
369 * set up the input pin config (depending on the given auto-pin type)
371 static void alc_set_input_pin(struct hda_codec
*codec
, hda_nid_t nid
,
374 unsigned int val
= PIN_IN
;
376 if (auto_pin_type
== AUTO_PIN_MIC
) {
379 oldval
= snd_hda_codec_read(codec
, nid
, 0,
380 AC_VERB_GET_PIN_WIDGET_CONTROL
, 0);
381 pincap
= snd_hda_query_pin_caps(codec
, nid
);
382 pincap
= (pincap
& AC_PINCAP_VREF
) >> AC_PINCAP_VREF_SHIFT
;
383 /* if the default pin setup is vref50, we give it priority */
384 if ((pincap
& AC_PINCAP_VREF_80
) && oldval
!= PIN_VREF50
)
386 else if (pincap
& AC_PINCAP_VREF_50
)
388 else if (pincap
& AC_PINCAP_VREF_100
)
390 else if (pincap
& AC_PINCAP_VREF_GRD
)
393 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_PIN_WIDGET_CONTROL
, val
);
397 * Append the given mixer and verb elements for the later use
398 * The mixer array is referred in build_controls(), and init_verbs are
401 static void add_mixer(struct alc_spec
*spec
, const struct snd_kcontrol_new
*mix
)
403 if (snd_BUG_ON(spec
->num_mixers
>= ARRAY_SIZE(spec
->mixers
)))
405 spec
->mixers
[spec
->num_mixers
++] = mix
;
408 static void add_verb(struct alc_spec
*spec
, const struct hda_verb
*verb
)
410 if (snd_BUG_ON(spec
->num_init_verbs
>= ARRAY_SIZE(spec
->init_verbs
)))
412 spec
->init_verbs
[spec
->num_init_verbs
++] = verb
;
416 * GPIO setup tables, used in initialization
418 /* Enable GPIO mask and set output */
419 static const struct hda_verb alc_gpio1_init_verbs
[] = {
420 {0x01, AC_VERB_SET_GPIO_MASK
, 0x01},
421 {0x01, AC_VERB_SET_GPIO_DIRECTION
, 0x01},
422 {0x01, AC_VERB_SET_GPIO_DATA
, 0x01},
426 static const struct hda_verb alc_gpio2_init_verbs
[] = {
427 {0x01, AC_VERB_SET_GPIO_MASK
, 0x02},
428 {0x01, AC_VERB_SET_GPIO_DIRECTION
, 0x02},
429 {0x01, AC_VERB_SET_GPIO_DATA
, 0x02},
433 static const struct hda_verb alc_gpio3_init_verbs
[] = {
434 {0x01, AC_VERB_SET_GPIO_MASK
, 0x03},
435 {0x01, AC_VERB_SET_GPIO_DIRECTION
, 0x03},
436 {0x01, AC_VERB_SET_GPIO_DATA
, 0x03},
441 * Fix hardware PLL issue
442 * On some codecs, the analog PLL gating control must be off while
443 * the default value is 1.
445 static void alc_fix_pll(struct hda_codec
*codec
)
447 struct alc_spec
*spec
= codec
->spec
;
452 snd_hda_codec_write(codec
, spec
->pll_nid
, 0, AC_VERB_SET_COEF_INDEX
,
454 val
= snd_hda_codec_read(codec
, spec
->pll_nid
, 0,
455 AC_VERB_GET_PROC_COEF
, 0);
456 snd_hda_codec_write(codec
, spec
->pll_nid
, 0, AC_VERB_SET_COEF_INDEX
,
458 snd_hda_codec_write(codec
, spec
->pll_nid
, 0, AC_VERB_SET_PROC_COEF
,
459 val
& ~(1 << spec
->pll_coef_bit
));
462 static void alc_fix_pll_init(struct hda_codec
*codec
, hda_nid_t nid
,
463 unsigned int coef_idx
, unsigned int coef_bit
)
465 struct alc_spec
*spec
= codec
->spec
;
467 spec
->pll_coef_idx
= coef_idx
;
468 spec
->pll_coef_bit
= coef_bit
;
473 * Jack detections for HP auto-mute and mic-switch
476 /* check each pin in the given array; returns true if any of them is plugged */
477 static bool detect_jacks(struct hda_codec
*codec
, int num_pins
, hda_nid_t
*pins
)
481 for (i
= 0; i
< num_pins
; i
++) {
482 hda_nid_t nid
= pins
[i
];
485 present
|= snd_hda_jack_detect(codec
, nid
);
490 /* standard HP/line-out auto-mute helper */
491 static void do_automute(struct hda_codec
*codec
, int num_pins
, hda_nid_t
*pins
,
492 bool mute
, bool hp_out
)
494 struct alc_spec
*spec
= codec
->spec
;
495 unsigned int mute_bits
= mute
? HDA_AMP_MUTE
: 0;
496 unsigned int pin_bits
= mute
? 0 : (hp_out
? PIN_HP
: PIN_OUT
);
499 for (i
= 0; i
< num_pins
; i
++) {
500 hda_nid_t nid
= pins
[i
];
504 switch (spec
->automute_mode
) {
505 case ALC_AUTOMUTE_PIN
:
506 /* don't reset VREF value in case it's controlling
507 * the amp (see alc861_fixup_asus_amp_vref_0f())
509 if (spec
->keep_vref_in_automute
) {
510 val
= snd_hda_codec_read(codec
, nid
, 0,
511 AC_VERB_GET_PIN_WIDGET_CONTROL
, 0);
516 snd_hda_codec_write(codec
, nid
, 0,
517 AC_VERB_SET_PIN_WIDGET_CONTROL
,
520 case ALC_AUTOMUTE_AMP
:
521 snd_hda_codec_amp_stereo(codec
, nid
, HDA_OUTPUT
, 0,
522 HDA_AMP_MUTE
, mute_bits
);
524 case ALC_AUTOMUTE_MIXER
:
525 nid
= spec
->automute_mixer_nid
[i
];
528 snd_hda_codec_amp_stereo(codec
, nid
, HDA_INPUT
, 0,
529 HDA_AMP_MUTE
, mute_bits
);
530 snd_hda_codec_amp_stereo(codec
, nid
, HDA_INPUT
, 1,
531 HDA_AMP_MUTE
, mute_bits
);
537 /* Toggle outputs muting */
538 static void update_outputs(struct hda_codec
*codec
)
540 struct alc_spec
*spec
= codec
->spec
;
543 /* Control HP pins/amps depending on master_mute state;
544 * in general, HP pins/amps control should be enabled in all cases,
545 * but currently set only for master_mute, just to be safe
547 if (!spec
->shared_mic_hp
) /* don't change HP-pin when shared with mic */
548 do_automute(codec
, ARRAY_SIZE(spec
->autocfg
.hp_pins
),
549 spec
->autocfg
.hp_pins
, spec
->master_mute
, true);
551 if (!spec
->automute_speaker
)
554 on
= spec
->hp_jack_present
| spec
->line_jack_present
;
555 on
|= spec
->master_mute
;
556 do_automute(codec
, ARRAY_SIZE(spec
->autocfg
.speaker_pins
),
557 spec
->autocfg
.speaker_pins
, on
, false);
559 /* toggle line-out mutes if needed, too */
560 /* if LO is a copy of either HP or Speaker, don't need to handle it */
561 if (spec
->autocfg
.line_out_pins
[0] == spec
->autocfg
.hp_pins
[0] ||
562 spec
->autocfg
.line_out_pins
[0] == spec
->autocfg
.speaker_pins
[0])
564 if (!spec
->automute_lo
)
567 on
= spec
->hp_jack_present
;
568 on
|= spec
->master_mute
;
569 do_automute(codec
, ARRAY_SIZE(spec
->autocfg
.line_out_pins
),
570 spec
->autocfg
.line_out_pins
, on
, false);
573 static void call_update_outputs(struct hda_codec
*codec
)
575 struct alc_spec
*spec
= codec
->spec
;
576 if (spec
->automute_hook
)
577 spec
->automute_hook(codec
);
579 update_outputs(codec
);
582 /* standard HP-automute helper */
583 static void alc_hp_automute(struct hda_codec
*codec
)
585 struct alc_spec
*spec
= codec
->spec
;
587 spec
->hp_jack_present
=
588 detect_jacks(codec
, ARRAY_SIZE(spec
->autocfg
.hp_pins
),
589 spec
->autocfg
.hp_pins
);
590 if (!spec
->detect_hp
|| (!spec
->automute_speaker
&& !spec
->automute_lo
))
592 call_update_outputs(codec
);
595 /* standard line-out-automute helper */
596 static void alc_line_automute(struct hda_codec
*codec
)
598 struct alc_spec
*spec
= codec
->spec
;
600 /* check LO jack only when it's different from HP */
601 if (spec
->autocfg
.line_out_pins
[0] == spec
->autocfg
.hp_pins
[0])
604 spec
->line_jack_present
=
605 detect_jacks(codec
, ARRAY_SIZE(spec
->autocfg
.line_out_pins
),
606 spec
->autocfg
.line_out_pins
);
607 if (!spec
->automute_speaker
|| !spec
->detect_lo
)
609 call_update_outputs(codec
);
612 #define get_connection_index(codec, mux, nid) \
613 snd_hda_get_conn_index(codec, mux, nid, 0)
615 /* standard mic auto-switch helper */
616 static void alc_mic_automute(struct hda_codec
*codec
)
618 struct alc_spec
*spec
= codec
->spec
;
619 hda_nid_t
*pins
= spec
->imux_pins
;
621 if (!spec
->auto_mic
|| !spec
->auto_mic_valid_imux
)
623 if (snd_BUG_ON(!spec
->adc_nids
))
625 if (snd_BUG_ON(spec
->int_mic_idx
< 0 || spec
->ext_mic_idx
< 0))
628 if (snd_hda_jack_detect(codec
, pins
[spec
->ext_mic_idx
]))
629 alc_mux_select(codec
, 0, spec
->ext_mic_idx
, false);
630 else if (spec
->dock_mic_idx
>= 0 &&
631 snd_hda_jack_detect(codec
, pins
[spec
->dock_mic_idx
]))
632 alc_mux_select(codec
, 0, spec
->dock_mic_idx
, false);
634 alc_mux_select(codec
, 0, spec
->int_mic_idx
, false);
637 /* handle the specified unsol action (ALC_XXX_EVENT) */
638 static void alc_exec_unsol_event(struct hda_codec
*codec
, int action
)
642 alc_hp_automute(codec
);
644 case ALC_FRONT_EVENT
:
645 alc_line_automute(codec
);
648 alc_mic_automute(codec
);
651 snd_hda_jack_report_sync(codec
);
654 /* update the master volume per volume-knob's unsol event */
655 static void alc_update_knob_master(struct hda_codec
*codec
, hda_nid_t nid
)
658 struct snd_kcontrol
*kctl
;
659 struct snd_ctl_elem_value
*uctl
;
661 kctl
= snd_hda_find_mixer_ctl(codec
, "Master Playback Volume");
664 uctl
= kzalloc(sizeof(*uctl
), GFP_KERNEL
);
667 val
= snd_hda_codec_read(codec
, nid
, 0,
668 AC_VERB_GET_VOLUME_KNOB_CONTROL
, 0);
669 val
&= HDA_AMP_VOLMASK
;
670 uctl
->value
.integer
.value
[0] = val
;
671 uctl
->value
.integer
.value
[1] = val
;
672 kctl
->put(kctl
, uctl
);
676 /* unsolicited event for HP jack sensing */
677 static void alc_sku_unsol_event(struct hda_codec
*codec
, unsigned int res
)
681 if (codec
->vendor_id
== 0x10ec0880)
685 action
= snd_hda_jack_get_action(codec
, res
);
686 if (res
== ALC_DCVOL_EVENT
) {
687 /* Execute the dc-vol event here as it requires the NID
688 * but we don't pass NID to alc_exec_unsol_event().
689 * Once when we convert all static quirks to the auto-parser,
690 * this can be integerated into there.
692 struct hda_jack_tbl
*jack
;
693 jack
= snd_hda_jack_tbl_get_from_tag(codec
, res
);
695 alc_update_knob_master(codec
, jack
->nid
);
698 alc_exec_unsol_event(codec
, action
);
701 /* call init functions of standard auto-mute helpers */
702 static void alc_inithook(struct hda_codec
*codec
)
704 alc_hp_automute(codec
);
705 alc_line_automute(codec
);
706 alc_mic_automute(codec
);
709 /* additional initialization for ALC888 variants */
710 static void alc888_coef_init(struct hda_codec
*codec
)
714 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_COEF_INDEX
, 0);
715 tmp
= snd_hda_codec_read(codec
, 0x20, 0, AC_VERB_GET_PROC_COEF
, 0);
716 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_COEF_INDEX
, 7);
717 if ((tmp
& 0xf0) == 0x20)
719 snd_hda_codec_read(codec
, 0x20, 0,
720 AC_VERB_SET_PROC_COEF
, 0x830);
723 snd_hda_codec_read(codec
, 0x20, 0,
724 AC_VERB_SET_PROC_COEF
, 0x3030);
727 /* additional initialization for ALC889 variants */
728 static void alc889_coef_init(struct hda_codec
*codec
)
732 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_COEF_INDEX
, 7);
733 tmp
= snd_hda_codec_read(codec
, 0x20, 0, AC_VERB_GET_PROC_COEF
, 0);
734 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_COEF_INDEX
, 7);
735 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_PROC_COEF
, tmp
|0x2010);
738 /* turn on/off EAPD control (only if available) */
739 static void set_eapd(struct hda_codec
*codec
, hda_nid_t nid
, int on
)
741 if (get_wcaps_type(get_wcaps(codec
, nid
)) != AC_WID_PIN
)
743 if (snd_hda_query_pin_caps(codec
, nid
) & AC_PINCAP_EAPD
)
744 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_EAPD_BTLENABLE
,
748 /* turn on/off EAPD controls of the codec */
749 static void alc_auto_setup_eapd(struct hda_codec
*codec
, bool on
)
751 /* We currently only handle front, HP */
752 static hda_nid_t pins
[] = {
753 0x0f, 0x10, 0x14, 0x15, 0
756 for (p
= pins
; *p
; p
++)
757 set_eapd(codec
, *p
, on
);
760 /* generic shutup callback;
761 * just turning off EPAD and a little pause for avoiding pop-noise
763 static void alc_eapd_shutup(struct hda_codec
*codec
)
765 alc_auto_setup_eapd(codec
, false);
769 /* generic EAPD initialization */
770 static void alc_auto_init_amp(struct hda_codec
*codec
, int type
)
774 alc_auto_setup_eapd(codec
, true);
777 snd_hda_sequence_write(codec
, alc_gpio1_init_verbs
);
780 snd_hda_sequence_write(codec
, alc_gpio2_init_verbs
);
783 snd_hda_sequence_write(codec
, alc_gpio3_init_verbs
);
785 case ALC_INIT_DEFAULT
:
786 switch (codec
->vendor_id
) {
788 snd_hda_codec_write(codec
, 0x1a, 0,
789 AC_VERB_SET_COEF_INDEX
, 7);
790 tmp
= snd_hda_codec_read(codec
, 0x1a, 0,
791 AC_VERB_GET_PROC_COEF
, 0);
792 snd_hda_codec_write(codec
, 0x1a, 0,
793 AC_VERB_SET_COEF_INDEX
, 7);
794 snd_hda_codec_write(codec
, 0x1a, 0,
795 AC_VERB_SET_PROC_COEF
,
804 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
805 alc889_coef_init(codec
);
808 alc888_coef_init(codec
);
810 #if 0 /* XXX: This may cause the silent output on speaker on some machines */
813 snd_hda_codec_write(codec
, 0x20, 0,
814 AC_VERB_SET_COEF_INDEX
, 7);
815 tmp
= snd_hda_codec_read(codec
, 0x20, 0,
816 AC_VERB_GET_PROC_COEF
, 0);
817 snd_hda_codec_write(codec
, 0x20, 0,
818 AC_VERB_SET_COEF_INDEX
, 7);
819 snd_hda_codec_write(codec
, 0x20, 0,
820 AC_VERB_SET_PROC_COEF
,
830 * Auto-Mute mode mixer enum support
832 static int alc_automute_mode_info(struct snd_kcontrol
*kcontrol
,
833 struct snd_ctl_elem_info
*uinfo
)
835 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
836 struct alc_spec
*spec
= codec
->spec
;
837 static const char * const texts2
[] = {
838 "Disabled", "Enabled"
840 static const char * const texts3
[] = {
841 "Disabled", "Speaker Only", "Line-Out+Speaker"
843 const char * const *texts
;
845 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
847 if (spec
->automute_speaker_possible
&& spec
->automute_lo_possible
) {
848 uinfo
->value
.enumerated
.items
= 3;
851 uinfo
->value
.enumerated
.items
= 2;
854 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
)
855 uinfo
->value
.enumerated
.item
= uinfo
->value
.enumerated
.items
- 1;
856 strcpy(uinfo
->value
.enumerated
.name
,
857 texts
[uinfo
->value
.enumerated
.item
]);
861 static int alc_automute_mode_get(struct snd_kcontrol
*kcontrol
,
862 struct snd_ctl_elem_value
*ucontrol
)
864 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
865 struct alc_spec
*spec
= codec
->spec
;
866 unsigned int val
= 0;
867 if (spec
->automute_speaker
)
869 if (spec
->automute_lo
)
872 ucontrol
->value
.enumerated
.item
[0] = val
;
876 static int alc_automute_mode_put(struct snd_kcontrol
*kcontrol
,
877 struct snd_ctl_elem_value
*ucontrol
)
879 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
880 struct alc_spec
*spec
= codec
->spec
;
882 switch (ucontrol
->value
.enumerated
.item
[0]) {
884 if (!spec
->automute_speaker
&& !spec
->automute_lo
)
886 spec
->automute_speaker
= 0;
887 spec
->automute_lo
= 0;
890 if (spec
->automute_speaker_possible
) {
891 if (!spec
->automute_lo
&& spec
->automute_speaker
)
893 spec
->automute_speaker
= 1;
894 spec
->automute_lo
= 0;
895 } else if (spec
->automute_lo_possible
) {
896 if (spec
->automute_lo
)
898 spec
->automute_lo
= 1;
903 if (!spec
->automute_lo_possible
|| !spec
->automute_speaker_possible
)
905 if (spec
->automute_speaker
&& spec
->automute_lo
)
907 spec
->automute_speaker
= 1;
908 spec
->automute_lo
= 1;
913 call_update_outputs(codec
);
917 static const struct snd_kcontrol_new alc_automute_mode_enum
= {
918 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
919 .name
= "Auto-Mute Mode",
920 .info
= alc_automute_mode_info
,
921 .get
= alc_automute_mode_get
,
922 .put
= alc_automute_mode_put
,
925 static struct snd_kcontrol_new
*alc_kcontrol_new(struct alc_spec
*spec
)
927 snd_array_init(&spec
->kctls
, sizeof(struct snd_kcontrol_new
), 32);
928 return snd_array_new(&spec
->kctls
);
931 static int alc_add_automute_mode_enum(struct hda_codec
*codec
)
933 struct alc_spec
*spec
= codec
->spec
;
934 struct snd_kcontrol_new
*knew
;
936 knew
= alc_kcontrol_new(spec
);
939 *knew
= alc_automute_mode_enum
;
940 knew
->name
= kstrdup("Auto-Mute Mode", GFP_KERNEL
);
947 * Check the availability of HP/line-out auto-mute;
948 * Set up appropriately if really supported
950 static void alc_init_automute(struct hda_codec
*codec
)
952 struct alc_spec
*spec
= codec
->spec
;
953 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
959 if (cfg
->line_out_pins
[0])
961 if (cfg
->speaker_pins
[0])
963 if (present
< 2) /* need two different output types */
966 if (!cfg
->speaker_pins
[0] &&
967 cfg
->line_out_type
== AUTO_PIN_SPEAKER_OUT
) {
968 memcpy(cfg
->speaker_pins
, cfg
->line_out_pins
,
969 sizeof(cfg
->speaker_pins
));
970 cfg
->speaker_outs
= cfg
->line_outs
;
973 if (!cfg
->hp_pins
[0] &&
974 cfg
->line_out_type
== AUTO_PIN_HP_OUT
) {
975 memcpy(cfg
->hp_pins
, cfg
->line_out_pins
,
976 sizeof(cfg
->hp_pins
));
977 cfg
->hp_outs
= cfg
->line_outs
;
980 spec
->automute_mode
= ALC_AUTOMUTE_PIN
;
982 for (i
= 0; i
< cfg
->hp_outs
; i
++) {
983 hda_nid_t nid
= cfg
->hp_pins
[i
];
984 if (!is_jack_detectable(codec
, nid
))
986 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
988 snd_hda_jack_detect_enable(codec
, nid
, ALC_HP_EVENT
);
992 if (cfg
->line_out_type
== AUTO_PIN_LINE_OUT
&& cfg
->line_outs
) {
993 if (cfg
->speaker_outs
)
994 for (i
= 0; i
< cfg
->line_outs
; i
++) {
995 hda_nid_t nid
= cfg
->line_out_pins
[i
];
996 if (!is_jack_detectable(codec
, nid
))
998 snd_printdd("realtek: Enable Line-Out "
999 "auto-muting on NID 0x%x\n", nid
);
1000 snd_hda_jack_detect_enable(codec
, nid
,
1002 spec
->detect_lo
= 1;
1004 spec
->automute_lo_possible
= spec
->detect_hp
;
1007 spec
->automute_speaker_possible
= cfg
->speaker_outs
&&
1008 (spec
->detect_hp
|| spec
->detect_lo
);
1010 spec
->automute_lo
= spec
->automute_lo_possible
;
1011 spec
->automute_speaker
= spec
->automute_speaker_possible
;
1013 if (spec
->automute_speaker_possible
|| spec
->automute_lo_possible
) {
1014 /* create a control for automute mode */
1015 alc_add_automute_mode_enum(codec
);
1016 spec
->unsol_event
= alc_sku_unsol_event
;
1020 /* return the position of NID in the list, or -1 if not found */
1021 static int find_idx_in_nid_list(hda_nid_t nid
, const hda_nid_t
*list
, int nums
)
1024 for (i
= 0; i
< nums
; i
++)
1030 /* check whether dynamic ADC-switching is available */
1031 static bool alc_check_dyn_adc_switch(struct hda_codec
*codec
)
1033 struct alc_spec
*spec
= codec
->spec
;
1034 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
1038 if (imux
!= spec
->input_mux
) /* no dynamic imux? */
1041 for (n
= 0; n
< spec
->num_adc_nids
; n
++) {
1042 cap
= spec
->private_capsrc_nids
[n
];
1043 for (i
= 0; i
< imux
->num_items
; i
++) {
1044 pin
= spec
->imux_pins
[i
];
1047 if (get_connection_index(codec
, cap
, pin
) < 0)
1050 if (i
>= imux
->num_items
)
1051 return true; /* no ADC-switch is needed */
1054 for (i
= 0; i
< imux
->num_items
; i
++) {
1055 pin
= spec
->imux_pins
[i
];
1056 for (n
= 0; n
< spec
->num_adc_nids
; n
++) {
1057 cap
= spec
->private_capsrc_nids
[n
];
1058 idx
= get_connection_index(codec
, cap
, pin
);
1060 imux
->items
[i
].index
= idx
;
1061 spec
->dyn_adc_idx
[i
] = n
;
1067 snd_printdd("realtek: enabling ADC switching\n");
1068 spec
->dyn_adc_switch
= 1;
1072 /* rebuild imux for matching with the given auto-mic pins (if not yet) */
1073 static bool alc_rebuild_imux_for_auto_mic(struct hda_codec
*codec
)
1075 struct alc_spec
*spec
= codec
->spec
;
1076 struct hda_input_mux
*imux
;
1077 static char * const texts
[3] = {
1078 "Mic", "Internal Mic", "Dock Mic"
1082 if (!spec
->auto_mic
)
1084 imux
= &spec
->private_imux
[0];
1085 if (spec
->input_mux
== imux
)
1087 spec
->imux_pins
[0] = spec
->ext_mic_pin
;
1088 spec
->imux_pins
[1] = spec
->int_mic_pin
;
1089 spec
->imux_pins
[2] = spec
->dock_mic_pin
;
1090 for (i
= 0; i
< 3; i
++) {
1091 strcpy(imux
->items
[i
].label
, texts
[i
]);
1092 if (spec
->imux_pins
[i
]) {
1093 hda_nid_t pin
= spec
->imux_pins
[i
];
1095 for (c
= 0; c
< spec
->num_adc_nids
; c
++) {
1096 hda_nid_t cap
= get_capsrc(spec
, c
);
1097 int idx
= get_connection_index(codec
, cap
, pin
);
1099 imux
->items
[i
].index
= idx
;
1103 imux
->num_items
= i
+ 1;
1106 spec
->num_mux_defs
= 1;
1107 spec
->input_mux
= imux
;
1111 /* check whether all auto-mic pins are valid; setup indices if OK */
1112 static bool alc_auto_mic_check_imux(struct hda_codec
*codec
)
1114 struct alc_spec
*spec
= codec
->spec
;
1115 const struct hda_input_mux
*imux
;
1117 if (!spec
->auto_mic
)
1119 if (spec
->auto_mic_valid_imux
)
1120 return true; /* already checked */
1122 /* fill up imux indices */
1123 if (!alc_check_dyn_adc_switch(codec
)) {
1128 imux
= spec
->input_mux
;
1129 spec
->ext_mic_idx
= find_idx_in_nid_list(spec
->ext_mic_pin
,
1130 spec
->imux_pins
, imux
->num_items
);
1131 spec
->int_mic_idx
= find_idx_in_nid_list(spec
->int_mic_pin
,
1132 spec
->imux_pins
, imux
->num_items
);
1133 spec
->dock_mic_idx
= find_idx_in_nid_list(spec
->dock_mic_pin
,
1134 spec
->imux_pins
, imux
->num_items
);
1135 if (spec
->ext_mic_idx
< 0 || spec
->int_mic_idx
< 0) {
1137 return false; /* no corresponding imux */
1140 snd_hda_jack_detect_enable(codec
, spec
->ext_mic_pin
, ALC_MIC_EVENT
);
1141 if (spec
->dock_mic_pin
)
1142 snd_hda_jack_detect_enable(codec
, spec
->dock_mic_pin
,
1145 spec
->auto_mic_valid_imux
= 1;
1151 * Check the availability of auto-mic switch;
1152 * Set up if really supported
1154 static void alc_init_auto_mic(struct hda_codec
*codec
)
1156 struct alc_spec
*spec
= codec
->spec
;
1157 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
1158 hda_nid_t fixed
, ext
, dock
;
1161 if (spec
->shared_mic_hp
)
1162 return; /* no auto-mic for the shared I/O */
1164 spec
->ext_mic_idx
= spec
->int_mic_idx
= spec
->dock_mic_idx
= -1;
1166 fixed
= ext
= dock
= 0;
1167 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
1168 hda_nid_t nid
= cfg
->inputs
[i
].pin
;
1169 unsigned int defcfg
;
1170 defcfg
= snd_hda_codec_get_pincfg(codec
, nid
);
1171 switch (snd_hda_get_input_pin_attr(defcfg
)) {
1172 case INPUT_PIN_ATTR_INT
:
1174 return; /* already occupied */
1175 if (cfg
->inputs
[i
].type
!= AUTO_PIN_MIC
)
1176 return; /* invalid type */
1179 case INPUT_PIN_ATTR_UNUSED
:
1180 return; /* invalid entry */
1181 case INPUT_PIN_ATTR_DOCK
:
1183 return; /* already occupied */
1184 if (cfg
->inputs
[i
].type
> AUTO_PIN_LINE_IN
)
1185 return; /* invalid type */
1190 return; /* already occupied */
1191 if (cfg
->inputs
[i
].type
!= AUTO_PIN_MIC
)
1192 return; /* invalid type */
1203 if (!is_jack_detectable(codec
, ext
))
1204 return; /* no unsol support */
1205 if (dock
&& !is_jack_detectable(codec
, dock
))
1206 return; /* no unsol support */
1208 /* check imux indices */
1209 spec
->ext_mic_pin
= ext
;
1210 spec
->int_mic_pin
= fixed
;
1211 spec
->dock_mic_pin
= dock
;
1214 if (!alc_auto_mic_check_imux(codec
))
1217 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1219 spec
->unsol_event
= alc_sku_unsol_event
;
1222 /* check the availabilities of auto-mute and auto-mic switches */
1223 static void alc_auto_check_switches(struct hda_codec
*codec
)
1225 alc_init_automute(codec
);
1226 alc_init_auto_mic(codec
);
1230 * Realtek SSID verification
1233 /* Could be any non-zero and even value. When used as fixup, tells
1234 * the driver to ignore any present sku defines.
1236 #define ALC_FIXUP_SKU_IGNORE (2)
1238 static int alc_auto_parse_customize_define(struct hda_codec
*codec
)
1240 unsigned int ass
, tmp
, i
;
1242 struct alc_spec
*spec
= codec
->spec
;
1244 spec
->cdefine
.enable_pcbeep
= 1; /* assume always enabled */
1246 if (spec
->cdefine
.fixup
) {
1247 ass
= spec
->cdefine
.sku_cfg
;
1248 if (ass
== ALC_FIXUP_SKU_IGNORE
)
1253 ass
= codec
->subsystem_id
& 0xffff;
1254 if (ass
!= codec
->bus
->pci
->subsystem_device
&& (ass
& 1))
1258 if (codec
->vendor_id
== 0x10ec0260)
1260 ass
= snd_hda_codec_get_pincfg(codec
, nid
);
1263 printk(KERN_INFO
"hda_codec: %s: SKU not ready 0x%08x\n",
1264 codec
->chip_name
, ass
);
1270 for (i
= 1; i
< 16; i
++) {
1274 if (((ass
>> 16) & 0xf) != tmp
)
1277 spec
->cdefine
.port_connectivity
= ass
>> 30;
1278 spec
->cdefine
.enable_pcbeep
= (ass
& 0x100000) >> 20;
1279 spec
->cdefine
.check_sum
= (ass
>> 16) & 0xf;
1280 spec
->cdefine
.customization
= ass
>> 8;
1282 spec
->cdefine
.sku_cfg
= ass
;
1283 spec
->cdefine
.external_amp
= (ass
& 0x38) >> 3;
1284 spec
->cdefine
.platform_type
= (ass
& 0x4) >> 2;
1285 spec
->cdefine
.swap
= (ass
& 0x2) >> 1;
1286 spec
->cdefine
.override
= ass
& 0x1;
1288 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1289 nid
, spec
->cdefine
.sku_cfg
);
1290 snd_printd("SKU: port_connectivity=0x%x\n",
1291 spec
->cdefine
.port_connectivity
);
1292 snd_printd("SKU: enable_pcbeep=0x%x\n", spec
->cdefine
.enable_pcbeep
);
1293 snd_printd("SKU: check_sum=0x%08x\n", spec
->cdefine
.check_sum
);
1294 snd_printd("SKU: customization=0x%08x\n", spec
->cdefine
.customization
);
1295 snd_printd("SKU: external_amp=0x%x\n", spec
->cdefine
.external_amp
);
1296 snd_printd("SKU: platform_type=0x%x\n", spec
->cdefine
.platform_type
);
1297 snd_printd("SKU: swap=0x%x\n", spec
->cdefine
.swap
);
1298 snd_printd("SKU: override=0x%x\n", spec
->cdefine
.override
);
1303 /* return true if the given NID is found in the list */
1304 static bool found_in_nid_list(hda_nid_t nid
, const hda_nid_t
*list
, int nums
)
1306 return find_idx_in_nid_list(nid
, list
, nums
) >= 0;
1309 /* check subsystem ID and set up device-specific initialization;
1310 * return 1 if initialized, 0 if invalid SSID
1312 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1313 * 31 ~ 16 : Manufacture ID
1315 * 7 ~ 0 : Assembly ID
1316 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1318 static int alc_subsystem_id(struct hda_codec
*codec
,
1319 hda_nid_t porta
, hda_nid_t porte
,
1320 hda_nid_t portd
, hda_nid_t porti
)
1322 unsigned int ass
, tmp
, i
;
1324 struct alc_spec
*spec
= codec
->spec
;
1326 if (spec
->cdefine
.fixup
) {
1327 ass
= spec
->cdefine
.sku_cfg
;
1328 if (ass
== ALC_FIXUP_SKU_IGNORE
)
1333 ass
= codec
->subsystem_id
& 0xffff;
1334 if ((ass
!= codec
->bus
->pci
->subsystem_device
) && (ass
& 1))
1337 /* invalid SSID, check the special NID pin defcfg instead */
1339 * 31~30 : port connectivity
1342 * 19~16 : Check sum (15:1)
1347 if (codec
->vendor_id
== 0x10ec0260)
1349 ass
= snd_hda_codec_get_pincfg(codec
, nid
);
1350 snd_printd("realtek: No valid SSID, "
1351 "checking pincfg 0x%08x for NID 0x%x\n",
1355 if ((ass
>> 30) != 1) /* no physical connection */
1360 for (i
= 1; i
< 16; i
++) {
1364 if (((ass
>> 16) & 0xf) != tmp
)
1367 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1368 ass
& 0xffff, codec
->vendor_id
);
1372 * 2 : 0 --> Desktop, 1 --> Laptop
1373 * 3~5 : External Amplifier control
1376 tmp
= (ass
& 0x38) >> 3; /* external Amp control */
1379 spec
->init_amp
= ALC_INIT_GPIO1
;
1382 spec
->init_amp
= ALC_INIT_GPIO2
;
1385 spec
->init_amp
= ALC_INIT_GPIO3
;
1389 spec
->init_amp
= ALC_INIT_DEFAULT
;
1393 /* is laptop or Desktop and enable the function "Mute internal speaker
1394 * when the external headphone out jack is plugged"
1396 if (!(ass
& 0x8000))
1399 * 10~8 : Jack location
1400 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1402 * 15 : 1 --> enable the function "Mute internal speaker
1403 * when the external headphone out jack is plugged"
1405 if (!spec
->autocfg
.hp_pins
[0] &&
1406 !(spec
->autocfg
.line_out_pins
[0] &&
1407 spec
->autocfg
.line_out_type
== AUTO_PIN_HP_OUT
)) {
1409 tmp
= (ass
>> 11) & 0x3; /* HP to chassis */
1420 if (found_in_nid_list(nid
, spec
->autocfg
.line_out_pins
,
1421 spec
->autocfg
.line_outs
))
1423 spec
->autocfg
.hp_pins
[0] = nid
;
1428 /* Check the validity of ALC subsystem-id
1429 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1430 static void alc_ssid_check(struct hda_codec
*codec
, const hda_nid_t
*ports
)
1432 if (!alc_subsystem_id(codec
, ports
[0], ports
[1], ports
[2], ports
[3])) {
1433 struct alc_spec
*spec
= codec
->spec
;
1434 snd_printd("realtek: "
1435 "Enable default setup for auto mode as fallback\n");
1436 spec
->init_amp
= ALC_INIT_DEFAULT
;
1441 * Fix-up pin default configurations and add default verbs
1449 struct alc_model_fixup
{
1460 const struct alc_pincfg
*pins
;
1461 const struct hda_verb
*verbs
;
1462 void (*func
)(struct hda_codec
*codec
,
1463 const struct alc_fixup
*fix
,
1477 ALC_FIXUP_ACT_PRE_PROBE
,
1478 ALC_FIXUP_ACT_PROBE
,
1482 static void alc_apply_fixup(struct hda_codec
*codec
, int action
)
1484 struct alc_spec
*spec
= codec
->spec
;
1485 int id
= spec
->fixup_id
;
1486 #ifdef CONFIG_SND_DEBUG_VERBOSE
1487 const char *modelname
= spec
->fixup_name
;
1491 if (!spec
->fixup_list
)
1495 const struct alc_fixup
*fix
= spec
->fixup_list
+ id
;
1496 const struct alc_pincfg
*cfg
;
1498 switch (fix
->type
) {
1500 if (action
!= ALC_FIXUP_ACT_PRE_PROBE
|| !fix
->v
.sku
)
1502 snd_printdd(KERN_INFO
"hda_codec: %s: "
1503 "Apply sku override for %s\n",
1504 codec
->chip_name
, modelname
);
1505 spec
->cdefine
.sku_cfg
= fix
->v
.sku
;
1506 spec
->cdefine
.fixup
= 1;
1508 case ALC_FIXUP_PINS
:
1510 if (action
!= ALC_FIXUP_ACT_PRE_PROBE
|| !cfg
)
1512 snd_printdd(KERN_INFO
"hda_codec: %s: "
1513 "Apply pincfg for %s\n",
1514 codec
->chip_name
, modelname
);
1515 for (; cfg
->nid
; cfg
++)
1516 snd_hda_codec_set_pincfg(codec
, cfg
->nid
,
1519 case ALC_FIXUP_VERBS
:
1520 if (action
!= ALC_FIXUP_ACT_PROBE
|| !fix
->v
.verbs
)
1522 snd_printdd(KERN_INFO
"hda_codec: %s: "
1523 "Apply fix-verbs for %s\n",
1524 codec
->chip_name
, modelname
);
1525 add_verb(codec
->spec
, fix
->v
.verbs
);
1527 case ALC_FIXUP_FUNC
:
1530 snd_printdd(KERN_INFO
"hda_codec: %s: "
1531 "Apply fix-func for %s\n",
1532 codec
->chip_name
, modelname
);
1533 fix
->v
.func(codec
, fix
, action
);
1536 snd_printk(KERN_ERR
"hda_codec: %s: "
1537 "Invalid fixup type %d\n",
1538 codec
->chip_name
, fix
->type
);
1549 static void alc_pick_fixup(struct hda_codec
*codec
,
1550 const struct alc_model_fixup
*models
,
1551 const struct snd_pci_quirk
*quirk
,
1552 const struct alc_fixup
*fixlist
)
1554 struct alc_spec
*spec
= codec
->spec
;
1555 const struct snd_pci_quirk
*q
;
1557 const char *name
= NULL
;
1559 if (codec
->modelname
&& models
) {
1560 while (models
->name
) {
1561 if (!strcmp(codec
->modelname
, models
->name
)) {
1563 name
= models
->name
;
1570 q
= snd_pci_quirk_lookup(codec
->bus
->pci
, quirk
);
1573 #ifdef CONFIG_SND_DEBUG_VERBOSE
1579 for (q
= quirk
; q
->subvendor
; q
++) {
1580 unsigned int vendorid
=
1581 q
->subdevice
| (q
->subvendor
<< 16);
1582 if (vendorid
== codec
->subsystem_id
) {
1584 #ifdef CONFIG_SND_DEBUG_VERBOSE
1592 spec
->fixup_id
= id
;
1594 spec
->fixup_list
= fixlist
;
1595 spec
->fixup_name
= name
;
1600 * COEF access helper functions
1602 static int alc_read_coef_idx(struct hda_codec
*codec
,
1603 unsigned int coef_idx
)
1606 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_COEF_INDEX
,
1608 val
= snd_hda_codec_read(codec
, 0x20, 0,
1609 AC_VERB_GET_PROC_COEF
, 0);
1613 static void alc_write_coef_idx(struct hda_codec
*codec
, unsigned int coef_idx
,
1614 unsigned int coef_val
)
1616 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_COEF_INDEX
,
1618 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_PROC_COEF
,
1622 /* a special bypass for COEF 0; read the cached value at the second time */
1623 static unsigned int alc_get_coef0(struct hda_codec
*codec
)
1625 struct alc_spec
*spec
= codec
->spec
;
1627 spec
->coef0
= alc_read_coef_idx(codec
, 0);
1632 * Digital I/O handling
1635 /* set right pin controls for digital I/O */
1636 static void alc_auto_init_digital(struct hda_codec
*codec
)
1638 struct alc_spec
*spec
= codec
->spec
;
1642 for (i
= 0; i
< spec
->autocfg
.dig_outs
; i
++) {
1643 pin
= spec
->autocfg
.dig_out_pins
[i
];
1646 snd_hda_codec_write(codec
, pin
, 0,
1647 AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
);
1649 dac
= spec
->multiout
.dig_out_nid
;
1651 dac
= spec
->slave_dig_outs
[i
- 1];
1652 if (!dac
|| !(get_wcaps(codec
, dac
) & AC_WCAP_OUT_AMP
))
1654 snd_hda_codec_write(codec
, dac
, 0,
1655 AC_VERB_SET_AMP_GAIN_MUTE
,
1658 pin
= spec
->autocfg
.dig_in_pin
;
1660 snd_hda_codec_write(codec
, pin
, 0,
1661 AC_VERB_SET_PIN_WIDGET_CONTROL
,
1665 /* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1666 static void alc_auto_parse_digital(struct hda_codec
*codec
)
1668 struct alc_spec
*spec
= codec
->spec
;
1672 /* support multiple SPDIFs; the secondary is set up as a slave */
1674 for (i
= 0; i
< spec
->autocfg
.dig_outs
; i
++) {
1676 err
= snd_hda_get_connections(codec
,
1677 spec
->autocfg
.dig_out_pins
[i
],
1678 conn
, ARRAY_SIZE(conn
));
1681 dig_nid
= conn
[0]; /* assume the first element is audio-out */
1683 spec
->multiout
.dig_out_nid
= dig_nid
;
1684 spec
->dig_out_type
= spec
->autocfg
.dig_out_type
[0];
1686 spec
->multiout
.slave_dig_outs
= spec
->slave_dig_outs
;
1687 if (nums
>= ARRAY_SIZE(spec
->slave_dig_outs
) - 1)
1689 spec
->slave_dig_outs
[nums
- 1] = dig_nid
;
1694 if (spec
->autocfg
.dig_in_pin
) {
1695 dig_nid
= codec
->start_nid
;
1696 for (i
= 0; i
< codec
->num_nodes
; i
++, dig_nid
++) {
1697 unsigned int wcaps
= get_wcaps(codec
, dig_nid
);
1698 if (get_wcaps_type(wcaps
) != AC_WID_AUD_IN
)
1700 if (!(wcaps
& AC_WCAP_DIGITAL
))
1702 if (!(wcaps
& AC_WCAP_CONN_LIST
))
1704 err
= get_connection_index(codec
, dig_nid
,
1705 spec
->autocfg
.dig_in_pin
);
1707 spec
->dig_in_nid
= dig_nid
;
1715 * capture mixer elements
1717 static int alc_cap_vol_info(struct snd_kcontrol
*kcontrol
,
1718 struct snd_ctl_elem_info
*uinfo
)
1720 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1721 struct alc_spec
*spec
= codec
->spec
;
1725 mutex_lock(&codec
->control_mutex
);
1726 if (spec
->vol_in_capsrc
)
1727 val
= HDA_COMPOSE_AMP_VAL(spec
->capsrc_nids
[0], 3, 0, HDA_OUTPUT
);
1729 val
= HDA_COMPOSE_AMP_VAL(spec
->adc_nids
[0], 3, 0, HDA_INPUT
);
1730 kcontrol
->private_value
= val
;
1731 err
= snd_hda_mixer_amp_volume_info(kcontrol
, uinfo
);
1732 mutex_unlock(&codec
->control_mutex
);
1736 static int alc_cap_vol_tlv(struct snd_kcontrol
*kcontrol
, int op_flag
,
1737 unsigned int size
, unsigned int __user
*tlv
)
1739 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1740 struct alc_spec
*spec
= codec
->spec
;
1744 mutex_lock(&codec
->control_mutex
);
1745 if (spec
->vol_in_capsrc
)
1746 val
= HDA_COMPOSE_AMP_VAL(spec
->capsrc_nids
[0], 3, 0, HDA_OUTPUT
);
1748 val
= HDA_COMPOSE_AMP_VAL(spec
->adc_nids
[0], 3, 0, HDA_INPUT
);
1749 kcontrol
->private_value
= val
;
1750 err
= snd_hda_mixer_amp_tlv(kcontrol
, op_flag
, size
, tlv
);
1751 mutex_unlock(&codec
->control_mutex
);
1755 typedef int (*getput_call_t
)(struct snd_kcontrol
*kcontrol
,
1756 struct snd_ctl_elem_value
*ucontrol
);
1758 static int alc_cap_getput_caller(struct snd_kcontrol
*kcontrol
,
1759 struct snd_ctl_elem_value
*ucontrol
,
1760 getput_call_t func
, bool check_adc_switch
)
1762 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1763 struct alc_spec
*spec
= codec
->spec
;
1766 mutex_lock(&codec
->control_mutex
);
1767 if (check_adc_switch
&& spec
->dyn_adc_switch
) {
1768 for (i
= 0; i
< spec
->num_adc_nids
; i
++) {
1769 kcontrol
->private_value
=
1770 HDA_COMPOSE_AMP_VAL(spec
->adc_nids
[i
],
1772 err
= func(kcontrol
, ucontrol
);
1777 i
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
1778 if (spec
->vol_in_capsrc
)
1779 kcontrol
->private_value
=
1780 HDA_COMPOSE_AMP_VAL(spec
->capsrc_nids
[i
],
1783 kcontrol
->private_value
=
1784 HDA_COMPOSE_AMP_VAL(spec
->adc_nids
[i
],
1786 err
= func(kcontrol
, ucontrol
);
1789 mutex_unlock(&codec
->control_mutex
);
1793 static int alc_cap_vol_get(struct snd_kcontrol
*kcontrol
,
1794 struct snd_ctl_elem_value
*ucontrol
)
1796 return alc_cap_getput_caller(kcontrol
, ucontrol
,
1797 snd_hda_mixer_amp_volume_get
, false);
1800 static int alc_cap_vol_put(struct snd_kcontrol
*kcontrol
,
1801 struct snd_ctl_elem_value
*ucontrol
)
1803 return alc_cap_getput_caller(kcontrol
, ucontrol
,
1804 snd_hda_mixer_amp_volume_put
, true);
1807 /* capture mixer elements */
1808 #define alc_cap_sw_info snd_ctl_boolean_stereo_info
1810 static int alc_cap_sw_get(struct snd_kcontrol
*kcontrol
,
1811 struct snd_ctl_elem_value
*ucontrol
)
1813 return alc_cap_getput_caller(kcontrol
, ucontrol
,
1814 snd_hda_mixer_amp_switch_get
, false);
1817 static int alc_cap_sw_put(struct snd_kcontrol
*kcontrol
,
1818 struct snd_ctl_elem_value
*ucontrol
)
1820 return alc_cap_getput_caller(kcontrol
, ucontrol
,
1821 snd_hda_mixer_amp_switch_put
, true);
1824 #define _DEFINE_CAPMIX(num) \
1826 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1827 .name = "Capture Switch", \
1828 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1830 .info = alc_cap_sw_info, \
1831 .get = alc_cap_sw_get, \
1832 .put = alc_cap_sw_put, \
1835 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1836 .name = "Capture Volume", \
1837 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1838 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1839 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1841 .info = alc_cap_vol_info, \
1842 .get = alc_cap_vol_get, \
1843 .put = alc_cap_vol_put, \
1844 .tlv = { .c = alc_cap_vol_tlv }, \
1847 #define _DEFINE_CAPSRC(num) \
1849 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1850 /* .name = "Capture Source", */ \
1851 .name = "Input Source", \
1853 .info = alc_mux_enum_info, \
1854 .get = alc_mux_enum_get, \
1855 .put = alc_mux_enum_put, \
1858 #define DEFINE_CAPMIX(num) \
1859 static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
1860 _DEFINE_CAPMIX(num), \
1861 _DEFINE_CAPSRC(num), \
1865 #define DEFINE_CAPMIX_NOSRC(num) \
1866 static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
1867 _DEFINE_CAPMIX(num), \
1871 /* up to three ADCs */
1875 DEFINE_CAPMIX_NOSRC(1);
1876 DEFINE_CAPMIX_NOSRC(2);
1877 DEFINE_CAPMIX_NOSRC(3);
1880 * virtual master controls
1884 * slave controls for virtual master
1886 static const char * const alc_slave_pfxs
[] = {
1887 "Front", "Surround", "Center", "LFE", "Side",
1888 "Headphone", "Speaker", "Mono", "Line-Out",
1889 "CLFE", "Bass Speaker", "PCM",
1894 * build control elements
1897 #define NID_MAPPING (-1)
1899 #define SUBDEV_SPEAKER_ (0 << 6)
1900 #define SUBDEV_HP_ (1 << 6)
1901 #define SUBDEV_LINE_ (2 << 6)
1902 #define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1903 #define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1904 #define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1906 static void alc_free_kctls(struct hda_codec
*codec
);
1908 #ifdef CONFIG_SND_HDA_INPUT_BEEP
1909 /* additional beep mixers; the actual parameters are overwritten at build */
1910 static const struct snd_kcontrol_new alc_beep_mixer
[] = {
1911 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT
),
1912 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT
),
1917 static int __alc_build_controls(struct hda_codec
*codec
)
1919 struct alc_spec
*spec
= codec
->spec
;
1920 struct snd_kcontrol
*kctl
= NULL
;
1921 const struct snd_kcontrol_new
*knew
;
1926 for (i
= 0; i
< spec
->num_mixers
; i
++) {
1927 err
= snd_hda_add_new_ctls(codec
, spec
->mixers
[i
]);
1931 if (spec
->cap_mixer
) {
1932 err
= snd_hda_add_new_ctls(codec
, spec
->cap_mixer
);
1936 if (spec
->multiout
.dig_out_nid
) {
1937 err
= snd_hda_create_spdif_out_ctls(codec
,
1938 spec
->multiout
.dig_out_nid
,
1939 spec
->multiout
.dig_out_nid
);
1942 if (!spec
->no_analog
) {
1943 err
= snd_hda_create_spdif_share_sw(codec
,
1947 spec
->multiout
.share_spdif
= 1;
1950 if (spec
->dig_in_nid
) {
1951 err
= snd_hda_create_spdif_in_ctls(codec
, spec
->dig_in_nid
);
1956 #ifdef CONFIG_SND_HDA_INPUT_BEEP
1957 /* create beep controls if needed */
1958 if (spec
->beep_amp
) {
1959 const struct snd_kcontrol_new
*knew
;
1960 for (knew
= alc_beep_mixer
; knew
->name
; knew
++) {
1961 struct snd_kcontrol
*kctl
;
1962 kctl
= snd_ctl_new1(knew
, codec
);
1965 kctl
->private_value
= spec
->beep_amp
;
1966 err
= snd_hda_ctl_add(codec
, 0, kctl
);
1973 /* if we have no master control, let's create it */
1974 if (!spec
->no_analog
&&
1975 !snd_hda_find_mixer_ctl(codec
, "Master Playback Volume")) {
1976 unsigned int vmaster_tlv
[4];
1977 snd_hda_set_vmaster_tlv(codec
, spec
->vmaster_nid
,
1978 HDA_OUTPUT
, vmaster_tlv
);
1979 err
= snd_hda_add_vmaster(codec
, "Master Playback Volume",
1980 vmaster_tlv
, alc_slave_pfxs
,
1985 if (!spec
->no_analog
&&
1986 !snd_hda_find_mixer_ctl(codec
, "Master Playback Switch")) {
1987 err
= snd_hda_add_vmaster(codec
, "Master Playback Switch",
1988 NULL
, alc_slave_pfxs
,
1994 /* assign Capture Source enums to NID */
1995 if (spec
->capsrc_nids
|| spec
->adc_nids
) {
1996 kctl
= snd_hda_find_mixer_ctl(codec
, "Capture Source");
1998 kctl
= snd_hda_find_mixer_ctl(codec
, "Input Source");
1999 for (i
= 0; kctl
&& i
< kctl
->count
; i
++) {
2000 err
= snd_hda_add_nid(codec
, kctl
, i
,
2001 get_capsrc(spec
, i
));
2006 if (spec
->cap_mixer
&& spec
->adc_nids
) {
2007 const char *kname
= kctl
? kctl
->id
.name
: NULL
;
2008 for (knew
= spec
->cap_mixer
; knew
->name
; knew
++) {
2009 if (kname
&& strcmp(knew
->name
, kname
) == 0)
2011 kctl
= snd_hda_find_mixer_ctl(codec
, knew
->name
);
2012 for (i
= 0; kctl
&& i
< kctl
->count
; i
++) {
2013 err
= snd_hda_add_nid(codec
, kctl
, i
,
2021 /* other nid->control mapping */
2022 for (i
= 0; i
< spec
->num_mixers
; i
++) {
2023 for (knew
= spec
->mixers
[i
]; knew
->name
; knew
++) {
2024 if (knew
->iface
!= NID_MAPPING
)
2026 kctl
= snd_hda_find_mixer_ctl(codec
, knew
->name
);
2029 u
= knew
->subdevice
;
2030 for (j
= 0; j
< 4; j
++, u
>>= 8) {
2035 case SUBDEV_SPEAKER_
:
2036 nid
= spec
->autocfg
.speaker_pins
[nid
];
2039 nid
= spec
->autocfg
.line_out_pins
[nid
];
2042 nid
= spec
->autocfg
.hp_pins
[nid
];
2047 err
= snd_hda_add_nid(codec
, kctl
, 0, nid
);
2051 u
= knew
->private_value
;
2052 for (j
= 0; j
< 4; j
++, u
>>= 8) {
2056 err
= snd_hda_add_nid(codec
, kctl
, 0, nid
);
2063 alc_free_kctls(codec
); /* no longer needed */
2068 static int alc_build_controls(struct hda_codec
*codec
)
2070 struct alc_spec
*spec
= codec
->spec
;
2071 int err
= __alc_build_controls(codec
);
2074 return snd_hda_jack_add_kctls(codec
, &spec
->autocfg
);
2082 static void alc_init_special_input_src(struct hda_codec
*codec
);
2084 static int alc_init(struct hda_codec
*codec
)
2086 struct alc_spec
*spec
= codec
->spec
;
2090 alc_auto_init_amp(codec
, spec
->init_amp
);
2092 for (i
= 0; i
< spec
->num_init_verbs
; i
++)
2093 snd_hda_sequence_write(codec
, spec
->init_verbs
[i
]);
2094 alc_init_special_input_src(codec
);
2096 if (spec
->init_hook
)
2097 spec
->init_hook(codec
);
2099 alc_apply_fixup(codec
, ALC_FIXUP_ACT_INIT
);
2101 snd_hda_jack_report_sync(codec
);
2103 hda_call_check_power_status(codec
, 0x01);
2107 static void alc_unsol_event(struct hda_codec
*codec
, unsigned int res
)
2109 struct alc_spec
*spec
= codec
->spec
;
2111 if (spec
->unsol_event
)
2112 spec
->unsol_event(codec
, res
);
2115 #ifdef CONFIG_SND_HDA_POWER_SAVE
2116 static int alc_check_power_status(struct hda_codec
*codec
, hda_nid_t nid
)
2118 struct alc_spec
*spec
= codec
->spec
;
2119 return snd_hda_check_amp_list_power(codec
, &spec
->loopback
, nid
);
2124 * Analog playback callbacks
2126 static int alc_playback_pcm_open(struct hda_pcm_stream
*hinfo
,
2127 struct hda_codec
*codec
,
2128 struct snd_pcm_substream
*substream
)
2130 struct alc_spec
*spec
= codec
->spec
;
2131 return snd_hda_multi_out_analog_open(codec
, &spec
->multiout
, substream
,
2135 static int alc_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
2136 struct hda_codec
*codec
,
2137 unsigned int stream_tag
,
2138 unsigned int format
,
2139 struct snd_pcm_substream
*substream
)
2141 struct alc_spec
*spec
= codec
->spec
;
2142 return snd_hda_multi_out_analog_prepare(codec
, &spec
->multiout
,
2143 stream_tag
, format
, substream
);
2146 static int alc_playback_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
2147 struct hda_codec
*codec
,
2148 struct snd_pcm_substream
*substream
)
2150 struct alc_spec
*spec
= codec
->spec
;
2151 return snd_hda_multi_out_analog_cleanup(codec
, &spec
->multiout
);
2157 static int alc_dig_playback_pcm_open(struct hda_pcm_stream
*hinfo
,
2158 struct hda_codec
*codec
,
2159 struct snd_pcm_substream
*substream
)
2161 struct alc_spec
*spec
= codec
->spec
;
2162 return snd_hda_multi_out_dig_open(codec
, &spec
->multiout
);
2165 static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
2166 struct hda_codec
*codec
,
2167 unsigned int stream_tag
,
2168 unsigned int format
,
2169 struct snd_pcm_substream
*substream
)
2171 struct alc_spec
*spec
= codec
->spec
;
2172 return snd_hda_multi_out_dig_prepare(codec
, &spec
->multiout
,
2173 stream_tag
, format
, substream
);
2176 static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
2177 struct hda_codec
*codec
,
2178 struct snd_pcm_substream
*substream
)
2180 struct alc_spec
*spec
= codec
->spec
;
2181 return snd_hda_multi_out_dig_cleanup(codec
, &spec
->multiout
);
2184 static int alc_dig_playback_pcm_close(struct hda_pcm_stream
*hinfo
,
2185 struct hda_codec
*codec
,
2186 struct snd_pcm_substream
*substream
)
2188 struct alc_spec
*spec
= codec
->spec
;
2189 return snd_hda_multi_out_dig_close(codec
, &spec
->multiout
);
2195 static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream
*hinfo
,
2196 struct hda_codec
*codec
,
2197 unsigned int stream_tag
,
2198 unsigned int format
,
2199 struct snd_pcm_substream
*substream
)
2201 struct alc_spec
*spec
= codec
->spec
;
2203 snd_hda_codec_setup_stream(codec
, spec
->adc_nids
[substream
->number
+ 1],
2204 stream_tag
, 0, format
);
2208 static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
2209 struct hda_codec
*codec
,
2210 struct snd_pcm_substream
*substream
)
2212 struct alc_spec
*spec
= codec
->spec
;
2214 snd_hda_codec_cleanup_stream(codec
,
2215 spec
->adc_nids
[substream
->number
+ 1]);
2219 /* analog capture with dynamic dual-adc changes */
2220 static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream
*hinfo
,
2221 struct hda_codec
*codec
,
2222 unsigned int stream_tag
,
2223 unsigned int format
,
2224 struct snd_pcm_substream
*substream
)
2226 struct alc_spec
*spec
= codec
->spec
;
2227 spec
->cur_adc
= spec
->adc_nids
[spec
->dyn_adc_idx
[spec
->cur_mux
[0]]];
2228 spec
->cur_adc_stream_tag
= stream_tag
;
2229 spec
->cur_adc_format
= format
;
2230 snd_hda_codec_setup_stream(codec
, spec
->cur_adc
, stream_tag
, 0, format
);
2234 static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
2235 struct hda_codec
*codec
,
2236 struct snd_pcm_substream
*substream
)
2238 struct alc_spec
*spec
= codec
->spec
;
2239 snd_hda_codec_cleanup_stream(codec
, spec
->cur_adc
);
2244 static const struct hda_pcm_stream dyn_adc_pcm_analog_capture
= {
2248 .nid
= 0, /* fill later */
2250 .prepare
= dyn_adc_capture_pcm_prepare
,
2251 .cleanup
= dyn_adc_capture_pcm_cleanup
2257 static const struct hda_pcm_stream alc_pcm_analog_playback
= {
2261 /* NID is set in alc_build_pcms */
2263 .open
= alc_playback_pcm_open
,
2264 .prepare
= alc_playback_pcm_prepare
,
2265 .cleanup
= alc_playback_pcm_cleanup
2269 static const struct hda_pcm_stream alc_pcm_analog_capture
= {
2273 /* NID is set in alc_build_pcms */
2276 static const struct hda_pcm_stream alc_pcm_analog_alt_playback
= {
2280 /* NID is set in alc_build_pcms */
2283 static const struct hda_pcm_stream alc_pcm_analog_alt_capture
= {
2284 .substreams
= 2, /* can be overridden */
2287 /* NID is set in alc_build_pcms */
2289 .prepare
= alc_alt_capture_pcm_prepare
,
2290 .cleanup
= alc_alt_capture_pcm_cleanup
2294 static const struct hda_pcm_stream alc_pcm_digital_playback
= {
2298 /* NID is set in alc_build_pcms */
2300 .open
= alc_dig_playback_pcm_open
,
2301 .close
= alc_dig_playback_pcm_close
,
2302 .prepare
= alc_dig_playback_pcm_prepare
,
2303 .cleanup
= alc_dig_playback_pcm_cleanup
2307 static const struct hda_pcm_stream alc_pcm_digital_capture
= {
2311 /* NID is set in alc_build_pcms */
2314 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
2315 static const struct hda_pcm_stream alc_pcm_null_stream
= {
2321 static int alc_build_pcms(struct hda_codec
*codec
)
2323 struct alc_spec
*spec
= codec
->spec
;
2324 struct hda_pcm
*info
= spec
->pcm_rec
;
2325 const struct hda_pcm_stream
*p
;
2326 bool have_multi_adcs
;
2329 codec
->num_pcms
= 1;
2330 codec
->pcm_info
= info
;
2332 if (spec
->no_analog
)
2335 snprintf(spec
->stream_name_analog
, sizeof(spec
->stream_name_analog
),
2336 "%s Analog", codec
->chip_name
);
2337 info
->name
= spec
->stream_name_analog
;
2339 if (spec
->multiout
.num_dacs
> 0) {
2340 p
= spec
->stream_analog_playback
;
2342 p
= &alc_pcm_analog_playback
;
2343 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] = *p
;
2344 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
= spec
->multiout
.dac_nids
[0];
2346 if (spec
->adc_nids
) {
2347 p
= spec
->stream_analog_capture
;
2349 if (spec
->dyn_adc_switch
)
2350 p
= &dyn_adc_pcm_analog_capture
;
2352 p
= &alc_pcm_analog_capture
;
2354 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] = *p
;
2355 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
= spec
->adc_nids
[0];
2358 if (spec
->channel_mode
) {
2359 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].channels_max
= 0;
2360 for (i
= 0; i
< spec
->num_channel_mode
; i
++) {
2361 if (spec
->channel_mode
[i
].channels
> info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].channels_max
) {
2362 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].channels_max
= spec
->channel_mode
[i
].channels
;
2368 /* SPDIF for stream index #1 */
2369 if (spec
->multiout
.dig_out_nid
|| spec
->dig_in_nid
) {
2370 snprintf(spec
->stream_name_digital
,
2371 sizeof(spec
->stream_name_digital
),
2372 "%s Digital", codec
->chip_name
);
2373 codec
->num_pcms
= 2;
2374 codec
->slave_dig_outs
= spec
->multiout
.slave_dig_outs
;
2375 info
= spec
->pcm_rec
+ 1;
2376 info
->name
= spec
->stream_name_digital
;
2377 if (spec
->dig_out_type
)
2378 info
->pcm_type
= spec
->dig_out_type
;
2380 info
->pcm_type
= HDA_PCM_TYPE_SPDIF
;
2381 if (spec
->multiout
.dig_out_nid
) {
2382 p
= spec
->stream_digital_playback
;
2384 p
= &alc_pcm_digital_playback
;
2385 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] = *p
;
2386 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
= spec
->multiout
.dig_out_nid
;
2388 if (spec
->dig_in_nid
) {
2389 p
= spec
->stream_digital_capture
;
2391 p
= &alc_pcm_digital_capture
;
2392 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] = *p
;
2393 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
= spec
->dig_in_nid
;
2395 /* FIXME: do we need this for all Realtek codec models? */
2396 codec
->spdif_status_reset
= 1;
2399 if (spec
->no_analog
)
2402 /* If the use of more than one ADC is requested for the current
2403 * model, configure a second analog capture-only PCM.
2405 have_multi_adcs
= (spec
->num_adc_nids
> 1) &&
2406 !spec
->dyn_adc_switch
&& !spec
->auto_mic
&&
2407 (!spec
->input_mux
|| spec
->input_mux
->num_items
> 1);
2408 /* Additional Analaog capture for index #2 */
2409 if (spec
->alt_dac_nid
|| have_multi_adcs
) {
2410 codec
->num_pcms
= 3;
2411 info
= spec
->pcm_rec
+ 2;
2412 info
->name
= spec
->stream_name_analog
;
2413 if (spec
->alt_dac_nid
) {
2414 p
= spec
->stream_analog_alt_playback
;
2416 p
= &alc_pcm_analog_alt_playback
;
2417 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] = *p
;
2418 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
=
2421 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] =
2422 alc_pcm_null_stream
;
2423 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
= 0;
2425 if (have_multi_adcs
) {
2426 p
= spec
->stream_analog_alt_capture
;
2428 p
= &alc_pcm_analog_alt_capture
;
2429 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] = *p
;
2430 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
=
2432 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].substreams
=
2433 spec
->num_adc_nids
- 1;
2435 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] =
2436 alc_pcm_null_stream
;
2437 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
= 0;
2444 static inline void alc_shutup(struct hda_codec
*codec
)
2446 struct alc_spec
*spec
= codec
->spec
;
2448 if (spec
&& spec
->shutup
)
2449 spec
->shutup(codec
);
2450 snd_hda_shutup_pins(codec
);
2453 static void alc_free_kctls(struct hda_codec
*codec
)
2455 struct alc_spec
*spec
= codec
->spec
;
2457 if (spec
->kctls
.list
) {
2458 struct snd_kcontrol_new
*kctl
= spec
->kctls
.list
;
2460 for (i
= 0; i
< spec
->kctls
.used
; i
++)
2461 kfree(kctl
[i
].name
);
2463 snd_array_free(&spec
->kctls
);
2466 static void alc_free_bind_ctls(struct hda_codec
*codec
)
2468 struct alc_spec
*spec
= codec
->spec
;
2469 if (spec
->bind_ctls
.list
) {
2470 struct hda_bind_ctls
**ctl
= spec
->bind_ctls
.list
;
2472 for (i
= 0; i
< spec
->bind_ctls
.used
; i
++)
2475 snd_array_free(&spec
->bind_ctls
);
2478 static void alc_free(struct hda_codec
*codec
)
2480 struct alc_spec
*spec
= codec
->spec
;
2486 alc_free_kctls(codec
);
2487 alc_free_bind_ctls(codec
);
2489 snd_hda_detach_beep_device(codec
);
2492 #ifdef CONFIG_SND_HDA_POWER_SAVE
2493 static void alc_power_eapd(struct hda_codec
*codec
)
2495 alc_auto_setup_eapd(codec
, false);
2498 static int alc_suspend(struct hda_codec
*codec
, pm_message_t state
)
2500 struct alc_spec
*spec
= codec
->spec
;
2502 if (spec
&& spec
->power_hook
)
2503 spec
->power_hook(codec
);
2509 static int alc_resume(struct hda_codec
*codec
)
2511 msleep(150); /* to avoid pop noise */
2512 codec
->patch_ops
.init(codec
);
2513 snd_hda_codec_resume_amp(codec
);
2514 snd_hda_codec_resume_cache(codec
);
2515 hda_call_check_power_status(codec
, 0x01);
2522 static const struct hda_codec_ops alc_patch_ops
= {
2523 .build_controls
= alc_build_controls
,
2524 .build_pcms
= alc_build_pcms
,
2527 .unsol_event
= alc_unsol_event
,
2529 .resume
= alc_resume
,
2531 #ifdef CONFIG_SND_HDA_POWER_SAVE
2532 .suspend
= alc_suspend
,
2533 .check_power_status
= alc_check_power_status
,
2535 .reboot_notify
= alc_shutup
,
2538 /* replace the codec chip_name with the given string */
2539 static int alc_codec_rename(struct hda_codec
*codec
, const char *name
)
2541 kfree(codec
->chip_name
);
2542 codec
->chip_name
= kstrdup(name
, GFP_KERNEL
);
2543 if (!codec
->chip_name
) {
2551 * Rename codecs appropriately from COEF value
2553 struct alc_codec_rename_table
{
2554 unsigned int vendor_id
;
2555 unsigned short coef_mask
;
2556 unsigned short coef_bits
;
2560 static struct alc_codec_rename_table rename_tbl
[] = {
2561 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2562 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2563 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2564 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2565 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2566 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2567 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
2568 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2569 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2570 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2571 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2572 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2573 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2574 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2575 { } /* terminator */
2578 static int alc_codec_rename_from_preset(struct hda_codec
*codec
)
2580 const struct alc_codec_rename_table
*p
;
2582 for (p
= rename_tbl
; p
->vendor_id
; p
++) {
2583 if (p
->vendor_id
!= codec
->vendor_id
)
2585 if ((alc_get_coef0(codec
) & p
->coef_mask
) == p
->coef_bits
)
2586 return alc_codec_rename(codec
, p
->name
);
2592 * Automatic parse of I/O pins from the BIOS configuration
2597 ALC_CTL_WIDGET_MUTE
,
2602 static const struct snd_kcontrol_new alc_control_templates
[] = {
2603 HDA_CODEC_VOLUME(NULL
, 0, 0, 0),
2604 HDA_CODEC_MUTE(NULL
, 0, 0, 0),
2605 HDA_BIND_MUTE(NULL
, 0, 0, 0),
2606 HDA_BIND_VOL(NULL
, 0),
2607 HDA_BIND_SW(NULL
, 0),
2610 /* add dynamic controls */
2611 static int add_control(struct alc_spec
*spec
, int type
, const char *name
,
2612 int cidx
, unsigned long val
)
2614 struct snd_kcontrol_new
*knew
;
2616 knew
= alc_kcontrol_new(spec
);
2619 *knew
= alc_control_templates
[type
];
2620 knew
->name
= kstrdup(name
, GFP_KERNEL
);
2624 if (get_amp_nid_(val
))
2625 knew
->subdevice
= HDA_SUBDEV_AMP_FLAG
;
2626 knew
->private_value
= val
;
2630 static int add_control_with_pfx(struct alc_spec
*spec
, int type
,
2631 const char *pfx
, const char *dir
,
2632 const char *sfx
, int cidx
, unsigned long val
)
2635 snprintf(name
, sizeof(name
), "%s %s %s", pfx
, dir
, sfx
);
2636 return add_control(spec
, type
, name
, cidx
, val
);
2639 #define add_pb_vol_ctrl(spec, type, pfx, val) \
2640 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2641 #define add_pb_sw_ctrl(spec, type, pfx, val) \
2642 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2643 #define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2644 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2645 #define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2646 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
2648 static const char * const channel_name
[4] = {
2649 "Front", "Surround", "CLFE", "Side"
2652 static const char *alc_get_line_out_pfx(struct alc_spec
*spec
, int ch
,
2653 bool can_be_master
, int *index
)
2655 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
2658 if (cfg
->line_outs
== 1 && !spec
->multi_ios
&&
2659 !cfg
->hp_outs
&& !cfg
->speaker_outs
&& can_be_master
)
2662 switch (cfg
->line_out_type
) {
2663 case AUTO_PIN_SPEAKER_OUT
:
2664 if (cfg
->line_outs
== 1)
2666 if (cfg
->line_outs
== 2)
2667 return ch
? "Bass Speaker" : "Speaker";
2669 case AUTO_PIN_HP_OUT
:
2670 /* for multi-io case, only the primary out */
2671 if (ch
&& spec
->multi_ios
)
2676 if (cfg
->line_outs
== 1 && !spec
->multi_ios
)
2680 if (snd_BUG_ON(ch
>= ARRAY_SIZE(channel_name
)))
2683 return channel_name
[ch
];
2686 /* create input playback/capture controls for the given pin */
2687 static int new_analog_input(struct alc_spec
*spec
, hda_nid_t pin
,
2688 const char *ctlname
, int ctlidx
,
2689 int idx
, hda_nid_t mix_nid
)
2693 err
= __add_pb_vol_ctrl(spec
, ALC_CTL_WIDGET_VOL
, ctlname
, ctlidx
,
2694 HDA_COMPOSE_AMP_VAL(mix_nid
, 3, idx
, HDA_INPUT
));
2697 err
= __add_pb_sw_ctrl(spec
, ALC_CTL_WIDGET_MUTE
, ctlname
, ctlidx
,
2698 HDA_COMPOSE_AMP_VAL(mix_nid
, 3, idx
, HDA_INPUT
));
2704 static int alc_is_input_pin(struct hda_codec
*codec
, hda_nid_t nid
)
2706 unsigned int pincap
= snd_hda_query_pin_caps(codec
, nid
);
2707 return (pincap
& AC_PINCAP_IN
) != 0;
2710 /* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
2711 static int alc_auto_fill_adc_caps(struct hda_codec
*codec
)
2713 struct alc_spec
*spec
= codec
->spec
;
2715 hda_nid_t
*adc_nids
= spec
->private_adc_nids
;
2716 hda_nid_t
*cap_nids
= spec
->private_capsrc_nids
;
2717 int max_nums
= ARRAY_SIZE(spec
->private_adc_nids
);
2720 if (spec
->shared_mic_hp
)
2721 max_nums
= 1; /* no multi streams with the shared HP/mic */
2723 nid
= codec
->start_nid
;
2724 for (i
= 0; i
< codec
->num_nodes
; i
++, nid
++) {
2726 const hda_nid_t
*list
;
2727 unsigned int caps
= get_wcaps(codec
, nid
);
2728 int type
= get_wcaps_type(caps
);
2730 if (type
!= AC_WID_AUD_IN
|| (caps
& AC_WCAP_DIGITAL
))
2732 adc_nids
[nums
] = nid
;
2733 cap_nids
[nums
] = nid
;
2737 type
= get_wcaps_type(get_wcaps(codec
, src
));
2738 if (type
== AC_WID_PIN
)
2740 if (type
== AC_WID_AUD_SEL
) {
2741 cap_nids
[nums
] = src
;
2744 n
= snd_hda_get_conn_list(codec
, src
, &list
);
2746 cap_nids
[nums
] = src
;
2752 if (++nums
>= max_nums
)
2755 spec
->adc_nids
= spec
->private_adc_nids
;
2756 spec
->capsrc_nids
= spec
->private_capsrc_nids
;
2757 spec
->num_adc_nids
= nums
;
2761 /* create playback/capture controls for input pins */
2762 static int alc_auto_create_input_ctls(struct hda_codec
*codec
)
2764 struct alc_spec
*spec
= codec
->spec
;
2765 const struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
2766 hda_nid_t mixer
= spec
->mixer_nid
;
2767 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
2769 int i
, c
, err
, idx
, type_idx
= 0;
2770 const char *prev_label
= NULL
;
2772 num_adcs
= alc_auto_fill_adc_caps(codec
);
2776 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
2780 pin
= cfg
->inputs
[i
].pin
;
2781 if (!alc_is_input_pin(codec
, pin
))
2784 label
= hda_get_autocfg_input_label(codec
, cfg
, i
);
2785 if (spec
->shared_mic_hp
&& !strcmp(label
, "Misc"))
2786 label
= "Headphone Mic";
2787 if (prev_label
&& !strcmp(label
, prev_label
))
2794 idx
= get_connection_index(codec
, mixer
, pin
);
2796 err
= new_analog_input(spec
, pin
,
2804 for (c
= 0; c
< num_adcs
; c
++) {
2805 hda_nid_t cap
= get_capsrc(spec
, c
);
2806 idx
= get_connection_index(codec
, cap
, pin
);
2808 spec
->imux_pins
[imux
->num_items
] = pin
;
2809 snd_hda_add_imux_item(imux
, label
, idx
, NULL
);
2815 spec
->num_mux_defs
= 1;
2816 spec
->input_mux
= imux
;
2821 /* create a shared input with the headphone out */
2822 static int alc_auto_create_shared_input(struct hda_codec
*codec
)
2824 struct alc_spec
*spec
= codec
->spec
;
2825 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
2826 unsigned int defcfg
;
2829 /* only one internal input pin? */
2830 if (cfg
->num_inputs
!= 1)
2832 defcfg
= snd_hda_codec_get_pincfg(codec
, cfg
->inputs
[0].pin
);
2833 if (snd_hda_get_input_pin_attr(defcfg
) != INPUT_PIN_ATTR_INT
)
2836 if (cfg
->hp_outs
== 1 && cfg
->line_out_type
== AUTO_PIN_SPEAKER_OUT
)
2837 nid
= cfg
->hp_pins
[0]; /* OK, we have a single HP-out */
2838 else if (cfg
->line_outs
== 1 && cfg
->line_out_type
== AUTO_PIN_HP_OUT
)
2839 nid
= cfg
->line_out_pins
[0]; /* OK, we have a single line-out */
2841 return 0; /* both not available */
2843 if (!(snd_hda_query_pin_caps(codec
, nid
) & AC_PINCAP_IN
))
2844 return 0; /* no input */
2846 cfg
->inputs
[1].pin
= nid
;
2847 cfg
->inputs
[1].type
= AUTO_PIN_MIC
;
2848 cfg
->num_inputs
= 2;
2849 spec
->shared_mic_hp
= 1;
2850 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid
);
2854 static void alc_set_pin_output(struct hda_codec
*codec
, hda_nid_t nid
,
2855 unsigned int pin_type
)
2857 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_PIN_WIDGET_CONTROL
,
2860 if (nid_has_mute(codec
, nid
, HDA_OUTPUT
))
2861 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
2865 static int get_pin_type(int line_out_type
)
2867 if (line_out_type
== AUTO_PIN_HP_OUT
)
2873 static void alc_auto_init_analog_input(struct hda_codec
*codec
)
2875 struct alc_spec
*spec
= codec
->spec
;
2876 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
2879 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
2880 hda_nid_t nid
= cfg
->inputs
[i
].pin
;
2881 if (alc_is_input_pin(codec
, nid
)) {
2882 alc_set_input_pin(codec
, nid
, cfg
->inputs
[i
].type
);
2883 if (get_wcaps(codec
, nid
) & AC_WCAP_OUT_AMP
)
2884 snd_hda_codec_write(codec
, nid
, 0,
2885 AC_VERB_SET_AMP_GAIN_MUTE
,
2890 /* mute all loopback inputs */
2891 if (spec
->mixer_nid
) {
2892 int nums
= snd_hda_get_conn_list(codec
, spec
->mixer_nid
, NULL
);
2893 for (i
= 0; i
< nums
; i
++)
2894 snd_hda_codec_write(codec
, spec
->mixer_nid
, 0,
2895 AC_VERB_SET_AMP_GAIN_MUTE
,
2900 /* convert from MIX nid to DAC */
2901 static hda_nid_t
alc_auto_mix_to_dac(struct hda_codec
*codec
, hda_nid_t nid
)
2906 if (get_wcaps_type(get_wcaps(codec
, nid
)) == AC_WID_AUD_OUT
)
2908 num
= snd_hda_get_connections(codec
, nid
, list
, ARRAY_SIZE(list
));
2909 for (i
= 0; i
< num
; i
++) {
2910 if (get_wcaps_type(get_wcaps(codec
, list
[i
])) == AC_WID_AUD_OUT
)
2916 /* go down to the selector widget before the mixer */
2917 static hda_nid_t
alc_go_down_to_selector(struct hda_codec
*codec
, hda_nid_t pin
)
2920 int num
= snd_hda_get_connections(codec
, pin
, srcs
,
2923 get_wcaps_type(get_wcaps(codec
, srcs
[0])) != AC_WID_AUD_SEL
)
2928 /* get MIX nid connected to the given pin targeted to DAC */
2929 static hda_nid_t
alc_auto_dac_to_mix(struct hda_codec
*codec
, hda_nid_t pin
,
2935 pin
= alc_go_down_to_selector(codec
, pin
);
2936 num
= snd_hda_get_connections(codec
, pin
, mix
, ARRAY_SIZE(mix
));
2937 for (i
= 0; i
< num
; i
++) {
2938 if (alc_auto_mix_to_dac(codec
, mix
[i
]) == dac
)
2944 /* select the connection from pin to DAC if needed */
2945 static int alc_auto_select_dac(struct hda_codec
*codec
, hda_nid_t pin
,
2951 pin
= alc_go_down_to_selector(codec
, pin
);
2952 num
= snd_hda_get_connections(codec
, pin
, mix
, ARRAY_SIZE(mix
));
2955 for (i
= 0; i
< num
; i
++) {
2956 if (alc_auto_mix_to_dac(codec
, mix
[i
]) == dac
) {
2957 snd_hda_codec_update_cache(codec
, pin
, 0,
2958 AC_VERB_SET_CONNECT_SEL
, i
);
2965 static bool alc_is_dac_already_used(struct hda_codec
*codec
, hda_nid_t nid
)
2967 struct alc_spec
*spec
= codec
->spec
;
2969 if (found_in_nid_list(nid
, spec
->multiout
.dac_nids
,
2970 ARRAY_SIZE(spec
->private_dac_nids
)) ||
2971 found_in_nid_list(nid
, spec
->multiout
.hp_out_nid
,
2972 ARRAY_SIZE(spec
->multiout
.hp_out_nid
)) ||
2973 found_in_nid_list(nid
, spec
->multiout
.extra_out_nid
,
2974 ARRAY_SIZE(spec
->multiout
.extra_out_nid
)))
2976 for (i
= 0; i
< spec
->multi_ios
; i
++) {
2977 if (spec
->multi_io
[i
].dac
== nid
)
2983 /* look for an empty DAC slot */
2984 static hda_nid_t
alc_auto_look_for_dac(struct hda_codec
*codec
, hda_nid_t pin
)
2989 pin
= alc_go_down_to_selector(codec
, pin
);
2990 num
= snd_hda_get_connections(codec
, pin
, srcs
, ARRAY_SIZE(srcs
));
2991 for (i
= 0; i
< num
; i
++) {
2992 hda_nid_t nid
= alc_auto_mix_to_dac(codec
, srcs
[i
]);
2995 if (!alc_is_dac_already_used(codec
, nid
))
3001 /* check whether the DAC is reachable from the pin */
3002 static bool alc_auto_is_dac_reachable(struct hda_codec
*codec
,
3003 hda_nid_t pin
, hda_nid_t dac
)
3010 pin
= alc_go_down_to_selector(codec
, pin
);
3011 num
= snd_hda_get_connections(codec
, pin
, srcs
, ARRAY_SIZE(srcs
));
3012 for (i
= 0; i
< num
; i
++) {
3013 hda_nid_t nid
= alc_auto_mix_to_dac(codec
, srcs
[i
]);
3020 static hda_nid_t
get_dac_if_single(struct hda_codec
*codec
, hda_nid_t pin
)
3022 struct alc_spec
*spec
= codec
->spec
;
3023 hda_nid_t sel
= alc_go_down_to_selector(codec
, pin
);
3024 hda_nid_t nid
, nid_found
, srcs
[5];
3025 int i
, num
= snd_hda_get_connections(codec
, sel
, srcs
,
3028 return alc_auto_look_for_dac(codec
, pin
);
3030 for (i
= 0; i
< num
; i
++) {
3031 if (srcs
[i
] == spec
->mixer_nid
)
3033 nid
= alc_auto_mix_to_dac(codec
, srcs
[i
]);
3034 if (nid
&& !alc_is_dac_already_used(codec
, nid
)) {
3043 /* mark up volume and mute control NIDs: used during badness parsing and
3044 * at creating actual controls
3046 static inline unsigned int get_ctl_pos(unsigned int data
)
3048 hda_nid_t nid
= get_amp_nid_(data
);
3050 if (snd_BUG_ON(nid
>= MAX_VOL_NIDS
))
3052 dir
= get_amp_direction_(data
);
3053 return (nid
<< 1) | dir
;
3056 #define is_ctl_used(bits, data) \
3057 test_bit(get_ctl_pos(data), bits)
3058 #define mark_ctl_usage(bits, data) \
3059 set_bit(get_ctl_pos(data), bits)
3061 static void clear_vol_marks(struct hda_codec
*codec
)
3063 struct alc_spec
*spec
= codec
->spec
;
3064 memset(spec
->vol_ctls
, 0, sizeof(spec
->vol_ctls
));
3065 memset(spec
->sw_ctls
, 0, sizeof(spec
->sw_ctls
));
3068 /* badness definition */
3070 /* No primary DAC is found for the main output */
3071 BAD_NO_PRIMARY_DAC
= 0x10000,
3072 /* No DAC is found for the extra output */
3073 BAD_NO_DAC
= 0x4000,
3074 /* No possible multi-ios */
3075 BAD_MULTI_IO
= 0x103,
3076 /* No individual DAC for extra output */
3077 BAD_NO_EXTRA_DAC
= 0x102,
3078 /* No individual DAC for extra surrounds */
3079 BAD_NO_EXTRA_SURR_DAC
= 0x101,
3080 /* Primary DAC shared with main surrounds */
3081 BAD_SHARED_SURROUND
= 0x100,
3082 /* Primary DAC shared with main CLFE */
3083 BAD_SHARED_CLFE
= 0x10,
3084 /* Primary DAC shared with extra surrounds */
3085 BAD_SHARED_EXTRA_SURROUND
= 0x10,
3086 /* Volume widget is shared */
3087 BAD_SHARED_VOL
= 0x10,
3090 static hda_nid_t
alc_look_for_out_mute_nid(struct hda_codec
*codec
,
3091 hda_nid_t pin
, hda_nid_t dac
);
3092 static hda_nid_t
alc_look_for_out_vol_nid(struct hda_codec
*codec
,
3093 hda_nid_t pin
, hda_nid_t dac
);
3095 static int eval_shared_vol_badness(struct hda_codec
*codec
, hda_nid_t pin
,
3098 struct alc_spec
*spec
= codec
->spec
;
3103 nid
= alc_look_for_out_vol_nid(codec
, pin
, dac
);
3105 val
= HDA_COMPOSE_AMP_VAL(nid
, 3, 0, HDA_OUTPUT
);
3106 if (is_ctl_used(spec
->vol_ctls
, nid
))
3107 badness
+= BAD_SHARED_VOL
;
3109 mark_ctl_usage(spec
->vol_ctls
, val
);
3111 badness
+= BAD_SHARED_VOL
;
3112 nid
= alc_look_for_out_mute_nid(codec
, pin
, dac
);
3114 unsigned int wid_type
= get_wcaps_type(get_wcaps(codec
, nid
));
3115 if (wid_type
== AC_WID_PIN
|| wid_type
== AC_WID_AUD_OUT
)
3116 val
= HDA_COMPOSE_AMP_VAL(nid
, 3, 0, HDA_OUTPUT
);
3118 val
= HDA_COMPOSE_AMP_VAL(nid
, 3, 0, HDA_INPUT
);
3119 if (is_ctl_used(spec
->sw_ctls
, val
))
3120 badness
+= BAD_SHARED_VOL
;
3122 mark_ctl_usage(spec
->sw_ctls
, val
);
3124 badness
+= BAD_SHARED_VOL
;
3128 struct badness_table
{
3129 int no_primary_dac
; /* no primary DAC */
3130 int no_dac
; /* no secondary DACs */
3131 int shared_primary
; /* primary DAC is shared with main output */
3132 int shared_surr
; /* secondary DAC shared with main or primary */
3133 int shared_clfe
; /* third DAC shared with main or primary */
3134 int shared_surr_main
; /* secondary DAC sahred with main/DAC0 */
3137 static struct badness_table main_out_badness
= {
3138 .no_primary_dac
= BAD_NO_PRIMARY_DAC
,
3139 .no_dac
= BAD_NO_DAC
,
3140 .shared_primary
= BAD_NO_PRIMARY_DAC
,
3141 .shared_surr
= BAD_SHARED_SURROUND
,
3142 .shared_clfe
= BAD_SHARED_CLFE
,
3143 .shared_surr_main
= BAD_SHARED_SURROUND
,
3146 static struct badness_table extra_out_badness
= {
3147 .no_primary_dac
= BAD_NO_DAC
,
3148 .no_dac
= BAD_NO_DAC
,
3149 .shared_primary
= BAD_NO_EXTRA_DAC
,
3150 .shared_surr
= BAD_SHARED_EXTRA_SURROUND
,
3151 .shared_clfe
= BAD_SHARED_EXTRA_SURROUND
,
3152 .shared_surr_main
= BAD_NO_EXTRA_SURR_DAC
,
3155 /* try to assign DACs to pins and return the resultant badness */
3156 static int alc_auto_fill_dacs(struct hda_codec
*codec
, int num_outs
,
3157 const hda_nid_t
*pins
, hda_nid_t
*dacs
,
3158 const struct badness_table
*bad
)
3160 struct alc_spec
*spec
= codec
->spec
;
3161 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
3169 for (i
= 0; i
< num_outs
; i
++) {
3170 hda_nid_t pin
= pins
[i
];
3172 dacs
[i
] = alc_auto_look_for_dac(codec
, pin
);
3173 if (!dacs
[i
] && !i
) {
3174 for (j
= 1; j
< num_outs
; j
++) {
3175 if (alc_auto_is_dac_reachable(codec
, pin
, dacs
[j
])) {
3184 if (alc_auto_is_dac_reachable(codec
, pin
, dacs
[0]))
3186 else if (cfg
->line_outs
> i
&&
3187 alc_auto_is_dac_reachable(codec
, pin
,
3188 spec
->private_dac_nids
[i
]))
3189 dac
= spec
->private_dac_nids
[i
];
3192 badness
+= bad
->shared_primary
;
3194 badness
+= bad
->shared_surr
;
3196 badness
+= bad
->shared_clfe
;
3197 } else if (alc_auto_is_dac_reachable(codec
, pin
,
3198 spec
->private_dac_nids
[0])) {
3199 dac
= spec
->private_dac_nids
[0];
3200 badness
+= bad
->shared_surr_main
;
3202 badness
+= bad
->no_primary_dac
;
3204 badness
+= bad
->no_dac
;
3207 badness
+= eval_shared_vol_badness(codec
, pin
, dac
);
3213 static int alc_auto_fill_multi_ios(struct hda_codec
*codec
,
3214 hda_nid_t reference_pin
,
3215 bool hardwired
, int offset
);
3217 static bool alc_map_singles(struct hda_codec
*codec
, int outs
,
3218 const hda_nid_t
*pins
, hda_nid_t
*dacs
)
3222 for (i
= 0; i
< outs
; i
++) {
3225 dacs
[i
] = get_dac_if_single(codec
, pins
[i
]);
3232 /* fill in the dac_nids table from the parsed pin configuration */
3233 static int fill_and_eval_dacs(struct hda_codec
*codec
,
3234 bool fill_hardwired
,
3235 bool fill_mio_first
)
3237 struct alc_spec
*spec
= codec
->spec
;
3238 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
3239 int i
, err
, badness
;
3241 /* set num_dacs once to full for alc_auto_look_for_dac() */
3242 spec
->multiout
.num_dacs
= cfg
->line_outs
;
3243 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
3244 memset(spec
->private_dac_nids
, 0, sizeof(spec
->private_dac_nids
));
3245 memset(spec
->multiout
.hp_out_nid
, 0, sizeof(spec
->multiout
.hp_out_nid
));
3246 memset(spec
->multiout
.extra_out_nid
, 0, sizeof(spec
->multiout
.extra_out_nid
));
3247 spec
->multi_ios
= 0;
3248 clear_vol_marks(codec
);
3251 /* fill hard-wired DACs first */
3252 if (fill_hardwired
) {
3255 mapped
= alc_map_singles(codec
, cfg
->line_outs
,
3257 spec
->private_dac_nids
);
3258 mapped
|= alc_map_singles(codec
, cfg
->hp_outs
,
3260 spec
->multiout
.hp_out_nid
);
3261 mapped
|= alc_map_singles(codec
, cfg
->speaker_outs
,
3263 spec
->multiout
.extra_out_nid
);
3264 if (fill_mio_first
&& cfg
->line_outs
== 1 &&
3265 cfg
->line_out_type
!= AUTO_PIN_SPEAKER_OUT
) {
3266 err
= alc_auto_fill_multi_ios(codec
, cfg
->line_out_pins
[0], true, 0);
3273 badness
+= alc_auto_fill_dacs(codec
, cfg
->line_outs
, cfg
->line_out_pins
,
3274 spec
->private_dac_nids
,
3277 /* re-count num_dacs and squash invalid entries */
3278 spec
->multiout
.num_dacs
= 0;
3279 for (i
= 0; i
< cfg
->line_outs
; i
++) {
3280 if (spec
->private_dac_nids
[i
])
3281 spec
->multiout
.num_dacs
++;
3283 memmove(spec
->private_dac_nids
+ i
,
3284 spec
->private_dac_nids
+ i
+ 1,
3285 sizeof(hda_nid_t
) * (cfg
->line_outs
- i
- 1));
3286 spec
->private_dac_nids
[cfg
->line_outs
- 1] = 0;
3290 if (fill_mio_first
&&
3291 cfg
->line_outs
== 1 && cfg
->line_out_type
!= AUTO_PIN_SPEAKER_OUT
) {
3292 /* try to fill multi-io first */
3293 err
= alc_auto_fill_multi_ios(codec
, cfg
->line_out_pins
[0], false, 0);
3296 /* we don't count badness at this stage yet */
3299 if (cfg
->line_out_type
!= AUTO_PIN_HP_OUT
) {
3300 err
= alc_auto_fill_dacs(codec
, cfg
->hp_outs
, cfg
->hp_pins
,
3301 spec
->multiout
.hp_out_nid
,
3302 &extra_out_badness
);
3307 if (cfg
->line_out_type
!= AUTO_PIN_SPEAKER_OUT
) {
3308 err
= alc_auto_fill_dacs(codec
, cfg
->speaker_outs
,
3310 spec
->multiout
.extra_out_nid
,
3311 &extra_out_badness
);
3316 if (cfg
->line_outs
== 1 && cfg
->line_out_type
!= AUTO_PIN_SPEAKER_OUT
) {
3317 err
= alc_auto_fill_multi_ios(codec
, cfg
->line_out_pins
[0], false, 0);
3322 if (cfg
->hp_outs
&& cfg
->line_out_type
== AUTO_PIN_SPEAKER_OUT
) {
3323 /* try multi-ios with HP + inputs */
3324 err
= alc_auto_fill_multi_ios(codec
, cfg
->hp_pins
[0], false, 1);
3330 if (spec
->multi_ios
== 2) {
3331 for (i
= 0; i
< 2; i
++)
3332 spec
->private_dac_nids
[spec
->multiout
.num_dacs
++] =
3333 spec
->multi_io
[i
].dac
;
3334 spec
->ext_channel_count
= 2;
3335 } else if (spec
->multi_ios
) {
3336 spec
->multi_ios
= 0;
3337 badness
+= BAD_MULTI_IO
;
3343 #define DEBUG_BADNESS
3345 #ifdef DEBUG_BADNESS
3346 #define debug_badness snd_printdd
3348 #define debug_badness(...)
3351 static void debug_show_configs(struct alc_spec
*spec
, struct auto_pin_cfg
*cfg
)
3353 debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3354 cfg
->line_out_pins
[0], cfg
->line_out_pins
[1],
3355 cfg
->line_out_pins
[2], cfg
->line_out_pins
[2],
3356 spec
->multiout
.dac_nids
[0],
3357 spec
->multiout
.dac_nids
[1],
3358 spec
->multiout
.dac_nids
[2],
3359 spec
->multiout
.dac_nids
[3]);
3360 if (spec
->multi_ios
> 0)
3361 debug_badness("multi_ios(%d) = %x/%x : %x/%x\n",
3363 spec
->multi_io
[0].pin
, spec
->multi_io
[1].pin
,
3364 spec
->multi_io
[0].dac
, spec
->multi_io
[1].dac
);
3365 debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3366 cfg
->hp_pins
[0], cfg
->hp_pins
[1],
3367 cfg
->hp_pins
[2], cfg
->hp_pins
[2],
3368 spec
->multiout
.hp_out_nid
[0],
3369 spec
->multiout
.hp_out_nid
[1],
3370 spec
->multiout
.hp_out_nid
[2],
3371 spec
->multiout
.hp_out_nid
[3]);
3372 debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3373 cfg
->speaker_pins
[0], cfg
->speaker_pins
[1],
3374 cfg
->speaker_pins
[2], cfg
->speaker_pins
[3],
3375 spec
->multiout
.extra_out_nid
[0],
3376 spec
->multiout
.extra_out_nid
[1],
3377 spec
->multiout
.extra_out_nid
[2],
3378 spec
->multiout
.extra_out_nid
[3]);
3381 static int alc_auto_fill_dac_nids(struct hda_codec
*codec
)
3383 struct alc_spec
*spec
= codec
->spec
;
3384 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
3385 struct auto_pin_cfg
*best_cfg
;
3386 int best_badness
= INT_MAX
;
3388 bool fill_hardwired
= true, fill_mio_first
= true;
3389 bool best_wired
= true, best_mio
= true;
3390 bool hp_spk_swapped
= false;
3392 best_cfg
= kmalloc(sizeof(*best_cfg
), GFP_KERNEL
);
3398 badness
= fill_and_eval_dacs(codec
, fill_hardwired
,
3402 debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n",
3403 cfg
->line_out_type
, fill_hardwired
, fill_mio_first
,
3405 debug_show_configs(spec
, cfg
);
3406 if (badness
< best_badness
) {
3407 best_badness
= badness
;
3409 best_wired
= fill_hardwired
;
3410 best_mio
= fill_mio_first
;
3414 fill_mio_first
= !fill_mio_first
;
3415 if (!fill_mio_first
)
3417 fill_hardwired
= !fill_hardwired
;
3418 if (!fill_hardwired
)
3422 hp_spk_swapped
= true;
3423 if (cfg
->speaker_outs
> 0 &&
3424 cfg
->line_out_type
== AUTO_PIN_HP_OUT
) {
3425 cfg
->hp_outs
= cfg
->line_outs
;
3426 memcpy(cfg
->hp_pins
, cfg
->line_out_pins
,
3427 sizeof(cfg
->hp_pins
));
3428 cfg
->line_outs
= cfg
->speaker_outs
;
3429 memcpy(cfg
->line_out_pins
, cfg
->speaker_pins
,
3430 sizeof(cfg
->speaker_pins
));
3431 cfg
->speaker_outs
= 0;
3432 memset(cfg
->speaker_pins
, 0, sizeof(cfg
->speaker_pins
));
3433 cfg
->line_out_type
= AUTO_PIN_SPEAKER_OUT
;
3434 fill_hardwired
= true;
3437 if (cfg
->hp_outs
> 0 &&
3438 cfg
->line_out_type
== AUTO_PIN_SPEAKER_OUT
) {
3439 cfg
->speaker_outs
= cfg
->line_outs
;
3440 memcpy(cfg
->speaker_pins
, cfg
->line_out_pins
,
3441 sizeof(cfg
->speaker_pins
));
3442 cfg
->line_outs
= cfg
->hp_outs
;
3443 memcpy(cfg
->line_out_pins
, cfg
->hp_pins
,
3444 sizeof(cfg
->hp_pins
));
3446 memset(cfg
->hp_pins
, 0, sizeof(cfg
->hp_pins
));
3447 cfg
->line_out_type
= AUTO_PIN_HP_OUT
;
3448 fill_hardwired
= true;
3456 fill_and_eval_dacs(codec
, best_wired
, best_mio
);
3458 debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n",
3459 cfg
->line_out_type
, best_wired
, best_mio
);
3460 debug_show_configs(spec
, cfg
);
3462 if (cfg
->line_out_pins
[0])
3464 alc_look_for_out_vol_nid(codec
, cfg
->line_out_pins
[0],
3465 spec
->multiout
.dac_nids
[0]);
3467 /* clear the bitmap flags for creating controls */
3468 clear_vol_marks(codec
);
3473 static int alc_auto_add_vol_ctl(struct hda_codec
*codec
,
3474 const char *pfx
, int cidx
,
3475 hda_nid_t nid
, unsigned int chs
)
3477 struct alc_spec
*spec
= codec
->spec
;
3481 val
= HDA_COMPOSE_AMP_VAL(nid
, chs
, 0, HDA_OUTPUT
);
3482 if (is_ctl_used(spec
->vol_ctls
, val
) && chs
!= 2) /* exclude LFE */
3484 mark_ctl_usage(spec
->vol_ctls
, val
);
3485 return __add_pb_vol_ctrl(codec
->spec
, ALC_CTL_WIDGET_VOL
, pfx
, cidx
,
3489 static int alc_auto_add_stereo_vol(struct hda_codec
*codec
,
3490 const char *pfx
, int cidx
,
3494 if (get_wcaps(codec
, nid
) & AC_WCAP_STEREO
)
3496 return alc_auto_add_vol_ctl(codec
, pfx
, cidx
, nid
, chs
);
3499 /* create a mute-switch for the given mixer widget;
3500 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3502 static int alc_auto_add_sw_ctl(struct hda_codec
*codec
,
3503 const char *pfx
, int cidx
,
3504 hda_nid_t nid
, unsigned int chs
)
3506 struct alc_spec
*spec
= codec
->spec
;
3512 wid_type
= get_wcaps_type(get_wcaps(codec
, nid
));
3513 if (wid_type
== AC_WID_PIN
|| wid_type
== AC_WID_AUD_OUT
) {
3514 type
= ALC_CTL_WIDGET_MUTE
;
3515 val
= HDA_COMPOSE_AMP_VAL(nid
, chs
, 0, HDA_OUTPUT
);
3516 } else if (snd_hda_get_conn_list(codec
, nid
, NULL
) == 1) {
3517 type
= ALC_CTL_WIDGET_MUTE
;
3518 val
= HDA_COMPOSE_AMP_VAL(nid
, chs
, 0, HDA_INPUT
);
3520 type
= ALC_CTL_BIND_MUTE
;
3521 val
= HDA_COMPOSE_AMP_VAL(nid
, chs
, 2, HDA_INPUT
);
3523 if (is_ctl_used(spec
->sw_ctls
, val
) && chs
!= 2) /* exclude LFE */
3525 mark_ctl_usage(spec
->sw_ctls
, val
);
3526 return __add_pb_sw_ctrl(codec
->spec
, type
, pfx
, cidx
, val
);
3529 static int alc_auto_add_stereo_sw(struct hda_codec
*codec
, const char *pfx
,
3530 int cidx
, hda_nid_t nid
)
3533 if (get_wcaps(codec
, nid
) & AC_WCAP_STEREO
)
3535 return alc_auto_add_sw_ctl(codec
, pfx
, cidx
, nid
, chs
);
3538 static hda_nid_t
alc_look_for_out_mute_nid(struct hda_codec
*codec
,
3539 hda_nid_t pin
, hda_nid_t dac
)
3541 hda_nid_t mix
= alc_auto_dac_to_mix(codec
, pin
, dac
);
3542 if (nid_has_mute(codec
, pin
, HDA_OUTPUT
))
3544 else if (mix
&& nid_has_mute(codec
, mix
, HDA_INPUT
))
3546 else if (nid_has_mute(codec
, dac
, HDA_OUTPUT
))
3551 static hda_nid_t
alc_look_for_out_vol_nid(struct hda_codec
*codec
,
3552 hda_nid_t pin
, hda_nid_t dac
)
3554 hda_nid_t mix
= alc_auto_dac_to_mix(codec
, pin
, dac
);
3555 if (nid_has_volume(codec
, dac
, HDA_OUTPUT
))
3557 else if (nid_has_volume(codec
, mix
, HDA_OUTPUT
))
3559 else if (nid_has_volume(codec
, pin
, HDA_OUTPUT
))
3564 /* add playback controls from the parsed DAC table */
3565 static int alc_auto_create_multi_out_ctls(struct hda_codec
*codec
,
3566 const struct auto_pin_cfg
*cfg
)
3568 struct alc_spec
*spec
= codec
->spec
;
3569 int i
, err
, noutputs
;
3571 noutputs
= cfg
->line_outs
;
3572 if (spec
->multi_ios
> 0 && cfg
->line_outs
< 3)
3573 noutputs
+= spec
->multi_ios
;
3575 for (i
= 0; i
< noutputs
; i
++) {
3581 dac
= spec
->multiout
.dac_nids
[i
];
3584 if (i
>= cfg
->line_outs
)
3585 pin
= spec
->multi_io
[i
- 1].pin
;
3587 pin
= cfg
->line_out_pins
[i
];
3589 sw
= alc_look_for_out_mute_nid(codec
, pin
, dac
);
3590 vol
= alc_look_for_out_vol_nid(codec
, pin
, dac
);
3591 name
= alc_get_line_out_pfx(spec
, i
, true, &index
);
3592 if (!name
|| !strcmp(name
, "CLFE")) {
3594 err
= alc_auto_add_vol_ctl(codec
, "Center", 0, vol
, 1);
3597 err
= alc_auto_add_vol_ctl(codec
, "LFE", 0, vol
, 2);
3600 err
= alc_auto_add_sw_ctl(codec
, "Center", 0, sw
, 1);
3603 err
= alc_auto_add_sw_ctl(codec
, "LFE", 0, sw
, 2);
3607 err
= alc_auto_add_stereo_vol(codec
, name
, index
, vol
);
3610 err
= alc_auto_add_stereo_sw(codec
, name
, index
, sw
);
3618 static int alc_auto_create_extra_out(struct hda_codec
*codec
, hda_nid_t pin
,
3619 hda_nid_t dac
, const char *pfx
,
3622 struct alc_spec
*spec
= codec
->spec
;
3628 /* the corresponding DAC is already occupied */
3629 if (!(get_wcaps(codec
, pin
) & AC_WCAP_OUT_AMP
))
3630 return 0; /* no way */
3631 /* create a switch only */
3632 val
= HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
);
3633 if (is_ctl_used(spec
->sw_ctls
, val
))
3634 return 0; /* already created */
3635 mark_ctl_usage(spec
->sw_ctls
, val
);
3636 return __add_pb_sw_ctrl(spec
, ALC_CTL_WIDGET_MUTE
, pfx
, cidx
, val
);
3639 sw
= alc_look_for_out_mute_nid(codec
, pin
, dac
);
3640 vol
= alc_look_for_out_vol_nid(codec
, pin
, dac
);
3641 err
= alc_auto_add_stereo_vol(codec
, pfx
, cidx
, vol
);
3644 err
= alc_auto_add_stereo_sw(codec
, pfx
, cidx
, sw
);
3650 static struct hda_bind_ctls
*new_bind_ctl(struct hda_codec
*codec
,
3652 struct hda_ctl_ops
*ops
)
3654 struct alc_spec
*spec
= codec
->spec
;
3655 struct hda_bind_ctls
**ctlp
, *ctl
;
3656 snd_array_init(&spec
->bind_ctls
, sizeof(ctl
), 8);
3657 ctlp
= snd_array_new(&spec
->bind_ctls
);
3660 ctl
= kzalloc(sizeof(*ctl
) + sizeof(long) * (nums
+ 1), GFP_KERNEL
);
3667 /* add playback controls for speaker and HP outputs */
3668 static int alc_auto_create_extra_outs(struct hda_codec
*codec
, int num_pins
,
3669 const hda_nid_t
*pins
,
3670 const hda_nid_t
*dacs
,
3673 struct alc_spec
*spec
= codec
->spec
;
3674 struct hda_bind_ctls
*ctl
;
3678 if (!num_pins
|| !pins
[0])
3681 if (num_pins
== 1) {
3682 hda_nid_t dac
= *dacs
;
3684 dac
= spec
->multiout
.dac_nids
[0];
3685 return alc_auto_create_extra_out(codec
, *pins
, dac
, pfx
, 0);
3688 if (dacs
[num_pins
- 1]) {
3689 /* OK, we have a multi-output system with individual volumes */
3690 for (i
= 0; i
< num_pins
; i
++) {
3691 if (num_pins
>= 3) {
3692 snprintf(name
, sizeof(name
), "%s %s",
3693 pfx
, channel_name
[i
]);
3694 err
= alc_auto_create_extra_out(codec
, pins
[i
], dacs
[i
],
3697 err
= alc_auto_create_extra_out(codec
, pins
[i
], dacs
[i
],
3706 /* Let's create a bind-controls */
3707 ctl
= new_bind_ctl(codec
, num_pins
, &snd_hda_bind_sw
);
3711 for (i
= 0; i
< num_pins
; i
++) {
3712 if (get_wcaps(codec
, pins
[i
]) & AC_WCAP_OUT_AMP
)
3714 HDA_COMPOSE_AMP_VAL(pins
[i
], 3, 0, HDA_OUTPUT
);
3717 snprintf(name
, sizeof(name
), "%s Playback Switch", pfx
);
3718 err
= add_control(spec
, ALC_CTL_BIND_SW
, name
, 0, (long)ctl
);
3723 ctl
= new_bind_ctl(codec
, num_pins
, &snd_hda_bind_vol
);
3727 for (i
= 0; i
< num_pins
; i
++) {
3729 if (!pins
[i
] || !dacs
[i
])
3731 vol
= alc_look_for_out_vol_nid(codec
, pins
[i
], dacs
[i
]);
3734 HDA_COMPOSE_AMP_VAL(vol
, 3, 0, HDA_OUTPUT
);
3737 snprintf(name
, sizeof(name
), "%s Playback Volume", pfx
);
3738 err
= add_control(spec
, ALC_CTL_BIND_VOL
, name
, 0, (long)ctl
);
3745 static int alc_auto_create_hp_out(struct hda_codec
*codec
)
3747 struct alc_spec
*spec
= codec
->spec
;
3748 return alc_auto_create_extra_outs(codec
, spec
->autocfg
.hp_outs
,
3749 spec
->autocfg
.hp_pins
,
3750 spec
->multiout
.hp_out_nid
,
3754 static int alc_auto_create_speaker_out(struct hda_codec
*codec
)
3756 struct alc_spec
*spec
= codec
->spec
;
3757 return alc_auto_create_extra_outs(codec
, spec
->autocfg
.speaker_outs
,
3758 spec
->autocfg
.speaker_pins
,
3759 spec
->multiout
.extra_out_nid
,
3763 static void alc_auto_set_output_and_unmute(struct hda_codec
*codec
,
3764 hda_nid_t pin
, int pin_type
,
3768 hda_nid_t nid
, mix
= 0;
3769 hda_nid_t srcs
[HDA_MAX_CONNECTIONS
];
3771 alc_set_pin_output(codec
, pin
, pin_type
);
3772 nid
= alc_go_down_to_selector(codec
, pin
);
3773 num
= snd_hda_get_connections(codec
, nid
, srcs
, ARRAY_SIZE(srcs
));
3774 for (i
= 0; i
< num
; i
++) {
3775 if (alc_auto_mix_to_dac(codec
, srcs
[i
]) != dac
)
3783 /* need the manual connection? */
3785 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_CONNECT_SEL
, i
);
3786 /* unmute mixer widget inputs */
3787 if (nid_has_mute(codec
, mix
, HDA_INPUT
)) {
3788 snd_hda_codec_write(codec
, mix
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
3790 snd_hda_codec_write(codec
, mix
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
3793 /* initialize volume */
3794 nid
= alc_look_for_out_vol_nid(codec
, pin
, dac
);
3796 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
3799 /* unmute DAC if it's not assigned to a mixer */
3800 nid
= alc_look_for_out_mute_nid(codec
, pin
, dac
);
3801 if (nid
== mix
&& nid_has_mute(codec
, dac
, HDA_OUTPUT
))
3802 snd_hda_codec_write(codec
, dac
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
3806 static void alc_auto_init_multi_out(struct hda_codec
*codec
)
3808 struct alc_spec
*spec
= codec
->spec
;
3809 int pin_type
= get_pin_type(spec
->autocfg
.line_out_type
);
3812 for (i
= 0; i
<= HDA_SIDE
; i
++) {
3813 hda_nid_t nid
= spec
->autocfg
.line_out_pins
[i
];
3815 alc_auto_set_output_and_unmute(codec
, nid
, pin_type
,
3816 spec
->multiout
.dac_nids
[i
]);
3820 static void alc_auto_init_extra_out(struct hda_codec
*codec
)
3822 struct alc_spec
*spec
= codec
->spec
;
3826 for (i
= 0; i
< spec
->autocfg
.hp_outs
; i
++) {
3827 if (spec
->autocfg
.line_out_type
== AUTO_PIN_HP_OUT
)
3829 pin
= spec
->autocfg
.hp_pins
[i
];
3832 dac
= spec
->multiout
.hp_out_nid
[i
];
3834 if (i
> 0 && spec
->multiout
.hp_out_nid
[0])
3835 dac
= spec
->multiout
.hp_out_nid
[0];
3837 dac
= spec
->multiout
.dac_nids
[0];
3839 alc_auto_set_output_and_unmute(codec
, pin
, PIN_HP
, dac
);
3841 for (i
= 0; i
< spec
->autocfg
.speaker_outs
; i
++) {
3842 if (spec
->autocfg
.line_out_type
== AUTO_PIN_SPEAKER_OUT
)
3844 pin
= spec
->autocfg
.speaker_pins
[i
];
3847 dac
= spec
->multiout
.extra_out_nid
[i
];
3849 if (i
> 0 && spec
->multiout
.extra_out_nid
[0])
3850 dac
= spec
->multiout
.extra_out_nid
[0];
3852 dac
= spec
->multiout
.dac_nids
[0];
3854 alc_auto_set_output_and_unmute(codec
, pin
, PIN_OUT
, dac
);
3858 /* check whether the given pin can be a multi-io pin */
3859 static bool can_be_multiio_pin(struct hda_codec
*codec
,
3860 unsigned int location
, hda_nid_t nid
)
3862 unsigned int defcfg
, caps
;
3864 defcfg
= snd_hda_codec_get_pincfg(codec
, nid
);
3865 if (get_defcfg_connect(defcfg
) != AC_JACK_PORT_COMPLEX
)
3867 if (location
&& get_defcfg_location(defcfg
) != location
)
3869 caps
= snd_hda_query_pin_caps(codec
, nid
);
3870 if (!(caps
& AC_PINCAP_OUT
))
3878 * When hardwired is set, try to fill ony hardwired pins, and returns
3879 * zero if any pins are filled, non-zero if nothing found.
3880 * When hardwired is off, try to fill possible input pins, and returns
3881 * the badness value.
3883 static int alc_auto_fill_multi_ios(struct hda_codec
*codec
,
3884 hda_nid_t reference_pin
,
3885 bool hardwired
, int offset
)
3887 struct alc_spec
*spec
= codec
->spec
;
3888 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
3889 int type
, i
, j
, dacs
, num_pins
, old_pins
;
3890 unsigned int defcfg
= snd_hda_codec_get_pincfg(codec
, reference_pin
);
3891 unsigned int location
= get_defcfg_location(defcfg
);
3894 old_pins
= spec
->multi_ios
;
3899 for (type
= AUTO_PIN_LINE_IN
; type
>= AUTO_PIN_MIC
; type
--) {
3900 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
3901 if (cfg
->inputs
[i
].type
!= type
)
3903 if (can_be_multiio_pin(codec
, location
,
3904 cfg
->inputs
[i
].pin
))
3911 dacs
= spec
->multiout
.num_dacs
;
3912 for (type
= AUTO_PIN_LINE_IN
; type
>= AUTO_PIN_MIC
; type
--) {
3913 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
3914 hda_nid_t nid
= cfg
->inputs
[i
].pin
;
3917 if (cfg
->inputs
[i
].type
!= type
)
3919 if (!can_be_multiio_pin(codec
, location
, nid
))
3921 for (j
= 0; j
< spec
->multi_ios
; j
++) {
3922 if (nid
== spec
->multi_io
[j
].pin
)
3925 if (j
< spec
->multi_ios
)
3928 if (offset
&& offset
+ spec
->multi_ios
< dacs
) {
3929 dac
= spec
->private_dac_nids
[offset
+ spec
->multi_ios
];
3930 if (!alc_auto_is_dac_reachable(codec
, nid
, dac
))
3934 dac
= get_dac_if_single(codec
, nid
);
3936 dac
= alc_auto_look_for_dac(codec
, nid
);
3941 spec
->multi_io
[spec
->multi_ios
].pin
= nid
;
3942 spec
->multi_io
[spec
->multi_ios
].dac
= dac
;
3944 if (spec
->multi_ios
>= 2)
3950 badness
= BAD_MULTI_IO
;
3951 if (old_pins
== spec
->multi_ios
) {
3953 return 1; /* nothing found */
3955 return badness
; /* no badness if nothing found */
3957 if (!hardwired
&& spec
->multi_ios
< 2) {
3958 spec
->multi_ios
= old_pins
;
3965 static int alc_auto_ch_mode_info(struct snd_kcontrol
*kcontrol
,
3966 struct snd_ctl_elem_info
*uinfo
)
3968 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3969 struct alc_spec
*spec
= codec
->spec
;
3971 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
3973 uinfo
->value
.enumerated
.items
= spec
->multi_ios
+ 1;
3974 if (uinfo
->value
.enumerated
.item
> spec
->multi_ios
)
3975 uinfo
->value
.enumerated
.item
= spec
->multi_ios
;
3976 sprintf(uinfo
->value
.enumerated
.name
, "%dch",
3977 (uinfo
->value
.enumerated
.item
+ 1) * 2);
3981 static int alc_auto_ch_mode_get(struct snd_kcontrol
*kcontrol
,
3982 struct snd_ctl_elem_value
*ucontrol
)
3984 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3985 struct alc_spec
*spec
= codec
->spec
;
3986 ucontrol
->value
.enumerated
.item
[0] = (spec
->ext_channel_count
- 1) / 2;
3990 static int alc_set_multi_io(struct hda_codec
*codec
, int idx
, bool output
)
3992 struct alc_spec
*spec
= codec
->spec
;
3993 hda_nid_t nid
= spec
->multi_io
[idx
].pin
;
3995 if (!spec
->multi_io
[idx
].ctl_in
)
3996 spec
->multi_io
[idx
].ctl_in
=
3997 snd_hda_codec_read(codec
, nid
, 0,
3998 AC_VERB_GET_PIN_WIDGET_CONTROL
, 0);
4000 snd_hda_codec_update_cache(codec
, nid
, 0,
4001 AC_VERB_SET_PIN_WIDGET_CONTROL
,
4003 if (get_wcaps(codec
, nid
) & AC_WCAP_OUT_AMP
)
4004 snd_hda_codec_amp_stereo(codec
, nid
, HDA_OUTPUT
, 0,
4006 alc_auto_select_dac(codec
, nid
, spec
->multi_io
[idx
].dac
);
4008 if (get_wcaps(codec
, nid
) & AC_WCAP_OUT_AMP
)
4009 snd_hda_codec_amp_stereo(codec
, nid
, HDA_OUTPUT
, 0,
4010 HDA_AMP_MUTE
, HDA_AMP_MUTE
);
4011 snd_hda_codec_update_cache(codec
, nid
, 0,
4012 AC_VERB_SET_PIN_WIDGET_CONTROL
,
4013 spec
->multi_io
[idx
].ctl_in
);
4018 static int alc_auto_ch_mode_put(struct snd_kcontrol
*kcontrol
,
4019 struct snd_ctl_elem_value
*ucontrol
)
4021 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
4022 struct alc_spec
*spec
= codec
->spec
;
4025 ch
= ucontrol
->value
.enumerated
.item
[0];
4026 if (ch
< 0 || ch
> spec
->multi_ios
)
4028 if (ch
== (spec
->ext_channel_count
- 1) / 2)
4030 spec
->ext_channel_count
= (ch
+ 1) * 2;
4031 for (i
= 0; i
< spec
->multi_ios
; i
++)
4032 alc_set_multi_io(codec
, i
, i
< ch
);
4033 spec
->multiout
.max_channels
= spec
->ext_channel_count
;
4034 if (spec
->need_dac_fix
&& !spec
->const_channel_count
)
4035 spec
->multiout
.num_dacs
= spec
->multiout
.max_channels
/ 2;
4039 static const struct snd_kcontrol_new alc_auto_channel_mode_enum
= {
4040 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
4041 .name
= "Channel Mode",
4042 .info
= alc_auto_ch_mode_info
,
4043 .get
= alc_auto_ch_mode_get
,
4044 .put
= alc_auto_ch_mode_put
,
4047 static int alc_auto_add_multi_channel_mode(struct hda_codec
*codec
)
4049 struct alc_spec
*spec
= codec
->spec
;
4051 if (spec
->multi_ios
> 0) {
4052 struct snd_kcontrol_new
*knew
;
4054 knew
= alc_kcontrol_new(spec
);
4057 *knew
= alc_auto_channel_mode_enum
;
4058 knew
->name
= kstrdup("Channel Mode", GFP_KERNEL
);
4065 /* filter out invalid adc_nids (and capsrc_nids) that don't give all
4068 static void alc_remove_invalid_adc_nids(struct hda_codec
*codec
)
4070 struct alc_spec
*spec
= codec
->spec
;
4071 const struct hda_input_mux
*imux
;
4072 hda_nid_t adc_nids
[ARRAY_SIZE(spec
->private_adc_nids
)];
4073 hda_nid_t capsrc_nids
[ARRAY_SIZE(spec
->private_adc_nids
)];
4076 imux
= spec
->input_mux
;
4079 if (spec
->dyn_adc_switch
)
4083 for (n
= 0; n
< spec
->num_adc_nids
; n
++) {
4084 hda_nid_t cap
= spec
->private_capsrc_nids
[n
];
4085 int num_conns
= snd_hda_get_conn_list(codec
, cap
, NULL
);
4086 for (i
= 0; i
< imux
->num_items
; i
++) {
4087 hda_nid_t pin
= spec
->imux_pins
[i
];
4089 if (get_connection_index(codec
, cap
, pin
) < 0)
4091 } else if (num_conns
<= imux
->items
[i
].index
)
4094 if (i
>= imux
->num_items
) {
4095 adc_nids
[nums
] = spec
->private_adc_nids
[n
];
4096 capsrc_nids
[nums
++] = cap
;
4100 /* check whether ADC-switch is possible */
4101 if (!alc_check_dyn_adc_switch(codec
)) {
4102 printk(KERN_WARNING
"hda_codec: %s: no valid ADC found;"
4103 " using fallback 0x%x\n",
4104 codec
->chip_name
, spec
->private_adc_nids
[0]);
4105 spec
->num_adc_nids
= 1;
4109 } else if (nums
!= spec
->num_adc_nids
) {
4110 memcpy(spec
->private_adc_nids
, adc_nids
,
4111 nums
* sizeof(hda_nid_t
));
4112 memcpy(spec
->private_capsrc_nids
, capsrc_nids
,
4113 nums
* sizeof(hda_nid_t
));
4114 spec
->num_adc_nids
= nums
;
4118 alc_auto_mic_check_imux(codec
); /* check auto-mic setups */
4119 else if (spec
->input_mux
->num_items
== 1)
4120 spec
->num_adc_nids
= 1; /* reduce to a single ADC */
4124 * initialize ADC paths
4126 static void alc_auto_init_adc(struct hda_codec
*codec
, int adc_idx
)
4128 struct alc_spec
*spec
= codec
->spec
;
4131 nid
= spec
->adc_nids
[adc_idx
];
4133 if (nid_has_mute(codec
, nid
, HDA_INPUT
)) {
4134 snd_hda_codec_write(codec
, nid
, 0,
4135 AC_VERB_SET_AMP_GAIN_MUTE
,
4139 if (!spec
->capsrc_nids
)
4141 nid
= spec
->capsrc_nids
[adc_idx
];
4142 if (nid_has_mute(codec
, nid
, HDA_OUTPUT
))
4143 snd_hda_codec_write(codec
, nid
, 0,
4144 AC_VERB_SET_AMP_GAIN_MUTE
,
4148 static void alc_auto_init_input_src(struct hda_codec
*codec
)
4150 struct alc_spec
*spec
= codec
->spec
;
4153 for (c
= 0; c
< spec
->num_adc_nids
; c
++)
4154 alc_auto_init_adc(codec
, c
);
4155 if (spec
->dyn_adc_switch
)
4158 nums
= spec
->num_adc_nids
;
4159 for (c
= 0; c
< nums
; c
++)
4160 alc_mux_select(codec
, 0, spec
->cur_mux
[c
], true);
4163 /* add mic boosts if needed */
4164 static int alc_auto_add_mic_boost(struct hda_codec
*codec
)
4166 struct alc_spec
*spec
= codec
->spec
;
4167 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
4171 const char *prev_label
= NULL
;
4173 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
4174 if (cfg
->inputs
[i
].type
> AUTO_PIN_MIC
)
4176 nid
= cfg
->inputs
[i
].pin
;
4177 if (get_wcaps(codec
, nid
) & AC_WCAP_IN_AMP
) {
4179 char boost_label
[32];
4181 label
= hda_get_autocfg_input_label(codec
, cfg
, i
);
4182 if (spec
->shared_mic_hp
&& !strcmp(label
, "Misc"))
4183 label
= "Headphone Mic";
4184 if (prev_label
&& !strcmp(label
, prev_label
))
4190 snprintf(boost_label
, sizeof(boost_label
),
4191 "%s Boost Volume", label
);
4192 err
= add_control(spec
, ALC_CTL_WIDGET_VOL
,
4193 boost_label
, type_idx
,
4194 HDA_COMPOSE_AMP_VAL(nid
, 3, 0, HDA_INPUT
));
4202 /* select or unmute the given capsrc route */
4203 static void select_or_unmute_capsrc(struct hda_codec
*codec
, hda_nid_t cap
,
4206 if (get_wcaps_type(get_wcaps(codec
, cap
)) == AC_WID_AUD_MIX
) {
4207 snd_hda_codec_amp_stereo(codec
, cap
, HDA_INPUT
, idx
,
4209 } else if (snd_hda_get_conn_list(codec
, cap
, NULL
) > 1) {
4210 snd_hda_codec_write_cache(codec
, cap
, 0,
4211 AC_VERB_SET_CONNECT_SEL
, idx
);
4215 /* set the default connection to that pin */
4216 static int init_capsrc_for_pin(struct hda_codec
*codec
, hda_nid_t pin
)
4218 struct alc_spec
*spec
= codec
->spec
;
4223 for (i
= 0; i
< spec
->num_adc_nids
; i
++) {
4224 hda_nid_t cap
= get_capsrc(spec
, i
);
4227 idx
= get_connection_index(codec
, cap
, pin
);
4230 select_or_unmute_capsrc(codec
, cap
, idx
);
4231 return i
; /* return the found index */
4233 return -1; /* not found */
4236 /* initialize some special cases for input sources */
4237 static void alc_init_special_input_src(struct hda_codec
*codec
)
4239 struct alc_spec
*spec
= codec
->spec
;
4242 for (i
= 0; i
< spec
->autocfg
.num_inputs
; i
++)
4243 init_capsrc_for_pin(codec
, spec
->autocfg
.inputs
[i
].pin
);
4246 /* assign appropriate capture mixers */
4247 static void set_capture_mixer(struct hda_codec
*codec
)
4249 struct alc_spec
*spec
= codec
->spec
;
4250 static const struct snd_kcontrol_new
*caps
[2][3] = {
4251 { alc_capture_mixer_nosrc1
,
4252 alc_capture_mixer_nosrc2
,
4253 alc_capture_mixer_nosrc3
},
4254 { alc_capture_mixer1
,
4256 alc_capture_mixer3
},
4259 /* check whether either of ADC or MUX has a volume control */
4260 if (!nid_has_volume(codec
, spec
->adc_nids
[0], HDA_INPUT
)) {
4261 if (!spec
->capsrc_nids
)
4262 return; /* no volume */
4263 if (!nid_has_volume(codec
, spec
->capsrc_nids
[0], HDA_OUTPUT
))
4264 return; /* no volume in capsrc, too */
4265 spec
->vol_in_capsrc
= 1;
4268 if (spec
->num_adc_nids
> 0) {
4272 if (spec
->input_mux
&& spec
->input_mux
->num_items
> 1)
4274 if (spec
->auto_mic
) {
4277 } else if (spec
->dyn_adc_switch
)
4280 if (spec
->num_adc_nids
> 3)
4281 spec
->num_adc_nids
= 3;
4282 else if (!spec
->num_adc_nids
)
4284 num_adcs
= spec
->num_adc_nids
;
4286 spec
->cap_mixer
= caps
[mux
][num_adcs
- 1];
4291 * standard auto-parser initializations
4293 static void alc_auto_init_std(struct hda_codec
*codec
)
4295 struct alc_spec
*spec
= codec
->spec
;
4296 alc_auto_init_multi_out(codec
);
4297 alc_auto_init_extra_out(codec
);
4298 alc_auto_init_analog_input(codec
);
4299 alc_auto_init_input_src(codec
);
4300 alc_auto_init_digital(codec
);
4301 if (spec
->unsol_event
)
4302 alc_inithook(codec
);
4306 * Digital-beep handlers
4308 #ifdef CONFIG_SND_HDA_INPUT_BEEP
4309 #define set_beep_amp(spec, nid, idx, dir) \
4310 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4312 static const struct snd_pci_quirk beep_white_list
[] = {
4313 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
4314 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
4315 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
4316 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
4317 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
4321 static inline int has_cdefine_beep(struct hda_codec
*codec
)
4323 struct alc_spec
*spec
= codec
->spec
;
4324 const struct snd_pci_quirk
*q
;
4325 q
= snd_pci_quirk_lookup(codec
->bus
->pci
, beep_white_list
);
4328 return spec
->cdefine
.enable_pcbeep
;
4331 #define set_beep_amp(spec, nid, idx, dir) /* NOP */
4332 #define has_cdefine_beep(codec) 0
4335 /* parse the BIOS configuration and set up the alc_spec */
4336 /* return 1 if successful, 0 if the proper config is not found,
4337 * or a negative error code
4339 static int alc_parse_auto_config(struct hda_codec
*codec
,
4340 const hda_nid_t
*ignore_nids
,
4341 const hda_nid_t
*ssid_nids
)
4343 struct alc_spec
*spec
= codec
->spec
;
4344 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
4347 err
= snd_hda_parse_pin_defcfg(codec
, cfg
, ignore_nids
,
4351 if (!cfg
->line_outs
) {
4352 if (cfg
->dig_outs
|| cfg
->dig_in_pin
) {
4353 spec
->multiout
.max_channels
= 2;
4354 spec
->no_analog
= 1;
4357 return 0; /* can't find valid BIOS pin config */
4360 if (cfg
->line_out_type
== AUTO_PIN_SPEAKER_OUT
&&
4361 cfg
->line_outs
<= cfg
->hp_outs
) {
4362 /* use HP as primary out */
4363 cfg
->speaker_outs
= cfg
->line_outs
;
4364 memcpy(cfg
->speaker_pins
, cfg
->line_out_pins
,
4365 sizeof(cfg
->speaker_pins
));
4366 cfg
->line_outs
= cfg
->hp_outs
;
4367 memcpy(cfg
->line_out_pins
, cfg
->hp_pins
, sizeof(cfg
->hp_pins
));
4369 memset(cfg
->hp_pins
, 0, sizeof(cfg
->hp_pins
));
4370 cfg
->line_out_type
= AUTO_PIN_HP_OUT
;
4373 err
= alc_auto_fill_dac_nids(codec
);
4376 err
= alc_auto_add_multi_channel_mode(codec
);
4379 err
= alc_auto_create_multi_out_ctls(codec
, cfg
);
4382 err
= alc_auto_create_hp_out(codec
);
4385 err
= alc_auto_create_speaker_out(codec
);
4388 err
= alc_auto_create_shared_input(codec
);
4391 err
= alc_auto_create_input_ctls(codec
);
4395 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
4398 alc_auto_parse_digital(codec
);
4400 if (!spec
->no_analog
)
4401 alc_remove_invalid_adc_nids(codec
);
4404 alc_ssid_check(codec
, ssid_nids
);
4406 if (!spec
->no_analog
) {
4407 alc_auto_check_switches(codec
);
4408 err
= alc_auto_add_mic_boost(codec
);
4413 if (spec
->kctls
.list
)
4414 add_mixer(spec
, spec
->kctls
.list
);
4419 static int alc880_parse_auto_config(struct hda_codec
*codec
)
4421 static const hda_nid_t alc880_ignore
[] = { 0x1d, 0 };
4422 static const hda_nid_t alc880_ssids
[] = { 0x15, 0x1b, 0x14, 0 };
4423 return alc_parse_auto_config(codec
, alc880_ignore
, alc880_ssids
);
4426 #ifdef CONFIG_SND_HDA_POWER_SAVE
4427 static const struct hda_amp_list alc880_loopbacks
[] = {
4428 { 0x0b, HDA_INPUT
, 0 },
4429 { 0x0b, HDA_INPUT
, 1 },
4430 { 0x0b, HDA_INPUT
, 2 },
4431 { 0x0b, HDA_INPUT
, 3 },
4432 { 0x0b, HDA_INPUT
, 4 },
4442 ALC880_FIXUP_MEDION_RIM
,
4445 ALC880_FIXUP_EAPD_COEF
,
4446 ALC880_FIXUP_TCL_S700
,
4447 ALC880_FIXUP_VOL_KNOB
,
4448 ALC880_FIXUP_FUJITSU
,
4450 ALC880_FIXUP_UNIWILL
,
4451 ALC880_FIXUP_UNIWILL_DIG
,
4455 /* enable the volume-knob widget support on NID 0x21 */
4456 static void alc880_fixup_vol_knob(struct hda_codec
*codec
,
4457 const struct alc_fixup
*fix
, int action
)
4459 if (action
== ALC_FIXUP_ACT_PROBE
)
4460 snd_hda_jack_detect_enable(codec
, 0x21, ALC_DCVOL_EVENT
);
4463 static const struct alc_fixup alc880_fixups
[] = {
4464 [ALC880_FIXUP_GPIO2
] = {
4465 .type
= ALC_FIXUP_VERBS
,
4466 .v
.verbs
= alc_gpio2_init_verbs
,
4468 [ALC880_FIXUP_MEDION_RIM
] = {
4469 .type
= ALC_FIXUP_VERBS
,
4470 .v
.verbs
= (const struct hda_verb
[]) {
4471 { 0x20, AC_VERB_SET_COEF_INDEX
, 0x07 },
4472 { 0x20, AC_VERB_SET_PROC_COEF
, 0x3060 },
4476 .chain_id
= ALC880_FIXUP_GPIO2
,
4478 [ALC880_FIXUP_LG
] = {
4479 .type
= ALC_FIXUP_PINS
,
4480 .v
.pins
= (const struct alc_pincfg
[]) {
4481 /* disable bogus unused pins */
4482 { 0x16, 0x411111f0 },
4483 { 0x18, 0x411111f0 },
4484 { 0x1a, 0x411111f0 },
4488 [ALC880_FIXUP_W810
] = {
4489 .type
= ALC_FIXUP_PINS
,
4490 .v
.pins
= (const struct alc_pincfg
[]) {
4491 /* disable bogus unused pins */
4492 { 0x17, 0x411111f0 },
4496 .chain_id
= ALC880_FIXUP_GPIO2
,
4498 [ALC880_FIXUP_EAPD_COEF
] = {
4499 .type
= ALC_FIXUP_VERBS
,
4500 .v
.verbs
= (const struct hda_verb
[]) {
4501 /* change to EAPD mode */
4502 { 0x20, AC_VERB_SET_COEF_INDEX
, 0x07 },
4503 { 0x20, AC_VERB_SET_PROC_COEF
, 0x3060 },
4507 [ALC880_FIXUP_TCL_S700
] = {
4508 .type
= ALC_FIXUP_VERBS
,
4509 .v
.verbs
= (const struct hda_verb
[]) {
4510 /* change to EAPD mode */
4511 { 0x20, AC_VERB_SET_COEF_INDEX
, 0x07 },
4512 { 0x20, AC_VERB_SET_PROC_COEF
, 0x3070 },
4516 .chain_id
= ALC880_FIXUP_GPIO2
,
4518 [ALC880_FIXUP_VOL_KNOB
] = {
4519 .type
= ALC_FIXUP_FUNC
,
4520 .v
.func
= alc880_fixup_vol_knob
,
4522 [ALC880_FIXUP_FUJITSU
] = {
4523 /* override all pins as BIOS on old Amilo is broken */
4524 .type
= ALC_FIXUP_PINS
,
4525 .v
.pins
= (const struct alc_pincfg
[]) {
4526 { 0x14, 0x0121411f }, /* HP */
4527 { 0x15, 0x99030120 }, /* speaker */
4528 { 0x16, 0x99030130 }, /* bass speaker */
4529 { 0x17, 0x411111f0 }, /* N/A */
4530 { 0x18, 0x411111f0 }, /* N/A */
4531 { 0x19, 0x01a19950 }, /* mic-in */
4532 { 0x1a, 0x411111f0 }, /* N/A */
4533 { 0x1b, 0x411111f0 }, /* N/A */
4534 { 0x1c, 0x411111f0 }, /* N/A */
4535 { 0x1d, 0x411111f0 }, /* N/A */
4536 { 0x1e, 0x01454140 }, /* SPDIF out */
4540 .chain_id
= ALC880_FIXUP_VOL_KNOB
,
4542 [ALC880_FIXUP_F1734
] = {
4543 /* almost compatible with FUJITSU, but no bass and SPDIF */
4544 .type
= ALC_FIXUP_PINS
,
4545 .v
.pins
= (const struct alc_pincfg
[]) {
4546 { 0x14, 0x0121411f }, /* HP */
4547 { 0x15, 0x99030120 }, /* speaker */
4548 { 0x16, 0x411111f0 }, /* N/A */
4549 { 0x17, 0x411111f0 }, /* N/A */
4550 { 0x18, 0x411111f0 }, /* N/A */
4551 { 0x19, 0x01a19950 }, /* mic-in */
4552 { 0x1a, 0x411111f0 }, /* N/A */
4553 { 0x1b, 0x411111f0 }, /* N/A */
4554 { 0x1c, 0x411111f0 }, /* N/A */
4555 { 0x1d, 0x411111f0 }, /* N/A */
4556 { 0x1e, 0x411111f0 }, /* N/A */
4560 .chain_id
= ALC880_FIXUP_VOL_KNOB
,
4562 [ALC880_FIXUP_UNIWILL
] = {
4563 /* need to fix HP and speaker pins to be parsed correctly */
4564 .type
= ALC_FIXUP_PINS
,
4565 .v
.pins
= (const struct alc_pincfg
[]) {
4566 { 0x14, 0x0121411f }, /* HP */
4567 { 0x15, 0x99030120 }, /* speaker */
4568 { 0x16, 0x99030130 }, /* bass speaker */
4572 [ALC880_FIXUP_UNIWILL_DIG
] = {
4573 .type
= ALC_FIXUP_PINS
,
4574 .v
.pins
= (const struct alc_pincfg
[]) {
4575 /* disable bogus unused pins */
4576 { 0x17, 0x411111f0 },
4577 { 0x19, 0x411111f0 },
4578 { 0x1b, 0x411111f0 },
4579 { 0x1f, 0x411111f0 },
4583 [ALC880_FIXUP_Z71V
] = {
4584 .type
= ALC_FIXUP_PINS
,
4585 .v
.pins
= (const struct alc_pincfg
[]) {
4586 /* set up the whole pins as BIOS is utterly broken */
4587 { 0x14, 0x99030120 }, /* speaker */
4588 { 0x15, 0x0121411f }, /* HP */
4589 { 0x16, 0x411111f0 }, /* N/A */
4590 { 0x17, 0x411111f0 }, /* N/A */
4591 { 0x18, 0x01a19950 }, /* mic-in */
4592 { 0x19, 0x411111f0 }, /* N/A */
4593 { 0x1a, 0x01813031 }, /* line-in */
4594 { 0x1b, 0x411111f0 }, /* N/A */
4595 { 0x1c, 0x411111f0 }, /* N/A */
4596 { 0x1d, 0x411111f0 }, /* N/A */
4597 { 0x1e, 0x0144111e }, /* SPDIF */
4603 static const struct snd_pci_quirk alc880_fixup_tbl
[] = {
4604 SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_FIXUP_W810
),
4605 SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_FIXUP_Z71V
),
4606 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo", ALC880_FIXUP_EAPD_COEF
),
4607 SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_FIXUP_UNIWILL_DIG
),
4608 SND_PCI_QUIRK(0x1584, 0x9054, "Uniwill", ALC880_FIXUP_F1734
),
4609 SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_FIXUP_UNIWILL
),
4610 SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_FIXUP_VOL_KNOB
),
4611 SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_FIXUP_W810
),
4612 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM
),
4613 SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_FIXUP_F1734
),
4614 SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FIXUP_FUJITSU
),
4615 SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_FIXUP_F1734
),
4616 SND_PCI_QUIRK(0x1734, 0x10b0, "FSC Amilo Pi1556", ALC880_FIXUP_FUJITSU
),
4617 SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_FIXUP_LG
),
4618 SND_PCI_QUIRK(0x1854, 0x005f, "LG P1 Express", ALC880_FIXUP_LG
),
4619 SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_FIXUP_LG
),
4620 SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_FIXUP_TCL_S700
),
4628 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4629 #define alc_board_config \
4630 snd_hda_check_board_config
4631 #define alc_board_codec_sid_config \
4632 snd_hda_check_board_codec_sid_config
4633 #include "alc_quirks.c"
4635 #define alc_board_config(codec, nums, models, tbl) -1
4636 #define alc_board_codec_sid_config(codec, nums, models, tbl) -1
4637 #define setup_preset(codec, x) /* NOP */
4641 * OK, here we have finally the patch for ALC880
4643 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4644 #include "alc880_quirks.c"
4647 static int patch_alc880(struct hda_codec
*codec
)
4649 struct alc_spec
*spec
;
4653 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
4659 spec
->mixer_nid
= 0x0b;
4660 spec
->need_dac_fix
= 1;
4662 board_config
= alc_board_config(codec
, ALC880_MODEL_LAST
,
4663 alc880_models
, alc880_cfg_tbl
);
4664 if (board_config
< 0) {
4665 printk(KERN_INFO
"hda_codec: %s: BIOS auto-probing.\n",
4667 board_config
= ALC_MODEL_AUTO
;
4670 if (board_config
== ALC_MODEL_AUTO
) {
4671 alc_pick_fixup(codec
, NULL
, alc880_fixup_tbl
, alc880_fixups
);
4672 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
4675 if (board_config
== ALC_MODEL_AUTO
) {
4676 /* automatic parse from the BIOS config */
4677 err
= alc880_parse_auto_config(codec
);
4680 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4683 "hda_codec: Cannot set up configuration "
4684 "from BIOS. Using 3-stack mode...\n");
4685 board_config
= ALC880_3ST
;
4690 if (board_config
!= ALC_MODEL_AUTO
) {
4691 spec
->vmaster_nid
= 0x0c;
4692 setup_preset(codec
, &alc880_presets
[board_config
]);
4695 if (!spec
->no_analog
&& !spec
->adc_nids
) {
4696 alc_auto_fill_adc_caps(codec
);
4697 alc_rebuild_imux_for_auto_mic(codec
);
4698 alc_remove_invalid_adc_nids(codec
);
4701 if (!spec
->no_analog
&& !spec
->cap_mixer
)
4702 set_capture_mixer(codec
);
4704 if (!spec
->no_analog
) {
4705 err
= snd_hda_attach_beep_device(codec
, 0x1);
4708 set_beep_amp(spec
, 0x0b, 0x05, HDA_INPUT
);
4711 codec
->patch_ops
= alc_patch_ops
;
4712 if (board_config
== ALC_MODEL_AUTO
)
4713 spec
->init_hook
= alc_auto_init_std
;
4715 codec
->patch_ops
.build_controls
= __alc_build_controls
;
4716 #ifdef CONFIG_SND_HDA_POWER_SAVE
4717 if (!spec
->loopback
.amplist
)
4718 spec
->loopback
.amplist
= alc880_loopbacks
;
4721 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
4734 static int alc260_parse_auto_config(struct hda_codec
*codec
)
4736 static const hda_nid_t alc260_ignore
[] = { 0x17, 0 };
4737 static const hda_nid_t alc260_ssids
[] = { 0x10, 0x15, 0x0f, 0 };
4738 return alc_parse_auto_config(codec
, alc260_ignore
, alc260_ssids
);
4741 #ifdef CONFIG_SND_HDA_POWER_SAVE
4742 static const struct hda_amp_list alc260_loopbacks
[] = {
4743 { 0x07, HDA_INPUT
, 0 },
4744 { 0x07, HDA_INPUT
, 1 },
4745 { 0x07, HDA_INPUT
, 2 },
4746 { 0x07, HDA_INPUT
, 3 },
4747 { 0x07, HDA_INPUT
, 4 },
4756 ALC260_FIXUP_HP_DC5750
,
4757 ALC260_FIXUP_HP_PIN_0F
,
4760 ALC260_FIXUP_GPIO1_TOGGLE
,
4761 ALC260_FIXUP_REPLACER
,
4762 ALC260_FIXUP_HP_B1900
,
4765 static void alc260_gpio1_automute(struct hda_codec
*codec
)
4767 struct alc_spec
*spec
= codec
->spec
;
4768 snd_hda_codec_write(codec
, 0x01, 0, AC_VERB_SET_GPIO_DATA
,
4769 spec
->hp_jack_present
);
4772 static void alc260_fixup_gpio1_toggle(struct hda_codec
*codec
,
4773 const struct alc_fixup
*fix
, int action
)
4775 struct alc_spec
*spec
= codec
->spec
;
4776 if (action
== ALC_FIXUP_ACT_PROBE
) {
4777 /* although the machine has only one output pin, we need to
4778 * toggle GPIO1 according to the jack state
4780 spec
->automute_hook
= alc260_gpio1_automute
;
4781 spec
->detect_hp
= 1;
4782 spec
->automute_speaker
= 1;
4783 spec
->autocfg
.hp_pins
[0] = 0x0f; /* copy it for automute */
4784 snd_hda_jack_detect_enable(codec
, 0x0f, ALC_HP_EVENT
);
4785 spec
->unsol_event
= alc_sku_unsol_event
;
4786 add_verb(codec
->spec
, alc_gpio1_init_verbs
);
4790 static const struct alc_fixup alc260_fixups
[] = {
4791 [ALC260_FIXUP_HP_DC5750
] = {
4792 .type
= ALC_FIXUP_PINS
,
4793 .v
.pins
= (const struct alc_pincfg
[]) {
4794 { 0x11, 0x90130110 }, /* speaker */
4798 [ALC260_FIXUP_HP_PIN_0F
] = {
4799 .type
= ALC_FIXUP_PINS
,
4800 .v
.pins
= (const struct alc_pincfg
[]) {
4801 { 0x0f, 0x01214000 }, /* HP */
4805 [ALC260_FIXUP_COEF
] = {
4806 .type
= ALC_FIXUP_VERBS
,
4807 .v
.verbs
= (const struct hda_verb
[]) {
4808 { 0x20, AC_VERB_SET_COEF_INDEX
, 0x07 },
4809 { 0x20, AC_VERB_SET_PROC_COEF
, 0x3040 },
4813 .chain_id
= ALC260_FIXUP_HP_PIN_0F
,
4815 [ALC260_FIXUP_GPIO1
] = {
4816 .type
= ALC_FIXUP_VERBS
,
4817 .v
.verbs
= alc_gpio1_init_verbs
,
4819 [ALC260_FIXUP_GPIO1_TOGGLE
] = {
4820 .type
= ALC_FIXUP_FUNC
,
4821 .v
.func
= alc260_fixup_gpio1_toggle
,
4823 .chain_id
= ALC260_FIXUP_HP_PIN_0F
,
4825 [ALC260_FIXUP_REPLACER
] = {
4826 .type
= ALC_FIXUP_VERBS
,
4827 .v
.verbs
= (const struct hda_verb
[]) {
4828 { 0x20, AC_VERB_SET_COEF_INDEX
, 0x07 },
4829 { 0x20, AC_VERB_SET_PROC_COEF
, 0x3050 },
4833 .chain_id
= ALC260_FIXUP_GPIO1_TOGGLE
,
4835 [ALC260_FIXUP_HP_B1900
] = {
4836 .type
= ALC_FIXUP_FUNC
,
4837 .v
.func
= alc260_fixup_gpio1_toggle
,
4839 .chain_id
= ALC260_FIXUP_COEF
,
4843 static const struct snd_pci_quirk alc260_fixup_tbl
[] = {
4844 SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_FIXUP_GPIO1
),
4845 SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF
),
4846 SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1
),
4847 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750
),
4848 SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900
),
4849 SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1
),
4850 SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER
),
4851 SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_FIXUP_COEF
),
4857 static int patch_alc260(struct hda_codec
*codec
)
4859 struct alc_spec
*spec
;
4862 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
4868 spec
->mixer_nid
= 0x07;
4870 alc_pick_fixup(codec
, NULL
, alc260_fixup_tbl
, alc260_fixups
);
4871 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
4873 /* automatic parse from the BIOS config */
4874 err
= alc260_parse_auto_config(codec
);
4878 if (!spec
->no_analog
&& !spec
->adc_nids
) {
4879 alc_auto_fill_adc_caps(codec
);
4880 alc_rebuild_imux_for_auto_mic(codec
);
4881 alc_remove_invalid_adc_nids(codec
);
4884 if (!spec
->no_analog
&& !spec
->cap_mixer
)
4885 set_capture_mixer(codec
);
4887 if (!spec
->no_analog
) {
4888 err
= snd_hda_attach_beep_device(codec
, 0x1);
4891 set_beep_amp(spec
, 0x07, 0x05, HDA_INPUT
);
4894 codec
->patch_ops
= alc_patch_ops
;
4895 spec
->init_hook
= alc_auto_init_std
;
4896 spec
->shutup
= alc_eapd_shutup
;
4897 #ifdef CONFIG_SND_HDA_POWER_SAVE
4898 if (!spec
->loopback
.amplist
)
4899 spec
->loopback
.amplist
= alc260_loopbacks
;
4902 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
4913 * ALC882/883/885/888/889 support
4915 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
4916 * configuration. Each pin widget can choose any input DACs and a mixer.
4917 * Each ADC is connected from a mixer of all inputs. This makes possible
4918 * 6-channel independent captures.
4920 * In addition, an independent DAC for the multi-playback (not used in this
4923 #ifdef CONFIG_SND_HDA_POWER_SAVE
4924 #define alc882_loopbacks alc880_loopbacks
4931 ALC882_FIXUP_ABIT_AW9D_MAX
,
4932 ALC882_FIXUP_LENOVO_Y530
,
4933 ALC882_FIXUP_PB_M5210
,
4934 ALC882_FIXUP_ACER_ASPIRE_7736
,
4935 ALC882_FIXUP_ASUS_W90V
,
4936 ALC889_FIXUP_VAIO_TT
,
4937 ALC888_FIXUP_EEE1601
,
4940 ALC883_FIXUP_ACER_EAPD
,
4943 ALC882_FIXUP_ASUS_W2JC
,
4944 ALC882_FIXUP_ACER_ASPIRE_4930G
,
4945 ALC882_FIXUP_ACER_ASPIRE_8930G
,
4946 ALC882_FIXUP_ASPIRE_8930G_VERBS
,
4947 ALC885_FIXUP_MACPRO_GPIO
,
4948 ALC889_FIXUP_DAC_ROUTE
,
4951 static void alc889_fixup_coef(struct hda_codec
*codec
,
4952 const struct alc_fixup
*fix
, int action
)
4954 if (action
!= ALC_FIXUP_ACT_INIT
)
4956 alc889_coef_init(codec
);
4959 /* toggle speaker-output according to the hp-jack state */
4960 static void alc882_gpio_mute(struct hda_codec
*codec
, int pin
, int muted
)
4962 unsigned int gpiostate
, gpiomask
, gpiodir
;
4964 gpiostate
= snd_hda_codec_read(codec
, codec
->afg
, 0,
4965 AC_VERB_GET_GPIO_DATA
, 0);
4968 gpiostate
|= (1 << pin
);
4970 gpiostate
&= ~(1 << pin
);
4972 gpiomask
= snd_hda_codec_read(codec
, codec
->afg
, 0,
4973 AC_VERB_GET_GPIO_MASK
, 0);
4974 gpiomask
|= (1 << pin
);
4976 gpiodir
= snd_hda_codec_read(codec
, codec
->afg
, 0,
4977 AC_VERB_GET_GPIO_DIRECTION
, 0);
4978 gpiodir
|= (1 << pin
);
4981 snd_hda_codec_write(codec
, codec
->afg
, 0,
4982 AC_VERB_SET_GPIO_MASK
, gpiomask
);
4983 snd_hda_codec_write(codec
, codec
->afg
, 0,
4984 AC_VERB_SET_GPIO_DIRECTION
, gpiodir
);
4988 snd_hda_codec_write(codec
, codec
->afg
, 0,
4989 AC_VERB_SET_GPIO_DATA
, gpiostate
);
4992 /* set up GPIO at initialization */
4993 static void alc885_fixup_macpro_gpio(struct hda_codec
*codec
,
4994 const struct alc_fixup
*fix
, int action
)
4996 if (action
!= ALC_FIXUP_ACT_INIT
)
4998 alc882_gpio_mute(codec
, 0, 0);
4999 alc882_gpio_mute(codec
, 1, 0);
5002 /* Fix the connection of some pins for ALC889:
5003 * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
5004 * work correctly (bko#42740)
5006 static void alc889_fixup_dac_route(struct hda_codec
*codec
,
5007 const struct alc_fixup
*fix
, int action
)
5009 if (action
== ALC_FIXUP_ACT_PRE_PROBE
) {
5010 hda_nid_t conn1
[2] = { 0x0c, 0x0d };
5011 hda_nid_t conn2
[2] = { 0x0e, 0x0f };
5012 snd_hda_override_conn_list(codec
, 0x14, 2, conn1
);
5013 snd_hda_override_conn_list(codec
, 0x15, 2, conn1
);
5014 snd_hda_override_conn_list(codec
, 0x18, 2, conn2
);
5015 snd_hda_override_conn_list(codec
, 0x1a, 2, conn2
);
5019 static const struct alc_fixup alc882_fixups
[] = {
5020 [ALC882_FIXUP_ABIT_AW9D_MAX
] = {
5021 .type
= ALC_FIXUP_PINS
,
5022 .v
.pins
= (const struct alc_pincfg
[]) {
5023 { 0x15, 0x01080104 }, /* side */
5024 { 0x16, 0x01011012 }, /* rear */
5025 { 0x17, 0x01016011 }, /* clfe */
5029 [ALC882_FIXUP_LENOVO_Y530
] = {
5030 .type
= ALC_FIXUP_PINS
,
5031 .v
.pins
= (const struct alc_pincfg
[]) {
5032 { 0x15, 0x99130112 }, /* rear int speakers */
5033 { 0x16, 0x99130111 }, /* subwoofer */
5037 [ALC882_FIXUP_PB_M5210
] = {
5038 .type
= ALC_FIXUP_VERBS
,
5039 .v
.verbs
= (const struct hda_verb
[]) {
5040 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_VREF50
},
5044 [ALC882_FIXUP_ACER_ASPIRE_7736
] = {
5045 .type
= ALC_FIXUP_SKU
,
5046 .v
.sku
= ALC_FIXUP_SKU_IGNORE
,
5048 [ALC882_FIXUP_ASUS_W90V
] = {
5049 .type
= ALC_FIXUP_PINS
,
5050 .v
.pins
= (const struct alc_pincfg
[]) {
5051 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
5055 [ALC889_FIXUP_VAIO_TT
] = {
5056 .type
= ALC_FIXUP_PINS
,
5057 .v
.pins
= (const struct alc_pincfg
[]) {
5058 { 0x17, 0x90170111 }, /* hidden surround speaker */
5062 [ALC888_FIXUP_EEE1601
] = {
5063 .type
= ALC_FIXUP_VERBS
,
5064 .v
.verbs
= (const struct hda_verb
[]) {
5065 { 0x20, AC_VERB_SET_COEF_INDEX
, 0x0b },
5066 { 0x20, AC_VERB_SET_PROC_COEF
, 0x0838 },
5070 [ALC882_FIXUP_EAPD
] = {
5071 .type
= ALC_FIXUP_VERBS
,
5072 .v
.verbs
= (const struct hda_verb
[]) {
5073 /* change to EAPD mode */
5074 { 0x20, AC_VERB_SET_COEF_INDEX
, 0x07 },
5075 { 0x20, AC_VERB_SET_PROC_COEF
, 0x3060 },
5079 [ALC883_FIXUP_EAPD
] = {
5080 .type
= ALC_FIXUP_VERBS
,
5081 .v
.verbs
= (const struct hda_verb
[]) {
5082 /* change to EAPD mode */
5083 { 0x20, AC_VERB_SET_COEF_INDEX
, 0x07 },
5084 { 0x20, AC_VERB_SET_PROC_COEF
, 0x3070 },
5088 [ALC883_FIXUP_ACER_EAPD
] = {
5089 .type
= ALC_FIXUP_VERBS
,
5090 .v
.verbs
= (const struct hda_verb
[]) {
5091 /* eanable EAPD on Acer laptops */
5092 { 0x20, AC_VERB_SET_COEF_INDEX
, 0x07 },
5093 { 0x20, AC_VERB_SET_PROC_COEF
, 0x3050 },
5097 [ALC882_FIXUP_GPIO3
] = {
5098 .type
= ALC_FIXUP_VERBS
,
5099 .v
.verbs
= alc_gpio3_init_verbs
,
5101 [ALC882_FIXUP_ASUS_W2JC
] = {
5102 .type
= ALC_FIXUP_VERBS
,
5103 .v
.verbs
= alc_gpio1_init_verbs
,
5105 .chain_id
= ALC882_FIXUP_EAPD
,
5107 [ALC889_FIXUP_COEF
] = {
5108 .type
= ALC_FIXUP_FUNC
,
5109 .v
.func
= alc889_fixup_coef
,
5111 [ALC882_FIXUP_ACER_ASPIRE_4930G
] = {
5112 .type
= ALC_FIXUP_PINS
,
5113 .v
.pins
= (const struct alc_pincfg
[]) {
5114 { 0x16, 0x99130111 }, /* CLFE speaker */
5115 { 0x17, 0x99130112 }, /* surround speaker */
5119 [ALC882_FIXUP_ACER_ASPIRE_8930G
] = {
5120 .type
= ALC_FIXUP_PINS
,
5121 .v
.pins
= (const struct alc_pincfg
[]) {
5122 { 0x16, 0x99130111 }, /* CLFE speaker */
5123 { 0x1b, 0x99130112 }, /* surround speaker */
5127 .chain_id
= ALC882_FIXUP_ASPIRE_8930G_VERBS
,
5129 [ALC882_FIXUP_ASPIRE_8930G_VERBS
] = {
5130 /* additional init verbs for Acer Aspire 8930G */
5131 .type
= ALC_FIXUP_VERBS
,
5132 .v
.verbs
= (const struct hda_verb
[]) {
5133 /* Enable all DACs */
5134 /* DAC DISABLE/MUTE 1? */
5135 /* setting bits 1-5 disables DAC nids 0x02-0x06
5136 * apparently. Init=0x38 */
5137 { 0x20, AC_VERB_SET_COEF_INDEX
, 0x03 },
5138 { 0x20, AC_VERB_SET_PROC_COEF
, 0x0000 },
5139 /* DAC DISABLE/MUTE 2? */
5140 /* some bit here disables the other DACs.
5142 { 0x20, AC_VERB_SET_COEF_INDEX
, 0x08 },
5143 { 0x20, AC_VERB_SET_PROC_COEF
, 0x0000 },
5145 * This laptop has a stereo digital microphone.
5146 * The mics are only 1cm apart which makes the stereo
5147 * useless. However, either the mic or the ALC889
5148 * makes the signal become a difference/sum signal
5149 * instead of standard stereo, which is annoying.
5150 * So instead we flip this bit which makes the
5151 * codec replicate the sum signal to both channels,
5152 * turning it into a normal mono mic.
5154 /* DMIC_CONTROL? Init value = 0x0001 */
5155 { 0x20, AC_VERB_SET_COEF_INDEX
, 0x0b },
5156 { 0x20, AC_VERB_SET_PROC_COEF
, 0x0003 },
5157 { 0x20, AC_VERB_SET_COEF_INDEX
, 0x07 },
5158 { 0x20, AC_VERB_SET_PROC_COEF
, 0x3050 },
5162 [ALC885_FIXUP_MACPRO_GPIO
] = {
5163 .type
= ALC_FIXUP_FUNC
,
5164 .v
.func
= alc885_fixup_macpro_gpio
,
5166 [ALC889_FIXUP_DAC_ROUTE
] = {
5167 .type
= ALC_FIXUP_FUNC
,
5168 .v
.func
= alc889_fixup_dac_route
,
5172 static const struct snd_pci_quirk alc882_fixup_tbl
[] = {
5173 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD
),
5174 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD
),
5175 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD
),
5176 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD
),
5177 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD
),
5178 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD
),
5179 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
5180 ALC882_FIXUP_ACER_ASPIRE_4930G
),
5181 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
5182 ALC882_FIXUP_ACER_ASPIRE_4930G
),
5183 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
5184 ALC882_FIXUP_ACER_ASPIRE_8930G
),
5185 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
5186 ALC882_FIXUP_ACER_ASPIRE_8930G
),
5187 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
5188 ALC882_FIXUP_ACER_ASPIRE_4930G
),
5189 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
5190 ALC882_FIXUP_ACER_ASPIRE_4930G
),
5191 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
5192 ALC882_FIXUP_ACER_ASPIRE_4930G
),
5193 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210
),
5194 SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE
),
5195 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736
),
5196 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD
),
5197 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V
),
5198 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC
),
5199 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601
),
5200 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT
),
5202 /* All Apple entries are in codec SSIDs */
5203 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO
),
5204 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO
),
5205 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO
),
5206 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD
),
5207 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO
),
5209 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD
),
5210 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3
),
5211 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX
),
5212 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD
),
5213 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD
),
5214 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530
),
5215 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF
),
5220 * BIOS auto configuration
5222 /* almost identical with ALC880 parser... */
5223 static int alc882_parse_auto_config(struct hda_codec
*codec
)
5225 static const hda_nid_t alc882_ignore
[] = { 0x1d, 0 };
5226 static const hda_nid_t alc882_ssids
[] = { 0x15, 0x1b, 0x14, 0 };
5227 return alc_parse_auto_config(codec
, alc882_ignore
, alc882_ssids
);
5232 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
5233 #include "alc882_quirks.c"
5236 static int patch_alc882(struct hda_codec
*codec
)
5238 struct alc_spec
*spec
;
5239 int err
, board_config
;
5241 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
5247 spec
->mixer_nid
= 0x0b;
5249 switch (codec
->vendor_id
) {
5254 /* ALC883 and variants */
5255 alc_fix_pll_init(codec
, 0x20, 0x0a, 10);
5259 err
= alc_codec_rename_from_preset(codec
);
5263 board_config
= alc_board_config(codec
, ALC882_MODEL_LAST
,
5264 alc882_models
, NULL
);
5265 if (board_config
< 0)
5266 board_config
= alc_board_codec_sid_config(codec
,
5267 ALC882_MODEL_LAST
, alc882_models
, alc882_ssid_cfg_tbl
);
5269 if (board_config
< 0) {
5270 printk(KERN_INFO
"hda_codec: %s: BIOS auto-probing.\n",
5272 board_config
= ALC_MODEL_AUTO
;
5275 if (board_config
== ALC_MODEL_AUTO
) {
5276 alc_pick_fixup(codec
, NULL
, alc882_fixup_tbl
, alc882_fixups
);
5277 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
5280 alc_auto_parse_customize_define(codec
);
5282 if (board_config
== ALC_MODEL_AUTO
) {
5283 /* automatic parse from the BIOS config */
5284 err
= alc882_parse_auto_config(codec
);
5289 if (board_config
!= ALC_MODEL_AUTO
) {
5290 setup_preset(codec
, &alc882_presets
[board_config
]);
5291 spec
->vmaster_nid
= 0x0c;
5294 if (!spec
->no_analog
&& !spec
->adc_nids
) {
5295 alc_auto_fill_adc_caps(codec
);
5296 alc_rebuild_imux_for_auto_mic(codec
);
5297 alc_remove_invalid_adc_nids(codec
);
5300 if (!spec
->no_analog
&& !spec
->cap_mixer
)
5301 set_capture_mixer(codec
);
5303 if (!spec
->no_analog
&& has_cdefine_beep(codec
)) {
5304 err
= snd_hda_attach_beep_device(codec
, 0x1);
5307 set_beep_amp(spec
, 0x0b, 0x05, HDA_INPUT
);
5310 codec
->patch_ops
= alc_patch_ops
;
5311 if (board_config
== ALC_MODEL_AUTO
)
5312 spec
->init_hook
= alc_auto_init_std
;
5314 codec
->patch_ops
.build_controls
= __alc_build_controls
;
5316 #ifdef CONFIG_SND_HDA_POWER_SAVE
5317 if (!spec
->loopback
.amplist
)
5318 spec
->loopback
.amplist
= alc882_loopbacks
;
5321 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
5334 static int alc262_parse_auto_config(struct hda_codec
*codec
)
5336 static const hda_nid_t alc262_ignore
[] = { 0x1d, 0 };
5337 static const hda_nid_t alc262_ssids
[] = { 0x15, 0x1b, 0x14, 0 };
5338 return alc_parse_auto_config(codec
, alc262_ignore
, alc262_ssids
);
5345 ALC262_FIXUP_FSC_H270
,
5346 ALC262_FIXUP_HP_Z200
,
5348 ALC262_FIXUP_LENOVO_3000
,
5350 ALC262_FIXUP_BENQ_T31
,
5353 static const struct alc_fixup alc262_fixups
[] = {
5354 [ALC262_FIXUP_FSC_H270
] = {
5355 .type
= ALC_FIXUP_PINS
,
5356 .v
.pins
= (const struct alc_pincfg
[]) {
5357 { 0x14, 0x99130110 }, /* speaker */
5358 { 0x15, 0x0221142f }, /* front HP */
5359 { 0x1b, 0x0121141f }, /* rear HP */
5363 [ALC262_FIXUP_HP_Z200
] = {
5364 .type
= ALC_FIXUP_PINS
,
5365 .v
.pins
= (const struct alc_pincfg
[]) {
5366 { 0x16, 0x99130120 }, /* internal speaker */
5370 [ALC262_FIXUP_TYAN
] = {
5371 .type
= ALC_FIXUP_PINS
,
5372 .v
.pins
= (const struct alc_pincfg
[]) {
5373 { 0x14, 0x1993e1f0 }, /* int AUX */
5377 [ALC262_FIXUP_LENOVO_3000
] = {
5378 .type
= ALC_FIXUP_VERBS
,
5379 .v
.verbs
= (const struct hda_verb
[]) {
5380 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_VREF50
},
5384 .chain_id
= ALC262_FIXUP_BENQ
,
5386 [ALC262_FIXUP_BENQ
] = {
5387 .type
= ALC_FIXUP_VERBS
,
5388 .v
.verbs
= (const struct hda_verb
[]) {
5389 { 0x20, AC_VERB_SET_COEF_INDEX
, 0x07 },
5390 { 0x20, AC_VERB_SET_PROC_COEF
, 0x3070 },
5394 [ALC262_FIXUP_BENQ_T31
] = {
5395 .type
= ALC_FIXUP_VERBS
,
5396 .v
.verbs
= (const struct hda_verb
[]) {
5397 { 0x20, AC_VERB_SET_COEF_INDEX
, 0x07 },
5398 { 0x20, AC_VERB_SET_PROC_COEF
, 0x3050 },
5404 static const struct snd_pci_quirk alc262_fixup_tbl
[] = {
5405 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200
),
5406 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ
),
5407 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ
),
5408 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN
),
5409 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270
),
5410 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000
),
5411 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ
),
5412 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31
),
5417 #ifdef CONFIG_SND_HDA_POWER_SAVE
5418 #define alc262_loopbacks alc880_loopbacks
5423 static int patch_alc262(struct hda_codec
*codec
)
5425 struct alc_spec
*spec
;
5428 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
5434 spec
->mixer_nid
= 0x0b;
5437 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
5442 snd_hda_codec_write(codec
, 0x1a, 0, AC_VERB_SET_COEF_INDEX
, 7);
5443 tmp
= snd_hda_codec_read(codec
, 0x20, 0, AC_VERB_GET_PROC_COEF
, 0);
5444 snd_hda_codec_write(codec
, 0x1a, 0, AC_VERB_SET_COEF_INDEX
, 7);
5445 snd_hda_codec_write(codec
, 0x1a, 0, AC_VERB_SET_PROC_COEF
, tmp
| 0x80);
5448 alc_auto_parse_customize_define(codec
);
5450 alc_fix_pll_init(codec
, 0x20, 0x0a, 10);
5452 alc_pick_fixup(codec
, NULL
, alc262_fixup_tbl
, alc262_fixups
);
5453 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
5455 /* automatic parse from the BIOS config */
5456 err
= alc262_parse_auto_config(codec
);
5460 if (!spec
->no_analog
&& !spec
->adc_nids
) {
5461 alc_auto_fill_adc_caps(codec
);
5462 alc_rebuild_imux_for_auto_mic(codec
);
5463 alc_remove_invalid_adc_nids(codec
);
5466 if (!spec
->no_analog
&& !spec
->cap_mixer
)
5467 set_capture_mixer(codec
);
5469 if (!spec
->no_analog
&& has_cdefine_beep(codec
)) {
5470 err
= snd_hda_attach_beep_device(codec
, 0x1);
5473 set_beep_amp(spec
, 0x0b, 0x05, HDA_INPUT
);
5476 codec
->patch_ops
= alc_patch_ops
;
5477 spec
->init_hook
= alc_auto_init_std
;
5478 spec
->shutup
= alc_eapd_shutup
;
5480 #ifdef CONFIG_SND_HDA_POWER_SAVE
5481 if (!spec
->loopback
.amplist
)
5482 spec
->loopback
.amplist
= alc262_loopbacks
;
5485 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
5497 /* bind Beep switches of both NID 0x0f and 0x10 */
5498 static const struct hda_bind_ctls alc268_bind_beep_sw
= {
5499 .ops
= &snd_hda_bind_sw
,
5501 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT
),
5502 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT
),
5507 static const struct snd_kcontrol_new alc268_beep_mixer
[] = {
5508 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT
),
5509 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw
),
5513 /* set PCBEEP vol = 0, mute connections */
5514 static const struct hda_verb alc268_beep_init_verbs
[] = {
5515 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
5516 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(1)},
5517 {0x10, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(1)},
5522 * BIOS auto configuration
5524 static int alc268_parse_auto_config(struct hda_codec
*codec
)
5526 static const hda_nid_t alc268_ssids
[] = { 0x15, 0x1b, 0x14, 0 };
5527 struct alc_spec
*spec
= codec
->spec
;
5528 int err
= alc_parse_auto_config(codec
, NULL
, alc268_ssids
);
5530 if (!spec
->no_analog
&& spec
->autocfg
.speaker_pins
[0] != 0x1d) {
5531 add_mixer(spec
, alc268_beep_mixer
);
5532 add_verb(spec
, alc268_beep_init_verbs
);
5540 static int patch_alc268(struct hda_codec
*codec
)
5542 struct alc_spec
*spec
;
5543 int i
, has_beep
, err
;
5545 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
5551 /* ALC268 has no aa-loopback mixer */
5553 /* automatic parse from the BIOS config */
5554 err
= alc268_parse_auto_config(codec
);
5559 for (i
= 0; i
< spec
->num_mixers
; i
++) {
5560 if (spec
->mixers
[i
] == alc268_beep_mixer
) {
5567 err
= snd_hda_attach_beep_device(codec
, 0x1);
5570 if (!query_amp_caps(codec
, 0x1d, HDA_INPUT
))
5571 /* override the amp caps for beep generator */
5572 snd_hda_override_amp_caps(codec
, 0x1d, HDA_INPUT
,
5573 (0x0c << AC_AMPCAP_OFFSET_SHIFT
) |
5574 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT
) |
5575 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT
) |
5576 (0 << AC_AMPCAP_MUTE_SHIFT
));
5579 if (!spec
->no_analog
&& !spec
->adc_nids
) {
5580 alc_auto_fill_adc_caps(codec
);
5581 alc_rebuild_imux_for_auto_mic(codec
);
5582 alc_remove_invalid_adc_nids(codec
);
5585 if (!spec
->no_analog
&& !spec
->cap_mixer
)
5586 set_capture_mixer(codec
);
5588 codec
->patch_ops
= alc_patch_ops
;
5589 spec
->init_hook
= alc_auto_init_std
;
5590 spec
->shutup
= alc_eapd_shutup
;
5602 #ifdef CONFIG_SND_HDA_POWER_SAVE
5603 #define alc269_loopbacks alc880_loopbacks
5606 static const struct hda_pcm_stream alc269_44k_pcm_analog_playback
= {
5610 .rates
= SNDRV_PCM_RATE_44100
, /* fixed rate */
5611 /* NID is set in alc_build_pcms */
5613 .open
= alc_playback_pcm_open
,
5614 .prepare
= alc_playback_pcm_prepare
,
5615 .cleanup
= alc_playback_pcm_cleanup
5619 static const struct hda_pcm_stream alc269_44k_pcm_analog_capture
= {
5623 .rates
= SNDRV_PCM_RATE_44100
, /* fixed rate */
5624 /* NID is set in alc_build_pcms */
5627 #ifdef CONFIG_SND_HDA_POWER_SAVE
5628 static int alc269_mic2_for_mute_led(struct hda_codec
*codec
)
5630 switch (codec
->subsystem_id
) {
5637 static int alc269_mic2_mute_check_ps(struct hda_codec
*codec
, hda_nid_t nid
)
5639 /* update mute-LED according to the speaker mute state */
5640 if (nid
== 0x01 || nid
== 0x14) {
5642 if (snd_hda_codec_amp_read(codec
, 0x14, 0, HDA_OUTPUT
, 0) &
5647 /* mic2 vref pin is used for mute LED control */
5648 snd_hda_codec_update_cache(codec
, 0x19, 0,
5649 AC_VERB_SET_PIN_WIDGET_CONTROL
,
5652 return alc_check_power_status(codec
, nid
);
5654 #endif /* CONFIG_SND_HDA_POWER_SAVE */
5656 /* different alc269-variants */
5658 ALC269_TYPE_ALC269VA
,
5659 ALC269_TYPE_ALC269VB
,
5660 ALC269_TYPE_ALC269VC
,
5664 * BIOS auto configuration
5666 static int alc269_parse_auto_config(struct hda_codec
*codec
)
5668 static const hda_nid_t alc269_ignore
[] = { 0x1d, 0 };
5669 static const hda_nid_t alc269_ssids
[] = { 0, 0x1b, 0x14, 0x21 };
5670 static const hda_nid_t alc269va_ssids
[] = { 0x15, 0x1b, 0x14, 0 };
5671 struct alc_spec
*spec
= codec
->spec
;
5672 const hda_nid_t
*ssids
= spec
->codec_variant
== ALC269_TYPE_ALC269VA
?
5673 alc269va_ssids
: alc269_ssids
;
5675 return alc_parse_auto_config(codec
, alc269_ignore
, ssids
);
5678 static void alc269_toggle_power_output(struct hda_codec
*codec
, int power_up
)
5680 int val
= alc_read_coef_idx(codec
, 0x04);
5685 alc_write_coef_idx(codec
, 0x04, val
);
5688 static void alc269_shutup(struct hda_codec
*codec
)
5690 if ((alc_get_coef0(codec
) & 0x00ff) == 0x017)
5691 alc269_toggle_power_output(codec
, 0);
5692 if ((alc_get_coef0(codec
) & 0x00ff) == 0x018) {
5693 alc269_toggle_power_output(codec
, 0);
5699 static int alc269_resume(struct hda_codec
*codec
)
5701 if ((alc_get_coef0(codec
) & 0x00ff) == 0x018) {
5702 alc269_toggle_power_output(codec
, 0);
5706 codec
->patch_ops
.init(codec
);
5708 if ((alc_get_coef0(codec
) & 0x00ff) == 0x017) {
5709 alc269_toggle_power_output(codec
, 1);
5713 if ((alc_get_coef0(codec
) & 0x00ff) == 0x018)
5714 alc269_toggle_power_output(codec
, 1);
5716 snd_hda_codec_resume_amp(codec
);
5717 snd_hda_codec_resume_cache(codec
);
5718 hda_call_check_power_status(codec
, 0x01);
5721 #endif /* CONFIG_PM */
5723 static void alc269_fixup_hweq(struct hda_codec
*codec
,
5724 const struct alc_fixup
*fix
, int action
)
5728 if (action
!= ALC_FIXUP_ACT_INIT
)
5730 coef
= alc_read_coef_idx(codec
, 0x1e);
5731 alc_write_coef_idx(codec
, 0x1e, coef
| 0x80);
5734 static void alc271_fixup_dmic(struct hda_codec
*codec
,
5735 const struct alc_fixup
*fix
, int action
)
5737 static const struct hda_verb verbs
[] = {
5738 {0x20, AC_VERB_SET_COEF_INDEX
, 0x0d},
5739 {0x20, AC_VERB_SET_PROC_COEF
, 0x4000},
5744 if (strcmp(codec
->chip_name
, "ALC271X"))
5746 cfg
= snd_hda_codec_get_pincfg(codec
, 0x12);
5747 if (get_defcfg_connect(cfg
) == AC_JACK_PORT_FIXED
)
5748 snd_hda_sequence_write(codec
, verbs
);
5751 static void alc269_fixup_pcm_44k(struct hda_codec
*codec
,
5752 const struct alc_fixup
*fix
, int action
)
5754 struct alc_spec
*spec
= codec
->spec
;
5756 if (action
!= ALC_FIXUP_ACT_PROBE
)
5759 /* Due to a hardware problem on Lenovo Ideadpad, we need to
5760 * fix the sample rate of analog I/O to 44.1kHz
5762 spec
->stream_analog_playback
= &alc269_44k_pcm_analog_playback
;
5763 spec
->stream_analog_capture
= &alc269_44k_pcm_analog_capture
;
5766 static void alc269_fixup_stereo_dmic(struct hda_codec
*codec
,
5767 const struct alc_fixup
*fix
, int action
)
5771 if (action
!= ALC_FIXUP_ACT_INIT
)
5773 /* The digital-mic unit sends PDM (differential signal) instead of
5774 * the standard PCM, thus you can't record a valid mono stream as is.
5775 * Below is a workaround specific to ALC269 to control the dmic
5776 * signal source as mono.
5778 coef
= alc_read_coef_idx(codec
, 0x07);
5779 alc_write_coef_idx(codec
, 0x07, coef
| 0x80);
5782 static void alc269_quanta_automute(struct hda_codec
*codec
)
5784 update_outputs(codec
);
5786 snd_hda_codec_write(codec
, 0x20, 0,
5787 AC_VERB_SET_COEF_INDEX
, 0x0c);
5788 snd_hda_codec_write(codec
, 0x20, 0,
5789 AC_VERB_SET_PROC_COEF
, 0x680);
5791 snd_hda_codec_write(codec
, 0x20, 0,
5792 AC_VERB_SET_COEF_INDEX
, 0x0c);
5793 snd_hda_codec_write(codec
, 0x20, 0,
5794 AC_VERB_SET_PROC_COEF
, 0x480);
5797 static void alc269_fixup_quanta_mute(struct hda_codec
*codec
,
5798 const struct alc_fixup
*fix
, int action
)
5800 struct alc_spec
*spec
= codec
->spec
;
5801 if (action
!= ALC_FIXUP_ACT_PROBE
)
5803 spec
->automute_hook
= alc269_quanta_automute
;
5807 ALC269_FIXUP_SONY_VAIO
,
5808 ALC275_FIXUP_SONY_VAIO_GPIO2
,
5809 ALC269_FIXUP_DELL_M101Z
,
5810 ALC269_FIXUP_SKU_IGNORE
,
5811 ALC269_FIXUP_ASUS_G73JW
,
5812 ALC269_FIXUP_LENOVO_EAPD
,
5813 ALC275_FIXUP_SONY_HWEQ
,
5815 ALC269_FIXUP_PCM_44K
,
5816 ALC269_FIXUP_STEREO_DMIC
,
5817 ALC269_FIXUP_QUANTA_MUTE
,
5818 ALC269_FIXUP_LIFEBOOK
,
5821 ALC269VB_FIXUP_AMIC
,
5822 ALC269VB_FIXUP_DMIC
,
5825 static const struct alc_fixup alc269_fixups
[] = {
5826 [ALC269_FIXUP_SONY_VAIO
] = {
5827 .type
= ALC_FIXUP_VERBS
,
5828 .v
.verbs
= (const struct hda_verb
[]) {
5829 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_VREFGRD
},
5833 [ALC275_FIXUP_SONY_VAIO_GPIO2
] = {
5834 .type
= ALC_FIXUP_VERBS
,
5835 .v
.verbs
= (const struct hda_verb
[]) {
5836 {0x01, AC_VERB_SET_GPIO_MASK
, 0x04},
5837 {0x01, AC_VERB_SET_GPIO_DIRECTION
, 0x04},
5838 {0x01, AC_VERB_SET_GPIO_DATA
, 0x00},
5842 .chain_id
= ALC269_FIXUP_SONY_VAIO
5844 [ALC269_FIXUP_DELL_M101Z
] = {
5845 .type
= ALC_FIXUP_VERBS
,
5846 .v
.verbs
= (const struct hda_verb
[]) {
5847 /* Enables internal speaker */
5848 {0x20, AC_VERB_SET_COEF_INDEX
, 13},
5849 {0x20, AC_VERB_SET_PROC_COEF
, 0x4040},
5853 [ALC269_FIXUP_SKU_IGNORE
] = {
5854 .type
= ALC_FIXUP_SKU
,
5855 .v
.sku
= ALC_FIXUP_SKU_IGNORE
,
5857 [ALC269_FIXUP_ASUS_G73JW
] = {
5858 .type
= ALC_FIXUP_PINS
,
5859 .v
.pins
= (const struct alc_pincfg
[]) {
5860 { 0x17, 0x99130111 }, /* subwoofer */
5864 [ALC269_FIXUP_LENOVO_EAPD
] = {
5865 .type
= ALC_FIXUP_VERBS
,
5866 .v
.verbs
= (const struct hda_verb
[]) {
5867 {0x14, AC_VERB_SET_EAPD_BTLENABLE
, 0},
5871 [ALC275_FIXUP_SONY_HWEQ
] = {
5872 .type
= ALC_FIXUP_FUNC
,
5873 .v
.func
= alc269_fixup_hweq
,
5875 .chain_id
= ALC275_FIXUP_SONY_VAIO_GPIO2
5877 [ALC271_FIXUP_DMIC
] = {
5878 .type
= ALC_FIXUP_FUNC
,
5879 .v
.func
= alc271_fixup_dmic
,
5881 [ALC269_FIXUP_PCM_44K
] = {
5882 .type
= ALC_FIXUP_FUNC
,
5883 .v
.func
= alc269_fixup_pcm_44k
,
5885 [ALC269_FIXUP_STEREO_DMIC
] = {
5886 .type
= ALC_FIXUP_FUNC
,
5887 .v
.func
= alc269_fixup_stereo_dmic
,
5889 [ALC269_FIXUP_QUANTA_MUTE
] = {
5890 .type
= ALC_FIXUP_FUNC
,
5891 .v
.func
= alc269_fixup_quanta_mute
,
5893 [ALC269_FIXUP_LIFEBOOK
] = {
5894 .type
= ALC_FIXUP_PINS
,
5895 .v
.pins
= (const struct alc_pincfg
[]) {
5896 { 0x1a, 0x2101103f }, /* dock line-out */
5897 { 0x1b, 0x23a11040 }, /* dock mic-in */
5901 .chain_id
= ALC269_FIXUP_QUANTA_MUTE
5903 [ALC269_FIXUP_AMIC
] = {
5904 .type
= ALC_FIXUP_PINS
,
5905 .v
.pins
= (const struct alc_pincfg
[]) {
5906 { 0x14, 0x99130110 }, /* speaker */
5907 { 0x15, 0x0121401f }, /* HP out */
5908 { 0x18, 0x01a19c20 }, /* mic */
5909 { 0x19, 0x99a3092f }, /* int-mic */
5913 [ALC269_FIXUP_DMIC
] = {
5914 .type
= ALC_FIXUP_PINS
,
5915 .v
.pins
= (const struct alc_pincfg
[]) {
5916 { 0x12, 0x99a3092f }, /* int-mic */
5917 { 0x14, 0x99130110 }, /* speaker */
5918 { 0x15, 0x0121401f }, /* HP out */
5919 { 0x18, 0x01a19c20 }, /* mic */
5923 [ALC269VB_FIXUP_AMIC
] = {
5924 .type
= ALC_FIXUP_PINS
,
5925 .v
.pins
= (const struct alc_pincfg
[]) {
5926 { 0x14, 0x99130110 }, /* speaker */
5927 { 0x18, 0x01a19c20 }, /* mic */
5928 { 0x19, 0x99a3092f }, /* int-mic */
5929 { 0x21, 0x0121401f }, /* HP out */
5933 [ALC269VB_FIXUP_DMIC
] = {
5934 .type
= ALC_FIXUP_PINS
,
5935 .v
.pins
= (const struct alc_pincfg
[]) {
5936 { 0x12, 0x99a3092f }, /* int-mic */
5937 { 0x14, 0x99130110 }, /* speaker */
5938 { 0x18, 0x01a19c20 }, /* mic */
5939 { 0x21, 0x0121401f }, /* HP out */
5945 static const struct snd_pci_quirk alc269_fixup_tbl
[] = {
5946 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW
),
5947 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC
),
5948 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC
),
5949 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC
),
5950 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC
),
5951 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC
),
5952 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2
),
5953 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ
),
5954 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ
),
5955 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO
),
5956 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z
),
5957 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC
),
5958 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK
),
5959 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE
),
5960 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE
),
5961 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE
),
5962 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE
),
5963 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE
),
5964 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_QUANTA_MUTE
),
5965 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K
),
5966 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD
),
5969 /* Below is a quirk table taken from the old code.
5970 * Basically the device should work as is without the fixup table.
5971 * If BIOS doesn't give a proper info, enable the corresponding
5974 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
5976 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC
),
5977 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC
),
5978 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC
),
5979 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC
),
5980 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC
),
5981 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC
),
5982 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC
),
5983 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC
),
5984 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC
),
5985 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC
),
5986 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC
),
5987 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC
),
5988 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC
),
5989 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC
),
5990 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC
),
5991 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC
),
5992 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC
),
5993 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC
),
5994 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC
),
5995 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC
),
5996 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC
),
5997 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC
),
5998 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC
),
5999 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC
),
6000 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC
),
6001 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC
),
6002 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC
),
6003 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC
),
6004 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC
),
6005 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC
),
6006 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC
),
6007 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC
),
6008 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC
),
6009 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC
),
6010 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC
),
6011 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC
),
6012 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC
),
6013 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC
),
6014 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC
),
6019 static const struct alc_model_fixup alc269_fixup_models
[] = {
6020 {.id
= ALC269_FIXUP_AMIC
, .name
= "laptop-amic"},
6021 {.id
= ALC269_FIXUP_DMIC
, .name
= "laptop-dmic"},
6026 static int alc269_fill_coef(struct hda_codec
*codec
)
6030 if ((alc_get_coef0(codec
) & 0x00ff) < 0x015) {
6031 alc_write_coef_idx(codec
, 0xf, 0x960b);
6032 alc_write_coef_idx(codec
, 0xe, 0x8817);
6035 if ((alc_get_coef0(codec
) & 0x00ff) == 0x016) {
6036 alc_write_coef_idx(codec
, 0xf, 0x960b);
6037 alc_write_coef_idx(codec
, 0xe, 0x8814);
6040 if ((alc_get_coef0(codec
) & 0x00ff) == 0x017) {
6041 val
= alc_read_coef_idx(codec
, 0x04);
6042 /* Power up output pin */
6043 alc_write_coef_idx(codec
, 0x04, val
| (1<<11));
6046 if ((alc_get_coef0(codec
) & 0x00ff) == 0x018) {
6047 val
= alc_read_coef_idx(codec
, 0xd);
6048 if ((val
& 0x0c00) >> 10 != 0x1) {
6049 /* Capless ramp up clock control */
6050 alc_write_coef_idx(codec
, 0xd, val
| (1<<10));
6052 val
= alc_read_coef_idx(codec
, 0x17);
6053 if ((val
& 0x01c0) >> 6 != 0x4) {
6054 /* Class D power on reset */
6055 alc_write_coef_idx(codec
, 0x17, val
| (1<<7));
6059 val
= alc_read_coef_idx(codec
, 0xd); /* Class D */
6060 alc_write_coef_idx(codec
, 0xd, val
| (1<<14));
6062 val
= alc_read_coef_idx(codec
, 0x4); /* HP */
6063 alc_write_coef_idx(codec
, 0x4, val
| (1<<11));
6070 static int patch_alc269(struct hda_codec
*codec
)
6072 struct alc_spec
*spec
;
6075 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
6081 spec
->mixer_nid
= 0x0b;
6083 alc_auto_parse_customize_define(codec
);
6085 err
= alc_codec_rename_from_preset(codec
);
6089 if (codec
->vendor_id
== 0x10ec0269) {
6090 spec
->codec_variant
= ALC269_TYPE_ALC269VA
;
6091 switch (alc_get_coef0(codec
) & 0x00f0) {
6093 if (codec
->bus
->pci
->subsystem_vendor
== 0x1025 &&
6094 spec
->cdefine
.platform_type
== 1)
6095 err
= alc_codec_rename(codec
, "ALC271X");
6096 spec
->codec_variant
= ALC269_TYPE_ALC269VB
;
6099 if (codec
->bus
->pci
->subsystem_vendor
== 0x17aa &&
6100 codec
->bus
->pci
->subsystem_device
== 0x21f3)
6101 err
= alc_codec_rename(codec
, "ALC3202");
6102 spec
->codec_variant
= ALC269_TYPE_ALC269VC
;
6105 alc_fix_pll_init(codec
, 0x20, 0x04, 15);
6109 alc269_fill_coef(codec
);
6112 alc_pick_fixup(codec
, alc269_fixup_models
,
6113 alc269_fixup_tbl
, alc269_fixups
);
6114 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
6116 /* automatic parse from the BIOS config */
6117 err
= alc269_parse_auto_config(codec
);
6121 if (!spec
->no_analog
&& !spec
->adc_nids
) {
6122 alc_auto_fill_adc_caps(codec
);
6123 alc_rebuild_imux_for_auto_mic(codec
);
6124 alc_remove_invalid_adc_nids(codec
);
6127 if (!spec
->no_analog
&& !spec
->cap_mixer
)
6128 set_capture_mixer(codec
);
6130 if (!spec
->no_analog
&& has_cdefine_beep(codec
)) {
6131 err
= snd_hda_attach_beep_device(codec
, 0x1);
6134 set_beep_amp(spec
, 0x0b, 0x04, HDA_INPUT
);
6137 codec
->patch_ops
= alc_patch_ops
;
6139 codec
->patch_ops
.resume
= alc269_resume
;
6141 spec
->init_hook
= alc_auto_init_std
;
6142 spec
->shutup
= alc269_shutup
;
6144 #ifdef CONFIG_SND_HDA_POWER_SAVE
6145 if (!spec
->loopback
.amplist
)
6146 spec
->loopback
.amplist
= alc269_loopbacks
;
6147 if (alc269_mic2_for_mute_led(codec
))
6148 codec
->patch_ops
.check_power_status
= alc269_mic2_mute_check_ps
;
6151 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
6164 static int alc861_parse_auto_config(struct hda_codec
*codec
)
6166 static const hda_nid_t alc861_ignore
[] = { 0x1d, 0 };
6167 static const hda_nid_t alc861_ssids
[] = { 0x0e, 0x0f, 0x0b, 0 };
6168 return alc_parse_auto_config(codec
, alc861_ignore
, alc861_ssids
);
6171 #ifdef CONFIG_SND_HDA_POWER_SAVE
6172 static const struct hda_amp_list alc861_loopbacks
[] = {
6173 { 0x15, HDA_INPUT
, 0 },
6174 { 0x15, HDA_INPUT
, 1 },
6175 { 0x15, HDA_INPUT
, 2 },
6176 { 0x15, HDA_INPUT
, 3 },
6182 /* Pin config fixes */
6184 ALC861_FIXUP_FSC_AMILO_PI1505
,
6185 ALC861_FIXUP_AMP_VREF_0F
,
6186 ALC861_FIXUP_NO_JACK_DETECT
,
6187 ALC861_FIXUP_ASUS_A6RP
,
6190 /* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
6191 static void alc861_fixup_asus_amp_vref_0f(struct hda_codec
*codec
,
6192 const struct alc_fixup
*fix
, int action
)
6194 struct alc_spec
*spec
= codec
->spec
;
6197 if (action
!= ALC_FIXUP_ACT_INIT
)
6199 val
= snd_hda_codec_read(codec
, 0x0f, 0,
6200 AC_VERB_GET_PIN_WIDGET_CONTROL
, 0);
6201 if (!(val
& (AC_PINCTL_IN_EN
| AC_PINCTL_OUT_EN
)))
6202 val
|= AC_PINCTL_IN_EN
;
6203 val
|= AC_PINCTL_VREF_50
;
6204 snd_hda_codec_write(codec
, 0x0f, 0,
6205 AC_VERB_SET_PIN_WIDGET_CONTROL
, val
);
6206 spec
->keep_vref_in_automute
= 1;
6209 /* suppress the jack-detection */
6210 static void alc_fixup_no_jack_detect(struct hda_codec
*codec
,
6211 const struct alc_fixup
*fix
, int action
)
6213 if (action
== ALC_FIXUP_ACT_PRE_PROBE
)
6214 codec
->no_jack_detect
= 1;
6217 static const struct alc_fixup alc861_fixups
[] = {
6218 [ALC861_FIXUP_FSC_AMILO_PI1505
] = {
6219 .type
= ALC_FIXUP_PINS
,
6220 .v
.pins
= (const struct alc_pincfg
[]) {
6221 { 0x0b, 0x0221101f }, /* HP */
6222 { 0x0f, 0x90170310 }, /* speaker */
6226 [ALC861_FIXUP_AMP_VREF_0F
] = {
6227 .type
= ALC_FIXUP_FUNC
,
6228 .v
.func
= alc861_fixup_asus_amp_vref_0f
,
6230 [ALC861_FIXUP_NO_JACK_DETECT
] = {
6231 .type
= ALC_FIXUP_FUNC
,
6232 .v
.func
= alc_fixup_no_jack_detect
,
6234 [ALC861_FIXUP_ASUS_A6RP
] = {
6235 .type
= ALC_FIXUP_FUNC
,
6236 .v
.func
= alc861_fixup_asus_amp_vref_0f
,
6238 .chain_id
= ALC861_FIXUP_NO_JACK_DETECT
,
6242 static const struct snd_pci_quirk alc861_fixup_tbl
[] = {
6243 SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP
),
6244 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", ALC861_FIXUP_AMP_VREF_0F
),
6245 SND_PCI_QUIRK(0x1462, 0x7254, "HP DX2200", ALC861_FIXUP_NO_JACK_DETECT
),
6246 SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", ALC861_FIXUP_AMP_VREF_0F
),
6247 SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", ALC861_FIXUP_AMP_VREF_0F
),
6248 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", ALC861_FIXUP_FSC_AMILO_PI1505
),
6254 static int patch_alc861(struct hda_codec
*codec
)
6256 struct alc_spec
*spec
;
6259 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
6265 spec
->mixer_nid
= 0x15;
6267 alc_pick_fixup(codec
, NULL
, alc861_fixup_tbl
, alc861_fixups
);
6268 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
6270 /* automatic parse from the BIOS config */
6271 err
= alc861_parse_auto_config(codec
);
6275 if (!spec
->no_analog
&& !spec
->adc_nids
) {
6276 alc_auto_fill_adc_caps(codec
);
6277 alc_rebuild_imux_for_auto_mic(codec
);
6278 alc_remove_invalid_adc_nids(codec
);
6281 if (!spec
->no_analog
&& !spec
->cap_mixer
)
6282 set_capture_mixer(codec
);
6284 if (!spec
->no_analog
) {
6285 err
= snd_hda_attach_beep_device(codec
, 0x23);
6288 set_beep_amp(spec
, 0x23, 0, HDA_OUTPUT
);
6291 codec
->patch_ops
= alc_patch_ops
;
6292 spec
->init_hook
= alc_auto_init_std
;
6293 #ifdef CONFIG_SND_HDA_POWER_SAVE
6294 spec
->power_hook
= alc_power_eapd
;
6295 if (!spec
->loopback
.amplist
)
6296 spec
->loopback
.amplist
= alc861_loopbacks
;
6299 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
6313 * In addition, an independent DAC
6315 #ifdef CONFIG_SND_HDA_POWER_SAVE
6316 #define alc861vd_loopbacks alc880_loopbacks
6319 static int alc861vd_parse_auto_config(struct hda_codec
*codec
)
6321 static const hda_nid_t alc861vd_ignore
[] = { 0x1d, 0 };
6322 static const hda_nid_t alc861vd_ssids
[] = { 0x15, 0x1b, 0x14, 0 };
6323 return alc_parse_auto_config(codec
, alc861vd_ignore
, alc861vd_ssids
);
6327 ALC660VD_FIX_ASUS_GPIO1
,
6328 ALC861VD_FIX_DALLAS
,
6331 /* exclude VREF80 */
6332 static void alc861vd_fixup_dallas(struct hda_codec
*codec
,
6333 const struct alc_fixup
*fix
, int action
)
6335 if (action
== ALC_FIXUP_ACT_PRE_PROBE
) {
6336 snd_hda_override_pin_caps(codec
, 0x18, 0x00001714);
6337 snd_hda_override_pin_caps(codec
, 0x19, 0x0000171c);
6341 static const struct alc_fixup alc861vd_fixups
[] = {
6342 [ALC660VD_FIX_ASUS_GPIO1
] = {
6343 .type
= ALC_FIXUP_VERBS
,
6344 .v
.verbs
= (const struct hda_verb
[]) {
6346 {0x01, AC_VERB_SET_GPIO_MASK
, 0x03},
6347 {0x01, AC_VERB_SET_GPIO_DIRECTION
, 0x01},
6348 {0x01, AC_VERB_SET_GPIO_DATA
, 0x01},
6352 [ALC861VD_FIX_DALLAS
] = {
6353 .type
= ALC_FIXUP_FUNC
,
6354 .v
.func
= alc861vd_fixup_dallas
,
6358 static const struct snd_pci_quirk alc861vd_fixup_tbl
[] = {
6359 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS
),
6360 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1
),
6361 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS
),
6365 static const struct hda_verb alc660vd_eapd_verbs
[] = {
6366 {0x14, AC_VERB_SET_EAPD_BTLENABLE
, 2},
6367 {0x15, AC_VERB_SET_EAPD_BTLENABLE
, 2},
6373 static int patch_alc861vd(struct hda_codec
*codec
)
6375 struct alc_spec
*spec
;
6378 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
6384 spec
->mixer_nid
= 0x0b;
6386 alc_pick_fixup(codec
, NULL
, alc861vd_fixup_tbl
, alc861vd_fixups
);
6387 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
6389 /* automatic parse from the BIOS config */
6390 err
= alc861vd_parse_auto_config(codec
);
6394 if (codec
->vendor_id
== 0x10ec0660) {
6395 /* always turn on EAPD */
6396 add_verb(spec
, alc660vd_eapd_verbs
);
6399 if (!spec
->no_analog
&& !spec
->adc_nids
) {
6400 alc_auto_fill_adc_caps(codec
);
6401 alc_rebuild_imux_for_auto_mic(codec
);
6402 alc_remove_invalid_adc_nids(codec
);
6405 if (!spec
->no_analog
&& !spec
->cap_mixer
)
6406 set_capture_mixer(codec
);
6408 if (!spec
->no_analog
) {
6409 err
= snd_hda_attach_beep_device(codec
, 0x23);
6412 set_beep_amp(spec
, 0x0b, 0x05, HDA_INPUT
);
6415 codec
->patch_ops
= alc_patch_ops
;
6417 spec
->init_hook
= alc_auto_init_std
;
6418 spec
->shutup
= alc_eapd_shutup
;
6419 #ifdef CONFIG_SND_HDA_POWER_SAVE
6420 if (!spec
->loopback
.amplist
)
6421 spec
->loopback
.amplist
= alc861vd_loopbacks
;
6424 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
6436 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
6437 * configuration. Each pin widget can choose any input DACs and a mixer.
6438 * Each ADC is connected from a mixer of all inputs. This makes possible
6439 * 6-channel independent captures.
6441 * In addition, an independent DAC for the multi-playback (not used in this
6444 #ifdef CONFIG_SND_HDA_POWER_SAVE
6445 #define alc662_loopbacks alc880_loopbacks
6449 * BIOS auto configuration
6452 static int alc662_parse_auto_config(struct hda_codec
*codec
)
6454 static const hda_nid_t alc662_ignore
[] = { 0x1d, 0 };
6455 static const hda_nid_t alc663_ssids
[] = { 0x15, 0x1b, 0x14, 0x21 };
6456 static const hda_nid_t alc662_ssids
[] = { 0x15, 0x1b, 0x14, 0 };
6457 const hda_nid_t
*ssids
;
6459 if (codec
->vendor_id
== 0x10ec0272 || codec
->vendor_id
== 0x10ec0663 ||
6460 codec
->vendor_id
== 0x10ec0665 || codec
->vendor_id
== 0x10ec0670)
6461 ssids
= alc663_ssids
;
6463 ssids
= alc662_ssids
;
6464 return alc_parse_auto_config(codec
, alc662_ignore
, ssids
);
6467 static void alc272_fixup_mario(struct hda_codec
*codec
,
6468 const struct alc_fixup
*fix
, int action
)
6470 if (action
!= ALC_FIXUP_ACT_PROBE
)
6472 if (snd_hda_override_amp_caps(codec
, 0x2, HDA_OUTPUT
,
6473 (0x3b << AC_AMPCAP_OFFSET_SHIFT
) |
6474 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT
) |
6475 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT
) |
6476 (0 << AC_AMPCAP_MUTE_SHIFT
)))
6478 "hda_codec: failed to override amp caps for NID 0x2\n");
6482 ALC662_FIXUP_ASPIRE
,
6483 ALC662_FIXUP_IDEAPAD
,
6485 ALC662_FIXUP_CZC_P10T
,
6486 ALC662_FIXUP_SKU_IGNORE
,
6487 ALC662_FIXUP_HP_RP5800
,
6488 ALC662_FIXUP_ASUS_MODE1
,
6489 ALC662_FIXUP_ASUS_MODE2
,
6490 ALC662_FIXUP_ASUS_MODE3
,
6491 ALC662_FIXUP_ASUS_MODE4
,
6492 ALC662_FIXUP_ASUS_MODE5
,
6493 ALC662_FIXUP_ASUS_MODE6
,
6494 ALC662_FIXUP_ASUS_MODE7
,
6495 ALC662_FIXUP_ASUS_MODE8
,
6496 ALC662_FIXUP_NO_JACK_DETECT
,
6499 static const struct alc_fixup alc662_fixups
[] = {
6500 [ALC662_FIXUP_ASPIRE
] = {
6501 .type
= ALC_FIXUP_PINS
,
6502 .v
.pins
= (const struct alc_pincfg
[]) {
6503 { 0x15, 0x99130112 }, /* subwoofer */
6507 [ALC662_FIXUP_IDEAPAD
] = {
6508 .type
= ALC_FIXUP_PINS
,
6509 .v
.pins
= (const struct alc_pincfg
[]) {
6510 { 0x17, 0x99130112 }, /* subwoofer */
6514 [ALC272_FIXUP_MARIO
] = {
6515 .type
= ALC_FIXUP_FUNC
,
6516 .v
.func
= alc272_fixup_mario
,
6518 [ALC662_FIXUP_CZC_P10T
] = {
6519 .type
= ALC_FIXUP_VERBS
,
6520 .v
.verbs
= (const struct hda_verb
[]) {
6521 {0x14, AC_VERB_SET_EAPD_BTLENABLE
, 0},
6525 [ALC662_FIXUP_SKU_IGNORE
] = {
6526 .type
= ALC_FIXUP_SKU
,
6527 .v
.sku
= ALC_FIXUP_SKU_IGNORE
,
6529 [ALC662_FIXUP_HP_RP5800
] = {
6530 .type
= ALC_FIXUP_PINS
,
6531 .v
.pins
= (const struct alc_pincfg
[]) {
6532 { 0x14, 0x0221201f }, /* HP out */
6536 .chain_id
= ALC662_FIXUP_SKU_IGNORE
6538 [ALC662_FIXUP_ASUS_MODE1
] = {
6539 .type
= ALC_FIXUP_PINS
,
6540 .v
.pins
= (const struct alc_pincfg
[]) {
6541 { 0x14, 0x99130110 }, /* speaker */
6542 { 0x18, 0x01a19c20 }, /* mic */
6543 { 0x19, 0x99a3092f }, /* int-mic */
6544 { 0x21, 0x0121401f }, /* HP out */
6548 .chain_id
= ALC662_FIXUP_SKU_IGNORE
6550 [ALC662_FIXUP_ASUS_MODE2
] = {
6551 .type
= ALC_FIXUP_PINS
,
6552 .v
.pins
= (const struct alc_pincfg
[]) {
6553 { 0x14, 0x99130110 }, /* speaker */
6554 { 0x18, 0x01a19820 }, /* mic */
6555 { 0x19, 0x99a3092f }, /* int-mic */
6556 { 0x1b, 0x0121401f }, /* HP out */
6560 .chain_id
= ALC662_FIXUP_SKU_IGNORE
6562 [ALC662_FIXUP_ASUS_MODE3
] = {
6563 .type
= ALC_FIXUP_PINS
,
6564 .v
.pins
= (const struct alc_pincfg
[]) {
6565 { 0x14, 0x99130110 }, /* speaker */
6566 { 0x15, 0x0121441f }, /* HP */
6567 { 0x18, 0x01a19840 }, /* mic */
6568 { 0x19, 0x99a3094f }, /* int-mic */
6569 { 0x21, 0x01211420 }, /* HP2 */
6573 .chain_id
= ALC662_FIXUP_SKU_IGNORE
6575 [ALC662_FIXUP_ASUS_MODE4
] = {
6576 .type
= ALC_FIXUP_PINS
,
6577 .v
.pins
= (const struct alc_pincfg
[]) {
6578 { 0x14, 0x99130110 }, /* speaker */
6579 { 0x16, 0x99130111 }, /* speaker */
6580 { 0x18, 0x01a19840 }, /* mic */
6581 { 0x19, 0x99a3094f }, /* int-mic */
6582 { 0x21, 0x0121441f }, /* HP */
6586 .chain_id
= ALC662_FIXUP_SKU_IGNORE
6588 [ALC662_FIXUP_ASUS_MODE5
] = {
6589 .type
= ALC_FIXUP_PINS
,
6590 .v
.pins
= (const struct alc_pincfg
[]) {
6591 { 0x14, 0x99130110 }, /* speaker */
6592 { 0x15, 0x0121441f }, /* HP */
6593 { 0x16, 0x99130111 }, /* speaker */
6594 { 0x18, 0x01a19840 }, /* mic */
6595 { 0x19, 0x99a3094f }, /* int-mic */
6599 .chain_id
= ALC662_FIXUP_SKU_IGNORE
6601 [ALC662_FIXUP_ASUS_MODE6
] = {
6602 .type
= ALC_FIXUP_PINS
,
6603 .v
.pins
= (const struct alc_pincfg
[]) {
6604 { 0x14, 0x99130110 }, /* speaker */
6605 { 0x15, 0x01211420 }, /* HP2 */
6606 { 0x18, 0x01a19840 }, /* mic */
6607 { 0x19, 0x99a3094f }, /* int-mic */
6608 { 0x1b, 0x0121441f }, /* HP */
6612 .chain_id
= ALC662_FIXUP_SKU_IGNORE
6614 [ALC662_FIXUP_ASUS_MODE7
] = {
6615 .type
= ALC_FIXUP_PINS
,
6616 .v
.pins
= (const struct alc_pincfg
[]) {
6617 { 0x14, 0x99130110 }, /* speaker */
6618 { 0x17, 0x99130111 }, /* speaker */
6619 { 0x18, 0x01a19840 }, /* mic */
6620 { 0x19, 0x99a3094f }, /* int-mic */
6621 { 0x1b, 0x01214020 }, /* HP */
6622 { 0x21, 0x0121401f }, /* HP */
6626 .chain_id
= ALC662_FIXUP_SKU_IGNORE
6628 [ALC662_FIXUP_ASUS_MODE8
] = {
6629 .type
= ALC_FIXUP_PINS
,
6630 .v
.pins
= (const struct alc_pincfg
[]) {
6631 { 0x14, 0x99130110 }, /* speaker */
6632 { 0x12, 0x99a30970 }, /* int-mic */
6633 { 0x15, 0x01214020 }, /* HP */
6634 { 0x17, 0x99130111 }, /* speaker */
6635 { 0x18, 0x01a19840 }, /* mic */
6636 { 0x21, 0x0121401f }, /* HP */
6640 .chain_id
= ALC662_FIXUP_SKU_IGNORE
6642 [ALC662_FIXUP_NO_JACK_DETECT
] = {
6643 .type
= ALC_FIXUP_FUNC
,
6644 .v
.func
= alc_fixup_no_jack_detect
,
6648 static const struct snd_pci_quirk alc662_fixup_tbl
[] = {
6649 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2
),
6650 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE
),
6651 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE
),
6652 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE
),
6653 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800
),
6654 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT
),
6655 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2
),
6656 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD
),
6657 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD
),
6658 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD
),
6659 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T
),
6662 /* Below is a quirk table taken from the old code.
6663 * Basically the device should work as is without the fixup table.
6664 * If BIOS doesn't give a proper info, enable the corresponding
6667 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1
),
6668 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3
),
6669 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1
),
6670 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3
),
6671 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1
),
6672 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2
),
6673 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1
),
6674 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1
),
6675 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1
),
6676 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2
),
6677 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7
),
6678 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7
),
6679 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8
),
6680 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3
),
6681 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1
),
6682 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2
),
6683 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2
),
6684 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1
),
6685 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2
),
6686 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6
),
6687 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6
),
6688 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2
),
6689 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1
),
6690 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3
),
6691 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2
),
6692 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2
),
6693 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5
),
6694 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6
),
6695 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2
),
6696 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1
),
6697 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2
),
6698 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2
),
6699 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3
),
6700 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3
),
6701 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1
),
6702 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1
),
6703 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1
),
6704 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1
),
6705 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1
),
6706 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2
),
6707 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2
),
6708 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1
),
6709 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1
),
6710 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3
),
6711 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1
),
6712 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1
),
6713 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1
),
6714 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2
),
6715 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1
),
6716 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4
),
6721 static const struct alc_model_fixup alc662_fixup_models
[] = {
6722 {.id
= ALC272_FIXUP_MARIO
, .name
= "mario"},
6723 {.id
= ALC662_FIXUP_ASUS_MODE1
, .name
= "asus-mode1"},
6724 {.id
= ALC662_FIXUP_ASUS_MODE2
, .name
= "asus-mode2"},
6725 {.id
= ALC662_FIXUP_ASUS_MODE3
, .name
= "asus-mode3"},
6726 {.id
= ALC662_FIXUP_ASUS_MODE4
, .name
= "asus-mode4"},
6727 {.id
= ALC662_FIXUP_ASUS_MODE5
, .name
= "asus-mode5"},
6728 {.id
= ALC662_FIXUP_ASUS_MODE6
, .name
= "asus-mode6"},
6729 {.id
= ALC662_FIXUP_ASUS_MODE7
, .name
= "asus-mode7"},
6730 {.id
= ALC662_FIXUP_ASUS_MODE8
, .name
= "asus-mode8"},
6737 static int patch_alc662(struct hda_codec
*codec
)
6739 struct alc_spec
*spec
;
6742 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
6748 spec
->mixer_nid
= 0x0b;
6750 /* handle multiple HPs as is */
6751 spec
->parse_flags
= HDA_PINCFG_NO_HP_FIXUP
;
6753 alc_auto_parse_customize_define(codec
);
6755 alc_fix_pll_init(codec
, 0x20, 0x04, 15);
6757 err
= alc_codec_rename_from_preset(codec
);
6761 if ((alc_get_coef0(codec
) & (1 << 14)) &&
6762 codec
->bus
->pci
->subsystem_vendor
== 0x1025 &&
6763 spec
->cdefine
.platform_type
== 1) {
6764 if (alc_codec_rename(codec
, "ALC272X") < 0)
6768 alc_pick_fixup(codec
, alc662_fixup_models
,
6769 alc662_fixup_tbl
, alc662_fixups
);
6770 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
6771 /* automatic parse from the BIOS config */
6772 err
= alc662_parse_auto_config(codec
);
6776 if (!spec
->no_analog
&& !spec
->adc_nids
) {
6777 alc_auto_fill_adc_caps(codec
);
6778 alc_rebuild_imux_for_auto_mic(codec
);
6779 alc_remove_invalid_adc_nids(codec
);
6782 if (!spec
->no_analog
&& !spec
->cap_mixer
)
6783 set_capture_mixer(codec
);
6785 if (!spec
->no_analog
&& has_cdefine_beep(codec
)) {
6786 err
= snd_hda_attach_beep_device(codec
, 0x1);
6789 switch (codec
->vendor_id
) {
6791 set_beep_amp(spec
, 0x0b, 0x05, HDA_INPUT
);
6796 set_beep_amp(spec
, 0x0b, 0x04, HDA_INPUT
);
6799 set_beep_amp(spec
, 0x0b, 0x03, HDA_INPUT
);
6804 codec
->patch_ops
= alc_patch_ops
;
6805 spec
->init_hook
= alc_auto_init_std
;
6806 spec
->shutup
= alc_eapd_shutup
;
6808 #ifdef CONFIG_SND_HDA_POWER_SAVE
6809 if (!spec
->loopback
.amplist
)
6810 spec
->loopback
.amplist
= alc662_loopbacks
;
6813 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
6826 static int alc680_parse_auto_config(struct hda_codec
*codec
)
6828 return alc_parse_auto_config(codec
, NULL
, NULL
);
6833 static int patch_alc680(struct hda_codec
*codec
)
6835 struct alc_spec
*spec
;
6838 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
6844 /* ALC680 has no aa-loopback mixer */
6846 /* automatic parse from the BIOS config */
6847 err
= alc680_parse_auto_config(codec
);
6853 if (!spec
->no_analog
&& !spec
->cap_mixer
)
6854 set_capture_mixer(codec
);
6856 codec
->patch_ops
= alc_patch_ops
;
6857 spec
->init_hook
= alc_auto_init_std
;
6865 static const struct hda_codec_preset snd_hda_preset_realtek
[] = {
6866 { .id
= 0x10ec0221, .name
= "ALC221", .patch
= patch_alc269
},
6867 { .id
= 0x10ec0260, .name
= "ALC260", .patch
= patch_alc260
},
6868 { .id
= 0x10ec0262, .name
= "ALC262", .patch
= patch_alc262
},
6869 { .id
= 0x10ec0267, .name
= "ALC267", .patch
= patch_alc268
},
6870 { .id
= 0x10ec0268, .name
= "ALC268", .patch
= patch_alc268
},
6871 { .id
= 0x10ec0269, .name
= "ALC269", .patch
= patch_alc269
},
6872 { .id
= 0x10ec0270, .name
= "ALC270", .patch
= patch_alc269
},
6873 { .id
= 0x10ec0272, .name
= "ALC272", .patch
= patch_alc662
},
6874 { .id
= 0x10ec0275, .name
= "ALC275", .patch
= patch_alc269
},
6875 { .id
= 0x10ec0276, .name
= "ALC276", .patch
= patch_alc269
},
6876 { .id
= 0x10ec0861, .rev
= 0x100340, .name
= "ALC660",
6877 .patch
= patch_alc861
},
6878 { .id
= 0x10ec0660, .name
= "ALC660-VD", .patch
= patch_alc861vd
},
6879 { .id
= 0x10ec0861, .name
= "ALC861", .patch
= patch_alc861
},
6880 { .id
= 0x10ec0862, .name
= "ALC861-VD", .patch
= patch_alc861vd
},
6881 { .id
= 0x10ec0662, .rev
= 0x100002, .name
= "ALC662 rev2",
6882 .patch
= patch_alc882
},
6883 { .id
= 0x10ec0662, .rev
= 0x100101, .name
= "ALC662 rev1",
6884 .patch
= patch_alc662
},
6885 { .id
= 0x10ec0662, .rev
= 0x100300, .name
= "ALC662 rev3",
6886 .patch
= patch_alc662
},
6887 { .id
= 0x10ec0663, .name
= "ALC663", .patch
= patch_alc662
},
6888 { .id
= 0x10ec0665, .name
= "ALC665", .patch
= patch_alc662
},
6889 { .id
= 0x10ec0670, .name
= "ALC670", .patch
= patch_alc662
},
6890 { .id
= 0x10ec0680, .name
= "ALC680", .patch
= patch_alc680
},
6891 { .id
= 0x10ec0880, .name
= "ALC880", .patch
= patch_alc880
},
6892 { .id
= 0x10ec0882, .name
= "ALC882", .patch
= patch_alc882
},
6893 { .id
= 0x10ec0883, .name
= "ALC883", .patch
= patch_alc882
},
6894 { .id
= 0x10ec0885, .rev
= 0x100101, .name
= "ALC889A",
6895 .patch
= patch_alc882
},
6896 { .id
= 0x10ec0885, .rev
= 0x100103, .name
= "ALC889A",
6897 .patch
= patch_alc882
},
6898 { .id
= 0x10ec0885, .name
= "ALC885", .patch
= patch_alc882
},
6899 { .id
= 0x10ec0887, .name
= "ALC887", .patch
= patch_alc882
},
6900 { .id
= 0x10ec0888, .rev
= 0x100101, .name
= "ALC1200",
6901 .patch
= patch_alc882
},
6902 { .id
= 0x10ec0888, .name
= "ALC888", .patch
= patch_alc882
},
6903 { .id
= 0x10ec0889, .name
= "ALC889", .patch
= patch_alc882
},
6904 { .id
= 0x10ec0892, .name
= "ALC892", .patch
= patch_alc662
},
6905 { .id
= 0x10ec0899, .name
= "ALC898", .patch
= patch_alc882
},
6909 MODULE_ALIAS("snd-hda-codec-id:10ec*");
6911 MODULE_LICENSE("GPL");
6912 MODULE_DESCRIPTION("Realtek HD-audio codec");
6914 static struct hda_codec_preset_list realtek_list
= {
6915 .preset
= snd_hda_preset_realtek
,
6916 .owner
= THIS_MODULE
,
6919 static int __init
patch_realtek_init(void)
6921 return snd_hda_add_codec_preset(&realtek_list
);
6924 static void __exit
patch_realtek_exit(void)
6926 snd_hda_delete_codec_preset(&realtek_list
);
6929 module_init(patch_realtek_init
)
6930 module_exit(patch_realtek_exit
)