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