Pull altix-ce1.0-asic into release branch
[linux-2.6] / 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 #define STAC_UNSOL_ENABLE       (AC_USRSP_EN | STAC_HP_EVENT)
40
41 #define STAC_REF                0
42 #define STAC_D945GTP3           1
43 #define STAC_D945GTP5           2
44
45 struct sigmatel_spec {
46         struct snd_kcontrol_new *mixers[4];
47         unsigned int num_mixers;
48
49         int board_config;
50         unsigned int surr_switch: 1;
51         unsigned int line_switch: 1;
52         unsigned int mic_switch: 1;
53         unsigned int alt_switch: 1;
54
55         /* playback */
56         struct hda_multi_out multiout;
57         hda_nid_t dac_nids[5];
58
59         /* capture */
60         hda_nid_t *adc_nids;
61         unsigned int num_adcs;
62         hda_nid_t *mux_nids;
63         unsigned int num_muxes;
64         hda_nid_t dig_in_nid;
65
66         /* pin widgets */
67         hda_nid_t *pin_nids;
68         unsigned int num_pins;
69         unsigned int *pin_configs;
70
71         /* codec specific stuff */
72         struct hda_verb *init;
73         struct snd_kcontrol_new *mixer;
74
75         /* capture source */
76         struct hda_input_mux *input_mux;
77         unsigned int cur_mux[3];
78
79         /* i/o switches */
80         unsigned int io_switch[2];
81
82         struct hda_pcm pcm_rec[2];      /* PCM information */
83
84         /* dynamic controls and input_mux */
85         struct auto_pin_cfg autocfg;
86         unsigned int num_kctl_alloc, num_kctl_used;
87         struct snd_kcontrol_new *kctl_alloc;
88         struct hda_input_mux private_imux;
89 };
90
91 static hda_nid_t stac9200_adc_nids[1] = {
92         0x03,
93 };
94
95 static hda_nid_t stac9200_mux_nids[1] = {
96         0x0c,
97 };
98
99 static hda_nid_t stac9200_dac_nids[1] = {
100         0x02,
101 };
102
103 static hda_nid_t stac922x_adc_nids[2] = {
104         0x06, 0x07,
105 };
106
107 static hda_nid_t stac922x_mux_nids[2] = {
108         0x12, 0x13,
109 };
110
111 static hda_nid_t stac927x_adc_nids[3] = {
112         0x07, 0x08, 0x09
113 };
114
115 static hda_nid_t stac927x_mux_nids[3] = {
116         0x15, 0x16, 0x17
117 };
118
119 static hda_nid_t stac9200_pin_nids[8] = {
120         0x08, 0x09, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12,
121 };
122
123 static hda_nid_t stac922x_pin_nids[10] = {
124         0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
125         0x0f, 0x10, 0x11, 0x15, 0x1b,
126 };
127
128 static hda_nid_t stac927x_pin_nids[14] = {
129         0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
130         0x0f, 0x10, 0x11, 0x12, 0x13,
131         0x14, 0x21, 0x22, 0x23,
132 };
133
134 static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
135 {
136         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
137         struct sigmatel_spec *spec = codec->spec;
138         return snd_hda_input_mux_info(spec->input_mux, uinfo);
139 }
140
141 static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
142 {
143         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
144         struct sigmatel_spec *spec = codec->spec;
145         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
146
147         ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
148         return 0;
149 }
150
151 static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
152 {
153         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
154         struct sigmatel_spec *spec = codec->spec;
155         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
156
157         return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
158                                      spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
159 }
160
161 static struct hda_verb stac9200_core_init[] = {
162         /* set dac0mux for dac converter */
163         { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
164         {}
165 };
166
167 static struct hda_verb stac922x_core_init[] = {
168         /* set master volume and direct control */      
169         { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
170         {}
171 };
172
173 static struct hda_verb stac927x_core_init[] = {
174         /* set master volume and direct control */      
175         { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
176         {}
177 };
178
179 static struct snd_kcontrol_new stac9200_mixer[] = {
180         HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
181         HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
182         {
183                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
184                 .name = "Input Source",
185                 .count = 1,
186                 .info = stac92xx_mux_enum_info,
187                 .get = stac92xx_mux_enum_get,
188                 .put = stac92xx_mux_enum_put,
189         },
190         HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
191         HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
192         HDA_CODEC_VOLUME("Capture Mux Volume", 0x0c, 0, HDA_OUTPUT),
193         { } /* end */
194 };
195
196 /* This needs to be generated dynamically based on sequence */
197 static struct snd_kcontrol_new stac922x_mixer[] = {
198         {
199                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
200                 .name = "Input Source",
201                 .count = 1,
202                 .info = stac92xx_mux_enum_info,
203                 .get = stac92xx_mux_enum_get,
204                 .put = stac92xx_mux_enum_put,
205         },
206         HDA_CODEC_VOLUME("Capture Volume", 0x17, 0x0, HDA_INPUT),
207         HDA_CODEC_MUTE("Capture Switch", 0x17, 0x0, HDA_INPUT),
208         HDA_CODEC_VOLUME("Mux Capture Volume", 0x12, 0x0, HDA_OUTPUT),
209         { } /* end */
210 };
211
212 static snd_kcontrol_new_t stac927x_mixer[] = {
213         {
214                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
215                 .name = "Input Source",
216                 .count = 1,
217                 .info = stac92xx_mux_enum_info,
218                 .get = stac92xx_mux_enum_get,
219                 .put = stac92xx_mux_enum_put,
220         },
221         HDA_CODEC_VOLUME("InMux Capture Volume", 0x15, 0x0, HDA_OUTPUT),
222         HDA_CODEC_VOLUME("InVol Capture Volume", 0x18, 0x0, HDA_INPUT),
223         HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
224         { } /* end */
225 };
226
227 static int stac92xx_build_controls(struct hda_codec *codec)
228 {
229         struct sigmatel_spec *spec = codec->spec;
230         int err;
231         int i;
232
233         err = snd_hda_add_new_ctls(codec, spec->mixer);
234         if (err < 0)
235                 return err;
236
237         for (i = 0; i < spec->num_mixers; i++) {
238                 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
239                 if (err < 0)
240                         return err;
241         }
242
243         if (spec->multiout.dig_out_nid) {
244                 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
245                 if (err < 0)
246                         return err;
247         }
248         if (spec->dig_in_nid) {
249                 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
250                 if (err < 0)
251                         return err;
252         }
253         return 0;       
254 }
255
256 static unsigned int ref9200_pin_configs[8] = {
257         0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
258         0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
259 };
260
261 static unsigned int *stac9200_brd_tbl[] = {
262         ref9200_pin_configs,
263 };
264
265 static struct hda_board_config stac9200_cfg_tbl[] = {
266         { .modelname = "ref",
267           .pci_subvendor = PCI_VENDOR_ID_INTEL,
268           .pci_subdevice = 0x2668,      /* DFI LanParty */
269           .config = STAC_REF },
270         {} /* terminator */
271 };
272
273 static unsigned int ref922x_pin_configs[10] = {
274         0x01014010, 0x01016011, 0x01012012, 0x0221401f,
275         0x01813122, 0x01011014, 0x01441030, 0x01c41030,
276         0x40000100, 0x40000100,
277 };
278
279 static unsigned int d945gtp3_pin_configs[10] = {
280         0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
281         0x40000100, 0x40000100, 0x40000100, 0x40000100,
282         0x02a19120, 0x40000100,
283 };
284
285 static unsigned int d945gtp5_pin_configs[10] = {
286         0x0221401f, 0x01011012, 0x01813024, 0x01014010,
287         0x01a19021, 0x01016011, 0x01452130, 0x40000100,
288         0x02a19320, 0x40000100,
289 };
290
291 static unsigned int *stac922x_brd_tbl[] = {
292         ref922x_pin_configs,
293         d945gtp3_pin_configs,
294         d945gtp5_pin_configs,
295 };
296
297 static struct hda_board_config stac922x_cfg_tbl[] = {
298         { .modelname = "ref",
299           .pci_subvendor = PCI_VENDOR_ID_INTEL,
300           .pci_subdevice = 0x2668,      /* DFI LanParty */
301           .config = STAC_REF },         /* SigmaTel reference board */
302         { .pci_subvendor = PCI_VENDOR_ID_INTEL,
303           .pci_subdevice = 0x0101,
304           .config = STAC_D945GTP3 },    /* Intel D945GTP - 3 Stack */
305         { .pci_subvendor = PCI_VENDOR_ID_INTEL,
306           .pci_subdevice = 0x0404,
307           .config = STAC_D945GTP5 },    /* Intel D945GTP - 5 Stack */
308         { .pci_subvendor = PCI_VENDOR_ID_INTEL,
309           .pci_subdevice = 0x0303,
310           .config = STAC_D945GTP5 },    /* Intel D945GNT - 5 Stack */
311         { .pci_subvendor = PCI_VENDOR_ID_INTEL,
312           .pci_subdevice = 0x0013,
313           .config = STAC_D945GTP5 },    /* Intel D955XBK - 5 Stack */
314         { .pci_subvendor = PCI_VENDOR_ID_INTEL,
315           .pci_subdevice = 0x0417,
316           .config = STAC_D945GTP5 },    /* Intel D975XBK - 5 Stack */
317         {} /* terminator */
318 };
319
320 static unsigned int ref927x_pin_configs[14] = {
321         0x01813122, 0x01a19021, 0x01014010, 0x01016011,
322         0x01012012, 0x01011014, 0x40000100, 0x40000100, 
323         0x40000100, 0x40000100, 0x40000100, 0x01441030,
324         0x01c41030, 0x40000100,
325 };
326
327 static unsigned int *stac927x_brd_tbl[] = {
328         ref927x_pin_configs,
329 };
330
331 static struct hda_board_config stac927x_cfg_tbl[] = {
332         { .modelname = "ref",
333           .pci_subvendor = PCI_VENDOR_ID_INTEL,
334           .pci_subdevice = 0x2668,      /* DFI LanParty */
335           .config = STAC_REF },         /* SigmaTel reference board */
336         {} /* terminator */
337 };
338
339 static void stac92xx_set_config_regs(struct hda_codec *codec)
340 {
341         int i;
342         struct sigmatel_spec *spec = codec->spec;
343         unsigned int pin_cfg;
344
345         for (i=0; i < spec->num_pins; i++) {
346                 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
347                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
348                                     spec->pin_configs[i] & 0x000000ff);
349                 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
350                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
351                                     (spec->pin_configs[i] & 0x0000ff00) >> 8);
352                 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
353                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
354                                     (spec->pin_configs[i] & 0x00ff0000) >> 16);
355                 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
356                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
357                                     spec->pin_configs[i] >> 24);
358                 pin_cfg = snd_hda_codec_read(codec, spec->pin_nids[i], 0,
359                                              AC_VERB_GET_CONFIG_DEFAULT,
360                                              0x00);     
361                 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x pin config %8.8x\n", spec->pin_nids[i], pin_cfg);
362         }
363 }
364
365 /*
366  * Analog playback callbacks
367  */
368 static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
369                                       struct hda_codec *codec,
370                                       struct snd_pcm_substream *substream)
371 {
372         struct sigmatel_spec *spec = codec->spec;
373         return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
374 }
375
376 static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
377                                          struct hda_codec *codec,
378                                          unsigned int stream_tag,
379                                          unsigned int format,
380                                          struct snd_pcm_substream *substream)
381 {
382         struct sigmatel_spec *spec = codec->spec;
383         return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
384 }
385
386 static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
387                                         struct hda_codec *codec,
388                                         struct snd_pcm_substream *substream)
389 {
390         struct sigmatel_spec *spec = codec->spec;
391         return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
392 }
393
394 /*
395  * Digital playback callbacks
396  */
397 static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
398                                           struct hda_codec *codec,
399                                           struct snd_pcm_substream *substream)
400 {
401         struct sigmatel_spec *spec = codec->spec;
402         return snd_hda_multi_out_dig_open(codec, &spec->multiout);
403 }
404
405 static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
406                                            struct hda_codec *codec,
407                                            struct snd_pcm_substream *substream)
408 {
409         struct sigmatel_spec *spec = codec->spec;
410         return snd_hda_multi_out_dig_close(codec, &spec->multiout);
411 }
412
413
414 /*
415  * Analog capture callbacks
416  */
417 static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
418                                         struct hda_codec *codec,
419                                         unsigned int stream_tag,
420                                         unsigned int format,
421                                         struct snd_pcm_substream *substream)
422 {
423         struct sigmatel_spec *spec = codec->spec;
424
425         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
426                                    stream_tag, 0, format);
427         return 0;
428 }
429
430 static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
431                                         struct hda_codec *codec,
432                                         struct snd_pcm_substream *substream)
433 {
434         struct sigmatel_spec *spec = codec->spec;
435
436         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
437         return 0;
438 }
439
440 static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
441         .substreams = 1,
442         .channels_min = 2,
443         .channels_max = 2,
444         /* NID is set in stac92xx_build_pcms */
445         .ops = {
446                 .open = stac92xx_dig_playback_pcm_open,
447                 .close = stac92xx_dig_playback_pcm_close
448         },
449 };
450
451 static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
452         .substreams = 1,
453         .channels_min = 2,
454         .channels_max = 2,
455         /* NID is set in stac92xx_build_pcms */
456 };
457
458 static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
459         .substreams = 1,
460         .channels_min = 2,
461         .channels_max = 8,
462         .nid = 0x02, /* NID to query formats and rates */
463         .ops = {
464                 .open = stac92xx_playback_pcm_open,
465                 .prepare = stac92xx_playback_pcm_prepare,
466                 .cleanup = stac92xx_playback_pcm_cleanup
467         },
468 };
469
470 static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
471         .substreams = 1,
472         .channels_min = 2,
473         .channels_max = 2,
474         .nid = 0x06, /* NID to query formats and rates */
475         .ops = {
476                 .open = stac92xx_playback_pcm_open,
477                 .prepare = stac92xx_playback_pcm_prepare,
478                 .cleanup = stac92xx_playback_pcm_cleanup
479         },
480 };
481
482 static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
483         .substreams = 2,
484         .channels_min = 2,
485         .channels_max = 2,
486         /* NID is set in stac92xx_build_pcms */
487         .ops = {
488                 .prepare = stac92xx_capture_pcm_prepare,
489                 .cleanup = stac92xx_capture_pcm_cleanup
490         },
491 };
492
493 static int stac92xx_build_pcms(struct hda_codec *codec)
494 {
495         struct sigmatel_spec *spec = codec->spec;
496         struct hda_pcm *info = spec->pcm_rec;
497
498         codec->num_pcms = 1;
499         codec->pcm_info = info;
500
501         info->name = "STAC92xx Analog";
502         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
503         info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
504         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
505
506         if (spec->alt_switch) {
507                 codec->num_pcms++;
508                 info++;
509                 info->name = "STAC92xx Analog Alt";
510                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
511         }
512
513         if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
514                 codec->num_pcms++;
515                 info++;
516                 info->name = "STAC92xx Digital";
517                 if (spec->multiout.dig_out_nid) {
518                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
519                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
520                 }
521                 if (spec->dig_in_nid) {
522                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
523                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
524                 }
525         }
526
527         return 0;
528 }
529
530 static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
531
532 {
533         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
534 }
535
536 static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
537 {
538         uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
539         uinfo->count = 1;
540         uinfo->value.integer.min = 0;
541         uinfo->value.integer.max = 1;
542         return 0;
543 }
544
545 static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
546 {
547         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
548         struct sigmatel_spec *spec = codec->spec;
549         int io_idx = kcontrol-> private_value & 0xff;
550
551         ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
552         return 0;
553 }
554
555 static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
556 {
557         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
558         struct sigmatel_spec *spec = codec->spec;
559         hda_nid_t nid = kcontrol->private_value >> 8;
560         int io_idx = kcontrol-> private_value & 0xff;
561         unsigned short val = ucontrol->value.integer.value[0];
562
563         spec->io_switch[io_idx] = val;
564
565         if (val)
566                 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
567         else
568                 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_IN_EN);
569
570         return 1;
571 }
572
573 #define STAC_CODEC_IO_SWITCH(xname, xpval) \
574         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
575           .name = xname, \
576           .index = 0, \
577           .info = stac92xx_io_switch_info, \
578           .get = stac92xx_io_switch_get, \
579           .put = stac92xx_io_switch_put, \
580           .private_value = xpval, \
581         }
582
583
584 enum {
585         STAC_CTL_WIDGET_VOL,
586         STAC_CTL_WIDGET_MUTE,
587         STAC_CTL_WIDGET_IO_SWITCH,
588 };
589
590 static struct snd_kcontrol_new stac92xx_control_templates[] = {
591         HDA_CODEC_VOLUME(NULL, 0, 0, 0),
592         HDA_CODEC_MUTE(NULL, 0, 0, 0),
593         STAC_CODEC_IO_SWITCH(NULL, 0),
594 };
595
596 /* add dynamic controls */
597 static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val)
598 {
599         struct snd_kcontrol_new *knew;
600
601         if (spec->num_kctl_used >= spec->num_kctl_alloc) {
602                 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
603
604                 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
605                 if (! knew)
606                         return -ENOMEM;
607                 if (spec->kctl_alloc) {
608                         memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
609                         kfree(spec->kctl_alloc);
610                 }
611                 spec->kctl_alloc = knew;
612                 spec->num_kctl_alloc = num;
613         }
614
615         knew = &spec->kctl_alloc[spec->num_kctl_used];
616         *knew = stac92xx_control_templates[type];
617         knew->name = kstrdup(name, GFP_KERNEL);
618         if (! knew->name)
619                 return -ENOMEM;
620         knew->private_value = val;
621         spec->num_kctl_used++;
622         return 0;
623 }
624
625 /* flag inputs as additional dynamic lineouts */
626 static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
627 {
628         struct sigmatel_spec *spec = codec->spec;
629
630         switch (cfg->line_outs) {
631         case 3:
632                 /* add line-in as side */
633                 if (cfg->input_pins[AUTO_PIN_LINE]) {
634                         cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_LINE];
635                         spec->line_switch = 1;
636                         cfg->line_outs++;
637                 }
638                 break;
639         case 2:
640                 /* add line-in as clfe and mic as side */
641                 if (cfg->input_pins[AUTO_PIN_LINE]) {
642                         cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_LINE];
643                         spec->line_switch = 1;
644                         cfg->line_outs++;
645                 }
646                 if (cfg->input_pins[AUTO_PIN_MIC]) {
647                         cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_MIC];
648                         spec->mic_switch = 1;
649                         cfg->line_outs++;
650                 }
651                 break;
652         case 1:
653                 /* add line-in as surr and mic as clfe */
654                 if (cfg->input_pins[AUTO_PIN_LINE]) {
655                         cfg->line_out_pins[1] = cfg->input_pins[AUTO_PIN_LINE];
656                         spec->line_switch = 1;
657                         cfg->line_outs++;
658                 }
659                 if (cfg->input_pins[AUTO_PIN_MIC]) {
660                         cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_MIC];
661                         spec->mic_switch = 1;
662                         cfg->line_outs++;
663                 }
664                 break;
665         }
666
667         return 0;
668 }
669
670 /*
671  * XXX The line_out pin widget connection list may not be set to the
672  * desired DAC nid. This is the case on 927x where ports A and B can
673  * be routed to several DACs.
674  *
675  * This requires an analysis of the line-out/hp pin configuration
676  * to provide a best fit for pin/DAC configurations that are routable.
677  * For now, 927x DAC4 is not supported and 927x DAC1 output to ports
678  * A and B is not supported.
679  */
680 /* fill in the dac_nids table from the parsed pin configuration */
681 static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
682 {
683         struct sigmatel_spec *spec = codec->spec;
684         hda_nid_t nid;
685         int i;
686
687         /* check the pins hardwired to audio widget */
688         for (i = 0; i < cfg->line_outs; i++) {
689                 nid = cfg->line_out_pins[i];
690                 spec->multiout.dac_nids[i] = snd_hda_codec_read(codec, nid, 0,
691                                         AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
692         }
693
694         if (cfg->line_outs)
695                 spec->multiout.num_dacs = cfg->line_outs;
696         else if (cfg->hp_pin) {
697                 spec->multiout.dac_nids[0] = snd_hda_codec_read(codec, cfg->hp_pin, 0,
698                                         AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
699                 spec->multiout.num_dacs = 1;
700         }
701
702         return 0;
703 }
704
705 /* add playback controls from the parsed DAC table */
706 static int stac92xx_auto_create_multi_out_ctls(struct sigmatel_spec *spec, const struct auto_pin_cfg *cfg)
707 {
708         char name[32];
709         static const char *chname[4] = { "Front", "Surround", NULL /*CLFE*/, "Side" };
710         hda_nid_t nid;
711         int i, err;
712
713         for (i = 0; i < cfg->line_outs; i++) {
714                 if (!spec->multiout.dac_nids[i])
715                         continue;
716
717                 nid = spec->multiout.dac_nids[i];
718
719                 if (i == 2) {
720                         /* Center/LFE */
721                         if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "Center Playback Volume",
722                                                HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT))) < 0)
723                                 return err;
724                         if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "LFE Playback Volume",
725                                                HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT))) < 0)
726                                 return err;
727                         if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "Center Playback Switch",
728                                                HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT))) < 0)
729                                 return err;
730                         if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "LFE Playback Switch",
731                                                HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT))) < 0)
732                                 return err;
733                 } else {
734                         sprintf(name, "%s Playback Volume", chname[i]);
735                         if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
736                                                HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
737                                 return err;
738                         sprintf(name, "%s Playback Switch", chname[i]);
739                         if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
740                                                HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
741                                 return err;
742                 }
743         }
744
745         if (spec->line_switch)
746                 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0)
747                         return err;
748
749         if (spec->mic_switch)
750                 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0)
751                         return err;
752
753         return 0;
754 }
755
756 /* add playback controls for HP output */
757 static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec, struct auto_pin_cfg *cfg)
758 {
759         struct sigmatel_spec *spec = codec->spec;
760         hda_nid_t pin = cfg->hp_pin;
761         hda_nid_t nid;
762         int i, err;
763         unsigned int wid_caps;
764
765         if (! pin)
766                 return 0;
767
768         wid_caps = get_wcaps(codec, pin);
769         if (wid_caps & AC_WCAP_UNSOL_CAP)
770                 /* Enable unsolicited responses on the HP widget */
771                 snd_hda_codec_write(codec, pin, 0,
772                                 AC_VERB_SET_UNSOLICITED_ENABLE,
773                                 STAC_UNSOL_ENABLE);
774
775         nid = snd_hda_codec_read(codec, pin, 0, AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
776         for (i = 0; i < cfg->line_outs; i++) {
777                 if (! spec->multiout.dac_nids[i])
778                         continue;
779                 if (spec->multiout.dac_nids[i] == nid)
780                         return 0;
781         }
782
783         spec->multiout.hp_nid = nid;
784
785         /* control HP volume/switch on the output mixer amp */
786         if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "Headphone Playback Volume",
787                                         HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
788                 return err;
789         if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "Headphone Playback Switch",
790                                         HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
791                 return err;
792
793         return 0;
794 }
795
796 /* create playback/capture controls for input pins */
797 static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
798 {
799         struct sigmatel_spec *spec = codec->spec;
800         struct hda_input_mux *imux = &spec->private_imux;
801         hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
802         int i, j, k;
803
804         for (i = 0; i < AUTO_PIN_LAST; i++) {
805                 int index = -1;
806                 if (cfg->input_pins[i]) {
807                         /* Enable active pin widget as an input */
808                         stac92xx_auto_set_pinctl(codec, cfg->input_pins[i], AC_PINCTL_IN_EN);
809
810                         imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
811
812                         for (j=0; j<spec->num_muxes; j++) {
813                                 int num_cons = snd_hda_get_connections(codec, spec->mux_nids[j], con_lst, HDA_MAX_NUM_INPUTS);
814                                 for (k=0; k<num_cons; k++)
815                                         if (con_lst[k] == cfg->input_pins[i]) {
816                                                 index = k;
817                                                 break;
818                                         }
819                                 if (index >= 0)
820                                         break;
821                         }
822                         imux->items[imux->num_items].index = index;
823                         imux->num_items++;
824                 }
825         }
826
827         return 0;
828 }
829
830 static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
831 {
832         struct sigmatel_spec *spec = codec->spec;
833         int i;
834
835         for (i = 0; i < spec->autocfg.line_outs; i++) {
836                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
837                 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
838         }
839 }
840
841 static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
842 {
843         struct sigmatel_spec *spec = codec->spec;
844         hda_nid_t pin;
845
846         pin = spec->autocfg.hp_pin;
847         if (pin) /* connect to front */
848                 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
849 }
850
851 static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out, hda_nid_t dig_in)
852 {
853         struct sigmatel_spec *spec = codec->spec;
854         int err;
855
856         if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
857                 return err;
858         if (! spec->autocfg.line_outs && ! spec->autocfg.hp_pin)
859                 return 0; /* can't find valid pin config */
860         stac92xx_auto_init_multi_out(codec);
861         stac92xx_auto_init_hp_out(codec);
862         if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
863                 return err;
864         if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
865                 return err;
866
867         if ((err = stac92xx_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
868             (err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg)) < 0 ||
869             (err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
870                 return err;
871
872         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
873         if (spec->multiout.max_channels > 2)
874                 spec->surr_switch = 1;
875
876         if (spec->autocfg.dig_out_pin) {
877                 spec->multiout.dig_out_nid = dig_out;
878                 stac92xx_auto_set_pinctl(codec, spec->autocfg.dig_out_pin, AC_PINCTL_OUT_EN);
879         }
880         if (spec->autocfg.dig_in_pin) {
881                 spec->dig_in_nid = dig_in;
882                 stac92xx_auto_set_pinctl(codec, spec->autocfg.dig_in_pin, AC_PINCTL_IN_EN);
883         }
884
885         if (spec->kctl_alloc)
886                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
887
888         spec->input_mux = &spec->private_imux;
889
890         return 1;
891 }
892
893 static int stac9200_parse_auto_config(struct hda_codec *codec)
894 {
895         struct sigmatel_spec *spec = codec->spec;
896         int err;
897
898         if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
899                 return err;
900
901         if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
902                 return err;
903
904         if (spec->autocfg.dig_out_pin) {
905                 spec->multiout.dig_out_nid = 0x05;
906                 stac92xx_auto_set_pinctl(codec, spec->autocfg.dig_out_pin, AC_PINCTL_OUT_EN);
907         }
908         if (spec->autocfg.dig_in_pin) {
909                 spec->dig_in_nid = 0x04;
910                 stac92xx_auto_set_pinctl(codec, spec->autocfg.dig_in_pin, AC_PINCTL_IN_EN);
911         }
912
913         if (spec->kctl_alloc)
914                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
915
916         spec->input_mux = &spec->private_imux;
917
918         return 1;
919 }
920
921 static int stac92xx_init(struct hda_codec *codec)
922 {
923         struct sigmatel_spec *spec = codec->spec;
924
925         snd_hda_sequence_write(codec, spec->init);
926
927         return 0;
928 }
929
930 static void stac92xx_free(struct hda_codec *codec)
931 {
932         struct sigmatel_spec *spec = codec->spec;
933         int i;
934
935         if (! spec)
936                 return;
937
938         if (spec->kctl_alloc) {
939                 for (i = 0; i < spec->num_kctl_used; i++)
940                         kfree(spec->kctl_alloc[i].name);
941                 kfree(spec->kctl_alloc);
942         }
943
944         kfree(spec);
945 }
946
947 static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
948                                 unsigned int flag)
949 {
950         unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
951                         0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
952         snd_hda_codec_write(codec, nid, 0,
953                         AC_VERB_SET_PIN_WIDGET_CONTROL,
954                         pin_ctl | flag);
955 }
956
957 static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
958                                   unsigned int flag)
959 {
960         unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
961                         0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
962         snd_hda_codec_write(codec, nid, 0,
963                         AC_VERB_SET_PIN_WIDGET_CONTROL,
964                         pin_ctl & ~flag);
965 }
966
967 static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
968 {
969         struct sigmatel_spec *spec = codec->spec;
970         struct auto_pin_cfg *cfg = &spec->autocfg;
971         int i, presence;
972
973         if ((res >> 26) != STAC_HP_EVENT)
974                 return;
975
976         presence = snd_hda_codec_read(codec, cfg->hp_pin, 0,
977                         AC_VERB_GET_PIN_SENSE, 0x00) >> 31;
978
979         if (presence) {
980                 /* disable lineouts, enable hp */
981                 for (i = 0; i < cfg->line_outs; i++)
982                         stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
983                                                 AC_PINCTL_OUT_EN);
984                 stac92xx_set_pinctl(codec, cfg->hp_pin, AC_PINCTL_OUT_EN);
985         } else {
986                 /* enable lineouts, disable hp */
987                 for (i = 0; i < cfg->line_outs; i++)
988                         stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
989                                                 AC_PINCTL_OUT_EN);
990                 stac92xx_reset_pinctl(codec, cfg->hp_pin, AC_PINCTL_OUT_EN);
991         }
992
993
994 #ifdef CONFIG_PM
995 static int stac92xx_resume(struct hda_codec *codec)
996 {
997         struct sigmatel_spec *spec = codec->spec;
998         int i;
999
1000         stac92xx_init(codec);
1001         for (i = 0; i < spec->num_mixers; i++)
1002                 snd_hda_resume_ctls(codec, spec->mixers[i]);
1003         if (spec->multiout.dig_out_nid)
1004                 snd_hda_resume_spdif_out(codec);
1005         if (spec->dig_in_nid)
1006                 snd_hda_resume_spdif_in(codec);
1007
1008         return 0;
1009 }
1010 #endif
1011
1012 static struct hda_codec_ops stac92xx_patch_ops = {
1013         .build_controls = stac92xx_build_controls,
1014         .build_pcms = stac92xx_build_pcms,
1015         .init = stac92xx_init,
1016         .free = stac92xx_free,
1017         .unsol_event = stac92xx_unsol_event,
1018 #ifdef CONFIG_PM
1019         .resume = stac92xx_resume,
1020 #endif
1021 };
1022
1023 static int patch_stac9200(struct hda_codec *codec)
1024 {
1025         struct sigmatel_spec *spec;
1026         int err;
1027
1028         spec  = kzalloc(sizeof(*spec), GFP_KERNEL);
1029         if (spec == NULL)
1030                 return -ENOMEM;
1031
1032         codec->spec = spec;
1033         spec->board_config = snd_hda_check_board_config(codec, stac9200_cfg_tbl);
1034         if (spec->board_config < 0)
1035                 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
1036         else {
1037                 spec->num_pins = 8;
1038                 spec->pin_nids = stac9200_pin_nids;
1039                 spec->pin_configs = stac9200_brd_tbl[spec->board_config];
1040                 stac92xx_set_config_regs(codec);
1041         }
1042
1043         spec->multiout.max_channels = 2;
1044         spec->multiout.num_dacs = 1;
1045         spec->multiout.dac_nids = stac9200_dac_nids;
1046         spec->adc_nids = stac9200_adc_nids;
1047         spec->mux_nids = stac9200_mux_nids;
1048         spec->num_muxes = 1;
1049
1050         spec->init = stac9200_core_init;
1051         spec->mixer = stac9200_mixer;
1052
1053         err = stac9200_parse_auto_config(codec);
1054         if (err < 0) {
1055                 stac92xx_free(codec);
1056                 return err;
1057         }
1058
1059         codec->patch_ops = stac92xx_patch_ops;
1060
1061         return 0;
1062 }
1063
1064 static int patch_stac922x(struct hda_codec *codec)
1065 {
1066         struct sigmatel_spec *spec;
1067         int err;
1068
1069         spec  = kzalloc(sizeof(*spec), GFP_KERNEL);
1070         if (spec == NULL)
1071                 return -ENOMEM;
1072
1073         codec->spec = spec;
1074         spec->board_config = snd_hda_check_board_config(codec, stac922x_cfg_tbl);
1075         if (spec->board_config < 0)
1076                 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, using BIOS defaults\n");
1077         else {
1078                 spec->num_pins = 10;
1079                 spec->pin_nids = stac922x_pin_nids;
1080                 spec->pin_configs = stac922x_brd_tbl[spec->board_config];
1081                 stac92xx_set_config_regs(codec);
1082         }
1083
1084         spec->adc_nids = stac922x_adc_nids;
1085         spec->mux_nids = stac922x_mux_nids;
1086         spec->num_muxes = 2;
1087
1088         spec->init = stac922x_core_init;
1089         spec->mixer = stac922x_mixer;
1090
1091         spec->multiout.dac_nids = spec->dac_nids;
1092
1093         err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
1094         if (err < 0) {
1095                 stac92xx_free(codec);
1096                 return err;
1097         }
1098
1099         codec->patch_ops = stac92xx_patch_ops;
1100
1101         return 0;
1102 }
1103
1104 static int patch_stac927x(struct hda_codec *codec)
1105 {
1106         struct sigmatel_spec *spec;
1107         int err;
1108
1109         spec  = kzalloc(sizeof(*spec), GFP_KERNEL);
1110         if (spec == NULL)
1111                 return -ENOMEM;
1112
1113         codec->spec = spec;
1114         spec->board_config = snd_hda_check_board_config(codec, stac927x_cfg_tbl);
1115         if (spec->board_config < 0)
1116                 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC927x, using BIOS defaults\n");
1117         else {
1118                 spec->num_pins = 14;
1119                 spec->pin_nids = stac927x_pin_nids;
1120                 spec->pin_configs = stac927x_brd_tbl[spec->board_config];
1121                 stac92xx_set_config_regs(codec);
1122         }
1123
1124         spec->adc_nids = stac927x_adc_nids;
1125         spec->mux_nids = stac927x_mux_nids;
1126         spec->num_muxes = 3;
1127
1128         spec->init = stac927x_core_init;
1129         spec->mixer = stac927x_mixer;
1130
1131         spec->multiout.dac_nids = spec->dac_nids;
1132
1133         err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
1134         if (err < 0) {
1135                 stac92xx_free(codec);
1136                 return err;
1137         }
1138
1139         codec->patch_ops = stac92xx_patch_ops;
1140
1141         return 0;
1142 }
1143
1144 /*
1145  * patch entries
1146  */
1147 struct hda_codec_preset snd_hda_preset_sigmatel[] = {
1148         { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
1149         { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
1150         { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
1151         { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
1152         { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
1153         { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
1154         { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
1155         { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
1156         { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
1157         { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
1158         { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
1159         { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
1160         { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
1161         { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
1162         { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
1163         { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
1164         { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
1165         {} /* terminator */
1166 };