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 */
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_lines
|| !spec
->automute
)
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
;
571 detect_jacks(codec
, ARRAY_SIZE(spec
->autocfg
.hp_pins
),
572 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 if (!spec
->automute
|| !spec
->detect_line
)
583 spec
->line_jack_present
=
584 detect_jacks(codec
, ARRAY_SIZE(spec
->autocfg
.line_out_pins
),
585 spec
->autocfg
.line_out_pins
);
586 update_speakers(codec
);
589 #define get_connection_index(codec, mux, nid) \
590 snd_hda_get_conn_index(codec, mux, nid, 0)
592 /* standard mic auto-switch helper */
593 static void alc_mic_automute(struct hda_codec
*codec
)
595 struct alc_spec
*spec
= codec
->spec
;
596 hda_nid_t
*pins
= spec
->imux_pins
;
598 if (!spec
->auto_mic
|| !spec
->auto_mic_valid_imux
)
600 if (snd_BUG_ON(!spec
->adc_nids
))
602 if (snd_BUG_ON(spec
->int_mic_idx
< 0 || spec
->ext_mic_idx
< 0))
605 if (snd_hda_jack_detect(codec
, pins
[spec
->ext_mic_idx
]))
606 alc_mux_select(codec
, 0, spec
->ext_mic_idx
, false);
607 else if (spec
->dock_mic_idx
>= 0 &&
608 snd_hda_jack_detect(codec
, pins
[spec
->dock_mic_idx
]))
609 alc_mux_select(codec
, 0, spec
->dock_mic_idx
, false);
611 alc_mux_select(codec
, 0, spec
->int_mic_idx
, false);
613 snd_hda_input_jack_report(codec
, pins
[spec
->ext_mic_idx
]);
614 if (spec
->dock_mic_idx
>= 0)
615 snd_hda_input_jack_report(codec
, pins
[spec
->dock_mic_idx
]);
618 /* unsolicited event for HP jack sensing */
619 static void alc_sku_unsol_event(struct hda_codec
*codec
, unsigned int res
)
621 if (codec
->vendor_id
== 0x10ec0880)
627 alc_hp_automute(codec
);
629 case ALC_FRONT_EVENT
:
630 alc_line_automute(codec
);
633 alc_mic_automute(codec
);
638 /* call init functions of standard auto-mute helpers */
639 static void alc_inithook(struct hda_codec
*codec
)
641 alc_hp_automute(codec
);
642 alc_line_automute(codec
);
643 alc_mic_automute(codec
);
646 /* additional initialization for ALC888 variants */
647 static void alc888_coef_init(struct hda_codec
*codec
)
651 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_COEF_INDEX
, 0);
652 tmp
= snd_hda_codec_read(codec
, 0x20, 0, AC_VERB_GET_PROC_COEF
, 0);
653 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_COEF_INDEX
, 7);
654 if ((tmp
& 0xf0) == 0x20)
656 snd_hda_codec_read(codec
, 0x20, 0,
657 AC_VERB_SET_PROC_COEF
, 0x830);
660 snd_hda_codec_read(codec
, 0x20, 0,
661 AC_VERB_SET_PROC_COEF
, 0x3030);
664 /* additional initialization for ALC889 variants */
665 static void alc889_coef_init(struct hda_codec
*codec
)
669 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_COEF_INDEX
, 7);
670 tmp
= snd_hda_codec_read(codec
, 0x20, 0, AC_VERB_GET_PROC_COEF
, 0);
671 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_COEF_INDEX
, 7);
672 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_PROC_COEF
, tmp
|0x2010);
675 /* turn on/off EAPD control (only if available) */
676 static void set_eapd(struct hda_codec
*codec
, hda_nid_t nid
, int on
)
678 if (get_wcaps_type(get_wcaps(codec
, nid
)) != AC_WID_PIN
)
680 if (snd_hda_query_pin_caps(codec
, nid
) & AC_PINCAP_EAPD
)
681 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_EAPD_BTLENABLE
,
685 /* turn on/off EAPD controls of the codec */
686 static void alc_auto_setup_eapd(struct hda_codec
*codec
, bool on
)
688 /* We currently only handle front, HP */
689 static hda_nid_t pins
[] = {
690 0x0f, 0x10, 0x14, 0x15, 0
693 for (p
= pins
; *p
; p
++)
694 set_eapd(codec
, *p
, on
);
697 /* generic shutup callback;
698 * just turning off EPAD and a little pause for avoiding pop-noise
700 static void alc_eapd_shutup(struct hda_codec
*codec
)
702 alc_auto_setup_eapd(codec
, false);
706 /* generic EAPD initialization */
707 static void alc_auto_init_amp(struct hda_codec
*codec
, int type
)
711 alc_auto_setup_eapd(codec
, true);
714 snd_hda_sequence_write(codec
, alc_gpio1_init_verbs
);
717 snd_hda_sequence_write(codec
, alc_gpio2_init_verbs
);
720 snd_hda_sequence_write(codec
, alc_gpio3_init_verbs
);
722 case ALC_INIT_DEFAULT
:
723 switch (codec
->vendor_id
) {
725 snd_hda_codec_write(codec
, 0x1a, 0,
726 AC_VERB_SET_COEF_INDEX
, 7);
727 tmp
= snd_hda_codec_read(codec
, 0x1a, 0,
728 AC_VERB_GET_PROC_COEF
, 0);
729 snd_hda_codec_write(codec
, 0x1a, 0,
730 AC_VERB_SET_COEF_INDEX
, 7);
731 snd_hda_codec_write(codec
, 0x1a, 0,
732 AC_VERB_SET_PROC_COEF
,
741 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
742 alc889_coef_init(codec
);
745 alc888_coef_init(codec
);
747 #if 0 /* XXX: This may cause the silent output on speaker on some machines */
750 snd_hda_codec_write(codec
, 0x20, 0,
751 AC_VERB_SET_COEF_INDEX
, 7);
752 tmp
= snd_hda_codec_read(codec
, 0x20, 0,
753 AC_VERB_GET_PROC_COEF
, 0);
754 snd_hda_codec_write(codec
, 0x20, 0,
755 AC_VERB_SET_COEF_INDEX
, 7);
756 snd_hda_codec_write(codec
, 0x20, 0,
757 AC_VERB_SET_PROC_COEF
,
767 * Auto-Mute mode mixer enum support
769 static int alc_automute_mode_info(struct snd_kcontrol
*kcontrol
,
770 struct snd_ctl_elem_info
*uinfo
)
772 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
773 struct alc_spec
*spec
= codec
->spec
;
774 static const char * const texts2
[] = {
775 "Disabled", "Enabled"
777 static const char * const texts3
[] = {
778 "Disabled", "Speaker Only", "Line-Out+Speaker"
780 const char * const *texts
;
782 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
784 if (spec
->automute_hp_lo
) {
785 uinfo
->value
.enumerated
.items
= 3;
788 uinfo
->value
.enumerated
.items
= 2;
791 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
)
792 uinfo
->value
.enumerated
.item
= uinfo
->value
.enumerated
.items
- 1;
793 strcpy(uinfo
->value
.enumerated
.name
,
794 texts
[uinfo
->value
.enumerated
.item
]);
798 static int alc_automute_mode_get(struct snd_kcontrol
*kcontrol
,
799 struct snd_ctl_elem_value
*ucontrol
)
801 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
802 struct alc_spec
*spec
= codec
->spec
;
806 else if (!spec
->automute_lines
)
810 ucontrol
->value
.enumerated
.item
[0] = val
;
814 static int alc_automute_mode_put(struct snd_kcontrol
*kcontrol
,
815 struct snd_ctl_elem_value
*ucontrol
)
817 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
818 struct alc_spec
*spec
= codec
->spec
;
820 switch (ucontrol
->value
.enumerated
.item
[0]) {
827 if (spec
->automute
&& !spec
->automute_lines
)
830 spec
->automute_lines
= 0;
833 if (!spec
->automute_hp_lo
)
835 if (spec
->automute
&& spec
->automute_lines
)
838 spec
->automute_lines
= 1;
843 update_speakers(codec
);
847 static const struct snd_kcontrol_new alc_automute_mode_enum
= {
848 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
849 .name
= "Auto-Mute Mode",
850 .info
= alc_automute_mode_info
,
851 .get
= alc_automute_mode_get
,
852 .put
= alc_automute_mode_put
,
855 static struct snd_kcontrol_new
*alc_kcontrol_new(struct alc_spec
*spec
)
857 snd_array_init(&spec
->kctls
, sizeof(struct snd_kcontrol_new
), 32);
858 return snd_array_new(&spec
->kctls
);
861 static int alc_add_automute_mode_enum(struct hda_codec
*codec
)
863 struct alc_spec
*spec
= codec
->spec
;
864 struct snd_kcontrol_new
*knew
;
866 knew
= alc_kcontrol_new(spec
);
869 *knew
= alc_automute_mode_enum
;
870 knew
->name
= kstrdup("Auto-Mute Mode", GFP_KERNEL
);
877 * Check the availability of HP/line-out auto-mute;
878 * Set up appropriately if really supported
880 static void alc_init_auto_hp(struct hda_codec
*codec
)
882 struct alc_spec
*spec
= codec
->spec
;
883 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
889 if (cfg
->line_out_pins
[0])
891 if (cfg
->speaker_pins
[0])
893 if (present
< 2) /* need two different output types */
896 spec
->automute_hp_lo
= 1; /* both HP and LO automute */
898 if (!cfg
->speaker_pins
[0] &&
899 cfg
->line_out_type
== AUTO_PIN_SPEAKER_OUT
) {
900 memcpy(cfg
->speaker_pins
, cfg
->line_out_pins
,
901 sizeof(cfg
->speaker_pins
));
902 cfg
->speaker_outs
= cfg
->line_outs
;
905 if (!cfg
->hp_pins
[0] &&
906 cfg
->line_out_type
== AUTO_PIN_HP_OUT
) {
907 memcpy(cfg
->hp_pins
, cfg
->line_out_pins
,
908 sizeof(cfg
->hp_pins
));
909 cfg
->hp_outs
= cfg
->line_outs
;
912 for (i
= 0; i
< cfg
->hp_outs
; i
++) {
913 hda_nid_t nid
= cfg
->hp_pins
[i
];
914 if (!is_jack_detectable(codec
, nid
))
916 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
918 snd_hda_codec_write_cache(codec
, nid
, 0,
919 AC_VERB_SET_UNSOLICITED_ENABLE
,
920 AC_USRSP_EN
| ALC_HP_EVENT
);
922 spec
->automute_mode
= ALC_AUTOMUTE_PIN
;
924 if (spec
->automute
&& cfg
->line_out_pins
[0] &&
925 cfg
->speaker_pins
[0] &&
926 cfg
->line_out_pins
[0] != cfg
->hp_pins
[0] &&
927 cfg
->line_out_pins
[0] != cfg
->speaker_pins
[0]) {
928 for (i
= 0; i
< cfg
->line_outs
; i
++) {
929 hda_nid_t nid
= cfg
->line_out_pins
[i
];
930 if (!is_jack_detectable(codec
, nid
))
932 snd_printdd("realtek: Enable Line-Out auto-muting "
933 "on NID 0x%x\n", nid
);
934 snd_hda_codec_write_cache(codec
, nid
, 0,
935 AC_VERB_SET_UNSOLICITED_ENABLE
,
936 AC_USRSP_EN
| ALC_FRONT_EVENT
);
937 spec
->detect_line
= 1;
939 spec
->automute_lines
= spec
->detect_line
;
942 if (spec
->automute
) {
943 /* create a control for automute mode */
944 alc_add_automute_mode_enum(codec
);
945 spec
->unsol_event
= alc_sku_unsol_event
;
949 /* return the position of NID in the list, or -1 if not found */
950 static int find_idx_in_nid_list(hda_nid_t nid
, const hda_nid_t
*list
, int nums
)
953 for (i
= 0; i
< nums
; i
++)
959 /* check whether dynamic ADC-switching is available */
960 static bool alc_check_dyn_adc_switch(struct hda_codec
*codec
)
962 struct alc_spec
*spec
= codec
->spec
;
963 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
967 if (imux
!= spec
->input_mux
) /* no dynamic imux? */
970 for (n
= 0; n
< spec
->num_adc_nids
; n
++) {
971 cap
= spec
->private_capsrc_nids
[n
];
972 for (i
= 0; i
< imux
->num_items
; i
++) {
973 pin
= spec
->imux_pins
[i
];
976 if (get_connection_index(codec
, cap
, pin
) < 0)
979 if (i
>= imux
->num_items
)
980 return true; /* no ADC-switch is needed */
983 for (i
= 0; i
< imux
->num_items
; i
++) {
984 pin
= spec
->imux_pins
[i
];
985 for (n
= 0; n
< spec
->num_adc_nids
; n
++) {
986 cap
= spec
->private_capsrc_nids
[n
];
987 idx
= get_connection_index(codec
, cap
, pin
);
989 imux
->items
[i
].index
= idx
;
990 spec
->dyn_adc_idx
[i
] = n
;
996 snd_printdd("realtek: enabling ADC switching\n");
997 spec
->dyn_adc_switch
= 1;
1001 /* rebuild imux for matching with the given auto-mic pins (if not yet) */
1002 static bool alc_rebuild_imux_for_auto_mic(struct hda_codec
*codec
)
1004 struct alc_spec
*spec
= codec
->spec
;
1005 struct hda_input_mux
*imux
;
1006 static char * const texts
[3] = {
1007 "Mic", "Internal Mic", "Dock Mic"
1011 if (!spec
->auto_mic
)
1013 imux
= &spec
->private_imux
[0];
1014 if (spec
->input_mux
== imux
)
1016 spec
->imux_pins
[0] = spec
->ext_mic_pin
;
1017 spec
->imux_pins
[1] = spec
->int_mic_pin
;
1018 spec
->imux_pins
[2] = spec
->dock_mic_pin
;
1019 for (i
= 0; i
< 3; i
++) {
1020 strcpy(imux
->items
[i
].label
, texts
[i
]);
1021 if (spec
->imux_pins
[i
])
1022 imux
->num_items
= i
+ 1;
1024 spec
->num_mux_defs
= 1;
1025 spec
->input_mux
= imux
;
1029 /* check whether all auto-mic pins are valid; setup indices if OK */
1030 static bool alc_auto_mic_check_imux(struct hda_codec
*codec
)
1032 struct alc_spec
*spec
= codec
->spec
;
1033 const struct hda_input_mux
*imux
;
1035 if (!spec
->auto_mic
)
1037 if (spec
->auto_mic_valid_imux
)
1038 return true; /* already checked */
1040 /* fill up imux indices */
1041 if (!alc_check_dyn_adc_switch(codec
)) {
1046 imux
= spec
->input_mux
;
1047 spec
->ext_mic_idx
= find_idx_in_nid_list(spec
->ext_mic_pin
,
1048 spec
->imux_pins
, imux
->num_items
);
1049 spec
->int_mic_idx
= find_idx_in_nid_list(spec
->int_mic_pin
,
1050 spec
->imux_pins
, imux
->num_items
);
1051 spec
->dock_mic_idx
= find_idx_in_nid_list(spec
->dock_mic_pin
,
1052 spec
->imux_pins
, imux
->num_items
);
1053 if (spec
->ext_mic_idx
< 0 || spec
->int_mic_idx
< 0) {
1055 return false; /* no corresponding imux */
1058 snd_hda_codec_write_cache(codec
, spec
->ext_mic_pin
, 0,
1059 AC_VERB_SET_UNSOLICITED_ENABLE
,
1060 AC_USRSP_EN
| ALC_MIC_EVENT
);
1061 if (spec
->dock_mic_pin
)
1062 snd_hda_codec_write_cache(codec
, spec
->dock_mic_pin
, 0,
1063 AC_VERB_SET_UNSOLICITED_ENABLE
,
1064 AC_USRSP_EN
| ALC_MIC_EVENT
);
1066 spec
->auto_mic_valid_imux
= 1;
1072 * Check the availability of auto-mic switch;
1073 * Set up if really supported
1075 static void alc_init_auto_mic(struct hda_codec
*codec
)
1077 struct alc_spec
*spec
= codec
->spec
;
1078 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
1079 hda_nid_t fixed
, ext
, dock
;
1082 spec
->ext_mic_idx
= spec
->int_mic_idx
= spec
->dock_mic_idx
= -1;
1084 fixed
= ext
= dock
= 0;
1085 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
1086 hda_nid_t nid
= cfg
->inputs
[i
].pin
;
1087 unsigned int defcfg
;
1088 defcfg
= snd_hda_codec_get_pincfg(codec
, nid
);
1089 switch (snd_hda_get_input_pin_attr(defcfg
)) {
1090 case INPUT_PIN_ATTR_INT
:
1092 return; /* already occupied */
1093 if (cfg
->inputs
[i
].type
!= AUTO_PIN_MIC
)
1094 return; /* invalid type */
1097 case INPUT_PIN_ATTR_UNUSED
:
1098 return; /* invalid entry */
1099 case INPUT_PIN_ATTR_DOCK
:
1101 return; /* already occupied */
1102 if (cfg
->inputs
[i
].type
> AUTO_PIN_LINE_IN
)
1103 return; /* invalid type */
1108 return; /* already occupied */
1109 if (cfg
->inputs
[i
].type
!= AUTO_PIN_MIC
)
1110 return; /* invalid type */
1121 if (!is_jack_detectable(codec
, ext
))
1122 return; /* no unsol support */
1123 if (dock
&& !is_jack_detectable(codec
, dock
))
1124 return; /* no unsol support */
1126 /* check imux indices */
1127 spec
->ext_mic_pin
= ext
;
1128 spec
->int_mic_pin
= fixed
;
1129 spec
->dock_mic_pin
= dock
;
1132 if (!alc_auto_mic_check_imux(codec
))
1135 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1137 spec
->unsol_event
= alc_sku_unsol_event
;
1140 /* check the availabilities of auto-mute and auto-mic switches */
1141 static void alc_auto_check_switches(struct hda_codec
*codec
)
1143 alc_init_auto_hp(codec
);
1144 alc_init_auto_mic(codec
);
1148 * Realtek SSID verification
1151 /* Could be any non-zero and even value. When used as fixup, tells
1152 * the driver to ignore any present sku defines.
1154 #define ALC_FIXUP_SKU_IGNORE (2)
1156 static int alc_auto_parse_customize_define(struct hda_codec
*codec
)
1158 unsigned int ass
, tmp
, i
;
1160 struct alc_spec
*spec
= codec
->spec
;
1162 spec
->cdefine
.enable_pcbeep
= 1; /* assume always enabled */
1164 if (spec
->cdefine
.fixup
) {
1165 ass
= spec
->cdefine
.sku_cfg
;
1166 if (ass
== ALC_FIXUP_SKU_IGNORE
)
1171 ass
= codec
->subsystem_id
& 0xffff;
1172 if (ass
!= codec
->bus
->pci
->subsystem_device
&& (ass
& 1))
1176 if (codec
->vendor_id
== 0x10ec0260)
1178 ass
= snd_hda_codec_get_pincfg(codec
, nid
);
1181 printk(KERN_INFO
"hda_codec: %s: SKU not ready 0x%08x\n",
1182 codec
->chip_name
, ass
);
1188 for (i
= 1; i
< 16; i
++) {
1192 if (((ass
>> 16) & 0xf) != tmp
)
1195 spec
->cdefine
.port_connectivity
= ass
>> 30;
1196 spec
->cdefine
.enable_pcbeep
= (ass
& 0x100000) >> 20;
1197 spec
->cdefine
.check_sum
= (ass
>> 16) & 0xf;
1198 spec
->cdefine
.customization
= ass
>> 8;
1200 spec
->cdefine
.sku_cfg
= ass
;
1201 spec
->cdefine
.external_amp
= (ass
& 0x38) >> 3;
1202 spec
->cdefine
.platform_type
= (ass
& 0x4) >> 2;
1203 spec
->cdefine
.swap
= (ass
& 0x2) >> 1;
1204 spec
->cdefine
.override
= ass
& 0x1;
1206 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1207 nid
, spec
->cdefine
.sku_cfg
);
1208 snd_printd("SKU: port_connectivity=0x%x\n",
1209 spec
->cdefine
.port_connectivity
);
1210 snd_printd("SKU: enable_pcbeep=0x%x\n", spec
->cdefine
.enable_pcbeep
);
1211 snd_printd("SKU: check_sum=0x%08x\n", spec
->cdefine
.check_sum
);
1212 snd_printd("SKU: customization=0x%08x\n", spec
->cdefine
.customization
);
1213 snd_printd("SKU: external_amp=0x%x\n", spec
->cdefine
.external_amp
);
1214 snd_printd("SKU: platform_type=0x%x\n", spec
->cdefine
.platform_type
);
1215 snd_printd("SKU: swap=0x%x\n", spec
->cdefine
.swap
);
1216 snd_printd("SKU: override=0x%x\n", spec
->cdefine
.override
);
1221 /* return true if the given NID is found in the list */
1222 static bool found_in_nid_list(hda_nid_t nid
, const hda_nid_t
*list
, int nums
)
1224 return find_idx_in_nid_list(nid
, list
, nums
) >= 0;
1227 /* check subsystem ID and set up device-specific initialization;
1228 * return 1 if initialized, 0 if invalid SSID
1230 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1231 * 31 ~ 16 : Manufacture ID
1233 * 7 ~ 0 : Assembly ID
1234 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1236 static int alc_subsystem_id(struct hda_codec
*codec
,
1237 hda_nid_t porta
, hda_nid_t porte
,
1238 hda_nid_t portd
, hda_nid_t porti
)
1240 unsigned int ass
, tmp
, i
;
1242 struct alc_spec
*spec
= codec
->spec
;
1244 if (spec
->cdefine
.fixup
) {
1245 ass
= spec
->cdefine
.sku_cfg
;
1246 if (ass
== ALC_FIXUP_SKU_IGNORE
)
1251 ass
= codec
->subsystem_id
& 0xffff;
1252 if ((ass
!= codec
->bus
->pci
->subsystem_device
) && (ass
& 1))
1255 /* invalid SSID, check the special NID pin defcfg instead */
1257 * 31~30 : port connectivity
1260 * 19~16 : Check sum (15:1)
1265 if (codec
->vendor_id
== 0x10ec0260)
1267 ass
= snd_hda_codec_get_pincfg(codec
, nid
);
1268 snd_printd("realtek: No valid SSID, "
1269 "checking pincfg 0x%08x for NID 0x%x\n",
1273 if ((ass
>> 30) != 1) /* no physical connection */
1278 for (i
= 1; i
< 16; i
++) {
1282 if (((ass
>> 16) & 0xf) != tmp
)
1285 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1286 ass
& 0xffff, codec
->vendor_id
);
1290 * 2 : 0 --> Desktop, 1 --> Laptop
1291 * 3~5 : External Amplifier control
1294 tmp
= (ass
& 0x38) >> 3; /* external Amp control */
1297 spec
->init_amp
= ALC_INIT_GPIO1
;
1300 spec
->init_amp
= ALC_INIT_GPIO2
;
1303 spec
->init_amp
= ALC_INIT_GPIO3
;
1307 spec
->init_amp
= ALC_INIT_DEFAULT
;
1311 /* is laptop or Desktop and enable the function "Mute internal speaker
1312 * when the external headphone out jack is plugged"
1314 if (!(ass
& 0x8000))
1317 * 10~8 : Jack location
1318 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1320 * 15 : 1 --> enable the function "Mute internal speaker
1321 * when the external headphone out jack is plugged"
1323 if (!spec
->autocfg
.hp_pins
[0]) {
1325 tmp
= (ass
>> 11) & 0x3; /* HP to chassis */
1336 if (found_in_nid_list(nid
, spec
->autocfg
.line_out_pins
,
1337 spec
->autocfg
.line_outs
))
1339 spec
->autocfg
.hp_pins
[0] = nid
;
1344 /* Check the validity of ALC subsystem-id
1345 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1346 static void alc_ssid_check(struct hda_codec
*codec
, const hda_nid_t
*ports
)
1348 if (!alc_subsystem_id(codec
, ports
[0], ports
[1], ports
[2], ports
[3])) {
1349 struct alc_spec
*spec
= codec
->spec
;
1350 snd_printd("realtek: "
1351 "Enable default setup for auto mode as fallback\n");
1352 spec
->init_amp
= ALC_INIT_DEFAULT
;
1357 * Fix-up pin default configurations and add default verbs
1365 struct alc_model_fixup
{
1376 const struct alc_pincfg
*pins
;
1377 const struct hda_verb
*verbs
;
1378 void (*func
)(struct hda_codec
*codec
,
1379 const struct alc_fixup
*fix
,
1393 ALC_FIXUP_ACT_PRE_PROBE
,
1394 ALC_FIXUP_ACT_PROBE
,
1398 static void alc_apply_fixup(struct hda_codec
*codec
, int action
)
1400 struct alc_spec
*spec
= codec
->spec
;
1401 int id
= spec
->fixup_id
;
1402 #ifdef CONFIG_SND_DEBUG_VERBOSE
1403 const char *modelname
= spec
->fixup_name
;
1407 if (!spec
->fixup_list
)
1411 const struct alc_fixup
*fix
= spec
->fixup_list
+ id
;
1412 const struct alc_pincfg
*cfg
;
1414 switch (fix
->type
) {
1416 if (action
!= ALC_FIXUP_ACT_PRE_PROBE
|| !fix
->v
.sku
)
1418 snd_printdd(KERN_INFO
"hda_codec: %s: "
1419 "Apply sku override for %s\n",
1420 codec
->chip_name
, modelname
);
1421 spec
->cdefine
.sku_cfg
= fix
->v
.sku
;
1422 spec
->cdefine
.fixup
= 1;
1424 case ALC_FIXUP_PINS
:
1426 if (action
!= ALC_FIXUP_ACT_PRE_PROBE
|| !cfg
)
1428 snd_printdd(KERN_INFO
"hda_codec: %s: "
1429 "Apply pincfg for %s\n",
1430 codec
->chip_name
, modelname
);
1431 for (; cfg
->nid
; cfg
++)
1432 snd_hda_codec_set_pincfg(codec
, cfg
->nid
,
1435 case ALC_FIXUP_VERBS
:
1436 if (action
!= ALC_FIXUP_ACT_PROBE
|| !fix
->v
.verbs
)
1438 snd_printdd(KERN_INFO
"hda_codec: %s: "
1439 "Apply fix-verbs for %s\n",
1440 codec
->chip_name
, modelname
);
1441 add_verb(codec
->spec
, fix
->v
.verbs
);
1443 case ALC_FIXUP_FUNC
:
1446 snd_printdd(KERN_INFO
"hda_codec: %s: "
1447 "Apply fix-func for %s\n",
1448 codec
->chip_name
, modelname
);
1449 fix
->v
.func(codec
, fix
, action
);
1452 snd_printk(KERN_ERR
"hda_codec: %s: "
1453 "Invalid fixup type %d\n",
1454 codec
->chip_name
, fix
->type
);
1465 static void alc_pick_fixup(struct hda_codec
*codec
,
1466 const struct alc_model_fixup
*models
,
1467 const struct snd_pci_quirk
*quirk
,
1468 const struct alc_fixup
*fixlist
)
1470 struct alc_spec
*spec
= codec
->spec
;
1472 const char *name
= NULL
;
1474 if (codec
->modelname
&& models
) {
1475 while (models
->name
) {
1476 if (!strcmp(codec
->modelname
, models
->name
)) {
1478 name
= models
->name
;
1485 quirk
= snd_pci_quirk_lookup(codec
->bus
->pci
, quirk
);
1488 #ifdef CONFIG_SND_DEBUG_VERBOSE
1494 spec
->fixup_id
= id
;
1496 spec
->fixup_list
= fixlist
;
1497 spec
->fixup_name
= name
;
1502 * COEF access helper functions
1504 static int alc_read_coef_idx(struct hda_codec
*codec
,
1505 unsigned int coef_idx
)
1508 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_COEF_INDEX
,
1510 val
= snd_hda_codec_read(codec
, 0x20, 0,
1511 AC_VERB_GET_PROC_COEF
, 0);
1515 static void alc_write_coef_idx(struct hda_codec
*codec
, unsigned int coef_idx
,
1516 unsigned int coef_val
)
1518 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_COEF_INDEX
,
1520 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_PROC_COEF
,
1525 * Digital I/O handling
1528 /* set right pin controls for digital I/O */
1529 static void alc_auto_init_digital(struct hda_codec
*codec
)
1531 struct alc_spec
*spec
= codec
->spec
;
1535 for (i
= 0; i
< spec
->autocfg
.dig_outs
; i
++) {
1536 pin
= spec
->autocfg
.dig_out_pins
[i
];
1539 snd_hda_codec_write(codec
, pin
, 0,
1540 AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
);
1542 dac
= spec
->multiout
.dig_out_nid
;
1544 dac
= spec
->slave_dig_outs
[i
- 1];
1545 if (!dac
|| !(get_wcaps(codec
, dac
) & AC_WCAP_OUT_AMP
))
1547 snd_hda_codec_write(codec
, dac
, 0,
1548 AC_VERB_SET_AMP_GAIN_MUTE
,
1551 pin
= spec
->autocfg
.dig_in_pin
;
1553 snd_hda_codec_write(codec
, pin
, 0,
1554 AC_VERB_SET_PIN_WIDGET_CONTROL
,
1558 /* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1559 static void alc_auto_parse_digital(struct hda_codec
*codec
)
1561 struct alc_spec
*spec
= codec
->spec
;
1565 /* support multiple SPDIFs; the secondary is set up as a slave */
1566 for (i
= 0; i
< spec
->autocfg
.dig_outs
; i
++) {
1568 err
= snd_hda_get_connections(codec
,
1569 spec
->autocfg
.dig_out_pins
[i
],
1570 conn
, ARRAY_SIZE(conn
));
1573 dig_nid
= conn
[0]; /* assume the first element is audio-out */
1575 spec
->multiout
.dig_out_nid
= dig_nid
;
1576 spec
->dig_out_type
= spec
->autocfg
.dig_out_type
[0];
1578 spec
->multiout
.slave_dig_outs
= spec
->slave_dig_outs
;
1579 if (i
>= ARRAY_SIZE(spec
->slave_dig_outs
) - 1)
1581 spec
->slave_dig_outs
[i
- 1] = dig_nid
;
1585 if (spec
->autocfg
.dig_in_pin
) {
1586 dig_nid
= codec
->start_nid
;
1587 for (i
= 0; i
< codec
->num_nodes
; i
++, dig_nid
++) {
1588 unsigned int wcaps
= get_wcaps(codec
, dig_nid
);
1589 if (get_wcaps_type(wcaps
) != AC_WID_AUD_IN
)
1591 if (!(wcaps
& AC_WCAP_DIGITAL
))
1593 if (!(wcaps
& AC_WCAP_CONN_LIST
))
1595 err
= get_connection_index(codec
, dig_nid
,
1596 spec
->autocfg
.dig_in_pin
);
1598 spec
->dig_in_nid
= dig_nid
;
1606 * capture mixer elements
1608 static int alc_cap_vol_info(struct snd_kcontrol
*kcontrol
,
1609 struct snd_ctl_elem_info
*uinfo
)
1611 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1612 struct alc_spec
*spec
= codec
->spec
;
1616 mutex_lock(&codec
->control_mutex
);
1617 if (spec
->vol_in_capsrc
)
1618 val
= HDA_COMPOSE_AMP_VAL(spec
->capsrc_nids
[0], 3, 0, HDA_OUTPUT
);
1620 val
= HDA_COMPOSE_AMP_VAL(spec
->adc_nids
[0], 3, 0, HDA_INPUT
);
1621 kcontrol
->private_value
= val
;
1622 err
= snd_hda_mixer_amp_volume_info(kcontrol
, uinfo
);
1623 mutex_unlock(&codec
->control_mutex
);
1627 static int alc_cap_vol_tlv(struct snd_kcontrol
*kcontrol
, int op_flag
,
1628 unsigned int size
, unsigned int __user
*tlv
)
1630 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1631 struct alc_spec
*spec
= codec
->spec
;
1635 mutex_lock(&codec
->control_mutex
);
1636 if (spec
->vol_in_capsrc
)
1637 val
= HDA_COMPOSE_AMP_VAL(spec
->capsrc_nids
[0], 3, 0, HDA_OUTPUT
);
1639 val
= HDA_COMPOSE_AMP_VAL(spec
->adc_nids
[0], 3, 0, HDA_INPUT
);
1640 kcontrol
->private_value
= val
;
1641 err
= snd_hda_mixer_amp_tlv(kcontrol
, op_flag
, size
, tlv
);
1642 mutex_unlock(&codec
->control_mutex
);
1646 typedef int (*getput_call_t
)(struct snd_kcontrol
*kcontrol
,
1647 struct snd_ctl_elem_value
*ucontrol
);
1649 static int alc_cap_getput_caller(struct snd_kcontrol
*kcontrol
,
1650 struct snd_ctl_elem_value
*ucontrol
,
1651 getput_call_t func
, bool check_adc_switch
)
1653 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1654 struct alc_spec
*spec
= codec
->spec
;
1657 mutex_lock(&codec
->control_mutex
);
1658 if (check_adc_switch
&& spec
->dyn_adc_switch
) {
1659 for (i
= 0; i
< spec
->num_adc_nids
; i
++) {
1660 kcontrol
->private_value
=
1661 HDA_COMPOSE_AMP_VAL(spec
->adc_nids
[i
],
1663 err
= func(kcontrol
, ucontrol
);
1668 i
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
1669 if (spec
->vol_in_capsrc
)
1670 kcontrol
->private_value
=
1671 HDA_COMPOSE_AMP_VAL(spec
->capsrc_nids
[i
],
1674 kcontrol
->private_value
=
1675 HDA_COMPOSE_AMP_VAL(spec
->adc_nids
[i
],
1677 err
= func(kcontrol
, ucontrol
);
1680 mutex_unlock(&codec
->control_mutex
);
1684 static int alc_cap_vol_get(struct snd_kcontrol
*kcontrol
,
1685 struct snd_ctl_elem_value
*ucontrol
)
1687 return alc_cap_getput_caller(kcontrol
, ucontrol
,
1688 snd_hda_mixer_amp_volume_get
, false);
1691 static int alc_cap_vol_put(struct snd_kcontrol
*kcontrol
,
1692 struct snd_ctl_elem_value
*ucontrol
)
1694 return alc_cap_getput_caller(kcontrol
, ucontrol
,
1695 snd_hda_mixer_amp_volume_put
, true);
1698 /* capture mixer elements */
1699 #define alc_cap_sw_info snd_ctl_boolean_stereo_info
1701 static int alc_cap_sw_get(struct snd_kcontrol
*kcontrol
,
1702 struct snd_ctl_elem_value
*ucontrol
)
1704 return alc_cap_getput_caller(kcontrol
, ucontrol
,
1705 snd_hda_mixer_amp_switch_get
, false);
1708 static int alc_cap_sw_put(struct snd_kcontrol
*kcontrol
,
1709 struct snd_ctl_elem_value
*ucontrol
)
1711 return alc_cap_getput_caller(kcontrol
, ucontrol
,
1712 snd_hda_mixer_amp_switch_put
, true);
1715 #define _DEFINE_CAPMIX(num) \
1717 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1718 .name = "Capture Switch", \
1719 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1721 .info = alc_cap_sw_info, \
1722 .get = alc_cap_sw_get, \
1723 .put = alc_cap_sw_put, \
1726 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1727 .name = "Capture Volume", \
1728 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1729 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1730 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1732 .info = alc_cap_vol_info, \
1733 .get = alc_cap_vol_get, \
1734 .put = alc_cap_vol_put, \
1735 .tlv = { .c = alc_cap_vol_tlv }, \
1738 #define _DEFINE_CAPSRC(num) \
1740 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1741 /* .name = "Capture Source", */ \
1742 .name = "Input Source", \
1744 .info = alc_mux_enum_info, \
1745 .get = alc_mux_enum_get, \
1746 .put = alc_mux_enum_put, \
1749 #define DEFINE_CAPMIX(num) \
1750 static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
1751 _DEFINE_CAPMIX(num), \
1752 _DEFINE_CAPSRC(num), \
1756 #define DEFINE_CAPMIX_NOSRC(num) \
1757 static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
1758 _DEFINE_CAPMIX(num), \
1762 /* up to three ADCs */
1766 DEFINE_CAPMIX_NOSRC(1);
1767 DEFINE_CAPMIX_NOSRC(2);
1768 DEFINE_CAPMIX_NOSRC(3);
1771 * virtual master controls
1775 * slave controls for virtual master
1777 static const char * const alc_slave_vols
[] = {
1778 "Front Playback Volume",
1779 "Surround Playback Volume",
1780 "Center Playback Volume",
1781 "LFE Playback Volume",
1782 "Side Playback Volume",
1783 "Headphone Playback Volume",
1784 "Speaker Playback Volume",
1785 "Mono Playback Volume",
1786 "Line-Out Playback Volume",
1790 static const char * const alc_slave_sws
[] = {
1791 "Front Playback Switch",
1792 "Surround Playback Switch",
1793 "Center Playback Switch",
1794 "LFE Playback Switch",
1795 "Side Playback Switch",
1796 "Headphone Playback Switch",
1797 "Speaker Playback Switch",
1798 "Mono Playback Switch",
1799 "IEC958 Playback Switch",
1800 "Line-Out Playback Switch",
1805 * build control elements
1808 #define NID_MAPPING (-1)
1810 #define SUBDEV_SPEAKER_ (0 << 6)
1811 #define SUBDEV_HP_ (1 << 6)
1812 #define SUBDEV_LINE_ (2 << 6)
1813 #define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1814 #define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1815 #define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1817 static void alc_free_kctls(struct hda_codec
*codec
);
1819 #ifdef CONFIG_SND_HDA_INPUT_BEEP
1820 /* additional beep mixers; the actual parameters are overwritten at build */
1821 static const struct snd_kcontrol_new alc_beep_mixer
[] = {
1822 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT
),
1823 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT
),
1828 static int alc_build_controls(struct hda_codec
*codec
)
1830 struct alc_spec
*spec
= codec
->spec
;
1831 struct snd_kcontrol
*kctl
= NULL
;
1832 const struct snd_kcontrol_new
*knew
;
1837 for (i
= 0; i
< spec
->num_mixers
; i
++) {
1838 err
= snd_hda_add_new_ctls(codec
, spec
->mixers
[i
]);
1842 if (spec
->cap_mixer
) {
1843 err
= snd_hda_add_new_ctls(codec
, spec
->cap_mixer
);
1847 if (spec
->multiout
.dig_out_nid
) {
1848 err
= snd_hda_create_spdif_out_ctls(codec
,
1849 spec
->multiout
.dig_out_nid
,
1850 spec
->multiout
.dig_out_nid
);
1853 if (!spec
->no_analog
) {
1854 err
= snd_hda_create_spdif_share_sw(codec
,
1858 spec
->multiout
.share_spdif
= 1;
1861 if (spec
->dig_in_nid
) {
1862 err
= snd_hda_create_spdif_in_ctls(codec
, spec
->dig_in_nid
);
1867 #ifdef CONFIG_SND_HDA_INPUT_BEEP
1868 /* create beep controls if needed */
1869 if (spec
->beep_amp
) {
1870 const struct snd_kcontrol_new
*knew
;
1871 for (knew
= alc_beep_mixer
; knew
->name
; knew
++) {
1872 struct snd_kcontrol
*kctl
;
1873 kctl
= snd_ctl_new1(knew
, codec
);
1876 kctl
->private_value
= spec
->beep_amp
;
1877 err
= snd_hda_ctl_add(codec
, 0, kctl
);
1884 /* if we have no master control, let's create it */
1885 if (!spec
->no_analog
&&
1886 !snd_hda_find_mixer_ctl(codec
, "Master Playback Volume")) {
1887 unsigned int vmaster_tlv
[4];
1888 snd_hda_set_vmaster_tlv(codec
, spec
->vmaster_nid
,
1889 HDA_OUTPUT
, vmaster_tlv
);
1890 err
= snd_hda_add_vmaster(codec
, "Master Playback Volume",
1891 vmaster_tlv
, alc_slave_vols
);
1895 if (!spec
->no_analog
&&
1896 !snd_hda_find_mixer_ctl(codec
, "Master Playback Switch")) {
1897 err
= snd_hda_add_vmaster(codec
, "Master Playback Switch",
1898 NULL
, alc_slave_sws
);
1903 /* assign Capture Source enums to NID */
1904 if (spec
->capsrc_nids
|| spec
->adc_nids
) {
1905 kctl
= snd_hda_find_mixer_ctl(codec
, "Capture Source");
1907 kctl
= snd_hda_find_mixer_ctl(codec
, "Input Source");
1908 for (i
= 0; kctl
&& i
< kctl
->count
; i
++) {
1909 const hda_nid_t
*nids
= spec
->capsrc_nids
;
1911 nids
= spec
->adc_nids
;
1912 err
= snd_hda_add_nid(codec
, kctl
, i
, nids
[i
]);
1917 if (spec
->cap_mixer
&& spec
->adc_nids
) {
1918 const char *kname
= kctl
? kctl
->id
.name
: NULL
;
1919 for (knew
= spec
->cap_mixer
; knew
->name
; knew
++) {
1920 if (kname
&& strcmp(knew
->name
, kname
) == 0)
1922 kctl
= snd_hda_find_mixer_ctl(codec
, knew
->name
);
1923 for (i
= 0; kctl
&& i
< kctl
->count
; i
++) {
1924 err
= snd_hda_add_nid(codec
, kctl
, i
,
1932 /* other nid->control mapping */
1933 for (i
= 0; i
< spec
->num_mixers
; i
++) {
1934 for (knew
= spec
->mixers
[i
]; knew
->name
; knew
++) {
1935 if (knew
->iface
!= NID_MAPPING
)
1937 kctl
= snd_hda_find_mixer_ctl(codec
, knew
->name
);
1940 u
= knew
->subdevice
;
1941 for (j
= 0; j
< 4; j
++, u
>>= 8) {
1946 case SUBDEV_SPEAKER_
:
1947 nid
= spec
->autocfg
.speaker_pins
[nid
];
1950 nid
= spec
->autocfg
.line_out_pins
[nid
];
1953 nid
= spec
->autocfg
.hp_pins
[nid
];
1958 err
= snd_hda_add_nid(codec
, kctl
, 0, nid
);
1962 u
= knew
->private_value
;
1963 for (j
= 0; j
< 4; j
++, u
>>= 8) {
1967 err
= snd_hda_add_nid(codec
, kctl
, 0, nid
);
1974 alc_free_kctls(codec
); /* no longer needed */
1984 static void alc_init_special_input_src(struct hda_codec
*codec
);
1986 static int alc_init(struct hda_codec
*codec
)
1988 struct alc_spec
*spec
= codec
->spec
;
1992 alc_auto_init_amp(codec
, spec
->init_amp
);
1994 for (i
= 0; i
< spec
->num_init_verbs
; i
++)
1995 snd_hda_sequence_write(codec
, spec
->init_verbs
[i
]);
1996 alc_init_special_input_src(codec
);
1998 if (spec
->init_hook
)
1999 spec
->init_hook(codec
);
2001 alc_apply_fixup(codec
, ALC_FIXUP_ACT_INIT
);
2003 hda_call_check_power_status(codec
, 0x01);
2007 static void alc_unsol_event(struct hda_codec
*codec
, unsigned int res
)
2009 struct alc_spec
*spec
= codec
->spec
;
2011 if (spec
->unsol_event
)
2012 spec
->unsol_event(codec
, res
);
2015 #ifdef CONFIG_SND_HDA_POWER_SAVE
2016 static int alc_check_power_status(struct hda_codec
*codec
, hda_nid_t nid
)
2018 struct alc_spec
*spec
= codec
->spec
;
2019 return snd_hda_check_amp_list_power(codec
, &spec
->loopback
, nid
);
2024 * Analog playback callbacks
2026 static int alc_playback_pcm_open(struct hda_pcm_stream
*hinfo
,
2027 struct hda_codec
*codec
,
2028 struct snd_pcm_substream
*substream
)
2030 struct alc_spec
*spec
= codec
->spec
;
2031 return snd_hda_multi_out_analog_open(codec
, &spec
->multiout
, substream
,
2035 static int alc_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
2036 struct hda_codec
*codec
,
2037 unsigned int stream_tag
,
2038 unsigned int format
,
2039 struct snd_pcm_substream
*substream
)
2041 struct alc_spec
*spec
= codec
->spec
;
2042 return snd_hda_multi_out_analog_prepare(codec
, &spec
->multiout
,
2043 stream_tag
, format
, substream
);
2046 static int alc_playback_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
2047 struct hda_codec
*codec
,
2048 struct snd_pcm_substream
*substream
)
2050 struct alc_spec
*spec
= codec
->spec
;
2051 return snd_hda_multi_out_analog_cleanup(codec
, &spec
->multiout
);
2057 static int alc_dig_playback_pcm_open(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_dig_open(codec
, &spec
->multiout
);
2065 static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
2066 struct hda_codec
*codec
,
2067 unsigned int stream_tag
,
2068 unsigned int format
,
2069 struct snd_pcm_substream
*substream
)
2071 struct alc_spec
*spec
= codec
->spec
;
2072 return snd_hda_multi_out_dig_prepare(codec
, &spec
->multiout
,
2073 stream_tag
, format
, substream
);
2076 static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
2077 struct hda_codec
*codec
,
2078 struct snd_pcm_substream
*substream
)
2080 struct alc_spec
*spec
= codec
->spec
;
2081 return snd_hda_multi_out_dig_cleanup(codec
, &spec
->multiout
);
2084 static int alc_dig_playback_pcm_close(struct hda_pcm_stream
*hinfo
,
2085 struct hda_codec
*codec
,
2086 struct snd_pcm_substream
*substream
)
2088 struct alc_spec
*spec
= codec
->spec
;
2089 return snd_hda_multi_out_dig_close(codec
, &spec
->multiout
);
2095 static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream
*hinfo
,
2096 struct hda_codec
*codec
,
2097 unsigned int stream_tag
,
2098 unsigned int format
,
2099 struct snd_pcm_substream
*substream
)
2101 struct alc_spec
*spec
= codec
->spec
;
2103 snd_hda_codec_setup_stream(codec
, spec
->adc_nids
[substream
->number
+ 1],
2104 stream_tag
, 0, format
);
2108 static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
2109 struct hda_codec
*codec
,
2110 struct snd_pcm_substream
*substream
)
2112 struct alc_spec
*spec
= codec
->spec
;
2114 snd_hda_codec_cleanup_stream(codec
,
2115 spec
->adc_nids
[substream
->number
+ 1]);
2119 /* analog capture with dynamic dual-adc changes */
2120 static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream
*hinfo
,
2121 struct hda_codec
*codec
,
2122 unsigned int stream_tag
,
2123 unsigned int format
,
2124 struct snd_pcm_substream
*substream
)
2126 struct alc_spec
*spec
= codec
->spec
;
2127 spec
->cur_adc
= spec
->adc_nids
[spec
->dyn_adc_idx
[spec
->cur_mux
[0]]];
2128 spec
->cur_adc_stream_tag
= stream_tag
;
2129 spec
->cur_adc_format
= format
;
2130 snd_hda_codec_setup_stream(codec
, spec
->cur_adc
, stream_tag
, 0, format
);
2134 static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
2135 struct hda_codec
*codec
,
2136 struct snd_pcm_substream
*substream
)
2138 struct alc_spec
*spec
= codec
->spec
;
2139 snd_hda_codec_cleanup_stream(codec
, spec
->cur_adc
);
2144 static const struct hda_pcm_stream dyn_adc_pcm_analog_capture
= {
2148 .nid
= 0, /* fill later */
2150 .prepare
= dyn_adc_capture_pcm_prepare
,
2151 .cleanup
= dyn_adc_capture_pcm_cleanup
2157 static const struct hda_pcm_stream alc_pcm_analog_playback
= {
2161 /* NID is set in alc_build_pcms */
2163 .open
= alc_playback_pcm_open
,
2164 .prepare
= alc_playback_pcm_prepare
,
2165 .cleanup
= alc_playback_pcm_cleanup
2169 static const struct hda_pcm_stream alc_pcm_analog_capture
= {
2173 /* NID is set in alc_build_pcms */
2176 static const struct hda_pcm_stream alc_pcm_analog_alt_playback
= {
2180 /* NID is set in alc_build_pcms */
2183 static const struct hda_pcm_stream alc_pcm_analog_alt_capture
= {
2184 .substreams
= 2, /* can be overridden */
2187 /* NID is set in alc_build_pcms */
2189 .prepare
= alc_alt_capture_pcm_prepare
,
2190 .cleanup
= alc_alt_capture_pcm_cleanup
2194 static const struct hda_pcm_stream alc_pcm_digital_playback
= {
2198 /* NID is set in alc_build_pcms */
2200 .open
= alc_dig_playback_pcm_open
,
2201 .close
= alc_dig_playback_pcm_close
,
2202 .prepare
= alc_dig_playback_pcm_prepare
,
2203 .cleanup
= alc_dig_playback_pcm_cleanup
2207 static const struct hda_pcm_stream alc_pcm_digital_capture
= {
2211 /* NID is set in alc_build_pcms */
2214 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
2215 static const struct hda_pcm_stream alc_pcm_null_stream
= {
2221 static int alc_build_pcms(struct hda_codec
*codec
)
2223 struct alc_spec
*spec
= codec
->spec
;
2224 struct hda_pcm
*info
= spec
->pcm_rec
;
2225 const struct hda_pcm_stream
*p
;
2228 codec
->num_pcms
= 1;
2229 codec
->pcm_info
= info
;
2231 if (spec
->no_analog
)
2234 snprintf(spec
->stream_name_analog
, sizeof(spec
->stream_name_analog
),
2235 "%s Analog", codec
->chip_name
);
2236 info
->name
= spec
->stream_name_analog
;
2238 if (spec
->multiout
.dac_nids
> 0) {
2239 p
= spec
->stream_analog_playback
;
2241 p
= &alc_pcm_analog_playback
;
2242 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] = *p
;
2243 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
= spec
->multiout
.dac_nids
[0];
2245 if (spec
->adc_nids
) {
2246 p
= spec
->stream_analog_capture
;
2248 if (spec
->dyn_adc_switch
)
2249 p
= &dyn_adc_pcm_analog_capture
;
2251 p
= &alc_pcm_analog_capture
;
2253 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] = *p
;
2254 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
= spec
->adc_nids
[0];
2257 if (spec
->channel_mode
) {
2258 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].channels_max
= 0;
2259 for (i
= 0; i
< spec
->num_channel_mode
; i
++) {
2260 if (spec
->channel_mode
[i
].channels
> info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].channels_max
) {
2261 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].channels_max
= spec
->channel_mode
[i
].channels
;
2267 /* SPDIF for stream index #1 */
2268 if (spec
->multiout
.dig_out_nid
|| spec
->dig_in_nid
) {
2269 snprintf(spec
->stream_name_digital
,
2270 sizeof(spec
->stream_name_digital
),
2271 "%s Digital", codec
->chip_name
);
2272 codec
->num_pcms
= 2;
2273 codec
->slave_dig_outs
= spec
->multiout
.slave_dig_outs
;
2274 info
= spec
->pcm_rec
+ 1;
2275 info
->name
= spec
->stream_name_digital
;
2276 if (spec
->dig_out_type
)
2277 info
->pcm_type
= spec
->dig_out_type
;
2279 info
->pcm_type
= HDA_PCM_TYPE_SPDIF
;
2280 if (spec
->multiout
.dig_out_nid
) {
2281 p
= spec
->stream_digital_playback
;
2283 p
= &alc_pcm_digital_playback
;
2284 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] = *p
;
2285 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
= spec
->multiout
.dig_out_nid
;
2287 if (spec
->dig_in_nid
) {
2288 p
= spec
->stream_digital_capture
;
2290 p
= &alc_pcm_digital_capture
;
2291 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] = *p
;
2292 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
= spec
->dig_in_nid
;
2294 /* FIXME: do we need this for all Realtek codec models? */
2295 codec
->spdif_status_reset
= 1;
2298 if (spec
->no_analog
)
2301 /* If the use of more than one ADC is requested for the current
2302 * model, configure a second analog capture-only PCM.
2304 /* Additional Analaog capture for index #2 */
2305 if (spec
->alt_dac_nid
|| spec
->num_adc_nids
> 1) {
2306 codec
->num_pcms
= 3;
2307 info
= spec
->pcm_rec
+ 2;
2308 info
->name
= spec
->stream_name_analog
;
2309 if (spec
->alt_dac_nid
) {
2310 p
= spec
->stream_analog_alt_playback
;
2312 p
= &alc_pcm_analog_alt_playback
;
2313 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] = *p
;
2314 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
=
2317 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] =
2318 alc_pcm_null_stream
;
2319 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
= 0;
2321 if (spec
->num_adc_nids
> 1) {
2322 p
= spec
->stream_analog_alt_capture
;
2324 p
= &alc_pcm_analog_alt_capture
;
2325 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] = *p
;
2326 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
=
2328 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].substreams
=
2329 spec
->num_adc_nids
- 1;
2331 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] =
2332 alc_pcm_null_stream
;
2333 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
= 0;
2340 static inline void alc_shutup(struct hda_codec
*codec
)
2342 struct alc_spec
*spec
= codec
->spec
;
2344 if (spec
&& spec
->shutup
)
2345 spec
->shutup(codec
);
2346 snd_hda_shutup_pins(codec
);
2349 static void alc_free_kctls(struct hda_codec
*codec
)
2351 struct alc_spec
*spec
= codec
->spec
;
2353 if (spec
->kctls
.list
) {
2354 struct snd_kcontrol_new
*kctl
= spec
->kctls
.list
;
2356 for (i
= 0; i
< spec
->kctls
.used
; i
++)
2357 kfree(kctl
[i
].name
);
2359 snd_array_free(&spec
->kctls
);
2362 static void alc_free(struct hda_codec
*codec
)
2364 struct alc_spec
*spec
= codec
->spec
;
2370 snd_hda_input_jack_free(codec
);
2371 alc_free_kctls(codec
);
2373 snd_hda_detach_beep_device(codec
);
2376 #ifdef CONFIG_SND_HDA_POWER_SAVE
2377 static void alc_power_eapd(struct hda_codec
*codec
)
2379 alc_auto_setup_eapd(codec
, false);
2382 static int alc_suspend(struct hda_codec
*codec
, pm_message_t state
)
2384 struct alc_spec
*spec
= codec
->spec
;
2386 if (spec
&& spec
->power_hook
)
2387 spec
->power_hook(codec
);
2393 static int alc_resume(struct hda_codec
*codec
)
2395 msleep(150); /* to avoid pop noise */
2396 codec
->patch_ops
.init(codec
);
2397 snd_hda_codec_resume_amp(codec
);
2398 snd_hda_codec_resume_cache(codec
);
2399 hda_call_check_power_status(codec
, 0x01);
2406 static const struct hda_codec_ops alc_patch_ops
= {
2407 .build_controls
= alc_build_controls
,
2408 .build_pcms
= alc_build_pcms
,
2411 .unsol_event
= alc_unsol_event
,
2413 .resume
= alc_resume
,
2415 #ifdef CONFIG_SND_HDA_POWER_SAVE
2416 .suspend
= alc_suspend
,
2417 .check_power_status
= alc_check_power_status
,
2419 .reboot_notify
= alc_shutup
,
2422 /* replace the codec chip_name with the given string */
2423 static int alc_codec_rename(struct hda_codec
*codec
, const char *name
)
2425 kfree(codec
->chip_name
);
2426 codec
->chip_name
= kstrdup(name
, GFP_KERNEL
);
2427 if (!codec
->chip_name
) {
2435 * Automatic parse of I/O pins from the BIOS configuration
2440 ALC_CTL_WIDGET_MUTE
,
2443 static const struct snd_kcontrol_new alc_control_templates
[] = {
2444 HDA_CODEC_VOLUME(NULL
, 0, 0, 0),
2445 HDA_CODEC_MUTE(NULL
, 0, 0, 0),
2446 HDA_BIND_MUTE(NULL
, 0, 0, 0),
2449 /* add dynamic controls */
2450 static int add_control(struct alc_spec
*spec
, int type
, const char *name
,
2451 int cidx
, unsigned long val
)
2453 struct snd_kcontrol_new
*knew
;
2455 knew
= alc_kcontrol_new(spec
);
2458 *knew
= alc_control_templates
[type
];
2459 knew
->name
= kstrdup(name
, GFP_KERNEL
);
2463 if (get_amp_nid_(val
))
2464 knew
->subdevice
= HDA_SUBDEV_AMP_FLAG
;
2465 knew
->private_value
= val
;
2469 static int add_control_with_pfx(struct alc_spec
*spec
, int type
,
2470 const char *pfx
, const char *dir
,
2471 const char *sfx
, int cidx
, unsigned long val
)
2474 snprintf(name
, sizeof(name
), "%s %s %s", pfx
, dir
, sfx
);
2475 return add_control(spec
, type
, name
, cidx
, val
);
2478 #define add_pb_vol_ctrl(spec, type, pfx, val) \
2479 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2480 #define add_pb_sw_ctrl(spec, type, pfx, val) \
2481 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2482 #define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2483 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2484 #define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2485 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
2487 static const char *alc_get_line_out_pfx(struct alc_spec
*spec
, int ch
,
2488 bool can_be_master
, int *index
)
2490 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
2491 static const char * const chname
[4] = {
2492 "Front", "Surround", NULL
/*CLFE*/, "Side"
2496 if (cfg
->line_outs
== 1 && !spec
->multi_ios
&&
2497 !cfg
->hp_outs
&& !cfg
->speaker_outs
&& can_be_master
)
2500 switch (cfg
->line_out_type
) {
2501 case AUTO_PIN_SPEAKER_OUT
:
2502 if (cfg
->line_outs
== 1)
2505 case AUTO_PIN_HP_OUT
:
2506 /* for multi-io case, only the primary out */
2507 if (ch
&& spec
->multi_ios
)
2512 if (cfg
->line_outs
== 1 && !spec
->multi_ios
)
2519 /* create input playback/capture controls for the given pin */
2520 static int new_analog_input(struct alc_spec
*spec
, hda_nid_t pin
,
2521 const char *ctlname
, int ctlidx
,
2522 int idx
, hda_nid_t mix_nid
)
2526 err
= __add_pb_vol_ctrl(spec
, ALC_CTL_WIDGET_VOL
, ctlname
, ctlidx
,
2527 HDA_COMPOSE_AMP_VAL(mix_nid
, 3, idx
, HDA_INPUT
));
2530 err
= __add_pb_sw_ctrl(spec
, ALC_CTL_WIDGET_MUTE
, ctlname
, ctlidx
,
2531 HDA_COMPOSE_AMP_VAL(mix_nid
, 3, idx
, HDA_INPUT
));
2537 static int alc_is_input_pin(struct hda_codec
*codec
, hda_nid_t nid
)
2539 unsigned int pincap
= snd_hda_query_pin_caps(codec
, nid
);
2540 return (pincap
& AC_PINCAP_IN
) != 0;
2543 /* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
2544 static int alc_auto_fill_adc_caps(struct hda_codec
*codec
)
2546 struct alc_spec
*spec
= codec
->spec
;
2548 hda_nid_t
*adc_nids
= spec
->private_adc_nids
;
2549 hda_nid_t
*cap_nids
= spec
->private_capsrc_nids
;
2550 int max_nums
= ARRAY_SIZE(spec
->private_adc_nids
);
2551 bool indep_capsrc
= false;
2554 nid
= codec
->start_nid
;
2555 for (i
= 0; i
< codec
->num_nodes
; i
++, nid
++) {
2557 const hda_nid_t
*list
;
2558 unsigned int caps
= get_wcaps(codec
, nid
);
2559 int type
= get_wcaps_type(caps
);
2561 if (type
!= AC_WID_AUD_IN
|| (caps
& AC_WCAP_DIGITAL
))
2563 adc_nids
[nums
] = nid
;
2564 cap_nids
[nums
] = nid
;
2568 type
= get_wcaps_type(get_wcaps(codec
, src
));
2569 if (type
== AC_WID_PIN
)
2571 if (type
== AC_WID_AUD_SEL
) {
2572 cap_nids
[nums
] = src
;
2573 indep_capsrc
= true;
2576 n
= snd_hda_get_conn_list(codec
, src
, &list
);
2578 cap_nids
[nums
] = src
;
2579 indep_capsrc
= true;
2585 if (++nums
>= max_nums
)
2588 spec
->adc_nids
= spec
->private_adc_nids
;
2589 spec
->capsrc_nids
= spec
->private_capsrc_nids
;
2590 spec
->num_adc_nids
= nums
;
2594 /* create playback/capture controls for input pins */
2595 static int alc_auto_create_input_ctls(struct hda_codec
*codec
)
2597 struct alc_spec
*spec
= codec
->spec
;
2598 const struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
2599 hda_nid_t mixer
= spec
->mixer_nid
;
2600 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
2602 int i
, c
, err
, idx
, type_idx
= 0;
2603 const char *prev_label
= NULL
;
2605 num_adcs
= alc_auto_fill_adc_caps(codec
);
2609 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
2613 pin
= cfg
->inputs
[i
].pin
;
2614 if (!alc_is_input_pin(codec
, pin
))
2617 label
= hda_get_autocfg_input_label(codec
, cfg
, i
);
2618 if (prev_label
&& !strcmp(label
, prev_label
))
2625 idx
= get_connection_index(codec
, mixer
, pin
);
2627 err
= new_analog_input(spec
, pin
,
2635 for (c
= 0; c
< num_adcs
; c
++) {
2636 hda_nid_t cap
= spec
->capsrc_nids
?
2637 spec
->capsrc_nids
[c
] : spec
->adc_nids
[c
];
2638 idx
= get_connection_index(codec
, cap
, pin
);
2640 spec
->imux_pins
[imux
->num_items
] = pin
;
2641 snd_hda_add_imux_item(imux
, label
, idx
, NULL
);
2647 spec
->num_mux_defs
= 1;
2648 spec
->input_mux
= imux
;
2653 static void alc_set_pin_output(struct hda_codec
*codec
, hda_nid_t nid
,
2654 unsigned int pin_type
)
2656 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_PIN_WIDGET_CONTROL
,
2659 if (nid_has_mute(codec
, nid
, HDA_OUTPUT
))
2660 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
2664 static int get_pin_type(int line_out_type
)
2666 if (line_out_type
== AUTO_PIN_HP_OUT
)
2672 static void alc_auto_init_analog_input(struct hda_codec
*codec
)
2674 struct alc_spec
*spec
= codec
->spec
;
2675 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
2678 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
2679 hda_nid_t nid
= cfg
->inputs
[i
].pin
;
2680 if (alc_is_input_pin(codec
, nid
)) {
2681 alc_set_input_pin(codec
, nid
, cfg
->inputs
[i
].type
);
2682 if (get_wcaps(codec
, nid
) & AC_WCAP_OUT_AMP
)
2683 snd_hda_codec_write(codec
, nid
, 0,
2684 AC_VERB_SET_AMP_GAIN_MUTE
,
2689 /* mute all loopback inputs */
2690 if (spec
->mixer_nid
) {
2691 int nums
= snd_hda_get_conn_list(codec
, spec
->mixer_nid
, NULL
);
2692 for (i
= 0; i
< nums
; i
++)
2693 snd_hda_codec_write(codec
, spec
->mixer_nid
, 0,
2694 AC_VERB_SET_AMP_GAIN_MUTE
,
2699 /* convert from MIX nid to DAC */
2700 static hda_nid_t
alc_auto_mix_to_dac(struct hda_codec
*codec
, hda_nid_t nid
)
2705 if (get_wcaps_type(get_wcaps(codec
, nid
)) == AC_WID_AUD_OUT
)
2707 num
= snd_hda_get_connections(codec
, nid
, list
, ARRAY_SIZE(list
));
2708 for (i
= 0; i
< num
; i
++) {
2709 if (get_wcaps_type(get_wcaps(codec
, list
[i
])) == AC_WID_AUD_OUT
)
2715 /* go down to the selector widget before the mixer */
2716 static hda_nid_t
alc_go_down_to_selector(struct hda_codec
*codec
, hda_nid_t pin
)
2719 int num
= snd_hda_get_connections(codec
, pin
, srcs
,
2722 get_wcaps_type(get_wcaps(codec
, srcs
[0])) != AC_WID_AUD_SEL
)
2727 /* get MIX nid connected to the given pin targeted to DAC */
2728 static hda_nid_t
alc_auto_dac_to_mix(struct hda_codec
*codec
, hda_nid_t pin
,
2734 pin
= alc_go_down_to_selector(codec
, pin
);
2735 num
= snd_hda_get_connections(codec
, pin
, mix
, ARRAY_SIZE(mix
));
2736 for (i
= 0; i
< num
; i
++) {
2737 if (alc_auto_mix_to_dac(codec
, mix
[i
]) == dac
)
2743 /* select the connection from pin to DAC if needed */
2744 static int alc_auto_select_dac(struct hda_codec
*codec
, hda_nid_t pin
,
2750 pin
= alc_go_down_to_selector(codec
, pin
);
2751 num
= snd_hda_get_connections(codec
, pin
, mix
, ARRAY_SIZE(mix
));
2754 for (i
= 0; i
< num
; i
++) {
2755 if (alc_auto_mix_to_dac(codec
, mix
[i
]) == dac
) {
2756 snd_hda_codec_update_cache(codec
, pin
, 0,
2757 AC_VERB_SET_CONNECT_SEL
, i
);
2764 /* look for an empty DAC slot */
2765 static hda_nid_t
alc_auto_look_for_dac(struct hda_codec
*codec
, hda_nid_t pin
)
2767 struct alc_spec
*spec
= codec
->spec
;
2771 pin
= alc_go_down_to_selector(codec
, pin
);
2772 num
= snd_hda_get_connections(codec
, pin
, srcs
, ARRAY_SIZE(srcs
));
2773 for (i
= 0; i
< num
; i
++) {
2774 hda_nid_t nid
= alc_auto_mix_to_dac(codec
, srcs
[i
]);
2777 if (found_in_nid_list(nid
, spec
->multiout
.dac_nids
,
2778 spec
->multiout
.num_dacs
))
2780 if (spec
->multiout
.hp_nid
== nid
)
2782 if (found_in_nid_list(nid
, spec
->multiout
.extra_out_nid
,
2783 ARRAY_SIZE(spec
->multiout
.extra_out_nid
)))
2790 static hda_nid_t
get_dac_if_single(struct hda_codec
*codec
, hda_nid_t pin
)
2792 hda_nid_t sel
= alc_go_down_to_selector(codec
, pin
);
2793 if (snd_hda_get_conn_list(codec
, sel
, NULL
) == 1)
2794 return alc_auto_look_for_dac(codec
, pin
);
2798 /* fill in the dac_nids table from the parsed pin configuration */
2799 static int alc_auto_fill_dac_nids(struct hda_codec
*codec
)
2801 struct alc_spec
*spec
= codec
->spec
;
2802 const struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
2803 bool redone
= false;
2807 /* set num_dacs once to full for alc_auto_look_for_dac() */
2808 spec
->multiout
.num_dacs
= cfg
->line_outs
;
2809 spec
->multiout
.hp_nid
= 0;
2810 spec
->multiout
.extra_out_nid
[0] = 0;
2811 memset(spec
->private_dac_nids
, 0, sizeof(spec
->private_dac_nids
));
2812 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
2814 /* fill hard-wired DACs first */
2816 for (i
= 0; i
< cfg
->line_outs
; i
++)
2817 spec
->private_dac_nids
[i
] =
2818 get_dac_if_single(codec
, cfg
->line_out_pins
[i
]);
2820 spec
->multiout
.hp_nid
=
2821 get_dac_if_single(codec
, cfg
->hp_pins
[0]);
2822 if (cfg
->speaker_outs
)
2823 spec
->multiout
.extra_out_nid
[0] =
2824 get_dac_if_single(codec
, cfg
->speaker_pins
[0]);
2827 for (i
= 0; i
< cfg
->line_outs
; i
++) {
2828 hda_nid_t pin
= cfg
->line_out_pins
[i
];
2829 if (spec
->private_dac_nids
[i
])
2831 spec
->private_dac_nids
[i
] = alc_auto_look_for_dac(codec
, pin
);
2832 if (!spec
->private_dac_nids
[i
] && !redone
) {
2833 /* if we can't find primary DACs, re-probe without
2834 * checking the hard-wired DACs
2841 /* re-count num_dacs and squash invalid entries */
2842 spec
->multiout
.num_dacs
= 0;
2843 for (i
= 0; i
< cfg
->line_outs
; i
++) {
2844 if (spec
->private_dac_nids
[i
])
2845 spec
->multiout
.num_dacs
++;
2847 memmove(spec
->private_dac_nids
+ i
,
2848 spec
->private_dac_nids
+ i
+ 1,
2849 sizeof(hda_nid_t
) * (cfg
->line_outs
- i
- 1));
2852 if (cfg
->hp_outs
&& !spec
->multiout
.hp_nid
)
2853 spec
->multiout
.hp_nid
=
2854 alc_auto_look_for_dac(codec
, cfg
->hp_pins
[0]);
2855 if (cfg
->speaker_outs
&& !spec
->multiout
.extra_out_nid
[0])
2856 spec
->multiout
.extra_out_nid
[0] =
2857 alc_auto_look_for_dac(codec
, cfg
->speaker_pins
[0]);
2862 static int alc_auto_add_vol_ctl(struct hda_codec
*codec
,
2863 const char *pfx
, int cidx
,
2864 hda_nid_t nid
, unsigned int chs
)
2868 return __add_pb_vol_ctrl(codec
->spec
, ALC_CTL_WIDGET_VOL
, pfx
, cidx
,
2869 HDA_COMPOSE_AMP_VAL(nid
, chs
, 0, HDA_OUTPUT
));
2872 #define alc_auto_add_stereo_vol(codec, pfx, cidx, nid) \
2873 alc_auto_add_vol_ctl(codec, pfx, cidx, nid, 3)
2875 /* create a mute-switch for the given mixer widget;
2876 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
2878 static int alc_auto_add_sw_ctl(struct hda_codec
*codec
,
2879 const char *pfx
, int cidx
,
2880 hda_nid_t nid
, unsigned int chs
)
2887 wid_type
= get_wcaps_type(get_wcaps(codec
, nid
));
2888 if (wid_type
== AC_WID_PIN
|| wid_type
== AC_WID_AUD_OUT
) {
2889 type
= ALC_CTL_WIDGET_MUTE
;
2890 val
= HDA_COMPOSE_AMP_VAL(nid
, chs
, 0, HDA_OUTPUT
);
2891 } else if (snd_hda_get_conn_list(codec
, nid
, NULL
) == 1) {
2892 type
= ALC_CTL_WIDGET_MUTE
;
2893 val
= HDA_COMPOSE_AMP_VAL(nid
, chs
, 0, HDA_INPUT
);
2895 type
= ALC_CTL_BIND_MUTE
;
2896 val
= HDA_COMPOSE_AMP_VAL(nid
, chs
, 2, HDA_INPUT
);
2898 return __add_pb_sw_ctrl(codec
->spec
, type
, pfx
, cidx
, val
);
2901 #define alc_auto_add_stereo_sw(codec, pfx, cidx, nid) \
2902 alc_auto_add_sw_ctl(codec, pfx, cidx, nid, 3)
2904 static hda_nid_t
alc_look_for_out_mute_nid(struct hda_codec
*codec
,
2905 hda_nid_t pin
, hda_nid_t dac
)
2907 hda_nid_t mix
= alc_auto_dac_to_mix(codec
, pin
, dac
);
2908 if (nid_has_mute(codec
, pin
, HDA_OUTPUT
))
2910 else if (mix
&& nid_has_mute(codec
, mix
, HDA_INPUT
))
2912 else if (nid_has_mute(codec
, dac
, HDA_OUTPUT
))
2917 static hda_nid_t
alc_look_for_out_vol_nid(struct hda_codec
*codec
,
2918 hda_nid_t pin
, hda_nid_t dac
)
2920 hda_nid_t mix
= alc_auto_dac_to_mix(codec
, pin
, dac
);
2921 if (nid_has_volume(codec
, dac
, HDA_OUTPUT
))
2923 else if (nid_has_volume(codec
, mix
, HDA_OUTPUT
))
2925 else if (nid_has_volume(codec
, pin
, HDA_OUTPUT
))
2930 /* add playback controls from the parsed DAC table */
2931 static int alc_auto_create_multi_out_ctls(struct hda_codec
*codec
,
2932 const struct auto_pin_cfg
*cfg
)
2934 struct alc_spec
*spec
= codec
->spec
;
2935 int i
, err
, noutputs
;
2937 noutputs
= cfg
->line_outs
;
2938 if (spec
->multi_ios
> 0)
2939 noutputs
+= spec
->multi_ios
;
2941 for (i
= 0; i
< noutputs
; i
++) {
2947 dac
= spec
->multiout
.dac_nids
[i
];
2950 if (i
>= cfg
->line_outs
)
2951 pin
= spec
->multi_io
[i
- 1].pin
;
2953 pin
= cfg
->line_out_pins
[i
];
2955 sw
= alc_look_for_out_mute_nid(codec
, pin
, dac
);
2956 vol
= alc_look_for_out_vol_nid(codec
, pin
, dac
);
2957 name
= alc_get_line_out_pfx(spec
, i
, true, &index
);
2960 err
= alc_auto_add_vol_ctl(codec
, "Center", 0, vol
, 1);
2963 err
= alc_auto_add_vol_ctl(codec
, "LFE", 0, vol
, 2);
2966 err
= alc_auto_add_sw_ctl(codec
, "Center", 0, sw
, 1);
2969 err
= alc_auto_add_sw_ctl(codec
, "LFE", 0, sw
, 2);
2973 err
= alc_auto_add_stereo_vol(codec
, name
, index
, vol
);
2976 err
= alc_auto_add_stereo_sw(codec
, name
, index
, sw
);
2984 /* add playback controls for speaker and HP outputs */
2985 static int alc_auto_create_extra_out(struct hda_codec
*codec
, hda_nid_t pin
,
2986 hda_nid_t dac
, const char *pfx
)
2988 struct alc_spec
*spec
= codec
->spec
;
2995 /* the corresponding DAC is already occupied */
2996 if (!(get_wcaps(codec
, pin
) & AC_WCAP_OUT_AMP
))
2997 return 0; /* no way */
2998 /* create a switch only */
2999 return add_pb_sw_ctrl(spec
, ALC_CTL_WIDGET_MUTE
, pfx
,
3000 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
3003 sw
= alc_look_for_out_mute_nid(codec
, pin
, dac
);
3004 vol
= alc_look_for_out_vol_nid(codec
, pin
, dac
);
3005 err
= alc_auto_add_stereo_vol(codec
, pfx
, 0, vol
);
3008 err
= alc_auto_add_stereo_sw(codec
, pfx
, 0, sw
);
3014 static int alc_auto_create_hp_out(struct hda_codec
*codec
)
3016 struct alc_spec
*spec
= codec
->spec
;
3017 return alc_auto_create_extra_out(codec
, spec
->autocfg
.hp_pins
[0],
3018 spec
->multiout
.hp_nid
,
3022 static int alc_auto_create_speaker_out(struct hda_codec
*codec
)
3024 struct alc_spec
*spec
= codec
->spec
;
3025 return alc_auto_create_extra_out(codec
, spec
->autocfg
.speaker_pins
[0],
3026 spec
->multiout
.extra_out_nid
[0],
3030 static void alc_auto_set_output_and_unmute(struct hda_codec
*codec
,
3031 hda_nid_t pin
, int pin_type
,
3035 hda_nid_t nid
, mix
= 0;
3036 hda_nid_t srcs
[HDA_MAX_CONNECTIONS
];
3038 alc_set_pin_output(codec
, pin
, pin_type
);
3039 nid
= alc_go_down_to_selector(codec
, pin
);
3040 num
= snd_hda_get_connections(codec
, nid
, srcs
, ARRAY_SIZE(srcs
));
3041 for (i
= 0; i
< num
; i
++) {
3042 if (alc_auto_mix_to_dac(codec
, srcs
[i
]) != dac
)
3050 /* need the manual connection? */
3052 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_CONNECT_SEL
, i
);
3053 /* unmute mixer widget inputs */
3054 if (nid_has_mute(codec
, mix
, HDA_INPUT
)) {
3055 snd_hda_codec_write(codec
, mix
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
3057 snd_hda_codec_write(codec
, mix
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
3060 /* initialize volume */
3061 nid
= alc_look_for_out_vol_nid(codec
, pin
, dac
);
3063 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
3067 static void alc_auto_init_multi_out(struct hda_codec
*codec
)
3069 struct alc_spec
*spec
= codec
->spec
;
3070 int pin_type
= get_pin_type(spec
->autocfg
.line_out_type
);
3073 for (i
= 0; i
<= HDA_SIDE
; i
++) {
3074 hda_nid_t nid
= spec
->autocfg
.line_out_pins
[i
];
3076 alc_auto_set_output_and_unmute(codec
, nid
, pin_type
,
3077 spec
->multiout
.dac_nids
[i
]);
3081 static void alc_auto_init_extra_out(struct hda_codec
*codec
)
3083 struct alc_spec
*spec
= codec
->spec
;
3086 pin
= spec
->autocfg
.hp_pins
[0];
3088 alc_auto_set_output_and_unmute(codec
, pin
, PIN_HP
,
3089 spec
->multiout
.hp_nid
);
3090 pin
= spec
->autocfg
.speaker_pins
[0];
3092 alc_auto_set_output_and_unmute(codec
, pin
, PIN_OUT
,
3093 spec
->multiout
.extra_out_nid
[0]);
3099 static int alc_auto_fill_multi_ios(struct hda_codec
*codec
,
3100 unsigned int location
)
3102 struct alc_spec
*spec
= codec
->spec
;
3103 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
3104 int type
, i
, num_pins
= 0;
3106 for (type
= AUTO_PIN_LINE_IN
; type
>= AUTO_PIN_MIC
; type
--) {
3107 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
3108 hda_nid_t nid
= cfg
->inputs
[i
].pin
;
3110 unsigned int defcfg
, caps
;
3111 if (cfg
->inputs
[i
].type
!= type
)
3113 defcfg
= snd_hda_codec_get_pincfg(codec
, nid
);
3114 if (get_defcfg_connect(defcfg
) != AC_JACK_PORT_COMPLEX
)
3116 if (location
&& get_defcfg_location(defcfg
) != location
)
3118 caps
= snd_hda_query_pin_caps(codec
, nid
);
3119 if (!(caps
& AC_PINCAP_OUT
))
3121 dac
= alc_auto_look_for_dac(codec
, nid
);
3124 spec
->multi_io
[num_pins
].pin
= nid
;
3125 spec
->multi_io
[num_pins
].dac
= dac
;
3127 spec
->private_dac_nids
[spec
->multiout
.num_dacs
++] = dac
;
3130 spec
->multiout
.num_dacs
= 1;
3136 static int alc_auto_ch_mode_info(struct snd_kcontrol
*kcontrol
,
3137 struct snd_ctl_elem_info
*uinfo
)
3139 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3140 struct alc_spec
*spec
= codec
->spec
;
3142 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
3144 uinfo
->value
.enumerated
.items
= spec
->multi_ios
+ 1;
3145 if (uinfo
->value
.enumerated
.item
> spec
->multi_ios
)
3146 uinfo
->value
.enumerated
.item
= spec
->multi_ios
;
3147 sprintf(uinfo
->value
.enumerated
.name
, "%dch",
3148 (uinfo
->value
.enumerated
.item
+ 1) * 2);
3152 static int alc_auto_ch_mode_get(struct snd_kcontrol
*kcontrol
,
3153 struct snd_ctl_elem_value
*ucontrol
)
3155 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3156 struct alc_spec
*spec
= codec
->spec
;
3157 ucontrol
->value
.enumerated
.item
[0] = (spec
->ext_channel_count
- 1) / 2;
3161 static int alc_set_multi_io(struct hda_codec
*codec
, int idx
, bool output
)
3163 struct alc_spec
*spec
= codec
->spec
;
3164 hda_nid_t nid
= spec
->multi_io
[idx
].pin
;
3166 if (!spec
->multi_io
[idx
].ctl_in
)
3167 spec
->multi_io
[idx
].ctl_in
=
3168 snd_hda_codec_read(codec
, nid
, 0,
3169 AC_VERB_GET_PIN_WIDGET_CONTROL
, 0);
3171 snd_hda_codec_update_cache(codec
, nid
, 0,
3172 AC_VERB_SET_PIN_WIDGET_CONTROL
,
3174 if (get_wcaps(codec
, nid
) & AC_WCAP_OUT_AMP
)
3175 snd_hda_codec_amp_stereo(codec
, nid
, HDA_OUTPUT
, 0,
3177 alc_auto_select_dac(codec
, nid
, spec
->multi_io
[idx
].dac
);
3179 if (get_wcaps(codec
, nid
) & AC_WCAP_OUT_AMP
)
3180 snd_hda_codec_amp_stereo(codec
, nid
, HDA_OUTPUT
, 0,
3181 HDA_AMP_MUTE
, HDA_AMP_MUTE
);
3182 snd_hda_codec_update_cache(codec
, nid
, 0,
3183 AC_VERB_SET_PIN_WIDGET_CONTROL
,
3184 spec
->multi_io
[idx
].ctl_in
);
3189 static int alc_auto_ch_mode_put(struct snd_kcontrol
*kcontrol
,
3190 struct snd_ctl_elem_value
*ucontrol
)
3192 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3193 struct alc_spec
*spec
= codec
->spec
;
3196 ch
= ucontrol
->value
.enumerated
.item
[0];
3197 if (ch
< 0 || ch
> spec
->multi_ios
)
3199 if (ch
== (spec
->ext_channel_count
- 1) / 2)
3201 spec
->ext_channel_count
= (ch
+ 1) * 2;
3202 for (i
= 0; i
< spec
->multi_ios
; i
++)
3203 alc_set_multi_io(codec
, i
, i
< ch
);
3204 spec
->multiout
.max_channels
= spec
->ext_channel_count
;
3205 if (spec
->need_dac_fix
&& !spec
->const_channel_count
)
3206 spec
->multiout
.num_dacs
= spec
->multiout
.max_channels
/ 2;
3210 static const struct snd_kcontrol_new alc_auto_channel_mode_enum
= {
3211 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
3212 .name
= "Channel Mode",
3213 .info
= alc_auto_ch_mode_info
,
3214 .get
= alc_auto_ch_mode_get
,
3215 .put
= alc_auto_ch_mode_put
,
3218 static int alc_auto_add_multi_channel_mode(struct hda_codec
*codec
,
3219 int (*fill_dac
)(struct hda_codec
*))
3221 struct alc_spec
*spec
= codec
->spec
;
3222 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
3223 unsigned int location
, defcfg
;
3226 if (cfg
->line_out_type
== AUTO_PIN_SPEAKER_OUT
&& cfg
->hp_outs
== 1) {
3227 /* use HP as primary out */
3228 cfg
->speaker_outs
= cfg
->line_outs
;
3229 memcpy(cfg
->speaker_pins
, cfg
->line_out_pins
,
3230 sizeof(cfg
->speaker_pins
));
3231 cfg
->line_outs
= cfg
->hp_outs
;
3232 memcpy(cfg
->line_out_pins
, cfg
->hp_pins
, sizeof(cfg
->hp_pins
));
3234 memset(cfg
->hp_pins
, 0, sizeof(cfg
->hp_pins
));
3235 cfg
->line_out_type
= AUTO_PIN_HP_OUT
;
3239 if (cfg
->line_outs
!= 1 ||
3240 cfg
->line_out_type
== AUTO_PIN_SPEAKER_OUT
)
3243 defcfg
= snd_hda_codec_get_pincfg(codec
, cfg
->line_out_pins
[0]);
3244 location
= get_defcfg_location(defcfg
);
3246 num_pins
= alc_auto_fill_multi_ios(codec
, location
);
3248 struct snd_kcontrol_new
*knew
;
3250 knew
= alc_kcontrol_new(spec
);
3253 *knew
= alc_auto_channel_mode_enum
;
3254 knew
->name
= kstrdup("Channel Mode", GFP_KERNEL
);
3258 spec
->multi_ios
= num_pins
;
3259 spec
->ext_channel_count
= 2;
3260 spec
->multiout
.num_dacs
= num_pins
+ 1;
3265 /* filter out invalid adc_nids (and capsrc_nids) that don't give all
3268 static void alc_remove_invalid_adc_nids(struct hda_codec
*codec
)
3270 struct alc_spec
*spec
= codec
->spec
;
3271 const struct hda_input_mux
*imux
;
3272 hda_nid_t adc_nids
[ARRAY_SIZE(spec
->private_adc_nids
)];
3273 hda_nid_t capsrc_nids
[ARRAY_SIZE(spec
->private_adc_nids
)];
3276 imux
= spec
->input_mux
;
3279 if (spec
->dyn_adc_switch
)
3283 for (n
= 0; n
< spec
->num_adc_nids
; n
++) {
3284 hda_nid_t cap
= spec
->private_capsrc_nids
[n
];
3285 int num_conns
= snd_hda_get_conn_list(codec
, cap
, NULL
);
3286 for (i
= 0; i
< imux
->num_items
; i
++) {
3287 hda_nid_t pin
= spec
->imux_pins
[i
];
3289 if (get_connection_index(codec
, cap
, pin
) < 0)
3291 } else if (num_conns
<= imux
->items
[i
].index
)
3294 if (i
>= imux
->num_items
) {
3295 adc_nids
[nums
] = spec
->private_adc_nids
[n
];
3296 capsrc_nids
[nums
++] = cap
;
3300 /* check whether ADC-switch is possible */
3301 if (!alc_check_dyn_adc_switch(codec
)) {
3302 printk(KERN_WARNING
"hda_codec: %s: no valid ADC found;"
3303 " using fallback 0x%x\n",
3304 codec
->chip_name
, spec
->private_adc_nids
[0]);
3305 spec
->num_adc_nids
= 1;
3309 } else if (nums
!= spec
->num_adc_nids
) {
3310 memcpy(spec
->private_adc_nids
, adc_nids
,
3311 nums
* sizeof(hda_nid_t
));
3312 memcpy(spec
->private_capsrc_nids
, capsrc_nids
,
3313 nums
* sizeof(hda_nid_t
));
3314 spec
->num_adc_nids
= nums
;
3318 alc_auto_mic_check_imux(codec
); /* check auto-mic setups */
3319 else if (spec
->input_mux
->num_items
== 1)
3320 spec
->num_adc_nids
= 1; /* reduce to a single ADC */
3324 * initialize ADC paths
3326 static void alc_auto_init_adc(struct hda_codec
*codec
, int adc_idx
)
3328 struct alc_spec
*spec
= codec
->spec
;
3331 nid
= spec
->adc_nids
[adc_idx
];
3333 if (nid_has_mute(codec
, nid
, HDA_INPUT
)) {
3334 snd_hda_codec_write(codec
, nid
, 0,
3335 AC_VERB_SET_AMP_GAIN_MUTE
,
3339 if (!spec
->capsrc_nids
)
3341 nid
= spec
->capsrc_nids
[adc_idx
];
3342 if (nid_has_mute(codec
, nid
, HDA_OUTPUT
))
3343 snd_hda_codec_write(codec
, nid
, 0,
3344 AC_VERB_SET_AMP_GAIN_MUTE
,
3348 static void alc_auto_init_input_src(struct hda_codec
*codec
)
3350 struct alc_spec
*spec
= codec
->spec
;
3353 for (c
= 0; c
< spec
->num_adc_nids
; c
++)
3354 alc_auto_init_adc(codec
, c
);
3355 if (spec
->dyn_adc_switch
)
3358 nums
= spec
->num_adc_nids
;
3359 for (c
= 0; c
< nums
; c
++)
3360 alc_mux_select(codec
, 0, spec
->cur_mux
[c
], true);
3363 /* add mic boosts if needed */
3364 static int alc_auto_add_mic_boost(struct hda_codec
*codec
)
3366 struct alc_spec
*spec
= codec
->spec
;
3367 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
3371 const char *prev_label
= NULL
;
3373 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
3374 if (cfg
->inputs
[i
].type
> AUTO_PIN_MIC
)
3376 nid
= cfg
->inputs
[i
].pin
;
3377 if (get_wcaps(codec
, nid
) & AC_WCAP_IN_AMP
) {
3379 char boost_label
[32];
3381 label
= hda_get_autocfg_input_label(codec
, cfg
, i
);
3382 if (prev_label
&& !strcmp(label
, prev_label
))
3388 snprintf(boost_label
, sizeof(boost_label
),
3389 "%s Boost Volume", label
);
3390 err
= add_control(spec
, ALC_CTL_WIDGET_VOL
,
3391 boost_label
, type_idx
,
3392 HDA_COMPOSE_AMP_VAL(nid
, 3, 0, HDA_INPUT
));
3400 /* select or unmute the given capsrc route */
3401 static void select_or_unmute_capsrc(struct hda_codec
*codec
, hda_nid_t cap
,
3404 if (get_wcaps_type(get_wcaps(codec
, cap
)) == AC_WID_AUD_MIX
) {
3405 snd_hda_codec_amp_stereo(codec
, cap
, HDA_INPUT
, idx
,
3407 } else if (snd_hda_get_conn_list(codec
, cap
, NULL
) > 1) {
3408 snd_hda_codec_write_cache(codec
, cap
, 0,
3409 AC_VERB_SET_CONNECT_SEL
, idx
);
3413 /* set the default connection to that pin */
3414 static int init_capsrc_for_pin(struct hda_codec
*codec
, hda_nid_t pin
)
3416 struct alc_spec
*spec
= codec
->spec
;
3421 for (i
= 0; i
< spec
->num_adc_nids
; i
++) {
3422 hda_nid_t cap
= spec
->capsrc_nids
?
3423 spec
->capsrc_nids
[i
] : spec
->adc_nids
[i
];
3426 idx
= get_connection_index(codec
, cap
, pin
);
3429 select_or_unmute_capsrc(codec
, cap
, idx
);
3430 return i
; /* return the found index */
3432 return -1; /* not found */
3435 /* initialize some special cases for input sources */
3436 static void alc_init_special_input_src(struct hda_codec
*codec
)
3438 struct alc_spec
*spec
= codec
->spec
;
3441 for (i
= 0; i
< spec
->autocfg
.num_inputs
; i
++)
3442 init_capsrc_for_pin(codec
, spec
->autocfg
.inputs
[i
].pin
);
3445 /* assign appropriate capture mixers */
3446 static void set_capture_mixer(struct hda_codec
*codec
)
3448 struct alc_spec
*spec
= codec
->spec
;
3449 static const struct snd_kcontrol_new
*caps
[2][3] = {
3450 { alc_capture_mixer_nosrc1
,
3451 alc_capture_mixer_nosrc2
,
3452 alc_capture_mixer_nosrc3
},
3453 { alc_capture_mixer1
,
3455 alc_capture_mixer3
},
3458 /* check whether either of ADC or MUX has a volume control */
3459 if (!nid_has_volume(codec
, spec
->adc_nids
[0], HDA_INPUT
)) {
3460 if (!spec
->capsrc_nids
)
3461 return; /* no volume */
3462 if (!nid_has_volume(codec
, spec
->capsrc_nids
[0], HDA_OUTPUT
))
3463 return; /* no volume in capsrc, too */
3464 spec
->vol_in_capsrc
= 1;
3467 if (spec
->num_adc_nids
> 0) {
3471 if (spec
->input_mux
&& spec
->input_mux
->num_items
> 1)
3473 if (spec
->auto_mic
) {
3476 } else if (spec
->dyn_adc_switch
)
3479 if (spec
->num_adc_nids
> 3)
3480 spec
->num_adc_nids
= 3;
3481 else if (!spec
->num_adc_nids
)
3483 num_adcs
= spec
->num_adc_nids
;
3485 spec
->cap_mixer
= caps
[mux
][num_adcs
- 1];
3490 * standard auto-parser initializations
3492 static void alc_auto_init_std(struct hda_codec
*codec
)
3494 struct alc_spec
*spec
= codec
->spec
;
3495 alc_auto_init_multi_out(codec
);
3496 alc_auto_init_extra_out(codec
);
3497 alc_auto_init_analog_input(codec
);
3498 alc_auto_init_input_src(codec
);
3499 alc_auto_init_digital(codec
);
3500 if (spec
->unsol_event
)
3501 alc_inithook(codec
);
3505 * Digital-beep handlers
3507 #ifdef CONFIG_SND_HDA_INPUT_BEEP
3508 #define set_beep_amp(spec, nid, idx, dir) \
3509 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
3511 static const struct snd_pci_quirk beep_white_list
[] = {
3512 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
3513 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
3514 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
3515 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
3516 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
3520 static inline int has_cdefine_beep(struct hda_codec
*codec
)
3522 struct alc_spec
*spec
= codec
->spec
;
3523 const struct snd_pci_quirk
*q
;
3524 q
= snd_pci_quirk_lookup(codec
->bus
->pci
, beep_white_list
);
3527 return spec
->cdefine
.enable_pcbeep
;
3530 #define set_beep_amp(spec, nid, idx, dir) /* NOP */
3531 #define has_cdefine_beep(codec) 0
3534 /* parse the BIOS configuration and set up the alc_spec */
3535 /* return 1 if successful, 0 if the proper config is not found,
3536 * or a negative error code
3538 static int alc_parse_auto_config(struct hda_codec
*codec
,
3539 const hda_nid_t
*ignore_nids
,
3540 const hda_nid_t
*ssid_nids
)
3542 struct alc_spec
*spec
= codec
->spec
;
3545 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
,
3549 if (!spec
->autocfg
.line_outs
) {
3550 if (spec
->autocfg
.dig_outs
|| spec
->autocfg
.dig_in_pin
) {
3551 spec
->multiout
.max_channels
= 2;
3552 spec
->no_analog
= 1;
3555 return 0; /* can't find valid BIOS pin config */
3557 err
= alc_auto_fill_dac_nids(codec
);
3560 err
= alc_auto_add_multi_channel_mode(codec
, alc_auto_fill_dac_nids
);
3563 err
= alc_auto_create_multi_out_ctls(codec
, &spec
->autocfg
);
3566 err
= alc_auto_create_hp_out(codec
);
3569 err
= alc_auto_create_speaker_out(codec
);
3572 err
= alc_auto_create_input_ctls(codec
);
3576 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
3579 alc_auto_parse_digital(codec
);
3581 if (!spec
->no_analog
)
3582 alc_remove_invalid_adc_nids(codec
);
3585 alc_ssid_check(codec
, ssid_nids
);
3587 if (!spec
->no_analog
) {
3588 alc_auto_check_switches(codec
);
3589 err
= alc_auto_add_mic_boost(codec
);
3594 if (spec
->kctls
.list
)
3595 add_mixer(spec
, spec
->kctls
.list
);
3600 static int alc880_parse_auto_config(struct hda_codec
*codec
)
3602 static const hda_nid_t alc880_ignore
[] = { 0x1d, 0 };
3603 static const hda_nid_t alc880_ssids
[] = { 0x15, 0x1b, 0x14, 0 };
3604 return alc_parse_auto_config(codec
, alc880_ignore
, alc880_ssids
);
3607 #ifdef CONFIG_SND_HDA_POWER_SAVE
3608 static const struct hda_amp_list alc880_loopbacks
[] = {
3609 { 0x0b, HDA_INPUT
, 0 },
3610 { 0x0b, HDA_INPUT
, 1 },
3611 { 0x0b, HDA_INPUT
, 2 },
3612 { 0x0b, HDA_INPUT
, 3 },
3613 { 0x0b, HDA_INPUT
, 4 },
3621 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3622 #define alc_board_config \
3623 snd_hda_check_board_config
3624 #define alc_board_codec_sid_config \
3625 snd_hda_check_board_codec_sid_config
3626 #include "alc_quirks.c"
3628 #define alc_board_config(codec, nums, models, tbl) -1
3629 #define alc_board_codec_sid_config(codec, nums, models, tbl) -1
3630 #define setup_preset(codec, x) /* NOP */
3634 * OK, here we have finally the patch for ALC880
3636 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3637 #include "alc880_quirks.c"
3640 static int patch_alc880(struct hda_codec
*codec
)
3642 struct alc_spec
*spec
;
3646 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
3652 spec
->mixer_nid
= 0x0b;
3653 spec
->need_dac_fix
= 1;
3655 board_config
= alc_board_config(codec
, ALC880_MODEL_LAST
,
3656 alc880_models
, alc880_cfg_tbl
);
3657 if (board_config
< 0) {
3658 printk(KERN_INFO
"hda_codec: %s: BIOS auto-probing.\n",
3660 board_config
= ALC_MODEL_AUTO
;
3663 if (board_config
== ALC_MODEL_AUTO
) {
3664 /* automatic parse from the BIOS config */
3665 err
= alc880_parse_auto_config(codec
);
3670 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3673 "hda_codec: Cannot set up configuration "
3674 "from BIOS. Using 3-stack mode...\n");
3675 board_config
= ALC880_3ST
;
3680 if (board_config
!= ALC_MODEL_AUTO
)
3681 setup_preset(codec
, &alc880_presets
[board_config
]);
3683 if (!spec
->no_analog
&& !spec
->adc_nids
) {
3684 alc_auto_fill_adc_caps(codec
);
3685 alc_rebuild_imux_for_auto_mic(codec
);
3686 alc_remove_invalid_adc_nids(codec
);
3689 if (!spec
->no_analog
&& !spec
->cap_mixer
)
3690 set_capture_mixer(codec
);
3692 if (!spec
->no_analog
) {
3693 err
= snd_hda_attach_beep_device(codec
, 0x1);
3698 set_beep_amp(spec
, 0x0b, 0x05, HDA_INPUT
);
3701 spec
->vmaster_nid
= 0x0c;
3703 codec
->patch_ops
= alc_patch_ops
;
3704 if (board_config
== ALC_MODEL_AUTO
)
3705 spec
->init_hook
= alc_auto_init_std
;
3706 #ifdef CONFIG_SND_HDA_POWER_SAVE
3707 if (!spec
->loopback
.amplist
)
3708 spec
->loopback
.amplist
= alc880_loopbacks
;
3718 static int alc260_parse_auto_config(struct hda_codec
*codec
)
3720 static const hda_nid_t alc260_ignore
[] = { 0x17, 0 };
3721 static const hda_nid_t alc260_ssids
[] = { 0x10, 0x15, 0x0f, 0 };
3722 return alc_parse_auto_config(codec
, alc260_ignore
, alc260_ssids
);
3725 #ifdef CONFIG_SND_HDA_POWER_SAVE
3726 static const struct hda_amp_list alc260_loopbacks
[] = {
3727 { 0x07, HDA_INPUT
, 0 },
3728 { 0x07, HDA_INPUT
, 1 },
3729 { 0x07, HDA_INPUT
, 2 },
3730 { 0x07, HDA_INPUT
, 3 },
3731 { 0x07, HDA_INPUT
, 4 },
3743 static const struct alc_fixup alc260_fixups
[] = {
3744 [PINFIX_HP_DC5750
] = {
3745 .type
= ALC_FIXUP_PINS
,
3746 .v
.pins
= (const struct alc_pincfg
[]) {
3747 { 0x11, 0x90130110 }, /* speaker */
3753 static const struct snd_pci_quirk alc260_fixup_tbl
[] = {
3754 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", PINFIX_HP_DC5750
),
3760 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3761 #include "alc260_quirks.c"
3764 static int patch_alc260(struct hda_codec
*codec
)
3766 struct alc_spec
*spec
;
3767 int err
, board_config
;
3769 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
3775 spec
->mixer_nid
= 0x07;
3777 board_config
= alc_board_config(codec
, ALC260_MODEL_LAST
,
3778 alc260_models
, alc260_cfg_tbl
);
3779 if (board_config
< 0) {
3780 snd_printd(KERN_INFO
"hda_codec: %s: BIOS auto-probing.\n",
3782 board_config
= ALC_MODEL_AUTO
;
3785 if (board_config
== ALC_MODEL_AUTO
) {
3786 alc_pick_fixup(codec
, NULL
, alc260_fixup_tbl
, alc260_fixups
);
3787 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
3790 if (board_config
== ALC_MODEL_AUTO
) {
3791 /* automatic parse from the BIOS config */
3792 err
= alc260_parse_auto_config(codec
);
3797 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3800 "hda_codec: Cannot set up configuration "
3801 "from BIOS. Using base mode...\n");
3802 board_config
= ALC260_BASIC
;
3807 if (board_config
!= ALC_MODEL_AUTO
)
3808 setup_preset(codec
, &alc260_presets
[board_config
]);
3810 if (!spec
->no_analog
&& !spec
->adc_nids
) {
3811 alc_auto_fill_adc_caps(codec
);
3812 alc_rebuild_imux_for_auto_mic(codec
);
3813 alc_remove_invalid_adc_nids(codec
);
3816 if (!spec
->no_analog
&& !spec
->cap_mixer
)
3817 set_capture_mixer(codec
);
3819 if (!spec
->no_analog
) {
3820 err
= snd_hda_attach_beep_device(codec
, 0x1);
3825 set_beep_amp(spec
, 0x07, 0x05, HDA_INPUT
);
3828 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
3830 spec
->vmaster_nid
= 0x08;
3832 codec
->patch_ops
= alc_patch_ops
;
3833 if (board_config
== ALC_MODEL_AUTO
)
3834 spec
->init_hook
= alc_auto_init_std
;
3835 spec
->shutup
= alc_eapd_shutup
;
3836 #ifdef CONFIG_SND_HDA_POWER_SAVE
3837 if (!spec
->loopback
.amplist
)
3838 spec
->loopback
.amplist
= alc260_loopbacks
;
3846 * ALC882/883/885/888/889 support
3848 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
3849 * configuration. Each pin widget can choose any input DACs and a mixer.
3850 * Each ADC is connected from a mixer of all inputs. This makes possible
3851 * 6-channel independent captures.
3853 * In addition, an independent DAC for the multi-playback (not used in this
3856 #ifdef CONFIG_SND_HDA_POWER_SAVE
3857 #define alc882_loopbacks alc880_loopbacks
3864 PINFIX_ABIT_AW9D_MAX
,
3867 PINFIX_ACER_ASPIRE_7736
,
3870 static const struct alc_fixup alc882_fixups
[] = {
3871 [PINFIX_ABIT_AW9D_MAX
] = {
3872 .type
= ALC_FIXUP_PINS
,
3873 .v
.pins
= (const struct alc_pincfg
[]) {
3874 { 0x15, 0x01080104 }, /* side */
3875 { 0x16, 0x01011012 }, /* rear */
3876 { 0x17, 0x01016011 }, /* clfe */
3880 [PINFIX_LENOVO_Y530
] = {
3881 .type
= ALC_FIXUP_PINS
,
3882 .v
.pins
= (const struct alc_pincfg
[]) {
3883 { 0x15, 0x99130112 }, /* rear int speakers */
3884 { 0x16, 0x99130111 }, /* subwoofer */
3888 [PINFIX_PB_M5210
] = {
3889 .type
= ALC_FIXUP_VERBS
,
3890 .v
.verbs
= (const struct hda_verb
[]) {
3891 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_VREF50
},
3895 [PINFIX_ACER_ASPIRE_7736
] = {
3896 .type
= ALC_FIXUP_SKU
,
3897 .v
.sku
= ALC_FIXUP_SKU_IGNORE
,
3901 static const struct snd_pci_quirk alc882_fixup_tbl
[] = {
3902 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", PINFIX_PB_M5210
),
3903 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", PINFIX_LENOVO_Y530
),
3904 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX
),
3905 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", PINFIX_ACER_ASPIRE_7736
),
3910 * BIOS auto configuration
3912 /* almost identical with ALC880 parser... */
3913 static int alc882_parse_auto_config(struct hda_codec
*codec
)
3915 static const hda_nid_t alc882_ignore
[] = { 0x1d, 0 };
3916 static const hda_nid_t alc882_ssids
[] = { 0x15, 0x1b, 0x14, 0 };
3917 return alc_parse_auto_config(codec
, alc882_ignore
, alc882_ssids
);
3922 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3923 #include "alc882_quirks.c"
3926 static int patch_alc882(struct hda_codec
*codec
)
3928 struct alc_spec
*spec
;
3929 int err
, board_config
;
3931 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
3937 spec
->mixer_nid
= 0x0b;
3939 switch (codec
->vendor_id
) {
3944 /* ALC883 and variants */
3945 alc_fix_pll_init(codec
, 0x20, 0x0a, 10);
3949 board_config
= alc_board_config(codec
, ALC882_MODEL_LAST
,
3950 alc882_models
, alc882_cfg_tbl
);
3952 if (board_config
< 0)
3953 board_config
= alc_board_codec_sid_config(codec
,
3954 ALC882_MODEL_LAST
, alc882_models
, alc882_ssid_cfg_tbl
);
3956 if (board_config
< 0) {
3957 printk(KERN_INFO
"hda_codec: %s: BIOS auto-probing.\n",
3959 board_config
= ALC_MODEL_AUTO
;
3962 if (board_config
== ALC_MODEL_AUTO
) {
3963 alc_pick_fixup(codec
, NULL
, alc882_fixup_tbl
, alc882_fixups
);
3964 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
3967 alc_auto_parse_customize_define(codec
);
3969 if (board_config
== ALC_MODEL_AUTO
) {
3970 /* automatic parse from the BIOS config */
3971 err
= alc882_parse_auto_config(codec
);
3976 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3979 "hda_codec: Cannot set up configuration "
3980 "from BIOS. Using base mode...\n");
3981 board_config
= ALC882_3ST_DIG
;
3986 if (board_config
!= ALC_MODEL_AUTO
)
3987 setup_preset(codec
, &alc882_presets
[board_config
]);
3989 if (!spec
->no_analog
&& !spec
->adc_nids
) {
3990 alc_auto_fill_adc_caps(codec
);
3991 alc_rebuild_imux_for_auto_mic(codec
);
3992 alc_remove_invalid_adc_nids(codec
);
3995 if (!spec
->no_analog
&& !spec
->cap_mixer
)
3996 set_capture_mixer(codec
);
3998 if (!spec
->no_analog
&& has_cdefine_beep(codec
)) {
3999 err
= snd_hda_attach_beep_device(codec
, 0x1);
4004 set_beep_amp(spec
, 0x0b, 0x05, HDA_INPUT
);
4007 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
4009 spec
->vmaster_nid
= 0x0c;
4011 codec
->patch_ops
= alc_patch_ops
;
4012 if (board_config
== ALC_MODEL_AUTO
)
4013 spec
->init_hook
= alc_auto_init_std
;
4015 alc_init_jacks(codec
);
4016 #ifdef CONFIG_SND_HDA_POWER_SAVE
4017 if (!spec
->loopback
.amplist
)
4018 spec
->loopback
.amplist
= alc882_loopbacks
;
4028 static int alc262_parse_auto_config(struct hda_codec
*codec
)
4030 static const hda_nid_t alc262_ignore
[] = { 0x1d, 0 };
4031 static const hda_nid_t alc262_ssids
[] = { 0x15, 0x1b, 0x14, 0 };
4032 return alc_parse_auto_config(codec
, alc262_ignore
, alc262_ssids
);
4043 static const struct alc_fixup alc262_fixups
[] = {
4044 [PINFIX_FSC_H270
] = {
4045 .type
= ALC_FIXUP_PINS
,
4046 .v
.pins
= (const struct alc_pincfg
[]) {
4047 { 0x14, 0x99130110 }, /* speaker */
4048 { 0x15, 0x0221142f }, /* front HP */
4049 { 0x1b, 0x0121141f }, /* rear HP */
4053 [PINFIX_HP_Z200
] = {
4054 .type
= ALC_FIXUP_PINS
,
4055 .v
.pins
= (const struct alc_pincfg
[]) {
4056 { 0x16, 0x99130120 }, /* internal speaker */
4062 static const struct snd_pci_quirk alc262_fixup_tbl
[] = {
4063 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", PINFIX_HP_Z200
),
4064 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", PINFIX_FSC_H270
),
4069 #ifdef CONFIG_SND_HDA_POWER_SAVE
4070 #define alc262_loopbacks alc880_loopbacks
4075 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4076 #include "alc262_quirks.c"
4079 static int patch_alc262(struct hda_codec
*codec
)
4081 struct alc_spec
*spec
;
4085 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
4091 spec
->mixer_nid
= 0x0b;
4094 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
4099 snd_hda_codec_write(codec
, 0x1a, 0, AC_VERB_SET_COEF_INDEX
, 7);
4100 tmp
= snd_hda_codec_read(codec
, 0x20, 0, AC_VERB_GET_PROC_COEF
, 0);
4101 snd_hda_codec_write(codec
, 0x1a, 0, AC_VERB_SET_COEF_INDEX
, 7);
4102 snd_hda_codec_write(codec
, 0x1a, 0, AC_VERB_SET_PROC_COEF
, tmp
| 0x80);
4105 alc_auto_parse_customize_define(codec
);
4107 alc_fix_pll_init(codec
, 0x20, 0x0a, 10);
4109 board_config
= alc_board_config(codec
, ALC262_MODEL_LAST
,
4110 alc262_models
, alc262_cfg_tbl
);
4112 if (board_config
< 0) {
4113 printk(KERN_INFO
"hda_codec: %s: BIOS auto-probing.\n",
4115 board_config
= ALC_MODEL_AUTO
;
4118 if (board_config
== ALC_MODEL_AUTO
) {
4119 alc_pick_fixup(codec
, NULL
, alc262_fixup_tbl
, alc262_fixups
);
4120 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
4123 if (board_config
== ALC_MODEL_AUTO
) {
4124 /* automatic parse from the BIOS config */
4125 err
= alc262_parse_auto_config(codec
);
4130 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4133 "hda_codec: Cannot set up configuration "
4134 "from BIOS. Using base mode...\n");
4135 board_config
= ALC262_BASIC
;
4140 if (board_config
!= ALC_MODEL_AUTO
)
4141 setup_preset(codec
, &alc262_presets
[board_config
]);
4143 if (!spec
->no_analog
&& !spec
->adc_nids
) {
4144 alc_auto_fill_adc_caps(codec
);
4145 alc_rebuild_imux_for_auto_mic(codec
);
4146 alc_remove_invalid_adc_nids(codec
);
4149 if (!spec
->no_analog
&& !spec
->cap_mixer
)
4150 set_capture_mixer(codec
);
4152 if (!spec
->no_analog
&& has_cdefine_beep(codec
)) {
4153 err
= snd_hda_attach_beep_device(codec
, 0x1);
4158 set_beep_amp(spec
, 0x0b, 0x05, HDA_INPUT
);
4161 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
4163 spec
->vmaster_nid
= 0x0c;
4165 codec
->patch_ops
= alc_patch_ops
;
4166 if (board_config
== ALC_MODEL_AUTO
)
4167 spec
->init_hook
= alc_auto_init_std
;
4168 spec
->shutup
= alc_eapd_shutup
;
4170 alc_init_jacks(codec
);
4171 #ifdef CONFIG_SND_HDA_POWER_SAVE
4172 if (!spec
->loopback
.amplist
)
4173 spec
->loopback
.amplist
= alc262_loopbacks
;
4182 /* bind Beep switches of both NID 0x0f and 0x10 */
4183 static const struct hda_bind_ctls alc268_bind_beep_sw
= {
4184 .ops
= &snd_hda_bind_sw
,
4186 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT
),
4187 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT
),
4192 static const struct snd_kcontrol_new alc268_beep_mixer
[] = {
4193 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT
),
4194 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw
),
4198 /* set PCBEEP vol = 0, mute connections */
4199 static const struct hda_verb alc268_beep_init_verbs
[] = {
4200 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
4201 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(1)},
4202 {0x10, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(1)},
4207 * BIOS auto configuration
4209 static int alc268_parse_auto_config(struct hda_codec
*codec
)
4211 static const hda_nid_t alc268_ssids
[] = { 0x15, 0x1b, 0x14, 0 };
4212 struct alc_spec
*spec
= codec
->spec
;
4213 int err
= alc_parse_auto_config(codec
, NULL
, alc268_ssids
);
4215 if (!spec
->no_analog
&& spec
->autocfg
.speaker_pins
[0] != 0x1d) {
4216 add_mixer(spec
, alc268_beep_mixer
);
4217 add_verb(spec
, alc268_beep_init_verbs
);
4225 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4226 #include "alc268_quirks.c"
4229 static int patch_alc268(struct hda_codec
*codec
)
4231 struct alc_spec
*spec
;
4233 int i
, has_beep
, err
;
4235 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
4241 /* ALC268 has no aa-loopback mixer */
4243 board_config
= alc_board_config(codec
, ALC268_MODEL_LAST
,
4244 alc268_models
, alc268_cfg_tbl
);
4246 if (board_config
< 0)
4247 board_config
= alc_board_codec_sid_config(codec
,
4248 ALC268_MODEL_LAST
, alc268_models
, alc268_ssid_cfg_tbl
);
4250 if (board_config
< 0) {
4251 printk(KERN_INFO
"hda_codec: %s: BIOS auto-probing.\n",
4253 board_config
= ALC_MODEL_AUTO
;
4256 if (board_config
== ALC_MODEL_AUTO
) {
4257 /* automatic parse from the BIOS config */
4258 err
= alc268_parse_auto_config(codec
);
4263 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4266 "hda_codec: Cannot set up configuration "
4267 "from BIOS. Using base mode...\n");
4268 board_config
= ALC268_3ST
;
4273 if (board_config
!= ALC_MODEL_AUTO
)
4274 setup_preset(codec
, &alc268_presets
[board_config
]);
4277 for (i
= 0; i
< spec
->num_mixers
; i
++) {
4278 if (spec
->mixers
[i
] == alc268_beep_mixer
) {
4285 err
= snd_hda_attach_beep_device(codec
, 0x1);
4290 if (!query_amp_caps(codec
, 0x1d, HDA_INPUT
))
4291 /* override the amp caps for beep generator */
4292 snd_hda_override_amp_caps(codec
, 0x1d, HDA_INPUT
,
4293 (0x0c << AC_AMPCAP_OFFSET_SHIFT
) |
4294 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT
) |
4295 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT
) |
4296 (0 << AC_AMPCAP_MUTE_SHIFT
));
4299 if (!spec
->no_analog
&& !spec
->adc_nids
) {
4300 alc_auto_fill_adc_caps(codec
);
4301 alc_rebuild_imux_for_auto_mic(codec
);
4302 alc_remove_invalid_adc_nids(codec
);
4305 if (!spec
->no_analog
&& !spec
->cap_mixer
)
4306 set_capture_mixer(codec
);
4308 spec
->vmaster_nid
= 0x02;
4310 codec
->patch_ops
= alc_patch_ops
;
4311 if (board_config
== ALC_MODEL_AUTO
)
4312 spec
->init_hook
= alc_auto_init_std
;
4313 spec
->shutup
= alc_eapd_shutup
;
4315 alc_init_jacks(codec
);
4323 #ifdef CONFIG_SND_HDA_POWER_SAVE
4324 #define alc269_loopbacks alc880_loopbacks
4327 static const struct hda_pcm_stream alc269_44k_pcm_analog_playback
= {
4331 .rates
= SNDRV_PCM_RATE_44100
, /* fixed rate */
4332 /* NID is set in alc_build_pcms */
4334 .open
= alc_playback_pcm_open
,
4335 .prepare
= alc_playback_pcm_prepare
,
4336 .cleanup
= alc_playback_pcm_cleanup
4340 static const struct hda_pcm_stream alc269_44k_pcm_analog_capture
= {
4344 .rates
= SNDRV_PCM_RATE_44100
, /* fixed rate */
4345 /* NID is set in alc_build_pcms */
4348 #ifdef CONFIG_SND_HDA_POWER_SAVE
4349 static int alc269_mic2_for_mute_led(struct hda_codec
*codec
)
4351 switch (codec
->subsystem_id
) {
4358 static int alc269_mic2_mute_check_ps(struct hda_codec
*codec
, hda_nid_t nid
)
4360 /* update mute-LED according to the speaker mute state */
4361 if (nid
== 0x01 || nid
== 0x14) {
4363 if (snd_hda_codec_amp_read(codec
, 0x14, 0, HDA_OUTPUT
, 0) &
4368 /* mic2 vref pin is used for mute LED control */
4369 snd_hda_codec_update_cache(codec
, 0x19, 0,
4370 AC_VERB_SET_PIN_WIDGET_CONTROL
,
4373 return alc_check_power_status(codec
, nid
);
4375 #endif /* CONFIG_SND_HDA_POWER_SAVE */
4377 /* different alc269-variants */
4379 ALC269_TYPE_ALC269VA
,
4380 ALC269_TYPE_ALC269VB
,
4381 ALC269_TYPE_ALC269VC
,
4385 * BIOS auto configuration
4387 static int alc269_parse_auto_config(struct hda_codec
*codec
)
4389 static const hda_nid_t alc269_ignore
[] = { 0x1d, 0 };
4390 static const hda_nid_t alc269_ssids
[] = { 0, 0x1b, 0x14, 0x21 };
4391 static const hda_nid_t alc269va_ssids
[] = { 0x15, 0x1b, 0x14, 0 };
4392 struct alc_spec
*spec
= codec
->spec
;
4393 const hda_nid_t
*ssids
= spec
->codec_variant
== ALC269_TYPE_ALC269VA
?
4394 alc269va_ssids
: alc269_ssids
;
4396 return alc_parse_auto_config(codec
, alc269_ignore
, ssids
);
4399 static void alc269_toggle_power_output(struct hda_codec
*codec
, int power_up
)
4401 int val
= alc_read_coef_idx(codec
, 0x04);
4406 alc_write_coef_idx(codec
, 0x04, val
);
4409 static void alc269_shutup(struct hda_codec
*codec
)
4411 if ((alc_read_coef_idx(codec
, 0) & 0x00ff) == 0x017)
4412 alc269_toggle_power_output(codec
, 0);
4413 if ((alc_read_coef_idx(codec
, 0) & 0x00ff) == 0x018) {
4414 alc269_toggle_power_output(codec
, 0);
4420 static int alc269_resume(struct hda_codec
*codec
)
4422 if ((alc_read_coef_idx(codec
, 0) & 0x00ff) == 0x018) {
4423 alc269_toggle_power_output(codec
, 0);
4427 codec
->patch_ops
.init(codec
);
4429 if ((alc_read_coef_idx(codec
, 0) & 0x00ff) == 0x017) {
4430 alc269_toggle_power_output(codec
, 1);
4434 if ((alc_read_coef_idx(codec
, 0) & 0x00ff) == 0x018)
4435 alc269_toggle_power_output(codec
, 1);
4437 snd_hda_codec_resume_amp(codec
);
4438 snd_hda_codec_resume_cache(codec
);
4439 hda_call_check_power_status(codec
, 0x01);
4442 #endif /* CONFIG_PM */
4444 static void alc269_fixup_hweq(struct hda_codec
*codec
,
4445 const struct alc_fixup
*fix
, int action
)
4449 if (action
!= ALC_FIXUP_ACT_INIT
)
4451 coef
= alc_read_coef_idx(codec
, 0x1e);
4452 alc_write_coef_idx(codec
, 0x1e, coef
| 0x80);
4455 static void alc271_fixup_dmic(struct hda_codec
*codec
,
4456 const struct alc_fixup
*fix
, int action
)
4458 static const struct hda_verb verbs
[] = {
4459 {0x20, AC_VERB_SET_COEF_INDEX
, 0x0d},
4460 {0x20, AC_VERB_SET_PROC_COEF
, 0x4000},
4465 if (strcmp(codec
->chip_name
, "ALC271X"))
4467 cfg
= snd_hda_codec_get_pincfg(codec
, 0x12);
4468 if (get_defcfg_connect(cfg
) == AC_JACK_PORT_FIXED
)
4469 snd_hda_sequence_write(codec
, verbs
);
4472 static void alc269_fixup_pcm_44k(struct hda_codec
*codec
,
4473 const struct alc_fixup
*fix
, int action
)
4475 struct alc_spec
*spec
= codec
->spec
;
4477 if (action
!= ALC_FIXUP_ACT_PROBE
)
4480 /* Due to a hardware problem on Lenovo Ideadpad, we need to
4481 * fix the sample rate of analog I/O to 44.1kHz
4483 spec
->stream_analog_playback
= &alc269_44k_pcm_analog_playback
;
4484 spec
->stream_analog_capture
= &alc269_44k_pcm_analog_capture
;
4487 static void alc269_fixup_stereo_dmic(struct hda_codec
*codec
,
4488 const struct alc_fixup
*fix
, int action
)
4492 if (action
!= ALC_FIXUP_ACT_INIT
)
4494 /* The digital-mic unit sends PDM (differential signal) instead of
4495 * the standard PCM, thus you can't record a valid mono stream as is.
4496 * Below is a workaround specific to ALC269 to control the dmic
4497 * signal source as mono.
4499 coef
= alc_read_coef_idx(codec
, 0x07);
4500 alc_write_coef_idx(codec
, 0x07, coef
| 0x80);
4504 ALC269_FIXUP_SONY_VAIO
,
4505 ALC275_FIXUP_SONY_VAIO_GPIO2
,
4506 ALC269_FIXUP_DELL_M101Z
,
4507 ALC269_FIXUP_SKU_IGNORE
,
4508 ALC269_FIXUP_ASUS_G73JW
,
4509 ALC269_FIXUP_LENOVO_EAPD
,
4510 ALC275_FIXUP_SONY_HWEQ
,
4512 ALC269_FIXUP_PCM_44K
,
4513 ALC269_FIXUP_STEREO_DMIC
,
4516 static const struct alc_fixup alc269_fixups
[] = {
4517 [ALC269_FIXUP_SONY_VAIO
] = {
4518 .type
= ALC_FIXUP_VERBS
,
4519 .v
.verbs
= (const struct hda_verb
[]) {
4520 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_VREFGRD
},
4524 [ALC275_FIXUP_SONY_VAIO_GPIO2
] = {
4525 .type
= ALC_FIXUP_VERBS
,
4526 .v
.verbs
= (const struct hda_verb
[]) {
4527 {0x01, AC_VERB_SET_GPIO_MASK
, 0x04},
4528 {0x01, AC_VERB_SET_GPIO_DIRECTION
, 0x04},
4529 {0x01, AC_VERB_SET_GPIO_DATA
, 0x00},
4533 .chain_id
= ALC269_FIXUP_SONY_VAIO
4535 [ALC269_FIXUP_DELL_M101Z
] = {
4536 .type
= ALC_FIXUP_VERBS
,
4537 .v
.verbs
= (const struct hda_verb
[]) {
4538 /* Enables internal speaker */
4539 {0x20, AC_VERB_SET_COEF_INDEX
, 13},
4540 {0x20, AC_VERB_SET_PROC_COEF
, 0x4040},
4544 [ALC269_FIXUP_SKU_IGNORE
] = {
4545 .type
= ALC_FIXUP_SKU
,
4546 .v
.sku
= ALC_FIXUP_SKU_IGNORE
,
4548 [ALC269_FIXUP_ASUS_G73JW
] = {
4549 .type
= ALC_FIXUP_PINS
,
4550 .v
.pins
= (const struct alc_pincfg
[]) {
4551 { 0x17, 0x99130111 }, /* subwoofer */
4555 [ALC269_FIXUP_LENOVO_EAPD
] = {
4556 .type
= ALC_FIXUP_VERBS
,
4557 .v
.verbs
= (const struct hda_verb
[]) {
4558 {0x14, AC_VERB_SET_EAPD_BTLENABLE
, 0},
4562 [ALC275_FIXUP_SONY_HWEQ
] = {
4563 .type
= ALC_FIXUP_FUNC
,
4564 .v
.func
= alc269_fixup_hweq
,
4566 .chain_id
= ALC275_FIXUP_SONY_VAIO_GPIO2
4568 [ALC271_FIXUP_DMIC
] = {
4569 .type
= ALC_FIXUP_FUNC
,
4570 .v
.func
= alc271_fixup_dmic
,
4572 [ALC269_FIXUP_PCM_44K
] = {
4573 .type
= ALC_FIXUP_FUNC
,
4574 .v
.func
= alc269_fixup_pcm_44k
,
4576 [ALC269_FIXUP_STEREO_DMIC
] = {
4577 .type
= ALC_FIXUP_FUNC
,
4578 .v
.func
= alc269_fixup_stereo_dmic
,
4582 static const struct snd_pci_quirk alc269_fixup_tbl
[] = {
4583 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW
),
4584 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC
),
4585 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC
),
4586 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC
),
4587 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC
),
4588 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC
),
4589 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2
),
4590 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ
),
4591 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ
),
4592 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO
),
4593 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z
),
4594 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC
),
4595 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE
),
4596 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE
),
4597 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE
),
4598 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE
),
4599 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE
),
4600 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K
),
4601 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD
),
4606 static int alc269_fill_coef(struct hda_codec
*codec
)
4610 if ((alc_read_coef_idx(codec
, 0) & 0x00ff) < 0x015) {
4611 alc_write_coef_idx(codec
, 0xf, 0x960b);
4612 alc_write_coef_idx(codec
, 0xe, 0x8817);
4615 if ((alc_read_coef_idx(codec
, 0) & 0x00ff) == 0x016) {
4616 alc_write_coef_idx(codec
, 0xf, 0x960b);
4617 alc_write_coef_idx(codec
, 0xe, 0x8814);
4620 if ((alc_read_coef_idx(codec
, 0) & 0x00ff) == 0x017) {
4621 val
= alc_read_coef_idx(codec
, 0x04);
4622 /* Power up output pin */
4623 alc_write_coef_idx(codec
, 0x04, val
| (1<<11));
4626 if ((alc_read_coef_idx(codec
, 0) & 0x00ff) == 0x018) {
4627 val
= alc_read_coef_idx(codec
, 0xd);
4628 if ((val
& 0x0c00) >> 10 != 0x1) {
4629 /* Capless ramp up clock control */
4630 alc_write_coef_idx(codec
, 0xd, val
| (1<<10));
4632 val
= alc_read_coef_idx(codec
, 0x17);
4633 if ((val
& 0x01c0) >> 6 != 0x4) {
4634 /* Class D power on reset */
4635 alc_write_coef_idx(codec
, 0x17, val
| (1<<7));
4639 val
= alc_read_coef_idx(codec
, 0xd); /* Class D */
4640 alc_write_coef_idx(codec
, 0xd, val
| (1<<14));
4642 val
= alc_read_coef_idx(codec
, 0x4); /* HP */
4643 alc_write_coef_idx(codec
, 0x4, val
| (1<<11));
4650 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4651 #include "alc269_quirks.c"
4654 static int patch_alc269(struct hda_codec
*codec
)
4656 struct alc_spec
*spec
;
4657 int board_config
, coef
;
4660 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
4666 spec
->mixer_nid
= 0x0b;
4668 alc_auto_parse_customize_define(codec
);
4670 if (codec
->vendor_id
== 0x10ec0269) {
4671 spec
->codec_variant
= ALC269_TYPE_ALC269VA
;
4672 coef
= alc_read_coef_idx(codec
, 0);
4673 if ((coef
& 0x00f0) == 0x0010) {
4674 if (codec
->bus
->pci
->subsystem_vendor
== 0x1025 &&
4675 spec
->cdefine
.platform_type
== 1) {
4676 alc_codec_rename(codec
, "ALC271X");
4677 } else if ((coef
& 0xf000) == 0x2000) {
4678 alc_codec_rename(codec
, "ALC259");
4679 } else if ((coef
& 0xf000) == 0x3000) {
4680 alc_codec_rename(codec
, "ALC258");
4681 } else if ((coef
& 0xfff0) == 0x3010) {
4682 alc_codec_rename(codec
, "ALC277");
4684 alc_codec_rename(codec
, "ALC269VB");
4686 spec
->codec_variant
= ALC269_TYPE_ALC269VB
;
4687 } else if ((coef
& 0x00f0) == 0x0020) {
4689 alc_codec_rename(codec
, "ALC259");
4690 else if (coef
== 0x6023)
4691 alc_codec_rename(codec
, "ALC281X");
4692 else if (codec
->bus
->pci
->subsystem_vendor
== 0x17aa &&
4693 codec
->bus
->pci
->subsystem_device
== 0x21f3)
4694 alc_codec_rename(codec
, "ALC3202");
4696 alc_codec_rename(codec
, "ALC269VC");
4697 spec
->codec_variant
= ALC269_TYPE_ALC269VC
;
4699 alc_fix_pll_init(codec
, 0x20, 0x04, 15);
4700 alc269_fill_coef(codec
);
4703 board_config
= alc_board_config(codec
, ALC269_MODEL_LAST
,
4704 alc269_models
, alc269_cfg_tbl
);
4706 if (board_config
< 0) {
4707 printk(KERN_INFO
"hda_codec: %s: BIOS auto-probing.\n",
4709 board_config
= ALC_MODEL_AUTO
;
4712 if (board_config
== ALC_MODEL_AUTO
) {
4713 alc_pick_fixup(codec
, NULL
, alc269_fixup_tbl
, alc269_fixups
);
4714 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
4717 if (board_config
== ALC_MODEL_AUTO
) {
4718 /* automatic parse from the BIOS config */
4719 err
= alc269_parse_auto_config(codec
);
4724 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4727 "hda_codec: Cannot set up configuration "
4728 "from BIOS. Using base mode...\n");
4729 board_config
= ALC269_BASIC
;
4734 if (board_config
!= ALC_MODEL_AUTO
)
4735 setup_preset(codec
, &alc269_presets
[board_config
]);
4737 if (!spec
->no_analog
&& !spec
->adc_nids
) {
4738 alc_auto_fill_adc_caps(codec
);
4739 alc_rebuild_imux_for_auto_mic(codec
);
4740 alc_remove_invalid_adc_nids(codec
);
4743 if (!spec
->no_analog
&& !spec
->cap_mixer
)
4744 set_capture_mixer(codec
);
4746 if (!spec
->no_analog
&& has_cdefine_beep(codec
)) {
4747 err
= snd_hda_attach_beep_device(codec
, 0x1);
4752 set_beep_amp(spec
, 0x0b, 0x04, HDA_INPUT
);
4755 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
4757 spec
->vmaster_nid
= 0x02;
4759 codec
->patch_ops
= alc_patch_ops
;
4761 codec
->patch_ops
.resume
= alc269_resume
;
4763 if (board_config
== ALC_MODEL_AUTO
)
4764 spec
->init_hook
= alc_auto_init_std
;
4765 spec
->shutup
= alc269_shutup
;
4767 alc_init_jacks(codec
);
4768 #ifdef CONFIG_SND_HDA_POWER_SAVE
4769 if (!spec
->loopback
.amplist
)
4770 spec
->loopback
.amplist
= alc269_loopbacks
;
4771 if (alc269_mic2_for_mute_led(codec
))
4772 codec
->patch_ops
.check_power_status
= alc269_mic2_mute_check_ps
;
4782 static int alc861_parse_auto_config(struct hda_codec
*codec
)
4784 static const hda_nid_t alc861_ignore
[] = { 0x1d, 0 };
4785 static const hda_nid_t alc861_ssids
[] = { 0x0e, 0x0f, 0x0b, 0 };
4786 return alc_parse_auto_config(codec
, alc861_ignore
, alc861_ssids
);
4789 #ifdef CONFIG_SND_HDA_POWER_SAVE
4790 static const struct hda_amp_list alc861_loopbacks
[] = {
4791 { 0x15, HDA_INPUT
, 0 },
4792 { 0x15, HDA_INPUT
, 1 },
4793 { 0x15, HDA_INPUT
, 2 },
4794 { 0x15, HDA_INPUT
, 3 },
4800 /* Pin config fixes */
4802 PINFIX_FSC_AMILO_PI1505
,
4805 static const struct alc_fixup alc861_fixups
[] = {
4806 [PINFIX_FSC_AMILO_PI1505
] = {
4807 .type
= ALC_FIXUP_PINS
,
4808 .v
.pins
= (const struct alc_pincfg
[]) {
4809 { 0x0b, 0x0221101f }, /* HP */
4810 { 0x0f, 0x90170310 }, /* speaker */
4816 static const struct snd_pci_quirk alc861_fixup_tbl
[] = {
4817 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", PINFIX_FSC_AMILO_PI1505
),
4823 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4824 #include "alc861_quirks.c"
4827 static int patch_alc861(struct hda_codec
*codec
)
4829 struct alc_spec
*spec
;
4833 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
4839 spec
->mixer_nid
= 0x15;
4841 board_config
= alc_board_config(codec
, ALC861_MODEL_LAST
,
4842 alc861_models
, alc861_cfg_tbl
);
4844 if (board_config
< 0) {
4845 printk(KERN_INFO
"hda_codec: %s: BIOS auto-probing.\n",
4847 board_config
= ALC_MODEL_AUTO
;
4850 if (board_config
== ALC_MODEL_AUTO
) {
4851 alc_pick_fixup(codec
, NULL
, alc861_fixup_tbl
, alc861_fixups
);
4852 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
4855 if (board_config
== ALC_MODEL_AUTO
) {
4856 /* automatic parse from the BIOS config */
4857 err
= alc861_parse_auto_config(codec
);
4862 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4865 "hda_codec: Cannot set up configuration "
4866 "from BIOS. Using base mode...\n");
4867 board_config
= ALC861_3ST_DIG
;
4872 if (board_config
!= ALC_MODEL_AUTO
)
4873 setup_preset(codec
, &alc861_presets
[board_config
]);
4875 if (!spec
->no_analog
&& !spec
->adc_nids
) {
4876 alc_auto_fill_adc_caps(codec
);
4877 alc_rebuild_imux_for_auto_mic(codec
);
4878 alc_remove_invalid_adc_nids(codec
);
4881 if (!spec
->no_analog
&& !spec
->cap_mixer
)
4882 set_capture_mixer(codec
);
4884 if (!spec
->no_analog
) {
4885 err
= snd_hda_attach_beep_device(codec
, 0x23);
4890 set_beep_amp(spec
, 0x23, 0, HDA_OUTPUT
);
4893 spec
->vmaster_nid
= 0x03;
4895 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
4897 codec
->patch_ops
= alc_patch_ops
;
4898 if (board_config
== ALC_MODEL_AUTO
) {
4899 spec
->init_hook
= alc_auto_init_std
;
4900 #ifdef CONFIG_SND_HDA_POWER_SAVE
4901 spec
->power_hook
= alc_power_eapd
;
4904 #ifdef CONFIG_SND_HDA_POWER_SAVE
4905 if (!spec
->loopback
.amplist
)
4906 spec
->loopback
.amplist
= alc861_loopbacks
;
4917 * In addition, an independent DAC
4919 #ifdef CONFIG_SND_HDA_POWER_SAVE
4920 #define alc861vd_loopbacks alc880_loopbacks
4923 static int alc861vd_parse_auto_config(struct hda_codec
*codec
)
4925 static const hda_nid_t alc861vd_ignore
[] = { 0x1d, 0 };
4926 static const hda_nid_t alc861vd_ssids
[] = { 0x15, 0x1b, 0x14, 0 };
4927 return alc_parse_auto_config(codec
, alc861vd_ignore
, alc861vd_ssids
);
4931 ALC660VD_FIX_ASUS_GPIO1
4935 static const struct alc_fixup alc861vd_fixups
[] = {
4936 [ALC660VD_FIX_ASUS_GPIO1
] = {
4937 .type
= ALC_FIXUP_VERBS
,
4938 .v
.verbs
= (const struct hda_verb
[]) {
4939 {0x01, AC_VERB_SET_GPIO_MASK
, 0x03},
4940 {0x01, AC_VERB_SET_GPIO_DIRECTION
, 0x01},
4941 {0x01, AC_VERB_SET_GPIO_DATA
, 0x01},
4947 static const struct snd_pci_quirk alc861vd_fixup_tbl
[] = {
4948 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1
),
4952 static const struct hda_verb alc660vd_eapd_verbs
[] = {
4953 {0x14, AC_VERB_SET_EAPD_BTLENABLE
, 2},
4954 {0x15, AC_VERB_SET_EAPD_BTLENABLE
, 2},
4960 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4961 #include "alc861vd_quirks.c"
4964 static int patch_alc861vd(struct hda_codec
*codec
)
4966 struct alc_spec
*spec
;
4967 int err
, board_config
;
4969 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
4975 spec
->mixer_nid
= 0x0b;
4977 board_config
= alc_board_config(codec
, ALC861VD_MODEL_LAST
,
4978 alc861vd_models
, alc861vd_cfg_tbl
);
4980 if (board_config
< 0) {
4981 printk(KERN_INFO
"hda_codec: %s: BIOS auto-probing.\n",
4983 board_config
= ALC_MODEL_AUTO
;
4986 if (board_config
== ALC_MODEL_AUTO
) {
4987 alc_pick_fixup(codec
, NULL
, alc861vd_fixup_tbl
, alc861vd_fixups
);
4988 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
4991 if (board_config
== ALC_MODEL_AUTO
) {
4992 /* automatic parse from the BIOS config */
4993 err
= alc861vd_parse_auto_config(codec
);
4998 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
5001 "hda_codec: Cannot set up configuration "
5002 "from BIOS. Using base mode...\n");
5003 board_config
= ALC861VD_3ST
;
5008 if (board_config
!= ALC_MODEL_AUTO
)
5009 setup_preset(codec
, &alc861vd_presets
[board_config
]);
5011 if (codec
->vendor_id
== 0x10ec0660) {
5012 /* always turn on EAPD */
5013 add_verb(spec
, alc660vd_eapd_verbs
);
5016 if (!spec
->no_analog
&& !spec
->adc_nids
) {
5017 alc_auto_fill_adc_caps(codec
);
5018 alc_rebuild_imux_for_auto_mic(codec
);
5019 alc_remove_invalid_adc_nids(codec
);
5022 if (!spec
->no_analog
&& !spec
->cap_mixer
)
5023 set_capture_mixer(codec
);
5025 if (!spec
->no_analog
) {
5026 err
= snd_hda_attach_beep_device(codec
, 0x23);
5031 set_beep_amp(spec
, 0x0b, 0x05, HDA_INPUT
);
5034 spec
->vmaster_nid
= 0x02;
5036 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
5038 codec
->patch_ops
= alc_patch_ops
;
5040 if (board_config
== ALC_MODEL_AUTO
)
5041 spec
->init_hook
= alc_auto_init_std
;
5042 spec
->shutup
= alc_eapd_shutup
;
5043 #ifdef CONFIG_SND_HDA_POWER_SAVE
5044 if (!spec
->loopback
.amplist
)
5045 spec
->loopback
.amplist
= alc861vd_loopbacks
;
5054 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
5055 * configuration. Each pin widget can choose any input DACs and a mixer.
5056 * Each ADC is connected from a mixer of all inputs. This makes possible
5057 * 6-channel independent captures.
5059 * In addition, an independent DAC for the multi-playback (not used in this
5062 #ifdef CONFIG_SND_HDA_POWER_SAVE
5063 #define alc662_loopbacks alc880_loopbacks
5067 * BIOS auto configuration
5070 static int alc662_parse_auto_config(struct hda_codec
*codec
)
5072 static const hda_nid_t alc662_ignore
[] = { 0x1d, 0 };
5073 static const hda_nid_t alc663_ssids
[] = { 0x15, 0x1b, 0x14, 0x21 };
5074 static const hda_nid_t alc662_ssids
[] = { 0x15, 0x1b, 0x14, 0 };
5075 const hda_nid_t
*ssids
;
5077 if (codec
->vendor_id
== 0x10ec0272 || codec
->vendor_id
== 0x10ec0663 ||
5078 codec
->vendor_id
== 0x10ec0665 || codec
->vendor_id
== 0x10ec0670)
5079 ssids
= alc663_ssids
;
5081 ssids
= alc662_ssids
;
5082 return alc_parse_auto_config(codec
, alc662_ignore
, ssids
);
5085 static void alc272_fixup_mario(struct hda_codec
*codec
,
5086 const struct alc_fixup
*fix
, int action
)
5088 if (action
!= ALC_FIXUP_ACT_PROBE
)
5090 if (snd_hda_override_amp_caps(codec
, 0x2, HDA_OUTPUT
,
5091 (0x3b << AC_AMPCAP_OFFSET_SHIFT
) |
5092 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT
) |
5093 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT
) |
5094 (0 << AC_AMPCAP_MUTE_SHIFT
)))
5096 "hda_codec: failed to override amp caps for NID 0x2\n");
5100 ALC662_FIXUP_ASPIRE
,
5101 ALC662_FIXUP_IDEAPAD
,
5103 ALC662_FIXUP_CZC_P10T
,
5104 ALC662_FIXUP_SKU_IGNORE
,
5105 ALC662_FIXUP_HP_RP5800
,
5108 static const struct alc_fixup alc662_fixups
[] = {
5109 [ALC662_FIXUP_ASPIRE
] = {
5110 .type
= ALC_FIXUP_PINS
,
5111 .v
.pins
= (const struct alc_pincfg
[]) {
5112 { 0x15, 0x99130112 }, /* subwoofer */
5116 [ALC662_FIXUP_IDEAPAD
] = {
5117 .type
= ALC_FIXUP_PINS
,
5118 .v
.pins
= (const struct alc_pincfg
[]) {
5119 { 0x17, 0x99130112 }, /* subwoofer */
5123 [ALC272_FIXUP_MARIO
] = {
5124 .type
= ALC_FIXUP_FUNC
,
5125 .v
.func
= alc272_fixup_mario
,
5127 [ALC662_FIXUP_CZC_P10T
] = {
5128 .type
= ALC_FIXUP_VERBS
,
5129 .v
.verbs
= (const struct hda_verb
[]) {
5130 {0x14, AC_VERB_SET_EAPD_BTLENABLE
, 0},
5134 [ALC662_FIXUP_SKU_IGNORE
] = {
5135 .type
= ALC_FIXUP_SKU
,
5136 .v
.sku
= ALC_FIXUP_SKU_IGNORE
,
5138 [ALC662_FIXUP_HP_RP5800
] = {
5139 .type
= ALC_FIXUP_PINS
,
5140 .v
.pins
= (const struct alc_pincfg
[]) {
5141 { 0x14, 0x0221201f }, /* HP out */
5145 .chain_id
= ALC662_FIXUP_SKU_IGNORE
5149 static const struct snd_pci_quirk alc662_fixup_tbl
[] = {
5150 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE
),
5151 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE
),
5152 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE
),
5153 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800
),
5154 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD
),
5155 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD
),
5156 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD
),
5157 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T
),
5161 static const struct alc_model_fixup alc662_fixup_models
[] = {
5162 {.id
= ALC272_FIXUP_MARIO
, .name
= "mario"},
5169 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
5170 #include "alc662_quirks.c"
5173 static int patch_alc662(struct hda_codec
*codec
)
5175 struct alc_spec
*spec
;
5176 int err
, board_config
;
5179 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
5185 spec
->mixer_nid
= 0x0b;
5187 alc_auto_parse_customize_define(codec
);
5189 alc_fix_pll_init(codec
, 0x20, 0x04, 15);
5191 coef
= alc_read_coef_idx(codec
, 0);
5192 if (coef
== 0x8020 || coef
== 0x8011)
5193 alc_codec_rename(codec
, "ALC661");
5194 else if (coef
& (1 << 14) &&
5195 codec
->bus
->pci
->subsystem_vendor
== 0x1025 &&
5196 spec
->cdefine
.platform_type
== 1)
5197 alc_codec_rename(codec
, "ALC272X");
5198 else if (coef
== 0x4011)
5199 alc_codec_rename(codec
, "ALC656");
5201 board_config
= alc_board_config(codec
, ALC662_MODEL_LAST
,
5202 alc662_models
, alc662_cfg_tbl
);
5203 if (board_config
< 0) {
5204 printk(KERN_INFO
"hda_codec: %s: BIOS auto-probing.\n",
5206 board_config
= ALC_MODEL_AUTO
;
5209 if (board_config
== ALC_MODEL_AUTO
) {
5210 alc_pick_fixup(codec
, alc662_fixup_models
,
5211 alc662_fixup_tbl
, alc662_fixups
);
5212 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
5213 /* automatic parse from the BIOS config */
5214 err
= alc662_parse_auto_config(codec
);
5219 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
5222 "hda_codec: Cannot set up configuration "
5223 "from BIOS. Using base mode...\n");
5224 board_config
= ALC662_3ST_2ch_DIG
;
5229 if (board_config
!= ALC_MODEL_AUTO
)
5230 setup_preset(codec
, &alc662_presets
[board_config
]);
5232 if (!spec
->no_analog
&& !spec
->adc_nids
) {
5233 alc_auto_fill_adc_caps(codec
);
5234 alc_rebuild_imux_for_auto_mic(codec
);
5235 alc_remove_invalid_adc_nids(codec
);
5238 if (!spec
->no_analog
&& !spec
->cap_mixer
)
5239 set_capture_mixer(codec
);
5241 if (!spec
->no_analog
&& has_cdefine_beep(codec
)) {
5242 err
= snd_hda_attach_beep_device(codec
, 0x1);
5247 switch (codec
->vendor_id
) {
5249 set_beep_amp(spec
, 0x0b, 0x05, HDA_INPUT
);
5254 set_beep_amp(spec
, 0x0b, 0x04, HDA_INPUT
);
5257 set_beep_amp(spec
, 0x0b, 0x03, HDA_INPUT
);
5261 spec
->vmaster_nid
= 0x02;
5263 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
5265 codec
->patch_ops
= alc_patch_ops
;
5266 if (board_config
== ALC_MODEL_AUTO
)
5267 spec
->init_hook
= alc_auto_init_std
;
5268 spec
->shutup
= alc_eapd_shutup
;
5270 alc_init_jacks(codec
);
5272 #ifdef CONFIG_SND_HDA_POWER_SAVE
5273 if (!spec
->loopback
.amplist
)
5274 spec
->loopback
.amplist
= alc662_loopbacks
;
5280 static int patch_alc888(struct hda_codec
*codec
)
5282 if ((alc_read_coef_idx(codec
, 0) & 0x00f0)==0x0030){
5283 kfree(codec
->chip_name
);
5284 if (codec
->vendor_id
== 0x10ec0887)
5285 codec
->chip_name
= kstrdup("ALC887-VD", GFP_KERNEL
);
5287 codec
->chip_name
= kstrdup("ALC888-VD", GFP_KERNEL
);
5288 if (!codec
->chip_name
) {
5292 return patch_alc662(codec
);
5294 return patch_alc882(codec
);
5297 static int patch_alc899(struct hda_codec
*codec
)
5299 if ((alc_read_coef_idx(codec
, 0) & 0x2000) != 0x2000) {
5300 kfree(codec
->chip_name
);
5301 codec
->chip_name
= kstrdup("ALC898", GFP_KERNEL
);
5303 return patch_alc882(codec
);
5310 static int alc680_parse_auto_config(struct hda_codec
*codec
)
5312 return alc_parse_auto_config(codec
, NULL
, NULL
);
5317 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
5318 #include "alc680_quirks.c"
5321 static int patch_alc680(struct hda_codec
*codec
)
5323 struct alc_spec
*spec
;
5327 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
5333 /* ALC680 has no aa-loopback mixer */
5335 board_config
= alc_board_config(codec
, ALC680_MODEL_LAST
,
5336 alc680_models
, alc680_cfg_tbl
);
5338 if (board_config
< 0) {
5339 printk(KERN_INFO
"hda_codec: %s: BIOS auto-probing.\n",
5341 board_config
= ALC_MODEL_AUTO
;
5344 if (board_config
== ALC_MODEL_AUTO
) {
5345 /* automatic parse from the BIOS config */
5346 err
= alc680_parse_auto_config(codec
);
5351 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
5354 "hda_codec: Cannot set up configuration "
5355 "from BIOS. Using base mode...\n");
5356 board_config
= ALC680_BASE
;
5361 if (board_config
!= ALC_MODEL_AUTO
) {
5362 setup_preset(codec
, &alc680_presets
[board_config
]);
5363 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
5364 spec
->stream_analog_capture
= &alc680_pcm_analog_auto_capture
;
5368 if (!spec
->no_analog
&& !spec
->adc_nids
) {
5369 alc_auto_fill_adc_caps(codec
);
5370 alc_rebuild_imux_for_auto_mic(codec
);
5371 alc_remove_invalid_adc_nids(codec
);
5374 if (!spec
->no_analog
&& !spec
->cap_mixer
)
5375 set_capture_mixer(codec
);
5377 spec
->vmaster_nid
= 0x02;
5379 codec
->patch_ops
= alc_patch_ops
;
5380 if (board_config
== ALC_MODEL_AUTO
)
5381 spec
->init_hook
= alc_auto_init_std
;
5389 static const struct hda_codec_preset snd_hda_preset_realtek
[] = {
5390 { .id
= 0x10ec0221, .name
= "ALC221", .patch
= patch_alc269
},
5391 { .id
= 0x10ec0260, .name
= "ALC260", .patch
= patch_alc260
},
5392 { .id
= 0x10ec0262, .name
= "ALC262", .patch
= patch_alc262
},
5393 { .id
= 0x10ec0267, .name
= "ALC267", .patch
= patch_alc268
},
5394 { .id
= 0x10ec0268, .name
= "ALC268", .patch
= patch_alc268
},
5395 { .id
= 0x10ec0269, .name
= "ALC269", .patch
= patch_alc269
},
5396 { .id
= 0x10ec0270, .name
= "ALC270", .patch
= patch_alc269
},
5397 { .id
= 0x10ec0272, .name
= "ALC272", .patch
= patch_alc662
},
5398 { .id
= 0x10ec0275, .name
= "ALC275", .patch
= patch_alc269
},
5399 { .id
= 0x10ec0276, .name
= "ALC276", .patch
= patch_alc269
},
5400 { .id
= 0x10ec0861, .rev
= 0x100340, .name
= "ALC660",
5401 .patch
= patch_alc861
},
5402 { .id
= 0x10ec0660, .name
= "ALC660-VD", .patch
= patch_alc861vd
},
5403 { .id
= 0x10ec0861, .name
= "ALC861", .patch
= patch_alc861
},
5404 { .id
= 0x10ec0862, .name
= "ALC861-VD", .patch
= patch_alc861vd
},
5405 { .id
= 0x10ec0662, .rev
= 0x100002, .name
= "ALC662 rev2",
5406 .patch
= patch_alc882
},
5407 { .id
= 0x10ec0662, .rev
= 0x100101, .name
= "ALC662 rev1",
5408 .patch
= patch_alc662
},
5409 { .id
= 0x10ec0663, .name
= "ALC663", .patch
= patch_alc662
},
5410 { .id
= 0x10ec0665, .name
= "ALC665", .patch
= patch_alc662
},
5411 { .id
= 0x10ec0670, .name
= "ALC670", .patch
= patch_alc662
},
5412 { .id
= 0x10ec0680, .name
= "ALC680", .patch
= patch_alc680
},
5413 { .id
= 0x10ec0880, .name
= "ALC880", .patch
= patch_alc880
},
5414 { .id
= 0x10ec0882, .name
= "ALC882", .patch
= patch_alc882
},
5415 { .id
= 0x10ec0883, .name
= "ALC883", .patch
= patch_alc882
},
5416 { .id
= 0x10ec0885, .rev
= 0x100101, .name
= "ALC889A",
5417 .patch
= patch_alc882
},
5418 { .id
= 0x10ec0885, .rev
= 0x100103, .name
= "ALC889A",
5419 .patch
= patch_alc882
},
5420 { .id
= 0x10ec0885, .name
= "ALC885", .patch
= patch_alc882
},
5421 { .id
= 0x10ec0887, .name
= "ALC887", .patch
= patch_alc888
},
5422 { .id
= 0x10ec0888, .rev
= 0x100101, .name
= "ALC1200",
5423 .patch
= patch_alc882
},
5424 { .id
= 0x10ec0888, .name
= "ALC888", .patch
= patch_alc888
},
5425 { .id
= 0x10ec0889, .name
= "ALC889", .patch
= patch_alc882
},
5426 { .id
= 0x10ec0892, .name
= "ALC892", .patch
= patch_alc662
},
5427 { .id
= 0x10ec0899, .name
= "ALC899", .patch
= patch_alc899
},
5431 MODULE_ALIAS("snd-hda-codec-id:10ec*");
5433 MODULE_LICENSE("GPL");
5434 MODULE_DESCRIPTION("Realtek HD-audio codec");
5436 static struct hda_codec_preset_list realtek_list
= {
5437 .preset
= snd_hda_preset_realtek
,
5438 .owner
= THIS_MODULE
,
5441 static int __init
patch_realtek_init(void)
5443 return snd_hda_add_codec_preset(&realtek_list
);
5446 static void __exit
patch_realtek_exit(void)
5448 snd_hda_delete_codec_preset(&realtek_list
);
5451 module_init(patch_realtek_init
)
5452 module_exit(patch_realtek_exit
)