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"
51 MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
52 MODULE_DESCRIPTION("VIA ICEnsemble ICE1724/1720 (Envy24HT/PT)");
53 MODULE_LICENSE("GPL");
54 MODULE_SUPPORTED_DEVICE("{"
56 AMP_AUDIO2000_DEVICE_DESC
58 VT1720_MOBO_DEVICE_DESC
62 "{ICEnsemble,Generic ICE1724},"
63 "{ICEnsemble,Generic Envy24HT}"
64 "{ICEnsemble,Generic Envy24PT}}");
66 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
67 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
68 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */
69 static char *model[SNDRV_CARDS];
72 module_param_array(index, int, boot_devs, 0444);
73 MODULE_PARM_DESC(index, "Index value for ICE1724 soundcard.");
74 module_param_array(id, charp, boot_devs, 0444);
75 MODULE_PARM_DESC(id, "ID string for ICE1724 soundcard.");
76 module_param_array(enable, bool, boot_devs, 0444);
77 MODULE_PARM_DESC(enable, "Enable ICE1724 soundcard.");
78 module_param_array(model, charp, boot_devs, 0444);
79 MODULE_PARM_DESC(model, "Use the given board model.");
81 #ifndef PCI_VENDOR_ID_ICE
82 #define PCI_VENDOR_ID_ICE 0x1412
84 #ifndef PCI_DEVICE_ID_VT1724
85 #define PCI_DEVICE_ID_VT1724 0x1724
88 /* Both VT1720 and VT1724 have the same PCI IDs */
89 static struct pci_device_id snd_vt1724_ids[] = {
90 { PCI_VENDOR_ID_ICE, PCI_DEVICE_ID_VT1724, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
94 MODULE_DEVICE_TABLE(pci, snd_vt1724_ids);
97 static int PRO_RATE_LOCKED;
98 static int PRO_RATE_RESET = 1;
99 static unsigned int PRO_RATE_DEFAULT = 44100;
105 /* check whether the clock mode is spdif-in */
106 static inline int is_spdif_master(ice1712_t *ice)
108 return (inb(ICEMT1724(ice, RATE)) & VT1724_SPDIF_MASTER) ? 1 : 0;
111 static inline int is_pro_rate_locked(ice1712_t *ice)
113 return is_spdif_master(ice) || PRO_RATE_LOCKED;
120 static unsigned char snd_vt1724_ac97_ready(ice1712_t *ice)
122 unsigned char old_cmd;
124 for (tm = 0; tm < 0x10000; tm++) {
125 old_cmd = inb(ICEMT1724(ice, AC97_CMD));
126 if (old_cmd & (VT1724_AC97_WRITE | VT1724_AC97_READ))
128 if (!(old_cmd & VT1724_AC97_READY))
132 snd_printd(KERN_ERR "snd_vt1724_ac97_ready: timeout\n");
136 static int snd_vt1724_ac97_wait_bit(ice1712_t *ice, unsigned char bit)
139 for (tm = 0; tm < 0x10000; tm++)
140 if ((inb(ICEMT1724(ice, AC97_CMD)) & bit) == 0)
142 snd_printd(KERN_ERR "snd_vt1724_ac97_wait_bit: timeout\n");
146 static void snd_vt1724_ac97_write(ac97_t *ac97,
150 ice1712_t *ice = (ice1712_t *)ac97->private_data;
151 unsigned char old_cmd;
153 old_cmd = snd_vt1724_ac97_ready(ice);
154 old_cmd &= ~VT1724_AC97_ID_MASK;
155 old_cmd |= ac97->num;
156 outb(reg, ICEMT1724(ice, AC97_INDEX));
157 outw(val, ICEMT1724(ice, AC97_DATA));
158 outb(old_cmd | VT1724_AC97_WRITE, ICEMT1724(ice, AC97_CMD));
159 snd_vt1724_ac97_wait_bit(ice, VT1724_AC97_WRITE);
162 static unsigned short snd_vt1724_ac97_read(ac97_t *ac97, unsigned short reg)
164 ice1712_t *ice = (ice1712_t *)ac97->private_data;
165 unsigned char old_cmd;
167 old_cmd = snd_vt1724_ac97_ready(ice);
168 old_cmd &= ~VT1724_AC97_ID_MASK;
169 old_cmd |= ac97->num;
170 outb(reg, ICEMT1724(ice, AC97_INDEX));
171 outb(old_cmd | VT1724_AC97_READ, ICEMT1724(ice, AC97_CMD));
172 if (snd_vt1724_ac97_wait_bit(ice, VT1724_AC97_READ) < 0)
174 return inw(ICEMT1724(ice, AC97_DATA));
182 /* set gpio direction 0 = read, 1 = write */
183 static void snd_vt1724_set_gpio_dir(ice1712_t *ice, unsigned int data)
185 outl(data, ICEREG1724(ice, GPIO_DIRECTION));
186 inw(ICEREG1724(ice, GPIO_DIRECTION)); /* dummy read for pci-posting */
189 /* set the gpio mask (0 = writable) */
190 static void snd_vt1724_set_gpio_mask(ice1712_t *ice, unsigned int data)
192 outw(data, ICEREG1724(ice, GPIO_WRITE_MASK));
193 if (! ice->vt1720) /* VT1720 supports only 16 GPIO bits */
194 outb((data >> 16) & 0xff, ICEREG1724(ice, GPIO_WRITE_MASK_22));
195 inw(ICEREG1724(ice, GPIO_WRITE_MASK)); /* dummy read for pci-posting */
198 static void snd_vt1724_set_gpio_data(ice1712_t *ice, unsigned int data)
200 outw(data, ICEREG1724(ice, GPIO_DATA));
202 outb(data >> 16, ICEREG1724(ice, GPIO_DATA_22));
203 inw(ICEREG1724(ice, GPIO_DATA)); /* dummy read for pci-posting */
206 static unsigned int snd_vt1724_get_gpio_data(ice1712_t *ice)
210 data = (unsigned int)inb(ICEREG1724(ice, GPIO_DATA_22));
213 data = (data << 16) | inw(ICEREG1724(ice, GPIO_DATA));
221 static irqreturn_t snd_vt1724_interrupt(int irq, void *dev_id, struct pt_regs *regs)
223 ice1712_t *ice = dev_id;
224 unsigned char status;
228 status = inb(ICEREG1724(ice, IRQSTAT));
233 /* these should probably be separated at some point,
234 but as we don't currently have MPU support on the board I will leave it */
235 if ((status & VT1724_IRQ_MPU_RX)||(status & VT1724_IRQ_MPU_TX)) {
237 snd_mpu401_uart_interrupt(irq, ice->rmidi[0]->private_data, regs);
238 outb(status & (VT1724_IRQ_MPU_RX|VT1724_IRQ_MPU_TX), ICEREG1724(ice, IRQSTAT));
239 status &= ~(VT1724_IRQ_MPU_RX|VT1724_IRQ_MPU_TX);
241 if (status & VT1724_IRQ_MTPCM) {
244 * PCM assignment are:
245 * Playback DMA0 (M/C) = playback_pro_substream
246 * Playback DMA1 = playback_con_substream_ds[0]
247 * Playback DMA2 = playback_con_substream_ds[1]
248 * Playback DMA3 = playback_con_substream_ds[2]
249 * Playback DMA4 (SPDIF) = playback_con_substream
250 * Record DMA0 = capture_pro_substream
251 * Record DMA1 = capture_con_substream
253 unsigned char mtstat = inb(ICEMT1724(ice, IRQ));
254 if (mtstat & VT1724_MULTI_PDMA0) {
255 if (ice->playback_pro_substream)
256 snd_pcm_period_elapsed(ice->playback_pro_substream);
258 if (mtstat & VT1724_MULTI_RDMA0) {
259 if (ice->capture_pro_substream)
260 snd_pcm_period_elapsed(ice->capture_pro_substream);
262 if (mtstat & VT1724_MULTI_PDMA1) {
263 if (ice->playback_con_substream_ds[0])
264 snd_pcm_period_elapsed(ice->playback_con_substream_ds[0]);
266 if (mtstat & VT1724_MULTI_PDMA2) {
267 if (ice->playback_con_substream_ds[1])
268 snd_pcm_period_elapsed(ice->playback_con_substream_ds[1]);
270 if (mtstat & VT1724_MULTI_PDMA3) {
271 if (ice->playback_con_substream_ds[2])
272 snd_pcm_period_elapsed(ice->playback_con_substream_ds[2]);
274 if (mtstat & VT1724_MULTI_PDMA4) {
275 if (ice->playback_con_substream)
276 snd_pcm_period_elapsed(ice->playback_con_substream);
278 if (mtstat & VT1724_MULTI_RDMA1) {
279 if (ice->capture_con_substream)
280 snd_pcm_period_elapsed(ice->capture_con_substream);
282 /* ack anyway to avoid freeze */
283 outb(mtstat, ICEMT1724(ice, IRQ));
284 /* ought to really handle this properly */
285 if (mtstat & VT1724_MULTI_FIFO_ERR) {
286 unsigned char fstat = inb(ICEMT1724(ice, DMA_FIFO_ERR));
287 outb(fstat, ICEMT1724(ice, DMA_FIFO_ERR));
288 outb(VT1724_MULTI_FIFO_ERR | inb(ICEMT1724(ice, DMA_INT_MASK)), ICEMT1724(ice, DMA_INT_MASK));
289 /* If I don't do this, I get machine lockup due to continual interrupts */
294 return IRQ_RETVAL(handled);
298 * PCM code - professional part (multitrack)
301 static unsigned int rates[] = {
302 8000, 9600, 11025, 12000, 16000, 22050, 24000,
303 32000, 44100, 48000, 64000, 88200, 96000,
307 static snd_pcm_hw_constraint_list_t hw_constraints_rates_96 = {
308 .count = ARRAY_SIZE(rates) - 2, /* up to 96000 */
313 static snd_pcm_hw_constraint_list_t hw_constraints_rates_48 = {
314 .count = ARRAY_SIZE(rates) - 5, /* up to 48000 */
319 static snd_pcm_hw_constraint_list_t hw_constraints_rates_192 = {
320 .count = ARRAY_SIZE(rates),
325 struct vt1724_pcm_reg {
326 unsigned int addr; /* ADDR register offset */
327 unsigned int size; /* SIZE register offset */
328 unsigned int count; /* COUNT register offset */
329 unsigned int start; /* start & pause bit */
332 static int snd_vt1724_pcm_trigger(snd_pcm_substream_t *substream, int cmd)
334 ice1712_t *ice = snd_pcm_substream_chip(substream);
337 struct list_head *pos;
338 snd_pcm_substream_t *s;
341 snd_pcm_group_for_each(pos, substream) {
342 struct vt1724_pcm_reg *reg;
343 s = snd_pcm_group_substream_entry(pos);
344 reg = s->runtime->private_data;
346 snd_pcm_trigger_done(s, substream);
350 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
351 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
352 spin_lock(&ice->reg_lock);
353 old = inb(ICEMT1724(ice, DMA_PAUSE));
354 if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH)
358 outb(old, ICEMT1724(ice, DMA_PAUSE));
359 spin_unlock(&ice->reg_lock);
362 case SNDRV_PCM_TRIGGER_START:
363 case SNDRV_PCM_TRIGGER_STOP:
364 spin_lock(&ice->reg_lock);
365 old = inb(ICEMT1724(ice, DMA_CONTROL));
366 if (cmd == SNDRV_PCM_TRIGGER_START)
370 outb(old, ICEMT1724(ice, DMA_CONTROL));
371 spin_unlock(&ice->reg_lock);
383 #define DMA_STARTS (VT1724_RDMA0_START|VT1724_PDMA0_START|VT1724_RDMA1_START|\
384 VT1724_PDMA1_START|VT1724_PDMA2_START|VT1724_PDMA3_START|VT1724_PDMA4_START)
385 #define DMA_PAUSES (VT1724_RDMA0_PAUSE|VT1724_PDMA0_PAUSE|VT1724_RDMA1_PAUSE|\
386 VT1724_PDMA1_PAUSE|VT1724_PDMA2_PAUSE|VT1724_PDMA3_PAUSE|VT1724_PDMA4_PAUSE)
388 static int get_max_rate(ice1712_t *ice)
390 if (ice->eeprom.data[ICE_EEP2_ACLINK] & VT1724_CFG_PRO_I2S) {
391 if ((ice->eeprom.data[ICE_EEP2_I2S] & 0x08) && !ice->vt1720)
399 static void snd_vt1724_set_pro_rate(ice1712_t *ice, unsigned int rate, int force)
402 unsigned char val, old;
405 if (rate > get_max_rate(ice))
408 spin_lock_irqsave(&ice->reg_lock, flags);
409 if ((inb(ICEMT1724(ice, DMA_CONTROL)) & DMA_STARTS) ||
410 (inb(ICEMT1724(ice, DMA_PAUSE)) & DMA_PAUSES)) {
411 /* running? we cannot change the rate now... */
412 spin_unlock_irqrestore(&ice->reg_lock, flags);
415 if (!force && is_pro_rate_locked(ice)) {
416 spin_unlock_irqrestore(&ice->reg_lock, flags);
421 case 8000: val = 6; break;
422 case 9600: val = 3; break;
423 case 11025: val = 10; break;
424 case 12000: val = 2; break;
425 case 16000: val = 5; break;
426 case 22050: val = 9; break;
427 case 24000: val = 1; break;
428 case 32000: val = 4; break;
429 case 44100: val = 8; break;
430 case 48000: val = 0; break;
431 case 64000: val = 15; break;
432 case 88200: val = 11; break;
433 case 96000: val = 7; break;
434 case 176400: val = 12; break;
435 case 192000: val = 14; break;
441 old = inb(ICEMT1724(ice, RATE));
443 outb(val, ICEMT1724(ice, RATE));
444 else if (rate == ice->cur_rate) {
445 spin_unlock_irqrestore(&ice->reg_lock, flags);
449 ice->cur_rate = rate;
452 if (ice->eeprom.data[ICE_EEP2_ACLINK] & VT1724_CFG_PRO_I2S) {
453 val = old = inb(ICEMT1724(ice, I2S_FORMAT));
455 val |= VT1724_MT_I2S_MCLK_128X; /* 128x MCLK */
457 val &= ~VT1724_MT_I2S_MCLK_128X; /* 256x MCLK */
459 outb(val, ICEMT1724(ice, I2S_FORMAT));
460 if (ice->eeprom.subvendor == VT1724_SUBDEVICE_REVOLUTION71) {
461 /* FIXME: is this revo only? */
462 /* assert PRST# to converters; MT05 bit 7 */
463 outb(inb(ICEMT1724(ice, AC97_CMD)) | 0x80, ICEMT1724(ice, AC97_CMD));
464 spin_unlock_irqrestore(&ice->reg_lock, flags);
466 spin_lock_irqsave(&ice->reg_lock, flags);
468 outb(inb(ICEMT1724(ice, AC97_CMD)) & ~0x80, ICEMT1724(ice, AC97_CMD));
472 spin_unlock_irqrestore(&ice->reg_lock, flags);
475 for (i = 0; i < ice->akm_codecs; i++) {
476 if (ice->akm[i].ops.set_rate_val)
477 ice->akm[i].ops.set_rate_val(&ice->akm[i], rate);
481 static int snd_vt1724_pcm_hw_params(snd_pcm_substream_t * substream,
482 snd_pcm_hw_params_t * hw_params)
484 ice1712_t *ice = snd_pcm_substream_chip(substream);
487 chs = params_channels(hw_params);
488 down(&ice->open_mutex);
489 /* mark surround channels */
490 if (substream == ice->playback_pro_substream) {
491 /* PDMA0 can be multi-channel up to 8 */
493 for (i = 0; i < chs; i++) {
494 if (ice->pcm_reserved[i] && ice->pcm_reserved[i] != substream) {
495 up(&ice->open_mutex);
498 ice->pcm_reserved[i] = substream;
501 if (ice->pcm_reserved[i] == substream)
502 ice->pcm_reserved[i] = NULL;
505 for (i = 0; i < 3; i++) {
506 /* check individual playback stream */
507 if (ice->playback_con_substream_ds[i] == substream) {
508 if (ice->pcm_reserved[i] && ice->pcm_reserved[i] != substream) {
509 up(&ice->open_mutex);
512 ice->pcm_reserved[i] = substream;
517 up(&ice->open_mutex);
518 snd_vt1724_set_pro_rate(ice, params_rate(hw_params), 0);
519 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
522 static int snd_vt1724_pcm_hw_free(snd_pcm_substream_t * substream)
524 ice1712_t *ice = snd_pcm_substream_chip(substream);
527 down(&ice->open_mutex);
528 /* unmark surround channels */
529 for (i = 0; i < 3; i++)
530 if (ice->pcm_reserved[i] == substream)
531 ice->pcm_reserved[i] = NULL;
532 up(&ice->open_mutex);
533 return snd_pcm_lib_free_pages(substream);
536 static int snd_vt1724_playback_pro_prepare(snd_pcm_substream_t * substream)
538 ice1712_t *ice = snd_pcm_substream_chip(substream);
542 spin_lock_irq(&ice->reg_lock);
543 val = (8 - substream->runtime->channels) >> 1;
544 outb(val, ICEMT1724(ice, BURST));
546 outl(substream->runtime->dma_addr, ICEMT1724(ice, PLAYBACK_ADDR));
548 size = (snd_pcm_lib_buffer_bytes(substream) >> 2) - 1;
549 // outl(size, ICEMT1724(ice, PLAYBACK_SIZE));
550 outw(size, ICEMT1724(ice, PLAYBACK_SIZE));
551 outb(size >> 16, ICEMT1724(ice, PLAYBACK_SIZE) + 2);
552 size = (snd_pcm_lib_period_bytes(substream) >> 2) - 1;
553 // outl(size, ICEMT1724(ice, PLAYBACK_COUNT));
554 outw(size, ICEMT1724(ice, PLAYBACK_COUNT));
555 outb(size >> 16, ICEMT1724(ice, PLAYBACK_COUNT) + 2);
557 spin_unlock_irq(&ice->reg_lock);
559 // 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));
563 static snd_pcm_uframes_t snd_vt1724_playback_pro_pointer(snd_pcm_substream_t * substream)
565 ice1712_t *ice = snd_pcm_substream_chip(substream);
568 if (!(inl(ICEMT1724(ice, DMA_CONTROL)) & VT1724_PDMA0_START))
570 #if 0 /* read PLAYBACK_ADDR */
571 ptr = inl(ICEMT1724(ice, PLAYBACK_ADDR));
572 if (ptr < substream->runtime->dma_addr) {
573 snd_printd("ice1724: invalid negative ptr\n");
576 ptr -= substream->runtime->dma_addr;
577 ptr = bytes_to_frames(substream->runtime, ptr);
578 if (ptr >= substream->runtime->buffer_size) {
579 snd_printd("ice1724: invalid ptr %d (size=%d)\n", (int)ptr, (int)substream->runtime->period_size);
582 #else /* read PLAYBACK_SIZE */
583 ptr = inl(ICEMT1724(ice, PLAYBACK_SIZE)) & 0xffffff;
584 ptr = (ptr + 1) << 2;
585 ptr = bytes_to_frames(substream->runtime, ptr);
588 else if (ptr <= substream->runtime->buffer_size)
589 ptr = substream->runtime->buffer_size - ptr;
591 snd_printd("ice1724: invalid ptr %d (size=%d)\n", (int)ptr, (int)substream->runtime->buffer_size);
598 static int snd_vt1724_pcm_prepare(snd_pcm_substream_t *substream)
600 ice1712_t *ice = snd_pcm_substream_chip(substream);
601 struct vt1724_pcm_reg *reg = substream->runtime->private_data;
603 spin_lock_irq(&ice->reg_lock);
604 outl(substream->runtime->dma_addr, ice->profi_port + reg->addr);
605 outw((snd_pcm_lib_buffer_bytes(substream) >> 2) - 1, ice->profi_port + reg->size);
606 outw((snd_pcm_lib_period_bytes(substream) >> 2) - 1, ice->profi_port + reg->count);
607 spin_unlock_irq(&ice->reg_lock);
611 static snd_pcm_uframes_t snd_vt1724_pcm_pointer(snd_pcm_substream_t *substream)
613 ice1712_t *ice = snd_pcm_substream_chip(substream);
614 struct vt1724_pcm_reg *reg = substream->runtime->private_data;
617 if (!(inl(ICEMT1724(ice, DMA_CONTROL)) & reg->start))
619 #if 0 /* use ADDR register */
620 ptr = inl(ice->profi_port + reg->addr);
621 ptr -= substream->runtime->dma_addr;
622 return bytes_to_frames(substream->runtime, ptr);
623 #else /* use SIZE register */
624 ptr = inw(ice->profi_port + reg->size);
625 ptr = (ptr + 1) << 2;
626 ptr = bytes_to_frames(substream->runtime, ptr);
629 else if (ptr <= substream->runtime->buffer_size)
630 ptr = substream->runtime->buffer_size - ptr;
632 snd_printd("ice1724: invalid ptr %d (size=%d)\n", (int)ptr, (int)substream->runtime->buffer_size);
639 static struct vt1724_pcm_reg vt1724_playback_pro_reg = {
640 .addr = VT1724_MT_PLAYBACK_ADDR,
641 .size = VT1724_MT_PLAYBACK_SIZE,
642 .count = VT1724_MT_PLAYBACK_COUNT,
643 .start = VT1724_PDMA0_START,
646 static struct vt1724_pcm_reg vt1724_capture_pro_reg = {
647 .addr = VT1724_MT_CAPTURE_ADDR,
648 .size = VT1724_MT_CAPTURE_SIZE,
649 .count = VT1724_MT_CAPTURE_COUNT,
650 .start = VT1724_RDMA0_START,
653 static snd_pcm_hardware_t snd_vt1724_playback_pro =
655 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
656 SNDRV_PCM_INFO_BLOCK_TRANSFER |
657 SNDRV_PCM_INFO_MMAP_VALID |
658 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START),
659 .formats = SNDRV_PCM_FMTBIT_S32_LE,
660 .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_192000,
665 .buffer_bytes_max = (1UL << 21), /* 19bits dword */
666 .period_bytes_min = 8 * 4 * 2, /* FIXME: constraints needed */
667 .period_bytes_max = (1UL << 21),
672 static snd_pcm_hardware_t snd_vt1724_spdif =
674 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
675 SNDRV_PCM_INFO_BLOCK_TRANSFER |
676 SNDRV_PCM_INFO_MMAP_VALID |
677 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START),
678 .formats = SNDRV_PCM_FMTBIT_S32_LE,
679 .rates = SNDRV_PCM_RATE_32000|SNDRV_PCM_RATE_44100|SNDRV_PCM_RATE_48000,
684 .buffer_bytes_max = (1UL << 18), /* 16bits dword */
685 .period_bytes_min = 2 * 4 * 2,
686 .period_bytes_max = (1UL << 18),
691 static snd_pcm_hardware_t snd_vt1724_2ch_stereo =
693 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
694 SNDRV_PCM_INFO_BLOCK_TRANSFER |
695 SNDRV_PCM_INFO_MMAP_VALID |
696 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START),
697 .formats = SNDRV_PCM_FMTBIT_S32_LE,
698 .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_192000,
703 .buffer_bytes_max = (1UL << 18), /* 16bits dword */
704 .period_bytes_min = 2 * 4 * 2,
705 .period_bytes_max = (1UL << 18),
711 * set rate constraints
713 static int set_rate_constraints(ice1712_t *ice, snd_pcm_substream_t *substream)
715 snd_pcm_runtime_t *runtime = substream->runtime;
716 if (ice->eeprom.data[ICE_EEP2_ACLINK] & VT1724_CFG_PRO_I2S) {
718 /* VT1720 doesn't support more than 96kHz */
719 if ((ice->eeprom.data[ICE_EEP2_I2S] & 0x08) && !ice->vt1720)
720 return snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates_192);
722 runtime->hw.rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_96000;
723 runtime->hw.rate_max = 96000;
724 return snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates_96);
726 } else if (ice->ac97) {
728 runtime->hw.rate_max = 48000;
729 runtime->hw.rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000;
730 return snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates_48);
735 /* multi-channel playback needs alignment 8x32bit regardless of the channels
738 #define VT1724_BUFFER_ALIGN 0x20
740 static int snd_vt1724_playback_pro_open(snd_pcm_substream_t * substream)
742 snd_pcm_runtime_t *runtime = substream->runtime;
743 ice1712_t *ice = snd_pcm_substream_chip(substream);
746 runtime->private_data = &vt1724_playback_pro_reg;
747 ice->playback_pro_substream = substream;
748 runtime->hw = snd_vt1724_playback_pro;
749 snd_pcm_set_sync(substream);
750 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
751 set_rate_constraints(ice, substream);
752 down(&ice->open_mutex);
753 /* calculate the currently available channels */
754 for (chs = 0; chs < 3; chs++) {
755 if (ice->pcm_reserved[chs])
759 runtime->hw.channels_max = chs;
760 if (chs > 2) /* channels must be even */
761 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, 2);
762 up(&ice->open_mutex);
763 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
764 VT1724_BUFFER_ALIGN);
765 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
766 VT1724_BUFFER_ALIGN);
770 static int snd_vt1724_capture_pro_open(snd_pcm_substream_t * substream)
772 ice1712_t *ice = snd_pcm_substream_chip(substream);
773 snd_pcm_runtime_t *runtime = substream->runtime;
775 runtime->private_data = &vt1724_capture_pro_reg;
776 ice->capture_pro_substream = substream;
777 runtime->hw = snd_vt1724_2ch_stereo;
778 snd_pcm_set_sync(substream);
779 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
780 set_rate_constraints(ice, substream);
781 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
782 VT1724_BUFFER_ALIGN);
783 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
784 VT1724_BUFFER_ALIGN);
788 static int snd_vt1724_playback_pro_close(snd_pcm_substream_t * substream)
790 ice1712_t *ice = snd_pcm_substream_chip(substream);
793 snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
794 ice->playback_pro_substream = NULL;
799 static int snd_vt1724_capture_pro_close(snd_pcm_substream_t * substream)
801 ice1712_t *ice = snd_pcm_substream_chip(substream);
804 snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
805 ice->capture_pro_substream = NULL;
809 static snd_pcm_ops_t snd_vt1724_playback_pro_ops = {
810 .open = snd_vt1724_playback_pro_open,
811 .close = snd_vt1724_playback_pro_close,
812 .ioctl = snd_pcm_lib_ioctl,
813 .hw_params = snd_vt1724_pcm_hw_params,
814 .hw_free = snd_vt1724_pcm_hw_free,
815 .prepare = snd_vt1724_playback_pro_prepare,
816 .trigger = snd_vt1724_pcm_trigger,
817 .pointer = snd_vt1724_playback_pro_pointer,
820 static snd_pcm_ops_t snd_vt1724_capture_pro_ops = {
821 .open = snd_vt1724_capture_pro_open,
822 .close = snd_vt1724_capture_pro_close,
823 .ioctl = snd_pcm_lib_ioctl,
824 .hw_params = snd_vt1724_pcm_hw_params,
825 .hw_free = snd_vt1724_pcm_hw_free,
826 .prepare = snd_vt1724_pcm_prepare,
827 .trigger = snd_vt1724_pcm_trigger,
828 .pointer = snd_vt1724_pcm_pointer,
831 static int __devinit snd_vt1724_pcm_profi(ice1712_t * ice, int device)
836 err = snd_pcm_new(ice->card, "ICE1724", device, 1, 1, &pcm);
840 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_vt1724_playback_pro_ops);
841 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_vt1724_capture_pro_ops);
843 pcm->private_data = ice;
845 strcpy(pcm->name, "ICE1724");
847 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
848 snd_dma_pci_data(ice->pci), 256*1024, 256*1024);
860 static struct vt1724_pcm_reg vt1724_playback_spdif_reg = {
861 .addr = VT1724_MT_PDMA4_ADDR,
862 .size = VT1724_MT_PDMA4_SIZE,
863 .count = VT1724_MT_PDMA4_COUNT,
864 .start = VT1724_PDMA4_START,
867 static struct vt1724_pcm_reg vt1724_capture_spdif_reg = {
868 .addr = VT1724_MT_RDMA1_ADDR,
869 .size = VT1724_MT_RDMA1_SIZE,
870 .count = VT1724_MT_RDMA1_COUNT,
871 .start = VT1724_RDMA1_START,
874 /* update spdif control bits; call with reg_lock */
875 static void update_spdif_bits(ice1712_t *ice, unsigned int val)
877 unsigned char cbit, disabled;
879 cbit = inb(ICEREG1724(ice, SPDIF_CFG));
880 disabled = cbit & ~VT1724_CFG_SPDIF_OUT_EN;
881 if (cbit != disabled)
882 outb(disabled, ICEREG1724(ice, SPDIF_CFG));
883 outw(val, ICEMT1724(ice, SPDIF_CTRL));
884 if (cbit != disabled)
885 outb(cbit, ICEREG1724(ice, SPDIF_CFG));
886 outw(val, ICEMT1724(ice, SPDIF_CTRL));
889 /* update SPDIF control bits according to the given rate */
890 static void update_spdif_rate(ice1712_t *ice, unsigned int rate)
892 unsigned int val, nval;
895 spin_lock_irqsave(&ice->reg_lock, flags);
896 nval = val = inw(ICEMT1724(ice, SPDIF_CTRL));
900 case 48000: nval |= 2 << 12; break;
901 case 32000: nval |= 3 << 12; break;
904 update_spdif_bits(ice, nval);
905 spin_unlock_irqrestore(&ice->reg_lock, flags);
908 static int snd_vt1724_playback_spdif_prepare(snd_pcm_substream_t * substream)
910 ice1712_t *ice = snd_pcm_substream_chip(substream);
911 if (! ice->force_pdma4)
912 update_spdif_rate(ice, substream->runtime->rate);
913 return snd_vt1724_pcm_prepare(substream);
916 static int snd_vt1724_playback_spdif_open(snd_pcm_substream_t *substream)
918 ice1712_t *ice = snd_pcm_substream_chip(substream);
919 snd_pcm_runtime_t *runtime = substream->runtime;
921 runtime->private_data = &vt1724_playback_spdif_reg;
922 ice->playback_con_substream = substream;
923 if (ice->force_pdma4) {
924 runtime->hw = snd_vt1724_2ch_stereo;
925 set_rate_constraints(ice, substream);
927 runtime->hw = snd_vt1724_spdif;
928 snd_pcm_set_sync(substream);
929 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
930 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
931 VT1724_BUFFER_ALIGN);
932 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
933 VT1724_BUFFER_ALIGN);
937 static int snd_vt1724_playback_spdif_close(snd_pcm_substream_t * substream)
939 ice1712_t *ice = snd_pcm_substream_chip(substream);
942 snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
943 ice->playback_con_substream = NULL;
948 static int snd_vt1724_capture_spdif_open(snd_pcm_substream_t *substream)
950 ice1712_t *ice = snd_pcm_substream_chip(substream);
951 snd_pcm_runtime_t *runtime = substream->runtime;
953 runtime->private_data = &vt1724_capture_spdif_reg;
954 ice->capture_con_substream = substream;
955 if (ice->force_rdma1) {
956 runtime->hw = snd_vt1724_2ch_stereo;
957 set_rate_constraints(ice, substream);
959 runtime->hw = snd_vt1724_spdif;
960 snd_pcm_set_sync(substream);
961 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
962 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
963 VT1724_BUFFER_ALIGN);
964 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
965 VT1724_BUFFER_ALIGN);
969 static int snd_vt1724_capture_spdif_close(snd_pcm_substream_t * substream)
971 ice1712_t *ice = snd_pcm_substream_chip(substream);
974 snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
975 ice->capture_con_substream = NULL;
980 static snd_pcm_ops_t snd_vt1724_playback_spdif_ops = {
981 .open = snd_vt1724_playback_spdif_open,
982 .close = snd_vt1724_playback_spdif_close,
983 .ioctl = snd_pcm_lib_ioctl,
984 .hw_params = snd_vt1724_pcm_hw_params,
985 .hw_free = snd_vt1724_pcm_hw_free,
986 .prepare = snd_vt1724_playback_spdif_prepare,
987 .trigger = snd_vt1724_pcm_trigger,
988 .pointer = snd_vt1724_pcm_pointer,
991 static snd_pcm_ops_t snd_vt1724_capture_spdif_ops = {
992 .open = snd_vt1724_capture_spdif_open,
993 .close = snd_vt1724_capture_spdif_close,
994 .ioctl = snd_pcm_lib_ioctl,
995 .hw_params = snd_vt1724_pcm_hw_params,
996 .hw_free = snd_vt1724_pcm_hw_free,
997 .prepare = snd_vt1724_pcm_prepare,
998 .trigger = snd_vt1724_pcm_trigger,
999 .pointer = snd_vt1724_pcm_pointer,
1003 static int __devinit snd_vt1724_pcm_spdif(ice1712_t * ice, int device)
1010 if (ice->force_pdma4 ||
1011 (ice->eeprom.data[ICE_EEP2_SPDIF] & VT1724_CFG_SPDIF_OUT_INT)) {
1016 if (ice->force_rdma1 ||
1017 (ice->eeprom.data[ICE_EEP2_SPDIF] & VT1724_CFG_SPDIF_IN)) {
1022 if (! play && ! capt)
1023 return 0; /* no spdif device */
1025 if (ice->force_pdma4 || ice->force_rdma1)
1026 name = "ICE1724 Secondary";
1028 name = "IEC1724 IEC958";
1029 err = snd_pcm_new(ice->card, name, device, play, capt, &pcm);
1034 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
1035 &snd_vt1724_playback_spdif_ops);
1037 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
1038 &snd_vt1724_capture_spdif_ops);
1040 pcm->private_data = ice;
1041 pcm->info_flags = 0;
1042 strcpy(pcm->name, name);
1044 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
1045 snd_dma_pci_data(ice->pci), 64*1024, 64*1024);
1054 * independent surround PCMs
1057 static struct vt1724_pcm_reg vt1724_playback_dma_regs[3] = {
1059 .addr = VT1724_MT_PDMA1_ADDR,
1060 .size = VT1724_MT_PDMA1_SIZE,
1061 .count = VT1724_MT_PDMA1_COUNT,
1062 .start = VT1724_PDMA1_START,
1065 .addr = VT1724_MT_PDMA2_ADDR,
1066 .size = VT1724_MT_PDMA2_SIZE,
1067 .count = VT1724_MT_PDMA2_COUNT,
1068 .start = VT1724_PDMA2_START,
1071 .addr = VT1724_MT_PDMA3_ADDR,
1072 .size = VT1724_MT_PDMA3_SIZE,
1073 .count = VT1724_MT_PDMA3_COUNT,
1074 .start = VT1724_PDMA3_START,
1078 static int snd_vt1724_playback_indep_prepare(snd_pcm_substream_t * substream)
1080 ice1712_t *ice = snd_pcm_substream_chip(substream);
1083 spin_lock_irq(&ice->reg_lock);
1084 val = 3 - substream->number;
1085 if (inb(ICEMT1724(ice, BURST)) < val)
1086 outb(val, ICEMT1724(ice, BURST));
1087 spin_unlock_irq(&ice->reg_lock);
1088 return snd_vt1724_pcm_prepare(substream);
1091 static int snd_vt1724_playback_indep_open(snd_pcm_substream_t *substream)
1093 ice1712_t *ice = snd_pcm_substream_chip(substream);
1094 snd_pcm_runtime_t *runtime = substream->runtime;
1096 down(&ice->open_mutex);
1097 /* already used by PDMA0? */
1098 if (ice->pcm_reserved[substream->number]) {
1099 up(&ice->open_mutex);
1100 return -EBUSY; /* FIXME: should handle blocking mode properly */
1102 up(&ice->open_mutex);
1103 runtime->private_data = &vt1724_playback_dma_regs[substream->number];
1104 ice->playback_con_substream_ds[substream->number] = substream;
1105 runtime->hw = snd_vt1724_2ch_stereo;
1106 snd_pcm_set_sync(substream);
1107 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
1108 set_rate_constraints(ice, substream);
1112 static int snd_vt1724_playback_indep_close(snd_pcm_substream_t * substream)
1114 ice1712_t *ice = snd_pcm_substream_chip(substream);
1117 snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
1118 ice->playback_con_substream_ds[substream->number] = NULL;
1119 ice->pcm_reserved[substream->number] = NULL;
1124 static snd_pcm_ops_t snd_vt1724_playback_indep_ops = {
1125 .open = snd_vt1724_playback_indep_open,
1126 .close = snd_vt1724_playback_indep_close,
1127 .ioctl = snd_pcm_lib_ioctl,
1128 .hw_params = snd_vt1724_pcm_hw_params,
1129 .hw_free = snd_vt1724_pcm_hw_free,
1130 .prepare = snd_vt1724_playback_indep_prepare,
1131 .trigger = snd_vt1724_pcm_trigger,
1132 .pointer = snd_vt1724_pcm_pointer,
1136 static int __devinit snd_vt1724_pcm_indep(ice1712_t * ice, int device)
1142 play = ice->num_total_dacs / 2 - 1;
1146 err = snd_pcm_new(ice->card, "ICE1724 Surrounds", device, play, 0, &pcm);
1150 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
1151 &snd_vt1724_playback_indep_ops);
1153 pcm->private_data = ice;
1154 pcm->info_flags = 0;
1155 strcpy(pcm->name, "ICE1724 Surround PCM");
1157 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
1158 snd_dma_pci_data(ice->pci), 64*1024, 64*1024);
1170 static int __devinit snd_vt1724_ac97_mixer(ice1712_t * ice)
1174 if (! (ice->eeprom.data[ICE_EEP2_ACLINK] & VT1724_CFG_PRO_I2S)) {
1176 ac97_template_t ac97;
1177 static ac97_bus_ops_t ops = {
1178 .write = snd_vt1724_ac97_write,
1179 .read = snd_vt1724_ac97_read,
1183 outb(inb(ICEMT1724(ice, AC97_CMD)) | 0x80, ICEMT1724(ice, AC97_CMD));
1184 mdelay(5); /* FIXME */
1185 outb(inb(ICEMT1724(ice, AC97_CMD)) & ~0x80, ICEMT1724(ice, AC97_CMD));
1187 if ((err = snd_ac97_bus(ice->card, 0, &ops, NULL, &pbus)) < 0)
1189 memset(&ac97, 0, sizeof(ac97));
1190 ac97.private_data = ice;
1191 if ((err = snd_ac97_mixer(pbus, &ac97, &ice->ac97)) < 0)
1192 printk(KERN_WARNING "ice1712: cannot initialize pro ac97, skipped\n");
1196 /* I2S mixer only */
1197 strcat(ice->card->mixername, "ICE1724 - multitrack");
1205 static inline unsigned int eeprom_triple(ice1712_t *ice, int idx)
1207 return (unsigned int)ice->eeprom.data[idx] | \
1208 ((unsigned int)ice->eeprom.data[idx + 1] << 8) | \
1209 ((unsigned int)ice->eeprom.data[idx + 2] << 16);
1212 static void snd_vt1724_proc_read(snd_info_entry_t *entry,
1213 snd_info_buffer_t * buffer)
1215 ice1712_t *ice = entry->private_data;
1218 snd_iprintf(buffer, "%s\n\n", ice->card->longname);
1219 snd_iprintf(buffer, "EEPROM:\n");
1221 snd_iprintf(buffer, " Subvendor : 0x%x\n", ice->eeprom.subvendor);
1222 snd_iprintf(buffer, " Size : %i bytes\n", ice->eeprom.size);
1223 snd_iprintf(buffer, " Version : %i\n", ice->eeprom.version);
1224 snd_iprintf(buffer, " System Config : 0x%x\n", ice->eeprom.data[ICE_EEP2_SYSCONF]);
1225 snd_iprintf(buffer, " ACLink : 0x%x\n", ice->eeprom.data[ICE_EEP2_ACLINK]);
1226 snd_iprintf(buffer, " I2S : 0x%x\n", ice->eeprom.data[ICE_EEP2_I2S]);
1227 snd_iprintf(buffer, " S/PDIF : 0x%x\n", ice->eeprom.data[ICE_EEP2_SPDIF]);
1228 snd_iprintf(buffer, " GPIO direction : 0x%x\n", ice->eeprom.gpiodir);
1229 snd_iprintf(buffer, " GPIO mask : 0x%x\n", ice->eeprom.gpiomask);
1230 snd_iprintf(buffer, " GPIO state : 0x%x\n", ice->eeprom.gpiostate);
1231 for (idx = 0x12; idx < ice->eeprom.size; idx++)
1232 snd_iprintf(buffer, " Extra #%02i : 0x%x\n", idx, ice->eeprom.data[idx]);
1234 snd_iprintf(buffer, "\nRegisters:\n");
1236 snd_iprintf(buffer, " PSDOUT03 : 0x%08x\n", (unsigned)inl(ICEMT1724(ice, ROUTE_PLAYBACK)));
1237 for (idx = 0x0; idx < 0x20 ; idx++)
1238 snd_iprintf(buffer, " CCS%02x : 0x%02x\n", idx, inb(ice->port+idx));
1239 for (idx = 0x0; idx < 0x30 ; idx++)
1240 snd_iprintf(buffer, " MT%02x : 0x%02x\n", idx, inb(ice->profi_port+idx));
1243 static void __devinit snd_vt1724_proc_init(ice1712_t * ice)
1245 snd_info_entry_t *entry;
1247 if (! snd_card_proc_new(ice->card, "ice1724", &entry))
1248 snd_info_set_text_ops(entry, ice, 1024, snd_vt1724_proc_read);
1255 static int snd_vt1724_eeprom_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1257 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
1258 uinfo->count = sizeof(ice1712_eeprom_t);
1262 static int snd_vt1724_eeprom_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1264 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1266 memcpy(ucontrol->value.bytes.data, &ice->eeprom, sizeof(ice->eeprom));
1270 static snd_kcontrol_new_t snd_vt1724_eeprom __devinitdata = {
1271 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1272 .name = "ICE1724 EEPROM",
1273 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1274 .info = snd_vt1724_eeprom_info,
1275 .get = snd_vt1724_eeprom_get
1280 static int snd_vt1724_spdif_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1282 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1287 static unsigned int encode_spdif_bits(snd_aes_iec958_t *diga)
1291 val = diga->status[0] & 0x03; /* professional, non-audio */
1294 if ((diga->status[0] & IEC958_AES0_PRO_EMPHASIS) == IEC958_AES0_PRO_EMPHASIS_5015)
1296 switch (diga->status[0] & IEC958_AES0_PRO_FS) {
1297 case IEC958_AES0_PRO_FS_44100:
1299 case IEC958_AES0_PRO_FS_32000:
1308 val |= diga->status[1] & 0x04; /* copyright */
1309 if ((diga->status[0] & IEC958_AES0_CON_EMPHASIS)== IEC958_AES0_CON_EMPHASIS_5015)
1311 val |= (unsigned int)(diga->status[1] & 0x3f) << 4; /* category */
1312 val |= (unsigned int)(diga->status[3] & IEC958_AES3_CON_FS) << 12; /* fs */
1317 static void decode_spdif_bits(snd_aes_iec958_t *diga, unsigned int val)
1319 memset(diga->status, 0, sizeof(diga->status));
1320 diga->status[0] = val & 0x03; /* professional, non-audio */
1323 if (val & (1U << 3))
1324 diga->status[0] |= IEC958_AES0_PRO_EMPHASIS_5015;
1325 switch ((val >> 12) & 0x7) {
1329 diga->status[0] |= IEC958_AES0_PRO_FS_32000;
1332 diga->status[0] |= IEC958_AES0_PRO_FS_48000;
1337 diga->status[0] |= val & (1U << 2); /* copyright */
1338 if (val & (1U << 3))
1339 diga->status[0] |= IEC958_AES0_CON_EMPHASIS_5015;
1340 diga->status[1] |= (val >> 4) & 0x3f; /* category */
1341 diga->status[3] |= (val >> 12) & 0x07; /* fs */
1345 static int snd_vt1724_spdif_default_get(snd_kcontrol_t * kcontrol,
1346 snd_ctl_elem_value_t * ucontrol)
1348 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1350 val = inw(ICEMT1724(ice, SPDIF_CTRL));
1351 decode_spdif_bits(&ucontrol->value.iec958, val);
1355 static int snd_vt1724_spdif_default_put(snd_kcontrol_t * kcontrol,
1356 snd_ctl_elem_value_t * ucontrol)
1358 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1359 unsigned int val, old;
1361 val = encode_spdif_bits(&ucontrol->value.iec958);
1362 spin_lock_irq(&ice->reg_lock);
1363 old = inw(ICEMT1724(ice, SPDIF_CTRL));
1365 update_spdif_bits(ice, val);
1366 spin_unlock_irq(&ice->reg_lock);
1367 return (val != old);
1370 static snd_kcontrol_new_t snd_vt1724_spdif_default __devinitdata =
1372 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1373 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
1374 .info = snd_vt1724_spdif_info,
1375 .get = snd_vt1724_spdif_default_get,
1376 .put = snd_vt1724_spdif_default_put
1379 static int snd_vt1724_spdif_maskc_get(snd_kcontrol_t * kcontrol,
1380 snd_ctl_elem_value_t * ucontrol)
1382 ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO |
1383 IEC958_AES0_PROFESSIONAL |
1384 IEC958_AES0_CON_NOT_COPYRIGHT |
1385 IEC958_AES0_CON_EMPHASIS;
1386 ucontrol->value.iec958.status[1] = IEC958_AES1_CON_ORIGINAL |
1387 IEC958_AES1_CON_CATEGORY;
1388 ucontrol->value.iec958.status[3] = IEC958_AES3_CON_FS;
1392 static int snd_vt1724_spdif_maskp_get(snd_kcontrol_t * kcontrol,
1393 snd_ctl_elem_value_t * ucontrol)
1395 ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO |
1396 IEC958_AES0_PROFESSIONAL |
1397 IEC958_AES0_PRO_FS |
1398 IEC958_AES0_PRO_EMPHASIS;
1402 static snd_kcontrol_new_t snd_vt1724_spdif_maskc __devinitdata =
1404 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1405 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1406 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,CON_MASK),
1407 .info = snd_vt1724_spdif_info,
1408 .get = snd_vt1724_spdif_maskc_get,
1411 static snd_kcontrol_new_t snd_vt1724_spdif_maskp __devinitdata =
1413 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1414 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1415 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PRO_MASK),
1416 .info = snd_vt1724_spdif_info,
1417 .get = snd_vt1724_spdif_maskp_get,
1420 static int snd_vt1724_spdif_sw_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1422 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1424 uinfo->value.integer.min = 0;
1425 uinfo->value.integer.max = 1;
1429 static int snd_vt1724_spdif_sw_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1431 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1432 ucontrol->value.integer.value[0] = inb(ICEREG1724(ice, SPDIF_CFG)) & VT1724_CFG_SPDIF_OUT_EN ? 1 : 0;
1436 static int snd_vt1724_spdif_sw_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1438 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1439 unsigned char old, val;
1441 spin_lock_irq(&ice->reg_lock);
1442 old = val = inb(ICEREG1724(ice, SPDIF_CFG));
1443 val &= ~VT1724_CFG_SPDIF_OUT_EN;
1444 if (ucontrol->value.integer.value[0])
1445 val |= VT1724_CFG_SPDIF_OUT_EN;
1447 outb(val, ICEREG1724(ice, SPDIF_CFG));
1448 spin_unlock_irq(&ice->reg_lock);
1452 static snd_kcontrol_new_t snd_vt1724_spdif_switch __devinitdata =
1454 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1455 /* FIXME: the following conflict with IEC958 Playback Route */
1456 // .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH),
1457 .name = "IEC958 Output Switch",
1458 .info = snd_vt1724_spdif_sw_info,
1459 .get = snd_vt1724_spdif_sw_get,
1460 .put = snd_vt1724_spdif_sw_put
1464 #if 0 /* NOT USED YET */
1466 * GPIO access from extern
1469 int snd_vt1724_gpio_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1471 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1473 uinfo->value.integer.min = 0;
1474 uinfo->value.integer.max = 1;
1478 int snd_vt1724_gpio_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1480 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1481 int shift = kcontrol->private_value & 0xff;
1482 int invert = (kcontrol->private_value & (1<<24)) ? 1 : 0;
1484 snd_ice1712_save_gpio_status(ice);
1485 ucontrol->value.integer.value[0] = (snd_ice1712_gpio_read(ice) & (1 << shift) ? 1 : 0) ^ invert;
1486 snd_ice1712_restore_gpio_status(ice);
1490 int snd_ice1712_gpio_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1492 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1493 int shift = kcontrol->private_value & 0xff;
1494 int invert = (kcontrol->private_value & (1<<24)) ? mask : 0;
1495 unsigned int val, nval;
1497 if (kcontrol->private_value & (1 << 31))
1499 nval = (ucontrol->value.integer.value[0] ? (1 << shift) : 0) ^ invert;
1500 snd_ice1712_save_gpio_status(ice);
1501 val = snd_ice1712_gpio_read(ice);
1502 nval |= val & ~(1 << shift);
1504 snd_ice1712_gpio_write(ice, nval);
1505 snd_ice1712_restore_gpio_status(ice);
1508 #endif /* NOT USED YET */
1513 static int snd_vt1724_pro_internal_clock_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1515 static char *texts_1724[] = {
1518 "11025", /* 2: 10 */
1526 "64000", /* 10: 15 */
1527 "88200", /* 11: 11 */
1528 "96000", /* 12: 7 */
1529 "176400", /* 13: 12 */
1530 "192000", /* 14: 14 */
1531 "IEC958 Input", /* 15: -- */
1533 static char *texts_1720[] = {
1536 "11025", /* 2: 10 */
1544 "64000", /* 10: 15 */
1545 "88200", /* 11: 11 */
1546 "96000", /* 12: 7 */
1547 "IEC958 Input", /* 13: -- */
1549 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1551 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1553 uinfo->value.enumerated.items = ice->vt1720 ? 14 : 16;
1554 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1555 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1556 strcpy(uinfo->value.enumerated.name,
1557 ice->vt1720 ? texts_1720[uinfo->value.enumerated.item] :
1558 texts_1724[uinfo->value.enumerated.item]);
1562 static int snd_vt1724_pro_internal_clock_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1564 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1565 static unsigned char xlate[16] = {
1566 9, 6, 3, 1, 7, 4, 0, 12, 8, 5, 2, 11, 13, 255, 14, 10
1570 spin_lock_irq(&ice->reg_lock);
1571 if (is_spdif_master(ice)) {
1572 ucontrol->value.enumerated.item[0] = ice->vt1720 ? 13 : 15;
1574 val = xlate[inb(ICEMT1724(ice, RATE)) & 15];
1579 ucontrol->value.enumerated.item[0] = val;
1581 spin_unlock_irq(&ice->reg_lock);
1585 static int snd_vt1724_pro_internal_clock_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1587 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1591 int spdif = ice->vt1720 ? 13 : 15;
1593 spin_lock_irq(&ice->reg_lock);
1594 oval = inb(ICEMT1724(ice, RATE));
1595 if (ucontrol->value.enumerated.item[0] == spdif) {
1596 outb(oval | VT1724_SPDIF_MASTER, ICEMT1724(ice, RATE));
1598 rate = rates[ucontrol->value.integer.value[0] % 15];
1599 if (rate <= get_max_rate(ice)) {
1600 PRO_RATE_DEFAULT = rate;
1601 spin_unlock_irq(&ice->reg_lock);
1602 snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 1);
1603 spin_lock_irq(&ice->reg_lock);
1606 change = inb(ICEMT1724(ice, RATE)) != oval;
1607 spin_unlock_irq(&ice->reg_lock);
1609 if ((oval & VT1724_SPDIF_MASTER) != (inb(ICEMT1724(ice, RATE)) & VT1724_SPDIF_MASTER)) {
1610 /* notify akm chips as well */
1611 if (is_spdif_master(ice)) {
1613 for (i = 0; i < ice->akm_codecs; i++) {
1614 if (ice->akm[i].ops.set_rate_val)
1615 ice->akm[i].ops.set_rate_val(&ice->akm[i], 0);
1622 static snd_kcontrol_new_t snd_vt1724_pro_internal_clock __devinitdata = {
1623 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1624 .name = "Multi Track Internal Clock",
1625 .info = snd_vt1724_pro_internal_clock_info,
1626 .get = snd_vt1724_pro_internal_clock_get,
1627 .put = snd_vt1724_pro_internal_clock_put
1630 static int snd_vt1724_pro_rate_locking_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1632 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1634 uinfo->value.integer.min = 0;
1635 uinfo->value.integer.max = 1;
1639 static int snd_vt1724_pro_rate_locking_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1641 ucontrol->value.integer.value[0] = PRO_RATE_LOCKED;
1645 static int snd_vt1724_pro_rate_locking_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1647 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1648 int change = 0, nval;
1650 nval = ucontrol->value.integer.value[0] ? 1 : 0;
1651 spin_lock_irq(&ice->reg_lock);
1652 change = PRO_RATE_LOCKED != nval;
1653 PRO_RATE_LOCKED = nval;
1654 spin_unlock_irq(&ice->reg_lock);
1658 static snd_kcontrol_new_t snd_vt1724_pro_rate_locking __devinitdata = {
1659 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1660 .name = "Multi Track Rate Locking",
1661 .info = snd_vt1724_pro_rate_locking_info,
1662 .get = snd_vt1724_pro_rate_locking_get,
1663 .put = snd_vt1724_pro_rate_locking_put
1666 static int snd_vt1724_pro_rate_reset_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1668 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1670 uinfo->value.integer.min = 0;
1671 uinfo->value.integer.max = 1;
1675 static int snd_vt1724_pro_rate_reset_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1677 ucontrol->value.integer.value[0] = PRO_RATE_RESET ? 1 : 0;
1681 static int snd_vt1724_pro_rate_reset_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1683 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1684 int change = 0, nval;
1686 nval = ucontrol->value.integer.value[0] ? 1 : 0;
1687 spin_lock_irq(&ice->reg_lock);
1688 change = PRO_RATE_RESET != nval;
1689 PRO_RATE_RESET = nval;
1690 spin_unlock_irq(&ice->reg_lock);
1694 static snd_kcontrol_new_t snd_vt1724_pro_rate_reset __devinitdata = {
1695 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1696 .name = "Multi Track Rate Reset",
1697 .info = snd_vt1724_pro_rate_reset_info,
1698 .get = snd_vt1724_pro_rate_reset_get,
1699 .put = snd_vt1724_pro_rate_reset_put
1706 static int snd_vt1724_pro_route_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1708 static char *texts[] = {
1710 "H/W In 0", "H/W In 1", /* 1-2 */
1711 "IEC958 In L", "IEC958 In R", /* 3-4 */
1714 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1716 uinfo->value.enumerated.items = 5;
1717 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1718 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1719 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1723 static inline int analog_route_shift(int idx)
1725 return (idx % 2) * 12 + ((idx / 2) * 3) + 8;
1728 static inline int digital_route_shift(int idx)
1733 static int get_route_val(ice1712_t *ice, int shift)
1736 unsigned char eitem;
1737 static unsigned char xlate[8] = {
1738 0, 255, 1, 2, 255, 255, 3, 4,
1741 val = inl(ICEMT1724(ice, ROUTE_PLAYBACK));
1743 val &= 7; //we now have 3 bits per output
1752 static int put_route_val(ice1712_t *ice, unsigned int val, int shift)
1754 unsigned int old_val, nval;
1756 static unsigned char xroute[8] = {
1758 2, /* PSDIN0 Left */
1759 3, /* PSDIN0 Right */
1761 7, /* SPDIN Right */
1764 nval = xroute[val % 5];
1765 val = old_val = inl(ICEMT1724(ice, ROUTE_PLAYBACK));
1766 val &= ~(0x07 << shift);
1767 val |= nval << shift;
1768 change = val != old_val;
1770 outl(val, ICEMT1724(ice, ROUTE_PLAYBACK));
1774 static int snd_vt1724_pro_route_analog_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)
1776 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1777 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1778 ucontrol->value.enumerated.item[0] = get_route_val(ice, analog_route_shift(idx));
1782 static int snd_vt1724_pro_route_analog_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)
1784 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1785 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1786 return put_route_val(ice, ucontrol->value.enumerated.item[0],
1787 analog_route_shift(idx));
1790 static int snd_vt1724_pro_route_spdif_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)
1792 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1793 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1794 ucontrol->value.enumerated.item[0] = get_route_val(ice, digital_route_shift(idx));
1798 static int snd_vt1724_pro_route_spdif_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)
1800 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1801 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1802 return put_route_val(ice, ucontrol->value.enumerated.item[0],
1803 digital_route_shift(idx));
1806 static snd_kcontrol_new_t snd_vt1724_mixer_pro_analog_route __devinitdata = {
1807 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1808 .name = "H/W Playback Route",
1809 .info = snd_vt1724_pro_route_info,
1810 .get = snd_vt1724_pro_route_analog_get,
1811 .put = snd_vt1724_pro_route_analog_put,
1814 static snd_kcontrol_new_t snd_vt1724_mixer_pro_spdif_route __devinitdata = {
1815 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1816 .name = "IEC958 Playback Route",
1817 .info = snd_vt1724_pro_route_info,
1818 .get = snd_vt1724_pro_route_spdif_get,
1819 .put = snd_vt1724_pro_route_spdif_put,
1824 static int snd_vt1724_pro_peak_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1826 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1827 uinfo->count = 22; /* FIXME: for compatibility with ice1712... */
1828 uinfo->value.integer.min = 0;
1829 uinfo->value.integer.max = 255;
1833 static int snd_vt1724_pro_peak_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1835 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1838 spin_lock_irq(&ice->reg_lock);
1839 for (idx = 0; idx < 22; idx++) {
1840 outb(idx, ICEMT1724(ice, MONITOR_PEAKINDEX));
1841 ucontrol->value.integer.value[idx] = inb(ICEMT1724(ice, MONITOR_PEAKDATA));
1843 spin_unlock_irq(&ice->reg_lock);
1847 static snd_kcontrol_new_t snd_vt1724_mixer_pro_peak __devinitdata = {
1848 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1849 .name = "Multi Track Peak",
1850 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
1851 .info = snd_vt1724_pro_peak_info,
1852 .get = snd_vt1724_pro_peak_get
1859 static struct snd_ice1712_card_info no_matched __devinitdata;
1861 static struct snd_ice1712_card_info *card_tables[] __devinitdata = {
1862 snd_vt1724_revo_cards,
1863 snd_vt1724_amp_cards,
1864 snd_vt1724_aureon_cards,
1865 snd_vt1720_mobo_cards,
1866 snd_vt1720_pontis_cards,
1874 static void wait_i2c_busy(ice1712_t *ice)
1877 while ((inb(ICEREG1724(ice, I2C_CTRL)) & VT1724_I2C_BUSY) && t--)
1881 unsigned char snd_vt1724_read_i2c(ice1712_t *ice, unsigned char dev, unsigned char addr)
1883 outb(addr, ICEREG1724(ice, I2C_BYTE_ADDR));
1884 outb(dev & ~VT1724_I2C_WRITE, ICEREG1724(ice, I2C_DEV_ADDR));
1886 return inb(ICEREG1724(ice, I2C_DATA));
1889 void snd_vt1724_write_i2c(ice1712_t *ice, unsigned char dev, unsigned char addr, unsigned char data)
1892 outb(addr, ICEREG1724(ice, I2C_BYTE_ADDR));
1893 outb(data, ICEREG1724(ice, I2C_DATA));
1894 outb(dev | VT1724_I2C_WRITE, ICEREG1724(ice, I2C_DEV_ADDR));
1898 static int __devinit snd_vt1724_read_eeprom(ice1712_t *ice, const char *modelname)
1900 const int dev = 0xa0; /* EEPROM device address */
1901 unsigned int i, size;
1902 struct snd_ice1712_card_info **tbl, *c;
1904 if (! modelname || ! *modelname) {
1905 ice->eeprom.subvendor = 0;
1906 if ((inb(ICEREG1724(ice, I2C_CTRL)) & VT1724_I2C_EEPROM) != 0)
1907 ice->eeprom.subvendor = (snd_vt1724_read_i2c(ice, dev, 0x00) << 0) |
1908 (snd_vt1724_read_i2c(ice, dev, 0x01) << 8) |
1909 (snd_vt1724_read_i2c(ice, dev, 0x02) << 16) |
1910 (snd_vt1724_read_i2c(ice, dev, 0x03) << 24);
1911 if (ice->eeprom.subvendor == 0 || ice->eeprom.subvendor == (unsigned int)-1) {
1912 /* invalid subvendor from EEPROM, try the PCI subststem ID instead */
1914 pci_read_config_word(ice->pci, PCI_SUBSYSTEM_VENDOR_ID, &vendor);
1915 pci_read_config_word(ice->pci, PCI_SUBSYSTEM_ID, &device);
1916 ice->eeprom.subvendor = ((unsigned int)swab16(vendor) << 16) | swab16(device);
1917 if (ice->eeprom.subvendor == 0 || ice->eeprom.subvendor == (unsigned int)-1) {
1918 printk(KERN_ERR "ice1724: No valid ID is found\n");
1923 for (tbl = card_tables; *tbl; tbl++) {
1924 for (c = *tbl; c->subvendor; c++) {
1925 if (modelname && c->model && ! strcmp(modelname, c->model)) {
1926 printk(KERN_INFO "ice1724: Using board model %s\n", c->name);
1927 ice->eeprom.subvendor = c->subvendor;
1928 } else if (c->subvendor != ice->eeprom.subvendor)
1930 if (! c->eeprom_size || ! c->eeprom_data)
1932 /* if the EEPROM is given by the driver, use it */
1933 snd_printdd("using the defined eeprom..\n");
1934 ice->eeprom.version = 2;
1935 ice->eeprom.size = c->eeprom_size + 6;
1936 memcpy(ice->eeprom.data, c->eeprom_data, c->eeprom_size);
1940 printk(KERN_WARNING "ice1724: No matching model found for ID 0x%x\n", ice->eeprom.subvendor);
1943 ice->eeprom.size = snd_vt1724_read_i2c(ice, dev, 0x04);
1944 if (ice->eeprom.size < 6)
1945 ice->eeprom.size = 32;
1946 else if (ice->eeprom.size > 32) {
1947 printk(KERN_ERR "ice1724: Invalid EEPROM (size = %i)\n", ice->eeprom.size);
1950 ice->eeprom.version = snd_vt1724_read_i2c(ice, dev, 0x05);
1951 if (ice->eeprom.version != 2)
1952 printk(KERN_WARNING "ice1724: Invalid EEPROM version %i\n", ice->eeprom.version);
1953 size = ice->eeprom.size - 6;
1954 for (i = 0; i < size; i++)
1955 ice->eeprom.data[i] = snd_vt1724_read_i2c(ice, dev, i + 6);
1958 ice->eeprom.gpiomask = eeprom_triple(ice, ICE_EEP2_GPIO_MASK);
1959 ice->eeprom.gpiostate = eeprom_triple(ice, ICE_EEP2_GPIO_STATE);
1960 ice->eeprom.gpiodir = eeprom_triple(ice, ICE_EEP2_GPIO_DIR);
1967 static int __devinit snd_vt1724_chip_init(ice1712_t *ice)
1969 outb(VT1724_RESET , ICEREG1724(ice, CONTROL));
1971 outb(0, ICEREG1724(ice, CONTROL));
1973 outb(ice->eeprom.data[ICE_EEP2_SYSCONF], ICEREG1724(ice, SYS_CFG));
1974 outb(ice->eeprom.data[ICE_EEP2_ACLINK], ICEREG1724(ice, AC97_CFG));
1975 outb(ice->eeprom.data[ICE_EEP2_I2S], ICEREG1724(ice, I2S_FEATURES));
1976 outb(ice->eeprom.data[ICE_EEP2_SPDIF], ICEREG1724(ice, SPDIF_CFG));
1978 ice->gpio.write_mask = ice->eeprom.gpiomask;
1979 ice->gpio.direction = ice->eeprom.gpiodir;
1980 snd_vt1724_set_gpio_mask(ice, ice->eeprom.gpiomask);
1981 snd_vt1724_set_gpio_dir(ice, ice->eeprom.gpiodir);
1982 snd_vt1724_set_gpio_data(ice, ice->eeprom.gpiostate);
1984 outb(0, ICEREG1724(ice, POWERDOWN));
1989 static int __devinit snd_vt1724_spdif_build_controls(ice1712_t *ice)
1992 snd_kcontrol_t *kctl;
1994 snd_assert(ice->pcm != NULL, return -EIO);
1996 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_mixer_pro_spdif_route, ice));
2000 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_spdif_switch, ice));
2004 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_vt1724_spdif_default, ice));
2007 kctl->id.device = ice->pcm->device;
2008 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_vt1724_spdif_maskc, ice));
2011 kctl->id.device = ice->pcm->device;
2012 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_vt1724_spdif_maskp, ice));
2015 kctl->id.device = ice->pcm->device;
2016 #if 0 /* use default only */
2017 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_vt1724_spdif_stream, ice));
2020 kctl->id.device = ice->pcm->device;
2021 ice->spdif.stream_ctl = kctl;
2027 static int __devinit snd_vt1724_build_controls(ice1712_t *ice)
2031 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_eeprom, ice));
2034 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_pro_internal_clock, ice));
2038 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_pro_rate_locking, ice));
2041 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_pro_rate_reset, ice));
2045 if (ice->num_total_dacs > 0) {
2046 snd_kcontrol_new_t tmp = snd_vt1724_mixer_pro_analog_route;
2047 tmp.count = ice->num_total_dacs;
2048 if (ice->vt1720 && tmp.count > 2)
2050 err = snd_ctl_add(ice->card, snd_ctl_new1(&tmp, ice));
2055 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_mixer_pro_peak, ice));
2062 static int snd_vt1724_free(ice1712_t *ice)
2066 /* mask all interrupts */
2067 outb(0xff, ICEMT1724(ice, DMA_INT_MASK));
2068 outb(0xff, ICEREG1724(ice, IRQMASK));
2071 if (ice->irq >= 0) {
2072 synchronize_irq(ice->irq);
2073 free_irq(ice->irq, (void *) ice);
2075 pci_release_regions(ice->pci);
2076 snd_ice1712_akm4xxx_free(ice);
2081 static int snd_vt1724_dev_free(snd_device_t *device)
2083 ice1712_t *ice = device->device_data;
2084 return snd_vt1724_free(ice);
2087 static int __devinit snd_vt1724_create(snd_card_t * card,
2088 struct pci_dev *pci,
2089 const char *modelname,
2090 ice1712_t ** r_ice1712)
2095 static snd_device_ops_t ops = {
2096 .dev_free = snd_vt1724_dev_free,
2101 /* enable PCI device */
2102 if ((err = pci_enable_device(pci)) < 0)
2105 ice = kcalloc(1, sizeof(*ice), GFP_KERNEL);
2109 spin_lock_init(&ice->reg_lock);
2110 init_MUTEX(&ice->gpio_mutex);
2111 init_MUTEX(&ice->open_mutex);
2112 ice->gpio.set_mask = snd_vt1724_set_gpio_mask;
2113 ice->gpio.set_dir = snd_vt1724_set_gpio_dir;
2114 ice->gpio.set_data = snd_vt1724_set_gpio_data;
2115 ice->gpio.get_data = snd_vt1724_get_gpio_data;
2119 pci_set_master(pci);
2120 snd_vt1724_proc_init(ice);
2121 synchronize_irq(pci->irq);
2123 if ((err = pci_request_regions(pci, "ICE1724")) < 0) {
2127 ice->port = pci_resource_start(pci, 0);
2128 ice->profi_port = pci_resource_start(pci, 1);
2130 if (request_irq(pci->irq, snd_vt1724_interrupt, SA_INTERRUPT|SA_SHIRQ, "ICE1724", (void *) ice)) {
2131 snd_printk("unable to grab IRQ %d\n", pci->irq);
2132 snd_vt1724_free(ice);
2136 ice->irq = pci->irq;
2138 if (snd_vt1724_read_eeprom(ice, modelname) < 0) {
2139 snd_vt1724_free(ice);
2142 if (snd_vt1724_chip_init(ice) < 0) {
2143 snd_vt1724_free(ice);
2147 /* unmask used interrupts */
2148 if (! (ice->eeprom.data[ICE_EEP2_SYSCONF] & VT1724_CFG_MPU401))
2149 mask = VT1724_IRQ_MPU_RX | VT1724_IRQ_MPU_TX;
2152 outb(mask, ICEREG1724(ice, IRQMASK));
2153 /* don't handle FIFO overrun/underruns (just yet), since they cause machine lockups */
2154 outb(VT1724_MULTI_FIFO_ERR, ICEMT1724(ice, DMA_INT_MASK));
2156 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, ice, &ops)) < 0) {
2157 snd_vt1724_free(ice);
2161 snd_card_set_dev(card, &pci->dev);
2174 static int __devinit snd_vt1724_probe(struct pci_dev *pci,
2175 const struct pci_device_id *pci_id)
2180 int pcm_dev = 0, err;
2181 struct snd_ice1712_card_info **tbl, *c;
2183 if (dev >= SNDRV_CARDS)
2190 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
2194 strcpy(card->driver, "ICE1724");
2195 strcpy(card->shortname, "ICEnsemble ICE1724");
2197 if ((err = snd_vt1724_create(card, pci, model[dev], &ice)) < 0) {
2198 snd_card_free(card);
2202 for (tbl = card_tables; *tbl; tbl++) {
2203 for (c = *tbl; c->subvendor; c++) {
2204 if (c->subvendor == ice->eeprom.subvendor) {
2205 strcpy(card->shortname, c->name);
2206 if (c->driver) /* specific driver? */
2207 strcpy(card->driver, c->driver);
2209 if ((err = c->chip_init(ice)) < 0) {
2210 snd_card_free(card);
2221 if ((err = snd_vt1724_pcm_profi(ice, pcm_dev++)) < 0) {
2222 snd_card_free(card);
2226 if ((err = snd_vt1724_pcm_spdif(ice, pcm_dev++)) < 0) {
2227 snd_card_free(card);
2231 if ((err = snd_vt1724_pcm_indep(ice, pcm_dev++)) < 0) {
2232 snd_card_free(card);
2236 if ((err = snd_vt1724_ac97_mixer(ice)) < 0) {
2237 snd_card_free(card);
2241 if ((err = snd_vt1724_build_controls(ice)) < 0) {
2242 snd_card_free(card);
2246 if (ice->pcm && ice->has_spdif) { /* has SPDIF I/O */
2247 if ((err = snd_vt1724_spdif_build_controls(ice)) < 0) {
2248 snd_card_free(card);
2253 if (c->build_controls) {
2254 if ((err = c->build_controls(ice)) < 0) {
2255 snd_card_free(card);
2260 if (! c->no_mpu401) {
2261 if (ice->eeprom.data[ICE_EEP2_SYSCONF] & VT1724_CFG_MPU401) {
2262 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_ICE1712,
2263 ICEREG1724(ice, MPU_CTRL), 1,
2265 &ice->rmidi[0])) < 0) {
2266 snd_card_free(card);
2272 sprintf(card->longname, "%s at 0x%lx, irq %i",
2273 card->shortname, ice->port, ice->irq);
2275 if ((err = snd_card_register(card)) < 0) {
2276 snd_card_free(card);
2279 pci_set_drvdata(pci, card);
2284 static void __devexit snd_vt1724_remove(struct pci_dev *pci)
2286 snd_card_free(pci_get_drvdata(pci));
2287 pci_set_drvdata(pci, NULL);
2290 static struct pci_driver driver = {
2292 .id_table = snd_vt1724_ids,
2293 .probe = snd_vt1724_probe,
2294 .remove = __devexit_p(snd_vt1724_remove),
2297 static int __init alsa_card_ice1724_init(void)
2299 return pci_module_init(&driver);
2302 static void __exit alsa_card_ice1724_exit(void)
2304 pci_unregister_driver(&driver);
2307 module_init(alsa_card_ice1724_init)
2308 module_exit(alsa_card_ice1724_exit)