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