2 * ALSA driver for VT1724 ICEnsemble ICE1724 / VIA VT1724 (Envy24HT)
3 * VIA VT1720 (Envy24PT)
5 * Copyright (c) 2000 Jaroslav Kysela <perex@suse.cz>
6 * 2002 James Stafford <jstafford@ampltd.com>
7 * 2003 Takashi Iwai <tiwai@suse.de>
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.
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.
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
25 #include <sound/driver.h>
27 #include <linux/delay.h>
28 #include <linux/interrupt.h>
29 #include <linux/init.h>
30 #include <linux/pci.h>
31 #include <linux/slab.h>
32 #include <linux/moduleparam.h>
33 #include <sound/core.h>
34 #include <sound/info.h>
35 #include <sound/mpu401.h>
36 #include <sound/initval.h>
38 #include <sound/asoundef.h>
43 /* lowlevel routines */
47 #include "vt1720_mobo.h"
49 #include "prodigy192.h"
52 MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
53 MODULE_DESCRIPTION("VIA ICEnsemble ICE1724/1720 (Envy24HT/PT)");
54 MODULE_LICENSE("GPL");
55 MODULE_SUPPORTED_DEVICE("{"
57 AMP_AUDIO2000_DEVICE_DESC
59 VT1720_MOBO_DEVICE_DESC
61 PRODIGY192_DEVICE_DESC
64 "{ICEnsemble,Generic ICE1724},"
65 "{ICEnsemble,Generic Envy24HT}"
66 "{ICEnsemble,Generic Envy24PT}}");
68 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
69 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
70 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */
71 static char *model[SNDRV_CARDS];
73 module_param_array(index, int, NULL, 0444);
74 MODULE_PARM_DESC(index, "Index value for ICE1724 soundcard.");
75 module_param_array(id, charp, NULL, 0444);
76 MODULE_PARM_DESC(id, "ID string for ICE1724 soundcard.");
77 module_param_array(enable, bool, NULL, 0444);
78 MODULE_PARM_DESC(enable, "Enable ICE1724 soundcard.");
79 module_param_array(model, charp, NULL, 0444);
80 MODULE_PARM_DESC(model, "Use the given board model.");
82 #ifndef PCI_VENDOR_ID_ICE
83 #define PCI_VENDOR_ID_ICE 0x1412
85 #ifndef PCI_DEVICE_ID_VT1724
86 #define PCI_DEVICE_ID_VT1724 0x1724
89 /* Both VT1720 and VT1724 have the same PCI IDs */
90 static struct pci_device_id snd_vt1724_ids[] = {
91 { PCI_VENDOR_ID_ICE, PCI_DEVICE_ID_VT1724, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
95 MODULE_DEVICE_TABLE(pci, snd_vt1724_ids);
98 static int PRO_RATE_LOCKED;
99 static int PRO_RATE_RESET = 1;
100 static unsigned int PRO_RATE_DEFAULT = 44100;
106 /* check whether the clock mode is spdif-in */
107 static inline int is_spdif_master(ice1712_t *ice)
109 return (inb(ICEMT1724(ice, RATE)) & VT1724_SPDIF_MASTER) ? 1 : 0;
112 static inline int is_pro_rate_locked(ice1712_t *ice)
114 return is_spdif_master(ice) || PRO_RATE_LOCKED;
121 static unsigned char snd_vt1724_ac97_ready(ice1712_t *ice)
123 unsigned char old_cmd;
125 for (tm = 0; tm < 0x10000; tm++) {
126 old_cmd = inb(ICEMT1724(ice, AC97_CMD));
127 if (old_cmd & (VT1724_AC97_WRITE | VT1724_AC97_READ))
129 if (!(old_cmd & VT1724_AC97_READY))
133 snd_printd(KERN_ERR "snd_vt1724_ac97_ready: timeout\n");
137 static int snd_vt1724_ac97_wait_bit(ice1712_t *ice, unsigned char bit)
140 for (tm = 0; tm < 0x10000; tm++)
141 if ((inb(ICEMT1724(ice, AC97_CMD)) & bit) == 0)
143 snd_printd(KERN_ERR "snd_vt1724_ac97_wait_bit: timeout\n");
147 static void snd_vt1724_ac97_write(ac97_t *ac97,
151 ice1712_t *ice = (ice1712_t *)ac97->private_data;
152 unsigned char old_cmd;
154 old_cmd = snd_vt1724_ac97_ready(ice);
155 old_cmd &= ~VT1724_AC97_ID_MASK;
156 old_cmd |= ac97->num;
157 outb(reg, ICEMT1724(ice, AC97_INDEX));
158 outw(val, ICEMT1724(ice, AC97_DATA));
159 outb(old_cmd | VT1724_AC97_WRITE, ICEMT1724(ice, AC97_CMD));
160 snd_vt1724_ac97_wait_bit(ice, VT1724_AC97_WRITE);
163 static unsigned short snd_vt1724_ac97_read(ac97_t *ac97, unsigned short reg)
165 ice1712_t *ice = (ice1712_t *)ac97->private_data;
166 unsigned char old_cmd;
168 old_cmd = snd_vt1724_ac97_ready(ice);
169 old_cmd &= ~VT1724_AC97_ID_MASK;
170 old_cmd |= ac97->num;
171 outb(reg, ICEMT1724(ice, AC97_INDEX));
172 outb(old_cmd | VT1724_AC97_READ, ICEMT1724(ice, AC97_CMD));
173 if (snd_vt1724_ac97_wait_bit(ice, VT1724_AC97_READ) < 0)
175 return inw(ICEMT1724(ice, AC97_DATA));
183 /* set gpio direction 0 = read, 1 = write */
184 static void snd_vt1724_set_gpio_dir(ice1712_t *ice, unsigned int data)
186 outl(data, ICEREG1724(ice, GPIO_DIRECTION));
187 inw(ICEREG1724(ice, GPIO_DIRECTION)); /* dummy read for pci-posting */
190 /* set the gpio mask (0 = writable) */
191 static void snd_vt1724_set_gpio_mask(ice1712_t *ice, unsigned int data)
193 outw(data, ICEREG1724(ice, GPIO_WRITE_MASK));
194 if (! ice->vt1720) /* VT1720 supports only 16 GPIO bits */
195 outb((data >> 16) & 0xff, ICEREG1724(ice, GPIO_WRITE_MASK_22));
196 inw(ICEREG1724(ice, GPIO_WRITE_MASK)); /* dummy read for pci-posting */
199 static void snd_vt1724_set_gpio_data(ice1712_t *ice, unsigned int data)
201 outw(data, ICEREG1724(ice, GPIO_DATA));
203 outb(data >> 16, ICEREG1724(ice, GPIO_DATA_22));
204 inw(ICEREG1724(ice, GPIO_DATA)); /* dummy read for pci-posting */
207 static unsigned int snd_vt1724_get_gpio_data(ice1712_t *ice)
211 data = (unsigned int)inb(ICEREG1724(ice, GPIO_DATA_22));
214 data = (data << 16) | inw(ICEREG1724(ice, GPIO_DATA));
222 static irqreturn_t snd_vt1724_interrupt(int irq, void *dev_id, struct pt_regs *regs)
224 ice1712_t *ice = dev_id;
225 unsigned char status;
229 status = inb(ICEREG1724(ice, IRQSTAT));
234 /* these should probably be separated at some point,
235 but as we don't currently have MPU support on the board I will leave it */
236 if ((status & VT1724_IRQ_MPU_RX)||(status & VT1724_IRQ_MPU_TX)) {
238 snd_mpu401_uart_interrupt(irq, ice->rmidi[0]->private_data, regs);
239 outb(status & (VT1724_IRQ_MPU_RX|VT1724_IRQ_MPU_TX), ICEREG1724(ice, IRQSTAT));
240 status &= ~(VT1724_IRQ_MPU_RX|VT1724_IRQ_MPU_TX);
242 if (status & VT1724_IRQ_MTPCM) {
245 * PCM assignment are:
246 * Playback DMA0 (M/C) = playback_pro_substream
247 * Playback DMA1 = playback_con_substream_ds[0]
248 * Playback DMA2 = playback_con_substream_ds[1]
249 * Playback DMA3 = playback_con_substream_ds[2]
250 * Playback DMA4 (SPDIF) = playback_con_substream
251 * Record DMA0 = capture_pro_substream
252 * Record DMA1 = capture_con_substream
254 unsigned char mtstat = inb(ICEMT1724(ice, IRQ));
255 if (mtstat & VT1724_MULTI_PDMA0) {
256 if (ice->playback_pro_substream)
257 snd_pcm_period_elapsed(ice->playback_pro_substream);
259 if (mtstat & VT1724_MULTI_RDMA0) {
260 if (ice->capture_pro_substream)
261 snd_pcm_period_elapsed(ice->capture_pro_substream);
263 if (mtstat & VT1724_MULTI_PDMA1) {
264 if (ice->playback_con_substream_ds[0])
265 snd_pcm_period_elapsed(ice->playback_con_substream_ds[0]);
267 if (mtstat & VT1724_MULTI_PDMA2) {
268 if (ice->playback_con_substream_ds[1])
269 snd_pcm_period_elapsed(ice->playback_con_substream_ds[1]);
271 if (mtstat & VT1724_MULTI_PDMA3) {
272 if (ice->playback_con_substream_ds[2])
273 snd_pcm_period_elapsed(ice->playback_con_substream_ds[2]);
275 if (mtstat & VT1724_MULTI_PDMA4) {
276 if (ice->playback_con_substream)
277 snd_pcm_period_elapsed(ice->playback_con_substream);
279 if (mtstat & VT1724_MULTI_RDMA1) {
280 if (ice->capture_con_substream)
281 snd_pcm_period_elapsed(ice->capture_con_substream);
283 /* ack anyway to avoid freeze */
284 outb(mtstat, ICEMT1724(ice, IRQ));
285 /* ought to really handle this properly */
286 if (mtstat & VT1724_MULTI_FIFO_ERR) {
287 unsigned char fstat = inb(ICEMT1724(ice, DMA_FIFO_ERR));
288 outb(fstat, ICEMT1724(ice, DMA_FIFO_ERR));
289 outb(VT1724_MULTI_FIFO_ERR | inb(ICEMT1724(ice, DMA_INT_MASK)), ICEMT1724(ice, DMA_INT_MASK));
290 /* If I don't do this, I get machine lockup due to continual interrupts */
295 return IRQ_RETVAL(handled);
299 * PCM code - professional part (multitrack)
302 static unsigned int rates[] = {
303 8000, 9600, 11025, 12000, 16000, 22050, 24000,
304 32000, 44100, 48000, 64000, 88200, 96000,
308 static snd_pcm_hw_constraint_list_t hw_constraints_rates_96 = {
309 .count = ARRAY_SIZE(rates) - 2, /* up to 96000 */
314 static snd_pcm_hw_constraint_list_t hw_constraints_rates_48 = {
315 .count = ARRAY_SIZE(rates) - 5, /* up to 48000 */
320 static snd_pcm_hw_constraint_list_t hw_constraints_rates_192 = {
321 .count = ARRAY_SIZE(rates),
326 struct vt1724_pcm_reg {
327 unsigned int addr; /* ADDR register offset */
328 unsigned int size; /* SIZE register offset */
329 unsigned int count; /* COUNT register offset */
330 unsigned int start; /* start & pause bit */
333 static int snd_vt1724_pcm_trigger(snd_pcm_substream_t *substream, int cmd)
335 ice1712_t *ice = snd_pcm_substream_chip(substream);
338 struct list_head *pos;
339 snd_pcm_substream_t *s;
342 snd_pcm_group_for_each(pos, substream) {
343 struct vt1724_pcm_reg *reg;
344 s = snd_pcm_group_substream_entry(pos);
345 reg = s->runtime->private_data;
347 snd_pcm_trigger_done(s, substream);
351 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
352 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
353 spin_lock(&ice->reg_lock);
354 old = inb(ICEMT1724(ice, DMA_PAUSE));
355 if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH)
359 outb(old, ICEMT1724(ice, DMA_PAUSE));
360 spin_unlock(&ice->reg_lock);
363 case SNDRV_PCM_TRIGGER_START:
364 case SNDRV_PCM_TRIGGER_STOP:
365 spin_lock(&ice->reg_lock);
366 old = inb(ICEMT1724(ice, DMA_CONTROL));
367 if (cmd == SNDRV_PCM_TRIGGER_START)
371 outb(old, ICEMT1724(ice, DMA_CONTROL));
372 spin_unlock(&ice->reg_lock);
384 #define DMA_STARTS (VT1724_RDMA0_START|VT1724_PDMA0_START|VT1724_RDMA1_START|\
385 VT1724_PDMA1_START|VT1724_PDMA2_START|VT1724_PDMA3_START|VT1724_PDMA4_START)
386 #define DMA_PAUSES (VT1724_RDMA0_PAUSE|VT1724_PDMA0_PAUSE|VT1724_RDMA1_PAUSE|\
387 VT1724_PDMA1_PAUSE|VT1724_PDMA2_PAUSE|VT1724_PDMA3_PAUSE|VT1724_PDMA4_PAUSE)
389 static int get_max_rate(ice1712_t *ice)
391 if (ice->eeprom.data[ICE_EEP2_ACLINK] & VT1724_CFG_PRO_I2S) {
392 if ((ice->eeprom.data[ICE_EEP2_I2S] & 0x08) && !ice->vt1720)
400 static void snd_vt1724_set_pro_rate(ice1712_t *ice, unsigned int rate, int force)
403 unsigned char val, old;
406 if (rate > get_max_rate(ice))
409 spin_lock_irqsave(&ice->reg_lock, flags);
410 if ((inb(ICEMT1724(ice, DMA_CONTROL)) & DMA_STARTS) ||
411 (inb(ICEMT1724(ice, DMA_PAUSE)) & DMA_PAUSES)) {
412 /* running? we cannot change the rate now... */
413 spin_unlock_irqrestore(&ice->reg_lock, flags);
416 if (!force && is_pro_rate_locked(ice)) {
417 spin_unlock_irqrestore(&ice->reg_lock, flags);
422 case 8000: val = 6; break;
423 case 9600: val = 3; break;
424 case 11025: val = 10; break;
425 case 12000: val = 2; break;
426 case 16000: val = 5; break;
427 case 22050: val = 9; break;
428 case 24000: val = 1; break;
429 case 32000: val = 4; break;
430 case 44100: val = 8; break;
431 case 48000: val = 0; break;
432 case 64000: val = 15; break;
433 case 88200: val = 11; break;
434 case 96000: val = 7; break;
435 case 176400: val = 12; break;
436 case 192000: val = 14; break;
442 old = inb(ICEMT1724(ice, RATE));
444 outb(val, ICEMT1724(ice, RATE));
445 else if (rate == ice->cur_rate) {
446 spin_unlock_irqrestore(&ice->reg_lock, flags);
450 ice->cur_rate = rate;
453 if (ice->eeprom.data[ICE_EEP2_ACLINK] & VT1724_CFG_PRO_I2S) {
454 val = old = inb(ICEMT1724(ice, I2S_FORMAT));
456 val |= VT1724_MT_I2S_MCLK_128X; /* 128x MCLK */
458 val &= ~VT1724_MT_I2S_MCLK_128X; /* 256x MCLK */
460 outb(val, ICEMT1724(ice, I2S_FORMAT));
461 if (ice->eeprom.subvendor == VT1724_SUBDEVICE_REVOLUTION71) {
462 /* FIXME: is this revo only? */
463 /* assert PRST# to converters; MT05 bit 7 */
464 outb(inb(ICEMT1724(ice, AC97_CMD)) | 0x80, ICEMT1724(ice, AC97_CMD));
465 spin_unlock_irqrestore(&ice->reg_lock, flags);
467 spin_lock_irqsave(&ice->reg_lock, flags);
469 outb(inb(ICEMT1724(ice, AC97_CMD)) & ~0x80, ICEMT1724(ice, AC97_CMD));
473 spin_unlock_irqrestore(&ice->reg_lock, flags);
476 for (i = 0; i < ice->akm_codecs; i++) {
477 if (ice->akm[i].ops.set_rate_val)
478 ice->akm[i].ops.set_rate_val(&ice->akm[i], rate);
482 static int snd_vt1724_pcm_hw_params(snd_pcm_substream_t * substream,
483 snd_pcm_hw_params_t * hw_params)
485 ice1712_t *ice = snd_pcm_substream_chip(substream);
488 chs = params_channels(hw_params);
489 down(&ice->open_mutex);
490 /* mark surround channels */
491 if (substream == ice->playback_pro_substream) {
492 /* PDMA0 can be multi-channel up to 8 */
494 for (i = 0; i < chs; i++) {
495 if (ice->pcm_reserved[i] && ice->pcm_reserved[i] != substream) {
496 up(&ice->open_mutex);
499 ice->pcm_reserved[i] = substream;
502 if (ice->pcm_reserved[i] == substream)
503 ice->pcm_reserved[i] = NULL;
506 for (i = 0; i < 3; i++) {
507 /* check individual playback stream */
508 if (ice->playback_con_substream_ds[i] == substream) {
509 if (ice->pcm_reserved[i] && ice->pcm_reserved[i] != substream) {
510 up(&ice->open_mutex);
513 ice->pcm_reserved[i] = substream;
518 up(&ice->open_mutex);
519 snd_vt1724_set_pro_rate(ice, params_rate(hw_params), 0);
520 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
523 static int snd_vt1724_pcm_hw_free(snd_pcm_substream_t * substream)
525 ice1712_t *ice = snd_pcm_substream_chip(substream);
528 down(&ice->open_mutex);
529 /* unmark surround channels */
530 for (i = 0; i < 3; i++)
531 if (ice->pcm_reserved[i] == substream)
532 ice->pcm_reserved[i] = NULL;
533 up(&ice->open_mutex);
534 return snd_pcm_lib_free_pages(substream);
537 static int snd_vt1724_playback_pro_prepare(snd_pcm_substream_t * substream)
539 ice1712_t *ice = snd_pcm_substream_chip(substream);
543 spin_lock_irq(&ice->reg_lock);
544 val = (8 - substream->runtime->channels) >> 1;
545 outb(val, ICEMT1724(ice, BURST));
547 outl(substream->runtime->dma_addr, ICEMT1724(ice, PLAYBACK_ADDR));
549 size = (snd_pcm_lib_buffer_bytes(substream) >> 2) - 1;
550 // outl(size, ICEMT1724(ice, PLAYBACK_SIZE));
551 outw(size, ICEMT1724(ice, PLAYBACK_SIZE));
552 outb(size >> 16, ICEMT1724(ice, PLAYBACK_SIZE) + 2);
553 size = (snd_pcm_lib_period_bytes(substream) >> 2) - 1;
554 // outl(size, ICEMT1724(ice, PLAYBACK_COUNT));
555 outw(size, ICEMT1724(ice, PLAYBACK_COUNT));
556 outb(size >> 16, ICEMT1724(ice, PLAYBACK_COUNT) + 2);
558 spin_unlock_irq(&ice->reg_lock);
560 // 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));
564 static snd_pcm_uframes_t snd_vt1724_playback_pro_pointer(snd_pcm_substream_t * substream)
566 ice1712_t *ice = snd_pcm_substream_chip(substream);
569 if (!(inl(ICEMT1724(ice, DMA_CONTROL)) & VT1724_PDMA0_START))
571 #if 0 /* read PLAYBACK_ADDR */
572 ptr = inl(ICEMT1724(ice, PLAYBACK_ADDR));
573 if (ptr < substream->runtime->dma_addr) {
574 snd_printd("ice1724: invalid negative ptr\n");
577 ptr -= substream->runtime->dma_addr;
578 ptr = bytes_to_frames(substream->runtime, ptr);
579 if (ptr >= substream->runtime->buffer_size) {
580 snd_printd("ice1724: invalid ptr %d (size=%d)\n", (int)ptr, (int)substream->runtime->period_size);
583 #else /* read PLAYBACK_SIZE */
584 ptr = inl(ICEMT1724(ice, PLAYBACK_SIZE)) & 0xffffff;
585 ptr = (ptr + 1) << 2;
586 ptr = bytes_to_frames(substream->runtime, ptr);
589 else if (ptr <= substream->runtime->buffer_size)
590 ptr = substream->runtime->buffer_size - ptr;
592 snd_printd("ice1724: invalid ptr %d (size=%d)\n", (int)ptr, (int)substream->runtime->buffer_size);
599 static int snd_vt1724_pcm_prepare(snd_pcm_substream_t *substream)
601 ice1712_t *ice = snd_pcm_substream_chip(substream);
602 struct vt1724_pcm_reg *reg = substream->runtime->private_data;
604 spin_lock_irq(&ice->reg_lock);
605 outl(substream->runtime->dma_addr, ice->profi_port + reg->addr);
606 outw((snd_pcm_lib_buffer_bytes(substream) >> 2) - 1, ice->profi_port + reg->size);
607 outw((snd_pcm_lib_period_bytes(substream) >> 2) - 1, ice->profi_port + reg->count);
608 spin_unlock_irq(&ice->reg_lock);
612 static snd_pcm_uframes_t snd_vt1724_pcm_pointer(snd_pcm_substream_t *substream)
614 ice1712_t *ice = snd_pcm_substream_chip(substream);
615 struct vt1724_pcm_reg *reg = substream->runtime->private_data;
618 if (!(inl(ICEMT1724(ice, DMA_CONTROL)) & reg->start))
620 #if 0 /* use ADDR register */
621 ptr = inl(ice->profi_port + reg->addr);
622 ptr -= substream->runtime->dma_addr;
623 return bytes_to_frames(substream->runtime, ptr);
624 #else /* use SIZE register */
625 ptr = inw(ice->profi_port + reg->size);
626 ptr = (ptr + 1) << 2;
627 ptr = bytes_to_frames(substream->runtime, ptr);
630 else if (ptr <= substream->runtime->buffer_size)
631 ptr = substream->runtime->buffer_size - ptr;
633 snd_printd("ice1724: invalid ptr %d (size=%d)\n", (int)ptr, (int)substream->runtime->buffer_size);
640 static struct vt1724_pcm_reg vt1724_playback_pro_reg = {
641 .addr = VT1724_MT_PLAYBACK_ADDR,
642 .size = VT1724_MT_PLAYBACK_SIZE,
643 .count = VT1724_MT_PLAYBACK_COUNT,
644 .start = VT1724_PDMA0_START,
647 static struct vt1724_pcm_reg vt1724_capture_pro_reg = {
648 .addr = VT1724_MT_CAPTURE_ADDR,
649 .size = VT1724_MT_CAPTURE_SIZE,
650 .count = VT1724_MT_CAPTURE_COUNT,
651 .start = VT1724_RDMA0_START,
654 static snd_pcm_hardware_t snd_vt1724_playback_pro =
656 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
657 SNDRV_PCM_INFO_BLOCK_TRANSFER |
658 SNDRV_PCM_INFO_MMAP_VALID |
659 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START),
660 .formats = SNDRV_PCM_FMTBIT_S32_LE,
661 .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_192000,
666 .buffer_bytes_max = (1UL << 21), /* 19bits dword */
667 .period_bytes_min = 8 * 4 * 2, /* FIXME: constraints needed */
668 .period_bytes_max = (1UL << 21),
673 static snd_pcm_hardware_t snd_vt1724_spdif =
675 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
676 SNDRV_PCM_INFO_BLOCK_TRANSFER |
677 SNDRV_PCM_INFO_MMAP_VALID |
678 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START),
679 .formats = SNDRV_PCM_FMTBIT_S32_LE,
680 .rates = SNDRV_PCM_RATE_32000|SNDRV_PCM_RATE_44100|SNDRV_PCM_RATE_48000,
685 .buffer_bytes_max = (1UL << 18), /* 16bits dword */
686 .period_bytes_min = 2 * 4 * 2,
687 .period_bytes_max = (1UL << 18),
692 static snd_pcm_hardware_t snd_vt1724_2ch_stereo =
694 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
695 SNDRV_PCM_INFO_BLOCK_TRANSFER |
696 SNDRV_PCM_INFO_MMAP_VALID |
697 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START),
698 .formats = SNDRV_PCM_FMTBIT_S32_LE,
699 .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_192000,
704 .buffer_bytes_max = (1UL << 18), /* 16bits dword */
705 .period_bytes_min = 2 * 4 * 2,
706 .period_bytes_max = (1UL << 18),
712 * set rate constraints
714 static int set_rate_constraints(ice1712_t *ice, snd_pcm_substream_t *substream)
716 snd_pcm_runtime_t *runtime = substream->runtime;
717 if (ice->eeprom.data[ICE_EEP2_ACLINK] & VT1724_CFG_PRO_I2S) {
719 /* VT1720 doesn't support more than 96kHz */
720 if ((ice->eeprom.data[ICE_EEP2_I2S] & 0x08) && !ice->vt1720)
721 return snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates_192);
723 runtime->hw.rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_96000;
724 runtime->hw.rate_max = 96000;
725 return snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates_96);
727 } else if (ice->ac97) {
729 runtime->hw.rate_max = 48000;
730 runtime->hw.rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000;
731 return snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates_48);
736 /* multi-channel playback needs alignment 8x32bit regardless of the channels
739 #define VT1724_BUFFER_ALIGN 0x20
741 static int snd_vt1724_playback_pro_open(snd_pcm_substream_t * substream)
743 snd_pcm_runtime_t *runtime = substream->runtime;
744 ice1712_t *ice = snd_pcm_substream_chip(substream);
747 runtime->private_data = &vt1724_playback_pro_reg;
748 ice->playback_pro_substream = substream;
749 runtime->hw = snd_vt1724_playback_pro;
750 snd_pcm_set_sync(substream);
751 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
752 set_rate_constraints(ice, substream);
753 down(&ice->open_mutex);
754 /* calculate the currently available channels */
755 for (chs = 0; chs < 3; chs++) {
756 if (ice->pcm_reserved[chs])
760 runtime->hw.channels_max = chs;
761 if (chs > 2) /* channels must be even */
762 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, 2);
763 up(&ice->open_mutex);
764 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
765 VT1724_BUFFER_ALIGN);
766 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
767 VT1724_BUFFER_ALIGN);
771 static int snd_vt1724_capture_pro_open(snd_pcm_substream_t * substream)
773 ice1712_t *ice = snd_pcm_substream_chip(substream);
774 snd_pcm_runtime_t *runtime = substream->runtime;
776 runtime->private_data = &vt1724_capture_pro_reg;
777 ice->capture_pro_substream = substream;
778 runtime->hw = snd_vt1724_2ch_stereo;
779 snd_pcm_set_sync(substream);
780 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
781 set_rate_constraints(ice, substream);
782 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
783 VT1724_BUFFER_ALIGN);
784 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
785 VT1724_BUFFER_ALIGN);
789 static int snd_vt1724_playback_pro_close(snd_pcm_substream_t * substream)
791 ice1712_t *ice = snd_pcm_substream_chip(substream);
794 snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
795 ice->playback_pro_substream = NULL;
800 static int snd_vt1724_capture_pro_close(snd_pcm_substream_t * substream)
802 ice1712_t *ice = snd_pcm_substream_chip(substream);
805 snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
806 ice->capture_pro_substream = NULL;
810 static snd_pcm_ops_t snd_vt1724_playback_pro_ops = {
811 .open = snd_vt1724_playback_pro_open,
812 .close = snd_vt1724_playback_pro_close,
813 .ioctl = snd_pcm_lib_ioctl,
814 .hw_params = snd_vt1724_pcm_hw_params,
815 .hw_free = snd_vt1724_pcm_hw_free,
816 .prepare = snd_vt1724_playback_pro_prepare,
817 .trigger = snd_vt1724_pcm_trigger,
818 .pointer = snd_vt1724_playback_pro_pointer,
821 static snd_pcm_ops_t snd_vt1724_capture_pro_ops = {
822 .open = snd_vt1724_capture_pro_open,
823 .close = snd_vt1724_capture_pro_close,
824 .ioctl = snd_pcm_lib_ioctl,
825 .hw_params = snd_vt1724_pcm_hw_params,
826 .hw_free = snd_vt1724_pcm_hw_free,
827 .prepare = snd_vt1724_pcm_prepare,
828 .trigger = snd_vt1724_pcm_trigger,
829 .pointer = snd_vt1724_pcm_pointer,
832 static int __devinit snd_vt1724_pcm_profi(ice1712_t * ice, int device)
837 err = snd_pcm_new(ice->card, "ICE1724", device, 1, 1, &pcm);
841 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_vt1724_playback_pro_ops);
842 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_vt1724_capture_pro_ops);
844 pcm->private_data = ice;
846 strcpy(pcm->name, "ICE1724");
848 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
849 snd_dma_pci_data(ice->pci), 256*1024, 256*1024);
861 static struct vt1724_pcm_reg vt1724_playback_spdif_reg = {
862 .addr = VT1724_MT_PDMA4_ADDR,
863 .size = VT1724_MT_PDMA4_SIZE,
864 .count = VT1724_MT_PDMA4_COUNT,
865 .start = VT1724_PDMA4_START,
868 static struct vt1724_pcm_reg vt1724_capture_spdif_reg = {
869 .addr = VT1724_MT_RDMA1_ADDR,
870 .size = VT1724_MT_RDMA1_SIZE,
871 .count = VT1724_MT_RDMA1_COUNT,
872 .start = VT1724_RDMA1_START,
875 /* update spdif control bits; call with reg_lock */
876 static void update_spdif_bits(ice1712_t *ice, unsigned int val)
878 unsigned char cbit, disabled;
880 cbit = inb(ICEREG1724(ice, SPDIF_CFG));
881 disabled = cbit & ~VT1724_CFG_SPDIF_OUT_EN;
882 if (cbit != disabled)
883 outb(disabled, ICEREG1724(ice, SPDIF_CFG));
884 outw(val, ICEMT1724(ice, SPDIF_CTRL));
885 if (cbit != disabled)
886 outb(cbit, ICEREG1724(ice, SPDIF_CFG));
887 outw(val, ICEMT1724(ice, SPDIF_CTRL));
890 /* update SPDIF control bits according to the given rate */
891 static void update_spdif_rate(ice1712_t *ice, unsigned int rate)
893 unsigned int val, nval;
896 spin_lock_irqsave(&ice->reg_lock, flags);
897 nval = val = inw(ICEMT1724(ice, SPDIF_CTRL));
901 case 48000: nval |= 2 << 12; break;
902 case 32000: nval |= 3 << 12; break;
905 update_spdif_bits(ice, nval);
906 spin_unlock_irqrestore(&ice->reg_lock, flags);
909 static int snd_vt1724_playback_spdif_prepare(snd_pcm_substream_t * substream)
911 ice1712_t *ice = snd_pcm_substream_chip(substream);
912 if (! ice->force_pdma4)
913 update_spdif_rate(ice, substream->runtime->rate);
914 return snd_vt1724_pcm_prepare(substream);
917 static int snd_vt1724_playback_spdif_open(snd_pcm_substream_t *substream)
919 ice1712_t *ice = snd_pcm_substream_chip(substream);
920 snd_pcm_runtime_t *runtime = substream->runtime;
922 runtime->private_data = &vt1724_playback_spdif_reg;
923 ice->playback_con_substream = substream;
924 if (ice->force_pdma4) {
925 runtime->hw = snd_vt1724_2ch_stereo;
926 set_rate_constraints(ice, substream);
928 runtime->hw = snd_vt1724_spdif;
929 snd_pcm_set_sync(substream);
930 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
931 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
932 VT1724_BUFFER_ALIGN);
933 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
934 VT1724_BUFFER_ALIGN);
938 static int snd_vt1724_playback_spdif_close(snd_pcm_substream_t * substream)
940 ice1712_t *ice = snd_pcm_substream_chip(substream);
943 snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
944 ice->playback_con_substream = NULL;
949 static int snd_vt1724_capture_spdif_open(snd_pcm_substream_t *substream)
951 ice1712_t *ice = snd_pcm_substream_chip(substream);
952 snd_pcm_runtime_t *runtime = substream->runtime;
954 runtime->private_data = &vt1724_capture_spdif_reg;
955 ice->capture_con_substream = substream;
956 if (ice->force_rdma1) {
957 runtime->hw = snd_vt1724_2ch_stereo;
958 set_rate_constraints(ice, substream);
960 runtime->hw = snd_vt1724_spdif;
961 snd_pcm_set_sync(substream);
962 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
963 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
964 VT1724_BUFFER_ALIGN);
965 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
966 VT1724_BUFFER_ALIGN);
970 static int snd_vt1724_capture_spdif_close(snd_pcm_substream_t * substream)
972 ice1712_t *ice = snd_pcm_substream_chip(substream);
975 snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
976 ice->capture_con_substream = NULL;
981 static snd_pcm_ops_t snd_vt1724_playback_spdif_ops = {
982 .open = snd_vt1724_playback_spdif_open,
983 .close = snd_vt1724_playback_spdif_close,
984 .ioctl = snd_pcm_lib_ioctl,
985 .hw_params = snd_vt1724_pcm_hw_params,
986 .hw_free = snd_vt1724_pcm_hw_free,
987 .prepare = snd_vt1724_playback_spdif_prepare,
988 .trigger = snd_vt1724_pcm_trigger,
989 .pointer = snd_vt1724_pcm_pointer,
992 static snd_pcm_ops_t snd_vt1724_capture_spdif_ops = {
993 .open = snd_vt1724_capture_spdif_open,
994 .close = snd_vt1724_capture_spdif_close,
995 .ioctl = snd_pcm_lib_ioctl,
996 .hw_params = snd_vt1724_pcm_hw_params,
997 .hw_free = snd_vt1724_pcm_hw_free,
998 .prepare = snd_vt1724_pcm_prepare,
999 .trigger = snd_vt1724_pcm_trigger,
1000 .pointer = snd_vt1724_pcm_pointer,
1004 static int __devinit snd_vt1724_pcm_spdif(ice1712_t * ice, int device)
1011 if (ice->force_pdma4 ||
1012 (ice->eeprom.data[ICE_EEP2_SPDIF] & VT1724_CFG_SPDIF_OUT_INT)) {
1017 if (ice->force_rdma1 ||
1018 (ice->eeprom.data[ICE_EEP2_SPDIF] & VT1724_CFG_SPDIF_IN)) {
1023 if (! play && ! capt)
1024 return 0; /* no spdif device */
1026 if (ice->force_pdma4 || ice->force_rdma1)
1027 name = "ICE1724 Secondary";
1029 name = "IEC1724 IEC958";
1030 err = snd_pcm_new(ice->card, name, device, play, capt, &pcm);
1035 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
1036 &snd_vt1724_playback_spdif_ops);
1038 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
1039 &snd_vt1724_capture_spdif_ops);
1041 pcm->private_data = ice;
1042 pcm->info_flags = 0;
1043 strcpy(pcm->name, name);
1045 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
1046 snd_dma_pci_data(ice->pci), 64*1024, 64*1024);
1055 * independent surround PCMs
1058 static struct vt1724_pcm_reg vt1724_playback_dma_regs[3] = {
1060 .addr = VT1724_MT_PDMA1_ADDR,
1061 .size = VT1724_MT_PDMA1_SIZE,
1062 .count = VT1724_MT_PDMA1_COUNT,
1063 .start = VT1724_PDMA1_START,
1066 .addr = VT1724_MT_PDMA2_ADDR,
1067 .size = VT1724_MT_PDMA2_SIZE,
1068 .count = VT1724_MT_PDMA2_COUNT,
1069 .start = VT1724_PDMA2_START,
1072 .addr = VT1724_MT_PDMA3_ADDR,
1073 .size = VT1724_MT_PDMA3_SIZE,
1074 .count = VT1724_MT_PDMA3_COUNT,
1075 .start = VT1724_PDMA3_START,
1079 static int snd_vt1724_playback_indep_prepare(snd_pcm_substream_t * substream)
1081 ice1712_t *ice = snd_pcm_substream_chip(substream);
1084 spin_lock_irq(&ice->reg_lock);
1085 val = 3 - substream->number;
1086 if (inb(ICEMT1724(ice, BURST)) < val)
1087 outb(val, ICEMT1724(ice, BURST));
1088 spin_unlock_irq(&ice->reg_lock);
1089 return snd_vt1724_pcm_prepare(substream);
1092 static int snd_vt1724_playback_indep_open(snd_pcm_substream_t *substream)
1094 ice1712_t *ice = snd_pcm_substream_chip(substream);
1095 snd_pcm_runtime_t *runtime = substream->runtime;
1097 down(&ice->open_mutex);
1098 /* already used by PDMA0? */
1099 if (ice->pcm_reserved[substream->number]) {
1100 up(&ice->open_mutex);
1101 return -EBUSY; /* FIXME: should handle blocking mode properly */
1103 up(&ice->open_mutex);
1104 runtime->private_data = &vt1724_playback_dma_regs[substream->number];
1105 ice->playback_con_substream_ds[substream->number] = substream;
1106 runtime->hw = snd_vt1724_2ch_stereo;
1107 snd_pcm_set_sync(substream);
1108 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
1109 set_rate_constraints(ice, substream);
1113 static int snd_vt1724_playback_indep_close(snd_pcm_substream_t * substream)
1115 ice1712_t *ice = snd_pcm_substream_chip(substream);
1118 snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
1119 ice->playback_con_substream_ds[substream->number] = NULL;
1120 ice->pcm_reserved[substream->number] = NULL;
1125 static snd_pcm_ops_t snd_vt1724_playback_indep_ops = {
1126 .open = snd_vt1724_playback_indep_open,
1127 .close = snd_vt1724_playback_indep_close,
1128 .ioctl = snd_pcm_lib_ioctl,
1129 .hw_params = snd_vt1724_pcm_hw_params,
1130 .hw_free = snd_vt1724_pcm_hw_free,
1131 .prepare = snd_vt1724_playback_indep_prepare,
1132 .trigger = snd_vt1724_pcm_trigger,
1133 .pointer = snd_vt1724_pcm_pointer,
1137 static int __devinit snd_vt1724_pcm_indep(ice1712_t * ice, int device)
1143 play = ice->num_total_dacs / 2 - 1;
1147 err = snd_pcm_new(ice->card, "ICE1724 Surrounds", device, play, 0, &pcm);
1151 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
1152 &snd_vt1724_playback_indep_ops);
1154 pcm->private_data = ice;
1155 pcm->info_flags = 0;
1156 strcpy(pcm->name, "ICE1724 Surround PCM");
1158 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
1159 snd_dma_pci_data(ice->pci), 64*1024, 64*1024);
1171 static int __devinit snd_vt1724_ac97_mixer(ice1712_t * ice)
1175 if (! (ice->eeprom.data[ICE_EEP2_ACLINK] & VT1724_CFG_PRO_I2S)) {
1177 ac97_template_t ac97;
1178 static ac97_bus_ops_t ops = {
1179 .write = snd_vt1724_ac97_write,
1180 .read = snd_vt1724_ac97_read,
1184 outb(inb(ICEMT1724(ice, AC97_CMD)) | 0x80, ICEMT1724(ice, AC97_CMD));
1185 mdelay(5); /* FIXME */
1186 outb(inb(ICEMT1724(ice, AC97_CMD)) & ~0x80, ICEMT1724(ice, AC97_CMD));
1188 if ((err = snd_ac97_bus(ice->card, 0, &ops, NULL, &pbus)) < 0)
1190 memset(&ac97, 0, sizeof(ac97));
1191 ac97.private_data = ice;
1192 if ((err = snd_ac97_mixer(pbus, &ac97, &ice->ac97)) < 0)
1193 printk(KERN_WARNING "ice1712: cannot initialize pro ac97, skipped\n");
1197 /* I2S mixer only */
1198 strcat(ice->card->mixername, "ICE1724 - multitrack");
1206 static inline unsigned int eeprom_triple(ice1712_t *ice, int idx)
1208 return (unsigned int)ice->eeprom.data[idx] | \
1209 ((unsigned int)ice->eeprom.data[idx + 1] << 8) | \
1210 ((unsigned int)ice->eeprom.data[idx + 2] << 16);
1213 static void snd_vt1724_proc_read(snd_info_entry_t *entry,
1214 snd_info_buffer_t * buffer)
1216 ice1712_t *ice = entry->private_data;
1219 snd_iprintf(buffer, "%s\n\n", ice->card->longname);
1220 snd_iprintf(buffer, "EEPROM:\n");
1222 snd_iprintf(buffer, " Subvendor : 0x%x\n", ice->eeprom.subvendor);
1223 snd_iprintf(buffer, " Size : %i bytes\n", ice->eeprom.size);
1224 snd_iprintf(buffer, " Version : %i\n", ice->eeprom.version);
1225 snd_iprintf(buffer, " System Config : 0x%x\n", ice->eeprom.data[ICE_EEP2_SYSCONF]);
1226 snd_iprintf(buffer, " ACLink : 0x%x\n", ice->eeprom.data[ICE_EEP2_ACLINK]);
1227 snd_iprintf(buffer, " I2S : 0x%x\n", ice->eeprom.data[ICE_EEP2_I2S]);
1228 snd_iprintf(buffer, " S/PDIF : 0x%x\n", ice->eeprom.data[ICE_EEP2_SPDIF]);
1229 snd_iprintf(buffer, " GPIO direction : 0x%x\n", ice->eeprom.gpiodir);
1230 snd_iprintf(buffer, " GPIO mask : 0x%x\n", ice->eeprom.gpiomask);
1231 snd_iprintf(buffer, " GPIO state : 0x%x\n", ice->eeprom.gpiostate);
1232 for (idx = 0x12; idx < ice->eeprom.size; idx++)
1233 snd_iprintf(buffer, " Extra #%02i : 0x%x\n", idx, ice->eeprom.data[idx]);
1235 snd_iprintf(buffer, "\nRegisters:\n");
1237 snd_iprintf(buffer, " PSDOUT03 : 0x%08x\n", (unsigned)inl(ICEMT1724(ice, ROUTE_PLAYBACK)));
1238 for (idx = 0x0; idx < 0x20 ; idx++)
1239 snd_iprintf(buffer, " CCS%02x : 0x%02x\n", idx, inb(ice->port+idx));
1240 for (idx = 0x0; idx < 0x30 ; idx++)
1241 snd_iprintf(buffer, " MT%02x : 0x%02x\n", idx, inb(ice->profi_port+idx));
1244 static void __devinit snd_vt1724_proc_init(ice1712_t * ice)
1246 snd_info_entry_t *entry;
1248 if (! snd_card_proc_new(ice->card, "ice1724", &entry))
1249 snd_info_set_text_ops(entry, ice, 1024, snd_vt1724_proc_read);
1256 static int snd_vt1724_eeprom_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1258 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
1259 uinfo->count = sizeof(ice1712_eeprom_t);
1263 static int snd_vt1724_eeprom_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1265 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1267 memcpy(ucontrol->value.bytes.data, &ice->eeprom, sizeof(ice->eeprom));
1271 static snd_kcontrol_new_t snd_vt1724_eeprom __devinitdata = {
1272 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1273 .name = "ICE1724 EEPROM",
1274 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1275 .info = snd_vt1724_eeprom_info,
1276 .get = snd_vt1724_eeprom_get
1281 static int snd_vt1724_spdif_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1283 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1288 static unsigned int encode_spdif_bits(snd_aes_iec958_t *diga)
1292 val = diga->status[0] & 0x03; /* professional, non-audio */
1295 if ((diga->status[0] & IEC958_AES0_PRO_EMPHASIS) == IEC958_AES0_PRO_EMPHASIS_5015)
1297 switch (diga->status[0] & IEC958_AES0_PRO_FS) {
1298 case IEC958_AES0_PRO_FS_44100:
1300 case IEC958_AES0_PRO_FS_32000:
1309 val |= diga->status[1] & 0x04; /* copyright */
1310 if ((diga->status[0] & IEC958_AES0_CON_EMPHASIS)== IEC958_AES0_CON_EMPHASIS_5015)
1312 val |= (unsigned int)(diga->status[1] & 0x3f) << 4; /* category */
1313 val |= (unsigned int)(diga->status[3] & IEC958_AES3_CON_FS) << 12; /* fs */
1318 static void decode_spdif_bits(snd_aes_iec958_t *diga, unsigned int val)
1320 memset(diga->status, 0, sizeof(diga->status));
1321 diga->status[0] = val & 0x03; /* professional, non-audio */
1324 if (val & (1U << 3))
1325 diga->status[0] |= IEC958_AES0_PRO_EMPHASIS_5015;
1326 switch ((val >> 12) & 0x7) {
1330 diga->status[0] |= IEC958_AES0_PRO_FS_32000;
1333 diga->status[0] |= IEC958_AES0_PRO_FS_48000;
1338 diga->status[0] |= val & (1U << 2); /* copyright */
1339 if (val & (1U << 3))
1340 diga->status[0] |= IEC958_AES0_CON_EMPHASIS_5015;
1341 diga->status[1] |= (val >> 4) & 0x3f; /* category */
1342 diga->status[3] |= (val >> 12) & 0x07; /* fs */
1346 static int snd_vt1724_spdif_default_get(snd_kcontrol_t * kcontrol,
1347 snd_ctl_elem_value_t * ucontrol)
1349 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1351 val = inw(ICEMT1724(ice, SPDIF_CTRL));
1352 decode_spdif_bits(&ucontrol->value.iec958, val);
1356 static int snd_vt1724_spdif_default_put(snd_kcontrol_t * kcontrol,
1357 snd_ctl_elem_value_t * ucontrol)
1359 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1360 unsigned int val, old;
1362 val = encode_spdif_bits(&ucontrol->value.iec958);
1363 spin_lock_irq(&ice->reg_lock);
1364 old = inw(ICEMT1724(ice, SPDIF_CTRL));
1366 update_spdif_bits(ice, val);
1367 spin_unlock_irq(&ice->reg_lock);
1368 return (val != old);
1371 static snd_kcontrol_new_t snd_vt1724_spdif_default __devinitdata =
1373 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1374 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
1375 .info = snd_vt1724_spdif_info,
1376 .get = snd_vt1724_spdif_default_get,
1377 .put = snd_vt1724_spdif_default_put
1380 static int snd_vt1724_spdif_maskc_get(snd_kcontrol_t * kcontrol,
1381 snd_ctl_elem_value_t * ucontrol)
1383 ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO |
1384 IEC958_AES0_PROFESSIONAL |
1385 IEC958_AES0_CON_NOT_COPYRIGHT |
1386 IEC958_AES0_CON_EMPHASIS;
1387 ucontrol->value.iec958.status[1] = IEC958_AES1_CON_ORIGINAL |
1388 IEC958_AES1_CON_CATEGORY;
1389 ucontrol->value.iec958.status[3] = IEC958_AES3_CON_FS;
1393 static int snd_vt1724_spdif_maskp_get(snd_kcontrol_t * kcontrol,
1394 snd_ctl_elem_value_t * ucontrol)
1396 ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO |
1397 IEC958_AES0_PROFESSIONAL |
1398 IEC958_AES0_PRO_FS |
1399 IEC958_AES0_PRO_EMPHASIS;
1403 static snd_kcontrol_new_t snd_vt1724_spdif_maskc __devinitdata =
1405 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1406 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1407 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,CON_MASK),
1408 .info = snd_vt1724_spdif_info,
1409 .get = snd_vt1724_spdif_maskc_get,
1412 static snd_kcontrol_new_t snd_vt1724_spdif_maskp __devinitdata =
1414 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1415 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1416 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PRO_MASK),
1417 .info = snd_vt1724_spdif_info,
1418 .get = snd_vt1724_spdif_maskp_get,
1421 static int snd_vt1724_spdif_sw_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1423 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1425 uinfo->value.integer.min = 0;
1426 uinfo->value.integer.max = 1;
1430 static int snd_vt1724_spdif_sw_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1432 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1433 ucontrol->value.integer.value[0] = inb(ICEREG1724(ice, SPDIF_CFG)) & VT1724_CFG_SPDIF_OUT_EN ? 1 : 0;
1437 static int snd_vt1724_spdif_sw_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1439 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1440 unsigned char old, val;
1442 spin_lock_irq(&ice->reg_lock);
1443 old = val = inb(ICEREG1724(ice, SPDIF_CFG));
1444 val &= ~VT1724_CFG_SPDIF_OUT_EN;
1445 if (ucontrol->value.integer.value[0])
1446 val |= VT1724_CFG_SPDIF_OUT_EN;
1448 outb(val, ICEREG1724(ice, SPDIF_CFG));
1449 spin_unlock_irq(&ice->reg_lock);
1453 static snd_kcontrol_new_t snd_vt1724_spdif_switch __devinitdata =
1455 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1456 /* FIXME: the following conflict with IEC958 Playback Route */
1457 // .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH),
1458 .name = "IEC958 Output Switch",
1459 .info = snd_vt1724_spdif_sw_info,
1460 .get = snd_vt1724_spdif_sw_get,
1461 .put = snd_vt1724_spdif_sw_put
1465 #if 0 /* NOT USED YET */
1467 * GPIO access from extern
1470 int snd_vt1724_gpio_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1472 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1474 uinfo->value.integer.min = 0;
1475 uinfo->value.integer.max = 1;
1479 int snd_vt1724_gpio_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1481 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1482 int shift = kcontrol->private_value & 0xff;
1483 int invert = (kcontrol->private_value & (1<<24)) ? 1 : 0;
1485 snd_ice1712_save_gpio_status(ice);
1486 ucontrol->value.integer.value[0] = (snd_ice1712_gpio_read(ice) & (1 << shift) ? 1 : 0) ^ invert;
1487 snd_ice1712_restore_gpio_status(ice);
1491 int snd_ice1712_gpio_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1493 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1494 int shift = kcontrol->private_value & 0xff;
1495 int invert = (kcontrol->private_value & (1<<24)) ? mask : 0;
1496 unsigned int val, nval;
1498 if (kcontrol->private_value & (1 << 31))
1500 nval = (ucontrol->value.integer.value[0] ? (1 << shift) : 0) ^ invert;
1501 snd_ice1712_save_gpio_status(ice);
1502 val = snd_ice1712_gpio_read(ice);
1503 nval |= val & ~(1 << shift);
1505 snd_ice1712_gpio_write(ice, nval);
1506 snd_ice1712_restore_gpio_status(ice);
1509 #endif /* NOT USED YET */
1514 static int snd_vt1724_pro_internal_clock_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1516 static char *texts_1724[] = {
1519 "11025", /* 2: 10 */
1527 "64000", /* 10: 15 */
1528 "88200", /* 11: 11 */
1529 "96000", /* 12: 7 */
1530 "176400", /* 13: 12 */
1531 "192000", /* 14: 14 */
1532 "IEC958 Input", /* 15: -- */
1534 static char *texts_1720[] = {
1537 "11025", /* 2: 10 */
1545 "64000", /* 10: 15 */
1546 "88200", /* 11: 11 */
1547 "96000", /* 12: 7 */
1548 "IEC958 Input", /* 13: -- */
1550 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1552 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1554 uinfo->value.enumerated.items = ice->vt1720 ? 14 : 16;
1555 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1556 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1557 strcpy(uinfo->value.enumerated.name,
1558 ice->vt1720 ? texts_1720[uinfo->value.enumerated.item] :
1559 texts_1724[uinfo->value.enumerated.item]);
1563 static int snd_vt1724_pro_internal_clock_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1565 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1566 static unsigned char xlate[16] = {
1567 9, 6, 3, 1, 7, 4, 0, 12, 8, 5, 2, 11, 13, 255, 14, 10
1571 spin_lock_irq(&ice->reg_lock);
1572 if (is_spdif_master(ice)) {
1573 ucontrol->value.enumerated.item[0] = ice->vt1720 ? 13 : 15;
1575 val = xlate[inb(ICEMT1724(ice, RATE)) & 15];
1580 ucontrol->value.enumerated.item[0] = val;
1582 spin_unlock_irq(&ice->reg_lock);
1586 static int snd_vt1724_pro_internal_clock_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1588 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1592 int spdif = ice->vt1720 ? 13 : 15;
1594 spin_lock_irq(&ice->reg_lock);
1595 oval = inb(ICEMT1724(ice, RATE));
1596 if (ucontrol->value.enumerated.item[0] == spdif) {
1597 outb(oval | VT1724_SPDIF_MASTER, ICEMT1724(ice, RATE));
1599 rate = rates[ucontrol->value.integer.value[0] % 15];
1600 if (rate <= get_max_rate(ice)) {
1601 PRO_RATE_DEFAULT = rate;
1602 spin_unlock_irq(&ice->reg_lock);
1603 snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 1);
1604 spin_lock_irq(&ice->reg_lock);
1607 change = inb(ICEMT1724(ice, RATE)) != oval;
1608 spin_unlock_irq(&ice->reg_lock);
1610 if ((oval & VT1724_SPDIF_MASTER) != (inb(ICEMT1724(ice, RATE)) & VT1724_SPDIF_MASTER)) {
1611 /* notify akm chips as well */
1612 if (is_spdif_master(ice)) {
1614 for (i = 0; i < ice->akm_codecs; i++) {
1615 if (ice->akm[i].ops.set_rate_val)
1616 ice->akm[i].ops.set_rate_val(&ice->akm[i], 0);
1623 static snd_kcontrol_new_t snd_vt1724_pro_internal_clock __devinitdata = {
1624 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1625 .name = "Multi Track Internal Clock",
1626 .info = snd_vt1724_pro_internal_clock_info,
1627 .get = snd_vt1724_pro_internal_clock_get,
1628 .put = snd_vt1724_pro_internal_clock_put
1631 static int snd_vt1724_pro_rate_locking_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1633 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1635 uinfo->value.integer.min = 0;
1636 uinfo->value.integer.max = 1;
1640 static int snd_vt1724_pro_rate_locking_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1642 ucontrol->value.integer.value[0] = PRO_RATE_LOCKED;
1646 static int snd_vt1724_pro_rate_locking_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1648 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1649 int change = 0, nval;
1651 nval = ucontrol->value.integer.value[0] ? 1 : 0;
1652 spin_lock_irq(&ice->reg_lock);
1653 change = PRO_RATE_LOCKED != nval;
1654 PRO_RATE_LOCKED = nval;
1655 spin_unlock_irq(&ice->reg_lock);
1659 static snd_kcontrol_new_t snd_vt1724_pro_rate_locking __devinitdata = {
1660 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1661 .name = "Multi Track Rate Locking",
1662 .info = snd_vt1724_pro_rate_locking_info,
1663 .get = snd_vt1724_pro_rate_locking_get,
1664 .put = snd_vt1724_pro_rate_locking_put
1667 static int snd_vt1724_pro_rate_reset_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1669 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1671 uinfo->value.integer.min = 0;
1672 uinfo->value.integer.max = 1;
1676 static int snd_vt1724_pro_rate_reset_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1678 ucontrol->value.integer.value[0] = PRO_RATE_RESET ? 1 : 0;
1682 static int snd_vt1724_pro_rate_reset_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1684 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1685 int change = 0, nval;
1687 nval = ucontrol->value.integer.value[0] ? 1 : 0;
1688 spin_lock_irq(&ice->reg_lock);
1689 change = PRO_RATE_RESET != nval;
1690 PRO_RATE_RESET = nval;
1691 spin_unlock_irq(&ice->reg_lock);
1695 static snd_kcontrol_new_t snd_vt1724_pro_rate_reset __devinitdata = {
1696 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1697 .name = "Multi Track Rate Reset",
1698 .info = snd_vt1724_pro_rate_reset_info,
1699 .get = snd_vt1724_pro_rate_reset_get,
1700 .put = snd_vt1724_pro_rate_reset_put
1707 static int snd_vt1724_pro_route_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1709 static char *texts[] = {
1711 "H/W In 0", "H/W In 1", /* 1-2 */
1712 "IEC958 In L", "IEC958 In R", /* 3-4 */
1715 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1717 uinfo->value.enumerated.items = 5;
1718 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1719 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1720 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1724 static inline int analog_route_shift(int idx)
1726 return (idx % 2) * 12 + ((idx / 2) * 3) + 8;
1729 static inline int digital_route_shift(int idx)
1734 static int get_route_val(ice1712_t *ice, int shift)
1737 unsigned char eitem;
1738 static unsigned char xlate[8] = {
1739 0, 255, 1, 2, 255, 255, 3, 4,
1742 val = inl(ICEMT1724(ice, ROUTE_PLAYBACK));
1744 val &= 7; //we now have 3 bits per output
1753 static int put_route_val(ice1712_t *ice, unsigned int val, int shift)
1755 unsigned int old_val, nval;
1757 static unsigned char xroute[8] = {
1759 2, /* PSDIN0 Left */
1760 3, /* PSDIN0 Right */
1762 7, /* SPDIN Right */
1765 nval = xroute[val % 5];
1766 val = old_val = inl(ICEMT1724(ice, ROUTE_PLAYBACK));
1767 val &= ~(0x07 << shift);
1768 val |= nval << shift;
1769 change = val != old_val;
1771 outl(val, ICEMT1724(ice, ROUTE_PLAYBACK));
1775 static int snd_vt1724_pro_route_analog_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)
1777 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1778 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1779 ucontrol->value.enumerated.item[0] = get_route_val(ice, analog_route_shift(idx));
1783 static int snd_vt1724_pro_route_analog_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)
1785 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1786 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1787 return put_route_val(ice, ucontrol->value.enumerated.item[0],
1788 analog_route_shift(idx));
1791 static int snd_vt1724_pro_route_spdif_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)
1793 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1794 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1795 ucontrol->value.enumerated.item[0] = get_route_val(ice, digital_route_shift(idx));
1799 static int snd_vt1724_pro_route_spdif_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)
1801 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1802 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1803 return put_route_val(ice, ucontrol->value.enumerated.item[0],
1804 digital_route_shift(idx));
1807 static snd_kcontrol_new_t snd_vt1724_mixer_pro_analog_route __devinitdata = {
1808 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1809 .name = "H/W Playback Route",
1810 .info = snd_vt1724_pro_route_info,
1811 .get = snd_vt1724_pro_route_analog_get,
1812 .put = snd_vt1724_pro_route_analog_put,
1815 static snd_kcontrol_new_t snd_vt1724_mixer_pro_spdif_route __devinitdata = {
1816 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1817 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Route",
1818 .info = snd_vt1724_pro_route_info,
1819 .get = snd_vt1724_pro_route_spdif_get,
1820 .put = snd_vt1724_pro_route_spdif_put,
1825 static int snd_vt1724_pro_peak_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1827 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1828 uinfo->count = 22; /* FIXME: for compatibility with ice1712... */
1829 uinfo->value.integer.min = 0;
1830 uinfo->value.integer.max = 255;
1834 static int snd_vt1724_pro_peak_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1836 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1839 spin_lock_irq(&ice->reg_lock);
1840 for (idx = 0; idx < 22; idx++) {
1841 outb(idx, ICEMT1724(ice, MONITOR_PEAKINDEX));
1842 ucontrol->value.integer.value[idx] = inb(ICEMT1724(ice, MONITOR_PEAKDATA));
1844 spin_unlock_irq(&ice->reg_lock);
1848 static snd_kcontrol_new_t snd_vt1724_mixer_pro_peak __devinitdata = {
1849 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1850 .name = "Multi Track Peak",
1851 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
1852 .info = snd_vt1724_pro_peak_info,
1853 .get = snd_vt1724_pro_peak_get
1860 static struct snd_ice1712_card_info no_matched __devinitdata;
1862 static struct snd_ice1712_card_info *card_tables[] __devinitdata = {
1863 snd_vt1724_revo_cards,
1864 snd_vt1724_amp_cards,
1865 snd_vt1724_aureon_cards,
1866 snd_vt1720_mobo_cards,
1867 snd_vt1720_pontis_cards,
1868 snd_vt1724_prodigy192_cards,
1876 static void wait_i2c_busy(ice1712_t *ice)
1879 while ((inb(ICEREG1724(ice, I2C_CTRL)) & VT1724_I2C_BUSY) && t--)
1883 unsigned char snd_vt1724_read_i2c(ice1712_t *ice, unsigned char dev, unsigned char addr)
1885 outb(addr, ICEREG1724(ice, I2C_BYTE_ADDR));
1886 outb(dev & ~VT1724_I2C_WRITE, ICEREG1724(ice, I2C_DEV_ADDR));
1888 return inb(ICEREG1724(ice, I2C_DATA));
1891 void snd_vt1724_write_i2c(ice1712_t *ice, unsigned char dev, unsigned char addr, unsigned char data)
1894 outb(addr, ICEREG1724(ice, I2C_BYTE_ADDR));
1895 outb(data, ICEREG1724(ice, I2C_DATA));
1896 outb(dev | VT1724_I2C_WRITE, ICEREG1724(ice, I2C_DEV_ADDR));
1900 static int __devinit snd_vt1724_read_eeprom(ice1712_t *ice, const char *modelname)
1902 const int dev = 0xa0; /* EEPROM device address */
1903 unsigned int i, size;
1904 struct snd_ice1712_card_info **tbl, *c;
1906 if (! modelname || ! *modelname) {
1907 ice->eeprom.subvendor = 0;
1908 if ((inb(ICEREG1724(ice, I2C_CTRL)) & VT1724_I2C_EEPROM) != 0)
1909 ice->eeprom.subvendor = (snd_vt1724_read_i2c(ice, dev, 0x00) << 0) |
1910 (snd_vt1724_read_i2c(ice, dev, 0x01) << 8) |
1911 (snd_vt1724_read_i2c(ice, dev, 0x02) << 16) |
1912 (snd_vt1724_read_i2c(ice, dev, 0x03) << 24);
1913 if (ice->eeprom.subvendor == 0 || ice->eeprom.subvendor == (unsigned int)-1) {
1914 /* invalid subvendor from EEPROM, try the PCI subststem ID instead */
1916 pci_read_config_word(ice->pci, PCI_SUBSYSTEM_VENDOR_ID, &vendor);
1917 pci_read_config_word(ice->pci, PCI_SUBSYSTEM_ID, &device);
1918 ice->eeprom.subvendor = ((unsigned int)swab16(vendor) << 16) | swab16(device);
1919 if (ice->eeprom.subvendor == 0 || ice->eeprom.subvendor == (unsigned int)-1) {
1920 printk(KERN_ERR "ice1724: No valid ID is found\n");
1925 for (tbl = card_tables; *tbl; tbl++) {
1926 for (c = *tbl; c->subvendor; c++) {
1927 if (modelname && c->model && ! strcmp(modelname, c->model)) {
1928 printk(KERN_INFO "ice1724: Using board model %s\n", c->name);
1929 ice->eeprom.subvendor = c->subvendor;
1930 } else if (c->subvendor != ice->eeprom.subvendor)
1932 if (! c->eeprom_size || ! c->eeprom_data)
1934 /* if the EEPROM is given by the driver, use it */
1935 snd_printdd("using the defined eeprom..\n");
1936 ice->eeprom.version = 2;
1937 ice->eeprom.size = c->eeprom_size + 6;
1938 memcpy(ice->eeprom.data, c->eeprom_data, c->eeprom_size);
1942 printk(KERN_WARNING "ice1724: No matching model found for ID 0x%x\n", ice->eeprom.subvendor);
1945 ice->eeprom.size = snd_vt1724_read_i2c(ice, dev, 0x04);
1946 if (ice->eeprom.size < 6)
1947 ice->eeprom.size = 32;
1948 else if (ice->eeprom.size > 32) {
1949 printk(KERN_ERR "ice1724: Invalid EEPROM (size = %i)\n", ice->eeprom.size);
1952 ice->eeprom.version = snd_vt1724_read_i2c(ice, dev, 0x05);
1953 if (ice->eeprom.version != 2)
1954 printk(KERN_WARNING "ice1724: Invalid EEPROM version %i\n", ice->eeprom.version);
1955 size = ice->eeprom.size - 6;
1956 for (i = 0; i < size; i++)
1957 ice->eeprom.data[i] = snd_vt1724_read_i2c(ice, dev, i + 6);
1960 ice->eeprom.gpiomask = eeprom_triple(ice, ICE_EEP2_GPIO_MASK);
1961 ice->eeprom.gpiostate = eeprom_triple(ice, ICE_EEP2_GPIO_STATE);
1962 ice->eeprom.gpiodir = eeprom_triple(ice, ICE_EEP2_GPIO_DIR);
1969 static int __devinit snd_vt1724_chip_init(ice1712_t *ice)
1971 outb(VT1724_RESET , ICEREG1724(ice, CONTROL));
1973 outb(0, ICEREG1724(ice, CONTROL));
1975 outb(ice->eeprom.data[ICE_EEP2_SYSCONF], ICEREG1724(ice, SYS_CFG));
1976 outb(ice->eeprom.data[ICE_EEP2_ACLINK], ICEREG1724(ice, AC97_CFG));
1977 outb(ice->eeprom.data[ICE_EEP2_I2S], ICEREG1724(ice, I2S_FEATURES));
1978 outb(ice->eeprom.data[ICE_EEP2_SPDIF], ICEREG1724(ice, SPDIF_CFG));
1980 ice->gpio.write_mask = ice->eeprom.gpiomask;
1981 ice->gpio.direction = ice->eeprom.gpiodir;
1982 snd_vt1724_set_gpio_mask(ice, ice->eeprom.gpiomask);
1983 snd_vt1724_set_gpio_dir(ice, ice->eeprom.gpiodir);
1984 snd_vt1724_set_gpio_data(ice, ice->eeprom.gpiostate);
1986 outb(0, ICEREG1724(ice, POWERDOWN));
1991 static int __devinit snd_vt1724_spdif_build_controls(ice1712_t *ice)
1994 snd_kcontrol_t *kctl;
1996 snd_assert(ice->pcm != NULL, return -EIO);
1998 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_mixer_pro_spdif_route, ice));
2002 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_spdif_switch, ice));
2006 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_vt1724_spdif_default, ice));
2009 kctl->id.device = ice->pcm->device;
2010 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_vt1724_spdif_maskc, ice));
2013 kctl->id.device = ice->pcm->device;
2014 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_vt1724_spdif_maskp, ice));
2017 kctl->id.device = ice->pcm->device;
2018 #if 0 /* use default only */
2019 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_vt1724_spdif_stream, ice));
2022 kctl->id.device = ice->pcm->device;
2023 ice->spdif.stream_ctl = kctl;
2029 static int __devinit snd_vt1724_build_controls(ice1712_t *ice)
2033 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_eeprom, ice));
2036 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_pro_internal_clock, ice));
2040 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_pro_rate_locking, ice));
2043 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_pro_rate_reset, ice));
2047 if (ice->num_total_dacs > 0) {
2048 snd_kcontrol_new_t tmp = snd_vt1724_mixer_pro_analog_route;
2049 tmp.count = ice->num_total_dacs;
2050 if (ice->vt1720 && tmp.count > 2)
2052 err = snd_ctl_add(ice->card, snd_ctl_new1(&tmp, ice));
2057 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_mixer_pro_peak, ice));
2064 static int snd_vt1724_free(ice1712_t *ice)
2068 /* mask all interrupts */
2069 outb(0xff, ICEMT1724(ice, DMA_INT_MASK));
2070 outb(0xff, ICEREG1724(ice, IRQMASK));
2073 if (ice->irq >= 0) {
2074 synchronize_irq(ice->irq);
2075 free_irq(ice->irq, (void *) ice);
2077 pci_release_regions(ice->pci);
2078 snd_ice1712_akm4xxx_free(ice);
2079 pci_disable_device(ice->pci);
2084 static int snd_vt1724_dev_free(snd_device_t *device)
2086 ice1712_t *ice = device->device_data;
2087 return snd_vt1724_free(ice);
2090 static int __devinit snd_vt1724_create(snd_card_t * card,
2091 struct pci_dev *pci,
2092 const char *modelname,
2093 ice1712_t ** r_ice1712)
2098 static snd_device_ops_t ops = {
2099 .dev_free = snd_vt1724_dev_free,
2104 /* enable PCI device */
2105 if ((err = pci_enable_device(pci)) < 0)
2108 ice = kcalloc(1, sizeof(*ice), GFP_KERNEL);
2110 pci_disable_device(pci);
2114 spin_lock_init(&ice->reg_lock);
2115 init_MUTEX(&ice->gpio_mutex);
2116 init_MUTEX(&ice->open_mutex);
2117 ice->gpio.set_mask = snd_vt1724_set_gpio_mask;
2118 ice->gpio.set_dir = snd_vt1724_set_gpio_dir;
2119 ice->gpio.set_data = snd_vt1724_set_gpio_data;
2120 ice->gpio.get_data = snd_vt1724_get_gpio_data;
2124 pci_set_master(pci);
2125 snd_vt1724_proc_init(ice);
2126 synchronize_irq(pci->irq);
2128 if ((err = pci_request_regions(pci, "ICE1724")) < 0) {
2130 pci_disable_device(pci);
2133 ice->port = pci_resource_start(pci, 0);
2134 ice->profi_port = pci_resource_start(pci, 1);
2136 if (request_irq(pci->irq, snd_vt1724_interrupt, SA_INTERRUPT|SA_SHIRQ, "ICE1724", (void *) ice)) {
2137 snd_printk("unable to grab IRQ %d\n", pci->irq);
2138 snd_vt1724_free(ice);
2142 ice->irq = pci->irq;
2144 if (snd_vt1724_read_eeprom(ice, modelname) < 0) {
2145 snd_vt1724_free(ice);
2148 if (snd_vt1724_chip_init(ice) < 0) {
2149 snd_vt1724_free(ice);
2153 /* unmask used interrupts */
2154 if (! (ice->eeprom.data[ICE_EEP2_SYSCONF] & VT1724_CFG_MPU401))
2155 mask = VT1724_IRQ_MPU_RX | VT1724_IRQ_MPU_TX;
2158 outb(mask, ICEREG1724(ice, IRQMASK));
2159 /* don't handle FIFO overrun/underruns (just yet), since they cause machine lockups */
2160 outb(VT1724_MULTI_FIFO_ERR, ICEMT1724(ice, DMA_INT_MASK));
2162 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, ice, &ops)) < 0) {
2163 snd_vt1724_free(ice);
2167 snd_card_set_dev(card, &pci->dev);
2180 static int __devinit snd_vt1724_probe(struct pci_dev *pci,
2181 const struct pci_device_id *pci_id)
2186 int pcm_dev = 0, err;
2187 struct snd_ice1712_card_info **tbl, *c;
2189 if (dev >= SNDRV_CARDS)
2196 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
2200 strcpy(card->driver, "ICE1724");
2201 strcpy(card->shortname, "ICEnsemble ICE1724");
2203 if ((err = snd_vt1724_create(card, pci, model[dev], &ice)) < 0) {
2204 snd_card_free(card);
2208 for (tbl = card_tables; *tbl; tbl++) {
2209 for (c = *tbl; c->subvendor; c++) {
2210 if (c->subvendor == ice->eeprom.subvendor) {
2211 strcpy(card->shortname, c->name);
2212 if (c->driver) /* specific driver? */
2213 strcpy(card->driver, c->driver);
2215 if ((err = c->chip_init(ice)) < 0) {
2216 snd_card_free(card);
2227 if ((err = snd_vt1724_pcm_profi(ice, pcm_dev++)) < 0) {
2228 snd_card_free(card);
2232 if ((err = snd_vt1724_pcm_spdif(ice, pcm_dev++)) < 0) {
2233 snd_card_free(card);
2237 if ((err = snd_vt1724_pcm_indep(ice, pcm_dev++)) < 0) {
2238 snd_card_free(card);
2242 if ((err = snd_vt1724_ac97_mixer(ice)) < 0) {
2243 snd_card_free(card);
2247 if ((err = snd_vt1724_build_controls(ice)) < 0) {
2248 snd_card_free(card);
2252 if (ice->pcm && ice->has_spdif) { /* has SPDIF I/O */
2253 if ((err = snd_vt1724_spdif_build_controls(ice)) < 0) {
2254 snd_card_free(card);
2259 if (c->build_controls) {
2260 if ((err = c->build_controls(ice)) < 0) {
2261 snd_card_free(card);
2266 if (! c->no_mpu401) {
2267 if (ice->eeprom.data[ICE_EEP2_SYSCONF] & VT1724_CFG_MPU401) {
2268 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_ICE1712,
2269 ICEREG1724(ice, MPU_CTRL), 1,
2271 &ice->rmidi[0])) < 0) {
2272 snd_card_free(card);
2278 sprintf(card->longname, "%s at 0x%lx, irq %i",
2279 card->shortname, ice->port, ice->irq);
2281 if ((err = snd_card_register(card)) < 0) {
2282 snd_card_free(card);
2285 pci_set_drvdata(pci, card);
2290 static void __devexit snd_vt1724_remove(struct pci_dev *pci)
2292 snd_card_free(pci_get_drvdata(pci));
2293 pci_set_drvdata(pci, NULL);
2296 static struct pci_driver driver = {
2298 .id_table = snd_vt1724_ids,
2299 .probe = snd_vt1724_probe,
2300 .remove = __devexit_p(snd_vt1724_remove),
2303 static int __init alsa_card_ice1724_init(void)
2305 return pci_module_init(&driver);
2308 static void __exit alsa_card_ice1724_exit(void)
2310 pci_unregister_driver(&driver);
2313 module_init(alsa_card_ice1724_init)
2314 module_exit(alsa_card_ice1724_exit)