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