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
35
36 /* ALC880 board config type */
37 enum {
38 ALC880_3ST,
39 ALC880_3ST_DIG,
40 ALC880_5ST,
41 ALC880_5ST_DIG,
42 ALC880_W810,
43 ALC880_Z71V,
44 ALC880_6ST,
45 ALC880_6ST_DIG,
46 ALC880_F1734,
47 ALC880_ASUS,
48 ALC880_ASUS_DIG,
49 ALC880_ASUS_W1V,
50 ALC880_ASUS_DIG2,
51 ALC880_UNIWILL_DIG,
52 ALC880_CLEVO,
53 ALC880_TCL_S700,
54 ALC880_LG,
55 ALC880_LG_LW,
56 #ifdef CONFIG_SND_DEBUG
57 ALC880_TEST,
58 #endif
59 ALC880_AUTO,
60 ALC880_MODEL_LAST /* last tag */
61 };
62
63 /* ALC260 models */
64 enum {
65 ALC260_BASIC,
66 ALC260_HP,
67 ALC260_HP_3013,
68 ALC260_FUJITSU_S702X,
69 ALC260_ACER,
70 #ifdef CONFIG_SND_DEBUG
71 ALC260_TEST,
72 #endif
73 ALC260_AUTO,
74 ALC260_MODEL_LAST /* last tag */
75 };
76
77 /* ALC262 models */
78 enum {
79 ALC262_BASIC,
80 ALC262_FUJITSU,
81 ALC262_AUTO,
82 ALC262_MODEL_LAST /* last tag */
83 };
84
85 /* ALC861 models */
86 enum {
87 ALC861_3ST,
88 ALC861_3ST_DIG,
89 ALC861_6ST_DIG,
90 ALC861_AUTO,
91 ALC861_MODEL_LAST,
92 };
93
94 /* ALC882 models */
95 enum {
96 ALC882_3ST_DIG,
97 ALC882_6ST_DIG,
98 ALC882_AUTO,
99 ALC882_MODEL_LAST,
100 };
101
102 /* for GPIO Poll */
103 #define GPIO_MASK 0x03
104
105 struct alc_spec {
106 /* codec parameterization */
107 struct snd_kcontrol_new *mixers[5]; /* mixer arrays */
108 unsigned int num_mixers;
109
110 const struct hda_verb *init_verbs[5]; /* initialization verbs
111 * don't forget NULL termination!
112 */
113 unsigned int num_init_verbs;
114
115 char *stream_name_analog; /* analog PCM stream */
116 struct hda_pcm_stream *stream_analog_playback;
117 struct hda_pcm_stream *stream_analog_capture;
118
119 char *stream_name_digital; /* digital PCM stream */
120 struct hda_pcm_stream *stream_digital_playback;
121 struct hda_pcm_stream *stream_digital_capture;
122
123 /* playback */
124 struct hda_multi_out multiout; /* playback set-up
125 * max_channels, dacs must be set
126 * dig_out_nid and hp_nid are optional
127 */
128
129 /* capture */
130 unsigned int num_adc_nids;
131 hda_nid_t *adc_nids;
132 hda_nid_t dig_in_nid; /* digital-in NID; optional */
133
134 /* capture source */
135 unsigned int num_mux_defs;
136 const struct hda_input_mux *input_mux;
137 unsigned int cur_mux[3];
138
139 /* channel model */
140 const struct hda_channel_mode *channel_mode;
141 int num_channel_mode;
142
143 /* PCM information */
144 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
145
146 /* dynamic controls, init_verbs and input_mux */
147 struct auto_pin_cfg autocfg;
148 unsigned int num_kctl_alloc, num_kctl_used;
149 struct snd_kcontrol_new *kctl_alloc;
150 struct hda_input_mux private_imux;
151 hda_nid_t private_dac_nids[5];
152
153 /* hooks */
154 void (*init_hook)(struct hda_codec *codec);
155 void (*unsol_event)(struct hda_codec *codec, unsigned int res);
156
157 /* for pin sensing */
158 unsigned int sense_updated: 1;
159 unsigned int jack_present: 1;
160 };
161
162 /*
163 * configuration template - to be copied to the spec instance
164 */
165 struct alc_config_preset {
166 struct snd_kcontrol_new *mixers[5]; /* should be identical size with spec */
167 const struct hda_verb *init_verbs[5];
168 unsigned int num_dacs;
169 hda_nid_t *dac_nids;
170 hda_nid_t dig_out_nid; /* optional */
171 hda_nid_t hp_nid; /* optional */
172 unsigned int num_adc_nids;
173 hda_nid_t *adc_nids;
174 hda_nid_t dig_in_nid;
175 unsigned int num_channel_mode;
176 const struct hda_channel_mode *channel_mode;
177 unsigned int num_mux_defs;
178 const struct hda_input_mux *input_mux;
179 void (*unsol_event)(struct hda_codec *, unsigned int);
180 void (*init_hook)(struct hda_codec *);
181 };
182
183
184 /*
185 * input MUX handling
186 */
187 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
188 {
189 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
190 struct alc_spec *spec = codec->spec;
191 unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
192 if (mux_idx >= spec->num_mux_defs)
193 mux_idx = 0;
194 return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
195 }
196
197 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
198 {
199 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
200 struct alc_spec *spec = codec->spec;
201 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
202
203 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
204 return 0;
205 }
206
207 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
208 {
209 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
210 struct alc_spec *spec = codec->spec;
211 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
212 unsigned int mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
213 return snd_hda_input_mux_put(codec, &spec->input_mux[mux_idx], ucontrol,
214 spec->adc_nids[adc_idx], &spec->cur_mux[adc_idx]);
215 }
216
217
218 /*
219 * channel mode setting
220 */
221 static int alc_ch_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
222 {
223 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
224 struct alc_spec *spec = codec->spec;
225 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
226 spec->num_channel_mode);
227 }
228
229 static int alc_ch_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
230 {
231 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
232 struct alc_spec *spec = codec->spec;
233 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
234 spec->num_channel_mode, spec->multiout.max_channels);
235 }
236
237 static int alc_ch_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
238 {
239 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
240 struct alc_spec *spec = codec->spec;
241 return snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
242 spec->num_channel_mode, &spec->multiout.max_channels);
243 }
244
245 /*
246 * Control the mode of pin widget settings via the mixer. "pc" is used
247 * instead of "%" to avoid consequences of accidently treating the % as
248 * being part of a format specifier. Maximum allowed length of a value is
249 * 63 characters plus NULL terminator.
250 *
251 * Note: some retasking pin complexes seem to ignore requests for input
252 * states other than HiZ (eg: PIN_VREFxx) and revert to HiZ if any of these
253 * are requested. Therefore order this list so that this behaviour will not
254 * cause problems when mixer clients move through the enum sequentially.
255 * NIDs 0x0f and 0x10 have been observed to have this behaviour as of
256 * March 2006.
257 */
258 static char *alc_pin_mode_names[] = {
259 "Mic 50pc bias", "Mic 80pc bias",
260 "Line in", "Line out", "Headphone out",
261 };
262 static unsigned char alc_pin_mode_values[] = {
263 PIN_VREF50, PIN_VREF80, PIN_IN, PIN_OUT, PIN_HP,
264 };
265 /* The control can present all 5 options, or it can limit the options based
266 * in the pin being assumed to be exclusively an input or an output pin. In
267 * addition, "input" pins may or may not process the mic bias option
268 * depending on actual widget capability (NIDs 0x0f and 0x10 don't seem to
269 * accept requests for bias as of chip versions up to March 2006) and/or
270 * wiring in the computer.
271 */
272 #define ALC_PIN_DIR_IN 0x00
273 #define ALC_PIN_DIR_OUT 0x01
274 #define ALC_PIN_DIR_INOUT 0x02
275 #define ALC_PIN_DIR_IN_NOMICBIAS 0x03
276 #define ALC_PIN_DIR_INOUT_NOMICBIAS 0x04
277
278 /* Info about the pin modes supported by the different pin direction modes.
279 * For each direction the minimum and maximum values are given.
280 */
281 static signed char alc_pin_mode_dir_info[5][2] = {
282 { 0, 2 }, /* ALC_PIN_DIR_IN */
283 { 3, 4 }, /* ALC_PIN_DIR_OUT */
284 { 0, 4 }, /* ALC_PIN_DIR_INOUT */
285 { 2, 2 }, /* ALC_PIN_DIR_IN_NOMICBIAS */
286 { 2, 4 }, /* ALC_PIN_DIR_INOUT_NOMICBIAS */
287 };
288 #define alc_pin_mode_min(_dir) (alc_pin_mode_dir_info[_dir][0])
289 #define alc_pin_mode_max(_dir) (alc_pin_mode_dir_info[_dir][1])
290 #define alc_pin_mode_n_items(_dir) \
291 (alc_pin_mode_max(_dir)-alc_pin_mode_min(_dir)+1)
292
293 static int alc_pin_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
294 {
295 unsigned int item_num = uinfo->value.enumerated.item;
296 unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
297
298 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
299 uinfo->count = 1;
300 uinfo->value.enumerated.items = alc_pin_mode_n_items(dir);
301
302 if (item_num<alc_pin_mode_min(dir) || item_num>alc_pin_mode_max(dir))
303 item_num = alc_pin_mode_min(dir);
304 strcpy(uinfo->value.enumerated.name, alc_pin_mode_names[item_num]);
305 return 0;
306 }
307
308 static int alc_pin_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
309 {
310 unsigned int i;
311 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
312 hda_nid_t nid = kcontrol->private_value & 0xffff;
313 unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
314 long *valp = ucontrol->value.integer.value;
315 unsigned int pinctl = snd_hda_codec_read(codec,nid,0,AC_VERB_GET_PIN_WIDGET_CONTROL,0x00);
316
317 /* Find enumerated value for current pinctl setting */
318 i = alc_pin_mode_min(dir);
319 while (alc_pin_mode_values[i]!=pinctl && i<=alc_pin_mode_max(dir))
320 i++;
321 *valp = i<=alc_pin_mode_max(dir)?i:alc_pin_mode_min(dir);
322 return 0;
323 }
324
325 static int alc_pin_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
326 {
327 signed int change;
328 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
329 hda_nid_t nid = kcontrol->private_value & 0xffff;
330 unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
331 long val = *ucontrol->value.integer.value;
332 unsigned int pinctl = snd_hda_codec_read(codec,nid,0,AC_VERB_GET_PIN_WIDGET_CONTROL,0x00);
333
334 if (val<alc_pin_mode_min(dir) || val>alc_pin_mode_max(dir))
335 val = alc_pin_mode_min(dir);
336
337 change = pinctl != alc_pin_mode_values[val];
338 if (change) {
339 /* Set pin mode to that requested */
340 snd_hda_codec_write(codec,nid,0,AC_VERB_SET_PIN_WIDGET_CONTROL,
341 alc_pin_mode_values[val]);
342
343 /* Also enable the retasking pin's input/output as required
344 * for the requested pin mode. Enum values of 2 or less are
345 * input modes.
346 *
347 * Dynamically switching the input/output buffers probably
348 * reduces noise slightly (particularly on input) so we'll
349 * do it. However, having both input and output buffers
350 * enabled simultaneously doesn't seem to be problematic if
351 * this turns out to be necessary in the future.
352 */
353 if (val <= 2) {
354 snd_hda_codec_write(codec,nid,0,AC_VERB_SET_AMP_GAIN_MUTE,
355 AMP_OUT_MUTE);
356 snd_hda_codec_write(codec,nid,0,AC_VERB_SET_AMP_GAIN_MUTE,
357 AMP_IN_UNMUTE(0));
358 } else {
359 snd_hda_codec_write(codec,nid,0,AC_VERB_SET_AMP_GAIN_MUTE,
360 AMP_IN_MUTE(0));
361 snd_hda_codec_write(codec,nid,0,AC_VERB_SET_AMP_GAIN_MUTE,
362 AMP_OUT_UNMUTE);
363 }
364 }
365 return change;
366 }
367
368 #define ALC_PIN_MODE(xname, nid, dir) \
369 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
370 .info = alc_pin_mode_info, \
371 .get = alc_pin_mode_get, \
372 .put = alc_pin_mode_put, \
373 .private_value = nid | (dir<<16) }
374
375 /* A switch control for ALC260 GPIO pins. Multiple GPIOs can be ganged
376 * together using a mask with more than one bit set. This control is
377 * currently used only by the ALC260 test model. At this stage they are not
378 * needed for any "production" models.
379 */
380 #ifdef CONFIG_SND_DEBUG
381 static int alc_gpio_data_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
382 {
383 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
384 uinfo->count = 1;
385 uinfo->value.integer.min = 0;
386 uinfo->value.integer.max = 1;
387 return 0;
388 }
389 static int alc_gpio_data_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
390 {
391 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
392 hda_nid_t nid = kcontrol->private_value & 0xffff;
393 unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
394 long *valp = ucontrol->value.integer.value;
395 unsigned int val = snd_hda_codec_read(codec,nid,0,AC_VERB_GET_GPIO_DATA,0x00);
396
397 *valp = (val & mask) != 0;
398 return 0;
399 }
400 static int alc_gpio_data_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
401 {
402 signed int change;
403 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
404 hda_nid_t nid = kcontrol->private_value & 0xffff;
405 unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
406 long val = *ucontrol->value.integer.value;
407 unsigned int gpio_data = snd_hda_codec_read(codec,nid,0,AC_VERB_GET_GPIO_DATA,0x00);
408
409 /* Set/unset the masked GPIO bit(s) as needed */
410 change = (val==0?0:mask) != (gpio_data & mask);
411 if (val==0)
412 gpio_data &= ~mask;
413 else
414 gpio_data |= mask;
415 snd_hda_codec_write(codec,nid,0,AC_VERB_SET_GPIO_DATA,gpio_data);
416
417 return change;
418 }
419 #define ALC_GPIO_DATA_SWITCH(xname, nid, mask) \
420 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
421 .info = alc_gpio_data_info, \
422 .get = alc_gpio_data_get, \
423 .put = alc_gpio_data_put, \
424 .private_value = nid | (mask<<16) }
425 #endif /* CONFIG_SND_DEBUG */
426
427 /* A switch control to allow the enabling of the digital IO pins on the
428 * ALC260. This is incredibly simplistic; the intention of this control is
429 * to provide something in the test model allowing digital outputs to be
430 * identified if present. If models are found which can utilise these
431 * outputs a more complete mixer control can be devised for those models if
432 * necessary.
433 */
434 #ifdef CONFIG_SND_DEBUG
435 static int alc_spdif_ctrl_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
436 {
437 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
438 uinfo->count = 1;
439 uinfo->value.integer.min = 0;
440 uinfo->value.integer.max = 1;
441 return 0;
442 }
443 static int alc_spdif_ctrl_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
444 {
445 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
446 hda_nid_t nid = kcontrol->private_value & 0xffff;
447 unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
448 long *valp = ucontrol->value.integer.value;
449 unsigned int val = snd_hda_codec_read(codec,nid,0,AC_VERB_GET_DIGI_CONVERT,0x00);
450
451 *valp = (val & mask) != 0;
452 return 0;
453 }
454 static int alc_spdif_ctrl_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
455 {
456 signed int change;
457 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
458 hda_nid_t nid = kcontrol->private_value & 0xffff;
459 unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
460 long val = *ucontrol->value.integer.value;
461 unsigned int ctrl_data = snd_hda_codec_read(codec,nid,0,AC_VERB_GET_DIGI_CONVERT,0x00);
462
463 /* Set/unset the masked control bit(s) as needed */
464 change = (val==0?0:mask) != (ctrl_data & mask);
465 if (val==0)
466 ctrl_data &= ~mask;
467 else
468 ctrl_data |= mask;
469 snd_hda_codec_write(codec,nid,0,AC_VERB_SET_DIGI_CONVERT_1,ctrl_data);
470
471 return change;
472 }
473 #define ALC_SPDIF_CTRL_SWITCH(xname, nid, mask) \
474 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
475 .info = alc_spdif_ctrl_info, \
476 .get = alc_spdif_ctrl_get, \
477 .put = alc_spdif_ctrl_put, \
478 .private_value = nid | (mask<<16) }
479 #endif /* CONFIG_SND_DEBUG */
480
481 /*
482 * set up from the preset table
483 */
484 static void setup_preset(struct alc_spec *spec, const struct alc_config_preset *preset)
485 {
486 int i;
487
488 for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++)
489 spec->mixers[spec->num_mixers++] = preset->mixers[i];
490 for (i = 0; i < ARRAY_SIZE(preset->init_verbs) && preset->init_verbs[i]; i++)
491 spec->init_verbs[spec->num_init_verbs++] = preset->init_verbs[i];
492
493 spec->channel_mode = preset->channel_mode;
494 spec->num_channel_mode = preset->num_channel_mode;
495
496 spec->multiout.max_channels = spec->channel_mode[0].channels;
497
498 spec->multiout.num_dacs = preset->num_dacs;
499 spec->multiout.dac_nids = preset->dac_nids;
500 spec->multiout.dig_out_nid = preset->dig_out_nid;
501 spec->multiout.hp_nid = preset->hp_nid;
502
503 spec->num_mux_defs = preset->num_mux_defs;
504 if (! spec->num_mux_defs)
505 spec->num_mux_defs = 1;
506 spec->input_mux = preset->input_mux;
507
508 spec->num_adc_nids = preset->num_adc_nids;
509 spec->adc_nids = preset->adc_nids;
510 spec->dig_in_nid = preset->dig_in_nid;
511
512 spec->unsol_event = preset->unsol_event;
513 spec->init_hook = preset->init_hook;
514 }
515
516 /*
517 * ALC880 3-stack model
518 *
519 * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0e)
520 * Pin assignment: Front = 0x14, Line-In/Surr = 0x1a, Mic/CLFE = 0x18, F-Mic = 0x1b
521 * HP = 0x19
522 */
523
524 static hda_nid_t alc880_dac_nids[4] = {
525 /* front, rear, clfe, rear_surr */
526 0x02, 0x05, 0x04, 0x03
527 };
528
529 static hda_nid_t alc880_adc_nids[3] = {
530 /* ADC0-2 */
531 0x07, 0x08, 0x09,
532 };
533
534 /* The datasheet says the node 0x07 is connected from inputs,
535 * but it shows zero connection in the real implementation on some devices.
536 * Note: this is a 915GAV bug, fixed on 915GLV
537 */
538 static hda_nid_t alc880_adc_nids_alt[2] = {
539 /* ADC1-2 */
540 0x08, 0x09,
541 };
542
543 #define ALC880_DIGOUT_NID 0x06
544 #define ALC880_DIGIN_NID 0x0a
545
546 static struct hda_input_mux alc880_capture_source = {
547 .num_items = 4,
548 .items = {
549 { "Mic", 0x0 },
550 { "Front Mic", 0x3 },
551 { "Line", 0x2 },
552 { "CD", 0x4 },
553 },
554 };
555
556 /* channel source setting (2/6 channel selection for 3-stack) */
557 /* 2ch mode */
558 static struct hda_verb alc880_threestack_ch2_init[] = {
559 /* set line-in to input, mute it */
560 { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
561 { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
562 /* set mic-in to input vref 80%, mute it */
563 { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
564 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
565 { } /* end */
566 };
567
568 /* 6ch mode */
569 static struct hda_verb alc880_threestack_ch6_init[] = {
570 /* set line-in to output, unmute it */
571 { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
572 { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
573 /* set mic-in to output, unmute it */
574 { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
575 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
576 { } /* end */
577 };
578
579 static struct hda_channel_mode alc880_threestack_modes[2] = {
580 { 2, alc880_threestack_ch2_init },
581 { 6, alc880_threestack_ch6_init },
582 };
583
584 static struct snd_kcontrol_new alc880_three_stack_mixer[] = {
585 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
586 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
587 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
588 HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
589 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
590 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
591 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
592 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
593 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
594 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
595 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
596 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
597 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
598 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
599 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
600 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
601 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
602 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
603 HDA_CODEC_MUTE("Headphone Playback Switch", 0x19, 0x0, HDA_OUTPUT),
604 {
605 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
606 .name = "Channel Mode",
607 .info = alc_ch_mode_info,
608 .get = alc_ch_mode_get,
609 .put = alc_ch_mode_put,
610 },
611 { } /* end */
612 };
613
614 /* capture mixer elements */
615 static struct snd_kcontrol_new alc880_capture_mixer[] = {
616 HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
617 HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
618 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x08, 0x0, HDA_INPUT),
619 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x08, 0x0, HDA_INPUT),
620 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x09, 0x0, HDA_INPUT),
621 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x09, 0x0, HDA_INPUT),
622 {
623 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
624 /* The multiple "Capture Source" controls confuse alsamixer
625 * So call somewhat different..
626 * FIXME: the controls appear in the "playback" view!
627 */
628 /* .name = "Capture Source", */
629 .name = "Input Source",
630 .count = 3,
631 .info = alc_mux_enum_info,
632 .get = alc_mux_enum_get,
633 .put = alc_mux_enum_put,
634 },
635 { } /* end */
636 };
637
638 /* capture mixer elements (in case NID 0x07 not available) */
639 static struct snd_kcontrol_new alc880_capture_alt_mixer[] = {
640 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
641 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
642 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
643 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
644 {
645 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
646 /* The multiple "Capture Source" controls confuse alsamixer
647 * So call somewhat different..
648 * FIXME: the controls appear in the "playback" view!
649 */
650 /* .name = "Capture Source", */
651 .name = "Input Source",
652 .count = 2,
653 .info = alc_mux_enum_info,
654 .get = alc_mux_enum_get,
655 .put = alc_mux_enum_put,
656 },
657 { } /* end */
658 };
659
660
661
662 /*
663 * ALC880 5-stack model
664 *
665 * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0d), Side = 0x02 (0xd)
666 * Pin assignment: Front = 0x14, Surr = 0x17, CLFE = 0x16
667 * Line-In/Side = 0x1a, Mic = 0x18, F-Mic = 0x1b, HP = 0x19
668 */
669
670 /* additional mixers to alc880_three_stack_mixer */
671 static struct snd_kcontrol_new alc880_five_stack_mixer[] = {
672 HDA_CODEC_VOLUME("Side Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
673 HDA_BIND_MUTE("Side Playback Switch", 0x0d, 2, HDA_INPUT),
674 { } /* end */
675 };
676
677 /* channel source setting (6/8 channel selection for 5-stack) */
678 /* 6ch mode */
679 static struct hda_verb alc880_fivestack_ch6_init[] = {
680 /* set line-in to input, mute it */
681 { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
682 { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
683 { } /* end */
684 };
685
686 /* 8ch mode */
687 static struct hda_verb alc880_fivestack_ch8_init[] = {
688 /* set line-in to output, unmute it */
689 { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
690 { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
691 { } /* end */
692 };
693
694 static struct hda_channel_mode alc880_fivestack_modes[2] = {
695 { 6, alc880_fivestack_ch6_init },
696 { 8, alc880_fivestack_ch8_init },
697 };
698
699
700 /*
701 * ALC880 6-stack model
702 *
703 * DAC: Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e), Side = 0x05 (0x0f)
704 * Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, Side = 0x17,
705 * Mic = 0x18, F-Mic = 0x19, Line = 0x1a, HP = 0x1b
706 */
707
708 static hda_nid_t alc880_6st_dac_nids[4] = {
709 /* front, rear, clfe, rear_surr */
710 0x02, 0x03, 0x04, 0x05
711 };
712
713 static struct hda_input_mux alc880_6stack_capture_source = {
714 .num_items = 4,
715 .items = {
716 { "Mic", 0x0 },
717 { "Front Mic", 0x1 },
718 { "Line", 0x2 },
719 { "CD", 0x4 },
720 },
721 };
722
723 /* fixed 8-channels */
724 static struct hda_channel_mode alc880_sixstack_modes[1] = {
725 { 8, NULL },
726 };
727
728 static struct snd_kcontrol_new alc880_six_stack_mixer[] = {
729 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
730 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
731 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
732 HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
733 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
734 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
735 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
736 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
737 HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
738 HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
739 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
740 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
741 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
742 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
743 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
744 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
745 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
746 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
747 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
748 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
749 {
750 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
751 .name = "Channel Mode",
752 .info = alc_ch_mode_info,
753 .get = alc_ch_mode_get,
754 .put = alc_ch_mode_put,
755 },
756 { } /* end */
757 };
758
759
760 /*
761 * ALC880 W810 model
762 *
763 * W810 has rear IO for:
764 * Front (DAC 02)
765 * Surround (DAC 03)
766 * Center/LFE (DAC 04)
767 * Digital out (06)
768 *
769 * The system also has a pair of internal speakers, and a headphone jack.
770 * These are both connected to Line2 on the codec, hence to DAC 02.
771 *
772 * There is a variable resistor to control the speaker or headphone
773 * volume. This is a hardware-only device without a software API.
774 *
775 * Plugging headphones in will disable the internal speakers. This is
776 * implemented in hardware, not via the driver using jack sense. In
777 * a similar fashion, plugging into the rear socket marked "front" will
778 * disable both the speakers and headphones.
779 *
780 * For input, there's a microphone jack, and an "audio in" jack.
781 * These may not do anything useful with this driver yet, because I
782 * haven't setup any initialization verbs for these yet...
783 */
784
785 static hda_nid_t alc880_w810_dac_nids[3] = {
786 /* front, rear/surround, clfe */
787 0x02, 0x03, 0x04
788 };
789
790 /* fixed 6 channels */
791 static struct hda_channel_mode alc880_w810_modes[1] = {
792 { 6, NULL }
793 };
794
795 /* Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, HP = 0x1b */
796 static struct snd_kcontrol_new alc880_w810_base_mixer[] = {
797 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
798 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
799 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
800 HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
801 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
802 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
803 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
804 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
805 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
806 { } /* end */
807 };
808
809
810 /*
811 * Z710V model
812 *
813 * DAC: Front = 0x02 (0x0c), HP = 0x03 (0x0d)
814 * Pin assignment: Front = 0x14, HP = 0x15, Mic = 0x18, Mic2 = 0x19(?), Line = 0x1a
815 */
816
817 static hda_nid_t alc880_z71v_dac_nids[1] = {
818 0x02
819 };
820 #define ALC880_Z71V_HP_DAC 0x03
821
822 /* fixed 2 channels */
823 static struct hda_channel_mode alc880_2_jack_modes[1] = {
824 { 2, NULL }
825 };
826
827 static struct snd_kcontrol_new alc880_z71v_mixer[] = {
828 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
829 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
830 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
831 HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
832 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
833 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
834 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
835 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
836 { } /* end */
837 };
838
839
840 /* FIXME! */
841 /*
842 * ALC880 F1734 model
843 *
844 * DAC: HP = 0x02 (0x0c), Front = 0x03 (0x0d)
845 * Pin assignment: HP = 0x14, Front = 0x15, Mic = 0x18
846 */
847
848 static hda_nid_t alc880_f1734_dac_nids[1] = {
849 0x03
850 };
851 #define ALC880_F1734_HP_DAC 0x02
852
853 static struct snd_kcontrol_new alc880_f1734_mixer[] = {
854 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
855 HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
856 HDA_CODEC_VOLUME("Internal Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
857 HDA_BIND_MUTE("Internal Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
858 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
859 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
860 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
861 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
862 { } /* end */
863 };
864
865
866 /* FIXME! */
867 /*
868 * ALC880 ASUS model
869 *
870 * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
871 * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
872 * Mic = 0x18, Line = 0x1a
873 */
874
875 #define alc880_asus_dac_nids alc880_w810_dac_nids /* identical with w810 */
876 #define alc880_asus_modes alc880_threestack_modes /* 2/6 channel mode */
877
878 static struct snd_kcontrol_new alc880_asus_mixer[] = {
879 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
880 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
881 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
882 HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
883 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
884 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
885 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
886 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
887 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
888 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
889 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
890 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
891 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
892 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
893 {
894 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
895 .name = "Channel Mode",
896 .info = alc_ch_mode_info,
897 .get = alc_ch_mode_get,
898 .put = alc_ch_mode_put,
899 },
900 { } /* end */
901 };
902
903 /* FIXME! */
904 /*
905 * ALC880 ASUS W1V model
906 *
907 * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
908 * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
909 * Mic = 0x18, Line = 0x1a, Line2 = 0x1b
910 */
911
912 /* additional mixers to alc880_asus_mixer */
913 static struct snd_kcontrol_new alc880_asus_w1v_mixer[] = {
914 HDA_CODEC_VOLUME("Line2 Playback Volume", 0x0b, 0x03, HDA_INPUT),
915 HDA_CODEC_MUTE("Line2 Playback Switch", 0x0b, 0x03, HDA_INPUT),
916 { } /* end */
917 };
918
919 /* additional mixers to alc880_asus_mixer */
920 static struct snd_kcontrol_new alc880_pcbeep_mixer[] = {
921 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
922 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
923 { } /* end */
924 };
925
926 /* TCL S700 */
927 static struct snd_kcontrol_new alc880_tcl_s700_mixer[] = {
928 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
929 HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
930 HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
931 HDA_CODEC_VOLUME("CD Playback Volume", 0x0B, 0x04, HDA_INPUT),
932 HDA_CODEC_MUTE("CD Playback Switch", 0x0B, 0x04, HDA_INPUT),
933 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0B, 0x0, HDA_INPUT),
934 HDA_CODEC_MUTE("Mic Playback Switch", 0x0B, 0x0, HDA_INPUT),
935 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
936 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
937 {
938 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
939 /* The multiple "Capture Source" controls confuse alsamixer
940 * So call somewhat different..
941 * FIXME: the controls appear in the "playback" view!
942 */
943 /* .name = "Capture Source", */
944 .name = "Input Source",
945 .count = 1,
946 .info = alc_mux_enum_info,
947 .get = alc_mux_enum_get,
948 .put = alc_mux_enum_put,
949