upgrade to linux 2.6.10-1.12_FC2
[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 = device->bus->private_data;
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 = device->bus->private_data;
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         case ICE1712_SUBDEVICE_MEDIASTATION:
530                 ice->num_total_dacs = 8;
531                 ice->num_total_adcs = 8;
532                 break;
533         case ICE1712_SUBDEVICE_VX442:
534                 ice->num_total_dacs = 4;
535                 ice->num_total_adcs = 4;
536                 break;
537         }
538
539         /* initialize spdif */
540         switch (ice->eeprom.subvendor) {
541         case ICE1712_SUBDEVICE_AUDIOPHILE:
542         case ICE1712_SUBDEVICE_DELTA410:
543         case ICE1712_SUBDEVICE_DELTA1010LT:
544         case ICE1712_SUBDEVICE_VX442:
545                 if ((err = snd_i2c_bus_create(ice->card, "ICE1712 GPIO 1", NULL, &ice->i2c)) < 0) {
546                         snd_printk("unable to create I2C bus\n");
547                         return err;
548                 }
549                 ice->i2c->private_data = ice;
550                 ice->i2c->ops = &ap_cs8427_i2c_ops;
551                 if ((err = snd_ice1712_init_cs8427(ice, CS8427_BASE_ADDR)) < 0)
552                         return err;
553                 break;
554         case ICE1712_SUBDEVICE_DELTA1010:
555         case ICE1712_SUBDEVICE_MEDIASTATION:
556                 ice->gpio.set_pro_rate = delta_1010_set_rate_val;
557                 break;
558         case ICE1712_SUBDEVICE_DELTADIO2496:
559                 ice->gpio.set_pro_rate = delta_1010_set_rate_val;
560                 /* fall thru */
561         case ICE1712_SUBDEVICE_DELTA66:
562                 ice->spdif.ops.open = delta_open_spdif;
563                 ice->spdif.ops.setup_rate = delta_setup_spdif;
564                 ice->spdif.ops.default_get = delta_spdif_default_get;
565                 ice->spdif.ops.default_put = delta_spdif_default_put;
566                 ice->spdif.ops.stream_get = delta_spdif_stream_get;
567                 ice->spdif.ops.stream_put = delta_spdif_stream_put;
568                 /* Set spdif defaults */
569                 snd_ice1712_delta_cs8403_spdif_write(ice, ice->spdif.cs8403_bits);
570                 break;
571         }
572
573         /* no analog? */
574         switch (ice->eeprom.subvendor) {
575         case ICE1712_SUBDEVICE_DELTA1010:
576         case ICE1712_SUBDEVICE_DELTADIO2496:
577         case ICE1712_SUBDEVICE_MEDIASTATION:
578                 return 0;
579         }
580
581         /* second stage of initialization, analog parts and others */
582         ak = ice->akm = kmalloc(sizeof(akm4xxx_t), GFP_KERNEL);
583         if (! ak)
584                 return -ENOMEM;
585         ice->akm_codecs = 1;
586
587         switch (ice->eeprom.subvendor) {
588         case ICE1712_SUBDEVICE_AUDIOPHILE:
589                 err = snd_ice1712_akm4xxx_init(ak, &akm_audiophile, &akm_audiophile_priv, ice);
590                 break;
591         case ICE1712_SUBDEVICE_DELTA410:
592                 err = snd_ice1712_akm4xxx_init(ak, &akm_delta410, &akm_delta410_priv, ice);
593                 break;
594         case ICE1712_SUBDEVICE_DELTA1010LT:
595                 err = snd_ice1712_akm4xxx_init(ak, &akm_delta1010lt, &akm_delta1010lt_priv, ice);
596                 break;
597         case ICE1712_SUBDEVICE_DELTA66:
598         case ICE1712_SUBDEVICE_DELTA44:
599                 err = snd_ice1712_akm4xxx_init(ak, &akm_delta44, &akm_delta44_priv, ice);
600                 break;
601         case ICE1712_SUBDEVICE_VX442:
602                 err = snd_ice1712_akm4xxx_init(ak, &akm_vx442, &akm_vx442_priv, ice);
603                 break;
604         default:
605                 snd_BUG();
606                 return -EINVAL;
607         }
608
609         return err;
610 }
611
612
613 /*
614  * additional controls for M-Audio cards
615  */
616
617 static snd_kcontrol_new_t snd_ice1712_delta1010_wordclock_select __devinitdata =
618 ICE1712_GPIO(SNDRV_CTL_ELEM_IFACE_PCM, "Word Clock Sync", 0, ICE1712_DELTA_WORD_CLOCK_SELECT, 1, 0);
619 static snd_kcontrol_new_t snd_ice1712_delta1010lt_wordclock_select __devinitdata =
620 ICE1712_GPIO(SNDRV_CTL_ELEM_IFACE_PCM, "Word Clock Sync", 0, ICE1712_DELTA_1010LT_WORDCLOCK, 1, 0);
621 static snd_kcontrol_new_t snd_ice1712_delta1010_wordclock_status __devinitdata =
622 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);
623 static snd_kcontrol_new_t snd_ice1712_deltadio2496_spdif_in_select __devinitdata =
624 ICE1712_GPIO(SNDRV_CTL_ELEM_IFACE_PCM, "IEC958 Input Optical", 0, ICE1712_DELTA_SPDIF_INPUT_SELECT, 0, 0);
625 static snd_kcontrol_new_t snd_ice1712_delta_spdif_in_status __devinitdata =
626 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);
627
628
629 static int __devinit snd_ice1712_delta_add_controls(ice1712_t *ice)
630 {
631         int err;
632
633         /* 1010 and dio specific controls */
634         switch (ice->eeprom.subvendor) {
635         case ICE1712_SUBDEVICE_DELTA1010:
636         case ICE1712_SUBDEVICE_MEDIASTATION:
637                 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_delta1010_wordclock_select, ice));
638                 if (err < 0)
639                         return err;
640                 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_delta1010_wordclock_status, ice));
641                 if (err < 0)
642                         return err;
643                 break;
644         case ICE1712_SUBDEVICE_DELTADIO2496:
645                 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_deltadio2496_spdif_in_select, ice));
646                 if (err < 0)
647                         return err;
648                 break;
649         case ICE1712_SUBDEVICE_DELTA1010LT:
650                 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_delta1010lt_wordclock_select, ice));
651                 if (err < 0)
652                         return err;
653                 break;
654         }
655
656         /* normal spdif controls */
657         switch (ice->eeprom.subvendor) {
658         case ICE1712_SUBDEVICE_DELTA1010:
659         case ICE1712_SUBDEVICE_DELTADIO2496:
660         case ICE1712_SUBDEVICE_DELTA66:
661         case ICE1712_SUBDEVICE_MEDIASTATION:
662                 err = snd_ice1712_spdif_build_controls(ice);
663                 if (err < 0)
664                         return err;
665                 break;
666         }
667
668         /* spdif status in */
669         switch (ice->eeprom.subvendor) {
670         case ICE1712_SUBDEVICE_DELTA1010:
671         case ICE1712_SUBDEVICE_DELTADIO2496:
672         case ICE1712_SUBDEVICE_DELTA66:
673         case ICE1712_SUBDEVICE_MEDIASTATION:
674                 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_delta_spdif_in_status, ice));
675                 if (err < 0)
676                         return err;
677                 break;
678         }
679
680         /* ak4524 controls */
681         switch (ice->eeprom.subvendor) {
682         case ICE1712_SUBDEVICE_DELTA1010LT:
683         case ICE1712_SUBDEVICE_AUDIOPHILE:
684         case ICE1712_SUBDEVICE_DELTA410:
685         case ICE1712_SUBDEVICE_DELTA44:
686         case ICE1712_SUBDEVICE_DELTA66:
687         case ICE1712_SUBDEVICE_VX442:
688                 err = snd_ice1712_akm4xxx_build_controls(ice);
689                 if (err < 0)
690                         return err;
691                 break;
692         }
693
694         return 0;
695 }
696
697
698 /* entry point */
699 struct snd_ice1712_card_info snd_ice1712_delta_cards[] __devinitdata = {
700         {
701                 .subvendor = ICE1712_SUBDEVICE_DELTA1010,
702                 .name = "M Audio Delta 1010",
703                 .model = "delta1010",
704                 .chip_init = snd_ice1712_delta_init,
705                 .build_controls = snd_ice1712_delta_add_controls,
706         },
707         {
708                 .subvendor = ICE1712_SUBDEVICE_DELTADIO2496,
709                 .name = "M Audio Delta DiO 2496",
710                 .model = "dio2496",
711                 .chip_init = snd_ice1712_delta_init,
712                 .build_controls = snd_ice1712_delta_add_controls,
713                 .no_mpu401 = 1,
714         },
715         {
716                 .subvendor = ICE1712_SUBDEVICE_DELTA66,
717                 .name = "M Audio Delta 66",
718                 .model = "delta66",
719                 .chip_init = snd_ice1712_delta_init,
720                 .build_controls = snd_ice1712_delta_add_controls,
721                 .no_mpu401 = 1,
722         },
723         {
724                 .subvendor = ICE1712_SUBDEVICE_DELTA44,
725                 .name = "M Audio Delta 44",
726                 .model = "delta44",
727                 .chip_init = snd_ice1712_delta_init,
728                 .build_controls = snd_ice1712_delta_add_controls,
729                 .no_mpu401 = 1,
730         },
731         {
732                 .subvendor = ICE1712_SUBDEVICE_AUDIOPHILE,
733                 .name = "M Audio Audiophile 24/96",
734                 .model = "audiophile",
735                 .chip_init = snd_ice1712_delta_init,
736                 .build_controls = snd_ice1712_delta_add_controls,
737         },
738         {
739                 .subvendor = ICE1712_SUBDEVICE_DELTA410,
740                 .name = "M Audio Delta 410",
741                 .model = "delta410",
742                 .chip_init = snd_ice1712_delta_init,
743                 .build_controls = snd_ice1712_delta_add_controls,
744         },
745         {
746                 .subvendor = ICE1712_SUBDEVICE_DELTA1010LT,
747                 .name = "M Audio Delta 1010LT",
748                 .model = "delta1010lt",
749                 .chip_init = snd_ice1712_delta_init,
750                 .build_controls = snd_ice1712_delta_add_controls,
751         },
752         {
753                 .subvendor = ICE1712_SUBDEVICE_VX442,
754                 .name = "Digigram VX442",
755                 .model = "vx442",
756                 .chip_init = snd_ice1712_delta_init,
757                 .build_controls = snd_ice1712_delta_add_controls,
758                 .no_mpu401 = 1,
759         },
760         {
761                 .subvendor = ICE1712_SUBDEVICE_MEDIASTATION,
762                 .name = "Lionstracs Mediastation",
763                 .model = "mediastation",
764                 .chip_init = snd_ice1712_delta_init,
765                 .build_controls = snd_ice1712_delta_add_controls,
766         },
767         { } /* terminator */
768 };