[ALSA] hda: add dig mic support for sigmatel codecs
[firefly-linux-kernel-4.4.55.git] / sound / pci / hda / patch_sigmatel.c
1 /*
2  * Universal Interface for Intel High Definition Audio Codec
3  *
4  * HD audio interface patch for SigmaTel STAC92xx
5  *
6  * Copyright (c) 2005 Embedded Alley Solutions, Inc.
7  * Matt Porter <mporter@embeddedalley.com>
8  *
9  * Based on patch_cmedia.c and patch_realtek.c
10  * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
11  *
12  *  This driver is free software; you can redistribute it and/or modify
13  *  it under the terms of the GNU General Public License as published by
14  *  the Free Software Foundation; either version 2 of the License, or
15  *  (at your option) any later version.
16  *
17  *  This driver is distributed in the hope that it will be useful,
18  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  *  GNU General Public License for more details.
21  *
22  *  You should have received a copy of the GNU General Public License
23  *  along with this program; if not, write to the Free Software
24  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
25  */
26
27 #include <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
37 #define NUM_CONTROL_ALLOC       32
38 #define STAC_HP_EVENT           0x37
39
40 #define STAC_REF                0
41 #define STAC_D945GTP3           1
42 #define STAC_D945GTP5           2
43 #define STAC_MACMINI            3
44 #define STAC_922X_MODELS        4       /* number of 922x models */
45 #define STAC_D965_3ST           4
46 #define STAC_D965_5ST           5
47 #define STAC_927X_MODELS        6       /* number of 927x models */
48
49 struct sigmatel_spec {
50         struct snd_kcontrol_new *mixers[4];
51         unsigned int num_mixers;
52
53         int board_config;
54         unsigned int surr_switch: 1;
55         unsigned int line_switch: 1;
56         unsigned int mic_switch: 1;
57         unsigned int alt_switch: 1;
58         unsigned int hp_detect: 1;
59         unsigned int gpio_mute: 1;
60
61         /* playback */
62         struct hda_multi_out multiout;
63         hda_nid_t dac_nids[5];
64
65         /* capture */
66         hda_nid_t *adc_nids;
67         unsigned int num_adcs;
68         hda_nid_t *mux_nids;
69         unsigned int num_muxes;
70         hda_nid_t *dmic_nids;
71         unsigned int num_dmics;
72         hda_nid_t dmux_nid;
73         hda_nid_t dig_in_nid;
74
75         /* pin widgets */
76         hda_nid_t *pin_nids;
77         unsigned int num_pins;
78         unsigned int *pin_configs;
79         unsigned int *bios_pin_configs;
80
81         /* codec specific stuff */
82         struct hda_verb *init;
83         struct snd_kcontrol_new *mixer;
84
85         /* capture source */
86         struct hda_input_mux *dinput_mux;
87         unsigned int cur_dmux;
88         struct hda_input_mux *input_mux;
89         unsigned int cur_mux[3];
90
91         /* i/o switches */
92         unsigned int io_switch[2];
93
94         struct hda_pcm pcm_rec[2];      /* PCM information */
95
96         /* dynamic controls and input_mux */
97         struct auto_pin_cfg autocfg;
98         unsigned int num_kctl_alloc, num_kctl_used;
99         struct snd_kcontrol_new *kctl_alloc;
100         struct hda_input_mux private_dimux;
101         struct hda_input_mux private_imux;
102 };
103
104 static hda_nid_t stac9200_adc_nids[1] = {
105         0x03,
106 };
107
108 static hda_nid_t stac9200_mux_nids[1] = {
109         0x0c,
110 };
111
112 static hda_nid_t stac9200_dac_nids[1] = {
113         0x02,
114 };
115
116 static hda_nid_t stac922x_adc_nids[2] = {
117         0x06, 0x07,
118 };
119
120 static hda_nid_t stac922x_mux_nids[2] = {
121         0x12, 0x13,
122 };
123
124 static hda_nid_t stac927x_adc_nids[3] = {
125         0x07, 0x08, 0x09
126 };
127
128 static hda_nid_t stac927x_mux_nids[3] = {
129         0x15, 0x16, 0x17
130 };
131
132 static hda_nid_t stac9205_adc_nids[2] = {
133         0x12, 0x13
134 };
135
136 static hda_nid_t stac9205_mux_nids[2] = {
137         0x19, 0x1a
138 };
139
140 static hda_nid_t stac9205_dmic_nids[3] = {
141         0x17, 0x18, 0
142 };
143
144 static hda_nid_t stac9200_pin_nids[8] = {
145         0x08, 0x09, 0x0d, 0x0e, 
146         0x0f, 0x10, 0x11, 0x12,
147 };
148
149 static hda_nid_t stac922x_pin_nids[10] = {
150         0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
151         0x0f, 0x10, 0x11, 0x15, 0x1b,
152 };
153
154 static hda_nid_t stac927x_pin_nids[14] = {
155         0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
156         0x0f, 0x10, 0x11, 0x12, 0x13,
157         0x14, 0x21, 0x22, 0x23,
158 };
159
160 static hda_nid_t stac9205_pin_nids[12] = {
161         0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
162         0x0f, 0x14, 0x16, 0x17, 0x18,
163         0x21, 0x22,
164         
165 };
166
167 static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
168                                    struct snd_ctl_elem_info *uinfo)
169 {
170         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
171         struct sigmatel_spec *spec = codec->spec;
172         return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
173 }
174
175 static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
176                                   struct snd_ctl_elem_value *ucontrol)
177 {
178         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
179         struct sigmatel_spec *spec = codec->spec;
180
181         ucontrol->value.enumerated.item[0] = spec->cur_dmux;
182         return 0;
183 }
184
185 static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
186                                   struct snd_ctl_elem_value *ucontrol)
187 {
188         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
189         struct sigmatel_spec *spec = codec->spec;
190
191         return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
192                                      spec->dmux_nid, &spec->cur_dmux);
193 }
194
195 static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
196 {
197         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
198         struct sigmatel_spec *spec = codec->spec;
199         return snd_hda_input_mux_info(spec->input_mux, uinfo);
200 }
201
202 static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
203 {
204         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
205         struct sigmatel_spec *spec = codec->spec;
206         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
207
208         ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
209         return 0;
210 }
211
212 static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
213 {
214         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
215         struct sigmatel_spec *spec = codec->spec;
216         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
217
218         return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
219                                      spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
220 }
221
222 static struct hda_verb stac9200_core_init[] = {
223         /* set dac0mux for dac converter */
224         { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
225         {}
226 };
227
228 static struct hda_verb stac922x_core_init[] = {
229         /* set master volume and direct control */      
230         { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
231         {}
232 };
233
234 static struct hda_verb d965_core_init[] = {
235         /* set master volume and direct control */      
236         { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
237         /* unmute node 0x1b */
238         { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
239         /* select node 0x03 as DAC */   
240         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
241         {}
242 };
243
244 static struct hda_verb stac927x_core_init[] = {
245         /* set master volume and direct control */      
246         { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
247         {}
248 };
249
250 static struct hda_verb stac9205_core_init[] = {
251         /* set master volume and direct control */      
252         { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
253         {}
254 };
255
256 static struct snd_kcontrol_new stac9200_mixer[] = {
257         HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
258         HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
259         {
260                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
261                 .name = "Input Source",
262                 .count = 1,
263                 .info = stac92xx_mux_enum_info,
264                 .get = stac92xx_mux_enum_get,
265                 .put = stac92xx_mux_enum_put,
266         },
267         HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
268         HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
269         HDA_CODEC_VOLUME("Capture Mux Volume", 0x0c, 0, HDA_OUTPUT),
270         { } /* end */
271 };
272
273 /* This needs to be generated dynamically based on sequence */
274 static struct snd_kcontrol_new stac922x_mixer[] = {
275         {
276                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
277                 .name = "Input Source",
278                 .count = 1,
279                 .info = stac92xx_mux_enum_info,
280                 .get = stac92xx_mux_enum_get,
281                 .put = stac92xx_mux_enum_put,
282         },
283         HDA_CODEC_VOLUME("Capture Volume", 0x17, 0x0, HDA_INPUT),
284         HDA_CODEC_MUTE("Capture Switch", 0x17, 0x0, HDA_INPUT),
285         HDA_CODEC_VOLUME("Mux Capture Volume", 0x12, 0x0, HDA_OUTPUT),
286         { } /* end */
287 };
288
289 /* This needs to be generated dynamically based on sequence */
290 static struct snd_kcontrol_new stac9227_mixer[] = {
291         {
292                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
293                 .name = "Input Source",
294                 .count = 1,
295                 .info = stac92xx_mux_enum_info,
296                 .get = stac92xx_mux_enum_get,
297                 .put = stac92xx_mux_enum_put,
298         },
299         HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
300         HDA_CODEC_MUTE("Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
301         { } /* end */
302 };
303
304 static snd_kcontrol_new_t stac927x_mixer[] = {
305         {
306                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
307                 .name = "Input Source",
308                 .count = 1,
309                 .info = stac92xx_mux_enum_info,
310                 .get = stac92xx_mux_enum_get,
311                 .put = stac92xx_mux_enum_put,
312         },
313         HDA_CODEC_VOLUME("InMux Capture Volume", 0x15, 0x0, HDA_OUTPUT),
314         HDA_CODEC_VOLUME("InVol Capture Volume", 0x18, 0x0, HDA_INPUT),
315         HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
316         { } /* end */
317 };
318
319 static snd_kcontrol_new_t stac9205_mixer[] = {
320         {
321                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
322                 .name = "Digital Input Source",
323                 .count = 1,
324                 .info = stac92xx_dmux_enum_info,
325                 .get = stac92xx_dmux_enum_get,
326                 .put = stac92xx_dmux_enum_put,
327         },
328         {
329                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
330                 .name = "Input Source",
331                 .count = 1,
332                 .info = stac92xx_mux_enum_info,
333                 .get = stac92xx_mux_enum_get,
334                 .put = stac92xx_mux_enum_put,
335         },
336         HDA_CODEC_VOLUME("InMux Capture Volume", 0x19, 0x0, HDA_OUTPUT),
337         HDA_CODEC_VOLUME("InVol Capture Volume", 0x1b, 0x0, HDA_INPUT),
338         HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1d, 0x0, HDA_OUTPUT),
339         { } /* end */
340 };
341
342 static int stac92xx_build_controls(struct hda_codec *codec)
343 {
344         struct sigmatel_spec *spec = codec->spec;
345         int err;
346         int i;
347
348         err = snd_hda_add_new_ctls(codec, spec->mixer);
349         if (err < 0)
350                 return err;
351
352         for (i = 0; i < spec->num_mixers; i++) {
353                 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
354                 if (err < 0)
355                         return err;
356         }
357
358         if (spec->multiout.dig_out_nid) {
359                 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
360                 if (err < 0)
361                         return err;
362         }
363         if (spec->dig_in_nid) {
364                 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
365                 if (err < 0)
366                         return err;
367         }
368         return 0;       
369 }
370
371 static unsigned int ref9200_pin_configs[8] = {
372         0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
373         0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
374 };
375
376 static unsigned int *stac9200_brd_tbl[] = {
377         ref9200_pin_configs,
378 };
379
380 static struct hda_board_config stac9200_cfg_tbl[] = {
381         { .modelname = "ref",
382           .pci_subvendor = PCI_VENDOR_ID_INTEL,
383           .pci_subdevice = 0x2668,      /* DFI LanParty */
384           .config = STAC_REF },
385         /* Dell laptops have BIOS problem */
386         { .pci_subvendor = PCI_VENDOR_ID_DELL, .pci_subdevice = 0x01b5,
387           .config = STAC_REF }, /* Dell Inspiron 630m */
388         { .pci_subvendor = PCI_VENDOR_ID_DELL, .pci_subdevice = 0x01c2,
389           .config = STAC_REF }, /* Dell Latitude D620 */
390         { .pci_subvendor = PCI_VENDOR_ID_DELL, .pci_subdevice = 0x01cb,
391           .config = STAC_REF }, /* Dell Latitude 120L */
392         {} /* terminator */
393 };
394
395 static unsigned int ref922x_pin_configs[10] = {
396         0x01014010, 0x01016011, 0x01012012, 0x0221401f,
397         0x01813122, 0x01011014, 0x01441030, 0x01c41030,
398         0x40000100, 0x40000100,
399 };
400
401 static unsigned int d945gtp3_pin_configs[10] = {
402         0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
403         0x40000100, 0x40000100, 0x40000100, 0x40000100,
404         0x02a19120, 0x40000100,
405 };
406
407 static unsigned int d945gtp5_pin_configs[10] = {
408         0x0221401f, 0x01011012, 0x01813024, 0x01014010,
409         0x01a19021, 0x01016011, 0x01452130, 0x40000100,
410         0x02a19320, 0x40000100,
411 };
412
413 static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
414         [STAC_REF] =    ref922x_pin_configs,
415         [STAC_D945GTP3] = d945gtp3_pin_configs,
416         [STAC_D945GTP5] = d945gtp5_pin_configs,
417         [STAC_MACMINI] = d945gtp5_pin_configs,
418 };
419
420 static struct hda_board_config stac922x_cfg_tbl[] = {
421         { .modelname = "5stack", .config = STAC_D945GTP5 },
422         { .modelname = "3stack", .config = STAC_D945GTP3 },
423         { .modelname = "ref",
424           .pci_subvendor = PCI_VENDOR_ID_INTEL,
425           .pci_subdevice = 0x2668,      /* DFI LanParty */
426           .config = STAC_REF },         /* SigmaTel reference board */
427          /* Intel 945G based systems */
428         { .pci_subvendor = PCI_VENDOR_ID_INTEL,
429           .pci_subdevice = 0x0101,
430           .config = STAC_D945GTP3 },    /* Intel D945GTP - 3 Stack */
431         { .pci_subvendor = PCI_VENDOR_ID_INTEL,
432           .pci_subdevice = 0x0202,
433           .config = STAC_D945GTP3 },    /* Intel D945GNT - 3 Stack */
434         { .pci_subvendor = PCI_VENDOR_ID_INTEL,
435           .pci_subdevice = 0x0606,
436           .config = STAC_D945GTP3 },    /* Intel D945GTP - 3 Stack */
437         { .pci_subvendor = PCI_VENDOR_ID_INTEL,
438           .pci_subdevice = 0x0601,
439           .config = STAC_D945GTP3 },    /* Intel D945GTP - 3 Stack */
440         { .pci_subvendor = PCI_VENDOR_ID_INTEL,
441           .pci_subdevice = 0x0111,
442           .config = STAC_D945GTP3 },    /* Intel D945GZP - 3 Stack */
443         { .pci_subvendor = PCI_VENDOR_ID_INTEL,
444           .pci_subdevice = 0x1115,
445           .config = STAC_D945GTP3 },    /* Intel D945GPM - 3 Stack */
446         { .pci_subvendor = PCI_VENDOR_ID_INTEL,
447           .pci_subdevice = 0x1116,
448           .config = STAC_D945GTP3 },    /* Intel D945GBO - 3 Stack */
449         { .pci_subvendor = PCI_VENDOR_ID_INTEL,
450           .pci_subdevice = 0x1117,
451           .config = STAC_D945GTP3 },    /* Intel D945GPM - 3 Stack */
452         { .pci_subvendor = PCI_VENDOR_ID_INTEL,
453           .pci_subdevice = 0x1118,
454           .config = STAC_D945GTP3 },    /* Intel D945GPM - 3 Stack */
455         { .pci_subvendor = PCI_VENDOR_ID_INTEL,
456           .pci_subdevice = 0x1119,
457           .config = STAC_D945GTP3 },    /* Intel D945GPM - 3 Stack */
458         { .pci_subvendor = PCI_VENDOR_ID_INTEL,
459           .pci_subdevice = 0x8826,
460           .config = STAC_D945GTP3 },    /* Intel D945GPM - 3 Stack */
461         { .pci_subvendor = PCI_VENDOR_ID_INTEL,
462           .pci_subdevice = 0x5049,
463           .config = STAC_D945GTP3 },    /* Intel D945GCZ - 3 Stack */
464         { .pci_subvendor = PCI_VENDOR_ID_INTEL,
465           .pci_subdevice = 0x5055,
466           .config = STAC_D945GTP3 },    /* Intel D945GCZ - 3 Stack */
467         { .pci_subvendor = PCI_VENDOR_ID_INTEL,
468           .pci_subdevice = 0x5048,
469           .config = STAC_D945GTP3 },    /* Intel D945GPB - 3 Stack */
470         { .pci_subvendor = PCI_VENDOR_ID_INTEL,
471           .pci_subdevice = 0x0110,
472           .config = STAC_D945GTP3 },    /* Intel D945GLR - 3 Stack */
473         { .pci_subvendor = PCI_VENDOR_ID_INTEL,
474           .pci_subdevice = 0x0404,
475           .config = STAC_D945GTP5 },    /* Intel D945GTP - 5 Stack */
476         { .pci_subvendor = PCI_VENDOR_ID_INTEL,
477           .pci_subdevice = 0x0303,
478           .config = STAC_D945GTP5 },    /* Intel D945GNT - 5 Stack */
479         { .pci_subvendor = PCI_VENDOR_ID_INTEL,
480           .pci_subdevice = 0x0013,
481           .config = STAC_D945GTP5 },    /* Intel D955XBK - 5 Stack */
482         { .pci_subvendor = PCI_VENDOR_ID_INTEL,
483           .pci_subdevice = 0x0417,
484           .config = STAC_D945GTP5 },    /* Intel D975XBK - 5 Stack */
485           /* Intel 945P based systems */
486         { .pci_subvendor = PCI_VENDOR_ID_INTEL,
487           .pci_subdevice = 0x0b0b,
488           .config = STAC_D945GTP3 },    /* Intel D945PSN - 3 Stack */
489         { .pci_subvendor = PCI_VENDOR_ID_INTEL,
490           .pci_subdevice = 0x0112,
491           .config = STAC_D945GTP3 },    /* Intel D945PLN - 3 Stack */
492         { .pci_subvendor = PCI_VENDOR_ID_INTEL,
493           .pci_subdevice = 0x0d0d,
494           .config = STAC_D945GTP3 },    /* Intel D945PLM - 3 Stack */
495         { .pci_subvendor = PCI_VENDOR_ID_INTEL,
496           .pci_subdevice = 0x0909,
497           .config = STAC_D945GTP3 },    /* Intel D945PAW - 3 Stack */
498         { .pci_subvendor = PCI_VENDOR_ID_INTEL,
499           .pci_subdevice = 0x0505,
500           .config = STAC_D945GTP3 },    /* Intel D945PLM - 3 Stack */
501         { .pci_subvendor = PCI_VENDOR_ID_INTEL,
502           .pci_subdevice = 0x0707,
503           .config = STAC_D945GTP5 },    /* Intel D945PSV - 5 Stack */
504           /* other systems  */
505         { .pci_subvendor = 0x8384,
506           .pci_subdevice = 0x7680,
507           .config = STAC_MACMINI },     /* Apple Mac Mini (early 2006) */
508         {} /* terminator */
509 };
510
511 static unsigned int ref927x_pin_configs[14] = {
512         0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
513         0x01a19040, 0x01011012, 0x01016011, 0x0101201f, 
514         0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
515         0x01c42190, 0x40000100,
516 };
517
518 static unsigned int d965_3st_pin_configs[14] = {
519         0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
520         0x01a19021, 0x01813024, 0x40000100, 0x40000100,
521         0x40000100, 0x40000100, 0x40000100, 0x40000100,
522         0x40000100, 0x40000100
523 };
524
525 static unsigned int d965_5st_pin_configs[14] = {
526         0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
527         0x01a19040, 0x01011012, 0x01016011, 0x40000100,
528         0x40000100, 0x40000100, 0x40000100, 0x01442070,
529         0x40000100, 0x40000100
530 };
531
532 static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
533         [STAC_REF] =    ref927x_pin_configs,
534         [STAC_D965_3ST] = d965_3st_pin_configs,
535         [STAC_D965_5ST] = d965_5st_pin_configs,
536 };
537
538 static struct hda_board_config stac927x_cfg_tbl[] = {
539         { .modelname = "5stack", .config = STAC_D965_5ST },
540         { .modelname = "3stack", .config = STAC_D965_3ST },
541         { .modelname = "ref",
542           .pci_subvendor = PCI_VENDOR_ID_INTEL,
543           .pci_subdevice = 0x2668,      /* DFI LanParty */
544           .config = STAC_REF },         /* SigmaTel reference board */
545          /* Intel 946 based systems */
546         { .pci_subvendor = PCI_VENDOR_ID_INTEL,
547           .pci_subdevice = 0x3d01,
548           .config = STAC_D965_3ST }, /* D946  configuration */
549         { .pci_subvendor = PCI_VENDOR_ID_INTEL,
550           .pci_subdevice = 0xa301,
551           .config = STAC_D965_3ST }, /* Intel D946GZT - 3 stack  */
552         /* 965 based 3 stack systems */
553         { .pci_subvendor = PCI_VENDOR_ID_INTEL,
554           .pci_subdevice = 0x2116,
555           .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
556         { .pci_subvendor = PCI_VENDOR_ID_INTEL,
557           .pci_subdevice = 0x2115,
558           .config = STAC_D965_3ST }, /* Intel DQ965WC - 3 Stack  */
559         { .pci_subvendor = PCI_VENDOR_ID_INTEL,
560           .pci_subdevice = 0x2114,
561           .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
562         { .pci_subvendor = PCI_VENDOR_ID_INTEL,
563           .pci_subdevice = 0x2113,
564           .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
565         { .pci_subvendor = PCI_VENDOR_ID_INTEL,
566           .pci_subdevice = 0x2112,
567           .config = STAC_D965_3ST }, /* Intel DG965MS - 3 Stack  */
568         { .pci_subvendor = PCI_VENDOR_ID_INTEL,
569           .pci_subdevice = 0x2111,
570           .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
571         { .pci_subvendor = PCI_VENDOR_ID_INTEL,
572           .pci_subdevice = 0x2110,
573           .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
574         { .pci_subvendor = PCI_VENDOR_ID_INTEL,
575           .pci_subdevice = 0x2009,
576           .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
577         { .pci_subvendor = PCI_VENDOR_ID_INTEL,
578           .pci_subdevice = 0x2008,
579           .config = STAC_D965_3ST }, /* Intel DQ965GF - 3 Stack  */
580         { .pci_subvendor = PCI_VENDOR_ID_INTEL,
581           .pci_subdevice = 0x2007,
582           .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
583         { .pci_subvendor = PCI_VENDOR_ID_INTEL,
584           .pci_subdevice = 0x2006,
585           .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
586         { .pci_subvendor = PCI_VENDOR_ID_INTEL,
587           .pci_subdevice = 0x2005,
588           .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
589         { .pci_subvendor = PCI_VENDOR_ID_INTEL,
590           .pci_subdevice = 0x2004,
591           .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
592         { .pci_subvendor = PCI_VENDOR_ID_INTEL,
593           .pci_subdevice = 0x2003,
594           .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
595         { .pci_subvendor = PCI_VENDOR_ID_INTEL,
596           .pci_subdevice = 0x2002,
597           .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
598         { .pci_subvendor = PCI_VENDOR_ID_INTEL,
599           .pci_subdevice = 0x2001,
600           .config = STAC_D965_3ST }, /* Intel DQ965GF - 3 Stack */
601         /* 965 based 5 stack systems */
602         { .pci_subvendor = PCI_VENDOR_ID_INTEL,
603           .pci_subdevice = 0x2301,
604           .config = STAC_D965_5ST }, /* Intel DG965 - 5 Stack */
605         { .pci_subvendor = PCI_VENDOR_ID_INTEL,
606           .pci_subdevice = 0x2302,
607           .config = STAC_D965_5ST }, /* Intel DG965 - 5 Stack */
608         { .pci_subvendor = PCI_VENDOR_ID_INTEL,
609           .pci_subdevice = 0x2303,
610           .config = STAC_D965_5ST }, /* Intel DG965 - 5 Stack */
611         { .pci_subvendor = PCI_VENDOR_ID_INTEL,
612           .pci_subdevice = 0x2304,
613           .config = STAC_D965_5ST }, /* Intel DG965 - 5 Stack */
614         { .pci_subvendor = PCI_VENDOR_ID_INTEL,
615           .pci_subdevice = 0x2305,
616           .config = STAC_D965_5ST }, /* Intel DG965 - 5 Stack */
617         { .pci_subvendor = PCI_VENDOR_ID_INTEL,
618           .pci_subdevice = 0x2501,
619           .config = STAC_D965_5ST }, /* Intel DG965MQ - 5 Stack */
620         { .pci_subvendor = PCI_VENDOR_ID_INTEL,
621           .pci_subdevice = 0x2502,
622           .config = STAC_D965_5ST }, /* Intel DG965 - 5 Stack */
623         { .pci_subvendor = PCI_VENDOR_ID_INTEL,
624           .pci_subdevice = 0x2503,
625           .config = STAC_D965_5ST }, /* Intel DG965 - 5 Stack */
626         { .pci_subvendor = PCI_VENDOR_ID_INTEL,
627           .pci_subdevice = 0x2504,
628           .config = STAC_D965_5ST }, /* Intel DQ965GF - 5 Stack */
629         {} /* terminator */
630 };
631
632 static unsigned int ref9205_pin_configs[12] = {
633         0x40000100, 0x40000100, 0x01016011, 0x01014010,
634         0x01813122, 0x01a19021, 0x40000100, 0x40000100,
635         0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
636 };
637
638 static unsigned int *stac9205_brd_tbl[] = {
639         ref9205_pin_configs,
640 };
641
642 static struct hda_board_config stac9205_cfg_tbl[] = {
643         { .modelname = "ref",
644           .pci_subvendor = PCI_VENDOR_ID_INTEL,
645           .pci_subdevice = 0x2668,      /* DFI LanParty */
646           .config = STAC_REF },         /* SigmaTel reference board */
647         {} /* terminator */
648 };
649
650 static int stac92xx_save_bios_config_regs(struct hda_codec *codec)
651 {
652         int i;
653         struct sigmatel_spec *spec = codec->spec;
654         
655         if (! spec->bios_pin_configs) {
656                 spec->bios_pin_configs = kcalloc(spec->num_pins,
657                                                  sizeof(*spec->bios_pin_configs), GFP_KERNEL);
658                 if (! spec->bios_pin_configs)
659                         return -ENOMEM;
660         }
661         
662         for (i = 0; i < spec->num_pins; i++) {
663                 hda_nid_t nid = spec->pin_nids[i];
664                 unsigned int pin_cfg;
665                 
666                 pin_cfg = snd_hda_codec_read(codec, nid, 0, 
667                         AC_VERB_GET_CONFIG_DEFAULT, 0x00);      
668                 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x bios pin config %8.8x\n",
669                                         nid, pin_cfg);
670                 spec->bios_pin_configs[i] = pin_cfg;
671         }
672         
673         return 0;
674 }
675
676 static void stac92xx_set_config_regs(struct hda_codec *codec)
677 {
678         int i;
679         struct sigmatel_spec *spec = codec->spec;
680         unsigned int pin_cfg;
681
682         if (! spec->pin_nids || ! spec->pin_configs)
683                 return;
684
685         for (i = 0; i < spec->num_pins; i++) {
686                 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
687                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
688                                     spec->pin_configs[i] & 0x000000ff);
689                 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
690                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
691                                     (spec->pin_configs[i] & 0x0000ff00) >> 8);
692                 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
693                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
694                                     (spec->pin_configs[i] & 0x00ff0000) >> 16);
695                 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
696                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
697                                     spec->pin_configs[i] >> 24);
698                 pin_cfg = snd_hda_codec_read(codec, spec->pin_nids[i], 0,
699                                              AC_VERB_GET_CONFIG_DEFAULT,
700                                              0x00);     
701                 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x pin config %8.8x\n", spec->pin_nids[i], pin_cfg);
702         }
703 }
704
705 /*
706  * Analog playback callbacks
707  */
708 static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
709                                       struct hda_codec *codec,
710                                       struct snd_pcm_substream *substream)
711 {
712         struct sigmatel_spec *spec = codec->spec;
713         return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
714 }
715
716 static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
717                                          struct hda_codec *codec,
718                                          unsigned int stream_tag,
719                                          unsigned int format,
720                                          struct snd_pcm_substream *substream)
721 {
722         struct sigmatel_spec *spec = codec->spec;
723         return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
724 }
725
726 static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
727                                         struct hda_codec *codec,
728                                         struct snd_pcm_substream *substream)
729 {
730         struct sigmatel_spec *spec = codec->spec;
731         return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
732 }
733
734 /*
735  * Digital playback callbacks
736  */
737 static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
738                                           struct hda_codec *codec,
739                                           struct snd_pcm_substream *substream)
740 {
741         struct sigmatel_spec *spec = codec->spec;
742         return snd_hda_multi_out_dig_open(codec, &spec->multiout);
743 }
744
745 static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
746                                            struct hda_codec *codec,
747                                            struct snd_pcm_substream *substream)
748 {
749         struct sigmatel_spec *spec = codec->spec;
750         return snd_hda_multi_out_dig_close(codec, &spec->multiout);
751 }
752
753
754 /*
755  * Analog capture callbacks
756  */
757 static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
758                                         struct hda_codec *codec,
759                                         unsigned int stream_tag,
760                                         unsigned int format,
761                                         struct snd_pcm_substream *substream)
762 {
763         struct sigmatel_spec *spec = codec->spec;
764
765         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
766                                    stream_tag, 0, format);
767         return 0;
768 }
769
770 static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
771                                         struct hda_codec *codec,
772                                         struct snd_pcm_substream *substream)
773 {
774         struct sigmatel_spec *spec = codec->spec;
775
776         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
777         return 0;
778 }
779
780 static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
781         .substreams = 1,
782         .channels_min = 2,
783         .channels_max = 2,
784         /* NID is set in stac92xx_build_pcms */
785         .ops = {
786                 .open = stac92xx_dig_playback_pcm_open,
787                 .close = stac92xx_dig_playback_pcm_close
788         },
789 };
790
791 static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
792         .substreams = 1,
793         .channels_min = 2,
794         .channels_max = 2,
795         /* NID is set in stac92xx_build_pcms */
796 };
797
798 static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
799         .substreams = 1,
800         .channels_min = 2,
801         .channels_max = 8,
802         .nid = 0x02, /* NID to query formats and rates */
803         .ops = {
804                 .open = stac92xx_playback_pcm_open,
805                 .prepare = stac92xx_playback_pcm_prepare,
806                 .cleanup = stac92xx_playback_pcm_cleanup
807         },
808 };
809
810 static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
811         .substreams = 1,
812         .channels_min = 2,
813         .channels_max = 2,
814         .nid = 0x06, /* NID to query formats and rates */
815         .ops = {
816                 .open = stac92xx_playback_pcm_open,
817                 .prepare = stac92xx_playback_pcm_prepare,
818                 .cleanup = stac92xx_playback_pcm_cleanup
819         },
820 };
821
822 static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
823         .substreams = 2,
824         .channels_min = 2,
825         .channels_max = 2,
826         /* NID is set in stac92xx_build_pcms */
827         .ops = {
828                 .prepare = stac92xx_capture_pcm_prepare,
829                 .cleanup = stac92xx_capture_pcm_cleanup
830         },
831 };
832
833 static int stac92xx_build_pcms(struct hda_codec *codec)
834 {
835         struct sigmatel_spec *spec = codec->spec;
836         struct hda_pcm *info = spec->pcm_rec;
837
838         codec->num_pcms = 1;
839         codec->pcm_info = info;
840
841         info->name = "STAC92xx Analog";
842         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
843         info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
844         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
845
846         if (spec->alt_switch) {
847                 codec->num_pcms++;
848                 info++;
849                 info->name = "STAC92xx Analog Alt";
850                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
851         }
852
853         if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
854                 codec->num_pcms++;
855                 info++;
856                 info->name = "STAC92xx Digital";
857                 if (spec->multiout.dig_out_nid) {
858                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
859                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
860                 }
861                 if (spec->dig_in_nid) {
862                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
863                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
864                 }
865         }
866
867         return 0;
868 }
869
870 static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
871 {
872         unsigned int pincap = snd_hda_param_read(codec, nid,
873                                                  AC_PAR_PIN_CAP);
874         pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
875         if (pincap & AC_PINCAP_VREF_100)
876                 return AC_PINCTL_VREF_100;
877         if (pincap & AC_PINCAP_VREF_80)
878                 return AC_PINCTL_VREF_80;
879         if (pincap & AC_PINCAP_VREF_50)
880                 return AC_PINCTL_VREF_50;
881         if (pincap & AC_PINCAP_VREF_GRD)
882                 return AC_PINCTL_VREF_GRD;
883         return 0;
884 }
885
886 static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
887
888 {
889         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
890 }
891
892 static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
893 {
894         uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
895         uinfo->count = 1;
896         uinfo->value.integer.min = 0;
897         uinfo->value.integer.max = 1;
898         return 0;
899 }
900
901 static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
902 {
903         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
904         struct sigmatel_spec *spec = codec->spec;
905         int io_idx = kcontrol-> private_value & 0xff;
906
907         ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
908         return 0;
909 }
910
911 static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
912 {
913         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
914         struct sigmatel_spec *spec = codec->spec;
915         hda_nid_t nid = kcontrol->private_value >> 8;
916         int io_idx = kcontrol-> private_value & 0xff;
917         unsigned short val = ucontrol->value.integer.value[0];
918
919         spec->io_switch[io_idx] = val;
920
921         if (val)
922                 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
923         else {
924                 unsigned int pinctl = AC_PINCTL_IN_EN;
925                 if (io_idx) /* set VREF for mic */
926                         pinctl |= stac92xx_get_vref(codec, nid);
927                 stac92xx_auto_set_pinctl(codec, nid, pinctl);
928         }
929         return 1;
930 }
931
932 #define STAC_CODEC_IO_SWITCH(xname, xpval) \
933         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
934           .name = xname, \
935           .index = 0, \
936           .info = stac92xx_io_switch_info, \
937           .get = stac92xx_io_switch_get, \
938           .put = stac92xx_io_switch_put, \
939           .private_value = xpval, \
940         }
941
942
943 enum {
944         STAC_CTL_WIDGET_VOL,
945         STAC_CTL_WIDGET_MUTE,
946         STAC_CTL_WIDGET_IO_SWITCH,
947 };
948
949 static struct snd_kcontrol_new stac92xx_control_templates[] = {
950         HDA_CODEC_VOLUME(NULL, 0, 0, 0),
951         HDA_CODEC_MUTE(NULL, 0, 0, 0),
952         STAC_CODEC_IO_SWITCH(NULL, 0),
953 };
954
955 /* add dynamic controls */
956 static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val)
957 {
958         struct snd_kcontrol_new *knew;
959
960         if (spec->num_kctl_used >= spec->num_kctl_alloc) {
961                 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
962
963                 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
964                 if (! knew)
965                         return -ENOMEM;
966                 if (spec->kctl_alloc) {
967                         memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
968                         kfree(spec->kctl_alloc);
969                 }
970                 spec->kctl_alloc = knew;
971                 spec->num_kctl_alloc = num;
972         }
973
974         knew = &spec->kctl_alloc[spec->num_kctl_used];
975         *knew = stac92xx_control_templates[type];
976         knew->name = kstrdup(name, GFP_KERNEL);
977         if (! knew->name)
978                 return -ENOMEM;
979         knew->private_value = val;
980         spec->num_kctl_used++;
981         return 0;
982 }
983
984 /* flag inputs as additional dynamic lineouts */
985 static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
986 {
987         struct sigmatel_spec *spec = codec->spec;
988
989         switch (cfg->line_outs) {
990         case 3:
991                 /* add line-in as side */
992                 if (cfg->input_pins[AUTO_PIN_LINE]) {
993                         cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_LINE];
994                         spec->line_switch = 1;
995                         cfg->line_outs++;
996                 }
997                 break;
998         case 2:
999                 /* add line-in as clfe and mic as side */
1000                 if (cfg->input_pins[AUTO_PIN_LINE]) {
1001                         cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_LINE];
1002                         spec->line_switch = 1;
1003                         cfg->line_outs++;
1004                 }
1005                 if (cfg->input_pins[AUTO_PIN_MIC]) {
1006                         cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_MIC];
1007                         spec->mic_switch = 1;
1008                         cfg->line_outs++;
1009                 }
1010                 break;
1011         case 1:
1012                 /* add line-in as surr and mic as clfe */
1013                 if (cfg->input_pins[AUTO_PIN_LINE]) {
1014                         cfg->line_out_pins[1] = cfg->input_pins[AUTO_PIN_LINE];
1015                         spec->line_switch = 1;
1016                         cfg->line_outs++;
1017                 }
1018                 if (cfg->input_pins[AUTO_PIN_MIC]) {
1019                         cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_MIC];
1020                         spec->mic_switch = 1;
1021                         cfg->line_outs++;
1022                 }
1023                 break;
1024         }
1025
1026         return 0;
1027 }
1028
1029 /*
1030  * XXX The line_out pin widget connection list may not be set to the
1031  * desired DAC nid. This is the case on 927x where ports A and B can
1032  * be routed to several DACs.
1033  *
1034  * This requires an analysis of the line-out/hp pin configuration
1035  * to provide a best fit for pin/DAC configurations that are routable.
1036  * For now, 927x DAC4 is not supported and 927x DAC1 output to ports
1037  * A and B is not supported.
1038  */
1039 /* fill in the dac_nids table from the parsed pin configuration */
1040 static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec,
1041                                        const struct auto_pin_cfg *cfg)
1042 {
1043         struct sigmatel_spec *spec = codec->spec;
1044         hda_nid_t nid;
1045         int i;
1046
1047         /* check the pins hardwired to audio widget */
1048         for (i = 0; i < cfg->line_outs; i++) {
1049                 nid = cfg->line_out_pins[i];
1050                 spec->multiout.dac_nids[i] = snd_hda_codec_read(codec, nid, 0,
1051                                         AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1052         }
1053
1054         spec->multiout.num_dacs = cfg->line_outs;
1055
1056         return 0;
1057 }
1058
1059 /* create volume control/switch for the given prefx type */
1060 static int create_controls(struct sigmatel_spec *spec, const char *pfx, hda_nid_t nid, int chs)
1061 {
1062         char name[32];
1063         int err;
1064
1065         sprintf(name, "%s Playback Volume", pfx);
1066         err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
1067                                    HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1068         if (err < 0)
1069                 return err;
1070         sprintf(name, "%s Playback Switch", pfx);
1071         err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
1072                                    HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1073         if (err < 0)
1074                 return err;
1075         return 0;
1076 }
1077
1078 /* add playback controls from the parsed DAC table */
1079 static int stac92xx_auto_create_multi_out_ctls(struct sigmatel_spec *spec,
1080                                                const struct auto_pin_cfg *cfg)
1081 {
1082         static const char *chname[4] = {
1083                 "Front", "Surround", NULL /*CLFE*/, "Side"
1084         };
1085         hda_nid_t nid;
1086         int i, err;
1087
1088         for (i = 0; i < cfg->line_outs; i++) {
1089                 if (!spec->multiout.dac_nids[i])
1090                         continue;
1091
1092                 nid = spec->multiout.dac_nids[i];
1093
1094                 if (i == 2) {
1095                         /* Center/LFE */
1096                         err = create_controls(spec, "Center", nid, 1);
1097                         if (err < 0)
1098                                 return err;
1099                         err = create_controls(spec, "LFE", nid, 2);
1100                         if (err < 0)
1101                                 return err;
1102                 } else {
1103                         err = create_controls(spec, chname[i], nid, 3);
1104                         if (err < 0)
1105                                 return err;
1106                 }
1107         }
1108
1109         if (spec->line_switch)
1110                 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0)
1111                         return err;
1112
1113         if (spec->mic_switch)
1114                 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0)
1115                         return err;
1116
1117         return 0;
1118 }
1119
1120 static int check_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
1121 {
1122         int i;
1123
1124         for (i = 0; i < spec->multiout.num_dacs; i++) {
1125                 if (spec->multiout.dac_nids[i] == nid)
1126                         return 1;
1127         }
1128         if (spec->multiout.hp_nid == nid)
1129                 return 1;
1130         return 0;
1131 }
1132
1133 static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
1134 {
1135         if (!spec->multiout.hp_nid)
1136                 spec->multiout.hp_nid = nid;
1137         else if (spec->multiout.num_dacs > 4) {
1138                 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
1139                 return 1;
1140         } else {
1141                 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
1142                 spec->multiout.num_dacs++;
1143         }
1144         return 0;
1145 }
1146
1147 /* add playback controls for Speaker and HP outputs */
1148 static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
1149                                         struct auto_pin_cfg *cfg)
1150 {
1151         struct sigmatel_spec *spec = codec->spec;
1152         hda_nid_t nid;
1153         int i, old_num_dacs, err;
1154
1155         old_num_dacs = spec->multiout.num_dacs;
1156         for (i = 0; i < cfg->hp_outs; i++) {
1157                 unsigned int wid_caps = get_wcaps(codec, cfg->hp_pins[i]);
1158                 if (wid_caps & AC_WCAP_UNSOL_CAP)
1159                         spec->hp_detect = 1;
1160                 nid = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
1161                                          AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1162                 if (check_in_dac_nids(spec, nid))
1163                         nid = 0;
1164                 if (! nid)
1165                         continue;
1166                 add_spec_dacs(spec, nid);
1167         }
1168         for (i = 0; i < cfg->speaker_outs; i++) {
1169                 nid = snd_hda_codec_read(codec, cfg->speaker_pins[0], 0,
1170                                          AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1171                 if (check_in_dac_nids(spec, nid))
1172                         nid = 0;
1173                 if (check_in_dac_nids(spec, nid))
1174                         nid = 0;
1175                 if (! nid)
1176                         continue;
1177                 add_spec_dacs(spec, nid);
1178         }
1179
1180         for (i = old_num_dacs; i < spec->multiout.num_dacs; i++) {
1181                 static const char *pfxs[] = {
1182                         "Speaker", "External Speaker", "Speaker2",
1183                 };
1184                 err = create_controls(spec, pfxs[i - old_num_dacs],
1185                                       spec->multiout.dac_nids[i], 3);
1186                 if (err < 0)
1187                         return err;
1188         }
1189         if (spec->multiout.hp_nid) {
1190                 const char *pfx;
1191                 if (old_num_dacs == spec->multiout.num_dacs)
1192                         pfx = "Master";
1193                 else
1194                         pfx = "Headphone";
1195                 err = create_controls(spec, pfx, spec->multiout.hp_nid, 3);
1196                 if (err < 0)
1197                         return err;
1198         }
1199
1200         return 0;
1201 }
1202
1203 /* labels for dmic mux inputs */
1204 const char *stac92xx_dmic_labels[5] = {
1205         "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
1206         "Digital Mic 3", "Digital Mic 4"
1207 };
1208
1209 /* create playback/capture controls for input pins on dmic capable codecs */
1210 static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
1211                                                 const struct auto_pin_cfg *cfg)
1212 {
1213         struct sigmatel_spec *spec = codec->spec;
1214         struct hda_input_mux *dimux = &spec->private_dimux;
1215         hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
1216         int i, j;
1217
1218         dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
1219         dimux->items[dimux->num_items].index = 0;
1220         dimux->num_items++;
1221
1222         for (i = 0; i < spec->num_dmics; i++) {
1223                 int index;
1224                 int num_cons;
1225                 unsigned int def_conf;
1226
1227                 def_conf = snd_hda_codec_read(codec,
1228                                               spec->dmic_nids[i],
1229                                               0,
1230                                               AC_VERB_GET_CONFIG_DEFAULT,
1231                                               0);
1232                 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
1233                         continue;
1234
1235                 num_cons = snd_hda_get_connections(codec,
1236                                 spec->dmux_nid,
1237                                 con_lst,
1238                                 HDA_MAX_NUM_INPUTS);
1239                 for (j = 0; j < num_cons; j++)
1240                         if (con_lst[j] == spec->dmic_nids[i]) {
1241                                 index = j;
1242                                 goto found;
1243                         }
1244                 continue;
1245 found:
1246                 dimux->items[dimux->num_items].label =
1247                         stac92xx_dmic_labels[dimux->num_items];
1248                 dimux->items[dimux->num_items].index = index;
1249                 dimux->num_items++;
1250         }
1251
1252         return 0;
1253 }
1254
1255 /* create playback/capture controls for input pins */
1256 static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
1257 {
1258         struct sigmatel_spec *spec = codec->spec;
1259         struct hda_input_mux *imux = &spec->private_imux;
1260         hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
1261         int i, j, k;
1262
1263         for (i = 0; i < AUTO_PIN_LAST; i++) {
1264                 int index;
1265
1266                 if (!cfg->input_pins[i])
1267                         continue;
1268                 index = -1;
1269                 for (j = 0; j < spec->num_muxes; j++) {
1270                         int num_cons;
1271                         num_cons = snd_hda_get_connections(codec,
1272                                                            spec->mux_nids[j],
1273                                                            con_lst,
1274                                                            HDA_MAX_NUM_INPUTS);
1275                         for (k = 0; k < num_cons; k++)
1276                                 if (con_lst[k] == cfg->input_pins[i]) {
1277                                         index = k;
1278                                         goto found;
1279                                 }
1280                 }
1281                 continue;
1282         found:
1283                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
1284                 imux->items[imux->num_items].index = index;
1285                 imux->num_items++;
1286         }
1287
1288         if (imux->num_items == 1) {
1289                 /*
1290                  * Set the current input for the muxes.
1291                  * The STAC9221 has two input muxes with identical source
1292                  * NID lists.  Hopefully this won't get confused.
1293                  */
1294                 for (i = 0; i < spec->num_muxes; i++) {
1295                         snd_hda_codec_write(codec, spec->mux_nids[i], 0,
1296                                             AC_VERB_SET_CONNECT_SEL,
1297                                             imux->items[0].index);
1298                 }
1299         }
1300
1301         return 0;
1302 }
1303
1304 static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
1305 {
1306         struct sigmatel_spec *spec = codec->spec;
1307         int i;
1308
1309         for (i = 0; i < spec->autocfg.line_outs; i++) {
1310                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
1311                 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
1312         }
1313 }
1314
1315 static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
1316 {
1317         struct sigmatel_spec *spec = codec->spec;
1318         int i;
1319
1320         for (i = 0; i < spec->autocfg.hp_outs; i++) {
1321                 hda_nid_t pin;
1322                 pin = spec->autocfg.hp_pins[i];
1323                 if (pin) /* connect to front */
1324                         stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
1325         }
1326         for (i = 0; i < spec->autocfg.speaker_outs; i++) {
1327                 hda_nid_t pin;
1328                 pin = spec->autocfg.speaker_pins[i];
1329                 if (pin) /* connect to front */
1330                         stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
1331         }
1332 }
1333
1334 static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out, hda_nid_t dig_in)
1335 {
1336         struct sigmatel_spec *spec = codec->spec;
1337         int err;
1338
1339         if ((err = snd_hda_parse_pin_def_config(codec,
1340                                                 &spec->autocfg,
1341                                                 spec->dmic_nids)) < 0)
1342                 return err;
1343         if (! spec->autocfg.line_outs)
1344                 return 0; /* can't find valid pin config */
1345
1346         if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
1347                 return err;
1348         if (spec->multiout.num_dacs == 0)
1349                 if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
1350                         return err;
1351
1352         if ((err = stac92xx_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
1353             (err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg)) < 0 ||
1354             (err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
1355                 return err;
1356
1357         if (spec->num_dmics > 0)
1358                 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
1359                                                 &spec->autocfg)) < 0)
1360                         return err;
1361
1362         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
1363         if (spec->multiout.max_channels > 2)
1364                 spec->surr_switch = 1;
1365
1366         if (spec->autocfg.dig_out_pin)
1367                 spec->multiout.dig_out_nid = dig_out;
1368         if (spec->autocfg.dig_in_pin)
1369                 spec->dig_in_nid = dig_in;
1370
1371         if (spec->kctl_alloc)
1372                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1373
1374         spec->input_mux = &spec->private_imux;
1375         spec->dinput_mux = &spec->private_dimux;
1376
1377         return 1;
1378 }
1379
1380 /* add playback controls for HP output */
1381 static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
1382                                         struct auto_pin_cfg *cfg)
1383 {
1384         struct sigmatel_spec *spec = codec->spec;
1385         hda_nid_t pin = cfg->hp_pins[0];
1386         unsigned int wid_caps;
1387
1388         if (! pin)
1389                 return 0;
1390
1391         wid_caps = get_wcaps(codec, pin);
1392         if (wid_caps & AC_WCAP_UNSOL_CAP)
1393                 spec->hp_detect = 1;
1394
1395         return 0;
1396 }
1397
1398 /* add playback controls for LFE output */
1399 static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
1400                                         struct auto_pin_cfg *cfg)
1401 {
1402         struct sigmatel_spec *spec = codec->spec;
1403         int err;
1404         hda_nid_t lfe_pin = 0x0;
1405         int i;
1406
1407         /*
1408          * search speaker outs and line outs for a mono speaker pin
1409          * with an amp.  If one is found, add LFE controls
1410          * for it.
1411          */
1412         for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
1413                 hda_nid_t pin = spec->autocfg.speaker_pins[i];
1414                 unsigned long wcaps = get_wcaps(codec, pin);
1415                 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
1416                 if (wcaps == AC_WCAP_OUT_AMP)
1417                         /* found a mono speaker with an amp, must be lfe */
1418                         lfe_pin = pin;
1419         }
1420
1421         /* if speaker_outs is 0, then speakers may be in line_outs */
1422         if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
1423                 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
1424                         hda_nid_t pin = spec->autocfg.line_out_pins[i];
1425                         unsigned long cfg;
1426                         cfg = snd_hda_codec_read(codec, pin, 0,
1427                                                  AC_VERB_GET_CONFIG_DEFAULT,
1428                                                  0x00);
1429                         if (get_defcfg_device(cfg) == AC_JACK_SPEAKER) {
1430                                 unsigned long wcaps = get_wcaps(codec, pin);
1431                                 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
1432                                 if (wcaps == AC_WCAP_OUT_AMP)
1433                                         /* found a mono speaker with an amp,
1434                                            must be lfe */
1435                                         lfe_pin = pin;
1436                         }
1437                 }
1438         }
1439
1440         if (lfe_pin) {
1441                 err = create_controls(spec, "LFE", lfe_pin, 1);
1442                 if (err < 0)
1443                         return err;
1444         }
1445
1446         return 0;
1447 }
1448
1449 static int stac9200_parse_auto_config(struct hda_codec *codec)
1450 {
1451         struct sigmatel_spec *spec = codec->spec;
1452         int err;
1453
1454         if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
1455                 return err;
1456
1457         if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
1458                 return err;
1459
1460         if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
1461                 return err;
1462
1463         if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
1464                 return err;
1465
1466         if (spec->autocfg.dig_out_pin)
1467                 spec->multiout.dig_out_nid = 0x05;
1468         if (spec->autocfg.dig_in_pin)
1469                 spec->dig_in_nid = 0x04;
1470
1471         if (spec->kctl_alloc)
1472                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1473
1474         spec->input_mux = &spec->private_imux;
1475         spec->dinput_mux = &spec->private_dimux;
1476
1477         return 1;
1478 }
1479
1480 /*
1481  * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
1482  * funky external mute control using GPIO pins.
1483  */
1484
1485 static void stac922x_gpio_mute(struct hda_codec *codec, int pin, int muted)
1486 {
1487         unsigned int gpiostate, gpiomask, gpiodir;
1488
1489         gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
1490                                        AC_VERB_GET_GPIO_DATA, 0);
1491
1492         if (!muted)
1493                 gpiostate |= (1 << pin);
1494         else
1495                 gpiostate &= ~(1 << pin);
1496
1497         gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
1498                                       AC_VERB_GET_GPIO_MASK, 0);
1499         gpiomask |= (1 << pin);
1500
1501         gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
1502                                      AC_VERB_GET_GPIO_DIRECTION, 0);
1503         gpiodir |= (1 << pin);
1504
1505         /* AppleHDA seems to do this -- WTF is this verb?? */
1506         snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
1507
1508         snd_hda_codec_write(codec, codec->afg, 0,
1509                             AC_VERB_SET_GPIO_MASK, gpiomask);
1510         snd_hda_codec_write(codec, codec->afg, 0,
1511                             AC_VERB_SET_GPIO_DIRECTION, gpiodir);
1512
1513         msleep(1);
1514
1515         snd_hda_codec_write(codec, codec->afg, 0,
1516                             AC_VERB_SET_GPIO_DATA, gpiostate);
1517 }
1518
1519 static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
1520                               unsigned int event)
1521 {
1522         if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP)
1523                 snd_hda_codec_write(codec, nid, 0,
1524                                     AC_VERB_SET_UNSOLICITED_ENABLE,
1525                                     (AC_USRSP_EN | event));
1526 }
1527
1528 static int stac92xx_init(struct hda_codec *codec)
1529 {
1530         struct sigmatel_spec *spec = codec->spec;
1531         struct auto_pin_cfg *cfg = &spec->autocfg;
1532         int i;
1533
1534         snd_hda_sequence_write(codec, spec->init);
1535
1536         /* set up pins */
1537         if (spec->hp_detect) {
1538                 /* Enable unsolicited responses on the HP widget */
1539                 for (i = 0; i < cfg->hp_outs; i++)
1540                         enable_pin_detect(codec, cfg->hp_pins[i],
1541                                           STAC_HP_EVENT);
1542                 stac92xx_auto_init_hp_out(codec);
1543                 /* fake event to set up pins */
1544                 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
1545         } else {
1546                 stac92xx_auto_init_multi_out(codec);
1547                 stac92xx_auto_init_hp_out(codec);
1548         }
1549         for (i = 0; i < AUTO_PIN_LAST; i++) {
1550                 hda_nid_t nid = cfg->input_pins[i];
1551                 if (nid) {
1552                         unsigned int pinctl = AC_PINCTL_IN_EN;
1553                         if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC)
1554                                 pinctl |= stac92xx_get_vref(codec, nid);
1555                         stac92xx_auto_set_pinctl(codec, nid, pinctl);
1556                 }
1557         }
1558         if (spec->num_dmics > 0)
1559                 for (i = 0; i < spec->num_dmics; i++)
1560                         stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
1561                                                  AC_PINCTL_IN_EN);
1562
1563         if (cfg->dig_out_pin)
1564                 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
1565                                          AC_PINCTL_OUT_EN);
1566         if (cfg->dig_in_pin)
1567                 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
1568                                          AC_PINCTL_IN_EN);
1569
1570         if (spec->gpio_mute) {
1571                 stac922x_gpio_mute(codec, 0, 0);
1572                 stac922x_gpio_mute(codec, 1, 0);
1573         }
1574
1575         return 0;
1576 }
1577
1578 static void stac92xx_free(struct hda_codec *codec)
1579 {
1580         struct sigmatel_spec *spec = codec->spec;
1581         int i;
1582
1583         if (! spec)
1584                 return;
1585
1586         if (spec->kctl_alloc) {
1587                 for (i = 0; i < spec->num_kctl_used; i++)
1588                         kfree(spec->kctl_alloc[i].name);
1589                 kfree(spec->kctl_alloc);
1590         }
1591
1592         if (spec->bios_pin_configs)
1593                 kfree(spec->bios_pin_configs);
1594
1595         kfree(spec);
1596 }
1597
1598 static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
1599                                 unsigned int flag)
1600 {
1601         unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
1602                         0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
1603         if (flag == AC_PINCTL_OUT_EN && (pin_ctl & AC_PINCTL_IN_EN))
1604                 return;
1605         snd_hda_codec_write(codec, nid, 0,
1606                         AC_VERB_SET_PIN_WIDGET_CONTROL,
1607                         pin_ctl | flag);
1608 }
1609
1610 static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
1611                                   unsigned int flag)
1612 {
1613         unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
1614                         0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
1615         snd_hda_codec_write(codec, nid, 0,
1616                         AC_VERB_SET_PIN_WIDGET_CONTROL,
1617                         pin_ctl & ~flag);
1618 }
1619
1620 static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
1621 {
1622         if (!nid)
1623                 return 0;
1624         if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
1625             & (1 << 31))
1626                 return 1;
1627         return 0;
1628 }
1629
1630 static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res)
1631 {
1632         struct sigmatel_spec *spec = codec->spec;
1633         struct auto_pin_cfg *cfg = &spec->autocfg;
1634         int i, presence;
1635
1636         presence = 0;
1637         for (i = 0; i < cfg->hp_outs; i++) {
1638                 presence = get_pin_presence(codec, cfg->hp_pins[i]);
1639                 if (presence)
1640                         break;
1641         }
1642
1643         if (presence) {
1644                 /* disable lineouts, enable hp */
1645                 for (i = 0; i < cfg->line_outs; i++)
1646                         stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
1647                                                 AC_PINCTL_OUT_EN);
1648                 for (i = 0; i < cfg->speaker_outs; i++)
1649                         stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
1650                                                 AC_PINCTL_OUT_EN);
1651         } else {
1652                 /* enable lineouts, disable hp */
1653                 for (i = 0; i < cfg->line_outs; i++)
1654                         stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
1655                                                 AC_PINCTL_OUT_EN);
1656                 for (i = 0; i < cfg->speaker_outs; i++)
1657                         stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
1658                                                 AC_PINCTL_OUT_EN);
1659         }
1660
1661
1662 static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
1663 {
1664         switch (res >> 26) {
1665         case STAC_HP_EVENT:
1666                 stac92xx_hp_detect(codec, res);
1667                 break;
1668         }
1669 }
1670
1671 #ifdef CONFIG_PM
1672 static int stac92xx_resume(struct hda_codec *codec)
1673 {
1674         struct sigmatel_spec *spec = codec->spec;
1675         int i;
1676
1677         stac92xx_init(codec);
1678         stac92xx_set_config_regs(codec);
1679         for (i = 0; i < spec->num_mixers; i++)
1680                 snd_hda_resume_ctls(codec, spec->mixers[i]);
1681         if (spec->multiout.dig_out_nid)
1682                 snd_hda_resume_spdif_out(codec);
1683         if (spec->dig_in_nid)
1684                 snd_hda_resume_spdif_in(codec);
1685
1686         return 0;
1687 }
1688 #endif
1689
1690 static struct hda_codec_ops stac92xx_patch_ops = {
1691         .build_controls = stac92xx_build_controls,
1692         .build_pcms = stac92xx_build_pcms,
1693         .init = stac92xx_init,
1694         .free = stac92xx_free,
1695         .unsol_event = stac92xx_unsol_event,
1696 #ifdef CONFIG_PM
1697         .resume = stac92xx_resume,
1698 #endif
1699 };
1700
1701 static int patch_stac9200(struct hda_codec *codec)
1702 {
1703         struct sigmatel_spec *spec;
1704         int err;
1705
1706         spec  = kzalloc(sizeof(*spec), GFP_KERNEL);
1707         if (spec == NULL)
1708                 return -ENOMEM;
1709
1710         codec->spec = spec;
1711         spec->num_pins = 8;
1712         spec->pin_nids = stac9200_pin_nids;
1713         spec->board_config = snd_hda_check_board_config(codec, stac9200_cfg_tbl);
1714         if (spec->board_config < 0) {
1715                 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
1716                 err = stac92xx_save_bios_config_regs(codec);
1717                 if (err < 0) {
1718                         stac92xx_free(codec);
1719                         return err;
1720                 }
1721                 spec->pin_configs = spec->bios_pin_configs;
1722         } else {
1723                 spec->pin_configs = stac9200_brd_tbl[spec->board_config];
1724                 stac92xx_set_config_regs(codec);
1725         }
1726
1727         spec->multiout.max_channels = 2;
1728         spec->multiout.num_dacs = 1;
1729         spec->multiout.dac_nids = stac9200_dac_nids;
1730         spec->adc_nids = stac9200_adc_nids;
1731         spec->mux_nids = stac9200_mux_nids;
1732         spec->num_muxes = 1;
1733         spec->num_dmics = 0;
1734
1735         spec->init = stac9200_core_init;
1736         spec->mixer = stac9200_mixer;
1737
1738         err = stac9200_parse_auto_config(codec);
1739         if (err < 0) {
1740                 stac92xx_free(codec);
1741                 return err;
1742         }
1743
1744         codec->patch_ops = stac92xx_patch_ops;
1745
1746         return 0;
1747 }
1748
1749 static int patch_stac922x(struct hda_codec *codec)
1750 {
1751         struct sigmatel_spec *spec;
1752         int err;
1753
1754         spec  = kzalloc(sizeof(*spec), GFP_KERNEL);
1755         if (spec == NULL)
1756                 return -ENOMEM;
1757
1758         codec->spec = spec;
1759         spec->num_pins = 10;
1760         spec->pin_nids = stac922x_pin_nids;
1761         spec->board_config = snd_hda_check_board_config(codec, stac922x_cfg_tbl);
1762         if (spec->board_config < 0) {
1763                 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
1764                         "using BIOS defaults\n");
1765                 err = stac92xx_save_bios_config_regs(codec);
1766                 if (err < 0) {
1767                         stac92xx_free(codec);
1768                         return err;
1769                 }
1770                 spec->pin_configs = spec->bios_pin_configs;
1771         } else if (stac922x_brd_tbl[spec->board_config] != NULL) {
1772                 spec->pin_configs = stac922x_brd_tbl[spec->board_config];
1773                 stac92xx_set_config_regs(codec);
1774         }
1775
1776         spec->adc_nids = stac922x_adc_nids;
1777         spec->mux_nids = stac922x_mux_nids;
1778         spec->num_muxes = 2;
1779         spec->num_dmics = 0;
1780
1781         spec->init = stac922x_core_init;
1782         spec->mixer = stac922x_mixer;
1783
1784         spec->multiout.dac_nids = spec->dac_nids;
1785         
1786         err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
1787         if (err < 0) {
1788                 stac92xx_free(codec);
1789                 return err;
1790         }
1791
1792         if (spec->board_config == STAC_MACMINI)
1793                 spec->gpio_mute = 1;
1794
1795         codec->patch_ops = stac92xx_patch_ops;
1796
1797         return 0;
1798 }
1799
1800 static int patch_stac927x(struct hda_codec *codec)
1801 {
1802         struct sigmatel_spec *spec;
1803         int err;
1804
1805         spec  = kzalloc(sizeof(*spec), GFP_KERNEL);
1806         if (spec == NULL)
1807                 return -ENOMEM;
1808
1809         codec->spec = spec;
1810         spec->num_pins = 14;
1811         spec->pin_nids = stac927x_pin_nids;
1812         spec->board_config = snd_hda_check_board_config(codec, stac927x_cfg_tbl);
1813         if (spec->board_config < 0) {
1814                 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC927x, using BIOS defaults\n");
1815                 err = stac92xx_save_bios_config_regs(codec);
1816                 if (err < 0) {
1817                         stac92xx_free(codec);
1818                         return err;
1819                 }
1820                 spec->pin_configs = spec->bios_pin_configs;
1821         } else if (stac927x_brd_tbl[spec->board_config] != NULL) {
1822                 spec->pin_configs = stac927x_brd_tbl[spec->board_config];
1823                 stac92xx_set_config_regs(codec);
1824         }
1825
1826         switch (spec->board_config) {
1827         case STAC_D965_3ST:
1828                 spec->adc_nids = stac927x_adc_nids;
1829                 spec->mux_nids = stac927x_mux_nids;
1830                 spec->num_muxes = 3;
1831                 spec->num_dmics = 0;
1832                 spec->init = d965_core_init;
1833                 spec->mixer = stac9227_mixer;
1834                 break;
1835         case STAC_D965_5ST:
1836                 spec->adc_nids = stac927x_adc_nids;
1837                 spec->mux_nids = stac927x_mux_nids;
1838                 spec->num_muxes = 3;
1839                 spec->num_dmics = 0;
1840                 spec->init = d965_core_init;
1841                 spec->mixer = stac9227_mixer;
1842                 break;
1843         default:
1844                 spec->adc_nids = stac927x_adc_nids;
1845                 spec->mux_nids = stac927x_mux_nids;
1846                 spec->num_muxes = 3;
1847                 spec->num_dmics = 0;
1848                 spec->init = stac927x_core_init;
1849                 spec->mixer = stac927x_mixer;
1850         }
1851
1852         spec->multiout.dac_nids = spec->dac_nids;
1853
1854         err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
1855         if (err < 0) {
1856                 stac92xx_free(codec);
1857                 return err;
1858         }
1859
1860         codec->patch_ops = stac92xx_patch_ops;
1861
1862         return 0;
1863 }
1864
1865 static int patch_stac9205(struct hda_codec *codec)
1866 {
1867         struct sigmatel_spec *spec;
1868         int err;
1869
1870         spec  = kzalloc(sizeof(*spec), GFP_KERNEL);
1871         if (spec == NULL)
1872                 return -ENOMEM;
1873
1874         codec->spec = spec;
1875         spec->num_pins = 14;
1876         spec->pin_nids = stac9205_pin_nids;
1877         spec->board_config = snd_hda_check_board_config(codec, stac9205_cfg_tbl);
1878         if (spec->board_config < 0) {
1879                 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
1880                 err = stac92xx_save_bios_config_regs(codec);
1881                 if (err < 0) {
1882                         stac92xx_free(codec);
1883                         return err;
1884                 }
1885                 spec->pin_configs = spec->bios_pin_configs;
1886         } else {
1887                 spec->pin_configs = stac9205_brd_tbl[spec->board_config];
1888                 stac92xx_set_config_regs(codec);
1889         }
1890
1891         spec->adc_nids = stac9205_adc_nids;
1892         spec->mux_nids = stac9205_mux_nids;
1893         spec->num_muxes = 2;
1894         spec->dmic_nids = stac9205_dmic_nids;
1895         spec->num_dmics = 2;
1896         spec->dmux_nid = 0x1d;
1897
1898         spec->init = stac9205_core_init;
1899         spec->mixer = stac9205_mixer;
1900
1901         spec->multiout.dac_nids = spec->dac_nids;
1902
1903         err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
1904         if (err < 0) {
1905                 stac92xx_free(codec);
1906                 return err;
1907         }
1908
1909         codec->patch_ops = stac92xx_patch_ops;
1910
1911         return 0;
1912 }
1913
1914 /*
1915  * STAC9872 hack
1916  */
1917
1918 /* static config for Sony VAIO FE550G and Sony VAIO AR */
1919 static hda_nid_t vaio_dacs[] = { 0x2 };
1920 #define VAIO_HP_DAC     0x5
1921 static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
1922 static hda_nid_t vaio_mux_nids[] = { 0x15 };
1923
1924 static struct hda_input_mux vaio_mux = {
1925         .num_items = 2,
1926         .items = {
1927                 /* { "HP", 0x0 }, */
1928                 { "Line", 0x1 },
1929                 { "Mic", 0x2 },
1930                 { "PCM", 0x3 },
1931         }
1932 };
1933
1934 static struct hda_verb vaio_init[] = {
1935         {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
1936         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
1937         {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
1938         {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
1939         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
1940         {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */
1941         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
1942         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
1943         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
1944         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
1945         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
1946         {}
1947 };
1948
1949 static struct hda_verb vaio_ar_init[] = {
1950         {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
1951         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
1952         {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
1953         {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
1954 /*      {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },*/ /* Optical Out */
1955         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
1956         {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */
1957         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
1958         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
1959 /*      {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},*/ /* Optical Out */
1960         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
1961         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
1962         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
1963         {}
1964 };
1965
1966 /* bind volumes of both NID 0x02 and 0x05 */
1967 static int vaio_master_vol_put(struct snd_kcontrol *kcontrol,
1968                                struct snd_ctl_elem_value *ucontrol)
1969 {
1970         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1971         long *valp = ucontrol->value.integer.value;
1972         int change;
1973
1974         change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
1975                                           0x7f, valp[0] & 0x7f);
1976         change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
1977                                            0x7f, valp[1] & 0x7f);
1978         snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
1979                                  0x7f, valp[0] & 0x7f);
1980         snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
1981                                  0x7f, valp[1] & 0x7f);
1982         return change;
1983 }
1984
1985 /* bind volumes of both NID 0x02 and 0x05 */
1986 static int vaio_master_sw_put(struct snd_kcontrol *kcontrol,
1987                               struct snd_ctl_elem_value *ucontrol)
1988 {
1989         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1990         long *valp = ucontrol->value.integer.value;
1991         int change;
1992
1993         change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
1994                                           0x80, (valp[0] ? 0 : 0x80));
1995         change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
1996                                            0x80, (valp[1] ? 0 : 0x80));
1997         snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
1998                                  0x80, (valp[0] ? 0 : 0x80));
1999         snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
2000                                  0x80, (valp[1] ? 0 : 0x80));
2001         return change;
2002 }
2003
2004 static struct snd_kcontrol_new vaio_mixer[] = {
2005         {
2006                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2007                 .name = "Master Playback Volume",
2008                 .info = snd_hda_mixer_amp_volume_info,
2009                 .get = snd_hda_mixer_amp_volume_get,
2010                 .put = vaio_master_vol_put,
2011                 .tlv = { .c = snd_hda_mixer_amp_tlv },
2012                 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2013         },
2014         {
2015                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2016                 .name = "Master Playback Switch",
2017                 .info = snd_hda_mixer_amp_switch_info,
2018                 .get = snd_hda_mixer_amp_switch_get,
2019                 .put = vaio_master_sw_put,
2020                 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2021         },
2022         /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
2023         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
2024         HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
2025         {
2026                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2027                 .name = "Capture Source",
2028                 .count = 1,
2029                 .info = stac92xx_mux_enum_info,
2030                 .get = stac92xx_mux_enum_get,
2031                 .put = stac92xx_mux_enum_put,
2032         },
2033         {}
2034 };
2035
2036 static struct snd_kcontrol_new vaio_ar_mixer[] = {
2037         {
2038                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2039                 .name = "Master Playback Volume",
2040                 .info = snd_hda_mixer_amp_volume_info,
2041                 .get = snd_hda_mixer_amp_volume_get,
2042                 .put = vaio_master_vol_put,
2043                 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2044         },
2045         {
2046                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2047                 .name = "Master Playback Switch",
2048                 .info = snd_hda_mixer_amp_switch_info,
2049                 .get = snd_hda_mixer_amp_switch_get,
2050                 .put = vaio_master_sw_put,
2051                 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2052         },
2053         /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
2054         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
2055         HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
2056         /*HDA_CODEC_MUTE("Optical Out Switch", 0x10, 0, HDA_OUTPUT),
2057         HDA_CODEC_VOLUME("Optical Out Volume", 0x10, 0, HDA_OUTPUT),*/
2058         {
2059                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2060                 .name = "Capture Source",
2061                 .count = 1,
2062                 .info = stac92xx_mux_enum_info,
2063                 .get = stac92xx_mux_enum_get,
2064                 .put = stac92xx_mux_enum_put,
2065         },
2066         {}
2067 };
2068
2069 static struct hda_codec_ops stac9872_patch_ops = {
2070         .build_controls = stac92xx_build_controls,
2071         .build_pcms = stac92xx_build_pcms,
2072         .init = stac92xx_init,
2073         .free = stac92xx_free,
2074 #ifdef CONFIG_PM
2075         .resume = stac92xx_resume,
2076 #endif
2077 };
2078
2079 enum { /* FE and SZ series. id=0x83847661 and subsys=0x104D0700 or 104D1000. */
2080        CXD9872RD_VAIO,
2081        /* Unknown. id=0x83847662 and subsys=0x104D1200 or 104D1000. */
2082        STAC9872AK_VAIO, 
2083        /* Unknown. id=0x83847661 and subsys=0x104D1200. */
2084        STAC9872K_VAIO,
2085        /* AR Series. id=0x83847664 and subsys=104D1300 */
2086        CXD9872AKD_VAIO 
2087      };
2088
2089 static struct hda_board_config stac9872_cfg_tbl[] = {
2090         { .modelname = "vaio", .config = CXD9872RD_VAIO },
2091         { .modelname = "vaio-ar", .config = CXD9872AKD_VAIO },
2092         { .pci_subvendor = 0x104d, .pci_subdevice = 0x81e6,
2093           .config = CXD9872RD_VAIO },
2094         { .pci_subvendor = 0x104d, .pci_subdevice = 0x81ef,
2095           .config = CXD9872RD_VAIO },
2096         { .pci_subvendor = 0x104d, .pci_subdevice = 0x81fd,
2097           .config = CXD9872AKD_VAIO },
2098         {}
2099 };
2100
2101 static int patch_stac9872(struct hda_codec *codec)
2102 {
2103         struct sigmatel_spec *spec;
2104         int board_config;
2105
2106         board_config = snd_hda_check_board_config(codec, stac9872_cfg_tbl);
2107         if (board_config < 0)
2108                 /* unknown config, let generic-parser do its job... */
2109                 return snd_hda_parse_generic_codec(codec);
2110         
2111         spec  = kzalloc(sizeof(*spec), GFP_KERNEL);
2112         if (spec == NULL)
2113                 return -ENOMEM;
2114
2115         codec->spec = spec;
2116         switch (board_config) {
2117         case CXD9872RD_VAIO:
2118         case STAC9872AK_VAIO:
2119         case STAC9872K_VAIO:
2120                 spec->mixer = vaio_mixer;
2121                 spec->init = vaio_init;
2122                 spec->multiout.max_channels = 2;
2123                 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
2124                 spec->multiout.dac_nids = vaio_dacs;
2125                 spec->multiout.hp_nid = VAIO_HP_DAC;
2126                 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
2127                 spec->adc_nids = vaio_adcs;
2128                 spec->input_mux = &vaio_mux;
2129                 spec->mux_nids = vaio_mux_nids;
2130                 break;
2131         
2132         case CXD9872AKD_VAIO:
2133                 spec->mixer = vaio_ar_mixer;
2134                 spec->init = vaio_ar_init;
2135                 spec->multiout.max_channels = 2;
2136                 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
2137                 spec->multiout.dac_nids = vaio_dacs;
2138                 spec->multiout.hp_nid = VAIO_HP_DAC;
2139                 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
2140                 spec->adc_nids = vaio_adcs;
2141                 spec->input_mux = &vaio_mux;
2142                 spec->mux_nids = vaio_mux_nids;
2143                 break;
2144         }
2145
2146         codec->patch_ops = stac9872_patch_ops;
2147         return 0;
2148 }
2149
2150
2151 /*
2152  * patch entries
2153  */
2154 struct hda_codec_preset snd_hda_preset_sigmatel[] = {
2155         { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
2156         { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
2157         { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
2158         { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
2159         { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
2160         { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
2161         { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
2162         { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
2163         { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
2164         { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
2165         { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
2166         { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
2167         { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
2168         { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
2169         { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
2170         { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
2171         { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
2172         { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
2173         { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
2174         { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
2175         { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
2176         { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
2177         { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
2178         /* The following does not take into account .id=0x83847661 when subsys =
2179          * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
2180          * currently not fully supported.
2181          */
2182         { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
2183         { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
2184         { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
2185         { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
2186         { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
2187         { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
2188         { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
2189         { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
2190         { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
2191         { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
2192         { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
2193         {} /* terminator */
2194 };