patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / sound / pci / ice1712 / delta.c
1 /*
2  *   ALSA driver for ICEnsemble ICE1712 (Envy24)
3  *
4  *   Lowlevel functions for M-Audio Delta 1010, 44, 66, Dio2496, Audiophile
5  *                          Digigram VX442
6  *
7  *      Copyright (c) 2000 Jaroslav Kysela <perex@suse.cz>
8  *
9  *   This program is free software; you can redistribute it and/or modify
10  *   it under the terms of the GNU General Public License as published by
11  *   the Free Software Foundation; either version 2 of the License, or
12  *   (at your option) any later version.
13  *
14  *   This program is distributed in the hope that it will be useful,
15  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *   GNU General Public License for more details.
18  *
19  *   You should have received a copy of the GNU General Public License
20  *   along with this program; if not, write to the Free Software
21  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
22  *
23  */      
24
25 #include <sound/driver.h>
26 #include <asm/io.h>
27 #include <linux/delay.h>
28 #include <linux/interrupt.h>
29 #include <linux/init.h>
30 #include <linux/slab.h>
31 #include <sound/core.h>
32 #include <sound/cs8427.h>
33 #include <sound/asoundef.h>
34
35 #include "ice1712.h"
36 #include "delta.h"
37
38 #define SND_CS8403
39 #include <sound/cs8403.h>
40
41
42 /*
43  * CS8427 via SPI mode (for Audiophile), emulated I2C
44  */
45
46 /* send 8 bits */
47 static void ap_cs8427_write_byte(ice1712_t *ice, unsigned char data, unsigned char tmp)
48 {
49         int idx;
50
51         for (idx = 7; idx >= 0; idx--) {
52                 tmp &= ~(ICE1712_DELTA_AP_DOUT|ICE1712_DELTA_AP_CCLK);
53                 if (data & (1 << idx))
54                         tmp |= ICE1712_DELTA_AP_DOUT;
55                 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp);
56                 udelay(5);
57                 tmp |= ICE1712_DELTA_AP_CCLK;
58                 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp);
59                 udelay(5);
60         }
61 }
62
63 /* read 8 bits */
64 static unsigned char ap_cs8427_read_byte(ice1712_t *ice, unsigned char tmp)
65 {
66         unsigned char data = 0;
67         int idx;
68         
69         for (idx = 7; idx >= 0; idx--) {
70                 tmp &= ~ICE1712_DELTA_AP_CCLK;
71                 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp);
72                 udelay(5);
73                 if (snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA) & ICE1712_DELTA_AP_DIN)
74                         data |= 1 << idx;
75                 tmp |= ICE1712_DELTA_AP_CCLK;
76                 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp);
77                 udelay(5);
78         }
79         return data;
80 }
81
82 /* assert chip select */
83 static unsigned char ap_cs8427_codec_select(ice1712_t *ice)
84 {
85         unsigned char tmp;
86         tmp = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA);
87         switch (ice->eeprom.subvendor) {
88         case ICE1712_SUBDEVICE_DELTA1010LT:
89                 tmp &= ~ICE1712_DELTA_1010LT_CS;
90                 tmp |= ICE1712_DELTA_1010LT_CCLK | ICE1712_DELTA_1010LT_CS_CS8427;
91                 break;
92         case ICE1712_SUBDEVICE_AUDIOPHILE:
93         case ICE1712_SUBDEVICE_DELTA410:
94                 tmp |= ICE1712_DELTA_AP_CCLK | ICE1712_DELTA_AP_CS_CODEC;
95                 tmp &= ~ICE1712_DELTA_AP_CS_DIGITAL;
96                 break;
97         case ICE1712_SUBDEVICE_VX442:
98                 tmp |= ICE1712_VX442_CCLK | ICE1712_VX442_CODEC_CHIP_A | ICE1712_VX442_CODEC_CHIP_B;
99                 tmp &= ~ICE1712_VX442_CS_DIGITAL;
100                 break;
101         }
102         snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp);
103         udelay(5);
104         return tmp;
105 }
106
107 /* deassert chip select */
108 static void ap_cs8427_codec_deassert(ice1712_t *ice, unsigned char tmp)
109 {
110         switch (ice->eeprom.subvendor) {
111         case ICE1712_SUBDEVICE_DELTA1010LT:
112                 tmp &= ~ICE1712_DELTA_1010LT_CS;
113                 tmp |= ICE1712_DELTA_1010LT_CS_NONE;
114                 break;
115         case ICE1712_SUBDEVICE_AUDIOPHILE:
116         case ICE1712_SUBDEVICE_DELTA410:
117                 tmp |= ICE1712_DELTA_AP_CS_DIGITAL;
118                 break;
119         case ICE1712_SUBDEVICE_VX442:
120                 tmp |= ICE1712_VX442_CS_DIGITAL;
121                 break;
122         }
123         snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp);
124 }
125
126 /* sequential write */
127 static int ap_cs8427_sendbytes(snd_i2c_device_t *device, unsigned char *bytes, int count)
128 {
129         ice1712_t *ice = snd_magic_cast(ice1712_t, device->bus->private_data, return -EIO);
130         int res = count;
131         unsigned char tmp;
132
133         down(&ice->gpio_mutex);
134         tmp = ap_cs8427_codec_select(ice);
135         ap_cs8427_write_byte(ice, (device->addr << 1) | 0, tmp); /* address + write mode */
136         while (count-- > 0)
137                 ap_cs8427_write_byte(ice, *bytes++, tmp);
138         ap_cs8427_codec_deassert(ice, tmp);
139         up(&ice->gpio_mutex);
140         return res;
141 }
142
143 /* sequential read */
144 static int ap_cs8427_readbytes(snd_i2c_device_t *device, unsigned char *bytes, int count)
145 {
146         ice1712_t *ice = snd_magic_cast(ice1712_t, device->bus->private_data, return -EIO);
147         int res = count;
148         unsigned char tmp;
149         
150         down(&ice->gpio_mutex);
151         tmp = ap_cs8427_codec_select(ice);
152         ap_cs8427_write_byte(ice, (device->addr << 1) | 1, tmp); /* address + read mode */
153         while (count-- > 0)
154                 *bytes++ = ap_cs8427_read_byte(ice, tmp);
155         ap_cs8427_codec_deassert(ice, tmp);
156         up(&ice->gpio_mutex);
157         return res;
158 }
159
160 static int ap_cs8427_probeaddr(snd_i2c_bus_t *bus, unsigned short addr)
161 {
162         if (addr == 0x10)
163                 return 1;
164         return -ENOENT;
165 }
166
167 static snd_i2c_ops_t ap_cs8427_i2c_ops = {
168         .sendbytes = ap_cs8427_sendbytes,
169         .readbytes = ap_cs8427_readbytes,
170         .probeaddr = ap_cs8427_probeaddr,
171 };
172
173 /*
174  */
175
176 static void snd_ice1712_delta_cs8403_spdif_write(ice1712_t *ice, unsigned char bits)
177 {
178         unsigned char tmp, mask1, mask2;
179         int idx;
180         /* send byte to transmitter */
181         mask1 = ICE1712_DELTA_SPDIF_OUT_STAT_CLOCK;
182         mask2 = ICE1712_DELTA_SPDIF_OUT_STAT_DATA;
183         down(&ice->gpio_mutex);
184         tmp = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA);
185         for (idx = 7; idx >= 0; idx--) {
186                 tmp &= ~(mask1 | mask2);
187                 if (bits & (1 << idx))
188                         tmp |= mask2;
189                 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp);
190                 udelay(100);
191                 tmp |= mask1;
192                 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp);
193                 udelay(100);
194         }
195         tmp &= ~mask1;
196         snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp);
197         up(&ice->gpio_mutex);
198 }
199
200
201 static void delta_spdif_default_get(ice1712_t *ice, snd_ctl_elem_value_t * ucontrol)
202 {
203         snd_cs8403_decode_spdif_bits(&ucontrol->value.iec958, ice->spdif.cs8403_bits);
204 }
205
206 static int delta_spdif_default_put(ice1712_t *ice, snd_ctl_elem_value_t * ucontrol)
207 {
208         unsigned int val;
209         int change;
210
211         val = snd_cs8403_encode_spdif_bits(&ucontrol->value.iec958);
212         spin_lock_irq(&ice->reg_lock);
213         change = ice->spdif.cs8403_bits != val;
214         ice->spdif.cs8403_bits = val;
215         if (change && ice->playback_pro_substream == NULL) {
216                 spin_unlock_irq(&ice->reg_lock);
217                 snd_ice1712_delta_cs8403_spdif_write(ice, val);
218         } else {
219                 spin_unlock_irq(&ice->reg_lock);
220         }
221         return change;
222 }
223
224 static void delta_spdif_stream_get(ice1712_t *ice, snd_ctl_elem_value_t * ucontrol)
225 {
226         snd_cs8403_decode_spdif_bits(&ucontrol->value.iec958, ice->spdif.cs8403_stream_bits);
227 }
228
229 static int delta_spdif_stream_put(ice1712_t *ice, snd_ctl_elem_value_t * ucontrol)
230 {
231         unsigned int val;
232         int change;
233
234         val = snd_cs8403_encode_spdif_bits(&ucontrol->value.iec958);
235         spin_lock_irq(&ice->reg_lock);
236         change = ice->spdif.cs8403_stream_bits != val;
237         ice->spdif.cs8403_stream_bits = val;
238         if (change && ice->playback_pro_substream != NULL) {
239                 spin_unlock_irq(&ice->reg_lock);
240                 snd_ice1712_delta_cs8403_spdif_write(ice, val);
241         } else {
242                 spin_unlock_irq(&ice->reg_lock);
243         }
244         return change;
245 }
246
247
248 /*
249  * AK4524 on Delta 44 and 66 to choose the chip mask
250  */
251 static void delta_ak4524_lock(akm4xxx_t *ak, int chip)
252 {
253         struct snd_ak4xxx_private *priv = (void *)ak->private_value[0];
254         ice1712_t *ice = ak->private_data[0];
255
256         snd_ice1712_save_gpio_status(ice);
257         priv->cs_mask =
258         priv->cs_addr = chip == 0 ? ICE1712_DELTA_CODEC_CHIP_A :
259                                     ICE1712_DELTA_CODEC_CHIP_B;
260 }
261
262 /*
263  * AK4524 on Delta1010LT to choose the chip address
264  */
265 static void delta1010lt_ak4524_lock(akm4xxx_t *ak, int chip)
266 {
267         struct snd_ak4xxx_private *priv = (void *)ak->private_value[0];
268         ice1712_t *ice = ak->private_data[0];
269
270         snd_ice1712_save_gpio_status(ice);
271         priv->cs_mask = ICE1712_DELTA_1010LT_CS;
272         priv->cs_addr = chip << 4;
273 }
274
275 /*
276  * AK4528 on VX442 to choose the chip mask
277  */
278 static void vx442_ak4524_lock(akm4xxx_t *ak, int chip)
279 {
280         struct snd_ak4xxx_private *priv = (void *)ak->private_value[0];
281         ice1712_t *ice = ak->private_data[0];
282
283         snd_ice1712_save_gpio_status(ice);
284         priv->cs_mask =
285         priv->cs_addr = chip == 0 ? ICE1712_VX442_CODEC_CHIP_A :
286                                     ICE1712_VX442_CODEC_CHIP_B;
287 }
288
289 /*
290  * change the DFS bit according rate for Delta1010
291  */
292 static void delta_1010_set_rate_val(ice1712_t *ice, unsigned int rate)
293 {
294         unsigned char tmp, tmp2;
295
296         if (rate == 0)  /* no hint - S/PDIF input is master, simply return */
297                 return;
298
299         down(&ice->gpio_mutex);
300         tmp = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA);
301         tmp2 = tmp & ~ICE1712_DELTA_DFS;
302         if (rate > 48000)
303                 tmp2 |= ICE1712_DELTA_DFS;
304         if (tmp != tmp2)
305                 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp2);
306         up(&ice->gpio_mutex);
307 }
308
309 /*
310  * change the rate of AK4524 on Delta 44/66, AP, 1010LT
311  */
312 static void delta_ak4524_set_rate_val(akm4xxx_t *ak, unsigned int rate)
313 {
314         unsigned char tmp, tmp2;
315         ice1712_t *ice = ak->private_data[0];
316
317         if (rate == 0)  /* no hint - S/PDIF input is master, simply return */
318                 return;
319
320         /* check before reset ak4524 to avoid unnecessary clicks */
321         down(&ice->gpio_mutex);
322         tmp = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA);
323         up(&ice->gpio_mutex);
324         tmp2 = tmp & ~ICE1712_DELTA_DFS; 
325         if (rate > 48000)
326                 tmp2 |= ICE1712_DELTA_DFS;
327         if (tmp == tmp2)
328                 return;
329
330         /* do it again */
331         snd_akm4xxx_reset(ak, 1);
332         down(&ice->gpio_mutex);
333         tmp = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA) & ~ICE1712_DELTA_DFS;
334         if (rate > 48000)
335                 tmp |= ICE1712_DELTA_DFS;
336         snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp);
337         up(&ice->gpio_mutex);
338         snd_akm4xxx_reset(ak, 0);
339 }
340
341 /*
342  * change the rate of AK4524 on VX442
343  */
344 static void vx442_ak4524_set_rate_val(akm4xxx_t *ak, unsigned int rate)
345 {
346         unsigned char val;
347
348         val = (rate > 48000) ? 0x65 : 0x60;
349         if (snd_akm4xxx_get(ak, 0, 0x02) != val ||
350             snd_akm4xxx_get(ak, 1, 0x02) != val) {
351                 snd_akm4xxx_reset(ak, 1);
352                 snd_akm4xxx_write(ak, 0, 0x02, val);
353                 snd_akm4xxx_write(ak, 1, 0x02, val);
354                 snd_akm4xxx_reset(ak, 0);
355         }
356 }
357
358
359 /*
360  * SPDIF ops for Delta 1010, Dio, 66
361  */
362
363 /* open callback */
364 static void delta_open_spdif(ice1712_t *ice, snd_pcm_substream_t * substream)
365 {
366         ice->spdif.cs8403_stream_bits = ice->spdif.cs8403_bits;
367 }
368
369 /* set up */
370 static void delta_setup_spdif(ice1712_t *ice, int rate)
371 {
372         unsigned long flags;
373         unsigned int tmp;
374         int change;
375
376         spin_lock_irqsave(&ice->reg_lock, flags);
377         tmp = ice->spdif.cs8403_stream_bits;
378         if (tmp & 0x01)         /* consumer */
379                 tmp &= (tmp & 0x01) ? ~0x06 : ~0x18;
380         switch (rate) {
381         case 32000: tmp |= (tmp & 0x01) ? 0x04 : 0x00; break;
382         case 44100: tmp |= (tmp & 0x01) ? 0x00 : 0x10; break;
383         case 48000: tmp |= (tmp & 0x01) ? 0x02 : 0x08; break;
384         default: tmp |= (tmp & 0x01) ? 0x00 : 0x18; break;
385         }
386         change = ice->spdif.cs8403_stream_bits != tmp;
387         ice->spdif.cs8403_stream_bits = tmp;
388         spin_unlock_irqrestore(&ice->reg_lock, flags);
389         if (change)
390                 snd_ctl_notify(ice->card, SNDRV_CTL_EVENT_MASK_VALUE, &ice->spdif.stream_ctl->id);
391         snd_ice1712_delta_cs8403_spdif_write(ice, tmp);
392 }
393
394
395 /*
396  * initialize the chips on M-Audio cards
397  */
398
399 static akm4xxx_t akm_audiophile __devinitdata = {
400         .type = SND_AK4528,
401         .num_adcs = 2,
402         .num_dacs = 2,
403         .ops = {
404                 .set_rate_val = delta_ak4524_set_rate_val
405         }
406 };
407
408 static struct snd_ak4xxx_private akm_audiophile_priv __devinitdata = {
409         .caddr = 2,
410         .cif = 0,
411         .data_mask = ICE1712_DELTA_AP_DOUT,
412         .clk_mask = ICE1712_DELTA_AP_CCLK,
413         .cs_mask = ICE1712_DELTA_AP_CS_CODEC,
414         .cs_addr = ICE1712_DELTA_AP_CS_CODEC,
415         .cs_none = 0,
416         .add_flags = ICE1712_DELTA_AP_CS_DIGITAL,
417         .mask_flags = 0,
418 };
419
420 static akm4xxx_t akm_delta410 __devinitdata = {
421         .type = SND_AK4529,
422         .num_adcs = 2,
423         .num_dacs = 8,
424         .ops = {
425                 .set_rate_val = delta_ak4524_set_rate_val
426         }
427 };
428
429 static struct snd_ak4xxx_private akm_delta410_priv __devinitdata = {
430         .caddr = 0,
431         .cif = 0,
432         .data_mask = ICE1712_DELTA_AP_DOUT,
433         .clk_mask = ICE1712_DELTA_AP_CCLK,
434         .cs_mask = ICE1712_DELTA_AP_CS_CODEC,
435         .cs_addr = ICE1712_DELTA_AP_CS_CODEC,
436         .cs_none = 0,
437         .add_flags = ICE1712_DELTA_AP_CS_DIGITAL,
438         .mask_flags = 0,
439 };
440
441 static akm4xxx_t akm_delta1010lt __devinitdata = {
442         .type = SND_AK4524,
443         .num_adcs = 8,
444         .num_dacs = 8,
445         .ops = {
446                 .lock = delta1010lt_ak4524_lock,
447                 .set_rate_val = delta_ak4524_set_rate_val
448         }
449 };
450
451 static struct snd_ak4xxx_private akm_delta1010lt_priv __devinitdata = {
452         .caddr = 2,
453         .cif = 0, /* the default level of the CIF pin from AK4524 */
454         .data_mask = ICE1712_DELTA_1010LT_DOUT,
455         .clk_mask = ICE1712_DELTA_1010LT_CCLK,
456         .cs_mask = 0,
457         .cs_addr = 0, /* set later */
458         .cs_none = ICE1712_DELTA_1010LT_CS_NONE,
459         .add_flags = 0,
460         .mask_flags = 0,
461 };
462
463 static akm4xxx_t akm_delta44 __devinitdata = {
464         .type = SND_AK4524,
465         .num_adcs = 4,
466         .num_dacs = 4,
467         .ops = {
468                 .lock = delta_ak4524_lock,
469                 .set_rate_val = delta_ak4524_set_rate_val
470         }
471 };
472
473 static struct snd_ak4xxx_private akm_delta44_priv __devinitdata = {
474         .caddr = 2,
475         .cif = 0, /* the default level of the CIF pin from AK4524 */
476         .data_mask = ICE1712_DELTA_CODEC_SERIAL_DATA,
477         .clk_mask = ICE1712_DELTA_CODEC_SERIAL_CLOCK,
478         .cs_mask = 0,
479         .cs_addr = 0, /* set later */
480         .cs_none = 0,
481         .add_flags = 0,
482         .mask_flags = 0,
483 };
484
485 static akm4xxx_t akm_vx442 __devinitdata = {
486         .type = SND_AK4524,
487         .num_adcs = 4,
488         .num_dacs = 4,
489         .ops = {
490                 .lock = vx442_ak4524_lock,
491                 .set_rate_val = vx442_ak4524_set_rate_val
492         }
493 };
494
495 static struct snd_ak4xxx_private akm_vx442_priv __devinitdata = {
496         .caddr = 2,
497         .cif = 0,
498         .data_mask = ICE1712_VX442_DOUT,
499         .clk_mask = ICE1712_VX442_CCLK,
500         .cs_mask = 0,
501         .cs_addr = 0, /* set later */
502         .cs_none = 0,
503         .add_flags = 0,
504         .mask_flags = 0,
505 };
506
507 static int __devinit snd_ice1712_delta_init(ice1712_t *ice)
508 {
509         int err;
510         akm4xxx_t *ak;
511
512         /* determine I2C, DACs and ADCs */
513         switch (ice->eeprom.subvendor) {
514         case ICE1712_SUBDEVICE_AUDIOPHILE:
515                 ice->num_total_dacs = 2;
516                 ice->num_total_adcs = 2;
517                 break;
518         case ICE1712_SUBDEVICE_DELTA410:
519                 ice->num_total_dacs = 8;
520                 ice->num_total_adcs = 2;
521                 break;
522         case ICE1712_SUBDEVICE_DELTA44:
523         case ICE1712_SUBDEVICE_DELTA66:
524                 ice->num_total_dacs = ice->omni ? 8 : 4;
525                 ice->num_total_adcs = ice->omni ? 8 : 4;
526                 break;
527         case ICE1712_SUBDEVICE_DELTA1010:
528         case ICE1712_SUBDEVICE_DELTA1010LT:
529                 ice->num_total_dacs = 8;
530                 ice->num_total_adcs = 8;
531                 break;
532         case ICE1712_SUBDEVICE_VX442:
533                 ice->num_total_dacs = 4;
534                 ice->num_total_adcs = 4;
535                 break;
536         }
537
538         /* initialize spdif */
539         switch (ice->eeprom.subvendor) {
540         case ICE1712_SUBDEVICE_AUDIOPHILE:
541         case ICE1712_SUBDEVICE_DELTA410:
542         case ICE1712_SUBDEVICE_DELTA1010LT:
543         case ICE1712_SUBDEVICE_VX442:
544                 if ((err = snd_i2c_bus_create(ice->card, "ICE1712 GPIO 1", NULL, &ice->i2c)) < 0) {
545                         snd_printk("unable to create I2C bus\n");
546                         return err;
547                 }
548                 ice->i2c->private_data = ice;
549                 ice->i2c->ops = &ap_cs8427_i2c_ops;
550                 if ((err = snd_ice1712_init_cs8427(ice, CS8427_BASE_ADDR)) < 0)
551                         return err;
552                 break;
553         case ICE1712_SUBDEVICE_DELTA1010:
554                 ice->gpio.set_pro_rate = delta_1010_set_rate_val;
555                 break;
556         case ICE1712_SUBDEVICE_DELTADIO2496:
557                 ice->gpio.set_pro_rate = delta_1010_set_rate_val;
558                 /* fall thru */
559         case ICE1712_SUBDEVICE_DELTA66:
560                 ice->spdif.ops.open = delta_open_spdif;
561                 ice->spdif.ops.setup_rate = delta_setup_spdif;
562                 ice->spdif.ops.default_get = delta_spdif_default_get;
563                 ice->spdif.ops.default_put = delta_spdif_default_put;
564                 ice->spdif.ops.stream_get = delta_spdif_stream_get;
565                 ice->spdif.ops.stream_put = delta_spdif_stream_put;
566                 /* Set spdif defaults */
567                 snd_ice1712_delta_cs8403_spdif_write(ice, ice->spdif.cs8403_bits);
568                 break;
569         }
570
571         /* no analog? */
572         switch (ice->eeprom.subvendor) {
573         case ICE1712_SUBDEVICE_DELTA1010:
574         case ICE1712_SUBDEVICE_DELTADIO2496:
575                 return 0;
576         }
577
578         /* second stage of initialization, analog parts and others */
579         ak = ice->akm = kmalloc(sizeof(akm4xxx_t), GFP_KERNEL);
580         if (! ak)
581                 return -ENOMEM;
582         ice->akm_codecs = 1;
583
584         switch (ice->eeprom.subvendor) {
585         case ICE1712_SUBDEVICE_AUDIOPHILE:
586                 err = snd_ice1712_akm4xxx_init(ak, &akm_audiophile, &akm_audiophile_priv, ice);
587                 break;
588         case ICE1712_SUBDEVICE_DELTA410:
589                 err = snd_ice1712_akm4xxx_init(ak, &akm_delta410, &akm_delta410_priv, ice);
590                 break;
591         case ICE1712_SUBDEVICE_DELTA1010LT:
592                 err = snd_ice1712_akm4xxx_init(ak, &akm_delta1010lt, &akm_delta1010lt_priv, ice);
593                 break;
594         case ICE1712_SUBDEVICE_DELTA66:
595         case ICE1712_SUBDEVICE_DELTA44:
596                 err = snd_ice1712_akm4xxx_init(ak, &akm_delta44, &akm_delta44_priv, ice);
597                 break;
598         case ICE1712_SUBDEVICE_VX442:
599                 err = snd_ice1712_akm4xxx_init(ak, &akm_vx442, &akm_vx442_priv, ice);
600                 break;
601         default:
602                 snd_BUG();
603                 return -EINVAL;
604         }
605
606         return err;
607 }
608
609
610 /*
611  * additional controls for M-Audio cards
612  */
613
614 static snd_kcontrol_new_t snd_ice1712_delta1010_wordclock_select __devinitdata =
615 ICE1712_GPIO(SNDRV_CTL_ELEM_IFACE_PCM, "Word Clock Sync", 0, ICE1712_DELTA_WORD_CLOCK_SELECT, 1, 0);
616 static snd_kcontrol_new_t snd_ice1712_delta1010lt_wordclock_select __devinitdata =
617 ICE1712_GPIO(SNDRV_CTL_ELEM_IFACE_PCM, "Word Clock Sync", 0, ICE1712_DELTA_1010LT_WORDCLOCK, 1, 0);
618 static snd_kcontrol_new_t snd_ice1712_delta1010_wordclock_status __devinitdata =
619 ICE1712_GPIO(SNDRV_CTL_ELEM_IFACE_PCM, "Word Clock Status", 0, ICE1712_DELTA_WORD_CLOCK_STATUS, 1, SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE);
620 static snd_kcontrol_new_t snd_ice1712_deltadio2496_spdif_in_select __devinitdata =
621 ICE1712_GPIO(SNDRV_CTL_ELEM_IFACE_PCM, "IEC958 Input Optical", 0, ICE1712_DELTA_SPDIF_INPUT_SELECT, 0, 0);
622 static snd_kcontrol_new_t snd_ice1712_delta_spdif_in_status __devinitdata =
623 ICE1712_GPIO(SNDRV_CTL_ELEM_IFACE_PCM, "Delta IEC958 Input Status", 0, ICE1712_DELTA_SPDIF_IN_STAT, 1, SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE);
624
625
626 static int __devinit snd_ice1712_delta_add_controls(ice1712_t *ice)
627 {
628         int err;
629
630         /* 1010 and dio specific controls */
631         switch (ice->eeprom.subvendor) {
632         case ICE1712_SUBDEVICE_DELTA1010:
633                 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_delta1010_wordclock_select, ice));
634                 if (err < 0)
635                         return err;
636                 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_delta1010_wordclock_status, ice));
637                 if (err < 0)
638                         return err;
639                 break;
640         case ICE1712_SUBDEVICE_DELTADIO2496:
641                 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_deltadio2496_spdif_in_select, ice));
642                 if (err < 0)
643                         return err;
644                 break;
645         case ICE1712_SUBDEVICE_DELTA1010LT:
646                 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_delta1010lt_wordclock_select, ice));
647                 if (err < 0)
648                         return err;
649                 break;
650         }
651
652         /* normal spdif controls */
653         switch (ice->eeprom.subvendor) {
654         case ICE1712_SUBDEVICE_DELTA1010:
655         case ICE1712_SUBDEVICE_DELTADIO2496:
656         case ICE1712_SUBDEVICE_DELTA66:
657                 err = snd_ice1712_spdif_build_controls(ice);
658                 if (err < 0)
659                         return err;
660                 break;
661         }
662
663         /* spdif status in */
664         switch (ice->eeprom.subvendor) {
665         case ICE1712_SUBDEVICE_DELTA1010:
666         case ICE1712_SUBDEVICE_DELTADIO2496:
667         case ICE1712_SUBDEVICE_DELTA66:
668                 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_delta_spdif_in_status, ice));
669                 if (err < 0)
670                         return err;
671                 break;
672         }
673
674         /* ak4524 controls */
675         switch (ice->eeprom.subvendor) {
676         case ICE1712_SUBDEVICE_DELTA1010LT:
677         case ICE1712_SUBDEVICE_AUDIOPHILE:
678         case ICE1712_SUBDEVICE_DELTA410:
679         case ICE1712_SUBDEVICE_DELTA44:
680         case ICE1712_SUBDEVICE_DELTA66:
681         case ICE1712_SUBDEVICE_VX442:
682                 err = snd_ice1712_akm4xxx_build_controls(ice);
683                 if (err < 0)
684                         return err;
685                 break;
686         }
687
688         return 0;
689 }
690
691
692 /* entry point */
693 struct snd_ice1712_card_info snd_ice1712_delta_cards[] __devinitdata = {
694         {
695                 .subvendor = ICE1712_SUBDEVICE_DELTA1010,
696                 .name = "M Audio Delta 1010",
697                 .model = "delta1010",
698                 .chip_init = snd_ice1712_delta_init,
699                 .build_controls = snd_ice1712_delta_add_controls,
700         },
701         {
702                 .subvendor = ICE1712_SUBDEVICE_DELTADIO2496,
703                 .name = "M Audio Delta DiO 2496",
704                 .model = "dio2496",
705                 .chip_init = snd_ice1712_delta_init,
706                 .build_controls = snd_ice1712_delta_add_controls,
707                 .no_mpu401 = 1,
708         },
709         {
710                 .subvendor = ICE1712_SUBDEVICE_DELTA66,
711                 .name = "M Audio Delta 66",
712                 .model = "delta66",
713                 .chip_init = snd_ice1712_delta_init,
714                 .build_controls = snd_ice1712_delta_add_controls,
715                 .no_mpu401 = 1,
716         },
717         {
718                 .subvendor = ICE1712_SUBDEVICE_DELTA44,
719                 .name = "M Audio Delta 44",
720                 .model = "delta44",
721                 .chip_init = snd_ice1712_delta_init,
722                 .build_controls = snd_ice1712_delta_add_controls,
723                 .no_mpu401 = 1,
724         },
725         {
726                 .subvendor = ICE1712_SUBDEVICE_AUDIOPHILE,
727                 .name = "M Audio Audiophile 24/96",
728                 .model = "audiophile",
729                 .chip_init = snd_ice1712_delta_init,
730                 .build_controls = snd_ice1712_delta_add_controls,
731         },
732         {
733                 .subvendor = ICE1712_SUBDEVICE_DELTA410,
734                 .name = "M Audio Delta 410",
735                 .model = "delta410",
736                 .chip_init = snd_ice1712_delta_init,
737                 .build_controls = snd_ice1712_delta_add_controls,
738         },
739         {
740                 .subvendor = ICE1712_SUBDEVICE_DELTA1010LT,
741                 .name = "M Audio Delta 1010LT",
742                 .model = "delta1010lt",
743                 .chip_init = snd_ice1712_delta_init,
744                 .build_controls = snd_ice1712_delta_add_controls,
745         },
746         {
747                 .subvendor = ICE1712_SUBDEVICE_VX442,
748                 .name = "Digigram VX442",
749                 .model = "vx442",
750                 .chip_init = snd_ice1712_delta_init,
751                 .build_controls = snd_ice1712_delta_add_controls,
752                 .no_mpu401 = 1,
753         },
754         { } /* terminator */
755 };