2 * Universal Interface for Intel High Definition Audio Codec
4 * HD audio interface patch for Realtek ALC codecs
6 * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
7 * PeiSen Hou <pshou@realtek.com.tw>
8 * Takashi Iwai <tiwai@suse.de>
9 * Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
11 * This driver is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This driver is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include <linux/init.h>
27 #include <linux/delay.h>
28 #include <linux/slab.h>
29 #include <linux/pci.h>
30 #include <linux/module.h>
31 #include <sound/core.h>
32 #include <sound/jack.h>
33 #include "hda_codec.h"
34 #include "hda_local.h"
38 /* unsol event tags */
39 #define ALC_FRONT_EVENT 0x01
40 #define ALC_DCVOL_EVENT 0x02
41 #define ALC_HP_EVENT 0x04
42 #define ALC_MIC_EVENT 0x08
45 #define GPIO_MASK 0x03
47 /* extra amp-initialization sequence types */
56 struct alc_customize_define
{
58 unsigned char port_connectivity
;
59 unsigned char check_sum
;
60 unsigned char customization
;
61 unsigned char external_amp
;
62 unsigned int enable_pcbeep
:1;
63 unsigned int platform_type
:1;
65 unsigned int override
:1;
66 unsigned int fixup
:1; /* Means that this sku is set by driver, not read from hw */
72 hda_nid_t pin
; /* multi-io widget pin NID */
73 hda_nid_t dac
; /* DAC to be connected */
74 unsigned int ctl_in
; /* cached input-pin control value */
78 ALC_AUTOMUTE_PIN
, /* change the pin control */
79 ALC_AUTOMUTE_AMP
, /* mute/unmute the pin AMP */
80 ALC_AUTOMUTE_MIXER
, /* mute/unmute mixer widget AMP */
83 #define MAX_VOL_NIDS 0x40
86 /* codec parameterization */
87 const struct snd_kcontrol_new
*mixers
[5]; /* mixer arrays */
88 unsigned int num_mixers
;
89 const struct snd_kcontrol_new
*cap_mixer
; /* capture mixer */
90 unsigned int beep_amp
; /* beep amp value, set via set_beep_amp() */
92 const struct hda_verb
*init_verbs
[10]; /* initialization verbs
96 unsigned int num_init_verbs
;
98 char stream_name_analog
[32]; /* analog PCM stream */
99 const struct hda_pcm_stream
*stream_analog_playback
;
100 const struct hda_pcm_stream
*stream_analog_capture
;
101 const struct hda_pcm_stream
*stream_analog_alt_playback
;
102 const struct hda_pcm_stream
*stream_analog_alt_capture
;
104 char stream_name_digital
[32]; /* digital PCM stream */
105 const struct hda_pcm_stream
*stream_digital_playback
;
106 const struct hda_pcm_stream
*stream_digital_capture
;
109 struct hda_multi_out multiout
; /* playback set-up
110 * max_channels, dacs must be set
111 * dig_out_nid and hp_nid are optional
113 hda_nid_t alt_dac_nid
;
114 hda_nid_t slave_dig_outs
[3]; /* optional - for auto-parsing */
118 unsigned int num_adc_nids
;
119 const hda_nid_t
*adc_nids
;
120 const hda_nid_t
*capsrc_nids
;
121 hda_nid_t dig_in_nid
; /* digital-in NID; optional */
122 hda_nid_t mixer_nid
; /* analog-mixer NID */
123 DECLARE_BITMAP(vol_ctls
, MAX_VOL_NIDS
<< 1);
124 DECLARE_BITMAP(sw_ctls
, MAX_VOL_NIDS
<< 1);
126 /* capture setup for dynamic dual-adc switch */
128 unsigned int cur_adc_stream_tag
;
129 unsigned int cur_adc_format
;
132 unsigned int num_mux_defs
;
133 const struct hda_input_mux
*input_mux
;
134 unsigned int cur_mux
[3];
135 hda_nid_t ext_mic_pin
;
136 hda_nid_t dock_mic_pin
;
137 hda_nid_t int_mic_pin
;
140 const struct hda_channel_mode
*channel_mode
;
141 int num_channel_mode
;
143 int const_channel_count
;
144 int ext_channel_count
;
146 /* PCM information */
147 struct hda_pcm pcm_rec
[3]; /* used in alc_build_pcms() */
149 /* dynamic controls, init_verbs and input_mux */
150 struct auto_pin_cfg autocfg
;
151 struct alc_customize_define cdefine
;
152 struct snd_array kctls
;
153 struct hda_input_mux private_imux
[3];
154 hda_nid_t private_dac_nids
[AUTO_CFG_MAX_OUTS
];
155 hda_nid_t private_adc_nids
[AUTO_CFG_MAX_OUTS
];
156 hda_nid_t private_capsrc_nids
[AUTO_CFG_MAX_OUTS
];
157 hda_nid_t imux_pins
[HDA_MAX_NUM_INPUTS
];
158 unsigned int dyn_adc_idx
[HDA_MAX_NUM_INPUTS
];
159 int int_mic_idx
, ext_mic_idx
, dock_mic_idx
; /* for auto-mic */
162 void (*init_hook
)(struct hda_codec
*codec
);
163 void (*unsol_event
)(struct hda_codec
*codec
, unsigned int res
);
164 #ifdef CONFIG_SND_HDA_POWER_SAVE
165 void (*power_hook
)(struct hda_codec
*codec
);
167 void (*shutup
)(struct hda_codec
*codec
);
168 void (*automute_hook
)(struct hda_codec
*codec
);
170 /* for pin sensing */
171 unsigned int hp_jack_present
:1;
172 unsigned int line_jack_present
:1;
173 unsigned int master_mute
:1;
174 unsigned int auto_mic
:1;
175 unsigned int auto_mic_valid_imux
:1; /* valid imux for auto-mic */
176 unsigned int automute_speaker
:1; /* automute speaker outputs */
177 unsigned int automute_lo
:1; /* automute LO outputs */
178 unsigned int detect_hp
:1; /* Headphone detection enabled */
179 unsigned int detect_lo
:1; /* Line-out detection enabled */
180 unsigned int automute_speaker_possible
:1; /* there are speakers and either LO or HP */
181 unsigned int automute_lo_possible
:1; /* there are line outs and HP */
182 unsigned int keep_vref_in_automute
:1; /* Don't clear VREF in automute */
185 unsigned int no_analog
:1; /* digital I/O only */
186 unsigned int dyn_adc_switch
:1; /* switch ADCs (for ALC275) */
187 unsigned int single_input_src
:1;
188 unsigned int vol_in_capsrc
:1; /* use capsrc volume (ADC has no vol) */
189 unsigned int parse_flags
; /* passed to snd_hda_parse_pin_defcfg() */
190 unsigned int shared_mic_hp
:1; /* HP/Mic-in sharing */
192 /* auto-mute control */
194 hda_nid_t automute_mixer_nid
[AUTO_CFG_MAX_OUTS
];
197 int codec_variant
; /* flag for other variants */
199 /* for virtual master */
200 hda_nid_t vmaster_nid
;
201 #ifdef CONFIG_SND_HDA_POWER_SAVE
202 struct hda_loopback_check loopback
;
207 unsigned int pll_coef_idx
, pll_coef_bit
;
212 const struct alc_fixup
*fixup_list
;
213 const char *fixup_name
;
217 struct alc_multi_io multi_io
[4];
220 struct snd_array bind_ctls
;
223 #define ALC_MODEL_AUTO 0 /* common for all chips */
225 static bool check_amp_caps(struct hda_codec
*codec
, hda_nid_t nid
,
226 int dir
, unsigned int bits
)
230 if (get_wcaps(codec
, nid
) & (1 << (dir
+ 1)))
231 if (query_amp_caps(codec
, nid
, dir
) & bits
)
236 #define nid_has_mute(codec, nid, dir) \
237 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
238 #define nid_has_volume(codec, nid, dir) \
239 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
244 static int alc_mux_enum_info(struct snd_kcontrol
*kcontrol
,
245 struct snd_ctl_elem_info
*uinfo
)
247 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
248 struct alc_spec
*spec
= codec
->spec
;
249 unsigned int mux_idx
= snd_ctl_get_ioffidx(kcontrol
, &uinfo
->id
);
250 if (mux_idx
>= spec
->num_mux_defs
)
252 if (!spec
->input_mux
[mux_idx
].num_items
&& mux_idx
> 0)
254 return snd_hda_input_mux_info(&spec
->input_mux
[mux_idx
], uinfo
);
257 static int alc_mux_enum_get(struct snd_kcontrol
*kcontrol
,
258 struct snd_ctl_elem_value
*ucontrol
)
260 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
261 struct alc_spec
*spec
= codec
->spec
;
262 unsigned int adc_idx
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
264 ucontrol
->value
.enumerated
.item
[0] = spec
->cur_mux
[adc_idx
];
268 static bool alc_dyn_adc_pcm_resetup(struct hda_codec
*codec
, int cur
)
270 struct alc_spec
*spec
= codec
->spec
;
271 hda_nid_t new_adc
= spec
->adc_nids
[spec
->dyn_adc_idx
[cur
]];
273 if (spec
->cur_adc
&& spec
->cur_adc
!= new_adc
) {
274 /* stream is running, let's swap the current ADC */
275 __snd_hda_codec_cleanup_stream(codec
, spec
->cur_adc
, 1);
276 spec
->cur_adc
= new_adc
;
277 snd_hda_codec_setup_stream(codec
, new_adc
,
278 spec
->cur_adc_stream_tag
, 0,
279 spec
->cur_adc_format
);
285 static inline hda_nid_t
get_capsrc(struct alc_spec
*spec
, int idx
)
287 return spec
->capsrc_nids
?
288 spec
->capsrc_nids
[idx
] : spec
->adc_nids
[idx
];
291 static void call_update_outputs(struct hda_codec
*codec
);
293 /* select the given imux item; either unmute exclusively or select the route */
294 static int alc_mux_select(struct hda_codec
*codec
, unsigned int adc_idx
,
295 unsigned int idx
, bool force
)
297 struct alc_spec
*spec
= codec
->spec
;
298 const struct hda_input_mux
*imux
;
299 unsigned int mux_idx
;
300 int i
, type
, num_conns
;
303 mux_idx
= adc_idx
>= spec
->num_mux_defs
? 0 : adc_idx
;
304 imux
= &spec
->input_mux
[mux_idx
];
305 if (!imux
->num_items
&& mux_idx
> 0)
306 imux
= &spec
->input_mux
[0];
307 if (!imux
->num_items
)
310 if (idx
>= imux
->num_items
)
311 idx
= imux
->num_items
- 1;
312 if (spec
->cur_mux
[adc_idx
] == idx
&& !force
)
314 spec
->cur_mux
[adc_idx
] = idx
;
316 /* for shared I/O, change the pin-control accordingly */
317 if (spec
->shared_mic_hp
) {
318 /* NOTE: this assumes that there are only two inputs, the
319 * first is the real internal mic and the second is HP jack.
321 snd_hda_codec_write(codec
, spec
->autocfg
.inputs
[1].pin
, 0,
322 AC_VERB_SET_PIN_WIDGET_CONTROL
,
323 spec
->cur_mux
[adc_idx
] ?
324 PIN_VREF80
: PIN_HP
);
325 spec
->automute_speaker
= !spec
->cur_mux
[adc_idx
];
326 call_update_outputs(codec
);
329 if (spec
->dyn_adc_switch
) {
330 alc_dyn_adc_pcm_resetup(codec
, idx
);
331 adc_idx
= spec
->dyn_adc_idx
[idx
];
334 nid
= get_capsrc(spec
, adc_idx
);
337 num_conns
= snd_hda_get_conn_list(codec
, nid
, NULL
);
341 type
= get_wcaps_type(get_wcaps(codec
, nid
));
342 if (type
== AC_WID_AUD_MIX
) {
343 /* Matrix-mixer style (e.g. ALC882) */
344 int active
= imux
->items
[idx
].index
;
345 for (i
= 0; i
< num_conns
; i
++) {
346 unsigned int v
= (i
== active
) ? 0 : HDA_AMP_MUTE
;
347 snd_hda_codec_amp_stereo(codec
, nid
, HDA_INPUT
, i
,
351 /* MUX style (e.g. ALC880) */
352 snd_hda_codec_write_cache(codec
, nid
, 0,
353 AC_VERB_SET_CONNECT_SEL
,
354 imux
->items
[idx
].index
);
359 static int alc_mux_enum_put(struct snd_kcontrol
*kcontrol
,
360 struct snd_ctl_elem_value
*ucontrol
)
362 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
363 unsigned int adc_idx
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
364 return alc_mux_select(codec
, adc_idx
,
365 ucontrol
->value
.enumerated
.item
[0], false);
369 * set up the input pin config (depending on the given auto-pin type)
371 static void alc_set_input_pin(struct hda_codec
*codec
, hda_nid_t nid
,
374 unsigned int val
= PIN_IN
;
376 if (auto_pin_type
== AUTO_PIN_MIC
) {
379 oldval
= snd_hda_codec_read(codec
, nid
, 0,
380 AC_VERB_GET_PIN_WIDGET_CONTROL
, 0);
381 pincap
= snd_hda_query_pin_caps(codec
, nid
);
382 pincap
= (pincap
& AC_PINCAP_VREF
) >> AC_PINCAP_VREF_SHIFT
;
383 /* if the default pin setup is vref50, we give it priority */
384 if ((pincap
& AC_PINCAP_VREF_80
) && oldval
!= PIN_VREF50
)
386 else if (pincap
& AC_PINCAP_VREF_50
)
388 else if (pincap
& AC_PINCAP_VREF_100
)
390 else if (pincap
& AC_PINCAP_VREF_GRD
)
393 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_PIN_WIDGET_CONTROL
, val
);
397 * Append the given mixer and verb elements for the later use
398 * The mixer array is referred in build_controls(), and init_verbs are
401 static void add_mixer(struct alc_spec
*spec
, const struct snd_kcontrol_new
*mix
)
403 if (snd_BUG_ON(spec
->num_mixers
>= ARRAY_SIZE(spec
->mixers
)))
405 spec
->mixers
[spec
->num_mixers
++] = mix
;
408 static void add_verb(struct alc_spec
*spec
, const struct hda_verb
*verb
)
410 if (snd_BUG_ON(spec
->num_init_verbs
>= ARRAY_SIZE(spec
->init_verbs
)))
412 spec
->init_verbs
[spec
->num_init_verbs
++] = verb
;
416 * GPIO setup tables, used in initialization
418 /* Enable GPIO mask and set output */
419 static const struct hda_verb alc_gpio1_init_verbs
[] = {
420 {0x01, AC_VERB_SET_GPIO_MASK
, 0x01},
421 {0x01, AC_VERB_SET_GPIO_DIRECTION
, 0x01},
422 {0x01, AC_VERB_SET_GPIO_DATA
, 0x01},
426 static const struct hda_verb alc_gpio2_init_verbs
[] = {
427 {0x01, AC_VERB_SET_GPIO_MASK
, 0x02},
428 {0x01, AC_VERB_SET_GPIO_DIRECTION
, 0x02},
429 {0x01, AC_VERB_SET_GPIO_DATA
, 0x02},
433 static const struct hda_verb alc_gpio3_init_verbs
[] = {
434 {0x01, AC_VERB_SET_GPIO_MASK
, 0x03},
435 {0x01, AC_VERB_SET_GPIO_DIRECTION
, 0x03},
436 {0x01, AC_VERB_SET_GPIO_DATA
, 0x03},
441 * Fix hardware PLL issue
442 * On some codecs, the analog PLL gating control must be off while
443 * the default value is 1.
445 static void alc_fix_pll(struct hda_codec
*codec
)
447 struct alc_spec
*spec
= codec
->spec
;
452 snd_hda_codec_write(codec
, spec
->pll_nid
, 0, AC_VERB_SET_COEF_INDEX
,
454 val
= snd_hda_codec_read(codec
, spec
->pll_nid
, 0,
455 AC_VERB_GET_PROC_COEF
, 0);
456 snd_hda_codec_write(codec
, spec
->pll_nid
, 0, AC_VERB_SET_COEF_INDEX
,
458 snd_hda_codec_write(codec
, spec
->pll_nid
, 0, AC_VERB_SET_PROC_COEF
,
459 val
& ~(1 << spec
->pll_coef_bit
));
462 static void alc_fix_pll_init(struct hda_codec
*codec
, hda_nid_t nid
,
463 unsigned int coef_idx
, unsigned int coef_bit
)
465 struct alc_spec
*spec
= codec
->spec
;
467 spec
->pll_coef_idx
= coef_idx
;
468 spec
->pll_coef_bit
= coef_bit
;
473 * Jack detections for HP auto-mute and mic-switch
476 /* check each pin in the given array; returns true if any of them is plugged */
477 static bool detect_jacks(struct hda_codec
*codec
, int num_pins
, hda_nid_t
*pins
)
481 for (i
= 0; i
< num_pins
; i
++) {
482 hda_nid_t nid
= pins
[i
];
485 present
|= snd_hda_jack_detect(codec
, nid
);
490 /* standard HP/line-out auto-mute helper */
491 static void do_automute(struct hda_codec
*codec
, int num_pins
, hda_nid_t
*pins
,
492 bool mute
, bool hp_out
)
494 struct alc_spec
*spec
= codec
->spec
;
495 unsigned int mute_bits
= mute
? HDA_AMP_MUTE
: 0;
496 unsigned int pin_bits
= mute
? 0 : (hp_out
? PIN_HP
: PIN_OUT
);
499 for (i
= 0; i
< num_pins
; i
++) {
500 hda_nid_t nid
= pins
[i
];
504 switch (spec
->automute_mode
) {
505 case ALC_AUTOMUTE_PIN
:
506 /* don't reset VREF value in case it's controlling
507 * the amp (see alc861_fixup_asus_amp_vref_0f())
509 if (spec
->keep_vref_in_automute
) {
510 val
= snd_hda_codec_read(codec
, nid
, 0,
511 AC_VERB_GET_PIN_WIDGET_CONTROL
, 0);
516 snd_hda_codec_write(codec
, nid
, 0,
517 AC_VERB_SET_PIN_WIDGET_CONTROL
,
520 case ALC_AUTOMUTE_AMP
:
521 snd_hda_codec_amp_stereo(codec
, nid
, HDA_OUTPUT
, 0,
522 HDA_AMP_MUTE
, mute_bits
);
524 case ALC_AUTOMUTE_MIXER
:
525 nid
= spec
->automute_mixer_nid
[i
];
528 snd_hda_codec_amp_stereo(codec
, nid
, HDA_INPUT
, 0,
529 HDA_AMP_MUTE
, mute_bits
);
530 snd_hda_codec_amp_stereo(codec
, nid
, HDA_INPUT
, 1,
531 HDA_AMP_MUTE
, mute_bits
);
537 /* Toggle outputs muting */
538 static void update_outputs(struct hda_codec
*codec
)
540 struct alc_spec
*spec
= codec
->spec
;
543 /* Control HP pins/amps depending on master_mute state;
544 * in general, HP pins/amps control should be enabled in all cases,
545 * but currently set only for master_mute, just to be safe
547 if (!spec
->shared_mic_hp
) /* don't change HP-pin when shared with mic */
548 do_automute(codec
, ARRAY_SIZE(spec
->autocfg
.hp_pins
),
549 spec
->autocfg
.hp_pins
, spec
->master_mute
, true);
551 if (!spec
->automute_speaker
)
554 on
= spec
->hp_jack_present
| spec
->line_jack_present
;
555 on
|= spec
->master_mute
;
556 do_automute(codec
, ARRAY_SIZE(spec
->autocfg
.speaker_pins
),
557 spec
->autocfg
.speaker_pins
, on
, false);
559 /* toggle line-out mutes if needed, too */
560 /* if LO is a copy of either HP or Speaker, don't need to handle it */
561 if (spec
->autocfg
.line_out_pins
[0] == spec
->autocfg
.hp_pins
[0] ||
562 spec
->autocfg
.line_out_pins
[0] == spec
->autocfg
.speaker_pins
[0])
564 if (!spec
->automute_lo
)
567 on
= spec
->hp_jack_present
;
568 on
|= spec
->master_mute
;
569 do_automute(codec
, ARRAY_SIZE(spec
->autocfg
.line_out_pins
),
570 spec
->autocfg
.line_out_pins
, on
, false);
573 static void call_update_outputs(struct hda_codec
*codec
)
575 struct alc_spec
*spec
= codec
->spec
;
576 if (spec
->automute_hook
)
577 spec
->automute_hook(codec
);
579 update_outputs(codec
);
582 /* standard HP-automute helper */
583 static void alc_hp_automute(struct hda_codec
*codec
)
585 struct alc_spec
*spec
= codec
->spec
;
587 spec
->hp_jack_present
=
588 detect_jacks(codec
, ARRAY_SIZE(spec
->autocfg
.hp_pins
),
589 spec
->autocfg
.hp_pins
);
590 if (!spec
->detect_hp
|| (!spec
->automute_speaker
&& !spec
->automute_lo
))
592 call_update_outputs(codec
);
595 /* standard line-out-automute helper */
596 static void alc_line_automute(struct hda_codec
*codec
)
598 struct alc_spec
*spec
= codec
->spec
;
600 /* check LO jack only when it's different from HP */
601 if (spec
->autocfg
.line_out_pins
[0] == spec
->autocfg
.hp_pins
[0])
604 spec
->line_jack_present
=
605 detect_jacks(codec
, ARRAY_SIZE(spec
->autocfg
.line_out_pins
),
606 spec
->autocfg
.line_out_pins
);
607 if (!spec
->automute_speaker
|| !spec
->detect_lo
)
609 call_update_outputs(codec
);
612 #define get_connection_index(codec, mux, nid) \
613 snd_hda_get_conn_index(codec, mux, nid, 0)
615 /* standard mic auto-switch helper */
616 static void alc_mic_automute(struct hda_codec
*codec
)
618 struct alc_spec
*spec
= codec
->spec
;
619 hda_nid_t
*pins
= spec
->imux_pins
;
621 if (!spec
->auto_mic
|| !spec
->auto_mic_valid_imux
)
623 if (snd_BUG_ON(!spec
->adc_nids
))
625 if (snd_BUG_ON(spec
->int_mic_idx
< 0 || spec
->ext_mic_idx
< 0))
628 if (snd_hda_jack_detect(codec
, pins
[spec
->ext_mic_idx
]))
629 alc_mux_select(codec
, 0, spec
->ext_mic_idx
, false);
630 else if (spec
->dock_mic_idx
>= 0 &&
631 snd_hda_jack_detect(codec
, pins
[spec
->dock_mic_idx
]))
632 alc_mux_select(codec
, 0, spec
->dock_mic_idx
, false);
634 alc_mux_select(codec
, 0, spec
->int_mic_idx
, false);
637 /* handle the specified unsol action (ALC_XXX_EVENT) */
638 static void alc_exec_unsol_event(struct hda_codec
*codec
, int action
)
642 alc_hp_automute(codec
);
644 case ALC_FRONT_EVENT
:
645 alc_line_automute(codec
);
648 alc_mic_automute(codec
);
651 snd_hda_jack_report_sync(codec
);
654 /* unsolicited event for HP jack sensing */
655 static void alc_sku_unsol_event(struct hda_codec
*codec
, unsigned int res
)
657 if (codec
->vendor_id
== 0x10ec0880)
661 res
= snd_hda_jack_get_action(codec
, res
);
662 alc_exec_unsol_event(codec
, res
);
665 /* call init functions of standard auto-mute helpers */
666 static void alc_inithook(struct hda_codec
*codec
)
668 alc_hp_automute(codec
);
669 alc_line_automute(codec
);
670 alc_mic_automute(codec
);
673 /* additional initialization for ALC888 variants */
674 static void alc888_coef_init(struct hda_codec
*codec
)
678 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_COEF_INDEX
, 0);
679 tmp
= snd_hda_codec_read(codec
, 0x20, 0, AC_VERB_GET_PROC_COEF
, 0);
680 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_COEF_INDEX
, 7);
681 if ((tmp
& 0xf0) == 0x20)
683 snd_hda_codec_read(codec
, 0x20, 0,
684 AC_VERB_SET_PROC_COEF
, 0x830);
687 snd_hda_codec_read(codec
, 0x20, 0,
688 AC_VERB_SET_PROC_COEF
, 0x3030);
691 /* additional initialization for ALC889 variants */
692 static void alc889_coef_init(struct hda_codec
*codec
)
696 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_COEF_INDEX
, 7);
697 tmp
= snd_hda_codec_read(codec
, 0x20, 0, AC_VERB_GET_PROC_COEF
, 0);
698 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_COEF_INDEX
, 7);
699 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_PROC_COEF
, tmp
|0x2010);
702 /* turn on/off EAPD control (only if available) */
703 static void set_eapd(struct hda_codec
*codec
, hda_nid_t nid
, int on
)
705 if (get_wcaps_type(get_wcaps(codec
, nid
)) != AC_WID_PIN
)
707 if (snd_hda_query_pin_caps(codec
, nid
) & AC_PINCAP_EAPD
)
708 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_EAPD_BTLENABLE
,
712 /* turn on/off EAPD controls of the codec */
713 static void alc_auto_setup_eapd(struct hda_codec
*codec
, bool on
)
715 /* We currently only handle front, HP */
716 static hda_nid_t pins
[] = {
717 0x0f, 0x10, 0x14, 0x15, 0
720 for (p
= pins
; *p
; p
++)
721 set_eapd(codec
, *p
, on
);
724 /* generic shutup callback;
725 * just turning off EPAD and a little pause for avoiding pop-noise
727 static void alc_eapd_shutup(struct hda_codec
*codec
)
729 alc_auto_setup_eapd(codec
, false);
733 /* generic EAPD initialization */
734 static void alc_auto_init_amp(struct hda_codec
*codec
, int type
)
738 alc_auto_setup_eapd(codec
, true);
741 snd_hda_sequence_write(codec
, alc_gpio1_init_verbs
);
744 snd_hda_sequence_write(codec
, alc_gpio2_init_verbs
);
747 snd_hda_sequence_write(codec
, alc_gpio3_init_verbs
);
749 case ALC_INIT_DEFAULT
:
750 switch (codec
->vendor_id
) {
752 snd_hda_codec_write(codec
, 0x1a, 0,
753 AC_VERB_SET_COEF_INDEX
, 7);
754 tmp
= snd_hda_codec_read(codec
, 0x1a, 0,
755 AC_VERB_GET_PROC_COEF
, 0);
756 snd_hda_codec_write(codec
, 0x1a, 0,
757 AC_VERB_SET_COEF_INDEX
, 7);
758 snd_hda_codec_write(codec
, 0x1a, 0,
759 AC_VERB_SET_PROC_COEF
,
768 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
769 alc889_coef_init(codec
);
772 alc888_coef_init(codec
);
774 #if 0 /* XXX: This may cause the silent output on speaker on some machines */
777 snd_hda_codec_write(codec
, 0x20, 0,
778 AC_VERB_SET_COEF_INDEX
, 7);
779 tmp
= snd_hda_codec_read(codec
, 0x20, 0,
780 AC_VERB_GET_PROC_COEF
, 0);
781 snd_hda_codec_write(codec
, 0x20, 0,
782 AC_VERB_SET_COEF_INDEX
, 7);
783 snd_hda_codec_write(codec
, 0x20, 0,
784 AC_VERB_SET_PROC_COEF
,
794 * Auto-Mute mode mixer enum support
796 static int alc_automute_mode_info(struct snd_kcontrol
*kcontrol
,
797 struct snd_ctl_elem_info
*uinfo
)
799 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
800 struct alc_spec
*spec
= codec
->spec
;
801 static const char * const texts2
[] = {
802 "Disabled", "Enabled"
804 static const char * const texts3
[] = {
805 "Disabled", "Speaker Only", "Line Out+Speaker"
807 const char * const *texts
;
809 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
811 if (spec
->automute_speaker_possible
&& spec
->automute_lo_possible
) {
812 uinfo
->value
.enumerated
.items
= 3;
815 uinfo
->value
.enumerated
.items
= 2;
818 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
)
819 uinfo
->value
.enumerated
.item
= uinfo
->value
.enumerated
.items
- 1;
820 strcpy(uinfo
->value
.enumerated
.name
,
821 texts
[uinfo
->value
.enumerated
.item
]);
825 static int alc_automute_mode_get(struct snd_kcontrol
*kcontrol
,
826 struct snd_ctl_elem_value
*ucontrol
)
828 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
829 struct alc_spec
*spec
= codec
->spec
;
830 unsigned int val
= 0;
831 if (spec
->automute_speaker
)
833 if (spec
->automute_lo
)
836 ucontrol
->value
.enumerated
.item
[0] = val
;
840 static int alc_automute_mode_put(struct snd_kcontrol
*kcontrol
,
841 struct snd_ctl_elem_value
*ucontrol
)
843 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
844 struct alc_spec
*spec
= codec
->spec
;
846 switch (ucontrol
->value
.enumerated
.item
[0]) {
848 if (!spec
->automute_speaker
&& !spec
->automute_lo
)
850 spec
->automute_speaker
= 0;
851 spec
->automute_lo
= 0;
854 if (spec
->automute_speaker_possible
) {
855 if (!spec
->automute_lo
&& spec
->automute_speaker
)
857 spec
->automute_speaker
= 1;
858 spec
->automute_lo
= 0;
859 } else if (spec
->automute_lo_possible
) {
860 if (spec
->automute_lo
)
862 spec
->automute_lo
= 1;
867 if (!spec
->automute_lo_possible
|| !spec
->automute_speaker_possible
)
869 if (spec
->automute_speaker
&& spec
->automute_lo
)
871 spec
->automute_speaker
= 1;
872 spec
->automute_lo
= 1;
877 call_update_outputs(codec
);
881 static const struct snd_kcontrol_new alc_automute_mode_enum
= {
882 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
883 .name
= "Auto-Mute Mode",
884 .info
= alc_automute_mode_info
,
885 .get
= alc_automute_mode_get
,
886 .put
= alc_automute_mode_put
,
889 static struct snd_kcontrol_new
*alc_kcontrol_new(struct alc_spec
*spec
)
891 snd_array_init(&spec
->kctls
, sizeof(struct snd_kcontrol_new
), 32);
892 return snd_array_new(&spec
->kctls
);
895 static int alc_add_automute_mode_enum(struct hda_codec
*codec
)
897 struct alc_spec
*spec
= codec
->spec
;
898 struct snd_kcontrol_new
*knew
;
900 knew
= alc_kcontrol_new(spec
);
903 *knew
= alc_automute_mode_enum
;
904 knew
->name
= kstrdup("Auto-Mute Mode", GFP_KERNEL
);
911 * Check the availability of HP/line-out auto-mute;
912 * Set up appropriately if really supported
914 static void alc_init_automute(struct hda_codec
*codec
)
916 struct alc_spec
*spec
= codec
->spec
;
917 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
923 if (cfg
->line_out_pins
[0])
925 if (cfg
->speaker_pins
[0])
927 if (present
< 2) /* need two different output types */
930 if (!cfg
->speaker_pins
[0] &&
931 cfg
->line_out_type
== AUTO_PIN_SPEAKER_OUT
) {
932 memcpy(cfg
->speaker_pins
, cfg
->line_out_pins
,
933 sizeof(cfg
->speaker_pins
));
934 cfg
->speaker_outs
= cfg
->line_outs
;
937 if (!cfg
->hp_pins
[0] &&
938 cfg
->line_out_type
== AUTO_PIN_HP_OUT
) {
939 memcpy(cfg
->hp_pins
, cfg
->line_out_pins
,
940 sizeof(cfg
->hp_pins
));
941 cfg
->hp_outs
= cfg
->line_outs
;
944 spec
->automute_mode
= ALC_AUTOMUTE_PIN
;
946 for (i
= 0; i
< cfg
->hp_outs
; i
++) {
947 hda_nid_t nid
= cfg
->hp_pins
[i
];
948 if (!is_jack_detectable(codec
, nid
))
950 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
952 snd_hda_jack_detect_enable(codec
, nid
, ALC_HP_EVENT
);
956 if (cfg
->line_out_type
== AUTO_PIN_LINE_OUT
&& cfg
->line_outs
) {
957 if (cfg
->speaker_outs
)
958 for (i
= 0; i
< cfg
->line_outs
; i
++) {
959 hda_nid_t nid
= cfg
->line_out_pins
[i
];
960 if (!is_jack_detectable(codec
, nid
))
962 snd_printdd("realtek: Enable Line-Out "
963 "auto-muting on NID 0x%x\n", nid
);
964 snd_hda_jack_detect_enable(codec
, nid
,
968 spec
->automute_lo_possible
= spec
->detect_hp
;
971 spec
->automute_speaker_possible
= cfg
->speaker_outs
&&
972 (spec
->detect_hp
|| spec
->detect_lo
);
974 spec
->automute_lo
= spec
->automute_lo_possible
;
975 spec
->automute_speaker
= spec
->automute_speaker_possible
;
977 if (spec
->automute_speaker_possible
|| spec
->automute_lo_possible
) {
978 /* create a control for automute mode */
979 alc_add_automute_mode_enum(codec
);
980 spec
->unsol_event
= alc_sku_unsol_event
;
984 /* return the position of NID in the list, or -1 if not found */
985 static int find_idx_in_nid_list(hda_nid_t nid
, const hda_nid_t
*list
, int nums
)
988 for (i
= 0; i
< nums
; i
++)
994 /* check whether dynamic ADC-switching is available */
995 static bool alc_check_dyn_adc_switch(struct hda_codec
*codec
)
997 struct alc_spec
*spec
= codec
->spec
;
998 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
1002 if (imux
!= spec
->input_mux
) /* no dynamic imux? */
1005 for (n
= 0; n
< spec
->num_adc_nids
; n
++) {
1006 cap
= spec
->private_capsrc_nids
[n
];
1007 for (i
= 0; i
< imux
->num_items
; i
++) {
1008 pin
= spec
->imux_pins
[i
];
1011 if (get_connection_index(codec
, cap
, pin
) < 0)
1014 if (i
>= imux
->num_items
)
1015 return true; /* no ADC-switch is needed */
1018 for (i
= 0; i
< imux
->num_items
; i
++) {
1019 pin
= spec
->imux_pins
[i
];
1020 for (n
= 0; n
< spec
->num_adc_nids
; n
++) {
1021 cap
= spec
->private_capsrc_nids
[n
];
1022 idx
= get_connection_index(codec
, cap
, pin
);
1024 imux
->items
[i
].index
= idx
;
1025 spec
->dyn_adc_idx
[i
] = n
;
1031 snd_printdd("realtek: enabling ADC switching\n");
1032 spec
->dyn_adc_switch
= 1;
1036 /* rebuild imux for matching with the given auto-mic pins (if not yet) */
1037 static bool alc_rebuild_imux_for_auto_mic(struct hda_codec
*codec
)
1039 struct alc_spec
*spec
= codec
->spec
;
1040 struct hda_input_mux
*imux
;
1041 static char * const texts
[3] = {
1042 "Mic", "Internal Mic", "Dock Mic"
1046 if (!spec
->auto_mic
)
1048 imux
= &spec
->private_imux
[0];
1049 if (spec
->input_mux
== imux
)
1051 spec
->imux_pins
[0] = spec
->ext_mic_pin
;
1052 spec
->imux_pins
[1] = spec
->int_mic_pin
;
1053 spec
->imux_pins
[2] = spec
->dock_mic_pin
;
1054 for (i
= 0; i
< 3; i
++) {
1055 strcpy(imux
->items
[i
].label
, texts
[i
]);
1056 if (spec
->imux_pins
[i
]) {
1057 hda_nid_t pin
= spec
->imux_pins
[i
];
1059 for (c
= 0; c
< spec
->num_adc_nids
; c
++) {
1060 hda_nid_t cap
= get_capsrc(spec
, c
);
1061 int idx
= get_connection_index(codec
, cap
, pin
);
1063 imux
->items
[i
].index
= idx
;
1067 imux
->num_items
= i
+ 1;
1070 spec
->num_mux_defs
= 1;
1071 spec
->input_mux
= imux
;
1075 /* check whether all auto-mic pins are valid; setup indices if OK */
1076 static bool alc_auto_mic_check_imux(struct hda_codec
*codec
)
1078 struct alc_spec
*spec
= codec
->spec
;
1079 const struct hda_input_mux
*imux
;
1081 if (!spec
->auto_mic
)
1083 if (spec
->auto_mic_valid_imux
)
1084 return true; /* already checked */
1086 /* fill up imux indices */
1087 if (!alc_check_dyn_adc_switch(codec
)) {
1092 imux
= spec
->input_mux
;
1093 spec
->ext_mic_idx
= find_idx_in_nid_list(spec
->ext_mic_pin
,
1094 spec
->imux_pins
, imux
->num_items
);
1095 spec
->int_mic_idx
= find_idx_in_nid_list(spec
->int_mic_pin
,
1096 spec
->imux_pins
, imux
->num_items
);
1097 spec
->dock_mic_idx
= find_idx_in_nid_list(spec
->dock_mic_pin
,
1098 spec
->imux_pins
, imux
->num_items
);
1099 if (spec
->ext_mic_idx
< 0 || spec
->int_mic_idx
< 0) {
1101 return false; /* no corresponding imux */
1104 snd_hda_jack_detect_enable(codec
, spec
->ext_mic_pin
, ALC_MIC_EVENT
);
1105 if (spec
->dock_mic_pin
)
1106 snd_hda_jack_detect_enable(codec
, spec
->dock_mic_pin
,
1109 spec
->auto_mic_valid_imux
= 1;
1115 * Check the availability of auto-mic switch;
1116 * Set up if really supported
1118 static void alc_init_auto_mic(struct hda_codec
*codec
)
1120 struct alc_spec
*spec
= codec
->spec
;
1121 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
1122 hda_nid_t fixed
, ext
, dock
;
1125 if (spec
->shared_mic_hp
)
1126 return; /* no auto-mic for the shared I/O */
1128 spec
->ext_mic_idx
= spec
->int_mic_idx
= spec
->dock_mic_idx
= -1;
1130 fixed
= ext
= dock
= 0;
1131 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
1132 hda_nid_t nid
= cfg
->inputs
[i
].pin
;
1133 unsigned int defcfg
;
1134 defcfg
= snd_hda_codec_get_pincfg(codec
, nid
);
1135 switch (snd_hda_get_input_pin_attr(defcfg
)) {
1136 case INPUT_PIN_ATTR_INT
:
1138 return; /* already occupied */
1139 if (cfg
->inputs
[i
].type
!= AUTO_PIN_MIC
)
1140 return; /* invalid type */
1143 case INPUT_PIN_ATTR_UNUSED
:
1144 return; /* invalid entry */
1145 case INPUT_PIN_ATTR_DOCK
:
1147 return; /* already occupied */
1148 if (cfg
->inputs
[i
].type
> AUTO_PIN_LINE_IN
)
1149 return; /* invalid type */
1154 return; /* already occupied */
1155 if (cfg
->inputs
[i
].type
!= AUTO_PIN_MIC
)
1156 return; /* invalid type */
1167 if (!is_jack_detectable(codec
, ext
))
1168 return; /* no unsol support */
1169 if (dock
&& !is_jack_detectable(codec
, dock
))
1170 return; /* no unsol support */
1172 /* check imux indices */
1173 spec
->ext_mic_pin
= ext
;
1174 spec
->int_mic_pin
= fixed
;
1175 spec
->dock_mic_pin
= dock
;
1178 if (!alc_auto_mic_check_imux(codec
))
1181 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1183 spec
->unsol_event
= alc_sku_unsol_event
;
1186 /* check the availabilities of auto-mute and auto-mic switches */
1187 static void alc_auto_check_switches(struct hda_codec
*codec
)
1189 alc_init_automute(codec
);
1190 alc_init_auto_mic(codec
);
1194 * Realtek SSID verification
1197 /* Could be any non-zero and even value. When used as fixup, tells
1198 * the driver to ignore any present sku defines.
1200 #define ALC_FIXUP_SKU_IGNORE (2)
1202 static int alc_auto_parse_customize_define(struct hda_codec
*codec
)
1204 unsigned int ass
, tmp
, i
;
1206 struct alc_spec
*spec
= codec
->spec
;
1208 spec
->cdefine
.enable_pcbeep
= 1; /* assume always enabled */
1210 if (spec
->cdefine
.fixup
) {
1211 ass
= spec
->cdefine
.sku_cfg
;
1212 if (ass
== ALC_FIXUP_SKU_IGNORE
)
1217 ass
= codec
->subsystem_id
& 0xffff;
1218 if (ass
!= codec
->bus
->pci
->subsystem_device
&& (ass
& 1))
1222 if (codec
->vendor_id
== 0x10ec0260)
1224 ass
= snd_hda_codec_get_pincfg(codec
, nid
);
1227 printk(KERN_INFO
"hda_codec: %s: SKU not ready 0x%08x\n",
1228 codec
->chip_name
, ass
);
1234 for (i
= 1; i
< 16; i
++) {
1238 if (((ass
>> 16) & 0xf) != tmp
)
1241 spec
->cdefine
.port_connectivity
= ass
>> 30;
1242 spec
->cdefine
.enable_pcbeep
= (ass
& 0x100000) >> 20;
1243 spec
->cdefine
.check_sum
= (ass
>> 16) & 0xf;
1244 spec
->cdefine
.customization
= ass
>> 8;
1246 spec
->cdefine
.sku_cfg
= ass
;
1247 spec
->cdefine
.external_amp
= (ass
& 0x38) >> 3;
1248 spec
->cdefine
.platform_type
= (ass
& 0x4) >> 2;
1249 spec
->cdefine
.swap
= (ass
& 0x2) >> 1;
1250 spec
->cdefine
.override
= ass
& 0x1;
1252 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1253 nid
, spec
->cdefine
.sku_cfg
);
1254 snd_printd("SKU: port_connectivity=0x%x\n",
1255 spec
->cdefine
.port_connectivity
);
1256 snd_printd("SKU: enable_pcbeep=0x%x\n", spec
->cdefine
.enable_pcbeep
);
1257 snd_printd("SKU: check_sum=0x%08x\n", spec
->cdefine
.check_sum
);
1258 snd_printd("SKU: customization=0x%08x\n", spec
->cdefine
.customization
);
1259 snd_printd("SKU: external_amp=0x%x\n", spec
->cdefine
.external_amp
);
1260 snd_printd("SKU: platform_type=0x%x\n", spec
->cdefine
.platform_type
);
1261 snd_printd("SKU: swap=0x%x\n", spec
->cdefine
.swap
);
1262 snd_printd("SKU: override=0x%x\n", spec
->cdefine
.override
);
1267 /* return true if the given NID is found in the list */
1268 static bool found_in_nid_list(hda_nid_t nid
, const hda_nid_t
*list
, int nums
)
1270 return find_idx_in_nid_list(nid
, list
, nums
) >= 0;
1273 /* check subsystem ID and set up device-specific initialization;
1274 * return 1 if initialized, 0 if invalid SSID
1276 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1277 * 31 ~ 16 : Manufacture ID
1279 * 7 ~ 0 : Assembly ID
1280 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1282 static int alc_subsystem_id(struct hda_codec
*codec
,
1283 hda_nid_t porta
, hda_nid_t porte
,
1284 hda_nid_t portd
, hda_nid_t porti
)
1286 unsigned int ass
, tmp
, i
;
1288 struct alc_spec
*spec
= codec
->spec
;
1290 if (spec
->cdefine
.fixup
) {
1291 ass
= spec
->cdefine
.sku_cfg
;
1292 if (ass
== ALC_FIXUP_SKU_IGNORE
)
1297 ass
= codec
->subsystem_id
& 0xffff;
1298 if ((ass
!= codec
->bus
->pci
->subsystem_device
) && (ass
& 1))
1301 /* invalid SSID, check the special NID pin defcfg instead */
1303 * 31~30 : port connectivity
1306 * 19~16 : Check sum (15:1)
1311 if (codec
->vendor_id
== 0x10ec0260)
1313 ass
= snd_hda_codec_get_pincfg(codec
, nid
);
1314 snd_printd("realtek: No valid SSID, "
1315 "checking pincfg 0x%08x for NID 0x%x\n",
1319 if ((ass
>> 30) != 1) /* no physical connection */
1324 for (i
= 1; i
< 16; i
++) {
1328 if (((ass
>> 16) & 0xf) != tmp
)
1331 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1332 ass
& 0xffff, codec
->vendor_id
);
1336 * 2 : 0 --> Desktop, 1 --> Laptop
1337 * 3~5 : External Amplifier control
1340 tmp
= (ass
& 0x38) >> 3; /* external Amp control */
1343 spec
->init_amp
= ALC_INIT_GPIO1
;
1346 spec
->init_amp
= ALC_INIT_GPIO2
;
1349 spec
->init_amp
= ALC_INIT_GPIO3
;
1353 spec
->init_amp
= ALC_INIT_DEFAULT
;
1357 /* is laptop or Desktop and enable the function "Mute internal speaker
1358 * when the external headphone out jack is plugged"
1360 if (!(ass
& 0x8000))
1363 * 10~8 : Jack location
1364 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1366 * 15 : 1 --> enable the function "Mute internal speaker
1367 * when the external headphone out jack is plugged"
1369 if (!spec
->autocfg
.hp_pins
[0] &&
1370 !(spec
->autocfg
.line_out_pins
[0] &&
1371 spec
->autocfg
.line_out_type
== AUTO_PIN_HP_OUT
)) {
1373 tmp
= (ass
>> 11) & 0x3; /* HP to chassis */
1384 if (found_in_nid_list(nid
, spec
->autocfg
.line_out_pins
,
1385 spec
->autocfg
.line_outs
))
1387 spec
->autocfg
.hp_pins
[0] = nid
;
1392 /* Check the validity of ALC subsystem-id
1393 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1394 static void alc_ssid_check(struct hda_codec
*codec
, const hda_nid_t
*ports
)
1396 if (!alc_subsystem_id(codec
, ports
[0], ports
[1], ports
[2], ports
[3])) {
1397 struct alc_spec
*spec
= codec
->spec
;
1398 snd_printd("realtek: "
1399 "Enable default setup for auto mode as fallback\n");
1400 spec
->init_amp
= ALC_INIT_DEFAULT
;
1405 * Fix-up pin default configurations and add default verbs
1413 struct alc_model_fixup
{
1424 const struct alc_pincfg
*pins
;
1425 const struct hda_verb
*verbs
;
1426 void (*func
)(struct hda_codec
*codec
,
1427 const struct alc_fixup
*fix
,
1441 ALC_FIXUP_ACT_PRE_PROBE
,
1442 ALC_FIXUP_ACT_PROBE
,
1446 static void alc_apply_fixup(struct hda_codec
*codec
, int action
)
1448 struct alc_spec
*spec
= codec
->spec
;
1449 int id
= spec
->fixup_id
;
1450 #ifdef CONFIG_SND_DEBUG_VERBOSE
1451 const char *modelname
= spec
->fixup_name
;
1455 if (!spec
->fixup_list
)
1459 const struct alc_fixup
*fix
= spec
->fixup_list
+ id
;
1460 const struct alc_pincfg
*cfg
;
1462 switch (fix
->type
) {
1464 if (action
!= ALC_FIXUP_ACT_PRE_PROBE
|| !fix
->v
.sku
)
1466 snd_printdd(KERN_INFO
"hda_codec: %s: "
1467 "Apply sku override for %s\n",
1468 codec
->chip_name
, modelname
);
1469 spec
->cdefine
.sku_cfg
= fix
->v
.sku
;
1470 spec
->cdefine
.fixup
= 1;
1472 case ALC_FIXUP_PINS
:
1474 if (action
!= ALC_FIXUP_ACT_PRE_PROBE
|| !cfg
)
1476 snd_printdd(KERN_INFO
"hda_codec: %s: "
1477 "Apply pincfg for %s\n",
1478 codec
->chip_name
, modelname
);
1479 for (; cfg
->nid
; cfg
++)
1480 snd_hda_codec_set_pincfg(codec
, cfg
->nid
,
1483 case ALC_FIXUP_VERBS
:
1484 if (action
!= ALC_FIXUP_ACT_PROBE
|| !fix
->v
.verbs
)
1486 snd_printdd(KERN_INFO
"hda_codec: %s: "
1487 "Apply fix-verbs for %s\n",
1488 codec
->chip_name
, modelname
);
1489 add_verb(codec
->spec
, fix
->v
.verbs
);
1491 case ALC_FIXUP_FUNC
:
1494 snd_printdd(KERN_INFO
"hda_codec: %s: "
1495 "Apply fix-func for %s\n",
1496 codec
->chip_name
, modelname
);
1497 fix
->v
.func(codec
, fix
, action
);
1500 snd_printk(KERN_ERR
"hda_codec: %s: "
1501 "Invalid fixup type %d\n",
1502 codec
->chip_name
, fix
->type
);
1513 static void alc_pick_fixup(struct hda_codec
*codec
,
1514 const struct alc_model_fixup
*models
,
1515 const struct snd_pci_quirk
*quirk
,
1516 const struct alc_fixup
*fixlist
)
1518 struct alc_spec
*spec
= codec
->spec
;
1519 const struct snd_pci_quirk
*q
;
1521 const char *name
= NULL
;
1523 if (codec
->modelname
&& models
) {
1524 while (models
->name
) {
1525 if (!strcmp(codec
->modelname
, models
->name
)) {
1527 name
= models
->name
;
1534 q
= snd_pci_quirk_lookup(codec
->bus
->pci
, quirk
);
1537 #ifdef CONFIG_SND_DEBUG_VERBOSE
1543 for (q
= quirk
; q
->subvendor
; q
++) {
1544 unsigned int vendorid
=
1545 q
->subdevice
| (q
->subvendor
<< 16);
1546 if (vendorid
== codec
->subsystem_id
) {
1548 #ifdef CONFIG_SND_DEBUG_VERBOSE
1556 spec
->fixup_id
= id
;
1558 spec
->fixup_list
= fixlist
;
1559 spec
->fixup_name
= name
;
1564 * COEF access helper functions
1566 static int alc_read_coef_idx(struct hda_codec
*codec
,
1567 unsigned int coef_idx
)
1570 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_COEF_INDEX
,
1572 val
= snd_hda_codec_read(codec
, 0x20, 0,
1573 AC_VERB_GET_PROC_COEF
, 0);
1577 static void alc_write_coef_idx(struct hda_codec
*codec
, unsigned int coef_idx
,
1578 unsigned int coef_val
)
1580 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_COEF_INDEX
,
1582 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_PROC_COEF
,
1586 /* a special bypass for COEF 0; read the cached value at the second time */
1587 static unsigned int alc_get_coef0(struct hda_codec
*codec
)
1589 struct alc_spec
*spec
= codec
->spec
;
1591 spec
->coef0
= alc_read_coef_idx(codec
, 0);
1596 * Digital I/O handling
1599 /* set right pin controls for digital I/O */
1600 static void alc_auto_init_digital(struct hda_codec
*codec
)
1602 struct alc_spec
*spec
= codec
->spec
;
1606 for (i
= 0; i
< spec
->autocfg
.dig_outs
; i
++) {
1607 pin
= spec
->autocfg
.dig_out_pins
[i
];
1610 snd_hda_codec_write(codec
, pin
, 0,
1611 AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
);
1613 dac
= spec
->multiout
.dig_out_nid
;
1615 dac
= spec
->slave_dig_outs
[i
- 1];
1616 if (!dac
|| !(get_wcaps(codec
, dac
) & AC_WCAP_OUT_AMP
))
1618 snd_hda_codec_write(codec
, dac
, 0,
1619 AC_VERB_SET_AMP_GAIN_MUTE
,
1622 pin
= spec
->autocfg
.dig_in_pin
;
1624 snd_hda_codec_write(codec
, pin
, 0,
1625 AC_VERB_SET_PIN_WIDGET_CONTROL
,
1629 /* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1630 static void alc_auto_parse_digital(struct hda_codec
*codec
)
1632 struct alc_spec
*spec
= codec
->spec
;
1636 /* support multiple SPDIFs; the secondary is set up as a slave */
1638 for (i
= 0; i
< spec
->autocfg
.dig_outs
; i
++) {
1640 err
= snd_hda_get_connections(codec
,
1641 spec
->autocfg
.dig_out_pins
[i
],
1642 conn
, ARRAY_SIZE(conn
));
1645 dig_nid
= conn
[0]; /* assume the first element is audio-out */
1647 spec
->multiout
.dig_out_nid
= dig_nid
;
1648 spec
->dig_out_type
= spec
->autocfg
.dig_out_type
[0];
1650 spec
->multiout
.slave_dig_outs
= spec
->slave_dig_outs
;
1651 if (nums
>= ARRAY_SIZE(spec
->slave_dig_outs
) - 1)
1653 spec
->slave_dig_outs
[nums
- 1] = dig_nid
;
1658 if (spec
->autocfg
.dig_in_pin
) {
1659 dig_nid
= codec
->start_nid
;
1660 for (i
= 0; i
< codec
->num_nodes
; i
++, dig_nid
++) {
1661 unsigned int wcaps
= get_wcaps(codec
, dig_nid
);
1662 if (get_wcaps_type(wcaps
) != AC_WID_AUD_IN
)
1664 if (!(wcaps
& AC_WCAP_DIGITAL
))
1666 if (!(wcaps
& AC_WCAP_CONN_LIST
))
1668 err
= get_connection_index(codec
, dig_nid
,
1669 spec
->autocfg
.dig_in_pin
);
1671 spec
->dig_in_nid
= dig_nid
;
1679 * capture mixer elements
1681 static int alc_cap_vol_info(struct snd_kcontrol
*kcontrol
,
1682 struct snd_ctl_elem_info
*uinfo
)
1684 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1685 struct alc_spec
*spec
= codec
->spec
;
1689 mutex_lock(&codec
->control_mutex
);
1690 if (spec
->vol_in_capsrc
)
1691 val
= HDA_COMPOSE_AMP_VAL(spec
->capsrc_nids
[0], 3, 0, HDA_OUTPUT
);
1693 val
= HDA_COMPOSE_AMP_VAL(spec
->adc_nids
[0], 3, 0, HDA_INPUT
);
1694 kcontrol
->private_value
= val
;
1695 err
= snd_hda_mixer_amp_volume_info(kcontrol
, uinfo
);
1696 mutex_unlock(&codec
->control_mutex
);
1700 static int alc_cap_vol_tlv(struct snd_kcontrol
*kcontrol
, int op_flag
,
1701 unsigned int size
, unsigned int __user
*tlv
)
1703 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1704 struct alc_spec
*spec
= codec
->spec
;
1708 mutex_lock(&codec
->control_mutex
);
1709 if (spec
->vol_in_capsrc
)
1710 val
= HDA_COMPOSE_AMP_VAL(spec
->capsrc_nids
[0], 3, 0, HDA_OUTPUT
);
1712 val
= HDA_COMPOSE_AMP_VAL(spec
->adc_nids
[0], 3, 0, HDA_INPUT
);
1713 kcontrol
->private_value
= val
;
1714 err
= snd_hda_mixer_amp_tlv(kcontrol
, op_flag
, size
, tlv
);
1715 mutex_unlock(&codec
->control_mutex
);
1719 typedef int (*getput_call_t
)(struct snd_kcontrol
*kcontrol
,
1720 struct snd_ctl_elem_value
*ucontrol
);
1722 static int alc_cap_getput_caller(struct snd_kcontrol
*kcontrol
,
1723 struct snd_ctl_elem_value
*ucontrol
,
1724 getput_call_t func
, bool check_adc_switch
)
1726 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1727 struct alc_spec
*spec
= codec
->spec
;
1730 mutex_lock(&codec
->control_mutex
);
1731 if (check_adc_switch
&& spec
->dyn_adc_switch
) {
1732 for (i
= 0; i
< spec
->num_adc_nids
; i
++) {
1733 kcontrol
->private_value
=
1734 HDA_COMPOSE_AMP_VAL(spec
->adc_nids
[i
],
1736 err
= func(kcontrol
, ucontrol
);
1741 i
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
1742 if (spec
->vol_in_capsrc
)
1743 kcontrol
->private_value
=
1744 HDA_COMPOSE_AMP_VAL(spec
->capsrc_nids
[i
],
1747 kcontrol
->private_value
=
1748 HDA_COMPOSE_AMP_VAL(spec
->adc_nids
[i
],
1750 err
= func(kcontrol
, ucontrol
);
1753 mutex_unlock(&codec
->control_mutex
);
1757 static int alc_cap_vol_get(struct snd_kcontrol
*kcontrol
,
1758 struct snd_ctl_elem_value
*ucontrol
)
1760 return alc_cap_getput_caller(kcontrol
, ucontrol
,
1761 snd_hda_mixer_amp_volume_get
, false);
1764 static int alc_cap_vol_put(struct snd_kcontrol
*kcontrol
,
1765 struct snd_ctl_elem_value
*ucontrol
)
1767 return alc_cap_getput_caller(kcontrol
, ucontrol
,
1768 snd_hda_mixer_amp_volume_put
, true);
1771 /* capture mixer elements */
1772 #define alc_cap_sw_info snd_ctl_boolean_stereo_info
1774 static int alc_cap_sw_get(struct snd_kcontrol
*kcontrol
,
1775 struct snd_ctl_elem_value
*ucontrol
)
1777 return alc_cap_getput_caller(kcontrol
, ucontrol
,
1778 snd_hda_mixer_amp_switch_get
, false);
1781 static int alc_cap_sw_put(struct snd_kcontrol
*kcontrol
,
1782 struct snd_ctl_elem_value
*ucontrol
)
1784 return alc_cap_getput_caller(kcontrol
, ucontrol
,
1785 snd_hda_mixer_amp_switch_put
, true);
1788 #define _DEFINE_CAPMIX(num) \
1790 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1791 .name = "Capture Switch", \
1792 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1794 .info = alc_cap_sw_info, \
1795 .get = alc_cap_sw_get, \
1796 .put = alc_cap_sw_put, \
1799 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1800 .name = "Capture Volume", \
1801 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1802 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1803 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1805 .info = alc_cap_vol_info, \
1806 .get = alc_cap_vol_get, \
1807 .put = alc_cap_vol_put, \
1808 .tlv = { .c = alc_cap_vol_tlv }, \
1811 #define _DEFINE_CAPSRC(num) \
1813 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1814 /* .name = "Capture Source", */ \
1815 .name = "Input Source", \
1817 .info = alc_mux_enum_info, \
1818 .get = alc_mux_enum_get, \
1819 .put = alc_mux_enum_put, \
1822 #define DEFINE_CAPMIX(num) \
1823 static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
1824 _DEFINE_CAPMIX(num), \
1825 _DEFINE_CAPSRC(num), \
1829 #define DEFINE_CAPMIX_NOSRC(num) \
1830 static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
1831 _DEFINE_CAPMIX(num), \
1835 /* up to three ADCs */
1839 DEFINE_CAPMIX_NOSRC(1);
1840 DEFINE_CAPMIX_NOSRC(2);
1841 DEFINE_CAPMIX_NOSRC(3);
1844 * virtual master controls
1848 * slave controls for virtual master
1850 static const char * const alc_slave_vols
[] = {
1851 "Front Playback Volume",
1852 "Surround Playback Volume",
1853 "Center Playback Volume",
1854 "LFE Playback Volume",
1855 "Side Playback Volume",
1856 "Headphone Playback Volume",
1857 "Speaker Playback Volume",
1858 "Mono Playback Volume",
1859 "Line Out Playback Volume",
1860 "CLFE Playback Volume",
1861 "Bass Speaker Playback Volume",
1862 "PCM Playback Volume",
1866 static const char * const alc_slave_sws
[] = {
1867 "Front Playback Switch",
1868 "Surround Playback Switch",
1869 "Center Playback Switch",
1870 "LFE Playback Switch",
1871 "Side Playback Switch",
1872 "Headphone Playback Switch",
1873 "Speaker Playback Switch",
1874 "Mono Playback Switch",
1875 "IEC958 Playback Switch",
1876 "Line Out Playback Switch",
1877 "CLFE Playback Switch",
1878 "Bass Speaker Playback Switch",
1879 "PCM Playback Switch",
1884 * build control elements
1887 #define NID_MAPPING (-1)
1889 #define SUBDEV_SPEAKER_ (0 << 6)
1890 #define SUBDEV_HP_ (1 << 6)
1891 #define SUBDEV_LINE_ (2 << 6)
1892 #define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1893 #define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1894 #define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1896 static void alc_free_kctls(struct hda_codec
*codec
);
1898 #ifdef CONFIG_SND_HDA_INPUT_BEEP
1899 /* additional beep mixers; the actual parameters are overwritten at build */
1900 static const struct snd_kcontrol_new alc_beep_mixer
[] = {
1901 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT
),
1902 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT
),
1907 static int __alc_build_controls(struct hda_codec
*codec
)
1909 struct alc_spec
*spec
= codec
->spec
;
1910 struct snd_kcontrol
*kctl
= NULL
;
1911 const struct snd_kcontrol_new
*knew
;
1916 for (i
= 0; i
< spec
->num_mixers
; i
++) {
1917 err
= snd_hda_add_new_ctls(codec
, spec
->mixers
[i
]);
1921 if (spec
->cap_mixer
) {
1922 err
= snd_hda_add_new_ctls(codec
, spec
->cap_mixer
);
1926 if (spec
->multiout
.dig_out_nid
) {
1927 err
= snd_hda_create_spdif_out_ctls(codec
,
1928 spec
->multiout
.dig_out_nid
,
1929 spec
->multiout
.dig_out_nid
);
1932 if (!spec
->no_analog
) {
1933 err
= snd_hda_create_spdif_share_sw(codec
,
1937 spec
->multiout
.share_spdif
= 1;
1940 if (spec
->dig_in_nid
) {
1941 err
= snd_hda_create_spdif_in_ctls(codec
, spec
->dig_in_nid
);
1946 #ifdef CONFIG_SND_HDA_INPUT_BEEP
1947 /* create beep controls if needed */
1948 if (spec
->beep_amp
) {
1949 const struct snd_kcontrol_new
*knew
;
1950 for (knew
= alc_beep_mixer
; knew
->name
; knew
++) {
1951 struct snd_kcontrol
*kctl
;
1952 kctl
= snd_ctl_new1(knew
, codec
);
1955 kctl
->private_value
= spec
->beep_amp
;
1956 err
= snd_hda_ctl_add(codec
, 0, kctl
);
1963 /* if we have no master control, let's create it */
1964 if (!spec
->no_analog
&&
1965 !snd_hda_find_mixer_ctl(codec
, "Master Playback Volume")) {
1966 unsigned int vmaster_tlv
[4];
1967 snd_hda_set_vmaster_tlv(codec
, spec
->vmaster_nid
,
1968 HDA_OUTPUT
, vmaster_tlv
);
1969 err
= snd_hda_add_vmaster(codec
, "Master Playback Volume",
1970 vmaster_tlv
, alc_slave_vols
);
1974 if (!spec
->no_analog
&&
1975 !snd_hda_find_mixer_ctl(codec
, "Master Playback Switch")) {
1976 err
= snd_hda_add_vmaster(codec
, "Master Playback Switch",
1977 NULL
, alc_slave_sws
);
1982 /* assign Capture Source enums to NID */
1983 if (spec
->capsrc_nids
|| spec
->adc_nids
) {
1984 kctl
= snd_hda_find_mixer_ctl(codec
, "Capture Source");
1986 kctl
= snd_hda_find_mixer_ctl(codec
, "Input Source");
1987 for (i
= 0; kctl
&& i
< kctl
->count
; i
++) {
1988 err
= snd_hda_add_nid(codec
, kctl
, i
,
1989 get_capsrc(spec
, i
));
1994 if (spec
->cap_mixer
&& spec
->adc_nids
) {
1995 const char *kname
= kctl
? kctl
->id
.name
: NULL
;
1996 for (knew
= spec
->cap_mixer
; knew
->name
; knew
++) {
1997 if (kname
&& strcmp(knew
->name
, kname
) == 0)
1999 kctl
= snd_hda_find_mixer_ctl(codec
, knew
->name
);
2000 for (i
= 0; kctl
&& i
< kctl
->count
; i
++) {
2001 err
= snd_hda_add_nid(codec
, kctl
, i
,
2009 /* other nid->control mapping */
2010 for (i
= 0; i
< spec
->num_mixers
; i
++) {
2011 for (knew
= spec
->mixers
[i
]; knew
->name
; knew
++) {
2012 if (knew
->iface
!= NID_MAPPING
)
2014 kctl
= snd_hda_find_mixer_ctl(codec
, knew
->name
);
2017 u
= knew
->subdevice
;
2018 for (j
= 0; j
< 4; j
++, u
>>= 8) {
2023 case SUBDEV_SPEAKER_
:
2024 nid
= spec
->autocfg
.speaker_pins
[nid
];
2027 nid
= spec
->autocfg
.line_out_pins
[nid
];
2030 nid
= spec
->autocfg
.hp_pins
[nid
];
2035 err
= snd_hda_add_nid(codec
, kctl
, 0, nid
);
2039 u
= knew
->private_value
;
2040 for (j
= 0; j
< 4; j
++, u
>>= 8) {
2044 err
= snd_hda_add_nid(codec
, kctl
, 0, nid
);
2051 alc_free_kctls(codec
); /* no longer needed */
2056 static int alc_build_controls(struct hda_codec
*codec
)
2058 struct alc_spec
*spec
= codec
->spec
;
2059 int err
= __alc_build_controls(codec
);
2062 return snd_hda_jack_add_kctls(codec
, &spec
->autocfg
);
2070 static void alc_init_special_input_src(struct hda_codec
*codec
);
2071 static int alc269_fill_coef(struct hda_codec
*codec
);
2073 static int alc_init(struct hda_codec
*codec
)
2075 struct alc_spec
*spec
= codec
->spec
;
2078 if (codec
->vendor_id
== 0x10ec0269)
2079 alc269_fill_coef(codec
);
2082 alc_auto_init_amp(codec
, spec
->init_amp
);
2084 for (i
= 0; i
< spec
->num_init_verbs
; i
++)
2085 snd_hda_sequence_write(codec
, spec
->init_verbs
[i
]);
2086 alc_init_special_input_src(codec
);
2088 if (spec
->init_hook
)
2089 spec
->init_hook(codec
);
2091 alc_apply_fixup(codec
, ALC_FIXUP_ACT_INIT
);
2093 snd_hda_jack_report_sync(codec
);
2095 hda_call_check_power_status(codec
, 0x01);
2099 static void alc_unsol_event(struct hda_codec
*codec
, unsigned int res
)
2101 struct alc_spec
*spec
= codec
->spec
;
2103 if (spec
->unsol_event
)
2104 spec
->unsol_event(codec
, res
);
2107 #ifdef CONFIG_SND_HDA_POWER_SAVE
2108 static int alc_check_power_status(struct hda_codec
*codec
, hda_nid_t nid
)
2110 struct alc_spec
*spec
= codec
->spec
;
2111 return snd_hda_check_amp_list_power(codec
, &spec
->loopback
, nid
);
2116 * Analog playback callbacks
2118 static int alc_playback_pcm_open(struct hda_pcm_stream
*hinfo
,
2119 struct hda_codec
*codec
,
2120 struct snd_pcm_substream
*substream
)
2122 struct alc_spec
*spec
= codec
->spec
;
2123 return snd_hda_multi_out_analog_open(codec
, &spec
->multiout
, substream
,
2127 static int alc_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
2128 struct hda_codec
*codec
,
2129 unsigned int stream_tag
,
2130 unsigned int format
,
2131 struct snd_pcm_substream
*substream
)
2133 struct alc_spec
*spec
= codec
->spec
;
2134 return snd_hda_multi_out_analog_prepare(codec
, &spec
->multiout
,
2135 stream_tag
, format
, substream
);
2138 static int alc_playback_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
2139 struct hda_codec
*codec
,
2140 struct snd_pcm_substream
*substream
)
2142 struct alc_spec
*spec
= codec
->spec
;
2143 return snd_hda_multi_out_analog_cleanup(codec
, &spec
->multiout
);
2149 static int alc_dig_playback_pcm_open(struct hda_pcm_stream
*hinfo
,
2150 struct hda_codec
*codec
,
2151 struct snd_pcm_substream
*substream
)
2153 struct alc_spec
*spec
= codec
->spec
;
2154 return snd_hda_multi_out_dig_open(codec
, &spec
->multiout
);
2157 static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
2158 struct hda_codec
*codec
,
2159 unsigned int stream_tag
,
2160 unsigned int format
,
2161 struct snd_pcm_substream
*substream
)
2163 struct alc_spec
*spec
= codec
->spec
;
2164 return snd_hda_multi_out_dig_prepare(codec
, &spec
->multiout
,
2165 stream_tag
, format
, substream
);
2168 static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
2169 struct hda_codec
*codec
,
2170 struct snd_pcm_substream
*substream
)
2172 struct alc_spec
*spec
= codec
->spec
;
2173 return snd_hda_multi_out_dig_cleanup(codec
, &spec
->multiout
);
2176 static int alc_dig_playback_pcm_close(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_close(codec
, &spec
->multiout
);
2187 static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream
*hinfo
,
2188 struct hda_codec
*codec
,
2189 unsigned int stream_tag
,
2190 unsigned int format
,
2191 struct snd_pcm_substream
*substream
)
2193 struct alc_spec
*spec
= codec
->spec
;
2195 snd_hda_codec_setup_stream(codec
, spec
->adc_nids
[substream
->number
+ 1],
2196 stream_tag
, 0, format
);
2200 static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
2201 struct hda_codec
*codec
,
2202 struct snd_pcm_substream
*substream
)
2204 struct alc_spec
*spec
= codec
->spec
;
2206 snd_hda_codec_cleanup_stream(codec
,
2207 spec
->adc_nids
[substream
->number
+ 1]);
2211 /* analog capture with dynamic dual-adc changes */
2212 static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream
*hinfo
,
2213 struct hda_codec
*codec
,
2214 unsigned int stream_tag
,
2215 unsigned int format
,
2216 struct snd_pcm_substream
*substream
)
2218 struct alc_spec
*spec
= codec
->spec
;
2219 spec
->cur_adc
= spec
->adc_nids
[spec
->dyn_adc_idx
[spec
->cur_mux
[0]]];
2220 spec
->cur_adc_stream_tag
= stream_tag
;
2221 spec
->cur_adc_format
= format
;
2222 snd_hda_codec_setup_stream(codec
, spec
->cur_adc
, stream_tag
, 0, format
);
2226 static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
2227 struct hda_codec
*codec
,
2228 struct snd_pcm_substream
*substream
)
2230 struct alc_spec
*spec
= codec
->spec
;
2231 snd_hda_codec_cleanup_stream(codec
, spec
->cur_adc
);
2236 static const struct hda_pcm_stream dyn_adc_pcm_analog_capture
= {
2240 .nid
= 0, /* fill later */
2242 .prepare
= dyn_adc_capture_pcm_prepare
,
2243 .cleanup
= dyn_adc_capture_pcm_cleanup
2249 static const struct hda_pcm_stream alc_pcm_analog_playback
= {
2253 /* NID is set in alc_build_pcms */
2255 .open
= alc_playback_pcm_open
,
2256 .prepare
= alc_playback_pcm_prepare
,
2257 .cleanup
= alc_playback_pcm_cleanup
2261 static const struct hda_pcm_stream alc_pcm_analog_capture
= {
2265 /* NID is set in alc_build_pcms */
2268 static const struct hda_pcm_stream alc_pcm_analog_alt_playback
= {
2272 /* NID is set in alc_build_pcms */
2275 static const struct hda_pcm_stream alc_pcm_analog_alt_capture
= {
2276 .substreams
= 2, /* can be overridden */
2279 /* NID is set in alc_build_pcms */
2281 .prepare
= alc_alt_capture_pcm_prepare
,
2282 .cleanup
= alc_alt_capture_pcm_cleanup
2286 static const struct hda_pcm_stream alc_pcm_digital_playback
= {
2290 /* NID is set in alc_build_pcms */
2292 .open
= alc_dig_playback_pcm_open
,
2293 .close
= alc_dig_playback_pcm_close
,
2294 .prepare
= alc_dig_playback_pcm_prepare
,
2295 .cleanup
= alc_dig_playback_pcm_cleanup
2299 static const struct hda_pcm_stream alc_pcm_digital_capture
= {
2303 /* NID is set in alc_build_pcms */
2306 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
2307 static const struct hda_pcm_stream alc_pcm_null_stream
= {
2313 static int alc_build_pcms(struct hda_codec
*codec
)
2315 struct alc_spec
*spec
= codec
->spec
;
2316 struct hda_pcm
*info
= spec
->pcm_rec
;
2317 const struct hda_pcm_stream
*p
;
2318 bool have_multi_adcs
;
2321 codec
->num_pcms
= 1;
2322 codec
->pcm_info
= info
;
2324 if (spec
->no_analog
)
2327 snprintf(spec
->stream_name_analog
, sizeof(spec
->stream_name_analog
),
2328 "%s Analog", codec
->chip_name
);
2329 info
->name
= spec
->stream_name_analog
;
2331 if (spec
->multiout
.num_dacs
> 0) {
2332 p
= spec
->stream_analog_playback
;
2334 p
= &alc_pcm_analog_playback
;
2335 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] = *p
;
2336 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
= spec
->multiout
.dac_nids
[0];
2338 if (spec
->adc_nids
) {
2339 p
= spec
->stream_analog_capture
;
2341 if (spec
->dyn_adc_switch
)
2342 p
= &dyn_adc_pcm_analog_capture
;
2344 p
= &alc_pcm_analog_capture
;
2346 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] = *p
;
2347 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
= spec
->adc_nids
[0];
2350 if (spec
->channel_mode
) {
2351 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].channels_max
= 0;
2352 for (i
= 0; i
< spec
->num_channel_mode
; i
++) {
2353 if (spec
->channel_mode
[i
].channels
> info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].channels_max
) {
2354 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].channels_max
= spec
->channel_mode
[i
].channels
;
2360 /* SPDIF for stream index #1 */
2361 if (spec
->multiout
.dig_out_nid
|| spec
->dig_in_nid
) {
2362 snprintf(spec
->stream_name_digital
,
2363 sizeof(spec
->stream_name_digital
),
2364 "%s Digital", codec
->chip_name
);
2365 codec
->num_pcms
= 2;
2366 codec
->slave_dig_outs
= spec
->multiout
.slave_dig_outs
;
2367 info
= spec
->pcm_rec
+ 1;
2368 info
->name
= spec
->stream_name_digital
;
2369 if (spec
->dig_out_type
)
2370 info
->pcm_type
= spec
->dig_out_type
;
2372 info
->pcm_type
= HDA_PCM_TYPE_SPDIF
;
2373 if (spec
->multiout
.dig_out_nid
) {
2374 p
= spec
->stream_digital_playback
;
2376 p
= &alc_pcm_digital_playback
;
2377 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] = *p
;
2378 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
= spec
->multiout
.dig_out_nid
;
2380 if (spec
->dig_in_nid
) {
2381 p
= spec
->stream_digital_capture
;
2383 p
= &alc_pcm_digital_capture
;
2384 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] = *p
;
2385 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
= spec
->dig_in_nid
;
2387 /* FIXME: do we need this for all Realtek codec models? */
2388 codec
->spdif_status_reset
= 1;
2391 if (spec
->no_analog
)
2394 /* If the use of more than one ADC is requested for the current
2395 * model, configure a second analog capture-only PCM.
2397 have_multi_adcs
= (spec
->num_adc_nids
> 1) &&
2398 !spec
->dyn_adc_switch
&& !spec
->auto_mic
&&
2399 (!spec
->input_mux
|| spec
->input_mux
->num_items
> 1);
2400 /* Additional Analaog capture for index #2 */
2401 if (spec
->alt_dac_nid
|| have_multi_adcs
) {
2402 codec
->num_pcms
= 3;
2403 info
= spec
->pcm_rec
+ 2;
2404 info
->name
= spec
->stream_name_analog
;
2405 if (spec
->alt_dac_nid
) {
2406 p
= spec
->stream_analog_alt_playback
;
2408 p
= &alc_pcm_analog_alt_playback
;
2409 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] = *p
;
2410 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
=
2413 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] =
2414 alc_pcm_null_stream
;
2415 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
= 0;
2417 if (have_multi_adcs
) {
2418 p
= spec
->stream_analog_alt_capture
;
2420 p
= &alc_pcm_analog_alt_capture
;
2421 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] = *p
;
2422 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
=
2424 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].substreams
=
2425 spec
->num_adc_nids
- 1;
2427 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] =
2428 alc_pcm_null_stream
;
2429 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
= 0;
2436 static inline void alc_shutup(struct hda_codec
*codec
)
2438 struct alc_spec
*spec
= codec
->spec
;
2440 if (spec
&& spec
->shutup
)
2441 spec
->shutup(codec
);
2442 snd_hda_shutup_pins(codec
);
2445 static void alc_free_kctls(struct hda_codec
*codec
)
2447 struct alc_spec
*spec
= codec
->spec
;
2449 if (spec
->kctls
.list
) {
2450 struct snd_kcontrol_new
*kctl
= spec
->kctls
.list
;
2452 for (i
= 0; i
< spec
->kctls
.used
; i
++)
2453 kfree(kctl
[i
].name
);
2455 snd_array_free(&spec
->kctls
);
2458 static void alc_free_bind_ctls(struct hda_codec
*codec
)
2460 struct alc_spec
*spec
= codec
->spec
;
2461 if (spec
->bind_ctls
.list
) {
2462 struct hda_bind_ctls
**ctl
= spec
->bind_ctls
.list
;
2464 for (i
= 0; i
< spec
->bind_ctls
.used
; i
++)
2467 snd_array_free(&spec
->bind_ctls
);
2470 static void alc_free(struct hda_codec
*codec
)
2472 struct alc_spec
*spec
= codec
->spec
;
2478 alc_free_kctls(codec
);
2479 alc_free_bind_ctls(codec
);
2481 snd_hda_detach_beep_device(codec
);
2484 #ifdef CONFIG_SND_HDA_POWER_SAVE
2485 static void alc_power_eapd(struct hda_codec
*codec
)
2487 alc_auto_setup_eapd(codec
, false);
2490 static int alc_suspend(struct hda_codec
*codec
, pm_message_t state
)
2492 struct alc_spec
*spec
= codec
->spec
;
2494 if (spec
&& spec
->power_hook
)
2495 spec
->power_hook(codec
);
2501 static int alc_resume(struct hda_codec
*codec
)
2503 msleep(150); /* to avoid pop noise */
2504 codec
->patch_ops
.init(codec
);
2505 snd_hda_codec_resume_amp(codec
);
2506 snd_hda_codec_resume_cache(codec
);
2507 hda_call_check_power_status(codec
, 0x01);
2514 static const struct hda_codec_ops alc_patch_ops
= {
2515 .build_controls
= alc_build_controls
,
2516 .build_pcms
= alc_build_pcms
,
2519 .unsol_event
= alc_unsol_event
,
2521 .resume
= alc_resume
,
2523 #ifdef CONFIG_SND_HDA_POWER_SAVE
2524 .suspend
= alc_suspend
,
2525 .check_power_status
= alc_check_power_status
,
2527 .reboot_notify
= alc_shutup
,
2530 /* replace the codec chip_name with the given string */
2531 static int alc_codec_rename(struct hda_codec
*codec
, const char *name
)
2533 kfree(codec
->chip_name
);
2534 codec
->chip_name
= kstrdup(name
, GFP_KERNEL
);
2535 if (!codec
->chip_name
) {
2543 * Rename codecs appropriately from COEF value
2545 struct alc_codec_rename_table
{
2546 unsigned int vendor_id
;
2547 unsigned short coef_mask
;
2548 unsigned short coef_bits
;
2552 static struct alc_codec_rename_table rename_tbl
[] = {
2553 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2554 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2555 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2556 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2557 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2558 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2559 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
2560 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2561 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2562 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2563 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2564 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2565 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2566 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2567 { } /* terminator */
2570 static int alc_codec_rename_from_preset(struct hda_codec
*codec
)
2572 const struct alc_codec_rename_table
*p
;
2574 for (p
= rename_tbl
; p
->vendor_id
; p
++) {
2575 if (p
->vendor_id
!= codec
->vendor_id
)
2577 if ((alc_get_coef0(codec
) & p
->coef_mask
) == p
->coef_bits
)
2578 return alc_codec_rename(codec
, p
->name
);
2584 * Automatic parse of I/O pins from the BIOS configuration
2589 ALC_CTL_WIDGET_MUTE
,
2594 static const struct snd_kcontrol_new alc_control_templates
[] = {
2595 HDA_CODEC_VOLUME(NULL
, 0, 0, 0),
2596 HDA_CODEC_MUTE(NULL
, 0, 0, 0),
2597 HDA_BIND_MUTE(NULL
, 0, 0, 0),
2598 HDA_BIND_VOL(NULL
, 0),
2599 HDA_BIND_SW(NULL
, 0),
2602 /* add dynamic controls */
2603 static int add_control(struct alc_spec
*spec
, int type
, const char *name
,
2604 int cidx
, unsigned long val
)
2606 struct snd_kcontrol_new
*knew
;
2608 knew
= alc_kcontrol_new(spec
);
2611 *knew
= alc_control_templates
[type
];
2612 knew
->name
= kstrdup(name
, GFP_KERNEL
);
2616 if (get_amp_nid_(val
))
2617 knew
->subdevice
= HDA_SUBDEV_AMP_FLAG
;
2618 knew
->private_value
= val
;
2622 static int add_control_with_pfx(struct alc_spec
*spec
, int type
,
2623 const char *pfx
, const char *dir
,
2624 const char *sfx
, int cidx
, unsigned long val
)
2627 snprintf(name
, sizeof(name
), "%s %s %s", pfx
, dir
, sfx
);
2628 return add_control(spec
, type
, name
, cidx
, val
);
2631 #define add_pb_vol_ctrl(spec, type, pfx, val) \
2632 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2633 #define add_pb_sw_ctrl(spec, type, pfx, val) \
2634 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2635 #define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2636 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2637 #define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2638 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
2640 static const char * const channel_name
[4] = {
2641 "Front", "Surround", "CLFE", "Side"
2644 static const char *alc_get_line_out_pfx(struct alc_spec
*spec
, int ch
,
2645 bool can_be_master
, int *index
)
2647 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
2650 if (cfg
->line_outs
== 1 && !spec
->multi_ios
&&
2651 !cfg
->hp_outs
&& !cfg
->speaker_outs
&& can_be_master
)
2654 switch (cfg
->line_out_type
) {
2655 case AUTO_PIN_SPEAKER_OUT
:
2656 if (cfg
->line_outs
== 1)
2658 if (cfg
->line_outs
== 2)
2659 return ch
? "Bass Speaker" : "Speaker";
2661 case AUTO_PIN_HP_OUT
:
2662 /* for multi-io case, only the primary out */
2663 if (ch
&& spec
->multi_ios
)
2668 if (cfg
->line_outs
== 1 && !spec
->multi_ios
)
2672 if (snd_BUG_ON(ch
>= ARRAY_SIZE(channel_name
)))
2675 return channel_name
[ch
];
2678 /* create input playback/capture controls for the given pin */
2679 static int new_analog_input(struct alc_spec
*spec
, hda_nid_t pin
,
2680 const char *ctlname
, int ctlidx
,
2681 int idx
, hda_nid_t mix_nid
)
2685 err
= __add_pb_vol_ctrl(spec
, ALC_CTL_WIDGET_VOL
, ctlname
, ctlidx
,
2686 HDA_COMPOSE_AMP_VAL(mix_nid
, 3, idx
, HDA_INPUT
));
2689 err
= __add_pb_sw_ctrl(spec
, ALC_CTL_WIDGET_MUTE
, ctlname
, ctlidx
,
2690 HDA_COMPOSE_AMP_VAL(mix_nid
, 3, idx
, HDA_INPUT
));
2696 static int alc_is_input_pin(struct hda_codec
*codec
, hda_nid_t nid
)
2698 unsigned int pincap
= snd_hda_query_pin_caps(codec
, nid
);
2699 return (pincap
& AC_PINCAP_IN
) != 0;
2702 /* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
2703 static int alc_auto_fill_adc_caps(struct hda_codec
*codec
)
2705 struct alc_spec
*spec
= codec
->spec
;
2707 hda_nid_t
*adc_nids
= spec
->private_adc_nids
;
2708 hda_nid_t
*cap_nids
= spec
->private_capsrc_nids
;
2709 int max_nums
= ARRAY_SIZE(spec
->private_adc_nids
);
2712 nid
= codec
->start_nid
;
2713 for (i
= 0; i
< codec
->num_nodes
; i
++, nid
++) {
2715 const hda_nid_t
*list
;
2716 unsigned int caps
= get_wcaps(codec
, nid
);
2717 int type
= get_wcaps_type(caps
);
2719 if (type
!= AC_WID_AUD_IN
|| (caps
& AC_WCAP_DIGITAL
))
2721 adc_nids
[nums
] = nid
;
2722 cap_nids
[nums
] = nid
;
2726 type
= get_wcaps_type(get_wcaps(codec
, src
));
2727 if (type
== AC_WID_PIN
)
2729 if (type
== AC_WID_AUD_SEL
) {
2730 cap_nids
[nums
] = src
;
2733 n
= snd_hda_get_conn_list(codec
, src
, &list
);
2735 cap_nids
[nums
] = src
;
2741 if (++nums
>= max_nums
)
2744 spec
->adc_nids
= spec
->private_adc_nids
;
2745 spec
->capsrc_nids
= spec
->private_capsrc_nids
;
2746 spec
->num_adc_nids
= nums
;
2750 /* create playback/capture controls for input pins */
2751 static int alc_auto_create_input_ctls(struct hda_codec
*codec
)
2753 struct alc_spec
*spec
= codec
->spec
;
2754 const struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
2755 hda_nid_t mixer
= spec
->mixer_nid
;
2756 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
2758 int i
, c
, err
, idx
, type_idx
= 0;
2759 const char *prev_label
= NULL
;
2761 num_adcs
= alc_auto_fill_adc_caps(codec
);
2765 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
2769 pin
= cfg
->inputs
[i
].pin
;
2770 if (!alc_is_input_pin(codec
, pin
))
2773 label
= hda_get_autocfg_input_label(codec
, cfg
, i
);
2774 if (spec
->shared_mic_hp
&& !strcmp(label
, "Misc"))
2775 label
= "Headphone Mic";
2776 if (prev_label
&& !strcmp(label
, prev_label
))
2783 idx
= get_connection_index(codec
, mixer
, pin
);
2785 err
= new_analog_input(spec
, pin
,
2793 for (c
= 0; c
< num_adcs
; c
++) {
2794 hda_nid_t cap
= get_capsrc(spec
, c
);
2795 idx
= get_connection_index(codec
, cap
, pin
);
2797 spec
->imux_pins
[imux
->num_items
] = pin
;
2798 snd_hda_add_imux_item(imux
, label
, idx
, NULL
);
2804 spec
->num_mux_defs
= 1;
2805 spec
->input_mux
= imux
;
2810 /* create a shared input with the headphone out */
2811 static int alc_auto_create_shared_input(struct hda_codec
*codec
)
2813 struct alc_spec
*spec
= codec
->spec
;
2814 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
2815 unsigned int defcfg
;
2818 /* only one internal input pin? */
2819 if (cfg
->num_inputs
!= 1)
2821 defcfg
= snd_hda_codec_get_pincfg(codec
, cfg
->inputs
[0].pin
);
2822 if (snd_hda_get_input_pin_attr(defcfg
) != INPUT_PIN_ATTR_INT
)
2825 if (cfg
->hp_outs
== 1 && cfg
->line_out_type
== AUTO_PIN_SPEAKER_OUT
)
2826 nid
= cfg
->hp_pins
[0]; /* OK, we have a single HP-out */
2827 else if (cfg
->line_outs
== 1 && cfg
->line_out_type
== AUTO_PIN_HP_OUT
)
2828 nid
= cfg
->line_out_pins
[0]; /* OK, we have a single line-out */
2830 return 0; /* both not available */
2832 if (!(snd_hda_query_pin_caps(codec
, nid
) & AC_PINCAP_IN
))
2833 return 0; /* no input */
2835 cfg
->inputs
[1].pin
= nid
;
2836 cfg
->inputs
[1].type
= AUTO_PIN_MIC
;
2837 cfg
->num_inputs
= 2;
2838 spec
->shared_mic_hp
= 1;
2839 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid
);
2843 static void alc_set_pin_output(struct hda_codec
*codec
, hda_nid_t nid
,
2844 unsigned int pin_type
)
2846 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_PIN_WIDGET_CONTROL
,
2849 if (nid_has_mute(codec
, nid
, HDA_OUTPUT
))
2850 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
2854 static int get_pin_type(int line_out_type
)
2856 if (line_out_type
== AUTO_PIN_HP_OUT
)
2862 static void alc_auto_init_analog_input(struct hda_codec
*codec
)
2864 struct alc_spec
*spec
= codec
->spec
;
2865 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
2868 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
2869 hda_nid_t nid
= cfg
->inputs
[i
].pin
;
2870 if (alc_is_input_pin(codec
, nid
)) {
2871 alc_set_input_pin(codec
, nid
, cfg
->inputs
[i
].type
);
2872 if (get_wcaps(codec
, nid
) & AC_WCAP_OUT_AMP
)
2873 snd_hda_codec_write(codec
, nid
, 0,
2874 AC_VERB_SET_AMP_GAIN_MUTE
,
2879 /* mute all loopback inputs */
2880 if (spec
->mixer_nid
) {
2881 int nums
= snd_hda_get_conn_list(codec
, spec
->mixer_nid
, NULL
);
2882 for (i
= 0; i
< nums
; i
++)
2883 snd_hda_codec_write(codec
, spec
->mixer_nid
, 0,
2884 AC_VERB_SET_AMP_GAIN_MUTE
,
2889 /* convert from MIX nid to DAC */
2890 static hda_nid_t
alc_auto_mix_to_dac(struct hda_codec
*codec
, hda_nid_t nid
)
2895 if (get_wcaps_type(get_wcaps(codec
, nid
)) == AC_WID_AUD_OUT
)
2897 num
= snd_hda_get_connections(codec
, nid
, list
, ARRAY_SIZE(list
));
2898 for (i
= 0; i
< num
; i
++) {
2899 if (get_wcaps_type(get_wcaps(codec
, list
[i
])) == AC_WID_AUD_OUT
)
2905 /* go down to the selector widget before the mixer */
2906 static hda_nid_t
alc_go_down_to_selector(struct hda_codec
*codec
, hda_nid_t pin
)
2909 int num
= snd_hda_get_connections(codec
, pin
, srcs
,
2912 get_wcaps_type(get_wcaps(codec
, srcs
[0])) != AC_WID_AUD_SEL
)
2917 /* get MIX nid connected to the given pin targeted to DAC */
2918 static hda_nid_t
alc_auto_dac_to_mix(struct hda_codec
*codec
, hda_nid_t pin
,
2924 pin
= alc_go_down_to_selector(codec
, pin
);
2925 num
= snd_hda_get_connections(codec
, pin
, mix
, ARRAY_SIZE(mix
));
2926 for (i
= 0; i
< num
; i
++) {
2927 if (alc_auto_mix_to_dac(codec
, mix
[i
]) == dac
)
2933 /* select the connection from pin to DAC if needed */
2934 static int alc_auto_select_dac(struct hda_codec
*codec
, hda_nid_t pin
,
2940 pin
= alc_go_down_to_selector(codec
, pin
);
2941 num
= snd_hda_get_connections(codec
, pin
, mix
, ARRAY_SIZE(mix
));
2944 for (i
= 0; i
< num
; i
++) {
2945 if (alc_auto_mix_to_dac(codec
, mix
[i
]) == dac
) {
2946 snd_hda_codec_update_cache(codec
, pin
, 0,
2947 AC_VERB_SET_CONNECT_SEL
, i
);
2954 /* look for an empty DAC slot */
2955 static hda_nid_t
alc_auto_look_for_dac(struct hda_codec
*codec
, hda_nid_t pin
)
2957 struct alc_spec
*spec
= codec
->spec
;
2961 pin
= alc_go_down_to_selector(codec
, pin
);
2962 num
= snd_hda_get_connections(codec
, pin
, srcs
, ARRAY_SIZE(srcs
));
2963 for (i
= 0; i
< num
; i
++) {
2964 hda_nid_t nid
= alc_auto_mix_to_dac(codec
, srcs
[i
]);
2967 if (found_in_nid_list(nid
, spec
->multiout
.dac_nids
,
2968 ARRAY_SIZE(spec
->private_dac_nids
)))
2970 if (found_in_nid_list(nid
, spec
->multiout
.hp_out_nid
,
2971 ARRAY_SIZE(spec
->multiout
.hp_out_nid
)))
2973 if (found_in_nid_list(nid
, spec
->multiout
.extra_out_nid
,
2974 ARRAY_SIZE(spec
->multiout
.extra_out_nid
)))
2981 /* check whether the DAC is reachable from the pin */
2982 static bool alc_auto_is_dac_reachable(struct hda_codec
*codec
,
2983 hda_nid_t pin
, hda_nid_t dac
)
2988 pin
= alc_go_down_to_selector(codec
, pin
);
2989 num
= snd_hda_get_connections(codec
, pin
, srcs
, ARRAY_SIZE(srcs
));
2990 for (i
= 0; i
< num
; i
++) {
2991 hda_nid_t nid
= alc_auto_mix_to_dac(codec
, srcs
[i
]);
2998 static hda_nid_t
get_dac_if_single(struct hda_codec
*codec
, hda_nid_t pin
)
3000 hda_nid_t sel
= alc_go_down_to_selector(codec
, pin
);
3001 if (snd_hda_get_conn_list(codec
, sel
, NULL
) == 1)
3002 return alc_auto_look_for_dac(codec
, pin
);
3006 /* return 0 if no possible DAC is found, 1 if one or more found */
3007 static int alc_auto_fill_extra_dacs(struct hda_codec
*codec
, int num_outs
,
3008 const hda_nid_t
*pins
, hda_nid_t
*dacs
)
3012 if (num_outs
&& !dacs
[0]) {
3013 dacs
[0] = alc_auto_look_for_dac(codec
, pins
[0]);
3018 for (i
= 1; i
< num_outs
; i
++)
3019 dacs
[i
] = get_dac_if_single(codec
, pins
[i
]);
3020 for (i
= 1; i
< num_outs
; i
++) {
3022 dacs
[i
] = alc_auto_look_for_dac(codec
, pins
[i
]);
3027 static int alc_auto_fill_multi_ios(struct hda_codec
*codec
,
3028 unsigned int location
, int offset
);
3029 static hda_nid_t
alc_look_for_out_vol_nid(struct hda_codec
*codec
,
3030 hda_nid_t pin
, hda_nid_t dac
);
3032 /* fill in the dac_nids table from the parsed pin configuration */
3033 static int alc_auto_fill_dac_nids(struct hda_codec
*codec
)
3035 struct alc_spec
*spec
= codec
->spec
;
3036 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
3037 unsigned int location
, defcfg
;
3039 bool redone
= false;
3043 /* set num_dacs once to full for alc_auto_look_for_dac() */
3044 spec
->multiout
.num_dacs
= cfg
->line_outs
;
3045 spec
->multiout
.hp_out_nid
[0] = 0;
3046 spec
->multiout
.extra_out_nid
[0] = 0;
3047 memset(spec
->private_dac_nids
, 0, sizeof(spec
->private_dac_nids
));
3048 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
3049 spec
->multi_ios
= 0;
3051 /* fill hard-wired DACs first */
3053 for (i
= 0; i
< cfg
->line_outs
; i
++)
3054 spec
->private_dac_nids
[i
] =
3055 get_dac_if_single(codec
, cfg
->line_out_pins
[i
]);
3057 spec
->multiout
.hp_out_nid
[0] =
3058 get_dac_if_single(codec
, cfg
->hp_pins
[0]);
3059 if (cfg
->speaker_outs
)
3060 spec
->multiout
.extra_out_nid
[0] =
3061 get_dac_if_single(codec
, cfg
->speaker_pins
[0]);
3064 for (i
= 0; i
< cfg
->line_outs
; i
++) {
3065 hda_nid_t pin
= cfg
->line_out_pins
[i
];
3066 if (spec
->private_dac_nids
[i
])
3068 spec
->private_dac_nids
[i
] = alc_auto_look_for_dac(codec
, pin
);
3069 if (!spec
->private_dac_nids
[i
] && !redone
) {
3070 /* if we can't find primary DACs, re-probe without
3071 * checking the hard-wired DACs
3078 /* re-count num_dacs and squash invalid entries */
3079 spec
->multiout
.num_dacs
= 0;
3080 for (i
= 0; i
< cfg
->line_outs
; i
++) {
3081 if (spec
->private_dac_nids
[i
])
3082 spec
->multiout
.num_dacs
++;
3084 memmove(spec
->private_dac_nids
+ i
,
3085 spec
->private_dac_nids
+ i
+ 1,
3086 sizeof(hda_nid_t
) * (cfg
->line_outs
- i
- 1));
3087 spec
->private_dac_nids
[cfg
->line_outs
- 1] = 0;
3091 if (cfg
->line_outs
== 1 && cfg
->line_out_type
!= AUTO_PIN_SPEAKER_OUT
) {
3092 /* try to fill multi-io first */
3093 defcfg
= snd_hda_codec_get_pincfg(codec
, cfg
->line_out_pins
[0]);
3094 location
= get_defcfg_location(defcfg
);
3096 num_pins
= alc_auto_fill_multi_ios(codec
, location
, 0);
3098 spec
->multi_ios
= num_pins
;
3099 spec
->ext_channel_count
= 2;
3100 spec
->multiout
.num_dacs
= num_pins
+ 1;
3104 if (cfg
->line_out_type
!= AUTO_PIN_HP_OUT
)
3105 alc_auto_fill_extra_dacs(codec
, cfg
->hp_outs
, cfg
->hp_pins
,
3106 spec
->multiout
.hp_out_nid
);
3107 if (cfg
->line_out_type
!= AUTO_PIN_SPEAKER_OUT
) {
3108 int err
= alc_auto_fill_extra_dacs(codec
, cfg
->speaker_outs
,
3110 spec
->multiout
.extra_out_nid
);
3111 /* if no speaker volume is assigned, try again as the primary
3114 if (!err
&& cfg
->speaker_outs
> 0 &&
3115 cfg
->line_out_type
== AUTO_PIN_HP_OUT
) {
3116 cfg
->hp_outs
= cfg
->line_outs
;
3117 memcpy(cfg
->hp_pins
, cfg
->line_out_pins
,
3118 sizeof(cfg
->hp_pins
));
3119 cfg
->line_outs
= cfg
->speaker_outs
;
3120 memcpy(cfg
->line_out_pins
, cfg
->speaker_pins
,
3121 sizeof(cfg
->speaker_pins
));
3122 cfg
->speaker_outs
= 0;
3123 memset(cfg
->speaker_pins
, 0, sizeof(cfg
->speaker_pins
));
3124 cfg
->line_out_type
= AUTO_PIN_SPEAKER_OUT
;
3130 if (!spec
->multi_ios
&&
3131 cfg
->line_out_type
== AUTO_PIN_SPEAKER_OUT
&&
3133 /* try multi-ios with HP + inputs */
3134 defcfg
= snd_hda_codec_get_pincfg(codec
, cfg
->hp_pins
[0]);
3135 location
= get_defcfg_location(defcfg
);
3137 num_pins
= alc_auto_fill_multi_ios(codec
, location
, 1);
3139 spec
->multi_ios
= num_pins
;
3140 spec
->ext_channel_count
= 2;
3141 spec
->multiout
.num_dacs
= num_pins
+ 1;
3145 if (cfg
->line_out_pins
[0])
3147 alc_look_for_out_vol_nid(codec
, cfg
->line_out_pins
[0],
3148 spec
->multiout
.dac_nids
[0]);
3152 static inline unsigned int get_ctl_pos(unsigned int data
)
3154 hda_nid_t nid
= get_amp_nid_(data
);
3156 if (snd_BUG_ON(nid
>= MAX_VOL_NIDS
))
3158 dir
= get_amp_direction_(data
);
3159 return (nid
<< 1) | dir
;
3162 #define is_ctl_used(bits, data) \
3163 test_bit(get_ctl_pos(data), bits)
3164 #define mark_ctl_usage(bits, data) \
3165 set_bit(get_ctl_pos(data), bits)
3167 static int alc_auto_add_vol_ctl(struct hda_codec
*codec
,
3168 const char *pfx
, int cidx
,
3169 hda_nid_t nid
, unsigned int chs
)
3171 struct alc_spec
*spec
= codec
->spec
;
3175 val
= HDA_COMPOSE_AMP_VAL(nid
, chs
, 0, HDA_OUTPUT
);
3176 if (is_ctl_used(spec
->vol_ctls
, val
) && chs
!= 2) /* exclude LFE */
3178 mark_ctl_usage(spec
->vol_ctls
, val
);
3179 return __add_pb_vol_ctrl(codec
->spec
, ALC_CTL_WIDGET_VOL
, pfx
, cidx
,
3183 static int alc_auto_add_stereo_vol(struct hda_codec
*codec
,
3184 const char *pfx
, int cidx
,
3188 if (get_wcaps(codec
, nid
) & AC_WCAP_STEREO
)
3190 return alc_auto_add_vol_ctl(codec
, pfx
, cidx
, nid
, chs
);
3193 /* create a mute-switch for the given mixer widget;
3194 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3196 static int alc_auto_add_sw_ctl(struct hda_codec
*codec
,
3197 const char *pfx
, int cidx
,
3198 hda_nid_t nid
, unsigned int chs
)
3200 struct alc_spec
*spec
= codec
->spec
;
3206 wid_type
= get_wcaps_type(get_wcaps(codec
, nid
));
3207 if (wid_type
== AC_WID_PIN
|| wid_type
== AC_WID_AUD_OUT
) {
3208 type
= ALC_CTL_WIDGET_MUTE
;
3209 val
= HDA_COMPOSE_AMP_VAL(nid
, chs
, 0, HDA_OUTPUT
);
3210 } else if (snd_hda_get_conn_list(codec
, nid
, NULL
) == 1) {
3211 type
= ALC_CTL_WIDGET_MUTE
;
3212 val
= HDA_COMPOSE_AMP_VAL(nid
, chs
, 0, HDA_INPUT
);
3214 type
= ALC_CTL_BIND_MUTE
;
3215 val
= HDA_COMPOSE_AMP_VAL(nid
, chs
, 2, HDA_INPUT
);
3217 if (is_ctl_used(spec
->sw_ctls
, val
) && chs
!= 2) /* exclude LFE */
3219 mark_ctl_usage(spec
->sw_ctls
, val
);
3220 return __add_pb_sw_ctrl(codec
->spec
, type
, pfx
, cidx
, val
);
3223 static int alc_auto_add_stereo_sw(struct hda_codec
*codec
, const char *pfx
,
3224 int cidx
, hda_nid_t nid
)
3227 if (get_wcaps(codec
, nid
) & AC_WCAP_STEREO
)
3229 return alc_auto_add_sw_ctl(codec
, pfx
, cidx
, nid
, chs
);
3232 static hda_nid_t
alc_look_for_out_mute_nid(struct hda_codec
*codec
,
3233 hda_nid_t pin
, hda_nid_t dac
)
3235 hda_nid_t mix
= alc_auto_dac_to_mix(codec
, pin
, dac
);
3236 if (nid_has_mute(codec
, pin
, HDA_OUTPUT
))
3238 else if (mix
&& nid_has_mute(codec
, mix
, HDA_INPUT
))
3240 else if (nid_has_mute(codec
, dac
, HDA_OUTPUT
))
3245 static hda_nid_t
alc_look_for_out_vol_nid(struct hda_codec
*codec
,
3246 hda_nid_t pin
, hda_nid_t dac
)
3248 hda_nid_t mix
= alc_auto_dac_to_mix(codec
, pin
, dac
);
3249 if (nid_has_volume(codec
, dac
, HDA_OUTPUT
))
3251 else if (nid_has_volume(codec
, mix
, HDA_OUTPUT
))
3253 else if (nid_has_volume(codec
, pin
, HDA_OUTPUT
))
3258 /* add playback controls from the parsed DAC table */
3259 static int alc_auto_create_multi_out_ctls(struct hda_codec
*codec
,
3260 const struct auto_pin_cfg
*cfg
)
3262 struct alc_spec
*spec
= codec
->spec
;
3263 int i
, err
, noutputs
;
3265 noutputs
= cfg
->line_outs
;
3266 if (spec
->multi_ios
> 0 && cfg
->line_outs
< 3)
3267 noutputs
+= spec
->multi_ios
;
3269 for (i
= 0; i
< noutputs
; i
++) {
3275 dac
= spec
->multiout
.dac_nids
[i
];
3278 if (i
>= cfg
->line_outs
)
3279 pin
= spec
->multi_io
[i
- 1].pin
;
3281 pin
= cfg
->line_out_pins
[i
];
3283 sw
= alc_look_for_out_mute_nid(codec
, pin
, dac
);
3284 vol
= alc_look_for_out_vol_nid(codec
, pin
, dac
);
3285 name
= alc_get_line_out_pfx(spec
, i
, true, &index
);
3286 if (!name
|| !strcmp(name
, "CLFE")) {
3288 err
= alc_auto_add_vol_ctl(codec
, "Center", 0, vol
, 1);
3291 err
= alc_auto_add_vol_ctl(codec
, "LFE", 0, vol
, 2);
3294 err
= alc_auto_add_sw_ctl(codec
, "Center", 0, sw
, 1);
3297 err
= alc_auto_add_sw_ctl(codec
, "LFE", 0, sw
, 2);
3301 err
= alc_auto_add_stereo_vol(codec
, name
, index
, vol
);
3304 err
= alc_auto_add_stereo_sw(codec
, name
, index
, sw
);
3312 static int alc_auto_create_extra_out(struct hda_codec
*codec
, hda_nid_t pin
,
3313 hda_nid_t dac
, const char *pfx
,
3316 struct alc_spec
*spec
= codec
->spec
;
3322 /* the corresponding DAC is already occupied */
3323 if (!(get_wcaps(codec
, pin
) & AC_WCAP_OUT_AMP
))
3324 return 0; /* no way */
3325 /* create a switch only */
3326 val
= HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
);
3327 if (is_ctl_used(spec
->sw_ctls
, val
))
3328 return 0; /* already created */
3329 mark_ctl_usage(spec
->sw_ctls
, val
);
3330 return __add_pb_sw_ctrl(spec
, ALC_CTL_WIDGET_MUTE
, pfx
, cidx
, val
);
3333 sw
= alc_look_for_out_mute_nid(codec
, pin
, dac
);
3334 vol
= alc_look_for_out_vol_nid(codec
, pin
, dac
);
3335 err
= alc_auto_add_stereo_vol(codec
, pfx
, cidx
, vol
);
3338 err
= alc_auto_add_stereo_sw(codec
, pfx
, cidx
, sw
);
3344 static struct hda_bind_ctls
*new_bind_ctl(struct hda_codec
*codec
,
3346 struct hda_ctl_ops
*ops
)
3348 struct alc_spec
*spec
= codec
->spec
;
3349 struct hda_bind_ctls
**ctlp
, *ctl
;
3350 snd_array_init(&spec
->bind_ctls
, sizeof(ctl
), 8);
3351 ctlp
= snd_array_new(&spec
->bind_ctls
);
3354 ctl
= kzalloc(sizeof(*ctl
) + sizeof(long) * (nums
+ 1), GFP_KERNEL
);
3361 /* add playback controls for speaker and HP outputs */
3362 static int alc_auto_create_extra_outs(struct hda_codec
*codec
, int num_pins
,
3363 const hda_nid_t
*pins
,
3364 const hda_nid_t
*dacs
,
3367 struct alc_spec
*spec
= codec
->spec
;
3368 struct hda_bind_ctls
*ctl
;
3372 if (!num_pins
|| !pins
[0])
3375 if (num_pins
== 1) {
3376 hda_nid_t dac
= *dacs
;
3378 dac
= spec
->multiout
.dac_nids
[0];
3379 return alc_auto_create_extra_out(codec
, *pins
, dac
, pfx
, 0);
3382 if (dacs
[num_pins
- 1]) {
3383 /* OK, we have a multi-output system with individual volumes */
3384 for (i
= 0; i
< num_pins
; i
++) {
3385 if (num_pins
>= 3) {
3386 snprintf(name
, sizeof(name
), "%s %s",
3387 pfx
, channel_name
[i
]);
3388 err
= alc_auto_create_extra_out(codec
, pins
[i
], dacs
[i
],
3391 err
= alc_auto_create_extra_out(codec
, pins
[i
], dacs
[i
],
3400 /* Let's create a bind-controls */
3401 ctl
= new_bind_ctl(codec
, num_pins
, &snd_hda_bind_sw
);
3405 for (i
= 0; i
< num_pins
; i
++) {
3406 if (get_wcaps(codec
, pins
[i
]) & AC_WCAP_OUT_AMP
)
3408 HDA_COMPOSE_AMP_VAL(pins
[i
], 3, 0, HDA_OUTPUT
);
3411 snprintf(name
, sizeof(name
), "%s Playback Switch", pfx
);
3412 err
= add_control(spec
, ALC_CTL_BIND_SW
, name
, 0, (long)ctl
);
3417 ctl
= new_bind_ctl(codec
, num_pins
, &snd_hda_bind_vol
);
3421 for (i
= 0; i
< num_pins
; i
++) {
3423 if (!pins
[i
] || !dacs
[i
])
3425 vol
= alc_look_for_out_vol_nid(codec
, pins
[i
], dacs
[i
]);
3428 HDA_COMPOSE_AMP_VAL(vol
, 3, 0, HDA_OUTPUT
);
3431 snprintf(name
, sizeof(name
), "%s Playback Volume", pfx
);
3432 err
= add_control(spec
, ALC_CTL_BIND_VOL
, name
, 0, (long)ctl
);
3439 static int alc_auto_create_hp_out(struct hda_codec
*codec
)
3441 struct alc_spec
*spec
= codec
->spec
;
3442 return alc_auto_create_extra_outs(codec
, spec
->autocfg
.hp_outs
,
3443 spec
->autocfg
.hp_pins
,
3444 spec
->multiout
.hp_out_nid
,
3448 static int alc_auto_create_speaker_out(struct hda_codec
*codec
)
3450 struct alc_spec
*spec
= codec
->spec
;
3451 return alc_auto_create_extra_outs(codec
, spec
->autocfg
.speaker_outs
,
3452 spec
->autocfg
.speaker_pins
,
3453 spec
->multiout
.extra_out_nid
,
3457 static void alc_auto_set_output_and_unmute(struct hda_codec
*codec
,
3458 hda_nid_t pin
, int pin_type
,
3462 hda_nid_t nid
, mix
= 0;
3463 hda_nid_t srcs
[HDA_MAX_CONNECTIONS
];
3465 alc_set_pin_output(codec
, pin
, pin_type
);
3466 nid
= alc_go_down_to_selector(codec
, pin
);
3467 num
= snd_hda_get_connections(codec
, nid
, srcs
, ARRAY_SIZE(srcs
));
3468 for (i
= 0; i
< num
; i
++) {
3469 if (alc_auto_mix_to_dac(codec
, srcs
[i
]) != dac
)
3477 /* need the manual connection? */
3479 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_CONNECT_SEL
, i
);
3480 /* unmute mixer widget inputs */
3481 if (nid_has_mute(codec
, mix
, HDA_INPUT
)) {
3482 snd_hda_codec_write(codec
, mix
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
3484 snd_hda_codec_write(codec
, mix
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
3487 /* initialize volume */
3488 nid
= alc_look_for_out_vol_nid(codec
, pin
, dac
);
3490 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
3493 /* unmute DAC if it's not assigned to a mixer */
3494 nid
= alc_look_for_out_mute_nid(codec
, pin
, dac
);
3495 if (nid
== mix
&& nid_has_mute(codec
, dac
, HDA_OUTPUT
))
3496 snd_hda_codec_write(codec
, dac
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
3500 static void alc_auto_init_multi_out(struct hda_codec
*codec
)
3502 struct alc_spec
*spec
= codec
->spec
;
3503 int pin_type
= get_pin_type(spec
->autocfg
.line_out_type
);
3506 for (i
= 0; i
<= HDA_SIDE
; i
++) {
3507 hda_nid_t nid
= spec
->autocfg
.line_out_pins
[i
];
3509 alc_auto_set_output_and_unmute(codec
, nid
, pin_type
,
3510 spec
->multiout
.dac_nids
[i
]);
3514 static void alc_auto_init_extra_out(struct hda_codec
*codec
)
3516 struct alc_spec
*spec
= codec
->spec
;
3520 for (i
= 0; i
< spec
->autocfg
.hp_outs
; i
++) {
3521 if (spec
->autocfg
.line_out_type
== AUTO_PIN_HP_OUT
)
3523 pin
= spec
->autocfg
.hp_pins
[i
];
3526 dac
= spec
->multiout
.hp_out_nid
[i
];
3528 if (i
> 0 && spec
->multiout
.hp_out_nid
[0])
3529 dac
= spec
->multiout
.hp_out_nid
[0];
3531 dac
= spec
->multiout
.dac_nids
[0];
3533 alc_auto_set_output_and_unmute(codec
, pin
, PIN_HP
, dac
);
3535 for (i
= 0; i
< spec
->autocfg
.speaker_outs
; i
++) {
3536 if (spec
->autocfg
.line_out_type
== AUTO_PIN_SPEAKER_OUT
)
3538 pin
= spec
->autocfg
.speaker_pins
[i
];
3541 dac
= spec
->multiout
.extra_out_nid
[i
];
3543 if (i
> 0 && spec
->multiout
.extra_out_nid
[0])
3544 dac
= spec
->multiout
.extra_out_nid
[0];
3546 dac
= spec
->multiout
.dac_nids
[0];
3548 alc_auto_set_output_and_unmute(codec
, pin
, PIN_OUT
, dac
);
3555 static int alc_auto_fill_multi_ios(struct hda_codec
*codec
,
3556 unsigned int location
,
3559 struct alc_spec
*spec
= codec
->spec
;
3560 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
3561 hda_nid_t prime_dac
= spec
->private_dac_nids
[0];
3562 int type
, i
, dacs
, num_pins
= 0;
3564 dacs
= spec
->multiout
.num_dacs
;
3565 for (type
= AUTO_PIN_LINE_IN
; type
>= AUTO_PIN_MIC
; type
--) {
3566 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
3567 hda_nid_t nid
= cfg
->inputs
[i
].pin
;
3569 unsigned int defcfg
, caps
;
3570 if (cfg
->inputs
[i
].type
!= type
)
3572 defcfg
= snd_hda_codec_get_pincfg(codec
, nid
);
3573 if (get_defcfg_connect(defcfg
) != AC_JACK_PORT_COMPLEX
)
3575 if (location
&& get_defcfg_location(defcfg
) != location
)
3577 caps
= snd_hda_query_pin_caps(codec
, nid
);
3578 if (!(caps
& AC_PINCAP_OUT
))
3580 if (offset
&& offset
+ num_pins
< dacs
) {
3581 dac
= spec
->private_dac_nids
[offset
+ num_pins
];
3582 if (!alc_auto_is_dac_reachable(codec
, nid
, dac
))
3586 dac
= alc_auto_look_for_dac(codec
, nid
);
3589 spec
->multi_io
[num_pins
].pin
= nid
;
3590 spec
->multi_io
[num_pins
].dac
= dac
;
3592 spec
->private_dac_nids
[spec
->multiout
.num_dacs
++] = dac
;
3595 spec
->multiout
.num_dacs
= dacs
;
3597 /* clear up again */
3598 memset(spec
->private_dac_nids
+ dacs
, 0,
3599 sizeof(hda_nid_t
) * (AUTO_CFG_MAX_OUTS
- dacs
));
3600 spec
->private_dac_nids
[0] = prime_dac
;
3606 static int alc_auto_ch_mode_info(struct snd_kcontrol
*kcontrol
,
3607 struct snd_ctl_elem_info
*uinfo
)
3609 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3610 struct alc_spec
*spec
= codec
->spec
;
3612 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
3614 uinfo
->value
.enumerated
.items
= spec
->multi_ios
+ 1;
3615 if (uinfo
->value
.enumerated
.item
> spec
->multi_ios
)
3616 uinfo
->value
.enumerated
.item
= spec
->multi_ios
;
3617 sprintf(uinfo
->value
.enumerated
.name
, "%dch",
3618 (uinfo
->value
.enumerated
.item
+ 1) * 2);
3622 static int alc_auto_ch_mode_get(struct snd_kcontrol
*kcontrol
,
3623 struct snd_ctl_elem_value
*ucontrol
)
3625 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3626 struct alc_spec
*spec
= codec
->spec
;
3627 ucontrol
->value
.enumerated
.item
[0] = (spec
->ext_channel_count
- 1) / 2;
3631 static int alc_set_multi_io(struct hda_codec
*codec
, int idx
, bool output
)
3633 struct alc_spec
*spec
= codec
->spec
;
3634 hda_nid_t nid
= spec
->multi_io
[idx
].pin
;
3636 if (!spec
->multi_io
[idx
].ctl_in
)
3637 spec
->multi_io
[idx
].ctl_in
=
3638 snd_hda_codec_read(codec
, nid
, 0,
3639 AC_VERB_GET_PIN_WIDGET_CONTROL
, 0);
3641 snd_hda_codec_update_cache(codec
, nid
, 0,
3642 AC_VERB_SET_PIN_WIDGET_CONTROL
,
3644 if (get_wcaps(codec
, nid
) & AC_WCAP_OUT_AMP
)
3645 snd_hda_codec_amp_stereo(codec
, nid
, HDA_OUTPUT
, 0,
3647 alc_auto_select_dac(codec
, nid
, spec
->multi_io
[idx
].dac
);
3649 if (get_wcaps(codec
, nid
) & AC_WCAP_OUT_AMP
)
3650 snd_hda_codec_amp_stereo(codec
, nid
, HDA_OUTPUT
, 0,
3651 HDA_AMP_MUTE
, HDA_AMP_MUTE
);
3652 snd_hda_codec_update_cache(codec
, nid
, 0,
3653 AC_VERB_SET_PIN_WIDGET_CONTROL
,
3654 spec
->multi_io
[idx
].ctl_in
);
3659 static int alc_auto_ch_mode_put(struct snd_kcontrol
*kcontrol
,
3660 struct snd_ctl_elem_value
*ucontrol
)
3662 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3663 struct alc_spec
*spec
= codec
->spec
;
3666 ch
= ucontrol
->value
.enumerated
.item
[0];
3667 if (ch
< 0 || ch
> spec
->multi_ios
)
3669 if (ch
== (spec
->ext_channel_count
- 1) / 2)
3671 spec
->ext_channel_count
= (ch
+ 1) * 2;
3672 for (i
= 0; i
< spec
->multi_ios
; i
++)
3673 alc_set_multi_io(codec
, i
, i
< ch
);
3674 spec
->multiout
.max_channels
= spec
->ext_channel_count
;
3675 if (spec
->need_dac_fix
&& !spec
->const_channel_count
)
3676 spec
->multiout
.num_dacs
= spec
->multiout
.max_channels
/ 2;
3680 static const struct snd_kcontrol_new alc_auto_channel_mode_enum
= {
3681 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
3682 .name
= "Channel Mode",
3683 .info
= alc_auto_ch_mode_info
,
3684 .get
= alc_auto_ch_mode_get
,
3685 .put
= alc_auto_ch_mode_put
,
3688 static int alc_auto_add_multi_channel_mode(struct hda_codec
*codec
)
3690 struct alc_spec
*spec
= codec
->spec
;
3692 if (spec
->multi_ios
> 0) {
3693 struct snd_kcontrol_new
*knew
;
3695 knew
= alc_kcontrol_new(spec
);
3698 *knew
= alc_auto_channel_mode_enum
;
3699 knew
->name
= kstrdup("Channel Mode", GFP_KERNEL
);
3706 /* filter out invalid adc_nids (and capsrc_nids) that don't give all
3709 static void alc_remove_invalid_adc_nids(struct hda_codec
*codec
)
3711 struct alc_spec
*spec
= codec
->spec
;
3712 const struct hda_input_mux
*imux
;
3713 hda_nid_t adc_nids
[ARRAY_SIZE(spec
->private_adc_nids
)];
3714 hda_nid_t capsrc_nids
[ARRAY_SIZE(spec
->private_adc_nids
)];
3717 imux
= spec
->input_mux
;
3720 if (spec
->dyn_adc_switch
)
3725 for (n
= 0; n
< spec
->num_adc_nids
; n
++) {
3726 hda_nid_t cap
= spec
->private_capsrc_nids
[n
];
3727 int num_conns
= snd_hda_get_conn_list(codec
, cap
, NULL
);
3728 for (i
= 0; i
< imux
->num_items
; i
++) {
3729 hda_nid_t pin
= spec
->imux_pins
[i
];
3731 if (get_connection_index(codec
, cap
, pin
) < 0)
3733 } else if (num_conns
<= imux
->items
[i
].index
)
3736 if (i
>= imux
->num_items
) {
3737 adc_nids
[nums
] = spec
->private_adc_nids
[n
];
3738 capsrc_nids
[nums
++] = cap
;
3742 /* check whether ADC-switch is possible */
3743 if (!alc_check_dyn_adc_switch(codec
)) {
3744 if (spec
->shared_mic_hp
) {
3745 spec
->shared_mic_hp
= 0;
3746 spec
->private_imux
[0].num_items
= 1;
3749 printk(KERN_WARNING
"hda_codec: %s: no valid ADC found;"
3750 " using fallback 0x%x\n",
3751 codec
->chip_name
, spec
->private_adc_nids
[0]);
3752 spec
->num_adc_nids
= 1;
3756 } else if (nums
!= spec
->num_adc_nids
) {
3757 memcpy(spec
->private_adc_nids
, adc_nids
,
3758 nums
* sizeof(hda_nid_t
));
3759 memcpy(spec
->private_capsrc_nids
, capsrc_nids
,
3760 nums
* sizeof(hda_nid_t
));
3761 spec
->num_adc_nids
= nums
;
3765 alc_auto_mic_check_imux(codec
); /* check auto-mic setups */
3766 else if (spec
->input_mux
->num_items
== 1 || spec
->shared_mic_hp
)
3767 spec
->num_adc_nids
= 1; /* reduce to a single ADC */
3771 * initialize ADC paths
3773 static void alc_auto_init_adc(struct hda_codec
*codec
, int adc_idx
)
3775 struct alc_spec
*spec
= codec
->spec
;
3778 nid
= spec
->adc_nids
[adc_idx
];
3780 if (nid_has_mute(codec
, nid
, HDA_INPUT
)) {
3781 snd_hda_codec_write(codec
, nid
, 0,
3782 AC_VERB_SET_AMP_GAIN_MUTE
,
3786 if (!spec
->capsrc_nids
)
3788 nid
= spec
->capsrc_nids
[adc_idx
];
3789 if (nid_has_mute(codec
, nid
, HDA_OUTPUT
))
3790 snd_hda_codec_write(codec
, nid
, 0,
3791 AC_VERB_SET_AMP_GAIN_MUTE
,
3795 static void alc_auto_init_input_src(struct hda_codec
*codec
)
3797 struct alc_spec
*spec
= codec
->spec
;
3800 for (c
= 0; c
< spec
->num_adc_nids
; c
++)
3801 alc_auto_init_adc(codec
, c
);
3802 if (spec
->dyn_adc_switch
)
3805 nums
= spec
->num_adc_nids
;
3806 for (c
= 0; c
< nums
; c
++)
3807 alc_mux_select(codec
, c
, spec
->cur_mux
[c
], true);
3810 /* add mic boosts if needed */
3811 static int alc_auto_add_mic_boost(struct hda_codec
*codec
)
3813 struct alc_spec
*spec
= codec
->spec
;
3814 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
3818 const char *prev_label
= NULL
;
3820 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
3821 if (cfg
->inputs
[i
].type
> AUTO_PIN_MIC
)
3823 nid
= cfg
->inputs
[i
].pin
;
3824 if (get_wcaps(codec
, nid
) & AC_WCAP_IN_AMP
) {
3826 char boost_label
[32];
3828 label
= hda_get_autocfg_input_label(codec
, cfg
, i
);
3829 if (spec
->shared_mic_hp
&& !strcmp(label
, "Misc"))
3830 label
= "Headphone Mic";
3831 if (prev_label
&& !strcmp(label
, prev_label
))
3837 snprintf(boost_label
, sizeof(boost_label
),
3838 "%s Boost Volume", label
);
3839 err
= add_control(spec
, ALC_CTL_WIDGET_VOL
,
3840 boost_label
, type_idx
,
3841 HDA_COMPOSE_AMP_VAL(nid
, 3, 0, HDA_INPUT
));
3849 /* select or unmute the given capsrc route */
3850 static void select_or_unmute_capsrc(struct hda_codec
*codec
, hda_nid_t cap
,
3853 if (get_wcaps_type(get_wcaps(codec
, cap
)) == AC_WID_AUD_MIX
) {
3854 snd_hda_codec_amp_stereo(codec
, cap
, HDA_INPUT
, idx
,
3856 } else if (snd_hda_get_conn_list(codec
, cap
, NULL
) > 1) {
3857 snd_hda_codec_write_cache(codec
, cap
, 0,
3858 AC_VERB_SET_CONNECT_SEL
, idx
);
3862 /* set the default connection to that pin */
3863 static int init_capsrc_for_pin(struct hda_codec
*codec
, hda_nid_t pin
)
3865 struct alc_spec
*spec
= codec
->spec
;
3870 for (i
= 0; i
< spec
->num_adc_nids
; i
++) {
3871 hda_nid_t cap
= get_capsrc(spec
, i
);
3874 idx
= get_connection_index(codec
, cap
, pin
);
3877 select_or_unmute_capsrc(codec
, cap
, idx
);
3878 return i
; /* return the found index */
3880 return -1; /* not found */
3883 /* initialize some special cases for input sources */
3884 static void alc_init_special_input_src(struct hda_codec
*codec
)
3886 struct alc_spec
*spec
= codec
->spec
;
3889 for (i
= 0; i
< spec
->autocfg
.num_inputs
; i
++)
3890 init_capsrc_for_pin(codec
, spec
->autocfg
.inputs
[i
].pin
);
3893 /* assign appropriate capture mixers */
3894 static void set_capture_mixer(struct hda_codec
*codec
)
3896 struct alc_spec
*spec
= codec
->spec
;
3897 static const struct snd_kcontrol_new
*caps
[2][3] = {
3898 { alc_capture_mixer_nosrc1
,
3899 alc_capture_mixer_nosrc2
,
3900 alc_capture_mixer_nosrc3
},
3901 { alc_capture_mixer1
,
3903 alc_capture_mixer3
},
3906 /* check whether either of ADC or MUX has a volume control */
3907 if (!nid_has_volume(codec
, spec
->adc_nids
[0], HDA_INPUT
)) {
3908 if (!spec
->capsrc_nids
)
3909 return; /* no volume */
3910 if (!nid_has_volume(codec
, spec
->capsrc_nids
[0], HDA_OUTPUT
))
3911 return; /* no volume in capsrc, too */
3912 spec
->vol_in_capsrc
= 1;
3915 if (spec
->num_adc_nids
> 0) {
3919 if (spec
->input_mux
&& spec
->input_mux
->num_items
> 1)
3921 if (spec
->auto_mic
) {
3924 } else if (spec
->dyn_adc_switch
)
3927 if (spec
->num_adc_nids
> 3)
3928 spec
->num_adc_nids
= 3;
3929 else if (!spec
->num_adc_nids
)
3931 num_adcs
= spec
->num_adc_nids
;
3933 spec
->cap_mixer
= caps
[mux
][num_adcs
- 1];
3938 * standard auto-parser initializations
3940 static void alc_auto_init_std(struct hda_codec
*codec
)
3942 struct alc_spec
*spec
= codec
->spec
;
3943 alc_auto_init_multi_out(codec
);
3944 alc_auto_init_extra_out(codec
);
3945 alc_auto_init_analog_input(codec
);
3946 alc_auto_init_input_src(codec
);
3947 alc_auto_init_digital(codec
);
3948 if (spec
->unsol_event
)
3949 alc_inithook(codec
);
3953 * Digital-beep handlers
3955 #ifdef CONFIG_SND_HDA_INPUT_BEEP
3956 #define set_beep_amp(spec, nid, idx, dir) \
3957 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
3959 static const struct snd_pci_quirk beep_white_list
[] = {
3960 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
3961 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
3962 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
3963 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
3964 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
3968 static inline int has_cdefine_beep(struct hda_codec
*codec
)
3970 struct alc_spec
*spec
= codec
->spec
;
3971 const struct snd_pci_quirk
*q
;
3972 q
= snd_pci_quirk_lookup(codec
->bus
->pci
, beep_white_list
);
3975 return spec
->cdefine
.enable_pcbeep
;
3978 #define set_beep_amp(spec, nid, idx, dir) /* NOP */
3979 #define has_cdefine_beep(codec) 0
3982 /* parse the BIOS configuration and set up the alc_spec */
3983 /* return 1 if successful, 0 if the proper config is not found,
3984 * or a negative error code
3986 static int alc_parse_auto_config(struct hda_codec
*codec
,
3987 const hda_nid_t
*ignore_nids
,
3988 const hda_nid_t
*ssid_nids
)
3990 struct alc_spec
*spec
= codec
->spec
;
3991 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
3994 err
= snd_hda_parse_pin_defcfg(codec
, cfg
, ignore_nids
,
3998 if (!cfg
->line_outs
) {
3999 if (cfg
->dig_outs
|| cfg
->dig_in_pin
) {
4000 spec
->multiout
.max_channels
= 2;
4001 spec
->no_analog
= 1;
4004 return 0; /* can't find valid BIOS pin config */
4007 if (cfg
->line_out_type
== AUTO_PIN_SPEAKER_OUT
&&
4008 cfg
->line_outs
<= cfg
->hp_outs
) {
4009 /* use HP as primary out */
4010 cfg
->speaker_outs
= cfg
->line_outs
;
4011 memcpy(cfg
->speaker_pins
, cfg
->line_out_pins
,
4012 sizeof(cfg
->speaker_pins
));
4013 cfg
->line_outs
= cfg
->hp_outs
;
4014 memcpy(cfg
->line_out_pins
, cfg
->hp_pins
, sizeof(cfg
->hp_pins
));
4016 memset(cfg
->hp_pins
, 0, sizeof(cfg
->hp_pins
));
4017 cfg
->line_out_type
= AUTO_PIN_HP_OUT
;
4020 err
= alc_auto_fill_dac_nids(codec
);
4023 err
= alc_auto_add_multi_channel_mode(codec
);
4026 err
= alc_auto_create_multi_out_ctls(codec
, cfg
);
4029 err
= alc_auto_create_hp_out(codec
);
4032 err
= alc_auto_create_speaker_out(codec
);
4035 err
= alc_auto_create_shared_input(codec
);
4038 err
= alc_auto_create_input_ctls(codec
);
4042 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
4045 alc_auto_parse_digital(codec
);
4047 if (!spec
->no_analog
)
4048 alc_remove_invalid_adc_nids(codec
);
4051 alc_ssid_check(codec
, ssid_nids
);
4053 if (!spec
->no_analog
) {
4054 alc_auto_check_switches(codec
);
4055 err
= alc_auto_add_mic_boost(codec
);
4060 if (spec
->kctls
.list
)
4061 add_mixer(spec
, spec
->kctls
.list
);
4066 static int alc880_parse_auto_config(struct hda_codec
*codec
)
4068 static const hda_nid_t alc880_ignore
[] = { 0x1d, 0 };
4069 static const hda_nid_t alc880_ssids
[] = { 0x15, 0x1b, 0x14, 0 };
4070 return alc_parse_auto_config(codec
, alc880_ignore
, alc880_ssids
);
4073 #ifdef CONFIG_SND_HDA_POWER_SAVE
4074 static const struct hda_amp_list alc880_loopbacks
[] = {
4075 { 0x0b, HDA_INPUT
, 0 },
4076 { 0x0b, HDA_INPUT
, 1 },
4077 { 0x0b, HDA_INPUT
, 2 },
4078 { 0x0b, HDA_INPUT
, 3 },
4079 { 0x0b, HDA_INPUT
, 4 },
4089 ALC880_FIXUP_MEDION_RIM
,
4092 static const struct alc_fixup alc880_fixups
[] = {
4093 [ALC880_FIXUP_GPIO2
] = {
4094 .type
= ALC_FIXUP_VERBS
,
4095 .v
.verbs
= alc_gpio2_init_verbs
,
4097 [ALC880_FIXUP_MEDION_RIM
] = {
4098 .type
= ALC_FIXUP_VERBS
,
4099 .v
.verbs
= (const struct hda_verb
[]) {
4100 { 0x20, AC_VERB_SET_COEF_INDEX
, 0x07 },
4101 { 0x20, AC_VERB_SET_PROC_COEF
, 0x3060 },
4105 .chain_id
= ALC880_FIXUP_GPIO2
,
4109 static const struct snd_pci_quirk alc880_fixup_tbl
[] = {
4110 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM
),
4118 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4119 #define alc_board_config \
4120 snd_hda_check_board_config
4121 #define alc_board_codec_sid_config \
4122 snd_hda_check_board_codec_sid_config
4123 #include "alc_quirks.c"
4125 #define alc_board_config(codec, nums, models, tbl) -1
4126 #define alc_board_codec_sid_config(codec, nums, models, tbl) -1
4127 #define setup_preset(codec, x) /* NOP */
4131 * OK, here we have finally the patch for ALC880
4133 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4134 #include "alc880_quirks.c"
4137 static int patch_alc880(struct hda_codec
*codec
)
4139 struct alc_spec
*spec
;
4143 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
4149 spec
->mixer_nid
= 0x0b;
4150 spec
->need_dac_fix
= 1;
4152 board_config
= alc_board_config(codec
, ALC880_MODEL_LAST
,
4153 alc880_models
, alc880_cfg_tbl
);
4154 if (board_config
< 0) {
4155 printk(KERN_INFO
"hda_codec: %s: BIOS auto-probing.\n",
4157 board_config
= ALC_MODEL_AUTO
;
4160 if (board_config
== ALC_MODEL_AUTO
) {
4161 alc_pick_fixup(codec
, NULL
, alc880_fixup_tbl
, alc880_fixups
);
4162 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
4165 if (board_config
== ALC_MODEL_AUTO
) {
4166 /* automatic parse from the BIOS config */
4167 err
= alc880_parse_auto_config(codec
);
4170 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4173 "hda_codec: Cannot set up configuration "
4174 "from BIOS. Using 3-stack mode...\n");
4175 board_config
= ALC880_3ST
;
4180 if (board_config
!= ALC_MODEL_AUTO
) {
4181 spec
->vmaster_nid
= 0x0c;
4182 setup_preset(codec
, &alc880_presets
[board_config
]);
4185 if (!spec
->no_analog
&& !spec
->adc_nids
) {
4186 alc_auto_fill_adc_caps(codec
);
4187 alc_rebuild_imux_for_auto_mic(codec
);
4188 alc_remove_invalid_adc_nids(codec
);
4191 if (!spec
->no_analog
&& !spec
->cap_mixer
)
4192 set_capture_mixer(codec
);
4194 if (!spec
->no_analog
) {
4195 err
= snd_hda_attach_beep_device(codec
, 0x1);
4198 set_beep_amp(spec
, 0x0b, 0x05, HDA_INPUT
);
4201 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
4203 codec
->patch_ops
= alc_patch_ops
;
4204 if (board_config
== ALC_MODEL_AUTO
)
4205 spec
->init_hook
= alc_auto_init_std
;
4207 codec
->patch_ops
.build_controls
= __alc_build_controls
;
4208 #ifdef CONFIG_SND_HDA_POWER_SAVE
4209 if (!spec
->loopback
.amplist
)
4210 spec
->loopback
.amplist
= alc880_loopbacks
;
4224 static int alc260_parse_auto_config(struct hda_codec
*codec
)
4226 static const hda_nid_t alc260_ignore
[] = { 0x17, 0 };
4227 static const hda_nid_t alc260_ssids
[] = { 0x10, 0x15, 0x0f, 0 };
4228 return alc_parse_auto_config(codec
, alc260_ignore
, alc260_ssids
);
4231 #ifdef CONFIG_SND_HDA_POWER_SAVE
4232 static const struct hda_amp_list alc260_loopbacks
[] = {
4233 { 0x07, HDA_INPUT
, 0 },
4234 { 0x07, HDA_INPUT
, 1 },
4235 { 0x07, HDA_INPUT
, 2 },
4236 { 0x07, HDA_INPUT
, 3 },
4237 { 0x07, HDA_INPUT
, 4 },
4249 static const struct alc_fixup alc260_fixups
[] = {
4250 [PINFIX_HP_DC5750
] = {
4251 .type
= ALC_FIXUP_PINS
,
4252 .v
.pins
= (const struct alc_pincfg
[]) {
4253 { 0x11, 0x90130110 }, /* speaker */
4259 static const struct snd_pci_quirk alc260_fixup_tbl
[] = {
4260 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", PINFIX_HP_DC5750
),
4266 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4267 #include "alc260_quirks.c"
4270 static int patch_alc260(struct hda_codec
*codec
)
4272 struct alc_spec
*spec
;
4273 int err
, board_config
;
4275 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
4281 spec
->mixer_nid
= 0x07;
4283 board_config
= alc_board_config(codec
, ALC260_MODEL_LAST
,
4284 alc260_models
, alc260_cfg_tbl
);
4285 if (board_config
< 0) {
4286 snd_printd(KERN_INFO
"hda_codec: %s: BIOS auto-probing.\n",
4288 board_config
= ALC_MODEL_AUTO
;
4291 if (board_config
== ALC_MODEL_AUTO
) {
4292 alc_pick_fixup(codec
, NULL
, alc260_fixup_tbl
, alc260_fixups
);
4293 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
4296 if (board_config
== ALC_MODEL_AUTO
) {
4297 /* automatic parse from the BIOS config */
4298 err
= alc260_parse_auto_config(codec
);
4301 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4304 "hda_codec: Cannot set up configuration "
4305 "from BIOS. Using base mode...\n");
4306 board_config
= ALC260_BASIC
;
4311 if (board_config
!= ALC_MODEL_AUTO
) {
4312 setup_preset(codec
, &alc260_presets
[board_config
]);
4313 spec
->vmaster_nid
= 0x08;
4316 if (!spec
->no_analog
&& !spec
->adc_nids
) {
4317 alc_auto_fill_adc_caps(codec
);
4318 alc_rebuild_imux_for_auto_mic(codec
);
4319 alc_remove_invalid_adc_nids(codec
);
4322 if (!spec
->no_analog
&& !spec
->cap_mixer
)
4323 set_capture_mixer(codec
);
4325 if (!spec
->no_analog
) {
4326 err
= snd_hda_attach_beep_device(codec
, 0x1);
4329 set_beep_amp(spec
, 0x07, 0x05, HDA_INPUT
);
4332 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
4334 codec
->patch_ops
= alc_patch_ops
;
4335 if (board_config
== ALC_MODEL_AUTO
)
4336 spec
->init_hook
= alc_auto_init_std
;
4338 codec
->patch_ops
.build_controls
= __alc_build_controls
;
4339 spec
->shutup
= alc_eapd_shutup
;
4340 #ifdef CONFIG_SND_HDA_POWER_SAVE
4341 if (!spec
->loopback
.amplist
)
4342 spec
->loopback
.amplist
= alc260_loopbacks
;
4354 * ALC882/883/885/888/889 support
4356 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
4357 * configuration. Each pin widget can choose any input DACs and a mixer.
4358 * Each ADC is connected from a mixer of all inputs. This makes possible
4359 * 6-channel independent captures.
4361 * In addition, an independent DAC for the multi-playback (not used in this
4364 #ifdef CONFIG_SND_HDA_POWER_SAVE
4365 #define alc882_loopbacks alc880_loopbacks
4372 ALC882_FIXUP_ABIT_AW9D_MAX
,
4373 ALC882_FIXUP_LENOVO_Y530
,
4374 ALC882_FIXUP_PB_M5210
,
4375 ALC882_FIXUP_ACER_ASPIRE_7736
,
4376 ALC882_FIXUP_ASUS_W90V
,
4378 ALC889_FIXUP_VAIO_TT
,
4379 ALC888_FIXUP_EEE1601
,
4382 ALC883_FIXUP_ACER_EAPD
,
4385 ALC882_FIXUP_ASUS_W2JC
,
4386 ALC882_FIXUP_ACER_ASPIRE_4930G
,
4387 ALC882_FIXUP_ACER_ASPIRE_8930G
,
4388 ALC882_FIXUP_ASPIRE_8930G_VERBS
,
4389 ALC885_FIXUP_MACPRO_GPIO
,
4390 ALC889_FIXUP_DAC_ROUTE
,
4393 static void alc889_fixup_coef(struct hda_codec
*codec
,
4394 const struct alc_fixup
*fix
, int action
)
4396 if (action
!= ALC_FIXUP_ACT_INIT
)
4398 alc889_coef_init(codec
);
4401 /* toggle speaker-output according to the hp-jack state */
4402 static void alc882_gpio_mute(struct hda_codec
*codec
, int pin
, int muted
)
4404 unsigned int gpiostate
, gpiomask
, gpiodir
;
4406 gpiostate
= snd_hda_codec_read(codec
, codec
->afg
, 0,
4407 AC_VERB_GET_GPIO_DATA
, 0);
4410 gpiostate
|= (1 << pin
);
4412 gpiostate
&= ~(1 << pin
);
4414 gpiomask
= snd_hda_codec_read(codec
, codec
->afg
, 0,
4415 AC_VERB_GET_GPIO_MASK
, 0);
4416 gpiomask
|= (1 << pin
);
4418 gpiodir
= snd_hda_codec_read(codec
, codec
->afg
, 0,
4419 AC_VERB_GET_GPIO_DIRECTION
, 0);
4420 gpiodir
|= (1 << pin
);
4423 snd_hda_codec_write(codec
, codec
->afg
, 0,
4424 AC_VERB_SET_GPIO_MASK
, gpiomask
);
4425 snd_hda_codec_write(codec
, codec
->afg
, 0,
4426 AC_VERB_SET_GPIO_DIRECTION
, gpiodir
);
4430 snd_hda_codec_write(codec
, codec
->afg
, 0,
4431 AC_VERB_SET_GPIO_DATA
, gpiostate
);
4434 /* set up GPIO at initialization */
4435 static void alc885_fixup_macpro_gpio(struct hda_codec
*codec
,
4436 const struct alc_fixup
*fix
, int action
)
4438 if (action
!= ALC_FIXUP_ACT_INIT
)
4440 alc882_gpio_mute(codec
, 0, 0);
4441 alc882_gpio_mute(codec
, 1, 0);
4444 /* Fix the connection of some pins for ALC889:
4445 * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
4446 * work correctly (bko#42740)
4448 static void alc889_fixup_dac_route(struct hda_codec
*codec
,
4449 const struct alc_fixup
*fix
, int action
)
4451 if (action
== ALC_FIXUP_ACT_PRE_PROBE
) {
4452 /* fake the connections during parsing the tree */
4453 hda_nid_t conn1
[2] = { 0x0c, 0x0d };
4454 hda_nid_t conn2
[2] = { 0x0e, 0x0f };
4455 snd_hda_override_conn_list(codec
, 0x14, 2, conn1
);
4456 snd_hda_override_conn_list(codec
, 0x15, 2, conn1
);
4457 snd_hda_override_conn_list(codec
, 0x18, 2, conn2
);
4458 snd_hda_override_conn_list(codec
, 0x1a, 2, conn2
);
4459 } else if (action
== ALC_FIXUP_ACT_PROBE
) {
4460 /* restore the connections */
4461 hda_nid_t conn
[5] = { 0x0c, 0x0d, 0x0e, 0x0f, 0x26 };
4462 snd_hda_override_conn_list(codec
, 0x14, 5, conn
);
4463 snd_hda_override_conn_list(codec
, 0x15, 5, conn
);
4464 snd_hda_override_conn_list(codec
, 0x18, 5, conn
);
4465 snd_hda_override_conn_list(codec
, 0x1a, 5, conn
);
4469 static const struct alc_fixup alc882_fixups
[] = {
4470 [ALC882_FIXUP_ABIT_AW9D_MAX
] = {
4471 .type
= ALC_FIXUP_PINS
,
4472 .v
.pins
= (const struct alc_pincfg
[]) {
4473 { 0x15, 0x01080104 }, /* side */
4474 { 0x16, 0x01011012 }, /* rear */
4475 { 0x17, 0x01016011 }, /* clfe */
4479 [ALC882_FIXUP_LENOVO_Y530
] = {
4480 .type
= ALC_FIXUP_PINS
,
4481 .v
.pins
= (const struct alc_pincfg
[]) {
4482 { 0x15, 0x99130112 }, /* rear int speakers */
4483 { 0x16, 0x99130111 }, /* subwoofer */
4487 [ALC882_FIXUP_PB_M5210
] = {
4488 .type
= ALC_FIXUP_VERBS
,
4489 .v
.verbs
= (const struct hda_verb
[]) {
4490 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_VREF50
},
4494 [ALC882_FIXUP_ACER_ASPIRE_7736
] = {
4495 .type
= ALC_FIXUP_SKU
,
4496 .v
.sku
= ALC_FIXUP_SKU_IGNORE
,
4498 [ALC882_FIXUP_ASUS_W90V
] = {
4499 .type
= ALC_FIXUP_PINS
,
4500 .v
.pins
= (const struct alc_pincfg
[]) {
4501 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
4505 [ALC889_FIXUP_CD
] = {
4506 .type
= ALC_FIXUP_PINS
,
4507 .v
.pins
= (const struct alc_pincfg
[]) {
4508 { 0x1c, 0x993301f0 }, /* CD */
4512 [ALC889_FIXUP_VAIO_TT
] = {
4513 .type
= ALC_FIXUP_PINS
,
4514 .v
.pins
= (const struct alc_pincfg
[]) {
4515 { 0x17, 0x90170111 }, /* hidden surround speaker */
4519 [ALC888_FIXUP_EEE1601
] = {
4520 .type
= ALC_FIXUP_VERBS
,
4521 .v
.verbs
= (const struct hda_verb
[]) {
4522 { 0x20, AC_VERB_SET_COEF_INDEX
, 0x0b },
4523 { 0x20, AC_VERB_SET_PROC_COEF
, 0x0838 },
4527 [ALC882_FIXUP_EAPD
] = {
4528 .type
= ALC_FIXUP_VERBS
,
4529 .v
.verbs
= (const struct hda_verb
[]) {
4530 /* change to EAPD mode */
4531 { 0x20, AC_VERB_SET_COEF_INDEX
, 0x07 },
4532 { 0x20, AC_VERB_SET_PROC_COEF
, 0x3060 },
4536 [ALC883_FIXUP_EAPD
] = {
4537 .type
= ALC_FIXUP_VERBS
,
4538 .v
.verbs
= (const struct hda_verb
[]) {
4539 /* change to EAPD mode */
4540 { 0x20, AC_VERB_SET_COEF_INDEX
, 0x07 },
4541 { 0x20, AC_VERB_SET_PROC_COEF
, 0x3070 },
4545 [ALC883_FIXUP_ACER_EAPD
] = {
4546 .type
= ALC_FIXUP_VERBS
,
4547 .v
.verbs
= (const struct hda_verb
[]) {
4548 /* eanable EAPD on Acer laptops */
4549 { 0x20, AC_VERB_SET_COEF_INDEX
, 0x07 },
4550 { 0x20, AC_VERB_SET_PROC_COEF
, 0x3050 },
4554 [ALC882_FIXUP_GPIO3
] = {
4555 .type
= ALC_FIXUP_VERBS
,
4556 .v
.verbs
= alc_gpio3_init_verbs
,
4558 [ALC882_FIXUP_ASUS_W2JC
] = {
4559 .type
= ALC_FIXUP_VERBS
,
4560 .v
.verbs
= alc_gpio1_init_verbs
,
4562 .chain_id
= ALC882_FIXUP_EAPD
,
4564 [ALC889_FIXUP_COEF
] = {
4565 .type
= ALC_FIXUP_FUNC
,
4566 .v
.func
= alc889_fixup_coef
,
4568 [ALC882_FIXUP_ACER_ASPIRE_4930G
] = {
4569 .type
= ALC_FIXUP_PINS
,
4570 .v
.pins
= (const struct alc_pincfg
[]) {
4571 { 0x16, 0x99130111 }, /* CLFE speaker */
4572 { 0x17, 0x99130112 }, /* surround speaker */
4576 [ALC882_FIXUP_ACER_ASPIRE_8930G
] = {
4577 .type
= ALC_FIXUP_PINS
,
4578 .v
.pins
= (const struct alc_pincfg
[]) {
4579 { 0x16, 0x99130111 }, /* CLFE speaker */
4580 { 0x1b, 0x99130112 }, /* surround speaker */
4584 .chain_id
= ALC882_FIXUP_ASPIRE_8930G_VERBS
,
4586 [ALC882_FIXUP_ASPIRE_8930G_VERBS
] = {
4587 /* additional init verbs for Acer Aspire 8930G */
4588 .type
= ALC_FIXUP_VERBS
,
4589 .v
.verbs
= (const struct hda_verb
[]) {
4590 /* Enable all DACs */
4591 /* DAC DISABLE/MUTE 1? */
4592 /* setting bits 1-5 disables DAC nids 0x02-0x06
4593 * apparently. Init=0x38 */
4594 { 0x20, AC_VERB_SET_COEF_INDEX
, 0x03 },
4595 { 0x20, AC_VERB_SET_PROC_COEF
, 0x0000 },
4596 /* DAC DISABLE/MUTE 2? */
4597 /* some bit here disables the other DACs.
4599 { 0x20, AC_VERB_SET_COEF_INDEX
, 0x08 },
4600 { 0x20, AC_VERB_SET_PROC_COEF
, 0x0000 },
4602 * This laptop has a stereo digital microphone.
4603 * The mics are only 1cm apart which makes the stereo
4604 * useless. However, either the mic or the ALC889
4605 * makes the signal become a difference/sum signal
4606 * instead of standard stereo, which is annoying.
4607 * So instead we flip this bit which makes the
4608 * codec replicate the sum signal to both channels,
4609 * turning it into a normal mono mic.
4611 /* DMIC_CONTROL? Init value = 0x0001 */
4612 { 0x20, AC_VERB_SET_COEF_INDEX
, 0x0b },
4613 { 0x20, AC_VERB_SET_PROC_COEF
, 0x0003 },
4614 { 0x20, AC_VERB_SET_COEF_INDEX
, 0x07 },
4615 { 0x20, AC_VERB_SET_PROC_COEF
, 0x3050 },
4619 [ALC885_FIXUP_MACPRO_GPIO
] = {
4620 .type
= ALC_FIXUP_FUNC
,
4621 .v
.func
= alc885_fixup_macpro_gpio
,
4623 [ALC889_FIXUP_DAC_ROUTE
] = {
4624 .type
= ALC_FIXUP_FUNC
,
4625 .v
.func
= alc889_fixup_dac_route
,
4629 static const struct snd_pci_quirk alc882_fixup_tbl
[] = {
4630 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD
),
4631 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD
),
4632 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD
),
4633 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD
),
4634 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD
),
4635 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD
),
4636 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
4637 ALC882_FIXUP_ACER_ASPIRE_4930G
),
4638 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
4639 ALC882_FIXUP_ACER_ASPIRE_4930G
),
4640 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
4641 ALC882_FIXUP_ACER_ASPIRE_8930G
),
4642 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
4643 ALC882_FIXUP_ACER_ASPIRE_8930G
),
4644 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
4645 ALC882_FIXUP_ACER_ASPIRE_4930G
),
4646 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
4647 ALC882_FIXUP_ACER_ASPIRE_4930G
),
4648 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
4649 ALC882_FIXUP_ACER_ASPIRE_4930G
),
4650 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210
),
4651 SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE
),
4652 SND_PCI_QUIRK(0x1025, 0x026b, "Acer Aspire 8940G", ALC882_FIXUP_ACER_ASPIRE_8930G
),
4653 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736
),
4654 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD
),
4655 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V
),
4656 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC
),
4657 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601
),
4658 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT
),
4660 /* All Apple entries are in codec SSIDs */
4661 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO
),
4662 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO
),
4663 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO
),
4664 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD
),
4665 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO
),
4667 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD
),
4668 SND_PCI_QUIRK(0x1462, 0x7350, "MSI-7350", ALC889_FIXUP_CD
),
4669 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3
),
4670 SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte EP45-DS3", ALC889_FIXUP_CD
),
4671 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX
),
4672 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD
),
4673 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD
),
4674 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530
),
4675 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF
),
4680 * BIOS auto configuration
4682 /* almost identical with ALC880 parser... */
4683 static int alc882_parse_auto_config(struct hda_codec
*codec
)
4685 static const hda_nid_t alc882_ignore
[] = { 0x1d, 0 };
4686 static const hda_nid_t alc882_ssids
[] = { 0x15, 0x1b, 0x14, 0 };
4687 return alc_parse_auto_config(codec
, alc882_ignore
, alc882_ssids
);
4692 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4693 #include "alc882_quirks.c"
4696 static int patch_alc882(struct hda_codec
*codec
)
4698 struct alc_spec
*spec
;
4699 int err
, board_config
;
4701 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
4707 spec
->mixer_nid
= 0x0b;
4709 switch (codec
->vendor_id
) {
4714 /* ALC883 and variants */
4715 alc_fix_pll_init(codec
, 0x20, 0x0a, 10);
4719 err
= alc_codec_rename_from_preset(codec
);
4723 board_config
= alc_board_config(codec
, ALC882_MODEL_LAST
,
4724 alc882_models
, NULL
);
4725 if (board_config
< 0)
4726 board_config
= alc_board_codec_sid_config(codec
,
4727 ALC882_MODEL_LAST
, alc882_models
, alc882_ssid_cfg_tbl
);
4729 if (board_config
< 0) {
4730 printk(KERN_INFO
"hda_codec: %s: BIOS auto-probing.\n",
4732 board_config
= ALC_MODEL_AUTO
;
4735 if (board_config
== ALC_MODEL_AUTO
) {
4736 alc_pick_fixup(codec
, NULL
, alc882_fixup_tbl
, alc882_fixups
);
4737 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
4740 alc_auto_parse_customize_define(codec
);
4742 if (board_config
== ALC_MODEL_AUTO
) {
4743 /* automatic parse from the BIOS config */
4744 err
= alc882_parse_auto_config(codec
);
4749 if (board_config
!= ALC_MODEL_AUTO
) {
4750 setup_preset(codec
, &alc882_presets
[board_config
]);
4751 spec
->vmaster_nid
= 0x0c;
4754 if (!spec
->no_analog
&& !spec
->adc_nids
) {
4755 alc_auto_fill_adc_caps(codec
);
4756 alc_rebuild_imux_for_auto_mic(codec
);
4757 alc_remove_invalid_adc_nids(codec
);
4760 if (!spec
->no_analog
&& !spec
->cap_mixer
)
4761 set_capture_mixer(codec
);
4763 if (!spec
->no_analog
&& has_cdefine_beep(codec
)) {
4764 err
= snd_hda_attach_beep_device(codec
, 0x1);
4767 set_beep_amp(spec
, 0x0b, 0x05, HDA_INPUT
);
4770 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
4772 codec
->patch_ops
= alc_patch_ops
;
4773 if (board_config
== ALC_MODEL_AUTO
)
4774 spec
->init_hook
= alc_auto_init_std
;
4776 codec
->patch_ops
.build_controls
= __alc_build_controls
;
4778 #ifdef CONFIG_SND_HDA_POWER_SAVE
4779 if (!spec
->loopback
.amplist
)
4780 spec
->loopback
.amplist
= alc882_loopbacks
;
4794 static int alc262_parse_auto_config(struct hda_codec
*codec
)
4796 static const hda_nid_t alc262_ignore
[] = { 0x1d, 0 };
4797 static const hda_nid_t alc262_ssids
[] = { 0x15, 0x1b, 0x14, 0 };
4798 return alc_parse_auto_config(codec
, alc262_ignore
, alc262_ssids
);
4805 ALC262_FIXUP_FSC_H270
,
4806 ALC262_FIXUP_HP_Z200
,
4808 ALC262_FIXUP_LENOVO_3000
,
4810 ALC262_FIXUP_BENQ_T31
,
4813 static const struct alc_fixup alc262_fixups
[] = {
4814 [ALC262_FIXUP_FSC_H270
] = {
4815 .type
= ALC_FIXUP_PINS
,
4816 .v
.pins
= (const struct alc_pincfg
[]) {
4817 { 0x14, 0x99130110 }, /* speaker */
4818 { 0x15, 0x0221142f }, /* front HP */
4819 { 0x1b, 0x0121141f }, /* rear HP */
4823 [ALC262_FIXUP_HP_Z200
] = {
4824 .type
= ALC_FIXUP_PINS
,
4825 .v
.pins
= (const struct alc_pincfg
[]) {
4826 { 0x16, 0x99130120 }, /* internal speaker */
4830 [ALC262_FIXUP_TYAN
] = {
4831 .type
= ALC_FIXUP_PINS
,
4832 .v
.pins
= (const struct alc_pincfg
[]) {
4833 { 0x14, 0x1993e1f0 }, /* int AUX */
4837 [ALC262_FIXUP_LENOVO_3000
] = {
4838 .type
= ALC_FIXUP_VERBS
,
4839 .v
.verbs
= (const struct hda_verb
[]) {
4840 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_VREF50
},
4844 .chain_id
= ALC262_FIXUP_BENQ
,
4846 [ALC262_FIXUP_BENQ
] = {
4847 .type
= ALC_FIXUP_VERBS
,
4848 .v
.verbs
= (const struct hda_verb
[]) {
4849 { 0x20, AC_VERB_SET_COEF_INDEX
, 0x07 },
4850 { 0x20, AC_VERB_SET_PROC_COEF
, 0x3070 },
4854 [ALC262_FIXUP_BENQ_T31
] = {
4855 .type
= ALC_FIXUP_VERBS
,
4856 .v
.verbs
= (const struct hda_verb
[]) {
4857 { 0x20, AC_VERB_SET_COEF_INDEX
, 0x07 },
4858 { 0x20, AC_VERB_SET_PROC_COEF
, 0x3050 },
4864 static const struct snd_pci_quirk alc262_fixup_tbl
[] = {
4865 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200
),
4866 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ
),
4867 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ
),
4868 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN
),
4869 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270
),
4870 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000
),
4871 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ
),
4872 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31
),
4877 #ifdef CONFIG_SND_HDA_POWER_SAVE
4878 #define alc262_loopbacks alc880_loopbacks
4883 static int patch_alc262(struct hda_codec
*codec
)
4885 struct alc_spec
*spec
;
4888 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
4894 spec
->mixer_nid
= 0x0b;
4897 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
4902 snd_hda_codec_write(codec
, 0x1a, 0, AC_VERB_SET_COEF_INDEX
, 7);
4903 tmp
= snd_hda_codec_read(codec
, 0x20, 0, AC_VERB_GET_PROC_COEF
, 0);
4904 snd_hda_codec_write(codec
, 0x1a, 0, AC_VERB_SET_COEF_INDEX
, 7);
4905 snd_hda_codec_write(codec
, 0x1a, 0, AC_VERB_SET_PROC_COEF
, tmp
| 0x80);
4908 alc_auto_parse_customize_define(codec
);
4910 alc_fix_pll_init(codec
, 0x20, 0x0a, 10);
4912 alc_pick_fixup(codec
, NULL
, alc262_fixup_tbl
, alc262_fixups
);
4913 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
4915 /* automatic parse from the BIOS config */
4916 err
= alc262_parse_auto_config(codec
);
4920 if (!spec
->no_analog
&& !spec
->adc_nids
) {
4921 alc_auto_fill_adc_caps(codec
);
4922 alc_rebuild_imux_for_auto_mic(codec
);
4923 alc_remove_invalid_adc_nids(codec
);
4926 if (!spec
->no_analog
&& !spec
->cap_mixer
)
4927 set_capture_mixer(codec
);
4929 if (!spec
->no_analog
&& has_cdefine_beep(codec
)) {
4930 err
= snd_hda_attach_beep_device(codec
, 0x1);
4933 set_beep_amp(spec
, 0x0b, 0x05, HDA_INPUT
);
4936 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
4938 codec
->patch_ops
= alc_patch_ops
;
4939 spec
->init_hook
= alc_auto_init_std
;
4940 spec
->shutup
= alc_eapd_shutup
;
4942 #ifdef CONFIG_SND_HDA_POWER_SAVE
4943 if (!spec
->loopback
.amplist
)
4944 spec
->loopback
.amplist
= alc262_loopbacks
;
4957 /* bind Beep switches of both NID 0x0f and 0x10 */
4958 static const struct hda_bind_ctls alc268_bind_beep_sw
= {
4959 .ops
= &snd_hda_bind_sw
,
4961 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT
),
4962 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT
),
4967 static const struct snd_kcontrol_new alc268_beep_mixer
[] = {
4968 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT
),
4969 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw
),
4973 /* set PCBEEP vol = 0, mute connections */
4974 static const struct hda_verb alc268_beep_init_verbs
[] = {
4975 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
4976 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(1)},
4977 {0x10, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(1)},
4982 * BIOS auto configuration
4984 static int alc268_parse_auto_config(struct hda_codec
*codec
)
4986 static const hda_nid_t alc268_ssids
[] = { 0x15, 0x1b, 0x14, 0 };
4987 struct alc_spec
*spec
= codec
->spec
;
4988 int err
= alc_parse_auto_config(codec
, NULL
, alc268_ssids
);
4990 if (!spec
->no_analog
&& spec
->autocfg
.speaker_pins
[0] != 0x1d) {
4991 add_mixer(spec
, alc268_beep_mixer
);
4992 add_verb(spec
, alc268_beep_init_verbs
);
5000 static int patch_alc268(struct hda_codec
*codec
)
5002 struct alc_spec
*spec
;
5003 int i
, has_beep
, err
;
5005 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
5011 /* ALC268 has no aa-loopback mixer */
5013 /* automatic parse from the BIOS config */
5014 err
= alc268_parse_auto_config(codec
);
5019 for (i
= 0; i
< spec
->num_mixers
; i
++) {
5020 if (spec
->mixers
[i
] == alc268_beep_mixer
) {
5027 err
= snd_hda_attach_beep_device(codec
, 0x1);
5030 if (!query_amp_caps(codec
, 0x1d, HDA_INPUT
))
5031 /* override the amp caps for beep generator */
5032 snd_hda_override_amp_caps(codec
, 0x1d, HDA_INPUT
,
5033 (0x0c << AC_AMPCAP_OFFSET_SHIFT
) |
5034 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT
) |
5035 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT
) |
5036 (0 << AC_AMPCAP_MUTE_SHIFT
));
5039 if (!spec
->no_analog
&& !spec
->adc_nids
) {
5040 alc_auto_fill_adc_caps(codec
);
5041 alc_rebuild_imux_for_auto_mic(codec
);
5042 alc_remove_invalid_adc_nids(codec
);
5045 if (!spec
->no_analog
&& !spec
->cap_mixer
)
5046 set_capture_mixer(codec
);
5048 codec
->patch_ops
= alc_patch_ops
;
5049 spec
->init_hook
= alc_auto_init_std
;
5050 spec
->shutup
= alc_eapd_shutup
;
5062 #ifdef CONFIG_SND_HDA_POWER_SAVE
5063 #define alc269_loopbacks alc880_loopbacks
5066 static const struct hda_pcm_stream alc269_44k_pcm_analog_playback
= {
5070 .rates
= SNDRV_PCM_RATE_44100
, /* fixed rate */
5071 /* NID is set in alc_build_pcms */
5073 .open
= alc_playback_pcm_open
,
5074 .prepare
= alc_playback_pcm_prepare
,
5075 .cleanup
= alc_playback_pcm_cleanup
5079 static const struct hda_pcm_stream alc269_44k_pcm_analog_capture
= {
5083 .rates
= SNDRV_PCM_RATE_44100
, /* fixed rate */
5084 /* NID is set in alc_build_pcms */
5087 #ifdef CONFIG_SND_HDA_POWER_SAVE
5088 static int alc269_mic2_for_mute_led(struct hda_codec
*codec
)
5090 switch (codec
->subsystem_id
) {
5097 static int alc269_mic2_mute_check_ps(struct hda_codec
*codec
, hda_nid_t nid
)
5099 /* update mute-LED according to the speaker mute state */
5100 if (nid
== 0x01 || nid
== 0x14) {
5102 if (snd_hda_codec_amp_read(codec
, 0x14, 0, HDA_OUTPUT
, 0) &
5107 /* mic2 vref pin is used for mute LED control */
5108 snd_hda_codec_update_cache(codec
, 0x19, 0,
5109 AC_VERB_SET_PIN_WIDGET_CONTROL
,
5112 return alc_check_power_status(codec
, nid
);
5114 #endif /* CONFIG_SND_HDA_POWER_SAVE */
5116 /* different alc269-variants */
5118 ALC269_TYPE_ALC269VA
,
5119 ALC269_TYPE_ALC269VB
,
5120 ALC269_TYPE_ALC269VC
,
5124 * BIOS auto configuration
5126 static int alc269_parse_auto_config(struct hda_codec
*codec
)
5128 static const hda_nid_t alc269_ignore
[] = { 0x1d, 0 };
5129 static const hda_nid_t alc269_ssids
[] = { 0, 0x1b, 0x14, 0x21 };
5130 static const hda_nid_t alc269va_ssids
[] = { 0x15, 0x1b, 0x14, 0 };
5131 struct alc_spec
*spec
= codec
->spec
;
5132 const hda_nid_t
*ssids
= spec
->codec_variant
== ALC269_TYPE_ALC269VA
?
5133 alc269va_ssids
: alc269_ssids
;
5135 return alc_parse_auto_config(codec
, alc269_ignore
, ssids
);
5138 static void alc269_toggle_power_output(struct hda_codec
*codec
, int power_up
)
5140 int val
= alc_read_coef_idx(codec
, 0x04);
5145 alc_write_coef_idx(codec
, 0x04, val
);
5148 static void alc269_shutup(struct hda_codec
*codec
)
5150 if ((alc_get_coef0(codec
) & 0x00ff) == 0x017)
5151 alc269_toggle_power_output(codec
, 0);
5152 if ((alc_get_coef0(codec
) & 0x00ff) == 0x018) {
5153 alc269_toggle_power_output(codec
, 0);
5159 static int alc269_resume(struct hda_codec
*codec
)
5161 if ((alc_get_coef0(codec
) & 0x00ff) == 0x018) {
5162 alc269_toggle_power_output(codec
, 0);
5166 codec
->patch_ops
.init(codec
);
5168 if ((alc_get_coef0(codec
) & 0x00ff) == 0x017) {
5169 alc269_toggle_power_output(codec
, 1);
5173 if ((alc_get_coef0(codec
) & 0x00ff) == 0x018)
5174 alc269_toggle_power_output(codec
, 1);
5176 snd_hda_codec_resume_amp(codec
);
5177 snd_hda_codec_resume_cache(codec
);
5178 hda_call_check_power_status(codec
, 0x01);
5181 #endif /* CONFIG_PM */
5183 static void alc269_fixup_hweq(struct hda_codec
*codec
,
5184 const struct alc_fixup
*fix
, int action
)
5188 if (action
!= ALC_FIXUP_ACT_INIT
)
5190 coef
= alc_read_coef_idx(codec
, 0x1e);
5191 alc_write_coef_idx(codec
, 0x1e, coef
| 0x80);
5194 static void alc271_fixup_dmic(struct hda_codec
*codec
,
5195 const struct alc_fixup
*fix
, int action
)
5197 static const struct hda_verb verbs
[] = {
5198 {0x20, AC_VERB_SET_COEF_INDEX
, 0x0d},
5199 {0x20, AC_VERB_SET_PROC_COEF
, 0x4000},
5204 if (strcmp(codec
->chip_name
, "ALC271X"))
5206 cfg
= snd_hda_codec_get_pincfg(codec
, 0x12);
5207 if (get_defcfg_connect(cfg
) == AC_JACK_PORT_FIXED
)
5208 snd_hda_sequence_write(codec
, verbs
);
5211 static void alc269_fixup_pcm_44k(struct hda_codec
*codec
,
5212 const struct alc_fixup
*fix
, int action
)
5214 struct alc_spec
*spec
= codec
->spec
;
5216 if (action
!= ALC_FIXUP_ACT_PROBE
)
5219 /* Due to a hardware problem on Lenovo Ideadpad, we need to
5220 * fix the sample rate of analog I/O to 44.1kHz
5222 spec
->stream_analog_playback
= &alc269_44k_pcm_analog_playback
;
5223 spec
->stream_analog_capture
= &alc269_44k_pcm_analog_capture
;
5226 static void alc269_fixup_stereo_dmic(struct hda_codec
*codec
,
5227 const struct alc_fixup
*fix
, int action
)
5231 if (action
!= ALC_FIXUP_ACT_INIT
)
5233 /* The digital-mic unit sends PDM (differential signal) instead of
5234 * the standard PCM, thus you can't record a valid mono stream as is.
5235 * Below is a workaround specific to ALC269 to control the dmic
5236 * signal source as mono.
5238 coef
= alc_read_coef_idx(codec
, 0x07);
5239 alc_write_coef_idx(codec
, 0x07, coef
| 0x80);
5242 static void alc269_quanta_automute(struct hda_codec
*codec
)
5244 update_outputs(codec
);
5246 snd_hda_codec_write(codec
, 0x20, 0,
5247 AC_VERB_SET_COEF_INDEX
, 0x0c);
5248 snd_hda_codec_write(codec
, 0x20, 0,
5249 AC_VERB_SET_PROC_COEF
, 0x680);
5251 snd_hda_codec_write(codec
, 0x20, 0,
5252 AC_VERB_SET_COEF_INDEX
, 0x0c);
5253 snd_hda_codec_write(codec
, 0x20, 0,
5254 AC_VERB_SET_PROC_COEF
, 0x480);
5257 static void alc269_fixup_quanta_mute(struct hda_codec
*codec
,
5258 const struct alc_fixup
*fix
, int action
)
5260 struct alc_spec
*spec
= codec
->spec
;
5261 if (action
!= ALC_FIXUP_ACT_PROBE
)
5263 spec
->automute_hook
= alc269_quanta_automute
;
5267 ALC269_FIXUP_SONY_VAIO
,
5268 ALC275_FIXUP_SONY_VAIO_GPIO2
,
5269 ALC269_FIXUP_DELL_M101Z
,
5270 ALC269_FIXUP_SKU_IGNORE
,
5271 ALC269_FIXUP_ASUS_G73JW
,
5272 ALC269_FIXUP_LENOVO_EAPD
,
5273 ALC275_FIXUP_SONY_HWEQ
,
5275 ALC269_FIXUP_PCM_44K
,
5276 ALC269_FIXUP_STEREO_DMIC
,
5277 ALC269_FIXUP_QUANTA_MUTE
,
5278 ALC269_FIXUP_LIFEBOOK
,
5281 ALC269VB_FIXUP_AMIC
,
5282 ALC269VB_FIXUP_DMIC
,
5285 static const struct alc_fixup alc269_fixups
[] = {
5286 [ALC269_FIXUP_SONY_VAIO
] = {
5287 .type
= ALC_FIXUP_VERBS
,
5288 .v
.verbs
= (const struct hda_verb
[]) {
5289 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_VREFGRD
},
5293 [ALC275_FIXUP_SONY_VAIO_GPIO2
] = {
5294 .type
= ALC_FIXUP_VERBS
,
5295 .v
.verbs
= (const struct hda_verb
[]) {
5296 {0x01, AC_VERB_SET_GPIO_MASK
, 0x04},
5297 {0x01, AC_VERB_SET_GPIO_DIRECTION
, 0x04},
5298 {0x01, AC_VERB_SET_GPIO_DATA
, 0x00},
5302 .chain_id
= ALC269_FIXUP_SONY_VAIO
5304 [ALC269_FIXUP_DELL_M101Z
] = {
5305 .type
= ALC_FIXUP_VERBS
,
5306 .v
.verbs
= (const struct hda_verb
[]) {
5307 /* Enables internal speaker */
5308 {0x20, AC_VERB_SET_COEF_INDEX
, 13},
5309 {0x20, AC_VERB_SET_PROC_COEF
, 0x4040},
5313 [ALC269_FIXUP_SKU_IGNORE
] = {
5314 .type
= ALC_FIXUP_SKU
,
5315 .v
.sku
= ALC_FIXUP_SKU_IGNORE
,
5317 [ALC269_FIXUP_ASUS_G73JW
] = {
5318 .type
= ALC_FIXUP_PINS
,
5319 .v
.pins
= (const struct alc_pincfg
[]) {
5320 { 0x17, 0x99130111 }, /* subwoofer */
5324 [ALC269_FIXUP_LENOVO_EAPD
] = {
5325 .type
= ALC_FIXUP_VERBS
,
5326 .v
.verbs
= (const struct hda_verb
[]) {
5327 {0x14, AC_VERB_SET_EAPD_BTLENABLE
, 0},
5331 [ALC275_FIXUP_SONY_HWEQ
] = {
5332 .type
= ALC_FIXUP_FUNC
,
5333 .v
.func
= alc269_fixup_hweq
,
5335 .chain_id
= ALC275_FIXUP_SONY_VAIO_GPIO2
5337 [ALC271_FIXUP_DMIC
] = {
5338 .type
= ALC_FIXUP_FUNC
,
5339 .v
.func
= alc271_fixup_dmic
,
5341 [ALC269_FIXUP_PCM_44K
] = {
5342 .type
= ALC_FIXUP_FUNC
,
5343 .v
.func
= alc269_fixup_pcm_44k
,
5345 [ALC269_FIXUP_STEREO_DMIC
] = {
5346 .type
= ALC_FIXUP_FUNC
,
5347 .v
.func
= alc269_fixup_stereo_dmic
,
5349 [ALC269_FIXUP_QUANTA_MUTE
] = {
5350 .type
= ALC_FIXUP_FUNC
,
5351 .v
.func
= alc269_fixup_quanta_mute
,
5353 [ALC269_FIXUP_LIFEBOOK
] = {
5354 .type
= ALC_FIXUP_PINS
,
5355 .v
.pins
= (const struct alc_pincfg
[]) {
5356 { 0x1a, 0x2101103f }, /* dock line-out */
5357 { 0x1b, 0x23a11040 }, /* dock mic-in */
5361 .chain_id
= ALC269_FIXUP_QUANTA_MUTE
5363 [ALC269_FIXUP_AMIC
] = {
5364 .type
= ALC_FIXUP_PINS
,
5365 .v
.pins
= (const struct alc_pincfg
[]) {
5366 { 0x14, 0x99130110 }, /* speaker */
5367 { 0x15, 0x0121401f }, /* HP out */
5368 { 0x18, 0x01a19c20 }, /* mic */
5369 { 0x19, 0x99a3092f }, /* int-mic */
5373 [ALC269_FIXUP_DMIC
] = {
5374 .type
= ALC_FIXUP_PINS
,
5375 .v
.pins
= (const struct alc_pincfg
[]) {
5376 { 0x12, 0x99a3092f }, /* int-mic */
5377 { 0x14, 0x99130110 }, /* speaker */
5378 { 0x15, 0x0121401f }, /* HP out */
5379 { 0x18, 0x01a19c20 }, /* mic */
5383 [ALC269VB_FIXUP_AMIC
] = {
5384 .type
= ALC_FIXUP_PINS
,
5385 .v
.pins
= (const struct alc_pincfg
[]) {
5386 { 0x14, 0x99130110 }, /* speaker */
5387 { 0x18, 0x01a19c20 }, /* mic */
5388 { 0x19, 0x99a3092f }, /* int-mic */
5389 { 0x21, 0x0121401f }, /* HP out */
5393 [ALC269VB_FIXUP_DMIC
] = {
5394 .type
= ALC_FIXUP_PINS
,
5395 .v
.pins
= (const struct alc_pincfg
[]) {
5396 { 0x12, 0x99a3092f }, /* int-mic */
5397 { 0x14, 0x99130110 }, /* speaker */
5398 { 0x18, 0x01a19c20 }, /* mic */
5399 { 0x21, 0x0121401f }, /* HP out */
5405 static const struct snd_pci_quirk alc269_fixup_tbl
[] = {
5406 SND_PCI_QUIRK(0x1043, 0x1427, "Asus Zenbook UX31E", ALC269VB_FIXUP_DMIC
),
5407 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW
),
5408 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC
),
5409 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC
),
5410 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC
),
5411 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC
),
5412 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC
),
5413 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2
),
5414 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ
),
5415 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ
),
5416 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO
),
5417 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z
),
5418 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC
),
5419 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK
),
5420 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE
),
5421 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE
),
5422 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE
),
5423 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE
),
5424 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE
),
5425 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_QUANTA_MUTE
),
5426 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K
),
5427 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD
),
5430 /* Below is a quirk table taken from the old code.
5431 * Basically the device should work as is without the fixup table.
5432 * If BIOS doesn't give a proper info, enable the corresponding
5435 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
5437 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC
),
5438 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC
),
5439 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC
),
5440 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC
),
5441 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC
),
5442 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC
),
5443 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC
),
5444 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC
),
5445 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC
),
5446 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC
),
5447 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC
),
5448 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC
),
5449 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC
),
5450 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC
),
5451 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC
),
5452 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC
),
5453 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC
),
5454 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC
),
5455 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC
),
5456 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC
),
5457 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC
),
5458 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC
),
5459 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC
),
5460 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC
),
5461 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC
),
5462 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC
),
5463 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC
),
5464 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC
),
5465 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC
),
5466 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC
),
5467 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC
),
5468 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC
),
5469 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC
),
5470 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC
),
5471 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC
),
5472 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC
),
5473 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC
),
5474 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC
),
5475 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC
),
5480 static const struct alc_model_fixup alc269_fixup_models
[] = {
5481 {.id
= ALC269_FIXUP_AMIC
, .name
= "laptop-amic"},
5482 {.id
= ALC269_FIXUP_DMIC
, .name
= "laptop-dmic"},
5487 static int alc269_fill_coef(struct hda_codec
*codec
)
5489 struct alc_spec
*spec
= codec
->spec
;
5492 if (spec
->codec_variant
!= ALC269_TYPE_ALC269VB
)
5495 if ((alc_get_coef0(codec
) & 0x00ff) < 0x015) {
5496 alc_write_coef_idx(codec
, 0xf, 0x960b);
5497 alc_write_coef_idx(codec
, 0xe, 0x8817);
5500 if ((alc_get_coef0(codec
) & 0x00ff) == 0x016) {
5501 alc_write_coef_idx(codec
, 0xf, 0x960b);
5502 alc_write_coef_idx(codec
, 0xe, 0x8814);
5505 if ((alc_get_coef0(codec
) & 0x00ff) == 0x017) {
5506 val
= alc_read_coef_idx(codec
, 0x04);
5507 /* Power up output pin */
5508 alc_write_coef_idx(codec
, 0x04, val
| (1<<11));
5511 if ((alc_get_coef0(codec
) & 0x00ff) == 0x018) {
5512 val
= alc_read_coef_idx(codec
, 0xd);
5513 if ((val
& 0x0c00) >> 10 != 0x1) {
5514 /* Capless ramp up clock control */
5515 alc_write_coef_idx(codec
, 0xd, val
| (1<<10));
5517 val
= alc_read_coef_idx(codec
, 0x17);
5518 if ((val
& 0x01c0) >> 6 != 0x4) {
5519 /* Class D power on reset */
5520 alc_write_coef_idx(codec
, 0x17, val
| (1<<7));
5524 val
= alc_read_coef_idx(codec
, 0xd); /* Class D */
5525 alc_write_coef_idx(codec
, 0xd, val
| (1<<14));
5527 val
= alc_read_coef_idx(codec
, 0x4); /* HP */
5528 alc_write_coef_idx(codec
, 0x4, val
| (1<<11));
5535 static int patch_alc269(struct hda_codec
*codec
)
5537 struct alc_spec
*spec
;
5540 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
5546 spec
->mixer_nid
= 0x0b;
5548 alc_auto_parse_customize_define(codec
);
5550 err
= alc_codec_rename_from_preset(codec
);
5554 if (codec
->vendor_id
== 0x10ec0269) {
5555 spec
->codec_variant
= ALC269_TYPE_ALC269VA
;
5556 switch (alc_get_coef0(codec
) & 0x00f0) {
5558 if (codec
->bus
->pci
->subsystem_vendor
== 0x1025 &&
5559 spec
->cdefine
.platform_type
== 1)
5560 err
= alc_codec_rename(codec
, "ALC271X");
5561 spec
->codec_variant
= ALC269_TYPE_ALC269VB
;
5564 if (codec
->bus
->pci
->subsystem_vendor
== 0x17aa &&
5565 codec
->bus
->pci
->subsystem_device
== 0x21f3)
5566 err
= alc_codec_rename(codec
, "ALC3202");
5567 spec
->codec_variant
= ALC269_TYPE_ALC269VC
;
5570 alc_fix_pll_init(codec
, 0x20, 0x04, 15);
5574 alc269_fill_coef(codec
);
5577 alc_pick_fixup(codec
, alc269_fixup_models
,
5578 alc269_fixup_tbl
, alc269_fixups
);
5579 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
5581 /* automatic parse from the BIOS config */
5582 err
= alc269_parse_auto_config(codec
);
5586 if (!spec
->no_analog
&& !spec
->adc_nids
) {
5587 alc_auto_fill_adc_caps(codec
);
5588 alc_rebuild_imux_for_auto_mic(codec
);
5589 alc_remove_invalid_adc_nids(codec
);
5592 if (!spec
->no_analog
&& !spec
->cap_mixer
)
5593 set_capture_mixer(codec
);
5595 if (!spec
->no_analog
&& has_cdefine_beep(codec
)) {
5596 err
= snd_hda_attach_beep_device(codec
, 0x1);
5599 set_beep_amp(spec
, 0x0b, 0x04, HDA_INPUT
);
5602 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
5604 codec
->patch_ops
= alc_patch_ops
;
5606 codec
->patch_ops
.resume
= alc269_resume
;
5608 spec
->init_hook
= alc_auto_init_std
;
5609 spec
->shutup
= alc269_shutup
;
5611 #ifdef CONFIG_SND_HDA_POWER_SAVE
5612 if (!spec
->loopback
.amplist
)
5613 spec
->loopback
.amplist
= alc269_loopbacks
;
5614 if (alc269_mic2_for_mute_led(codec
))
5615 codec
->patch_ops
.check_power_status
= alc269_mic2_mute_check_ps
;
5629 static int alc861_parse_auto_config(struct hda_codec
*codec
)
5631 static const hda_nid_t alc861_ignore
[] = { 0x1d, 0 };
5632 static const hda_nid_t alc861_ssids
[] = { 0x0e, 0x0f, 0x0b, 0 };
5633 return alc_parse_auto_config(codec
, alc861_ignore
, alc861_ssids
);
5636 #ifdef CONFIG_SND_HDA_POWER_SAVE
5637 static const struct hda_amp_list alc861_loopbacks
[] = {
5638 { 0x15, HDA_INPUT
, 0 },
5639 { 0x15, HDA_INPUT
, 1 },
5640 { 0x15, HDA_INPUT
, 2 },
5641 { 0x15, HDA_INPUT
, 3 },
5647 /* Pin config fixes */
5649 PINFIX_FSC_AMILO_PI1505
,
5653 /* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
5654 static void alc861_fixup_asus_amp_vref_0f(struct hda_codec
*codec
,
5655 const struct alc_fixup
*fix
, int action
)
5657 struct alc_spec
*spec
= codec
->spec
;
5660 if (action
!= ALC_FIXUP_ACT_INIT
)
5662 val
= snd_hda_codec_read(codec
, 0x0f, 0,
5663 AC_VERB_GET_PIN_WIDGET_CONTROL
, 0);
5664 if (!(val
& (AC_PINCTL_IN_EN
| AC_PINCTL_OUT_EN
)))
5665 val
|= AC_PINCTL_IN_EN
;
5666 val
|= AC_PINCTL_VREF_50
;
5667 snd_hda_codec_write(codec
, 0x0f, 0,
5668 AC_VERB_SET_PIN_WIDGET_CONTROL
, val
);
5669 spec
->keep_vref_in_automute
= 1;
5672 static const struct alc_fixup alc861_fixups
[] = {
5673 [PINFIX_FSC_AMILO_PI1505
] = {
5674 .type
= ALC_FIXUP_PINS
,
5675 .v
.pins
= (const struct alc_pincfg
[]) {
5676 { 0x0b, 0x0221101f }, /* HP */
5677 { 0x0f, 0x90170310 }, /* speaker */
5681 [PINFIX_ASUS_A6RP
] = {
5682 .type
= ALC_FIXUP_FUNC
,
5683 .v
.func
= alc861_fixup_asus_amp_vref_0f
,
5687 static const struct snd_pci_quirk alc861_fixup_tbl
[] = {
5688 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", PINFIX_ASUS_A6RP
),
5689 SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", PINFIX_ASUS_A6RP
),
5690 SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", PINFIX_ASUS_A6RP
),
5691 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", PINFIX_FSC_AMILO_PI1505
),
5697 static int patch_alc861(struct hda_codec
*codec
)
5699 struct alc_spec
*spec
;
5702 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
5708 spec
->mixer_nid
= 0x15;
5710 alc_pick_fixup(codec
, NULL
, alc861_fixup_tbl
, alc861_fixups
);
5711 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
5713 /* automatic parse from the BIOS config */
5714 err
= alc861_parse_auto_config(codec
);
5718 if (!spec
->no_analog
&& !spec
->adc_nids
) {
5719 alc_auto_fill_adc_caps(codec
);
5720 alc_rebuild_imux_for_auto_mic(codec
);
5721 alc_remove_invalid_adc_nids(codec
);
5724 if (!spec
->no_analog
&& !spec
->cap_mixer
)
5725 set_capture_mixer(codec
);
5727 if (!spec
->no_analog
) {
5728 err
= snd_hda_attach_beep_device(codec
, 0x23);
5731 set_beep_amp(spec
, 0x23, 0, HDA_OUTPUT
);
5734 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
5736 codec
->patch_ops
= alc_patch_ops
;
5737 spec
->init_hook
= alc_auto_init_std
;
5738 #ifdef CONFIG_SND_HDA_POWER_SAVE
5739 spec
->power_hook
= alc_power_eapd
;
5740 if (!spec
->loopback
.amplist
)
5741 spec
->loopback
.amplist
= alc861_loopbacks
;
5756 * In addition, an independent DAC
5758 #ifdef CONFIG_SND_HDA_POWER_SAVE
5759 #define alc861vd_loopbacks alc880_loopbacks
5762 static int alc861vd_parse_auto_config(struct hda_codec
*codec
)
5764 static const hda_nid_t alc861vd_ignore
[] = { 0x1d, 0 };
5765 static const hda_nid_t alc861vd_ssids
[] = { 0x15, 0x1b, 0x14, 0 };
5766 return alc_parse_auto_config(codec
, alc861vd_ignore
, alc861vd_ssids
);
5770 ALC660VD_FIX_ASUS_GPIO1
,
5771 ALC861VD_FIX_DALLAS
,
5774 /* exclude VREF80 */
5775 static void alc861vd_fixup_dallas(struct hda_codec
*codec
,
5776 const struct alc_fixup
*fix
, int action
)
5778 if (action
== ALC_FIXUP_ACT_PRE_PROBE
) {
5779 snd_hda_override_pin_caps(codec
, 0x18, 0x00001714);
5780 snd_hda_override_pin_caps(codec
, 0x19, 0x0000171c);
5784 static const struct alc_fixup alc861vd_fixups
[] = {
5785 [ALC660VD_FIX_ASUS_GPIO1
] = {
5786 .type
= ALC_FIXUP_VERBS
,
5787 .v
.verbs
= (const struct hda_verb
[]) {
5789 {0x01, AC_VERB_SET_GPIO_MASK
, 0x03},
5790 {0x01, AC_VERB_SET_GPIO_DIRECTION
, 0x01},
5791 {0x01, AC_VERB_SET_GPIO_DATA
, 0x01},
5795 [ALC861VD_FIX_DALLAS
] = {
5796 .type
= ALC_FIXUP_FUNC
,
5797 .v
.func
= alc861vd_fixup_dallas
,
5801 static const struct snd_pci_quirk alc861vd_fixup_tbl
[] = {
5802 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS
),
5803 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1
),
5804 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS
),
5808 static const struct hda_verb alc660vd_eapd_verbs
[] = {
5809 {0x14, AC_VERB_SET_EAPD_BTLENABLE
, 2},
5810 {0x15, AC_VERB_SET_EAPD_BTLENABLE
, 2},
5816 static int patch_alc861vd(struct hda_codec
*codec
)
5818 struct alc_spec
*spec
;
5821 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
5827 spec
->mixer_nid
= 0x0b;
5829 alc_pick_fixup(codec
, NULL
, alc861vd_fixup_tbl
, alc861vd_fixups
);
5830 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
5832 /* automatic parse from the BIOS config */
5833 err
= alc861vd_parse_auto_config(codec
);
5837 if (codec
->vendor_id
== 0x10ec0660) {
5838 /* always turn on EAPD */
5839 add_verb(spec
, alc660vd_eapd_verbs
);
5842 if (!spec
->no_analog
&& !spec
->adc_nids
) {
5843 alc_auto_fill_adc_caps(codec
);
5844 alc_rebuild_imux_for_auto_mic(codec
);
5845 alc_remove_invalid_adc_nids(codec
);
5848 if (!spec
->no_analog
&& !spec
->cap_mixer
)
5849 set_capture_mixer(codec
);
5851 if (!spec
->no_analog
) {
5852 err
= snd_hda_attach_beep_device(codec
, 0x23);
5855 set_beep_amp(spec
, 0x0b, 0x05, HDA_INPUT
);
5858 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
5860 codec
->patch_ops
= alc_patch_ops
;
5862 spec
->init_hook
= alc_auto_init_std
;
5863 spec
->shutup
= alc_eapd_shutup
;
5864 #ifdef CONFIG_SND_HDA_POWER_SAVE
5865 if (!spec
->loopback
.amplist
)
5866 spec
->loopback
.amplist
= alc861vd_loopbacks
;
5879 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
5880 * configuration. Each pin widget can choose any input DACs and a mixer.
5881 * Each ADC is connected from a mixer of all inputs. This makes possible
5882 * 6-channel independent captures.
5884 * In addition, an independent DAC for the multi-playback (not used in this
5887 #ifdef CONFIG_SND_HDA_POWER_SAVE
5888 #define alc662_loopbacks alc880_loopbacks
5892 * BIOS auto configuration
5895 static int alc662_parse_auto_config(struct hda_codec
*codec
)
5897 static const hda_nid_t alc662_ignore
[] = { 0x1d, 0 };
5898 static const hda_nid_t alc663_ssids
[] = { 0x15, 0x1b, 0x14, 0x21 };
5899 static const hda_nid_t alc662_ssids
[] = { 0x15, 0x1b, 0x14, 0 };
5900 const hda_nid_t
*ssids
;
5902 if (codec
->vendor_id
== 0x10ec0272 || codec
->vendor_id
== 0x10ec0663 ||
5903 codec
->vendor_id
== 0x10ec0665 || codec
->vendor_id
== 0x10ec0670)
5904 ssids
= alc663_ssids
;
5906 ssids
= alc662_ssids
;
5907 return alc_parse_auto_config(codec
, alc662_ignore
, ssids
);
5910 static void alc272_fixup_mario(struct hda_codec
*codec
,
5911 const struct alc_fixup
*fix
, int action
)
5913 if (action
!= ALC_FIXUP_ACT_PROBE
)
5915 if (snd_hda_override_amp_caps(codec
, 0x2, HDA_OUTPUT
,
5916 (0x3b << AC_AMPCAP_OFFSET_SHIFT
) |
5917 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT
) |
5918 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT
) |
5919 (0 << AC_AMPCAP_MUTE_SHIFT
)))
5921 "hda_codec: failed to override amp caps for NID 0x2\n");
5925 ALC662_FIXUP_ASPIRE
,
5926 ALC662_FIXUP_IDEAPAD
,
5928 ALC662_FIXUP_CZC_P10T
,
5929 ALC662_FIXUP_SKU_IGNORE
,
5930 ALC662_FIXUP_HP_RP5800
,
5931 ALC662_FIXUP_ASUS_MODE1
,
5932 ALC662_FIXUP_ASUS_MODE2
,
5933 ALC662_FIXUP_ASUS_MODE3
,
5934 ALC662_FIXUP_ASUS_MODE4
,
5935 ALC662_FIXUP_ASUS_MODE5
,
5936 ALC662_FIXUP_ASUS_MODE6
,
5937 ALC662_FIXUP_ASUS_MODE7
,
5938 ALC662_FIXUP_ASUS_MODE8
,
5941 static const struct alc_fixup alc662_fixups
[] = {
5942 [ALC662_FIXUP_ASPIRE
] = {
5943 .type
= ALC_FIXUP_PINS
,
5944 .v
.pins
= (const struct alc_pincfg
[]) {
5945 { 0x15, 0x99130112 }, /* subwoofer */
5949 [ALC662_FIXUP_IDEAPAD
] = {
5950 .type
= ALC_FIXUP_PINS
,
5951 .v
.pins
= (const struct alc_pincfg
[]) {
5952 { 0x17, 0x99130112 }, /* subwoofer */
5956 [ALC272_FIXUP_MARIO
] = {
5957 .type
= ALC_FIXUP_FUNC
,
5958 .v
.func
= alc272_fixup_mario
,
5960 [ALC662_FIXUP_CZC_P10T
] = {
5961 .type
= ALC_FIXUP_VERBS
,
5962 .v
.verbs
= (const struct hda_verb
[]) {
5963 {0x14, AC_VERB_SET_EAPD_BTLENABLE
, 0},
5967 [ALC662_FIXUP_SKU_IGNORE
] = {
5968 .type
= ALC_FIXUP_SKU
,
5969 .v
.sku
= ALC_FIXUP_SKU_IGNORE
,
5971 [ALC662_FIXUP_HP_RP5800
] = {
5972 .type
= ALC_FIXUP_PINS
,
5973 .v
.pins
= (const struct alc_pincfg
[]) {
5974 { 0x14, 0x0221201f }, /* HP out */
5978 .chain_id
= ALC662_FIXUP_SKU_IGNORE
5980 [ALC662_FIXUP_ASUS_MODE1
] = {
5981 .type
= ALC_FIXUP_PINS
,
5982 .v
.pins
= (const struct alc_pincfg
[]) {
5983 { 0x14, 0x99130110 }, /* speaker */
5984 { 0x18, 0x01a19c20 }, /* mic */
5985 { 0x19, 0x99a3092f }, /* int-mic */
5986 { 0x21, 0x0121401f }, /* HP out */
5990 .chain_id
= ALC662_FIXUP_SKU_IGNORE
5992 [ALC662_FIXUP_ASUS_MODE2
] = {
5993 .type
= ALC_FIXUP_PINS
,
5994 .v
.pins
= (const struct alc_pincfg
[]) {
5995 { 0x14, 0x99130110 }, /* speaker */
5996 { 0x18, 0x01a19820 }, /* mic */
5997 { 0x19, 0x99a3092f }, /* int-mic */
5998 { 0x1b, 0x0121401f }, /* HP out */
6002 .chain_id
= ALC662_FIXUP_SKU_IGNORE
6004 [ALC662_FIXUP_ASUS_MODE3
] = {
6005 .type
= ALC_FIXUP_PINS
,
6006 .v
.pins
= (const struct alc_pincfg
[]) {
6007 { 0x14, 0x99130110 }, /* speaker */
6008 { 0x15, 0x0121441f }, /* HP */
6009 { 0x18, 0x01a19840 }, /* mic */
6010 { 0x19, 0x99a3094f }, /* int-mic */
6011 { 0x21, 0x01211420 }, /* HP2 */
6015 .chain_id
= ALC662_FIXUP_SKU_IGNORE
6017 [ALC662_FIXUP_ASUS_MODE4
] = {
6018 .type
= ALC_FIXUP_PINS
,
6019 .v
.pins
= (const struct alc_pincfg
[]) {
6020 { 0x14, 0x99130110 }, /* speaker */
6021 { 0x16, 0x99130111 }, /* speaker */
6022 { 0x18, 0x01a19840 }, /* mic */
6023 { 0x19, 0x99a3094f }, /* int-mic */
6024 { 0x21, 0x0121441f }, /* HP */
6028 .chain_id
= ALC662_FIXUP_SKU_IGNORE
6030 [ALC662_FIXUP_ASUS_MODE5
] = {
6031 .type
= ALC_FIXUP_PINS
,
6032 .v
.pins
= (const struct alc_pincfg
[]) {
6033 { 0x14, 0x99130110 }, /* speaker */
6034 { 0x15, 0x0121441f }, /* HP */
6035 { 0x16, 0x99130111 }, /* speaker */
6036 { 0x18, 0x01a19840 }, /* mic */
6037 { 0x19, 0x99a3094f }, /* int-mic */
6041 .chain_id
= ALC662_FIXUP_SKU_IGNORE
6043 [ALC662_FIXUP_ASUS_MODE6
] = {
6044 .type
= ALC_FIXUP_PINS
,
6045 .v
.pins
= (const struct alc_pincfg
[]) {
6046 { 0x14, 0x99130110 }, /* speaker */
6047 { 0x15, 0x01211420 }, /* HP2 */
6048 { 0x18, 0x01a19840 }, /* mic */
6049 { 0x19, 0x99a3094f }, /* int-mic */
6050 { 0x1b, 0x0121441f }, /* HP */
6054 .chain_id
= ALC662_FIXUP_SKU_IGNORE
6056 [ALC662_FIXUP_ASUS_MODE7
] = {
6057 .type
= ALC_FIXUP_PINS
,
6058 .v
.pins
= (const struct alc_pincfg
[]) {
6059 { 0x14, 0x99130110 }, /* speaker */
6060 { 0x17, 0x99130111 }, /* speaker */
6061 { 0x18, 0x01a19840 }, /* mic */
6062 { 0x19, 0x99a3094f }, /* int-mic */
6063 { 0x1b, 0x01214020 }, /* HP */
6064 { 0x21, 0x0121401f }, /* HP */
6068 .chain_id
= ALC662_FIXUP_SKU_IGNORE
6070 [ALC662_FIXUP_ASUS_MODE8
] = {
6071 .type
= ALC_FIXUP_PINS
,
6072 .v
.pins
= (const struct alc_pincfg
[]) {
6073 { 0x14, 0x99130110 }, /* speaker */
6074 { 0x12, 0x99a30970 }, /* int-mic */
6075 { 0x15, 0x01214020 }, /* HP */
6076 { 0x17, 0x99130111 }, /* speaker */
6077 { 0x18, 0x01a19840 }, /* mic */
6078 { 0x21, 0x0121401f }, /* HP */
6082 .chain_id
= ALC662_FIXUP_SKU_IGNORE
6086 static const struct snd_pci_quirk alc662_fixup_tbl
[] = {
6087 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2
),
6088 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE
),
6089 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE
),
6090 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE
),
6091 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800
),
6092 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2
),
6093 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD
),
6094 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD
),
6095 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD
),
6096 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T
),
6099 /* Below is a quirk table taken from the old code.
6100 * Basically the device should work as is without the fixup table.
6101 * If BIOS doesn't give a proper info, enable the corresponding
6104 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1
),
6105 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3
),
6106 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1
),
6107 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3
),
6108 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1
),
6109 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2
),
6110 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1
),
6111 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1
),
6112 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1
),
6113 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2
),
6114 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7
),
6115 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7
),
6116 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8
),
6117 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3
),
6118 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1
),
6119 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2
),
6120 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2
),
6121 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1
),
6122 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2
),
6123 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6
),
6124 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6
),
6125 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2
),
6126 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1
),
6127 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3
),
6128 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2
),
6129 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2
),
6130 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5
),
6131 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6
),
6132 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2
),
6133 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1
),
6134 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2
),
6135 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2
),
6136 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3
),
6137 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3
),
6138 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1
),
6139 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1
),
6140 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1
),
6141 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1
),
6142 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1
),
6143 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2
),
6144 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2
),
6145 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1
),
6146 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1
),
6147 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3
),
6148 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1
),
6149 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1
),
6150 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1
),
6151 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2
),
6152 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1
),
6153 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4
),
6158 static const struct alc_model_fixup alc662_fixup_models
[] = {
6159 {.id
= ALC272_FIXUP_MARIO
, .name
= "mario"},
6160 {.id
= ALC662_FIXUP_ASUS_MODE1
, .name
= "asus-mode1"},
6161 {.id
= ALC662_FIXUP_ASUS_MODE2
, .name
= "asus-mode2"},
6162 {.id
= ALC662_FIXUP_ASUS_MODE3
, .name
= "asus-mode3"},
6163 {.id
= ALC662_FIXUP_ASUS_MODE4
, .name
= "asus-mode4"},
6164 {.id
= ALC662_FIXUP_ASUS_MODE5
, .name
= "asus-mode5"},
6165 {.id
= ALC662_FIXUP_ASUS_MODE6
, .name
= "asus-mode6"},
6166 {.id
= ALC662_FIXUP_ASUS_MODE7
, .name
= "asus-mode7"},
6167 {.id
= ALC662_FIXUP_ASUS_MODE8
, .name
= "asus-mode8"},
6174 static int patch_alc662(struct hda_codec
*codec
)
6176 struct alc_spec
*spec
;
6179 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
6185 spec
->mixer_nid
= 0x0b;
6187 /* handle multiple HPs as is */
6188 spec
->parse_flags
= HDA_PINCFG_NO_HP_FIXUP
;
6190 alc_auto_parse_customize_define(codec
);
6192 alc_fix_pll_init(codec
, 0x20, 0x04, 15);
6194 err
= alc_codec_rename_from_preset(codec
);
6198 if ((alc_get_coef0(codec
) & (1 << 14)) &&
6199 codec
->bus
->pci
->subsystem_vendor
== 0x1025 &&
6200 spec
->cdefine
.platform_type
== 1) {
6201 if (alc_codec_rename(codec
, "ALC272X") < 0)
6205 alc_pick_fixup(codec
, alc662_fixup_models
,
6206 alc662_fixup_tbl
, alc662_fixups
);
6207 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
6208 /* automatic parse from the BIOS config */
6209 err
= alc662_parse_auto_config(codec
);
6213 if (!spec
->no_analog
&& !spec
->adc_nids
) {
6214 alc_auto_fill_adc_caps(codec
);
6215 alc_rebuild_imux_for_auto_mic(codec
);
6216 alc_remove_invalid_adc_nids(codec
);
6219 if (!spec
->no_analog
&& !spec
->cap_mixer
)
6220 set_capture_mixer(codec
);
6222 if (!spec
->no_analog
&& has_cdefine_beep(codec
)) {
6223 err
= snd_hda_attach_beep_device(codec
, 0x1);
6226 switch (codec
->vendor_id
) {
6228 set_beep_amp(spec
, 0x0b, 0x05, HDA_INPUT
);
6233 set_beep_amp(spec
, 0x0b, 0x04, HDA_INPUT
);
6236 set_beep_amp(spec
, 0x0b, 0x03, HDA_INPUT
);
6241 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
6243 codec
->patch_ops
= alc_patch_ops
;
6244 spec
->init_hook
= alc_auto_init_std
;
6245 spec
->shutup
= alc_eapd_shutup
;
6247 #ifdef CONFIG_SND_HDA_POWER_SAVE
6248 if (!spec
->loopback
.amplist
)
6249 spec
->loopback
.amplist
= alc662_loopbacks
;
6263 static int alc680_parse_auto_config(struct hda_codec
*codec
)
6265 return alc_parse_auto_config(codec
, NULL
, NULL
);
6270 static int patch_alc680(struct hda_codec
*codec
)
6272 struct alc_spec
*spec
;
6275 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
6281 /* ALC680 has no aa-loopback mixer */
6283 /* automatic parse from the BIOS config */
6284 err
= alc680_parse_auto_config(codec
);
6290 if (!spec
->no_analog
&& !spec
->cap_mixer
)
6291 set_capture_mixer(codec
);
6293 codec
->patch_ops
= alc_patch_ops
;
6294 spec
->init_hook
= alc_auto_init_std
;
6302 static const struct hda_codec_preset snd_hda_preset_realtek
[] = {
6303 { .id
= 0x10ec0221, .name
= "ALC221", .patch
= patch_alc269
},
6304 { .id
= 0x10ec0260, .name
= "ALC260", .patch
= patch_alc260
},
6305 { .id
= 0x10ec0262, .name
= "ALC262", .patch
= patch_alc262
},
6306 { .id
= 0x10ec0267, .name
= "ALC267", .patch
= patch_alc268
},
6307 { .id
= 0x10ec0268, .name
= "ALC268", .patch
= patch_alc268
},
6308 { .id
= 0x10ec0269, .name
= "ALC269", .patch
= patch_alc269
},
6309 { .id
= 0x10ec0270, .name
= "ALC270", .patch
= patch_alc269
},
6310 { .id
= 0x10ec0272, .name
= "ALC272", .patch
= patch_alc662
},
6311 { .id
= 0x10ec0275, .name
= "ALC275", .patch
= patch_alc269
},
6312 { .id
= 0x10ec0276, .name
= "ALC276", .patch
= patch_alc269
},
6313 { .id
= 0x10ec0861, .rev
= 0x100340, .name
= "ALC660",
6314 .patch
= patch_alc861
},
6315 { .id
= 0x10ec0660, .name
= "ALC660-VD", .patch
= patch_alc861vd
},
6316 { .id
= 0x10ec0861, .name
= "ALC861", .patch
= patch_alc861
},
6317 { .id
= 0x10ec0862, .name
= "ALC861-VD", .patch
= patch_alc861vd
},
6318 { .id
= 0x10ec0662, .rev
= 0x100002, .name
= "ALC662 rev2",
6319 .patch
= patch_alc882
},
6320 { .id
= 0x10ec0662, .rev
= 0x100101, .name
= "ALC662 rev1",
6321 .patch
= patch_alc662
},
6322 { .id
= 0x10ec0662, .rev
= 0x100300, .name
= "ALC662 rev3",
6323 .patch
= patch_alc662
},
6324 { .id
= 0x10ec0663, .name
= "ALC663", .patch
= patch_alc662
},
6325 { .id
= 0x10ec0665, .name
= "ALC665", .patch
= patch_alc662
},
6326 { .id
= 0x10ec0670, .name
= "ALC670", .patch
= patch_alc662
},
6327 { .id
= 0x10ec0680, .name
= "ALC680", .patch
= patch_alc680
},
6328 { .id
= 0x10ec0880, .name
= "ALC880", .patch
= patch_alc880
},
6329 { .id
= 0x10ec0882, .name
= "ALC882", .patch
= patch_alc882
},
6330 { .id
= 0x10ec0883, .name
= "ALC883", .patch
= patch_alc882
},
6331 { .id
= 0x10ec0885, .rev
= 0x100101, .name
= "ALC889A",
6332 .patch
= patch_alc882
},
6333 { .id
= 0x10ec0885, .rev
= 0x100103, .name
= "ALC889A",
6334 .patch
= patch_alc882
},
6335 { .id
= 0x10ec0885, .name
= "ALC885", .patch
= patch_alc882
},
6336 { .id
= 0x10ec0887, .name
= "ALC887", .patch
= patch_alc882
},
6337 { .id
= 0x10ec0888, .rev
= 0x100101, .name
= "ALC1200",
6338 .patch
= patch_alc882
},
6339 { .id
= 0x10ec0888, .name
= "ALC888", .patch
= patch_alc882
},
6340 { .id
= 0x10ec0889, .name
= "ALC889", .patch
= patch_alc882
},
6341 { .id
= 0x10ec0892, .name
= "ALC892", .patch
= patch_alc662
},
6342 { .id
= 0x10ec0899, .name
= "ALC898", .patch
= patch_alc882
},
6346 MODULE_ALIAS("snd-hda-codec-id:10ec*");
6348 MODULE_LICENSE("GPL");
6349 MODULE_DESCRIPTION("Realtek HD-audio codec");
6351 static struct hda_codec_preset_list realtek_list
= {
6352 .preset
= snd_hda_preset_realtek
,
6353 .owner
= THIS_MODULE
,
6356 static int __init
patch_realtek_init(void)
6358 return snd_hda_add_codec_preset(&realtek_list
);
6361 static void __exit
patch_realtek_exit(void)
6363 snd_hda_delete_codec_preset(&realtek_list
);
6366 module_init(patch_realtek_init
)
6367 module_exit(patch_realtek_exit
)