~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Linux/sound/pci/hda/patch_realtek.c

Version: ~ [ 2.4.21-47.EL ] ~ [ 2.6.9-67.EL ] ~ [ 2.6.18-92.el5 ] ~
Architecture: ~ [ i386 ] ~ [ x86_64 ] ~

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