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