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