2 * ALSA driver for VT1724 ICEnsemble ICE1724 / VIA VT1724 (Envy24HT)
4 * Copyright (c) 2000 Jaroslav Kysela <perex@suse.cz>
5 * 2002 James Stafford <jstafford@ampltd.com>
6 * 2003 Takashi Iwai <tiwai@suse.de>
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.
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.
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
24 #include <sound/driver.h>
26 #include <linux/delay.h>
27 #include <linux/interrupt.h>
28 #include <linux/init.h>
29 #include <linux/pci.h>
30 #include <linux/slab.h>
31 #include <sound/core.h>
32 #include <sound/info.h>
33 #include <sound/mpu401.h>
35 #include <sound/initval.h>
37 #include <sound/asoundef.h>
42 /* lowlevel routines */
49 MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
50 MODULE_DESCRIPTION("ICEnsemble ICE1724 (Envy24HT)");
51 MODULE_LICENSE("GPL");
52 MODULE_CLASSES("{sound}");
55 AMP_AUDIO2000_DEVICE_DESC
59 "{ICEnsemble,Generic ICE1724},"
60 "{ICEnsemble,Generic Envy24HT}}");
62 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
63 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
64 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */
66 MODULE_PARM(index, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
67 MODULE_PARM_DESC(index, "Index value for ICE1724 soundcard.");
68 MODULE_PARM_SYNTAX(index, SNDRV_INDEX_DESC);
69 MODULE_PARM(id, "1-" __MODULE_STRING(SNDRV_CARDS) "s");
70 MODULE_PARM_DESC(id, "ID string for ICE1724 soundcard.");
71 MODULE_PARM_SYNTAX(id, SNDRV_ID_DESC);
72 MODULE_PARM(enable, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
73 MODULE_PARM_DESC(enable, "Enable ICE1724 soundcard.");
74 MODULE_PARM_SYNTAX(enable, SNDRV_ENABLE_DESC);
76 #ifndef PCI_VENDOR_ID_ICE
77 #define PCI_VENDOR_ID_ICE 0x1412
79 #ifndef PCI_DEVICE_ID_VT1724
80 #define PCI_DEVICE_ID_VT1724 0x1724
83 static struct pci_device_id snd_vt1724_ids[] = {
84 { PCI_VENDOR_ID_ICE, PCI_DEVICE_ID_VT1724, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
88 MODULE_DEVICE_TABLE(pci, snd_vt1724_ids);
91 static int PRO_RATE_LOCKED;
92 static int PRO_RATE_RESET = 1;
93 static unsigned int PRO_RATE_DEFAULT = 44100;
99 /* check whether the clock mode is spdif-in */
100 static inline int is_spdif_master(ice1712_t *ice)
102 return (inb(ICEMT1724(ice, RATE)) & VT1724_SPDIF_MASTER) ? 1 : 0;
105 static inline int is_pro_rate_locked(ice1712_t *ice)
107 return is_spdif_master(ice) || PRO_RATE_LOCKED;
114 static unsigned char snd_vt1724_ac97_ready(ice1712_t *ice)
116 unsigned char old_cmd;
118 for (tm = 0; tm < 0x10000; tm++) {
119 old_cmd = inb(ICEMT1724(ice, AC97_CMD));
120 if (old_cmd & (VT1724_AC97_WRITE | VT1724_AC97_READ))
122 if (!(old_cmd & VT1724_AC97_READY))
126 snd_printd(KERN_ERR "snd_vt1724_ac97_ready: timeout\n");
130 static int snd_vt1724_ac97_wait_bit(ice1712_t *ice, unsigned char bit)
133 for (tm = 0; tm < 0x10000; tm++)
134 if ((inb(ICEMT1724(ice, AC97_CMD)) & bit) == 0)
136 snd_printd(KERN_ERR "snd_vt1724_ac97_wait_bit: timeout\n");
140 static void snd_vt1724_ac97_write(ac97_t *ac97,
144 ice1712_t *ice = (ice1712_t *)ac97->private_data;
145 unsigned char old_cmd;
147 old_cmd = snd_vt1724_ac97_ready(ice);
148 old_cmd &= ~VT1724_AC97_ID_MASK;
149 old_cmd |= ac97->num;
150 outb(reg, ICEMT1724(ice, AC97_INDEX));
151 outw(val, ICEMT1724(ice, AC97_DATA));
152 outb(old_cmd | VT1724_AC97_WRITE, ICEMT1724(ice, AC97_CMD));
153 snd_vt1724_ac97_wait_bit(ice, VT1724_AC97_WRITE);
156 static unsigned short snd_vt1724_ac97_read(ac97_t *ac97, unsigned short reg)
158 ice1712_t *ice = (ice1712_t *)ac97->private_data;
159 unsigned char old_cmd;
161 old_cmd = snd_vt1724_ac97_ready(ice);
162 old_cmd &= ~VT1724_AC97_ID_MASK;
163 old_cmd |= ac97->num;
164 outb(reg, ICEMT1724(ice, AC97_INDEX));
165 outb(old_cmd | VT1724_AC97_READ, ICEMT1724(ice, AC97_CMD));
166 if (snd_vt1724_ac97_wait_bit(ice, VT1724_AC97_READ) < 0)
168 return inw(ICEMT1724(ice, AC97_DATA));
176 /* set gpio direction 0 = read, 1 = write */
177 static void snd_vt1724_set_gpio_dir(ice1712_t *ice, unsigned int data)
179 outl(data, ICEREG1724(ice, GPIO_DIRECTION));
180 inw(ICEREG1724(ice, GPIO_DIRECTION)); /* dummy read for pci-posting */
183 /* set the gpio mask (0 = writable) */
184 static void snd_vt1724_set_gpio_mask(ice1712_t *ice, unsigned int data)
186 outw(data, ICEREG1724(ice, GPIO_WRITE_MASK));
187 outb((data >> 16) & 0xff, ICEREG1724(ice, GPIO_WRITE_MASK_22));
188 inw(ICEREG1724(ice, GPIO_WRITE_MASK)); /* dummy read for pci-posting */
191 static void snd_vt1724_set_gpio_data(ice1712_t *ice, unsigned int data)
193 outw(data, ICEREG1724(ice, GPIO_DATA));
194 outb(data >> 16, ICEREG1724(ice, GPIO_DATA_22));
195 inw(ICEREG1724(ice, GPIO_DATA)); /* dummy read for pci-posting */
198 static unsigned int snd_vt1724_get_gpio_data(ice1712_t *ice)
201 data = (unsigned int)inb(ICEREG1724(ice, GPIO_DATA_22));
202 data = (data << 16) | inw(ICEREG1724(ice, GPIO_DATA));
210 static irqreturn_t snd_vt1724_interrupt(int irq, void *dev_id, struct pt_regs *regs)
212 ice1712_t *ice = snd_magic_cast(ice1712_t, dev_id, return IRQ_NONE);
213 unsigned char status;
217 status = inb(ICEREG1724(ice, IRQSTAT));
222 /* these should probably be separated at some point,
223 but as we don't currently have MPU support on the board I will leave it */
224 if ((status & VT1724_IRQ_MPU_RX)||(status & VT1724_IRQ_MPU_TX)) {
226 snd_mpu401_uart_interrupt(irq, ice->rmidi[0]->private_data, regs);
227 outb(VT1724_IRQ_MPU_RX|VT1724_IRQ_MPU_TX, ICEREG1724(ice, IRQSTAT));
228 status &= ~(VT1724_IRQ_MPU_RX|VT1724_IRQ_MPU_TX);
230 if (status & VT1724_IRQ_MTPCM) {
231 unsigned char mtstat = inb(ICEMT1724(ice, IRQ));
232 if (mtstat & VT1724_MULTI_PDMA0) {
233 if (ice->playback_pro_substream)
234 snd_pcm_period_elapsed(ice->playback_pro_substream);
236 if (mtstat & VT1724_MULTI_RDMA0) {
237 if (ice->capture_pro_substream)
238 snd_pcm_period_elapsed(ice->capture_pro_substream);
240 if (mtstat & VT1724_MULTI_PDMA1) {
241 if (ice->playback_con_substream_ds[0])
242 snd_pcm_period_elapsed(ice->playback_con_substream_ds[0]);
244 if (mtstat & VT1724_MULTI_PDMA2) {
245 if (ice->playback_con_substream_ds[1])
246 snd_pcm_period_elapsed(ice->playback_con_substream_ds[1]);
248 if (mtstat & VT1724_MULTI_PDMA3) {
249 if (ice->playback_con_substream_ds[2])
250 snd_pcm_period_elapsed(ice->playback_con_substream_ds[2]);
252 if (mtstat & VT1724_MULTI_PDMA4) {
253 if (ice->playback_con_substream)
254 snd_pcm_period_elapsed(ice->playback_con_substream);
256 if (mtstat & VT1724_MULTI_RDMA1) {
257 if (ice->capture_con_substream)
258 snd_pcm_period_elapsed(ice->capture_con_substream);
260 /* ack anyway to avoid freeze */
261 outb(mtstat, ICEMT1724(ice, IRQ));
262 /* ought to really handle this properly */
263 if (mtstat & VT1724_MULTI_FIFO_ERR) {
264 unsigned char fstat = inb(ICEMT1724(ice, DMA_FIFO_ERR));
265 outb(fstat, ICEMT1724(ice, DMA_FIFO_ERR));
266 outb(VT1724_MULTI_FIFO_ERR | inb(ICEMT1724(ice, DMA_INT_MASK)), ICEMT1724(ice, DMA_INT_MASK));
267 /* If I don't do this, I get machine lockup due to continual interrupts */
272 return IRQ_RETVAL(handled);
276 * PCM code - professional part (multitrack)
279 static unsigned int rates[] = {
280 8000, 9600, 11025, 12000, 16000, 22050, 24000,
281 32000, 44100, 48000, 64000, 88200, 96000,
285 static snd_pcm_hw_constraint_list_t hw_constraints_rates_96 = {
286 .count = ARRAY_SIZE(rates) - 2, /* up to 96000 */
291 static snd_pcm_hw_constraint_list_t hw_constraints_rates_192 = {
292 .count = ARRAY_SIZE(rates),
297 static int snd_vt1724_pcm_trigger(snd_pcm_substream_t *substream, int cmd)
299 ice1712_t *ice = snd_pcm_substream_chip(substream);
302 struct list_head *pos;
303 snd_pcm_substream_t *s;
306 snd_pcm_group_for_each(pos, substream) {
307 s = snd_pcm_group_substream_entry(pos);
308 what |= (unsigned long)(s->runtime->private_data);
309 snd_pcm_trigger_done(s, substream);
313 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
314 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
315 spin_lock(&ice->reg_lock);
316 old = inb(ICEMT1724(ice, DMA_PAUSE));
317 if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH)
321 outb(old, ICEMT1724(ice, DMA_PAUSE));
322 spin_unlock(&ice->reg_lock);
325 case SNDRV_PCM_TRIGGER_START:
326 case SNDRV_PCM_TRIGGER_STOP:
327 spin_lock(&ice->reg_lock);
328 old = inb(ICEMT1724(ice, DMA_CONTROL));
329 if (cmd == SNDRV_PCM_TRIGGER_START)
333 outb(old, ICEMT1724(ice, DMA_CONTROL));
334 spin_unlock(&ice->reg_lock);
346 #define DMA_STARTS (VT1724_RDMA0_START|VT1724_PDMA0_START|VT1724_RDMA1_START|\
347 VT1724_PDMA1_START|VT1724_PDMA2_START|VT1724_PDMA3_START|VT1724_PDMA4_START)
348 #define DMA_PAUSES (VT1724_RDMA0_PAUSE|VT1724_PDMA0_PAUSE|VT1724_RDMA1_PAUSE|\
349 VT1724_PDMA1_PAUSE|VT1724_PDMA2_PAUSE|VT1724_PDMA3_PAUSE|VT1724_PDMA4_PAUSE)
351 static void snd_vt1724_set_pro_rate(ice1712_t *ice, unsigned int rate, int force)
354 unsigned char val, old;
357 spin_lock_irqsave(&ice->reg_lock, flags);
358 if ((inb(ICEMT1724(ice, DMA_CONTROL)) & DMA_STARTS) ||
359 (inb(ICEMT1724(ice, DMA_PAUSE)) & DMA_PAUSES)) {
360 /* running? we cannot change the rate now... */
361 spin_unlock_irqrestore(&ice->reg_lock, flags);
364 if (!force && is_pro_rate_locked(ice)) {
365 spin_unlock_irqrestore(&ice->reg_lock, flags);
370 case 8000: val = 6; break;
371 case 9600: val = 3; break;
372 case 11025: val = 10; break;
373 case 12000: val = 2; break;
374 case 16000: val = 5; break;
375 case 22050: val = 9; break;
376 case 24000: val = 1; break;
377 case 32000: val = 4; break;
378 case 44100: val = 8; break;
379 case 48000: val = 0; break;
380 case 64000: val = 15; break;
381 case 88200: val = 11; break;
382 case 96000: val = 7; break;
383 case 176400: val = 12; break;
384 case 192000: val = 14; break;
390 outb(val, ICEMT1724(ice, RATE));
391 if (rate == ice->cur_rate) {
392 spin_unlock_irqrestore(&ice->reg_lock, flags);
396 ice->cur_rate = rate;
399 if (ice->eeprom.data[ICE_EEP2_ACLINK] & 0x80) {
400 val = old = inb(ICEMT1724(ice, I2S_FORMAT));
402 val |= VT1724_MT_I2S_MCLK_128X; /* 128x MCLK */
404 val &= ~VT1724_MT_I2S_MCLK_128X; /* 256x MCLK */
406 outb(val, ICEMT1724(ice, I2S_FORMAT));
407 if (ice->eeprom.subvendor == VT1724_SUBDEVICE_REVOLUTION71) {
408 /* FIXME: is this revo only? */
409 /* assert PRST# to converters; MT05 bit 7 */
410 outb(inb(ICEMT1724(ice, AC97_CMD)) | 0x80, ICEMT1724(ice, AC97_CMD));
411 spin_unlock_irqrestore(&ice->reg_lock, flags);
413 spin_lock_irqsave(&ice->reg_lock, flags);
415 outb(inb(ICEMT1724(ice, AC97_CMD)) & ~0x80, ICEMT1724(ice, AC97_CMD));
419 spin_unlock_irqrestore(&ice->reg_lock, flags);
422 for (i = 0; i < ice->akm_codecs; i++) {
423 if (ice->akm[i].ops.set_rate_val)
424 ice->akm[i].ops.set_rate_val(&ice->akm[i], rate);
428 static int snd_vt1724_pcm_hw_params(snd_pcm_substream_t * substream,
429 snd_pcm_hw_params_t * hw_params)
431 ice1712_t *ice = snd_pcm_substream_chip(substream);
434 chs = params_channels(hw_params);
435 down(&ice->open_mutex);
436 /* mark surround channels */
437 if (substream == ice->playback_pro_substream) {
439 for (i = 0; i < chs; i++) {
440 if (ice->pcm_reserved[i] && ice->pcm_reserved[i] != substream) {
441 up(&ice->open_mutex);
444 ice->pcm_reserved[i] = substream;
447 if (ice->pcm_reserved[i] == substream)
448 ice->pcm_reserved[i] = NULL;
451 for (i = 0; i < 3; i++) {
452 if (ice->playback_con_substream_ds[i] == substream) {
453 if (ice->pcm_reserved[i] && ice->pcm_reserved[i] != substream) {
454 up(&ice->open_mutex);
457 ice->pcm_reserved[i] = substream;
462 up(&ice->open_mutex);
463 snd_vt1724_set_pro_rate(ice, params_rate(hw_params), 0);
464 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
467 static int snd_vt1724_pcm_hw_free(snd_pcm_substream_t * substream)
469 ice1712_t *ice = snd_pcm_substream_chip(substream);
472 down(&ice->open_mutex);
473 /* unmark surround channels */
474 for (i = 0; i < 3; i++)
475 if (ice->pcm_reserved[i] == substream)
476 ice->pcm_reserved[i] = NULL;
477 up(&ice->open_mutex);
478 return snd_pcm_lib_free_pages(substream);
481 static int snd_vt1724_playback_pro_prepare(snd_pcm_substream_t * substream)
483 ice1712_t *ice = snd_pcm_substream_chip(substream);
487 spin_lock(&ice->reg_lock);
488 val = (8 - substream->runtime->channels) >> 1;
489 outb(val, ICEMT1724(ice, BURST));
491 outl(substream->runtime->dma_addr, ICEMT1724(ice, PLAYBACK_ADDR));
493 size = (snd_pcm_lib_buffer_bytes(substream) >> 2) - 1;
494 // outl(size, ICEMT1724(ice, PLAYBACK_SIZE));
495 outw(size, ICEMT1724(ice, PLAYBACK_SIZE));
496 outb(size >> 16, ICEMT1724(ice, PLAYBACK_SIZE) + 2);
497 size = (snd_pcm_lib_period_bytes(substream) >> 2) - 1;
498 // outl(size, ICEMT1724(ice, PLAYBACK_COUNT));
499 outw(size, ICEMT1724(ice, PLAYBACK_COUNT));
500 outb(size >> 16, ICEMT1724(ice, PLAYBACK_COUNT) + 2);
502 spin_unlock(&ice->reg_lock);
504 // printk("pro prepare: ch = %d, addr = 0x%x, buffer = 0x%x, period = 0x%x\n", substream->runtime->channels, (unsigned int)substream->runtime->dma_addr, snd_pcm_lib_buffer_bytes(substream), snd_pcm_lib_period_bytes(substream));
508 static snd_pcm_uframes_t snd_vt1724_playback_pro_pointer(snd_pcm_substream_t * substream)
510 ice1712_t *ice = snd_pcm_substream_chip(substream);
513 if (!(inl(ICEMT1724(ice, DMA_CONTROL)) & VT1724_PDMA0_START))
515 #if 0 /* read PLAYBACK_ADDR */
516 ptr = inl(ICEMT1724(ice, PLAYBACK_ADDR));
517 if (ptr < substream->runtime->dma_addr) {
518 snd_printd("ice1724: invalid negative ptr\n");
521 ptr -= substream->runtime->dma_addr;
522 ptr = bytes_to_frames(substream->runtime, ptr);
523 if (ptr >= substream->runtime->buffer_size) {
524 snd_printd("ice1724: invalid ptr %d (size=%d)\n", (int)ptr, (int)substream->runtime->period_size);
527 #else /* read PLAYBACK_SIZE */
528 ptr = inl(ICEMT1724(ice, PLAYBACK_SIZE)) & 0xffffff;
529 ptr = (ptr + 1) << 2;
530 ptr = bytes_to_frames(substream->runtime, ptr);
531 if (ptr <= substream->runtime->buffer_size)
532 ptr = substream->runtime->buffer_size - ptr;
534 snd_printd("ice1724: invalid ptr %d (size=%d)\n", (int)ptr, (int)substream->runtime->buffer_size);
541 struct vt1724_pcm_reg {
542 unsigned int addr; /* ADDR register offset */
543 unsigned int size; /* SIZE register offset */
544 unsigned int count; /* COUNT register offset */
545 unsigned int start; /* start bit */
546 unsigned int pause; /* pause bit */
549 static int snd_vt1724_pcm_prepare(snd_pcm_substream_t *substream, const struct vt1724_pcm_reg *reg)
551 ice1712_t *ice = snd_pcm_substream_chip(substream);
553 spin_lock(&ice->reg_lock);
554 outl(substream->runtime->dma_addr, ice->profi_port + reg->addr);
555 outw((snd_pcm_lib_buffer_bytes(substream) >> 2) - 1, ice->profi_port + reg->size);
556 outw((snd_pcm_lib_period_bytes(substream) >> 2) - 1, ice->profi_port + reg->count);
557 spin_unlock(&ice->reg_lock);
561 static snd_pcm_uframes_t snd_vt1724_pcm_pointer(snd_pcm_substream_t *substream, const struct vt1724_pcm_reg *reg)
563 ice1712_t *ice = snd_pcm_substream_chip(substream);
566 if (!(inl(ICEMT1724(ice, DMA_CONTROL)) & reg->start))
568 #if 0 /* use ADDR register */
569 ptr = inl(ice->profi_port + reg->addr);
570 ptr -= substream->runtime->dma_addr;
571 return bytes_to_frames(substream->runtime, ptr);
572 #else /* use SIZE register */
573 ptr = inw(ice->profi_port + reg->size);
574 ptr = (ptr + 1) << 2;
575 ptr = bytes_to_frames(substream->runtime, ptr);
576 if (ptr <= substream->runtime->buffer_size)
577 ptr = substream->runtime->buffer_size - ptr;
579 snd_printd("ice1724: invalid ptr %d (size=%d)\n", (int)ptr, (int)substream->runtime->buffer_size);
586 const static struct vt1724_pcm_reg vt1724_capture_pro_reg = {
587 .addr = VT1724_MT_CAPTURE_ADDR,
588 .size = VT1724_MT_CAPTURE_SIZE,
589 .count = VT1724_MT_CAPTURE_COUNT,
590 .start = VT1724_RDMA0_START,
591 .pause = VT1724_RDMA0_PAUSE,
594 static int snd_vt1724_capture_pro_prepare(snd_pcm_substream_t * substream)
596 return snd_vt1724_pcm_prepare(substream, &vt1724_capture_pro_reg);
599 static snd_pcm_uframes_t snd_vt1724_capture_pro_pointer(snd_pcm_substream_t * substream)
601 return snd_vt1724_pcm_pointer(substream, &vt1724_capture_pro_reg);
604 static snd_pcm_hardware_t snd_vt1724_playback_pro =
606 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
607 SNDRV_PCM_INFO_BLOCK_TRANSFER |
608 SNDRV_PCM_INFO_MMAP_VALID |
609 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START),
610 .formats = SNDRV_PCM_FMTBIT_S32_LE,
611 .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_192000,
616 .buffer_bytes_max = (1UL << 21), /* 19bits dword */
617 .period_bytes_min = 8 * 4 * 2, /* FIXME: constraints needed */
618 .period_bytes_max = (1UL << 21),
623 static snd_pcm_hardware_t snd_vt1724_2ch_stereo =
625 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
626 SNDRV_PCM_INFO_BLOCK_TRANSFER |
627 SNDRV_PCM_INFO_MMAP_VALID |
628 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START),
629 .formats = SNDRV_PCM_FMTBIT_S32_LE,
630 .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_192000,
635 .buffer_bytes_max = (1UL << 18), /* 16bits dword */
636 .period_bytes_min = 2 * 4 * 2,
637 .period_bytes_max = (1UL << 18),
642 /* multi-channel playback needs alignment 8x32bit regarless of the channels
645 #define VT1724_BUFFER_ALIGN 0x20
647 static int snd_vt1724_playback_pro_open(snd_pcm_substream_t * substream)
649 snd_pcm_runtime_t *runtime = substream->runtime;
650 ice1712_t *ice = snd_pcm_substream_chip(substream);
653 runtime->private_data = (void*)VT1724_PDMA0_START; /* irq/status/trigger bit */
654 ice->playback_pro_substream = substream;
655 runtime->hw = snd_vt1724_playback_pro;
656 snd_pcm_set_sync(substream);
657 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
658 if ((ice->eeprom.data[ICE_EEP2_ACLINK] & 0x80) &&
659 (ice->eeprom.data[ICE_EEP2_I2S] & 0x08))
660 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates_192);
662 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates_96);
664 down(&ice->open_mutex);
665 /* calculate the currently available channels */
666 for (chs = 0; chs < 3; chs++) {
667 if (ice->pcm_reserved[chs])
671 runtime->hw.channels_max = chs;
672 if (chs > 2) /* channels must be even */
673 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, 2);
674 up(&ice->open_mutex);
675 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
676 VT1724_BUFFER_ALIGN);
677 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
678 VT1724_BUFFER_ALIGN);
682 static int snd_vt1724_capture_pro_open(snd_pcm_substream_t * substream)
684 ice1712_t *ice = snd_pcm_substream_chip(substream);
685 snd_pcm_runtime_t *runtime = substream->runtime;
687 runtime->private_data = (void*)VT1724_RDMA0_START; /* irq/status/trigger bit */
688 ice->capture_pro_substream = substream;
689 runtime->hw = snd_vt1724_2ch_stereo;
690 snd_pcm_set_sync(substream);
691 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
692 if ((ice->eeprom.data[ICE_EEP2_ACLINK] & 0x80) &&
693 (ice->eeprom.data[ICE_EEP2_I2S] & 0x08))
694 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates_192);
696 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates_96);
700 static int snd_vt1724_playback_pro_close(snd_pcm_substream_t * substream)
702 ice1712_t *ice = snd_pcm_substream_chip(substream);
705 snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
706 ice->playback_pro_substream = NULL;
711 static int snd_vt1724_capture_pro_close(snd_pcm_substream_t * substream)
713 ice1712_t *ice = snd_pcm_substream_chip(substream);
716 snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
717 ice->capture_pro_substream = NULL;
721 static snd_pcm_ops_t snd_vt1724_playback_pro_ops = {
722 .open = snd_vt1724_playback_pro_open,
723 .close = snd_vt1724_playback_pro_close,
724 .ioctl = snd_pcm_lib_ioctl,
725 .hw_params = snd_vt1724_pcm_hw_params,
726 .hw_free = snd_vt1724_pcm_hw_free,
727 .prepare = snd_vt1724_playback_pro_prepare,
728 .trigger = snd_vt1724_pcm_trigger,
729 .pointer = snd_vt1724_playback_pro_pointer,
732 static snd_pcm_ops_t snd_vt1724_capture_pro_ops = {
733 .open = snd_vt1724_capture_pro_open,
734 .close = snd_vt1724_capture_pro_close,
735 .ioctl = snd_pcm_lib_ioctl,
736 .hw_params = snd_vt1724_pcm_hw_params,
737 .hw_free = snd_vt1724_pcm_hw_free,
738 .prepare = snd_vt1724_capture_pro_prepare,
739 .trigger = snd_vt1724_pcm_trigger,
740 .pointer = snd_vt1724_capture_pro_pointer,
743 static int __devinit snd_vt1724_pcm_profi(ice1712_t * ice, int device)
748 err = snd_pcm_new(ice->card, "ICE1724", device, 1, 1, &pcm);
752 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_vt1724_playback_pro_ops);
753 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_vt1724_capture_pro_ops);
755 pcm->private_data = ice;
757 strcpy(pcm->name, "ICE1724");
759 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
760 snd_dma_pci_data(ice->pci), 256*1024, 256*1024);
772 const static struct vt1724_pcm_reg vt1724_playback_spdif_reg = {
773 .addr = VT1724_MT_PDMA4_ADDR,
774 .size = VT1724_MT_PDMA4_SIZE,
775 .count = VT1724_MT_PDMA4_COUNT,
776 .start = VT1724_PDMA4_START,
777 .pause = VT1724_PDMA4_PAUSE,
780 const static struct vt1724_pcm_reg vt1724_capture_spdif_reg = {
781 .addr = VT1724_MT_RDMA1_ADDR,
782 .size = VT1724_MT_RDMA1_SIZE,
783 .count = VT1724_MT_RDMA1_COUNT,
784 .start = VT1724_RDMA1_START,
785 .pause = VT1724_RDMA1_PAUSE,
788 static int snd_vt1724_playback_spdif_prepare(snd_pcm_substream_t * substream)
790 return snd_vt1724_pcm_prepare(substream, &vt1724_playback_spdif_reg);
793 static snd_pcm_uframes_t snd_vt1724_playback_spdif_pointer(snd_pcm_substream_t * substream)
795 return snd_vt1724_pcm_pointer(substream, &vt1724_playback_spdif_reg);
798 static int snd_vt1724_capture_spdif_prepare(snd_pcm_substream_t * substream)
800 return snd_vt1724_pcm_prepare(substream, &vt1724_capture_spdif_reg);
803 static snd_pcm_uframes_t snd_vt1724_capture_spdif_pointer(snd_pcm_substream_t * substream)
805 return snd_vt1724_pcm_pointer(substream, &vt1724_capture_spdif_reg);
808 static int snd_vt1724_playback_spdif_open(snd_pcm_substream_t *substream)
810 ice1712_t *ice = snd_pcm_substream_chip(substream);
811 snd_pcm_runtime_t *runtime = substream->runtime;
813 runtime->private_data = (void*)VT1724_PDMA4_START; /* irq/status/trigger bit */
814 ice->playback_con_substream = substream;
815 runtime->hw = snd_vt1724_2ch_stereo;
816 snd_pcm_set_sync(substream);
817 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
819 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates_192);
823 static int snd_vt1724_playback_spdif_close(snd_pcm_substream_t * substream)
825 ice1712_t *ice = snd_pcm_substream_chip(substream);
828 snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
829 ice->playback_con_substream = NULL;
834 static int snd_vt1724_capture_spdif_open(snd_pcm_substream_t *substream)
836 ice1712_t *ice = snd_pcm_substream_chip(substream);
837 snd_pcm_runtime_t *runtime = substream->runtime;
839 runtime->private_data = (void*)VT1724_RDMA1_START; /* irq/status/trigger bit */
840 ice->capture_con_substream = substream;
841 runtime->hw = snd_vt1724_2ch_stereo;
842 snd_pcm_set_sync(substream);
843 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
844 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates_96);
848 static int snd_vt1724_capture_spdif_close(snd_pcm_substream_t * substream)
850 ice1712_t *ice = snd_pcm_substream_chip(substream);
853 snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
854 ice->capture_con_substream = NULL;
859 static snd_pcm_ops_t snd_vt1724_playback_spdif_ops = {
860 .open = snd_vt1724_playback_spdif_open,
861 .close = snd_vt1724_playback_spdif_close,
862 .ioctl = snd_pcm_lib_ioctl,
863 .hw_params = snd_vt1724_pcm_hw_params,
864 .hw_free = snd_vt1724_pcm_hw_free,
865 .prepare = snd_vt1724_playback_spdif_prepare,
866 .trigger = snd_vt1724_pcm_trigger,
867 .pointer = snd_vt1724_playback_spdif_pointer,
870 static snd_pcm_ops_t snd_vt1724_capture_spdif_ops = {
871 .open = snd_vt1724_capture_spdif_open,
872 .close = snd_vt1724_capture_spdif_close,
873 .ioctl = snd_pcm_lib_ioctl,
874 .hw_params = snd_vt1724_pcm_hw_params,
875 .hw_free = snd_vt1724_pcm_hw_free,
876 .prepare = snd_vt1724_capture_spdif_prepare,
877 .trigger = snd_vt1724_pcm_trigger,
878 .pointer = snd_vt1724_capture_spdif_pointer,
882 static int __devinit snd_vt1724_pcm_spdif(ice1712_t * ice, int device)
888 if (ice->eeprom.data[ICE_EEP2_SPDIF] & VT1724_CFG_SPDIF_OUT_INT)
892 if (ice->eeprom.data[ICE_EEP2_SPDIF] & VT1724_CFG_SPDIF_IN)
896 if (! play && ! capt)
897 return 0; /* no spdif device */
899 err = snd_pcm_new(ice->card, "ICE1724 IEC958", device, play, capt, &pcm);
904 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
905 &snd_vt1724_playback_spdif_ops);
907 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
908 &snd_vt1724_capture_spdif_ops);
910 pcm->private_data = ice;
912 strcpy(pcm->name, "ICE1724 IEC958");
914 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
915 snd_dma_pci_data(ice->pci), 64*1024, 64*1024);
924 * independent surround PCMs
927 const static struct vt1724_pcm_reg vt1724_playback_dma_regs[3] = {
929 .addr = VT1724_MT_PDMA1_ADDR,
930 .size = VT1724_MT_PDMA1_SIZE,
931 .count = VT1724_MT_PDMA1_COUNT,
932 .start = VT1724_PDMA1_START,
933 .pause = VT1724_PDMA1_PAUSE,
936 .addr = VT1724_MT_PDMA2_ADDR,
937 .size = VT1724_MT_PDMA2_SIZE,
938 .count = VT1724_MT_PDMA2_COUNT,
939 .start = VT1724_PDMA2_START,
940 .pause = VT1724_PDMA2_PAUSE,
943 .addr = VT1724_MT_PDMA3_ADDR,
944 .size = VT1724_MT_PDMA3_SIZE,
945 .count = VT1724_MT_PDMA3_COUNT,
946 .start = VT1724_PDMA3_START,
947 .pause = VT1724_PDMA3_PAUSE,
951 static int snd_vt1724_playback_indep_prepare(snd_pcm_substream_t * substream)
953 ice1712_t *ice = snd_pcm_substream_chip(substream);
956 spin_lock(&ice->reg_lock);
957 val = 3 - substream->number;
958 if (inb(ICEMT1724(ice, BURST)) < val)
959 outb(val, ICEMT1724(ice, BURST));
960 spin_unlock(&ice->reg_lock);
961 return snd_vt1724_pcm_prepare(substream, &vt1724_playback_dma_regs[substream->number]);
964 static snd_pcm_uframes_t snd_vt1724_playback_indep_pointer(snd_pcm_substream_t * substream)
966 return snd_vt1724_pcm_pointer(substream, &vt1724_playback_dma_regs[substream->number]);
969 static int snd_vt1724_playback_indep_open(snd_pcm_substream_t *substream)
971 ice1712_t *ice = snd_pcm_substream_chip(substream);
972 snd_pcm_runtime_t *runtime = substream->runtime;
974 down(&ice->open_mutex);
975 /* already used by PDMA0? */
976 if (ice->pcm_reserved[substream->number]) {
977 up(&ice->open_mutex);
978 return -EBUSY; /* FIXME: should handle blocking mode properly */
980 up(&ice->open_mutex);
981 runtime->private_data = (void*)(1 << (substream->number + 4));
982 ice->playback_con_substream_ds[substream->number] = substream;
983 runtime->hw = snd_vt1724_2ch_stereo;
984 snd_pcm_set_sync(substream);
985 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
987 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates_192);
991 static int snd_vt1724_playback_indep_close(snd_pcm_substream_t * substream)
993 ice1712_t *ice = snd_pcm_substream_chip(substream);
996 snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
997 ice->playback_con_substream_ds[substream->number] = NULL;
998 ice->pcm_reserved[substream->number] = NULL;
1003 static snd_pcm_ops_t snd_vt1724_playback_indep_ops = {
1004 .open = snd_vt1724_playback_indep_open,
1005 .close = snd_vt1724_playback_indep_close,
1006 .ioctl = snd_pcm_lib_ioctl,
1007 .hw_params = snd_vt1724_pcm_hw_params,
1008 .hw_free = snd_vt1724_pcm_hw_free,
1009 .prepare = snd_vt1724_playback_indep_prepare,
1010 .trigger = snd_vt1724_pcm_trigger,
1011 .pointer = snd_vt1724_playback_indep_pointer,
1015 static int __devinit snd_vt1724_pcm_indep(ice1712_t * ice, int device)
1021 play = ice->num_total_dacs / 2 - 1;
1025 err = snd_pcm_new(ice->card, "ICE1724 Surrounds", device, play, 0, &pcm);
1029 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
1030 &snd_vt1724_playback_indep_ops);
1032 pcm->private_data = ice;
1033 pcm->info_flags = 0;
1034 strcpy(pcm->name, "ICE1724 Surround PCM");
1036 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
1037 snd_dma_pci_data(ice->pci), 64*1024, 64*1024);
1049 static int __devinit snd_vt1724_ac97_mixer(ice1712_t * ice)
1053 if (! (ice->eeprom.data[ICE_EEP2_ACLINK] & VT1724_CFG_PRO_I2S)) {
1054 ac97_bus_t bus, *pbus;
1057 outb(inb(ICEMT1724(ice, AC97_CMD)) | 0x80, ICEMT1724(ice, AC97_CMD));
1058 mdelay(5); /* FIXME */
1059 outb(inb(ICEMT1724(ice, AC97_CMD)) & ~0x80, ICEMT1724(ice, AC97_CMD));
1061 memset(&bus, 0, sizeof(bus));
1062 bus.write = snd_vt1724_ac97_write;
1063 bus.read = snd_vt1724_ac97_read;
1064 if ((err = snd_ac97_bus(ice->card, &bus, &pbus)) < 0)
1066 memset(&ac97, 0, sizeof(ac97));
1067 ac97.private_data = ice;
1068 if ((err = snd_ac97_mixer(pbus, &ac97, &ice->ac97)) < 0)
1069 printk(KERN_WARNING "ice1712: cannot initialize pro ac97, skipped\n");
1073 /* I2S mixer only */
1074 strcat(ice->card->mixername, "ICE1724 - multitrack");
1082 static inline unsigned int eeprom_triple(ice1712_t *ice, int idx)
1084 return (unsigned int)ice->eeprom.data[idx] | \
1085 ((unsigned int)ice->eeprom.data[idx + 1] << 8) | \
1086 ((unsigned int)ice->eeprom.data[idx + 2] << 16);
1089 static void snd_vt1724_proc_read(snd_info_entry_t *entry,
1090 snd_info_buffer_t * buffer)
1092 ice1712_t *ice = snd_magic_cast(ice1712_t, entry->private_data, return);
1095 snd_iprintf(buffer, "%s\n\n", ice->card->longname);
1096 snd_iprintf(buffer, "EEPROM:\n");
1098 snd_iprintf(buffer, " Subvendor : 0x%x\n", ice->eeprom.subvendor);
1099 snd_iprintf(buffer, " Size : %i bytes\n", ice->eeprom.size);
1100 snd_iprintf(buffer, " Version : %i\n", ice->eeprom.version);
1101 snd_iprintf(buffer, " System Config : 0x%x\n", ice->eeprom.data[ICE_EEP2_SYSCONF]);
1102 snd_iprintf(buffer, " ACLink : 0x%x\n", ice->eeprom.data[ICE_EEP2_ACLINK]);
1103 snd_iprintf(buffer, " I2S : 0x%x\n", ice->eeprom.data[ICE_EEP2_I2S]);
1104 snd_iprintf(buffer, " S/PDIF : 0x%x\n", ice->eeprom.data[ICE_EEP2_SPDIF]);
1105 snd_iprintf(buffer, " GPIO direction : 0x%x\n", ice->eeprom.gpiodir);
1106 snd_iprintf(buffer, " GPIO mask : 0x%x\n", ice->eeprom.gpiomask);
1107 snd_iprintf(buffer, " GPIO state : 0x%x\n", ice->eeprom.gpiostate);
1108 for (idx = 0x12; idx < ice->eeprom.size; idx++)
1109 snd_iprintf(buffer, " Extra #%02i : 0x%x\n", idx, ice->eeprom.data[idx]);
1111 snd_iprintf(buffer, "\nRegisters:\n");
1113 snd_iprintf(buffer, " PSDOUT03 : 0x%08x\n", (unsigned)inl(ICEMT1724(ice, ROUTE_PLAYBACK)));
1114 for (idx = 0x0; idx < 0x20 ; idx++)
1115 snd_iprintf(buffer, " CCS%02x : 0x%02x\n", idx, inb(ice->port+idx));
1116 for (idx = 0x0; idx < 0x30 ; idx++)
1117 snd_iprintf(buffer, " MT%02x : 0x%02x\n", idx, inb(ice->profi_port+idx));
1120 static void __devinit snd_vt1724_proc_init(ice1712_t * ice)
1122 snd_info_entry_t *entry;
1124 if (! snd_card_proc_new(ice->card, "ice1724", &entry))
1125 snd_info_set_text_ops(entry, ice, 1024, snd_vt1724_proc_read);
1132 static int snd_vt1724_eeprom_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1134 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
1135 uinfo->count = sizeof(ice1712_eeprom_t);
1139 static int snd_vt1724_eeprom_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1141 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1143 memcpy(ucontrol->value.bytes.data, &ice->eeprom, sizeof(ice->eeprom));
1147 static snd_kcontrol_new_t snd_vt1724_eeprom __devinitdata = {
1148 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1149 .name = "ICE1724 EEPROM",
1150 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1151 .info = snd_vt1724_eeprom_info,
1152 .get = snd_vt1724_eeprom_get
1157 static int snd_vt1724_spdif_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1159 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1164 static unsigned int encode_spdif_bits(snd_aes_iec958_t *diga)
1168 val = diga->status[0] & 0x03; /* professional, non-audio */
1171 if ((diga->status[0] & IEC958_AES0_PRO_EMPHASIS) == IEC958_AES0_PRO_EMPHASIS_5015)
1173 switch (diga->status[0] & IEC958_AES0_PRO_FS) {
1174 case IEC958_AES0_PRO_FS_44100:
1176 case IEC958_AES0_PRO_FS_32000:
1185 val |= diga->status[0] & 0x04; /* copyright */
1186 if ((diga->status[0] & IEC958_AES0_CON_EMPHASIS)== IEC958_AES0_CON_EMPHASIS_5015)
1188 val |= (unsigned int)(diga->status[1] & 0x3f) << 4; /* category */
1189 val |= (unsigned int)(diga->status[3] & IEC958_AES3_CON_FS) << 12; /* fs */
1194 static void decode_spdif_bits(snd_aes_iec958_t *diga, unsigned int val)
1196 memset(diga->status, 0, sizeof(diga->status));
1197 diga->status[0] = val & 0x03; /* professional, non-audio */
1200 if (val & (1U << 3))
1201 diga->status[0] |= IEC958_AES0_PRO_EMPHASIS_5015;
1202 switch ((val >> 12) & 0x7) {
1206 diga->status[0] |= IEC958_AES0_PRO_FS_32000;
1209 diga->status[0] |= IEC958_AES0_PRO_FS_48000;
1214 diga->status[0] |= val & (1U << 2); /* copyright */
1215 if (val & (1U << 3))
1216 diga->status[0] |= IEC958_AES0_CON_EMPHASIS_5015;
1217 diga->status[1] |= (val >> 4) & 0x3f; /* category */
1218 diga->status[3] |= (val >> 12) & 0x07; /* fs */
1222 static int snd_vt1724_spdif_default_get(snd_kcontrol_t * kcontrol,
1223 snd_ctl_elem_value_t * ucontrol)
1225 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1227 val = inw(ICEMT1724(ice, SPDIF_CTRL));
1228 decode_spdif_bits(&ucontrol->value.iec958, val);
1232 static int snd_vt1724_spdif_default_put(snd_kcontrol_t * kcontrol,
1233 snd_ctl_elem_value_t * ucontrol)
1235 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1236 unsigned int val, old;
1237 unsigned long flags;
1239 val = encode_spdif_bits(&ucontrol->value.iec958);
1240 spin_lock_irqsave(&ice->reg_lock, flags);
1241 old = inw(ICEMT1724(ice, SPDIF_CTRL));
1243 unsigned char cbit, disabled;
1244 cbit = inb(ICEREG1724(ice, SPDIF_CFG));
1245 disabled = cbit & ~VT1724_CFG_SPDIF_OUT_EN;
1246 if (cbit != disabled)
1247 outb(disabled, ICEREG1724(ice, SPDIF_CFG));
1248 outw(val, ICEMT1724(ice, SPDIF_CTRL));
1249 if (cbit != disabled)
1250 outb(cbit, ICEREG1724(ice, SPDIF_CFG));
1252 spin_unlock_irqrestore(&ice->reg_lock, flags);
1253 return (val != old);
1256 static snd_kcontrol_new_t snd_vt1724_spdif_default __devinitdata =
1258 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1259 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
1260 .info = snd_vt1724_spdif_info,
1261 .get = snd_vt1724_spdif_default_get,
1262 .put = snd_vt1724_spdif_default_put
1265 static int snd_vt1724_spdif_maskc_get(snd_kcontrol_t * kcontrol,
1266 snd_ctl_elem_value_t * ucontrol)
1268 ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO |
1269 IEC958_AES0_PROFESSIONAL |
1270 IEC958_AES0_CON_NOT_COPYRIGHT |
1271 IEC958_AES0_CON_EMPHASIS;
1272 ucontrol->value.iec958.status[1] = IEC958_AES1_CON_ORIGINAL |
1273 IEC958_AES1_CON_CATEGORY;
1274 ucontrol->value.iec958.status[3] = IEC958_AES3_CON_FS;
1278 static int snd_vt1724_spdif_maskp_get(snd_kcontrol_t * kcontrol,
1279 snd_ctl_elem_value_t * ucontrol)
1281 ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO |
1282 IEC958_AES0_PROFESSIONAL |
1283 IEC958_AES0_PRO_FS |
1284 IEC958_AES0_PRO_EMPHASIS;
1288 static snd_kcontrol_new_t snd_vt1724_spdif_maskc __devinitdata =
1290 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1291 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1292 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,CON_MASK),
1293 .info = snd_vt1724_spdif_info,
1294 .get = snd_vt1724_spdif_maskc_get,
1297 static snd_kcontrol_new_t snd_vt1724_spdif_maskp __devinitdata =
1299 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1300 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1301 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PRO_MASK),
1302 .info = snd_vt1724_spdif_info,
1303 .get = snd_vt1724_spdif_maskp_get,
1306 static int snd_vt1724_spdif_sw_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1308 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1310 uinfo->value.integer.min = 0;
1311 uinfo->value.integer.max = 1;
1315 static int snd_vt1724_spdif_sw_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1317 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1318 ucontrol->value.integer.value[0] = inb(ICEREG1724(ice, SPDIF_CFG)) & VT1724_CFG_SPDIF_OUT_EN ? 1 : 0;
1322 static int snd_vt1724_spdif_sw_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1324 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1325 unsigned char old, val;
1326 unsigned long flags;
1327 spin_lock_irqsave(&ice->reg_lock, flags);
1328 old = val = inb(ICEREG1724(ice, SPDIF_CFG));
1329 val &= ~VT1724_CFG_SPDIF_OUT_EN;
1330 if (ucontrol->value.integer.value[0])
1331 val |= VT1724_CFG_SPDIF_OUT_EN;
1333 outb(val, ICEREG1724(ice, SPDIF_CFG));
1334 spin_unlock_irqrestore(&ice->reg_lock, flags);
1338 static snd_kcontrol_new_t snd_vt1724_spdif_switch __devinitdata =
1340 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1341 /* FIXME: the following conflict with IEC958 Playback Route */
1342 // .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH),
1343 .name = "IEC958 Output Switch",
1344 .info = snd_vt1724_spdif_sw_info,
1345 .get = snd_vt1724_spdif_sw_get,
1346 .put = snd_vt1724_spdif_sw_put
1350 #if 0 /* NOT USED YET */
1352 * GPIO access from extern
1355 int snd_vt1724_gpio_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1357 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1359 uinfo->value.integer.min = 0;
1360 uinfo->value.integer.max = 1;
1364 int snd_vt1724_gpio_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1366 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1367 int shift = kcontrol->private_value & 0xff;
1368 int invert = (kcontrol->private_value & (1<<24)) ? 1 : 0;
1370 snd_ice1712_save_gpio_status(ice);
1371 ucontrol->value.integer.value[0] = (snd_ice1712_gpio_read(ice) & (1 << shift) ? 1 : 0) ^ invert;
1372 snd_ice1712_restore_gpio_status(ice);
1376 int snd_ice1712_gpio_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1378 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1379 int shift = kcontrol->private_value & 0xff;
1380 int invert = (kcontrol->private_value & (1<<24)) ? mask : 0;
1381 unsigned int val, nval;
1383 if (kcontrol->private_value & (1 << 31))
1385 nval = (ucontrol->value.integer.value[0] ? (1 << shift) : 0) ^ invert;
1386 snd_ice1712_save_gpio_status(ice);
1387 val = snd_ice1712_gpio_read(ice);
1388 nval |= val & ~(1 << shift);
1390 snd_ice1712_gpio_write(ice, nval);
1391 snd_ice1712_restore_gpio_status(ice);
1394 #endif /* NOT USED YET */
1399 static int snd_vt1724_pro_internal_clock_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1401 static char *texts[] = {
1404 "11025", /* 2: 10 */
1412 "64000", /* 10: 15 */
1413 "88200", /* 11: 11 */
1414 "96000", /* 12: 7 */
1415 "176400", /* 13: 12 */
1416 "192000", /* 14: 14 */
1417 "IEC958 Input", /* 15: -- */
1419 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1421 uinfo->value.enumerated.items = 16;
1422 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1423 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1424 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1428 static int snd_vt1724_pro_internal_clock_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1430 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1431 static unsigned char xlate[16] = {
1432 9, 6, 3, 1, 7, 4, 0, 12, 8, 5, 2, 11, 13, 255, 14, 10
1436 spin_lock_irq(&ice->reg_lock);
1437 if (is_spdif_master(ice)) {
1438 ucontrol->value.enumerated.item[0] = 15;
1440 val = xlate[inb(ICEMT1724(ice, RATE)) & 15];
1445 ucontrol->value.enumerated.item[0] = val;
1447 spin_unlock_irq(&ice->reg_lock);
1451 static int snd_vt1724_pro_internal_clock_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1453 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1457 spin_lock_irq(&ice->reg_lock);
1458 oval = inb(ICEMT1724(ice, RATE));
1459 if (ucontrol->value.enumerated.item[0] == 15) {
1460 outb(oval | VT1724_SPDIF_MASTER, ICEMT1724(ice, RATE));
1462 PRO_RATE_DEFAULT = rates[ucontrol->value.integer.value[0] % 15];
1463 spin_unlock_irq(&ice->reg_lock);
1464 snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 1);
1465 spin_lock_irq(&ice->reg_lock);
1467 change = inb(ICEMT1724(ice, RATE)) != oval;
1468 spin_unlock_irq(&ice->reg_lock);
1470 if ((oval & VT1724_SPDIF_MASTER) != (inb(ICEMT1724(ice, RATE)) & VT1724_SPDIF_MASTER)) {
1471 /* notify akm chips as well */
1472 if (is_spdif_master(ice)) {
1474 for (i = 0; i < ice->akm_codecs; i++) {
1475 if (ice->akm[i].ops.set_rate_val)
1476 ice->akm[i].ops.set_rate_val(&ice->akm[i], 0);
1483 static snd_kcontrol_new_t snd_vt1724_pro_internal_clock __devinitdata = {
1484 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1485 .name = "Multi Track Internal Clock",
1486 .info = snd_vt1724_pro_internal_clock_info,
1487 .get = snd_vt1724_pro_internal_clock_get,
1488 .put = snd_vt1724_pro_internal_clock_put
1491 static int snd_vt1724_pro_rate_locking_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1493 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1495 uinfo->value.integer.min = 0;
1496 uinfo->value.integer.max = 1;
1500 static int snd_vt1724_pro_rate_locking_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1502 ucontrol->value.integer.value[0] = PRO_RATE_LOCKED;
1506 static int snd_vt1724_pro_rate_locking_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1508 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1509 int change = 0, nval;
1511 nval = ucontrol->value.integer.value[0] ? 1 : 0;
1512 spin_lock_irq(&ice->reg_lock);
1513 change = PRO_RATE_LOCKED != nval;
1514 PRO_RATE_LOCKED = nval;
1515 spin_unlock_irq(&ice->reg_lock);
1519 static snd_kcontrol_new_t snd_vt1724_pro_rate_locking __devinitdata = {
1520 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1521 .name = "Multi Track Rate Locking",
1522 .info = snd_vt1724_pro_rate_locking_info,
1523 .get = snd_vt1724_pro_rate_locking_get,
1524 .put = snd_vt1724_pro_rate_locking_put
1527 static int snd_vt1724_pro_rate_reset_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1529 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1531 uinfo->value.integer.min = 0;
1532 uinfo->value.integer.max = 1;
1536 static int snd_vt1724_pro_rate_reset_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1538 ucontrol->value.integer.value[0] = PRO_RATE_RESET ? 1 : 0;
1542 static int snd_vt1724_pro_rate_reset_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1544 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1545 int change = 0, nval;
1547 nval = ucontrol->value.integer.value[0] ? 1 : 0;
1548 spin_lock_irq(&ice->reg_lock);
1549 change = PRO_RATE_RESET != nval;
1550 PRO_RATE_RESET = nval;
1551 spin_unlock_irq(&ice->reg_lock);
1555 static snd_kcontrol_new_t snd_vt1724_pro_rate_reset __devinitdata = {
1556 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1557 .name = "Multi Track Rate Reset",
1558 .info = snd_vt1724_pro_rate_reset_info,
1559 .get = snd_vt1724_pro_rate_reset_get,
1560 .put = snd_vt1724_pro_rate_reset_put
1567 static int snd_vt1724_pro_route_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1569 static char *texts[] = {
1571 "H/W In 0", "H/W In 1", /* 1-2 */
1572 "IEC958 In L", "IEC958 In R", /* 3-4 */
1575 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1577 uinfo->value.enumerated.items = 5;
1578 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1579 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1580 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1584 static inline int analog_route_shift(int idx)
1586 return (idx % 2) * 12 + ((idx / 2) * 3) + 8;
1589 static inline int digital_route_shift(int idx)
1594 static int get_route_val(ice1712_t *ice, int shift)
1597 unsigned char eitem;
1598 static unsigned char xlate[8] = {
1599 0, 255, 1, 2, 255, 255, 3, 4,
1602 val = inl(ICEMT1724(ice, ROUTE_PLAYBACK));
1604 val &= 7; //we now have 3 bits per output
1613 static int put_route_val(ice1712_t *ice, unsigned int val, int shift)
1615 unsigned int old_val, nval;
1617 static unsigned char xroute[8] = {
1619 2, /* PSDIN0 Left */
1620 3, /* PSDIN0 Right */
1622 7, /* SPDIN Right */
1625 nval = xroute[val % 5];
1626 val = old_val = inl(ICEMT1724(ice, ROUTE_PLAYBACK));
1627 val &= ~(0x07 << shift);
1628 val |= nval << shift;
1629 change = val != old_val;
1631 outl(val, ICEMT1724(ice, ROUTE_PLAYBACK));
1635 static int snd_vt1724_pro_route_analog_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)
1637 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1638 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1639 ucontrol->value.enumerated.item[0] = get_route_val(ice, analog_route_shift(idx));
1643 static int snd_vt1724_pro_route_analog_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)
1645 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1646 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1647 return put_route_val(ice, ucontrol->value.enumerated.item[0],
1648 analog_route_shift(idx));
1651 static int snd_vt1724_pro_route_spdif_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)
1653 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1654 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1655 ucontrol->value.enumerated.item[0] = get_route_val(ice, digital_route_shift(idx));
1659 static int snd_vt1724_pro_route_spdif_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)
1661 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1662 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1663 return put_route_val(ice, ucontrol->value.enumerated.item[0],
1664 digital_route_shift(idx));
1667 static snd_kcontrol_new_t snd_vt1724_mixer_pro_analog_route __devinitdata = {
1668 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1669 .name = "H/W Playback Route",
1670 .info = snd_vt1724_pro_route_info,
1671 .get = snd_vt1724_pro_route_analog_get,
1672 .put = snd_vt1724_pro_route_analog_put,
1675 static snd_kcontrol_new_t snd_vt1724_mixer_pro_spdif_route __devinitdata = {
1676 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1677 .name = "IEC958 Playback Route",
1678 .info = snd_vt1724_pro_route_info,
1679 .get = snd_vt1724_pro_route_spdif_get,
1680 .put = snd_vt1724_pro_route_spdif_put,
1685 static int snd_vt1724_pro_peak_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1687 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1688 uinfo->count = 22; /* FIXME: for compatibility with ice1712... */
1689 uinfo->value.integer.min = 0;
1690 uinfo->value.integer.max = 255;
1694 static int snd_vt1724_pro_peak_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1696 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1699 spin_lock_irq(&ice->reg_lock);
1700 for (idx = 0; idx < 22; idx++) {
1701 outb(idx, ICEMT1724(ice, MONITOR_PEAKINDEX));
1702 ucontrol->value.integer.value[idx] = inb(ICEMT1724(ice, MONITOR_PEAKDATA));
1704 spin_unlock_irq(&ice->reg_lock);
1708 static snd_kcontrol_new_t snd_vt1724_mixer_pro_peak __devinitdata = {
1709 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1710 .name = "Multi Track Peak",
1711 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
1712 .info = snd_vt1724_pro_peak_info,
1713 .get = snd_vt1724_pro_peak_get
1720 static struct snd_ice1712_card_info no_matched __devinitdata;
1722 static struct snd_ice1712_card_info *card_tables[] __devinitdata = {
1723 snd_vt1724_revo_cards,
1724 snd_vt1724_amp_cards,
1725 snd_vt1724_aureon_cards,
1726 snd_vt1724_prodigy_cards,
1734 static unsigned char __devinit snd_vt1724_read_i2c(ice1712_t *ice,
1740 outb(addr, ICEREG1724(ice, I2C_BYTE_ADDR));
1741 outb(dev & ~VT1724_I2C_WRITE, ICEREG1724(ice, I2C_DEV_ADDR));
1742 while (t-- > 0 && (inb(ICEREG1724(ice, I2C_CTRL)) & VT1724_I2C_BUSY)) ;
1743 return inb(ICEREG1724(ice, I2C_DATA));
1746 static int __devinit snd_vt1724_read_eeprom(ice1712_t *ice)
1748 int dev = 0xa0; /* EEPROM device address */
1749 unsigned int i, size;
1750 struct snd_ice1712_card_info **tbl, *c;
1752 if ((inb(ICEREG1724(ice, I2C_CTRL)) & VT1724_I2C_EEPROM) == 0) {
1753 snd_printk(KERN_WARNING "ICE1724 has not detected EEPROM\n");
1756 ice->eeprom.subvendor = (snd_vt1724_read_i2c(ice, dev, 0x00) << 0) |
1757 (snd_vt1724_read_i2c(ice, dev, 0x01) << 8) |
1758 (snd_vt1724_read_i2c(ice, dev, 0x02) << 16) |
1759 (snd_vt1724_read_i2c(ice, dev, 0x03) << 24);
1761 /* if the EEPROM is given by the driver, use it */
1762 for (tbl = card_tables; *tbl; tbl++) {
1763 for (c = *tbl; c->subvendor; c++) {
1764 if (c->subvendor == ice->eeprom.subvendor) {
1765 if (! c->eeprom_size || ! c->eeprom_data)
1767 snd_printdd("using the defined eeprom..\n");
1768 ice->eeprom.version = 2;
1769 ice->eeprom.size = c->eeprom_size + 6;
1770 memcpy(ice->eeprom.data, c->eeprom_data, c->eeprom_size);
1777 ice->eeprom.size = snd_vt1724_read_i2c(ice, dev, 0x04);
1778 if (ice->eeprom.size < 6)
1779 ice->eeprom.size = 32;
1780 else if (ice->eeprom.size > 32) {
1781 snd_printk("invalid EEPROM (size = %i)\n", ice->eeprom.size);
1784 ice->eeprom.version = snd_vt1724_read_i2c(ice, dev, 0x05);
1785 if (ice->eeprom.version != 2) {
1786 snd_printk("invalid EEPROM version %i\n", ice->eeprom.version);
1789 size = ice->eeprom.size - 6;
1790 for (i = 0; i < size; i++)
1791 ice->eeprom.data[i] = snd_vt1724_read_i2c(ice, dev, i + 6);
1794 ice->eeprom.gpiomask = eeprom_triple(ice, ICE_EEP2_GPIO_MASK);
1795 ice->eeprom.gpiostate = eeprom_triple(ice, ICE_EEP2_GPIO_STATE);
1796 ice->eeprom.gpiodir = eeprom_triple(ice, ICE_EEP2_GPIO_DIR);
1803 static int __devinit snd_vt1724_chip_init(ice1712_t *ice)
1805 outb(VT1724_RESET , ICEREG1724(ice, CONTROL));
1807 outb(0, ICEREG1724(ice, CONTROL));
1809 outb(ice->eeprom.data[ICE_EEP2_SYSCONF], ICEREG1724(ice, SYS_CFG));
1810 outb(ice->eeprom.data[ICE_EEP2_ACLINK], ICEREG1724(ice, AC97_CFG));
1811 outb(ice->eeprom.data[ICE_EEP2_I2S], ICEREG1724(ice, I2S_FEATURES));
1812 outb(ice->eeprom.data[ICE_EEP2_SPDIF], ICEREG1724(ice, SPDIF_CFG));
1814 ice->gpio.write_mask = ice->eeprom.gpiomask;
1815 ice->gpio.direction = ice->eeprom.gpiodir;
1816 snd_vt1724_set_gpio_mask(ice, ice->eeprom.gpiomask);
1817 snd_vt1724_set_gpio_dir(ice, ice->eeprom.gpiodir);
1818 snd_vt1724_set_gpio_data(ice, ice->eeprom.gpiostate);
1820 outb(0, ICEREG1724(ice, POWERDOWN));
1825 static int __devinit snd_vt1724_spdif_build_controls(ice1712_t *ice)
1828 snd_kcontrol_t *kctl;
1830 snd_assert(ice->pcm != NULL, return -EIO);
1832 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_mixer_pro_spdif_route, ice));
1836 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_spdif_switch, ice));
1840 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_vt1724_spdif_default, ice));
1843 kctl->id.device = ice->pcm->device;
1844 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_vt1724_spdif_maskc, ice));
1847 kctl->id.device = ice->pcm->device;
1848 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_vt1724_spdif_maskp, ice));
1851 kctl->id.device = ice->pcm->device;
1852 #if 0 /* use default only */
1853 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_vt1724_spdif_stream, ice));
1856 kctl->id.device = ice->pcm->device;
1857 ice->spdif.stream_ctl = kctl;
1863 static int __devinit snd_vt1724_build_controls(ice1712_t *ice)
1867 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_eeprom, ice));
1870 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_pro_internal_clock, ice));
1874 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_pro_rate_locking, ice));
1877 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_pro_rate_reset, ice));
1881 if (ice->num_total_dacs > 0) {
1882 snd_kcontrol_new_t tmp = snd_vt1724_mixer_pro_analog_route;
1883 tmp.count = ice->num_total_dacs;
1884 err = snd_ctl_add(ice->card, snd_ctl_new1(&tmp, ice));
1889 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_mixer_pro_peak, ice));
1896 static int snd_vt1724_free(ice1712_t *ice)
1898 if (ice->res_port == NULL)
1900 /* mask all interrupts */
1901 outb(0xff, ICEMT1724(ice, DMA_INT_MASK));
1902 outb(0xff, ICEREG1724(ice, IRQMASK));
1905 if (ice->irq >= 0) {
1906 synchronize_irq(ice->irq);
1907 free_irq(ice->irq, (void *) ice);
1909 if (ice->res_port) {
1910 release_resource(ice->res_port);
1911 kfree_nocheck(ice->res_port);
1913 if (ice->res_profi_port) {
1914 release_resource(ice->res_profi_port);
1915 kfree_nocheck(ice->res_profi_port);
1917 snd_ice1712_akm4xxx_free(ice);
1918 snd_magic_kfree(ice);
1922 static int snd_vt1724_dev_free(snd_device_t *device)
1924 ice1712_t *ice = snd_magic_cast(ice1712_t, device->device_data, return -ENXIO);
1925 return snd_vt1724_free(ice);
1928 static int __devinit snd_vt1724_create(snd_card_t * card,
1929 struct pci_dev *pci,
1930 ice1712_t ** r_ice1712)
1935 static snd_device_ops_t ops = {
1936 .dev_free = snd_vt1724_dev_free,
1941 /* enable PCI device */
1942 if ((err = pci_enable_device(pci)) < 0)
1945 ice = snd_magic_kcalloc(ice1712_t, 0, GFP_KERNEL);
1949 spin_lock_init(&ice->reg_lock);
1950 init_MUTEX(&ice->gpio_mutex);
1951 init_MUTEX(&ice->open_mutex);
1952 ice->gpio.set_mask = snd_vt1724_set_gpio_mask;
1953 ice->gpio.set_dir = snd_vt1724_set_gpio_dir;
1954 ice->gpio.set_data = snd_vt1724_set_gpio_data;
1955 ice->gpio.get_data = snd_vt1724_get_gpio_data;
1959 ice->port = pci_resource_start(pci, 0);
1960 ice->profi_port = pci_resource_start(pci, 1);
1961 pci_set_master(pci);
1962 snd_vt1724_proc_init(ice);
1963 synchronize_irq(pci->irq);
1965 if ((ice->res_port = request_region(ice->port, 32, "ICE1724 - Controller")) == NULL) {
1966 snd_printk("unable to grab ports 0x%lx-0x%lx\n", ice->port, ice->port + 32 - 1);
1967 snd_vt1724_free(ice);
1971 if ((ice->res_profi_port = request_region(ice->profi_port, 128, "ICE1724 - Professional")) == NULL) {
1972 snd_printk("unable to grab ports 0x%lx-0x%lx\n", ice->profi_port, ice->profi_port + 16 - 1);
1973 snd_vt1724_free(ice);
1977 if (request_irq(pci->irq, snd_vt1724_interrupt, SA_INTERRUPT|SA_SHIRQ, "ICE1724", (void *) ice)) {
1978 snd_printk("unable to grab IRQ %d\n", pci->irq);
1979 snd_vt1724_free(ice);
1983 ice->irq = pci->irq;
1985 if (snd_vt1724_read_eeprom(ice) < 0) {
1986 snd_vt1724_free(ice);
1989 if (snd_vt1724_chip_init(ice) < 0) {
1990 snd_vt1724_free(ice);
1994 /* unmask used interrupts */
1995 if (! (ice->eeprom.data[ICE_EEP2_SYSCONF] & VT1724_CFG_MPU401))
1996 mask = VT1724_IRQ_MPU_RX | VT1724_IRQ_MPU_TX;
1999 outb(mask, ICEREG1724(ice, IRQMASK));
2000 /* don't handle FIFO overrun/underruns (just yet), since they cause machine lockups */
2001 outb(VT1724_MULTI_FIFO_ERR, ICEMT1724(ice, DMA_INT_MASK));
2003 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, ice, &ops)) < 0) {
2004 snd_vt1724_free(ice);
2008 snd_card_set_dev(card, &pci->dev);
2021 static int __devinit snd_vt1724_probe(struct pci_dev *pci,
2022 const struct pci_device_id *pci_id)
2027 int pcm_dev = 0, err;
2028 struct snd_ice1712_card_info **tbl, *c;
2030 if (dev >= SNDRV_CARDS)
2037 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
2041 strcpy(card->driver, "ICE1724");
2042 strcpy(card->shortname, "ICEnsemble ICE1724");
2044 if ((err = snd_vt1724_create(card, pci, &ice)) < 0) {
2045 snd_card_free(card);
2049 for (tbl = card_tables; *tbl; tbl++) {
2050 for (c = *tbl; c->subvendor; c++) {
2051 if (c->subvendor == ice->eeprom.subvendor) {
2052 strcpy(card->shortname, c->name);
2054 if ((err = c->chip_init(ice)) < 0) {
2055 snd_card_free(card);
2066 if ((err = snd_vt1724_pcm_profi(ice, pcm_dev++)) < 0) {
2067 snd_card_free(card);
2071 if ((err = snd_vt1724_pcm_spdif(ice, pcm_dev++)) < 0) {
2072 snd_card_free(card);
2076 if ((err = snd_vt1724_pcm_indep(ice, pcm_dev++)) < 0) {
2077 snd_card_free(card);
2081 if ((err = snd_vt1724_ac97_mixer(ice)) < 0) {
2082 snd_card_free(card);
2086 if ((err = snd_vt1724_build_controls(ice)) < 0) {
2087 snd_card_free(card);
2091 if (ice->pcm) { /* has SPDIF I/O */
2092 if ((err = snd_vt1724_spdif_build_controls(ice)) < 0) {
2093 snd_card_free(card);
2098 if (c->build_controls) {
2099 if ((err = c->build_controls(ice)) < 0) {
2100 snd_card_free(card);
2105 if (! c->no_mpu401) {
2106 if (ice->eeprom.data[ICE_EEP2_SYSCONF] & VT1724_CFG_MPU401) {
2107 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_ICE1712,
2108 ICEREG1724(ice, MPU_CTRL), 1,
2110 &ice->rmidi[0])) < 0) {
2111 snd_card_free(card);
2117 sprintf(card->longname, "%s at 0x%lx, irq %i",
2118 card->shortname, ice->port, ice->irq);
2120 if ((err = snd_card_register(card)) < 0) {
2121 snd_card_free(card);
2124 pci_set_drvdata(pci, card);
2129 static void __devexit snd_vt1724_remove(struct pci_dev *pci)
2131 snd_card_free(pci_get_drvdata(pci));
2132 pci_set_drvdata(pci, NULL);
2135 static struct pci_driver driver = {
2137 .id_table = snd_vt1724_ids,
2138 .probe = snd_vt1724_probe,
2139 .remove = __devexit_p(snd_vt1724_remove),
2142 static int __init alsa_card_ice1724_init(void)
2146 if ((err = pci_module_init(&driver)) < 0) {
2148 printk(KERN_ERR "ICE1724 soundcard not found or device busy\n");
2155 static void __exit alsa_card_ice1724_exit(void)
2157 pci_unregister_driver(&driver);
2160 module_init(alsa_card_ice1724_init)
2161 module_exit(alsa_card_ice1724_exit)
2165 /* format is: snd-ice1724=enable,index,id */
2167 static int __init alsa_card_ice1724_setup(char *str)
2169 static unsigned __initdata nr_dev = 0;
2171 if (nr_dev >= SNDRV_CARDS)
2173 (void)(get_option(&str,&enable[nr_dev]) == 2 &&
2174 get_option(&str,&index[nr_dev]) == 2 &&
2175 get_id(&str,&id[nr_dev]) == 2);
2180 __setup("snd-ice1724=", alsa_card_ice1724_setup);
2182 #endif /* ifndef MODULE */