~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Linux/sound/pci/hda/patch_sigmatel.c

Version: ~ [ 2.4.21-47.EL ] ~ [ 2.6.9-67.EL ] ~ [ 2.6.18-128.el5 ] ~ [ 2.6.18-164.el5 ] ~
Architecture: ~ [ i386 ] ~ [ x86_64 ] ~

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