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