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
);
163 /* for pin sensing */
164 unsigned int jack_present
: 1;
165 unsigned int line_jack_present
:1;
166 unsigned int master_mute
:1;
167 unsigned int auto_mic
:1;
168 unsigned int auto_mic_valid_imux
:1; /* valid imux for auto-mic */
169 unsigned int automute
:1; /* HP automute enabled */
170 unsigned int detect_line
:1; /* Line-out detection enabled */
171 unsigned int automute_lines
:1; /* automute line-out as well; NOP when automute_hp_lo isn't set */
172 unsigned int automute_hp_lo
:1; /* both HP and LO available */
175 unsigned int no_analog
:1; /* digital I/O only */
176 unsigned int dyn_adc_switch
:1; /* switch ADCs (for ALC275) */
177 unsigned int single_input_src
:1;
178 unsigned int vol_in_capsrc
:1; /* use capsrc volume (ADC has no vol) */
180 /* auto-mute control */
182 hda_nid_t automute_mixer_nid
[AUTO_CFG_MAX_OUTS
];
185 int codec_variant
; /* flag for other variants */
187 /* for virtual master */
188 hda_nid_t vmaster_nid
;
189 #ifdef CONFIG_SND_HDA_POWER_SAVE
190 struct hda_loopback_check loopback
;
195 unsigned int pll_coef_idx
, pll_coef_bit
;
199 const struct alc_fixup
*fixup_list
;
200 const char *fixup_name
;
204 struct alc_multi_io multi_io
[4];
207 #define ALC_MODEL_AUTO 0 /* common for all chips */
209 static bool check_amp_caps(struct hda_codec
*codec
, hda_nid_t nid
,
210 int dir
, unsigned int bits
)
214 if (get_wcaps(codec
, nid
) & (1 << (dir
+ 1)))
215 if (query_amp_caps(codec
, nid
, dir
) & bits
)
220 #define nid_has_mute(codec, nid, dir) \
221 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
222 #define nid_has_volume(codec, nid, dir) \
223 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
228 static int alc_mux_enum_info(struct snd_kcontrol
*kcontrol
,
229 struct snd_ctl_elem_info
*uinfo
)
231 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
232 struct alc_spec
*spec
= codec
->spec
;
233 unsigned int mux_idx
= snd_ctl_get_ioffidx(kcontrol
, &uinfo
->id
);
234 if (mux_idx
>= spec
->num_mux_defs
)
236 if (!spec
->input_mux
[mux_idx
].num_items
&& mux_idx
> 0)
238 return snd_hda_input_mux_info(&spec
->input_mux
[mux_idx
], uinfo
);
241 static int alc_mux_enum_get(struct snd_kcontrol
*kcontrol
,
242 struct snd_ctl_elem_value
*ucontrol
)
244 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
245 struct alc_spec
*spec
= codec
->spec
;
246 unsigned int adc_idx
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
248 ucontrol
->value
.enumerated
.item
[0] = spec
->cur_mux
[adc_idx
];
252 static bool alc_dyn_adc_pcm_resetup(struct hda_codec
*codec
, int cur
)
254 struct alc_spec
*spec
= codec
->spec
;
255 hda_nid_t new_adc
= spec
->adc_nids
[spec
->dyn_adc_idx
[cur
]];
257 if (spec
->cur_adc
&& spec
->cur_adc
!= new_adc
) {
258 /* stream is running, let's swap the current ADC */
259 __snd_hda_codec_cleanup_stream(codec
, spec
->cur_adc
, 1);
260 spec
->cur_adc
= new_adc
;
261 snd_hda_codec_setup_stream(codec
, new_adc
,
262 spec
->cur_adc_stream_tag
, 0,
263 spec
->cur_adc_format
);
269 /* select the given imux item; either unmute exclusively or select the route */
270 static int alc_mux_select(struct hda_codec
*codec
, unsigned int adc_idx
,
271 unsigned int idx
, bool force
)
273 struct alc_spec
*spec
= codec
->spec
;
274 const struct hda_input_mux
*imux
;
275 unsigned int mux_idx
;
279 mux_idx
= adc_idx
>= spec
->num_mux_defs
? 0 : adc_idx
;
280 imux
= &spec
->input_mux
[mux_idx
];
281 if (!imux
->num_items
&& mux_idx
> 0)
282 imux
= &spec
->input_mux
[0];
284 if (idx
>= imux
->num_items
)
285 idx
= imux
->num_items
- 1;
286 if (spec
->cur_mux
[adc_idx
] == idx
&& !force
)
288 spec
->cur_mux
[adc_idx
] = idx
;
290 if (spec
->dyn_adc_switch
) {
291 alc_dyn_adc_pcm_resetup(codec
, idx
);
292 adc_idx
= spec
->dyn_adc_idx
[idx
];
295 nid
= spec
->capsrc_nids
?
296 spec
->capsrc_nids
[adc_idx
] : spec
->adc_nids
[adc_idx
];
299 if (snd_hda_get_conn_list(codec
, nid
, NULL
) <= 1)
302 type
= get_wcaps_type(get_wcaps(codec
, nid
));
303 if (type
== AC_WID_AUD_MIX
) {
304 /* Matrix-mixer style (e.g. ALC882) */
305 for (i
= 0; i
< imux
->num_items
; i
++) {
306 unsigned int v
= (i
== idx
) ? 0 : HDA_AMP_MUTE
;
307 snd_hda_codec_amp_stereo(codec
, nid
, HDA_INPUT
,
308 imux
->items
[i
].index
,
312 /* MUX style (e.g. ALC880) */
313 snd_hda_codec_write_cache(codec
, nid
, 0,
314 AC_VERB_SET_CONNECT_SEL
,
315 imux
->items
[idx
].index
);
320 static int alc_mux_enum_put(struct snd_kcontrol
*kcontrol
,
321 struct snd_ctl_elem_value
*ucontrol
)
323 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
324 unsigned int adc_idx
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
325 return alc_mux_select(codec
, adc_idx
,
326 ucontrol
->value
.enumerated
.item
[0], false);
330 * set up the input pin config (depending on the given auto-pin type)
332 static void alc_set_input_pin(struct hda_codec
*codec
, hda_nid_t nid
,
335 unsigned int val
= PIN_IN
;
337 if (auto_pin_type
== AUTO_PIN_MIC
) {
340 oldval
= snd_hda_codec_read(codec
, nid
, 0,
341 AC_VERB_GET_PIN_WIDGET_CONTROL
, 0);
342 pincap
= snd_hda_query_pin_caps(codec
, nid
);
343 pincap
= (pincap
& AC_PINCAP_VREF
) >> AC_PINCAP_VREF_SHIFT
;
344 /* if the default pin setup is vref50, we give it priority */
345 if ((pincap
& AC_PINCAP_VREF_80
) && oldval
!= PIN_VREF50
)
347 else if (pincap
& AC_PINCAP_VREF_50
)
349 else if (pincap
& AC_PINCAP_VREF_100
)
351 else if (pincap
& AC_PINCAP_VREF_GRD
)
354 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_PIN_WIDGET_CONTROL
, val
);
358 * Append the given mixer and verb elements for the later use
359 * The mixer array is referred in build_controls(), and init_verbs are
362 static void add_mixer(struct alc_spec
*spec
, const struct snd_kcontrol_new
*mix
)
364 if (snd_BUG_ON(spec
->num_mixers
>= ARRAY_SIZE(spec
->mixers
)))
366 spec
->mixers
[spec
->num_mixers
++] = mix
;
369 static void add_verb(struct alc_spec
*spec
, const struct hda_verb
*verb
)
371 if (snd_BUG_ON(spec
->num_init_verbs
>= ARRAY_SIZE(spec
->init_verbs
)))
373 spec
->init_verbs
[spec
->num_init_verbs
++] = verb
;
377 * GPIO setup tables, used in initialization
379 /* Enable GPIO mask and set output */
380 static const struct hda_verb alc_gpio1_init_verbs
[] = {
381 {0x01, AC_VERB_SET_GPIO_MASK
, 0x01},
382 {0x01, AC_VERB_SET_GPIO_DIRECTION
, 0x01},
383 {0x01, AC_VERB_SET_GPIO_DATA
, 0x01},
387 static const struct hda_verb alc_gpio2_init_verbs
[] = {
388 {0x01, AC_VERB_SET_GPIO_MASK
, 0x02},
389 {0x01, AC_VERB_SET_GPIO_DIRECTION
, 0x02},
390 {0x01, AC_VERB_SET_GPIO_DATA
, 0x02},
394 static const struct hda_verb alc_gpio3_init_verbs
[] = {
395 {0x01, AC_VERB_SET_GPIO_MASK
, 0x03},
396 {0x01, AC_VERB_SET_GPIO_DIRECTION
, 0x03},
397 {0x01, AC_VERB_SET_GPIO_DATA
, 0x03},
402 * Fix hardware PLL issue
403 * On some codecs, the analog PLL gating control must be off while
404 * the default value is 1.
406 static void alc_fix_pll(struct hda_codec
*codec
)
408 struct alc_spec
*spec
= codec
->spec
;
413 snd_hda_codec_write(codec
, spec
->pll_nid
, 0, AC_VERB_SET_COEF_INDEX
,
415 val
= snd_hda_codec_read(codec
, spec
->pll_nid
, 0,
416 AC_VERB_GET_PROC_COEF
, 0);
417 snd_hda_codec_write(codec
, spec
->pll_nid
, 0, AC_VERB_SET_COEF_INDEX
,
419 snd_hda_codec_write(codec
, spec
->pll_nid
, 0, AC_VERB_SET_PROC_COEF
,
420 val
& ~(1 << spec
->pll_coef_bit
));
423 static void alc_fix_pll_init(struct hda_codec
*codec
, hda_nid_t nid
,
424 unsigned int coef_idx
, unsigned int coef_bit
)
426 struct alc_spec
*spec
= codec
->spec
;
428 spec
->pll_coef_idx
= coef_idx
;
429 spec
->pll_coef_bit
= coef_bit
;
434 * Jack-reporting via input-jack layer
437 /* initialization of jacks; currently checks only a few known pins */
438 static int alc_init_jacks(struct hda_codec
*codec
)
440 #ifdef CONFIG_SND_HDA_INPUT_JACK
441 struct alc_spec
*spec
= codec
->spec
;
443 unsigned int hp_nid
= spec
->autocfg
.hp_pins
[0];
444 unsigned int mic_nid
= spec
->ext_mic_pin
;
445 unsigned int dock_nid
= spec
->dock_mic_pin
;
448 err
= snd_hda_input_jack_add(codec
, hp_nid
,
449 SND_JACK_HEADPHONE
, NULL
);
452 snd_hda_input_jack_report(codec
, hp_nid
);
456 err
= snd_hda_input_jack_add(codec
, mic_nid
,
457 SND_JACK_MICROPHONE
, NULL
);
460 snd_hda_input_jack_report(codec
, mic_nid
);
463 err
= snd_hda_input_jack_add(codec
, dock_nid
,
464 SND_JACK_MICROPHONE
, NULL
);
467 snd_hda_input_jack_report(codec
, dock_nid
);
469 #endif /* CONFIG_SND_HDA_INPUT_JACK */
474 * Jack detections for HP auto-mute and mic-switch
477 /* check each pin in the given array; returns true if any of them is plugged */
478 static bool detect_jacks(struct hda_codec
*codec
, int num_pins
, hda_nid_t
*pins
)
482 for (i
= 0; i
< num_pins
; i
++) {
483 hda_nid_t nid
= pins
[i
];
486 snd_hda_input_jack_report(codec
, nid
);
487 present
|= snd_hda_jack_detect(codec
, nid
);
492 /* standard HP/line-out auto-mute helper */
493 static void do_automute(struct hda_codec
*codec
, int num_pins
, hda_nid_t
*pins
,
494 bool mute
, bool hp_out
)
496 struct alc_spec
*spec
= codec
->spec
;
497 unsigned int mute_bits
= mute
? HDA_AMP_MUTE
: 0;
498 unsigned int pin_bits
= mute
? 0 : (hp_out
? PIN_HP
: PIN_OUT
);
501 for (i
= 0; i
< num_pins
; i
++) {
502 hda_nid_t nid
= pins
[i
];
505 switch (spec
->automute_mode
) {
506 case ALC_AUTOMUTE_PIN
:
507 snd_hda_codec_write(codec
, nid
, 0,
508 AC_VERB_SET_PIN_WIDGET_CONTROL
,
511 case ALC_AUTOMUTE_AMP
:
512 snd_hda_codec_amp_stereo(codec
, nid
, HDA_OUTPUT
, 0,
513 HDA_AMP_MUTE
, mute_bits
);
515 case ALC_AUTOMUTE_MIXER
:
516 nid
= spec
->automute_mixer_nid
[i
];
519 snd_hda_codec_amp_stereo(codec
, nid
, HDA_INPUT
, 0,
520 HDA_AMP_MUTE
, mute_bits
);
521 snd_hda_codec_amp_stereo(codec
, nid
, HDA_INPUT
, 1,
522 HDA_AMP_MUTE
, mute_bits
);
528 /* Toggle internal speakers muting */
529 static void update_speakers(struct hda_codec
*codec
)
531 struct alc_spec
*spec
= codec
->spec
;
534 /* Control HP pins/amps depending on master_mute state;
535 * in general, HP pins/amps control should be enabled in all cases,
536 * but currently set only for master_mute, just to be safe
538 do_automute(codec
, ARRAY_SIZE(spec
->autocfg
.hp_pins
),
539 spec
->autocfg
.hp_pins
, spec
->master_mute
, true);
544 on
= spec
->jack_present
| spec
->line_jack_present
;
545 on
|= spec
->master_mute
;
546 do_automute(codec
, ARRAY_SIZE(spec
->autocfg
.speaker_pins
),
547 spec
->autocfg
.speaker_pins
, on
, false);
549 /* toggle line-out mutes if needed, too */
550 /* if LO is a copy of either HP or Speaker, don't need to handle it */
551 if (spec
->autocfg
.line_out_pins
[0] == spec
->autocfg
.hp_pins
[0] ||
552 spec
->autocfg
.line_out_pins
[0] == spec
->autocfg
.speaker_pins
[0])
554 if (!spec
->automute
|| (spec
->automute_hp_lo
&& !spec
->automute_lines
))
557 on
= spec
->jack_present
;
558 on
|= spec
->master_mute
;
559 do_automute(codec
, ARRAY_SIZE(spec
->autocfg
.line_out_pins
),
560 spec
->autocfg
.line_out_pins
, on
, false);
563 /* standard HP-automute helper */
564 static void alc_hp_automute(struct hda_codec
*codec
)
566 struct alc_spec
*spec
= codec
->spec
;
569 detect_jacks(codec
, ARRAY_SIZE(spec
->autocfg
.hp_pins
),
570 spec
->autocfg
.hp_pins
);
573 update_speakers(codec
);
576 /* standard line-out-automute helper */
577 static void alc_line_automute(struct hda_codec
*codec
)
579 struct alc_spec
*spec
= codec
->spec
;
581 /* check LO jack only when it's different from HP */
582 if (spec
->autocfg
.line_out_pins
[0] == spec
->autocfg
.hp_pins
[0])
585 spec
->line_jack_present
=
586 detect_jacks(codec
, ARRAY_SIZE(spec
->autocfg
.line_out_pins
),
587 spec
->autocfg
.line_out_pins
);
588 if (!spec
->automute
|| !spec
->detect_line
)
590 update_speakers(codec
);
593 #define get_connection_index(codec, mux, nid) \
594 snd_hda_get_conn_index(codec, mux, nid, 0)
596 /* standard mic auto-switch helper */
597 static void alc_mic_automute(struct hda_codec
*codec
)
599 struct alc_spec
*spec
= codec
->spec
;
600 hda_nid_t
*pins
= spec
->imux_pins
;
602 if (!spec
->auto_mic
|| !spec
->auto_mic_valid_imux
)
604 if (snd_BUG_ON(!spec
->adc_nids
))
606 if (snd_BUG_ON(spec
->int_mic_idx
< 0 || spec
->ext_mic_idx
< 0))
609 if (snd_hda_jack_detect(codec
, pins
[spec
->ext_mic_idx
]))
610 alc_mux_select(codec
, 0, spec
->ext_mic_idx
, false);
611 else if (spec
->dock_mic_idx
>= 0 &&
612 snd_hda_jack_detect(codec
, pins
[spec
->dock_mic_idx
]))
613 alc_mux_select(codec
, 0, spec
->dock_mic_idx
, false);
615 alc_mux_select(codec
, 0, spec
->int_mic_idx
, false);
617 snd_hda_input_jack_report(codec
, pins
[spec
->ext_mic_idx
]);
618 if (spec
->dock_mic_idx
>= 0)
619 snd_hda_input_jack_report(codec
, pins
[spec
->dock_mic_idx
]);
622 /* unsolicited event for HP jack sensing */
623 static void alc_sku_unsol_event(struct hda_codec
*codec
, unsigned int res
)
625 if (codec
->vendor_id
== 0x10ec0880)
631 alc_hp_automute(codec
);
633 case ALC_FRONT_EVENT
:
634 alc_line_automute(codec
);
637 alc_mic_automute(codec
);
642 /* call init functions of standard auto-mute helpers */
643 static void alc_inithook(struct hda_codec
*codec
)
645 alc_hp_automute(codec
);
646 alc_line_automute(codec
);
647 alc_mic_automute(codec
);
650 /* additional initialization for ALC888 variants */
651 static void alc888_coef_init(struct hda_codec
*codec
)
655 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_COEF_INDEX
, 0);
656 tmp
= snd_hda_codec_read(codec
, 0x20, 0, AC_VERB_GET_PROC_COEF
, 0);
657 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_COEF_INDEX
, 7);
658 if ((tmp
& 0xf0) == 0x20)
660 snd_hda_codec_read(codec
, 0x20, 0,
661 AC_VERB_SET_PROC_COEF
, 0x830);
664 snd_hda_codec_read(codec
, 0x20, 0,
665 AC_VERB_SET_PROC_COEF
, 0x3030);
668 /* additional initialization for ALC889 variants */
669 static void alc889_coef_init(struct hda_codec
*codec
)
673 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_COEF_INDEX
, 7);
674 tmp
= snd_hda_codec_read(codec
, 0x20, 0, AC_VERB_GET_PROC_COEF
, 0);
675 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_COEF_INDEX
, 7);
676 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_PROC_COEF
, tmp
|0x2010);
679 /* turn on/off EAPD control (only if available) */
680 static void set_eapd(struct hda_codec
*codec
, hda_nid_t nid
, int on
)
682 if (get_wcaps_type(get_wcaps(codec
, nid
)) != AC_WID_PIN
)
684 if (snd_hda_query_pin_caps(codec
, nid
) & AC_PINCAP_EAPD
)
685 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_EAPD_BTLENABLE
,
689 /* turn on/off EAPD controls of the codec */
690 static void alc_auto_setup_eapd(struct hda_codec
*codec
, bool on
)
692 /* We currently only handle front, HP */
693 static hda_nid_t pins
[] = {
694 0x0f, 0x10, 0x14, 0x15, 0
697 for (p
= pins
; *p
; p
++)
698 set_eapd(codec
, *p
, on
);
701 /* generic shutup callback;
702 * just turning off EPAD and a little pause for avoiding pop-noise
704 static void alc_eapd_shutup(struct hda_codec
*codec
)
706 alc_auto_setup_eapd(codec
, false);
710 /* generic EAPD initialization */
711 static void alc_auto_init_amp(struct hda_codec
*codec
, int type
)
715 alc_auto_setup_eapd(codec
, true);
718 snd_hda_sequence_write(codec
, alc_gpio1_init_verbs
);
721 snd_hda_sequence_write(codec
, alc_gpio2_init_verbs
);
724 snd_hda_sequence_write(codec
, alc_gpio3_init_verbs
);
726 case ALC_INIT_DEFAULT
:
727 switch (codec
->vendor_id
) {
729 snd_hda_codec_write(codec
, 0x1a, 0,
730 AC_VERB_SET_COEF_INDEX
, 7);
731 tmp
= snd_hda_codec_read(codec
, 0x1a, 0,
732 AC_VERB_GET_PROC_COEF
, 0);
733 snd_hda_codec_write(codec
, 0x1a, 0,
734 AC_VERB_SET_COEF_INDEX
, 7);
735 snd_hda_codec_write(codec
, 0x1a, 0,
736 AC_VERB_SET_PROC_COEF
,
745 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
746 alc889_coef_init(codec
);
749 alc888_coef_init(codec
);
751 #if 0 /* XXX: This may cause the silent output on speaker on some machines */
754 snd_hda_codec_write(codec
, 0x20, 0,
755 AC_VERB_SET_COEF_INDEX
, 7);
756 tmp
= snd_hda_codec_read(codec
, 0x20, 0,
757 AC_VERB_GET_PROC_COEF
, 0);
758 snd_hda_codec_write(codec
, 0x20, 0,
759 AC_VERB_SET_COEF_INDEX
, 7);
760 snd_hda_codec_write(codec
, 0x20, 0,
761 AC_VERB_SET_PROC_COEF
,
771 * Auto-Mute mode mixer enum support
773 static int alc_automute_mode_info(struct snd_kcontrol
*kcontrol
,
774 struct snd_ctl_elem_info
*uinfo
)
776 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
777 struct alc_spec
*spec
= codec
->spec
;
778 static const char * const texts2
[] = {
779 "Disabled", "Enabled"
781 static const char * const texts3
[] = {
782 "Disabled", "Speaker Only", "Line-Out+Speaker"
784 const char * const *texts
;
786 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
788 if (spec
->automute_hp_lo
) {
789 uinfo
->value
.enumerated
.items
= 3;
792 uinfo
->value
.enumerated
.items
= 2;
795 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
)
796 uinfo
->value
.enumerated
.item
= uinfo
->value
.enumerated
.items
- 1;
797 strcpy(uinfo
->value
.enumerated
.name
,
798 texts
[uinfo
->value
.enumerated
.item
]);
802 static int alc_automute_mode_get(struct snd_kcontrol
*kcontrol
,
803 struct snd_ctl_elem_value
*ucontrol
)
805 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
806 struct alc_spec
*spec
= codec
->spec
;
810 else if (!spec
->automute_hp_lo
|| !spec
->automute_lines
)
814 ucontrol
->value
.enumerated
.item
[0] = val
;
818 static int alc_automute_mode_put(struct snd_kcontrol
*kcontrol
,
819 struct snd_ctl_elem_value
*ucontrol
)
821 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
822 struct alc_spec
*spec
= codec
->spec
;
824 switch (ucontrol
->value
.enumerated
.item
[0]) {
831 if (spec
->automute
&&
832 (!spec
->automute_hp_lo
|| !spec
->automute_lines
))
835 spec
->automute_lines
= 0;
838 if (!spec
->automute_hp_lo
)
840 if (spec
->automute
&& spec
->automute_lines
)
843 spec
->automute_lines
= 1;
848 update_speakers(codec
);
852 static const struct snd_kcontrol_new alc_automute_mode_enum
= {
853 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
854 .name
= "Auto-Mute Mode",
855 .info
= alc_automute_mode_info
,
856 .get
= alc_automute_mode_get
,
857 .put
= alc_automute_mode_put
,
860 static struct snd_kcontrol_new
*alc_kcontrol_new(struct alc_spec
*spec
)
862 snd_array_init(&spec
->kctls
, sizeof(struct snd_kcontrol_new
), 32);
863 return snd_array_new(&spec
->kctls
);
866 static int alc_add_automute_mode_enum(struct hda_codec
*codec
)
868 struct alc_spec
*spec
= codec
->spec
;
869 struct snd_kcontrol_new
*knew
;
871 knew
= alc_kcontrol_new(spec
);
874 *knew
= alc_automute_mode_enum
;
875 knew
->name
= kstrdup("Auto-Mute Mode", GFP_KERNEL
);
882 * Check the availability of HP/line-out auto-mute;
883 * Set up appropriately if really supported
885 static void alc_init_auto_hp(struct hda_codec
*codec
)
887 struct alc_spec
*spec
= codec
->spec
;
888 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
894 if (cfg
->line_out_pins
[0])
896 if (cfg
->speaker_pins
[0])
898 if (present
< 2) /* need two different output types */
901 spec
->automute_hp_lo
= 1; /* both HP and LO automute */
903 if (!cfg
->speaker_pins
[0] &&
904 cfg
->line_out_type
== AUTO_PIN_SPEAKER_OUT
) {
905 memcpy(cfg
->speaker_pins
, cfg
->line_out_pins
,
906 sizeof(cfg
->speaker_pins
));
907 cfg
->speaker_outs
= cfg
->line_outs
;
910 if (!cfg
->hp_pins
[0] &&
911 cfg
->line_out_type
== AUTO_PIN_HP_OUT
) {
912 memcpy(cfg
->hp_pins
, cfg
->line_out_pins
,
913 sizeof(cfg
->hp_pins
));
914 cfg
->hp_outs
= cfg
->line_outs
;
917 for (i
= 0; i
< cfg
->hp_outs
; i
++) {
918 hda_nid_t nid
= cfg
->hp_pins
[i
];
919 if (!is_jack_detectable(codec
, nid
))
921 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
923 snd_hda_codec_write_cache(codec
, nid
, 0,
924 AC_VERB_SET_UNSOLICITED_ENABLE
,
925 AC_USRSP_EN
| ALC_HP_EVENT
);
927 spec
->automute_mode
= ALC_AUTOMUTE_PIN
;
929 if (spec
->automute
&& cfg
->line_out_pins
[0] &&
930 cfg
->speaker_pins
[0] &&
931 cfg
->line_out_pins
[0] != cfg
->hp_pins
[0] &&
932 cfg
->line_out_pins
[0] != cfg
->speaker_pins
[0]) {
933 for (i
= 0; i
< cfg
->line_outs
; i
++) {
934 hda_nid_t nid
= cfg
->line_out_pins
[i
];
935 if (!is_jack_detectable(codec
, nid
))
937 snd_printdd("realtek: Enable Line-Out auto-muting "
938 "on NID 0x%x\n", nid
);
939 snd_hda_codec_write_cache(codec
, nid
, 0,
940 AC_VERB_SET_UNSOLICITED_ENABLE
,
941 AC_USRSP_EN
| ALC_FRONT_EVENT
);
942 spec
->detect_line
= 1;
944 spec
->automute_lines
= spec
->detect_line
;
947 if (spec
->automute
) {
948 /* create a control for automute mode */
949 alc_add_automute_mode_enum(codec
);
950 spec
->unsol_event
= alc_sku_unsol_event
;
954 /* return the position of NID in the list, or -1 if not found */
955 static int find_idx_in_nid_list(hda_nid_t nid
, const hda_nid_t
*list
, int nums
)
958 for (i
= 0; i
< nums
; i
++)
964 /* check whether dynamic ADC-switching is available */
965 static bool alc_check_dyn_adc_switch(struct hda_codec
*codec
)
967 struct alc_spec
*spec
= codec
->spec
;
968 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
972 if (imux
!= spec
->input_mux
) /* no dynamic imux? */
975 for (n
= 0; n
< spec
->num_adc_nids
; n
++) {
976 cap
= spec
->private_capsrc_nids
[n
];
977 for (i
= 0; i
< imux
->num_items
; i
++) {
978 pin
= spec
->imux_pins
[i
];
981 if (get_connection_index(codec
, cap
, pin
) < 0)
984 if (i
>= imux
->num_items
)
985 return true; /* no ADC-switch is needed */
988 for (i
= 0; i
< imux
->num_items
; i
++) {
989 pin
= spec
->imux_pins
[i
];
990 for (n
= 0; n
< spec
->num_adc_nids
; n
++) {
991 cap
= spec
->private_capsrc_nids
[n
];
992 idx
= get_connection_index(codec
, cap
, pin
);
994 imux
->items
[i
].index
= idx
;
995 spec
->dyn_adc_idx
[i
] = n
;
1001 snd_printdd("realtek: enabling ADC switching\n");
1002 spec
->dyn_adc_switch
= 1;
1006 /* rebuild imux for matching with the given auto-mic pins (if not yet) */
1007 static bool alc_rebuild_imux_for_auto_mic(struct hda_codec
*codec
)
1009 struct alc_spec
*spec
= codec
->spec
;
1010 struct hda_input_mux
*imux
;
1011 static char * const texts
[3] = {
1012 "Mic", "Internal Mic", "Dock Mic"
1016 if (!spec
->auto_mic
)
1018 imux
= &spec
->private_imux
[0];
1019 if (spec
->input_mux
== imux
)
1021 spec
->imux_pins
[0] = spec
->ext_mic_pin
;
1022 spec
->imux_pins
[1] = spec
->int_mic_pin
;
1023 spec
->imux_pins
[2] = spec
->dock_mic_pin
;
1024 for (i
= 0; i
< 3; i
++) {
1025 strcpy(imux
->items
[i
].label
, texts
[i
]);
1026 if (spec
->imux_pins
[i
])
1027 imux
->num_items
= i
+ 1;
1029 spec
->num_mux_defs
= 1;
1030 spec
->input_mux
= imux
;
1034 /* check whether all auto-mic pins are valid; setup indices if OK */
1035 static bool alc_auto_mic_check_imux(struct hda_codec
*codec
)
1037 struct alc_spec
*spec
= codec
->spec
;
1038 const struct hda_input_mux
*imux
;
1040 if (!spec
->auto_mic
)
1042 if (spec
->auto_mic_valid_imux
)
1043 return true; /* already checked */
1045 /* fill up imux indices */
1046 if (!alc_check_dyn_adc_switch(codec
)) {
1051 imux
= spec
->input_mux
;
1052 spec
->ext_mic_idx
= find_idx_in_nid_list(spec
->ext_mic_pin
,
1053 spec
->imux_pins
, imux
->num_items
);
1054 spec
->int_mic_idx
= find_idx_in_nid_list(spec
->int_mic_pin
,
1055 spec
->imux_pins
, imux
->num_items
);
1056 spec
->dock_mic_idx
= find_idx_in_nid_list(spec
->dock_mic_pin
,
1057 spec
->imux_pins
, imux
->num_items
);
1058 if (spec
->ext_mic_idx
< 0 || spec
->int_mic_idx
< 0) {
1060 return false; /* no corresponding imux */
1063 snd_hda_codec_write_cache(codec
, spec
->ext_mic_pin
, 0,
1064 AC_VERB_SET_UNSOLICITED_ENABLE
,
1065 AC_USRSP_EN
| ALC_MIC_EVENT
);
1066 if (spec
->dock_mic_pin
)
1067 snd_hda_codec_write_cache(codec
, spec
->dock_mic_pin
, 0,
1068 AC_VERB_SET_UNSOLICITED_ENABLE
,
1069 AC_USRSP_EN
| ALC_MIC_EVENT
);
1071 spec
->auto_mic_valid_imux
= 1;
1077 * Check the availability of auto-mic switch;
1078 * Set up if really supported
1080 static void alc_init_auto_mic(struct hda_codec
*codec
)
1082 struct alc_spec
*spec
= codec
->spec
;
1083 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
1084 hda_nid_t fixed
, ext
, dock
;
1087 spec
->ext_mic_idx
= spec
->int_mic_idx
= spec
->dock_mic_idx
= -1;
1089 fixed
= ext
= dock
= 0;
1090 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
1091 hda_nid_t nid
= cfg
->inputs
[i
].pin
;
1092 unsigned int defcfg
;
1093 defcfg
= snd_hda_codec_get_pincfg(codec
, nid
);
1094 switch (snd_hda_get_input_pin_attr(defcfg
)) {
1095 case INPUT_PIN_ATTR_INT
:
1097 return; /* already occupied */
1098 if (cfg
->inputs
[i
].type
!= AUTO_PIN_MIC
)
1099 return; /* invalid type */
1102 case INPUT_PIN_ATTR_UNUSED
:
1103 return; /* invalid entry */
1104 case INPUT_PIN_ATTR_DOCK
:
1106 return; /* already occupied */
1107 if (cfg
->inputs
[i
].type
> AUTO_PIN_LINE_IN
)
1108 return; /* invalid type */
1113 return; /* already occupied */
1114 if (cfg
->inputs
[i
].type
!= AUTO_PIN_MIC
)
1115 return; /* invalid type */
1126 if (!is_jack_detectable(codec
, ext
))
1127 return; /* no unsol support */
1128 if (dock
&& !is_jack_detectable(codec
, dock
))
1129 return; /* no unsol support */
1131 /* check imux indices */
1132 spec
->ext_mic_pin
= ext
;
1133 spec
->int_mic_pin
= fixed
;
1134 spec
->dock_mic_pin
= dock
;
1137 if (!alc_auto_mic_check_imux(codec
))
1140 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1142 spec
->unsol_event
= alc_sku_unsol_event
;
1145 /* check the availabilities of auto-mute and auto-mic switches */
1146 static void alc_auto_check_switches(struct hda_codec
*codec
)
1148 alc_init_auto_hp(codec
);
1149 alc_init_auto_mic(codec
);
1153 * Realtek SSID verification
1156 /* Could be any non-zero and even value. When used as fixup, tells
1157 * the driver to ignore any present sku defines.
1159 #define ALC_FIXUP_SKU_IGNORE (2)
1161 static int alc_auto_parse_customize_define(struct hda_codec
*codec
)
1163 unsigned int ass
, tmp
, i
;
1165 struct alc_spec
*spec
= codec
->spec
;
1167 spec
->cdefine
.enable_pcbeep
= 1; /* assume always enabled */
1169 if (spec
->cdefine
.fixup
) {
1170 ass
= spec
->cdefine
.sku_cfg
;
1171 if (ass
== ALC_FIXUP_SKU_IGNORE
)
1176 ass
= codec
->subsystem_id
& 0xffff;
1177 if (ass
!= codec
->bus
->pci
->subsystem_device
&& (ass
& 1))
1181 if (codec
->vendor_id
== 0x10ec0260)
1183 ass
= snd_hda_codec_get_pincfg(codec
, nid
);
1186 printk(KERN_INFO
"hda_codec: %s: SKU not ready 0x%08x\n",
1187 codec
->chip_name
, ass
);
1193 for (i
= 1; i
< 16; i
++) {
1197 if (((ass
>> 16) & 0xf) != tmp
)
1200 spec
->cdefine
.port_connectivity
= ass
>> 30;
1201 spec
->cdefine
.enable_pcbeep
= (ass
& 0x100000) >> 20;
1202 spec
->cdefine
.check_sum
= (ass
>> 16) & 0xf;
1203 spec
->cdefine
.customization
= ass
>> 8;
1205 spec
->cdefine
.sku_cfg
= ass
;
1206 spec
->cdefine
.external_amp
= (ass
& 0x38) >> 3;
1207 spec
->cdefine
.platform_type
= (ass
& 0x4) >> 2;
1208 spec
->cdefine
.swap
= (ass
& 0x2) >> 1;
1209 spec
->cdefine
.override
= ass
& 0x1;
1211 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1212 nid
, spec
->cdefine
.sku_cfg
);
1213 snd_printd("SKU: port_connectivity=0x%x\n",
1214 spec
->cdefine
.port_connectivity
);
1215 snd_printd("SKU: enable_pcbeep=0x%x\n", spec
->cdefine
.enable_pcbeep
);
1216 snd_printd("SKU: check_sum=0x%08x\n", spec
->cdefine
.check_sum
);
1217 snd_printd("SKU: customization=0x%08x\n", spec
->cdefine
.customization
);
1218 snd_printd("SKU: external_amp=0x%x\n", spec
->cdefine
.external_amp
);
1219 snd_printd("SKU: platform_type=0x%x\n", spec
->cdefine
.platform_type
);
1220 snd_printd("SKU: swap=0x%x\n", spec
->cdefine
.swap
);
1221 snd_printd("SKU: override=0x%x\n", spec
->cdefine
.override
);
1226 /* return true if the given NID is found in the list */
1227 static bool found_in_nid_list(hda_nid_t nid
, const hda_nid_t
*list
, int nums
)
1229 return find_idx_in_nid_list(nid
, list
, nums
) >= 0;
1232 /* check subsystem ID and set up device-specific initialization;
1233 * return 1 if initialized, 0 if invalid SSID
1235 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1236 * 31 ~ 16 : Manufacture ID
1238 * 7 ~ 0 : Assembly ID
1239 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1241 static int alc_subsystem_id(struct hda_codec
*codec
,
1242 hda_nid_t porta
, hda_nid_t porte
,
1243 hda_nid_t portd
, hda_nid_t porti
)
1245 unsigned int ass
, tmp
, i
;
1247 struct alc_spec
*spec
= codec
->spec
;
1249 if (spec
->cdefine
.fixup
) {
1250 ass
= spec
->cdefine
.sku_cfg
;
1251 if (ass
== ALC_FIXUP_SKU_IGNORE
)
1256 ass
= codec
->subsystem_id
& 0xffff;
1257 if ((ass
!= codec
->bus
->pci
->subsystem_device
) && (ass
& 1))
1260 /* invalid SSID, check the special NID pin defcfg instead */
1262 * 31~30 : port connectivity
1265 * 19~16 : Check sum (15:1)
1270 if (codec
->vendor_id
== 0x10ec0260)
1272 ass
= snd_hda_codec_get_pincfg(codec
, nid
);
1273 snd_printd("realtek: No valid SSID, "
1274 "checking pincfg 0x%08x for NID 0x%x\n",
1278 if ((ass
>> 30) != 1) /* no physical connection */
1283 for (i
= 1; i
< 16; i
++) {
1287 if (((ass
>> 16) & 0xf) != tmp
)
1290 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1291 ass
& 0xffff, codec
->vendor_id
);
1295 * 2 : 0 --> Desktop, 1 --> Laptop
1296 * 3~5 : External Amplifier control
1299 tmp
= (ass
& 0x38) >> 3; /* external Amp control */
1302 spec
->init_amp
= ALC_INIT_GPIO1
;
1305 spec
->init_amp
= ALC_INIT_GPIO2
;
1308 spec
->init_amp
= ALC_INIT_GPIO3
;
1312 spec
->init_amp
= ALC_INIT_DEFAULT
;
1316 /* is laptop or Desktop and enable the function "Mute internal speaker
1317 * when the external headphone out jack is plugged"
1319 if (!(ass
& 0x8000))
1322 * 10~8 : Jack location
1323 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1325 * 15 : 1 --> enable the function "Mute internal speaker
1326 * when the external headphone out jack is plugged"
1328 if (!spec
->autocfg
.hp_pins
[0] &&
1329 !(spec
->autocfg
.line_out_pins
[0] &&
1330 spec
->autocfg
.line_out_type
== AUTO_PIN_HP_OUT
)) {
1332 tmp
= (ass
>> 11) & 0x3; /* HP to chassis */
1343 if (found_in_nid_list(nid
, spec
->autocfg
.line_out_pins
,
1344 spec
->autocfg
.line_outs
))
1346 spec
->autocfg
.hp_pins
[0] = nid
;
1351 /* Check the validity of ALC subsystem-id
1352 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1353 static void alc_ssid_check(struct hda_codec
*codec
, const hda_nid_t
*ports
)
1355 if (!alc_subsystem_id(codec
, ports
[0], ports
[1], ports
[2], ports
[3])) {
1356 struct alc_spec
*spec
= codec
->spec
;
1357 snd_printd("realtek: "
1358 "Enable default setup for auto mode as fallback\n");
1359 spec
->init_amp
= ALC_INIT_DEFAULT
;
1364 * Fix-up pin default configurations and add default verbs
1372 struct alc_model_fixup
{
1383 const struct alc_pincfg
*pins
;
1384 const struct hda_verb
*verbs
;
1385 void (*func
)(struct hda_codec
*codec
,
1386 const struct alc_fixup
*fix
,
1400 ALC_FIXUP_ACT_PRE_PROBE
,
1401 ALC_FIXUP_ACT_PROBE
,
1405 static void alc_apply_fixup(struct hda_codec
*codec
, int action
)
1407 struct alc_spec
*spec
= codec
->spec
;
1408 int id
= spec
->fixup_id
;
1409 #ifdef CONFIG_SND_DEBUG_VERBOSE
1410 const char *modelname
= spec
->fixup_name
;
1414 if (!spec
->fixup_list
)
1418 const struct alc_fixup
*fix
= spec
->fixup_list
+ id
;
1419 const struct alc_pincfg
*cfg
;
1421 switch (fix
->type
) {
1423 if (action
!= ALC_FIXUP_ACT_PRE_PROBE
|| !fix
->v
.sku
)
1425 snd_printdd(KERN_INFO
"hda_codec: %s: "
1426 "Apply sku override for %s\n",
1427 codec
->chip_name
, modelname
);
1428 spec
->cdefine
.sku_cfg
= fix
->v
.sku
;
1429 spec
->cdefine
.fixup
= 1;
1431 case ALC_FIXUP_PINS
:
1433 if (action
!= ALC_FIXUP_ACT_PRE_PROBE
|| !cfg
)
1435 snd_printdd(KERN_INFO
"hda_codec: %s: "
1436 "Apply pincfg for %s\n",
1437 codec
->chip_name
, modelname
);
1438 for (; cfg
->nid
; cfg
++)
1439 snd_hda_codec_set_pincfg(codec
, cfg
->nid
,
1442 case ALC_FIXUP_VERBS
:
1443 if (action
!= ALC_FIXUP_ACT_PROBE
|| !fix
->v
.verbs
)
1445 snd_printdd(KERN_INFO
"hda_codec: %s: "
1446 "Apply fix-verbs for %s\n",
1447 codec
->chip_name
, modelname
);
1448 add_verb(codec
->spec
, fix
->v
.verbs
);
1450 case ALC_FIXUP_FUNC
:
1453 snd_printdd(KERN_INFO
"hda_codec: %s: "
1454 "Apply fix-func for %s\n",
1455 codec
->chip_name
, modelname
);
1456 fix
->v
.func(codec
, fix
, action
);
1459 snd_printk(KERN_ERR
"hda_codec: %s: "
1460 "Invalid fixup type %d\n",
1461 codec
->chip_name
, fix
->type
);
1472 static void alc_pick_fixup(struct hda_codec
*codec
,
1473 const struct alc_model_fixup
*models
,
1474 const struct snd_pci_quirk
*quirk
,
1475 const struct alc_fixup
*fixlist
)
1477 struct alc_spec
*spec
= codec
->spec
;
1479 const char *name
= NULL
;
1481 if (codec
->modelname
&& models
) {
1482 while (models
->name
) {
1483 if (!strcmp(codec
->modelname
, models
->name
)) {
1485 name
= models
->name
;
1492 quirk
= snd_pci_quirk_lookup(codec
->bus
->pci
, quirk
);
1495 #ifdef CONFIG_SND_DEBUG_VERBOSE
1501 spec
->fixup_id
= id
;
1503 spec
->fixup_list
= fixlist
;
1504 spec
->fixup_name
= name
;
1509 * COEF access helper functions
1511 static int alc_read_coef_idx(struct hda_codec
*codec
,
1512 unsigned int coef_idx
)
1515 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_COEF_INDEX
,
1517 val
= snd_hda_codec_read(codec
, 0x20, 0,
1518 AC_VERB_GET_PROC_COEF
, 0);
1522 static void alc_write_coef_idx(struct hda_codec
*codec
, unsigned int coef_idx
,
1523 unsigned int coef_val
)
1525 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_COEF_INDEX
,
1527 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_PROC_COEF
,
1532 * Digital I/O handling
1535 /* set right pin controls for digital I/O */
1536 static void alc_auto_init_digital(struct hda_codec
*codec
)
1538 struct alc_spec
*spec
= codec
->spec
;
1542 for (i
= 0; i
< spec
->autocfg
.dig_outs
; i
++) {
1543 pin
= spec
->autocfg
.dig_out_pins
[i
];
1546 snd_hda_codec_write(codec
, pin
, 0,
1547 AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
);
1549 dac
= spec
->multiout
.dig_out_nid
;
1551 dac
= spec
->slave_dig_outs
[i
- 1];
1552 if (!dac
|| !(get_wcaps(codec
, dac
) & AC_WCAP_OUT_AMP
))
1554 snd_hda_codec_write(codec
, dac
, 0,
1555 AC_VERB_SET_AMP_GAIN_MUTE
,
1558 pin
= spec
->autocfg
.dig_in_pin
;
1560 snd_hda_codec_write(codec
, pin
, 0,
1561 AC_VERB_SET_PIN_WIDGET_CONTROL
,
1565 /* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1566 static void alc_auto_parse_digital(struct hda_codec
*codec
)
1568 struct alc_spec
*spec
= codec
->spec
;
1572 /* support multiple SPDIFs; the secondary is set up as a slave */
1574 for (i
= 0; i
< spec
->autocfg
.dig_outs
; i
++) {
1576 err
= snd_hda_get_connections(codec
,
1577 spec
->autocfg
.dig_out_pins
[i
],
1578 conn
, ARRAY_SIZE(conn
));
1581 dig_nid
= conn
[0]; /* assume the first element is audio-out */
1583 spec
->multiout
.dig_out_nid
= dig_nid
;
1584 spec
->dig_out_type
= spec
->autocfg
.dig_out_type
[0];
1586 spec
->multiout
.slave_dig_outs
= spec
->slave_dig_outs
;
1587 if (nums
>= ARRAY_SIZE(spec
->slave_dig_outs
) - 1)
1589 spec
->slave_dig_outs
[nums
- 1] = dig_nid
;
1594 if (spec
->autocfg
.dig_in_pin
) {
1595 dig_nid
= codec
->start_nid
;
1596 for (i
= 0; i
< codec
->num_nodes
; i
++, dig_nid
++) {
1597 unsigned int wcaps
= get_wcaps(codec
, dig_nid
);
1598 if (get_wcaps_type(wcaps
) != AC_WID_AUD_IN
)
1600 if (!(wcaps
& AC_WCAP_DIGITAL
))
1602 if (!(wcaps
& AC_WCAP_CONN_LIST
))
1604 err
= get_connection_index(codec
, dig_nid
,
1605 spec
->autocfg
.dig_in_pin
);
1607 spec
->dig_in_nid
= dig_nid
;
1615 * capture mixer elements
1617 static int alc_cap_vol_info(struct snd_kcontrol
*kcontrol
,
1618 struct snd_ctl_elem_info
*uinfo
)
1620 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1621 struct alc_spec
*spec
= codec
->spec
;
1625 mutex_lock(&codec
->control_mutex
);
1626 if (spec
->vol_in_capsrc
)
1627 val
= HDA_COMPOSE_AMP_VAL(spec
->capsrc_nids
[0], 3, 0, HDA_OUTPUT
);
1629 val
= HDA_COMPOSE_AMP_VAL(spec
->adc_nids
[0], 3, 0, HDA_INPUT
);
1630 kcontrol
->private_value
= val
;
1631 err
= snd_hda_mixer_amp_volume_info(kcontrol
, uinfo
);
1632 mutex_unlock(&codec
->control_mutex
);
1636 static int alc_cap_vol_tlv(struct snd_kcontrol
*kcontrol
, int op_flag
,
1637 unsigned int size
, unsigned int __user
*tlv
)
1639 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1640 struct alc_spec
*spec
= codec
->spec
;
1644 mutex_lock(&codec
->control_mutex
);
1645 if (spec
->vol_in_capsrc
)
1646 val
= HDA_COMPOSE_AMP_VAL(spec
->capsrc_nids
[0], 3, 0, HDA_OUTPUT
);
1648 val
= HDA_COMPOSE_AMP_VAL(spec
->adc_nids
[0], 3, 0, HDA_INPUT
);
1649 kcontrol
->private_value
= val
;
1650 err
= snd_hda_mixer_amp_tlv(kcontrol
, op_flag
, size
, tlv
);
1651 mutex_unlock(&codec
->control_mutex
);
1655 typedef int (*getput_call_t
)(struct snd_kcontrol
*kcontrol
,
1656 struct snd_ctl_elem_value
*ucontrol
);
1658 static int alc_cap_getput_caller(struct snd_kcontrol
*kcontrol
,
1659 struct snd_ctl_elem_value
*ucontrol
,
1660 getput_call_t func
, bool check_adc_switch
)
1662 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1663 struct alc_spec
*spec
= codec
->spec
;
1666 mutex_lock(&codec
->control_mutex
);
1667 if (check_adc_switch
&& spec
->dyn_adc_switch
) {
1668 for (i
= 0; i
< spec
->num_adc_nids
; i
++) {
1669 kcontrol
->private_value
=
1670 HDA_COMPOSE_AMP_VAL(spec
->adc_nids
[i
],
1672 err
= func(kcontrol
, ucontrol
);
1677 i
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
1678 if (spec
->vol_in_capsrc
)
1679 kcontrol
->private_value
=
1680 HDA_COMPOSE_AMP_VAL(spec
->capsrc_nids
[i
],
1683 kcontrol
->private_value
=
1684 HDA_COMPOSE_AMP_VAL(spec
->adc_nids
[i
],
1686 err
= func(kcontrol
, ucontrol
);
1689 mutex_unlock(&codec
->control_mutex
);
1693 static int alc_cap_vol_get(struct snd_kcontrol
*kcontrol
,
1694 struct snd_ctl_elem_value
*ucontrol
)
1696 return alc_cap_getput_caller(kcontrol
, ucontrol
,
1697 snd_hda_mixer_amp_volume_get
, false);
1700 static int alc_cap_vol_put(struct snd_kcontrol
*kcontrol
,
1701 struct snd_ctl_elem_value
*ucontrol
)
1703 return alc_cap_getput_caller(kcontrol
, ucontrol
,
1704 snd_hda_mixer_amp_volume_put
, true);
1707 /* capture mixer elements */
1708 #define alc_cap_sw_info snd_ctl_boolean_stereo_info
1710 static int alc_cap_sw_get(struct snd_kcontrol
*kcontrol
,
1711 struct snd_ctl_elem_value
*ucontrol
)
1713 return alc_cap_getput_caller(kcontrol
, ucontrol
,
1714 snd_hda_mixer_amp_switch_get
, false);
1717 static int alc_cap_sw_put(struct snd_kcontrol
*kcontrol
,
1718 struct snd_ctl_elem_value
*ucontrol
)
1720 return alc_cap_getput_caller(kcontrol
, ucontrol
,
1721 snd_hda_mixer_amp_switch_put
, true);
1724 #define _DEFINE_CAPMIX(num) \
1726 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1727 .name = "Capture Switch", \
1728 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1730 .info = alc_cap_sw_info, \
1731 .get = alc_cap_sw_get, \
1732 .put = alc_cap_sw_put, \
1735 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1736 .name = "Capture Volume", \
1737 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1738 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1739 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1741 .info = alc_cap_vol_info, \
1742 .get = alc_cap_vol_get, \
1743 .put = alc_cap_vol_put, \
1744 .tlv = { .c = alc_cap_vol_tlv }, \
1747 #define _DEFINE_CAPSRC(num) \
1749 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1750 /* .name = "Capture Source", */ \
1751 .name = "Input Source", \
1753 .info = alc_mux_enum_info, \
1754 .get = alc_mux_enum_get, \
1755 .put = alc_mux_enum_put, \
1758 #define DEFINE_CAPMIX(num) \
1759 static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
1760 _DEFINE_CAPMIX(num), \
1761 _DEFINE_CAPSRC(num), \
1765 #define DEFINE_CAPMIX_NOSRC(num) \
1766 static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
1767 _DEFINE_CAPMIX(num), \
1771 /* up to three ADCs */
1775 DEFINE_CAPMIX_NOSRC(1);
1776 DEFINE_CAPMIX_NOSRC(2);
1777 DEFINE_CAPMIX_NOSRC(3);
1780 * virtual master controls
1784 * slave controls for virtual master
1786 static const char * const alc_slave_vols
[] = {
1787 "Front Playback Volume",
1788 "Surround Playback Volume",
1789 "Center Playback Volume",
1790 "LFE Playback Volume",
1791 "Side Playback Volume",
1792 "Headphone Playback Volume",
1793 "Speaker Playback Volume",
1794 "Mono Playback Volume",
1795 "Line-Out Playback Volume",
1796 "PCM Playback Volume",
1800 static const char * const alc_slave_sws
[] = {
1801 "Front Playback Switch",
1802 "Surround Playback Switch",
1803 "Center Playback Switch",
1804 "LFE Playback Switch",
1805 "Side Playback Switch",
1806 "Headphone Playback Switch",
1807 "Speaker Playback Switch",
1808 "Mono Playback Switch",
1809 "IEC958 Playback Switch",
1810 "Line-Out Playback Switch",
1811 "PCM Playback Switch",
1816 * build control elements
1819 #define NID_MAPPING (-1)
1821 #define SUBDEV_SPEAKER_ (0 << 6)
1822 #define SUBDEV_HP_ (1 << 6)
1823 #define SUBDEV_LINE_ (2 << 6)
1824 #define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1825 #define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1826 #define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1828 static void alc_free_kctls(struct hda_codec
*codec
);
1830 #ifdef CONFIG_SND_HDA_INPUT_BEEP
1831 /* additional beep mixers; the actual parameters are overwritten at build */
1832 static const struct snd_kcontrol_new alc_beep_mixer
[] = {
1833 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT
),
1834 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT
),
1839 static int alc_build_controls(struct hda_codec
*codec
)
1841 struct alc_spec
*spec
= codec
->spec
;
1842 struct snd_kcontrol
*kctl
= NULL
;
1843 const struct snd_kcontrol_new
*knew
;
1848 for (i
= 0; i
< spec
->num_mixers
; i
++) {
1849 err
= snd_hda_add_new_ctls(codec
, spec
->mixers
[i
]);
1853 if (spec
->cap_mixer
) {
1854 err
= snd_hda_add_new_ctls(codec
, spec
->cap_mixer
);
1858 if (spec
->multiout
.dig_out_nid
) {
1859 err
= snd_hda_create_spdif_out_ctls(codec
,
1860 spec
->multiout
.dig_out_nid
,
1861 spec
->multiout
.dig_out_nid
);
1864 if (!spec
->no_analog
) {
1865 err
= snd_hda_create_spdif_share_sw(codec
,
1869 spec
->multiout
.share_spdif
= 1;
1872 if (spec
->dig_in_nid
) {
1873 err
= snd_hda_create_spdif_in_ctls(codec
, spec
->dig_in_nid
);
1878 #ifdef CONFIG_SND_HDA_INPUT_BEEP
1879 /* create beep controls if needed */
1880 if (spec
->beep_amp
) {
1881 const struct snd_kcontrol_new
*knew
;
1882 for (knew
= alc_beep_mixer
; knew
->name
; knew
++) {
1883 struct snd_kcontrol
*kctl
;
1884 kctl
= snd_ctl_new1(knew
, codec
);
1887 kctl
->private_value
= spec
->beep_amp
;
1888 err
= snd_hda_ctl_add(codec
, 0, kctl
);
1895 /* if we have no master control, let's create it */
1896 if (!spec
->no_analog
&&
1897 !snd_hda_find_mixer_ctl(codec
, "Master Playback Volume")) {
1898 unsigned int vmaster_tlv
[4];
1899 snd_hda_set_vmaster_tlv(codec
, spec
->vmaster_nid
,
1900 HDA_OUTPUT
, vmaster_tlv
);
1901 err
= snd_hda_add_vmaster(codec
, "Master Playback Volume",
1902 vmaster_tlv
, alc_slave_vols
);
1906 if (!spec
->no_analog
&&
1907 !snd_hda_find_mixer_ctl(codec
, "Master Playback Switch")) {
1908 err
= snd_hda_add_vmaster(codec
, "Master Playback Switch",
1909 NULL
, alc_slave_sws
);
1914 /* assign Capture Source enums to NID */
1915 if (spec
->capsrc_nids
|| spec
->adc_nids
) {
1916 kctl
= snd_hda_find_mixer_ctl(codec
, "Capture Source");
1918 kctl
= snd_hda_find_mixer_ctl(codec
, "Input Source");
1919 for (i
= 0; kctl
&& i
< kctl
->count
; i
++) {
1920 const hda_nid_t
*nids
= spec
->capsrc_nids
;
1922 nids
= spec
->adc_nids
;
1923 err
= snd_hda_add_nid(codec
, kctl
, i
, nids
[i
]);
1928 if (spec
->cap_mixer
&& spec
->adc_nids
) {
1929 const char *kname
= kctl
? kctl
->id
.name
: NULL
;
1930 for (knew
= spec
->cap_mixer
; knew
->name
; knew
++) {
1931 if (kname
&& strcmp(knew
->name
, kname
) == 0)
1933 kctl
= snd_hda_find_mixer_ctl(codec
, knew
->name
);
1934 for (i
= 0; kctl
&& i
< kctl
->count
; i
++) {
1935 err
= snd_hda_add_nid(codec
, kctl
, i
,
1943 /* other nid->control mapping */
1944 for (i
= 0; i
< spec
->num_mixers
; i
++) {
1945 for (knew
= spec
->mixers
[i
]; knew
->name
; knew
++) {
1946 if (knew
->iface
!= NID_MAPPING
)
1948 kctl
= snd_hda_find_mixer_ctl(codec
, knew
->name
);
1951 u
= knew
->subdevice
;
1952 for (j
= 0; j
< 4; j
++, u
>>= 8) {
1957 case SUBDEV_SPEAKER_
:
1958 nid
= spec
->autocfg
.speaker_pins
[nid
];
1961 nid
= spec
->autocfg
.line_out_pins
[nid
];
1964 nid
= spec
->autocfg
.hp_pins
[nid
];
1969 err
= snd_hda_add_nid(codec
, kctl
, 0, nid
);
1973 u
= knew
->private_value
;
1974 for (j
= 0; j
< 4; j
++, u
>>= 8) {
1978 err
= snd_hda_add_nid(codec
, kctl
, 0, nid
);
1985 alc_free_kctls(codec
); /* no longer needed */
1995 static void alc_init_special_input_src(struct hda_codec
*codec
);
1997 static int alc_init(struct hda_codec
*codec
)
1999 struct alc_spec
*spec
= codec
->spec
;
2003 alc_auto_init_amp(codec
, spec
->init_amp
);
2005 for (i
= 0; i
< spec
->num_init_verbs
; i
++)
2006 snd_hda_sequence_write(codec
, spec
->init_verbs
[i
]);
2007 alc_init_special_input_src(codec
);
2009 if (spec
->init_hook
)
2010 spec
->init_hook(codec
);
2012 alc_apply_fixup(codec
, ALC_FIXUP_ACT_INIT
);
2014 hda_call_check_power_status(codec
, 0x01);
2018 static void alc_unsol_event(struct hda_codec
*codec
, unsigned int res
)
2020 struct alc_spec
*spec
= codec
->spec
;
2022 if (spec
->unsol_event
)
2023 spec
->unsol_event(codec
, res
);
2026 #ifdef CONFIG_SND_HDA_POWER_SAVE
2027 static int alc_check_power_status(struct hda_codec
*codec
, hda_nid_t nid
)
2029 struct alc_spec
*spec
= codec
->spec
;
2030 return snd_hda_check_amp_list_power(codec
, &spec
->loopback
, nid
);
2035 * Analog playback callbacks
2037 static int alc_playback_pcm_open(struct hda_pcm_stream
*hinfo
,
2038 struct hda_codec
*codec
,
2039 struct snd_pcm_substream
*substream
)
2041 struct alc_spec
*spec
= codec
->spec
;
2042 return snd_hda_multi_out_analog_open(codec
, &spec
->multiout
, substream
,
2046 static int alc_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
2047 struct hda_codec
*codec
,
2048 unsigned int stream_tag
,
2049 unsigned int format
,
2050 struct snd_pcm_substream
*substream
)
2052 struct alc_spec
*spec
= codec
->spec
;
2053 return snd_hda_multi_out_analog_prepare(codec
, &spec
->multiout
,
2054 stream_tag
, format
, substream
);
2057 static int alc_playback_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
2058 struct hda_codec
*codec
,
2059 struct snd_pcm_substream
*substream
)
2061 struct alc_spec
*spec
= codec
->spec
;
2062 return snd_hda_multi_out_analog_cleanup(codec
, &spec
->multiout
);
2068 static int alc_dig_playback_pcm_open(struct hda_pcm_stream
*hinfo
,
2069 struct hda_codec
*codec
,
2070 struct snd_pcm_substream
*substream
)
2072 struct alc_spec
*spec
= codec
->spec
;
2073 return snd_hda_multi_out_dig_open(codec
, &spec
->multiout
);
2076 static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
2077 struct hda_codec
*codec
,
2078 unsigned int stream_tag
,
2079 unsigned int format
,
2080 struct snd_pcm_substream
*substream
)
2082 struct alc_spec
*spec
= codec
->spec
;
2083 return snd_hda_multi_out_dig_prepare(codec
, &spec
->multiout
,
2084 stream_tag
, format
, substream
);
2087 static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
2088 struct hda_codec
*codec
,
2089 struct snd_pcm_substream
*substream
)
2091 struct alc_spec
*spec
= codec
->spec
;
2092 return snd_hda_multi_out_dig_cleanup(codec
, &spec
->multiout
);
2095 static int alc_dig_playback_pcm_close(struct hda_pcm_stream
*hinfo
,
2096 struct hda_codec
*codec
,
2097 struct snd_pcm_substream
*substream
)
2099 struct alc_spec
*spec
= codec
->spec
;
2100 return snd_hda_multi_out_dig_close(codec
, &spec
->multiout
);
2106 static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream
*hinfo
,
2107 struct hda_codec
*codec
,
2108 unsigned int stream_tag
,
2109 unsigned int format
,
2110 struct snd_pcm_substream
*substream
)
2112 struct alc_spec
*spec
= codec
->spec
;
2114 snd_hda_codec_setup_stream(codec
, spec
->adc_nids
[substream
->number
+ 1],
2115 stream_tag
, 0, format
);
2119 static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
2120 struct hda_codec
*codec
,
2121 struct snd_pcm_substream
*substream
)
2123 struct alc_spec
*spec
= codec
->spec
;
2125 snd_hda_codec_cleanup_stream(codec
,
2126 spec
->adc_nids
[substream
->number
+ 1]);
2130 /* analog capture with dynamic dual-adc changes */
2131 static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream
*hinfo
,
2132 struct hda_codec
*codec
,
2133 unsigned int stream_tag
,
2134 unsigned int format
,
2135 struct snd_pcm_substream
*substream
)
2137 struct alc_spec
*spec
= codec
->spec
;
2138 spec
->cur_adc
= spec
->adc_nids
[spec
->dyn_adc_idx
[spec
->cur_mux
[0]]];
2139 spec
->cur_adc_stream_tag
= stream_tag
;
2140 spec
->cur_adc_format
= format
;
2141 snd_hda_codec_setup_stream(codec
, spec
->cur_adc
, stream_tag
, 0, format
);
2145 static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
2146 struct hda_codec
*codec
,
2147 struct snd_pcm_substream
*substream
)
2149 struct alc_spec
*spec
= codec
->spec
;
2150 snd_hda_codec_cleanup_stream(codec
, spec
->cur_adc
);
2155 static const struct hda_pcm_stream dyn_adc_pcm_analog_capture
= {
2159 .nid
= 0, /* fill later */
2161 .prepare
= dyn_adc_capture_pcm_prepare
,
2162 .cleanup
= dyn_adc_capture_pcm_cleanup
2168 static const struct hda_pcm_stream alc_pcm_analog_playback
= {
2172 /* NID is set in alc_build_pcms */
2174 .open
= alc_playback_pcm_open
,
2175 .prepare
= alc_playback_pcm_prepare
,
2176 .cleanup
= alc_playback_pcm_cleanup
2180 static const struct hda_pcm_stream alc_pcm_analog_capture
= {
2184 /* NID is set in alc_build_pcms */
2187 static const struct hda_pcm_stream alc_pcm_analog_alt_playback
= {
2191 /* NID is set in alc_build_pcms */
2194 static const struct hda_pcm_stream alc_pcm_analog_alt_capture
= {
2195 .substreams
= 2, /* can be overridden */
2198 /* NID is set in alc_build_pcms */
2200 .prepare
= alc_alt_capture_pcm_prepare
,
2201 .cleanup
= alc_alt_capture_pcm_cleanup
2205 static const struct hda_pcm_stream alc_pcm_digital_playback
= {
2209 /* NID is set in alc_build_pcms */
2211 .open
= alc_dig_playback_pcm_open
,
2212 .close
= alc_dig_playback_pcm_close
,
2213 .prepare
= alc_dig_playback_pcm_prepare
,
2214 .cleanup
= alc_dig_playback_pcm_cleanup
2218 static const struct hda_pcm_stream alc_pcm_digital_capture
= {
2222 /* NID is set in alc_build_pcms */
2225 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
2226 static const struct hda_pcm_stream alc_pcm_null_stream
= {
2232 static int alc_build_pcms(struct hda_codec
*codec
)
2234 struct alc_spec
*spec
= codec
->spec
;
2235 struct hda_pcm
*info
= spec
->pcm_rec
;
2236 const struct hda_pcm_stream
*p
;
2237 bool have_multi_adcs
;
2240 codec
->num_pcms
= 1;
2241 codec
->pcm_info
= info
;
2243 if (spec
->no_analog
)
2246 snprintf(spec
->stream_name_analog
, sizeof(spec
->stream_name_analog
),
2247 "%s Analog", codec
->chip_name
);
2248 info
->name
= spec
->stream_name_analog
;
2250 if (spec
->multiout
.dac_nids
> 0) {
2251 p
= spec
->stream_analog_playback
;
2253 p
= &alc_pcm_analog_playback
;
2254 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] = *p
;
2255 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
= spec
->multiout
.dac_nids
[0];
2257 if (spec
->adc_nids
) {
2258 p
= spec
->stream_analog_capture
;
2260 if (spec
->dyn_adc_switch
)
2261 p
= &dyn_adc_pcm_analog_capture
;
2263 p
= &alc_pcm_analog_capture
;
2265 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] = *p
;
2266 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
= spec
->adc_nids
[0];
2269 if (spec
->channel_mode
) {
2270 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].channels_max
= 0;
2271 for (i
= 0; i
< spec
->num_channel_mode
; i
++) {
2272 if (spec
->channel_mode
[i
].channels
> info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].channels_max
) {
2273 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].channels_max
= spec
->channel_mode
[i
].channels
;
2279 /* SPDIF for stream index #1 */
2280 if (spec
->multiout
.dig_out_nid
|| spec
->dig_in_nid
) {
2281 snprintf(spec
->stream_name_digital
,
2282 sizeof(spec
->stream_name_digital
),
2283 "%s Digital", codec
->chip_name
);
2284 codec
->num_pcms
= 2;
2285 codec
->slave_dig_outs
= spec
->multiout
.slave_dig_outs
;
2286 info
= spec
->pcm_rec
+ 1;
2287 info
->name
= spec
->stream_name_digital
;
2288 if (spec
->dig_out_type
)
2289 info
->pcm_type
= spec
->dig_out_type
;
2291 info
->pcm_type
= HDA_PCM_TYPE_SPDIF
;
2292 if (spec
->multiout
.dig_out_nid
) {
2293 p
= spec
->stream_digital_playback
;
2295 p
= &alc_pcm_digital_playback
;
2296 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] = *p
;
2297 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
= spec
->multiout
.dig_out_nid
;
2299 if (spec
->dig_in_nid
) {
2300 p
= spec
->stream_digital_capture
;
2302 p
= &alc_pcm_digital_capture
;
2303 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] = *p
;
2304 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
= spec
->dig_in_nid
;
2306 /* FIXME: do we need this for all Realtek codec models? */
2307 codec
->spdif_status_reset
= 1;
2310 if (spec
->no_analog
)
2313 /* If the use of more than one ADC is requested for the current
2314 * model, configure a second analog capture-only PCM.
2316 have_multi_adcs
= (spec
->num_adc_nids
> 1) &&
2317 !spec
->dyn_adc_switch
&& !spec
->auto_mic
&&
2318 (!spec
->input_mux
|| spec
->input_mux
->num_items
> 1);
2319 /* Additional Analaog capture for index #2 */
2320 if (spec
->alt_dac_nid
|| have_multi_adcs
) {
2321 codec
->num_pcms
= 3;
2322 info
= spec
->pcm_rec
+ 2;
2323 info
->name
= spec
->stream_name_analog
;
2324 if (spec
->alt_dac_nid
) {
2325 p
= spec
->stream_analog_alt_playback
;
2327 p
= &alc_pcm_analog_alt_playback
;
2328 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] = *p
;
2329 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
=
2332 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] =
2333 alc_pcm_null_stream
;
2334 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
= 0;
2336 if (have_multi_adcs
) {
2337 p
= spec
->stream_analog_alt_capture
;
2339 p
= &alc_pcm_analog_alt_capture
;
2340 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] = *p
;
2341 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
=
2343 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].substreams
=
2344 spec
->num_adc_nids
- 1;
2346 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] =
2347 alc_pcm_null_stream
;
2348 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
= 0;
2355 static inline void alc_shutup(struct hda_codec
*codec
)
2357 struct alc_spec
*spec
= codec
->spec
;
2359 if (spec
&& spec
->shutup
)
2360 spec
->shutup(codec
);
2361 snd_hda_shutup_pins(codec
);
2364 static void alc_free_kctls(struct hda_codec
*codec
)
2366 struct alc_spec
*spec
= codec
->spec
;
2368 if (spec
->kctls
.list
) {
2369 struct snd_kcontrol_new
*kctl
= spec
->kctls
.list
;
2371 for (i
= 0; i
< spec
->kctls
.used
; i
++)
2372 kfree(kctl
[i
].name
);
2374 snd_array_free(&spec
->kctls
);
2377 static void alc_free(struct hda_codec
*codec
)
2379 struct alc_spec
*spec
= codec
->spec
;
2385 snd_hda_input_jack_free(codec
);
2386 alc_free_kctls(codec
);
2388 snd_hda_detach_beep_device(codec
);
2391 #ifdef CONFIG_SND_HDA_POWER_SAVE
2392 static void alc_power_eapd(struct hda_codec
*codec
)
2394 alc_auto_setup_eapd(codec
, false);
2397 static int alc_suspend(struct hda_codec
*codec
, pm_message_t state
)
2399 struct alc_spec
*spec
= codec
->spec
;
2401 if (spec
&& spec
->power_hook
)
2402 spec
->power_hook(codec
);
2408 static int alc_resume(struct hda_codec
*codec
)
2410 msleep(150); /* to avoid pop noise */
2411 codec
->patch_ops
.init(codec
);
2412 snd_hda_codec_resume_amp(codec
);
2413 snd_hda_codec_resume_cache(codec
);
2414 hda_call_check_power_status(codec
, 0x01);
2421 static const struct hda_codec_ops alc_patch_ops
= {
2422 .build_controls
= alc_build_controls
,
2423 .build_pcms
= alc_build_pcms
,
2426 .unsol_event
= alc_unsol_event
,
2428 .resume
= alc_resume
,
2430 #ifdef CONFIG_SND_HDA_POWER_SAVE
2431 .suspend
= alc_suspend
,
2432 .check_power_status
= alc_check_power_status
,
2434 .reboot_notify
= alc_shutup
,
2437 /* replace the codec chip_name with the given string */
2438 static int alc_codec_rename(struct hda_codec
*codec
, const char *name
)
2440 kfree(codec
->chip_name
);
2441 codec
->chip_name
= kstrdup(name
, GFP_KERNEL
);
2442 if (!codec
->chip_name
) {
2450 * Automatic parse of I/O pins from the BIOS configuration
2455 ALC_CTL_WIDGET_MUTE
,
2458 static const struct snd_kcontrol_new alc_control_templates
[] = {
2459 HDA_CODEC_VOLUME(NULL
, 0, 0, 0),
2460 HDA_CODEC_MUTE(NULL
, 0, 0, 0),
2461 HDA_BIND_MUTE(NULL
, 0, 0, 0),
2464 /* add dynamic controls */
2465 static int add_control(struct alc_spec
*spec
, int type
, const char *name
,
2466 int cidx
, unsigned long val
)
2468 struct snd_kcontrol_new
*knew
;
2470 knew
= alc_kcontrol_new(spec
);
2473 *knew
= alc_control_templates
[type
];
2474 knew
->name
= kstrdup(name
, GFP_KERNEL
);
2478 if (get_amp_nid_(val
))
2479 knew
->subdevice
= HDA_SUBDEV_AMP_FLAG
;
2480 knew
->private_value
= val
;
2484 static int add_control_with_pfx(struct alc_spec
*spec
, int type
,
2485 const char *pfx
, const char *dir
,
2486 const char *sfx
, int cidx
, unsigned long val
)
2489 snprintf(name
, sizeof(name
), "%s %s %s", pfx
, dir
, sfx
);
2490 return add_control(spec
, type
, name
, cidx
, val
);
2493 #define add_pb_vol_ctrl(spec, type, pfx, val) \
2494 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2495 #define add_pb_sw_ctrl(spec, type, pfx, val) \
2496 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2497 #define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2498 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2499 #define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2500 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
2502 static const char *alc_get_line_out_pfx(struct alc_spec
*spec
, int ch
,
2503 bool can_be_master
, int *index
)
2505 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
2506 static const char * const chname
[4] = {
2507 "Front", "Surround", NULL
/*CLFE*/, "Side"
2511 if (cfg
->line_outs
== 1 && !spec
->multi_ios
&&
2512 !cfg
->hp_outs
&& !cfg
->speaker_outs
&& can_be_master
)
2515 switch (cfg
->line_out_type
) {
2516 case AUTO_PIN_SPEAKER_OUT
:
2517 if (cfg
->line_outs
== 1)
2520 case AUTO_PIN_HP_OUT
:
2521 /* for multi-io case, only the primary out */
2522 if (ch
&& spec
->multi_ios
)
2527 if (cfg
->line_outs
== 1 && !spec
->multi_ios
)
2534 /* create input playback/capture controls for the given pin */
2535 static int new_analog_input(struct alc_spec
*spec
, hda_nid_t pin
,
2536 const char *ctlname
, int ctlidx
,
2537 int idx
, hda_nid_t mix_nid
)
2541 err
= __add_pb_vol_ctrl(spec
, ALC_CTL_WIDGET_VOL
, ctlname
, ctlidx
,
2542 HDA_COMPOSE_AMP_VAL(mix_nid
, 3, idx
, HDA_INPUT
));
2545 err
= __add_pb_sw_ctrl(spec
, ALC_CTL_WIDGET_MUTE
, ctlname
, ctlidx
,
2546 HDA_COMPOSE_AMP_VAL(mix_nid
, 3, idx
, HDA_INPUT
));
2552 static int alc_is_input_pin(struct hda_codec
*codec
, hda_nid_t nid
)
2554 unsigned int pincap
= snd_hda_query_pin_caps(codec
, nid
);
2555 return (pincap
& AC_PINCAP_IN
) != 0;
2558 /* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
2559 static int alc_auto_fill_adc_caps(struct hda_codec
*codec
)
2561 struct alc_spec
*spec
= codec
->spec
;
2563 hda_nid_t
*adc_nids
= spec
->private_adc_nids
;
2564 hda_nid_t
*cap_nids
= spec
->private_capsrc_nids
;
2565 int max_nums
= ARRAY_SIZE(spec
->private_adc_nids
);
2566 bool indep_capsrc
= false;
2569 nid
= codec
->start_nid
;
2570 for (i
= 0; i
< codec
->num_nodes
; i
++, nid
++) {
2572 const hda_nid_t
*list
;
2573 unsigned int caps
= get_wcaps(codec
, nid
);
2574 int type
= get_wcaps_type(caps
);
2576 if (type
!= AC_WID_AUD_IN
|| (caps
& AC_WCAP_DIGITAL
))
2578 adc_nids
[nums
] = nid
;
2579 cap_nids
[nums
] = nid
;
2583 type
= get_wcaps_type(get_wcaps(codec
, src
));
2584 if (type
== AC_WID_PIN
)
2586 if (type
== AC_WID_AUD_SEL
) {
2587 cap_nids
[nums
] = src
;
2588 indep_capsrc
= true;
2591 n
= snd_hda_get_conn_list(codec
, src
, &list
);
2593 cap_nids
[nums
] = src
;
2594 indep_capsrc
= true;
2600 if (++nums
>= max_nums
)
2603 spec
->adc_nids
= spec
->private_adc_nids
;
2604 spec
->capsrc_nids
= spec
->private_capsrc_nids
;
2605 spec
->num_adc_nids
= nums
;
2609 /* create playback/capture controls for input pins */
2610 static int alc_auto_create_input_ctls(struct hda_codec
*codec
)
2612 struct alc_spec
*spec
= codec
->spec
;
2613 const struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
2614 hda_nid_t mixer
= spec
->mixer_nid
;
2615 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
2617 int i
, c
, err
, idx
, type_idx
= 0;
2618 const char *prev_label
= NULL
;
2620 num_adcs
= alc_auto_fill_adc_caps(codec
);
2624 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
2628 pin
= cfg
->inputs
[i
].pin
;
2629 if (!alc_is_input_pin(codec
, pin
))
2632 label
= hda_get_autocfg_input_label(codec
, cfg
, i
);
2633 if (prev_label
&& !strcmp(label
, prev_label
))
2640 idx
= get_connection_index(codec
, mixer
, pin
);
2642 err
= new_analog_input(spec
, pin
,
2650 for (c
= 0; c
< num_adcs
; c
++) {
2651 hda_nid_t cap
= spec
->capsrc_nids
?
2652 spec
->capsrc_nids
[c
] : spec
->adc_nids
[c
];
2653 idx
= get_connection_index(codec
, cap
, pin
);
2655 spec
->imux_pins
[imux
->num_items
] = pin
;
2656 snd_hda_add_imux_item(imux
, label
, idx
, NULL
);
2662 spec
->num_mux_defs
= 1;
2663 spec
->input_mux
= imux
;
2668 static void alc_set_pin_output(struct hda_codec
*codec
, hda_nid_t nid
,
2669 unsigned int pin_type
)
2671 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_PIN_WIDGET_CONTROL
,
2674 if (nid_has_mute(codec
, nid
, HDA_OUTPUT
))
2675 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
2679 static int get_pin_type(int line_out_type
)
2681 if (line_out_type
== AUTO_PIN_HP_OUT
)
2687 static void alc_auto_init_analog_input(struct hda_codec
*codec
)
2689 struct alc_spec
*spec
= codec
->spec
;
2690 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
2693 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
2694 hda_nid_t nid
= cfg
->inputs
[i
].pin
;
2695 if (alc_is_input_pin(codec
, nid
)) {
2696 alc_set_input_pin(codec
, nid
, cfg
->inputs
[i
].type
);
2697 if (get_wcaps(codec
, nid
) & AC_WCAP_OUT_AMP
)
2698 snd_hda_codec_write(codec
, nid
, 0,
2699 AC_VERB_SET_AMP_GAIN_MUTE
,
2704 /* mute all loopback inputs */
2705 if (spec
->mixer_nid
) {
2706 int nums
= snd_hda_get_conn_list(codec
, spec
->mixer_nid
, NULL
);
2707 for (i
= 0; i
< nums
; i
++)
2708 snd_hda_codec_write(codec
, spec
->mixer_nid
, 0,
2709 AC_VERB_SET_AMP_GAIN_MUTE
,
2714 /* convert from MIX nid to DAC */
2715 static hda_nid_t
alc_auto_mix_to_dac(struct hda_codec
*codec
, hda_nid_t nid
)
2720 if (get_wcaps_type(get_wcaps(codec
, nid
)) == AC_WID_AUD_OUT
)
2722 num
= snd_hda_get_connections(codec
, nid
, list
, ARRAY_SIZE(list
));
2723 for (i
= 0; i
< num
; i
++) {
2724 if (get_wcaps_type(get_wcaps(codec
, list
[i
])) == AC_WID_AUD_OUT
)
2730 /* go down to the selector widget before the mixer */
2731 static hda_nid_t
alc_go_down_to_selector(struct hda_codec
*codec
, hda_nid_t pin
)
2734 int num
= snd_hda_get_connections(codec
, pin
, srcs
,
2737 get_wcaps_type(get_wcaps(codec
, srcs
[0])) != AC_WID_AUD_SEL
)
2742 /* get MIX nid connected to the given pin targeted to DAC */
2743 static hda_nid_t
alc_auto_dac_to_mix(struct hda_codec
*codec
, hda_nid_t pin
,
2749 pin
= alc_go_down_to_selector(codec
, pin
);
2750 num
= snd_hda_get_connections(codec
, pin
, mix
, ARRAY_SIZE(mix
));
2751 for (i
= 0; i
< num
; i
++) {
2752 if (alc_auto_mix_to_dac(codec
, mix
[i
]) == dac
)
2758 /* select the connection from pin to DAC if needed */
2759 static int alc_auto_select_dac(struct hda_codec
*codec
, hda_nid_t pin
,
2765 pin
= alc_go_down_to_selector(codec
, pin
);
2766 num
= snd_hda_get_connections(codec
, pin
, mix
, ARRAY_SIZE(mix
));
2769 for (i
= 0; i
< num
; i
++) {
2770 if (alc_auto_mix_to_dac(codec
, mix
[i
]) == dac
) {
2771 snd_hda_codec_update_cache(codec
, pin
, 0,
2772 AC_VERB_SET_CONNECT_SEL
, i
);
2779 /* look for an empty DAC slot */
2780 static hda_nid_t
alc_auto_look_for_dac(struct hda_codec
*codec
, hda_nid_t pin
)
2782 struct alc_spec
*spec
= codec
->spec
;
2786 pin
= alc_go_down_to_selector(codec
, pin
);
2787 num
= snd_hda_get_connections(codec
, pin
, srcs
, ARRAY_SIZE(srcs
));
2788 for (i
= 0; i
< num
; i
++) {
2789 hda_nid_t nid
= alc_auto_mix_to_dac(codec
, srcs
[i
]);
2792 if (found_in_nid_list(nid
, spec
->multiout
.dac_nids
,
2793 spec
->multiout
.num_dacs
))
2795 if (spec
->multiout
.hp_nid
== nid
)
2797 if (found_in_nid_list(nid
, spec
->multiout
.extra_out_nid
,
2798 ARRAY_SIZE(spec
->multiout
.extra_out_nid
)))
2805 static hda_nid_t
get_dac_if_single(struct hda_codec
*codec
, hda_nid_t pin
)
2807 hda_nid_t sel
= alc_go_down_to_selector(codec
, pin
);
2808 if (snd_hda_get_conn_list(codec
, sel
, NULL
) == 1)
2809 return alc_auto_look_for_dac(codec
, pin
);
2813 /* fill in the dac_nids table from the parsed pin configuration */
2814 static int alc_auto_fill_dac_nids(struct hda_codec
*codec
)
2816 struct alc_spec
*spec
= codec
->spec
;
2817 const struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
2818 bool redone
= false;
2822 /* set num_dacs once to full for alc_auto_look_for_dac() */
2823 spec
->multiout
.num_dacs
= cfg
->line_outs
;
2824 spec
->multiout
.hp_nid
= 0;
2825 spec
->multiout
.extra_out_nid
[0] = 0;
2826 memset(spec
->private_dac_nids
, 0, sizeof(spec
->private_dac_nids
));
2827 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
2829 /* fill hard-wired DACs first */
2831 for (i
= 0; i
< cfg
->line_outs
; i
++)
2832 spec
->private_dac_nids
[i
] =
2833 get_dac_if_single(codec
, cfg
->line_out_pins
[i
]);
2835 spec
->multiout
.hp_nid
=
2836 get_dac_if_single(codec
, cfg
->hp_pins
[0]);
2837 if (cfg
->speaker_outs
)
2838 spec
->multiout
.extra_out_nid
[0] =
2839 get_dac_if_single(codec
, cfg
->speaker_pins
[0]);
2842 for (i
= 0; i
< cfg
->line_outs
; i
++) {
2843 hda_nid_t pin
= cfg
->line_out_pins
[i
];
2844 if (spec
->private_dac_nids
[i
])
2846 spec
->private_dac_nids
[i
] = alc_auto_look_for_dac(codec
, pin
);
2847 if (!spec
->private_dac_nids
[i
] && !redone
) {
2848 /* if we can't find primary DACs, re-probe without
2849 * checking the hard-wired DACs
2856 /* re-count num_dacs and squash invalid entries */
2857 spec
->multiout
.num_dacs
= 0;
2858 for (i
= 0; i
< cfg
->line_outs
; i
++) {
2859 if (spec
->private_dac_nids
[i
])
2860 spec
->multiout
.num_dacs
++;
2862 memmove(spec
->private_dac_nids
+ i
,
2863 spec
->private_dac_nids
+ i
+ 1,
2864 sizeof(hda_nid_t
) * (cfg
->line_outs
- i
- 1));
2867 if (cfg
->hp_outs
&& !spec
->multiout
.hp_nid
)
2868 spec
->multiout
.hp_nid
=
2869 alc_auto_look_for_dac(codec
, cfg
->hp_pins
[0]);
2870 if (cfg
->speaker_outs
&& !spec
->multiout
.extra_out_nid
[0])
2871 spec
->multiout
.extra_out_nid
[0] =
2872 alc_auto_look_for_dac(codec
, cfg
->speaker_pins
[0]);
2877 static int alc_auto_add_vol_ctl(struct hda_codec
*codec
,
2878 const char *pfx
, int cidx
,
2879 hda_nid_t nid
, unsigned int chs
)
2883 return __add_pb_vol_ctrl(codec
->spec
, ALC_CTL_WIDGET_VOL
, pfx
, cidx
,
2884 HDA_COMPOSE_AMP_VAL(nid
, chs
, 0, HDA_OUTPUT
));
2887 #define alc_auto_add_stereo_vol(codec, pfx, cidx, nid) \
2888 alc_auto_add_vol_ctl(codec, pfx, cidx, nid, 3)
2890 /* create a mute-switch for the given mixer widget;
2891 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
2893 static int alc_auto_add_sw_ctl(struct hda_codec
*codec
,
2894 const char *pfx
, int cidx
,
2895 hda_nid_t nid
, unsigned int chs
)
2902 wid_type
= get_wcaps_type(get_wcaps(codec
, nid
));
2903 if (wid_type
== AC_WID_PIN
|| wid_type
== AC_WID_AUD_OUT
) {
2904 type
= ALC_CTL_WIDGET_MUTE
;
2905 val
= HDA_COMPOSE_AMP_VAL(nid
, chs
, 0, HDA_OUTPUT
);
2906 } else if (snd_hda_get_conn_list(codec
, nid
, NULL
) == 1) {
2907 type
= ALC_CTL_WIDGET_MUTE
;
2908 val
= HDA_COMPOSE_AMP_VAL(nid
, chs
, 0, HDA_INPUT
);
2910 type
= ALC_CTL_BIND_MUTE
;
2911 val
= HDA_COMPOSE_AMP_VAL(nid
, chs
, 2, HDA_INPUT
);
2913 return __add_pb_sw_ctrl(codec
->spec
, type
, pfx
, cidx
, val
);
2916 #define alc_auto_add_stereo_sw(codec, pfx, cidx, nid) \
2917 alc_auto_add_sw_ctl(codec, pfx, cidx, nid, 3)
2919 static hda_nid_t
alc_look_for_out_mute_nid(struct hda_codec
*codec
,
2920 hda_nid_t pin
, hda_nid_t dac
)
2922 hda_nid_t mix
= alc_auto_dac_to_mix(codec
, pin
, dac
);
2923 if (nid_has_mute(codec
, pin
, HDA_OUTPUT
))
2925 else if (mix
&& nid_has_mute(codec
, mix
, HDA_INPUT
))
2927 else if (nid_has_mute(codec
, dac
, HDA_OUTPUT
))
2932 static hda_nid_t
alc_look_for_out_vol_nid(struct hda_codec
*codec
,
2933 hda_nid_t pin
, hda_nid_t dac
)
2935 hda_nid_t mix
= alc_auto_dac_to_mix(codec
, pin
, dac
);
2936 if (nid_has_volume(codec
, dac
, HDA_OUTPUT
))
2938 else if (nid_has_volume(codec
, mix
, HDA_OUTPUT
))
2940 else if (nid_has_volume(codec
, pin
, HDA_OUTPUT
))
2945 /* add playback controls from the parsed DAC table */
2946 static int alc_auto_create_multi_out_ctls(struct hda_codec
*codec
,
2947 const struct auto_pin_cfg
*cfg
)
2949 struct alc_spec
*spec
= codec
->spec
;
2950 int i
, err
, noutputs
;
2952 noutputs
= cfg
->line_outs
;
2953 if (spec
->multi_ios
> 0)
2954 noutputs
+= spec
->multi_ios
;
2956 for (i
= 0; i
< noutputs
; i
++) {
2962 dac
= spec
->multiout
.dac_nids
[i
];
2965 if (i
>= cfg
->line_outs
)
2966 pin
= spec
->multi_io
[i
- 1].pin
;
2968 pin
= cfg
->line_out_pins
[i
];
2970 sw
= alc_look_for_out_mute_nid(codec
, pin
, dac
);
2971 vol
= alc_look_for_out_vol_nid(codec
, pin
, dac
);
2972 name
= alc_get_line_out_pfx(spec
, i
, true, &index
);
2975 err
= alc_auto_add_vol_ctl(codec
, "Center", 0, vol
, 1);
2978 err
= alc_auto_add_vol_ctl(codec
, "LFE", 0, vol
, 2);
2981 err
= alc_auto_add_sw_ctl(codec
, "Center", 0, sw
, 1);
2984 err
= alc_auto_add_sw_ctl(codec
, "LFE", 0, sw
, 2);
2988 err
= alc_auto_add_stereo_vol(codec
, name
, index
, vol
);
2991 err
= alc_auto_add_stereo_sw(codec
, name
, index
, sw
);
2999 /* add playback controls for speaker and HP outputs */
3000 static int alc_auto_create_extra_out(struct hda_codec
*codec
, hda_nid_t pin
,
3001 hda_nid_t dac
, const char *pfx
)
3003 struct alc_spec
*spec
= codec
->spec
;
3010 /* the corresponding DAC is already occupied */
3011 if (!(get_wcaps(codec
, pin
) & AC_WCAP_OUT_AMP
))
3012 return 0; /* no way */
3013 /* create a switch only */
3014 return add_pb_sw_ctrl(spec
, ALC_CTL_WIDGET_MUTE
, pfx
,
3015 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
3018 sw
= alc_look_for_out_mute_nid(codec
, pin
, dac
);
3019 vol
= alc_look_for_out_vol_nid(codec
, pin
, dac
);
3020 err
= alc_auto_add_stereo_vol(codec
, pfx
, 0, vol
);
3023 err
= alc_auto_add_stereo_sw(codec
, pfx
, 0, sw
);
3029 static int alc_auto_create_hp_out(struct hda_codec
*codec
)
3031 struct alc_spec
*spec
= codec
->spec
;
3032 return alc_auto_create_extra_out(codec
, spec
->autocfg
.hp_pins
[0],
3033 spec
->multiout
.hp_nid
,
3037 static int alc_auto_create_speaker_out(struct hda_codec
*codec
)
3039 struct alc_spec
*spec
= codec
->spec
;
3040 return alc_auto_create_extra_out(codec
, spec
->autocfg
.speaker_pins
[0],
3041 spec
->multiout
.extra_out_nid
[0],
3045 static void alc_auto_set_output_and_unmute(struct hda_codec
*codec
,
3046 hda_nid_t pin
, int pin_type
,
3050 hda_nid_t nid
, mix
= 0;
3051 hda_nid_t srcs
[HDA_MAX_CONNECTIONS
];
3053 alc_set_pin_output(codec
, pin
, pin_type
);
3054 nid
= alc_go_down_to_selector(codec
, pin
);
3055 num
= snd_hda_get_connections(codec
, nid
, srcs
, ARRAY_SIZE(srcs
));
3056 for (i
= 0; i
< num
; i
++) {
3057 if (alc_auto_mix_to_dac(codec
, srcs
[i
]) != dac
)
3065 /* need the manual connection? */
3067 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_CONNECT_SEL
, i
);
3068 /* unmute mixer widget inputs */
3069 if (nid_has_mute(codec
, mix
, HDA_INPUT
)) {
3070 snd_hda_codec_write(codec
, mix
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
3072 snd_hda_codec_write(codec
, mix
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
3075 /* initialize volume */
3076 nid
= alc_look_for_out_vol_nid(codec
, pin
, dac
);
3078 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
3082 static void alc_auto_init_multi_out(struct hda_codec
*codec
)
3084 struct alc_spec
*spec
= codec
->spec
;
3085 int pin_type
= get_pin_type(spec
->autocfg
.line_out_type
);
3088 for (i
= 0; i
<= HDA_SIDE
; i
++) {
3089 hda_nid_t nid
= spec
->autocfg
.line_out_pins
[i
];
3091 alc_auto_set_output_and_unmute(codec
, nid
, pin_type
,
3092 spec
->multiout
.dac_nids
[i
]);
3096 static void alc_auto_init_extra_out(struct hda_codec
*codec
)
3098 struct alc_spec
*spec
= codec
->spec
;
3101 pin
= spec
->autocfg
.hp_pins
[0];
3103 dac
= spec
->multiout
.hp_nid
;
3105 dac
= spec
->multiout
.dac_nids
[0];
3106 alc_auto_set_output_and_unmute(codec
, pin
, PIN_HP
, dac
);
3108 pin
= spec
->autocfg
.speaker_pins
[0];
3110 dac
= spec
->multiout
.extra_out_nid
[0];
3112 dac
= spec
->multiout
.dac_nids
[0];
3113 alc_auto_set_output_and_unmute(codec
, pin
, PIN_OUT
, dac
);
3120 static int alc_auto_fill_multi_ios(struct hda_codec
*codec
,
3121 unsigned int location
)
3123 struct alc_spec
*spec
= codec
->spec
;
3124 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
3125 int type
, i
, num_pins
= 0;
3127 for (type
= AUTO_PIN_LINE_IN
; type
>= AUTO_PIN_MIC
; type
--) {
3128 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
3129 hda_nid_t nid
= cfg
->inputs
[i
].pin
;
3131 unsigned int defcfg
, caps
;
3132 if (cfg
->inputs
[i
].type
!= type
)
3134 defcfg
= snd_hda_codec_get_pincfg(codec
, nid
);
3135 if (get_defcfg_connect(defcfg
) != AC_JACK_PORT_COMPLEX
)
3137 if (location
&& get_defcfg_location(defcfg
) != location
)
3139 caps
= snd_hda_query_pin_caps(codec
, nid
);
3140 if (!(caps
& AC_PINCAP_OUT
))
3142 dac
= alc_auto_look_for_dac(codec
, nid
);
3145 spec
->multi_io
[num_pins
].pin
= nid
;
3146 spec
->multi_io
[num_pins
].dac
= dac
;
3148 spec
->private_dac_nids
[spec
->multiout
.num_dacs
++] = dac
;
3151 spec
->multiout
.num_dacs
= 1;
3157 static int alc_auto_ch_mode_info(struct snd_kcontrol
*kcontrol
,
3158 struct snd_ctl_elem_info
*uinfo
)
3160 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3161 struct alc_spec
*spec
= codec
->spec
;
3163 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
3165 uinfo
->value
.enumerated
.items
= spec
->multi_ios
+ 1;
3166 if (uinfo
->value
.enumerated
.item
> spec
->multi_ios
)
3167 uinfo
->value
.enumerated
.item
= spec
->multi_ios
;
3168 sprintf(uinfo
->value
.enumerated
.name
, "%dch",
3169 (uinfo
->value
.enumerated
.item
+ 1) * 2);
3173 static int alc_auto_ch_mode_get(struct snd_kcontrol
*kcontrol
,
3174 struct snd_ctl_elem_value
*ucontrol
)
3176 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3177 struct alc_spec
*spec
= codec
->spec
;
3178 ucontrol
->value
.enumerated
.item
[0] = (spec
->ext_channel_count
- 1) / 2;
3182 static int alc_set_multi_io(struct hda_codec
*codec
, int idx
, bool output
)
3184 struct alc_spec
*spec
= codec
->spec
;
3185 hda_nid_t nid
= spec
->multi_io
[idx
].pin
;
3187 if (!spec
->multi_io
[idx
].ctl_in
)
3188 spec
->multi_io
[idx
].ctl_in
=
3189 snd_hda_codec_read(codec
, nid
, 0,
3190 AC_VERB_GET_PIN_WIDGET_CONTROL
, 0);
3192 snd_hda_codec_update_cache(codec
, nid
, 0,
3193 AC_VERB_SET_PIN_WIDGET_CONTROL
,
3195 if (get_wcaps(codec
, nid
) & AC_WCAP_OUT_AMP
)
3196 snd_hda_codec_amp_stereo(codec
, nid
, HDA_OUTPUT
, 0,
3198 alc_auto_select_dac(codec
, nid
, spec
->multi_io
[idx
].dac
);
3200 if (get_wcaps(codec
, nid
) & AC_WCAP_OUT_AMP
)
3201 snd_hda_codec_amp_stereo(codec
, nid
, HDA_OUTPUT
, 0,
3202 HDA_AMP_MUTE
, HDA_AMP_MUTE
);
3203 snd_hda_codec_update_cache(codec
, nid
, 0,
3204 AC_VERB_SET_PIN_WIDGET_CONTROL
,
3205 spec
->multi_io
[idx
].ctl_in
);
3210 static int alc_auto_ch_mode_put(struct snd_kcontrol
*kcontrol
,
3211 struct snd_ctl_elem_value
*ucontrol
)
3213 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3214 struct alc_spec
*spec
= codec
->spec
;
3217 ch
= ucontrol
->value
.enumerated
.item
[0];
3218 if (ch
< 0 || ch
> spec
->multi_ios
)
3220 if (ch
== (spec
->ext_channel_count
- 1) / 2)
3222 spec
->ext_channel_count
= (ch
+ 1) * 2;
3223 for (i
= 0; i
< spec
->multi_ios
; i
++)
3224 alc_set_multi_io(codec
, i
, i
< ch
);
3225 spec
->multiout
.max_channels
= spec
->ext_channel_count
;
3226 if (spec
->need_dac_fix
&& !spec
->const_channel_count
)
3227 spec
->multiout
.num_dacs
= spec
->multiout
.max_channels
/ 2;
3231 static const struct snd_kcontrol_new alc_auto_channel_mode_enum
= {
3232 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
3233 .name
= "Channel Mode",
3234 .info
= alc_auto_ch_mode_info
,
3235 .get
= alc_auto_ch_mode_get
,
3236 .put
= alc_auto_ch_mode_put
,
3239 static int alc_auto_add_multi_channel_mode(struct hda_codec
*codec
,
3240 int (*fill_dac
)(struct hda_codec
*))
3242 struct alc_spec
*spec
= codec
->spec
;
3243 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
3244 unsigned int location
, defcfg
;
3247 if (cfg
->line_out_type
== AUTO_PIN_SPEAKER_OUT
&& cfg
->hp_outs
== 1) {
3248 /* use HP as primary out */
3249 cfg
->speaker_outs
= cfg
->line_outs
;
3250 memcpy(cfg
->speaker_pins
, cfg
->line_out_pins
,
3251 sizeof(cfg
->speaker_pins
));
3252 cfg
->line_outs
= cfg
->hp_outs
;
3253 memcpy(cfg
->line_out_pins
, cfg
->hp_pins
, sizeof(cfg
->hp_pins
));
3255 memset(cfg
->hp_pins
, 0, sizeof(cfg
->hp_pins
));
3256 cfg
->line_out_type
= AUTO_PIN_HP_OUT
;
3260 if (cfg
->line_outs
!= 1 ||
3261 cfg
->line_out_type
== AUTO_PIN_SPEAKER_OUT
)
3264 defcfg
= snd_hda_codec_get_pincfg(codec
, cfg
->line_out_pins
[0]);
3265 location
= get_defcfg_location(defcfg
);
3267 num_pins
= alc_auto_fill_multi_ios(codec
, location
);
3269 struct snd_kcontrol_new
*knew
;
3271 knew
= alc_kcontrol_new(spec
);
3274 *knew
= alc_auto_channel_mode_enum
;
3275 knew
->name
= kstrdup("Channel Mode", GFP_KERNEL
);
3279 spec
->multi_ios
= num_pins
;
3280 spec
->ext_channel_count
= 2;
3281 spec
->multiout
.num_dacs
= num_pins
+ 1;
3286 /* filter out invalid adc_nids (and capsrc_nids) that don't give all
3289 static void alc_remove_invalid_adc_nids(struct hda_codec
*codec
)
3291 struct alc_spec
*spec
= codec
->spec
;
3292 const struct hda_input_mux
*imux
;
3293 hda_nid_t adc_nids
[ARRAY_SIZE(spec
->private_adc_nids
)];
3294 hda_nid_t capsrc_nids
[ARRAY_SIZE(spec
->private_adc_nids
)];
3297 imux
= spec
->input_mux
;
3300 if (spec
->dyn_adc_switch
)
3304 for (n
= 0; n
< spec
->num_adc_nids
; n
++) {
3305 hda_nid_t cap
= spec
->private_capsrc_nids
[n
];
3306 int num_conns
= snd_hda_get_conn_list(codec
, cap
, NULL
);
3307 for (i
= 0; i
< imux
->num_items
; i
++) {
3308 hda_nid_t pin
= spec
->imux_pins
[i
];
3310 if (get_connection_index(codec
, cap
, pin
) < 0)
3312 } else if (num_conns
<= imux
->items
[i
].index
)
3315 if (i
>= imux
->num_items
) {
3316 adc_nids
[nums
] = spec
->private_adc_nids
[n
];
3317 capsrc_nids
[nums
++] = cap
;
3321 /* check whether ADC-switch is possible */
3322 if (!alc_check_dyn_adc_switch(codec
)) {
3323 printk(KERN_WARNING
"hda_codec: %s: no valid ADC found;"
3324 " using fallback 0x%x\n",
3325 codec
->chip_name
, spec
->private_adc_nids
[0]);
3326 spec
->num_adc_nids
= 1;
3330 } else if (nums
!= spec
->num_adc_nids
) {
3331 memcpy(spec
->private_adc_nids
, adc_nids
,
3332 nums
* sizeof(hda_nid_t
));
3333 memcpy(spec
->private_capsrc_nids
, capsrc_nids
,
3334 nums
* sizeof(hda_nid_t
));
3335 spec
->num_adc_nids
= nums
;
3339 alc_auto_mic_check_imux(codec
); /* check auto-mic setups */
3340 else if (spec
->input_mux
->num_items
== 1)
3341 spec
->num_adc_nids
= 1; /* reduce to a single ADC */
3345 * initialize ADC paths
3347 static void alc_auto_init_adc(struct hda_codec
*codec
, int adc_idx
)
3349 struct alc_spec
*spec
= codec
->spec
;
3352 nid
= spec
->adc_nids
[adc_idx
];
3354 if (nid_has_mute(codec
, nid
, HDA_INPUT
)) {
3355 snd_hda_codec_write(codec
, nid
, 0,
3356 AC_VERB_SET_AMP_GAIN_MUTE
,
3360 if (!spec
->capsrc_nids
)
3362 nid
= spec
->capsrc_nids
[adc_idx
];
3363 if (nid_has_mute(codec
, nid
, HDA_OUTPUT
))
3364 snd_hda_codec_write(codec
, nid
, 0,
3365 AC_VERB_SET_AMP_GAIN_MUTE
,
3369 static void alc_auto_init_input_src(struct hda_codec
*codec
)
3371 struct alc_spec
*spec
= codec
->spec
;
3374 for (c
= 0; c
< spec
->num_adc_nids
; c
++)
3375 alc_auto_init_adc(codec
, c
);
3376 if (spec
->dyn_adc_switch
)
3379 nums
= spec
->num_adc_nids
;
3380 for (c
= 0; c
< nums
; c
++)
3381 alc_mux_select(codec
, 0, spec
->cur_mux
[c
], true);
3384 /* add mic boosts if needed */
3385 static int alc_auto_add_mic_boost(struct hda_codec
*codec
)
3387 struct alc_spec
*spec
= codec
->spec
;
3388 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
3392 const char *prev_label
= NULL
;
3394 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
3395 if (cfg
->inputs
[i
].type
> AUTO_PIN_MIC
)
3397 nid
= cfg
->inputs
[i
].pin
;
3398 if (get_wcaps(codec
, nid
) & AC_WCAP_IN_AMP
) {
3400 char boost_label
[32];
3402 label
= hda_get_autocfg_input_label(codec
, cfg
, i
);
3403 if (prev_label
&& !strcmp(label
, prev_label
))
3409 snprintf(boost_label
, sizeof(boost_label
),
3410 "%s Boost Volume", label
);
3411 err
= add_control(spec
, ALC_CTL_WIDGET_VOL
,
3412 boost_label
, type_idx
,
3413 HDA_COMPOSE_AMP_VAL(nid
, 3, 0, HDA_INPUT
));
3421 /* select or unmute the given capsrc route */
3422 static void select_or_unmute_capsrc(struct hda_codec
*codec
, hda_nid_t cap
,
3425 if (get_wcaps_type(get_wcaps(codec
, cap
)) == AC_WID_AUD_MIX
) {
3426 snd_hda_codec_amp_stereo(codec
, cap
, HDA_INPUT
, idx
,
3428 } else if (snd_hda_get_conn_list(codec
, cap
, NULL
) > 1) {
3429 snd_hda_codec_write_cache(codec
, cap
, 0,
3430 AC_VERB_SET_CONNECT_SEL
, idx
);
3434 /* set the default connection to that pin */
3435 static int init_capsrc_for_pin(struct hda_codec
*codec
, hda_nid_t pin
)
3437 struct alc_spec
*spec
= codec
->spec
;
3442 for (i
= 0; i
< spec
->num_adc_nids
; i
++) {
3443 hda_nid_t cap
= spec
->capsrc_nids
?
3444 spec
->capsrc_nids
[i
] : spec
->adc_nids
[i
];
3447 idx
= get_connection_index(codec
, cap
, pin
);
3450 select_or_unmute_capsrc(codec
, cap
, idx
);
3451 return i
; /* return the found index */
3453 return -1; /* not found */
3456 /* initialize some special cases for input sources */
3457 static void alc_init_special_input_src(struct hda_codec
*codec
)
3459 struct alc_spec
*spec
= codec
->spec
;
3462 for (i
= 0; i
< spec
->autocfg
.num_inputs
; i
++)
3463 init_capsrc_for_pin(codec
, spec
->autocfg
.inputs
[i
].pin
);
3466 /* assign appropriate capture mixers */
3467 static void set_capture_mixer(struct hda_codec
*codec
)
3469 struct alc_spec
*spec
= codec
->spec
;
3470 static const struct snd_kcontrol_new
*caps
[2][3] = {
3471 { alc_capture_mixer_nosrc1
,
3472 alc_capture_mixer_nosrc2
,
3473 alc_capture_mixer_nosrc3
},
3474 { alc_capture_mixer1
,
3476 alc_capture_mixer3
},
3479 /* check whether either of ADC or MUX has a volume control */
3480 if (!nid_has_volume(codec
, spec
->adc_nids
[0], HDA_INPUT
)) {
3481 if (!spec
->capsrc_nids
)
3482 return; /* no volume */
3483 if (!nid_has_volume(codec
, spec
->capsrc_nids
[0], HDA_OUTPUT
))
3484 return; /* no volume in capsrc, too */
3485 spec
->vol_in_capsrc
= 1;
3488 if (spec
->num_adc_nids
> 0) {
3492 if (spec
->input_mux
&& spec
->input_mux
->num_items
> 1)
3494 if (spec
->auto_mic
) {
3497 } else if (spec
->dyn_adc_switch
)
3500 if (spec
->num_adc_nids
> 3)
3501 spec
->num_adc_nids
= 3;
3502 else if (!spec
->num_adc_nids
)
3504 num_adcs
= spec
->num_adc_nids
;
3506 spec
->cap_mixer
= caps
[mux
][num_adcs
- 1];
3511 * standard auto-parser initializations
3513 static void alc_auto_init_std(struct hda_codec
*codec
)
3515 struct alc_spec
*spec
= codec
->spec
;
3516 alc_auto_init_multi_out(codec
);
3517 alc_auto_init_extra_out(codec
);
3518 alc_auto_init_analog_input(codec
);
3519 alc_auto_init_input_src(codec
);
3520 alc_auto_init_digital(codec
);
3521 if (spec
->unsol_event
)
3522 alc_inithook(codec
);
3526 * Digital-beep handlers
3528 #ifdef CONFIG_SND_HDA_INPUT_BEEP
3529 #define set_beep_amp(spec, nid, idx, dir) \
3530 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
3532 static const struct snd_pci_quirk beep_white_list
[] = {
3533 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
3534 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
3535 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
3536 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
3537 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
3541 static inline int has_cdefine_beep(struct hda_codec
*codec
)
3543 struct alc_spec
*spec
= codec
->spec
;
3544 const struct snd_pci_quirk
*q
;
3545 q
= snd_pci_quirk_lookup(codec
->bus
->pci
, beep_white_list
);
3548 return spec
->cdefine
.enable_pcbeep
;
3551 #define set_beep_amp(spec, nid, idx, dir) /* NOP */
3552 #define has_cdefine_beep(codec) 0
3555 /* parse the BIOS configuration and set up the alc_spec */
3556 /* return 1 if successful, 0 if the proper config is not found,
3557 * or a negative error code
3559 static int alc_parse_auto_config(struct hda_codec
*codec
,
3560 const hda_nid_t
*ignore_nids
,
3561 const hda_nid_t
*ssid_nids
)
3563 struct alc_spec
*spec
= codec
->spec
;
3566 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
,
3570 if (!spec
->autocfg
.line_outs
) {
3571 if (spec
->autocfg
.dig_outs
|| spec
->autocfg
.dig_in_pin
) {
3572 spec
->multiout
.max_channels
= 2;
3573 spec
->no_analog
= 1;
3576 return 0; /* can't find valid BIOS pin config */
3578 err
= alc_auto_fill_dac_nids(codec
);
3581 err
= alc_auto_add_multi_channel_mode(codec
, alc_auto_fill_dac_nids
);
3584 err
= alc_auto_create_multi_out_ctls(codec
, &spec
->autocfg
);
3587 err
= alc_auto_create_hp_out(codec
);
3590 err
= alc_auto_create_speaker_out(codec
);
3593 err
= alc_auto_create_input_ctls(codec
);
3597 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
3600 alc_auto_parse_digital(codec
);
3602 if (!spec
->no_analog
)
3603 alc_remove_invalid_adc_nids(codec
);
3606 alc_ssid_check(codec
, ssid_nids
);
3608 if (!spec
->no_analog
) {
3609 alc_auto_check_switches(codec
);
3610 err
= alc_auto_add_mic_boost(codec
);
3615 if (spec
->kctls
.list
)
3616 add_mixer(spec
, spec
->kctls
.list
);
3621 static int alc880_parse_auto_config(struct hda_codec
*codec
)
3623 static const hda_nid_t alc880_ignore
[] = { 0x1d, 0 };
3624 static const hda_nid_t alc880_ssids
[] = { 0x15, 0x1b, 0x14, 0 };
3625 return alc_parse_auto_config(codec
, alc880_ignore
, alc880_ssids
);
3628 #ifdef CONFIG_SND_HDA_POWER_SAVE
3629 static const struct hda_amp_list alc880_loopbacks
[] = {
3630 { 0x0b, HDA_INPUT
, 0 },
3631 { 0x0b, HDA_INPUT
, 1 },
3632 { 0x0b, HDA_INPUT
, 2 },
3633 { 0x0b, HDA_INPUT
, 3 },
3634 { 0x0b, HDA_INPUT
, 4 },
3642 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3643 #define alc_board_config \
3644 snd_hda_check_board_config
3645 #define alc_board_codec_sid_config \
3646 snd_hda_check_board_codec_sid_config
3647 #include "alc_quirks.c"
3649 #define alc_board_config(codec, nums, models, tbl) -1
3650 #define alc_board_codec_sid_config(codec, nums, models, tbl) -1
3651 #define setup_preset(codec, x) /* NOP */
3655 * OK, here we have finally the patch for ALC880
3657 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3658 #include "alc880_quirks.c"
3661 static int patch_alc880(struct hda_codec
*codec
)
3663 struct alc_spec
*spec
;
3667 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
3673 spec
->mixer_nid
= 0x0b;
3674 spec
->need_dac_fix
= 1;
3676 board_config
= alc_board_config(codec
, ALC880_MODEL_LAST
,
3677 alc880_models
, alc880_cfg_tbl
);
3678 if (board_config
< 0) {
3679 printk(KERN_INFO
"hda_codec: %s: BIOS auto-probing.\n",
3681 board_config
= ALC_MODEL_AUTO
;
3684 if (board_config
== ALC_MODEL_AUTO
) {
3685 /* automatic parse from the BIOS config */
3686 err
= alc880_parse_auto_config(codec
);
3691 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3694 "hda_codec: Cannot set up configuration "
3695 "from BIOS. Using 3-stack mode...\n");
3696 board_config
= ALC880_3ST
;
3701 if (board_config
!= ALC_MODEL_AUTO
)
3702 setup_preset(codec
, &alc880_presets
[board_config
]);
3704 if (!spec
->no_analog
&& !spec
->adc_nids
) {
3705 alc_auto_fill_adc_caps(codec
);
3706 alc_rebuild_imux_for_auto_mic(codec
);
3707 alc_remove_invalid_adc_nids(codec
);
3710 if (!spec
->no_analog
&& !spec
->cap_mixer
)
3711 set_capture_mixer(codec
);
3713 if (!spec
->no_analog
) {
3714 err
= snd_hda_attach_beep_device(codec
, 0x1);
3719 set_beep_amp(spec
, 0x0b, 0x05, HDA_INPUT
);
3722 spec
->vmaster_nid
= 0x0c;
3724 codec
->patch_ops
= alc_patch_ops
;
3725 if (board_config
== ALC_MODEL_AUTO
)
3726 spec
->init_hook
= alc_auto_init_std
;
3727 #ifdef CONFIG_SND_HDA_POWER_SAVE
3728 if (!spec
->loopback
.amplist
)
3729 spec
->loopback
.amplist
= alc880_loopbacks
;
3739 static int alc260_parse_auto_config(struct hda_codec
*codec
)
3741 static const hda_nid_t alc260_ignore
[] = { 0x17, 0 };
3742 static const hda_nid_t alc260_ssids
[] = { 0x10, 0x15, 0x0f, 0 };
3743 return alc_parse_auto_config(codec
, alc260_ignore
, alc260_ssids
);
3746 #ifdef CONFIG_SND_HDA_POWER_SAVE
3747 static const struct hda_amp_list alc260_loopbacks
[] = {
3748 { 0x07, HDA_INPUT
, 0 },
3749 { 0x07, HDA_INPUT
, 1 },
3750 { 0x07, HDA_INPUT
, 2 },
3751 { 0x07, HDA_INPUT
, 3 },
3752 { 0x07, HDA_INPUT
, 4 },
3764 static const struct alc_fixup alc260_fixups
[] = {
3765 [PINFIX_HP_DC5750
] = {
3766 .type
= ALC_FIXUP_PINS
,
3767 .v
.pins
= (const struct alc_pincfg
[]) {
3768 { 0x11, 0x90130110 }, /* speaker */
3774 static const struct snd_pci_quirk alc260_fixup_tbl
[] = {
3775 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", PINFIX_HP_DC5750
),
3781 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3782 #include "alc260_quirks.c"
3785 static int patch_alc260(struct hda_codec
*codec
)
3787 struct alc_spec
*spec
;
3788 int err
, board_config
;
3790 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
3796 spec
->mixer_nid
= 0x07;
3798 board_config
= alc_board_config(codec
, ALC260_MODEL_LAST
,
3799 alc260_models
, alc260_cfg_tbl
);
3800 if (board_config
< 0) {
3801 snd_printd(KERN_INFO
"hda_codec: %s: BIOS auto-probing.\n",
3803 board_config
= ALC_MODEL_AUTO
;
3806 if (board_config
== ALC_MODEL_AUTO
) {
3807 alc_pick_fixup(codec
, NULL
, alc260_fixup_tbl
, alc260_fixups
);
3808 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
3811 if (board_config
== ALC_MODEL_AUTO
) {
3812 /* automatic parse from the BIOS config */
3813 err
= alc260_parse_auto_config(codec
);
3818 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3821 "hda_codec: Cannot set up configuration "
3822 "from BIOS. Using base mode...\n");
3823 board_config
= ALC260_BASIC
;
3828 if (board_config
!= ALC_MODEL_AUTO
)
3829 setup_preset(codec
, &alc260_presets
[board_config
]);
3831 if (!spec
->no_analog
&& !spec
->adc_nids
) {
3832 alc_auto_fill_adc_caps(codec
);
3833 alc_rebuild_imux_for_auto_mic(codec
);
3834 alc_remove_invalid_adc_nids(codec
);
3837 if (!spec
->no_analog
&& !spec
->cap_mixer
)
3838 set_capture_mixer(codec
);
3840 if (!spec
->no_analog
) {
3841 err
= snd_hda_attach_beep_device(codec
, 0x1);
3846 set_beep_amp(spec
, 0x07, 0x05, HDA_INPUT
);
3849 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
3851 spec
->vmaster_nid
= 0x08;
3853 codec
->patch_ops
= alc_patch_ops
;
3854 if (board_config
== ALC_MODEL_AUTO
)
3855 spec
->init_hook
= alc_auto_init_std
;
3856 spec
->shutup
= alc_eapd_shutup
;
3857 #ifdef CONFIG_SND_HDA_POWER_SAVE
3858 if (!spec
->loopback
.amplist
)
3859 spec
->loopback
.amplist
= alc260_loopbacks
;
3867 * ALC882/883/885/888/889 support
3869 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
3870 * configuration. Each pin widget can choose any input DACs and a mixer.
3871 * Each ADC is connected from a mixer of all inputs. This makes possible
3872 * 6-channel independent captures.
3874 * In addition, an independent DAC for the multi-playback (not used in this
3877 #ifdef CONFIG_SND_HDA_POWER_SAVE
3878 #define alc882_loopbacks alc880_loopbacks
3885 PINFIX_ABIT_AW9D_MAX
,
3888 PINFIX_ACER_ASPIRE_7736
,
3891 static const struct alc_fixup alc882_fixups
[] = {
3892 [PINFIX_ABIT_AW9D_MAX
] = {
3893 .type
= ALC_FIXUP_PINS
,
3894 .v
.pins
= (const struct alc_pincfg
[]) {
3895 { 0x15, 0x01080104 }, /* side */
3896 { 0x16, 0x01011012 }, /* rear */
3897 { 0x17, 0x01016011 }, /* clfe */
3901 [PINFIX_LENOVO_Y530
] = {
3902 .type
= ALC_FIXUP_PINS
,
3903 .v
.pins
= (const struct alc_pincfg
[]) {
3904 { 0x15, 0x99130112 }, /* rear int speakers */
3905 { 0x16, 0x99130111 }, /* subwoofer */
3909 [PINFIX_PB_M5210
] = {
3910 .type
= ALC_FIXUP_VERBS
,
3911 .v
.verbs
= (const struct hda_verb
[]) {
3912 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_VREF50
},
3916 [PINFIX_ACER_ASPIRE_7736
] = {
3917 .type
= ALC_FIXUP_SKU
,
3918 .v
.sku
= ALC_FIXUP_SKU_IGNORE
,
3922 static const struct snd_pci_quirk alc882_fixup_tbl
[] = {
3923 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", PINFIX_PB_M5210
),
3924 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", PINFIX_LENOVO_Y530
),
3925 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX
),
3926 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", PINFIX_ACER_ASPIRE_7736
),
3931 * BIOS auto configuration
3933 /* almost identical with ALC880 parser... */
3934 static int alc882_parse_auto_config(struct hda_codec
*codec
)
3936 static const hda_nid_t alc882_ignore
[] = { 0x1d, 0 };
3937 static const hda_nid_t alc882_ssids
[] = { 0x15, 0x1b, 0x14, 0 };
3938 return alc_parse_auto_config(codec
, alc882_ignore
, alc882_ssids
);
3943 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3944 #include "alc882_quirks.c"
3947 static int patch_alc882(struct hda_codec
*codec
)
3949 struct alc_spec
*spec
;
3950 int err
, board_config
;
3952 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
3958 spec
->mixer_nid
= 0x0b;
3960 switch (codec
->vendor_id
) {
3965 /* ALC883 and variants */
3966 alc_fix_pll_init(codec
, 0x20, 0x0a, 10);
3970 board_config
= alc_board_config(codec
, ALC882_MODEL_LAST
,
3971 alc882_models
, alc882_cfg_tbl
);
3973 if (board_config
< 0)
3974 board_config
= alc_board_codec_sid_config(codec
,
3975 ALC882_MODEL_LAST
, alc882_models
, alc882_ssid_cfg_tbl
);
3977 if (board_config
< 0) {
3978 printk(KERN_INFO
"hda_codec: %s: BIOS auto-probing.\n",
3980 board_config
= ALC_MODEL_AUTO
;
3983 if (board_config
== ALC_MODEL_AUTO
) {
3984 alc_pick_fixup(codec
, NULL
, alc882_fixup_tbl
, alc882_fixups
);
3985 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
3988 alc_auto_parse_customize_define(codec
);
3990 if (board_config
== ALC_MODEL_AUTO
) {
3991 /* automatic parse from the BIOS config */
3992 err
= alc882_parse_auto_config(codec
);
3997 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4000 "hda_codec: Cannot set up configuration "
4001 "from BIOS. Using base mode...\n");
4002 board_config
= ALC882_3ST_DIG
;
4007 if (board_config
!= ALC_MODEL_AUTO
)
4008 setup_preset(codec
, &alc882_presets
[board_config
]);
4010 if (!spec
->no_analog
&& !spec
->adc_nids
) {
4011 alc_auto_fill_adc_caps(codec
);
4012 alc_rebuild_imux_for_auto_mic(codec
);
4013 alc_remove_invalid_adc_nids(codec
);
4016 if (!spec
->no_analog
&& !spec
->cap_mixer
)
4017 set_capture_mixer(codec
);
4019 if (!spec
->no_analog
&& has_cdefine_beep(codec
)) {
4020 err
= snd_hda_attach_beep_device(codec
, 0x1);
4025 set_beep_amp(spec
, 0x0b, 0x05, HDA_INPUT
);
4028 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
4030 spec
->vmaster_nid
= 0x0c;
4032 codec
->patch_ops
= alc_patch_ops
;
4033 if (board_config
== ALC_MODEL_AUTO
)
4034 spec
->init_hook
= alc_auto_init_std
;
4036 alc_init_jacks(codec
);
4037 #ifdef CONFIG_SND_HDA_POWER_SAVE
4038 if (!spec
->loopback
.amplist
)
4039 spec
->loopback
.amplist
= alc882_loopbacks
;
4049 static int alc262_parse_auto_config(struct hda_codec
*codec
)
4051 static const hda_nid_t alc262_ignore
[] = { 0x1d, 0 };
4052 static const hda_nid_t alc262_ssids
[] = { 0x15, 0x1b, 0x14, 0 };
4053 return alc_parse_auto_config(codec
, alc262_ignore
, alc262_ssids
);
4064 static const struct alc_fixup alc262_fixups
[] = {
4065 [PINFIX_FSC_H270
] = {
4066 .type
= ALC_FIXUP_PINS
,
4067 .v
.pins
= (const struct alc_pincfg
[]) {
4068 { 0x14, 0x99130110 }, /* speaker */
4069 { 0x15, 0x0221142f }, /* front HP */
4070 { 0x1b, 0x0121141f }, /* rear HP */
4074 [PINFIX_HP_Z200
] = {
4075 .type
= ALC_FIXUP_PINS
,
4076 .v
.pins
= (const struct alc_pincfg
[]) {
4077 { 0x16, 0x99130120 }, /* internal speaker */
4083 static const struct snd_pci_quirk alc262_fixup_tbl
[] = {
4084 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", PINFIX_HP_Z200
),
4085 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", PINFIX_FSC_H270
),
4090 #ifdef CONFIG_SND_HDA_POWER_SAVE
4091 #define alc262_loopbacks alc880_loopbacks
4096 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4097 #include "alc262_quirks.c"
4100 static int patch_alc262(struct hda_codec
*codec
)
4102 struct alc_spec
*spec
;
4106 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
4112 spec
->mixer_nid
= 0x0b;
4115 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
4120 snd_hda_codec_write(codec
, 0x1a, 0, AC_VERB_SET_COEF_INDEX
, 7);
4121 tmp
= snd_hda_codec_read(codec
, 0x20, 0, AC_VERB_GET_PROC_COEF
, 0);
4122 snd_hda_codec_write(codec
, 0x1a, 0, AC_VERB_SET_COEF_INDEX
, 7);
4123 snd_hda_codec_write(codec
, 0x1a, 0, AC_VERB_SET_PROC_COEF
, tmp
| 0x80);
4126 alc_auto_parse_customize_define(codec
);
4128 alc_fix_pll_init(codec
, 0x20, 0x0a, 10);
4130 board_config
= alc_board_config(codec
, ALC262_MODEL_LAST
,
4131 alc262_models
, alc262_cfg_tbl
);
4133 if (board_config
< 0) {
4134 printk(KERN_INFO
"hda_codec: %s: BIOS auto-probing.\n",
4136 board_config
= ALC_MODEL_AUTO
;
4139 if (board_config
== ALC_MODEL_AUTO
) {
4140 alc_pick_fixup(codec
, NULL
, alc262_fixup_tbl
, alc262_fixups
);
4141 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
4144 if (board_config
== ALC_MODEL_AUTO
) {
4145 /* automatic parse from the BIOS config */
4146 err
= alc262_parse_auto_config(codec
);
4151 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4154 "hda_codec: Cannot set up configuration "
4155 "from BIOS. Using base mode...\n");
4156 board_config
= ALC262_BASIC
;
4161 if (board_config
!= ALC_MODEL_AUTO
)
4162 setup_preset(codec
, &alc262_presets
[board_config
]);
4164 if (!spec
->no_analog
&& !spec
->adc_nids
) {
4165 alc_auto_fill_adc_caps(codec
);
4166 alc_rebuild_imux_for_auto_mic(codec
);
4167 alc_remove_invalid_adc_nids(codec
);
4170 if (!spec
->no_analog
&& !spec
->cap_mixer
)
4171 set_capture_mixer(codec
);
4173 if (!spec
->no_analog
&& has_cdefine_beep(codec
)) {
4174 err
= snd_hda_attach_beep_device(codec
, 0x1);
4179 set_beep_amp(spec
, 0x0b, 0x05, HDA_INPUT
);
4182 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
4184 spec
->vmaster_nid
= 0x0c;
4186 codec
->patch_ops
= alc_patch_ops
;
4187 if (board_config
== ALC_MODEL_AUTO
)
4188 spec
->init_hook
= alc_auto_init_std
;
4189 spec
->shutup
= alc_eapd_shutup
;
4191 alc_init_jacks(codec
);
4192 #ifdef CONFIG_SND_HDA_POWER_SAVE
4193 if (!spec
->loopback
.amplist
)
4194 spec
->loopback
.amplist
= alc262_loopbacks
;
4203 /* bind Beep switches of both NID 0x0f and 0x10 */
4204 static const struct hda_bind_ctls alc268_bind_beep_sw
= {
4205 .ops
= &snd_hda_bind_sw
,
4207 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT
),
4208 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT
),
4213 static const struct snd_kcontrol_new alc268_beep_mixer
[] = {
4214 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT
),
4215 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw
),
4219 /* set PCBEEP vol = 0, mute connections */
4220 static const struct hda_verb alc268_beep_init_verbs
[] = {
4221 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
4222 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(1)},
4223 {0x10, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(1)},
4228 * BIOS auto configuration
4230 static int alc268_parse_auto_config(struct hda_codec
*codec
)
4232 static const hda_nid_t alc268_ssids
[] = { 0x15, 0x1b, 0x14, 0 };
4233 struct alc_spec
*spec
= codec
->spec
;
4234 int err
= alc_parse_auto_config(codec
, NULL
, alc268_ssids
);
4236 if (!spec
->no_analog
&& spec
->autocfg
.speaker_pins
[0] != 0x1d) {
4237 add_mixer(spec
, alc268_beep_mixer
);
4238 add_verb(spec
, alc268_beep_init_verbs
);
4246 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4247 #include "alc268_quirks.c"
4250 static int patch_alc268(struct hda_codec
*codec
)
4252 struct alc_spec
*spec
;
4254 int i
, has_beep
, err
;
4256 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
4262 /* ALC268 has no aa-loopback mixer */
4264 board_config
= alc_board_config(codec
, ALC268_MODEL_LAST
,
4265 alc268_models
, alc268_cfg_tbl
);
4267 if (board_config
< 0)
4268 board_config
= alc_board_codec_sid_config(codec
,
4269 ALC268_MODEL_LAST
, alc268_models
, alc268_ssid_cfg_tbl
);
4271 if (board_config
< 0) {
4272 printk(KERN_INFO
"hda_codec: %s: BIOS auto-probing.\n",
4274 board_config
= ALC_MODEL_AUTO
;
4277 if (board_config
== ALC_MODEL_AUTO
) {
4278 /* automatic parse from the BIOS config */
4279 err
= alc268_parse_auto_config(codec
);
4284 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4287 "hda_codec: Cannot set up configuration "
4288 "from BIOS. Using base mode...\n");
4289 board_config
= ALC268_3ST
;
4294 if (board_config
!= ALC_MODEL_AUTO
)
4295 setup_preset(codec
, &alc268_presets
[board_config
]);
4298 for (i
= 0; i
< spec
->num_mixers
; i
++) {
4299 if (spec
->mixers
[i
] == alc268_beep_mixer
) {
4306 err
= snd_hda_attach_beep_device(codec
, 0x1);
4311 if (!query_amp_caps(codec
, 0x1d, HDA_INPUT
))
4312 /* override the amp caps for beep generator */
4313 snd_hda_override_amp_caps(codec
, 0x1d, HDA_INPUT
,
4314 (0x0c << AC_AMPCAP_OFFSET_SHIFT
) |
4315 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT
) |
4316 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT
) |
4317 (0 << AC_AMPCAP_MUTE_SHIFT
));
4320 if (!spec
->no_analog
&& !spec
->adc_nids
) {
4321 alc_auto_fill_adc_caps(codec
);
4322 alc_rebuild_imux_for_auto_mic(codec
);
4323 alc_remove_invalid_adc_nids(codec
);
4326 if (!spec
->no_analog
&& !spec
->cap_mixer
)
4327 set_capture_mixer(codec
);
4329 spec
->vmaster_nid
= 0x02;
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
);
4344 #ifdef CONFIG_SND_HDA_POWER_SAVE
4345 #define alc269_loopbacks alc880_loopbacks
4348 static const struct hda_pcm_stream alc269_44k_pcm_analog_playback
= {
4352 .rates
= SNDRV_PCM_RATE_44100
, /* fixed rate */
4353 /* NID is set in alc_build_pcms */
4355 .open
= alc_playback_pcm_open
,
4356 .prepare
= alc_playback_pcm_prepare
,
4357 .cleanup
= alc_playback_pcm_cleanup
4361 static const struct hda_pcm_stream alc269_44k_pcm_analog_capture
= {
4365 .rates
= SNDRV_PCM_RATE_44100
, /* fixed rate */
4366 /* NID is set in alc_build_pcms */
4369 #ifdef CONFIG_SND_HDA_POWER_SAVE
4370 static int alc269_mic2_for_mute_led(struct hda_codec
*codec
)
4372 switch (codec
->subsystem_id
) {
4379 static int alc269_mic2_mute_check_ps(struct hda_codec
*codec
, hda_nid_t nid
)
4381 /* update mute-LED according to the speaker mute state */
4382 if (nid
== 0x01 || nid
== 0x14) {
4384 if (snd_hda_codec_amp_read(codec
, 0x14, 0, HDA_OUTPUT
, 0) &
4389 /* mic2 vref pin is used for mute LED control */
4390 snd_hda_codec_update_cache(codec
, 0x19, 0,
4391 AC_VERB_SET_PIN_WIDGET_CONTROL
,
4394 return alc_check_power_status(codec
, nid
);
4396 #endif /* CONFIG_SND_HDA_POWER_SAVE */
4398 /* different alc269-variants */
4400 ALC269_TYPE_ALC269VA
,
4401 ALC269_TYPE_ALC269VB
,
4402 ALC269_TYPE_ALC269VC
,
4406 * BIOS auto configuration
4408 static int alc269_parse_auto_config(struct hda_codec
*codec
)
4410 static const hda_nid_t alc269_ignore
[] = { 0x1d, 0 };
4411 static const hda_nid_t alc269_ssids
[] = { 0, 0x1b, 0x14, 0x21 };
4412 static const hda_nid_t alc269va_ssids
[] = { 0x15, 0x1b, 0x14, 0 };
4413 struct alc_spec
*spec
= codec
->spec
;
4414 const hda_nid_t
*ssids
= spec
->codec_variant
== ALC269_TYPE_ALC269VA
?
4415 alc269va_ssids
: alc269_ssids
;
4417 return alc_parse_auto_config(codec
, alc269_ignore
, ssids
);
4420 static void alc269_toggle_power_output(struct hda_codec
*codec
, int power_up
)
4422 int val
= alc_read_coef_idx(codec
, 0x04);
4427 alc_write_coef_idx(codec
, 0x04, val
);
4430 static void alc269_shutup(struct hda_codec
*codec
)
4432 if ((alc_read_coef_idx(codec
, 0) & 0x00ff) == 0x017)
4433 alc269_toggle_power_output(codec
, 0);
4434 if ((alc_read_coef_idx(codec
, 0) & 0x00ff) == 0x018) {
4435 alc269_toggle_power_output(codec
, 0);
4441 static int alc269_resume(struct hda_codec
*codec
)
4443 if ((alc_read_coef_idx(codec
, 0) & 0x00ff) == 0x018) {
4444 alc269_toggle_power_output(codec
, 0);
4448 codec
->patch_ops
.init(codec
);
4450 if ((alc_read_coef_idx(codec
, 0) & 0x00ff) == 0x017) {
4451 alc269_toggle_power_output(codec
, 1);
4455 if ((alc_read_coef_idx(codec
, 0) & 0x00ff) == 0x018)
4456 alc269_toggle_power_output(codec
, 1);
4458 snd_hda_codec_resume_amp(codec
);
4459 snd_hda_codec_resume_cache(codec
);
4460 hda_call_check_power_status(codec
, 0x01);
4463 #endif /* CONFIG_PM */
4465 static void alc269_fixup_hweq(struct hda_codec
*codec
,
4466 const struct alc_fixup
*fix
, int action
)
4470 if (action
!= ALC_FIXUP_ACT_INIT
)
4472 coef
= alc_read_coef_idx(codec
, 0x1e);
4473 alc_write_coef_idx(codec
, 0x1e, coef
| 0x80);
4476 static void alc271_fixup_dmic(struct hda_codec
*codec
,
4477 const struct alc_fixup
*fix
, int action
)
4479 static const struct hda_verb verbs
[] = {
4480 {0x20, AC_VERB_SET_COEF_INDEX
, 0x0d},
4481 {0x20, AC_VERB_SET_PROC_COEF
, 0x4000},
4486 if (strcmp(codec
->chip_name
, "ALC271X"))
4488 cfg
= snd_hda_codec_get_pincfg(codec
, 0x12);
4489 if (get_defcfg_connect(cfg
) == AC_JACK_PORT_FIXED
)
4490 snd_hda_sequence_write(codec
, verbs
);
4493 static void alc269_fixup_pcm_44k(struct hda_codec
*codec
,
4494 const struct alc_fixup
*fix
, int action
)
4496 struct alc_spec
*spec
= codec
->spec
;
4498 if (action
!= ALC_FIXUP_ACT_PROBE
)
4501 /* Due to a hardware problem on Lenovo Ideadpad, we need to
4502 * fix the sample rate of analog I/O to 44.1kHz
4504 spec
->stream_analog_playback
= &alc269_44k_pcm_analog_playback
;
4505 spec
->stream_analog_capture
= &alc269_44k_pcm_analog_capture
;
4508 static void alc269_fixup_stereo_dmic(struct hda_codec
*codec
,
4509 const struct alc_fixup
*fix
, int action
)
4513 if (action
!= ALC_FIXUP_ACT_INIT
)
4515 /* The digital-mic unit sends PDM (differential signal) instead of
4516 * the standard PCM, thus you can't record a valid mono stream as is.
4517 * Below is a workaround specific to ALC269 to control the dmic
4518 * signal source as mono.
4520 coef
= alc_read_coef_idx(codec
, 0x07);
4521 alc_write_coef_idx(codec
, 0x07, coef
| 0x80);
4525 ALC269_FIXUP_SONY_VAIO
,
4526 ALC275_FIXUP_SONY_VAIO_GPIO2
,
4527 ALC269_FIXUP_DELL_M101Z
,
4528 ALC269_FIXUP_SKU_IGNORE
,
4529 ALC269_FIXUP_ASUS_G73JW
,
4530 ALC269_FIXUP_LENOVO_EAPD
,
4531 ALC275_FIXUP_SONY_HWEQ
,
4533 ALC269_FIXUP_PCM_44K
,
4534 ALC269_FIXUP_STEREO_DMIC
,
4537 static const struct alc_fixup alc269_fixups
[] = {
4538 [ALC269_FIXUP_SONY_VAIO
] = {
4539 .type
= ALC_FIXUP_VERBS
,
4540 .v
.verbs
= (const struct hda_verb
[]) {
4541 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_VREFGRD
},
4545 [ALC275_FIXUP_SONY_VAIO_GPIO2
] = {
4546 .type
= ALC_FIXUP_VERBS
,
4547 .v
.verbs
= (const struct hda_verb
[]) {
4548 {0x01, AC_VERB_SET_GPIO_MASK
, 0x04},
4549 {0x01, AC_VERB_SET_GPIO_DIRECTION
, 0x04},
4550 {0x01, AC_VERB_SET_GPIO_DATA
, 0x00},
4554 .chain_id
= ALC269_FIXUP_SONY_VAIO
4556 [ALC269_FIXUP_DELL_M101Z
] = {
4557 .type
= ALC_FIXUP_VERBS
,
4558 .v
.verbs
= (const struct hda_verb
[]) {
4559 /* Enables internal speaker */
4560 {0x20, AC_VERB_SET_COEF_INDEX
, 13},
4561 {0x20, AC_VERB_SET_PROC_COEF
, 0x4040},
4565 [ALC269_FIXUP_SKU_IGNORE
] = {
4566 .type
= ALC_FIXUP_SKU
,
4567 .v
.sku
= ALC_FIXUP_SKU_IGNORE
,
4569 [ALC269_FIXUP_ASUS_G73JW
] = {
4570 .type
= ALC_FIXUP_PINS
,
4571 .v
.pins
= (const struct alc_pincfg
[]) {
4572 { 0x17, 0x99130111 }, /* subwoofer */
4576 [ALC269_FIXUP_LENOVO_EAPD
] = {
4577 .type
= ALC_FIXUP_VERBS
,
4578 .v
.verbs
= (const struct hda_verb
[]) {
4579 {0x14, AC_VERB_SET_EAPD_BTLENABLE
, 0},
4583 [ALC275_FIXUP_SONY_HWEQ
] = {
4584 .type
= ALC_FIXUP_FUNC
,
4585 .v
.func
= alc269_fixup_hweq
,
4587 .chain_id
= ALC275_FIXUP_SONY_VAIO_GPIO2
4589 [ALC271_FIXUP_DMIC
] = {
4590 .type
= ALC_FIXUP_FUNC
,
4591 .v
.func
= alc271_fixup_dmic
,
4593 [ALC269_FIXUP_PCM_44K
] = {
4594 .type
= ALC_FIXUP_FUNC
,
4595 .v
.func
= alc269_fixup_pcm_44k
,
4597 [ALC269_FIXUP_STEREO_DMIC
] = {
4598 .type
= ALC_FIXUP_FUNC
,
4599 .v
.func
= alc269_fixup_stereo_dmic
,
4603 static const struct snd_pci_quirk alc269_fixup_tbl
[] = {
4604 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW
),
4605 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC
),
4606 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC
),
4607 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC
),
4608 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC
),
4609 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC
),
4610 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2
),
4611 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ
),
4612 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ
),
4613 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO
),
4614 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z
),
4615 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC
),
4616 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE
),
4617 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE
),
4618 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE
),
4619 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE
),
4620 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE
),
4621 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K
),
4622 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD
),
4627 static int alc269_fill_coef(struct hda_codec
*codec
)
4631 if ((alc_read_coef_idx(codec
, 0) & 0x00ff) < 0x015) {
4632 alc_write_coef_idx(codec
, 0xf, 0x960b);
4633 alc_write_coef_idx(codec
, 0xe, 0x8817);
4636 if ((alc_read_coef_idx(codec
, 0) & 0x00ff) == 0x016) {
4637 alc_write_coef_idx(codec
, 0xf, 0x960b);
4638 alc_write_coef_idx(codec
, 0xe, 0x8814);
4641 if ((alc_read_coef_idx(codec
, 0) & 0x00ff) == 0x017) {
4642 val
= alc_read_coef_idx(codec
, 0x04);
4643 /* Power up output pin */
4644 alc_write_coef_idx(codec
, 0x04, val
| (1<<11));
4647 if ((alc_read_coef_idx(codec
, 0) & 0x00ff) == 0x018) {
4648 val
= alc_read_coef_idx(codec
, 0xd);
4649 if ((val
& 0x0c00) >> 10 != 0x1) {
4650 /* Capless ramp up clock control */
4651 alc_write_coef_idx(codec
, 0xd, val
| (1<<10));
4653 val
= alc_read_coef_idx(codec
, 0x17);
4654 if ((val
& 0x01c0) >> 6 != 0x4) {
4655 /* Class D power on reset */
4656 alc_write_coef_idx(codec
, 0x17, val
| (1<<7));
4660 val
= alc_read_coef_idx(codec
, 0xd); /* Class D */
4661 alc_write_coef_idx(codec
, 0xd, val
| (1<<14));
4663 val
= alc_read_coef_idx(codec
, 0x4); /* HP */
4664 alc_write_coef_idx(codec
, 0x4, val
| (1<<11));
4671 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4672 #include "alc269_quirks.c"
4675 static int patch_alc269(struct hda_codec
*codec
)
4677 struct alc_spec
*spec
;
4678 int board_config
, coef
;
4681 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
4687 spec
->mixer_nid
= 0x0b;
4689 alc_auto_parse_customize_define(codec
);
4691 if (codec
->vendor_id
== 0x10ec0269) {
4692 spec
->codec_variant
= ALC269_TYPE_ALC269VA
;
4693 coef
= alc_read_coef_idx(codec
, 0);
4694 if ((coef
& 0x00f0) == 0x0010) {
4695 if (codec
->bus
->pci
->subsystem_vendor
== 0x1025 &&
4696 spec
->cdefine
.platform_type
== 1) {
4697 alc_codec_rename(codec
, "ALC271X");
4698 } else if ((coef
& 0xf000) == 0x2000) {
4699 alc_codec_rename(codec
, "ALC259");
4700 } else if ((coef
& 0xf000) == 0x3000) {
4701 alc_codec_rename(codec
, "ALC258");
4702 } else if ((coef
& 0xfff0) == 0x3010) {
4703 alc_codec_rename(codec
, "ALC277");
4705 alc_codec_rename(codec
, "ALC269VB");
4707 spec
->codec_variant
= ALC269_TYPE_ALC269VB
;
4708 } else if ((coef
& 0x00f0) == 0x0020) {
4710 alc_codec_rename(codec
, "ALC259");
4711 else if (coef
== 0x6023)
4712 alc_codec_rename(codec
, "ALC281X");
4713 else if (codec
->bus
->pci
->subsystem_vendor
== 0x17aa &&
4714 codec
->bus
->pci
->subsystem_device
== 0x21f3)
4715 alc_codec_rename(codec
, "ALC3202");
4717 alc_codec_rename(codec
, "ALC269VC");
4718 spec
->codec_variant
= ALC269_TYPE_ALC269VC
;
4720 alc_fix_pll_init(codec
, 0x20, 0x04, 15);
4721 alc269_fill_coef(codec
);
4724 board_config
= alc_board_config(codec
, ALC269_MODEL_LAST
,
4725 alc269_models
, alc269_cfg_tbl
);
4727 if (board_config
< 0) {
4728 printk(KERN_INFO
"hda_codec: %s: BIOS auto-probing.\n",
4730 board_config
= ALC_MODEL_AUTO
;
4733 if (board_config
== ALC_MODEL_AUTO
) {
4734 alc_pick_fixup(codec
, NULL
, alc269_fixup_tbl
, alc269_fixups
);
4735 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
4738 if (board_config
== ALC_MODEL_AUTO
) {
4739 /* automatic parse from the BIOS config */
4740 err
= alc269_parse_auto_config(codec
);
4745 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4748 "hda_codec: Cannot set up configuration "
4749 "from BIOS. Using base mode...\n");
4750 board_config
= ALC269_BASIC
;
4755 if (board_config
!= ALC_MODEL_AUTO
)
4756 setup_preset(codec
, &alc269_presets
[board_config
]);
4758 if (!spec
->no_analog
&& !spec
->adc_nids
) {
4759 alc_auto_fill_adc_caps(codec
);
4760 alc_rebuild_imux_for_auto_mic(codec
);
4761 alc_remove_invalid_adc_nids(codec
);
4764 if (!spec
->no_analog
&& !spec
->cap_mixer
)
4765 set_capture_mixer(codec
);
4767 if (!spec
->no_analog
&& has_cdefine_beep(codec
)) {
4768 err
= snd_hda_attach_beep_device(codec
, 0x1);
4773 set_beep_amp(spec
, 0x0b, 0x04, HDA_INPUT
);
4776 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
4778 spec
->vmaster_nid
= 0x02;
4780 codec
->patch_ops
= alc_patch_ops
;
4782 codec
->patch_ops
.resume
= alc269_resume
;
4784 if (board_config
== ALC_MODEL_AUTO
)
4785 spec
->init_hook
= alc_auto_init_std
;
4786 spec
->shutup
= alc269_shutup
;
4788 alc_init_jacks(codec
);
4789 #ifdef CONFIG_SND_HDA_POWER_SAVE
4790 if (!spec
->loopback
.amplist
)
4791 spec
->loopback
.amplist
= alc269_loopbacks
;
4792 if (alc269_mic2_for_mute_led(codec
))
4793 codec
->patch_ops
.check_power_status
= alc269_mic2_mute_check_ps
;
4803 static int alc861_parse_auto_config(struct hda_codec
*codec
)
4805 static const hda_nid_t alc861_ignore
[] = { 0x1d, 0 };
4806 static const hda_nid_t alc861_ssids
[] = { 0x0e, 0x0f, 0x0b, 0 };
4807 return alc_parse_auto_config(codec
, alc861_ignore
, alc861_ssids
);
4810 #ifdef CONFIG_SND_HDA_POWER_SAVE
4811 static const struct hda_amp_list alc861_loopbacks
[] = {
4812 { 0x15, HDA_INPUT
, 0 },
4813 { 0x15, HDA_INPUT
, 1 },
4814 { 0x15, HDA_INPUT
, 2 },
4815 { 0x15, HDA_INPUT
, 3 },
4821 /* Pin config fixes */
4823 PINFIX_FSC_AMILO_PI1505
,
4826 static const struct alc_fixup alc861_fixups
[] = {
4827 [PINFIX_FSC_AMILO_PI1505
] = {
4828 .type
= ALC_FIXUP_PINS
,
4829 .v
.pins
= (const struct alc_pincfg
[]) {
4830 { 0x0b, 0x0221101f }, /* HP */
4831 { 0x0f, 0x90170310 }, /* speaker */
4837 static const struct snd_pci_quirk alc861_fixup_tbl
[] = {
4838 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", PINFIX_FSC_AMILO_PI1505
),
4844 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4845 #include "alc861_quirks.c"
4848 static int patch_alc861(struct hda_codec
*codec
)
4850 struct alc_spec
*spec
;
4854 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
4860 spec
->mixer_nid
= 0x15;
4862 board_config
= alc_board_config(codec
, ALC861_MODEL_LAST
,
4863 alc861_models
, alc861_cfg_tbl
);
4865 if (board_config
< 0) {
4866 printk(KERN_INFO
"hda_codec: %s: BIOS auto-probing.\n",
4868 board_config
= ALC_MODEL_AUTO
;
4871 if (board_config
== ALC_MODEL_AUTO
) {
4872 alc_pick_fixup(codec
, NULL
, alc861_fixup_tbl
, alc861_fixups
);
4873 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
4876 if (board_config
== ALC_MODEL_AUTO
) {
4877 /* automatic parse from the BIOS config */
4878 err
= alc861_parse_auto_config(codec
);
4883 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4886 "hda_codec: Cannot set up configuration "
4887 "from BIOS. Using base mode...\n");
4888 board_config
= ALC861_3ST_DIG
;
4893 if (board_config
!= ALC_MODEL_AUTO
)
4894 setup_preset(codec
, &alc861_presets
[board_config
]);
4896 if (!spec
->no_analog
&& !spec
->adc_nids
) {
4897 alc_auto_fill_adc_caps(codec
);
4898 alc_rebuild_imux_for_auto_mic(codec
);
4899 alc_remove_invalid_adc_nids(codec
);
4902 if (!spec
->no_analog
&& !spec
->cap_mixer
)
4903 set_capture_mixer(codec
);
4905 if (!spec
->no_analog
) {
4906 err
= snd_hda_attach_beep_device(codec
, 0x23);
4911 set_beep_amp(spec
, 0x23, 0, HDA_OUTPUT
);
4914 spec
->vmaster_nid
= 0x03;
4916 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
4918 codec
->patch_ops
= alc_patch_ops
;
4919 if (board_config
== ALC_MODEL_AUTO
) {
4920 spec
->init_hook
= alc_auto_init_std
;
4921 #ifdef CONFIG_SND_HDA_POWER_SAVE
4922 spec
->power_hook
= alc_power_eapd
;
4925 #ifdef CONFIG_SND_HDA_POWER_SAVE
4926 if (!spec
->loopback
.amplist
)
4927 spec
->loopback
.amplist
= alc861_loopbacks
;
4938 * In addition, an independent DAC
4940 #ifdef CONFIG_SND_HDA_POWER_SAVE
4941 #define alc861vd_loopbacks alc880_loopbacks
4944 static int alc861vd_parse_auto_config(struct hda_codec
*codec
)
4946 static const hda_nid_t alc861vd_ignore
[] = { 0x1d, 0 };
4947 static const hda_nid_t alc861vd_ssids
[] = { 0x15, 0x1b, 0x14, 0 };
4948 return alc_parse_auto_config(codec
, alc861vd_ignore
, alc861vd_ssids
);
4952 ALC660VD_FIX_ASUS_GPIO1
4956 static const struct alc_fixup alc861vd_fixups
[] = {
4957 [ALC660VD_FIX_ASUS_GPIO1
] = {
4958 .type
= ALC_FIXUP_VERBS
,
4959 .v
.verbs
= (const struct hda_verb
[]) {
4960 {0x01, AC_VERB_SET_GPIO_MASK
, 0x03},
4961 {0x01, AC_VERB_SET_GPIO_DIRECTION
, 0x01},
4962 {0x01, AC_VERB_SET_GPIO_DATA
, 0x01},
4968 static const struct snd_pci_quirk alc861vd_fixup_tbl
[] = {
4969 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1
),
4973 static const struct hda_verb alc660vd_eapd_verbs
[] = {
4974 {0x14, AC_VERB_SET_EAPD_BTLENABLE
, 2},
4975 {0x15, AC_VERB_SET_EAPD_BTLENABLE
, 2},
4981 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4982 #include "alc861vd_quirks.c"
4985 static int patch_alc861vd(struct hda_codec
*codec
)
4987 struct alc_spec
*spec
;
4988 int err
, board_config
;
4990 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
4996 spec
->mixer_nid
= 0x0b;
4998 board_config
= alc_board_config(codec
, ALC861VD_MODEL_LAST
,
4999 alc861vd_models
, alc861vd_cfg_tbl
);
5001 if (board_config
< 0) {
5002 printk(KERN_INFO
"hda_codec: %s: BIOS auto-probing.\n",
5004 board_config
= ALC_MODEL_AUTO
;
5007 if (board_config
== ALC_MODEL_AUTO
) {
5008 alc_pick_fixup(codec
, NULL
, alc861vd_fixup_tbl
, alc861vd_fixups
);
5009 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
5012 if (board_config
== ALC_MODEL_AUTO
) {
5013 /* automatic parse from the BIOS config */
5014 err
= alc861vd_parse_auto_config(codec
);
5019 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
5022 "hda_codec: Cannot set up configuration "
5023 "from BIOS. Using base mode...\n");
5024 board_config
= ALC861VD_3ST
;
5029 if (board_config
!= ALC_MODEL_AUTO
)
5030 setup_preset(codec
, &alc861vd_presets
[board_config
]);
5032 if (codec
->vendor_id
== 0x10ec0660) {
5033 /* always turn on EAPD */
5034 add_verb(spec
, alc660vd_eapd_verbs
);
5037 if (!spec
->no_analog
&& !spec
->adc_nids
) {
5038 alc_auto_fill_adc_caps(codec
);
5039 alc_rebuild_imux_for_auto_mic(codec
);
5040 alc_remove_invalid_adc_nids(codec
);
5043 if (!spec
->no_analog
&& !spec
->cap_mixer
)
5044 set_capture_mixer(codec
);
5046 if (!spec
->no_analog
) {
5047 err
= snd_hda_attach_beep_device(codec
, 0x23);
5052 set_beep_amp(spec
, 0x0b, 0x05, HDA_INPUT
);
5055 spec
->vmaster_nid
= 0x02;
5057 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
5059 codec
->patch_ops
= alc_patch_ops
;
5061 if (board_config
== ALC_MODEL_AUTO
)
5062 spec
->init_hook
= alc_auto_init_std
;
5063 spec
->shutup
= alc_eapd_shutup
;
5064 #ifdef CONFIG_SND_HDA_POWER_SAVE
5065 if (!spec
->loopback
.amplist
)
5066 spec
->loopback
.amplist
= alc861vd_loopbacks
;
5075 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
5076 * configuration. Each pin widget can choose any input DACs and a mixer.
5077 * Each ADC is connected from a mixer of all inputs. This makes possible
5078 * 6-channel independent captures.
5080 * In addition, an independent DAC for the multi-playback (not used in this
5083 #ifdef CONFIG_SND_HDA_POWER_SAVE
5084 #define alc662_loopbacks alc880_loopbacks
5088 * BIOS auto configuration
5091 static int alc662_parse_auto_config(struct hda_codec
*codec
)
5093 static const hda_nid_t alc662_ignore
[] = { 0x1d, 0 };
5094 static const hda_nid_t alc663_ssids
[] = { 0x15, 0x1b, 0x14, 0x21 };
5095 static const hda_nid_t alc662_ssids
[] = { 0x15, 0x1b, 0x14, 0 };
5096 const hda_nid_t
*ssids
;
5098 if (codec
->vendor_id
== 0x10ec0272 || codec
->vendor_id
== 0x10ec0663 ||
5099 codec
->vendor_id
== 0x10ec0665 || codec
->vendor_id
== 0x10ec0670)
5100 ssids
= alc663_ssids
;
5102 ssids
= alc662_ssids
;
5103 return alc_parse_auto_config(codec
, alc662_ignore
, ssids
);
5106 static void alc272_fixup_mario(struct hda_codec
*codec
,
5107 const struct alc_fixup
*fix
, int action
)
5109 if (action
!= ALC_FIXUP_ACT_PROBE
)
5111 if (snd_hda_override_amp_caps(codec
, 0x2, HDA_OUTPUT
,
5112 (0x3b << AC_AMPCAP_OFFSET_SHIFT
) |
5113 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT
) |
5114 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT
) |
5115 (0 << AC_AMPCAP_MUTE_SHIFT
)))
5117 "hda_codec: failed to override amp caps for NID 0x2\n");
5121 ALC662_FIXUP_ASPIRE
,
5122 ALC662_FIXUP_IDEAPAD
,
5124 ALC662_FIXUP_CZC_P10T
,
5125 ALC662_FIXUP_SKU_IGNORE
,
5126 ALC662_FIXUP_HP_RP5800
,
5129 static const struct alc_fixup alc662_fixups
[] = {
5130 [ALC662_FIXUP_ASPIRE
] = {
5131 .type
= ALC_FIXUP_PINS
,
5132 .v
.pins
= (const struct alc_pincfg
[]) {
5133 { 0x15, 0x99130112 }, /* subwoofer */
5137 [ALC662_FIXUP_IDEAPAD
] = {
5138 .type
= ALC_FIXUP_PINS
,
5139 .v
.pins
= (const struct alc_pincfg
[]) {
5140 { 0x17, 0x99130112 }, /* subwoofer */
5144 [ALC272_FIXUP_MARIO
] = {
5145 .type
= ALC_FIXUP_FUNC
,
5146 .v
.func
= alc272_fixup_mario
,
5148 [ALC662_FIXUP_CZC_P10T
] = {
5149 .type
= ALC_FIXUP_VERBS
,
5150 .v
.verbs
= (const struct hda_verb
[]) {
5151 {0x14, AC_VERB_SET_EAPD_BTLENABLE
, 0},
5155 [ALC662_FIXUP_SKU_IGNORE
] = {
5156 .type
= ALC_FIXUP_SKU
,
5157 .v
.sku
= ALC_FIXUP_SKU_IGNORE
,
5159 [ALC662_FIXUP_HP_RP5800
] = {
5160 .type
= ALC_FIXUP_PINS
,
5161 .v
.pins
= (const struct alc_pincfg
[]) {
5162 { 0x14, 0x0221201f }, /* HP out */
5166 .chain_id
= ALC662_FIXUP_SKU_IGNORE
5170 static const struct snd_pci_quirk alc662_fixup_tbl
[] = {
5171 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE
),
5172 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE
),
5173 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE
),
5174 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800
),
5175 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD
),
5176 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD
),
5177 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD
),
5178 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T
),
5182 static const struct alc_model_fixup alc662_fixup_models
[] = {
5183 {.id
= ALC272_FIXUP_MARIO
, .name
= "mario"},
5190 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
5191 #include "alc662_quirks.c"
5194 static int patch_alc662(struct hda_codec
*codec
)
5196 struct alc_spec
*spec
;
5197 int err
, board_config
;
5200 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
5206 spec
->mixer_nid
= 0x0b;
5208 alc_auto_parse_customize_define(codec
);
5210 alc_fix_pll_init(codec
, 0x20, 0x04, 15);
5212 coef
= alc_read_coef_idx(codec
, 0);
5213 if (coef
== 0x8020 || coef
== 0x8011)
5214 alc_codec_rename(codec
, "ALC661");
5215 else if (coef
& (1 << 14) &&
5216 codec
->bus
->pci
->subsystem_vendor
== 0x1025 &&
5217 spec
->cdefine
.platform_type
== 1)
5218 alc_codec_rename(codec
, "ALC272X");
5219 else if (coef
== 0x4011)
5220 alc_codec_rename(codec
, "ALC656");
5222 board_config
= alc_board_config(codec
, ALC662_MODEL_LAST
,
5223 alc662_models
, alc662_cfg_tbl
);
5224 if (board_config
< 0) {
5225 printk(KERN_INFO
"hda_codec: %s: BIOS auto-probing.\n",
5227 board_config
= ALC_MODEL_AUTO
;
5230 if (board_config
== ALC_MODEL_AUTO
) {
5231 alc_pick_fixup(codec
, alc662_fixup_models
,
5232 alc662_fixup_tbl
, alc662_fixups
);
5233 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
5234 /* automatic parse from the BIOS config */
5235 err
= alc662_parse_auto_config(codec
);
5240 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
5243 "hda_codec: Cannot set up configuration "
5244 "from BIOS. Using base mode...\n");
5245 board_config
= ALC662_3ST_2ch_DIG
;
5250 if (board_config
!= ALC_MODEL_AUTO
)
5251 setup_preset(codec
, &alc662_presets
[board_config
]);
5253 if (!spec
->no_analog
&& !spec
->adc_nids
) {
5254 alc_auto_fill_adc_caps(codec
);
5255 alc_rebuild_imux_for_auto_mic(codec
);
5256 alc_remove_invalid_adc_nids(codec
);
5259 if (!spec
->no_analog
&& !spec
->cap_mixer
)
5260 set_capture_mixer(codec
);
5262 if (!spec
->no_analog
&& has_cdefine_beep(codec
)) {
5263 err
= snd_hda_attach_beep_device(codec
, 0x1);
5268 switch (codec
->vendor_id
) {
5270 set_beep_amp(spec
, 0x0b, 0x05, HDA_INPUT
);
5275 set_beep_amp(spec
, 0x0b, 0x04, HDA_INPUT
);
5278 set_beep_amp(spec
, 0x0b, 0x03, HDA_INPUT
);
5282 spec
->vmaster_nid
= 0x02;
5284 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
5286 codec
->patch_ops
= alc_patch_ops
;
5287 if (board_config
== ALC_MODEL_AUTO
)
5288 spec
->init_hook
= alc_auto_init_std
;
5289 spec
->shutup
= alc_eapd_shutup
;
5291 alc_init_jacks(codec
);
5293 #ifdef CONFIG_SND_HDA_POWER_SAVE
5294 if (!spec
->loopback
.amplist
)
5295 spec
->loopback
.amplist
= alc662_loopbacks
;
5301 static int patch_alc888(struct hda_codec
*codec
)
5303 if ((alc_read_coef_idx(codec
, 0) & 0x00f0)==0x0030){
5304 kfree(codec
->chip_name
);
5305 if (codec
->vendor_id
== 0x10ec0887)
5306 codec
->chip_name
= kstrdup("ALC887-VD", GFP_KERNEL
);
5308 codec
->chip_name
= kstrdup("ALC888-VD", GFP_KERNEL
);
5309 if (!codec
->chip_name
) {
5313 return patch_alc662(codec
);
5315 return patch_alc882(codec
);
5318 static int patch_alc899(struct hda_codec
*codec
)
5320 if ((alc_read_coef_idx(codec
, 0) & 0x2000) != 0x2000) {
5321 kfree(codec
->chip_name
);
5322 codec
->chip_name
= kstrdup("ALC898", GFP_KERNEL
);
5324 return patch_alc882(codec
);
5331 static int alc680_parse_auto_config(struct hda_codec
*codec
)
5333 return alc_parse_auto_config(codec
, NULL
, NULL
);
5338 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
5339 #include "alc680_quirks.c"
5342 static int patch_alc680(struct hda_codec
*codec
)
5344 struct alc_spec
*spec
;
5348 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
5354 /* ALC680 has no aa-loopback mixer */
5356 board_config
= alc_board_config(codec
, ALC680_MODEL_LAST
,
5357 alc680_models
, alc680_cfg_tbl
);
5359 if (board_config
< 0) {
5360 printk(KERN_INFO
"hda_codec: %s: BIOS auto-probing.\n",
5362 board_config
= ALC_MODEL_AUTO
;
5365 if (board_config
== ALC_MODEL_AUTO
) {
5366 /* automatic parse from the BIOS config */
5367 err
= alc680_parse_auto_config(codec
);
5372 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
5375 "hda_codec: Cannot set up configuration "
5376 "from BIOS. Using base mode...\n");
5377 board_config
= ALC680_BASE
;
5382 if (board_config
!= ALC_MODEL_AUTO
) {
5383 setup_preset(codec
, &alc680_presets
[board_config
]);
5384 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
5385 spec
->stream_analog_capture
= &alc680_pcm_analog_auto_capture
;
5389 if (!spec
->no_analog
&& !spec
->adc_nids
) {
5390 alc_auto_fill_adc_caps(codec
);
5391 alc_rebuild_imux_for_auto_mic(codec
);
5392 alc_remove_invalid_adc_nids(codec
);
5395 if (!spec
->no_analog
&& !spec
->cap_mixer
)
5396 set_capture_mixer(codec
);
5398 spec
->vmaster_nid
= 0x02;
5400 codec
->patch_ops
= alc_patch_ops
;
5401 if (board_config
== ALC_MODEL_AUTO
)
5402 spec
->init_hook
= alc_auto_init_std
;
5410 static const struct hda_codec_preset snd_hda_preset_realtek
[] = {
5411 { .id
= 0x10ec0221, .name
= "ALC221", .patch
= patch_alc269
},
5412 { .id
= 0x10ec0260, .name
= "ALC260", .patch
= patch_alc260
},
5413 { .id
= 0x10ec0262, .name
= "ALC262", .patch
= patch_alc262
},
5414 { .id
= 0x10ec0267, .name
= "ALC267", .patch
= patch_alc268
},
5415 { .id
= 0x10ec0268, .name
= "ALC268", .patch
= patch_alc268
},
5416 { .id
= 0x10ec0269, .name
= "ALC269", .patch
= patch_alc269
},
5417 { .id
= 0x10ec0270, .name
= "ALC270", .patch
= patch_alc269
},
5418 { .id
= 0x10ec0272, .name
= "ALC272", .patch
= patch_alc662
},
5419 { .id
= 0x10ec0275, .name
= "ALC275", .patch
= patch_alc269
},
5420 { .id
= 0x10ec0276, .name
= "ALC276", .patch
= patch_alc269
},
5421 { .id
= 0x10ec0861, .rev
= 0x100340, .name
= "ALC660",
5422 .patch
= patch_alc861
},
5423 { .id
= 0x10ec0660, .name
= "ALC660-VD", .patch
= patch_alc861vd
},
5424 { .id
= 0x10ec0861, .name
= "ALC861", .patch
= patch_alc861
},
5425 { .id
= 0x10ec0862, .name
= "ALC861-VD", .patch
= patch_alc861vd
},
5426 { .id
= 0x10ec0662, .rev
= 0x100002, .name
= "ALC662 rev2",
5427 .patch
= patch_alc882
},
5428 { .id
= 0x10ec0662, .rev
= 0x100101, .name
= "ALC662 rev1",
5429 .patch
= patch_alc662
},
5430 { .id
= 0x10ec0662, .rev
= 0x100300, .name
= "ALC662 rev3",
5431 .patch
= patch_alc662
},
5432 { .id
= 0x10ec0663, .name
= "ALC663", .patch
= patch_alc662
},
5433 { .id
= 0x10ec0665, .name
= "ALC665", .patch
= patch_alc662
},
5434 { .id
= 0x10ec0670, .name
= "ALC670", .patch
= patch_alc662
},
5435 { .id
= 0x10ec0680, .name
= "ALC680", .patch
= patch_alc680
},
5436 { .id
= 0x10ec0880, .name
= "ALC880", .patch
= patch_alc880
},
5437 { .id
= 0x10ec0882, .name
= "ALC882", .patch
= patch_alc882
},
5438 { .id
= 0x10ec0883, .name
= "ALC883", .patch
= patch_alc882
},
5439 { .id
= 0x10ec0885, .rev
= 0x100101, .name
= "ALC889A",
5440 .patch
= patch_alc882
},
5441 { .id
= 0x10ec0885, .rev
= 0x100103, .name
= "ALC889A",
5442 .patch
= patch_alc882
},
5443 { .id
= 0x10ec0885, .name
= "ALC885", .patch
= patch_alc882
},
5444 { .id
= 0x10ec0887, .name
= "ALC887", .patch
= patch_alc888
},
5445 { .id
= 0x10ec0888, .rev
= 0x100101, .name
= "ALC1200",
5446 .patch
= patch_alc882
},
5447 { .id
= 0x10ec0888, .name
= "ALC888", .patch
= patch_alc888
},
5448 { .id
= 0x10ec0889, .name
= "ALC889", .patch
= patch_alc882
},
5449 { .id
= 0x10ec0892, .name
= "ALC892", .patch
= patch_alc662
},
5450 { .id
= 0x10ec0899, .name
= "ALC899", .patch
= patch_alc899
},
5454 MODULE_ALIAS("snd-hda-codec-id:10ec*");
5456 MODULE_LICENSE("GPL");
5457 MODULE_DESCRIPTION("Realtek HD-audio codec");
5459 static struct hda_codec_preset_list realtek_list
= {
5460 .preset
= snd_hda_preset_realtek
,
5461 .owner
= THIS_MODULE
,
5464 static int __init
patch_realtek_init(void)
5466 return snd_hda_add_codec_preset(&realtek_list
);
5469 static void __exit
patch_realtek_exit(void)
5471 snd_hda_delete_codec_preset(&realtek_list
);
5474 module_init(patch_realtek_init
)
5475 module_exit(patch_realtek_exit
)