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