]> git.karo-electronics.de Git - linux-beck.git/blob - sound/pci/hda/patch_sigmatel.c
ALSA: hda: remove unused quirk for inverted mute led
[linux-beck.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 <linux/dmi.h>
32 #include <linux/module.h>
33 #include <sound/core.h>
34 #include <sound/asoundef.h>
35 #include <sound/jack.h>
36 #include <sound/tlv.h>
37 #include "hda_codec.h"
38 #include "hda_local.h"
39 #include "hda_beep.h"
40
41 enum {
42         STAC_VREF_EVENT = 1,
43         STAC_INSERT_EVENT,
44         STAC_PWR_EVENT,
45         STAC_HP_EVENT,
46         STAC_LO_EVENT,
47         STAC_MIC_EVENT,
48 };
49
50 enum {
51         STAC_AUTO,
52         STAC_REF,
53         STAC_9200_OQO,
54         STAC_9200_DELL_D21,
55         STAC_9200_DELL_D22,
56         STAC_9200_DELL_D23,
57         STAC_9200_DELL_M21,
58         STAC_9200_DELL_M22,
59         STAC_9200_DELL_M23,
60         STAC_9200_DELL_M24,
61         STAC_9200_DELL_M25,
62         STAC_9200_DELL_M26,
63         STAC_9200_DELL_M27,
64         STAC_9200_M4,
65         STAC_9200_M4_2,
66         STAC_9200_PANASONIC,
67         STAC_9200_MODELS
68 };
69
70 enum {
71         STAC_9205_AUTO,
72         STAC_9205_REF,
73         STAC_9205_DELL_M42,
74         STAC_9205_DELL_M43,
75         STAC_9205_DELL_M44,
76         STAC_9205_EAPD,
77         STAC_9205_MODELS
78 };
79
80 enum {
81         STAC_92HD73XX_AUTO,
82         STAC_92HD73XX_NO_JD, /* no jack-detection */
83         STAC_92HD73XX_REF,
84         STAC_92HD73XX_INTEL,
85         STAC_DELL_M6_AMIC,
86         STAC_DELL_M6_DMIC,
87         STAC_DELL_M6_BOTH,
88         STAC_DELL_EQ,
89         STAC_ALIENWARE_M17X,
90         STAC_92HD73XX_MODELS
91 };
92
93 enum {
94         STAC_92HD83XXX_AUTO,
95         STAC_92HD83XXX_REF,
96         STAC_92HD83XXX_PWR_REF,
97         STAC_DELL_S14,
98         STAC_DELL_VOSTRO_3500,
99         STAC_92HD83XXX_HP_cNB11_INTQUAD,
100         STAC_HP_DV7_4000,
101         STAC_92HD83XXX_MODELS
102 };
103
104 enum {
105         STAC_92HD71BXX_AUTO,
106         STAC_92HD71BXX_REF,
107         STAC_DELL_M4_1,
108         STAC_DELL_M4_2,
109         STAC_DELL_M4_3,
110         STAC_HP_M4,
111         STAC_HP_DV4,
112         STAC_HP_DV5,
113         STAC_HP_HDX,
114         STAC_HP_DV4_1222NR,
115         STAC_92HD71BXX_MODELS
116 };
117
118 enum {
119         STAC_925x_AUTO,
120         STAC_925x_REF,
121         STAC_M1,
122         STAC_M1_2,
123         STAC_M2,
124         STAC_M2_2,
125         STAC_M3,
126         STAC_M5,
127         STAC_M6,
128         STAC_925x_MODELS
129 };
130
131 enum {
132         STAC_922X_AUTO,
133         STAC_D945_REF,
134         STAC_D945GTP3,
135         STAC_D945GTP5,
136         STAC_INTEL_MAC_V1,
137         STAC_INTEL_MAC_V2,
138         STAC_INTEL_MAC_V3,
139         STAC_INTEL_MAC_V4,
140         STAC_INTEL_MAC_V5,
141         STAC_INTEL_MAC_AUTO, /* This model is selected if no module parameter
142                               * is given, one of the above models will be
143                               * chosen according to the subsystem id. */
144         /* for backward compatibility */
145         STAC_MACMINI,
146         STAC_MACBOOK,
147         STAC_MACBOOK_PRO_V1,
148         STAC_MACBOOK_PRO_V2,
149         STAC_IMAC_INTEL,
150         STAC_IMAC_INTEL_20,
151         STAC_ECS_202,
152         STAC_922X_DELL_D81,
153         STAC_922X_DELL_D82,
154         STAC_922X_DELL_M81,
155         STAC_922X_DELL_M82,
156         STAC_922X_MODELS
157 };
158
159 enum {
160         STAC_927X_AUTO,
161         STAC_D965_REF_NO_JD, /* no jack-detection */
162         STAC_D965_REF,
163         STAC_D965_3ST,
164         STAC_D965_5ST,
165         STAC_D965_5ST_NO_FP,
166         STAC_DELL_3ST,
167         STAC_DELL_BIOS,
168         STAC_927X_VOLKNOB,
169         STAC_927X_MODELS
170 };
171
172 enum {
173         STAC_9872_AUTO,
174         STAC_9872_VAIO,
175         STAC_9872_MODELS
176 };
177
178 struct sigmatel_event {
179         hda_nid_t nid;
180         unsigned char type;
181         unsigned char tag;
182         int data;
183 };
184
185 struct sigmatel_mic_route {
186         hda_nid_t pin;
187         signed char mux_idx;
188         signed char dmux_idx;
189 };
190
191 #define MAX_PINS_NUM 16
192 #define MAX_ADCS_NUM 4
193 #define MAX_DMICS_NUM 4
194
195 struct sigmatel_spec {
196         struct snd_kcontrol_new *mixers[4];
197         unsigned int num_mixers;
198
199         int board_config;
200         unsigned int eapd_switch: 1;
201         unsigned int surr_switch: 1;
202         unsigned int alt_switch: 1;
203         unsigned int hp_detect: 1;
204         unsigned int spdif_mute: 1;
205         unsigned int check_volume_offset:1;
206         unsigned int auto_mic:1;
207         unsigned int linear_tone_beep:1;
208
209         /* gpio lines */
210         unsigned int eapd_mask;
211         unsigned int gpio_mask;
212         unsigned int gpio_dir;
213         unsigned int gpio_data;
214         unsigned int gpio_mute;
215         unsigned int gpio_led;
216         unsigned int gpio_led_polarity;
217         unsigned int vref_mute_led_nid; /* pin NID for mute-LED vref control */
218         unsigned int vref_led;
219
220         /* stream */
221         unsigned int stream_delay;
222
223         /* analog loopback */
224         const struct snd_kcontrol_new *aloopback_ctl;
225         unsigned char aloopback_mask;
226         unsigned char aloopback_shift;
227
228         /* power management */
229         unsigned int num_pwrs;
230         const hda_nid_t *pwr_nids;
231         const hda_nid_t *dac_list;
232
233         /* events */
234         struct snd_array events;
235
236         /* playback */
237         struct hda_input_mux *mono_mux;
238         unsigned int cur_mmux;
239         struct hda_multi_out multiout;
240         hda_nid_t dac_nids[5];
241         hda_nid_t hp_dacs[5];
242         hda_nid_t speaker_dacs[5];
243
244         int volume_offset;
245
246         /* capture */
247         const hda_nid_t *adc_nids;
248         unsigned int num_adcs;
249         const hda_nid_t *mux_nids;
250         unsigned int num_muxes;
251         const hda_nid_t *dmic_nids;
252         unsigned int num_dmics;
253         const hda_nid_t *dmux_nids;
254         unsigned int num_dmuxes;
255         const hda_nid_t *smux_nids;
256         unsigned int num_smuxes;
257         unsigned int num_analog_muxes;
258
259         const unsigned long *capvols; /* amp-volume attr: HDA_COMPOSE_AMP_VAL() */
260         const unsigned long *capsws; /* amp-mute attr: HDA_COMPOSE_AMP_VAL() */
261         unsigned int num_caps; /* number of capture volume/switch elements */
262
263         struct sigmatel_mic_route ext_mic;
264         struct sigmatel_mic_route int_mic;
265         struct sigmatel_mic_route dock_mic;
266
267         const char * const *spdif_labels;
268
269         hda_nid_t dig_in_nid;
270         hda_nid_t mono_nid;
271         hda_nid_t anabeep_nid;
272         hda_nid_t digbeep_nid;
273
274         /* pin widgets */
275         const hda_nid_t *pin_nids;
276         unsigned int num_pins;
277
278         /* codec specific stuff */
279         const struct hda_verb *init;
280         const struct snd_kcontrol_new *mixer;
281
282         /* capture source */
283         struct hda_input_mux *dinput_mux;
284         unsigned int cur_dmux[2];
285         struct hda_input_mux *input_mux;
286         unsigned int cur_mux[3];
287         struct hda_input_mux *sinput_mux;
288         unsigned int cur_smux[2];
289         unsigned int cur_amux;
290         hda_nid_t *amp_nids;
291         unsigned int powerdown_adcs;
292
293         /* i/o switches */
294         unsigned int io_switch[2];
295         unsigned int clfe_swap;
296         hda_nid_t line_switch;  /* shared line-in for input and output */
297         hda_nid_t mic_switch;   /* shared mic-in for input and output */
298         hda_nid_t hp_switch; /* NID of HP as line-out */
299         unsigned int aloopback;
300
301         struct hda_pcm pcm_rec[2];      /* PCM information */
302
303         /* dynamic controls and input_mux */
304         struct auto_pin_cfg autocfg;
305         struct snd_array kctls;
306         struct hda_input_mux private_dimux;
307         struct hda_input_mux private_imux;
308         struct hda_input_mux private_smux;
309         struct hda_input_mux private_mono_mux;
310
311         /* auto spec */
312         unsigned auto_pin_cnt;
313         hda_nid_t auto_pin_nids[MAX_PINS_NUM];
314         unsigned auto_adc_cnt;
315         hda_nid_t auto_adc_nids[MAX_ADCS_NUM];
316         hda_nid_t auto_mux_nids[MAX_ADCS_NUM];
317         hda_nid_t auto_dmux_nids[MAX_ADCS_NUM];
318         unsigned long auto_capvols[MAX_ADCS_NUM];
319         unsigned auto_dmic_cnt;
320         hda_nid_t auto_dmic_nids[MAX_DMICS_NUM];
321 };
322
323 static const hda_nid_t stac9200_adc_nids[1] = {
324         0x03,
325 };
326
327 static const hda_nid_t stac9200_mux_nids[1] = {
328         0x0c,
329 };
330
331 static const hda_nid_t stac9200_dac_nids[1] = {
332         0x02,
333 };
334
335 static const hda_nid_t stac92hd73xx_pwr_nids[8] = {
336         0x0a, 0x0b, 0x0c, 0xd, 0x0e,
337         0x0f, 0x10, 0x11
338 };
339
340 static const hda_nid_t stac92hd73xx_slave_dig_outs[2] = {
341         0x26, 0,
342 };
343
344 static const hda_nid_t stac92hd73xx_adc_nids[2] = {
345         0x1a, 0x1b
346 };
347
348 #define STAC92HD73XX_NUM_DMICS  2
349 static const hda_nid_t stac92hd73xx_dmic_nids[STAC92HD73XX_NUM_DMICS + 1] = {
350         0x13, 0x14, 0
351 };
352
353 #define STAC92HD73_DAC_COUNT 5
354
355 static const hda_nid_t stac92hd73xx_mux_nids[2] = {
356         0x20, 0x21,
357 };
358
359 static const hda_nid_t stac92hd73xx_dmux_nids[2] = {
360         0x20, 0x21,
361 };
362
363 static const hda_nid_t stac92hd73xx_smux_nids[2] = {
364         0x22, 0x23,
365 };
366
367 #define STAC92HD73XX_NUM_CAPS   2
368 static const unsigned long stac92hd73xx_capvols[] = {
369         HDA_COMPOSE_AMP_VAL(0x20, 3, 0, HDA_OUTPUT),
370         HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
371 };
372 #define stac92hd73xx_capsws     stac92hd73xx_capvols
373
374 #define STAC92HD83_DAC_COUNT 3
375
376 static const hda_nid_t stac92hd83xxx_pwr_nids[7] = {
377         0x0a, 0x0b, 0x0c, 0xd, 0x0e,
378         0x0f, 0x10
379 };
380
381 static const hda_nid_t stac92hd83xxx_slave_dig_outs[2] = {
382         0x1e, 0,
383 };
384
385 static const hda_nid_t stac92hd83xxx_dmic_nids[] = {
386                 0x11, 0x20,
387 };
388
389 static const hda_nid_t stac92hd71bxx_pwr_nids[3] = {
390         0x0a, 0x0d, 0x0f
391 };
392
393 static const hda_nid_t stac92hd71bxx_adc_nids[2] = {
394         0x12, 0x13,
395 };
396
397 static const hda_nid_t stac92hd71bxx_mux_nids[2] = {
398         0x1a, 0x1b
399 };
400
401 static const hda_nid_t stac92hd71bxx_dmux_nids[2] = {
402         0x1c, 0x1d,
403 };
404
405 static const hda_nid_t stac92hd71bxx_smux_nids[2] = {
406         0x24, 0x25,
407 };
408
409 #define STAC92HD71BXX_NUM_DMICS 2
410 static const hda_nid_t stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS + 1] = {
411         0x18, 0x19, 0
412 };
413
414 static const hda_nid_t stac92hd71bxx_dmic_5port_nids[STAC92HD71BXX_NUM_DMICS] = {
415         0x18, 0
416 };
417
418 static const hda_nid_t stac92hd71bxx_slave_dig_outs[2] = {
419         0x22, 0
420 };
421
422 #define STAC92HD71BXX_NUM_CAPS          2
423 static const unsigned long stac92hd71bxx_capvols[] = {
424         HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
425         HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
426 };
427 #define stac92hd71bxx_capsws    stac92hd71bxx_capvols
428
429 static const hda_nid_t stac925x_adc_nids[1] = {
430         0x03,
431 };
432
433 static const hda_nid_t stac925x_mux_nids[1] = {
434         0x0f,
435 };
436
437 static const hda_nid_t stac925x_dac_nids[1] = {
438         0x02,
439 };
440
441 #define STAC925X_NUM_DMICS      1
442 static const hda_nid_t stac925x_dmic_nids[STAC925X_NUM_DMICS + 1] = {
443         0x15, 0
444 };
445
446 static const hda_nid_t stac925x_dmux_nids[1] = {
447         0x14,
448 };
449
450 static const unsigned long stac925x_capvols[] = {
451         HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
452 };
453 static const unsigned long stac925x_capsws[] = {
454         HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
455 };
456
457 static const hda_nid_t stac922x_adc_nids[2] = {
458         0x06, 0x07,
459 };
460
461 static const hda_nid_t stac922x_mux_nids[2] = {
462         0x12, 0x13,
463 };
464
465 #define STAC922X_NUM_CAPS       2
466 static const unsigned long stac922x_capvols[] = {
467         HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_INPUT),
468         HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT),
469 };
470 #define stac922x_capsws         stac922x_capvols
471
472 static const hda_nid_t stac927x_slave_dig_outs[2] = {
473         0x1f, 0,
474 };
475
476 static const hda_nid_t stac927x_adc_nids[3] = {
477         0x07, 0x08, 0x09
478 };
479
480 static const hda_nid_t stac927x_mux_nids[3] = {
481         0x15, 0x16, 0x17
482 };
483
484 static const hda_nid_t stac927x_smux_nids[1] = {
485         0x21,
486 };
487
488 static const hda_nid_t stac927x_dac_nids[6] = {
489         0x02, 0x03, 0x04, 0x05, 0x06, 0
490 };
491
492 static const hda_nid_t stac927x_dmux_nids[1] = {
493         0x1b,
494 };
495
496 #define STAC927X_NUM_DMICS 2
497 static const hda_nid_t stac927x_dmic_nids[STAC927X_NUM_DMICS + 1] = {
498         0x13, 0x14, 0
499 };
500
501 #define STAC927X_NUM_CAPS       3
502 static const unsigned long stac927x_capvols[] = {
503         HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT),
504         HDA_COMPOSE_AMP_VAL(0x19, 3, 0, HDA_INPUT),
505         HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_INPUT),
506 };
507 static const unsigned long stac927x_capsws[] = {
508         HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
509         HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
510         HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
511 };
512
513 static const char * const stac927x_spdif_labels[5] = {
514         "Digital Playback", "ADAT", "Analog Mux 1",
515         "Analog Mux 2", "Analog Mux 3"
516 };
517
518 static const hda_nid_t stac9205_adc_nids[2] = {
519         0x12, 0x13
520 };
521
522 static const hda_nid_t stac9205_mux_nids[2] = {
523         0x19, 0x1a
524 };
525
526 static const hda_nid_t stac9205_dmux_nids[1] = {
527         0x1d,
528 };
529
530 static const hda_nid_t stac9205_smux_nids[1] = {
531         0x21,
532 };
533
534 #define STAC9205_NUM_DMICS      2
535 static const hda_nid_t stac9205_dmic_nids[STAC9205_NUM_DMICS + 1] = {
536         0x17, 0x18, 0
537 };
538
539 #define STAC9205_NUM_CAPS       2
540 static const unsigned long stac9205_capvols[] = {
541         HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_INPUT),
542         HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_INPUT),
543 };
544 static const unsigned long stac9205_capsws[] = {
545         HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
546         HDA_COMPOSE_AMP_VAL(0x1e, 3, 0, HDA_OUTPUT),
547 };
548
549 static const hda_nid_t stac9200_pin_nids[8] = {
550         0x08, 0x09, 0x0d, 0x0e, 
551         0x0f, 0x10, 0x11, 0x12,
552 };
553
554 static const hda_nid_t stac925x_pin_nids[8] = {
555         0x07, 0x08, 0x0a, 0x0b, 
556         0x0c, 0x0d, 0x10, 0x11,
557 };
558
559 static const hda_nid_t stac922x_pin_nids[10] = {
560         0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
561         0x0f, 0x10, 0x11, 0x15, 0x1b,
562 };
563
564 static const hda_nid_t stac92hd73xx_pin_nids[13] = {
565         0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
566         0x0f, 0x10, 0x11, 0x12, 0x13,
567         0x14, 0x22, 0x23
568 };
569
570 #define STAC92HD71BXX_NUM_PINS 13
571 static const hda_nid_t stac92hd71bxx_pin_nids_4port[STAC92HD71BXX_NUM_PINS] = {
572         0x0a, 0x0b, 0x0c, 0x0d, 0x00,
573         0x00, 0x14, 0x18, 0x19, 0x1e,
574         0x1f, 0x20, 0x27
575 };
576 static const hda_nid_t stac92hd71bxx_pin_nids_6port[STAC92HD71BXX_NUM_PINS] = {
577         0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
578         0x0f, 0x14, 0x18, 0x19, 0x1e,
579         0x1f, 0x20, 0x27
580 };
581
582 static const hda_nid_t stac927x_pin_nids[14] = {
583         0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
584         0x0f, 0x10, 0x11, 0x12, 0x13,
585         0x14, 0x21, 0x22, 0x23,
586 };
587
588 static const hda_nid_t stac9205_pin_nids[12] = {
589         0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
590         0x0f, 0x14, 0x16, 0x17, 0x18,
591         0x21, 0x22,
592 };
593
594 static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
595                                    struct snd_ctl_elem_info *uinfo)
596 {
597         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
598         struct sigmatel_spec *spec = codec->spec;
599         return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
600 }
601
602 static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
603                                   struct snd_ctl_elem_value *ucontrol)
604 {
605         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
606         struct sigmatel_spec *spec = codec->spec;
607         unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
608
609         ucontrol->value.enumerated.item[0] = spec->cur_dmux[dmux_idx];
610         return 0;
611 }
612
613 static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
614                                   struct snd_ctl_elem_value *ucontrol)
615 {
616         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
617         struct sigmatel_spec *spec = codec->spec;
618         unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
619
620         return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
621                         spec->dmux_nids[dmux_idx], &spec->cur_dmux[dmux_idx]);
622 }
623
624 static int stac92xx_smux_enum_info(struct snd_kcontrol *kcontrol,
625                                    struct snd_ctl_elem_info *uinfo)
626 {
627         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
628         struct sigmatel_spec *spec = codec->spec;
629         return snd_hda_input_mux_info(spec->sinput_mux, uinfo);
630 }
631
632 static int stac92xx_smux_enum_get(struct snd_kcontrol *kcontrol,
633                                   struct snd_ctl_elem_value *ucontrol)
634 {
635         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
636         struct sigmatel_spec *spec = codec->spec;
637         unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
638
639         ucontrol->value.enumerated.item[0] = spec->cur_smux[smux_idx];
640         return 0;
641 }
642
643 static int stac92xx_smux_enum_put(struct snd_kcontrol *kcontrol,
644                                   struct snd_ctl_elem_value *ucontrol)
645 {
646         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
647         struct sigmatel_spec *spec = codec->spec;
648         struct hda_input_mux *smux = &spec->private_smux;
649         unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
650         int err, val;
651         hda_nid_t nid;
652
653         err = snd_hda_input_mux_put(codec, spec->sinput_mux, ucontrol,
654                         spec->smux_nids[smux_idx], &spec->cur_smux[smux_idx]);
655         if (err < 0)
656                 return err;
657
658         if (spec->spdif_mute) {
659                 if (smux_idx == 0)
660                         nid = spec->multiout.dig_out_nid;
661                 else
662                         nid = codec->slave_dig_outs[smux_idx - 1];
663                 if (spec->cur_smux[smux_idx] == smux->num_items - 1)
664                         val = HDA_AMP_MUTE;
665                 else
666                         val = 0;
667                 /* un/mute SPDIF out */
668                 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
669                                          HDA_AMP_MUTE, val);
670         }
671         return 0;
672 }
673
674 #ifdef CONFIG_SND_HDA_POWER_SAVE
675 static int stac_vrefout_set(struct hda_codec *codec,
676                                         hda_nid_t nid, unsigned int new_vref)
677 {
678         int error, pinctl;
679
680         snd_printdd("%s, nid %x ctl %x\n", __func__, nid, new_vref);
681         pinctl = snd_hda_codec_read(codec, nid, 0,
682                                 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
683
684         if (pinctl < 0)
685                 return pinctl;
686
687         pinctl &= 0xff;
688         pinctl &= ~AC_PINCTL_VREFEN;
689         pinctl |= (new_vref & AC_PINCTL_VREFEN);
690
691         error = snd_hda_codec_write_cache(codec, nid, 0,
692                                         AC_VERB_SET_PIN_WIDGET_CONTROL, pinctl);
693         if (error < 0)
694                 return error;
695
696         return 1;
697 }
698 #endif
699
700 static unsigned int stac92xx_vref_set(struct hda_codec *codec,
701                                         hda_nid_t nid, unsigned int new_vref)
702 {
703         int error;
704         unsigned int pincfg;
705         pincfg = snd_hda_codec_read(codec, nid, 0,
706                                 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
707
708         pincfg &= 0xff;
709         pincfg &= ~(AC_PINCTL_VREFEN | AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
710         pincfg |= new_vref;
711
712         if (new_vref == AC_PINCTL_VREF_HIZ)
713                 pincfg |= AC_PINCTL_OUT_EN;
714         else
715                 pincfg |= AC_PINCTL_IN_EN;
716
717         error = snd_hda_codec_write_cache(codec, nid, 0,
718                                         AC_VERB_SET_PIN_WIDGET_CONTROL, pincfg);
719         if (error < 0)
720                 return error;
721         else
722                 return 1;
723 }
724
725 static unsigned int stac92xx_vref_get(struct hda_codec *codec, hda_nid_t nid)
726 {
727         unsigned int vref;
728         vref = snd_hda_codec_read(codec, nid, 0,
729                                 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
730         vref &= AC_PINCTL_VREFEN;
731         return vref;
732 }
733
734 static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
735 {
736         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
737         struct sigmatel_spec *spec = codec->spec;
738         return snd_hda_input_mux_info(spec->input_mux, uinfo);
739 }
740
741 static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
742 {
743         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
744         struct sigmatel_spec *spec = codec->spec;
745         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
746
747         ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
748         return 0;
749 }
750
751 static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
752 {
753         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
754         struct sigmatel_spec *spec = codec->spec;
755         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
756         const struct hda_input_mux *imux = spec->input_mux;
757         unsigned int idx, prev_idx, didx;
758
759         idx = ucontrol->value.enumerated.item[0];
760         if (idx >= imux->num_items)
761                 idx = imux->num_items - 1;
762         prev_idx = spec->cur_mux[adc_idx];
763         if (prev_idx == idx)
764                 return 0;
765         if (idx < spec->num_analog_muxes) {
766                 snd_hda_codec_write_cache(codec, spec->mux_nids[adc_idx], 0,
767                                           AC_VERB_SET_CONNECT_SEL,
768                                           imux->items[idx].index);
769                 if (prev_idx >= spec->num_analog_muxes &&
770                     spec->mux_nids[adc_idx] != spec->dmux_nids[adc_idx]) {
771                         imux = spec->dinput_mux;
772                         /* 0 = analog */
773                         snd_hda_codec_write_cache(codec,
774                                                   spec->dmux_nids[adc_idx], 0,
775                                                   AC_VERB_SET_CONNECT_SEL,
776                                                   imux->items[0].index);
777                 }
778         } else {
779                 imux = spec->dinput_mux;
780                 /* first dimux item is hardcoded to select analog imux,
781                  * so lets skip it
782                  */
783                 didx = idx - spec->num_analog_muxes + 1;
784                 snd_hda_codec_write_cache(codec, spec->dmux_nids[adc_idx], 0,
785                                           AC_VERB_SET_CONNECT_SEL,
786                                           imux->items[didx].index);
787         }
788         spec->cur_mux[adc_idx] = idx;
789         return 1;
790 }
791
792 static int stac92xx_mono_mux_enum_info(struct snd_kcontrol *kcontrol,
793         struct snd_ctl_elem_info *uinfo)
794 {
795         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
796         struct sigmatel_spec *spec = codec->spec;
797         return snd_hda_input_mux_info(spec->mono_mux, uinfo);
798 }
799
800 static int stac92xx_mono_mux_enum_get(struct snd_kcontrol *kcontrol,
801         struct snd_ctl_elem_value *ucontrol)
802 {
803         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
804         struct sigmatel_spec *spec = codec->spec;
805
806         ucontrol->value.enumerated.item[0] = spec->cur_mmux;
807         return 0;
808 }
809
810 static int stac92xx_mono_mux_enum_put(struct snd_kcontrol *kcontrol,
811         struct snd_ctl_elem_value *ucontrol)
812 {
813         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
814         struct sigmatel_spec *spec = codec->spec;
815
816         return snd_hda_input_mux_put(codec, spec->mono_mux, ucontrol,
817                                      spec->mono_nid, &spec->cur_mmux);
818 }
819
820 #define stac92xx_aloopback_info snd_ctl_boolean_mono_info
821
822 static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol,
823         struct snd_ctl_elem_value *ucontrol)
824 {
825         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
826         unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
827         struct sigmatel_spec *spec = codec->spec;
828
829         ucontrol->value.integer.value[0] = !!(spec->aloopback &
830                                               (spec->aloopback_mask << idx));
831         return 0;
832 }
833
834 static int stac92xx_aloopback_put(struct snd_kcontrol *kcontrol,
835                 struct snd_ctl_elem_value *ucontrol)
836 {
837         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
838         struct sigmatel_spec *spec = codec->spec;
839         unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
840         unsigned int dac_mode;
841         unsigned int val, idx_val;
842
843         idx_val = spec->aloopback_mask << idx;
844         if (ucontrol->value.integer.value[0])
845                 val = spec->aloopback | idx_val;
846         else
847                 val = spec->aloopback & ~idx_val;
848         if (spec->aloopback == val)
849                 return 0;
850
851         spec->aloopback = val;
852
853         /* Only return the bits defined by the shift value of the
854          * first two bytes of the mask
855          */
856         dac_mode = snd_hda_codec_read(codec, codec->afg, 0,
857                                       kcontrol->private_value & 0xFFFF, 0x0);
858         dac_mode >>= spec->aloopback_shift;
859
860         if (spec->aloopback & idx_val) {
861                 snd_hda_power_up(codec);
862                 dac_mode |= idx_val;
863         } else {
864                 snd_hda_power_down(codec);
865                 dac_mode &= ~idx_val;
866         }
867
868         snd_hda_codec_write_cache(codec, codec->afg, 0,
869                 kcontrol->private_value >> 16, dac_mode);
870
871         return 1;
872 }
873
874 static const struct hda_verb stac9200_core_init[] = {
875         /* set dac0mux for dac converter */
876         { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
877         {}
878 };
879
880 static const struct hda_verb stac9200_eapd_init[] = {
881         /* set dac0mux for dac converter */
882         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
883         {0x08, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
884         {}
885 };
886
887 static const struct hda_verb dell_eq_core_init[] = {
888         /* set master volume to max value without distortion
889          * and direct control */
890         { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xec},
891         {}
892 };
893
894 static const struct hda_verb stac92hd73xx_core_init[] = {
895         /* set master volume and direct control */
896         { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
897         {}
898 };
899
900 static const struct hda_verb stac92hd83xxx_core_init[] = {
901         /* power state controls amps */
902         { 0x01, AC_VERB_SET_EAPD, 1 << 2},
903         {}
904 };
905
906 static const struct hda_verb stac92hd71bxx_core_init[] = {
907         /* set master volume and direct control */
908         { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
909         {}
910 };
911
912 static const struct hda_verb stac92hd71bxx_unmute_core_init[] = {
913         /* unmute right and left channels for nodes 0x0f, 0xa, 0x0d */
914         { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
915         { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
916         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
917         {}
918 };
919
920 static const struct hda_verb stac925x_core_init[] = {
921         /* set dac0mux for dac converter */
922         { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
923         /* mute the master volume */
924         { 0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
925         {}
926 };
927
928 static const struct hda_verb stac922x_core_init[] = {
929         /* set master volume and direct control */      
930         { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
931         {}
932 };
933
934 static const struct hda_verb d965_core_init[] = {
935         /* set master volume and direct control */      
936         { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
937         /* unmute node 0x1b */
938         { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
939         /* select node 0x03 as DAC */   
940         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
941         {}
942 };
943
944 static const struct hda_verb dell_3st_core_init[] = {
945         /* don't set delta bit */
946         {0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0x7f},
947         /* unmute node 0x1b */
948         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
949         /* select node 0x03 as DAC */
950         {0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
951         {}
952 };
953
954 static const struct hda_verb stac927x_core_init[] = {
955         /* set master volume and direct control */      
956         { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
957         /* enable analog pc beep path */
958         { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
959         {}
960 };
961
962 static const struct hda_verb stac927x_volknob_core_init[] = {
963         /* don't set delta bit */
964         {0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0x7f},
965         /* enable analog pc beep path */
966         {0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
967         {}
968 };
969
970 static const struct hda_verb stac9205_core_init[] = {
971         /* set master volume and direct control */      
972         { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
973         /* enable analog pc beep path */
974         { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
975         {}
976 };
977
978 #define STAC_MONO_MUX \
979         { \
980                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
981                 .name = "Mono Mux", \
982                 .count = 1, \
983                 .info = stac92xx_mono_mux_enum_info, \
984                 .get = stac92xx_mono_mux_enum_get, \
985                 .put = stac92xx_mono_mux_enum_put, \
986         }
987
988 #define STAC_ANALOG_LOOPBACK(verb_read, verb_write, cnt) \
989         { \
990                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
991                 .name  = "Analog Loopback", \
992                 .count = cnt, \
993                 .info  = stac92xx_aloopback_info, \
994                 .get   = stac92xx_aloopback_get, \
995                 .put   = stac92xx_aloopback_put, \
996                 .private_value = verb_read | (verb_write << 16), \
997         }
998
999 #define DC_BIAS(xname, idx, nid) \
1000         { \
1001                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1002                 .name = xname, \
1003                 .index = idx, \
1004                 .info = stac92xx_dc_bias_info, \
1005                 .get = stac92xx_dc_bias_get, \
1006                 .put = stac92xx_dc_bias_put, \
1007                 .private_value = nid, \
1008         }
1009
1010 static const struct snd_kcontrol_new stac9200_mixer[] = {
1011         HDA_CODEC_VOLUME_MIN_MUTE("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
1012         HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
1013         HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
1014         HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
1015         { } /* end */
1016 };
1017
1018 static const struct snd_kcontrol_new stac92hd73xx_6ch_loopback[] = {
1019         STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 3),
1020         {}
1021 };
1022
1023 static const struct snd_kcontrol_new stac92hd73xx_8ch_loopback[] = {
1024         STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 4),
1025         {}
1026 };
1027
1028 static const struct snd_kcontrol_new stac92hd73xx_10ch_loopback[] = {
1029         STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 5),
1030         {}
1031 };
1032
1033
1034 static const struct snd_kcontrol_new stac92hd71bxx_loopback[] = {
1035         STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2)
1036 };
1037
1038 static const struct snd_kcontrol_new stac925x_mixer[] = {
1039         HDA_CODEC_VOLUME_MIN_MUTE("Master Playback Volume", 0xe, 0, HDA_OUTPUT),
1040         HDA_CODEC_MUTE("Master Playback Switch", 0x0e, 0, HDA_OUTPUT),
1041         { } /* end */
1042 };
1043
1044 static const struct snd_kcontrol_new stac9205_loopback[] = {
1045         STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0, 1),
1046         {}
1047 };
1048
1049 static const struct snd_kcontrol_new stac927x_loopback[] = {
1050         STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB, 1),
1051         {}
1052 };
1053
1054 static struct snd_kcontrol_new stac_dmux_mixer = {
1055         .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1056         .name = "Digital Input Source",
1057         /* count set later */
1058         .info = stac92xx_dmux_enum_info,
1059         .get = stac92xx_dmux_enum_get,
1060         .put = stac92xx_dmux_enum_put,
1061 };
1062
1063 static struct snd_kcontrol_new stac_smux_mixer = {
1064         .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1065         .name = "IEC958 Playback Source",
1066         /* count set later */
1067         .info = stac92xx_smux_enum_info,
1068         .get = stac92xx_smux_enum_get,
1069         .put = stac92xx_smux_enum_put,
1070 };
1071
1072 static const char * const slave_vols[] = {
1073         "Front Playback Volume",
1074         "Surround Playback Volume",
1075         "Center Playback Volume",
1076         "LFE Playback Volume",
1077         "Side Playback Volume",
1078         "Headphone Playback Volume",
1079         "Speaker Playback Volume",
1080         NULL
1081 };
1082
1083 static const char * const slave_sws[] = {
1084         "Front Playback Switch",
1085         "Surround Playback Switch",
1086         "Center Playback Switch",
1087         "LFE Playback Switch",
1088         "Side Playback Switch",
1089         "Headphone Playback Switch",
1090         "Speaker Playback Switch",
1091         "IEC958 Playback Switch",
1092         NULL
1093 };
1094
1095 static void stac92xx_free_kctls(struct hda_codec *codec);
1096 static int stac92xx_add_jack(struct hda_codec *codec, hda_nid_t nid, int type);
1097
1098 static int stac92xx_build_controls(struct hda_codec *codec)
1099 {
1100         struct sigmatel_spec *spec = codec->spec;
1101         struct auto_pin_cfg *cfg = &spec->autocfg;
1102         hda_nid_t nid;
1103         int err;
1104         int i;
1105
1106         if (spec->mixer) {
1107                 err = snd_hda_add_new_ctls(codec, spec->mixer);
1108                 if (err < 0)
1109                         return err;
1110         }
1111
1112         for (i = 0; i < spec->num_mixers; i++) {
1113                 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1114                 if (err < 0)
1115                         return err;
1116         }
1117         if (!spec->auto_mic && spec->num_dmuxes > 0 &&
1118             snd_hda_get_bool_hint(codec, "separate_dmux") == 1) {
1119                 stac_dmux_mixer.count = spec->num_dmuxes;
1120                 err = snd_hda_ctl_add(codec, 0,
1121                                   snd_ctl_new1(&stac_dmux_mixer, codec));
1122                 if (err < 0)
1123                         return err;
1124         }
1125         if (spec->num_smuxes > 0) {
1126                 int wcaps = get_wcaps(codec, spec->multiout.dig_out_nid);
1127                 struct hda_input_mux *smux = &spec->private_smux;
1128                 /* check for mute support on SPDIF out */
1129                 if (wcaps & AC_WCAP_OUT_AMP) {
1130                         snd_hda_add_imux_item(smux, "Off", 0, NULL);
1131                         spec->spdif_mute = 1;
1132                 }
1133                 stac_smux_mixer.count = spec->num_smuxes;
1134                 err = snd_hda_ctl_add(codec, 0,
1135                                   snd_ctl_new1(&stac_smux_mixer, codec));
1136                 if (err < 0)
1137                         return err;
1138         }
1139
1140         if (spec->multiout.dig_out_nid) {
1141                 err = snd_hda_create_spdif_out_ctls(codec,
1142                                                     spec->multiout.dig_out_nid,
1143                                                     spec->multiout.dig_out_nid);
1144                 if (err < 0)
1145                         return err;
1146                 err = snd_hda_create_spdif_share_sw(codec,
1147                                                     &spec->multiout);
1148                 if (err < 0)
1149                         return err;
1150                 spec->multiout.share_spdif = 1;
1151         }
1152         if (spec->dig_in_nid && !(spec->gpio_dir & 0x01)) {
1153                 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1154                 if (err < 0)
1155                         return err;
1156         }
1157
1158         /* if we have no master control, let's create it */
1159         if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1160                 unsigned int vmaster_tlv[4];
1161                 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
1162                                         HDA_OUTPUT, vmaster_tlv);
1163                 /* correct volume offset */
1164                 vmaster_tlv[2] += vmaster_tlv[3] * spec->volume_offset;
1165                 /* minimum value is actually mute */
1166                 vmaster_tlv[3] |= TLV_DB_SCALE_MUTE;
1167                 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1168                                           vmaster_tlv, slave_vols);
1169                 if (err < 0)
1170                         return err;
1171         }
1172         if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1173                 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1174                                           NULL, slave_sws);
1175                 if (err < 0)
1176                         return err;
1177         }
1178
1179         if (spec->aloopback_ctl &&
1180             snd_hda_get_bool_hint(codec, "loopback") == 1) {
1181                 err = snd_hda_add_new_ctls(codec, spec->aloopback_ctl);
1182                 if (err < 0)
1183                         return err;
1184         }
1185
1186         stac92xx_free_kctls(codec); /* no longer needed */
1187
1188         /* create jack input elements */
1189         if (spec->hp_detect) {
1190                 for (i = 0; i < cfg->hp_outs; i++) {
1191                         int type = SND_JACK_HEADPHONE;
1192                         nid = cfg->hp_pins[i];
1193                         /* jack detection */
1194                         if (cfg->hp_outs == i)
1195                                 type |= SND_JACK_LINEOUT;
1196                         err = stac92xx_add_jack(codec, nid, type);
1197                         if (err < 0)
1198                                 return err;
1199                 }
1200         }
1201         for (i = 0; i < cfg->line_outs; i++) {
1202                 err = stac92xx_add_jack(codec, cfg->line_out_pins[i],
1203                                         SND_JACK_LINEOUT);
1204                 if (err < 0)
1205                         return err;
1206         }
1207         for (i = 0; i < cfg->num_inputs; i++) {
1208                 nid = cfg->inputs[i].pin;
1209                 err = stac92xx_add_jack(codec, nid, SND_JACK_MICROPHONE);
1210                 if (err < 0)
1211                         return err;
1212         }
1213
1214         return 0;       
1215 }
1216
1217 static const unsigned int ref9200_pin_configs[8] = {
1218         0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
1219         0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
1220 };
1221
1222 static const unsigned int gateway9200_m4_pin_configs[8] = {
1223         0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1224         0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1225 };
1226 static const unsigned int gateway9200_m4_2_pin_configs[8] = {
1227         0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1228         0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1229 };
1230
1231 /*
1232     STAC 9200 pin configs for
1233     102801A8
1234     102801DE
1235     102801E8
1236 */
1237 static const unsigned int dell9200_d21_pin_configs[8] = {
1238         0x400001f0, 0x400001f1, 0x02214030, 0x01014010, 
1239         0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
1240 };
1241
1242 /* 
1243     STAC 9200 pin configs for
1244     102801C0
1245     102801C1
1246 */
1247 static const unsigned int dell9200_d22_pin_configs[8] = {
1248         0x400001f0, 0x400001f1, 0x0221401f, 0x01014010, 
1249         0x01813020, 0x02a19021, 0x90100140, 0x400001f2,
1250 };
1251
1252 /* 
1253     STAC 9200 pin configs for
1254     102801C4 (Dell Dimension E310)
1255     102801C5
1256     102801C7
1257     102801D9
1258     102801DA
1259     102801E3
1260 */
1261 static const unsigned int dell9200_d23_pin_configs[8] = {
1262         0x400001f0, 0x400001f1, 0x0221401f, 0x01014010, 
1263         0x01813020, 0x01a19021, 0x90100140, 0x400001f2, 
1264 };
1265
1266
1267 /* 
1268     STAC 9200-32 pin configs for
1269     102801B5 (Dell Inspiron 630m)
1270     102801D8 (Dell Inspiron 640m)
1271 */
1272 static const unsigned int dell9200_m21_pin_configs[8] = {
1273         0x40c003fa, 0x03441340, 0x0321121f, 0x90170310,
1274         0x408003fb, 0x03a11020, 0x401003fc, 0x403003fd,
1275 };
1276
1277 /* 
1278     STAC 9200-32 pin configs for
1279     102801C2 (Dell Latitude D620)
1280     102801C8 
1281     102801CC (Dell Latitude D820)
1282     102801D4 
1283     102801D6 
1284 */
1285 static const unsigned int dell9200_m22_pin_configs[8] = {
1286         0x40c003fa, 0x0144131f, 0x0321121f, 0x90170310, 
1287         0x90a70321, 0x03a11020, 0x401003fb, 0x40f000fc,
1288 };
1289
1290 /* 
1291     STAC 9200-32 pin configs for
1292     102801CE (Dell XPS M1710)
1293     102801CF (Dell Precision M90)
1294 */
1295 static const unsigned int dell9200_m23_pin_configs[8] = {
1296         0x40c003fa, 0x01441340, 0x0421421f, 0x90170310,
1297         0x408003fb, 0x04a1102e, 0x90170311, 0x403003fc,
1298 };
1299
1300 /*
1301     STAC 9200-32 pin configs for 
1302     102801C9
1303     102801CA
1304     102801CB (Dell Latitude 120L)
1305     102801D3
1306 */
1307 static const unsigned int dell9200_m24_pin_configs[8] = {
1308         0x40c003fa, 0x404003fb, 0x0321121f, 0x90170310, 
1309         0x408003fc, 0x03a11020, 0x401003fd, 0x403003fe, 
1310 };
1311
1312 /*
1313     STAC 9200-32 pin configs for
1314     102801BD (Dell Inspiron E1505n)
1315     102801EE
1316     102801EF
1317 */
1318 static const unsigned int dell9200_m25_pin_configs[8] = {
1319         0x40c003fa, 0x01441340, 0x0421121f, 0x90170310, 
1320         0x408003fb, 0x04a11020, 0x401003fc, 0x403003fd,
1321 };
1322
1323 /*
1324     STAC 9200-32 pin configs for
1325     102801F5 (Dell Inspiron 1501)
1326     102801F6
1327 */
1328 static const unsigned int dell9200_m26_pin_configs[8] = {
1329         0x40c003fa, 0x404003fb, 0x0421121f, 0x90170310, 
1330         0x408003fc, 0x04a11020, 0x401003fd, 0x403003fe,
1331 };
1332
1333 /*
1334     STAC 9200-32
1335     102801CD (Dell Inspiron E1705/9400)
1336 */
1337 static const unsigned int dell9200_m27_pin_configs[8] = {
1338         0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1339         0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
1340 };
1341
1342 static const unsigned int oqo9200_pin_configs[8] = {
1343         0x40c000f0, 0x404000f1, 0x0221121f, 0x02211210,
1344         0x90170111, 0x90a70120, 0x400000f2, 0x400000f3,
1345 };
1346
1347
1348 static const unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
1349         [STAC_REF] = ref9200_pin_configs,
1350         [STAC_9200_OQO] = oqo9200_pin_configs,
1351         [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
1352         [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
1353         [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
1354         [STAC_9200_DELL_M21] = dell9200_m21_pin_configs,
1355         [STAC_9200_DELL_M22] = dell9200_m22_pin_configs,
1356         [STAC_9200_DELL_M23] = dell9200_m23_pin_configs,
1357         [STAC_9200_DELL_M24] = dell9200_m24_pin_configs,
1358         [STAC_9200_DELL_M25] = dell9200_m25_pin_configs,
1359         [STAC_9200_DELL_M26] = dell9200_m26_pin_configs,
1360         [STAC_9200_DELL_M27] = dell9200_m27_pin_configs,
1361         [STAC_9200_M4] = gateway9200_m4_pin_configs,
1362         [STAC_9200_M4_2] = gateway9200_m4_2_pin_configs,
1363         [STAC_9200_PANASONIC] = ref9200_pin_configs,
1364 };
1365
1366 static const char * const stac9200_models[STAC_9200_MODELS] = {
1367         [STAC_AUTO] = "auto",
1368         [STAC_REF] = "ref",
1369         [STAC_9200_OQO] = "oqo",
1370         [STAC_9200_DELL_D21] = "dell-d21",
1371         [STAC_9200_DELL_D22] = "dell-d22",
1372         [STAC_9200_DELL_D23] = "dell-d23",
1373         [STAC_9200_DELL_M21] = "dell-m21",
1374         [STAC_9200_DELL_M22] = "dell-m22",
1375         [STAC_9200_DELL_M23] = "dell-m23",
1376         [STAC_9200_DELL_M24] = "dell-m24",
1377         [STAC_9200_DELL_M25] = "dell-m25",
1378         [STAC_9200_DELL_M26] = "dell-m26",
1379         [STAC_9200_DELL_M27] = "dell-m27",
1380         [STAC_9200_M4] = "gateway-m4",
1381         [STAC_9200_M4_2] = "gateway-m4-2",
1382         [STAC_9200_PANASONIC] = "panasonic",
1383 };
1384
1385 static const struct snd_pci_quirk stac9200_cfg_tbl[] = {
1386         /* SigmaTel reference board */
1387         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1388                       "DFI LanParty", STAC_REF),
1389         SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1390                       "DFI LanParty", STAC_REF),
1391         /* Dell laptops have BIOS problem */
1392         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
1393                       "unknown Dell", STAC_9200_DELL_D21),
1394         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
1395                       "Dell Inspiron 630m", STAC_9200_DELL_M21),
1396         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bd,
1397                       "Dell Inspiron E1505n", STAC_9200_DELL_M25),
1398         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c0,
1399                       "unknown Dell", STAC_9200_DELL_D22),
1400         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c1,
1401                       "unknown Dell", STAC_9200_DELL_D22),
1402         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
1403                       "Dell Latitude D620", STAC_9200_DELL_M22),
1404         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c5,
1405                       "unknown Dell", STAC_9200_DELL_D23),
1406         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c7,
1407                       "unknown Dell", STAC_9200_DELL_D23),
1408         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c8,
1409                       "unknown Dell", STAC_9200_DELL_M22),
1410         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c9,
1411                       "unknown Dell", STAC_9200_DELL_M24),
1412         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ca,
1413                       "unknown Dell", STAC_9200_DELL_M24),
1414         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
1415                       "Dell Latitude 120L", STAC_9200_DELL_M24),
1416         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
1417                       "Dell Latitude D820", STAC_9200_DELL_M22),
1418         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
1419                       "Dell Inspiron E1705/9400", STAC_9200_DELL_M27),
1420         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
1421                       "Dell XPS M1710", STAC_9200_DELL_M23),
1422         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
1423                       "Dell Precision M90", STAC_9200_DELL_M23),
1424         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d3,
1425                       "unknown Dell", STAC_9200_DELL_M22),
1426         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d4,
1427                       "unknown Dell", STAC_9200_DELL_M22),
1428         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
1429                       "unknown Dell", STAC_9200_DELL_M22),
1430         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
1431                       "Dell Inspiron 640m", STAC_9200_DELL_M21),
1432         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d9,
1433                       "unknown Dell", STAC_9200_DELL_D23),
1434         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01da,
1435                       "unknown Dell", STAC_9200_DELL_D23),
1436         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01de,
1437                       "unknown Dell", STAC_9200_DELL_D21),
1438         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e3,
1439                       "unknown Dell", STAC_9200_DELL_D23),
1440         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e8,
1441                       "unknown Dell", STAC_9200_DELL_D21),
1442         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ee,
1443                       "unknown Dell", STAC_9200_DELL_M25),
1444         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ef,
1445                       "unknown Dell", STAC_9200_DELL_M25),
1446         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
1447                       "Dell Inspiron 1501", STAC_9200_DELL_M26),
1448         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
1449                       "unknown Dell", STAC_9200_DELL_M26),
1450         /* Panasonic */
1451         SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_9200_PANASONIC),
1452         /* Gateway machines needs EAPD to be set on resume */
1453         SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_M4),
1454         SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*", STAC_9200_M4_2),
1455         SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707", STAC_9200_M4_2),
1456         /* OQO Mobile */
1457         SND_PCI_QUIRK(0x1106, 0x3288, "OQO Model 2", STAC_9200_OQO),
1458         {} /* terminator */
1459 };
1460
1461 static const unsigned int ref925x_pin_configs[8] = {
1462         0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
1463         0x90a70320, 0x02214210, 0x01019020, 0x9033032e,
1464 };
1465
1466 static const unsigned int stac925xM1_pin_configs[8] = {
1467         0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1468         0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1469 };
1470
1471 static const unsigned int stac925xM1_2_pin_configs[8] = {
1472         0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1473         0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1474 };
1475
1476 static const unsigned int stac925xM2_pin_configs[8] = {
1477         0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1478         0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1479 };
1480
1481 static const unsigned int stac925xM2_2_pin_configs[8] = {
1482         0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1483         0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1484 };
1485
1486 static const unsigned int stac925xM3_pin_configs[8] = {
1487         0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1488         0x40a000f0, 0x90100210, 0x400003f1, 0x503303f3,
1489 };
1490
1491 static const unsigned int stac925xM5_pin_configs[8] = {
1492         0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1493         0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1494 };
1495
1496 static const unsigned int stac925xM6_pin_configs[8] = {
1497         0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1498         0x40a000f0, 0x90100210, 0x400003f1, 0x90330320,
1499 };
1500
1501 static const unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
1502         [STAC_REF] = ref925x_pin_configs,
1503         [STAC_M1] = stac925xM1_pin_configs,
1504         [STAC_M1_2] = stac925xM1_2_pin_configs,
1505         [STAC_M2] = stac925xM2_pin_configs,
1506         [STAC_M2_2] = stac925xM2_2_pin_configs,
1507         [STAC_M3] = stac925xM3_pin_configs,
1508         [STAC_M5] = stac925xM5_pin_configs,
1509         [STAC_M6] = stac925xM6_pin_configs,
1510 };
1511
1512 static const char * const stac925x_models[STAC_925x_MODELS] = {
1513         [STAC_925x_AUTO] = "auto",
1514         [STAC_REF] = "ref",
1515         [STAC_M1] = "m1",
1516         [STAC_M1_2] = "m1-2",
1517         [STAC_M2] = "m2",
1518         [STAC_M2_2] = "m2-2",
1519         [STAC_M3] = "m3",
1520         [STAC_M5] = "m5",
1521         [STAC_M6] = "m6",
1522 };
1523
1524 static const struct snd_pci_quirk stac925x_codec_id_cfg_tbl[] = {
1525         SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_M2),
1526         SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_M5),
1527         SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_M1),
1528         SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_M2),
1529         SND_PCI_QUIRK(0x107b, 0x0367, "Gateway MX6453", STAC_M1_2),
1530         /* Not sure about the brand name for those */
1531         SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M1),
1532         SND_PCI_QUIRK(0x107b, 0x0507, "Gateway mobile", STAC_M3),
1533         SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M6),
1534         SND_PCI_QUIRK(0x107b, 0x0685, "Gateway mobile", STAC_M2_2),
1535         {} /* terminator */
1536 };
1537
1538 static const struct snd_pci_quirk stac925x_cfg_tbl[] = {
1539         /* SigmaTel reference board */
1540         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
1541         SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101, "DFI LanParty", STAC_REF),
1542         SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
1543
1544         /* Default table for unknown ID */
1545         SND_PCI_QUIRK(0x1002, 0x437b, "Gateway mobile", STAC_M2_2),
1546
1547         {} /* terminator */
1548 };
1549
1550 static const unsigned int ref92hd73xx_pin_configs[13] = {
1551         0x02214030, 0x02a19040, 0x01a19020, 0x02214030,
1552         0x0181302e, 0x01014010, 0x01014020, 0x01014030,
1553         0x02319040, 0x90a000f0, 0x90a000f0, 0x01452050,
1554         0x01452050,
1555 };
1556
1557 static const unsigned int dell_m6_pin_configs[13] = {
1558         0x0321101f, 0x4f00000f, 0x4f0000f0, 0x90170110,
1559         0x03a11020, 0x0321101f, 0x4f0000f0, 0x4f0000f0,
1560         0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1561         0x4f0000f0,
1562 };
1563
1564 static const unsigned int alienware_m17x_pin_configs[13] = {
1565         0x0321101f, 0x0321101f, 0x03a11020, 0x03014020,
1566         0x90170110, 0x4f0000f0, 0x4f0000f0, 0x4f0000f0,
1567         0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1568         0x904601b0,
1569 };
1570
1571 static const unsigned int intel_dg45id_pin_configs[13] = {
1572         0x02214230, 0x02A19240, 0x01013214, 0x01014210,
1573         0x01A19250, 0x01011212, 0x01016211
1574 };
1575
1576 static const unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = {
1577         [STAC_92HD73XX_REF]     = ref92hd73xx_pin_configs,
1578         [STAC_DELL_M6_AMIC]     = dell_m6_pin_configs,
1579         [STAC_DELL_M6_DMIC]     = dell_m6_pin_configs,
1580         [STAC_DELL_M6_BOTH]     = dell_m6_pin_configs,
1581         [STAC_DELL_EQ]  = dell_m6_pin_configs,
1582         [STAC_ALIENWARE_M17X]   = alienware_m17x_pin_configs,
1583         [STAC_92HD73XX_INTEL]   = intel_dg45id_pin_configs,
1584 };
1585
1586 static const char * const stac92hd73xx_models[STAC_92HD73XX_MODELS] = {
1587         [STAC_92HD73XX_AUTO] = "auto",
1588         [STAC_92HD73XX_NO_JD] = "no-jd",
1589         [STAC_92HD73XX_REF] = "ref",
1590         [STAC_92HD73XX_INTEL] = "intel",
1591         [STAC_DELL_M6_AMIC] = "dell-m6-amic",
1592         [STAC_DELL_M6_DMIC] = "dell-m6-dmic",
1593         [STAC_DELL_M6_BOTH] = "dell-m6",
1594         [STAC_DELL_EQ] = "dell-eq",
1595         [STAC_ALIENWARE_M17X] = "alienware",
1596 };
1597
1598 static const struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
1599         /* SigmaTel reference board */
1600         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1601                                 "DFI LanParty", STAC_92HD73XX_REF),
1602         SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1603                                 "DFI LanParty", STAC_92HD73XX_REF),
1604         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5002,
1605                                 "Intel DG45ID", STAC_92HD73XX_INTEL),
1606         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5003,
1607                                 "Intel DG45FC", STAC_92HD73XX_INTEL),
1608         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0254,
1609                                 "Dell Studio 1535", STAC_DELL_M6_DMIC),
1610         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0255,
1611                                 "unknown Dell", STAC_DELL_M6_DMIC),
1612         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0256,
1613                                 "unknown Dell", STAC_DELL_M6_BOTH),
1614         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0257,
1615                                 "unknown Dell", STAC_DELL_M6_BOTH),
1616         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025e,
1617                                 "unknown Dell", STAC_DELL_M6_AMIC),
1618         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025f,
1619                                 "unknown Dell", STAC_DELL_M6_AMIC),
1620         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0271,
1621                                 "unknown Dell", STAC_DELL_M6_DMIC),
1622         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0272,
1623                                 "unknown Dell", STAC_DELL_M6_DMIC),
1624         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x029f,
1625                                 "Dell Studio 1537", STAC_DELL_M6_DMIC),
1626         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a0,
1627                                 "Dell Studio 17", STAC_DELL_M6_DMIC),
1628         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02be,
1629                                 "Dell Studio 1555", STAC_DELL_M6_DMIC),
1630         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02bd,
1631                                 "Dell Studio 1557", STAC_DELL_M6_DMIC),
1632         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02fe,
1633                                 "Dell Studio XPS 1645", STAC_DELL_M6_BOTH),
1634         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0413,
1635                                 "Dell Studio 1558", STAC_DELL_M6_DMIC),
1636         {} /* terminator */
1637 };
1638
1639 static const struct snd_pci_quirk stac92hd73xx_codec_id_cfg_tbl[] = {
1640         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a1,
1641                       "Alienware M17x", STAC_ALIENWARE_M17X),
1642         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x043a,
1643                       "Alienware M17x", STAC_ALIENWARE_M17X),
1644         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0490,
1645                       "Alienware M17x", STAC_ALIENWARE_M17X),
1646         {} /* terminator */
1647 };
1648
1649 static const unsigned int ref92hd83xxx_pin_configs[10] = {
1650         0x02214030, 0x02211010, 0x02a19020, 0x02170130,
1651         0x01014050, 0x01819040, 0x01014020, 0x90a3014e,
1652         0x01451160, 0x98560170,
1653 };
1654
1655 static const unsigned int dell_s14_pin_configs[10] = {
1656         0x0221403f, 0x0221101f, 0x02a19020, 0x90170110,
1657         0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a60160,
1658         0x40f000f0, 0x40f000f0,
1659 };
1660
1661 static const unsigned int dell_vostro_3500_pin_configs[10] = {
1662         0x02a11020, 0x0221101f, 0x400000f0, 0x90170110,
1663         0x400000f1, 0x400000f2, 0x400000f3, 0x90a60160,
1664         0x400000f4, 0x400000f5,
1665 };
1666
1667 static const unsigned int hp_dv7_4000_pin_configs[10] = {
1668         0x03a12050, 0x0321201f, 0x40f000f0, 0x90170110,
1669         0x40f000f0, 0x40f000f0, 0x90170110, 0xd5a30140,
1670         0x40f000f0, 0x40f000f0,
1671 };
1672
1673 static const unsigned int hp_cNB11_intquad_pin_configs[10] = {
1674         0x40f000f0, 0x0221101f, 0x02a11020, 0x92170110,
1675         0x40f000f0, 0x92170110, 0x40f000f0, 0xd5a30130,
1676         0x40f000f0, 0x40f000f0,
1677 };
1678
1679 static const unsigned int *stac92hd83xxx_brd_tbl[STAC_92HD83XXX_MODELS] = {
1680         [STAC_92HD83XXX_REF] = ref92hd83xxx_pin_configs,
1681         [STAC_92HD83XXX_PWR_REF] = ref92hd83xxx_pin_configs,
1682         [STAC_DELL_S14] = dell_s14_pin_configs,
1683         [STAC_DELL_VOSTRO_3500] = dell_vostro_3500_pin_configs,
1684         [STAC_92HD83XXX_HP_cNB11_INTQUAD] = hp_cNB11_intquad_pin_configs,
1685         [STAC_HP_DV7_4000] = hp_dv7_4000_pin_configs,
1686 };
1687
1688 static const char * const stac92hd83xxx_models[STAC_92HD83XXX_MODELS] = {
1689         [STAC_92HD83XXX_AUTO] = "auto",
1690         [STAC_92HD83XXX_REF] = "ref",
1691         [STAC_92HD83XXX_PWR_REF] = "mic-ref",
1692         [STAC_DELL_S14] = "dell-s14",
1693         [STAC_DELL_VOSTRO_3500] = "dell-vostro-3500",
1694         [STAC_92HD83XXX_HP_cNB11_INTQUAD] = "hp_cNB11_intquad",
1695         [STAC_HP_DV7_4000] = "hp-dv7-4000",
1696 };
1697
1698 static const struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = {
1699         /* SigmaTel reference board */
1700         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1701                       "DFI LanParty", STAC_92HD83XXX_REF),
1702         SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1703                       "DFI LanParty", STAC_92HD83XXX_REF),
1704         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ba,
1705                       "unknown Dell", STAC_DELL_S14),
1706         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x1028,
1707                       "Dell Vostro 3500", STAC_DELL_VOSTRO_3500),
1708         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1656,
1709                           "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1710         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1657,
1711                           "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1712         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1658,
1713                           "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1714         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1659,
1715                           "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1716         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x165A,
1717                           "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1718         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x165B,
1719                           "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1720         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3388,
1721                           "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1722         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3389,
1723                           "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1724         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355B,
1725                           "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1726         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355C,
1727                           "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1728         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355D,
1729                           "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1730         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355E,
1731                           "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1732         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355F,
1733                           "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1734         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3560,
1735                           "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1736         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x358B,
1737                           "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1738         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x358C,
1739                           "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1740         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x358D,
1741                           "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1742         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3591,
1743                           "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1744         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3592,
1745                           "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1746         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3593,
1747                           "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1748         {} /* terminator */
1749 };
1750
1751 static const unsigned int ref92hd71bxx_pin_configs[STAC92HD71BXX_NUM_PINS] = {
1752         0x02214030, 0x02a19040, 0x01a19020, 0x01014010,
1753         0x0181302e, 0x01014010, 0x01019020, 0x90a000f0,
1754         0x90a000f0, 0x01452050, 0x01452050, 0x00000000,
1755         0x00000000
1756 };
1757
1758 static const unsigned int dell_m4_1_pin_configs[STAC92HD71BXX_NUM_PINS] = {
1759         0x0421101f, 0x04a11221, 0x40f000f0, 0x90170110,
1760         0x23a1902e, 0x23014250, 0x40f000f0, 0x90a000f0,
1761         0x40f000f0, 0x4f0000f0, 0x4f0000f0, 0x00000000,
1762         0x00000000
1763 };
1764
1765 static const unsigned int dell_m4_2_pin_configs[STAC92HD71BXX_NUM_PINS] = {
1766         0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1767         0x23a1902e, 0x23014250, 0x40f000f0, 0x40f000f0,
1768         0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1769         0x00000000
1770 };
1771
1772 static const unsigned int dell_m4_3_pin_configs[STAC92HD71BXX_NUM_PINS] = {
1773         0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1774         0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a000f0,
1775         0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1776         0x00000000
1777 };
1778
1779 static const unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
1780         [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs,
1781         [STAC_DELL_M4_1]        = dell_m4_1_pin_configs,
1782         [STAC_DELL_M4_2]        = dell_m4_2_pin_configs,
1783         [STAC_DELL_M4_3]        = dell_m4_3_pin_configs,
1784         [STAC_HP_M4]            = NULL,
1785         [STAC_HP_DV4]           = NULL,
1786         [STAC_HP_DV5]           = NULL,
1787         [STAC_HP_HDX]           = NULL,
1788         [STAC_HP_DV4_1222NR]    = NULL,
1789 };
1790
1791 static const char * const stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
1792         [STAC_92HD71BXX_AUTO] = "auto",
1793         [STAC_92HD71BXX_REF] = "ref",
1794         [STAC_DELL_M4_1] = "dell-m4-1",
1795         [STAC_DELL_M4_2] = "dell-m4-2",
1796         [STAC_DELL_M4_3] = "dell-m4-3",
1797         [STAC_HP_M4] = "hp-m4",
1798         [STAC_HP_DV4] = "hp-dv4",
1799         [STAC_HP_DV5] = "hp-dv5",
1800         [STAC_HP_HDX] = "hp-hdx",
1801         [STAC_HP_DV4_1222NR] = "hp-dv4-1222nr",
1802 };
1803
1804 static const struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
1805         /* SigmaTel reference board */
1806         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1807                       "DFI LanParty", STAC_92HD71BXX_REF),
1808         SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1809                       "DFI LanParty", STAC_92HD71BXX_REF),
1810         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30fb,
1811                       "HP dv4-1222nr", STAC_HP_DV4_1222NR),
1812         SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x1720,
1813                           "HP", STAC_HP_DV5),
1814         SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3080,
1815                       "HP", STAC_HP_DV5),
1816         SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x30f0,
1817                       "HP dv4-7", STAC_HP_DV4),
1818         SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3600,
1819                       "HP dv4-7", STAC_HP_DV5),
1820         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3610,
1821                       "HP HDX", STAC_HP_HDX),  /* HDX18 */
1822         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361a,
1823                       "HP mini 1000", STAC_HP_M4),
1824         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361b,
1825                       "HP HDX", STAC_HP_HDX),  /* HDX16 */
1826         SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3620,
1827                       "HP dv6", STAC_HP_DV5),
1828         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3061,
1829                       "HP dv6", STAC_HP_DV5), /* HP dv6-1110ax */
1830         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x363e,
1831                       "HP DV6", STAC_HP_DV5),
1832         SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x7010,
1833                       "HP", STAC_HP_DV5),
1834         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
1835                                 "unknown Dell", STAC_DELL_M4_1),
1836         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234,
1837                                 "unknown Dell", STAC_DELL_M4_1),
1838         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0250,
1839                                 "unknown Dell", STAC_DELL_M4_1),
1840         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024f,
1841                                 "unknown Dell", STAC_DELL_M4_1),
1842         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024d,
1843                                 "unknown Dell", STAC_DELL_M4_1),
1844         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0251,
1845                                 "unknown Dell", STAC_DELL_M4_1),
1846         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0277,
1847                                 "unknown Dell", STAC_DELL_M4_1),
1848         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0263,
1849                                 "unknown Dell", STAC_DELL_M4_2),
1850         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0265,
1851                                 "unknown Dell", STAC_DELL_M4_2),
1852         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0262,
1853                                 "unknown Dell", STAC_DELL_M4_2),
1854         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0264,
1855                                 "unknown Dell", STAC_DELL_M4_2),
1856         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02aa,
1857                                 "unknown Dell", STAC_DELL_M4_3),
1858         {} /* terminator */
1859 };
1860
1861 static const unsigned int ref922x_pin_configs[10] = {
1862         0x01014010, 0x01016011, 0x01012012, 0x0221401f,
1863         0x01813122, 0x01011014, 0x01441030, 0x01c41030,
1864         0x40000100, 0x40000100,
1865 };
1866
1867 /*
1868     STAC 922X pin configs for
1869     102801A7
1870     102801AB
1871     102801A9
1872     102801D1
1873     102801D2
1874 */
1875 static const unsigned int dell_922x_d81_pin_configs[10] = {
1876         0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1877         0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
1878         0x01813122, 0x400001f2,
1879 };
1880
1881 /*
1882     STAC 922X pin configs for
1883     102801AC
1884     102801D0
1885 */
1886 static const unsigned int dell_922x_d82_pin_configs[10] = {
1887         0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1888         0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
1889         0x01813122, 0x400001f1,
1890 };
1891
1892 /*
1893     STAC 922X pin configs for
1894     102801BF
1895 */
1896 static const unsigned int dell_922x_m81_pin_configs[10] = {
1897         0x0321101f, 0x01112024, 0x01111222, 0x91174220,
1898         0x03a11050, 0x01116221, 0x90a70330, 0x01452340, 
1899         0x40C003f1, 0x405003f0,
1900 };
1901
1902 /*
1903     STAC 9221 A1 pin configs for
1904     102801D7 (Dell XPS M1210)
1905 */
1906 static const unsigned int dell_922x_m82_pin_configs[10] = {
1907         0x02211211, 0x408103ff, 0x02a1123e, 0x90100310, 
1908         0x408003f1, 0x0221121f, 0x03451340, 0x40c003f2, 
1909         0x508003f3, 0x405003f4, 
1910 };
1911
1912 static const unsigned int d945gtp3_pin_configs[10] = {
1913         0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
1914         0x40000100, 0x40000100, 0x40000100, 0x40000100,
1915         0x02a19120, 0x40000100,
1916 };
1917
1918 static const unsigned int d945gtp5_pin_configs[10] = {
1919         0x0221401f, 0x01011012, 0x01813024, 0x01014010,
1920         0x01a19021, 0x01016011, 0x01452130, 0x40000100,
1921         0x02a19320, 0x40000100,
1922 };
1923
1924 static const unsigned int intel_mac_v1_pin_configs[10] = {
1925         0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
1926         0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
1927         0x400000fc, 0x400000fb,
1928 };
1929
1930 static const unsigned int intel_mac_v2_pin_configs[10] = {
1931         0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1932         0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
1933         0x400000fc, 0x400000fb,
1934 };
1935
1936 static const unsigned int intel_mac_v3_pin_configs[10] = {
1937         0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1938         0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
1939         0x400000fc, 0x400000fb,
1940 };
1941
1942 static const unsigned int intel_mac_v4_pin_configs[10] = {
1943         0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1944         0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1945         0x400000fc, 0x400000fb,
1946 };
1947
1948 static const unsigned int intel_mac_v5_pin_configs[10] = {
1949         0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1950         0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1951         0x400000fc, 0x400000fb,
1952 };
1953
1954 static const unsigned int ecs202_pin_configs[10] = {
1955         0x0221401f, 0x02a19020, 0x01a19020, 0x01114010,
1956         0x408000f0, 0x01813022, 0x074510a0, 0x40c400f1,
1957         0x9037012e, 0x40e000f2,
1958 };
1959
1960 static const unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
1961         [STAC_D945_REF] = ref922x_pin_configs,
1962         [STAC_D945GTP3] = d945gtp3_pin_configs,
1963         [STAC_D945GTP5] = d945gtp5_pin_configs,
1964         [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
1965         [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
1966         [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
1967         [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
1968         [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
1969         [STAC_INTEL_MAC_AUTO] = intel_mac_v3_pin_configs,
1970         /* for backward compatibility */
1971         [STAC_MACMINI] = intel_mac_v3_pin_configs,
1972         [STAC_MACBOOK] = intel_mac_v5_pin_configs,
1973         [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
1974         [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
1975         [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
1976         [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
1977         [STAC_ECS_202] = ecs202_pin_configs,
1978         [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
1979         [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,       
1980         [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
1981         [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,       
1982 };
1983
1984 static const char * const stac922x_models[STAC_922X_MODELS] = {
1985         [STAC_922X_AUTO] = "auto",
1986         [STAC_D945_REF] = "ref",
1987         [STAC_D945GTP5] = "5stack",
1988         [STAC_D945GTP3] = "3stack",
1989         [STAC_INTEL_MAC_V1] = "intel-mac-v1",
1990         [STAC_INTEL_MAC_V2] = "intel-mac-v2",
1991         [STAC_INTEL_MAC_V3] = "intel-mac-v3",
1992         [STAC_INTEL_MAC_V4] = "intel-mac-v4",
1993         [STAC_INTEL_MAC_V5] = "intel-mac-v5",
1994         [STAC_INTEL_MAC_AUTO] = "intel-mac-auto",
1995         /* for backward compatibility */
1996         [STAC_MACMINI]  = "macmini",
1997         [STAC_MACBOOK]  = "macbook",
1998         [STAC_MACBOOK_PRO_V1]   = "macbook-pro-v1",
1999         [STAC_MACBOOK_PRO_V2]   = "macbook-pro",
2000         [STAC_IMAC_INTEL] = "imac-intel",
2001         [STAC_IMAC_INTEL_20] = "imac-intel-20",
2002         [STAC_ECS_202] = "ecs202",
2003         [STAC_922X_DELL_D81] = "dell-d81",
2004         [STAC_922X_DELL_D82] = "dell-d82",
2005         [STAC_922X_DELL_M81] = "dell-m81",
2006         [STAC_922X_DELL_M82] = "dell-m82",
2007 };
2008
2009 static const struct snd_pci_quirk stac922x_cfg_tbl[] = {
2010         /* SigmaTel reference board */
2011         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2012                       "DFI LanParty", STAC_D945_REF),
2013         SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2014                       "DFI LanParty", STAC_D945_REF),
2015         /* Intel 945G based systems */
2016         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
2017                       "Intel D945G", STAC_D945GTP3),
2018         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
2019                       "Intel D945G", STAC_D945GTP3),
2020         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
2021                       "Intel D945G", STAC_D945GTP3),
2022         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
2023                       "Intel D945G", STAC_D945GTP3),
2024         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
2025                       "Intel D945G", STAC_D945GTP3),
2026         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
2027                       "Intel D945G", STAC_D945GTP3),
2028         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
2029                       "Intel D945G", STAC_D945GTP3),
2030         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
2031                       "Intel D945G", STAC_D945GTP3),
2032         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
2033                       "Intel D945G", STAC_D945GTP3),
2034         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
2035                       "Intel D945G", STAC_D945GTP3),
2036         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
2037                       "Intel D945G", STAC_D945GTP3),
2038         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
2039                       "Intel D945G", STAC_D945GTP3),
2040         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
2041                       "Intel D945G", STAC_D945GTP3),
2042         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
2043                       "Intel D945G", STAC_D945GTP3),
2044         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
2045                       "Intel D945G", STAC_D945GTP3),
2046         /* Intel D945G 5-stack systems */
2047         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
2048                       "Intel D945G", STAC_D945GTP5),
2049         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
2050                       "Intel D945G", STAC_D945GTP5),
2051         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
2052                       "Intel D945G", STAC_D945GTP5),
2053         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
2054                       "Intel D945G", STAC_D945GTP5),
2055         /* Intel 945P based systems */
2056         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
2057                       "Intel D945P", STAC_D945GTP3),
2058         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
2059                       "Intel D945P", STAC_D945GTP3),
2060         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
2061                       "Intel D945P", STAC_D945GTP3),
2062         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
2063                       "Intel D945P", STAC_D945GTP3),
2064         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
2065                       "Intel D945P", STAC_D945GTP3),
2066         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
2067                       "Intel D945P", STAC_D945GTP5),
2068         /* other intel */
2069         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0204,
2070                       "Intel D945", STAC_D945_REF),
2071         /* other systems  */
2072         /* Apple Intel Mac (Mac Mini, MacBook, MacBook Pro...) */
2073         SND_PCI_QUIRK(0x8384, 0x7680,
2074                       "Mac", STAC_INTEL_MAC_AUTO),
2075         /* Dell systems  */
2076         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
2077                       "unknown Dell", STAC_922X_DELL_D81),
2078         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
2079                       "unknown Dell", STAC_922X_DELL_D81),
2080         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
2081                       "unknown Dell", STAC_922X_DELL_D81),
2082         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
2083                       "unknown Dell", STAC_922X_DELL_D82),
2084         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
2085                       "unknown Dell", STAC_922X_DELL_M81),
2086         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
2087                       "unknown Dell", STAC_922X_DELL_D82),
2088         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
2089                       "unknown Dell", STAC_922X_DELL_D81),
2090         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
2091                       "unknown Dell", STAC_922X_DELL_D81),
2092         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
2093                       "Dell XPS M1210", STAC_922X_DELL_M82),
2094         /* ECS/PC Chips boards */
2095         SND_PCI_QUIRK_MASK(0x1019, 0xf000, 0x2000,
2096                       "ECS/PC chips", STAC_ECS_202),
2097         {} /* terminator */
2098 };
2099
2100 static const unsigned int ref927x_pin_configs[14] = {
2101         0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2102         0x01a19040, 0x01011012, 0x01016011, 0x0101201f, 
2103         0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
2104         0x01c42190, 0x40000100,
2105 };
2106
2107 static const unsigned int d965_3st_pin_configs[14] = {
2108         0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
2109         0x01a19021, 0x01813024, 0x40000100, 0x40000100,
2110         0x40000100, 0x40000100, 0x40000100, 0x40000100,
2111         0x40000100, 0x40000100
2112 };
2113
2114 static const unsigned int d965_5st_pin_configs[14] = {
2115         0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2116         0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2117         0x40000100, 0x40000100, 0x40000100, 0x01442070,
2118         0x40000100, 0x40000100
2119 };
2120
2121 static const unsigned int d965_5st_no_fp_pin_configs[14] = {
2122         0x40000100, 0x40000100, 0x0181304e, 0x01014010,
2123         0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2124         0x40000100, 0x40000100, 0x40000100, 0x01442070,
2125         0x40000100, 0x40000100
2126 };
2127
2128 static const unsigned int dell_3st_pin_configs[14] = {
2129         0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
2130         0x01111212, 0x01116211, 0x01813050, 0x01112214,
2131         0x403003fa, 0x90a60040, 0x90a60040, 0x404003fb,
2132         0x40c003fc, 0x40000100
2133 };
2134
2135 static const unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
2136         [STAC_D965_REF_NO_JD] = ref927x_pin_configs,
2137         [STAC_D965_REF]  = ref927x_pin_configs,
2138         [STAC_D965_3ST]  = d965_3st_pin_configs,
2139         [STAC_D965_5ST]  = d965_5st_pin_configs,
2140         [STAC_D965_5ST_NO_FP]  = d965_5st_no_fp_pin_configs,
2141         [STAC_DELL_3ST]  = dell_3st_pin_configs,
2142         [STAC_DELL_BIOS] = NULL,
2143         [STAC_927X_VOLKNOB] = NULL,
2144 };
2145
2146 static const char * const stac927x_models[STAC_927X_MODELS] = {
2147         [STAC_927X_AUTO]        = "auto",
2148         [STAC_D965_REF_NO_JD]   = "ref-no-jd",
2149         [STAC_D965_REF]         = "ref",
2150         [STAC_D965_3ST]         = "3stack",
2151         [STAC_D965_5ST]         = "5stack",
2152         [STAC_D965_5ST_NO_FP]   = "5stack-no-fp",
2153         [STAC_DELL_3ST]         = "dell-3stack",
2154         [STAC_DELL_BIOS]        = "dell-bios",
2155         [STAC_927X_VOLKNOB]     = "volknob",
2156 };
2157
2158 static const struct snd_pci_quirk stac927x_cfg_tbl[] = {
2159         /* SigmaTel reference board */
2160         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2161                       "DFI LanParty", STAC_D965_REF),
2162         SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2163                       "DFI LanParty", STAC_D965_REF),
2164          /* Intel 946 based systems */
2165         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
2166         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
2167         /* 965 based 3 stack systems */
2168         SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2100,
2169                            "Intel D965", STAC_D965_3ST),
2170         SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2000,
2171                            "Intel D965", STAC_D965_3ST),
2172         /* Dell 3 stack systems */
2173         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
2174         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x01ed, "Dell     ", STAC_DELL_3ST),
2175         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x01f4, "Dell     ", STAC_DELL_3ST),
2176         /* Dell 3 stack systems with verb table in BIOS */
2177         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x01f3, "Dell Inspiron 1420", STAC_DELL_BIOS),
2178         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x01f7, "Dell XPS M1730", STAC_DELL_BIOS),
2179         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x0227, "Dell Vostro 1400  ", STAC_DELL_BIOS),
2180         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x022e, "Dell     ", STAC_DELL_BIOS),
2181         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x022f, "Dell Inspiron 1525", STAC_DELL_BIOS),
2182         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x0242, "Dell     ", STAC_DELL_BIOS),
2183         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x0243, "Dell     ", STAC_DELL_BIOS),
2184         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x02ff, "Dell     ", STAC_DELL_BIOS),
2185         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x0209, "Dell XPS 1330", STAC_DELL_BIOS),
2186         /* 965 based 5 stack systems */
2187         SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2300,
2188                            "Intel D965", STAC_D965_5ST),
2189         SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2500,
2190                            "Intel D965", STAC_D965_5ST),
2191         /* volume-knob fixes */
2192         SND_PCI_QUIRK_VENDOR(0x10cf, "FSC", STAC_927X_VOLKNOB),
2193         {} /* terminator */
2194 };
2195
2196 static const unsigned int ref9205_pin_configs[12] = {
2197         0x40000100, 0x40000100, 0x01016011, 0x01014010,
2198         0x01813122, 0x01a19021, 0x01019020, 0x40000100,
2199         0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
2200 };
2201
2202 /*
2203     STAC 9205 pin configs for
2204     102801F1
2205     102801F2
2206     102801FC
2207     102801FD
2208     10280204
2209     1028021F
2210     10280228 (Dell Vostro 1500)
2211     10280229 (Dell Vostro 1700)
2212 */
2213 static const unsigned int dell_9205_m42_pin_configs[12] = {
2214         0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
2215         0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
2216         0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
2217 };
2218
2219 /*
2220     STAC 9205 pin configs for
2221     102801F9
2222     102801FA
2223     102801FE
2224     102801FF (Dell Precision M4300)
2225     10280206
2226     10280200
2227     10280201
2228 */
2229 static const unsigned int dell_9205_m43_pin_configs[12] = {
2230         0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
2231         0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
2232         0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
2233 };
2234
2235 static const unsigned int dell_9205_m44_pin_configs[12] = {
2236         0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
2237         0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
2238         0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
2239 };
2240
2241 static const unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
2242         [STAC_9205_REF] = ref9205_pin_configs,
2243         [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
2244         [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
2245         [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
2246         [STAC_9205_EAPD] = NULL,
2247 };
2248
2249 static const char * const stac9205_models[STAC_9205_MODELS] = {
2250         [STAC_9205_AUTO] = "auto",
2251         [STAC_9205_REF] = "ref",
2252         [STAC_9205_DELL_M42] = "dell-m42",
2253         [STAC_9205_DELL_M43] = "dell-m43",
2254         [STAC_9205_DELL_M44] = "dell-m44",
2255         [STAC_9205_EAPD] = "eapd",
2256 };
2257
2258 static const struct snd_pci_quirk stac9205_cfg_tbl[] = {
2259         /* SigmaTel reference board */
2260         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2261                       "DFI LanParty", STAC_9205_REF),
2262         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xfb30,
2263                       "SigmaTel", STAC_9205_REF),
2264         SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2265                       "DFI LanParty", STAC_9205_REF),
2266         /* Dell */
2267         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
2268                       "unknown Dell", STAC_9205_DELL_M42),
2269         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
2270                       "unknown Dell", STAC_9205_DELL_M42),
2271         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
2272                       "Dell Precision", STAC_9205_DELL_M43),
2273         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
2274                       "Dell Precision", STAC_9205_DELL_M43),
2275         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
2276                       "Dell Precision", STAC_9205_DELL_M43),
2277         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
2278                       "unknown Dell", STAC_9205_DELL_M42),
2279         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
2280                       "unknown Dell", STAC_9205_DELL_M42),
2281         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
2282                       "Dell Precision", STAC_9205_DELL_M43),
2283         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
2284                       "Dell Precision M4300", STAC_9205_DELL_M43),
2285         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
2286                       "unknown Dell", STAC_9205_DELL_M42),
2287         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
2288                       "Dell Precision", STAC_9205_DELL_M43),
2289         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
2290                       "Dell Precision", STAC_9205_DELL_M43),
2291         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
2292                       "Dell Precision", STAC_9205_DELL_M43),
2293         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
2294                       "Dell Inspiron", STAC_9205_DELL_M44),
2295         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0228,
2296                       "Dell Vostro 1500", STAC_9205_DELL_M42),
2297         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0229,
2298                       "Dell Vostro 1700", STAC_9205_DELL_M42),
2299         /* Gateway */
2300         SND_PCI_QUIRK(0x107b, 0x0560, "Gateway T6834c", STAC_9205_EAPD),
2301         SND_PCI_QUIRK(0x107b, 0x0565, "Gateway T1616", STAC_9205_EAPD),
2302         {} /* terminator */
2303 };
2304
2305 static void stac92xx_set_config_regs(struct hda_codec *codec,
2306                                      const unsigned int *pincfgs)
2307 {
2308         int i;
2309         struct sigmatel_spec *spec = codec->spec;
2310
2311         if (!pincfgs)
2312                 return;
2313
2314         for (i = 0; i < spec->num_pins; i++)
2315                 if (spec->pin_nids[i] && pincfgs[i])
2316                         snd_hda_codec_set_pincfg(codec, spec->pin_nids[i],
2317                                                  pincfgs[i]);
2318 }
2319
2320 /*
2321  * Analog playback callbacks
2322  */
2323 static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
2324                                       struct hda_codec *codec,
2325                                       struct snd_pcm_substream *substream)
2326 {
2327         struct sigmatel_spec *spec = codec->spec;
2328         if (spec->stream_delay)
2329                 msleep(spec->stream_delay);
2330         return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2331                                              hinfo);
2332 }
2333
2334 static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2335                                          struct hda_codec *codec,
2336                                          unsigned int stream_tag,
2337                                          unsigned int format,
2338                                          struct snd_pcm_substream *substream)
2339 {
2340         struct sigmatel_spec *spec = codec->spec;
2341         return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
2342 }
2343
2344 static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2345                                         struct hda_codec *codec,
2346                                         struct snd_pcm_substream *substream)
2347 {
2348         struct sigmatel_spec *spec = codec->spec;
2349         return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2350 }
2351
2352 /*
2353  * Digital playback callbacks
2354  */
2355 static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2356                                           struct hda_codec *codec,
2357                                           struct snd_pcm_substream *substream)
2358 {
2359         struct sigmatel_spec *spec = codec->spec;
2360         return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2361 }
2362
2363 static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2364                                            struct hda_codec *codec,
2365                                            struct snd_pcm_substream *substream)
2366 {
2367         struct sigmatel_spec *spec = codec->spec;
2368         return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2369 }
2370
2371 static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2372                                          struct hda_codec *codec,
2373                                          unsigned int stream_tag,
2374                                          unsigned int format,
2375                                          struct snd_pcm_substream *substream)
2376 {
2377         struct sigmatel_spec *spec = codec->spec;
2378         return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2379                                              stream_tag, format, substream);
2380 }
2381
2382 static int stac92xx_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2383                                         struct hda_codec *codec,
2384                                         struct snd_pcm_substream *substream)
2385 {
2386         struct sigmatel_spec *spec = codec->spec;
2387         return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2388 }
2389
2390
2391 /*
2392  * Analog capture callbacks
2393  */
2394 static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2395                                         struct hda_codec *codec,
2396                                         unsigned int stream_tag,
2397                                         unsigned int format,
2398                                         struct snd_pcm_substream *substream)
2399 {
2400         struct sigmatel_spec *spec = codec->spec;
2401         hda_nid_t nid = spec->adc_nids[substream->number];
2402
2403         if (spec->powerdown_adcs) {
2404                 msleep(40);
2405                 snd_hda_codec_write(codec, nid, 0,
2406                         AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
2407         }
2408         snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
2409         return 0;
2410 }
2411
2412 static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2413                                         struct hda_codec *codec,
2414                                         struct snd_pcm_substream *substream)
2415 {
2416         struct sigmatel_spec *spec = codec->spec;
2417         hda_nid_t nid = spec->adc_nids[substream->number];
2418
2419         snd_hda_codec_cleanup_stream(codec, nid);
2420         if (spec->powerdown_adcs)
2421                 snd_hda_codec_write(codec, nid, 0,
2422                         AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
2423         return 0;
2424 }
2425
2426 static const struct hda_pcm_stream stac92xx_pcm_digital_playback = {
2427         .substreams = 1,
2428         .channels_min = 2,
2429         .channels_max = 2,
2430         /* NID is set in stac92xx_build_pcms */
2431         .ops = {
2432                 .open = stac92xx_dig_playback_pcm_open,
2433                 .close = stac92xx_dig_playback_pcm_close,
2434                 .prepare = stac92xx_dig_playback_pcm_prepare,
2435                 .cleanup = stac92xx_dig_playback_pcm_cleanup
2436         },
2437 };
2438
2439 static const struct hda_pcm_stream stac92xx_pcm_digital_capture = {
2440         .substreams = 1,
2441         .channels_min = 2,
2442         .channels_max = 2,
2443         /* NID is set in stac92xx_build_pcms */
2444 };
2445
2446 static const struct hda_pcm_stream stac92xx_pcm_analog_playback = {
2447         .substreams = 1,
2448         .channels_min = 2,
2449         .channels_max = 8,
2450         .nid = 0x02, /* NID to query formats and rates */
2451         .ops = {
2452                 .open = stac92xx_playback_pcm_open,
2453                 .prepare = stac92xx_playback_pcm_prepare,
2454                 .cleanup = stac92xx_playback_pcm_cleanup
2455         },
2456 };
2457
2458 static const struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
2459         .substreams = 1,
2460         .channels_min = 2,
2461         .channels_max = 2,
2462         .nid = 0x06, /* NID to query formats and rates */
2463         .ops = {
2464                 .open = stac92xx_playback_pcm_open,
2465                 .prepare = stac92xx_playback_pcm_prepare,
2466                 .cleanup = stac92xx_playback_pcm_cleanup
2467         },
2468 };
2469
2470 static const struct hda_pcm_stream stac92xx_pcm_analog_capture = {
2471         .channels_min = 2,
2472         .channels_max = 2,
2473         /* NID + .substreams is set in stac92xx_build_pcms */
2474         .ops = {
2475                 .prepare = stac92xx_capture_pcm_prepare,
2476                 .cleanup = stac92xx_capture_pcm_cleanup
2477         },
2478 };
2479
2480 static int stac92xx_build_pcms(struct hda_codec *codec)
2481 {
2482         struct sigmatel_spec *spec = codec->spec;
2483         struct hda_pcm *info = spec->pcm_rec;
2484
2485         codec->num_pcms = 1;
2486         codec->pcm_info = info;
2487
2488         info->name = "STAC92xx Analog";
2489         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
2490         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2491                 spec->multiout.dac_nids[0];
2492         info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
2493         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2494         info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
2495
2496         if (spec->alt_switch) {
2497                 codec->num_pcms++;
2498                 info++;
2499                 info->name = "STAC92xx Analog Alt";
2500                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
2501         }
2502
2503         if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2504                 codec->num_pcms++;
2505                 info++;
2506                 info->name = "STAC92xx Digital";
2507                 info->pcm_type = spec->autocfg.dig_out_type[0];
2508                 if (spec->multiout.dig_out_nid) {
2509                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
2510                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2511                 }
2512                 if (spec->dig_in_nid) {
2513                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
2514                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2515                 }
2516         }
2517
2518         return 0;
2519 }
2520
2521 static unsigned int stac92xx_get_default_vref(struct hda_codec *codec,
2522                                         hda_nid_t nid)
2523 {
2524         unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2525         pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
2526         if (pincap & AC_PINCAP_VREF_100)
2527                 return AC_PINCTL_VREF_100;
2528         if (pincap & AC_PINCAP_VREF_80)
2529                 return AC_PINCTL_VREF_80;
2530         if (pincap & AC_PINCAP_VREF_50)
2531                 return AC_PINCTL_VREF_50;
2532         if (pincap & AC_PINCAP_VREF_GRD)
2533                 return AC_PINCTL_VREF_GRD;
2534         return 0;
2535 }
2536
2537 static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
2538
2539 {
2540         snd_hda_codec_write_cache(codec, nid, 0,
2541                                   AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
2542 }
2543
2544 #define stac92xx_hp_switch_info         snd_ctl_boolean_mono_info
2545
2546 static int stac92xx_hp_switch_get(struct snd_kcontrol *kcontrol,
2547                         struct snd_ctl_elem_value *ucontrol)
2548 {
2549         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2550         struct sigmatel_spec *spec = codec->spec;
2551
2552         ucontrol->value.integer.value[0] = !!spec->hp_switch;
2553         return 0;
2554 }
2555
2556 static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid);
2557
2558 static int stac92xx_hp_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         int nid = kcontrol->private_value;
2564  
2565         spec->hp_switch = ucontrol->value.integer.value[0] ? nid : 0;
2566
2567         /* check to be sure that the ports are up to date with
2568          * switch changes
2569          */
2570         stac_issue_unsol_event(codec, nid);
2571
2572         return 1;
2573 }
2574
2575 static int stac92xx_dc_bias_info(struct snd_kcontrol *kcontrol,
2576                                 struct snd_ctl_elem_info *uinfo)
2577 {
2578         int i;
2579         static const char * const texts[] = {
2580                 "Mic In", "Line In", "Line Out"
2581         };
2582
2583         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2584         struct sigmatel_spec *spec = codec->spec;
2585         hda_nid_t nid = kcontrol->private_value;
2586
2587         if (nid == spec->mic_switch || nid == spec->line_switch)
2588                 i = 3;
2589         else
2590                 i = 2;
2591
2592         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2593         uinfo->value.enumerated.items = i;
2594         uinfo->count = 1;
2595         if (uinfo->value.enumerated.item >= i)
2596                 uinfo->value.enumerated.item = i-1;
2597         strcpy(uinfo->value.enumerated.name,
2598                 texts[uinfo->value.enumerated.item]);
2599
2600         return 0;
2601 }
2602
2603 static int stac92xx_dc_bias_get(struct snd_kcontrol *kcontrol,
2604                                 struct snd_ctl_elem_value *ucontrol)
2605 {
2606         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2607         hda_nid_t nid = kcontrol->private_value;
2608         unsigned int vref = stac92xx_vref_get(codec, nid);
2609
2610         if (vref == stac92xx_get_default_vref(codec, nid))
2611                 ucontrol->value.enumerated.item[0] = 0;
2612         else if (vref == AC_PINCTL_VREF_GRD)
2613                 ucontrol->value.enumerated.item[0] = 1;
2614         else if (vref == AC_PINCTL_VREF_HIZ)
2615                 ucontrol->value.enumerated.item[0] = 2;
2616
2617         return 0;
2618 }
2619
2620 static int stac92xx_dc_bias_put(struct snd_kcontrol *kcontrol,
2621                                 struct snd_ctl_elem_value *ucontrol)
2622 {
2623         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2624         unsigned int new_vref = 0;
2625         int error;
2626         hda_nid_t nid = kcontrol->private_value;
2627
2628         if (ucontrol->value.enumerated.item[0] == 0)
2629                 new_vref = stac92xx_get_default_vref(codec, nid);
2630         else if (ucontrol->value.enumerated.item[0] == 1)
2631                 new_vref = AC_PINCTL_VREF_GRD;
2632         else if (ucontrol->value.enumerated.item[0] == 2)
2633                 new_vref = AC_PINCTL_VREF_HIZ;
2634         else
2635                 return 0;
2636
2637         if (new_vref != stac92xx_vref_get(codec, nid)) {
2638                 error = stac92xx_vref_set(codec, nid, new_vref);
2639                 return error;
2640         }
2641
2642         return 0;
2643 }
2644
2645 static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol,
2646                                 struct snd_ctl_elem_info *uinfo)
2647 {
2648         char *texts[2];
2649         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2650         struct sigmatel_spec *spec = codec->spec;
2651
2652         if (kcontrol->private_value == spec->line_switch)
2653                 texts[0] = "Line In";
2654         else
2655                 texts[0] = "Mic In";
2656         texts[1] = "Line Out";
2657         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2658         uinfo->value.enumerated.items = 2;
2659         uinfo->count = 1;
2660
2661         if (uinfo->value.enumerated.item >= 2)
2662                 uinfo->value.enumerated.item = 1;
2663         strcpy(uinfo->value.enumerated.name,
2664                 texts[uinfo->value.enumerated.item]);
2665
2666         return 0;
2667 }
2668
2669 static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2670 {
2671         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2672         struct sigmatel_spec *spec = codec->spec;
2673         hda_nid_t nid = kcontrol->private_value;
2674         int io_idx = (nid == spec->mic_switch) ? 1 : 0;
2675
2676         ucontrol->value.enumerated.item[0] = spec->io_switch[io_idx];
2677         return 0;
2678 }
2679
2680 static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2681 {
2682         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2683         struct sigmatel_spec *spec = codec->spec;
2684         hda_nid_t nid = kcontrol->private_value;
2685         int io_idx = (nid == spec->mic_switch) ? 1 : 0;
2686         unsigned short val = !!ucontrol->value.enumerated.item[0];
2687
2688         spec->io_switch[io_idx] = val;
2689
2690         if (val)
2691                 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
2692         else {
2693                 unsigned int pinctl = AC_PINCTL_IN_EN;
2694                 if (io_idx) /* set VREF for mic */
2695                         pinctl |= stac92xx_get_default_vref(codec, nid);
2696                 stac92xx_auto_set_pinctl(codec, nid, pinctl);
2697         }
2698
2699         /* check the auto-mute again: we need to mute/unmute the speaker
2700          * appropriately according to the pin direction
2701          */
2702         if (spec->hp_detect)
2703                 stac_issue_unsol_event(codec, nid);
2704
2705         return 1;
2706 }
2707
2708 #define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
2709
2710 static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
2711                 struct snd_ctl_elem_value *ucontrol)
2712 {
2713         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2714         struct sigmatel_spec *spec = codec->spec;
2715
2716         ucontrol->value.integer.value[0] = spec->clfe_swap;
2717         return 0;
2718 }
2719
2720 static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
2721                 struct snd_ctl_elem_value *ucontrol)
2722 {
2723         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2724         struct sigmatel_spec *spec = codec->spec;
2725         hda_nid_t nid = kcontrol->private_value & 0xff;
2726         unsigned int val = !!ucontrol->value.integer.value[0];
2727
2728         if (spec->clfe_swap == val)
2729                 return 0;
2730
2731         spec->clfe_swap = val;
2732
2733         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
2734                 spec->clfe_swap ? 0x4 : 0x0);
2735
2736         return 1;
2737 }
2738
2739 #define STAC_CODEC_HP_SWITCH(xname) \
2740         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2741           .name = xname, \
2742           .index = 0, \
2743           .info = stac92xx_hp_switch_info, \
2744           .get = stac92xx_hp_switch_get, \
2745           .put = stac92xx_hp_switch_put, \
2746         }
2747
2748 #define STAC_CODEC_IO_SWITCH(xname, xpval) \
2749         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2750           .name = xname, \
2751           .index = 0, \
2752           .info = stac92xx_io_switch_info, \
2753           .get = stac92xx_io_switch_get, \
2754           .put = stac92xx_io_switch_put, \
2755           .private_value = xpval, \
2756         }
2757
2758 #define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
2759         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2760           .name = xname, \
2761           .index = 0, \
2762           .info = stac92xx_clfe_switch_info, \
2763           .get = stac92xx_clfe_switch_get, \
2764           .put = stac92xx_clfe_switch_put, \
2765           .private_value = xpval, \
2766         }
2767
2768 enum {
2769         STAC_CTL_WIDGET_VOL,
2770         STAC_CTL_WIDGET_MUTE,
2771         STAC_CTL_WIDGET_MUTE_BEEP,
2772         STAC_CTL_WIDGET_MONO_MUX,
2773         STAC_CTL_WIDGET_HP_SWITCH,
2774         STAC_CTL_WIDGET_IO_SWITCH,
2775         STAC_CTL_WIDGET_CLFE_SWITCH,
2776         STAC_CTL_WIDGET_DC_BIAS
2777 };
2778
2779 static const struct snd_kcontrol_new stac92xx_control_templates[] = {
2780         HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2781         HDA_CODEC_MUTE(NULL, 0, 0, 0),
2782         HDA_CODEC_MUTE_BEEP(NULL, 0, 0, 0),
2783         STAC_MONO_MUX,
2784         STAC_CODEC_HP_SWITCH(NULL),
2785         STAC_CODEC_IO_SWITCH(NULL, 0),
2786         STAC_CODEC_CLFE_SWITCH(NULL, 0),
2787         DC_BIAS(NULL, 0, 0),
2788 };
2789
2790 /* add dynamic controls */
2791 static struct snd_kcontrol_new *
2792 stac_control_new(struct sigmatel_spec *spec,
2793                  const struct snd_kcontrol_new *ktemp,
2794                  const char *name,
2795                  unsigned int subdev)
2796 {
2797         struct snd_kcontrol_new *knew;
2798
2799         snd_array_init(&spec->kctls, sizeof(*knew), 32);
2800         knew = snd_array_new(&spec->kctls);
2801         if (!knew)
2802                 return NULL;
2803         *knew = *ktemp;
2804         knew->name = kstrdup(name, GFP_KERNEL);
2805         if (!knew->name) {
2806                 /* roolback */
2807                 memset(knew, 0, sizeof(*knew));
2808                 spec->kctls.alloced--;
2809                 return NULL;
2810         }
2811         knew->subdevice = subdev;
2812         return knew;
2813 }
2814
2815 static int stac92xx_add_control_temp(struct sigmatel_spec *spec,
2816                                      const struct snd_kcontrol_new *ktemp,
2817                                      int idx, const char *name,
2818                                      unsigned long val)
2819 {
2820         struct snd_kcontrol_new *knew = stac_control_new(spec, ktemp, name,
2821                                                          HDA_SUBDEV_AMP_FLAG);
2822         if (!knew)
2823                 return -ENOMEM;
2824         knew->index = idx;
2825         knew->private_value = val;
2826         return 0;
2827 }
2828
2829 static inline int stac92xx_add_control_idx(struct sigmatel_spec *spec,
2830                                            int type, int idx, const char *name,
2831                                            unsigned long val)
2832 {
2833         return stac92xx_add_control_temp(spec,
2834                                          &stac92xx_control_templates[type],
2835                                          idx, name, val);
2836 }
2837
2838
2839 /* add dynamic controls */
2840 static inline int stac92xx_add_control(struct sigmatel_spec *spec, int type,
2841                                        const char *name, unsigned long val)
2842 {
2843         return stac92xx_add_control_idx(spec, type, 0, name, val);
2844 }
2845
2846 static const struct snd_kcontrol_new stac_input_src_temp = {
2847         .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2848         .name = "Input Source",
2849         .info = stac92xx_mux_enum_info,
2850         .get = stac92xx_mux_enum_get,
2851         .put = stac92xx_mux_enum_put,
2852 };
2853
2854 static inline int stac92xx_add_jack_mode_control(struct hda_codec *codec,
2855                                                 hda_nid_t nid, int idx)
2856 {
2857         int def_conf = snd_hda_codec_get_pincfg(codec, nid);
2858         int control = 0;
2859         struct sigmatel_spec *spec = codec->spec;
2860         char name[22];
2861
2862         if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT) {
2863                 if (stac92xx_get_default_vref(codec, nid) == AC_PINCTL_VREF_GRD
2864                         && nid == spec->line_switch)
2865                         control = STAC_CTL_WIDGET_IO_SWITCH;
2866                 else if (snd_hda_query_pin_caps(codec, nid)
2867                         & (AC_PINCAP_VREF_GRD << AC_PINCAP_VREF_SHIFT))
2868                         control = STAC_CTL_WIDGET_DC_BIAS;
2869                 else if (nid == spec->mic_switch)
2870                         control = STAC_CTL_WIDGET_IO_SWITCH;
2871         }
2872
2873         if (control) {
2874                 strcpy(name, hda_get_input_pin_label(codec, nid, 1));
2875                 return stac92xx_add_control(codec->spec, control,
2876                                         strcat(name, " Jack Mode"), nid);
2877         }
2878
2879         return 0;
2880 }
2881
2882 static int stac92xx_add_input_source(struct sigmatel_spec *spec)
2883 {
2884         struct snd_kcontrol_new *knew;
2885         struct hda_input_mux *imux = &spec->private_imux;
2886
2887         if (spec->auto_mic)
2888                 return 0; /* no need for input source */
2889         if (!spec->num_adcs || imux->num_items <= 1)
2890                 return 0; /* no need for input source control */
2891         knew = stac_control_new(spec, &stac_input_src_temp,
2892                                 stac_input_src_temp.name, 0);
2893         if (!knew)
2894                 return -ENOMEM;
2895         knew->count = spec->num_adcs;
2896         return 0;
2897 }
2898
2899 /* check whether the line-input can be used as line-out */
2900 static hda_nid_t check_line_out_switch(struct hda_codec *codec)
2901 {
2902         struct sigmatel_spec *spec = codec->spec;
2903         struct auto_pin_cfg *cfg = &spec->autocfg;
2904         hda_nid_t nid;
2905         unsigned int pincap;
2906         int i;
2907
2908         if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2909                 return 0;
2910         for (i = 0; i < cfg->num_inputs; i++) {
2911                 if (cfg->inputs[i].type == AUTO_PIN_LINE_IN) {
2912                         nid = cfg->inputs[i].pin;
2913                         pincap = snd_hda_query_pin_caps(codec, nid);
2914                         if (pincap & AC_PINCAP_OUT)
2915                                 return nid;
2916                 }
2917         }
2918         return 0;
2919 }
2920
2921 static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid);
2922
2923 /* check whether the mic-input can be used as line-out */
2924 static hda_nid_t check_mic_out_switch(struct hda_codec *codec, hda_nid_t *dac)
2925 {
2926         struct sigmatel_spec *spec = codec->spec;
2927         struct auto_pin_cfg *cfg = &spec->autocfg;
2928         unsigned int def_conf, pincap;
2929         int i;
2930
2931         *dac = 0;
2932         if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2933                 return 0;
2934         for (i = 0; i < cfg->num_inputs; i++) {
2935                 hda_nid_t nid = cfg->inputs[i].pin;
2936                 if (cfg->inputs[i].type != AUTO_PIN_MIC)
2937                         continue;
2938                 def_conf = snd_hda_codec_get_pincfg(codec, nid);
2939                 /* some laptops have an internal analog microphone
2940                  * which can't be used as a output */
2941                 if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT) {
2942                         pincap = snd_hda_query_pin_caps(codec, nid);
2943                         if (pincap & AC_PINCAP_OUT) {
2944                                 *dac = get_unassigned_dac(codec, nid);
2945                                 if (*dac)
2946                                         return nid;
2947                         }
2948                 }
2949         }
2950         return 0;
2951 }
2952
2953 static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2954 {
2955         int i;
2956         
2957         for (i = 0; i < spec->multiout.num_dacs; i++) {
2958                 if (spec->multiout.dac_nids[i] == nid)
2959                         return 1;
2960         }
2961
2962         return 0;
2963 }
2964
2965 static int check_all_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2966 {
2967         int i;
2968         if (is_in_dac_nids(spec, nid))
2969                 return 1;
2970         for (i = 0; i < spec->autocfg.hp_outs; i++)
2971                 if (spec->hp_dacs[i] == nid)
2972                         return 1;
2973         for (i = 0; i < spec->autocfg.speaker_outs; i++)
2974                 if (spec->speaker_dacs[i] == nid)
2975                         return 1;
2976         return 0;
2977 }
2978
2979 static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid)
2980 {
2981         struct sigmatel_spec *spec = codec->spec;
2982         struct auto_pin_cfg *cfg = &spec->autocfg;
2983         int j, conn_len;
2984         hda_nid_t conn[HDA_MAX_CONNECTIONS], fallback_dac;
2985         unsigned int wcaps, wtype;
2986
2987         conn_len = snd_hda_get_connections(codec, nid, conn,
2988                                            HDA_MAX_CONNECTIONS);
2989         /* 92HD88: trace back up the link of nids to find the DAC */
2990         while (conn_len == 1 && (get_wcaps_type(get_wcaps(codec, conn[0]))
2991                                         != AC_WID_AUD_OUT)) {
2992                 nid = conn[0];
2993                 conn_len = snd_hda_get_connections(codec, nid, conn,
2994                         HDA_MAX_CONNECTIONS);
2995         }
2996         for (j = 0; j < conn_len; j++) {
2997                 wcaps = get_wcaps(codec, conn[j]);
2998                 wtype = get_wcaps_type(wcaps);
2999                 /* we check only analog outputs */
3000                 if (wtype != AC_WID_AUD_OUT || (wcaps & AC_WCAP_DIGITAL))
3001                         continue;
3002                 /* if this route has a free DAC, assign it */
3003                 if (!check_all_dac_nids(spec, conn[j])) {
3004                         if (conn_len > 1) {
3005                                 /* select this DAC in the pin's input mux */
3006                                 snd_hda_codec_write_cache(codec, nid, 0,
3007                                                   AC_VERB_SET_CONNECT_SEL, j);
3008                         }
3009                         return conn[j];
3010                 }
3011         }
3012
3013         /* if all DACs are already assigned, connect to the primary DAC,
3014            unless we're assigning a secondary headphone */
3015         fallback_dac = spec->multiout.dac_nids[0];
3016         if (spec->multiout.hp_nid) {
3017                 for (j = 0; j < cfg->hp_outs; j++)
3018                         if (cfg->hp_pins[j] == nid) {
3019                                 fallback_dac = spec->multiout.hp_nid;
3020                                 break;
3021                         }
3022         }
3023
3024         if (conn_len > 1) {
3025                 for (j = 0; j < conn_len; j++) {
3026                         if (conn[j] == fallback_dac) {
3027                                 snd_hda_codec_write_cache(codec, nid, 0,
3028                                                   AC_VERB_SET_CONNECT_SEL, j);
3029                                 break;
3030                         }
3031                 }
3032         }
3033         return 0;
3034 }
3035
3036 static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
3037 static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
3038
3039 /*
3040  * Fill in the dac_nids table from the parsed pin configuration
3041  * This function only works when every pin in line_out_pins[]
3042  * contains atleast one DAC in its connection list. Some 92xx
3043  * codecs are not connected directly to a DAC, such as the 9200
3044  * and 9202/925x. For those, dac_nids[] must be hard-coded.
3045  */
3046 static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec)
3047 {
3048         struct sigmatel_spec *spec = codec->spec;
3049         struct auto_pin_cfg *cfg = &spec->autocfg;
3050         int i;
3051         hda_nid_t nid, dac;
3052         
3053         for (i = 0; i < cfg->line_outs; i++) {
3054                 nid = cfg->line_out_pins[i];
3055                 dac = get_unassigned_dac(codec, nid);
3056                 if (!dac) {
3057                         if (spec->multiout.num_dacs > 0) {
3058                                 /* we have already working output pins,
3059                                  * so let's drop the broken ones again
3060                                  */
3061                                 cfg->line_outs = spec->multiout.num_dacs;
3062                                 break;
3063                         }
3064                         /* error out, no available DAC found */
3065                         snd_printk(KERN_ERR
3066                                    "%s: No available DAC for pin 0x%x\n",
3067                                    __func__, nid);
3068                         return -ENODEV;
3069                 }
3070                 add_spec_dacs(spec, dac);
3071         }
3072
3073         for (i = 0; i < cfg->hp_outs; i++) {
3074                 nid = cfg->hp_pins[i];
3075                 dac = get_unassigned_dac(codec, nid);
3076                 if (dac) {
3077                         if (!spec->multiout.hp_nid)
3078                                 spec->multiout.hp_nid = dac;
3079                         else
3080                                 add_spec_extra_dacs(spec, dac);
3081                 }
3082                 spec->hp_dacs[i] = dac;
3083         }
3084
3085         for (i = 0; i < cfg->speaker_outs; i++) {
3086                 nid = cfg->speaker_pins[i];
3087                 dac = get_unassigned_dac(codec, nid);
3088                 if (dac)
3089                         add_spec_extra_dacs(spec, dac);
3090                 spec->speaker_dacs[i] = dac;
3091         }
3092
3093         /* add line-in as output */
3094         nid = check_line_out_switch(codec);
3095         if (nid) {
3096                 dac = get_unassigned_dac(codec, nid);
3097                 if (dac) {
3098                         snd_printdd("STAC: Add line-in 0x%x as output %d\n",
3099                                     nid, cfg->line_outs);
3100                         cfg->line_out_pins[cfg->line_outs] = nid;
3101                         cfg->line_outs++;
3102                         spec->line_switch = nid;
3103                         add_spec_dacs(spec, dac);
3104                 }
3105         }
3106         /* add mic as output */
3107         nid = check_mic_out_switch(codec, &dac);
3108         if (nid && dac) {
3109                 snd_printdd("STAC: Add mic-in 0x%x as output %d\n",
3110                             nid, cfg->line_outs);
3111                 cfg->line_out_pins[cfg->line_outs] = nid;
3112                 cfg->line_outs++;
3113                 spec->mic_switch = nid;
3114                 add_spec_dacs(spec, dac);
3115         }
3116
3117         snd_printd("stac92xx: dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
3118                    spec->multiout.num_dacs,
3119                    spec->multiout.dac_nids[0],
3120                    spec->multiout.dac_nids[1],
3121                    spec->multiout.dac_nids[2],
3122                    spec->multiout.dac_nids[3],
3123                    spec->multiout.dac_nids[4]);
3124
3125         return 0;
3126 }
3127
3128 /* create volume control/switch for the given prefx type */
3129 static int create_controls_idx(struct hda_codec *codec, const char *pfx,
3130                                int idx, hda_nid_t nid, int chs)
3131 {
3132         struct sigmatel_spec *spec = codec->spec;
3133         char name[32];
3134         int err;
3135
3136         if (!spec->check_volume_offset) {
3137                 unsigned int caps, step, nums, db_scale;
3138                 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3139                 step = (caps & AC_AMPCAP_STEP_SIZE) >>
3140                         AC_AMPCAP_STEP_SIZE_SHIFT;
3141                 step = (step + 1) * 25; /* in .01dB unit */
3142                 nums = (caps & AC_AMPCAP_NUM_STEPS) >>
3143                         AC_AMPCAP_NUM_STEPS_SHIFT;
3144                 db_scale = nums * step;
3145                 /* if dB scale is over -64dB, and finer enough,
3146                  * let's reduce it to half
3147                  */
3148                 if (db_scale > 6400 && nums >= 0x1f)
3149                         spec->volume_offset = nums / 2;
3150                 spec->check_volume_offset = 1;
3151         }
3152
3153         sprintf(name, "%s Playback Volume", pfx);
3154         err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, idx, name,
3155                 HDA_COMPOSE_AMP_VAL_OFS(nid, chs, 0, HDA_OUTPUT,
3156                                         spec->volume_offset));
3157         if (err < 0)
3158                 return err;
3159         sprintf(name, "%s Playback Switch", pfx);
3160         err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_MUTE, idx, name,
3161                                    HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
3162         if (err < 0)
3163                 return err;
3164         return 0;
3165 }
3166
3167 #define create_controls(codec, pfx, nid, chs) \
3168         create_controls_idx(codec, pfx, 0, nid, chs)
3169
3170 static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
3171 {
3172         if (spec->multiout.num_dacs > 4) {
3173                 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
3174                 return 1;
3175         } else {
3176                 snd_BUG_ON(spec->multiout.dac_nids != spec->dac_nids);
3177                 spec->dac_nids[spec->multiout.num_dacs] = nid;
3178                 spec->multiout.num_dacs++;
3179         }
3180         return 0;
3181 }
3182
3183 static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
3184 {
3185         int i;
3186         for (i = 0; i < ARRAY_SIZE(spec->multiout.extra_out_nid); i++) {
3187                 if (!spec->multiout.extra_out_nid[i]) {
3188                         spec->multiout.extra_out_nid[i] = nid;
3189                         return 0;
3190                 }
3191         }
3192         printk(KERN_WARNING "stac92xx: No space for extra DAC 0x%x\n", nid);
3193         return 1;
3194 }
3195
3196 /* Create output controls
3197  * The mixer elements are named depending on the given type (AUTO_PIN_XXX_OUT)
3198  */
3199 static int create_multi_out_ctls(struct hda_codec *codec, int num_outs,
3200                                  const hda_nid_t *pins,
3201                                  const hda_nid_t *dac_nids,
3202                                  int type)
3203 {
3204         struct sigmatel_spec *spec = codec->spec;
3205         static const char * const chname[4] = {
3206                 "Front", "Surround", NULL /*CLFE*/, "Side"
3207         };
3208         hda_nid_t nid;
3209         int i, err;
3210         unsigned int wid_caps;
3211
3212         for (i = 0; i < num_outs && i < ARRAY_SIZE(chname); i++) {
3213                 if (type == AUTO_PIN_HP_OUT && !spec->hp_detect) {
3214                         if (is_jack_detectable(codec, pins[i]))
3215                                 spec->hp_detect = 1;
3216                 }
3217                 nid = dac_nids[i];
3218                 if (!nid)
3219                         continue;
3220                 if (type != AUTO_PIN_HP_OUT && i == 2) {
3221                         /* Center/LFE */
3222                         err = create_controls(codec, "Center", nid, 1);
3223                         if (err < 0)
3224                                 return err;
3225                         err = create_controls(codec, "LFE", nid, 2);
3226                         if (err < 0)
3227                                 return err;
3228
3229                         wid_caps = get_wcaps(codec, nid);
3230
3231                         if (wid_caps & AC_WCAP_LR_SWAP) {
3232                                 err = stac92xx_add_control(spec,
3233                                         STAC_CTL_WIDGET_CLFE_SWITCH,
3234                                         "Swap Center/LFE Playback Switch", nid);
3235
3236                                 if (err < 0)
3237                                         return err;
3238                         }
3239
3240                 } else {
3241                         const char *name;
3242                         int idx;
3243                         switch (type) {
3244                         case AUTO_PIN_HP_OUT:
3245                                 name = "Headphone";
3246                                 idx = i;
3247                                 break;
3248                         case AUTO_PIN_SPEAKER_OUT:
3249                                 name = "Speaker";
3250                                 idx = i;
3251                                 break;
3252                         default:
3253                                 name = chname[i];
3254                                 idx = 0;
3255                                 break;
3256                         }
3257                         err = create_controls_idx(codec, name, idx, nid, 3);
3258                         if (err < 0)
3259                                 return err;
3260                 }
3261         }
3262         return 0;
3263 }
3264
3265 static int stac92xx_add_capvol_ctls(struct hda_codec *codec, unsigned long vol,
3266                                     unsigned long sw, int idx)
3267 {
3268         int err;
3269         err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_VOL, idx,
3270                                        "Capture Volume", vol);
3271         if (err < 0)
3272                 return err;
3273         err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_MUTE, idx,
3274                                        "Capture Switch", sw);
3275         if (err < 0)
3276                 return err;
3277         return 0;
3278 }
3279
3280 /* add playback controls from the parsed DAC table */
3281 static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
3282                                                const struct auto_pin_cfg *cfg)
3283 {
3284         struct sigmatel_spec *spec = codec->spec;
3285         hda_nid_t nid;
3286         int err;
3287         int idx;
3288
3289         err = create_multi_out_ctls(codec, cfg->line_outs, cfg->line_out_pins,
3290                                     spec->multiout.dac_nids,
3291                                     cfg->line_out_type);
3292         if (err < 0)
3293                 return err;
3294
3295         if (cfg->hp_outs > 1 && cfg->line_out_type == AUTO_PIN_LINE_OUT) {
3296                 err = stac92xx_add_control(spec,
3297                         STAC_CTL_WIDGET_HP_SWITCH,
3298                         "Headphone as Line Out Switch",
3299                         cfg->hp_pins[cfg->hp_outs - 1]);
3300                 if (err < 0)
3301                         return err;
3302         }
3303
3304         for (idx = 0; idx < cfg->num_inputs; idx++) {
3305                 if (cfg->inputs[idx].type > AUTO_PIN_LINE_IN)
3306                         break;
3307                 nid = cfg->inputs[idx].pin;
3308                 err = stac92xx_add_jack_mode_control(codec, nid, idx);
3309                 if (err < 0)
3310                         return err;
3311         }
3312
3313         return 0;
3314 }
3315
3316 /* add playback controls for Speaker and HP outputs */
3317 static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
3318                                         struct auto_pin_cfg *cfg)
3319 {
3320         struct sigmatel_spec *spec = codec->spec;
3321         int err;
3322
3323         err = create_multi_out_ctls(codec, cfg->hp_outs, cfg->hp_pins,
3324                                     spec->hp_dacs, AUTO_PIN_HP_OUT);
3325         if (err < 0)
3326                 return err;
3327
3328         err = create_multi_out_ctls(codec, cfg->speaker_outs, cfg->speaker_pins,
3329                                     spec->speaker_dacs, AUTO_PIN_SPEAKER_OUT);
3330         if (err < 0)
3331                 return err;
3332
3333         return 0;
3334 }
3335
3336 /* labels for mono mux outputs */
3337 static const char * const stac92xx_mono_labels[4] = {
3338         "DAC0", "DAC1", "Mixer", "DAC2"
3339 };
3340
3341 /* create mono mux for mono out on capable codecs */
3342 static int stac92xx_auto_create_mono_output_ctls(struct hda_codec *codec)
3343 {
3344         struct sigmatel_spec *spec = codec->spec;
3345         struct hda_input_mux *mono_mux = &spec->private_mono_mux;
3346         int i, num_cons;
3347         hda_nid_t con_lst[ARRAY_SIZE(stac92xx_mono_labels)];
3348
3349         num_cons = snd_hda_get_connections(codec,
3350                                 spec->mono_nid,
3351                                 con_lst,
3352                                 HDA_MAX_NUM_INPUTS);
3353         if (num_cons <= 0 || num_cons > ARRAY_SIZE(stac92xx_mono_labels))
3354                 return -EINVAL;
3355
3356         for (i = 0; i < num_cons; i++)
3357                 snd_hda_add_imux_item(mono_mux, stac92xx_mono_labels[i], i,
3358                                       NULL);
3359
3360         return stac92xx_add_control(spec, STAC_CTL_WIDGET_MONO_MUX,
3361                                 "Mono Mux", spec->mono_nid);
3362 }
3363
3364 /* create PC beep volume controls */
3365 static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
3366                                                 hda_nid_t nid)
3367 {
3368         struct sigmatel_spec *spec = codec->spec;
3369         u32 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3370         int err, type = STAC_CTL_WIDGET_MUTE_BEEP;
3371
3372         if (spec->anabeep_nid == nid)
3373                 type = STAC_CTL_WIDGET_MUTE;
3374
3375         /* check for mute support for the the amp */
3376         if ((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT) {
3377                 err = stac92xx_add_control(spec, type,
3378                         "Beep Playback Switch",
3379                         HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3380                         if (err < 0)
3381                                 return err;
3382         }
3383
3384         /* check to see if there is volume support for the amp */
3385         if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3386                 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL,
3387                         "Beep Playback Volume",
3388                         HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3389                         if (err < 0)
3390                                 return err;
3391         }
3392         return 0;
3393 }
3394
3395 #ifdef CONFIG_SND_HDA_INPUT_BEEP
3396 #define stac92xx_dig_beep_switch_info snd_ctl_boolean_mono_info
3397
3398 static int stac92xx_dig_beep_switch_get(struct snd_kcontrol *kcontrol,
3399                                         struct snd_ctl_elem_value *ucontrol)
3400 {
3401         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3402         ucontrol->value.integer.value[0] = codec->beep->enabled;
3403         return 0;
3404 }
3405
3406 static int stac92xx_dig_beep_switch_put(struct snd_kcontrol *kcontrol,
3407                                         struct snd_ctl_elem_value *ucontrol)
3408 {
3409         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3410         return snd_hda_enable_beep_device(codec, ucontrol->value.integer.value[0]);
3411 }
3412
3413 static const struct snd_kcontrol_new stac92xx_dig_beep_ctrl = {
3414         .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3415         .info = stac92xx_dig_beep_switch_info,
3416         .get = stac92xx_dig_beep_switch_get,
3417         .put = stac92xx_dig_beep_switch_put,
3418 };
3419
3420 static int stac92xx_beep_switch_ctl(struct hda_codec *codec)
3421 {
3422         return stac92xx_add_control_temp(codec->spec, &stac92xx_dig_beep_ctrl,
3423                                          0, "Beep Playback Switch", 0);
3424 }
3425 #endif
3426
3427 static int stac92xx_auto_create_mux_input_ctls(struct hda_codec *codec)
3428 {
3429         struct sigmatel_spec *spec = codec->spec;
3430         int i, j, err = 0;
3431
3432         for (i = 0; i < spec->num_muxes; i++) {
3433                 hda_nid_t nid;
3434                 unsigned int wcaps;
3435                 unsigned long val;
3436
3437                 nid = spec->mux_nids[i];
3438                 wcaps = get_wcaps(codec, nid);
3439                 if (!(wcaps & AC_WCAP_OUT_AMP))
3440                         continue;
3441
3442                 /* check whether already the same control was created as
3443                  * normal Capture Volume.
3444                  */
3445                 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3446                 for (j = 0; j < spec->num_caps; j++) {
3447                         if (spec->capvols[j] == val)
3448                                 break;
3449                 }
3450                 if (j < spec->num_caps)
3451                         continue;
3452
3453                 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, i,
3454                                                "Mux Capture Volume", val);
3455                 if (err < 0)
3456                         return err;
3457         }
3458         return 0;
3459 };
3460
3461 static const char * const stac92xx_spdif_labels[3] = {
3462         "Digital Playback", "Analog Mux 1", "Analog Mux 2",
3463 };
3464
3465 static int stac92xx_auto_create_spdif_mux_ctls(struct hda_codec *codec)
3466 {
3467         struct sigmatel_spec *spec = codec->spec;
3468         struct hda_input_mux *spdif_mux = &spec->private_smux;
3469         const char * const *labels = spec->spdif_labels;
3470         int i, num_cons;
3471         hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
3472
3473         num_cons = snd_hda_get_connections(codec,
3474                                 spec->smux_nids[0],
3475                                 con_lst,
3476                                 HDA_MAX_NUM_INPUTS);
3477         if (num_cons <= 0)
3478                 return -EINVAL;
3479
3480         if (!labels)
3481                 labels = stac92xx_spdif_labels;
3482
3483         for (i = 0; i < num_cons; i++)
3484                 snd_hda_add_imux_item(spdif_mux, labels[i], i, NULL);
3485
3486         return 0;
3487 }
3488
3489 /* labels for dmic mux inputs */
3490 static const char * const stac92xx_dmic_labels[5] = {
3491         "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
3492         "Digital Mic 3", "Digital Mic 4"
3493 };
3494
3495 static hda_nid_t get_connected_node(struct hda_codec *codec, hda_nid_t mux,
3496                                     int idx)
3497 {
3498         hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3499         int nums;
3500         nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3501         if (idx >= 0 && idx < nums)
3502                 return conn[idx];
3503         return 0;
3504 }
3505
3506 /* look for NID recursively */
3507 #define get_connection_index(codec, mux, nid) \
3508         snd_hda_get_conn_index(codec, mux, nid, 1)
3509
3510 /* create a volume assigned to the given pin (only if supported) */
3511 /* return 1 if the volume control is created */
3512 static int create_elem_capture_vol(struct hda_codec *codec, hda_nid_t nid,
3513                                    const char *label, int idx, int direction)
3514 {
3515         unsigned int caps, nums;
3516         char name[32];
3517         int err;
3518
3519         if (direction == HDA_OUTPUT)
3520                 caps = AC_WCAP_OUT_AMP;
3521         else
3522                 caps = AC_WCAP_IN_AMP;
3523         if (!(get_wcaps(codec, nid) & caps))
3524                 return 0;
3525         caps = query_amp_caps(codec, nid, direction);
3526         nums = (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT;
3527         if (!nums)
3528                 return 0;
3529         snprintf(name, sizeof(name), "%s Capture Volume", label);
3530         err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_VOL, idx, name,
3531                                        HDA_COMPOSE_AMP_VAL(nid, 3, 0, direction));
3532         if (err < 0)
3533                 return err;
3534         return 1;
3535 }
3536
3537 /* create playback/capture controls for input pins on dmic capable codecs */
3538 static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
3539                                                 const struct auto_pin_cfg *cfg)
3540 {
3541         struct sigmatel_spec *spec = codec->spec;
3542         struct hda_input_mux *imux = &spec->private_imux;
3543         struct hda_input_mux *dimux = &spec->private_dimux;
3544         int err, i;
3545         unsigned int def_conf;
3546
3547         snd_hda_add_imux_item(dimux, stac92xx_dmic_labels[0], 0, NULL);
3548
3549         for (i = 0; i < spec->num_dmics; i++) {
3550                 hda_nid_t nid;
3551                 int index, type_idx;
3552                 const char *label;
3553
3554                 nid = spec->dmic_nids[i];
3555                 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
3556                         continue;
3557                 def_conf = snd_hda_codec_get_pincfg(codec, nid);
3558                 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
3559                         continue;
3560
3561                 index = get_connection_index(codec, spec->dmux_nids[0], nid);
3562                 if (index < 0)
3563                         continue;
3564
3565                 label = hda_get_input_pin_label(codec, nid, 1);
3566                 snd_hda_add_imux_item(dimux, label, index, &type_idx);
3567                 if (snd_hda_get_bool_hint(codec, "separate_dmux") != 1)
3568                         snd_hda_add_imux_item(imux, label, index, &type_idx);
3569
3570                 err = create_elem_capture_vol(codec, nid, label, type_idx,
3571                                               HDA_INPUT);
3572                 if (err < 0)
3573                         return err;
3574                 if (!err) {
3575                         err = create_elem_capture_vol(codec, nid, label,
3576                                                       type_idx, HDA_OUTPUT);
3577                         if (err < 0)
3578                                 return err;
3579                         if (!err) {
3580                                 nid = get_connected_node(codec,
3581                                                 spec->dmux_nids[0], index);
3582                                 if (nid)
3583                                         err = create_elem_capture_vol(codec,
3584                                                         nid, label,
3585                                                         type_idx, HDA_INPUT);
3586                                 if (err < 0)
3587                                         return err;
3588                         }
3589                 }
3590         }
3591
3592         return 0;
3593 }
3594
3595 static int check_mic_pin(struct hda_codec *codec, hda_nid_t nid,
3596                          hda_nid_t *fixed, hda_nid_t *ext, hda_nid_t *dock)
3597 {
3598         unsigned int cfg;
3599         unsigned int type;
3600
3601         if (!nid)
3602                 return 0;
3603         cfg = snd_hda_codec_get_pincfg(codec, nid);
3604         type = get_defcfg_device(cfg);
3605         switch (snd_hda_get_input_pin_attr(cfg)) {
3606         case INPUT_PIN_ATTR_INT:
3607                 if (*fixed)
3608                         return 1; /* already occupied */
3609                 if (type != AC_JACK_MIC_IN)
3610                         return 1; /* invalid type */
3611                 *fixed = nid;
3612                 break;
3613         case INPUT_PIN_ATTR_UNUSED:
3614                 break;
3615         case INPUT_PIN_ATTR_DOCK:
3616                 if (*dock)
3617                         return 1; /* already occupied */
3618                 if (type != AC_JACK_MIC_IN && type != AC_JACK_LINE_IN)
3619                         return 1; /* invalid type */
3620                 *dock = nid;
3621                 break;
3622         default:
3623                 if (*ext)
3624                         return 1; /* already occupied */
3625                 if (type != AC_JACK_MIC_IN)
3626                         return 1; /* invalid type */
3627                 *ext = nid;
3628                 break;
3629         }
3630         return 0;
3631 }
3632
3633 static int set_mic_route(struct hda_codec *codec,
3634                          struct sigmatel_mic_route *mic,
3635                          hda_nid_t pin)
3636 {
3637         struct sigmatel_spec *spec = codec->spec;
3638         struct auto_pin_cfg *cfg = &spec->autocfg;
3639         int i;
3640
3641         mic->pin = pin;
3642         if (pin == 0)
3643                 return 0;
3644         for (i = 0; i < cfg->num_inputs; i++) {
3645                 if (pin == cfg->inputs[i].pin)
3646                         break;
3647         }
3648         if (i < cfg->num_inputs && cfg->inputs[i].type == AUTO_PIN_MIC) {
3649                 /* analog pin */
3650                 i = get_connection_index(codec, spec->mux_nids[0], pin);
3651                 if (i < 0)
3652                         return -1;
3653                 mic->mux_idx = i;
3654                 mic->dmux_idx = -1;
3655                 if (spec->dmux_nids)
3656                         mic->dmux_idx = get_connection_index(codec,
3657                                                              spec->dmux_nids[0],
3658                                                              spec->mux_nids[0]);
3659         }  else if (spec->dmux_nids) {
3660                 /* digital pin */
3661                 i = get_connection_index(codec, spec->dmux_nids[0], pin);
3662                 if (i < 0)
3663                         return -1;
3664                 mic->dmux_idx = i;
3665                 mic->mux_idx = -1;
3666                 if (spec->mux_nids)
3667                         mic->mux_idx = get_connection_index(codec,
3668                                                             spec->mux_nids[0],
3669                                                             spec->dmux_nids[0]);
3670         }
3671         return 0;
3672 }
3673
3674 /* return non-zero if the device is for automatic mic switch */
3675 static int stac_check_auto_mic(struct hda_codec *codec)
3676 {
3677         struct sigmatel_spec *spec = codec->spec;
3678         struct auto_pin_cfg *cfg = &spec->autocfg;
3679         hda_nid_t fixed, ext, dock;
3680         int i;
3681
3682         fixed = ext = dock = 0;
3683         for (i = 0; i < cfg->num_inputs; i++)
3684                 if (check_mic_pin(codec, cfg->inputs[i].pin,
3685                     &fixed, &ext, &dock))
3686                         return 0;
3687         for (i = 0; i < spec->num_dmics; i++)
3688                 if (check_mic_pin(codec, spec->dmic_nids[i],
3689                     &fixed, &ext, &dock))
3690                         return 0;
3691         if (!fixed || (!ext && !dock))
3692                 return 0; /* no input to switch */
3693         if (!is_jack_detectable(codec, ext))
3694                 return 0; /* no unsol support */
3695         if (set_mic_route(codec, &spec->ext_mic, ext) ||
3696             set_mic_route(codec, &spec->int_mic, fixed) ||
3697             set_mic_route(codec, &spec->dock_mic, dock))
3698                 return 0; /* something is wrong */
3699         return 1;
3700 }
3701
3702 /* create playback/capture controls for input pins */
3703 static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
3704 {
3705         struct sigmatel_spec *spec = codec->spec;
3706         struct hda_input_mux *imux = &spec->private_imux;
3707         int i, j;
3708         const char *label;
3709
3710         for (i = 0; i < cfg->num_inputs; i++) {
3711                 hda_nid_t nid = cfg->inputs[i].pin;
3712                 int index, err, type_idx;
3713
3714                 index = -1;
3715                 for (j = 0; j < spec->num_muxes; j++) {
3716                         index = get_connection_index(codec, spec->mux_nids[j],
3717                                                      nid);
3718                         if (index >= 0)
3719                                 break;
3720                 }
3721                 if (index < 0)
3722                         continue;
3723
3724                 label = hda_get_autocfg_input_label(codec, cfg, i);
3725                 snd_hda_add_imux_item(imux, label, index, &type_idx);
3726
3727                 err = create_elem_capture_vol(codec, nid,
3728                                               label, type_idx,
3729                                               HDA_INPUT);
3730                 if (err < 0)
3731                         return err;
3732         }
3733         spec->num_analog_muxes = imux->num_items;
3734
3735         if (imux->num_items) {
3736                 /*
3737                  * Set the current input for the muxes.
3738                  * The STAC9221 has two input muxes with identical source
3739                  * NID lists.  Hopefully this won't get confused.
3740                  */
3741                 for (i = 0; i < spec->num_muxes; i++) {
3742                         snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
3743                                                   AC_VERB_SET_CONNECT_SEL,
3744                                                   imux->items[0].index);
3745                 }
3746         }
3747
3748         return 0;
3749 }
3750
3751 static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
3752 {
3753         struct sigmatel_spec *spec = codec->spec;
3754         int i;
3755
3756         for (i = 0; i < spec->autocfg.line_outs; i++) {
3757                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3758                 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
3759         }
3760 }
3761
3762 static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
3763 {
3764         struct sigmatel_spec *spec = codec->spec;
3765         int i;
3766
3767         for (i = 0; i < spec->autocfg.hp_outs; i++) {
3768                 hda_nid_t pin;
3769                 pin = spec->autocfg.hp_pins[i];
3770                 if (pin) /* connect to front */
3771                         stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
3772         }
3773         for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3774                 hda_nid_t pin;
3775                 pin = spec->autocfg.speaker_pins[i];
3776                 if (pin) /* connect to front */
3777                         stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
3778         }
3779 }
3780
3781 static int is_dual_headphones(struct hda_codec *codec)
3782 {
3783         struct sigmatel_spec *spec = codec->spec;
3784         int i, valid_hps;
3785
3786         if (spec->autocfg.line_out_type != AUTO_PIN_SPEAKER_OUT ||
3787             spec->autocfg.hp_outs <= 1)
3788                 return 0;
3789         valid_hps = 0;
3790         for (i = 0; i < spec->autocfg.hp_outs; i++) {
3791                 hda_nid_t nid = spec->autocfg.hp_pins[i];
3792                 unsigned int cfg = snd_hda_codec_get_pincfg(codec, nid);
3793                 if (get_defcfg_location(cfg) & AC_JACK_LOC_SEPARATE)
3794                         continue;
3795                 valid_hps++;
3796         }
3797         return (valid_hps > 1);
3798 }
3799
3800
3801 static int stac92xx_parse_auto_config(struct hda_codec *codec)
3802 {
3803         struct sigmatel_spec *spec = codec->spec;
3804         hda_nid_t dig_out = 0, dig_in = 0;
3805         int hp_swap = 0;
3806         int i, err;
3807
3808         if ((err = snd_hda_parse_pin_def_config(codec,
3809                                                 &spec->autocfg,
3810                                                 spec->dmic_nids)) < 0)
3811                 return err;
3812         if (! spec->autocfg.line_outs)
3813                 return 0; /* can't find valid pin config */
3814
3815         /* If we have no real line-out pin and multiple hp-outs, HPs should
3816          * be set up as multi-channel outputs.
3817          */
3818         if (is_dual_headphones(codec)) {
3819                 /* Copy hp_outs to line_outs, backup line_outs in
3820                  * speaker_outs so that the following routines can handle
3821                  * HP pins as primary outputs.
3822                  */
3823                 snd_printdd("stac92xx: Enabling multi-HPs workaround\n");
3824                 memcpy(spec->autocfg.speaker_pins, spec->autocfg.line_out_pins,
3825                        sizeof(spec->autocfg.line_out_pins));
3826                 spec->autocfg.speaker_outs = spec->autocfg.line_outs;
3827                 memcpy(spec->autocfg.line_out_pins, spec->autocfg.hp_pins,
3828                        sizeof(spec->autocfg.hp_pins));
3829                 spec->autocfg.line_outs = spec->autocfg.hp_outs;
3830                 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3831                 spec->autocfg.hp_outs = 0;
3832                 hp_swap = 1;
3833         }
3834         if (spec->autocfg.mono_out_pin) {
3835                 int dir = get_wcaps(codec, spec->autocfg.mono_out_pin) &
3836                         (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
3837                 u32 caps = query_amp_caps(codec,
3838                                 spec->autocfg.mono_out_pin, dir);
3839                 hda_nid_t conn_list[1];
3840
3841                 /* get the mixer node and then the mono mux if it exists */
3842                 if (snd_hda_get_connections(codec,
3843                                 spec->autocfg.mono_out_pin, conn_list, 1) &&
3844                                 snd_hda_get_connections(codec, conn_list[0],
3845                                 conn_list, 1) > 0) {
3846
3847                                 int wcaps = get_wcaps(codec, conn_list[0]);
3848                                 int wid_type = get_wcaps_type(wcaps);
3849                                 /* LR swap check, some stac925x have a mux that
3850                                  * changes the DACs output path instead of the
3851                                  * mono-mux path.
3852                                  */
3853                                 if (wid_type == AC_WID_AUD_SEL &&
3854                                                 !(wcaps & AC_WCAP_LR_SWAP))
3855                                         spec->mono_nid = conn_list[0];
3856                 }
3857                 if (dir) {
3858                         hda_nid_t nid = spec->autocfg.mono_out_pin;
3859
3860                         /* most mono outs have a least a mute/unmute switch */
3861                         dir = (dir & AC_WCAP_OUT_AMP) ? HDA_OUTPUT : HDA_INPUT;
3862                         err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3863                                 "Mono Playback Switch",
3864                                 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
3865                         if (err < 0)
3866                                 return err;
3867                         /* check for volume support for the amp */
3868                         if ((caps & AC_AMPCAP_NUM_STEPS)
3869                                         >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3870                                 err = stac92xx_add_control(spec,
3871                                         STAC_CTL_WIDGET_VOL,
3872                                         "Mono Playback Volume",
3873                                 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
3874                                 if (err < 0)
3875                                         return err;
3876                         }
3877                 }
3878
3879                 stac92xx_auto_set_pinctl(codec, spec->autocfg.mono_out_pin,
3880                                          AC_PINCTL_OUT_EN);
3881         }
3882
3883         if (!spec->multiout.num_dacs) {
3884                 err = stac92xx_auto_fill_dac_nids(codec);
3885                 if (err < 0)
3886                         return err;
3887                 err = stac92xx_auto_create_multi_out_ctls(codec,
3888                                                           &spec->autocfg);
3889                 if (err < 0)
3890                         return err;
3891         }
3892
3893         /* setup analog beep controls */
3894         if (spec->anabeep_nid > 0) {
3895                 err = stac92xx_auto_create_beep_ctls(codec,
3896                         spec->anabeep_nid);
3897                 if (err < 0)
3898                         return err;
3899         }
3900
3901         /* setup digital beep controls and input device */
3902 #ifdef CONFIG_SND_HDA_INPUT_BEEP
3903         if (spec->digbeep_nid > 0) {
3904                 hda_nid_t nid = spec->digbeep_nid;
3905                 unsigned int caps;
3906
3907                 err = stac92xx_auto_create_beep_ctls(codec, nid);
3908                 if (err < 0)
3909                         return err;
3910                 err = snd_hda_attach_beep_device(codec, nid);
3911                 if (err < 0)
3912                         return err;
3913                 if (codec->beep) {
3914                         /* IDT/STAC codecs have linear beep tone parameter */
3915                         codec->beep->linear_tone = spec->linear_tone_beep;
3916                         /* if no beep switch is available, make its own one */
3917                         caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3918                         if (!(caps & AC_AMPCAP_MUTE)) {
3919                                 err = stac92xx_beep_switch_ctl(codec);
3920                                 if (err < 0)
3921                                         return err;
3922                         }
3923                 }
3924         }
3925 #endif
3926
3927         err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
3928         if (err < 0)
3929                 return err;
3930
3931         /* All output parsing done, now restore the swapped hp pins */
3932         if (hp_swap) {
3933                 memcpy(spec->autocfg.hp_pins, spec->autocfg.line_out_pins,
3934                        sizeof(spec->autocfg.hp_pins));
3935                 spec->autocfg.hp_outs = spec->autocfg.line_outs;
3936                 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3937                 spec->autocfg.line_outs = 0;
3938         }
3939
3940         if (stac_check_auto_mic(codec)) {
3941                 spec->auto_mic = 1;
3942                 /* only one capture for auto-mic */
3943                 spec->num_adcs = 1;
3944                 spec->num_caps = 1;
3945                 spec->num_muxes = 1;
3946         }
3947
3948         for (i = 0; i < spec->num_caps; i++) {
3949                 err = stac92xx_add_capvol_ctls(codec, spec->capvols[i],
3950                                                spec->capsws[i], i);
3951                 if (err < 0)
3952                         return err;
3953         }
3954
3955         err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
3956         if (err < 0)
3957                 return err;
3958
3959         if (spec->mono_nid > 0) {
3960                 err = stac92xx_auto_create_mono_output_ctls(codec);
3961                 if (err < 0)
3962                         return err;
3963         }
3964         if (spec->num_dmics > 0 && !spec->dinput_mux)
3965                 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
3966                                                 &spec->autocfg)) < 0)
3967                         return err;
3968         if (spec->num_muxes > 0) {
3969                 err = stac92xx_auto_create_mux_input_ctls(codec);
3970                 if (err < 0)
3971                         return err;
3972         }
3973         if (spec->num_smuxes > 0) {
3974                 err = stac92xx_auto_create_spdif_mux_ctls(codec);
3975                 if (err < 0)
3976                         return err;
3977         }
3978
3979         err = stac92xx_add_input_source(spec);
3980         if (err < 0)
3981                 return err;
3982
3983         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3984         if (spec->multiout.max_channels > 2)
3985                 spec->surr_switch = 1;
3986
3987         /* find digital out and in converters */
3988         for (i = codec->start_nid; i < codec->start_nid + codec->num_nodes; i++) {
3989                 unsigned int wid_caps = get_wcaps(codec, i);
3990                 if (wid_caps & AC_WCAP_DIGITAL) {
3991                         switch (get_wcaps_type(wid_caps)) {
3992                         case AC_WID_AUD_OUT:
3993                                 if (!dig_out)
3994                                         dig_out = i;
3995                                 break;
3996                         case AC_WID_AUD_IN:
3997                                 if (!dig_in)
3998                                         dig_in = i;
3999                                 break;
4000                         }
4001                 }
4002         }
4003         if (spec->autocfg.dig_outs)
4004                 spec->multiout.dig_out_nid = dig_out;
4005         if (dig_in && spec->autocfg.dig_in_pin)
4006                 spec->dig_in_nid = dig_in;
4007
4008         if (spec->kctls.list)
4009                 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4010
4011         spec->input_mux = &spec->private_imux;
4012         if (!spec->dinput_mux)
4013                 spec->dinput_mux = &spec->private_dimux;
4014         spec->sinput_mux = &spec->private_smux;
4015         spec->mono_mux = &spec->private_mono_mux;
4016         return 1;
4017 }
4018
4019 /* add playback controls for HP output */
4020 static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
4021                                         struct auto_pin_cfg *cfg)
4022 {
4023         struct sigmatel_spec *spec = codec->spec;
4024         hda_nid_t pin = cfg->hp_pins[0];
4025
4026         if (! pin)
4027                 return 0;
4028
4029         if (is_jack_detectable(codec, pin))
4030                 spec->hp_detect = 1;
4031
4032         return 0;
4033 }
4034
4035 /* add playback controls for LFE output */
4036 static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
4037                                         struct auto_pin_cfg *cfg)
4038 {
4039         struct sigmatel_spec *spec = codec->spec;
4040         int err;
4041         hda_nid_t lfe_pin = 0x0;
4042         int i;
4043
4044         /*
4045          * search speaker outs and line outs for a mono speaker pin
4046          * with an amp.  If one is found, add LFE controls
4047          * for it.
4048          */
4049         for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
4050                 hda_nid_t pin = spec->autocfg.speaker_pins[i];
4051                 unsigned int wcaps = get_wcaps(codec, pin);
4052                 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
4053                 if (wcaps == AC_WCAP_OUT_AMP)
4054                         /* found a mono speaker with an amp, must be lfe */
4055                         lfe_pin = pin;
4056         }
4057
4058         /* if speaker_outs is 0, then speakers may be in line_outs */
4059         if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
4060                 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
4061                         hda_nid_t pin = spec->autocfg.line_out_pins[i];
4062                         unsigned int defcfg;
4063                         defcfg = snd_hda_codec_get_pincfg(codec, pin);
4064                         if (get_defcfg_device(defcfg) == AC_JACK_SPEAKER) {
4065                                 unsigned int wcaps = get_wcaps(codec, pin);
4066                                 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
4067                                 if (wcaps == AC_WCAP_OUT_AMP)
4068                                         /* found a mono speaker with an amp,
4069                                            must be lfe */
4070                                         lfe_pin = pin;
4071                         }
4072                 }
4073         }
4074
4075         if (lfe_pin) {
4076                 err = create_controls(codec, "LFE", lfe_pin, 1);
4077                 if (err < 0)
4078                         return err;
4079         }
4080
4081         return 0;
4082 }
4083
4084 static int stac9200_parse_auto_config(struct hda_codec *codec)
4085 {
4086         struct sigmatel_spec *spec = codec->spec;
4087         int err;
4088
4089         if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
4090                 return err;
4091
4092         if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
4093                 return err;
4094
4095         if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
4096                 return err;
4097
4098         if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
4099                 return err;
4100
4101         if (spec->num_muxes > 0) {
4102                 err = stac92xx_auto_create_mux_input_ctls(codec);
4103                 if (err < 0)
4104                         return err;
4105         }
4106
4107         err = stac92xx_add_input_source(spec);
4108         if (err < 0)
4109                 return err;
4110
4111         if (spec->autocfg.dig_outs)
4112                 spec->multiout.dig_out_nid = 0x05;
4113         if (spec->autocfg.dig_in_pin)
4114                 spec->dig_in_nid = 0x04;
4115
4116         if (spec->kctls.list)
4117                 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4118
4119         spec->input_mux = &spec->private_imux;
4120         spec->dinput_mux = &spec->private_dimux;
4121
4122         return 1;
4123 }
4124
4125 /*
4126  * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
4127  * funky external mute control using GPIO pins.
4128  */
4129
4130 static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
4131                           unsigned int dir_mask, unsigned int data)
4132 {
4133         unsigned int gpiostate, gpiomask, gpiodir;
4134
4135         snd_printdd("%s msk %x dir %x gpio %x\n", __func__, mask, dir_mask, data);
4136
4137         gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
4138                                        AC_VERB_GET_GPIO_DATA, 0);
4139         gpiostate = (gpiostate & ~dir_mask) | (data & dir_mask);
4140
4141         gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
4142                                       AC_VERB_GET_GPIO_MASK, 0);
4143         gpiomask |= mask;
4144
4145         gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
4146                                      AC_VERB_GET_GPIO_DIRECTION, 0);
4147         gpiodir |= dir_mask;
4148
4149         /* Configure GPIOx as CMOS */
4150         snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
4151
4152         snd_hda_codec_write(codec, codec->afg, 0,
4153                             AC_VERB_SET_GPIO_MASK, gpiomask);
4154         snd_hda_codec_read(codec, codec->afg, 0,
4155                            AC_VERB_SET_GPIO_DIRECTION, gpiodir); /* sync */
4156
4157         msleep(1);
4158
4159         snd_hda_codec_read(codec, codec->afg, 0,
4160                            AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */
4161 }
4162
4163 static int stac92xx_add_jack(struct hda_codec *codec,
4164                 hda_nid_t nid, int type)
4165 {
4166 #ifdef CONFIG_SND_HDA_INPUT_JACK
4167         int def_conf = snd_hda_codec_get_pincfg(codec, nid);
4168         int connectivity = get_defcfg_connect(def_conf);
4169
4170         if (connectivity && connectivity != AC_JACK_PORT_FIXED)
4171                 return 0;
4172
4173         return snd_hda_input_jack_add(codec, nid, type, NULL);
4174 #else
4175         return 0;
4176 #endif /* CONFIG_SND_HDA_INPUT_JACK */
4177 }
4178
4179 static int stac_add_event(struct sigmatel_spec *spec, hda_nid_t nid,
4180                           unsigned char type, int data)
4181 {
4182         struct sigmatel_event *event;
4183
4184         snd_array_init(&spec->events, sizeof(*event), 32);
4185         event = snd_array_new(&spec->events);
4186         if (!event)
4187                 return -ENOMEM;
4188         event->nid = nid;
4189         event->type = type;
4190         event->tag = spec->events.used;
4191         event->data = data;
4192
4193         return event->tag;
4194 }
4195
4196 static struct sigmatel_event *stac_get_event(struct hda_codec *codec,
4197                                              hda_nid_t nid)
4198 {
4199         struct sigmatel_spec *spec = codec->spec;
4200         struct sigmatel_event *event = spec->events.list;
4201         int i;
4202
4203         for (i = 0; i < spec->events.used; i++, event++) {
4204                 if (event->nid == nid)
4205                         return event;
4206         }
4207         return NULL;
4208 }
4209
4210 static struct sigmatel_event *stac_get_event_from_tag(struct hda_codec *codec,
4211                                                       unsigned char tag)
4212 {
4213         struct sigmatel_spec *spec = codec->spec;
4214         struct sigmatel_event *event = spec->events.list;
4215         int i;
4216
4217         for (i = 0; i < spec->events.used; i++, event++) {
4218                 if (event->tag == tag)
4219                         return event;
4220         }
4221         return NULL;
4222 }
4223
4224 /* check if given nid is a valid pin and no other events are assigned
4225  * to it.  If OK, assign the event, set the unsol flag, and returns 1.
4226  * Otherwise, returns zero.
4227  */
4228 static int enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
4229                              unsigned int type)
4230 {
4231         struct sigmatel_event *event;
4232         int tag;
4233
4234         if (!is_jack_detectable(codec, nid))
4235                 return 0;
4236         event = stac_get_event(codec, nid);
4237         if (event) {
4238                 if (event->type != type)
4239                         return 0;
4240                 tag = event->tag;
4241         } else {
4242                 tag = stac_add_event(codec->spec, nid, type, 0);
4243                 if (tag < 0)
4244                         return 0;
4245         }
4246         snd_hda_codec_write_cache(codec, nid, 0,
4247                                   AC_VERB_SET_UNSOLICITED_ENABLE,
4248                                   AC_USRSP_EN | tag);
4249         return 1;
4250 }
4251
4252 static int is_nid_hp_pin(struct auto_pin_cfg *cfg, hda_nid_t nid)
4253 {
4254         int i;
4255         for (i = 0; i < cfg->hp_outs; i++)
4256                 if (cfg->hp_pins[i] == nid)
4257                         return 1; /* nid is a HP-Out */
4258
4259         return 0; /* nid is not a HP-Out */
4260 };
4261
4262 static void stac92xx_power_down(struct hda_codec *codec)
4263 {
4264         struct sigmatel_spec *spec = codec->spec;
4265
4266         /* power down inactive DACs */
4267         const hda_nid_t *dac;
4268         for (dac = spec->dac_list; *dac; dac++)
4269                 if (!check_all_dac_nids(spec, *dac))
4270                         snd_hda_codec_write(codec, *dac, 0,
4271                                         AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4272 }
4273
4274 static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4275                                   int enable);
4276
4277 static inline int get_int_hint(struct hda_codec *codec, const char *key,
4278                                int *valp)
4279 {
4280         const char *p;
4281         p = snd_hda_get_hint(codec, key);
4282         if (p) {
4283                 unsigned long val;
4284                 if (!strict_strtoul(p, 0, &val)) {
4285                         *valp = val;
4286                         return 1;
4287                 }
4288         }
4289         return 0;
4290 }
4291
4292 /* override some hints from the hwdep entry */
4293 static void stac_store_hints(struct hda_codec *codec)
4294 {
4295         struct sigmatel_spec *spec = codec->spec;
4296         int val;
4297
4298         val = snd_hda_get_bool_hint(codec, "hp_detect");
4299         if (val >= 0)
4300                 spec->hp_detect = val;
4301         if (get_int_hint(codec, "gpio_mask", &spec->gpio_mask)) {
4302                 spec->eapd_mask = spec->gpio_dir = spec->gpio_data =
4303                         spec->gpio_mask;
4304         }
4305         if (get_int_hint(codec, "gpio_dir", &spec->gpio_dir))
4306                 spec->gpio_mask &= spec->gpio_mask;
4307         if (get_int_hint(codec, "gpio_data", &spec->gpio_data))
4308                 spec->gpio_dir &= spec->gpio_mask;
4309         if (get_int_hint(codec, "eapd_mask", &spec->eapd_mask))
4310                 spec->eapd_mask &= spec->gpio_mask;
4311         if (get_int_hint(codec, "gpio_mute", &spec->gpio_mute))
4312                 spec->gpio_mute &= spec->gpio_mask;
4313         val = snd_hda_get_bool_hint(codec, "eapd_switch");
4314         if (val >= 0)
4315                 spec->eapd_switch = val;
4316         get_int_hint(codec, "gpio_led_polarity", &spec->gpio_led_polarity);
4317         if (get_int_hint(codec, "gpio_led", &spec->gpio_led)) {
4318                 spec->gpio_mask |= spec->gpio_led;
4319                 spec->gpio_dir |= spec->gpio_led;
4320                 if (spec->gpio_led_polarity)
4321                         spec->gpio_data |= spec->gpio_led;
4322         }
4323 }
4324
4325 static int stac92xx_init(struct hda_codec *codec)
4326 {
4327         struct sigmatel_spec *spec = codec->spec;
4328         struct auto_pin_cfg *cfg = &spec->autocfg;
4329         unsigned int gpio;
4330         int i;
4331
4332         snd_hda_sequence_write(codec, spec->init);
4333
4334         /* power down adcs initially */
4335         if (spec->powerdown_adcs)
4336                 for (i = 0; i < spec->num_adcs; i++)
4337                         snd_hda_codec_write(codec,
4338                                 spec->adc_nids[i], 0,
4339                                 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4340
4341         /* override some hints */
4342         stac_store_hints(codec);
4343
4344         /* set up GPIO */
4345         gpio = spec->gpio_data;
4346         /* turn on EAPD statically when spec->eapd_switch isn't set.
4347          * otherwise, unsol event will turn it on/off dynamically
4348          */
4349         if (!spec->eapd_switch)
4350                 gpio |= spec->eapd_mask;
4351         stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, gpio);
4352
4353         /* set up pins */
4354         if (spec->hp_detect) {
4355                 /* Enable unsolicited responses on the HP widget */
4356                 for (i = 0; i < cfg->hp_outs; i++) {
4357                         hda_nid_t nid = cfg->hp_pins[i];
4358                         enable_pin_detect(codec, nid, STAC_HP_EVENT);
4359                 }
4360                 if (cfg->line_out_type == AUTO_PIN_LINE_OUT &&
4361                     cfg->speaker_outs > 0) {
4362                         /* enable pin-detect for line-outs as well */
4363                         for (i = 0; i < cfg->line_outs; i++) {
4364                                 hda_nid_t nid = cfg->line_out_pins[i];
4365                                 enable_pin_detect(codec, nid, STAC_LO_EVENT);
4366                         }
4367                 }
4368
4369                 /* force to enable the first line-out; the others are set up
4370                  * in unsol_event
4371                  */
4372                 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
4373                                 AC_PINCTL_OUT_EN);
4374                 /* fake event to set up pins */
4375                 if (cfg->hp_pins[0])
4376                         stac_issue_unsol_event(codec, cfg->hp_pins[0]);
4377                 else if (cfg->line_out_pins[0])
4378                         stac_issue_unsol_event(codec, cfg->line_out_pins[0]);
4379         } else {
4380                 stac92xx_auto_init_multi_out(codec);
4381                 stac92xx_auto_init_hp_out(codec);
4382                 for (i = 0; i < cfg->hp_outs; i++)
4383                         stac_toggle_power_map(codec, cfg->hp_pins[i], 1);
4384         }
4385         if (spec->auto_mic) {
4386                 /* initialize connection to analog input */
4387                 if (spec->dmux_nids)
4388                         snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
4389                                           AC_VERB_SET_CONNECT_SEL, 0);
4390                 if (enable_pin_detect(codec, spec->ext_mic.pin, STAC_MIC_EVENT))
4391                         stac_issue_unsol_event(codec, spec->ext_mic.pin);
4392                 if (enable_pin_detect(codec, spec->dock_mic.pin,
4393                     STAC_MIC_EVENT))
4394                         stac_issue_unsol_event(codec, spec->dock_mic.pin);
4395         }
4396         for (i = 0; i < cfg->num_inputs; i++) {
4397                 hda_nid_t nid = cfg->inputs[i].pin;
4398                 int type = cfg->inputs[i].type;
4399                 unsigned int pinctl, conf;
4400                 if (type == AUTO_PIN_MIC) {
4401                         /* for mic pins, force to initialize */
4402                         pinctl = stac92xx_get_default_vref(codec, nid);
4403                         pinctl |= AC_PINCTL_IN_EN;
4404                         stac92xx_auto_set_pinctl(codec, nid, pinctl);
4405                 } else {
4406                         pinctl = snd_hda_codec_read(codec, nid, 0,
4407                                         AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4408                         /* if PINCTL already set then skip */
4409                         /* Also, if both INPUT and OUTPUT are set,
4410                          * it must be a BIOS bug; need to override, too
4411                          */
4412                         if (!(pinctl & AC_PINCTL_IN_EN) ||
4413                             (pinctl & AC_PINCTL_OUT_EN)) {
4414                                 pinctl &= ~AC_PINCTL_OUT_EN;
4415                                 pinctl |= AC_PINCTL_IN_EN;
4416                                 stac92xx_auto_set_pinctl(codec, nid, pinctl);
4417                         }
4418                 }
4419                 conf = snd_hda_codec_get_pincfg(codec, nid);
4420                 if (get_defcfg_connect(conf) != AC_JACK_PORT_FIXED) {
4421                         if (enable_pin_detect(codec, nid, STAC_INSERT_EVENT))
4422                                 stac_issue_unsol_event(codec, nid);
4423                 }
4424         }
4425         for (i = 0; i < spec->num_dmics; i++)
4426                 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
4427                                         AC_PINCTL_IN_EN);
4428         if (cfg->dig_out_pins[0])
4429                 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pins[0],
4430                                          AC_PINCTL_OUT_EN);
4431         if (cfg->dig_in_pin)
4432                 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
4433                                          AC_PINCTL_IN_EN);
4434         for (i = 0; i < spec->num_pwrs; i++)  {
4435                 hda_nid_t nid = spec->pwr_nids[i];
4436                 int pinctl, def_conf;
4437
4438                 /* power on when no jack detection is available */
4439                 /* or when the VREF is used for controlling LED */
4440                 if (!spec->hp_detect ||
4441                     spec->vref_mute_led_nid == nid) {
4442                         stac_toggle_power_map(codec, nid, 1);
4443                         continue;
4444                 }
4445
4446                 if (is_nid_hp_pin(cfg, nid))
4447                         continue; /* already has an unsol event */
4448
4449                 pinctl = snd_hda_codec_read(codec, nid, 0,
4450                                             AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4451                 /* outputs are only ports capable of power management
4452                  * any attempts on powering down a input port cause the
4453                  * referenced VREF to act quirky.
4454                  */
4455                 if (pinctl & AC_PINCTL_IN_EN) {
4456                         stac_toggle_power_map(codec, nid, 1);
4457                         continue;
4458                 }
4459                 def_conf = snd_hda_codec_get_pincfg(codec, nid);
4460                 def_conf = get_defcfg_connect(def_conf);
4461                 /* skip any ports that don't have jacks since presence
4462                  * detection is useless */
4463                 if (def_conf != AC_JACK_PORT_COMPLEX) {
4464                         if (def_conf != AC_JACK_PORT_NONE)
4465                                 stac_toggle_power_map(codec, nid, 1);
4466                         continue;
4467                 }
4468                 if (enable_pin_detect(codec, nid, STAC_PWR_EVENT)) {
4469                         stac_issue_unsol_event(codec, nid);
4470                         continue;
4471                 }
4472                 /* none of the above, turn the port OFF */
4473                 stac_toggle_power_map(codec, nid, 0);
4474         }
4475
4476         /* sync mute LED */
4477         if (spec->gpio_led)
4478                 hda_call_check_power_status(codec, 0x01);
4479         if (spec->dac_list)
4480                 stac92xx_power_down(codec);
4481         return 0;
4482 }
4483
4484 static void stac92xx_free_kctls(struct hda_codec *codec)
4485 {
4486         struct sigmatel_spec *spec = codec->spec;
4487
4488         if (spec->kctls.list) {
4489                 struct snd_kcontrol_new *kctl = spec->kctls.list;
4490                 int i;
4491                 for (i = 0; i < spec->kctls.used; i++)
4492                         kfree(kctl[i].name);
4493         }
4494         snd_array_free(&spec->kctls);
4495 }
4496
4497 static void stac92xx_shutup_pins(struct hda_codec *codec)
4498 {
4499         unsigned int i, def_conf;
4500
4501         if (codec->bus->shutdown)
4502                 return;
4503         for (i = 0; i < codec->init_pins.used; i++) {
4504                 struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i);
4505                 def_conf = snd_hda_codec_get_pincfg(codec, pin->nid);
4506                 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)
4507                         snd_hda_codec_write(codec, pin->nid, 0,
4508                                     AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
4509         }
4510 }
4511
4512 static void stac92xx_shutup(struct hda_codec *codec)
4513 {
4514         struct sigmatel_spec *spec = codec->spec;
4515
4516         stac92xx_shutup_pins(codec);
4517
4518         if (spec->eapd_mask)
4519                 stac_gpio_set(codec, spec->gpio_mask,
4520                                 spec->gpio_dir, spec->gpio_data &
4521                                 ~spec->eapd_mask);
4522 }
4523
4524 static void stac92xx_free(struct hda_codec *codec)
4525 {
4526         struct sigmatel_spec *spec = codec->spec;
4527
4528         if (! spec)
4529                 return;
4530
4531         stac92xx_shutup(codec);
4532         snd_hda_input_jack_free(codec);
4533         snd_array_free(&spec->events);
4534
4535         kfree(spec);
4536         snd_hda_detach_beep_device(codec);
4537 }
4538
4539 static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
4540                                 unsigned int flag)
4541 {
4542         unsigned int old_ctl, pin_ctl;
4543
4544         pin_ctl = snd_hda_codec_read(codec, nid,
4545                         0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
4546
4547         if (pin_ctl & AC_PINCTL_IN_EN) {
4548                 /*
4549                  * we need to check the current set-up direction of
4550                  * shared input pins since they can be switched via
4551                  * "xxx as Output" mixer switch
4552                  */
4553                 struct sigmatel_spec *spec = codec->spec;
4554                 if (nid == spec->line_switch || nid == spec->mic_switch)
4555                         return;
4556         }
4557
4558         old_ctl = pin_ctl;
4559         /* if setting pin direction bits, clear the current
4560            direction bits first */
4561         if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
4562                 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
4563         
4564         pin_ctl |= flag;
4565         if (old_ctl != pin_ctl)
4566                 snd_hda_codec_write_cache(codec, nid, 0,
4567                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
4568                                           pin_ctl);
4569 }
4570
4571 static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
4572                                   unsigned int flag)
4573 {
4574         unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
4575                         0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
4576         if (pin_ctl & flag)
4577                 snd_hda_codec_write_cache(codec, nid, 0,
4578                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
4579                                           pin_ctl & ~flag);
4580 }
4581
4582 static inline int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
4583 {
4584         if (!nid)
4585                 return 0;
4586         return snd_hda_jack_detect(codec, nid);
4587 }
4588
4589 static void stac92xx_line_out_detect(struct hda_codec *codec,
4590                                      int presence)
4591 {
4592         struct sigmatel_spec *spec = codec->spec;
4593         struct auto_pin_cfg *cfg = &spec->autocfg;
4594         int i;
4595
4596         for (i = 0; i < cfg->line_outs; i++) {
4597                 if (presence)
4598                         break;
4599                 presence = get_pin_presence(codec, cfg->line_out_pins[i]);
4600                 if (presence) {
4601                         unsigned int pinctl;
4602                         pinctl = snd_hda_codec_read(codec,
4603                                                     cfg->line_out_pins[i], 0,
4604                                             AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4605                         if (pinctl & AC_PINCTL_IN_EN)
4606                                 presence = 0; /* mic- or line-input */
4607                 }
4608         }
4609
4610         if (presence) {
4611                 /* disable speakers */
4612                 for (i = 0; i < cfg->speaker_outs; i++)
4613                         stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
4614                                                 AC_PINCTL_OUT_EN);
4615                 if (spec->eapd_mask && spec->eapd_switch)
4616                         stac_gpio_set(codec, spec->gpio_mask,
4617                                 spec->gpio_dir, spec->gpio_data &
4618                                 ~spec->eapd_mask);
4619         } else {
4620                 /* enable speakers */
4621                 for (i = 0; i < cfg->speaker_outs; i++)
4622                         stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
4623                                                 AC_PINCTL_OUT_EN);
4624                 if (spec->eapd_mask && spec->eapd_switch)
4625                         stac_gpio_set(codec, spec->gpio_mask,
4626                                 spec->gpio_dir, spec->gpio_data |
4627                                 spec->eapd_mask);
4628         }
4629
4630
4631 /* return non-zero if the hp-pin of the given array index isn't
4632  * a jack-detection target
4633  */
4634 static int no_hp_sensing(struct sigmatel_spec *spec, int i)
4635 {
4636         struct auto_pin_cfg *cfg = &spec->autocfg;
4637
4638         /* ignore sensing of shared line and mic jacks */
4639         if (cfg->hp_pins[i] == spec->line_switch)
4640                 return 1;
4641         if (cfg->hp_pins[i] == spec->mic_switch)
4642                 return 1;
4643         /* ignore if the pin is set as line-out */
4644         if (cfg->hp_pins[i] == spec->hp_switch)
4645                 return 1;
4646         return 0;
4647 }
4648
4649 static void stac92xx_hp_detect(struct hda_codec *codec)
4650 {
4651         struct sigmatel_spec *spec = codec->spec;
4652         struct auto_pin_cfg *cfg = &spec->autocfg;
4653         int i, presence;
4654
4655         presence = 0;
4656         if (spec->gpio_mute)
4657                 presence = !(snd_hda_codec_read(codec, codec->afg, 0,
4658                         AC_VERB_GET_GPIO_DATA, 0) & spec->gpio_mute);
4659
4660         for (i = 0; i < cfg->hp_outs; i++) {
4661                 if (presence)
4662                         break;
4663                 if (no_hp_sensing(spec, i))
4664                         continue;
4665                 presence = get_pin_presence(codec, cfg->hp_pins[i]);
4666                 if (presence) {
4667                         unsigned int pinctl;
4668                         pinctl = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
4669                                             AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4670                         if (pinctl & AC_PINCTL_IN_EN)
4671                                 presence = 0; /* mic- or line-input */
4672                 }
4673         }
4674
4675         if (presence) {
4676                 /* disable lineouts */
4677                 if (spec->hp_switch)
4678                         stac92xx_reset_pinctl(codec, spec->hp_switch,
4679                                               AC_PINCTL_OUT_EN);
4680                 for (i = 0; i < cfg->line_outs; i++)
4681                         stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
4682                                                 AC_PINCTL_OUT_EN);
4683         } else {
4684                 /* enable lineouts */
4685                 if (spec->hp_switch)
4686                         stac92xx_set_pinctl(codec, spec->hp_switch,
4687                                             AC_PINCTL_OUT_EN);
4688                 for (i = 0; i < cfg->line_outs; i++)
4689                         stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
4690                                                 AC_PINCTL_OUT_EN);
4691         }
4692         stac92xx_line_out_detect(codec, presence);
4693         /* toggle hp outs */
4694         for (i = 0; i < cfg->hp_outs; i++) {
4695                 unsigned int val = AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN;
4696                 if (no_hp_sensing(spec, i))
4697                         continue;
4698                 if (presence)
4699                         stac92xx_set_pinctl(codec, cfg->hp_pins[i], val);
4700 #if 0 /* FIXME */
4701 /* Resetting the pinctl like below may lead to (a sort of) regressions
4702  * on some devices since they use the HP pin actually for line/speaker
4703  * outs although the default pin config shows a different pin (that is
4704  * wrong and useless).
4705  *
4706  * So, it's basically a problem of default pin configs, likely a BIOS issue.
4707  * But, disabling the code below just works around it, and I'm too tired of
4708  * bug reports with such devices... 
4709  */
4710                 else
4711                         stac92xx_reset_pinctl(codec, cfg->hp_pins[i], val);
4712 #endif /* FIXME */
4713         }
4714
4715
4716 static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4717                                   int enable)
4718 {
4719         struct sigmatel_spec *spec = codec->spec;
4720         unsigned int idx, val;
4721
4722         for (idx = 0; idx < spec->num_pwrs; idx++) {
4723                 if (spec->pwr_nids[idx] == nid)
4724                         break;
4725         }
4726         if (idx >= spec->num_pwrs)
4727                 return;
4728
4729         idx = 1 << idx;
4730
4731         val = snd_hda_codec_read(codec, codec->afg, 0, 0x0fec, 0x0) & 0xff;
4732         if (enable)
4733                 val &= ~idx;
4734         else
4735                 val |= idx;
4736
4737         /* power down unused output ports */
4738         snd_hda_codec_write(codec, codec->afg, 0, 0x7ec, val);
4739 }
4740
4741 static void stac92xx_pin_sense(struct hda_codec *codec, hda_nid_t nid)
4742 {
4743         stac_toggle_power_map(codec, nid, get_pin_presence(codec, nid));
4744 }
4745
4746 /* get the pin connection (fixed, none, etc) */
4747 static unsigned int stac_get_defcfg_connect(struct hda_codec *codec, int idx)
4748 {
4749         struct sigmatel_spec *spec = codec->spec;
4750         unsigned int cfg;
4751
4752         cfg = snd_hda_codec_get_pincfg(codec, spec->pin_nids[idx]);
4753         return get_defcfg_connect(cfg);
4754 }
4755
4756 static int stac92xx_connected_ports(struct hda_codec *codec,
4757                                     const hda_nid_t *nids, int num_nids)
4758 {
4759         struct sigmatel_spec *spec = codec->spec;
4760         int idx, num;
4761         unsigned int def_conf;
4762
4763         for (num = 0; num < num_nids; num++) {
4764                 for (idx = 0; idx < spec->num_pins; idx++)
4765                         if (spec->pin_nids[idx] == nids[num])
4766                                 break;
4767                 if (idx >= spec->num_pins)
4768                         break;
4769                 def_conf = stac_get_defcfg_connect(codec, idx);
4770                 if (def_conf == AC_JACK_PORT_NONE)
4771                         break;
4772         }
4773         return num;
4774 }
4775
4776 static void stac92xx_mic_detect(struct hda_codec *codec)
4777 {
4778         struct sigmatel_spec *spec = codec->spec;
4779         struct sigmatel_mic_route *mic;
4780
4781         if (get_pin_presence(codec, spec->ext_mic.pin))
4782                 mic = &spec->ext_mic;
4783         else if (get_pin_presence(codec, spec->dock_mic.pin))
4784                 mic = &spec->dock_mic;
4785         else
4786                 mic = &spec->int_mic;
4787         if (mic->dmux_idx >= 0)
4788                 snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
4789                                           AC_VERB_SET_CONNECT_SEL,
4790                                           mic->dmux_idx);
4791         if (mic->mux_idx >= 0)
4792                 snd_hda_codec_write_cache(codec, spec->mux_nids[0], 0,
4793                                           AC_VERB_SET_CONNECT_SEL,
4794                                           mic->mux_idx);
4795 }
4796
4797 static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid)
4798 {
4799         struct sigmatel_event *event = stac_get_event(codec, nid);
4800         if (!event)
4801                 return;
4802         codec->patch_ops.unsol_event(codec, (unsigned)event->tag << 26);
4803 }
4804
4805 static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
4806 {
4807         struct sigmatel_spec *spec = codec->spec;
4808         struct sigmatel_event *event;
4809         int tag, data;
4810
4811         tag = (res >> 26) & 0x7f;
4812         event = stac_get_event_from_tag(codec, tag);
4813         if (!event)
4814                 return;
4815
4816         switch (event->type) {
4817         case STAC_HP_EVENT:
4818         case STAC_LO_EVENT:
4819                 stac92xx_hp_detect(codec);
4820                 break;
4821         case STAC_MIC_EVENT:
4822                 stac92xx_mic_detect(codec);
4823                 break;
4824         }
4825
4826         switch (event->type) {
4827         case STAC_HP_EVENT:
4828         case STAC_LO_EVENT:
4829         case STAC_MIC_EVENT:
4830         case STAC_INSERT_EVENT:
4831         case STAC_PWR_EVENT:
4832                 if (spec->num_pwrs > 0)
4833                         stac92xx_pin_sense(codec, event->nid);
4834                 snd_hda_input_jack_report(codec, event->nid);
4835
4836                 switch (codec->subsystem_id) {
4837                 case 0x103c308f:
4838                         if (event->nid == 0xb) {
4839                                 int pin = AC_PINCTL_IN_EN;
4840
4841                                 if (get_pin_presence(codec, 0xa)
4842                                                 && get_pin_presence(codec, 0xb))
4843                                         pin |= AC_PINCTL_VREF_80;
4844                                 if (!get_pin_presence(codec, 0xb))
4845                                         pin |= AC_PINCTL_VREF_80;
4846
4847                                 /* toggle VREF state based on mic + hp pin
4848                                  * status
4849                                  */
4850                                 stac92xx_auto_set_pinctl(codec, 0x0a, pin);
4851                         }
4852                 }
4853                 break;
4854         case STAC_VREF_EVENT:
4855                 data = snd_hda_codec_read(codec, codec->afg, 0,
4856                                           AC_VERB_GET_GPIO_DATA, 0);
4857                 /* toggle VREF state based on GPIOx status */
4858                 snd_hda_codec_write(codec, codec->afg, 0, 0x7e0,
4859                                     !!(data & (1 << event->data)));
4860                 break;
4861         }
4862 }
4863
4864 static int hp_blike_system(u32 subsystem_id);
4865
4866 static void set_hp_led_gpio(struct hda_codec *codec)
4867 {
4868         struct sigmatel_spec *spec = codec->spec;
4869         unsigned int gpio;
4870
4871         if (spec->gpio_led)
4872                 return;
4873
4874         gpio = snd_hda_param_read(codec, codec->afg, AC_PAR_GPIO_CAP);
4875         gpio &= AC_GPIO_IO_COUNT;
4876         if (gpio > 3)
4877                 spec->gpio_led = 0x08; /* GPIO 3 */
4878         else
4879                 spec->gpio_led = 0x01; /* GPIO 0 */
4880 }
4881
4882 /*
4883  * This method searches for the mute LED GPIO configuration
4884  * provided as OEM string in SMBIOS. The format of that string
4885  * is HP_Mute_LED_P_G or HP_Mute_LED_P
4886  * where P can be 0 or 1 and defines mute LED GPIO control state (low/high)
4887  * that corresponds to the NOT muted state of the master volume
4888  * and G is the index of the GPIO to use as the mute LED control (0..9)
4889  * If _G portion is missing it is assigned based on the codec ID
4890  *
4891  * So, HP B-series like systems may have HP_Mute_LED_0 (current models)
4892  * or  HP_Mute_LED_0_3 (future models) OEM SMBIOS strings
4893  *
4894  *
4895  * The dv-series laptops don't seem to have the HP_Mute_LED* strings in
4896  * SMBIOS - at least the ones I have seen do not have them - which include
4897  * my own system (HP Pavilion dv6-1110ax) and my cousin's
4898  * HP Pavilion dv9500t CTO.
4899  * Need more information on whether it is true across the entire series.
4900  * -- kunal
4901  */
4902 static int find_mute_led_cfg(struct hda_codec *codec, int default_polarity)
4903 {
4904         struct sigmatel_spec *spec = codec->spec;
4905         const struct dmi_device *dev = NULL;
4906
4907         if ((codec->subsystem_id >> 16) == PCI_VENDOR_ID_HP) {
4908                 while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING,
4909                                                                 NULL, dev))) {
4910                         if (sscanf(dev->name, "HP_Mute_LED_%d_%x",
4911                                   &spec->gpio_led_polarity,
4912                                   &spec->gpio_led) == 2) {
4913                                 unsigned int max_gpio;
4914                                 max_gpio = snd_hda_param_read(codec, codec->afg,
4915                                                               AC_PAR_GPIO_CAP);
4916                                 max_gpio &= AC_GPIO_IO_COUNT;
4917                                 if (spec->gpio_led < max_gpio)
4918                                         spec->gpio_led = 1 << spec->gpio_led;
4919                                 else
4920                                         spec->vref_mute_led_nid = spec->gpio_led;
4921                                 return 1;
4922                         }
4923                         if (sscanf(dev->name, "HP_Mute_LED_%d",
4924                                   &spec->gpio_led_polarity) == 1) {
4925                                 set_hp_led_gpio(codec);
4926                                 return 1;
4927                         }
4928                 }
4929
4930                 /*
4931                  * Fallback case - if we don't find the DMI strings,
4932                  * we statically set the GPIO - if not a B-series system
4933                  * and default polarity is provided
4934                  */
4935                 if (!hp_blike_system(codec->subsystem_id) &&
4936                         (default_polarity == 0 || default_polarity == 1)) {
4937                         set_hp_led_gpio(codec);
4938                         spec->gpio_led_polarity = default_polarity;
4939                         return 1;
4940                 }
4941         }
4942         return 0;
4943 }
4944
4945 static int hp_blike_system(u32 subsystem_id)
4946 {
4947         switch (subsystem_id) {
4948         case 0x103c1520:
4949         case 0x103c1521:
4950         case 0x103c1523:
4951         case 0x103c1524:
4952         case 0x103c1525:
4953         case 0x103c1722:
4954         case 0x103c1723:
4955         case 0x103c1724:
4956         case 0x103c1725:
4957         case 0x103c1726:
4958         case 0x103c1727:
4959         case 0x103c1728:
4960         case 0x103c1729:
4961         case 0x103c172a:
4962         case 0x103c172b:
4963         case 0x103c307e:
4964         case 0x103c307f:
4965         case 0x103c3080:
4966         case 0x103c3081:
4967         case 0x103c7007:
4968         case 0x103c7008:
4969                 return 1;
4970         }
4971         return 0;
4972 }
4973
4974 #ifdef CONFIG_PROC_FS
4975 static void stac92hd_proc_hook(struct snd_info_buffer *buffer,
4976                                struct hda_codec *codec, hda_nid_t nid)
4977 {
4978         if (nid == codec->afg)
4979                 snd_iprintf(buffer, "Power-Map: 0x%02x\n", 
4980                             snd_hda_codec_read(codec, nid, 0, 0x0fec, 0x0));
4981 }
4982
4983 static void analog_loop_proc_hook(struct snd_info_buffer *buffer,
4984                                   struct hda_codec *codec,
4985                                   unsigned int verb)
4986 {
4987         snd_iprintf(buffer, "Analog Loopback: 0x%02x\n",
4988                     snd_hda_codec_read(codec, codec->afg, 0, verb, 0));
4989 }
4990
4991 /* stac92hd71bxx, stac92hd73xx */
4992 static void stac92hd7x_proc_hook(struct snd_info_buffer *buffer,
4993                                  struct hda_codec *codec, hda_nid_t nid)
4994 {
4995         stac92hd_proc_hook(buffer, codec, nid);
4996         if (nid == codec->afg)
4997                 analog_loop_proc_hook(buffer, codec, 0xfa0);
4998 }
4999
5000 static void stac9205_proc_hook(struct snd_info_buffer *buffer,
5001                                struct hda_codec *codec, hda_nid_t nid)
5002 {
5003         if (nid == codec->afg)
5004                 analog_loop_proc_hook(buffer, codec, 0xfe0);
5005 }
5006
5007 static void stac927x_proc_hook(struct snd_info_buffer *buffer,
5008                                struct hda_codec *codec, hda_nid_t nid)
5009 {
5010         if (nid == codec->afg)
5011                 analog_loop_proc_hook(buffer, codec, 0xfeb);
5012 }
5013 #else
5014 #define stac92hd_proc_hook      NULL
5015 #define stac92hd7x_proc_hook    NULL
5016 #define stac9205_proc_hook      NULL
5017 #define stac927x_proc_hook      NULL
5018 #endif
5019
5020 #ifdef CONFIG_PM
5021 static int stac92xx_resume(struct hda_codec *codec)
5022 {
5023         struct sigmatel_spec *spec = codec->spec;
5024
5025         stac92xx_init(codec);
5026         snd_hda_codec_resume_amp(codec);
5027         snd_hda_codec_resume_cache(codec);
5028         /* fake event to set up pins again to override cached values */
5029         if (spec->hp_detect) {
5030                 if (spec->autocfg.hp_pins[0])
5031                         stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0]);
5032                 else if (spec->autocfg.line_out_pins[0])
5033                         stac_issue_unsol_event(codec,
5034                                                spec->autocfg.line_out_pins[0]);
5035         }
5036         return 0;
5037 }
5038
5039 static int stac92xx_suspend(struct hda_codec *codec, pm_message_t state)
5040 {
5041         stac92xx_shutup(codec);
5042         return 0;
5043 }
5044
5045 #ifdef CONFIG_SND_HDA_POWER_SAVE
5046 static int stac92xx_pre_resume(struct hda_codec *codec)
5047 {
5048         struct sigmatel_spec *spec = codec->spec;
5049
5050         /* sync mute LED */
5051         if (spec->vref_mute_led_nid)
5052                 stac_vrefout_set(codec, spec->vref_mute_led_nid,
5053                                  spec->vref_led);
5054         else if (spec->gpio_led)
5055                 stac_gpio_set(codec, spec->gpio_mask,
5056                               spec->gpio_dir, spec->gpio_data);
5057         return 0;
5058 }
5059
5060 static void stac92xx_set_power_state(struct hda_codec *codec, hda_nid_t fg,
5061                                 unsigned int power_state)
5062 {
5063         unsigned int afg_power_state = power_state;
5064         struct sigmatel_spec *spec = codec->spec;
5065
5066         if (power_state == AC_PWRST_D3) {
5067                 if (spec->vref_mute_led_nid) {
5068                         /* with vref-out pin used for mute led control
5069                          * codec AFG is prevented from D3 state
5070                          */
5071                         afg_power_state = AC_PWRST_D1;
5072                 }
5073                 /* this delay seems necessary to avoid click noise at power-down */
5074                 msleep(100);
5075         }
5076         snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE,
5077                         afg_power_state);
5078         snd_hda_codec_set_power_to_all(codec, fg, power_state, true);
5079 }
5080
5081 /*
5082  * For this feature CONFIG_SND_HDA_POWER_SAVE is needed
5083  * as mute LED state is updated in check_power_status hook
5084  */
5085 static int stac92xx_update_led_status(struct hda_codec *codec)
5086 {
5087         struct sigmatel_spec *spec = codec->spec;
5088         int i, num_ext_dacs, muted = 1;
5089         unsigned int muted_lvl, notmtd_lvl;
5090         hda_nid_t nid;
5091
5092         if (!spec->gpio_led)
5093                 return 0;
5094
5095         for (i = 0; i < spec->multiout.num_dacs; i++) {
5096                 nid = spec->multiout.dac_nids[i];
5097                 if (!(snd_hda_codec_amp_read(codec, nid, 0, HDA_OUTPUT, 0) &
5098                       HDA_AMP_MUTE)) {
5099                         muted = 0; /* something heard */
5100                         break;
5101                 }
5102         }
5103         if (muted && spec->multiout.hp_nid)
5104                 if (!(snd_hda_codec_amp_read(codec,
5105                                 spec->multiout.hp_nid, 0, HDA_OUTPUT, 0) &
5106                                         HDA_AMP_MUTE)) {
5107                         muted = 0; /* HP is not muted */
5108                 }
5109         num_ext_dacs = ARRAY_SIZE(spec->multiout.extra_out_nid);
5110         for (i = 0; muted && i < num_ext_dacs; i++) {
5111                 nid = spec->multiout.extra_out_nid[i];
5112                 if (nid == 0)
5113                         break;
5114                 if (!(snd_hda_codec_amp_read(codec, nid, 0, HDA_OUTPUT, 0) &
5115                       HDA_AMP_MUTE)) {
5116                         muted = 0; /* extra output is not muted */
5117                 }
5118         }
5119         /*polarity defines *not* muted state level*/
5120         if (!spec->vref_mute_led_nid) {
5121                 if (muted)
5122                         spec->gpio_data &= ~spec->gpio_led; /* orange */
5123                 else
5124                         spec->gpio_data |= spec->gpio_led; /* white */
5125
5126                 if (!spec->gpio_led_polarity) {
5127                         /* LED state is inverted on these systems */
5128                         spec->gpio_data ^= spec->gpio_led;
5129                 }
5130                 stac_gpio_set(codec, spec->gpio_mask,
5131                                 spec->gpio_dir, spec->gpio_data);
5132         } else {
5133                 notmtd_lvl = spec->gpio_led_polarity ?
5134                                 AC_PINCTL_VREF_HIZ : AC_PINCTL_VREF_GRD;
5135                 muted_lvl = spec->gpio_led_polarity ?
5136                                 AC_PINCTL_VREF_GRD : AC_PINCTL_VREF_HIZ;
5137                 spec->vref_led = muted ? muted_lvl : notmtd_lvl;
5138                 stac_vrefout_set(codec, spec->vref_mute_led_nid,
5139                                  spec->vref_led);
5140         }
5141         return 0;
5142 }
5143
5144 /*
5145  * use power check for controlling mute led of HP notebooks
5146  */
5147 static int stac92xx_check_power_status(struct hda_codec *codec,
5148                                               hda_nid_t nid)
5149 {
5150         stac92xx_update_led_status(codec);
5151
5152         return 0;
5153 }
5154 #endif /* CONFIG_SND_HDA_POWER_SAVE */
5155 #endif /* CONFIG_PM */
5156
5157 static const struct hda_codec_ops stac92xx_patch_ops = {
5158         .build_controls = stac92xx_build_controls,
5159         .build_pcms = stac92xx_build_pcms,
5160         .init = stac92xx_init,
5161         .free = stac92xx_free,
5162         .unsol_event = stac92xx_unsol_event,
5163 #ifdef CONFIG_PM
5164         .suspend = stac92xx_suspend,
5165         .resume = stac92xx_resume,
5166 #endif
5167         .reboot_notify = stac92xx_shutup,
5168 };
5169
5170 static int patch_stac9200(struct hda_codec *codec)
5171 {
5172         struct sigmatel_spec *spec;
5173         int err;
5174
5175         spec  = kzalloc(sizeof(*spec), GFP_KERNEL);
5176         if (spec == NULL)
5177                 return -ENOMEM;
5178
5179         codec->no_trigger_sense = 1;
5180         codec->spec = spec;
5181         spec->linear_tone_beep = 1;
5182         spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
5183         spec->pin_nids = stac9200_pin_nids;
5184         spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
5185                                                         stac9200_models,
5186                                                         stac9200_cfg_tbl);
5187         if (spec->board_config < 0)
5188                 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5189                             codec->chip_name);
5190         else
5191                 stac92xx_set_config_regs(codec,
5192                                          stac9200_brd_tbl[spec->board_config]);
5193
5194         spec->multiout.max_channels = 2;
5195         spec->multiout.num_dacs = 1;
5196         spec->multiout.dac_nids = stac9200_dac_nids;
5197         spec->adc_nids = stac9200_adc_nids;
5198         spec->mux_nids = stac9200_mux_nids;
5199         spec->num_muxes = 1;
5200         spec->num_dmics = 0;
5201         spec->num_adcs = 1;
5202         spec->num_pwrs = 0;
5203
5204         if (spec->board_config == STAC_9200_M4 ||
5205             spec->board_config == STAC_9200_M4_2 ||
5206             spec->board_config == STAC_9200_OQO)
5207                 spec->init = stac9200_eapd_init;
5208         else
5209                 spec->init = stac9200_core_init;
5210         spec->mixer = stac9200_mixer;
5211
5212         if (spec->board_config == STAC_9200_PANASONIC) {
5213                 spec->gpio_mask = spec->gpio_dir = 0x09;
5214                 spec->gpio_data = 0x00;
5215         }
5216
5217         err = stac9200_parse_auto_config(codec);
5218         if (err < 0) {
5219                 stac92xx_free(codec);
5220                 return err;
5221         }
5222
5223         /* CF-74 has no headphone detection, and the driver should *NOT*
5224          * do detection and HP/speaker toggle because the hardware does it.
5225          */
5226         if (spec->board_config == STAC_9200_PANASONIC)
5227                 spec->hp_detect = 0;
5228
5229         codec->patch_ops = stac92xx_patch_ops;
5230
5231         return 0;
5232 }
5233
5234 static int patch_stac925x(struct hda_codec *codec)
5235 {
5236         struct sigmatel_spec *spec;
5237         int err;
5238
5239         spec  = kzalloc(sizeof(*spec), GFP_KERNEL);
5240         if (spec == NULL)
5241                 return -ENOMEM;
5242
5243         codec->no_trigger_sense = 1;
5244         codec->spec = spec;
5245         spec->linear_tone_beep = 1;
5246         spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
5247         spec->pin_nids = stac925x_pin_nids;
5248
5249         /* Check first for codec ID */
5250         spec->board_config = snd_hda_check_board_codec_sid_config(codec,
5251                                                         STAC_925x_MODELS,
5252                                                         stac925x_models,
5253                                                         stac925x_codec_id_cfg_tbl);
5254
5255         /* Now checks for PCI ID, if codec ID is not found */
5256         if (spec->board_config < 0)
5257                 spec->board_config = snd_hda_check_board_config(codec,
5258                                                         STAC_925x_MODELS,
5259                                                         stac925x_models,
5260                                                         stac925x_cfg_tbl);
5261  again:
5262         if (spec->board_config < 0)
5263                 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5264                             codec->chip_name);
5265         else
5266                 stac92xx_set_config_regs(codec,
5267                                          stac925x_brd_tbl[spec->board_config]);
5268
5269         spec->multiout.max_channels = 2;
5270         spec->multiout.num_dacs = 1;
5271         spec->multiout.dac_nids = stac925x_dac_nids;
5272         spec->adc_nids = stac925x_adc_nids;
5273         spec->mux_nids = stac925x_mux_nids;
5274         spec->num_muxes = 1;
5275         spec->num_adcs = 1;
5276         spec->num_pwrs = 0;
5277         switch (codec->vendor_id) {
5278         case 0x83847632: /* STAC9202  */
5279         case 0x83847633: /* STAC9202D */
5280         case 0x83847636: /* STAC9251  */
5281         case 0x83847637: /* STAC9251D */
5282                 spec->num_dmics = STAC925X_NUM_DMICS;
5283                 spec->dmic_nids = stac925x_dmic_nids;
5284                 spec->num_dmuxes = ARRAY_SIZE(stac925x_dmux_nids);
5285                 spec->dmux_nids = stac925x_dmux_nids;
5286                 break;
5287         default:
5288                 spec->num_dmics = 0;
5289                 break;
5290         }
5291
5292         spec->init = stac925x_core_init;
5293         spec->mixer = stac925x_mixer;
5294         spec->num_caps = 1;
5295         spec->capvols = stac925x_capvols;
5296         spec->capsws = stac925x_capsws;
5297
5298         err = stac92xx_parse_auto_config(codec);
5299         if (!err) {
5300                 if (spec->board_config < 0) {
5301                         printk(KERN_WARNING "hda_codec: No auto-config is "
5302                                "available, default to model=ref\n");
5303                         spec->board_config = STAC_925x_REF;
5304                         goto again;
5305                 }
5306                 err = -EINVAL;
5307         }
5308         if (err < 0) {
5309                 stac92xx_free(codec);
5310                 return err;
5311         }
5312
5313         codec->patch_ops = stac92xx_patch_ops;
5314
5315         return 0;
5316 }
5317
5318 static int patch_stac92hd73xx(struct hda_codec *codec)
5319 {
5320         struct sigmatel_spec *spec;
5321         hda_nid_t conn[STAC92HD73_DAC_COUNT + 2];
5322         int err = 0;
5323         int num_dacs;
5324
5325         spec  = kzalloc(sizeof(*spec), GFP_KERNEL);
5326         if (spec == NULL)
5327                 return -ENOMEM;
5328
5329         codec->no_trigger_sense = 1;
5330         codec->spec = spec;
5331         spec->linear_tone_beep = 0;
5332         codec->slave_dig_outs = stac92hd73xx_slave_dig_outs;
5333         spec->num_pins = ARRAY_SIZE(stac92hd73xx_pin_nids);
5334         spec->pin_nids = stac92hd73xx_pin_nids;
5335         spec->board_config = snd_hda_check_board_config(codec,
5336                                                         STAC_92HD73XX_MODELS,
5337                                                         stac92hd73xx_models,
5338                                                         stac92hd73xx_cfg_tbl);
5339         /* check codec subsystem id if not found */
5340         if (spec->board_config < 0)
5341                 spec->board_config =
5342                         snd_hda_check_board_codec_sid_config(codec,
5343                                 STAC_92HD73XX_MODELS, stac92hd73xx_models,
5344                                 stac92hd73xx_codec_id_cfg_tbl);
5345 again:
5346         if (spec->board_config < 0)
5347                 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5348                             codec->chip_name);
5349         else
5350                 stac92xx_set_config_regs(codec,
5351                                 stac92hd73xx_brd_tbl[spec->board_config]);
5352
5353         num_dacs = snd_hda_get_connections(codec, 0x0a,
5354                         conn, STAC92HD73_DAC_COUNT + 2) - 1;
5355
5356         if (num_dacs < 3 || num_dacs > 5) {
5357                 printk(KERN_WARNING "hda_codec: Could not determine "
5358                        "number of channels defaulting to DAC count\n");
5359                 num_dacs = STAC92HD73_DAC_COUNT;
5360         }
5361         spec->init = stac92hd73xx_core_init;
5362         switch (num_dacs) {
5363         case 0x3: /* 6 Channel */
5364                 spec->aloopback_ctl = stac92hd73xx_6ch_loopback;
5365                 break;
5366         case 0x4: /* 8 Channel */
5367                 spec->aloopback_ctl = stac92hd73xx_8ch_loopback;
5368                 break;
5369         case 0x5: /* 10 Channel */
5370                 spec->aloopback_ctl = stac92hd73xx_10ch_loopback;
5371                 break;
5372         }
5373         spec->multiout.dac_nids = spec->dac_nids;
5374
5375         spec->aloopback_mask = 0x01;
5376         spec->aloopback_shift = 8;
5377
5378         spec->digbeep_nid = 0x1c;
5379         spec->mux_nids = stac92hd73xx_mux_nids;
5380         spec->adc_nids = stac92hd73xx_adc_nids;
5381         spec->dmic_nids = stac92hd73xx_dmic_nids;
5382         spec->dmux_nids = stac92hd73xx_dmux_nids;
5383         spec->smux_nids = stac92hd73xx_smux_nids;
5384
5385         spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids);
5386         spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids);
5387         spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids);
5388
5389         spec->num_caps = STAC92HD73XX_NUM_CAPS;
5390         spec->capvols = stac92hd73xx_capvols;
5391         spec->capsws = stac92hd73xx_capsws;
5392
5393         switch (spec->board_config) {
5394         case STAC_DELL_EQ:
5395                 spec->init = dell_eq_core_init;
5396                 /* fallthru */
5397         case STAC_DELL_M6_AMIC:
5398         case STAC_DELL_M6_DMIC:
5399         case STAC_DELL_M6_BOTH:
5400                 spec->num_smuxes = 0;
5401                 spec->eapd_switch = 0;
5402
5403                 switch (spec->board_config) {
5404                 case STAC_DELL_M6_AMIC: /* Analog Mics */
5405                         snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
5406                         spec->num_dmics = 0;
5407                         break;
5408                 case STAC_DELL_M6_DMIC: /* Digital Mics */
5409                         snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
5410                         spec->num_dmics = 1;
5411                         break;
5412                 case STAC_DELL_M6_BOTH: /* Both */
5413                         snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
5414                         snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
5415                         spec->num_dmics = 1;
5416                         break;
5417                 }
5418                 break;
5419         case STAC_ALIENWARE_M17X:
5420                 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
5421                 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
5422                 spec->eapd_switch = 0;
5423                 break;
5424         default:
5425                 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
5426                 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
5427                 spec->eapd_switch = 1;
5428                 break;
5429         }
5430         if (spec->board_config != STAC_92HD73XX_REF) {
5431                 /* GPIO0 High = Enable EAPD */
5432                 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
5433                 spec->gpio_data = 0x01;
5434         }
5435
5436         spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
5437         spec->pwr_nids = stac92hd73xx_pwr_nids;
5438
5439         err = stac92xx_parse_auto_config(codec);
5440
5441         if (!err) {
5442                 if (spec->board_config < 0) {
5443                         printk(KERN_WARNING "hda_codec: No auto-config is "
5444                                "available, default to model=ref\n");
5445                         spec->board_config = STAC_92HD73XX_REF;
5446                         goto again;
5447                 }
5448                 err = -EINVAL;
5449         }
5450
5451         if (err < 0) {
5452                 stac92xx_free(codec);
5453                 return err;
5454         }
5455
5456         if (spec->board_config == STAC_92HD73XX_NO_JD)
5457                 spec->hp_detect = 0;
5458
5459         codec->patch_ops = stac92xx_patch_ops;
5460
5461         codec->proc_widget_hook = stac92hd7x_proc_hook;
5462
5463         return 0;
5464 }
5465
5466 static int hp_bnb2011_with_dock(struct hda_codec *codec)
5467 {
5468         if (codec->vendor_id != 0x111d7605 &&
5469             codec->vendor_id != 0x111d76d1)
5470                 return 0;
5471
5472         switch (codec->subsystem_id) {
5473         case 0x103c1618:
5474         case 0x103c1619:
5475         case 0x103c161a:
5476         case 0x103c161b:
5477         case 0x103c161c:
5478         case 0x103c161d:
5479         case 0x103c161e:
5480         case 0x103c161f:
5481
5482         case 0x103c162a:
5483         case 0x103c162b:
5484
5485         case 0x103c1630:
5486         case 0x103c1631:
5487
5488         case 0x103c1633:
5489         case 0x103c1634:
5490         case 0x103c1635:
5491
5492         case 0x103c3587:
5493         case 0x103c3588:
5494         case 0x103c3589:
5495         case 0x103c358a:
5496
5497         case 0x103c3667:
5498         case 0x103c3668:
5499         case 0x103c3669:
5500
5501                 return 1;
5502         }
5503         return 0;
5504 }
5505
5506 static void stac92hd8x_add_pin(struct hda_codec *codec, hda_nid_t nid)
5507 {
5508         struct sigmatel_spec *spec = codec->spec;
5509         unsigned int def_conf = snd_hda_codec_get_pincfg(codec, nid);
5510         int i;
5511
5512         spec->auto_pin_nids[spec->auto_pin_cnt] = nid;
5513         spec->auto_pin_cnt++;
5514
5515         if (get_defcfg_device(def_conf) == AC_JACK_MIC_IN &&
5516             get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE) {
5517                 for (i = 0; i < ARRAY_SIZE(stac92hd83xxx_dmic_nids); i++) {
5518                         if (nid == stac92hd83xxx_dmic_nids[i]) {
5519                                 spec->auto_dmic_nids[spec->auto_dmic_cnt] = nid;
5520                                 spec->auto_dmic_cnt++;
5521                         }
5522                 }
5523         }
5524 }
5525
5526 static void stac92hd8x_add_adc(struct hda_codec *codec, hda_nid_t nid)
5527 {
5528         struct sigmatel_spec *spec = codec->spec;
5529
5530         spec->auto_adc_nids[spec->auto_adc_cnt] = nid;
5531         spec->auto_adc_cnt++;
5532 }
5533
5534 static void stac92hd8x_add_mux(struct hda_codec *codec, hda_nid_t nid)
5535 {
5536         int i, j;
5537         struct sigmatel_spec *spec = codec->spec;
5538
5539         for (i = 0; i < spec->auto_adc_cnt; i++) {
5540                 if (get_connection_index(codec,
5541                                 spec->auto_adc_nids[i], nid) >= 0) {
5542                         /* mux and volume for adc_nids[i] */
5543                         if (!spec->auto_mux_nids[i]) {
5544                                 spec->auto_mux_nids[i] = nid;
5545                                 /* 92hd codecs capture volume is in mux */
5546                                 spec->auto_capvols[i] = HDA_COMPOSE_AMP_VAL(nid,
5547                                                         3, 0, HDA_OUTPUT);
5548                         }
5549                         for (j = 0; j < spec->auto_dmic_cnt; j++) {
5550                                 if (get_connection_index(codec, nid,
5551                                                 spec->auto_dmic_nids[j]) >= 0) {
5552                                         /* dmux for adc_nids[i] */
5553                                         if (!spec->auto_dmux_nids[i])
5554                                                 spec->auto_dmux_nids[i] = nid;
5555                                         break;
5556                                 }
5557                         }
5558                         break;
5559                 }
5560         }
5561 }
5562
5563 static void stac92hd8x_fill_auto_spec(struct hda_codec *codec)
5564 {
5565         hda_nid_t nid, end_nid;
5566         unsigned int wid_caps, wid_type;
5567         struct sigmatel_spec *spec = codec->spec;
5568
5569         end_nid = codec->start_nid + codec->num_nodes;
5570
5571         for (nid = codec->start_nid; nid < end_nid; nid++) {
5572                 wid_caps = get_wcaps(codec, nid);
5573                 wid_type = get_wcaps_type(wid_caps);
5574
5575                 if (wid_type == AC_WID_PIN)
5576                         stac92hd8x_add_pin(codec, nid);
5577
5578                 if (wid_type == AC_WID_AUD_IN && !(wid_caps & AC_WCAP_DIGITAL))
5579                         stac92hd8x_add_adc(codec, nid);
5580         }
5581
5582         for (nid = codec->start_nid; nid < end_nid; nid++) {
5583                 wid_caps = get_wcaps(codec, nid);
5584                 wid_type = get_wcaps_type(wid_caps);
5585
5586                 if (wid_type == AC_WID_AUD_SEL)
5587                         stac92hd8x_add_mux(codec, nid);
5588         }
5589
5590         spec->pin_nids = spec->auto_pin_nids;
5591         spec->num_pins = spec->auto_pin_cnt;
5592         spec->adc_nids = spec->auto_adc_nids;
5593         spec->num_adcs = spec->auto_adc_cnt;
5594         spec->capvols = spec->auto_capvols;
5595         spec->capsws = spec->auto_capvols;
5596         spec->num_caps = spec->auto_adc_cnt;
5597         spec->mux_nids = spec->auto_mux_nids;
5598         spec->num_muxes = spec->auto_adc_cnt;
5599         spec->dmux_nids = spec->auto_dmux_nids;
5600         spec->num_dmuxes = spec->auto_adc_cnt;
5601         spec->dmic_nids = spec->auto_dmic_nids;
5602         spec->num_dmics = spec->auto_dmic_cnt;
5603 }
5604
5605 static int patch_stac92hd83xxx(struct hda_codec *codec)
5606 {
5607         struct sigmatel_spec *spec;
5608         int err;
5609
5610         spec  = kzalloc(sizeof(*spec), GFP_KERNEL);
5611         if (spec == NULL)
5612                 return -ENOMEM;
5613
5614         if (hp_bnb2011_with_dock(codec)) {
5615                 snd_hda_codec_set_pincfg(codec, 0xa, 0x2101201f);
5616                 snd_hda_codec_set_pincfg(codec, 0xf, 0x2181205e);
5617         }
5618
5619         codec->no_trigger_sense = 1;
5620         codec->spec = spec;
5621
5622         stac92hd8x_fill_auto_spec(codec);
5623
5624         spec->linear_tone_beep = 0;
5625         codec->slave_dig_outs = stac92hd83xxx_slave_dig_outs;
5626         spec->digbeep_nid = 0x21;
5627         spec->pwr_nids = stac92hd83xxx_pwr_nids;
5628         spec->num_pwrs = ARRAY_SIZE(stac92hd83xxx_pwr_nids);
5629         spec->multiout.dac_nids = spec->dac_nids;
5630         spec->init = stac92hd83xxx_core_init;
5631
5632         spec->board_config = snd_hda_check_board_config(codec,
5633                                                         STAC_92HD83XXX_MODELS,
5634                                                         stac92hd83xxx_models,
5635                                                         stac92hd83xxx_cfg_tbl);
5636 again:
5637         if (spec->board_config < 0)
5638                 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5639                             codec->chip_name);
5640         else
5641                 stac92xx_set_config_regs(codec,
5642                                 stac92hd83xxx_brd_tbl[spec->board_config]);
5643
5644         codec->patch_ops = stac92xx_patch_ops;
5645
5646         if (find_mute_led_cfg(codec, -1/*no default cfg*/))
5647                 snd_printd("mute LED gpio %d polarity %d\n",
5648                                 spec->gpio_led,
5649                                 spec->gpio_led_polarity);
5650
5651 #ifdef CONFIG_SND_HDA_POWER_SAVE
5652         if (spec->gpio_led) {
5653                 if (!spec->vref_mute_led_nid) {
5654                         spec->gpio_mask |= spec->gpio_led;
5655                         spec->gpio_dir |= spec->gpio_led;
5656                         spec->gpio_data |= spec->gpio_led;
5657                 } else {
5658                         codec->patch_ops.set_power_state =
5659                                         stac92xx_set_power_state;
5660                 }
5661                 codec->patch_ops.pre_resume = stac92xx_pre_resume;
5662                 codec->patch_ops.check_power_status =
5663                         stac92xx_check_power_status;
5664         }
5665 #endif  
5666
5667         err = stac92xx_parse_auto_config(codec);
5668         if (!err) {
5669                 if (spec->board_config < 0) {
5670                         printk(KERN_WARNING "hda_codec: No auto-config is "
5671                                "available, default to model=ref\n");
5672                         spec->board_config = STAC_92HD83XXX_REF;
5673                         goto again;
5674                 }
5675                 err = -EINVAL;
5676         }
5677
5678         if (err < 0) {
5679                 stac92xx_free(codec);
5680                 return err;
5681         }
5682
5683         codec->proc_widget_hook = stac92hd_proc_hook;
5684
5685         return 0;
5686 }
5687
5688 static int stac92hd71bxx_connected_smuxes(struct hda_codec *codec,
5689                                           hda_nid_t dig0pin)
5690 {
5691         struct sigmatel_spec *spec = codec->spec;
5692         int idx;
5693
5694         for (idx = 0; idx < spec->num_pins; idx++)
5695                 if (spec->pin_nids[idx] == dig0pin)
5696                         break;
5697         if ((idx + 2) >= spec->num_pins)
5698                 return 0;
5699
5700         /* dig1pin case */
5701         if (stac_get_defcfg_connect(codec, idx + 1) != AC_JACK_PORT_NONE)
5702                 return 2;
5703
5704         /* dig0pin + dig2pin case */
5705         if (stac_get_defcfg_connect(codec, idx + 2) != AC_JACK_PORT_NONE)
5706                 return 2;
5707         if (stac_get_defcfg_connect(codec, idx) != AC_JACK_PORT_NONE)
5708                 return 1;
5709         else
5710                 return 0;
5711 }
5712
5713 /* HP dv7 bass switch - GPIO5 */
5714 #define stac_hp_bass_gpio_info  snd_ctl_boolean_mono_info
5715 static int stac_hp_bass_gpio_get(struct snd_kcontrol *kcontrol,
5716                                  struct snd_ctl_elem_value *ucontrol)
5717 {
5718         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5719         struct sigmatel_spec *spec = codec->spec;
5720         ucontrol->value.integer.value[0] = !!(spec->gpio_data & 0x20);
5721         return 0;
5722 }
5723
5724 static int stac_hp_bass_gpio_put(struct snd_kcontrol *kcontrol,
5725                                  struct snd_ctl_elem_value *ucontrol)
5726 {
5727         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5728         struct sigmatel_spec *spec = codec->spec;
5729         unsigned int gpio_data;
5730
5731         gpio_data = (spec->gpio_data & ~0x20) |
5732                 (ucontrol->value.integer.value[0] ? 0x20 : 0);
5733         if (gpio_data == spec->gpio_data)
5734                 return 0;
5735         spec->gpio_data = gpio_data;
5736         stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, spec->gpio_data);
5737         return 1;
5738 }
5739
5740 static const struct snd_kcontrol_new stac_hp_bass_sw_ctrl = {
5741         .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5742         .info = stac_hp_bass_gpio_info,
5743         .get = stac_hp_bass_gpio_get,
5744         .put = stac_hp_bass_gpio_put,
5745 };
5746
5747 static int stac_add_hp_bass_switch(struct hda_codec *codec)
5748 {
5749         struct sigmatel_spec *spec = codec->spec;
5750
5751         if (!stac_control_new(spec, &stac_hp_bass_sw_ctrl,
5752                               "Bass Speaker Playback Switch", 0))
5753                 return -ENOMEM;
5754
5755         spec->gpio_mask |= 0x20;
5756         spec->gpio_dir |= 0x20;
5757         spec->gpio_data |= 0x20;
5758         return 0;
5759 }
5760
5761 static int patch_stac92hd71bxx(struct hda_codec *codec)
5762 {
5763         struct sigmatel_spec *spec;
5764         const struct hda_verb *unmute_init = stac92hd71bxx_unmute_core_init;
5765         unsigned int pin_cfg;
5766         int err = 0;
5767
5768         spec  = kzalloc(sizeof(*spec), GFP_KERNEL);
5769         if (spec == NULL)
5770                 return -ENOMEM;
5771
5772         codec->no_trigger_sense = 1;
5773         codec->spec = spec;
5774         spec->linear_tone_beep = 0;
5775         codec->patch_ops = stac92xx_patch_ops;
5776         spec->num_pins = STAC92HD71BXX_NUM_PINS;
5777         switch (codec->vendor_id) {
5778         case 0x111d76b6:
5779         case 0x111d76b7:
5780                 spec->pin_nids = stac92hd71bxx_pin_nids_4port;
5781                 break;
5782         case 0x111d7603:
5783         case 0x111d7608:
5784                 /* On 92HD75Bx 0x27 isn't a pin nid */
5785                 spec->num_pins--;
5786                 /* fallthrough */
5787         default:
5788                 spec->pin_nids = stac92hd71bxx_pin_nids_6port;
5789         }
5790         spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids);
5791         spec->board_config = snd_hda_check_board_config(codec,
5792                                                         STAC_92HD71BXX_MODELS,
5793                                                         stac92hd71bxx_models,
5794                                                         stac92hd71bxx_cfg_tbl);
5795 again:
5796         if (spec->board_config < 0)
5797                 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5798                             codec->chip_name);
5799         else
5800                 stac92xx_set_config_regs(codec,
5801                                 stac92hd71bxx_brd_tbl[spec->board_config]);
5802
5803         if (spec->board_config != STAC_92HD71BXX_REF) {
5804                 /* GPIO0 = EAPD */
5805                 spec->gpio_mask = 0x01;
5806                 spec->gpio_dir = 0x01;
5807                 spec->gpio_data = 0x01;
5808         }
5809
5810         spec->dmic_nids = stac92hd71bxx_dmic_nids;
5811         spec->dmux_nids = stac92hd71bxx_dmux_nids;
5812
5813         spec->num_caps = STAC92HD71BXX_NUM_CAPS;
5814         spec->capvols = stac92hd71bxx_capvols;
5815         spec->capsws = stac92hd71bxx_capsws;
5816
5817         switch (codec->vendor_id) {
5818         case 0x111d76b6: /* 4 Port without Analog Mixer */
5819         case 0x111d76b7:
5820                 unmute_init++;
5821                 /* fallthru */
5822         case 0x111d76b4: /* 6 Port without Analog Mixer */
5823         case 0x111d76b5:
5824                 spec->init = stac92hd71bxx_core_init;
5825                 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
5826                 spec->num_dmics = stac92xx_connected_ports(codec,
5827                                         stac92hd71bxx_dmic_nids,
5828                                         STAC92HD71BXX_NUM_DMICS);
5829                 break;
5830         case 0x111d7608: /* 5 Port with Analog Mixer */
5831                 switch (spec->board_config) {
5832                 case STAC_HP_M4:
5833                         /* Enable VREF power saving on GPIO1 detect */
5834                         err = stac_add_event(spec, codec->afg,
5835                                              STAC_VREF_EVENT, 0x02);
5836                         if (err < 0)
5837                                 return err;
5838                         snd_hda_codec_write_cache(codec, codec->afg, 0,
5839                                 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02);
5840                         snd_hda_codec_write_cache(codec, codec->afg, 0,
5841                                 AC_VERB_SET_UNSOLICITED_ENABLE,
5842                                 AC_USRSP_EN | err);
5843                         spec->gpio_mask |= 0x02;
5844                         break;
5845                 }
5846                 if ((codec->revision_id & 0xf) == 0 ||
5847                     (codec->revision_id & 0xf) == 1)
5848                         spec->stream_delay = 40; /* 40 milliseconds */
5849
5850                 /* disable VSW */
5851                 spec->init = stac92hd71bxx_core_init;
5852                 unmute_init++;
5853                 snd_hda_codec_set_pincfg(codec, 0x0f, 0x40f000f0);
5854                 snd_hda_codec_set_pincfg(codec, 0x19, 0x40f000f3);
5855                 spec->dmic_nids = stac92hd71bxx_dmic_5port_nids;
5856                 spec->num_dmics = stac92xx_connected_ports(codec,
5857                                         stac92hd71bxx_dmic_5port_nids,
5858                                         STAC92HD71BXX_NUM_DMICS - 1);
5859                 break;
5860         case 0x111d7603: /* 6 Port with Analog Mixer */
5861                 if ((codec->revision_id & 0xf) == 1)
5862                         spec->stream_delay = 40; /* 40 milliseconds */
5863
5864                 /* fallthru */
5865         default:
5866                 spec->init = stac92hd71bxx_core_init;
5867                 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
5868                 spec->num_dmics = stac92xx_connected_ports(codec,
5869                                         stac92hd71bxx_dmic_nids,
5870                                         STAC92HD71BXX_NUM_DMICS);
5871                 break;
5872         }
5873
5874         if (get_wcaps(codec, 0xa) & AC_WCAP_IN_AMP)
5875                 snd_hda_sequence_write_cache(codec, unmute_init);
5876
5877         spec->aloopback_ctl = stac92hd71bxx_loopback;
5878         spec->aloopback_mask = 0x50;
5879         spec->aloopback_shift = 0;
5880
5881         spec->powerdown_adcs = 1;
5882         spec->digbeep_nid = 0x26;
5883         spec->mux_nids = stac92hd71bxx_mux_nids;
5884         spec->adc_nids = stac92hd71bxx_adc_nids;
5885         spec->smux_nids = stac92hd71bxx_smux_nids;
5886         spec->pwr_nids = stac92hd71bxx_pwr_nids;
5887
5888         spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids);
5889         spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids);
5890         spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
5891         spec->num_smuxes = stac92hd71bxx_connected_smuxes(codec, 0x1e);
5892
5893         snd_printdd("Found board config: %d\n", spec->board_config);
5894
5895         switch (spec->board_config) {
5896         case STAC_HP_M4:
5897                 /* enable internal microphone */
5898                 snd_hda_codec_set_pincfg(codec, 0x0e, 0x01813040);
5899                 stac92xx_auto_set_pinctl(codec, 0x0e,
5900                         AC_PINCTL_IN_EN | AC_PINCTL_VREF_80);
5901                 /* fallthru */
5902         case STAC_DELL_M4_2:
5903                 spec->num_dmics = 0;
5904                 spec->num_smuxes = 0;
5905                 spec->num_dmuxes = 0;
5906                 break;
5907         case STAC_DELL_M4_1:
5908         case STAC_DELL_M4_3:
5909                 spec->num_dmics = 1;
5910                 spec->num_smuxes = 0;
5911                 spec->num_dmuxes = 1;
5912                 break;
5913         case STAC_HP_DV4_1222NR:
5914                 spec->num_dmics = 1;
5915                 /* I don't know if it needs 1 or 2 smuxes - will wait for
5916                  * bug reports to fix if needed
5917                  */
5918                 spec->num_smuxes = 1;
5919                 spec->num_dmuxes = 1;
5920                 /* fallthrough */
5921         case STAC_HP_DV4:
5922                 spec->gpio_led = 0x01;
5923                 /* fallthrough */
5924         case STAC_HP_DV5:
5925                 snd_hda_codec_set_pincfg(codec, 0x0d, 0x90170010);
5926                 stac92xx_auto_set_pinctl(codec, 0x0d, AC_PINCTL_OUT_EN);
5927                 /* HP dv6 gives the headphone pin as a line-out.  Thus we
5928                  * need to set hp_detect flag here to force to enable HP
5929                  * detection.
5930                  */
5931                 spec->hp_detect = 1;
5932                 break;
5933         case STAC_HP_HDX:
5934                 spec->num_dmics = 1;
5935                 spec->num_dmuxes = 1;
5936                 spec->num_smuxes = 1;
5937                 spec->gpio_led = 0x08;
5938                 break;
5939         }
5940
5941         if (hp_blike_system(codec->subsystem_id)) {
5942                 pin_cfg = snd_hda_codec_get_pincfg(codec, 0x0f);
5943                 if (get_defcfg_device(pin_cfg) == AC_JACK_LINE_OUT ||
5944                         get_defcfg_device(pin_cfg) == AC_JACK_SPEAKER  ||
5945                         get_defcfg_device(pin_cfg) == AC_JACK_HP_OUT) {
5946                         /* It was changed in the BIOS to just satisfy MS DTM.
5947                          * Lets turn it back into slaved HP
5948                          */
5949                         pin_cfg = (pin_cfg & (~AC_DEFCFG_DEVICE))
5950                                         | (AC_JACK_HP_OUT <<
5951                                                 AC_DEFCFG_DEVICE_SHIFT);
5952                         pin_cfg = (pin_cfg & (~(AC_DEFCFG_DEF_ASSOC
5953                                                         | AC_DEFCFG_SEQUENCE)))
5954                                                                 | 0x1f;
5955                         snd_hda_codec_set_pincfg(codec, 0x0f, pin_cfg);
5956                 }
5957         }
5958
5959         if (find_mute_led_cfg(codec, 1))
5960                 snd_printd("mute LED gpio %d polarity %d\n",
5961                                 spec->gpio_led,
5962                                 spec->gpio_led_polarity);
5963
5964 #ifdef CONFIG_SND_HDA_POWER_SAVE
5965         if (spec->gpio_led) {
5966                 if (!spec->vref_mute_led_nid) {
5967                         spec->gpio_mask |= spec->gpio_led;
5968                         spec->gpio_dir |= spec->gpio_led;
5969                         spec->gpio_data |= spec->gpio_led;
5970                 } else {
5971                         codec->patch_ops.set_power_state =
5972                                         stac92xx_set_power_state;
5973                 }
5974                 codec->patch_ops.pre_resume = stac92xx_pre_resume;
5975                 codec->patch_ops.check_power_status =
5976                         stac92xx_check_power_status;
5977         }
5978 #endif  
5979
5980         spec->multiout.dac_nids = spec->dac_nids;
5981
5982         err = stac92xx_parse_auto_config(codec);
5983         if (!err) {
5984                 if (spec->board_config < 0) {
5985                         printk(KERN_WARNING "hda_codec: No auto-config is "
5986                                "available, default to model=ref\n");
5987                         spec->board_config = STAC_92HD71BXX_REF;
5988                         goto again;
5989                 }
5990                 err = -EINVAL;
5991         }
5992
5993         if (err < 0) {
5994                 stac92xx_free(codec);
5995                 return err;
5996         }
5997
5998         /* enable bass on HP dv7 */
5999         if (spec->board_config == STAC_HP_DV4 ||
6000             spec->board_config == STAC_HP_DV5) {
6001                 unsigned int cap;
6002                 cap = snd_hda_param_read(codec, 0x1, AC_PAR_GPIO_CAP);
6003                 cap &= AC_GPIO_IO_COUNT;
6004                 if (cap >= 6)
6005                         stac_add_hp_bass_switch(codec);
6006         }
6007
6008         codec->proc_widget_hook = stac92hd7x_proc_hook;
6009
6010         return 0;
6011 }
6012
6013 static int patch_stac922x(struct hda_codec *codec)
6014 {
6015         struct sigmatel_spec *spec;
6016         int err;
6017
6018         spec  = kzalloc(sizeof(*spec), GFP_KERNEL);
6019         if (spec == NULL)
6020                 return -ENOMEM;
6021
6022         codec->no_trigger_sense = 1;
6023         codec->spec = spec;
6024         spec->linear_tone_beep = 1;
6025         spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
6026         spec->pin_nids = stac922x_pin_nids;
6027         spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
6028                                                         stac922x_models,
6029                                                         stac922x_cfg_tbl);
6030         if (spec->board_config == STAC_INTEL_MAC_AUTO) {
6031                 spec->gpio_mask = spec->gpio_dir = 0x03;
6032                 spec->gpio_data = 0x03;
6033                 /* Intel Macs have all same PCI SSID, so we need to check
6034                  * codec SSID to distinguish the exact models
6035                  */
6036                 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
6037                 switch (codec->subsystem_id) {
6038
6039                 case 0x106b0800:
6040                         spec->board_config = STAC_INTEL_MAC_V1;
6041                         break;
6042                 case 0x106b0600:
6043                 case 0x106b0700:
6044                         spec->board_config = STAC_INTEL_MAC_V2;
6045                         break;
6046                 case 0x106b0e00:
6047                 case 0x106b0f00:
6048                 case 0x106b1600:
6049                 case 0x106b1700:
6050                 case 0x106b0200:
6051                 case 0x106b1e00:
6052                         spec->board_config = STAC_INTEL_MAC_V3;
6053                         break;
6054                 case 0x106b1a00:
6055                 case 0x00000100:
6056                         spec->board_config = STAC_INTEL_MAC_V4;
6057                         break;
6058                 case 0x106b0a00:
6059                 case 0x106b2200:
6060                         spec->board_config = STAC_INTEL_MAC_V5;
6061                         break;
6062                 default:
6063                         spec->board_config = STAC_INTEL_MAC_V3;
6064                         break;
6065                 }
6066         }
6067
6068  again:
6069         if (spec->board_config < 0)
6070                 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6071                             codec->chip_name);
6072         else
6073                 stac92xx_set_config_regs(codec,
6074                                 stac922x_brd_tbl[spec->board_config]);
6075
6076         spec->adc_nids = stac922x_adc_nids;
6077         spec->mux_nids = stac922x_mux_nids;
6078         spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
6079         spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
6080         spec->num_dmics = 0;
6081         spec->num_pwrs = 0;
6082
6083         spec->init = stac922x_core_init;
6084
6085         spec->num_caps = STAC922X_NUM_CAPS;
6086         spec->capvols = stac922x_capvols;
6087         spec->capsws = stac922x_capsws;
6088
6089         spec->multiout.dac_nids = spec->dac_nids;
6090         
6091         err = stac92xx_parse_auto_config(codec);
6092         if (!err) {
6093                 if (spec->board_config < 0) {
6094                         printk(KERN_WARNING "hda_codec: No auto-config is "
6095                                "available, default to model=ref\n");
6096                         spec->board_config = STAC_D945_REF;
6097                         goto again;
6098                 }
6099                 err = -EINVAL;
6100         }
6101         if (err < 0) {
6102                 stac92xx_free(codec);
6103                 return err;
6104         }
6105
6106         codec->patch_ops = stac92xx_patch_ops;
6107
6108         /* Fix Mux capture level; max to 2 */
6109         snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
6110                                   (0 << AC_AMPCAP_OFFSET_SHIFT) |
6111                                   (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
6112                                   (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6113                                   (0 << AC_AMPCAP_MUTE_SHIFT));
6114
6115         return 0;
6116 }
6117
6118 static int patch_stac927x(struct hda_codec *codec)
6119 {
6120         struct sigmatel_spec *spec;
6121         int err;
6122
6123         spec  = kzalloc(sizeof(*spec), GFP_KERNEL);
6124         if (spec == NULL)
6125                 return -ENOMEM;
6126
6127         codec->no_trigger_sense = 1;
6128         codec->spec = spec;
6129         spec->linear_tone_beep = 1;
6130         codec->slave_dig_outs = stac927x_slave_dig_outs;
6131         spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
6132         spec->pin_nids = stac927x_pin_nids;
6133         spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
6134                                                         stac927x_models,
6135                                                         stac927x_cfg_tbl);
6136  again:
6137         if (spec->board_config < 0)
6138                 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6139                             codec->chip_name);
6140         else
6141                 stac92xx_set_config_regs(codec,
6142                                 stac927x_brd_tbl[spec->board_config]);
6143
6144         spec->digbeep_nid = 0x23;
6145         spec->adc_nids = stac927x_adc_nids;
6146         spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
6147         spec->mux_nids = stac927x_mux_nids;
6148         spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
6149         spec->smux_nids = stac927x_smux_nids;
6150         spec->num_smuxes = ARRAY_SIZE(stac927x_smux_nids);
6151         spec->spdif_labels = stac927x_spdif_labels;
6152         spec->dac_list = stac927x_dac_nids;
6153         spec->multiout.dac_nids = spec->dac_nids;
6154
6155         if (spec->board_config != STAC_D965_REF) {
6156                 /* GPIO0 High = Enable EAPD */
6157                 spec->eapd_mask = spec->gpio_mask = 0x01;
6158                 spec->gpio_dir = spec->gpio_data = 0x01;
6159         }
6160
6161         switch (spec->board_config) {
6162         case STAC_D965_3ST:
6163         case STAC_D965_5ST:
6164                 /* GPIO0 High = Enable EAPD */
6165                 spec->num_dmics = 0;
6166                 spec->init = d965_core_init;
6167                 break;
6168         case STAC_DELL_BIOS:
6169                 switch (codec->subsystem_id) {
6170                 case 0x10280209:
6171                 case 0x1028022e:
6172                         /* correct the device field to SPDIF out */
6173                         snd_hda_codec_set_pincfg(codec, 0x21, 0x01442070);
6174                         break;
6175                 }
6176                 /* configure the analog microphone on some laptops */
6177                 snd_hda_codec_set_pincfg(codec, 0x0c, 0x90a79130);
6178                 /* correct the front output jack as a hp out */
6179                 snd_hda_codec_set_pincfg(codec, 0x0f, 0x0227011f);
6180                 /* correct the front input jack as a mic */
6181                 snd_hda_codec_set_pincfg(codec, 0x0e, 0x02a79130);
6182                 /* fallthru */
6183         case STAC_DELL_3ST:
6184                 if (codec->subsystem_id != 0x1028022f) {
6185                         /* GPIO2 High = Enable EAPD */
6186                         spec->eapd_mask = spec->gpio_mask = 0x04;
6187                         spec->gpio_dir = spec->gpio_data = 0x04;
6188                 }
6189                 spec->dmic_nids = stac927x_dmic_nids;
6190                 spec->num_dmics = STAC927X_NUM_DMICS;
6191
6192                 spec->init = dell_3st_core_init;
6193                 spec->dmux_nids = stac927x_dmux_nids;
6194                 spec->num_dmuxes = ARRAY_SIZE(stac927x_dmux_nids);
6195                 break;
6196         case STAC_927X_VOLKNOB:
6197                 spec->num_dmics = 0;
6198                 spec->init = stac927x_volknob_core_init;
6199                 break;
6200         default:
6201                 spec->num_dmics = 0;
6202                 spec->init = stac927x_core_init;
6203                 break;
6204         }
6205
6206         spec->num_caps = STAC927X_NUM_CAPS;
6207         spec->capvols = stac927x_capvols;
6208         spec->capsws = stac927x_capsws;
6209
6210         spec->num_pwrs = 0;
6211         spec->aloopback_ctl = stac927x_loopback;
6212         spec->aloopback_mask = 0x40;
6213         spec->aloopback_shift = 0;
6214         spec->eapd_switch = 1;
6215
6216         err = stac92xx_parse_auto_config(codec);
6217         if (!err) {
6218                 if (spec->board_config < 0) {
6219                         printk(KERN_WARNING "hda_codec: No auto-config is "
6220                                "available, default to model=ref\n");
6221                         spec->board_config = STAC_D965_REF;
6222                         goto again;
6223                 }
6224                 err = -EINVAL;
6225         }
6226         if (err < 0) {
6227                 stac92xx_free(codec);
6228                 return err;
6229         }
6230
6231         codec->patch_ops = stac92xx_patch_ops;
6232
6233         codec->proc_widget_hook = stac927x_proc_hook;
6234
6235         /*
6236          * !!FIXME!!
6237          * The STAC927x seem to require fairly long delays for certain
6238          * command sequences.  With too short delays (even if the answer
6239          * is set to RIRB properly), it results in the silence output
6240          * on some hardwares like Dell.
6241          *
6242          * The below flag enables the longer delay (see get_response
6243          * in hda_intel.c).
6244          */
6245         codec->bus->needs_damn_long_delay = 1;
6246
6247         /* no jack detecion for ref-no-jd model */
6248         if (spec->board_config == STAC_D965_REF_NO_JD)
6249                 spec->hp_detect = 0;
6250
6251         return 0;
6252 }
6253
6254 static int patch_stac9205(struct hda_codec *codec)
6255 {
6256         struct sigmatel_spec *spec;
6257         int err;
6258
6259         spec  = kzalloc(sizeof(*spec), GFP_KERNEL);
6260         if (spec == NULL)
6261                 return -ENOMEM;
6262
6263         codec->no_trigger_sense = 1;
6264         codec->spec = spec;
6265         spec->linear_tone_beep = 1;
6266         spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
6267         spec->pin_nids = stac9205_pin_nids;
6268         spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
6269                                                         stac9205_models,
6270                                                         stac9205_cfg_tbl);
6271  again:
6272         if (spec->board_config < 0)
6273                 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6274                             codec->chip_name);
6275         else
6276                 stac92xx_set_config_regs(codec,
6277                                          stac9205_brd_tbl[spec->board_config]);
6278
6279         spec->digbeep_nid = 0x23;
6280         spec->adc_nids = stac9205_adc_nids;
6281         spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
6282         spec->mux_nids = stac9205_mux_nids;
6283         spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
6284         spec->smux_nids = stac9205_smux_nids;
6285         spec->num_smuxes = ARRAY_SIZE(stac9205_smux_nids);
6286         spec->dmic_nids = stac9205_dmic_nids;
6287         spec->num_dmics = STAC9205_NUM_DMICS;
6288         spec->dmux_nids = stac9205_dmux_nids;
6289         spec->num_dmuxes = ARRAY_SIZE(stac9205_dmux_nids);
6290         spec->num_pwrs = 0;
6291
6292         spec->init = stac9205_core_init;
6293         spec->aloopback_ctl = stac9205_loopback;
6294
6295         spec->num_caps = STAC9205_NUM_CAPS;
6296         spec->capvols = stac9205_capvols;
6297         spec->capsws = stac9205_capsws;
6298
6299         spec->aloopback_mask = 0x40;
6300         spec->aloopback_shift = 0;
6301         /* Turn on/off EAPD per HP plugging */
6302         if (spec->board_config != STAC_9205_EAPD)
6303                 spec->eapd_switch = 1;
6304         spec->multiout.dac_nids = spec->dac_nids;
6305         
6306         switch (spec->board_config){
6307         case STAC_9205_DELL_M43:
6308                 /* Enable SPDIF in/out */
6309                 snd_hda_codec_set_pincfg(codec, 0x1f, 0x01441030);
6310                 snd_hda_codec_set_pincfg(codec, 0x20, 0x1c410030);
6311
6312                 /* Enable unsol response for GPIO4/Dock HP connection */
6313                 err = stac_add_event(spec, codec->afg, STAC_VREF_EVENT, 0x01);
6314                 if (err < 0)
6315                         return err;
6316                 snd_hda_codec_write_cache(codec, codec->afg, 0,
6317                         AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10);
6318                 snd_hda_codec_write_cache(codec, codec->afg, 0,
6319                                           AC_VERB_SET_UNSOLICITED_ENABLE,
6320                                           AC_USRSP_EN | err);
6321
6322                 spec->gpio_dir = 0x0b;
6323                 spec->eapd_mask = 0x01;
6324                 spec->gpio_mask = 0x1b;
6325                 spec->gpio_mute = 0x10;
6326                 /* GPIO0 High = EAPD, GPIO1 Low = Headphone Mute,
6327                  * GPIO3 Low = DRM
6328                  */
6329                 spec->gpio_data = 0x01;
6330                 break;
6331         case STAC_9205_REF:
6332                 /* SPDIF-In enabled */
6333                 break;
6334         default:
6335                 /* GPIO0 High = EAPD */
6336                 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
6337                 spec->gpio_data = 0x01;
6338                 break;
6339         }
6340
6341         err = stac92xx_parse_auto_config(codec);
6342         if (!err) {
6343                 if (spec->board_config < 0) {
6344                         printk(KERN_WARNING "hda_codec: No auto-config is "
6345                                "available, default to model=ref\n");
6346                         spec->board_config = STAC_9205_REF;
6347                         goto again;
6348                 }
6349                 err = -EINVAL;
6350         }
6351         if (err < 0) {
6352                 stac92xx_free(codec);
6353                 return err;
6354         }
6355
6356         codec->patch_ops = stac92xx_patch_ops;
6357
6358         codec->proc_widget_hook = stac9205_proc_hook;
6359
6360         return 0;
6361 }
6362
6363 /*
6364  * STAC9872 hack
6365  */
6366
6367 static const struct hda_verb stac9872_core_init[] = {
6368         {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
6369         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
6370         {}
6371 };
6372
6373 static const hda_nid_t stac9872_pin_nids[] = {
6374         0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
6375         0x11, 0x13, 0x14,
6376 };
6377
6378 static const hda_nid_t stac9872_adc_nids[] = {
6379         0x8 /*,0x6*/
6380 };
6381
6382 static const hda_nid_t stac9872_mux_nids[] = {
6383         0x15
6384 };
6385
6386 static const unsigned long stac9872_capvols[] = {
6387         HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
6388 };
6389 #define stac9872_capsws         stac9872_capvols
6390
6391 static const unsigned int stac9872_vaio_pin_configs[9] = {
6392         0x03211020, 0x411111f0, 0x411111f0, 0x03a15030,
6393         0x411111f0, 0x90170110, 0x411111f0, 0x411111f0,
6394         0x90a7013e
6395 };
6396
6397 static const char * const stac9872_models[STAC_9872_MODELS] = {
6398         [STAC_9872_AUTO] = "auto",
6399         [STAC_9872_VAIO] = "vaio",
6400 };
6401
6402 static const unsigned int *stac9872_brd_tbl[STAC_9872_MODELS] = {
6403         [STAC_9872_VAIO] = stac9872_vaio_pin_configs,
6404 };
6405
6406 static const struct snd_pci_quirk stac9872_cfg_tbl[] = {
6407         SND_PCI_QUIRK_MASK(0x104d, 0xfff0, 0x81e0,
6408                            "Sony VAIO F/S", STAC_9872_VAIO),
6409         {} /* terminator */
6410 };
6411
6412 static int patch_stac9872(struct hda_codec *codec)
6413 {
6414         struct sigmatel_spec *spec;
6415         int err;
6416
6417         spec  = kzalloc(sizeof(*spec), GFP_KERNEL);
6418         if (spec == NULL)
6419                 return -ENOMEM;
6420         codec->no_trigger_sense = 1;
6421         codec->spec = spec;
6422         spec->linear_tone_beep = 1;
6423         spec->num_pins = ARRAY_SIZE(stac9872_pin_nids);
6424         spec->pin_nids = stac9872_pin_nids;
6425
6426         spec->board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
6427                                                         stac9872_models,
6428                                                         stac9872_cfg_tbl);
6429         if (spec->board_config < 0)
6430                 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6431                             codec->chip_name);
6432         else
6433                 stac92xx_set_config_regs(codec,
6434                                          stac9872_brd_tbl[spec->board_config]);
6435
6436         spec->multiout.dac_nids = spec->dac_nids;
6437         spec->num_adcs = ARRAY_SIZE(stac9872_adc_nids);
6438         spec->adc_nids = stac9872_adc_nids;
6439         spec->num_muxes = ARRAY_SIZE(stac9872_mux_nids);
6440         spec->mux_nids = stac9872_mux_nids;
6441         spec->init = stac9872_core_init;
6442         spec->num_caps = 1;
6443         spec->capvols = stac9872_capvols;
6444         spec->capsws = stac9872_capsws;
6445
6446         err = stac92xx_parse_auto_config(codec);
6447         if (err < 0) {
6448                 stac92xx_free(codec);
6449                 return -EINVAL;
6450         }
6451         spec->input_mux = &spec->private_imux;
6452         codec->patch_ops = stac92xx_patch_ops;
6453         return 0;
6454 }
6455
6456
6457 /*
6458  * patch entries
6459  */
6460 static const struct hda_codec_preset snd_hda_preset_sigmatel[] = {
6461         { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
6462         { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
6463         { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
6464         { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
6465         { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
6466         { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
6467         { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
6468         { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
6469         { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
6470         { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
6471         { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
6472         { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
6473         { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
6474         { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
6475         { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
6476         { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
6477         { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
6478         { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
6479         { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
6480         { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
6481         { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
6482         { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
6483         { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
6484         { .id = 0x83847632, .name = "STAC9202",  .patch = patch_stac925x },
6485         { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
6486         { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
6487         { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
6488         { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
6489         { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
6490         { .id = 0x83847645, .name = "92HD206X", .patch = patch_stac927x },
6491         { .id = 0x83847646, .name = "92HD206D", .patch = patch_stac927x },
6492         /* The following does not take into account .id=0x83847661 when subsys =
6493          * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
6494          * currently not fully supported.
6495          */
6496         { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
6497         { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
6498         { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
6499         { .id = 0x83847698, .name = "STAC9205", .patch = patch_stac9205 },
6500         { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
6501         { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
6502         { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
6503         { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
6504         { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
6505         { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
6506         { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
6507         { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
6508         { .id = 0x111d7603, .name = "92HD75B3X5", .patch = patch_stac92hd71bxx},
6509         { .id = 0x111d7604, .name = "92HD83C1X5", .patch = patch_stac92hd83xxx},
6510         { .id = 0x111d76d4, .name = "92HD83C1C5", .patch = patch_stac92hd83xxx},
6511         { .id = 0x111d7605, .name = "92HD81B1X5", .patch = patch_stac92hd83xxx},
6512         { .id = 0x111d76d5, .name = "92HD81B1C5", .patch = patch_stac92hd83xxx},
6513         { .id = 0x111d76d1, .name = "92HD87B1/3", .patch = patch_stac92hd83xxx},
6514         { .id = 0x111d76d9, .name = "92HD87B2/4", .patch = patch_stac92hd83xxx},
6515         { .id = 0x111d7666, .name = "92HD88B3", .patch = patch_stac92hd83xxx},
6516         { .id = 0x111d7667, .name = "92HD88B1", .patch = patch_stac92hd83xxx},
6517         { .id = 0x111d7668, .name = "92HD88B2", .patch = patch_stac92hd83xxx},
6518         { .id = 0x111d7669, .name = "92HD88B4", .patch = patch_stac92hd83xxx},
6519         { .id = 0x111d7608, .name = "92HD75B2X5", .patch = patch_stac92hd71bxx},
6520         { .id = 0x111d7674, .name = "92HD73D1X5", .patch = patch_stac92hd73xx },
6521         { .id = 0x111d7675, .name = "92HD73C1X5", .patch = patch_stac92hd73xx },
6522         { .id = 0x111d7676, .name = "92HD73E1X5", .patch = patch_stac92hd73xx },
6523         { .id = 0x111d76b0, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
6524         { .id = 0x111d76b1, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
6525         { .id = 0x111d76b2, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
6526         { .id = 0x111d76b3, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
6527         { .id = 0x111d76b4, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
6528         { .id = 0x111d76b5, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
6529         { .id = 0x111d76b6, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
6530         { .id = 0x111d76b7, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
6531         { .id = 0x111d76c0, .name = "92HD89C3", .patch = patch_stac92hd73xx },
6532         { .id = 0x111d76c1, .name = "92HD89C2", .patch = patch_stac92hd73xx },
6533         { .id = 0x111d76c2, .name = "92HD89C1", .patch = patch_stac92hd73xx },
6534         { .id = 0x111d76c3, .name = "92HD89B3", .patch = patch_stac92hd73xx },
6535         { .id = 0x111d76c4, .name = "92HD89B2", .patch = patch_stac92hd73xx },
6536         { .id = 0x111d76c5, .name = "92HD89B1", .patch = patch_stac92hd73xx },
6537         { .id = 0x111d76c6, .name = "92HD89E3", .patch = patch_stac92hd73xx },
6538         { .id = 0x111d76c7, .name = "92HD89E2", .patch = patch_stac92hd73xx },
6539         { .id = 0x111d76c8, .name = "92HD89E1", .patch = patch_stac92hd73xx },
6540         { .id = 0x111d76c9, .name = "92HD89D3", .patch = patch_stac92hd73xx },
6541         { .id = 0x111d76ca, .name = "92HD89D2", .patch = patch_stac92hd73xx },
6542         { .id = 0x111d76cb, .name = "92HD89D1", .patch = patch_stac92hd73xx },
6543         { .id = 0x111d76cc, .name = "92HD89F3", .patch = patch_stac92hd73xx },
6544         { .id = 0x111d76cd, .name = "92HD89F2", .patch = patch_stac92hd73xx },
6545         { .id = 0x111d76ce, .name = "92HD89F1", .patch = patch_stac92hd73xx },
6546         { .id = 0x111d76df, .name = "92HD93BXX", .patch = patch_stac92hd83xxx},
6547         { .id = 0x111d76e0, .name = "92HD91BXX", .patch = patch_stac92hd83xxx},
6548         { .id = 0x111d76e3, .name = "92HD98BXX", .patch = patch_stac92hd83xxx},
6549         { .id = 0x111d76e5, .name = "92HD99BXX", .patch = patch_stac92hd83xxx},
6550         { .id = 0x111d76e7, .name = "92HD90BXX", .patch = patch_stac92hd83xxx},
6551         { .id = 0x111d76e8, .name = "92HD66B1X5", .patch = patch_stac92hd83xxx},
6552         { .id = 0x111d76e9, .name = "92HD66B2X5", .patch = patch_stac92hd83xxx},
6553         { .id = 0x111d76ea, .name = "92HD66B3X5", .patch = patch_stac92hd83xxx},
6554         { .id = 0x111d76eb, .name = "92HD66C1X5", .patch = patch_stac92hd83xxx},
6555         { .id = 0x111d76ec, .name = "92HD66C2X5", .patch = patch_stac92hd83xxx},
6556         { .id = 0x111d76ed, .name = "92HD66C3X5", .patch = patch_stac92hd83xxx},
6557         { .id = 0x111d76ee, .name = "92HD66B1X3", .patch = patch_stac92hd83xxx},
6558         { .id = 0x111d76ef, .name = "92HD66B2X3", .patch = patch_stac92hd83xxx},
6559         { .id = 0x111d76f0, .name = "92HD66B3X3", .patch = patch_stac92hd83xxx},
6560         { .id = 0x111d76f1, .name = "92HD66C1X3", .patch = patch_stac92hd83xxx},
6561         { .id = 0x111d76f2, .name = "92HD66C2X3", .patch = patch_stac92hd83xxx},
6562         { .id = 0x111d76f3, .name = "92HD66C3/65", .patch = patch_stac92hd83xxx},
6563         {} /* terminator */
6564 };
6565
6566 MODULE_ALIAS("snd-hda-codec-id:8384*");
6567 MODULE_ALIAS("snd-hda-codec-id:111d*");
6568
6569 MODULE_LICENSE("GPL");
6570 MODULE_DESCRIPTION("IDT/Sigmatel HD-audio codec");
6571
6572 static struct hda_codec_preset_list sigmatel_list = {
6573         .preset = snd_hda_preset_sigmatel,
6574         .owner = THIS_MODULE,
6575 };
6576
6577 static int __init patch_sigmatel_init(void)
6578 {
6579         return snd_hda_add_codec_preset(&sigmatel_list);
6580 }
6581
6582 static void __exit patch_sigmatel_exit(void)
6583 {
6584         snd_hda_delete_codec_preset(&sigmatel_list);
6585 }
6586
6587 module_init(patch_sigmatel_init)
6588 module_exit(patch_sigmatel_exit)