2 * Universal Interface for Intel High Definition Audio Codec
4 * HD audio interface patch for Realtek ALC codecs
6 * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
7 * PeiSen Hou <pshou@realtek.com.tw>
8 * Takashi Iwai <tiwai@suse.de>
9 * Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
11 * This driver is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This driver is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include <linux/init.h>
27 #include <linux/delay.h>
28 #include <linux/slab.h>
29 #include <linux/pci.h>
30 #include <sound/core.h>
31 #include <sound/jack.h>
32 #include "hda_codec.h"
33 #include "hda_local.h"
36 /* unsol event tags */
37 #define ALC_FRONT_EVENT 0x01
38 #define ALC_DCVOL_EVENT 0x02
39 #define ALC_HP_EVENT 0x04
40 #define ALC_MIC_EVENT 0x08
43 #define GPIO_MASK 0x03
45 /* extra amp-initialization sequence types */
54 struct alc_customize_define
{
56 unsigned char port_connectivity
;
57 unsigned char check_sum
;
58 unsigned char customization
;
59 unsigned char external_amp
;
60 unsigned int enable_pcbeep
:1;
61 unsigned int platform_type
:1;
63 unsigned int override
:1;
64 unsigned int fixup
:1; /* Means that this sku is set by driver, not read from hw */
70 hda_nid_t pin
; /* multi-io widget pin NID */
71 hda_nid_t dac
; /* DAC to be connected */
72 unsigned int ctl_in
; /* cached input-pin control value */
76 ALC_AUTOMUTE_PIN
, /* change the pin control */
77 ALC_AUTOMUTE_AMP
, /* mute/unmute the pin AMP */
78 ALC_AUTOMUTE_MIXER
, /* mute/unmute mixer widget AMP */
82 /* codec parameterization */
83 const struct snd_kcontrol_new
*mixers
[5]; /* mixer arrays */
84 unsigned int num_mixers
;
85 const struct snd_kcontrol_new
*cap_mixer
; /* capture mixer */
86 unsigned int beep_amp
; /* beep amp value, set via set_beep_amp() */
88 const struct hda_verb
*init_verbs
[10]; /* initialization verbs
92 unsigned int num_init_verbs
;
94 char stream_name_analog
[32]; /* analog PCM stream */
95 const struct hda_pcm_stream
*stream_analog_playback
;
96 const struct hda_pcm_stream
*stream_analog_capture
;
97 const struct hda_pcm_stream
*stream_analog_alt_playback
;
98 const struct hda_pcm_stream
*stream_analog_alt_capture
;
100 char stream_name_digital
[32]; /* digital PCM stream */
101 const struct hda_pcm_stream
*stream_digital_playback
;
102 const struct hda_pcm_stream
*stream_digital_capture
;
105 struct hda_multi_out multiout
; /* playback set-up
106 * max_channels, dacs must be set
107 * dig_out_nid and hp_nid are optional
109 hda_nid_t alt_dac_nid
;
110 hda_nid_t slave_dig_outs
[3]; /* optional - for auto-parsing */
114 unsigned int num_adc_nids
;
115 const hda_nid_t
*adc_nids
;
116 const hda_nid_t
*capsrc_nids
;
117 hda_nid_t dig_in_nid
; /* digital-in NID; optional */
118 hda_nid_t mixer_nid
; /* analog-mixer NID */
120 /* capture setup for dynamic dual-adc switch */
122 unsigned int cur_adc_stream_tag
;
123 unsigned int cur_adc_format
;
126 unsigned int num_mux_defs
;
127 const struct hda_input_mux
*input_mux
;
128 unsigned int cur_mux
[3];
129 hda_nid_t ext_mic_pin
;
130 hda_nid_t dock_mic_pin
;
131 hda_nid_t int_mic_pin
;
134 const struct hda_channel_mode
*channel_mode
;
135 int num_channel_mode
;
137 int const_channel_count
;
138 int ext_channel_count
;
140 /* PCM information */
141 struct hda_pcm pcm_rec
[3]; /* used in alc_build_pcms() */
143 /* dynamic controls, init_verbs and input_mux */
144 struct auto_pin_cfg autocfg
;
145 struct alc_customize_define cdefine
;
146 struct snd_array kctls
;
147 struct hda_input_mux private_imux
[3];
148 hda_nid_t private_dac_nids
[AUTO_CFG_MAX_OUTS
];
149 hda_nid_t private_adc_nids
[AUTO_CFG_MAX_OUTS
];
150 hda_nid_t private_capsrc_nids
[AUTO_CFG_MAX_OUTS
];
151 hda_nid_t imux_pins
[HDA_MAX_NUM_INPUTS
];
152 unsigned int dyn_adc_idx
[HDA_MAX_NUM_INPUTS
];
153 int int_mic_idx
, ext_mic_idx
, dock_mic_idx
; /* for auto-mic */
156 void (*init_hook
)(struct hda_codec
*codec
);
157 void (*unsol_event
)(struct hda_codec
*codec
, unsigned int res
);
158 #ifdef CONFIG_SND_HDA_POWER_SAVE
159 void (*power_hook
)(struct hda_codec
*codec
);
161 void (*shutup
)(struct hda_codec
*codec
);
163 /* for pin sensing */
164 unsigned int jack_present
: 1;
165 unsigned int line_jack_present
:1;
166 unsigned int master_mute
:1;
167 unsigned int auto_mic
:1;
168 unsigned int auto_mic_valid_imux
:1; /* valid imux for auto-mic */
169 unsigned int automute
:1; /* HP automute enabled */
170 unsigned int detect_line
:1; /* Line-out detection enabled */
171 unsigned int automute_lines
:1; /* automute line-out as well; NOP when automute_hp_lo isn't set */
172 unsigned int automute_hp_lo
:1; /* both HP and LO available */
175 unsigned int no_analog
:1; /* digital I/O only */
176 unsigned int dyn_adc_switch
:1; /* switch ADCs (for ALC275) */
177 unsigned int single_input_src
:1;
178 unsigned int vol_in_capsrc
:1; /* use capsrc volume (ADC has no vol) */
180 /* auto-mute control */
182 hda_nid_t automute_mixer_nid
[AUTO_CFG_MAX_OUTS
];
185 int codec_variant
; /* flag for other variants */
187 /* for virtual master */
188 hda_nid_t vmaster_nid
;
189 #ifdef CONFIG_SND_HDA_POWER_SAVE
190 struct hda_loopback_check loopback
;
195 unsigned int pll_coef_idx
, pll_coef_bit
;
199 const struct alc_fixup
*fixup_list
;
200 const char *fixup_name
;
204 struct alc_multi_io multi_io
[4];
207 #define ALC_MODEL_AUTO 0 /* common for all chips */
209 static bool check_amp_caps(struct hda_codec
*codec
, hda_nid_t nid
,
210 int dir
, unsigned int bits
)
214 if (get_wcaps(codec
, nid
) & (1 << (dir
+ 1)))
215 if (query_amp_caps(codec
, nid
, dir
) & bits
)
220 #define nid_has_mute(codec, nid, dir) \
221 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
222 #define nid_has_volume(codec, nid, dir) \
223 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
228 static int alc_mux_enum_info(struct snd_kcontrol
*kcontrol
,
229 struct snd_ctl_elem_info
*uinfo
)
231 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
232 struct alc_spec
*spec
= codec
->spec
;
233 unsigned int mux_idx
= snd_ctl_get_ioffidx(kcontrol
, &uinfo
->id
);
234 if (mux_idx
>= spec
->num_mux_defs
)
236 if (!spec
->input_mux
[mux_idx
].num_items
&& mux_idx
> 0)
238 return snd_hda_input_mux_info(&spec
->input_mux
[mux_idx
], uinfo
);
241 static int alc_mux_enum_get(struct snd_kcontrol
*kcontrol
,
242 struct snd_ctl_elem_value
*ucontrol
)
244 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
245 struct alc_spec
*spec
= codec
->spec
;
246 unsigned int adc_idx
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
248 ucontrol
->value
.enumerated
.item
[0] = spec
->cur_mux
[adc_idx
];
252 static bool alc_dyn_adc_pcm_resetup(struct hda_codec
*codec
, int cur
)
254 struct alc_spec
*spec
= codec
->spec
;
255 hda_nid_t new_adc
= spec
->adc_nids
[spec
->dyn_adc_idx
[cur
]];
257 if (spec
->cur_adc
&& spec
->cur_adc
!= new_adc
) {
258 /* stream is running, let's swap the current ADC */
259 __snd_hda_codec_cleanup_stream(codec
, spec
->cur_adc
, 1);
260 spec
->cur_adc
= new_adc
;
261 snd_hda_codec_setup_stream(codec
, new_adc
,
262 spec
->cur_adc_stream_tag
, 0,
263 spec
->cur_adc_format
);
269 /* select the given imux item; either unmute exclusively or select the route */
270 static int alc_mux_select(struct hda_codec
*codec
, unsigned int adc_idx
,
271 unsigned int idx
, bool force
)
273 struct alc_spec
*spec
= codec
->spec
;
274 const struct hda_input_mux
*imux
;
275 unsigned int mux_idx
;
279 mux_idx
= adc_idx
>= spec
->num_mux_defs
? 0 : adc_idx
;
280 imux
= &spec
->input_mux
[mux_idx
];
281 if (!imux
->num_items
&& mux_idx
> 0)
282 imux
= &spec
->input_mux
[0];
284 if (idx
>= imux
->num_items
)
285 idx
= imux
->num_items
- 1;
286 if (spec
->cur_mux
[adc_idx
] == idx
&& !force
)
288 spec
->cur_mux
[adc_idx
] = idx
;
290 if (spec
->dyn_adc_switch
) {
291 alc_dyn_adc_pcm_resetup(codec
, idx
);
292 adc_idx
= spec
->dyn_adc_idx
[idx
];
295 nid
= spec
->capsrc_nids
?
296 spec
->capsrc_nids
[adc_idx
] : spec
->adc_nids
[adc_idx
];
299 if (snd_hda_get_conn_list(codec
, nid
, NULL
) <= 1)
302 type
= get_wcaps_type(get_wcaps(codec
, nid
));
303 if (type
== AC_WID_AUD_MIX
) {
304 /* Matrix-mixer style (e.g. ALC882) */
305 for (i
= 0; i
< imux
->num_items
; i
++) {
306 unsigned int v
= (i
== idx
) ? 0 : HDA_AMP_MUTE
;
307 snd_hda_codec_amp_stereo(codec
, nid
, HDA_INPUT
,
308 imux
->items
[i
].index
,
312 /* MUX style (e.g. ALC880) */
313 snd_hda_codec_write_cache(codec
, nid
, 0,
314 AC_VERB_SET_CONNECT_SEL
,
315 imux
->items
[idx
].index
);
320 static int alc_mux_enum_put(struct snd_kcontrol
*kcontrol
,
321 struct snd_ctl_elem_value
*ucontrol
)
323 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
324 unsigned int adc_idx
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
325 return alc_mux_select(codec
, adc_idx
,
326 ucontrol
->value
.enumerated
.item
[0], false);
330 * set up the input pin config (depending on the given auto-pin type)
332 static void alc_set_input_pin(struct hda_codec
*codec
, hda_nid_t nid
,
335 unsigned int val
= PIN_IN
;
337 if (auto_pin_type
== AUTO_PIN_MIC
) {
340 oldval
= snd_hda_codec_read(codec
, nid
, 0,
341 AC_VERB_GET_PIN_WIDGET_CONTROL
, 0);
342 pincap
= snd_hda_query_pin_caps(codec
, nid
);
343 pincap
= (pincap
& AC_PINCAP_VREF
) >> AC_PINCAP_VREF_SHIFT
;
344 /* if the default pin setup is vref50, we give it priority */
345 if ((pincap
& AC_PINCAP_VREF_80
) && oldval
!= PIN_VREF50
)
347 else if (pincap
& AC_PINCAP_VREF_50
)
349 else if (pincap
& AC_PINCAP_VREF_100
)
351 else if (pincap
& AC_PINCAP_VREF_GRD
)
354 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_PIN_WIDGET_CONTROL
, val
);
358 * Append the given mixer and verb elements for the later use
359 * The mixer array is referred in build_controls(), and init_verbs are
362 static void add_mixer(struct alc_spec
*spec
, const struct snd_kcontrol_new
*mix
)
364 if (snd_BUG_ON(spec
->num_mixers
>= ARRAY_SIZE(spec
->mixers
)))
366 spec
->mixers
[spec
->num_mixers
++] = mix
;
369 static void add_verb(struct alc_spec
*spec
, const struct hda_verb
*verb
)
371 if (snd_BUG_ON(spec
->num_init_verbs
>= ARRAY_SIZE(spec
->init_verbs
)))
373 spec
->init_verbs
[spec
->num_init_verbs
++] = verb
;
377 * GPIO setup tables, used in initialization
379 /* Enable GPIO mask and set output */
380 static const struct hda_verb alc_gpio1_init_verbs
[] = {
381 {0x01, AC_VERB_SET_GPIO_MASK
, 0x01},
382 {0x01, AC_VERB_SET_GPIO_DIRECTION
, 0x01},
383 {0x01, AC_VERB_SET_GPIO_DATA
, 0x01},
387 static const struct hda_verb alc_gpio2_init_verbs
[] = {
388 {0x01, AC_VERB_SET_GPIO_MASK
, 0x02},
389 {0x01, AC_VERB_SET_GPIO_DIRECTION
, 0x02},
390 {0x01, AC_VERB_SET_GPIO_DATA
, 0x02},
394 static const struct hda_verb alc_gpio3_init_verbs
[] = {
395 {0x01, AC_VERB_SET_GPIO_MASK
, 0x03},
396 {0x01, AC_VERB_SET_GPIO_DIRECTION
, 0x03},
397 {0x01, AC_VERB_SET_GPIO_DATA
, 0x03},
402 * Fix hardware PLL issue
403 * On some codecs, the analog PLL gating control must be off while
404 * the default value is 1.
406 static void alc_fix_pll(struct hda_codec
*codec
)
408 struct alc_spec
*spec
= codec
->spec
;
413 snd_hda_codec_write(codec
, spec
->pll_nid
, 0, AC_VERB_SET_COEF_INDEX
,
415 val
= snd_hda_codec_read(codec
, spec
->pll_nid
, 0,
416 AC_VERB_GET_PROC_COEF
, 0);
417 snd_hda_codec_write(codec
, spec
->pll_nid
, 0, AC_VERB_SET_COEF_INDEX
,
419 snd_hda_codec_write(codec
, spec
->pll_nid
, 0, AC_VERB_SET_PROC_COEF
,
420 val
& ~(1 << spec
->pll_coef_bit
));
423 static void alc_fix_pll_init(struct hda_codec
*codec
, hda_nid_t nid
,
424 unsigned int coef_idx
, unsigned int coef_bit
)
426 struct alc_spec
*spec
= codec
->spec
;
428 spec
->pll_coef_idx
= coef_idx
;
429 spec
->pll_coef_bit
= coef_bit
;
434 * Jack-reporting via input-jack layer
437 /* initialization of jacks; currently checks only a few known pins */
438 static int alc_init_jacks(struct hda_codec
*codec
)
440 #ifdef CONFIG_SND_HDA_INPUT_JACK
441 struct alc_spec
*spec
= codec
->spec
;
443 unsigned int hp_nid
= spec
->autocfg
.hp_pins
[0];
444 unsigned int mic_nid
= spec
->ext_mic_pin
;
445 unsigned int dock_nid
= spec
->dock_mic_pin
;
448 err
= snd_hda_input_jack_add(codec
, hp_nid
,
449 SND_JACK_HEADPHONE
, NULL
);
452 snd_hda_input_jack_report(codec
, hp_nid
);
456 err
= snd_hda_input_jack_add(codec
, mic_nid
,
457 SND_JACK_MICROPHONE
, NULL
);
460 snd_hda_input_jack_report(codec
, mic_nid
);
463 err
= snd_hda_input_jack_add(codec
, dock_nid
,
464 SND_JACK_MICROPHONE
, NULL
);
467 snd_hda_input_jack_report(codec
, dock_nid
);
469 #endif /* CONFIG_SND_HDA_INPUT_JACK */
474 * Jack detections for HP auto-mute and mic-switch
477 /* check each pin in the given array; returns true if any of them is plugged */
478 static bool detect_jacks(struct hda_codec
*codec
, int num_pins
, hda_nid_t
*pins
)
482 for (i
= 0; i
< num_pins
; i
++) {
483 hda_nid_t nid
= pins
[i
];
486 snd_hda_input_jack_report(codec
, nid
);
487 present
|= snd_hda_jack_detect(codec
, nid
);
492 /* standard HP/line-out auto-mute helper */
493 static void do_automute(struct hda_codec
*codec
, int num_pins
, hda_nid_t
*pins
,
494 bool mute
, bool hp_out
)
496 struct alc_spec
*spec
= codec
->spec
;
497 unsigned int mute_bits
= mute
? HDA_AMP_MUTE
: 0;
498 unsigned int pin_bits
= mute
? 0 : (hp_out
? PIN_HP
: PIN_OUT
);
501 for (i
= 0; i
< num_pins
; i
++) {
502 hda_nid_t nid
= pins
[i
];
505 switch (spec
->automute_mode
) {
506 case ALC_AUTOMUTE_PIN
:
507 snd_hda_codec_write(codec
, nid
, 0,
508 AC_VERB_SET_PIN_WIDGET_CONTROL
,
511 case ALC_AUTOMUTE_AMP
:
512 snd_hda_codec_amp_stereo(codec
, nid
, HDA_OUTPUT
, 0,
513 HDA_AMP_MUTE
, mute_bits
);
515 case ALC_AUTOMUTE_MIXER
:
516 nid
= spec
->automute_mixer_nid
[i
];
519 snd_hda_codec_amp_stereo(codec
, nid
, HDA_INPUT
, 0,
520 HDA_AMP_MUTE
, mute_bits
);
521 snd_hda_codec_amp_stereo(codec
, nid
, HDA_INPUT
, 1,
522 HDA_AMP_MUTE
, mute_bits
);
528 /* Toggle internal speakers muting */
529 static void update_speakers(struct hda_codec
*codec
)
531 struct alc_spec
*spec
= codec
->spec
;
534 /* Control HP pins/amps depending on master_mute state;
535 * in general, HP pins/amps control should be enabled in all cases,
536 * but currently set only for master_mute, just to be safe
538 do_automute(codec
, ARRAY_SIZE(spec
->autocfg
.hp_pins
),
539 spec
->autocfg
.hp_pins
, spec
->master_mute
, true);
544 on
= spec
->jack_present
| spec
->line_jack_present
;
545 on
|= spec
->master_mute
;
546 do_automute(codec
, ARRAY_SIZE(spec
->autocfg
.speaker_pins
),
547 spec
->autocfg
.speaker_pins
, on
, false);
549 /* toggle line-out mutes if needed, too */
550 /* if LO is a copy of either HP or Speaker, don't need to handle it */
551 if (spec
->autocfg
.line_out_pins
[0] == spec
->autocfg
.hp_pins
[0] ||
552 spec
->autocfg
.line_out_pins
[0] == spec
->autocfg
.speaker_pins
[0])
554 if (!spec
->automute
|| (spec
->automute_hp_lo
&& !spec
->automute_lines
))
557 on
= spec
->jack_present
;
558 on
|= spec
->master_mute
;
559 do_automute(codec
, ARRAY_SIZE(spec
->autocfg
.line_out_pins
),
560 spec
->autocfg
.line_out_pins
, on
, false);
563 /* standard HP-automute helper */
564 static void alc_hp_automute(struct hda_codec
*codec
)
566 struct alc_spec
*spec
= codec
->spec
;
569 detect_jacks(codec
, ARRAY_SIZE(spec
->autocfg
.hp_pins
),
570 spec
->autocfg
.hp_pins
);
573 update_speakers(codec
);
576 /* standard line-out-automute helper */
577 static void alc_line_automute(struct hda_codec
*codec
)
579 struct alc_spec
*spec
= codec
->spec
;
581 /* check LO jack only when it's different from HP */
582 if (spec
->autocfg
.line_out_pins
[0] == spec
->autocfg
.hp_pins
[0])
585 spec
->line_jack_present
=
586 detect_jacks(codec
, ARRAY_SIZE(spec
->autocfg
.line_out_pins
),
587 spec
->autocfg
.line_out_pins
);
588 if (!spec
->automute
|| !spec
->detect_line
)
590 update_speakers(codec
);
593 #define get_connection_index(codec, mux, nid) \
594 snd_hda_get_conn_index(codec, mux, nid, 0)
596 /* standard mic auto-switch helper */
597 static void alc_mic_automute(struct hda_codec
*codec
)
599 struct alc_spec
*spec
= codec
->spec
;
600 hda_nid_t
*pins
= spec
->imux_pins
;
602 if (!spec
->auto_mic
|| !spec
->auto_mic_valid_imux
)
604 if (snd_BUG_ON(!spec
->adc_nids
))
606 if (snd_BUG_ON(spec
->int_mic_idx
< 0 || spec
->ext_mic_idx
< 0))
609 if (snd_hda_jack_detect(codec
, pins
[spec
->ext_mic_idx
]))
610 alc_mux_select(codec
, 0, spec
->ext_mic_idx
, false);
611 else if (spec
->dock_mic_idx
>= 0 &&
612 snd_hda_jack_detect(codec
, pins
[spec
->dock_mic_idx
]))
613 alc_mux_select(codec
, 0, spec
->dock_mic_idx
, false);
615 alc_mux_select(codec
, 0, spec
->int_mic_idx
, false);
617 snd_hda_input_jack_report(codec
, pins
[spec
->ext_mic_idx
]);
618 if (spec
->dock_mic_idx
>= 0)
619 snd_hda_input_jack_report(codec
, pins
[spec
->dock_mic_idx
]);
622 /* unsolicited event for HP jack sensing */
623 static void alc_sku_unsol_event(struct hda_codec
*codec
, unsigned int res
)
625 if (codec
->vendor_id
== 0x10ec0880)
631 alc_hp_automute(codec
);
633 case ALC_FRONT_EVENT
:
634 alc_line_automute(codec
);
637 alc_mic_automute(codec
);
642 /* call init functions of standard auto-mute helpers */
643 static void alc_inithook(struct hda_codec
*codec
)
645 alc_hp_automute(codec
);
646 alc_line_automute(codec
);
647 alc_mic_automute(codec
);
650 /* additional initialization for ALC888 variants */
651 static void alc888_coef_init(struct hda_codec
*codec
)
655 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_COEF_INDEX
, 0);
656 tmp
= snd_hda_codec_read(codec
, 0x20, 0, AC_VERB_GET_PROC_COEF
, 0);
657 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_COEF_INDEX
, 7);
658 if ((tmp
& 0xf0) == 0x20)
660 snd_hda_codec_read(codec
, 0x20, 0,
661 AC_VERB_SET_PROC_COEF
, 0x830);
664 snd_hda_codec_read(codec
, 0x20, 0,
665 AC_VERB_SET_PROC_COEF
, 0x3030);
668 /* additional initialization for ALC889 variants */
669 static void alc889_coef_init(struct hda_codec
*codec
)
673 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_COEF_INDEX
, 7);
674 tmp
= snd_hda_codec_read(codec
, 0x20, 0, AC_VERB_GET_PROC_COEF
, 0);
675 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_COEF_INDEX
, 7);
676 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_PROC_COEF
, tmp
|0x2010);
679 /* turn on/off EAPD control (only if available) */
680 static void set_eapd(struct hda_codec
*codec
, hda_nid_t nid
, int on
)
682 if (get_wcaps_type(get_wcaps(codec
, nid
)) != AC_WID_PIN
)
684 if (snd_hda_query_pin_caps(codec
, nid
) & AC_PINCAP_EAPD
)
685 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_EAPD_BTLENABLE
,
689 /* turn on/off EAPD controls of the codec */
690 static void alc_auto_setup_eapd(struct hda_codec
*codec
, bool on
)
692 /* We currently only handle front, HP */
693 static hda_nid_t pins
[] = {
694 0x0f, 0x10, 0x14, 0x15, 0
697 for (p
= pins
; *p
; p
++)
698 set_eapd(codec
, *p
, on
);
701 /* generic shutup callback;
702 * just turning off EPAD and a little pause for avoiding pop-noise
704 static void alc_eapd_shutup(struct hda_codec
*codec
)
706 alc_auto_setup_eapd(codec
, false);
710 /* generic EAPD initialization */
711 static void alc_auto_init_amp(struct hda_codec
*codec
, int type
)
715 alc_auto_setup_eapd(codec
, true);
718 snd_hda_sequence_write(codec
, alc_gpio1_init_verbs
);
721 snd_hda_sequence_write(codec
, alc_gpio2_init_verbs
);
724 snd_hda_sequence_write(codec
, alc_gpio3_init_verbs
);
726 case ALC_INIT_DEFAULT
:
727 switch (codec
->vendor_id
) {
729 snd_hda_codec_write(codec
, 0x1a, 0,
730 AC_VERB_SET_COEF_INDEX
, 7);
731 tmp
= snd_hda_codec_read(codec
, 0x1a, 0,
732 AC_VERB_GET_PROC_COEF
, 0);
733 snd_hda_codec_write(codec
, 0x1a, 0,
734 AC_VERB_SET_COEF_INDEX
, 7);
735 snd_hda_codec_write(codec
, 0x1a, 0,
736 AC_VERB_SET_PROC_COEF
,
745 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
746 alc889_coef_init(codec
);
749 alc888_coef_init(codec
);
751 #if 0 /* XXX: This may cause the silent output on speaker on some machines */
754 snd_hda_codec_write(codec
, 0x20, 0,
755 AC_VERB_SET_COEF_INDEX
, 7);
756 tmp
= snd_hda_codec_read(codec
, 0x20, 0,
757 AC_VERB_GET_PROC_COEF
, 0);
758 snd_hda_codec_write(codec
, 0x20, 0,
759 AC_VERB_SET_COEF_INDEX
, 7);
760 snd_hda_codec_write(codec
, 0x20, 0,
761 AC_VERB_SET_PROC_COEF
,
771 * Auto-Mute mode mixer enum support
773 static int alc_automute_mode_info(struct snd_kcontrol
*kcontrol
,
774 struct snd_ctl_elem_info
*uinfo
)
776 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
777 struct alc_spec
*spec
= codec
->spec
;
778 static const char * const texts2
[] = {
779 "Disabled", "Enabled"
781 static const char * const texts3
[] = {
782 "Disabled", "Speaker Only", "Line-Out+Speaker"
784 const char * const *texts
;
786 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
788 if (spec
->automute_hp_lo
) {
789 uinfo
->value
.enumerated
.items
= 3;
792 uinfo
->value
.enumerated
.items
= 2;
795 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
)
796 uinfo
->value
.enumerated
.item
= uinfo
->value
.enumerated
.items
- 1;
797 strcpy(uinfo
->value
.enumerated
.name
,
798 texts
[uinfo
->value
.enumerated
.item
]);
802 static int alc_automute_mode_get(struct snd_kcontrol
*kcontrol
,
803 struct snd_ctl_elem_value
*ucontrol
)
805 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
806 struct alc_spec
*spec
= codec
->spec
;
810 else if (!spec
->automute_hp_lo
|| !spec
->automute_lines
)
814 ucontrol
->value
.enumerated
.item
[0] = val
;
818 static int alc_automute_mode_put(struct snd_kcontrol
*kcontrol
,
819 struct snd_ctl_elem_value
*ucontrol
)
821 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
822 struct alc_spec
*spec
= codec
->spec
;
824 switch (ucontrol
->value
.enumerated
.item
[0]) {
831 if (spec
->automute
&&
832 (!spec
->automute_hp_lo
|| !spec
->automute_lines
))
835 spec
->automute_lines
= 0;
838 if (!spec
->automute_hp_lo
)
840 if (spec
->automute
&& spec
->automute_lines
)
843 spec
->automute_lines
= 1;
848 update_speakers(codec
);
852 static const struct snd_kcontrol_new alc_automute_mode_enum
= {
853 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
854 .name
= "Auto-Mute Mode",
855 .info
= alc_automute_mode_info
,
856 .get
= alc_automute_mode_get
,
857 .put
= alc_automute_mode_put
,
860 static struct snd_kcontrol_new
*alc_kcontrol_new(struct alc_spec
*spec
)
862 snd_array_init(&spec
->kctls
, sizeof(struct snd_kcontrol_new
), 32);
863 return snd_array_new(&spec
->kctls
);
866 static int alc_add_automute_mode_enum(struct hda_codec
*codec
)
868 struct alc_spec
*spec
= codec
->spec
;
869 struct snd_kcontrol_new
*knew
;
871 knew
= alc_kcontrol_new(spec
);
874 *knew
= alc_automute_mode_enum
;
875 knew
->name
= kstrdup("Auto-Mute Mode", GFP_KERNEL
);
882 * Check the availability of HP/line-out auto-mute;
883 * Set up appropriately if really supported
885 static void alc_init_auto_hp(struct hda_codec
*codec
)
887 struct alc_spec
*spec
= codec
->spec
;
888 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
894 if (cfg
->line_out_pins
[0])
896 if (cfg
->speaker_pins
[0])
898 if (present
< 2) /* need two different output types */
901 spec
->automute_hp_lo
= 1; /* both HP and LO automute */
903 if (!cfg
->speaker_pins
[0] &&
904 cfg
->line_out_type
== AUTO_PIN_SPEAKER_OUT
) {
905 memcpy(cfg
->speaker_pins
, cfg
->line_out_pins
,
906 sizeof(cfg
->speaker_pins
));
907 cfg
->speaker_outs
= cfg
->line_outs
;
910 if (!cfg
->hp_pins
[0] &&
911 cfg
->line_out_type
== AUTO_PIN_HP_OUT
) {
912 memcpy(cfg
->hp_pins
, cfg
->line_out_pins
,
913 sizeof(cfg
->hp_pins
));
914 cfg
->hp_outs
= cfg
->line_outs
;
917 for (i
= 0; i
< cfg
->hp_outs
; i
++) {
918 hda_nid_t nid
= cfg
->hp_pins
[i
];
919 if (!is_jack_detectable(codec
, nid
))
921 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
923 snd_hda_codec_write_cache(codec
, nid
, 0,
924 AC_VERB_SET_UNSOLICITED_ENABLE
,
925 AC_USRSP_EN
| ALC_HP_EVENT
);
927 spec
->automute_mode
= ALC_AUTOMUTE_PIN
;
929 if (spec
->automute
&& cfg
->line_out_pins
[0] &&
930 cfg
->speaker_pins
[0] &&
931 cfg
->line_out_pins
[0] != cfg
->hp_pins
[0] &&
932 cfg
->line_out_pins
[0] != cfg
->speaker_pins
[0]) {
933 for (i
= 0; i
< cfg
->line_outs
; i
++) {
934 hda_nid_t nid
= cfg
->line_out_pins
[i
];
935 if (!is_jack_detectable(codec
, nid
))
937 snd_printdd("realtek: Enable Line-Out auto-muting "
938 "on NID 0x%x\n", nid
);
939 snd_hda_codec_write_cache(codec
, nid
, 0,
940 AC_VERB_SET_UNSOLICITED_ENABLE
,
941 AC_USRSP_EN
| ALC_FRONT_EVENT
);
942 spec
->detect_line
= 1;
944 spec
->automute_lines
= spec
->detect_line
;
947 if (spec
->automute
) {
948 /* create a control for automute mode */
949 alc_add_automute_mode_enum(codec
);
950 spec
->unsol_event
= alc_sku_unsol_event
;
954 /* return the position of NID in the list, or -1 if not found */
955 static int find_idx_in_nid_list(hda_nid_t nid
, const hda_nid_t
*list
, int nums
)
958 for (i
= 0; i
< nums
; i
++)
964 /* check whether dynamic ADC-switching is available */
965 static bool alc_check_dyn_adc_switch(struct hda_codec
*codec
)
967 struct alc_spec
*spec
= codec
->spec
;
968 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
972 if (imux
!= spec
->input_mux
) /* no dynamic imux? */
975 for (n
= 0; n
< spec
->num_adc_nids
; n
++) {
976 cap
= spec
->private_capsrc_nids
[n
];
977 for (i
= 0; i
< imux
->num_items
; i
++) {
978 pin
= spec
->imux_pins
[i
];
981 if (get_connection_index(codec
, cap
, pin
) < 0)
984 if (i
>= imux
->num_items
)
985 return true; /* no ADC-switch is needed */
988 for (i
= 0; i
< imux
->num_items
; i
++) {
989 pin
= spec
->imux_pins
[i
];
990 for (n
= 0; n
< spec
->num_adc_nids
; n
++) {
991 cap
= spec
->private_capsrc_nids
[n
];
992 idx
= get_connection_index(codec
, cap
, pin
);
994 imux
->items
[i
].index
= idx
;
995 spec
->dyn_adc_idx
[i
] = n
;
1001 snd_printdd("realtek: enabling ADC switching\n");
1002 spec
->dyn_adc_switch
= 1;
1006 /* rebuild imux for matching with the given auto-mic pins (if not yet) */
1007 static bool alc_rebuild_imux_for_auto_mic(struct hda_codec
*codec
)
1009 struct alc_spec
*spec
= codec
->spec
;
1010 struct hda_input_mux
*imux
;
1011 static char * const texts
[3] = {
1012 "Mic", "Internal Mic", "Dock Mic"
1016 if (!spec
->auto_mic
)
1018 imux
= &spec
->private_imux
[0];
1019 if (spec
->input_mux
== imux
)
1021 spec
->imux_pins
[0] = spec
->ext_mic_pin
;
1022 spec
->imux_pins
[1] = spec
->int_mic_pin
;
1023 spec
->imux_pins
[2] = spec
->dock_mic_pin
;
1024 for (i
= 0; i
< 3; i
++) {
1025 strcpy(imux
->items
[i
].label
, texts
[i
]);
1026 if (spec
->imux_pins
[i
]) {
1027 hda_nid_t pin
= spec
->imux_pins
[i
];
1029 for (c
= 0; c
< spec
->num_adc_nids
; c
++) {
1030 hda_nid_t cap
= spec
->capsrc_nids
?
1031 spec
->capsrc_nids
[c
] : spec
->adc_nids
[c
];
1032 int idx
= get_connection_index(codec
, cap
, pin
);
1034 imux
->items
[i
].index
= idx
;
1038 imux
->num_items
= i
+ 1;
1041 spec
->num_mux_defs
= 1;
1042 spec
->input_mux
= imux
;
1046 /* check whether all auto-mic pins are valid; setup indices if OK */
1047 static bool alc_auto_mic_check_imux(struct hda_codec
*codec
)
1049 struct alc_spec
*spec
= codec
->spec
;
1050 const struct hda_input_mux
*imux
;
1052 if (!spec
->auto_mic
)
1054 if (spec
->auto_mic_valid_imux
)
1055 return true; /* already checked */
1057 /* fill up imux indices */
1058 if (!alc_check_dyn_adc_switch(codec
)) {
1063 imux
= spec
->input_mux
;
1064 spec
->ext_mic_idx
= find_idx_in_nid_list(spec
->ext_mic_pin
,
1065 spec
->imux_pins
, imux
->num_items
);
1066 spec
->int_mic_idx
= find_idx_in_nid_list(spec
->int_mic_pin
,
1067 spec
->imux_pins
, imux
->num_items
);
1068 spec
->dock_mic_idx
= find_idx_in_nid_list(spec
->dock_mic_pin
,
1069 spec
->imux_pins
, imux
->num_items
);
1070 if (spec
->ext_mic_idx
< 0 || spec
->int_mic_idx
< 0) {
1072 return false; /* no corresponding imux */
1075 snd_hda_codec_write_cache(codec
, spec
->ext_mic_pin
, 0,
1076 AC_VERB_SET_UNSOLICITED_ENABLE
,
1077 AC_USRSP_EN
| ALC_MIC_EVENT
);
1078 if (spec
->dock_mic_pin
)
1079 snd_hda_codec_write_cache(codec
, spec
->dock_mic_pin
, 0,
1080 AC_VERB_SET_UNSOLICITED_ENABLE
,
1081 AC_USRSP_EN
| ALC_MIC_EVENT
);
1083 spec
->auto_mic_valid_imux
= 1;
1089 * Check the availability of auto-mic switch;
1090 * Set up if really supported
1092 static void alc_init_auto_mic(struct hda_codec
*codec
)
1094 struct alc_spec
*spec
= codec
->spec
;
1095 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
1096 hda_nid_t fixed
, ext
, dock
;
1099 spec
->ext_mic_idx
= spec
->int_mic_idx
= spec
->dock_mic_idx
= -1;
1101 fixed
= ext
= dock
= 0;
1102 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
1103 hda_nid_t nid
= cfg
->inputs
[i
].pin
;
1104 unsigned int defcfg
;
1105 defcfg
= snd_hda_codec_get_pincfg(codec
, nid
);
1106 switch (snd_hda_get_input_pin_attr(defcfg
)) {
1107 case INPUT_PIN_ATTR_INT
:
1109 return; /* already occupied */
1110 if (cfg
->inputs
[i
].type
!= AUTO_PIN_MIC
)
1111 return; /* invalid type */
1114 case INPUT_PIN_ATTR_UNUSED
:
1115 return; /* invalid entry */
1116 case INPUT_PIN_ATTR_DOCK
:
1118 return; /* already occupied */
1119 if (cfg
->inputs
[i
].type
> AUTO_PIN_LINE_IN
)
1120 return; /* invalid type */
1125 return; /* already occupied */
1126 if (cfg
->inputs
[i
].type
!= AUTO_PIN_MIC
)
1127 return; /* invalid type */
1138 if (!is_jack_detectable(codec
, ext
))
1139 return; /* no unsol support */
1140 if (dock
&& !is_jack_detectable(codec
, dock
))
1141 return; /* no unsol support */
1143 /* check imux indices */
1144 spec
->ext_mic_pin
= ext
;
1145 spec
->int_mic_pin
= fixed
;
1146 spec
->dock_mic_pin
= dock
;
1149 if (!alc_auto_mic_check_imux(codec
))
1152 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1154 spec
->unsol_event
= alc_sku_unsol_event
;
1157 /* check the availabilities of auto-mute and auto-mic switches */
1158 static void alc_auto_check_switches(struct hda_codec
*codec
)
1160 alc_init_auto_hp(codec
);
1161 alc_init_auto_mic(codec
);
1165 * Realtek SSID verification
1168 /* Could be any non-zero and even value. When used as fixup, tells
1169 * the driver to ignore any present sku defines.
1171 #define ALC_FIXUP_SKU_IGNORE (2)
1173 static int alc_auto_parse_customize_define(struct hda_codec
*codec
)
1175 unsigned int ass
, tmp
, i
;
1177 struct alc_spec
*spec
= codec
->spec
;
1179 spec
->cdefine
.enable_pcbeep
= 1; /* assume always enabled */
1181 if (spec
->cdefine
.fixup
) {
1182 ass
= spec
->cdefine
.sku_cfg
;
1183 if (ass
== ALC_FIXUP_SKU_IGNORE
)
1188 ass
= codec
->subsystem_id
& 0xffff;
1189 if (ass
!= codec
->bus
->pci
->subsystem_device
&& (ass
& 1))
1193 if (codec
->vendor_id
== 0x10ec0260)
1195 ass
= snd_hda_codec_get_pincfg(codec
, nid
);
1198 printk(KERN_INFO
"hda_codec: %s: SKU not ready 0x%08x\n",
1199 codec
->chip_name
, ass
);
1205 for (i
= 1; i
< 16; i
++) {
1209 if (((ass
>> 16) & 0xf) != tmp
)
1212 spec
->cdefine
.port_connectivity
= ass
>> 30;
1213 spec
->cdefine
.enable_pcbeep
= (ass
& 0x100000) >> 20;
1214 spec
->cdefine
.check_sum
= (ass
>> 16) & 0xf;
1215 spec
->cdefine
.customization
= ass
>> 8;
1217 spec
->cdefine
.sku_cfg
= ass
;
1218 spec
->cdefine
.external_amp
= (ass
& 0x38) >> 3;
1219 spec
->cdefine
.platform_type
= (ass
& 0x4) >> 2;
1220 spec
->cdefine
.swap
= (ass
& 0x2) >> 1;
1221 spec
->cdefine
.override
= ass
& 0x1;
1223 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1224 nid
, spec
->cdefine
.sku_cfg
);
1225 snd_printd("SKU: port_connectivity=0x%x\n",
1226 spec
->cdefine
.port_connectivity
);
1227 snd_printd("SKU: enable_pcbeep=0x%x\n", spec
->cdefine
.enable_pcbeep
);
1228 snd_printd("SKU: check_sum=0x%08x\n", spec
->cdefine
.check_sum
);
1229 snd_printd("SKU: customization=0x%08x\n", spec
->cdefine
.customization
);
1230 snd_printd("SKU: external_amp=0x%x\n", spec
->cdefine
.external_amp
);
1231 snd_printd("SKU: platform_type=0x%x\n", spec
->cdefine
.platform_type
);
1232 snd_printd("SKU: swap=0x%x\n", spec
->cdefine
.swap
);
1233 snd_printd("SKU: override=0x%x\n", spec
->cdefine
.override
);
1238 /* return true if the given NID is found in the list */
1239 static bool found_in_nid_list(hda_nid_t nid
, const hda_nid_t
*list
, int nums
)
1241 return find_idx_in_nid_list(nid
, list
, nums
) >= 0;
1244 /* check subsystem ID and set up device-specific initialization;
1245 * return 1 if initialized, 0 if invalid SSID
1247 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1248 * 31 ~ 16 : Manufacture ID
1250 * 7 ~ 0 : Assembly ID
1251 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1253 static int alc_subsystem_id(struct hda_codec
*codec
,
1254 hda_nid_t porta
, hda_nid_t porte
,
1255 hda_nid_t portd
, hda_nid_t porti
)
1257 unsigned int ass
, tmp
, i
;
1259 struct alc_spec
*spec
= codec
->spec
;
1261 if (spec
->cdefine
.fixup
) {
1262 ass
= spec
->cdefine
.sku_cfg
;
1263 if (ass
== ALC_FIXUP_SKU_IGNORE
)
1268 ass
= codec
->subsystem_id
& 0xffff;
1269 if ((ass
!= codec
->bus
->pci
->subsystem_device
) && (ass
& 1))
1272 /* invalid SSID, check the special NID pin defcfg instead */
1274 * 31~30 : port connectivity
1277 * 19~16 : Check sum (15:1)
1282 if (codec
->vendor_id
== 0x10ec0260)
1284 ass
= snd_hda_codec_get_pincfg(codec
, nid
);
1285 snd_printd("realtek: No valid SSID, "
1286 "checking pincfg 0x%08x for NID 0x%x\n",
1290 if ((ass
>> 30) != 1) /* no physical connection */
1295 for (i
= 1; i
< 16; i
++) {
1299 if (((ass
>> 16) & 0xf) != tmp
)
1302 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1303 ass
& 0xffff, codec
->vendor_id
);
1307 * 2 : 0 --> Desktop, 1 --> Laptop
1308 * 3~5 : External Amplifier control
1311 tmp
= (ass
& 0x38) >> 3; /* external Amp control */
1314 spec
->init_amp
= ALC_INIT_GPIO1
;
1317 spec
->init_amp
= ALC_INIT_GPIO2
;
1320 spec
->init_amp
= ALC_INIT_GPIO3
;
1324 spec
->init_amp
= ALC_INIT_DEFAULT
;
1328 /* is laptop or Desktop and enable the function "Mute internal speaker
1329 * when the external headphone out jack is plugged"
1331 if (!(ass
& 0x8000))
1334 * 10~8 : Jack location
1335 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1337 * 15 : 1 --> enable the function "Mute internal speaker
1338 * when the external headphone out jack is plugged"
1340 if (!spec
->autocfg
.hp_pins
[0] &&
1341 !(spec
->autocfg
.line_out_pins
[0] &&
1342 spec
->autocfg
.line_out_type
== AUTO_PIN_HP_OUT
)) {
1344 tmp
= (ass
>> 11) & 0x3; /* HP to chassis */
1355 if (found_in_nid_list(nid
, spec
->autocfg
.line_out_pins
,
1356 spec
->autocfg
.line_outs
))
1358 spec
->autocfg
.hp_pins
[0] = nid
;
1363 /* Check the validity of ALC subsystem-id
1364 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1365 static void alc_ssid_check(struct hda_codec
*codec
, const hda_nid_t
*ports
)
1367 if (!alc_subsystem_id(codec
, ports
[0], ports
[1], ports
[2], ports
[3])) {
1368 struct alc_spec
*spec
= codec
->spec
;
1369 snd_printd("realtek: "
1370 "Enable default setup for auto mode as fallback\n");
1371 spec
->init_amp
= ALC_INIT_DEFAULT
;
1376 * Fix-up pin default configurations and add default verbs
1384 struct alc_model_fixup
{
1395 const struct alc_pincfg
*pins
;
1396 const struct hda_verb
*verbs
;
1397 void (*func
)(struct hda_codec
*codec
,
1398 const struct alc_fixup
*fix
,
1412 ALC_FIXUP_ACT_PRE_PROBE
,
1413 ALC_FIXUP_ACT_PROBE
,
1417 static void alc_apply_fixup(struct hda_codec
*codec
, int action
)
1419 struct alc_spec
*spec
= codec
->spec
;
1420 int id
= spec
->fixup_id
;
1421 #ifdef CONFIG_SND_DEBUG_VERBOSE
1422 const char *modelname
= spec
->fixup_name
;
1426 if (!spec
->fixup_list
)
1430 const struct alc_fixup
*fix
= spec
->fixup_list
+ id
;
1431 const struct alc_pincfg
*cfg
;
1433 switch (fix
->type
) {
1435 if (action
!= ALC_FIXUP_ACT_PRE_PROBE
|| !fix
->v
.sku
)
1437 snd_printdd(KERN_INFO
"hda_codec: %s: "
1438 "Apply sku override for %s\n",
1439 codec
->chip_name
, modelname
);
1440 spec
->cdefine
.sku_cfg
= fix
->v
.sku
;
1441 spec
->cdefine
.fixup
= 1;
1443 case ALC_FIXUP_PINS
:
1445 if (action
!= ALC_FIXUP_ACT_PRE_PROBE
|| !cfg
)
1447 snd_printdd(KERN_INFO
"hda_codec: %s: "
1448 "Apply pincfg for %s\n",
1449 codec
->chip_name
, modelname
);
1450 for (; cfg
->nid
; cfg
++)
1451 snd_hda_codec_set_pincfg(codec
, cfg
->nid
,
1454 case ALC_FIXUP_VERBS
:
1455 if (action
!= ALC_FIXUP_ACT_PROBE
|| !fix
->v
.verbs
)
1457 snd_printdd(KERN_INFO
"hda_codec: %s: "
1458 "Apply fix-verbs for %s\n",
1459 codec
->chip_name
, modelname
);
1460 add_verb(codec
->spec
, fix
->v
.verbs
);
1462 case ALC_FIXUP_FUNC
:
1465 snd_printdd(KERN_INFO
"hda_codec: %s: "
1466 "Apply fix-func for %s\n",
1467 codec
->chip_name
, modelname
);
1468 fix
->v
.func(codec
, fix
, action
);
1471 snd_printk(KERN_ERR
"hda_codec: %s: "
1472 "Invalid fixup type %d\n",
1473 codec
->chip_name
, fix
->type
);
1484 static void alc_pick_fixup(struct hda_codec
*codec
,
1485 const struct alc_model_fixup
*models
,
1486 const struct snd_pci_quirk
*quirk
,
1487 const struct alc_fixup
*fixlist
)
1489 struct alc_spec
*spec
= codec
->spec
;
1491 const char *name
= NULL
;
1493 if (codec
->modelname
&& models
) {
1494 while (models
->name
) {
1495 if (!strcmp(codec
->modelname
, models
->name
)) {
1497 name
= models
->name
;
1504 quirk
= snd_pci_quirk_lookup(codec
->bus
->pci
, quirk
);
1507 #ifdef CONFIG_SND_DEBUG_VERBOSE
1513 spec
->fixup_id
= id
;
1515 spec
->fixup_list
= fixlist
;
1516 spec
->fixup_name
= name
;
1521 * COEF access helper functions
1523 static int alc_read_coef_idx(struct hda_codec
*codec
,
1524 unsigned int coef_idx
)
1527 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_COEF_INDEX
,
1529 val
= snd_hda_codec_read(codec
, 0x20, 0,
1530 AC_VERB_GET_PROC_COEF
, 0);
1534 static void alc_write_coef_idx(struct hda_codec
*codec
, unsigned int coef_idx
,
1535 unsigned int coef_val
)
1537 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_COEF_INDEX
,
1539 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_PROC_COEF
,
1544 * Digital I/O handling
1547 /* set right pin controls for digital I/O */
1548 static void alc_auto_init_digital(struct hda_codec
*codec
)
1550 struct alc_spec
*spec
= codec
->spec
;
1554 for (i
= 0; i
< spec
->autocfg
.dig_outs
; i
++) {
1555 pin
= spec
->autocfg
.dig_out_pins
[i
];
1558 snd_hda_codec_write(codec
, pin
, 0,
1559 AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
);
1561 dac
= spec
->multiout
.dig_out_nid
;
1563 dac
= spec
->slave_dig_outs
[i
- 1];
1564 if (!dac
|| !(get_wcaps(codec
, dac
) & AC_WCAP_OUT_AMP
))
1566 snd_hda_codec_write(codec
, dac
, 0,
1567 AC_VERB_SET_AMP_GAIN_MUTE
,
1570 pin
= spec
->autocfg
.dig_in_pin
;
1572 snd_hda_codec_write(codec
, pin
, 0,
1573 AC_VERB_SET_PIN_WIDGET_CONTROL
,
1577 /* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1578 static void alc_auto_parse_digital(struct hda_codec
*codec
)
1580 struct alc_spec
*spec
= codec
->spec
;
1584 /* support multiple SPDIFs; the secondary is set up as a slave */
1586 for (i
= 0; i
< spec
->autocfg
.dig_outs
; i
++) {
1588 err
= snd_hda_get_connections(codec
,
1589 spec
->autocfg
.dig_out_pins
[i
],
1590 conn
, ARRAY_SIZE(conn
));
1593 dig_nid
= conn
[0]; /* assume the first element is audio-out */
1595 spec
->multiout
.dig_out_nid
= dig_nid
;
1596 spec
->dig_out_type
= spec
->autocfg
.dig_out_type
[0];
1598 spec
->multiout
.slave_dig_outs
= spec
->slave_dig_outs
;
1599 if (nums
>= ARRAY_SIZE(spec
->slave_dig_outs
) - 1)
1601 spec
->slave_dig_outs
[nums
- 1] = dig_nid
;
1606 if (spec
->autocfg
.dig_in_pin
) {
1607 dig_nid
= codec
->start_nid
;
1608 for (i
= 0; i
< codec
->num_nodes
; i
++, dig_nid
++) {
1609 unsigned int wcaps
= get_wcaps(codec
, dig_nid
);
1610 if (get_wcaps_type(wcaps
) != AC_WID_AUD_IN
)
1612 if (!(wcaps
& AC_WCAP_DIGITAL
))
1614 if (!(wcaps
& AC_WCAP_CONN_LIST
))
1616 err
= get_connection_index(codec
, dig_nid
,
1617 spec
->autocfg
.dig_in_pin
);
1619 spec
->dig_in_nid
= dig_nid
;
1627 * capture mixer elements
1629 static int alc_cap_vol_info(struct snd_kcontrol
*kcontrol
,
1630 struct snd_ctl_elem_info
*uinfo
)
1632 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1633 struct alc_spec
*spec
= codec
->spec
;
1637 mutex_lock(&codec
->control_mutex
);
1638 if (spec
->vol_in_capsrc
)
1639 val
= HDA_COMPOSE_AMP_VAL(spec
->capsrc_nids
[0], 3, 0, HDA_OUTPUT
);
1641 val
= HDA_COMPOSE_AMP_VAL(spec
->adc_nids
[0], 3, 0, HDA_INPUT
);
1642 kcontrol
->private_value
= val
;
1643 err
= snd_hda_mixer_amp_volume_info(kcontrol
, uinfo
);
1644 mutex_unlock(&codec
->control_mutex
);
1648 static int alc_cap_vol_tlv(struct snd_kcontrol
*kcontrol
, int op_flag
,
1649 unsigned int size
, unsigned int __user
*tlv
)
1651 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1652 struct alc_spec
*spec
= codec
->spec
;
1656 mutex_lock(&codec
->control_mutex
);
1657 if (spec
->vol_in_capsrc
)
1658 val
= HDA_COMPOSE_AMP_VAL(spec
->capsrc_nids
[0], 3, 0, HDA_OUTPUT
);
1660 val
= HDA_COMPOSE_AMP_VAL(spec
->adc_nids
[0], 3, 0, HDA_INPUT
);
1661 kcontrol
->private_value
= val
;
1662 err
= snd_hda_mixer_amp_tlv(kcontrol
, op_flag
, size
, tlv
);
1663 mutex_unlock(&codec
->control_mutex
);
1667 typedef int (*getput_call_t
)(struct snd_kcontrol
*kcontrol
,
1668 struct snd_ctl_elem_value
*ucontrol
);
1670 static int alc_cap_getput_caller(struct snd_kcontrol
*kcontrol
,
1671 struct snd_ctl_elem_value
*ucontrol
,
1672 getput_call_t func
, bool check_adc_switch
)
1674 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1675 struct alc_spec
*spec
= codec
->spec
;
1678 mutex_lock(&codec
->control_mutex
);
1679 if (check_adc_switch
&& spec
->dyn_adc_switch
) {
1680 for (i
= 0; i
< spec
->num_adc_nids
; i
++) {
1681 kcontrol
->private_value
=
1682 HDA_COMPOSE_AMP_VAL(spec
->adc_nids
[i
],
1684 err
= func(kcontrol
, ucontrol
);
1689 i
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
1690 if (spec
->vol_in_capsrc
)
1691 kcontrol
->private_value
=
1692 HDA_COMPOSE_AMP_VAL(spec
->capsrc_nids
[i
],
1695 kcontrol
->private_value
=
1696 HDA_COMPOSE_AMP_VAL(spec
->adc_nids
[i
],
1698 err
= func(kcontrol
, ucontrol
);
1701 mutex_unlock(&codec
->control_mutex
);
1705 static int alc_cap_vol_get(struct snd_kcontrol
*kcontrol
,
1706 struct snd_ctl_elem_value
*ucontrol
)
1708 return alc_cap_getput_caller(kcontrol
, ucontrol
,
1709 snd_hda_mixer_amp_volume_get
, false);
1712 static int alc_cap_vol_put(struct snd_kcontrol
*kcontrol
,
1713 struct snd_ctl_elem_value
*ucontrol
)
1715 return alc_cap_getput_caller(kcontrol
, ucontrol
,
1716 snd_hda_mixer_amp_volume_put
, true);
1719 /* capture mixer elements */
1720 #define alc_cap_sw_info snd_ctl_boolean_stereo_info
1722 static int alc_cap_sw_get(struct snd_kcontrol
*kcontrol
,
1723 struct snd_ctl_elem_value
*ucontrol
)
1725 return alc_cap_getput_caller(kcontrol
, ucontrol
,
1726 snd_hda_mixer_amp_switch_get
, false);
1729 static int alc_cap_sw_put(struct snd_kcontrol
*kcontrol
,
1730 struct snd_ctl_elem_value
*ucontrol
)
1732 return alc_cap_getput_caller(kcontrol
, ucontrol
,
1733 snd_hda_mixer_amp_switch_put
, true);
1736 #define _DEFINE_CAPMIX(num) \
1738 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1739 .name = "Capture Switch", \
1740 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1742 .info = alc_cap_sw_info, \
1743 .get = alc_cap_sw_get, \
1744 .put = alc_cap_sw_put, \
1747 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1748 .name = "Capture Volume", \
1749 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1750 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1751 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1753 .info = alc_cap_vol_info, \
1754 .get = alc_cap_vol_get, \
1755 .put = alc_cap_vol_put, \
1756 .tlv = { .c = alc_cap_vol_tlv }, \
1759 #define _DEFINE_CAPSRC(num) \
1761 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1762 /* .name = "Capture Source", */ \
1763 .name = "Input Source", \
1765 .info = alc_mux_enum_info, \
1766 .get = alc_mux_enum_get, \
1767 .put = alc_mux_enum_put, \
1770 #define DEFINE_CAPMIX(num) \
1771 static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
1772 _DEFINE_CAPMIX(num), \
1773 _DEFINE_CAPSRC(num), \
1777 #define DEFINE_CAPMIX_NOSRC(num) \
1778 static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
1779 _DEFINE_CAPMIX(num), \
1783 /* up to three ADCs */
1787 DEFINE_CAPMIX_NOSRC(1);
1788 DEFINE_CAPMIX_NOSRC(2);
1789 DEFINE_CAPMIX_NOSRC(3);
1792 * virtual master controls
1796 * slave controls for virtual master
1798 static const char * const alc_slave_vols
[] = {
1799 "Front Playback Volume",
1800 "Surround Playback Volume",
1801 "Center Playback Volume",
1802 "LFE Playback Volume",
1803 "Side Playback Volume",
1804 "Headphone Playback Volume",
1805 "Speaker Playback Volume",
1806 "Mono Playback Volume",
1807 "Line-Out Playback Volume",
1808 "PCM Playback Volume",
1812 static const char * const alc_slave_sws
[] = {
1813 "Front Playback Switch",
1814 "Surround Playback Switch",
1815 "Center Playback Switch",
1816 "LFE Playback Switch",
1817 "Side Playback Switch",
1818 "Headphone Playback Switch",
1819 "Speaker Playback Switch",
1820 "Mono Playback Switch",
1821 "IEC958 Playback Switch",
1822 "Line-Out Playback Switch",
1823 "PCM Playback Switch",
1828 * build control elements
1831 #define NID_MAPPING (-1)
1833 #define SUBDEV_SPEAKER_ (0 << 6)
1834 #define SUBDEV_HP_ (1 << 6)
1835 #define SUBDEV_LINE_ (2 << 6)
1836 #define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1837 #define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1838 #define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1840 static void alc_free_kctls(struct hda_codec
*codec
);
1842 #ifdef CONFIG_SND_HDA_INPUT_BEEP
1843 /* additional beep mixers; the actual parameters are overwritten at build */
1844 static const struct snd_kcontrol_new alc_beep_mixer
[] = {
1845 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT
),
1846 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT
),
1851 static int alc_build_controls(struct hda_codec
*codec
)
1853 struct alc_spec
*spec
= codec
->spec
;
1854 struct snd_kcontrol
*kctl
= NULL
;
1855 const struct snd_kcontrol_new
*knew
;
1860 for (i
= 0; i
< spec
->num_mixers
; i
++) {
1861 err
= snd_hda_add_new_ctls(codec
, spec
->mixers
[i
]);
1865 if (spec
->cap_mixer
) {
1866 err
= snd_hda_add_new_ctls(codec
, spec
->cap_mixer
);
1870 if (spec
->multiout
.dig_out_nid
) {
1871 err
= snd_hda_create_spdif_out_ctls(codec
,
1872 spec
->multiout
.dig_out_nid
,
1873 spec
->multiout
.dig_out_nid
);
1876 if (!spec
->no_analog
) {
1877 err
= snd_hda_create_spdif_share_sw(codec
,
1881 spec
->multiout
.share_spdif
= 1;
1884 if (spec
->dig_in_nid
) {
1885 err
= snd_hda_create_spdif_in_ctls(codec
, spec
->dig_in_nid
);
1890 #ifdef CONFIG_SND_HDA_INPUT_BEEP
1891 /* create beep controls if needed */
1892 if (spec
->beep_amp
) {
1893 const struct snd_kcontrol_new
*knew
;
1894 for (knew
= alc_beep_mixer
; knew
->name
; knew
++) {
1895 struct snd_kcontrol
*kctl
;
1896 kctl
= snd_ctl_new1(knew
, codec
);
1899 kctl
->private_value
= spec
->beep_amp
;
1900 err
= snd_hda_ctl_add(codec
, 0, kctl
);
1907 /* if we have no master control, let's create it */
1908 if (!spec
->no_analog
&&
1909 !snd_hda_find_mixer_ctl(codec
, "Master Playback Volume")) {
1910 unsigned int vmaster_tlv
[4];
1911 snd_hda_set_vmaster_tlv(codec
, spec
->vmaster_nid
,
1912 HDA_OUTPUT
, vmaster_tlv
);
1913 err
= snd_hda_add_vmaster(codec
, "Master Playback Volume",
1914 vmaster_tlv
, alc_slave_vols
);
1918 if (!spec
->no_analog
&&
1919 !snd_hda_find_mixer_ctl(codec
, "Master Playback Switch")) {
1920 err
= snd_hda_add_vmaster(codec
, "Master Playback Switch",
1921 NULL
, alc_slave_sws
);
1926 /* assign Capture Source enums to NID */
1927 if (spec
->capsrc_nids
|| spec
->adc_nids
) {
1928 kctl
= snd_hda_find_mixer_ctl(codec
, "Capture Source");
1930 kctl
= snd_hda_find_mixer_ctl(codec
, "Input Source");
1931 for (i
= 0; kctl
&& i
< kctl
->count
; i
++) {
1932 const hda_nid_t
*nids
= spec
->capsrc_nids
;
1934 nids
= spec
->adc_nids
;
1935 err
= snd_hda_add_nid(codec
, kctl
, i
, nids
[i
]);
1940 if (spec
->cap_mixer
&& spec
->adc_nids
) {
1941 const char *kname
= kctl
? kctl
->id
.name
: NULL
;
1942 for (knew
= spec
->cap_mixer
; knew
->name
; knew
++) {
1943 if (kname
&& strcmp(knew
->name
, kname
) == 0)
1945 kctl
= snd_hda_find_mixer_ctl(codec
, knew
->name
);
1946 for (i
= 0; kctl
&& i
< kctl
->count
; i
++) {
1947 err
= snd_hda_add_nid(codec
, kctl
, i
,
1955 /* other nid->control mapping */
1956 for (i
= 0; i
< spec
->num_mixers
; i
++) {
1957 for (knew
= spec
->mixers
[i
]; knew
->name
; knew
++) {
1958 if (knew
->iface
!= NID_MAPPING
)
1960 kctl
= snd_hda_find_mixer_ctl(codec
, knew
->name
);
1963 u
= knew
->subdevice
;
1964 for (j
= 0; j
< 4; j
++, u
>>= 8) {
1969 case SUBDEV_SPEAKER_
:
1970 nid
= spec
->autocfg
.speaker_pins
[nid
];
1973 nid
= spec
->autocfg
.line_out_pins
[nid
];
1976 nid
= spec
->autocfg
.hp_pins
[nid
];
1981 err
= snd_hda_add_nid(codec
, kctl
, 0, nid
);
1985 u
= knew
->private_value
;
1986 for (j
= 0; j
< 4; j
++, u
>>= 8) {
1990 err
= snd_hda_add_nid(codec
, kctl
, 0, nid
);
1997 alc_free_kctls(codec
); /* no longer needed */
2007 static void alc_init_special_input_src(struct hda_codec
*codec
);
2009 static int alc_init(struct hda_codec
*codec
)
2011 struct alc_spec
*spec
= codec
->spec
;
2015 alc_auto_init_amp(codec
, spec
->init_amp
);
2017 for (i
= 0; i
< spec
->num_init_verbs
; i
++)
2018 snd_hda_sequence_write(codec
, spec
->init_verbs
[i
]);
2019 alc_init_special_input_src(codec
);
2021 if (spec
->init_hook
)
2022 spec
->init_hook(codec
);
2024 alc_apply_fixup(codec
, ALC_FIXUP_ACT_INIT
);
2026 hda_call_check_power_status(codec
, 0x01);
2030 static void alc_unsol_event(struct hda_codec
*codec
, unsigned int res
)
2032 struct alc_spec
*spec
= codec
->spec
;
2034 if (spec
->unsol_event
)
2035 spec
->unsol_event(codec
, res
);
2038 #ifdef CONFIG_SND_HDA_POWER_SAVE
2039 static int alc_check_power_status(struct hda_codec
*codec
, hda_nid_t nid
)
2041 struct alc_spec
*spec
= codec
->spec
;
2042 return snd_hda_check_amp_list_power(codec
, &spec
->loopback
, nid
);
2047 * Analog playback callbacks
2049 static int alc_playback_pcm_open(struct hda_pcm_stream
*hinfo
,
2050 struct hda_codec
*codec
,
2051 struct snd_pcm_substream
*substream
)
2053 struct alc_spec
*spec
= codec
->spec
;
2054 return snd_hda_multi_out_analog_open(codec
, &spec
->multiout
, substream
,
2058 static int alc_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
2059 struct hda_codec
*codec
,
2060 unsigned int stream_tag
,
2061 unsigned int format
,
2062 struct snd_pcm_substream
*substream
)
2064 struct alc_spec
*spec
= codec
->spec
;
2065 return snd_hda_multi_out_analog_prepare(codec
, &spec
->multiout
,
2066 stream_tag
, format
, substream
);
2069 static int alc_playback_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
2070 struct hda_codec
*codec
,
2071 struct snd_pcm_substream
*substream
)
2073 struct alc_spec
*spec
= codec
->spec
;
2074 return snd_hda_multi_out_analog_cleanup(codec
, &spec
->multiout
);
2080 static int alc_dig_playback_pcm_open(struct hda_pcm_stream
*hinfo
,
2081 struct hda_codec
*codec
,
2082 struct snd_pcm_substream
*substream
)
2084 struct alc_spec
*spec
= codec
->spec
;
2085 return snd_hda_multi_out_dig_open(codec
, &spec
->multiout
);
2088 static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
2089 struct hda_codec
*codec
,
2090 unsigned int stream_tag
,
2091 unsigned int format
,
2092 struct snd_pcm_substream
*substream
)
2094 struct alc_spec
*spec
= codec
->spec
;
2095 return snd_hda_multi_out_dig_prepare(codec
, &spec
->multiout
,
2096 stream_tag
, format
, substream
);
2099 static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
2100 struct hda_codec
*codec
,
2101 struct snd_pcm_substream
*substream
)
2103 struct alc_spec
*spec
= codec
->spec
;
2104 return snd_hda_multi_out_dig_cleanup(codec
, &spec
->multiout
);
2107 static int alc_dig_playback_pcm_close(struct hda_pcm_stream
*hinfo
,
2108 struct hda_codec
*codec
,
2109 struct snd_pcm_substream
*substream
)
2111 struct alc_spec
*spec
= codec
->spec
;
2112 return snd_hda_multi_out_dig_close(codec
, &spec
->multiout
);
2118 static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream
*hinfo
,
2119 struct hda_codec
*codec
,
2120 unsigned int stream_tag
,
2121 unsigned int format
,
2122 struct snd_pcm_substream
*substream
)
2124 struct alc_spec
*spec
= codec
->spec
;
2126 snd_hda_codec_setup_stream(codec
, spec
->adc_nids
[substream
->number
+ 1],
2127 stream_tag
, 0, format
);
2131 static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
2132 struct hda_codec
*codec
,
2133 struct snd_pcm_substream
*substream
)
2135 struct alc_spec
*spec
= codec
->spec
;
2137 snd_hda_codec_cleanup_stream(codec
,
2138 spec
->adc_nids
[substream
->number
+ 1]);
2142 /* analog capture with dynamic dual-adc changes */
2143 static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream
*hinfo
,
2144 struct hda_codec
*codec
,
2145 unsigned int stream_tag
,
2146 unsigned int format
,
2147 struct snd_pcm_substream
*substream
)
2149 struct alc_spec
*spec
= codec
->spec
;
2150 spec
->cur_adc
= spec
->adc_nids
[spec
->dyn_adc_idx
[spec
->cur_mux
[0]]];
2151 spec
->cur_adc_stream_tag
= stream_tag
;
2152 spec
->cur_adc_format
= format
;
2153 snd_hda_codec_setup_stream(codec
, spec
->cur_adc
, stream_tag
, 0, format
);
2157 static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
2158 struct hda_codec
*codec
,
2159 struct snd_pcm_substream
*substream
)
2161 struct alc_spec
*spec
= codec
->spec
;
2162 snd_hda_codec_cleanup_stream(codec
, spec
->cur_adc
);
2167 static const struct hda_pcm_stream dyn_adc_pcm_analog_capture
= {
2171 .nid
= 0, /* fill later */
2173 .prepare
= dyn_adc_capture_pcm_prepare
,
2174 .cleanup
= dyn_adc_capture_pcm_cleanup
2180 static const struct hda_pcm_stream alc_pcm_analog_playback
= {
2184 /* NID is set in alc_build_pcms */
2186 .open
= alc_playback_pcm_open
,
2187 .prepare
= alc_playback_pcm_prepare
,
2188 .cleanup
= alc_playback_pcm_cleanup
2192 static const struct hda_pcm_stream alc_pcm_analog_capture
= {
2196 /* NID is set in alc_build_pcms */
2199 static const struct hda_pcm_stream alc_pcm_analog_alt_playback
= {
2203 /* NID is set in alc_build_pcms */
2206 static const struct hda_pcm_stream alc_pcm_analog_alt_capture
= {
2207 .substreams
= 2, /* can be overridden */
2210 /* NID is set in alc_build_pcms */
2212 .prepare
= alc_alt_capture_pcm_prepare
,
2213 .cleanup
= alc_alt_capture_pcm_cleanup
2217 static const struct hda_pcm_stream alc_pcm_digital_playback
= {
2221 /* NID is set in alc_build_pcms */
2223 .open
= alc_dig_playback_pcm_open
,
2224 .close
= alc_dig_playback_pcm_close
,
2225 .prepare
= alc_dig_playback_pcm_prepare
,
2226 .cleanup
= alc_dig_playback_pcm_cleanup
2230 static const struct hda_pcm_stream alc_pcm_digital_capture
= {
2234 /* NID is set in alc_build_pcms */
2237 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
2238 static const struct hda_pcm_stream alc_pcm_null_stream
= {
2244 static int alc_build_pcms(struct hda_codec
*codec
)
2246 struct alc_spec
*spec
= codec
->spec
;
2247 struct hda_pcm
*info
= spec
->pcm_rec
;
2248 const struct hda_pcm_stream
*p
;
2249 bool have_multi_adcs
;
2252 codec
->num_pcms
= 1;
2253 codec
->pcm_info
= info
;
2255 if (spec
->no_analog
)
2258 snprintf(spec
->stream_name_analog
, sizeof(spec
->stream_name_analog
),
2259 "%s Analog", codec
->chip_name
);
2260 info
->name
= spec
->stream_name_analog
;
2262 if (spec
->multiout
.dac_nids
> 0) {
2263 p
= spec
->stream_analog_playback
;
2265 p
= &alc_pcm_analog_playback
;
2266 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] = *p
;
2267 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
= spec
->multiout
.dac_nids
[0];
2269 if (spec
->adc_nids
) {
2270 p
= spec
->stream_analog_capture
;
2272 if (spec
->dyn_adc_switch
)
2273 p
= &dyn_adc_pcm_analog_capture
;
2275 p
= &alc_pcm_analog_capture
;
2277 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] = *p
;
2278 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
= spec
->adc_nids
[0];
2281 if (spec
->channel_mode
) {
2282 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].channels_max
= 0;
2283 for (i
= 0; i
< spec
->num_channel_mode
; i
++) {
2284 if (spec
->channel_mode
[i
].channels
> info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].channels_max
) {
2285 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].channels_max
= spec
->channel_mode
[i
].channels
;
2291 /* SPDIF for stream index #1 */
2292 if (spec
->multiout
.dig_out_nid
|| spec
->dig_in_nid
) {
2293 snprintf(spec
->stream_name_digital
,
2294 sizeof(spec
->stream_name_digital
),
2295 "%s Digital", codec
->chip_name
);
2296 codec
->num_pcms
= 2;
2297 codec
->slave_dig_outs
= spec
->multiout
.slave_dig_outs
;
2298 info
= spec
->pcm_rec
+ 1;
2299 info
->name
= spec
->stream_name_digital
;
2300 if (spec
->dig_out_type
)
2301 info
->pcm_type
= spec
->dig_out_type
;
2303 info
->pcm_type
= HDA_PCM_TYPE_SPDIF
;
2304 if (spec
->multiout
.dig_out_nid
) {
2305 p
= spec
->stream_digital_playback
;
2307 p
= &alc_pcm_digital_playback
;
2308 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] = *p
;
2309 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
= spec
->multiout
.dig_out_nid
;
2311 if (spec
->dig_in_nid
) {
2312 p
= spec
->stream_digital_capture
;
2314 p
= &alc_pcm_digital_capture
;
2315 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] = *p
;
2316 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
= spec
->dig_in_nid
;
2318 /* FIXME: do we need this for all Realtek codec models? */
2319 codec
->spdif_status_reset
= 1;
2322 if (spec
->no_analog
)
2325 /* If the use of more than one ADC is requested for the current
2326 * model, configure a second analog capture-only PCM.
2328 have_multi_adcs
= (spec
->num_adc_nids
> 1) &&
2329 !spec
->dyn_adc_switch
&& !spec
->auto_mic
&&
2330 (!spec
->input_mux
|| spec
->input_mux
->num_items
> 1);
2331 /* Additional Analaog capture for index #2 */
2332 if (spec
->alt_dac_nid
|| have_multi_adcs
) {
2333 codec
->num_pcms
= 3;
2334 info
= spec
->pcm_rec
+ 2;
2335 info
->name
= spec
->stream_name_analog
;
2336 if (spec
->alt_dac_nid
) {
2337 p
= spec
->stream_analog_alt_playback
;
2339 p
= &alc_pcm_analog_alt_playback
;
2340 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] = *p
;
2341 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
=
2344 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] =
2345 alc_pcm_null_stream
;
2346 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
= 0;
2348 if (have_multi_adcs
) {
2349 p
= spec
->stream_analog_alt_capture
;
2351 p
= &alc_pcm_analog_alt_capture
;
2352 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] = *p
;
2353 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
=
2355 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].substreams
=
2356 spec
->num_adc_nids
- 1;
2358 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] =
2359 alc_pcm_null_stream
;
2360 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
= 0;
2367 static inline void alc_shutup(struct hda_codec
*codec
)
2369 struct alc_spec
*spec
= codec
->spec
;
2371 if (spec
&& spec
->shutup
)
2372 spec
->shutup(codec
);
2373 snd_hda_shutup_pins(codec
);
2376 static void alc_free_kctls(struct hda_codec
*codec
)
2378 struct alc_spec
*spec
= codec
->spec
;
2380 if (spec
->kctls
.list
) {
2381 struct snd_kcontrol_new
*kctl
= spec
->kctls
.list
;
2383 for (i
= 0; i
< spec
->kctls
.used
; i
++)
2384 kfree(kctl
[i
].name
);
2386 snd_array_free(&spec
->kctls
);
2389 static void alc_free(struct hda_codec
*codec
)
2391 struct alc_spec
*spec
= codec
->spec
;
2397 snd_hda_input_jack_free(codec
);
2398 alc_free_kctls(codec
);
2400 snd_hda_detach_beep_device(codec
);
2403 #ifdef CONFIG_SND_HDA_POWER_SAVE
2404 static void alc_power_eapd(struct hda_codec
*codec
)
2406 alc_auto_setup_eapd(codec
, false);
2409 static int alc_suspend(struct hda_codec
*codec
, pm_message_t state
)
2411 struct alc_spec
*spec
= codec
->spec
;
2413 if (spec
&& spec
->power_hook
)
2414 spec
->power_hook(codec
);
2420 static int alc_resume(struct hda_codec
*codec
)
2422 msleep(150); /* to avoid pop noise */
2423 codec
->patch_ops
.init(codec
);
2424 snd_hda_codec_resume_amp(codec
);
2425 snd_hda_codec_resume_cache(codec
);
2426 hda_call_check_power_status(codec
, 0x01);
2433 static const struct hda_codec_ops alc_patch_ops
= {
2434 .build_controls
= alc_build_controls
,
2435 .build_pcms
= alc_build_pcms
,
2438 .unsol_event
= alc_unsol_event
,
2440 .resume
= alc_resume
,
2442 #ifdef CONFIG_SND_HDA_POWER_SAVE
2443 .suspend
= alc_suspend
,
2444 .check_power_status
= alc_check_power_status
,
2446 .reboot_notify
= alc_shutup
,
2449 /* replace the codec chip_name with the given string */
2450 static int alc_codec_rename(struct hda_codec
*codec
, const char *name
)
2452 kfree(codec
->chip_name
);
2453 codec
->chip_name
= kstrdup(name
, GFP_KERNEL
);
2454 if (!codec
->chip_name
) {
2462 * Automatic parse of I/O pins from the BIOS configuration
2467 ALC_CTL_WIDGET_MUTE
,
2470 static const struct snd_kcontrol_new alc_control_templates
[] = {
2471 HDA_CODEC_VOLUME(NULL
, 0, 0, 0),
2472 HDA_CODEC_MUTE(NULL
, 0, 0, 0),
2473 HDA_BIND_MUTE(NULL
, 0, 0, 0),
2476 /* add dynamic controls */
2477 static int add_control(struct alc_spec
*spec
, int type
, const char *name
,
2478 int cidx
, unsigned long val
)
2480 struct snd_kcontrol_new
*knew
;
2482 knew
= alc_kcontrol_new(spec
);
2485 *knew
= alc_control_templates
[type
];
2486 knew
->name
= kstrdup(name
, GFP_KERNEL
);
2490 if (get_amp_nid_(val
))
2491 knew
->subdevice
= HDA_SUBDEV_AMP_FLAG
;
2492 knew
->private_value
= val
;
2496 static int add_control_with_pfx(struct alc_spec
*spec
, int type
,
2497 const char *pfx
, const char *dir
,
2498 const char *sfx
, int cidx
, unsigned long val
)
2501 snprintf(name
, sizeof(name
), "%s %s %s", pfx
, dir
, sfx
);
2502 return add_control(spec
, type
, name
, cidx
, val
);
2505 #define add_pb_vol_ctrl(spec, type, pfx, val) \
2506 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2507 #define add_pb_sw_ctrl(spec, type, pfx, val) \
2508 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2509 #define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2510 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2511 #define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2512 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
2514 static const char *alc_get_line_out_pfx(struct alc_spec
*spec
, int ch
,
2515 bool can_be_master
, int *index
)
2517 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
2518 static const char * const chname
[4] = {
2519 "Front", "Surround", NULL
/*CLFE*/, "Side"
2523 if (cfg
->line_outs
== 1 && !spec
->multi_ios
&&
2524 !cfg
->hp_outs
&& !cfg
->speaker_outs
&& can_be_master
)
2527 switch (cfg
->line_out_type
) {
2528 case AUTO_PIN_SPEAKER_OUT
:
2529 if (cfg
->line_outs
== 1)
2532 case AUTO_PIN_HP_OUT
:
2533 /* for multi-io case, only the primary out */
2534 if (ch
&& spec
->multi_ios
)
2539 if (cfg
->line_outs
== 1 && !spec
->multi_ios
)
2546 /* create input playback/capture controls for the given pin */
2547 static int new_analog_input(struct alc_spec
*spec
, hda_nid_t pin
,
2548 const char *ctlname
, int ctlidx
,
2549 int idx
, hda_nid_t mix_nid
)
2553 err
= __add_pb_vol_ctrl(spec
, ALC_CTL_WIDGET_VOL
, ctlname
, ctlidx
,
2554 HDA_COMPOSE_AMP_VAL(mix_nid
, 3, idx
, HDA_INPUT
));
2557 err
= __add_pb_sw_ctrl(spec
, ALC_CTL_WIDGET_MUTE
, ctlname
, ctlidx
,
2558 HDA_COMPOSE_AMP_VAL(mix_nid
, 3, idx
, HDA_INPUT
));
2564 static int alc_is_input_pin(struct hda_codec
*codec
, hda_nid_t nid
)
2566 unsigned int pincap
= snd_hda_query_pin_caps(codec
, nid
);
2567 return (pincap
& AC_PINCAP_IN
) != 0;
2570 /* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
2571 static int alc_auto_fill_adc_caps(struct hda_codec
*codec
)
2573 struct alc_spec
*spec
= codec
->spec
;
2575 hda_nid_t
*adc_nids
= spec
->private_adc_nids
;
2576 hda_nid_t
*cap_nids
= spec
->private_capsrc_nids
;
2577 int max_nums
= ARRAY_SIZE(spec
->private_adc_nids
);
2578 bool indep_capsrc
= false;
2581 nid
= codec
->start_nid
;
2582 for (i
= 0; i
< codec
->num_nodes
; i
++, nid
++) {
2584 const hda_nid_t
*list
;
2585 unsigned int caps
= get_wcaps(codec
, nid
);
2586 int type
= get_wcaps_type(caps
);
2588 if (type
!= AC_WID_AUD_IN
|| (caps
& AC_WCAP_DIGITAL
))
2590 adc_nids
[nums
] = nid
;
2591 cap_nids
[nums
] = nid
;
2595 type
= get_wcaps_type(get_wcaps(codec
, src
));
2596 if (type
== AC_WID_PIN
)
2598 if (type
== AC_WID_AUD_SEL
) {
2599 cap_nids
[nums
] = src
;
2600 indep_capsrc
= true;
2603 n
= snd_hda_get_conn_list(codec
, src
, &list
);
2605 cap_nids
[nums
] = src
;
2606 indep_capsrc
= true;
2612 if (++nums
>= max_nums
)
2615 spec
->adc_nids
= spec
->private_adc_nids
;
2616 spec
->capsrc_nids
= spec
->private_capsrc_nids
;
2617 spec
->num_adc_nids
= nums
;
2621 /* create playback/capture controls for input pins */
2622 static int alc_auto_create_input_ctls(struct hda_codec
*codec
)
2624 struct alc_spec
*spec
= codec
->spec
;
2625 const struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
2626 hda_nid_t mixer
= spec
->mixer_nid
;
2627 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
2629 int i
, c
, err
, idx
, type_idx
= 0;
2630 const char *prev_label
= NULL
;
2632 num_adcs
= alc_auto_fill_adc_caps(codec
);
2636 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
2640 pin
= cfg
->inputs
[i
].pin
;
2641 if (!alc_is_input_pin(codec
, pin
))
2644 label
= hda_get_autocfg_input_label(codec
, cfg
, i
);
2645 if (prev_label
&& !strcmp(label
, prev_label
))
2652 idx
= get_connection_index(codec
, mixer
, pin
);
2654 err
= new_analog_input(spec
, pin
,
2662 for (c
= 0; c
< num_adcs
; c
++) {
2663 hda_nid_t cap
= spec
->capsrc_nids
?
2664 spec
->capsrc_nids
[c
] : spec
->adc_nids
[c
];
2665 idx
= get_connection_index(codec
, cap
, pin
);
2667 spec
->imux_pins
[imux
->num_items
] = pin
;
2668 snd_hda_add_imux_item(imux
, label
, idx
, NULL
);
2674 spec
->num_mux_defs
= 1;
2675 spec
->input_mux
= imux
;
2680 static void alc_set_pin_output(struct hda_codec
*codec
, hda_nid_t nid
,
2681 unsigned int pin_type
)
2683 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_PIN_WIDGET_CONTROL
,
2686 if (nid_has_mute(codec
, nid
, HDA_OUTPUT
))
2687 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
2691 static int get_pin_type(int line_out_type
)
2693 if (line_out_type
== AUTO_PIN_HP_OUT
)
2699 static void alc_auto_init_analog_input(struct hda_codec
*codec
)
2701 struct alc_spec
*spec
= codec
->spec
;
2702 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
2705 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
2706 hda_nid_t nid
= cfg
->inputs
[i
].pin
;
2707 if (alc_is_input_pin(codec
, nid
)) {
2708 alc_set_input_pin(codec
, nid
, cfg
->inputs
[i
].type
);
2709 if (get_wcaps(codec
, nid
) & AC_WCAP_OUT_AMP
)
2710 snd_hda_codec_write(codec
, nid
, 0,
2711 AC_VERB_SET_AMP_GAIN_MUTE
,
2716 /* mute all loopback inputs */
2717 if (spec
->mixer_nid
) {
2718 int nums
= snd_hda_get_conn_list(codec
, spec
->mixer_nid
, NULL
);
2719 for (i
= 0; i
< nums
; i
++)
2720 snd_hda_codec_write(codec
, spec
->mixer_nid
, 0,
2721 AC_VERB_SET_AMP_GAIN_MUTE
,
2726 /* convert from MIX nid to DAC */
2727 static hda_nid_t
alc_auto_mix_to_dac(struct hda_codec
*codec
, hda_nid_t nid
)
2732 if (get_wcaps_type(get_wcaps(codec
, nid
)) == AC_WID_AUD_OUT
)
2734 num
= snd_hda_get_connections(codec
, nid
, list
, ARRAY_SIZE(list
));
2735 for (i
= 0; i
< num
; i
++) {
2736 if (get_wcaps_type(get_wcaps(codec
, list
[i
])) == AC_WID_AUD_OUT
)
2742 /* go down to the selector widget before the mixer */
2743 static hda_nid_t
alc_go_down_to_selector(struct hda_codec
*codec
, hda_nid_t pin
)
2746 int num
= snd_hda_get_connections(codec
, pin
, srcs
,
2749 get_wcaps_type(get_wcaps(codec
, srcs
[0])) != AC_WID_AUD_SEL
)
2754 /* get MIX nid connected to the given pin targeted to DAC */
2755 static hda_nid_t
alc_auto_dac_to_mix(struct hda_codec
*codec
, hda_nid_t pin
,
2761 pin
= alc_go_down_to_selector(codec
, pin
);
2762 num
= snd_hda_get_connections(codec
, pin
, mix
, ARRAY_SIZE(mix
));
2763 for (i
= 0; i
< num
; i
++) {
2764 if (alc_auto_mix_to_dac(codec
, mix
[i
]) == dac
)
2770 /* select the connection from pin to DAC if needed */
2771 static int alc_auto_select_dac(struct hda_codec
*codec
, hda_nid_t pin
,
2777 pin
= alc_go_down_to_selector(codec
, pin
);
2778 num
= snd_hda_get_connections(codec
, pin
, mix
, ARRAY_SIZE(mix
));
2781 for (i
= 0; i
< num
; i
++) {
2782 if (alc_auto_mix_to_dac(codec
, mix
[i
]) == dac
) {
2783 snd_hda_codec_update_cache(codec
, pin
, 0,
2784 AC_VERB_SET_CONNECT_SEL
, i
);
2791 /* look for an empty DAC slot */
2792 static hda_nid_t
alc_auto_look_for_dac(struct hda_codec
*codec
, hda_nid_t pin
)
2794 struct alc_spec
*spec
= codec
->spec
;
2798 pin
= alc_go_down_to_selector(codec
, pin
);
2799 num
= snd_hda_get_connections(codec
, pin
, srcs
, ARRAY_SIZE(srcs
));
2800 for (i
= 0; i
< num
; i
++) {
2801 hda_nid_t nid
= alc_auto_mix_to_dac(codec
, srcs
[i
]);
2804 if (found_in_nid_list(nid
, spec
->multiout
.dac_nids
,
2805 spec
->multiout
.num_dacs
))
2807 if (spec
->multiout
.hp_nid
== nid
)
2809 if (found_in_nid_list(nid
, spec
->multiout
.extra_out_nid
,
2810 ARRAY_SIZE(spec
->multiout
.extra_out_nid
)))
2817 static hda_nid_t
get_dac_if_single(struct hda_codec
*codec
, hda_nid_t pin
)
2819 hda_nid_t sel
= alc_go_down_to_selector(codec
, pin
);
2820 if (snd_hda_get_conn_list(codec
, sel
, NULL
) == 1)
2821 return alc_auto_look_for_dac(codec
, pin
);
2825 /* fill in the dac_nids table from the parsed pin configuration */
2826 static int alc_auto_fill_dac_nids(struct hda_codec
*codec
)
2828 struct alc_spec
*spec
= codec
->spec
;
2829 const struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
2830 bool redone
= false;
2834 /* set num_dacs once to full for alc_auto_look_for_dac() */
2835 spec
->multiout
.num_dacs
= cfg
->line_outs
;
2836 spec
->multiout
.hp_nid
= 0;
2837 spec
->multiout
.extra_out_nid
[0] = 0;
2838 memset(spec
->private_dac_nids
, 0, sizeof(spec
->private_dac_nids
));
2839 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
2841 /* fill hard-wired DACs first */
2843 for (i
= 0; i
< cfg
->line_outs
; i
++)
2844 spec
->private_dac_nids
[i
] =
2845 get_dac_if_single(codec
, cfg
->line_out_pins
[i
]);
2847 spec
->multiout
.hp_nid
=
2848 get_dac_if_single(codec
, cfg
->hp_pins
[0]);
2849 if (cfg
->speaker_outs
)
2850 spec
->multiout
.extra_out_nid
[0] =
2851 get_dac_if_single(codec
, cfg
->speaker_pins
[0]);
2854 for (i
= 0; i
< cfg
->line_outs
; i
++) {
2855 hda_nid_t pin
= cfg
->line_out_pins
[i
];
2856 if (spec
->private_dac_nids
[i
])
2858 spec
->private_dac_nids
[i
] = alc_auto_look_for_dac(codec
, pin
);
2859 if (!spec
->private_dac_nids
[i
] && !redone
) {
2860 /* if we can't find primary DACs, re-probe without
2861 * checking the hard-wired DACs
2868 /* re-count num_dacs and squash invalid entries */
2869 spec
->multiout
.num_dacs
= 0;
2870 for (i
= 0; i
< cfg
->line_outs
; i
++) {
2871 if (spec
->private_dac_nids
[i
])
2872 spec
->multiout
.num_dacs
++;
2874 memmove(spec
->private_dac_nids
+ i
,
2875 spec
->private_dac_nids
+ i
+ 1,
2876 sizeof(hda_nid_t
) * (cfg
->line_outs
- i
- 1));
2879 if (cfg
->hp_outs
&& !spec
->multiout
.hp_nid
)
2880 spec
->multiout
.hp_nid
=
2881 alc_auto_look_for_dac(codec
, cfg
->hp_pins
[0]);
2882 if (cfg
->speaker_outs
&& !spec
->multiout
.extra_out_nid
[0])
2883 spec
->multiout
.extra_out_nid
[0] =
2884 alc_auto_look_for_dac(codec
, cfg
->speaker_pins
[0]);
2889 static int alc_auto_add_vol_ctl(struct hda_codec
*codec
,
2890 const char *pfx
, int cidx
,
2891 hda_nid_t nid
, unsigned int chs
)
2895 return __add_pb_vol_ctrl(codec
->spec
, ALC_CTL_WIDGET_VOL
, pfx
, cidx
,
2896 HDA_COMPOSE_AMP_VAL(nid
, chs
, 0, HDA_OUTPUT
));
2899 #define alc_auto_add_stereo_vol(codec, pfx, cidx, nid) \
2900 alc_auto_add_vol_ctl(codec, pfx, cidx, nid, 3)
2902 /* create a mute-switch for the given mixer widget;
2903 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
2905 static int alc_auto_add_sw_ctl(struct hda_codec
*codec
,
2906 const char *pfx
, int cidx
,
2907 hda_nid_t nid
, unsigned int chs
)
2914 wid_type
= get_wcaps_type(get_wcaps(codec
, nid
));
2915 if (wid_type
== AC_WID_PIN
|| wid_type
== AC_WID_AUD_OUT
) {
2916 type
= ALC_CTL_WIDGET_MUTE
;
2917 val
= HDA_COMPOSE_AMP_VAL(nid
, chs
, 0, HDA_OUTPUT
);
2918 } else if (snd_hda_get_conn_list(codec
, nid
, NULL
) == 1) {
2919 type
= ALC_CTL_WIDGET_MUTE
;
2920 val
= HDA_COMPOSE_AMP_VAL(nid
, chs
, 0, HDA_INPUT
);
2922 type
= ALC_CTL_BIND_MUTE
;
2923 val
= HDA_COMPOSE_AMP_VAL(nid
, chs
, 2, HDA_INPUT
);
2925 return __add_pb_sw_ctrl(codec
->spec
, type
, pfx
, cidx
, val
);
2928 #define alc_auto_add_stereo_sw(codec, pfx, cidx, nid) \
2929 alc_auto_add_sw_ctl(codec, pfx, cidx, nid, 3)
2931 static hda_nid_t
alc_look_for_out_mute_nid(struct hda_codec
*codec
,
2932 hda_nid_t pin
, hda_nid_t dac
)
2934 hda_nid_t mix
= alc_auto_dac_to_mix(codec
, pin
, dac
);
2935 if (nid_has_mute(codec
, pin
, HDA_OUTPUT
))
2937 else if (mix
&& nid_has_mute(codec
, mix
, HDA_INPUT
))
2939 else if (nid_has_mute(codec
, dac
, HDA_OUTPUT
))
2944 static hda_nid_t
alc_look_for_out_vol_nid(struct hda_codec
*codec
,
2945 hda_nid_t pin
, hda_nid_t dac
)
2947 hda_nid_t mix
= alc_auto_dac_to_mix(codec
, pin
, dac
);
2948 if (nid_has_volume(codec
, dac
, HDA_OUTPUT
))
2950 else if (nid_has_volume(codec
, mix
, HDA_OUTPUT
))
2952 else if (nid_has_volume(codec
, pin
, HDA_OUTPUT
))
2957 /* add playback controls from the parsed DAC table */
2958 static int alc_auto_create_multi_out_ctls(struct hda_codec
*codec
,
2959 const struct auto_pin_cfg
*cfg
)
2961 struct alc_spec
*spec
= codec
->spec
;
2962 int i
, err
, noutputs
;
2964 noutputs
= cfg
->line_outs
;
2965 if (spec
->multi_ios
> 0)
2966 noutputs
+= spec
->multi_ios
;
2968 for (i
= 0; i
< noutputs
; i
++) {
2974 dac
= spec
->multiout
.dac_nids
[i
];
2977 if (i
>= cfg
->line_outs
)
2978 pin
= spec
->multi_io
[i
- 1].pin
;
2980 pin
= cfg
->line_out_pins
[i
];
2982 sw
= alc_look_for_out_mute_nid(codec
, pin
, dac
);
2983 vol
= alc_look_for_out_vol_nid(codec
, pin
, dac
);
2984 name
= alc_get_line_out_pfx(spec
, i
, true, &index
);
2987 err
= alc_auto_add_vol_ctl(codec
, "Center", 0, vol
, 1);
2990 err
= alc_auto_add_vol_ctl(codec
, "LFE", 0, vol
, 2);
2993 err
= alc_auto_add_sw_ctl(codec
, "Center", 0, sw
, 1);
2996 err
= alc_auto_add_sw_ctl(codec
, "LFE", 0, sw
, 2);
3000 err
= alc_auto_add_stereo_vol(codec
, name
, index
, vol
);
3003 err
= alc_auto_add_stereo_sw(codec
, name
, index
, sw
);
3011 /* add playback controls for speaker and HP outputs */
3012 static int alc_auto_create_extra_out(struct hda_codec
*codec
, hda_nid_t pin
,
3013 hda_nid_t dac
, const char *pfx
)
3015 struct alc_spec
*spec
= codec
->spec
;
3022 /* the corresponding DAC is already occupied */
3023 if (!(get_wcaps(codec
, pin
) & AC_WCAP_OUT_AMP
))
3024 return 0; /* no way */
3025 /* create a switch only */
3026 return add_pb_sw_ctrl(spec
, ALC_CTL_WIDGET_MUTE
, pfx
,
3027 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
3030 sw
= alc_look_for_out_mute_nid(codec
, pin
, dac
);
3031 vol
= alc_look_for_out_vol_nid(codec
, pin
, dac
);
3032 err
= alc_auto_add_stereo_vol(codec
, pfx
, 0, vol
);
3035 err
= alc_auto_add_stereo_sw(codec
, pfx
, 0, sw
);
3041 static int alc_auto_create_hp_out(struct hda_codec
*codec
)
3043 struct alc_spec
*spec
= codec
->spec
;
3044 return alc_auto_create_extra_out(codec
, spec
->autocfg
.hp_pins
[0],
3045 spec
->multiout
.hp_nid
,
3049 static int alc_auto_create_speaker_out(struct hda_codec
*codec
)
3051 struct alc_spec
*spec
= codec
->spec
;
3052 return alc_auto_create_extra_out(codec
, spec
->autocfg
.speaker_pins
[0],
3053 spec
->multiout
.extra_out_nid
[0],
3057 static void alc_auto_set_output_and_unmute(struct hda_codec
*codec
,
3058 hda_nid_t pin
, int pin_type
,
3062 hda_nid_t nid
, mix
= 0;
3063 hda_nid_t srcs
[HDA_MAX_CONNECTIONS
];
3065 alc_set_pin_output(codec
, pin
, pin_type
);
3066 nid
= alc_go_down_to_selector(codec
, pin
);
3067 num
= snd_hda_get_connections(codec
, nid
, srcs
, ARRAY_SIZE(srcs
));
3068 for (i
= 0; i
< num
; i
++) {
3069 if (alc_auto_mix_to_dac(codec
, srcs
[i
]) != dac
)
3077 /* need the manual connection? */
3079 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_CONNECT_SEL
, i
);
3080 /* unmute mixer widget inputs */
3081 if (nid_has_mute(codec
, mix
, HDA_INPUT
)) {
3082 snd_hda_codec_write(codec
, mix
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
3084 snd_hda_codec_write(codec
, mix
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
3087 /* initialize volume */
3088 nid
= alc_look_for_out_vol_nid(codec
, pin
, dac
);
3090 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
3093 /* unmute DAC if it's not assigned to a mixer */
3094 nid
= alc_look_for_out_mute_nid(codec
, pin
, dac
);
3095 if (nid
== mix
&& nid_has_mute(codec
, dac
, HDA_OUTPUT
))
3096 snd_hda_codec_write(codec
, dac
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
3100 static void alc_auto_init_multi_out(struct hda_codec
*codec
)
3102 struct alc_spec
*spec
= codec
->spec
;
3103 int pin_type
= get_pin_type(spec
->autocfg
.line_out_type
);
3106 for (i
= 0; i
<= HDA_SIDE
; i
++) {
3107 hda_nid_t nid
= spec
->autocfg
.line_out_pins
[i
];
3109 alc_auto_set_output_and_unmute(codec
, nid
, pin_type
,
3110 spec
->multiout
.dac_nids
[i
]);
3114 static void alc_auto_init_extra_out(struct hda_codec
*codec
)
3116 struct alc_spec
*spec
= codec
->spec
;
3119 pin
= spec
->autocfg
.hp_pins
[0];
3121 dac
= spec
->multiout
.hp_nid
;
3123 dac
= spec
->multiout
.dac_nids
[0];
3124 alc_auto_set_output_and_unmute(codec
, pin
, PIN_HP
, dac
);
3126 pin
= spec
->autocfg
.speaker_pins
[0];
3128 dac
= spec
->multiout
.extra_out_nid
[0];
3130 dac
= spec
->multiout
.dac_nids
[0];
3131 alc_auto_set_output_and_unmute(codec
, pin
, PIN_OUT
, dac
);
3138 static int alc_auto_fill_multi_ios(struct hda_codec
*codec
,
3139 unsigned int location
)
3141 struct alc_spec
*spec
= codec
->spec
;
3142 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
3143 int type
, i
, num_pins
= 0;
3145 for (type
= AUTO_PIN_LINE_IN
; type
>= AUTO_PIN_MIC
; type
--) {
3146 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
3147 hda_nid_t nid
= cfg
->inputs
[i
].pin
;
3149 unsigned int defcfg
, caps
;
3150 if (cfg
->inputs
[i
].type
!= type
)
3152 defcfg
= snd_hda_codec_get_pincfg(codec
, nid
);
3153 if (get_defcfg_connect(defcfg
) != AC_JACK_PORT_COMPLEX
)
3155 if (location
&& get_defcfg_location(defcfg
) != location
)
3157 caps
= snd_hda_query_pin_caps(codec
, nid
);
3158 if (!(caps
& AC_PINCAP_OUT
))
3160 dac
= alc_auto_look_for_dac(codec
, nid
);
3163 spec
->multi_io
[num_pins
].pin
= nid
;
3164 spec
->multi_io
[num_pins
].dac
= dac
;
3166 spec
->private_dac_nids
[spec
->multiout
.num_dacs
++] = dac
;
3169 spec
->multiout
.num_dacs
= 1;
3175 static int alc_auto_ch_mode_info(struct snd_kcontrol
*kcontrol
,
3176 struct snd_ctl_elem_info
*uinfo
)
3178 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3179 struct alc_spec
*spec
= codec
->spec
;
3181 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
3183 uinfo
->value
.enumerated
.items
= spec
->multi_ios
+ 1;
3184 if (uinfo
->value
.enumerated
.item
> spec
->multi_ios
)
3185 uinfo
->value
.enumerated
.item
= spec
->multi_ios
;
3186 sprintf(uinfo
->value
.enumerated
.name
, "%dch",
3187 (uinfo
->value
.enumerated
.item
+ 1) * 2);
3191 static int alc_auto_ch_mode_get(struct snd_kcontrol
*kcontrol
,
3192 struct snd_ctl_elem_value
*ucontrol
)
3194 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3195 struct alc_spec
*spec
= codec
->spec
;
3196 ucontrol
->value
.enumerated
.item
[0] = (spec
->ext_channel_count
- 1) / 2;
3200 static int alc_set_multi_io(struct hda_codec
*codec
, int idx
, bool output
)
3202 struct alc_spec
*spec
= codec
->spec
;
3203 hda_nid_t nid
= spec
->multi_io
[idx
].pin
;
3205 if (!spec
->multi_io
[idx
].ctl_in
)
3206 spec
->multi_io
[idx
].ctl_in
=
3207 snd_hda_codec_read(codec
, nid
, 0,
3208 AC_VERB_GET_PIN_WIDGET_CONTROL
, 0);
3210 snd_hda_codec_update_cache(codec
, nid
, 0,
3211 AC_VERB_SET_PIN_WIDGET_CONTROL
,
3213 if (get_wcaps(codec
, nid
) & AC_WCAP_OUT_AMP
)
3214 snd_hda_codec_amp_stereo(codec
, nid
, HDA_OUTPUT
, 0,
3216 alc_auto_select_dac(codec
, nid
, spec
->multi_io
[idx
].dac
);
3218 if (get_wcaps(codec
, nid
) & AC_WCAP_OUT_AMP
)
3219 snd_hda_codec_amp_stereo(codec
, nid
, HDA_OUTPUT
, 0,
3220 HDA_AMP_MUTE
, HDA_AMP_MUTE
);
3221 snd_hda_codec_update_cache(codec
, nid
, 0,
3222 AC_VERB_SET_PIN_WIDGET_CONTROL
,
3223 spec
->multi_io
[idx
].ctl_in
);
3228 static int alc_auto_ch_mode_put(struct snd_kcontrol
*kcontrol
,
3229 struct snd_ctl_elem_value
*ucontrol
)
3231 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3232 struct alc_spec
*spec
= codec
->spec
;
3235 ch
= ucontrol
->value
.enumerated
.item
[0];
3236 if (ch
< 0 || ch
> spec
->multi_ios
)
3238 if (ch
== (spec
->ext_channel_count
- 1) / 2)
3240 spec
->ext_channel_count
= (ch
+ 1) * 2;
3241 for (i
= 0; i
< spec
->multi_ios
; i
++)
3242 alc_set_multi_io(codec
, i
, i
< ch
);
3243 spec
->multiout
.max_channels
= spec
->ext_channel_count
;
3244 if (spec
->need_dac_fix
&& !spec
->const_channel_count
)
3245 spec
->multiout
.num_dacs
= spec
->multiout
.max_channels
/ 2;
3249 static const struct snd_kcontrol_new alc_auto_channel_mode_enum
= {
3250 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
3251 .name
= "Channel Mode",
3252 .info
= alc_auto_ch_mode_info
,
3253 .get
= alc_auto_ch_mode_get
,
3254 .put
= alc_auto_ch_mode_put
,
3257 static int alc_auto_add_multi_channel_mode(struct hda_codec
*codec
,
3258 int (*fill_dac
)(struct hda_codec
*))
3260 struct alc_spec
*spec
= codec
->spec
;
3261 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
3262 unsigned int location
, defcfg
;
3265 if (cfg
->line_out_type
== AUTO_PIN_SPEAKER_OUT
&& cfg
->hp_outs
== 1) {
3266 /* use HP as primary out */
3267 cfg
->speaker_outs
= cfg
->line_outs
;
3268 memcpy(cfg
->speaker_pins
, cfg
->line_out_pins
,
3269 sizeof(cfg
->speaker_pins
));
3270 cfg
->line_outs
= cfg
->hp_outs
;
3271 memcpy(cfg
->line_out_pins
, cfg
->hp_pins
, sizeof(cfg
->hp_pins
));
3273 memset(cfg
->hp_pins
, 0, sizeof(cfg
->hp_pins
));
3274 cfg
->line_out_type
= AUTO_PIN_HP_OUT
;
3278 if (cfg
->line_outs
!= 1 ||
3279 cfg
->line_out_type
== AUTO_PIN_SPEAKER_OUT
)
3282 defcfg
= snd_hda_codec_get_pincfg(codec
, cfg
->line_out_pins
[0]);
3283 location
= get_defcfg_location(defcfg
);
3285 num_pins
= alc_auto_fill_multi_ios(codec
, location
);
3287 struct snd_kcontrol_new
*knew
;
3289 knew
= alc_kcontrol_new(spec
);
3292 *knew
= alc_auto_channel_mode_enum
;
3293 knew
->name
= kstrdup("Channel Mode", GFP_KERNEL
);
3297 spec
->multi_ios
= num_pins
;
3298 spec
->ext_channel_count
= 2;
3299 spec
->multiout
.num_dacs
= num_pins
+ 1;
3304 /* filter out invalid adc_nids (and capsrc_nids) that don't give all
3307 static void alc_remove_invalid_adc_nids(struct hda_codec
*codec
)
3309 struct alc_spec
*spec
= codec
->spec
;
3310 const struct hda_input_mux
*imux
;
3311 hda_nid_t adc_nids
[ARRAY_SIZE(spec
->private_adc_nids
)];
3312 hda_nid_t capsrc_nids
[ARRAY_SIZE(spec
->private_adc_nids
)];
3315 imux
= spec
->input_mux
;
3318 if (spec
->dyn_adc_switch
)
3322 for (n
= 0; n
< spec
->num_adc_nids
; n
++) {
3323 hda_nid_t cap
= spec
->private_capsrc_nids
[n
];
3324 int num_conns
= snd_hda_get_conn_list(codec
, cap
, NULL
);
3325 for (i
= 0; i
< imux
->num_items
; i
++) {
3326 hda_nid_t pin
= spec
->imux_pins
[i
];
3328 if (get_connection_index(codec
, cap
, pin
) < 0)
3330 } else if (num_conns
<= imux
->items
[i
].index
)
3333 if (i
>= imux
->num_items
) {
3334 adc_nids
[nums
] = spec
->private_adc_nids
[n
];
3335 capsrc_nids
[nums
++] = cap
;
3339 /* check whether ADC-switch is possible */
3340 if (!alc_check_dyn_adc_switch(codec
)) {
3341 printk(KERN_WARNING
"hda_codec: %s: no valid ADC found;"
3342 " using fallback 0x%x\n",
3343 codec
->chip_name
, spec
->private_adc_nids
[0]);
3344 spec
->num_adc_nids
= 1;
3348 } else if (nums
!= spec
->num_adc_nids
) {
3349 memcpy(spec
->private_adc_nids
, adc_nids
,
3350 nums
* sizeof(hda_nid_t
));
3351 memcpy(spec
->private_capsrc_nids
, capsrc_nids
,
3352 nums
* sizeof(hda_nid_t
));
3353 spec
->num_adc_nids
= nums
;
3357 alc_auto_mic_check_imux(codec
); /* check auto-mic setups */
3358 else if (spec
->input_mux
->num_items
== 1)
3359 spec
->num_adc_nids
= 1; /* reduce to a single ADC */
3363 * initialize ADC paths
3365 static void alc_auto_init_adc(struct hda_codec
*codec
, int adc_idx
)
3367 struct alc_spec
*spec
= codec
->spec
;
3370 nid
= spec
->adc_nids
[adc_idx
];
3372 if (nid_has_mute(codec
, nid
, HDA_INPUT
)) {
3373 snd_hda_codec_write(codec
, nid
, 0,
3374 AC_VERB_SET_AMP_GAIN_MUTE
,
3378 if (!spec
->capsrc_nids
)
3380 nid
= spec
->capsrc_nids
[adc_idx
];
3381 if (nid_has_mute(codec
, nid
, HDA_OUTPUT
))
3382 snd_hda_codec_write(codec
, nid
, 0,
3383 AC_VERB_SET_AMP_GAIN_MUTE
,
3387 static void alc_auto_init_input_src(struct hda_codec
*codec
)
3389 struct alc_spec
*spec
= codec
->spec
;
3392 for (c
= 0; c
< spec
->num_adc_nids
; c
++)
3393 alc_auto_init_adc(codec
, c
);
3394 if (spec
->dyn_adc_switch
)
3397 nums
= spec
->num_adc_nids
;
3398 for (c
= 0; c
< nums
; c
++)
3399 alc_mux_select(codec
, 0, spec
->cur_mux
[c
], true);
3402 /* add mic boosts if needed */
3403 static int alc_auto_add_mic_boost(struct hda_codec
*codec
)
3405 struct alc_spec
*spec
= codec
->spec
;
3406 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
3410 const char *prev_label
= NULL
;
3412 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
3413 if (cfg
->inputs
[i
].type
> AUTO_PIN_MIC
)
3415 nid
= cfg
->inputs
[i
].pin
;
3416 if (get_wcaps(codec
, nid
) & AC_WCAP_IN_AMP
) {
3418 char boost_label
[32];
3420 label
= hda_get_autocfg_input_label(codec
, cfg
, i
);
3421 if (prev_label
&& !strcmp(label
, prev_label
))
3427 snprintf(boost_label
, sizeof(boost_label
),
3428 "%s Boost Volume", label
);
3429 err
= add_control(spec
, ALC_CTL_WIDGET_VOL
,
3430 boost_label
, type_idx
,
3431 HDA_COMPOSE_AMP_VAL(nid
, 3, 0, HDA_INPUT
));
3439 /* select or unmute the given capsrc route */
3440 static void select_or_unmute_capsrc(struct hda_codec
*codec
, hda_nid_t cap
,
3443 if (get_wcaps_type(get_wcaps(codec
, cap
)) == AC_WID_AUD_MIX
) {
3444 snd_hda_codec_amp_stereo(codec
, cap
, HDA_INPUT
, idx
,
3446 } else if (snd_hda_get_conn_list(codec
, cap
, NULL
) > 1) {
3447 snd_hda_codec_write_cache(codec
, cap
, 0,
3448 AC_VERB_SET_CONNECT_SEL
, idx
);
3452 /* set the default connection to that pin */
3453 static int init_capsrc_for_pin(struct hda_codec
*codec
, hda_nid_t pin
)
3455 struct alc_spec
*spec
= codec
->spec
;
3460 for (i
= 0; i
< spec
->num_adc_nids
; i
++) {
3461 hda_nid_t cap
= spec
->capsrc_nids
?
3462 spec
->capsrc_nids
[i
] : spec
->adc_nids
[i
];
3465 idx
= get_connection_index(codec
, cap
, pin
);
3468 select_or_unmute_capsrc(codec
, cap
, idx
);
3469 return i
; /* return the found index */
3471 return -1; /* not found */
3474 /* initialize some special cases for input sources */
3475 static void alc_init_special_input_src(struct hda_codec
*codec
)
3477 struct alc_spec
*spec
= codec
->spec
;
3480 for (i
= 0; i
< spec
->autocfg
.num_inputs
; i
++)
3481 init_capsrc_for_pin(codec
, spec
->autocfg
.inputs
[i
].pin
);
3484 /* assign appropriate capture mixers */
3485 static void set_capture_mixer(struct hda_codec
*codec
)
3487 struct alc_spec
*spec
= codec
->spec
;
3488 static const struct snd_kcontrol_new
*caps
[2][3] = {
3489 { alc_capture_mixer_nosrc1
,
3490 alc_capture_mixer_nosrc2
,
3491 alc_capture_mixer_nosrc3
},
3492 { alc_capture_mixer1
,
3494 alc_capture_mixer3
},
3497 /* check whether either of ADC or MUX has a volume control */
3498 if (!nid_has_volume(codec
, spec
->adc_nids
[0], HDA_INPUT
)) {
3499 if (!spec
->capsrc_nids
)
3500 return; /* no volume */
3501 if (!nid_has_volume(codec
, spec
->capsrc_nids
[0], HDA_OUTPUT
))
3502 return; /* no volume in capsrc, too */
3503 spec
->vol_in_capsrc
= 1;
3506 if (spec
->num_adc_nids
> 0) {
3510 if (spec
->input_mux
&& spec
->input_mux
->num_items
> 1)
3512 if (spec
->auto_mic
) {
3515 } else if (spec
->dyn_adc_switch
)
3518 if (spec
->num_adc_nids
> 3)
3519 spec
->num_adc_nids
= 3;
3520 else if (!spec
->num_adc_nids
)
3522 num_adcs
= spec
->num_adc_nids
;
3524 spec
->cap_mixer
= caps
[mux
][num_adcs
- 1];
3529 * standard auto-parser initializations
3531 static void alc_auto_init_std(struct hda_codec
*codec
)
3533 struct alc_spec
*spec
= codec
->spec
;
3534 alc_auto_init_multi_out(codec
);
3535 alc_auto_init_extra_out(codec
);
3536 alc_auto_init_analog_input(codec
);
3537 alc_auto_init_input_src(codec
);
3538 alc_auto_init_digital(codec
);
3539 if (spec
->unsol_event
)
3540 alc_inithook(codec
);
3544 * Digital-beep handlers
3546 #ifdef CONFIG_SND_HDA_INPUT_BEEP
3547 #define set_beep_amp(spec, nid, idx, dir) \
3548 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
3550 static const struct snd_pci_quirk beep_white_list
[] = {
3551 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
3552 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
3553 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
3554 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
3555 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
3559 static inline int has_cdefine_beep(struct hda_codec
*codec
)
3561 struct alc_spec
*spec
= codec
->spec
;
3562 const struct snd_pci_quirk
*q
;
3563 q
= snd_pci_quirk_lookup(codec
->bus
->pci
, beep_white_list
);
3566 return spec
->cdefine
.enable_pcbeep
;
3569 #define set_beep_amp(spec, nid, idx, dir) /* NOP */
3570 #define has_cdefine_beep(codec) 0
3573 /* parse the BIOS configuration and set up the alc_spec */
3574 /* return 1 if successful, 0 if the proper config is not found,
3575 * or a negative error code
3577 static int alc_parse_auto_config(struct hda_codec
*codec
,
3578 const hda_nid_t
*ignore_nids
,
3579 const hda_nid_t
*ssid_nids
)
3581 struct alc_spec
*spec
= codec
->spec
;
3584 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
,
3588 if (!spec
->autocfg
.line_outs
) {
3589 if (spec
->autocfg
.dig_outs
|| spec
->autocfg
.dig_in_pin
) {
3590 spec
->multiout
.max_channels
= 2;
3591 spec
->no_analog
= 1;
3594 return 0; /* can't find valid BIOS pin config */
3596 err
= alc_auto_fill_dac_nids(codec
);
3599 err
= alc_auto_add_multi_channel_mode(codec
, alc_auto_fill_dac_nids
);
3602 err
= alc_auto_create_multi_out_ctls(codec
, &spec
->autocfg
);
3605 err
= alc_auto_create_hp_out(codec
);
3608 err
= alc_auto_create_speaker_out(codec
);
3611 err
= alc_auto_create_input_ctls(codec
);
3615 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
3618 alc_auto_parse_digital(codec
);
3620 if (!spec
->no_analog
)
3621 alc_remove_invalid_adc_nids(codec
);
3624 alc_ssid_check(codec
, ssid_nids
);
3626 if (!spec
->no_analog
) {
3627 alc_auto_check_switches(codec
);
3628 err
= alc_auto_add_mic_boost(codec
);
3633 if (spec
->kctls
.list
)
3634 add_mixer(spec
, spec
->kctls
.list
);
3639 static int alc880_parse_auto_config(struct hda_codec
*codec
)
3641 static const hda_nid_t alc880_ignore
[] = { 0x1d, 0 };
3642 static const hda_nid_t alc880_ssids
[] = { 0x15, 0x1b, 0x14, 0 };
3643 return alc_parse_auto_config(codec
, alc880_ignore
, alc880_ssids
);
3646 #ifdef CONFIG_SND_HDA_POWER_SAVE
3647 static const struct hda_amp_list alc880_loopbacks
[] = {
3648 { 0x0b, HDA_INPUT
, 0 },
3649 { 0x0b, HDA_INPUT
, 1 },
3650 { 0x0b, HDA_INPUT
, 2 },
3651 { 0x0b, HDA_INPUT
, 3 },
3652 { 0x0b, HDA_INPUT
, 4 },
3660 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3661 #define alc_board_config \
3662 snd_hda_check_board_config
3663 #define alc_board_codec_sid_config \
3664 snd_hda_check_board_codec_sid_config
3665 #include "alc_quirks.c"
3667 #define alc_board_config(codec, nums, models, tbl) -1
3668 #define alc_board_codec_sid_config(codec, nums, models, tbl) -1
3669 #define setup_preset(codec, x) /* NOP */
3673 * OK, here we have finally the patch for ALC880
3675 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3676 #include "alc880_quirks.c"
3679 static int patch_alc880(struct hda_codec
*codec
)
3681 struct alc_spec
*spec
;
3685 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
3691 spec
->mixer_nid
= 0x0b;
3692 spec
->need_dac_fix
= 1;
3694 board_config
= alc_board_config(codec
, ALC880_MODEL_LAST
,
3695 alc880_models
, alc880_cfg_tbl
);
3696 if (board_config
< 0) {
3697 printk(KERN_INFO
"hda_codec: %s: BIOS auto-probing.\n",
3699 board_config
= ALC_MODEL_AUTO
;
3702 if (board_config
== ALC_MODEL_AUTO
) {
3703 /* automatic parse from the BIOS config */
3704 err
= alc880_parse_auto_config(codec
);
3709 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3712 "hda_codec: Cannot set up configuration "
3713 "from BIOS. Using 3-stack mode...\n");
3714 board_config
= ALC880_3ST
;
3719 if (board_config
!= ALC_MODEL_AUTO
)
3720 setup_preset(codec
, &alc880_presets
[board_config
]);
3722 if (!spec
->no_analog
&& !spec
->adc_nids
) {
3723 alc_auto_fill_adc_caps(codec
);
3724 alc_rebuild_imux_for_auto_mic(codec
);
3725 alc_remove_invalid_adc_nids(codec
);
3728 if (!spec
->no_analog
&& !spec
->cap_mixer
)
3729 set_capture_mixer(codec
);
3731 if (!spec
->no_analog
) {
3732 err
= snd_hda_attach_beep_device(codec
, 0x1);
3737 set_beep_amp(spec
, 0x0b, 0x05, HDA_INPUT
);
3740 spec
->vmaster_nid
= 0x0c;
3742 codec
->patch_ops
= alc_patch_ops
;
3743 if (board_config
== ALC_MODEL_AUTO
)
3744 spec
->init_hook
= alc_auto_init_std
;
3745 #ifdef CONFIG_SND_HDA_POWER_SAVE
3746 if (!spec
->loopback
.amplist
)
3747 spec
->loopback
.amplist
= alc880_loopbacks
;
3757 static int alc260_parse_auto_config(struct hda_codec
*codec
)
3759 static const hda_nid_t alc260_ignore
[] = { 0x17, 0 };
3760 static const hda_nid_t alc260_ssids
[] = { 0x10, 0x15, 0x0f, 0 };
3761 return alc_parse_auto_config(codec
, alc260_ignore
, alc260_ssids
);
3764 #ifdef CONFIG_SND_HDA_POWER_SAVE
3765 static const struct hda_amp_list alc260_loopbacks
[] = {
3766 { 0x07, HDA_INPUT
, 0 },
3767 { 0x07, HDA_INPUT
, 1 },
3768 { 0x07, HDA_INPUT
, 2 },
3769 { 0x07, HDA_INPUT
, 3 },
3770 { 0x07, HDA_INPUT
, 4 },
3782 static const struct alc_fixup alc260_fixups
[] = {
3783 [PINFIX_HP_DC5750
] = {
3784 .type
= ALC_FIXUP_PINS
,
3785 .v
.pins
= (const struct alc_pincfg
[]) {
3786 { 0x11, 0x90130110 }, /* speaker */
3792 static const struct snd_pci_quirk alc260_fixup_tbl
[] = {
3793 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", PINFIX_HP_DC5750
),
3799 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3800 #include "alc260_quirks.c"
3803 static int patch_alc260(struct hda_codec
*codec
)
3805 struct alc_spec
*spec
;
3806 int err
, board_config
;
3808 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
3814 spec
->mixer_nid
= 0x07;
3816 board_config
= alc_board_config(codec
, ALC260_MODEL_LAST
,
3817 alc260_models
, alc260_cfg_tbl
);
3818 if (board_config
< 0) {
3819 snd_printd(KERN_INFO
"hda_codec: %s: BIOS auto-probing.\n",
3821 board_config
= ALC_MODEL_AUTO
;
3824 if (board_config
== ALC_MODEL_AUTO
) {
3825 alc_pick_fixup(codec
, NULL
, alc260_fixup_tbl
, alc260_fixups
);
3826 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
3829 if (board_config
== ALC_MODEL_AUTO
) {
3830 /* automatic parse from the BIOS config */
3831 err
= alc260_parse_auto_config(codec
);
3836 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3839 "hda_codec: Cannot set up configuration "
3840 "from BIOS. Using base mode...\n");
3841 board_config
= ALC260_BASIC
;
3846 if (board_config
!= ALC_MODEL_AUTO
)
3847 setup_preset(codec
, &alc260_presets
[board_config
]);
3849 if (!spec
->no_analog
&& !spec
->adc_nids
) {
3850 alc_auto_fill_adc_caps(codec
);
3851 alc_rebuild_imux_for_auto_mic(codec
);
3852 alc_remove_invalid_adc_nids(codec
);
3855 if (!spec
->no_analog
&& !spec
->cap_mixer
)
3856 set_capture_mixer(codec
);
3858 if (!spec
->no_analog
) {
3859 err
= snd_hda_attach_beep_device(codec
, 0x1);
3864 set_beep_amp(spec
, 0x07, 0x05, HDA_INPUT
);
3867 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
3869 spec
->vmaster_nid
= 0x08;
3871 codec
->patch_ops
= alc_patch_ops
;
3872 if (board_config
== ALC_MODEL_AUTO
)
3873 spec
->init_hook
= alc_auto_init_std
;
3874 spec
->shutup
= alc_eapd_shutup
;
3875 #ifdef CONFIG_SND_HDA_POWER_SAVE
3876 if (!spec
->loopback
.amplist
)
3877 spec
->loopback
.amplist
= alc260_loopbacks
;
3885 * ALC882/883/885/888/889 support
3887 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
3888 * configuration. Each pin widget can choose any input DACs and a mixer.
3889 * Each ADC is connected from a mixer of all inputs. This makes possible
3890 * 6-channel independent captures.
3892 * In addition, an independent DAC for the multi-playback (not used in this
3895 #ifdef CONFIG_SND_HDA_POWER_SAVE
3896 #define alc882_loopbacks alc880_loopbacks
3903 PINFIX_ABIT_AW9D_MAX
,
3906 PINFIX_ACER_ASPIRE_7736
,
3909 static const struct alc_fixup alc882_fixups
[] = {
3910 [PINFIX_ABIT_AW9D_MAX
] = {
3911 .type
= ALC_FIXUP_PINS
,
3912 .v
.pins
= (const struct alc_pincfg
[]) {
3913 { 0x15, 0x01080104 }, /* side */
3914 { 0x16, 0x01011012 }, /* rear */
3915 { 0x17, 0x01016011 }, /* clfe */
3919 [PINFIX_LENOVO_Y530
] = {
3920 .type
= ALC_FIXUP_PINS
,
3921 .v
.pins
= (const struct alc_pincfg
[]) {
3922 { 0x15, 0x99130112 }, /* rear int speakers */
3923 { 0x16, 0x99130111 }, /* subwoofer */
3927 [PINFIX_PB_M5210
] = {
3928 .type
= ALC_FIXUP_VERBS
,
3929 .v
.verbs
= (const struct hda_verb
[]) {
3930 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_VREF50
},
3934 [PINFIX_ACER_ASPIRE_7736
] = {
3935 .type
= ALC_FIXUP_SKU
,
3936 .v
.sku
= ALC_FIXUP_SKU_IGNORE
,
3940 static const struct snd_pci_quirk alc882_fixup_tbl
[] = {
3941 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", PINFIX_PB_M5210
),
3942 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", PINFIX_LENOVO_Y530
),
3943 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX
),
3944 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", PINFIX_ACER_ASPIRE_7736
),
3949 * BIOS auto configuration
3951 /* almost identical with ALC880 parser... */
3952 static int alc882_parse_auto_config(struct hda_codec
*codec
)
3954 static const hda_nid_t alc882_ignore
[] = { 0x1d, 0 };
3955 static const hda_nid_t alc882_ssids
[] = { 0x15, 0x1b, 0x14, 0 };
3956 return alc_parse_auto_config(codec
, alc882_ignore
, alc882_ssids
);
3961 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3962 #include "alc882_quirks.c"
3965 static int patch_alc882(struct hda_codec
*codec
)
3967 struct alc_spec
*spec
;
3968 int err
, board_config
;
3970 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
3976 spec
->mixer_nid
= 0x0b;
3978 switch (codec
->vendor_id
) {
3983 /* ALC883 and variants */
3984 alc_fix_pll_init(codec
, 0x20, 0x0a, 10);
3988 board_config
= alc_board_config(codec
, ALC882_MODEL_LAST
,
3989 alc882_models
, alc882_cfg_tbl
);
3991 if (board_config
< 0)
3992 board_config
= alc_board_codec_sid_config(codec
,
3993 ALC882_MODEL_LAST
, alc882_models
, alc882_ssid_cfg_tbl
);
3995 if (board_config
< 0) {
3996 printk(KERN_INFO
"hda_codec: %s: BIOS auto-probing.\n",
3998 board_config
= ALC_MODEL_AUTO
;
4001 if (board_config
== ALC_MODEL_AUTO
) {
4002 alc_pick_fixup(codec
, NULL
, alc882_fixup_tbl
, alc882_fixups
);
4003 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
4006 alc_auto_parse_customize_define(codec
);
4008 if (board_config
== ALC_MODEL_AUTO
) {
4009 /* automatic parse from the BIOS config */
4010 err
= alc882_parse_auto_config(codec
);
4015 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4018 "hda_codec: Cannot set up configuration "
4019 "from BIOS. Using base mode...\n");
4020 board_config
= ALC882_3ST_DIG
;
4025 if (board_config
!= ALC_MODEL_AUTO
)
4026 setup_preset(codec
, &alc882_presets
[board_config
]);
4028 if (!spec
->no_analog
&& !spec
->adc_nids
) {
4029 alc_auto_fill_adc_caps(codec
);
4030 alc_rebuild_imux_for_auto_mic(codec
);
4031 alc_remove_invalid_adc_nids(codec
);
4034 if (!spec
->no_analog
&& !spec
->cap_mixer
)
4035 set_capture_mixer(codec
);
4037 if (!spec
->no_analog
&& has_cdefine_beep(codec
)) {
4038 err
= snd_hda_attach_beep_device(codec
, 0x1);
4043 set_beep_amp(spec
, 0x0b, 0x05, HDA_INPUT
);
4046 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
4048 spec
->vmaster_nid
= 0x0c;
4050 codec
->patch_ops
= alc_patch_ops
;
4051 if (board_config
== ALC_MODEL_AUTO
)
4052 spec
->init_hook
= alc_auto_init_std
;
4054 alc_init_jacks(codec
);
4055 #ifdef CONFIG_SND_HDA_POWER_SAVE
4056 if (!spec
->loopback
.amplist
)
4057 spec
->loopback
.amplist
= alc882_loopbacks
;
4067 static int alc262_parse_auto_config(struct hda_codec
*codec
)
4069 static const hda_nid_t alc262_ignore
[] = { 0x1d, 0 };
4070 static const hda_nid_t alc262_ssids
[] = { 0x15, 0x1b, 0x14, 0 };
4071 return alc_parse_auto_config(codec
, alc262_ignore
, alc262_ssids
);
4082 static const struct alc_fixup alc262_fixups
[] = {
4083 [PINFIX_FSC_H270
] = {
4084 .type
= ALC_FIXUP_PINS
,
4085 .v
.pins
= (const struct alc_pincfg
[]) {
4086 { 0x14, 0x99130110 }, /* speaker */
4087 { 0x15, 0x0221142f }, /* front HP */
4088 { 0x1b, 0x0121141f }, /* rear HP */
4092 [PINFIX_HP_Z200
] = {
4093 .type
= ALC_FIXUP_PINS
,
4094 .v
.pins
= (const struct alc_pincfg
[]) {
4095 { 0x16, 0x99130120 }, /* internal speaker */
4101 static const struct snd_pci_quirk alc262_fixup_tbl
[] = {
4102 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", PINFIX_HP_Z200
),
4103 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", PINFIX_FSC_H270
),
4108 #ifdef CONFIG_SND_HDA_POWER_SAVE
4109 #define alc262_loopbacks alc880_loopbacks
4114 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4115 #include "alc262_quirks.c"
4118 static int patch_alc262(struct hda_codec
*codec
)
4120 struct alc_spec
*spec
;
4124 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
4130 spec
->mixer_nid
= 0x0b;
4133 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
4138 snd_hda_codec_write(codec
, 0x1a, 0, AC_VERB_SET_COEF_INDEX
, 7);
4139 tmp
= snd_hda_codec_read(codec
, 0x20, 0, AC_VERB_GET_PROC_COEF
, 0);
4140 snd_hda_codec_write(codec
, 0x1a, 0, AC_VERB_SET_COEF_INDEX
, 7);
4141 snd_hda_codec_write(codec
, 0x1a, 0, AC_VERB_SET_PROC_COEF
, tmp
| 0x80);
4144 alc_auto_parse_customize_define(codec
);
4146 alc_fix_pll_init(codec
, 0x20, 0x0a, 10);
4148 board_config
= alc_board_config(codec
, ALC262_MODEL_LAST
,
4149 alc262_models
, alc262_cfg_tbl
);
4151 if (board_config
< 0) {
4152 printk(KERN_INFO
"hda_codec: %s: BIOS auto-probing.\n",
4154 board_config
= ALC_MODEL_AUTO
;
4157 if (board_config
== ALC_MODEL_AUTO
) {
4158 alc_pick_fixup(codec
, NULL
, alc262_fixup_tbl
, alc262_fixups
);
4159 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
4162 if (board_config
== ALC_MODEL_AUTO
) {
4163 /* automatic parse from the BIOS config */
4164 err
= alc262_parse_auto_config(codec
);
4169 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4172 "hda_codec: Cannot set up configuration "
4173 "from BIOS. Using base mode...\n");
4174 board_config
= ALC262_BASIC
;
4179 if (board_config
!= ALC_MODEL_AUTO
)
4180 setup_preset(codec
, &alc262_presets
[board_config
]);
4182 if (!spec
->no_analog
&& !spec
->adc_nids
) {
4183 alc_auto_fill_adc_caps(codec
);
4184 alc_rebuild_imux_for_auto_mic(codec
);
4185 alc_remove_invalid_adc_nids(codec
);
4188 if (!spec
->no_analog
&& !spec
->cap_mixer
)
4189 set_capture_mixer(codec
);
4191 if (!spec
->no_analog
&& has_cdefine_beep(codec
)) {
4192 err
= snd_hda_attach_beep_device(codec
, 0x1);
4197 set_beep_amp(spec
, 0x0b, 0x05, HDA_INPUT
);
4200 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
4202 spec
->vmaster_nid
= 0x0c;
4204 codec
->patch_ops
= alc_patch_ops
;
4205 if (board_config
== ALC_MODEL_AUTO
)
4206 spec
->init_hook
= alc_auto_init_std
;
4207 spec
->shutup
= alc_eapd_shutup
;
4209 alc_init_jacks(codec
);
4210 #ifdef CONFIG_SND_HDA_POWER_SAVE
4211 if (!spec
->loopback
.amplist
)
4212 spec
->loopback
.amplist
= alc262_loopbacks
;
4221 /* bind Beep switches of both NID 0x0f and 0x10 */
4222 static const struct hda_bind_ctls alc268_bind_beep_sw
= {
4223 .ops
= &snd_hda_bind_sw
,
4225 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT
),
4226 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT
),
4231 static const struct snd_kcontrol_new alc268_beep_mixer
[] = {
4232 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT
),
4233 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw
),
4237 /* set PCBEEP vol = 0, mute connections */
4238 static const struct hda_verb alc268_beep_init_verbs
[] = {
4239 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
4240 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(1)},
4241 {0x10, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(1)},
4246 * BIOS auto configuration
4248 static int alc268_parse_auto_config(struct hda_codec
*codec
)
4250 static const hda_nid_t alc268_ssids
[] = { 0x15, 0x1b, 0x14, 0 };
4251 struct alc_spec
*spec
= codec
->spec
;
4252 int err
= alc_parse_auto_config(codec
, NULL
, alc268_ssids
);
4254 if (!spec
->no_analog
&& spec
->autocfg
.speaker_pins
[0] != 0x1d) {
4255 add_mixer(spec
, alc268_beep_mixer
);
4256 add_verb(spec
, alc268_beep_init_verbs
);
4264 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4265 #include "alc268_quirks.c"
4268 static int patch_alc268(struct hda_codec
*codec
)
4270 struct alc_spec
*spec
;
4272 int i
, has_beep
, err
;
4274 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
4280 /* ALC268 has no aa-loopback mixer */
4282 board_config
= alc_board_config(codec
, ALC268_MODEL_LAST
,
4283 alc268_models
, alc268_cfg_tbl
);
4285 if (board_config
< 0)
4286 board_config
= alc_board_codec_sid_config(codec
,
4287 ALC268_MODEL_LAST
, alc268_models
, alc268_ssid_cfg_tbl
);
4289 if (board_config
< 0) {
4290 printk(KERN_INFO
"hda_codec: %s: BIOS auto-probing.\n",
4292 board_config
= ALC_MODEL_AUTO
;
4295 if (board_config
== ALC_MODEL_AUTO
) {
4296 /* automatic parse from the BIOS config */
4297 err
= alc268_parse_auto_config(codec
);
4302 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4305 "hda_codec: Cannot set up configuration "
4306 "from BIOS. Using base mode...\n");
4307 board_config
= ALC268_3ST
;
4312 if (board_config
!= ALC_MODEL_AUTO
)
4313 setup_preset(codec
, &alc268_presets
[board_config
]);
4316 for (i
= 0; i
< spec
->num_mixers
; i
++) {
4317 if (spec
->mixers
[i
] == alc268_beep_mixer
) {
4324 err
= snd_hda_attach_beep_device(codec
, 0x1);
4329 if (!query_amp_caps(codec
, 0x1d, HDA_INPUT
))
4330 /* override the amp caps for beep generator */
4331 snd_hda_override_amp_caps(codec
, 0x1d, HDA_INPUT
,
4332 (0x0c << AC_AMPCAP_OFFSET_SHIFT
) |
4333 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT
) |
4334 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT
) |
4335 (0 << AC_AMPCAP_MUTE_SHIFT
));
4338 if (!spec
->no_analog
&& !spec
->adc_nids
) {
4339 alc_auto_fill_adc_caps(codec
);
4340 alc_rebuild_imux_for_auto_mic(codec
);
4341 alc_remove_invalid_adc_nids(codec
);
4344 if (!spec
->no_analog
&& !spec
->cap_mixer
)
4345 set_capture_mixer(codec
);
4347 spec
->vmaster_nid
= 0x02;
4349 codec
->patch_ops
= alc_patch_ops
;
4350 if (board_config
== ALC_MODEL_AUTO
)
4351 spec
->init_hook
= alc_auto_init_std
;
4352 spec
->shutup
= alc_eapd_shutup
;
4354 alc_init_jacks(codec
);
4362 #ifdef CONFIG_SND_HDA_POWER_SAVE
4363 #define alc269_loopbacks alc880_loopbacks
4366 static const struct hda_pcm_stream alc269_44k_pcm_analog_playback
= {
4370 .rates
= SNDRV_PCM_RATE_44100
, /* fixed rate */
4371 /* NID is set in alc_build_pcms */
4373 .open
= alc_playback_pcm_open
,
4374 .prepare
= alc_playback_pcm_prepare
,
4375 .cleanup
= alc_playback_pcm_cleanup
4379 static const struct hda_pcm_stream alc269_44k_pcm_analog_capture
= {
4383 .rates
= SNDRV_PCM_RATE_44100
, /* fixed rate */
4384 /* NID is set in alc_build_pcms */
4387 #ifdef CONFIG_SND_HDA_POWER_SAVE
4388 static int alc269_mic2_for_mute_led(struct hda_codec
*codec
)
4390 switch (codec
->subsystem_id
) {
4397 static int alc269_mic2_mute_check_ps(struct hda_codec
*codec
, hda_nid_t nid
)
4399 /* update mute-LED according to the speaker mute state */
4400 if (nid
== 0x01 || nid
== 0x14) {
4402 if (snd_hda_codec_amp_read(codec
, 0x14, 0, HDA_OUTPUT
, 0) &
4407 /* mic2 vref pin is used for mute LED control */
4408 snd_hda_codec_update_cache(codec
, 0x19, 0,
4409 AC_VERB_SET_PIN_WIDGET_CONTROL
,
4412 return alc_check_power_status(codec
, nid
);
4414 #endif /* CONFIG_SND_HDA_POWER_SAVE */
4416 /* different alc269-variants */
4418 ALC269_TYPE_ALC269VA
,
4419 ALC269_TYPE_ALC269VB
,
4420 ALC269_TYPE_ALC269VC
,
4424 * BIOS auto configuration
4426 static int alc269_parse_auto_config(struct hda_codec
*codec
)
4428 static const hda_nid_t alc269_ignore
[] = { 0x1d, 0 };
4429 static const hda_nid_t alc269_ssids
[] = { 0, 0x1b, 0x14, 0x21 };
4430 static const hda_nid_t alc269va_ssids
[] = { 0x15, 0x1b, 0x14, 0 };
4431 struct alc_spec
*spec
= codec
->spec
;
4432 const hda_nid_t
*ssids
= spec
->codec_variant
== ALC269_TYPE_ALC269VA
?
4433 alc269va_ssids
: alc269_ssids
;
4435 return alc_parse_auto_config(codec
, alc269_ignore
, ssids
);
4438 static void alc269_toggle_power_output(struct hda_codec
*codec
, int power_up
)
4440 int val
= alc_read_coef_idx(codec
, 0x04);
4445 alc_write_coef_idx(codec
, 0x04, val
);
4448 static void alc269_shutup(struct hda_codec
*codec
)
4450 if ((alc_read_coef_idx(codec
, 0) & 0x00ff) == 0x017)
4451 alc269_toggle_power_output(codec
, 0);
4452 if ((alc_read_coef_idx(codec
, 0) & 0x00ff) == 0x018) {
4453 alc269_toggle_power_output(codec
, 0);
4459 static int alc269_resume(struct hda_codec
*codec
)
4461 if ((alc_read_coef_idx(codec
, 0) & 0x00ff) == 0x018) {
4462 alc269_toggle_power_output(codec
, 0);
4466 codec
->patch_ops
.init(codec
);
4468 if ((alc_read_coef_idx(codec
, 0) & 0x00ff) == 0x017) {
4469 alc269_toggle_power_output(codec
, 1);
4473 if ((alc_read_coef_idx(codec
, 0) & 0x00ff) == 0x018)
4474 alc269_toggle_power_output(codec
, 1);
4476 snd_hda_codec_resume_amp(codec
);
4477 snd_hda_codec_resume_cache(codec
);
4478 hda_call_check_power_status(codec
, 0x01);
4481 #endif /* CONFIG_PM */
4483 static void alc269_fixup_hweq(struct hda_codec
*codec
,
4484 const struct alc_fixup
*fix
, int action
)
4488 if (action
!= ALC_FIXUP_ACT_INIT
)
4490 coef
= alc_read_coef_idx(codec
, 0x1e);
4491 alc_write_coef_idx(codec
, 0x1e, coef
| 0x80);
4494 static void alc271_fixup_dmic(struct hda_codec
*codec
,
4495 const struct alc_fixup
*fix
, int action
)
4497 static const struct hda_verb verbs
[] = {
4498 {0x20, AC_VERB_SET_COEF_INDEX
, 0x0d},
4499 {0x20, AC_VERB_SET_PROC_COEF
, 0x4000},
4504 if (strcmp(codec
->chip_name
, "ALC271X"))
4506 cfg
= snd_hda_codec_get_pincfg(codec
, 0x12);
4507 if (get_defcfg_connect(cfg
) == AC_JACK_PORT_FIXED
)
4508 snd_hda_sequence_write(codec
, verbs
);
4511 static void alc269_fixup_pcm_44k(struct hda_codec
*codec
,
4512 const struct alc_fixup
*fix
, int action
)
4514 struct alc_spec
*spec
= codec
->spec
;
4516 if (action
!= ALC_FIXUP_ACT_PROBE
)
4519 /* Due to a hardware problem on Lenovo Ideadpad, we need to
4520 * fix the sample rate of analog I/O to 44.1kHz
4522 spec
->stream_analog_playback
= &alc269_44k_pcm_analog_playback
;
4523 spec
->stream_analog_capture
= &alc269_44k_pcm_analog_capture
;
4526 static void alc269_fixup_stereo_dmic(struct hda_codec
*codec
,
4527 const struct alc_fixup
*fix
, int action
)
4531 if (action
!= ALC_FIXUP_ACT_INIT
)
4533 /* The digital-mic unit sends PDM (differential signal) instead of
4534 * the standard PCM, thus you can't record a valid mono stream as is.
4535 * Below is a workaround specific to ALC269 to control the dmic
4536 * signal source as mono.
4538 coef
= alc_read_coef_idx(codec
, 0x07);
4539 alc_write_coef_idx(codec
, 0x07, coef
| 0x80);
4543 ALC269_FIXUP_SONY_VAIO
,
4544 ALC275_FIXUP_SONY_VAIO_GPIO2
,
4545 ALC269_FIXUP_DELL_M101Z
,
4546 ALC269_FIXUP_SKU_IGNORE
,
4547 ALC269_FIXUP_ASUS_G73JW
,
4548 ALC269_FIXUP_LENOVO_EAPD
,
4549 ALC275_FIXUP_SONY_HWEQ
,
4551 ALC269_FIXUP_PCM_44K
,
4552 ALC269_FIXUP_STEREO_DMIC
,
4555 static const struct alc_fixup alc269_fixups
[] = {
4556 [ALC269_FIXUP_SONY_VAIO
] = {
4557 .type
= ALC_FIXUP_VERBS
,
4558 .v
.verbs
= (const struct hda_verb
[]) {
4559 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_VREFGRD
},
4563 [ALC275_FIXUP_SONY_VAIO_GPIO2
] = {
4564 .type
= ALC_FIXUP_VERBS
,
4565 .v
.verbs
= (const struct hda_verb
[]) {
4566 {0x01, AC_VERB_SET_GPIO_MASK
, 0x04},
4567 {0x01, AC_VERB_SET_GPIO_DIRECTION
, 0x04},
4568 {0x01, AC_VERB_SET_GPIO_DATA
, 0x00},
4572 .chain_id
= ALC269_FIXUP_SONY_VAIO
4574 [ALC269_FIXUP_DELL_M101Z
] = {
4575 .type
= ALC_FIXUP_VERBS
,
4576 .v
.verbs
= (const struct hda_verb
[]) {
4577 /* Enables internal speaker */
4578 {0x20, AC_VERB_SET_COEF_INDEX
, 13},
4579 {0x20, AC_VERB_SET_PROC_COEF
, 0x4040},
4583 [ALC269_FIXUP_SKU_IGNORE
] = {
4584 .type
= ALC_FIXUP_SKU
,
4585 .v
.sku
= ALC_FIXUP_SKU_IGNORE
,
4587 [ALC269_FIXUP_ASUS_G73JW
] = {
4588 .type
= ALC_FIXUP_PINS
,
4589 .v
.pins
= (const struct alc_pincfg
[]) {
4590 { 0x17, 0x99130111 }, /* subwoofer */
4594 [ALC269_FIXUP_LENOVO_EAPD
] = {
4595 .type
= ALC_FIXUP_VERBS
,
4596 .v
.verbs
= (const struct hda_verb
[]) {
4597 {0x14, AC_VERB_SET_EAPD_BTLENABLE
, 0},
4601 [ALC275_FIXUP_SONY_HWEQ
] = {
4602 .type
= ALC_FIXUP_FUNC
,
4603 .v
.func
= alc269_fixup_hweq
,
4605 .chain_id
= ALC275_FIXUP_SONY_VAIO_GPIO2
4607 [ALC271_FIXUP_DMIC
] = {
4608 .type
= ALC_FIXUP_FUNC
,
4609 .v
.func
= alc271_fixup_dmic
,
4611 [ALC269_FIXUP_PCM_44K
] = {
4612 .type
= ALC_FIXUP_FUNC
,
4613 .v
.func
= alc269_fixup_pcm_44k
,
4615 [ALC269_FIXUP_STEREO_DMIC
] = {
4616 .type
= ALC_FIXUP_FUNC
,
4617 .v
.func
= alc269_fixup_stereo_dmic
,
4621 static const struct snd_pci_quirk alc269_fixup_tbl
[] = {
4622 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW
),
4623 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC
),
4624 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC
),
4625 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC
),
4626 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC
),
4627 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC
),
4628 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2
),
4629 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ
),
4630 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ
),
4631 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO
),
4632 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z
),
4633 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC
),
4634 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE
),
4635 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE
),
4636 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE
),
4637 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE
),
4638 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE
),
4639 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K
),
4640 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD
),
4645 static int alc269_fill_coef(struct hda_codec
*codec
)
4649 if ((alc_read_coef_idx(codec
, 0) & 0x00ff) < 0x015) {
4650 alc_write_coef_idx(codec
, 0xf, 0x960b);
4651 alc_write_coef_idx(codec
, 0xe, 0x8817);
4654 if ((alc_read_coef_idx(codec
, 0) & 0x00ff) == 0x016) {
4655 alc_write_coef_idx(codec
, 0xf, 0x960b);
4656 alc_write_coef_idx(codec
, 0xe, 0x8814);
4659 if ((alc_read_coef_idx(codec
, 0) & 0x00ff) == 0x017) {
4660 val
= alc_read_coef_idx(codec
, 0x04);
4661 /* Power up output pin */
4662 alc_write_coef_idx(codec
, 0x04, val
| (1<<11));
4665 if ((alc_read_coef_idx(codec
, 0) & 0x00ff) == 0x018) {
4666 val
= alc_read_coef_idx(codec
, 0xd);
4667 if ((val
& 0x0c00) >> 10 != 0x1) {
4668 /* Capless ramp up clock control */
4669 alc_write_coef_idx(codec
, 0xd, val
| (1<<10));
4671 val
= alc_read_coef_idx(codec
, 0x17);
4672 if ((val
& 0x01c0) >> 6 != 0x4) {
4673 /* Class D power on reset */
4674 alc_write_coef_idx(codec
, 0x17, val
| (1<<7));
4678 val
= alc_read_coef_idx(codec
, 0xd); /* Class D */
4679 alc_write_coef_idx(codec
, 0xd, val
| (1<<14));
4681 val
= alc_read_coef_idx(codec
, 0x4); /* HP */
4682 alc_write_coef_idx(codec
, 0x4, val
| (1<<11));
4689 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4690 #include "alc269_quirks.c"
4693 static int patch_alc269(struct hda_codec
*codec
)
4695 struct alc_spec
*spec
;
4696 int board_config
, coef
;
4699 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
4705 spec
->mixer_nid
= 0x0b;
4707 alc_auto_parse_customize_define(codec
);
4709 if (codec
->vendor_id
== 0x10ec0269) {
4710 spec
->codec_variant
= ALC269_TYPE_ALC269VA
;
4711 coef
= alc_read_coef_idx(codec
, 0);
4712 if ((coef
& 0x00f0) == 0x0010) {
4713 if (codec
->bus
->pci
->subsystem_vendor
== 0x1025 &&
4714 spec
->cdefine
.platform_type
== 1) {
4715 alc_codec_rename(codec
, "ALC271X");
4716 } else if ((coef
& 0xf000) == 0x2000) {
4717 alc_codec_rename(codec
, "ALC259");
4718 } else if ((coef
& 0xf000) == 0x3000) {
4719 alc_codec_rename(codec
, "ALC258");
4720 } else if ((coef
& 0xfff0) == 0x3010) {
4721 alc_codec_rename(codec
, "ALC277");
4723 alc_codec_rename(codec
, "ALC269VB");
4725 spec
->codec_variant
= ALC269_TYPE_ALC269VB
;
4726 } else if ((coef
& 0x00f0) == 0x0020) {
4728 alc_codec_rename(codec
, "ALC259");
4729 else if (coef
== 0x6023)
4730 alc_codec_rename(codec
, "ALC281X");
4731 else if (codec
->bus
->pci
->subsystem_vendor
== 0x17aa &&
4732 codec
->bus
->pci
->subsystem_device
== 0x21f3)
4733 alc_codec_rename(codec
, "ALC3202");
4735 alc_codec_rename(codec
, "ALC269VC");
4736 spec
->codec_variant
= ALC269_TYPE_ALC269VC
;
4738 alc_fix_pll_init(codec
, 0x20, 0x04, 15);
4739 alc269_fill_coef(codec
);
4742 board_config
= alc_board_config(codec
, ALC269_MODEL_LAST
,
4743 alc269_models
, alc269_cfg_tbl
);
4745 if (board_config
< 0) {
4746 printk(KERN_INFO
"hda_codec: %s: BIOS auto-probing.\n",
4748 board_config
= ALC_MODEL_AUTO
;
4751 if (board_config
== ALC_MODEL_AUTO
) {
4752 alc_pick_fixup(codec
, NULL
, alc269_fixup_tbl
, alc269_fixups
);
4753 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
4756 if (board_config
== ALC_MODEL_AUTO
) {
4757 /* automatic parse from the BIOS config */
4758 err
= alc269_parse_auto_config(codec
);
4763 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4766 "hda_codec: Cannot set up configuration "
4767 "from BIOS. Using base mode...\n");
4768 board_config
= ALC269_BASIC
;
4773 if (board_config
!= ALC_MODEL_AUTO
)
4774 setup_preset(codec
, &alc269_presets
[board_config
]);
4776 if (!spec
->no_analog
&& !spec
->adc_nids
) {
4777 alc_auto_fill_adc_caps(codec
);
4778 alc_rebuild_imux_for_auto_mic(codec
);
4779 alc_remove_invalid_adc_nids(codec
);
4782 if (!spec
->no_analog
&& !spec
->cap_mixer
)
4783 set_capture_mixer(codec
);
4785 if (!spec
->no_analog
&& has_cdefine_beep(codec
)) {
4786 err
= snd_hda_attach_beep_device(codec
, 0x1);
4791 set_beep_amp(spec
, 0x0b, 0x04, HDA_INPUT
);
4794 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
4796 spec
->vmaster_nid
= 0x02;
4798 codec
->patch_ops
= alc_patch_ops
;
4800 codec
->patch_ops
.resume
= alc269_resume
;
4802 if (board_config
== ALC_MODEL_AUTO
)
4803 spec
->init_hook
= alc_auto_init_std
;
4804 spec
->shutup
= alc269_shutup
;
4806 alc_init_jacks(codec
);
4807 #ifdef CONFIG_SND_HDA_POWER_SAVE
4808 if (!spec
->loopback
.amplist
)
4809 spec
->loopback
.amplist
= alc269_loopbacks
;
4810 if (alc269_mic2_for_mute_led(codec
))
4811 codec
->patch_ops
.check_power_status
= alc269_mic2_mute_check_ps
;
4821 static int alc861_parse_auto_config(struct hda_codec
*codec
)
4823 static const hda_nid_t alc861_ignore
[] = { 0x1d, 0 };
4824 static const hda_nid_t alc861_ssids
[] = { 0x0e, 0x0f, 0x0b, 0 };
4825 return alc_parse_auto_config(codec
, alc861_ignore
, alc861_ssids
);
4828 #ifdef CONFIG_SND_HDA_POWER_SAVE
4829 static const struct hda_amp_list alc861_loopbacks
[] = {
4830 { 0x15, HDA_INPUT
, 0 },
4831 { 0x15, HDA_INPUT
, 1 },
4832 { 0x15, HDA_INPUT
, 2 },
4833 { 0x15, HDA_INPUT
, 3 },
4839 /* Pin config fixes */
4841 PINFIX_FSC_AMILO_PI1505
,
4844 static const struct alc_fixup alc861_fixups
[] = {
4845 [PINFIX_FSC_AMILO_PI1505
] = {
4846 .type
= ALC_FIXUP_PINS
,
4847 .v
.pins
= (const struct alc_pincfg
[]) {
4848 { 0x0b, 0x0221101f }, /* HP */
4849 { 0x0f, 0x90170310 }, /* speaker */
4855 static const struct snd_pci_quirk alc861_fixup_tbl
[] = {
4856 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", PINFIX_FSC_AMILO_PI1505
),
4862 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4863 #include "alc861_quirks.c"
4866 static int patch_alc861(struct hda_codec
*codec
)
4868 struct alc_spec
*spec
;
4872 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
4878 spec
->mixer_nid
= 0x15;
4880 board_config
= alc_board_config(codec
, ALC861_MODEL_LAST
,
4881 alc861_models
, alc861_cfg_tbl
);
4883 if (board_config
< 0) {
4884 printk(KERN_INFO
"hda_codec: %s: BIOS auto-probing.\n",
4886 board_config
= ALC_MODEL_AUTO
;
4889 if (board_config
== ALC_MODEL_AUTO
) {
4890 alc_pick_fixup(codec
, NULL
, alc861_fixup_tbl
, alc861_fixups
);
4891 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
4894 if (board_config
== ALC_MODEL_AUTO
) {
4895 /* automatic parse from the BIOS config */
4896 err
= alc861_parse_auto_config(codec
);
4901 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4904 "hda_codec: Cannot set up configuration "
4905 "from BIOS. Using base mode...\n");
4906 board_config
= ALC861_3ST_DIG
;
4911 if (board_config
!= ALC_MODEL_AUTO
)
4912 setup_preset(codec
, &alc861_presets
[board_config
]);
4914 if (!spec
->no_analog
&& !spec
->adc_nids
) {
4915 alc_auto_fill_adc_caps(codec
);
4916 alc_rebuild_imux_for_auto_mic(codec
);
4917 alc_remove_invalid_adc_nids(codec
);
4920 if (!spec
->no_analog
&& !spec
->cap_mixer
)
4921 set_capture_mixer(codec
);
4923 if (!spec
->no_analog
) {
4924 err
= snd_hda_attach_beep_device(codec
, 0x23);
4929 set_beep_amp(spec
, 0x23, 0, HDA_OUTPUT
);
4932 spec
->vmaster_nid
= 0x03;
4934 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
4936 codec
->patch_ops
= alc_patch_ops
;
4937 if (board_config
== ALC_MODEL_AUTO
) {
4938 spec
->init_hook
= alc_auto_init_std
;
4939 #ifdef CONFIG_SND_HDA_POWER_SAVE
4940 spec
->power_hook
= alc_power_eapd
;
4943 #ifdef CONFIG_SND_HDA_POWER_SAVE
4944 if (!spec
->loopback
.amplist
)
4945 spec
->loopback
.amplist
= alc861_loopbacks
;
4956 * In addition, an independent DAC
4958 #ifdef CONFIG_SND_HDA_POWER_SAVE
4959 #define alc861vd_loopbacks alc880_loopbacks
4962 static int alc861vd_parse_auto_config(struct hda_codec
*codec
)
4964 static const hda_nid_t alc861vd_ignore
[] = { 0x1d, 0 };
4965 static const hda_nid_t alc861vd_ssids
[] = { 0x15, 0x1b, 0x14, 0 };
4966 return alc_parse_auto_config(codec
, alc861vd_ignore
, alc861vd_ssids
);
4970 ALC660VD_FIX_ASUS_GPIO1
4974 static const struct alc_fixup alc861vd_fixups
[] = {
4975 [ALC660VD_FIX_ASUS_GPIO1
] = {
4976 .type
= ALC_FIXUP_VERBS
,
4977 .v
.verbs
= (const struct hda_verb
[]) {
4978 {0x01, AC_VERB_SET_GPIO_MASK
, 0x03},
4979 {0x01, AC_VERB_SET_GPIO_DIRECTION
, 0x01},
4980 {0x01, AC_VERB_SET_GPIO_DATA
, 0x01},
4986 static const struct snd_pci_quirk alc861vd_fixup_tbl
[] = {
4987 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1
),
4991 static const struct hda_verb alc660vd_eapd_verbs
[] = {
4992 {0x14, AC_VERB_SET_EAPD_BTLENABLE
, 2},
4993 {0x15, AC_VERB_SET_EAPD_BTLENABLE
, 2},
4999 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
5000 #include "alc861vd_quirks.c"
5003 static int patch_alc861vd(struct hda_codec
*codec
)
5005 struct alc_spec
*spec
;
5006 int err
, board_config
;
5008 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
5014 spec
->mixer_nid
= 0x0b;
5016 board_config
= alc_board_config(codec
, ALC861VD_MODEL_LAST
,
5017 alc861vd_models
, alc861vd_cfg_tbl
);
5019 if (board_config
< 0) {
5020 printk(KERN_INFO
"hda_codec: %s: BIOS auto-probing.\n",
5022 board_config
= ALC_MODEL_AUTO
;
5025 if (board_config
== ALC_MODEL_AUTO
) {
5026 alc_pick_fixup(codec
, NULL
, alc861vd_fixup_tbl
, alc861vd_fixups
);
5027 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
5030 if (board_config
== ALC_MODEL_AUTO
) {
5031 /* automatic parse from the BIOS config */
5032 err
= alc861vd_parse_auto_config(codec
);
5037 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
5040 "hda_codec: Cannot set up configuration "
5041 "from BIOS. Using base mode...\n");
5042 board_config
= ALC861VD_3ST
;
5047 if (board_config
!= ALC_MODEL_AUTO
)
5048 setup_preset(codec
, &alc861vd_presets
[board_config
]);
5050 if (codec
->vendor_id
== 0x10ec0660) {
5051 /* always turn on EAPD */
5052 add_verb(spec
, alc660vd_eapd_verbs
);
5055 if (!spec
->no_analog
&& !spec
->adc_nids
) {
5056 alc_auto_fill_adc_caps(codec
);
5057 alc_rebuild_imux_for_auto_mic(codec
);
5058 alc_remove_invalid_adc_nids(codec
);
5061 if (!spec
->no_analog
&& !spec
->cap_mixer
)
5062 set_capture_mixer(codec
);
5064 if (!spec
->no_analog
) {
5065 err
= snd_hda_attach_beep_device(codec
, 0x23);
5070 set_beep_amp(spec
, 0x0b, 0x05, HDA_INPUT
);
5073 spec
->vmaster_nid
= 0x02;
5075 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
5077 codec
->patch_ops
= alc_patch_ops
;
5079 if (board_config
== ALC_MODEL_AUTO
)
5080 spec
->init_hook
= alc_auto_init_std
;
5081 spec
->shutup
= alc_eapd_shutup
;
5082 #ifdef CONFIG_SND_HDA_POWER_SAVE
5083 if (!spec
->loopback
.amplist
)
5084 spec
->loopback
.amplist
= alc861vd_loopbacks
;
5093 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
5094 * configuration. Each pin widget can choose any input DACs and a mixer.
5095 * Each ADC is connected from a mixer of all inputs. This makes possible
5096 * 6-channel independent captures.
5098 * In addition, an independent DAC for the multi-playback (not used in this
5101 #ifdef CONFIG_SND_HDA_POWER_SAVE
5102 #define alc662_loopbacks alc880_loopbacks
5106 * BIOS auto configuration
5109 static int alc662_parse_auto_config(struct hda_codec
*codec
)
5111 static const hda_nid_t alc662_ignore
[] = { 0x1d, 0 };
5112 static const hda_nid_t alc663_ssids
[] = { 0x15, 0x1b, 0x14, 0x21 };
5113 static const hda_nid_t alc662_ssids
[] = { 0x15, 0x1b, 0x14, 0 };
5114 const hda_nid_t
*ssids
;
5116 if (codec
->vendor_id
== 0x10ec0272 || codec
->vendor_id
== 0x10ec0663 ||
5117 codec
->vendor_id
== 0x10ec0665 || codec
->vendor_id
== 0x10ec0670)
5118 ssids
= alc663_ssids
;
5120 ssids
= alc662_ssids
;
5121 return alc_parse_auto_config(codec
, alc662_ignore
, ssids
);
5124 static void alc272_fixup_mario(struct hda_codec
*codec
,
5125 const struct alc_fixup
*fix
, int action
)
5127 if (action
!= ALC_FIXUP_ACT_PROBE
)
5129 if (snd_hda_override_amp_caps(codec
, 0x2, HDA_OUTPUT
,
5130 (0x3b << AC_AMPCAP_OFFSET_SHIFT
) |
5131 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT
) |
5132 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT
) |
5133 (0 << AC_AMPCAP_MUTE_SHIFT
)))
5135 "hda_codec: failed to override amp caps for NID 0x2\n");
5139 ALC662_FIXUP_ASPIRE
,
5140 ALC662_FIXUP_IDEAPAD
,
5142 ALC662_FIXUP_CZC_P10T
,
5143 ALC662_FIXUP_SKU_IGNORE
,
5144 ALC662_FIXUP_HP_RP5800
,
5147 static const struct alc_fixup alc662_fixups
[] = {
5148 [ALC662_FIXUP_ASPIRE
] = {
5149 .type
= ALC_FIXUP_PINS
,
5150 .v
.pins
= (const struct alc_pincfg
[]) {
5151 { 0x15, 0x99130112 }, /* subwoofer */
5155 [ALC662_FIXUP_IDEAPAD
] = {
5156 .type
= ALC_FIXUP_PINS
,
5157 .v
.pins
= (const struct alc_pincfg
[]) {
5158 { 0x17, 0x99130112 }, /* subwoofer */
5162 [ALC272_FIXUP_MARIO
] = {
5163 .type
= ALC_FIXUP_FUNC
,
5164 .v
.func
= alc272_fixup_mario
,
5166 [ALC662_FIXUP_CZC_P10T
] = {
5167 .type
= ALC_FIXUP_VERBS
,
5168 .v
.verbs
= (const struct hda_verb
[]) {
5169 {0x14, AC_VERB_SET_EAPD_BTLENABLE
, 0},
5173 [ALC662_FIXUP_SKU_IGNORE
] = {
5174 .type
= ALC_FIXUP_SKU
,
5175 .v
.sku
= ALC_FIXUP_SKU_IGNORE
,
5177 [ALC662_FIXUP_HP_RP5800
] = {
5178 .type
= ALC_FIXUP_PINS
,
5179 .v
.pins
= (const struct alc_pincfg
[]) {
5180 { 0x14, 0x0221201f }, /* HP out */
5184 .chain_id
= ALC662_FIXUP_SKU_IGNORE
5188 static const struct snd_pci_quirk alc662_fixup_tbl
[] = {
5189 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE
),
5190 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE
),
5191 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE
),
5192 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800
),
5193 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD
),
5194 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD
),
5195 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD
),
5196 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T
),
5200 static const struct alc_model_fixup alc662_fixup_models
[] = {
5201 {.id
= ALC272_FIXUP_MARIO
, .name
= "mario"},
5208 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
5209 #include "alc662_quirks.c"
5212 static int patch_alc662(struct hda_codec
*codec
)
5214 struct alc_spec
*spec
;
5215 int err
, board_config
;
5218 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
5224 spec
->mixer_nid
= 0x0b;
5226 alc_auto_parse_customize_define(codec
);
5228 alc_fix_pll_init(codec
, 0x20, 0x04, 15);
5230 coef
= alc_read_coef_idx(codec
, 0);
5231 if (coef
== 0x8020 || coef
== 0x8011)
5232 alc_codec_rename(codec
, "ALC661");
5233 else if (coef
& (1 << 14) &&
5234 codec
->bus
->pci
->subsystem_vendor
== 0x1025 &&
5235 spec
->cdefine
.platform_type
== 1)
5236 alc_codec_rename(codec
, "ALC272X");
5237 else if (coef
== 0x4011)
5238 alc_codec_rename(codec
, "ALC656");
5240 board_config
= alc_board_config(codec
, ALC662_MODEL_LAST
,
5241 alc662_models
, alc662_cfg_tbl
);
5242 if (board_config
< 0) {
5243 printk(KERN_INFO
"hda_codec: %s: BIOS auto-probing.\n",
5245 board_config
= ALC_MODEL_AUTO
;
5248 if (board_config
== ALC_MODEL_AUTO
) {
5249 alc_pick_fixup(codec
, alc662_fixup_models
,
5250 alc662_fixup_tbl
, alc662_fixups
);
5251 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PRE_PROBE
);
5252 /* automatic parse from the BIOS config */
5253 err
= alc662_parse_auto_config(codec
);
5258 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
5261 "hda_codec: Cannot set up configuration "
5262 "from BIOS. Using base mode...\n");
5263 board_config
= ALC662_3ST_2ch_DIG
;
5268 if (board_config
!= ALC_MODEL_AUTO
)
5269 setup_preset(codec
, &alc662_presets
[board_config
]);
5271 if (!spec
->no_analog
&& !spec
->adc_nids
) {
5272 alc_auto_fill_adc_caps(codec
);
5273 alc_rebuild_imux_for_auto_mic(codec
);
5274 alc_remove_invalid_adc_nids(codec
);
5277 if (!spec
->no_analog
&& !spec
->cap_mixer
)
5278 set_capture_mixer(codec
);
5280 if (!spec
->no_analog
&& has_cdefine_beep(codec
)) {
5281 err
= snd_hda_attach_beep_device(codec
, 0x1);
5286 switch (codec
->vendor_id
) {
5288 set_beep_amp(spec
, 0x0b, 0x05, HDA_INPUT
);
5293 set_beep_amp(spec
, 0x0b, 0x04, HDA_INPUT
);
5296 set_beep_amp(spec
, 0x0b, 0x03, HDA_INPUT
);
5300 spec
->vmaster_nid
= 0x02;
5302 alc_apply_fixup(codec
, ALC_FIXUP_ACT_PROBE
);
5304 codec
->patch_ops
= alc_patch_ops
;
5305 if (board_config
== ALC_MODEL_AUTO
)
5306 spec
->init_hook
= alc_auto_init_std
;
5307 spec
->shutup
= alc_eapd_shutup
;
5309 alc_init_jacks(codec
);
5311 #ifdef CONFIG_SND_HDA_POWER_SAVE
5312 if (!spec
->loopback
.amplist
)
5313 spec
->loopback
.amplist
= alc662_loopbacks
;
5319 static int patch_alc888(struct hda_codec
*codec
)
5321 if ((alc_read_coef_idx(codec
, 0) & 0x00f0)==0x0030){
5322 kfree(codec
->chip_name
);
5323 if (codec
->vendor_id
== 0x10ec0887)
5324 codec
->chip_name
= kstrdup("ALC887-VD", GFP_KERNEL
);
5326 codec
->chip_name
= kstrdup("ALC888-VD", GFP_KERNEL
);
5327 if (!codec
->chip_name
) {
5331 return patch_alc662(codec
);
5333 return patch_alc882(codec
);
5336 static int patch_alc899(struct hda_codec
*codec
)
5338 if ((alc_read_coef_idx(codec
, 0) & 0x2000) != 0x2000) {
5339 kfree(codec
->chip_name
);
5340 codec
->chip_name
= kstrdup("ALC898", GFP_KERNEL
);
5342 return patch_alc882(codec
);
5349 static int alc680_parse_auto_config(struct hda_codec
*codec
)
5351 return alc_parse_auto_config(codec
, NULL
, NULL
);
5356 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
5357 #include "alc680_quirks.c"
5360 static int patch_alc680(struct hda_codec
*codec
)
5362 struct alc_spec
*spec
;
5366 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
5372 /* ALC680 has no aa-loopback mixer */
5374 board_config
= alc_board_config(codec
, ALC680_MODEL_LAST
,
5375 alc680_models
, alc680_cfg_tbl
);
5377 if (board_config
< 0) {
5378 printk(KERN_INFO
"hda_codec: %s: BIOS auto-probing.\n",
5380 board_config
= ALC_MODEL_AUTO
;
5383 if (board_config
== ALC_MODEL_AUTO
) {
5384 /* automatic parse from the BIOS config */
5385 err
= alc680_parse_auto_config(codec
);
5390 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
5393 "hda_codec: Cannot set up configuration "
5394 "from BIOS. Using base mode...\n");
5395 board_config
= ALC680_BASE
;
5400 if (board_config
!= ALC_MODEL_AUTO
) {
5401 setup_preset(codec
, &alc680_presets
[board_config
]);
5402 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
5403 spec
->stream_analog_capture
= &alc680_pcm_analog_auto_capture
;
5407 if (!spec
->no_analog
&& !spec
->adc_nids
) {
5408 alc_auto_fill_adc_caps(codec
);
5409 alc_rebuild_imux_for_auto_mic(codec
);
5410 alc_remove_invalid_adc_nids(codec
);
5413 if (!spec
->no_analog
&& !spec
->cap_mixer
)
5414 set_capture_mixer(codec
);
5416 spec
->vmaster_nid
= 0x02;
5418 codec
->patch_ops
= alc_patch_ops
;
5419 if (board_config
== ALC_MODEL_AUTO
)
5420 spec
->init_hook
= alc_auto_init_std
;
5428 static const struct hda_codec_preset snd_hda_preset_realtek
[] = {
5429 { .id
= 0x10ec0221, .name
= "ALC221", .patch
= patch_alc269
},
5430 { .id
= 0x10ec0260, .name
= "ALC260", .patch
= patch_alc260
},
5431 { .id
= 0x10ec0262, .name
= "ALC262", .patch
= patch_alc262
},
5432 { .id
= 0x10ec0267, .name
= "ALC267", .patch
= patch_alc268
},
5433 { .id
= 0x10ec0268, .name
= "ALC268", .patch
= patch_alc268
},
5434 { .id
= 0x10ec0269, .name
= "ALC269", .patch
= patch_alc269
},
5435 { .id
= 0x10ec0270, .name
= "ALC270", .patch
= patch_alc269
},
5436 { .id
= 0x10ec0272, .name
= "ALC272", .patch
= patch_alc662
},
5437 { .id
= 0x10ec0275, .name
= "ALC275", .patch
= patch_alc269
},
5438 { .id
= 0x10ec0276, .name
= "ALC276", .patch
= patch_alc269
},
5439 { .id
= 0x10ec0861, .rev
= 0x100340, .name
= "ALC660",
5440 .patch
= patch_alc861
},
5441 { .id
= 0x10ec0660, .name
= "ALC660-VD", .patch
= patch_alc861vd
},
5442 { .id
= 0x10ec0861, .name
= "ALC861", .patch
= patch_alc861
},
5443 { .id
= 0x10ec0862, .name
= "ALC861-VD", .patch
= patch_alc861vd
},
5444 { .id
= 0x10ec0662, .rev
= 0x100002, .name
= "ALC662 rev2",
5445 .patch
= patch_alc882
},
5446 { .id
= 0x10ec0662, .rev
= 0x100101, .name
= "ALC662 rev1",
5447 .patch
= patch_alc662
},
5448 { .id
= 0x10ec0662, .rev
= 0x100300, .name
= "ALC662 rev3",
5449 .patch
= patch_alc662
},
5450 { .id
= 0x10ec0663, .name
= "ALC663", .patch
= patch_alc662
},
5451 { .id
= 0x10ec0665, .name
= "ALC665", .patch
= patch_alc662
},
5452 { .id
= 0x10ec0670, .name
= "ALC670", .patch
= patch_alc662
},
5453 { .id
= 0x10ec0680, .name
= "ALC680", .patch
= patch_alc680
},
5454 { .id
= 0x10ec0880, .name
= "ALC880", .patch
= patch_alc880
},
5455 { .id
= 0x10ec0882, .name
= "ALC882", .patch
= patch_alc882
},
5456 { .id
= 0x10ec0883, .name
= "ALC883", .patch
= patch_alc882
},
5457 { .id
= 0x10ec0885, .rev
= 0x100101, .name
= "ALC889A",
5458 .patch
= patch_alc882
},
5459 { .id
= 0x10ec0885, .rev
= 0x100103, .name
= "ALC889A",
5460 .patch
= patch_alc882
},
5461 { .id
= 0x10ec0885, .name
= "ALC885", .patch
= patch_alc882
},
5462 { .id
= 0x10ec0887, .name
= "ALC887", .patch
= patch_alc888
},
5463 { .id
= 0x10ec0888, .rev
= 0x100101, .name
= "ALC1200",
5464 .patch
= patch_alc882
},
5465 { .id
= 0x10ec0888, .name
= "ALC888", .patch
= patch_alc888
},
5466 { .id
= 0x10ec0889, .name
= "ALC889", .patch
= patch_alc882
},
5467 { .id
= 0x10ec0892, .name
= "ALC892", .patch
= patch_alc662
},
5468 { .id
= 0x10ec0899, .name
= "ALC899", .patch
= patch_alc899
},
5472 MODULE_ALIAS("snd-hda-codec-id:10ec*");
5474 MODULE_LICENSE("GPL");
5475 MODULE_DESCRIPTION("Realtek HD-audio codec");
5477 static struct hda_codec_preset_list realtek_list
= {
5478 .preset
= snd_hda_preset_realtek
,
5479 .owner
= THIS_MODULE
,
5482 static int __init
patch_realtek_init(void)
5484 return snd_hda_add_codec_preset(&realtek_list
);
5487 static void __exit
patch_realtek_exit(void)
5489 snd_hda_delete_codec_preset(&realtek_list
);
5492 module_init(patch_realtek_init
)
5493 module_exit(patch_realtek_exit
)