1 /*
2 * Universal Interface for Intel High Definition Audio Codec
3 *
4 * HD audio interface patch for ALC 260/880/882 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 <sound/driver.h>
27 #include <linux/init.h>
28 #include <linux/delay.h>
29 #include <linux/slab.h>
30 #include <linux/pci.h>
31 #include <sound/core.h>
32 #include "hda_codec.h"
33 #include "hda_local.h"
34 #include "hda_patch.h"
35
36 #define ALC880_FRONT_EVENT 0x01
37 #define ALC880_DCVOL_EVENT 0x02
38 #define ALC880_HP_EVENT 0x04
39 #define ALC880_MIC_EVENT 0x08
40
41 /* ALC880 board config type */
42 enum {
43 ALC880_3ST,
44 ALC880_3ST_DIG,
45 ALC880_5ST,
46 ALC880_5ST_DIG,
47 ALC880_W810,
48 ALC880_Z71V,
49 ALC880_6ST,
50 ALC880_6ST_DIG,
51 ALC880_F1734,
52 ALC880_ASUS,
53 ALC880_ASUS_DIG,
54 ALC880_ASUS_W1V,
55 ALC880_ASUS_DIG2,
56 ALC880_FUJITSU,
57 ALC880_UNIWILL_DIG,
58 ALC880_UNIWILL,
59 ALC880_UNIWILL_P53,
60 ALC880_CLEVO,
61 ALC880_TCL_S700,
62 ALC880_LG,
63 ALC880_LG_LW,
64 ALC880_MEDION_RIM,
65 #ifdef CONFIG_SND_DEBUG
66 ALC880_TEST,
67 #endif
68 ALC880_AUTO,
69 ALC880_MODEL_LAST /* last tag */
70 };
71
72 /* ALC260 models */
73 enum {
74 ALC260_BASIC,
75 ALC260_HP,
76 ALC260_HP_3013,
77 ALC260_FUJITSU_S702X,
78 ALC260_ACER,
79 ALC260_WILL,
80 ALC260_REPLACER_672V,
81 #ifdef CONFIG_SND_DEBUG
82 ALC260_TEST,
83 #endif
84 ALC260_AUTO,
85 ALC260_MODEL_LAST /* last tag */
86 };
87
88 /* ALC262 models */
89 enum {
90 ALC262_BASIC,
91 ALC262_HIPPO,
92 ALC262_HIPPO_1,
93 ALC262_FUJITSU,
94 ALC262_HP_BPC,
95 ALC262_HP_BPC_D7000_WL,
96 ALC262_HP_BPC_D7000_WF,
97 ALC262_HP_TC_T5735,
98 ALC262_HP_RP5700,
99 ALC262_BENQ_ED8,
100 ALC262_SONY_ASSAMD,
101 ALC262_BENQ_T31,
102 ALC262_ULTRA,
103 ALC262_LENOVO_3000,
104 ALC262_AUTO,
105 ALC262_MODEL_LAST /* last tag */
106 };
107
108 /* ALC268 models */
109 enum {
110 ALC267_QUANTA_IL1,
111 ALC268_3ST,
112 ALC268_TOSHIBA,
113 ALC268_ACER,
114 ALC268_DELL,
115 ALC268_ZEPTO,
116 #ifdef CONFIG_SND_DEBUG
117 ALC268_TEST,
118 #endif
119 ALC268_AUTO,
120 ALC268_MODEL_LAST /* last tag */
121 };
122
123 /* ALC269 models */
124 enum {
125 ALC269_BASIC,
126 ALC269_ASUS_EEEPC_P703,
127 ALC269_ASUS_EEEPC_P901,
128 ALC269_AUTO,
129 ALC269_MODEL_LAST /* last tag */
130 };
131
132 /* ALC861 models */
133 enum {
134 ALC861_3ST,
135 ALC660_3ST,
136 ALC861_3ST_DIG,
137 ALC861_6ST_DIG,
138 ALC861_UNIWILL_M31,
139 ALC861_TOSHIBA,
140 ALC861_ASUS,
141 ALC861_ASUS_LAPTOP,
142 ALC861_AUTO,
143 ALC861_MODEL_LAST,
144 };
145
146 /* ALC861-VD models */
147 enum {
148 ALC660VD_3ST,
149 ALC660VD_3ST_DIG,
150 ALC861VD_3ST,
151 ALC861VD_3ST_DIG,
152 ALC861VD_6ST_DIG,
153 ALC861VD_LENOVO,
154 ALC861VD_DALLAS,
155 ALC861VD_HP,
156 ALC861VD_AUTO,
157 ALC861VD_MODEL_LAST,
158 };
159
160 /* ALC662 models */
161 enum {
162 ALC662_3ST_2ch_DIG,
163 ALC662_3ST_6ch_DIG,
164 ALC662_3ST_6ch,
165 ALC662_5ST_DIG,
166 ALC662_LENOVO_101E,
167 ALC662_ASUS_EEEPC_P701,
168 ALC662_ASUS_EEEPC_EP20,
169 ALC663_ASUS_M51VA,
170 ALC663_ASUS_G71V,
171 ALC663_ASUS_H13,
172 ALC663_ASUS_G50V,
173 ALC662_AUTO,
174 ALC662_MODEL_LAST,
175 };
176
177 /* ALC882 models */
178 enum {
179 ALC882_3ST_DIG,
180 ALC882_6ST_DIG,
181 ALC882_ARIMA,
182 ALC882_W2JC,
183 ALC882_TARGA,
184 ALC882_ASUS_A7J,
185 ALC882_ASUS_A7M,
186 ALC885_MACPRO,
187 ALC885_MBP3,
188 ALC885_IMAC24,
189 ALC882_AUTO,
190 ALC882_MODEL_LAST,
191 };
192
193 /* ALC883 models */
194 enum {
195 ALC883_3ST_2ch_DIG,
196 ALC883_3ST_6ch_DIG,
197 ALC883_3ST_6ch,
198 ALC883_6ST_DIG,
199 ALC883_TARGA_DIG,
200 ALC883_TARGA_2ch_DIG,
201 ALC883_ACER,
202 ALC883_ACER_ASPIRE,
203 ALC883_MEDION,
204 ALC883_MEDION_MD2,
205 ALC883_LAPTOP_EAPD,
206 ALC883_LENOVO_101E_2ch,
207 ALC883_LENOVO_NB0763,
208 ALC888_LENOVO_MS7195_DIG,
209 ALC883_HAIER_W66,
210 ALC888_3ST_HP,
211 ALC888_6ST_DELL,
212 ALC883_MITAC,
213 ALC883_CLEVO_M720,
214 ALC883_FUJITSU_PI2515,
215 ALC883_3ST_6ch_INTEL,
216 ALC883_AUTO,
217 ALC883_MODEL_LAST,
218 };
219
220 /* for GPIO Poll */
221 #define GPIO_MASK 0x03
222
223 struct alc_spec {
224 /* codec parameterization */
225 struct snd_kcontrol_new *mixers[5]; /* mixer arrays */
226 unsigned int num_mixers;
227
228 const struct hda_verb *init_verbs[5]; /* initialization verbs
229 * don't forget NULL
230 * termination!
231 */
232 unsigned int num_init_verbs;
233
234 char *stream_name_analog; /* analog PCM stream */
235 struct hda_pcm_stream *stream_analog_playback;
236 struct hda_pcm_stream *stream_analog_capture;
237 struct hda_pcm_stream *stream_analog_alt_playback;
238 struct hda_pcm_stream *stream_analog_alt_capture;
239
240 char *stream_name_digital; /* digital PCM stream */
241 struct hda_pcm_stream *stream_digital_playback;
242 struct hda_pcm_stream *stream_digital_capture;
243
244 /* playback */
245 struct hda_multi_out multiout; /* playback set-up
246 * max_channels, dacs must be set
247 * dig_out_nid and hp_nid are optional
248 */
249 hda_nid_t alt_dac_nid;
250
251 /* capture */
252 unsigned int num_adc_nids;
253 hda_nid_t *adc_nids;
254 hda_nid_t *capsrc_nids;
255 hda_nid_t dig_in_nid; /* digital-in NID; optional */
256
257 /* capture source */
258 unsigned int num_mux_defs;
259 const struct hda_input_mux *input_mux;
260 unsigned int cur_mux[3];
261
262 /* channel model */
263 const struct hda_channel_mode *channel_mode;
264 int num_channel_mode;
265 int need_dac_fix;
266
267 /* PCM information */
268 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
269
270 /* dynamic controls, init_verbs and input_mux */
271 struct auto_pin_cfg autocfg;
272 unsigned int num_kctl_alloc, num_kctl_used;
273 struct snd_kcontrol_new *kctl_alloc;
274 struct hda_input_mux private_imux;
275 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
276
277 /* hooks */
278 void (*init_hook)(struct hda_codec *codec);
279 void (*unsol_event)(struct hda_codec *codec, unsigned int res);
280
281 /* for pin sensing */
282 unsigned int sense_updated: 1;
283 unsigned int jack_present: 1;
284 unsigned int master_sw: 1;
285
286 /* for virtual master */
287 hda_nid_t vmaster_nid;
288 #ifdef CONFIG_SND_HDA_POWER_SAVE
289 struct hda_loopback_check loopback;
290 #endif
291
292 /* for PLL fix */
293 hda_nid_t pll_nid;
294 unsigned int pll_coef_idx, pll_coef_bit;
295 };
296
297 /*
298 * configuration template - to be copied to the spec instance
299 */
300 struct alc_config_preset {
301 struct snd_kcontrol_new *mixers[5]; /* should be identical size
302 * with spec
303 */
304 const struct hda_verb *init_verbs[5];
305 unsigned int num_dacs;
306 hda_nid_t *dac_nids;
307 hda_nid_t dig_out_nid; /* optional */
308 hda_nid_t hp_nid; /* optional */
309 unsigned int num_adc_nids;
310 hda_nid_t *adc_nids;
311 hda_nid_t *capsrc_nids;
312 hda_nid_t dig_in_nid;
313 unsigned int num_channel_mode;
314 const struct hda_channel_mode *channel_mode;
315 int need_dac_fix;
316 unsigned int num_mux_defs;
317 const struct hda_input_mux *input_mux;
318 void (*unsol_event)(struct hda_codec *, unsigned int);
319 void (*init_hook)(struct hda_codec *);
320 #ifdef CONFIG_SND_HDA_POWER_SAVE
321 struct hda_amp_list *loopbacks;
322 #endif
323 };
324
325
326 /*
327 * input MUX handling
328 */
329 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
330 struct snd_ctl_elem_info *uinfo)
331 {
332 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
333 struct alc_spec *spec = codec->spec;
334 unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
335 if (mux_idx >= spec->num_mux_defs)
336 mux_idx = 0;
337 return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
338 }
339
340 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
341 struct snd_ctl_elem_value *ucontrol)
342 {
343 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
344 struct alc_spec *spec = codec->spec;
345 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
346
347 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
348 return 0;
349 }
350
351 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
352 struct snd_ctl_elem_value *ucontrol)
353 {
354 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
355 struct alc_spec *spec = codec->spec;
356 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
357 unsigned int mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
358 hda_nid_t nid = spec->capsrc_nids ?
359 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
360 return snd_hda_input_mux_put(codec, &spec->input_mux[mux_idx], ucontrol,
361 nid, &spec->cur_mux[adc_idx]);
362 }
363
364
365 /*
366 * channel mode setting
367 */
368 static int alc_ch_mode_info(struct snd_kcontrol *kcontrol,
369 struct snd_ctl_elem_info *uinfo)
370 {
371 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
372 struct alc_spec *spec = codec->spec;
373 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
374 spec->num_channel_mode);
375 }
376
377 static int alc_ch_mode_get(struct snd_kcontrol *kcontrol,
378 struct snd_ctl_elem_value *ucontrol)
379 {
380 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
381 struct alc_spec *spec = codec->spec;
382 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
383 spec->num_channel_mode,
384 spec->multiout.max_channels);
385 }
386
387 static int alc_ch_mode_put(struct snd_kcontrol *kcontrol,
388 struct snd_ctl_elem_value *ucontrol)
389 {
390 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
391 struct alc_spec *spec = codec->spec;
392 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
393 spec->num_channel_mode,
394 &spec->multiout.max_channels);
395 if (err >= 0 && spec->need_dac_fix)
396 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
397 return err;
398 }
399
400 /*
401 * Control the mode of pin widget settings via the mixer. "pc" is used
402 * instead of "%" to avoid consequences of accidently treating the % as
403 * being part of a format specifier. Maximum allowed length of a value is
404 * 63 characters plus NULL terminator.
405 *
406 * Note: some retasking pin complexes seem to ignore requests for input
407 * states other than HiZ (eg: PIN_VREFxx) and revert to HiZ if any of these
408 * are requested. Therefore order this list so that this behaviour will not
409 * cause problems when mixer clients move through the enum sequentially.
410 * NIDs 0x0f and 0x10 have been observed to have this behaviour as of
411 * March 2006.
412 */
413 static char *alc_pin_mode_names[] = {
414 "Mic 50pc bias", "Mic 80pc bias",
415 "Line in", "Line out", "Headphone out",
416 };
417 static unsigned char alc_pin_mode_values[] = {
418 PIN_VREF50, PIN_VREF80, PIN_IN, PIN_OUT, PIN_HP,
419 };
420 /* The control can present all 5 options, or it can limit the options based
421 * in the pin being assumed to be exclusively an input or an output pin. In
422 * addition, "input" pins may or may not process the mic bias option
423 * depending on actual widget capability (NIDs 0x0f and 0x10 don't seem to
424 * accept requests for bias as of chip versions up to March 2006) and/or
425 * wiring in the computer.
426 */
427 #define ALC_PIN_DIR_IN 0x00
428 #define ALC_PIN_DIR_OUT 0x01
429 #define ALC_PIN_DIR_INOUT 0x02
430 #define ALC_PIN_DIR_IN_NOMICBIAS 0x03
431 #define ALC_PIN_DIR_INOUT_NOMICBIAS 0x04
432
433 /* Info about the pin modes supported by the different pin direction modes.
434 * For each direction the minimum and maximum values are given.
435 */
436 static signed char alc_pin_mode_dir_info[5][2] = {
437 { 0, 2 }, /* ALC_PIN_DIR_IN */
438 { 3, 4 }, /* ALC_PIN_DIR_OUT */
439 { 0, 4 }, /* ALC_PIN_DIR_INOUT */
440 { 2, 2 }, /* ALC_PIN_DIR_IN_NOMICBIAS */
441 { 2, 4 }, /* ALC_PIN_DIR_INOUT_NOMICBIAS */
442 };
443 #define alc_pin_mode_min(_dir) (alc_pin_mode_dir_info[_dir][0])
444 #define alc_pin_mode_max(_dir) (alc_pin_mode_dir_info[_dir][1])
445 #define alc_pin_mode_n_items(_dir) \
446 (alc_pin_mode_max(_dir)-alc_pin_mode_min(_dir)+1)
447
448 static int alc_pin_mode_info(struct snd_kcontrol *kcontrol,
449 struct snd_ctl_elem_info *uinfo)
450 {
451 unsigned int item_num = uinfo->value.enumerated.item;
452 unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
453
454 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
455 uinfo->count = 1;
456 uinfo->value.enumerated.items = alc_pin_mode_n_items(dir);
457
458 if (item_num<alc_pin_mode_min(dir) || item_num>alc_pin_mode_max(dir))
459 item_num = alc_pin_mode_min(dir);
460 strcpy(uinfo->value.enumerated.name, alc_pin_mode_names[item_num]);
461 return 0;
462 }
463
464 static int alc_pin_mode_get(struct snd_kcontrol *kcontrol,
465 struct snd_ctl_elem_value *ucontrol)
466 {
467 unsigned int i;
468 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
469 hda_nid_t nid = kcontrol->private_value & 0xffff;
470 unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
471 long *valp = ucontrol->value.integer.value;
472 unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
473 AC_VERB_GET_PIN_WIDGET_CONTROL,
474 0x00);
475
476 /* Find enumerated value for current pinctl setting */
477 i = alc_pin_mode_min(dir);
478 while (alc_pin_mode_values[i] != pinctl && i <= alc_pin_mode_max(dir))
479 i++;
480 *valp = i <= alc_pin_mode_max(dir) ? i: alc_pin_mode_min(dir);
481 return 0;
482 }
483
484 static int alc_pin_mode_put(struct snd_kcontrol *kcontrol,
485 struct snd_ctl_elem_value *ucontrol)
486 {
487 signed int change;
488 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
489 hda_nid_t nid = kcontrol->private_value & 0xffff;
490 unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
491 long val = *ucontrol->value.integer.value;
492 unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
493 AC_VERB_GET_PIN_WIDGET_CONTROL,
494 0x00);
495
496 if (val < alc_pin_mode_min(dir) || val > alc_pin_mode_max(dir))
497 val = alc_pin_mode_min(dir);
498
499 change = pinctl != alc_pin_mode_values[val];
500 if (change) {
501 /* Set pin mode to that requested */
502 snd_hda_codec_write_cache(codec, nid, 0,
503 AC_VERB_SET_PIN_WIDGET_CONTROL,
504 alc_pin_mode_values[val]);
505
506 /* Also enable the retasking pin's input/output as required
507 * for the requested pin mode. Enum values of 2 or less are
508 * input modes.
509 *
510 * Dynamically switching the input/output buffers probably
511 * reduces noise slightly (particularly on input) so we'll
512 * do it. However, having both input and output buffers
513 * enabled simultaneously doesn't seem to be problematic if
514 * this turns out to be necessary in the future.
515 */
516 if (val <= 2) {
517 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
518 HDA_AMP_MUTE, HDA_AMP_MUTE);
519 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
520 HDA_AMP_MUTE, 0);
521 } else {
522 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
523 HDA_AMP_MUTE, HDA_AMP_MUTE);
524 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
525 HDA_AMP_MUTE, 0);
526 }
527 }
528 return change;
529 }
530
531 #define ALC_PIN_MODE(xname, nid, dir) \
532 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
533 .info = alc_pin_mode_info, \
534 .get = alc_pin_mode_get, \
535 .put = alc_pin_mode_put, \
536 .private_value = nid | (dir<<16) }
537
538 /* A switch control for ALC260 GPIO pins. Multiple GPIOs can be ganged
539 * together using a mask with more than one bit set. This control is
540 * currently used only by the ALC260 test model. At this stage they are not
541 * needed for any "production" models.
542 */
543 #ifdef CONFIG_SND_DEBUG
544 #define alc_gpio_data_info snd_ctl_boolean_mono_info
545
546 static int alc_gpio_data_get(struct snd_kcontrol *kcontrol,
547 struct snd_ctl_elem_value *ucontrol)
548 {
549 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
550 hda_nid_t nid = kcontrol->private_value & 0xffff;
551 unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
552 long *valp = ucontrol->value.integer.value;
553 unsigned int val = snd_hda_codec_read(codec, nid, 0,
554 AC_VERB_GET_GPIO_DATA, 0x00);
555
556 *valp = (val & mask) != 0;
557 return 0;
558 }
559 static int alc_gpio_data_put(struct snd_kcontrol *kcontrol,
560 struct snd_ctl_elem_value *ucontrol)
561 {
562 signed int change;
563 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
564 hda_nid_t nid = kcontrol->private_value & 0xffff;
565 unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
566 long val = *ucontrol->value.integer.value;
567 unsigned int gpio_data = snd_hda_codec_read(codec, nid, 0,
568 AC_VERB_GET_GPIO_DATA,
569 0x00);
570
571 /* Set/unset the masked GPIO bit(s) as needed */
572 change = (val == 0 ? 0 : mask) != (gpio_data & mask);
573 if (val == 0)
574 gpio_data &= ~mask;
575 else
576 gpio_data |= mask;
577 snd_hda_codec_write_cache(codec, nid, 0,
578 AC_VERB_SET_GPIO_DATA, gpio_data);
579
580 return change;
581 }
582 #define ALC_GPIO_DATA_SWITCH(xname, nid, mask) \
583 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
584 .info = alc_gpio_data_info, \
585 .get = alc_gpio_data_get, \
586 .put = alc_gpio_data_put, \
587 .private_value = nid | (mask<<16) }
588 #endif /* CONFIG_SND_DEBUG */
589
590 /* A switch control to allow the enabling of the digital IO pins on the
591 * ALC260. This is incredibly simplistic; the intention of this control is
592 * to provide something in the test model allowing digital outputs to be
593 * identified if present. If models are found which can utilise these
594 * outputs a more complete mixer control can be devised for those models if
595 * necessary.
596 */
597 #ifdef CONFIG_SND_DEBUG
598 #define alc_spdif_ctrl_info snd_ctl_boolean_mono_info
599
600 static int alc_spdif_ctrl_get(struct snd_kcontrol *kcontrol,
601 struct snd_ctl_elem_value *ucontrol)
602 {
603 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
604 hda_nid_t nid = kcontrol->private_value & 0xffff;
605 unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
606 long *valp = ucontrol->value.integer.value;
607 unsigned int val = snd_hda_codec_read(codec, nid, 0,
608 AC_VERB_GET_DIGI_CONVERT_1, 0x00);
609
610 *valp = (val & mask) != 0;
611 return 0;
612 }
613 static int alc_spdif_ctrl_put(struct snd_kcontrol *kcontrol,
614 struct snd_ctl_elem_value *ucontrol)
615 {
616 signed int change;
617 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
618 hda_nid_t nid = kcontrol->private_value & 0xffff;
619 unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
620 long val = *ucontrol->value.integer.value;
621 unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
622 AC_VERB_GET_DIGI_CONVERT_1,
623 0x00);
624
625 /* Set/unset the masked control bit(s) as needed */
626 change = (val == 0 ? 0 : mask) != (ctrl_data & mask);
627 if (val==0)
628 ctrl_data &= ~mask;
629 else
630 ctrl_data |= mask;
631 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
632 ctrl_data);
633
634 return change;
635 }
636 #define ALC_SPDIF_CTRL_SWITCH(xname, nid, mask) \
637 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
638 .info = alc_spdif_ctrl_info, \
639 .get = alc_spdif_ctrl_get, \
640 .put = alc_spdif_ctrl_put, \
641 .private_value = nid | (mask<<16) }
642 #endif /* CONFIG_SND_DEBUG */
643
644 /* A switch control to allow the enabling EAPD digital outputs on the ALC26x.
645 * Again, this is only used in the ALC26x test models to help identify when
646 * the EAPD line must be asserted for features to work.
647 */
648 #ifdef CONFIG_SND_DEBUG
649 #define alc_eapd_ctrl_info snd_ctl_boolean_mono_info
650
651 static int alc_eapd_ctrl_get(struct snd_kcontrol *kcontrol,
652 struct snd_ctl_elem_value *ucontrol)
653 {
654 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
655 hda_nid_t nid = kcontrol->private_value & 0xffff;
656 unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
657 long *valp = ucontrol->value.integer.value;
658 unsigned int val = snd_hda_codec_read(codec, nid, 0,
659 AC_VERB_GET_EAPD_BTLENABLE, 0x00);
660
661 *valp = (val & mask) != 0;
662 return 0;
663 }
664
665 static int alc_eapd_ctrl_put(struct snd_kcontrol *kcontrol,
666 struct snd_ctl_elem_value *ucontrol)
667 {
668 int change;
669 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
670 hda_nid_t nid = kcontrol->private_value & 0xffff;
671 unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
672 long val = *ucontrol->value.integer.value;
673 unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
674 AC_VERB_GET_EAPD_BTLENABLE,
675 0x00);
676
677 /* Set/unset the masked control bit(s) as needed */
678 change = (!val ? 0 : mask) != (ctrl_data & mask);
679 if (!val)
680 ctrl_data &= ~mask;
681 else
682 ctrl_data |= mask;
683 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
684 ctrl_data);
685
686 return change;
687 }
688
689 #define ALC_EAPD_CTRL_SWITCH(xname, nid, mask) \
690 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
691 .info = alc_eapd_ctrl_info, \
692 .get = alc_eapd_ctrl_get, \
693 .put = alc_eapd_ctrl_put, \
694 .private_value = nid | (mask<<16) }
695 #endif /* CONFIG_SND_DEBUG */
696
697 /*
698 * set up from the preset table
699 */
700 static void setup_preset(struct alc_spec *spec,
701 const struct alc_config_preset *preset)
702 {
703 int i;
704
705 for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++)
706 spec->mixers[spec->num_mixers++] = preset->mixers[i];
707 for (i = 0; i < ARRAY_SIZE(preset->init_verbs) && preset->init_verbs[i];
708 i++)
709 spec->init_verbs[spec->num_init_verbs++] =
710 preset->init_verbs[i];
711
712 spec->channel_mode = preset->channel_mode;
713 spec->num_channel_mode = preset->num_channel_mode;
714 spec->need_dac_fix = preset->need_dac_fix;
715
716 spec->multiout.max_channels = spec->channel_mode[0].channels;
717
718 spec->multiout.num_dacs = preset->num_dacs;
719 spec->multiout.dac_nids = preset->dac_nids;
720 spec->multiout.dig_out_nid = preset->dig_out_nid;
721 spec->multiout.hp_nid = preset->hp_nid;
722
723 spec->num_mux_defs = preset->num_mux_defs;
724 if (!spec->num_mux_defs)
725 spec->num_mux_defs = 1;
726 spec->input_mux = preset->input_mux;
727
728 spec->num_adc_nids = preset->num_adc_nids;
729 spec->adc_nids = preset->adc_nids;
730 spec->capsrc_nids = preset->capsrc_nids;
731 spec->dig_in_nid = preset->dig_in_nid;
732
733 spec->unsol_event = preset->unsol_event;
734 spec->init_hook = preset->init_hook;
735 #ifdef CONFIG_SND_HDA_POWER_SAVE
736 spec->loopback.amplist = preset->loopbacks;
737 #endif
738 }
739
740 /* Enable GPIO mask and set output */
741 static struct hda_verb alc_gpio1_init_verbs[] = {
742 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
743 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
744 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
745 { }
746 };
747
748 static struct hda_verb alc_gpio2_init_verbs[] = {
749 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
750 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
751 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
752 { }
753 };
754
755 static struct hda_verb alc_gpio3_init_verbs[] = {
756 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
757 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
758 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
759 { }
760 };
761
762 /*
763 * Fix hardware PLL issue
764 * On some codecs, the analog PLL gating control must be off while
765 * the default value is 1.
766 */
767 static void alc_fix_pll(struct hda_codec *codec)
768 {
769 struct alc_spec *spec = codec->spec;
770 unsigned int val;
771
772 if (!spec->pll_nid)
773 return;
774 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
775 spec->pll_coef_idx);
776 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
777 AC_VERB_GET_PROC_COEF, 0);
778 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
779 spec->pll_coef_idx);
780 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
781 val & ~(1 << spec->pll_coef_bit));
782 }
783
784 static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
785 unsigned int coef_idx, unsigned int coef_bit)
786 {
787 struct alc_spec *spec = codec->spec;
788 spec->pll_nid = nid;
789 spec->pll_coef_idx = coef_idx;
790 spec->pll_coef_bit = coef_bit;
791 alc_fix_pll(codec);
792 }
793
794 static void alc_sku_automute(struct hda_codec *codec)
795 {
796 struct alc_spec *spec = codec->spec;
797 unsigned int present;
798 unsigned int hp_nid = spec->autocfg.hp_pins[0];
799 unsigned int sp_nid = spec->autocfg.speaker_pins[0];
800
801 /* need to execute and sync at first */
802 snd_hda_codec_read(codec, hp_nid, 0, AC_VERB_SET_PIN_SENSE, 0);
803 present = snd_hda_codec_read(codec, hp_nid, 0,
804 AC_VERB_GET_PIN_SENSE, 0);
805 spec->jack_present = (present & 0x80000000) != 0;
806 snd_hda_codec_write(codec, sp_nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
807 spec->jack_present ? 0 : PIN_OUT);
808 }
809
810 /* unsolicited event for HP jack sensing */
811 static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
812 {
813 if (codec->vendor_id == 0x10ec0880)
814 res >>= 28;
815 else
816 res >>= 26;
817 if (res != ALC880_HP_EVENT)
818 return;
819
820 alc_sku_automute(codec);
821 }
822
823 /* additional initialization for ALC888 variants */
824 static void alc888_coef_init(struct hda_codec *codec)
825 {
826 unsigned int tmp;
827
828 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
829 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
830 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
831 if ((tmp & 0xf0) == 2)
832 /* alc888S-VC */
833 snd_hda_codec_read(codec, 0x20, 0,
834 AC_VERB_SET_PROC_COEF, 0x830);
835 else
836 /* alc888-VB */
837 snd_hda_codec_read(codec, 0x20, 0,
838 AC_VERB_SET_PROC_COEF, 0x3030);
839 }
840
841 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
842 * 31 ~ 16 : Manufacture ID
843 * 15 ~ 8 : SKU ID
844 * 7 ~ 0 : Assembly ID
845 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
846 */
847 static void alc_subsystem_id(struct hda_codec *codec,
848 unsigned int porta, unsigned int porte,
849 unsigned int portd)
850 {
851 unsigned int ass, tmp, i;
852 unsigned nid;
853 struct alc_spec *spec = codec->spec;
854
855 ass = codec->subsystem_id & 0xffff;
856 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
857 goto do_sku;
858
859 /*
860 * 31~30 : port conetcivity
861 * 29~21 : reserve
862 * 20 : PCBEEP input
863 * 19~16 : Check sum (15:1)
864 * 15~1 : Custom
865 * 0 : override
866 */
867 nid = 0x1d;
868 if (codec->vendor_id == 0x10ec0260)
869 nid = 0x17;
870 ass = snd_hda_codec_read(codec, nid, 0,
871 AC_VERB_GET_CONFIG_DEFAULT, 0);
872 if (!(ass & 1) && !(ass & 0x100000))
873 return;
874 if ((ass >> 30) != 1) /* no physical connection */
875 return;
876
877 /* check sum */
878 tmp = 0;
879 for (i = 1; i < 16; i++) {
880 if ((ass >> i) & 1)
881 tmp++;
882 }
883 if (((ass >> 16) & 0xf) != tmp)
884 return;
885 do_sku:
886 /*
887 * 0 : override
888 * 1 : Swap Jack
889 * 2 : 0 --> Desktop, 1 --> Laptop
890 * 3~5 : External Amplifier control
891 * 7~6 : Reserved
892 */
893 tmp = (ass & 0x38) >> 3; /* external Amp control */
894 switch (tmp) {
895 case 1:
896 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
897 break;
898 case 3:
899 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
900 break;
901 case 7:
902 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
903 break;
904 case 5: /* set EAPD output high */
905 switch (codec->vendor_id) {
906 case 0x10ec0260:
907 snd_hda_codec_write(codec, 0x0f, 0,
908 AC_VERB_SET_EAPD_BTLENABLE, 2);
909 snd_hda_codec_write(codec, 0x10, 0,
910 AC_VERB_SET_EAPD_BTLENABLE, 2);
911 break;
912 case 0x10ec0262:
913 case 0x10ec0267:
914 case 0x10ec0268:
915 case 0x10ec0269:
916 case 0x10ec0660:
917 case 0x10ec0662:
918 case 0x10ec0663:
919 case 0x10ec0862:
920 case 0x10ec0889:
921 snd_hda_codec_write(codec, 0x14, 0,
922 AC_VERB_SET_EAPD_BTLENABLE, 2);
923 snd_hda_codec_write(codec, 0x15, 0,
924 AC_VERB_SET_EAPD_BTLENABLE, 2);
925 break;
926 }
927 switch (codec->vendor_id) {
928 case 0x10ec0260:
929 snd_hda_codec_write(codec, 0x1a, 0,
930 AC_VERB_SET_COEF_INDEX, 7);
931 tmp = snd_hda_codec_read(codec, 0x1a, 0,
932 AC_VERB_GET_PROC_COEF, 0);
933 snd_hda_codec_write(codec, 0x1a, 0,
934 AC_VERB_SET_COEF_INDEX, 7);
935 snd_hda_codec_write(codec, 0x1a, 0,
936 AC_VERB_SET_PROC_COEF,
937 tmp | 0x2010);
938 break;
939 case 0x10ec0262:
940 case 0x10ec0880:
941 case 0x10ec0882:
942 case 0x10ec0883:
943 case 0x10ec0885:
944 case 0x10ec0889:
945 snd_hda_codec_write(codec, 0x20, 0,
946 AC_VERB_SET_COEF_INDEX, 7);
947 tmp = snd_hda_codec_read(codec, 0x20, 0,
948 AC_VERB_GET_PROC_COEF, 0);
949 snd_hda_codec_write(codec, 0x20, 0,
950 AC_VERB_SET_COEF_INDEX, 7);
951 snd_hda_codec_write(codec, 0x20, 0,
952 AC_VERB_SET_PROC_COEF,
953 tmp | 0x2010);
954 break;
955 case 0x10ec0888:
956 alc888_coef_init(codec);
957 break;
958 case 0x10ec0267:
959 case 0x10ec0268:
960 snd_hda_codec_write(codec, 0x20, 0,
961 AC_VERB_SET_COEF_INDEX, 7);
962 tmp = snd_hda_codec_read(codec, 0x20, 0,
963 AC_VERB_GET_PROC_COEF, 0);
964 snd_hda_codec_write(codec, 0x20, 0,
965 AC_VERB_SET_COEF_INDEX, 7);
966 snd_hda_codec_write(codec, 0x20, 0,
967 AC_VERB_SET_PROC_COEF,
968 tmp | 0x3000);
969 break;
970 }
971 default:
972 break;
973 }
974
975 /* is laptop or Desktop and enable the function "Mute internal speaker
976 * when the external headphone out jack is plugged"
977 */
978 if (!(ass & 0x8000))
979 return;
980 /*
981 * 10~8 : Jack location
982 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
983 * 14~13: Resvered
984 * 15 : 1 --> enable the function "Mute internal speaker
985 * when the external headphone out jack is plugged"
986 */
987 if (!spec->autocfg.speaker_pins[0]) {
988 if (spec->autocfg.line_out_pins[0])
989 spec->autocfg.speaker_pins[0] =
990 spec->autocfg.line_out_pins[0];
991 else
992 return;
993 }
994
995 if (!spec->autocfg.hp_pins[0]) {
996 tmp = (ass >> 11) & 0x3; /* HP to chassis */
997 if (tmp == 0)
998 spec->autocfg.hp_pins[0] = porta;
999 else if (tmp == 1)
1000 spec->autocfg.hp_pins[0] = porte;
1001 else if (tmp == 2)
1002 spec->autocfg.hp_pins[0] = portd;
1003 else
1004 return;
1005 }
1006
1007 snd_hda_codec_write(codec, spec->autocfg.hp_pins[0], 0,
1008 AC_VERB_SET_UNSOLICITED_ENABLE,
1009 AC_USRSP_EN | ALC880_HP_EVENT);
1010 spec->unsol_event = alc_sku_unsol_event;
1011 }
1012
1013 /*
1014 * Fix-up pin default configurations
1015 */
1016
1017 struct alc_pincfg {
1018 hda_nid_t nid;
1019 u32 val;
1020 };
1021
1022 static void alc_fix_pincfg(struct hda_codec *codec,
1023 const struct snd_pci_quirk *quirk,
1024 const struct alc_pincfg **pinfix)
1025 {
1026 const struct alc_pincfg *cfg;
1027
1028 quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1029 if (!quirk)
1030 return;
1031
1032 cfg = pinfix[quirk->value];
1033 for (; cfg->nid; cfg++) {
1034 int i;
1035 u32 val = cfg->val;
1036 for (i = 0; i < 4; i++) {
1037 snd_hda_codec_write(codec, cfg->nid, 0,
1038 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0 + i,
1039 val & 0xff);
1040 val >>= 8;
1041 }
1042 }
1043 }
1044
1045 /*
1046 * ALC880 3-stack model
1047 *
1048 * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0e)
1049 * Pin assignment: Front = 0x14, Line-In/Surr = 0x1a, Mic/CLFE = 0x18,
1050 * F-Mic = 0x1b, HP = 0x19
1051 */
1052
1053 static hda_nid_t alc880_dac_nids[4] = {
1054 /* front, rear, clfe, rear_surr */
1055 0x02, 0x05, 0x04, 0x03
1056 };
1057
1058 static hda_nid_t alc880_adc_nids[3] = {
1059 /* ADC0-2 */
1060 0x07, 0x08, 0x09,
1061 };
1062
1063 /* The datasheet says the node 0x07 is connected from inputs,
1064 * but it shows zero connection in the real implementation on some devices.
1065 * Note: this is a 915GAV bug, fixed on 915GLV
1066 */
1067 static hda_nid_t alc880_adc_nids_alt[2] = {
1068 /* ADC1-2 */
1069 0x08, 0x09,
1070 };
1071
1072 #define ALC880_DIGOUT_NID 0x06
1073 #define ALC880_DIGIN_NID 0x0a
1074
1075 static struct hda_input_mux alc880_capture_source = {
1076 .num_items = 4,
1077 .items = {
1078 { "Mic", 0x0 },
1079 { "Front Mic", 0x3 },
1080 { "Line", 0x2 },
1081 { "CD", 0x4 },
1082 },
1083 };
1084
1085 /* channel source setting (2/6 channel selection for 3-stack) */
1086 /* 2ch mode */
1087 static struct hda_verb alc880_threestack_ch2_init[] = {
1088 /* set line-in to input, mute it */
1089 { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1090 { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1091 /* set mic-in to input vref 80%, mute it */
1092 { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1093 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1094 { } /* end */
1095 };
1096
1097 /* 6ch mode */
1098 static struct hda_verb alc880_threestack_ch6_init[] = {
1099 /* set line-in to output, unmute it */
1100 { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1101 { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1102 /* set mic-in to output, unmute it */
1103 { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1104 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1105 { } /* end */
1106 };
1107
1108 static struct hda_channel_mode alc880_threestack_modes[2] = {
1109 { 2, alc880_threestack_ch2_init },
1110 { 6, alc880_threestack_ch6_init },
1111 };
1112
1113 static struct snd_kcontrol_new alc880_three_stack_mixer[] = {
1114 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1115 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1116 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1117 HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
1118 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1119 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1120 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1121 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1122 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1123 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1124 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1125 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1126 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1127 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1128 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
1129 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
1130 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1131 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1132 HDA_CODEC_MUTE("Headphone Playback Switch", 0x19, 0x0, HDA_OUTPUT),
1133 {
1134 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1135 .name = "Channel Mode",
1136 .info = alc_ch_mode_info,
1137 .get = alc_ch_mode_get,
1138 .put = alc_ch_mode_put,
1139 },
1140 { } /* end */
1141 };
1142
1143 /* capture mixer elements */
1144 static struct snd_kcontrol_new alc880_capture_mixer[] = {
1145 HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
1146 HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
1147 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x08, 0x0, HDA_INPUT),
1148 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x08, 0x0, HDA_INPUT),
1149 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x09, 0x0, HDA_INPUT),
1150 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x09, 0x0, HDA_INPUT),
1151 {
1152 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1153 /* The multiple "Capture Source" controls confuse alsamixer
1154 * So call somewhat different..
1155 */
1156 /* .name = "Capture Source", */
1157 .name = "Input Source",
1158 .count = 3,
1159 .info = alc_mux_enum_info,
1160 .get = alc_mux_enum_get,
1161 .put = alc_mux_enum_put,
1162 },
1163 { } /* end */
1164 };
1165
1166 /* capture mixer elements (in case NID 0x07 not available) */
1167 static struct snd_kcontrol_new alc880_capture_alt_mixer[] = {
1168 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
1169 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
1170 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
1171 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
1172 {
1173 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1174 /* The multiple "Capture Source" controls confuse alsamixer
1175 * So call somewhat different..
1176 */
1177 /* .name = "Capture Source", */
1178 .name = "Input Source",
1179 .count = 2,
1180 .info = alc_mux_enum_info,
1181 .get = alc_mux_enum_get,
1182 .put = alc_mux_enum_put,
1183 },
1184 { } /* end */
1185 };
1186
1187
1188
1189 /*
1190 * ALC880 5-stack model
1191 *
1192 * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0d),
1193 * Side = 0x02 (0xd)
1194 * Pin assignment: Front = 0x14, Surr = 0x17, CLFE = 0x16
1195 * Line-In/Side = 0x1a, Mic = 0x18, F-Mic = 0x1b, HP = 0x19
1196 */
1197
1198 /* additional mixers to alc880_three_stack_mixer */
1199 static struct snd_kcontrol_new alc880_five_stack_mixer[] = {
1200 HDA_CODEC_VOLUME("Side Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1201 HDA_BIND_MUTE("Side Playback Switch", 0x0d, 2, HDA_INPUT),
1202 { } /* end */
1203 };
1204
1205 /* channel source setting (6/8 channel selection for 5-stack) */
1206 /* 6ch mode */
1207 static struct hda_verb alc880_fivestack_ch6_init[] = {
1208 /* set line-in to input, mute it */
1209 { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1210 { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1211 { } /* end */
1212 };
1213
1214 /* 8ch mode */
1215 static struct hda_verb alc880_fivestack_ch8_init[] = {
1216 /* set line-in to output, unmute it */
1217 { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1218 { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1219 { } /* end */
1220 };
1221
1222 static struct hda_channel_mode alc880_fivestack_modes[2] = {
1223 { 6, alc880_fivestack_ch6_init },
1224 { 8, alc880_fivestack_ch8_init },
1225 };
1226
1227
1228 /*
1229 * ALC880 6-stack model
1230 *
1231 * DAC: Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e),
1232 * Side = 0x05 (0x0f)
1233 * Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, Side = 0x17,
1234 * Mic = 0x18, F-Mic = 0x19, Line = 0x1a, HP = 0x1b
1235 */
1236
1237 static hda_nid_t alc880_6st_dac_nids[4] = {
1238 /* front, rear, clfe, rear_surr */
1239 0x02, 0x03, 0x04, 0x05
1240 };
1241
1242 static struct hda_input_mux alc880_6stack_capture_source = {
1243 .num_items = 4,
1244 .items = {
1245 { "Mic", 0x0 },
1246 { "Front Mic", 0x1 },
1247 { "Line", 0x2 },
1248 { "CD", 0x4 },
1249 },
1250 };
1251
1252 /* fixed 8-channels */
1253 static struct hda_channel_mode alc880_sixstack_modes[1] = {
1254 { 8, NULL },
1255 };
1256
1257 static struct snd_kcontrol_new alc880_six_stack_mixer[] = {
1258 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1259 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1260 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1261 HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1262 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1263 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1264 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1265 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1266 HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1267 HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
1268 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1269 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1270 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1271 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1272 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1273 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1274 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1275 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1276 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1277 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1278 {
1279 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1280 .name = "Channel Mode",
1281 .info = alc_ch_mode_info,
1282 .get = alc_ch_mode_get,
1283 .put = alc_ch_mode_put,
1284 },
1285 { } /* end */
1286 };
1287
1288
1289 /*
1290 * ALC880 W810 model
1291 *
1292 * W810 has rear IO for:
1293 * Front (DAC 02)
1294 * Surround (DAC 03)
1295 * Center/LFE (DAC 04)
1296 * Digital out (06)
1297 *
1298 * The system also has a pair of internal speakers, and a headphone jack.
1299 * These are both connected to Line2 on the codec, hence to DAC 02.
1300 *
1301 * There is a variable resistor to control the speaker or headphone
1302 * volume. This is a hardware-only device without a software API.
1303 *
1304 * Plugging headphones in will disable the internal speakers. This is
1305 * implemented in hardware, not via the driver using jack sense. In
1306 * a similar fashion, plugging into the rear socket marked "front" will
1307 * disable both the speakers and headphones.
1308 *
1309 * For input, there's a microphone jack, and an "audio in" jack.
1310 * These may not do anything useful with this driver yet, because I
1311 * haven't setup any initialization verbs for these yet...
1312 */
1313
1314 static hda_nid_t alc880_w810_dac_nids[3] = {
1315 /* front, rear/surround, clfe */
1316 0x02, 0x03, 0x04
1317 };
1318
1319 /* fixed 6 channels */
1320 static struct hda_channel_mode alc880_w810_modes[1] = {
1321 { 6, NULL }
1322 };
1323
1324 /* Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, HP = 0x1b */
1325 static struct snd_kcontrol_new alc880_w810_base_mixer[] = {
1326 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1327 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1328 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1329 HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1330 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1331 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1332 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1333 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1334 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1335 { } /* end */
1336 };
1337
1338
1339 /*
1340 * Z710V model
1341 *
1342 * DAC: Front = 0x02 (0x0c), HP = 0x03 (0x0d)
1343 * Pin assignment: Front = 0x14, HP = 0x15, Mic = 0x18, Mic2 = 0x19(?),
1344 * Line = 0x1a
1345 */
1346
1347 static hda_nid_t alc880_z71v_dac_nids[1] = {
1348 0x02
1349 };
1350 #define ALC880_Z71V_HP_DAC 0x03
1351
1352 /* fixed 2 channels */
1353 static struct hda_channel_mode alc880_2_jack_modes[1] = {
1354 { 2, NULL }
1355 };
1356
1357 static struct snd_kcontrol_new alc880_z71v_mixer[] = {
1358 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1359 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1360 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1361 HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
1362 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1363 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1364 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1365 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1366 { } /* end */
1367 };
1368
1369
1370 /*
1371 * ALC880 F1734 model
1372 *
1373 * DAC: HP = 0x02 (0x0c), Front = 0x03 (0x0d)
1374 * Pin assignment: HP = 0x14, Front = 0x15, Mic = 0x18
1375 */
1376
1377 static hda_nid_t alc880_f1734_dac_nids[1] = {
1378 0x03
1379 };
1380 #define ALC880_F1734_HP_DAC 0x02
1381
1382 static struct snd_kcontrol_new alc880_f1734_mixer[] = {
1383 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1384 HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1385 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1386 HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1387 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1388 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1389 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1390 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1391 { } /* end */
1392 };
1393
1394 static struct hda_input_mux alc880_f1734_capture_source = {
1395 .num_items = 2,
1396 .items = {
1397 { "Mic", 0x1 },
1398 { "CD", 0x4 },
1399 },
1400 };
1401
1402
1403 /*
1404 * ALC880 ASUS model
1405 *
1406 * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1407 * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1408 * Mic = 0x18, Line = 0x1a
1409 */
1410
1411 #define alc880_asus_dac_nids alc880_w810_dac_nids /* identical with w810 */
1412 #define alc880_asus_modes alc880_threestack_modes /* 2/6 channel mode */
1413
1414 static struct snd_kcontrol_new alc880_asus_mixer[] = {
1415 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1416 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1417 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1418 HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1419 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1420 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1421 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1422 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1423 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1424 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1425 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1426 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1427 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1428 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1429 {
1430 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1431 .name = "Channel Mode",
1432 .info = alc_ch_mode_info,
1433 .get = alc_ch_mode_get,
1434 .put = alc_ch_mode_put,
1435 },
1436 { } /* end */
1437 };
1438
1439 /*
1440 * ALC880 ASUS W1V model
1441 *
1442 * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1443 * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1444 * Mic = 0x18, Line = 0x1a, Line2 = 0x1b
1445 */
1446
1447 /* additional mixers to alc880_asus_mixer */
1448 static struct snd_kcontrol_new alc880_asus_w1v_mixer[] = {
1449 HDA_CODEC_VOLUME("Line2 Playback Volume", 0x0b, 0x03, HDA_INPUT),
1450 HDA_CODEC_MUTE("Line2 Playback Switch", 0x0b, 0x03, HDA_INPUT),
1451 { } /* end */
1452 };
1453
1454 /* additional mixers to alc880_asus_mixer */
1455 static struct snd_kcontrol_new alc880_pcbeep_mixer[] = {
1456 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1457 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1458 { } /* end */
1459 };
1460
1461 /* TCL S700 */
1462 static struct snd_kcontrol_new alc880_tcl_s700_mixer[] = {
1463 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1464 HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1465 HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1466 HDA_CODEC_VOLUME("CD Playback Volume", 0x0B, 0x04, HDA_INPUT),
1467 HDA_CODEC_MUTE("CD Playback Switch", 0x0B, 0x04, HDA_INPUT),
1468 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0B, 0x0, HDA_INPUT),
1469 HDA_CODEC_MUTE("Mic Playback Switch", 0x0B, 0x0, HDA_INPUT),
1470 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
1471 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
1472 {
1473 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1474 /* The multiple "Capture Source" controls confuse alsamixer
1475 * So call somewhat different..
1476 */
1477 /* .name = "Capture Source", */
1478 .name = "Input Source",
1479 .count = 1,
1480 .info = alc_mux_enum_info,
1481 .get = alc_mux_enum_get,
1482 .put = alc_mux_enum_put,
1483 },
1484 { } /* end */
1485 };
1486
1487 /* Uniwill */
1488 static struct snd_kcontrol_new alc880_uniwill_mixer[] = {
1489 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1490 HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1491 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1492 HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1493 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1494 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1495 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1496 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1497 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1498 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1499 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1500 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1501 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1502 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1503 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1504 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1505 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1506 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1507 {
1508 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1509 .name = "Channel Mode",
1510 .info = alc_ch_mode_info,
1511 .get = alc_ch_mode_get,
1512 .put = alc_ch_mode_put,
1513 },
1514 { } /* end */
1515 };
1516
1517 static struct snd_kcontrol_new alc880_fujitsu_mixer[] = {
1518 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1519 HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1520 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1521 HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1522 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1523 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1524 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1525 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1526 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1527 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1528 { } /* end */
1529 };
1530
1531 static struct snd_kcontrol_new alc880_uniwill_p53_mixer[] = {
1532 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1533 HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1534 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1535 HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1536 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1537 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1538 { } /* end */
1539 };
1540
1541 /*
1542 * virtual master controls
1543 */
1544
1545 /*
1546 * slave controls for virtual master
1547 */
1548 static const char *alc_slave_vols[] = {
1549 "Front Playback Volume",
1550 "Surround Playback Volume",
1551 "Center Playback Volume",
1552 "LFE Playback Volume",
1553 "Side Playback Volume",
1554 "Headphone Playback Volume",
1555 "Speaker Playback Volume",
1556 "Mono Playback Volume",
1557 "Line-Out Playback Volume",
1558 NULL,
1559 };
1560
1561 static const char *alc_slave_sws[] = {
1562 "Front Playback Switch",
1563 "Surround Playback Switch",
1564 "Center Playback Switch",
1565 "LFE Playback Switch",
1566 "Side Playback Switch",
1567 "Headphone Playback Switch",
1568 "Speaker Playback Switch",
1569 "Mono Playback Switch",
1570 "IEC958 Playback Switch",
1571 NULL,
1572 };
1573
1574 /*
1575 * build control elements
1576 */
1577 static int alc_build_controls(struct hda_codec *codec)
1578 {
1579 struct alc_spec *spec = codec->spec;
1580 int err;
1581 int i;
1582
1583 for (i = 0; i < spec->num_mixers; i++) {
1584 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1585 if (err < 0)
1586 return err;
1587 }
1588
1589 if (spec->multiout.dig_out_nid) {
1590 err = snd_hda_create_spdif_out_ctls(codec,
1591 spec->multiout.dig_out_nid);
1592 if (err < 0)
1593 return err;
1594 err = snd_hda_create_spdif_share_sw(codec,
1595 &spec->multiout);
1596 if (err < 0)
1597 return err;
1598 spec->multiout.share_spdif = 1;
1599 }
1600 if (spec->dig_in_nid) {
1601 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1602 if (err < 0)
1603 return err;
1604 }
1605
1606 /* if we have no master control, let's create it */
1607 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1608 unsigned int vmaster_tlv[4];
1609 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
1610 HDA_OUTPUT, vmaster_tlv);
1611 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1612 vmaster_tlv, alc_slave_vols);
1613 if (err < 0)
1614 return err;
1615 }
1616 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1617 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1618 NULL, alc_slave_sws);
1619 if (err < 0)
1620 return err;
1621 }
1622
1623 return 0;
1624 }
1625
1626
1627 /*
1628 * initialize the codec volumes, etc
1629 */
1630
1631 /*
1632 * generic initialization of ADC, input mixers and output mixers
1633 */
1634 static struct hda_verb alc880_volume_init_verbs[] = {
1635 /*
1636 * Unmute ADC0-2 and set the default input to mic-in
1637 */
1638 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
1639 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1640 {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
1641 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1642 {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
1643 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1644
1645 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1646 * mixer widget
1647 * Note: PASD motherboards uses the Line In 2 as the input for front
1648 * panel mic (mic 2)
1649 */
1650 /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
1651 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1652 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1653 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
1654 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
1655 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
1656 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
1657 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
1658
1659 /*
1660 * Set up output mixers (0x0c - 0x0f)
1661 */
1662 /* set vol=0 to output mixers */
1663 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1664 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1665 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1666 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1667 /* set up input amps for analog loopback */
1668 /* Amp Indices: DAC = 0, mixer = 1 */
1669 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1670 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1671 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1672 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1673 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1674 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1675 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1676 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1677
1678 { }
1679 };
1680
1681 /*
1682 * 3-stack pin configuration:
1683 * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
1684 */
1685 static struct hda_verb alc880_pin_3stack_init_verbs[] = {
1686 /*
1687 * preset connection lists of input pins
1688 * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
1689 */
1690 {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
1691 {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1692 {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
1693
1694 /*
1695 * Set pin mode and muting
1696 */
1697 /* set front pin widgets 0x14 for output */
1698 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1699 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1700 /* Mic1 (rear panel) pin widget for input and vref at 80% */
1701 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1702 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1703 /* Mic2 (as headphone out) for HP output */
1704 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1705 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1706 /* Line In pin widget for input */
1707 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1708 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1709 /* Line2 (as front mic) pin widget for input and vref at 80% */
1710 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1711 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1712 /* CD pin widget for input */
1713 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1714
1715 { }
1716 };
1717
1718 /*
1719 * 5-stack pin configuration:
1720 * front = 0x14, surround = 0x17, clfe = 0x16, mic = 0x18, HP = 0x19,
1721 * line-in/side = 0x1a, f-mic = 0x1b
1722 */
1723 static struct hda_verb alc880_pin_5stack_init_verbs[] = {
1724 /*
1725 * preset connection lists of input pins
1726 * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
1727 */
1728 {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1729 {0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/side */
1730
1731 /*
1732 * Set pin mode and muting
1733 */
1734 /* set pin widgets 0x14-0x17 for output */
1735 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1736 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1737 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1738 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1739 /* unmute pins for output (no gain on this amp) */
1740 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1741 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1742 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1743 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1744
1745 /* Mic1 (rear panel) pin widget for input and vref at 80% */
1746 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1747 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1748 /* Mic2 (as headphone out) for HP output */
1749 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1750 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1751 /* Line In pin widget for input */
1752 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1753 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1754 /* Line2 (as front mic) pin widget for input and vref at 80% */
1755 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1756 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1757 /* CD pin widget for input */
1758 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1759
1760 { }
1761 };
1762
1763 /*
1764 * W810 pin configuration:
1765 * front = 0x14, surround = 0x15, clfe = 0x16, HP = 0x1b
1766 */
1767 static struct hda_verb alc880_pin_w810_init_verbs[] = {
1768 /* hphone/speaker input selector: front DAC */
1769 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
1770
1771 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1772 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1773 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1774 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1775 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1776 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1777
1778 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1779 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1780
1781 { }
1782 };
1783
1784 /*
1785 * Z71V pin configuration:
1786 * Speaker-out = 0x14, HP = 0x15, Mic = 0x18, Line-in = 0x1a, Mic2 = 0x1b (?)
1787 */
1788 static struct hda_verb alc880_pin_z71v_init_verbs[] = {
1789 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1790 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1791 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1792 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1793
1794 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1795 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1796 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1797 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1798
1799 { }
1800 };
1801
1802 /*
1803 * 6-stack pin configuration:
1804 * front = 0x14, surr = 0x15, clfe = 0x16, side = 0x17, mic = 0x18,
1805 * f-mic = 0x19, line = 0x1a, HP = 0x1b
1806 */
1807 static struct hda_verb alc880_pin_6stack_init_verbs[] = {
1808 {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1809
1810 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1811 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1812 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1813 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1814 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1815 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1816 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1817 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1818
1819 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1820 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1821 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1822 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1823 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1824 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1825 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1826 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1827 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1828
1829 { }
1830 };
1831
1832 /*
1833 * Uniwill pin configuration:
1834 * HP = 0x14, InternalSpeaker = 0x15, mic = 0x18, internal mic = 0x19,
1835 * line = 0x1a
1836 */
1837 static struct hda_verb alc880_uniwill_init_verbs[] = {
1838 {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1839
1840 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1841 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1842 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1843 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1844 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1845 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1846 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1847 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1848 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1849 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1850 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1851 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1852 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1853 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1854
1855 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1856 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1857 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1858 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1859 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1860 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1861 /* {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, */
1862 /* {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
1863 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1864
1865 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
1866 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
1867
1868 { }
1869 };
1870
1871 /*
1872 * Uniwill P53
1873 * HP = 0x14, InternalSpeaker = 0x15, mic = 0x19,
1874 */
1875 static struct hda_verb alc880_uniwill_p53_init_verbs[] = {
1876 {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1877
1878 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1879 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1880 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1881 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1882 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1883 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1884 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1885 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1886 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1887 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1888 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1889 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1890
1891 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1892 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1893 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1894 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1895 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1896 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1897
1898 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
1899 {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_DCVOL_EVENT},
1900
1901 { }
1902 };
1903
1904 static struct hda_verb alc880_beep_init_verbs[] = {
1905 { 0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5) },
1906 { }
1907 };
1908
1909 /* toggle speaker-output according to the hp-jack state */
1910 static void alc880_uniwill_hp_automute(struct hda_codec *codec)
1911 {
1912 unsigned int present;
1913 unsigned char bits;
1914
1915 present = snd_hda_codec_read(codec, 0x14, 0,
1916 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1917 bits = present ? HDA_AMP_MUTE : 0;
1918 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
1919 HDA_AMP_MUTE, bits);
1920 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
1921 HDA_AMP_MUTE, bits);
1922 }
1923
1924 /* auto-toggle front mic */
1925 static void alc880_uniwill_mic_automute(struct hda_codec *codec)
1926 {
1927 unsigned int present;
1928 unsigned char bits;
1929
1930 present = snd_hda_codec_read(codec, 0x18, 0,
1931 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1932 bits = present ? HDA_AMP_MUTE : 0;
1933 snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
1934 }
1935
1936 static void alc880_uniwill_automute(struct hda_codec *codec)
1937 {
1938 alc880_uniwill_hp_automute(codec);
1939 alc880_uniwill_mic_automute(codec);
1940 }
1941
1942 static void alc880_uniwill_unsol_event(struct hda_codec *codec,
1943 unsigned int res)
1944 {
1945 /* Looks like the unsol event is incompatible with the standard
1946 * definition. 4bit tag is placed at 28 bit!
1947 */
1948 switch (res >> 28) {
1949 case ALC880_HP_EVENT:
1950 alc880_uniwill_hp_automute(codec);
1951 break;
1952 case ALC880_MIC_EVENT:
1953 alc880_uniwill_mic_automute(codec);
1954 break;
1955 }
1956 }
1957
1958 static void alc880_uniwill_p53_hp_automute(struct hda_codec *codec)
1959 {
1960 unsigned int present;
1961 unsigned char bits;
1962
1963 present = snd_hda_codec_read(codec, 0x14, 0,
1964 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1965 bits = present ? HDA_AMP_MUTE : 0;
1966 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, HDA_AMP_MUTE, bits);
1967 }
1968
1969 static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
1970 {
1971 unsigned int present;
1972
1973 present = snd_hda_codec_read(codec, 0x21, 0,
1974 AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
1975 present &= HDA_AMP_VOLMASK;
1976 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0,
1977 HDA_AMP_VOLMASK, present);
1978 snd_hda_codec_amp_stereo(codec, 0x0d, HDA_OUTPUT, 0,
1979 HDA_AMP_VOLMASK, present);
1980 }
1981
1982 static void alc880_uniwill_p53_unsol_event(struct hda_codec *codec,
1983 unsigned int res)
1984 {
1985 /* Looks like the unsol event is incompatible with the standard
1986 * definition. 4bit tag is placed at 28 bit!
1987 */
1988 if ((res >> 28) == ALC880_HP_EVENT)
1989 alc880_uniwill_p53_hp_automute(codec);
1990 if ((res >> 28) == ALC880_DCVOL_EVENT)
1991 alc880_uniwill_p53_dcvol_automute(codec);
1992 }
1993
1994 /*
1995 * F1734 pin configuration:
1996 * HP = 0x14, speaker-out = 0x15, mic = 0x18
1997 */
1998 static struct hda_verb alc880_pin_f1734_init_verbs[] = {
1999 {0x07, AC_VERB_SET_CONNECT_SEL, 0x01},
2000 {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2001 {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2002 {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2003 {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2004
2005 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2006 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2007 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2008 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2009
2010 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2011 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2012 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
2013 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2014 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2015 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2016 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2017 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2018 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2019
2020 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
2021 {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_DCVOL_EVENT},
2022
2023 { }
2024 };
2025
2026 /*
2027 * ASUS pin configuration:
2028 * HP/front = 0x14, surr = 0x15, clfe = 0x16, mic = 0x18, line = 0x1a
2029 */
2030 static struct hda_verb alc880_pin_asus_init_verbs[] = {
2031 {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2032 {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2033 {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2034 {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2035
2036 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2037 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2038 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2039 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2040 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2041 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2042 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2043 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2044
2045 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2046 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2047 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2048 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2049 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2050 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2051 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2052 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2053 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2054
2055 { }
2056 };
2057
2058 /* Enable GPIO mask and set output */
2059 #define alc880_gpio1_init_verbs alc_gpio1_init_verbs
2060 #define alc880_gpio2_init_verbs alc_gpio2_init_verbs
2061
2062 /* Clevo m520g init */
2063 static struct hda_verb alc880_pin_clevo_init_verbs[] = {
2064 /* headphone output */
2065 {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2066 /* line-out */
2067 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2068 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2069 /* Line-in */
2070 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2071 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2072 /* CD */
2073 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2074 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2075 /* Mic1 (rear panel) */
2076 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2077 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2078 /* Mic2 (front panel) */
2079 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2080 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2081 /* headphone */
2082 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2083 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2084 /* change to EAPD mode */
2085 {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2086 {0x20, AC_VERB_SET_PROC_COEF, 0x3060},
2087
2088 { }
2089 };
2090
2091 static struct hda_verb alc880_pin_tcl_S700_init_verbs[] = {
2092 /* change to EAPD mode */
2093 {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2094 {0x20, AC_VERB_SET_PROC_COEF, 0x3060},
2095
2096 /* Headphone output */
2097 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2098 /* Front output*/
2099 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2100 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
2101
2102 /* Line In pin widget for input */
2103 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2104 /* CD pin widget for input */
2105 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2106 /* Mic1 (rear panel) pin widget for input and vref at 80% */
2107 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2108
2109 /* change to EAPD mode */
2110 {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2111 {0x20, AC_VERB_SET_PROC_COEF, 0x3070},
2112
2113 { }
2114 };
2115
2116 /*
2117 * LG m1 express dual
2118 *
2119 * Pin assignment:
2120 * Rear Line-In/Out (blue): 0x14
2121 * Build-in Mic-In: 0x15
2122 * Speaker-out: 0x17
2123 * HP-Out (green): 0x1b
2124 * Mic-In/Out (red): 0x19
2125 * SPDIF-Out: 0x1e
2126 */
2127
2128 /* To make 5.1 output working (green=Front, blue=Surr, red=CLFE) */
2129 static hda_nid_t alc880_lg_dac_nids[3] = {
2130 0x05, 0x02, 0x03
2131 };
2132
2133 /* seems analog CD is not working */
2134 static struct hda_input_mux alc880_lg_capture_source = {
2135 .num_items = 3,
2136 .items = {
2137 { "Mic", 0x1 },
2138 { "Line", 0x5 },
2139 { "Internal Mic", 0x6 },
2140 },
2141 };
2142
2143 /* 2,4,6 channel modes */
2144 static struct hda_verb alc880_lg_ch2_init[] = {
2145 /* set line-in and mic-in to input */
2146 { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2147 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2148 { }
2149 };
2150
2151 static struct hda_verb alc880_lg_ch4_init[] = {
2152 /* set line-in to out and mic-in to input */
2153 { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2154 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2155 { }
2156 };
2157
2158 static struct hda_verb alc880_lg_ch6_init[] = {
2159 /* set line-in and mic-in to output */
2160 { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2161 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2162 { }
2163 };
2164
2165 static struct hda_channel_mode alc880_lg_ch_modes[3] = {
2166 { 2, alc880_lg_ch2_init },
2167 { 4, alc880_lg_ch4_init },
2168 { 6, alc880_lg_ch6_init },
2169 };
2170
2171 static struct snd_kcontrol_new alc880_lg_mixer[] = {
2172 HDA_CODEC_VOLUME("Front Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2173 HDA_BIND_MUTE("Front Playback Switch", 0x0f, 2, HDA_INPUT),
2174 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2175 HDA_BIND_MUTE("Surround Playback Switch", 0x0c, 2, HDA_INPUT),
2176 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
2177 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
2178 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
2179 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
2180 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2181 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2182 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x06, HDA_INPUT),
2183 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x06, HDA_INPUT),
2184 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x07, HDA_INPUT),
2185 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x07, HDA_INPUT),
2186 {
2187 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2188 .name = "Channel Mode",
2189 .info = alc_ch_mode_info,
2190 .get = alc_ch_mode_get,
2191 .put = alc_ch_mode_put,
2192 },
2193 { } /* end */
2194 };
2195
2196 static struct hda_verb alc880_lg_init_verbs[] = {
2197 /* set capture source to mic-in */
2198 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2199 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2200 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2201 /* mute all amp mixer inputs */
2202 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
2203 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2204 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2205 /* line-in to input */
2206 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2207 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2208 /* built-in mic */
2209 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2210 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2211 /* speaker-out */
2212 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2213 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2214 /* mic-in to input */
2215 {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2216 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2217 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2218 /* HP-out */
2219 {0x13, AC_VERB_SET_CONNECT_SEL, 0x03},
2220 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2221 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2222 /* jack sense */
2223 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
2224 { }
2225 };
2226
2227 /* toggle speaker-output according to the hp-jack state */
2228 static void alc880_lg_automute(struct hda_codec *codec)
2229 {
2230 unsigned int present;
2231 unsigned char bits;
2232
2233 present = snd_hda_codec_read(codec, 0x1b, 0,
2234 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2235 bits = present ? HDA_AMP_MUTE : 0;
2236 snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
2237 HDA_AMP_MUTE, bits);
2238 }
2239
2240 static void alc880_lg_unsol_event(struct hda_codec *codec, unsigned int res)
2241 {
2242 /* Looks like the unsol event is incompatible with the standard
2243 * definition. 4bit tag is placed at 28 bit!
2244 */
2245 if ((res >> 28) == 0x01)
2246 alc880_lg_automute(codec);
2247 }
2248
2249 /*
2250 * LG LW20
2251 *
2252 * Pin assignment:
2253 * Speaker-out: 0x14
2254 * Mic-In: 0x18
2255 * Built-in Mic-In: 0x19
2256 * Line-In: 0x1b
2257 * HP-Out: 0x1a
2258 * SPDIF-Out: 0x1e
2259 */
2260
2261 static struct hda_input_mux alc880_lg_lw_capture_source = {
2262 .num_items = 3,
2263 .items = {
2264 { "Mic", 0x0 },
2265 { "Internal Mic", 0x1 },
2266 { "Line In", 0x2 },
2267 },
2268 };
2269
2270 #define alc880_lg_lw_modes alc880_threestack_modes
2271
2272 static struct snd_kcontrol_new alc880_lg_lw_mixer[] = {
2273 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2274 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2275 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2276 HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
2277 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2278 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2279 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2280 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2281 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2282 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2283 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2284 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2285 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
2286 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
2287 {
2288 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2289 .name = "Channel Mode",
2290 .info = alc_ch_mode_info,
2291 .get = alc_ch_mode_get,
2292 .put = alc_ch_mode_put,
2293 },
2294 { } /* end */
2295 };
2296
2297 static struct hda_verb alc880_lg_lw_init_verbs[] = {
2298 {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2299 {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
2300 {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
2301
2302 /* set capture source to mic-in */
2303 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2304 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2305 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2306 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2307 /* speaker-out */
2308 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2309 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2310 /* HP-out */
2311 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2312 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2313 /* mic-in to input */
2314 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2315 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2316 /* built-in mic */
2317 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2318 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2319 /* jack sense */
2320 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
2321 { }
2322 };
2323
2324 /* toggle speaker-output according to the hp-jack state */
2325 static void alc880_lg_lw_automute(struct hda_codec *codec)
2326 {
2327 unsigned int present;
2328 unsigned char bits;
2329
2330 present = snd_hda_codec_read(codec, 0x1b, 0,
2331 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2332 bits = present ? HDA_AMP_MUTE : 0;
2333 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
2334 HDA_AMP_MUTE, bits);
2335 }
2336
2337 static void alc880_lg_lw_unsol_event(struct hda_codec *codec, unsigned int res)
2338 {
2339 /* Looks like the unsol event is incompatible with the standard
2340 * definition. 4bit tag is placed at 28 bit!
2341 */
2342 if ((res >> 28) == 0x01)
2343 alc880_lg_lw_automute(codec);
2344 }
2345
2346 static struct snd_kcontrol_new alc880_medion_rim_mixer[] = {
2347 HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2348 HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
2349 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2350 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2351 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2352 HDA_CODEC_MUTE("Internal Playback Switch", 0x0b, 0x1, HDA_INPUT),
2353 { } /* end */
2354 };
2355
2356 static struct hda_input_mux alc880_medion_rim_capture_source = {
2357 .num_items = 2,
2358 .items = {
2359 { "Mic", 0x0 },
2360 { "Internal Mic", 0x1 },
2361 },
2362 };
2363
2364 static struct hda_verb alc880_medion_rim_init_verbs[] = {
2365 {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2366
2367 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2368 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2369
2370 /* Mic1 (rear panel) pin widget for input and vref at 80% */
2371 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2372 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2373 /* Mic2 (as headphone out) for HP output */
2374 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2375 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2376 /* Internal Speaker */
2377 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2378 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2379
2380 {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2381 {0x20, AC_VERB_SET_PROC_COEF, 0x3060},
2382
2383 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2384 { }
2385 };
2386
2387 /* toggle speaker-output according to the hp-jack state */
2388 static void alc880_medion_rim_automute(struct hda_codec *codec)
2389 {
2390 unsigned int present;
2391 unsigned char bits;
2392
2393 present = snd_hda_codec_read(codec, 0x14, 0,
2394 AC_VERB_GET_PIN_SENSE, 0)
2395 & AC_PINSENSE_PRESENCE;
2396 bits = present ? HDA_AMP_MUTE : 0;
2397 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
2398 HDA_AMP_MUTE, bits);
2399 if (present)
2400 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 0);
2401 else
2402 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 2);
2403 }
2404
2405 static void alc880_medion_rim_unsol_event(struct hda_codec *codec,
2406 unsigned int res)
2407 {
2408 /* Looks like the unsol event is incompatible with the standard
2409 * definition. 4bit tag is placed at 28 bit!
2410 */
2411 if ((res >> 28) == ALC880_HP_EVENT)
2412 alc880_medion_rim_automute(codec);
2413 }
2414
2415 #ifdef CONFIG_SND_HDA_POWER_SAVE
2416 static struct hda_amp_list alc880_loopbacks[] = {
2417 { 0x0b, HDA_INPUT, 0 },
2418 { 0x0b, HDA_INPUT, 1 },
2419 { 0x0b, HDA_INPUT, 2 },
2420 { 0x0b, HDA_INPUT, 3 },
2421 { 0x0b, HDA_INPUT, 4 },
2422 { } /* end */
2423 };
2424
2425 static struct hda_amp_list alc880_lg_loopbacks[] = {
2426 { 0x0b, HDA_INPUT, 1 },
2427 { 0x0b, HDA_INPUT, 6 },
2428 { 0x0b, HDA_INPUT, 7 },
2429 { } /* end */
2430 };
2431 #endif
2432
2433 /*
2434 * Common callbacks
2435 */
2436
2437 static int alc_init(struct hda_codec *codec)
2438 {
2439 struct alc_spec *spec = codec->spec;
2440 unsigned int i;
2441
2442 alc_fix_pll(codec);
2443
2444 for (i = 0; i < spec->num_init_verbs; i++)
2445 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2446
2447 if (spec->init_hook)
2448 spec->init_hook(codec);
2449
2450 return 0;
2451 }
2452
2453 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2454 {
2455 struct alc_spec *spec = codec->spec;
2456
2457 if (spec->unsol_event)
2458 spec->unsol_event(codec, res);
2459 }
2460
2461 #ifdef CONFIG_SND_HDA_POWER_SAVE
2462 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2463 {
2464 struct alc_spec *spec = codec->spec;
2465 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2466 }
2467 #endif
2468
2469 /*
2470 * Analog playback callbacks
2471 */
2472 static int alc880_playback_pcm_open(struct hda_pcm_stream *hinfo,
2473 struct hda_codec *codec,
2474 struct snd_pcm_substream *substream)
2475 {
2476 struct alc_spec *spec = codec->spec;
2477 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2478 hinfo);
2479 }
2480
2481 static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2482 struct hda_codec *codec,
2483 unsigned int stream_tag,
2484 unsigned int format,
2485 struct snd_pcm_substream *substream)
2486 {
2487 struct alc_spec *spec = codec->spec;
2488 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2489 stream_tag, format, substream);
2490 }
2491
2492 static int alc880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2493 struct hda_codec *codec,
2494 struct snd_pcm_substream *substream)
2495 {
2496 struct alc_spec *spec = codec->spec;
2497 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2498 }
2499
2500 /*
2501 * Digital out
2502 */
2503 static int alc880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2504 struct hda_codec *codec,
2505 struct snd_pcm_substream *substream)
2506 {
2507 struct alc_spec *spec = codec->spec;
2508 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2509 }
2510
2511 static int alc880_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2512 struct hda_codec *codec,
2513 unsigned int stream_tag,
2514 unsigned int format,
2515 struct snd_pcm_substream *substream)
2516 {
2517 struct alc_spec *spec = codec->spec;
2518 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2519 stream_tag, format, substream);
2520 }
2521
2522 static int alc880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2523 struct hda_codec *codec,
2524 struct snd_pcm_substream *substream)
2525 {
2526 struct alc_spec *spec = codec->spec;
2527 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2528 }
2529
2530 /*
2531 * Analog capture
2532 */
2533 static int alc880_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2534 struct hda_codec *codec,
2535 unsigned int stream_tag,
2536 unsigned int format,
2537 struct snd_pcm_substream *substream)
2538 {
2539 struct alc_spec *spec = codec->spec;
2540
2541 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
2542 stream_tag, 0, format);
2543 return 0;
2544 }
2545
2546 static int alc880_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2547 struct hda_codec *codec,
2548 struct snd_pcm_substream *substream)
2549 {
2550 struct alc_spec *spec = codec->spec;
2551
2552 snd_hda_codec_cleanup_stream(codec,
2553 spec->adc_nids[substream->number + 1]);
2554 return 0;
2555 }
2556
2557
2558 /*
2559 */
2560 static struct hda_pcm_stream alc880_pcm_analog_playback = {
2561 .substreams = 1,
2562 .channels_min = 2,
2563 .channels_max = 8,
2564 /* NID is set in alc_build_pcms */
2565 .ops = {
2566 .open = alc880_playback_pcm_open,
2567 .prepare = alc880_playback_pcm_prepare,
2568 .cleanup = alc880_playback_pcm_cleanup
2569 },
2570 };
2571
2572 static struct hda_pcm_stream alc880_pcm_analog_capture = {
2573 .substreams = 1,
2574 .channels_min = 2,
2575 .channels_max = 2,
2576 /* NID is set in alc_build_pcms */
2577 };
2578
2579 static struct hda_pcm_stream alc880_pcm_analog_alt_playback = {
2580 .substreams = 1,
2581 .channels_min = 2,
2582 .channels_max = 2,
2583 /* NID is set in alc_build_pcms */
2584 };
2585
2586 static struct hda_pcm_stream alc880_pcm_analog_alt_capture = {
2587 .substreams = 2, /* can be overridden */
2588 .channels_min = 2,
2589 .channels_max = 2,
2590 /* NID is set in alc_build_pcms */
2591 .ops = {
2592 .prepare = alc880_alt_capture_pcm_prepare,
2593 .cleanup = alc880_alt_capture_pcm_cleanup
2594 },
2595 };
2596
2597 static struct hda_pcm_stream alc880_pcm_digital_playback = {
2598 .substreams = 1,
2599 .channels_min = 2,
2600 .channels_max = 2,
2601 /* NID is set in alc_build_pcms */
2602 .ops = {
2603 .open = alc880_dig_playback_pcm_open,
2604 .close = alc880_dig_playback_pcm_close,
2605 .prepare = alc880_dig_playback_pcm_prepare
2606 },
2607 };
2608
2609 static struct hda_pcm_stream alc880_pcm_digital_capture = {
2610 .substreams = 1,
2611 .channels_min = 2,
2612 .channels_max = 2,
2613 /* NID is set in alc_build_pcms */
2614 };
2615
2616 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
2617 static struct hda_pcm_stream alc_pcm_null_stream = {
2618 .substreams = 0,
2619 .channels_min = 0,
2620 .channels_max = 0,
2621 };
2622
2623 static int alc_build_pcms(struct hda_codec *codec)
2624 {
2625 struct alc_spec *spec = codec->spec;
2626 struct hda_pcm *info = spec->pcm_rec;
2627 int i;
2628
2629 codec->num_pcms = 1;
2630 codec->pcm_info = info;
2631
2632 info->name = spec->stream_name_analog;
2633 if (spec->stream_analog_playback) {
2634 snd_assert(spec->multiout.dac_nids, return -EINVAL);
2635 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
2636 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2637 }
2638 if (spec->stream_analog_capture) {
2639 snd_assert(spec->adc_nids, return -EINVAL);
2640 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
2641 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2642 }
2643
2644 if (spec->channel_mode) {
2645 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2646 for (i = 0; i < spec->num_channel_mode; i++) {
2647 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2648 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2649 }
2650 }
2651 }
2652
2653 /* SPDIF for stream index #1 */
2654 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2655 codec->num_pcms = 2;
2656 info = spec->pcm_rec + 1;
2657 info->name = spec->stream_name_digital;
2658 info->pcm_type = HDA_PCM_TYPE_SPDIF;
2659 if (spec->multiout.dig_out_nid &&
2660 spec->stream_digital_playback) {
2661 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
2662 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2663 }
2664 if (spec->dig_in_nid &&
2665 spec->stream_digital_capture) {
2666 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_digital_capture);
2667 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2668 }
2669 }
2670
2671 /* If the use of more than one ADC is requested for the current
2672 * model, configure a second analog capture-only PCM.
2673 */
2674 /* Additional Analaog capture for index #2 */
2675 if ((spec->alt_dac_nid && spec->stream_analog_alt_playback) ||
2676 (spec->num_adc_nids > 1 && spec->stream_analog_alt_capture)) {
2677 codec->num_pcms = 3;
2678 info = spec->pcm_rec + 2;
2679 info->name = spec->stream_name_analog;
2680 if (spec->alt_dac_nid) {
2681 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2682 *spec->stream_analog_alt_playback;
2683 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2684 spec->alt_dac_nid;
2685 } else {
2686 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2687 alc_pcm_null_stream;
2688 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2689 }
2690 if (spec->num_adc_nids > 1) {
2691 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2692 *spec->stream_analog_alt_capture;
2693 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2694 spec->adc_nids[1];
2695 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2696 spec->num_adc_nids - 1;
2697 } else {
2698 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2699 alc_pcm_null_stream;
2700 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
2701 }
2702 }
2703
2704 return 0;
2705 }
2706
2707 static void alc_free(struct hda_codec *codec)
2708 {
2709 struct alc_spec *spec = codec->spec;
2710 unsigned int i;
2711
2712 if (!spec)
2713 return;
2714
2715 if (spec->kctl_alloc) {
2716 for (i = 0; i < spec->num_kctl_used; i++)
2717 kfree(spec->kctl_alloc[i].name);
2718 kfree(spec->kctl_alloc);
2719 }
2720 kfree(spec);
2721 codec->spec = NULL; /* to be sure */
2722 }
2723
2724 /*
2725 */
2726 static struct hda_codec_ops alc_patch_ops = {
2727 .build_controls = alc_build_controls,
2728 .build_pcms = alc_build_pcms,
2729 .init = alc_init,
2730 .free = alc_free,
2731 .unsol_event = alc_unsol_event,
2732 #ifdef CONFIG_SND_HDA_POWER_SAVE
2733 .check_power_status = alc_check_power_status,
2734 #endif
2735 };
2736
2737
2738 /*
2739 * Test configuration for debugging
2740 *
2741 * Almost all inputs/outputs are enabled. I/O pins can be configured via
2742 * enum controls.
2743 */
2744 #ifdef CONFIG_SND_DEBUG
2745 static hda_nid_t alc880_test_dac_nids[4] = {
2746 0x02, 0x03, 0x04, 0x05
2747 };
2748
2749 static struct hda_input_mux alc880_test_capture_source = {
2750 .num_items = 7,
2751 .items = {
2752 { "In-1", 0x0 },
2753 { "In-2", 0x1 },
2754 { "In-3", 0x2 },
2755 { "In-4", 0x3 },
2756 { "CD", 0x4 },
2757 { "Front", 0x5 },
2758 { "Surround", 0x6 },
2759 },
2760 };
2761
2762 static struct hda_channel_mode alc880_test_modes[4] = {
2763 { 2, NULL },
2764 { 4, NULL },
2765 { 6, NULL },
2766 { 8, NULL },
2767 };
2768
2769 static int alc_test_pin_ctl_info(struct snd_kcontrol *kcontrol,
2770 struct snd_ctl_elem_info *uinfo)
2771 {
2772 static char *texts[] = {
2773 "N/A", "Line Out", "HP Out",
2774 "In Hi-Z", "In 50%", "In Grd", "In 80%", "In 100%"
2775 };
2776 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2777 uinfo->count = 1;
2778 uinfo->value.enumerated.items = 8;
2779 if (uinfo->value.enumerated.item >= 8)
2780 uinfo->value.enumerated.item = 7;
2781 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2782 return 0;
2783 }
2784
2785 static int alc_test_pin_ctl_get(struct snd_kcontrol *kcontrol,
2786 struct snd_ctl_elem_value *ucontrol)
2787 {
2788 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2789 hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2790 unsigned int pin_ctl, item = 0;
2791
2792 pin_ctl = snd_hda_codec_read(codec, nid, 0,
2793 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
2794 if (pin_ctl & AC_PINCTL_OUT_EN) {
2795 if (pin_ctl & AC_PINCTL_HP_EN)
2796 item = 2;
2797 else
2798 item = 1;
2799 } else if (pin_ctl & AC_PINCTL_IN_EN) {
2800 switch (pin_ctl & AC_PINCTL_VREFEN) {
2801 case AC_PINCTL_VREF_HIZ: item = 3; break;
2802 case AC_PINCTL_VREF_50: item = 4; break;
2803 case AC_PINCTL_VREF_GRD: item = 5; break;
2804 case AC_PINCTL_VREF_80: item = 6; break;
2805 case AC_PINCTL_VREF_100: item = 7; break;
2806 }
2807 }
2808 ucontrol->value.enumerated.item[0] = item;
2809 return 0;
2810 }
2811
2812 static int alc_test_pin_ctl_put(struct snd_kcontrol *kcontrol,
2813 struct snd_ctl_elem_value *ucontrol)
2814 {
2815 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2816 hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2817 static unsigned int ctls[] = {
2818 0, AC_PINCTL_OUT_EN, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN,
2819 AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ,
2820 AC_PINCTL_IN_EN | AC_PINCTL_VREF_50,
2821 AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD,
2822 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80,
2823 AC_PINCTL_IN_EN | AC_PINCTL_VREF_100,
2824 };
2825 unsigned int old_ctl, new_ctl;
2826
2827 old_ctl = snd_hda_codec_read(codec, nid, 0,
2828 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
2829 new_ctl = ctls[ucontrol->value.enumerated.item[0]];
2830 if (old_ctl != new_ctl) {
2831 int val;
2832 snd_hda_codec_write_cache(codec, nid, 0,
2833 AC_VERB_SET_PIN_WIDGET_CONTROL,
2834 new_ctl);
2835 val = ucontrol->value.enumerated.item[0] >= 3 ?
2836 HDA_AMP_MUTE : 0;
2837 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
2838 HDA_AMP_MUTE, val);
2839 return 1;
2840 }
2841 return 0;
2842 }
2843
2844 static int alc_test_pin_src_info(struct snd_kcontrol *kcontrol,
2845 struct snd_ctl_elem_info *uinfo)
2846 {
2847 static char *texts[] = {
2848 "Front", "Surround", "CLFE", "Side"
2849 };
2850 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2851 uinfo->count = 1;
2852 uinfo->value.enumerated.items = 4;
2853 if (uinfo->value.enumerated.item >= 4)
2854 uinfo->value.enumerated.item = 3;
2855 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2856 return 0;
2857 }
2858
2859 static int alc_test_pin_src_get(struct snd_kcontrol *kcontrol,
2860 struct snd_ctl_elem_value *ucontrol)
2861 {
2862 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2863 hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2864 unsigned int sel;
2865
2866 sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0);
2867 ucontrol->value.enumerated.item[0] = sel & 3;
2868 return 0;
2869 }
2870
2871 static int alc_test_pin_src_put(struct snd_kcontrol *kcontrol,
2872 struct snd_ctl_elem_value *ucontrol)
2873 {
2874 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2875 hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2876 unsigned int sel;
2877
2878 sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0) & 3;
2879 if (ucontrol->value.enumerated.item[0] != sel) {
2880 sel = ucontrol->value.enumerated.item[0] & 3;
2881 snd_hda_codec_write_cache(codec, nid, 0,
2882 AC_VERB_SET_CONNECT_SEL, sel);
2883 return 1;
2884 }
2885 return 0;
2886 }
2887
2888 #define PIN_CTL_TEST(xname,nid) { \
2889 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2890 .name = xname, \
2891 .info = alc_test_pin_ctl_info, \
2892 .get = alc_test_pin_ctl_get, \
2893 .put = alc_test_pin_ctl_put, \
2894 .private_value = nid \
2895 }
2896
2897 #define PIN_SRC_TEST(xname,nid) { \
2898 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2899 .name = xname, \
2900 .info = alc_test_pin_src_info, \
2901 .get = alc_test_pin_src_get, \
2902 .put = alc_test_pin_src_put, \
2903 .private_value = nid \
2904 }
2905
2906 static struct snd_kcontrol_new alc880_test_mixer[] = {
2907 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2908 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2909 HDA_CODEC_VOLUME("CLFE Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
2910 HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2911 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2912 HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2913 HDA_BIND_MUTE("CLFE Playback Switch", 0x0e, 2, HDA_INPUT),
2914 HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
2915 PIN_CTL_TEST("Front Pin Mode", 0x14),
2916 PIN_CTL_TEST("Surround Pin Mode", 0x15),
2917 PIN_CTL_TEST("CLFE Pin Mode", 0x16),
2918 PIN_CTL_TEST("Side Pin Mode", 0x17),
2919 PIN_CTL_TEST("In-1 Pin Mode", 0x18),
2920 PIN_CTL_TEST("In-2 Pin Mode", 0x19),
2921 PIN_CTL_TEST("In-3 Pin Mode", 0x1a),
2922 PIN_CTL_TEST("In-4 Pin Mode", 0x1b),
2923 PIN_SRC_TEST("In-1 Pin Source", 0x18),
2924 PIN_SRC_TEST("In-2 Pin Source", 0x19),
2925 PIN_SRC_TEST("In-3 Pin Source", 0x1a),
2926 PIN_SRC_TEST("In-4 Pin Source", 0x1b),
2927 HDA_CODEC_VOLUME("In-1 Playback Volume", 0x0b, 0x0, HDA_INPUT),
2928 HDA_CODEC_MUTE("In-1 Playback Switch", 0x0b, 0x0, HDA_INPUT),
2929 HDA_CODEC_VOLUME("In-2 Playback Volume", 0x0b, 0x1, HDA_INPUT),
2930 HDA_CODEC_MUTE("In-2 Playback Switch", 0x0b, 0x1, HDA_INPUT),
2931 HDA_CODEC_VOLUME("In-3 Playback Volume", 0x0b, 0x2, HDA_INPUT),
2932 HDA_CODEC_MUTE("In-3 Playback Switch", 0x0b, 0x2, HDA_INPUT),
2933 HDA_CODEC_VOLUME("In-4 Playback Volume", 0x0b, 0x3, HDA_INPUT),
2934 HDA_CODEC_MUTE("In-4 Playback Switch", 0x0b, 0x3, HDA_INPUT),
2935 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x4, HDA_INPUT),
2936 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x4, HDA_INPUT),
2937 {
2938 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2939 .name = "Channel Mode",
2940 .info = alc_ch_mode_info,
2941 .get = alc_ch_mode_get,
2942 .put = alc_ch_mode_put,
2943 },
2944 { } /* end */
2945 };
2946
2947 static struct hda_verb alc880_test_init_verbs[] = {
2948 /* Unmute inputs of 0x0c - 0x0f */
2949 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2950 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2951 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2952 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2953 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2954 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2955 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2956 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2957 /* Vol output for 0x0c-0x0f */
2958 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2959 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2960 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2961 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2962 /* Set output pins 0x14-0x17 */
2963 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2964 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2965 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2966 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2967 /* Unmute output pins 0x14-0x17 */
2968 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2969 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2970 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2971 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2972 /* Set input pins 0x18-0x1c */
2973 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2974 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2975 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2976 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2977 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2978 /* Mute input pins 0x18-0x1b */
2979 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2980 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2981 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2982 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2983 /* ADC set up */
2984 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2985 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
2986 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2987 {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
2988 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2989 {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
2990 /* Analog input/passthru */
2991 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2992 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2993 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2994 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2995 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2996 { }
2997 };
2998 #endif
2999
3000 /*
3001 */
3002
3003 static const char *alc880_models[ALC880_MODEL_LAST] = {
3004 [ALC880_3ST] = "3stack",
3005 [ALC880_TCL_S700] = "tcl",
3006 [ALC880_3ST_DIG] = "3stack-digout",
3007 [ALC880_CLEVO] = "clevo",
3008 [ALC880_5ST] = "5stack",
3009 [ALC880_5ST_DIG] = "5stack-digout",
3010 [ALC880_W810] = "w810",
3011 [ALC880_Z71V] = "z71v",
3012 [ALC880_6ST] = "6stack",
3013 [ALC880_6ST_DIG] = "6stack-digout",
3014 [ALC880_ASUS] = "asus",
3015 [ALC880_ASUS_W1V] = "asus-w1v",
3016 [ALC880_ASUS_DIG] = "asus-dig",
3017 [ALC880_ASUS_DIG2] = "asus-dig2",
3018 [ALC880_UNIWILL_DIG] = "uniwill",
3019 [ALC880_UNIWILL_P53] = "uniwill-p53",
3020 [ALC880_FUJITSU] = "fujitsu",
3021 [ALC880_F1734] = "F1734",
3022 [ALC880_LG] = "lg",
3023 [ALC880_LG_LW] = "lg-lw",
3024 [ALC880_MEDION_RIM] = "medion",
3025 #ifdef CONFIG_SND_DEBUG
3026 [ALC880_TEST] = "test",
3027 #endif
3028 [ALC880_AUTO] = "auto",
3029 };
3030
3031 static struct snd_pci_quirk alc880_cfg_tbl[] = {
3032 SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_W810),
3033 SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_5ST_DIG),
3034 SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_6ST),
3035 SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_3ST_DIG),
3036 SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_6ST_DIG),
3037 SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_6ST_DIG),
3038 SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_6ST_DIG),
3039 SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_3ST_DIG),
3040 SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_3ST),
3041 SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_6ST_DIG),
3042 SND_PCI_QUIRK(0x103c, 0x2a09, "HP", ALC880_5ST),
3043 SND_PCI_QUIRK(0x1043, 0x10b3, "ASUS W1V", ALC880_ASUS_W1V),
3044 SND_PCI_QUIRK(0x1043, 0x10c2, "ASUS W6A", ALC880_ASUS_DIG),
3045 SND_PCI_QUIRK(0x1043, 0x10c3, "ASUS Wxx", ALC880_ASUS_DIG),
3046 SND_PCI_QUIRK(0x1043, 0x1113, "ASUS", ALC880_ASUS_DIG),
3047 SND_PCI_QUIRK(0x1043, 0x1123, "ASUS", ALC880_ASUS_DIG),
3048 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS", ALC880_ASUS_DIG),
3049 SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_Z71V),
3050 /* SND_PCI_QUIRK(0x1043, 0x1964, "ASUS", ALC880_ASUS_DIG), */
3051 SND_PCI_QUIRK(0x1043, 0x1973, "ASUS", ALC880_ASUS_DIG),
3052 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS", ALC880_ASUS_DIG),
3053 SND_PCI_QUIRK(0x1043, 0x814e, "ASUS P5GD1 w/SPDIF", ALC880_6ST_DIG),
3054 SND_PCI_QUIRK(0x1043, 0x8181, "ASUS P4GPL", ALC880_ASUS_DIG),
3055 SND_PCI_QUIRK(0x1043, 0x8196, "ASUS P5GD1", ALC880_6ST),
3056 SND_PCI_QUIRK(0x1043, 0x81b4, "ASUS", ALC880_6ST),
3057 SND_PCI_QUIRK(0x1043, 0, "ASUS", ALC880_ASUS), /* default ASUS */
3058 SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_3ST),
3059 SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_3ST),
3060 SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_5ST),
3061 SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_5ST),
3062 SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_5ST),
3063 SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_6ST_DIG),
3064 SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_6ST_DIG),
3065 SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_6ST_DIG),
3066 SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_6ST_DIG),
3067 SND_PCI_QUIRK(0x1558, 0x0520, "Clevo m520G", ALC880_CLEVO),
3068 SND_PCI_QUIRK(0x1558, 0x0660, "Clevo m655n", ALC880_CLEVO),
3069 SND_PCI_QUIRK(0x1558, 0x5401, "ASUS", ALC880_ASUS_DIG2),
3070 SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_5ST_DIG),
3071 SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_UNIWILL_DIG),
3072 SND_PCI_QUIRK(0x1584, 0x9054, "Uniwlll", ALC880_F1734),
3073 SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_UNIWILL),
3074 SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_UNIWILL_P53),
3075 SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_W810),
3076 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_MEDION_RIM),
3077 SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_5ST_DIG),
3078 SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_5ST_DIG),
3079 SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_F1734),
3080 SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FUJITSU),
3081 SND_PCI_QUIRK(0x1734, 0x10ac, "FSC", ALC880_UNIWILL),
3082 SND_PCI_QUIRK(0x1734, 0x10b0, "Fujitsu", ALC880_FUJITSU),
3083 SND_PCI_QUIRK(0x1854, 0x0018, "LG LW20", ALC880_LG_LW),
3084 SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_LG),
3085 SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_LG),
3086 SND_PCI_QUIRK(0x1854, 0x0077, "LG LW25", ALC880_LG_LW),
3087 SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_TCL_S700),
3088 SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_6ST_DIG), /* broken BIOS */
3089 SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_6ST_DIG),
3090 SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_5ST_DIG),
3091 SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_5ST_DIG),
3092 SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_5ST_DIG),
3093 SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_3ST_DIG),
3094 SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_5ST_DIG),
3095 SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_3ST_DIG),
3096 SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_3ST_DIG),
3097 SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_5ST_DIG),
3098 SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_5ST_DIG),
3099 SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_5ST_DIG),
3100 SND_PCI_QUIRK(0x8086, 0, "Intel mobo", ALC880_3ST), /* default Intel */
3101 SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_5ST_DIG),
3102 SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_6ST_DIG),
3103 {}
3104 };
3105
3106 /*
3107 * ALC880 codec presets
3108 */
3109 static struct alc_config_preset alc880_presets[] = {
3110 [ALC880_3ST] = {
3111 .mixers = { alc880_three_stack_mixer },
3112 .init_verbs = { alc880_volume_init_verbs,
3113 alc880_pin_3stack_init_verbs },
3114 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3115 .dac_nids = alc880_dac_nids,
3116 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3117 .channel_mode = alc880_threestack_modes,
3118 .need_dac_fix = 1,
3119 .input_mux = &alc880_capture_source,
3120 },
3121 [ALC880_3ST_DIG] = {
3122 .mixers = { alc880_three_stack_mixer },
3123 .init_verbs = { alc880_volume_init_verbs,
3124 alc880_pin_3stack_init_verbs },
3125 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3126 .dac_nids = alc880_dac_nids,
3127 .dig_out_nid = ALC880_DIGOUT_NID,
3128 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3129 .channel_mode = alc880_threestack_modes,
3130 .need_dac_fix = 1,
3131 .input_mux = &alc880_capture_source,
3132 },
3133 [ALC880_TCL_S700] = {
3134 .mixers = { alc880_tcl_s700_mixer },
3135 .init_verbs = { alc880_volume_init_verbs,
3136 alc880_pin_tcl_S700_init_verbs,
3137 alc880_gpio2_init_verbs },
3138 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3139 .dac_nids = alc880_dac_nids,
3140 .hp_nid = 0x03,
3141 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3142 .channel_mode = alc880_2_jack_modes,
3143 .input_mux = &alc880_capture_source,
3144 },
3145 [ALC880_5ST] = {
3146 .mixers = { alc880_three_stack_mixer,
3147 alc880_five_stack_mixer},
3148 .init_verbs = { alc880_volume_init_verbs,
3149 alc880_pin_5stack_init_verbs },
3150 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3151 .dac_nids = alc880_dac_nids,
3152 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
3153 .channel_mode = alc880_fivestack_modes,
3154 .input_mux = &alc880_capture_source,
3155 },
3156 [ALC880_5ST_DIG] = {
3157 .mixers = { alc880_three_stack_mixer,
3158 alc880_five_stack_mixer },
3159 .init_verbs = { alc880_volume_init_verbs,
3160 alc880_pin_5stack_init_verbs },
3161 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3162 .dac_nids = alc880_dac_nids,
3163 .dig_out_nid = ALC880_DIGOUT_NID,
3164 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
3165 .channel_mode = alc880_fivestack_modes,
3166 .input_mux = &alc880_capture_source,
3167 },
3168 [ALC880_6ST] = {
3169 .mixers = { alc880_six_stack_mixer },
3170 .init_verbs = { alc880_volume_init_verbs,
3171 alc880_pin_6stack_init_verbs },
3172 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
3173 .dac_nids = alc880_6st_dac_nids,
3174 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
3175 .channel_mode = alc880_sixstack_modes,
3176 .input_mux = &alc880_6stack_capture_source,
3177 },
3178 [ALC880_6ST_DIG] = {
3179 .mixers = { alc880_six_stack_mixer },
3180 .init_verbs = { alc880_volume_init_verbs,
3181 alc880_pin_6stack_init_verbs },
3182 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
3183 .dac_nids = alc880_6st_dac_nids,
3184 .dig_out_nid = ALC880_DIGOUT_NID,
3185 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
3186 .channel_mode = alc880_sixstack_modes,
3187 .input_mux = &alc880_6stack_capture_source,
3188 },
3189 [ALC880_W810] = {
3190 .mixers = { alc880_w810_base_mixer },
3191 .init_verbs = { alc880_volume_init_verbs,
3192 alc880_pin_w810_init_verbs,
3193 alc880_gpio2_init_verbs },
3194 .num_dacs = ARRAY_SIZE(alc880_w810_dac_nids),
3195 .dac_nids = alc880_w810_dac_nids,
3196 .dig_out_nid = ALC880_DIGOUT_NID,
3197 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
3198 .channel_mode = alc880_w810_modes,
3199 .input_mux = &alc880_capture_source,
3200 },
3201 [ALC880_Z71V] = {
3202 .mixers = { alc880_z71v_mixer },
3203 .init_verbs = { alc880_volume_init_verbs,
3204 alc880_pin_z71v_init_verbs },
3205 .num_dacs = ARRAY_SIZE(alc880_z71v_dac_nids),
3206 .dac_nids = alc880_z71v_dac_nids,
3207 .dig_out_nid = ALC880_DIGOUT_NID,
3208 .hp_nid = 0x03,
3209 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3210 .channel_mode = alc880_2_jack_modes,
3211 .input_mux = &alc880_capture_source,
3212 },
3213 [ALC880_F1734] = {
3214 .mixers = { alc880_f1734_mixer },
3215 .init_verbs = { alc880_volume_init_verbs,
3216 alc880_pin_f1734_init_verbs },
3217 .num_dacs = ARRAY_SIZE(alc880_f1734_dac_nids),
3218 .dac_nids = alc880_f1734_dac_nids,
3219 .hp_nid = 0x02,
3220 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3221 .channel_mode = alc880_2_jack_modes,
3222 .input_mux = &alc880_f1734_capture_source,
3223 .unsol_event = alc880_uniwill_p53_unsol_event,
3224 .init_hook = alc880_uniwill_p53_hp_automute,
3225 },
3226 [ALC880_ASUS] = {
3227 .mixers = { alc880_asus_mixer },
3228 .init_verbs = { alc880_volume_init_verbs,
3229 alc880_pin_asus_init_verbs,
3230 alc880_gpio1_init_verbs },
3231 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3232 .dac_nids = alc880_asus_dac_nids,
3233 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3234 .channel_mode = alc880_asus_modes,
3235 .need_dac_fix = 1,
3236 .input_mux = &alc880_capture_source,
3237 },
3238 [ALC880_ASUS_DIG] = {
3239 .mixers = { alc880_asus_mixer },
3240 .init_verbs = { alc880_volume_init_verbs,
3241 alc880_pin_asus_init_verbs,
3242 alc880_gpio1_init_verbs },
3243 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3244 .dac_nids = alc880_asus_dac_nids,
3245 .dig_out_nid = ALC880_DIGOUT_NID,
3246 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3247 .channel_mode = alc880_asus_modes,
3248 .need_dac_fix = 1,
3249 .input_mux = &alc880_capture_source,
3250 },
3251 [ALC880_ASUS_DIG2] = {
3252 .mixers = { alc880_asus_mixer },
3253 .init_verbs = { alc880_volume_init_verbs,
3254 alc880_pin_asus_init_verbs,
3255 alc880_gpio2_init_verbs }, /* use GPIO2 */
3256 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3257 .dac_nids = alc880_asus_dac_nids,
3258 .dig_out_nid = ALC880_DIGOUT_NID,
3259 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3260 .channel_mode = alc880_asus_modes,
3261 .need_dac_fix = 1,
3262 .input_mux = &alc880_capture_source,
3263 },
3264 [ALC880_ASUS_W1V] = {
3265 .mixers = { alc880_asus_mixer, alc880_asus_w1v_mixer },
3266 .init_verbs = { alc880_volume_init_verbs,
3267 alc880_pin_asus_init_verbs,
3268 alc880_gpio1_init_verbs },
3269 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3270 .dac_nids = alc880_asus_dac_nids,
3271 .dig_out_nid = ALC880_DIGOUT_NID,
3272 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3273 .channel_mode = alc880_asus_modes,
3274 .need_dac_fix = 1,
3275 .input_mux = &alc880_capture_source,
3276 },
3277 [ALC880_UNIWILL_DIG] = {
3278 .mixers = { alc880_asus_mixer, alc880_pcbeep_mixer },
3279 .init_verbs = { alc880_volume_init_verbs,
3280 alc880_pin_asus_init_verbs },
3281 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3282 .dac_nids = alc880_asus_dac_nids,
3283 .dig_out_nid = ALC880_DIGOUT_NID,
3284 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3285 .channel_mode = alc880_asus_modes,
3286 .need_dac_fix = 1,
3287 .input_mux = &alc880_capture_source,
3288 },
3289 [ALC880_UNIWILL] = {
3290 .mixers = { alc880_uniwill_mixer },
3291 .init_verbs = { alc880_volume_init_verbs,
3292 alc880_uniwill_init_verbs },
3293 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3294 .dac_nids = alc880_asus_dac_nids,
3295 .dig_out_nid = ALC880_DIGOUT_NID,
3296 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3297 .channel_mode = alc880_threestack_modes,
3298 .need_dac_fix = 1,
3299 .input_mux = &alc880_capture_source,
3300 .unsol_event = alc880_uniwill_unsol_event,
3301 .init_hook = alc880_uniwill_automute,
3302 },
3303 [ALC880_UNIWILL_P53] = {
3304 .mixers = { alc880_uniwill_p53_mixer },
3305 .init_verbs = { alc880_volume_init_verbs,
3306 alc880_uniwill_p53_init_verbs },
3307 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3308 .dac_nids = alc880_asus_dac_nids,
3309 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
3310 .channel_mode = alc880_threestack_modes,
3311 .input_mux = &alc880_capture_source,
3312 .unsol_event = alc880_uniwill_p53_unsol_event,
3313 .init_hook = alc880_uniwill_p53_hp_automute,
3314 },
3315 [ALC880_FUJITSU] = {
3316 .mixers = { alc880_fujitsu_mixer,
3317 alc880_pcbeep_mixer, },
3318 .init_verbs = { alc880_volume_init_verbs,
3319 alc880_uniwill_p53_init_verbs,
3320 alc880_beep_init_verbs },
3321 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3322 .dac_nids = alc880_dac_nids,
3323 .dig_out_nid = ALC880_DIGOUT_NID,
3324 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3325 .channel_mode = alc880_2_jack_modes,
3326 .input_mux = &alc880_capture_source,
3327 .unsol_event = alc880_uniwill_p53_unsol_event,
3328 .init_hook = alc880_uniwill_p53_hp_automute,
3329 },
3330 [ALC880_CLEVO] = {
3331 .mixers = { alc880_three_stack_mixer },
3332 .init_verbs = { alc880_volume_init_verbs,
3333 alc880_pin_clevo_init_verbs },
3334 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3335 .dac_nids = alc880_dac_nids,
3336 .hp_nid = 0x03,
3337 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3338 .channel_mode = alc880_threestack_modes,
3339 .need_dac_fix = 1,
3340 .input_mux = &alc880_capture_source,
3341 },
3342 [ALC880_LG] = {
3343 .mixers = { alc880_lg_mixer },
3344 .init_verbs = { alc880_volume_init_verbs,
3345 alc880_lg_init_verbs },
3346 .num_dacs = ARRAY_SIZE(alc880_lg_dac_nids),
3347 .dac_nids = alc880_lg_dac_nids,
3348 .dig_out_nid = ALC880_DIGOUT_NID,
3349 .num_channel_mode = ARRAY_SIZE(alc880_lg_ch_modes),
3350 .channel_mode = alc880_lg_ch_modes,
3351 .need_dac_fix = 1,
3352 .input_mux = &alc880_lg_capture_source,
3353 .unsol_event = alc880_lg_unsol_event,
3354 .init_hook = alc880_lg_automute,
3355 #ifdef CONFIG_SND_HDA_POWER_SAVE
3356 .loopbacks = alc880_lg_loopbacks,
3357 #endif
3358 },
3359 [ALC880_LG_LW] = {
3360 .mixers = { alc880_lg_lw_mixer },
3361 .init_verbs = { alc880_volume_init_verbs,
3362 alc880_lg_lw_init_verbs },
3363 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3364 .dac_nids = alc880_dac_nids,
3365 .dig_out_nid = ALC880_DIGOUT_NID,
3366 .num_channel_mode = ARRAY_SIZE(alc880_lg_lw_modes),
3367 .channel_mode = alc880_lg_lw_modes,
3368 .input_mux = &alc880_lg_lw_capture_source,
3369 .unsol_event = alc880_lg_lw_unsol_event,
3370 .init_hook = alc880_lg_lw_automute,
3371 },
3372 [ALC880_MEDION_RIM] = {
3373 .mixers = { alc880_medion_rim_mixer },
3374 .init_verbs = { alc880_volume_init_verbs,
3375 alc880_medion_rim_init_verbs,
3376 alc_gpio2_init_verbs },
3377 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3378 .dac_nids = alc880_dac_nids,
3379 .dig_out_nid = ALC880_DIGOUT_NID,
3380 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3381 .channel_mode = alc880_2_jack_modes,
3382 .input_mux = &alc880_medion_rim_capture_source,
3383 .unsol_event = alc880_medion_rim_unsol_event,
3384 .init_hook = alc880_medion_rim_automute,
3385 },
3386 #ifdef CONFIG_SND_DEBUG
3387 [ALC880_TEST] = {
3388 .mixers = { alc880_test_mixer },
3389 .init_verbs = { alc880_test_init_verbs },
3390 .num_dacs = ARRAY_SIZE(alc880_test_dac_nids),
3391 .dac_nids = alc880_test_dac_nids,
3392 .dig_out_nid = ALC880_DIGOUT_NID,
3393 .num_channel_mode = ARRAY_SIZE(alc880_test_modes),
3394 .channel_mode = alc880_test_modes,
3395 .input_mux = &alc880_test_capture_source,
3396 },
3397 #endif
3398 };
3399
3400 /*
3401 * Automatic parse of I/O pins from the BIOS configuration
3402 */
3403
3404 #define NUM_CONTROL_ALLOC 32
3405 #define NUM_VERB_ALLOC 32
3406
3407 enum {
3408 ALC_CTL_WIDGET_VOL,
3409 ALC_CTL_WIDGET_MUTE,
3410 ALC_CTL_BIND_MUTE,
3411 };
3412 static struct snd_kcontrol_new alc880_control_templates[] = {
3413 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
3414 HDA_CODEC_MUTE(NULL, 0, 0, 0),
3415 HDA_BIND_MUTE(NULL, 0, 0, 0),
3416 };
3417
3418 /* add dynamic controls */
3419 static int add_control(struct alc_spec *spec, int type, const char *name,
3420 unsigned long val)
3421 {
3422 struct snd_kcontrol_new *knew;
3423
3424 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
3425 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
3426
3427 /* array + terminator */
3428 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL);
3429 if (!knew)
3430 return -ENOMEM;
3431 if (spec->kctl_alloc) {
3432 memcpy(knew, spec->kctl_alloc,
3433 sizeof(*knew) * spec->num_kctl_alloc);
3434 kfree(spec->kctl_alloc);
3435 }
3436 spec->kctl_alloc = knew;
3437 spec->num_kctl_alloc = num;
3438 }
3439
3440 knew = &spec->kctl_alloc[spec->num_kctl_used];
3441 *knew = alc880_control_templates[type];
3442 knew->name = kstrdup(name, GFP_KERNEL);
3443 if (!knew->name)
3444 return -ENOMEM;
3445 knew->private_value = val;
3446 spec->num_kctl_used++;
3447 return 0;
3448 }
3449
3450 #define alc880_is_fixed_pin(nid) ((nid) >= 0x14 && (nid) <= 0x17)
3451 #define alc880_fixed_pin_idx(nid) ((nid) - 0x14)
3452 #define alc880_is_multi_pin(nid) ((nid) >= 0x18)
3453 #define alc880_multi_pin_idx(nid) ((nid) - 0x18)
3454 #define alc880_is_input_pin(nid) ((nid) >= 0x18)
3455 #define alc880_input_pin_idx(nid) ((nid) - 0x18)
3456 #define alc880_idx_to_dac(nid) ((nid) + 0x02)
3457 #define alc880_dac_to_idx(nid) ((nid) - 0x02)
3458 #define alc880_idx_to_mixer(nid) ((nid) + 0x0c)
3459 #define alc880_idx_to_selector(nid) ((nid) + 0x10)
3460 #define ALC880_PIN_CD_NID 0x1c
3461
3462 /* fill in the dac_nids table from the parsed pin configuration */
3463 static int alc880_auto_fill_dac_nids(struct alc_spec *spec,
3464 const struct auto_pin_cfg *cfg)
3465 {
3466 hda_nid_t nid;
3467 int assigned[4];
3468 int i, j;
3469
3470 memset(assigned, 0, sizeof(assigned));
3471 spec->multiout.dac_nids = spec->private_dac_nids;
3472
3473 /* check the pins hardwired to audio widget */
3474 for (i = 0; i < cfg->line_outs; i++) {
3475 nid = cfg->line_out_pins[i];
3476 if (alc880_is_fixed_pin(nid)) {
3477 int idx = alc880_fixed_pin_idx(nid);
3478 spec->multiout.dac_nids[i] = alc880_idx_to_dac(idx);
3479 assigned[idx] = 1;
3480 }
3481 }
3482 /* left pins can be connect to any audio widget */
3483 for (i = 0; i < cfg->line_outs; i++) {
3484 nid = cfg->line_out_pins[i];
3485 if (alc880_is_fixed_pin(nid))
3486 continue;
3487 /* search for an empty channel */
3488 for (j = 0; j < cfg->line_outs; j++) {
3489 if (!assigned[j]) {
3490 spec->multiout.dac_nids[i] =
3491 alc880_idx_to_dac(j);
3492 assigned[j] = 1;
3493 break;
3494 }
3495 }
3496 }
3497 spec->multiout.num_dacs = cfg->line_outs;
3498 return 0;
3499 }
3500
3501 /* add playback controls from the parsed DAC table */
3502 static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
3503 const struct auto_pin_cfg *cfg)
3504 {
3505 char name[32];
3506 static const char *chname[4] = {
3507 "Front", "Surround", NULL /*CLFE*/, "Side"
3508 };
3509 hda_nid_t nid;
3510 int i, err;
3511
3512 for (i = 0; i < cfg->line_outs; i++) {
3513 if (!spec->multiout.dac_nids[i])
3514 continue;
3515 nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i]));
3516 if (i == 2) {
3517 /* Center/LFE */
3518 err = add_control(spec, ALC_CTL_WIDGET_VOL,
3519 "Center Playback Volume",
3520 HDA_COMPOSE_AMP_VAL(nid, 1, 0,
3521 HDA_OUTPUT));
3522 if (err < 0)
3523 return err;
3524 err = add_control(spec, ALC_CTL_WIDGET_VOL,
3525 "LFE Playback Volume",
3526 HDA_COMPOSE_AMP_VAL(nid, 2, 0,
3527 HDA_OUTPUT));
3528 if (err < 0)
3529 return err;
3530 err = add_control(spec, ALC_CTL_BIND_MUTE,
3531 "Center Playback Switch",
3532 HDA_COMPOSE_AMP_VAL(nid, 1, 2,
3533 HDA_INPUT));
3534 if (err < 0)
3535 return err;
3536 err = add_control(spec, ALC_CTL_BIND_MUTE,
3537 "LFE Playback Switch",
3538 HDA_COMPOSE_AMP_VAL(nid, 2, 2,
3539 HDA_INPUT));
3540 if (err < 0)
3541 return err;
3542 } else {
3543 sprintf(name, "%s Playback Volume", chname[i]);
3544 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3545 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3546 HDA_OUTPUT));
3547 if (err < 0)
3548 return err;
3549 sprintf(name, "%s Playback Switch", chname[i]);
3550 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
3551 HDA_COMPOSE_AMP_VAL(nid, 3, 2,
3552 HDA_INPUT));
3553 if (err < 0)
3554 return err;
3555 }
3556 }
3557 return 0;
3558 }
3559
3560 /* add playback controls for speaker and HP outputs */
3561 static int alc880_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
3562 const char *pfx)
3563 {
3564 hda_nid_t nid;
3565 int err;
3566 char name[32];
3567
3568 if (!pin)
3569 return 0;
3570
3571 if (alc880_is_fixed_pin(pin)) {
3572 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
3573 /* specify the DAC as the extra output */
3574 if (!spec->multiout.hp_nid)
3575 spec->multiout.hp_nid = nid;
3576 else
3577 spec->multiout.extra_out_nid[0] = nid;
3578 /* control HP volume/switch on the output mixer amp */
3579 nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin));
3580 sprintf(name, "%s Playback Volume", pfx);
3581 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3582 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
3583 if (err < 0)
3584 return err;
3585 sprintf(name, "%s Playback Switch", pfx);
3586 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
3587 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
3588 if (err < 0)
3589 return err;
3590 } else if (alc880_is_multi_pin(pin)) {
3591 /* set manual connection */
3592 /* we have only a switch on HP-out PIN */
3593 sprintf(name, "%s Playback Switch", pfx);
3594 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
3595 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3596 if (err < 0)
3597 return err;
3598 }
3599 return 0;
3600 }
3601
3602 /* create input playback/capture controls for the given pin */
3603 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
3604 const char *ctlname,
3605 int idx, hda_nid_t mix_nid)
3606 {
3607 char name[32];
3608 int err;
3609
3610 sprintf(name, "%s Playback Volume", ctlname);
3611 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3612 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
3613 if (err < 0)
3614 return err;
3615 sprintf(name, "%s Playback Switch", ctlname);
3616 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
3617 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
3618 if (err < 0)
3619 return err;
3620 return 0;
3621 }
3622
3623 /* create playback/capture controls for input pins */
3624 static int alc880_auto_create_analog_input_ctls(struct alc_spec *spec,
3625 const struct auto_pin_cfg *cfg)
3626 {
3627 struct hda_input_mux *imux = &spec->private_imux;
3628 int i, err, idx;
3629
3630 for (i = 0; i < AUTO_PIN_LAST; i++) {
3631 if (alc880_is_input_pin(cfg->input_pins[i])) {
3632 idx = alc880_input_pin_idx(cfg->input_pins[i]);
3633 err = new_analog_input(spec, cfg->input_pins[i],
3634 auto_pin_cfg_labels[i],
3635 idx, 0x0b);
3636 if (err < 0)
3637 return err;
3638 imux->items[imux->num_items].label =
3639 auto_pin_cfg_labels[i];
3640 imux->items[imux->num_items].index =
3641 alc880_input_pin_idx(cfg->input_pins[i]);
3642 imux->num_items++;