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 <sound/core.h>
31 #include <sound/jack.h>
32 #include "hda_codec.h"
33 #include "hda_local.h"
36 /* unsol event tags */
37 #define ALC_FRONT_EVENT 0x01
38 #define ALC_DCVOL_EVENT 0x02
39 #define ALC_HP_EVENT 0x04
40 #define ALC_MIC_EVENT 0x08
43 #define GPIO_MASK 0x03
45 /* extra amp-initialization sequence types */
54 struct alc_customize_define
{
56 unsigned char port_connectivity
;
57 unsigned char check_sum
;
58 unsigned char customization
;
59 unsigned char external_amp
;
60 unsigned int enable_pcbeep
:1;
61 unsigned int platform_type
:1;
63 unsigned int override
:1;
64 unsigned int fixup
:1; /* Means that this sku is set by driver, not read from hw */
70 hda_nid_t pin
; /* multi-io widget pin NID */
71 hda_nid_t dac
; /* DAC to be connected */
72 unsigned int ctl_in
; /* cached input-pin control value */
76 ALC_AUTOMUTE_PIN
, /* change the pin control */
77 ALC_AUTOMUTE_AMP
, /* mute/unmute the pin AMP */
78 ALC_AUTOMUTE_MIXER
, /* mute/unmute mixer widget AMP */
82 /* codec parameterization */
83 const struct snd_kcontrol_new
*mixers
[5]; /* mixer arrays */
84 unsigned int num_mixers
;
85 const struct snd_kcontrol_new
*cap_mixer
; /* capture mixer */
86 unsigned int beep_amp
; /* beep amp value, set via set_beep_amp() */
88 const struct hda_verb
*init_verbs
[10]; /* initialization verbs
92 unsigned int num_init_verbs
;
94 char stream_name_analog
[32]; /* analog PCM stream */
95 const struct hda_pcm_stream
*stream_analog_playback
;
96 const struct hda_pcm_stream
*stream_analog_capture
;
97 const struct hda_pcm_stream
*stream_analog_alt_playback
;
98 const struct hda_pcm_stream
*stream_analog_alt_capture
;
100 char stream_name_digital
[32]; /* digital PCM stream */
101 const struct hda_pcm_stream
*stream_digital_playback
;
102 const struct hda_pcm_stream
*stream_digital_capture
;
105 struct hda_multi_out multiout
; /* playback set-up
106 * max_channels, dacs must be set
107 * dig_out_nid and hp_nid are optional
109 hda_nid_t alt_dac_nid
;
110 hda_nid_t slave_dig_outs
[3]; /* optional - for auto-parsing */
114 unsigned int num_adc_nids
;
115 const hda_nid_t
*adc_nids
;
116 const hda_nid_t
*capsrc_nids
;
117 hda_nid_t dig_in_nid
; /* digital-in NID; optional */
118 hda_nid_t mixer_nid
; /* analog-mixer NID */
120 /* capture setup for dynamic dual-adc switch */
122 unsigned int cur_adc_stream_tag
;
123 unsigned int cur_adc_format
;
126 unsigned int num_mux_defs
;
127 const struct hda_input_mux
*input_mux
;
128 unsigned int cur_mux
[3];
129 hda_nid_t ext_mic_pin
;
130 hda_nid_t dock_mic_pin
;
131 hda_nid_t int_mic_pin
;
134 const struct hda_channel_mode
*channel_mode
;
135 int num_channel_mode
;
137 int const_channel_count
;
138 int ext_channel_count
;
140 /* PCM information */
141 struct hda_pcm pcm_rec
[3]; /* used in alc_build_pcms() */
143 /* dynamic controls, init_verbs and input_mux */
144 struct auto_pin_cfg autocfg
;
145 struct alc_customize_define cdefine
;
146 struct snd_array kctls
;
147 struct hda_input_mux private_imux
[3];
148 hda_nid_t private_dac_nids
[AUTO_CFG_MAX_OUTS
];
149 hda_nid_t private_adc_nids
[AUTO_CFG_MAX_OUTS
];
150 hda_nid_t private_capsrc_nids
[AUTO_CFG_MAX_OUTS
];
151 hda_nid_t imux_pins
[HDA_MAX_NUM_INPUTS
];
152 unsigned int dyn_adc_idx
[HDA_MAX_NUM_INPUTS
];
153 int int_mic_idx
, ext_mic_idx
, dock_mic_idx
; /* for auto-mic */
156 void (*init_hook
)(struct hda_codec
*codec
);
157 void (*unsol_event
)(struct hda_codec
*codec
, unsigned int res
);
158 #ifdef CONFIG_SND_HDA_POWER_SAVE
159 void (*power_hook
)(struct hda_codec
*codec
);
161 void (*shutup
)(struct hda_codec
*codec
);
162 void (*automute_hook
)(struct hda_codec
*codec
);
164 /* for pin sensing */
165 unsigned int jack_present
: 1;
166 unsigned int line_jack_present
:1;
167 unsigned int master_mute
:1;
168 unsigned int auto_mic
:1;
169 unsigned int auto_mic_valid_imux
:1; /* valid imux for auto-mic */
170 unsigned int automute
:1; /* HP automute enabled */
171 unsigned int detect_line
:1; /* Line-out detection enabled */
172 unsigned int automute_lines
:1; /* automute line-out as well */
173 unsigned int automute_hp_lo
:1; /* both HP and LO available */
176 unsigned int no_analog
:1; /* digital I/O only */
177 unsigned int dyn_adc_switch
:1; /* switch ADCs (for ALC275) */
178 unsigned int single_input_src
:1;
179 unsigned int vol_in_capsrc
:1; /* use capsrc volume (ADC has no vol) */
180 unsigned int parse_flags
; /* passed to snd_hda_parse_pin_defcfg() */
182 /* auto-mute control */
184 hda_nid_t automute_mixer_nid
[AUTO_CFG_MAX_OUTS
];
187 int codec_variant
; /* flag for other variants */
189 /* for virtual master */
190 hda_nid_t vmaster_nid
;
191 #ifdef CONFIG_SND_HDA_POWER_SAVE
192 struct hda_loopback_check loopback
;
197 unsigned int pll_coef_idx
, pll_coef_bit
;
201 const struct alc_fixup
*fixup_list
;
202 const char *fixup_name
;
206 struct alc_multi_io multi_io
[4];
209 struct snd_array bind_ctls
;
212 #define ALC_MODEL_AUTO 0 /* common for all chips */
214 static bool check_amp_caps(struct hda_codec
*codec
, hda_nid_t nid
,
215 int dir
, unsigned int bits
)
219 if (get_wcaps(codec
, nid
) & (1 << (dir
+ 1)))
220 if (query_amp_caps(codec
, nid
, dir
) & bits
)
225 #define nid_has_mute(codec, nid, dir) \
226 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
227 #define nid_has_volume(codec, nid, dir) \
228 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
233 static int alc_mux_enum_info(struct snd_kcontrol
*kcontrol
,
234 struct snd_ctl_elem_info
*uinfo
)
236 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
237 struct alc_spec
*spec
= codec
->spec
;
238 unsigned int mux_idx
= snd_ctl_get_ioffidx(kcontrol
, &uinfo
->id
);
239 if (mux_idx
>= spec
->num_mux_defs
)
241 if (!spec
->input_mux
[mux_idx
].num_items
&& mux_idx
> 0)
243 return snd_hda_input_mux_info(&spec
->input_mux
[mux_idx
], uinfo
);
246 static int alc_mux_enum_get(struct snd_kcontrol
*kcontrol
,
247 struct snd_ctl_elem_value
*ucontrol
)
249 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
250 struct alc_spec
*spec
= codec
->spec
;
251 unsigned int adc_idx
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
253 ucontrol
->value
.enumerated
.item
[0] = spec
->cur_mux
[adc_idx
];
257 static bool alc_dyn_adc_pcm_resetup(struct hda_codec
*codec
, int cur
)
259 struct alc_spec
*spec
= codec
->spec
;
260 hda_nid_t new_adc
= spec
->adc_nids
[spec
->dyn_adc_idx
[cur
]];
262 if (spec
->cur_adc
&& spec
->cur_adc
!= new_adc
) {
263 /* stream is running, let's swap the current ADC */
264 __snd_hda_codec_cleanup_stream(codec
, spec
->cur_adc
, 1);
265 spec
->cur_adc
= new_adc
;
266 snd_hda_codec_setup_stream(codec
, new_adc
,
267 spec
->cur_adc_stream_tag
, 0,
268 spec
->cur_adc_format
);
274 /* select the given imux item; either unmute exclusively or select the route */
275 static int alc_mux_select(struct hda_codec
*codec
, unsigned int adc_idx
,
276 unsigned int idx
, bool force
)
278 struct alc_spec
*spec
= codec
->spec
;
279 const struct hda_input_mux
*imux
;
280 unsigned int mux_idx
;
284 mux_idx
= adc_idx
>= spec
->num_mux_defs
? 0 : adc_idx
;
285 imux
= &spec
->input_mux
[mux_idx
];
286 if (!imux
->num_items
&& mux_idx
> 0)
287 imux
= &spec
->input_mux
[0];
289 if (idx
>= imux
->num_items
)
290 idx
= imux
->num_items
- 1;
291 if (spec
->cur_mux
[adc_idx
] == idx
&& !force
)
293 spec
->cur_mux
[adc_idx
] = idx
;
295 if (spec
->dyn_adc_switch
) {
296 alc_dyn_adc_pcm_resetup(codec
, idx
);
297 adc_idx
= spec
->dyn_adc_idx
[idx
];
300 nid
= spec
->capsrc_nids
?
301 spec
->capsrc_nids
[adc_idx
] : spec
->adc_nids
[adc_idx
];
304 if (snd_hda_get_conn_list(codec
, nid
, NULL
) <= 1)
307 type
= get_wcaps_type(get_wcaps(codec
, nid
));
308 if (type
== AC_WID_AUD_MIX
) {
309 /* Matrix-mixer style (e.g. ALC882) */
310 for (i
= 0; i
< imux
->num_items
; i
++) {
311 unsigned int v
= (i
== idx
) ? 0 : HDA_AMP_MUTE
;
312 snd_hda_codec_amp_stereo(codec
, nid
, HDA_INPUT
,
313 imux
->items
[i
].index
,
317 /* MUX style (e.g. ALC880) */
318 snd_hda_codec_write_cache(codec
, nid
, 0,
319 AC_VERB_SET_CONNECT_SEL
,
320 imux
->items
[idx
].index
);
325 static int alc_mux_enum_put(struct snd_kcontrol
*kcontrol
,
326 struct snd_ctl_elem_value
*ucontrol
)
328 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
329 unsigned int adc_idx
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
330 return alc_mux_select(codec
, adc_idx
,
331 ucontrol
->value
.enumerated
.item
[0], false);
335 * set up the input pin config (depending on the given auto-pin type)
337 static void alc_set_input_pin(struct hda_codec
*codec
, hda_nid_t nid
,
340 unsigned int val
= PIN_IN
;
342 if (auto_pin_type
== AUTO_PIN_MIC
) {
345 oldval
= snd_hda_codec_read(codec
, nid
, 0,
346 AC_VERB_GET_PIN_WIDGET_CONTROL
, 0);
347 pincap
= snd_hda_query_pin_caps(codec
, nid
);
348 pincap
= (pincap
& AC_PINCAP_VREF
) >> AC_PINCAP_VREF_SHIFT
;
349 /* if the default pin setup is vref50, we give it priority */
350 if ((pincap
& AC_PINCAP_VREF_80
) && oldval
!= PIN_VREF50
)
352 else if (pincap
& AC_PINCAP_VREF_50
)
354 else if (pincap
& AC_PINCAP_VREF_100
)
356 else if (pincap
& AC_PINCAP_VREF_GRD
)
359 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_PIN_WIDGET_CONTROL
, val
);
363 * Append the given mixer and verb elements for the later use
364 * The mixer array is referred in build_controls(), and init_verbs are
367 static void add_mixer(struct alc_spec
*spec
, const struct snd_kcontrol_new
*mix
)
369 if (snd_BUG_ON(spec
->num_mixers
>= ARRAY_SIZE(spec
->mixers
)))
371 spec
->mixers
[spec
->num_mixers
++] = mix
;
374 static void add_verb(struct alc_spec
*spec
, const struct hda_verb
*verb
)
376 if (snd_BUG_ON(spec
->num_init_verbs
>= ARRAY_SIZE(spec
->init_verbs
)))
378 spec
->init_verbs
[spec
->num_init_verbs
++] = verb
;
382 * GPIO setup tables, used in initialization
384 /* Enable GPIO mask and set output */
385 static const struct hda_verb alc_gpio1_init_verbs
[] = {
386 {0x01, AC_VERB_SET_GPIO_MASK
, 0x01},
387 {0x01, AC_VERB_SET_GPIO_DIRECTION
, 0x01},
388 {0x01, AC_VERB_SET_GPIO_DATA
, 0x01},
392 static const struct hda_verb alc_gpio2_init_verbs
[] = {
393 {0x01, AC_VERB_SET_GPIO_MASK
, 0x02},
394 {0x01, AC_VERB_SET_GPIO_DIRECTION
, 0x02},
395 {0x01, AC_VERB_SET_GPIO_DATA
, 0x02},
399 static const struct hda_verb alc_gpio3_init_verbs
[] = {
400 {0x01, AC_VERB_SET_GPIO_MASK
, 0x03},
401 {0x01, AC_VERB_SET_GPIO_DIRECTION
, 0x03},
402 {0x01, AC_VERB_SET_GPIO_DATA
, 0x03},
407 * Fix hardware PLL issue
408 * On some codecs, the analog PLL gating control must be off while
409 * the default value is 1.
411 static void alc_fix_pll(struct hda_codec
*codec
)
413 struct alc_spec
*spec
= codec
->spec
;
418 snd_hda_codec_write(codec
, spec
->pll_nid
, 0, AC_VERB_SET_COEF_INDEX
,
420 val
= snd_hda_codec_read(codec
, spec
->pll_nid
, 0,
421 AC_VERB_GET_PROC_COEF
, 0);
422 snd_hda_codec_write(codec
, spec
->pll_nid
, 0, AC_VERB_SET_COEF_INDEX
,
424 snd_hda_codec_write(codec
, spec
->pll_nid
, 0, AC_VERB_SET_PROC_COEF
,
425 val
& ~(1 << spec
->pll_coef_bit
));
428 static void alc_fix_pll_init(struct hda_codec
*codec
, hda_nid_t nid
,
429 unsigned int coef_idx
, unsigned int coef_bit
)
431 struct alc_spec
*spec
= codec
->spec
;
433 spec
->pll_coef_idx
= coef_idx
;
434 spec
->pll_coef_bit
= coef_bit
;
439 * Jack-reporting via input-jack layer
442 /* initialization of jacks; currently checks only a few known pins */
443 static int alc_init_jacks(struct hda_codec
*codec
)
445 #ifdef CONFIG_SND_HDA_INPUT_JACK
446 struct alc_spec
*spec
= codec
->spec
;
448 unsigned int hp_nid
= spec
->autocfg
.hp_pins
[0];
449 unsigned int mic_nid
= spec
->ext_mic_pin
;
450 unsigned int dock_nid
= spec
->dock_mic_pin
;
453 err
= snd_hda_input_jack_add(codec
, hp_nid
,
454 SND_JACK_HEADPHONE
, NULL
);
457 snd_hda_input_jack_report(codec
, hp_nid
);
461 err
= snd_hda_input_jack_add(codec
, mic_nid
,
462 SND_JACK_MICROPHONE
, NULL
);
465 snd_hda_input_jack_report(codec
, mic_nid
);
468 err
= snd_hda_input_jack_add(codec
, dock_nid
,
469 SND_JACK_MICROPHONE
, NULL
);
472 snd_hda_input_jack_report(codec
, dock_nid
);
474 #endif /* CONFIG_SND_HDA_INPUT_JACK */
479 * Jack detections for HP auto-mute and mic-switch
482 /* check each pin in the given array; returns true if any of them is plugged */
483 static bool detect_jacks(struct hda_codec
*codec
, int num_pins
, hda_nid_t
*pins
)
487 for (i
= 0; i
< num_pins
; i
++) {
488 hda_nid_t nid
= pins
[i
];
491 snd_hda_input_jack_report(codec
, nid
);
492 present
|= snd_hda_jack_detect(codec
, nid
);
497 /* standard HP/line-out auto-mute helper */
498 static void do_automute(struct hda_codec
*codec
, int num_pins
, hda_nid_t
*pins
,
499 bool mute
, bool hp_out
)
501 struct alc_spec
*spec
= codec
->spec
;
502 unsigned int mute_bits
= mute
? HDA_AMP_MUTE
: 0;
503 unsigned int pin_bits
= mute
? 0 : (hp_out
? PIN_HP
: PIN_OUT
);
506 for (i
= 0; i
< num_pins
; i
++) {
507 hda_nid_t nid
= pins
[i
];
510 switch (spec
->automute_mode
) {
511 case ALC_AUTOMUTE_PIN
:
512 snd_hda_codec_write(codec
, nid
, 0,
513 AC_VERB_SET_PIN_WIDGET_CONTROL
,
516 case ALC_AUTOMUTE_AMP
:
517 snd_hda_codec_amp_stereo(codec
, nid
, HDA_OUTPUT
, 0,
518 HDA_AMP_MUTE
, mute_bits
);
520 case ALC_AUTOMUTE_MIXER
:
521 nid
= spec
->automute_mixer_nid
[i
];
524 snd_hda_codec_amp_stereo(codec
, nid
, HDA_INPUT
, 0,
525 HDA_AMP_MUTE
, mute_bits
);
526 snd_hda_codec_amp_stereo(codec
, nid
, HDA_INPUT
, 1,
527 HDA_AMP_MUTE
, mute_bits
);
533 /* Toggle internal speakers muting */
534 static void update_speakers(struct hda_codec
*codec
)
536 struct alc_spec
*spec
= codec
->spec
;
539 /* Control HP pins/amps depending on master_mute state;
540 * in general, HP pins/amps control should be enabled in all cases,
541 * but currently set only for master_mute, just to be safe
543 do_automute(codec
, ARRAY_SIZE(spec
->autocfg
.hp_pins
),
544 spec
->autocfg
.hp_pins
, spec
->master_mute
, true);
549 on
= spec
->jack_present
| spec
->line_jack_present
;
550 on
|= spec
->master_mute
;
551 do_automute(codec
, ARRAY_SIZE(spec
->autocfg
.speaker_pins
),
552 spec
->autocfg
.speaker_pins
, on
, false);
554 /* toggle line-out mutes if needed, too */
555 /* if LO is a copy of either HP or Speaker, don't need to handle it */
556 if (spec
->autocfg
.line_out_pins
[0] == spec
->autocfg
.hp_pins
[0] ||
557 spec
->autocfg
.line_out_pins
[0] == spec
->autocfg
.speaker_pins
[0])
559 if (!spec
->automute_lines
|| !spec
->automute
)
562 on
= spec
->jack_present
;
563 on
|= spec
->master_mute
;
564 do_automute(codec
, ARRAY_SIZE(spec
->autocfg
.line_out_pins
),
565 spec
->autocfg
.line_out_pins
, on
, false);
568 static void call_update_speakers(struct hda_codec
*codec
)
570 struct alc_spec
*spec
= codec
->spec
;
571 if (spec
->automute_hook
)
572 spec
->automute_hook(codec
);
574 update_speakers(codec
);
577 /* standard HP-automute helper */
578 static void alc_hp_automute(struct hda_codec
*codec
)
580 struct alc_spec
*spec
= codec
->spec
;
583 detect_jacks(codec
, ARRAY_SIZE(spec
->autocfg
.hp_pins
),
584 spec
->autocfg
.hp_pins
);
587 call_update_speakers(codec
);
590 /* standard line-out-automute helper */
591 static void alc_line_automute(struct hda_codec
*codec
)
593 struct alc_spec
*spec
= codec
->spec
;
595 spec
->line_jack_present
=
596 detect_jacks(codec
, ARRAY_SIZE(spec
->autocfg
.line_out_pins
),
597 spec
->autocfg
.line_out_pins
);
598 if (!spec
->automute
|| !spec
->detect_line
)
600 call_update_speakers(codec
);
603 #define get_connection_index(codec, mux, nid) \
604 snd_hda_get_conn_index(codec, mux, nid, 0)
606 /* standard mic auto-switch helper */
607 static void alc_mic_automute(struct hda_codec
*codec
)
609 struct alc_spec
*spec
= codec
->spec
;
610 hda_nid_t
*pins
= spec
->imux_pins
;
612 if (!spec
->auto_mic
|| !spec
->auto_mic_valid_imux
)
614 if (snd_BUG_ON(!spec
->adc_nids
))
616 if (snd_BUG_ON(spec
->int_mic_idx
< 0 || spec
->ext_mic_idx
< 0))
619 if (snd_hda_jack_detect(codec
, pins
[spec
->ext_mic_idx
]))
620 alc_mux_select(codec
, 0, spec
->ext_mic_idx
, false);
621 else if (spec
->dock_mic_idx
>= 0 &&
622 snd_hda_jack_detect(codec
, pins
[spec
->dock_mic_idx
]))
623 alc_mux_select(codec
, 0, spec
->dock_mic_idx
, false);
625 alc_mux_select(codec
, 0, spec
->int_mic_idx
, false);
627 snd_hda_input_jack_report(codec
, pins
[spec
->ext_mic_idx
]);
628 if (spec
->dock_mic_idx
>= 0)
629 snd_hda_input_jack_report(codec
, pins
[spec
->dock_mic_idx
]);
632 /* unsolicited event for HP jack sensing */
633 static void alc_sku_unsol_event(struct hda_codec
*codec
, unsigned int res
)
635 if (codec
->vendor_id
== 0x10ec0880)
641 alc_hp_automute(codec
);
643 case ALC_FRONT_EVENT
:
644 alc_line_automute(codec
);
647 alc_mic_automute(codec
);
652 /* call init functions of standard auto-mute helpers */
653 static void alc_inithook(struct hda_codec
*codec
)
655 alc_hp_automute(codec
);
656 alc_line_automute(codec
);
657 alc_mic_automute(codec
);
660 /* additional initialization for ALC888 variants */
661 static void alc888_coef_init(struct hda_codec
*codec
)
665 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_COEF_INDEX
, 0);
666 tmp
= snd_hda_codec_read(codec
, 0x20, 0, AC_VERB_GET_PROC_COEF
, 0);
667 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_COEF_INDEX
, 7);
668 if ((tmp
& 0xf0) == 0x20)
670 snd_hda_codec_read(codec
, 0x20, 0,
671 AC_VERB_SET_PROC_COEF
, 0x830);
674 snd_hda_codec_read(codec
, 0x20, 0,
675 AC_VERB_SET_PROC_COEF
, 0x3030);
678 /* additional initialization for ALC889 variants */
679 static void alc889_coef_init(struct hda_codec
*codec
)
683 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_COEF_INDEX
, 7);
684 tmp
= snd_hda_codec_read(codec
, 0x20, 0, AC_VERB_GET_PROC_COEF
, 0);
685 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_COEF_INDEX
, 7);
686 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_PROC_COEF
, tmp
|0x2010);
689 /* turn on/off EAPD control (only if available) */
690 static void set_eapd(struct hda_codec
*codec
, hda_nid_t nid
, int on
)
692 if (get_wcaps_type(get_wcaps(codec
, nid
)) != AC_WID_PIN
)
694 if (snd_hda_query_pin_caps(codec
, nid
) & AC_PINCAP_EAPD
)
695 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_EAPD_BTLENABLE
,
699 /* turn on/off EAPD controls of the codec */
700 static void alc_auto_setup_eapd(struct hda_codec
*codec
, bool on
)
702 /* We currently only handle front, HP */
703 static hda_nid_t pins
[] = {
704 0x0f, 0x10, 0x14, 0x15, 0
707 for (p
= pins
; *p
; p
++)
708 set_eapd(codec
, *p
, on
);
711 /* generic shutup callback;
712 * just turning off EPAD and a little pause for avoiding pop-noise
714 static void alc_eapd_shutup(struct hda_codec
*codec
)
716 alc_auto_setup_eapd(codec
, false);
720 /* generic EAPD initialization */
721 static void alc_auto_init_amp(struct hda_codec
*codec
, int type
)
725 alc_auto_setup_eapd(codec
, true);
728 snd_hda_sequence_write(codec
, alc_gpio1_init_verbs
);
731 snd_hda_sequence_write(codec
, alc_gpio2_init_verbs
);
734 snd_hda_sequence_write(codec
, alc_gpio3_init_verbs
);
736 case ALC_INIT_DEFAULT
:
737 switch (codec
->vendor_id
) {
739 snd_hda_codec_write(codec
, 0x1a, 0,
740 AC_VERB_SET_COEF_INDEX
, 7);
741 tmp
= snd_hda_codec_read(codec
, 0x1a, 0,
742 AC_VERB_GET_PROC_COEF
, 0);
743 snd_hda_codec_write(codec
, 0x1a, 0,
744 AC_VERB_SET_COEF_INDEX
, 7);
745 snd_hda_codec_write(codec
, 0x1a, 0,
746 AC_VERB_SET_PROC_COEF
,
755 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
756 alc889_coef_init(codec
);
759 alc888_coef_init(codec
);
761 #if 0 /* XXX: This may cause the silent output on speaker on some machines */
764 snd_hda_codec_write(codec
, 0x20, 0,
765 AC_VERB_SET_COEF_INDEX
, 7);
766 tmp
= snd_hda_codec_read(codec
, 0x20, 0,
767 AC_VERB_GET_PROC_COEF
, 0);
768 snd_hda_codec_write(codec
, 0x20, 0,
769 AC_VERB_SET_COEF_INDEX
, 7);
770 snd_hda_codec_write(codec
, 0x20, 0,
771 AC_VERB_SET_PROC_COEF
,
781 * Auto-Mute mode mixer enum support
783 static int alc_automute_mode_info(struct snd_kcontrol
*kcontrol
,
784 struct snd_ctl_elem_info
*uinfo
)
786 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
787 struct alc_spec
*spec
= codec
->spec
;
788 static const char * const texts2
[] = {
789 "Disabled", "Enabled"
791 static const char * const texts3
[] = {
792 "Disabled", "Speaker Only", "Line-Out+Speaker"
794 const char * const *texts
;
796 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
798 if (spec
->automute_hp_lo
) {
799 uinfo
->value
.enumerated
.items
= 3;
802 uinfo
->value
.enumerated
.items
= 2;
805 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
)
806 uinfo
->value
.enumerated
.item
= uinfo
->value
.enumerated
.items
- 1;
807 strcpy(uinfo
->value
.enumerated
.name
,
808 texts
[uinfo
->value
.enumerated
.item
]);
812 static int alc_automute_mode_get(struct snd_kcontrol
*kcontrol
,
813 struct snd_ctl_elem_value
*ucontrol
)
815 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
816 struct alc_spec
*spec
= codec
->spec
;
820 else if (!spec
->automute_lines
)
824 ucontrol
->value
.enumerated
.item
[0] = val
;
828 static int alc_automute_mode_put(struct snd_kcontrol
*kcontrol
,
829 struct snd_ctl_elem_value
*ucontrol
)
831 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
832 struct alc_spec
*spec
= codec
->spec
;
834 switch (ucontrol
->value
.enumerated
.item
[0]) {
841 if (spec
->automute
&& !spec
->automute_lines
)
844 spec
->automute_lines
= 0;
847 if (!spec
->automute_hp_lo
)
849 if (spec
->automute
&& spec
->automute_lines
)
852 spec
->automute_lines
= 1;
857 call_update_speakers(codec
);
861 static const struct snd_kcontrol_new alc_automute_mode_enum
= {
862 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
863 .name
= "Auto-Mute Mode",
864 .info
= alc_automute_mode_info
,
865 .get
= alc_automute_mode_get
,
866 .put
= alc_automute_mode_put
,
869 static struct snd_kcontrol_new
*alc_kcontrol_new(struct alc_spec
*spec
)
871 snd_array_init(&spec
->kctls
, sizeof(struct snd_kcontrol_new
), 32);
872 return snd_array_new(&spec
->kctls
);
875 static int alc_add_automute_mode_enum(struct hda_codec
*codec
)
877 struct alc_spec
*spec
= codec
->spec
;
878 struct snd_kcontrol_new
*knew
;
880 knew
= alc_kcontrol_new(spec
);
883 *knew
= alc_automute_mode_enum
;
884 knew
->name
= kstrdup("Auto-Mute Mode", GFP_KERNEL
);
891 * Check the availability of HP/line-out auto-mute;
892 * Set up appropriately if really supported
894 static void alc_init_auto_hp(struct hda_codec
*codec
)
896 struct alc_spec
*spec
= codec
->spec
;
897 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
903 if (cfg
->line_out_pins
[0])
905 if (cfg
->speaker_pins
[0])
907 if (present
< 2) /* need two different output types */
910 spec
->automute_hp_lo
= 1; /* both HP and LO automute */
912 if (!cfg
->speaker_pins
[0] &&
913 cfg
->line_out_type
== AUTO_PIN_SPEAKER_OUT
) {
914 memcpy(cfg
->speaker_pins
, cfg
->line_out_pins
,
915 sizeof(cfg
->speaker_pins
));
916 cfg
->speaker_outs
= cfg
->line_outs
;
919 if (!cfg
->hp_pins
[0] &&
920 cfg
->line_out_type
== AUTO_PIN_HP_OUT
) {
921 memcpy(cfg
->hp_pins
, cfg
->line_out_pins
,
922 sizeof(cfg
->hp_pins
));
923 cfg
->hp_outs
= cfg
->line_outs
;
926 for (i
= 0; i
< cfg
->hp_outs
; i
++) {
927 hda_nid_t nid
= cfg
->hp_pins
[i
];
928 if (!is_jack_detectable(codec
, nid
))
930 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
932 snd_hda_codec_write_cache(codec
, nid
, 0,
933 AC_VERB_SET_UNSOLICITED_ENABLE
,
934 AC_USRSP_EN
| ALC_HP_EVENT
);
936 spec
->automute_mode
= ALC_AUTOMUTE_PIN
;
938 if (spec
->automute
&& cfg
->line_out_pins
[0] &&
939 cfg
->speaker_pins
[0] &&
940 cfg
->line_out_pins
[0] != cfg
->hp_pins
[0] &&
941 cfg
->line_out_pins
[0] != cfg
->speaker_pins
[0]) {
942 for (i
= 0; i
< cfg
->line_outs
; i
++) {
943 hda_nid_t nid
= cfg
->line_out_pins
[i
];
944 if (!is_jack_detectable(codec
, nid
))
946 snd_printdd("realtek: Enable Line-Out auto-muting "
947 "on NID 0x%x\n", nid
);
948 snd_hda_codec_write_cache(codec
, nid
, 0,
949 AC_VERB_SET_UNSOLICITED_ENABLE
,
950 AC_USRSP_EN
| ALC_FRONT_EVENT
);
951 spec
->detect_line
= 1;
953 spec
->automute_lines
= spec
->detect_line
;
956 if (spec
->automute
) {
957 /* create a control for automute mode */
958 alc_add_automute_mode_enum(codec
);
959 spec
->unsol_event
= alc_sku_unsol_event
;
963 /* return the position of NID in the list, or -1 if not found */
964 static int find_idx_in_nid_list(hda_nid_t nid
, const hda_nid_t
*list
, int nums
)
967 for (i
= 0; i
< nums
; i
++)
973 /* check whether dynamic ADC-switching is available */
974 static bool alc_check_dyn_adc_switch(struct hda_codec
*codec
)
976 struct alc_spec
*spec
= codec
->spec
;
977 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
981 if (imux
!= spec
->input_mux
) /* no dynamic imux? */
984 for (n
= 0; n
< spec
->num_adc_nids
; n
++) {
985 cap
= spec
->private_capsrc_nids
[n
];
986 for (i
= 0; i
< imux
->num_items
; i
++) {
987 pin
= spec
->imux_pins
[i
];
990 if (get_connection_index(codec
, cap
, pin
) < 0)
993 if (i
>= imux
->num_items
)
994 return true; /* no ADC-switch is needed */
997 for (i
= 0; i
< imux
->num_items
; i
++) {
998 pin
= spec
->imux_pins
[i
];
999 for (n
= 0; n
< spec
->num_adc_nids
; n
++) {
1000 cap
= spec
->private_capsrc_nids
[n
];
1001 idx
= get_connection_index(codec
, cap
, pin
);
1003 imux
->items
[i
].index
= idx
;
1004 spec
->dyn_adc_idx
[i
] = n
;
1010 snd_printdd("realtek: enabling ADC switching\n");
1011 spec
->dyn_adc_switch
= 1;
1015 /* rebuild imux for matching with the given auto-mic pins (if not yet) */
1016 static bool alc_rebuild_imux_for_auto_mic(struct hda_codec
*codec
)
1018 struct alc_spec
*spec
= codec
->spec
;
1019 struct hda_input_mux
*imux
;
1020 static char * const texts
[3] = {
1021 "Mic", "Internal Mic", "Dock Mic"
1025 if (!spec
->auto_mic
)
1027 imux
= &spec
->private_imux
[0];
1028 if (spec
->input_mux
== imux
)
1030 spec
->imux_pins
[0] = spec
->ext_mic_pin
;
1031 spec
->imux_pins
[1] = spec
->int_mic_pin
;
1032 spec
->imux_pins
[2] = spec
->dock_mic_pin
;
1033 for (i
= 0; i
< 3; i
++) {
1034 strcpy(imux
->items
[i
].label
, texts
[i
]);
1035 if (spec
->imux_pins
[i
])
1036 imux
->num_items
= i
+ 1;
1038 spec
->num_mux_defs
= 1;
1039 spec
->input_mux
= imux
;
1043 /* check whether all auto-mic pins are valid; setup indices if OK */
1044 static bool alc_auto_mic_check_imux(struct hda_codec
*codec
)
1046 struct alc_spec
*spec
= codec
->spec
;
1047 const struct hda_input_mux
*imux
;
1049 if (!spec
->auto_mic
)
1051 if (spec
->auto_mic_valid_imux
)
1052 return true; /* already checked */
1054 /* fill up imux indices */
1055 if (!alc_check_dyn_adc_switch(codec
)) {
1060 imux
= spec
->input_mux
;
1061 spec
->ext_mic_idx
= find_idx_in_nid_list(spec
->ext_mic_pin
,
1062 spec
->imux_pins
, imux
->num_items
);
1063 spec
->int_mic_idx
= find_idx_in_nid_list(spec
->int_mic_pin
,
1064 spec
->imux_pins
, imux
->num_items
);
1065 spec
->dock_mic_idx
= find_idx_in_nid_list(spec
->dock_mic_pin
,
1066 spec
->imux_pins
, imux
->num_items
);
1067 if (spec
->ext_mic_idx
< 0 || spec
->int_mic_idx
< 0) {
1069 return false; /* no corresponding imux */
1072 snd_hda_codec_write_cache(codec
, spec
->ext_mic_pin
, 0,
1073 AC_VERB_SET_UNSOLICITED_ENABLE
,
1074 AC_USRSP_EN
| ALC_MIC_EVENT
);
1075 if (spec
->dock_mic_pin
)
1076 snd_hda_codec_write_cache(codec
, spec
->dock_mic_pin
, 0,
1077 AC_VERB_SET_UNSOLICITED_ENABLE
,
1078 AC_USRSP_EN
| ALC_MIC_EVENT
);
1080 spec
->auto_mic_valid_imux
= 1;
1086 * Check the availability of auto-mic switch;
1087 * Set up if really supported
1089 static void alc_init_auto_mic(struct hda_codec
*codec
)
1091 struct alc_spec
*spec
= codec
->spec
;
1092 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
1093 hda_nid_t fixed
, ext
, dock
;
1096 spec
->ext_mic_idx
= spec
->int_mic_idx
= spec
->dock_mic_idx
= -1;
1098 fixed
= ext
= dock
= 0;
1099 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
1100 hda_nid_t nid
= cfg
->inputs
[i
].pin
;
1101 unsigned int defcfg
;
1102 defcfg
= snd_hda_codec_get_pincfg(codec
, nid
);
1103 switch (snd_hda_get_input_pin_attr(defcfg
)) {
1104 case INPUT_PIN_ATTR_INT
:
1106 return; /* already occupied */
1107 if (cfg
->inputs
[i
].type
!= AUTO_PIN_MIC
)
1108 return; /* invalid type */
1111 case INPUT_PIN_ATTR_UNUSED
:
1112 return; /* invalid entry */
1113 case INPUT_PIN_ATTR_DOCK
:
1115 return; /* already occupied */
1116 if (cfg
->inputs
[i
].type
> AUTO_PIN_LINE_IN
)
1117 return; /* invalid type */
1122 return; /* already occupied */
1123 if (cfg
->inputs
[i
].type
!= AUTO_PIN_MIC
)
1124 return; /* invalid type */
1135 if (!is_jack_detectable(codec
, ext
))
1136 return; /* no unsol support */
1137 if (dock
&& !is_jack_detectable(codec
, dock
))
1138 return; /* no unsol support */
1140 /* check imux indices */
1141 spec
->ext_mic_pin
= ext
;
1142 spec
->int_mic_pin
= fixed
;
1143 spec
->dock_mic_pin
= dock
;
1146 if (!alc_auto_mic_check_imux(codec
))
1149 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1151 spec
->unsol_event
= alc_sku_unsol_event
;
1154 /* check the availabilities of auto-mute and auto-mic switches */
1155 static void alc_auto_check_switches(struct hda_codec
*codec
)
1157 alc_init_auto_hp(codec
);
1158 alc_init_auto_mic(codec
);
1162 * Realtek SSID verification
1165 /* Could be any non-zero and even value. When used as fixup, tells
1166 * the driver to ignore any present sku defines.
1168 #define ALC_FIXUP_SKU_IGNORE (2)
1170 static int alc_auto_parse_customize_define(struct hda_codec
*codec
)
1172 unsigned int ass
, tmp
, i
;
1174 struct alc_spec
*spec
= codec
->spec
;
1176 spec
->cdefine
.enable_pcbeep
= 1; /* assume always enabled */
1178 if (spec
->cdefine
.fixup
) {
1179 ass
= spec
->cdefine
.sku_cfg
;
1180 if (ass
== ALC_FIXUP_SKU_IGNORE
)
1185 ass
= codec
->subsystem_id
& 0xffff;
1186 if (ass
!= codec
->bus
->pci
->subsystem_device
&& (ass
& 1))
1190 if (codec
->vendor_id
== 0x10ec0260)
1192 ass
= snd_hda_codec_get_pincfg(codec
, nid
);
1195 printk(KERN_INFO
"hda_codec: %s: SKU not ready 0x%08x\n",
1196 codec
->chip_name
, ass
);
1202 for (i
= 1; i
< 16; i
++) {
1206 if (((ass
>> 16) & 0xf) != tmp
)
1209 spec
->cdefine
.port_connectivity
= ass
>> 30;
1210 spec
->cdefine
.enable_pcbeep
= (ass
& 0x100000) >> 20;
1211 spec
->cdefine
.check_sum
= (ass
>> 16) & 0xf;
1212 spec
->cdefine
.customization
= ass
>> 8;
1214 spec
->cdefine
.sku_cfg
= ass
;
1215 spec
->cdefine
.external_amp
= (ass
& 0x38) >> 3;
1216 spec
->cdefine
.platform_type
= (ass
& 0x4) >> 2;
1217 spec
->cdefine
.swap
= (ass
& 0x2) >> 1;
1218 spec
->cdefine
.override
= ass
& 0x1;
1220 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1221 nid
, spec
->cdefine
.sku_cfg
);
1222 snd_printd("SKU: port_connectivity=0x%x\n",
1223 spec
->cdefine
.port_connectivity
);
1224 snd_printd("SKU: enable_pcbeep=0x%x\n", spec
->cdefine
.enable_pcbeep
);
1225 snd_printd("SKU: check_sum=0x%08x\n", spec
->cdefine
.check_sum
);
1226 snd_printd("SKU: customization=0x%08x\n", spec
->cdefine
.customization
);
1227 snd_printd("SKU: external_amp=0x%x\n", spec
->cdefine
.external_amp
);
1228 snd_printd("SKU: platform_type=0x%x\n", spec
->cdefine
.platform_type
);
1229 snd_printd("SKU: swap=0x%x\n", spec
->cdefine
.swap
);
1230 snd_printd("SKU: override=0x%x\n", spec
->cdefine
.override
);
1235 /* return true if the given NID is found in the list */
1236 static bool found_in_nid_list(hda_nid_t nid
, const hda_nid_t
*list
, int nums
)
1238 return find_idx_in_nid_list(nid
, list
, nums
) >= 0;
1241 /* check subsystem ID and set up device-specific initialization;
1242 * return 1 if initialized, 0 if invalid SSID
1244 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1245 * 31 ~ 16 : Manufacture ID
1247 * 7 ~ 0 : Assembly ID
1248 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1250 static int alc_subsystem_id(struct hda_codec
*codec
,
1251 hda_nid_t porta
, hda_nid_t porte
,
1252 hda_nid_t portd
, hda_nid_t porti
)
1254 unsigned int ass
, tmp
, i
;
1256 struct alc_spec
*spec
= codec
->spec
;
1258 if (spec
->cdefine
.fixup
) {
1259 ass
= spec
->cdefine
.sku_cfg
;
1260 if (ass
== ALC_FIXUP_SKU_IGNORE
)
1265 ass
= codec
->subsystem_id
& 0xffff;
1266 if ((ass
!= codec
->bus
->pci
->subsystem_device
) && (ass
& 1))
1269 /* invalid SSID, check the special NID pin defcfg instead */
1271 * 31~30 : port connectivity
1274 * 19~16 : Check sum (15:1)
1279 if (codec
->vendor_id
== 0x10ec0260)
1281 ass
= snd_hda_codec_get_pincfg(codec
, nid
);
1282 snd_printd("realtek: No valid SSID, "
1283 "checking pincfg 0x%08x for NID 0x%x\n",
1287 if ((ass
>> 30) != 1) /* no physical connection */
1292 for (i
= 1; i
< 16; i
++) {
1296 if (((ass
>> 16) & 0xf) != tmp
)
1299 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1300 ass
& 0xffff, codec
->vendor_id
);
1304 * 2 : 0 --> Desktop, 1 --> Laptop
1305 * 3~5 : External Amplifier control
1308 tmp
= (ass
& 0x38) >> 3; /* external Amp control */
1311 spec
->init_amp
= ALC_INIT_GPIO1
;
1314 spec
->init_amp
= ALC_INIT_GPIO2
;
1317 spec
->init_amp
= ALC_INIT_GPIO3
;
1321 spec
->init_amp
= ALC_INIT_DEFAULT
;
1325 /* is laptop or Desktop and enable the function "Mute internal speaker
1326 * when the external headphone out jack is plugged"
1328 if (!(ass
& 0x8000))
1331 * 10~8 : Jack location
1332 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1334 * 15 : 1 --> enable the function "Mute internal speaker
1335 * when the external headphone out jack is plugged"
1337 if (!spec
->autocfg
.hp_pins
[0]) {
1339 tmp
= (ass
>> 11) & 0x3; /* HP to chassis */
1350 if (found_in_nid_list(nid
, spec
->autocfg
.line_out_pins
,
1351 spec
->autocfg
.line_outs
))
1353 spec
->autocfg
.hp_pins
[0] = nid
;
1358 /* Check the validity of ALC subsystem-id
1359 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1360 static void alc_ssid_check(struct hda_codec
*codec
, const hda_nid_t
*ports
)
1362 if (!alc_subsystem_id(codec
, ports
[0], ports
[1], ports
[2], ports
[3])) {
1363 struct alc_spec
*spec
= codec
->spec
;
1364 snd_printd("realtek: "
1365 "Enable default setup for auto mode as fallback\n");
1366 spec
->init_amp
= ALC_INIT_DEFAULT
;
1371 * Fix-up pin default configurations and add default verbs
1379 struct alc_model_fixup
{
1390 const struct alc_pincfg
*pins
;
1391 const struct hda_verb
*verbs
;
1392 void (*func
)(struct hda_codec
*codec
,
1393 const struct alc_fixup
*fix
,
1407 ALC_FIXUP_ACT_PRE_PROBE
,
1408 ALC_FIXUP_ACT_PROBE
,
1412 static void alc_apply_fixup(struct hda_codec
*codec
, int action
)
1414 struct alc_spec
*spec
= codec
->spec
;
1415 int id
= spec
->fixup_id
;
1416 #ifdef CONFIG_SND_DEBUG_VERBOSE
1417 const char *modelname
= spec
->fixup_name
;
1421 if (!spec
->fixup_list
)
1425 const struct alc_fixup
*fix
= spec
->fixup_list
+ id
;
1426 const struct alc_pincfg
*cfg
;
1428 switch (fix
->type
) {
1430 if (action
!= ALC_FIXUP_ACT_PRE_PROBE
|| !fix
->v
.sku
)
1432 snd_printdd(KERN_INFO
"hda_codec: %s: "
1433 "Apply sku override for %s\n",
1434 codec
->chip_name
, modelname
);
1435 spec
->cdefine
.sku_cfg
= fix
->v
.sku
;
1436 spec
->cdefine
.fixup
= 1;
1438 case ALC_FIXUP_PINS
:
1440 if (action
!= ALC_FIXUP_ACT_PRE_PROBE
|| !cfg
)
1442 snd_printdd(KERN_INFO
"hda_codec: %s: "
1443 "Apply pincfg for %s\n",
1444 codec
->chip_name
, modelname
);
1445 for (; cfg
->nid
; cfg
++)
1446 snd_hda_codec_set_pincfg(codec
, cfg
->nid
,
1449 case ALC_FIXUP_VERBS
:
1450 if (action
!= ALC_FIXUP_ACT_PROBE
|| !fix
->v
.verbs
)
1452 snd_printdd(KERN_INFO
"hda_codec: %s: "
1453 "Apply fix-verbs for %s\n",
1454 codec
->chip_name
, modelname
);
1455 add_verb(codec
->spec
, fix
->v
.verbs
);
1457 case ALC_FIXUP_FUNC
:
1460 snd_printdd(KERN_INFO
"hda_codec: %s: "
1461 "Apply fix-func for %s\n",
1462 codec
->chip_name
, modelname
);
1463 fix
->v
.func(codec
, fix
, action
);
1466 snd_printk(KERN_ERR
"hda_codec: %s: "
1467 "Invalid fixup type %d\n",
1468 codec
->chip_name
, fix
->type
);
1479 static void alc_pick_fixup(struct hda_codec
*codec
,
1480 const struct alc_model_fixup
*models
,
1481 const struct snd_pci_quirk
*quirk
,
1482 const struct alc_fixup
*fixlist
)
1484 struct alc_spec
*spec
= codec
->spec
;
1486 const char *name
= NULL
;
1488 if (codec
->modelname
&& models
) {
1489 while (models
->name
) {
1490 if (!strcmp(codec
->modelname
, models
->name
)) {
1492 name
= models
->name
;
1499 quirk
= snd_pci_quirk_lookup(codec
->bus
->pci
, quirk
);
1502 #ifdef CONFIG_SND_DEBUG_VERBOSE
1508 spec
->fixup_id
= id
;
1510 spec
->fixup_list
= fixlist
;
1511 spec
->fixup_name
= name
;
1516 * COEF access helper functions
1518 static int alc_read_coef_idx(struct hda_codec
*codec
,
1519 unsigned int coef_idx
)
1522 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_COEF_INDEX
,
1524 val
= snd_hda_codec_read(codec
, 0x20, 0,
1525 AC_VERB_GET_PROC_COEF
, 0);
1529 static void alc_write_coef_idx(struct hda_codec
*codec
, unsigned int coef_idx
,
1530 unsigned int coef_val
)
1532 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_COEF_INDEX
,
1534 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_PROC_COEF
,
1539 * Digital I/O handling
1542 /* set right pin controls for digital I/O */
1543 static void alc_auto_init_digital(struct hda_codec
*codec
)
1545 struct alc_spec
*spec
= codec
->spec
;
1549 for (i
= 0; i
< spec
->autocfg
.dig_outs
; i
++) {
1550 pin
= spec
->autocfg
.dig_out_pins
[i
];
1553 snd_hda_codec_write(codec
, pin
, 0,
1554 AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
);
1556 dac
= spec
->multiout
.dig_out_nid
;
1558 dac
= spec
->slave_dig_outs
[i
- 1];
1559 if (!dac
|| !(get_wcaps(codec
, dac
) & AC_WCAP_OUT_AMP
))
1561 snd_hda_codec_write(codec
, dac
, 0,
1562 AC_VERB_SET_AMP_GAIN_MUTE
,
1565 pin
= spec
->autocfg
.dig_in_pin
;
1567 snd_hda_codec_write(codec
, pin
, 0,
1568 AC_VERB_SET_PIN_WIDGET_CONTROL
,
1572 /* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1573 static void alc_auto_parse_digital(struct hda_codec
*codec
)
1575 struct alc_spec
*spec
= codec
->spec
;
1579 /* support multiple SPDIFs; the secondary is set up as a slave */
1580 for (i
= 0; i
< spec
->autocfg
.dig_outs
; i
++) {
1582 err
= snd_hda_get_connections(codec
,
1583 spec
->autocfg
.dig_out_pins
[i
],
1584 conn
, ARRAY_SIZE(conn
));
1587 dig_nid
= conn
[0]; /* assume the first element is audio-out */
1589 spec
->multiout
.dig_out_nid
= dig_nid
;
1590 spec
->dig_out_type
= spec
->autocfg
.dig_out_type
[0];
1592 spec
->multiout
.slave_dig_outs
= spec
->slave_dig_outs
;
1593 if (i
>= ARRAY_SIZE(spec
->slave_dig_outs
) - 1)
1595 spec
->slave_dig_outs
[i
- 1] = dig_nid
;
1599 if (spec
->autocfg
.dig_in_pin
) {
1600 dig_nid
= codec
->start_nid
;
1601 for (i
= 0; i
< codec
->num_nodes
; i
++, dig_nid
++) {
1602 unsigned int wcaps
= get_wcaps(codec
, dig_nid
);
1603 if (get_wcaps_type(wcaps
) != AC_WID_AUD_IN
)
1605 if (!(wcaps
& AC_WCAP_DIGITAL
))
1607 if (!(wcaps
& AC_WCAP_CONN_LIST
))
1609 err
= get_connection_index(codec
, dig_nid
,
1610 spec
->autocfg
.dig_in_pin
);
1612 spec
->dig_in_nid
= dig_nid
;
1620 * capture mixer elements
1622 static int alc_cap_vol_info(struct snd_kcontrol
*kcontrol
,
1623 struct snd_ctl_elem_info
*uinfo
)
1625 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1626 struct alc_spec
*spec
= codec
->spec
;
1630 mutex_lock(&codec
->control_mutex
);
1631 if (spec
->vol_in_capsrc
)
1632 val
= HDA_COMPOSE_AMP_VAL(spec
->capsrc_nids
[0], 3, 0, HDA_OUTPUT
);
1634 val
= HDA_COMPOSE_AMP_VAL(spec
->adc_nids
[0], 3, 0, HDA_INPUT
);
1635 kcontrol
->private_value
= val
;
1636 err
= snd_hda_mixer_amp_volume_info(kcontrol
, uinfo
);
1637 mutex_unlock(&codec
->control_mutex
);
1641 static int alc_cap_vol_tlv(struct snd_kcontrol
*kcontrol
, int op_flag
,
1642 unsigned int size
, unsigned int __user
*tlv
)
1644 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1645 struct alc_spec
*spec
= codec
->spec
;
1649 mutex_lock(&codec
->control_mutex
);
1650 if (spec
->vol_in_capsrc
)
1651 val
= HDA_COMPOSE_AMP_VAL(spec
->capsrc_nids
[0], 3, 0, HDA_OUTPUT
);
1653 val
= HDA_COMPOSE_AMP_VAL(spec
->adc_nids
[0], 3, 0, HDA_INPUT
);
1654 kcontrol
->private_value
= val
;
1655 err
= snd_hda_mixer_amp_tlv(kcontrol
, op_flag
, size
, tlv
);
1656 mutex_unlock(&codec
->control_mutex
);
1660 typedef int (*getput_call_t
)(struct snd_kcontrol
*kcontrol
,
1661 struct snd_ctl_elem_value
*ucontrol
);
1663 static int alc_cap_getput_caller(struct snd_kcontrol
*kcontrol
,
1664 struct snd_ctl_elem_value
*ucontrol
,
1665 getput_call_t func
, bool check_adc_switch
)
1667 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1668 struct alc_spec
*spec
= codec
->spec
;
1671 mutex_lock(&codec
->control_mutex
);
1672 if (check_adc_switch
&& spec
->dyn_adc_switch
) {
1673 for (i
= 0; i
< spec
->num_adc_nids
; i
++) {
1674 kcontrol
->private_value
=
1675 HDA_COMPOSE_AMP_VAL(spec
->adc_nids
[i
],
1677 err
= func(kcontrol
, ucontrol
);
1682 i
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
1683 if (spec
->vol_in_capsrc
)
1684 kcontrol
->private_value
=
1685 HDA_COMPOSE_AMP_VAL(spec
->capsrc_nids
[i
],
1688 kcontrol
->private_value
=
1689 HDA_COMPOSE_AMP_VAL(spec
->adc_nids
[i
],
1691 err
= func(kcontrol
, ucontrol
);
1694 mutex_unlock(&codec
->control_mutex
);
1698 static int alc_cap_vol_get(struct snd_kcontrol
*kcontrol
,
1699 struct snd_ctl_elem_value
*ucontrol
)
1701 return alc_cap_getput_caller(kcontrol
, ucontrol
,
1702 snd_hda_mixer_amp_volume_get
, false);
1705 static int alc_cap_vol_put(struct snd_kcontrol
*kcontrol
,
1706 struct snd_ctl_elem_value
*ucontrol
)
1708 return alc_cap_getput_caller(kcontrol
, ucontrol
,
1709 snd_hda_mixer_amp_volume_put
, true);
1712 /* capture mixer elements */
1713 #define alc_cap_sw_info snd_ctl_boolean_stereo_info
1715 static int alc_cap_sw_get(struct snd_kcontrol
*kcontrol
,
1716 struct snd_ctl_elem_value
*ucontrol
)
1718 return alc_cap_getput_caller(kcontrol
, ucontrol
,
1719 snd_hda_mixer_amp_switch_get
, false);
1722 static int alc_cap_sw_put(struct snd_kcontrol
*kcontrol
,
1723 struct snd_ctl_elem_value
*ucontrol
)
1725 return alc_cap_getput_caller(kcontrol
, ucontrol
,
1726 snd_hda_mixer_amp_switch_put
, true);
1729 #define _DEFINE_CAPMIX(num) \
1731 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1732 .name = "Capture Switch", \
1733 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1735 .info = alc_cap_sw_info, \
1736 .get = alc_cap_sw_get, \
1737 .put = alc_cap_sw_put, \
1740 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1741 .name = "Capture Volume", \
1742 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1743 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1744 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1746 .info = alc_cap_vol_info, \
1747 .get = alc_cap_vol_get, \
1748 .put = alc_cap_vol_put, \
1749 .tlv = { .c = alc_cap_vol_tlv }, \
1752 #define _DEFINE_CAPSRC(num) \
1754 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1755 /* .name = "Capture Source", */ \
1756 .name = "Input Source", \
1758 .info = alc_mux_enum_info, \
1759 .get = alc_mux_enum_get, \
1760 .put = alc_mux_enum_put, \
1763 #define DEFINE_CAPMIX(num) \
1764 static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
1765 _DEFINE_CAPMIX(num), \
1766 _DEFINE_CAPSRC(num), \
1770 #define DEFINE_CAPMIX_NOSRC(num) \
1771 static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
1772 _DEFINE_CAPMIX(num), \
1776 /* up to three ADCs */
1780 DEFINE_CAPMIX_NOSRC(1);
1781 DEFINE_CAPMIX_NOSRC(2);
1782 DEFINE_CAPMIX_NOSRC(3);
1785 * virtual master controls
1789 * slave controls for virtual master
1791 static const char * const alc_slave_vols
[] = {
1792 "Front Playback Volume",
1793 "Surround Playback Volume",
1794 "Center Playback Volume",
1795 "LFE Playback Volume",
1796 "Side Playback Volume",
1797 "Headphone Playback Volume",
1798 "Speaker Playback Volume",
1799 "Mono Playback Volume",
1800 "Line-Out Playback Volume",
1801 "PCM Playback Volume",
1805 static const char * const alc_slave_sws
[] = {
1806 "Front Playback Switch",
1807 "Surround Playback Switch",
1808 "Center Playback Switch",
1809 "LFE Playback Switch",
1810 "Side Playback Switch",
1811 "Headphone Playback Switch",
1812 "Speaker Playback Switch",
1813 "Mono Playback Switch",
1814 "IEC958 Playback Switch",
1815 "Line-Out Playback Switch",
1816 "PCM Playback Switch",
1821 * build control elements
1824 #define NID_MAPPING (-1)
1826 #define SUBDEV_SPEAKER_ (0 << 6)
1827 #define SUBDEV_HP_ (1 << 6)
1828 #define SUBDEV_LINE_ (2 << 6)
1829 #define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1830 #define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1831 #define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1833 static void alc_free_kctls(struct hda_codec
*codec
);
1835 #ifdef CONFIG_SND_HDA_INPUT_BEEP
1836 /* additional beep mixers; the actual parameters are overwritten at build */
1837 static const struct snd_kcontrol_new alc_beep_mixer
[] = {
1838 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT
),
1839 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT
),
1844 static int alc_build_controls(struct hda_codec
*codec
)
1846 struct alc_spec
*spec
= codec
->spec
;
1847 struct snd_kcontrol
*kctl
= NULL
;
1848 const struct snd_kcontrol_new
*knew
;
1853 for (i
= 0; i
< spec
->num_mixers
; i
++) {
1854 err
= snd_hda_add_new_ctls(codec
, spec
->mixers
[i
]);
1858 if (spec
->cap_mixer
) {
1859 err
= snd_hda_add_new_ctls(codec
, spec
->cap_mixer
);
1863 if (spec
->multiout
.dig_out_nid
) {
1864 err
= snd_hda_create_spdif_out_ctls(codec
,
1865 spec
->multiout
.dig_out_nid
,
1866 spec
->multiout
.dig_out_nid
);
1869 if (!spec
->no_analog
) {
1870 err
= snd_hda_create_spdif_share_sw(codec
,
1874 spec
->multiout
.share_spdif
= 1;
1877 if (spec
->dig_in_nid
) {
1878 err
= snd_hda_create_spdif_in_ctls(codec
, spec
->dig_in_nid
);
1883 #ifdef CONFIG_SND_HDA_INPUT_BEEP
1884 /* create beep controls if needed */
1885 if (spec
->beep_amp
) {
1886 const struct snd_kcontrol_new
*knew
;
1887 for (knew
= alc_beep_mixer
; knew
->name
; knew
++) {
1888 struct snd_kcontrol
*kctl
;
1889 kctl
= snd_ctl_new1(knew
, codec
);
1892 kctl
->private_value
= spec
->beep_amp
;
1893 err
= snd_hda_ctl_add(codec
, 0, kctl
);
1900 /* if we have no master control, let's create it */
1901 if (!spec
->no_analog
&&
1902 !snd_hda_find_mixer_ctl(codec
, "Master Playback Volume")) {
1903 unsigned int vmaster_tlv
[4];
1904 snd_hda_set_vmaster_tlv(codec
, spec
->vmaster_nid
,
1905 HDA_OUTPUT
, vmaster_tlv
);
1906 err
= snd_hda_add_vmaster(codec
, "Master Playback Volume",
1907 vmaster_tlv
, alc_slave_vols
);
1911 if (!spec
->no_analog
&&
1912 !snd_hda_find_mixer_ctl(codec
, "Master Playback Switch")) {
1913 err
= snd_hda_add_vmaster(codec
, "Master Playback Switch",
1914 NULL
, alc_slave_sws
);
1919 /* assign Capture Source enums to NID */
1920 if (spec
->capsrc_nids
|| spec
->adc_nids
) {
1921 kctl
= snd_hda_find_mixer_ctl(codec
, "Capture Source");
1923 kctl
= snd_hda_find_mixer_ctl(codec
, "Input Source");
1924 for (i
= 0; kctl
&& i
< kctl
->count
; i
++) {
1925 const hda_nid_t
*nids
= spec
->capsrc_nids
;
1927 nids
= spec
->adc_nids
;
1928 err
= snd_hda_add_nid(codec
, kctl
, i
, nids
[i
]);
1933 if (spec
->cap_mixer
&& spec
->adc_nids
) {
1934 const char *kname
= kctl
? kctl
->id
.name
: NULL
;
1935 for (knew
= spec
->cap_mixer
; knew
->name
; knew
++) {
1936 if (kname
&& strcmp(knew
->name
, kname
) == 0)
1938 kctl
= snd_hda_find_mixer_ctl(codec
, knew
->name
);
1939 for (i
= 0; kctl
&& i
< kctl
->count
; i
++) {
1940 err
= snd_hda_add_nid(codec
, kctl
, i
,
1948 /* other nid->control mapping */
1949 for (i
= 0; i
< spec
->num_mixers
; i
++) {
1950 for (knew
= spec
->mixers
[i
]; knew
->name
; knew
++) {
1951 if (knew
->iface
!= NID_MAPPING
)
1953 kctl
= snd_hda_find_mixer_ctl(codec
, knew
->name
);
1956 u
= knew
->subdevice
;
1957 for (j
= 0; j
< 4; j
++, u
>>= 8) {
1962 case SUBDEV_SPEAKER_
:
1963 nid
= spec
->autocfg
.speaker_pins
[nid
];
1966 nid
= spec
->autocfg
.line_out_pins
[nid
];
1969 nid
= spec
->autocfg
.hp_pins
[nid
];
1974 err
= snd_hda_add_nid(codec
, kctl
, 0, nid
);
1978 u
= knew
->private_value
;
1979 for (j
= 0; j
< 4; j
++, u
>>= 8) {
1983 err
= snd_hda_add_nid(codec
, kctl
, 0, nid
);
1990 alc_free_kctls(codec
); /* no longer needed */
2000 static void alc_init_special_input_src(struct hda_codec
*codec
);
2002 static int alc_init(struct hda_codec
*codec
)
2004 struct alc_spec
*spec
= codec
->spec
;
2008 alc_auto_init_amp(codec
, spec
->init_amp
);
2010 for (i
= 0; i
< spec
->num_init_verbs
; i
++)
2011 snd_hda_sequence_write(codec
, spec
->init_verbs
[i
]);
2012 alc_init_special_input_src(codec
);
2014 if (spec
->init_hook
)
2015 spec
->init_hook(codec
);
2017 alc_apply_fixup(codec
, ALC_FIXUP_ACT_INIT
);
2019 hda_call_check_power_status(codec
, 0x01);
2023 static void alc_unsol_event(struct hda_codec
*codec
, unsigned int res
)
2025 struct alc_spec
*spec
= codec
->spec
;
2027 if (spec
->unsol_event
)
2028 spec
->unsol_event(codec
, res
);
2031 #ifdef CONFIG_SND_HDA_POWER_SAVE
2032 static int alc_check_power_status(struct hda_codec
*codec
, hda_nid_t nid
)
2034 struct alc_spec
*spec
= codec
->spec
;
2035 return snd_hda_check_amp_list_power(codec
, &spec
->loopback
, nid
);
2040 * Analog playback callbacks
2042 static int alc_playback_pcm_open(struct hda_pcm_stream
*hinfo
,
2043 struct hda_codec
*codec
,
2044 struct snd_pcm_substream
*substream
)
2046 struct alc_spec
*spec
= codec
->spec
;
2047 return snd_hda_multi_out_analog_open(codec
, &spec
->multiout
, substream
,
2051 static int alc_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
2052 struct hda_codec
*codec
,
2053 unsigned int stream_tag
,
2054 unsigned int format
,
2055 struct snd_pcm_substream
*substream
)
2057 struct alc_spec
*spec
= codec
->spec
;
2058 return snd_hda_multi_out_analog_prepare(codec
, &spec
->multiout
,
2059 stream_tag
, format
, substream
);
2062 static int alc_playback_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
2063 struct hda_codec
*codec
,
2064 struct snd_pcm_substream
*substream
)
2066 struct alc_spec
*spec
= codec
->spec
;
2067 return snd_hda_multi_out_analog_cleanup(codec
, &spec
->multiout
);
2073 static int alc_dig_playback_pcm_open(struct hda_pcm_stream
*hinfo
,
2074 struct hda_codec
*codec
,
2075 struct snd_pcm_substream
*substream
)
2077 struct alc_spec
*spec
= codec
->spec
;
2078 return snd_hda_multi_out_dig_open(codec
, &spec
->multiout
);
2081 static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
2082 struct hda_codec
*codec
,
2083 unsigned int stream_tag
,
2084 unsigned int format
,
2085 struct snd_pcm_substream
*substream
)
2087 struct alc_spec
*spec
= codec
->spec
;
2088 return snd_hda_multi_out_dig_prepare(codec
, &spec
->multiout
,
2089 stream_tag
, format
, substream
);
2092 static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
2093 struct hda_codec
*codec
,
2094 struct snd_pcm_substream
*substream
)
2096 struct alc_spec
*spec
= codec
->spec
;
2097 return snd_hda_multi_out_dig_cleanup(codec
, &spec
->multiout
);
2100 static int alc_dig_playback_pcm_close(struct hda_pcm_stream
*hinfo
,
2101 struct hda_codec
*codec
,
2102 struct snd_pcm_substream
*substream
)
2104 struct alc_spec
*spec
= codec
->spec
;
2105 return snd_hda_multi_out_dig_close(codec
, &spec
->multiout
);
2111 static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream
*hinfo
,
2112 struct hda_codec
*codec
,
2113 unsigned int stream_tag
,
2114 unsigned int format
,
2115 struct snd_pcm_substream
*substream
)
2117 struct alc_spec
*spec
= codec
->spec
;
2119 snd_hda_codec_setup_stream(codec
, spec
->adc_nids
[substream
->number
+ 1],
2120 stream_tag
, 0, format
);
2124 static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
2125 struct hda_codec
*codec
,
2126 struct snd_pcm_substream
*substream
)
2128 struct alc_spec
*spec
= codec
->spec
;
2130 snd_hda_codec_cleanup_stream(codec
,
2131 spec
->adc_nids
[substream
->number
+ 1]);
2135 /* analog capture with dynamic dual-adc changes */
2136 static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream
*hinfo
,
2137 struct hda_codec
*codec
,
2138 unsigned int stream_tag
,
2139 unsigned int format
,
2140 struct snd_pcm_substream
*substream
)
2142 struct alc_spec
*spec
= codec
->spec
;
2143 spec
->cur_adc
= spec
->adc_nids
[spec
->dyn_adc_idx
[spec
->cur_mux
[0]]];
2144 spec
->cur_adc_stream_tag
= stream_tag
;
2145 spec
->cur_adc_format
= format
;
2146 snd_hda_codec_setup_stream(codec
, spec
->cur_adc
, stream_tag
, 0, format
);
2150 static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
2151 struct hda_codec
*codec
,
2152 struct snd_pcm_substream
*substream
)
2154 struct alc_spec
*spec
= codec
->spec
;
2155 snd_hda_codec_cleanup_stream(codec
, spec
->cur_adc
);
2160 static const struct hda_pcm_stream dyn_adc_pcm_analog_capture
= {
2164 .nid
= 0, /* fill later */
2166 .prepare
= dyn_adc_capture_pcm_prepare
,
2167 .cleanup
= dyn_adc_capture_pcm_cleanup
2173 static const struct hda_pcm_stream alc_pcm_analog_playback
= {
2177 /* NID is set in alc_build_pcms */
2179 .open
= alc_playback_pcm_open
,
2180 .prepare
= alc_playback_pcm_prepare
,
2181 .cleanup
= alc_playback_pcm_cleanup
2185 static const struct hda_pcm_stream alc_pcm_analog_capture
= {
2189 /* NID is set in alc_build_pcms */
2192 static const struct hda_pcm_stream alc_pcm_analog_alt_playback
= {
2196 /* NID is set in alc_build_pcms */
2199 static const struct hda_pcm_stream alc_pcm_analog_alt_capture
= {
2200 .substreams
= 2, /* can be overridden */
2203 /* NID is set in alc_build_pcms */
2205 .prepare
= alc_alt_capture_pcm_prepare
,
2206 .cleanup
= alc_alt_capture_pcm_cleanup
2210 static const struct hda_pcm_stream alc_pcm_digital_playback
= {
2214 /* NID is set in alc_build_pcms */
2216 .open
= alc_dig_playback_pcm_open
,
2217 .close
= alc_dig_playback_pcm_close
,
2218 .prepare
= alc_dig_playback_pcm_prepare
,
2219 .cleanup
= alc_dig_playback_pcm_cleanup
2223 static const struct hda_pcm_stream alc_pcm_digital_capture
= {
2227 /* NID is set in alc_build_pcms */
2230 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
2231 static const struct hda_pcm_stream alc_pcm_null_stream
= {
2237 static int alc_build_pcms(struct hda_codec
*codec
)
2239 struct alc_spec
*spec
= codec
->spec
;
2240 struct hda_pcm
*info
= spec
->pcm_rec
;
2241 const struct hda_pcm_stream
*p
;
2244 codec
->num_pcms
= 1;
2245 codec
->pcm_info
= info
;
2247 if (spec
->no_analog
)
2250 snprintf(spec
->stream_name_analog
, sizeof(spec
->stream_name_analog
),
2251 "%s Analog", codec
->chip_name
);
2252 info
->name
= spec
->stream_name_analog
;
2254 if (spec
->multiout
.dac_nids
> 0) {
2255 p
= spec
->stream_analog_playback
;
2257 p
= &alc_pcm_analog_playback
;
2258 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] = *p
;
2259 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
= spec
->multiout
.dac_nids
[0];
2261 if (spec
->adc_nids
) {
2262 p
= spec
->stream_analog_capture
;
2264 if (spec
->dyn_adc_switch
)
2265 p
= &dyn_adc_pcm_analog_capture
;
2267 p
= &alc_pcm_analog_capture
;
2269 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] = *p
;
2270 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
= spec
->adc_nids
[0];
2273 if (spec
->channel_mode
) {
2274 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].channels_max
= 0;
2275 for (i
= 0; i
< spec
->num_channel_mode
; i
++) {
2276 if (spec
->channel_mode
[i
].channels
> info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].channels_max
) {
2277 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].channels_max
= spec
->channel_mode
[i
].channels
;
2283 /* SPDIF for stream index #1 */
2284 if (spec
->multiout
.dig_out_nid
|| spec
->dig_in_nid
) {
2285 snprintf(spec
->stream_name_digital
,
2286 sizeof(spec
->stream_name_digital
),
2287 "%s Digital", codec
->chip_name
);
2288 codec
->num_pcms
= 2;
2289 codec
->slave_dig_outs
= spec
->multiout
.slave_dig_outs
;
2290 info
= spec
->pcm_rec
+ 1;
2291 info
->name
= spec
->stream_name_digital
;
2292 if (spec
->dig_out_type
)
2293 info
->pcm_type
= spec
->dig_out_type
;
2295 info
->pcm_type
= HDA_PCM_TYPE_SPDIF
;
2296 if (spec
->multiout
.dig_out_nid
) {
2297 p
= spec
->stream_digital_playback
;
2299 p
= &alc_pcm_digital_playback
;
2300 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] = *p
;
2301 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
= spec
->multiout
.dig_out_nid
;
2303 if (spec
->dig_in_nid
) {
2304 p
= spec
->stream_digital_capture
;
2306 p
= &alc_pcm_digital_capture
;
2307 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] = *p
;
2308 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
= spec
->dig_in_nid
;
2310 /* FIXME: do we need this for all Realtek codec models? */
2311 codec
->spdif_status_reset
= 1;
2314 if (spec
->no_analog
)
2317 /* If the use of more than one ADC is requested for the current
2318 * model, configure a second analog capture-only PCM.
2320 /* Additional Analaog capture for index #2 */
2321 if (spec
->alt_dac_nid
|| spec
->num_adc_nids
> 1) {
2322 codec
->num_pcms
= 3;
2323 info
= spec
->pcm_rec
+ 2;
2324 info
->name
= spec
->stream_name_analog
;
2325 if (spec
->alt_dac_nid
) {
2326 p
= spec
->stream_analog_alt_playback
;
2328 p
= &alc_pcm_analog_alt_playback
;
2329 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] = *p
;
2330 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
=
2333 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] =
2334 alc_pcm_null_stream
;
2335 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
= 0;
2337 if (spec
->num_adc_nids
> 1) {
2338 p
= spec
->stream_analog_alt_capture
;
2340 p
= &alc_pcm_analog_alt_capture
;
2341 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] = *p
;
2342 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
=
2344 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].substreams
=
2345 spec
->num_adc_nids
- 1;
2347 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] =
2348 alc_pcm_null_stream
;
2349 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
= 0;
2356 static inline void alc_shutup(struct hda_codec
*codec
)
2358 struct alc_spec
*spec
= codec
->spec
;
2360 if (spec
&& spec
->shutup
)
2361 spec
->shutup(codec
);
2362 snd_hda_shutup_pins(codec
);
2365 static void alc_free_kctls(struct hda_codec
*codec
)
2367 struct alc_spec
*spec
= codec
->spec
;
2369 if (spec
->kctls
.list
) {
2370 struct snd_kcontrol_new
*kctl
= spec
->kctls
.list
;
2372 for (i
= 0; i
< spec
->kctls
.used
; i
++)
2373 kfree(kctl
[i
].name
);
2375 snd_array_free(&spec
->kctls
);
2378 static void alc_free_bind_ctls(struct hda_codec
*codec
)
2380 struct alc_spec
*spec
= codec
->spec
;
2381 if (spec
->bind_ctls
.list
) {
2382 struct hda_bind_ctls
**ctl
= spec
->bind_ctls
.list
;
2384 for (i
= 0; i
< spec
->bind_ctls
.used
; i
++)
2387 snd_array_free(&spec
->bind_ctls
);
2390 static void alc_free(struct hda_codec
*codec
)
2392 struct alc_spec
*spec
= codec
->spec
;
2398 snd_hda_input_jack_free(codec
);
2399 alc_free_kctls(codec
);
2400 alc_free_bind_ctls(codec
);
2402 snd_hda_detach_beep_device(codec
);
2405 #ifdef CONFIG_SND_HDA_POWER_SAVE
2406 static void alc_power_eapd(struct hda_codec
*codec
)
2408 alc_auto_setup_eapd(codec
, false);
2411 static int alc_suspend(struct hda_codec
*codec
, pm_message_t state
)
2413 struct alc_spec
*spec
= codec
->spec
;
2415 if (spec
&& spec
->power_hook
)
2416 spec
->power_hook(codec
);
2422 static int alc_resume(struct hda_codec
*codec
)
2424 msleep(150); /* to avoid pop noise */
2425 codec
->patch_ops
.init(codec
);
2426 snd_hda_codec_resume_amp(codec
);
2427 snd_hda_codec_resume_cache(codec
);
2428 hda_call_check_power_status(codec
, 0x01);
2435 static const struct hda_codec_ops alc_patch_ops
= {
2436 .build_controls
= alc_build_controls
,
2437 .build_pcms
= alc_build_pcms
,
2440 .unsol_event
= alc_unsol_event
,
2442 .resume
= alc_resume
,
2444 #ifdef CONFIG_SND_HDA_POWER_SAVE
2445 .suspend
= alc_suspend
,
2446 .check_power_status
= alc_check_power_status
,
2448 .reboot_notify
= alc_shutup
,
2451 /* replace the codec chip_name with the given string */
2452 static int alc_codec_rename(struct hda_codec
*codec
, const char *name
)
2454 kfree(codec
->chip_name
);
2455 codec
->chip_name
= kstrdup(name
, GFP_KERNEL
);
2456 if (!codec
->chip_name
) {
2464 * Automatic parse of I/O pins from the BIOS configuration
2469 ALC_CTL_WIDGET_MUTE
,
2474 static const struct snd_kcontrol_new alc_control_templates
[] = {
2475 HDA_CODEC_VOLUME(NULL
, 0, 0, 0),
2476 HDA_CODEC_MUTE(NULL
, 0, 0, 0),
2477 HDA_BIND_MUTE(NULL
, 0, 0, 0),
2478 HDA_BIND_VOL(NULL
, 0),
2479 HDA_BIND_SW(NULL
, 0),
2482 /* add dynamic controls */
2483 static int add_control(struct alc_spec
*spec
, int type
, const char *name
,
2484 int cidx
, unsigned long val
)
2486 struct snd_kcontrol_new
*knew
;
2488 knew
= alc_kcontrol_new(spec
);
2491 *knew
= alc_control_templates
[type
];
2492 knew
->name
= kstrdup(name
, GFP_KERNEL
);
2496 if (get_amp_nid_(val
))
2497 knew
->subdevice
= HDA_SUBDEV_AMP_FLAG
;
2498 knew
->private_value
= val
;
2502 static int add_control_with_pfx(struct alc_spec
*spec
, int type
,
2503 const char *pfx
, const char *dir
,
2504 const char *sfx
, int cidx
, unsigned long val
)
2507 snprintf(name
, sizeof(name
), "%s %s %s", pfx
, dir
, sfx
);
2508 return add_control(spec
, type
, name
, cidx
, val
);
2511 #define add_pb_vol_ctrl(spec, type, pfx, val) \
2512 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2513 #define add_pb_sw_ctrl(spec, type, pfx, val) \
2514 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2515 #define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2516 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2517 #define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2518 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
2520 static const char * const channel_name
[4] = {
2521 "Front", "Surround", "CLFE", "Side"
2524 static const char *alc_get_line_out_pfx(struct alc_spec
*spec
, int ch
,
2525 bool can_be_master
, int *index
)
2527 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
2530 if (cfg
->line_outs
== 1 && !spec
->multi_ios
&&
2531 !cfg
->hp_outs
&& !cfg
->speaker_outs
&& can_be_master
)
2534 switch (cfg
->line_out_type
) {
2535 case AUTO_PIN_SPEAKER_OUT
:
2536 if (cfg
->line_outs
== 1)
2539 case AUTO_PIN_HP_OUT
:
2540 /* for multi-io case, only the primary out */
2541 if (ch
&& spec
->multi_ios
)
2546 if (cfg
->line_outs
== 1 && !spec
->multi_ios
)
2550 if (snd_BUG_ON(ch
>= ARRAY_SIZE(channel_name
)))
2553 return channel_name
[ch
];
2556 /* create input playback/capture controls for the given pin */
2557 static int new_analog_input(struct alc_spec
*spec
, hda_nid_t pin
,
2558 const char *ctlname
, int ctlidx
,
2559 int idx
, hda_nid_t mix_nid
)
2563 err
= __add_pb_vol_ctrl(spec
, ALC_CTL_WIDGET_VOL
, ctlname
, ctlidx
,
2564 HDA_COMPOSE_AMP_VAL(mix_nid
, 3, idx
, HDA_INPUT
));
2567 err
= __add_pb_sw_ctrl(spec
, ALC_CTL_WIDGET_MUTE
, ctlname
, ctlidx
,
2568 HDA_COMPOSE_AMP_VAL(mix_nid
, 3, idx
, HDA_INPUT
));
2574 static int alc_is_input_pin(struct hda_codec
*codec
, hda_nid_t nid
)
2576 unsigned int pincap
= snd_hda_query_pin_caps(codec
, nid
);
2577 return (pincap
& AC_PINCAP_IN
) != 0;
2580 /* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
2581 static int alc_auto_fill_adc_caps(struct hda_codec
*codec
)
2583 struct alc_spec
*spec
= codec
->spec
;
2585 hda_nid_t
*adc_nids
= spec
->private_adc_nids
;
2586 hda_nid_t
*cap_nids
= spec
->private_capsrc_nids
;
2587 int max_nums
= ARRAY_SIZE(spec
->private_adc_nids
);
2588 bool indep_capsrc
= false;
2591 nid
= codec
->start_nid
;
2592 for (i
= 0; i
< codec
->num_nodes
; i
++, nid
++) {
2594 const hda_nid_t
*list
;
2595 unsigned int caps
= get_wcaps(codec
, nid
);
2596 int type
= get_wcaps_type(caps
);
2598 if (type
!= AC_WID_AUD_IN
|| (caps
& AC_WCAP_DIGITAL
))
2600 adc_nids
[nums
] = nid
;
2601 cap_nids
[nums
] = nid
;
2605 type
= get_wcaps_type(get_wcaps(codec
, src
));
2606 if (type
== AC_WID_PIN
)
2608 if (type
== AC_WID_AUD_SEL
) {
2609 cap_nids
[nums
] = src
;
2610 indep_capsrc
= true;
2613 n
= snd_hda_get_conn_list(codec
, src
, &list
);
2615 cap_nids
[nums
] = src
;
2616 indep_capsrc
= true;
2622 if (++nums
>= max_nums
)
2625 spec
->adc_nids
= spec
->private_adc_nids
;
2626 spec
->capsrc_nids
= spec
->private_capsrc_nids
;
2627 spec
->num_adc_nids
= nums
;
2631 /* create playback/capture controls for input pins */
2632 static int alc_auto_create_input_ctls(struct hda_codec
*codec
)
2634 struct alc_spec
*spec
= codec
->spec
;
2635 const struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
2636 hda_nid_t mixer
= spec
->mixer_nid
;
2637 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
2639 int i
, c
, err
, idx
, type_idx
= 0;
2640 const char *prev_label
= NULL
;
2642 num_adcs
= alc_auto_fill_adc_caps(codec
);
2646 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
2650 pin
= cfg
->inputs
[i
].pin
;
2651 if (!alc_is_input_pin(codec
, pin
))
2654 label
= hda_get_autocfg_input_label(codec
, cfg
, i
);
2655 if (prev_label
&& !strcmp(label
, prev_label
))
2662 idx
= get_connection_index(codec
, mixer
, pin
);
2664 err
= new_analog_input(spec
, pin
,
2672 for (c
= 0; c
< num_adcs
; c
++) {
2673 hda_nid_t cap
= spec
->capsrc_nids
?
2674 spec
->capsrc_nids
[c
] : spec
->adc_nids
[c
];
2675 idx
= get_connection_index(codec
, cap
, pin
);
2677 spec
->imux_pins
[imux
->num_items
] = pin
;
2678 snd_hda_add_imux_item(imux
, label
, idx
, NULL
);
2684 spec
->num_mux_defs
= 1;
2685 spec
->input_mux
= imux
;
2690 static void alc_set_pin_output(struct hda_codec
*codec
, hda_nid_t nid
,
2691 unsigned int pin_type
)
2693 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_PIN_WIDGET_CONTROL
,
2696 if (nid_has_mute(codec
, nid
, HDA_OUTPUT
))
2697 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
2701 static int get_pin_type(int line_out_type
)
2703 if (line_out_type
== AUTO_PIN_HP_OUT
)
2709 static void alc_auto_init_analog_input(struct hda_codec
*codec
)
2711 struct alc_spec
*spec
= codec
->spec
;
2712 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
2715 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
2716 hda_nid_t nid
= cfg
->inputs
[i
].pin
;
2717 if (alc_is_input_pin(codec
, nid
)) {
2718 alc_set_input_pin(codec
, nid
, cfg
->inputs
[i
].type
);
2719 if (get_wcaps(codec
, nid
) & AC_WCAP_OUT_AMP
)
2720 snd_hda_codec_write(codec
, nid
, 0,
2721 AC_VERB_SET_AMP_GAIN_MUTE
,
2726 /* mute all loopback inputs */
2727 if (spec
->mixer_nid
) {
2728 int nums
= snd_hda_get_conn_list(codec
, spec
->mixer_nid
, NULL
);
2729 for (i
= 0; i
< nums
; i
++)
2730 snd_hda_codec_write(codec
, spec
->mixer_nid
, 0,
2731 AC_VERB_SET_AMP_GAIN_MUTE
,
2736 /* convert from MIX nid to DAC */
2737 static hda_nid_t
alc_auto_mix_to_dac(struct hda_codec
*codec
, hda_nid_t nid
)
2742 if (get_wcaps_type(get_wcaps(codec
, nid
)) == AC_WID_AUD_OUT
)
2744 num
= snd_hda_get_connections(codec
, nid
, list
, ARRAY_SIZE(list
));
2745 for (i
= 0; i
< num
; i
++) {
2746 if (get_wcaps_type(get_wcaps(codec
, list
[i
])) == AC_WID_AUD_OUT
)
2752 /* go down to the selector widget before the mixer */
2753 static hda_nid_t
alc_go_down_to_selector(struct hda_codec
*codec
, hda_nid_t pin
)
2756 int num
= snd_hda_get_connections(codec
, pin
, srcs
,
2759 get_wcaps_type(get_wcaps(codec
, srcs
[0])) != AC_WID_AUD_SEL
)
2764 /* get MIX nid connected to the given pin targeted to DAC */
2765 static hda_nid_t
alc_auto_dac_to_mix(struct hda_codec
*codec
, hda_nid_t pin
,
2771 pin
= alc_go_down_to_selector(codec
, pin
);
2772 num
= snd_hda_get_connections(codec
, pin
, mix
, ARRAY_SIZE(mix
));
2773 for (i
= 0; i
< num
; i
++) {
2774 if (alc_auto_mix_to_dac(codec
, mix
[i
]) == dac
)
2780 /* select the connection from pin to DAC if needed */
2781 static int alc_auto_select_dac(struct hda_codec
*codec
, hda_nid_t pin
,
2787 pin
= alc_go_down_to_selector(codec
, pin
);
2788 num
= snd_hda_get_connections(codec
, pin
, mix
, ARRAY_SIZE(mix
));
2791 for (i
= 0; i
< num
; i
++) {
2792 if (alc_auto_mix_to_dac(codec
, mix
[i
]) == dac
) {
2793 snd_hda_codec_update_cache(codec
, pin
, 0,
2794 AC_VERB_SET_CONNECT_SEL
, i
);
2801 /* look for an empty DAC slot */
2802 static hda_nid_t
alc_auto_look_for_dac(struct hda_codec
*codec
, hda_nid_t pin
)
2804 struct alc_spec
*spec
= codec
->spec
;
2808 pin
= alc_go_down_to_selector(codec
, pin
);
2809 num
= snd_hda_get_connections(codec
, pin
, srcs
, ARRAY_SIZE(srcs
));
2810 for (i
= 0; i
< num
; i
++) {
2811 hda_nid_t nid
= alc_auto_mix_to_dac(codec
, srcs
[i
]);
2814 if (found_in_nid_list(nid
, spec
->multiout
.dac_nids
,
2815 spec
->multiout
.num_dacs
))
2817 if (spec
->multiout
.hp_out_nid
[0] == nid
)
2819 if (found_in_nid_list(nid
, spec
->multiout
.extra_out_nid
,
2820 ARRAY_SIZE(spec
->multiout
.extra_out_nid
)))
2827 static hda_nid_t
get_dac_if_single(struct hda_codec
*codec
, hda_nid_t pin
)
2829 hda_nid_t sel
= alc_go_down_to_selector(codec
, pin
);
2830 if (snd_hda_get_conn_list(codec
, sel
, NULL
) == 1)
2831 return alc_auto_look_for_dac(codec
, pin
);
2835 /* fill in the dac_nids table from the parsed pin configuration */
2836 static int alc_auto_fill_dac_nids(struct hda_codec
*codec
)
2838 struct alc_spec
*spec
= codec
->spec
;
2839 const struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
2840 bool redone
= false;
2844 /* set num_dacs once to full for alc_auto_look_for_dac() */
2845 spec
->multiout
.num_dacs
= cfg
->line_outs
;
2846 spec
->multiout
.hp_out_nid
[0] = 0;
2847 spec
->multiout
.extra_out_nid
[0] = 0;
2848 memset(spec
->private_dac_nids
, 0, sizeof(spec
->private_dac_nids
));
2849 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
2851 /* fill hard-wired DACs first */
2853 for (i
= 0; i
< cfg
->line_outs
; i
++)
2854 spec
->private_dac_nids
[i
] =
2855 get_dac_if_single(codec
, cfg
->line_out_pins
[i
]);
2857 spec
->multiout
.hp_out_nid
[0] =
2858 get_dac_if_single(codec
, cfg
->hp_pins
[0]);
2859 if (cfg
->speaker_outs
)
2860 spec
->multiout
.extra_out_nid
[0] =
2861 get_dac_if_single(codec
, cfg
->speaker_pins
[0]);
2864 for (i
= 0; i
< cfg
->line_outs
; i
++) {
2865 hda_nid_t pin
= cfg
->line_out_pins
[i
];
2866 if (spec
->private_dac_nids
[i
])
2868 spec
->private_dac_nids
[i
] = alc_auto_look_for_dac(codec
, pin
);
2869 if (!spec
->private_dac_nids
[i
] && !redone
) {
2870 /* if we can't find primary DACs, re-probe without
2871 * checking the hard-wired DACs
2878 /* re-count num_dacs and squash invalid entries */
2879 spec
->multiout
.num_dacs
= 0;
2880 for (i
= 0; i
< cfg
->line_outs
; i
++) {
2881 if (spec
->private_dac_nids
[i
])
2882 spec
->multiout
.num_dacs
++;
2884 memmove(spec
->private_dac_nids
+ i
,
2885 spec
->private_dac_nids
+ i
+ 1,
2886 sizeof(hda_nid_t
) * (cfg
->line_outs
- i
- 1));
2889 if (cfg
->hp_outs
&& !spec
->multiout
.hp_out_nid
[0])
2890 spec
->multiout
.hp_out_nid
[0] =
2891 alc_auto_look_for_dac(codec
, cfg
->hp_pins
[0]);
2892 if (cfg
->speaker_outs
&& !spec
->multiout
.extra_out_nid
[0])
2893 spec
->multiout
.extra_out_nid
[0] =
2894 alc_auto_look_for_dac(codec
, cfg
->speaker_pins
[0]);
2899 /* fill in the dac_nids table for surround speakers, etc */
2900 static int alc_auto_fill_extra_dacs(struct hda_codec
*codec
)
2902 struct alc_spec
*spec
= codec
->spec
;
2903 const struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
2906 if (cfg
->speaker_outs
< 2 || !spec
->multiout
.extra_out_nid
[0])
2909 for (i
= 1; i
< cfg
->speaker_outs
; i
++)
2910 spec
->multiout
.extra_out_nid
[i
] =
2911 get_dac_if_single(codec
, cfg
->speaker_pins
[i
]);
2912 for (i
= 1; i
< cfg
->speaker_outs
; i
++) {
2913 if (spec
->multiout
.extra_out_nid
[i
])
2915 spec
->multiout
.extra_out_nid
[i
] =
2916 alc_auto_look_for_dac(codec
, cfg
->speaker_pins
[0]);
2921 static int alc_auto_add_vol_ctl(struct hda_codec
*codec
,
2922 const char *pfx
, int cidx
,
2923 hda_nid_t nid
, unsigned int chs
)
2927 return __add_pb_vol_ctrl(codec
->spec
, ALC_CTL_WIDGET_VOL
, pfx
, cidx
,
2928 HDA_COMPOSE_AMP_VAL(nid
, chs
, 0, HDA_OUTPUT
));
2931 #define alc_auto_add_stereo_vol(codec, pfx, cidx, nid) \
2932 alc_auto_add_vol_ctl(codec, pfx, cidx, nid, 3)
2934 /* create a mute-switch for the given mixer widget;
2935 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
2937 static int alc_auto_add_sw_ctl(struct hda_codec
*codec
,
2938 const char *pfx
, int cidx
,
2939 hda_nid_t nid
, unsigned int chs
)
2946 wid_type
= get_wcaps_type(get_wcaps(codec
, nid
));
2947 if (wid_type
== AC_WID_PIN
|| wid_type
== AC_WID_AUD_OUT
) {
2948 type
= ALC_CTL_WIDGET_MUTE
;
2949 val
= HDA_COMPOSE_AMP_VAL(nid
, chs
, 0, HDA_OUTPUT
);
2950 } else if (snd_hda_get_conn_list(codec
, nid
, NULL
) == 1) {
2951 type
= ALC_CTL_WIDGET_MUTE
;
2952 val
= HDA_COMPOSE_AMP_VAL(nid
, chs
, 0, HDA_INPUT
);
2954 type
= ALC_CTL_BIND_MUTE
;
2955 val
= HDA_COMPOSE_AMP_VAL(nid
, chs
, 2, HDA_INPUT
);
2957 return __add_pb_sw_ctrl(codec
->spec
, type
, pfx
, cidx
, val
);
2960 #define alc_auto_add_stereo_sw(codec, pfx, cidx, nid) \
2961 alc_auto_add_sw_ctl(codec, pfx, cidx, nid, 3)
2963 static hda_nid_t
alc_look_for_out_mute_nid(struct hda_codec
*codec
,
2964 hda_nid_t pin
, hda_nid_t dac
)
2966 hda_nid_t mix
= alc_auto_dac_to_mix(codec
, pin
, dac
);
2967 if (nid_has_mute(codec
, pin
, HDA_OUTPUT
))
2969 else if (mix
&& nid_has_mute(codec
, mix
, HDA_INPUT
))
2971 else if (nid_has_mute(codec
, dac
, HDA_OUTPUT
))
2976 static hda_nid_t
alc_look_for_out_vol_nid(struct hda_codec
*codec
,
2977 hda_nid_t pin
, hda_nid_t dac
)
2979 hda_nid_t mix
= alc_auto_dac_to_mix(codec
, pin
, dac
);
2980 if (nid_has_volume(codec
, dac
, HDA_OUTPUT
))
2982 else if (nid_has_volume(codec
, mix
, HDA_OUTPUT
))
2984 else if (nid_has_volume(codec
, pin
, HDA_OUTPUT
))
2989 /* add playback controls from the parsed DAC table */
2990 static int alc_auto_create_multi_out_ctls(struct hda_codec
*codec
,
2991 const struct auto_pin_cfg
*cfg
)
2993 struct alc_spec
*spec
= codec
->spec
;
2994 int i
, err
, noutputs
;
2996 noutputs
= cfg
->line_outs
;
2997 if (spec
->multi_ios
> 0)
2998 noutputs
+= spec
->multi_ios
;
3000 for (i
= 0; i
< noutputs
; i
++) {
3006 dac
= spec
->multiout
.dac_nids
[i
];
3009 if (i
>= cfg
->line_outs
)
3010 pin
= spec
->multi_io
[i
- 1].pin
;
3012 pin
= cfg
->line_out_pins
[i
];
3014 sw
= alc_look_for_out_mute_nid(codec
, pin
, dac
);
3015 vol
= alc_look_for_out_vol_nid(codec
, pin
, dac
);
3016 name
= alc_get_line_out_pfx(spec
, i
, true, &index
);
3019 err
= alc_auto_add_vol_ctl(codec
, "Center", 0, vol
, 1);
3022 err
= alc_auto_add_vol_ctl(codec
, "LFE", 0, vol
, 2);
3025 err
= alc_auto_add_sw_ctl(codec
, "Center", 0, sw
, 1);
3028 err
= alc_auto_add_sw_ctl(codec
, "LFE", 0, sw
, 2);
3032 err
= alc_auto_add_stereo_vol(codec
, name
, index
, vol
);
3035 err
= alc_auto_add_stereo_sw(codec
, name
, index
, sw
);
3043 static int alc_auto_create_extra_out(struct hda_codec
*codec
, hda_nid_t pin
,
3044 hda_nid_t dac
, const char *pfx
)
3046 struct alc_spec
*spec
= codec
->spec
;
3051 /* the corresponding DAC is already occupied */
3052 if (!(get_wcaps(codec
, pin
) & AC_WCAP_OUT_AMP
))
3053 return 0; /* no way */
3054 /* create a switch only */
3055 return add_pb_sw_ctrl(spec
, ALC_CTL_WIDGET_MUTE
, pfx
,
3056 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
3059 sw
= alc_look_for_out_mute_nid(codec
, pin
, dac
);
3060 vol
= alc_look_for_out_vol_nid(codec
, pin
, dac
);
3061 err
= alc_auto_add_stereo_vol(codec
, pfx
, 0, vol
);
3064 err
= alc_auto_add_stereo_sw(codec
, pfx
, 0, sw
);
3070 static struct hda_bind_ctls
*new_bind_ctl(struct hda_codec
*codec
,
3072 struct hda_ctl_ops
*ops
)
3074 struct alc_spec
*spec
= codec
->spec
;
3075 struct hda_bind_ctls
**ctlp
, *ctl
;
3076 snd_array_init(&spec
->bind_ctls
, sizeof(ctl
), 8);
3077 ctlp
= snd_array_new(&spec
->bind_ctls
);
3080 ctl
= kzalloc(sizeof(*ctl
) + sizeof(long) * (nums
+ 1), GFP_KERNEL
);
3087 /* add playback controls for speaker and HP outputs */
3088 static int alc_auto_create_extra_outs(struct hda_codec
*codec
, int num_pins
,
3089 const hda_nid_t
*pins
,
3090 const hda_nid_t
*dacs
,
3093 struct alc_spec
*spec
= codec
->spec
;
3094 struct hda_bind_ctls
*ctl
;
3098 if (!num_pins
|| !pins
[0])
3102 return alc_auto_create_extra_out(codec
, *pins
, *dacs
, pfx
);
3104 if (dacs
[num_pins
- 1]) {
3105 /* OK, we have a multi-output system with individual volumes */
3106 for (i
= 0; i
< num_pins
; i
++) {
3107 snprintf(name
, sizeof(name
), "%s %s",
3108 pfx
, channel_name
[i
]);
3109 err
= alc_auto_create_extra_out(codec
, pins
[i
], dacs
[i
],
3117 /* Let's create a bind-controls */
3118 ctl
= new_bind_ctl(codec
, num_pins
, &snd_hda_bind_sw
);
3122 for (i
= 0; i
< num_pins
; i
++) {
3123 if (get_wcaps(codec
, pins
[i
]) & AC_WCAP_OUT_AMP
)
3125 HDA_COMPOSE_AMP_VAL(pins
[i
], 3, 0, HDA_OUTPUT
);
3128 snprintf(name
, sizeof(name
), "%s Playback Switch", pfx
);
3129 err
= add_control(spec
, ALC_CTL_BIND_SW
, name
, 0, (long)ctl
);
3134 ctl
= new_bind_ctl(codec
, num_pins
, &snd_hda_bind_vol
);
3138 for (i
= 0; i
< num_pins
; i
++) {
3140 if (!pins
[i
] || !dacs
[i
])
3142 vol
= alc_look_for_out_vol_nid(codec
, pins
[i
], dacs
[i
]);
3145 HDA_COMPOSE_AMP_VAL(vol
, 3, 0, HDA_OUTPUT
);
3148 snprintf(name
, sizeof(name
), "%s Playback Volume", pfx
);
3149 err
= add_control(spec
, ALC_CTL_BIND_VOL
, name
, 0, (long)ctl
);
3156 static int alc_auto_create_hp_out(struct hda_codec
*codec
)
3158 struct alc_spec
*spec
= codec
->spec
;
3159 return alc_auto_create_extra_outs(codec
, spec
->autocfg
.hp_outs
,
3160 spec
->autocfg
.hp_pins
,
3161 spec
->multiout
.hp_out_nid
,
3165 static int alc_auto_create_speaker_out(struct hda_codec
*codec
)
3167 struct alc_spec
*spec
= codec
->spec
;
3168 return alc_auto_create_extra_outs(codec
, spec
->autocfg
.speaker_outs
,
3169 spec
->autocfg
.speaker_pins
,
3170 spec
->multiout
.extra_out_nid
,
3174 static void alc_auto_set_output_and_unmute(struct hda_codec
*codec
,
3175 hda_nid_t pin
, int pin_type
,
3179 hda_nid_t nid
, mix
= 0;
3180 hda_nid_t srcs
[HDA_MAX_CONNECTIONS
];
3182 alc_set_pin_output(codec
, pin
, pin_type
);
3183 nid
= alc_go_down_to_selector(codec
, pin
);
3184 num
= snd_hda_get_connections(codec
, nid
, srcs
, ARRAY_SIZE(srcs
));
3185 for (i
= 0; i
< num
; i
++) {
3186 if (alc_auto_mix_to_dac(codec
, srcs
[i
]) != dac
)
3194 /* need the manual connection? */
3196 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_CONNECT_SEL
, i
);
3197 /* unmute mixer widget inputs */
3198 if (nid_has_mute(codec
, mix
, HDA_INPUT
)) {
3199 snd_hda_codec_write(codec
, mix
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
3201 snd_hda_codec_write(codec
, mix
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
3204 /* initialize volume */
3205 nid
= alc_look_for_out_vol_nid(codec
, pin
, dac
);
3207 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
3211 static void alc_auto_init_multi_out(struct hda_codec
*codec
)
3213 struct alc_spec
*spec
= codec
->spec
;
3214 int pin_type
= get_pin_type(spec
->autocfg
.line_out_type
);
3217 for (i
= 0; i
<= HDA_SIDE
; i
++) {
3218 hda_nid_t nid
= spec
->autocfg
.line_out_pins
[i
];
3220 alc_auto_set_output_and_unmute(codec
, nid
, pin_type
,
3221 spec
->multiout
.dac_nids
[i
]);
3225 static void alc_auto_init_extra_out(struct hda_codec
*codec
)
3227 struct alc_spec
*spec
= codec
->spec
;
3231 for (i
= 0; i
< spec
->autocfg
.speaker_outs
; i
++) {
3232 pin
= spec
->autocfg
.hp_pins
[i
];
3235 dac
= spec
->multiout
.hp_out_nid
[i
];
3237 if (i
> 0 && spec
->multiout
.hp_out_nid
[0])
3238 dac
= spec
->multiout
.hp_out_nid
[0];
3240 dac
= spec
->multiout
.dac_nids
[0];
3242 alc_auto_set_output_and_unmute(codec
, pin
, PIN_HP
, dac
);
3244 for (i
= 0; i
< spec
->autocfg
.speaker_outs
; i
++) {
3245 pin
= spec
->autocfg
.speaker_pins
[i
];
3248 dac
= spec
->multiout
.extra_out_nid
[i
];
3250 if (i
> 0 && spec
->multiout
.extra_out_nid
[0])
3251 dac
= spec
->multiout
.extra_out_nid
[0];
3253 dac
= spec
->multiout
.dac_nids
[0];
3255 alc_auto_set_output_and_unmute(codec
, pin
, PIN_OUT
, dac
);
3262 static int alc_auto_fill_multi_ios(struct hda_codec
*codec
,
3263 unsigned int location
)
3265 struct alc_spec
*spec
= codec
->spec
;
3266 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
3267 int type
, i
, num_pins
= 0;
3269 for (type
= AUTO_PIN_LINE_IN
; type
>= AUTO_PIN_MIC
; type
--) {
3270 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
3271 hda_nid_t nid
= cfg
->inputs
[i
].pin
;
3273 unsigned int defcfg
, caps
;
3274 if (cfg
->inputs
[i
].type
!= type
)
3276 defcfg
= snd_hda_codec_get_pincfg(codec
, nid
);
3277 if (get_defcfg_connect(defcfg
) != AC_JACK_PORT_COMPLEX
)
3279 if (location
&& get_defcfg_location(defcfg
) != location
)
3281 caps
= snd_hda_query_pin_caps(codec
, nid
);
3282 if (!(caps
& AC_PINCAP_OUT
))
3284 dac
= alc_auto_look_for_dac(codec
, nid
);
3287 spec
->multi_io
[num_pins
].pin
= nid
;
3288 spec
->multi_io
[num_pins
].dac
= dac
;
3290 spec
->private_dac_nids
[spec
->multiout
.num_dacs
++] = dac
;
3293 spec
->multiout
.num_dacs
= 1;
3299 static int alc_auto_ch_mode_info(struct snd_kcontrol
*kcontrol
,
3300 struct snd_ctl_elem_info
*uinfo
)
3302 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3303 struct alc_spec
*spec
= codec
->spec
;
3305 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
3307 uinfo
->value
.enumerated
.items
= spec
->multi_ios
+ 1;
3308 if (uinfo
->value
.enumerated
.item
> spec
->multi_ios
)
3309 uinfo
->value
.enumerated
.item
= spec
->multi_ios
;
3310 sprintf(uinfo
->value
.enumerated
.name
, "%dch",
3311 (uinfo
->value
.enumerated
.item
+ 1) * 2);
3315 static int alc_auto_ch_mode_get(struct snd_kcontrol
*kcontrol
,
3316 struct snd_ctl_elem_value
*ucontrol
)
3318 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3319 struct alc_spec
*spec
= codec
->spec
;
3320 ucontrol
->value
.enumerated
.item
[0] = (spec
->ext_channel_count
- 1) / 2;
3324 static int alc_set_multi_io(struct hda_codec
*codec
, int idx
, bool output
)
3326 struct alc_spec
*spec
= codec
->spec
;
3327 hda_nid_t nid
= spec
->multi_io
[idx
].pin
;
3329 if (!spec
->multi_io
[idx
].ctl_in
)
3330 spec
->multi_io
[idx
].ctl_in
=
3331 snd_hda_codec_read(codec
, nid
, 0,
3332 AC_VERB_GET_PIN_WIDGET_CONTROL
, 0);
3334 snd_hda_codec_update_cache(codec
, nid
, 0,
3335 AC_VERB_SET_PIN_WIDGET_CONTROL
,
3337 if (get_wcaps(codec
, nid
) & AC_WCAP_OUT_AMP
)
3338 snd_hda_codec_amp_stereo(codec
, nid
, HDA_OUTPUT
, 0,
3340 alc_auto_select_dac(codec
, nid
, spec
->multi_io
[idx
].dac
);
3342 if (get_wcaps(codec
, nid
) & AC_WCAP_OUT_AMP
)
3343 snd_hda_codec_amp_stereo(codec
, nid
, HDA_OUTPUT
, 0,
3344 HDA_AMP_MUTE
, HDA_AMP_MUTE
);
3345 snd_hda_codec_update_cache(codec
, nid
, 0,
3346 AC_VERB_SET_PIN_WIDGET_CONTROL
,
3347 spec
->multi_io
[idx
].ctl_in
);
3352 static int alc_auto_ch_mode_put(struct snd_kcontrol
*kcontrol
,
3353 struct snd_ctl_elem_value
*ucontrol
)
3355 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3356 struct alc_spec
*spec
= codec
->spec
;
3359 ch
= ucontrol
->value
.enumerated
.item
[0];
3360 if (ch
< 0 || ch
> spec
->multi_ios
)
3362 if (ch
== (spec
->ext_channel_count
- 1) / 2)
3364 spec
->ext_channel_count
= (ch
+ 1) * 2;
3365 for (i
= 0; i
< spec
->multi_ios
; i
++)
3366 alc_set_multi_io(codec
, i
, i
< ch
);
3367 spec
->multiout
.max_channels
= spec
->ext_channel_count
;
3368 if (spec
->need_dac_fix
&& !spec
->const_channel_count
)
3369 spec
->multiout
.num_dacs
= spec
->multiout
.max_channels
/ 2;
3373 static const struct snd_kcontrol_new alc_auto_channel_mode_enum
= {
3374 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
3375 .name
= "Channel Mode",
3376 .info
= alc_auto_ch_mode_info
,
3377 .get
= alc_auto_ch_mode_get
,
3378 .put
= alc_auto_ch_mode_put
,
3381 static int alc_auto_add_multi_channel_mode(struct hda_codec
*codec
)
3383 struct alc_spec
*spec
= codec
->spec
;
3384 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
3385 unsigned int location
, defcfg
;
3388 if (cfg
->line_outs
!= 1 ||
3389 cfg
->line_out_type
== AUTO_PIN_SPEAKER_OUT
)
3392 defcfg
= snd_hda_codec_get_pincfg(codec
, cfg
->line_out_pins
[0]);
3393 location
= get_defcfg_location(defcfg
);
3395 num_pins
= alc_auto_fill_multi_ios(codec
, location
);
3397 struct snd_kcontrol_new
*knew
;
3399 knew
= alc_kcontrol_new(spec
);
3402 *knew
= alc_auto_channel_mode_enum
;
3403 knew
->name
= kstrdup("Channel Mode", GFP_KERNEL
);
3407 spec
->multi_ios
= num_pins
;
3408 spec
->ext_channel_count
= 2;
3409 spec
->multiout
.num_dacs
= num_pins
+ 1;
3414 /* filter out invalid adc_nids (and capsrc_nids) that don't give all
3417 static void alc_remove_invalid_adc_nids(struct hda_codec
*codec
)
3419 struct alc_spec
*spec
= codec
->spec
;
3420 const struct hda_input_mux
*imux
;
3421 hda_nid_t adc_nids
[ARRAY_SIZE(spec
->private_adc_nids
)];
3422 hda_nid_t capsrc_nids
[ARRAY_SIZE(spec
->private_adc_nids
)];
3425 imux
= spec
->input_mux
;
3428 if (spec
->dyn_adc_switch
)
3432 for (n
= 0; n
< spec
->num_adc_nids
; n
++) {
3433 hda_nid_t cap
= spec
->private_capsrc_nids
[n
];
3434 int num_conns
= snd_hda_get_conn_list(codec
, cap
, NULL
);
3435 for (i
= 0; i
< imux
->num_items
; i
++) {
3436 hda_nid_t pin
= spec
->imux_pins
[i
];
3438 if (get_connection_index(codec
, cap
, pin
) < 0)
3440 } else if (num_conns
<= imux
->items
[i
].index
)
3443 if (i
>= imux
->num_items
) {
3444 adc_nids
[nums
] = spec
->private_adc_nids
[n
];
3445 capsrc_nids
[nums
++] = cap
;
3449 /* check whether ADC-switch is possible */
3450 if (!alc_check_dyn_adc_switch(codec
)) {
3451 printk(KERN_WARNING
"hda_codec: %s: no valid ADC found;"
3452 " using fallback 0x%x\n",
3453 codec
->chip_name
, spec
->private_adc_nids
[0]);
3454 spec
->num_adc_nids
= 1;
3458 } else if (nums
!= spec
->num_adc_nids
) {
3459 memcpy(spec
->private_adc_nids
, adc_nids
,
3460 nums
* sizeof(hda_nid_t
));
3461 memcpy(spec
->private_capsrc_nids
, capsrc_nids
,
3462 nums
* sizeof(hda_nid_t
));
3463 spec
->num_adc_nids
= nums
;
3467 alc_auto_mic_check_imux(codec
); /* check auto-mic setups */
3468 else if (spec
->input_mux
->num_items
== 1)
3469 spec
->num_adc_nids
= 1; /* reduce to a single ADC */
3473 * initialize ADC paths
3475 static void alc_auto_init_adc(struct hda_codec
*codec
, int adc_idx
)
3477 struct alc_spec
*spec
= codec
->spec
;
3480 nid
= spec
->adc_nids
[adc_idx
];
3482 if (nid_has_mute(codec
, nid
, HDA_INPUT
)) {
3483 snd_hda_codec_write(codec
, nid
, 0,
3484 AC_VERB_SET_AMP_GAIN_MUTE
,
3488 if (!spec
->capsrc_nids
)
3490 nid
= spec
->capsrc_nids
[adc_idx
];
3491 if (nid_has_mute(codec
, nid
, HDA_OUTPUT
))
3492 snd_hda_codec_write(codec
, nid
, 0,
3493 AC_VERB_SET_AMP_GAIN_MUTE
,
3497 static void alc_auto_init_input_src(struct hda_codec
*codec
)
3499 struct alc_spec
*spec
= codec
->spec
;
3502 for (c
= 0; c
< spec
->num_adc_nids
; c
++)
3503 alc_auto_init_adc(codec
, c
);
3504 if (spec
->dyn_adc_switch
)
3507 nums
= spec
->num_adc_nids
;
3508 for (c
= 0; c
< nums
; c
++)
3509 alc_mux_select(codec
, 0, spec
->cur_mux
[c
], true);
3512 /* add mic boosts if needed */
3513 static int alc_auto_add_mic_boost(struct hda_codec
*codec
)
3515 struct alc_spec
*spec
= codec
->spec
;
3516 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
3520 const char *prev_label
= NULL
;
3522 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
3523 if (cfg
->inputs
[i
].type
> AUTO_PIN_MIC
)
3525 nid
= cfg
->inputs
[i
].pin
;
3526 if (get_wcaps(codec
, nid
) & AC_WCAP_IN_AMP
) {
3528 char boost_label
[32];
3530 label
= hda_get_autocfg_input_label(codec
, cfg
, i
);
3531 if (prev_label
&& !strcmp(label
, prev_label
))
3537 snprintf(boost_label
, sizeof(boost_label
),
3538 "%s Boost Volume", label
);
3539 err
= add_control(spec
, ALC_CTL_WIDGET_VOL
,
3540 boost_label
, type_idx
,
3541 HDA_COMPOSE_AMP_VAL(nid
, 3, 0, HDA_INPUT
));
3549 /* select or unmute the given capsrc route */
3550 static void select_or_unmute_capsrc(struct hda_codec
*codec
, hda_nid_t cap
,
3553 if (get_wcaps_type(get_wcaps(codec
, cap
)) == AC_WID_AUD_MIX
) {
3554 snd_hda_codec_amp_stereo(codec
, cap
, HDA_INPUT
, idx
,
3556 } else if (snd_hda_get_conn_list(codec
, cap
, NULL
) > 1) {
3557 snd_hda_codec_write_cache(codec
, cap
, 0,
3558 AC_VERB_SET_CONNECT_SEL
, idx
);
3562 /* set the default connection to that pin */
3563 static int init_capsrc_for_pin(struct hda_codec
*codec
, hda_nid_t pin
)
3565 struct alc_spec
*spec
= codec
->spec
;
3570 for (i
= 0; i
< spec
->num_adc_nids
; i
++) {
3571 hda_nid_t cap
= spec
->capsrc_nids
?
3572 spec
->capsrc_nids
[i
] : spec
->adc_nids
[i
];
3575 idx
= get_connection_index(codec
, cap
, pin
);
3578 select_or_unmute_capsrc(codec
, cap
, idx
);
3579 return i
; /* return the found index */
3581 return -1; /* not found */
3584 /* initialize some special cases for input sources */
3585 static void alc_init_special_input_src(struct hda_codec
*codec
)
3587 struct alc_spec
*spec
= codec
->spec
;
3590 for (i
= 0; i
< spec
->autocfg
.num_inputs
; i
++)
3591 init_capsrc_for_pin(codec
, spec
->autocfg
.inputs
[i
].pin
);
3594 /* assign appropriate capture mixers */
3595 static void set_capture_mixer(struct hda_codec
*codec
)
3597 struct alc_spec
*spec
= codec
->spec
;
3598 static const struct snd_kcontrol_new
*caps
[2][3] = {
3599 { alc_capture_mixer_nosrc1
,
3600 alc_capture_mixer_nosrc2
,
3601 alc_capture_mixer_nosrc3
},
3602 { alc_capture_mixer1
,
3604 alc_capture_mixer3
},
3607 /* check whether either of ADC or MUX has a volume control */
3608 if (!nid_has_volume(codec
, spec
->adc_nids
[0], HDA_INPUT
)) {
3609 if (!spec
->capsrc_nids
)
3610 return; /* no volume */
3611 if (!nid_has_volume(codec
, spec
->capsrc_nids
[0], HDA_OUTPUT
))
3612 return; /* no volume in capsrc, too */
3613 spec
->vol_in_capsrc
= 1;
3616 if (spec
->num_adc_nids
> 0) {
3620 if (spec
->input_mux
&& spec
->input_mux
->num_items
> 1)
3622 if (spec
->auto_mic
) {
3625 } else if (spec
->dyn_adc_switch
)
3628 if (spec
->num_adc_nids
> 3)
3629 spec
->num_adc_nids
= 3;
3630 else if (!spec
->num_adc_nids
)
3632 num_adcs
= spec
->num_adc_nids
;
3634 spec
->cap_mixer
= caps
[mux
][num_adcs
- 1];
3639 * standard auto-parser initializations
3641 static void alc_auto_init_std(struct hda_codec
*codec
)
3643 struct alc_spec
*spec
= codec
->spec
;
3644 alc_auto_init_multi_out(codec
);
3645 alc_auto_init_extra_out(codec
);
3646 alc_auto_init_analog_input(codec
);
3647 alc_auto_init_input_src(codec
);
3648 alc_auto_init_digital(codec
);
3649 if (spec
->unsol_event
)
3650 alc_inithook(codec
);
3654 * Digital-beep handlers
3656 #ifdef CONFIG_SND_HDA_INPUT_BEEP
3657 #define set_beep_amp(spec, nid, idx, dir) \
3658 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
3660 static const struct snd_pci_quirk beep_white_list
[] = {
3661 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
3662 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
3663 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
3664 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
3665 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
3669 static inline int has_cdefine_beep(struct hda_codec
*codec
)
3671 struct alc_spec
*spec
= codec
->spec
;
3672 const struct snd_pci_quirk
*q
;
3673 q
= snd_pci_quirk_lookup(codec
->bus
->pci
, beep_white_list
);
3676 return spec
->cdefine
.enable_pcbeep
;
3679 #define set_beep_amp(spec, nid, idx, dir) /* NOP */
3680 #define has_cdefine_beep(codec) 0
3683 /* parse the BIOS configuration and set up the alc_spec */
3684 /* return 1 if successful, 0 if the proper config is not found,
3685 * or a negative error code
3687 static int alc_parse_auto_config(struct hda_codec
*codec
,
3688 const hda_nid_t
*ignore_nids
,
3689 const hda_nid_t
*ssid_nids
)
3691 struct alc_spec
*spec
= codec
->spec
;
3692 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
3695 err
= snd_hda_parse_pin_defcfg(codec
, cfg
, ignore_nids
,
3699 if (!cfg
->line_outs
) {
3700 if (cfg
->dig_outs
|| cfg
->dig_in_pin
) {
3701 spec
->multiout
.max_channels
= 2;
3702 spec
->no_analog
= 1;
3705 return 0; /* can't find valid BIOS pin config */
3708 if (cfg
->line_out_type
== AUTO_PIN_SPEAKER_OUT
&& cfg
->hp_outs
> 0) {
3709 /* use HP as primary out */
3710 cfg
->speaker_outs
= cfg
->line_outs
;
3711 memcpy(cfg
->speaker_pins
, cfg
->line_out_pins
,
3712 sizeof(cfg
->speaker_pins
));
3713 cfg
->line_outs
= cfg
->hp_outs
;
3714 memcpy(cfg
->line_out_pins
, cfg
->hp_pins
, sizeof(cfg
->hp_pins
));
3716 memset(cfg
->hp_pins
, 0, sizeof(cfg
->hp_pins
));
3717 cfg
->line_out_type
= AUTO_PIN_HP_OUT
;
3720 err
= alc_auto_fill_dac_nids(codec
);
3723 err
= alc_auto_add_multi_channel_mode(codec
);
3726 err
= alc_auto_fill_extra_dacs(codec
);
3729 err
= alc_auto_create_multi_out_ctls(codec
, cfg
);
3732 err
= alc_auto_create_hp_out(codec
);
3735 err
= alc_auto_create_speaker_out(codec
);
3738 err
= alc_auto_create_input_ctls(codec
);
3742 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
3745 alc_auto_parse_digital(codec
);
3747 if (!spec
->no_analog
)
3748 alc_remove_invalid_adc_nids(codec
);
3751 alc_ssid_check(codec
, ssid_nids
);
3753 if (!spec
->no_analog
) {
3754 alc_auto_check_switches(codec
);
3755 err
= alc_auto_add_mic_boost(codec
);
3760 if (spec
->kctls
.list
)
3761 add_mixer(spec
, spec
->kctls
.list
);
3766 static int alc880_parse_auto_config(struct hda_codec
*codec
)
3768 static const hda_nid_t alc880_ignore
[] = { 0x1d, 0 };
3769 static const hda_nid_t alc880_ssids
[] = { 0x15, 0x1b, 0x14, 0 };
3770 return alc_parse_auto_config(codec
, alc880_ignore
, alc880_ssids
);
3773 #ifdef CONFIG_SND_HDA_POWER_SAVE
3774 static const struct hda_amp_list alc880_loopbacks
[] = {
3775 { 0x0b, HDA_INPUT
, 0 },
3776 { 0x0b, HDA_INPUT
, 1 },
3777 { 0x0b, HDA_INPUT
, 2 },
3778 { 0x0b, HDA_INPUT
, 3 },
3779 { 0x0b, HDA_INPUT
, 4 },
3787 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3788 #define alc_board_config \
3789 snd_hda_check_board_config
3790 #define alc_board_codec_sid_config \
3791 snd_hda_check_board_codec_sid_config
3792 #include "alc_quirks.c"
3794 #define alc_board_config(codec, nums, models, tbl) -1
3795 #define alc_board_codec_sid_config(codec, nums, models, tbl) -1
3796 #define setup_preset(codec, x) /* NOP */
3800 * OK, here we have finally the patch for ALC880
3802 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3803 #include "alc880_quirks.c"
3806 static int patch_alc880(struct hda_codec
*codec
)
3808 struct alc_spec
*spec
;
3812 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
3818 spec
->mixer_nid
= 0x0b;
3819 spec
->need_dac_fix
= 1;
3821 board_config
= alc_board_config(codec
, ALC880_MODEL_LAST
,
3822 alc880_models
, alc880_cfg_tbl
);
3823 if (board_config
< 0) {
3824 printk(KERN_INFO
"hda_codec: %s: BIOS auto-probing.\n",
3826 board_config
= ALC_MODEL_AUTO
;
3829 if (board_config
== ALC_MODEL_AUTO
) {
3830 /* automatic parse from the BIOS config */
3831 err
= alc880_parse_auto_config(codec
);
3836 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3839 "hda_codec: Cannot set up configuration "
3840 "from BIOS. Using 3-stack mode...\n");
3841 board_config
= ALC880_3ST
;
3846 if (board_config
!= ALC_MODEL_AUTO
)
3847 setup_preset(codec
, &alc880_presets
[board_config
]);
3849 if (!spec
->no_analog
&& !spec
->adc_nids
) {
3850 alc_auto_fill_adc_caps(codec
);
3851 alc_rebuild_imux_for_auto_mic(codec
);
3852 alc_remove_invalid_adc_nids(codec
);
3855 if (!spec
->no_analog
&& !spec
->cap_mixer
)
3856 set_capture_mixer(codec
);
3858 if (!spec
->no_analog
) {
3859 err
= snd_hda_attach_beep_device(codec
, 0x1);
3864 set_beep_amp(spec
, 0x0b, 0x05, HDA_INPUT
);
3867 spec
->vmaster_nid
= 0x0c;
3869 codec
->patch_ops
= alc_patch_ops
;
3870 if (board_config
== ALC_MODEL_AUTO
)
3871 spec
->init_hook
= alc_auto_init_std
;
3872 #ifdef CONFIG_SND_HDA_POWER_SAVE
3873 if (!spec
->loopback
.amplist
)
3874 spec
->loopback
.amplist
= alc880_loopbacks
;
3884 static int alc260_parse_auto_config(struct hda_codec
*codec
)
3886 static const hda_nid_t alc260_ignore
[] = { 0x17, 0 };
3887 static const hda_nid_t alc260_ssids
[] = { 0x10, 0x15, 0x0f, 0 };
3888 return alc_parse_auto_config(codec
, alc260_ignore
, alc260_ssids
);
3891 #ifdef CONFIG_SND_HDA_POWER_SAVE
3892 static const struct hda_amp_list alc260_loopbacks
[] = {
3893 { 0x07, HDA_INPUT
, 0 },
3894 { 0x07, HDA_INPUT
, 1 },
3895 { 0x07, HDA_INPUT
, 2 },
3896 { 0x07, HDA_INPUT
, 3 },
3897 { 0x07, HDA_INPUT
, 4 },
3909 static const struct alc_fixup alc260_fixups
[] = {
3910 [PINFIX_HP_DC5750
] = {
3911 .type
= ALC_FIXUP_PINS
,
3912 .v
.pins
= (const struct alc_pincfg
[]) {
3913 { 0x11, 0x90130110 }, /* speaker */
3919 static const struct snd_pci_quirk alc260_fixup_tbl
[] = {
3920 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", PINFIX_HP_DC5750
),
3926 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3927 #include "alc260_quirks.c"
3930 static int patch_alc260(struct hda_codec
*codec
)
3932 struct alc_spec
*spec
;
3933 int err
, board_config
;
3935 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
3941 spec
->mixer_nid
= 0x07;
3943 board_config
= alc_board_config(codec
, ALC260_MODEL_LAST
,
3944 alc260_models
, alc260_cfg_tbl
);
3945 if (board_config
< 0) {
3946 snd_printd(KERN_INFO
"hda_codec: %s: BIOS auto-probing.\n",
3948 board_config
= ALC_MODEL_AUTO
;
3951 if (board_config
== ALC_MODEL_AUTO
) {
3952 alc_pick_fixup(codec
, NULL
, alc260_fixup_tbl
, alc260_fixups
);
3953 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
3956 if (board_config
== ALC_MODEL_AUTO
) {
3957 /* automatic parse from the BIOS config */
3958 err
= alc260_parse_auto_config(codec
);
3963 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3966 "hda_codec: Cannot set up configuration "
3967 "from BIOS. Using base mode...\n");
3968 board_config
= ALC260_BASIC
;
3973 if (board_config
!= ALC_MODEL_AUTO
)
3974 setup_preset(codec
, &alc260_presets
[board_config
]);
3976 if (!spec
->no_analog
&& !spec
->adc_nids
) {
3977 alc_auto_fill_adc_caps(codec
);
3978 alc_rebuild_imux_for_auto_mic(codec
);
3979 alc_remove_invalid_adc_nids(codec
);
3982 if (!spec
->no_analog
&& !spec
->cap_mixer
)
3983 set_capture_mixer(codec
);
3985 if (!spec
->no_analog
) {
3986 err
= snd_hda_attach_beep_device(codec
, 0x1);
3991 set_beep_amp(spec
, 0x07, 0x05, HDA_INPUT
);
3994 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
3996 spec
->vmaster_nid
= 0x08;
3998 codec
->patch_ops
= alc_patch_ops
;
3999 if (board_config
== ALC_MODEL_AUTO
)
4000 spec
->init_hook
= alc_auto_init_std
;
4001 spec
->shutup
= alc_eapd_shutup
;
4002 #ifdef CONFIG_SND_HDA_POWER_SAVE
4003 if (!spec
->loopback
.amplist
)
4004 spec
->loopback
.amplist
= alc260_loopbacks
;
4012 * ALC882/883/885/888/889 support
4014 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
4015 * configuration. Each pin widget can choose any input DACs and a mixer.
4016 * Each ADC is connected from a mixer of all inputs. This makes possible
4017 * 6-channel independent captures.
4019 * In addition, an independent DAC for the multi-playback (not used in this
4022 #ifdef CONFIG_SND_HDA_POWER_SAVE
4023 #define alc882_loopbacks alc880_loopbacks
4030 PINFIX_ABIT_AW9D_MAX
,
4033 PINFIX_ACER_ASPIRE_7736
,
4036 static const struct alc_fixup alc882_fixups
[] = {
4037 [PINFIX_ABIT_AW9D_MAX
] = {
4038 .type
= ALC_FIXUP_PINS
,
4039 .v
.pins
= (const struct alc_pincfg
[]) {
4040 { 0x15, 0x01080104 }, /* side */
4041 { 0x16, 0x01011012 }, /* rear */
4042 { 0x17, 0x01016011 }, /* clfe */
4046 [PINFIX_LENOVO_Y530
] = {
4047 .type
= ALC_FIXUP_PINS
,
4048 .v
.pins
= (const struct alc_pincfg
[]) {
4049 { 0x15, 0x99130112 }, /* rear int speakers */
4050 { 0x16, 0x99130111 }, /* subwoofer */
4054 [PINFIX_PB_M5210
] = {
4055 .type
= ALC_FIXUP_VERBS
,
4056 .v
.verbs
= (const struct hda_verb
[]) {
4057 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_VREF50
},
4061 [PINFIX_ACER_ASPIRE_7736
] = {
4062 .type
= ALC_FIXUP_SKU
,
4063 .v
.sku
= ALC_FIXUP_SKU_IGNORE
,
4067 static const struct snd_pci_quirk alc882_fixup_tbl
[] = {
4068 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", PINFIX_PB_M5210
),
4069 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", PINFIX_LENOVO_Y530
),
4070 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX
),
4071 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", PINFIX_ACER_ASPIRE_7736
),
4076 * BIOS auto configuration
4078 /* almost identical with ALC880 parser... */
4079 static int alc882_parse_auto_config(struct hda_codec
*codec
)
4081 static const hda_nid_t alc882_ignore
[] = { 0x1d, 0 };
4082 static const hda_nid_t alc882_ssids
[] = { 0x15, 0x1b, 0x14, 0 };
4083 return alc_parse_auto_config(codec
, alc882_ignore
, alc882_ssids
);
4088 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4089 #include "alc882_quirks.c"
4092 static int patch_alc882(struct hda_codec
*codec
)
4094 struct alc_spec
*spec
;
4095 int err
, board_config
;
4097 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
4103 spec
->mixer_nid
= 0x0b;
4105 switch (codec
->vendor_id
) {
4110 /* ALC883 and variants */
4111 alc_fix_pll_init(codec
, 0x20, 0x0a, 10);
4115 board_config
= alc_board_config(codec
, ALC882_MODEL_LAST
,
4116 alc882_models
, alc882_cfg_tbl
);
4118 if (board_config
< 0)
4119 board_config
= alc_board_codec_sid_config(codec
,
4120 ALC882_MODEL_LAST
, alc882_models
, alc882_ssid_cfg_tbl
);
4122 if (board_config
< 0) {
4123 printk(KERN_INFO
"hda_codec: %s: BIOS auto-probing.\n",
4125 board_config
= ALC_MODEL_AUTO
;
4128 if (board_config
== ALC_MODEL_AUTO
) {
4129 alc_pick_fixup(codec
, NULL
, alc882_fixup_tbl
, alc882_fixups
);
4130 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
4133 alc_auto_parse_customize_define(codec
);
4135 if (board_config
== ALC_MODEL_AUTO
) {
4136 /* automatic parse from the BIOS config */
4137 err
= alc882_parse_auto_config(codec
);
4142 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4145 "hda_codec: Cannot set up configuration "
4146 "from BIOS. Using base mode...\n");
4147 board_config
= ALC882_3ST_DIG
;
4152 if (board_config
!= ALC_MODEL_AUTO
)
4153 setup_preset(codec
, &alc882_presets
[board_config
]);
4155 if (!spec
->no_analog
&& !spec
->adc_nids
) {
4156 alc_auto_fill_adc_caps(codec
);
4157 alc_rebuild_imux_for_auto_mic(codec
);
4158 alc_remove_invalid_adc_nids(codec
);
4161 if (!spec
->no_analog
&& !spec
->cap_mixer
)
4162 set_capture_mixer(codec
);
4164 if (!spec
->no_analog
&& has_cdefine_beep(codec
)) {
4165 err
= snd_hda_attach_beep_device(codec
, 0x1);
4170 set_beep_amp(spec
, 0x0b, 0x05, HDA_INPUT
);
4173 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
4175 spec
->vmaster_nid
= 0x0c;
4177 codec
->patch_ops
= alc_patch_ops
;
4178 if (board_config
== ALC_MODEL_AUTO
)
4179 spec
->init_hook
= alc_auto_init_std
;
4181 alc_init_jacks(codec
);
4182 #ifdef CONFIG_SND_HDA_POWER_SAVE
4183 if (!spec
->loopback
.amplist
)
4184 spec
->loopback
.amplist
= alc882_loopbacks
;
4194 static int alc262_parse_auto_config(struct hda_codec
*codec
)
4196 static const hda_nid_t alc262_ignore
[] = { 0x1d, 0 };
4197 static const hda_nid_t alc262_ssids
[] = { 0x15, 0x1b, 0x14, 0 };
4198 return alc_parse_auto_config(codec
, alc262_ignore
, alc262_ssids
);
4209 static const struct alc_fixup alc262_fixups
[] = {
4210 [PINFIX_FSC_H270
] = {
4211 .type
= ALC_FIXUP_PINS
,
4212 .v
.pins
= (const struct alc_pincfg
[]) {
4213 { 0x14, 0x99130110 }, /* speaker */
4214 { 0x15, 0x0221142f }, /* front HP */
4215 { 0x1b, 0x0121141f }, /* rear HP */
4219 [PINFIX_HP_Z200
] = {
4220 .type
= ALC_FIXUP_PINS
,
4221 .v
.pins
= (const struct alc_pincfg
[]) {
4222 { 0x16, 0x99130120 }, /* internal speaker */
4228 static const struct snd_pci_quirk alc262_fixup_tbl
[] = {
4229 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", PINFIX_HP_Z200
),
4230 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", PINFIX_FSC_H270
),
4235 #ifdef CONFIG_SND_HDA_POWER_SAVE
4236 #define alc262_loopbacks alc880_loopbacks
4241 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4242 #include "alc262_quirks.c"
4245 static int patch_alc262(struct hda_codec
*codec
)
4247 struct alc_spec
*spec
;
4251 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
4257 spec
->mixer_nid
= 0x0b;
4260 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
4265 snd_hda_codec_write(codec
, 0x1a, 0, AC_VERB_SET_COEF_INDEX
, 7);
4266 tmp
= snd_hda_codec_read(codec
, 0x20, 0, AC_VERB_GET_PROC_COEF
, 0);
4267 snd_hda_codec_write(codec
, 0x1a, 0, AC_VERB_SET_COEF_INDEX
, 7);
4268 snd_hda_codec_write(codec
, 0x1a, 0, AC_VERB_SET_PROC_COEF
, tmp
| 0x80);
4271 alc_auto_parse_customize_define(codec
);
4273 alc_fix_pll_init(codec
, 0x20, 0x0a, 10);
4275 board_config
= alc_board_config(codec
, ALC262_MODEL_LAST
,
4276 alc262_models
, alc262_cfg_tbl
);
4278 if (board_config
< 0) {
4279 printk(KERN_INFO
"hda_codec: %s: BIOS auto-probing.\n",
4281 board_config
= ALC_MODEL_AUTO
;
4284 if (board_config
== ALC_MODEL_AUTO
) {
4285 alc_pick_fixup(codec
, NULL
, alc262_fixup_tbl
, alc262_fixups
);
4286 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
4289 if (board_config
== ALC_MODEL_AUTO
) {
4290 /* automatic parse from the BIOS config */
4291 err
= alc262_parse_auto_config(codec
);
4296 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4299 "hda_codec: Cannot set up configuration "
4300 "from BIOS. Using base mode...\n");
4301 board_config
= ALC262_BASIC
;
4306 if (board_config
!= ALC_MODEL_AUTO
)
4307 setup_preset(codec
, &alc262_presets
[board_config
]);
4309 if (!spec
->no_analog
&& !spec
->adc_nids
) {
4310 alc_auto_fill_adc_caps(codec
);
4311 alc_rebuild_imux_for_auto_mic(codec
);
4312 alc_remove_invalid_adc_nids(codec
);
4315 if (!spec
->no_analog
&& !spec
->cap_mixer
)
4316 set_capture_mixer(codec
);
4318 if (!spec
->no_analog
&& has_cdefine_beep(codec
)) {
4319 err
= snd_hda_attach_beep_device(codec
, 0x1);
4324 set_beep_amp(spec
, 0x0b, 0x05, HDA_INPUT
);
4327 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
4329 spec
->vmaster_nid
= 0x0c;
4331 codec
->patch_ops
= alc_patch_ops
;
4332 if (board_config
== ALC_MODEL_AUTO
)
4333 spec
->init_hook
= alc_auto_init_std
;
4334 spec
->shutup
= alc_eapd_shutup
;
4336 alc_init_jacks(codec
);
4337 #ifdef CONFIG_SND_HDA_POWER_SAVE
4338 if (!spec
->loopback
.amplist
)
4339 spec
->loopback
.amplist
= alc262_loopbacks
;
4348 /* bind Beep switches of both NID 0x0f and 0x10 */
4349 static const struct hda_bind_ctls alc268_bind_beep_sw
= {
4350 .ops
= &snd_hda_bind_sw
,
4352 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT
),
4353 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT
),
4358 static const struct snd_kcontrol_new alc268_beep_mixer
[] = {
4359 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT
),
4360 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw
),
4364 /* set PCBEEP vol = 0, mute connections */
4365 static const struct hda_verb alc268_beep_init_verbs
[] = {
4366 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
4367 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(1)},
4368 {0x10, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(1)},
4373 * BIOS auto configuration
4375 static int alc268_parse_auto_config(struct hda_codec
*codec
)
4377 static const hda_nid_t alc268_ssids
[] = { 0x15, 0x1b, 0x14, 0 };
4378 struct alc_spec
*spec
= codec
->spec
;
4379 int err
= alc_parse_auto_config(codec
, NULL
, alc268_ssids
);
4381 if (!spec
->no_analog
&& spec
->autocfg
.speaker_pins
[0] != 0x1d) {
4382 add_mixer(spec
, alc268_beep_mixer
);
4383 add_verb(spec
, alc268_beep_init_verbs
);
4391 static int patch_alc268(struct hda_codec
*codec
)
4393 struct alc_spec
*spec
;
4394 int i
, has_beep
, err
;
4396 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
4402 /* ALC268 has no aa-loopback mixer */
4404 /* automatic parse from the BIOS config */
4405 err
= alc268_parse_auto_config(codec
);
4412 for (i
= 0; i
< spec
->num_mixers
; i
++) {
4413 if (spec
->mixers
[i
] == alc268_beep_mixer
) {
4420 err
= snd_hda_attach_beep_device(codec
, 0x1);
4425 if (!query_amp_caps(codec
, 0x1d, HDA_INPUT
))
4426 /* override the amp caps for beep generator */
4427 snd_hda_override_amp_caps(codec
, 0x1d, HDA_INPUT
,
4428 (0x0c << AC_AMPCAP_OFFSET_SHIFT
) |
4429 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT
) |
4430 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT
) |
4431 (0 << AC_AMPCAP_MUTE_SHIFT
));
4434 if (!spec
->no_analog
&& !spec
->adc_nids
) {
4435 alc_auto_fill_adc_caps(codec
);
4436 alc_rebuild_imux_for_auto_mic(codec
);
4437 alc_remove_invalid_adc_nids(codec
);
4440 if (!spec
->no_analog
&& !spec
->cap_mixer
)
4441 set_capture_mixer(codec
);
4443 spec
->vmaster_nid
= 0x02;
4445 codec
->patch_ops
= alc_patch_ops
;
4446 spec
->init_hook
= alc_auto_init_std
;
4447 spec
->shutup
= alc_eapd_shutup
;
4449 alc_init_jacks(codec
);
4457 #ifdef CONFIG_SND_HDA_POWER_SAVE
4458 #define alc269_loopbacks alc880_loopbacks
4461 static const struct hda_pcm_stream alc269_44k_pcm_analog_playback
= {
4465 .rates
= SNDRV_PCM_RATE_44100
, /* fixed rate */
4466 /* NID is set in alc_build_pcms */
4468 .open
= alc_playback_pcm_open
,
4469 .prepare
= alc_playback_pcm_prepare
,
4470 .cleanup
= alc_playback_pcm_cleanup
4474 static const struct hda_pcm_stream alc269_44k_pcm_analog_capture
= {
4478 .rates
= SNDRV_PCM_RATE_44100
, /* fixed rate */
4479 /* NID is set in alc_build_pcms */
4482 #ifdef CONFIG_SND_HDA_POWER_SAVE
4483 static int alc269_mic2_for_mute_led(struct hda_codec
*codec
)
4485 switch (codec
->subsystem_id
) {
4492 static int alc269_mic2_mute_check_ps(struct hda_codec
*codec
, hda_nid_t nid
)
4494 /* update mute-LED according to the speaker mute state */
4495 if (nid
== 0x01 || nid
== 0x14) {
4497 if (snd_hda_codec_amp_read(codec
, 0x14, 0, HDA_OUTPUT
, 0) &
4502 /* mic2 vref pin is used for mute LED control */
4503 snd_hda_codec_update_cache(codec
, 0x19, 0,
4504 AC_VERB_SET_PIN_WIDGET_CONTROL
,
4507 return alc_check_power_status(codec
, nid
);
4509 #endif /* CONFIG_SND_HDA_POWER_SAVE */
4511 /* different alc269-variants */
4513 ALC269_TYPE_ALC269VA
,
4514 ALC269_TYPE_ALC269VB
,
4515 ALC269_TYPE_ALC269VC
,
4519 * BIOS auto configuration
4521 static int alc269_parse_auto_config(struct hda_codec
*codec
)
4523 static const hda_nid_t alc269_ignore
[] = { 0x1d, 0 };
4524 static const hda_nid_t alc269_ssids
[] = { 0, 0x1b, 0x14, 0x21 };
4525 static const hda_nid_t alc269va_ssids
[] = { 0x15, 0x1b, 0x14, 0 };
4526 struct alc_spec
*spec
= codec
->spec
;
4527 const hda_nid_t
*ssids
= spec
->codec_variant
== ALC269_TYPE_ALC269VA
?
4528 alc269va_ssids
: alc269_ssids
;
4530 return alc_parse_auto_config(codec
, alc269_ignore
, ssids
);
4533 static void alc269_toggle_power_output(struct hda_codec
*codec
, int power_up
)
4535 int val
= alc_read_coef_idx(codec
, 0x04);
4540 alc_write_coef_idx(codec
, 0x04, val
);
4543 static void alc269_shutup(struct hda_codec
*codec
)
4545 if ((alc_read_coef_idx(codec
, 0) & 0x00ff) == 0x017)
4546 alc269_toggle_power_output(codec
, 0);
4547 if ((alc_read_coef_idx(codec
, 0) & 0x00ff) == 0x018) {
4548 alc269_toggle_power_output(codec
, 0);
4554 static int alc269_resume(struct hda_codec
*codec
)
4556 if ((alc_read_coef_idx(codec
, 0) & 0x00ff) == 0x018) {
4557 alc269_toggle_power_output(codec
, 0);
4561 codec
->patch_ops
.init(codec
);
4563 if ((alc_read_coef_idx(codec
, 0) & 0x00ff) == 0x017) {
4564 alc269_toggle_power_output(codec
, 1);
4568 if ((alc_read_coef_idx(codec
, 0) & 0x00ff) == 0x018)
4569 alc269_toggle_power_output(codec
, 1);
4571 snd_hda_codec_resume_amp(codec
);
4572 snd_hda_codec_resume_cache(codec
);
4573 hda_call_check_power_status(codec
, 0x01);
4576 #endif /* CONFIG_PM */
4578 static void alc269_fixup_hweq(struct hda_codec
*codec
,
4579 const struct alc_fixup
*fix
, int action
)
4583 if (action
!= ALC_FIXUP_ACT_INIT
)
4585 coef
= alc_read_coef_idx(codec
, 0x1e);
4586 alc_write_coef_idx(codec
, 0x1e, coef
| 0x80);
4589 static void alc271_fixup_dmic(struct hda_codec
*codec
,
4590 const struct alc_fixup
*fix
, int action
)
4592 static const struct hda_verb verbs
[] = {
4593 {0x20, AC_VERB_SET_COEF_INDEX
, 0x0d},
4594 {0x20, AC_VERB_SET_PROC_COEF
, 0x4000},
4599 if (strcmp(codec
->chip_name
, "ALC271X"))
4601 cfg
= snd_hda_codec_get_pincfg(codec
, 0x12);
4602 if (get_defcfg_connect(cfg
) == AC_JACK_PORT_FIXED
)
4603 snd_hda_sequence_write(codec
, verbs
);
4606 static void alc269_fixup_pcm_44k(struct hda_codec
*codec
,
4607 const struct alc_fixup
*fix
, int action
)
4609 struct alc_spec
*spec
= codec
->spec
;
4611 if (action
!= ALC_FIXUP_ACT_PROBE
)
4614 /* Due to a hardware problem on Lenovo Ideadpad, we need to
4615 * fix the sample rate of analog I/O to 44.1kHz
4617 spec
->stream_analog_playback
= &alc269_44k_pcm_analog_playback
;
4618 spec
->stream_analog_capture
= &alc269_44k_pcm_analog_capture
;
4621 static void alc269_fixup_stereo_dmic(struct hda_codec
*codec
,
4622 const struct alc_fixup
*fix
, int action
)
4626 if (action
!= ALC_FIXUP_ACT_INIT
)
4628 /* The digital-mic unit sends PDM (differential signal) instead of
4629 * the standard PCM, thus you can't record a valid mono stream as is.
4630 * Below is a workaround specific to ALC269 to control the dmic
4631 * signal source as mono.
4633 coef
= alc_read_coef_idx(codec
, 0x07);
4634 alc_write_coef_idx(codec
, 0x07, coef
| 0x80);
4637 static void alc269_quanta_automute(struct hda_codec
*codec
)
4639 update_speakers(codec
);
4641 snd_hda_codec_write(codec
, 0x20, 0,
4642 AC_VERB_SET_COEF_INDEX
, 0x0c);
4643 snd_hda_codec_write(codec
, 0x20, 0,
4644 AC_VERB_SET_PROC_COEF
, 0x680);
4646 snd_hda_codec_write(codec
, 0x20, 0,
4647 AC_VERB_SET_COEF_INDEX
, 0x0c);
4648 snd_hda_codec_write(codec
, 0x20, 0,
4649 AC_VERB_SET_PROC_COEF
, 0x480);
4652 static void alc269_fixup_quanta_mute(struct hda_codec
*codec
,
4653 const struct alc_fixup
*fix
, int action
)
4655 struct alc_spec
*spec
= codec
->spec
;
4656 if (action
!= ALC_FIXUP_ACT_PROBE
)
4658 spec
->automute_hook
= alc269_quanta_automute
;
4662 ALC269_FIXUP_SONY_VAIO
,
4663 ALC275_FIXUP_SONY_VAIO_GPIO2
,
4664 ALC269_FIXUP_DELL_M101Z
,
4665 ALC269_FIXUP_SKU_IGNORE
,
4666 ALC269_FIXUP_ASUS_G73JW
,
4667 ALC269_FIXUP_LENOVO_EAPD
,
4668 ALC275_FIXUP_SONY_HWEQ
,
4670 ALC269_FIXUP_PCM_44K
,
4671 ALC269_FIXUP_STEREO_DMIC
,
4672 ALC269_FIXUP_QUANTA_MUTE
,
4673 ALC269_FIXUP_LIFEBOOK
,
4676 ALC269VB_FIXUP_AMIC
,
4677 ALC269VB_FIXUP_DMIC
,
4680 static const struct alc_fixup alc269_fixups
[] = {
4681 [ALC269_FIXUP_SONY_VAIO
] = {
4682 .type
= ALC_FIXUP_VERBS
,
4683 .v
.verbs
= (const struct hda_verb
[]) {
4684 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_VREFGRD
},
4688 [ALC275_FIXUP_SONY_VAIO_GPIO2
] = {
4689 .type
= ALC_FIXUP_VERBS
,
4690 .v
.verbs
= (const struct hda_verb
[]) {
4691 {0x01, AC_VERB_SET_GPIO_MASK
, 0x04},
4692 {0x01, AC_VERB_SET_GPIO_DIRECTION
, 0x04},
4693 {0x01, AC_VERB_SET_GPIO_DATA
, 0x00},
4697 .chain_id
= ALC269_FIXUP_SONY_VAIO
4699 [ALC269_FIXUP_DELL_M101Z
] = {
4700 .type
= ALC_FIXUP_VERBS
,
4701 .v
.verbs
= (const struct hda_verb
[]) {
4702 /* Enables internal speaker */
4703 {0x20, AC_VERB_SET_COEF_INDEX
, 13},
4704 {0x20, AC_VERB_SET_PROC_COEF
, 0x4040},
4708 [ALC269_FIXUP_SKU_IGNORE
] = {
4709 .type
= ALC_FIXUP_SKU
,
4710 .v
.sku
= ALC_FIXUP_SKU_IGNORE
,
4712 [ALC269_FIXUP_ASUS_G73JW
] = {
4713 .type
= ALC_FIXUP_PINS
,
4714 .v
.pins
= (const struct alc_pincfg
[]) {
4715 { 0x17, 0x99130111 }, /* subwoofer */
4719 [ALC269_FIXUP_LENOVO_EAPD
] = {
4720 .type
= ALC_FIXUP_VERBS
,
4721 .v
.verbs
= (const struct hda_verb
[]) {
4722 {0x14, AC_VERB_SET_EAPD_BTLENABLE
, 0},
4726 [ALC275_FIXUP_SONY_HWEQ
] = {
4727 .type
= ALC_FIXUP_FUNC
,
4728 .v
.func
= alc269_fixup_hweq
,
4730 .chain_id
= ALC275_FIXUP_SONY_VAIO_GPIO2
4732 [ALC271_FIXUP_DMIC
] = {
4733 .type
= ALC_FIXUP_FUNC
,
4734 .v
.func
= alc271_fixup_dmic
,
4736 [ALC269_FIXUP_PCM_44K
] = {
4737 .type
= ALC_FIXUP_FUNC
,
4738 .v
.func
= alc269_fixup_pcm_44k
,
4740 [ALC269_FIXUP_STEREO_DMIC
] = {
4741 .type
= ALC_FIXUP_FUNC
,
4742 .v
.func
= alc269_fixup_stereo_dmic
,
4744 [ALC269_FIXUP_QUANTA_MUTE
] = {
4745 .type
= ALC_FIXUP_FUNC
,
4746 .v
.func
= alc269_fixup_quanta_mute
,
4748 [ALC269_FIXUP_LIFEBOOK
] = {
4749 .type
= ALC_FIXUP_PINS
,
4750 .v
.pins
= (const struct alc_pincfg
[]) {
4751 { 0x1a, 0x2101103f }, /* dock line-out */
4752 { 0x1b, 0x23a11040 }, /* dock mic-in */
4756 .chain_id
= ALC269_FIXUP_QUANTA_MUTE
4758 [ALC269_FIXUP_AMIC
] = {
4759 .type
= ALC_FIXUP_PINS
,
4760 .v
.pins
= (const struct alc_pincfg
[]) {
4761 { 0x14, 0x99130110 }, /* speaker */
4762 { 0x15, 0x0121401f }, /* HP out */
4763 { 0x18, 0x01a19c20 }, /* mic */
4764 { 0x19, 0x99a3092f }, /* int-mic */
4768 [ALC269_FIXUP_DMIC
] = {
4769 .type
= ALC_FIXUP_PINS
,
4770 .v
.pins
= (const struct alc_pincfg
[]) {
4771 { 0x12, 0x99a3092f }, /* int-mic */
4772 { 0x14, 0x99130110 }, /* speaker */
4773 { 0x15, 0x0121401f }, /* HP out */
4774 { 0x18, 0x01a19c20 }, /* mic */
4778 [ALC269VB_FIXUP_AMIC
] = {
4779 .type
= ALC_FIXUP_PINS
,
4780 .v
.pins
= (const struct alc_pincfg
[]) {
4781 { 0x14, 0x99130110 }, /* speaker */
4782 { 0x18, 0x01a19c20 }, /* mic */
4783 { 0x19, 0x99a3092f }, /* int-mic */
4784 { 0x21, 0x0121401f }, /* HP out */
4788 [ALC269_FIXUP_DMIC
] = {
4789 .type
= ALC_FIXUP_PINS
,
4790 .v
.pins
= (const struct alc_pincfg
[]) {
4791 { 0x12, 0x99a3092f }, /* int-mic */
4792 { 0x14, 0x99130110 }, /* speaker */
4793 { 0x18, 0x01a19c20 }, /* mic */
4794 { 0x21, 0x0121401f }, /* HP out */
4800 static const struct snd_pci_quirk alc269_fixup_tbl
[] = {
4801 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW
),
4802 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC
),
4803 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC
),
4804 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC
),
4805 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC
),
4806 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC
),
4807 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2
),
4808 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ
),
4809 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ
),
4810 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO
),
4811 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z
),
4812 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC
),
4813 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK
),
4814 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE
),
4815 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE
),
4816 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE
),
4817 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE
),
4818 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE
),
4819 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_QUANTA_MUTE
),
4820 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K
),
4821 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD
),
4824 /* Below is a quirk table taken from the old code.
4825 * Basically the device should work as is without the fixup table.
4826 * If BIOS doesn't give a proper info, enable the corresponding
4829 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
4831 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC
),
4832 SND_PCI_QUIRK(0x1043, 0x1113, "ASUS N63Jn", ALC269_FIXUP_AMIC
),
4833 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC
),
4834 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC
),
4835 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC
),
4836 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC
),
4837 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC
),
4838 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC
),
4839 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC
),
4840 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC
),
4841 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC
),
4842 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC
),
4843 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC
),
4844 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC
),
4845 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC
),
4846 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC
),
4847 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC
),
4848 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC
),
4849 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC
),
4850 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC
),
4851 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC
),
4852 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC
),
4853 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC
),
4854 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC
),
4855 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC
),
4856 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC
),
4857 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC
),
4858 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC
),
4859 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC
),
4860 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC
),
4861 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC
),
4862 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC
),
4863 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC
),
4864 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC
),
4865 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC
),
4866 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC
),
4867 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC
),
4868 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC
),
4869 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC
),
4870 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC
),
4875 static const struct alc_model_fixup alc269_fixup_models
[] = {
4876 {.id
= ALC269_FIXUP_AMIC
, .name
= "laptop-amic"},
4877 {.id
= ALC269_FIXUP_DMIC
, .name
= "laptop-dmic"},
4882 static int alc269_fill_coef(struct hda_codec
*codec
)
4886 if ((alc_read_coef_idx(codec
, 0) & 0x00ff) < 0x015) {
4887 alc_write_coef_idx(codec
, 0xf, 0x960b);
4888 alc_write_coef_idx(codec
, 0xe, 0x8817);
4891 if ((alc_read_coef_idx(codec
, 0) & 0x00ff) == 0x016) {
4892 alc_write_coef_idx(codec
, 0xf, 0x960b);
4893 alc_write_coef_idx(codec
, 0xe, 0x8814);
4896 if ((alc_read_coef_idx(codec
, 0) & 0x00ff) == 0x017) {
4897 val
= alc_read_coef_idx(codec
, 0x04);
4898 /* Power up output pin */
4899 alc_write_coef_idx(codec
, 0x04, val
| (1<<11));
4902 if ((alc_read_coef_idx(codec
, 0) & 0x00ff) == 0x018) {
4903 val
= alc_read_coef_idx(codec
, 0xd);
4904 if ((val
& 0x0c00) >> 10 != 0x1) {
4905 /* Capless ramp up clock control */
4906 alc_write_coef_idx(codec
, 0xd, val
| (1<<10));
4908 val
= alc_read_coef_idx(codec
, 0x17);
4909 if ((val
& 0x01c0) >> 6 != 0x4) {
4910 /* Class D power on reset */
4911 alc_write_coef_idx(codec
, 0x17, val
| (1<<7));
4915 val
= alc_read_coef_idx(codec
, 0xd); /* Class D */
4916 alc_write_coef_idx(codec
, 0xd, val
| (1<<14));
4918 val
= alc_read_coef_idx(codec
, 0x4); /* HP */
4919 alc_write_coef_idx(codec
, 0x4, val
| (1<<11));
4926 static int patch_alc269(struct hda_codec
*codec
)
4928 struct alc_spec
*spec
;
4931 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
4937 spec
->mixer_nid
= 0x0b;
4939 alc_auto_parse_customize_define(codec
);
4941 if (codec
->vendor_id
== 0x10ec0269) {
4943 spec
->codec_variant
= ALC269_TYPE_ALC269VA
;
4944 coef
= alc_read_coef_idx(codec
, 0);
4945 if ((coef
& 0x00f0) == 0x0010) {
4946 if (codec
->bus
->pci
->subsystem_vendor
== 0x1025 &&
4947 spec
->cdefine
.platform_type
== 1) {
4948 alc_codec_rename(codec
, "ALC271X");
4949 } else if ((coef
& 0xf000) == 0x2000) {
4950 alc_codec_rename(codec
, "ALC259");
4951 } else if ((coef
& 0xf000) == 0x3000) {
4952 alc_codec_rename(codec
, "ALC258");
4953 } else if ((coef
& 0xfff0) == 0x3010) {
4954 alc_codec_rename(codec
, "ALC277");
4956 alc_codec_rename(codec
, "ALC269VB");
4958 spec
->codec_variant
= ALC269_TYPE_ALC269VB
;
4959 } else if ((coef
& 0x00f0) == 0x0020) {
4961 alc_codec_rename(codec
, "ALC259");
4962 else if (coef
== 0x6023)
4963 alc_codec_rename(codec
, "ALC281X");
4964 else if (codec
->bus
->pci
->subsystem_vendor
== 0x17aa &&
4965 codec
->bus
->pci
->subsystem_device
== 0x21f3)
4966 alc_codec_rename(codec
, "ALC3202");
4968 alc_codec_rename(codec
, "ALC269VC");
4969 spec
->codec_variant
= ALC269_TYPE_ALC269VC
;
4971 alc_fix_pll_init(codec
, 0x20, 0x04, 15);
4972 alc269_fill_coef(codec
);
4975 alc_pick_fixup(codec
, alc269_fixup_models
,
4976 alc269_fixup_tbl
, alc269_fixups
);
4977 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
4979 /* automatic parse from the BIOS config */
4980 err
= alc269_parse_auto_config(codec
);
4986 if (!spec
->no_analog
&& !spec
->adc_nids
) {
4987 alc_auto_fill_adc_caps(codec
);
4988 alc_rebuild_imux_for_auto_mic(codec
);
4989 alc_remove_invalid_adc_nids(codec
);
4992 if (!spec
->no_analog
&& !spec
->cap_mixer
)
4993 set_capture_mixer(codec
);
4995 if (!spec
->no_analog
&& has_cdefine_beep(codec
)) {
4996 err
= snd_hda_attach_beep_device(codec
, 0x1);
5001 set_beep_amp(spec
, 0x0b, 0x04, HDA_INPUT
);
5004 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
5006 spec
->vmaster_nid
= 0x02;
5008 codec
->patch_ops
= alc_patch_ops
;
5010 codec
->patch_ops
.resume
= alc269_resume
;
5012 spec
->init_hook
= alc_auto_init_std
;
5013 spec
->shutup
= alc269_shutup
;
5015 alc_init_jacks(codec
);
5016 #ifdef CONFIG_SND_HDA_POWER_SAVE
5017 if (!spec
->loopback
.amplist
)
5018 spec
->loopback
.amplist
= alc269_loopbacks
;
5019 if (alc269_mic2_for_mute_led(codec
))
5020 codec
->patch_ops
.check_power_status
= alc269_mic2_mute_check_ps
;
5030 static int alc861_parse_auto_config(struct hda_codec
*codec
)
5032 static const hda_nid_t alc861_ignore
[] = { 0x1d, 0 };
5033 static const hda_nid_t alc861_ssids
[] = { 0x0e, 0x0f, 0x0b, 0 };
5034 return alc_parse_auto_config(codec
, alc861_ignore
, alc861_ssids
);
5037 #ifdef CONFIG_SND_HDA_POWER_SAVE
5038 static const struct hda_amp_list alc861_loopbacks
[] = {
5039 { 0x15, HDA_INPUT
, 0 },
5040 { 0x15, HDA_INPUT
, 1 },
5041 { 0x15, HDA_INPUT
, 2 },
5042 { 0x15, HDA_INPUT
, 3 },
5048 /* Pin config fixes */
5050 PINFIX_FSC_AMILO_PI1505
,
5053 static const struct alc_fixup alc861_fixups
[] = {
5054 [PINFIX_FSC_AMILO_PI1505
] = {
5055 .type
= ALC_FIXUP_PINS
,
5056 .v
.pins
= (const struct alc_pincfg
[]) {
5057 { 0x0b, 0x0221101f }, /* HP */
5058 { 0x0f, 0x90170310 }, /* speaker */
5064 static const struct snd_pci_quirk alc861_fixup_tbl
[] = {
5065 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", PINFIX_FSC_AMILO_PI1505
),
5071 static int patch_alc861(struct hda_codec
*codec
)
5073 struct alc_spec
*spec
;
5076 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
5082 spec
->mixer_nid
= 0x15;
5084 alc_pick_fixup(codec
, NULL
, alc861_fixup_tbl
, alc861_fixups
);
5085 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
5087 /* automatic parse from the BIOS config */
5088 err
= alc861_parse_auto_config(codec
);
5094 if (!spec
->no_analog
&& !spec
->adc_nids
) {
5095 alc_auto_fill_adc_caps(codec
);
5096 alc_rebuild_imux_for_auto_mic(codec
);
5097 alc_remove_invalid_adc_nids(codec
);
5100 if (!spec
->no_analog
&& !spec
->cap_mixer
)
5101 set_capture_mixer(codec
);
5103 if (!spec
->no_analog
) {
5104 err
= snd_hda_attach_beep_device(codec
, 0x23);
5109 set_beep_amp(spec
, 0x23, 0, HDA_OUTPUT
);
5112 spec
->vmaster_nid
= 0x03;
5114 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
5116 codec
->patch_ops
= alc_patch_ops
;
5117 spec
->init_hook
= alc_auto_init_std
;
5118 #ifdef CONFIG_SND_HDA_POWER_SAVE
5119 spec
->power_hook
= alc_power_eapd
;
5120 if (!spec
->loopback
.amplist
)
5121 spec
->loopback
.amplist
= alc861_loopbacks
;
5132 * In addition, an independent DAC
5134 #ifdef CONFIG_SND_HDA_POWER_SAVE
5135 #define alc861vd_loopbacks alc880_loopbacks
5138 static int alc861vd_parse_auto_config(struct hda_codec
*codec
)
5140 static const hda_nid_t alc861vd_ignore
[] = { 0x1d, 0 };
5141 static const hda_nid_t alc861vd_ssids
[] = { 0x15, 0x1b, 0x14, 0 };
5142 return alc_parse_auto_config(codec
, alc861vd_ignore
, alc861vd_ssids
);
5146 ALC660VD_FIX_ASUS_GPIO1
,
5147 ALC861VD_FIX_DALLAS
,
5150 /* exclude VREF80 */
5151 static void alc861vd_fixup_dallas(struct hda_codec
*codec
,
5152 const struct alc_fixup
*fix
, int action
)
5154 if (action
== ALC_FIXUP_ACT_PRE_PROBE
) {
5155 snd_hda_override_pin_caps(codec
, 0x18, 0x00001714);
5156 snd_hda_override_pin_caps(codec
, 0x19, 0x0000171c);
5160 static const struct alc_fixup alc861vd_fixups
[] = {
5161 [ALC660VD_FIX_ASUS_GPIO1
] = {
5162 .type
= ALC_FIXUP_VERBS
,
5163 .v
.verbs
= (const struct hda_verb
[]) {
5165 {0x01, AC_VERB_SET_GPIO_MASK
, 0x03},
5166 {0x01, AC_VERB_SET_GPIO_DIRECTION
, 0x01},
5167 {0x01, AC_VERB_SET_GPIO_DATA
, 0x01},
5171 [ALC861VD_FIX_DALLAS
] = {
5172 .type
= ALC_FIXUP_FUNC
,
5173 .v
.func
= alc861vd_fixup_dallas
,
5177 static const struct snd_pci_quirk alc861vd_fixup_tbl
[] = {
5178 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS
),
5179 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1
),
5180 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS
),
5184 static const struct hda_verb alc660vd_eapd_verbs
[] = {
5185 {0x14, AC_VERB_SET_EAPD_BTLENABLE
, 2},
5186 {0x15, AC_VERB_SET_EAPD_BTLENABLE
, 2},
5192 static int patch_alc861vd(struct hda_codec
*codec
)
5194 struct alc_spec
*spec
;
5197 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
5203 spec
->mixer_nid
= 0x0b;
5205 alc_pick_fixup(codec
, NULL
, alc861vd_fixup_tbl
, alc861vd_fixups
);
5206 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
5208 /* automatic parse from the BIOS config */
5209 err
= alc861vd_parse_auto_config(codec
);
5215 if (codec
->vendor_id
== 0x10ec0660) {
5216 /* always turn on EAPD */
5217 add_verb(spec
, alc660vd_eapd_verbs
);
5220 if (!spec
->no_analog
&& !spec
->adc_nids
) {
5221 alc_auto_fill_adc_caps(codec
);
5222 alc_rebuild_imux_for_auto_mic(codec
);
5223 alc_remove_invalid_adc_nids(codec
);
5226 if (!spec
->no_analog
&& !spec
->cap_mixer
)
5227 set_capture_mixer(codec
);
5229 if (!spec
->no_analog
) {
5230 err
= snd_hda_attach_beep_device(codec
, 0x23);
5235 set_beep_amp(spec
, 0x0b, 0x05, HDA_INPUT
);
5238 spec
->vmaster_nid
= 0x02;
5240 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
5242 codec
->patch_ops
= alc_patch_ops
;
5244 spec
->init_hook
= alc_auto_init_std
;
5245 spec
->shutup
= alc_eapd_shutup
;
5246 #ifdef CONFIG_SND_HDA_POWER_SAVE
5247 if (!spec
->loopback
.amplist
)
5248 spec
->loopback
.amplist
= alc861vd_loopbacks
;
5257 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
5258 * configuration. Each pin widget can choose any input DACs and a mixer.
5259 * Each ADC is connected from a mixer of all inputs. This makes possible
5260 * 6-channel independent captures.
5262 * In addition, an independent DAC for the multi-playback (not used in this
5265 #ifdef CONFIG_SND_HDA_POWER_SAVE
5266 #define alc662_loopbacks alc880_loopbacks
5270 * BIOS auto configuration
5273 static int alc662_parse_auto_config(struct hda_codec
*codec
)
5275 static const hda_nid_t alc662_ignore
[] = { 0x1d, 0 };
5276 static const hda_nid_t alc663_ssids
[] = { 0x15, 0x1b, 0x14, 0x21 };
5277 static const hda_nid_t alc662_ssids
[] = { 0x15, 0x1b, 0x14, 0 };
5278 const hda_nid_t
*ssids
;
5280 if (codec
->vendor_id
== 0x10ec0272 || codec
->vendor_id
== 0x10ec0663 ||
5281 codec
->vendor_id
== 0x10ec0665 || codec
->vendor_id
== 0x10ec0670)
5282 ssids
= alc663_ssids
;
5284 ssids
= alc662_ssids
;
5285 return alc_parse_auto_config(codec
, alc662_ignore
, ssids
);
5288 static void alc272_fixup_mario(struct hda_codec
*codec
,
5289 const struct alc_fixup
*fix
, int action
)
5291 if (action
!= ALC_FIXUP_ACT_PROBE
)
5293 if (snd_hda_override_amp_caps(codec
, 0x2, HDA_OUTPUT
,
5294 (0x3b << AC_AMPCAP_OFFSET_SHIFT
) |
5295 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT
) |
5296 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT
) |
5297 (0 << AC_AMPCAP_MUTE_SHIFT
)))
5299 "hda_codec: failed to override amp caps for NID 0x2\n");
5303 ALC662_FIXUP_ASPIRE
,
5304 ALC662_FIXUP_IDEAPAD
,
5306 ALC662_FIXUP_CZC_P10T
,
5307 ALC662_FIXUP_SKU_IGNORE
,
5308 ALC662_FIXUP_HP_RP5800
,
5309 ALC662_FIXUP_ASUS_MODE1
,
5310 ALC662_FIXUP_ASUS_MODE2
,
5311 ALC662_FIXUP_ASUS_MODE3
,
5312 ALC662_FIXUP_ASUS_MODE4
,
5313 ALC662_FIXUP_ASUS_MODE5
,
5314 ALC662_FIXUP_ASUS_MODE6
,
5315 ALC662_FIXUP_ASUS_MODE7
,
5316 ALC662_FIXUP_ASUS_MODE8
,
5319 static const struct alc_fixup alc662_fixups
[] = {
5320 [ALC662_FIXUP_ASPIRE
] = {
5321 .type
= ALC_FIXUP_PINS
,
5322 .v
.pins
= (const struct alc_pincfg
[]) {
5323 { 0x15, 0x99130112 }, /* subwoofer */
5327 [ALC662_FIXUP_IDEAPAD
] = {
5328 .type
= ALC_FIXUP_PINS
,
5329 .v
.pins
= (const struct alc_pincfg
[]) {
5330 { 0x17, 0x99130112 }, /* subwoofer */
5334 [ALC272_FIXUP_MARIO
] = {
5335 .type
= ALC_FIXUP_FUNC
,
5336 .v
.func
= alc272_fixup_mario
,
5338 [ALC662_FIXUP_CZC_P10T
] = {
5339 .type
= ALC_FIXUP_VERBS
,
5340 .v
.verbs
= (const struct hda_verb
[]) {
5341 {0x14, AC_VERB_SET_EAPD_BTLENABLE
, 0},
5345 [ALC662_FIXUP_SKU_IGNORE
] = {
5346 .type
= ALC_FIXUP_SKU
,
5347 .v
.sku
= ALC_FIXUP_SKU_IGNORE
,
5349 [ALC662_FIXUP_HP_RP5800
] = {
5350 .type
= ALC_FIXUP_PINS
,
5351 .v
.pins
= (const struct alc_pincfg
[]) {
5352 { 0x14, 0x0221201f }, /* HP out */
5356 .chain_id
= ALC662_FIXUP_SKU_IGNORE
5358 [ALC662_FIXUP_ASUS_MODE1
] = {
5359 .type
= ALC_FIXUP_PINS
,
5360 .v
.pins
= (const struct alc_pincfg
[]) {
5361 { 0x14, 0x99130110 }, /* speaker */
5362 { 0x18, 0x01a19c20 }, /* mic */
5363 { 0x19, 0x99a3092f }, /* int-mic */
5364 { 0x21, 0x0121401f }, /* HP out */
5368 .chain_id
= ALC662_FIXUP_SKU_IGNORE
5370 [ALC662_FIXUP_ASUS_MODE2
] = {
5371 .type
= ALC_FIXUP_PINS
,
5372 .v
.pins
= (const struct alc_pincfg
[]) {
5373 { 0x14, 0x99130110 }, /* speaker */
5374 { 0x18, 0x01a19820 }, /* mic */
5375 { 0x19, 0x99a3092f }, /* int-mic */
5376 { 0x1b, 0x0121401f }, /* HP out */
5380 .chain_id
= ALC662_FIXUP_SKU_IGNORE
5382 [ALC662_FIXUP_ASUS_MODE3
] = {
5383 .type
= ALC_FIXUP_PINS
,
5384 .v
.pins
= (const struct alc_pincfg
[]) {
5385 { 0x14, 0x99130110 }, /* speaker */
5386 { 0x15, 0x0121441f }, /* HP */
5387 { 0x18, 0x01a19840 }, /* mic */
5388 { 0x19, 0x99a3094f }, /* int-mic */
5389 { 0x21, 0x01211420 }, /* HP2 */
5393 .chain_id
= ALC662_FIXUP_SKU_IGNORE
5395 [ALC662_FIXUP_ASUS_MODE4
] = {
5396 .type
= ALC_FIXUP_PINS
,
5397 .v
.pins
= (const struct alc_pincfg
[]) {
5398 { 0x14, 0x99130110 }, /* speaker */
5399 { 0x16, 0x99130111 }, /* speaker */
5400 { 0x18, 0x01a19840 }, /* mic */
5401 { 0x19, 0x99a3094f }, /* int-mic */
5402 { 0x21, 0x0121441f }, /* HP */
5406 .chain_id
= ALC662_FIXUP_SKU_IGNORE
5408 [ALC662_FIXUP_ASUS_MODE5
] = {
5409 .type
= ALC_FIXUP_PINS
,
5410 .v
.pins
= (const struct alc_pincfg
[]) {
5411 { 0x14, 0x99130110 }, /* speaker */
5412 { 0x15, 0x0121441f }, /* HP */
5413 { 0x16, 0x99130111 }, /* speaker */
5414 { 0x18, 0x01a19840 }, /* mic */
5415 { 0x19, 0x99a3094f }, /* int-mic */
5419 .chain_id
= ALC662_FIXUP_SKU_IGNORE
5421 [ALC662_FIXUP_ASUS_MODE6
] = {
5422 .type
= ALC_FIXUP_PINS
,
5423 .v
.pins
= (const struct alc_pincfg
[]) {
5424 { 0x14, 0x99130110 }, /* speaker */
5425 { 0x15, 0x01211420 }, /* HP2 */
5426 { 0x18, 0x01a19840 }, /* mic */
5427 { 0x19, 0x99a3094f }, /* int-mic */
5428 { 0x1b, 0x0121441f }, /* HP */
5432 .chain_id
= ALC662_FIXUP_SKU_IGNORE
5434 [ALC662_FIXUP_ASUS_MODE7
] = {
5435 .type
= ALC_FIXUP_PINS
,
5436 .v
.pins
= (const struct alc_pincfg
[]) {
5437 { 0x14, 0x99130110 }, /* speaker */
5438 { 0x17, 0x99130111 }, /* speaker */
5439 { 0x18, 0x01a19840 }, /* mic */
5440 { 0x19, 0x99a3094f }, /* int-mic */
5441 { 0x1b, 0x01214020 }, /* HP */
5442 { 0x21, 0x0121401f }, /* HP */
5446 .chain_id
= ALC662_FIXUP_SKU_IGNORE
5448 [ALC662_FIXUP_ASUS_MODE8
] = {
5449 .type
= ALC_FIXUP_PINS
,
5450 .v
.pins
= (const struct alc_pincfg
[]) {
5451 { 0x14, 0x99130110 }, /* speaker */
5452 { 0x12, 0x99a30970 }, /* int-mic */
5453 { 0x15, 0x01214020 }, /* HP */
5454 { 0x17, 0x99130111 }, /* speaker */
5455 { 0x18, 0x01a19840 }, /* mic */
5456 { 0x21, 0x0121401f }, /* HP */
5460 .chain_id
= ALC662_FIXUP_SKU_IGNORE
5464 static const struct snd_pci_quirk alc662_fixup_tbl
[] = {
5465 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2
),
5466 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE
),
5467 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE
),
5468 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE
),
5469 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800
),
5470 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2
),
5471 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD
),
5472 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD
),
5473 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD
),
5474 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T
),
5477 /* Below is a quirk table taken from the old code.
5478 * Basically the device should work as is without the fixup table.
5479 * If BIOS doesn't give a proper info, enable the corresponding
5482 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1
),
5483 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3
),
5484 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1
),
5485 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3
),
5486 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1
),
5487 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2
),
5488 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1
),
5489 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1
),
5490 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1
),
5491 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2
),
5492 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7
),
5493 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7
),
5494 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8
),
5495 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3
),
5496 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1
),
5497 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2
),
5498 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2
),
5499 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1
),
5500 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2
),
5501 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6
),
5502 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6
),
5503 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2
),
5504 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1
),
5505 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3
),
5506 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2
),
5507 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2
),
5508 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5
),
5509 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6
),
5510 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2
),
5511 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1
),
5512 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2
),
5513 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2
),
5514 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3
),
5515 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3
),
5516 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1
),
5517 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1
),
5518 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1
),
5519 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1
),
5520 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1
),
5521 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2
),
5522 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2
),
5523 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1
),
5524 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1
),
5525 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3
),
5526 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1
),
5527 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1
),
5528 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1
),
5529 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2
),
5530 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1
),
5531 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4
),
5536 static const struct alc_model_fixup alc662_fixup_models
[] = {
5537 {.id
= ALC272_FIXUP_MARIO
, .name
= "mario"},
5538 {.id
= ALC662_FIXUP_ASUS_MODE1
, .name
= "asus-mode1"},
5539 {.id
= ALC662_FIXUP_ASUS_MODE2
, .name
= "asus-mode2"},
5540 {.id
= ALC662_FIXUP_ASUS_MODE3
, .name
= "asus-mode3"},
5541 {.id
= ALC662_FIXUP_ASUS_MODE4
, .name
= "asus-mode4"},
5542 {.id
= ALC662_FIXUP_ASUS_MODE5
, .name
= "asus-mode5"},
5543 {.id
= ALC662_FIXUP_ASUS_MODE6
, .name
= "asus-mode6"},
5544 {.id
= ALC662_FIXUP_ASUS_MODE7
, .name
= "asus-mode7"},
5545 {.id
= ALC662_FIXUP_ASUS_MODE8
, .name
= "asus-mode8"},
5552 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
5553 #include "alc662_quirks.c"
5556 static int patch_alc662(struct hda_codec
*codec
)
5558 struct alc_spec
*spec
;
5559 int err
, board_config
;
5562 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
5568 spec
->mixer_nid
= 0x0b;
5570 /* handle multiple HPs as is */
5571 spec
->parse_flags
= HDA_PINCFG_NO_HP_FIXUP
;
5573 alc_auto_parse_customize_define(codec
);
5575 alc_fix_pll_init(codec
, 0x20, 0x04, 15);
5577 coef
= alc_read_coef_idx(codec
, 0);
5578 if (coef
== 0x8020 || coef
== 0x8011)
5579 alc_codec_rename(codec
, "ALC661");
5580 else if (coef
& (1 << 14) &&
5581 codec
->bus
->pci
->subsystem_vendor
== 0x1025 &&
5582 spec
->cdefine
.platform_type
== 1)
5583 alc_codec_rename(codec
, "ALC272X");
5584 else if (coef
== 0x4011)
5585 alc_codec_rename(codec
, "ALC656");
5587 board_config
= alc_board_config(codec
, ALC662_MODEL_LAST
,
5588 alc662_models
, alc662_cfg_tbl
);
5589 if (board_config
< 0) {
5590 printk(KERN_INFO
"hda_codec: %s: BIOS auto-probing.\n",
5592 board_config
= ALC_MODEL_AUTO
;
5595 if (board_config
== ALC_MODEL_AUTO
) {
5596 alc_pick_fixup(codec
, alc662_fixup_models
,
5597 alc662_fixup_tbl
, alc662_fixups
);
5598 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
5599 /* automatic parse from the BIOS config */
5600 err
= alc662_parse_auto_config(codec
);
5605 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
5608 "hda_codec: Cannot set up configuration "
5609 "from BIOS. Using base mode...\n");
5610 board_config
= ALC662_3ST_2ch_DIG
;
5615 if (board_config
!= ALC_MODEL_AUTO
)
5616 setup_preset(codec
, &alc662_presets
[board_config
]);
5618 if (!spec
->no_analog
&& !spec
->adc_nids
) {
5619 alc_auto_fill_adc_caps(codec
);
5620 alc_rebuild_imux_for_auto_mic(codec
);
5621 alc_remove_invalid_adc_nids(codec
);
5624 if (!spec
->no_analog
&& !spec
->cap_mixer
)
5625 set_capture_mixer(codec
);
5627 if (!spec
->no_analog
&& has_cdefine_beep(codec
)) {
5628 err
= snd_hda_attach_beep_device(codec
, 0x1);
5633 switch (codec
->vendor_id
) {
5635 set_beep_amp(spec
, 0x0b, 0x05, HDA_INPUT
);
5640 set_beep_amp(spec
, 0x0b, 0x04, HDA_INPUT
);
5643 set_beep_amp(spec
, 0x0b, 0x03, HDA_INPUT
);
5647 spec
->vmaster_nid
= 0x02;
5649 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
5651 codec
->patch_ops
= alc_patch_ops
;
5652 if (board_config
== ALC_MODEL_AUTO
)
5653 spec
->init_hook
= alc_auto_init_std
;
5654 spec
->shutup
= alc_eapd_shutup
;
5656 alc_init_jacks(codec
);
5658 #ifdef CONFIG_SND_HDA_POWER_SAVE
5659 if (!spec
->loopback
.amplist
)
5660 spec
->loopback
.amplist
= alc662_loopbacks
;
5666 static int patch_alc888(struct hda_codec
*codec
)
5668 if ((alc_read_coef_idx(codec
, 0) & 0x00f0)==0x0030){
5669 kfree(codec
->chip_name
);
5670 if (codec
->vendor_id
== 0x10ec0887)
5671 codec
->chip_name
= kstrdup("ALC887-VD", GFP_KERNEL
);
5673 codec
->chip_name
= kstrdup("ALC888-VD", GFP_KERNEL
);
5674 if (!codec
->chip_name
) {
5678 return patch_alc662(codec
);
5680 return patch_alc882(codec
);
5683 static int patch_alc899(struct hda_codec
*codec
)
5685 if ((alc_read_coef_idx(codec
, 0) & 0x2000) != 0x2000) {
5686 kfree(codec
->chip_name
);
5687 codec
->chip_name
= kstrdup("ALC898", GFP_KERNEL
);
5689 return patch_alc882(codec
);
5696 static int alc680_parse_auto_config(struct hda_codec
*codec
)
5698 return alc_parse_auto_config(codec
, NULL
, NULL
);
5703 static int patch_alc680(struct hda_codec
*codec
)
5705 struct alc_spec
*spec
;
5708 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
5714 /* ALC680 has no aa-loopback mixer */
5716 /* automatic parse from the BIOS config */
5717 err
= alc680_parse_auto_config(codec
);
5723 if (!spec
->no_analog
&& !spec
->cap_mixer
)
5724 set_capture_mixer(codec
);
5726 spec
->vmaster_nid
= 0x02;
5728 codec
->patch_ops
= alc_patch_ops
;
5729 spec
->init_hook
= alc_auto_init_std
;
5737 static const struct hda_codec_preset snd_hda_preset_realtek
[] = {
5738 { .id
= 0x10ec0221, .name
= "ALC221", .patch
= patch_alc269
},
5739 { .id
= 0x10ec0260, .name
= "ALC260", .patch
= patch_alc260
},
5740 { .id
= 0x10ec0262, .name
= "ALC262", .patch
= patch_alc262
},
5741 { .id
= 0x10ec0267, .name
= "ALC267", .patch
= patch_alc268
},
5742 { .id
= 0x10ec0268, .name
= "ALC268", .patch
= patch_alc268
},
5743 { .id
= 0x10ec0269, .name
= "ALC269", .patch
= patch_alc269
},
5744 { .id
= 0x10ec0270, .name
= "ALC270", .patch
= patch_alc269
},
5745 { .id
= 0x10ec0272, .name
= "ALC272", .patch
= patch_alc662
},
5746 { .id
= 0x10ec0275, .name
= "ALC275", .patch
= patch_alc269
},
5747 { .id
= 0x10ec0276, .name
= "ALC276", .patch
= patch_alc269
},
5748 { .id
= 0x10ec0861, .rev
= 0x100340, .name
= "ALC660",
5749 .patch
= patch_alc861
},
5750 { .id
= 0x10ec0660, .name
= "ALC660-VD", .patch
= patch_alc861vd
},
5751 { .id
= 0x10ec0861, .name
= "ALC861", .patch
= patch_alc861
},
5752 { .id
= 0x10ec0862, .name
= "ALC861-VD", .patch
= patch_alc861vd
},
5753 { .id
= 0x10ec0662, .rev
= 0x100002, .name
= "ALC662 rev2",
5754 .patch
= patch_alc882
},
5755 { .id
= 0x10ec0662, .rev
= 0x100101, .name
= "ALC662 rev1",
5756 .patch
= patch_alc662
},
5757 { .id
= 0x10ec0663, .name
= "ALC663", .patch
= patch_alc662
},
5758 { .id
= 0x10ec0665, .name
= "ALC665", .patch
= patch_alc662
},
5759 { .id
= 0x10ec0670, .name
= "ALC670", .patch
= patch_alc662
},
5760 { .id
= 0x10ec0680, .name
= "ALC680", .patch
= patch_alc680
},
5761 { .id
= 0x10ec0880, .name
= "ALC880", .patch
= patch_alc880
},
5762 { .id
= 0x10ec0882, .name
= "ALC882", .patch
= patch_alc882
},
5763 { .id
= 0x10ec0883, .name
= "ALC883", .patch
= patch_alc882
},
5764 { .id
= 0x10ec0885, .rev
= 0x100101, .name
= "ALC889A",
5765 .patch
= patch_alc882
},
5766 { .id
= 0x10ec0885, .rev
= 0x100103, .name
= "ALC889A",
5767 .patch
= patch_alc882
},
5768 { .id
= 0x10ec0885, .name
= "ALC885", .patch
= patch_alc882
},
5769 { .id
= 0x10ec0887, .name
= "ALC887", .patch
= patch_alc888
},
5770 { .id
= 0x10ec0888, .rev
= 0x100101, .name
= "ALC1200",
5771 .patch
= patch_alc882
},
5772 { .id
= 0x10ec0888, .name
= "ALC888", .patch
= patch_alc888
},
5773 { .id
= 0x10ec0889, .name
= "ALC889", .patch
= patch_alc882
},
5774 { .id
= 0x10ec0892, .name
= "ALC892", .patch
= patch_alc662
},
5775 { .id
= 0x10ec0899, .name
= "ALC899", .patch
= patch_alc899
},
5779 MODULE_ALIAS("snd-hda-codec-id:10ec*");
5781 MODULE_LICENSE("GPL");
5782 MODULE_DESCRIPTION("Realtek HD-audio codec");
5784 static struct hda_codec_preset_list realtek_list
= {
5785 .preset
= snd_hda_preset_realtek
,
5786 .owner
= THIS_MODULE
,
5789 static int __init
patch_realtek_init(void)
5791 return snd_hda_add_codec_preset(&realtek_list
);
5794 static void __exit
patch_realtek_exit(void)
5796 snd_hda_delete_codec_preset(&realtek_list
);
5799 module_init(patch_realtek_init
)
5800 module_exit(patch_realtek_exit
)