[ALSA] Fix missing AD1986a capsrc
[pandora-kernel.git] / sound / pci / hda / patch_analog.c
1 /*
2  * HD audio interface patch for AD1981HD, AD1983, AD1986A, AD1988
3  *
4  * Copyright (c) 2005 Takashi Iwai <tiwai@suse.de>
5  *
6  *  This driver is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This driver is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19  */
20
21 #include <sound/driver.h>
22 #include <linux/init.h>
23 #include <linux/delay.h>
24 #include <linux/slab.h>
25 #include <linux/pci.h>
26 #include <linux/mutex.h>
27
28 #include <sound/core.h>
29 #include "hda_codec.h"
30 #include "hda_local.h"
31
32 struct ad198x_spec {
33         struct snd_kcontrol_new *mixers[5];
34         int num_mixers;
35
36         const struct hda_verb *init_verbs[5];   /* initialization verbs
37                                                  * don't forget NULL termination!
38                                                  */
39         unsigned int num_init_verbs;
40
41         /* playback */
42         struct hda_multi_out multiout;  /* playback set-up
43                                          * max_channels, dacs must be set
44                                          * dig_out_nid and hp_nid are optional
45                                          */
46         unsigned int cur_eapd;
47
48         /* capture */
49         unsigned int num_adc_nids;
50         hda_nid_t *adc_nids;
51         hda_nid_t dig_in_nid;           /* digital-in NID; optional */
52
53         /* capture source */
54         const struct hda_input_mux *input_mux;
55         hda_nid_t *capsrc_nids;
56         unsigned int cur_mux[3];
57
58         /* channel model */
59         const struct hda_channel_mode *channel_mode;
60         int num_channel_mode;
61
62         /* PCM information */
63         struct hda_pcm pcm_rec[2];      /* used in alc_build_pcms() */
64
65         struct mutex amp_mutex; /* PCM volume/mute control mutex */
66         unsigned int spdif_route;
67
68         /* dynamic controls, init_verbs and input_mux */
69         struct auto_pin_cfg autocfg;
70         unsigned int num_kctl_alloc, num_kctl_used;
71         struct snd_kcontrol_new *kctl_alloc;
72         struct hda_input_mux private_imux;
73         hda_nid_t private_dac_nids[4];
74 };
75
76 /*
77  * input MUX handling (common part)
78  */
79 static int ad198x_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
80 {
81         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
82         struct ad198x_spec *spec = codec->spec;
83
84         return snd_hda_input_mux_info(spec->input_mux, uinfo);
85 }
86
87 static int ad198x_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
88 {
89         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
90         struct ad198x_spec *spec = codec->spec;
91         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
92
93         ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
94         return 0;
95 }
96
97 static int ad198x_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
98 {
99         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
100         struct ad198x_spec *spec = codec->spec;
101         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
102
103         return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
104                                      spec->capsrc_nids[adc_idx],
105                                      &spec->cur_mux[adc_idx]);
106 }
107
108 /*
109  * initialization (common callbacks)
110  */
111 static int ad198x_init(struct hda_codec *codec)
112 {
113         struct ad198x_spec *spec = codec->spec;
114         int i;
115
116         for (i = 0; i < spec->num_init_verbs; i++)
117                 snd_hda_sequence_write(codec, spec->init_verbs[i]);
118         return 0;
119 }
120
121 static int ad198x_build_controls(struct hda_codec *codec)
122 {
123         struct ad198x_spec *spec = codec->spec;
124         unsigned int i;
125         int err;
126
127         for (i = 0; i < spec->num_mixers; i++) {
128                 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
129                 if (err < 0)
130                         return err;
131         }
132         if (spec->multiout.dig_out_nid) {
133                 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
134                 if (err < 0)
135                         return err;
136         } 
137         if (spec->dig_in_nid) {
138                 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
139                 if (err < 0)
140                         return err;
141         }
142         return 0;
143 }
144
145 /*
146  * Analog playback callbacks
147  */
148 static int ad198x_playback_pcm_open(struct hda_pcm_stream *hinfo,
149                                     struct hda_codec *codec,
150                                     struct snd_pcm_substream *substream)
151 {
152         struct ad198x_spec *spec = codec->spec;
153         return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
154 }
155
156 static int ad198x_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
157                                        struct hda_codec *codec,
158                                        unsigned int stream_tag,
159                                        unsigned int format,
160                                        struct snd_pcm_substream *substream)
161 {
162         struct ad198x_spec *spec = codec->spec;
163         return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
164                                                 format, substream);
165 }
166
167 static int ad198x_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
168                                        struct hda_codec *codec,
169                                        struct snd_pcm_substream *substream)
170 {
171         struct ad198x_spec *spec = codec->spec;
172         return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
173 }
174
175 /*
176  * Digital out
177  */
178 static int ad198x_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
179                                         struct hda_codec *codec,
180                                         struct snd_pcm_substream *substream)
181 {
182         struct ad198x_spec *spec = codec->spec;
183         return snd_hda_multi_out_dig_open(codec, &spec->multiout);
184 }
185
186 static int ad198x_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
187                                          struct hda_codec *codec,
188                                          struct snd_pcm_substream *substream)
189 {
190         struct ad198x_spec *spec = codec->spec;
191         return snd_hda_multi_out_dig_close(codec, &spec->multiout);
192 }
193
194 /*
195  * Analog capture
196  */
197 static int ad198x_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
198                                       struct hda_codec *codec,
199                                       unsigned int stream_tag,
200                                       unsigned int format,
201                                       struct snd_pcm_substream *substream)
202 {
203         struct ad198x_spec *spec = codec->spec;
204         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
205                                    stream_tag, 0, format);
206         return 0;
207 }
208
209 static int ad198x_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
210                                       struct hda_codec *codec,
211                                       struct snd_pcm_substream *substream)
212 {
213         struct ad198x_spec *spec = codec->spec;
214         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
215                                    0, 0, 0);
216         return 0;
217 }
218
219
220 /*
221  */
222 static struct hda_pcm_stream ad198x_pcm_analog_playback = {
223         .substreams = 1,
224         .channels_min = 2,
225         .channels_max = 6, /* changed later */
226         .nid = 0, /* fill later */
227         .ops = {
228                 .open = ad198x_playback_pcm_open,
229                 .prepare = ad198x_playback_pcm_prepare,
230                 .cleanup = ad198x_playback_pcm_cleanup
231         },
232 };
233
234 static struct hda_pcm_stream ad198x_pcm_analog_capture = {
235         .substreams = 1,
236         .channels_min = 2,
237         .channels_max = 2,
238         .nid = 0, /* fill later */
239         .ops = {
240                 .prepare = ad198x_capture_pcm_prepare,
241                 .cleanup = ad198x_capture_pcm_cleanup
242         },
243 };
244
245 static struct hda_pcm_stream ad198x_pcm_digital_playback = {
246         .substreams = 1,
247         .channels_min = 2,
248         .channels_max = 2,
249         .nid = 0, /* fill later */
250         .ops = {
251                 .open = ad198x_dig_playback_pcm_open,
252                 .close = ad198x_dig_playback_pcm_close
253         },
254 };
255
256 static struct hda_pcm_stream ad198x_pcm_digital_capture = {
257         .substreams = 1,
258         .channels_min = 2,
259         .channels_max = 2,
260         /* NID is set in alc_build_pcms */
261 };
262
263 static int ad198x_build_pcms(struct hda_codec *codec)
264 {
265         struct ad198x_spec *spec = codec->spec;
266         struct hda_pcm *info = spec->pcm_rec;
267
268         codec->num_pcms = 1;
269         codec->pcm_info = info;
270
271         info->name = "AD198x Analog";
272         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_analog_playback;
273         info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->multiout.max_channels;
274         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
275         info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_analog_capture;
276         info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
277         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
278
279         if (spec->multiout.dig_out_nid) {
280                 info++;
281                 codec->num_pcms++;
282                 info->name = "AD198x Digital";
283                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_digital_playback;
284                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
285                 if (spec->dig_in_nid) {
286                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_digital_capture;
287                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
288                 }
289         }
290
291         return 0;
292 }
293
294 static void ad198x_free(struct hda_codec *codec)
295 {
296         struct ad198x_spec *spec = codec->spec;
297         unsigned int i;
298
299         if (spec->kctl_alloc) {
300                 for (i = 0; i < spec->num_kctl_used; i++)
301                         kfree(spec->kctl_alloc[i].name);
302                 kfree(spec->kctl_alloc);
303         }
304         kfree(codec->spec);
305 }
306
307 #ifdef CONFIG_PM
308 static int ad198x_resume(struct hda_codec *codec)
309 {
310         struct ad198x_spec *spec = codec->spec;
311         int i;
312
313         codec->patch_ops.init(codec);
314         for (i = 0; i < spec->num_mixers; i++)
315                 snd_hda_resume_ctls(codec, spec->mixers[i]);
316         if (spec->multiout.dig_out_nid)
317                 snd_hda_resume_spdif_out(codec);
318         if (spec->dig_in_nid)
319                 snd_hda_resume_spdif_in(codec);
320         return 0;
321 }
322 #endif
323
324 static struct hda_codec_ops ad198x_patch_ops = {
325         .build_controls = ad198x_build_controls,
326         .build_pcms = ad198x_build_pcms,
327         .init = ad198x_init,
328         .free = ad198x_free,
329 #ifdef CONFIG_PM
330         .resume = ad198x_resume,
331 #endif
332 };
333
334
335 /*
336  * EAPD control
337  * the private value = nid | (invert << 8)
338  */
339 static int ad198x_eapd_info(struct snd_kcontrol *kcontrol,
340                             struct snd_ctl_elem_info *uinfo)
341 {
342         uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
343         uinfo->count = 1;
344         uinfo->value.integer.min = 0;
345         uinfo->value.integer.max = 1;
346         return 0;
347 }
348
349 static int ad198x_eapd_get(struct snd_kcontrol *kcontrol,
350                            struct snd_ctl_elem_value *ucontrol)
351 {
352         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
353         struct ad198x_spec *spec = codec->spec;
354         int invert = (kcontrol->private_value >> 8) & 1;
355         if (invert)
356                 ucontrol->value.integer.value[0] = ! spec->cur_eapd;
357         else
358                 ucontrol->value.integer.value[0] = spec->cur_eapd;
359         return 0;
360 }
361
362 static int ad198x_eapd_put(struct snd_kcontrol *kcontrol,
363                            struct snd_ctl_elem_value *ucontrol)
364 {
365         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
366         struct ad198x_spec *spec = codec->spec;
367         int invert = (kcontrol->private_value >> 8) & 1;
368         hda_nid_t nid = kcontrol->private_value & 0xff;
369         unsigned int eapd;
370         eapd = ucontrol->value.integer.value[0];
371         if (invert)
372                 eapd = !eapd;
373         if (eapd == spec->cur_eapd && ! codec->in_resume)
374                 return 0;
375         spec->cur_eapd = eapd;
376         snd_hda_codec_write(codec, nid,
377                             0, AC_VERB_SET_EAPD_BTLENABLE,
378                             eapd ? 0x02 : 0x00);
379         return 1;
380 }
381
382 /*
383  * AD1986A specific
384  */
385
386 #define AD1986A_SPDIF_OUT       0x02
387 #define AD1986A_FRONT_DAC       0x03
388 #define AD1986A_SURR_DAC        0x04
389 #define AD1986A_CLFE_DAC        0x05
390 #define AD1986A_ADC             0x06
391
392 static hda_nid_t ad1986a_dac_nids[3] = {
393         AD1986A_FRONT_DAC, AD1986A_SURR_DAC, AD1986A_CLFE_DAC
394 };
395 static hda_nid_t ad1986a_adc_nids[1] = { AD1986A_ADC };
396 static hda_nid_t ad1986a_capsrc_nids[1] = { 0x12 };
397
398 static struct hda_input_mux ad1986a_capture_source = {
399         .num_items = 7,
400         .items = {
401                 { "Mic", 0x0 },
402                 { "CD", 0x1 },
403                 { "Aux", 0x3 },
404                 { "Line", 0x4 },
405                 { "Mix", 0x5 },
406                 { "Mono", 0x6 },
407                 { "Phone", 0x7 },
408         },
409 };
410
411 /*
412  * PCM control
413  *
414  * bind volumes/mutes of 3 DACs as a single PCM control for simplicity
415  */
416
417 #define ad1986a_pcm_amp_vol_info        snd_hda_mixer_amp_volume_info
418
419 static int ad1986a_pcm_amp_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
420 {
421         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
422         struct ad198x_spec *ad = codec->spec;
423
424         mutex_lock(&ad->amp_mutex);
425         snd_hda_mixer_amp_volume_get(kcontrol, ucontrol);
426         mutex_unlock(&ad->amp_mutex);
427         return 0;
428 }
429
430 static int ad1986a_pcm_amp_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
431 {
432         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
433         struct ad198x_spec *ad = codec->spec;
434         int i, change = 0;
435
436         mutex_lock(&ad->amp_mutex);
437         for (i = 0; i < ARRAY_SIZE(ad1986a_dac_nids); i++) {
438                 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(ad1986a_dac_nids[i], 3, 0, HDA_OUTPUT);
439                 change |= snd_hda_mixer_amp_volume_put(kcontrol, ucontrol);
440         }
441         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT);
442         mutex_unlock(&ad->amp_mutex);
443         return change;
444 }
445
446 #define ad1986a_pcm_amp_sw_info         snd_hda_mixer_amp_switch_info
447
448 static int ad1986a_pcm_amp_sw_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
449 {
450         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
451         struct ad198x_spec *ad = codec->spec;
452
453         mutex_lock(&ad->amp_mutex);
454         snd_hda_mixer_amp_switch_get(kcontrol, ucontrol);
455         mutex_unlock(&ad->amp_mutex);
456         return 0;
457 }
458
459 static int ad1986a_pcm_amp_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
460 {
461         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
462         struct ad198x_spec *ad = codec->spec;
463         int i, change = 0;
464
465         mutex_lock(&ad->amp_mutex);
466         for (i = 0; i < ARRAY_SIZE(ad1986a_dac_nids); i++) {
467                 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(ad1986a_dac_nids[i], 3, 0, HDA_OUTPUT);
468                 change |= snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
469         }
470         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT);
471         mutex_unlock(&ad->amp_mutex);
472         return change;
473 }
474
475 /*
476  * mixers
477  */
478 static struct snd_kcontrol_new ad1986a_mixers[] = {
479         {
480                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
481                 .name = "PCM Playback Volume",
482                 .info = ad1986a_pcm_amp_vol_info,
483                 .get = ad1986a_pcm_amp_vol_get,
484                 .put = ad1986a_pcm_amp_vol_put,
485                 .private_value = HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT)
486         },
487         {
488                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
489                 .name = "PCM Playback Switch",
490                 .info = ad1986a_pcm_amp_sw_info,
491                 .get = ad1986a_pcm_amp_sw_get,
492                 .put = ad1986a_pcm_amp_sw_put,
493                 .private_value = HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT)
494         },
495         HDA_CODEC_VOLUME("Front Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
496         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
497         HDA_CODEC_VOLUME("Surround Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
498         HDA_CODEC_MUTE("Surround Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
499         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x1d, 1, 0x0, HDA_OUTPUT),
500         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x1d, 2, 0x0, HDA_OUTPUT),
501         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x1d, 1, 0x0, HDA_OUTPUT),
502         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x1d, 2, 0x0, HDA_OUTPUT),
503         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x1a, 0x0, HDA_OUTPUT),
504         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x0, HDA_OUTPUT),
505         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
506         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
507         HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
508         HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT),
509         HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT),
510         HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
511         HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
512         HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
513         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x18, 0x0, HDA_OUTPUT),
514         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x18, 0x0, HDA_OUTPUT),
515         HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
516         HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT),
517         HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
518         HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
519         {
520                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
521                 .name = "Capture Source",
522                 .info = ad198x_mux_enum_info,
523                 .get = ad198x_mux_enum_get,
524                 .put = ad198x_mux_enum_put,
525         },
526         HDA_CODEC_MUTE("Stereo Downmix Switch", 0x09, 0x0, HDA_OUTPUT),
527         { } /* end */
528 };
529
530 /*
531  * initialization verbs
532  */
533 static struct hda_verb ad1986a_init_verbs[] = {
534         /* Front, Surround, CLFE DAC; mute as default */
535         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
536         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
537         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
538         /* Downmix - off */
539         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
540         /* HP, Line-Out, Surround, CLFE selectors */
541         {0x0a, AC_VERB_SET_CONNECT_SEL, 0x0},
542         {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0},
543         {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
544         {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
545         /* Mono selector */
546         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x0},
547         /* Mic selector: Mic 1/2 pin */
548         {0x0f, AC_VERB_SET_CONNECT_SEL, 0x0},
549         /* Line-in selector: Line-in */
550         {0x10, AC_VERB_SET_CONNECT_SEL, 0x0},
551         /* Mic 1/2 swap */
552         {0x11, AC_VERB_SET_CONNECT_SEL, 0x0},
553         /* Record selector: mic */
554         {0x12, AC_VERB_SET_CONNECT_SEL, 0x0},
555         /* Mic, Phone, CD, Aux, Line-In amp; mute as default */
556         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
557         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
558         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
559         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
560         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
561         /* PC beep */
562         {0x18, AC_VERB_SET_CONNECT_SEL, 0x0},
563         /* HP, Line-Out, Surround, CLFE, Mono pins; mute as default */
564         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
565         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
566         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
567         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
568         {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
569         /* HP Pin */
570         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
571         /* Front, Surround, CLFE Pins */
572         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
573         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
574         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
575         /* Mono Pin */
576         {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
577         /* Mic Pin */
578         {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
579         /* Line, Aux, CD, Beep-In Pin */
580         {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
581         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
582         {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
583         {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
584         {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
585         { } /* end */
586 };
587
588
589 static int patch_ad1986a(struct hda_codec *codec)
590 {
591         struct ad198x_spec *spec;
592
593         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
594         if (spec == NULL)
595                 return -ENOMEM;
596
597         mutex_init(&spec->amp_mutex);
598         codec->spec = spec;
599
600         spec->multiout.max_channels = 6;
601         spec->multiout.num_dacs = ARRAY_SIZE(ad1986a_dac_nids);
602         spec->multiout.dac_nids = ad1986a_dac_nids;
603         spec->multiout.dig_out_nid = AD1986A_SPDIF_OUT;
604         spec->num_adc_nids = 1;
605         spec->adc_nids = ad1986a_adc_nids;
606         spec->capsrc_nids = ad1986a_capsrc_nids;
607         spec->input_mux = &ad1986a_capture_source;
608         spec->num_mixers = 1;
609         spec->mixers[0] = ad1986a_mixers;
610         spec->num_init_verbs = 1;
611         spec->init_verbs[0] = ad1986a_init_verbs;
612
613         codec->patch_ops = ad198x_patch_ops;
614
615         return 0;
616 }
617
618 /*
619  * AD1983 specific
620  */
621
622 #define AD1983_SPDIF_OUT        0x02
623 #define AD1983_DAC              0x03
624 #define AD1983_ADC              0x04
625
626 static hda_nid_t ad1983_dac_nids[1] = { AD1983_DAC };
627 static hda_nid_t ad1983_adc_nids[1] = { AD1983_ADC };
628 static hda_nid_t ad1983_capsrc_nids[1] = { 0x15 };
629
630 static struct hda_input_mux ad1983_capture_source = {
631         .num_items = 4,
632         .items = {
633                 { "Mic", 0x0 },
634                 { "Line", 0x1 },
635                 { "Mix", 0x2 },
636                 { "Mix Mono", 0x3 },
637         },
638 };
639
640 /*
641  * SPDIF playback route
642  */
643 static int ad1983_spdif_route_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
644 {
645         static char *texts[] = { "PCM", "ADC" };
646
647         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
648         uinfo->count = 1;
649         uinfo->value.enumerated.items = 2;
650         if (uinfo->value.enumerated.item > 1)
651                 uinfo->value.enumerated.item = 1;
652         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
653         return 0;
654 }
655
656 static int ad1983_spdif_route_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
657 {
658         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
659         struct ad198x_spec *spec = codec->spec;
660
661         ucontrol->value.enumerated.item[0] = spec->spdif_route;
662         return 0;
663 }
664
665 static int ad1983_spdif_route_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
666 {
667         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
668         struct ad198x_spec *spec = codec->spec;
669
670         if (spec->spdif_route != ucontrol->value.enumerated.item[0]) {
671                 spec->spdif_route = ucontrol->value.enumerated.item[0];
672                 snd_hda_codec_write(codec, spec->multiout.dig_out_nid, 0,
673                                     AC_VERB_SET_CONNECT_SEL, spec->spdif_route);
674                 return 1;
675         }
676         return 0;
677 }
678
679 static struct snd_kcontrol_new ad1983_mixers[] = {
680         HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
681         HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
682         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
683         HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
684         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
685         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
686         HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
687         HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
688         HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
689         HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
690         HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
691         HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
692         HDA_CODEC_VOLUME_MONO("PC Speaker Playback Volume", 0x10, 1, 0x0, HDA_OUTPUT),
693         HDA_CODEC_MUTE_MONO("PC Speaker Playback Switch", 0x10, 1, 0x0, HDA_OUTPUT),
694         HDA_CODEC_VOLUME("Mic Boost", 0x0c, 0x0, HDA_OUTPUT),
695         HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
696         HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
697         {
698                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
699                 .name = "Capture Source",
700                 .info = ad198x_mux_enum_info,
701                 .get = ad198x_mux_enum_get,
702                 .put = ad198x_mux_enum_put,
703         },
704         {
705                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
706                 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Route",
707                 .info = ad1983_spdif_route_info,
708                 .get = ad1983_spdif_route_get,
709                 .put = ad1983_spdif_route_put,
710         },
711         { } /* end */
712 };
713
714 static struct hda_verb ad1983_init_verbs[] = {
715         /* Front, HP, Mono; mute as default */
716         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
717         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
718         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
719         /* Beep, PCM, Mic, Line-In: mute */
720         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
721         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
722         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
723         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
724         /* Front, HP selectors; from Mix */
725         {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
726         {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
727         /* Mono selector; from Mix */
728         {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
729         /* Mic selector; Mic */
730         {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
731         /* Line-in selector: Line-in */
732         {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
733         /* Mic boost: 0dB */
734         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
735         /* Record selector: mic */
736         {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
737         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
738         /* SPDIF route: PCM */
739         {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
740         /* Front Pin */
741         {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
742         /* HP Pin */
743         {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
744         /* Mono Pin */
745         {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
746         /* Mic Pin */
747         {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
748         /* Line Pin */
749         {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
750         { } /* end */
751 };
752
753
754 static int patch_ad1983(struct hda_codec *codec)
755 {
756         struct ad198x_spec *spec;
757
758         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
759         if (spec == NULL)
760                 return -ENOMEM;
761
762         mutex_init(&spec->amp_mutex);
763         codec->spec = spec;
764
765         spec->multiout.max_channels = 2;
766         spec->multiout.num_dacs = ARRAY_SIZE(ad1983_dac_nids);
767         spec->multiout.dac_nids = ad1983_dac_nids;
768         spec->multiout.dig_out_nid = AD1983_SPDIF_OUT;
769         spec->num_adc_nids = 1;
770         spec->adc_nids = ad1983_adc_nids;
771         spec->capsrc_nids = ad1983_capsrc_nids;
772         spec->input_mux = &ad1983_capture_source;
773         spec->num_mixers = 1;
774         spec->mixers[0] = ad1983_mixers;
775         spec->num_init_verbs = 1;
776         spec->init_verbs[0] = ad1983_init_verbs;
777         spec->spdif_route = 0;
778
779         codec->patch_ops = ad198x_patch_ops;
780
781         return 0;
782 }
783
784
785 /*
786  * AD1981 HD specific
787  */
788
789 #define AD1981_SPDIF_OUT        0x02
790 #define AD1981_DAC              0x03
791 #define AD1981_ADC              0x04
792
793 static hda_nid_t ad1981_dac_nids[1] = { AD1981_DAC };
794 static hda_nid_t ad1981_adc_nids[1] = { AD1981_ADC };
795 static hda_nid_t ad1981_capsrc_nids[1] = { 0x15 };
796
797 /* 0x0c, 0x09, 0x0e, 0x0f, 0x19, 0x05, 0x18, 0x17 */
798 static struct hda_input_mux ad1981_capture_source = {
799         .num_items = 7,
800         .items = {
801                 { "Front Mic", 0x0 },
802                 { "Line", 0x1 },
803                 { "Mix", 0x2 },
804                 { "Mix Mono", 0x3 },
805                 { "CD", 0x4 },
806                 { "Mic", 0x6 },
807                 { "Aux", 0x7 },
808         },
809 };
810
811 static struct snd_kcontrol_new ad1981_mixers[] = {
812         HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
813         HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
814         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
815         HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
816         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
817         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
818         HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
819         HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
820         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
821         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
822         HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
823         HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
824         HDA_CODEC_VOLUME("Aux Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
825         HDA_CODEC_MUTE("Aux Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
826         HDA_CODEC_VOLUME("Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
827         HDA_CODEC_MUTE("Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
828         HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
829         HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
830         HDA_CODEC_VOLUME_MONO("PC Speaker Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
831         HDA_CODEC_MUTE_MONO("PC Speaker Playback Switch", 0x0d, 1, 0x0, HDA_OUTPUT),
832         HDA_CODEC_VOLUME("Front Mic Boost", 0x08, 0x0, HDA_INPUT),
833         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x0, HDA_INPUT),
834         HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
835         HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
836         {
837                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
838                 .name = "Capture Source",
839                 .info = ad198x_mux_enum_info,
840                 .get = ad198x_mux_enum_get,
841                 .put = ad198x_mux_enum_put,
842         },
843         /* identical with AD1983 */
844         {
845                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
846                 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Route",
847                 .info = ad1983_spdif_route_info,
848                 .get = ad1983_spdif_route_get,
849                 .put = ad1983_spdif_route_put,
850         },
851         { } /* end */
852 };
853
854 static struct hda_verb ad1981_init_verbs[] = {
855         /* Front, HP, Mono; mute as default */
856         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
857         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
858         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
859         /* Beep, PCM, Front Mic, Line, Rear Mic, Aux, CD-In: mute */
860         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
861         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
862         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
863         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
864         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
865         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
866         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
867         /* Front, HP selectors; from Mix */
868         {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
869         {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
870         /* Mono selector; from Mix */
871         {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
872         /* Mic Mixer; select Front Mic */
873         {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
874         {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
875         /* Mic boost: 0dB */
876         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
877         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
878         /* Record selector: Front mic */
879         {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
880         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
881         /* SPDIF route: PCM */
882         {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
883         /* Front Pin */
884         {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
885         /* HP Pin */
886         {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
887         /* Mono Pin */
888         {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
889         /* Front & Rear Mic Pins */
890         {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
891         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
892         /* Line Pin */
893         {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
894         /* Digital Beep */
895         {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
896         /* Line-Out as Input: disabled */
897         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
898         { } /* end */
899 };
900
901 /*
902  * Patch for HP nx6320
903  *
904  * nx6320 uses EAPD in the reserve way - EAPD-on means the internal
905  * speaker output enabled _and_ mute-LED off.
906  */
907
908 #define AD1981_HP_EVENT         0x37
909 #define AD1981_MIC_EVENT        0x38
910
911 static struct hda_verb ad1981_hp_init_verbs[] = {
912         {0x05, AC_VERB_SET_EAPD_BTLENABLE, 0x00 }, /* default off */
913         /* pin sensing on HP and Mic jacks */
914         {0x06, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_HP_EVENT},
915         {0x08, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_MIC_EVENT},
916         {}
917 };
918
919 /* turn on/off EAPD (+ mute HP) as a master switch */
920 static int ad1981_hp_master_sw_put(struct snd_kcontrol *kcontrol,
921                                    struct snd_ctl_elem_value *ucontrol)
922 {
923         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
924         struct ad198x_spec *spec = codec->spec;
925
926         if (! ad198x_eapd_put(kcontrol, ucontrol))
927                 return 0;
928
929         /* toggle HP mute appropriately */
930         snd_hda_codec_amp_update(codec, 0x06, 0, HDA_OUTPUT, 0,
931                                  0x80, spec->cur_eapd ? 0 : 0x80);
932         snd_hda_codec_amp_update(codec, 0x06, 1, HDA_OUTPUT, 0,
933                                  0x80, spec->cur_eapd ? 0 : 0x80);
934         return 1;
935 }
936
937 /* bind volumes of both NID 0x05 and 0x06 */
938 static int ad1981_hp_master_vol_put(struct snd_kcontrol *kcontrol,
939                                     struct snd_ctl_elem_value *ucontrol)
940 {
941         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
942         long *valp = ucontrol->value.integer.value;
943         int change;
944
945         change = snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
946                                           0x7f, valp[0] & 0x7f);
947         change |= snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
948                                            0x7f, valp[1] & 0x7f);
949         snd_hda_codec_amp_update(codec, 0x06, 0, HDA_OUTPUT, 0,
950                                  0x7f, valp[0] & 0x7f);
951         snd_hda_codec_amp_update(codec, 0x06, 1, HDA_OUTPUT, 0,
952                                  0x7f, valp[1] & 0x7f);
953         return change;
954 }
955
956 /* mute internal speaker if HP is plugged */
957 static void ad1981_hp_automute(struct hda_codec *codec)
958 {
959         unsigned int present;
960
961         present = snd_hda_codec_read(codec, 0x06, 0,
962                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
963         snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
964                                  0x80, present ? 0x80 : 0);
965         snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
966                                  0x80, present ? 0x80 : 0);
967 }
968
969 /* toggle input of built-in and mic jack appropriately */
970 static void ad1981_hp_automic(struct hda_codec *codec)
971 {
972         static struct hda_verb mic_jack_on[] = {
973                 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
974                 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
975                 {}
976         };
977         static struct hda_verb mic_jack_off[] = {
978                 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
979                 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
980                 {}
981         };
982         unsigned int present;
983
984         present = snd_hda_codec_read(codec, 0x08, 0,
985                                  AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
986         if (present)
987                 snd_hda_sequence_write(codec, mic_jack_on);
988         else
989                 snd_hda_sequence_write(codec, mic_jack_off);
990 }
991
992 /* unsolicited event for HP jack sensing */
993 static void ad1981_hp_unsol_event(struct hda_codec *codec,
994                                   unsigned int res)
995 {
996         res >>= 26;
997         switch (res) {
998         case AD1981_HP_EVENT:
999                 ad1981_hp_automute(codec);
1000                 break;
1001         case AD1981_MIC_EVENT:
1002                 ad1981_hp_automic(codec);
1003                 break;
1004         }
1005 }
1006
1007 static struct hda_input_mux ad1981_hp_capture_source = {
1008         .num_items = 3,
1009         .items = {
1010                 { "Mic", 0x0 },
1011                 { "Docking-Station", 0x1 },
1012                 { "Mix", 0x2 },
1013         },
1014 };
1015
1016 static struct snd_kcontrol_new ad1981_hp_mixers[] = {
1017         {
1018                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1019                 .name = "Master Playback Volume",
1020                 .info = snd_hda_mixer_amp_volume_info,
1021                 .get = snd_hda_mixer_amp_volume_get,
1022                 .put = ad1981_hp_master_vol_put,
1023                 .private_value = HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
1024         },
1025         {
1026                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1027                 .name = "Master Playback Switch",
1028                 .info = ad198x_eapd_info,
1029                 .get = ad198x_eapd_get,
1030                 .put = ad1981_hp_master_sw_put,
1031                 .private_value = 0x05,
1032         },
1033         HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1034         HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1035 #if 0
1036         /* FIXME: analog mic/line loopback doesn't work with my tests...
1037          *        (although recording is OK)
1038          */
1039         HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1040         HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1041         HDA_CODEC_VOLUME("Docking-Station Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1042         HDA_CODEC_MUTE("Docking-Station Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1043         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
1044         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
1045         /* FIXME: does this laptop have analog CD connection? */
1046         HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1047         HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1048 #endif
1049         HDA_CODEC_VOLUME("Mic Boost", 0x08, 0x0, HDA_INPUT),
1050         HDA_CODEC_VOLUME("Internal Mic Boost", 0x18, 0x0, HDA_INPUT),
1051         HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1052         HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1053         {
1054                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1055                 .name = "Capture Source",
1056                 .info = ad198x_mux_enum_info,
1057                 .get = ad198x_mux_enum_get,
1058                 .put = ad198x_mux_enum_put,
1059         },
1060         { } /* end */
1061 };
1062
1063 /* initialize jack-sensing, too */
1064 static int ad1981_hp_init(struct hda_codec *codec)
1065 {
1066         ad198x_init(codec);
1067         ad1981_hp_automute(codec);
1068         ad1981_hp_automic(codec);
1069         return 0;
1070 }
1071
1072 /* models */
1073 enum { AD1981_BASIC, AD1981_HP };
1074
1075 static struct hda_board_config ad1981_cfg_tbl[] = {
1076         { .modelname = "hp", .config = AD1981_HP },
1077         { .pci_subvendor = 0x103c, .pci_subdevice = 0x30aa,
1078           .config = AD1981_HP },
1079         { .modelname = "basic", .config = AD1981_BASIC },
1080         {}
1081 };
1082
1083 static int patch_ad1981(struct hda_codec *codec)
1084 {
1085         struct ad198x_spec *spec;
1086         int board_config;
1087
1088         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1089         if (spec == NULL)
1090                 return -ENOMEM;
1091
1092         mutex_init(&spec->amp_mutex);
1093         codec->spec = spec;
1094
1095         spec->multiout.max_channels = 2;
1096         spec->multiout.num_dacs = ARRAY_SIZE(ad1981_dac_nids);
1097         spec->multiout.dac_nids = ad1981_dac_nids;
1098         spec->multiout.dig_out_nid = AD1981_SPDIF_OUT;
1099         spec->num_adc_nids = 1;
1100         spec->adc_nids = ad1981_adc_nids;
1101         spec->capsrc_nids = ad1981_capsrc_nids;
1102         spec->input_mux = &ad1981_capture_source;
1103         spec->num_mixers = 1;
1104         spec->mixers[0] = ad1981_mixers;
1105         spec->num_init_verbs = 1;
1106         spec->init_verbs[0] = ad1981_init_verbs;
1107         spec->spdif_route = 0;
1108
1109         codec->patch_ops = ad198x_patch_ops;
1110
1111         /* override some parameters */
1112         board_config = snd_hda_check_board_config(codec, ad1981_cfg_tbl);
1113         switch (board_config) {
1114         case AD1981_HP:
1115                 spec->mixers[0] = ad1981_hp_mixers;
1116                 spec->num_init_verbs = 2;
1117                 spec->init_verbs[1] = ad1981_hp_init_verbs;
1118                 spec->multiout.dig_out_nid = 0;
1119                 spec->input_mux = &ad1981_hp_capture_source;
1120
1121                 codec->patch_ops.init = ad1981_hp_init;
1122                 codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
1123                 break;
1124         }
1125
1126         return 0;
1127 }
1128
1129
1130 /*
1131  * AD1988
1132  *
1133  * Output pins and routes
1134  *
1135  *        Pin               Mix     Sel     DAC (*)
1136  * port-A 0x11 (mute/hp) <- 0x22 <- 0x37 <- 03/04/06
1137  * port-B 0x14 (mute/hp) <- 0x2b <- 0x30 <- 03/04/06
1138  * port-C 0x15 (mute)    <- 0x2c <- 0x31 <- 05/0a
1139  * port-D 0x12 (mute/hp) <- 0x29         <- 04
1140  * port-E 0x17 (mute/hp) <- 0x26 <- 0x32 <- 05/0a
1141  * port-F 0x16 (mute)    <- 0x2a         <- 06
1142  * port-G 0x24 (mute)    <- 0x27         <- 05
1143  * port-H 0x25 (mute)    <- 0x28         <- 0a
1144  * mono   0x13 (mute/amp)<- 0x1e <- 0x36 <- 03/04/06
1145  *
1146  * DAC0 = 03h, DAC1 = 04h, DAC2 = 05h, DAC3 = 06h, DAC4 = 0ah
1147  * (*) DAC2/3/4 are swapped to DAC3/4/2 on AD198A rev.2 due to a h/w bug.
1148  *
1149  * Input pins and routes
1150  *
1151  *        pin     boost   mix input # / adc input #
1152  * port-A 0x11 -> 0x38 -> mix 2, ADC 0
1153  * port-B 0x14 -> 0x39 -> mix 0, ADC 1
1154  * port-C 0x15 -> 0x3a -> 33:0 - mix 1, ADC 2
1155  * port-D 0x12 -> 0x3d -> mix 3, ADC 8
1156  * port-E 0x17 -> 0x3c -> 34:0 - mix 4, ADC 4
1157  * port-F 0x16 -> 0x3b -> mix 5, ADC 3
1158  * port-G 0x24 -> N/A  -> 33:1 - mix 1, 34:1 - mix 4, ADC 6
1159  * port-H 0x25 -> N/A  -> 33:2 - mix 1, 34:2 - mix 4, ADC 7
1160  *
1161  *
1162  * DAC assignment
1163  *   6stack - front/surr/CLFE/side/opt DACs - 04/06/05/0a/03
1164  *   3stack - front/surr/CLFE/opt DACs - 04/05/0a/03
1165  *
1166  * Inputs of Analog Mix (0x20)
1167  *   0:Port-B (front mic)
1168  *   1:Port-C/G/H (line-in)
1169  *   2:Port-A
1170  *   3:Port-D (line-in/2)
1171  *   4:Port-E/G/H (mic-in)
1172  *   5:Port-F (mic2-in)
1173  *   6:CD
1174  *   7:Beep
1175  *
1176  * ADC selection
1177  *   0:Port-A
1178  *   1:Port-B (front mic-in)
1179  *   2:Port-C (line-in)
1180  *   3:Port-F (mic2-in)
1181  *   4:Port-E (mic-in)
1182  *   5:CD
1183  *   6:Port-G
1184  *   7:Port-H
1185  *   8:Port-D (line-in/2)
1186  *   9:Mix
1187  *
1188  * Proposed pin assignments by the datasheet
1189  *
1190  * 6-stack
1191  * Port-A front headphone
1192  *      B front mic-in
1193  *      C rear line-in
1194  *      D rear front-out
1195  *      E rear mic-in
1196  *      F rear surround
1197  *      G rear CLFE
1198  *      H rear side
1199  *
1200  * 3-stack
1201  * Port-A front headphone
1202  *      B front mic
1203  *      C rear line-in/surround
1204  *      D rear front-out
1205  *      E rear mic-in/CLFE
1206  *
1207  * laptop
1208  * Port-A headphone
1209  *      B mic-in
1210  *      C docking station
1211  *      D internal speaker (with EAPD)
1212  *      E/F quad mic array
1213  */
1214
1215
1216 /* models */
1217 enum {
1218         AD1988_6STACK,
1219         AD1988_6STACK_DIG,
1220         AD1988_3STACK,
1221         AD1988_3STACK_DIG,
1222         AD1988_LAPTOP,
1223         AD1988_LAPTOP_DIG,
1224         AD1988_AUTO,
1225         AD1988_MODEL_LAST,
1226 };
1227
1228 /* reivision id to check workarounds */
1229 #define AD1988A_REV2            0x100200
1230
1231
1232 /*
1233  * mixers
1234  */
1235
1236 static hda_nid_t ad1988_6stack_dac_nids[4] = {
1237         0x04, 0x06, 0x05, 0x0a
1238 };
1239
1240 static hda_nid_t ad1988_3stack_dac_nids[3] = {
1241         0x04, 0x05, 0x0a
1242 };
1243
1244 /* for AD1988A revision-2, DAC2-4 are swapped */
1245 static hda_nid_t ad1988_6stack_dac_nids_rev2[4] = {
1246         0x04, 0x05, 0x0a, 0x06
1247 };
1248
1249 static hda_nid_t ad1988_3stack_dac_nids_rev2[3] = {
1250         0x04, 0x0a, 0x06
1251 };
1252
1253 static hda_nid_t ad1988_adc_nids[3] = {
1254         0x08, 0x09, 0x0f
1255 };
1256
1257 static hda_nid_t ad1988_capsrc_nids[3] = {
1258         0x0c, 0x0d, 0x0e
1259 };
1260
1261 #define AD1988_SPDIF_OUT        0x02
1262 #define AD1988_SPDIF_IN         0x07
1263
1264 static struct hda_input_mux ad1988_6stack_capture_source = {
1265         .num_items = 5,
1266         .items = {
1267                 { "Front Mic", 0x0 },
1268                 { "Line", 0x1 },
1269                 { "Mic", 0x4 },
1270                 { "CD", 0x5 },
1271                 { "Mix", 0x9 },
1272         },
1273 };
1274
1275 static struct hda_input_mux ad1988_laptop_capture_source = {
1276         .num_items = 3,
1277         .items = {
1278                 { "Mic/Line", 0x0 },
1279                 { "CD", 0x5 },
1280                 { "Mix", 0x9 },
1281         },
1282 };
1283
1284 /*
1285  */
1286 static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
1287                                struct snd_ctl_elem_info *uinfo)
1288 {
1289         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1290         struct ad198x_spec *spec = codec->spec;
1291         return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
1292                                     spec->num_channel_mode);
1293 }
1294
1295 static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
1296                               struct snd_ctl_elem_value *ucontrol)
1297 {
1298         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1299         struct ad198x_spec *spec = codec->spec;
1300         return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
1301                                    spec->num_channel_mode, spec->multiout.max_channels);
1302 }
1303
1304 static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
1305                               struct snd_ctl_elem_value *ucontrol)
1306 {
1307         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1308         struct ad198x_spec *spec = codec->spec;
1309         return snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
1310                                    spec->num_channel_mode, &spec->multiout.max_channels);
1311 }
1312
1313 /* 6-stack mode */
1314 static struct snd_kcontrol_new ad1988_6stack_mixers1[] = {
1315         HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1316         HDA_CODEC_VOLUME("Surround Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1317         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
1318         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
1319         HDA_CODEC_VOLUME("Side Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
1320 };
1321
1322 static struct snd_kcontrol_new ad1988_6stack_mixers1_rev2[] = {
1323         HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1324         HDA_CODEC_VOLUME("Surround Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1325         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
1326         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0a, 2, 0x0, HDA_OUTPUT),
1327         HDA_CODEC_VOLUME("Side Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1328 };
1329
1330 static struct snd_kcontrol_new ad1988_6stack_mixers2[] = {
1331         HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
1332         HDA_BIND_MUTE("Surround Playback Switch", 0x2a, 2, HDA_INPUT),
1333         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x27, 1, 2, HDA_INPUT),
1334         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x27, 2, 2, HDA_INPUT),
1335         HDA_BIND_MUTE("Side Playback Switch", 0x28, 2, HDA_INPUT),
1336         HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
1337         HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
1338
1339         HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
1340         HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
1341         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
1342         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
1343         HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
1344         HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
1345         HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
1346         HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
1347
1348         HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
1349         HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
1350
1351         HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
1352         HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
1353
1354         HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
1355         HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
1356
1357         { } /* end */
1358 };
1359
1360 /* 3-stack mode */
1361 static struct snd_kcontrol_new ad1988_3stack_mixers1[] = {
1362         HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1363         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
1364         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
1365         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
1366 };
1367
1368 static struct snd_kcontrol_new ad1988_3stack_mixers1_rev2[] = {
1369         HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1370         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
1371         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x06, 1, 0x0, HDA_OUTPUT),
1372         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x06, 2, 0x0, HDA_OUTPUT),
1373 };
1374
1375 static struct snd_kcontrol_new ad1988_3stack_mixers2[] = {
1376         HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
1377         HDA_BIND_MUTE("Surround Playback Switch", 0x2c, 2, HDA_INPUT),
1378         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x26, 1, 2, HDA_INPUT),
1379         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x26, 2, 2, HDA_INPUT),
1380         HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
1381         HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
1382
1383         HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
1384         HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
1385         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
1386         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
1387         HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
1388         HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
1389         HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
1390         HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
1391
1392         HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
1393         HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
1394
1395         HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
1396         HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
1397
1398         HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
1399         HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
1400         {
1401                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1402                 .name = "Channel Mode",
1403                 .info = ad198x_ch_mode_info,
1404                 .get = ad198x_ch_mode_get,
1405                 .put = ad198x_ch_mode_put,
1406         },
1407
1408         { } /* end */
1409 };
1410
1411 /* laptop mode */
1412 static struct snd_kcontrol_new ad1988_laptop_mixers[] = {
1413         HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1414         HDA_CODEC_MUTE("PCM Playback Switch", 0x29, 0x0, HDA_INPUT),
1415         HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
1416
1417         HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
1418         HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
1419         HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
1420         HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
1421         HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
1422         HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
1423
1424         HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
1425         HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
1426
1427         HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
1428         HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
1429
1430         HDA_CODEC_VOLUME("Mic Boost", 0x39, 0x0, HDA_OUTPUT),
1431
1432         {
1433                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1434                 .name = "External Amplifier",
1435                 .info = ad198x_eapd_info,
1436                 .get = ad198x_eapd_get,
1437                 .put = ad198x_eapd_put,
1438                 .private_value = 0x12 | (1 << 8), /* port-D, inversed */
1439         },
1440
1441         { } /* end */
1442 };
1443
1444 /* capture */
1445 static struct snd_kcontrol_new ad1988_capture_mixers[] = {
1446         HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
1447         HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
1448         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
1449         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
1450         HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x0e, 0x0, HDA_OUTPUT),
1451         HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x0e, 0x0, HDA_OUTPUT),
1452         {
1453                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1454                 /* The multiple "Capture Source" controls confuse alsamixer
1455                  * So call somewhat different..
1456                  * FIXME: the controls appear in the "playback" view!
1457                  */
1458                 /* .name = "Capture Source", */
1459                 .name = "Input Source",
1460                 .count = 3,
1461                 .info = ad198x_mux_enum_info,
1462                 .get = ad198x_mux_enum_get,
1463                 .put = ad198x_mux_enum_put,
1464         },
1465         { } /* end */
1466 };
1467
1468 static int ad1988_spdif_playback_source_info(struct snd_kcontrol *kcontrol,
1469                                              struct snd_ctl_elem_info *uinfo)
1470 {
1471         static char *texts[] = {
1472                 "PCM", "ADC1", "ADC2", "ADC3"
1473         };
1474         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1475         uinfo->count = 1;
1476         uinfo->value.enumerated.items = 4;
1477         if (uinfo->value.enumerated.item >= 4)
1478                 uinfo->value.enumerated.item = 3;
1479         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1480         return 0;
1481 }
1482
1483 static int ad1988_spdif_playback_source_get(struct snd_kcontrol *kcontrol,
1484                                             struct snd_ctl_elem_value *ucontrol)
1485 {
1486         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1487         unsigned int sel;
1488
1489         sel = snd_hda_codec_read(codec, 0x02, 0, AC_VERB_GET_CONNECT_SEL, 0);
1490         if (sel > 0) {
1491                 sel = snd_hda_codec_read(codec, 0x0b, 0, AC_VERB_GET_CONNECT_SEL, 0);
1492                 if (sel <= 3)
1493                         sel++;
1494                 else
1495                         sel = 0;
1496         }
1497         ucontrol->value.enumerated.item[0] = sel;
1498         return 0;
1499 }
1500
1501 static int ad1988_spdif_playback_source_put(struct snd_kcontrol *kcontrol,
1502                                             struct snd_ctl_elem_value *ucontrol)
1503 {
1504         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1505         unsigned int sel;
1506         int change;
1507
1508         sel = snd_hda_codec_read(codec, 0x02, 0, AC_VERB_GET_CONNECT_SEL, 0);
1509         if (! ucontrol->value.enumerated.item[0]) {
1510                 change = sel != 0;
1511                 if (change)
1512                         snd_hda_codec_write(codec, 0x02, 0, AC_VERB_SET_CONNECT_SEL, 0);
1513         } else {
1514                 change = sel == 0;
1515                 if (change)
1516                         snd_hda_codec_write(codec, 0x02, 0, AC_VERB_SET_CONNECT_SEL, 1);
1517                 sel = snd_hda_codec_read(codec, 0x0b, 0, AC_VERB_GET_CONNECT_SEL, 0) + 1;
1518                 change |= sel == ucontrol->value.enumerated.item[0];
1519                 if (change)
1520                         snd_hda_codec_write(codec, 0x02, 0, AC_VERB_SET_CONNECT_SEL,
1521                                             ucontrol->value.enumerated.item[0] - 1);
1522         }
1523         return change;
1524 }
1525
1526 static struct snd_kcontrol_new ad1988_spdif_out_mixers[] = {
1527         HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
1528         {
1529                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1530                 .name = "IEC958 Playback Source",
1531                 .info = ad1988_spdif_playback_source_info,
1532                 .get = ad1988_spdif_playback_source_get,
1533                 .put = ad1988_spdif_playback_source_put,
1534         },
1535         { } /* end */
1536 };
1537
1538 static struct snd_kcontrol_new ad1988_spdif_in_mixers[] = {
1539         HDA_CODEC_VOLUME("IEC958 Capture Volume", 0x1c, 0x0, HDA_INPUT),
1540         { } /* end */
1541 };
1542
1543
1544 /*
1545  * initialization verbs
1546  */
1547
1548 /*
1549  * for 6-stack (+dig)
1550  */
1551 static struct hda_verb ad1988_6stack_init_verbs[] = {
1552         /* Front, Surround, CLFE, side DAC; unmute as default */
1553         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1554         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1555         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1556         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1557         /* Port-A front headphon path */
1558         {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
1559         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1560         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1561         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1562         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1563         /* Port-D line-out path */
1564         {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1565         {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1566         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1567         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1568         /* Port-F surround path */
1569         {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1570         {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1571         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1572         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1573         /* Port-G CLFE path */
1574         {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1575         {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1576         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1577         {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1578         /* Port-H side path */
1579         {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1580         {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1581         {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1582         {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1583         /* Mono out path */
1584         {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
1585         {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1586         {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1587         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1588         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
1589         /* Port-B front mic-in path */
1590         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1591         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1592         {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1593         /* Port-C line-in path */
1594         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1595         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1596         {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1597         {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
1598         /* Port-E mic-in path */
1599         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1600         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1601         {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1602         {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
1603
1604         { }
1605 };
1606
1607 static struct hda_verb ad1988_capture_init_verbs[] = {
1608         /* mute analog mix */
1609         {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1610         {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1611         {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
1612         {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
1613         {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
1614         {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
1615         {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
1616         {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
1617         /* select ADCs - front-mic */
1618         {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
1619         {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
1620         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
1621         /* ADCs; muted */
1622         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1623         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1624         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1625
1626         { }
1627 };
1628
1629 static struct hda_verb ad1988_spdif_init_verbs[] = {
1630         /* SPDIF out sel */
1631         {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
1632         {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0}, /* ADC1 */
1633         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1634         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1635         /* SPDIF out pin */
1636         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
1637         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x17}, /* 0dB */
1638
1639         { }
1640 };
1641
1642 /*
1643  * verbs for 3stack (+dig)
1644  */
1645 static struct hda_verb ad1988_3stack_ch2_init[] = {
1646         /* set port-C to line-in */
1647         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1648         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1649         /* set port-E to mic-in */
1650         { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1651         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1652         { } /* end */
1653 };
1654
1655 static struct hda_verb ad1988_3stack_ch6_init[] = {
1656         /* set port-C to surround out */
1657         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1658         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1659         /* set port-E to CLFE out */
1660         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1661         { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1662         { } /* end */
1663 };
1664
1665 static struct hda_channel_mode ad1988_3stack_modes[2] = {
1666         { 2, ad1988_3stack_ch2_init },
1667         { 6, ad1988_3stack_ch6_init },
1668 };
1669
1670 static struct hda_verb ad1988_3stack_init_verbs[] = {
1671         /* Front, Surround, CLFE, side DAC; unmute as default */
1672         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1673         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1674         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1675         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1676         /* Port-A front headphon path */
1677         {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
1678         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1679         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1680         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1681         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1682         /* Port-D line-out path */
1683         {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1684         {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1685         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1686         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1687         /* Mono out path */
1688         {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
1689         {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1690         {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1691         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1692         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
1693         /* Port-B front mic-in path */
1694         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1695         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1696         {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1697         /* Port-C line-in/surround path - 6ch mode as default */
1698         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1699         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1700         {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1701         {0x31, AC_VERB_SET_CONNECT_SEL, 0x0}, /* output sel: DAC 0x05 */
1702         {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
1703         /* Port-E mic-in/CLFE path - 6ch mode as default */
1704         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1705         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1706         {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1707         {0x32, AC_VERB_SET_CONNECT_SEL, 0x1}, /* output sel: DAC 0x0a */
1708         {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
1709         /* mute analog mix */
1710         {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1711         {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1712         {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
1713         {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
1714         {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
1715         {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
1716         {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
1717         {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
1718         /* select ADCs - front-mic */
1719         {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
1720         {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
1721         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
1722         /* ADCs; muted */
1723         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1724         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1725         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1726         { }
1727 };
1728
1729 /*
1730  * verbs for laptop mode (+dig)
1731  */
1732 static struct hda_verb ad1988_laptop_hp_on[] = {
1733         /* unmute port-A and mute port-D */
1734         { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1735         { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1736         { } /* end */
1737 };
1738 static struct hda_verb ad1988_laptop_hp_off[] = {
1739         /* mute port-A and unmute port-D */
1740         { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1741         { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1742         { } /* end */
1743 };
1744
1745 #define AD1988_HP_EVENT 0x01
1746
1747 static struct hda_verb ad1988_laptop_init_verbs[] = {
1748         /* Front, Surround, CLFE, side DAC; unmute as default */
1749         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1750         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1751         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1752         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1753         /* Port-A front headphon path */
1754         {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
1755         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1756         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1757         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1758         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1759         /* unsolicited event for pin-sense */
1760         {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1988_HP_EVENT },
1761         /* Port-D line-out path + EAPD */
1762         {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1763         {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1764         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1765         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1766         {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x00}, /* EAPD-off */
1767         /* Mono out path */
1768         {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
1769         {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1770         {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1771         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1772         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
1773         /* Port-B mic-in path */
1774         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1775         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1776         {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1777         /* Port-C docking station - try to output */
1778         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1779         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1780         {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1781         {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
1782         /* mute analog mix */
1783         {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1784         {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1785         {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
1786         {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
1787         {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
1788         {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
1789         {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
1790         {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
1791         /* select ADCs - mic */
1792         {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
1793         {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
1794         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
1795         /* ADCs; muted */
1796         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1797         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1798         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1799         { }
1800 };
1801
1802 static void ad1988_laptop_unsol_event(struct hda_codec *codec, unsigned int res)
1803 {
1804         if ((res >> 26) != AD1988_HP_EVENT)
1805                 return;
1806         if (snd_hda_codec_read(codec, 0x11, 0, AC_VERB_GET_PIN_SENSE, 0) & (1 << 31))
1807                 snd_hda_sequence_write(codec, ad1988_laptop_hp_on);
1808         else
1809                 snd_hda_sequence_write(codec, ad1988_laptop_hp_off);
1810
1811
1812
1813 /*
1814  * Automatic parse of I/O pins from the BIOS configuration
1815  */
1816
1817 #define NUM_CONTROL_ALLOC       32
1818 #define NUM_VERB_ALLOC          32
1819
1820 enum {
1821         AD_CTL_WIDGET_VOL,
1822         AD_CTL_WIDGET_MUTE,
1823         AD_CTL_BIND_MUTE,
1824 };
1825 static struct snd_kcontrol_new ad1988_control_templates[] = {
1826         HDA_CODEC_VOLUME(NULL, 0, 0, 0),
1827         HDA_CODEC_MUTE(NULL, 0, 0, 0),
1828         HDA_BIND_MUTE(NULL, 0, 0, 0),
1829 };
1830
1831 /* add dynamic controls */
1832 static int add_control(struct ad198x_spec *spec, int type, const char *name,
1833                        unsigned long val)
1834 {
1835         struct snd_kcontrol_new *knew;
1836
1837         if (spec->num_kctl_used >= spec->num_kctl_alloc) {
1838                 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
1839
1840                 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
1841                 if (! knew)
1842                         return -ENOMEM;
1843                 if (spec->kctl_alloc) {
1844                         memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
1845                         kfree(spec->kctl_alloc);
1846                 }
1847                 spec->kctl_alloc = knew;
1848                 spec->num_kctl_alloc = num;
1849         }
1850
1851         knew = &spec->kctl_alloc[spec->num_kctl_used];
1852         *knew = ad1988_control_templates[type];
1853         knew->name = kstrdup(name, GFP_KERNEL);
1854         if (! knew->name)
1855                 return -ENOMEM;
1856         knew->private_value = val;
1857         spec->num_kctl_used++;
1858         return 0;
1859 }
1860
1861 #define AD1988_PIN_CD_NID               0x18
1862 #define AD1988_PIN_BEEP_NID             0x10
1863
1864 static hda_nid_t ad1988_mixer_nids[8] = {
1865         /* A     B     C     D     E     F     G     H */
1866         0x22, 0x2b, 0x2c, 0x29, 0x26, 0x2a, 0x27, 0x28
1867 };
1868
1869 static inline hda_nid_t ad1988_idx_to_dac(struct hda_codec *codec, int idx)
1870 {
1871         static hda_nid_t idx_to_dac[8] = {
1872                 /* A     B     C     D     E     F     G     H */
1873                 0x04, 0x06, 0x05, 0x04, 0x0a, 0x06, 0x05, 0x0a
1874         };
1875         static hda_nid_t idx_to_dac_rev2[8] = {
1876                 /* A     B     C     D     E     F     G     H */
1877                 0x04, 0x05, 0x0a, 0x04, 0x06, 0x05, 0x0a, 0x06
1878         };
1879         if (codec->revision_id == AD1988A_REV2)
1880                 return idx_to_dac_rev2[idx];
1881         else
1882                 return idx_to_dac[idx];
1883 }
1884
1885 static hda_nid_t ad1988_boost_nids[8] = {
1886         0x38, 0x39, 0x3a, 0x3d, 0x3c, 0x3b, 0, 0
1887 };
1888
1889 static int ad1988_pin_idx(hda_nid_t nid)
1890 {
1891         static hda_nid_t ad1988_io_pins[8] = {
1892                 0x11, 0x14, 0x15, 0x12, 0x17, 0x16, 0x24, 0x25
1893         };
1894         int i;
1895         for (i = 0; i < ARRAY_SIZE(ad1988_io_pins); i++)
1896                 if (ad1988_io_pins[i] == nid)
1897                         return i;
1898         return 0; /* should be -1 */
1899 }
1900
1901 static int ad1988_pin_to_loopback_idx(hda_nid_t nid)
1902 {
1903         static int loopback_idx[8] = {
1904                 2, 0, 1, 3, 4, 5, 1, 4
1905         };
1906         switch (nid) {
1907         case AD1988_PIN_CD_NID:
1908                 return 6;
1909         default:
1910                 return loopback_idx[ad1988_pin_idx(nid)];
1911         }
1912 }
1913
1914 static int ad1988_pin_to_adc_idx(hda_nid_t nid)
1915 {
1916         static int adc_idx[8] = {
1917                 0, 1, 2, 8, 4, 3, 6, 7
1918         };
1919         switch (nid) {
1920         case AD1988_PIN_CD_NID:
1921                 return 5;
1922         default:
1923                 return adc_idx[ad1988_pin_idx(nid)];
1924         }
1925 }
1926
1927 /* fill in the dac_nids table from the parsed pin configuration */
1928 static int ad1988_auto_fill_dac_nids(struct hda_codec *codec,
1929                                      const struct auto_pin_cfg *cfg)
1930 {
1931         struct ad198x_spec *spec = codec->spec;
1932         int i, idx;
1933
1934         spec->multiout.dac_nids = spec->private_dac_nids;
1935
1936         /* check the pins hardwired to audio widget */
1937         for (i = 0; i < cfg->line_outs; i++) {
1938                 idx = ad1988_pin_idx(cfg->line_out_pins[i]);
1939                 spec->multiout.dac_nids[i] = ad1988_idx_to_dac(codec, idx);
1940         }
1941         spec->multiout.num_dacs = cfg->line_outs;
1942         return 0;
1943 }
1944
1945 /* add playback controls from the parsed DAC table */
1946 static int ad1988_auto_create_multi_out_ctls(struct ad198x_spec *spec,
1947                                              const struct auto_pin_cfg *cfg)
1948 {
1949         char name[32];
1950         static const char *chname[4] = { "Front", "Surround", NULL /*CLFE*/, "Side" };
1951         hda_nid_t nid;
1952         int i, err;
1953
1954         for (i = 0; i < cfg->line_outs; i++) {
1955                 hda_nid_t dac = spec->multiout.dac_nids[i];
1956                 if (! dac)
1957                         continue;
1958                 nid = ad1988_mixer_nids[ad1988_pin_idx(cfg->line_out_pins[i])];
1959                 if (i == 2) {
1960                         /* Center/LFE */
1961                         err = add_control(spec, AD_CTL_WIDGET_VOL,
1962                                           "Center Playback Volume",
1963                                           HDA_COMPOSE_AMP_VAL(dac, 1, 0, HDA_OUTPUT));
1964                         if (err < 0)
1965                                 return err;
1966                         err = add_control(spec, AD_CTL_WIDGET_VOL,
1967                                           "LFE Playback Volume",
1968                                           HDA_COMPOSE_AMP_VAL(dac, 2, 0, HDA_OUTPUT));
1969                         if (err < 0)
1970                                 return err;
1971                         err = add_control(spec, AD_CTL_BIND_MUTE,
1972                                           "Center Playback Switch",
1973                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2, HDA_INPUT));
1974                         if (err < 0)
1975                                 return err;
1976                         err = add_control(spec, AD_CTL_BIND_MUTE,
1977                                           "LFE Playback Switch",
1978                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2, HDA_INPUT));
1979                         if (err < 0)
1980                                 return err;
1981                 } else {
1982                         sprintf(name, "%s Playback Volume", chname[i]);
1983                         err = add_control(spec, AD_CTL_WIDGET_VOL, name,
1984                                           HDA_COMPOSE_AMP_VAL(dac, 3, 0, HDA_OUTPUT));
1985                         if (err < 0)
1986                                 return err;
1987                         sprintf(name, "%s Playback Switch", chname[i]);
1988                         err = add_control(spec, AD_CTL_BIND_MUTE, name,
1989                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
1990                         if (err < 0)
1991                                 return err;
1992                 }
1993         }
1994         return 0;
1995 }
1996
1997 /* add playback controls for speaker and HP outputs */
1998 static int ad1988_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
1999                                         const char *pfx)
2000 {
2001         struct ad198x_spec *spec = codec->spec;
2002         hda_nid_t nid;
2003         int idx, err;
2004         char name[32];
2005
2006         if (! pin)
2007                 return 0;
2008
2009         idx = ad1988_pin_idx(pin);
2010         nid = ad1988_idx_to_dac(codec, idx);
2011         if (! spec->multiout.dac_nids[0]) {
2012                 /* use this as the primary output */
2013                 spec->multiout.dac_nids[0] = nid;
2014                 if (! spec->multiout.num_dacs)
2015                         spec->multiout.num_dacs = 1;
2016         } else 
2017                 /* specify the DAC as the extra output */
2018                 spec->multiout.hp_nid = nid;
2019         /* control HP volume/switch on the output mixer amp */
2020         sprintf(name, "%s Playback Volume", pfx);
2021         if ((err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2022                                HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
2023                 return err;
2024         nid = ad1988_mixer_nids[idx];
2025         sprintf(name, "%s Playback Switch", pfx);
2026         if ((err = add_control(spec, AD_CTL_BIND_MUTE, name,
2027                                HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT))) < 0)
2028                 return err;
2029         return 0;
2030 }
2031
2032 /* create input playback/capture controls for the given pin */
2033 static int new_analog_input(struct ad198x_spec *spec, hda_nid_t pin,
2034                             const char *ctlname, int boost)
2035 {
2036         char name[32];
2037         int err, idx;
2038
2039         sprintf(name, "%s Playback Volume", ctlname);
2040         idx = ad1988_pin_to_loopback_idx(pin);
2041         if ((err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2042                                HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
2043                 return err;
2044         sprintf(name, "%s Playback Switch", ctlname);
2045         if ((err = add_control(spec, AD_CTL_WIDGET_MUTE, name,
2046                                HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
2047                 return err;
2048         if (boost) {
2049                 hda_nid_t bnid;
2050                 idx = ad1988_pin_idx(pin);
2051                 bnid = ad1988_boost_nids[idx];
2052                 if (bnid) {
2053                         sprintf(name, "%s Boost", ctlname);
2054                         return add_control(spec, AD_CTL_WIDGET_VOL, name,
2055                                            HDA_COMPOSE_AMP_VAL(bnid, 3, idx, HDA_OUTPUT));
2056
2057                 }
2058         }
2059         return 0;
2060 }
2061
2062 /* create playback/capture controls for input pins */
2063 static int ad1988_auto_create_analog_input_ctls(struct ad198x_spec *spec,
2064                                                 const struct auto_pin_cfg *cfg)
2065 {
2066         struct hda_input_mux *imux = &spec->private_imux;
2067         int i, err;
2068
2069         for (i = 0; i < AUTO_PIN_LAST; i++) {
2070                 err = new_analog_input(spec, cfg->input_pins[i],
2071                                        auto_pin_cfg_labels[i],
2072                                        i <= AUTO_PIN_FRONT_MIC);
2073                 if (err < 0)
2074                         return err;
2075                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
2076                 imux->items[imux->num_items].index = ad1988_pin_to_adc_idx(cfg->input_pins[i]);
2077                 imux->num_items++;
2078         }
2079         imux->items[imux->num_items].label = "Mix";
2080         imux->items[imux->num_items].index = 9;
2081         imux->num_items++;
2082
2083         if ((err = add_control(spec, AD_CTL_WIDGET_VOL,
2084                                "Analog Mix Playback Volume",
2085                                HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
2086                 return err;
2087         if ((err = add_control(spec, AD_CTL_WIDGET_MUTE,
2088                                "Analog Mix Playback Switch",
2089                                HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
2090                 return err;
2091
2092         return 0;
2093 }
2094
2095 static void ad1988_auto_set_output_and_unmute(struct hda_codec *codec,
2096                                               hda_nid_t nid, int pin_type,
2097                                               int dac_idx)
2098 {
2099         /* set as output */
2100         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
2101         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
2102         switch (nid) {
2103         case 0x11: /* port-A - DAC 04 */
2104                 snd_hda_codec_write(codec, 0x37, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2105                 break;
2106         case 0x14: /* port-B - DAC 06 */
2107                 snd_hda_codec_write(codec, 0x30, 0, AC_VERB_SET_CONNECT_SEL, 0x02);
2108                 break;
2109         case 0x15: /* port-C - DAC 05 */
2110                 snd_hda_codec_write(codec, 0x31, 0, AC_VERB_SET_CONNECT_SEL, 0x00);
2111                 break;
2112         case 0x17: /* port-E - DAC 0a */
2113                 snd_hda_codec_write(codec, 0x32, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2114                 break;
2115         case 0x13: /* mono - DAC 04 */
2116                 snd_hda_codec_write(codec, 0x36, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2117                 break;
2118         }
2119 }
2120
2121 static void ad1988_auto_init_multi_out(struct hda_codec *codec)
2122 {
2123         struct ad198x_spec *spec = codec->spec;
2124         int i;
2125
2126         for (i = 0; i < spec->autocfg.line_outs; i++) {
2127                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
2128                 ad1988_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
2129         }
2130 }
2131
2132 static void ad1988_auto_init_extra_out(struct hda_codec *codec)
2133 {
2134         struct ad198x_spec *spec = codec->spec;
2135         hda_nid_t pin;
2136
2137         pin = spec->autocfg.speaker_pin;
2138         if (pin) /* connect to front */
2139                 ad1988_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
2140         pin = spec->autocfg.hp_pin;
2141         if (pin) /* connect to front */
2142                 ad1988_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
2143 }
2144
2145 static void ad1988_auto_init_analog_input(struct hda_codec *codec)
2146 {
2147         struct ad198x_spec *spec = codec->spec;
2148         int i, idx;
2149
2150         for (i = 0; i < AUTO_PIN_LAST; i++) {
2151                 hda_nid_t nid = spec->autocfg.input_pins[i];
2152                 if (! nid)
2153                         continue;
2154                 switch (nid) {
2155                 case 0x15: /* port-C */
2156                         snd_hda_codec_write(codec, 0x33, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
2157                         break;
2158                 case 0x17: /* port-E */
2159                         snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
2160                         break;
2161                 }
2162                 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2163                                     i <= AUTO_PIN_FRONT_MIC ? PIN_VREF80 : PIN_IN);
2164                 if (nid != AD1988_PIN_CD_NID)
2165                         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2166                                             AMP_OUT_MUTE);
2167                 idx = ad1988_pin_idx(nid);
2168                 if (ad1988_boost_nids[idx])
2169                         snd_hda_codec_write(codec, ad1988_boost_nids[idx], 0,
2170                                             AC_VERB_SET_AMP_GAIN_MUTE,
2171                                             AMP_OUT_ZERO);
2172         }
2173 }
2174
2175 /* parse the BIOS configuration and set up the alc_spec */
2176 /* return 1 if successful, 0 if the proper config is not found, or a negative error code */
2177 static int ad1988_parse_auto_config(struct hda_codec *codec)
2178 {
2179         struct ad198x_spec *spec = codec->spec;
2180         int err;
2181
2182         if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
2183                 return err;
2184         if ((err = ad1988_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
2185                 return err;
2186         if (! spec->autocfg.line_outs && ! spec->autocfg.speaker_pin &&
2187             ! spec->autocfg.hp_pin)
2188                 return 0; /* can't find valid BIOS pin config */
2189         if ((err = ad1988_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
2190             (err = ad1988_auto_create_extra_out(codec, spec->autocfg.speaker_pin,
2191                                                 "Speaker")) < 0 ||
2192             (err = ad1988_auto_create_extra_out(codec, spec->autocfg.speaker_pin,
2193                                                 "Headphone")) < 0 ||
2194             (err = ad1988_auto_create_analog_input_ctls(spec, &spec->autocfg)) < 0)
2195                 return err;
2196
2197         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2198
2199         if (spec->autocfg.dig_out_pin)
2200                 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2201         if (spec->autocfg.dig_in_pin)
2202                 spec->dig_in_nid = AD1988_SPDIF_IN;
2203
2204         if (spec->kctl_alloc)
2205                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
2206
2207         spec->init_verbs[spec->num_init_verbs++] = ad1988_6stack_init_verbs;
2208
2209         spec->input_mux = &spec->private_imux;
2210
2211         return 1;
2212 }
2213
2214 /* init callback for auto-configuration model -- overriding the default init */
2215 static int ad1988_auto_init(struct hda_codec *codec)
2216 {
2217         ad198x_init(codec);
2218         ad1988_auto_init_multi_out(codec);
2219         ad1988_auto_init_extra_out(codec);
2220         ad1988_auto_init_analog_input(codec);
2221         return 0;
2222 }
2223
2224
2225 /*
2226  */
2227
2228 static struct hda_board_config ad1988_cfg_tbl[] = {
2229         { .modelname = "6stack",        .config = AD1988_6STACK },
2230         { .modelname = "6stack-dig",    .config = AD1988_6STACK_DIG },
2231         { .modelname = "3stack",        .config = AD1988_3STACK },
2232         { .modelname = "3stack-dig",    .config = AD1988_3STACK_DIG },
2233         { .modelname = "laptop",        .config = AD1988_LAPTOP },
2234         { .modelname = "laptop-dig",    .config = AD1988_LAPTOP_DIG },
2235         { .modelname = "auto",          .config = AD1988_AUTO },
2236         {}
2237 };
2238
2239 static int patch_ad1988(struct hda_codec *codec)
2240 {
2241         struct ad198x_spec *spec;
2242         int board_config;
2243
2244         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2245         if (spec == NULL)
2246                 return -ENOMEM;
2247
2248         mutex_init(&spec->amp_mutex);
2249         codec->spec = spec;
2250
2251         if (codec->revision_id == AD1988A_REV2)
2252                 snd_printk(KERN_INFO "patch_analog: AD1988A rev.2 is detected, enable workarounds\n");
2253
2254         board_config = snd_hda_check_board_config(codec, ad1988_cfg_tbl);
2255         if (board_config < 0 || board_config >= AD1988_MODEL_LAST) {
2256                 printk(KERN_INFO "hda_codec: Unknown model for AD1988, trying auto-probe from BIOS...\n");
2257                 board_config = AD1988_AUTO;
2258         }
2259
2260         if (board_config == AD1988_AUTO) {
2261                 /* automatic parse from the BIOS config */
2262                 int err = ad1988_parse_auto_config(codec);
2263                 if (err < 0) {
2264                         ad198x_free(codec);
2265                         return err;
2266                 } else if (! err) {
2267                         printk(KERN_INFO "hda_codec: Cannot set up configuration from BIOS.  Using 6-stack mode...\n");
2268                         board_config = AD1988_6STACK;
2269                 }
2270         }
2271
2272         switch (board_config) {
2273         case AD1988_6STACK:
2274         case AD1988_6STACK_DIG:
2275                 spec->multiout.max_channels = 8;
2276                 spec->multiout.num_dacs = 4;
2277                 if (codec->revision_id == AD1988A_REV2)
2278                         spec->multiout.dac_nids = ad1988_6stack_dac_nids_rev2;
2279                 else
2280                         spec->multiout.dac_nids = ad1988_6stack_dac_nids;
2281                 spec->input_mux = &ad1988_6stack_capture_source;
2282                 spec->num_mixers = 2;
2283                 if (codec->revision_id == AD1988A_REV2)
2284                         spec->mixers[0] = ad1988_6stack_mixers1_rev2;
2285                 else
2286                         spec->mixers[0] = ad1988_6stack_mixers1;
2287                 spec->mixers[1] = ad1988_6stack_mixers2;
2288                 spec->num_init_verbs = 1;
2289                 spec->init_verbs[0] = ad1988_6stack_init_verbs;
2290                 if (board_config == AD1988_6STACK_DIG) {
2291                         spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2292                         spec->dig_in_nid = AD1988_SPDIF_IN;
2293                 }
2294                 break;
2295         case AD1988_3STACK:
2296         case AD1988_3STACK_DIG:
2297                 spec->multiout.max_channels = 6;
2298                 spec->multiout.num_dacs = 3;
2299                 if (codec->revision_id == AD1988A_REV2)
2300                         spec->multiout.dac_nids = ad1988_3stack_dac_nids_rev2;
2301                 else
2302                         spec->multiout.dac_nids = ad1988_3stack_dac_nids;
2303                 spec->input_mux = &ad1988_6stack_capture_source;
2304                 spec->channel_mode = ad1988_3stack_modes;
2305                 spec->num_channel_mode = ARRAY_SIZE(ad1988_3stack_modes);
2306                 spec->num_mixers = 2;
2307                 if (codec->revision_id == AD1988A_REV2)
2308                         spec->mixers[0] = ad1988_3stack_mixers1_rev2;
2309                 else
2310                         spec->mixers[0] = ad1988_3stack_mixers1;
2311                 spec->mixers[1] = ad1988_3stack_mixers2;
2312                 spec->num_init_verbs = 1;
2313                 spec->init_verbs[0] = ad1988_3stack_init_verbs;
2314                 if (board_config == AD1988_3STACK_DIG)
2315                         spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2316                 break;
2317         case AD1988_LAPTOP:
2318         case AD1988_LAPTOP_DIG:
2319                 spec->multiout.max_channels = 2;
2320                 spec->multiout.num_dacs = 1;
2321                 spec->multiout.dac_nids = ad1988_3stack_dac_nids;
2322                 spec->input_mux = &ad1988_laptop_capture_source;
2323                 spec->num_mixers = 1;
2324                 spec->mixers[0] = ad1988_laptop_mixers;
2325                 spec->num_init_verbs = 1;
2326                 spec->init_verbs[0] = ad1988_laptop_init_verbs;
2327                 if (board_config == AD1988_LAPTOP_DIG)
2328                         spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2329                 break;
2330         }
2331
2332         spec->num_adc_nids = ARRAY_SIZE(ad1988_adc_nids);
2333         spec->adc_nids = ad1988_adc_nids;
2334         spec->capsrc_nids = ad1988_capsrc_nids;
2335         spec->mixers[spec->num_mixers++] = ad1988_capture_mixers;
2336         spec->init_verbs[spec->num_init_verbs++] = ad1988_capture_init_verbs;
2337         if (spec->multiout.dig_out_nid) {
2338                 spec->mixers[spec->num_mixers++] = ad1988_spdif_out_mixers;
2339                 spec->init_verbs[spec->num_init_verbs++] = ad1988_spdif_init_verbs;
2340         }
2341         if (spec->dig_in_nid)
2342                 spec->mixers[spec->num_mixers++] = ad1988_spdif_in_mixers;
2343
2344         codec->patch_ops = ad198x_patch_ops;
2345         switch (board_config) {
2346         case AD1988_AUTO:
2347                 codec->patch_ops.init = ad1988_auto_init;
2348                 break;
2349         case AD1988_LAPTOP:
2350         case AD1988_LAPTOP_DIG:
2351                 codec->patch_ops.unsol_event = ad1988_laptop_unsol_event;
2352                 break;
2353         }
2354
2355         return 0;
2356 }
2357
2358
2359 /*
2360  * patch entries
2361  */
2362 struct hda_codec_preset snd_hda_preset_analog[] = {
2363         { .id = 0x11d41981, .name = "AD1981", .patch = patch_ad1981 },
2364         { .id = 0x11d41983, .name = "AD1983", .patch = patch_ad1983 },
2365         { .id = 0x11d41986, .name = "AD1986A", .patch = patch_ad1986a },
2366         { .id = 0x11d41988, .name = "AD1988", .patch = patch_ad1988 },
2367         {} /* terminator */
2368 };