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