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