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