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 */
49 MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
50 MODULE_DESCRIPTION("VIA ICEnsemble ICE1724/1720 (Envy24HT/PT)");
51 MODULE_LICENSE("GPL");
52 MODULE_CLASSES("{sound}");
55 AMP_AUDIO2000_DEVICE_DESC
59 "{ICEnsemble,Generic ICE1724},"
60 "{ICEnsemble,Generic Envy24HT}"
61 "{ICEnsemble,Generic Envy24PT}}");
63 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
64 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
65 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */
66 static char *model[SNDRV_CARDS];
69 module_param_array(index, int, boot_devs, 0444);
70 MODULE_PARM_DESC(index, "Index value for ICE1724 soundcard.");
71 MODULE_PARM_SYNTAX(index, SNDRV_INDEX_DESC);
72 module_param_array(id, charp, boot_devs, 0444);
73 MODULE_PARM_DESC(id, "ID string for ICE1724 soundcard.");
74 MODULE_PARM_SYNTAX(id, SNDRV_ID_DESC);
75 module_param_array(enable, bool, boot_devs, 0444);
76 MODULE_PARM_DESC(enable, "Enable ICE1724 soundcard.");
77 MODULE_PARM_SYNTAX(enable, SNDRV_ENABLE_DESC);
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 outb((data >> 16) & 0xff, ICEREG1724(ice, GPIO_WRITE_MASK_22));
194 inw(ICEREG1724(ice, GPIO_WRITE_MASK)); /* dummy read for pci-posting */
197 static void snd_vt1724_set_gpio_data(ice1712_t *ice, unsigned int data)
199 outw(data, ICEREG1724(ice, GPIO_DATA));
200 outb(data >> 16, ICEREG1724(ice, GPIO_DATA_22));
201 inw(ICEREG1724(ice, GPIO_DATA)); /* dummy read for pci-posting */
204 static unsigned int snd_vt1724_get_gpio_data(ice1712_t *ice)
207 data = (unsigned int)inb(ICEREG1724(ice, GPIO_DATA_22));
208 data = (data << 16) | inw(ICEREG1724(ice, GPIO_DATA));
216 static irqreturn_t snd_vt1724_interrupt(int irq, void *dev_id, struct pt_regs *regs)
218 ice1712_t *ice = snd_magic_cast(ice1712_t, dev_id, return IRQ_NONE);
219 unsigned char status;
223 status = inb(ICEREG1724(ice, IRQSTAT));
228 /* these should probably be separated at some point,
229 but as we don't currently have MPU support on the board I will leave it */
230 if ((status & VT1724_IRQ_MPU_RX)||(status & VT1724_IRQ_MPU_TX)) {
232 snd_mpu401_uart_interrupt(irq, ice->rmidi[0]->private_data, regs);
233 outb(VT1724_IRQ_MPU_RX|VT1724_IRQ_MPU_TX, ICEREG1724(ice, IRQSTAT));
234 status &= ~(VT1724_IRQ_MPU_RX|VT1724_IRQ_MPU_TX);
236 if (status & VT1724_IRQ_MTPCM) {
239 * PCM assignment are:
240 * Playback DMA0 (M/C) = playback_pro_substream
241 * Playback DMA1 = playback_con_substream_ds[0]
242 * Playback DMA2 = playback_con_substream_ds[1]
243 * Playback DMA3 = playback_con_substream_ds[2]
244 * Playback DMA4 (SPDIF) = playback_con_substream
245 * Record DMA0 = capture_pro_substream
246 * Record DMA1 = capture_con_substream
248 unsigned char mtstat = inb(ICEMT1724(ice, IRQ));
249 if (mtstat & VT1724_MULTI_PDMA0) {
250 if (ice->playback_pro_substream)
251 snd_pcm_period_elapsed(ice->playback_pro_substream);
253 if (mtstat & VT1724_MULTI_RDMA0) {
254 if (ice->capture_pro_substream)
255 snd_pcm_period_elapsed(ice->capture_pro_substream);
257 if (mtstat & VT1724_MULTI_PDMA1) {
258 if (ice->playback_con_substream_ds[0])
259 snd_pcm_period_elapsed(ice->playback_con_substream_ds[0]);
261 if (mtstat & VT1724_MULTI_PDMA2) {
262 if (ice->playback_con_substream_ds[1])
263 snd_pcm_period_elapsed(ice->playback_con_substream_ds[1]);
265 if (mtstat & VT1724_MULTI_PDMA3) {
266 if (ice->playback_con_substream_ds[2])
267 snd_pcm_period_elapsed(ice->playback_con_substream_ds[2]);
269 if (mtstat & VT1724_MULTI_PDMA4) {
270 if (ice->playback_con_substream)
271 snd_pcm_period_elapsed(ice->playback_con_substream);
273 if (mtstat & VT1724_MULTI_RDMA1) {
274 if (ice->capture_con_substream)
275 snd_pcm_period_elapsed(ice->capture_con_substream);
277 /* ack anyway to avoid freeze */
278 outb(mtstat, ICEMT1724(ice, IRQ));
279 /* ought to really handle this properly */
280 if (mtstat & VT1724_MULTI_FIFO_ERR) {
281 unsigned char fstat = inb(ICEMT1724(ice, DMA_FIFO_ERR));
282 outb(fstat, ICEMT1724(ice, DMA_FIFO_ERR));
283 outb(VT1724_MULTI_FIFO_ERR | inb(ICEMT1724(ice, DMA_INT_MASK)), ICEMT1724(ice, DMA_INT_MASK));
284 /* If I don't do this, I get machine lockup due to continual interrupts */
289 return IRQ_RETVAL(handled);
293 * PCM code - professional part (multitrack)
296 static unsigned int rates[] = {
297 8000, 9600, 11025, 12000, 16000, 22050, 24000,
298 32000, 44100, 48000, 64000, 88200, 96000,
302 static snd_pcm_hw_constraint_list_t hw_constraints_rates_96 = {
303 .count = ARRAY_SIZE(rates) - 2, /* up to 96000 */
308 static snd_pcm_hw_constraint_list_t hw_constraints_rates_48 = {
309 .count = ARRAY_SIZE(rates) - 5, /* up to 48000 */
314 static snd_pcm_hw_constraint_list_t hw_constraints_rates_192 = {
315 .count = ARRAY_SIZE(rates),
320 static int snd_vt1724_pcm_trigger(snd_pcm_substream_t *substream, int cmd)
322 ice1712_t *ice = snd_pcm_substream_chip(substream);
325 struct list_head *pos;
326 snd_pcm_substream_t *s;
329 snd_pcm_group_for_each(pos, substream) {
330 s = snd_pcm_group_substream_entry(pos);
331 what |= (unsigned long)(s->runtime->private_data);
332 snd_pcm_trigger_done(s, substream);
336 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
337 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
338 spin_lock(&ice->reg_lock);
339 old = inb(ICEMT1724(ice, DMA_PAUSE));
340 if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH)
344 outb(old, ICEMT1724(ice, DMA_PAUSE));
345 spin_unlock(&ice->reg_lock);
348 case SNDRV_PCM_TRIGGER_START:
349 case SNDRV_PCM_TRIGGER_STOP:
350 spin_lock(&ice->reg_lock);
351 old = inb(ICEMT1724(ice, DMA_CONTROL));
352 if (cmd == SNDRV_PCM_TRIGGER_START)
356 outb(old, ICEMT1724(ice, DMA_CONTROL));
357 spin_unlock(&ice->reg_lock);
369 #define DMA_STARTS (VT1724_RDMA0_START|VT1724_PDMA0_START|VT1724_RDMA1_START|\
370 VT1724_PDMA1_START|VT1724_PDMA2_START|VT1724_PDMA3_START|VT1724_PDMA4_START)
371 #define DMA_PAUSES (VT1724_RDMA0_PAUSE|VT1724_PDMA0_PAUSE|VT1724_RDMA1_PAUSE|\
372 VT1724_PDMA1_PAUSE|VT1724_PDMA2_PAUSE|VT1724_PDMA3_PAUSE|VT1724_PDMA4_PAUSE)
374 static void snd_vt1724_set_pro_rate(ice1712_t *ice, unsigned int rate, int force)
377 unsigned char val, old;
380 spin_lock_irqsave(&ice->reg_lock, flags);
381 if ((inb(ICEMT1724(ice, DMA_CONTROL)) & DMA_STARTS) ||
382 (inb(ICEMT1724(ice, DMA_PAUSE)) & DMA_PAUSES)) {
383 /* running? we cannot change the rate now... */
384 spin_unlock_irqrestore(&ice->reg_lock, flags);
387 if (!force && is_pro_rate_locked(ice)) {
388 spin_unlock_irqrestore(&ice->reg_lock, flags);
393 case 8000: val = 6; break;
394 case 9600: val = 3; break;
395 case 11025: val = 10; break;
396 case 12000: val = 2; break;
397 case 16000: val = 5; break;
398 case 22050: val = 9; break;
399 case 24000: val = 1; break;
400 case 32000: val = 4; break;
401 case 44100: val = 8; break;
402 case 48000: val = 0; break;
403 case 64000: val = 15; break;
404 case 88200: val = 11; break;
405 case 96000: val = 7; break;
406 case 176400: val = 12; break;
407 case 192000: val = 14; break;
413 outb(val, ICEMT1724(ice, RATE));
414 if (rate == ice->cur_rate) {
415 spin_unlock_irqrestore(&ice->reg_lock, flags);
419 ice->cur_rate = rate;
422 if (ice->eeprom.data[ICE_EEP2_ACLINK] & 0x80) {
423 val = old = inb(ICEMT1724(ice, I2S_FORMAT));
425 val |= VT1724_MT_I2S_MCLK_128X; /* 128x MCLK */
427 val &= ~VT1724_MT_I2S_MCLK_128X; /* 256x MCLK */
429 outb(val, ICEMT1724(ice, I2S_FORMAT));
430 if (ice->eeprom.subvendor == VT1724_SUBDEVICE_REVOLUTION71) {
431 /* FIXME: is this revo only? */
432 /* assert PRST# to converters; MT05 bit 7 */
433 outb(inb(ICEMT1724(ice, AC97_CMD)) | 0x80, ICEMT1724(ice, AC97_CMD));
434 spin_unlock_irqrestore(&ice->reg_lock, flags);
436 spin_lock_irqsave(&ice->reg_lock, flags);
438 outb(inb(ICEMT1724(ice, AC97_CMD)) & ~0x80, ICEMT1724(ice, AC97_CMD));
442 spin_unlock_irqrestore(&ice->reg_lock, flags);
445 for (i = 0; i < ice->akm_codecs; i++) {
446 if (ice->akm[i].ops.set_rate_val)
447 ice->akm[i].ops.set_rate_val(&ice->akm[i], rate);
450 /* set up AC97 registers if needed */
451 if (! (ice->eeprom.data[ICE_EEP2_ACLINK] & 0x80) && ice->ac97) {
452 snd_ac97_set_rate(ice->ac97, AC97_PCM_FRONT_DAC_RATE, rate);
453 snd_ac97_set_rate(ice->ac97, AC97_PCM_SURR_DAC_RATE, rate);
454 snd_ac97_set_rate(ice->ac97, AC97_PCM_LFE_DAC_RATE, rate);
455 snd_ac97_set_rate(ice->ac97, AC97_SPDIF, rate);
456 snd_ac97_set_rate(ice->ac97, AC97_PCM_LR_ADC_RATE, rate);
460 static int snd_vt1724_pcm_hw_params(snd_pcm_substream_t * substream,
461 snd_pcm_hw_params_t * hw_params)
463 ice1712_t *ice = snd_pcm_substream_chip(substream);
466 chs = params_channels(hw_params);
467 down(&ice->open_mutex);
468 /* mark surround channels */
469 if (substream == ice->playback_pro_substream) {
470 /* PDMA0 can be multi-channel up to 8 */
472 for (i = 0; i < chs; i++) {
473 if (ice->pcm_reserved[i] && ice->pcm_reserved[i] != substream) {
474 up(&ice->open_mutex);
477 ice->pcm_reserved[i] = substream;
480 if (ice->pcm_reserved[i] == substream)
481 ice->pcm_reserved[i] = NULL;
484 for (i = 0; i < 3; i++) {
485 /* check individual playback stream */
486 if (ice->playback_con_substream_ds[i] == substream) {
487 if (ice->pcm_reserved[i] && ice->pcm_reserved[i] != substream) {
488 up(&ice->open_mutex);
491 ice->pcm_reserved[i] = substream;
496 up(&ice->open_mutex);
497 snd_vt1724_set_pro_rate(ice, params_rate(hw_params), 0);
498 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
501 static int snd_vt1724_pcm_hw_free(snd_pcm_substream_t * substream)
503 ice1712_t *ice = snd_pcm_substream_chip(substream);
506 down(&ice->open_mutex);
507 /* unmark surround channels */
508 for (i = 0; i < 3; i++)
509 if (ice->pcm_reserved[i] == substream)
510 ice->pcm_reserved[i] = NULL;
511 up(&ice->open_mutex);
512 return snd_pcm_lib_free_pages(substream);
515 static int snd_vt1724_playback_pro_prepare(snd_pcm_substream_t * substream)
517 ice1712_t *ice = snd_pcm_substream_chip(substream);
521 spin_lock(&ice->reg_lock);
522 val = (8 - substream->runtime->channels) >> 1;
523 outb(val, ICEMT1724(ice, BURST));
525 outl(substream->runtime->dma_addr, ICEMT1724(ice, PLAYBACK_ADDR));
527 size = (snd_pcm_lib_buffer_bytes(substream) >> 2) - 1;
528 // outl(size, ICEMT1724(ice, PLAYBACK_SIZE));
529 outw(size, ICEMT1724(ice, PLAYBACK_SIZE));
530 outb(size >> 16, ICEMT1724(ice, PLAYBACK_SIZE) + 2);
531 size = (snd_pcm_lib_period_bytes(substream) >> 2) - 1;
532 // outl(size, ICEMT1724(ice, PLAYBACK_COUNT));
533 outw(size, ICEMT1724(ice, PLAYBACK_COUNT));
534 outb(size >> 16, ICEMT1724(ice, PLAYBACK_COUNT) + 2);
536 spin_unlock(&ice->reg_lock);
538 // 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));
542 static snd_pcm_uframes_t snd_vt1724_playback_pro_pointer(snd_pcm_substream_t * substream)
544 ice1712_t *ice = snd_pcm_substream_chip(substream);
547 if (!(inl(ICEMT1724(ice, DMA_CONTROL)) & VT1724_PDMA0_START))
549 #if 0 /* read PLAYBACK_ADDR */
550 ptr = inl(ICEMT1724(ice, PLAYBACK_ADDR));
551 if (ptr < substream->runtime->dma_addr) {
552 snd_printd("ice1724: invalid negative ptr\n");
555 ptr -= substream->runtime->dma_addr;
556 ptr = bytes_to_frames(substream->runtime, ptr);
557 if (ptr >= substream->runtime->buffer_size) {
558 snd_printd("ice1724: invalid ptr %d (size=%d)\n", (int)ptr, (int)substream->runtime->period_size);
561 #else /* read PLAYBACK_SIZE */
562 ptr = inl(ICEMT1724(ice, PLAYBACK_SIZE)) & 0xffffff;
563 ptr = (ptr + 1) << 2;
564 ptr = bytes_to_frames(substream->runtime, ptr);
565 if (ptr <= substream->runtime->buffer_size)
566 ptr = substream->runtime->buffer_size - ptr;
568 snd_printd("ice1724: invalid ptr %d (size=%d)\n", (int)ptr, (int)substream->runtime->buffer_size);
575 struct vt1724_pcm_reg {
576 unsigned int addr; /* ADDR register offset */
577 unsigned int size; /* SIZE register offset */
578 unsigned int count; /* COUNT register offset */
579 unsigned int start; /* start bit */
580 unsigned int pause; /* pause bit */
583 static int snd_vt1724_pcm_prepare(snd_pcm_substream_t *substream, const struct vt1724_pcm_reg *reg)
585 ice1712_t *ice = snd_pcm_substream_chip(substream);
587 spin_lock(&ice->reg_lock);
588 outl(substream->runtime->dma_addr, ice->profi_port + reg->addr);
589 outw((snd_pcm_lib_buffer_bytes(substream) >> 2) - 1, ice->profi_port + reg->size);
590 outw((snd_pcm_lib_period_bytes(substream) >> 2) - 1, ice->profi_port + reg->count);
591 spin_unlock(&ice->reg_lock);
595 static snd_pcm_uframes_t snd_vt1724_pcm_pointer(snd_pcm_substream_t *substream, const struct vt1724_pcm_reg *reg)
597 ice1712_t *ice = snd_pcm_substream_chip(substream);
600 if (!(inl(ICEMT1724(ice, DMA_CONTROL)) & reg->start))
602 #if 0 /* use ADDR register */
603 ptr = inl(ice->profi_port + reg->addr);
604 ptr -= substream->runtime->dma_addr;
605 return bytes_to_frames(substream->runtime, ptr);
606 #else /* use SIZE register */
607 ptr = inw(ice->profi_port + reg->size);
608 ptr = (ptr + 1) << 2;
609 ptr = bytes_to_frames(substream->runtime, ptr);
610 if (ptr <= substream->runtime->buffer_size)
611 ptr = substream->runtime->buffer_size - ptr;
613 snd_printd("ice1724: invalid ptr %d (size=%d)\n", (int)ptr, (int)substream->runtime->buffer_size);
620 const static struct vt1724_pcm_reg vt1724_capture_pro_reg = {
621 .addr = VT1724_MT_CAPTURE_ADDR,
622 .size = VT1724_MT_CAPTURE_SIZE,
623 .count = VT1724_MT_CAPTURE_COUNT,
624 .start = VT1724_RDMA0_START,
625 .pause = VT1724_RDMA0_PAUSE,
628 static int snd_vt1724_capture_pro_prepare(snd_pcm_substream_t * substream)
630 return snd_vt1724_pcm_prepare(substream, &vt1724_capture_pro_reg);
633 static snd_pcm_uframes_t snd_vt1724_capture_pro_pointer(snd_pcm_substream_t * substream)
635 return snd_vt1724_pcm_pointer(substream, &vt1724_capture_pro_reg);
638 static snd_pcm_hardware_t snd_vt1724_playback_pro =
640 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
641 SNDRV_PCM_INFO_BLOCK_TRANSFER |
642 SNDRV_PCM_INFO_MMAP_VALID |
643 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START),
644 .formats = SNDRV_PCM_FMTBIT_S32_LE,
645 .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_192000,
650 .buffer_bytes_max = (1UL << 21), /* 19bits dword */
651 .period_bytes_min = 8 * 4 * 2, /* FIXME: constraints needed */
652 .period_bytes_max = (1UL << 21),
657 static snd_pcm_hardware_t snd_vt1724_spdif =
659 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
660 SNDRV_PCM_INFO_BLOCK_TRANSFER |
661 SNDRV_PCM_INFO_MMAP_VALID |
662 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START),
663 .formats = SNDRV_PCM_FMTBIT_S32_LE,
664 .rates = SNDRV_PCM_RATE_32000|SNDRV_PCM_RATE_44100|SNDRV_PCM_RATE_48000,
669 .buffer_bytes_max = (1UL << 18), /* 16bits dword */
670 .period_bytes_min = 2 * 4 * 2,
671 .period_bytes_max = (1UL << 18),
676 static snd_pcm_hardware_t snd_vt1724_2ch_stereo =
678 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
679 SNDRV_PCM_INFO_BLOCK_TRANSFER |
680 SNDRV_PCM_INFO_MMAP_VALID |
681 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START),
682 .formats = SNDRV_PCM_FMTBIT_S32_LE,
683 .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_192000,
688 .buffer_bytes_max = (1UL << 18), /* 16bits dword */
689 .period_bytes_min = 2 * 4 * 2,
690 .period_bytes_max = (1UL << 18),
696 * set rate constraints
698 static int set_rate_constraints(ice1712_t *ice, snd_pcm_substream_t *substream)
700 snd_pcm_runtime_t *runtime = substream->runtime;
701 if (ice->eeprom.data[ICE_EEP2_ACLINK] & 0x80) {
703 if (ice->eeprom.data[ICE_EEP2_I2S] & 0x08)
704 return snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates_192);
706 runtime->hw.rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_96000;
707 runtime->hw.rate_max = 96000;
708 return snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates_96);
710 } else if (ice->ac97) {
713 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
714 ratec = AC97_RATES_FRONT_DAC;
716 ratec = AC97_RATES_ADC;
717 runtime->hw.rates = ice->ac97->rates[ratec];
718 runtime->hw.rate_max = 48000;
719 if (runtime->hw.rates == SNDRV_PCM_RATE_48000) {
720 runtime->hw.rate_min = 48000;
723 runtime->hw.rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000;
724 return snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates_48);
730 /* multi-channel playback needs alignment 8x32bit regarless of the channels
733 #define VT1724_BUFFER_ALIGN 0x20
735 static int snd_vt1724_playback_pro_open(snd_pcm_substream_t * substream)
737 snd_pcm_runtime_t *runtime = substream->runtime;
738 ice1712_t *ice = snd_pcm_substream_chip(substream);
741 runtime->private_data = (void*)VT1724_PDMA0_START; /* irq/status/trigger bit */
742 ice->playback_pro_substream = substream;
743 runtime->hw = snd_vt1724_playback_pro;
744 snd_pcm_set_sync(substream);
745 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
746 set_rate_constraints(ice, substream);
747 down(&ice->open_mutex);
748 /* calculate the currently available channels */
749 for (chs = 0; chs < 3; chs++) {
750 if (ice->pcm_reserved[chs])
754 runtime->hw.channels_max = chs;
755 if (chs > 2) /* channels must be even */
756 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, 2);
757 up(&ice->open_mutex);
758 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
759 VT1724_BUFFER_ALIGN);
760 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
761 VT1724_BUFFER_ALIGN);
765 static int snd_vt1724_capture_pro_open(snd_pcm_substream_t * substream)
767 ice1712_t *ice = snd_pcm_substream_chip(substream);
768 snd_pcm_runtime_t *runtime = substream->runtime;
770 runtime->private_data = (void*)VT1724_RDMA0_START; /* irq/status/trigger bit */
771 ice->capture_pro_substream = substream;
772 runtime->hw = snd_vt1724_2ch_stereo;
773 snd_pcm_set_sync(substream);
774 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
775 set_rate_constraints(ice, substream);
779 static int snd_vt1724_playback_pro_close(snd_pcm_substream_t * substream)
781 ice1712_t *ice = snd_pcm_substream_chip(substream);
784 snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
785 ice->playback_pro_substream = NULL;
790 static int snd_vt1724_capture_pro_close(snd_pcm_substream_t * substream)
792 ice1712_t *ice = snd_pcm_substream_chip(substream);
795 snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
796 ice->capture_pro_substream = NULL;
800 static snd_pcm_ops_t snd_vt1724_playback_pro_ops = {
801 .open = snd_vt1724_playback_pro_open,
802 .close = snd_vt1724_playback_pro_close,
803 .ioctl = snd_pcm_lib_ioctl,
804 .hw_params = snd_vt1724_pcm_hw_params,
805 .hw_free = snd_vt1724_pcm_hw_free,
806 .prepare = snd_vt1724_playback_pro_prepare,
807 .trigger = snd_vt1724_pcm_trigger,
808 .pointer = snd_vt1724_playback_pro_pointer,
811 static snd_pcm_ops_t snd_vt1724_capture_pro_ops = {
812 .open = snd_vt1724_capture_pro_open,
813 .close = snd_vt1724_capture_pro_close,
814 .ioctl = snd_pcm_lib_ioctl,
815 .hw_params = snd_vt1724_pcm_hw_params,
816 .hw_free = snd_vt1724_pcm_hw_free,
817 .prepare = snd_vt1724_capture_pro_prepare,
818 .trigger = snd_vt1724_pcm_trigger,
819 .pointer = snd_vt1724_capture_pro_pointer,
822 static int __devinit snd_vt1724_pcm_profi(ice1712_t * ice, int device)
827 err = snd_pcm_new(ice->card, "ICE1724", device, 1, 1, &pcm);
831 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_vt1724_playback_pro_ops);
832 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_vt1724_capture_pro_ops);
834 pcm->private_data = ice;
836 strcpy(pcm->name, "ICE1724");
838 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
839 snd_dma_pci_data(ice->pci), 256*1024, 256*1024);
851 const static struct vt1724_pcm_reg vt1724_playback_spdif_reg = {
852 .addr = VT1724_MT_PDMA4_ADDR,
853 .size = VT1724_MT_PDMA4_SIZE,
854 .count = VT1724_MT_PDMA4_COUNT,
855 .start = VT1724_PDMA4_START,
856 .pause = VT1724_PDMA4_PAUSE,
859 const static struct vt1724_pcm_reg vt1724_capture_spdif_reg = {
860 .addr = VT1724_MT_RDMA1_ADDR,
861 .size = VT1724_MT_RDMA1_SIZE,
862 .count = VT1724_MT_RDMA1_COUNT,
863 .start = VT1724_RDMA1_START,
864 .pause = VT1724_RDMA1_PAUSE,
867 static int snd_vt1724_playback_spdif_prepare(snd_pcm_substream_t * substream)
869 return snd_vt1724_pcm_prepare(substream, &vt1724_playback_spdif_reg);
872 static snd_pcm_uframes_t snd_vt1724_playback_spdif_pointer(snd_pcm_substream_t * substream)
874 return snd_vt1724_pcm_pointer(substream, &vt1724_playback_spdif_reg);
877 static int snd_vt1724_capture_spdif_prepare(snd_pcm_substream_t * substream)
879 return snd_vt1724_pcm_prepare(substream, &vt1724_capture_spdif_reg);
882 static snd_pcm_uframes_t snd_vt1724_capture_spdif_pointer(snd_pcm_substream_t * substream)
884 return snd_vt1724_pcm_pointer(substream, &vt1724_capture_spdif_reg);
887 static int snd_vt1724_playback_spdif_open(snd_pcm_substream_t *substream)
889 ice1712_t *ice = snd_pcm_substream_chip(substream);
890 snd_pcm_runtime_t *runtime = substream->runtime;
892 runtime->private_data = (void*)VT1724_PDMA4_START; /* irq/status/trigger bit */
893 ice->playback_con_substream = substream;
894 if (ice->force_pdma4) {
895 runtime->hw = snd_vt1724_2ch_stereo;
896 set_rate_constraints(ice, substream);
898 runtime->hw = snd_vt1724_spdif;
899 snd_pcm_set_sync(substream);
900 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
904 static int snd_vt1724_playback_spdif_close(snd_pcm_substream_t * substream)
906 ice1712_t *ice = snd_pcm_substream_chip(substream);
909 snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
910 ice->playback_con_substream = NULL;
915 static int snd_vt1724_capture_spdif_open(snd_pcm_substream_t *substream)
917 ice1712_t *ice = snd_pcm_substream_chip(substream);
918 snd_pcm_runtime_t *runtime = substream->runtime;
920 runtime->private_data = (void*)VT1724_RDMA1_START; /* irq/status/trigger bit */
921 ice->capture_con_substream = substream;
922 if (ice->force_rdma1) {
923 runtime->hw = snd_vt1724_2ch_stereo;
924 set_rate_constraints(ice, substream);
926 runtime->hw = snd_vt1724_spdif;
927 snd_pcm_set_sync(substream);
928 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
932 static int snd_vt1724_capture_spdif_close(snd_pcm_substream_t * substream)
934 ice1712_t *ice = snd_pcm_substream_chip(substream);
937 snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
938 ice->capture_con_substream = NULL;
943 static snd_pcm_ops_t snd_vt1724_playback_spdif_ops = {
944 .open = snd_vt1724_playback_spdif_open,
945 .close = snd_vt1724_playback_spdif_close,
946 .ioctl = snd_pcm_lib_ioctl,
947 .hw_params = snd_vt1724_pcm_hw_params,
948 .hw_free = snd_vt1724_pcm_hw_free,
949 .prepare = snd_vt1724_playback_spdif_prepare,
950 .trigger = snd_vt1724_pcm_trigger,
951 .pointer = snd_vt1724_playback_spdif_pointer,
954 static snd_pcm_ops_t snd_vt1724_capture_spdif_ops = {
955 .open = snd_vt1724_capture_spdif_open,
956 .close = snd_vt1724_capture_spdif_close,
957 .ioctl = snd_pcm_lib_ioctl,
958 .hw_params = snd_vt1724_pcm_hw_params,
959 .hw_free = snd_vt1724_pcm_hw_free,
960 .prepare = snd_vt1724_capture_spdif_prepare,
961 .trigger = snd_vt1724_pcm_trigger,
962 .pointer = snd_vt1724_capture_spdif_pointer,
966 static int __devinit snd_vt1724_pcm_spdif(ice1712_t * ice, int device)
973 if (ice->force_pdma4 ||
974 (ice->eeprom.data[ICE_EEP2_SPDIF] & VT1724_CFG_SPDIF_OUT_INT)) {
979 if (ice->force_rdma1 ||
980 (ice->eeprom.data[ICE_EEP2_SPDIF] & VT1724_CFG_SPDIF_IN)) {
985 if (! play && ! capt)
986 return 0; /* no spdif device */
988 if (ice->force_pdma4 || ice->force_rdma1)
989 name = "ICE1724 Secondary";
991 name = "IEC1724 IEC958";
992 err = snd_pcm_new(ice->card, name, device, play, capt, &pcm);
997 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
998 &snd_vt1724_playback_spdif_ops);
1000 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
1001 &snd_vt1724_capture_spdif_ops);
1003 pcm->private_data = ice;
1004 pcm->info_flags = 0;
1005 strcpy(pcm->name, name);
1007 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
1008 snd_dma_pci_data(ice->pci), 64*1024, 64*1024);
1017 * independent surround PCMs
1020 const static struct vt1724_pcm_reg vt1724_playback_dma_regs[3] = {
1022 .addr = VT1724_MT_PDMA1_ADDR,
1023 .size = VT1724_MT_PDMA1_SIZE,
1024 .count = VT1724_MT_PDMA1_COUNT,
1025 .start = VT1724_PDMA1_START,
1026 .pause = VT1724_PDMA1_PAUSE,
1029 .addr = VT1724_MT_PDMA2_ADDR,
1030 .size = VT1724_MT_PDMA2_SIZE,
1031 .count = VT1724_MT_PDMA2_COUNT,
1032 .start = VT1724_PDMA2_START,
1033 .pause = VT1724_PDMA2_PAUSE,
1036 .addr = VT1724_MT_PDMA3_ADDR,
1037 .size = VT1724_MT_PDMA3_SIZE,
1038 .count = VT1724_MT_PDMA3_COUNT,
1039 .start = VT1724_PDMA3_START,
1040 .pause = VT1724_PDMA3_PAUSE,
1044 static int snd_vt1724_playback_indep_prepare(snd_pcm_substream_t * substream)
1046 ice1712_t *ice = snd_pcm_substream_chip(substream);
1049 spin_lock(&ice->reg_lock);
1050 val = 3 - substream->number;
1051 if (inb(ICEMT1724(ice, BURST)) < val)
1052 outb(val, ICEMT1724(ice, BURST));
1053 spin_unlock(&ice->reg_lock);
1054 return snd_vt1724_pcm_prepare(substream, &vt1724_playback_dma_regs[substream->number]);
1057 static snd_pcm_uframes_t snd_vt1724_playback_indep_pointer(snd_pcm_substream_t * substream)
1059 return snd_vt1724_pcm_pointer(substream, &vt1724_playback_dma_regs[substream->number]);
1062 static int snd_vt1724_playback_indep_open(snd_pcm_substream_t *substream)
1064 ice1712_t *ice = snd_pcm_substream_chip(substream);
1065 snd_pcm_runtime_t *runtime = substream->runtime;
1067 down(&ice->open_mutex);
1068 /* already used by PDMA0? */
1069 if (ice->pcm_reserved[substream->number]) {
1070 up(&ice->open_mutex);
1071 return -EBUSY; /* FIXME: should handle blocking mode properly */
1073 up(&ice->open_mutex);
1074 runtime->private_data = (void*)(1 << (substream->number + 4));
1075 ice->playback_con_substream_ds[substream->number] = substream;
1076 runtime->hw = snd_vt1724_2ch_stereo;
1077 snd_pcm_set_sync(substream);
1078 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
1079 set_rate_constraints(ice, substream);
1083 static int snd_vt1724_playback_indep_close(snd_pcm_substream_t * substream)
1085 ice1712_t *ice = snd_pcm_substream_chip(substream);
1088 snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
1089 ice->playback_con_substream_ds[substream->number] = NULL;
1090 ice->pcm_reserved[substream->number] = NULL;
1095 static snd_pcm_ops_t snd_vt1724_playback_indep_ops = {
1096 .open = snd_vt1724_playback_indep_open,
1097 .close = snd_vt1724_playback_indep_close,
1098 .ioctl = snd_pcm_lib_ioctl,
1099 .hw_params = snd_vt1724_pcm_hw_params,
1100 .hw_free = snd_vt1724_pcm_hw_free,
1101 .prepare = snd_vt1724_playback_indep_prepare,
1102 .trigger = snd_vt1724_pcm_trigger,
1103 .pointer = snd_vt1724_playback_indep_pointer,
1107 static int __devinit snd_vt1724_pcm_indep(ice1712_t * ice, int device)
1113 play = ice->num_total_dacs / 2 - 1;
1117 err = snd_pcm_new(ice->card, "ICE1724 Surrounds", device, play, 0, &pcm);
1121 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
1122 &snd_vt1724_playback_indep_ops);
1124 pcm->private_data = ice;
1125 pcm->info_flags = 0;
1126 strcpy(pcm->name, "ICE1724 Surround PCM");
1128 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
1129 snd_dma_pci_data(ice->pci), 64*1024, 64*1024);
1141 static int __devinit snd_vt1724_ac97_mixer(ice1712_t * ice)
1145 if (! (ice->eeprom.data[ICE_EEP2_ACLINK] & VT1724_CFG_PRO_I2S)) {
1146 ac97_bus_t bus, *pbus;
1149 outb(inb(ICEMT1724(ice, AC97_CMD)) | 0x80, ICEMT1724(ice, AC97_CMD));
1150 mdelay(5); /* FIXME */
1151 outb(inb(ICEMT1724(ice, AC97_CMD)) & ~0x80, ICEMT1724(ice, AC97_CMD));
1153 memset(&bus, 0, sizeof(bus));
1154 bus.write = snd_vt1724_ac97_write;
1155 bus.read = snd_vt1724_ac97_read;
1156 if ((err = snd_ac97_bus(ice->card, &bus, &pbus)) < 0)
1158 memset(&ac97, 0, sizeof(ac97));
1159 ac97.private_data = ice;
1160 if ((err = snd_ac97_mixer(pbus, &ac97, &ice->ac97)) < 0)
1161 printk(KERN_WARNING "ice1712: cannot initialize pro ac97, skipped\n");
1165 /* I2S mixer only */
1166 strcat(ice->card->mixername, "ICE1724 - multitrack");
1174 static inline unsigned int eeprom_triple(ice1712_t *ice, int idx)
1176 return (unsigned int)ice->eeprom.data[idx] | \
1177 ((unsigned int)ice->eeprom.data[idx + 1] << 8) | \
1178 ((unsigned int)ice->eeprom.data[idx + 2] << 16);
1181 static void snd_vt1724_proc_read(snd_info_entry_t *entry,
1182 snd_info_buffer_t * buffer)
1184 ice1712_t *ice = snd_magic_cast(ice1712_t, entry->private_data, return);
1187 snd_iprintf(buffer, "%s\n\n", ice->card->longname);
1188 snd_iprintf(buffer, "EEPROM:\n");
1190 snd_iprintf(buffer, " Subvendor : 0x%x\n", ice->eeprom.subvendor);
1191 snd_iprintf(buffer, " Size : %i bytes\n", ice->eeprom.size);
1192 snd_iprintf(buffer, " Version : %i\n", ice->eeprom.version);
1193 snd_iprintf(buffer, " System Config : 0x%x\n", ice->eeprom.data[ICE_EEP2_SYSCONF]);
1194 snd_iprintf(buffer, " ACLink : 0x%x\n", ice->eeprom.data[ICE_EEP2_ACLINK]);
1195 snd_iprintf(buffer, " I2S : 0x%x\n", ice->eeprom.data[ICE_EEP2_I2S]);
1196 snd_iprintf(buffer, " S/PDIF : 0x%x\n", ice->eeprom.data[ICE_EEP2_SPDIF]);
1197 snd_iprintf(buffer, " GPIO direction : 0x%x\n", ice->eeprom.gpiodir);
1198 snd_iprintf(buffer, " GPIO mask : 0x%x\n", ice->eeprom.gpiomask);
1199 snd_iprintf(buffer, " GPIO state : 0x%x\n", ice->eeprom.gpiostate);
1200 for (idx = 0x12; idx < ice->eeprom.size; idx++)
1201 snd_iprintf(buffer, " Extra #%02i : 0x%x\n", idx, ice->eeprom.data[idx]);
1203 snd_iprintf(buffer, "\nRegisters:\n");
1205 snd_iprintf(buffer, " PSDOUT03 : 0x%08x\n", (unsigned)inl(ICEMT1724(ice, ROUTE_PLAYBACK)));
1206 for (idx = 0x0; idx < 0x20 ; idx++)
1207 snd_iprintf(buffer, " CCS%02x : 0x%02x\n", idx, inb(ice->port+idx));
1208 for (idx = 0x0; idx < 0x30 ; idx++)
1209 snd_iprintf(buffer, " MT%02x : 0x%02x\n", idx, inb(ice->profi_port+idx));
1212 static void __devinit snd_vt1724_proc_init(ice1712_t * ice)
1214 snd_info_entry_t *entry;
1216 if (! snd_card_proc_new(ice->card, "ice1724", &entry))
1217 snd_info_set_text_ops(entry, ice, 1024, snd_vt1724_proc_read);
1224 static int snd_vt1724_eeprom_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1226 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
1227 uinfo->count = sizeof(ice1712_eeprom_t);
1231 static int snd_vt1724_eeprom_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1233 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1235 memcpy(ucontrol->value.bytes.data, &ice->eeprom, sizeof(ice->eeprom));
1239 static snd_kcontrol_new_t snd_vt1724_eeprom __devinitdata = {
1240 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1241 .name = "ICE1724 EEPROM",
1242 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1243 .info = snd_vt1724_eeprom_info,
1244 .get = snd_vt1724_eeprom_get
1249 static int snd_vt1724_spdif_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1251 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1256 static unsigned int encode_spdif_bits(snd_aes_iec958_t *diga)
1260 val = diga->status[0] & 0x03; /* professional, non-audio */
1263 if ((diga->status[0] & IEC958_AES0_PRO_EMPHASIS) == IEC958_AES0_PRO_EMPHASIS_5015)
1265 switch (diga->status[0] & IEC958_AES0_PRO_FS) {
1266 case IEC958_AES0_PRO_FS_44100:
1268 case IEC958_AES0_PRO_FS_32000:
1277 val |= diga->status[0] & 0x04; /* copyright */
1278 if ((diga->status[0] & IEC958_AES0_CON_EMPHASIS)== IEC958_AES0_CON_EMPHASIS_5015)
1280 val |= (unsigned int)(diga->status[1] & 0x3f) << 4; /* category */
1281 val |= (unsigned int)(diga->status[3] & IEC958_AES3_CON_FS) << 12; /* fs */
1286 static void decode_spdif_bits(snd_aes_iec958_t *diga, unsigned int val)
1288 memset(diga->status, 0, sizeof(diga->status));
1289 diga->status[0] = val & 0x03; /* professional, non-audio */
1292 if (val & (1U << 3))
1293 diga->status[0] |= IEC958_AES0_PRO_EMPHASIS_5015;
1294 switch ((val >> 12) & 0x7) {
1298 diga->status[0] |= IEC958_AES0_PRO_FS_32000;
1301 diga->status[0] |= IEC958_AES0_PRO_FS_48000;
1306 diga->status[0] |= val & (1U << 2); /* copyright */
1307 if (val & (1U << 3))
1308 diga->status[0] |= IEC958_AES0_CON_EMPHASIS_5015;
1309 diga->status[1] |= (val >> 4) & 0x3f; /* category */
1310 diga->status[3] |= (val >> 12) & 0x07; /* fs */
1314 static int snd_vt1724_spdif_default_get(snd_kcontrol_t * kcontrol,
1315 snd_ctl_elem_value_t * ucontrol)
1317 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1319 val = inw(ICEMT1724(ice, SPDIF_CTRL));
1320 decode_spdif_bits(&ucontrol->value.iec958, val);
1324 static int snd_vt1724_spdif_default_put(snd_kcontrol_t * kcontrol,
1325 snd_ctl_elem_value_t * ucontrol)
1327 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1328 unsigned int val, old;
1329 unsigned long flags;
1331 val = encode_spdif_bits(&ucontrol->value.iec958);
1332 spin_lock_irqsave(&ice->reg_lock, flags);
1333 old = inw(ICEMT1724(ice, SPDIF_CTRL));
1335 unsigned char cbit, disabled;
1336 cbit = inb(ICEREG1724(ice, SPDIF_CFG));
1337 disabled = cbit & ~VT1724_CFG_SPDIF_OUT_EN;
1338 if (cbit != disabled)
1339 outb(disabled, ICEREG1724(ice, SPDIF_CFG));
1340 outw(val, ICEMT1724(ice, SPDIF_CTRL));
1341 if (cbit != disabled)
1342 outb(cbit, ICEREG1724(ice, SPDIF_CFG));
1344 spin_unlock_irqrestore(&ice->reg_lock, flags);
1345 return (val != old);
1348 static snd_kcontrol_new_t snd_vt1724_spdif_default __devinitdata =
1350 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1351 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
1352 .info = snd_vt1724_spdif_info,
1353 .get = snd_vt1724_spdif_default_get,
1354 .put = snd_vt1724_spdif_default_put
1357 static int snd_vt1724_spdif_maskc_get(snd_kcontrol_t * kcontrol,
1358 snd_ctl_elem_value_t * ucontrol)
1360 ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO |
1361 IEC958_AES0_PROFESSIONAL |
1362 IEC958_AES0_CON_NOT_COPYRIGHT |
1363 IEC958_AES0_CON_EMPHASIS;
1364 ucontrol->value.iec958.status[1] = IEC958_AES1_CON_ORIGINAL |
1365 IEC958_AES1_CON_CATEGORY;
1366 ucontrol->value.iec958.status[3] = IEC958_AES3_CON_FS;
1370 static int snd_vt1724_spdif_maskp_get(snd_kcontrol_t * kcontrol,
1371 snd_ctl_elem_value_t * ucontrol)
1373 ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO |
1374 IEC958_AES0_PROFESSIONAL |
1375 IEC958_AES0_PRO_FS |
1376 IEC958_AES0_PRO_EMPHASIS;
1380 static snd_kcontrol_new_t snd_vt1724_spdif_maskc __devinitdata =
1382 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1383 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1384 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,CON_MASK),
1385 .info = snd_vt1724_spdif_info,
1386 .get = snd_vt1724_spdif_maskc_get,
1389 static snd_kcontrol_new_t snd_vt1724_spdif_maskp __devinitdata =
1391 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1392 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1393 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PRO_MASK),
1394 .info = snd_vt1724_spdif_info,
1395 .get = snd_vt1724_spdif_maskp_get,
1398 static int snd_vt1724_spdif_sw_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1400 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1402 uinfo->value.integer.min = 0;
1403 uinfo->value.integer.max = 1;
1407 static int snd_vt1724_spdif_sw_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1409 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1410 ucontrol->value.integer.value[0] = inb(ICEREG1724(ice, SPDIF_CFG)) & VT1724_CFG_SPDIF_OUT_EN ? 1 : 0;
1414 static int snd_vt1724_spdif_sw_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1416 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1417 unsigned char old, val;
1418 unsigned long flags;
1419 spin_lock_irqsave(&ice->reg_lock, flags);
1420 old = val = inb(ICEREG1724(ice, SPDIF_CFG));
1421 val &= ~VT1724_CFG_SPDIF_OUT_EN;
1422 if (ucontrol->value.integer.value[0])
1423 val |= VT1724_CFG_SPDIF_OUT_EN;
1425 outb(val, ICEREG1724(ice, SPDIF_CFG));
1426 spin_unlock_irqrestore(&ice->reg_lock, flags);
1430 static snd_kcontrol_new_t snd_vt1724_spdif_switch __devinitdata =
1432 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1433 /* FIXME: the following conflict with IEC958 Playback Route */
1434 // .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH),
1435 .name = "IEC958 Output Switch",
1436 .info = snd_vt1724_spdif_sw_info,
1437 .get = snd_vt1724_spdif_sw_get,
1438 .put = snd_vt1724_spdif_sw_put
1442 #if 0 /* NOT USED YET */
1444 * GPIO access from extern
1447 int snd_vt1724_gpio_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1449 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1451 uinfo->value.integer.min = 0;
1452 uinfo->value.integer.max = 1;
1456 int snd_vt1724_gpio_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1458 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1459 int shift = kcontrol->private_value & 0xff;
1460 int invert = (kcontrol->private_value & (1<<24)) ? 1 : 0;
1462 snd_ice1712_save_gpio_status(ice);
1463 ucontrol->value.integer.value[0] = (snd_ice1712_gpio_read(ice) & (1 << shift) ? 1 : 0) ^ invert;
1464 snd_ice1712_restore_gpio_status(ice);
1468 int snd_ice1712_gpio_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1470 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1471 int shift = kcontrol->private_value & 0xff;
1472 int invert = (kcontrol->private_value & (1<<24)) ? mask : 0;
1473 unsigned int val, nval;
1475 if (kcontrol->private_value & (1 << 31))
1477 nval = (ucontrol->value.integer.value[0] ? (1 << shift) : 0) ^ invert;
1478 snd_ice1712_save_gpio_status(ice);
1479 val = snd_ice1712_gpio_read(ice);
1480 nval |= val & ~(1 << shift);
1482 snd_ice1712_gpio_write(ice, nval);
1483 snd_ice1712_restore_gpio_status(ice);
1486 #endif /* NOT USED YET */
1491 static int snd_vt1724_pro_internal_clock_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1493 static char *texts[] = {
1496 "11025", /* 2: 10 */
1504 "64000", /* 10: 15 */
1505 "88200", /* 11: 11 */
1506 "96000", /* 12: 7 */
1507 "176400", /* 13: 12 */
1508 "192000", /* 14: 14 */
1509 "IEC958 Input", /* 15: -- */
1511 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1513 uinfo->value.enumerated.items = 16;
1514 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1515 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1516 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1520 static int snd_vt1724_pro_internal_clock_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1522 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1523 static unsigned char xlate[16] = {
1524 9, 6, 3, 1, 7, 4, 0, 12, 8, 5, 2, 11, 13, 255, 14, 10
1528 spin_lock_irq(&ice->reg_lock);
1529 if (is_spdif_master(ice)) {
1530 ucontrol->value.enumerated.item[0] = 15;
1532 val = xlate[inb(ICEMT1724(ice, RATE)) & 15];
1537 ucontrol->value.enumerated.item[0] = val;
1539 spin_unlock_irq(&ice->reg_lock);
1543 static int snd_vt1724_pro_internal_clock_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1545 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1549 spin_lock_irq(&ice->reg_lock);
1550 oval = inb(ICEMT1724(ice, RATE));
1551 if (ucontrol->value.enumerated.item[0] == 15) {
1552 outb(oval | VT1724_SPDIF_MASTER, ICEMT1724(ice, RATE));
1554 PRO_RATE_DEFAULT = rates[ucontrol->value.integer.value[0] % 15];
1555 spin_unlock_irq(&ice->reg_lock);
1556 snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 1);
1557 spin_lock_irq(&ice->reg_lock);
1559 change = inb(ICEMT1724(ice, RATE)) != oval;
1560 spin_unlock_irq(&ice->reg_lock);
1562 if ((oval & VT1724_SPDIF_MASTER) != (inb(ICEMT1724(ice, RATE)) & VT1724_SPDIF_MASTER)) {
1563 /* notify akm chips as well */
1564 if (is_spdif_master(ice)) {
1566 for (i = 0; i < ice->akm_codecs; i++) {
1567 if (ice->akm[i].ops.set_rate_val)
1568 ice->akm[i].ops.set_rate_val(&ice->akm[i], 0);
1575 static snd_kcontrol_new_t snd_vt1724_pro_internal_clock __devinitdata = {
1576 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1577 .name = "Multi Track Internal Clock",
1578 .info = snd_vt1724_pro_internal_clock_info,
1579 .get = snd_vt1724_pro_internal_clock_get,
1580 .put = snd_vt1724_pro_internal_clock_put
1583 static int snd_vt1724_pro_rate_locking_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1585 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1587 uinfo->value.integer.min = 0;
1588 uinfo->value.integer.max = 1;
1592 static int snd_vt1724_pro_rate_locking_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1594 ucontrol->value.integer.value[0] = PRO_RATE_LOCKED;
1598 static int snd_vt1724_pro_rate_locking_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1600 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1601 int change = 0, nval;
1603 nval = ucontrol->value.integer.value[0] ? 1 : 0;
1604 spin_lock_irq(&ice->reg_lock);
1605 change = PRO_RATE_LOCKED != nval;
1606 PRO_RATE_LOCKED = nval;
1607 spin_unlock_irq(&ice->reg_lock);
1611 static snd_kcontrol_new_t snd_vt1724_pro_rate_locking __devinitdata = {
1612 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1613 .name = "Multi Track Rate Locking",
1614 .info = snd_vt1724_pro_rate_locking_info,
1615 .get = snd_vt1724_pro_rate_locking_get,
1616 .put = snd_vt1724_pro_rate_locking_put
1619 static int snd_vt1724_pro_rate_reset_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1621 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1623 uinfo->value.integer.min = 0;
1624 uinfo->value.integer.max = 1;
1628 static int snd_vt1724_pro_rate_reset_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1630 ucontrol->value.integer.value[0] = PRO_RATE_RESET ? 1 : 0;
1634 static int snd_vt1724_pro_rate_reset_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1636 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1637 int change = 0, nval;
1639 nval = ucontrol->value.integer.value[0] ? 1 : 0;
1640 spin_lock_irq(&ice->reg_lock);
1641 change = PRO_RATE_RESET != nval;
1642 PRO_RATE_RESET = nval;
1643 spin_unlock_irq(&ice->reg_lock);
1647 static snd_kcontrol_new_t snd_vt1724_pro_rate_reset __devinitdata = {
1648 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1649 .name = "Multi Track Rate Reset",
1650 .info = snd_vt1724_pro_rate_reset_info,
1651 .get = snd_vt1724_pro_rate_reset_get,
1652 .put = snd_vt1724_pro_rate_reset_put
1659 static int snd_vt1724_pro_route_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1661 static char *texts[] = {
1663 "H/W In 0", "H/W In 1", /* 1-2 */
1664 "IEC958 In L", "IEC958 In R", /* 3-4 */
1667 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1669 uinfo->value.enumerated.items = 5;
1670 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1671 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1672 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1676 static inline int analog_route_shift(int idx)
1678 return (idx % 2) * 12 + ((idx / 2) * 3) + 8;
1681 static inline int digital_route_shift(int idx)
1686 static int get_route_val(ice1712_t *ice, int shift)
1689 unsigned char eitem;
1690 static unsigned char xlate[8] = {
1691 0, 255, 1, 2, 255, 255, 3, 4,
1694 val = inl(ICEMT1724(ice, ROUTE_PLAYBACK));
1696 val &= 7; //we now have 3 bits per output
1705 static int put_route_val(ice1712_t *ice, unsigned int val, int shift)
1707 unsigned int old_val, nval;
1709 static unsigned char xroute[8] = {
1711 2, /* PSDIN0 Left */
1712 3, /* PSDIN0 Right */
1714 7, /* SPDIN Right */
1717 nval = xroute[val % 5];
1718 val = old_val = inl(ICEMT1724(ice, ROUTE_PLAYBACK));
1719 val &= ~(0x07 << shift);
1720 val |= nval << shift;
1721 change = val != old_val;
1723 outl(val, ICEMT1724(ice, ROUTE_PLAYBACK));
1727 static int snd_vt1724_pro_route_analog_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)
1729 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1730 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1731 ucontrol->value.enumerated.item[0] = get_route_val(ice, analog_route_shift(idx));
1735 static int snd_vt1724_pro_route_analog_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)
1737 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1738 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1739 return put_route_val(ice, ucontrol->value.enumerated.item[0],
1740 analog_route_shift(idx));
1743 static int snd_vt1724_pro_route_spdif_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)
1745 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1746 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1747 ucontrol->value.enumerated.item[0] = get_route_val(ice, digital_route_shift(idx));
1751 static int snd_vt1724_pro_route_spdif_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)
1753 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1754 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1755 return put_route_val(ice, ucontrol->value.enumerated.item[0],
1756 digital_route_shift(idx));
1759 static snd_kcontrol_new_t snd_vt1724_mixer_pro_analog_route __devinitdata = {
1760 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1761 .name = "H/W Playback Route",
1762 .info = snd_vt1724_pro_route_info,
1763 .get = snd_vt1724_pro_route_analog_get,
1764 .put = snd_vt1724_pro_route_analog_put,
1767 static snd_kcontrol_new_t snd_vt1724_mixer_pro_spdif_route __devinitdata = {
1768 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1769 .name = "IEC958 Playback Route",
1770 .info = snd_vt1724_pro_route_info,
1771 .get = snd_vt1724_pro_route_spdif_get,
1772 .put = snd_vt1724_pro_route_spdif_put,
1777 static int snd_vt1724_pro_peak_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1779 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1780 uinfo->count = 22; /* FIXME: for compatibility with ice1712... */
1781 uinfo->value.integer.min = 0;
1782 uinfo->value.integer.max = 255;
1786 static int snd_vt1724_pro_peak_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1788 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1791 spin_lock_irq(&ice->reg_lock);
1792 for (idx = 0; idx < 22; idx++) {
1793 outb(idx, ICEMT1724(ice, MONITOR_PEAKINDEX));
1794 ucontrol->value.integer.value[idx] = inb(ICEMT1724(ice, MONITOR_PEAKDATA));
1796 spin_unlock_irq(&ice->reg_lock);
1800 static snd_kcontrol_new_t snd_vt1724_mixer_pro_peak __devinitdata = {
1801 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1802 .name = "Multi Track Peak",
1803 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
1804 .info = snd_vt1724_pro_peak_info,
1805 .get = snd_vt1724_pro_peak_get
1812 static struct snd_ice1712_card_info no_matched __devinitdata;
1814 static struct snd_ice1712_card_info *card_tables[] __devinitdata = {
1815 snd_vt1724_revo_cards,
1816 snd_vt1724_amp_cards,
1817 snd_vt1724_aureon_cards,
1825 unsigned char snd_vt1724_read_i2c(ice1712_t *ice, unsigned char dev, unsigned char addr)
1829 outb(addr, ICEREG1724(ice, I2C_BYTE_ADDR));
1830 outb(dev & ~VT1724_I2C_WRITE, ICEREG1724(ice, I2C_DEV_ADDR));
1831 while (t-- > 0 && (inb(ICEREG1724(ice, I2C_CTRL)) & VT1724_I2C_BUSY)) ;
1832 return inb(ICEREG1724(ice, I2C_DATA));
1835 void snd_vt1724_write_i2c(ice1712_t *ice, unsigned char dev, unsigned char addr, unsigned char data)
1839 outb(addr, ICEREG1724(ice, I2C_BYTE_ADDR));
1840 outb(data, ICEREG1724(ice, I2C_DATA));
1841 outb(dev | VT1724_I2C_WRITE, ICEREG1724(ice, I2C_DEV_ADDR));
1842 while (t-- > 0 && (inb(ICEREG1724(ice, I2C_CTRL)) & VT1724_I2C_BUSY)) ;
1845 static int __devinit snd_vt1724_read_eeprom(ice1712_t *ice, const char *modelname)
1847 const int dev = 0xa0; /* EEPROM device address */
1848 unsigned int i, size;
1849 struct snd_ice1712_card_info **tbl, *c;
1851 if (! modelname || ! *modelname) {
1852 ice->eeprom.subvendor = 0;
1853 if ((inb(ICEREG1724(ice, I2C_CTRL)) & VT1724_I2C_EEPROM) != 0)
1854 ice->eeprom.subvendor = (snd_vt1724_read_i2c(ice, dev, 0x00) << 0) |
1855 (snd_vt1724_read_i2c(ice, dev, 0x01) << 8) |
1856 (snd_vt1724_read_i2c(ice, dev, 0x02) << 16) |
1857 (snd_vt1724_read_i2c(ice, dev, 0x03) << 24);
1858 if (ice->eeprom.subvendor == 0 || ice->eeprom.subvendor == (unsigned int)-1) {
1859 /* invalid subvendor from EEPROM, try the PCI subststem ID instead */
1861 pci_read_config_word(ice->pci, PCI_SUBSYSTEM_VENDOR_ID, &vendor);
1862 pci_read_config_word(ice->pci, PCI_SUBSYSTEM_ID, &device);
1863 ice->eeprom.subvendor = ((unsigned int)swab16(vendor) << 16) | swab16(device);
1864 if (ice->eeprom.subvendor == 0 || ice->eeprom.subvendor == (unsigned int)-1) {
1865 printk(KERN_ERR "ice1724: No valid ID is found\n");
1870 for (tbl = card_tables; *tbl; tbl++) {
1871 for (c = *tbl; c->subvendor; c++) {
1872 if (modelname && c->model && ! strcmp(modelname, c->model)) {
1873 printk(KERN_INFO "ice1724: Using board model %s\n", c->name);
1874 ice->eeprom.subvendor = c->subvendor;
1875 } else if (c->subvendor != ice->eeprom.subvendor)
1877 if (! c->eeprom_size || ! c->eeprom_data)
1879 /* if the EEPROM is given by the driver, use it */
1880 snd_printdd("using the defined eeprom..\n");
1881 ice->eeprom.version = 2;
1882 ice->eeprom.size = c->eeprom_size + 6;
1883 memcpy(ice->eeprom.data, c->eeprom_data, c->eeprom_size);
1887 printk(KERN_WARNING "ice1724: No matching model found for ID 0x%x\n", ice->eeprom.subvendor);
1890 ice->eeprom.size = snd_vt1724_read_i2c(ice, dev, 0x04);
1891 if (ice->eeprom.size < 6)
1892 ice->eeprom.size = 32;
1893 else if (ice->eeprom.size > 32) {
1894 printk(KERN_ERR "ice1724: Invalid EEPROM (size = %i)\n", ice->eeprom.size);
1897 ice->eeprom.version = snd_vt1724_read_i2c(ice, dev, 0x05);
1898 if (ice->eeprom.version != 2)
1899 printk(KERN_WARNING "ice1724: Invalid EEPROM version %i\n", ice->eeprom.version);
1900 size = ice->eeprom.size - 6;
1901 for (i = 0; i < size; i++)
1902 ice->eeprom.data[i] = snd_vt1724_read_i2c(ice, dev, i + 6);
1905 ice->eeprom.gpiomask = eeprom_triple(ice, ICE_EEP2_GPIO_MASK);
1906 ice->eeprom.gpiostate = eeprom_triple(ice, ICE_EEP2_GPIO_STATE);
1907 ice->eeprom.gpiodir = eeprom_triple(ice, ICE_EEP2_GPIO_DIR);
1914 static int __devinit snd_vt1724_chip_init(ice1712_t *ice)
1916 outb(VT1724_RESET , ICEREG1724(ice, CONTROL));
1918 outb(0, ICEREG1724(ice, CONTROL));
1920 outb(ice->eeprom.data[ICE_EEP2_SYSCONF], ICEREG1724(ice, SYS_CFG));
1921 outb(ice->eeprom.data[ICE_EEP2_ACLINK], ICEREG1724(ice, AC97_CFG));
1922 outb(ice->eeprom.data[ICE_EEP2_I2S], ICEREG1724(ice, I2S_FEATURES));
1923 outb(ice->eeprom.data[ICE_EEP2_SPDIF], ICEREG1724(ice, SPDIF_CFG));
1925 ice->gpio.write_mask = ice->eeprom.gpiomask;
1926 ice->gpio.direction = ice->eeprom.gpiodir;
1927 snd_vt1724_set_gpio_mask(ice, ice->eeprom.gpiomask);
1928 snd_vt1724_set_gpio_dir(ice, ice->eeprom.gpiodir);
1929 snd_vt1724_set_gpio_data(ice, ice->eeprom.gpiostate);
1931 outb(0, ICEREG1724(ice, POWERDOWN));
1933 /* read back to check the availability of SPDIF out */
1934 ice->eeprom.data[ICE_EEP2_SPDIF] = inb(ICEREG1724(ice, SPDIF_CFG));
1939 static int __devinit snd_vt1724_spdif_build_controls(ice1712_t *ice)
1942 snd_kcontrol_t *kctl;
1944 snd_assert(ice->pcm != NULL, return -EIO);
1946 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_mixer_pro_spdif_route, ice));
1950 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_spdif_switch, ice));
1954 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_vt1724_spdif_default, ice));
1957 kctl->id.device = ice->pcm->device;
1958 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_vt1724_spdif_maskc, ice));
1961 kctl->id.device = ice->pcm->device;
1962 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_vt1724_spdif_maskp, ice));
1965 kctl->id.device = ice->pcm->device;
1966 #if 0 /* use default only */
1967 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_vt1724_spdif_stream, ice));
1970 kctl->id.device = ice->pcm->device;
1971 ice->spdif.stream_ctl = kctl;
1977 static int __devinit snd_vt1724_build_controls(ice1712_t *ice)
1981 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_eeprom, ice));
1984 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_pro_internal_clock, ice));
1988 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_pro_rate_locking, ice));
1991 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_pro_rate_reset, ice));
1995 if (ice->num_total_dacs > 0) {
1996 snd_kcontrol_new_t tmp = snd_vt1724_mixer_pro_analog_route;
2000 tmp.count = ice->num_total_dacs;
2001 err = snd_ctl_add(ice->card, snd_ctl_new1(&tmp, ice));
2006 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_mixer_pro_peak, ice));
2013 static int snd_vt1724_free(ice1712_t *ice)
2015 if (ice->res_port == NULL)
2017 /* mask all interrupts */
2018 outb(0xff, ICEMT1724(ice, DMA_INT_MASK));
2019 outb(0xff, ICEREG1724(ice, IRQMASK));
2022 if (ice->irq >= 0) {
2023 synchronize_irq(ice->irq);
2024 free_irq(ice->irq, (void *) ice);
2026 if (ice->res_port) {
2027 release_resource(ice->res_port);
2028 kfree_nocheck(ice->res_port);
2030 if (ice->res_profi_port) {
2031 release_resource(ice->res_profi_port);
2032 kfree_nocheck(ice->res_profi_port);
2034 snd_ice1712_akm4xxx_free(ice);
2035 snd_magic_kfree(ice);
2039 static int snd_vt1724_dev_free(snd_device_t *device)
2041 ice1712_t *ice = snd_magic_cast(ice1712_t, device->device_data, return -ENXIO);
2042 return snd_vt1724_free(ice);
2045 static int __devinit snd_vt1724_create(snd_card_t * card,
2046 struct pci_dev *pci,
2047 const char *modelname,
2048 ice1712_t ** r_ice1712)
2053 static snd_device_ops_t ops = {
2054 .dev_free = snd_vt1724_dev_free,
2059 /* enable PCI device */
2060 if ((err = pci_enable_device(pci)) < 0)
2063 ice = snd_magic_kcalloc(ice1712_t, 0, GFP_KERNEL);
2067 spin_lock_init(&ice->reg_lock);
2068 init_MUTEX(&ice->gpio_mutex);
2069 init_MUTEX(&ice->open_mutex);
2070 ice->gpio.set_mask = snd_vt1724_set_gpio_mask;
2071 ice->gpio.set_dir = snd_vt1724_set_gpio_dir;
2072 ice->gpio.set_data = snd_vt1724_set_gpio_data;
2073 ice->gpio.get_data = snd_vt1724_get_gpio_data;
2077 ice->port = pci_resource_start(pci, 0);
2078 ice->profi_port = pci_resource_start(pci, 1);
2079 pci_set_master(pci);
2080 snd_vt1724_proc_init(ice);
2081 synchronize_irq(pci->irq);
2083 if ((ice->res_port = request_region(ice->port, 32, "ICE1724 - Controller")) == NULL) {
2084 snd_printk("unable to grab ports 0x%lx-0x%lx\n", ice->port, ice->port + 32 - 1);
2085 snd_vt1724_free(ice);
2089 if ((ice->res_profi_port = request_region(ice->profi_port, 128, "ICE1724 - Professional")) == NULL) {
2090 snd_printk("unable to grab ports 0x%lx-0x%lx\n", ice->profi_port, ice->profi_port + 16 - 1);
2091 snd_vt1724_free(ice);
2095 if (request_irq(pci->irq, snd_vt1724_interrupt, SA_INTERRUPT|SA_SHIRQ, "ICE1724", (void *) ice)) {
2096 snd_printk("unable to grab IRQ %d\n", pci->irq);
2097 snd_vt1724_free(ice);
2101 ice->irq = pci->irq;
2103 if (snd_vt1724_read_eeprom(ice, modelname) < 0) {
2104 snd_vt1724_free(ice);
2107 if (snd_vt1724_chip_init(ice) < 0) {
2108 snd_vt1724_free(ice);
2112 /* unmask used interrupts */
2113 if (! (ice->eeprom.data[ICE_EEP2_SYSCONF] & VT1724_CFG_MPU401))
2114 mask = VT1724_IRQ_MPU_RX | VT1724_IRQ_MPU_TX;
2117 outb(mask, ICEREG1724(ice, IRQMASK));
2118 /* don't handle FIFO overrun/underruns (just yet), since they cause machine lockups */
2119 outb(VT1724_MULTI_FIFO_ERR, ICEMT1724(ice, DMA_INT_MASK));
2121 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, ice, &ops)) < 0) {
2122 snd_vt1724_free(ice);
2126 snd_card_set_dev(card, &pci->dev);
2139 static int __devinit snd_vt1724_probe(struct pci_dev *pci,
2140 const struct pci_device_id *pci_id)
2145 int pcm_dev = 0, err;
2146 struct snd_ice1712_card_info **tbl, *c;
2148 if (dev >= SNDRV_CARDS)
2155 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
2159 strcpy(card->driver, "ICE1724");
2160 strcpy(card->shortname, "ICEnsemble ICE1724");
2162 if ((err = snd_vt1724_create(card, pci, model[dev], &ice)) < 0) {
2163 snd_card_free(card);
2167 for (tbl = card_tables; *tbl; tbl++) {
2168 for (c = *tbl; c->subvendor; c++) {
2169 if (c->subvendor == ice->eeprom.subvendor) {
2170 strcpy(card->shortname, c->name);
2171 if (c->driver) /* specific driver? */
2172 strcpy(card->driver, c->driver);
2174 if ((err = c->chip_init(ice)) < 0) {
2175 snd_card_free(card);
2186 if ((err = snd_vt1724_pcm_profi(ice, pcm_dev++)) < 0) {
2187 snd_card_free(card);
2191 if ((err = snd_vt1724_pcm_spdif(ice, pcm_dev++)) < 0) {
2192 snd_card_free(card);
2196 if ((err = snd_vt1724_pcm_indep(ice, pcm_dev++)) < 0) {
2197 snd_card_free(card);
2201 if ((err = snd_vt1724_ac97_mixer(ice)) < 0) {
2202 snd_card_free(card);
2206 if ((err = snd_vt1724_build_controls(ice)) < 0) {
2207 snd_card_free(card);
2211 if (ice->pcm && ice->has_spdif) { /* has SPDIF I/O */
2212 if ((err = snd_vt1724_spdif_build_controls(ice)) < 0) {
2213 snd_card_free(card);
2218 if (c->build_controls) {
2219 if ((err = c->build_controls(ice)) < 0) {
2220 snd_card_free(card);
2225 if (! c->no_mpu401) {
2226 if (ice->eeprom.data[ICE_EEP2_SYSCONF] & VT1724_CFG_MPU401) {
2227 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_ICE1712,
2228 ICEREG1724(ice, MPU_CTRL), 1,
2230 &ice->rmidi[0])) < 0) {
2231 snd_card_free(card);
2237 sprintf(card->longname, "%s at 0x%lx, irq %i",
2238 card->shortname, ice->port, ice->irq);
2240 if ((err = snd_card_register(card)) < 0) {
2241 snd_card_free(card);
2244 pci_set_drvdata(pci, card);
2249 static void __devexit snd_vt1724_remove(struct pci_dev *pci)
2251 snd_card_free(pci_get_drvdata(pci));
2252 pci_set_drvdata(pci, NULL);
2255 static struct pci_driver driver = {
2257 .id_table = snd_vt1724_ids,
2258 .probe = snd_vt1724_probe,
2259 .remove = __devexit_p(snd_vt1724_remove),
2262 static int __init alsa_card_ice1724_init(void)
2264 return pci_module_init(&driver);
2267 static void __exit alsa_card_ice1724_exit(void)
2269 pci_unregister_driver(&driver);
2272 module_init(alsa_card_ice1724_init)
2273 module_exit(alsa_card_ice1724_exit)