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