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 */
84 /* codec parameterization */
85 const struct snd_kcontrol_new
*mixers
[5]; /* mixer arrays */
86 unsigned int num_mixers
;
87 const struct snd_kcontrol_new
*cap_mixer
; /* capture mixer */
88 unsigned int beep_amp
; /* beep amp value, set via set_beep_amp() */
90 const struct hda_verb
*init_verbs
[10]; /* initialization verbs
94 unsigned int num_init_verbs
;
96 char stream_name_analog
[32]; /* analog PCM stream */
97 const struct hda_pcm_stream
*stream_analog_playback
;
98 const struct hda_pcm_stream
*stream_analog_capture
;
99 const struct hda_pcm_stream
*stream_analog_alt_playback
;
100 const struct hda_pcm_stream
*stream_analog_alt_capture
;
102 char stream_name_digital
[32]; /* digital PCM stream */
103 const struct hda_pcm_stream
*stream_digital_playback
;
104 const struct hda_pcm_stream
*stream_digital_capture
;
107 struct hda_multi_out multiout
; /* playback set-up
108 * max_channels, dacs must be set
109 * dig_out_nid and hp_nid are optional
111 hda_nid_t alt_dac_nid
;
112 hda_nid_t slave_dig_outs
[3]; /* optional - for auto-parsing */
116 unsigned int num_adc_nids
;
117 const hda_nid_t
*adc_nids
;
118 const hda_nid_t
*capsrc_nids
;
119 hda_nid_t dig_in_nid
; /* digital-in NID; optional */
120 hda_nid_t mixer_nid
; /* analog-mixer NID */
121 DECLARE_BITMAP(vol_ctls
, 0x20 << 1);
122 DECLARE_BITMAP(sw_ctls
, 0x20 << 1);
124 /* capture setup for dynamic dual-adc switch */
126 unsigned int cur_adc_stream_tag
;
127 unsigned int cur_adc_format
;
130 unsigned int num_mux_defs
;
131 const struct hda_input_mux
*input_mux
;
132 unsigned int cur_mux
[3];
133 hda_nid_t ext_mic_pin
;
134 hda_nid_t dock_mic_pin
;
135 hda_nid_t int_mic_pin
;
138 const struct hda_channel_mode
*channel_mode
;
139 int num_channel_mode
;
141 int const_channel_count
;
142 int ext_channel_count
;
144 /* PCM information */
145 struct hda_pcm pcm_rec
[3]; /* used in alc_build_pcms() */
147 /* dynamic controls, init_verbs and input_mux */
148 struct auto_pin_cfg autocfg
;
149 struct alc_customize_define cdefine
;
150 struct snd_array kctls
;
151 struct hda_input_mux private_imux
[3];
152 hda_nid_t private_dac_nids
[AUTO_CFG_MAX_OUTS
];
153 hda_nid_t private_adc_nids
[AUTO_CFG_MAX_OUTS
];
154 hda_nid_t private_capsrc_nids
[AUTO_CFG_MAX_OUTS
];
155 hda_nid_t imux_pins
[HDA_MAX_NUM_INPUTS
];
156 unsigned int dyn_adc_idx
[HDA_MAX_NUM_INPUTS
];
157 int int_mic_idx
, ext_mic_idx
, dock_mic_idx
; /* for auto-mic */
160 void (*init_hook
)(struct hda_codec
*codec
);
161 void (*unsol_event
)(struct hda_codec
*codec
, unsigned int res
);
162 #ifdef CONFIG_SND_HDA_POWER_SAVE
163 void (*power_hook
)(struct hda_codec
*codec
);
165 void (*shutup
)(struct hda_codec
*codec
);
166 void (*automute_hook
)(struct hda_codec
*codec
);
168 /* for pin sensing */
169 unsigned int hp_jack_present
:1;
170 unsigned int line_jack_present
:1;
171 unsigned int master_mute
:1;
172 unsigned int auto_mic
:1;
173 unsigned int auto_mic_valid_imux
:1; /* valid imux for auto-mic */
174 unsigned int automute_speaker
:1; /* automute speaker outputs */
175 unsigned int automute_lo
:1; /* automute LO outputs */
176 unsigned int detect_hp
:1; /* Headphone detection enabled */
177 unsigned int detect_lo
:1; /* Line-out detection enabled */
178 unsigned int automute_speaker_possible
:1; /* there are speakers and either LO or HP */
179 unsigned int automute_lo_possible
:1; /* there are line outs and HP */
182 unsigned int no_analog
:1; /* digital I/O only */
183 unsigned int dyn_adc_switch
:1; /* switch ADCs (for ALC275) */
184 unsigned int single_input_src
:1;
185 unsigned int vol_in_capsrc
:1; /* use capsrc volume (ADC has no vol) */
186 unsigned int parse_flags
; /* passed to snd_hda_parse_pin_defcfg() */
187 unsigned int shared_mic_hp
:1; /* HP/Mic-in sharing */
188 unsigned int use_jack_tbl
:1; /* 1 for model=auto */
190 /* auto-mute control */
192 hda_nid_t automute_mixer_nid
[AUTO_CFG_MAX_OUTS
];
195 int codec_variant
; /* flag for other variants */
197 /* for virtual master */
198 hda_nid_t vmaster_nid
;
199 #ifdef CONFIG_SND_HDA_POWER_SAVE
200 struct hda_loopback_check loopback
;
205 unsigned int pll_coef_idx
, pll_coef_bit
;
210 const struct alc_fixup
*fixup_list
;
211 const char *fixup_name
;
215 struct alc_multi_io multi_io
[4];
218 struct snd_array bind_ctls
;
221 #define ALC_MODEL_AUTO 0 /* common for all chips */
223 static bool check_amp_caps(struct hda_codec
*codec
, hda_nid_t nid
,
224 int dir
, unsigned int bits
)
228 if (get_wcaps(codec
, nid
) & (1 << (dir
+ 1)))
229 if (query_amp_caps(codec
, nid
, dir
) & bits
)
234 #define nid_has_mute(codec, nid, dir) \
235 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
236 #define nid_has_volume(codec, nid, dir) \
237 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
242 static int alc_mux_enum_info(struct snd_kcontrol
*kcontrol
,
243 struct snd_ctl_elem_info
*uinfo
)
245 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
246 struct alc_spec
*spec
= codec
->spec
;
247 unsigned int mux_idx
= snd_ctl_get_ioffidx(kcontrol
, &uinfo
->id
);
248 if (mux_idx
>= spec
->num_mux_defs
)
250 if (!spec
->input_mux
[mux_idx
].num_items
&& mux_idx
> 0)
252 return snd_hda_input_mux_info(&spec
->input_mux
[mux_idx
], uinfo
);
255 static int alc_mux_enum_get(struct snd_kcontrol
*kcontrol
,
256 struct snd_ctl_elem_value
*ucontrol
)
258 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
259 struct alc_spec
*spec
= codec
->spec
;
260 unsigned int adc_idx
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
262 ucontrol
->value
.enumerated
.item
[0] = spec
->cur_mux
[adc_idx
];
266 static bool alc_dyn_adc_pcm_resetup(struct hda_codec
*codec
, int cur
)
268 struct alc_spec
*spec
= codec
->spec
;
269 hda_nid_t new_adc
= spec
->adc_nids
[spec
->dyn_adc_idx
[cur
]];
271 if (spec
->cur_adc
&& spec
->cur_adc
!= new_adc
) {
272 /* stream is running, let's swap the current ADC */
273 __snd_hda_codec_cleanup_stream(codec
, spec
->cur_adc
, 1);
274 spec
->cur_adc
= new_adc
;
275 snd_hda_codec_setup_stream(codec
, new_adc
,
276 spec
->cur_adc_stream_tag
, 0,
277 spec
->cur_adc_format
);
283 static inline hda_nid_t
get_capsrc(struct alc_spec
*spec
, int idx
)
285 return spec
->capsrc_nids
?
286 spec
->capsrc_nids
[idx
] : spec
->adc_nids
[idx
];
289 static void call_update_outputs(struct hda_codec
*codec
);
291 /* select the given imux item; either unmute exclusively or select the route */
292 static int alc_mux_select(struct hda_codec
*codec
, unsigned int adc_idx
,
293 unsigned int idx
, bool force
)
295 struct alc_spec
*spec
= codec
->spec
;
296 const struct hda_input_mux
*imux
;
297 unsigned int mux_idx
;
298 int i
, type
, num_conns
;
301 mux_idx
= adc_idx
>= spec
->num_mux_defs
? 0 : adc_idx
;
302 imux
= &spec
->input_mux
[mux_idx
];
303 if (!imux
->num_items
&& mux_idx
> 0)
304 imux
= &spec
->input_mux
[0];
305 if (!imux
->num_items
)
308 if (idx
>= imux
->num_items
)
309 idx
= imux
->num_items
- 1;
310 if (spec
->cur_mux
[adc_idx
] == idx
&& !force
)
312 spec
->cur_mux
[adc_idx
] = idx
;
314 /* for shared I/O, change the pin-control accordingly */
315 if (spec
->shared_mic_hp
) {
316 /* NOTE: this assumes that there are only two inputs, the
317 * first is the real internal mic and the second is HP jack.
319 snd_hda_codec_write(codec
, spec
->autocfg
.inputs
[1].pin
, 0,
320 AC_VERB_SET_PIN_WIDGET_CONTROL
,
321 spec
->cur_mux
[adc_idx
] ?
322 PIN_VREF80
: PIN_HP
);
323 spec
->automute_speaker
= !spec
->cur_mux
[adc_idx
];
324 call_update_outputs(codec
);
327 if (spec
->dyn_adc_switch
) {
328 alc_dyn_adc_pcm_resetup(codec
, idx
);
329 adc_idx
= spec
->dyn_adc_idx
[idx
];
332 nid
= get_capsrc(spec
, adc_idx
);
335 num_conns
= snd_hda_get_conn_list(codec
, nid
, NULL
);
339 type
= get_wcaps_type(get_wcaps(codec
, nid
));
340 if (type
== AC_WID_AUD_MIX
) {
341 /* Matrix-mixer style (e.g. ALC882) */
342 int active
= imux
->items
[idx
].index
;
343 for (i
= 0; i
< num_conns
; i
++) {
344 unsigned int v
= (i
== active
) ? 0 : HDA_AMP_MUTE
;
345 snd_hda_codec_amp_stereo(codec
, nid
, HDA_INPUT
, i
,
349 /* MUX style (e.g. ALC880) */
350 snd_hda_codec_write_cache(codec
, nid
, 0,
351 AC_VERB_SET_CONNECT_SEL
,
352 imux
->items
[idx
].index
);
357 static int alc_mux_enum_put(struct snd_kcontrol
*kcontrol
,
358 struct snd_ctl_elem_value
*ucontrol
)
360 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
361 unsigned int adc_idx
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
362 return alc_mux_select(codec
, adc_idx
,
363 ucontrol
->value
.enumerated
.item
[0], false);
367 * set up the input pin config (depending on the given auto-pin type)
369 static void alc_set_input_pin(struct hda_codec
*codec
, hda_nid_t nid
,
372 unsigned int val
= PIN_IN
;
374 if (auto_pin_type
== AUTO_PIN_MIC
) {
377 oldval
= snd_hda_codec_read(codec
, nid
, 0,
378 AC_VERB_GET_PIN_WIDGET_CONTROL
, 0);
379 pincap
= snd_hda_query_pin_caps(codec
, nid
);
380 pincap
= (pincap
& AC_PINCAP_VREF
) >> AC_PINCAP_VREF_SHIFT
;
381 /* if the default pin setup is vref50, we give it priority */
382 if ((pincap
& AC_PINCAP_VREF_80
) && oldval
!= PIN_VREF50
)
384 else if (pincap
& AC_PINCAP_VREF_50
)
386 else if (pincap
& AC_PINCAP_VREF_100
)
388 else if (pincap
& AC_PINCAP_VREF_GRD
)
391 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_PIN_WIDGET_CONTROL
, val
);
395 * Append the given mixer and verb elements for the later use
396 * The mixer array is referred in build_controls(), and init_verbs are
399 static void add_mixer(struct alc_spec
*spec
, const struct snd_kcontrol_new
*mix
)
401 if (snd_BUG_ON(spec
->num_mixers
>= ARRAY_SIZE(spec
->mixers
)))
403 spec
->mixers
[spec
->num_mixers
++] = mix
;
406 static void add_verb(struct alc_spec
*spec
, const struct hda_verb
*verb
)
408 if (snd_BUG_ON(spec
->num_init_verbs
>= ARRAY_SIZE(spec
->init_verbs
)))
410 spec
->init_verbs
[spec
->num_init_verbs
++] = verb
;
414 * GPIO setup tables, used in initialization
416 /* Enable GPIO mask and set output */
417 static const struct hda_verb alc_gpio1_init_verbs
[] = {
418 {0x01, AC_VERB_SET_GPIO_MASK
, 0x01},
419 {0x01, AC_VERB_SET_GPIO_DIRECTION
, 0x01},
420 {0x01, AC_VERB_SET_GPIO_DATA
, 0x01},
424 static const struct hda_verb alc_gpio2_init_verbs
[] = {
425 {0x01, AC_VERB_SET_GPIO_MASK
, 0x02},
426 {0x01, AC_VERB_SET_GPIO_DIRECTION
, 0x02},
427 {0x01, AC_VERB_SET_GPIO_DATA
, 0x02},
431 static const struct hda_verb alc_gpio3_init_verbs
[] = {
432 {0x01, AC_VERB_SET_GPIO_MASK
, 0x03},
433 {0x01, AC_VERB_SET_GPIO_DIRECTION
, 0x03},
434 {0x01, AC_VERB_SET_GPIO_DATA
, 0x03},
439 * Fix hardware PLL issue
440 * On some codecs, the analog PLL gating control must be off while
441 * the default value is 1.
443 static void alc_fix_pll(struct hda_codec
*codec
)
445 struct alc_spec
*spec
= codec
->spec
;
450 snd_hda_codec_write(codec
, spec
->pll_nid
, 0, AC_VERB_SET_COEF_INDEX
,
452 val
= snd_hda_codec_read(codec
, spec
->pll_nid
, 0,
453 AC_VERB_GET_PROC_COEF
, 0);
454 snd_hda_codec_write(codec
, spec
->pll_nid
, 0, AC_VERB_SET_COEF_INDEX
,
456 snd_hda_codec_write(codec
, spec
->pll_nid
, 0, AC_VERB_SET_PROC_COEF
,
457 val
& ~(1 << spec
->pll_coef_bit
));
460 static void alc_fix_pll_init(struct hda_codec
*codec
, hda_nid_t nid
,
461 unsigned int coef_idx
, unsigned int coef_bit
)
463 struct alc_spec
*spec
= codec
->spec
;
465 spec
->pll_coef_idx
= coef_idx
;
466 spec
->pll_coef_bit
= coef_bit
;
471 * Jack detections for HP auto-mute and mic-switch
474 /* check each pin in the given array; returns true if any of them is plugged */
475 static bool detect_jacks(struct hda_codec
*codec
, int num_pins
, hda_nid_t
*pins
)
479 for (i
= 0; i
< num_pins
; i
++) {
480 hda_nid_t nid
= pins
[i
];
483 present
|= snd_hda_jack_detect(codec
, nid
);
488 /* standard HP/line-out auto-mute helper */
489 static void do_automute(struct hda_codec
*codec
, int num_pins
, hda_nid_t
*pins
,
490 bool mute
, bool hp_out
)
492 struct alc_spec
*spec
= codec
->spec
;
493 unsigned int mute_bits
= mute
? HDA_AMP_MUTE
: 0;
494 unsigned int pin_bits
= mute
? 0 : (hp_out
? PIN_HP
: PIN_OUT
);
497 for (i
= 0; i
< num_pins
; i
++) {
498 hda_nid_t nid
= pins
[i
];
501 switch (spec
->automute_mode
) {
502 case ALC_AUTOMUTE_PIN
:
503 snd_hda_codec_write(codec
, nid
, 0,
504 AC_VERB_SET_PIN_WIDGET_CONTROL
,
507 case ALC_AUTOMUTE_AMP
:
508 snd_hda_codec_amp_stereo(codec
, nid
, HDA_OUTPUT
, 0,
509 HDA_AMP_MUTE
, mute_bits
);
511 case ALC_AUTOMUTE_MIXER
:
512 nid
= spec
->automute_mixer_nid
[i
];
515 snd_hda_codec_amp_stereo(codec
, nid
, HDA_INPUT
, 0,
516 HDA_AMP_MUTE
, mute_bits
);
517 snd_hda_codec_amp_stereo(codec
, nid
, HDA_INPUT
, 1,
518 HDA_AMP_MUTE
, mute_bits
);
524 /* Toggle outputs muting */
525 static void update_outputs(struct hda_codec
*codec
)
527 struct alc_spec
*spec
= codec
->spec
;
530 /* Control HP pins/amps depending on master_mute state;
531 * in general, HP pins/amps control should be enabled in all cases,
532 * but currently set only for master_mute, just to be safe
534 if (!spec
->shared_mic_hp
) /* don't change HP-pin when shared with mic */
535 do_automute(codec
, ARRAY_SIZE(spec
->autocfg
.hp_pins
),
536 spec
->autocfg
.hp_pins
, spec
->master_mute
, true);
538 if (!spec
->automute_speaker
)
541 on
= spec
->hp_jack_present
| spec
->line_jack_present
;
542 on
|= spec
->master_mute
;
543 do_automute(codec
, ARRAY_SIZE(spec
->autocfg
.speaker_pins
),
544 spec
->autocfg
.speaker_pins
, on
, false);
546 /* toggle line-out mutes if needed, too */
547 /* if LO is a copy of either HP or Speaker, don't need to handle it */
548 if (spec
->autocfg
.line_out_pins
[0] == spec
->autocfg
.hp_pins
[0] ||
549 spec
->autocfg
.line_out_pins
[0] == spec
->autocfg
.speaker_pins
[0])
551 if (!spec
->automute_lo
)
554 on
= spec
->hp_jack_present
;
555 on
|= spec
->master_mute
;
556 do_automute(codec
, ARRAY_SIZE(spec
->autocfg
.line_out_pins
),
557 spec
->autocfg
.line_out_pins
, on
, false);
560 static void call_update_outputs(struct hda_codec
*codec
)
562 struct alc_spec
*spec
= codec
->spec
;
563 if (spec
->automute_hook
)
564 spec
->automute_hook(codec
);
566 update_outputs(codec
);
569 /* standard HP-automute helper */
570 static void alc_hp_automute(struct hda_codec
*codec
)
572 struct alc_spec
*spec
= codec
->spec
;
574 spec
->hp_jack_present
=
575 detect_jacks(codec
, ARRAY_SIZE(spec
->autocfg
.hp_pins
),
576 spec
->autocfg
.hp_pins
);
577 if (!spec
->detect_hp
|| (!spec
->automute_speaker
&& !spec
->automute_lo
))
579 call_update_outputs(codec
);
582 /* standard line-out-automute helper */
583 static void alc_line_automute(struct hda_codec
*codec
)
585 struct alc_spec
*spec
= codec
->spec
;
587 /* check LO jack only when it's different from HP */
588 if (spec
->autocfg
.line_out_pins
[0] == spec
->autocfg
.hp_pins
[0])
591 spec
->line_jack_present
=
592 detect_jacks(codec
, ARRAY_SIZE(spec
->autocfg
.line_out_pins
),
593 spec
->autocfg
.line_out_pins
);
594 if (!spec
->automute_speaker
|| !spec
->detect_lo
)
596 call_update_outputs(codec
);
599 #define get_connection_index(codec, mux, nid) \
600 snd_hda_get_conn_index(codec, mux, nid, 0)
602 /* standard mic auto-switch helper */
603 static void alc_mic_automute(struct hda_codec
*codec
)
605 struct alc_spec
*spec
= codec
->spec
;
606 hda_nid_t
*pins
= spec
->imux_pins
;
608 if (!spec
->auto_mic
|| !spec
->auto_mic_valid_imux
)
610 if (snd_BUG_ON(!spec
->adc_nids
))
612 if (snd_BUG_ON(spec
->int_mic_idx
< 0 || spec
->ext_mic_idx
< 0))
615 if (snd_hda_jack_detect(codec
, pins
[spec
->ext_mic_idx
]))
616 alc_mux_select(codec
, 0, spec
->ext_mic_idx
, false);
617 else if (spec
->dock_mic_idx
>= 0 &&
618 snd_hda_jack_detect(codec
, pins
[spec
->dock_mic_idx
]))
619 alc_mux_select(codec
, 0, spec
->dock_mic_idx
, false);
621 alc_mux_select(codec
, 0, spec
->int_mic_idx
, false);
624 /* unsolicited event for HP jack sensing */
625 static void alc_sku_unsol_event(struct hda_codec
*codec
, unsigned int res
)
627 struct alc_spec
*spec
= codec
->spec
;
628 if (codec
->vendor_id
== 0x10ec0880)
632 if (spec
->use_jack_tbl
)
633 res
= snd_hda_jack_get_action(codec
, res
);
636 alc_hp_automute(codec
);
638 case ALC_FRONT_EVENT
:
639 alc_line_automute(codec
);
642 alc_mic_automute(codec
);
645 snd_hda_jack_report_sync(codec
);
648 /* call init functions of standard auto-mute helpers */
649 static void alc_inithook(struct hda_codec
*codec
)
651 alc_hp_automute(codec
);
652 alc_line_automute(codec
);
653 alc_mic_automute(codec
);
656 /* additional initialization for ALC888 variants */
657 static void alc888_coef_init(struct hda_codec
*codec
)
661 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_COEF_INDEX
, 0);
662 tmp
= snd_hda_codec_read(codec
, 0x20, 0, AC_VERB_GET_PROC_COEF
, 0);
663 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_COEF_INDEX
, 7);
664 if ((tmp
& 0xf0) == 0x20)
666 snd_hda_codec_read(codec
, 0x20, 0,
667 AC_VERB_SET_PROC_COEF
, 0x830);
670 snd_hda_codec_read(codec
, 0x20, 0,
671 AC_VERB_SET_PROC_COEF
, 0x3030);
674 /* additional initialization for ALC889 variants */
675 static void alc889_coef_init(struct hda_codec
*codec
)
679 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_COEF_INDEX
, 7);
680 tmp
= snd_hda_codec_read(codec
, 0x20, 0, AC_VERB_GET_PROC_COEF
, 0);
681 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_COEF_INDEX
, 7);
682 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_PROC_COEF
, tmp
|0x2010);
685 /* turn on/off EAPD control (only if available) */
686 static void set_eapd(struct hda_codec
*codec
, hda_nid_t nid
, int on
)
688 if (get_wcaps_type(get_wcaps(codec
, nid
)) != AC_WID_PIN
)
690 if (snd_hda_query_pin_caps(codec
, nid
) & AC_PINCAP_EAPD
)
691 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_EAPD_BTLENABLE
,
695 /* turn on/off EAPD controls of the codec */
696 static void alc_auto_setup_eapd(struct hda_codec
*codec
, bool on
)
698 /* We currently only handle front, HP */
699 static hda_nid_t pins
[] = {
700 0x0f, 0x10, 0x14, 0x15, 0
703 for (p
= pins
; *p
; p
++)
704 set_eapd(codec
, *p
, on
);
707 /* generic shutup callback;
708 * just turning off EPAD and a little pause for avoiding pop-noise
710 static void alc_eapd_shutup(struct hda_codec
*codec
)
712 alc_auto_setup_eapd(codec
, false);
716 /* generic EAPD initialization */
717 static void alc_auto_init_amp(struct hda_codec
*codec
, int type
)
721 alc_auto_setup_eapd(codec
, true);
724 snd_hda_sequence_write(codec
, alc_gpio1_init_verbs
);
727 snd_hda_sequence_write(codec
, alc_gpio2_init_verbs
);
730 snd_hda_sequence_write(codec
, alc_gpio3_init_verbs
);
732 case ALC_INIT_DEFAULT
:
733 switch (codec
->vendor_id
) {
735 snd_hda_codec_write(codec
, 0x1a, 0,
736 AC_VERB_SET_COEF_INDEX
, 7);
737 tmp
= snd_hda_codec_read(codec
, 0x1a, 0,
738 AC_VERB_GET_PROC_COEF
, 0);
739 snd_hda_codec_write(codec
, 0x1a, 0,
740 AC_VERB_SET_COEF_INDEX
, 7);
741 snd_hda_codec_write(codec
, 0x1a, 0,
742 AC_VERB_SET_PROC_COEF
,
751 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
752 alc889_coef_init(codec
);
755 alc888_coef_init(codec
);
757 #if 0 /* XXX: This may cause the silent output on speaker on some machines */
760 snd_hda_codec_write(codec
, 0x20, 0,
761 AC_VERB_SET_COEF_INDEX
, 7);
762 tmp
= snd_hda_codec_read(codec
, 0x20, 0,
763 AC_VERB_GET_PROC_COEF
, 0);
764 snd_hda_codec_write(codec
, 0x20, 0,
765 AC_VERB_SET_COEF_INDEX
, 7);
766 snd_hda_codec_write(codec
, 0x20, 0,
767 AC_VERB_SET_PROC_COEF
,
777 * Auto-Mute mode mixer enum support
779 static int alc_automute_mode_info(struct snd_kcontrol
*kcontrol
,
780 struct snd_ctl_elem_info
*uinfo
)
782 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
783 struct alc_spec
*spec
= codec
->spec
;
784 static const char * const texts2
[] = {
785 "Disabled", "Enabled"
787 static const char * const texts3
[] = {
788 "Disabled", "Speaker Only", "Line-Out+Speaker"
790 const char * const *texts
;
792 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
794 if (spec
->automute_speaker_possible
&& spec
->automute_lo_possible
) {
795 uinfo
->value
.enumerated
.items
= 3;
798 uinfo
->value
.enumerated
.items
= 2;
801 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
)
802 uinfo
->value
.enumerated
.item
= uinfo
->value
.enumerated
.items
- 1;
803 strcpy(uinfo
->value
.enumerated
.name
,
804 texts
[uinfo
->value
.enumerated
.item
]);
808 static int alc_automute_mode_get(struct snd_kcontrol
*kcontrol
,
809 struct snd_ctl_elem_value
*ucontrol
)
811 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
812 struct alc_spec
*spec
= codec
->spec
;
813 unsigned int val
= 0;
814 if (spec
->automute_speaker
)
816 if (spec
->automute_lo
)
819 ucontrol
->value
.enumerated
.item
[0] = val
;
823 static int alc_automute_mode_put(struct snd_kcontrol
*kcontrol
,
824 struct snd_ctl_elem_value
*ucontrol
)
826 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
827 struct alc_spec
*spec
= codec
->spec
;
829 switch (ucontrol
->value
.enumerated
.item
[0]) {
831 if (!spec
->automute_speaker
&& !spec
->automute_lo
)
833 spec
->automute_speaker
= 0;
834 spec
->automute_lo
= 0;
837 if (spec
->automute_speaker_possible
) {
838 if (!spec
->automute_lo
&& spec
->automute_speaker
)
840 spec
->automute_speaker
= 1;
841 spec
->automute_lo
= 0;
842 } else if (spec
->automute_lo_possible
) {
843 if (spec
->automute_lo
)
845 spec
->automute_lo
= 1;
850 if (!spec
->automute_lo_possible
|| !spec
->automute_speaker_possible
)
852 if (spec
->automute_speaker
&& spec
->automute_lo
)
854 spec
->automute_speaker
= 1;
855 spec
->automute_lo
= 1;
860 call_update_outputs(codec
);
864 static const struct snd_kcontrol_new alc_automute_mode_enum
= {
865 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
866 .name
= "Auto-Mute Mode",
867 .info
= alc_automute_mode_info
,
868 .get
= alc_automute_mode_get
,
869 .put
= alc_automute_mode_put
,
872 static struct snd_kcontrol_new
*alc_kcontrol_new(struct alc_spec
*spec
)
874 snd_array_init(&spec
->kctls
, sizeof(struct snd_kcontrol_new
), 32);
875 return snd_array_new(&spec
->kctls
);
878 static int alc_add_automute_mode_enum(struct hda_codec
*codec
)
880 struct alc_spec
*spec
= codec
->spec
;
881 struct snd_kcontrol_new
*knew
;
883 knew
= alc_kcontrol_new(spec
);
886 *knew
= alc_automute_mode_enum
;
887 knew
->name
= kstrdup("Auto-Mute Mode", GFP_KERNEL
);
894 * Check the availability of HP/line-out auto-mute;
895 * Set up appropriately if really supported
897 static void alc_init_automute(struct hda_codec
*codec
)
899 struct alc_spec
*spec
= codec
->spec
;
900 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
906 if (cfg
->line_out_pins
[0])
908 if (cfg
->speaker_pins
[0])
910 if (present
< 2) /* need two different output types */
913 if (!cfg
->speaker_pins
[0] &&
914 cfg
->line_out_type
== AUTO_PIN_SPEAKER_OUT
) {
915 memcpy(cfg
->speaker_pins
, cfg
->line_out_pins
,
916 sizeof(cfg
->speaker_pins
));
917 cfg
->speaker_outs
= cfg
->line_outs
;
920 if (!cfg
->hp_pins
[0] &&
921 cfg
->line_out_type
== AUTO_PIN_HP_OUT
) {
922 memcpy(cfg
->hp_pins
, cfg
->line_out_pins
,
923 sizeof(cfg
->hp_pins
));
924 cfg
->hp_outs
= cfg
->line_outs
;
927 spec
->automute_mode
= ALC_AUTOMUTE_PIN
;
929 for (i
= 0; i
< cfg
->hp_outs
; i
++) {
930 hda_nid_t nid
= cfg
->hp_pins
[i
];
931 if (!is_jack_detectable(codec
, nid
))
933 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
935 snd_hda_jack_detect_enable(codec
, nid
, ALC_HP_EVENT
);
939 if (cfg
->line_out_type
== AUTO_PIN_LINE_OUT
&& cfg
->line_outs
) {
940 if (cfg
->speaker_outs
)
941 for (i
= 0; i
< cfg
->line_outs
; i
++) {
942 hda_nid_t nid
= cfg
->line_out_pins
[i
];
943 if (!is_jack_detectable(codec
, nid
))
945 snd_printdd("realtek: Enable Line-Out "
946 "auto-muting on NID 0x%x\n", nid
);
947 snd_hda_jack_detect_enable(codec
, nid
,
951 spec
->automute_lo_possible
= spec
->detect_hp
;
954 spec
->automute_speaker_possible
= cfg
->speaker_outs
&&
955 (spec
->detect_hp
|| spec
->detect_lo
);
957 spec
->automute_lo
= spec
->automute_lo_possible
;
958 spec
->automute_speaker
= spec
->automute_speaker_possible
;
960 if (spec
->automute_speaker_possible
|| spec
->automute_lo_possible
) {
961 /* create a control for automute mode */
962 alc_add_automute_mode_enum(codec
);
963 spec
->unsol_event
= alc_sku_unsol_event
;
967 /* return the position of NID in the list, or -1 if not found */
968 static int find_idx_in_nid_list(hda_nid_t nid
, const hda_nid_t
*list
, int nums
)
971 for (i
= 0; i
< nums
; i
++)
977 /* check whether dynamic ADC-switching is available */
978 static bool alc_check_dyn_adc_switch(struct hda_codec
*codec
)
980 struct alc_spec
*spec
= codec
->spec
;
981 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
985 if (imux
!= spec
->input_mux
) /* no dynamic imux? */
988 for (n
= 0; n
< spec
->num_adc_nids
; n
++) {
989 cap
= spec
->private_capsrc_nids
[n
];
990 for (i
= 0; i
< imux
->num_items
; i
++) {
991 pin
= spec
->imux_pins
[i
];
994 if (get_connection_index(codec
, cap
, pin
) < 0)
997 if (i
>= imux
->num_items
)
998 return true; /* no ADC-switch is needed */
1001 for (i
= 0; i
< imux
->num_items
; i
++) {
1002 pin
= spec
->imux_pins
[i
];
1003 for (n
= 0; n
< spec
->num_adc_nids
; n
++) {
1004 cap
= spec
->private_capsrc_nids
[n
];
1005 idx
= get_connection_index(codec
, cap
, pin
);
1007 imux
->items
[i
].index
= idx
;
1008 spec
->dyn_adc_idx
[i
] = n
;
1014 snd_printdd("realtek: enabling ADC switching\n");
1015 spec
->dyn_adc_switch
= 1;
1019 /* rebuild imux for matching with the given auto-mic pins (if not yet) */
1020 static bool alc_rebuild_imux_for_auto_mic(struct hda_codec
*codec
)
1022 struct alc_spec
*spec
= codec
->spec
;
1023 struct hda_input_mux
*imux
;
1024 static char * const texts
[3] = {
1025 "Mic", "Internal Mic", "Dock Mic"
1029 if (!spec
->auto_mic
)
1031 imux
= &spec
->private_imux
[0];
1032 if (spec
->input_mux
== imux
)
1034 spec
->imux_pins
[0] = spec
->ext_mic_pin
;
1035 spec
->imux_pins
[1] = spec
->int_mic_pin
;
1036 spec
->imux_pins
[2] = spec
->dock_mic_pin
;
1037 for (i
= 0; i
< 3; i
++) {
1038 strcpy(imux
->items
[i
].label
, texts
[i
]);
1039 if (spec
->imux_pins
[i
]) {
1040 hda_nid_t pin
= spec
->imux_pins
[i
];
1042 for (c
= 0; c
< spec
->num_adc_nids
; c
++) {
1043 hda_nid_t cap
= get_capsrc(spec
, c
);
1044 int idx
= get_connection_index(codec
, cap
, pin
);
1046 imux
->items
[i
].index
= idx
;
1050 imux
->num_items
= i
+ 1;
1053 spec
->num_mux_defs
= 1;
1054 spec
->input_mux
= imux
;
1058 /* check whether all auto-mic pins are valid; setup indices if OK */
1059 static bool alc_auto_mic_check_imux(struct hda_codec
*codec
)
1061 struct alc_spec
*spec
= codec
->spec
;
1062 const struct hda_input_mux
*imux
;
1064 if (!spec
->auto_mic
)
1066 if (spec
->auto_mic_valid_imux
)
1067 return true; /* already checked */
1069 /* fill up imux indices */
1070 if (!alc_check_dyn_adc_switch(codec
)) {
1075 imux
= spec
->input_mux
;
1076 spec
->ext_mic_idx
= find_idx_in_nid_list(spec
->ext_mic_pin
,
1077 spec
->imux_pins
, imux
->num_items
);
1078 spec
->int_mic_idx
= find_idx_in_nid_list(spec
->int_mic_pin
,
1079 spec
->imux_pins
, imux
->num_items
);
1080 spec
->dock_mic_idx
= find_idx_in_nid_list(spec
->dock_mic_pin
,
1081 spec
->imux_pins
, imux
->num_items
);
1082 if (spec
->ext_mic_idx
< 0 || spec
->int_mic_idx
< 0) {
1084 return false; /* no corresponding imux */
1087 snd_hda_jack_detect_enable(codec
, spec
->ext_mic_pin
, ALC_MIC_EVENT
);
1088 if (spec
->dock_mic_pin
)
1089 snd_hda_jack_detect_enable(codec
, spec
->dock_mic_pin
,
1092 spec
->auto_mic_valid_imux
= 1;
1098 * Check the availability of auto-mic switch;
1099 * Set up if really supported
1101 static void alc_init_auto_mic(struct hda_codec
*codec
)
1103 struct alc_spec
*spec
= codec
->spec
;
1104 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
1105 hda_nid_t fixed
, ext
, dock
;
1108 if (spec
->shared_mic_hp
)
1109 return; /* no auto-mic for the shared I/O */
1111 spec
->ext_mic_idx
= spec
->int_mic_idx
= spec
->dock_mic_idx
= -1;
1113 fixed
= ext
= dock
= 0;
1114 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
1115 hda_nid_t nid
= cfg
->inputs
[i
].pin
;
1116 unsigned int defcfg
;
1117 defcfg
= snd_hda_codec_get_pincfg(codec
, nid
);
1118 switch (snd_hda_get_input_pin_attr(defcfg
)) {
1119 case INPUT_PIN_ATTR_INT
:
1121 return; /* already occupied */
1122 if (cfg
->inputs
[i
].type
!= AUTO_PIN_MIC
)
1123 return; /* invalid type */
1126 case INPUT_PIN_ATTR_UNUSED
:
1127 return; /* invalid entry */
1128 case INPUT_PIN_ATTR_DOCK
:
1130 return; /* already occupied */
1131 if (cfg
->inputs
[i
].type
> AUTO_PIN_LINE_IN
)
1132 return; /* invalid type */
1137 return; /* already occupied */
1138 if (cfg
->inputs
[i
].type
!= AUTO_PIN_MIC
)
1139 return; /* invalid type */
1150 if (!is_jack_detectable(codec
, ext
))
1151 return; /* no unsol support */
1152 if (dock
&& !is_jack_detectable(codec
, dock
))
1153 return; /* no unsol support */
1155 /* check imux indices */
1156 spec
->ext_mic_pin
= ext
;
1157 spec
->int_mic_pin
= fixed
;
1158 spec
->dock_mic_pin
= dock
;
1161 if (!alc_auto_mic_check_imux(codec
))
1164 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1166 spec
->unsol_event
= alc_sku_unsol_event
;
1169 /* check the availabilities of auto-mute and auto-mic switches */
1170 static void alc_auto_check_switches(struct hda_codec
*codec
)
1172 alc_init_automute(codec
);
1173 alc_init_auto_mic(codec
);
1177 * Realtek SSID verification
1180 /* Could be any non-zero and even value. When used as fixup, tells
1181 * the driver to ignore any present sku defines.
1183 #define ALC_FIXUP_SKU_IGNORE (2)
1185 static int alc_auto_parse_customize_define(struct hda_codec
*codec
)
1187 unsigned int ass
, tmp
, i
;
1189 struct alc_spec
*spec
= codec
->spec
;
1191 spec
->cdefine
.enable_pcbeep
= 1; /* assume always enabled */
1193 if (spec
->cdefine
.fixup
) {
1194 ass
= spec
->cdefine
.sku_cfg
;
1195 if (ass
== ALC_FIXUP_SKU_IGNORE
)
1200 ass
= codec
->subsystem_id
& 0xffff;
1201 if (ass
!= codec
->bus
->pci
->subsystem_device
&& (ass
& 1))
1205 if (codec
->vendor_id
== 0x10ec0260)
1207 ass
= snd_hda_codec_get_pincfg(codec
, nid
);
1210 printk(KERN_INFO
"hda_codec: %s: SKU not ready 0x%08x\n",
1211 codec
->chip_name
, ass
);
1217 for (i
= 1; i
< 16; i
++) {
1221 if (((ass
>> 16) & 0xf) != tmp
)
1224 spec
->cdefine
.port_connectivity
= ass
>> 30;
1225 spec
->cdefine
.enable_pcbeep
= (ass
& 0x100000) >> 20;
1226 spec
->cdefine
.check_sum
= (ass
>> 16) & 0xf;
1227 spec
->cdefine
.customization
= ass
>> 8;
1229 spec
->cdefine
.sku_cfg
= ass
;
1230 spec
->cdefine
.external_amp
= (ass
& 0x38) >> 3;
1231 spec
->cdefine
.platform_type
= (ass
& 0x4) >> 2;
1232 spec
->cdefine
.swap
= (ass
& 0x2) >> 1;
1233 spec
->cdefine
.override
= ass
& 0x1;
1235 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1236 nid
, spec
->cdefine
.sku_cfg
);
1237 snd_printd("SKU: port_connectivity=0x%x\n",
1238 spec
->cdefine
.port_connectivity
);
1239 snd_printd("SKU: enable_pcbeep=0x%x\n", spec
->cdefine
.enable_pcbeep
);
1240 snd_printd("SKU: check_sum=0x%08x\n", spec
->cdefine
.check_sum
);
1241 snd_printd("SKU: customization=0x%08x\n", spec
->cdefine
.customization
);
1242 snd_printd("SKU: external_amp=0x%x\n", spec
->cdefine
.external_amp
);
1243 snd_printd("SKU: platform_type=0x%x\n", spec
->cdefine
.platform_type
);
1244 snd_printd("SKU: swap=0x%x\n", spec
->cdefine
.swap
);
1245 snd_printd("SKU: override=0x%x\n", spec
->cdefine
.override
);
1250 /* return true if the given NID is found in the list */
1251 static bool found_in_nid_list(hda_nid_t nid
, const hda_nid_t
*list
, int nums
)
1253 return find_idx_in_nid_list(nid
, list
, nums
) >= 0;
1256 /* check subsystem ID and set up device-specific initialization;
1257 * return 1 if initialized, 0 if invalid SSID
1259 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1260 * 31 ~ 16 : Manufacture ID
1262 * 7 ~ 0 : Assembly ID
1263 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1265 static int alc_subsystem_id(struct hda_codec
*codec
,
1266 hda_nid_t porta
, hda_nid_t porte
,
1267 hda_nid_t portd
, hda_nid_t porti
)
1269 unsigned int ass
, tmp
, i
;
1271 struct alc_spec
*spec
= codec
->spec
;
1273 if (spec
->cdefine
.fixup
) {
1274 ass
= spec
->cdefine
.sku_cfg
;
1275 if (ass
== ALC_FIXUP_SKU_IGNORE
)
1280 ass
= codec
->subsystem_id
& 0xffff;
1281 if ((ass
!= codec
->bus
->pci
->subsystem_device
) && (ass
& 1))
1284 /* invalid SSID, check the special NID pin defcfg instead */
1286 * 31~30 : port connectivity
1289 * 19~16 : Check sum (15:1)
1294 if (codec
->vendor_id
== 0x10ec0260)
1296 ass
= snd_hda_codec_get_pincfg(codec
, nid
);
1297 snd_printd("realtek: No valid SSID, "
1298 "checking pincfg 0x%08x for NID 0x%x\n",
1302 if ((ass
>> 30) != 1) /* no physical connection */
1307 for (i
= 1; i
< 16; i
++) {
1311 if (((ass
>> 16) & 0xf) != tmp
)
1314 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1315 ass
& 0xffff, codec
->vendor_id
);
1319 * 2 : 0 --> Desktop, 1 --> Laptop
1320 * 3~5 : External Amplifier control
1323 tmp
= (ass
& 0x38) >> 3; /* external Amp control */
1326 spec
->init_amp
= ALC_INIT_GPIO1
;
1329 spec
->init_amp
= ALC_INIT_GPIO2
;
1332 spec
->init_amp
= ALC_INIT_GPIO3
;
1336 spec
->init_amp
= ALC_INIT_DEFAULT
;
1340 /* is laptop or Desktop and enable the function "Mute internal speaker
1341 * when the external headphone out jack is plugged"
1343 if (!(ass
& 0x8000))
1346 * 10~8 : Jack location
1347 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1349 * 15 : 1 --> enable the function "Mute internal speaker
1350 * when the external headphone out jack is plugged"
1352 if (!spec
->autocfg
.hp_pins
[0] &&
1353 !(spec
->autocfg
.line_out_pins
[0] &&
1354 spec
->autocfg
.line_out_type
== AUTO_PIN_HP_OUT
)) {
1356 tmp
= (ass
>> 11) & 0x3; /* HP to chassis */
1367 if (found_in_nid_list(nid
, spec
->autocfg
.line_out_pins
,
1368 spec
->autocfg
.line_outs
))
1370 spec
->autocfg
.hp_pins
[0] = nid
;
1375 /* Check the validity of ALC subsystem-id
1376 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1377 static void alc_ssid_check(struct hda_codec
*codec
, const hda_nid_t
*ports
)
1379 if (!alc_subsystem_id(codec
, ports
[0], ports
[1], ports
[2], ports
[3])) {
1380 struct alc_spec
*spec
= codec
->spec
;
1381 snd_printd("realtek: "
1382 "Enable default setup for auto mode as fallback\n");
1383 spec
->init_amp
= ALC_INIT_DEFAULT
;
1388 * Fix-up pin default configurations and add default verbs
1396 struct alc_model_fixup
{
1407 const struct alc_pincfg
*pins
;
1408 const struct hda_verb
*verbs
;
1409 void (*func
)(struct hda_codec
*codec
,
1410 const struct alc_fixup
*fix
,
1424 ALC_FIXUP_ACT_PRE_PROBE
,
1425 ALC_FIXUP_ACT_PROBE
,
1429 static void alc_apply_fixup(struct hda_codec
*codec
, int action
)
1431 struct alc_spec
*spec
= codec
->spec
;
1432 int id
= spec
->fixup_id
;
1433 #ifdef CONFIG_SND_DEBUG_VERBOSE
1434 const char *modelname
= spec
->fixup_name
;
1438 if (!spec
->fixup_list
)
1442 const struct alc_fixup
*fix
= spec
->fixup_list
+ id
;
1443 const struct alc_pincfg
*cfg
;
1445 switch (fix
->type
) {
1447 if (action
!= ALC_FIXUP_ACT_PRE_PROBE
|| !fix
->v
.sku
)
1449 snd_printdd(KERN_INFO
"hda_codec: %s: "
1450 "Apply sku override for %s\n",
1451 codec
->chip_name
, modelname
);
1452 spec
->cdefine
.sku_cfg
= fix
->v
.sku
;
1453 spec
->cdefine
.fixup
= 1;
1455 case ALC_FIXUP_PINS
:
1457 if (action
!= ALC_FIXUP_ACT_PRE_PROBE
|| !cfg
)
1459 snd_printdd(KERN_INFO
"hda_codec: %s: "
1460 "Apply pincfg for %s\n",
1461 codec
->chip_name
, modelname
);
1462 for (; cfg
->nid
; cfg
++)
1463 snd_hda_codec_set_pincfg(codec
, cfg
->nid
,
1466 case ALC_FIXUP_VERBS
:
1467 if (action
!= ALC_FIXUP_ACT_PROBE
|| !fix
->v
.verbs
)
1469 snd_printdd(KERN_INFO
"hda_codec: %s: "
1470 "Apply fix-verbs for %s\n",
1471 codec
->chip_name
, modelname
);
1472 add_verb(codec
->spec
, fix
->v
.verbs
);
1474 case ALC_FIXUP_FUNC
:
1477 snd_printdd(KERN_INFO
"hda_codec: %s: "
1478 "Apply fix-func for %s\n",
1479 codec
->chip_name
, modelname
);
1480 fix
->v
.func(codec
, fix
, action
);
1483 snd_printk(KERN_ERR
"hda_codec: %s: "
1484 "Invalid fixup type %d\n",
1485 codec
->chip_name
, fix
->type
);
1496 static void alc_pick_fixup(struct hda_codec
*codec
,
1497 const struct alc_model_fixup
*models
,
1498 const struct snd_pci_quirk
*quirk
,
1499 const struct alc_fixup
*fixlist
)
1501 struct alc_spec
*spec
= codec
->spec
;
1502 const struct snd_pci_quirk
*q
;
1504 const char *name
= NULL
;
1506 if (codec
->modelname
&& models
) {
1507 while (models
->name
) {
1508 if (!strcmp(codec
->modelname
, models
->name
)) {
1510 name
= models
->name
;
1517 q
= snd_pci_quirk_lookup(codec
->bus
->pci
, quirk
);
1520 #ifdef CONFIG_SND_DEBUG_VERBOSE
1526 for (q
= quirk
; q
->subvendor
; q
++) {
1527 unsigned int vendorid
=
1528 q
->subdevice
| (q
->subvendor
<< 16);
1529 if (vendorid
== codec
->subsystem_id
) {
1531 #ifdef CONFIG_SND_DEBUG_VERBOSE
1539 spec
->fixup_id
= id
;
1541 spec
->fixup_list
= fixlist
;
1542 spec
->fixup_name
= name
;
1547 * COEF access helper functions
1549 static int alc_read_coef_idx(struct hda_codec
*codec
,
1550 unsigned int coef_idx
)
1553 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_COEF_INDEX
,
1555 val
= snd_hda_codec_read(codec
, 0x20, 0,
1556 AC_VERB_GET_PROC_COEF
, 0);
1560 static void alc_write_coef_idx(struct hda_codec
*codec
, unsigned int coef_idx
,
1561 unsigned int coef_val
)
1563 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_COEF_INDEX
,
1565 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_PROC_COEF
,
1569 /* a special bypass for COEF 0; read the cached value at the second time */
1570 static unsigned int alc_get_coef0(struct hda_codec
*codec
)
1572 struct alc_spec
*spec
= codec
->spec
;
1574 spec
->coef0
= alc_read_coef_idx(codec
, 0);
1579 * Digital I/O handling
1582 /* set right pin controls for digital I/O */
1583 static void alc_auto_init_digital(struct hda_codec
*codec
)
1585 struct alc_spec
*spec
= codec
->spec
;
1589 for (i
= 0; i
< spec
->autocfg
.dig_outs
; i
++) {
1590 pin
= spec
->autocfg
.dig_out_pins
[i
];
1593 snd_hda_codec_write(codec
, pin
, 0,
1594 AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
);
1596 dac
= spec
->multiout
.dig_out_nid
;
1598 dac
= spec
->slave_dig_outs
[i
- 1];
1599 if (!dac
|| !(get_wcaps(codec
, dac
) & AC_WCAP_OUT_AMP
))
1601 snd_hda_codec_write(codec
, dac
, 0,
1602 AC_VERB_SET_AMP_GAIN_MUTE
,
1605 pin
= spec
->autocfg
.dig_in_pin
;
1607 snd_hda_codec_write(codec
, pin
, 0,
1608 AC_VERB_SET_PIN_WIDGET_CONTROL
,
1612 /* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1613 static void alc_auto_parse_digital(struct hda_codec
*codec
)
1615 struct alc_spec
*spec
= codec
->spec
;
1619 /* support multiple SPDIFs; the secondary is set up as a slave */
1621 for (i
= 0; i
< spec
->autocfg
.dig_outs
; i
++) {
1623 err
= snd_hda_get_connections(codec
,
1624 spec
->autocfg
.dig_out_pins
[i
],
1625 conn
, ARRAY_SIZE(conn
));
1628 dig_nid
= conn
[0]; /* assume the first element is audio-out */
1630 spec
->multiout
.dig_out_nid
= dig_nid
;
1631 spec
->dig_out_type
= spec
->autocfg
.dig_out_type
[0];
1633 spec
->multiout
.slave_dig_outs
= spec
->slave_dig_outs
;
1634 if (nums
>= ARRAY_SIZE(spec
->slave_dig_outs
) - 1)
1636 spec
->slave_dig_outs
[nums
- 1] = dig_nid
;
1641 if (spec
->autocfg
.dig_in_pin
) {
1642 dig_nid
= codec
->start_nid
;
1643 for (i
= 0; i
< codec
->num_nodes
; i
++, dig_nid
++) {
1644 unsigned int wcaps
= get_wcaps(codec
, dig_nid
);
1645 if (get_wcaps_type(wcaps
) != AC_WID_AUD_IN
)
1647 if (!(wcaps
& AC_WCAP_DIGITAL
))
1649 if (!(wcaps
& AC_WCAP_CONN_LIST
))
1651 err
= get_connection_index(codec
, dig_nid
,
1652 spec
->autocfg
.dig_in_pin
);
1654 spec
->dig_in_nid
= dig_nid
;
1662 * capture mixer elements
1664 static int alc_cap_vol_info(struct snd_kcontrol
*kcontrol
,
1665 struct snd_ctl_elem_info
*uinfo
)
1667 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1668 struct alc_spec
*spec
= codec
->spec
;
1672 mutex_lock(&codec
->control_mutex
);
1673 if (spec
->vol_in_capsrc
)
1674 val
= HDA_COMPOSE_AMP_VAL(spec
->capsrc_nids
[0], 3, 0, HDA_OUTPUT
);
1676 val
= HDA_COMPOSE_AMP_VAL(spec
->adc_nids
[0], 3, 0, HDA_INPUT
);
1677 kcontrol
->private_value
= val
;
1678 err
= snd_hda_mixer_amp_volume_info(kcontrol
, uinfo
);
1679 mutex_unlock(&codec
->control_mutex
);
1683 static int alc_cap_vol_tlv(struct snd_kcontrol
*kcontrol
, int op_flag
,
1684 unsigned int size
, unsigned int __user
*tlv
)
1686 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1687 struct alc_spec
*spec
= codec
->spec
;
1691 mutex_lock(&codec
->control_mutex
);
1692 if (spec
->vol_in_capsrc
)
1693 val
= HDA_COMPOSE_AMP_VAL(spec
->capsrc_nids
[0], 3, 0, HDA_OUTPUT
);
1695 val
= HDA_COMPOSE_AMP_VAL(spec
->adc_nids
[0], 3, 0, HDA_INPUT
);
1696 kcontrol
->private_value
= val
;
1697 err
= snd_hda_mixer_amp_tlv(kcontrol
, op_flag
, size
, tlv
);
1698 mutex_unlock(&codec
->control_mutex
);
1702 typedef int (*getput_call_t
)(struct snd_kcontrol
*kcontrol
,
1703 struct snd_ctl_elem_value
*ucontrol
);
1705 static int alc_cap_getput_caller(struct snd_kcontrol
*kcontrol
,
1706 struct snd_ctl_elem_value
*ucontrol
,
1707 getput_call_t func
, bool check_adc_switch
)
1709 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1710 struct alc_spec
*spec
= codec
->spec
;
1713 mutex_lock(&codec
->control_mutex
);
1714 if (check_adc_switch
&& spec
->dyn_adc_switch
) {
1715 for (i
= 0; i
< spec
->num_adc_nids
; i
++) {
1716 kcontrol
->private_value
=
1717 HDA_COMPOSE_AMP_VAL(spec
->adc_nids
[i
],
1719 err
= func(kcontrol
, ucontrol
);
1724 i
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
1725 if (spec
->vol_in_capsrc
)
1726 kcontrol
->private_value
=
1727 HDA_COMPOSE_AMP_VAL(spec
->capsrc_nids
[i
],
1730 kcontrol
->private_value
=
1731 HDA_COMPOSE_AMP_VAL(spec
->adc_nids
[i
],
1733 err
= func(kcontrol
, ucontrol
);
1736 mutex_unlock(&codec
->control_mutex
);
1740 static int alc_cap_vol_get(struct snd_kcontrol
*kcontrol
,
1741 struct snd_ctl_elem_value
*ucontrol
)
1743 return alc_cap_getput_caller(kcontrol
, ucontrol
,
1744 snd_hda_mixer_amp_volume_get
, false);
1747 static int alc_cap_vol_put(struct snd_kcontrol
*kcontrol
,
1748 struct snd_ctl_elem_value
*ucontrol
)
1750 return alc_cap_getput_caller(kcontrol
, ucontrol
,
1751 snd_hda_mixer_amp_volume_put
, true);
1754 /* capture mixer elements */
1755 #define alc_cap_sw_info snd_ctl_boolean_stereo_info
1757 static int alc_cap_sw_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_switch_get
, false);
1764 static int alc_cap_sw_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_switch_put
, true);
1771 #define _DEFINE_CAPMIX(num) \
1773 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1774 .name = "Capture Switch", \
1775 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1777 .info = alc_cap_sw_info, \
1778 .get = alc_cap_sw_get, \
1779 .put = alc_cap_sw_put, \
1782 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1783 .name = "Capture Volume", \
1784 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1785 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1786 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1788 .info = alc_cap_vol_info, \
1789 .get = alc_cap_vol_get, \
1790 .put = alc_cap_vol_put, \
1791 .tlv = { .c = alc_cap_vol_tlv }, \
1794 #define _DEFINE_CAPSRC(num) \
1796 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1797 /* .name = "Capture Source", */ \
1798 .name = "Input Source", \
1800 .info = alc_mux_enum_info, \
1801 .get = alc_mux_enum_get, \
1802 .put = alc_mux_enum_put, \
1805 #define DEFINE_CAPMIX(num) \
1806 static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
1807 _DEFINE_CAPMIX(num), \
1808 _DEFINE_CAPSRC(num), \
1812 #define DEFINE_CAPMIX_NOSRC(num) \
1813 static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
1814 _DEFINE_CAPMIX(num), \
1818 /* up to three ADCs */
1822 DEFINE_CAPMIX_NOSRC(1);
1823 DEFINE_CAPMIX_NOSRC(2);
1824 DEFINE_CAPMIX_NOSRC(3);
1827 * virtual master controls
1831 * slave controls for virtual master
1833 static const char * const alc_slave_vols
[] = {
1834 "Front Playback Volume",
1835 "Surround Playback Volume",
1836 "Center Playback Volume",
1837 "LFE Playback Volume",
1838 "Side Playback Volume",
1839 "Headphone Playback Volume",
1840 "Speaker Playback Volume",
1841 "Mono Playback Volume",
1842 "Line-Out Playback Volume",
1843 "PCM Playback Volume",
1847 static const char * const alc_slave_sws
[] = {
1848 "Front Playback Switch",
1849 "Surround Playback Switch",
1850 "Center Playback Switch",
1851 "LFE Playback Switch",
1852 "Side Playback Switch",
1853 "Headphone Playback Switch",
1854 "Speaker Playback Switch",
1855 "Mono Playback Switch",
1856 "IEC958 Playback Switch",
1857 "Line-Out Playback Switch",
1858 "PCM Playback Switch",
1863 * build control elements
1866 #define NID_MAPPING (-1)
1868 #define SUBDEV_SPEAKER_ (0 << 6)
1869 #define SUBDEV_HP_ (1 << 6)
1870 #define SUBDEV_LINE_ (2 << 6)
1871 #define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1872 #define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1873 #define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1875 static void alc_free_kctls(struct hda_codec
*codec
);
1877 #ifdef CONFIG_SND_HDA_INPUT_BEEP
1878 /* additional beep mixers; the actual parameters are overwritten at build */
1879 static const struct snd_kcontrol_new alc_beep_mixer
[] = {
1880 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT
),
1881 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT
),
1886 static int alc_build_controls(struct hda_codec
*codec
)
1888 struct alc_spec
*spec
= codec
->spec
;
1889 struct snd_kcontrol
*kctl
= NULL
;
1890 const struct snd_kcontrol_new
*knew
;
1895 for (i
= 0; i
< spec
->num_mixers
; i
++) {
1896 err
= snd_hda_add_new_ctls(codec
, spec
->mixers
[i
]);
1900 if (spec
->cap_mixer
) {
1901 err
= snd_hda_add_new_ctls(codec
, spec
->cap_mixer
);
1905 if (spec
->multiout
.dig_out_nid
) {
1906 err
= snd_hda_create_spdif_out_ctls(codec
,
1907 spec
->multiout
.dig_out_nid
,
1908 spec
->multiout
.dig_out_nid
);
1911 if (!spec
->no_analog
) {
1912 err
= snd_hda_create_spdif_share_sw(codec
,
1916 spec
->multiout
.share_spdif
= 1;
1919 if (spec
->dig_in_nid
) {
1920 err
= snd_hda_create_spdif_in_ctls(codec
, spec
->dig_in_nid
);
1925 #ifdef CONFIG_SND_HDA_INPUT_BEEP
1926 /* create beep controls if needed */
1927 if (spec
->beep_amp
) {
1928 const struct snd_kcontrol_new
*knew
;
1929 for (knew
= alc_beep_mixer
; knew
->name
; knew
++) {
1930 struct snd_kcontrol
*kctl
;
1931 kctl
= snd_ctl_new1(knew
, codec
);
1934 kctl
->private_value
= spec
->beep_amp
;
1935 err
= snd_hda_ctl_add(codec
, 0, kctl
);
1942 /* if we have no master control, let's create it */
1943 if (!spec
->no_analog
&&
1944 !snd_hda_find_mixer_ctl(codec
, "Master Playback Volume")) {
1945 unsigned int vmaster_tlv
[4];
1946 snd_hda_set_vmaster_tlv(codec
, spec
->vmaster_nid
,
1947 HDA_OUTPUT
, vmaster_tlv
);
1948 err
= snd_hda_add_vmaster(codec
, "Master Playback Volume",
1949 vmaster_tlv
, alc_slave_vols
);
1953 if (!spec
->no_analog
&&
1954 !snd_hda_find_mixer_ctl(codec
, "Master Playback Switch")) {
1955 err
= snd_hda_add_vmaster(codec
, "Master Playback Switch",
1956 NULL
, alc_slave_sws
);
1961 /* assign Capture Source enums to NID */
1962 if (spec
->capsrc_nids
|| spec
->adc_nids
) {
1963 kctl
= snd_hda_find_mixer_ctl(codec
, "Capture Source");
1965 kctl
= snd_hda_find_mixer_ctl(codec
, "Input Source");
1966 for (i
= 0; kctl
&& i
< kctl
->count
; i
++) {
1967 err
= snd_hda_add_nid(codec
, kctl
, i
,
1968 get_capsrc(spec
, i
));
1973 if (spec
->cap_mixer
&& spec
->adc_nids
) {
1974 const char *kname
= kctl
? kctl
->id
.name
: NULL
;
1975 for (knew
= spec
->cap_mixer
; knew
->name
; knew
++) {
1976 if (kname
&& strcmp(knew
->name
, kname
) == 0)
1978 kctl
= snd_hda_find_mixer_ctl(codec
, knew
->name
);
1979 for (i
= 0; kctl
&& i
< kctl
->count
; i
++) {
1980 err
= snd_hda_add_nid(codec
, kctl
, i
,
1988 /* other nid->control mapping */
1989 for (i
= 0; i
< spec
->num_mixers
; i
++) {
1990 for (knew
= spec
->mixers
[i
]; knew
->name
; knew
++) {
1991 if (knew
->iface
!= NID_MAPPING
)
1993 kctl
= snd_hda_find_mixer_ctl(codec
, knew
->name
);
1996 u
= knew
->subdevice
;
1997 for (j
= 0; j
< 4; j
++, u
>>= 8) {
2002 case SUBDEV_SPEAKER_
:
2003 nid
= spec
->autocfg
.speaker_pins
[nid
];
2006 nid
= spec
->autocfg
.line_out_pins
[nid
];
2009 nid
= spec
->autocfg
.hp_pins
[nid
];
2014 err
= snd_hda_add_nid(codec
, kctl
, 0, nid
);
2018 u
= knew
->private_value
;
2019 for (j
= 0; j
< 4; j
++, u
>>= 8) {
2023 err
= snd_hda_add_nid(codec
, kctl
, 0, nid
);
2030 alc_free_kctls(codec
); /* no longer needed */
2032 err
= snd_hda_jack_add_kctls(codec
, &spec
->autocfg
);
2044 static void alc_init_special_input_src(struct hda_codec
*codec
);
2046 static int alc_init(struct hda_codec
*codec
)
2048 struct alc_spec
*spec
= codec
->spec
;
2052 alc_auto_init_amp(codec
, spec
->init_amp
);
2054 for (i
= 0; i
< spec
->num_init_verbs
; i
++)
2055 snd_hda_sequence_write(codec
, spec
->init_verbs
[i
]);
2056 alc_init_special_input_src(codec
);
2058 if (spec
->init_hook
)
2059 spec
->init_hook(codec
);
2061 alc_apply_fixup(codec
, ALC_FIXUP_ACT_INIT
);
2063 snd_hda_jack_report_sync(codec
);
2065 hda_call_check_power_status(codec
, 0x01);
2069 static void alc_unsol_event(struct hda_codec
*codec
, unsigned int res
)
2071 struct alc_spec
*spec
= codec
->spec
;
2073 if (spec
->unsol_event
)
2074 spec
->unsol_event(codec
, res
);
2077 #ifdef CONFIG_SND_HDA_POWER_SAVE
2078 static int alc_check_power_status(struct hda_codec
*codec
, hda_nid_t nid
)
2080 struct alc_spec
*spec
= codec
->spec
;
2081 return snd_hda_check_amp_list_power(codec
, &spec
->loopback
, nid
);
2086 * Analog playback callbacks
2088 static int alc_playback_pcm_open(struct hda_pcm_stream
*hinfo
,
2089 struct hda_codec
*codec
,
2090 struct snd_pcm_substream
*substream
)
2092 struct alc_spec
*spec
= codec
->spec
;
2093 return snd_hda_multi_out_analog_open(codec
, &spec
->multiout
, substream
,
2097 static int alc_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
2098 struct hda_codec
*codec
,
2099 unsigned int stream_tag
,
2100 unsigned int format
,
2101 struct snd_pcm_substream
*substream
)
2103 struct alc_spec
*spec
= codec
->spec
;
2104 return snd_hda_multi_out_analog_prepare(codec
, &spec
->multiout
,
2105 stream_tag
, format
, substream
);
2108 static int alc_playback_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
2109 struct hda_codec
*codec
,
2110 struct snd_pcm_substream
*substream
)
2112 struct alc_spec
*spec
= codec
->spec
;
2113 return snd_hda_multi_out_analog_cleanup(codec
, &spec
->multiout
);
2119 static int alc_dig_playback_pcm_open(struct hda_pcm_stream
*hinfo
,
2120 struct hda_codec
*codec
,
2121 struct snd_pcm_substream
*substream
)
2123 struct alc_spec
*spec
= codec
->spec
;
2124 return snd_hda_multi_out_dig_open(codec
, &spec
->multiout
);
2127 static int alc_dig_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_dig_prepare(codec
, &spec
->multiout
,
2135 stream_tag
, format
, substream
);
2138 static int alc_dig_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_dig_cleanup(codec
, &spec
->multiout
);
2146 static int alc_dig_playback_pcm_close(struct hda_pcm_stream
*hinfo
,
2147 struct hda_codec
*codec
,
2148 struct snd_pcm_substream
*substream
)
2150 struct alc_spec
*spec
= codec
->spec
;
2151 return snd_hda_multi_out_dig_close(codec
, &spec
->multiout
);
2157 static int alc_alt_capture_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
;
2165 snd_hda_codec_setup_stream(codec
, spec
->adc_nids
[substream
->number
+ 1],
2166 stream_tag
, 0, format
);
2170 static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
2171 struct hda_codec
*codec
,
2172 struct snd_pcm_substream
*substream
)
2174 struct alc_spec
*spec
= codec
->spec
;
2176 snd_hda_codec_cleanup_stream(codec
,
2177 spec
->adc_nids
[substream
->number
+ 1]);
2181 /* analog capture with dynamic dual-adc changes */
2182 static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream
*hinfo
,
2183 struct hda_codec
*codec
,
2184 unsigned int stream_tag
,
2185 unsigned int format
,
2186 struct snd_pcm_substream
*substream
)
2188 struct alc_spec
*spec
= codec
->spec
;
2189 spec
->cur_adc
= spec
->adc_nids
[spec
->dyn_adc_idx
[spec
->cur_mux
[0]]];
2190 spec
->cur_adc_stream_tag
= stream_tag
;
2191 spec
->cur_adc_format
= format
;
2192 snd_hda_codec_setup_stream(codec
, spec
->cur_adc
, stream_tag
, 0, format
);
2196 static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
2197 struct hda_codec
*codec
,
2198 struct snd_pcm_substream
*substream
)
2200 struct alc_spec
*spec
= codec
->spec
;
2201 snd_hda_codec_cleanup_stream(codec
, spec
->cur_adc
);
2206 static const struct hda_pcm_stream dyn_adc_pcm_analog_capture
= {
2210 .nid
= 0, /* fill later */
2212 .prepare
= dyn_adc_capture_pcm_prepare
,
2213 .cleanup
= dyn_adc_capture_pcm_cleanup
2219 static const struct hda_pcm_stream alc_pcm_analog_playback
= {
2223 /* NID is set in alc_build_pcms */
2225 .open
= alc_playback_pcm_open
,
2226 .prepare
= alc_playback_pcm_prepare
,
2227 .cleanup
= alc_playback_pcm_cleanup
2231 static const struct hda_pcm_stream alc_pcm_analog_capture
= {
2235 /* NID is set in alc_build_pcms */
2238 static const struct hda_pcm_stream alc_pcm_analog_alt_playback
= {
2242 /* NID is set in alc_build_pcms */
2245 static const struct hda_pcm_stream alc_pcm_analog_alt_capture
= {
2246 .substreams
= 2, /* can be overridden */
2249 /* NID is set in alc_build_pcms */
2251 .prepare
= alc_alt_capture_pcm_prepare
,
2252 .cleanup
= alc_alt_capture_pcm_cleanup
2256 static const struct hda_pcm_stream alc_pcm_digital_playback
= {
2260 /* NID is set in alc_build_pcms */
2262 .open
= alc_dig_playback_pcm_open
,
2263 .close
= alc_dig_playback_pcm_close
,
2264 .prepare
= alc_dig_playback_pcm_prepare
,
2265 .cleanup
= alc_dig_playback_pcm_cleanup
2269 static const struct hda_pcm_stream alc_pcm_digital_capture
= {
2273 /* NID is set in alc_build_pcms */
2276 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
2277 static const struct hda_pcm_stream alc_pcm_null_stream
= {
2283 static int alc_build_pcms(struct hda_codec
*codec
)
2285 struct alc_spec
*spec
= codec
->spec
;
2286 struct hda_pcm
*info
= spec
->pcm_rec
;
2287 const struct hda_pcm_stream
*p
;
2288 bool have_multi_adcs
;
2291 codec
->num_pcms
= 1;
2292 codec
->pcm_info
= info
;
2294 if (spec
->no_analog
)
2297 snprintf(spec
->stream_name_analog
, sizeof(spec
->stream_name_analog
),
2298 "%s Analog", codec
->chip_name
);
2299 info
->name
= spec
->stream_name_analog
;
2301 if (spec
->multiout
.dac_nids
> 0) {
2302 p
= spec
->stream_analog_playback
;
2304 p
= &alc_pcm_analog_playback
;
2305 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] = *p
;
2306 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
= spec
->multiout
.dac_nids
[0];
2308 if (spec
->adc_nids
) {
2309 p
= spec
->stream_analog_capture
;
2311 if (spec
->dyn_adc_switch
)
2312 p
= &dyn_adc_pcm_analog_capture
;
2314 p
= &alc_pcm_analog_capture
;
2316 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] = *p
;
2317 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
= spec
->adc_nids
[0];
2320 if (spec
->channel_mode
) {
2321 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].channels_max
= 0;
2322 for (i
= 0; i
< spec
->num_channel_mode
; i
++) {
2323 if (spec
->channel_mode
[i
].channels
> info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].channels_max
) {
2324 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].channels_max
= spec
->channel_mode
[i
].channels
;
2330 /* SPDIF for stream index #1 */
2331 if (spec
->multiout
.dig_out_nid
|| spec
->dig_in_nid
) {
2332 snprintf(spec
->stream_name_digital
,
2333 sizeof(spec
->stream_name_digital
),
2334 "%s Digital", codec
->chip_name
);
2335 codec
->num_pcms
= 2;
2336 codec
->slave_dig_outs
= spec
->multiout
.slave_dig_outs
;
2337 info
= spec
->pcm_rec
+ 1;
2338 info
->name
= spec
->stream_name_digital
;
2339 if (spec
->dig_out_type
)
2340 info
->pcm_type
= spec
->dig_out_type
;
2342 info
->pcm_type
= HDA_PCM_TYPE_SPDIF
;
2343 if (spec
->multiout
.dig_out_nid
) {
2344 p
= spec
->stream_digital_playback
;
2346 p
= &alc_pcm_digital_playback
;
2347 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] = *p
;
2348 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
= spec
->multiout
.dig_out_nid
;
2350 if (spec
->dig_in_nid
) {
2351 p
= spec
->stream_digital_capture
;
2353 p
= &alc_pcm_digital_capture
;
2354 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] = *p
;
2355 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
= spec
->dig_in_nid
;
2357 /* FIXME: do we need this for all Realtek codec models? */
2358 codec
->spdif_status_reset
= 1;
2361 if (spec
->no_analog
)
2364 /* If the use of more than one ADC is requested for the current
2365 * model, configure a second analog capture-only PCM.
2367 have_multi_adcs
= (spec
->num_adc_nids
> 1) &&
2368 !spec
->dyn_adc_switch
&& !spec
->auto_mic
&&
2369 (!spec
->input_mux
|| spec
->input_mux
->num_items
> 1);
2370 /* Additional Analaog capture for index #2 */
2371 if (spec
->alt_dac_nid
|| have_multi_adcs
) {
2372 codec
->num_pcms
= 3;
2373 info
= spec
->pcm_rec
+ 2;
2374 info
->name
= spec
->stream_name_analog
;
2375 if (spec
->alt_dac_nid
) {
2376 p
= spec
->stream_analog_alt_playback
;
2378 p
= &alc_pcm_analog_alt_playback
;
2379 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] = *p
;
2380 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
=
2383 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] =
2384 alc_pcm_null_stream
;
2385 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
= 0;
2387 if (have_multi_adcs
) {
2388 p
= spec
->stream_analog_alt_capture
;
2390 p
= &alc_pcm_analog_alt_capture
;
2391 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] = *p
;
2392 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
=
2394 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].substreams
=
2395 spec
->num_adc_nids
- 1;
2397 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] =
2398 alc_pcm_null_stream
;
2399 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
= 0;
2406 static inline void alc_shutup(struct hda_codec
*codec
)
2408 struct alc_spec
*spec
= codec
->spec
;
2410 if (spec
&& spec
->shutup
)
2411 spec
->shutup(codec
);
2412 snd_hda_shutup_pins(codec
);
2415 static void alc_free_kctls(struct hda_codec
*codec
)
2417 struct alc_spec
*spec
= codec
->spec
;
2419 if (spec
->kctls
.list
) {
2420 struct snd_kcontrol_new
*kctl
= spec
->kctls
.list
;
2422 for (i
= 0; i
< spec
->kctls
.used
; i
++)
2423 kfree(kctl
[i
].name
);
2425 snd_array_free(&spec
->kctls
);
2428 static void alc_free_bind_ctls(struct hda_codec
*codec
)
2430 struct alc_spec
*spec
= codec
->spec
;
2431 if (spec
->bind_ctls
.list
) {
2432 struct hda_bind_ctls
**ctl
= spec
->bind_ctls
.list
;
2434 for (i
= 0; i
< spec
->bind_ctls
.used
; i
++)
2437 snd_array_free(&spec
->bind_ctls
);
2440 static void alc_free(struct hda_codec
*codec
)
2442 struct alc_spec
*spec
= codec
->spec
;
2448 alc_free_kctls(codec
);
2449 alc_free_bind_ctls(codec
);
2451 snd_hda_detach_beep_device(codec
);
2454 #ifdef CONFIG_SND_HDA_POWER_SAVE
2455 static void alc_power_eapd(struct hda_codec
*codec
)
2457 alc_auto_setup_eapd(codec
, false);
2460 static int alc_suspend(struct hda_codec
*codec
, pm_message_t state
)
2462 struct alc_spec
*spec
= codec
->spec
;
2464 if (spec
&& spec
->power_hook
)
2465 spec
->power_hook(codec
);
2471 static int alc_resume(struct hda_codec
*codec
)
2473 msleep(150); /* to avoid pop noise */
2474 codec
->patch_ops
.init(codec
);
2475 snd_hda_codec_resume_amp(codec
);
2476 snd_hda_codec_resume_cache(codec
);
2477 hda_call_check_power_status(codec
, 0x01);
2484 static const struct hda_codec_ops alc_patch_ops
= {
2485 .build_controls
= alc_build_controls
,
2486 .build_pcms
= alc_build_pcms
,
2489 .unsol_event
= alc_unsol_event
,
2491 .resume
= alc_resume
,
2493 #ifdef CONFIG_SND_HDA_POWER_SAVE
2494 .suspend
= alc_suspend
,
2495 .check_power_status
= alc_check_power_status
,
2497 .reboot_notify
= alc_shutup
,
2500 /* replace the codec chip_name with the given string */
2501 static int alc_codec_rename(struct hda_codec
*codec
, const char *name
)
2503 kfree(codec
->chip_name
);
2504 codec
->chip_name
= kstrdup(name
, GFP_KERNEL
);
2505 if (!codec
->chip_name
) {
2513 * Rename codecs appropriately from COEF value
2515 struct alc_codec_rename_table
{
2516 unsigned int vendor_id
;
2517 unsigned short coef_mask
;
2518 unsigned short coef_bits
;
2522 static struct alc_codec_rename_table rename_tbl
[] = {
2523 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2524 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2525 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2526 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2527 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2528 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2529 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
2530 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2531 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2532 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2533 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2534 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2535 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2536 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2537 { } /* terminator */
2540 static int alc_codec_rename_from_preset(struct hda_codec
*codec
)
2542 const struct alc_codec_rename_table
*p
;
2544 for (p
= rename_tbl
; p
->vendor_id
; p
++) {
2545 if (p
->vendor_id
!= codec
->vendor_id
)
2547 if ((alc_get_coef0(codec
) & p
->coef_mask
) == p
->coef_bits
)
2548 return alc_codec_rename(codec
, p
->name
);
2554 * Automatic parse of I/O pins from the BIOS configuration
2559 ALC_CTL_WIDGET_MUTE
,
2564 static const struct snd_kcontrol_new alc_control_templates
[] = {
2565 HDA_CODEC_VOLUME(NULL
, 0, 0, 0),
2566 HDA_CODEC_MUTE(NULL
, 0, 0, 0),
2567 HDA_BIND_MUTE(NULL
, 0, 0, 0),
2568 HDA_BIND_VOL(NULL
, 0),
2569 HDA_BIND_SW(NULL
, 0),
2572 /* add dynamic controls */
2573 static int add_control(struct alc_spec
*spec
, int type
, const char *name
,
2574 int cidx
, unsigned long val
)
2576 struct snd_kcontrol_new
*knew
;
2578 knew
= alc_kcontrol_new(spec
);
2581 *knew
= alc_control_templates
[type
];
2582 knew
->name
= kstrdup(name
, GFP_KERNEL
);
2586 if (get_amp_nid_(val
))
2587 knew
->subdevice
= HDA_SUBDEV_AMP_FLAG
;
2588 knew
->private_value
= val
;
2592 static int add_control_with_pfx(struct alc_spec
*spec
, int type
,
2593 const char *pfx
, const char *dir
,
2594 const char *sfx
, int cidx
, unsigned long val
)
2597 snprintf(name
, sizeof(name
), "%s %s %s", pfx
, dir
, sfx
);
2598 return add_control(spec
, type
, name
, cidx
, val
);
2601 #define add_pb_vol_ctrl(spec, type, pfx, val) \
2602 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2603 #define add_pb_sw_ctrl(spec, type, pfx, val) \
2604 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2605 #define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2606 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2607 #define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2608 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
2610 static const char * const channel_name
[4] = {
2611 "Front", "Surround", "CLFE", "Side"
2614 static const char *alc_get_line_out_pfx(struct alc_spec
*spec
, int ch
,
2615 bool can_be_master
, int *index
)
2617 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
2620 if (cfg
->line_outs
== 1 && !spec
->multi_ios
&&
2621 !cfg
->hp_outs
&& !cfg
->speaker_outs
&& can_be_master
)
2624 switch (cfg
->line_out_type
) {
2625 case AUTO_PIN_SPEAKER_OUT
:
2626 if (cfg
->line_outs
== 1)
2628 if (cfg
->line_outs
== 2)
2629 return ch
? "Bass Speaker" : "Speaker";
2631 case AUTO_PIN_HP_OUT
:
2632 /* for multi-io case, only the primary out */
2633 if (ch
&& spec
->multi_ios
)
2638 if (cfg
->line_outs
== 1 && !spec
->multi_ios
)
2642 if (snd_BUG_ON(ch
>= ARRAY_SIZE(channel_name
)))
2645 return channel_name
[ch
];
2648 /* create input playback/capture controls for the given pin */
2649 static int new_analog_input(struct alc_spec
*spec
, hda_nid_t pin
,
2650 const char *ctlname
, int ctlidx
,
2651 int idx
, hda_nid_t mix_nid
)
2655 err
= __add_pb_vol_ctrl(spec
, ALC_CTL_WIDGET_VOL
, ctlname
, ctlidx
,
2656 HDA_COMPOSE_AMP_VAL(mix_nid
, 3, idx
, HDA_INPUT
));
2659 err
= __add_pb_sw_ctrl(spec
, ALC_CTL_WIDGET_MUTE
, ctlname
, ctlidx
,
2660 HDA_COMPOSE_AMP_VAL(mix_nid
, 3, idx
, HDA_INPUT
));
2666 static int alc_is_input_pin(struct hda_codec
*codec
, hda_nid_t nid
)
2668 unsigned int pincap
= snd_hda_query_pin_caps(codec
, nid
);
2669 return (pincap
& AC_PINCAP_IN
) != 0;
2672 /* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
2673 static int alc_auto_fill_adc_caps(struct hda_codec
*codec
)
2675 struct alc_spec
*spec
= codec
->spec
;
2677 hda_nid_t
*adc_nids
= spec
->private_adc_nids
;
2678 hda_nid_t
*cap_nids
= spec
->private_capsrc_nids
;
2679 int max_nums
= ARRAY_SIZE(spec
->private_adc_nids
);
2682 if (spec
->shared_mic_hp
)
2683 max_nums
= 1; /* no multi streams with the shared HP/mic */
2685 nid
= codec
->start_nid
;
2686 for (i
= 0; i
< codec
->num_nodes
; i
++, nid
++) {
2688 const hda_nid_t
*list
;
2689 unsigned int caps
= get_wcaps(codec
, nid
);
2690 int type
= get_wcaps_type(caps
);
2692 if (type
!= AC_WID_AUD_IN
|| (caps
& AC_WCAP_DIGITAL
))
2694 adc_nids
[nums
] = nid
;
2695 cap_nids
[nums
] = nid
;
2699 type
= get_wcaps_type(get_wcaps(codec
, src
));
2700 if (type
== AC_WID_PIN
)
2702 if (type
== AC_WID_AUD_SEL
) {
2703 cap_nids
[nums
] = src
;
2706 n
= snd_hda_get_conn_list(codec
, src
, &list
);
2708 cap_nids
[nums
] = src
;
2714 if (++nums
>= max_nums
)
2717 spec
->adc_nids
= spec
->private_adc_nids
;
2718 spec
->capsrc_nids
= spec
->private_capsrc_nids
;
2719 spec
->num_adc_nids
= nums
;
2723 /* create playback/capture controls for input pins */
2724 static int alc_auto_create_input_ctls(struct hda_codec
*codec
)
2726 struct alc_spec
*spec
= codec
->spec
;
2727 const struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
2728 hda_nid_t mixer
= spec
->mixer_nid
;
2729 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
2731 int i
, c
, err
, idx
, type_idx
= 0;
2732 const char *prev_label
= NULL
;
2734 num_adcs
= alc_auto_fill_adc_caps(codec
);
2738 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
2742 pin
= cfg
->inputs
[i
].pin
;
2743 if (!alc_is_input_pin(codec
, pin
))
2746 label
= hda_get_autocfg_input_label(codec
, cfg
, i
);
2747 if (spec
->shared_mic_hp
&& !strcmp(label
, "Misc"))
2748 label
= "Headphone Mic";
2749 if (prev_label
&& !strcmp(label
, prev_label
))
2756 idx
= get_connection_index(codec
, mixer
, pin
);
2758 err
= new_analog_input(spec
, pin
,
2766 for (c
= 0; c
< num_adcs
; c
++) {
2767 hda_nid_t cap
= get_capsrc(spec
, c
);
2768 idx
= get_connection_index(codec
, cap
, pin
);
2770 spec
->imux_pins
[imux
->num_items
] = pin
;
2771 snd_hda_add_imux_item(imux
, label
, idx
, NULL
);
2777 spec
->num_mux_defs
= 1;
2778 spec
->input_mux
= imux
;
2783 /* create a shared input with the headphone out */
2784 static int alc_auto_create_shared_input(struct hda_codec
*codec
)
2786 struct alc_spec
*spec
= codec
->spec
;
2787 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
2788 unsigned int defcfg
;
2791 /* only one internal input pin? */
2792 if (cfg
->num_inputs
!= 1)
2794 defcfg
= snd_hda_codec_get_pincfg(codec
, cfg
->inputs
[0].pin
);
2795 if (snd_hda_get_input_pin_attr(defcfg
) != INPUT_PIN_ATTR_INT
)
2798 if (cfg
->hp_outs
== 1 && cfg
->line_out_type
== AUTO_PIN_SPEAKER_OUT
)
2799 nid
= cfg
->hp_pins
[0]; /* OK, we have a single HP-out */
2800 else if (cfg
->line_outs
== 1 && cfg
->line_out_type
== AUTO_PIN_HP_OUT
)
2801 nid
= cfg
->line_out_pins
[0]; /* OK, we have a single line-out */
2803 return 0; /* both not available */
2805 if (!(snd_hda_query_pin_caps(codec
, nid
) & AC_PINCAP_IN
))
2806 return 0; /* no input */
2808 cfg
->inputs
[1].pin
= nid
;
2809 cfg
->inputs
[1].type
= AUTO_PIN_MIC
;
2810 cfg
->num_inputs
= 2;
2811 spec
->shared_mic_hp
= 1;
2812 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid
);
2816 static void alc_set_pin_output(struct hda_codec
*codec
, hda_nid_t nid
,
2817 unsigned int pin_type
)
2819 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_PIN_WIDGET_CONTROL
,
2822 if (nid_has_mute(codec
, nid
, HDA_OUTPUT
))
2823 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
2827 static int get_pin_type(int line_out_type
)
2829 if (line_out_type
== AUTO_PIN_HP_OUT
)
2835 static void alc_auto_init_analog_input(struct hda_codec
*codec
)
2837 struct alc_spec
*spec
= codec
->spec
;
2838 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
2841 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
2842 hda_nid_t nid
= cfg
->inputs
[i
].pin
;
2843 if (alc_is_input_pin(codec
, nid
)) {
2844 alc_set_input_pin(codec
, nid
, cfg
->inputs
[i
].type
);
2845 if (get_wcaps(codec
, nid
) & AC_WCAP_OUT_AMP
)
2846 snd_hda_codec_write(codec
, nid
, 0,
2847 AC_VERB_SET_AMP_GAIN_MUTE
,
2852 /* mute all loopback inputs */
2853 if (spec
->mixer_nid
) {
2854 int nums
= snd_hda_get_conn_list(codec
, spec
->mixer_nid
, NULL
);
2855 for (i
= 0; i
< nums
; i
++)
2856 snd_hda_codec_write(codec
, spec
->mixer_nid
, 0,
2857 AC_VERB_SET_AMP_GAIN_MUTE
,
2862 /* convert from MIX nid to DAC */
2863 static hda_nid_t
alc_auto_mix_to_dac(struct hda_codec
*codec
, hda_nid_t nid
)
2868 if (get_wcaps_type(get_wcaps(codec
, nid
)) == AC_WID_AUD_OUT
)
2870 num
= snd_hda_get_connections(codec
, nid
, list
, ARRAY_SIZE(list
));
2871 for (i
= 0; i
< num
; i
++) {
2872 if (get_wcaps_type(get_wcaps(codec
, list
[i
])) == AC_WID_AUD_OUT
)
2878 /* go down to the selector widget before the mixer */
2879 static hda_nid_t
alc_go_down_to_selector(struct hda_codec
*codec
, hda_nid_t pin
)
2882 int num
= snd_hda_get_connections(codec
, pin
, srcs
,
2885 get_wcaps_type(get_wcaps(codec
, srcs
[0])) != AC_WID_AUD_SEL
)
2890 /* get MIX nid connected to the given pin targeted to DAC */
2891 static hda_nid_t
alc_auto_dac_to_mix(struct hda_codec
*codec
, hda_nid_t pin
,
2897 pin
= alc_go_down_to_selector(codec
, pin
);
2898 num
= snd_hda_get_connections(codec
, pin
, mix
, ARRAY_SIZE(mix
));
2899 for (i
= 0; i
< num
; i
++) {
2900 if (alc_auto_mix_to_dac(codec
, mix
[i
]) == dac
)
2906 /* select the connection from pin to DAC if needed */
2907 static int alc_auto_select_dac(struct hda_codec
*codec
, hda_nid_t pin
,
2913 pin
= alc_go_down_to_selector(codec
, pin
);
2914 num
= snd_hda_get_connections(codec
, pin
, mix
, ARRAY_SIZE(mix
));
2917 for (i
= 0; i
< num
; i
++) {
2918 if (alc_auto_mix_to_dac(codec
, mix
[i
]) == dac
) {
2919 snd_hda_codec_update_cache(codec
, pin
, 0,
2920 AC_VERB_SET_CONNECT_SEL
, i
);
2927 /* look for an empty DAC slot */
2928 static hda_nid_t
alc_auto_look_for_dac(struct hda_codec
*codec
, hda_nid_t pin
)
2930 struct alc_spec
*spec
= codec
->spec
;
2934 pin
= alc_go_down_to_selector(codec
, pin
);
2935 num
= snd_hda_get_connections(codec
, pin
, srcs
, ARRAY_SIZE(srcs
));
2936 for (i
= 0; i
< num
; i
++) {
2937 hda_nid_t nid
= alc_auto_mix_to_dac(codec
, srcs
[i
]);
2940 if (found_in_nid_list(nid
, spec
->multiout
.dac_nids
,
2941 ARRAY_SIZE(spec
->private_dac_nids
)))
2943 if (found_in_nid_list(nid
, spec
->multiout
.hp_out_nid
,
2944 ARRAY_SIZE(spec
->multiout
.hp_out_nid
)))
2946 if (found_in_nid_list(nid
, spec
->multiout
.extra_out_nid
,
2947 ARRAY_SIZE(spec
->multiout
.extra_out_nid
)))
2954 /* check whether the DAC is reachable from the pin */
2955 static bool alc_auto_is_dac_reachable(struct hda_codec
*codec
,
2956 hda_nid_t pin
, hda_nid_t dac
)
2961 pin
= alc_go_down_to_selector(codec
, pin
);
2962 num
= snd_hda_get_connections(codec
, pin
, srcs
, ARRAY_SIZE(srcs
));
2963 for (i
= 0; i
< num
; i
++) {
2964 hda_nid_t nid
= alc_auto_mix_to_dac(codec
, srcs
[i
]);
2971 static hda_nid_t
get_dac_if_single(struct hda_codec
*codec
, hda_nid_t pin
)
2973 hda_nid_t sel
= alc_go_down_to_selector(codec
, pin
);
2974 if (snd_hda_get_conn_list(codec
, sel
, NULL
) == 1)
2975 return alc_auto_look_for_dac(codec
, pin
);
2979 /* return 0 if no possible DAC is found, 1 if one or more found */
2980 static int alc_auto_fill_extra_dacs(struct hda_codec
*codec
, int num_outs
,
2981 const hda_nid_t
*pins
, hda_nid_t
*dacs
)
2985 if (num_outs
&& !dacs
[0]) {
2986 dacs
[0] = alc_auto_look_for_dac(codec
, pins
[0]);
2991 for (i
= 1; i
< num_outs
; i
++)
2992 dacs
[i
] = get_dac_if_single(codec
, pins
[i
]);
2993 for (i
= 1; i
< num_outs
; i
++) {
2995 dacs
[i
] = alc_auto_look_for_dac(codec
, pins
[i
]);
3000 static int alc_auto_fill_multi_ios(struct hda_codec
*codec
,
3001 unsigned int location
, int offset
);
3002 static hda_nid_t
alc_look_for_out_vol_nid(struct hda_codec
*codec
,
3003 hda_nid_t pin
, hda_nid_t dac
);
3005 /* fill in the dac_nids table from the parsed pin configuration */
3006 static int alc_auto_fill_dac_nids(struct hda_codec
*codec
)
3008 struct alc_spec
*spec
= codec
->spec
;
3009 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
3010 unsigned int location
, defcfg
;
3012 bool redone
= false;
3016 /* set num_dacs once to full for alc_auto_look_for_dac() */
3017 spec
->multiout
.num_dacs
= cfg
->line_outs
;
3018 spec
->multiout
.hp_out_nid
[0] = 0;
3019 spec
->multiout
.extra_out_nid
[0] = 0;
3020 memset(spec
->private_dac_nids
, 0, sizeof(spec
->private_dac_nids
));
3021 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
3022 spec
->multi_ios
= 0;
3024 /* fill hard-wired DACs first */
3026 for (i
= 0; i
< cfg
->line_outs
; i
++)
3027 spec
->private_dac_nids
[i
] =
3028 get_dac_if_single(codec
, cfg
->line_out_pins
[i
]);
3030 spec
->multiout
.hp_out_nid
[0] =
3031 get_dac_if_single(codec
, cfg
->hp_pins
[0]);
3032 if (cfg
->speaker_outs
)
3033 spec
->multiout
.extra_out_nid
[0] =
3034 get_dac_if_single(codec
, cfg
->speaker_pins
[0]);
3037 for (i
= 0; i
< cfg
->line_outs
; i
++) {
3038 hda_nid_t pin
= cfg
->line_out_pins
[i
];
3039 if (spec
->private_dac_nids
[i
])
3041 spec
->private_dac_nids
[i
] = alc_auto_look_for_dac(codec
, pin
);
3042 if (!spec
->private_dac_nids
[i
] && !redone
) {
3043 /* if we can't find primary DACs, re-probe without
3044 * checking the hard-wired DACs
3051 /* re-count num_dacs and squash invalid entries */
3052 spec
->multiout
.num_dacs
= 0;
3053 for (i
= 0; i
< cfg
->line_outs
; i
++) {
3054 if (spec
->private_dac_nids
[i
])
3055 spec
->multiout
.num_dacs
++;
3057 memmove(spec
->private_dac_nids
+ i
,
3058 spec
->private_dac_nids
+ i
+ 1,
3059 sizeof(hda_nid_t
) * (cfg
->line_outs
- i
- 1));
3060 spec
->private_dac_nids
[cfg
->line_outs
- 1] = 0;
3064 if (cfg
->line_outs
== 1 && cfg
->line_out_type
!= AUTO_PIN_SPEAKER_OUT
) {
3065 /* try to fill multi-io first */
3066 defcfg
= snd_hda_codec_get_pincfg(codec
, cfg
->line_out_pins
[0]);
3067 location
= get_defcfg_location(defcfg
);
3069 num_pins
= alc_auto_fill_multi_ios(codec
, location
, 0);
3071 spec
->multi_ios
= num_pins
;
3072 spec
->ext_channel_count
= 2;
3073 spec
->multiout
.num_dacs
= num_pins
+ 1;
3077 if (cfg
->line_out_type
!= AUTO_PIN_HP_OUT
)
3078 alc_auto_fill_extra_dacs(codec
, cfg
->hp_outs
, cfg
->hp_pins
,
3079 spec
->multiout
.hp_out_nid
);
3080 if (cfg
->line_out_type
!= AUTO_PIN_SPEAKER_OUT
) {
3081 int err
= alc_auto_fill_extra_dacs(codec
, cfg
->speaker_outs
,
3083 spec
->multiout
.extra_out_nid
);
3084 /* if no speaker volume is assigned, try again as the primary
3087 if (!err
&& cfg
->speaker_outs
> 0 &&
3088 cfg
->line_out_type
== AUTO_PIN_HP_OUT
) {
3089 cfg
->hp_outs
= cfg
->line_outs
;
3090 memcpy(cfg
->hp_pins
, cfg
->line_out_pins
,
3091 sizeof(cfg
->hp_pins
));
3092 cfg
->line_outs
= cfg
->speaker_outs
;
3093 memcpy(cfg
->line_out_pins
, cfg
->speaker_pins
,
3094 sizeof(cfg
->speaker_pins
));
3095 cfg
->speaker_outs
= 0;
3096 memset(cfg
->speaker_pins
, 0, sizeof(cfg
->speaker_pins
));
3097 cfg
->line_out_type
= AUTO_PIN_SPEAKER_OUT
;
3103 if (!spec
->multi_ios
&&
3104 cfg
->line_out_type
== AUTO_PIN_SPEAKER_OUT
&&
3106 /* try multi-ios with HP + inputs */
3107 defcfg
= snd_hda_codec_get_pincfg(codec
, cfg
->hp_pins
[0]);
3108 location
= get_defcfg_location(defcfg
);
3110 num_pins
= alc_auto_fill_multi_ios(codec
, location
, 1);
3112 spec
->multi_ios
= num_pins
;
3113 spec
->ext_channel_count
= 2;
3114 spec
->multiout
.num_dacs
= num_pins
+ 1;
3118 if (cfg
->line_out_pins
[0])
3120 alc_look_for_out_vol_nid(codec
, cfg
->line_out_pins
[0],
3121 spec
->multiout
.dac_nids
[0]);
3125 static inline unsigned int get_ctl_pos(unsigned int data
)
3127 hda_nid_t nid
= get_amp_nid_(data
);
3128 unsigned int dir
= get_amp_direction_(data
);
3129 return (nid
<< 1) | dir
;
3132 #define is_ctl_used(bits, data) \
3133 test_bit(get_ctl_pos(data), bits)
3134 #define mark_ctl_usage(bits, data) \
3135 set_bit(get_ctl_pos(data), bits)
3137 static int alc_auto_add_vol_ctl(struct hda_codec
*codec
,
3138 const char *pfx
, int cidx
,
3139 hda_nid_t nid
, unsigned int chs
)
3141 struct alc_spec
*spec
= codec
->spec
;
3145 val
= HDA_COMPOSE_AMP_VAL(nid
, chs
, 0, HDA_OUTPUT
);
3146 if (is_ctl_used(spec
->vol_ctls
, val
) && chs
!= 2) /* exclude LFE */
3148 mark_ctl_usage(spec
->vol_ctls
, val
);
3149 return __add_pb_vol_ctrl(codec
->spec
, ALC_CTL_WIDGET_VOL
, pfx
, cidx
,
3153 static int alc_auto_add_stereo_vol(struct hda_codec
*codec
,
3154 const char *pfx
, int cidx
,
3158 if (get_wcaps(codec
, nid
) & AC_WCAP_STEREO
)
3160 return alc_auto_add_vol_ctl(codec
, pfx
, cidx
, nid
, chs
);
3163 /* create a mute-switch for the given mixer widget;
3164 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3166 static int alc_auto_add_sw_ctl(struct hda_codec
*codec
,
3167 const char *pfx
, int cidx
,
3168 hda_nid_t nid
, unsigned int chs
)
3170 struct alc_spec
*spec
= codec
->spec
;
3176 wid_type
= get_wcaps_type(get_wcaps(codec
, nid
));
3177 if (wid_type
== AC_WID_PIN
|| wid_type
== AC_WID_AUD_OUT
) {
3178 type
= ALC_CTL_WIDGET_MUTE
;
3179 val
= HDA_COMPOSE_AMP_VAL(nid
, chs
, 0, HDA_OUTPUT
);
3180 } else if (snd_hda_get_conn_list(codec
, nid
, NULL
) == 1) {
3181 type
= ALC_CTL_WIDGET_MUTE
;
3182 val
= HDA_COMPOSE_AMP_VAL(nid
, chs
, 0, HDA_INPUT
);
3184 type
= ALC_CTL_BIND_MUTE
;
3185 val
= HDA_COMPOSE_AMP_VAL(nid
, chs
, 2, HDA_INPUT
);
3187 if (is_ctl_used(spec
->sw_ctls
, val
) && chs
!= 2) /* exclude LFE */
3189 mark_ctl_usage(spec
->sw_ctls
, val
);
3190 return __add_pb_sw_ctrl(codec
->spec
, type
, pfx
, cidx
, val
);
3193 static int alc_auto_add_stereo_sw(struct hda_codec
*codec
, const char *pfx
,
3194 int cidx
, hda_nid_t nid
)
3197 if (get_wcaps(codec
, nid
) & AC_WCAP_STEREO
)
3199 return alc_auto_add_sw_ctl(codec
, pfx
, cidx
, nid
, chs
);
3202 static hda_nid_t
alc_look_for_out_mute_nid(struct hda_codec
*codec
,
3203 hda_nid_t pin
, hda_nid_t dac
)
3205 hda_nid_t mix
= alc_auto_dac_to_mix(codec
, pin
, dac
);
3206 if (nid_has_mute(codec
, pin
, HDA_OUTPUT
))
3208 else if (mix
&& nid_has_mute(codec
, mix
, HDA_INPUT
))
3210 else if (nid_has_mute(codec
, dac
, HDA_OUTPUT
))
3215 static hda_nid_t
alc_look_for_out_vol_nid(struct hda_codec
*codec
,
3216 hda_nid_t pin
, hda_nid_t dac
)
3218 hda_nid_t mix
= alc_auto_dac_to_mix(codec
, pin
, dac
);
3219 if (nid_has_volume(codec
, dac
, HDA_OUTPUT
))
3221 else if (nid_has_volume(codec
, mix
, HDA_OUTPUT
))
3223 else if (nid_has_volume(codec
, pin
, HDA_OUTPUT
))
3228 /* add playback controls from the parsed DAC table */
3229 static int alc_auto_create_multi_out_ctls(struct hda_codec
*codec
,
3230 const struct auto_pin_cfg
*cfg
)
3232 struct alc_spec
*spec
= codec
->spec
;
3233 int i
, err
, noutputs
;
3235 noutputs
= cfg
->line_outs
;
3236 if (spec
->multi_ios
> 0)
3237 noutputs
+= spec
->multi_ios
;
3239 for (i
= 0; i
< noutputs
; i
++) {
3245 dac
= spec
->multiout
.dac_nids
[i
];
3248 if (i
>= cfg
->line_outs
)
3249 pin
= spec
->multi_io
[i
- 1].pin
;
3251 pin
= cfg
->line_out_pins
[i
];
3253 sw
= alc_look_for_out_mute_nid(codec
, pin
, dac
);
3254 vol
= alc_look_for_out_vol_nid(codec
, pin
, dac
);
3255 name
= alc_get_line_out_pfx(spec
, i
, true, &index
);
3256 if (!name
|| !strcmp(name
, "CLFE")) {
3258 err
= alc_auto_add_vol_ctl(codec
, "Center", 0, vol
, 1);
3261 err
= alc_auto_add_vol_ctl(codec
, "LFE", 0, vol
, 2);
3264 err
= alc_auto_add_sw_ctl(codec
, "Center", 0, sw
, 1);
3267 err
= alc_auto_add_sw_ctl(codec
, "LFE", 0, sw
, 2);
3271 err
= alc_auto_add_stereo_vol(codec
, name
, index
, vol
);
3274 err
= alc_auto_add_stereo_sw(codec
, name
, index
, sw
);
3282 static int alc_auto_create_extra_out(struct hda_codec
*codec
, hda_nid_t pin
,
3283 hda_nid_t dac
, const char *pfx
,
3286 struct alc_spec
*spec
= codec
->spec
;
3292 /* the corresponding DAC is already occupied */
3293 if (!(get_wcaps(codec
, pin
) & AC_WCAP_OUT_AMP
))
3294 return 0; /* no way */
3295 /* create a switch only */
3296 val
= HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
);
3297 if (is_ctl_used(spec
->sw_ctls
, val
))
3298 return 0; /* already created */
3299 mark_ctl_usage(spec
->sw_ctls
, val
);
3300 return __add_pb_sw_ctrl(spec
, ALC_CTL_WIDGET_MUTE
, pfx
, cidx
, val
);
3303 sw
= alc_look_for_out_mute_nid(codec
, pin
, dac
);
3304 vol
= alc_look_for_out_vol_nid(codec
, pin
, dac
);
3305 err
= alc_auto_add_stereo_vol(codec
, pfx
, cidx
, vol
);
3308 err
= alc_auto_add_stereo_sw(codec
, pfx
, cidx
, sw
);
3314 static struct hda_bind_ctls
*new_bind_ctl(struct hda_codec
*codec
,
3316 struct hda_ctl_ops
*ops
)
3318 struct alc_spec
*spec
= codec
->spec
;
3319 struct hda_bind_ctls
**ctlp
, *ctl
;
3320 snd_array_init(&spec
->bind_ctls
, sizeof(ctl
), 8);
3321 ctlp
= snd_array_new(&spec
->bind_ctls
);
3324 ctl
= kzalloc(sizeof(*ctl
) + sizeof(long) * (nums
+ 1), GFP_KERNEL
);
3331 /* add playback controls for speaker and HP outputs */
3332 static int alc_auto_create_extra_outs(struct hda_codec
*codec
, int num_pins
,
3333 const hda_nid_t
*pins
,
3334 const hda_nid_t
*dacs
,
3337 struct alc_spec
*spec
= codec
->spec
;
3338 struct hda_bind_ctls
*ctl
;
3342 if (!num_pins
|| !pins
[0])
3345 if (num_pins
== 1) {
3346 hda_nid_t dac
= *dacs
;
3348 dac
= spec
->multiout
.dac_nids
[0];
3349 return alc_auto_create_extra_out(codec
, *pins
, dac
, pfx
, 0);
3352 if (dacs
[num_pins
- 1]) {
3353 /* OK, we have a multi-output system with individual volumes */
3354 for (i
= 0; i
< num_pins
; i
++) {
3355 if (num_pins
>= 3) {
3356 snprintf(name
, sizeof(name
), "%s %s",
3357 pfx
, channel_name
[i
]);
3358 err
= alc_auto_create_extra_out(codec
, pins
[i
], dacs
[i
],
3361 err
= alc_auto_create_extra_out(codec
, pins
[i
], dacs
[i
],
3370 /* Let's create a bind-controls */
3371 ctl
= new_bind_ctl(codec
, num_pins
, &snd_hda_bind_sw
);
3375 for (i
= 0; i
< num_pins
; i
++) {
3376 if (get_wcaps(codec
, pins
[i
]) & AC_WCAP_OUT_AMP
)
3378 HDA_COMPOSE_AMP_VAL(pins
[i
], 3, 0, HDA_OUTPUT
);
3381 snprintf(name
, sizeof(name
), "%s Playback Switch", pfx
);
3382 err
= add_control(spec
, ALC_CTL_BIND_SW
, name
, 0, (long)ctl
);
3387 ctl
= new_bind_ctl(codec
, num_pins
, &snd_hda_bind_vol
);
3391 for (i
= 0; i
< num_pins
; i
++) {
3393 if (!pins
[i
] || !dacs
[i
])
3395 vol
= alc_look_for_out_vol_nid(codec
, pins
[i
], dacs
[i
]);
3398 HDA_COMPOSE_AMP_VAL(vol
, 3, 0, HDA_OUTPUT
);
3401 snprintf(name
, sizeof(name
), "%s Playback Volume", pfx
);
3402 err
= add_control(spec
, ALC_CTL_BIND_VOL
, name
, 0, (long)ctl
);
3409 static int alc_auto_create_hp_out(struct hda_codec
*codec
)
3411 struct alc_spec
*spec
= codec
->spec
;
3412 return alc_auto_create_extra_outs(codec
, spec
->autocfg
.hp_outs
,
3413 spec
->autocfg
.hp_pins
,
3414 spec
->multiout
.hp_out_nid
,
3418 static int alc_auto_create_speaker_out(struct hda_codec
*codec
)
3420 struct alc_spec
*spec
= codec
->spec
;
3421 return alc_auto_create_extra_outs(codec
, spec
->autocfg
.speaker_outs
,
3422 spec
->autocfg
.speaker_pins
,
3423 spec
->multiout
.extra_out_nid
,
3427 static void alc_auto_set_output_and_unmute(struct hda_codec
*codec
,
3428 hda_nid_t pin
, int pin_type
,
3432 hda_nid_t nid
, mix
= 0;
3433 hda_nid_t srcs
[HDA_MAX_CONNECTIONS
];
3435 alc_set_pin_output(codec
, pin
, pin_type
);
3436 nid
= alc_go_down_to_selector(codec
, pin
);
3437 num
= snd_hda_get_connections(codec
, nid
, srcs
, ARRAY_SIZE(srcs
));
3438 for (i
= 0; i
< num
; i
++) {
3439 if (alc_auto_mix_to_dac(codec
, srcs
[i
]) != dac
)
3447 /* need the manual connection? */
3449 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_CONNECT_SEL
, i
);
3450 /* unmute mixer widget inputs */
3451 if (nid_has_mute(codec
, mix
, HDA_INPUT
)) {
3452 snd_hda_codec_write(codec
, mix
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
3454 snd_hda_codec_write(codec
, mix
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
3457 /* initialize volume */
3458 nid
= alc_look_for_out_vol_nid(codec
, pin
, dac
);
3460 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
3463 /* unmute DAC if it's not assigned to a mixer */
3464 nid
= alc_look_for_out_mute_nid(codec
, pin
, dac
);
3465 if (nid
== mix
&& nid_has_mute(codec
, dac
, HDA_OUTPUT
))
3466 snd_hda_codec_write(codec
, dac
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
3470 static void alc_auto_init_multi_out(struct hda_codec
*codec
)
3472 struct alc_spec
*spec
= codec
->spec
;
3473 int pin_type
= get_pin_type(spec
->autocfg
.line_out_type
);
3476 for (i
= 0; i
<= HDA_SIDE
; i
++) {
3477 hda_nid_t nid
= spec
->autocfg
.line_out_pins
[i
];
3479 alc_auto_set_output_and_unmute(codec
, nid
, pin_type
,
3480 spec
->multiout
.dac_nids
[i
]);
3484 static void alc_auto_init_extra_out(struct hda_codec
*codec
)
3486 struct alc_spec
*spec
= codec
->spec
;
3490 for (i
= 0; i
< spec
->autocfg
.hp_outs
; i
++) {
3491 if (spec
->autocfg
.line_out_type
== AUTO_PIN_HP_OUT
)
3493 pin
= spec
->autocfg
.hp_pins
[i
];
3496 dac
= spec
->multiout
.hp_out_nid
[i
];
3498 if (i
> 0 && spec
->multiout
.hp_out_nid
[0])
3499 dac
= spec
->multiout
.hp_out_nid
[0];
3501 dac
= spec
->multiout
.dac_nids
[0];
3503 alc_auto_set_output_and_unmute(codec
, pin
, PIN_HP
, dac
);
3505 for (i
= 0; i
< spec
->autocfg
.speaker_outs
; i
++) {
3506 if (spec
->autocfg
.line_out_type
== AUTO_PIN_SPEAKER_OUT
)
3508 pin
= spec
->autocfg
.speaker_pins
[i
];
3511 dac
= spec
->multiout
.extra_out_nid
[i
];
3513 if (i
> 0 && spec
->multiout
.extra_out_nid
[0])
3514 dac
= spec
->multiout
.extra_out_nid
[0];
3516 dac
= spec
->multiout
.dac_nids
[0];
3518 alc_auto_set_output_and_unmute(codec
, pin
, PIN_OUT
, dac
);
3525 static int alc_auto_fill_multi_ios(struct hda_codec
*codec
,
3526 unsigned int location
,
3529 struct alc_spec
*spec
= codec
->spec
;
3530 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
3531 hda_nid_t prime_dac
= spec
->private_dac_nids
[0];
3532 int type
, i
, dacs
, num_pins
= 0;
3534 dacs
= spec
->multiout
.num_dacs
;
3535 for (type
= AUTO_PIN_LINE_IN
; type
>= AUTO_PIN_MIC
; type
--) {
3536 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
3537 hda_nid_t nid
= cfg
->inputs
[i
].pin
;
3539 unsigned int defcfg
, caps
;
3540 if (cfg
->inputs
[i
].type
!= type
)
3542 defcfg
= snd_hda_codec_get_pincfg(codec
, nid
);
3543 if (get_defcfg_connect(defcfg
) != AC_JACK_PORT_COMPLEX
)
3545 if (location
&& get_defcfg_location(defcfg
) != location
)
3547 caps
= snd_hda_query_pin_caps(codec
, nid
);
3548 if (!(caps
& AC_PINCAP_OUT
))
3550 if (offset
&& offset
+ num_pins
< dacs
) {
3551 dac
= spec
->private_dac_nids
[offset
+ num_pins
];
3552 if (!alc_auto_is_dac_reachable(codec
, nid
, dac
))
3556 dac
= alc_auto_look_for_dac(codec
, nid
);
3559 spec
->multi_io
[num_pins
].pin
= nid
;
3560 spec
->multi_io
[num_pins
].dac
= dac
;
3562 spec
->private_dac_nids
[spec
->multiout
.num_dacs
++] = dac
;
3565 spec
->multiout
.num_dacs
= dacs
;
3567 /* clear up again */
3568 memset(spec
->private_dac_nids
+ dacs
, 0,
3569 sizeof(hda_nid_t
) * (AUTO_CFG_MAX_OUTS
- dacs
));
3570 spec
->private_dac_nids
[0] = prime_dac
;
3576 static int alc_auto_ch_mode_info(struct snd_kcontrol
*kcontrol
,
3577 struct snd_ctl_elem_info
*uinfo
)
3579 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3580 struct alc_spec
*spec
= codec
->spec
;
3582 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
3584 uinfo
->value
.enumerated
.items
= spec
->multi_ios
+ 1;
3585 if (uinfo
->value
.enumerated
.item
> spec
->multi_ios
)
3586 uinfo
->value
.enumerated
.item
= spec
->multi_ios
;
3587 sprintf(uinfo
->value
.enumerated
.name
, "%dch",
3588 (uinfo
->value
.enumerated
.item
+ 1) * 2);
3592 static int alc_auto_ch_mode_get(struct snd_kcontrol
*kcontrol
,
3593 struct snd_ctl_elem_value
*ucontrol
)
3595 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3596 struct alc_spec
*spec
= codec
->spec
;
3597 ucontrol
->value
.enumerated
.item
[0] = (spec
->ext_channel_count
- 1) / 2;
3601 static int alc_set_multi_io(struct hda_codec
*codec
, int idx
, bool output
)
3603 struct alc_spec
*spec
= codec
->spec
;
3604 hda_nid_t nid
= spec
->multi_io
[idx
].pin
;
3606 if (!spec
->multi_io
[idx
].ctl_in
)
3607 spec
->multi_io
[idx
].ctl_in
=
3608 snd_hda_codec_read(codec
, nid
, 0,
3609 AC_VERB_GET_PIN_WIDGET_CONTROL
, 0);
3611 snd_hda_codec_update_cache(codec
, nid
, 0,
3612 AC_VERB_SET_PIN_WIDGET_CONTROL
,
3614 if (get_wcaps(codec
, nid
) & AC_WCAP_OUT_AMP
)
3615 snd_hda_codec_amp_stereo(codec
, nid
, HDA_OUTPUT
, 0,
3617 alc_auto_select_dac(codec
, nid
, spec
->multi_io
[idx
].dac
);
3619 if (get_wcaps(codec
, nid
) & AC_WCAP_OUT_AMP
)
3620 snd_hda_codec_amp_stereo(codec
, nid
, HDA_OUTPUT
, 0,
3621 HDA_AMP_MUTE
, HDA_AMP_MUTE
);
3622 snd_hda_codec_update_cache(codec
, nid
, 0,
3623 AC_VERB_SET_PIN_WIDGET_CONTROL
,
3624 spec
->multi_io
[idx
].ctl_in
);
3629 static int alc_auto_ch_mode_put(struct snd_kcontrol
*kcontrol
,
3630 struct snd_ctl_elem_value
*ucontrol
)
3632 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3633 struct alc_spec
*spec
= codec
->spec
;
3636 ch
= ucontrol
->value
.enumerated
.item
[0];
3637 if (ch
< 0 || ch
> spec
->multi_ios
)
3639 if (ch
== (spec
->ext_channel_count
- 1) / 2)
3641 spec
->ext_channel_count
= (ch
+ 1) * 2;
3642 for (i
= 0; i
< spec
->multi_ios
; i
++)
3643 alc_set_multi_io(codec
, i
, i
< ch
);
3644 spec
->multiout
.max_channels
= spec
->ext_channel_count
;
3645 if (spec
->need_dac_fix
&& !spec
->const_channel_count
)
3646 spec
->multiout
.num_dacs
= spec
->multiout
.max_channels
/ 2;
3650 static const struct snd_kcontrol_new alc_auto_channel_mode_enum
= {
3651 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
3652 .name
= "Channel Mode",
3653 .info
= alc_auto_ch_mode_info
,
3654 .get
= alc_auto_ch_mode_get
,
3655 .put
= alc_auto_ch_mode_put
,
3658 static int alc_auto_add_multi_channel_mode(struct hda_codec
*codec
)
3660 struct alc_spec
*spec
= codec
->spec
;
3662 if (spec
->multi_ios
> 0) {
3663 struct snd_kcontrol_new
*knew
;
3665 knew
= alc_kcontrol_new(spec
);
3668 *knew
= alc_auto_channel_mode_enum
;
3669 knew
->name
= kstrdup("Channel Mode", GFP_KERNEL
);
3676 /* filter out invalid adc_nids (and capsrc_nids) that don't give all
3679 static void alc_remove_invalid_adc_nids(struct hda_codec
*codec
)
3681 struct alc_spec
*spec
= codec
->spec
;
3682 const struct hda_input_mux
*imux
;
3683 hda_nid_t adc_nids
[ARRAY_SIZE(spec
->private_adc_nids
)];
3684 hda_nid_t capsrc_nids
[ARRAY_SIZE(spec
->private_adc_nids
)];
3687 imux
= spec
->input_mux
;
3690 if (spec
->dyn_adc_switch
)
3694 for (n
= 0; n
< spec
->num_adc_nids
; n
++) {
3695 hda_nid_t cap
= spec
->private_capsrc_nids
[n
];
3696 int num_conns
= snd_hda_get_conn_list(codec
, cap
, NULL
);
3697 for (i
= 0; i
< imux
->num_items
; i
++) {
3698 hda_nid_t pin
= spec
->imux_pins
[i
];
3700 if (get_connection_index(codec
, cap
, pin
) < 0)
3702 } else if (num_conns
<= imux
->items
[i
].index
)
3705 if (i
>= imux
->num_items
) {
3706 adc_nids
[nums
] = spec
->private_adc_nids
[n
];
3707 capsrc_nids
[nums
++] = cap
;
3711 /* check whether ADC-switch is possible */
3712 if (!alc_check_dyn_adc_switch(codec
)) {
3713 printk(KERN_WARNING
"hda_codec: %s: no valid ADC found;"
3714 " using fallback 0x%x\n",
3715 codec
->chip_name
, spec
->private_adc_nids
[0]);
3716 spec
->num_adc_nids
= 1;
3720 } else if (nums
!= spec
->num_adc_nids
) {
3721 memcpy(spec
->private_adc_nids
, adc_nids
,
3722 nums
* sizeof(hda_nid_t
));
3723 memcpy(spec
->private_capsrc_nids
, capsrc_nids
,
3724 nums
* sizeof(hda_nid_t
));
3725 spec
->num_adc_nids
= nums
;
3729 alc_auto_mic_check_imux(codec
); /* check auto-mic setups */
3730 else if (spec
->input_mux
->num_items
== 1)
3731 spec
->num_adc_nids
= 1; /* reduce to a single ADC */
3735 * initialize ADC paths
3737 static void alc_auto_init_adc(struct hda_codec
*codec
, int adc_idx
)
3739 struct alc_spec
*spec
= codec
->spec
;
3742 nid
= spec
->adc_nids
[adc_idx
];
3744 if (nid_has_mute(codec
, nid
, HDA_INPUT
)) {
3745 snd_hda_codec_write(codec
, nid
, 0,
3746 AC_VERB_SET_AMP_GAIN_MUTE
,
3750 if (!spec
->capsrc_nids
)
3752 nid
= spec
->capsrc_nids
[adc_idx
];
3753 if (nid_has_mute(codec
, nid
, HDA_OUTPUT
))
3754 snd_hda_codec_write(codec
, nid
, 0,
3755 AC_VERB_SET_AMP_GAIN_MUTE
,
3759 static void alc_auto_init_input_src(struct hda_codec
*codec
)
3761 struct alc_spec
*spec
= codec
->spec
;
3764 for (c
= 0; c
< spec
->num_adc_nids
; c
++)
3765 alc_auto_init_adc(codec
, c
);
3766 if (spec
->dyn_adc_switch
)
3769 nums
= spec
->num_adc_nids
;
3770 for (c
= 0; c
< nums
; c
++)
3771 alc_mux_select(codec
, 0, spec
->cur_mux
[c
], true);
3774 /* add mic boosts if needed */
3775 static int alc_auto_add_mic_boost(struct hda_codec
*codec
)
3777 struct alc_spec
*spec
= codec
->spec
;
3778 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
3782 const char *prev_label
= NULL
;
3784 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
3785 if (cfg
->inputs
[i
].type
> AUTO_PIN_MIC
)
3787 nid
= cfg
->inputs
[i
].pin
;
3788 if (get_wcaps(codec
, nid
) & AC_WCAP_IN_AMP
) {
3790 char boost_label
[32];
3792 label
= hda_get_autocfg_input_label(codec
, cfg
, i
);
3793 if (spec
->shared_mic_hp
&& !strcmp(label
, "Misc"))
3794 label
= "Headphone Mic";
3795 if (prev_label
&& !strcmp(label
, prev_label
))
3801 snprintf(boost_label
, sizeof(boost_label
),
3802 "%s Boost Volume", label
);
3803 err
= add_control(spec
, ALC_CTL_WIDGET_VOL
,
3804 boost_label
, type_idx
,
3805 HDA_COMPOSE_AMP_VAL(nid
, 3, 0, HDA_INPUT
));
3813 /* select or unmute the given capsrc route */
3814 static void select_or_unmute_capsrc(struct hda_codec
*codec
, hda_nid_t cap
,
3817 if (get_wcaps_type(get_wcaps(codec
, cap
)) == AC_WID_AUD_MIX
) {
3818 snd_hda_codec_amp_stereo(codec
, cap
, HDA_INPUT
, idx
,
3820 } else if (snd_hda_get_conn_list(codec
, cap
, NULL
) > 1) {
3821 snd_hda_codec_write_cache(codec
, cap
, 0,
3822 AC_VERB_SET_CONNECT_SEL
, idx
);
3826 /* set the default connection to that pin */
3827 static int init_capsrc_for_pin(struct hda_codec
*codec
, hda_nid_t pin
)
3829 struct alc_spec
*spec
= codec
->spec
;
3834 for (i
= 0; i
< spec
->num_adc_nids
; i
++) {
3835 hda_nid_t cap
= get_capsrc(spec
, i
);
3838 idx
= get_connection_index(codec
, cap
, pin
);
3841 select_or_unmute_capsrc(codec
, cap
, idx
);
3842 return i
; /* return the found index */
3844 return -1; /* not found */
3847 /* initialize some special cases for input sources */
3848 static void alc_init_special_input_src(struct hda_codec
*codec
)
3850 struct alc_spec
*spec
= codec
->spec
;
3853 for (i
= 0; i
< spec
->autocfg
.num_inputs
; i
++)
3854 init_capsrc_for_pin(codec
, spec
->autocfg
.inputs
[i
].pin
);
3857 /* assign appropriate capture mixers */
3858 static void set_capture_mixer(struct hda_codec
*codec
)
3860 struct alc_spec
*spec
= codec
->spec
;
3861 static const struct snd_kcontrol_new
*caps
[2][3] = {
3862 { alc_capture_mixer_nosrc1
,
3863 alc_capture_mixer_nosrc2
,
3864 alc_capture_mixer_nosrc3
},
3865 { alc_capture_mixer1
,
3867 alc_capture_mixer3
},
3870 /* check whether either of ADC or MUX has a volume control */
3871 if (!nid_has_volume(codec
, spec
->adc_nids
[0], HDA_INPUT
)) {
3872 if (!spec
->capsrc_nids
)
3873 return; /* no volume */
3874 if (!nid_has_volume(codec
, spec
->capsrc_nids
[0], HDA_OUTPUT
))
3875 return; /* no volume in capsrc, too */
3876 spec
->vol_in_capsrc
= 1;
3879 if (spec
->num_adc_nids
> 0) {
3883 if (spec
->input_mux
&& spec
->input_mux
->num_items
> 1)
3885 if (spec
->auto_mic
) {
3888 } else if (spec
->dyn_adc_switch
)
3891 if (spec
->num_adc_nids
> 3)
3892 spec
->num_adc_nids
= 3;
3893 else if (!spec
->num_adc_nids
)
3895 num_adcs
= spec
->num_adc_nids
;
3897 spec
->cap_mixer
= caps
[mux
][num_adcs
- 1];
3902 * standard auto-parser initializations
3904 static void alc_auto_init_std(struct hda_codec
*codec
)
3906 struct alc_spec
*spec
= codec
->spec
;
3907 spec
->use_jack_tbl
= 1;
3908 alc_auto_init_multi_out(codec
);
3909 alc_auto_init_extra_out(codec
);
3910 alc_auto_init_analog_input(codec
);
3911 alc_auto_init_input_src(codec
);
3912 alc_auto_init_digital(codec
);
3913 if (spec
->unsol_event
)
3914 alc_inithook(codec
);
3918 * Digital-beep handlers
3920 #ifdef CONFIG_SND_HDA_INPUT_BEEP
3921 #define set_beep_amp(spec, nid, idx, dir) \
3922 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
3924 static const struct snd_pci_quirk beep_white_list
[] = {
3925 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
3926 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
3927 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
3928 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
3929 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
3933 static inline int has_cdefine_beep(struct hda_codec
*codec
)
3935 struct alc_spec
*spec
= codec
->spec
;
3936 const struct snd_pci_quirk
*q
;
3937 q
= snd_pci_quirk_lookup(codec
->bus
->pci
, beep_white_list
);
3940 return spec
->cdefine
.enable_pcbeep
;
3943 #define set_beep_amp(spec, nid, idx, dir) /* NOP */
3944 #define has_cdefine_beep(codec) 0
3947 /* parse the BIOS configuration and set up the alc_spec */
3948 /* return 1 if successful, 0 if the proper config is not found,
3949 * or a negative error code
3951 static int alc_parse_auto_config(struct hda_codec
*codec
,
3952 const hda_nid_t
*ignore_nids
,
3953 const hda_nid_t
*ssid_nids
)
3955 struct alc_spec
*spec
= codec
->spec
;
3956 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
3959 err
= snd_hda_parse_pin_defcfg(codec
, cfg
, ignore_nids
,
3963 if (!cfg
->line_outs
) {
3964 if (cfg
->dig_outs
|| cfg
->dig_in_pin
) {
3965 spec
->multiout
.max_channels
= 2;
3966 spec
->no_analog
= 1;
3969 return 0; /* can't find valid BIOS pin config */
3972 if (cfg
->line_out_type
== AUTO_PIN_SPEAKER_OUT
&&
3973 cfg
->line_outs
<= cfg
->hp_outs
) {
3974 /* use HP as primary out */
3975 cfg
->speaker_outs
= cfg
->line_outs
;
3976 memcpy(cfg
->speaker_pins
, cfg
->line_out_pins
,
3977 sizeof(cfg
->speaker_pins
));
3978 cfg
->line_outs
= cfg
->hp_outs
;
3979 memcpy(cfg
->line_out_pins
, cfg
->hp_pins
, sizeof(cfg
->hp_pins
));
3981 memset(cfg
->hp_pins
, 0, sizeof(cfg
->hp_pins
));
3982 cfg
->line_out_type
= AUTO_PIN_HP_OUT
;
3985 err
= alc_auto_fill_dac_nids(codec
);
3988 err
= alc_auto_add_multi_channel_mode(codec
);
3991 err
= alc_auto_create_multi_out_ctls(codec
, cfg
);
3994 err
= alc_auto_create_hp_out(codec
);
3997 err
= alc_auto_create_speaker_out(codec
);
4000 err
= alc_auto_create_shared_input(codec
);
4003 err
= alc_auto_create_input_ctls(codec
);
4007 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
4010 alc_auto_parse_digital(codec
);
4012 if (!spec
->no_analog
)
4013 alc_remove_invalid_adc_nids(codec
);
4016 alc_ssid_check(codec
, ssid_nids
);
4018 if (!spec
->no_analog
) {
4019 alc_auto_check_switches(codec
);
4020 err
= alc_auto_add_mic_boost(codec
);
4025 if (spec
->kctls
.list
)
4026 add_mixer(spec
, spec
->kctls
.list
);
4031 static int alc880_parse_auto_config(struct hda_codec
*codec
)
4033 static const hda_nid_t alc880_ignore
[] = { 0x1d, 0 };
4034 static const hda_nid_t alc880_ssids
[] = { 0x15, 0x1b, 0x14, 0 };
4035 return alc_parse_auto_config(codec
, alc880_ignore
, alc880_ssids
);
4038 #ifdef CONFIG_SND_HDA_POWER_SAVE
4039 static const struct hda_amp_list alc880_loopbacks
[] = {
4040 { 0x0b, HDA_INPUT
, 0 },
4041 { 0x0b, HDA_INPUT
, 1 },
4042 { 0x0b, HDA_INPUT
, 2 },
4043 { 0x0b, HDA_INPUT
, 3 },
4044 { 0x0b, HDA_INPUT
, 4 },
4054 ALC880_FIXUP_MEDION_RIM
,
4057 static const struct alc_fixup alc880_fixups
[] = {
4058 [ALC880_FIXUP_GPIO2
] = {
4059 .type
= ALC_FIXUP_VERBS
,
4060 .v
.verbs
= alc_gpio2_init_verbs
,
4062 [ALC880_FIXUP_MEDION_RIM
] = {
4063 .type
= ALC_FIXUP_VERBS
,
4064 .v
.verbs
= (const struct hda_verb
[]) {
4065 { 0x20, AC_VERB_SET_COEF_INDEX
, 0x07 },
4066 { 0x20, AC_VERB_SET_PROC_COEF
, 0x3060 },
4070 .chain_id
= ALC880_FIXUP_GPIO2
,
4074 static const struct snd_pci_quirk alc880_fixup_tbl
[] = {
4075 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM
),
4083 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4084 #define alc_board_config \
4085 snd_hda_check_board_config
4086 #define alc_board_codec_sid_config \
4087 snd_hda_check_board_codec_sid_config
4088 #include "alc_quirks.c"
4090 #define alc_board_config(codec, nums, models, tbl) -1
4091 #define alc_board_codec_sid_config(codec, nums, models, tbl) -1
4092 #define setup_preset(codec, x) /* NOP */
4096 * OK, here we have finally the patch for ALC880
4098 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4099 #include "alc880_quirks.c"
4102 static int patch_alc880(struct hda_codec
*codec
)
4104 struct alc_spec
*spec
;
4108 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
4114 spec
->mixer_nid
= 0x0b;
4115 spec
->need_dac_fix
= 1;
4117 board_config
= alc_board_config(codec
, ALC880_MODEL_LAST
,
4118 alc880_models
, alc880_cfg_tbl
);
4119 if (board_config
< 0) {
4120 printk(KERN_INFO
"hda_codec: %s: BIOS auto-probing.\n",
4122 board_config
= ALC_MODEL_AUTO
;
4125 if (board_config
== ALC_MODEL_AUTO
) {
4126 alc_pick_fixup(codec
, NULL
, alc880_fixup_tbl
, alc880_fixups
);
4127 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
4130 if (board_config
== ALC_MODEL_AUTO
) {
4131 /* automatic parse from the BIOS config */
4132 err
= alc880_parse_auto_config(codec
);
4135 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4138 "hda_codec: Cannot set up configuration "
4139 "from BIOS. Using 3-stack mode...\n");
4140 board_config
= ALC880_3ST
;
4145 if (board_config
!= ALC_MODEL_AUTO
) {
4146 spec
->vmaster_nid
= 0x0c;
4147 setup_preset(codec
, &alc880_presets
[board_config
]);
4150 if (!spec
->no_analog
&& !spec
->adc_nids
) {
4151 alc_auto_fill_adc_caps(codec
);
4152 alc_rebuild_imux_for_auto_mic(codec
);
4153 alc_remove_invalid_adc_nids(codec
);
4156 if (!spec
->no_analog
&& !spec
->cap_mixer
)
4157 set_capture_mixer(codec
);
4159 if (!spec
->no_analog
) {
4160 err
= snd_hda_attach_beep_device(codec
, 0x1);
4163 set_beep_amp(spec
, 0x0b, 0x05, HDA_INPUT
);
4166 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
4168 codec
->patch_ops
= alc_patch_ops
;
4169 if (board_config
== ALC_MODEL_AUTO
)
4170 spec
->init_hook
= alc_auto_init_std
;
4171 #ifdef CONFIG_SND_HDA_POWER_SAVE
4172 if (!spec
->loopback
.amplist
)
4173 spec
->loopback
.amplist
= alc880_loopbacks
;
4187 static int alc260_parse_auto_config(struct hda_codec
*codec
)
4189 static const hda_nid_t alc260_ignore
[] = { 0x17, 0 };
4190 static const hda_nid_t alc260_ssids
[] = { 0x10, 0x15, 0x0f, 0 };
4191 return alc_parse_auto_config(codec
, alc260_ignore
, alc260_ssids
);
4194 #ifdef CONFIG_SND_HDA_POWER_SAVE
4195 static const struct hda_amp_list alc260_loopbacks
[] = {
4196 { 0x07, HDA_INPUT
, 0 },
4197 { 0x07, HDA_INPUT
, 1 },
4198 { 0x07, HDA_INPUT
, 2 },
4199 { 0x07, HDA_INPUT
, 3 },
4200 { 0x07, HDA_INPUT
, 4 },
4212 static const struct alc_fixup alc260_fixups
[] = {
4213 [PINFIX_HP_DC5750
] = {
4214 .type
= ALC_FIXUP_PINS
,
4215 .v
.pins
= (const struct alc_pincfg
[]) {
4216 { 0x11, 0x90130110 }, /* speaker */
4222 static const struct snd_pci_quirk alc260_fixup_tbl
[] = {
4223 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", PINFIX_HP_DC5750
),
4229 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4230 #include "alc260_quirks.c"
4233 static int patch_alc260(struct hda_codec
*codec
)
4235 struct alc_spec
*spec
;
4236 int err
, board_config
;
4238 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
4244 spec
->mixer_nid
= 0x07;
4246 board_config
= alc_board_config(codec
, ALC260_MODEL_LAST
,
4247 alc260_models
, alc260_cfg_tbl
);
4248 if (board_config
< 0) {
4249 snd_printd(KERN_INFO
"hda_codec: %s: BIOS auto-probing.\n",
4251 board_config
= ALC_MODEL_AUTO
;
4254 if (board_config
== ALC_MODEL_AUTO
) {
4255 alc_pick_fixup(codec
, NULL
, alc260_fixup_tbl
, alc260_fixups
);
4256 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
4259 if (board_config
== ALC_MODEL_AUTO
) {
4260 /* automatic parse from the BIOS config */
4261 err
= alc260_parse_auto_config(codec
);
4264 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4267 "hda_codec: Cannot set up configuration "
4268 "from BIOS. Using base mode...\n");
4269 board_config
= ALC260_BASIC
;
4274 if (board_config
!= ALC_MODEL_AUTO
) {
4275 setup_preset(codec
, &alc260_presets
[board_config
]);
4276 spec
->vmaster_nid
= 0x08;
4279 if (!spec
->no_analog
&& !spec
->adc_nids
) {
4280 alc_auto_fill_adc_caps(codec
);
4281 alc_rebuild_imux_for_auto_mic(codec
);
4282 alc_remove_invalid_adc_nids(codec
);
4285 if (!spec
->no_analog
&& !spec
->cap_mixer
)
4286 set_capture_mixer(codec
);
4288 if (!spec
->no_analog
) {
4289 err
= snd_hda_attach_beep_device(codec
, 0x1);
4292 set_beep_amp(spec
, 0x07, 0x05, HDA_INPUT
);
4295 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
4297 codec
->patch_ops
= alc_patch_ops
;
4298 if (board_config
== ALC_MODEL_AUTO
)
4299 spec
->init_hook
= alc_auto_init_std
;
4300 spec
->shutup
= alc_eapd_shutup
;
4301 #ifdef CONFIG_SND_HDA_POWER_SAVE
4302 if (!spec
->loopback
.amplist
)
4303 spec
->loopback
.amplist
= alc260_loopbacks
;
4315 * ALC882/883/885/888/889 support
4317 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
4318 * configuration. Each pin widget can choose any input DACs and a mixer.
4319 * Each ADC is connected from a mixer of all inputs. This makes possible
4320 * 6-channel independent captures.
4322 * In addition, an independent DAC for the multi-playback (not used in this
4325 #ifdef CONFIG_SND_HDA_POWER_SAVE
4326 #define alc882_loopbacks alc880_loopbacks
4333 ALC882_FIXUP_ABIT_AW9D_MAX
,
4334 ALC882_FIXUP_LENOVO_Y530
,
4335 ALC882_FIXUP_PB_M5210
,
4336 ALC882_FIXUP_ACER_ASPIRE_7736
,
4337 ALC882_FIXUP_ASUS_W90V
,
4338 ALC889_FIXUP_VAIO_TT
,
4339 ALC888_FIXUP_EEE1601
,
4342 ALC883_FIXUP_ACER_EAPD
,
4345 ALC882_FIXUP_ASUS_W2JC
,
4346 ALC882_FIXUP_ACER_ASPIRE_4930G
,
4347 ALC882_FIXUP_ACER_ASPIRE_8930G
,
4348 ALC882_FIXUP_ASPIRE_8930G_VERBS
,
4349 ALC885_FIXUP_MACPRO_GPIO
,
4352 static void alc889_fixup_coef(struct hda_codec
*codec
,
4353 const struct alc_fixup
*fix
, int action
)
4355 if (action
!= ALC_FIXUP_ACT_INIT
)
4357 alc889_coef_init(codec
);
4360 /* toggle speaker-output according to the hp-jack state */
4361 static void alc882_gpio_mute(struct hda_codec
*codec
, int pin
, int muted
)
4363 unsigned int gpiostate
, gpiomask
, gpiodir
;
4365 gpiostate
= snd_hda_codec_read(codec
, codec
->afg
, 0,
4366 AC_VERB_GET_GPIO_DATA
, 0);
4369 gpiostate
|= (1 << pin
);
4371 gpiostate
&= ~(1 << pin
);
4373 gpiomask
= snd_hda_codec_read(codec
, codec
->afg
, 0,
4374 AC_VERB_GET_GPIO_MASK
, 0);
4375 gpiomask
|= (1 << pin
);
4377 gpiodir
= snd_hda_codec_read(codec
, codec
->afg
, 0,
4378 AC_VERB_GET_GPIO_DIRECTION
, 0);
4379 gpiodir
|= (1 << pin
);
4382 snd_hda_codec_write(codec
, codec
->afg
, 0,
4383 AC_VERB_SET_GPIO_MASK
, gpiomask
);
4384 snd_hda_codec_write(codec
, codec
->afg
, 0,
4385 AC_VERB_SET_GPIO_DIRECTION
, gpiodir
);
4389 snd_hda_codec_write(codec
, codec
->afg
, 0,
4390 AC_VERB_SET_GPIO_DATA
, gpiostate
);
4393 /* set up GPIO at initialization */
4394 static void alc885_fixup_macpro_gpio(struct hda_codec
*codec
,
4395 const struct alc_fixup
*fix
, int action
)
4397 if (action
!= ALC_FIXUP_ACT_INIT
)
4399 alc882_gpio_mute(codec
, 0, 0);
4400 alc882_gpio_mute(codec
, 1, 0);
4403 static const struct alc_fixup alc882_fixups
[] = {
4404 [ALC882_FIXUP_ABIT_AW9D_MAX
] = {
4405 .type
= ALC_FIXUP_PINS
,
4406 .v
.pins
= (const struct alc_pincfg
[]) {
4407 { 0x15, 0x01080104 }, /* side */
4408 { 0x16, 0x01011012 }, /* rear */
4409 { 0x17, 0x01016011 }, /* clfe */
4413 [ALC882_FIXUP_LENOVO_Y530
] = {
4414 .type
= ALC_FIXUP_PINS
,
4415 .v
.pins
= (const struct alc_pincfg
[]) {
4416 { 0x15, 0x99130112 }, /* rear int speakers */
4417 { 0x16, 0x99130111 }, /* subwoofer */
4421 [ALC882_FIXUP_PB_M5210
] = {
4422 .type
= ALC_FIXUP_VERBS
,
4423 .v
.verbs
= (const struct hda_verb
[]) {
4424 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_VREF50
},
4428 [ALC882_FIXUP_ACER_ASPIRE_7736
] = {
4429 .type
= ALC_FIXUP_SKU
,
4430 .v
.sku
= ALC_FIXUP_SKU_IGNORE
,
4432 [ALC882_FIXUP_ASUS_W90V
] = {
4433 .type
= ALC_FIXUP_PINS
,
4434 .v
.pins
= (const struct alc_pincfg
[]) {
4435 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
4439 [ALC889_FIXUP_VAIO_TT
] = {
4440 .type
= ALC_FIXUP_PINS
,
4441 .v
.pins
= (const struct alc_pincfg
[]) {
4442 { 0x17, 0x90170111 }, /* hidden surround speaker */
4446 [ALC888_FIXUP_EEE1601
] = {
4447 .type
= ALC_FIXUP_VERBS
,
4448 .v
.verbs
= (const struct hda_verb
[]) {
4449 { 0x20, AC_VERB_SET_COEF_INDEX
, 0x0b },
4450 { 0x20, AC_VERB_SET_PROC_COEF
, 0x0838 },
4454 [ALC882_FIXUP_EAPD
] = {
4455 .type
= ALC_FIXUP_VERBS
,
4456 .v
.verbs
= (const struct hda_verb
[]) {
4457 /* change to EAPD mode */
4458 { 0x20, AC_VERB_SET_COEF_INDEX
, 0x07 },
4459 { 0x20, AC_VERB_SET_PROC_COEF
, 0x3060 },
4463 [ALC883_FIXUP_EAPD
] = {
4464 .type
= ALC_FIXUP_VERBS
,
4465 .v
.verbs
= (const struct hda_verb
[]) {
4466 /* change to EAPD mode */
4467 { 0x20, AC_VERB_SET_COEF_INDEX
, 0x07 },
4468 { 0x20, AC_VERB_SET_PROC_COEF
, 0x3070 },
4472 [ALC883_FIXUP_ACER_EAPD
] = {
4473 .type
= ALC_FIXUP_VERBS
,
4474 .v
.verbs
= (const struct hda_verb
[]) {
4475 /* eanable EAPD on Acer laptops */
4476 { 0x20, AC_VERB_SET_COEF_INDEX
, 0x07 },
4477 { 0x20, AC_VERB_SET_PROC_COEF
, 0x3050 },
4481 [ALC882_FIXUP_GPIO3
] = {
4482 .type
= ALC_FIXUP_VERBS
,
4483 .v
.verbs
= alc_gpio3_init_verbs
,
4485 [ALC882_FIXUP_ASUS_W2JC
] = {
4486 .type
= ALC_FIXUP_VERBS
,
4487 .v
.verbs
= alc_gpio1_init_verbs
,
4489 .chain_id
= ALC882_FIXUP_EAPD
,
4491 [ALC889_FIXUP_COEF
] = {
4492 .type
= ALC_FIXUP_FUNC
,
4493 .v
.func
= alc889_fixup_coef
,
4495 [ALC882_FIXUP_ACER_ASPIRE_4930G
] = {
4496 .type
= ALC_FIXUP_PINS
,
4497 .v
.pins
= (const struct alc_pincfg
[]) {
4498 { 0x16, 0x99130111 }, /* CLFE speaker */
4499 { 0x17, 0x99130112 }, /* surround speaker */
4503 [ALC882_FIXUP_ACER_ASPIRE_8930G
] = {
4504 .type
= ALC_FIXUP_PINS
,
4505 .v
.pins
= (const struct alc_pincfg
[]) {
4506 { 0x16, 0x99130111 }, /* CLFE speaker */
4507 { 0x1b, 0x99130112 }, /* surround speaker */
4511 .chain_id
= ALC882_FIXUP_ASPIRE_8930G_VERBS
,
4513 [ALC882_FIXUP_ASPIRE_8930G_VERBS
] = {
4514 /* additional init verbs for Acer Aspire 8930G */
4515 .type
= ALC_FIXUP_VERBS
,
4516 .v
.verbs
= (const struct hda_verb
[]) {
4517 /* Enable all DACs */
4518 /* DAC DISABLE/MUTE 1? */
4519 /* setting bits 1-5 disables DAC nids 0x02-0x06
4520 * apparently. Init=0x38 */
4521 { 0x20, AC_VERB_SET_COEF_INDEX
, 0x03 },
4522 { 0x20, AC_VERB_SET_PROC_COEF
, 0x0000 },
4523 /* DAC DISABLE/MUTE 2? */
4524 /* some bit here disables the other DACs.
4526 { 0x20, AC_VERB_SET_COEF_INDEX
, 0x08 },
4527 { 0x20, AC_VERB_SET_PROC_COEF
, 0x0000 },
4529 * This laptop has a stereo digital microphone.
4530 * The mics are only 1cm apart which makes the stereo
4531 * useless. However, either the mic or the ALC889
4532 * makes the signal become a difference/sum signal
4533 * instead of standard stereo, which is annoying.
4534 * So instead we flip this bit which makes the
4535 * codec replicate the sum signal to both channels,
4536 * turning it into a normal mono mic.
4538 /* DMIC_CONTROL? Init value = 0x0001 */
4539 { 0x20, AC_VERB_SET_COEF_INDEX
, 0x0b },
4540 { 0x20, AC_VERB_SET_PROC_COEF
, 0x0003 },
4541 { 0x20, AC_VERB_SET_COEF_INDEX
, 0x07 },
4542 { 0x20, AC_VERB_SET_PROC_COEF
, 0x3050 },
4546 [ALC885_FIXUP_MACPRO_GPIO
] = {
4547 .type
= ALC_FIXUP_FUNC
,
4548 .v
.func
= alc885_fixup_macpro_gpio
,
4552 static const struct snd_pci_quirk alc882_fixup_tbl
[] = {
4553 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD
),
4554 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD
),
4555 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD
),
4556 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD
),
4557 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD
),
4558 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD
),
4559 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
4560 ALC882_FIXUP_ACER_ASPIRE_4930G
),
4561 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
4562 ALC882_FIXUP_ACER_ASPIRE_4930G
),
4563 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
4564 ALC882_FIXUP_ACER_ASPIRE_8930G
),
4565 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
4566 ALC882_FIXUP_ACER_ASPIRE_8930G
),
4567 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
4568 ALC882_FIXUP_ACER_ASPIRE_4930G
),
4569 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
4570 ALC882_FIXUP_ACER_ASPIRE_4930G
),
4571 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
4572 ALC882_FIXUP_ACER_ASPIRE_4930G
),
4573 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210
),
4574 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736
),
4575 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD
),
4576 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V
),
4577 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC
),
4578 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601
),
4579 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT
),
4581 /* All Apple entries are in codec SSIDs */
4582 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO
),
4583 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO
),
4584 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO
),
4585 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD
),
4586 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO
),
4588 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD
),
4589 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3
),
4590 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX
),
4591 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD
),
4592 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD
),
4593 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530
),
4594 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF
),
4599 * BIOS auto configuration
4601 /* almost identical with ALC880 parser... */
4602 static int alc882_parse_auto_config(struct hda_codec
*codec
)
4604 static const hda_nid_t alc882_ignore
[] = { 0x1d, 0 };
4605 static const hda_nid_t alc882_ssids
[] = { 0x15, 0x1b, 0x14, 0 };
4606 return alc_parse_auto_config(codec
, alc882_ignore
, alc882_ssids
);
4611 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4612 #include "alc882_quirks.c"
4615 static int patch_alc882(struct hda_codec
*codec
)
4617 struct alc_spec
*spec
;
4618 int err
, board_config
;
4620 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
4626 spec
->mixer_nid
= 0x0b;
4628 switch (codec
->vendor_id
) {
4633 /* ALC883 and variants */
4634 alc_fix_pll_init(codec
, 0x20, 0x0a, 10);
4638 err
= alc_codec_rename_from_preset(codec
);
4642 board_config
= alc_board_config(codec
, ALC882_MODEL_LAST
,
4643 alc882_models
, NULL
);
4644 if (board_config
< 0)
4645 board_config
= alc_board_codec_sid_config(codec
,
4646 ALC882_MODEL_LAST
, alc882_models
, alc882_ssid_cfg_tbl
);
4648 if (board_config
< 0) {
4649 printk(KERN_INFO
"hda_codec: %s: BIOS auto-probing.\n",
4651 board_config
= ALC_MODEL_AUTO
;
4654 if (board_config
== ALC_MODEL_AUTO
) {
4655 alc_pick_fixup(codec
, NULL
, alc882_fixup_tbl
, alc882_fixups
);
4656 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
4659 alc_auto_parse_customize_define(codec
);
4661 if (board_config
== ALC_MODEL_AUTO
) {
4662 /* automatic parse from the BIOS config */
4663 err
= alc882_parse_auto_config(codec
);
4668 if (board_config
!= ALC_MODEL_AUTO
) {
4669 setup_preset(codec
, &alc882_presets
[board_config
]);
4670 spec
->vmaster_nid
= 0x0c;
4673 if (!spec
->no_analog
&& !spec
->adc_nids
) {
4674 alc_auto_fill_adc_caps(codec
);
4675 alc_rebuild_imux_for_auto_mic(codec
);
4676 alc_remove_invalid_adc_nids(codec
);
4679 if (!spec
->no_analog
&& !spec
->cap_mixer
)
4680 set_capture_mixer(codec
);
4682 if (!spec
->no_analog
&& has_cdefine_beep(codec
)) {
4683 err
= snd_hda_attach_beep_device(codec
, 0x1);
4686 set_beep_amp(spec
, 0x0b, 0x05, HDA_INPUT
);
4689 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
4691 codec
->patch_ops
= alc_patch_ops
;
4692 if (board_config
== ALC_MODEL_AUTO
)
4693 spec
->init_hook
= alc_auto_init_std
;
4695 #ifdef CONFIG_SND_HDA_POWER_SAVE
4696 if (!spec
->loopback
.amplist
)
4697 spec
->loopback
.amplist
= alc882_loopbacks
;
4711 static int alc262_parse_auto_config(struct hda_codec
*codec
)
4713 static const hda_nid_t alc262_ignore
[] = { 0x1d, 0 };
4714 static const hda_nid_t alc262_ssids
[] = { 0x15, 0x1b, 0x14, 0 };
4715 return alc_parse_auto_config(codec
, alc262_ignore
, alc262_ssids
);
4722 ALC262_FIXUP_FSC_H270
,
4723 ALC262_FIXUP_HP_Z200
,
4725 ALC262_FIXUP_TOSHIBA_RX1
,
4726 ALC262_FIXUP_LENOVO_3000
,
4728 ALC262_FIXUP_BENQ_T31
,
4731 static const struct alc_fixup alc262_fixups
[] = {
4732 [ALC262_FIXUP_FSC_H270
] = {
4733 .type
= ALC_FIXUP_PINS
,
4734 .v
.pins
= (const struct alc_pincfg
[]) {
4735 { 0x14, 0x99130110 }, /* speaker */
4736 { 0x15, 0x0221142f }, /* front HP */
4737 { 0x1b, 0x0121141f }, /* rear HP */
4741 [ALC262_FIXUP_HP_Z200
] = {
4742 .type
= ALC_FIXUP_PINS
,
4743 .v
.pins
= (const struct alc_pincfg
[]) {
4744 { 0x16, 0x99130120 }, /* internal speaker */
4748 [ALC262_FIXUP_TYAN
] = {
4749 .type
= ALC_FIXUP_PINS
,
4750 .v
.pins
= (const struct alc_pincfg
[]) {
4751 { 0x14, 0x1993e1f0 }, /* int AUX */
4755 [ALC262_FIXUP_TOSHIBA_RX1
] = {
4756 .type
= ALC_FIXUP_PINS
,
4757 .v
.pins
= (const struct alc_pincfg
[]) {
4758 { 0x14, 0x90170110 }, /* speaker */
4759 { 0x15, 0x0421101f }, /* HP */
4760 { 0x1a, 0x40f000f0 }, /* N/A */
4761 { 0x1b, 0x40f000f0 }, /* N/A */
4762 { 0x1e, 0x40f000f0 }, /* N/A */
4765 [ALC262_FIXUP_LENOVO_3000
] = {
4766 .type
= ALC_FIXUP_VERBS
,
4767 .v
.verbs
= (const struct hda_verb
[]) {
4768 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_VREF50
},
4772 .chain_id
= ALC262_FIXUP_BENQ
,
4774 [ALC262_FIXUP_BENQ
] = {
4775 .type
= ALC_FIXUP_VERBS
,
4776 .v
.verbs
= (const struct hda_verb
[]) {
4777 { 0x20, AC_VERB_SET_COEF_INDEX
, 0x07 },
4778 { 0x20, AC_VERB_SET_PROC_COEF
, 0x3070 },
4782 [ALC262_FIXUP_BENQ_T31
] = {
4783 .type
= ALC_FIXUP_VERBS
,
4784 .v
.verbs
= (const struct hda_verb
[]) {
4785 { 0x20, AC_VERB_SET_COEF_INDEX
, 0x07 },
4786 { 0x20, AC_VERB_SET_PROC_COEF
, 0x3050 },
4792 static const struct snd_pci_quirk alc262_fixup_tbl
[] = {
4793 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200
),
4794 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ
),
4795 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ
),
4796 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN
),
4797 SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1",
4798 ALC262_FIXUP_TOSHIBA_RX1
),
4799 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270
),
4800 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000
),
4801 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ
),
4802 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31
),
4807 #ifdef CONFIG_SND_HDA_POWER_SAVE
4808 #define alc262_loopbacks alc880_loopbacks
4813 static int patch_alc262(struct hda_codec
*codec
)
4815 struct alc_spec
*spec
;
4818 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
4824 spec
->mixer_nid
= 0x0b;
4827 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
4832 snd_hda_codec_write(codec
, 0x1a, 0, AC_VERB_SET_COEF_INDEX
, 7);
4833 tmp
= snd_hda_codec_read(codec
, 0x20, 0, AC_VERB_GET_PROC_COEF
, 0);
4834 snd_hda_codec_write(codec
, 0x1a, 0, AC_VERB_SET_COEF_INDEX
, 7);
4835 snd_hda_codec_write(codec
, 0x1a, 0, AC_VERB_SET_PROC_COEF
, tmp
| 0x80);
4838 alc_auto_parse_customize_define(codec
);
4840 alc_fix_pll_init(codec
, 0x20, 0x0a, 10);
4842 alc_pick_fixup(codec
, NULL
, alc262_fixup_tbl
, alc262_fixups
);
4843 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
4845 /* automatic parse from the BIOS config */
4846 err
= alc262_parse_auto_config(codec
);
4850 if (!spec
->no_analog
&& !spec
->adc_nids
) {
4851 alc_auto_fill_adc_caps(codec
);
4852 alc_rebuild_imux_for_auto_mic(codec
);
4853 alc_remove_invalid_adc_nids(codec
);
4856 if (!spec
->no_analog
&& !spec
->cap_mixer
)
4857 set_capture_mixer(codec
);
4859 if (!spec
->no_analog
&& has_cdefine_beep(codec
)) {
4860 err
= snd_hda_attach_beep_device(codec
, 0x1);
4863 set_beep_amp(spec
, 0x0b, 0x05, HDA_INPUT
);
4866 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
4868 codec
->patch_ops
= alc_patch_ops
;
4869 spec
->init_hook
= alc_auto_init_std
;
4870 spec
->shutup
= alc_eapd_shutup
;
4872 #ifdef CONFIG_SND_HDA_POWER_SAVE
4873 if (!spec
->loopback
.amplist
)
4874 spec
->loopback
.amplist
= alc262_loopbacks
;
4887 /* bind Beep switches of both NID 0x0f and 0x10 */
4888 static const struct hda_bind_ctls alc268_bind_beep_sw
= {
4889 .ops
= &snd_hda_bind_sw
,
4891 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT
),
4892 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT
),
4897 static const struct snd_kcontrol_new alc268_beep_mixer
[] = {
4898 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT
),
4899 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw
),
4903 /* set PCBEEP vol = 0, mute connections */
4904 static const struct hda_verb alc268_beep_init_verbs
[] = {
4905 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
4906 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(1)},
4907 {0x10, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(1)},
4912 * BIOS auto configuration
4914 static int alc268_parse_auto_config(struct hda_codec
*codec
)
4916 static const hda_nid_t alc268_ssids
[] = { 0x15, 0x1b, 0x14, 0 };
4917 struct alc_spec
*spec
= codec
->spec
;
4918 int err
= alc_parse_auto_config(codec
, NULL
, alc268_ssids
);
4920 if (!spec
->no_analog
&& spec
->autocfg
.speaker_pins
[0] != 0x1d) {
4921 add_mixer(spec
, alc268_beep_mixer
);
4922 add_verb(spec
, alc268_beep_init_verbs
);
4930 static int patch_alc268(struct hda_codec
*codec
)
4932 struct alc_spec
*spec
;
4933 int i
, has_beep
, err
;
4935 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
4941 /* ALC268 has no aa-loopback mixer */
4943 /* automatic parse from the BIOS config */
4944 err
= alc268_parse_auto_config(codec
);
4949 for (i
= 0; i
< spec
->num_mixers
; i
++) {
4950 if (spec
->mixers
[i
] == alc268_beep_mixer
) {
4957 err
= snd_hda_attach_beep_device(codec
, 0x1);
4960 if (!query_amp_caps(codec
, 0x1d, HDA_INPUT
))
4961 /* override the amp caps for beep generator */
4962 snd_hda_override_amp_caps(codec
, 0x1d, HDA_INPUT
,
4963 (0x0c << AC_AMPCAP_OFFSET_SHIFT
) |
4964 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT
) |
4965 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT
) |
4966 (0 << AC_AMPCAP_MUTE_SHIFT
));
4969 if (!spec
->no_analog
&& !spec
->adc_nids
) {
4970 alc_auto_fill_adc_caps(codec
);
4971 alc_rebuild_imux_for_auto_mic(codec
);
4972 alc_remove_invalid_adc_nids(codec
);
4975 if (!spec
->no_analog
&& !spec
->cap_mixer
)
4976 set_capture_mixer(codec
);
4978 codec
->patch_ops
= alc_patch_ops
;
4979 spec
->init_hook
= alc_auto_init_std
;
4980 spec
->shutup
= alc_eapd_shutup
;
4992 #ifdef CONFIG_SND_HDA_POWER_SAVE
4993 #define alc269_loopbacks alc880_loopbacks
4996 static const struct hda_pcm_stream alc269_44k_pcm_analog_playback
= {
5000 .rates
= SNDRV_PCM_RATE_44100
, /* fixed rate */
5001 /* NID is set in alc_build_pcms */
5003 .open
= alc_playback_pcm_open
,
5004 .prepare
= alc_playback_pcm_prepare
,
5005 .cleanup
= alc_playback_pcm_cleanup
5009 static const struct hda_pcm_stream alc269_44k_pcm_analog_capture
= {
5013 .rates
= SNDRV_PCM_RATE_44100
, /* fixed rate */
5014 /* NID is set in alc_build_pcms */
5017 #ifdef CONFIG_SND_HDA_POWER_SAVE
5018 static int alc269_mic2_for_mute_led(struct hda_codec
*codec
)
5020 switch (codec
->subsystem_id
) {
5027 static int alc269_mic2_mute_check_ps(struct hda_codec
*codec
, hda_nid_t nid
)
5029 /* update mute-LED according to the speaker mute state */
5030 if (nid
== 0x01 || nid
== 0x14) {
5032 if (snd_hda_codec_amp_read(codec
, 0x14, 0, HDA_OUTPUT
, 0) &
5037 /* mic2 vref pin is used for mute LED control */
5038 snd_hda_codec_update_cache(codec
, 0x19, 0,
5039 AC_VERB_SET_PIN_WIDGET_CONTROL
,
5042 return alc_check_power_status(codec
, nid
);
5044 #endif /* CONFIG_SND_HDA_POWER_SAVE */
5046 /* different alc269-variants */
5048 ALC269_TYPE_ALC269VA
,
5049 ALC269_TYPE_ALC269VB
,
5050 ALC269_TYPE_ALC269VC
,
5054 * BIOS auto configuration
5056 static int alc269_parse_auto_config(struct hda_codec
*codec
)
5058 static const hda_nid_t alc269_ignore
[] = { 0x1d, 0 };
5059 static const hda_nid_t alc269_ssids
[] = { 0, 0x1b, 0x14, 0x21 };
5060 static const hda_nid_t alc269va_ssids
[] = { 0x15, 0x1b, 0x14, 0 };
5061 struct alc_spec
*spec
= codec
->spec
;
5062 const hda_nid_t
*ssids
= spec
->codec_variant
== ALC269_TYPE_ALC269VA
?
5063 alc269va_ssids
: alc269_ssids
;
5065 return alc_parse_auto_config(codec
, alc269_ignore
, ssids
);
5068 static void alc269_toggle_power_output(struct hda_codec
*codec
, int power_up
)
5070 int val
= alc_read_coef_idx(codec
, 0x04);
5075 alc_write_coef_idx(codec
, 0x04, val
);
5078 static void alc269_shutup(struct hda_codec
*codec
)
5080 if ((alc_get_coef0(codec
) & 0x00ff) == 0x017)
5081 alc269_toggle_power_output(codec
, 0);
5082 if ((alc_get_coef0(codec
) & 0x00ff) == 0x018) {
5083 alc269_toggle_power_output(codec
, 0);
5089 static int alc269_resume(struct hda_codec
*codec
)
5091 if ((alc_get_coef0(codec
) & 0x00ff) == 0x018) {
5092 alc269_toggle_power_output(codec
, 0);
5096 codec
->patch_ops
.init(codec
);
5098 if ((alc_get_coef0(codec
) & 0x00ff) == 0x017) {
5099 alc269_toggle_power_output(codec
, 1);
5103 if ((alc_get_coef0(codec
) & 0x00ff) == 0x018)
5104 alc269_toggle_power_output(codec
, 1);
5106 snd_hda_codec_resume_amp(codec
);
5107 snd_hda_codec_resume_cache(codec
);
5108 hda_call_check_power_status(codec
, 0x01);
5111 #endif /* CONFIG_PM */
5113 static void alc269_fixup_hweq(struct hda_codec
*codec
,
5114 const struct alc_fixup
*fix
, int action
)
5118 if (action
!= ALC_FIXUP_ACT_INIT
)
5120 coef
= alc_read_coef_idx(codec
, 0x1e);
5121 alc_write_coef_idx(codec
, 0x1e, coef
| 0x80);
5124 static void alc271_fixup_dmic(struct hda_codec
*codec
,
5125 const struct alc_fixup
*fix
, int action
)
5127 static const struct hda_verb verbs
[] = {
5128 {0x20, AC_VERB_SET_COEF_INDEX
, 0x0d},
5129 {0x20, AC_VERB_SET_PROC_COEF
, 0x4000},
5134 if (strcmp(codec
->chip_name
, "ALC271X"))
5136 cfg
= snd_hda_codec_get_pincfg(codec
, 0x12);
5137 if (get_defcfg_connect(cfg
) == AC_JACK_PORT_FIXED
)
5138 snd_hda_sequence_write(codec
, verbs
);
5141 static void alc269_fixup_pcm_44k(struct hda_codec
*codec
,
5142 const struct alc_fixup
*fix
, int action
)
5144 struct alc_spec
*spec
= codec
->spec
;
5146 if (action
!= ALC_FIXUP_ACT_PROBE
)
5149 /* Due to a hardware problem on Lenovo Ideadpad, we need to
5150 * fix the sample rate of analog I/O to 44.1kHz
5152 spec
->stream_analog_playback
= &alc269_44k_pcm_analog_playback
;
5153 spec
->stream_analog_capture
= &alc269_44k_pcm_analog_capture
;
5156 static void alc269_fixup_stereo_dmic(struct hda_codec
*codec
,
5157 const struct alc_fixup
*fix
, int action
)
5161 if (action
!= ALC_FIXUP_ACT_INIT
)
5163 /* The digital-mic unit sends PDM (differential signal) instead of
5164 * the standard PCM, thus you can't record a valid mono stream as is.
5165 * Below is a workaround specific to ALC269 to control the dmic
5166 * signal source as mono.
5168 coef
= alc_read_coef_idx(codec
, 0x07);
5169 alc_write_coef_idx(codec
, 0x07, coef
| 0x80);
5172 static void alc269_quanta_automute(struct hda_codec
*codec
)
5174 update_outputs(codec
);
5176 snd_hda_codec_write(codec
, 0x20, 0,
5177 AC_VERB_SET_COEF_INDEX
, 0x0c);
5178 snd_hda_codec_write(codec
, 0x20, 0,
5179 AC_VERB_SET_PROC_COEF
, 0x680);
5181 snd_hda_codec_write(codec
, 0x20, 0,
5182 AC_VERB_SET_COEF_INDEX
, 0x0c);
5183 snd_hda_codec_write(codec
, 0x20, 0,
5184 AC_VERB_SET_PROC_COEF
, 0x480);
5187 static void alc269_fixup_quanta_mute(struct hda_codec
*codec
,
5188 const struct alc_fixup
*fix
, int action
)
5190 struct alc_spec
*spec
= codec
->spec
;
5191 if (action
!= ALC_FIXUP_ACT_PROBE
)
5193 spec
->automute_hook
= alc269_quanta_automute
;
5197 ALC269_FIXUP_SONY_VAIO
,
5198 ALC275_FIXUP_SONY_VAIO_GPIO2
,
5199 ALC269_FIXUP_DELL_M101Z
,
5200 ALC269_FIXUP_SKU_IGNORE
,
5201 ALC269_FIXUP_ASUS_G73JW
,
5202 ALC269_FIXUP_LENOVO_EAPD
,
5203 ALC275_FIXUP_SONY_HWEQ
,
5205 ALC269_FIXUP_PCM_44K
,
5206 ALC269_FIXUP_STEREO_DMIC
,
5207 ALC269_FIXUP_QUANTA_MUTE
,
5208 ALC269_FIXUP_LIFEBOOK
,
5211 ALC269VB_FIXUP_AMIC
,
5212 ALC269VB_FIXUP_DMIC
,
5215 static const struct alc_fixup alc269_fixups
[] = {
5216 [ALC269_FIXUP_SONY_VAIO
] = {
5217 .type
= ALC_FIXUP_VERBS
,
5218 .v
.verbs
= (const struct hda_verb
[]) {
5219 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_VREFGRD
},
5223 [ALC275_FIXUP_SONY_VAIO_GPIO2
] = {
5224 .type
= ALC_FIXUP_VERBS
,
5225 .v
.verbs
= (const struct hda_verb
[]) {
5226 {0x01, AC_VERB_SET_GPIO_MASK
, 0x04},
5227 {0x01, AC_VERB_SET_GPIO_DIRECTION
, 0x04},
5228 {0x01, AC_VERB_SET_GPIO_DATA
, 0x00},
5232 .chain_id
= ALC269_FIXUP_SONY_VAIO
5234 [ALC269_FIXUP_DELL_M101Z
] = {
5235 .type
= ALC_FIXUP_VERBS
,
5236 .v
.verbs
= (const struct hda_verb
[]) {
5237 /* Enables internal speaker */
5238 {0x20, AC_VERB_SET_COEF_INDEX
, 13},
5239 {0x20, AC_VERB_SET_PROC_COEF
, 0x4040},
5243 [ALC269_FIXUP_SKU_IGNORE
] = {
5244 .type
= ALC_FIXUP_SKU
,
5245 .v
.sku
= ALC_FIXUP_SKU_IGNORE
,
5247 [ALC269_FIXUP_ASUS_G73JW
] = {
5248 .type
= ALC_FIXUP_PINS
,
5249 .v
.pins
= (const struct alc_pincfg
[]) {
5250 { 0x17, 0x99130111 }, /* subwoofer */
5254 [ALC269_FIXUP_LENOVO_EAPD
] = {
5255 .type
= ALC_FIXUP_VERBS
,
5256 .v
.verbs
= (const struct hda_verb
[]) {
5257 {0x14, AC_VERB_SET_EAPD_BTLENABLE
, 0},
5261 [ALC275_FIXUP_SONY_HWEQ
] = {
5262 .type
= ALC_FIXUP_FUNC
,
5263 .v
.func
= alc269_fixup_hweq
,
5265 .chain_id
= ALC275_FIXUP_SONY_VAIO_GPIO2
5267 [ALC271_FIXUP_DMIC
] = {
5268 .type
= ALC_FIXUP_FUNC
,
5269 .v
.func
= alc271_fixup_dmic
,
5271 [ALC269_FIXUP_PCM_44K
] = {
5272 .type
= ALC_FIXUP_FUNC
,
5273 .v
.func
= alc269_fixup_pcm_44k
,
5275 [ALC269_FIXUP_STEREO_DMIC
] = {
5276 .type
= ALC_FIXUP_FUNC
,
5277 .v
.func
= alc269_fixup_stereo_dmic
,
5279 [ALC269_FIXUP_QUANTA_MUTE
] = {
5280 .type
= ALC_FIXUP_FUNC
,
5281 .v
.func
= alc269_fixup_quanta_mute
,
5283 [ALC269_FIXUP_LIFEBOOK
] = {
5284 .type
= ALC_FIXUP_PINS
,
5285 .v
.pins
= (const struct alc_pincfg
[]) {
5286 { 0x1a, 0x2101103f }, /* dock line-out */
5287 { 0x1b, 0x23a11040 }, /* dock mic-in */
5291 .chain_id
= ALC269_FIXUP_QUANTA_MUTE
5293 [ALC269_FIXUP_AMIC
] = {
5294 .type
= ALC_FIXUP_PINS
,
5295 .v
.pins
= (const struct alc_pincfg
[]) {
5296 { 0x14, 0x99130110 }, /* speaker */
5297 { 0x15, 0x0121401f }, /* HP out */
5298 { 0x18, 0x01a19c20 }, /* mic */
5299 { 0x19, 0x99a3092f }, /* int-mic */
5303 [ALC269_FIXUP_DMIC
] = {
5304 .type
= ALC_FIXUP_PINS
,
5305 .v
.pins
= (const struct alc_pincfg
[]) {
5306 { 0x12, 0x99a3092f }, /* int-mic */
5307 { 0x14, 0x99130110 }, /* speaker */
5308 { 0x15, 0x0121401f }, /* HP out */
5309 { 0x18, 0x01a19c20 }, /* mic */
5313 [ALC269VB_FIXUP_AMIC
] = {
5314 .type
= ALC_FIXUP_PINS
,
5315 .v
.pins
= (const struct alc_pincfg
[]) {
5316 { 0x14, 0x99130110 }, /* speaker */
5317 { 0x18, 0x01a19c20 }, /* mic */
5318 { 0x19, 0x99a3092f }, /* int-mic */
5319 { 0x21, 0x0121401f }, /* HP out */
5323 [ALC269VB_FIXUP_DMIC
] = {
5324 .type
= ALC_FIXUP_PINS
,
5325 .v
.pins
= (const struct alc_pincfg
[]) {
5326 { 0x12, 0x99a3092f }, /* int-mic */
5327 { 0x14, 0x99130110 }, /* speaker */
5328 { 0x18, 0x01a19c20 }, /* mic */
5329 { 0x21, 0x0121401f }, /* HP out */
5335 static const struct snd_pci_quirk alc269_fixup_tbl
[] = {
5336 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW
),
5337 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC
),
5338 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC
),
5339 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC
),
5340 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC
),
5341 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC
),
5342 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2
),
5343 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ
),
5344 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ
),
5345 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO
),
5346 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z
),
5347 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC
),
5348 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK
),
5349 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE
),
5350 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE
),
5351 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE
),
5352 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE
),
5353 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE
),
5354 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_QUANTA_MUTE
),
5355 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K
),
5356 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD
),
5359 /* Below is a quirk table taken from the old code.
5360 * Basically the device should work as is without the fixup table.
5361 * If BIOS doesn't give a proper info, enable the corresponding
5364 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
5366 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC
),
5367 SND_PCI_QUIRK(0x1043, 0x1113, "ASUS N63Jn", ALC269_FIXUP_AMIC
),
5368 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC
),
5369 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC
),
5370 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC
),
5371 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC
),
5372 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC
),
5373 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC
),
5374 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC
),
5375 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC
),
5376 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC
),
5377 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC
),
5378 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC
),
5379 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC
),
5380 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC
),
5381 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC
),
5382 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC
),
5383 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC
),
5384 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC
),
5385 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC
),
5386 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC
),
5387 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC
),
5388 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC
),
5389 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC
),
5390 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC
),
5391 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC
),
5392 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC
),
5393 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC
),
5394 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC
),
5395 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC
),
5396 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC
),
5397 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC
),
5398 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC
),
5399 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC
),
5400 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC
),
5401 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC
),
5402 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC
),
5403 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC
),
5404 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC
),
5405 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC
),
5410 static const struct alc_model_fixup alc269_fixup_models
[] = {
5411 {.id
= ALC269_FIXUP_AMIC
, .name
= "laptop-amic"},
5412 {.id
= ALC269_FIXUP_DMIC
, .name
= "laptop-dmic"},
5417 static int alc269_fill_coef(struct hda_codec
*codec
)
5421 if ((alc_get_coef0(codec
) & 0x00ff) < 0x015) {
5422 alc_write_coef_idx(codec
, 0xf, 0x960b);
5423 alc_write_coef_idx(codec
, 0xe, 0x8817);
5426 if ((alc_get_coef0(codec
) & 0x00ff) == 0x016) {
5427 alc_write_coef_idx(codec
, 0xf, 0x960b);
5428 alc_write_coef_idx(codec
, 0xe, 0x8814);
5431 if ((alc_get_coef0(codec
) & 0x00ff) == 0x017) {
5432 val
= alc_read_coef_idx(codec
, 0x04);
5433 /* Power up output pin */
5434 alc_write_coef_idx(codec
, 0x04, val
| (1<<11));
5437 if ((alc_get_coef0(codec
) & 0x00ff) == 0x018) {
5438 val
= alc_read_coef_idx(codec
, 0xd);
5439 if ((val
& 0x0c00) >> 10 != 0x1) {
5440 /* Capless ramp up clock control */
5441 alc_write_coef_idx(codec
, 0xd, val
| (1<<10));
5443 val
= alc_read_coef_idx(codec
, 0x17);
5444 if ((val
& 0x01c0) >> 6 != 0x4) {
5445 /* Class D power on reset */
5446 alc_write_coef_idx(codec
, 0x17, val
| (1<<7));
5450 val
= alc_read_coef_idx(codec
, 0xd); /* Class D */
5451 alc_write_coef_idx(codec
, 0xd, val
| (1<<14));
5453 val
= alc_read_coef_idx(codec
, 0x4); /* HP */
5454 alc_write_coef_idx(codec
, 0x4, val
| (1<<11));
5461 static int patch_alc269(struct hda_codec
*codec
)
5463 struct alc_spec
*spec
;
5466 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
5472 spec
->mixer_nid
= 0x0b;
5474 alc_auto_parse_customize_define(codec
);
5476 err
= alc_codec_rename_from_preset(codec
);
5480 if (codec
->vendor_id
== 0x10ec0269) {
5481 spec
->codec_variant
= ALC269_TYPE_ALC269VA
;
5482 switch (alc_get_coef0(codec
) & 0x00f0) {
5484 if (codec
->bus
->pci
->subsystem_vendor
== 0x1025 &&
5485 spec
->cdefine
.platform_type
== 1)
5486 err
= alc_codec_rename(codec
, "ALC271X");
5487 spec
->codec_variant
= ALC269_TYPE_ALC269VB
;
5490 if (codec
->bus
->pci
->subsystem_vendor
== 0x17aa &&
5491 codec
->bus
->pci
->subsystem_device
== 0x21f3)
5492 err
= alc_codec_rename(codec
, "ALC3202");
5493 spec
->codec_variant
= ALC269_TYPE_ALC269VC
;
5496 alc_fix_pll_init(codec
, 0x20, 0x04, 15);
5500 alc269_fill_coef(codec
);
5503 alc_pick_fixup(codec
, alc269_fixup_models
,
5504 alc269_fixup_tbl
, alc269_fixups
);
5505 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
5507 /* automatic parse from the BIOS config */
5508 err
= alc269_parse_auto_config(codec
);
5512 if (!spec
->no_analog
&& !spec
->adc_nids
) {
5513 alc_auto_fill_adc_caps(codec
);
5514 alc_rebuild_imux_for_auto_mic(codec
);
5515 alc_remove_invalid_adc_nids(codec
);
5518 if (!spec
->no_analog
&& !spec
->cap_mixer
)
5519 set_capture_mixer(codec
);
5521 if (!spec
->no_analog
&& has_cdefine_beep(codec
)) {
5522 err
= snd_hda_attach_beep_device(codec
, 0x1);
5525 set_beep_amp(spec
, 0x0b, 0x04, HDA_INPUT
);
5528 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
5530 codec
->patch_ops
= alc_patch_ops
;
5532 codec
->patch_ops
.resume
= alc269_resume
;
5534 spec
->init_hook
= alc_auto_init_std
;
5535 spec
->shutup
= alc269_shutup
;
5537 #ifdef CONFIG_SND_HDA_POWER_SAVE
5538 if (!spec
->loopback
.amplist
)
5539 spec
->loopback
.amplist
= alc269_loopbacks
;
5540 if (alc269_mic2_for_mute_led(codec
))
5541 codec
->patch_ops
.check_power_status
= alc269_mic2_mute_check_ps
;
5555 static int alc861_parse_auto_config(struct hda_codec
*codec
)
5557 static const hda_nid_t alc861_ignore
[] = { 0x1d, 0 };
5558 static const hda_nid_t alc861_ssids
[] = { 0x0e, 0x0f, 0x0b, 0 };
5559 return alc_parse_auto_config(codec
, alc861_ignore
, alc861_ssids
);
5562 #ifdef CONFIG_SND_HDA_POWER_SAVE
5563 static const struct hda_amp_list alc861_loopbacks
[] = {
5564 { 0x15, HDA_INPUT
, 0 },
5565 { 0x15, HDA_INPUT
, 1 },
5566 { 0x15, HDA_INPUT
, 2 },
5567 { 0x15, HDA_INPUT
, 3 },
5573 /* Pin config fixes */
5575 PINFIX_FSC_AMILO_PI1505
,
5578 static const struct alc_fixup alc861_fixups
[] = {
5579 [PINFIX_FSC_AMILO_PI1505
] = {
5580 .type
= ALC_FIXUP_PINS
,
5581 .v
.pins
= (const struct alc_pincfg
[]) {
5582 { 0x0b, 0x0221101f }, /* HP */
5583 { 0x0f, 0x90170310 }, /* speaker */
5589 static const struct snd_pci_quirk alc861_fixup_tbl
[] = {
5590 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", PINFIX_FSC_AMILO_PI1505
),
5596 static int patch_alc861(struct hda_codec
*codec
)
5598 struct alc_spec
*spec
;
5601 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
5607 spec
->mixer_nid
= 0x15;
5609 alc_pick_fixup(codec
, NULL
, alc861_fixup_tbl
, alc861_fixups
);
5610 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
5612 /* automatic parse from the BIOS config */
5613 err
= alc861_parse_auto_config(codec
);
5617 if (!spec
->no_analog
&& !spec
->adc_nids
) {
5618 alc_auto_fill_adc_caps(codec
);
5619 alc_rebuild_imux_for_auto_mic(codec
);
5620 alc_remove_invalid_adc_nids(codec
);
5623 if (!spec
->no_analog
&& !spec
->cap_mixer
)
5624 set_capture_mixer(codec
);
5626 if (!spec
->no_analog
) {
5627 err
= snd_hda_attach_beep_device(codec
, 0x23);
5630 set_beep_amp(spec
, 0x23, 0, HDA_OUTPUT
);
5633 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
5635 codec
->patch_ops
= alc_patch_ops
;
5636 spec
->init_hook
= alc_auto_init_std
;
5637 #ifdef CONFIG_SND_HDA_POWER_SAVE
5638 spec
->power_hook
= alc_power_eapd
;
5639 if (!spec
->loopback
.amplist
)
5640 spec
->loopback
.amplist
= alc861_loopbacks
;
5655 * In addition, an independent DAC
5657 #ifdef CONFIG_SND_HDA_POWER_SAVE
5658 #define alc861vd_loopbacks alc880_loopbacks
5661 static int alc861vd_parse_auto_config(struct hda_codec
*codec
)
5663 static const hda_nid_t alc861vd_ignore
[] = { 0x1d, 0 };
5664 static const hda_nid_t alc861vd_ssids
[] = { 0x15, 0x1b, 0x14, 0 };
5665 return alc_parse_auto_config(codec
, alc861vd_ignore
, alc861vd_ssids
);
5669 ALC660VD_FIX_ASUS_GPIO1
,
5670 ALC861VD_FIX_DALLAS
,
5673 /* exclude VREF80 */
5674 static void alc861vd_fixup_dallas(struct hda_codec
*codec
,
5675 const struct alc_fixup
*fix
, int action
)
5677 if (action
== ALC_FIXUP_ACT_PRE_PROBE
) {
5678 snd_hda_override_pin_caps(codec
, 0x18, 0x00001714);
5679 snd_hda_override_pin_caps(codec
, 0x19, 0x0000171c);
5683 static const struct alc_fixup alc861vd_fixups
[] = {
5684 [ALC660VD_FIX_ASUS_GPIO1
] = {
5685 .type
= ALC_FIXUP_VERBS
,
5686 .v
.verbs
= (const struct hda_verb
[]) {
5688 {0x01, AC_VERB_SET_GPIO_MASK
, 0x03},
5689 {0x01, AC_VERB_SET_GPIO_DIRECTION
, 0x01},
5690 {0x01, AC_VERB_SET_GPIO_DATA
, 0x01},
5694 [ALC861VD_FIX_DALLAS
] = {
5695 .type
= ALC_FIXUP_FUNC
,
5696 .v
.func
= alc861vd_fixup_dallas
,
5700 static const struct snd_pci_quirk alc861vd_fixup_tbl
[] = {
5701 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS
),
5702 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1
),
5703 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS
),
5707 static const struct hda_verb alc660vd_eapd_verbs
[] = {
5708 {0x14, AC_VERB_SET_EAPD_BTLENABLE
, 2},
5709 {0x15, AC_VERB_SET_EAPD_BTLENABLE
, 2},
5715 static int patch_alc861vd(struct hda_codec
*codec
)
5717 struct alc_spec
*spec
;
5720 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
5726 spec
->mixer_nid
= 0x0b;
5728 alc_pick_fixup(codec
, NULL
, alc861vd_fixup_tbl
, alc861vd_fixups
);
5729 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
5731 /* automatic parse from the BIOS config */
5732 err
= alc861vd_parse_auto_config(codec
);
5736 if (codec
->vendor_id
== 0x10ec0660) {
5737 /* always turn on EAPD */
5738 add_verb(spec
, alc660vd_eapd_verbs
);
5741 if (!spec
->no_analog
&& !spec
->adc_nids
) {
5742 alc_auto_fill_adc_caps(codec
);
5743 alc_rebuild_imux_for_auto_mic(codec
);
5744 alc_remove_invalid_adc_nids(codec
);
5747 if (!spec
->no_analog
&& !spec
->cap_mixer
)
5748 set_capture_mixer(codec
);
5750 if (!spec
->no_analog
) {
5751 err
= snd_hda_attach_beep_device(codec
, 0x23);
5754 set_beep_amp(spec
, 0x0b, 0x05, HDA_INPUT
);
5757 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
5759 codec
->patch_ops
= alc_patch_ops
;
5761 spec
->init_hook
= alc_auto_init_std
;
5762 spec
->shutup
= alc_eapd_shutup
;
5763 #ifdef CONFIG_SND_HDA_POWER_SAVE
5764 if (!spec
->loopback
.amplist
)
5765 spec
->loopback
.amplist
= alc861vd_loopbacks
;
5778 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
5779 * configuration. Each pin widget can choose any input DACs and a mixer.
5780 * Each ADC is connected from a mixer of all inputs. This makes possible
5781 * 6-channel independent captures.
5783 * In addition, an independent DAC for the multi-playback (not used in this
5786 #ifdef CONFIG_SND_HDA_POWER_SAVE
5787 #define alc662_loopbacks alc880_loopbacks
5791 * BIOS auto configuration
5794 static int alc662_parse_auto_config(struct hda_codec
*codec
)
5796 static const hda_nid_t alc662_ignore
[] = { 0x1d, 0 };
5797 static const hda_nid_t alc663_ssids
[] = { 0x15, 0x1b, 0x14, 0x21 };
5798 static const hda_nid_t alc662_ssids
[] = { 0x15, 0x1b, 0x14, 0 };
5799 const hda_nid_t
*ssids
;
5801 if (codec
->vendor_id
== 0x10ec0272 || codec
->vendor_id
== 0x10ec0663 ||
5802 codec
->vendor_id
== 0x10ec0665 || codec
->vendor_id
== 0x10ec0670)
5803 ssids
= alc663_ssids
;
5805 ssids
= alc662_ssids
;
5806 return alc_parse_auto_config(codec
, alc662_ignore
, ssids
);
5809 static void alc272_fixup_mario(struct hda_codec
*codec
,
5810 const struct alc_fixup
*fix
, int action
)
5812 if (action
!= ALC_FIXUP_ACT_PROBE
)
5814 if (snd_hda_override_amp_caps(codec
, 0x2, HDA_OUTPUT
,
5815 (0x3b << AC_AMPCAP_OFFSET_SHIFT
) |
5816 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT
) |
5817 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT
) |
5818 (0 << AC_AMPCAP_MUTE_SHIFT
)))
5820 "hda_codec: failed to override amp caps for NID 0x2\n");
5824 ALC662_FIXUP_ASPIRE
,
5825 ALC662_FIXUP_IDEAPAD
,
5827 ALC662_FIXUP_CZC_P10T
,
5828 ALC662_FIXUP_SKU_IGNORE
,
5829 ALC662_FIXUP_HP_RP5800
,
5830 ALC662_FIXUP_ASUS_MODE1
,
5831 ALC662_FIXUP_ASUS_MODE2
,
5832 ALC662_FIXUP_ASUS_MODE3
,
5833 ALC662_FIXUP_ASUS_MODE4
,
5834 ALC662_FIXUP_ASUS_MODE5
,
5835 ALC662_FIXUP_ASUS_MODE6
,
5836 ALC662_FIXUP_ASUS_MODE7
,
5837 ALC662_FIXUP_ASUS_MODE8
,
5840 static const struct alc_fixup alc662_fixups
[] = {
5841 [ALC662_FIXUP_ASPIRE
] = {
5842 .type
= ALC_FIXUP_PINS
,
5843 .v
.pins
= (const struct alc_pincfg
[]) {
5844 { 0x15, 0x99130112 }, /* subwoofer */
5848 [ALC662_FIXUP_IDEAPAD
] = {
5849 .type
= ALC_FIXUP_PINS
,
5850 .v
.pins
= (const struct alc_pincfg
[]) {
5851 { 0x17, 0x99130112 }, /* subwoofer */
5855 [ALC272_FIXUP_MARIO
] = {
5856 .type
= ALC_FIXUP_FUNC
,
5857 .v
.func
= alc272_fixup_mario
,
5859 [ALC662_FIXUP_CZC_P10T
] = {
5860 .type
= ALC_FIXUP_VERBS
,
5861 .v
.verbs
= (const struct hda_verb
[]) {
5862 {0x14, AC_VERB_SET_EAPD_BTLENABLE
, 0},
5866 [ALC662_FIXUP_SKU_IGNORE
] = {
5867 .type
= ALC_FIXUP_SKU
,
5868 .v
.sku
= ALC_FIXUP_SKU_IGNORE
,
5870 [ALC662_FIXUP_HP_RP5800
] = {
5871 .type
= ALC_FIXUP_PINS
,
5872 .v
.pins
= (const struct alc_pincfg
[]) {
5873 { 0x14, 0x0221201f }, /* HP out */
5877 .chain_id
= ALC662_FIXUP_SKU_IGNORE
5879 [ALC662_FIXUP_ASUS_MODE1
] = {
5880 .type
= ALC_FIXUP_PINS
,
5881 .v
.pins
= (const struct alc_pincfg
[]) {
5882 { 0x14, 0x99130110 }, /* speaker */
5883 { 0x18, 0x01a19c20 }, /* mic */
5884 { 0x19, 0x99a3092f }, /* int-mic */
5885 { 0x21, 0x0121401f }, /* HP out */
5889 .chain_id
= ALC662_FIXUP_SKU_IGNORE
5891 [ALC662_FIXUP_ASUS_MODE2
] = {
5892 .type
= ALC_FIXUP_PINS
,
5893 .v
.pins
= (const struct alc_pincfg
[]) {
5894 { 0x14, 0x99130110 }, /* speaker */
5895 { 0x18, 0x01a19820 }, /* mic */
5896 { 0x19, 0x99a3092f }, /* int-mic */
5897 { 0x1b, 0x0121401f }, /* HP out */
5901 .chain_id
= ALC662_FIXUP_SKU_IGNORE
5903 [ALC662_FIXUP_ASUS_MODE3
] = {
5904 .type
= ALC_FIXUP_PINS
,
5905 .v
.pins
= (const struct alc_pincfg
[]) {
5906 { 0x14, 0x99130110 }, /* speaker */
5907 { 0x15, 0x0121441f }, /* HP */
5908 { 0x18, 0x01a19840 }, /* mic */
5909 { 0x19, 0x99a3094f }, /* int-mic */
5910 { 0x21, 0x01211420 }, /* HP2 */
5914 .chain_id
= ALC662_FIXUP_SKU_IGNORE
5916 [ALC662_FIXUP_ASUS_MODE4
] = {
5917 .type
= ALC_FIXUP_PINS
,
5918 .v
.pins
= (const struct alc_pincfg
[]) {
5919 { 0x14, 0x99130110 }, /* speaker */
5920 { 0x16, 0x99130111 }, /* speaker */
5921 { 0x18, 0x01a19840 }, /* mic */
5922 { 0x19, 0x99a3094f }, /* int-mic */
5923 { 0x21, 0x0121441f }, /* HP */
5927 .chain_id
= ALC662_FIXUP_SKU_IGNORE
5929 [ALC662_FIXUP_ASUS_MODE5
] = {
5930 .type
= ALC_FIXUP_PINS
,
5931 .v
.pins
= (const struct alc_pincfg
[]) {
5932 { 0x14, 0x99130110 }, /* speaker */
5933 { 0x15, 0x0121441f }, /* HP */
5934 { 0x16, 0x99130111 }, /* speaker */
5935 { 0x18, 0x01a19840 }, /* mic */
5936 { 0x19, 0x99a3094f }, /* int-mic */
5940 .chain_id
= ALC662_FIXUP_SKU_IGNORE
5942 [ALC662_FIXUP_ASUS_MODE6
] = {
5943 .type
= ALC_FIXUP_PINS
,
5944 .v
.pins
= (const struct alc_pincfg
[]) {
5945 { 0x14, 0x99130110 }, /* speaker */
5946 { 0x15, 0x01211420 }, /* HP2 */
5947 { 0x18, 0x01a19840 }, /* mic */
5948 { 0x19, 0x99a3094f }, /* int-mic */
5949 { 0x1b, 0x0121441f }, /* HP */
5953 .chain_id
= ALC662_FIXUP_SKU_IGNORE
5955 [ALC662_FIXUP_ASUS_MODE7
] = {
5956 .type
= ALC_FIXUP_PINS
,
5957 .v
.pins
= (const struct alc_pincfg
[]) {
5958 { 0x14, 0x99130110 }, /* speaker */
5959 { 0x17, 0x99130111 }, /* speaker */
5960 { 0x18, 0x01a19840 }, /* mic */
5961 { 0x19, 0x99a3094f }, /* int-mic */
5962 { 0x1b, 0x01214020 }, /* HP */
5963 { 0x21, 0x0121401f }, /* HP */
5967 .chain_id
= ALC662_FIXUP_SKU_IGNORE
5969 [ALC662_FIXUP_ASUS_MODE8
] = {
5970 .type
= ALC_FIXUP_PINS
,
5971 .v
.pins
= (const struct alc_pincfg
[]) {
5972 { 0x14, 0x99130110 }, /* speaker */
5973 { 0x12, 0x99a30970 }, /* int-mic */
5974 { 0x15, 0x01214020 }, /* HP */
5975 { 0x17, 0x99130111 }, /* speaker */
5976 { 0x18, 0x01a19840 }, /* mic */
5977 { 0x21, 0x0121401f }, /* HP */
5981 .chain_id
= ALC662_FIXUP_SKU_IGNORE
5985 static const struct snd_pci_quirk alc662_fixup_tbl
[] = {
5986 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2
),
5987 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE
),
5988 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE
),
5989 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE
),
5990 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800
),
5991 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2
),
5992 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD
),
5993 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD
),
5994 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD
),
5995 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T
),
5998 /* Below is a quirk table taken from the old code.
5999 * Basically the device should work as is without the fixup table.
6000 * If BIOS doesn't give a proper info, enable the corresponding
6003 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1
),
6004 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3
),
6005 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1
),
6006 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3
),
6007 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1
),
6008 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2
),
6009 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1
),
6010 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1
),
6011 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1
),
6012 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2
),
6013 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7
),
6014 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7
),
6015 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8
),
6016 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3
),
6017 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1
),
6018 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2
),
6019 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2
),
6020 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1
),
6021 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2
),
6022 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6
),
6023 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6
),
6024 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2
),
6025 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1
),
6026 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3
),
6027 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2
),
6028 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2
),
6029 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5
),
6030 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6
),
6031 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2
),
6032 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1
),
6033 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2
),
6034 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2
),
6035 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3
),
6036 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3
),
6037 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1
),
6038 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1
),
6039 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1
),
6040 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1
),
6041 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1
),
6042 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2
),
6043 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2
),
6044 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1
),
6045 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1
),
6046 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3
),
6047 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1
),
6048 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1
),
6049 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1
),
6050 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2
),
6051 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1
),
6052 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4
),
6057 static const struct alc_model_fixup alc662_fixup_models
[] = {
6058 {.id
= ALC272_FIXUP_MARIO
, .name
= "mario"},
6059 {.id
= ALC662_FIXUP_ASUS_MODE1
, .name
= "asus-mode1"},
6060 {.id
= ALC662_FIXUP_ASUS_MODE2
, .name
= "asus-mode2"},
6061 {.id
= ALC662_FIXUP_ASUS_MODE3
, .name
= "asus-mode3"},
6062 {.id
= ALC662_FIXUP_ASUS_MODE4
, .name
= "asus-mode4"},
6063 {.id
= ALC662_FIXUP_ASUS_MODE5
, .name
= "asus-mode5"},
6064 {.id
= ALC662_FIXUP_ASUS_MODE6
, .name
= "asus-mode6"},
6065 {.id
= ALC662_FIXUP_ASUS_MODE7
, .name
= "asus-mode7"},
6066 {.id
= ALC662_FIXUP_ASUS_MODE8
, .name
= "asus-mode8"},
6073 static int patch_alc662(struct hda_codec
*codec
)
6075 struct alc_spec
*spec
;
6078 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
6084 spec
->mixer_nid
= 0x0b;
6086 /* handle multiple HPs as is */
6087 spec
->parse_flags
= HDA_PINCFG_NO_HP_FIXUP
;
6089 alc_auto_parse_customize_define(codec
);
6091 alc_fix_pll_init(codec
, 0x20, 0x04, 15);
6093 err
= alc_codec_rename_from_preset(codec
);
6097 if ((alc_get_coef0(codec
) & (1 << 14)) &&
6098 codec
->bus
->pci
->subsystem_vendor
== 0x1025 &&
6099 spec
->cdefine
.platform_type
== 1) {
6100 if (alc_codec_rename(codec
, "ALC272X") < 0)
6104 alc_pick_fixup(codec
, alc662_fixup_models
,
6105 alc662_fixup_tbl
, alc662_fixups
);
6106 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
6107 /* automatic parse from the BIOS config */
6108 err
= alc662_parse_auto_config(codec
);
6112 if (!spec
->no_analog
&& !spec
->adc_nids
) {
6113 alc_auto_fill_adc_caps(codec
);
6114 alc_rebuild_imux_for_auto_mic(codec
);
6115 alc_remove_invalid_adc_nids(codec
);
6118 if (!spec
->no_analog
&& !spec
->cap_mixer
)
6119 set_capture_mixer(codec
);
6121 if (!spec
->no_analog
&& has_cdefine_beep(codec
)) {
6122 err
= snd_hda_attach_beep_device(codec
, 0x1);
6125 switch (codec
->vendor_id
) {
6127 set_beep_amp(spec
, 0x0b, 0x05, HDA_INPUT
);
6132 set_beep_amp(spec
, 0x0b, 0x04, HDA_INPUT
);
6135 set_beep_amp(spec
, 0x0b, 0x03, HDA_INPUT
);
6140 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
6142 codec
->patch_ops
= alc_patch_ops
;
6143 spec
->init_hook
= alc_auto_init_std
;
6144 spec
->shutup
= alc_eapd_shutup
;
6146 #ifdef CONFIG_SND_HDA_POWER_SAVE
6147 if (!spec
->loopback
.amplist
)
6148 spec
->loopback
.amplist
= alc662_loopbacks
;
6162 static int alc680_parse_auto_config(struct hda_codec
*codec
)
6164 return alc_parse_auto_config(codec
, NULL
, NULL
);
6169 static int patch_alc680(struct hda_codec
*codec
)
6171 struct alc_spec
*spec
;
6174 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
6180 /* ALC680 has no aa-loopback mixer */
6182 /* automatic parse from the BIOS config */
6183 err
= alc680_parse_auto_config(codec
);
6189 if (!spec
->no_analog
&& !spec
->cap_mixer
)
6190 set_capture_mixer(codec
);
6192 codec
->patch_ops
= alc_patch_ops
;
6193 spec
->init_hook
= alc_auto_init_std
;
6201 static const struct hda_codec_preset snd_hda_preset_realtek
[] = {
6202 { .id
= 0x10ec0221, .name
= "ALC221", .patch
= patch_alc269
},
6203 { .id
= 0x10ec0260, .name
= "ALC260", .patch
= patch_alc260
},
6204 { .id
= 0x10ec0262, .name
= "ALC262", .patch
= patch_alc262
},
6205 { .id
= 0x10ec0267, .name
= "ALC267", .patch
= patch_alc268
},
6206 { .id
= 0x10ec0268, .name
= "ALC268", .patch
= patch_alc268
},
6207 { .id
= 0x10ec0269, .name
= "ALC269", .patch
= patch_alc269
},
6208 { .id
= 0x10ec0270, .name
= "ALC270", .patch
= patch_alc269
},
6209 { .id
= 0x10ec0272, .name
= "ALC272", .patch
= patch_alc662
},
6210 { .id
= 0x10ec0275, .name
= "ALC275", .patch
= patch_alc269
},
6211 { .id
= 0x10ec0276, .name
= "ALC276", .patch
= patch_alc269
},
6212 { .id
= 0x10ec0861, .rev
= 0x100340, .name
= "ALC660",
6213 .patch
= patch_alc861
},
6214 { .id
= 0x10ec0660, .name
= "ALC660-VD", .patch
= patch_alc861vd
},
6215 { .id
= 0x10ec0861, .name
= "ALC861", .patch
= patch_alc861
},
6216 { .id
= 0x10ec0862, .name
= "ALC861-VD", .patch
= patch_alc861vd
},
6217 { .id
= 0x10ec0662, .rev
= 0x100002, .name
= "ALC662 rev2",
6218 .patch
= patch_alc882
},
6219 { .id
= 0x10ec0662, .rev
= 0x100101, .name
= "ALC662 rev1",
6220 .patch
= patch_alc662
},
6221 { .id
= 0x10ec0662, .rev
= 0x100300, .name
= "ALC662 rev3",
6222 .patch
= patch_alc662
},
6223 { .id
= 0x10ec0663, .name
= "ALC663", .patch
= patch_alc662
},
6224 { .id
= 0x10ec0665, .name
= "ALC665", .patch
= patch_alc662
},
6225 { .id
= 0x10ec0670, .name
= "ALC670", .patch
= patch_alc662
},
6226 { .id
= 0x10ec0680, .name
= "ALC680", .patch
= patch_alc680
},
6227 { .id
= 0x10ec0880, .name
= "ALC880", .patch
= patch_alc880
},
6228 { .id
= 0x10ec0882, .name
= "ALC882", .patch
= patch_alc882
},
6229 { .id
= 0x10ec0883, .name
= "ALC883", .patch
= patch_alc882
},
6230 { .id
= 0x10ec0885, .rev
= 0x100101, .name
= "ALC889A",
6231 .patch
= patch_alc882
},
6232 { .id
= 0x10ec0885, .rev
= 0x100103, .name
= "ALC889A",
6233 .patch
= patch_alc882
},
6234 { .id
= 0x10ec0885, .name
= "ALC885", .patch
= patch_alc882
},
6235 { .id
= 0x10ec0887, .name
= "ALC887", .patch
= patch_alc882
},
6236 { .id
= 0x10ec0888, .rev
= 0x100101, .name
= "ALC1200",
6237 .patch
= patch_alc882
},
6238 { .id
= 0x10ec0888, .name
= "ALC888", .patch
= patch_alc882
},
6239 { .id
= 0x10ec0889, .name
= "ALC889", .patch
= patch_alc882
},
6240 { .id
= 0x10ec0892, .name
= "ALC892", .patch
= patch_alc662
},
6241 { .id
= 0x10ec0899, .name
= "ALC898", .patch
= patch_alc882
},
6245 MODULE_ALIAS("snd-hda-codec-id:10ec*");
6247 MODULE_LICENSE("GPL");
6248 MODULE_DESCRIPTION("Realtek HD-audio codec");
6250 static struct hda_codec_preset_list realtek_list
= {
6251 .preset
= snd_hda_preset_realtek
,
6252 .owner
= THIS_MODULE
,
6255 static int __init
patch_realtek_init(void)
6257 return snd_hda_add_codec_preset(&realtek_list
);
6260 static void __exit
patch_realtek_exit(void)
6262 snd_hda_delete_codec_preset(&realtek_list
);
6265 module_init(patch_realtek_init
)
6266 module_exit(patch_realtek_exit
)