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