patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / sound / pci / ice1712 / aureon.c
1 /*
2  *   ALSA driver for ICEnsemble VT1724 (Envy24HT)
3  *
4  *   Lowlevel functions for Terratec Aureon cards
5  *
6  *      Copyright (c) 2003 Takashi Iwai <tiwai@suse.de>
7  *
8  *   This program is free software; you can redistribute it and/or modify
9  *   it under the terms of the GNU General Public License as published by
10  *   the Free Software Foundation; either version 2 of the License, or
11  *   (at your option) any later version.
12  *
13  *   This program is distributed in the hope that it will be useful,
14  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *   GNU General Public License for more details.
17  *
18  *   You should have received a copy of the GNU General Public License
19  *   along with this program; if not, write to the Free Software
20  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21  *
22  *
23  * NOTES:
24  *
25  * - we reuse the akm4xxx_t record for storing the wm8770 codec data.
26  *   both wm and akm codecs are pretty similar, so we can integrate
27  *   both controls in the future, once if wm codecs are reused in
28  *   many boards.
29  *
30  * - writing over SPI is implemented but reading is not yet.
31  *   the SPDIF-in channel status, etc. can be read from CS chip.
32  *
33  * - DAC digital volumes are not implemented in the mixer.
34  *   if they show better response than DAC analog volumes, we can use them
35  *   instead.
36  *
37  * - Aureon boards are equipped with AC97 codec, too.  it's used to do
38  *   the analog mixing but not easily controllable (it's not connected
39  *   directly from envy24ht chip).  so let's leave it as it is.
40  *
41  *
42  *   Lowlevel functions for AudioTrak Prodigy 7.1 (and possibly 192) cards
43  *      Copyright (c) 2003 Dimitromanolakis Apostolos <apostol@cs.utoronto.ca>
44  *
45  *   version 0.82: Stable / not all features work yet (no communication with AC97 secondary)
46  *       added 64x/128x oversampling switch (should be 64x only for 96khz)
47  *       fixed some recording labels (still need to check the rest)
48  *       recording is working probably thanks to correct wm8770 initialization
49  *
50  *   version 0.5: Initial release:
51  *           working: analog output, mixer, headphone amplifier switch
52  *       not working: prety much everything else, at least i could verify that
53  *                    we have no digital output, no capture, pretty bad clicks and poops
54  *                    on mixer switch and other coll stuff.
55  *
56  * - Prodigy boards are equipped with AC97 STAC9744 chip , too.  it's used to do
57  *   the analog mixing but not easily controllable (it's not connected
58  *   directly from envy24ht chip).  so let's leave it as it is.
59  *
60  */      
61
62 #include <sound/driver.h>
63 #include <asm/io.h>
64 #include <linux/delay.h>
65 #include <linux/interrupt.h>
66 #include <linux/init.h>
67 #include <linux/slab.h>
68 #include <sound/core.h>
69
70 #include "ice1712.h"
71 #include "envy24ht.h"
72 #include "aureon.h"
73
74 /* WM8770 registers */
75 #define WM_DAC_ATTEN            0x00    /* DAC1-8 analog attenuation */
76 #define WM_DAC_MASTER_ATTEN     0x08    /* DAC master analog attenuation */
77 #define WM_DAC_DIG_ATTEN        0x09    /* DAC1-8 digital attenuation */
78 #define WM_DAC_DIG_MATER_ATTEN  0x11    /* DAC master digital attenuation */
79 #define WM_PHASE_SWAP           0x12    /* DAC phase */
80 #define WM_DAC_CTRL1            0x13    /* DAC control bits */
81 #define WM_MUTE                 0x14    /* mute controls */
82 #define WM_DAC_CTRL2            0x15    /* de-emphasis and zefo-flag */
83 #define WM_INT_CTRL             0x16    /* interface control */
84 #define WM_MASTER               0x17    /* master clock and mode */
85 #define WM_POWERDOWN            0x18    /* power-down controls */
86 #define WM_ADC_GAIN             0x19    /* ADC gain L(19)/R(1a) */
87 #define WM_ADC_MUX              0x1b    /* input MUX */
88 #define WM_OUT_MUX1             0x1c    /* output MUX */
89 #define WM_OUT_MUX2             0x1e    /* output MUX */
90 #define WM_RESET                0x1f    /* software reset */
91
92
93 /*
94  * write data in the SPI mode
95  */
96 static void aureon_spi_write(ice1712_t *ice, unsigned int cs, unsigned int data, int bits)
97 {
98         unsigned int tmp;
99         unsigned int cscs;
100         int i;
101
102         tmp = snd_ice1712_gpio_read(ice);
103
104         if (ice->eeprom.subvendor == VT1724_SUBDEVICE_PRODIGY71)
105                 cscs = PRODIGY_CS8415_CS;
106         else
107                 cscs = AUREON_CS8415_CS;
108
109         snd_ice1712_gpio_set_mask(ice, ~(AUREON_WM_RW|AUREON_WM_DATA|AUREON_WM_CLK|
110                                          AUREON_WM_CS|cscs));
111         tmp |= AUREON_WM_RW;
112         tmp &= ~cs;
113         snd_ice1712_gpio_write(ice, tmp);
114         udelay(1);
115
116         for (i = bits - 1; i >= 0; i--) {
117                 tmp &= ~AUREON_WM_CLK;
118                 snd_ice1712_gpio_write(ice, tmp);
119                 udelay(1);
120                 if (data & (1 << i))
121                         tmp |= AUREON_WM_DATA;
122                 else
123                         tmp &= ~AUREON_WM_DATA;
124                 snd_ice1712_gpio_write(ice, tmp);
125                 udelay(1);
126                 tmp |= AUREON_WM_CLK;
127                 snd_ice1712_gpio_write(ice, tmp);
128                 udelay(1);
129         }
130
131         tmp &= ~AUREON_WM_CLK;
132         tmp |= cs;
133         snd_ice1712_gpio_write(ice, tmp);
134         udelay(1);
135         tmp |= AUREON_WM_CLK;
136         snd_ice1712_gpio_write(ice, tmp);
137         udelay(1);
138 }
139      
140
141 /*
142  * get the current register value of WM codec
143  */
144 static unsigned short wm_get(ice1712_t *ice, int reg)
145 {
146         reg <<= 1;
147         return ((unsigned short)ice->akm[0].images[reg] << 8) |
148                 ice->akm[0].images[reg + 1];
149 }
150
151 /*
152  * set the register value of WM codec and remember it
153  */
154 static void wm_put(ice1712_t *ice, int reg, unsigned short val)
155 {
156         aureon_spi_write(ice, AUREON_WM_CS, (reg << 9) | (val & 0x1ff), 16);
157         reg <<= 1;
158         ice->akm[0].images[reg] = val >> 8;
159         ice->akm[0].images[reg + 1] = val;
160 }
161
162 /*
163  * DAC mute control
164  */
165 static int wm_dac_mute_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
166 {
167         uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
168         uinfo->count = 1;
169         uinfo->value.integer.min = 0;
170         uinfo->value.integer.max = 1;
171         return 0;
172 }
173
174 static int wm_dac_mute_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
175 {
176         ice1712_t *ice = snd_kcontrol_chip(kcontrol);
177         unsigned short val;
178
179         down(&ice->gpio_mutex);
180         val = wm_get(ice, snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)+WM_MUTE);
181         ucontrol->value.integer.value[0] = ~val>>4 & 0x1;
182         up(&ice->gpio_mutex);
183         return 0;
184 }
185
186 static int wm_dac_mute_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
187 {
188         ice1712_t *ice = snd_kcontrol_chip(kcontrol);
189         unsigned short new, old;
190         int change;
191
192         snd_ice1712_save_gpio_status(ice);
193         old = wm_get(ice, snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)+WM_MUTE);
194         new = (~ucontrol->value.integer.value[0]<<4&0x10) | (old&~0x10);
195         change = (new != old);
196         if (change)
197                 wm_put(ice, snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)+WM_MUTE, new);
198         snd_ice1712_restore_gpio_status(ice);
199
200         return change;
201 }
202
203 /*
204  * DAC volume attenuation mixer control
205  */
206 static int wm_dac_vol_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
207 {
208         uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
209         uinfo->count = 1;
210         uinfo->value.integer.min = 0;           /* mute */
211         uinfo->value.integer.max = 101;         /* 0dB */
212         return 0;
213 }
214
215 static int wm_dac_vol_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
216 {
217         ice1712_t *ice = snd_kcontrol_chip(kcontrol);
218         int idx;
219         unsigned short vol;
220
221         down(&ice->gpio_mutex);
222         if (kcontrol->private_value)
223                 idx = WM_DAC_MASTER_ATTEN;
224         else
225                 idx  = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + WM_DAC_ATTEN;
226         vol = wm_get(ice, idx) & 0x7f;
227         if (vol <= 0x1a)
228                 ucontrol->value.integer.value[0] = 0;
229         else
230                 ucontrol->value.integer.value[0] = vol - 0x1a;
231         up(&ice->gpio_mutex);
232         return 0;
233 }
234
235 static int wm_dac_vol_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
236 {
237         ice1712_t *ice = snd_kcontrol_chip(kcontrol);
238         int idx;
239         unsigned short ovol, nvol;
240         int change;
241
242         snd_ice1712_save_gpio_status(ice);
243         if (kcontrol->private_value)
244                 idx = WM_DAC_MASTER_ATTEN;
245         else
246                 idx  = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + WM_DAC_ATTEN;
247         nvol = ucontrol->value.integer.value[0] + 0x1a;
248         ovol = wm_get(ice, idx) & 0x7f;
249         change = (ovol != nvol);
250         if (change) {
251                 if (nvol <= 0x1a && ovol <= 0x1a)
252                         change = 0;
253                 else
254                         wm_put(ice, idx, nvol | 0x180); /* update on zero detect */
255         }
256         snd_ice1712_restore_gpio_status(ice);
257         return change;
258 }
259
260 /*
261  * ADC mute control
262  */
263 static int wm_adc_mute_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
264 {
265         uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
266         uinfo->count = 1;
267         uinfo->value.integer.min = 0;
268         uinfo->value.integer.max = 1;
269         return 0;
270 }
271
272 static int wm_adc_mute_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
273 {
274         ice1712_t *ice = snd_kcontrol_chip(kcontrol);
275         unsigned short val;
276
277         down(&ice->gpio_mutex);
278         val = wm_get(ice, snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)+WM_ADC_GAIN);
279         ucontrol->value.integer.value[0] = ~val>>5 & 0x1;
280         up(&ice->gpio_mutex);
281         return 0;
282 }
283
284 static int wm_adc_mute_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
285 {
286         ice1712_t *ice = snd_kcontrol_chip(kcontrol);
287         unsigned short new, old;
288         int change;
289
290         snd_ice1712_save_gpio_status(ice);
291         old = wm_get(ice, snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)+WM_ADC_GAIN);
292         new = (~ucontrol->value.integer.value[0]<<5&0x20) | (old&~0x20);
293         change = (new != old);
294         if (change)
295                 wm_put(ice, snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)+WM_ADC_GAIN, new);
296         snd_ice1712_restore_gpio_status(ice);
297
298         return change;
299 }
300
301 /*
302  * ADC gain mixer control
303  */
304 static int wm_adc_vol_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
305 {
306         uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
307         uinfo->count = 1;
308         uinfo->value.integer.min = 0;           /* -12dB */
309         uinfo->value.integer.max = 0x1f;        /* 19dB */
310         return 0;
311 }
312
313 static int wm_adc_vol_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
314 {
315         ice1712_t *ice = snd_kcontrol_chip(kcontrol);
316         int idx;
317         unsigned short vol;
318
319         down(&ice->gpio_mutex);
320         idx  = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + WM_ADC_GAIN;
321         vol = wm_get(ice, idx) & 0x1f;
322         ucontrol->value.integer.value[0] = vol;
323         up(&ice->gpio_mutex);
324         return 0;
325 }
326
327 static int wm_adc_vol_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
328 {
329         ice1712_t *ice = snd_kcontrol_chip(kcontrol);
330         int idx;
331         unsigned short ovol, nvol;
332         int change;
333
334         snd_ice1712_save_gpio_status(ice);
335         idx  = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + WM_ADC_GAIN;
336         nvol = ucontrol->value.integer.value[0];
337         ovol = wm_get(ice, idx);
338         change = ((ovol & 0x1f)  != nvol);
339         if (change)
340                 wm_put(ice, idx, nvol | (ovol & ~0x1f));
341         snd_ice1712_restore_gpio_status(ice);
342         return change;
343 }
344
345 /*
346  * ADC input mux mixer control
347  */
348 static int wm_adc_mux_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
349 {
350         static char *texts[] = {
351                 "CD",           //AIN1
352                 "Aux",          //AIN2
353                 "Line",         //AIN3
354                 "Mic",          //AIN4
355                 "AC97"          //AIN5
356         };
357         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
358         uinfo->count = 1;
359         uinfo->value.enumerated.items = 5;
360         if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
361                 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
362         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
363         return 0;
364 }
365
366 static int wm_adc_mux_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)
367 {
368         ice1712_t *ice = snd_kcontrol_chip(kcontrol);
369         unsigned short val;
370
371         down(&ice->gpio_mutex);
372         val = wm_get(ice, WM_ADC_MUX);
373         ucontrol->value.integer.value[0] = val & 7;
374         ucontrol->value.integer.value[1] = (val >> 4) & 7;
375         up(&ice->gpio_mutex);
376         return 0;
377 }
378
379 static int wm_adc_mux_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)
380 {
381         ice1712_t *ice = snd_kcontrol_chip(kcontrol);
382         unsigned short oval, nval;
383         int change;
384
385         snd_ice1712_save_gpio_status(ice);
386         oval = wm_get(ice, WM_ADC_MUX);
387         nval = oval & ~0x77;
388         nval |= ucontrol->value.integer.value[0] & 7;
389         nval |= (ucontrol->value.integer.value[1] & 7) << 4;
390         change = (oval != nval);
391         if (change)
392                 wm_put(ice, WM_ADC_MUX, nval);
393         snd_ice1712_restore_gpio_status(ice);
394         return 0;
395 }
396
397 /*
398  * Headphone Amplifier
399  */
400 static int aureon_set_headphone_amp(ice1712_t *ice, int enable)
401 {
402         unsigned int tmp, tmp2;
403
404         tmp2 = tmp = snd_ice1712_gpio_read(ice);
405         if (enable)
406                 tmp |= AUREON_HP_SEL;
407         else
408                 tmp &= ~ AUREON_HP_SEL;
409         if (tmp != tmp2) {
410                 snd_ice1712_gpio_write(ice, tmp);
411                 return 1;
412         }
413         return 0;
414 }
415
416 static int aureon_get_headphone_amp(ice1712_t *ice)
417 {
418         unsigned int tmp = snd_ice1712_gpio_read(ice);
419
420         return ( tmp & AUREON_HP_SEL )!= 0;
421 }
422
423 static int aureon_bool_info(snd_kcontrol_t *k, snd_ctl_elem_info_t *uinfo)
424 {
425         uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
426         uinfo->count = 1;
427         uinfo->value.integer.min = 0;
428         uinfo->value.integer.max = 1;
429         return 0;
430 }
431
432 static int aureon_hpamp_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
433 {
434         ice1712_t *ice = snd_kcontrol_chip(kcontrol);
435
436         ucontrol->value.integer.value[0] = aureon_get_headphone_amp(ice);
437         return 0;
438 }
439
440
441 static int aureon_hpamp_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
442 {
443         ice1712_t *ice = snd_kcontrol_chip(kcontrol);
444
445         return aureon_set_headphone_amp(ice,ucontrol->value.integer.value[0]);
446 }
447
448 /*
449  * Deemphasis
450  */
451 static int aureon_deemp_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
452 {
453         ice1712_t *ice = snd_kcontrol_chip(kcontrol);
454         ucontrol->value.integer.value[0] = (wm_get(ice, WM_DAC_CTRL2) & 0xf) == 0xf;
455         return 0;
456 }
457
458 static int aureon_deemp_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
459 {
460         ice1712_t *ice = snd_kcontrol_chip(kcontrol);
461         int temp, temp2;
462         temp2 = temp = wm_get(ice, WM_DAC_CTRL2);
463         if (ucontrol->value.integer.value[0])
464                 temp |= 0xf;
465         else
466                 temp &= ~0xf;
467         if (temp != temp2) {
468                 wm_put(ice, WM_DAC_CTRL2, temp);
469                 return 1;
470         }
471         return 0;
472 }
473
474 /*
475  * ADC Oversampling
476  */
477 static int aureon_oversampling_info(snd_kcontrol_t *k, snd_ctl_elem_info_t *uinfo)
478 {
479         static char *texts[2] = { "128x", "64x" };
480
481         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
482         uinfo->count = 1;
483         uinfo->value.enumerated.items = 2;
484
485         if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
486                 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
487         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
488
489         return 0;
490 }
491
492 static int aureon_oversampling_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
493 {
494         ice1712_t *ice = snd_kcontrol_chip(kcontrol);
495         ucontrol->value.enumerated.item[0] = (wm_get(ice, WM_MASTER) & 0x8) == 0x8;
496         return 0;
497 }
498
499 static int aureon_oversampling_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
500 {
501         int temp, temp2;
502         ice1712_t *ice = snd_kcontrol_chip(kcontrol);
503
504         temp2 = temp = wm_get(ice, WM_MASTER);
505
506         if (ucontrol->value.enumerated.item[0])
507                 temp |= 0x8;
508         else
509                 temp &= ~0x8;
510
511         if (temp != temp2) {
512                 wm_put(ice, WM_MASTER, temp);
513                 return 1;
514         }
515         return 0;
516 }
517
518 /*
519  * mixers
520  */
521
522 static snd_kcontrol_new_t aureon51_dac_control __devinitdata = {
523         .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
524         .name = "DAC Volume",
525         .count = 6,
526         .info = wm_dac_vol_info,
527         .get = wm_dac_vol_get,
528         .put = wm_dac_vol_put,
529 };
530
531 static snd_kcontrol_new_t aureon71_dac_control __devinitdata = {
532         .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
533         .name = "DAC Volume",
534         .count = 8,
535         .info = wm_dac_vol_info,
536         .get = wm_dac_vol_get,
537         .put = wm_dac_vol_put,
538 };
539
540 static snd_kcontrol_new_t wm_controls[] __devinitdata = {
541         {
542                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
543                 .name = "Master Playback Switch",
544                 .info = wm_dac_mute_info,
545                 .get = wm_dac_mute_get,
546                 .put = wm_dac_mute_put,
547         },
548         {
549                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
550                 .name = "Master Playback Volume",
551                 .info = wm_dac_vol_info,
552                 .get = wm_dac_vol_get,
553                 .put = wm_dac_vol_put,
554                 .private_value = 1,
555         },
556         {
557                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
558                 .name = "ADC Switch",
559                 .count = 2,
560                 .info = wm_adc_mute_info,
561                 .get = wm_adc_mute_get,
562                 .put = wm_adc_mute_put,
563
564         },
565         {
566                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
567                 .name = "ADC Volume",
568                 .count = 2,
569                 .info = wm_adc_vol_info,
570                 .get = wm_adc_vol_get,
571                 .put = wm_adc_vol_put,
572         },
573         {
574                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
575                 .name = "Capture Route",
576                 .info = wm_adc_mux_info,
577                 .get = wm_adc_mux_get,
578                 .put = wm_adc_mux_put,
579         },
580         {
581                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
582                 .name = "Headphone Amplifier Switch",
583                 .info = aureon_bool_info,
584                 .get = aureon_hpamp_get,
585                 .put = aureon_hpamp_put
586         },
587         {
588                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
589                 .name = "DAC Deemphasis Switch",
590                 .info = aureon_bool_info,
591                 .get = aureon_deemp_get,
592                 .put = aureon_deemp_put
593         },
594         {
595                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
596                 .name = "ADC Oversampling",
597                 .info = aureon_oversampling_info,
598                 .get = aureon_oversampling_get,
599                 .put = aureon_oversampling_put
600         },
601 };
602
603
604 static int __devinit aureon_add_controls(ice1712_t *ice)
605 {
606         unsigned int i;
607         int err;
608
609         if (ice->eeprom.subvendor == VT1724_SUBDEVICE_AUREON51_SKY)
610                 err = snd_ctl_add(ice->card, snd_ctl_new1(&aureon51_dac_control, ice));
611         else
612                 err = snd_ctl_add(ice->card, snd_ctl_new1(&aureon71_dac_control, ice));
613         if (err < 0)
614                 return err;
615
616         for (i = 0; i < ARRAY_SIZE(wm_controls); i++) {
617                 err = snd_ctl_add(ice->card, snd_ctl_new1(&wm_controls[i], ice));
618                 if (err < 0)
619                         return err;
620         }
621         return 0;
622 }
623
624
625 /*
626  * initialize the chip
627  */
628 static int __devinit aureon_init(ice1712_t *ice)
629 {
630         static unsigned short wm_inits_aureon[] = {
631                 /* These come first to reduce init pop noise */
632                 0x1b, 0x000,            /* ADC Mux */
633                 0x1c, 0x009,            /* Out Mux1 */
634                 0x1d, 0x009,            /* Out Mux2 */
635
636                 0x18, 0x000,            /* All power-up */
637
638                 0x16, 0x122,            /* I2S, normal polarity, 24bit */
639                 0x17, 0x022,            /* 256fs, slave mode */
640                 0x00, 0,                /* DAC1 analog mute */
641                 0x01, 0,                /* DAC2 analog mute */
642                 0x02, 0,                /* DAC3 analog mute */
643                 0x03, 0,                /* DAC4 analog mute */
644                 0x04, 0,                /* DAC5 analog mute */
645                 0x05, 0,                /* DAC6 analog mute */
646                 0x06, 0,                /* DAC7 analog mute */
647                 0x07, 0,                /* DAC8 analog mute */
648                 0x08, 0x100,            /* master analog mute */
649                 0x09, 0xff,             /* DAC1 digital full */
650                 0x0a, 0xff,             /* DAC2 digital full */
651                 0x0b, 0xff,             /* DAC3 digital full */
652                 0x0c, 0xff,             /* DAC4 digital full */
653                 0x0d, 0xff,             /* DAC5 digital full */
654                 0x0e, 0xff,             /* DAC6 digital full */
655                 0x0f, 0xff,             /* DAC7 digital full */
656                 0x10, 0xff,             /* DAC8 digital full */
657                 0x11, 0x1ff,            /* master digital full */
658                 0x12, 0x000,            /* phase normal */
659                 0x13, 0x090,            /* unmute DAC L/R */
660                 0x14, 0x000,            /* all unmute */
661                 0x15, 0x000,            /* no deemphasis, no ZFLG */
662                 0x19, 0x000,            /* -12dB ADC/L */
663                 0x1a, 0x000,            /* -12dB ADC/R */
664                 (unsigned short)-1
665         };
666         static unsigned short wm_inits_prodigy[] = {
667
668                 /* These come first to reduce init pop noise */
669                 0x1b, 0x000,            /* ADC Mux */
670                 0x1c, 0x009,            /* Out Mux1 */
671                 0x1d, 0x009,            /* Out Mux2 */
672
673                 0x18, 0x000,            /* All power-up */
674
675                 0x16, 0x022,            /* I2S, normal polarity, 24bit, high-pass on */
676                 0x17, 0x006,            /* 128fs, slave mode */
677
678                 0x00, 0,                /* DAC1 analog mute */
679                 0x01, 0,                /* DAC2 analog mute */
680                 0x02, 0,                /* DAC3 analog mute */
681                 0x03, 0,                /* DAC4 analog mute */
682                 0x04, 0,                /* DAC5 analog mute */
683                 0x05, 0,                /* DAC6 analog mute */
684                 0x06, 0,                /* DAC7 analog mute */
685                 0x07, 0,                /* DAC8 analog mute */
686                 0x08, 0x100,            /* master analog mute */
687
688                 0x09, 0x7f,             /* DAC1 digital full */
689                 0x0a, 0x7f,             /* DAC2 digital full */
690                 0x0b, 0x7f,             /* DAC3 digital full */
691                 0x0c, 0x7f,             /* DAC4 digital full */
692                 0x0d, 0x7f,             /* DAC5 digital full */
693                 0x0e, 0x7f,             /* DAC6 digital full */
694                 0x0f, 0x7f,             /* DAC7 digital full */
695                 0x10, 0x7f,             /* DAC8 digital full */
696                 0x11, 0x1FF,            /* master digital full */
697
698                 0x12, 0x000,            /* phase normal */
699                 0x13, 0x090,            /* unmute DAC L/R */
700                 0x14, 0x000,            /* all unmute */
701                 0x15, 0x000,            /* no deemphasis, no ZFLG */
702
703                 0x19, 0x000,            /* -12dB ADC/L */
704                 0x1a, 0x000,            /* -12dB ADC/R */
705                 (unsigned short)-1
706
707         };
708         static unsigned short cs_inits[] = {
709                 0x0441, /* RUN */
710                 0x0100, /* no mute */
711                 0x0200, /* */
712                 0x0600, /* slave, 24bit */
713                 (unsigned short)-1
714         };
715         unsigned int tmp;
716         unsigned short *p;
717         unsigned int cscs;
718
719         if (ice->eeprom.subvendor == VT1724_SUBDEVICE_AUREON51_SKY) {
720                 ice->num_total_dacs = 6;
721                 ice->num_total_adcs = 6;
722         } else {
723                 /* aureon 7.1 and prodigy 7.1 */
724                 ice->num_total_dacs = 8;
725                 ice->num_total_adcs = 8;
726         }
727
728         /* to remeber the register values */
729         ice->akm = snd_kcalloc(sizeof(akm4xxx_t), GFP_KERNEL);
730         if (! ice->akm)
731                 return -ENOMEM;
732         ice->akm_codecs = 1;
733
734         if (ice->eeprom.subvendor == VT1724_SUBDEVICE_PRODIGY71)
735                 cscs = PRODIGY_CS8415_CS;
736         else
737                 cscs = AUREON_CS8415_CS;
738
739         snd_ice1712_gpio_set_dir(ice, 0xbfffff); /* fix this for the time being */
740
741         /* reset the wm codec as the SPI mode */
742         snd_ice1712_save_gpio_status(ice);
743         snd_ice1712_gpio_set_mask(ice, ~(AUREON_WM_RESET|AUREON_WM_CS|
744                                          cscs|AUREON_HP_SEL));
745         tmp = snd_ice1712_gpio_read(ice);
746         tmp &= ~AUREON_WM_RESET;
747         snd_ice1712_gpio_write(ice, tmp);
748         udelay(1);
749         tmp |= AUREON_WM_CS | cscs;
750         snd_ice1712_gpio_write(ice, tmp);
751         udelay(1);
752         tmp |= AUREON_WM_RESET;
753         snd_ice1712_gpio_write(ice, tmp);
754         udelay(1);
755
756         /* initialize WM8770 codec */
757         if (ice->eeprom.subvendor == VT1724_SUBDEVICE_PRODIGY71)
758                 p = wm_inits_prodigy;
759         else
760                 p = wm_inits_aureon;
761         for (; *p != (unsigned short)-1; p += 2)
762                 wm_put(ice, p[0], p[1]);
763
764         /* initialize CS8415A codec */
765         for (p = cs_inits; *p != (unsigned short)-1; p++)
766                 aureon_spi_write(ice, cscs,
767                                  *p | 0x200000, 24);
768
769         aureon_set_headphone_amp(ice, 1);
770
771         snd_ice1712_restore_gpio_status(ice);
772
773         return 0;
774 }
775
776
777 /*
778  * Aureon boards don't provide the EEPROM data except for the vendor IDs.
779  * hence the driver needs to sets up it properly.
780  */
781
782 static unsigned char aureon51_eeprom[] __devinitdata = {
783         0x2a,   /* SYSCONF: clock 512, mpu401, spdif-in/ADC, 3DACs */
784         0x80,   /* ACLINK: I2S */
785         0xf8,   /* I2S: vol, 96k, 24bit, 192k */
786         0xc3,   /* SPDIF: out-en, out-int, spdif-in */
787         0xff,   /* GPIO_DIR */
788         0xff,   /* GPIO_DIR1 */
789         0xbf,   /* GPIO_DIR2 */
790         0xff,   /* GPIO_MASK */
791         0xff,   /* GPIO_MASK1 */
792         0xff,   /* GPIO_MASK2 */
793         0x00,   /* GPIO_STATE */
794         0x00,   /* GPIO_STATE1 */
795         0x00,   /* GPIO_STATE2 */
796 };
797
798 static unsigned char aureon71_eeprom[] __devinitdata = {
799         0x2b,   /* SYSCONF: clock 512, mpu401, spdif-in/ADC, 4DACs */
800         0x80,   /* ACLINK: I2S */
801         0xf8,   /* I2S: vol, 96k, 24bit, 192k */
802         0xc3,   /* SPDIF: out-en, out-int, spdif-in */
803         0xff,   /* GPIO_DIR */
804         0xff,   /* GPIO_DIR1 */
805         0xbf,   /* GPIO_DIR2 */
806         0x00,   /* GPIO_MASK */
807         0x00,   /* GPIO_MASK1 */
808         0x00,   /* GPIO_MASK2 */
809         0x00,   /* GPIO_STATE */
810         0x00,   /* GPIO_STATE1 */
811         0x00,   /* GPIO_STATE2 */
812 };
813
814 static unsigned char prodigy71_eeprom[] __devinitdata = {
815         0x2b,   /* SYSCONF: clock 512, mpu401, spdif-in/ADC, 4DACs */
816         0x80,   /* ACLINK: I2S */
817         0xf8,   /* I2S: vol, 96k, 24bit, 192k */
818         0xc3,   /* SPDIF: out-en, out-int, spdif-in */
819         0xff,   /* GPIO_DIR */
820         0xff,   /* GPIO_DIR1 */
821         0xbf,   /* GPIO_DIR2 */
822         0x00,   /* GPIO_MASK */
823         0x00,   /* GPIO_MASK1 */
824         0x00,   /* GPIO_MASK2 */
825         0x00,   /* GPIO_STATE */
826         0x00,   /* GPIO_STATE1 */
827         0x00,   /* GPIO_STATE2 */
828 };
829
830 /* entry point */
831 struct snd_ice1712_card_info snd_vt1724_aureon_cards[] __devinitdata = {
832         {
833                 .subvendor = VT1724_SUBDEVICE_AUREON51_SKY,
834                 .name = "Terratec Aureon 5.1-Sky",
835                 .model = "aureon51",
836                 .chip_init = aureon_init,
837                 .build_controls = aureon_add_controls,
838                 .eeprom_size = sizeof(aureon51_eeprom),
839                 .eeprom_data = aureon51_eeprom,
840         },
841         {
842                 .subvendor = VT1724_SUBDEVICE_AUREON71_SPACE,
843                 .name = "Terratec Aureon 7.1-Space",
844                 .model = "aureon71",
845                 .chip_init = aureon_init,
846                 .build_controls = aureon_add_controls,
847                 .eeprom_size = sizeof(aureon71_eeprom),
848                 .eeprom_data = aureon71_eeprom,
849         },
850         {
851                 .subvendor = VT1724_SUBDEVICE_AUREON71_UNIVERSE,
852                 .name = "Terratec Aureon 7.1-Universe",
853                 /* model not needed - identical with 7.1-Space */
854                 .chip_init = aureon_init,
855                 .build_controls = aureon_add_controls,
856                 .eeprom_size = sizeof(aureon71_eeprom),
857                 .eeprom_data = aureon71_eeprom,
858         },
859         {
860                 .subvendor = VT1724_SUBDEVICE_PRODIGY71,
861                 .name = "Audiotrak Prodigy 7.1",
862                 .model = "prodigy71",
863                 .chip_init = aureon_init,
864                 .build_controls = aureon_add_controls,
865                 .eeprom_size = sizeof(prodigy71_eeprom),
866                 .eeprom_data = prodigy71_eeprom,
867         },
868         { } /* terminator */
869 };