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