]> git.ipfire.org Git - thirdparty/linux.git/blame - sound/pci/hda/patch_realtek.c
ALSA: hda - Rewrite ALC662 asus-mode* models with fixups
[thirdparty/linux.git] / sound / pci / hda / patch_realtek.c
CommitLineData
1da177e4
LT
1/*
2 * Universal Interface for Intel High Definition Audio Codec
3 *
1d045db9 4 * HD audio interface patch for Realtek ALC codecs
1da177e4 5 *
df694daa
KY
6 * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
7 * PeiSen Hou <pshou@realtek.com.tw>
1da177e4 8 * Takashi Iwai <tiwai@suse.de>
7cf51e48 9 * Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
1da177e4
LT
10 *
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.
15 *
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.
20 *
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
24 */
25
1da177e4
LT
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>
9ad0e496 31#include <sound/jack.h>
1da177e4
LT
32#include "hda_codec.h"
33#include "hda_local.h"
680cd536 34#include "hda_beep.h"
1da177e4 35
1d045db9
TI
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
d4a86d81 41
df694daa
KY
42/* for GPIO Poll */
43#define GPIO_MASK 0x03
44
4a79ba34
TI
45/* extra amp-initialization sequence types */
46enum {
47 ALC_INIT_NONE,
48 ALC_INIT_DEFAULT,
49 ALC_INIT_GPIO1,
50 ALC_INIT_GPIO2,
51 ALC_INIT_GPIO3,
52};
53
da00c244
KY
54struct alc_customize_define {
55 unsigned int sku_cfg;
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;
62 unsigned int swap:1;
63 unsigned int override:1;
90622917 64 unsigned int fixup:1; /* Means that this sku is set by driver, not read from hw */
da00c244
KY
65};
66
b5bfbc67
TI
67struct alc_fixup;
68
ce764ab2
TI
69struct alc_multi_io {
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 */
73};
74
d922b51d 75enum {
3b8510ce
TI
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 */
d922b51d
TI
79};
80
1da177e4
LT
81struct alc_spec {
82 /* codec parameterization */
a9111321 83 const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */
1da177e4 84 unsigned int num_mixers;
a9111321 85 const struct snd_kcontrol_new *cap_mixer; /* capture mixer */
45bdd1c1 86 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
1da177e4 87
2d9c6482 88 const struct hda_verb *init_verbs[10]; /* initialization verbs
9c7f852e
TI
89 * don't forget NULL
90 * termination!
e9edcee0
TI
91 */
92 unsigned int num_init_verbs;
1da177e4 93
aa563af7 94 char stream_name_analog[32]; /* analog PCM stream */
a9111321
TI
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;
1da177e4 99
aa563af7 100 char stream_name_digital[32]; /* digital PCM stream */
a9111321
TI
101 const struct hda_pcm_stream *stream_digital_playback;
102 const struct hda_pcm_stream *stream_digital_capture;
1da177e4
LT
103
104 /* playback */
16ded525
TI
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
108 */
6330079f 109 hda_nid_t alt_dac_nid;
6a05ac4a 110 hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */
8c441982 111 int dig_out_type;
1da177e4
LT
112
113 /* capture */
114 unsigned int num_adc_nids;
4c6d72d1
TI
115 const hda_nid_t *adc_nids;
116 const hda_nid_t *capsrc_nids;
16ded525 117 hda_nid_t dig_in_nid; /* digital-in NID; optional */
1f0f4b80 118 hda_nid_t mixer_nid; /* analog-mixer NID */
1da177e4 119
840b64c0 120 /* capture setup for dynamic dual-adc switch */
840b64c0
TI
121 hda_nid_t cur_adc;
122 unsigned int cur_adc_stream_tag;
123 unsigned int cur_adc_format;
124
1da177e4 125 /* capture source */
a1e8d2da 126 unsigned int num_mux_defs;
1da177e4
LT
127 const struct hda_input_mux *input_mux;
128 unsigned int cur_mux[3];
21268961
TI
129 hda_nid_t ext_mic_pin;
130 hda_nid_t dock_mic_pin;
131 hda_nid_t int_mic_pin;
1da177e4
LT
132
133 /* channel model */
d2a6d7dc 134 const struct hda_channel_mode *channel_mode;
1da177e4 135 int num_channel_mode;
4e195a7b 136 int need_dac_fix;
3b315d70
HM
137 int const_channel_count;
138 int ext_channel_count;
1da177e4
LT
139
140 /* PCM information */
4c5186ed 141 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
41e41f1f 142
e9edcee0
TI
143 /* dynamic controls, init_verbs and input_mux */
144 struct auto_pin_cfg autocfg;
da00c244 145 struct alc_customize_define cdefine;
603c4019 146 struct snd_array kctls;
61b9b9b1 147 struct hda_input_mux private_imux[3];
41923e44 148 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
4953550a
TI
149 hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS];
150 hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS];
21268961
TI
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 */
834be88d 154
ae6b813a
TI
155 /* hooks */
156 void (*init_hook)(struct hda_codec *codec);
157 void (*unsol_event)(struct hda_codec *codec, unsigned int res);
f5de24b0 158#ifdef CONFIG_SND_HDA_POWER_SAVE
c97259df 159 void (*power_hook)(struct hda_codec *codec);
f5de24b0 160#endif
1c716153 161 void (*shutup)(struct hda_codec *codec);
24519911 162 void (*automute_hook)(struct hda_codec *codec);
ae6b813a 163
834be88d 164 /* for pin sensing */
834be88d 165 unsigned int jack_present: 1;
e6a5e1b7 166 unsigned int line_jack_present:1;
e9427969 167 unsigned int master_mute:1;
6c819492 168 unsigned int auto_mic:1;
21268961 169 unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */
d922b51d 170 unsigned int automute:1; /* HP automute enabled */
e6a5e1b7
TI
171 unsigned int detect_line:1; /* Line-out detection enabled */
172 unsigned int automute_lines:1; /* automute line-out as well */
ae8a60a5 173 unsigned int automute_hp_lo:1; /* both HP and LO available */
cb53c626 174
e64f14f4
TI
175 /* other flags */
176 unsigned int no_analog :1; /* digital I/O only */
21268961 177 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
584c0c4c 178 unsigned int single_input_src:1;
d6cc9fab 179 unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */
53c334ad 180 unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */
d922b51d
TI
181
182 /* auto-mute control */
183 int automute_mode;
3b8510ce 184 hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS];
d922b51d 185
4a79ba34 186 int init_amp;
d433a678 187 int codec_variant; /* flag for other variants */
e64f14f4 188
2134ea4f
TI
189 /* for virtual master */
190 hda_nid_t vmaster_nid;
cb53c626
TI
191#ifdef CONFIG_SND_HDA_POWER_SAVE
192 struct hda_loopback_check loopback;
193#endif
2c3bf9ab
TI
194
195 /* for PLL fix */
196 hda_nid_t pll_nid;
197 unsigned int pll_coef_idx, pll_coef_bit;
b5bfbc67
TI
198
199 /* fix-up list */
200 int fixup_id;
201 const struct alc_fixup *fixup_list;
202 const char *fixup_name;
ce764ab2
TI
203
204 /* multi-io */
205 int multi_ios;
206 struct alc_multi_io multi_io[4];
23c09b00
TI
207
208 /* bind volumes */
209 struct snd_array bind_ctls;
df694daa
KY
210};
211
1d045db9 212#define ALC_MODEL_AUTO 0 /* common for all chips */
1da177e4 213
44c02400
TI
214static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
215 int dir, unsigned int bits)
216{
217 if (!nid)
218 return false;
219 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
220 if (query_amp_caps(codec, nid, dir) & bits)
221 return true;
222 return false;
223}
224
225#define nid_has_mute(codec, nid, dir) \
226 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
227#define nid_has_volume(codec, nid, dir) \
228 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
229
1da177e4
LT
230/*
231 * input MUX handling
232 */
9c7f852e
TI
233static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
234 struct snd_ctl_elem_info *uinfo)
1da177e4
LT
235{
236 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
237 struct alc_spec *spec = codec->spec;
a1e8d2da
JW
238 unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
239 if (mux_idx >= spec->num_mux_defs)
240 mux_idx = 0;
5311114d
TI
241 if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
242 mux_idx = 0;
a1e8d2da 243 return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
1da177e4
LT
244}
245
9c7f852e
TI
246static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
247 struct snd_ctl_elem_value *ucontrol)
1da177e4
LT
248{
249 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
250 struct alc_spec *spec = codec->spec;
251 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
252
253 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
254 return 0;
255}
256
21268961
TI
257static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
258{
259 struct alc_spec *spec = codec->spec;
260 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
261
262 if (spec->cur_adc && spec->cur_adc != new_adc) {
263 /* stream is running, let's swap the current ADC */
264 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
265 spec->cur_adc = new_adc;
266 snd_hda_codec_setup_stream(codec, new_adc,
267 spec->cur_adc_stream_tag, 0,
268 spec->cur_adc_format);
269 return true;
270 }
271 return false;
272}
273
274/* select the given imux item; either unmute exclusively or select the route */
275static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
276 unsigned int idx, bool force)
1da177e4 277{
1da177e4 278 struct alc_spec *spec = codec->spec;
cd896c33 279 const struct hda_input_mux *imux;
cd896c33 280 unsigned int mux_idx;
21268961
TI
281 int i, type;
282 hda_nid_t nid;
1da177e4 283
cd896c33
TI
284 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
285 imux = &spec->input_mux[mux_idx];
5311114d
TI
286 if (!imux->num_items && mux_idx > 0)
287 imux = &spec->input_mux[0];
cd896c33 288
21268961
TI
289 if (idx >= imux->num_items)
290 idx = imux->num_items - 1;
291 if (spec->cur_mux[adc_idx] == idx && !force)
292 return 0;
293 spec->cur_mux[adc_idx] = idx;
294
295 if (spec->dyn_adc_switch) {
296 alc_dyn_adc_pcm_resetup(codec, idx);
297 adc_idx = spec->dyn_adc_idx[idx];
298 }
299
300 nid = spec->capsrc_nids ?
301 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
302
303 /* no selection? */
304 if (snd_hda_get_conn_list(codec, nid, NULL) <= 1)
305 return 1;
306
a22d543a 307 type = get_wcaps_type(get_wcaps(codec, nid));
0169b6b3 308 if (type == AC_WID_AUD_MIX) {
54cbc9ab 309 /* Matrix-mixer style (e.g. ALC882) */
54cbc9ab
TI
310 for (i = 0; i < imux->num_items; i++) {
311 unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
312 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
313 imux->items[i].index,
314 HDA_AMP_MUTE, v);
315 }
54cbc9ab
TI
316 } else {
317 /* MUX style (e.g. ALC880) */
21268961
TI
318 snd_hda_codec_write_cache(codec, nid, 0,
319 AC_VERB_SET_CONNECT_SEL,
320 imux->items[idx].index);
54cbc9ab 321 }
21268961
TI
322 return 1;
323}
324
325static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
326 struct snd_ctl_elem_value *ucontrol)
327{
328 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
329 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
330 return alc_mux_select(codec, adc_idx,
331 ucontrol->value.enumerated.item[0], false);
54cbc9ab 332}
e9edcee0 333
23f0c048
TI
334/*
335 * set up the input pin config (depending on the given auto-pin type)
336 */
337static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
338 int auto_pin_type)
339{
340 unsigned int val = PIN_IN;
341
86e2959a 342 if (auto_pin_type == AUTO_PIN_MIC) {
23f0c048 343 unsigned int pincap;
954a29c8
TI
344 unsigned int oldval;
345 oldval = snd_hda_codec_read(codec, nid, 0,
346 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1327a32b 347 pincap = snd_hda_query_pin_caps(codec, nid);
23f0c048 348 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
954a29c8
TI
349 /* if the default pin setup is vref50, we give it priority */
350 if ((pincap & AC_PINCAP_VREF_80) && oldval != PIN_VREF50)
23f0c048 351 val = PIN_VREF80;
461c6c3a
TI
352 else if (pincap & AC_PINCAP_VREF_50)
353 val = PIN_VREF50;
354 else if (pincap & AC_PINCAP_VREF_100)
355 val = PIN_VREF100;
356 else if (pincap & AC_PINCAP_VREF_GRD)
357 val = PIN_VREFGRD;
23f0c048
TI
358 }
359 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val);
360}
361
d88897ea 362/*
1d045db9
TI
363 * Append the given mixer and verb elements for the later use
364 * The mixer array is referred in build_controls(), and init_verbs are
365 * called in init().
d88897ea 366 */
a9111321 367static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
d88897ea
TI
368{
369 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
370 return;
371 spec->mixers[spec->num_mixers++] = mix;
372}
373
374static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
375{
376 if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
377 return;
378 spec->init_verbs[spec->num_init_verbs++] = verb;
379}
380
df694daa 381/*
1d045db9 382 * GPIO setup tables, used in initialization
df694daa 383 */
bc9f98a9 384/* Enable GPIO mask and set output */
a9111321 385static const struct hda_verb alc_gpio1_init_verbs[] = {
bc9f98a9
KY
386 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
387 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
388 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
389 { }
390};
391
a9111321 392static const struct hda_verb alc_gpio2_init_verbs[] = {
bc9f98a9
KY
393 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
394 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
395 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
396 { }
397};
398
a9111321 399static const struct hda_verb alc_gpio3_init_verbs[] = {
bdd148a3
KY
400 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
401 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
402 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
403 { }
404};
405
2c3bf9ab
TI
406/*
407 * Fix hardware PLL issue
408 * On some codecs, the analog PLL gating control must be off while
409 * the default value is 1.
410 */
411static void alc_fix_pll(struct hda_codec *codec)
412{
413 struct alc_spec *spec = codec->spec;
414 unsigned int val;
415
416 if (!spec->pll_nid)
417 return;
418 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
419 spec->pll_coef_idx);
420 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
421 AC_VERB_GET_PROC_COEF, 0);
422 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
423 spec->pll_coef_idx);
424 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
425 val & ~(1 << spec->pll_coef_bit));
426}
427
428static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
429 unsigned int coef_idx, unsigned int coef_bit)
430{
431 struct alc_spec *spec = codec->spec;
432 spec->pll_nid = nid;
433 spec->pll_coef_idx = coef_idx;
434 spec->pll_coef_bit = coef_bit;
435 alc_fix_pll(codec);
436}
437
1d045db9
TI
438/*
439 * Jack-reporting via input-jack layer
440 */
441
442/* initialization of jacks; currently checks only a few known pins */
9ad0e496
KY
443static int alc_init_jacks(struct hda_codec *codec)
444{
cd372fb3 445#ifdef CONFIG_SND_HDA_INPUT_JACK
9ad0e496
KY
446 struct alc_spec *spec = codec->spec;
447 int err;
448 unsigned int hp_nid = spec->autocfg.hp_pins[0];
21268961
TI
449 unsigned int mic_nid = spec->ext_mic_pin;
450 unsigned int dock_nid = spec->dock_mic_pin;
9ad0e496 451
265a0247 452 if (hp_nid) {
cd372fb3
TI
453 err = snd_hda_input_jack_add(codec, hp_nid,
454 SND_JACK_HEADPHONE, NULL);
265a0247
TI
455 if (err < 0)
456 return err;
cd372fb3 457 snd_hda_input_jack_report(codec, hp_nid);
265a0247 458 }
9ad0e496 459
265a0247 460 if (mic_nid) {
cd372fb3
TI
461 err = snd_hda_input_jack_add(codec, mic_nid,
462 SND_JACK_MICROPHONE, NULL);
265a0247
TI
463 if (err < 0)
464 return err;
cd372fb3 465 snd_hda_input_jack_report(codec, mic_nid);
265a0247 466 }
8ed99d97
TI
467 if (dock_nid) {
468 err = snd_hda_input_jack_add(codec, dock_nid,
469 SND_JACK_MICROPHONE, NULL);
470 if (err < 0)
471 return err;
472 snd_hda_input_jack_report(codec, dock_nid);
473 }
cd372fb3 474#endif /* CONFIG_SND_HDA_INPUT_JACK */
9ad0e496
KY
475 return 0;
476}
9ad0e496 477
1d045db9
TI
478/*
479 * Jack detections for HP auto-mute and mic-switch
480 */
481
482/* check each pin in the given array; returns true if any of them is plugged */
483static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
c9b58006 484{
e6a5e1b7 485 int i, present = 0;
c9b58006 486
e6a5e1b7
TI
487 for (i = 0; i < num_pins; i++) {
488 hda_nid_t nid = pins[i];
bb35febd
TI
489 if (!nid)
490 break;
cd372fb3 491 snd_hda_input_jack_report(codec, nid);
e6a5e1b7 492 present |= snd_hda_jack_detect(codec, nid);
bb35febd 493 }
e6a5e1b7
TI
494 return present;
495}
bb35febd 496
1d045db9 497/* standard HP/line-out auto-mute helper */
e6a5e1b7 498static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
e9427969 499 bool mute, bool hp_out)
e6a5e1b7
TI
500{
501 struct alc_spec *spec = codec->spec;
502 unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0;
e9427969 503 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
e6a5e1b7
TI
504 int i;
505
506 for (i = 0; i < num_pins; i++) {
507 hda_nid_t nid = pins[i];
a9fd4f3f
TI
508 if (!nid)
509 break;
3b8510ce
TI
510 switch (spec->automute_mode) {
511 case ALC_AUTOMUTE_PIN:
bb35febd 512 snd_hda_codec_write(codec, nid, 0,
e6a5e1b7
TI
513 AC_VERB_SET_PIN_WIDGET_CONTROL,
514 pin_bits);
3b8510ce
TI
515 break;
516 case ALC_AUTOMUTE_AMP:
bb35febd 517 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
e6a5e1b7 518 HDA_AMP_MUTE, mute_bits);
3b8510ce
TI
519 break;
520 case ALC_AUTOMUTE_MIXER:
521 nid = spec->automute_mixer_nid[i];
522 if (!nid)
523 break;
524 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
e6a5e1b7 525 HDA_AMP_MUTE, mute_bits);
3b8510ce 526 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1,
e6a5e1b7 527 HDA_AMP_MUTE, mute_bits);
3b8510ce 528 break;
bb35febd 529 }
a9fd4f3f 530 }
c9b58006
KY
531}
532
e6a5e1b7
TI
533/* Toggle internal speakers muting */
534static void update_speakers(struct hda_codec *codec)
535{
536 struct alc_spec *spec = codec->spec;
1a1455de 537 int on;
e6a5e1b7 538
c0a20263
TI
539 /* Control HP pins/amps depending on master_mute state;
540 * in general, HP pins/amps control should be enabled in all cases,
541 * but currently set only for master_mute, just to be safe
542 */
543 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
544 spec->autocfg.hp_pins, spec->master_mute, true);
545
1a1455de
TI
546 if (!spec->automute)
547 on = 0;
548 else
549 on = spec->jack_present | spec->line_jack_present;
550 on |= spec->master_mute;
e6a5e1b7 551 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
1a1455de 552 spec->autocfg.speaker_pins, on, false);
e6a5e1b7
TI
553
554 /* toggle line-out mutes if needed, too */
1a1455de
TI
555 /* if LO is a copy of either HP or Speaker, don't need to handle it */
556 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
557 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
e6a5e1b7 558 return;
1a1455de
TI
559 if (!spec->automute_lines || !spec->automute)
560 on = 0;
561 else
562 on = spec->jack_present;
563 on |= spec->master_mute;
e6a5e1b7 564 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
1a1455de 565 spec->autocfg.line_out_pins, on, false);
e6a5e1b7
TI
566}
567
24519911
TI
568static void call_update_speakers(struct hda_codec *codec)
569{
570 struct alc_spec *spec = codec->spec;
571 if (spec->automute_hook)
572 spec->automute_hook(codec);
573 else
574 update_speakers(codec);
575}
576
1d045db9 577/* standard HP-automute helper */
e6a5e1b7
TI
578static void alc_hp_automute(struct hda_codec *codec)
579{
580 struct alc_spec *spec = codec->spec;
581
e6a5e1b7
TI
582 spec->jack_present =
583 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
584 spec->autocfg.hp_pins);
3c715a98
TI
585 if (!spec->automute)
586 return;
24519911 587 call_update_speakers(codec);
e6a5e1b7
TI
588}
589
1d045db9 590/* standard line-out-automute helper */
e6a5e1b7
TI
591static void alc_line_automute(struct hda_codec *codec)
592{
593 struct alc_spec *spec = codec->spec;
594
e6a5e1b7
TI
595 spec->line_jack_present =
596 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
597 spec->autocfg.line_out_pins);
3c715a98
TI
598 if (!spec->automute || !spec->detect_line)
599 return;
24519911 600 call_update_speakers(codec);
e6a5e1b7
TI
601}
602
8d087c76
TI
603#define get_connection_index(codec, mux, nid) \
604 snd_hda_get_conn_index(codec, mux, nid, 0)
6c819492 605
1d045db9 606/* standard mic auto-switch helper */
7fb0d78f
KY
607static void alc_mic_automute(struct hda_codec *codec)
608{
609 struct alc_spec *spec = codec->spec;
21268961 610 hda_nid_t *pins = spec->imux_pins;
6c819492 611
21268961 612 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
6c819492
TI
613 return;
614 if (snd_BUG_ON(!spec->adc_nids))
615 return;
21268961 616 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
840b64c0 617 return;
6c819492 618
21268961
TI
619 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
620 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
621 else if (spec->dock_mic_idx >= 0 &&
622 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
623 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
624 else
625 alc_mux_select(codec, 0, spec->int_mic_idx, false);
6c819492 626
21268961
TI
627 snd_hda_input_jack_report(codec, pins[spec->ext_mic_idx]);
628 if (spec->dock_mic_idx >= 0)
629 snd_hda_input_jack_report(codec, pins[spec->dock_mic_idx]);
7fb0d78f
KY
630}
631
c9b58006
KY
632/* unsolicited event for HP jack sensing */
633static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
634{
635 if (codec->vendor_id == 0x10ec0880)
636 res >>= 28;
637 else
638 res >>= 26;
a9fd4f3f 639 switch (res) {
1d045db9 640 case ALC_HP_EVENT:
d922b51d 641 alc_hp_automute(codec);
a9fd4f3f 642 break;
1d045db9 643 case ALC_FRONT_EVENT:
e6a5e1b7
TI
644 alc_line_automute(codec);
645 break;
1d045db9 646 case ALC_MIC_EVENT:
7fb0d78f 647 alc_mic_automute(codec);
a9fd4f3f
TI
648 break;
649 }
7fb0d78f
KY
650}
651
1d045db9 652/* call init functions of standard auto-mute helpers */
7fb0d78f
KY
653static void alc_inithook(struct hda_codec *codec)
654{
d922b51d 655 alc_hp_automute(codec);
e6a5e1b7 656 alc_line_automute(codec);
7fb0d78f 657 alc_mic_automute(codec);
c9b58006
KY
658}
659
f9423e7a
KY
660/* additional initialization for ALC888 variants */
661static void alc888_coef_init(struct hda_codec *codec)
662{
663 unsigned int tmp;
664
665 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
666 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
667 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
37db623a 668 if ((tmp & 0xf0) == 0x20)
f9423e7a
KY
669 /* alc888S-VC */
670 snd_hda_codec_read(codec, 0x20, 0,
671 AC_VERB_SET_PROC_COEF, 0x830);
672 else
673 /* alc888-VB */
674 snd_hda_codec_read(codec, 0x20, 0,
675 AC_VERB_SET_PROC_COEF, 0x3030);
676}
677
1d045db9 678/* additional initialization for ALC889 variants */
87a8c370
JK
679static void alc889_coef_init(struct hda_codec *codec)
680{
681 unsigned int tmp;
682
683 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
684 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
685 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
686 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
687}
688
3fb4a508
TI
689/* turn on/off EAPD control (only if available) */
690static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
691{
692 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
693 return;
694 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
695 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
696 on ? 2 : 0);
697}
698
691f1fcc
TI
699/* turn on/off EAPD controls of the codec */
700static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
701{
702 /* We currently only handle front, HP */
39fa84e9
TI
703 static hda_nid_t pins[] = {
704 0x0f, 0x10, 0x14, 0x15, 0
705 };
706 hda_nid_t *p;
707 for (p = pins; *p; p++)
708 set_eapd(codec, *p, on);
691f1fcc
TI
709}
710
1c716153
TI
711/* generic shutup callback;
712 * just turning off EPAD and a little pause for avoiding pop-noise
713 */
714static void alc_eapd_shutup(struct hda_codec *codec)
715{
716 alc_auto_setup_eapd(codec, false);
717 msleep(200);
718}
719
1d045db9 720/* generic EAPD initialization */
4a79ba34 721static void alc_auto_init_amp(struct hda_codec *codec, int type)
bc9f98a9 722{
4a79ba34 723 unsigned int tmp;
bc9f98a9 724
39fa84e9 725 alc_auto_setup_eapd(codec, true);
4a79ba34
TI
726 switch (type) {
727 case ALC_INIT_GPIO1:
bc9f98a9
KY
728 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
729 break;
4a79ba34 730 case ALC_INIT_GPIO2:
bc9f98a9
KY
731 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
732 break;
4a79ba34 733 case ALC_INIT_GPIO3:
bdd148a3
KY
734 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
735 break;
4a79ba34 736 case ALC_INIT_DEFAULT:
c9b58006
KY
737 switch (codec->vendor_id) {
738 case 0x10ec0260:
739 snd_hda_codec_write(codec, 0x1a, 0,
740 AC_VERB_SET_COEF_INDEX, 7);
741 tmp = snd_hda_codec_read(codec, 0x1a, 0,
742 AC_VERB_GET_PROC_COEF, 0);
743 snd_hda_codec_write(codec, 0x1a, 0,
744 AC_VERB_SET_COEF_INDEX, 7);
745 snd_hda_codec_write(codec, 0x1a, 0,
746 AC_VERB_SET_PROC_COEF,
747 tmp | 0x2010);
748 break;
749 case 0x10ec0262:
750 case 0x10ec0880:
751 case 0x10ec0882:
752 case 0x10ec0883:
753 case 0x10ec0885:
4a5a4c56 754 case 0x10ec0887:
20b67ddd 755 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
87a8c370 756 alc889_coef_init(codec);
c9b58006 757 break;
f9423e7a 758 case 0x10ec0888:
4a79ba34 759 alc888_coef_init(codec);
f9423e7a 760 break;
0aea778e 761#if 0 /* XXX: This may cause the silent output on speaker on some machines */
c9b58006
KY
762 case 0x10ec0267:
763 case 0x10ec0268:
764 snd_hda_codec_write(codec, 0x20, 0,
765 AC_VERB_SET_COEF_INDEX, 7);
766 tmp = snd_hda_codec_read(codec, 0x20, 0,
767 AC_VERB_GET_PROC_COEF, 0);
768 snd_hda_codec_write(codec, 0x20, 0,
ea1fb29a 769 AC_VERB_SET_COEF_INDEX, 7);
c9b58006
KY
770 snd_hda_codec_write(codec, 0x20, 0,
771 AC_VERB_SET_PROC_COEF,
772 tmp | 0x3000);
773 break;
0aea778e 774#endif /* XXX */
bc9f98a9 775 }
4a79ba34
TI
776 break;
777 }
778}
779
1d045db9
TI
780/*
781 * Auto-Mute mode mixer enum support
782 */
1a1455de
TI
783static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
784 struct snd_ctl_elem_info *uinfo)
785{
ae8a60a5
TI
786 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
787 struct alc_spec *spec = codec->spec;
788 static const char * const texts2[] = {
789 "Disabled", "Enabled"
790 };
791 static const char * const texts3[] = {
1a1455de
TI
792 "Disabled", "Speaker Only", "Line-Out+Speaker"
793 };
ae8a60a5 794 const char * const *texts;
1a1455de
TI
795
796 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
797 uinfo->count = 1;
ae8a60a5
TI
798 if (spec->automute_hp_lo) {
799 uinfo->value.enumerated.items = 3;
800 texts = texts3;
801 } else {
802 uinfo->value.enumerated.items = 2;
803 texts = texts2;
804 }
805 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
806 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1a1455de
TI
807 strcpy(uinfo->value.enumerated.name,
808 texts[uinfo->value.enumerated.item]);
809 return 0;
810}
811
812static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
813 struct snd_ctl_elem_value *ucontrol)
814{
815 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
816 struct alc_spec *spec = codec->spec;
817 unsigned int val;
818 if (!spec->automute)
819 val = 0;
820 else if (!spec->automute_lines)
821 val = 1;
822 else
823 val = 2;
824 ucontrol->value.enumerated.item[0] = val;
825 return 0;
826}
827
828static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
829 struct snd_ctl_elem_value *ucontrol)
830{
831 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
832 struct alc_spec *spec = codec->spec;
833
834 switch (ucontrol->value.enumerated.item[0]) {
835 case 0:
836 if (!spec->automute)
837 return 0;
838 spec->automute = 0;
839 break;
840 case 1:
841 if (spec->automute && !spec->automute_lines)
842 return 0;
843 spec->automute = 1;
844 spec->automute_lines = 0;
845 break;
846 case 2:
ae8a60a5
TI
847 if (!spec->automute_hp_lo)
848 return -EINVAL;
1a1455de
TI
849 if (spec->automute && spec->automute_lines)
850 return 0;
851 spec->automute = 1;
852 spec->automute_lines = 1;
853 break;
854 default:
855 return -EINVAL;
856 }
24519911 857 call_update_speakers(codec);
1a1455de
TI
858 return 1;
859}
860
a9111321 861static const struct snd_kcontrol_new alc_automute_mode_enum = {
1a1455de
TI
862 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
863 .name = "Auto-Mute Mode",
864 .info = alc_automute_mode_info,
865 .get = alc_automute_mode_get,
866 .put = alc_automute_mode_put,
867};
868
1d045db9
TI
869static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec)
870{
871 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
872 return snd_array_new(&spec->kctls);
873}
1a1455de
TI
874
875static int alc_add_automute_mode_enum(struct hda_codec *codec)
876{
877 struct alc_spec *spec = codec->spec;
878 struct snd_kcontrol_new *knew;
879
880 knew = alc_kcontrol_new(spec);
881 if (!knew)
882 return -ENOMEM;
883 *knew = alc_automute_mode_enum;
884 knew->name = kstrdup("Auto-Mute Mode", GFP_KERNEL);
885 if (!knew->name)
886 return -ENOMEM;
887 return 0;
888}
889
1d045db9
TI
890/*
891 * Check the availability of HP/line-out auto-mute;
892 * Set up appropriately if really supported
893 */
4a79ba34
TI
894static void alc_init_auto_hp(struct hda_codec *codec)
895{
896 struct alc_spec *spec = codec->spec;
bb35febd 897 struct auto_pin_cfg *cfg = &spec->autocfg;
1daf5f46 898 int present = 0;
bb35febd 899 int i;
4a79ba34 900
1daf5f46
TI
901 if (cfg->hp_pins[0])
902 present++;
903 if (cfg->line_out_pins[0])
904 present++;
905 if (cfg->speaker_pins[0])
906 present++;
907 if (present < 2) /* need two different output types */
908 return;
ae8a60a5
TI
909 if (present == 3)
910 spec->automute_hp_lo = 1; /* both HP and LO automute */
4a79ba34 911
c48a8fb0
TI
912 if (!cfg->speaker_pins[0] &&
913 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
bb35febd
TI
914 memcpy(cfg->speaker_pins, cfg->line_out_pins,
915 sizeof(cfg->speaker_pins));
916 cfg->speaker_outs = cfg->line_outs;
917 }
918
c48a8fb0
TI
919 if (!cfg->hp_pins[0] &&
920 cfg->line_out_type == AUTO_PIN_HP_OUT) {
bb35febd
TI
921 memcpy(cfg->hp_pins, cfg->line_out_pins,
922 sizeof(cfg->hp_pins));
923 cfg->hp_outs = cfg->line_outs;
4a79ba34
TI
924 }
925
bb35febd 926 for (i = 0; i < cfg->hp_outs; i++) {
1a1455de 927 hda_nid_t nid = cfg->hp_pins[i];
06dec228 928 if (!is_jack_detectable(codec, nid))
1a1455de 929 continue;
bb35febd 930 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
1a1455de
TI
931 nid);
932 snd_hda_codec_write_cache(codec, nid, 0,
4a79ba34 933 AC_VERB_SET_UNSOLICITED_ENABLE,
1d045db9 934 AC_USRSP_EN | ALC_HP_EVENT);
d922b51d
TI
935 spec->automute = 1;
936 spec->automute_mode = ALC_AUTOMUTE_PIN;
bb35febd 937 }
1a1455de 938 if (spec->automute && cfg->line_out_pins[0] &&
c48a8fb0 939 cfg->speaker_pins[0] &&
1a1455de
TI
940 cfg->line_out_pins[0] != cfg->hp_pins[0] &&
941 cfg->line_out_pins[0] != cfg->speaker_pins[0]) {
942 for (i = 0; i < cfg->line_outs; i++) {
943 hda_nid_t nid = cfg->line_out_pins[i];
06dec228 944 if (!is_jack_detectable(codec, nid))
1a1455de
TI
945 continue;
946 snd_printdd("realtek: Enable Line-Out auto-muting "
947 "on NID 0x%x\n", nid);
948 snd_hda_codec_write_cache(codec, nid, 0,
949 AC_VERB_SET_UNSOLICITED_ENABLE,
1d045db9 950 AC_USRSP_EN | ALC_FRONT_EVENT);
1a1455de
TI
951 spec->detect_line = 1;
952 }
52d3cb88 953 spec->automute_lines = spec->detect_line;
ae8a60a5
TI
954 }
955
956 if (spec->automute) {
1a1455de
TI
957 /* create a control for automute mode */
958 alc_add_automute_mode_enum(codec);
ae8a60a5 959 spec->unsol_event = alc_sku_unsol_event;
1a1455de 960 }
4a79ba34
TI
961}
962
1d045db9 963/* return the position of NID in the list, or -1 if not found */
21268961
TI
964static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
965{
966 int i;
967 for (i = 0; i < nums; i++)
968 if (list[i] == nid)
969 return i;
970 return -1;
971}
972
1d045db9
TI
973/* check whether dynamic ADC-switching is available */
974static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
975{
976 struct alc_spec *spec = codec->spec;
977 struct hda_input_mux *imux = &spec->private_imux[0];
978 int i, n, idx;
979 hda_nid_t cap, pin;
980
981 if (imux != spec->input_mux) /* no dynamic imux? */
982 return false;
983
984 for (n = 0; n < spec->num_adc_nids; n++) {
985 cap = spec->private_capsrc_nids[n];
986 for (i = 0; i < imux->num_items; i++) {
987 pin = spec->imux_pins[i];
988 if (!pin)
989 return false;
990 if (get_connection_index(codec, cap, pin) < 0)
991 break;
992 }
993 if (i >= imux->num_items)
268ff6fb 994 return true; /* no ADC-switch is needed */
1d045db9
TI
995 }
996
997 for (i = 0; i < imux->num_items; i++) {
998 pin = spec->imux_pins[i];
999 for (n = 0; n < spec->num_adc_nids; n++) {
1000 cap = spec->private_capsrc_nids[n];
1001 idx = get_connection_index(codec, cap, pin);
1002 if (idx >= 0) {
1003 imux->items[i].index = idx;
1004 spec->dyn_adc_idx[i] = n;
1005 break;
1006 }
1007 }
1008 }
1009
1010 snd_printdd("realtek: enabling ADC switching\n");
1011 spec->dyn_adc_switch = 1;
1012 return true;
1013}
21268961
TI
1014
1015/* rebuild imux for matching with the given auto-mic pins (if not yet) */
1016static bool alc_rebuild_imux_for_auto_mic(struct hda_codec *codec)
1017{
1018 struct alc_spec *spec = codec->spec;
1019 struct hda_input_mux *imux;
1020 static char * const texts[3] = {
1021 "Mic", "Internal Mic", "Dock Mic"
1022 };
1023 int i;
1024
1025 if (!spec->auto_mic)
1026 return false;
1027 imux = &spec->private_imux[0];
1028 if (spec->input_mux == imux)
1029 return true;
1030 spec->imux_pins[0] = spec->ext_mic_pin;
1031 spec->imux_pins[1] = spec->int_mic_pin;
1032 spec->imux_pins[2] = spec->dock_mic_pin;
1033 for (i = 0; i < 3; i++) {
1034 strcpy(imux->items[i].label, texts[i]);
1035 if (spec->imux_pins[i])
1036 imux->num_items = i + 1;
1037 }
1038 spec->num_mux_defs = 1;
1039 spec->input_mux = imux;
1040 return true;
1041}
1042
1043/* check whether all auto-mic pins are valid; setup indices if OK */
1044static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1045{
1046 struct alc_spec *spec = codec->spec;
1047 const struct hda_input_mux *imux;
1048
1049 if (!spec->auto_mic)
1050 return false;
1051 if (spec->auto_mic_valid_imux)
1052 return true; /* already checked */
1053
1054 /* fill up imux indices */
1055 if (!alc_check_dyn_adc_switch(codec)) {
1056 spec->auto_mic = 0;
1057 return false;
1058 }
1059
1060 imux = spec->input_mux;
1061 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1062 spec->imux_pins, imux->num_items);
1063 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1064 spec->imux_pins, imux->num_items);
1065 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1066 spec->imux_pins, imux->num_items);
1067 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1068 spec->auto_mic = 0;
1069 return false; /* no corresponding imux */
1070 }
1071
1072 snd_hda_codec_write_cache(codec, spec->ext_mic_pin, 0,
1073 AC_VERB_SET_UNSOLICITED_ENABLE,
1d045db9 1074 AC_USRSP_EN | ALC_MIC_EVENT);
21268961
TI
1075 if (spec->dock_mic_pin)
1076 snd_hda_codec_write_cache(codec, spec->dock_mic_pin, 0,
1077 AC_VERB_SET_UNSOLICITED_ENABLE,
1d045db9 1078 AC_USRSP_EN | ALC_MIC_EVENT);
21268961
TI
1079
1080 spec->auto_mic_valid_imux = 1;
1081 spec->auto_mic = 1;
1082 return true;
1083}
1084
1d045db9
TI
1085/*
1086 * Check the availability of auto-mic switch;
1087 * Set up if really supported
1088 */
6c819492
TI
1089static void alc_init_auto_mic(struct hda_codec *codec)
1090{
1091 struct alc_spec *spec = codec->spec;
1092 struct auto_pin_cfg *cfg = &spec->autocfg;
8ed99d97 1093 hda_nid_t fixed, ext, dock;
6c819492
TI
1094 int i;
1095
21268961
TI
1096 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1097
8ed99d97 1098 fixed = ext = dock = 0;
66ceeb6b
TI
1099 for (i = 0; i < cfg->num_inputs; i++) {
1100 hda_nid_t nid = cfg->inputs[i].pin;
6c819492 1101 unsigned int defcfg;
6c819492 1102 defcfg = snd_hda_codec_get_pincfg(codec, nid);
99ae28be
TI
1103 switch (snd_hda_get_input_pin_attr(defcfg)) {
1104 case INPUT_PIN_ATTR_INT:
6c819492
TI
1105 if (fixed)
1106 return; /* already occupied */
8ed99d97
TI
1107 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1108 return; /* invalid type */
6c819492
TI
1109 fixed = nid;
1110 break;
99ae28be
TI
1111 case INPUT_PIN_ATTR_UNUSED:
1112 return; /* invalid entry */
8ed99d97
TI
1113 case INPUT_PIN_ATTR_DOCK:
1114 if (dock)
1115 return; /* already occupied */
1116 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1117 return; /* invalid type */
1118 dock = nid;
1119 break;
99ae28be 1120 default:
6c819492
TI
1121 if (ext)
1122 return; /* already occupied */
8ed99d97
TI
1123 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1124 return; /* invalid type */
6c819492
TI
1125 ext = nid;
1126 break;
6c819492
TI
1127 }
1128 }
8ed99d97
TI
1129 if (!ext && dock) {
1130 ext = dock;
1131 dock = 0;
1132 }
eaa9b3a7
TI
1133 if (!ext || !fixed)
1134 return;
e35d9d6a 1135 if (!is_jack_detectable(codec, ext))
6c819492 1136 return; /* no unsol support */
8ed99d97
TI
1137 if (dock && !is_jack_detectable(codec, dock))
1138 return; /* no unsol support */
21268961
TI
1139
1140 /* check imux indices */
1141 spec->ext_mic_pin = ext;
1142 spec->int_mic_pin = fixed;
1143 spec->dock_mic_pin = dock;
1144
1145 spec->auto_mic = 1;
1146 if (!alc_auto_mic_check_imux(codec))
1147 return;
1148
8ed99d97
TI
1149 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1150 ext, fixed, dock);
6c819492
TI
1151 spec->unsol_event = alc_sku_unsol_event;
1152}
1153
1d045db9
TI
1154/* check the availabilities of auto-mute and auto-mic switches */
1155static void alc_auto_check_switches(struct hda_codec *codec)
1156{
1157 alc_init_auto_hp(codec);
1158 alc_init_auto_mic(codec);
1159}
1160
1161/*
1162 * Realtek SSID verification
1163 */
1164
90622917
DH
1165/* Could be any non-zero and even value. When used as fixup, tells
1166 * the driver to ignore any present sku defines.
1167 */
1168#define ALC_FIXUP_SKU_IGNORE (2)
1169
da00c244
KY
1170static int alc_auto_parse_customize_define(struct hda_codec *codec)
1171{
1172 unsigned int ass, tmp, i;
7fb56223 1173 unsigned nid = 0;
da00c244
KY
1174 struct alc_spec *spec = codec->spec;
1175
b6cbe517
TI
1176 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1177
90622917
DH
1178 if (spec->cdefine.fixup) {
1179 ass = spec->cdefine.sku_cfg;
1180 if (ass == ALC_FIXUP_SKU_IGNORE)
1181 return -1;
1182 goto do_sku;
1183 }
1184
da00c244 1185 ass = codec->subsystem_id & 0xffff;
b6cbe517 1186 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
da00c244
KY
1187 goto do_sku;
1188
1189 nid = 0x1d;
1190 if (codec->vendor_id == 0x10ec0260)
1191 nid = 0x17;
1192 ass = snd_hda_codec_get_pincfg(codec, nid);
1193
1194 if (!(ass & 1)) {
1195 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1196 codec->chip_name, ass);
1197 return -1;
1198 }
1199
1200 /* check sum */
1201 tmp = 0;
1202 for (i = 1; i < 16; i++) {
1203 if ((ass >> i) & 1)
1204 tmp++;
1205 }
1206 if (((ass >> 16) & 0xf) != tmp)
1207 return -1;
1208
1209 spec->cdefine.port_connectivity = ass >> 30;
1210 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1211 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1212 spec->cdefine.customization = ass >> 8;
1213do_sku:
1214 spec->cdefine.sku_cfg = ass;
1215 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1216 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1217 spec->cdefine.swap = (ass & 0x2) >> 1;
1218 spec->cdefine.override = ass & 0x1;
1219
1220 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1221 nid, spec->cdefine.sku_cfg);
1222 snd_printd("SKU: port_connectivity=0x%x\n",
1223 spec->cdefine.port_connectivity);
1224 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1225 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1226 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1227 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1228 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1229 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1230 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1231
1232 return 0;
1233}
1234
1d045db9 1235/* return true if the given NID is found in the list */
3af9ee6b
TI
1236static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1237{
21268961 1238 return find_idx_in_nid_list(nid, list, nums) >= 0;
3af9ee6b
TI
1239}
1240
4a79ba34
TI
1241/* check subsystem ID and set up device-specific initialization;
1242 * return 1 if initialized, 0 if invalid SSID
1243 */
1244/* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1245 * 31 ~ 16 : Manufacture ID
1246 * 15 ~ 8 : SKU ID
1247 * 7 ~ 0 : Assembly ID
1248 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1249 */
1250static int alc_subsystem_id(struct hda_codec *codec,
1251 hda_nid_t porta, hda_nid_t porte,
6227cdce 1252 hda_nid_t portd, hda_nid_t porti)
4a79ba34
TI
1253{
1254 unsigned int ass, tmp, i;
1255 unsigned nid;
1256 struct alc_spec *spec = codec->spec;
1257
90622917
DH
1258 if (spec->cdefine.fixup) {
1259 ass = spec->cdefine.sku_cfg;
1260 if (ass == ALC_FIXUP_SKU_IGNORE)
1261 return 0;
1262 goto do_sku;
1263 }
1264
4a79ba34
TI
1265 ass = codec->subsystem_id & 0xffff;
1266 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1267 goto do_sku;
1268
1269 /* invalid SSID, check the special NID pin defcfg instead */
1270 /*
def319f9 1271 * 31~30 : port connectivity
4a79ba34
TI
1272 * 29~21 : reserve
1273 * 20 : PCBEEP input
1274 * 19~16 : Check sum (15:1)
1275 * 15~1 : Custom
1276 * 0 : override
1277 */
1278 nid = 0x1d;
1279 if (codec->vendor_id == 0x10ec0260)
1280 nid = 0x17;
1281 ass = snd_hda_codec_get_pincfg(codec, nid);
1282 snd_printd("realtek: No valid SSID, "
1283 "checking pincfg 0x%08x for NID 0x%x\n",
cb6605c1 1284 ass, nid);
6227cdce 1285 if (!(ass & 1))
4a79ba34
TI
1286 return 0;
1287 if ((ass >> 30) != 1) /* no physical connection */
1288 return 0;
1289
1290 /* check sum */
1291 tmp = 0;
1292 for (i = 1; i < 16; i++) {
1293 if ((ass >> i) & 1)
1294 tmp++;
1295 }
1296 if (((ass >> 16) & 0xf) != tmp)
1297 return 0;
1298do_sku:
1299 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1300 ass & 0xffff, codec->vendor_id);
1301 /*
1302 * 0 : override
1303 * 1 : Swap Jack
1304 * 2 : 0 --> Desktop, 1 --> Laptop
1305 * 3~5 : External Amplifier control
1306 * 7~6 : Reserved
1307 */
1308 tmp = (ass & 0x38) >> 3; /* external Amp control */
1309 switch (tmp) {
1310 case 1:
1311 spec->init_amp = ALC_INIT_GPIO1;
1312 break;
1313 case 3:
1314 spec->init_amp = ALC_INIT_GPIO2;
1315 break;
1316 case 7:
1317 spec->init_amp = ALC_INIT_GPIO3;
1318 break;
1319 case 5:
5a8cfb4e 1320 default:
4a79ba34 1321 spec->init_amp = ALC_INIT_DEFAULT;
bc9f98a9
KY
1322 break;
1323 }
ea1fb29a 1324
8c427226 1325 /* is laptop or Desktop and enable the function "Mute internal speaker
c9b58006
KY
1326 * when the external headphone out jack is plugged"
1327 */
8c427226 1328 if (!(ass & 0x8000))
4a79ba34 1329 return 1;
c9b58006
KY
1330 /*
1331 * 10~8 : Jack location
1332 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1333 * 14~13: Resvered
1334 * 15 : 1 --> enable the function "Mute internal speaker
1335 * when the external headphone out jack is plugged"
1336 */
c9b58006 1337 if (!spec->autocfg.hp_pins[0]) {
01d4825d 1338 hda_nid_t nid;
c9b58006
KY
1339 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1340 if (tmp == 0)
01d4825d 1341 nid = porta;
c9b58006 1342 else if (tmp == 1)
01d4825d 1343 nid = porte;
c9b58006 1344 else if (tmp == 2)
01d4825d 1345 nid = portd;
6227cdce
KY
1346 else if (tmp == 3)
1347 nid = porti;
c9b58006 1348 else
4a79ba34 1349 return 1;
3af9ee6b
TI
1350 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1351 spec->autocfg.line_outs))
1352 return 1;
01d4825d 1353 spec->autocfg.hp_pins[0] = nid;
c9b58006 1354 }
4a79ba34
TI
1355 return 1;
1356}
ea1fb29a 1357
3e6179b8
TI
1358/* Check the validity of ALC subsystem-id
1359 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1360static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
4a79ba34 1361{
3e6179b8 1362 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
4a79ba34
TI
1363 struct alc_spec *spec = codec->spec;
1364 snd_printd("realtek: "
1365 "Enable default setup for auto mode as fallback\n");
1366 spec->init_amp = ALC_INIT_DEFAULT;
4a79ba34 1367 }
21268961 1368}
1a1455de 1369
f95474ec 1370/*
f8f25ba3 1371 * Fix-up pin default configurations and add default verbs
f95474ec
TI
1372 */
1373
1374struct alc_pincfg {
1375 hda_nid_t nid;
1376 u32 val;
1377};
1378
e1eb5f10
TB
1379struct alc_model_fixup {
1380 const int id;
1381 const char *name;
1382};
1383
f8f25ba3 1384struct alc_fixup {
b5bfbc67 1385 int type;
361fe6e9
TI
1386 bool chained;
1387 int chain_id;
b5bfbc67
TI
1388 union {
1389 unsigned int sku;
1390 const struct alc_pincfg *pins;
1391 const struct hda_verb *verbs;
1392 void (*func)(struct hda_codec *codec,
1393 const struct alc_fixup *fix,
1394 int action);
1395 } v;
f8f25ba3
TI
1396};
1397
b5bfbc67
TI
1398enum {
1399 ALC_FIXUP_INVALID,
1400 ALC_FIXUP_SKU,
1401 ALC_FIXUP_PINS,
1402 ALC_FIXUP_VERBS,
1403 ALC_FIXUP_FUNC,
1404};
1405
1406enum {
1407 ALC_FIXUP_ACT_PRE_PROBE,
1408 ALC_FIXUP_ACT_PROBE,
58701120 1409 ALC_FIXUP_ACT_INIT,
b5bfbc67
TI
1410};
1411
1412static void alc_apply_fixup(struct hda_codec *codec, int action)
f95474ec 1413{
b5bfbc67
TI
1414 struct alc_spec *spec = codec->spec;
1415 int id = spec->fixup_id;
aa1d0c52 1416#ifdef CONFIG_SND_DEBUG_VERBOSE
b5bfbc67 1417 const char *modelname = spec->fixup_name;
aa1d0c52 1418#endif
b5bfbc67 1419 int depth = 0;
f95474ec 1420
b5bfbc67
TI
1421 if (!spec->fixup_list)
1422 return;
1423
1424 while (id >= 0) {
1425 const struct alc_fixup *fix = spec->fixup_list + id;
1426 const struct alc_pincfg *cfg;
1427
1428 switch (fix->type) {
1429 case ALC_FIXUP_SKU:
1430 if (action != ALC_FIXUP_ACT_PRE_PROBE || !fix->v.sku)
1431 break;;
1432 snd_printdd(KERN_INFO "hda_codec: %s: "
1433 "Apply sku override for %s\n",
1434 codec->chip_name, modelname);
1435 spec->cdefine.sku_cfg = fix->v.sku;
1436 spec->cdefine.fixup = 1;
1437 break;
1438 case ALC_FIXUP_PINS:
1439 cfg = fix->v.pins;
1440 if (action != ALC_FIXUP_ACT_PRE_PROBE || !cfg)
1441 break;
1442 snd_printdd(KERN_INFO "hda_codec: %s: "
1443 "Apply pincfg for %s\n",
1444 codec->chip_name, modelname);
1445 for (; cfg->nid; cfg++)
1446 snd_hda_codec_set_pincfg(codec, cfg->nid,
1447 cfg->val);
1448 break;
1449 case ALC_FIXUP_VERBS:
1450 if (action != ALC_FIXUP_ACT_PROBE || !fix->v.verbs)
1451 break;
1452 snd_printdd(KERN_INFO "hda_codec: %s: "
1453 "Apply fix-verbs for %s\n",
1454 codec->chip_name, modelname);
1455 add_verb(codec->spec, fix->v.verbs);
1456 break;
1457 case ALC_FIXUP_FUNC:
1458 if (!fix->v.func)
1459 break;
1460 snd_printdd(KERN_INFO "hda_codec: %s: "
1461 "Apply fix-func for %s\n",
1462 codec->chip_name, modelname);
1463 fix->v.func(codec, fix, action);
1464 break;
1465 default:
1466 snd_printk(KERN_ERR "hda_codec: %s: "
1467 "Invalid fixup type %d\n",
1468 codec->chip_name, fix->type);
1469 break;
1470 }
24af2b1c 1471 if (!fix->chained)
b5bfbc67
TI
1472 break;
1473 if (++depth > 10)
1474 break;
24af2b1c 1475 id = fix->chain_id;
9d57883f 1476 }
f95474ec
TI
1477}
1478
e1eb5f10 1479static void alc_pick_fixup(struct hda_codec *codec,
b5bfbc67
TI
1480 const struct alc_model_fixup *models,
1481 const struct snd_pci_quirk *quirk,
1482 const struct alc_fixup *fixlist)
e1eb5f10 1483{
b5bfbc67
TI
1484 struct alc_spec *spec = codec->spec;
1485 int id = -1;
1486 const char *name = NULL;
e1eb5f10 1487
e1eb5f10
TB
1488 if (codec->modelname && models) {
1489 while (models->name) {
1490 if (!strcmp(codec->modelname, models->name)) {
b5bfbc67
TI
1491 id = models->id;
1492 name = models->name;
e1eb5f10
TB
1493 break;
1494 }
1495 models++;
1496 }
b5bfbc67
TI
1497 }
1498 if (id < 0) {
1499 quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1500 if (quirk) {
1501 id = quirk->value;
1502#ifdef CONFIG_SND_DEBUG_VERBOSE
1503 name = quirk->name;
1504#endif
1505 }
1506 }
1507
1508 spec->fixup_id = id;
1509 if (id >= 0) {
1510 spec->fixup_list = fixlist;
1511 spec->fixup_name = name;
e1eb5f10 1512 }
f95474ec
TI
1513}
1514
1d045db9
TI
1515/*
1516 * COEF access helper functions
1517 */
274693f3
KY
1518static int alc_read_coef_idx(struct hda_codec *codec,
1519 unsigned int coef_idx)
1520{
1521 unsigned int val;
1522 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1523 coef_idx);
1524 val = snd_hda_codec_read(codec, 0x20, 0,
1525 AC_VERB_GET_PROC_COEF, 0);
1526 return val;
1527}
1528
977ddd6b
KY
1529static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1530 unsigned int coef_val)
1531{
1532 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1533 coef_idx);
1534 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1535 coef_val);
1536}
1537
1d045db9
TI
1538/*
1539 * Digital I/O handling
1540 */
1541
757899ac
TI
1542/* set right pin controls for digital I/O */
1543static void alc_auto_init_digital(struct hda_codec *codec)
1544{
1545 struct alc_spec *spec = codec->spec;
1546 int i;
1f0f4b80 1547 hda_nid_t pin, dac;
757899ac
TI
1548
1549 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1550 pin = spec->autocfg.dig_out_pins[i];
1f0f4b80
TI
1551 if (!pin)
1552 continue;
1553 snd_hda_codec_write(codec, pin, 0,
1554 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
1555 if (!i)
1556 dac = spec->multiout.dig_out_nid;
1557 else
1558 dac = spec->slave_dig_outs[i - 1];
1559 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
1560 continue;
1561 snd_hda_codec_write(codec, dac, 0,
1562 AC_VERB_SET_AMP_GAIN_MUTE,
1563 AMP_OUT_UNMUTE);
757899ac
TI
1564 }
1565 pin = spec->autocfg.dig_in_pin;
1566 if (pin)
1567 snd_hda_codec_write(codec, pin, 0,
1568 AC_VERB_SET_PIN_WIDGET_CONTROL,
1569 PIN_IN);
1570}
1571
1572/* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1573static void alc_auto_parse_digital(struct hda_codec *codec)
1574{
1575 struct alc_spec *spec = codec->spec;
1576 int i, err;
1577 hda_nid_t dig_nid;
1578
1579 /* support multiple SPDIFs; the secondary is set up as a slave */
1580 for (i = 0; i < spec->autocfg.dig_outs; i++) {
a926757f 1581 hda_nid_t conn[4];
757899ac
TI
1582 err = snd_hda_get_connections(codec,
1583 spec->autocfg.dig_out_pins[i],
a926757f 1584 conn, ARRAY_SIZE(conn));
757899ac
TI
1585 if (err < 0)
1586 continue;
a926757f 1587 dig_nid = conn[0]; /* assume the first element is audio-out */
757899ac
TI
1588 if (!i) {
1589 spec->multiout.dig_out_nid = dig_nid;
1590 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1591 } else {
1592 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
1593 if (i >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
1594 break;
1595 spec->slave_dig_outs[i - 1] = dig_nid;
1596 }
1597 }
1598
1599 if (spec->autocfg.dig_in_pin) {
01fdf180
TI
1600 dig_nid = codec->start_nid;
1601 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1602 unsigned int wcaps = get_wcaps(codec, dig_nid);
1603 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1604 continue;
1605 if (!(wcaps & AC_WCAP_DIGITAL))
1606 continue;
1607 if (!(wcaps & AC_WCAP_CONN_LIST))
1608 continue;
1609 err = get_connection_index(codec, dig_nid,
1610 spec->autocfg.dig_in_pin);
1611 if (err >= 0) {
1612 spec->dig_in_nid = dig_nid;
1613 break;
1614 }
1615 }
757899ac
TI
1616 }
1617}
1618
ef8ef5fb 1619/*
1d045db9 1620 * capture mixer elements
ef8ef5fb 1621 */
f9e336f6
TI
1622static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1623 struct snd_ctl_elem_info *uinfo)
1624{
1625 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1626 struct alc_spec *spec = codec->spec;
d6cc9fab 1627 unsigned long val;
f9e336f6 1628 int err;
1da177e4 1629
5a9e02e9 1630 mutex_lock(&codec->control_mutex);
d6cc9fab
TI
1631 if (spec->vol_in_capsrc)
1632 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1633 else
1634 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1635 kcontrol->private_value = val;
f9e336f6 1636 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
5a9e02e9 1637 mutex_unlock(&codec->control_mutex);
f9e336f6
TI
1638 return err;
1639}
1640
1641static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1642 unsigned int size, unsigned int __user *tlv)
1643{
1644 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1645 struct alc_spec *spec = codec->spec;
d6cc9fab 1646 unsigned long val;
f9e336f6 1647 int err;
1da177e4 1648
5a9e02e9 1649 mutex_lock(&codec->control_mutex);
d6cc9fab
TI
1650 if (spec->vol_in_capsrc)
1651 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1652 else
1653 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1654 kcontrol->private_value = val;
f9e336f6 1655 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
5a9e02e9 1656 mutex_unlock(&codec->control_mutex);
f9e336f6
TI
1657 return err;
1658}
1659
1660typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1661 struct snd_ctl_elem_value *ucontrol);
1662
1663static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1664 struct snd_ctl_elem_value *ucontrol,
9c7a083d 1665 getput_call_t func, bool check_adc_switch)
f9e336f6
TI
1666{
1667 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1668 struct alc_spec *spec = codec->spec;
21268961 1669 int i, err = 0;
f9e336f6 1670
5a9e02e9 1671 mutex_lock(&codec->control_mutex);
21268961 1672 if (check_adc_switch && spec->dyn_adc_switch) {
9c7a083d
TI
1673 for (i = 0; i < spec->num_adc_nids; i++) {
1674 kcontrol->private_value =
1675 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1676 3, 0, HDA_INPUT);
1677 err = func(kcontrol, ucontrol);
1678 if (err < 0)
1679 goto error;
1680 }
1681 } else {
1682 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
d6cc9fab
TI
1683 if (spec->vol_in_capsrc)
1684 kcontrol->private_value =
1685 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1686 3, 0, HDA_OUTPUT);
1687 else
1688 kcontrol->private_value =
21268961
TI
1689 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1690 3, 0, HDA_INPUT);
9c7a083d
TI
1691 err = func(kcontrol, ucontrol);
1692 }
1693 error:
5a9e02e9 1694 mutex_unlock(&codec->control_mutex);
f9e336f6
TI
1695 return err;
1696}
1697
1698static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1699 struct snd_ctl_elem_value *ucontrol)
1700{
1701 return alc_cap_getput_caller(kcontrol, ucontrol,
9c7a083d 1702 snd_hda_mixer_amp_volume_get, false);
f9e336f6
TI
1703}
1704
1705static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1706 struct snd_ctl_elem_value *ucontrol)
1707{
1708 return alc_cap_getput_caller(kcontrol, ucontrol,
9c7a083d 1709 snd_hda_mixer_amp_volume_put, true);
f9e336f6
TI
1710}
1711
1712/* capture mixer elements */
1713#define alc_cap_sw_info snd_ctl_boolean_stereo_info
1714
1715static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1716 struct snd_ctl_elem_value *ucontrol)
1717{
1718 return alc_cap_getput_caller(kcontrol, ucontrol,
9c7a083d 1719 snd_hda_mixer_amp_switch_get, false);
f9e336f6
TI
1720}
1721
1722static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1723 struct snd_ctl_elem_value *ucontrol)
1724{
1725 return alc_cap_getput_caller(kcontrol, ucontrol,
9c7a083d 1726 snd_hda_mixer_amp_switch_put, true);
f9e336f6
TI
1727}
1728
a23b688f 1729#define _DEFINE_CAPMIX(num) \
f9e336f6
TI
1730 { \
1731 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1732 .name = "Capture Switch", \
1733 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1734 .count = num, \
1735 .info = alc_cap_sw_info, \
1736 .get = alc_cap_sw_get, \
1737 .put = alc_cap_sw_put, \
1738 }, \
1739 { \
1740 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1741 .name = "Capture Volume", \
1742 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1743 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1744 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1745 .count = num, \
1746 .info = alc_cap_vol_info, \
1747 .get = alc_cap_vol_get, \
1748 .put = alc_cap_vol_put, \
1749 .tlv = { .c = alc_cap_vol_tlv }, \
a23b688f
TI
1750 }
1751
1752#define _DEFINE_CAPSRC(num) \
3c3e9892
TI
1753 { \
1754 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1755 /* .name = "Capture Source", */ \
1756 .name = "Input Source", \
1757 .count = num, \
1758 .info = alc_mux_enum_info, \
1759 .get = alc_mux_enum_get, \
1760 .put = alc_mux_enum_put, \
a23b688f
TI
1761 }
1762
1763#define DEFINE_CAPMIX(num) \
a9111321 1764static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
a23b688f
TI
1765 _DEFINE_CAPMIX(num), \
1766 _DEFINE_CAPSRC(num), \
1767 { } /* end */ \
1768}
1769
1770#define DEFINE_CAPMIX_NOSRC(num) \
a9111321 1771static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
a23b688f
TI
1772 _DEFINE_CAPMIX(num), \
1773 { } /* end */ \
f9e336f6
TI
1774}
1775
1776/* up to three ADCs */
1777DEFINE_CAPMIX(1);
1778DEFINE_CAPMIX(2);
1779DEFINE_CAPMIX(3);
a23b688f
TI
1780DEFINE_CAPMIX_NOSRC(1);
1781DEFINE_CAPMIX_NOSRC(2);
1782DEFINE_CAPMIX_NOSRC(3);
e9edcee0
TI
1783
1784/*
1d045db9 1785 * virtual master controls
e9edcee0
TI
1786 */
1787
e9edcee0 1788/*
1d045db9 1789 * slave controls for virtual master
e9edcee0 1790 */
1d045db9
TI
1791static const char * const alc_slave_vols[] = {
1792 "Front Playback Volume",
1793 "Surround Playback Volume",
1794 "Center Playback Volume",
1795 "LFE Playback Volume",
1796 "Side Playback Volume",
1797 "Headphone Playback Volume",
1798 "Speaker Playback Volume",
1799 "Mono Playback Volume",
1800 "Line-Out Playback Volume",
3fe45aea 1801 "PCM Playback Volume",
1d045db9 1802 NULL,
e9edcee0
TI
1803};
1804
1d045db9
TI
1805static const char * const alc_slave_sws[] = {
1806 "Front Playback Switch",
1807 "Surround Playback Switch",
1808 "Center Playback Switch",
1809 "LFE Playback Switch",
1810 "Side Playback Switch",
1811 "Headphone Playback Switch",
1812 "Speaker Playback Switch",
1813 "Mono Playback Switch",
1814 "IEC958 Playback Switch",
1815 "Line-Out Playback Switch",
3fe45aea 1816 "PCM Playback Switch",
1d045db9 1817 NULL,
16ded525
TI
1818};
1819
e9edcee0 1820/*
1d045db9 1821 * build control elements
e9edcee0
TI
1822 */
1823
1d045db9 1824#define NID_MAPPING (-1)
e9edcee0 1825
1d045db9
TI
1826#define SUBDEV_SPEAKER_ (0 << 6)
1827#define SUBDEV_HP_ (1 << 6)
1828#define SUBDEV_LINE_ (2 << 6)
1829#define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1830#define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1831#define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
e9edcee0 1832
1d045db9 1833static void alc_free_kctls(struct hda_codec *codec);
e9edcee0 1834
1d045db9
TI
1835#ifdef CONFIG_SND_HDA_INPUT_BEEP
1836/* additional beep mixers; the actual parameters are overwritten at build */
1837static const struct snd_kcontrol_new alc_beep_mixer[] = {
1838 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
1839 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
16ded525
TI
1840 { } /* end */
1841};
1d045db9 1842#endif
16ded525 1843
1d045db9
TI
1844static int alc_build_controls(struct hda_codec *codec)
1845{
1846 struct alc_spec *spec = codec->spec;
1847 struct snd_kcontrol *kctl = NULL;
1848 const struct snd_kcontrol_new *knew;
1849 int i, j, err;
1850 unsigned int u;
1851 hda_nid_t nid;
1da177e4
LT
1852
1853 for (i = 0; i < spec->num_mixers; i++) {
1854 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1855 if (err < 0)
1856 return err;
1857 }
f9e336f6
TI
1858 if (spec->cap_mixer) {
1859 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1860 if (err < 0)
1861 return err;
1862 }
1da177e4 1863 if (spec->multiout.dig_out_nid) {
9c7f852e 1864 err = snd_hda_create_spdif_out_ctls(codec,
74b654c9 1865 spec->multiout.dig_out_nid,
9c7f852e 1866 spec->multiout.dig_out_nid);
1da177e4
LT
1867 if (err < 0)
1868 return err;
e64f14f4
TI
1869 if (!spec->no_analog) {
1870 err = snd_hda_create_spdif_share_sw(codec,
1871 &spec->multiout);
1872 if (err < 0)
1873 return err;
1874 spec->multiout.share_spdif = 1;
1875 }
1da177e4
LT
1876 }
1877 if (spec->dig_in_nid) {
1878 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1879 if (err < 0)
1880 return err;
1881 }
2134ea4f 1882
67d634c0 1883#ifdef CONFIG_SND_HDA_INPUT_BEEP
45bdd1c1
TI
1884 /* create beep controls if needed */
1885 if (spec->beep_amp) {
a9111321 1886 const struct snd_kcontrol_new *knew;
45bdd1c1
TI
1887 for (knew = alc_beep_mixer; knew->name; knew++) {
1888 struct snd_kcontrol *kctl;
1889 kctl = snd_ctl_new1(knew, codec);
1890 if (!kctl)
1891 return -ENOMEM;
1892 kctl->private_value = spec->beep_amp;
5e26dfd0 1893 err = snd_hda_ctl_add(codec, 0, kctl);
45bdd1c1
TI
1894 if (err < 0)
1895 return err;
1896 }
1897 }
67d634c0 1898#endif
45bdd1c1 1899
2134ea4f 1900 /* if we have no master control, let's create it */
e64f14f4
TI
1901 if (!spec->no_analog &&
1902 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1c82ed1b 1903 unsigned int vmaster_tlv[4];
2134ea4f 1904 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
1c82ed1b 1905 HDA_OUTPUT, vmaster_tlv);
2134ea4f 1906 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1c82ed1b 1907 vmaster_tlv, alc_slave_vols);
2134ea4f
TI
1908 if (err < 0)
1909 return err;
1910 }
e64f14f4
TI
1911 if (!spec->no_analog &&
1912 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
2134ea4f
TI
1913 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1914 NULL, alc_slave_sws);
1915 if (err < 0)
1916 return err;
1917 }
1918
5b0cb1d8 1919 /* assign Capture Source enums to NID */
fbe618f2
TI
1920 if (spec->capsrc_nids || spec->adc_nids) {
1921 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
1922 if (!kctl)
1923 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1924 for (i = 0; kctl && i < kctl->count; i++) {
4c6d72d1 1925 const hda_nid_t *nids = spec->capsrc_nids;
fbe618f2
TI
1926 if (!nids)
1927 nids = spec->adc_nids;
1928 err = snd_hda_add_nid(codec, kctl, i, nids[i]);
1929 if (err < 0)
1930 return err;
1931 }
5b0cb1d8 1932 }
60a6a842 1933 if (spec->cap_mixer && spec->adc_nids) {
5b0cb1d8
JK
1934 const char *kname = kctl ? kctl->id.name : NULL;
1935 for (knew = spec->cap_mixer; knew->name; knew++) {
1936 if (kname && strcmp(knew->name, kname) == 0)
1937 continue;
1938 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1939 for (i = 0; kctl && i < kctl->count; i++) {
1940 err = snd_hda_add_nid(codec, kctl, i,
1941 spec->adc_nids[i]);
1942 if (err < 0)
1943 return err;
1944 }
1945 }
1946 }
1947
1948 /* other nid->control mapping */
1949 for (i = 0; i < spec->num_mixers; i++) {
1950 for (knew = spec->mixers[i]; knew->name; knew++) {
1951 if (knew->iface != NID_MAPPING)
1952 continue;
1953 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1954 if (kctl == NULL)
1955 continue;
1956 u = knew->subdevice;
1957 for (j = 0; j < 4; j++, u >>= 8) {
1958 nid = u & 0x3f;
1959 if (nid == 0)
1960 continue;
1961 switch (u & 0xc0) {
1962 case SUBDEV_SPEAKER_:
1963 nid = spec->autocfg.speaker_pins[nid];
1964 break;
1965 case SUBDEV_LINE_:
1966 nid = spec->autocfg.line_out_pins[nid];
1967 break;
1968 case SUBDEV_HP_:
1969 nid = spec->autocfg.hp_pins[nid];
1970 break;
1971 default:
1972 continue;
1973 }
1974 err = snd_hda_add_nid(codec, kctl, 0, nid);
1975 if (err < 0)
1976 return err;
1977 }
1978 u = knew->private_value;
1979 for (j = 0; j < 4; j++, u >>= 8) {
1980 nid = u & 0xff;
1981 if (nid == 0)
1982 continue;
1983 err = snd_hda_add_nid(codec, kctl, 0, nid);
1984 if (err < 0)
1985 return err;
1986 }
1987 }
1988 }
bae84e70
TI
1989
1990 alc_free_kctls(codec); /* no longer needed */
1991
1da177e4
LT
1992 return 0;
1993}
1994
e9edcee0 1995
1da177e4 1996/*
1d045db9 1997 * Common callbacks
e9edcee0 1998 */
1da177e4 1999
1d045db9 2000static void alc_init_special_input_src(struct hda_codec *codec);
1da177e4 2001
1d045db9
TI
2002static int alc_init(struct hda_codec *codec)
2003{
2004 struct alc_spec *spec = codec->spec;
2005 unsigned int i;
1da177e4 2006
1d045db9
TI
2007 alc_fix_pll(codec);
2008 alc_auto_init_amp(codec, spec->init_amp);
1da177e4 2009
1d045db9
TI
2010 for (i = 0; i < spec->num_init_verbs; i++)
2011 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2012 alc_init_special_input_src(codec);
dfc0ff62 2013
1d045db9
TI
2014 if (spec->init_hook)
2015 spec->init_hook(codec);
16ded525 2016
1d045db9 2017 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
16ded525 2018
1d045db9
TI
2019 hda_call_check_power_status(codec, 0x01);
2020 return 0;
2021}
ea1fb29a 2022
1d045db9
TI
2023static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2024{
2025 struct alc_spec *spec = codec->spec;
e9edcee0 2026
1d045db9
TI
2027 if (spec->unsol_event)
2028 spec->unsol_event(codec, res);
2029}
ccc656ce 2030
1d045db9
TI
2031#ifdef CONFIG_SND_HDA_POWER_SAVE
2032static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2033{
2034 struct alc_spec *spec = codec->spec;
2035 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2036}
2037#endif
ccc656ce
KY
2038
2039/*
1d045db9 2040 * Analog playback callbacks
ccc656ce 2041 */
1d045db9
TI
2042static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
2043 struct hda_codec *codec,
2044 struct snd_pcm_substream *substream)
458a4fab 2045{
1d045db9
TI
2046 struct alc_spec *spec = codec->spec;
2047 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2048 hinfo);
458a4fab
TI
2049}
2050
1d045db9
TI
2051static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2052 struct hda_codec *codec,
2053 unsigned int stream_tag,
2054 unsigned int format,
2055 struct snd_pcm_substream *substream)
458a4fab 2056{
a9fd4f3f 2057 struct alc_spec *spec = codec->spec;
1d045db9
TI
2058 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2059 stream_tag, format, substream);
4f5d1706
TI
2060}
2061
1d045db9
TI
2062static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2063 struct hda_codec *codec,
2064 struct snd_pcm_substream *substream)
4f5d1706 2065{
1d045db9
TI
2066 struct alc_spec *spec = codec->spec;
2067 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
ccc656ce
KY
2068}
2069
1d045db9
TI
2070/*
2071 * Digital out
2072 */
2073static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2074 struct hda_codec *codec,
2075 struct snd_pcm_substream *substream)
ccc656ce 2076{
1d045db9
TI
2077 struct alc_spec *spec = codec->spec;
2078 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
ccc656ce
KY
2079}
2080
1d045db9
TI
2081static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2082 struct hda_codec *codec,
2083 unsigned int stream_tag,
2084 unsigned int format,
2085 struct snd_pcm_substream *substream)
ccc656ce 2086{
a9fd4f3f 2087 struct alc_spec *spec = codec->spec;
1d045db9
TI
2088 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2089 stream_tag, format, substream);
ccc656ce
KY
2090}
2091
1d045db9
TI
2092static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2093 struct hda_codec *codec,
2094 struct snd_pcm_substream *substream)
ccc656ce 2095{
1d045db9
TI
2096 struct alc_spec *spec = codec->spec;
2097 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
ccc656ce 2098}
47fd830a 2099
1d045db9
TI
2100static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2101 struct hda_codec *codec,
2102 struct snd_pcm_substream *substream)
ccc656ce 2103{
1d045db9
TI
2104 struct alc_spec *spec = codec->spec;
2105 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
ccc656ce
KY
2106}
2107
e9edcee0 2108/*
1d045db9 2109 * Analog capture
e9edcee0 2110 */
1d045db9
TI
2111static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2112 struct hda_codec *codec,
2113 unsigned int stream_tag,
2114 unsigned int format,
2115 struct snd_pcm_substream *substream)
2116{
2117 struct alc_spec *spec = codec->spec;
1da177e4 2118
6330079f 2119 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
1da177e4
LT
2120 stream_tag, 0, format);
2121 return 0;
2122}
2123
c2d986b0 2124static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1da177e4 2125 struct hda_codec *codec,
c8b6bf9b 2126 struct snd_pcm_substream *substream)
1da177e4
LT
2127{
2128 struct alc_spec *spec = codec->spec;
2129
888afa15
TI
2130 snd_hda_codec_cleanup_stream(codec,
2131 spec->adc_nids[substream->number + 1]);
1da177e4
LT
2132 return 0;
2133}
2134
840b64c0 2135/* analog capture with dynamic dual-adc changes */
21268961 2136static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
840b64c0
TI
2137 struct hda_codec *codec,
2138 unsigned int stream_tag,
2139 unsigned int format,
2140 struct snd_pcm_substream *substream)
2141{
2142 struct alc_spec *spec = codec->spec;
21268961 2143 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
840b64c0
TI
2144 spec->cur_adc_stream_tag = stream_tag;
2145 spec->cur_adc_format = format;
2146 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2147 return 0;
2148}
2149
21268961 2150static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
840b64c0
TI
2151 struct hda_codec *codec,
2152 struct snd_pcm_substream *substream)
2153{
2154 struct alc_spec *spec = codec->spec;
2155 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2156 spec->cur_adc = 0;
2157 return 0;
2158}
2159
21268961 2160static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
840b64c0
TI
2161 .substreams = 1,
2162 .channels_min = 2,
2163 .channels_max = 2,
2164 .nid = 0, /* fill later */
2165 .ops = {
21268961
TI
2166 .prepare = dyn_adc_capture_pcm_prepare,
2167 .cleanup = dyn_adc_capture_pcm_cleanup
840b64c0
TI
2168 },
2169};
1da177e4
LT
2170
2171/*
2172 */
c2d986b0 2173static const struct hda_pcm_stream alc_pcm_analog_playback = {
1da177e4
LT
2174 .substreams = 1,
2175 .channels_min = 2,
2176 .channels_max = 8,
e9edcee0 2177 /* NID is set in alc_build_pcms */
1da177e4 2178 .ops = {
c2d986b0
TI
2179 .open = alc_playback_pcm_open,
2180 .prepare = alc_playback_pcm_prepare,
2181 .cleanup = alc_playback_pcm_cleanup
1da177e4
LT
2182 },
2183};
2184
c2d986b0 2185static const struct hda_pcm_stream alc_pcm_analog_capture = {
6330079f
TI
2186 .substreams = 1,
2187 .channels_min = 2,
2188 .channels_max = 2,
2189 /* NID is set in alc_build_pcms */
2190};
2191
c2d986b0 2192static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
6330079f
TI
2193 .substreams = 1,
2194 .channels_min = 2,
2195 .channels_max = 2,
2196 /* NID is set in alc_build_pcms */
2197};
2198
c2d986b0 2199static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
6330079f 2200 .substreams = 2, /* can be overridden */
1da177e4
LT
2201 .channels_min = 2,
2202 .channels_max = 2,
e9edcee0 2203 /* NID is set in alc_build_pcms */
1da177e4 2204 .ops = {
c2d986b0
TI
2205 .prepare = alc_alt_capture_pcm_prepare,
2206 .cleanup = alc_alt_capture_pcm_cleanup
1da177e4
LT
2207 },
2208};
2209
c2d986b0 2210static const struct hda_pcm_stream alc_pcm_digital_playback = {
1da177e4
LT
2211 .substreams = 1,
2212 .channels_min = 2,
2213 .channels_max = 2,
2214 /* NID is set in alc_build_pcms */
2215 .ops = {
c2d986b0
TI
2216 .open = alc_dig_playback_pcm_open,
2217 .close = alc_dig_playback_pcm_close,
2218 .prepare = alc_dig_playback_pcm_prepare,
2219 .cleanup = alc_dig_playback_pcm_cleanup
1da177e4
LT
2220 },
2221};
2222
c2d986b0 2223static const struct hda_pcm_stream alc_pcm_digital_capture = {
1da177e4
LT
2224 .substreams = 1,
2225 .channels_min = 2,
2226 .channels_max = 2,
2227 /* NID is set in alc_build_pcms */
2228};
2229
4c5186ed 2230/* Used by alc_build_pcms to flag that a PCM has no playback stream */
a9111321 2231static const struct hda_pcm_stream alc_pcm_null_stream = {
4c5186ed
JW
2232 .substreams = 0,
2233 .channels_min = 0,
2234 .channels_max = 0,
2235};
2236
1da177e4
LT
2237static int alc_build_pcms(struct hda_codec *codec)
2238{
2239 struct alc_spec *spec = codec->spec;
2240 struct hda_pcm *info = spec->pcm_rec;
c2d986b0 2241 const struct hda_pcm_stream *p;
1da177e4
LT
2242 int i;
2243
2244 codec->num_pcms = 1;
2245 codec->pcm_info = info;
2246
e64f14f4
TI
2247 if (spec->no_analog)
2248 goto skip_analog;
2249
812a2cca
TI
2250 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2251 "%s Analog", codec->chip_name);
1da177e4 2252 info->name = spec->stream_name_analog;
274693f3 2253
c2d986b0
TI
2254 if (spec->multiout.dac_nids > 0) {
2255 p = spec->stream_analog_playback;
2256 if (!p)
2257 p = &alc_pcm_analog_playback;
2258 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
4a471b7d
TI
2259 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2260 }
c2d986b0
TI
2261 if (spec->adc_nids) {
2262 p = spec->stream_analog_capture;
21268961
TI
2263 if (!p) {
2264 if (spec->dyn_adc_switch)
2265 p = &dyn_adc_pcm_analog_capture;
2266 else
2267 p = &alc_pcm_analog_capture;
2268 }
c2d986b0 2269 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
4a471b7d
TI
2270 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2271 }
2272
2273 if (spec->channel_mode) {
2274 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2275 for (i = 0; i < spec->num_channel_mode; i++) {
2276 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2277 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2278 }
1da177e4
LT
2279 }
2280 }
2281
e64f14f4 2282 skip_analog:
e08a007d 2283 /* SPDIF for stream index #1 */
1da177e4 2284 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
812a2cca
TI
2285 snprintf(spec->stream_name_digital,
2286 sizeof(spec->stream_name_digital),
2287 "%s Digital", codec->chip_name);
e08a007d 2288 codec->num_pcms = 2;
b25c9da1 2289 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
c06134d7 2290 info = spec->pcm_rec + 1;
1da177e4 2291 info->name = spec->stream_name_digital;
8c441982
TI
2292 if (spec->dig_out_type)
2293 info->pcm_type = spec->dig_out_type;
2294 else
2295 info->pcm_type = HDA_PCM_TYPE_SPDIF;
c2d986b0
TI
2296 if (spec->multiout.dig_out_nid) {
2297 p = spec->stream_digital_playback;
2298 if (!p)
2299 p = &alc_pcm_digital_playback;
2300 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
1da177e4
LT
2301 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2302 }
c2d986b0
TI
2303 if (spec->dig_in_nid) {
2304 p = spec->stream_digital_capture;
2305 if (!p)
2306 p = &alc_pcm_digital_capture;
2307 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
1da177e4
LT
2308 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2309 }
963f803f
TI
2310 /* FIXME: do we need this for all Realtek codec models? */
2311 codec->spdif_status_reset = 1;
1da177e4
LT
2312 }
2313
e64f14f4
TI
2314 if (spec->no_analog)
2315 return 0;
2316
e08a007d
TI
2317 /* If the use of more than one ADC is requested for the current
2318 * model, configure a second analog capture-only PCM.
2319 */
2320 /* Additional Analaog capture for index #2 */
c2d986b0 2321 if (spec->alt_dac_nid || spec->num_adc_nids > 1) {
e08a007d 2322 codec->num_pcms = 3;
c06134d7 2323 info = spec->pcm_rec + 2;
e08a007d 2324 info->name = spec->stream_name_analog;
6330079f 2325 if (spec->alt_dac_nid) {
c2d986b0
TI
2326 p = spec->stream_analog_alt_playback;
2327 if (!p)
2328 p = &alc_pcm_analog_alt_playback;
2329 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
6330079f
TI
2330 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2331 spec->alt_dac_nid;
2332 } else {
2333 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2334 alc_pcm_null_stream;
2335 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2336 }
c2d986b0
TI
2337 if (spec->num_adc_nids > 1) {
2338 p = spec->stream_analog_alt_capture;
2339 if (!p)
2340 p = &alc_pcm_analog_alt_capture;
2341 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
6330079f
TI
2342 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2343 spec->adc_nids[1];
2344 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2345 spec->num_adc_nids - 1;
2346 } else {
2347 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2348 alc_pcm_null_stream;
2349 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
e08a007d
TI
2350 }
2351 }
2352
1da177e4
LT
2353 return 0;
2354}
2355
a4e09aa3
TI
2356static inline void alc_shutup(struct hda_codec *codec)
2357{
1c716153
TI
2358 struct alc_spec *spec = codec->spec;
2359
2360 if (spec && spec->shutup)
2361 spec->shutup(codec);
a4e09aa3
TI
2362 snd_hda_shutup_pins(codec);
2363}
2364
603c4019
TI
2365static void alc_free_kctls(struct hda_codec *codec)
2366{
2367 struct alc_spec *spec = codec->spec;
2368
2369 if (spec->kctls.list) {
2370 struct snd_kcontrol_new *kctl = spec->kctls.list;
2371 int i;
2372 for (i = 0; i < spec->kctls.used; i++)
2373 kfree(kctl[i].name);
2374 }
2375 snd_array_free(&spec->kctls);
2376}
2377
23c09b00
TI
2378static void alc_free_bind_ctls(struct hda_codec *codec)
2379{
2380 struct alc_spec *spec = codec->spec;
2381 if (spec->bind_ctls.list) {
2382 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2383 int i;
2384 for (i = 0; i < spec->bind_ctls.used; i++)
2385 kfree(ctl[i]);
2386 }
2387 snd_array_free(&spec->bind_ctls);
2388}
2389
1da177e4
LT
2390static void alc_free(struct hda_codec *codec)
2391{
e9edcee0 2392 struct alc_spec *spec = codec->spec;
e9edcee0 2393
f12ab1e0 2394 if (!spec)
e9edcee0
TI
2395 return;
2396
a4e09aa3 2397 alc_shutup(codec);
cd372fb3 2398 snd_hda_input_jack_free(codec);
603c4019 2399 alc_free_kctls(codec);
23c09b00 2400 alc_free_bind_ctls(codec);
e9edcee0 2401 kfree(spec);
680cd536 2402 snd_hda_detach_beep_device(codec);
1da177e4
LT
2403}
2404
f5de24b0 2405#ifdef CONFIG_SND_HDA_POWER_SAVE
c97259df
DC
2406static void alc_power_eapd(struct hda_codec *codec)
2407{
691f1fcc 2408 alc_auto_setup_eapd(codec, false);
c97259df
DC
2409}
2410
f5de24b0
HM
2411static int alc_suspend(struct hda_codec *codec, pm_message_t state)
2412{
2413 struct alc_spec *spec = codec->spec;
a4e09aa3 2414 alc_shutup(codec);
f5de24b0 2415 if (spec && spec->power_hook)
c97259df 2416 spec->power_hook(codec);
f5de24b0
HM
2417 return 0;
2418}
2419#endif
2420
2a43952a 2421#ifdef CONFIG_PM
e044c39a
TI
2422static int alc_resume(struct hda_codec *codec)
2423{
1c716153 2424 msleep(150); /* to avoid pop noise */
e044c39a
TI
2425 codec->patch_ops.init(codec);
2426 snd_hda_codec_resume_amp(codec);
2427 snd_hda_codec_resume_cache(codec);
9e5341b9 2428 hda_call_check_power_status(codec, 0x01);
e044c39a
TI
2429 return 0;
2430}
e044c39a
TI
2431#endif
2432
1da177e4
LT
2433/*
2434 */
a9111321 2435static const struct hda_codec_ops alc_patch_ops = {
1da177e4
LT
2436 .build_controls = alc_build_controls,
2437 .build_pcms = alc_build_pcms,
2438 .init = alc_init,
2439 .free = alc_free,
ae6b813a 2440 .unsol_event = alc_unsol_event,
2a43952a 2441#ifdef CONFIG_PM
e044c39a
TI
2442 .resume = alc_resume,
2443#endif
cb53c626 2444#ifdef CONFIG_SND_HDA_POWER_SAVE
f5de24b0 2445 .suspend = alc_suspend,
cb53c626
TI
2446 .check_power_status = alc_check_power_status,
2447#endif
c97259df 2448 .reboot_notify = alc_shutup,
1da177e4
LT
2449};
2450
c027ddcd
KY
2451/* replace the codec chip_name with the given string */
2452static int alc_codec_rename(struct hda_codec *codec, const char *name)
2453{
2454 kfree(codec->chip_name);
2455 codec->chip_name = kstrdup(name, GFP_KERNEL);
2456 if (!codec->chip_name) {
2457 alc_free(codec);
2458 return -ENOMEM;
2459 }
2460 return 0;
2461}
2462
2fa522be 2463/*
1d045db9 2464 * Automatic parse of I/O pins from the BIOS configuration
2fa522be 2465 */
2fa522be 2466
1d045db9
TI
2467enum {
2468 ALC_CTL_WIDGET_VOL,
2469 ALC_CTL_WIDGET_MUTE,
2470 ALC_CTL_BIND_MUTE,
23c09b00
TI
2471 ALC_CTL_BIND_VOL,
2472 ALC_CTL_BIND_SW,
2fa522be 2473};
1d045db9
TI
2474static const struct snd_kcontrol_new alc_control_templates[] = {
2475 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2476 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2477 HDA_BIND_MUTE(NULL, 0, 0, 0),
23c09b00
TI
2478 HDA_BIND_VOL(NULL, 0),
2479 HDA_BIND_SW(NULL, 0),
2fa522be
TI
2480};
2481
1d045db9
TI
2482/* add dynamic controls */
2483static int add_control(struct alc_spec *spec, int type, const char *name,
2484 int cidx, unsigned long val)
e9edcee0 2485{
c8b6bf9b 2486 struct snd_kcontrol_new *knew;
e9edcee0 2487
ce764ab2 2488 knew = alc_kcontrol_new(spec);
603c4019
TI
2489 if (!knew)
2490 return -ENOMEM;
1d045db9 2491 *knew = alc_control_templates[type];
543537bd 2492 knew->name = kstrdup(name, GFP_KERNEL);
f12ab1e0 2493 if (!knew->name)
e9edcee0 2494 return -ENOMEM;
66ceeb6b 2495 knew->index = cidx;
4d02d1b6 2496 if (get_amp_nid_(val))
5e26dfd0 2497 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
e9edcee0 2498 knew->private_value = val;
e9edcee0
TI
2499 return 0;
2500}
2501
0afe5f89
TI
2502static int add_control_with_pfx(struct alc_spec *spec, int type,
2503 const char *pfx, const char *dir,
66ceeb6b 2504 const char *sfx, int cidx, unsigned long val)
0afe5f89
TI
2505{
2506 char name[32];
2507 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
66ceeb6b 2508 return add_control(spec, type, name, cidx, val);
0afe5f89
TI
2509}
2510
66ceeb6b
TI
2511#define add_pb_vol_ctrl(spec, type, pfx, val) \
2512 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2513#define add_pb_sw_ctrl(spec, type, pfx, val) \
2514 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2515#define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2516 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2517#define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2518 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
0afe5f89 2519
23c09b00
TI
2520static const char * const channel_name[4] = {
2521 "Front", "Surround", "CLFE", "Side"
2522};
2523
6843ca16
TI
2524static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2525 bool can_be_master, int *index)
bcb2f0f5 2526{
ce764ab2
TI
2527 struct auto_pin_cfg *cfg = &spec->autocfg;
2528
6843ca16 2529 *index = 0;
ce764ab2
TI
2530 if (cfg->line_outs == 1 && !spec->multi_ios &&
2531 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
bcb2f0f5
TI
2532 return "Master";
2533
2534 switch (cfg->line_out_type) {
2535 case AUTO_PIN_SPEAKER_OUT:
ebbeb3d6
DH
2536 if (cfg->line_outs == 1)
2537 return "Speaker";
2538 break;
bcb2f0f5 2539 case AUTO_PIN_HP_OUT:
6843ca16
TI
2540 /* for multi-io case, only the primary out */
2541 if (ch && spec->multi_ios)
2542 break;
2543 *index = ch;
bcb2f0f5
TI
2544 return "Headphone";
2545 default:
ce764ab2 2546 if (cfg->line_outs == 1 && !spec->multi_ios)
bcb2f0f5
TI
2547 return "PCM";
2548 break;
2549 }
23c09b00
TI
2550 if (snd_BUG_ON(ch >= ARRAY_SIZE(channel_name)))
2551 return "PCM";
2552
2553 return channel_name[ch];
bcb2f0f5
TI
2554}
2555
e9edcee0 2556/* create input playback/capture controls for the given pin */
f12ab1e0 2557static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
66ceeb6b 2558 const char *ctlname, int ctlidx,
df694daa 2559 int idx, hda_nid_t mix_nid)
e9edcee0 2560{
df694daa 2561 int err;
e9edcee0 2562
66ceeb6b 2563 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
f12ab1e0
TI
2564 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2565 if (err < 0)
e9edcee0 2566 return err;
66ceeb6b 2567 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
f12ab1e0
TI
2568 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2569 if (err < 0)
e9edcee0
TI
2570 return err;
2571 return 0;
2572}
2573
05f5f477
TI
2574static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
2575{
2576 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2577 return (pincap & AC_PINCAP_IN) != 0;
2578}
2579
1d045db9 2580/* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
d6cc9fab 2581static int alc_auto_fill_adc_caps(struct hda_codec *codec)
b7821709 2582{
d6cc9fab 2583 struct alc_spec *spec = codec->spec;
b7821709 2584 hda_nid_t nid;
d6cc9fab
TI
2585 hda_nid_t *adc_nids = spec->private_adc_nids;
2586 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2587 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
2588 bool indep_capsrc = false;
b7821709
TI
2589 int i, nums = 0;
2590
2591 nid = codec->start_nid;
2592 for (i = 0; i < codec->num_nodes; i++, nid++) {
2593 hda_nid_t src;
2594 const hda_nid_t *list;
2595 unsigned int caps = get_wcaps(codec, nid);
2596 int type = get_wcaps_type(caps);
2597
2598 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2599 continue;
2600 adc_nids[nums] = nid;
2601 cap_nids[nums] = nid;
2602 src = nid;
2603 for (;;) {
2604 int n;
2605 type = get_wcaps_type(get_wcaps(codec, src));
2606 if (type == AC_WID_PIN)
2607 break;
2608 if (type == AC_WID_AUD_SEL) {
2609 cap_nids[nums] = src;
d6cc9fab 2610 indep_capsrc = true;
b7821709
TI
2611 break;
2612 }
2613 n = snd_hda_get_conn_list(codec, src, &list);
2614 if (n > 1) {
2615 cap_nids[nums] = src;
d6cc9fab 2616 indep_capsrc = true;
b7821709
TI
2617 break;
2618 } else if (n != 1)
2619 break;
2620 src = *list;
2621 }
2622 if (++nums >= max_nums)
2623 break;
2624 }
d6cc9fab 2625 spec->adc_nids = spec->private_adc_nids;
21268961 2626 spec->capsrc_nids = spec->private_capsrc_nids;
d6cc9fab 2627 spec->num_adc_nids = nums;
b7821709
TI
2628 return nums;
2629}
2630
e9edcee0 2631/* create playback/capture controls for input pins */
b7821709 2632static int alc_auto_create_input_ctls(struct hda_codec *codec)
e9edcee0 2633{
05f5f477 2634 struct alc_spec *spec = codec->spec;
b7821709
TI
2635 const struct auto_pin_cfg *cfg = &spec->autocfg;
2636 hda_nid_t mixer = spec->mixer_nid;
61b9b9b1 2637 struct hda_input_mux *imux = &spec->private_imux[0];
b7821709 2638 int num_adcs;
b7821709 2639 int i, c, err, idx, type_idx = 0;
5322bf27 2640 const char *prev_label = NULL;
e9edcee0 2641
d6cc9fab 2642 num_adcs = alc_auto_fill_adc_caps(codec);
b7821709
TI
2643 if (num_adcs < 0)
2644 return 0;
2645
66ceeb6b 2646 for (i = 0; i < cfg->num_inputs; i++) {
05f5f477 2647 hda_nid_t pin;
10a20af7 2648 const char *label;
05f5f477 2649
66ceeb6b 2650 pin = cfg->inputs[i].pin;
05f5f477
TI
2651 if (!alc_is_input_pin(codec, pin))
2652 continue;
2653
5322bf27
DH
2654 label = hda_get_autocfg_input_label(codec, cfg, i);
2655 if (prev_label && !strcmp(label, prev_label))
66ceeb6b
TI
2656 type_idx++;
2657 else
2658 type_idx = 0;
5322bf27
DH
2659 prev_label = label;
2660
05f5f477
TI
2661 if (mixer) {
2662 idx = get_connection_index(codec, mixer, pin);
2663 if (idx >= 0) {
2664 err = new_analog_input(spec, pin,
10a20af7
TI
2665 label, type_idx,
2666 idx, mixer);
05f5f477
TI
2667 if (err < 0)
2668 return err;
2669 }
2670 }
2671
b7821709 2672 for (c = 0; c < num_adcs; c++) {
d6cc9fab
TI
2673 hda_nid_t cap = spec->capsrc_nids ?
2674 spec->capsrc_nids[c] : spec->adc_nids[c];
2675 idx = get_connection_index(codec, cap, pin);
b7821709 2676 if (idx >= 0) {
21268961 2677 spec->imux_pins[imux->num_items] = pin;
b7821709
TI
2678 snd_hda_add_imux_item(imux, label, idx, NULL);
2679 break;
2680 }
2681 }
e9edcee0 2682 }
21268961
TI
2683
2684 spec->num_mux_defs = 1;
2685 spec->input_mux = imux;
2686
e9edcee0
TI
2687 return 0;
2688}
2689
f6c7e546
TI
2690static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
2691 unsigned int pin_type)
2692{
2693 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2694 pin_type);
2695 /* unmute pin */
44c02400
TI
2696 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2697 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
d260cdf6 2698 AMP_OUT_UNMUTE);
f6c7e546
TI
2699}
2700
baba8ee9
TI
2701static int get_pin_type(int line_out_type)
2702{
2703 if (line_out_type == AUTO_PIN_HP_OUT)
2704 return PIN_HP;
2705 else
2706 return PIN_OUT;
2707}
2708
0a7f5320 2709static void alc_auto_init_analog_input(struct hda_codec *codec)
e9edcee0
TI
2710{
2711 struct alc_spec *spec = codec->spec;
66ceeb6b 2712 struct auto_pin_cfg *cfg = &spec->autocfg;
e9edcee0
TI
2713 int i;
2714
66ceeb6b
TI
2715 for (i = 0; i < cfg->num_inputs; i++) {
2716 hda_nid_t nid = cfg->inputs[i].pin;
05f5f477 2717 if (alc_is_input_pin(codec, nid)) {
30ea098f 2718 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
1f0f4b80 2719 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
f12ab1e0
TI
2720 snd_hda_codec_write(codec, nid, 0,
2721 AC_VERB_SET_AMP_GAIN_MUTE,
e9edcee0
TI
2722 AMP_OUT_MUTE);
2723 }
2724 }
1f0f4b80
TI
2725
2726 /* mute all loopback inputs */
2727 if (spec->mixer_nid) {
2728 int nums = snd_hda_get_conn_list(codec, spec->mixer_nid, NULL);
2729 for (i = 0; i < nums; i++)
2730 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2731 AC_VERB_SET_AMP_GAIN_MUTE,
2732 AMP_IN_MUTE(i));
2733 }
e9edcee0
TI
2734}
2735
1d045db9
TI
2736/* convert from MIX nid to DAC */
2737static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid)
e9edcee0 2738{
1d045db9
TI
2739 hda_nid_t list[5];
2740 int i, num;
4a79ba34 2741
afcd5515
TI
2742 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT)
2743 return nid;
1d045db9
TI
2744 num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list));
2745 for (i = 0; i < num; i++) {
2746 if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT)
2747 return list[i];
2748 }
2749 return 0;
e9edcee0
TI
2750}
2751
1d045db9
TI
2752/* go down to the selector widget before the mixer */
2753static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin)
e9edcee0 2754{
1d045db9
TI
2755 hda_nid_t srcs[5];
2756 int num = snd_hda_get_connections(codec, pin, srcs,
2757 ARRAY_SIZE(srcs));
2758 if (num != 1 ||
2759 get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL)
2760 return pin;
2761 return srcs[0];
e9edcee0
TI
2762}
2763
1d045db9
TI
2764/* get MIX nid connected to the given pin targeted to DAC */
2765static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
2766 hda_nid_t dac)
748cce43 2767{
1d045db9
TI
2768 hda_nid_t mix[5];
2769 int i, num;
2770
2771 pin = alc_go_down_to_selector(codec, pin);
2772 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2773 for (i = 0; i < num; i++) {
2774 if (alc_auto_mix_to_dac(codec, mix[i]) == dac)
2775 return mix[i];
748cce43 2776 }
1d045db9 2777 return 0;
748cce43
TI
2778}
2779
1d045db9
TI
2780/* select the connection from pin to DAC if needed */
2781static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin,
2782 hda_nid_t dac)
eaa9b3a7 2783{
1d045db9
TI
2784 hda_nid_t mix[5];
2785 int i, num;
eaa9b3a7 2786
1d045db9
TI
2787 pin = alc_go_down_to_selector(codec, pin);
2788 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2789 if (num < 2)
8ed99d97 2790 return 0;
1d045db9
TI
2791 for (i = 0; i < num; i++) {
2792 if (alc_auto_mix_to_dac(codec, mix[i]) == dac) {
2793 snd_hda_codec_update_cache(codec, pin, 0,
2794 AC_VERB_SET_CONNECT_SEL, i);
2795 return 0;
2796 }
840b64c0 2797 }
1d045db9 2798 return 0;
840b64c0
TI
2799}
2800
1d045db9
TI
2801/* look for an empty DAC slot */
2802static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
584c0c4c
TI
2803{
2804 struct alc_spec *spec = codec->spec;
1d045db9
TI
2805 hda_nid_t srcs[5];
2806 int i, num;
21268961 2807
1d045db9
TI
2808 pin = alc_go_down_to_selector(codec, pin);
2809 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
2810 for (i = 0; i < num; i++) {
2811 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
2812 if (!nid)
2813 continue;
2814 if (found_in_nid_list(nid, spec->multiout.dac_nids,
2815 spec->multiout.num_dacs))
2816 continue;
e23832ac 2817 if (spec->multiout.hp_out_nid[0] == nid)
1d045db9
TI
2818 continue;
2819 if (found_in_nid_list(nid, spec->multiout.extra_out_nid,
2820 ARRAY_SIZE(spec->multiout.extra_out_nid)))
2821 continue;
2822 return nid;
2823 }
2824 return 0;
584c0c4c
TI
2825}
2826
1d045db9 2827static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
f9e336f6 2828{
1d045db9
TI
2829 hda_nid_t sel = alc_go_down_to_selector(codec, pin);
2830 if (snd_hda_get_conn_list(codec, sel, NULL) == 1)
2831 return alc_auto_look_for_dac(codec, pin);
2832 return 0;
f9e336f6
TI
2833}
2834
1d045db9
TI
2835/* fill in the dac_nids table from the parsed pin configuration */
2836static int alc_auto_fill_dac_nids(struct hda_codec *codec)
21268961
TI
2837{
2838 struct alc_spec *spec = codec->spec;
1d045db9
TI
2839 const struct auto_pin_cfg *cfg = &spec->autocfg;
2840 bool redone = false;
2841 int i;
21268961 2842
1d045db9 2843 again:
8f398ae7
TI
2844 /* set num_dacs once to full for alc_auto_look_for_dac() */
2845 spec->multiout.num_dacs = cfg->line_outs;
e23832ac 2846 spec->multiout.hp_out_nid[0] = 0;
1d045db9
TI
2847 spec->multiout.extra_out_nid[0] = 0;
2848 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
2849 spec->multiout.dac_nids = spec->private_dac_nids;
21268961 2850
1d045db9
TI
2851 /* fill hard-wired DACs first */
2852 if (!redone) {
2853 for (i = 0; i < cfg->line_outs; i++)
2854 spec->private_dac_nids[i] =
2855 get_dac_if_single(codec, cfg->line_out_pins[i]);
2856 if (cfg->hp_outs)
e23832ac 2857 spec->multiout.hp_out_nid[0] =
1d045db9
TI
2858 get_dac_if_single(codec, cfg->hp_pins[0]);
2859 if (cfg->speaker_outs)
2860 spec->multiout.extra_out_nid[0] =
2861 get_dac_if_single(codec, cfg->speaker_pins[0]);
21268961
TI
2862 }
2863
1d045db9
TI
2864 for (i = 0; i < cfg->line_outs; i++) {
2865 hda_nid_t pin = cfg->line_out_pins[i];
2866 if (spec->private_dac_nids[i])
2867 continue;
2868 spec->private_dac_nids[i] = alc_auto_look_for_dac(codec, pin);
2869 if (!spec->private_dac_nids[i] && !redone) {
2870 /* if we can't find primary DACs, re-probe without
2871 * checking the hard-wired DACs
2872 */
2873 redone = true;
2874 goto again;
21268961
TI
2875 }
2876 }
2877
8f398ae7
TI
2878 /* re-count num_dacs and squash invalid entries */
2879 spec->multiout.num_dacs = 0;
1d045db9
TI
2880 for (i = 0; i < cfg->line_outs; i++) {
2881 if (spec->private_dac_nids[i])
2882 spec->multiout.num_dacs++;
2883 else
2884 memmove(spec->private_dac_nids + i,
2885 spec->private_dac_nids + i + 1,
2886 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
2887 }
2888
e23832ac
TI
2889 if (cfg->hp_outs && !spec->multiout.hp_out_nid[0])
2890 spec->multiout.hp_out_nid[0] =
1d045db9
TI
2891 alc_auto_look_for_dac(codec, cfg->hp_pins[0]);
2892 if (cfg->speaker_outs && !spec->multiout.extra_out_nid[0])
2893 spec->multiout.extra_out_nid[0] =
2894 alc_auto_look_for_dac(codec, cfg->speaker_pins[0]);
2895
2896 return 0;
21268961
TI
2897}
2898
23c09b00
TI
2899/* fill in the dac_nids table for surround speakers, etc */
2900static int alc_auto_fill_extra_dacs(struct hda_codec *codec)
2901{
2902 struct alc_spec *spec = codec->spec;
2903 const struct auto_pin_cfg *cfg = &spec->autocfg;
2904 int i;
2905
2906 if (cfg->speaker_outs < 2 || !spec->multiout.extra_out_nid[0])
2907 return 0;
2908
2909 for (i = 1; i < cfg->speaker_outs; i++)
2910 spec->multiout.extra_out_nid[i] =
2911 get_dac_if_single(codec, cfg->speaker_pins[i]);
2912 for (i = 1; i < cfg->speaker_outs; i++) {
2913 if (spec->multiout.extra_out_nid[i])
2914 continue;
2915 spec->multiout.extra_out_nid[i] =
2916 alc_auto_look_for_dac(codec, cfg->speaker_pins[0]);
2917 }
2918 return 0;
2919}
2920
1d045db9
TI
2921static int alc_auto_add_vol_ctl(struct hda_codec *codec,
2922 const char *pfx, int cidx,
2923 hda_nid_t nid, unsigned int chs)
6694635d 2924{
afcd5515
TI
2925 if (!nid)
2926 return 0;
1d045db9
TI
2927 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
2928 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
2929}
6694635d 2930
1d045db9
TI
2931#define alc_auto_add_stereo_vol(codec, pfx, cidx, nid) \
2932 alc_auto_add_vol_ctl(codec, pfx, cidx, nid, 3)
21268961 2933
1d045db9
TI
2934/* create a mute-switch for the given mixer widget;
2935 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
2936 */
2937static int alc_auto_add_sw_ctl(struct hda_codec *codec,
2938 const char *pfx, int cidx,
2939 hda_nid_t nid, unsigned int chs)
2940{
afcd5515 2941 int wid_type;
1d045db9
TI
2942 int type;
2943 unsigned long val;
afcd5515
TI
2944 if (!nid)
2945 return 0;
2946 wid_type = get_wcaps_type(get_wcaps(codec, nid));
2947 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) {
2948 type = ALC_CTL_WIDGET_MUTE;
2949 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
2950 } else if (snd_hda_get_conn_list(codec, nid, NULL) == 1) {
1d045db9
TI
2951 type = ALC_CTL_WIDGET_MUTE;
2952 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
2953 } else {
2954 type = ALC_CTL_BIND_MUTE;
2955 val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
6694635d 2956 }
1d045db9 2957 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
6694635d
TI
2958}
2959
1d045db9
TI
2960#define alc_auto_add_stereo_sw(codec, pfx, cidx, nid) \
2961 alc_auto_add_sw_ctl(codec, pfx, cidx, nid, 3)
dc1eae25 2962
afcd5515
TI
2963static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
2964 hda_nid_t pin, hda_nid_t dac)
2965{
2966 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
2967 if (nid_has_mute(codec, pin, HDA_OUTPUT))
2968 return pin;
2969 else if (mix && nid_has_mute(codec, mix, HDA_INPUT))
2970 return mix;
2971 else if (nid_has_mute(codec, dac, HDA_OUTPUT))
2972 return dac;
2973 return 0;
2974}
2975
2976static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
2977 hda_nid_t pin, hda_nid_t dac)
2978{
2979 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
2980 if (nid_has_volume(codec, dac, HDA_OUTPUT))
2981 return dac;
2982 else if (nid_has_volume(codec, mix, HDA_OUTPUT))
2983 return mix;
2984 else if (nid_has_volume(codec, pin, HDA_OUTPUT))
2985 return pin;
2986 return 0;
2987}
2988
1d045db9
TI
2989/* add playback controls from the parsed DAC table */
2990static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
2991 const struct auto_pin_cfg *cfg)
dc1eae25
TI
2992{
2993 struct alc_spec *spec = codec->spec;
1d045db9 2994 int i, err, noutputs;
1f0f4b80 2995
1d045db9
TI
2996 noutputs = cfg->line_outs;
2997 if (spec->multi_ios > 0)
2998 noutputs += spec->multi_ios;
1da177e4 2999
1d045db9
TI
3000 for (i = 0; i < noutputs; i++) {
3001 const char *name;
3002 int index;
afcd5515
TI
3003 hda_nid_t dac, pin;
3004 hda_nid_t sw, vol;
3005
3006 dac = spec->multiout.dac_nids[i];
3007 if (!dac)
1d045db9
TI
3008 continue;
3009 if (i >= cfg->line_outs)
3010 pin = spec->multi_io[i - 1].pin;
3011 else
3012 pin = cfg->line_out_pins[i];
afcd5515
TI
3013
3014 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3015 vol = alc_look_for_out_vol_nid(codec, pin, dac);
1d045db9
TI
3016 name = alc_get_line_out_pfx(spec, i, true, &index);
3017 if (!name) {
3018 /* Center/LFE */
afcd5515 3019 err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1);
1d045db9
TI
3020 if (err < 0)
3021 return err;
afcd5515 3022 err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2);
1d045db9
TI
3023 if (err < 0)
3024 return err;
afcd5515 3025 err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1);
1d045db9
TI
3026 if (err < 0)
3027 return err;
afcd5515 3028 err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2);
1d045db9
TI
3029 if (err < 0)
3030 return err;
3031 } else {
afcd5515 3032 err = alc_auto_add_stereo_vol(codec, name, index, vol);
1d045db9
TI
3033 if (err < 0)
3034 return err;
afcd5515 3035 err = alc_auto_add_stereo_sw(codec, name, index, sw);
1d045db9
TI
3036 if (err < 0)
3037 return err;
e9edcee0 3038 }
1da177e4 3039 }
1d045db9
TI
3040 return 0;
3041}
1da177e4 3042
1d045db9 3043static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
23c09b00 3044 hda_nid_t dac, const char *pfx)
1d045db9
TI
3045{
3046 struct alc_spec *spec = codec->spec;
afcd5515 3047 hda_nid_t sw, vol;
1d045db9 3048 int err;
1da177e4 3049
1d045db9
TI
3050 if (!dac) {
3051 /* the corresponding DAC is already occupied */
3052 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
3053 return 0; /* no way */
3054 /* create a switch only */
3055 return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx,
3056 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
e9edcee0 3057 }
1da177e4 3058
afcd5515
TI
3059 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3060 vol = alc_look_for_out_vol_nid(codec, pin, dac);
3061 err = alc_auto_add_stereo_vol(codec, pfx, 0, vol);
1d045db9
TI
3062 if (err < 0)
3063 return err;
afcd5515 3064 err = alc_auto_add_stereo_sw(codec, pfx, 0, sw);
1d045db9
TI
3065 if (err < 0)
3066 return err;
1da177e4
LT
3067 return 0;
3068}
3069
23c09b00
TI
3070static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3071 unsigned int nums,
3072 struct hda_ctl_ops *ops)
3073{
3074 struct alc_spec *spec = codec->spec;
3075 struct hda_bind_ctls **ctlp, *ctl;
3076 snd_array_init(&spec->bind_ctls, sizeof(ctl), 8);
3077 ctlp = snd_array_new(&spec->bind_ctls);
3078 if (!ctlp)
3079 return NULL;
3080 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3081 *ctlp = ctl;
3082 if (ctl)
3083 ctl->ops = ops;
3084 return ctl;
3085}
3086
3087/* add playback controls for speaker and HP outputs */
3088static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3089 const hda_nid_t *pins,
3090 const hda_nid_t *dacs,
3091 const char *pfx)
3092{
3093 struct alc_spec *spec = codec->spec;
3094 struct hda_bind_ctls *ctl;
3095 char name[32];
3096 int i, n, err;
3097
3098 if (!num_pins || !pins[0])
3099 return 0;
3100
3101 if (num_pins == 1)
3102 return alc_auto_create_extra_out(codec, *pins, *dacs, pfx);
3103
3104 if (dacs[num_pins - 1]) {
3105 /* OK, we have a multi-output system with individual volumes */
3106 for (i = 0; i < num_pins; i++) {
3107 snprintf(name, sizeof(name), "%s %s",
3108 pfx, channel_name[i]);
3109 err = alc_auto_create_extra_out(codec, pins[i], dacs[i],
3110 name);
3111 if (err < 0)
3112 return err;
3113 }
3114 return 0;
3115 }
3116
3117 /* Let's create a bind-controls */
3118 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_sw);
3119 if (!ctl)
3120 return -ENOMEM;
3121 n = 0;
3122 for (i = 0; i < num_pins; i++) {
3123 if (get_wcaps(codec, pins[i]) & AC_WCAP_OUT_AMP)
3124 ctl->values[n++] =
3125 HDA_COMPOSE_AMP_VAL(pins[i], 3, 0, HDA_OUTPUT);
3126 }
3127 if (n) {
3128 snprintf(name, sizeof(name), "%s Playback Switch", pfx);
3129 err = add_control(spec, ALC_CTL_BIND_SW, name, 0, (long)ctl);
3130 if (err < 0)
3131 return err;
3132 }
3133
3134 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3135 if (!ctl)
3136 return -ENOMEM;
3137 n = 0;
3138 for (i = 0; i < num_pins; i++) {
3139 hda_nid_t vol;
3140 if (!pins[i] || !dacs[i])
3141 continue;
3142 vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]);
3143 if (vol)
3144 ctl->values[n++] =
3145 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3146 }
3147 if (n) {
3148 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3149 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3150 if (err < 0)
3151 return err;
3152 }
3153 return 0;
3154}
3155
1d045db9 3156static int alc_auto_create_hp_out(struct hda_codec *codec)
bec15c3a 3157{
1d045db9 3158 struct alc_spec *spec = codec->spec;
e23832ac
TI
3159 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3160 spec->autocfg.hp_pins,
3161 spec->multiout.hp_out_nid,
3162 "Headphone");
bec15c3a
TI
3163}
3164
1d045db9 3165static int alc_auto_create_speaker_out(struct hda_codec *codec)
bec15c3a 3166{
bec15c3a 3167 struct alc_spec *spec = codec->spec;
23c09b00
TI
3168 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3169 spec->autocfg.speaker_pins,
3170 spec->multiout.extra_out_nid,
3171 "Speaker");
bec15c3a
TI
3172}
3173
1d045db9 3174static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
afcd5515 3175 hda_nid_t pin, int pin_type,
1d045db9 3176 hda_nid_t dac)
bec15c3a 3177{
1d045db9 3178 int i, num;
afcd5515 3179 hda_nid_t nid, mix = 0;
1d045db9 3180 hda_nid_t srcs[HDA_MAX_CONNECTIONS];
bec15c3a 3181
afcd5515
TI
3182 alc_set_pin_output(codec, pin, pin_type);
3183 nid = alc_go_down_to_selector(codec, pin);
1d045db9
TI
3184 num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
3185 for (i = 0; i < num; i++) {
3186 if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
3187 continue;
3188 mix = srcs[i];
3189 break;
3190 }
3191 if (!mix)
3192 return;
bec15c3a 3193
1d045db9
TI
3194 /* need the manual connection? */
3195 if (num > 1)
3196 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
3197 /* unmute mixer widget inputs */
afcd5515
TI
3198 if (nid_has_mute(codec, mix, HDA_INPUT)) {
3199 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
1d045db9 3200 AMP_IN_UNMUTE(0));
afcd5515 3201 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
1d045db9 3202 AMP_IN_UNMUTE(1));
afcd5515 3203 }
1d045db9 3204 /* initialize volume */
afcd5515
TI
3205 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3206 if (nid)
3207 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3208 AMP_OUT_ZERO);
1d045db9 3209}
bec15c3a 3210
1d045db9 3211static void alc_auto_init_multi_out(struct hda_codec *codec)
bec15c3a
TI
3212{
3213 struct alc_spec *spec = codec->spec;
1d045db9
TI
3214 int pin_type = get_pin_type(spec->autocfg.line_out_type);
3215 int i;
bec15c3a 3216
1d045db9
TI
3217 for (i = 0; i <= HDA_SIDE; i++) {
3218 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3219 if (nid)
3220 alc_auto_set_output_and_unmute(codec, nid, pin_type,
3221 spec->multiout.dac_nids[i]);
3222 }
bec15c3a
TI
3223}
3224
1d045db9 3225static void alc_auto_init_extra_out(struct hda_codec *codec)
e9427969
TI
3226{
3227 struct alc_spec *spec = codec->spec;
8cd0775d 3228 int i;
675c1aa3 3229 hda_nid_t pin, dac;
e9427969 3230
e23832ac
TI
3231 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3232 pin = spec->autocfg.hp_pins[i];
3233 if (!pin)
3234 break;
3235 dac = spec->multiout.hp_out_nid[i];
3236 if (!dac) {
3237 if (i > 0 && spec->multiout.hp_out_nid[0])
3238 dac = spec->multiout.hp_out_nid[0];
3239 else
3240 dac = spec->multiout.dac_nids[0];
3241 }
675c1aa3
TI
3242 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
3243 }
8cd0775d
TI
3244 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3245 pin = spec->autocfg.speaker_pins[i];
3246 if (!pin)
3247 break;
3248 dac = spec->multiout.extra_out_nid[i];
3249 if (!dac) {
3250 if (i > 0 && spec->multiout.extra_out_nid[0])
3251 dac = spec->multiout.extra_out_nid[0];
3252 else
3253 dac = spec->multiout.dac_nids[0];
3254 }
675c1aa3
TI
3255 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
3256 }
bc9f98a9
KY
3257}
3258
df694daa 3259/*
1d045db9 3260 * multi-io helper
df694daa 3261 */
1d045db9
TI
3262static int alc_auto_fill_multi_ios(struct hda_codec *codec,
3263 unsigned int location)
df694daa 3264{
1d045db9
TI
3265 struct alc_spec *spec = codec->spec;
3266 struct auto_pin_cfg *cfg = &spec->autocfg;
3267 int type, i, num_pins = 0;
ea1fb29a 3268
1d045db9
TI
3269 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3270 for (i = 0; i < cfg->num_inputs; i++) {
3271 hda_nid_t nid = cfg->inputs[i].pin;
3272 hda_nid_t dac;
3273 unsigned int defcfg, caps;
3274 if (cfg->inputs[i].type != type)
3275 continue;
3276 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3277 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3278 continue;
3279 if (location && get_defcfg_location(defcfg) != location)
3280 continue;
3281 caps = snd_hda_query_pin_caps(codec, nid);
3282 if (!(caps & AC_PINCAP_OUT))
3283 continue;
3284 dac = alc_auto_look_for_dac(codec, nid);
3285 if (!dac)
3286 continue;
3287 spec->multi_io[num_pins].pin = nid;
3288 spec->multi_io[num_pins].dac = dac;
3289 num_pins++;
3290 spec->private_dac_nids[spec->multiout.num_dacs++] = dac;
3291 }
863b4518 3292 }
df694daa 3293 spec->multiout.num_dacs = 1;
1d045db9
TI
3294 if (num_pins < 2)
3295 return 0;
3296 return num_pins;
a361d84b
KY
3297}
3298
1d045db9
TI
3299static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
3300 struct snd_ctl_elem_info *uinfo)
a361d84b 3301{
1d045db9 3302 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
a361d84b 3303 struct alc_spec *spec = codec->spec;
a361d84b 3304
1d045db9
TI
3305 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3306 uinfo->count = 1;
3307 uinfo->value.enumerated.items = spec->multi_ios + 1;
3308 if (uinfo->value.enumerated.item > spec->multi_ios)
3309 uinfo->value.enumerated.item = spec->multi_ios;
3310 sprintf(uinfo->value.enumerated.name, "%dch",
3311 (uinfo->value.enumerated.item + 1) * 2);
3312 return 0;
3313}
a361d84b 3314
1d045db9
TI
3315static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
3316 struct snd_ctl_elem_value *ucontrol)
3317{
3318 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3319 struct alc_spec *spec = codec->spec;
3320 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
3321 return 0;
3322}
a361d84b 3323
1d045db9
TI
3324static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
3325{
3326 struct alc_spec *spec = codec->spec;
3327 hda_nid_t nid = spec->multi_io[idx].pin;
a361d84b 3328
1d045db9
TI
3329 if (!spec->multi_io[idx].ctl_in)
3330 spec->multi_io[idx].ctl_in =
3331 snd_hda_codec_read(codec, nid, 0,
3332 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3333 if (output) {
3334 snd_hda_codec_update_cache(codec, nid, 0,
3335 AC_VERB_SET_PIN_WIDGET_CONTROL,
3336 PIN_OUT);
3337 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3338 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3339 HDA_AMP_MUTE, 0);
3340 alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
3341 } else {
3342 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3343 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3344 HDA_AMP_MUTE, HDA_AMP_MUTE);
3345 snd_hda_codec_update_cache(codec, nid, 0,
3346 AC_VERB_SET_PIN_WIDGET_CONTROL,
3347 spec->multi_io[idx].ctl_in);
4f574b7b 3348 }
1d045db9 3349 return 0;
a361d84b
KY
3350}
3351
1d045db9
TI
3352static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
3353 struct snd_ctl_elem_value *ucontrol)
a361d84b 3354{
1d045db9 3355 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
f6c7e546 3356 struct alc_spec *spec = codec->spec;
1d045db9 3357 int i, ch;
a361d84b 3358
1d045db9
TI
3359 ch = ucontrol->value.enumerated.item[0];
3360 if (ch < 0 || ch > spec->multi_ios)
3361 return -EINVAL;
3362 if (ch == (spec->ext_channel_count - 1) / 2)
3363 return 0;
3364 spec->ext_channel_count = (ch + 1) * 2;
3365 for (i = 0; i < spec->multi_ios; i++)
3366 alc_set_multi_io(codec, i, i < ch);
3367 spec->multiout.max_channels = spec->ext_channel_count;
7b1655f5
TI
3368 if (spec->need_dac_fix && !spec->const_channel_count)
3369 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
1d045db9
TI
3370 return 1;
3371}
3abf2f36 3372
1d045db9
TI
3373static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
3374 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3375 .name = "Channel Mode",
3376 .info = alc_auto_ch_mode_info,
3377 .get = alc_auto_ch_mode_get,
3378 .put = alc_auto_ch_mode_put,
a361d84b
KY
3379};
3380
23c09b00 3381static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
a361d84b 3382{
1d045db9
TI
3383 struct alc_spec *spec = codec->spec;
3384 struct auto_pin_cfg *cfg = &spec->autocfg;
3385 unsigned int location, defcfg;
3386 int num_pins;
a361d84b 3387
1d045db9
TI
3388 if (cfg->line_outs != 1 ||
3389 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
3390 return 0;
a361d84b 3391
1d045db9
TI
3392 defcfg = snd_hda_codec_get_pincfg(codec, cfg->line_out_pins[0]);
3393 location = get_defcfg_location(defcfg);
1f0f4b80 3394
1d045db9
TI
3395 num_pins = alc_auto_fill_multi_ios(codec, location);
3396 if (num_pins > 0) {
3397 struct snd_kcontrol_new *knew;
a361d84b 3398
1d045db9
TI
3399 knew = alc_kcontrol_new(spec);
3400 if (!knew)
3401 return -ENOMEM;
3402 *knew = alc_auto_channel_mode_enum;
3403 knew->name = kstrdup("Channel Mode", GFP_KERNEL);
3404 if (!knew->name)
3405 return -ENOMEM;
3abf2f36 3406
1d045db9
TI
3407 spec->multi_ios = num_pins;
3408 spec->ext_channel_count = 2;
3409 spec->multiout.num_dacs = num_pins + 1;
a361d84b 3410 }
1d045db9
TI
3411 return 0;
3412}
a361d84b 3413
1d045db9
TI
3414/* filter out invalid adc_nids (and capsrc_nids) that don't give all
3415 * active input pins
3416 */
3417static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
3418{
3419 struct alc_spec *spec = codec->spec;
3420 const struct hda_input_mux *imux;
3421 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3422 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3423 int i, n, nums;
a361d84b 3424
1d045db9
TI
3425 imux = spec->input_mux;
3426 if (!imux)
3427 return;
3428 if (spec->dyn_adc_switch)
3429 return;
a361d84b 3430
1d045db9
TI
3431 nums = 0;
3432 for (n = 0; n < spec->num_adc_nids; n++) {
3433 hda_nid_t cap = spec->private_capsrc_nids[n];
3434 int num_conns = snd_hda_get_conn_list(codec, cap, NULL);
3435 for (i = 0; i < imux->num_items; i++) {
3436 hda_nid_t pin = spec->imux_pins[i];
3437 if (pin) {
3438 if (get_connection_index(codec, cap, pin) < 0)
3439 break;
3440 } else if (num_conns <= imux->items[i].index)
3441 break;
3442 }
3443 if (i >= imux->num_items) {
3444 adc_nids[nums] = spec->private_adc_nids[n];
3445 capsrc_nids[nums++] = cap;
22971e3a
TI
3446 }
3447 }
1d045db9
TI
3448 if (!nums) {
3449 /* check whether ADC-switch is possible */
3450 if (!alc_check_dyn_adc_switch(codec)) {
3451 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
3452 " using fallback 0x%x\n",
3453 codec->chip_name, spec->private_adc_nids[0]);
3454 spec->num_adc_nids = 1;
3455 spec->auto_mic = 0;
3456 return;
22971e3a 3457 }
1d045db9
TI
3458 } else if (nums != spec->num_adc_nids) {
3459 memcpy(spec->private_adc_nids, adc_nids,
3460 nums * sizeof(hda_nid_t));
3461 memcpy(spec->private_capsrc_nids, capsrc_nids,
3462 nums * sizeof(hda_nid_t));
3463 spec->num_adc_nids = nums;
22971e3a 3464 }
aef9d318 3465
1d045db9
TI
3466 if (spec->auto_mic)
3467 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
3468 else if (spec->input_mux->num_items == 1)
3469 spec->num_adc_nids = 1; /* reduce to a single ADC */
3470}
3471
3472/*
3473 * initialize ADC paths
3474 */
3475static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
3476{
3477 struct alc_spec *spec = codec->spec;
3478 hda_nid_t nid;
3479
3480 nid = spec->adc_nids[adc_idx];
3481 /* mute ADC */
44c02400 3482 if (nid_has_mute(codec, nid, HDA_INPUT)) {
1d045db9
TI
3483 snd_hda_codec_write(codec, nid, 0,
3484 AC_VERB_SET_AMP_GAIN_MUTE,
3485 AMP_IN_MUTE(0));
3486 return;
a361d84b 3487 }
1d045db9
TI
3488 if (!spec->capsrc_nids)
3489 return;
3490 nid = spec->capsrc_nids[adc_idx];
44c02400 3491 if (nid_has_mute(codec, nid, HDA_OUTPUT))
1d045db9
TI
3492 snd_hda_codec_write(codec, nid, 0,
3493 AC_VERB_SET_AMP_GAIN_MUTE,
3494 AMP_OUT_MUTE);
3495}
2134ea4f 3496
1d045db9
TI
3497static void alc_auto_init_input_src(struct hda_codec *codec)
3498{
3499 struct alc_spec *spec = codec->spec;
3500 int c, nums;
d6cc9fab 3501
1d045db9
TI
3502 for (c = 0; c < spec->num_adc_nids; c++)
3503 alc_auto_init_adc(codec, c);
3504 if (spec->dyn_adc_switch)
3505 nums = 1;
3506 else
3507 nums = spec->num_adc_nids;
3508 for (c = 0; c < nums; c++)
3509 alc_mux_select(codec, 0, spec->cur_mux[c], true);
3510}
2134ea4f 3511
1d045db9
TI
3512/* add mic boosts if needed */
3513static int alc_auto_add_mic_boost(struct hda_codec *codec)
3514{
3515 struct alc_spec *spec = codec->spec;
3516 struct auto_pin_cfg *cfg = &spec->autocfg;
3517 int i, err;
3518 int type_idx = 0;
3519 hda_nid_t nid;
3520 const char *prev_label = NULL;
ea1fb29a 3521
1d045db9
TI
3522 for (i = 0; i < cfg->num_inputs; i++) {
3523 if (cfg->inputs[i].type > AUTO_PIN_MIC)
3524 break;
3525 nid = cfg->inputs[i].pin;
3526 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
3527 const char *label;
3528 char boost_label[32];
3529
3530 label = hda_get_autocfg_input_label(codec, cfg, i);
3531 if (prev_label && !strcmp(label, prev_label))
3532 type_idx++;
3533 else
3534 type_idx = 0;
3535 prev_label = label;
bf1b0225 3536
1d045db9
TI
3537 snprintf(boost_label, sizeof(boost_label),
3538 "%s Boost Volume", label);
3539 err = add_control(spec, ALC_CTL_WIDGET_VOL,
3540 boost_label, type_idx,
3541 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
3542 if (err < 0)
3543 return err;
3544 }
3545 }
a361d84b
KY
3546 return 0;
3547}
3548
1d045db9
TI
3549/* select or unmute the given capsrc route */
3550static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
3551 int idx)
3552{
3553 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
3554 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
3555 HDA_AMP_MUTE, 0);
3556 } else if (snd_hda_get_conn_list(codec, cap, NULL) > 1) {
3557 snd_hda_codec_write_cache(codec, cap, 0,
3558 AC_VERB_SET_CONNECT_SEL, idx);
3559 }
3560}
f6a92248 3561
1d045db9
TI
3562/* set the default connection to that pin */
3563static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
3564{
3565 struct alc_spec *spec = codec->spec;
3566 int i;
f6a92248 3567
1d045db9
TI
3568 if (!pin)
3569 return 0;
3570 for (i = 0; i < spec->num_adc_nids; i++) {
3571 hda_nid_t cap = spec->capsrc_nids ?
3572 spec->capsrc_nids[i] : spec->adc_nids[i];
3573 int idx;
f53281e6 3574
1d045db9
TI
3575 idx = get_connection_index(codec, cap, pin);
3576 if (idx < 0)
3577 continue;
3578 select_or_unmute_capsrc(codec, cap, idx);
3579 return i; /* return the found index */
3580 }
3581 return -1; /* not found */
3582}
e01bf509 3583
1d045db9
TI
3584/* initialize some special cases for input sources */
3585static void alc_init_special_input_src(struct hda_codec *codec)
3586{
3587 struct alc_spec *spec = codec->spec;
3588 int i;
84898e87 3589
1d045db9
TI
3590 for (i = 0; i < spec->autocfg.num_inputs; i++)
3591 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
3592}
84898e87 3593
1d045db9
TI
3594/* assign appropriate capture mixers */
3595static void set_capture_mixer(struct hda_codec *codec)
3596{
3597 struct alc_spec *spec = codec->spec;
3598 static const struct snd_kcontrol_new *caps[2][3] = {
3599 { alc_capture_mixer_nosrc1,
3600 alc_capture_mixer_nosrc2,
3601 alc_capture_mixer_nosrc3 },
3602 { alc_capture_mixer1,
3603 alc_capture_mixer2,
3604 alc_capture_mixer3 },
3605 };
f6a92248 3606
1d045db9 3607 /* check whether either of ADC or MUX has a volume control */
44c02400 3608 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
1d045db9
TI
3609 if (!spec->capsrc_nids)
3610 return; /* no volume */
44c02400 3611 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
1d045db9
TI
3612 return; /* no volume in capsrc, too */
3613 spec->vol_in_capsrc = 1;
3614 }
60db6b53 3615
1d045db9
TI
3616 if (spec->num_adc_nids > 0) {
3617 int mux = 0;
3618 int num_adcs = 0;
64154835 3619
1d045db9
TI
3620 if (spec->input_mux && spec->input_mux->num_items > 1)
3621 mux = 1;
3622 if (spec->auto_mic) {
3623 num_adcs = 1;
3624 mux = 0;
3625 } else if (spec->dyn_adc_switch)
3626 num_adcs = 1;
3627 if (!num_adcs) {
3628 if (spec->num_adc_nids > 3)
3629 spec->num_adc_nids = 3;
3630 else if (!spec->num_adc_nids)
3631 return;
3632 num_adcs = spec->num_adc_nids;
3633 }
3634 spec->cap_mixer = caps[mux][num_adcs - 1];
3635 }
3636}
f53281e6 3637
e4770629
TI
3638/*
3639 * standard auto-parser initializations
3640 */
3641static void alc_auto_init_std(struct hda_codec *codec)
3642{
3643 struct alc_spec *spec = codec->spec;
3644 alc_auto_init_multi_out(codec);
3645 alc_auto_init_extra_out(codec);
3646 alc_auto_init_analog_input(codec);
3647 alc_auto_init_input_src(codec);
3648 alc_auto_init_digital(codec);
3649 if (spec->unsol_event)
3650 alc_inithook(codec);
3651}
3652
1d045db9
TI
3653/*
3654 * Digital-beep handlers
3655 */
3656#ifdef CONFIG_SND_HDA_INPUT_BEEP
3657#define set_beep_amp(spec, nid, idx, dir) \
3658 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
84898e87 3659
1d045db9
TI
3660static const struct snd_pci_quirk beep_white_list[] = {
3661 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
3662 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
3663 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
3664 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
3665 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
3666 {}
fe3eb0a7
KY
3667};
3668
1d045db9
TI
3669static inline int has_cdefine_beep(struct hda_codec *codec)
3670{
3671 struct alc_spec *spec = codec->spec;
3672 const struct snd_pci_quirk *q;
3673 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
3674 if (q)
3675 return q->value;
3676 return spec->cdefine.enable_pcbeep;
3677}
3678#else
3679#define set_beep_amp(spec, nid, idx, dir) /* NOP */
3680#define has_cdefine_beep(codec) 0
3681#endif
84898e87 3682
1d045db9
TI
3683/* parse the BIOS configuration and set up the alc_spec */
3684/* return 1 if successful, 0 if the proper config is not found,
3685 * or a negative error code
3686 */
3e6179b8
TI
3687static int alc_parse_auto_config(struct hda_codec *codec,
3688 const hda_nid_t *ignore_nids,
3689 const hda_nid_t *ssid_nids)
1d045db9
TI
3690{
3691 struct alc_spec *spec = codec->spec;
23c09b00 3692 struct auto_pin_cfg *cfg = &spec->autocfg;
1d045db9 3693 int err;
26f5df26 3694
53c334ad
TI
3695 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
3696 spec->parse_flags);
1d045db9
TI
3697 if (err < 0)
3698 return err;
23c09b00
TI
3699 if (!cfg->line_outs) {
3700 if (cfg->dig_outs || cfg->dig_in_pin) {
3e6179b8
TI
3701 spec->multiout.max_channels = 2;
3702 spec->no_analog = 1;
3703 goto dig_only;
3704 }
1d045db9 3705 return 0; /* can't find valid BIOS pin config */
3e6179b8 3706 }
23c09b00 3707
e23832ac 3708 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT && cfg->hp_outs > 0) {
23c09b00
TI
3709 /* use HP as primary out */
3710 cfg->speaker_outs = cfg->line_outs;
3711 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3712 sizeof(cfg->speaker_pins));
3713 cfg->line_outs = cfg->hp_outs;
3714 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
3715 cfg->hp_outs = 0;
3716 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3717 cfg->line_out_type = AUTO_PIN_HP_OUT;
3718 }
3719
1d045db9 3720 err = alc_auto_fill_dac_nids(codec);
3e6179b8
TI
3721 if (err < 0)
3722 return err;
23c09b00
TI
3723 err = alc_auto_add_multi_channel_mode(codec);
3724 if (err < 0)
3725 return err;
3726 err = alc_auto_fill_extra_dacs(codec);
1d045db9
TI
3727 if (err < 0)
3728 return err;
23c09b00 3729 err = alc_auto_create_multi_out_ctls(codec, cfg);
1d045db9
TI
3730 if (err < 0)
3731 return err;
3732 err = alc_auto_create_hp_out(codec);
3733 if (err < 0)
3734 return err;
3735 err = alc_auto_create_speaker_out(codec);
3736 if (err < 0)
3737 return err;
3738 err = alc_auto_create_input_ctls(codec);
3739 if (err < 0)
3740 return err;
84898e87 3741
1d045db9 3742 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
f53281e6 3743
3e6179b8 3744 dig_only:
1d045db9 3745 alc_auto_parse_digital(codec);
f6a92248 3746
3e6179b8
TI
3747 if (!spec->no_analog)
3748 alc_remove_invalid_adc_nids(codec);
3749
3750 if (ssid_nids)
3751 alc_ssid_check(codec, ssid_nids);
64154835 3752
3e6179b8
TI
3753 if (!spec->no_analog) {
3754 alc_auto_check_switches(codec);
3755 err = alc_auto_add_mic_boost(codec);
3756 if (err < 0)
3757 return err;
3758 }
f6a92248 3759
3e6179b8
TI
3760 if (spec->kctls.list)
3761 add_mixer(spec, spec->kctls.list);
f6a92248 3762
1d045db9 3763 return 1;
60db6b53 3764}
f6a92248 3765
3e6179b8
TI
3766static int alc880_parse_auto_config(struct hda_codec *codec)
3767{
3768 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
3769 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
3770 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
3771}
3772
1d045db9
TI
3773#ifdef CONFIG_SND_HDA_POWER_SAVE
3774static const struct hda_amp_list alc880_loopbacks[] = {
3775 { 0x0b, HDA_INPUT, 0 },
3776 { 0x0b, HDA_INPUT, 1 },
3777 { 0x0b, HDA_INPUT, 2 },
3778 { 0x0b, HDA_INPUT, 3 },
3779 { 0x0b, HDA_INPUT, 4 },
3780 { } /* end */
3781};
3782#endif
f6a92248 3783
1d045db9
TI
3784/*
3785 * board setups
3786 */
3787#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3788#define alc_board_config \
3789 snd_hda_check_board_config
3790#define alc_board_codec_sid_config \
3791 snd_hda_check_board_codec_sid_config
3792#include "alc_quirks.c"
3793#else
3794#define alc_board_config(codec, nums, models, tbl) -1
3795#define alc_board_codec_sid_config(codec, nums, models, tbl) -1
3796#define setup_preset(codec, x) /* NOP */
3797#endif
64154835 3798
1d045db9
TI
3799/*
3800 * OK, here we have finally the patch for ALC880
3801 */
3802#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3803#include "alc880_quirks.c"
3804#endif
4f5d1706 3805
1d045db9 3806static int patch_alc880(struct hda_codec *codec)
60db6b53 3807{
1d045db9
TI
3808 struct alc_spec *spec;
3809 int board_config;
3810 int err;
f6a92248 3811
1d045db9
TI
3812 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3813 if (spec == NULL)
3814 return -ENOMEM;
3b8510ce 3815
1d045db9 3816 codec->spec = spec;
64154835 3817
1d045db9 3818 spec->mixer_nid = 0x0b;
7b1655f5 3819 spec->need_dac_fix = 1;
f53281e6 3820
1d045db9
TI
3821 board_config = alc_board_config(codec, ALC880_MODEL_LAST,
3822 alc880_models, alc880_cfg_tbl);
3823 if (board_config < 0) {
3824 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
3825 codec->chip_name);
3826 board_config = ALC_MODEL_AUTO;
3827 }
f53281e6 3828
1d045db9
TI
3829 if (board_config == ALC_MODEL_AUTO) {
3830 /* automatic parse from the BIOS config */
3831 err = alc880_parse_auto_config(codec);
3832 if (err < 0) {
3833 alc_free(codec);
3834 return err;
3835 }
3836#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3837 else if (!err) {
3838 printk(KERN_INFO
3839 "hda_codec: Cannot set up configuration "
3840 "from BIOS. Using 3-stack mode...\n");
3841 board_config = ALC880_3ST;
3842 }
3843#endif
3844 }
84898e87 3845
1d045db9
TI
3846 if (board_config != ALC_MODEL_AUTO)
3847 setup_preset(codec, &alc880_presets[board_config]);
fe3eb0a7 3848
60a6a842 3849 if (!spec->no_analog && !spec->adc_nids) {
1d045db9
TI
3850 alc_auto_fill_adc_caps(codec);
3851 alc_rebuild_imux_for_auto_mic(codec);
3852 alc_remove_invalid_adc_nids(codec);
3853 }
3e6179b8
TI
3854
3855 if (!spec->no_analog && !spec->cap_mixer)
3856 set_capture_mixer(codec);
3857
3858 if (!spec->no_analog) {
3859 err = snd_hda_attach_beep_device(codec, 0x1);
3860 if (err < 0) {
3861 alc_free(codec);
3862 return err;
3863 }
3864 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
3865 }
f53281e6 3866
1d045db9 3867 spec->vmaster_nid = 0x0c;
84898e87 3868
1d045db9
TI
3869 codec->patch_ops = alc_patch_ops;
3870 if (board_config == ALC_MODEL_AUTO)
e4770629 3871 spec->init_hook = alc_auto_init_std;
1d045db9
TI
3872#ifdef CONFIG_SND_HDA_POWER_SAVE
3873 if (!spec->loopback.amplist)
3874 spec->loopback.amplist = alc880_loopbacks;
3875#endif
f53281e6 3876
1d045db9 3877 return 0;
226b1ec8
KY
3878}
3879
1d045db9 3880
60db6b53 3881/*
1d045db9 3882 * ALC260 support
60db6b53 3883 */
1d045db9 3884static int alc260_parse_auto_config(struct hda_codec *codec)
f6a92248 3885{
1d045db9 3886 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
3e6179b8
TI
3887 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
3888 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
f6a92248
KY
3889}
3890
1d045db9
TI
3891#ifdef CONFIG_SND_HDA_POWER_SAVE
3892static const struct hda_amp_list alc260_loopbacks[] = {
3893 { 0x07, HDA_INPUT, 0 },
3894 { 0x07, HDA_INPUT, 1 },
3895 { 0x07, HDA_INPUT, 2 },
3896 { 0x07, HDA_INPUT, 3 },
3897 { 0x07, HDA_INPUT, 4 },
3898 { } /* end */
3899};
3900#endif
0ec33d1f 3901
1d045db9
TI
3902/*
3903 * Pin config fixes
3904 */
3905enum {
3906 PINFIX_HP_DC5750,
3907};
3908
3909static const struct alc_fixup alc260_fixups[] = {
3910 [PINFIX_HP_DC5750] = {
3911 .type = ALC_FIXUP_PINS,
3912 .v.pins = (const struct alc_pincfg[]) {
3913 { 0x11, 0x90130110 }, /* speaker */
3914 { }
3915 }
3916 },
3917};
3918
3919static const struct snd_pci_quirk alc260_fixup_tbl[] = {
3920 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", PINFIX_HP_DC5750),
3921 {}
3922};
3923
3924/*
3925 */
3926#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3927#include "alc260_quirks.c"
3928#endif
3929
3930static int patch_alc260(struct hda_codec *codec)
977ddd6b 3931{
1d045db9
TI
3932 struct alc_spec *spec;
3933 int err, board_config;
3934
3935 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3936 if (spec == NULL)
3937 return -ENOMEM;
3938
3939 codec->spec = spec;
3940
3941 spec->mixer_nid = 0x07;
3942
3943 board_config = alc_board_config(codec, ALC260_MODEL_LAST,
3944 alc260_models, alc260_cfg_tbl);
3945 if (board_config < 0) {
3946 snd_printd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
3947 codec->chip_name);
3948 board_config = ALC_MODEL_AUTO;
977ddd6b 3949 }
0ec33d1f 3950
1d045db9
TI
3951 if (board_config == ALC_MODEL_AUTO) {
3952 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
3953 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
977ddd6b
KY
3954 }
3955
1d045db9
TI
3956 if (board_config == ALC_MODEL_AUTO) {
3957 /* automatic parse from the BIOS config */
3958 err = alc260_parse_auto_config(codec);
3959 if (err < 0) {
3960 alc_free(codec);
3961 return err;
3962 }
3963#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3964 else if (!err) {
3965 printk(KERN_INFO
3966 "hda_codec: Cannot set up configuration "
3967 "from BIOS. Using base mode...\n");
3968 board_config = ALC260_BASIC;
3969 }
3970#endif
3971 }
977ddd6b 3972
1d045db9
TI
3973 if (board_config != ALC_MODEL_AUTO)
3974 setup_preset(codec, &alc260_presets[board_config]);
977ddd6b 3975
60a6a842 3976 if (!spec->no_analog && !spec->adc_nids) {
1d045db9
TI
3977 alc_auto_fill_adc_caps(codec);
3978 alc_rebuild_imux_for_auto_mic(codec);
3979 alc_remove_invalid_adc_nids(codec);
3980 }
3e6179b8
TI
3981
3982 if (!spec->no_analog && !spec->cap_mixer)
3983 set_capture_mixer(codec);
3984
3985 if (!spec->no_analog) {
3986 err = snd_hda_attach_beep_device(codec, 0x1);
3987 if (err < 0) {
3988 alc_free(codec);
3989 return err;
3990 }
3991 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
3992 }
977ddd6b 3993
1d045db9 3994 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
1a99d4a4 3995
1d045db9 3996 spec->vmaster_nid = 0x08;
1a99d4a4 3997
1d045db9
TI
3998 codec->patch_ops = alc_patch_ops;
3999 if (board_config == ALC_MODEL_AUTO)
8452a982 4000 spec->init_hook = alc_auto_init_std;
1d045db9
TI
4001 spec->shutup = alc_eapd_shutup;
4002#ifdef CONFIG_SND_HDA_POWER_SAVE
4003 if (!spec->loopback.amplist)
4004 spec->loopback.amplist = alc260_loopbacks;
4005#endif
6981d184 4006
1d045db9 4007 return 0;
6981d184
TI
4008}
4009
1d045db9
TI
4010
4011/*
4012 * ALC882/883/885/888/889 support
4013 *
4014 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
4015 * configuration. Each pin widget can choose any input DACs and a mixer.
4016 * Each ADC is connected from a mixer of all inputs. This makes possible
4017 * 6-channel independent captures.
4018 *
4019 * In addition, an independent DAC for the multi-playback (not used in this
4020 * driver yet).
4021 */
4022#ifdef CONFIG_SND_HDA_POWER_SAVE
4023#define alc882_loopbacks alc880_loopbacks
4024#endif
4025
4026/*
4027 * Pin config fixes
4028 */
ff818c24 4029enum {
1d045db9
TI
4030 PINFIX_ABIT_AW9D_MAX,
4031 PINFIX_LENOVO_Y530,
4032 PINFIX_PB_M5210,
4033 PINFIX_ACER_ASPIRE_7736,
ff818c24
TI
4034};
4035
1d045db9
TI
4036static const struct alc_fixup alc882_fixups[] = {
4037 [PINFIX_ABIT_AW9D_MAX] = {
4038 .type = ALC_FIXUP_PINS,
4039 .v.pins = (const struct alc_pincfg[]) {
4040 { 0x15, 0x01080104 }, /* side */
4041 { 0x16, 0x01011012 }, /* rear */
4042 { 0x17, 0x01016011 }, /* clfe */
2785591a 4043 { }
145a902b
DH
4044 }
4045 },
1d045db9 4046 [PINFIX_LENOVO_Y530] = {
b5bfbc67
TI
4047 .type = ALC_FIXUP_PINS,
4048 .v.pins = (const struct alc_pincfg[]) {
1d045db9
TI
4049 { 0x15, 0x99130112 }, /* rear int speakers */
4050 { 0x16, 0x99130111 }, /* subwoofer */
ac612407
DH
4051 { }
4052 }
4053 },
1d045db9 4054 [PINFIX_PB_M5210] = {
b5bfbc67
TI
4055 .type = ALC_FIXUP_VERBS,
4056 .v.verbs = (const struct hda_verb[]) {
1d045db9 4057 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
357f915e
KY
4058 {}
4059 }
4060 },
1d045db9
TI
4061 [PINFIX_ACER_ASPIRE_7736] = {
4062 .type = ALC_FIXUP_SKU,
4063 .v.sku = ALC_FIXUP_SKU_IGNORE,
6981d184 4064 },
ff818c24
TI
4065};
4066
1d045db9
TI
4067static const struct snd_pci_quirk alc882_fixup_tbl[] = {
4068 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", PINFIX_PB_M5210),
4069 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", PINFIX_LENOVO_Y530),
4070 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
4071 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", PINFIX_ACER_ASPIRE_7736),
ff818c24
TI
4072 {}
4073};
4074
f6a92248 4075/*
1d045db9 4076 * BIOS auto configuration
f6a92248 4077 */
1d045db9
TI
4078/* almost identical with ALC880 parser... */
4079static int alc882_parse_auto_config(struct hda_codec *codec)
4080{
1d045db9 4081 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
3e6179b8
TI
4082 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4083 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
1d045db9 4084}
b896b4eb 4085
1d045db9
TI
4086/*
4087 */
4088#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4089#include "alc882_quirks.c"
4090#endif
4091
4092static int patch_alc882(struct hda_codec *codec)
f6a92248
KY
4093{
4094 struct alc_spec *spec;
1d045db9 4095 int err, board_config;
f6a92248
KY
4096
4097 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4098 if (spec == NULL)
4099 return -ENOMEM;
4100
4101 codec->spec = spec;
4102
1f0f4b80
TI
4103 spec->mixer_nid = 0x0b;
4104
1d045db9
TI
4105 switch (codec->vendor_id) {
4106 case 0x10ec0882:
4107 case 0x10ec0885:
4108 break;
4109 default:
4110 /* ALC883 and variants */
4111 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
4112 break;
c793bec5 4113 }
977ddd6b 4114
1d045db9
TI
4115 board_config = alc_board_config(codec, ALC882_MODEL_LAST,
4116 alc882_models, alc882_cfg_tbl);
4117
4118 if (board_config < 0)
4119 board_config = alc_board_codec_sid_config(codec,
4120 ALC882_MODEL_LAST, alc882_models, alc882_ssid_cfg_tbl);
f6a92248
KY
4121
4122 if (board_config < 0) {
9a11f1aa
TI
4123 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4124 codec->chip_name);
1d045db9 4125 board_config = ALC_MODEL_AUTO;
f6a92248
KY
4126 }
4127
1d045db9
TI
4128 if (board_config == ALC_MODEL_AUTO) {
4129 alc_pick_fixup(codec, NULL, alc882_fixup_tbl, alc882_fixups);
b5bfbc67
TI
4130 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4131 }
ff818c24 4132
1d045db9
TI
4133 alc_auto_parse_customize_define(codec);
4134
4135 if (board_config == ALC_MODEL_AUTO) {
f6a92248 4136 /* automatic parse from the BIOS config */
1d045db9 4137 err = alc882_parse_auto_config(codec);
f6a92248
KY
4138 if (err < 0) {
4139 alc_free(codec);
4140 return err;
1d045db9
TI
4141 }
4142#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4143 else if (!err) {
f6a92248
KY
4144 printk(KERN_INFO
4145 "hda_codec: Cannot set up configuration "
4146 "from BIOS. Using base mode...\n");
1d045db9 4147 board_config = ALC882_3ST_DIG;
f6a92248 4148 }
1d045db9 4149#endif
f6a92248
KY
4150 }
4151
1d045db9
TI
4152 if (board_config != ALC_MODEL_AUTO)
4153 setup_preset(codec, &alc882_presets[board_config]);
f6a92248 4154
60a6a842 4155 if (!spec->no_analog && !spec->adc_nids) {
d6cc9fab 4156 alc_auto_fill_adc_caps(codec);
21268961 4157 alc_rebuild_imux_for_auto_mic(codec);
d6cc9fab 4158 alc_remove_invalid_adc_nids(codec);
84898e87
KY
4159 }
4160
3e6179b8
TI
4161 if (!spec->no_analog && !spec->cap_mixer)
4162 set_capture_mixer(codec);
1d045db9 4163
3e6179b8
TI
4164 if (!spec->no_analog && has_cdefine_beep(codec)) {
4165 err = snd_hda_attach_beep_device(codec, 0x1);
4166 if (err < 0) {
4167 alc_free(codec);
4168 return err;
4169 }
1d045db9 4170 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
3e6179b8 4171 }
f6a92248 4172
b5bfbc67 4173 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
ff818c24 4174
1d045db9 4175 spec->vmaster_nid = 0x0c;
100d5eb3 4176
f6a92248 4177 codec->patch_ops = alc_patch_ops;
1d045db9 4178 if (board_config == ALC_MODEL_AUTO)
e4770629 4179 spec->init_hook = alc_auto_init_std;
bf1b0225
KY
4180
4181 alc_init_jacks(codec);
f6a92248
KY
4182#ifdef CONFIG_SND_HDA_POWER_SAVE
4183 if (!spec->loopback.amplist)
1d045db9 4184 spec->loopback.amplist = alc882_loopbacks;
f6a92248
KY
4185#endif
4186
4187 return 0;
4188}
4189
df694daa 4190
df694daa 4191/*
1d045db9 4192 * ALC262 support
df694daa 4193 */
1d045db9 4194static int alc262_parse_auto_config(struct hda_codec *codec)
df694daa 4195{
1d045db9 4196 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
3e6179b8
TI
4197 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4198 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
df694daa
KY
4199}
4200
df694daa 4201/*
1d045db9 4202 * Pin config fixes
df694daa 4203 */
cfc9b06f 4204enum {
1d045db9
TI
4205 PINFIX_FSC_H270,
4206 PINFIX_HP_Z200,
cfc9b06f
TI
4207};
4208
1d045db9
TI
4209static const struct alc_fixup alc262_fixups[] = {
4210 [PINFIX_FSC_H270] = {
b5bfbc67
TI
4211 .type = ALC_FIXUP_PINS,
4212 .v.pins = (const struct alc_pincfg[]) {
1d045db9
TI
4213 { 0x14, 0x99130110 }, /* speaker */
4214 { 0x15, 0x0221142f }, /* front HP */
4215 { 0x1b, 0x0121141f }, /* rear HP */
4216 { }
4217 }
4218 },
4219 [PINFIX_HP_Z200] = {
4220 .type = ALC_FIXUP_PINS,
4221 .v.pins = (const struct alc_pincfg[]) {
4222 { 0x16, 0x99130120 }, /* internal speaker */
73413b12
TI
4223 { }
4224 }
cfc9b06f
TI
4225 },
4226};
4227
1d045db9
TI
4228static const struct snd_pci_quirk alc262_fixup_tbl[] = {
4229 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", PINFIX_HP_Z200),
4230 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", PINFIX_FSC_H270),
cfc9b06f
TI
4231 {}
4232};
df694daa 4233
1d045db9
TI
4234
4235#ifdef CONFIG_SND_HDA_POWER_SAVE
4236#define alc262_loopbacks alc880_loopbacks
4237#endif
4238
1d045db9
TI
4239/*
4240 */
4241#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4242#include "alc262_quirks.c"
4243#endif
4244
4245static int patch_alc262(struct hda_codec *codec)
df694daa
KY
4246{
4247 struct alc_spec *spec;
4248 int board_config;
4249 int err;
4250
dc041e0b 4251 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
df694daa
KY
4252 if (spec == NULL)
4253 return -ENOMEM;
4254
f12ab1e0 4255 codec->spec = spec;
df694daa 4256
1d045db9
TI
4257 spec->mixer_nid = 0x0b;
4258
4259#if 0
4260 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
4261 * under-run
4262 */
4263 {
4264 int tmp;
4265 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4266 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
4267 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4268 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
4269 }
4270#endif
4271 alc_auto_parse_customize_define(codec);
1f0f4b80 4272
1d045db9
TI
4273 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
4274
4275 board_config = alc_board_config(codec, ALC262_MODEL_LAST,
4276 alc262_models, alc262_cfg_tbl);
9c7f852e 4277
f5fcc13c 4278 if (board_config < 0) {
9a11f1aa
TI
4279 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4280 codec->chip_name);
1d045db9 4281 board_config = ALC_MODEL_AUTO;
df694daa
KY
4282 }
4283
1d045db9
TI
4284 if (board_config == ALC_MODEL_AUTO) {
4285 alc_pick_fixup(codec, NULL, alc262_fixup_tbl, alc262_fixups);
b5bfbc67
TI
4286 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4287 }
cfc9b06f 4288
1d045db9 4289 if (board_config == ALC_MODEL_AUTO) {
df694daa 4290 /* automatic parse from the BIOS config */
1d045db9 4291 err = alc262_parse_auto_config(codec);
df694daa
KY
4292 if (err < 0) {
4293 alc_free(codec);
4294 return err;
1d045db9
TI
4295 }
4296#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4297 else if (!err) {
9c7f852e
TI
4298 printk(KERN_INFO
4299 "hda_codec: Cannot set up configuration "
4300 "from BIOS. Using base mode...\n");
1d045db9 4301 board_config = ALC262_BASIC;
df694daa 4302 }
1d045db9 4303#endif
df694daa
KY
4304 }
4305
1d045db9
TI
4306 if (board_config != ALC_MODEL_AUTO)
4307 setup_preset(codec, &alc262_presets[board_config]);
df694daa 4308
60a6a842 4309 if (!spec->no_analog && !spec->adc_nids) {
21268961
TI
4310 alc_auto_fill_adc_caps(codec);
4311 alc_rebuild_imux_for_auto_mic(codec);
4312 alc_remove_invalid_adc_nids(codec);
4313 }
3e6179b8
TI
4314
4315 if (!spec->no_analog && !spec->cap_mixer)
c7a8eb10 4316 set_capture_mixer(codec);
3e6179b8
TI
4317
4318 if (!spec->no_analog && has_cdefine_beep(codec)) {
4319 err = snd_hda_attach_beep_device(codec, 0x1);
4320 if (err < 0) {
4321 alc_free(codec);
4322 return err;
4323 }
1d045db9 4324 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
3e6179b8 4325 }
2134ea4f 4326
b5bfbc67 4327 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
7fa90e87 4328
1d045db9
TI
4329 spec->vmaster_nid = 0x0c;
4330
df694daa 4331 codec->patch_ops = alc_patch_ops;
1d045db9 4332 if (board_config == ALC_MODEL_AUTO)
e4770629 4333 spec->init_hook = alc_auto_init_std;
1d045db9
TI
4334 spec->shutup = alc_eapd_shutup;
4335
4336 alc_init_jacks(codec);
cb53c626
TI
4337#ifdef CONFIG_SND_HDA_POWER_SAVE
4338 if (!spec->loopback.amplist)
1d045db9 4339 spec->loopback.amplist = alc262_loopbacks;
cb53c626 4340#endif
ea1fb29a 4341
1da177e4
LT
4342 return 0;
4343}
4344
f32610ed 4345/*
1d045db9 4346 * ALC268
f32610ed 4347 */
1d045db9
TI
4348/* bind Beep switches of both NID 0x0f and 0x10 */
4349static const struct hda_bind_ctls alc268_bind_beep_sw = {
4350 .ops = &snd_hda_bind_sw,
4351 .values = {
4352 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
4353 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
4354 0
4355 },
f32610ed
JS
4356};
4357
1d045db9
TI
4358static const struct snd_kcontrol_new alc268_beep_mixer[] = {
4359 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
4360 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
4361 { }
f32610ed
JS
4362};
4363
1d045db9
TI
4364/* set PCBEEP vol = 0, mute connections */
4365static const struct hda_verb alc268_beep_init_verbs[] = {
4366 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4367 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4368 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4369 { }
f32610ed
JS
4370};
4371
4372/*
4373 * BIOS auto configuration
4374 */
1d045db9 4375static int alc268_parse_auto_config(struct hda_codec *codec)
f32610ed 4376{
3e6179b8 4377 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
f32610ed 4378 struct alc_spec *spec = codec->spec;
3e6179b8
TI
4379 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
4380 if (err > 0) {
4381 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
4382 add_mixer(spec, alc268_beep_mixer);
4383 add_verb(spec, alc268_beep_init_verbs);
1d045db9 4384 }
1d045db9 4385 }
3e6179b8 4386 return err;
f32610ed
JS
4387}
4388
1d045db9
TI
4389/*
4390 */
1d045db9 4391static int patch_alc268(struct hda_codec *codec)
f32610ed
JS
4392{
4393 struct alc_spec *spec;
1d045db9 4394 int i, has_beep, err;
f32610ed
JS
4395
4396 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4397 if (spec == NULL)
4398 return -ENOMEM;
4399
4400 codec->spec = spec;
4401
1d045db9 4402 /* ALC268 has no aa-loopback mixer */
1f0f4b80 4403
6ebb8053
TI
4404 /* automatic parse from the BIOS config */
4405 err = alc268_parse_auto_config(codec);
4406 if (err < 0) {
4407 alc_free(codec);
4408 return err;
f32610ed
JS
4409 }
4410
1d045db9
TI
4411 has_beep = 0;
4412 for (i = 0; i < spec->num_mixers; i++) {
4413 if (spec->mixers[i] == alc268_beep_mixer) {
4414 has_beep = 1;
4415 break;
4416 }
4417 }
f32610ed 4418
1d045db9
TI
4419 if (has_beep) {
4420 err = snd_hda_attach_beep_device(codec, 0x1);
4421 if (err < 0) {
4422 alc_free(codec);
4423 return err;
4424 }
4425 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
4426 /* override the amp caps for beep generator */
4427 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
4428 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
4429 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
4430 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4431 (0 << AC_AMPCAP_MUTE_SHIFT));
2f893286
KY
4432 }
4433
60a6a842 4434 if (!spec->no_analog && !spec->adc_nids) {
d6cc9fab 4435 alc_auto_fill_adc_caps(codec);
21268961 4436 alc_rebuild_imux_for_auto_mic(codec);
d6cc9fab 4437 alc_remove_invalid_adc_nids(codec);
dd704698 4438 }
f32610ed 4439
3e6179b8 4440 if (!spec->no_analog && !spec->cap_mixer)
1d045db9 4441 set_capture_mixer(codec);
f32610ed 4442
2134ea4f
TI
4443 spec->vmaster_nid = 0x02;
4444
f32610ed 4445 codec->patch_ops = alc_patch_ops;
6ebb8053 4446 spec->init_hook = alc_auto_init_std;
1c716153 4447 spec->shutup = alc_eapd_shutup;
1d045db9
TI
4448
4449 alc_init_jacks(codec);
f32610ed
JS
4450
4451 return 0;
4452}
4453
bc9f98a9 4454/*
1d045db9 4455 * ALC269
bc9f98a9 4456 */
1d045db9
TI
4457#ifdef CONFIG_SND_HDA_POWER_SAVE
4458#define alc269_loopbacks alc880_loopbacks
4459#endif
e1406348 4460
1d045db9
TI
4461static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
4462 .substreams = 1,
4463 .channels_min = 2,
4464 .channels_max = 8,
4465 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
4466 /* NID is set in alc_build_pcms */
4467 .ops = {
4468 .open = alc_playback_pcm_open,
4469 .prepare = alc_playback_pcm_prepare,
4470 .cleanup = alc_playback_pcm_cleanup
bc9f98a9
KY
4471 },
4472};
4473
1d045db9
TI
4474static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
4475 .substreams = 1,
4476 .channels_min = 2,
4477 .channels_max = 2,
4478 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
4479 /* NID is set in alc_build_pcms */
bc9f98a9 4480};
291702f0 4481
1d045db9
TI
4482#ifdef CONFIG_SND_HDA_POWER_SAVE
4483static int alc269_mic2_for_mute_led(struct hda_codec *codec)
4484{
4485 switch (codec->subsystem_id) {
4486 case 0x103c1586:
4487 return 1;
4488 }
4489 return 0;
4490}
6dda9f4a 4491
1d045db9
TI
4492static int alc269_mic2_mute_check_ps(struct hda_codec *codec, hda_nid_t nid)
4493{
4494 /* update mute-LED according to the speaker mute state */
4495 if (nid == 0x01 || nid == 0x14) {
4496 int pinval;
4497 if (snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0) &
4498 HDA_AMP_MUTE)
4499 pinval = 0x24;
4500 else
4501 pinval = 0x20;
4502 /* mic2 vref pin is used for mute LED control */
4503 snd_hda_codec_update_cache(codec, 0x19, 0,
4504 AC_VERB_SET_PIN_WIDGET_CONTROL,
4505 pinval);
4506 }
4507 return alc_check_power_status(codec, nid);
4508}
4509#endif /* CONFIG_SND_HDA_POWER_SAVE */
9541ba1d 4510
1d045db9
TI
4511/* different alc269-variants */
4512enum {
4513 ALC269_TYPE_ALC269VA,
4514 ALC269_TYPE_ALC269VB,
4515 ALC269_TYPE_ALC269VC,
bc9f98a9
KY
4516};
4517
4518/*
1d045db9 4519 * BIOS auto configuration
bc9f98a9 4520 */
1d045db9
TI
4521static int alc269_parse_auto_config(struct hda_codec *codec)
4522{
1d045db9 4523 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
3e6179b8
TI
4524 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
4525 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4526 struct alc_spec *spec = codec->spec;
4527 const hda_nid_t *ssids = spec->codec_variant == ALC269_TYPE_ALC269VA ?
4528 alc269va_ssids : alc269_ssids;
bc9f98a9 4529
3e6179b8 4530 return alc_parse_auto_config(codec, alc269_ignore, ssids);
1d045db9 4531}
bc9f98a9 4532
1d045db9
TI
4533static void alc269_toggle_power_output(struct hda_codec *codec, int power_up)
4534{
4535 int val = alc_read_coef_idx(codec, 0x04);
4536 if (power_up)
4537 val |= 1 << 11;
4538 else
4539 val &= ~(1 << 11);
4540 alc_write_coef_idx(codec, 0x04, val);
4541}
291702f0 4542
1d045db9
TI
4543static void alc269_shutup(struct hda_codec *codec)
4544{
4545 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x017)
4546 alc269_toggle_power_output(codec, 0);
4547 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x018) {
4548 alc269_toggle_power_output(codec, 0);
4549 msleep(150);
4550 }
4551}
291702f0 4552
2a43952a 4553#ifdef CONFIG_PM
1d045db9
TI
4554static int alc269_resume(struct hda_codec *codec)
4555{
4556 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x018) {
4557 alc269_toggle_power_output(codec, 0);
4558 msleep(150);
4559 }
8c427226 4560
1d045db9 4561 codec->patch_ops.init(codec);
f1d4e28b 4562
1d045db9
TI
4563 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x017) {
4564 alc269_toggle_power_output(codec, 1);
4565 msleep(200);
4566 }
f1d4e28b 4567
1d045db9
TI
4568 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x018)
4569 alc269_toggle_power_output(codec, 1);
f1d4e28b 4570
1d045db9
TI
4571 snd_hda_codec_resume_amp(codec);
4572 snd_hda_codec_resume_cache(codec);
4573 hda_call_check_power_status(codec, 0x01);
4574 return 0;
4575}
2a43952a 4576#endif /* CONFIG_PM */
f1d4e28b 4577
1d045db9
TI
4578static void alc269_fixup_hweq(struct hda_codec *codec,
4579 const struct alc_fixup *fix, int action)
4580{
4581 int coef;
f1d4e28b 4582
1d045db9
TI
4583 if (action != ALC_FIXUP_ACT_INIT)
4584 return;
4585 coef = alc_read_coef_idx(codec, 0x1e);
4586 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
4587}
f1d4e28b 4588
1d045db9
TI
4589static void alc271_fixup_dmic(struct hda_codec *codec,
4590 const struct alc_fixup *fix, int action)
4591{
4592 static const struct hda_verb verbs[] = {
4593 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
4594 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
4595 {}
4596 };
4597 unsigned int cfg;
f1d4e28b 4598
1d045db9
TI
4599 if (strcmp(codec->chip_name, "ALC271X"))
4600 return;
4601 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
4602 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
4603 snd_hda_sequence_write(codec, verbs);
4604}
f1d4e28b 4605
017f2a10
TI
4606static void alc269_fixup_pcm_44k(struct hda_codec *codec,
4607 const struct alc_fixup *fix, int action)
4608{
4609 struct alc_spec *spec = codec->spec;
4610
4611 if (action != ALC_FIXUP_ACT_PROBE)
4612 return;
4613
4614 /* Due to a hardware problem on Lenovo Ideadpad, we need to
4615 * fix the sample rate of analog I/O to 44.1kHz
4616 */
4617 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
4618 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
4619}
4620
adabb3ec
TI
4621static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
4622 const struct alc_fixup *fix, int action)
4623{
4624 int coef;
4625
4626 if (action != ALC_FIXUP_ACT_INIT)
4627 return;
4628 /* The digital-mic unit sends PDM (differential signal) instead of
4629 * the standard PCM, thus you can't record a valid mono stream as is.
4630 * Below is a workaround specific to ALC269 to control the dmic
4631 * signal source as mono.
4632 */
4633 coef = alc_read_coef_idx(codec, 0x07);
4634 alc_write_coef_idx(codec, 0x07, coef | 0x80);
4635}
4636
24519911
TI
4637static void alc269_quanta_automute(struct hda_codec *codec)
4638{
4639 update_speakers(codec);
4640
4641 snd_hda_codec_write(codec, 0x20, 0,
4642 AC_VERB_SET_COEF_INDEX, 0x0c);
4643 snd_hda_codec_write(codec, 0x20, 0,
4644 AC_VERB_SET_PROC_COEF, 0x680);
4645
4646 snd_hda_codec_write(codec, 0x20, 0,
4647 AC_VERB_SET_COEF_INDEX, 0x0c);
4648 snd_hda_codec_write(codec, 0x20, 0,
4649 AC_VERB_SET_PROC_COEF, 0x480);
4650}
4651
4652static void alc269_fixup_quanta_mute(struct hda_codec *codec,
4653 const struct alc_fixup *fix, int action)
4654{
4655 struct alc_spec *spec = codec->spec;
4656 if (action != ALC_FIXUP_ACT_PROBE)
4657 return;
4658 spec->automute_hook = alc269_quanta_automute;
4659}
4660
1d045db9
TI
4661enum {
4662 ALC269_FIXUP_SONY_VAIO,
4663 ALC275_FIXUP_SONY_VAIO_GPIO2,
4664 ALC269_FIXUP_DELL_M101Z,
4665 ALC269_FIXUP_SKU_IGNORE,
4666 ALC269_FIXUP_ASUS_G73JW,
4667 ALC269_FIXUP_LENOVO_EAPD,
4668 ALC275_FIXUP_SONY_HWEQ,
4669 ALC271_FIXUP_DMIC,
017f2a10 4670 ALC269_FIXUP_PCM_44K,
adabb3ec 4671 ALC269_FIXUP_STEREO_DMIC,
24519911
TI
4672 ALC269_FIXUP_QUANTA_MUTE,
4673 ALC269_FIXUP_LIFEBOOK,
f1d4e28b
KY
4674};
4675
1d045db9
TI
4676static const struct alc_fixup alc269_fixups[] = {
4677 [ALC269_FIXUP_SONY_VAIO] = {
4678 .type = ALC_FIXUP_VERBS,
4679 .v.verbs = (const struct hda_verb[]) {
4680 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
4681 {}
4682 }
f1d4e28b 4683 },
1d045db9
TI
4684 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
4685 .type = ALC_FIXUP_VERBS,
4686 .v.verbs = (const struct hda_verb[]) {
4687 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
4688 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
4689 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
4690 { }
4691 },
4692 .chained = true,
4693 .chain_id = ALC269_FIXUP_SONY_VAIO
4694 },
4695 [ALC269_FIXUP_DELL_M101Z] = {
4696 .type = ALC_FIXUP_VERBS,
4697 .v.verbs = (const struct hda_verb[]) {
4698 /* Enables internal speaker */
4699 {0x20, AC_VERB_SET_COEF_INDEX, 13},
4700 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
4701 {}
4702 }
4703 },
4704 [ALC269_FIXUP_SKU_IGNORE] = {
4705 .type = ALC_FIXUP_SKU,
4706 .v.sku = ALC_FIXUP_SKU_IGNORE,
4707 },
4708 [ALC269_FIXUP_ASUS_G73JW] = {
4709 .type = ALC_FIXUP_PINS,
4710 .v.pins = (const struct alc_pincfg[]) {
4711 { 0x17, 0x99130111 }, /* subwoofer */
4712 { }
4713 }
4714 },
4715 [ALC269_FIXUP_LENOVO_EAPD] = {
4716 .type = ALC_FIXUP_VERBS,
4717 .v.verbs = (const struct hda_verb[]) {
4718 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
4719 {}
4720 }
4721 },
4722 [ALC275_FIXUP_SONY_HWEQ] = {
4723 .type = ALC_FIXUP_FUNC,
4724 .v.func = alc269_fixup_hweq,
4725 .chained = true,
4726 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
4727 },
4728 [ALC271_FIXUP_DMIC] = {
4729 .type = ALC_FIXUP_FUNC,
4730 .v.func = alc271_fixup_dmic,
f1d4e28b 4731 },
017f2a10
TI
4732 [ALC269_FIXUP_PCM_44K] = {
4733 .type = ALC_FIXUP_FUNC,
4734 .v.func = alc269_fixup_pcm_44k,
4735 },
adabb3ec
TI
4736 [ALC269_FIXUP_STEREO_DMIC] = {
4737 .type = ALC_FIXUP_FUNC,
4738 .v.func = alc269_fixup_stereo_dmic,
4739 },
24519911
TI
4740 [ALC269_FIXUP_QUANTA_MUTE] = {
4741 .type = ALC_FIXUP_FUNC,
4742 .v.func = alc269_fixup_quanta_mute,
4743 },
4744 [ALC269_FIXUP_LIFEBOOK] = {
4745 .type = ALC_FIXUP_PINS,
4746 .v.pins = (const struct alc_pincfg[]) {
4747 { 0x1a, 0x2101103f }, /* dock line-out */
4748 { 0x1b, 0x23a11040 }, /* dock mic-in */
4749 { }
4750 },
4751 .chained = true,
4752 .chain_id = ALC269_FIXUP_QUANTA_MUTE
4753 },
f1d4e28b
KY
4754};
4755
1d045db9 4756static const struct snd_pci_quirk alc269_fixup_tbl[] = {
017f2a10 4757 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
adabb3ec
TI
4758 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
4759 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
4760 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
4761 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
4762 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
1d045db9
TI
4763 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
4764 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
4765 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
4766 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
4767 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
4768 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
24519911 4769 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
1d045db9
TI
4770 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
4771 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
4772 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
4773 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
4774 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
24519911 4775 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_QUANTA_MUTE),
017f2a10 4776 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K),
1d045db9
TI
4777 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
4778 {}
6dda9f4a
KY
4779};
4780
6dda9f4a 4781
1d045db9
TI
4782static int alc269_fill_coef(struct hda_codec *codec)
4783{
4784 int val;
ebb83eeb 4785
1d045db9
TI
4786 if ((alc_read_coef_idx(codec, 0) & 0x00ff) < 0x015) {
4787 alc_write_coef_idx(codec, 0xf, 0x960b);
4788 alc_write_coef_idx(codec, 0xe, 0x8817);
4789 }
ebb83eeb 4790
1d045db9
TI
4791 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x016) {
4792 alc_write_coef_idx(codec, 0xf, 0x960b);
4793 alc_write_coef_idx(codec, 0xe, 0x8814);
4794 }
ebb83eeb 4795
1d045db9
TI
4796 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x017) {
4797 val = alc_read_coef_idx(codec, 0x04);
4798 /* Power up output pin */
4799 alc_write_coef_idx(codec, 0x04, val | (1<<11));
4800 }
ebb83eeb 4801
1d045db9
TI
4802 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x018) {
4803 val = alc_read_coef_idx(codec, 0xd);
4804 if ((val & 0x0c00) >> 10 != 0x1) {
4805 /* Capless ramp up clock control */
4806 alc_write_coef_idx(codec, 0xd, val | (1<<10));
4807 }
4808 val = alc_read_coef_idx(codec, 0x17);
4809 if ((val & 0x01c0) >> 6 != 0x4) {
4810 /* Class D power on reset */
4811 alc_write_coef_idx(codec, 0x17, val | (1<<7));
4812 }
4813 }
ebb83eeb 4814
1d045db9
TI
4815 val = alc_read_coef_idx(codec, 0xd); /* Class D */
4816 alc_write_coef_idx(codec, 0xd, val | (1<<14));
bc9f98a9 4817
1d045db9
TI
4818 val = alc_read_coef_idx(codec, 0x4); /* HP */
4819 alc_write_coef_idx(codec, 0x4, val | (1<<11));
6dda9f4a 4820
1d045db9
TI
4821 return 0;
4822}
a7f2371f 4823
1d045db9
TI
4824/*
4825 */
4826#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4827#include "alc269_quirks.c"
4828#endif
bc9f98a9 4829
1d045db9
TI
4830static int patch_alc269(struct hda_codec *codec)
4831{
4832 struct alc_spec *spec;
4833 int board_config, coef;
4834 int err;
291702f0 4835
1d045db9
TI
4836 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4837 if (spec == NULL)
4838 return -ENOMEM;
bc9f98a9 4839
1d045db9 4840 codec->spec = spec;
8c427226 4841
1d045db9 4842 spec->mixer_nid = 0x0b;
f1d4e28b 4843
1d045db9 4844 alc_auto_parse_customize_define(codec);
f1d4e28b 4845
1d045db9
TI
4846 if (codec->vendor_id == 0x10ec0269) {
4847 spec->codec_variant = ALC269_TYPE_ALC269VA;
4848 coef = alc_read_coef_idx(codec, 0);
4849 if ((coef & 0x00f0) == 0x0010) {
4850 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
4851 spec->cdefine.platform_type == 1) {
4852 alc_codec_rename(codec, "ALC271X");
4853 } else if ((coef & 0xf000) == 0x2000) {
4854 alc_codec_rename(codec, "ALC259");
4855 } else if ((coef & 0xf000) == 0x3000) {
4856 alc_codec_rename(codec, "ALC258");
4857 } else if ((coef & 0xfff0) == 0x3010) {
4858 alc_codec_rename(codec, "ALC277");
4859 } else {
4860 alc_codec_rename(codec, "ALC269VB");
4861 }
4862 spec->codec_variant = ALC269_TYPE_ALC269VB;
4863 } else if ((coef & 0x00f0) == 0x0020) {
4864 if (coef == 0xa023)
4865 alc_codec_rename(codec, "ALC259");
4866 else if (coef == 0x6023)
4867 alc_codec_rename(codec, "ALC281X");
4868 else if (codec->bus->pci->subsystem_vendor == 0x17aa &&
4869 codec->bus->pci->subsystem_device == 0x21f3)
4870 alc_codec_rename(codec, "ALC3202");
4871 else
4872 alc_codec_rename(codec, "ALC269VC");
4873 spec->codec_variant = ALC269_TYPE_ALC269VC;
4874 } else
4875 alc_fix_pll_init(codec, 0x20, 0x04, 15);
4876 alc269_fill_coef(codec);
4877 }
6dda9f4a 4878
1d045db9
TI
4879 board_config = alc_board_config(codec, ALC269_MODEL_LAST,
4880 alc269_models, alc269_cfg_tbl);
6dda9f4a 4881
1d045db9
TI
4882 if (board_config < 0) {
4883 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4884 codec->chip_name);
4885 board_config = ALC_MODEL_AUTO;
4886 }
f1d4e28b 4887
1d045db9
TI
4888 if (board_config == ALC_MODEL_AUTO) {
4889 alc_pick_fixup(codec, NULL, alc269_fixup_tbl, alc269_fixups);
4890 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4891 }
6dda9f4a 4892
1d045db9
TI
4893 if (board_config == ALC_MODEL_AUTO) {
4894 /* automatic parse from the BIOS config */
4895 err = alc269_parse_auto_config(codec);
4896 if (err < 0) {
4897 alc_free(codec);
4898 return err;
4899 }
4900#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4901 else if (!err) {
4902 printk(KERN_INFO
4903 "hda_codec: Cannot set up configuration "
4904 "from BIOS. Using base mode...\n");
4905 board_config = ALC269_BASIC;
4906 }
4907#endif
4908 }
6dda9f4a 4909
1d045db9
TI
4910 if (board_config != ALC_MODEL_AUTO)
4911 setup_preset(codec, &alc269_presets[board_config]);
6dda9f4a 4912
60a6a842 4913 if (!spec->no_analog && !spec->adc_nids) {
1d045db9
TI
4914 alc_auto_fill_adc_caps(codec);
4915 alc_rebuild_imux_for_auto_mic(codec);
4916 alc_remove_invalid_adc_nids(codec);
4917 }
6dda9f4a 4918
3e6179b8 4919 if (!spec->no_analog && !spec->cap_mixer)
1d045db9 4920 set_capture_mixer(codec);
3e6179b8
TI
4921
4922 if (!spec->no_analog && has_cdefine_beep(codec)) {
4923 err = snd_hda_attach_beep_device(codec, 0x1);
4924 if (err < 0) {
4925 alc_free(codec);
4926 return err;
4927 }
1d045db9 4928 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
3e6179b8 4929 }
f1d4e28b 4930
1d045db9 4931 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
622e84cd 4932
1d045db9 4933 spec->vmaster_nid = 0x02;
622e84cd 4934
1d045db9 4935 codec->patch_ops = alc_patch_ops;
2a43952a 4936#ifdef CONFIG_PM
1d045db9
TI
4937 codec->patch_ops.resume = alc269_resume;
4938#endif
4939 if (board_config == ALC_MODEL_AUTO)
be9bc37b 4940 spec->init_hook = alc_auto_init_std;
1d045db9 4941 spec->shutup = alc269_shutup;
ebb83eeb 4942
1d045db9
TI
4943 alc_init_jacks(codec);
4944#ifdef CONFIG_SND_HDA_POWER_SAVE
4945 if (!spec->loopback.amplist)
4946 spec->loopback.amplist = alc269_loopbacks;
4947 if (alc269_mic2_for_mute_led(codec))
4948 codec->patch_ops.check_power_status = alc269_mic2_mute_check_ps;
4949#endif
ebb83eeb 4950
1d045db9
TI
4951 return 0;
4952}
f1d4e28b 4953
1d045db9
TI
4954/*
4955 * ALC861
4956 */
622e84cd 4957
1d045db9 4958static int alc861_parse_auto_config(struct hda_codec *codec)
6dda9f4a 4959{
1d045db9 4960 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
3e6179b8
TI
4961 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
4962 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
604401a9
TI
4963}
4964
1d045db9
TI
4965#ifdef CONFIG_SND_HDA_POWER_SAVE
4966static const struct hda_amp_list alc861_loopbacks[] = {
4967 { 0x15, HDA_INPUT, 0 },
4968 { 0x15, HDA_INPUT, 1 },
4969 { 0x15, HDA_INPUT, 2 },
4970 { 0x15, HDA_INPUT, 3 },
4971 { } /* end */
4972};
4973#endif
ce764ab2 4974
ce764ab2 4975
1d045db9
TI
4976/* Pin config fixes */
4977enum {
4978 PINFIX_FSC_AMILO_PI1505,
4979};
7085ec12 4980
1d045db9
TI
4981static const struct alc_fixup alc861_fixups[] = {
4982 [PINFIX_FSC_AMILO_PI1505] = {
4983 .type = ALC_FIXUP_PINS,
4984 .v.pins = (const struct alc_pincfg[]) {
4985 { 0x0b, 0x0221101f }, /* HP */
4986 { 0x0f, 0x90170310 }, /* speaker */
4987 { }
4988 }
4989 },
4990};
7085ec12 4991
1d045db9
TI
4992static const struct snd_pci_quirk alc861_fixup_tbl[] = {
4993 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", PINFIX_FSC_AMILO_PI1505),
4994 {}
4995};
3af9ee6b 4996
1d045db9
TI
4997/*
4998 */
1d045db9 4999static int patch_alc861(struct hda_codec *codec)
7085ec12 5000{
1d045db9 5001 struct alc_spec *spec;
1d045db9 5002 int err;
7085ec12 5003
1d045db9
TI
5004 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5005 if (spec == NULL)
5006 return -ENOMEM;
3af9ee6b 5007
1d045db9
TI
5008 codec->spec = spec;
5009
5010 spec->mixer_nid = 0x15;
5011
cb4e4824
TI
5012 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
5013 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
3af9ee6b 5014
cb4e4824
TI
5015 /* automatic parse from the BIOS config */
5016 err = alc861_parse_auto_config(codec);
5017 if (err < 0) {
5018 alc_free(codec);
5019 return err;
3af9ee6b
TI
5020 }
5021
60a6a842 5022 if (!spec->no_analog && !spec->adc_nids) {
1d045db9
TI
5023 alc_auto_fill_adc_caps(codec);
5024 alc_rebuild_imux_for_auto_mic(codec);
5025 alc_remove_invalid_adc_nids(codec);
5026 }
7085ec12 5027
3e6179b8 5028 if (!spec->no_analog && !spec->cap_mixer)
1d045db9 5029 set_capture_mixer(codec);
3e6179b8
TI
5030
5031 if (!spec->no_analog) {
5032 err = snd_hda_attach_beep_device(codec, 0x23);
5033 if (err < 0) {
5034 alc_free(codec);
5035 return err;
5036 }
5037 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
5038 }
7085ec12 5039
1d045db9 5040 spec->vmaster_nid = 0x03;
97aaab7b 5041
1d045db9
TI
5042 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5043
5044 codec->patch_ops = alc_patch_ops;
cb4e4824 5045 spec->init_hook = alc_auto_init_std;
1d045db9 5046#ifdef CONFIG_SND_HDA_POWER_SAVE
cb4e4824 5047 spec->power_hook = alc_power_eapd;
1d045db9
TI
5048 if (!spec->loopback.amplist)
5049 spec->loopback.amplist = alc861_loopbacks;
5050#endif
5051
5052 return 0;
7085ec12
TI
5053}
5054
1d045db9
TI
5055/*
5056 * ALC861-VD support
5057 *
5058 * Based on ALC882
5059 *
5060 * In addition, an independent DAC
5061 */
5062#ifdef CONFIG_SND_HDA_POWER_SAVE
5063#define alc861vd_loopbacks alc880_loopbacks
5064#endif
5065
1d045db9 5066static int alc861vd_parse_auto_config(struct hda_codec *codec)
bc9f98a9 5067{
1d045db9 5068 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
3e6179b8
TI
5069 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5070 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
ce764ab2
TI
5071}
5072
1d045db9 5073enum {
8fdcb6fe
TI
5074 ALC660VD_FIX_ASUS_GPIO1,
5075 ALC861VD_FIX_DALLAS,
1d045db9 5076};
ce764ab2 5077
8fdcb6fe
TI
5078/* exclude VREF80 */
5079static void alc861vd_fixup_dallas(struct hda_codec *codec,
5080 const struct alc_fixup *fix, int action)
5081{
5082 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
5083 snd_hda_override_pin_caps(codec, 0x18, 0x00001714);
5084 snd_hda_override_pin_caps(codec, 0x19, 0x0000171c);
5085 }
5086}
5087
1d045db9
TI
5088static const struct alc_fixup alc861vd_fixups[] = {
5089 [ALC660VD_FIX_ASUS_GPIO1] = {
5090 .type = ALC_FIXUP_VERBS,
5091 .v.verbs = (const struct hda_verb[]) {
8fdcb6fe 5092 /* reset GPIO1 */
1d045db9
TI
5093 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
5094 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5095 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5096 { }
5097 }
5098 },
8fdcb6fe
TI
5099 [ALC861VD_FIX_DALLAS] = {
5100 .type = ALC_FIXUP_FUNC,
5101 .v.func = alc861vd_fixup_dallas,
5102 },
1d045db9 5103};
ce764ab2 5104
1d045db9 5105static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
8fdcb6fe 5106 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
1d045db9 5107 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
8fdcb6fe 5108 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
1d045db9
TI
5109 {}
5110};
ce764ab2 5111
1d045db9
TI
5112static const struct hda_verb alc660vd_eapd_verbs[] = {
5113 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
5114 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
5115 { }
ce764ab2
TI
5116};
5117
1d045db9
TI
5118/*
5119 */
1d045db9 5120static int patch_alc861vd(struct hda_codec *codec)
ce764ab2 5121{
1d045db9 5122 struct alc_spec *spec;
cb4e4824 5123 int err;
ce764ab2 5124
1d045db9
TI
5125 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5126 if (spec == NULL)
5127 return -ENOMEM;
5128
5129 codec->spec = spec;
5130
5131 spec->mixer_nid = 0x0b;
5132
cb4e4824
TI
5133 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
5134 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
1d045db9 5135
cb4e4824
TI
5136 /* automatic parse from the BIOS config */
5137 err = alc861vd_parse_auto_config(codec);
5138 if (err < 0) {
5139 alc_free(codec);
5140 return err;
1d045db9 5141 }
ce764ab2 5142
1d045db9
TI
5143 if (codec->vendor_id == 0x10ec0660) {
5144 /* always turn on EAPD */
5145 add_verb(spec, alc660vd_eapd_verbs);
5146 }
5147
60a6a842 5148 if (!spec->no_analog && !spec->adc_nids) {
1d045db9
TI
5149 alc_auto_fill_adc_caps(codec);
5150 alc_rebuild_imux_for_auto_mic(codec);
5151 alc_remove_invalid_adc_nids(codec);
ce764ab2 5152 }
1d045db9 5153
3e6179b8
TI
5154 if (!spec->no_analog && !spec->cap_mixer)
5155 set_capture_mixer(codec);
5156
5157 if (!spec->no_analog) {
5158 err = snd_hda_attach_beep_device(codec, 0x23);
5159 if (err < 0) {
5160 alc_free(codec);
5161 return err;
5162 }
5163 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5164 }
1d045db9
TI
5165
5166 spec->vmaster_nid = 0x02;
5167
5168 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5169
5170 codec->patch_ops = alc_patch_ops;
5171
cb4e4824 5172 spec->init_hook = alc_auto_init_std;
1d045db9
TI
5173 spec->shutup = alc_eapd_shutup;
5174#ifdef CONFIG_SND_HDA_POWER_SAVE
5175 if (!spec->loopback.amplist)
5176 spec->loopback.amplist = alc861vd_loopbacks;
5177#endif
5178
ce764ab2
TI
5179 return 0;
5180}
5181
1d045db9
TI
5182/*
5183 * ALC662 support
5184 *
5185 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
5186 * configuration. Each pin widget can choose any input DACs and a mixer.
5187 * Each ADC is connected from a mixer of all inputs. This makes possible
5188 * 6-channel independent captures.
5189 *
5190 * In addition, an independent DAC for the multi-playback (not used in this
5191 * driver yet).
5192 */
5193#ifdef CONFIG_SND_HDA_POWER_SAVE
5194#define alc662_loopbacks alc880_loopbacks
5195#endif
5196
5197/*
5198 * BIOS auto configuration
5199 */
5200
bc9f98a9
KY
5201static int alc662_parse_auto_config(struct hda_codec *codec)
5202{
4c6d72d1 5203 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
3e6179b8
TI
5204 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
5205 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5206 const hda_nid_t *ssids;
ee979a14 5207
6227cdce
KY
5208 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
5209 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
3e6179b8 5210 ssids = alc663_ssids;
6227cdce 5211 else
3e6179b8
TI
5212 ssids = alc662_ssids;
5213 return alc_parse_auto_config(codec, alc662_ignore, ssids);
bc9f98a9
KY
5214}
5215
6be7948f 5216static void alc272_fixup_mario(struct hda_codec *codec,
b5bfbc67 5217 const struct alc_fixup *fix, int action)
6fc398cb 5218{
b5bfbc67 5219 if (action != ALC_FIXUP_ACT_PROBE)
6fc398cb 5220 return;
6be7948f
TB
5221 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
5222 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
5223 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
5224 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5225 (0 << AC_AMPCAP_MUTE_SHIFT)))
5226 printk(KERN_WARNING
5227 "hda_codec: failed to override amp caps for NID 0x2\n");
5228}
5229
6cb3b707 5230enum {
2df03514 5231 ALC662_FIXUP_ASPIRE,
6cb3b707 5232 ALC662_FIXUP_IDEAPAD,
6be7948f 5233 ALC272_FIXUP_MARIO,
d2ebd479 5234 ALC662_FIXUP_CZC_P10T,
94024cd1 5235 ALC662_FIXUP_SKU_IGNORE,
e59ea3ed 5236 ALC662_FIXUP_HP_RP5800,
53c334ad
TI
5237 ALC662_FIXUP_ASUS_MODE1,
5238 ALC662_FIXUP_ASUS_MODE2,
5239 ALC662_FIXUP_ASUS_MODE3,
5240 ALC662_FIXUP_ASUS_MODE4,
5241 ALC662_FIXUP_ASUS_MODE5,
5242 ALC662_FIXUP_ASUS_MODE6,
5243 ALC662_FIXUP_ASUS_MODE7,
5244 ALC662_FIXUP_ASUS_MODE8,
6cb3b707
DH
5245};
5246
5247static const struct alc_fixup alc662_fixups[] = {
2df03514 5248 [ALC662_FIXUP_ASPIRE] = {
b5bfbc67
TI
5249 .type = ALC_FIXUP_PINS,
5250 .v.pins = (const struct alc_pincfg[]) {
2df03514
DC
5251 { 0x15, 0x99130112 }, /* subwoofer */
5252 { }
5253 }
5254 },
6cb3b707 5255 [ALC662_FIXUP_IDEAPAD] = {
b5bfbc67
TI
5256 .type = ALC_FIXUP_PINS,
5257 .v.pins = (const struct alc_pincfg[]) {
6cb3b707
DH
5258 { 0x17, 0x99130112 }, /* subwoofer */
5259 { }
5260 }
5261 },
6be7948f 5262 [ALC272_FIXUP_MARIO] = {
b5bfbc67
TI
5263 .type = ALC_FIXUP_FUNC,
5264 .v.func = alc272_fixup_mario,
d2ebd479
AA
5265 },
5266 [ALC662_FIXUP_CZC_P10T] = {
5267 .type = ALC_FIXUP_VERBS,
5268 .v.verbs = (const struct hda_verb[]) {
5269 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
5270 {}
5271 }
5272 },
94024cd1
DH
5273 [ALC662_FIXUP_SKU_IGNORE] = {
5274 .type = ALC_FIXUP_SKU,
5275 .v.sku = ALC_FIXUP_SKU_IGNORE,
c6b35874 5276 },
e59ea3ed
TI
5277 [ALC662_FIXUP_HP_RP5800] = {
5278 .type = ALC_FIXUP_PINS,
5279 .v.pins = (const struct alc_pincfg[]) {
5280 { 0x14, 0x0221201f }, /* HP out */
5281 { }
5282 },
5283 .chained = true,
5284 .chain_id = ALC662_FIXUP_SKU_IGNORE
5285 },
53c334ad
TI
5286 [ALC662_FIXUP_ASUS_MODE1] = {
5287 .type = ALC_FIXUP_PINS,
5288 .v.pins = (const struct alc_pincfg[]) {
5289 { 0x14, 0x99130110 }, /* speaker */
5290 { 0x18, 0x01a19c20 }, /* mic */
5291 { 0x19, 0x99a3092f }, /* int-mic */
5292 { 0x21, 0x0121401f }, /* HP out */
5293 { }
5294 },
5295 .chained = true,
5296 .chain_id = ALC662_FIXUP_SKU_IGNORE
5297 },
5298 [ALC662_FIXUP_ASUS_MODE2] = {
2996bdba
TI
5299 .type = ALC_FIXUP_PINS,
5300 .v.pins = (const struct alc_pincfg[]) {
5301 { 0x14, 0x99130110 }, /* speaker */
5302 { 0x18, 0x01a19820 }, /* mic */
5303 { 0x19, 0x99a3092f }, /* int-mic */
5304 { 0x1b, 0x0121401f }, /* HP out */
5305 { }
5306 },
53c334ad
TI
5307 .chained = true,
5308 .chain_id = ALC662_FIXUP_SKU_IGNORE
5309 },
5310 [ALC662_FIXUP_ASUS_MODE3] = {
5311 .type = ALC_FIXUP_PINS,
5312 .v.pins = (const struct alc_pincfg[]) {
5313 { 0x14, 0x99130110 }, /* speaker */
5314 { 0x15, 0x0121441f }, /* HP */
5315 { 0x18, 0x01a19840 }, /* mic */
5316 { 0x19, 0x99a3094f }, /* int-mic */
5317 { 0x21, 0x01211420 }, /* HP2 */
5318 { }
5319 },
5320 .chained = true,
5321 .chain_id = ALC662_FIXUP_SKU_IGNORE
5322 },
5323 [ALC662_FIXUP_ASUS_MODE4] = {
5324 .type = ALC_FIXUP_PINS,
5325 .v.pins = (const struct alc_pincfg[]) {
5326 { 0x14, 0x99130110 }, /* speaker */
5327 { 0x16, 0x99130111 }, /* speaker */
5328 { 0x18, 0x01a19840 }, /* mic */
5329 { 0x19, 0x99a3094f }, /* int-mic */
5330 { 0x21, 0x0121441f }, /* HP */
5331 { }
5332 },
5333 .chained = true,
5334 .chain_id = ALC662_FIXUP_SKU_IGNORE
5335 },
5336 [ALC662_FIXUP_ASUS_MODE5] = {
5337 .type = ALC_FIXUP_PINS,
5338 .v.pins = (const struct alc_pincfg[]) {
5339 { 0x14, 0x99130110 }, /* speaker */
5340 { 0x15, 0x0121441f }, /* HP */
5341 { 0x16, 0x99130111 }, /* speaker */
5342 { 0x18, 0x01a19840 }, /* mic */
5343 { 0x19, 0x99a3094f }, /* int-mic */
5344 { }
5345 },
5346 .chained = true,
5347 .chain_id = ALC662_FIXUP_SKU_IGNORE
5348 },
5349 [ALC662_FIXUP_ASUS_MODE6] = {
5350 .type = ALC_FIXUP_PINS,
5351 .v.pins = (const struct alc_pincfg[]) {
5352 { 0x14, 0x99130110 }, /* speaker */
5353 { 0x15, 0x01211420 }, /* HP2 */
5354 { 0x18, 0x01a19840 }, /* mic */
5355 { 0x19, 0x99a3094f }, /* int-mic */
5356 { 0x1b, 0x0121441f }, /* HP */
5357 { }
5358 },
5359 .chained = true,
5360 .chain_id = ALC662_FIXUP_SKU_IGNORE
5361 },
5362 [ALC662_FIXUP_ASUS_MODE7] = {
5363 .type = ALC_FIXUP_PINS,
5364 .v.pins = (const struct alc_pincfg[]) {
5365 { 0x14, 0x99130110 }, /* speaker */
5366 { 0x17, 0x99130111 }, /* speaker */
5367 { 0x18, 0x01a19840 }, /* mic */
5368 { 0x19, 0x99a3094f }, /* int-mic */
5369 { 0x1b, 0x01214020 }, /* HP */
5370 { 0x21, 0x0121401f }, /* HP */
5371 { }
5372 },
5373 .chained = true,
5374 .chain_id = ALC662_FIXUP_SKU_IGNORE
5375 },
5376 [ALC662_FIXUP_ASUS_MODE8] = {
5377 .type = ALC_FIXUP_PINS,
5378 .v.pins = (const struct alc_pincfg[]) {
5379 { 0x14, 0x99130110 }, /* speaker */
5380 { 0x12, 0x99a30970 }, /* int-mic */
5381 { 0x15, 0x01214020 }, /* HP */
5382 { 0x17, 0x99130111 }, /* speaker */
5383 { 0x18, 0x01a19840 }, /* mic */
5384 { 0x21, 0x0121401f }, /* HP */
5385 { }
5386 },
5387 .chained = true,
5388 .chain_id = ALC662_FIXUP_SKU_IGNORE
2996bdba 5389 },
6cb3b707
DH
5390};
5391
a9111321 5392static const struct snd_pci_quirk alc662_fixup_tbl[] = {
53c334ad 5393 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
a6c47a85 5394 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
94024cd1 5395 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
2df03514 5396 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
e59ea3ed 5397 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
53c334ad 5398 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
a0e90acc 5399 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
d4118588 5400 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
6cb3b707 5401 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
d2ebd479 5402 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
53c334ad
TI
5403
5404#if 0
5405 /* Below is a quirk table taken from the old code.
5406 * Basically the device should work as is without the fixup table.
5407 * If BIOS doesn't give a proper info, enable the corresponding
5408 * fixup entry.
5409 */
5410 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
5411 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
5412 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
5413 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
5414 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
5415 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5416 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
5417 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
5418 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
5419 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5420 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
5421 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
5422 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
5423 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
5424 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
5425 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5426 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
5427 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
5428 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5429 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
5430 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
5431 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5432 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
5433 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
5434 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
5435 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5436 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
5437 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
5438 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5439 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
5440 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5441 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5442 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
5443 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
5444 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
5445 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
5446 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
5447 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
5448 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
5449 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5450 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
5451 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
5452 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
5453 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
5454 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
5455 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
5456 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
5457 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
5458 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
5459 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
5460#endif
6cb3b707
DH
5461 {}
5462};
5463
6be7948f
TB
5464static const struct alc_model_fixup alc662_fixup_models[] = {
5465 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
53c334ad
TI
5466 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
5467 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
5468 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
5469 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
5470 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
5471 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
5472 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
5473 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
6be7948f
TB
5474 {}
5475};
6cb3b707
DH
5476
5477
1d045db9
TI
5478/*
5479 */
5480#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
5481#include "alc662_quirks.c"
5482#endif
5483
bc9f98a9
KY
5484static int patch_alc662(struct hda_codec *codec)
5485{
5486 struct alc_spec *spec;
5487 int err, board_config;
693194f3 5488 int coef;
bc9f98a9
KY
5489
5490 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5491 if (!spec)
5492 return -ENOMEM;
5493
5494 codec->spec = spec;
5495
1f0f4b80
TI
5496 spec->mixer_nid = 0x0b;
5497
53c334ad
TI
5498 /* handle multiple HPs as is */
5499 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
5500
da00c244
KY
5501 alc_auto_parse_customize_define(codec);
5502
2c3bf9ab
TI
5503 alc_fix_pll_init(codec, 0x20, 0x04, 15);
5504
693194f3
KY
5505 coef = alc_read_coef_idx(codec, 0);
5506 if (coef == 0x8020 || coef == 0x8011)
c027ddcd 5507 alc_codec_rename(codec, "ALC661");
693194f3
KY
5508 else if (coef & (1 << 14) &&
5509 codec->bus->pci->subsystem_vendor == 0x1025 &&
5510 spec->cdefine.platform_type == 1)
c027ddcd 5511 alc_codec_rename(codec, "ALC272X");
693194f3
KY
5512 else if (coef == 0x4011)
5513 alc_codec_rename(codec, "ALC656");
274693f3 5514
1d045db9
TI
5515 board_config = alc_board_config(codec, ALC662_MODEL_LAST,
5516 alc662_models, alc662_cfg_tbl);
bc9f98a9 5517 if (board_config < 0) {
9a11f1aa
TI
5518 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5519 codec->chip_name);
1d045db9 5520 board_config = ALC_MODEL_AUTO;
bc9f98a9
KY
5521 }
5522
1d045db9 5523 if (board_config == ALC_MODEL_AUTO) {
b5bfbc67
TI
5524 alc_pick_fixup(codec, alc662_fixup_models,
5525 alc662_fixup_tbl, alc662_fixups);
5526 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
bc9f98a9
KY
5527 /* automatic parse from the BIOS config */
5528 err = alc662_parse_auto_config(codec);
5529 if (err < 0) {
5530 alc_free(codec);
5531 return err;
1d045db9
TI
5532 }
5533#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
5534 else if (!err) {
bc9f98a9
KY
5535 printk(KERN_INFO
5536 "hda_codec: Cannot set up configuration "
5537 "from BIOS. Using base mode...\n");
5538 board_config = ALC662_3ST_2ch_DIG;
5539 }
1d045db9 5540#endif
bc9f98a9
KY
5541 }
5542
1d045db9 5543 if (board_config != ALC_MODEL_AUTO)
e9c364c0 5544 setup_preset(codec, &alc662_presets[board_config]);
bc9f98a9 5545
60a6a842 5546 if (!spec->no_analog && !spec->adc_nids) {
d6cc9fab 5547 alc_auto_fill_adc_caps(codec);
21268961 5548 alc_rebuild_imux_for_auto_mic(codec);
d6cc9fab 5549 alc_remove_invalid_adc_nids(codec);
dd704698 5550 }
bc9f98a9 5551
3e6179b8 5552 if (!spec->no_analog && !spec->cap_mixer)
b59bdf3b 5553 set_capture_mixer(codec);
cec27c89 5554
3e6179b8
TI
5555 if (!spec->no_analog && has_cdefine_beep(codec)) {
5556 err = snd_hda_attach_beep_device(codec, 0x1);
5557 if (err < 0) {
5558 alc_free(codec);
5559 return err;
5560 }
da00c244
KY
5561 switch (codec->vendor_id) {
5562 case 0x10ec0662:
5563 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5564 break;
5565 case 0x10ec0272:
5566 case 0x10ec0663:
5567 case 0x10ec0665:
5568 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
5569 break;
5570 case 0x10ec0273:
5571 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
5572 break;
5573 }
cec27c89 5574 }
2134ea4f
TI
5575 spec->vmaster_nid = 0x02;
5576
b5bfbc67
TI
5577 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5578
bc9f98a9 5579 codec->patch_ops = alc_patch_ops;
1d045db9 5580 if (board_config == ALC_MODEL_AUTO)
e4770629 5581 spec->init_hook = alc_auto_init_std;
1c716153 5582 spec->shutup = alc_eapd_shutup;
6cb3b707 5583
bf1b0225
KY
5584 alc_init_jacks(codec);
5585
cb53c626
TI
5586#ifdef CONFIG_SND_HDA_POWER_SAVE
5587 if (!spec->loopback.amplist)
5588 spec->loopback.amplist = alc662_loopbacks;
5589#endif
bc9f98a9
KY
5590
5591 return 0;
5592}
5593
274693f3
KY
5594static int patch_alc888(struct hda_codec *codec)
5595{
5596 if ((alc_read_coef_idx(codec, 0) & 0x00f0)==0x0030){
5597 kfree(codec->chip_name);
01e0f137
KY
5598 if (codec->vendor_id == 0x10ec0887)
5599 codec->chip_name = kstrdup("ALC887-VD", GFP_KERNEL);
5600 else
5601 codec->chip_name = kstrdup("ALC888-VD", GFP_KERNEL);
ac2c92e0
TI
5602 if (!codec->chip_name) {
5603 alc_free(codec);
274693f3 5604 return -ENOMEM;
ac2c92e0
TI
5605 }
5606 return patch_alc662(codec);
274693f3 5607 }
ac2c92e0 5608 return patch_alc882(codec);
274693f3
KY
5609}
5610
b478b998
KY
5611static int patch_alc899(struct hda_codec *codec)
5612{
5613 if ((alc_read_coef_idx(codec, 0) & 0x2000) != 0x2000) {
5614 kfree(codec->chip_name);
5615 codec->chip_name = kstrdup("ALC898", GFP_KERNEL);
5616 }
5617 return patch_alc882(codec);
5618}
5619
d1eb57f4
KY
5620/*
5621 * ALC680 support
5622 */
d1eb57f4 5623
d1eb57f4
KY
5624static int alc680_parse_auto_config(struct hda_codec *codec)
5625{
3e6179b8 5626 return alc_parse_auto_config(codec, NULL, NULL);
d1eb57f4
KY
5627}
5628
d1eb57f4 5629/*
d1eb57f4 5630 */
d1eb57f4
KY
5631static int patch_alc680(struct hda_codec *codec)
5632{
5633 struct alc_spec *spec;
d1eb57f4
KY
5634 int err;
5635
5636 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5637 if (spec == NULL)
5638 return -ENOMEM;
5639
5640 codec->spec = spec;
5641
1f0f4b80
TI
5642 /* ALC680 has no aa-loopback mixer */
5643
1ebec5f2
TI
5644 /* automatic parse from the BIOS config */
5645 err = alc680_parse_auto_config(codec);
5646 if (err < 0) {
5647 alc_free(codec);
5648 return err;
d1eb57f4
KY
5649 }
5650
3e6179b8 5651 if (!spec->no_analog && !spec->cap_mixer)
d1eb57f4
KY
5652 set_capture_mixer(codec);
5653
5654 spec->vmaster_nid = 0x02;
5655
5656 codec->patch_ops = alc_patch_ops;
1ebec5f2 5657 spec->init_hook = alc_auto_init_std;
d1eb57f4
KY
5658
5659 return 0;
5660}
5661
1da177e4
LT
5662/*
5663 * patch entries
5664 */
a9111321 5665static const struct hda_codec_preset snd_hda_preset_realtek[] = {
296f0338 5666 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
1da177e4 5667 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
df694daa 5668 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
f6a92248 5669 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
a361d84b 5670 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
f6a92248 5671 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
ebb83eeb 5672 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
01afd41f 5673 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
ebb83eeb 5674 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
296f0338 5675 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
f32610ed 5676 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
bc9f98a9 5677 .patch = patch_alc861 },
f32610ed
JS
5678 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
5679 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
5680 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
bc9f98a9 5681 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
4953550a 5682 .patch = patch_alc882 },
bc9f98a9
KY
5683 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
5684 .patch = patch_alc662 },
6dda9f4a 5685 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
cec27c89 5686 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
6227cdce 5687 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
d1eb57f4 5688 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
f32610ed 5689 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
1da177e4 5690 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
4953550a 5691 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
669faba2 5692 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
4953550a 5693 .patch = patch_alc882 },
cb308f97 5694 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
4953550a 5695 .patch = patch_alc882 },
df694daa 5696 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
01e0f137 5697 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc888 },
4442608d 5698 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
4953550a 5699 .patch = patch_alc882 },
274693f3 5700 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc888 },
4953550a 5701 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
274693f3 5702 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
b478b998 5703 { .id = 0x10ec0899, .name = "ALC899", .patch = patch_alc899 },
1da177e4
LT
5704 {} /* terminator */
5705};
1289e9e8
TI
5706
5707MODULE_ALIAS("snd-hda-codec-id:10ec*");
5708
5709MODULE_LICENSE("GPL");
5710MODULE_DESCRIPTION("Realtek HD-audio codec");
5711
5712static struct hda_codec_preset_list realtek_list = {
5713 .preset = snd_hda_preset_realtek,
5714 .owner = THIS_MODULE,
5715};
5716
5717static int __init patch_realtek_init(void)
5718{
5719 return snd_hda_add_codec_preset(&realtek_list);
5720}
5721
5722static void __exit patch_realtek_exit(void)
5723{
5724 snd_hda_delete_codec_preset(&realtek_list);
5725}
5726
5727module_init(patch_realtek_init)
5728module_exit(patch_realtek_exit)