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