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