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