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