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