]> git.openfabrics.org - ~shefty/rdma-dev.git/blob - sound/pci/hda/patch_sigmatel.c
4cce92cf8eadf1a6a1873939df31e2140beead16
[~shefty/rdma-dev.git] / sound / pci / hda / patch_sigmatel.c
1 /*
2  * Universal Interface for Intel High Definition Audio Codec
3  *
4  * HD audio interface patch for SigmaTel STAC92xx
5  *
6  * Copyright (c) 2005 Embedded Alley Solutions, Inc.
7  * Matt Porter <mporter@embeddedalley.com>
8  *
9  * Based on patch_cmedia.c and patch_realtek.c
10  * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
11  *
12  *  This driver is free software; you can redistribute it and/or modify
13  *  it under the terms of the GNU General Public License as published by
14  *  the Free Software Foundation; either version 2 of the License, or
15  *  (at your option) any later version.
16  *
17  *  This driver is distributed in the hope that it will be useful,
18  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  *  GNU General Public License for more details.
21  *
22  *  You should have received a copy of the GNU General Public License
23  *  along with this program; if not, write to the Free Software
24  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
25  */
26
27 #include <linux/init.h>
28 #include <linux/delay.h>
29 #include <linux/slab.h>
30 #include <linux/pci.h>
31 #include <sound/core.h>
32 #include <sound/asoundef.h>
33 #include <sound/jack.h>
34 #include "hda_codec.h"
35 #include "hda_local.h"
36 #include "hda_beep.h"
37
38 enum {
39         STAC_VREF_EVENT = 1,
40         STAC_INSERT_EVENT,
41         STAC_PWR_EVENT,
42         STAC_HP_EVENT,
43         STAC_LO_EVENT,
44         STAC_MIC_EVENT,
45 };
46
47 enum {
48         STAC_AUTO,
49         STAC_REF,
50         STAC_9200_OQO,
51         STAC_9200_DELL_D21,
52         STAC_9200_DELL_D22,
53         STAC_9200_DELL_D23,
54         STAC_9200_DELL_M21,
55         STAC_9200_DELL_M22,
56         STAC_9200_DELL_M23,
57         STAC_9200_DELL_M24,
58         STAC_9200_DELL_M25,
59         STAC_9200_DELL_M26,
60         STAC_9200_DELL_M27,
61         STAC_9200_M4,
62         STAC_9200_M4_2,
63         STAC_9200_PANASONIC,
64         STAC_9200_MODELS
65 };
66
67 enum {
68         STAC_9205_AUTO,
69         STAC_9205_REF,
70         STAC_9205_DELL_M42,
71         STAC_9205_DELL_M43,
72         STAC_9205_DELL_M44,
73         STAC_9205_EAPD,
74         STAC_9205_MODELS
75 };
76
77 enum {
78         STAC_92HD73XX_AUTO,
79         STAC_92HD73XX_NO_JD, /* no jack-detection */
80         STAC_92HD73XX_REF,
81         STAC_92HD73XX_INTEL,
82         STAC_DELL_M6_AMIC,
83         STAC_DELL_M6_DMIC,
84         STAC_DELL_M6_BOTH,
85         STAC_DELL_EQ,
86         STAC_92HD73XX_MODELS
87 };
88
89 enum {
90         STAC_92HD83XXX_AUTO,
91         STAC_92HD83XXX_REF,
92         STAC_92HD83XXX_PWR_REF,
93         STAC_DELL_S14,
94         STAC_92HD83XXX_MODELS
95 };
96
97 enum {
98         STAC_92HD71BXX_AUTO,
99         STAC_92HD71BXX_REF,
100         STAC_DELL_M4_1,
101         STAC_DELL_M4_2,
102         STAC_DELL_M4_3,
103         STAC_HP_M4,
104         STAC_HP_DV5,
105         STAC_HP_HDX,
106         STAC_HP_DV4_1222NR,
107         STAC_92HD71BXX_MODELS
108 };
109
110 enum {
111         STAC_925x_AUTO,
112         STAC_925x_REF,
113         STAC_M1,
114         STAC_M1_2,
115         STAC_M2,
116         STAC_M2_2,
117         STAC_M3,
118         STAC_M5,
119         STAC_M6,
120         STAC_925x_MODELS
121 };
122
123 enum {
124         STAC_922X_AUTO,
125         STAC_D945_REF,
126         STAC_D945GTP3,
127         STAC_D945GTP5,
128         STAC_INTEL_MAC_V1,
129         STAC_INTEL_MAC_V2,
130         STAC_INTEL_MAC_V3,
131         STAC_INTEL_MAC_V4,
132         STAC_INTEL_MAC_V5,
133         STAC_INTEL_MAC_AUTO, /* This model is selected if no module parameter
134                               * is given, one of the above models will be
135                               * chosen according to the subsystem id. */
136         /* for backward compatibility */
137         STAC_MACMINI,
138         STAC_MACBOOK,
139         STAC_MACBOOK_PRO_V1,
140         STAC_MACBOOK_PRO_V2,
141         STAC_IMAC_INTEL,
142         STAC_IMAC_INTEL_20,
143         STAC_ECS_202,
144         STAC_922X_DELL_D81,
145         STAC_922X_DELL_D82,
146         STAC_922X_DELL_M81,
147         STAC_922X_DELL_M82,
148         STAC_922X_MODELS
149 };
150
151 enum {
152         STAC_927X_AUTO,
153         STAC_D965_REF_NO_JD, /* no jack-detection */
154         STAC_D965_REF,
155         STAC_D965_3ST,
156         STAC_D965_5ST,
157         STAC_D965_5ST_NO_FP,
158         STAC_DELL_3ST,
159         STAC_DELL_BIOS,
160         STAC_927X_MODELS
161 };
162
163 enum {
164         STAC_9872_AUTO,
165         STAC_9872_VAIO,
166         STAC_9872_MODELS
167 };
168
169 struct sigmatel_event {
170         hda_nid_t nid;
171         unsigned char type;
172         unsigned char tag;
173         int data;
174 };
175
176 struct sigmatel_jack {
177         hda_nid_t nid;
178         int type;
179         struct snd_jack *jack;
180 };
181
182 struct sigmatel_mic_route {
183         hda_nid_t pin;
184         unsigned char mux_idx;
185         unsigned char dmux_idx;
186 };
187
188 struct sigmatel_spec {
189         struct snd_kcontrol_new *mixers[4];
190         unsigned int num_mixers;
191
192         int board_config;
193         unsigned int eapd_switch: 1;
194         unsigned int surr_switch: 1;
195         unsigned int alt_switch: 1;
196         unsigned int hp_detect: 1;
197         unsigned int spdif_mute: 1;
198         unsigned int check_volume_offset:1;
199         unsigned int auto_mic:1;
200
201         /* gpio lines */
202         unsigned int eapd_mask;
203         unsigned int gpio_mask;
204         unsigned int gpio_dir;
205         unsigned int gpio_data;
206         unsigned int gpio_mute;
207         unsigned int gpio_led;
208
209         /* stream */
210         unsigned int stream_delay;
211
212         /* analog loopback */
213         struct snd_kcontrol_new *aloopback_ctl;
214         unsigned char aloopback_mask;
215         unsigned char aloopback_shift;
216
217         /* power management */
218         unsigned int num_pwrs;
219         unsigned int *pwr_mapping;
220         hda_nid_t *pwr_nids;
221         hda_nid_t *dac_list;
222
223         /* jack detection */
224         struct snd_array jacks;
225
226         /* events */
227         struct snd_array events;
228
229         /* playback */
230         struct hda_input_mux *mono_mux;
231         struct hda_input_mux *amp_mux;
232         unsigned int cur_mmux;
233         struct hda_multi_out multiout;
234         hda_nid_t dac_nids[5];
235         hda_nid_t hp_dacs[5];
236         hda_nid_t speaker_dacs[5];
237
238         int volume_offset;
239
240         /* capture */
241         hda_nid_t *adc_nids;
242         unsigned int num_adcs;
243         hda_nid_t *mux_nids;
244         unsigned int num_muxes;
245         hda_nid_t *dmic_nids;
246         unsigned int num_dmics;
247         hda_nid_t *dmux_nids;
248         unsigned int num_dmuxes;
249         hda_nid_t *smux_nids;
250         unsigned int num_smuxes;
251         unsigned int num_analog_muxes;
252
253         unsigned long *capvols; /* amp-volume attr: HDA_COMPOSE_AMP_VAL() */
254         unsigned long *capsws; /* amp-mute attr: HDA_COMPOSE_AMP_VAL() */
255         unsigned int num_caps; /* number of capture volume/switch elements */
256
257         struct sigmatel_mic_route ext_mic;
258         struct sigmatel_mic_route int_mic;
259
260         const char **spdif_labels;
261
262         hda_nid_t dig_in_nid;
263         hda_nid_t mono_nid;
264         hda_nid_t anabeep_nid;
265         hda_nid_t digbeep_nid;
266
267         /* pin widgets */
268         hda_nid_t *pin_nids;
269         unsigned int num_pins;
270
271         /* codec specific stuff */
272         struct hda_verb *init;
273         struct snd_kcontrol_new *mixer;
274
275         /* capture source */
276         struct hda_input_mux *dinput_mux;
277         unsigned int cur_dmux[2];
278         struct hda_input_mux *input_mux;
279         unsigned int cur_mux[3];
280         struct hda_input_mux *sinput_mux;
281         unsigned int cur_smux[2];
282         unsigned int cur_amux;
283         hda_nid_t *amp_nids;
284         unsigned int num_amps;
285         unsigned int powerdown_adcs;
286
287         /* i/o switches */
288         unsigned int io_switch[2];
289         unsigned int clfe_swap;
290         hda_nid_t line_switch;  /* shared line-in for input and output */
291         hda_nid_t mic_switch;   /* shared mic-in for input and output */
292         hda_nid_t hp_switch; /* NID of HP as line-out */
293         unsigned int aloopback;
294
295         struct hda_pcm pcm_rec[2];      /* PCM information */
296
297         /* dynamic controls and input_mux */
298         struct auto_pin_cfg autocfg;
299         struct snd_array kctls;
300         struct hda_input_mux private_dimux;
301         struct hda_input_mux private_imux;
302         struct hda_input_mux private_smux;
303         struct hda_input_mux private_amp_mux;
304         struct hda_input_mux private_mono_mux;
305 };
306
307 static hda_nid_t stac9200_adc_nids[1] = {
308         0x03,
309 };
310
311 static hda_nid_t stac9200_mux_nids[1] = {
312         0x0c,
313 };
314
315 static hda_nid_t stac9200_dac_nids[1] = {
316         0x02,
317 };
318
319 static hda_nid_t stac92hd73xx_pwr_nids[8] = {
320         0x0a, 0x0b, 0x0c, 0xd, 0x0e,
321         0x0f, 0x10, 0x11
322 };
323
324 static hda_nid_t stac92hd73xx_slave_dig_outs[2] = {
325         0x26, 0,
326 };
327
328 static hda_nid_t stac92hd73xx_adc_nids[2] = {
329         0x1a, 0x1b
330 };
331
332 #define STAC92HD73XX_NUM_DMICS  2
333 static hda_nid_t stac92hd73xx_dmic_nids[STAC92HD73XX_NUM_DMICS + 1] = {
334         0x13, 0x14, 0
335 };
336
337 #define STAC92HD73_DAC_COUNT 5
338
339 static hda_nid_t stac92hd73xx_mux_nids[2] = {
340         0x20, 0x21,
341 };
342
343 static hda_nid_t stac92hd73xx_dmux_nids[2] = {
344         0x20, 0x21,
345 };
346
347 static hda_nid_t stac92hd73xx_smux_nids[2] = {
348         0x22, 0x23,
349 };
350
351 #define STAC92HD73XX_NUM_CAPS   2
352 static unsigned long stac92hd73xx_capvols[] = {
353         HDA_COMPOSE_AMP_VAL(0x20, 3, 0, HDA_OUTPUT),
354         HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
355 };
356 #define stac92hd73xx_capsws     stac92hd73xx_capvols
357
358 #define STAC92HD83_DAC_COUNT 3
359
360 static hda_nid_t stac92hd83xxx_mux_nids[2] = {
361         0x17, 0x18,
362 };
363
364 static hda_nid_t stac92hd83xxx_adc_nids[2] = {
365         0x15, 0x16,
366 };
367
368 static hda_nid_t stac92hd83xxx_pwr_nids[4] = {
369         0xa, 0xb, 0xd, 0xe,
370 };
371
372 static hda_nid_t stac92hd83xxx_slave_dig_outs[2] = {
373         0x1e, 0,
374 };
375
376 static unsigned int stac92hd83xxx_pwr_mapping[4] = {
377         0x03, 0x0c, 0x20, 0x40,
378 };
379
380 #define STAC92HD83XXX_NUM_CAPS  2
381 static unsigned long stac92hd83xxx_capvols[] = {
382         HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_OUTPUT),
383         HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_OUTPUT),
384 };
385 #define stac92hd83xxx_capsws    stac92hd83xxx_capvols
386
387 static hda_nid_t stac92hd71bxx_pwr_nids[3] = {
388         0x0a, 0x0d, 0x0f
389 };
390
391 static hda_nid_t stac92hd71bxx_adc_nids[2] = {
392         0x12, 0x13,
393 };
394
395 static hda_nid_t stac92hd71bxx_mux_nids[2] = {
396         0x1a, 0x1b
397 };
398
399 static hda_nid_t stac92hd71bxx_dmux_nids[2] = {
400         0x1c, 0x1d,
401 };
402
403 static hda_nid_t stac92hd71bxx_smux_nids[2] = {
404         0x24, 0x25,
405 };
406
407 #define STAC92HD71BXX_NUM_DMICS 2
408 static hda_nid_t stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS + 1] = {
409         0x18, 0x19, 0
410 };
411
412 static hda_nid_t stac92hd71bxx_slave_dig_outs[2] = {
413         0x22, 0
414 };
415
416 #define STAC92HD71BXX_NUM_CAPS          2
417 static unsigned long stac92hd71bxx_capvols[] = {
418         HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
419         HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
420 };
421 #define stac92hd71bxx_capsws    stac92hd71bxx_capvols
422
423 static hda_nid_t stac925x_adc_nids[1] = {
424         0x03,
425 };
426
427 static hda_nid_t stac925x_mux_nids[1] = {
428         0x0f,
429 };
430
431 static hda_nid_t stac925x_dac_nids[1] = {
432         0x02,
433 };
434
435 #define STAC925X_NUM_DMICS      1
436 static hda_nid_t stac925x_dmic_nids[STAC925X_NUM_DMICS + 1] = {
437         0x15, 0
438 };
439
440 static hda_nid_t stac925x_dmux_nids[1] = {
441         0x14,
442 };
443
444 static unsigned long stac925x_capvols[] = {
445         HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
446 };
447 static unsigned long stac925x_capsws[] = {
448         HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
449 };
450
451 static hda_nid_t stac922x_adc_nids[2] = {
452         0x06, 0x07,
453 };
454
455 static hda_nid_t stac922x_mux_nids[2] = {
456         0x12, 0x13,
457 };
458
459 #define STAC922X_NUM_CAPS       2
460 static unsigned long stac922x_capvols[] = {
461         HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_INPUT),
462         HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT),
463 };
464 #define stac922x_capsws         stac922x_capvols
465
466 static hda_nid_t stac927x_slave_dig_outs[2] = {
467         0x1f, 0,
468 };
469
470 static hda_nid_t stac927x_adc_nids[3] = {
471         0x07, 0x08, 0x09
472 };
473
474 static hda_nid_t stac927x_mux_nids[3] = {
475         0x15, 0x16, 0x17
476 };
477
478 static hda_nid_t stac927x_smux_nids[1] = {
479         0x21,
480 };
481
482 static hda_nid_t stac927x_dac_nids[6] = {
483         0x02, 0x03, 0x04, 0x05, 0x06, 0
484 };
485
486 static hda_nid_t stac927x_dmux_nids[1] = {
487         0x1b,
488 };
489
490 #define STAC927X_NUM_DMICS 2
491 static hda_nid_t stac927x_dmic_nids[STAC927X_NUM_DMICS + 1] = {
492         0x13, 0x14, 0
493 };
494
495 #define STAC927X_NUM_CAPS       3
496 static unsigned long stac927x_capvols[] = {
497         HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT),
498         HDA_COMPOSE_AMP_VAL(0x19, 3, 0, HDA_INPUT),
499         HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_INPUT),
500 };
501 static unsigned long stac927x_capsws[] = {
502         HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
503         HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
504         HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
505 };
506
507 static const char *stac927x_spdif_labels[5] = {
508         "Digital Playback", "ADAT", "Analog Mux 1",
509         "Analog Mux 2", "Analog Mux 3"
510 };
511
512 static hda_nid_t stac9205_adc_nids[2] = {
513         0x12, 0x13
514 };
515
516 static hda_nid_t stac9205_mux_nids[2] = {
517         0x19, 0x1a
518 };
519
520 static hda_nid_t stac9205_dmux_nids[1] = {
521         0x1d,
522 };
523
524 static hda_nid_t stac9205_smux_nids[1] = {
525         0x21,
526 };
527
528 #define STAC9205_NUM_DMICS      2
529 static hda_nid_t stac9205_dmic_nids[STAC9205_NUM_DMICS + 1] = {
530         0x17, 0x18, 0
531 };
532
533 #define STAC9205_NUM_CAPS       2
534 static unsigned long stac9205_capvols[] = {
535         HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_INPUT),
536         HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_INPUT),
537 };
538 static unsigned long stac9205_capsws[] = {
539         HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
540         HDA_COMPOSE_AMP_VAL(0x1e, 3, 0, HDA_OUTPUT),
541 };
542
543 static hda_nid_t stac9200_pin_nids[8] = {
544         0x08, 0x09, 0x0d, 0x0e, 
545         0x0f, 0x10, 0x11, 0x12,
546 };
547
548 static hda_nid_t stac925x_pin_nids[8] = {
549         0x07, 0x08, 0x0a, 0x0b, 
550         0x0c, 0x0d, 0x10, 0x11,
551 };
552
553 static hda_nid_t stac922x_pin_nids[10] = {
554         0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
555         0x0f, 0x10, 0x11, 0x15, 0x1b,
556 };
557
558 static hda_nid_t stac92hd73xx_pin_nids[13] = {
559         0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
560         0x0f, 0x10, 0x11, 0x12, 0x13,
561         0x14, 0x22, 0x23
562 };
563
564 static hda_nid_t stac92hd83xxx_pin_nids[10] = {
565         0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
566         0x0f, 0x10, 0x11, 0x1f, 0x20,
567 };
568
569 #define STAC92HD71BXX_NUM_PINS 13
570 static hda_nid_t stac92hd71bxx_pin_nids_4port[STAC92HD71BXX_NUM_PINS] = {
571         0x0a, 0x0b, 0x0c, 0x0d, 0x00,
572         0x00, 0x14, 0x18, 0x19, 0x1e,
573         0x1f, 0x20, 0x27
574 };
575 static hda_nid_t stac92hd71bxx_pin_nids_6port[STAC92HD71BXX_NUM_PINS] = {
576         0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
577         0x0f, 0x14, 0x18, 0x19, 0x1e,
578         0x1f, 0x20, 0x27
579 };
580
581 static hda_nid_t stac927x_pin_nids[14] = {
582         0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
583         0x0f, 0x10, 0x11, 0x12, 0x13,
584         0x14, 0x21, 0x22, 0x23,
585 };
586
587 static hda_nid_t stac9205_pin_nids[12] = {
588         0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
589         0x0f, 0x14, 0x16, 0x17, 0x18,
590         0x21, 0x22,
591 };
592
593 #define stac92xx_amp_volume_info snd_hda_mixer_amp_volume_info
594
595 static int stac92xx_amp_volume_get(struct snd_kcontrol *kcontrol,
596                                  struct snd_ctl_elem_value *ucontrol)
597 {
598         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
599         struct sigmatel_spec *spec = codec->spec;
600         hda_nid_t nid = spec->amp_nids[spec->cur_amux];
601
602         kcontrol->private_value ^= get_amp_nid(kcontrol);
603         kcontrol->private_value |= nid;
604
605         return snd_hda_mixer_amp_volume_get(kcontrol, ucontrol);
606 }
607
608 static int stac92xx_amp_volume_put(struct snd_kcontrol *kcontrol,
609                                  struct snd_ctl_elem_value *ucontrol)
610 {
611         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
612         struct sigmatel_spec *spec = codec->spec;
613         hda_nid_t nid = spec->amp_nids[spec->cur_amux];
614
615         kcontrol->private_value ^= get_amp_nid(kcontrol);
616         kcontrol->private_value |= nid;
617
618         return snd_hda_mixer_amp_volume_put(kcontrol, ucontrol);
619 }
620
621 static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
622                                    struct snd_ctl_elem_info *uinfo)
623 {
624         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
625         struct sigmatel_spec *spec = codec->spec;
626         return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
627 }
628
629 static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
630                                   struct snd_ctl_elem_value *ucontrol)
631 {
632         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
633         struct sigmatel_spec *spec = codec->spec;
634         unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
635
636         ucontrol->value.enumerated.item[0] = spec->cur_dmux[dmux_idx];
637         return 0;
638 }
639
640 static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
641                                   struct snd_ctl_elem_value *ucontrol)
642 {
643         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
644         struct sigmatel_spec *spec = codec->spec;
645         unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
646
647         return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
648                         spec->dmux_nids[dmux_idx], &spec->cur_dmux[dmux_idx]);
649 }
650
651 static int stac92xx_smux_enum_info(struct snd_kcontrol *kcontrol,
652                                    struct snd_ctl_elem_info *uinfo)
653 {
654         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
655         struct sigmatel_spec *spec = codec->spec;
656         return snd_hda_input_mux_info(spec->sinput_mux, uinfo);
657 }
658
659 static int stac92xx_smux_enum_get(struct snd_kcontrol *kcontrol,
660                                   struct snd_ctl_elem_value *ucontrol)
661 {
662         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
663         struct sigmatel_spec *spec = codec->spec;
664         unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
665
666         ucontrol->value.enumerated.item[0] = spec->cur_smux[smux_idx];
667         return 0;
668 }
669
670 static int stac92xx_smux_enum_put(struct snd_kcontrol *kcontrol,
671                                   struct snd_ctl_elem_value *ucontrol)
672 {
673         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
674         struct sigmatel_spec *spec = codec->spec;
675         struct hda_input_mux *smux = &spec->private_smux;
676         unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
677         int err, val;
678         hda_nid_t nid;
679
680         err = snd_hda_input_mux_put(codec, spec->sinput_mux, ucontrol,
681                         spec->smux_nids[smux_idx], &spec->cur_smux[smux_idx]);
682         if (err < 0)
683                 return err;
684
685         if (spec->spdif_mute) {
686                 if (smux_idx == 0)
687                         nid = spec->multiout.dig_out_nid;
688                 else
689                         nid = codec->slave_dig_outs[smux_idx - 1];
690                 if (spec->cur_smux[smux_idx] == smux->num_items - 1)
691                         val = HDA_AMP_MUTE;
692                 else
693                         val = 0;
694                 /* un/mute SPDIF out */
695                 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
696                                          HDA_AMP_MUTE, val);
697         }
698         return 0;
699 }
700
701 static unsigned int stac92xx_vref_set(struct hda_codec *codec,
702                                         hda_nid_t nid, unsigned int new_vref)
703 {
704         int error;
705         unsigned int pincfg;
706         pincfg = snd_hda_codec_read(codec, nid, 0,
707                                 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
708
709         pincfg &= 0xff;
710         pincfg &= ~(AC_PINCTL_VREFEN | AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
711         pincfg |= new_vref;
712
713         if (new_vref == AC_PINCTL_VREF_HIZ)
714                 pincfg |= AC_PINCTL_OUT_EN;
715         else
716                 pincfg |= AC_PINCTL_IN_EN;
717
718         error = snd_hda_codec_write_cache(codec, nid, 0,
719                                         AC_VERB_SET_PIN_WIDGET_CONTROL, pincfg);
720         if (error < 0)
721                 return error;
722         else
723                 return 1;
724 }
725
726 static unsigned int stac92xx_vref_get(struct hda_codec *codec, hda_nid_t nid)
727 {
728         unsigned int vref;
729         vref = snd_hda_codec_read(codec, nid, 0,
730                                 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
731         vref &= AC_PINCTL_VREFEN;
732         return vref;
733 }
734
735 static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
736 {
737         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
738         struct sigmatel_spec *spec = codec->spec;
739         return snd_hda_input_mux_info(spec->input_mux, uinfo);
740 }
741
742 static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
743 {
744         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
745         struct sigmatel_spec *spec = codec->spec;
746         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
747
748         ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
749         return 0;
750 }
751
752 static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
753 {
754         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
755         struct sigmatel_spec *spec = codec->spec;
756         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
757         const struct hda_input_mux *imux = spec->input_mux;
758         unsigned int idx, prev_idx;
759
760         idx = ucontrol->value.enumerated.item[0];
761         if (idx >= imux->num_items)
762                 idx = imux->num_items - 1;
763         prev_idx = spec->cur_mux[adc_idx];
764         if (prev_idx == idx)
765                 return 0;
766         if (idx < spec->num_analog_muxes) {
767                 snd_hda_codec_write_cache(codec, spec->mux_nids[adc_idx], 0,
768                                           AC_VERB_SET_CONNECT_SEL,
769                                           imux->items[idx].index);
770                 if (prev_idx >= spec->num_analog_muxes) {
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                 snd_hda_codec_write_cache(codec, spec->dmux_nids[adc_idx], 0,
781                                           AC_VERB_SET_CONNECT_SEL,
782                                           imux->items[idx - 1].index);
783         }
784         spec->cur_mux[adc_idx] = idx;
785         return 1;
786 }
787
788 static int stac92xx_mono_mux_enum_info(struct snd_kcontrol *kcontrol,
789         struct snd_ctl_elem_info *uinfo)
790 {
791         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
792         struct sigmatel_spec *spec = codec->spec;
793         return snd_hda_input_mux_info(spec->mono_mux, uinfo);
794 }
795
796 static int stac92xx_mono_mux_enum_get(struct snd_kcontrol *kcontrol,
797         struct snd_ctl_elem_value *ucontrol)
798 {
799         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
800         struct sigmatel_spec *spec = codec->spec;
801
802         ucontrol->value.enumerated.item[0] = spec->cur_mmux;
803         return 0;
804 }
805
806 static int stac92xx_mono_mux_enum_put(struct snd_kcontrol *kcontrol,
807         struct snd_ctl_elem_value *ucontrol)
808 {
809         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
810         struct sigmatel_spec *spec = codec->spec;
811
812         return snd_hda_input_mux_put(codec, spec->mono_mux, ucontrol,
813                                      spec->mono_nid, &spec->cur_mmux);
814 }
815
816 static int stac92xx_amp_mux_enum_info(struct snd_kcontrol *kcontrol,
817         struct snd_ctl_elem_info *uinfo)
818 {
819         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
820         struct sigmatel_spec *spec = codec->spec;
821         return snd_hda_input_mux_info(spec->amp_mux, uinfo);
822 }
823
824 static int stac92xx_amp_mux_enum_get(struct snd_kcontrol *kcontrol,
825         struct snd_ctl_elem_value *ucontrol)
826 {
827         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
828         struct sigmatel_spec *spec = codec->spec;
829
830         ucontrol->value.enumerated.item[0] = spec->cur_amux;
831         return 0;
832 }
833
834 static int stac92xx_amp_mux_enum_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         struct snd_kcontrol *ctl =
840                 snd_hda_find_mixer_ctl(codec, "Amp Capture Volume");
841         if (!ctl)
842                 return -EINVAL;
843
844         snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE |
845                 SNDRV_CTL_EVENT_MASK_INFO, &ctl->id);
846
847         return snd_hda_input_mux_put(codec, spec->amp_mux, ucontrol,
848                                      0, &spec->cur_amux);
849 }
850
851 #define stac92xx_aloopback_info snd_ctl_boolean_mono_info
852
853 static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol,
854         struct snd_ctl_elem_value *ucontrol)
855 {
856         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
857         unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
858         struct sigmatel_spec *spec = codec->spec;
859
860         ucontrol->value.integer.value[0] = !!(spec->aloopback &
861                                               (spec->aloopback_mask << idx));
862         return 0;
863 }
864
865 static int stac92xx_aloopback_put(struct snd_kcontrol *kcontrol,
866                 struct snd_ctl_elem_value *ucontrol)
867 {
868         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
869         struct sigmatel_spec *spec = codec->spec;
870         unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
871         unsigned int dac_mode;
872         unsigned int val, idx_val;
873
874         idx_val = spec->aloopback_mask << idx;
875         if (ucontrol->value.integer.value[0])
876                 val = spec->aloopback | idx_val;
877         else
878                 val = spec->aloopback & ~idx_val;
879         if (spec->aloopback == val)
880                 return 0;
881
882         spec->aloopback = val;
883
884         /* Only return the bits defined by the shift value of the
885          * first two bytes of the mask
886          */
887         dac_mode = snd_hda_codec_read(codec, codec->afg, 0,
888                                       kcontrol->private_value & 0xFFFF, 0x0);
889         dac_mode >>= spec->aloopback_shift;
890
891         if (spec->aloopback & idx_val) {
892                 snd_hda_power_up(codec);
893                 dac_mode |= idx_val;
894         } else {
895                 snd_hda_power_down(codec);
896                 dac_mode &= ~idx_val;
897         }
898
899         snd_hda_codec_write_cache(codec, codec->afg, 0,
900                 kcontrol->private_value >> 16, dac_mode);
901
902         return 1;
903 }
904
905 static struct hda_verb stac9200_core_init[] = {
906         /* set dac0mux for dac converter */
907         { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
908         {}
909 };
910
911 static struct hda_verb stac9200_eapd_init[] = {
912         /* set dac0mux for dac converter */
913         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
914         {0x08, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
915         {}
916 };
917
918 static struct hda_verb dell_eq_core_init[] = {
919         /* set master volume to max value without distortion
920          * and direct control */
921         { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xec},
922         {}
923 };
924
925 static struct hda_verb stac92hd73xx_core_init[] = {
926         /* set master volume and direct control */
927         { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
928         {}
929 };
930
931 static struct hda_verb stac92hd83xxx_core_init[] = {
932         { 0xa, AC_VERB_SET_CONNECT_SEL, 0x1},
933         { 0xb, AC_VERB_SET_CONNECT_SEL, 0x1},
934         { 0xd, AC_VERB_SET_CONNECT_SEL, 0x0},
935
936         /* power state controls amps */
937         { 0x01, AC_VERB_SET_EAPD, 1 << 2},
938         {}
939 };
940
941 static struct hda_verb stac92hd71bxx_core_init[] = {
942         /* set master volume and direct control */
943         { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
944         {}
945 };
946
947 static struct hda_verb stac92hd71bxx_unmute_core_init[] = {
948         /* unmute right and left channels for nodes 0x0f, 0xa, 0x0d */
949         { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
950         { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
951         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
952         {}
953 };
954
955 static struct hda_verb stac925x_core_init[] = {
956         /* set dac0mux for dac converter */
957         { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
958         /* mute the master volume */
959         { 0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
960         {}
961 };
962
963 static struct hda_verb stac922x_core_init[] = {
964         /* set master volume and direct control */      
965         { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
966         {}
967 };
968
969 static struct hda_verb d965_core_init[] = {
970         /* set master volume and direct control */      
971         { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
972         /* unmute node 0x1b */
973         { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
974         /* select node 0x03 as DAC */   
975         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
976         {}
977 };
978
979 static struct hda_verb stac927x_core_init[] = {
980         /* set master volume and direct control */      
981         { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
982         /* enable analog pc beep path */
983         { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
984         {}
985 };
986
987 static struct hda_verb stac9205_core_init[] = {
988         /* set master volume and direct control */      
989         { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
990         /* enable analog pc beep path */
991         { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
992         {}
993 };
994
995 #define STAC_MONO_MUX \
996         { \
997                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
998                 .name = "Mono Mux", \
999                 .count = 1, \
1000                 .info = stac92xx_mono_mux_enum_info, \
1001                 .get = stac92xx_mono_mux_enum_get, \
1002                 .put = stac92xx_mono_mux_enum_put, \
1003         }
1004
1005 #define STAC_AMP_MUX \
1006         { \
1007                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1008                 .name = "Amp Selector Capture Switch", \
1009                 .count = 1, \
1010                 .info = stac92xx_amp_mux_enum_info, \
1011                 .get = stac92xx_amp_mux_enum_get, \
1012                 .put = stac92xx_amp_mux_enum_put, \
1013         }
1014
1015 #define STAC_AMP_VOL(xname, nid, chs, idx, dir) \
1016         { \
1017                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1018                 .name = xname, \
1019                 .index = 0, \
1020                 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1021                         SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1022                         SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
1023                 .info = stac92xx_amp_volume_info, \
1024                 .get = stac92xx_amp_volume_get, \
1025                 .put = stac92xx_amp_volume_put, \
1026                 .tlv = { .c = snd_hda_mixer_amp_tlv }, \
1027                 .private_value = HDA_COMPOSE_AMP_VAL(nid, chs, idx, dir) \
1028         }
1029
1030 #define STAC_ANALOG_LOOPBACK(verb_read, verb_write, cnt) \
1031         { \
1032                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1033                 .name  = "Analog Loopback", \
1034                 .count = cnt, \
1035                 .info  = stac92xx_aloopback_info, \
1036                 .get   = stac92xx_aloopback_get, \
1037                 .put   = stac92xx_aloopback_put, \
1038                 .private_value = verb_read | (verb_write << 16), \
1039         }
1040
1041 #define DC_BIAS(xname, idx, nid) \
1042         { \
1043                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1044                 .name = xname, \
1045                 .index = idx, \
1046                 .info = stac92xx_dc_bias_info, \
1047                 .get = stac92xx_dc_bias_get, \
1048                 .put = stac92xx_dc_bias_put, \
1049                 .private_value = nid, \
1050         }
1051
1052 static struct snd_kcontrol_new stac9200_mixer[] = {
1053         HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
1054         HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
1055         HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
1056         HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
1057         { } /* end */
1058 };
1059
1060 static struct snd_kcontrol_new stac92hd73xx_6ch_loopback[] = {
1061         STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 3),
1062         {}
1063 };
1064
1065 static struct snd_kcontrol_new stac92hd73xx_8ch_loopback[] = {
1066         STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 4),
1067         {}
1068 };
1069
1070 static struct snd_kcontrol_new stac92hd73xx_10ch_loopback[] = {
1071         STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 5),
1072         {}
1073 };
1074
1075
1076 static struct snd_kcontrol_new stac92hd71bxx_loopback[] = {
1077         STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2)
1078 };
1079
1080 static struct snd_kcontrol_new stac925x_mixer[] = {
1081         HDA_CODEC_VOLUME("Master Playback Volume", 0x0e, 0, HDA_OUTPUT),
1082         HDA_CODEC_MUTE("Master Playback Switch", 0x0e, 0, HDA_OUTPUT),
1083         { } /* end */
1084 };
1085
1086 static struct snd_kcontrol_new stac9205_loopback[] = {
1087         STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0, 1),
1088         {}
1089 };
1090
1091 static struct snd_kcontrol_new stac927x_loopback[] = {
1092         STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB, 1),
1093         {}
1094 };
1095
1096 static struct snd_kcontrol_new stac_dmux_mixer = {
1097         .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1098         .name = "Digital Input Source",
1099         /* count set later */
1100         .info = stac92xx_dmux_enum_info,
1101         .get = stac92xx_dmux_enum_get,
1102         .put = stac92xx_dmux_enum_put,
1103 };
1104
1105 static struct snd_kcontrol_new stac_smux_mixer = {
1106         .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1107         .name = "IEC958 Playback Source",
1108         /* count set later */
1109         .info = stac92xx_smux_enum_info,
1110         .get = stac92xx_smux_enum_get,
1111         .put = stac92xx_smux_enum_put,
1112 };
1113
1114 static const char *slave_vols[] = {
1115         "Front Playback Volume",
1116         "Surround Playback Volume",
1117         "Center Playback Volume",
1118         "LFE Playback Volume",
1119         "Side Playback Volume",
1120         "Headphone Playback Volume",
1121         "Speaker Playback Volume",
1122         NULL
1123 };
1124
1125 static const char *slave_sws[] = {
1126         "Front Playback Switch",
1127         "Surround Playback Switch",
1128         "Center Playback Switch",
1129         "LFE Playback Switch",
1130         "Side Playback Switch",
1131         "Headphone Playback Switch",
1132         "Speaker Playback Switch",
1133         "IEC958 Playback Switch",
1134         NULL
1135 };
1136
1137 static void stac92xx_free_kctls(struct hda_codec *codec);
1138 static int stac92xx_add_jack(struct hda_codec *codec, hda_nid_t nid, int type);
1139
1140 static int stac92xx_build_controls(struct hda_codec *codec)
1141 {
1142         struct sigmatel_spec *spec = codec->spec;
1143         struct auto_pin_cfg *cfg = &spec->autocfg;
1144         hda_nid_t nid;
1145         int err;
1146         int i;
1147
1148         if (spec->mixer) {
1149                 err = snd_hda_add_new_ctls(codec, spec->mixer);
1150                 if (err < 0)
1151                         return err;
1152         }
1153
1154         for (i = 0; i < spec->num_mixers; i++) {
1155                 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1156                 if (err < 0)
1157                         return err;
1158         }
1159         if (!spec->auto_mic && spec->num_dmuxes > 0 &&
1160             snd_hda_get_bool_hint(codec, "separate_dmux") == 1) {
1161                 stac_dmux_mixer.count = spec->num_dmuxes;
1162                 err = snd_hda_ctl_add(codec,
1163                                   snd_ctl_new1(&stac_dmux_mixer, codec));
1164                 if (err < 0)
1165                         return err;
1166         }
1167         if (spec->num_smuxes > 0) {
1168                 int wcaps = get_wcaps(codec, spec->multiout.dig_out_nid);
1169                 struct hda_input_mux *smux = &spec->private_smux;
1170                 /* check for mute support on SPDIF out */
1171                 if (wcaps & AC_WCAP_OUT_AMP) {
1172                         smux->items[smux->num_items].label = "Off";
1173                         smux->items[smux->num_items].index = 0;
1174                         smux->num_items++;
1175                         spec->spdif_mute = 1;
1176                 }
1177                 stac_smux_mixer.count = spec->num_smuxes;
1178                 err = snd_hda_ctl_add(codec,
1179                                   snd_ctl_new1(&stac_smux_mixer, codec));
1180                 if (err < 0)
1181                         return err;
1182         }
1183
1184         if (spec->multiout.dig_out_nid) {
1185                 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
1186                 if (err < 0)
1187                         return err;
1188                 err = snd_hda_create_spdif_share_sw(codec,
1189                                                     &spec->multiout);
1190                 if (err < 0)
1191                         return err;
1192                 spec->multiout.share_spdif = 1;
1193         }
1194         if (spec->dig_in_nid && !(spec->gpio_dir & 0x01)) {
1195                 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1196                 if (err < 0)
1197                         return err;
1198         }
1199
1200         /* if we have no master control, let's create it */
1201         if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1202                 unsigned int vmaster_tlv[4];
1203                 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
1204                                         HDA_OUTPUT, vmaster_tlv);
1205                 /* correct volume offset */
1206                 vmaster_tlv[2] += vmaster_tlv[3] * spec->volume_offset;
1207                 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1208                                           vmaster_tlv, slave_vols);
1209                 if (err < 0)
1210                         return err;
1211         }
1212         if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1213                 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1214                                           NULL, slave_sws);
1215                 if (err < 0)
1216                         return err;
1217         }
1218
1219         if (spec->aloopback_ctl &&
1220             snd_hda_get_bool_hint(codec, "loopback") == 1) {
1221                 err = snd_hda_add_new_ctls(codec, spec->aloopback_ctl);
1222                 if (err < 0)
1223                         return err;
1224         }
1225
1226         stac92xx_free_kctls(codec); /* no longer needed */
1227
1228         /* create jack input elements */
1229         if (spec->hp_detect) {
1230                 for (i = 0; i < cfg->hp_outs; i++) {
1231                         int type = SND_JACK_HEADPHONE;
1232                         nid = cfg->hp_pins[i];
1233                         /* jack detection */
1234                         if (cfg->hp_outs == i)
1235                                 type |= SND_JACK_LINEOUT;
1236                         err = stac92xx_add_jack(codec, nid, type);
1237                         if (err < 0)
1238                                 return err;
1239                 }
1240         }
1241         for (i = 0; i < cfg->line_outs; i++) {
1242                 err = stac92xx_add_jack(codec, cfg->line_out_pins[i],
1243                                         SND_JACK_LINEOUT);
1244                 if (err < 0)
1245                         return err;
1246         }
1247         for (i = 0; i < AUTO_PIN_LAST; i++) {
1248                 nid = cfg->input_pins[i];
1249                 if (nid) {
1250                         err = stac92xx_add_jack(codec, nid,
1251                                                 SND_JACK_MICROPHONE);
1252                         if (err < 0)
1253                                 return err;
1254                 }
1255         }
1256
1257         return 0;       
1258 }
1259
1260 static unsigned int ref9200_pin_configs[8] = {
1261         0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
1262         0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
1263 };
1264
1265 static unsigned int gateway9200_m4_pin_configs[8] = {
1266         0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1267         0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1268 };
1269 static unsigned int gateway9200_m4_2_pin_configs[8] = {
1270         0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1271         0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1272 };
1273
1274 /*
1275     STAC 9200 pin configs for
1276     102801A8
1277     102801DE
1278     102801E8
1279 */
1280 static unsigned int dell9200_d21_pin_configs[8] = {
1281         0x400001f0, 0x400001f1, 0x02214030, 0x01014010, 
1282         0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
1283 };
1284
1285 /* 
1286     STAC 9200 pin configs for
1287     102801C0
1288     102801C1
1289 */
1290 static unsigned int dell9200_d22_pin_configs[8] = {
1291         0x400001f0, 0x400001f1, 0x0221401f, 0x01014010, 
1292         0x01813020, 0x02a19021, 0x90100140, 0x400001f2,
1293 };
1294
1295 /* 
1296     STAC 9200 pin configs for
1297     102801C4 (Dell Dimension E310)
1298     102801C5
1299     102801C7
1300     102801D9
1301     102801DA
1302     102801E3
1303 */
1304 static unsigned int dell9200_d23_pin_configs[8] = {
1305         0x400001f0, 0x400001f1, 0x0221401f, 0x01014010, 
1306         0x01813020, 0x01a19021, 0x90100140, 0x400001f2, 
1307 };
1308
1309
1310 /* 
1311     STAC 9200-32 pin configs for
1312     102801B5 (Dell Inspiron 630m)
1313     102801D8 (Dell Inspiron 640m)
1314 */
1315 static unsigned int dell9200_m21_pin_configs[8] = {
1316         0x40c003fa, 0x03441340, 0x0321121f, 0x90170310,
1317         0x408003fb, 0x03a11020, 0x401003fc, 0x403003fd,
1318 };
1319
1320 /* 
1321     STAC 9200-32 pin configs for
1322     102801C2 (Dell Latitude D620)
1323     102801C8 
1324     102801CC (Dell Latitude D820)
1325     102801D4 
1326     102801D6 
1327 */
1328 static unsigned int dell9200_m22_pin_configs[8] = {
1329         0x40c003fa, 0x0144131f, 0x0321121f, 0x90170310, 
1330         0x90a70321, 0x03a11020, 0x401003fb, 0x40f000fc,
1331 };
1332
1333 /* 
1334     STAC 9200-32 pin configs for
1335     102801CE (Dell XPS M1710)
1336     102801CF (Dell Precision M90)
1337 */
1338 static unsigned int dell9200_m23_pin_configs[8] = {
1339         0x40c003fa, 0x01441340, 0x0421421f, 0x90170310,
1340         0x408003fb, 0x04a1102e, 0x90170311, 0x403003fc,
1341 };
1342
1343 /*
1344     STAC 9200-32 pin configs for 
1345     102801C9
1346     102801CA
1347     102801CB (Dell Latitude 120L)
1348     102801D3
1349 */
1350 static unsigned int dell9200_m24_pin_configs[8] = {
1351         0x40c003fa, 0x404003fb, 0x0321121f, 0x90170310, 
1352         0x408003fc, 0x03a11020, 0x401003fd, 0x403003fe, 
1353 };
1354
1355 /*
1356     STAC 9200-32 pin configs for
1357     102801BD (Dell Inspiron E1505n)
1358     102801EE
1359     102801EF
1360 */
1361 static unsigned int dell9200_m25_pin_configs[8] = {
1362         0x40c003fa, 0x01441340, 0x0421121f, 0x90170310, 
1363         0x408003fb, 0x04a11020, 0x401003fc, 0x403003fd,
1364 };
1365
1366 /*
1367     STAC 9200-32 pin configs for
1368     102801F5 (Dell Inspiron 1501)
1369     102801F6
1370 */
1371 static unsigned int dell9200_m26_pin_configs[8] = {
1372         0x40c003fa, 0x404003fb, 0x0421121f, 0x90170310, 
1373         0x408003fc, 0x04a11020, 0x401003fd, 0x403003fe,
1374 };
1375
1376 /*
1377     STAC 9200-32
1378     102801CD (Dell Inspiron E1705/9400)
1379 */
1380 static unsigned int dell9200_m27_pin_configs[8] = {
1381         0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1382         0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
1383 };
1384
1385 static unsigned int oqo9200_pin_configs[8] = {
1386         0x40c000f0, 0x404000f1, 0x0221121f, 0x02211210,
1387         0x90170111, 0x90a70120, 0x400000f2, 0x400000f3,
1388 };
1389
1390
1391 static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
1392         [STAC_REF] = ref9200_pin_configs,
1393         [STAC_9200_OQO] = oqo9200_pin_configs,
1394         [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
1395         [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
1396         [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
1397         [STAC_9200_DELL_M21] = dell9200_m21_pin_configs,
1398         [STAC_9200_DELL_M22] = dell9200_m22_pin_configs,
1399         [STAC_9200_DELL_M23] = dell9200_m23_pin_configs,
1400         [STAC_9200_DELL_M24] = dell9200_m24_pin_configs,
1401         [STAC_9200_DELL_M25] = dell9200_m25_pin_configs,
1402         [STAC_9200_DELL_M26] = dell9200_m26_pin_configs,
1403         [STAC_9200_DELL_M27] = dell9200_m27_pin_configs,
1404         [STAC_9200_M4] = gateway9200_m4_pin_configs,
1405         [STAC_9200_M4_2] = gateway9200_m4_2_pin_configs,
1406         [STAC_9200_PANASONIC] = ref9200_pin_configs,
1407 };
1408
1409 static const char *stac9200_models[STAC_9200_MODELS] = {
1410         [STAC_AUTO] = "auto",
1411         [STAC_REF] = "ref",
1412         [STAC_9200_OQO] = "oqo",
1413         [STAC_9200_DELL_D21] = "dell-d21",
1414         [STAC_9200_DELL_D22] = "dell-d22",
1415         [STAC_9200_DELL_D23] = "dell-d23",
1416         [STAC_9200_DELL_M21] = "dell-m21",
1417         [STAC_9200_DELL_M22] = "dell-m22",
1418         [STAC_9200_DELL_M23] = "dell-m23",
1419         [STAC_9200_DELL_M24] = "dell-m24",
1420         [STAC_9200_DELL_M25] = "dell-m25",
1421         [STAC_9200_DELL_M26] = "dell-m26",
1422         [STAC_9200_DELL_M27] = "dell-m27",
1423         [STAC_9200_M4] = "gateway-m4",
1424         [STAC_9200_M4_2] = "gateway-m4-2",
1425         [STAC_9200_PANASONIC] = "panasonic",
1426 };
1427
1428 static struct snd_pci_quirk stac9200_cfg_tbl[] = {
1429         /* SigmaTel reference board */
1430         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1431                       "DFI LanParty", STAC_REF),
1432         SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1433                       "DFI LanParty", STAC_REF),
1434         /* Dell laptops have BIOS problem */
1435         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
1436                       "unknown Dell", STAC_9200_DELL_D21),
1437         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
1438                       "Dell Inspiron 630m", STAC_9200_DELL_M21),
1439         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bd,
1440                       "Dell Inspiron E1505n", STAC_9200_DELL_M25),
1441         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c0,
1442                       "unknown Dell", STAC_9200_DELL_D22),
1443         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c1,
1444                       "unknown Dell", STAC_9200_DELL_D22),
1445         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
1446                       "Dell Latitude D620", STAC_9200_DELL_M22),
1447         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c5,
1448                       "unknown Dell", STAC_9200_DELL_D23),
1449         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c7,
1450                       "unknown Dell", STAC_9200_DELL_D23),
1451         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c8,
1452                       "unknown Dell", STAC_9200_DELL_M22),
1453         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c9,
1454                       "unknown Dell", STAC_9200_DELL_M24),
1455         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ca,
1456                       "unknown Dell", STAC_9200_DELL_M24),
1457         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
1458                       "Dell Latitude 120L", STAC_9200_DELL_M24),
1459         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
1460                       "Dell Latitude D820", STAC_9200_DELL_M22),
1461         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
1462                       "Dell Inspiron E1705/9400", STAC_9200_DELL_M27),
1463         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
1464                       "Dell XPS M1710", STAC_9200_DELL_M23),
1465         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
1466                       "Dell Precision M90", STAC_9200_DELL_M23),
1467         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d3,
1468                       "unknown Dell", STAC_9200_DELL_M22),
1469         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d4,
1470                       "unknown Dell", STAC_9200_DELL_M22),
1471         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
1472                       "unknown Dell", STAC_9200_DELL_M22),
1473         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
1474                       "Dell Inspiron 640m", STAC_9200_DELL_M21),
1475         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d9,
1476                       "unknown Dell", STAC_9200_DELL_D23),
1477         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01da,
1478                       "unknown Dell", STAC_9200_DELL_D23),
1479         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01de,
1480                       "unknown Dell", STAC_9200_DELL_D21),
1481         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e3,
1482                       "unknown Dell", STAC_9200_DELL_D23),
1483         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e8,
1484                       "unknown Dell", STAC_9200_DELL_D21),
1485         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ee,
1486                       "unknown Dell", STAC_9200_DELL_M25),
1487         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ef,
1488                       "unknown Dell", STAC_9200_DELL_M25),
1489         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
1490                       "Dell Inspiron 1501", STAC_9200_DELL_M26),
1491         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
1492                       "unknown Dell", STAC_9200_DELL_M26),
1493         /* Panasonic */
1494         SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_9200_PANASONIC),
1495         /* Gateway machines needs EAPD to be set on resume */
1496         SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_M4),
1497         SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*", STAC_9200_M4_2),
1498         SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707", STAC_9200_M4_2),
1499         /* OQO Mobile */
1500         SND_PCI_QUIRK(0x1106, 0x3288, "OQO Model 2", STAC_9200_OQO),
1501         {} /* terminator */
1502 };
1503
1504 static unsigned int ref925x_pin_configs[8] = {
1505         0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
1506         0x90a70320, 0x02214210, 0x01019020, 0x9033032e,
1507 };
1508
1509 static unsigned int stac925xM1_pin_configs[8] = {
1510         0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1511         0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1512 };
1513
1514 static unsigned int stac925xM1_2_pin_configs[8] = {
1515         0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1516         0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1517 };
1518
1519 static unsigned int stac925xM2_pin_configs[8] = {
1520         0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1521         0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1522 };
1523
1524 static unsigned int stac925xM2_2_pin_configs[8] = {
1525         0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1526         0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1527 };
1528
1529 static unsigned int stac925xM3_pin_configs[8] = {
1530         0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1531         0x40a000f0, 0x90100210, 0x400003f1, 0x503303f3,
1532 };
1533
1534 static unsigned int stac925xM5_pin_configs[8] = {
1535         0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1536         0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1537 };
1538
1539 static unsigned int stac925xM6_pin_configs[8] = {
1540         0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1541         0x40a000f0, 0x90100210, 0x400003f1, 0x90330320,
1542 };
1543
1544 static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
1545         [STAC_REF] = ref925x_pin_configs,
1546         [STAC_M1] = stac925xM1_pin_configs,
1547         [STAC_M1_2] = stac925xM1_2_pin_configs,
1548         [STAC_M2] = stac925xM2_pin_configs,
1549         [STAC_M2_2] = stac925xM2_2_pin_configs,
1550         [STAC_M3] = stac925xM3_pin_configs,
1551         [STAC_M5] = stac925xM5_pin_configs,
1552         [STAC_M6] = stac925xM6_pin_configs,
1553 };
1554
1555 static const char *stac925x_models[STAC_925x_MODELS] = {
1556         [STAC_925x_AUTO] = "auto",
1557         [STAC_REF] = "ref",
1558         [STAC_M1] = "m1",
1559         [STAC_M1_2] = "m1-2",
1560         [STAC_M2] = "m2",
1561         [STAC_M2_2] = "m2-2",
1562         [STAC_M3] = "m3",
1563         [STAC_M5] = "m5",
1564         [STAC_M6] = "m6",
1565 };
1566
1567 static struct snd_pci_quirk stac925x_codec_id_cfg_tbl[] = {
1568         SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_M2),
1569         SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_M5),
1570         SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_M1),
1571         SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_M2),
1572         SND_PCI_QUIRK(0x107b, 0x0367, "Gateway MX6453", STAC_M1_2),
1573         /* Not sure about the brand name for those */
1574         SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M1),
1575         SND_PCI_QUIRK(0x107b, 0x0507, "Gateway mobile", STAC_M3),
1576         SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M6),
1577         SND_PCI_QUIRK(0x107b, 0x0685, "Gateway mobile", STAC_M2_2),
1578         {} /* terminator */
1579 };
1580
1581 static struct snd_pci_quirk stac925x_cfg_tbl[] = {
1582         /* SigmaTel reference board */
1583         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
1584         SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101, "DFI LanParty", STAC_REF),
1585         SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
1586
1587         /* Default table for unknown ID */
1588         SND_PCI_QUIRK(0x1002, 0x437b, "Gateway mobile", STAC_M2_2),
1589
1590         {} /* terminator */
1591 };
1592
1593 static unsigned int ref92hd73xx_pin_configs[13] = {
1594         0x02214030, 0x02a19040, 0x01a19020, 0x02214030,
1595         0x0181302e, 0x01014010, 0x01014020, 0x01014030,
1596         0x02319040, 0x90a000f0, 0x90a000f0, 0x01452050,
1597         0x01452050,
1598 };
1599
1600 static unsigned int dell_m6_pin_configs[13] = {
1601         0x0321101f, 0x4f00000f, 0x4f0000f0, 0x90170110,
1602         0x03a11020, 0x0321101f, 0x4f0000f0, 0x4f0000f0,
1603         0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1604         0x4f0000f0,
1605 };
1606
1607 static unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = {
1608         [STAC_92HD73XX_REF]     = ref92hd73xx_pin_configs,
1609         [STAC_DELL_M6_AMIC]     = dell_m6_pin_configs,
1610         [STAC_DELL_M6_DMIC]     = dell_m6_pin_configs,
1611         [STAC_DELL_M6_BOTH]     = dell_m6_pin_configs,
1612         [STAC_DELL_EQ]  = dell_m6_pin_configs,
1613 };
1614
1615 static const char *stac92hd73xx_models[STAC_92HD73XX_MODELS] = {
1616         [STAC_92HD73XX_AUTO] = "auto",
1617         [STAC_92HD73XX_NO_JD] = "no-jd",
1618         [STAC_92HD73XX_REF] = "ref",
1619         [STAC_92HD73XX_INTEL] = "intel",
1620         [STAC_DELL_M6_AMIC] = "dell-m6-amic",
1621         [STAC_DELL_M6_DMIC] = "dell-m6-dmic",
1622         [STAC_DELL_M6_BOTH] = "dell-m6",
1623         [STAC_DELL_EQ] = "dell-eq",
1624 };
1625
1626 static struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
1627         /* SigmaTel reference board */
1628         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1629                                 "DFI LanParty", STAC_92HD73XX_REF),
1630         SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1631                                 "DFI LanParty", STAC_92HD73XX_REF),
1632         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5002,
1633                                 "Intel DG45ID", STAC_92HD73XX_INTEL),
1634         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5003,
1635                                 "Intel DG45FC", STAC_92HD73XX_INTEL),
1636         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0254,
1637                                 "Dell Studio 1535", STAC_DELL_M6_DMIC),
1638         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0255,
1639                                 "unknown Dell", STAC_DELL_M6_DMIC),
1640         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0256,
1641                                 "unknown Dell", STAC_DELL_M6_BOTH),
1642         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0257,
1643                                 "unknown Dell", STAC_DELL_M6_BOTH),
1644         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025e,
1645                                 "unknown Dell", STAC_DELL_M6_AMIC),
1646         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025f,
1647                                 "unknown Dell", STAC_DELL_M6_AMIC),
1648         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0271,
1649                                 "unknown Dell", STAC_DELL_M6_DMIC),
1650         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0272,
1651                                 "unknown Dell", STAC_DELL_M6_DMIC),
1652         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x029f,
1653                                 "Dell Studio 1537", STAC_DELL_M6_DMIC),
1654         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a0,
1655                                 "Dell Studio 17", STAC_DELL_M6_DMIC),
1656         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02be,
1657                                 "Dell Studio 1555", STAC_DELL_M6_DMIC),
1658         {} /* terminator */
1659 };
1660
1661 static unsigned int ref92hd83xxx_pin_configs[10] = {
1662         0x02214030, 0x02211010, 0x02a19020, 0x02170130,
1663         0x01014050, 0x01819040, 0x01014020, 0x90a3014e,
1664         0x01451160, 0x98560170,
1665 };
1666
1667 static unsigned int dell_s14_pin_configs[10] = {
1668         0x02214030, 0x02211010, 0x02a19020, 0x01014050,
1669         0x40f000f0, 0x01819040, 0x40f000f0, 0x90a60160,
1670         0x40f000f0, 0x40f000f0,
1671 };
1672
1673 static unsigned int *stac92hd83xxx_brd_tbl[STAC_92HD83XXX_MODELS] = {
1674         [STAC_92HD83XXX_REF] = ref92hd83xxx_pin_configs,
1675         [STAC_92HD83XXX_PWR_REF] = ref92hd83xxx_pin_configs,
1676         [STAC_DELL_S14] = dell_s14_pin_configs,
1677 };
1678
1679 static const char *stac92hd83xxx_models[STAC_92HD83XXX_MODELS] = {
1680         [STAC_92HD83XXX_AUTO] = "auto",
1681         [STAC_92HD83XXX_REF] = "ref",
1682         [STAC_92HD83XXX_PWR_REF] = "mic-ref",
1683         [STAC_DELL_S14] = "dell-s14",
1684 };
1685
1686 static struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = {
1687         /* SigmaTel reference board */
1688         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1689                       "DFI LanParty", STAC_92HD83XXX_REF),
1690         SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1691                       "DFI LanParty", STAC_92HD83XXX_REF),
1692         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ba,
1693                       "unknown Dell", STAC_DELL_S14),
1694         {} /* terminator */
1695 };
1696
1697 static unsigned int ref92hd71bxx_pin_configs[STAC92HD71BXX_NUM_PINS] = {
1698         0x02214030, 0x02a19040, 0x01a19020, 0x01014010,
1699         0x0181302e, 0x01014010, 0x01019020, 0x90a000f0,
1700         0x90a000f0, 0x01452050, 0x01452050, 0x00000000,
1701         0x00000000
1702 };
1703
1704 static unsigned int dell_m4_1_pin_configs[STAC92HD71BXX_NUM_PINS] = {
1705         0x0421101f, 0x04a11221, 0x40f000f0, 0x90170110,
1706         0x23a1902e, 0x23014250, 0x40f000f0, 0x90a000f0,
1707         0x40f000f0, 0x4f0000f0, 0x4f0000f0, 0x00000000,
1708         0x00000000
1709 };
1710
1711 static unsigned int dell_m4_2_pin_configs[STAC92HD71BXX_NUM_PINS] = {
1712         0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1713         0x23a1902e, 0x23014250, 0x40f000f0, 0x40f000f0,
1714         0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1715         0x00000000
1716 };
1717
1718 static unsigned int dell_m4_3_pin_configs[STAC92HD71BXX_NUM_PINS] = {
1719         0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1720         0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a000f0,
1721         0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1722         0x00000000
1723 };
1724
1725 static unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
1726         [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs,
1727         [STAC_DELL_M4_1]        = dell_m4_1_pin_configs,
1728         [STAC_DELL_M4_2]        = dell_m4_2_pin_configs,
1729         [STAC_DELL_M4_3]        = dell_m4_3_pin_configs,
1730         [STAC_HP_M4]            = NULL,
1731         [STAC_HP_DV5]           = NULL,
1732         [STAC_HP_HDX]           = NULL,
1733         [STAC_HP_DV4_1222NR]    = NULL,
1734 };
1735
1736 static const char *stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
1737         [STAC_92HD71BXX_AUTO] = "auto",
1738         [STAC_92HD71BXX_REF] = "ref",
1739         [STAC_DELL_M4_1] = "dell-m4-1",
1740         [STAC_DELL_M4_2] = "dell-m4-2",
1741         [STAC_DELL_M4_3] = "dell-m4-3",
1742         [STAC_HP_M4] = "hp-m4",
1743         [STAC_HP_DV5] = "hp-dv5",
1744         [STAC_HP_HDX] = "hp-hdx",
1745         [STAC_HP_DV4_1222NR] = "hp-dv4-1222nr",
1746 };
1747
1748 static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
1749         /* SigmaTel reference board */
1750         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1751                       "DFI LanParty", STAC_92HD71BXX_REF),
1752         SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1753                       "DFI LanParty", STAC_92HD71BXX_REF),
1754         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30fb,
1755                       "HP dv4-1222nr", STAC_HP_DV4_1222NR),
1756         SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3080,
1757                       "HP", STAC_HP_DV5),
1758         SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x30f0,
1759                       "HP dv4-7", STAC_HP_DV5),
1760         SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3600,
1761                       "HP dv4-7", STAC_HP_DV5),
1762         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3610,
1763                       "HP HDX", STAC_HP_HDX),  /* HDX18 */
1764         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361a,
1765                       "HP mini 1000", STAC_HP_M4),
1766         SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361b,
1767                       "HP HDX", STAC_HP_HDX),  /* HDX16 */
1768         SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x7010,
1769                       "HP", STAC_HP_DV5),
1770         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
1771                                 "unknown Dell", STAC_DELL_M4_1),
1772         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234,
1773                                 "unknown Dell", STAC_DELL_M4_1),
1774         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0250,
1775                                 "unknown Dell", STAC_DELL_M4_1),
1776         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024f,
1777                                 "unknown Dell", STAC_DELL_M4_1),
1778         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024d,
1779                                 "unknown Dell", STAC_DELL_M4_1),
1780         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0251,
1781                                 "unknown Dell", STAC_DELL_M4_1),
1782         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0277,
1783                                 "unknown Dell", STAC_DELL_M4_1),
1784         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0263,
1785                                 "unknown Dell", STAC_DELL_M4_2),
1786         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0265,
1787                                 "unknown Dell", STAC_DELL_M4_2),
1788         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0262,
1789                                 "unknown Dell", STAC_DELL_M4_2),
1790         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0264,
1791                                 "unknown Dell", STAC_DELL_M4_2),
1792         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02aa,
1793                                 "unknown Dell", STAC_DELL_M4_3),
1794         {} /* terminator */
1795 };
1796
1797 static unsigned int ref922x_pin_configs[10] = {
1798         0x01014010, 0x01016011, 0x01012012, 0x0221401f,
1799         0x01813122, 0x01011014, 0x01441030, 0x01c41030,
1800         0x40000100, 0x40000100,
1801 };
1802
1803 /*
1804     STAC 922X pin configs for
1805     102801A7
1806     102801AB
1807     102801A9
1808     102801D1
1809     102801D2
1810 */
1811 static unsigned int dell_922x_d81_pin_configs[10] = {
1812         0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1813         0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
1814         0x01813122, 0x400001f2,
1815 };
1816
1817 /*
1818     STAC 922X pin configs for
1819     102801AC
1820     102801D0
1821 */
1822 static unsigned int dell_922x_d82_pin_configs[10] = {
1823         0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1824         0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
1825         0x01813122, 0x400001f1,
1826 };
1827
1828 /*
1829     STAC 922X pin configs for
1830     102801BF
1831 */
1832 static unsigned int dell_922x_m81_pin_configs[10] = {
1833         0x0321101f, 0x01112024, 0x01111222, 0x91174220,
1834         0x03a11050, 0x01116221, 0x90a70330, 0x01452340, 
1835         0x40C003f1, 0x405003f0,
1836 };
1837
1838 /*
1839     STAC 9221 A1 pin configs for
1840     102801D7 (Dell XPS M1210)
1841 */
1842 static unsigned int dell_922x_m82_pin_configs[10] = {
1843         0x02211211, 0x408103ff, 0x02a1123e, 0x90100310, 
1844         0x408003f1, 0x0221121f, 0x03451340, 0x40c003f2, 
1845         0x508003f3, 0x405003f4, 
1846 };
1847
1848 static unsigned int d945gtp3_pin_configs[10] = {
1849         0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
1850         0x40000100, 0x40000100, 0x40000100, 0x40000100,
1851         0x02a19120, 0x40000100,
1852 };
1853
1854 static unsigned int d945gtp5_pin_configs[10] = {
1855         0x0221401f, 0x01011012, 0x01813024, 0x01014010,
1856         0x01a19021, 0x01016011, 0x01452130, 0x40000100,
1857         0x02a19320, 0x40000100,
1858 };
1859
1860 static unsigned int intel_mac_v1_pin_configs[10] = {
1861         0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
1862         0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
1863         0x400000fc, 0x400000fb,
1864 };
1865
1866 static unsigned int intel_mac_v2_pin_configs[10] = {
1867         0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1868         0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
1869         0x400000fc, 0x400000fb,
1870 };
1871
1872 static unsigned int intel_mac_v3_pin_configs[10] = {
1873         0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1874         0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
1875         0x400000fc, 0x400000fb,
1876 };
1877
1878 static unsigned int intel_mac_v4_pin_configs[10] = {
1879         0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1880         0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1881         0x400000fc, 0x400000fb,
1882 };
1883
1884 static unsigned int intel_mac_v5_pin_configs[10] = {
1885         0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1886         0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1887         0x400000fc, 0x400000fb,
1888 };
1889
1890 static unsigned int ecs202_pin_configs[10] = {
1891         0x0221401f, 0x02a19020, 0x01a19020, 0x01114010,
1892         0x408000f0, 0x01813022, 0x074510a0, 0x40c400f1,
1893         0x9037012e, 0x40e000f2,
1894 };
1895
1896 static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
1897         [STAC_D945_REF] = ref922x_pin_configs,
1898         [STAC_D945GTP3] = d945gtp3_pin_configs,
1899         [STAC_D945GTP5] = d945gtp5_pin_configs,
1900         [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
1901         [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
1902         [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
1903         [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
1904         [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
1905         [STAC_INTEL_MAC_AUTO] = intel_mac_v3_pin_configs,
1906         /* for backward compatibility */
1907         [STAC_MACMINI] = intel_mac_v3_pin_configs,
1908         [STAC_MACBOOK] = intel_mac_v5_pin_configs,
1909         [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
1910         [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
1911         [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
1912         [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
1913         [STAC_ECS_202] = ecs202_pin_configs,
1914         [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
1915         [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,       
1916         [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
1917         [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,       
1918 };
1919
1920 static const char *stac922x_models[STAC_922X_MODELS] = {
1921         [STAC_922X_AUTO] = "auto",
1922         [STAC_D945_REF] = "ref",
1923         [STAC_D945GTP5] = "5stack",
1924         [STAC_D945GTP3] = "3stack",
1925         [STAC_INTEL_MAC_V1] = "intel-mac-v1",
1926         [STAC_INTEL_MAC_V2] = "intel-mac-v2",
1927         [STAC_INTEL_MAC_V3] = "intel-mac-v3",
1928         [STAC_INTEL_MAC_V4] = "intel-mac-v4",
1929         [STAC_INTEL_MAC_V5] = "intel-mac-v5",
1930         [STAC_INTEL_MAC_AUTO] = "intel-mac-auto",
1931         /* for backward compatibility */
1932         [STAC_MACMINI]  = "macmini",
1933         [STAC_MACBOOK]  = "macbook",
1934         [STAC_MACBOOK_PRO_V1]   = "macbook-pro-v1",
1935         [STAC_MACBOOK_PRO_V2]   = "macbook-pro",
1936         [STAC_IMAC_INTEL] = "imac-intel",
1937         [STAC_IMAC_INTEL_20] = "imac-intel-20",
1938         [STAC_ECS_202] = "ecs202",
1939         [STAC_922X_DELL_D81] = "dell-d81",
1940         [STAC_922X_DELL_D82] = "dell-d82",
1941         [STAC_922X_DELL_M81] = "dell-m81",
1942         [STAC_922X_DELL_M82] = "dell-m82",
1943 };
1944
1945 static struct snd_pci_quirk stac922x_cfg_tbl[] = {
1946         /* SigmaTel reference board */
1947         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1948                       "DFI LanParty", STAC_D945_REF),
1949         SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1950                       "DFI LanParty", STAC_D945_REF),
1951         /* Intel 945G based systems */
1952         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
1953                       "Intel D945G", STAC_D945GTP3),
1954         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
1955                       "Intel D945G", STAC_D945GTP3),
1956         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
1957                       "Intel D945G", STAC_D945GTP3),
1958         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
1959                       "Intel D945G", STAC_D945GTP3),
1960         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
1961                       "Intel D945G", STAC_D945GTP3),
1962         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
1963                       "Intel D945G", STAC_D945GTP3),
1964         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
1965                       "Intel D945G", STAC_D945GTP3),
1966         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
1967                       "Intel D945G", STAC_D945GTP3),
1968         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
1969                       "Intel D945G", STAC_D945GTP3),
1970         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
1971                       "Intel D945G", STAC_D945GTP3),
1972         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
1973                       "Intel D945G", STAC_D945GTP3),
1974         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
1975                       "Intel D945G", STAC_D945GTP3),
1976         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
1977                       "Intel D945G", STAC_D945GTP3),
1978         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
1979                       "Intel D945G", STAC_D945GTP3),
1980         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
1981                       "Intel D945G", STAC_D945GTP3),
1982         /* Intel D945G 5-stack systems */
1983         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
1984                       "Intel D945G", STAC_D945GTP5),
1985         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
1986                       "Intel D945G", STAC_D945GTP5),
1987         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
1988                       "Intel D945G", STAC_D945GTP5),
1989         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
1990                       "Intel D945G", STAC_D945GTP5),
1991         /* Intel 945P based systems */
1992         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
1993                       "Intel D945P", STAC_D945GTP3),
1994         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
1995                       "Intel D945P", STAC_D945GTP3),
1996         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
1997                       "Intel D945P", STAC_D945GTP3),
1998         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
1999                       "Intel D945P", STAC_D945GTP3),
2000         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
2001                       "Intel D945P", STAC_D945GTP3),
2002         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
2003                       "Intel D945P", STAC_D945GTP5),
2004         /* other intel */
2005         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0204,
2006                       "Intel D945", STAC_D945_REF),
2007         /* other systems  */
2008         /* Apple Intel Mac (Mac Mini, MacBook, MacBook Pro...) */
2009         SND_PCI_QUIRK(0x8384, 0x7680,
2010                       "Mac", STAC_INTEL_MAC_AUTO),
2011         /* Dell systems  */
2012         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
2013                       "unknown Dell", STAC_922X_DELL_D81),
2014         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
2015                       "unknown Dell", STAC_922X_DELL_D81),
2016         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
2017                       "unknown Dell", STAC_922X_DELL_D81),
2018         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
2019                       "unknown Dell", STAC_922X_DELL_D82),
2020         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
2021                       "unknown Dell", STAC_922X_DELL_M81),
2022         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
2023                       "unknown Dell", STAC_922X_DELL_D82),
2024         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
2025                       "unknown Dell", STAC_922X_DELL_D81),
2026         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
2027                       "unknown Dell", STAC_922X_DELL_D81),
2028         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
2029                       "Dell XPS M1210", STAC_922X_DELL_M82),
2030         /* ECS/PC Chips boards */
2031         SND_PCI_QUIRK_MASK(0x1019, 0xf000, 0x2000,
2032                       "ECS/PC chips", STAC_ECS_202),
2033         {} /* terminator */
2034 };
2035
2036 static unsigned int ref927x_pin_configs[14] = {
2037         0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2038         0x01a19040, 0x01011012, 0x01016011, 0x0101201f, 
2039         0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
2040         0x01c42190, 0x40000100,
2041 };
2042
2043 static unsigned int d965_3st_pin_configs[14] = {
2044         0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
2045         0x01a19021, 0x01813024, 0x40000100, 0x40000100,
2046         0x40000100, 0x40000100, 0x40000100, 0x40000100,
2047         0x40000100, 0x40000100
2048 };
2049
2050 static unsigned int d965_5st_pin_configs[14] = {
2051         0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2052         0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2053         0x40000100, 0x40000100, 0x40000100, 0x01442070,
2054         0x40000100, 0x40000100
2055 };
2056
2057 static unsigned int d965_5st_no_fp_pin_configs[14] = {
2058         0x40000100, 0x40000100, 0x0181304e, 0x01014010,
2059         0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2060         0x40000100, 0x40000100, 0x40000100, 0x01442070,
2061         0x40000100, 0x40000100
2062 };
2063
2064 static unsigned int dell_3st_pin_configs[14] = {
2065         0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
2066         0x01111212, 0x01116211, 0x01813050, 0x01112214,
2067         0x403003fa, 0x90a60040, 0x90a60040, 0x404003fb,
2068         0x40c003fc, 0x40000100
2069 };
2070
2071 static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
2072         [STAC_D965_REF_NO_JD] = ref927x_pin_configs,
2073         [STAC_D965_REF]  = ref927x_pin_configs,
2074         [STAC_D965_3ST]  = d965_3st_pin_configs,
2075         [STAC_D965_5ST]  = d965_5st_pin_configs,
2076         [STAC_D965_5ST_NO_FP]  = d965_5st_no_fp_pin_configs,
2077         [STAC_DELL_3ST]  = dell_3st_pin_configs,
2078         [STAC_DELL_BIOS] = NULL,
2079 };
2080
2081 static const char *stac927x_models[STAC_927X_MODELS] = {
2082         [STAC_927X_AUTO]        = "auto",
2083         [STAC_D965_REF_NO_JD]   = "ref-no-jd",
2084         [STAC_D965_REF]         = "ref",
2085         [STAC_D965_3ST]         = "3stack",
2086         [STAC_D965_5ST]         = "5stack",
2087         [STAC_D965_5ST_NO_FP]   = "5stack-no-fp",
2088         [STAC_DELL_3ST]         = "dell-3stack",
2089         [STAC_DELL_BIOS]        = "dell-bios",
2090 };
2091
2092 static struct snd_pci_quirk stac927x_cfg_tbl[] = {
2093         /* SigmaTel reference board */
2094         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2095                       "DFI LanParty", STAC_D965_REF),
2096         SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2097                       "DFI LanParty", STAC_D965_REF),
2098          /* Intel 946 based systems */
2099         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
2100         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
2101         /* 965 based 3 stack systems */
2102         SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2100,
2103                            "Intel D965", STAC_D965_3ST),
2104         SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2000,
2105                            "Intel D965", STAC_D965_3ST),
2106         /* Dell 3 stack systems */
2107         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x01f7, "Dell XPS M1730", STAC_DELL_3ST),
2108         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
2109         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x01ed, "Dell     ", STAC_DELL_3ST),
2110         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x01f4, "Dell     ", STAC_DELL_3ST),
2111         /* Dell 3 stack systems with verb table in BIOS */
2112         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x01f3, "Dell Inspiron 1420", STAC_DELL_BIOS),
2113         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x0227, "Dell Vostro 1400  ", STAC_DELL_BIOS),
2114         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x022e, "Dell     ", STAC_DELL_BIOS),
2115         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x022f, "Dell Inspiron 1525", STAC_DELL_BIOS),
2116         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x0242, "Dell     ", STAC_DELL_BIOS),
2117         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x0243, "Dell     ", STAC_DELL_BIOS),
2118         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x02ff, "Dell     ", STAC_DELL_BIOS),
2119         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x0209, "Dell XPS 1330", STAC_DELL_BIOS),
2120         /* 965 based 5 stack systems */
2121         SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2300,
2122                            "Intel D965", STAC_D965_5ST),
2123         SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2500,
2124                            "Intel D965", STAC_D965_5ST),
2125         {} /* terminator */
2126 };
2127
2128 static unsigned int ref9205_pin_configs[12] = {
2129         0x40000100, 0x40000100, 0x01016011, 0x01014010,
2130         0x01813122, 0x01a19021, 0x01019020, 0x40000100,
2131         0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
2132 };
2133
2134 /*
2135     STAC 9205 pin configs for
2136     102801F1
2137     102801F2
2138     102801FC
2139     102801FD
2140     10280204
2141     1028021F
2142     10280228 (Dell Vostro 1500)
2143 */
2144 static unsigned int dell_9205_m42_pin_configs[12] = {
2145         0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
2146         0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
2147         0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
2148 };
2149
2150 /*
2151     STAC 9205 pin configs for
2152     102801F9
2153     102801FA
2154     102801FE
2155     102801FF (Dell Precision M4300)
2156     10280206
2157     10280200
2158     10280201
2159 */
2160 static unsigned int dell_9205_m43_pin_configs[12] = {
2161         0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
2162         0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
2163         0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
2164 };
2165
2166 static unsigned int dell_9205_m44_pin_configs[12] = {
2167         0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
2168         0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
2169         0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
2170 };
2171
2172 static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
2173         [STAC_9205_REF] = ref9205_pin_configs,
2174         [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
2175         [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
2176         [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
2177         [STAC_9205_EAPD] = NULL,
2178 };
2179
2180 static const char *stac9205_models[STAC_9205_MODELS] = {
2181         [STAC_9205_AUTO] = "auto",
2182         [STAC_9205_REF] = "ref",
2183         [STAC_9205_DELL_M42] = "dell-m42",
2184         [STAC_9205_DELL_M43] = "dell-m43",
2185         [STAC_9205_DELL_M44] = "dell-m44",
2186         [STAC_9205_EAPD] = "eapd",
2187 };
2188
2189 static struct snd_pci_quirk stac9205_cfg_tbl[] = {
2190         /* SigmaTel reference board */
2191         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2192                       "DFI LanParty", STAC_9205_REF),
2193         SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xfb30,
2194                       "SigmaTel", STAC_9205_REF),
2195         SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2196                       "DFI LanParty", STAC_9205_REF),
2197         /* Dell */
2198         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
2199                       "unknown Dell", STAC_9205_DELL_M42),
2200         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
2201                       "unknown Dell", STAC_9205_DELL_M42),
2202         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
2203                       "Dell Precision", STAC_9205_DELL_M43),
2204         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
2205                       "Dell Precision", STAC_9205_DELL_M43),
2206         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
2207                       "Dell Precision", STAC_9205_DELL_M43),
2208         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
2209                       "unknown Dell", STAC_9205_DELL_M42),
2210         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
2211                       "unknown Dell", STAC_9205_DELL_M42),
2212         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
2213                       "Dell Precision", STAC_9205_DELL_M43),
2214         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
2215                       "Dell Precision M4300", STAC_9205_DELL_M43),
2216         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
2217                       "unknown Dell", STAC_9205_DELL_M42),
2218         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
2219                       "Dell Precision", STAC_9205_DELL_M43),
2220         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
2221                       "Dell Precision", STAC_9205_DELL_M43),
2222         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
2223                       "Dell Precision", STAC_9205_DELL_M43),
2224         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
2225                       "Dell Inspiron", STAC_9205_DELL_M44),
2226         SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0228,
2227                       "Dell Vostro 1500", STAC_9205_DELL_M42),
2228         /* Gateway */
2229         SND_PCI_QUIRK(0x107b, 0x0560, "Gateway T6834c", STAC_9205_EAPD),
2230         SND_PCI_QUIRK(0x107b, 0x0565, "Gateway T1616", STAC_9205_EAPD),
2231         {} /* terminator */
2232 };
2233
2234 static void stac92xx_set_config_regs(struct hda_codec *codec,
2235                                      unsigned int *pincfgs)
2236 {
2237         int i;
2238         struct sigmatel_spec *spec = codec->spec;
2239
2240         if (!pincfgs)
2241                 return;
2242
2243         for (i = 0; i < spec->num_pins; i++)
2244                 if (spec->pin_nids[i] && pincfgs[i])
2245                         snd_hda_codec_set_pincfg(codec, spec->pin_nids[i],
2246                                                  pincfgs[i]);
2247 }
2248
2249 /*
2250  * Analog playback callbacks
2251  */
2252 static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
2253                                       struct hda_codec *codec,
2254                                       struct snd_pcm_substream *substream)
2255 {
2256         struct sigmatel_spec *spec = codec->spec;
2257         if (spec->stream_delay)
2258                 msleep(spec->stream_delay);
2259         return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2260                                              hinfo);
2261 }
2262
2263 static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2264                                          struct hda_codec *codec,
2265                                          unsigned int stream_tag,
2266                                          unsigned int format,
2267                                          struct snd_pcm_substream *substream)
2268 {
2269         struct sigmatel_spec *spec = codec->spec;
2270         return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
2271 }
2272
2273 static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2274                                         struct hda_codec *codec,
2275                                         struct snd_pcm_substream *substream)
2276 {
2277         struct sigmatel_spec *spec = codec->spec;
2278         return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2279 }
2280
2281 /*
2282  * Digital playback callbacks
2283  */
2284 static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2285                                           struct hda_codec *codec,
2286                                           struct snd_pcm_substream *substream)
2287 {
2288         struct sigmatel_spec *spec = codec->spec;
2289         return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2290 }
2291
2292 static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2293                                            struct hda_codec *codec,
2294                                            struct snd_pcm_substream *substream)
2295 {
2296         struct sigmatel_spec *spec = codec->spec;
2297         return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2298 }
2299
2300 static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2301                                          struct hda_codec *codec,
2302                                          unsigned int stream_tag,
2303                                          unsigned int format,
2304                                          struct snd_pcm_substream *substream)
2305 {
2306         struct sigmatel_spec *spec = codec->spec;
2307         return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2308                                              stream_tag, format, substream);
2309 }
2310
2311 static int stac92xx_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2312                                         struct hda_codec *codec,
2313                                         struct snd_pcm_substream *substream)
2314 {
2315         struct sigmatel_spec *spec = codec->spec;
2316         return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2317 }
2318
2319
2320 /*
2321  * Analog capture callbacks
2322  */
2323 static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2324                                         struct hda_codec *codec,
2325                                         unsigned int stream_tag,
2326                                         unsigned int format,
2327                                         struct snd_pcm_substream *substream)
2328 {
2329         struct sigmatel_spec *spec = codec->spec;
2330         hda_nid_t nid = spec->adc_nids[substream->number];
2331
2332         if (spec->powerdown_adcs) {
2333                 msleep(40);
2334                 snd_hda_codec_write(codec, nid, 0,
2335                         AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
2336         }
2337         snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
2338         return 0;
2339 }
2340
2341 static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2342                                         struct hda_codec *codec,
2343                                         struct snd_pcm_substream *substream)
2344 {
2345         struct sigmatel_spec *spec = codec->spec;
2346         hda_nid_t nid = spec->adc_nids[substream->number];
2347
2348         snd_hda_codec_cleanup_stream(codec, nid);
2349         if (spec->powerdown_adcs)
2350                 snd_hda_codec_write(codec, nid, 0,
2351                         AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
2352         return 0;
2353 }
2354
2355 static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
2356         .substreams = 1,
2357         .channels_min = 2,
2358         .channels_max = 2,
2359         /* NID is set in stac92xx_build_pcms */
2360         .ops = {
2361                 .open = stac92xx_dig_playback_pcm_open,
2362                 .close = stac92xx_dig_playback_pcm_close,
2363                 .prepare = stac92xx_dig_playback_pcm_prepare,
2364                 .cleanup = stac92xx_dig_playback_pcm_cleanup
2365         },
2366 };
2367
2368 static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
2369         .substreams = 1,
2370         .channels_min = 2,
2371         .channels_max = 2,
2372         /* NID is set in stac92xx_build_pcms */
2373 };
2374
2375 static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
2376         .substreams = 1,
2377         .channels_min = 2,
2378         .channels_max = 8,
2379         .nid = 0x02, /* NID to query formats and rates */
2380         .ops = {
2381                 .open = stac92xx_playback_pcm_open,
2382                 .prepare = stac92xx_playback_pcm_prepare,
2383                 .cleanup = stac92xx_playback_pcm_cleanup
2384         },
2385 };
2386
2387 static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
2388         .substreams = 1,
2389         .channels_min = 2,
2390         .channels_max = 2,
2391         .nid = 0x06, /* NID to query formats and rates */
2392         .ops = {
2393                 .open = stac92xx_playback_pcm_open,
2394                 .prepare = stac92xx_playback_pcm_prepare,
2395                 .cleanup = stac92xx_playback_pcm_cleanup
2396         },
2397 };
2398
2399 static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
2400         .channels_min = 2,
2401         .channels_max = 2,
2402         /* NID + .substreams is set in stac92xx_build_pcms */
2403         .ops = {
2404                 .prepare = stac92xx_capture_pcm_prepare,
2405                 .cleanup = stac92xx_capture_pcm_cleanup
2406         },
2407 };
2408
2409 static int stac92xx_build_pcms(struct hda_codec *codec)
2410 {
2411         struct sigmatel_spec *spec = codec->spec;
2412         struct hda_pcm *info = spec->pcm_rec;
2413
2414         codec->num_pcms = 1;
2415         codec->pcm_info = info;
2416
2417         info->name = "STAC92xx Analog";
2418         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
2419         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2420                 spec->multiout.dac_nids[0];
2421         info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
2422         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2423         info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
2424
2425         if (spec->alt_switch) {
2426                 codec->num_pcms++;
2427                 info++;
2428                 info->name = "STAC92xx Analog Alt";
2429                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
2430         }
2431
2432         if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2433                 codec->num_pcms++;
2434                 info++;
2435                 info->name = "STAC92xx Digital";
2436                 info->pcm_type = spec->autocfg.dig_out_type[0];
2437                 if (spec->multiout.dig_out_nid) {
2438                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
2439                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2440                 }
2441                 if (spec->dig_in_nid) {
2442                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
2443                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2444                 }
2445         }
2446
2447         return 0;
2448 }
2449
2450 static unsigned int stac92xx_get_default_vref(struct hda_codec *codec,
2451                                         hda_nid_t nid)
2452 {
2453         unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2454         pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
2455         if (pincap & AC_PINCAP_VREF_100)
2456                 return AC_PINCTL_VREF_100;
2457         if (pincap & AC_PINCAP_VREF_80)
2458                 return AC_PINCTL_VREF_80;
2459         if (pincap & AC_PINCAP_VREF_50)
2460                 return AC_PINCTL_VREF_50;
2461         if (pincap & AC_PINCAP_VREF_GRD)
2462                 return AC_PINCTL_VREF_GRD;
2463         return 0;
2464 }
2465
2466 static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
2467
2468 {
2469         snd_hda_codec_write_cache(codec, nid, 0,
2470                                   AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
2471 }
2472
2473 #define stac92xx_hp_switch_info         snd_ctl_boolean_mono_info
2474
2475 static int stac92xx_hp_switch_get(struct snd_kcontrol *kcontrol,
2476                         struct snd_ctl_elem_value *ucontrol)
2477 {
2478         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2479         struct sigmatel_spec *spec = codec->spec;
2480
2481         ucontrol->value.integer.value[0] = !!spec->hp_switch;
2482         return 0;
2483 }
2484
2485 static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid);
2486
2487 static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol,
2488                         struct snd_ctl_elem_value *ucontrol)
2489 {
2490         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2491         struct sigmatel_spec *spec = codec->spec;
2492         int nid = kcontrol->private_value;
2493  
2494         spec->hp_switch = ucontrol->value.integer.value[0] ? nid : 0;
2495
2496         /* check to be sure that the ports are upto date with
2497          * switch changes
2498          */
2499         stac_issue_unsol_event(codec, nid);
2500
2501         return 1;
2502 }
2503
2504 static int stac92xx_dc_bias_info(struct snd_kcontrol *kcontrol,
2505                                 struct snd_ctl_elem_info *uinfo)
2506 {
2507         int i;
2508         static char *texts[] = {
2509                 "Mic In", "Line In", "Line Out"
2510         };
2511
2512         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2513         struct sigmatel_spec *spec = codec->spec;
2514         hda_nid_t nid = kcontrol->private_value;
2515
2516         if (nid == spec->mic_switch || nid == spec->line_switch)
2517                 i = 3;
2518         else
2519                 i = 2;
2520
2521         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2522         uinfo->value.enumerated.items = i;
2523         uinfo->count = 1;
2524         if (uinfo->value.enumerated.item >= i)
2525                 uinfo->value.enumerated.item = i-1;
2526         strcpy(uinfo->value.enumerated.name,
2527                 texts[uinfo->value.enumerated.item]);
2528
2529         return 0;
2530 }
2531
2532 static int stac92xx_dc_bias_get(struct snd_kcontrol *kcontrol,
2533                                 struct snd_ctl_elem_value *ucontrol)
2534 {
2535         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2536         hda_nid_t nid = kcontrol->private_value;
2537         unsigned int vref = stac92xx_vref_get(codec, nid);
2538
2539         if (vref == stac92xx_get_default_vref(codec, nid))
2540                 ucontrol->value.enumerated.item[0] = 0;
2541         else if (vref == AC_PINCTL_VREF_GRD)
2542                 ucontrol->value.enumerated.item[0] = 1;
2543         else if (vref == AC_PINCTL_VREF_HIZ)
2544                 ucontrol->value.enumerated.item[0] = 2;
2545
2546         return 0;
2547 }
2548
2549 static int stac92xx_dc_bias_put(struct snd_kcontrol *kcontrol,
2550                                 struct snd_ctl_elem_value *ucontrol)
2551 {
2552         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2553         unsigned int new_vref = 0;
2554         int error;
2555         hda_nid_t nid = kcontrol->private_value;
2556
2557         if (ucontrol->value.enumerated.item[0] == 0)
2558                 new_vref = stac92xx_get_default_vref(codec, nid);
2559         else if (ucontrol->value.enumerated.item[0] == 1)
2560                 new_vref = AC_PINCTL_VREF_GRD;
2561         else if (ucontrol->value.enumerated.item[0] == 2)
2562                 new_vref = AC_PINCTL_VREF_HIZ;
2563         else
2564                 return 0;
2565
2566         if (new_vref != stac92xx_vref_get(codec, nid)) {
2567                 error = stac92xx_vref_set(codec, nid, new_vref);
2568                 return error;
2569         }
2570
2571         return 0;
2572 }
2573
2574 static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol,
2575                                 struct snd_ctl_elem_info *uinfo)
2576 {
2577         static char *texts[2];
2578         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2579         struct sigmatel_spec *spec = codec->spec;
2580
2581         if (kcontrol->private_value == spec->line_switch)
2582                 texts[0] = "Line In";
2583         else
2584                 texts[0] = "Mic In";
2585         texts[1] = "Line Out";
2586         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2587         uinfo->value.enumerated.items = 2;
2588         uinfo->count = 1;
2589
2590         if (uinfo->value.enumerated.item >= 2)
2591                 uinfo->value.enumerated.item = 1;
2592         strcpy(uinfo->value.enumerated.name,
2593                 texts[uinfo->value.enumerated.item]);
2594
2595         return 0;
2596 }
2597
2598 static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2599 {
2600         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2601         struct sigmatel_spec *spec = codec->spec;
2602         hda_nid_t nid = kcontrol->private_value;
2603         int io_idx = (nid == spec->mic_switch) ? 1 : 0;
2604
2605         ucontrol->value.enumerated.item[0] = spec->io_switch[io_idx];
2606         return 0;
2607 }
2608
2609 static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2610 {
2611         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2612         struct sigmatel_spec *spec = codec->spec;
2613         hda_nid_t nid = kcontrol->private_value;
2614         int io_idx = (nid == spec->mic_switch) ? 1 : 0;
2615         unsigned short val = !!ucontrol->value.enumerated.item[0];
2616
2617         spec->io_switch[io_idx] = val;
2618
2619         if (val)
2620                 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
2621         else {
2622                 unsigned int pinctl = AC_PINCTL_IN_EN;
2623                 if (io_idx) /* set VREF for mic */
2624                         pinctl |= stac92xx_get_default_vref(codec, nid);
2625                 stac92xx_auto_set_pinctl(codec, nid, pinctl);
2626         }
2627
2628         /* check the auto-mute again: we need to mute/unmute the speaker
2629          * appropriately according to the pin direction
2630          */
2631         if (spec->hp_detect)
2632                 stac_issue_unsol_event(codec, nid);
2633
2634         return 1;
2635 }
2636
2637 #define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
2638
2639 static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
2640                 struct snd_ctl_elem_value *ucontrol)
2641 {
2642         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2643         struct sigmatel_spec *spec = codec->spec;
2644
2645         ucontrol->value.integer.value[0] = spec->clfe_swap;
2646         return 0;
2647 }
2648
2649 static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
2650                 struct snd_ctl_elem_value *ucontrol)
2651 {
2652         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2653         struct sigmatel_spec *spec = codec->spec;
2654         hda_nid_t nid = kcontrol->private_value & 0xff;
2655         unsigned int val = !!ucontrol->value.integer.value[0];
2656
2657         if (spec->clfe_swap == val)
2658                 return 0;
2659
2660         spec->clfe_swap = val;
2661
2662         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
2663                 spec->clfe_swap ? 0x4 : 0x0);
2664
2665         return 1;
2666 }
2667
2668 #define STAC_CODEC_HP_SWITCH(xname) \
2669         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2670           .name = xname, \
2671           .index = 0, \
2672           .info = stac92xx_hp_switch_info, \
2673           .get = stac92xx_hp_switch_get, \
2674           .put = stac92xx_hp_switch_put, \
2675         }
2676
2677 #define STAC_CODEC_IO_SWITCH(xname, xpval) \
2678         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2679           .name = xname, \
2680           .index = 0, \
2681           .info = stac92xx_io_switch_info, \
2682           .get = stac92xx_io_switch_get, \
2683           .put = stac92xx_io_switch_put, \
2684           .private_value = xpval, \
2685         }
2686
2687 #define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
2688         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2689           .name = xname, \
2690           .index = 0, \
2691           .info = stac92xx_clfe_switch_info, \
2692           .get = stac92xx_clfe_switch_get, \
2693           .put = stac92xx_clfe_switch_put, \
2694           .private_value = xpval, \
2695         }
2696
2697 enum {
2698         STAC_CTL_WIDGET_VOL,
2699         STAC_CTL_WIDGET_MUTE,
2700         STAC_CTL_WIDGET_MONO_MUX,
2701         STAC_CTL_WIDGET_AMP_MUX,
2702         STAC_CTL_WIDGET_AMP_VOL,
2703         STAC_CTL_WIDGET_HP_SWITCH,
2704         STAC_CTL_WIDGET_IO_SWITCH,
2705         STAC_CTL_WIDGET_CLFE_SWITCH,
2706         STAC_CTL_WIDGET_DC_BIAS
2707 };
2708
2709 static struct snd_kcontrol_new stac92xx_control_templates[] = {
2710         HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2711         HDA_CODEC_MUTE(NULL, 0, 0, 0),
2712         STAC_MONO_MUX,
2713         STAC_AMP_MUX,
2714         STAC_AMP_VOL(NULL, 0, 0, 0, 0),
2715         STAC_CODEC_HP_SWITCH(NULL),
2716         STAC_CODEC_IO_SWITCH(NULL, 0),
2717         STAC_CODEC_CLFE_SWITCH(NULL, 0),
2718         DC_BIAS(NULL, 0, 0),
2719 };
2720
2721 /* add dynamic controls */
2722 static struct snd_kcontrol_new *
2723 stac_control_new(struct sigmatel_spec *spec,
2724                  struct snd_kcontrol_new *ktemp,
2725                  const char *name)
2726 {
2727         struct snd_kcontrol_new *knew;
2728
2729         snd_array_init(&spec->kctls, sizeof(*knew), 32);
2730         knew = snd_array_new(&spec->kctls);
2731         if (!knew)
2732                 return NULL;
2733         *knew = *ktemp;
2734         knew->name = kstrdup(name, GFP_KERNEL);
2735         if (!knew->name) {
2736                 /* roolback */
2737                 memset(knew, 0, sizeof(*knew));
2738                 spec->kctls.alloced--;
2739                 return NULL;
2740         }
2741         return knew;
2742 }
2743
2744 static int stac92xx_add_control_temp(struct sigmatel_spec *spec,
2745                                      struct snd_kcontrol_new *ktemp,
2746                                      int idx, const char *name,
2747                                      unsigned long val)
2748 {
2749         struct snd_kcontrol_new *knew = stac_control_new(spec, ktemp, name);
2750         if (!knew)
2751                 return -ENOMEM;
2752         knew->index = idx;
2753         knew->private_value = val;
2754         return 0;
2755 }
2756
2757 static inline int stac92xx_add_control_idx(struct sigmatel_spec *spec,
2758                                            int type, int idx, const char *name,
2759                                            unsigned long val)
2760 {
2761         return stac92xx_add_control_temp(spec,
2762                                          &stac92xx_control_templates[type],
2763                                          idx, name, val);
2764 }
2765
2766
2767 /* add dynamic controls */
2768 static inline int stac92xx_add_control(struct sigmatel_spec *spec, int type,
2769                                        const char *name, unsigned long val)
2770 {
2771         return stac92xx_add_control_idx(spec, type, 0, name, val);
2772 }
2773
2774 static struct snd_kcontrol_new stac_input_src_temp = {
2775         .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2776         .name = "Input Source",
2777         .info = stac92xx_mux_enum_info,
2778         .get = stac92xx_mux_enum_get,
2779         .put = stac92xx_mux_enum_put,
2780 };
2781
2782 static inline int stac92xx_add_jack_mode_control(struct hda_codec *codec,
2783                                                 hda_nid_t nid, int idx)
2784 {
2785         int def_conf = snd_hda_codec_get_pincfg(codec, nid);
2786         int control = 0;
2787         struct sigmatel_spec *spec = codec->spec;
2788         char name[22];
2789
2790         if (!((get_defcfg_connect(def_conf)) & AC_JACK_PORT_FIXED)) {
2791                 if (stac92xx_get_default_vref(codec, nid) == AC_PINCTL_VREF_GRD
2792                         && nid == spec->line_switch)
2793                         control = STAC_CTL_WIDGET_IO_SWITCH;
2794                 else if (snd_hda_query_pin_caps(codec, nid)
2795                         & (AC_PINCAP_VREF_GRD << AC_PINCAP_VREF_SHIFT))
2796                         control = STAC_CTL_WIDGET_DC_BIAS;
2797                 else if (nid == spec->mic_switch)
2798                         control = STAC_CTL_WIDGET_IO_SWITCH;
2799         }
2800
2801         if (control) {
2802                 strcpy(name, auto_pin_cfg_labels[idx]);
2803                 return stac92xx_add_control(codec->spec, control,
2804                                         strcat(name, " Jack Mode"), nid);
2805         }
2806
2807         return 0;
2808 }
2809
2810 static int stac92xx_add_input_source(struct sigmatel_spec *spec)
2811 {
2812         struct snd_kcontrol_new *knew;
2813         struct hda_input_mux *imux = &spec->private_imux;
2814
2815         if (spec->auto_mic)
2816                 return 0; /* no need for input source */
2817         if (!spec->num_adcs || imux->num_items <= 1)
2818                 return 0; /* no need for input source control */
2819         knew = stac_control_new(spec, &stac_input_src_temp,
2820                                 stac_input_src_temp.name);
2821         if (!knew)
2822                 return -ENOMEM;
2823         knew->count = spec->num_adcs;
2824         return 0;
2825 }
2826
2827 /* check whether the line-input can be used as line-out */
2828 static hda_nid_t check_line_out_switch(struct hda_codec *codec)
2829 {
2830         struct sigmatel_spec *spec = codec->spec;
2831         struct auto_pin_cfg *cfg = &spec->autocfg;
2832         hda_nid_t nid;
2833         unsigned int pincap;
2834
2835         if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2836                 return 0;
2837         nid = cfg->input_pins[AUTO_PIN_LINE];
2838         pincap = snd_hda_query_pin_caps(codec, nid);
2839         if (pincap & AC_PINCAP_OUT)
2840                 return nid;
2841         return 0;
2842 }
2843
2844 /* check whether the mic-input can be used as line-out */
2845 static hda_nid_t check_mic_out_switch(struct hda_codec *codec)
2846 {
2847         struct sigmatel_spec *spec = codec->spec;
2848         struct auto_pin_cfg *cfg = &spec->autocfg;
2849         unsigned int def_conf, pincap;
2850         unsigned int mic_pin;
2851
2852         if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2853                 return 0;
2854         mic_pin = AUTO_PIN_MIC;
2855         for (;;) {
2856                 hda_nid_t nid = cfg->input_pins[mic_pin];
2857                 def_conf = snd_hda_codec_get_pincfg(codec, nid);
2858                 /* some laptops have an internal analog microphone
2859                  * which can't be used as a output */
2860                 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_FIXED) {
2861                         pincap = snd_hda_query_pin_caps(codec, nid);
2862                         if (pincap & AC_PINCAP_OUT)
2863                                 return nid;
2864                 }
2865                 if (mic_pin == AUTO_PIN_MIC)
2866                         mic_pin = AUTO_PIN_FRONT_MIC;
2867                 else
2868                         break;
2869         }
2870         return 0;
2871 }
2872
2873 static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2874 {
2875         int i;
2876         
2877         for (i = 0; i < spec->multiout.num_dacs; i++) {
2878                 if (spec->multiout.dac_nids[i] == nid)
2879                         return 1;
2880         }
2881
2882         return 0;
2883 }
2884
2885 static int check_all_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2886 {
2887         int i;
2888         if (is_in_dac_nids(spec, nid))
2889                 return 1;
2890         for (i = 0; i < spec->autocfg.hp_outs; i++)
2891                 if (spec->hp_dacs[i] == nid)
2892                         return 1;
2893         for (i = 0; i < spec->autocfg.speaker_outs; i++)
2894                 if (spec->speaker_dacs[i] == nid)
2895                         return 1;
2896         return 0;
2897 }
2898
2899 static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid)
2900 {
2901         struct sigmatel_spec *spec = codec->spec;
2902         int j, conn_len;
2903         hda_nid_t conn[HDA_MAX_CONNECTIONS];
2904         unsigned int wcaps, wtype;
2905
2906         conn_len = snd_hda_get_connections(codec, nid, conn,
2907                                            HDA_MAX_CONNECTIONS);
2908         for (j = 0; j < conn_len; j++) {
2909                 wcaps = get_wcaps(codec, conn[j]);
2910                 wtype = get_wcaps_type(wcaps);
2911                 /* we check only analog outputs */
2912                 if (wtype != AC_WID_AUD_OUT || (wcaps & AC_WCAP_DIGITAL))
2913                         continue;
2914                 /* if this route has a free DAC, assign it */
2915                 if (!check_all_dac_nids(spec, conn[j])) {
2916                         if (conn_len > 1) {
2917                                 /* select this DAC in the pin's input mux */
2918                                 snd_hda_codec_write_cache(codec, nid, 0,
2919                                                   AC_VERB_SET_CONNECT_SEL, j);
2920                         }
2921                         return conn[j];
2922                 }
2923         }
2924         /* if all DACs are already assigned, connect to the primary DAC */
2925         if (conn_len > 1) {
2926                 for (j = 0; j < conn_len; j++) {
2927                         if (conn[j] == spec->multiout.dac_nids[0]) {
2928                                 snd_hda_codec_write_cache(codec, nid, 0,
2929                                                   AC_VERB_SET_CONNECT_SEL, j);
2930                                 break;
2931                         }
2932                 }
2933         }
2934         return 0;
2935 }
2936
2937 static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
2938 static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
2939
2940 /*
2941  * Fill in the dac_nids table from the parsed pin configuration
2942  * This function only works when every pin in line_out_pins[]
2943  * contains atleast one DAC in its connection list. Some 92xx
2944  * codecs are not connected directly to a DAC, such as the 9200
2945  * and 9202/925x. For those, dac_nids[] must be hard-coded.
2946  */
2947 static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec)
2948 {
2949         struct sigmatel_spec *spec = codec->spec;
2950         struct auto_pin_cfg *cfg = &spec->autocfg;
2951         int i;
2952         hda_nid_t nid, dac;
2953         
2954         for (i = 0; i < cfg->line_outs; i++) {
2955                 nid = cfg->line_out_pins[i];
2956                 dac = get_unassigned_dac(codec, nid);
2957                 if (!dac) {
2958                         if (spec->multiout.num_dacs > 0) {
2959                                 /* we have already working output pins,
2960                                  * so let's drop the broken ones again
2961                                  */
2962                                 cfg->line_outs = spec->multiout.num_dacs;
2963                                 break;
2964                         }
2965                         /* error out, no available DAC found */
2966                         snd_printk(KERN_ERR
2967                                    "%s: No available DAC for pin 0x%x\n",
2968                                    __func__, nid);
2969                         return -ENODEV;
2970                 }
2971                 add_spec_dacs(spec, dac);
2972         }
2973
2974         for (i = 0; i < cfg->hp_outs; i++) {
2975                 nid = cfg->hp_pins[i];
2976                 dac = get_unassigned_dac(codec, nid);
2977                 if (dac) {
2978                         if (!spec->multiout.hp_nid)
2979                                 spec->multiout.hp_nid = dac;
2980                         else
2981                                 add_spec_extra_dacs(spec, dac);
2982                 }
2983                 spec->hp_dacs[i] = dac;
2984         }
2985
2986         for (i = 0; i < cfg->speaker_outs; i++) {
2987                 nid = cfg->speaker_pins[i];
2988                 dac = get_unassigned_dac(codec, nid);
2989                 if (dac)
2990                         add_spec_extra_dacs(spec, dac);
2991                 spec->speaker_dacs[i] = dac;
2992         }
2993
2994         /* add line-in as output */
2995         nid = check_line_out_switch(codec);
2996         if (nid) {
2997                 dac = get_unassigned_dac(codec, nid);
2998                 if (dac) {
2999                         snd_printdd("STAC: Add line-in 0x%x as output %d\n",
3000                                     nid, cfg->line_outs);
3001                         cfg->line_out_pins[cfg->line_outs] = nid;
3002                         cfg->line_outs++;
3003                         spec->line_switch = nid;
3004                         add_spec_dacs(spec, dac);
3005                 }
3006         }
3007         /* add mic as output */
3008         nid = check_mic_out_switch(codec);
3009         if (nid) {
3010                 dac = get_unassigned_dac(codec, nid);
3011                 if (dac) {
3012                         snd_printdd("STAC: Add mic-in 0x%x as output %d\n",
3013                                     nid, cfg->line_outs);
3014                         cfg->line_out_pins[cfg->line_outs] = nid;
3015                         cfg->line_outs++;
3016                         spec->mic_switch = nid;
3017                         add_spec_dacs(spec, dac);
3018                 }
3019         }
3020
3021         snd_printd("stac92xx: dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
3022                    spec->multiout.num_dacs,
3023                    spec->multiout.dac_nids[0],
3024                    spec->multiout.dac_nids[1],
3025                    spec->multiout.dac_nids[2],
3026                    spec->multiout.dac_nids[3],
3027                    spec->multiout.dac_nids[4]);
3028
3029         return 0;
3030 }
3031
3032 /* create volume control/switch for the given prefx type */
3033 static int create_controls_idx(struct hda_codec *codec, const char *pfx,
3034                                int idx, hda_nid_t nid, int chs)
3035 {
3036         struct sigmatel_spec *spec = codec->spec;
3037         char name[32];
3038         int err;
3039
3040         if (!spec->check_volume_offset) {
3041                 unsigned int caps, step, nums, db_scale;
3042                 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3043                 step = (caps & AC_AMPCAP_STEP_SIZE) >>
3044                         AC_AMPCAP_STEP_SIZE_SHIFT;
3045                 step = (step + 1) * 25; /* in .01dB unit */
3046                 nums = (caps & AC_AMPCAP_NUM_STEPS) >>
3047                         AC_AMPCAP_NUM_STEPS_SHIFT;
3048                 db_scale = nums * step;
3049                 /* if dB scale is over -64dB, and finer enough,
3050                  * let's reduce it to half
3051                  */
3052                 if (db_scale > 6400 && nums >= 0x1f)
3053                         spec->volume_offset = nums / 2;
3054                 spec->check_volume_offset = 1;
3055         }
3056
3057         sprintf(name, "%s Playback Volume", pfx);
3058         err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, idx, name,
3059                 HDA_COMPOSE_AMP_VAL_OFS(nid, chs, 0, HDA_OUTPUT,
3060                                         spec->volume_offset));
3061         if (err < 0)
3062                 return err;
3063         sprintf(name, "%s Playback Switch", pfx);
3064         err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_MUTE, idx, name,
3065                                    HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
3066         if (err < 0)
3067                 return err;
3068         return 0;
3069 }
3070
3071 #define create_controls(codec, pfx, nid, chs) \
3072         create_controls_idx(codec, pfx, 0, nid, chs)
3073
3074 static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
3075 {
3076         if (spec->multiout.num_dacs > 4) {
3077                 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
3078                 return 1;
3079         } else {
3080                 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
3081                 spec->multiout.num_dacs++;
3082         }
3083         return 0;
3084 }
3085
3086 static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
3087 {
3088         int i;
3089         for (i = 0; i < ARRAY_SIZE(spec->multiout.extra_out_nid); i++) {
3090                 if (!spec->multiout.extra_out_nid[i]) {
3091                         spec->multiout.extra_out_nid[i] = nid;
3092                         return 0;
3093                 }
3094         }
3095         printk(KERN_WARNING "stac92xx: No space for extra DAC 0x%x\n", nid);
3096         return 1;
3097 }
3098
3099 /* Create output controls
3100  * The mixer elements are named depending on the given type (AUTO_PIN_XXX_OUT)
3101  */
3102 static int create_multi_out_ctls(struct hda_codec *codec, int num_outs,
3103                                  const hda_nid_t *pins,
3104                                  const hda_nid_t *dac_nids,
3105                                  int type)
3106 {
3107         struct sigmatel_spec *spec = codec->spec;
3108         static const char *chname[4] = {
3109                 "Front", "Surround", NULL /*CLFE*/, "Side"
3110         };
3111         hda_nid_t nid;
3112         int i, err;
3113         unsigned int wid_caps;
3114
3115         for (i = 0; i < num_outs && i < ARRAY_SIZE(chname); i++) {
3116                 if (type == AUTO_PIN_HP_OUT && !spec->hp_detect) {
3117                         wid_caps = get_wcaps(codec, pins[i]);
3118                         if (wid_caps & AC_WCAP_UNSOL_CAP)
3119                                 spec->hp_detect = 1;
3120                 }
3121                 nid = dac_nids[i];
3122                 if (!nid)
3123                         continue;
3124                 if (type != AUTO_PIN_HP_OUT && i == 2) {
3125                         /* Center/LFE */
3126                         err = create_controls(codec, "Center", nid, 1);
3127                         if (err < 0)
3128                                 return err;
3129                         err = create_controls(codec, "LFE", nid, 2);
3130                         if (err < 0)
3131                                 return err;
3132
3133                         wid_caps = get_wcaps(codec, nid);
3134
3135                         if (wid_caps & AC_WCAP_LR_SWAP) {
3136                                 err = stac92xx_add_control(spec,
3137                                         STAC_CTL_WIDGET_CLFE_SWITCH,
3138                                         "Swap Center/LFE Playback Switch", nid);
3139
3140                                 if (err < 0)
3141                                         return err;
3142                         }
3143
3144                 } else {
3145                         const char *name;
3146                         int idx;
3147                         switch (type) {
3148                         case AUTO_PIN_HP_OUT:
3149                                 name = "Headphone";
3150                                 idx = i;
3151                                 break;
3152                         case AUTO_PIN_SPEAKER_OUT:
3153                                 name = "Speaker";
3154                                 idx = i;
3155                                 break;
3156                         default:
3157                                 name = chname[i];
3158                                 idx = 0;
3159                                 break;
3160                         }
3161                         err = create_controls_idx(codec, name, idx, nid, 3);
3162                         if (err < 0)
3163                                 return err;
3164                 }
3165         }
3166         return 0;
3167 }
3168
3169 static int stac92xx_add_capvol_ctls(struct hda_codec *codec, unsigned long vol,
3170                                     unsigned long sw, int idx)
3171 {
3172         int err;
3173         err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_VOL, idx,
3174                                        "Capture Volume", vol);
3175         if (err < 0)
3176                 return err;
3177         err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_MUTE, idx,
3178                                        "Capture Switch", sw);
3179         if (err < 0)
3180                 return err;
3181         return 0;
3182 }
3183
3184 /* add playback controls from the parsed DAC table */
3185 static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
3186                                                const struct auto_pin_cfg *cfg)
3187 {
3188         struct sigmatel_spec *spec = codec->spec;
3189         hda_nid_t nid;
3190         int err;
3191         int idx;
3192
3193         err = create_multi_out_ctls(codec, cfg->line_outs, cfg->line_out_pins,
3194                                     spec->multiout.dac_nids,
3195                                     cfg->line_out_type);
3196         if (err < 0)
3197                 return err;
3198
3199         if (cfg->hp_outs > 1 && cfg->line_out_type == AUTO_PIN_LINE_OUT) {
3200                 err = stac92xx_add_control(spec,
3201                         STAC_CTL_WIDGET_HP_SWITCH,
3202                         "Headphone as Line Out Switch",
3203                         cfg->hp_pins[cfg->hp_outs - 1]);
3204                 if (err < 0)
3205                         return err;
3206         }
3207
3208         for (idx = AUTO_PIN_MIC; idx <= AUTO_PIN_FRONT_LINE; idx++) {
3209                 nid = cfg->input_pins[idx];
3210                 if (nid) {
3211                         err = stac92xx_add_jack_mode_control(codec, nid, idx);
3212                         if (err < 0)
3213                                 return err;
3214                 }
3215         }
3216
3217         return 0;
3218 }
3219
3220 /* add playback controls for Speaker and HP outputs */
3221 static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
3222                                         struct auto_pin_cfg *cfg)
3223 {
3224         struct sigmatel_spec *spec = codec->spec;
3225         int err;
3226
3227         err = create_multi_out_ctls(codec, cfg->hp_outs, cfg->hp_pins,
3228                                     spec->hp_dacs, AUTO_PIN_HP_OUT);
3229         if (err < 0)
3230                 return err;
3231
3232         err = create_multi_out_ctls(codec, cfg->speaker_outs, cfg->speaker_pins,
3233                                     spec->speaker_dacs, AUTO_PIN_SPEAKER_OUT);
3234         if (err < 0)
3235                 return err;
3236
3237         return 0;
3238 }
3239
3240 /* labels for mono mux outputs */
3241 static const char *stac92xx_mono_labels[4] = {
3242         "DAC0", "DAC1", "Mixer", "DAC2"
3243 };
3244
3245 /* create mono mux for mono out on capable codecs */
3246 static int stac92xx_auto_create_mono_output_ctls(struct hda_codec *codec)
3247 {
3248         struct sigmatel_spec *spec = codec->spec;
3249         struct hda_input_mux *mono_mux = &spec->private_mono_mux;
3250         int i, num_cons;
3251         hda_nid_t con_lst[ARRAY_SIZE(stac92xx_mono_labels)];
3252
3253         num_cons = snd_hda_get_connections(codec,
3254                                 spec->mono_nid,
3255                                 con_lst,
3256                                 HDA_MAX_NUM_INPUTS);
3257         if (num_cons <= 0 || num_cons > ARRAY_SIZE(stac92xx_mono_labels))
3258                 return -EINVAL;
3259
3260         for (i = 0; i < num_cons; i++) {
3261                 mono_mux->items[mono_mux->num_items].label =
3262                                         stac92xx_mono_labels[i];
3263                 mono_mux->items[mono_mux->num_items].index = i;
3264                 mono_mux->num_items++;
3265         }
3266
3267         return stac92xx_add_control(spec, STAC_CTL_WIDGET_MONO_MUX,
3268                                 "Mono Mux", spec->mono_nid);
3269 }
3270
3271 /* labels for amp mux outputs */
3272 static const char *stac92xx_amp_labels[3] = {
3273         "Front Microphone", "Microphone", "Line In",
3274 };
3275
3276 /* create amp out controls mux on capable codecs */
3277 static int stac92xx_auto_create_amp_output_ctls(struct hda_codec *codec)
3278 {
3279         struct sigmatel_spec *spec = codec->spec;
3280         struct hda_input_mux *amp_mux = &spec->private_amp_mux;
3281         int i, err;
3282
3283         for (i = 0; i < spec->num_amps; i++) {
3284                 amp_mux->items[amp_mux->num_items].label =
3285                                         stac92xx_amp_labels[i];
3286                 amp_mux->items[amp_mux->num_items].index = i;
3287                 amp_mux->num_items++;
3288         }
3289
3290         if (spec->num_amps > 1) {
3291                 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_AMP_MUX,
3292                         "Amp Selector Capture Switch", 0);
3293                 if (err < 0)
3294                         return err;
3295         }
3296         return stac92xx_add_control(spec, STAC_CTL_WIDGET_AMP_VOL,
3297                 "Amp Capture Volume",
3298                 HDA_COMPOSE_AMP_VAL(spec->amp_nids[0], 3, 0, HDA_INPUT));
3299 }
3300
3301
3302 /* create PC beep volume controls */
3303 static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
3304                                                 hda_nid_t nid)
3305 {
3306         struct sigmatel_spec *spec = codec->spec;
3307         u32 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3308         int err;
3309
3310         /* check for mute support for the the amp */
3311         if ((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT) {
3312                 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3313                         "PC Beep Playback Switch",
3314                         HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3315                         if (err < 0)
3316                                 return err;
3317         }
3318
3319         /* check to see if there is volume support for the amp */
3320         if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3321                 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL,
3322                         "PC Beep Playback Volume",
3323                         HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3324                         if (err < 0)
3325                                 return err;
3326         }
3327         return 0;
3328 }
3329
3330 #ifdef CONFIG_SND_HDA_INPUT_BEEP
3331 #define stac92xx_dig_beep_switch_info snd_ctl_boolean_mono_info
3332
3333 static int stac92xx_dig_beep_switch_get(struct snd_kcontrol *kcontrol,
3334                                         struct snd_ctl_elem_value *ucontrol)
3335 {
3336         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3337         ucontrol->value.integer.value[0] = codec->beep->enabled;
3338         return 0;
3339 }
3340
3341 static int stac92xx_dig_beep_switch_put(struct snd_kcontrol *kcontrol,
3342                                         struct snd_ctl_elem_value *ucontrol)
3343 {
3344         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3345         int enabled = !!ucontrol->value.integer.value[0];
3346         if (codec->beep->enabled != enabled) {
3347                 codec->beep->enabled = enabled;
3348                 return 1;
3349         }
3350         return 0;
3351 }
3352
3353 static struct snd_kcontrol_new stac92xx_dig_beep_ctrl = {
3354         .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3355         .info = stac92xx_dig_beep_switch_info,
3356         .get = stac92xx_dig_beep_switch_get,
3357         .put = stac92xx_dig_beep_switch_put,
3358 };
3359
3360 static int stac92xx_beep_switch_ctl(struct hda_codec *codec)
3361 {
3362         return stac92xx_add_control_temp(codec->spec, &stac92xx_dig_beep_ctrl,
3363                                          0, "PC Beep Playback Switch", 0);
3364 }
3365 #endif
3366
3367 static int stac92xx_auto_create_mux_input_ctls(struct hda_codec *codec)
3368 {
3369         struct sigmatel_spec *spec = codec->spec;
3370         int i, j, err = 0;
3371
3372         for (i = 0; i < spec->num_muxes; i++) {
3373                 hda_nid_t nid;
3374                 unsigned int wcaps;
3375                 unsigned long val;
3376
3377                 nid = spec->mux_nids[i];
3378                 wcaps = get_wcaps(codec, nid);
3379                 if (!(wcaps & AC_WCAP_OUT_AMP))
3380                         continue;
3381
3382                 /* check whether already the same control was created as
3383                  * normal Capture Volume.
3384                  */
3385                 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3386                 for (j = 0; j < spec->num_caps; j++) {
3387                         if (spec->capvols[j] == val)
3388                                 break;
3389                 }
3390                 if (j < spec->num_caps)
3391                         continue;
3392
3393                 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, i,
3394                                                "Mux Capture Volume", val);
3395                 if (err < 0)
3396                         return err;
3397         }
3398         return 0;
3399 };
3400
3401 static const char *stac92xx_spdif_labels[3] = {
3402         "Digital Playback", "Analog Mux 1", "Analog Mux 2",
3403 };
3404
3405 static int stac92xx_auto_create_spdif_mux_ctls(struct hda_codec *codec)
3406 {
3407         struct sigmatel_spec *spec = codec->spec;
3408         struct hda_input_mux *spdif_mux = &spec->private_smux;
3409         const char **labels = spec->spdif_labels;
3410         int i, num_cons;
3411         hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
3412
3413         num_cons = snd_hda_get_connections(codec,
3414                                 spec->smux_nids[0],
3415                                 con_lst,
3416                                 HDA_MAX_NUM_INPUTS);
3417         if (num_cons <= 0)
3418                 return -EINVAL;
3419
3420         if (!labels)
3421                 labels = stac92xx_spdif_labels;
3422
3423         for (i = 0; i < num_cons; i++) {
3424                 spdif_mux->items[spdif_mux->num_items].label = labels[i];
3425                 spdif_mux->items[spdif_mux->num_items].index = i;
3426                 spdif_mux->num_items++;
3427         }
3428
3429         return 0;
3430 }
3431
3432 /* labels for dmic mux inputs */
3433 static const char *stac92xx_dmic_labels[5] = {
3434         "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
3435         "Digital Mic 3", "Digital Mic 4"
3436 };
3437
3438 static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
3439                                 hda_nid_t nid)
3440 {
3441         hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3442         int i, nums;
3443
3444         nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3445         for (i = 0; i < nums; i++)
3446                 if (conn[i] == nid)
3447                         return i;
3448         return -1;
3449 }
3450
3451 /* create a volume assigned to the given pin (only if supported) */
3452 /* return 1 if the volume control is created */
3453 static int create_elem_capture_vol(struct hda_codec *codec, hda_nid_t nid,
3454                                    const char *label, int direction)
3455 {
3456         unsigned int caps, nums;
3457         char name[32];
3458         int err;
3459
3460         if (direction == HDA_OUTPUT)
3461                 caps = AC_WCAP_OUT_AMP;
3462         else
3463                 caps = AC_WCAP_IN_AMP;
3464         if (!(get_wcaps(codec, nid) & caps))
3465                 return 0;
3466         caps = query_amp_caps(codec, nid, direction);
3467         nums = (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT;
3468         if (!nums)
3469                 return 0;
3470         snprintf(name, sizeof(name), "%s Capture Volume", label);
3471         err = stac92xx_add_control(codec->spec, STAC_CTL_WIDGET_VOL, name,
3472                                     HDA_COMPOSE_AMP_VAL(nid, 3, 0, direction));
3473         if (err < 0)
3474                 return err;
3475         return 1;
3476 }
3477
3478 /* create playback/capture controls for input pins on dmic capable codecs */
3479 static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
3480                                                 const struct auto_pin_cfg *cfg)
3481 {
3482         struct sigmatel_spec *spec = codec->spec;
3483         struct hda_input_mux *imux = &spec->private_imux;
3484         struct hda_input_mux *dimux = &spec->private_dimux;
3485         int err, i, active_mics;
3486         unsigned int def_conf;
3487
3488         dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
3489         dimux->items[dimux->num_items].index = 0;
3490         dimux->num_items++;
3491
3492         active_mics = 0;
3493         for (i = 0; i < spec->num_dmics; i++) {
3494                 /* check the validity: sometimes it's a dead vendor-spec node */
3495                 if (get_wcaps_type(get_wcaps(codec, spec->dmic_nids[i]))
3496                     != AC_WID_PIN)
3497                         continue;
3498                 def_conf = snd_hda_codec_get_pincfg(codec, spec->dmic_nids[i]);
3499                 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)
3500                         active_mics++;
3501         }
3502
3503         for (i = 0; i < spec->num_dmics; i++) {
3504                 hda_nid_t nid;
3505                 int index;
3506                 const char *label;
3507
3508                 nid = spec->dmic_nids[i];
3509                 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
3510                         continue;
3511                 def_conf = snd_hda_codec_get_pincfg(codec, nid);
3512                 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
3513                         continue;
3514
3515                 index = get_connection_index(codec, spec->dmux_nids[0], nid);
3516                 if (index < 0)
3517                         continue;
3518
3519                 if (active_mics == 1)
3520                         label = "Digital Mic";
3521                 else
3522                         label = stac92xx_dmic_labels[dimux->num_items];
3523
3524                 err = create_elem_capture_vol(codec, nid, label, HDA_INPUT);
3525                 if (err < 0)
3526                         return err;
3527                 if (!err) {
3528                         err = create_elem_capture_vol(codec, nid, label,
3529                                                       HDA_OUTPUT);
3530                         if (err < 0)
3531                                 return err;
3532                 }
3533
3534                 dimux->items[dimux->num_items].label = label;
3535                 dimux->items[dimux->num_items].index = index;
3536                 dimux->num_items++;
3537                 if (snd_hda_get_bool_hint(codec, "separate_dmux") != 1) {
3538                         imux->items[imux->num_items].label = label;
3539                         imux->items[imux->num_items].index = index;
3540                         imux->num_items++;
3541                 }
3542         }
3543
3544         return 0;
3545 }
3546
3547 static int check_mic_pin(struct hda_codec *codec, hda_nid_t nid,
3548                          hda_nid_t *fixed, hda_nid_t *ext)
3549 {
3550         unsigned int cfg;
3551
3552         if (!nid)
3553                 return 0;
3554         cfg = snd_hda_codec_get_pincfg(codec, nid);
3555         switch (get_defcfg_connect(cfg)) {
3556         case AC_JACK_PORT_FIXED:
3557                 if (*fixed)
3558                         return 1; /* already occupied */
3559                 *fixed = nid;
3560                 break;
3561         case AC_JACK_PORT_COMPLEX:
3562                 if (*ext)
3563                         return 1; /* already occupied */
3564                 *ext = nid;
3565                 break;
3566         }
3567         return 0;
3568 }
3569
3570 static int set_mic_route(struct hda_codec *codec,
3571                          struct sigmatel_mic_route *mic,
3572                          hda_nid_t pin)
3573 {
3574         struct sigmatel_spec *spec = codec->spec;
3575         struct auto_pin_cfg *cfg = &spec->autocfg;
3576         int i;
3577
3578         mic->pin = pin;
3579         for (i = AUTO_PIN_MIC; i <= AUTO_PIN_FRONT_MIC; i++)
3580                 if (pin == cfg->input_pins[i])
3581                         break;
3582         if (i <= AUTO_PIN_FRONT_MIC) {
3583                 /* analog pin */
3584                 mic->dmux_idx = 0;
3585                 i = get_connection_index(codec, spec->mux_nids[0], pin);
3586                 if (i < 0)
3587                         return -1;
3588                 mic->mux_idx = i;
3589         }  else if (spec->dmux_nids) {
3590                 /* digital pin */
3591                 mic->mux_idx = 0;
3592                 i = get_connection_index(codec, spec->dmux_nids[0], pin);
3593                 if (i < 0)
3594                         return -1;
3595                 mic->dmux_idx = i;
3596         }
3597         return 0;
3598 }
3599
3600 /* return non-zero if the device is for automatic mic switch */
3601 static int stac_check_auto_mic(struct hda_codec *codec)
3602 {
3603         struct sigmatel_spec *spec = codec->spec;
3604         struct auto_pin_cfg *cfg = &spec->autocfg;
3605         hda_nid_t fixed, ext;
3606         int i;
3607
3608         for (i = AUTO_PIN_LINE; i < AUTO_PIN_LAST; i++) {
3609                 if (cfg->input_pins[i])
3610                         return 0; /* must be exclusively mics */
3611         }
3612         fixed = ext = 0;
3613         for (i = AUTO_PIN_MIC; i <= AUTO_PIN_FRONT_MIC; i++)
3614                 if (check_mic_pin(codec, cfg->input_pins[i], &fixed, &ext))
3615                         return 0;
3616         for (i = 0; i < spec->num_dmics; i++)
3617                 if (check_mic_pin(codec, spec->dmic_nids[i], &fixed, &ext))
3618                         return 0;
3619         if (!fixed || !ext)
3620                 return 0;
3621         if (!(get_wcaps(codec, ext) & AC_WCAP_UNSOL_CAP))
3622                 return 0; /* no unsol support */
3623         if (set_mic_route(codec, &spec->ext_mic, ext) ||
3624             set_mic_route(codec, &spec->int_mic, fixed))
3625                 return 0; /* something is wrong */
3626         return 1;
3627 }
3628
3629 /* create playback/capture controls for input pins */
3630 static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
3631 {
3632         struct sigmatel_spec *spec = codec->spec;
3633         struct hda_input_mux *imux = &spec->private_imux;
3634         int i, j;
3635
3636         for (i = 0; i < AUTO_PIN_LAST; i++) {
3637                 hda_nid_t nid = cfg->input_pins[i];
3638                 int index, err;
3639
3640                 if (!nid)
3641                         continue;
3642                 index = -1;
3643                 for (j = 0; j < spec->num_muxes; j++) {
3644                         index = get_connection_index(codec, spec->mux_nids[j],
3645                                                      nid);
3646                         if (index >= 0)
3647                                 break;
3648                 }
3649                 if (index < 0)
3650                         continue;
3651
3652                 err = create_elem_capture_vol(codec, nid,
3653                                               auto_pin_cfg_labels[i],
3654                                               HDA_INPUT);
3655                 if (err < 0)
3656                         return err;
3657
3658                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
3659                 imux->items[imux->num_items].index = index;
3660                 imux->num_items++;
3661         }
3662         spec->num_analog_muxes = imux->num_items;
3663
3664         if (imux->num_items) {
3665                 /*
3666                  * Set the current input for the muxes.
3667                  * The STAC9221 has two input muxes with identical source
3668                  * NID lists.  Hopefully this won't get confused.
3669                  */
3670                 for (i = 0; i < spec->num_muxes; i++) {
3671                         snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
3672                                                   AC_VERB_SET_CONNECT_SEL,
3673                                                   imux->items[0].index);
3674                 }
3675         }
3676
3677         return 0;
3678 }
3679
3680 static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
3681 {
3682         struct sigmatel_spec *spec = codec->spec;
3683         int i;
3684
3685         for (i = 0; i < spec->autocfg.line_outs; i++) {
3686                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3687                 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
3688         }
3689 }
3690
3691 static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
3692 {
3693         struct sigmatel_spec *spec = codec->spec;
3694         int i;
3695
3696         for (i = 0; i < spec->autocfg.hp_outs; i++) {
3697                 hda_nid_t pin;
3698                 pin = spec->autocfg.hp_pins[i];
3699                 if (pin) /* connect to front */
3700                         stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
3701         }
3702         for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3703                 hda_nid_t pin;
3704                 pin = spec->autocfg.speaker_pins[i];
3705                 if (pin) /* connect to front */
3706                         stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
3707         }
3708 }
3709
3710 static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out, hda_nid_t dig_in)
3711 {
3712         struct sigmatel_spec *spec = codec->spec;
3713         int hp_swap = 0;
3714         int i, err;
3715
3716         if ((err = snd_hda_parse_pin_def_config(codec,
3717                                                 &spec->autocfg,
3718                                                 spec->dmic_nids)) < 0)
3719                 return err;
3720         if (! spec->autocfg.line_outs)
3721                 return 0; /* can't find valid pin config */
3722
3723         /* If we have no real line-out pin and multiple hp-outs, HPs should
3724          * be set up as multi-channel outputs.
3725          */
3726         if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
3727             spec->autocfg.hp_outs > 1) {
3728                 /* Copy hp_outs to line_outs, backup line_outs in
3729                  * speaker_outs so that the following routines can handle
3730                  * HP pins as primary outputs.
3731                  */
3732                 snd_printdd("stac92xx: Enabling multi-HPs workaround\n");
3733                 memcpy(spec->autocfg.speaker_pins, spec->autocfg.line_out_pins,
3734                        sizeof(spec->autocfg.line_out_pins));
3735                 spec->autocfg.speaker_outs = spec->autocfg.line_outs;
3736                 memcpy(spec->autocfg.line_out_pins, spec->autocfg.hp_pins,
3737                        sizeof(spec->autocfg.hp_pins));
3738                 spec->autocfg.line_outs = spec->autocfg.hp_outs;
3739                 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3740                 spec->autocfg.hp_outs = 0;
3741                 hp_swap = 1;
3742         }
3743         if (spec->autocfg.mono_out_pin) {
3744                 int dir = get_wcaps(codec, spec->autocfg.mono_out_pin) &
3745                         (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
3746                 u32 caps = query_amp_caps(codec,
3747                                 spec->autocfg.mono_out_pin, dir);
3748                 hda_nid_t conn_list[1];
3749
3750                 /* get the mixer node and then the mono mux if it exists */
3751                 if (snd_hda_get_connections(codec,
3752                                 spec->autocfg.mono_out_pin, conn_list, 1) &&
3753                                 snd_hda_get_connections(codec, conn_list[0],
3754                                 conn_list, 1) > 0) {
3755
3756                                 int wcaps = get_wcaps(codec, conn_list[0]);
3757                                 int wid_type = get_wcaps_type(wcaps);
3758                                 /* LR swap check, some stac925x have a mux that
3759                                  * changes the DACs output path instead of the
3760                                  * mono-mux path.
3761                                  */
3762                                 if (wid_type == AC_WID_AUD_SEL &&
3763                                                 !(wcaps & AC_WCAP_LR_SWAP))
3764                                         spec->mono_nid = conn_list[0];
3765                 }
3766                 if (dir) {
3767                         hda_nid_t nid = spec->autocfg.mono_out_pin;
3768
3769                         /* most mono outs have a least a mute/unmute switch */
3770                         dir = (dir & AC_WCAP_OUT_AMP) ? HDA_OUTPUT : HDA_INPUT;
3771                         err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3772                                 "Mono Playback Switch",
3773                                 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
3774                         if (err < 0)
3775                                 return err;
3776                         /* check for volume support for the amp */
3777                         if ((caps & AC_AMPCAP_NUM_STEPS)
3778                                         >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3779                                 err = stac92xx_add_control(spec,
3780                                         STAC_CTL_WIDGET_VOL,
3781                                         "Mono Playback Volume",
3782                                 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
3783                                 if (err < 0)
3784                                         return err;
3785                         }
3786                 }
3787
3788                 stac92xx_auto_set_pinctl(codec, spec->autocfg.mono_out_pin,
3789                                          AC_PINCTL_OUT_EN);
3790         }
3791
3792         if (!spec->multiout.num_dacs) {
3793                 err = stac92xx_auto_fill_dac_nids(codec);
3794                 if (err < 0)
3795                         return err;
3796                 err = stac92xx_auto_create_multi_out_ctls(codec,
3797                                                           &spec->autocfg);
3798                 if (err < 0)
3799                         return err;
3800         }
3801
3802         /* setup analog beep controls */
3803         if (spec->anabeep_nid > 0) {
3804                 err = stac92xx_auto_create_beep_ctls(codec,
3805                         spec->anabeep_nid);
3806                 if (err < 0)
3807