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