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