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