470f6f286e8144f4f7a8282b2dc126239c69f765
[pandora-kernel.git] / sound / pci / hda / patch_sigmatel.c
1 /*
2  * Universal Interface for Intel High Definition Audio Codec
3  *
4  * HD audio interface patch for SigmaTel STAC92xx
5  *
6  * Copyright (c) 2005 Embedded Alley Solutions, Inc.
7  * Matt Porter <mporter@embeddedalley.com>
8  *
9  * Based on patch_cmedia.c and patch_realtek.c
10  * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
11  *
12  *  This driver is free software; you can redistribute it and/or modify
13  *  it under the terms of the GNU General Public License as published by
14  *  the Free Software Foundation; either version 2 of the License, or
15  *  (at your option) any later version.
16  *
17  *  This driver is distributed in the hope that it will be useful,
18  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  *  GNU General Public License for more details.
21  *
22  *  You should have received a copy of the GNU General Public License
23  *  along with this program; if not, write to the Free Software
24  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
25  */
26
27 #include <linux/init.h>
28 #include <linux/delay.h>
29 #include <linux/slab.h>
30 #include <linux/pci.h>
31 #include <linux/dmi.h>
32 #include <linux/module.h>
33 #include <sound/core.h>
34 #include <sound/asoundef.h>
35 #include <sound/jack.h>
36 #include <sound/tlv.h>
37 #include "hda_codec.h"
38 #include "hda_local.h"
39 #include "hda_beep.h"
40
41 enum {
42         STAC_VREF_EVENT = 1,
43         STAC_INSERT_EVENT,
44         STAC_PWR_EVENT,
45         STAC_HP_EVENT,
46         STAC_LO_EVENT,
47         STAC_MIC_EVENT,
48 };
49
50 enum {
51         STAC_AUTO,
52         STAC_REF,
53         STAC_9200_OQO,
54         STAC_9200_DELL_D21,
55         STAC_9200_DELL_D22,
56         STAC_9200_DELL_D23,
57         STAC_9200_DELL_M21,
58         STAC_9200_DELL_M22,
59         STAC_9200_DELL_M23,
60         STAC_9200_DELL_M24,
61         STAC_9200_DELL_M25,
62         STAC_9200_DELL_M26,
63         STAC_9200_DELL_M27,
64         STAC_9200_M4,
65         STAC_9200_M4_2,
66         STAC_9200_PANASONIC,
67         STAC_9200_MODELS
68 };
69
70 enum {
71         STAC_9205_AUTO,
72         STAC_9205_REF,
73         STAC_9205_DELL_M42,
74         STAC_9205_DELL_M43,
75         STAC_9205_DELL_M44,
76         STAC_9205_EAPD,
77         STAC_9205_MODELS
78 };
79
80 enum {
81         STAC_92HD73XX_AUTO,
82         STAC_92HD73XX_NO_JD, /* no jack-detection */
83         STAC_92HD73XX_REF,
84         STAC_92HD73XX_INTEL,
85         STAC_DELL_M6_AMIC,
86         STAC_DELL_M6_DMIC,
87         STAC_DELL_M6_BOTH,
88         STAC_DELL_EQ,
89         STAC_ALIENWARE_M17X,
90         STAC_92HD73XX_MODELS
91 };
92
93 enum {
94         STAC_92HD83XXX_AUTO,
95         STAC_92HD83XXX_REF,
96         STAC_92HD83XXX_PWR_REF,
97         STAC_DELL_S14,
98         STAC_DELL_VOSTRO_3500,
99         STAC_92HD83XXX_HP,
100         STAC_92HD83XXX_HP_cNB11_INTQUAD,
101         STAC_HP_DV7_4000,
102         STAC_92HD83XXX_MODELS
103 };
104
105 enum {
106         STAC_92HD71BXX_AUTO,
107         STAC_92HD71BXX_REF,
108         STAC_DELL_M4_1,
109         STAC_DELL_M4_2,
110         STAC_DELL_M4_3,
111         STAC_HP_M4,
112         STAC_HP_DV4,
113         STAC_HP_DV5,
114         STAC_HP_HDX,
115         STAC_HP_DV4_1222NR,
116         STAC_92HD71BXX_MODELS
117 };
118
119 enum {
120         STAC_925x_AUTO,
121         STAC_925x_REF,
122         STAC_M1,
123         STAC_M1_2,
124         STAC_M2,
125         STAC_M2_2,
126         STAC_M3,
127         STAC_M5,
128         STAC_M6,
129         STAC_925x_MODELS
130 };
131
132 enum {
133         STAC_922X_AUTO,
134         STAC_D945_REF,
135         STAC_D945GTP3,
136         STAC_D945GTP5,
137         STAC_INTEL_MAC_V1,
138         STAC_INTEL_MAC_V2,
139         STAC_INTEL_MAC_V3,
140         STAC_INTEL_MAC_V4,
141         STAC_INTEL_MAC_V5,
142         STAC_INTEL_MAC_AUTO, /* This model is selected if no module parameter
143                               * is given, one of the above models will be
144                               * chosen according to the subsystem id. */
145         /* for backward compatibility */
146         STAC_MACMINI,
147         STAC_MACBOOK,
148         STAC_MACBOOK_PRO_V1,
149         STAC_MACBOOK_PRO_V2,
150         STAC_IMAC_INTEL,
151         STAC_IMAC_INTEL_20,
152         STAC_ECS_202,
153         STAC_922X_DELL_D81,
154         STAC_922X_DELL_D82,
155         STAC_922X_DELL_M81,
156         STAC_922X_DELL_M82,
157         STAC_922X_MODELS
158 };
159
160 enum {
161         STAC_927X_AUTO,
162         STAC_D965_REF_NO_JD, /* no jack-detection */
163         STAC_D965_REF,
164         STAC_D965_3ST,
165         STAC_D965_5ST,
166         STAC_D965_5ST_NO_FP,
167         STAC_DELL_3ST,
168         STAC_DELL_BIOS,
169         STAC_927X_VOLKNOB,
170         STAC_927X_MODELS
171 };
172
173 enum {
174         STAC_9872_AUTO,
175         STAC_9872_VAIO,
176         STAC_9872_MODELS
177 };
178
179 struct sigmatel_event {
180         hda_nid_t nid;
181         unsigned char type;
182         unsigned char tag;
183         int data;
184 };
185
186 struct sigmatel_mic_route {
187         hda_nid_t pin;
188         signed char mux_idx;
189         signed char dmux_idx;
190 };
191
192 #define MAX_PINS_NUM 16
193 #define MAX_ADCS_NUM 4
194 #define MAX_DMICS_NUM 4
195
196 struct sigmatel_spec {
197         struct snd_kcontrol_new *mixers[4];
198         unsigned int num_mixers;
199
200         int board_config;
201         unsigned int eapd_switch: 1;
202         unsigned int surr_switch: 1;
203         unsigned int alt_switch: 1;
204         unsigned int hp_detect: 1;
205         unsigned int spdif_mute: 1;
206         unsigned int check_volume_offset:1;
207         unsigned int auto_mic:1;
208         unsigned int linear_tone_beep:1;
209
210         /* gpio lines */
211         unsigned int eapd_mask;
212         unsigned int gpio_mask;
213         unsigned int gpio_dir;
214         unsigned int gpio_data;
215         unsigned int gpio_mute;
216         unsigned int gpio_led;
217         unsigned int gpio_led_polarity;
218         unsigned int vref_led;
219
220         /* stream */
221         unsigned int stream_delay;
222
223         /* analog loopback */
224         const struct snd_kcontrol_new *aloopback_ctl;
225         unsigned char aloopback_mask;
226         unsigned char aloopback_shift;
227
228         /* power management */
229         unsigned int num_pwrs;
230         const hda_nid_t *pwr_nids;
231         const hda_nid_t *dac_list;
232
233         /* events */
234         struct snd_array events;
235
236         /* playback */
237         struct hda_input_mux *mono_mux;
238         unsigned int cur_mmux;
239         struct hda_multi_out multiout;
240         hda_nid_t dac_nids[5];
241         hda_nid_t hp_dacs[5];
242         hda_nid_t speaker_dacs[5];
243
244         int volume_offset;
245
246         /* capture */
247         const hda_nid_t *adc_nids;
248         unsigned int num_adcs;
249         const hda_nid_t *mux_nids;
250         unsigned int num_muxes;
251         const hda_nid_t *dmic_nids;
252         unsigned int num_dmics;
253         const hda_nid_t *dmux_nids;
254         unsigned int num_dmuxes;
255         const hda_nid_t *smux_nids;
256         unsigned int num_smuxes;
257         unsigned int num_analog_muxes;
258
259         const unsigned long *capvols; /* amp-volume attr: HDA_COMPOSE_AMP_VAL() */
260         const unsigned long *capsws; /* amp-mute attr: HDA_COMPOSE_AMP_VAL() */
261         unsigned int num_caps; /* number of capture volume/switch elements */
262
263         struct sigmatel_mic_route ext_mic;
264         struct sigmatel_mic_route int_mic;
265         struct sigmatel_mic_route dock_mic;
266
267         const char * const *spdif_labels;
268
269         hda_nid_t dig_in_nid;
270         hda_nid_t mono_nid;
271         hda_nid_t anabeep_nid;
272         hda_nid_t digbeep_nid;
273
274         /* pin widgets */
275         const hda_nid_t *pin_nids;
276         unsigned int num_pins;
277
278         /* codec specific stuff */
279         const struct hda_verb *init;
280         const struct snd_kcontrol_new *mixer;
281
282         /* capture source */
283         struct hda_input_mux *dinput_mux;
284         unsigned int cur_dmux[2];
285         struct hda_input_mux *input_mux;
286         unsigned int cur_mux[3];
287         struct hda_input_mux *sinput_mux;
288         unsigned int cur_smux[2];
289         unsigned int cur_amux;
290         hda_nid_t *amp_nids;
291         unsigned int powerdown_adcs;
292
293         /* i/o switches */
294         unsigned int io_switch[2];
295         unsigned int clfe_swap;
296         hda_nid_t line_switch;  /* shared line-in for input and output */
297         hda_nid_t mic_switch;   /* shared mic-in for input and output */
298         hda_nid_t hp_switch; /* NID of HP as line-out */
299         unsigned int aloopback;
300
301         struct hda_pcm pcm_rec[2];      /* PCM information */
302
303         /* dynamic controls and input_mux */
304         struct auto_pin_cfg autocfg;
305         struct snd_array kctls;
306         struct hda_input_mux private_dimux;
307         struct hda_input_mux private_imux;
308         struct hda_input_mux private_smux;
309         struct hda_input_mux private_mono_mux;
310
311         /* auto spec */
312         unsigned auto_pin_cnt;
313         hda_nid_t auto_pin_nids[MAX_PINS_NUM];
314         unsigned auto_adc_cnt;
315         hda_nid_t auto_adc_nids[MAX_ADCS_NUM];
316         hda_nid_t auto_mux_nids[MAX_ADCS_NUM];
317         hda_nid_t auto_dmux_nids[MAX_ADCS_NUM];
318         unsigned long auto_capvols[MAX_ADCS_NUM];
319         unsigned auto_dmic_cnt;
320         hda_nid_t auto_dmic_nids[MAX_DMICS_NUM];
321 };
322
323 static const hda_nid_t stac9200_adc_nids[1] = {
324         0x03,
325 };
326
327 static const hda_nid_t stac9200_mux_nids[1] = {
328         0x0c,
329 };
330
331 static const hda_nid_t stac9200_dac_nids[1] = {
332         0x02,
333 };
334
335 static const hda_nid_t stac92hd73xx_pwr_nids[8] = {
336         0x0a, 0x0b, 0x0c, 0xd, 0x0e,
337         0x0f, 0x10, 0x11
338 };
339
340 static const hda_nid_t stac92hd73xx_slave_dig_outs[2] = {
341         0x26, 0,
342 };
343
344 static const hda_nid_t stac92hd73xx_adc_nids[2] = {
345         0x1a, 0x1b
346 };
347
348 #define STAC92HD73XX_NUM_DMICS  2
349 static const hda_nid_t stac92hd73xx_dmic_nids[STAC92HD73XX_NUM_DMICS + 1] = {
350         0x13, 0x14, 0
351 };
352
353 #define STAC92HD73_DAC_COUNT 5
354
355 static const hda_nid_t stac92hd73xx_mux_nids[2] = {
356         0x20, 0x21,
357 };
358
359 static const hda_nid_t stac92hd73xx_dmux_nids[2] = {
360         0x20, 0x21,
361 };
362
363 static const hda_nid_t stac92hd73xx_smux_nids[2] = {
364         0x22, 0x23,
365 };
366
367 #define STAC92HD73XX_NUM_CAPS   2
368 static const unsigned long stac92hd73xx_capvols[] = {
369         HDA_COMPOSE_AMP_VAL(0x20, 3, 0, HDA_OUTPUT),
370         HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
371 };
372 #define stac92hd73xx_capsws     stac92hd73xx_capvols
373
374 #define STAC92HD83_DAC_COUNT 3
375
376 static const hda_nid_t stac92hd83xxx_pwr_nids[7] = {
377         0x0a, 0x0b, 0x0c, 0xd, 0x0e,
378         0x0f, 0x10
379 };
380
381 static const hda_nid_t stac92hd83xxx_slave_dig_outs[2] = {
382         0x1e, 0,
383 };
384
385 static const hda_nid_t stac92hd83xxx_dmic_nids[] = {
386                 0x11, 0x20,
387 };
388
389 static const hda_nid_t stac92hd71bxx_pwr_nids[3] = {
390         0x0a, 0x0d, 0x0f
391 };
392
393 static const hda_nid_t stac92hd71bxx_adc_nids[2] = {
394         0x12, 0x13,
395 };
396
397 static const hda_nid_t stac92hd71bxx_mux_nids[2] = {
398         0x1a, 0x1b
399 };
400
401 static const hda_nid_t stac92hd71bxx_dmux_nids[2] = {
402         0x1c, 0x1d,
403 };
404
405 static const hda_nid_t stac92hd71bxx_smux_nids[2] = {
406         0x24, 0x25,
407 };
408
409 #define STAC92HD71BXX_NUM_DMICS 2
410 static const hda_nid_t stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS + 1] = {
411         0x18, 0x19, 0
412 };
413
414 static const hda_nid_t stac92hd71bxx_dmic_5port_nids[STAC92HD71BXX_NUM_DMICS] = {
415         0x18, 0
416 };
417
418 static const hda_nid_t stac92hd71bxx_slave_dig_outs[2] = {
419         0x22, 0
420 };
421
422 #define STAC92HD71BXX_NUM_CAPS          2
423 static const unsigned long stac92hd71bxx_capvols[] = {
424         HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
425         HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
426 };
427 #define stac92hd71bxx_capsws    stac92hd71bxx_capvols
428
429 static const hda_nid_t stac925x_adc_nids[1] = {
430         0x03,
431 };
432
433 static const hda_nid_t stac925x_mux_nids[1] = {
434         0x0f,
435 };
436
437 static const hda_nid_t stac925x_dac_nids[1] = {
438         0x02,
439 };
440
441 #define STAC925X_NUM_DMICS      1
442 static const hda_nid_t stac925x_dmic_nids[STAC925X_NUM_DMICS + 1] = {
443         0x15, 0
444 };
445
446 static const hda_nid_t stac925x_dmux_nids[1] = {
447         0x14,
448 };
449
450 static const unsigned long stac925x_capvols[] = {
451         HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
452 };
453 static const unsigned long stac925x_capsws[] = {
454         HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
455 };
456
457 static const hda_nid_t stac922x_adc_nids[2] = {
458         0x06, 0x07,
459 };
460
461 static const hda_nid_t stac922x_mux_nids[2] = {
462         0x12, 0x13,
463 };
464
465 #define STAC922X_NUM_CAPS       2
466 static const unsigned long stac922x_capvols[] = {
467         HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_INPUT),
468         HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT),
469 };
470 #define stac922x_capsws         stac922x_capvols
471
472 static const hda_nid_t stac927x_slave_dig_outs[2] = {
473         0x1f, 0,
474 };
475
476 static const hda_nid_t stac927x_adc_nids[3] = {
477         0x07, 0x08, 0x09
478 };
479
480 static const hda_nid_t stac927x_mux_nids[3] = {
481         0x15, 0x16, 0x17
482 };
483
484 static const hda_nid_t stac927x_smux_nids[1] = {
485         0x21,
486 };
487
488 static const hda_nid_t stac927x_dac_nids[6] = {
489         0x02, 0x03, 0x04, 0x05, 0x06, 0
490 };
491
492 static const hda_nid_t stac927x_dmux_nids[1] = {
493         0x1b,
494 };
495
496 #define STAC927X_NUM_DMICS 2
497 static const hda_nid_t stac927x_dmic_nids[STAC927X_NUM_DMICS + 1] = {
498         0x13, 0x14, 0
499 };
500
501 #define STAC927X_NUM_CAPS       3
502 static const unsigned long stac927x_capvols[] = {
503         HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT),
504         HDA_COMPOSE_AMP_VAL(0x19, 3, 0, HDA_INPUT),
505         HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_INPUT),
506 };
507 static const unsigned long stac927x_capsws[] = {
508         HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
509         HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
510         HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
511 };
512
513 static const char * const stac927x_spdif_labels[5] = {
514         "Digital Playback", "ADAT", "Analog Mux 1",
515         "Analog Mux 2", "Analog Mux 3"
516 };
517
518 static const hda_nid_t stac9205_adc_nids[2] = {
519         0x12, 0x13
520 };
521
522 static const hda_nid_t stac9205_mux_nids[2] = {
523         0x19, 0x1a
524 };
525
526 static const hda_nid_t stac9205_dmux_nids[1] = {
527         0x1d,
528 };
529
530 static const hda_nid_t stac9205_smux_nids[1] = {
531         0x21,
532 };
533
534 #define STAC9205_NUM_DMICS      2
535 static const hda_nid_t stac9205_dmic_nids[STAC9205_NUM_DMICS + 1] = {
536         0x17, 0x18, 0
537 };
538
539 #define STAC9205_NUM_CAPS       2
540 static const unsigned long stac9205_capvols[] = {
541         HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_INPUT),
542         HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_INPUT),
543 };
544 static const unsigned long stac9205_capsws[] = {
545         HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
546         HDA_COMPOSE_AMP_VAL(0x1e, 3, 0, HDA_OUTPUT),
547 };
548
549 static const hda_nid_t stac9200_pin_nids[8] = {
550         0x08, 0x09, 0x0d, 0x0e, 
551         0x0f, 0x10, 0x11, 0x12,
552 };
553
554 static const hda_nid_t stac925x_pin_nids[8] = {
555         0x07, 0x08, 0x0a, 0x0b, 
556         0x0c, 0x0d, 0x10, 0x11,
557 };
558
559 static const hda_nid_t stac922x_pin_nids[10] = {
560         0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
561         0x0f, 0x10, 0x11, 0x15, 0x1b,
562 };
563
564 static const hda_nid_t stac92hd73xx_pin_nids[13] = {
565         0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
566         0x0f, 0x10, 0x11, 0x12, 0x13,
567         0x14, 0x22, 0x23
568 };
569
570 #define STAC92HD71BXX_NUM_PINS 13
571 static const hda_nid_t stac92hd71bxx_pin_nids_4port[STAC92HD71BXX_NUM_PINS] = {
572         0x0a, 0x0b, 0x0c, 0x0d, 0x00,
573         0x00, 0x14, 0x18, 0x19, 0x1e,
574         0x1f, 0x20, 0x27
575 };
576 static const hda_nid_t stac92hd71bxx_pin_nids_6port[STAC92HD71BXX_NUM_PINS] = {
577         0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
578         0x0f, 0x14, 0x18, 0x19, 0x1e,
579         0x1f, 0x20, 0x27
580 };
581
582 static const hda_nid_t stac927x_pin_nids[14] = {
583         0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
584         0x0f, 0x10, 0x11, 0x12, 0x13,
585         0x14, 0x21, 0x22, 0x23,
586 };
587
588 static const hda_nid_t stac9205_pin_nids[12] = {
589         0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
590         0x0f, 0x14, 0x16, 0x17, 0x18,
591         0x21, 0x22,
592 };
593
594 static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
595                                    struct snd_ctl_elem_info *uinfo)
596 {
597         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
598         struct sigmatel_spec *spec = codec->spec;
599         return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
600 }
601
602 static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
603                                   struct snd_ctl_elem_value *ucontrol)
604 {
605         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
606         struct sigmatel_spec *spec = codec->spec;
607         unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
608
609         ucontrol->value.enumerated.item[0] = spec->cur_dmux[dmux_idx];
610         return 0;
611 }
612
613 static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
614                                   struct snd_ctl_elem_value *ucontrol)
615 {
616         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
617         struct sigmatel_spec *spec = codec->spec;
618         unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
619
620         return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
621                         spec->dmux_nids[dmux_idx], &spec->cur_dmux[dmux_idx]);
622 }
623
624 static int stac92xx_smux_enum_info(struct snd_kcontrol *kcontrol,
625                                    struct snd_ctl_elem_info *uinfo)
626 {
627         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
628         struct sigmatel_spec *spec = codec->spec;
629         return snd_hda_input_mux_info(spec->sinput_mux, uinfo);
630 }
631
632 static int stac92xx_smux_enum_get(struct snd_kcontrol *kcontrol,
633                                   struct snd_ctl_elem_value *ucontrol)
634 {
635         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
636         struct sigmatel_spec *spec = codec->spec;
637         unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
638
639         ucontrol->value.enumerated.item[0] = spec->cur_smux[smux_idx];
640         return 0;
641 }
642
643 static int stac92xx_smux_enum_put(struct snd_kcontrol *kcontrol,
644                                   struct snd_ctl_elem_value *ucontrol)
645 {
646         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
647         struct sigmatel_spec *spec = codec->spec;
648         struct hda_input_mux *smux = &spec->private_smux;
649         unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
650         int err, val;
651         hda_nid_t nid;
652
653         err = snd_hda_input_mux_put(codec, spec->sinput_mux, ucontrol,
654                         spec->smux_nids[smux_idx], &spec->cur_smux[smux_idx]);
655         if (err < 0)
656                 return err;
657
658         if (spec->spdif_mute) {
659                 if (smux_idx == 0)
660                         nid = spec->multiout.dig_out_nid;
661                 else
662                         nid = codec->slave_dig_outs[smux_idx - 1];
663                 if (spec->cur_smux[smux_idx] == smux->num_items - 1)
664                         val = HDA_AMP_MUTE;
665                 else
666                         val = 0;
667                 /* un/mute SPDIF out */
668                 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
669                                          HDA_AMP_MUTE, val);
670         }
671         return 0;
672 }
673
674 #ifdef CONFIG_SND_HDA_POWER_SAVE
675 static int stac_vrefout_set(struct hda_codec *codec,
676                                         hda_nid_t nid, unsigned int new_vref)
677 {
678         int error, pinctl;
679
680         snd_printdd("%s, nid %x ctl %x\n", __func__, nid, new_vref);
681         pinctl = snd_hda_codec_read(codec, nid, 0,
682                                 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
683
684         if (pinctl < 0)
685                 return pinctl;
686
687         pinctl &= 0xff;
688         pinctl &= ~AC_PINCTL_VREFEN;
689         pinctl |= (new_vref & AC_PINCTL_VREFEN);
690
691         error = snd_hda_codec_write_cache(codec, nid, 0,
692                                         AC_VERB_SET_PIN_WIDGET_CONTROL, pinctl);
693         if (error < 0)
694                 return error;
695
696         return 1;
697 }
698 #endif
699
700 static unsigned int stac92xx_vref_set(struct hda_codec *codec,
701                                         hda_nid_t nid, unsigned int new_vref)
702 {
703         int error;
704         unsigned int pincfg;
705         pincfg = snd_hda_codec_read(codec, nid, 0,
706                                 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
707
708         pincfg &= 0xff;
709         pincfg &= ~(AC_PINCTL_VREFEN | AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
710         pincfg |= new_vref;
711
712         if (new_vref == AC_PINCTL_VREF_HIZ)
713                 pincfg |= AC_PINCTL_OUT_EN;
714         else
715                 pincfg |= AC_PINCTL_IN_EN;
716
717         error = snd_hda_codec_write_cache(codec, nid, 0,
718                                         AC_VERB_SET_PIN_WIDGET_CONTROL, pincfg);
719         if (error < 0)
720                 return error;
721         else
722                 return 1;
723 }
724
725 static unsigned int stac92xx_vref_get(struct hda_codec *codec, hda_nid_t nid)
726 {
727         unsigned int vref;
728         vref = snd_hda_codec_read(codec, nid, 0,
729                                 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
730         vref &= AC_PINCTL_VREFEN;
731         return vref;
732 }
733
734 static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
735 {
736         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
737         struct sigmatel_spec *spec = codec->spec;
738         return snd_hda_input_mux_info(spec->input_mux, uinfo);
739 }
740
741 static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
742 {
743         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
744         struct sigmatel_spec *spec = codec->spec;
745         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
746
747         ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
748         return 0;
749 }
750
751 static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
752 {
753         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
754         struct sigmatel_spec *spec = codec->spec;
755         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
756         const struct hda_input_mux *imux = spec->input_mux;
757         unsigned int idx, prev_idx, didx;
758
759         idx = ucontrol->value.enumerated.item[0];
760         if (idx >= imux->num_items)
761                 idx = imux->num_items - 1;
762         prev_idx = spec->cur_mux[adc_idx];
763         if (prev_idx == idx)
764                 return 0;
765         if (idx < spec->num_analog_muxes) {
766                 snd_hda_codec_write_cache(codec, spec->mux_nids[adc_idx], 0,
767                                           AC_VERB_SET_CONNECT_SEL,
768                                           imux->items[idx].index);
769                 if (prev_idx >= spec->num_analog_muxes &&
770                     spec->mux_nids[adc_idx] != spec->dmux_nids[adc_idx]) {
771                         imux = spec->dinput_mux;
772                         /* 0 = analog */
773                         snd_hda_codec_write_cache(codec,
774                                                   spec->dmux_nids[adc_idx], 0,
775                                                   AC_VERB_SET_CONNECT_SEL,
776                                                   imux->items[0].index);
777                 }
778         } else {
779                 imux = spec->dinput_mux;
780                 /* first dimux item is hardcoded to select analog imux,
781                  * so lets skip it
782                  */
783                 didx = idx - spec->num_analog_muxes + 1;
784                 snd_hda_codec_write_cache(codec, spec->dmux_nids[adc_idx], 0,
785                                           AC_VERB_SET_CONNECT_SEL,
786                                           imux->items[didx].index);
787         }
788         spec->cur_mux[adc_idx] = idx;
789         return 1;
790 }
791
792 static int stac92xx_mono_mux_enum_info(struct snd_kcontrol *kcontrol,
793         struct snd_ctl_elem_info *uinfo)
794 {
795         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
796         struct sigmatel_spec *spec = codec->spec;
797         return snd_hda_input_mux_info(spec->mono_mux, uinfo);
798 }
799
800 static int stac92xx_mono_mux_enum_get(struct snd_kcontrol *kcontrol,
801         struct snd_ctl_elem_value *ucontrol)
802 {
803         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
804         struct sigmatel_spec *spec = codec->spec;
805
806         ucontrol->value.enumerated.item[0] = spec->cur_mmux;
807         return 0;
808 }
809
810 static int stac92xx_mono_mux_enum_put(struct snd_kcontrol *kcontrol,
811         struct snd_ctl_elem_value *ucontrol)
812 {
813         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
814         struct sigmatel_spec *spec = codec->spec;
815
816         return snd_hda_input_mux_put(codec, spec->mono_mux, ucontrol,
817                                      spec->mono_nid, &spec->cur_mmux);
818 }
819
820 #define stac92xx_aloopback_info snd_ctl_boolean_mono_info
821
822 static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol,
823         struct snd_ctl_elem_value *ucontrol)
824 {
825         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
826         unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
827         struct sigmatel_spec *spec = codec->spec;
828
829         ucontrol->value.integer.value[0] = !!(spec->aloopback &
830                                               (spec->aloopback_mask << idx));
831         return 0;
832 }
833
834 static int stac92xx_aloopback_put(struct snd_kcontrol *kcontrol,
835                 struct snd_ctl_elem_value *ucontrol)
836 {
837         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
838         struct sigmatel_spec *spec = codec->spec;
839         unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
840         unsigned int dac_mode;
841         unsigned int val, idx_val;
842
843         idx_val = spec->aloopback_mask << idx;
844         if (ucontrol->value.integer.value[0])
845                 val = spec->aloopback | idx_val;
846         else
847                 val = spec->aloopback & ~idx_val;
848         if (spec->aloopback == val)
849                 return 0;
850
851         spec->aloopback = val;
852
853         /* Only return the bits defined by the shift value of the
854          * first two bytes of the mask
855          */
856         dac_mode = snd_hda_codec_read(codec, codec->afg, 0,
857                                       kcontrol->private_value & 0xFFFF, 0x0);
858         dac_mode >>= spec->aloopback_shift;
859
860         if (spec->aloopback & idx_val) {
861                 snd_hda_power_up(codec);
862                 dac_mode |= idx_val;
863         } else {
864                 snd_hda_power_down(codec);
865                 dac_mode &= ~idx_val;
866         }
867
868         snd_hda_codec_write_cache(codec, codec->afg, 0,
869                 kcontrol->private_value >> 16, dac_mode);
870
871         return 1;
872 }
873
874 static const struct hda_verb stac9200_core_init[] = {
875         /* set dac0mux for dac converter */
876         { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
877         {}
878 };
879
880 static const struct hda_verb stac9200_eapd_init[] = {
881         /* set dac0mux for dac converter */
882         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
883         {0x08, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
884         {}
885 };
886
887 static const struct hda_verb dell_eq_core_init[] = {
888         /* set master volume to max value without distortion
889          * and direct control */
890         { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xec},
891         {}
892 };
893
894 static const struct hda_verb stac92hd73xx_core_init[] = {
895         /* set master volume and direct control */
896         { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
897         {}
898 };
899
900 static const struct hda_verb stac92hd83xxx_core_init[] = {
901         /* power state controls amps */
902         { 0x01, AC_VERB_SET_EAPD, 1 << 2},
903         {}
904 };
905
906 static const struct hda_verb stac92hd71bxx_core_init[] = {
907         /* set master volume and direct control */
908         { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
909         {}
910 };
911
912 static const struct hda_verb stac92hd71bxx_unmute_core_init[] = {
913         /* unmute right and left channels for nodes 0x0f, 0xa, 0x0d */
914         { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
915         { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
916         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
917         {}
918 };
919
920 static const struct hda_verb stac925x_core_init[] = {
921         /* set dac0mux for dac converter */
922         { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
923         /* mute the master volume */
924         { 0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
925         {}
926 };
927
928 static const struct hda_verb stac922x_core_init[] = {
929         /* set master volume and direct control */      
930         { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
931         {}
932 };
933
934 static const struct hda_verb d965_core_init[] = {
935         /* set master volume and direct control */      
936         { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
937         /* unmute node 0x1b */
938         { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
939         /* select node 0x03 as DAC */   
940         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
941         {}
942 };
943
944 static const struct hda_verb dell_3st_core_init[] = {
945         /* don't set delta bit */
946         {0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0x7f},
947         /* unmute node 0x1b */
948         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
949         /* select node 0x03 as DAC */
950         {0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
951         {}
952 };
953
954 static const struct hda_verb stac927x_core_init[] = {
955         /* set master volume and direct control */      
956         { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
957         /* enable analog pc beep path */
958         { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
959         {}
960 };
961
962 static const struct hda_verb stac927x_volknob_core_init[] = {
963         /* don't set delta bit */
964         {0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0x7f},
965         /* enable analog pc beep path */
966         {0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
967         {}
968 };
969
970 static const struct hda_verb stac9205_core_init[] = {
971         /* set master volume and direct control */      
972         { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
973         /* enable analog pc beep path */
974         { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
975         {}
976 };
977
978 #define STAC_MONO_MUX \
979         { \
980                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
981                 .name = "Mono Mux", \
982                 .count = 1, \
983                 .info = stac92xx_mono_mux_enum_info, \
984                 .get = stac92xx_mono_mux_enum_get, \
985                 .put = stac92xx_mono_mux_enum_put, \
986         }
987
988 #define STAC_ANALOG_LOOPBACK(verb_read, verb_write, cnt) \
989         { \
990                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
991                 .name  = "Analog Loopback", \
992                 .count = cnt, \
993                 .info  = stac92xx_aloopback_info, \
994                 .get   = stac92xx_aloopback_get, \
995                 .put   = stac92xx_aloopback_put, \
996                 .private_value = verb_read | (verb_write << 16), \
997         }
998
999 #define DC_BIAS(xname, idx, nid) \
1000         { \
1001                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1002                 .name = xname, \
1003                 .index = idx, \
1004                 .info = stac92xx_dc_bias_info, \
1005                 .get = stac92xx_dc_bias_get, \
1006                 .put = stac92xx_dc_bias_put, \
1007                 .private_value = nid, \
1008         }
1009
1010 static const struct snd_kcontrol_new stac9200_mixer[] = {
1011         HDA_CODEC_VOLUME_MIN_MUTE("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
1012         HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
1013         HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
1014         HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
1015         { } /* end */
1016 };
1017
1018 static const struct snd_kcontrol_new stac92hd73xx_6ch_loopback[] = {
1019         STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 3),
1020         {}
1021 };
1022
1023 static const struct snd_kcontrol_new stac92hd73xx_8ch_loopback[] = {
1024         STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 4),
1025         {}
1026 };
1027
1028 static const struct snd_kcontrol_new stac92hd73xx_10ch_loopback[] = {
1029         STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 5),
1030         {}
1031 };
1032
1033
1034 static const struct snd_kcontrol_new stac92hd71bxx_loopback[] = {
1035         STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2)
1036 };
1037
1038 static const struct snd_kcontrol_new stac925x_mixer[] = {
1039         HDA_CODEC_VOLUME_MIN_MUTE("Master Playback Volume", 0xe, 0, HDA_OUTPUT),
1040         HDA_CODEC_MUTE("Master Playback Switch", 0x0e, 0, HDA_OUTPUT),
1041         { } /* end */
1042 };
1043
1044 static const struct snd_kcontrol_new stac9205_loopback[] = {
1045         STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0, 1),
1046         {}
1047 };
1048
1049 static const struct snd_kcontrol_new stac927x_loopback[] = {
1050         STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB, 1),
1051         {}
1052 };
1053
1054 static struct snd_kcontrol_new stac_dmux_mixer = {
1055         .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1056         .name = "Digital Input Source",
1057         /* count set later */
1058         .info = stac92xx_dmux_enum_info,
1059         .get = stac92xx_dmux_enum_get,
1060         .put = stac92xx_dmux_enum_put,
1061 };
1062
1063 static struct snd_kcontrol_new stac_smux_mixer = {
1064         .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1065         .name = "IEC958 Playback Source",
1066         /* count set later */
1067         .info = stac92xx_smux_enum_info,
1068         .get = stac92xx_smux_enum_get,
1069         .put = stac92xx_smux_enum_put,
1070 };
1071
1072 static const char * const slave_vols[] = {
1073         "Front Playback Volume",
1074         "Surround Playback Volume",
1075         "Center Playback Volume",
1076         "LFE Playback Volume",
1077         "Side Playback Volume",
1078         "Headphone Playback Volume",
1079         "Speaker Playback Volume",
1080         NULL
1081 };
1082
1083 static const char * const slave_sws[] = {
1084         "Front Playback Switch",
1085         "Surround Playback Switch",
1086         "Center Playback Switch",
1087         "LFE Playback Switch",
1088         "Side Playback Switch",
1089         "Headphone Playback Switch",
1090         "Speaker Playback Switch",
1091         "IEC958 Playback Switch",
1092         NULL
1093 };
1094
1095 static void stac92xx_free_kctls(struct hda_codec *codec);
1096 static int stac92xx_add_jack(struct hda_codec *codec, hda_nid_t nid, int type);
1097
1098 static int stac92xx_build_controls(struct hda_codec *codec)
1099 {
1100         struct sigmatel_spec *spec = codec->spec;
1101         struct auto_pin_cfg *cfg = &spec->autocfg;
1102         hda_nid_t nid;
1103         int err;
1104         int i;
1105
1106         if (spec->mixer) {
1107                 err = snd_hda_add_new_ctls(codec, spec->mixer);
1108                 if (err < 0)
1109                         return err;
1110         }
1111
1112         for (i = 0; i < spec->num_mixers; i++) {
1113                 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1114                 if (err < 0)
1115                         return err;
1116         }
1117         if (!spec->auto_mic && spec->num_dmuxes > 0 &&
1118             snd_hda_get_bool_hint(codec, "separate_dmux") == 1) {
1119                 stac_dmux_mixer.count = spec->num_dmuxes;
1120                 err = snd_hda_ctl_add(codec, 0,
1121                                   snd_ctl_new1(&stac_dmux_mixer, codec));
1122                 if (err < 0)
1123                         return err;
1124         }
1125         if (spec->num_smuxes > 0) {
1126                 int wcaps = get_wcaps(codec, spec->multiout.dig_out_nid);
1127                 struct hda_input_mux *smux = &spec->private_smux;
1128                 /* check for mute support on SPDIF out */
1129                 if (wcaps & AC_WCAP_OUT_AMP) {
1130                         snd_hda_add_imux_item(smux, "Off", 0, NULL);
1131                         spec->spdif_mute = 1;
1132                 }
1133                 stac_smux_mixer.count = spec->num_smuxes;
1134                 err = snd_hda_ctl_add(codec, 0,
1135                                   snd_ctl_new1(&stac_smux_mixer, codec));
1136                 if (err < 0)
1137                         return err;
1138         }
1139
1140         if (spec->multiout.dig_out_nid) {
1141                 err = snd_hda_create_spdif_out_ctls(codec,
1142                                                     spec->multiout.dig_out_nid,
1143                                                     spec->multiout.dig_out_nid);
1144                 if (err < 0)
1145                         return err;
1146                 err = snd_hda_create_spdif_share_sw(codec,
1147                                                     &spec->multiout);
1148                 if (err < 0)
1149                         return err;
1150                 spec->multiout.share_spdif = 1;
1151         }
1152         if (spec->dig_in_nid && !(spec->gpio_dir & 0x01)) {
1153                 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1154                 if (err < 0)
1155                         return err;
1156         }
1157
1158         /* if we have no master control, let's create it */
1159         if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1160                 unsigned int vmaster_tlv[4];
1161                 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
1162                                         HDA_OUTPUT, vmaster_tlv);
1163                 /* correct volume offset */
1164                 vmaster_tlv[2] += vmaster_tlv[3] * spec->volume_offset;
1165                 /* minimum value is actually mute */
1166                 vmaster_tlv[3] |= TLV_DB_SCALE_MUTE;
1167                 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1168                                           vmaster_tlv, slave_vols);
1169                 if (err < 0)
1170                         return err;
1171         }
1172         if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1173                 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1174                                           NULL, slave_sws);
1175                 if (err < 0)
1176                         return err;
1177         }
1178
1179         if (spec->aloopback_ctl &&
1180             snd_hda_get_bool_hint(codec, "loopback") == 1) {
1181                 err = snd_hda_add_new_ctls(codec, spec->aloopback_ctl);
1182                 if (err < 0)
1183                         return err;
1184         }
1185
1186         stac92xx_free_kctls(codec); /* no longer needed */
1187
1188         /* create jack input elements */
1189         if (spec->hp_detect) {
1190                 for (i = 0; i < cfg->hp_outs; i++) {
1191                         int type = SND_JACK_HEADPHONE;
1192                         nid = cfg->hp_pins[i];
1193                         /* jack detection */
1194                         if (cfg->hp_outs == i)
1195                                 type |= SND_JACK_LINEOUT;
1196                         err = stac92xx_add_jack(codec, nid, type);
1197                         if (err < 0)
1198                                 return err;
1199                 }
1200         }
1201         for (i = 0; i < cfg->line_outs; i++) {
1202                 err = stac92xx_add_jack(codec, cfg->line_out_pins[i],
1203                                         SND_JACK_LINEOUT);
1204                 if (err < 0)
1205                         return err;
1206         }
1207         for (i = 0; i < cfg->num_inputs; i++) {
1208                 nid = cfg->inputs[i].pin;
1209                 err = stac92xx_add_jack(codec, nid, SND_JACK_MICROPHONE);
1210                 if (err < 0)
1211                         return err;
1212         }
1213
1214         return 0;       
1215 }
1216
1217 static const unsigned int ref9200_pin_configs[8] = {
1218         0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
1219         0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
1220 };
1221
1222 static const unsigned int gateway9200_m4_pin_configs[8] = {
1223         0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1224         0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1225 };
1226 static const unsigned int gateway9200_m4_2_pin_configs[8] = {
1227         0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1228         0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1229 };
1230
1231 /*
1232     STAC 9200 pin configs for
1233     102801A8
1234     102801DE
1235     102801E8
1236 */
1237 static const unsigned int dell9200_d21_pin_configs[8] = {
1238         0x400001f0, 0x400001f1, 0x02214030, 0x01014010, 
1239         0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
1240 };
1241
1242 /* 
1243     STAC 9200 pin configs for
1244     102801C0
1245     102801C1
1246 */
1247 static const unsigned int dell9200_d22_pin_configs[8] = {
1248         0x400001f0, 0x400001f1, 0x0221401f, 0x01014010, 
1249         0x01813020, 0x02a19021, 0x90100140, 0x400001f2,
1250 };
1251
1252 /* 
1253     STAC 9200 pin configs for
1254     102801C4 (Dell Dimension E310)
1255     102801C5
1256     102801C7
1257     102801D9
1258     102801DA
1259     102801E3
1260 */
1261 static const unsigned int dell9200_d23_pin_configs[8] = {
1262         0x400001f0, 0x400001f1, 0x0221401f, 0x01014010, 
1263         0x01813020, 0x01a19021, 0x90100140, 0x400001f2, 
1264 };
1265
1266
1267 /* 
1268     STAC 9200-32 pin configs for
1269     102801B5 (Dell Inspiron 630m)
1270     102801D8 (Dell Inspiron 640m)
1271 */
1272 static const unsigned int dell9200_m21_pin_configs[8] = {
1273         0x40c003fa, 0x03441340, 0x0321121f, 0x90170310,
1274         0x408003fb, 0x03a11020, 0x401003fc, 0x403003fd,
1275 };
1276
1277 /* 
1278     STAC 9200-32 pin configs for
1279     102801C2 (Dell Latitude D620)
1280     102801C8 
1281     102801CC (Dell Latitude D820)
1282     102801D4 
1283     102801D6 
1284 */
1285 static const unsigned int dell9200_m22_pin_configs[8] = {
1286         0x40c003fa, 0x0144131f, 0x0321121f, 0x90170310, 
1287         0x90a70321, 0x03a11020, 0x401003fb, 0x40f000fc,
1288 };
1289
1290 /* 
1291     STAC 9200-32 pin configs for
1292     102801CE (Dell XPS M1710)
1293     102801CF (Dell Precision M90)
1294 */
1295 static const unsigned int dell9200_m23_pin_configs[8] = {
1296         0x40c003fa, 0x01441340, 0x0421421f, 0x90170310,
1297         0x408003fb, 0x04a1102e, 0x90170311, 0x403003fc,
1298 };
1299
1300 /*
1301     STAC 9200-32 pin configs for 
1302     102801C9
1303     102801CA
1304     102801CB (Dell Latitude 120L)
1305     102801D3
1306 */
1307 static const unsigned int dell9200_m24_pin_configs[8] = {
1308         0x40c003fa, 0x404003fb, 0x0321121f, 0x90170310, 
1309         0x408003fc, 0x03a11020, 0x401003fd, 0x403003fe, 
1310 };
1311
1312 /*
1313     STAC 9200-32 pin configs for
1314     102801BD (Dell Inspiron E1505n)
1315     102801EE
1316     102801EF
1317 */
1318 static const unsigned int dell9200_m25_pin_configs[8] = {
1319         0x40c003fa, 0x01441340, 0x0421121f, 0x90170310, 
1320         0x408003fb, 0x04a11020, 0x401003fc, 0x403003fd,
1321 };
1322
1323 /*
1324     STAC 9200-32 pin configs for
1325     102801F5 (Dell Inspiron 1501)
1326     102801F6
1327 */
1328 static const unsigned int dell9200_m26_pin_configs[8] = {
1329         0x40c003fa, 0x404003fb, 0x0421121f, 0x90170310, 
1330         0x408003fc, 0x04a11020, 0x401003fd, 0x403003fe,
1331 };
1332
1333 /*
1334     STAC 9200-32
1335     102801CD (Dell Inspiron E1705/9400)
1336 */
1337 static const unsigned int dell9200_m27_pin_configs[8] = {
1338         0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1339         0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
1340 };
1341
1342 static const unsigned int oqo9200_pin_configs[8] = {
1343         0x40c000f0, 0x404000f1, 0x0221121f, 0x02211210,
1344         0x90170111, 0x90a70120, 0x400000f2, 0x400000f3,
1345 };
1346
1347
1348 static const unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
1349         [STAC_REF] = ref9200_pin_configs,
1350         [STAC_9200_OQO] = oqo9200_pin_configs,
1351         [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
1352         [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
1353         [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
1354         [STAC_9200_DELL_M21] = dell9200_m21_pin_configs,
1355         [STAC_9200_DELL_M22] = dell9200_m22_pin_configs,
1356         [STAC_9200_DELL_M23] = dell9200_m23_pin_configs,
1357         [STAC_9200_DELL_M24] = dell9200_m24_pin_configs,
1358         [STAC_9200_DELL_M25] = dell9200_m25_pin_configs,
1359         [STAC_9200_DELL_M26] = dell9200_m26_pin_configs,
1360         [STAC_9200_DELL_M27] = dell9200_m27_pin_configs,
1361         [STAC_9200_M4] = gateway9200_m4_pin_configs,
1362         [STAC_9200_M4_2] = gateway9200_m4_2_pin_configs,
1363         [STAC_9200_PANASONIC] = ref9200_pin_configs,
1364 };
1365
1366 static const char * const stac9200_models[STAC_9200_MODELS] = {
1367         [STAC_AUTO] = "auto",
1368         [STAC_REF] = "ref",
1369         [STAC_9200_OQO] = "oqo",
1370         [STAC_9200_DELL_D21] = "dell-d21",
1371         [STAC_9200_DELL_D22] = "dell-d22",
1372         [STAC_9200_DELL_D23] = "dell-d23",
1373         [STAC_9200_DELL_M21] = "dell-m21",
1374         [STAC_9200_DELL_M22] = "dell-m22",
1375         [STAC_9200_DELL_M23] = "dell-m23",
1376         [STAC_9200_DELL_M24] = "dell-m24",
1377         [STAC_9200_DELL_M25] = "dell-m25",
1378         [STAC_9200_DELL_M26] = "dell-m26",
1379         [STAC_9200_DELL_M27] = "dell-m27",
1380         [STAC_9200_M4] = "gateway-m4",
1381         [STAC_9200_M4_2] = "gateway-m4-2",
1382         [STAC_9200_PANASONIC] = "panasonic",
1383 };
1384
1385 static const struct snd_pci_quirk stac9200_cfg_tbl[] = {
1386         /* SigmaTel reference board */
1387         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1388                       "DFI LanParty", STAC_REF),
1389         SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1390                       "DFI LanParty", STAC_REF),
1391         /* Dell laptops have BIOS problem */
1392         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
1393                       "unknown Dell", STAC_9200_DELL_D21),
1394         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
1395                       "Dell Inspiron 630m", STAC_9200_DELL_M21),
1396         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bd,
1397                       "Dell Inspiron E1505n", STAC_9200_DELL_M25),
1398         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c0,
1399                       "unknown Dell", STAC_9200_DELL_D22),
1400         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c1,
1401                       "unknown Dell", STAC_9200_DELL_D22),
1402         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
1403                       "Dell Latitude D620", STAC_9200_DELL_M22),
1404         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c5,
1405                       "unknown Dell", STAC_9200_DELL_D23),
1406         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c7,
1407                       "unknown Dell", STAC_9200_DELL_D23),
1408         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c8,
1409                       "unknown Dell", STAC_9200_DELL_M22),
1410         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c9,
1411                       "unknown Dell", STAC_9200_DELL_M24),
1412         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ca,
1413                       "unknown Dell", STAC_9200_DELL_M24),
1414         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
1415                       "Dell Latitude 120L", STAC_9200_DELL_M24),
1416         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
1417                       "Dell Latitude D820", STAC_9200_DELL_M22),
1418         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
1419                       "Dell Inspiron E1705/9400", STAC_9200_DELL_M27),
1420         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
1421                       "Dell XPS M1710", STAC_9200_DELL_M23),
1422         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
1423                       "Dell Precision M90", STAC_9200_DELL_M23),
1424         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d3,
1425                       "unknown Dell", STAC_9200_DELL_M22),
1426         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d4,
1427                       "unknown Dell", STAC_9200_DELL_M22),
1428         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
1429                       "unknown Dell", STAC_9200_DELL_M22),
1430         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
1431                       "Dell Inspiron 640m", STAC_9200_DELL_M21),
1432         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d9,
1433                       "unknown Dell", STAC_9200_DELL_D23),
1434         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01da,
1435                       "unknown Dell", STAC_9200_DELL_D23),
1436         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01de,
1437                       "unknown Dell", STAC_9200_DELL_D21),
1438         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e3,
1439                       "unknown Dell", STAC_9200_DELL_D23),
1440         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e8,
1441                       "unknown Dell", STAC_9200_DELL_D21),
1442         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ee,
1443                       "unknown Dell", STAC_9200_DELL_M25),
1444         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ef,
1445                       "unknown Dell", STAC_9200_DELL_M25),
1446         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
1447                       "Dell Inspiron 1501", STAC_9200_DELL_M26),
1448         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
1449                       "unknown Dell", STAC_9200_DELL_M26),
1450         /* Panasonic */
1451         SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_9200_PANASONIC),
1452         /* Gateway machines needs EAPD to be set on resume */
1453         SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_M4),
1454         SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*", STAC_9200_M4_2),
1455         SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707", STAC_9200_M4_2),
1456         /* OQO Mobile */
1457         SND_PCI_QUIRK(0x1106, 0x3288, "OQO Model 2", STAC_9200_OQO),
1458         {} /* terminator */
1459 };
1460
1461 static const unsigned int ref925x_pin_configs[8] = {
1462         0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
1463         0x90a70320, 0x02214210, 0x01019020, 0x9033032e,
1464 };
1465
1466 static const unsigned int stac925xM1_pin_configs[8] = {
1467         0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1468         0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1469 };
1470
1471 static const unsigned int stac925xM1_2_pin_configs[8] = {
1472         0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1473         0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1474 };
1475
1476 static const unsigned int stac925xM2_pin_configs[8] = {
1477         0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1478         0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1479 };
1480
1481 static const unsigned int stac925xM2_2_pin_configs[8] = {
1482         0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1483         0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1484 };
1485
1486 static const unsigned int stac925xM3_pin_configs[8] = {
1487         0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1488         0x40a000f0, 0x90100210, 0x400003f1, 0x503303f3,
1489 };
1490
1491 static const unsigned int stac925xM5_pin_configs[8] = {
1492         0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1493         0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1494 };
1495
1496 static const unsigned int stac925xM6_pin_configs[8] = {
1497         0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1498         0x40a000f0, 0x90100210, 0x400003f1, 0x90330320,
1499 };
1500
1501 static const unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
1502         [STAC_REF] = ref925x_pin_configs,
1503         [STAC_M1] = stac925xM1_pin_configs,
1504         [STAC_M1_2] = stac925xM1_2_pin_configs,
1505         [STAC_M2] = stac925xM2_pin_configs,
1506         [STAC_M2_2] = stac925xM2_2_pin_configs,
1507         [STAC_M3] = stac925xM3_pin_configs,
1508         [STAC_M5] = stac925xM5_pin_configs,
1509         [STAC_M6] = stac925xM6_pin_configs,
1510 };
1511
1512 static const char * const stac925x_models[STAC_925x_MODELS] = {
1513         [STAC_925x_AUTO] = "auto",
1514         [STAC_REF] = "ref",
1515         [STAC_M1] = "m1",
1516         [STAC_M1_2] = "m1-2",
1517         [STAC_M2] = "m2",
1518         [STAC_M2_2] = "m2-2",
1519         [STAC_M3] = "m3",
1520         [STAC_M5] = "m5",
1521         [STAC_M6] = "m6",
1522 };
1523
1524 static const struct snd_pci_quirk stac925x_codec_id_cfg_tbl[] = {
1525         SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_M2),
1526         SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_M5),
1527         SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_M1),
1528         SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_M2),
1529         SND_PCI_QUIRK(0x107b, 0x0367, "Gateway MX6453", STAC_M1_2),
1530         /* Not sure about the brand name for those */
1531         SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M1),
1532         SND_PCI_QUIRK(0x107b, 0x0507, "Gateway mobile", STAC_M3),
1533         SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M6),
1534         SND_PCI_QUIRK(0x107b, 0x0685, "Gateway mobile", STAC_M2_2),
1535         {} /* terminator */
1536 };
1537
1538 static const struct snd_pci_quirk stac925x_cfg_tbl[] = {
1539         /* SigmaTel reference board */
1540         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
1541         SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101, "DFI LanParty", STAC_REF),
1542         SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
1543
1544         /* Default table for unknown ID */
1545         SND_PCI_QUIRK(0x1002, 0x437b, "Gateway mobile", STAC_M2_2),
1546
1547         {} /* terminator */
1548 };
1549
1550 static const unsigned int ref92hd73xx_pin_configs[13] = {
1551         0x02214030, 0x02a19040, 0x01a19020, 0x02214030,
1552         0x0181302e, 0x01014010, 0x01014020, 0x01014030,
1553         0x02319040, 0x90a000f0, 0x90a000f0, 0x01452050,
1554         0x01452050,
1555 };
1556
1557 static const unsigned int dell_m6_pin_configs[13] = {
1558         0x0321101f, 0x4f00000f, 0x4f0000f0, 0x90170110,
1559         0x03a11020, 0x0321101f, 0x4f0000f0, 0x4f0000f0,
1560         0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1561         0x4f0000f0,
1562 };
1563
1564 static const unsigned int alienware_m17x_pin_configs[13] = {
1565         0x0321101f, 0x0321101f, 0x03a11020, 0x03014020,
1566         0x90170110, 0x4f0000f0, 0x4f0000f0, 0x4f0000f0,
1567         0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1568         0x904601b0,
1569 };
1570
1571 static const unsigned int intel_dg45id_pin_configs[13] = {
1572         0x02214230, 0x02A19240, 0x01013214, 0x01014210,
1573         0x01A19250, 0x01011212, 0x01016211
1574 };
1575
1576 static const unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = {
1577         [STAC_92HD73XX_REF]     = ref92hd73xx_pin_configs,
1578         [STAC_DELL_M6_AMIC]     = dell_m6_pin_configs,
1579         [STAC_DELL_M6_DMIC]     = dell_m6_pin_configs,
1580         [STAC_DELL_M6_BOTH]     = dell_m6_pin_configs,
1581         [STAC_DELL_EQ]  = dell_m6_pin_configs,
1582         [STAC_ALIENWARE_M17X]   = alienware_m17x_pin_configs,
1583         [STAC_92HD73XX_INTEL]   = intel_dg45id_pin_configs,
1584 };
1585
1586 static const char * const stac92hd73xx_models[STAC_92HD73XX_MODELS] = {
1587         [STAC_92HD73XX_AUTO] = "auto",
1588         [STAC_92HD73XX_NO_JD] = "no-jd",
1589         [STAC_92HD73XX_REF] = "ref",
1590         [STAC_92HD73XX_INTEL] = "intel",
1591         [STAC_DELL_M6_AMIC] = "dell-m6-amic",
1592         [STAC_DELL_M6_DMIC] = "dell-m6-dmic",
1593         [STAC_DELL_M6_BOTH] = "dell-m6",
1594         [STAC_DELL_EQ] = "dell-eq",
1595         [STAC_ALIENWARE_M17X] = "alienware",
1596 };
1597
1598 static const struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
1599         /* SigmaTel reference board */
1600         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1601                                 "DFI LanParty", STAC_92HD73XX_REF),
1602         SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1603                                 "DFI LanParty", STAC_92HD73XX_REF),
1604         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5002,
1605                                 "Intel DG45ID", STAC_92HD73XX_INTEL),
1606         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5003,
1607                                 "Intel DG45FC", STAC_92HD73XX_INTEL),
1608         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0254,
1609                                 "Dell Studio 1535", STAC_DELL_M6_DMIC),
1610         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0255,
1611                                 "unknown Dell", STAC_DELL_M6_DMIC),
1612         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0256,
1613                                 "unknown Dell", STAC_DELL_M6_BOTH),
1614         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0257,
1615                                 "unknown Dell", STAC_DELL_M6_BOTH),
1616         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025e,
1617                                 "unknown Dell", STAC_DELL_M6_AMIC),
1618         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025f,
1619                                 "unknown Dell", STAC_DELL_M6_AMIC),
1620         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0271,
1621                                 "unknown Dell", STAC_DELL_M6_DMIC),
1622         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0272,
1623                                 "unknown Dell", STAC_DELL_M6_DMIC),
1624         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x029f,
1625                                 "Dell Studio 1537", STAC_DELL_M6_DMIC),
1626         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a0,
1627                                 "Dell Studio 17", STAC_DELL_M6_DMIC),
1628         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02be,
1629                                 "Dell Studio 1555", STAC_DELL_M6_DMIC),
1630         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02bd,
1631                                 "Dell Studio 1557", STAC_DELL_M6_DMIC),
1632         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02fe,
1633                                 "Dell Studio XPS 1645", STAC_DELL_M6_BOTH),
1634         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0413,
1635                                 "Dell Studio 1558", STAC_DELL_M6_DMIC),
1636         {} /* terminator */
1637 };
1638
1639 static const struct snd_pci_quirk stac92hd73xx_codec_id_cfg_tbl[] = {
1640         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a1,
1641                       "Alienware M17x", STAC_ALIENWARE_M17X),
1642         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x043a,
1643                       "Alienware M17x", STAC_ALIENWARE_M17X),
1644         {} /* terminator */
1645 };
1646
1647 static const unsigned int ref92hd83xxx_pin_configs[10] = {
1648         0x02214030, 0x02211010, 0x02a19020, 0x02170130,
1649         0x01014050, 0x01819040, 0x01014020, 0x90a3014e,
1650         0x01451160, 0x98560170,
1651 };
1652
1653 static const unsigned int dell_s14_pin_configs[10] = {
1654         0x0221403f, 0x0221101f, 0x02a19020, 0x90170110,
1655         0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a60160,
1656         0x40f000f0, 0x40f000f0,
1657 };
1658
1659 static const unsigned int dell_vostro_3500_pin_configs[10] = {
1660         0x02a11020, 0x0221101f, 0x400000f0, 0x90170110,
1661         0x400000f1, 0x400000f2, 0x400000f3, 0x90a60160,
1662         0x400000f4, 0x400000f5,
1663 };
1664
1665 static const unsigned int hp_dv7_4000_pin_configs[10] = {
1666         0x03a12050, 0x0321201f, 0x40f000f0, 0x90170110,
1667         0x40f000f0, 0x40f000f0, 0x90170110, 0xd5a30140,
1668         0x40f000f0, 0x40f000f0,
1669 };
1670
1671 static const unsigned int hp_cNB11_intquad_pin_configs[10] = {
1672         0x40f000f0, 0x0221101f, 0x02a11020, 0x92170110,
1673         0x40f000f0, 0x92170110, 0x40f000f0, 0xd5a30130,
1674         0x40f000f0, 0x40f000f0,
1675 };
1676
1677 static const unsigned int *stac92hd83xxx_brd_tbl[STAC_92HD83XXX_MODELS] = {
1678         [STAC_92HD83XXX_REF] = ref92hd83xxx_pin_configs,
1679         [STAC_92HD83XXX_PWR_REF] = ref92hd83xxx_pin_configs,
1680         [STAC_DELL_S14] = dell_s14_pin_configs,
1681         [STAC_DELL_VOSTRO_3500] = dell_vostro_3500_pin_configs,
1682         [STAC_92HD83XXX_HP_cNB11_INTQUAD] = hp_cNB11_intquad_pin_configs,
1683         [STAC_HP_DV7_4000] = hp_dv7_4000_pin_configs,
1684 };
1685
1686 static const char * const stac92hd83xxx_models[STAC_92HD83XXX_MODELS] = {
1687         [STAC_92HD83XXX_AUTO] = "auto",
1688         [STAC_92HD83XXX_REF] = "ref",
1689         [STAC_92HD83XXX_PWR_REF] = "mic-ref",
1690         [STAC_DELL_S14] = "dell-s14",
1691         [STAC_DELL_VOSTRO_3500] = "dell-vostro-3500",
1692         [STAC_92HD83XXX_HP] = "hp",
1693         [STAC_92HD83XXX_HP_cNB11_INTQUAD] = "hp_cNB11_intquad",
1694         [STAC_HP_DV7_4000] = "hp-dv7-4000",
1695 };
1696
1697 static const struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = {
1698         /* SigmaTel reference board */
1699         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1700                       "DFI LanParty", STAC_92HD83XXX_REF),
1701         SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1702                       "DFI LanParty", STAC_92HD83XXX_REF),
1703         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ba,
1704                       "unknown Dell", STAC_DELL_S14),
1705         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x1028,
1706                       "Dell Vostro 3500", STAC_DELL_VOSTRO_3500),
1707         SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xff00, 0x3600,
1708                           "HP", STAC_92HD83XXX_HP),
1709         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1656,
1710                           "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1711         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1657,
1712                           "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1713         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1658,
1714                           "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1715         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1659,
1716                           "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1717         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x165A,
1718                           "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1719         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x165B,
1720                           "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1721         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3388,
1722                           "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1723         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3389,
1724                           "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1725         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355B,
1726                           "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1727         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355C,
1728                           "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1729         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355D,
1730                           "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1731         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355E,
1732                           "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1733         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355F,
1734                           "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1735         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3560,
1736                           "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1737         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x358B,
1738                           "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1739         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x358C,
1740                           "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1741         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x358D,
1742                           "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1743         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3591,
1744                           "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1745         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3592,
1746                           "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1747         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3593,
1748                           "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1749         {} /* terminator */
1750 };
1751
1752 static const unsigned int ref92hd71bxx_pin_configs[STAC92HD71BXX_NUM_PINS] = {
1753         0x02214030, 0x02a19040, 0x01a19020, 0x01014010,
1754         0x0181302e, 0x01014010, 0x01019020, 0x90a000f0,
1755         0x90a000f0, 0x01452050, 0x01452050, 0x00000000,
1756         0x00000000
1757 };
1758
1759 static const unsigned int dell_m4_1_pin_configs[STAC92HD71BXX_NUM_PINS] = {
1760         0x0421101f, 0x04a11221, 0x40f000f0, 0x90170110,
1761         0x23a1902e, 0x23014250, 0x40f000f0, 0x90a000f0,
1762         0x40f000f0, 0x4f0000f0, 0x4f0000f0, 0x00000000,
1763         0x00000000
1764 };
1765
1766 static const unsigned int dell_m4_2_pin_configs[STAC92HD71BXX_NUM_PINS] = {
1767         0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1768         0x23a1902e, 0x23014250, 0x40f000f0, 0x40f000f0,
1769         0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1770         0x00000000
1771 };
1772
1773 static const unsigned int dell_m4_3_pin_configs[STAC92HD71BXX_NUM_PINS] = {
1774         0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1775         0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a000f0,
1776         0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1777         0x00000000
1778 };
1779
1780 static const unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
1781         [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs,
1782         [STAC_DELL_M4_1]        = dell_m4_1_pin_configs,
1783         [STAC_DELL_M4_2]        = dell_m4_2_pin_configs,
1784         [STAC_DELL_M4_3]        = dell_m4_3_pin_configs,
1785         [STAC_HP_M4]            = NULL,
1786         [STAC_HP_DV4]           = NULL,
1787         [STAC_HP_DV5]           = NULL,
1788         [STAC_HP_HDX]           = NULL,
1789         [STAC_HP_DV4_1222NR]    = NULL,
1790 };
1791
1792 static const char * const stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
1793         [STAC_92HD71BXX_AUTO] = "auto",
1794         [STAC_92HD71BXX_REF] = "ref",
1795         [STAC_DELL_M4_1] = "dell-m4-1",
1796         [STAC_DELL_M4_2] = "dell-m4-2",
1797         [STAC_DELL_M4_3] = "dell-m4-3",
1798         [STAC_HP_M4] = "hp-m4",
1799         [STAC_HP_DV4] = "hp-dv4",
1800         [STAC_HP_DV5] = "hp-dv5",
1801         [STAC_HP_HDX] = "hp-hdx",
1802         [STAC_HP_DV4_1222NR] = "hp-dv4-1222nr",
1803 };
1804
1805 static const struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
1806         /* SigmaTel reference board */
1807         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1808                       "DFI LanParty", STAC_92HD71BXX_REF),
1809         SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1810                       "DFI LanParty", STAC_92HD71BXX_REF),
1811         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30fb,
1812                       "HP dv4-1222nr", STAC_HP_DV4_1222NR),
1813         SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x1720,
1814                           "HP", STAC_HP_DV5),
1815         SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3080,
1816                       "HP", STAC_HP_DV5),
1817         SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x30f0,
1818                       "HP dv4-7", STAC_HP_DV4),
1819         SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3600,
1820                       "HP dv4-7", STAC_HP_DV5),
1821         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3610,
1822                       "HP HDX", STAC_HP_HDX),  /* HDX18 */
1823         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361a,
1824                       "HP mini 1000", STAC_HP_M4),
1825         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361b,
1826                       "HP HDX", STAC_HP_HDX),  /* HDX16 */
1827         SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3620,
1828                       "HP dv6", STAC_HP_DV5),
1829         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3061,
1830                       "HP dv6", STAC_HP_DV5), /* HP dv6-1110ax */
1831         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x363e,
1832                       "HP DV6", STAC_HP_DV5),
1833         SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x7010,
1834                       "HP", STAC_HP_DV5),
1835         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
1836                                 "unknown Dell", STAC_DELL_M4_1),
1837         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234,
1838                                 "unknown Dell", STAC_DELL_M4_1),
1839         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0250,
1840                                 "unknown Dell", STAC_DELL_M4_1),
1841         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024f,
1842                                 "unknown Dell", STAC_DELL_M4_1),
1843         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024d,
1844                                 "unknown Dell", STAC_DELL_M4_1),
1845         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0251,
1846                                 "unknown Dell", STAC_DELL_M4_1),
1847         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0277,
1848                                 "unknown Dell", STAC_DELL_M4_1),
1849         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0263,
1850                                 "unknown Dell", STAC_DELL_M4_2),
1851         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0265,
1852                                 "unknown Dell", STAC_DELL_M4_2),
1853         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0262,
1854                                 "unknown Dell", STAC_DELL_M4_2),
1855         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0264,
1856                                 "unknown Dell", STAC_DELL_M4_2),
1857         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02aa,
1858                                 "unknown Dell", STAC_DELL_M4_3),
1859         {} /* terminator */
1860 };
1861
1862 static const unsigned int ref922x_pin_configs[10] = {
1863         0x01014010, 0x01016011, 0x01012012, 0x0221401f,
1864         0x01813122, 0x01011014, 0x01441030, 0x01c41030,
1865         0x40000100, 0x40000100,
1866 };
1867
1868 /*
1869     STAC 922X pin configs for
1870     102801A7
1871     102801AB
1872     102801A9
1873     102801D1
1874     102801D2
1875 */
1876 static const unsigned int dell_922x_d81_pin_configs[10] = {
1877         0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1878         0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
1879         0x01813122, 0x400001f2,
1880 };
1881
1882 /*
1883     STAC 922X pin configs for
1884     102801AC
1885     102801D0
1886 */
1887 static const unsigned int dell_922x_d82_pin_configs[10] = {
1888         0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1889         0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
1890         0x01813122, 0x400001f1,
1891 };
1892
1893 /*
1894     STAC 922X pin configs for
1895     102801BF
1896 */
1897 static const unsigned int dell_922x_m81_pin_configs[10] = {
1898         0x0321101f, 0x01112024, 0x01111222, 0x91174220,
1899         0x03a11050, 0x01116221, 0x90a70330, 0x01452340, 
1900         0x40C003f1, 0x405003f0,
1901 };
1902
1903 /*
1904     STAC 9221 A1 pin configs for
1905     102801D7 (Dell XPS M1210)
1906 */
1907 static const unsigned int dell_922x_m82_pin_configs[10] = {
1908         0x02211211, 0x408103ff, 0x02a1123e, 0x90100310, 
1909         0x408003f1, 0x0221121f, 0x03451340, 0x40c003f2, 
1910         0x508003f3, 0x405003f4, 
1911 };
1912
1913 static const unsigned int d945gtp3_pin_configs[10] = {
1914         0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
1915         0x40000100, 0x40000100, 0x40000100, 0x40000100,
1916         0x02a19120, 0x40000100,
1917 };
1918
1919 static const unsigned int d945gtp5_pin_configs[10] = {
1920         0x0221401f, 0x01011012, 0x01813024, 0x01014010,
1921         0x01a19021, 0x01016011, 0x01452130, 0x40000100,
1922         0x02a19320, 0x40000100,
1923 };
1924
1925 static const unsigned int intel_mac_v1_pin_configs[10] = {
1926         0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
1927         0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
1928         0x400000fc, 0x400000fb,
1929 };
1930
1931 static const unsigned int intel_mac_v2_pin_configs[10] = {
1932         0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1933         0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
1934         0x400000fc, 0x400000fb,
1935 };
1936
1937 static const unsigned int intel_mac_v3_pin_configs[10] = {
1938         0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1939         0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
1940         0x400000fc, 0x400000fb,
1941 };
1942
1943 static const unsigned int intel_mac_v4_pin_configs[10] = {
1944         0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1945         0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1946         0x400000fc, 0x400000fb,
1947 };
1948
1949 static const unsigned int intel_mac_v5_pin_configs[10] = {
1950         0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1951         0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1952         0x400000fc, 0x400000fb,
1953 };
1954
1955 static const unsigned int ecs202_pin_configs[10] = {
1956         0x0221401f, 0x02a19020, 0x01a19020, 0x01114010,
1957         0x408000f0, 0x01813022, 0x074510a0, 0x40c400f1,
1958         0x9037012e, 0x40e000f2,
1959 };
1960
1961 static const unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
1962         [STAC_D945_REF] = ref922x_pin_configs,
1963         [STAC_D945GTP3] = d945gtp3_pin_configs,
1964         [STAC_D945GTP5] = d945gtp5_pin_configs,
1965         [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
1966         [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
1967         [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
1968         [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
1969         [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
1970         [STAC_INTEL_MAC_AUTO] = intel_mac_v3_pin_configs,
1971         /* for backward compatibility */
1972         [STAC_MACMINI] = intel_mac_v3_pin_configs,
1973         [STAC_MACBOOK] = intel_mac_v5_pin_configs,
1974         [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
1975         [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
1976         [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
1977         [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
1978         [STAC_ECS_202] = ecs202_pin_configs,
1979         [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
1980         [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,       
1981         [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
1982         [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,       
1983 };
1984
1985 static const char * const stac922x_models[STAC_922X_MODELS] = {
1986         [STAC_922X_AUTO] = "auto",
1987         [STAC_D945_REF] = "ref",
1988         [STAC_D945GTP5] = "5stack",
1989         [STAC_D945GTP3] = "3stack",
1990         [STAC_INTEL_MAC_V1] = "intel-mac-v1",
1991         [STAC_INTEL_MAC_V2] = "intel-mac-v2",
1992         [STAC_INTEL_MAC_V3] = "intel-mac-v3",
1993         [STAC_INTEL_MAC_V4] = "intel-mac-v4",
1994         [STAC_INTEL_MAC_V5] = "intel-mac-v5",
1995         [STAC_INTEL_MAC_AUTO] = "intel-mac-auto",
1996         /* for backward compatibility */
1997         [STAC_MACMINI]  = "macmini",
1998         [STAC_MACBOOK]  = "macbook",
1999         [STAC_MACBOOK_PRO_V1]   = "macbook-pro-v1",
2000         [STAC_MACBOOK_PRO_V2]   = "macbook-pro",
2001         [STAC_IMAC_INTEL] = "imac-intel",
2002         [STAC_IMAC_INTEL_20] = "imac-intel-20",
2003         [STAC_ECS_202] = "ecs202",
2004         [STAC_922X_DELL_D81] = "dell-d81",
2005         [STAC_922X_DELL_D82] = "dell-d82",
2006         [STAC_922X_DELL_M81] = "dell-m81",
2007         [STAC_922X_DELL_M82] = "dell-m82",
2008 };
2009
2010 static const struct snd_pci_quirk stac922x_cfg_tbl[] = {
2011         /* SigmaTel reference board */
2012         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2013                       "DFI LanParty", STAC_D945_REF),
2014         SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2015                       "DFI LanParty", STAC_D945_REF),
2016         /* Intel 945G based systems */
2017         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
2018                       "Intel D945G", STAC_D945GTP3),
2019         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
2020                       "Intel D945G", STAC_D945GTP3),
2021         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
2022                       "Intel D945G", STAC_D945GTP3),
2023         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
2024                       "Intel D945G", STAC_D945GTP3),
2025         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
2026                       "Intel D945G", STAC_D945GTP3),
2027         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
2028                       "Intel D945G", STAC_D945GTP3),
2029         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
2030                       "Intel D945G", STAC_D945GTP3),
2031         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
2032                       "Intel D945G", STAC_D945GTP3),
2033         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
2034                       "Intel D945G", STAC_D945GTP3),
2035         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
2036                       "Intel D945G", STAC_D945GTP3),
2037         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
2038                       "Intel D945G", STAC_D945GTP3),
2039         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
2040                       "Intel D945G", STAC_D945GTP3),
2041         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
2042                       "Intel D945G", STAC_D945GTP3),
2043         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
2044                       "Intel D945G", STAC_D945GTP3),
2045         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
2046                       "Intel D945G", STAC_D945GTP3),
2047         /* Intel D945G 5-stack systems */
2048         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
2049                       "Intel D945G", STAC_D945GTP5),
2050         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
2051                       "Intel D945G", STAC_D945GTP5),
2052         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
2053                       "Intel D945G", STAC_D945GTP5),
2054         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
2055                       "Intel D945G", STAC_D945GTP5),
2056         /* Intel 945P based systems */
2057         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
2058                       "Intel D945P", STAC_D945GTP3),
2059         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
2060                       "Intel D945P", STAC_D945GTP3),
2061         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
2062                       "Intel D945P", STAC_D945GTP3),
2063         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
2064                       "Intel D945P", STAC_D945GTP3),
2065         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
2066                       "Intel D945P", STAC_D945GTP3),
2067         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
2068                       "Intel D945P", STAC_D945GTP5),
2069         /* other intel */
2070         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0204,
2071                       "Intel D945", STAC_D945_REF),
2072         /* other systems  */
2073         /* Apple Intel Mac (Mac Mini, MacBook, MacBook Pro...) */
2074         SND_PCI_QUIRK(0x8384, 0x7680,
2075                       "Mac", STAC_INTEL_MAC_AUTO),
2076         /* Dell systems  */
2077         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
2078                       "unknown Dell", STAC_922X_DELL_D81),
2079         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
2080                       "unknown Dell", STAC_922X_DELL_D81),
2081         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
2082                       "unknown Dell", STAC_922X_DELL_D81),
2083         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
2084                       "unknown Dell", STAC_922X_DELL_D82),
2085         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
2086                       "unknown Dell", STAC_922X_DELL_M81),
2087         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
2088                       "unknown Dell", STAC_922X_DELL_D82),
2089         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
2090                       "unknown Dell", STAC_922X_DELL_D81),
2091         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
2092                       "unknown Dell", STAC_922X_DELL_D81),
2093         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
2094                       "Dell XPS M1210", STAC_922X_DELL_M82),
2095         /* ECS/PC Chips boards */
2096         SND_PCI_QUIRK_MASK(0x1019, 0xf000, 0x2000,
2097                       "ECS/PC chips", STAC_ECS_202),
2098         {} /* terminator */
2099 };
2100
2101 static const unsigned int ref927x_pin_configs[14] = {
2102         0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2103         0x01a19040, 0x01011012, 0x01016011, 0x0101201f, 
2104         0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
2105         0x01c42190, 0x40000100,
2106 };
2107
2108 static const unsigned int d965_3st_pin_configs[14] = {
2109         0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
2110         0x01a19021, 0x01813024, 0x40000100, 0x40000100,
2111         0x40000100, 0x40000100, 0x40000100, 0x40000100,
2112         0x40000100, 0x40000100
2113 };
2114
2115 static const unsigned int d965_5st_pin_configs[14] = {
2116         0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2117         0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2118         0x40000100, 0x40000100, 0x40000100, 0x01442070,
2119         0x40000100, 0x40000100
2120 };
2121
2122 static const unsigned int d965_5st_no_fp_pin_configs[14] = {
2123         0x40000100, 0x40000100, 0x0181304e, 0x01014010,
2124         0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2125         0x40000100, 0x40000100, 0x40000100, 0x01442070,
2126         0x40000100, 0x40000100
2127 };
2128
2129 static const unsigned int dell_3st_pin_configs[14] = {
2130         0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
2131         0x01111212, 0x01116211, 0x01813050, 0x01112214,
2132         0x403003fa, 0x90a60040, 0x90a60040, 0x404003fb,
2133         0x40c003fc, 0x40000100
2134 };
2135
2136 static const unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
2137         [STAC_D965_REF_NO_JD] = ref927x_pin_configs,
2138         [STAC_D965_REF]  = ref927x_pin_configs,
2139         [STAC_D965_3ST]  = d965_3st_pin_configs,
2140         [STAC_D965_5ST]  = d965_5st_pin_configs,
2141         [STAC_D965_5ST_NO_FP]  = d965_5st_no_fp_pin_configs,
2142         [STAC_DELL_3ST]  = dell_3st_pin_configs,
2143         [STAC_DELL_BIOS] = NULL,
2144         [STAC_927X_VOLKNOB] = NULL,
2145 };
2146
2147 static const char * const stac927x_models[STAC_927X_MODELS] = {
2148         [STAC_927X_AUTO]        = "auto",
2149         [STAC_D965_REF_NO_JD]   = "ref-no-jd",
2150         [STAC_D965_REF]         = "ref",
2151         [STAC_D965_3ST]         = "3stack",
2152         [STAC_D965_5ST]         = "5stack",
2153         [STAC_D965_5ST_NO_FP]   = "5stack-no-fp",
2154         [STAC_DELL_3ST]         = "dell-3stack",
2155         [STAC_DELL_BIOS]        = "dell-bios",
2156         [STAC_927X_VOLKNOB]     = "volknob",
2157 };
2158
2159 static const struct snd_pci_quirk stac927x_cfg_tbl[] = {
2160         /* SigmaTel reference board */
2161         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2162                       "DFI LanParty", STAC_D965_REF),
2163         SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2164                       "DFI LanParty", STAC_D965_REF),
2165          /* Intel 946 based systems */
2166         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
2167         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
2168         /* 965 based 3 stack systems */
2169         SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2100,
2170                            "Intel D965", STAC_D965_3ST),
2171         SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2000,
2172                            "Intel D965", STAC_D965_3ST),
2173         /* Dell 3 stack systems */
2174         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
2175         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x01ed, "Dell     ", STAC_DELL_3ST),
2176         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x01f4, "Dell     ", STAC_DELL_3ST),
2177         /* Dell 3 stack systems with verb table in BIOS */
2178         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x01f3, "Dell Inspiron 1420", STAC_DELL_BIOS),
2179         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x01f7, "Dell XPS M1730", STAC_DELL_BIOS),
2180         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x0227, "Dell Vostro 1400  ", STAC_DELL_BIOS),
2181         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x022e, "Dell     ", STAC_DELL_BIOS),
2182         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x022f, "Dell Inspiron 1525", STAC_DELL_BIOS),
2183         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x0242, "Dell     ", STAC_DELL_BIOS),
2184         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x0243, "Dell     ", STAC_DELL_BIOS),
2185         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x02ff, "Dell     ", STAC_DELL_BIOS),
2186         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x0209, "Dell XPS 1330", STAC_DELL_BIOS),
2187         /* 965 based 5 stack systems */
2188         SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2300,
2189                            "Intel D965", STAC_D965_5ST),
2190         SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2500,
2191                            "Intel D965", STAC_D965_5ST),
2192         /* volume-knob fixes */
2193         SND_PCI_QUIRK_VENDOR(0x10cf, "FSC", STAC_927X_VOLKNOB),
2194         {} /* terminator */
2195 };
2196
2197 static const unsigned int ref9205_pin_configs[12] = {
2198         0x40000100, 0x40000100, 0x01016011, 0x01014010,
2199         0x01813122, 0x01a19021, 0x01019020, 0x40000100,
2200         0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
2201 };
2202
2203 /*
2204     STAC 9205 pin configs for
2205     102801F1
2206     102801F2
2207     102801FC
2208     102801FD
2209     10280204
2210     1028021F
2211     10280228 (Dell Vostro 1500)
2212     10280229 (Dell Vostro 1700)
2213 */
2214 static const unsigned int dell_9205_m42_pin_configs[12] = {
2215         0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
2216         0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
2217         0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
2218 };
2219
2220 /*
2221     STAC 9205 pin configs for
2222     102801F9
2223     102801FA
2224     102801FE
2225     102801FF (Dell Precision M4300)
2226     10280206
2227     10280200
2228     10280201
2229 */
2230 static const unsigned int dell_9205_m43_pin_configs[12] = {
2231         0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
2232         0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
2233         0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
2234 };
2235
2236 static const unsigned int dell_9205_m44_pin_configs[12] = {
2237         0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
2238         0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
2239         0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
2240 };
2241
2242 static const unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
2243         [STAC_9205_REF] = ref9205_pin_configs,
2244         [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
2245         [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
2246         [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
2247         [STAC_9205_EAPD] = NULL,
2248 };
2249
2250 static const char * const stac9205_models[STAC_9205_MODELS] = {
2251         [STAC_9205_AUTO] = "auto",
2252         [STAC_9205_REF] = "ref",
2253         [STAC_9205_DELL_M42] = "dell-m42",
2254         [STAC_9205_DELL_M43] = "dell-m43",
2255         [STAC_9205_DELL_M44] = "dell-m44",
2256         [STAC_9205_EAPD] = "eapd",
2257 };
2258
2259 static const struct snd_pci_quirk stac9205_cfg_tbl[] = {
2260         /* SigmaTel reference board */
2261         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2262                       "DFI LanParty", STAC_9205_REF),
2263         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xfb30,
2264                       "SigmaTel", STAC_9205_REF),
2265         SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2266                       "DFI LanParty", STAC_9205_REF),
2267         /* Dell */
2268         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
2269                       "unknown Dell", STAC_9205_DELL_M42),
2270         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
2271                       "unknown Dell", STAC_9205_DELL_M42),
2272         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
2273                       "Dell Precision", STAC_9205_DELL_M43),
2274         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
2275                       "Dell Precision", STAC_9205_DELL_M43),
2276         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
2277                       "Dell Precision", STAC_9205_DELL_M43),
2278         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
2279                       "unknown Dell", STAC_9205_DELL_M42),
2280         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
2281                       "unknown Dell", STAC_9205_DELL_M42),
2282         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
2283                       "Dell Precision", STAC_9205_DELL_M43),
2284         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
2285                       "Dell Precision M4300", STAC_9205_DELL_M43),
2286         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
2287                       "unknown Dell", STAC_9205_DELL_M42),
2288         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
2289                       "Dell Precision", STAC_9205_DELL_M43),
2290         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
2291                       "Dell Precision", STAC_9205_DELL_M43),
2292         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
2293                       "Dell Precision", STAC_9205_DELL_M43),
2294         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
2295                       "Dell Inspiron", STAC_9205_DELL_M44),
2296         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0228,
2297                       "Dell Vostro 1500", STAC_9205_DELL_M42),
2298         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0229,
2299                       "Dell Vostro 1700", STAC_9205_DELL_M42),
2300         /* Gateway */
2301         SND_PCI_QUIRK(0x107b, 0x0560, "Gateway T6834c", STAC_9205_EAPD),
2302         SND_PCI_QUIRK(0x107b, 0x0565, "Gateway T1616", STAC_9205_EAPD),
2303         {} /* terminator */
2304 };
2305
2306 static void stac92xx_set_config_regs(struct hda_codec *codec,
2307                                      const unsigned int *pincfgs)
2308 {
2309         int i;
2310         struct sigmatel_spec *spec = codec->spec;
2311
2312         if (!pincfgs)
2313                 return;
2314
2315         for (i = 0; i < spec->num_pins; i++)
2316                 if (spec->pin_nids[i] && pincfgs[i])
2317                         snd_hda_codec_set_pincfg(codec, spec->pin_nids[i],
2318                                                  pincfgs[i]);
2319 }
2320
2321 /*
2322  * Analog playback callbacks
2323  */
2324 static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
2325                                       struct hda_codec *codec,
2326                                       struct snd_pcm_substream *substream)
2327 {
2328         struct sigmatel_spec *spec = codec->spec;
2329         if (spec->stream_delay)
2330                 msleep(spec->stream_delay);
2331         return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2332                                              hinfo);
2333 }
2334
2335 static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2336                                          struct hda_codec *codec,
2337                                          unsigned int stream_tag,
2338                                          unsigned int format,
2339                                          struct snd_pcm_substream *substream)
2340 {
2341         struct sigmatel_spec *spec = codec->spec;
2342         return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
2343 }
2344
2345 static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2346                                         struct hda_codec *codec,
2347                                         struct snd_pcm_substream *substream)
2348 {
2349         struct sigmatel_spec *spec = codec->spec;
2350         return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2351 }
2352
2353 /*
2354  * Digital playback callbacks
2355  */
2356 static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2357                                           struct hda_codec *codec,
2358                                           struct snd_pcm_substream *substream)
2359 {
2360         struct sigmatel_spec *spec = codec->spec;
2361         return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2362 }
2363
2364 static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2365                                            struct hda_codec *codec,
2366                                            struct snd_pcm_substream *substream)
2367 {
2368         struct sigmatel_spec *spec = codec->spec;
2369         return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2370 }
2371
2372 static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2373                                          struct hda_codec *codec,
2374                                          unsigned int stream_tag,
2375                                          unsigned int format,
2376                                          struct snd_pcm_substream *substream)
2377 {
2378         struct sigmatel_spec *spec = codec->spec;
2379         return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2380                                              stream_tag, format, substream);
2381 }
2382
2383 static int stac92xx_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2384                                         struct hda_codec *codec,
2385                                         struct snd_pcm_substream *substream)
2386 {
2387         struct sigmatel_spec *spec = codec->spec;
2388         return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2389 }
2390
2391
2392 /*
2393  * Analog capture callbacks
2394  */
2395 static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2396                                         struct hda_codec *codec,
2397                                         unsigned int stream_tag,
2398                                         unsigned int format,
2399                                         struct snd_pcm_substream *substream)
2400 {
2401         struct sigmatel_spec *spec = codec->spec;
2402         hda_nid_t nid = spec->adc_nids[substream->number];
2403
2404         if (spec->powerdown_adcs) {
2405                 msleep(40);
2406                 snd_hda_codec_write(codec, nid, 0,
2407                         AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
2408         }
2409         snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
2410         return 0;
2411 }
2412
2413 static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2414                                         struct hda_codec *codec,
2415                                         struct snd_pcm_substream *substream)
2416 {
2417         struct sigmatel_spec *spec = codec->spec;
2418         hda_nid_t nid = spec->adc_nids[substream->number];
2419
2420         snd_hda_codec_cleanup_stream(codec, nid);
2421         if (spec->powerdown_adcs)
2422                 snd_hda_codec_write(codec, nid, 0,
2423                         AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
2424         return 0;
2425 }
2426
2427 static const struct hda_pcm_stream stac92xx_pcm_digital_playback = {
2428         .substreams = 1,
2429         .channels_min = 2,
2430         .channels_max = 2,
2431         /* NID is set in stac92xx_build_pcms */
2432         .ops = {
2433                 .open = stac92xx_dig_playback_pcm_open,
2434                 .close = stac92xx_dig_playback_pcm_close,
2435                 .prepare = stac92xx_dig_playback_pcm_prepare,
2436                 .cleanup = stac92xx_dig_playback_pcm_cleanup
2437         },
2438 };
2439
2440 static const struct hda_pcm_stream stac92xx_pcm_digital_capture = {
2441         .substreams = 1,
2442         .channels_min = 2,
2443         .channels_max = 2,
2444         /* NID is set in stac92xx_build_pcms */
2445 };
2446
2447 static const struct hda_pcm_stream stac92xx_pcm_analog_playback = {
2448         .substreams = 1,
2449         .channels_min = 2,
2450         .channels_max = 8,
2451         .nid = 0x02, /* NID to query formats and rates */
2452         .ops = {
2453                 .open = stac92xx_playback_pcm_open,
2454                 .prepare = stac92xx_playback_pcm_prepare,
2455                 .cleanup = stac92xx_playback_pcm_cleanup
2456         },
2457 };
2458
2459 static const struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
2460         .substreams = 1,
2461         .channels_min = 2,
2462         .channels_max = 2,
2463         .nid = 0x06, /* NID to query formats and rates */
2464         .ops = {
2465                 .open = stac92xx_playback_pcm_open,
2466                 .prepare = stac92xx_playback_pcm_prepare,
2467                 .cleanup = stac92xx_playback_pcm_cleanup
2468         },
2469 };
2470
2471 static const struct hda_pcm_stream stac92xx_pcm_analog_capture = {
2472         .channels_min = 2,
2473         .channels_max = 2,
2474         /* NID + .substreams is set in stac92xx_build_pcms */
2475         .ops = {
2476                 .prepare = stac92xx_capture_pcm_prepare,
2477                 .cleanup = stac92xx_capture_pcm_cleanup
2478         },
2479 };
2480
2481 static int stac92xx_build_pcms(struct hda_codec *codec)
2482 {
2483         struct sigmatel_spec *spec = codec->spec;
2484         struct hda_pcm *info = spec->pcm_rec;
2485
2486         codec->num_pcms = 1;
2487         codec->pcm_info = info;
2488
2489         info->name = "STAC92xx Analog";
2490         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
2491         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2492                 spec->multiout.dac_nids[0];
2493         info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
2494         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2495         info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
2496
2497         if (spec->alt_switch) {
2498                 codec->num_pcms++;
2499                 info++;
2500                 info->name = "STAC92xx Analog Alt";
2501                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
2502         }
2503
2504         if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2505                 codec->num_pcms++;
2506                 info++;
2507                 info->name = "STAC92xx Digital";
2508                 info->pcm_type = spec->autocfg.dig_out_type[0];
2509                 if (spec->multiout.dig_out_nid) {
2510                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
2511                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2512                 }
2513                 if (spec->dig_in_nid) {
2514                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
2515                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2516                 }
2517         }
2518
2519         return 0;
2520 }
2521
2522 static unsigned int stac92xx_get_default_vref(struct hda_codec *codec,
2523                                         hda_nid_t nid)
2524 {
2525         unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2526         pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
2527         if (pincap & AC_PINCAP_VREF_100)
2528                 return AC_PINCTL_VREF_100;
2529         if (pincap & AC_PINCAP_VREF_80)
2530                 return AC_PINCTL_VREF_80;
2531         if (pincap & AC_PINCAP_VREF_50)
2532                 return AC_PINCTL_VREF_50;
2533         if (pincap & AC_PINCAP_VREF_GRD)
2534                 return AC_PINCTL_VREF_GRD;
2535         return 0;
2536 }
2537
2538 static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
2539
2540 {
2541         snd_hda_codec_write_cache(codec, nid, 0,
2542                                   AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
2543 }
2544
2545 #define stac92xx_hp_switch_info         snd_ctl_boolean_mono_info
2546
2547 static int stac92xx_hp_switch_get(struct snd_kcontrol *kcontrol,
2548                         struct snd_ctl_elem_value *ucontrol)
2549 {
2550         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2551         struct sigmatel_spec *spec = codec->spec;
2552
2553         ucontrol->value.integer.value[0] = !!spec->hp_switch;
2554         return 0;
2555 }
2556
2557 static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid);
2558
2559 static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol,
2560                         struct snd_ctl_elem_value *ucontrol)
2561 {
2562         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2563         struct sigmatel_spec *spec = codec->spec;
2564         int nid = kcontrol->private_value;
2565  
2566         spec->hp_switch = ucontrol->value.integer.value[0] ? nid : 0;
2567
2568         /* check to be sure that the ports are up to date with
2569          * switch changes
2570          */
2571         stac_issue_unsol_event(codec, nid);
2572
2573         return 1;
2574 }
2575
2576 static int stac92xx_dc_bias_info(struct snd_kcontrol *kcontrol,
2577                                 struct snd_ctl_elem_info *uinfo)
2578 {
2579         int i;
2580         static const char * const texts[] = {
2581                 "Mic In", "Line In", "Line Out"
2582         };
2583
2584         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2585         struct sigmatel_spec *spec = codec->spec;
2586         hda_nid_t nid = kcontrol->private_value;
2587
2588         if (nid == spec->mic_switch || nid == spec->line_switch)
2589                 i = 3;
2590         else
2591                 i = 2;
2592
2593         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2594         uinfo->value.enumerated.items = i;
2595         uinfo->count = 1;
2596         if (uinfo->value.enumerated.item >= i)
2597                 uinfo->value.enumerated.item = i-1;
2598         strcpy(uinfo->value.enumerated.name,
2599                 texts[uinfo->value.enumerated.item]);
2600
2601         return 0;
2602 }
2603
2604 static int stac92xx_dc_bias_get(struct snd_kcontrol *kcontrol,
2605                                 struct snd_ctl_elem_value *ucontrol)
2606 {
2607         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2608         hda_nid_t nid = kcontrol->private_value;
2609         unsigned int vref = stac92xx_vref_get(codec, nid);
2610
2611         if (vref == stac92xx_get_default_vref(codec, nid))
2612                 ucontrol->value.enumerated.item[0] = 0;
2613         else if (vref == AC_PINCTL_VREF_GRD)
2614                 ucontrol->value.enumerated.item[0] = 1;
2615         else if (vref == AC_PINCTL_VREF_HIZ)
2616                 ucontrol->value.enumerated.item[0] = 2;
2617
2618         return 0;
2619 }
2620
2621 static int stac92xx_dc_bias_put(struct snd_kcontrol *kcontrol,
2622                                 struct snd_ctl_elem_value *ucontrol)
2623 {
2624         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2625         unsigned int new_vref = 0;
2626         int error;
2627         hda_nid_t nid = kcontrol->private_value;
2628
2629         if (ucontrol->value.enumerated.item[0] == 0)
2630                 new_vref = stac92xx_get_default_vref(codec, nid);
2631         else if (ucontrol->value.enumerated.item[0] == 1)
2632                 new_vref = AC_PINCTL_VREF_GRD;
2633         else if (ucontrol->value.enumerated.item[0] == 2)
2634                 new_vref = AC_PINCTL_VREF_HIZ;
2635         else
2636                 return 0;
2637
2638         if (new_vref != stac92xx_vref_get(codec, nid)) {
2639                 error = stac92xx_vref_set(codec, nid, new_vref);
2640                 return error;
2641         }
2642
2643         return 0;
2644 }
2645
2646 static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol,
2647                                 struct snd_ctl_elem_info *uinfo)
2648 {
2649         char *texts[2];
2650         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2651         struct sigmatel_spec *spec = codec->spec;
2652
2653         if (kcontrol->private_value == spec->line_switch)
2654                 texts[0] = "Line In";
2655         else
2656                 texts[0] = "Mic In";
2657         texts[1] = "Line Out";
2658         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2659         uinfo->value.enumerated.items = 2;
2660         uinfo->count = 1;
2661
2662         if (uinfo->value.enumerated.item >= 2)
2663                 uinfo->value.enumerated.item = 1;
2664         strcpy(uinfo->value.enumerated.name,
2665                 texts[uinfo->value.enumerated.item]);
2666
2667         return 0;
2668 }
2669
2670 static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2671 {
2672         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2673         struct sigmatel_spec *spec = codec->spec;
2674         hda_nid_t nid = kcontrol->private_value;
2675         int io_idx = (nid == spec->mic_switch) ? 1 : 0;
2676
2677         ucontrol->value.enumerated.item[0] = spec->io_switch[io_idx];
2678         return 0;
2679 }
2680
2681 static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2682 {
2683         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2684         struct sigmatel_spec *spec = codec->spec;
2685         hda_nid_t nid = kcontrol->private_value;
2686         int io_idx = (nid == spec->mic_switch) ? 1 : 0;
2687         unsigned short val = !!ucontrol->value.enumerated.item[0];
2688
2689         spec->io_switch[io_idx] = val;
2690
2691         if (val)
2692                 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
2693         else {
2694                 unsigned int pinctl = AC_PINCTL_IN_EN;
2695                 if (io_idx) /* set VREF for mic */
2696                         pinctl |= stac92xx_get_default_vref(codec, nid);
2697                 stac92xx_auto_set_pinctl(codec, nid, pinctl);
2698         }
2699
2700         /* check the auto-mute again: we need to mute/unmute the speaker
2701          * appropriately according to the pin direction
2702          */
2703         if (spec->hp_detect)
2704                 stac_issue_unsol_event(codec, nid);
2705
2706         return 1;
2707 }
2708
2709 #define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
2710
2711 static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
2712                 struct snd_ctl_elem_value *ucontrol)
2713 {
2714         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2715         struct sigmatel_spec *spec = codec->spec;
2716
2717         ucontrol->value.integer.value[0] = spec->clfe_swap;
2718         return 0;
2719 }
2720
2721 static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
2722                 struct snd_ctl_elem_value *ucontrol)
2723 {
2724         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2725         struct sigmatel_spec *spec = codec->spec;
2726         hda_nid_t nid = kcontrol->private_value & 0xff;
2727         unsigned int val = !!ucontrol->value.integer.value[0];
2728
2729         if (spec->clfe_swap == val)
2730                 return 0;
2731
2732         spec->clfe_swap = val;
2733
2734         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
2735                 spec->clfe_swap ? 0x4 : 0x0);
2736
2737         return 1;
2738 }
2739
2740 #define STAC_CODEC_HP_SWITCH(xname) \
2741         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2742           .name = xname, \
2743           .index = 0, \
2744           .info = stac92xx_hp_switch_info, \
2745           .get = stac92xx_hp_switch_get, \
2746           .put = stac92xx_hp_switch_put, \
2747         }
2748
2749 #define STAC_CODEC_IO_SWITCH(xname, xpval) \
2750         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2751           .name = xname, \
2752           .index = 0, \
2753           .info = stac92xx_io_switch_info, \
2754           .get = stac92xx_io_switch_get, \
2755           .put = stac92xx_io_switch_put, \
2756           .private_value = xpval, \
2757         }
2758
2759 #define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
2760         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2761           .name = xname, \
2762           .index = 0, \
2763           .info = stac92xx_clfe_switch_info, \
2764           .get = stac92xx_clfe_switch_get, \
2765           .put = stac92xx_clfe_switch_put, \
2766           .private_value = xpval, \
2767         }
2768
2769 enum {
2770         STAC_CTL_WIDGET_VOL,
2771         STAC_CTL_WIDGET_MUTE,
2772         STAC_CTL_WIDGET_MUTE_BEEP,
2773         STAC_CTL_WIDGET_MONO_MUX,
2774         STAC_CTL_WIDGET_HP_SWITCH,
2775         STAC_CTL_WIDGET_IO_SWITCH,
2776         STAC_CTL_WIDGET_CLFE_SWITCH,
2777         STAC_CTL_WIDGET_DC_BIAS
2778 };
2779
2780 static const struct snd_kcontrol_new stac92xx_control_templates[] = {
2781         HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2782         HDA_CODEC_MUTE(NULL, 0, 0, 0),
2783         HDA_CODEC_MUTE_BEEP(NULL, 0, 0, 0),
2784         STAC_MONO_MUX,
2785         STAC_CODEC_HP_SWITCH(NULL),
2786         STAC_CODEC_IO_SWITCH(NULL, 0),
2787         STAC_CODEC_CLFE_SWITCH(NULL, 0),
2788         DC_BIAS(NULL, 0, 0),
2789 };
2790
2791 /* add dynamic controls */
2792 static struct snd_kcontrol_new *
2793 stac_control_new(struct sigmatel_spec *spec,
2794                  const struct snd_kcontrol_new *ktemp,
2795                  const char *name,
2796                  unsigned int subdev)
2797 {
2798         struct snd_kcontrol_new *knew;
2799
2800         snd_array_init(&spec->kctls, sizeof(*knew), 32);
2801         knew = snd_array_new(&spec->kctls);
2802         if (!knew)
2803                 return NULL;
2804         *knew = *ktemp;
2805         knew->name = kstrdup(name, GFP_KERNEL);
2806         if (!knew->name) {
2807                 /* roolback */
2808                 memset(knew, 0, sizeof(*knew));
2809                 spec->kctls.alloced--;
2810                 return NULL;
2811         }
2812         knew->subdevice = subdev;
2813         return knew;
2814 }
2815
2816 static int stac92xx_add_control_temp(struct sigmatel_spec *spec,
2817                                      const struct snd_kcontrol_new *ktemp,
2818                                      int idx, const char *name,
2819                                      unsigned long val)
2820 {
2821         struct snd_kcontrol_new *knew = stac_control_new(spec, ktemp, name,
2822                                                          HDA_SUBDEV_AMP_FLAG);
2823         if (!knew)
2824                 return -ENOMEM;
2825         knew->index = idx;
2826         knew->private_value = val;
2827         return 0;
2828 }
2829
2830 static inline int stac92xx_add_control_idx(struct sigmatel_spec *spec,
2831                                            int type, int idx, const char *name,
2832                                            unsigned long val)
2833 {
2834         return stac92xx_add_control_temp(spec,
2835                                          &stac92xx_control_templates[type],
2836                                          idx, name, val);
2837 }
2838
2839
2840 /* add dynamic controls */
2841 static inline int stac92xx_add_control(struct sigmatel_spec *spec, int type,
2842                                        const char *name, unsigned long val)
2843 {
2844         return stac92xx_add_control_idx(spec, type, 0, name, val);
2845 }
2846
2847 static const struct snd_kcontrol_new stac_input_src_temp = {
2848         .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2849         .name = "Input Source",
2850         .info = stac92xx_mux_enum_info,
2851         .get = stac92xx_mux_enum_get,
2852         .put = stac92xx_mux_enum_put,
2853 };
2854
2855 static inline int stac92xx_add_jack_mode_control(struct hda_codec *codec,
2856                                                 hda_nid_t nid, int idx)
2857 {
2858         int def_conf = snd_hda_codec_get_pincfg(codec, nid);
2859         int control = 0;
2860         struct sigmatel_spec *spec = codec->spec;
2861         char name[22];
2862
2863         if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT) {
2864                 if (stac92xx_get_default_vref(codec, nid) == AC_PINCTL_VREF_GRD
2865                         && nid == spec->line_switch)
2866                         control = STAC_CTL_WIDGET_IO_SWITCH;
2867                 else if (snd_hda_query_pin_caps(codec, nid)
2868                         & (AC_PINCAP_VREF_GRD << AC_PINCAP_VREF_SHIFT))
2869                         control = STAC_CTL_WIDGET_DC_BIAS;
2870                 else if (nid == spec->mic_switch)
2871                         control = STAC_CTL_WIDGET_IO_SWITCH;
2872         }
2873
2874         if (control) {
2875                 strcpy(name, hda_get_input_pin_label(codec, nid, 1));
2876                 return stac92xx_add_control(codec->spec, control,
2877                                         strcat(name, " Jack Mode"), nid);
2878         }
2879
2880         return 0;
2881 }
2882
2883 static int stac92xx_add_input_source(struct sigmatel_spec *spec)
2884 {
2885         struct snd_kcontrol_new *knew;
2886         struct hda_input_mux *imux = &spec->private_imux;
2887
2888         if (spec->auto_mic)
2889                 return 0; /* no need for input source */
2890         if (!spec->num_adcs || imux->num_items <= 1)
2891                 return 0; /* no need for input source control */
2892         knew = stac_control_new(spec, &stac_input_src_temp,
2893                                 stac_input_src_temp.name, 0);
2894         if (!knew)
2895                 return -ENOMEM;
2896         knew->count = spec->num_adcs;
2897         return 0;
2898 }
2899
2900 /* check whether the line-input can be used as line-out */
2901 static hda_nid_t check_line_out_switch(struct hda_codec *codec)
2902 {
2903         struct sigmatel_spec *spec = codec->spec;
2904         struct auto_pin_cfg *cfg = &spec->autocfg;
2905         hda_nid_t nid;
2906         unsigned int pincap;
2907         int i;
2908
2909         if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2910                 return 0;
2911         for (i = 0; i < cfg->num_inputs; i++) {
2912                 if (cfg->inputs[i].type == AUTO_PIN_LINE_IN) {
2913                         nid = cfg->inputs[i].pin;
2914                         pincap = snd_hda_query_pin_caps(codec, nid);
2915                         if (pincap & AC_PINCAP_OUT)
2916                                 return nid;
2917                 }
2918         }
2919         return 0;
2920 }
2921
2922 static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid);
2923
2924 /* check whether the mic-input can be used as line-out */
2925 static hda_nid_t check_mic_out_switch(struct hda_codec *codec, hda_nid_t *dac)
2926 {
2927         struct sigmatel_spec *spec = codec->spec;
2928         struct auto_pin_cfg *cfg = &spec->autocfg;
2929         unsigned int def_conf, pincap;
2930         int i;
2931
2932         *dac = 0;
2933         if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2934                 return 0;
2935         for (i = 0; i < cfg->num_inputs; i++) {
2936                 hda_nid_t nid = cfg->inputs[i].pin;
2937                 if (cfg->inputs[i].type != AUTO_PIN_MIC)
2938                         continue;
2939                 def_conf = snd_hda_codec_get_pincfg(codec, nid);
2940                 /* some laptops have an internal analog microphone
2941                  * which can't be used as a output */
2942                 if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT) {
2943                         pincap = snd_hda_query_pin_caps(codec, nid);
2944                         if (pincap & AC_PINCAP_OUT) {
2945                                 *dac = get_unassigned_dac(codec, nid);
2946                                 if (*dac)
2947                                         return nid;
2948                         }
2949                 }
2950         }
2951         return 0;
2952 }
2953
2954 static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2955 {
2956         int i;
2957         
2958         for (i = 0; i < spec->multiout.num_dacs; i++) {
2959                 if (spec->multiout.dac_nids[i] == nid)
2960                         return 1;
2961         }
2962
2963         return 0;
2964 }
2965
2966 static int check_all_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2967 {
2968         int i;
2969         if (is_in_dac_nids(spec, nid))
2970                 return 1;
2971         for (i = 0; i < spec->autocfg.hp_outs; i++)
2972                 if (spec->hp_dacs[i] == nid)
2973                         return 1;
2974         for (i = 0; i < spec->autocfg.speaker_outs; i++)
2975                 if (spec->speaker_dacs[i] == nid)
2976                         return 1;
2977         return 0;
2978 }
2979
2980 static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid)
2981 {
2982         struct sigmatel_spec *spec = codec->spec;
2983         struct auto_pin_cfg *cfg = &spec->autocfg;
2984         int j, conn_len;
2985         hda_nid_t conn[HDA_MAX_CONNECTIONS], fallback_dac;
2986         unsigned int wcaps, wtype;
2987
2988         conn_len = snd_hda_get_connections(codec, nid, conn,
2989                                            HDA_MAX_CONNECTIONS);
2990         /* 92HD88: trace back up the link of nids to find the DAC */
2991         while (conn_len == 1 && (get_wcaps_type(get_wcaps(codec, conn[0]))
2992                                         != AC_WID_AUD_OUT)) {
2993                 nid = conn[0];
2994                 conn_len = snd_hda_get_connections(codec, nid, conn,
2995                         HDA_MAX_CONNECTIONS);
2996         }
2997         for (j = 0; j < conn_len; j++) {
2998                 wcaps = get_wcaps(codec, conn[j]);
2999                 wtype = get_wcaps_type(wcaps);
3000                 /* we check only analog outputs */
3001                 if (wtype != AC_WID_AUD_OUT || (wcaps & AC_WCAP_DIGITAL))
3002                         continue;
3003                 /* if this route has a free DAC, assign it */
3004                 if (!check_all_dac_nids(spec, conn[j])) {
3005                         if (conn_len > 1) {
3006                                 /* select this DAC in the pin's input mux */
3007                                 snd_hda_codec_write_cache(codec, nid, 0,
3008                                                   AC_VERB_SET_CONNECT_SEL, j);
3009                         }
3010                         return conn[j];
3011                 }
3012         }
3013
3014         /* if all DACs are already assigned, connect to the primary DAC,
3015            unless we're assigning a secondary headphone */
3016         fallback_dac = spec->multiout.dac_nids[0];
3017         if (spec->multiout.hp_nid) {
3018                 for (j = 0; j < cfg->hp_outs; j++)
3019                         if (cfg->hp_pins[j] == nid) {
3020                                 fallback_dac = spec->multiout.hp_nid;
3021                                 break;
3022                         }
3023         }
3024
3025         if (conn_len > 1) {
3026                 for (j = 0; j < conn_len; j++) {
3027                         if (conn[j] == fallback_dac) {
3028                                 snd_hda_codec_write_cache(codec, nid, 0,
3029                                                   AC_VERB_SET_CONNECT_SEL, j);
3030                                 break;
3031                         }
3032                 }
3033         }
3034         return 0;
3035 }
3036
3037 static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
3038 static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
3039
3040 /*
3041  * Fill in the dac_nids table from the parsed pin configuration
3042  * This function only works when every pin in line_out_pins[]
3043  * contains atleast one DAC in its connection list. Some 92xx
3044  * codecs are not connected directly to a DAC, such as the 9200
3045  * and 9202/925x. For those, dac_nids[] must be hard-coded.
3046  */
3047 static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec)
3048 {
3049         struct sigmatel_spec *spec = codec->spec;
3050         struct auto_pin_cfg *cfg = &spec->autocfg;
3051         int i;
3052         hda_nid_t nid, dac;
3053         
3054         for (i = 0; i < cfg->line_outs; i++) {
3055                 nid = cfg->line_out_pins[i];
3056                 dac = get_unassigned_dac(codec, nid);
3057                 if (!dac) {
3058                         if (spec->multiout.num_dacs > 0) {
3059                                 /* we have already working output pins,
3060                                  * so let's drop the broken ones again
3061                                  */
3062                                 cfg->line_outs = spec->multiout.num_dacs;
3063                                 break;
3064                         }
3065                         /* error out, no available DAC found */
3066                         snd_printk(KERN_ERR
3067                                    "%s: No available DAC for pin 0x%x\n",
3068                                    __func__, nid);
3069                         return -ENODEV;
3070                 }
3071                 add_spec_dacs(spec, dac);
3072         }
3073
3074         for (i = 0; i < cfg->hp_outs; i++) {
3075                 nid = cfg->hp_pins[i];
3076                 dac = get_unassigned_dac(codec, nid);
3077                 if (dac) {
3078                         if (!spec->multiout.hp_nid)
3079                                 spec->multiout.hp_nid = dac;
3080                         else
3081                                 add_spec_extra_dacs(spec, dac);
3082                 }
3083                 spec->hp_dacs[i] = dac;
3084         }
3085
3086         for (i = 0; i < cfg->speaker_outs; i++) {
3087                 nid = cfg->speaker_pins[i];
3088                 dac = get_unassigned_dac(codec, nid);
3089                 if (dac)
3090                         add_spec_extra_dacs(spec, dac);
3091                 spec->speaker_dacs[i] = dac;
3092         }
3093
3094         /* add line-in as output */
3095         nid = check_line_out_switch(codec);
3096         if (nid) {
3097                 dac = get_unassigned_dac(codec, nid);
3098                 if (dac) {
3099                         snd_printdd("STAC: Add line-in 0x%x as output %d\n",
3100                                     nid, cfg->line_outs);
3101                         cfg->line_out_pins[cfg->line_outs] = nid;
3102                         cfg->line_outs++;
3103                         spec->line_switch = nid;
3104                         add_spec_dacs(spec, dac);
3105                 }
3106         }
3107         /* add mic as output */
3108         nid = check_mic_out_switch(codec, &dac);
3109         if (nid && dac) {
3110                 snd_printdd("STAC: Add mic-in 0x%x as output %d\n",
3111                             nid, cfg->line_outs);
3112                 cfg->line_out_pins[cfg->line_outs] = nid;
3113                 cfg->line_outs++;
3114                 spec->mic_switch = nid;
3115                 add_spec_dacs(spec, dac);
3116         }
3117
3118         snd_printd("stac92xx: dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
3119                    spec->multiout.num_dacs,
3120                    spec->multiout.dac_nids[0],
3121                    spec->multiout.dac_nids[1],
3122                    spec->multiout.dac_nids[2],
3123                    spec->multiout.dac_nids[3],
3124                    spec->multiout.dac_nids[4]);
3125
3126         return 0;
3127 }
3128
3129 /* create volume control/switch for the given prefx type */
3130 static int create_controls_idx(struct hda_codec *codec, const char *pfx,
3131                                int idx, hda_nid_t nid, int chs)
3132 {
3133         struct sigmatel_spec *spec = codec->spec;
3134         char name[32];
3135         int err;
3136
3137         if (!spec->check_volume_offset) {
3138                 unsigned int caps, step, nums, db_scale;
3139                 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3140                 step = (caps & AC_AMPCAP_STEP_SIZE) >>
3141                         AC_AMPCAP_STEP_SIZE_SHIFT;
3142                 step = (step + 1) * 25; /* in .01dB unit */
3143                 nums = (caps & AC_AMPCAP_NUM_STEPS) >>
3144                         AC_AMPCAP_NUM_STEPS_SHIFT;
3145                 db_scale = nums * step;
3146                 /* if dB scale is over -64dB, and finer enough,
3147                  * let's reduce it to half
3148                  */
3149                 if (db_scale > 6400 && nums >= 0x1f)
3150                         spec->volume_offset = nums / 2;
3151                 spec->check_volume_offset = 1;
3152         }
3153
3154         sprintf(name, "%s Playback Volume", pfx);
3155         err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, idx, name,
3156                 HDA_COMPOSE_AMP_VAL_OFS(nid, chs, 0, HDA_OUTPUT,
3157                                         spec->volume_offset));
3158         if (err < 0)
3159                 return err;
3160         sprintf(name, "%s Playback Switch", pfx);
3161         err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_MUTE, idx, name,
3162                                    HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
3163         if (err < 0)
3164                 return err;
3165         return 0;
3166 }
3167
3168 #define create_controls(codec, pfx, nid, chs) \
3169         create_controls_idx(codec, pfx, 0, nid, chs)
3170
3171 static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
3172 {
3173         if (spec->multiout.num_dacs > 4) {
3174                 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
3175                 return 1;
3176         } else {
3177                 snd_BUG_ON(spec->multiout.dac_nids != spec->dac_nids);
3178                 spec->dac_nids[spec->multiout.num_dacs] = nid;
3179                 spec->multiout.num_dacs++;
3180         }
3181         return 0;
3182 }
3183
3184 static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
3185 {
3186         int i;
3187         for (i = 0; i < ARRAY_SIZE(spec->multiout.extra_out_nid); i++) {
3188                 if (!spec->multiout.extra_out_nid[i]) {
3189                         spec->multiout.extra_out_nid[i] = nid;
3190                         return 0;
3191                 }
3192         }
3193         printk(KERN_WARNING "stac92xx: No space for extra DAC 0x%x\n", nid);
3194         return 1;
3195 }
3196
3197 /* Create output controls
3198  * The mixer elements are named depending on the given type (AUTO_PIN_XXX_OUT)
3199  */
3200 static int create_multi_out_ctls(struct hda_codec *codec, int num_outs,
3201                                  const hda_nid_t *pins,
3202                                  const hda_nid_t *dac_nids,
3203                                  int type)
3204 {
3205         struct sigmatel_spec *spec = codec->spec;
3206         static const char * const chname[4] = {
3207                 "Front", "Surround", NULL /*CLFE*/, "Side"
3208         };
3209         hda_nid_t nid;
3210         int i, err;
3211         unsigned int wid_caps;
3212
3213         for (i = 0; i < num_outs && i < ARRAY_SIZE(chname); i++) {
3214                 if (type == AUTO_PIN_HP_OUT && !spec->hp_detect) {
3215                         if (is_jack_detectable(codec, pins[i]))
3216                                 spec->hp_detect = 1;
3217                 }
3218                 nid = dac_nids[i];
3219                 if (!nid)
3220                         continue;
3221                 if (type != AUTO_PIN_HP_OUT && i == 2) {
3222                         /* Center/LFE */
3223                         err = create_controls(codec, "Center", nid, 1);
3224                         if (err < 0)
3225                                 return err;
3226                         err = create_controls(codec, "LFE", nid, 2);
3227                         if (err < 0)
3228                                 return err;
3229
3230                         wid_caps = get_wcaps(codec, nid);
3231
3232                         if (wid_caps & AC_WCAP_LR_SWAP) {
3233                                 err = stac92xx_add_control(spec,
3234                                         STAC_CTL_WIDGET_CLFE_SWITCH,
3235                                         "Swap Center/LFE Playback Switch", nid);
3236
3237                                 if (err < 0)
3238                                         return err;
3239                         }
3240
3241                 } else {
3242                         const char *name;
3243                         int idx;
3244                         switch (type) {
3245                         case AUTO_PIN_HP_OUT:
3246                                 name = "Headphone";
3247                                 idx = i;
3248                                 break;
3249                         case AUTO_PIN_SPEAKER_OUT:
3250                                 name = "Speaker";
3251                                 idx = i;
3252                                 break;
3253                         default:
3254                                 name = chname[i];
3255                                 idx = 0;
3256                                 break;
3257                         }
3258                         err = create_controls_idx(codec, name, idx, nid, 3);
3259                         if (err < 0)
3260                                 return err;
3261                 }
3262         }
3263         return 0;
3264 }
3265
3266 static int stac92xx_add_capvol_ctls(struct hda_codec *codec, unsigned long vol,
3267                                     unsigned long sw, int idx)
3268 {
3269         int err;
3270         err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_VOL, idx,
3271                                        "Capture Volume", vol);
3272         if (err < 0)
3273                 return err;
3274         err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_MUTE, idx,
3275                                        "Capture Switch", sw);
3276         if (err < 0)
3277                 return err;
3278         return 0;
3279 }
3280
3281 /* add playback controls from the parsed DAC table */
3282 static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
3283                                                const struct auto_pin_cfg *cfg)
3284 {
3285         struct sigmatel_spec *spec = codec->spec;
3286         hda_nid_t nid;
3287         int err;
3288         int idx;
3289
3290         err = create_multi_out_ctls(codec, cfg->line_outs, cfg->line_out_pins,
3291                                     spec->multiout.dac_nids,
3292                                     cfg->line_out_type);
3293         if (err < 0)
3294                 return err;
3295
3296         if (cfg->hp_outs > 1 && cfg->line_out_type == AUTO_PIN_LINE_OUT) {
3297                 err = stac92xx_add_control(spec,
3298                         STAC_CTL_WIDGET_HP_SWITCH,
3299                         "Headphone as Line Out Switch",
3300                         cfg->hp_pins[cfg->hp_outs - 1]);
3301                 if (err < 0)
3302                         return err;
3303         }
3304
3305         for (idx = 0; idx < cfg->num_inputs; idx++) {
3306                 if (cfg->inputs[idx].type > AUTO_PIN_LINE_IN)
3307                         break;
3308                 nid = cfg->inputs[idx].pin;
3309                 err = stac92xx_add_jack_mode_control(codec, nid, idx);
3310                 if (err < 0)
3311                         return err;
3312         }
3313
3314         return 0;
3315 }
3316
3317 /* add playback controls for Speaker and HP outputs */
3318 static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
3319                                         struct auto_pin_cfg *cfg)
3320 {
3321         struct sigmatel_spec *spec = codec->spec;
3322         int err;
3323
3324         err = create_multi_out_ctls(codec, cfg->hp_outs, cfg->hp_pins,
3325                                     spec->hp_dacs, AUTO_PIN_HP_OUT);
3326         if (err < 0)
3327                 return err;
3328
3329         err = create_multi_out_ctls(codec, cfg->speaker_outs, cfg->speaker_pins,
3330                                     spec->speaker_dacs, AUTO_PIN_SPEAKER_OUT);
3331         if (err < 0)
3332                 return err;
3333
3334         return 0;
3335 }
3336
3337 /* labels for mono mux outputs */
3338 static const char * const stac92xx_mono_labels[4] = {
3339         "DAC0", "DAC1", "Mixer", "DAC2"
3340 };
3341
3342 /* create mono mux for mono out on capable codecs */
3343 static int stac92xx_auto_create_mono_output_ctls(struct hda_codec *codec)
3344 {
3345         struct sigmatel_spec *spec = codec->spec;
3346         struct hda_input_mux *mono_mux = &spec->private_mono_mux;
3347         int i, num_cons;
3348         hda_nid_t con_lst[ARRAY_SIZE(stac92xx_mono_labels)];
3349
3350         num_cons = snd_hda_get_connections(codec,
3351                                 spec->mono_nid,
3352                                 con_lst,
3353                                 HDA_MAX_NUM_INPUTS);
3354         if (num_cons <= 0 || num_cons > ARRAY_SIZE(stac92xx_mono_labels))
3355                 return -EINVAL;
3356
3357         for (i = 0; i < num_cons; i++)
3358                 snd_hda_add_imux_item(mono_mux, stac92xx_mono_labels[i], i,
3359                                       NULL);
3360
3361         return stac92xx_add_control(spec, STAC_CTL_WIDGET_MONO_MUX,
3362                                 "Mono Mux", spec->mono_nid);
3363 }
3364
3365 /* create PC beep volume controls */
3366 static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
3367                                                 hda_nid_t nid)
3368 {
3369         struct sigmatel_spec *spec = codec->spec;
3370         u32 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3371         int err, type = STAC_CTL_WIDGET_MUTE_BEEP;
3372
3373         if (spec->anabeep_nid == nid)
3374                 type = STAC_CTL_WIDGET_MUTE;
3375
3376         /* check for mute support for the the amp */
3377         if ((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT) {
3378                 err = stac92xx_add_control(spec, type,
3379                         "Beep Playback Switch",
3380                         HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3381                         if (err < 0)
3382                                 return err;
3383         }
3384
3385         /* check to see if there is volume support for the amp */
3386         if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3387                 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL,
3388                         "Beep Playback Volume",
3389                         HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3390                         if (err < 0)
3391                                 return err;
3392         }
3393         return 0;
3394 }
3395
3396 #ifdef CONFIG_SND_HDA_INPUT_BEEP
3397 #define stac92xx_dig_beep_switch_info snd_ctl_boolean_mono_info
3398
3399 static int stac92xx_dig_beep_switch_get(struct snd_kcontrol *kcontrol,
3400                                         struct snd_ctl_elem_value *ucontrol)
3401 {
3402         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3403         ucontrol->value.integer.value[0] = codec->beep->enabled;
3404         return 0;
3405 }
3406
3407 static int stac92xx_dig_beep_switch_put(struct snd_kcontrol *kcontrol,
3408                                         struct snd_ctl_elem_value *ucontrol)
3409 {
3410         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3411         return snd_hda_enable_beep_device(codec, ucontrol->value.integer.value[0]);
3412 }
3413
3414 static const struct snd_kcontrol_new stac92xx_dig_beep_ctrl = {
3415         .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3416         .info = stac92xx_dig_beep_switch_info,
3417         .get = stac92xx_dig_beep_switch_get,
3418         .put = stac92xx_dig_beep_switch_put,
3419 };
3420
3421 static int stac92xx_beep_switch_ctl(struct hda_codec *codec)
3422 {
3423         return stac92xx_add_control_temp(codec->spec, &stac92xx_dig_beep_ctrl,
3424                                          0, "Beep Playback Switch", 0);
3425 }
3426 #endif
3427
3428 static int stac92xx_auto_create_mux_input_ctls(struct hda_codec *codec)
3429 {
3430         struct sigmatel_spec *spec = codec->spec;
3431         int i, j, err = 0;
3432
3433         for (i = 0; i < spec->num_muxes; i++) {
3434                 hda_nid_t nid;
3435                 unsigned int wcaps;
3436                 unsigned long val;
3437
3438                 nid = spec->mux_nids[i];
3439                 wcaps = get_wcaps(codec, nid);
3440                 if (!(wcaps & AC_WCAP_OUT_AMP))
3441                         continue;
3442
3443                 /* check whether already the same control was created as
3444                  * normal Capture Volume.
3445                  */
3446                 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3447                 for (j = 0; j < spec->num_caps; j++) {
3448                         if (spec->capvols[j] == val)
3449                                 break;
3450                 }
3451                 if (j < spec->num_caps)
3452                         continue;
3453
3454                 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, i,
3455                                                "Mux Capture Volume", val);
3456                 if (err < 0)
3457                         return err;
3458         }
3459         return 0;
3460 };
3461
3462 static const char * const stac92xx_spdif_labels[3] = {
3463         "Digital Playback", "Analog Mux 1", "Analog Mux 2",
3464 };
3465
3466 static int stac92xx_auto_create_spdif_mux_ctls(struct hda_codec *codec)
3467 {
3468         struct sigmatel_spec *spec = codec->spec;
3469         struct hda_input_mux *spdif_mux = &spec->private_smux;
3470         const char * const *labels = spec->spdif_labels;
3471         int i, num_cons;
3472         hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
3473
3474         num_cons = snd_hda_get_connections(codec,
3475                                 spec->smux_nids[0],
3476                                 con_lst,
3477                                 HDA_MAX_NUM_INPUTS);
3478         if (num_cons <= 0)
3479                 return -EINVAL;
3480
3481         if (!labels)
3482                 labels = stac92xx_spdif_labels;
3483
3484         for (i = 0; i < num_cons; i++)
3485                 snd_hda_add_imux_item(spdif_mux, labels[i], i, NULL);
3486
3487         return 0;
3488 }
3489
3490 /* labels for dmic mux inputs */
3491 static const char * const stac92xx_dmic_labels[5] = {
3492         "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
3493         "Digital Mic 3", "Digital Mic 4"
3494 };
3495
3496 static hda_nid_t get_connected_node(struct hda_codec *codec, hda_nid_t mux,
3497                                     int idx)
3498 {
3499         hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3500         int nums;
3501         nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3502         if (idx >= 0 && idx < nums)
3503                 return conn[idx];
3504         return 0;
3505 }
3506
3507 /* look for NID recursively */
3508 #define get_connection_index(codec, mux, nid) \
3509         snd_hda_get_conn_index(codec, mux, nid, 1)
3510
3511 /* create a volume assigned to the given pin (only if supported) */
3512 /* return 1 if the volume control is created */
3513 static int create_elem_capture_vol(struct hda_codec *codec, hda_nid_t nid,
3514                                    const char *label, int idx, int direction)
3515 {
3516         unsigned int caps, nums;
3517         char name[32];
3518         int err;
3519
3520         if (direction == HDA_OUTPUT)
3521                 caps = AC_WCAP_OUT_AMP;
3522         else
3523                 caps = AC_WCAP_IN_AMP;
3524         if (!(get_wcaps(codec, nid) & caps))
3525                 return 0;
3526         caps = query_amp_caps(codec, nid, direction);
3527         nums = (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT;
3528         if (!nums)
3529                 return 0;
3530         snprintf(name, sizeof(name), "%s Capture Volume", label);
3531         err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_VOL, idx, name,
3532                                        HDA_COMPOSE_AMP_VAL(nid, 3, 0, direction));
3533         if (err < 0)
3534                 return err;
3535         return 1;
3536 }
3537
3538 /* create playback/capture controls for input pins on dmic capable codecs */
3539 static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
3540                                                 const struct auto_pin_cfg *cfg)
3541 {
3542         struct sigmatel_spec *spec = codec->spec;
3543         struct hda_input_mux *imux = &spec->private_imux;
3544         struct hda_input_mux *dimux = &spec->private_dimux;
3545         int err, i;
3546         unsigned int def_conf;
3547
3548         snd_hda_add_imux_item(dimux, stac92xx_dmic_labels[0], 0, NULL);
3549
3550         for (i = 0; i < spec->num_dmics; i++) {
3551                 hda_nid_t nid;
3552                 int index, type_idx;
3553                 const char *label;
3554
3555                 nid = spec->dmic_nids[i];
3556                 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
3557                         continue;
3558                 def_conf = snd_hda_codec_get_pincfg(codec, nid);
3559                 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
3560                         continue;
3561
3562                 index = get_connection_index(codec, spec->dmux_nids[0], nid);
3563                 if (index < 0)
3564                         continue;
3565
3566                 label = hda_get_input_pin_label(codec, nid, 1);
3567                 snd_hda_add_imux_item(dimux, label, index, &type_idx);
3568                 if (snd_hda_get_bool_hint(codec, "separate_dmux") != 1)
3569                         snd_hda_add_imux_item(imux, label, index, &type_idx);
3570
3571                 err = create_elem_capture_vol(codec, nid, label, type_idx,
3572                                               HDA_INPUT);
3573                 if (err < 0)
3574                         return err;
3575                 if (!err) {
3576                         err = create_elem_capture_vol(codec, nid, label,
3577                                                       type_idx, HDA_OUTPUT);
3578                         if (err < 0)
3579                                 return err;
3580                         if (!err) {
3581                                 nid = get_connected_node(codec,
3582                                                 spec->dmux_nids[0], index);
3583                                 if (nid)
3584                                         err = create_elem_capture_vol(codec,
3585                                                         nid, label,
3586                                                         type_idx, HDA_INPUT);
3587                                 if (err < 0)
3588                                         return err;
3589                         }
3590                 }
3591         }
3592
3593         return 0;
3594 }
3595
3596 static int check_mic_pin(struct hda_codec *codec, hda_nid_t nid,
3597                          hda_nid_t *fixed, hda_nid_t *ext, hda_nid_t *dock)
3598 {
3599         unsigned int cfg;
3600         unsigned int type;
3601
3602         if (!nid)
3603                 return 0;
3604         cfg = snd_hda_codec_get_pincfg(codec, nid);
3605         type = get_defcfg_device(cfg);
3606         switch (snd_hda_get_input_pin_attr(cfg)) {
3607         case INPUT_PIN_ATTR_INT:
3608                 if (*fixed)
3609                         return 1; /* already occupied */
3610                 if (type != AC_JACK_MIC_IN)
3611                         return 1; /* invalid type */
3612                 *fixed = nid;
3613                 break;
3614         case INPUT_PIN_ATTR_UNUSED:
3615                 break;
3616         case INPUT_PIN_ATTR_DOCK:
3617                 if (*dock)
3618                         return 1; /* already occupied */
3619                 if (type != AC_JACK_MIC_IN && type != AC_JACK_LINE_IN)
3620                         return 1; /* invalid type */
3621                 *dock = nid;
3622                 break;
3623         default:
3624                 if (*ext)
3625                         return 1; /* already occupied */
3626                 if (type != AC_JACK_MIC_IN)
3627                         return 1; /* invalid type */
3628                 *ext = nid;
3629                 break;
3630         }
3631         return 0;
3632 }
3633
3634 static int set_mic_route(struct hda_codec *codec,
3635                          struct sigmatel_mic_route *mic,
3636                          hda_nid_t pin)
3637 {
3638         struct sigmatel_spec *spec = codec->spec;
3639         struct auto_pin_cfg *cfg = &spec->autocfg;
3640         int i;
3641
3642         mic->pin = pin;
3643         if (pin == 0)
3644                 return 0;
3645         for (i = 0; i < cfg->num_inputs; i++) {
3646                 if (pin == cfg->inputs[i].pin)
3647                         break;
3648         }
3649         if (i < cfg->num_inputs && cfg->inputs[i].type == AUTO_PIN_MIC) {
3650                 /* analog pin */
3651                 i = get_connection_index(codec, spec->mux_nids[0], pin);
3652                 if (i < 0)
3653                         return -1;
3654                 mic->mux_idx = i;
3655                 mic->dmux_idx = -1;
3656                 if (spec->dmux_nids)
3657                         mic->dmux_idx = get_connection_index(codec,
3658                                                              spec->dmux_nids[0],
3659                                                              spec->mux_nids[0]);
3660         }  else if (spec->dmux_nids) {
3661                 /* digital pin */
3662                 i = get_connection_index(codec, spec->dmux_nids[0], pin);
3663                 if (i < 0)
3664                         return -1;
3665                 mic->dmux_idx = i;
3666                 mic->mux_idx = -1;
3667                 if (spec->mux_nids)
3668                         mic->mux_idx = get_connection_index(codec,
3669                                                             spec->mux_nids[0],
3670                                                             spec->dmux_nids[0]);
3671         }
3672         return 0;
3673 }
3674
3675 /* return non-zero if the device is for automatic mic switch */
3676 static int stac_check_auto_mic(struct hda_codec *codec)
3677 {
3678         struct sigmatel_spec *spec = codec->spec;
3679         struct auto_pin_cfg *cfg = &spec->autocfg;
3680         hda_nid_t fixed, ext, dock;
3681         int i;
3682
3683         fixed = ext = dock = 0;
3684         for (i = 0; i < cfg->num_inputs; i++)
3685                 if (check_mic_pin(codec, cfg->inputs[i].pin,
3686                     &fixed, &ext, &dock))
3687                         return 0;
3688         for (i = 0; i < spec->num_dmics; i++)
3689                 if (check_mic_pin(codec, spec->dmic_nids[i],
3690                     &fixed, &ext, &dock))
3691                         return 0;
3692         if (!fixed || (!ext && !dock))
3693                 return 0; /* no input to switch */
3694         if (!is_jack_detectable(codec, ext))
3695                 return 0; /* no unsol support */
3696         if (set_mic_route(codec, &spec->ext_mic, ext) ||
3697             set_mic_route(codec, &spec->int_mic, fixed) ||
3698             set_mic_route(codec, &spec->dock_mic, dock))
3699                 return 0; /* something is wrong */
3700         return 1;
3701 }
3702
3703 /* create playback/capture controls for input pins */
3704 static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
3705 {
3706         struct sigmatel_spec *spec = codec->spec;
3707         struct hda_input_mux *imux = &spec->private_imux;
3708         int i, j;
3709         const char *label;
3710
3711         for (i = 0; i < cfg->num_inputs; i++) {
3712                 hda_nid_t nid = cfg->inputs[i].pin;
3713                 int index, err, type_idx;
3714
3715                 index = -1;
3716                 for (j = 0; j < spec->num_muxes; j++) {
3717                         index = get_connection_index(codec, spec->mux_nids[j],
3718                                                      nid);
3719                         if (index >= 0)
3720                                 break;
3721                 }
3722                 if (index < 0)
3723                         continue;
3724
3725                 label = hda_get_autocfg_input_label(codec, cfg, i);
3726                 snd_hda_add_imux_item(imux, label, index, &type_idx);
3727
3728                 err = create_elem_capture_vol(codec, nid,
3729                                               label, type_idx,
3730                                               HDA_INPUT);
3731                 if (err < 0)
3732                         return err;
3733         }
3734         spec->num_analog_muxes = imux->num_items;
3735
3736         if (imux->num_items) {
3737                 /*
3738                  * Set the current input for the muxes.
3739                  * The STAC9221 has two input muxes with identical source
3740                  * NID lists.  Hopefully this won't get confused.
3741                  */
3742                 for (i = 0; i < spec->num_muxes; i++) {
3743                         snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
3744                                                   AC_VERB_SET_CONNECT_SEL,
3745                                                   imux->items[0].index);
3746                 }
3747         }
3748
3749         return 0;
3750 }
3751
3752 static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
3753 {
3754         struct sigmatel_spec *spec = codec->spec;
3755         int i;
3756
3757         for (i = 0; i < spec->autocfg.line_outs; i++) {
3758                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3759                 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
3760         }
3761 }
3762
3763 static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
3764 {
3765         struct sigmatel_spec *spec = codec->spec;
3766         int i;
3767
3768         for (i = 0; i < spec->autocfg.hp_outs; i++) {
3769                 hda_nid_t pin;
3770                 pin = spec->autocfg.hp_pins[i];
3771                 if (pin) /* connect to front */
3772                         stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
3773         }
3774         for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3775                 hda_nid_t pin;
3776                 pin = spec->autocfg.speaker_pins[i];
3777                 if (pin) /* connect to front */
3778                         stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
3779         }
3780 }
3781
3782 static int is_dual_headphones(struct hda_codec *codec)
3783 {
3784         struct sigmatel_spec *spec = codec->spec;
3785         int i, valid_hps;
3786
3787         if (spec->autocfg.line_out_type != AUTO_PIN_SPEAKER_OUT ||
3788             spec->autocfg.hp_outs <= 1)
3789                 return 0;
3790         valid_hps = 0;
3791         for (i = 0; i < spec->autocfg.hp_outs; i++) {
3792                 hda_nid_t nid = spec->autocfg.hp_pins[i];
3793                 unsigned int cfg = snd_hda_codec_get_pincfg(codec, nid);
3794                 if (get_defcfg_location(cfg) & AC_JACK_LOC_SEPARATE)
3795                         continue;
3796                 valid_hps++;
3797         }
3798         return (valid_hps > 1);
3799 }
3800
3801
3802 static int stac92xx_parse_auto_config(struct hda_codec *codec)
3803 {
3804         struct sigmatel_spec *spec = codec->spec;
3805         hda_nid_t dig_out = 0, dig_in = 0;
3806         int hp_swap = 0;
3807         int i, err;
3808
3809         if ((err = snd_hda_parse_pin_def_config(codec,
3810                                                 &spec->autocfg,
3811                                                 spec->dmic_nids)) < 0)
3812                 return err;
3813         if (! spec->autocfg.line_outs)
3814                 return 0; /* can't find valid pin config */
3815
3816         /* If we have no real line-out pin and multiple hp-outs, HPs should
3817          * be set up as multi-channel outputs.
3818          */
3819         if (is_dual_headphones(codec)) {
3820                 /* Copy hp_outs to line_outs, backup line_outs in
3821                  * speaker_outs so that the following routines can handle
3822                  * HP pins as primary outputs.
3823                  */
3824                 snd_printdd("stac92xx: Enabling multi-HPs workaround\n");
3825                 memcpy(spec->autocfg.speaker_pins, spec->autocfg.line_out_pins,
3826                        sizeof(spec->autocfg.line_out_pins));
3827                 spec->autocfg.speaker_outs = spec->autocfg.line_outs;
3828                 memcpy(spec->autocfg.line_out_pins, spec->autocfg.hp_pins,
3829                        sizeof(spec->autocfg.hp_pins));
3830                 spec->autocfg.line_outs = spec->autocfg.hp_outs;
3831                 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3832                 spec->autocfg.hp_outs = 0;
3833                 hp_swap = 1;
3834         }
3835         if (spec->autocfg.mono_out_pin) {
3836                 int dir = get_wcaps(codec, spec->autocfg.mono_out_pin) &
3837                         (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
3838                 u32 caps = query_amp_caps(codec,
3839                                 spec->autocfg.mono_out_pin, dir);
3840                 hda_nid_t conn_list[1];
3841
3842                 /* get the mixer node and then the mono mux if it exists */
3843                 if (snd_hda_get_connections(codec,
3844                                 spec->autocfg.mono_out_pin, conn_list, 1) &&
3845                                 snd_hda_get_connections(codec, conn_list[0],
3846                                 conn_list, 1) > 0) {
3847
3848                                 int wcaps = get_wcaps(codec, conn_list[0]);
3849                                 int wid_type = get_wcaps_type(wcaps);
3850                                 /* LR swap check, some stac925x have a mux that
3851                                  * changes the DACs output path instead of the
3852                                  * mono-mux path.
3853                                  */
3854                                 if (wid_type == AC_WID_AUD_SEL &&
3855                                                 !(wcaps & AC_WCAP_LR_SWAP))
3856                                         spec->mono_nid = conn_list[0];
3857                 }
3858                 if (dir) {
3859                         hda_nid_t nid = spec->autocfg.mono_out_pin;
3860
3861                         /* most mono outs have a least a mute/unmute switch */
3862                         dir = (dir & AC_WCAP_OUT_AMP) ? HDA_OUTPUT : HDA_INPUT;
3863                         err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3864                                 "Mono Playback Switch",
3865                                 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
3866                         if (err < 0)
3867                                 return err;
3868                         /* check for volume support for the amp */
3869                         if ((caps & AC_AMPCAP_NUM_STEPS)
3870                                         >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3871                                 err = stac92xx_add_control(spec,
3872                                         STAC_CTL_WIDGET_VOL,
3873                                         "Mono Playback Volume",
3874                                 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
3875                                 if (err < 0)
3876                                         return err;
3877                         }
3878                 }
3879
3880                 stac92xx_auto_set_pinctl(codec, spec->autocfg.mono_out_pin,
3881                                          AC_PINCTL_OUT_EN);
3882         }
3883
3884         if (!spec->multiout.num_dacs) {
3885                 err = stac92xx_auto_fill_dac_nids(codec);
3886                 if (err < 0)
3887                         return err;
3888                 err = stac92xx_auto_create_multi_out_ctls(codec,
3889                                                           &spec->autocfg);
3890                 if (err < 0)
3891                         return err;
3892         }
3893
3894         /* setup analog beep controls */
3895         if (spec->anabeep_nid > 0) {
3896                 err = stac92xx_auto_create_beep_ctls(codec,
3897                         spec->anabeep_nid);
3898                 if (err < 0)
3899                         return err;
3900         }
3901
3902         /* setup digital beep controls and input device */
3903 #ifdef CONFIG_SND_HDA_INPUT_BEEP
3904         if (spec->digbeep_nid > 0) {
3905                 hda_nid_t nid = spec->digbeep_nid;
3906                 unsigned int caps;
3907
3908                 err = stac92xx_auto_create_beep_ctls(codec, nid);
3909                 if (err < 0)
3910                         return err;
3911                 err = snd_hda_attach_beep_device(codec, nid);
3912                 if (err < 0)
3913                         return err;
3914                 if (codec->beep) {
3915                         /* IDT/STAC codecs have linear beep tone parameter */
3916                         codec->beep->linear_tone = spec->linear_tone_beep;
3917                         /* if no beep switch is available, make its own one */
3918                         caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3919                         if (!(caps & AC_AMPCAP_MUTE)) {
3920                                 err = stac92xx_beep_switch_ctl(codec);
3921                                 if (err < 0)
3922                                         return err;
3923                         }
3924                 }
3925         }
3926 #endif
3927
3928         err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
3929         if (err < 0)
3930                 return err;
3931
3932         /* All output parsing done, now restore the swapped hp pins */
3933         if (hp_swap) {
3934                 memcpy(spec->autocfg.hp_pins, spec->autocfg.line_out_pins,
3935                        sizeof(spec->autocfg.hp_pins));
3936                 spec->autocfg.hp_outs = spec->autocfg.line_outs;
3937                 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3938                 spec->autocfg.line_outs = 0;
3939         }
3940
3941         if (stac_check_auto_mic(codec)) {
3942                 spec->auto_mic = 1;
3943                 /* only one capture for auto-mic */
3944                 spec->num_adcs = 1;
3945                 spec->num_caps = 1;
3946                 spec->num_muxes = 1;
3947         }
3948
3949         for (i = 0; i < spec->num_caps; i++) {
3950                 err = stac92xx_add_capvol_ctls(codec, spec->capvols[i],
3951                                                spec->capsws[i], i);
3952                 if (err < 0)
3953                         return err;
3954         }
3955
3956         err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
3957         if (err < 0)
3958                 return err;
3959
3960         if (spec->mono_nid > 0) {
3961                 err = stac92xx_auto_create_mono_output_ctls(codec);
3962                 if (err < 0)
3963                         return err;
3964         }
3965         if (spec->num_dmics > 0 && !spec->dinput_mux)
3966                 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
3967                                                 &spec->autocfg)) < 0)
3968                         return err;
3969         if (spec->num_muxes > 0) {
3970                 err = stac92xx_auto_create_mux_input_ctls(codec);
3971                 if (err < 0)
3972                         return err;
3973         }
3974         if (spec->num_smuxes > 0) {
3975                 err = stac92xx_auto_create_spdif_mux_ctls(codec);
3976                 if (err < 0)
3977                         return err;
3978         }
3979
3980         err = stac92xx_add_input_source(spec);
3981         if (err < 0)
3982                 return err;
3983
3984         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3985         if (spec->multiout.max_channels > 2)
3986                 spec->surr_switch = 1;
3987
3988         /* find digital out and in converters */
3989         for (i = codec->start_nid; i < codec->start_nid + codec->num_nodes; i++) {
3990                 unsigned int wid_caps = get_wcaps(codec, i);
3991                 if (wid_caps & AC_WCAP_DIGITAL) {
3992                         switch (get_wcaps_type(wid_caps)) {
3993                         case AC_WID_AUD_OUT:
3994                                 if (!dig_out)
3995                                         dig_out = i;
3996                                 break;
3997                         case AC_WID_AUD_IN:
3998                                 if (!dig_in)
3999                                         dig_in = i;
4000                                 break;
4001                         }
4002                 }
4003         }
4004         if (spec->autocfg.dig_outs)
4005                 spec->multiout.dig_out_nid = dig_out;
4006         if (dig_in && spec->autocfg.dig_in_pin)
4007                 spec->dig_in_nid = dig_in;
4008
4009         if (spec->kctls.list)
4010                 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4011
4012         spec->input_mux = &spec->private_imux;
4013         if (!spec->dinput_mux)
4014                 spec->dinput_mux = &spec->private_dimux;
4015         spec->sinput_mux = &spec->private_smux;
4016         spec->mono_mux = &spec->private_mono_mux;
4017         return 1;
4018 }
4019
4020 /* add playback controls for HP output */
4021 static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
4022                                         struct auto_pin_cfg *cfg)
4023 {
4024         struct sigmatel_spec *spec = codec->spec;
4025         hda_nid_t pin = cfg->hp_pins[0];
4026
4027         if (! pin)
4028                 return 0;
4029
4030         if (is_jack_detectable(codec, pin))
4031                 spec->hp_detect = 1;
4032
4033         return 0;
4034 }
4035
4036 /* add playback controls for LFE output */
4037 static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
4038                                         struct auto_pin_cfg *cfg)
4039 {
4040         struct sigmatel_spec *spec = codec->spec;
4041         int err;
4042         hda_nid_t lfe_pin = 0x0;
4043         int i;
4044
4045         /*
4046          * search speaker outs and line outs for a mono speaker pin
4047          * with an amp.  If one is found, add LFE controls
4048          * for it.
4049          */
4050         for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
4051                 hda_nid_t pin = spec->autocfg.speaker_pins[i];
4052                 unsigned int wcaps = get_wcaps(codec, pin);
4053                 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
4054                 if (wcaps == AC_WCAP_OUT_AMP)
4055                         /* found a mono speaker with an amp, must be lfe */
4056                         lfe_pin = pin;
4057         }
4058
4059         /* if speaker_outs is 0, then speakers may be in line_outs */
4060         if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
4061                 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
4062                         hda_nid_t pin = spec->autocfg.line_out_pins[i];
4063                         unsigned int defcfg;
4064                         defcfg = snd_hda_codec_get_pincfg(codec, pin);
4065                         if (get_defcfg_device(defcfg) == AC_JACK_SPEAKER) {
4066                                 unsigned int wcaps = get_wcaps(codec, pin);
4067                                 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
4068                                 if (wcaps == AC_WCAP_OUT_AMP)
4069                                         /* found a mono speaker with an amp,
4070                                            must be lfe */
4071                                         lfe_pin = pin;
4072                         }
4073                 }
4074         }
4075
4076         if (lfe_pin) {
4077                 err = create_controls(codec, "LFE", lfe_pin, 1);
4078                 if (err < 0)
4079                         return err;
4080         }
4081
4082         return 0;
4083 }
4084
4085 static int stac9200_parse_auto_config(struct hda_codec *codec)
4086 {
4087         struct sigmatel_spec *spec = codec->spec;
4088         int err;
4089
4090         if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
4091                 return err;
4092
4093         if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
4094                 return err;
4095
4096         if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
4097                 return err;
4098
4099         if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
4100                 return err;
4101
4102         if (spec->num_muxes > 0) {
4103                 err = stac92xx_auto_create_mux_input_ctls(codec);
4104                 if (err < 0)
4105                         return err;
4106         }
4107
4108         err = stac92xx_add_input_source(spec);
4109         if (err < 0)
4110                 return err;
4111
4112         if (spec->autocfg.dig_outs)
4113                 spec->multiout.dig_out_nid = 0x05;
4114         if (spec->autocfg.dig_in_pin)
4115                 spec->dig_in_nid = 0x04;
4116
4117         if (spec->kctls.list)
4118                 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4119
4120         spec->input_mux = &spec->private_imux;
4121         spec->dinput_mux = &spec->private_dimux;
4122
4123         return 1;
4124 }
4125
4126 /*
4127  * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
4128  * funky external mute control using GPIO pins.
4129  */
4130
4131 static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
4132                           unsigned int dir_mask, unsigned int data)
4133 {
4134         unsigned int gpiostate, gpiomask, gpiodir;
4135
4136         snd_printdd("%s msk %x dir %x gpio %x\n", __func__, mask, dir_mask, data);
4137
4138         gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
4139                                        AC_VERB_GET_GPIO_DATA, 0);
4140         gpiostate = (gpiostate & ~dir_mask) | (data & dir_mask);
4141
4142         gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
4143                                       AC_VERB_GET_GPIO_MASK, 0);
4144         gpiomask |= mask;
4145
4146         gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
4147                                      AC_VERB_GET_GPIO_DIRECTION, 0);
4148         gpiodir |= dir_mask;
4149
4150         /* Configure GPIOx as CMOS */
4151         snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
4152
4153         snd_hda_codec_write(codec, codec->afg, 0,
4154                             AC_VERB_SET_GPIO_MASK, gpiomask);
4155         snd_hda_codec_read(codec, codec->afg, 0,
4156                            AC_VERB_SET_GPIO_DIRECTION, gpiodir); /* sync */
4157
4158         msleep(1);
4159
4160         snd_hda_codec_read(codec, codec->afg, 0,
4161                            AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */
4162 }
4163
4164 static int stac92xx_add_jack(struct hda_codec *codec,
4165                 hda_nid_t nid, int type)
4166 {
4167 #ifdef CONFIG_SND_HDA_INPUT_JACK
4168         int def_conf = snd_hda_codec_get_pincfg(codec, nid);
4169         int connectivity = get_defcfg_connect(def_conf);
4170
4171         if (connectivity && connectivity != AC_JACK_PORT_FIXED)
4172                 return 0;
4173
4174         return snd_hda_input_jack_add(codec, nid, type, NULL);
4175 #else
4176         return 0;
4177 #endif /* CONFIG_SND_HDA_INPUT_JACK */
4178 }
4179
4180 static int stac_add_event(struct sigmatel_spec *spec, hda_nid_t nid,
4181                           unsigned char type, int data)
4182 {
4183         struct sigmatel_event *event;
4184
4185         snd_array_init(&spec->events, sizeof(*event), 32);
4186         event = snd_array_new(&spec->events);
4187         if (!event)
4188                 return -ENOMEM;
4189         event->nid = nid;
4190         event->type = type;
4191         event->tag = spec->events.used;
4192         event->data = data;
4193
4194         return event->tag;
4195 }
4196
4197 static struct sigmatel_event *stac_get_event(struct hda_codec *codec,
4198                                              hda_nid_t nid)
4199 {
4200         struct sigmatel_spec *spec = codec->spec;
4201         struct sigmatel_event *event = spec->events.list;
4202         int i;
4203
4204         for (i = 0; i < spec->events.used; i++, event++) {
4205                 if (event->nid == nid)
4206                         return event;
4207         }
4208         return NULL;
4209 }
4210
4211 static struct sigmatel_event *stac_get_event_from_tag(struct hda_codec *codec,
4212                                                       unsigned char tag)
4213 {
4214         struct sigmatel_spec *spec = codec->spec;
4215         struct sigmatel_event *event = spec->events.list;
4216         int i;
4217
4218         for (i = 0; i < spec->events.used; i++, event++) {
4219                 if (event->tag == tag)
4220                         return event;
4221         }
4222         return NULL;
4223 }
4224
4225 /* check if given nid is a valid pin and no other events are assigned
4226  * to it.  If OK, assign the event, set the unsol flag, and returns 1.
4227  * Otherwise, returns zero.
4228  */
4229 static int enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
4230                              unsigned int type)
4231 {
4232         struct sigmatel_event *event;
4233         int tag;
4234
4235         if (!is_jack_detectable(codec, nid))
4236                 return 0;
4237         event = stac_get_event(codec, nid);
4238         if (event) {
4239                 if (event->type != type)
4240                         return 0;
4241                 tag = event->tag;
4242         } else {
4243                 tag = stac_add_event(codec->spec, nid, type, 0);
4244                 if (tag < 0)
4245                         return 0;
4246         }
4247         snd_hda_codec_write_cache(codec, nid, 0,
4248                                   AC_VERB_SET_UNSOLICITED_ENABLE,
4249                                   AC_USRSP_EN | tag);
4250         return 1;
4251 }
4252
4253 static int is_nid_hp_pin(struct auto_pin_cfg *cfg, hda_nid_t nid)
4254 {
4255         int i;
4256         for (i = 0; i < cfg->hp_outs; i++)
4257                 if (cfg->hp_pins[i] == nid)
4258                         return 1; /* nid is a HP-Out */
4259
4260         return 0; /* nid is not a HP-Out */
4261 };
4262
4263 static void stac92xx_power_down(struct hda_codec *codec)
4264 {
4265         struct sigmatel_spec *spec = codec->spec;
4266
4267         /* power down inactive DACs */
4268         const hda_nid_t *dac;
4269         for (dac = spec->dac_list; *dac; dac++)
4270                 if (!check_all_dac_nids(spec, *dac))
4271                         snd_hda_codec_write(codec, *dac, 0,
4272                                         AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4273 }
4274
4275 static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4276                                   int enable);
4277
4278 static inline int get_int_hint(struct hda_codec *codec, const char *key,
4279                                int *valp)
4280 {
4281         const char *p;
4282         p = snd_hda_get_hint(codec, key);
4283         if (p) {
4284                 unsigned long val;
4285                 if (!strict_strtoul(p, 0, &val)) {
4286                         *valp = val;
4287                         return 1;
4288                 }
4289         }
4290         return 0;
4291 }
4292
4293 /* override some hints from the hwdep entry */
4294 static void stac_store_hints(struct hda_codec *codec)
4295 {
4296         struct sigmatel_spec *spec = codec->spec;
4297         int val;
4298
4299         val = snd_hda_get_bool_hint(codec, "hp_detect");
4300         if (val >= 0)
4301                 spec->hp_detect = val;
4302         if (get_int_hint(codec, "gpio_mask", &spec->gpio_mask)) {
4303                 spec->eapd_mask = spec->gpio_dir = spec->gpio_data =
4304                         spec->gpio_mask;
4305         }
4306         if (get_int_hint(codec, "gpio_dir", &spec->gpio_dir))
4307                 spec->gpio_mask &= spec->gpio_mask;
4308         if (get_int_hint(codec, "gpio_data", &spec->gpio_data))
4309                 spec->gpio_dir &= spec->gpio_mask;
4310         if (get_int_hint(codec, "eapd_mask", &spec->eapd_mask))
4311                 spec->eapd_mask &= spec->gpio_mask;
4312         if (get_int_hint(codec, "gpio_mute", &spec->gpio_mute))
4313                 spec->gpio_mute &= spec->gpio_mask;
4314         val = snd_hda_get_bool_hint(codec, "eapd_switch");
4315         if (val >= 0)
4316                 spec->eapd_switch = val;
4317         get_int_hint(codec, "gpio_led_polarity", &spec->gpio_led_polarity);
4318         if (get_int_hint(codec, "gpio_led", &spec->gpio_led)) {
4319                 if (spec->gpio_led <= 8) {
4320                         spec->gpio_mask |= spec->gpio_led;
4321                         spec->gpio_dir |= spec->gpio_led;
4322                         if (spec->gpio_led_polarity)
4323                                 spec->gpio_data |= spec->gpio_led;
4324                 }
4325         }
4326 }
4327
4328 static int stac92xx_init(struct hda_codec *codec)
4329 {
4330         struct sigmatel_spec *spec = codec->spec;
4331         struct auto_pin_cfg *cfg = &spec->autocfg;
4332         unsigned int gpio;
4333         int i;
4334
4335         snd_hda_sequence_write(codec, spec->init);
4336
4337         /* power down adcs initially */
4338         if (spec->powerdown_adcs)
4339                 for (i = 0; i < spec->num_adcs; i++)
4340                         snd_hda_codec_write(codec,
4341                                 spec->adc_nids[i], 0,
4342                                 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4343
4344         /* override some hints */
4345         stac_store_hints(codec);
4346
4347         /* set up GPIO */
4348         gpio = spec->gpio_data;
4349         /* turn on EAPD statically when spec->eapd_switch isn't set.
4350          * otherwise, unsol event will turn it on/off dynamically
4351          */
4352         if (!spec->eapd_switch)
4353                 gpio |= spec->eapd_mask;
4354         stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, gpio);
4355
4356         /* set up pins */
4357         if (spec->hp_detect) {
4358                 /* Enable unsolicited responses on the HP widget */
4359                 for (i = 0; i < cfg->hp_outs; i++) {
4360                         hda_nid_t nid = cfg->hp_pins[i];
4361                         enable_pin_detect(codec, nid, STAC_HP_EVENT);
4362                 }
4363                 if (cfg->line_out_type == AUTO_PIN_LINE_OUT &&
4364                     cfg->speaker_outs > 0) {
4365                         /* enable pin-detect for line-outs as well */
4366                         for (i = 0; i < cfg->line_outs; i++) {
4367                                 hda_nid_t nid = cfg->line_out_pins[i];
4368                                 enable_pin_detect(codec, nid, STAC_LO_EVENT);
4369                         }
4370                 }
4371
4372                 /* force to enable the first line-out; the others are set up
4373                  * in unsol_event
4374                  */
4375                 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
4376                                 AC_PINCTL_OUT_EN);
4377                 /* fake event to set up pins */
4378                 if (cfg->hp_pins[0])
4379                         stac_issue_unsol_event(codec, cfg->hp_pins[0]);
4380                 else if (cfg->line_out_pins[0])
4381                         stac_issue_unsol_event(codec, cfg->line_out_pins[0]);
4382         } else {
4383                 stac92xx_auto_init_multi_out(codec);
4384                 stac92xx_auto_init_hp_out(codec);
4385                 for (i = 0; i < cfg->hp_outs; i++)
4386                         stac_toggle_power_map(codec, cfg->hp_pins[i], 1);
4387         }
4388         if (spec->auto_mic) {
4389                 /* initialize connection to analog input */
4390                 if (spec->dmux_nids)
4391                         snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
4392                                           AC_VERB_SET_CONNECT_SEL, 0);
4393                 if (enable_pin_detect(codec, spec->ext_mic.pin, STAC_MIC_EVENT))
4394                         stac_issue_unsol_event(codec, spec->ext_mic.pin);
4395                 if (enable_pin_detect(codec, spec->dock_mic.pin,
4396                     STAC_MIC_EVENT))
4397                         stac_issue_unsol_event(codec, spec->dock_mic.pin);
4398         }
4399         for (i = 0; i < cfg->num_inputs; i++) {
4400                 hda_nid_t nid = cfg->inputs[i].pin;
4401                 int type = cfg->inputs[i].type;
4402                 unsigned int pinctl, conf;
4403                 if (type == AUTO_PIN_MIC) {
4404                         /* for mic pins, force to initialize */
4405                         pinctl = stac92xx_get_default_vref(codec, nid);
4406                         pinctl |= AC_PINCTL_IN_EN;
4407                         stac92xx_auto_set_pinctl(codec, nid, pinctl);
4408                 } else {
4409                         pinctl = snd_hda_codec_read(codec, nid, 0,
4410                                         AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4411                         /* if PINCTL already set then skip */
4412                         /* Also, if both INPUT and OUTPUT are set,
4413                          * it must be a BIOS bug; need to override, too
4414                          */
4415                         if (!(pinctl & AC_PINCTL_IN_EN) ||
4416                             (pinctl & AC_PINCTL_OUT_EN)) {
4417                                 pinctl &= ~AC_PINCTL_OUT_EN;
4418                                 pinctl |= AC_PINCTL_IN_EN;
4419                                 stac92xx_auto_set_pinctl(codec, nid, pinctl);
4420                         }
4421                 }
4422                 conf = snd_hda_codec_get_pincfg(codec, nid);
4423                 if (get_defcfg_connect(conf) != AC_JACK_PORT_FIXED) {
4424                         if (enable_pin_detect(codec, nid, STAC_INSERT_EVENT))
4425                                 stac_issue_unsol_event(codec, nid);
4426                 }
4427         }
4428         for (i = 0; i < spec->num_dmics; i++)
4429                 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
4430                                         AC_PINCTL_IN_EN);
4431         if (cfg->dig_out_pins[0])
4432                 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pins[0],
4433                                          AC_PINCTL_OUT_EN);
4434         if (cfg->dig_in_pin)
4435                 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
4436                                          AC_PINCTL_IN_EN);
4437         for (i = 0; i < spec->num_pwrs; i++)  {
4438                 hda_nid_t nid = spec->pwr_nids[i];
4439                 int pinctl, def_conf;
4440
4441                 /* power on when no jack detection is available */
4442                 if (!spec->hp_detect) {
4443                         stac_toggle_power_map(codec, nid, 1);
4444                         continue;
4445                 }
4446
4447                 if (is_nid_hp_pin(cfg, nid))
4448                         continue; /* already has an unsol event */
4449
4450                 pinctl = snd_hda_codec_read(codec, nid, 0,
4451                                             AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4452                 /* outputs are only ports capable of power management
4453                  * any attempts on powering down a input port cause the
4454                  * referenced VREF to act quirky.
4455                  */
4456                 if (pinctl & AC_PINCTL_IN_EN) {
4457                         stac_toggle_power_map(codec, nid, 1);
4458                         continue;
4459                 }
4460                 def_conf = snd_hda_codec_get_pincfg(codec, nid);
4461                 def_conf = get_defcfg_connect(def_conf);
4462                 /* skip any ports that don't have jacks since presence
4463                  * detection is useless */
4464                 if (def_conf != AC_JACK_PORT_COMPLEX) {
4465                         if (def_conf != AC_JACK_PORT_NONE)
4466                                 stac_toggle_power_map(codec, nid, 1);
4467                         continue;
4468                 }
4469                 if (enable_pin_detect(codec, nid, STAC_PWR_EVENT)) {
4470                         stac_issue_unsol_event(codec, nid);
4471                         continue;
4472                 }
4473                 /* none of the above, turn the port OFF */
4474                 stac_toggle_power_map(codec, nid, 0);
4475         }
4476
4477         /* sync mute LED */
4478         if (spec->gpio_led)
4479                 hda_call_check_power_status(codec, 0x01);
4480         if (spec->dac_list)
4481                 stac92xx_power_down(codec);
4482         return 0;
4483 }
4484
4485 static void stac92xx_free_kctls(struct hda_codec *codec)
4486 {
4487         struct sigmatel_spec *spec = codec->spec;
4488
4489         if (spec->kctls.list) {
4490                 struct snd_kcontrol_new *kctl = spec->kctls.list;
4491                 int i;
4492                 for (i = 0; i < spec->kctls.used; i++)
4493                         kfree(kctl[i].name);
4494         }
4495         snd_array_free(&spec->kctls);
4496 }
4497
4498 static void stac92xx_shutup_pins(struct hda_codec *codec)
4499 {
4500         unsigned int i, def_conf;
4501
4502         if (codec->bus->shutdown)
4503                 return;
4504         for (i = 0; i < codec->init_pins.used; i++) {
4505                 struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i);
4506                 def_conf = snd_hda_codec_get_pincfg(codec, pin->nid);
4507                 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)
4508                         snd_hda_codec_write(codec, pin->nid, 0,
4509                                     AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
4510         }
4511 }
4512
4513 static void stac92xx_shutup(struct hda_codec *codec)
4514 {
4515         struct sigmatel_spec *spec = codec->spec;
4516
4517         stac92xx_shutup_pins(codec);
4518
4519         if (spec->eapd_mask)
4520                 stac_gpio_set(codec, spec->gpio_mask,
4521                                 spec->gpio_dir, spec->gpio_data &
4522                                 ~spec->eapd_mask);
4523 }
4524
4525 static void stac92xx_free(struct hda_codec *codec)
4526 {
4527         struct sigmatel_spec *spec = codec->spec;
4528
4529         if (! spec)
4530                 return;
4531
4532         stac92xx_shutup(codec);
4533         snd_hda_input_jack_free(codec);
4534         snd_array_free(&spec->events);
4535
4536         kfree(spec);
4537         snd_hda_detach_beep_device(codec);
4538 }
4539
4540 static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
4541                                 unsigned int flag)
4542 {
4543         unsigned int old_ctl, pin_ctl;
4544
4545         pin_ctl = snd_hda_codec_read(codec, nid,
4546                         0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
4547
4548         if (pin_ctl & AC_PINCTL_IN_EN) {
4549                 /*
4550                  * we need to check the current set-up direction of
4551                  * shared input pins since they can be switched via
4552                  * "xxx as Output" mixer switch
4553                  */
4554                 struct sigmatel_spec *spec = codec->spec;
4555                 if (nid == spec->line_switch || nid == spec->mic_switch)
4556                         return;
4557         }
4558
4559         old_ctl = pin_ctl;
4560         /* if setting pin direction bits, clear the current
4561            direction bits first */
4562         if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
4563                 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
4564         
4565         pin_ctl |= flag;
4566         if (old_ctl != pin_ctl)
4567                 snd_hda_codec_write_cache(codec, nid, 0,
4568                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
4569                                           pin_ctl);
4570 }
4571
4572 static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
4573                                   unsigned int flag)
4574 {
4575         unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
4576                         0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
4577         if (pin_ctl & flag)
4578                 snd_hda_codec_write_cache(codec, nid, 0,
4579                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
4580                                           pin_ctl & ~flag);
4581 }
4582
4583 static inline int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
4584 {
4585         if (!nid)
4586                 return 0;
4587         return snd_hda_jack_detect(codec, nid);
4588 }
4589
4590 static void stac92xx_line_out_detect(struct hda_codec *codec,
4591                                      int presence)
4592 {
4593         struct sigmatel_spec *spec = codec->spec;
4594         struct auto_pin_cfg *cfg = &spec->autocfg;
4595         int i;
4596
4597         for (i = 0; i < cfg->line_outs; i++) {
4598                 if (presence)
4599                         break;
4600                 presence = get_pin_presence(codec, cfg->line_out_pins[i]);
4601                 if (presence) {
4602                         unsigned int pinctl;
4603                         pinctl = snd_hda_codec_read(codec,
4604                                                     cfg->line_out_pins[i], 0,
4605                                             AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4606                         if (pinctl & AC_PINCTL_IN_EN)
4607                                 presence = 0; /* mic- or line-input */
4608                 }
4609         }
4610
4611         if (presence) {
4612                 /* disable speakers */
4613                 for (i = 0; i < cfg->speaker_outs; i++)
4614                         stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
4615                                                 AC_PINCTL_OUT_EN);
4616                 if (spec->eapd_mask && spec->eapd_switch)
4617                         stac_gpio_set(codec, spec->gpio_mask,
4618                                 spec->gpio_dir, spec->gpio_data &
4619                                 ~spec->eapd_mask);
4620         } else {
4621                 /* enable speakers */
4622                 for (i = 0; i < cfg->speaker_outs; i++)
4623                         stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
4624                                                 AC_PINCTL_OUT_EN);
4625                 if (spec->eapd_mask && spec->eapd_switch)
4626                         stac_gpio_set(codec, spec->gpio_mask,
4627                                 spec->gpio_dir, spec->gpio_data |
4628                                 spec->eapd_mask);
4629         }
4630
4631
4632 /* return non-zero if the hp-pin of the given array index isn't
4633  * a jack-detection target
4634  */
4635 static int no_hp_sensing(struct sigmatel_spec *spec, int i)
4636 {
4637         struct auto_pin_cfg *cfg = &spec->autocfg;
4638
4639         /* ignore sensing of shared line and mic jacks */
4640         if (cfg->hp_pins[i] == spec->line_switch)
4641                 return 1;
4642         if (cfg->hp_pins[i] == spec->mic_switch)
4643                 return 1;
4644         /* ignore if the pin is set as line-out */
4645         if (cfg->hp_pins[i] == spec->hp_switch)
4646                 return 1;
4647         return 0;
4648 }
4649
4650 static void stac92xx_hp_detect(struct hda_codec *codec)
4651 {
4652         struct sigmatel_spec *spec = codec->spec;
4653         struct auto_pin_cfg *cfg = &spec->autocfg;
4654         int i, presence;
4655
4656         presence = 0;
4657         if (spec->gpio_mute)
4658                 presence = !(snd_hda_codec_read(codec, codec->afg, 0,
4659                         AC_VERB_GET_GPIO_DATA, 0) & spec->gpio_mute);
4660
4661         for (i = 0; i < cfg->hp_outs; i++) {
4662                 if (presence)
4663                         break;
4664                 if (no_hp_sensing(spec, i))
4665                         continue;
4666                 presence = get_pin_presence(codec, cfg->hp_pins[i]);
4667                 if (presence) {
4668                         unsigned int pinctl;
4669                         pinctl = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
4670                                             AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4671                         if (pinctl & AC_PINCTL_IN_EN)
4672                                 presence = 0; /* mic- or line-input */
4673                 }
4674         }
4675
4676         if (presence) {
4677                 /* disable lineouts */
4678                 if (spec->hp_switch)
4679                         stac92xx_reset_pinctl(codec, spec->hp_switch,
4680                                               AC_PINCTL_OUT_EN);
4681                 for (i = 0; i < cfg->line_outs; i++)
4682                         stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
4683                                                 AC_PINCTL_OUT_EN);
4684         } else {
4685                 /* enable lineouts */
4686                 if (spec->hp_switch)
4687                         stac92xx_set_pinctl(codec, spec->hp_switch,
4688                                             AC_PINCTL_OUT_EN);
4689                 for (i = 0; i < cfg->line_outs; i++)
4690                         stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
4691                                                 AC_PINCTL_OUT_EN);
4692         }
4693         stac92xx_line_out_detect(codec, presence);
4694         /* toggle hp outs */
4695         for (i = 0; i < cfg->hp_outs; i++) {
4696                 unsigned int val = AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN;
4697                 if (no_hp_sensing(spec, i))
4698                         continue;
4699                 if (presence)
4700                         stac92xx_set_pinctl(codec, cfg->hp_pins[i], val);
4701 #if 0 /* FIXME */
4702 /* Resetting the pinctl like below may lead to (a sort of) regressions
4703  * on some devices since they use the HP pin actually for line/speaker
4704  * outs although the default pin config shows a different pin (that is
4705  * wrong and useless).
4706  *
4707  * So, it's basically a problem of default pin configs, likely a BIOS issue.
4708  * But, disabling the code below just works around it, and I'm too tired of
4709  * bug reports with such devices... 
4710  */
4711                 else
4712                         stac92xx_reset_pinctl(codec, cfg->hp_pins[i], val);
4713 #endif /* FIXME */
4714         }
4715
4716
4717 static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4718                                   int enable)
4719 {
4720         struct sigmatel_spec *spec = codec->spec;
4721         unsigned int idx, val;
4722
4723         for (idx = 0; idx < spec->num_pwrs; idx++) {
4724                 if (spec->pwr_nids[idx] == nid)
4725                         break;
4726         }
4727         if (idx >= spec->num_pwrs)
4728                 return;
4729
4730         idx = 1 << idx;
4731
4732         val = snd_hda_codec_read(codec, codec->afg, 0, 0x0fec, 0x0) & 0xff;
4733         if (enable)
4734                 val &= ~idx;
4735         else
4736                 val |= idx;
4737
4738         /* power down unused output ports */
4739         snd_hda_codec_write(codec, codec->afg, 0, 0x7ec, val);
4740 }
4741
4742 static void stac92xx_pin_sense(struct hda_codec *codec, hda_nid_t nid)
4743 {
4744         stac_toggle_power_map(codec, nid, get_pin_presence(codec, nid));
4745 }
4746
4747 /* get the pin connection (fixed, none, etc) */
4748 static unsigned int stac_get_defcfg_connect(struct hda_codec *codec, int idx)
4749 {
4750         struct sigmatel_spec *spec = codec->spec;
4751         unsigned int cfg;
4752
4753         cfg = snd_hda_codec_get_pincfg(codec, spec->pin_nids[idx]);
4754         return get_defcfg_connect(cfg);
4755 }
4756
4757 static int stac92xx_connected_ports(struct hda_codec *codec,
4758                                     const hda_nid_t *nids, int num_nids)
4759 {
4760         struct sigmatel_spec *spec = codec->spec;
4761         int idx, num;
4762         unsigned int def_conf;
4763
4764         for (num = 0; num < num_nids; num++) {
4765                 for (idx = 0; idx < spec->num_pins; idx++)
4766                         if (spec->pin_nids[idx] == nids[num])
4767                                 break;
4768                 if (idx >= spec->num_pins)
4769                         break;
4770                 def_conf = stac_get_defcfg_connect(codec, idx);
4771                 if (def_conf == AC_JACK_PORT_NONE)
4772                         break;
4773         }
4774         return num;
4775 }
4776
4777 static void stac92xx_mic_detect(struct hda_codec *codec)
4778 {
4779         struct sigmatel_spec *spec = codec->spec;
4780         struct sigmatel_mic_route *mic;
4781
4782         if (get_pin_presence(codec, spec->ext_mic.pin))
4783                 mic = &spec->ext_mic;
4784         else if (get_pin_presence(codec, spec->dock_mic.pin))
4785                 mic = &spec->dock_mic;
4786         else
4787                 mic = &spec->int_mic;
4788         if (mic->dmux_idx >= 0)
4789                 snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
4790                                           AC_VERB_SET_CONNECT_SEL,
4791                                           mic->dmux_idx);
4792         if (mic->mux_idx >= 0)
4793                 snd_hda_codec_write_cache(codec, spec->mux_nids[0], 0,
4794                                           AC_VERB_SET_CONNECT_SEL,
4795                                           mic->mux_idx);
4796 }
4797
4798 static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid)
4799 {
4800         struct sigmatel_event *event = stac_get_event(codec, nid);
4801         if (!event)
4802                 return;
4803         codec->patch_ops.unsol_event(codec, (unsigned)event->tag << 26);
4804 }
4805
4806 static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
4807 {
4808         struct sigmatel_spec *spec = codec->spec;
4809         struct sigmatel_event *event;
4810         int tag, data;
4811
4812         tag = (res >> 26) & 0x7f;
4813         event = stac_get_event_from_tag(codec, tag);
4814         if (!event)
4815                 return;
4816
4817         switch (event->type) {
4818         case STAC_HP_EVENT:
4819         case STAC_LO_EVENT:
4820                 stac92xx_hp_detect(codec);
4821                 break;
4822         case STAC_MIC_EVENT:
4823                 stac92xx_mic_detect(codec);
4824                 break;
4825         }
4826
4827         switch (event->type) {
4828         case STAC_HP_EVENT:
4829         case STAC_LO_EVENT:
4830         case STAC_MIC_EVENT:
4831         case STAC_INSERT_EVENT:
4832         case STAC_PWR_EVENT:
4833                 if (spec->num_pwrs > 0)
4834                         stac92xx_pin_sense(codec, event->nid);
4835                 snd_hda_input_jack_report(codec, event->nid);
4836
4837                 switch (codec->subsystem_id) {
4838                 case 0x103c308f:
4839                         if (event->nid == 0xb) {
4840                                 int pin = AC_PINCTL_IN_EN;
4841
4842                                 if (get_pin_presence(codec, 0xa)
4843                                                 && get_pin_presence(codec, 0xb))
4844                                         pin |= AC_PINCTL_VREF_80;
4845                                 if (!get_pin_presence(codec, 0xb))
4846                                         pin |= AC_PINCTL_VREF_80;
4847
4848                                 /* toggle VREF state based on mic + hp pin
4849                                  * status
4850                                  */
4851                                 stac92xx_auto_set_pinctl(codec, 0x0a, pin);
4852                         }
4853                 }
4854                 break;
4855         case STAC_VREF_EVENT:
4856                 data = snd_hda_codec_read(codec, codec->afg, 0,
4857                                           AC_VERB_GET_GPIO_DATA, 0);
4858                 /* toggle VREF state based on GPIOx status */
4859                 snd_hda_codec_write(codec, codec->afg, 0, 0x7e0,
4860                                     !!(data & (1 << event->data)));
4861                 break;
4862         }
4863 }
4864
4865 static int hp_blike_system(u32 subsystem_id);
4866
4867 static void set_hp_led_gpio(struct hda_codec *codec)
4868 {
4869         struct sigmatel_spec *spec = codec->spec;
4870         unsigned int gpio;
4871
4872         if (spec->gpio_led)
4873                 return;
4874
4875         gpio = snd_hda_param_read(codec, codec->afg, AC_PAR_GPIO_CAP);
4876         gpio &= AC_GPIO_IO_COUNT;
4877         if (gpio > 3)
4878                 spec->gpio_led = 0x08; /* GPIO 3 */
4879         else
4880                 spec->gpio_led = 0x01; /* GPIO 0 */
4881 }
4882
4883 /*
4884  * This method searches for the mute LED GPIO configuration
4885  * provided as OEM string in SMBIOS. The format of that string
4886  * is HP_Mute_LED_P_G or HP_Mute_LED_P
4887  * where P can be 0 or 1 and defines mute LED GPIO control state (low/high)
4888  * that corresponds to the NOT muted state of the master volume
4889  * and G is the index of the GPIO to use as the mute LED control (0..9)
4890  * If _G portion is missing it is assigned based on the codec ID
4891  *
4892  * So, HP B-series like systems may have HP_Mute_LED_0 (current models)
4893  * or  HP_Mute_LED_0_3 (future models) OEM SMBIOS strings
4894  *
4895  *
4896  * The dv-series laptops don't seem to have the HP_Mute_LED* strings in
4897  * SMBIOS - at least the ones I have seen do not have them - which include
4898  * my own system (HP Pavilion dv6-1110ax) and my cousin's
4899  * HP Pavilion dv9500t CTO.
4900  * Need more information on whether it is true across the entire series.
4901  * -- kunal
4902  */
4903 static int find_mute_led_gpio(struct hda_codec *codec, int default_polarity)
4904 {
4905         struct sigmatel_spec *spec = codec->spec;
4906         const struct dmi_device *dev = NULL;
4907
4908         if ((codec->subsystem_id >> 16) == PCI_VENDOR_ID_HP) {
4909                 while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING,
4910                                                                 NULL, dev))) {
4911                         if (sscanf(dev->name, "HP_Mute_LED_%d_%x",
4912                                   &spec->gpio_led_polarity,
4913                                   &spec->gpio_led) == 2) {
4914                                 if (spec->gpio_led < 4)
4915                                         spec->gpio_led = 1 << spec->gpio_led;
4916                                 return 1;
4917                         }
4918                         if (sscanf(dev->name, "HP_Mute_LED_%d",
4919                                   &spec->gpio_led_polarity) == 1) {
4920                                 set_hp_led_gpio(codec);
4921                                 return 1;
4922                         }
4923                 }
4924
4925                 /*
4926                  * Fallback case - if we don't find the DMI strings,
4927                  * we statically set the GPIO - if not a B-series system.
4928                  */
4929                 if (!hp_blike_system(codec->subsystem_id)) {
4930                         set_hp_led_gpio(codec);
4931                         spec->gpio_led_polarity = default_polarity;
4932                         return 1;
4933                 }
4934         }
4935         return 0;
4936 }
4937
4938 static int hp_blike_system(u32 subsystem_id)
4939 {
4940         switch (subsystem_id) {
4941         case 0x103c1520:
4942         case 0x103c1521:
4943         case 0x103c1523:
4944         case 0x103c1524:
4945         case 0x103c1525:
4946         case 0x103c1722:
4947         case 0x103c1723:
4948         case 0x103c1724:
4949         case 0x103c1725:
4950         case 0x103c1726:
4951         case 0x103c1727:
4952         case 0x103c1728:
4953         case 0x103c1729:
4954         case 0x103c172a:
4955         case 0x103c172b:
4956         case 0x103c307e:
4957         case 0x103c307f:
4958         case 0x103c3080:
4959         case 0x103c3081:
4960         case 0x103c7007:
4961         case 0x103c7008:
4962                 return 1;
4963         }
4964         return 0;
4965 }
4966
4967 #ifdef CONFIG_PROC_FS
4968 static void stac92hd_proc_hook(struct snd_info_buffer *buffer,
4969                                struct hda_codec *codec, hda_nid_t nid)
4970 {
4971         if (nid == codec->afg)
4972                 snd_iprintf(buffer, "Power-Map: 0x%02x\n", 
4973                             snd_hda_codec_read(codec, nid, 0, 0x0fec, 0x0));
4974 }
4975
4976 static void analog_loop_proc_hook(struct snd_info_buffer *buffer,
4977                                   struct hda_codec *codec,
4978                                   unsigned int verb)
4979 {
4980         snd_iprintf(buffer, "Analog Loopback: 0x%02x\n",
4981                     snd_hda_codec_read(codec, codec->afg, 0, verb, 0));
4982 }
4983
4984 /* stac92hd71bxx, stac92hd73xx */
4985 static void stac92hd7x_proc_hook(struct snd_info_buffer *buffer,
4986                                  struct hda_codec *codec, hda_nid_t nid)
4987 {
4988         stac92hd_proc_hook(buffer, codec, nid);
4989         if (nid == codec->afg)
4990                 analog_loop_proc_hook(buffer, codec, 0xfa0);
4991 }
4992
4993 static void stac9205_proc_hook(struct snd_info_buffer *buffer,
4994                                struct hda_codec *codec, hda_nid_t nid)
4995 {
4996         if (nid == codec->afg)
4997                 analog_loop_proc_hook(buffer, codec, 0xfe0);
4998 }
4999
5000 static void stac927x_proc_hook(struct snd_info_buffer *buffer,
5001                                struct hda_codec *codec, hda_nid_t nid)
5002 {
5003         if (nid == codec->afg)
5004                 analog_loop_proc_hook(buffer, codec, 0xfeb);
5005 }
5006 #else
5007 #define stac92hd_proc_hook      NULL
5008 #define stac92hd7x_proc_hook    NULL
5009 #define stac9205_proc_hook      NULL
5010 #define stac927x_proc_hook      NULL
5011 #endif
5012
5013 #ifdef CONFIG_PM
5014 static int stac92xx_resume(struct hda_codec *codec)
5015 {
5016         struct sigmatel_spec *spec = codec->spec;
5017
5018         stac92xx_init(codec);
5019         snd_hda_codec_resume_amp(codec);
5020         snd_hda_codec_resume_cache(codec);
5021         /* fake event to set up pins again to override cached values */
5022         if (spec->hp_detect) {
5023                 if (spec->autocfg.hp_pins[0])
5024                         stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0]);
5025                 else if (spec->autocfg.line_out_pins[0])
5026                         stac_issue_unsol_event(codec,
5027                                                spec->autocfg.line_out_pins[0]);
5028         }
5029         return 0;
5030 }
5031
5032 static int stac92xx_suspend(struct hda_codec *codec, pm_message_t state)
5033 {
5034         stac92xx_shutup(codec);
5035         return 0;
5036 }
5037
5038 #ifdef CONFIG_SND_HDA_POWER_SAVE
5039 static int stac92xx_pre_resume(struct hda_codec *codec)
5040 {
5041         struct sigmatel_spec *spec = codec->spec;
5042
5043         /* sync mute LED */
5044         if (spec->gpio_led) {
5045                 if (spec->gpio_led <= 8) {
5046                         stac_gpio_set(codec, spec->gpio_mask,
5047                                         spec->gpio_dir, spec->gpio_data);
5048                 } else {
5049                         stac_vrefout_set(codec,
5050                                         spec->gpio_led, spec->vref_led);
5051                 }
5052         }
5053         return 0;
5054 }
5055
5056 static int stac92xx_post_suspend(struct hda_codec *codec)
5057 {
5058         struct sigmatel_spec *spec = codec->spec;
5059         if (spec->gpio_led > 8) {
5060                 /* with vref-out pin used for mute led control
5061                  * codec AFG is prevented from D3 state, but on
5062                  * system suspend it can (and should) be used
5063                  */
5064                 snd_hda_codec_read(codec, codec->afg, 0,
5065                                 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
5066         }
5067         return 0;
5068 }
5069
5070 static void stac92xx_set_power_state(struct hda_codec *codec, hda_nid_t fg,
5071                                 unsigned int power_state)
5072 {
5073         unsigned int afg_power_state = power_state;
5074         struct sigmatel_spec *spec = codec->spec;
5075
5076         if (power_state == AC_PWRST_D3) {
5077                 if (spec->gpio_led > 8) {
5078                         /* with vref-out pin used for mute led control
5079                          * codec AFG is prevented from D3 state
5080                          */
5081                         afg_power_state = AC_PWRST_D1;
5082                 }
5083                 /* this delay seems necessary to avoid click noise at power-down */
5084                 msleep(100);
5085         }
5086         snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE,
5087                         afg_power_state);
5088         snd_hda_codec_set_power_to_all(codec, fg, power_state, true);
5089 }
5090
5091 /*
5092  * For this feature CONFIG_SND_HDA_POWER_SAVE is needed
5093  * as mute LED state is updated in check_power_status hook
5094  */
5095 static int stac92xx_update_led_status(struct hda_codec *codec)
5096 {
5097         struct sigmatel_spec *spec = codec->spec;
5098         int i, num_ext_dacs, muted = 1;
5099         unsigned int muted_lvl, notmtd_lvl;
5100         hda_nid_t nid;
5101
5102         if (!spec->gpio_led)
5103                 return 0;
5104
5105         for (i = 0; i < spec->multiout.num_dacs; i++) {
5106                 nid = spec->multiout.dac_nids[i];
5107                 if (!(snd_hda_codec_amp_read(codec, nid, 0, HDA_OUTPUT, 0) &
5108                       HDA_AMP_MUTE)) {
5109                         muted = 0; /* something heard */
5110                         break;
5111                 }
5112         }
5113         if (muted && spec->multiout.hp_nid)
5114                 if (!(snd_hda_codec_amp_read(codec,
5115                                 spec->multiout.hp_nid, 0, HDA_OUTPUT, 0) &
5116                                         HDA_AMP_MUTE)) {
5117                         muted = 0; /* HP is not muted */
5118                 }
5119         num_ext_dacs = ARRAY_SIZE(spec->multiout.extra_out_nid);
5120         for (i = 0; muted && i < num_ext_dacs; i++) {
5121                 nid = spec->multiout.extra_out_nid[i];
5122                 if (nid == 0)
5123                         break;
5124                 if (!(snd_hda_codec_amp_read(codec, nid, 0, HDA_OUTPUT, 0) &
5125                       HDA_AMP_MUTE)) {
5126                         muted = 0; /* extra output is not muted */
5127                 }
5128         }
5129         /*polarity defines *not* muted state level*/
5130         if (spec->gpio_led <= 8) {
5131                 if (muted)
5132                         spec->gpio_data &= ~spec->gpio_led; /* orange */
5133                 else
5134                         spec->gpio_data |= spec->gpio_led; /* white */
5135
5136                 if (!spec->gpio_led_polarity) {
5137                         /* LED state is inverted on these systems */
5138                         spec->gpio_data ^= spec->gpio_led;
5139                 }
5140                 stac_gpio_set(codec, spec->gpio_mask,
5141                                 spec->gpio_dir, spec->gpio_data);
5142         } else {
5143                 notmtd_lvl = spec->gpio_led_polarity ?
5144                                 AC_PINCTL_VREF_HIZ : AC_PINCTL_VREF_GRD;
5145                 muted_lvl = spec->gpio_led_polarity ?
5146                                 AC_PINCTL_VREF_GRD : AC_PINCTL_VREF_HIZ;
5147                 spec->vref_led = muted ? muted_lvl : notmtd_lvl;
5148                 stac_vrefout_set(codec, spec->gpio_led, spec->vref_led);
5149         }
5150         return 0;
5151 }
5152
5153 /*
5154  * use power check for controlling mute led of HP notebooks
5155  */
5156 static int stac92xx_check_power_status(struct hda_codec *codec,
5157                                               hda_nid_t nid)
5158 {
5159         stac92xx_update_led_status(codec);
5160
5161         return 0;
5162 }
5163 #endif /* CONFIG_SND_HDA_POWER_SAVE */
5164 #endif /* CONFIG_PM */
5165
5166 static const struct hda_codec_ops stac92xx_patch_ops = {
5167         .build_controls = stac92xx_build_controls,
5168         .build_pcms = stac92xx_build_pcms,
5169         .init = stac92xx_init,
5170         .free = stac92xx_free,
5171         .unsol_event = stac92xx_unsol_event,
5172 #ifdef CONFIG_PM
5173         .suspend = stac92xx_suspend,
5174         .resume = stac92xx_resume,
5175 #endif
5176         .reboot_notify = stac92xx_shutup,
5177 };
5178
5179 static int patch_stac9200(struct hda_codec *codec)
5180 {
5181         struct sigmatel_spec *spec;
5182         int err;
5183
5184         spec  = kzalloc(sizeof(*spec), GFP_KERNEL);
5185         if (spec == NULL)
5186                 return -ENOMEM;
5187
5188         codec->no_trigger_sense = 1;
5189         codec->spec = spec;
5190         spec->linear_tone_beep = 1;
5191         spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
5192         spec->pin_nids = stac9200_pin_nids;
5193         spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
5194                                                         stac9200_models,
5195                                                         stac9200_cfg_tbl);
5196         if (spec->board_config < 0)
5197                 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5198                             codec->chip_name);
5199         else
5200                 stac92xx_set_config_regs(codec,
5201                                          stac9200_brd_tbl[spec->board_config]);
5202
5203         spec->multiout.max_channels = 2;
5204         spec->multiout.num_dacs = 1;
5205         spec->multiout.dac_nids = stac9200_dac_nids;
5206         spec->adc_nids = stac9200_adc_nids;
5207         spec->mux_nids = stac9200_mux_nids;
5208         spec->num_muxes = 1;
5209         spec->num_dmics = 0;
5210         spec->num_adcs = 1;
5211         spec->num_pwrs = 0;
5212
5213         if (spec->board_config == STAC_9200_M4 ||
5214             spec->board_config == STAC_9200_M4_2 ||
5215             spec->board_config == STAC_9200_OQO)
5216                 spec->init = stac9200_eapd_init;
5217         else
5218                 spec->init = stac9200_core_init;
5219         spec->mixer = stac9200_mixer;
5220
5221         if (spec->board_config == STAC_9200_PANASONIC) {
5222                 spec->gpio_mask = spec->gpio_dir = 0x09;
5223                 spec->gpio_data = 0x00;
5224         }
5225
5226         err = stac9200_parse_auto_config(codec);
5227         if (err < 0) {
5228                 stac92xx_free(codec);
5229                 return err;
5230         }
5231
5232         /* CF-74 has no headphone detection, and the driver should *NOT*
5233          * do detection and HP/speaker toggle because the hardware does it.
5234          */
5235         if (spec->board_config == STAC_9200_PANASONIC)
5236                 spec->hp_detect = 0;
5237
5238         codec->patch_ops = stac92xx_patch_ops;
5239
5240         return 0;
5241 }
5242
5243 static int patch_stac925x(struct hda_codec *codec)
5244 {
5245         struct sigmatel_spec *spec;
5246         int err;
5247
5248         spec  = kzalloc(sizeof(*spec), GFP_KERNEL);
5249         if (spec == NULL)
5250                 return -ENOMEM;
5251
5252         codec->no_trigger_sense = 1;
5253         codec->spec = spec;
5254         spec->linear_tone_beep = 1;
5255         spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
5256         spec->pin_nids = stac925x_pin_nids;
5257
5258         /* Check first for codec ID */
5259         spec->board_config = snd_hda_check_board_codec_sid_config(codec,
5260                                                         STAC_925x_MODELS,
5261                                                         stac925x_models,
5262                                                         stac925x_codec_id_cfg_tbl);
5263
5264         /* Now checks for PCI ID, if codec ID is not found */
5265         if (spec->board_config < 0)
5266                 spec->board_config = snd_hda_check_board_config(codec,
5267                                                         STAC_925x_MODELS,
5268                                                         stac925x_models,
5269                                                         stac925x_cfg_tbl);
5270  again:
5271         if (spec->board_config < 0)
5272                 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5273                             codec->chip_name);
5274         else
5275                 stac92xx_set_config_regs(codec,
5276                                          stac925x_brd_tbl[spec->board_config]);
5277
5278         spec->multiout.max_channels = 2;
5279         spec->multiout.num_dacs = 1;
5280         spec->multiout.dac_nids = stac925x_dac_nids;
5281         spec->adc_nids = stac925x_adc_nids;
5282         spec->mux_nids = stac925x_mux_nids;
5283         spec->num_muxes = 1;
5284         spec->num_adcs = 1;
5285         spec->num_pwrs = 0;
5286         switch (codec->vendor_id) {
5287         case 0x83847632: /* STAC9202  */
5288         case 0x83847633: /* STAC9202D */
5289         case 0x83847636: /* STAC9251  */
5290         case 0x83847637: /* STAC9251D */
5291                 spec->num_dmics = STAC925X_NUM_DMICS;
5292                 spec->dmic_nids = stac925x_dmic_nids;
5293                 spec->num_dmuxes = ARRAY_SIZE(stac925x_dmux_nids);
5294                 spec->dmux_nids = stac925x_dmux_nids;
5295                 break;
5296         default:
5297                 spec->num_dmics = 0;
5298                 break;
5299         }
5300
5301         spec->init = stac925x_core_init;
5302         spec->mixer = stac925x_mixer;
5303         spec->num_caps = 1;
5304         spec->capvols = stac925x_capvols;
5305         spec->capsws = stac925x_capsws;
5306
5307         err = stac92xx_parse_auto_config(codec);
5308         if (!err) {
5309                 if (spec->board_config < 0) {
5310                         printk(KERN_WARNING "hda_codec: No auto-config is "
5311                                "available, default to model=ref\n");
5312                         spec->board_config = STAC_925x_REF;
5313                         goto again;
5314                 }
5315                 err = -EINVAL;
5316         }
5317         if (err < 0) {
5318                 stac92xx_free(codec);
5319                 return err;
5320         }
5321
5322         codec->patch_ops = stac92xx_patch_ops;
5323
5324         return 0;
5325 }
5326
5327 static int patch_stac92hd73xx(struct hda_codec *codec)
5328 {
5329         struct sigmatel_spec *spec;
5330         hda_nid_t conn[STAC92HD73_DAC_COUNT + 2];
5331         int err = 0;
5332         int num_dacs;
5333
5334         spec  = kzalloc(sizeof(*spec), GFP_KERNEL);
5335         if (spec == NULL)
5336                 return -ENOMEM;
5337
5338         codec->no_trigger_sense = 1;
5339         codec->spec = spec;
5340         spec->linear_tone_beep = 0;
5341         codec->slave_dig_outs = stac92hd73xx_slave_dig_outs;
5342         spec->num_pins = ARRAY_SIZE(stac92hd73xx_pin_nids);
5343         spec->pin_nids = stac92hd73xx_pin_nids;
5344         spec->board_config = snd_hda_check_board_config(codec,
5345                                                         STAC_92HD73XX_MODELS,
5346                                                         stac92hd73xx_models,
5347                                                         stac92hd73xx_cfg_tbl);
5348         /* check codec subsystem id if not found */
5349         if (spec->board_config < 0)
5350                 spec->board_config =
5351                         snd_hda_check_board_codec_sid_config(codec,
5352                                 STAC_92HD73XX_MODELS, stac92hd73xx_models,
5353                                 stac92hd73xx_codec_id_cfg_tbl);
5354 again:
5355         if (spec->board_config < 0)
5356                 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5357                             codec->chip_name);
5358         else
5359                 stac92xx_set_config_regs(codec,
5360                                 stac92hd73xx_brd_tbl[spec->board_config]);
5361
5362         num_dacs = snd_hda_get_connections(codec, 0x0a,
5363                         conn, STAC92HD73_DAC_COUNT + 2) - 1;
5364
5365         if (num_dacs < 3 || num_dacs > 5) {
5366                 printk(KERN_WARNING "hda_codec: Could not determine "
5367                        "number of channels defaulting to DAC count\n");
5368                 num_dacs = STAC92HD73_DAC_COUNT;
5369         }
5370         spec->init = stac92hd73xx_core_init;
5371         switch (num_dacs) {
5372         case 0x3: /* 6 Channel */
5373                 spec->aloopback_ctl = stac92hd73xx_6ch_loopback;
5374                 break;
5375         case 0x4: /* 8 Channel */
5376                 spec->aloopback_ctl = stac92hd73xx_8ch_loopback;
5377                 break;
5378         case 0x5: /* 10 Channel */
5379                 spec->aloopback_ctl = stac92hd73xx_10ch_loopback;
5380                 break;
5381         }
5382         spec->multiout.dac_nids = spec->dac_nids;
5383
5384         spec->aloopback_mask = 0x01;
5385         spec->aloopback_shift = 8;
5386
5387         spec->digbeep_nid = 0x1c;
5388         spec->mux_nids = stac92hd73xx_mux_nids;
5389         spec->adc_nids = stac92hd73xx_adc_nids;
5390         spec->dmic_nids = stac92hd73xx_dmic_nids;
5391         spec->dmux_nids = stac92hd73xx_dmux_nids;
5392         spec->smux_nids = stac92hd73xx_smux_nids;
5393
5394         spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids);
5395         spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids);
5396         spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids);
5397
5398         spec->num_caps = STAC92HD73XX_NUM_CAPS;
5399         spec->capvols = stac92hd73xx_capvols;
5400         spec->capsws = stac92hd73xx_capsws;
5401
5402         switch (spec->board_config) {
5403         case STAC_DELL_EQ:
5404                 spec->init = dell_eq_core_init;
5405                 /* fallthru */
5406         case STAC_DELL_M6_AMIC:
5407         case STAC_DELL_M6_DMIC:
5408         case STAC_DELL_M6_BOTH:
5409                 spec->num_smuxes = 0;
5410                 spec->eapd_switch = 0;
5411
5412                 switch (spec->board_config) {
5413                 case STAC_DELL_M6_AMIC: /* Analog Mics */
5414                         snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
5415                         spec->num_dmics = 0;
5416                         break;
5417                 case STAC_DELL_M6_DMIC: /* Digital Mics */
5418                         snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
5419                         spec->num_dmics = 1;
5420                         break;
5421                 case STAC_DELL_M6_BOTH: /* Both */
5422                         snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
5423                         snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
5424                         spec->num_dmics = 1;
5425                         break;
5426                 }
5427                 break;
5428         case STAC_ALIENWARE_M17X:
5429                 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
5430                 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
5431                 spec->eapd_switch = 0;
5432                 break;
5433         default:
5434                 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
5435                 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
5436                 spec->eapd_switch = 1;
5437                 break;
5438         }
5439         if (spec->board_config != STAC_92HD73XX_REF) {
5440                 /* GPIO0 High = Enable EAPD */
5441                 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
5442                 spec->gpio_data = 0x01;
5443         }
5444
5445         spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
5446         spec->pwr_nids = stac92hd73xx_pwr_nids;
5447
5448         err = stac92xx_parse_auto_config(codec);
5449
5450         if (!err) {
5451                 if (spec->board_config < 0) {
5452                         printk(KERN_WARNING "hda_codec: No auto-config is "
5453                                "available, default to model=ref\n");
5454                         spec->board_config = STAC_92HD73XX_REF;
5455                         goto again;
5456                 }
5457                 err = -EINVAL;
5458         }
5459
5460         if (err < 0) {
5461                 stac92xx_free(codec);
5462                 return err;
5463         }
5464
5465         if (spec->board_config == STAC_92HD73XX_NO_JD)
5466                 spec->hp_detect = 0;
5467
5468         codec->patch_ops = stac92xx_patch_ops;
5469
5470         codec->proc_widget_hook = stac92hd7x_proc_hook;
5471
5472         return 0;
5473 }
5474
5475 static int hp_bnb2011_with_dock(struct hda_codec *codec)
5476 {
5477         if (codec->vendor_id != 0x111d7605 &&
5478             codec->vendor_id != 0x111d76d1)
5479                 return 0;
5480
5481         switch (codec->subsystem_id) {
5482         case 0x103c1618:
5483         case 0x103c1619:
5484         case 0x103c161a:
5485         case 0x103c161b:
5486         case 0x103c161c:
5487         case 0x103c161d:
5488         case 0x103c161e:
5489         case 0x103c161f:
5490
5491         case 0x103c162a:
5492         case 0x103c162b:
5493
5494         case 0x103c1630:
5495         case 0x103c1631:
5496
5497         case 0x103c1633:
5498         case 0x103c1634:
5499         case 0x103c1635:
5500
5501         case 0x103c3587:
5502         case 0x103c3588:
5503         case 0x103c3589:
5504         case 0x103c358a:
5505
5506         case 0x103c3667:
5507         case 0x103c3668:
5508         case 0x103c3669:
5509
5510                 return 1;
5511         }
5512         return 0;
5513 }
5514
5515 static void stac92hd8x_add_pin(struct hda_codec *codec, hda_nid_t nid)
5516 {
5517         struct sigmatel_spec *spec = codec->spec;
5518         unsigned int def_conf = snd_hda_codec_get_pincfg(codec, nid);
5519         int i;
5520
5521         spec->auto_pin_nids[spec->auto_pin_cnt] = nid;
5522         spec->auto_pin_cnt++;
5523
5524         if (get_defcfg_device(def_conf) == AC_JACK_MIC_IN &&
5525             get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE) {
5526                 for (i = 0; i < ARRAY_SIZE(stac92hd83xxx_dmic_nids); i++) {
5527                         if (nid == stac92hd83xxx_dmic_nids[i]) {
5528                                 spec->auto_dmic_nids[spec->auto_dmic_cnt] = nid;
5529                                 spec->auto_dmic_cnt++;
5530                         }
5531                 }
5532         }
5533 }
5534
5535 static void stac92hd8x_add_adc(struct hda_codec *codec, hda_nid_t nid)
5536 {
5537         struct sigmatel_spec *spec = codec->spec;
5538
5539         spec->auto_adc_nids[spec->auto_adc_cnt] = nid;
5540         spec->auto_adc_cnt++;
5541 }
5542
5543 static void stac92hd8x_add_mux(struct hda_codec *codec, hda_nid_t nid)
5544 {
5545         int i, j;
5546         struct sigmatel_spec *spec = codec->spec;
5547
5548         for (i = 0; i < spec->auto_adc_cnt; i++) {
5549                 if (get_connection_index(codec,
5550                                 spec->auto_adc_nids[i], nid) >= 0) {
5551                         /* mux and volume for adc_nids[i] */
5552                         if (!spec->auto_mux_nids[i]) {
5553                                 spec->auto_mux_nids[i] = nid;
5554                                 /* 92hd codecs capture volume is in mux */
5555                                 spec->auto_capvols[i] = HDA_COMPOSE_AMP_VAL(nid,
5556                                                         3, 0, HDA_OUTPUT);
5557                         }
5558                         for (j = 0; j < spec->auto_dmic_cnt; j++) {
5559                                 if (get_connection_index(codec, nid,
5560                                                 spec->auto_dmic_nids[j]) >= 0) {
5561                                         /* dmux for adc_nids[i] */
5562                                         if (!spec->auto_dmux_nids[i])
5563                                                 spec->auto_dmux_nids[i] = nid;
5564                                         break;
5565                                 }
5566                         }
5567                         break;
5568                 }
5569         }
5570 }
5571
5572 static void stac92hd8x_fill_auto_spec(struct hda_codec *codec)
5573 {
5574         hda_nid_t nid, end_nid;
5575         unsigned int wid_caps, wid_type;
5576         struct sigmatel_spec *spec = codec->spec;
5577
5578         end_nid = codec->start_nid + codec->num_nodes;
5579
5580         for (nid = codec->start_nid; nid < end_nid; nid++) {
5581                 wid_caps = get_wcaps(codec, nid);
5582                 wid_type = get_wcaps_type(wid_caps);
5583
5584                 if (wid_type == AC_WID_PIN)
5585                         stac92hd8x_add_pin(codec, nid);
5586
5587                 if (wid_type == AC_WID_AUD_IN && !(wid_caps & AC_WCAP_DIGITAL))
5588                         stac92hd8x_add_adc(codec, nid);
5589         }
5590
5591         for (nid = codec->start_nid; nid < end_nid; nid++) {
5592                 wid_caps = get_wcaps(codec, nid);
5593                 wid_type = get_wcaps_type(wid_caps);
5594
5595                 if (wid_type == AC_WID_AUD_SEL)
5596                         stac92hd8x_add_mux(codec, nid);
5597         }
5598
5599         spec->pin_nids = spec->auto_pin_nids;
5600         spec->num_pins = spec->auto_pin_cnt;
5601         spec->adc_nids = spec->auto_adc_nids;
5602         spec->num_adcs = spec->auto_adc_cnt;
5603         spec->capvols = spec->auto_capvols;
5604         spec->capsws = spec->auto_capvols;
5605         spec->num_caps = spec->auto_adc_cnt;
5606         spec->mux_nids = spec->auto_mux_nids;
5607         spec->num_muxes = spec->auto_adc_cnt;
5608         spec->dmux_nids = spec->auto_dmux_nids;
5609         spec->num_dmuxes = spec->auto_adc_cnt;
5610         spec->dmic_nids = spec->auto_dmic_nids;
5611         spec->num_dmics = spec->auto_dmic_cnt;
5612 }
5613
5614 static int patch_stac92hd83xxx(struct hda_codec *codec)
5615 {
5616         struct sigmatel_spec *spec;
5617         int err;
5618
5619         spec  = kzalloc(sizeof(*spec), GFP_KERNEL);
5620         if (spec == NULL)
5621                 return -ENOMEM;
5622
5623         if (hp_bnb2011_with_dock(codec)) {
5624                 snd_hda_codec_set_pincfg(codec, 0xa, 0x2101201f);
5625                 snd_hda_codec_set_pincfg(codec, 0xf, 0x2181205e);
5626         }
5627
5628         codec->no_trigger_sense = 1;
5629         codec->spec = spec;
5630
5631         stac92hd8x_fill_auto_spec(codec);
5632
5633         spec->linear_tone_beep = 0;
5634         codec->slave_dig_outs = stac92hd83xxx_slave_dig_outs;
5635         spec->digbeep_nid = 0x21;
5636         spec->pwr_nids = stac92hd83xxx_pwr_nids;
5637         spec->num_pwrs = ARRAY_SIZE(stac92hd83xxx_pwr_nids);
5638         spec->multiout.dac_nids = spec->dac_nids;
5639         spec->init = stac92hd83xxx_core_init;
5640
5641         spec->board_config = snd_hda_check_board_config(codec,
5642                                                         STAC_92HD83XXX_MODELS,
5643                                                         stac92hd83xxx_models,
5644                                                         stac92hd83xxx_cfg_tbl);
5645 again:
5646         if (spec->board_config < 0)
5647                 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5648                             codec->chip_name);
5649         else
5650                 stac92xx_set_config_regs(codec,
5651                                 stac92hd83xxx_brd_tbl[spec->board_config]);
5652
5653         codec->patch_ops = stac92xx_patch_ops;
5654
5655         if (find_mute_led_gpio(codec, 0))
5656                 snd_printd("mute LED gpio %d polarity %d\n",
5657                                 spec->gpio_led,
5658                                 spec->gpio_led_polarity);
5659
5660 #ifdef CONFIG_SND_HDA_POWER_SAVE
5661         if (spec->gpio_led) {
5662                 if (spec->gpio_led <= 8) {
5663                         spec->gpio_mask |= spec->gpio_led;
5664                         spec->gpio_dir |= spec->gpio_led;
5665                         spec->gpio_data |= spec->gpio_led;
5666                 } else {
5667                         codec->patch_ops.set_power_state =
5668                                         stac92xx_set_power_state;
5669                         codec->patch_ops.post_suspend =
5670                                         stac92xx_post_suspend;
5671                 }
5672                 codec->patch_ops.pre_resume = stac92xx_pre_resume;
5673                 codec->patch_ops.check_power_status =
5674                         stac92xx_check_power_status;
5675         }
5676 #endif  
5677
5678         err = stac92xx_parse_auto_config(codec);
5679         if (!err) {
5680                 if (spec->board_config < 0) {
5681                         printk(KERN_WARNING "hda_codec: No auto-config is "
5682                                "available, default to model=ref\n");
5683                         spec->board_config = STAC_92HD83XXX_REF;
5684                         goto again;
5685                 }
5686                 err = -EINVAL;
5687         }
5688
5689         if (err < 0) {
5690                 stac92xx_free(codec);
5691                 return err;
5692         }
5693
5694         codec->proc_widget_hook = stac92hd_proc_hook;
5695
5696         return 0;
5697 }
5698
5699 static int stac92hd71bxx_connected_smuxes(struct hda_codec *codec,
5700                                           hda_nid_t dig0pin)
5701 {
5702         struct sigmatel_spec *spec = codec->spec;
5703         int idx;
5704
5705         for (idx = 0; idx < spec->num_pins; idx++)
5706                 if (spec->pin_nids[idx] == dig0pin)
5707                         break;
5708         if ((idx + 2) >= spec->num_pins)
5709                 return 0;
5710
5711         /* dig1pin case */
5712         if (stac_get_defcfg_connect(codec, idx + 1) != AC_JACK_PORT_NONE)
5713                 return 2;
5714
5715         /* dig0pin + dig2pin case */
5716         if (stac_get_defcfg_connect(codec, idx + 2) != AC_JACK_PORT_NONE)
5717                 return 2;
5718         if (stac_get_defcfg_connect(codec, idx) != AC_JACK_PORT_NONE)
5719                 return 1;
5720         else
5721                 return 0;
5722 }
5723
5724 /* HP dv7 bass switch - GPIO5 */
5725 #define stac_hp_bass_gpio_info  snd_ctl_boolean_mono_info
5726 static int stac_hp_bass_gpio_get(struct snd_kcontrol *kcontrol,
5727                                  struct snd_ctl_elem_value *ucontrol)
5728 {
5729         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5730         struct sigmatel_spec *spec = codec->spec;
5731         ucontrol->value.integer.value[0] = !!(spec->gpio_data & 0x20);
5732         return 0;
5733 }
5734
5735 static int stac_hp_bass_gpio_put(struct snd_kcontrol *kcontrol,
5736                                  struct snd_ctl_elem_value *ucontrol)
5737 {
5738         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5739         struct sigmatel_spec *spec = codec->spec;
5740         unsigned int gpio_data;
5741
5742         gpio_data = (spec->gpio_data & ~0x20) |
5743                 (ucontrol->value.integer.value[0] ? 0x20 : 0);
5744         if (gpio_data == spec->gpio_data)
5745                 return 0;
5746         spec->gpio_data = gpio_data;
5747         stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, spec->gpio_data);
5748         return 1;
5749 }
5750
5751 static const struct snd_kcontrol_new stac_hp_bass_sw_ctrl = {
5752         .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5753         .info = stac_hp_bass_gpio_info,
5754         .get = stac_hp_bass_gpio_get,
5755         .put = stac_hp_bass_gpio_put,
5756 };
5757
5758 static int stac_add_hp_bass_switch(struct hda_codec *codec)
5759 {
5760         struct sigmatel_spec *spec = codec->spec;
5761
5762         if (!stac_control_new(spec, &stac_hp_bass_sw_ctrl,
5763                               "Bass Speaker Playback Switch", 0))
5764                 return -ENOMEM;
5765
5766         spec->gpio_mask |= 0x20;
5767         spec->gpio_dir |= 0x20;
5768         spec->gpio_data |= 0x20;
5769         return 0;
5770 }
5771
5772 static int patch_stac92hd71bxx(struct hda_codec *codec)
5773 {
5774         struct sigmatel_spec *spec;
5775         const struct hda_verb *unmute_init = stac92hd71bxx_unmute_core_init;
5776         unsigned int pin_cfg;
5777         int err = 0;
5778
5779         spec  = kzalloc(sizeof(*spec), GFP_KERNEL);
5780         if (spec == NULL)
5781                 return -ENOMEM;
5782
5783         codec->no_trigger_sense = 1;
5784         codec->spec = spec;
5785         spec->linear_tone_beep = 0;
5786         codec->patch_ops = stac92xx_patch_ops;
5787         spec->num_pins = STAC92HD71BXX_NUM_PINS;
5788         switch (codec->vendor_id) {
5789         case 0x111d76b6:
5790         case 0x111d76b7:
5791                 spec->pin_nids = stac92hd71bxx_pin_nids_4port;
5792                 break;
5793         case 0x111d7603:
5794         case 0x111d7608:
5795                 /* On 92HD75Bx 0x27 isn't a pin nid */
5796                 spec->num_pins--;
5797                 /* fallthrough */
5798         default:
5799                 spec->pin_nids = stac92hd71bxx_pin_nids_6port;
5800         }
5801         spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids);
5802         spec->board_config = snd_hda_check_board_config(codec,
5803                                                         STAC_92HD71BXX_MODELS,
5804                                                         stac92hd71bxx_models,
5805                                                         stac92hd71bxx_cfg_tbl);
5806 again:
5807         if (spec->board_config < 0)
5808                 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5809                             codec->chip_name);
5810         else
5811                 stac92xx_set_config_regs(codec,
5812                                 stac92hd71bxx_brd_tbl[spec->board_config]);
5813
5814         if (spec->board_config != STAC_92HD71BXX_REF) {
5815                 /* GPIO0 = EAPD */
5816                 spec->gpio_mask = 0x01;
5817                 spec->gpio_dir = 0x01;
5818                 spec->gpio_data = 0x01;
5819         }
5820
5821         spec->dmic_nids = stac92hd71bxx_dmic_nids;
5822         spec->dmux_nids = stac92hd71bxx_dmux_nids;
5823
5824         spec->num_caps = STAC92HD71BXX_NUM_CAPS;
5825         spec->capvols = stac92hd71bxx_capvols;
5826         spec->capsws = stac92hd71bxx_capsws;
5827
5828         switch (codec->vendor_id) {
5829         case 0x111d76b6: /* 4 Port without Analog Mixer */
5830         case 0x111d76b7:
5831                 unmute_init++;
5832                 /* fallthru */
5833         case 0x111d76b4: /* 6 Port without Analog Mixer */
5834         case 0x111d76b5:
5835                 spec->init = stac92hd71bxx_core_init;
5836                 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
5837                 spec->num_dmics = stac92xx_connected_ports(codec,
5838                                         stac92hd71bxx_dmic_nids,
5839                                         STAC92HD71BXX_NUM_DMICS);
5840                 break;
5841         case 0x111d7608: /* 5 Port with Analog Mixer */
5842                 switch (spec->board_config) {
5843                 case STAC_HP_M4:
5844                         /* Enable VREF power saving on GPIO1 detect */
5845                         err = stac_add_event(spec, codec->afg,
5846                                              STAC_VREF_EVENT, 0x02);
5847                         if (err < 0)
5848                                 return err;
5849                         snd_hda_codec_write_cache(codec, codec->afg, 0,
5850                                 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02);
5851                         snd_hda_codec_write_cache(codec, codec->afg, 0,
5852                                 AC_VERB_SET_UNSOLICITED_ENABLE,
5853                                 AC_USRSP_EN | err);
5854                         spec->gpio_mask |= 0x02;
5855                         break;
5856                 }
5857                 if ((codec->revision_id & 0xf) == 0 ||
5858                     (codec->revision_id & 0xf) == 1)
5859                         spec->stream_delay = 40; /* 40 milliseconds */
5860
5861                 /* disable VSW */
5862                 spec->init = stac92hd71bxx_core_init;
5863                 unmute_init++;
5864                 snd_hda_codec_set_pincfg(codec, 0x0f, 0x40f000f0);
5865                 snd_hda_codec_set_pincfg(codec, 0x19, 0x40f000f3);
5866                 spec->dmic_nids = stac92hd71bxx_dmic_5port_nids;
5867                 spec->num_dmics = stac92xx_connected_ports(codec,
5868                                         stac92hd71bxx_dmic_5port_nids,
5869                                         STAC92HD71BXX_NUM_DMICS - 1);
5870                 break;
5871         case 0x111d7603: /* 6 Port with Analog Mixer */
5872                 if ((codec->revision_id & 0xf) == 1)
5873                         spec->stream_delay = 40; /* 40 milliseconds */
5874
5875                 /* fallthru */
5876         default:
5877                 spec->init = stac92hd71bxx_core_init;
5878                 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
5879                 spec->num_dmics = stac92xx_connected_ports(codec,
5880                                         stac92hd71bxx_dmic_nids,
5881                                         STAC92HD71BXX_NUM_DMICS);
5882                 break;
5883         }
5884
5885         if (get_wcaps(codec, 0xa) & AC_WCAP_IN_AMP)
5886                 snd_hda_sequence_write_cache(codec, unmute_init);
5887
5888         spec->aloopback_ctl = stac92hd71bxx_loopback;
5889         spec->aloopback_mask = 0x50;
5890         spec->aloopback_shift = 0;
5891
5892         spec->powerdown_adcs = 1;
5893         spec->digbeep_nid = 0x26;
5894         spec->mux_nids = stac92hd71bxx_mux_nids;
5895         spec->adc_nids = stac92hd71bxx_adc_nids;
5896         spec->smux_nids = stac92hd71bxx_smux_nids;
5897         spec->pwr_nids = stac92hd71bxx_pwr_nids;
5898
5899         spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids);
5900         spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids);
5901         spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
5902         spec->num_smuxes = stac92hd71bxx_connected_smuxes(codec, 0x1e);
5903
5904         snd_printdd("Found board config: %d\n", spec->board_config);
5905
5906         switch (spec->board_config) {
5907         case STAC_HP_M4:
5908                 /* enable internal microphone */
5909                 snd_hda_codec_set_pincfg(codec, 0x0e, 0x01813040);
5910                 stac92xx_auto_set_pinctl(codec, 0x0e,
5911                         AC_PINCTL_IN_EN | AC_PINCTL_VREF_80);
5912                 /* fallthru */
5913         case STAC_DELL_M4_2:
5914                 spec->num_dmics = 0;
5915                 spec->num_smuxes = 0;
5916                 spec->num_dmuxes = 0;
5917                 break;
5918         case STAC_DELL_M4_1:
5919         case STAC_DELL_M4_3:
5920                 spec->num_dmics = 1;
5921                 spec->num_smuxes = 0;
5922                 spec->num_dmuxes = 1;
5923                 break;
5924         case STAC_HP_DV4_1222NR:
5925                 spec->num_dmics = 1;
5926                 /* I don't know if it needs 1 or 2 smuxes - will wait for
5927                  * bug reports to fix if needed
5928                  */
5929                 spec->num_smuxes = 1;
5930                 spec->num_dmuxes = 1;
5931                 /* fallthrough */
5932         case STAC_HP_DV4:
5933                 spec->gpio_led = 0x01;
5934                 /* fallthrough */
5935         case STAC_HP_DV5:
5936                 snd_hda_codec_set_pincfg(codec, 0x0d, 0x90170010);
5937                 stac92xx_auto_set_pinctl(codec, 0x0d, AC_PINCTL_OUT_EN);
5938                 /* HP dv6 gives the headphone pin as a line-out.  Thus we
5939                  * need to set hp_detect flag here to force to enable HP
5940                  * detection.
5941                  */
5942                 spec->hp_detect = 1;
5943                 break;
5944         case STAC_HP_HDX:
5945                 spec->num_dmics = 1;
5946                 spec->num_dmuxes = 1;
5947                 spec->num_smuxes = 1;
5948                 spec->gpio_led = 0x08;
5949                 break;
5950         }
5951
5952         if (hp_blike_system(codec->subsystem_id)) {
5953                 pin_cfg = snd_hda_codec_get_pincfg(codec, 0x0f);
5954                 if (get_defcfg_device(pin_cfg) == AC_JACK_LINE_OUT ||
5955                         get_defcfg_device(pin_cfg) == AC_JACK_SPEAKER  ||
5956                         get_defcfg_device(pin_cfg) == AC_JACK_HP_OUT) {
5957                         /* It was changed in the BIOS to just satisfy MS DTM.
5958                          * Lets turn it back into slaved HP
5959                          */
5960                         pin_cfg = (pin_cfg & (~AC_DEFCFG_DEVICE))
5961                                         | (AC_JACK_HP_OUT <<
5962                                                 AC_DEFCFG_DEVICE_SHIFT);
5963                         pin_cfg = (pin_cfg & (~(AC_DEFCFG_DEF_ASSOC
5964                                                         | AC_DEFCFG_SEQUENCE)))
5965                                                                 | 0x1f;
5966                         snd_hda_codec_set_pincfg(codec, 0x0f, pin_cfg);
5967                 }
5968         }
5969
5970         if (find_mute_led_gpio(codec, 1))
5971                 snd_printd("mute LED gpio %d polarity %d\n",
5972                                 spec->gpio_led,
5973                                 spec->gpio_led_polarity);
5974
5975 #ifdef CONFIG_SND_HDA_POWER_SAVE
5976         if (spec->gpio_led) {
5977                 if (spec->gpio_led <= 8) {
5978                         spec->gpio_mask |= spec->gpio_led;
5979                         spec->gpio_dir |= spec->gpio_led;
5980                         spec->gpio_data |= spec->gpio_led;
5981                 } else {
5982                         codec->patch_ops.set_power_state =
5983                                         stac92xx_set_power_state;
5984                         codec->patch_ops.post_suspend =
5985                                         stac92xx_post_suspend;
5986                 }
5987                 codec->patch_ops.pre_resume = stac92xx_pre_resume;
5988                 codec->patch_ops.check_power_status =
5989                         stac92xx_check_power_status;
5990         }
5991 #endif  
5992
5993         spec->multiout.dac_nids = spec->dac_nids;
5994
5995         err = stac92xx_parse_auto_config(codec);
5996         if (!err) {
5997                 if (spec->board_config < 0) {
5998                         printk(KERN_WARNING "hda_codec: No auto-config is "
5999                                "available, default to model=ref\n");
6000                         spec->board_config = STAC_92HD71BXX_REF;
6001                         goto again;
6002                 }
6003                 err = -EINVAL;
6004         }
6005
6006         if (err < 0) {
6007                 stac92xx_free(codec);
6008                 return err;
6009         }
6010
6011         /* enable bass on HP dv7 */
6012         if (spec->board_config == STAC_HP_DV4 ||
6013             spec->board_config == STAC_HP_DV5) {
6014                 unsigned int cap;
6015                 cap = snd_hda_param_read(codec, 0x1, AC_PAR_GPIO_CAP);
6016                 cap &= AC_GPIO_IO_COUNT;
6017                 if (cap >= 6)
6018                         stac_add_hp_bass_switch(codec);
6019         }
6020
6021         codec->proc_widget_hook = stac92hd7x_proc_hook;
6022
6023         return 0;
6024 }
6025
6026 static int patch_stac922x(struct hda_codec *codec)
6027 {
6028         struct sigmatel_spec *spec;
6029         int err;
6030
6031         spec  = kzalloc(sizeof(*spec), GFP_KERNEL);
6032         if (spec == NULL)
6033                 return -ENOMEM;
6034
6035         codec->no_trigger_sense = 1;
6036         codec->spec = spec;
6037         spec->linear_tone_beep = 1;
6038         spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
6039         spec->pin_nids = stac922x_pin_nids;
6040         spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
6041                                                         stac922x_models,
6042                                                         stac922x_cfg_tbl);
6043         if (spec->board_config == STAC_INTEL_MAC_AUTO) {
6044                 spec->gpio_mask = spec->gpio_dir = 0x03;
6045                 spec->gpio_data = 0x03;
6046                 /* Intel Macs have all same PCI SSID, so we need to check
6047                  * codec SSID to distinguish the exact models
6048                  */
6049                 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
6050                 switch (codec->subsystem_id) {
6051
6052                 case 0x106b0800:
6053                         spec->board_config = STAC_INTEL_MAC_V1;
6054                         break;
6055                 case 0x106b0600:
6056                 case 0x106b0700:
6057                         spec->board_config = STAC_INTEL_MAC_V2;
6058                         break;
6059                 case 0x106b0e00:
6060                 case 0x106b0f00:
6061                 case 0x106b1600:
6062                 case 0x106b1700:
6063                 case 0x106b0200:
6064                 case 0x106b1e00:
6065                         spec->board_config = STAC_INTEL_MAC_V3;
6066                         break;
6067                 case 0x106b1a00:
6068                 case 0x00000100:
6069                         spec->board_config = STAC_INTEL_MAC_V4;
6070                         break;
6071                 case 0x106b0a00:
6072                 case 0x106b2200:
6073                         spec->board_config = STAC_INTEL_MAC_V5;
6074                         break;
6075                 default:
6076                         spec->board_config = STAC_INTEL_MAC_V3;
6077                         break;
6078                 }
6079         }
6080
6081  again:
6082         if (spec->board_config < 0)
6083                 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6084                             codec->chip_name);
6085         else
6086                 stac92xx_set_config_regs(codec,
6087                                 stac922x_brd_tbl[spec->board_config]);
6088
6089         spec->adc_nids = stac922x_adc_nids;
6090         spec->mux_nids = stac922x_mux_nids;
6091         spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
6092         spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
6093         spec->num_dmics = 0;
6094         spec->num_pwrs = 0;
6095
6096         spec->init = stac922x_core_init;
6097
6098         spec->num_caps = STAC922X_NUM_CAPS;
6099         spec->capvols = stac922x_capvols;
6100         spec->capsws = stac922x_capsws;
6101
6102         spec->multiout.dac_nids = spec->dac_nids;
6103         
6104         err = stac92xx_parse_auto_config(codec);
6105         if (!err) {
6106                 if (spec->board_config < 0) {
6107                         printk(KERN_WARNING "hda_codec: No auto-config is "
6108                                "available, default to model=ref\n");
6109                         spec->board_config = STAC_D945_REF;
6110                         goto again;
6111                 }
6112                 err = -EINVAL;
6113         }
6114         if (err < 0) {
6115                 stac92xx_free(codec);
6116                 return err;
6117         }
6118
6119         codec->patch_ops = stac92xx_patch_ops;
6120
6121         /* Fix Mux capture level; max to 2 */
6122         snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
6123                                   (0 << AC_AMPCAP_OFFSET_SHIFT) |
6124                                   (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
6125                                   (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6126                                   (0 << AC_AMPCAP_MUTE_SHIFT));
6127
6128         return 0;
6129 }
6130
6131 static int patch_stac927x(struct hda_codec *codec)
6132 {
6133         struct sigmatel_spec *spec;
6134         int err;
6135
6136         spec  = kzalloc(sizeof(*spec), GFP_KERNEL);
6137         if (spec == NULL)
6138                 return -ENOMEM;
6139
6140         codec->no_trigger_sense = 1;
6141         codec->spec = spec;
6142         spec->linear_tone_beep = 1;
6143         codec->slave_dig_outs = stac927x_slave_dig_outs;
6144         spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
6145         spec->pin_nids = stac927x_pin_nids;
6146         spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
6147                                                         stac927x_models,
6148                                                         stac927x_cfg_tbl);
6149  again:
6150         if (spec->board_config < 0)
6151                 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6152                             codec->chip_name);
6153         else
6154                 stac92xx_set_config_regs(codec,
6155                                 stac927x_brd_tbl[spec->board_config]);
6156
6157         spec->digbeep_nid = 0x23;
6158         spec->adc_nids = stac927x_adc_nids;
6159         spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
6160         spec->mux_nids = stac927x_mux_nids;
6161         spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
6162         spec->smux_nids = stac927x_smux_nids;
6163         spec->num_smuxes = ARRAY_SIZE(stac927x_smux_nids);
6164         spec->spdif_labels = stac927x_spdif_labels;
6165         spec->dac_list = stac927x_dac_nids;
6166         spec->multiout.dac_nids = spec->dac_nids;
6167
6168         if (spec->board_config != STAC_D965_REF) {
6169                 /* GPIO0 High = Enable EAPD */
6170                 spec->eapd_mask = spec->gpio_mask = 0x01;
6171                 spec->gpio_dir = spec->gpio_data = 0x01;
6172         }
6173
6174         switch (spec->board_config) {
6175         case STAC_D965_3ST:
6176         case STAC_D965_5ST:
6177                 /* GPIO0 High = Enable EAPD */
6178                 spec->num_dmics = 0;
6179                 spec->init = d965_core_init;
6180                 break;
6181         case STAC_DELL_BIOS:
6182                 switch (codec->subsystem_id) {
6183                 case 0x10280209:
6184                 case 0x1028022e:
6185                         /* correct the device field to SPDIF out */
6186                         snd_hda_codec_set_pincfg(codec, 0x21, 0x01442070);
6187                         break;
6188                 }
6189                 /* configure the analog microphone on some laptops */
6190                 snd_hda_codec_set_pincfg(codec, 0x0c, 0x90a79130);
6191                 /* correct the front output jack as a hp out */
6192                 snd_hda_codec_set_pincfg(codec, 0x0f, 0x0227011f);
6193                 /* correct the front input jack as a mic */
6194                 snd_hda_codec_set_pincfg(codec, 0x0e, 0x02a79130);
6195                 /* fallthru */
6196         case STAC_DELL_3ST:
6197                 if (codec->subsystem_id != 0x1028022f) {
6198                         /* GPIO2 High = Enable EAPD */
6199                         spec->eapd_mask = spec->gpio_mask = 0x04;
6200                         spec->gpio_dir = spec->gpio_data = 0x04;
6201                 }
6202                 spec->dmic_nids = stac927x_dmic_nids;
6203                 spec->num_dmics = STAC927X_NUM_DMICS;
6204
6205                 spec->init = dell_3st_core_init;
6206                 spec->dmux_nids = stac927x_dmux_nids;
6207                 spec->num_dmuxes = ARRAY_SIZE(stac927x_dmux_nids);
6208                 break;
6209         case STAC_927X_VOLKNOB:
6210                 spec->num_dmics = 0;
6211                 spec->init = stac927x_volknob_core_init;
6212                 break;
6213         default:
6214                 spec->num_dmics = 0;
6215                 spec->init = stac927x_core_init;
6216                 break;
6217         }
6218
6219         spec->num_caps = STAC927X_NUM_CAPS;
6220         spec->capvols = stac927x_capvols;
6221         spec->capsws = stac927x_capsws;
6222
6223         spec->num_pwrs = 0;
6224         spec->aloopback_ctl = stac927x_loopback;
6225         spec->aloopback_mask = 0x40;
6226         spec->aloopback_shift = 0;
6227         spec->eapd_switch = 1;
6228
6229         err = stac92xx_parse_auto_config(codec);
6230         if (!err) {
6231                 if (spec->board_config < 0) {
6232                         printk(KERN_WARNING "hda_codec: No auto-config is "
6233                                "available, default to model=ref\n");
6234                         spec->board_config = STAC_D965_REF;
6235                         goto again;
6236                 }
6237                 err = -EINVAL;
6238         }
6239         if (err < 0) {
6240                 stac92xx_free(codec);
6241                 return err;
6242         }
6243
6244         codec->patch_ops = stac92xx_patch_ops;
6245
6246         codec->proc_widget_hook = stac927x_proc_hook;
6247
6248         /*
6249          * !!FIXME!!
6250          * The STAC927x seem to require fairly long delays for certain
6251          * command sequences.  With too short delays (even if the answer
6252          * is set to RIRB properly), it results in the silence output
6253          * on some hardwares like Dell.
6254          *
6255          * The below flag enables the longer delay (see get_response
6256          * in hda_intel.c).
6257          */
6258         codec->bus->needs_damn_long_delay = 1;
6259
6260         /* no jack detecion for ref-no-jd model */
6261         if (spec->board_config == STAC_D965_REF_NO_JD)
6262                 spec->hp_detect = 0;
6263
6264         return 0;
6265 }
6266
6267 static int patch_stac9205(struct hda_codec *codec)
6268 {
6269         struct sigmatel_spec *spec;
6270         int err;
6271
6272         spec  = kzalloc(sizeof(*spec), GFP_KERNEL);
6273         if (spec == NULL)
6274                 return -ENOMEM;
6275
6276         codec->no_trigger_sense = 1;
6277         codec->spec = spec;
6278         spec->linear_tone_beep = 1;
6279         spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
6280         spec->pin_nids = stac9205_pin_nids;
6281         spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
6282                                                         stac9205_models,
6283                                                         stac9205_cfg_tbl);
6284  again:
6285         if (spec->board_config < 0)
6286                 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6287                             codec->chip_name);
6288         else
6289                 stac92xx_set_config_regs(codec,
6290                                          stac9205_brd_tbl[spec->board_config]);
6291
6292         spec->digbeep_nid = 0x23;
6293         spec->adc_nids = stac9205_adc_nids;
6294         spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
6295         spec->mux_nids = stac9205_mux_nids;
6296         spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
6297         spec->smux_nids = stac9205_smux_nids;
6298         spec->num_smuxes = ARRAY_SIZE(stac9205_smux_nids);
6299         spec->dmic_nids = stac9205_dmic_nids;
6300         spec->num_dmics = STAC9205_NUM_DMICS;
6301         spec->dmux_nids = stac9205_dmux_nids;
6302         spec->num_dmuxes = ARRAY_SIZE(stac9205_dmux_nids);
6303         spec->num_pwrs = 0;
6304
6305         spec->init = stac9205_core_init;
6306         spec->aloopback_ctl = stac9205_loopback;
6307
6308         spec->num_caps = STAC9205_NUM_CAPS;
6309         spec->capvols = stac9205_capvols;
6310         spec->capsws = stac9205_capsws;
6311
6312         spec->aloopback_mask = 0x40;
6313         spec->aloopback_shift = 0;
6314         /* Turn on/off EAPD per HP plugging */
6315         if (spec->board_config != STAC_9205_EAPD)
6316                 spec->eapd_switch = 1;
6317         spec->multiout.dac_nids = spec->dac_nids;
6318         
6319         switch (spec->board_config){
6320         case STAC_9205_DELL_M43:
6321                 /* Enable SPDIF in/out */
6322                 snd_hda_codec_set_pincfg(codec, 0x1f, 0x01441030);
6323                 snd_hda_codec_set_pincfg(codec, 0x20, 0x1c410030);
6324
6325                 /* Enable unsol response for GPIO4/Dock HP connection */
6326                 err = stac_add_event(spec, codec->afg, STAC_VREF_EVENT, 0x01);
6327                 if (err < 0)
6328                         return err;
6329                 snd_hda_codec_write_cache(codec, codec->afg, 0,
6330                         AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10);
6331                 snd_hda_codec_write_cache(codec, codec->afg, 0,
6332                                           AC_VERB_SET_UNSOLICITED_ENABLE,
6333                                           AC_USRSP_EN | err);
6334
6335                 spec->gpio_dir = 0x0b;
6336                 spec->eapd_mask = 0x01;
6337                 spec->gpio_mask = 0x1b;
6338                 spec->gpio_mute = 0x10;
6339                 /* GPIO0 High = EAPD, GPIO1 Low = Headphone Mute,
6340                  * GPIO3 Low = DRM
6341                  */
6342                 spec->gpio_data = 0x01;
6343                 break;
6344         case STAC_9205_REF:
6345                 /* SPDIF-In enabled */
6346                 break;
6347         default:
6348                 /* GPIO0 High = EAPD */
6349                 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
6350                 spec->gpio_data = 0x01;
6351                 break;
6352         }
6353
6354         err = stac92xx_parse_auto_config(codec);
6355         if (!err) {
6356                 if (spec->board_config < 0) {
6357                         printk(KERN_WARNING "hda_codec: No auto-config is "
6358                                "available, default to model=ref\n");
6359                         spec->board_config = STAC_9205_REF;
6360                         goto again;
6361                 }
6362                 err = -EINVAL;
6363         }
6364         if (err < 0) {
6365                 stac92xx_free(codec);
6366                 return err;
6367         }
6368
6369         codec->patch_ops = stac92xx_patch_ops;
6370
6371         codec->proc_widget_hook = stac9205_proc_hook;
6372
6373         return 0;
6374 }
6375
6376 /*
6377  * STAC9872 hack
6378  */
6379
6380 static const struct hda_verb stac9872_core_init[] = {
6381         {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
6382         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
6383         {}
6384 };
6385
6386 static const hda_nid_t stac9872_pin_nids[] = {
6387         0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
6388         0x11, 0x13, 0x14,
6389 };
6390
6391 static const hda_nid_t stac9872_adc_nids[] = {
6392         0x8 /*,0x6*/
6393 };
6394
6395 static const hda_nid_t stac9872_mux_nids[] = {
6396         0x15
6397 };
6398
6399 static const unsigned long stac9872_capvols[] = {
6400         HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
6401 };
6402 #define stac9872_capsws         stac9872_capvols
6403
6404 static const unsigned int stac9872_vaio_pin_configs[9] = {
6405         0x03211020, 0x411111f0, 0x411111f0, 0x03a15030,
6406         0x411111f0, 0x90170110, 0x411111f0, 0x411111f0,
6407         0x90a7013e
6408 };
6409
6410 static const char * const stac9872_models[STAC_9872_MODELS] = {
6411         [STAC_9872_AUTO] = "auto",
6412         [STAC_9872_VAIO] = "vaio",
6413 };
6414
6415 static const unsigned int *stac9872_brd_tbl[STAC_9872_MODELS] = {
6416         [STAC_9872_VAIO] = stac9872_vaio_pin_configs,
6417 };
6418
6419 static const struct snd_pci_quirk stac9872_cfg_tbl[] = {
6420         SND_PCI_QUIRK_MASK(0x104d, 0xfff0, 0x81e0,
6421                            "Sony VAIO F/S", STAC_9872_VAIO),
6422         {} /* terminator */
6423 };
6424
6425 static int patch_stac9872(struct hda_codec *codec)
6426 {
6427         struct sigmatel_spec *spec;
6428         int err;
6429
6430         spec  = kzalloc(sizeof(*spec), GFP_KERNEL);
6431         if (spec == NULL)
6432                 return -ENOMEM;
6433         codec->no_trigger_sense = 1;
6434         codec->spec = spec;
6435         spec->linear_tone_beep = 1;
6436         spec->num_pins = ARRAY_SIZE(stac9872_pin_nids);
6437         spec->pin_nids = stac9872_pin_nids;
6438
6439         spec->board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
6440                                                         stac9872_models,
6441                                                         stac9872_cfg_tbl);
6442         if (spec->board_config < 0)
6443                 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6444                             codec->chip_name);
6445         else
6446                 stac92xx_set_config_regs(codec,
6447                                          stac9872_brd_tbl[spec->board_config]);
6448
6449         spec->multiout.dac_nids = spec->dac_nids;
6450         spec->num_adcs = ARRAY_SIZE(stac9872_adc_nids);
6451         spec->adc_nids = stac9872_adc_nids;
6452         spec->num_muxes = ARRAY_SIZE(stac9872_mux_nids);
6453         spec->mux_nids = stac9872_mux_nids;
6454         spec->init = stac9872_core_init;
6455         spec->num_caps = 1;
6456         spec->capvols = stac9872_capvols;
6457         spec->capsws = stac9872_capsws;
6458
6459         err = stac92xx_parse_auto_config(codec);
6460         if (err < 0) {
6461                 stac92xx_free(codec);
6462                 return -EINVAL;
6463         }
6464         spec->input_mux = &spec->private_imux;
6465         codec->patch_ops = stac92xx_patch_ops;
6466         return 0;
6467 }
6468
6469
6470 /*
6471  * patch entries
6472  */
6473 static const struct hda_codec_preset snd_hda_preset_sigmatel[] = {
6474         { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
6475         { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
6476         { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
6477         { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
6478         { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
6479         { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
6480         { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
6481         { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
6482         { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
6483         { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
6484         { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
6485         { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
6486         { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
6487         { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
6488         { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
6489         { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
6490         { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
6491         { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
6492         { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
6493         { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
6494         { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
6495         { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
6496         { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
6497         { .id = 0x83847632, .name = "STAC9202",  .patch = patch_stac925x },
6498         { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
6499         { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
6500         { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
6501         { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
6502         { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
6503         { .id = 0x83847645, .name = "92HD206X", .patch = patch_stac927x },
6504         { .id = 0x83847646, .name = "92HD206D", .patch = patch_stac927x },
6505         /* The following does not take into account .id=0x83847661 when subsys =
6506          * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
6507          * currently not fully supported.
6508          */
6509         { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
6510         { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
6511         { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
6512         { .id = 0x83847698, .name = "STAC9205", .patch = patch_stac9205 },
6513         { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
6514         { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
6515         { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
6516         { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
6517         { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
6518         { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
6519         { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
6520         { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
6521         { .id = 0x111d7603, .name = "92HD75B3X5", .patch = patch_stac92hd71bxx},
6522         { .id = 0x111d7604, .name = "92HD83C1X5", .patch = patch_stac92hd83xxx},
6523         { .id = 0x111d76d4, .name = "92HD83C1C5", .patch = patch_stac92hd83xxx},
6524         { .id = 0x111d7605, .name = "92HD81B1X5", .patch = patch_stac92hd83xxx},
6525         { .id = 0x111d76d5, .name = "92HD81B1C5", .patch = patch_stac92hd83xxx},
6526         { .id = 0x111d76d1, .name = "92HD87B1/3", .patch = patch_stac92hd83xxx},
6527         { .id = 0x111d76d9, .name = "92HD87B2/4", .patch = patch_stac92hd83xxx},
6528         { .id = 0x111d7666, .name = "92HD88B3", .patch = patch_stac92hd83xxx},
6529         { .id = 0x111d7667, .name = "92HD88B1", .patch = patch_stac92hd83xxx},
6530         { .id = 0x111d7668, .name = "92HD88B2", .patch = patch_stac92hd83xxx},
6531         { .id = 0x111d7669, .name = "92HD88B4", .patch = patch_stac92hd83xxx},
6532         { .id = 0x111d7608, .name = "92HD75B2X5", .patch = patch_stac92hd71bxx},
6533         { .id = 0x111d7674, .name = "92HD73D1X5", .patch = patch_stac92hd73xx },
6534         { .id = 0x111d7675, .name = "92HD73C1X5", .patch = patch_stac92hd73xx },
6535         { .id = 0x111d7676, .name = "92HD73E1X5", .patch = patch_stac92hd73xx },
6536         { .id = 0x111d76b0, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
6537         { .id = 0x111d76b1, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
6538         { .id = 0x111d76b2, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
6539         { .id = 0x111d76b3, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
6540         { .id = 0x111d76b4, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
6541         { .id = 0x111d76b5, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
6542         { .id = 0x111d76b6, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
6543         { .id = 0x111d76b7, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
6544         { .id = 0x111d76c0, .name = "92HD89C3", .patch = patch_stac92hd73xx },
6545         { .id = 0x111d76c1, .name = "92HD89C2", .patch = patch_stac92hd73xx },
6546         { .id = 0x111d76c2, .name = "92HD89C1", .patch = patch_stac92hd73xx },
6547         { .id = 0x111d76c3, .name = "92HD89B3", .patch = patch_stac92hd73xx },
6548         { .id = 0x111d76c4, .name = "92HD89B2", .patch = patch_stac92hd73xx },
6549         { .id = 0x111d76c5, .name = "92HD89B1", .patch = patch_stac92hd73xx },
6550         { .id = 0x111d76c6, .name = "92HD89E3", .patch = patch_stac92hd73xx },
6551         { .id = 0x111d76c7, .name = "92HD89E2", .patch = patch_stac92hd73xx },
6552         { .id = 0x111d76c8, .name = "92HD89E1", .patch = patch_stac92hd73xx },
6553         { .id = 0x111d76c9, .name = "92HD89D3", .patch = patch_stac92hd73xx },
6554         { .id = 0x111d76ca, .name = "92HD89D2", .patch = patch_stac92hd73xx },
6555         { .id = 0x111d76cb, .name = "92HD89D1", .patch = patch_stac92hd73xx },
6556         { .id = 0x111d76cc, .name = "92HD89F3", .patch = patch_stac92hd73xx },
6557         { .id = 0x111d76cd, .name = "92HD89F2", .patch = patch_stac92hd73xx },
6558         { .id = 0x111d76ce, .name = "92HD89F1", .patch = patch_stac92hd73xx },
6559         { .id = 0x111d76df, .name = "92HD93BXX", .patch = patch_stac92hd83xxx},
6560         { .id = 0x111d76e0, .name = "92HD91BXX", .patch = patch_stac92hd83xxx},
6561         { .id = 0x111d76e3, .name = "92HD98BXX", .patch = patch_stac92hd83xxx},
6562         { .id = 0x111d76e5, .name = "92HD99BXX", .patch = patch_stac92hd83xxx},
6563         { .id = 0x111d76e7, .name = "92HD90BXX", .patch = patch_stac92hd83xxx},
6564         { .id = 0x111d76e8, .name = "92HD66B1X5", .patch = patch_stac92hd83xxx},
6565         { .id = 0x111d76e9, .name = "92HD66B2X5", .patch = patch_stac92hd83xxx},
6566         { .id = 0x111d76ea, .name = "92HD66B3X5", .patch = patch_stac92hd83xxx},
6567         { .id = 0x111d76eb, .name = "92HD66C1X5", .patch = patch_stac92hd83xxx},
6568         { .id = 0x111d76ec, .name = "92HD66C2X5", .patch = patch_stac92hd83xxx},
6569         { .id = 0x111d76ed, .name = "92HD66C3X5", .patch = patch_stac92hd83xxx},
6570         { .id = 0x111d76ee, .name = "92HD66B1X3", .patch = patch_stac92hd83xxx},
6571         { .id = 0x111d76ef, .name = "92HD66B2X3", .patch = patch_stac92hd83xxx},
6572         { .id = 0x111d76f0, .name = "92HD66B3X3", .patch = patch_stac92hd83xxx},
6573         { .id = 0x111d76f1, .name = "92HD66C1X3", .patch = patch_stac92hd83xxx},
6574         { .id = 0x111d76f2, .name = "92HD66C2X3", .patch = patch_stac92hd83xxx},
6575         { .id = 0x111d76f3, .name = "92HD66C3/65", .patch = patch_stac92hd83xxx},
6576         {} /* terminator */
6577 };
6578
6579 MODULE_ALIAS("snd-hda-codec-id:8384*");
6580 MODULE_ALIAS("snd-hda-codec-id:111d*");
6581
6582 MODULE_LICENSE("GPL");
6583 MODULE_DESCRIPTION("IDT/Sigmatel HD-audio codec");
6584
6585 static struct hda_codec_preset_list sigmatel_list = {
6586         .preset = snd_hda_preset_sigmatel,
6587         .owner = THIS_MODULE,
6588 };
6589
6590 static int __init patch_sigmatel_init(void)
6591 {
6592         return snd_hda_add_codec_preset(&sigmatel_list);
6593 }
6594
6595 static void __exit patch_sigmatel_exit(void)
6596 {
6597         snd_hda_delete_codec_preset(&sigmatel_list);
6598 }
6599
6600 module_init(patch_sigmatel_init)
6601 module_exit(patch_sigmatel_exit)