ALSA: hda - Avoid overwrite of jack events with STAC/IDT
[pandora-kernel.git] / sound / pci / hda / patch_sigmatel.c
1 /*
2  * Universal Interface for Intel High Definition Audio Codec
3  *
4  * HD audio interface patch for SigmaTel STAC92xx
5  *
6  * Copyright (c) 2005 Embedded Alley Solutions, Inc.
7  * Matt Porter <mporter@embeddedalley.com>
8  *
9  * Based on patch_cmedia.c and patch_realtek.c
10  * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
11  *
12  *  This driver is free software; you can redistribute it and/or modify
13  *  it under the terms of the GNU General Public License as published by
14  *  the Free Software Foundation; either version 2 of the License, or
15  *  (at your option) any later version.
16  *
17  *  This driver is distributed in the hope that it will be useful,
18  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  *  GNU General Public License for more details.
21  *
22  *  You should have received a copy of the GNU General Public License
23  *  along with this program; if not, write to the Free Software
24  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
25  */
26
27 #include <linux/init.h>
28 #include <linux/delay.h>
29 #include <linux/slab.h>
30 #include <linux/pci.h>
31 #include <sound/core.h>
32 #include <sound/asoundef.h>
33 #include <sound/jack.h>
34 #include "hda_codec.h"
35 #include "hda_local.h"
36 #include "hda_beep.h"
37
38 enum {
39         STAC_VREF_EVENT = 1,
40         STAC_INSERT_EVENT,
41         STAC_PWR_EVENT,
42         STAC_HP_EVENT,
43 };
44
45 enum {
46         STAC_AUTO,
47         STAC_REF,
48         STAC_9200_OQO,
49         STAC_9200_DELL_D21,
50         STAC_9200_DELL_D22,
51         STAC_9200_DELL_D23,
52         STAC_9200_DELL_M21,
53         STAC_9200_DELL_M22,
54         STAC_9200_DELL_M23,
55         STAC_9200_DELL_M24,
56         STAC_9200_DELL_M25,
57         STAC_9200_DELL_M26,
58         STAC_9200_DELL_M27,
59         STAC_9200_M4,
60         STAC_9200_M4_2,
61         STAC_9200_PANASONIC,
62         STAC_9200_MODELS
63 };
64
65 enum {
66         STAC_9205_AUTO,
67         STAC_9205_REF,
68         STAC_9205_DELL_M42,
69         STAC_9205_DELL_M43,
70         STAC_9205_DELL_M44,
71         STAC_9205_EAPD,
72         STAC_9205_MODELS
73 };
74
75 enum {
76         STAC_92HD73XX_AUTO,
77         STAC_92HD73XX_NO_JD, /* no jack-detection */
78         STAC_92HD73XX_REF,
79         STAC_DELL_M6_AMIC,
80         STAC_DELL_M6_DMIC,
81         STAC_DELL_M6_BOTH,
82         STAC_DELL_EQ,
83         STAC_92HD73XX_MODELS
84 };
85
86 enum {
87         STAC_92HD83XXX_AUTO,
88         STAC_92HD83XXX_REF,
89         STAC_92HD83XXX_PWR_REF,
90         STAC_DELL_S14,
91         STAC_92HD83XXX_MODELS
92 };
93
94 enum {
95         STAC_92HD71BXX_AUTO,
96         STAC_92HD71BXX_REF,
97         STAC_DELL_M4_1,
98         STAC_DELL_M4_2,
99         STAC_DELL_M4_3,
100         STAC_HP_M4,
101         STAC_HP_DV5,
102         STAC_HP_HDX,
103         STAC_HP_DV4_1222NR,
104         STAC_92HD71BXX_MODELS
105 };
106
107 enum {
108         STAC_925x_AUTO,
109         STAC_925x_REF,
110         STAC_M1,
111         STAC_M1_2,
112         STAC_M2,
113         STAC_M2_2,
114         STAC_M3,
115         STAC_M5,
116         STAC_M6,
117         STAC_925x_MODELS
118 };
119
120 enum {
121         STAC_922X_AUTO,
122         STAC_D945_REF,
123         STAC_D945GTP3,
124         STAC_D945GTP5,
125         STAC_INTEL_MAC_V1,
126         STAC_INTEL_MAC_V2,
127         STAC_INTEL_MAC_V3,
128         STAC_INTEL_MAC_V4,
129         STAC_INTEL_MAC_V5,
130         STAC_INTEL_MAC_AUTO, /* This model is selected if no module parameter
131                               * is given, one of the above models will be
132                               * chosen according to the subsystem id. */
133         /* for backward compatibility */
134         STAC_MACMINI,
135         STAC_MACBOOK,
136         STAC_MACBOOK_PRO_V1,
137         STAC_MACBOOK_PRO_V2,
138         STAC_IMAC_INTEL,
139         STAC_IMAC_INTEL_20,
140         STAC_ECS_202,
141         STAC_922X_DELL_D81,
142         STAC_922X_DELL_D82,
143         STAC_922X_DELL_M81,
144         STAC_922X_DELL_M82,
145         STAC_922X_MODELS
146 };
147
148 enum {
149         STAC_927X_AUTO,
150         STAC_D965_REF_NO_JD, /* no jack-detection */
151         STAC_D965_REF,
152         STAC_D965_3ST,
153         STAC_D965_5ST,
154         STAC_D965_5ST_NO_FP,
155         STAC_DELL_3ST,
156         STAC_DELL_BIOS,
157         STAC_927X_MODELS
158 };
159
160 enum {
161         STAC_9872_AUTO,
162         STAC_9872_VAIO,
163         STAC_9872_MODELS
164 };
165
166 struct sigmatel_event {
167         hda_nid_t nid;
168         unsigned char type;
169         unsigned char tag;
170         int data;
171 };
172
173 struct sigmatel_jack {
174         hda_nid_t nid;
175         int type;
176         struct snd_jack *jack;
177 };
178
179 struct sigmatel_spec {
180         struct snd_kcontrol_new *mixers[4];
181         unsigned int num_mixers;
182
183         int board_config;
184         unsigned int eapd_switch: 1;
185         unsigned int surr_switch: 1;
186         unsigned int alt_switch: 1;
187         unsigned int hp_detect: 1;
188         unsigned int spdif_mute: 1;
189         unsigned int check_volume_offset:1;
190
191         /* gpio lines */
192         unsigned int eapd_mask;
193         unsigned int gpio_mask;
194         unsigned int gpio_dir;
195         unsigned int gpio_data;
196         unsigned int gpio_mute;
197         unsigned int gpio_led;
198
199         /* stream */
200         unsigned int stream_delay;
201
202         /* analog loopback */
203         struct snd_kcontrol_new *aloopback_ctl;
204         unsigned char aloopback_mask;
205         unsigned char aloopback_shift;
206
207         /* power management */
208         unsigned int num_pwrs;
209         unsigned int *pwr_mapping;
210         hda_nid_t *pwr_nids;
211         hda_nid_t *dac_list;
212
213         /* jack detection */
214         struct snd_array jacks;
215
216         /* events */
217         struct snd_array events;
218
219         /* playback */
220         struct hda_input_mux *mono_mux;
221         struct hda_input_mux *amp_mux;
222         unsigned int cur_mmux;
223         struct hda_multi_out multiout;
224         hda_nid_t dac_nids[5];
225         hda_nid_t hp_dacs[5];
226         hda_nid_t speaker_dacs[5];
227
228         int volume_offset;
229
230         /* capture */
231         hda_nid_t *adc_nids;
232         unsigned int num_adcs;
233         hda_nid_t *mux_nids;
234         unsigned int num_muxes;
235         hda_nid_t *dmic_nids;
236         unsigned int num_dmics;
237         hda_nid_t *dmux_nids;
238         unsigned int num_dmuxes;
239         hda_nid_t *smux_nids;
240         unsigned int num_smuxes;
241
242         unsigned long *capvols; /* amp-volume attr: HDA_COMPOSE_AMP_VAL() */
243         unsigned long *capsws; /* amp-mute attr: HDA_COMPOSE_AMP_VAL() */
244         unsigned int num_caps; /* number of capture volume/switch elements */
245
246         const char **spdif_labels;
247
248         hda_nid_t dig_in_nid;
249         hda_nid_t mono_nid;
250         hda_nid_t anabeep_nid;
251         hda_nid_t digbeep_nid;
252
253         /* pin widgets */
254         hda_nid_t *pin_nids;
255         unsigned int num_pins;
256
257         /* codec specific stuff */
258         struct hda_verb *init;
259         struct snd_kcontrol_new *mixer;
260
261         /* capture source */
262         struct hda_input_mux *dinput_mux;
263         unsigned int cur_dmux[2];
264         struct hda_input_mux *input_mux;
265         unsigned int cur_mux[3];
266         struct hda_input_mux *sinput_mux;
267         unsigned int cur_smux[2];
268         unsigned int cur_amux;
269         hda_nid_t *amp_nids;
270         unsigned int num_amps;
271         unsigned int powerdown_adcs;
272
273         /* i/o switches */
274         unsigned int io_switch[2];
275         unsigned int clfe_swap;
276         hda_nid_t line_switch;  /* shared line-in for input and output */
277         hda_nid_t mic_switch;   /* shared mic-in for input and output */
278         hda_nid_t hp_switch; /* NID of HP as line-out */
279         unsigned int aloopback;
280
281         struct hda_pcm pcm_rec[2];      /* PCM information */
282
283         /* dynamic controls and input_mux */
284         struct auto_pin_cfg autocfg;
285         struct snd_array kctls;
286         struct hda_input_mux private_dimux;
287         struct hda_input_mux private_imux;
288         struct hda_input_mux private_smux;
289         struct hda_input_mux private_amp_mux;
290         struct hda_input_mux private_mono_mux;
291 };
292
293 static hda_nid_t stac9200_adc_nids[1] = {
294         0x03,
295 };
296
297 static hda_nid_t stac9200_mux_nids[1] = {
298         0x0c,
299 };
300
301 static hda_nid_t stac9200_dac_nids[1] = {
302         0x02,
303 };
304
305 static hda_nid_t stac92hd73xx_pwr_nids[8] = {
306         0x0a, 0x0b, 0x0c, 0xd, 0x0e,
307         0x0f, 0x10, 0x11
308 };
309
310 static hda_nid_t stac92hd73xx_slave_dig_outs[2] = {
311         0x26, 0,
312 };
313
314 static hda_nid_t stac92hd73xx_adc_nids[2] = {
315         0x1a, 0x1b
316 };
317
318 #define DELL_M6_AMP 2
319 static hda_nid_t stac92hd73xx_amp_nids[3] = {
320         0x0b, 0x0c, 0x0e
321 };
322
323 #define STAC92HD73XX_NUM_DMICS  2
324 static hda_nid_t stac92hd73xx_dmic_nids[STAC92HD73XX_NUM_DMICS + 1] = {
325         0x13, 0x14, 0
326 };
327
328 #define STAC92HD73_DAC_COUNT 5
329
330 static hda_nid_t stac92hd73xx_mux_nids[4] = {
331         0x28, 0x29, 0x2a, 0x2b,
332 };
333
334 static hda_nid_t stac92hd73xx_dmux_nids[2] = {
335         0x20, 0x21,
336 };
337
338 static hda_nid_t stac92hd73xx_smux_nids[2] = {
339         0x22, 0x23,
340 };
341
342 #define STAC92HD73XX_NUM_CAPS   2
343 static unsigned long stac92hd73xx_capvols[] = {
344         HDA_COMPOSE_AMP_VAL(0x20, 3, 0, HDA_OUTPUT),
345         HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
346 };
347 #define stac92hd73xx_capsws     stac92hd73xx_capvols
348
349 #define STAC92HD83XXX_NUM_DMICS 2
350 static hda_nid_t stac92hd83xxx_dmic_nids[STAC92HD83XXX_NUM_DMICS + 1] = {
351         0x11, 0x12, 0
352 };
353
354 #define STAC92HD83_DAC_COUNT 3
355
356 static hda_nid_t stac92hd83xxx_dmux_nids[2] = {
357         0x17, 0x18,
358 };
359
360 static hda_nid_t stac92hd83xxx_adc_nids[2] = {
361         0x15, 0x16,
362 };
363
364 static hda_nid_t stac92hd83xxx_pwr_nids[4] = {
365         0xa, 0xb, 0xd, 0xe,
366 };
367
368 static hda_nid_t stac92hd83xxx_slave_dig_outs[2] = {
369         0x1e, 0,
370 };
371
372 static unsigned int stac92hd83xxx_pwr_mapping[4] = {
373         0x03, 0x0c, 0x20, 0x40,
374 };
375
376 static hda_nid_t stac92hd83xxx_amp_nids[1] = {
377         0xc,
378 };
379
380 #define STAC92HD83XXX_NUM_CAPS  2
381 static unsigned long stac92hd83xxx_capvols[] = {
382         HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_OUTPUT),
383         HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_OUTPUT),
384 };
385 #define stac92hd83xxx_capsws    stac92hd83xxx_capvols
386
387 static hda_nid_t stac92hd71bxx_pwr_nids[3] = {
388         0x0a, 0x0d, 0x0f
389 };
390
391 static hda_nid_t stac92hd71bxx_adc_nids[2] = {
392         0x12, 0x13,
393 };
394
395 static hda_nid_t stac92hd71bxx_mux_nids[2] = {
396         0x1a, 0x1b
397 };
398
399 static hda_nid_t stac92hd71bxx_dmux_nids[2] = {
400         0x1c, 0x1d,
401 };
402
403 static hda_nid_t stac92hd71bxx_smux_nids[2] = {
404         0x24, 0x25,
405 };
406
407 #define STAC92HD71BXX_NUM_DMICS 2
408 static hda_nid_t stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS + 1] = {
409         0x18, 0x19, 0
410 };
411
412 static hda_nid_t stac92hd71bxx_slave_dig_outs[2] = {
413         0x22, 0
414 };
415
416 #define STAC92HD71BXX_NUM_CAPS          2
417 static unsigned long stac92hd71bxx_capvols[] = {
418         HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
419         HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
420 };
421 #define stac92hd71bxx_capsws    stac92hd71bxx_capvols
422
423 static hda_nid_t stac925x_adc_nids[1] = {
424         0x03,
425 };
426
427 static hda_nid_t stac925x_mux_nids[1] = {
428         0x0f,
429 };
430
431 static hda_nid_t stac925x_dac_nids[1] = {
432         0x02,
433 };
434
435 #define STAC925X_NUM_DMICS      1
436 static hda_nid_t stac925x_dmic_nids[STAC925X_NUM_DMICS + 1] = {
437         0x15, 0
438 };
439
440 static hda_nid_t stac925x_dmux_nids[1] = {
441         0x14,
442 };
443
444 static unsigned long stac925x_capvols[] = {
445         HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
446 };
447 static unsigned long stac925x_capsws[] = {
448         HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
449 };
450
451 static hda_nid_t stac922x_adc_nids[2] = {
452         0x06, 0x07,
453 };
454
455 static hda_nid_t stac922x_mux_nids[2] = {
456         0x12, 0x13,
457 };
458
459 #define STAC922X_NUM_CAPS       2
460 static unsigned long stac922x_capvols[] = {
461         HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_INPUT),
462         HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT),
463 };
464 #define stac922x_capsws         stac922x_capvols
465
466 static hda_nid_t stac927x_slave_dig_outs[2] = {
467         0x1f, 0,
468 };
469
470 static hda_nid_t stac927x_adc_nids[3] = {
471         0x07, 0x08, 0x09
472 };
473
474 static hda_nid_t stac927x_mux_nids[3] = {
475         0x15, 0x16, 0x17
476 };
477
478 static hda_nid_t stac927x_smux_nids[1] = {
479         0x21,
480 };
481
482 static hda_nid_t stac927x_dac_nids[6] = {
483         0x02, 0x03, 0x04, 0x05, 0x06, 0
484 };
485
486 static hda_nid_t stac927x_dmux_nids[1] = {
487         0x1b,
488 };
489
490 #define STAC927X_NUM_DMICS 2
491 static hda_nid_t stac927x_dmic_nids[STAC927X_NUM_DMICS + 1] = {
492         0x13, 0x14, 0
493 };
494
495 #define STAC927X_NUM_CAPS       3
496 static unsigned long stac927x_capvols[] = {
497         HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT),
498         HDA_COMPOSE_AMP_VAL(0x19, 3, 0, HDA_INPUT),
499         HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_INPUT),
500 };
501 static unsigned long stac927x_capsws[] = {
502         HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
503         HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
504         HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
505 };
506
507 static const char *stac927x_spdif_labels[5] = {
508         "Digital Playback", "ADAT", "Analog Mux 1",
509         "Analog Mux 2", "Analog Mux 3"
510 };
511
512 static hda_nid_t stac9205_adc_nids[2] = {
513         0x12, 0x13
514 };
515
516 static hda_nid_t stac9205_mux_nids[2] = {
517         0x19, 0x1a
518 };
519
520 static hda_nid_t stac9205_dmux_nids[1] = {
521         0x1d,
522 };
523
524 static hda_nid_t stac9205_smux_nids[1] = {
525         0x21,
526 };
527
528 #define STAC9205_NUM_DMICS      2
529 static hda_nid_t stac9205_dmic_nids[STAC9205_NUM_DMICS + 1] = {
530         0x17, 0x18, 0
531 };
532
533 #define STAC9205_NUM_CAPS       2
534 static unsigned long stac9205_capvols[] = {
535         HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_INPUT),
536         HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_INPUT),
537 };
538 static unsigned long stac9205_capsws[] = {
539         HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
540         HDA_COMPOSE_AMP_VAL(0x1e, 3, 0, HDA_OUTPUT),
541 };
542
543 static hda_nid_t stac9200_pin_nids[8] = {
544         0x08, 0x09, 0x0d, 0x0e, 
545         0x0f, 0x10, 0x11, 0x12,
546 };
547
548 static hda_nid_t stac925x_pin_nids[8] = {
549         0x07, 0x08, 0x0a, 0x0b, 
550         0x0c, 0x0d, 0x10, 0x11,
551 };
552
553 static hda_nid_t stac922x_pin_nids[10] = {
554         0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
555         0x0f, 0x10, 0x11, 0x15, 0x1b,
556 };
557
558 static hda_nid_t stac92hd73xx_pin_nids[13] = {
559         0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
560         0x0f, 0x10, 0x11, 0x12, 0x13,
561         0x14, 0x22, 0x23
562 };
563
564 static hda_nid_t stac92hd83xxx_pin_nids[10] = {
565         0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
566         0x0f, 0x10, 0x11, 0x1f, 0x20,
567 };
568
569 #define STAC92HD71BXX_NUM_PINS 13
570 static hda_nid_t stac92hd71bxx_pin_nids_4port[STAC92HD71BXX_NUM_PINS] = {
571         0x0a, 0x0b, 0x0c, 0x0d, 0x00,
572         0x00, 0x14, 0x18, 0x19, 0x1e,
573         0x1f, 0x20, 0x27
574 };
575 static hda_nid_t stac92hd71bxx_pin_nids_6port[STAC92HD71BXX_NUM_PINS] = {
576         0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
577         0x0f, 0x14, 0x18, 0x19, 0x1e,
578         0x1f, 0x20, 0x27
579 };
580
581 static hda_nid_t stac927x_pin_nids[14] = {
582         0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
583         0x0f, 0x10, 0x11, 0x12, 0x13,
584         0x14, 0x21, 0x22, 0x23,
585 };
586
587 static hda_nid_t stac9205_pin_nids[12] = {
588         0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
589         0x0f, 0x14, 0x16, 0x17, 0x18,
590         0x21, 0x22,
591 };
592
593 #define stac92xx_amp_volume_info snd_hda_mixer_amp_volume_info
594
595 static int stac92xx_amp_volume_get(struct snd_kcontrol *kcontrol,
596                                  struct snd_ctl_elem_value *ucontrol)
597 {
598         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
599         struct sigmatel_spec *spec = codec->spec;
600         hda_nid_t nid = spec->amp_nids[spec->cur_amux];
601
602         kcontrol->private_value ^= get_amp_nid(kcontrol);
603         kcontrol->private_value |= nid;
604
605         return snd_hda_mixer_amp_volume_get(kcontrol, ucontrol);
606 }
607
608 static int stac92xx_amp_volume_put(struct snd_kcontrol *kcontrol,
609                                  struct snd_ctl_elem_value *ucontrol)
610 {
611         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
612         struct sigmatel_spec *spec = codec->spec;
613         hda_nid_t nid = spec->amp_nids[spec->cur_amux];
614
615         kcontrol->private_value ^= get_amp_nid(kcontrol);
616         kcontrol->private_value |= nid;
617
618         return snd_hda_mixer_amp_volume_put(kcontrol, ucontrol);
619 }
620
621 static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
622                                    struct snd_ctl_elem_info *uinfo)
623 {
624         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
625         struct sigmatel_spec *spec = codec->spec;
626         return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
627 }
628
629 static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
630                                   struct snd_ctl_elem_value *ucontrol)
631 {
632         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
633         struct sigmatel_spec *spec = codec->spec;
634         unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
635
636         ucontrol->value.enumerated.item[0] = spec->cur_dmux[dmux_idx];
637         return 0;
638 }
639
640 static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
641                                   struct snd_ctl_elem_value *ucontrol)
642 {
643         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
644         struct sigmatel_spec *spec = codec->spec;
645         unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
646
647         return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
648                         spec->dmux_nids[dmux_idx], &spec->cur_dmux[dmux_idx]);
649 }
650
651 static int stac92xx_smux_enum_info(struct snd_kcontrol *kcontrol,
652                                    struct snd_ctl_elem_info *uinfo)
653 {
654         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
655         struct sigmatel_spec *spec = codec->spec;
656         return snd_hda_input_mux_info(spec->sinput_mux, uinfo);
657 }
658
659 static int stac92xx_smux_enum_get(struct snd_kcontrol *kcontrol,
660                                   struct snd_ctl_elem_value *ucontrol)
661 {
662         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
663         struct sigmatel_spec *spec = codec->spec;
664         unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
665
666         ucontrol->value.enumerated.item[0] = spec->cur_smux[smux_idx];
667         return 0;
668 }
669
670 static int stac92xx_smux_enum_put(struct snd_kcontrol *kcontrol,
671                                   struct snd_ctl_elem_value *ucontrol)
672 {
673         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
674         struct sigmatel_spec *spec = codec->spec;
675         struct hda_input_mux *smux = &spec->private_smux;
676         unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
677         int err, val;
678         hda_nid_t nid;
679
680         err = snd_hda_input_mux_put(codec, spec->sinput_mux, ucontrol,
681                         spec->smux_nids[smux_idx], &spec->cur_smux[smux_idx]);
682         if (err < 0)
683                 return err;
684
685         if (spec->spdif_mute) {
686                 if (smux_idx == 0)
687                         nid = spec->multiout.dig_out_nid;
688                 else
689                         nid = codec->slave_dig_outs[smux_idx - 1];
690                 if (spec->cur_smux[smux_idx] == smux->num_items - 1)
691                         val = HDA_AMP_MUTE;
692                 else
693                         val = 0;
694                 /* un/mute SPDIF out */
695                 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
696                                          HDA_AMP_MUTE, val);
697         }
698         return 0;
699 }
700
701 static unsigned int stac92xx_vref_set(struct hda_codec *codec,
702                                         hda_nid_t nid, unsigned int new_vref)
703 {
704         int error;
705         unsigned int pincfg;
706         pincfg = snd_hda_codec_read(codec, nid, 0,
707                                 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
708
709         pincfg &= 0xff;
710         pincfg &= ~(AC_PINCTL_VREFEN | AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
711         pincfg |= new_vref;
712
713         if (new_vref == AC_PINCTL_VREF_HIZ)
714                 pincfg |= AC_PINCTL_OUT_EN;
715         else
716                 pincfg |= AC_PINCTL_IN_EN;
717
718         error = snd_hda_codec_write_cache(codec, nid, 0,
719                                         AC_VERB_SET_PIN_WIDGET_CONTROL, pincfg);
720         if (error < 0)
721                 return error;
722         else
723                 return 1;
724 }
725
726 static unsigned int stac92xx_vref_get(struct hda_codec *codec, hda_nid_t nid)
727 {
728         unsigned int vref;
729         vref = snd_hda_codec_read(codec, nid, 0,
730                                 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
731         vref &= AC_PINCTL_VREFEN;
732         return vref;
733 }
734
735 static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
736 {
737         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
738         struct sigmatel_spec *spec = codec->spec;
739         return snd_hda_input_mux_info(spec->input_mux, uinfo);
740 }
741
742 static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
743 {
744         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
745         struct sigmatel_spec *spec = codec->spec;
746         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
747
748         ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
749         return 0;
750 }
751
752 static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
753 {
754         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
755         struct sigmatel_spec *spec = codec->spec;
756         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
757
758         return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
759                                      spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
760 }
761
762 static int stac92xx_mono_mux_enum_info(struct snd_kcontrol *kcontrol,
763         struct snd_ctl_elem_info *uinfo)
764 {
765         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
766         struct sigmatel_spec *spec = codec->spec;
767         return snd_hda_input_mux_info(spec->mono_mux, uinfo);
768 }
769
770 static int stac92xx_mono_mux_enum_get(struct snd_kcontrol *kcontrol,
771         struct snd_ctl_elem_value *ucontrol)
772 {
773         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
774         struct sigmatel_spec *spec = codec->spec;
775
776         ucontrol->value.enumerated.item[0] = spec->cur_mmux;
777         return 0;
778 }
779
780 static int stac92xx_mono_mux_enum_put(struct snd_kcontrol *kcontrol,
781         struct snd_ctl_elem_value *ucontrol)
782 {
783         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
784         struct sigmatel_spec *spec = codec->spec;
785
786         return snd_hda_input_mux_put(codec, spec->mono_mux, ucontrol,
787                                      spec->mono_nid, &spec->cur_mmux);
788 }
789
790 static int stac92xx_amp_mux_enum_info(struct snd_kcontrol *kcontrol,
791         struct snd_ctl_elem_info *uinfo)
792 {
793         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
794         struct sigmatel_spec *spec = codec->spec;
795         return snd_hda_input_mux_info(spec->amp_mux, uinfo);
796 }
797
798 static int stac92xx_amp_mux_enum_get(struct snd_kcontrol *kcontrol,
799         struct snd_ctl_elem_value *ucontrol)
800 {
801         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
802         struct sigmatel_spec *spec = codec->spec;
803
804         ucontrol->value.enumerated.item[0] = spec->cur_amux;
805         return 0;
806 }
807
808 static int stac92xx_amp_mux_enum_put(struct snd_kcontrol *kcontrol,
809         struct snd_ctl_elem_value *ucontrol)
810 {
811         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
812         struct sigmatel_spec *spec = codec->spec;
813         struct snd_kcontrol *ctl =
814                 snd_hda_find_mixer_ctl(codec, "Amp Capture Volume");
815         if (!ctl)
816                 return -EINVAL;
817
818         snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE |
819                 SNDRV_CTL_EVENT_MASK_INFO, &ctl->id);
820
821         return snd_hda_input_mux_put(codec, spec->amp_mux, ucontrol,
822                                      0, &spec->cur_amux);
823 }
824
825 #define stac92xx_aloopback_info snd_ctl_boolean_mono_info
826
827 static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol,
828         struct snd_ctl_elem_value *ucontrol)
829 {
830         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
831         unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
832         struct sigmatel_spec *spec = codec->spec;
833
834         ucontrol->value.integer.value[0] = !!(spec->aloopback &
835                                               (spec->aloopback_mask << idx));
836         return 0;
837 }
838
839 static int stac92xx_aloopback_put(struct snd_kcontrol *kcontrol,
840                 struct snd_ctl_elem_value *ucontrol)
841 {
842         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
843         struct sigmatel_spec *spec = codec->spec;
844         unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
845         unsigned int dac_mode;
846         unsigned int val, idx_val;
847
848         idx_val = spec->aloopback_mask << idx;
849         if (ucontrol->value.integer.value[0])
850                 val = spec->aloopback | idx_val;
851         else
852                 val = spec->aloopback & ~idx_val;
853         if (spec->aloopback == val)
854                 return 0;
855
856         spec->aloopback = val;
857
858         /* Only return the bits defined by the shift value of the
859          * first two bytes of the mask
860          */
861         dac_mode = snd_hda_codec_read(codec, codec->afg, 0,
862                                       kcontrol->private_value & 0xFFFF, 0x0);
863         dac_mode >>= spec->aloopback_shift;
864
865         if (spec->aloopback & idx_val) {
866                 snd_hda_power_up(codec);
867                 dac_mode |= idx_val;
868         } else {
869                 snd_hda_power_down(codec);
870                 dac_mode &= ~idx_val;
871         }
872
873         snd_hda_codec_write_cache(codec, codec->afg, 0,
874                 kcontrol->private_value >> 16, dac_mode);
875
876         return 1;
877 }
878
879 static struct hda_verb stac9200_core_init[] = {
880         /* set dac0mux for dac converter */
881         { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
882         {}
883 };
884
885 static struct hda_verb stac9200_eapd_init[] = {
886         /* set dac0mux for dac converter */
887         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
888         {0x08, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
889         {}
890 };
891
892 static struct hda_verb stac92hd73xx_6ch_core_init[] = {
893         /* set master volume and direct control */
894         { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
895         /* setup adcs to point to mixer */
896         { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
897         { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
898         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
899         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
900         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
901         /* setup import muxs */
902         { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
903         { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
904         { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
905         { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
906         {}
907 };
908
909 static struct hda_verb dell_eq_core_init[] = {
910         /* set master volume to max value without distortion
911          * and direct control */
912         { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xec},
913         /* setup adcs to point to mixer */
914         { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
915         { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
916         /* setup import muxs */
917         { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
918         { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
919         { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
920         { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
921         {}
922 };
923
924 static struct hda_verb dell_m6_core_init[] = {
925         { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
926         /* setup adcs to point to mixer */
927         { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
928         { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
929         /* setup import muxs */
930         { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
931         { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
932         { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
933         { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
934         {}
935 };
936
937 static struct hda_verb stac92hd73xx_8ch_core_init[] = {
938         /* set master volume and direct control */
939         { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
940         /* setup adcs to point to mixer */
941         { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
942         { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
943         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
944         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
945         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
946         /* setup import muxs */
947         { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
948         { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
949         { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
950         { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x03},
951         {}
952 };
953
954 static struct hda_verb stac92hd73xx_10ch_core_init[] = {
955         /* set master volume and direct control */
956         { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
957         /* dac3 is connected to import3 mux */
958         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0xb07f},
959         /* setup adcs to point to mixer */
960         { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
961         { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
962         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
963         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
964         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
965         /* setup import muxs */
966         { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
967         { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
968         { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
969         { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x03},
970         {}
971 };
972
973 static struct hda_verb stac92hd83xxx_core_init[] = {
974         { 0xa, AC_VERB_SET_CONNECT_SEL, 0x1},
975         { 0xb, AC_VERB_SET_CONNECT_SEL, 0x1},
976         { 0xd, AC_VERB_SET_CONNECT_SEL, 0x0},
977
978         /* power state controls amps */
979         { 0x01, AC_VERB_SET_EAPD, 1 << 2},
980         {}
981 };
982
983 static struct hda_verb stac92hd71bxx_core_init[] = {
984         /* set master volume and direct control */
985         { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
986         {}
987 };
988
989 #define HD_DISABLE_PORTF 1
990 static struct hda_verb stac92hd71bxx_analog_core_init[] = {
991         /* start of config #1 */
992
993         /* connect port 0f to audio mixer */
994         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x2},
995         /* start of config #2 */
996
997         /* set master volume and direct control */
998         { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
999         {}
1000 };
1001
1002 static struct hda_verb stac92hd71bxx_unmute_core_init[] = {
1003         /* unmute right and left channels for nodes 0x0f, 0xa, 0x0d */
1004         { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1005         { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1006         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1007         {}
1008 };
1009
1010 static struct hda_verb stac925x_core_init[] = {
1011         /* set dac0mux for dac converter */
1012         { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
1013         /* mute the master volume */
1014         { 0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1015         {}
1016 };
1017
1018 static struct hda_verb stac922x_core_init[] = {
1019         /* set master volume and direct control */      
1020         { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
1021         {}
1022 };
1023
1024 static struct hda_verb d965_core_init[] = {
1025         /* set master volume and direct control */      
1026         { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
1027         /* unmute node 0x1b */
1028         { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1029         /* select node 0x03 as DAC */   
1030         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
1031         {}
1032 };
1033
1034 static struct hda_verb stac927x_core_init[] = {
1035         /* set master volume and direct control */      
1036         { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
1037         /* enable analog pc beep path */
1038         { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
1039         {}
1040 };
1041
1042 static struct hda_verb stac9205_core_init[] = {
1043         /* set master volume and direct control */      
1044         { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
1045         /* enable analog pc beep path */
1046         { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
1047         {}
1048 };
1049
1050 #define STAC_MONO_MUX \
1051         { \
1052                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1053                 .name = "Mono Mux", \
1054                 .count = 1, \
1055                 .info = stac92xx_mono_mux_enum_info, \
1056                 .get = stac92xx_mono_mux_enum_get, \
1057                 .put = stac92xx_mono_mux_enum_put, \
1058         }
1059
1060 #define STAC_AMP_MUX \
1061         { \
1062                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1063                 .name = "Amp Selector Capture Switch", \
1064                 .count = 1, \
1065                 .info = stac92xx_amp_mux_enum_info, \
1066                 .get = stac92xx_amp_mux_enum_get, \
1067                 .put = stac92xx_amp_mux_enum_put, \
1068         }
1069
1070 #define STAC_AMP_VOL(xname, nid, chs, idx, dir) \
1071         { \
1072                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1073                 .name = xname, \
1074                 .index = 0, \
1075                 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1076                         SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1077                         SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
1078                 .info = stac92xx_amp_volume_info, \
1079                 .get = stac92xx_amp_volume_get, \
1080                 .put = stac92xx_amp_volume_put, \
1081                 .tlv = { .c = snd_hda_mixer_amp_tlv }, \
1082                 .private_value = HDA_COMPOSE_AMP_VAL(nid, chs, idx, dir) \
1083         }
1084
1085 #define STAC_ANALOG_LOOPBACK(verb_read, verb_write, cnt) \
1086         { \
1087                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1088                 .name  = "Analog Loopback", \
1089                 .count = cnt, \
1090                 .info  = stac92xx_aloopback_info, \
1091                 .get   = stac92xx_aloopback_get, \
1092                 .put   = stac92xx_aloopback_put, \
1093                 .private_value = verb_read | (verb_write << 16), \
1094         }
1095
1096 #define DC_BIAS(xname, idx, nid) \
1097         { \
1098                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1099                 .name = xname, \
1100                 .index = idx, \
1101                 .info = stac92xx_dc_bias_info, \
1102                 .get = stac92xx_dc_bias_get, \
1103                 .put = stac92xx_dc_bias_put, \
1104                 .private_value = nid, \
1105         }
1106
1107 static struct snd_kcontrol_new stac9200_mixer[] = {
1108         HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
1109         HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
1110         HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
1111         HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
1112         { } /* end */
1113 };
1114
1115 #define DELL_M6_MIXER 6
1116 static struct snd_kcontrol_new stac92hd73xx_6ch_mixer[] = {
1117         /* start of config #1 */
1118         HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
1119         HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
1120
1121         HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
1122         HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
1123
1124         HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1125         HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1126
1127         /* start of config #2 */
1128         HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1129         HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1130
1131         HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1132         HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1133
1134         { } /* end */
1135 };
1136
1137 static struct snd_kcontrol_new stac92hd73xx_6ch_loopback[] = {
1138         STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 3),
1139         {}
1140 };
1141
1142 static struct snd_kcontrol_new stac92hd73xx_8ch_loopback[] = {
1143         STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 4),
1144         {}
1145 };
1146
1147 static struct snd_kcontrol_new stac92hd73xx_10ch_loopback[] = {
1148         STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 5),
1149         {}
1150 };
1151
1152 static struct snd_kcontrol_new stac92hd73xx_8ch_mixer[] = {
1153         HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
1154         HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
1155
1156         HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1157         HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1158
1159         HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
1160         HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
1161
1162         HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1163         HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1164
1165         HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1166         HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1167         { } /* end */
1168 };
1169
1170 static struct snd_kcontrol_new stac92hd73xx_10ch_mixer[] = {
1171         HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
1172         HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
1173
1174         HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1175         HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1176
1177         HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
1178         HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
1179
1180         HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1181         HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1182
1183         HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1184         HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1185         { } /* end */
1186 };
1187
1188
1189 static struct snd_kcontrol_new stac92hd83xxx_mixer[] = {
1190         HDA_CODEC_VOLUME("DAC0 Capture Volume", 0x1b, 0x3, HDA_INPUT),
1191         HDA_CODEC_MUTE("DAC0 Capture Switch", 0x1b, 0x3, HDA_INPUT),
1192
1193         HDA_CODEC_VOLUME("DAC1 Capture Volume", 0x1b, 0x4, HDA_INPUT),
1194         HDA_CODEC_MUTE("DAC1 Capture Switch", 0x1b, 0x4, HDA_INPUT),
1195
1196         HDA_CODEC_VOLUME("Front Mic Capture Volume", 0x1b, 0x0, HDA_INPUT),
1197         HDA_CODEC_MUTE("Front Mic Capture Switch", 0x1b, 0x0, HDA_INPUT),
1198
1199         HDA_CODEC_VOLUME("Line In Capture Volume", 0x1b, 0x2, HDA_INPUT),
1200         HDA_CODEC_MUTE("Line In Capture Switch", 0x1b, 0x2, HDA_INPUT),
1201
1202         /*
1203         HDA_CODEC_VOLUME("Mic Capture Volume", 0x1b, 0x1, HDA_INPUT),
1204         HDA_CODEC_MUTE("Mic Capture Switch", 0x1b 0x1, HDA_INPUT),
1205         */
1206         { } /* end */
1207 };
1208
1209 static struct snd_kcontrol_new stac92hd71bxx_analog_mixer[] = {
1210         HDA_CODEC_MUTE("Import0 Mux Capture Switch", 0x17, 0x0, HDA_INPUT),
1211         HDA_CODEC_VOLUME("Import0 Mux Capture Volume", 0x17, 0x0, HDA_INPUT),
1212
1213         HDA_CODEC_MUTE("Import1 Mux Capture Switch", 0x17, 0x1, HDA_INPUT),
1214         HDA_CODEC_VOLUME("Import1 Mux Capture Volume", 0x17, 0x1, HDA_INPUT),
1215
1216         HDA_CODEC_MUTE("DAC0 Capture Switch", 0x17, 0x3, HDA_INPUT),
1217         HDA_CODEC_VOLUME("DAC0 Capture Volume", 0x17, 0x3, HDA_INPUT),
1218
1219         HDA_CODEC_MUTE("DAC1 Capture Switch", 0x17, 0x4, HDA_INPUT),
1220         HDA_CODEC_VOLUME("DAC1 Capture Volume", 0x17, 0x4, HDA_INPUT),
1221         { } /* end */
1222 };
1223
1224 static struct snd_kcontrol_new stac92hd71bxx_loopback[] = {
1225         STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2)
1226 };
1227
1228 static struct snd_kcontrol_new stac925x_mixer[] = {
1229         HDA_CODEC_VOLUME("Master Playback Volume", 0x0e, 0, HDA_OUTPUT),
1230         HDA_CODEC_MUTE("Master Playback Switch", 0x0e, 0, HDA_OUTPUT),
1231         { } /* end */
1232 };
1233
1234 static struct snd_kcontrol_new stac9205_loopback[] = {
1235         STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0, 1),
1236         {}
1237 };
1238
1239 static struct snd_kcontrol_new stac927x_loopback[] = {
1240         STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB, 1),
1241         {}
1242 };
1243
1244 static struct snd_kcontrol_new stac_dmux_mixer = {
1245         .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1246         .name = "Digital Input Source",
1247         /* count set later */
1248         .info = stac92xx_dmux_enum_info,
1249         .get = stac92xx_dmux_enum_get,
1250         .put = stac92xx_dmux_enum_put,
1251 };
1252
1253 static struct snd_kcontrol_new stac_smux_mixer = {
1254         .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1255         .name = "IEC958 Playback Source",
1256         /* count set later */
1257         .info = stac92xx_smux_enum_info,
1258         .get = stac92xx_smux_enum_get,
1259         .put = stac92xx_smux_enum_put,
1260 };
1261
1262 static const char *slave_vols[] = {
1263         "Front Playback Volume",
1264         "Surround Playback Volume",
1265         "Center Playback Volume",
1266         "LFE Playback Volume",
1267         "Side Playback Volume",
1268         "Headphone Playback Volume",
1269         "Speaker Playback Volume",
1270         NULL
1271 };
1272
1273 static const char *slave_sws[] = {
1274         "Front Playback Switch",
1275         "Surround Playback Switch",
1276         "Center Playback Switch",
1277         "LFE Playback Switch",
1278         "Side Playback Switch",
1279         "Headphone Playback Switch",
1280         "Speaker Playback Switch",
1281         "IEC958 Playback Switch",
1282         NULL
1283 };
1284
1285 static void stac92xx_free_kctls(struct hda_codec *codec);
1286 static int stac92xx_add_jack(struct hda_codec *codec, hda_nid_t nid, int type);
1287
1288 static int stac92xx_build_controls(struct hda_codec *codec)
1289 {
1290         struct sigmatel_spec *spec = codec->spec;
1291         struct auto_pin_cfg *cfg = &spec->autocfg;
1292         hda_nid_t nid;
1293         int err;
1294         int i;
1295
1296         if (spec->mixer) {
1297                 err = snd_hda_add_new_ctls(codec, spec->mixer);
1298                 if (err < 0)
1299                         return err;
1300         }
1301
1302         for (i = 0; i < spec->num_mixers; i++) {
1303                 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1304                 if (err < 0)
1305                         return err;
1306         }
1307         if (spec->num_dmuxes > 0) {
1308                 stac_dmux_mixer.count = spec->num_dmuxes;
1309                 err = snd_hda_ctl_add(codec,
1310                                   snd_ctl_new1(&stac_dmux_mixer, codec));
1311                 if (err < 0)
1312                         return err;
1313         }
1314         if (spec->num_smuxes > 0) {
1315                 int wcaps = get_wcaps(codec, spec->multiout.dig_out_nid);
1316                 struct hda_input_mux *smux = &spec->private_smux;
1317                 /* check for mute support on SPDIF out */
1318                 if (wcaps & AC_WCAP_OUT_AMP) {
1319                         smux->items[smux->num_items].label = "Off";
1320                         smux->items[smux->num_items].index = 0;
1321                         smux->num_items++;
1322                         spec->spdif_mute = 1;
1323                 }
1324                 stac_smux_mixer.count = spec->num_smuxes;
1325                 err = snd_hda_ctl_add(codec,
1326                                   snd_ctl_new1(&stac_smux_mixer, codec));
1327                 if (err < 0)
1328                         return err;
1329         }
1330
1331         if (spec->multiout.dig_out_nid) {
1332                 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
1333                 if (err < 0)
1334                         return err;
1335                 err = snd_hda_create_spdif_share_sw(codec,
1336                                                     &spec->multiout);
1337                 if (err < 0)
1338                         return err;
1339                 spec->multiout.share_spdif = 1;
1340         }
1341         if (spec->dig_in_nid && !(spec->gpio_dir & 0x01)) {
1342                 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1343                 if (err < 0)
1344                         return err;
1345         }
1346
1347         /* if we have no master control, let's create it */
1348         if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1349                 unsigned int vmaster_tlv[4];
1350                 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
1351                                         HDA_OUTPUT, vmaster_tlv);
1352                 /* correct volume offset */
1353                 vmaster_tlv[2] += vmaster_tlv[3] * spec->volume_offset;
1354                 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1355                                           vmaster_tlv, slave_vols);
1356                 if (err < 0)
1357                         return err;
1358         }
1359         if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1360                 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1361                                           NULL, slave_sws);
1362                 if (err < 0)
1363                         return err;
1364         }
1365
1366         if (spec->aloopback_ctl &&
1367             snd_hda_get_bool_hint(codec, "loopback") == 1) {
1368                 err = snd_hda_add_new_ctls(codec, spec->aloopback_ctl);
1369                 if (err < 0)
1370                         return err;
1371         }
1372
1373         stac92xx_free_kctls(codec); /* no longer needed */
1374
1375         /* create jack input elements */
1376         if (spec->hp_detect) {
1377                 for (i = 0; i < cfg->hp_outs; i++) {
1378                         int type = SND_JACK_HEADPHONE;
1379                         nid = cfg->hp_pins[i];
1380                         /* jack detection */
1381                         if (cfg->hp_outs == i)
1382                                 type |= SND_JACK_LINEOUT;
1383                         err = stac92xx_add_jack(codec, nid, type);
1384                         if (err < 0)
1385                                 return err;
1386                 }
1387         }
1388         for (i = 0; i < cfg->line_outs; i++) {
1389                 err = stac92xx_add_jack(codec, cfg->line_out_pins[i],
1390                                         SND_JACK_LINEOUT);
1391                 if (err < 0)
1392                         return err;
1393         }
1394         for (i = 0; i < AUTO_PIN_LAST; i++) {
1395                 nid = cfg->input_pins[i];
1396                 if (nid) {
1397                         err = stac92xx_add_jack(codec, nid,
1398                                                 SND_JACK_MICROPHONE);
1399                         if (err < 0)
1400                                 return err;
1401                 }
1402         }
1403
1404         return 0;       
1405 }
1406
1407 static unsigned int ref9200_pin_configs[8] = {
1408         0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
1409         0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
1410 };
1411
1412 static unsigned int gateway9200_m4_pin_configs[8] = {
1413         0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1414         0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1415 };
1416 static unsigned int gateway9200_m4_2_pin_configs[8] = {
1417         0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1418         0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1419 };
1420
1421 /*
1422     STAC 9200 pin configs for
1423     102801A8
1424     102801DE
1425     102801E8
1426 */
1427 static unsigned int dell9200_d21_pin_configs[8] = {
1428         0x400001f0, 0x400001f1, 0x02214030, 0x01014010, 
1429         0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
1430 };
1431
1432 /* 
1433     STAC 9200 pin configs for
1434     102801C0
1435     102801C1
1436 */
1437 static unsigned int dell9200_d22_pin_configs[8] = {
1438         0x400001f0, 0x400001f1, 0x0221401f, 0x01014010, 
1439         0x01813020, 0x02a19021, 0x90100140, 0x400001f2,
1440 };
1441
1442 /* 
1443     STAC 9200 pin configs for
1444     102801C4 (Dell Dimension E310)
1445     102801C5
1446     102801C7
1447     102801D9
1448     102801DA
1449     102801E3
1450 */
1451 static unsigned int dell9200_d23_pin_configs[8] = {
1452         0x400001f0, 0x400001f1, 0x0221401f, 0x01014010, 
1453         0x01813020, 0x01a19021, 0x90100140, 0x400001f2, 
1454 };
1455
1456
1457 /* 
1458     STAC 9200-32 pin configs for
1459     102801B5 (Dell Inspiron 630m)
1460     102801D8 (Dell Inspiron 640m)
1461 */
1462 static unsigned int dell9200_m21_pin_configs[8] = {
1463         0x40c003fa, 0x03441340, 0x0321121f, 0x90170310,
1464         0x408003fb, 0x03a11020, 0x401003fc, 0x403003fd,
1465 };
1466
1467 /* 
1468     STAC 9200-32 pin configs for
1469     102801C2 (Dell Latitude D620)
1470     102801C8 
1471     102801CC (Dell Latitude D820)
1472     102801D4 
1473     102801D6 
1474 */
1475 static unsigned int dell9200_m22_pin_configs[8] = {
1476         0x40c003fa, 0x0144131f, 0x0321121f, 0x90170310, 
1477         0x90a70321, 0x03a11020, 0x401003fb, 0x40f000fc,
1478 };
1479
1480 /* 
1481     STAC 9200-32 pin configs for
1482     102801CE (Dell XPS M1710)
1483     102801CF (Dell Precision M90)
1484 */
1485 static unsigned int dell9200_m23_pin_configs[8] = {
1486         0x40c003fa, 0x01441340, 0x0421421f, 0x90170310,
1487         0x408003fb, 0x04a1102e, 0x90170311, 0x403003fc,
1488 };
1489
1490 /*
1491     STAC 9200-32 pin configs for 
1492     102801C9
1493     102801CA
1494     102801CB (Dell Latitude 120L)
1495     102801D3
1496 */
1497 static unsigned int dell9200_m24_pin_configs[8] = {
1498         0x40c003fa, 0x404003fb, 0x0321121f, 0x90170310, 
1499         0x408003fc, 0x03a11020, 0x401003fd, 0x403003fe, 
1500 };
1501
1502 /*
1503     STAC 9200-32 pin configs for
1504     102801BD (Dell Inspiron E1505n)
1505     102801EE
1506     102801EF
1507 */
1508 static unsigned int dell9200_m25_pin_configs[8] = {
1509         0x40c003fa, 0x01441340, 0x0421121f, 0x90170310, 
1510         0x408003fb, 0x04a11020, 0x401003fc, 0x403003fd,
1511 };
1512
1513 /*
1514     STAC 9200-32 pin configs for
1515     102801F5 (Dell Inspiron 1501)
1516     102801F6
1517 */
1518 static unsigned int dell9200_m26_pin_configs[8] = {
1519         0x40c003fa, 0x404003fb, 0x0421121f, 0x90170310, 
1520         0x408003fc, 0x04a11020, 0x401003fd, 0x403003fe,
1521 };
1522
1523 /*
1524     STAC 9200-32
1525     102801CD (Dell Inspiron E1705/9400)
1526 */
1527 static unsigned int dell9200_m27_pin_configs[8] = {
1528         0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1529         0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
1530 };
1531
1532 static unsigned int oqo9200_pin_configs[8] = {
1533         0x40c000f0, 0x404000f1, 0x0221121f, 0x02211210,
1534         0x90170111, 0x90a70120, 0x400000f2, 0x400000f3,
1535 };
1536
1537
1538 static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
1539         [STAC_REF] = ref9200_pin_configs,
1540         [STAC_9200_OQO] = oqo9200_pin_configs,
1541         [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
1542         [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
1543         [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
1544         [STAC_9200_DELL_M21] = dell9200_m21_pin_configs,
1545         [STAC_9200_DELL_M22] = dell9200_m22_pin_configs,
1546         [STAC_9200_DELL_M23] = dell9200_m23_pin_configs,
1547         [STAC_9200_DELL_M24] = dell9200_m24_pin_configs,
1548         [STAC_9200_DELL_M25] = dell9200_m25_pin_configs,
1549         [STAC_9200_DELL_M26] = dell9200_m26_pin_configs,
1550         [STAC_9200_DELL_M27] = dell9200_m27_pin_configs,
1551         [STAC_9200_M4] = gateway9200_m4_pin_configs,
1552         [STAC_9200_M4_2] = gateway9200_m4_2_pin_configs,
1553         [STAC_9200_PANASONIC] = ref9200_pin_configs,
1554 };
1555
1556 static const char *stac9200_models[STAC_9200_MODELS] = {
1557         [STAC_AUTO] = "auto",
1558         [STAC_REF] = "ref",
1559         [STAC_9200_OQO] = "oqo",
1560         [STAC_9200_DELL_D21] = "dell-d21",
1561         [STAC_9200_DELL_D22] = "dell-d22",
1562         [STAC_9200_DELL_D23] = "dell-d23",
1563         [STAC_9200_DELL_M21] = "dell-m21",
1564         [STAC_9200_DELL_M22] = "dell-m22",
1565         [STAC_9200_DELL_M23] = "dell-m23",
1566         [STAC_9200_DELL_M24] = "dell-m24",
1567         [STAC_9200_DELL_M25] = "dell-m25",
1568         [STAC_9200_DELL_M26] = "dell-m26",
1569         [STAC_9200_DELL_M27] = "dell-m27",
1570         [STAC_9200_M4] = "gateway-m4",
1571         [STAC_9200_M4_2] = "gateway-m4-2",
1572         [STAC_9200_PANASONIC] = "panasonic",
1573 };
1574
1575 static struct snd_pci_quirk stac9200_cfg_tbl[] = {
1576         /* SigmaTel reference board */
1577         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1578                       "DFI LanParty", STAC_REF),
1579         SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1580                       "DFI LanParty", STAC_REF),
1581         /* Dell laptops have BIOS problem */
1582         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
1583                       "unknown Dell", STAC_9200_DELL_D21),
1584         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
1585                       "Dell Inspiron 630m", STAC_9200_DELL_M21),
1586         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bd,
1587                       "Dell Inspiron E1505n", STAC_9200_DELL_M25),
1588         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c0,
1589                       "unknown Dell", STAC_9200_DELL_D22),
1590         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c1,
1591                       "unknown Dell", STAC_9200_DELL_D22),
1592         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
1593                       "Dell Latitude D620", STAC_9200_DELL_M22),
1594         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c5,
1595                       "unknown Dell", STAC_9200_DELL_D23),
1596         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c7,
1597                       "unknown Dell", STAC_9200_DELL_D23),
1598         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c8,
1599                       "unknown Dell", STAC_9200_DELL_M22),
1600         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c9,
1601                       "unknown Dell", STAC_9200_DELL_M24),
1602         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ca,
1603                       "unknown Dell", STAC_9200_DELL_M24),
1604         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
1605                       "Dell Latitude 120L", STAC_9200_DELL_M24),
1606         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
1607                       "Dell Latitude D820", STAC_9200_DELL_M22),
1608         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
1609                       "Dell Inspiron E1705/9400", STAC_9200_DELL_M27),
1610         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
1611                       "Dell XPS M1710", STAC_9200_DELL_M23),
1612         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
1613                       "Dell Precision M90", STAC_9200_DELL_M23),
1614         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d3,
1615                       "unknown Dell", STAC_9200_DELL_M22),
1616         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d4,
1617                       "unknown Dell", STAC_9200_DELL_M22),
1618         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
1619                       "unknown Dell", STAC_9200_DELL_M22),
1620         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
1621                       "Dell Inspiron 640m", STAC_9200_DELL_M21),
1622         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d9,
1623                       "unknown Dell", STAC_9200_DELL_D23),
1624         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01da,
1625                       "unknown Dell", STAC_9200_DELL_D23),
1626         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01de,
1627                       "unknown Dell", STAC_9200_DELL_D21),
1628         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e3,
1629                       "unknown Dell", STAC_9200_DELL_D23),
1630         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e8,
1631                       "unknown Dell", STAC_9200_DELL_D21),
1632         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ee,
1633                       "unknown Dell", STAC_9200_DELL_M25),
1634         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ef,
1635                       "unknown Dell", STAC_9200_DELL_M25),
1636         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
1637                       "Dell Inspiron 1501", STAC_9200_DELL_M26),
1638         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
1639                       "unknown Dell", STAC_9200_DELL_M26),
1640         /* Panasonic */
1641         SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_9200_PANASONIC),
1642         /* Gateway machines needs EAPD to be set on resume */
1643         SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_M4),
1644         SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*", STAC_9200_M4_2),
1645         SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707", STAC_9200_M4_2),
1646         /* OQO Mobile */
1647         SND_PCI_QUIRK(0x1106, 0x3288, "OQO Model 2", STAC_9200_OQO),
1648         {} /* terminator */
1649 };
1650
1651 static unsigned int ref925x_pin_configs[8] = {
1652         0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
1653         0x90a70320, 0x02214210, 0x01019020, 0x9033032e,
1654 };
1655
1656 static unsigned int stac925xM1_pin_configs[8] = {
1657         0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1658         0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1659 };
1660
1661 static unsigned int stac925xM1_2_pin_configs[8] = {
1662         0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1663         0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1664 };
1665
1666 static unsigned int stac925xM2_pin_configs[8] = {
1667         0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1668         0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1669 };
1670
1671 static unsigned int stac925xM2_2_pin_configs[8] = {
1672         0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1673         0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1674 };
1675
1676 static unsigned int stac925xM3_pin_configs[8] = {
1677         0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1678         0x40a000f0, 0x90100210, 0x400003f1, 0x503303f3,
1679 };
1680
1681 static unsigned int stac925xM5_pin_configs[8] = {
1682         0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1683         0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1684 };
1685
1686 static unsigned int stac925xM6_pin_configs[8] = {
1687         0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1688         0x40a000f0, 0x90100210, 0x400003f1, 0x90330320,
1689 };
1690
1691 static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
1692         [STAC_REF] = ref925x_pin_configs,
1693         [STAC_M1] = stac925xM1_pin_configs,
1694         [STAC_M1_2] = stac925xM1_2_pin_configs,
1695         [STAC_M2] = stac925xM2_pin_configs,
1696         [STAC_M2_2] = stac925xM2_2_pin_configs,
1697         [STAC_M3] = stac925xM3_pin_configs,
1698         [STAC_M5] = stac925xM5_pin_configs,
1699         [STAC_M6] = stac925xM6_pin_configs,
1700 };
1701
1702 static const char *stac925x_models[STAC_925x_MODELS] = {
1703         [STAC_925x_AUTO] = "auto",
1704         [STAC_REF] = "ref",
1705         [STAC_M1] = "m1",
1706         [STAC_M1_2] = "m1-2",
1707         [STAC_M2] = "m2",
1708         [STAC_M2_2] = "m2-2",
1709         [STAC_M3] = "m3",
1710         [STAC_M5] = "m5",
1711         [STAC_M6] = "m6",
1712 };
1713
1714 static struct snd_pci_quirk stac925x_codec_id_cfg_tbl[] = {
1715         SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_M2),
1716         SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_M5),
1717         SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_M1),
1718         SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_M2),
1719         SND_PCI_QUIRK(0x107b, 0x0367, "Gateway MX6453", STAC_M1_2),
1720         /* Not sure about the brand name for those */
1721         SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M1),
1722         SND_PCI_QUIRK(0x107b, 0x0507, "Gateway mobile", STAC_M3),
1723         SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M6),
1724         SND_PCI_QUIRK(0x107b, 0x0685, "Gateway mobile", STAC_M2_2),
1725         {} /* terminator */
1726 };
1727
1728 static struct snd_pci_quirk stac925x_cfg_tbl[] = {
1729         /* SigmaTel reference board */
1730         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
1731         SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101, "DFI LanParty", STAC_REF),
1732         SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
1733
1734         /* Default table for unknown ID */
1735         SND_PCI_QUIRK(0x1002, 0x437b, "Gateway mobile", STAC_M2_2),
1736
1737         {} /* terminator */
1738 };
1739
1740 static unsigned int ref92hd73xx_pin_configs[13] = {
1741         0x02214030, 0x02a19040, 0x01a19020, 0x02214030,
1742         0x0181302e, 0x01014010, 0x01014020, 0x01014030,
1743         0x02319040, 0x90a000f0, 0x90a000f0, 0x01452050,
1744         0x01452050,
1745 };
1746
1747 static unsigned int dell_m6_pin_configs[13] = {
1748         0x0321101f, 0x4f00000f, 0x4f0000f0, 0x90170110,
1749         0x03a11020, 0x0321101f, 0x4f0000f0, 0x4f0000f0,
1750         0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1751         0x4f0000f0,
1752 };
1753
1754 static unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = {
1755         [STAC_92HD73XX_REF]     = ref92hd73xx_pin_configs,
1756         [STAC_DELL_M6_AMIC]     = dell_m6_pin_configs,
1757         [STAC_DELL_M6_DMIC]     = dell_m6_pin_configs,
1758         [STAC_DELL_M6_BOTH]     = dell_m6_pin_configs,
1759         [STAC_DELL_EQ]  = dell_m6_pin_configs,
1760 };
1761
1762 static const char *stac92hd73xx_models[STAC_92HD73XX_MODELS] = {
1763         [STAC_92HD73XX_AUTO] = "auto",
1764         [STAC_92HD73XX_NO_JD] = "no-jd",
1765         [STAC_92HD73XX_REF] = "ref",
1766         [STAC_DELL_M6_AMIC] = "dell-m6-amic",
1767         [STAC_DELL_M6_DMIC] = "dell-m6-dmic",
1768         [STAC_DELL_M6_BOTH] = "dell-m6",
1769         [STAC_DELL_EQ] = "dell-eq",
1770 };
1771
1772 static struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
1773         /* SigmaTel reference board */
1774         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1775                                 "DFI LanParty", STAC_92HD73XX_REF),
1776         SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1777                                 "DFI LanParty", STAC_92HD73XX_REF),
1778         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0254,
1779                                 "Dell Studio 1535", STAC_DELL_M6_DMIC),
1780         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0255,
1781                                 "unknown Dell", STAC_DELL_M6_DMIC),
1782         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0256,
1783                                 "unknown Dell", STAC_DELL_M6_BOTH),
1784         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0257,
1785                                 "unknown Dell", STAC_DELL_M6_BOTH),
1786         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025e,
1787                                 "unknown Dell", STAC_DELL_M6_AMIC),
1788         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025f,
1789                                 "unknown Dell", STAC_DELL_M6_AMIC),
1790         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0271,
1791                                 "unknown Dell", STAC_DELL_M6_DMIC),
1792         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0272,
1793                                 "unknown Dell", STAC_DELL_M6_DMIC),
1794         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x029f,
1795                                 "Dell Studio 1537", STAC_DELL_M6_DMIC),
1796         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a0,
1797                                 "Dell Studio 17", STAC_DELL_M6_DMIC),
1798         {} /* terminator */
1799 };
1800
1801 static unsigned int ref92hd83xxx_pin_configs[10] = {
1802         0x02214030, 0x02211010, 0x02a19020, 0x02170130,
1803         0x01014050, 0x01819040, 0x01014020, 0x90a3014e,
1804         0x01451160, 0x98560170,
1805 };
1806
1807 static unsigned int dell_s14_pin_configs[10] = {
1808         0x02214030, 0x02211010, 0x02a19020, 0x01014050,
1809         0x40f000f0, 0x01819040, 0x40f000f0, 0x90a60160,
1810         0x40f000f0, 0x40f000f0,
1811 };
1812
1813 static unsigned int *stac92hd83xxx_brd_tbl[STAC_92HD83XXX_MODELS] = {
1814         [STAC_92HD83XXX_REF] = ref92hd83xxx_pin_configs,
1815         [STAC_92HD83XXX_PWR_REF] = ref92hd83xxx_pin_configs,
1816         [STAC_DELL_S14] = dell_s14_pin_configs,
1817 };
1818
1819 static const char *stac92hd83xxx_models[STAC_92HD83XXX_MODELS] = {
1820         [STAC_92HD83XXX_AUTO] = "auto",
1821         [STAC_92HD83XXX_REF] = "ref",
1822         [STAC_92HD83XXX_PWR_REF] = "mic-ref",
1823         [STAC_DELL_S14] = "dell-s14",
1824 };
1825
1826 static struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = {
1827         /* SigmaTel reference board */
1828         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1829                       "DFI LanParty", STAC_92HD83XXX_REF),
1830         SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1831                       "DFI LanParty", STAC_92HD83XXX_REF),
1832         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ba,
1833                       "unknown Dell", STAC_DELL_S14),
1834         {} /* terminator */
1835 };
1836
1837 static unsigned int ref92hd71bxx_pin_configs[STAC92HD71BXX_NUM_PINS] = {
1838         0x02214030, 0x02a19040, 0x01a19020, 0x01014010,
1839         0x0181302e, 0x01014010, 0x01019020, 0x90a000f0,
1840         0x90a000f0, 0x01452050, 0x01452050, 0x00000000,
1841         0x00000000
1842 };
1843
1844 static unsigned int dell_m4_1_pin_configs[STAC92HD71BXX_NUM_PINS] = {
1845         0x0421101f, 0x04a11221, 0x40f000f0, 0x90170110,
1846         0x23a1902e, 0x23014250, 0x40f000f0, 0x90a000f0,
1847         0x40f000f0, 0x4f0000f0, 0x4f0000f0, 0x00000000,
1848         0x00000000
1849 };
1850
1851 static unsigned int dell_m4_2_pin_configs[STAC92HD71BXX_NUM_PINS] = {
1852         0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1853         0x23a1902e, 0x23014250, 0x40f000f0, 0x40f000f0,
1854         0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1855         0x00000000
1856 };
1857
1858 static unsigned int dell_m4_3_pin_configs[STAC92HD71BXX_NUM_PINS] = {
1859         0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1860         0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a000f0,
1861         0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1862         0x00000000
1863 };
1864
1865 static unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
1866         [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs,
1867         [STAC_DELL_M4_1]        = dell_m4_1_pin_configs,
1868         [STAC_DELL_M4_2]        = dell_m4_2_pin_configs,
1869         [STAC_DELL_M4_3]        = dell_m4_3_pin_configs,
1870         [STAC_HP_M4]            = NULL,
1871         [STAC_HP_DV5]           = NULL,
1872         [STAC_HP_HDX]           = NULL,
1873         [STAC_HP_DV4_1222NR]    = NULL,
1874 };
1875
1876 static const char *stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
1877         [STAC_92HD71BXX_AUTO] = "auto",
1878         [STAC_92HD71BXX_REF] = "ref",
1879         [STAC_DELL_M4_1] = "dell-m4-1",
1880         [STAC_DELL_M4_2] = "dell-m4-2",
1881         [STAC_DELL_M4_3] = "dell-m4-3",
1882         [STAC_HP_M4] = "hp-m4",
1883         [STAC_HP_DV5] = "hp-dv5",
1884         [STAC_HP_HDX] = "hp-hdx",
1885         [STAC_HP_DV4_1222NR] = "hp-dv4-1222nr",
1886 };
1887
1888 static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
1889         /* SigmaTel reference board */
1890         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1891                       "DFI LanParty", STAC_92HD71BXX_REF),
1892         SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1893                       "DFI LanParty", STAC_92HD71BXX_REF),
1894         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30fb,
1895                       "HP dv4-1222nr", STAC_HP_DV4_1222NR),
1896         SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3080,
1897                       "HP", STAC_HP_DV5),
1898         SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x30f0,
1899                       "HP dv4-7", STAC_HP_DV5),
1900         SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3600,
1901                       "HP dv4-7", STAC_HP_DV5),
1902         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3610,
1903                       "HP HDX", STAC_HP_HDX),  /* HDX18 */
1904         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361a,
1905                       "HP mini 1000", STAC_HP_M4),
1906         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361b,
1907                       "HP HDX", STAC_HP_HDX),  /* HDX16 */
1908         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
1909                                 "unknown Dell", STAC_DELL_M4_1),
1910         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234,
1911                                 "unknown Dell", STAC_DELL_M4_1),
1912         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0250,
1913                                 "unknown Dell", STAC_DELL_M4_1),
1914         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024f,
1915                                 "unknown Dell", STAC_DELL_M4_1),
1916         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024d,
1917                                 "unknown Dell", STAC_DELL_M4_1),
1918         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0251,
1919                                 "unknown Dell", STAC_DELL_M4_1),
1920         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0277,
1921                                 "unknown Dell", STAC_DELL_M4_1),
1922         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0263,
1923                                 "unknown Dell", STAC_DELL_M4_2),
1924         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0265,
1925                                 "unknown Dell", STAC_DELL_M4_2),
1926         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0262,
1927                                 "unknown Dell", STAC_DELL_M4_2),
1928         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0264,
1929                                 "unknown Dell", STAC_DELL_M4_2),
1930         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02aa,
1931                                 "unknown Dell", STAC_DELL_M4_3),
1932         {} /* terminator */
1933 };
1934
1935 static unsigned int ref922x_pin_configs[10] = {
1936         0x01014010, 0x01016011, 0x01012012, 0x0221401f,
1937         0x01813122, 0x01011014, 0x01441030, 0x01c41030,
1938         0x40000100, 0x40000100,
1939 };
1940
1941 /*
1942     STAC 922X pin configs for
1943     102801A7
1944     102801AB
1945     102801A9
1946     102801D1
1947     102801D2
1948 */
1949 static unsigned int dell_922x_d81_pin_configs[10] = {
1950         0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1951         0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
1952         0x01813122, 0x400001f2,
1953 };
1954
1955 /*
1956     STAC 922X pin configs for
1957     102801AC
1958     102801D0
1959 */
1960 static unsigned int dell_922x_d82_pin_configs[10] = {
1961         0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1962         0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
1963         0x01813122, 0x400001f1,
1964 };
1965
1966 /*
1967     STAC 922X pin configs for
1968     102801BF
1969 */
1970 static unsigned int dell_922x_m81_pin_configs[10] = {
1971         0x0321101f, 0x01112024, 0x01111222, 0x91174220,
1972         0x03a11050, 0x01116221, 0x90a70330, 0x01452340, 
1973         0x40C003f1, 0x405003f0,
1974 };
1975
1976 /*
1977     STAC 9221 A1 pin configs for
1978     102801D7 (Dell XPS M1210)
1979 */
1980 static unsigned int dell_922x_m82_pin_configs[10] = {
1981         0x02211211, 0x408103ff, 0x02a1123e, 0x90100310, 
1982         0x408003f1, 0x0221121f, 0x03451340, 0x40c003f2, 
1983         0x508003f3, 0x405003f4, 
1984 };
1985
1986 static unsigned int d945gtp3_pin_configs[10] = {
1987         0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
1988         0x40000100, 0x40000100, 0x40000100, 0x40000100,
1989         0x02a19120, 0x40000100,
1990 };
1991
1992 static unsigned int d945gtp5_pin_configs[10] = {
1993         0x0221401f, 0x01011012, 0x01813024, 0x01014010,
1994         0x01a19021, 0x01016011, 0x01452130, 0x40000100,
1995         0x02a19320, 0x40000100,
1996 };
1997
1998 static unsigned int intel_mac_v1_pin_configs[10] = {
1999         0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
2000         0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
2001         0x400000fc, 0x400000fb,
2002 };
2003
2004 static unsigned int intel_mac_v2_pin_configs[10] = {
2005         0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
2006         0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
2007         0x400000fc, 0x400000fb,
2008 };
2009
2010 static unsigned int intel_mac_v3_pin_configs[10] = {
2011         0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
2012         0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
2013         0x400000fc, 0x400000fb,
2014 };
2015
2016 static unsigned int intel_mac_v4_pin_configs[10] = {
2017         0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
2018         0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
2019         0x400000fc, 0x400000fb,
2020 };
2021
2022 static unsigned int intel_mac_v5_pin_configs[10] = {
2023         0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
2024         0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
2025         0x400000fc, 0x400000fb,
2026 };
2027
2028 static unsigned int ecs202_pin_configs[10] = {
2029         0x0221401f, 0x02a19020, 0x01a19020, 0x01114010,
2030         0x408000f0, 0x01813022, 0x074510a0, 0x40c400f1,
2031         0x9037012e, 0x40e000f2,
2032 };
2033
2034 static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
2035         [STAC_D945_REF] = ref922x_pin_configs,
2036         [STAC_D945GTP3] = d945gtp3_pin_configs,
2037         [STAC_D945GTP5] = d945gtp5_pin_configs,
2038         [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
2039         [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
2040         [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
2041         [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
2042         [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
2043         [STAC_INTEL_MAC_AUTO] = intel_mac_v3_pin_configs,
2044         /* for backward compatibility */
2045         [STAC_MACMINI] = intel_mac_v3_pin_configs,
2046         [STAC_MACBOOK] = intel_mac_v5_pin_configs,
2047         [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
2048         [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
2049         [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
2050         [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
2051         [STAC_ECS_202] = ecs202_pin_configs,
2052         [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
2053         [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,       
2054         [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
2055         [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,       
2056 };
2057
2058 static const char *stac922x_models[STAC_922X_MODELS] = {
2059         [STAC_922X_AUTO] = "auto",
2060         [STAC_D945_REF] = "ref",
2061         [STAC_D945GTP5] = "5stack",
2062         [STAC_D945GTP3] = "3stack",
2063         [STAC_INTEL_MAC_V1] = "intel-mac-v1",
2064         [STAC_INTEL_MAC_V2] = "intel-mac-v2",
2065         [STAC_INTEL_MAC_V3] = "intel-mac-v3",
2066         [STAC_INTEL_MAC_V4] = "intel-mac-v4",
2067         [STAC_INTEL_MAC_V5] = "intel-mac-v5",
2068         [STAC_INTEL_MAC_AUTO] = "intel-mac-auto",
2069         /* for backward compatibility */
2070         [STAC_MACMINI]  = "macmini",
2071         [STAC_MACBOOK]  = "macbook",
2072         [STAC_MACBOOK_PRO_V1]   = "macbook-pro-v1",
2073         [STAC_MACBOOK_PRO_V2]   = "macbook-pro",
2074         [STAC_IMAC_INTEL] = "imac-intel",
2075         [STAC_IMAC_INTEL_20] = "imac-intel-20",
2076         [STAC_ECS_202] = "ecs202",
2077         [STAC_922X_DELL_D81] = "dell-d81",
2078         [STAC_922X_DELL_D82] = "dell-d82",
2079         [STAC_922X_DELL_M81] = "dell-m81",
2080         [STAC_922X_DELL_M82] = "dell-m82",
2081 };
2082
2083 static struct snd_pci_quirk stac922x_cfg_tbl[] = {
2084         /* SigmaTel reference board */
2085         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2086                       "DFI LanParty", STAC_D945_REF),
2087         SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2088                       "DFI LanParty", STAC_D945_REF),
2089         /* Intel 945G based systems */
2090         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
2091                       "Intel D945G", STAC_D945GTP3),
2092         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
2093                       "Intel D945G", STAC_D945GTP3),
2094         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
2095                       "Intel D945G", STAC_D945GTP3),
2096         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
2097                       "Intel D945G", STAC_D945GTP3),
2098         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
2099                       "Intel D945G", STAC_D945GTP3),
2100         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
2101                       "Intel D945G", STAC_D945GTP3),
2102         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
2103                       "Intel D945G", STAC_D945GTP3),
2104         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
2105                       "Intel D945G", STAC_D945GTP3),
2106         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
2107                       "Intel D945G", STAC_D945GTP3),
2108         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
2109                       "Intel D945G", STAC_D945GTP3),
2110         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
2111                       "Intel D945G", STAC_D945GTP3),
2112         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
2113                       "Intel D945G", STAC_D945GTP3),
2114         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
2115                       "Intel D945G", STAC_D945GTP3),
2116         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
2117                       "Intel D945G", STAC_D945GTP3),
2118         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
2119                       "Intel D945G", STAC_D945GTP3),
2120         /* Intel D945G 5-stack systems */
2121         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
2122                       "Intel D945G", STAC_D945GTP5),
2123         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
2124                       "Intel D945G", STAC_D945GTP5),
2125         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
2126                       "Intel D945G", STAC_D945GTP5),
2127         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
2128                       "Intel D945G", STAC_D945GTP5),
2129         /* Intel 945P based systems */
2130         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
2131                       "Intel D945P", STAC_D945GTP3),
2132         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
2133                       "Intel D945P", STAC_D945GTP3),
2134         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
2135                       "Intel D945P", STAC_D945GTP3),
2136         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
2137                       "Intel D945P", STAC_D945GTP3),
2138         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
2139                       "Intel D945P", STAC_D945GTP3),
2140         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
2141                       "Intel D945P", STAC_D945GTP5),
2142         /* other intel */
2143         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0204,
2144                       "Intel D945", STAC_D945_REF),
2145         /* other systems  */
2146         /* Apple Intel Mac (Mac Mini, MacBook, MacBook Pro...) */
2147         SND_PCI_QUIRK(0x8384, 0x7680,
2148                       "Mac", STAC_INTEL_MAC_AUTO),
2149         /* Dell systems  */
2150         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
2151                       "unknown Dell", STAC_922X_DELL_D81),
2152         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
2153                       "unknown Dell", STAC_922X_DELL_D81),
2154         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
2155                       "unknown Dell", STAC_922X_DELL_D81),
2156         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
2157                       "unknown Dell", STAC_922X_DELL_D82),
2158         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
2159                       "unknown Dell", STAC_922X_DELL_M81),
2160         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
2161                       "unknown Dell", STAC_922X_DELL_D82),
2162         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
2163                       "unknown Dell", STAC_922X_DELL_D81),
2164         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
2165                       "unknown Dell", STAC_922X_DELL_D81),
2166         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
2167                       "Dell XPS M1210", STAC_922X_DELL_M82),
2168         /* ECS/PC Chips boards */
2169         SND_PCI_QUIRK_MASK(0x1019, 0xf000, 0x2000,
2170                       "ECS/PC chips", STAC_ECS_202),
2171         {} /* terminator */
2172 };
2173
2174 static unsigned int ref927x_pin_configs[14] = {
2175         0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2176         0x01a19040, 0x01011012, 0x01016011, 0x0101201f, 
2177         0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
2178         0x01c42190, 0x40000100,
2179 };
2180
2181 static unsigned int d965_3st_pin_configs[14] = {
2182         0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
2183         0x01a19021, 0x01813024, 0x40000100, 0x40000100,
2184         0x40000100, 0x40000100, 0x40000100, 0x40000100,
2185         0x40000100, 0x40000100
2186 };
2187
2188 static unsigned int d965_5st_pin_configs[14] = {
2189         0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2190         0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2191         0x40000100, 0x40000100, 0x40000100, 0x01442070,
2192         0x40000100, 0x40000100
2193 };
2194
2195 static unsigned int d965_5st_no_fp_pin_configs[14] = {
2196         0x40000100, 0x40000100, 0x0181304e, 0x01014010,
2197         0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2198         0x40000100, 0x40000100, 0x40000100, 0x01442070,
2199         0x40000100, 0x40000100
2200 };
2201
2202 static unsigned int dell_3st_pin_configs[14] = {
2203         0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
2204         0x01111212, 0x01116211, 0x01813050, 0x01112214,
2205         0x403003fa, 0x90a60040, 0x90a60040, 0x404003fb,
2206         0x40c003fc, 0x40000100
2207 };
2208
2209 static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
2210         [STAC_D965_REF_NO_JD] = ref927x_pin_configs,
2211         [STAC_D965_REF]  = ref927x_pin_configs,
2212         [STAC_D965_3ST]  = d965_3st_pin_configs,
2213         [STAC_D965_5ST]  = d965_5st_pin_configs,
2214         [STAC_D965_5ST_NO_FP]  = d965_5st_no_fp_pin_configs,
2215         [STAC_DELL_3ST]  = dell_3st_pin_configs,
2216         [STAC_DELL_BIOS] = NULL,
2217 };
2218
2219 static const char *stac927x_models[STAC_927X_MODELS] = {
2220         [STAC_927X_AUTO]        = "auto",
2221         [STAC_D965_REF_NO_JD]   = "ref-no-jd",
2222         [STAC_D965_REF]         = "ref",
2223         [STAC_D965_3ST]         = "3stack",
2224         [STAC_D965_5ST]         = "5stack",
2225         [STAC_D965_5ST_NO_FP]   = "5stack-no-fp",
2226         [STAC_DELL_3ST]         = "dell-3stack",
2227         [STAC_DELL_BIOS]        = "dell-bios",
2228 };
2229
2230 static struct snd_pci_quirk stac927x_cfg_tbl[] = {
2231         /* SigmaTel reference board */
2232         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2233                       "DFI LanParty", STAC_D965_REF),
2234         SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2235                       "DFI LanParty", STAC_D965_REF),
2236          /* Intel 946 based systems */
2237         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
2238         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
2239         /* 965 based 3 stack systems */
2240         SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2100,
2241                            "Intel D965", STAC_D965_3ST),
2242         SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2000,
2243                            "Intel D965", STAC_D965_3ST),
2244         /* Dell 3 stack systems */
2245         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x01f7, "Dell XPS M1730", STAC_DELL_3ST),
2246         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
2247         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x01ed, "Dell     ", STAC_DELL_3ST),
2248         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x01f4, "Dell     ", STAC_DELL_3ST),
2249         /* Dell 3 stack systems with verb table in BIOS */
2250         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x01f3, "Dell Inspiron 1420", STAC_DELL_BIOS),
2251         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x0227, "Dell Vostro 1400  ", STAC_DELL_BIOS),
2252         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x022e, "Dell     ", STAC_DELL_BIOS),
2253         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x022f, "Dell Inspiron 1525", STAC_DELL_3ST),
2254         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x0242, "Dell     ", STAC_DELL_BIOS),
2255         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x0243, "Dell     ", STAC_DELL_BIOS),
2256         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x02ff, "Dell     ", STAC_DELL_BIOS),
2257         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x0209, "Dell XPS 1330", STAC_DELL_BIOS),
2258         /* 965 based 5 stack systems */
2259         SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2300,
2260                            "Intel D965", STAC_D965_5ST),
2261         SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2500,
2262                            "Intel D965", STAC_D965_5ST),
2263         {} /* terminator */
2264 };
2265
2266 static unsigned int ref9205_pin_configs[12] = {
2267         0x40000100, 0x40000100, 0x01016011, 0x01014010,
2268         0x01813122, 0x01a19021, 0x01019020, 0x40000100,
2269         0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
2270 };
2271
2272 /*
2273     STAC 9205 pin configs for
2274     102801F1
2275     102801F2
2276     102801FC
2277     102801FD
2278     10280204
2279     1028021F
2280     10280228 (Dell Vostro 1500)
2281 */
2282 static unsigned int dell_9205_m42_pin_configs[12] = {
2283         0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
2284         0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
2285         0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
2286 };
2287
2288 /*
2289     STAC 9205 pin configs for
2290     102801F9
2291     102801FA
2292     102801FE
2293     102801FF (Dell Precision M4300)
2294     10280206
2295     10280200
2296     10280201
2297 */
2298 static unsigned int dell_9205_m43_pin_configs[12] = {
2299         0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
2300         0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
2301         0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
2302 };
2303
2304 static unsigned int dell_9205_m44_pin_configs[12] = {
2305         0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
2306         0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
2307         0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
2308 };
2309
2310 static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
2311         [STAC_9205_REF] = ref9205_pin_configs,
2312         [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
2313         [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
2314         [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
2315         [STAC_9205_EAPD] = NULL,
2316 };
2317
2318 static const char *stac9205_models[STAC_9205_MODELS] = {
2319         [STAC_9205_AUTO] = "auto",
2320         [STAC_9205_REF] = "ref",
2321         [STAC_9205_DELL_M42] = "dell-m42",
2322         [STAC_9205_DELL_M43] = "dell-m43",
2323         [STAC_9205_DELL_M44] = "dell-m44",
2324         [STAC_9205_EAPD] = "eapd",
2325 };
2326
2327 static struct snd_pci_quirk stac9205_cfg_tbl[] = {
2328         /* SigmaTel reference board */
2329         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2330                       "DFI LanParty", STAC_9205_REF),
2331         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xfb30,
2332                       "SigmaTel", STAC_9205_REF),
2333         SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2334                       "DFI LanParty", STAC_9205_REF),
2335         /* Dell */
2336         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
2337                       "unknown Dell", STAC_9205_DELL_M42),
2338         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
2339                       "unknown Dell", STAC_9205_DELL_M42),
2340         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
2341                       "Dell Precision", STAC_9205_DELL_M43),
2342         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
2343                       "Dell Precision", STAC_9205_DELL_M43),
2344         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
2345                       "Dell Precision", STAC_9205_DELL_M43),
2346         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
2347                       "unknown Dell", STAC_9205_DELL_M42),
2348         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
2349                       "unknown Dell", STAC_9205_DELL_M42),
2350         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
2351                       "Dell Precision", STAC_9205_DELL_M43),
2352         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
2353                       "Dell Precision M4300", STAC_9205_DELL_M43),
2354         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
2355                       "unknown Dell", STAC_9205_DELL_M42),
2356         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
2357                       "Dell Precision", STAC_9205_DELL_M43),
2358         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
2359                       "Dell Precision", STAC_9205_DELL_M43),
2360         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
2361                       "Dell Precision", STAC_9205_DELL_M43),
2362         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
2363                       "Dell Inspiron", STAC_9205_DELL_M44),
2364         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0228,
2365                       "Dell Vostro 1500", STAC_9205_DELL_M42),
2366         /* Gateway */
2367         SND_PCI_QUIRK(0x107b, 0x0560, "Gateway T6834c", STAC_9205_EAPD),
2368         SND_PCI_QUIRK(0x107b, 0x0565, "Gateway T1616", STAC_9205_EAPD),
2369         {} /* terminator */
2370 };
2371
2372 static void stac92xx_set_config_regs(struct hda_codec *codec,
2373                                      unsigned int *pincfgs)
2374 {
2375         int i;
2376         struct sigmatel_spec *spec = codec->spec;
2377
2378         if (!pincfgs)
2379                 return;
2380
2381         for (i = 0; i < spec->num_pins; i++)
2382                 if (spec->pin_nids[i] && pincfgs[i])
2383                         snd_hda_codec_set_pincfg(codec, spec->pin_nids[i],
2384                                                  pincfgs[i]);
2385 }
2386
2387 /*
2388  * Analog playback callbacks
2389  */
2390 static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
2391                                       struct hda_codec *codec,
2392                                       struct snd_pcm_substream *substream)
2393 {
2394         struct sigmatel_spec *spec = codec->spec;
2395         if (spec->stream_delay)
2396                 msleep(spec->stream_delay);
2397         return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2398                                              hinfo);
2399 }
2400
2401 static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2402                                          struct hda_codec *codec,
2403                                          unsigned int stream_tag,
2404                                          unsigned int format,
2405                                          struct snd_pcm_substream *substream)
2406 {
2407         struct sigmatel_spec *spec = codec->spec;
2408         return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
2409 }
2410
2411 static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2412                                         struct hda_codec *codec,
2413                                         struct snd_pcm_substream *substream)
2414 {
2415         struct sigmatel_spec *spec = codec->spec;
2416         return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2417 }
2418
2419 /*
2420  * Digital playback callbacks
2421  */
2422 static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2423                                           struct hda_codec *codec,
2424                                           struct snd_pcm_substream *substream)
2425 {
2426         struct sigmatel_spec *spec = codec->spec;
2427         return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2428 }
2429
2430 static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2431                                            struct hda_codec *codec,
2432                                            struct snd_pcm_substream *substream)
2433 {
2434         struct sigmatel_spec *spec = codec->spec;
2435         return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2436 }
2437
2438 static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2439                                          struct hda_codec *codec,
2440                                          unsigned int stream_tag,
2441                                          unsigned int format,
2442                                          struct snd_pcm_substream *substream)
2443 {
2444         struct sigmatel_spec *spec = codec->spec;
2445         return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2446                                              stream_tag, format, substream);
2447 }
2448
2449 static int stac92xx_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2450                                         struct hda_codec *codec,
2451                                         struct snd_pcm_substream *substream)
2452 {
2453         struct sigmatel_spec *spec = codec->spec;
2454         return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2455 }
2456
2457
2458 /*
2459  * Analog capture callbacks
2460  */
2461 static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2462                                         struct hda_codec *codec,
2463                                         unsigned int stream_tag,
2464                                         unsigned int format,
2465                                         struct snd_pcm_substream *substream)
2466 {
2467         struct sigmatel_spec *spec = codec->spec;
2468         hda_nid_t nid = spec->adc_nids[substream->number];
2469
2470         if (spec->powerdown_adcs) {
2471                 msleep(40);
2472                 snd_hda_codec_write(codec, nid, 0,
2473                         AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
2474         }
2475         snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
2476         return 0;
2477 }
2478
2479 static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2480                                         struct hda_codec *codec,
2481                                         struct snd_pcm_substream *substream)
2482 {
2483         struct sigmatel_spec *spec = codec->spec;
2484         hda_nid_t nid = spec->adc_nids[substream->number];
2485
2486         snd_hda_codec_cleanup_stream(codec, nid);
2487         if (spec->powerdown_adcs)
2488                 snd_hda_codec_write(codec, nid, 0,
2489                         AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
2490         return 0;
2491 }
2492
2493 static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
2494         .substreams = 1,
2495         .channels_min = 2,
2496         .channels_max = 2,
2497         /* NID is set in stac92xx_build_pcms */
2498         .ops = {
2499                 .open = stac92xx_dig_playback_pcm_open,
2500                 .close = stac92xx_dig_playback_pcm_close,
2501                 .prepare = stac92xx_dig_playback_pcm_prepare,
2502                 .cleanup = stac92xx_dig_playback_pcm_cleanup
2503         },
2504 };
2505
2506 static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
2507         .substreams = 1,
2508         .channels_min = 2,
2509         .channels_max = 2,
2510         /* NID is set in stac92xx_build_pcms */
2511 };
2512
2513 static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
2514         .substreams = 1,
2515         .channels_min = 2,
2516         .channels_max = 8,
2517         .nid = 0x02, /* NID to query formats and rates */
2518         .ops = {
2519                 .open = stac92xx_playback_pcm_open,
2520                 .prepare = stac92xx_playback_pcm_prepare,
2521                 .cleanup = stac92xx_playback_pcm_cleanup
2522         },
2523 };
2524
2525 static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
2526         .substreams = 1,
2527         .channels_min = 2,
2528         .channels_max = 2,
2529         .nid = 0x06, /* NID to query formats and rates */
2530         .ops = {
2531                 .open = stac92xx_playback_pcm_open,
2532                 .prepare = stac92xx_playback_pcm_prepare,
2533                 .cleanup = stac92xx_playback_pcm_cleanup
2534         },
2535 };
2536
2537 static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
2538         .channels_min = 2,
2539         .channels_max = 2,
2540         /* NID + .substreams is set in stac92xx_build_pcms */
2541         .ops = {
2542                 .prepare = stac92xx_capture_pcm_prepare,
2543                 .cleanup = stac92xx_capture_pcm_cleanup
2544         },
2545 };
2546
2547 static int stac92xx_build_pcms(struct hda_codec *codec)
2548 {
2549         struct sigmatel_spec *spec = codec->spec;
2550         struct hda_pcm *info = spec->pcm_rec;
2551
2552         codec->num_pcms = 1;
2553         codec->pcm_info = info;
2554
2555         info->name = "STAC92xx Analog";
2556         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
2557         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2558                 spec->multiout.dac_nids[0];
2559         info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
2560         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2561         info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
2562
2563         if (spec->alt_switch) {
2564                 codec->num_pcms++;
2565                 info++;
2566                 info->name = "STAC92xx Analog Alt";
2567                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
2568         }
2569
2570         if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2571                 codec->num_pcms++;
2572                 info++;
2573                 info->name = "STAC92xx Digital";
2574                 info->pcm_type = spec->autocfg.dig_out_type[0];
2575                 if (spec->multiout.dig_out_nid) {
2576                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
2577                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2578                 }
2579                 if (spec->dig_in_nid) {
2580                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
2581                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2582                 }
2583         }
2584
2585         return 0;
2586 }
2587
2588 static unsigned int stac92xx_get_default_vref(struct hda_codec *codec,
2589                                         hda_nid_t nid)
2590 {
2591         unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2592         pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
2593         if (pincap & AC_PINCAP_VREF_100)
2594                 return AC_PINCTL_VREF_100;
2595         if (pincap & AC_PINCAP_VREF_80)
2596                 return AC_PINCTL_VREF_80;
2597         if (pincap & AC_PINCAP_VREF_50)
2598                 return AC_PINCTL_VREF_50;
2599         if (pincap & AC_PINCAP_VREF_GRD)
2600                 return AC_PINCTL_VREF_GRD;
2601         return 0;
2602 }
2603
2604 static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
2605
2606 {
2607         snd_hda_codec_write_cache(codec, nid, 0,
2608                                   AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
2609 }
2610
2611 #define stac92xx_hp_switch_info         snd_ctl_boolean_mono_info
2612
2613 static int stac92xx_hp_switch_get(struct snd_kcontrol *kcontrol,
2614                         struct snd_ctl_elem_value *ucontrol)
2615 {
2616         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2617         struct sigmatel_spec *spec = codec->spec;
2618
2619         ucontrol->value.integer.value[0] = !!spec->hp_switch;
2620         return 0;
2621 }
2622
2623 static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid);
2624
2625 static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol,
2626                         struct snd_ctl_elem_value *ucontrol)
2627 {
2628         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2629         struct sigmatel_spec *spec = codec->spec;
2630         int nid = kcontrol->private_value;
2631  
2632         spec->hp_switch = ucontrol->value.integer.value[0] ? nid : 0;
2633
2634         /* check to be sure that the ports are upto date with
2635          * switch changes
2636          */
2637         stac_issue_unsol_event(codec, nid);
2638
2639         return 1;
2640 }
2641
2642 static int stac92xx_dc_bias_info(struct snd_kcontrol *kcontrol,
2643                                 struct snd_ctl_elem_info *uinfo)
2644 {
2645         int i;
2646         static char *texts[] = {
2647                 "Mic In", "Line In", "Line Out"
2648         };
2649
2650         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2651         struct sigmatel_spec *spec = codec->spec;
2652         hda_nid_t nid = kcontrol->private_value;
2653
2654         if (nid == spec->mic_switch || nid == spec->line_switch)
2655                 i = 3;
2656         else
2657                 i = 2;
2658
2659         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2660         uinfo->value.enumerated.items = i;
2661         uinfo->count = 1;
2662         if (uinfo->value.enumerated.item >= i)
2663                 uinfo->value.enumerated.item = i-1;
2664         strcpy(uinfo->value.enumerated.name,
2665                 texts[uinfo->value.enumerated.item]);
2666
2667         return 0;
2668 }
2669
2670 static int stac92xx_dc_bias_get(struct snd_kcontrol *kcontrol,
2671                                 struct snd_ctl_elem_value *ucontrol)
2672 {
2673         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2674         hda_nid_t nid = kcontrol->private_value;
2675         unsigned int vref = stac92xx_vref_get(codec, nid);
2676
2677         if (vref == stac92xx_get_default_vref(codec, nid))
2678                 ucontrol->value.enumerated.item[0] = 0;
2679         else if (vref == AC_PINCTL_VREF_GRD)
2680                 ucontrol->value.enumerated.item[0] = 1;
2681         else if (vref == AC_PINCTL_VREF_HIZ)
2682                 ucontrol->value.enumerated.item[0] = 2;
2683
2684         return 0;
2685 }
2686
2687 static int stac92xx_dc_bias_put(struct snd_kcontrol *kcontrol,
2688                                 struct snd_ctl_elem_value *ucontrol)
2689 {
2690         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2691         unsigned int new_vref = 0;
2692         int error;
2693         hda_nid_t nid = kcontrol->private_value;
2694
2695         if (ucontrol->value.enumerated.item[0] == 0)
2696                 new_vref = stac92xx_get_default_vref(codec, nid);
2697         else if (ucontrol->value.enumerated.item[0] == 1)
2698                 new_vref = AC_PINCTL_VREF_GRD;
2699         else if (ucontrol->value.enumerated.item[0] == 2)
2700                 new_vref = AC_PINCTL_VREF_HIZ;
2701         else
2702                 return 0;
2703
2704         if (new_vref != stac92xx_vref_get(codec, nid)) {
2705                 error = stac92xx_vref_set(codec, nid, new_vref);
2706                 return error;
2707         }
2708
2709         return 0;
2710 }
2711
2712 static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol,
2713                                 struct snd_ctl_elem_info *uinfo)
2714 {
2715         static char *texts[2];
2716         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2717         struct sigmatel_spec *spec = codec->spec;
2718
2719         if (kcontrol->private_value == spec->line_switch)
2720                 texts[0] = "Line In";
2721         else
2722                 texts[0] = "Mic In";
2723         texts[1] = "Line Out";
2724         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2725         uinfo->value.enumerated.items = 2;
2726         uinfo->count = 1;
2727
2728         if (uinfo->value.enumerated.item >= 2)
2729                 uinfo->value.enumerated.item = 1;
2730         strcpy(uinfo->value.enumerated.name,
2731                 texts[uinfo->value.enumerated.item]);
2732
2733         return 0;
2734 }
2735
2736 static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2737 {
2738         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2739         struct sigmatel_spec *spec = codec->spec;
2740         hda_nid_t nid = kcontrol->private_value;
2741         int io_idx = (nid == spec->mic_switch) ? 1 : 0;
2742
2743         ucontrol->value.enumerated.item[0] = spec->io_switch[io_idx];
2744         return 0;
2745 }
2746
2747 static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2748 {
2749         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2750         struct sigmatel_spec *spec = codec->spec;
2751         hda_nid_t nid = kcontrol->private_value;
2752         int io_idx = (nid == spec->mic_switch) ? 1 : 0;
2753         unsigned short val = !!ucontrol->value.enumerated.item[0];
2754
2755         spec->io_switch[io_idx] = val;
2756
2757         if (val)
2758                 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
2759         else {
2760                 unsigned int pinctl = AC_PINCTL_IN_EN;
2761                 if (io_idx) /* set VREF for mic */
2762                         pinctl |= stac92xx_get_default_vref(codec, nid);
2763                 stac92xx_auto_set_pinctl(codec, nid, pinctl);
2764         }
2765
2766         /* check the auto-mute again: we need to mute/unmute the speaker
2767          * appropriately according to the pin direction
2768          */
2769         if (spec->hp_detect)
2770                 stac_issue_unsol_event(codec, nid);
2771
2772         return 1;
2773 }
2774
2775 #define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
2776
2777 static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
2778                 struct snd_ctl_elem_value *ucontrol)
2779 {
2780         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2781         struct sigmatel_spec *spec = codec->spec;
2782
2783         ucontrol->value.integer.value[0] = spec->clfe_swap;
2784         return 0;
2785 }
2786
2787 static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
2788                 struct snd_ctl_elem_value *ucontrol)
2789 {
2790         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2791         struct sigmatel_spec *spec = codec->spec;
2792         hda_nid_t nid = kcontrol->private_value & 0xff;
2793         unsigned int val = !!ucontrol->value.integer.value[0];
2794
2795         if (spec->clfe_swap == val)
2796                 return 0;
2797
2798         spec->clfe_swap = val;
2799
2800         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
2801                 spec->clfe_swap ? 0x4 : 0x0);
2802
2803         return 1;
2804 }
2805
2806 #define STAC_CODEC_HP_SWITCH(xname) \
2807         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2808           .name = xname, \
2809           .index = 0, \
2810           .info = stac92xx_hp_switch_info, \
2811           .get = stac92xx_hp_switch_get, \
2812           .put = stac92xx_hp_switch_put, \
2813         }
2814
2815 #define STAC_CODEC_IO_SWITCH(xname, xpval) \
2816         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2817           .name = xname, \
2818           .index = 0, \
2819           .info = stac92xx_io_switch_info, \
2820           .get = stac92xx_io_switch_get, \
2821           .put = stac92xx_io_switch_put, \
2822           .private_value = xpval, \
2823         }
2824
2825 #define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
2826         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2827           .name = xname, \
2828           .index = 0, \
2829           .info = stac92xx_clfe_switch_info, \
2830           .get = stac92xx_clfe_switch_get, \
2831           .put = stac92xx_clfe_switch_put, \
2832           .private_value = xpval, \
2833         }
2834
2835 enum {
2836         STAC_CTL_WIDGET_VOL,
2837         STAC_CTL_WIDGET_MUTE,
2838         STAC_CTL_WIDGET_MONO_MUX,
2839         STAC_CTL_WIDGET_AMP_MUX,
2840         STAC_CTL_WIDGET_AMP_VOL,
2841         STAC_CTL_WIDGET_HP_SWITCH,
2842         STAC_CTL_WIDGET_IO_SWITCH,
2843         STAC_CTL_WIDGET_CLFE_SWITCH,
2844         STAC_CTL_WIDGET_DC_BIAS
2845 };
2846
2847 static struct snd_kcontrol_new stac92xx_control_templates[] = {
2848         HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2849         HDA_CODEC_MUTE(NULL, 0, 0, 0),
2850         STAC_MONO_MUX,
2851         STAC_AMP_MUX,
2852         STAC_AMP_VOL(NULL, 0, 0, 0, 0),
2853         STAC_CODEC_HP_SWITCH(NULL),
2854         STAC_CODEC_IO_SWITCH(NULL, 0),
2855         STAC_CODEC_CLFE_SWITCH(NULL, 0),
2856         DC_BIAS(NULL, 0, 0),
2857 };
2858
2859 /* add dynamic controls */
2860 static struct snd_kcontrol_new *
2861 stac_control_new(struct sigmatel_spec *spec,
2862                  struct snd_kcontrol_new *ktemp,
2863                  const char *name)
2864 {
2865         struct snd_kcontrol_new *knew;
2866
2867         snd_array_init(&spec->kctls, sizeof(*knew), 32);
2868         knew = snd_array_new(&spec->kctls);
2869         if (!knew)
2870                 return NULL;
2871         *knew = *ktemp;
2872         knew->name = kstrdup(name, GFP_KERNEL);
2873         if (!knew->name) {
2874                 /* roolback */
2875                 memset(knew, 0, sizeof(*knew));
2876                 spec->kctls.alloced--;
2877                 return NULL;
2878         }
2879         return knew;
2880 }
2881
2882 static int stac92xx_add_control_temp(struct sigmatel_spec *spec,
2883                                      struct snd_kcontrol_new *ktemp,
2884                                      int idx, const char *name,
2885                                      unsigned long val)
2886 {
2887         struct snd_kcontrol_new *knew = stac_control_new(spec, ktemp, name);
2888         if (!knew)
2889                 return -ENOMEM;
2890         knew->index = idx;
2891         knew->private_value = val;
2892         return 0;
2893 }
2894
2895 static inline int stac92xx_add_control_idx(struct sigmatel_spec *spec,
2896                                            int type, int idx, const char *name,
2897                                            unsigned long val)
2898 {
2899         return stac92xx_add_control_temp(spec,
2900                                          &stac92xx_control_templates[type],
2901                                          idx, name, val);
2902 }
2903
2904
2905 /* add dynamic controls */
2906 static inline int stac92xx_add_control(struct sigmatel_spec *spec, int type,
2907                                        const char *name, unsigned long val)
2908 {
2909         return stac92xx_add_control_idx(spec, type, 0, name, val);
2910 }
2911
2912 static struct snd_kcontrol_new stac_input_src_temp = {
2913         .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2914         .name = "Input Source",
2915         .info = stac92xx_mux_enum_info,
2916         .get = stac92xx_mux_enum_get,
2917         .put = stac92xx_mux_enum_put,
2918 };
2919
2920 static inline int stac92xx_add_jack_mode_control(struct hda_codec *codec,
2921                                                 hda_nid_t nid, int idx)
2922 {
2923         int def_conf = snd_hda_codec_get_pincfg(codec, nid);
2924         int control = 0;
2925         struct sigmatel_spec *spec = codec->spec;
2926         char name[22];
2927
2928         if (!((get_defcfg_connect(def_conf)) & AC_JACK_PORT_FIXED)) {
2929                 if (stac92xx_get_default_vref(codec, nid) == AC_PINCTL_VREF_GRD
2930                         && nid == spec->line_switch)
2931                         control = STAC_CTL_WIDGET_IO_SWITCH;
2932                 else if (snd_hda_query_pin_caps(codec, nid)
2933                         & (AC_PINCAP_VREF_GRD << AC_PINCAP_VREF_SHIFT))
2934                         control = STAC_CTL_WIDGET_DC_BIAS;
2935                 else if (nid == spec->mic_switch)
2936                         control = STAC_CTL_WIDGET_IO_SWITCH;
2937         }
2938
2939         if (control) {
2940                 strcpy(name, auto_pin_cfg_labels[idx]);
2941                 return stac92xx_add_control(codec->spec, control,
2942                                         strcat(name, " Jack Mode"), nid);
2943         }
2944
2945         return 0;
2946 }
2947
2948 static int stac92xx_add_input_source(struct sigmatel_spec *spec)
2949 {
2950         struct snd_kcontrol_new *knew;
2951         struct hda_input_mux *imux = &spec->private_imux;
2952
2953         if (!spec->num_adcs || imux->num_items <= 1)
2954                 return 0; /* no need for input source control */
2955         knew = stac_control_new(spec, &stac_input_src_temp,
2956                                 stac_input_src_temp.name);
2957         if (!knew)
2958                 return -ENOMEM;
2959         knew->count = spec->num_adcs;
2960         return 0;
2961 }
2962
2963 /* check whether the line-input can be used as line-out */
2964 static hda_nid_t check_line_out_switch(struct hda_codec *codec)
2965 {
2966         struct sigmatel_spec *spec = codec->spec;
2967         struct auto_pin_cfg *cfg = &spec->autocfg;
2968         hda_nid_t nid;
2969         unsigned int pincap;
2970
2971         if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2972                 return 0;
2973         nid = cfg->input_pins[AUTO_PIN_LINE];
2974         pincap = snd_hda_query_pin_caps(codec, nid);
2975         if (pincap & AC_PINCAP_OUT)
2976                 return nid;
2977         return 0;
2978 }
2979
2980 /* check whether the mic-input can be used as line-out */
2981 static hda_nid_t check_mic_out_switch(struct hda_codec *codec)
2982 {
2983         struct sigmatel_spec *spec = codec->spec;
2984         struct auto_pin_cfg *cfg = &spec->autocfg;
2985         unsigned int def_conf, pincap;
2986         unsigned int mic_pin;
2987
2988         if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2989                 return 0;
2990         mic_pin = AUTO_PIN_MIC;
2991         for (;;) {
2992                 hda_nid_t nid = cfg->input_pins[mic_pin];
2993                 def_conf = snd_hda_codec_get_pincfg(codec, nid);
2994                 /* some laptops have an internal analog microphone
2995                  * which can't be used as a output */
2996                 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_FIXED) {
2997                         pincap = snd_hda_query_pin_caps(codec, nid);
2998                         if (pincap & AC_PINCAP_OUT)
2999                                 return nid;
3000                 }
3001                 if (mic_pin == AUTO_PIN_MIC)
3002                         mic_pin = AUTO_PIN_FRONT_MIC;
3003                 else
3004                         break;
3005         }
3006         return 0;
3007 }
3008
3009 static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
3010 {
3011         int i;
3012         
3013         for (i = 0; i < spec->multiout.num_dacs; i++) {
3014                 if (spec->multiout.dac_nids[i] == nid)
3015                         return 1;
3016         }
3017
3018         return 0;
3019 }
3020
3021 static int check_all_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
3022 {
3023         int i;
3024         if (is_in_dac_nids(spec, nid))
3025                 return 1;
3026         for (i = 0; i < spec->autocfg.hp_outs; i++)
3027                 if (spec->hp_dacs[i] == nid)
3028                         return 1;
3029         for (i = 0; i < spec->autocfg.speaker_outs; i++)
3030                 if (spec->speaker_dacs[i] == nid)
3031                         return 1;
3032         return 0;
3033 }
3034
3035 static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid)
3036 {
3037         struct sigmatel_spec *spec = codec->spec;
3038         int j, conn_len;
3039         hda_nid_t conn[HDA_MAX_CONNECTIONS];
3040         unsigned int wcaps, wtype;
3041
3042         conn_len = snd_hda_get_connections(codec, nid, conn,
3043                                            HDA_MAX_CONNECTIONS);
3044         for (j = 0; j < conn_len; j++) {
3045                 wcaps = get_wcaps(codec, conn[j]);
3046                 wtype = get_wcaps_type(wcaps);
3047                 /* we check only analog outputs */
3048                 if (wtype != AC_WID_AUD_OUT || (wcaps & AC_WCAP_DIGITAL))
3049                         continue;
3050                 /* if this route has a free DAC, assign it */
3051                 if (!check_all_dac_nids(spec, conn[j])) {
3052                         if (conn_len > 1) {
3053                                 /* select this DAC in the pin's input mux */
3054                                 snd_hda_codec_write_cache(codec, nid, 0,
3055                                                   AC_VERB_SET_CONNECT_SEL, j);
3056                         }
3057                         return conn[j];
3058                 }
3059         }
3060         /* if all DACs are already assigned, connect to the primary DAC */
3061         if (conn_len > 1) {
3062                 for (j = 0; j < conn_len; j++) {
3063                         if (conn[j] == spec->multiout.dac_nids[0]) {
3064                                 snd_hda_codec_write_cache(codec, nid, 0,
3065                                                   AC_VERB_SET_CONNECT_SEL, j);
3066                                 break;
3067                         }
3068                 }
3069         }
3070         return 0;
3071 }
3072
3073 static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
3074 static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
3075
3076 /*
3077  * Fill in the dac_nids table from the parsed pin configuration
3078  * This function only works when every pin in line_out_pins[]
3079  * contains atleast one DAC in its connection list. Some 92xx
3080  * codecs are not connected directly to a DAC, such as the 9200
3081  * and 9202/925x. For those, dac_nids[] must be hard-coded.
3082  */
3083 static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec)
3084 {
3085         struct sigmatel_spec *spec = codec->spec;
3086         struct auto_pin_cfg *cfg = &spec->autocfg;
3087         int i;
3088         hda_nid_t nid, dac;
3089         
3090         for (i = 0; i < cfg->line_outs; i++) {
3091                 nid = cfg->line_out_pins[i];
3092                 dac = get_unassigned_dac(codec, nid);
3093                 if (!dac) {
3094                         if (spec->multiout.num_dacs > 0) {
3095                                 /* we have already working output pins,
3096                                  * so let's drop the broken ones again
3097                                  */
3098                                 cfg->line_outs = spec->multiout.num_dacs;
3099                                 break;
3100                         }
3101                         /* error out, no available DAC found */
3102                         snd_printk(KERN_ERR
3103                                    "%s: No available DAC for pin 0x%x\n",
3104                                    __func__, nid);
3105                         return -ENODEV;
3106                 }
3107                 add_spec_dacs(spec, dac);
3108         }
3109
3110         for (i = 0; i < cfg->hp_outs; i++) {
3111                 nid = cfg->hp_pins[i];
3112                 dac = get_unassigned_dac(codec, nid);
3113                 if (dac) {
3114                         if (!spec->multiout.hp_nid)
3115                                 spec->multiout.hp_nid = dac;
3116                         else
3117                                 add_spec_extra_dacs(spec, dac);
3118                 }
3119                 spec->hp_dacs[i] = dac;
3120         }
3121
3122         for (i = 0; i < cfg->speaker_outs; i++) {
3123                 nid = cfg->speaker_pins[i];
3124                 dac = get_unassigned_dac(codec, nid);
3125                 if (dac)
3126                         add_spec_extra_dacs(spec, dac);
3127                 spec->speaker_dacs[i] = dac;
3128         }
3129
3130         /* add line-in as output */
3131         nid = check_line_out_switch(codec);
3132         if (nid) {
3133                 dac = get_unassigned_dac(codec, nid);
3134                 if (dac) {
3135                         snd_printdd("STAC: Add line-in 0x%x as output %d\n",
3136                                     nid, cfg->line_outs);
3137                         cfg->line_out_pins[cfg->line_outs] = nid;
3138                         cfg->line_outs++;
3139                         spec->line_switch = nid;
3140                         add_spec_dacs(spec, dac);
3141                 }
3142         }
3143         /* add mic as output */
3144         nid = check_mic_out_switch(codec);
3145         if (nid) {
3146                 dac = get_unassigned_dac(codec, nid);
3147                 if (dac) {
3148                         snd_printdd("STAC: Add mic-in 0x%x as output %d\n",
3149                                     nid, cfg->line_outs);
3150                         cfg->line_out_pins[cfg->line_outs] = nid;
3151                         cfg->line_outs++;
3152                         spec->mic_switch = nid;
3153                         add_spec_dacs(spec, dac);
3154                 }
3155         }
3156
3157         snd_printd("stac92xx: dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
3158                    spec->multiout.num_dacs,
3159                    spec->multiout.dac_nids[0],
3160                    spec->multiout.dac_nids[1],
3161                    spec->multiout.dac_nids[2],
3162                    spec->multiout.dac_nids[3],
3163                    spec->multiout.dac_nids[4]);
3164
3165         return 0;
3166 }
3167
3168 /* create volume control/switch for the given prefx type */
3169 static int create_controls_idx(struct hda_codec *codec, const char *pfx,
3170                                int idx, hda_nid_t nid, int chs)
3171 {
3172         struct sigmatel_spec *spec = codec->spec;
3173         char name[32];
3174         int err;
3175
3176         if (!spec->check_volume_offset) {
3177                 unsigned int caps, step, nums, db_scale;
3178                 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3179                 step = (caps & AC_AMPCAP_STEP_SIZE) >>
3180                         AC_AMPCAP_STEP_SIZE_SHIFT;
3181                 step = (step + 1) * 25; /* in .01dB unit */
3182                 nums = (caps & AC_AMPCAP_NUM_STEPS) >>
3183                         AC_AMPCAP_NUM_STEPS_SHIFT;