2 * ALSA driver for VT1724 ICEnsemble ICE1724 / VIA VT1724 (Envy24HT)
3 * VIA VT1720 (Envy24PT)
5 * Copyright (c) 2000 Jaroslav Kysela <perex@perex.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
26 #include <linux/delay.h>
27 #include <linux/interrupt.h>
28 #include <linux/init.h>
29 #include <linux/pci.h>
30 #include <linux/slab.h>
31 #include <linux/moduleparam.h>
32 #include <linux/mutex.h>
33 #include <sound/core.h>
34 #include <sound/info.h>
35 #include <sound/mpu401.h>
36 #include <sound/initval.h>
38 #include <sound/asoundef.h>
43 /* lowlevel routines */
47 #include "vt1720_mobo.h"
49 #include "prodigy192.h"
50 #include "prodigy_hifi.h"
56 MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
57 MODULE_DESCRIPTION("VIA ICEnsemble ICE1724/1720 (Envy24HT/PT)");
58 MODULE_LICENSE("GPL");
59 MODULE_SUPPORTED_DEVICE("{"
61 AMP_AUDIO2000_DEVICE_DESC
63 VT1720_MOBO_DEVICE_DESC
65 PRODIGY192_DEVICE_DESC
66 PRODIGY_HIFI_DEVICE_DESC
73 "{ICEnsemble,Generic ICE1724},"
74 "{ICEnsemble,Generic Envy24HT}"
75 "{ICEnsemble,Generic Envy24PT}}");
77 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
78 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
79 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */
80 static char *model[SNDRV_CARDS];
82 module_param_array(index, int, NULL, 0444);
83 MODULE_PARM_DESC(index, "Index value for ICE1724 soundcard.");
84 module_param_array(id, charp, NULL, 0444);
85 MODULE_PARM_DESC(id, "ID string for ICE1724 soundcard.");
86 module_param_array(enable, bool, NULL, 0444);
87 MODULE_PARM_DESC(enable, "Enable ICE1724 soundcard.");
88 module_param_array(model, charp, NULL, 0444);
89 MODULE_PARM_DESC(model, "Use the given board model.");
92 /* Both VT1720 and VT1724 have the same PCI IDs */
93 static const struct pci_device_id snd_vt1724_ids[] = {
94 { PCI_VENDOR_ID_ICE, PCI_DEVICE_ID_VT1724, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
98 MODULE_DEVICE_TABLE(pci, snd_vt1724_ids);
101 static int PRO_RATE_LOCKED;
102 static int PRO_RATE_RESET = 1;
103 static unsigned int PRO_RATE_DEFAULT = 44100;
110 * default rates, default clock routines
113 /* check whether the clock mode is spdif-in */
114 static inline int stdclock_is_spdif_master(struct snd_ice1712 *ice)
116 return (inb(ICEMT1724(ice, RATE)) & VT1724_SPDIF_MASTER) ? 1 : 0;
119 static inline int is_pro_rate_locked(struct snd_ice1712 *ice)
121 return ice->is_spdif_master(ice) || PRO_RATE_LOCKED;
128 static unsigned char snd_vt1724_ac97_ready(struct snd_ice1712 *ice)
130 unsigned char old_cmd;
132 for (tm = 0; tm < 0x10000; tm++) {
133 old_cmd = inb(ICEMT1724(ice, AC97_CMD));
134 if (old_cmd & (VT1724_AC97_WRITE | VT1724_AC97_READ))
136 if (!(old_cmd & VT1724_AC97_READY))
140 snd_printd(KERN_ERR "snd_vt1724_ac97_ready: timeout\n");
144 static int snd_vt1724_ac97_wait_bit(struct snd_ice1712 *ice, unsigned char bit)
147 for (tm = 0; tm < 0x10000; tm++)
148 if ((inb(ICEMT1724(ice, AC97_CMD)) & bit) == 0)
150 snd_printd(KERN_ERR "snd_vt1724_ac97_wait_bit: timeout\n");
154 static void snd_vt1724_ac97_write(struct snd_ac97 *ac97,
158 struct snd_ice1712 *ice = ac97->private_data;
159 unsigned char old_cmd;
161 old_cmd = snd_vt1724_ac97_ready(ice);
162 old_cmd &= ~VT1724_AC97_ID_MASK;
163 old_cmd |= ac97->num;
164 outb(reg, ICEMT1724(ice, AC97_INDEX));
165 outw(val, ICEMT1724(ice, AC97_DATA));
166 outb(old_cmd | VT1724_AC97_WRITE, ICEMT1724(ice, AC97_CMD));
167 snd_vt1724_ac97_wait_bit(ice, VT1724_AC97_WRITE);
170 static unsigned short snd_vt1724_ac97_read(struct snd_ac97 *ac97, unsigned short reg)
172 struct snd_ice1712 *ice = ac97->private_data;
173 unsigned char old_cmd;
175 old_cmd = snd_vt1724_ac97_ready(ice);
176 old_cmd &= ~VT1724_AC97_ID_MASK;
177 old_cmd |= ac97->num;
178 outb(reg, ICEMT1724(ice, AC97_INDEX));
179 outb(old_cmd | VT1724_AC97_READ, ICEMT1724(ice, AC97_CMD));
180 if (snd_vt1724_ac97_wait_bit(ice, VT1724_AC97_READ) < 0)
182 return inw(ICEMT1724(ice, AC97_DATA));
190 /* set gpio direction 0 = read, 1 = write */
191 static void snd_vt1724_set_gpio_dir(struct snd_ice1712 *ice, unsigned int data)
193 outl(data, ICEREG1724(ice, GPIO_DIRECTION));
194 inw(ICEREG1724(ice, GPIO_DIRECTION)); /* dummy read for pci-posting */
197 /* set the gpio mask (0 = writable) */
198 static void snd_vt1724_set_gpio_mask(struct snd_ice1712 *ice, unsigned int data)
200 outw(data, ICEREG1724(ice, GPIO_WRITE_MASK));
201 if (! ice->vt1720) /* VT1720 supports only 16 GPIO bits */
202 outb((data >> 16) & 0xff, ICEREG1724(ice, GPIO_WRITE_MASK_22));
203 inw(ICEREG1724(ice, GPIO_WRITE_MASK)); /* dummy read for pci-posting */
206 static void snd_vt1724_set_gpio_data(struct snd_ice1712 *ice, unsigned int data)
208 outw(data, ICEREG1724(ice, GPIO_DATA));
210 outb(data >> 16, ICEREG1724(ice, GPIO_DATA_22));
211 inw(ICEREG1724(ice, GPIO_DATA)); /* dummy read for pci-posting */
214 static unsigned int snd_vt1724_get_gpio_data(struct snd_ice1712 *ice)
218 data = (unsigned int)inb(ICEREG1724(ice, GPIO_DATA_22));
221 data = (data << 16) | inw(ICEREG1724(ice, GPIO_DATA));
229 static irqreturn_t snd_vt1724_interrupt(int irq, void *dev_id)
231 struct snd_ice1712 *ice = dev_id;
232 unsigned char status;
236 status = inb(ICEREG1724(ice, IRQSTAT));
241 /* these should probably be separated at some point,
242 * but as we don't currently have MPU support on the board
245 if ((status & VT1724_IRQ_MPU_RX)||(status & VT1724_IRQ_MPU_TX)) {
247 snd_mpu401_uart_interrupt(irq, ice->rmidi[0]->private_data);
248 outb(status & (VT1724_IRQ_MPU_RX|VT1724_IRQ_MPU_TX), ICEREG1724(ice, IRQSTAT));
249 status &= ~(VT1724_IRQ_MPU_RX|VT1724_IRQ_MPU_TX);
251 if (status & VT1724_IRQ_MTPCM) {
254 * PCM assignment are:
255 * Playback DMA0 (M/C) = playback_pro_substream
256 * Playback DMA1 = playback_con_substream_ds[0]
257 * Playback DMA2 = playback_con_substream_ds[1]
258 * Playback DMA3 = playback_con_substream_ds[2]
259 * Playback DMA4 (SPDIF) = playback_con_substream
260 * Record DMA0 = capture_pro_substream
261 * Record DMA1 = capture_con_substream
263 unsigned char mtstat = inb(ICEMT1724(ice, IRQ));
264 if (mtstat & VT1724_MULTI_PDMA0) {
265 if (ice->playback_pro_substream)
266 snd_pcm_period_elapsed(ice->playback_pro_substream);
268 if (mtstat & VT1724_MULTI_RDMA0) {
269 if (ice->capture_pro_substream)
270 snd_pcm_period_elapsed(ice->capture_pro_substream);
272 if (mtstat & VT1724_MULTI_PDMA1) {
273 if (ice->playback_con_substream_ds[0])
274 snd_pcm_period_elapsed(ice->playback_con_substream_ds[0]);
276 if (mtstat & VT1724_MULTI_PDMA2) {
277 if (ice->playback_con_substream_ds[1])
278 snd_pcm_period_elapsed(ice->playback_con_substream_ds[1]);
280 if (mtstat & VT1724_MULTI_PDMA3) {
281 if (ice->playback_con_substream_ds[2])
282 snd_pcm_period_elapsed(ice->playback_con_substream_ds[2]);
284 if (mtstat & VT1724_MULTI_PDMA4) {
285 if (ice->playback_con_substream)
286 snd_pcm_period_elapsed(ice->playback_con_substream);
288 if (mtstat & VT1724_MULTI_RDMA1) {
289 if (ice->capture_con_substream)
290 snd_pcm_period_elapsed(ice->capture_con_substream);
292 /* ack anyway to avoid freeze */
293 outb(mtstat, ICEMT1724(ice, IRQ));
294 /* ought to really handle this properly */
295 if (mtstat & VT1724_MULTI_FIFO_ERR) {
296 unsigned char fstat = inb(ICEMT1724(ice, DMA_FIFO_ERR));
297 outb(fstat, ICEMT1724(ice, DMA_FIFO_ERR));
298 outb(VT1724_MULTI_FIFO_ERR | inb(ICEMT1724(ice, DMA_INT_MASK)), ICEMT1724(ice, DMA_INT_MASK));
299 /* If I don't do this, I get machine lockup due to continual interrupts */
304 return IRQ_RETVAL(handled);
308 * PCM code - professional part (multitrack)
311 static unsigned int rates[] = {
312 8000, 9600, 11025, 12000, 16000, 22050, 24000,
313 32000, 44100, 48000, 64000, 88200, 96000,
317 static struct snd_pcm_hw_constraint_list hw_constraints_rates_96 = {
318 .count = ARRAY_SIZE(rates) - 2, /* up to 96000 */
323 static struct snd_pcm_hw_constraint_list hw_constraints_rates_48 = {
324 .count = ARRAY_SIZE(rates) - 5, /* up to 48000 */
329 static struct snd_pcm_hw_constraint_list hw_constraints_rates_192 = {
330 .count = ARRAY_SIZE(rates),
335 struct vt1724_pcm_reg {
336 unsigned int addr; /* ADDR register offset */
337 unsigned int size; /* SIZE register offset */
338 unsigned int count; /* COUNT register offset */
339 unsigned int start; /* start & pause bit */
342 static int snd_vt1724_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
344 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
347 struct snd_pcm_substream *s;
350 snd_pcm_group_for_each_entry(s, substream) {
351 if (snd_pcm_substream_chip(s) == ice) {
352 const struct vt1724_pcm_reg *reg;
353 reg = s->runtime->private_data;
355 snd_pcm_trigger_done(s, substream);
360 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
361 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
362 spin_lock(&ice->reg_lock);
363 old = inb(ICEMT1724(ice, DMA_PAUSE));
364 if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH)
368 outb(old, ICEMT1724(ice, DMA_PAUSE));
369 spin_unlock(&ice->reg_lock);
372 case SNDRV_PCM_TRIGGER_START:
373 case SNDRV_PCM_TRIGGER_STOP:
374 spin_lock(&ice->reg_lock);
375 old = inb(ICEMT1724(ice, DMA_CONTROL));
376 if (cmd == SNDRV_PCM_TRIGGER_START)
380 outb(old, ICEMT1724(ice, DMA_CONTROL));
381 spin_unlock(&ice->reg_lock);
393 #define DMA_STARTS (VT1724_RDMA0_START|VT1724_PDMA0_START|VT1724_RDMA1_START|\
394 VT1724_PDMA1_START|VT1724_PDMA2_START|VT1724_PDMA3_START|VT1724_PDMA4_START)
395 #define DMA_PAUSES (VT1724_RDMA0_PAUSE|VT1724_PDMA0_PAUSE|VT1724_RDMA1_PAUSE|\
396 VT1724_PDMA1_PAUSE|VT1724_PDMA2_PAUSE|VT1724_PDMA3_PAUSE|VT1724_PDMA4_PAUSE)
398 static const unsigned int stdclock_rate_list[16] = {
399 48000, 24000, 12000, 9600, 32000, 16000, 8000, 96000, 44100,
400 22050, 11025, 88200, 176400, 0, 192000, 64000
403 static unsigned int stdclock_get_rate(struct snd_ice1712 *ice)
406 rate = stdclock_rate_list[inb(ICEMT1724(ice, RATE)) & 15];
410 static void stdclock_set_rate(struct snd_ice1712 *ice, unsigned int rate)
413 for (i = 0; i < ARRAY_SIZE(stdclock_rate_list); i++) {
414 if (stdclock_rate_list[i] == rate) {
415 outb(i, ICEMT1724(ice, RATE));
421 static unsigned char stdclock_set_mclk(struct snd_ice1712 *ice,
424 unsigned char val, old;
426 if (ice->eeprom.data[ICE_EEP2_ACLINK] & VT1724_CFG_PRO_I2S) {
427 val = old = inb(ICEMT1724(ice, I2S_FORMAT));
429 val |= VT1724_MT_I2S_MCLK_128X; /* 128x MCLK */
431 val &= ~VT1724_MT_I2S_MCLK_128X; /* 256x MCLK */
433 outb(val, ICEMT1724(ice, I2S_FORMAT));
434 /* master clock changed */
438 /* no change in master clock */
442 static void snd_vt1724_set_pro_rate(struct snd_ice1712 *ice, unsigned int rate,
446 unsigned char mclk_change;
447 unsigned int i, old_rate;
449 if (rate > ice->hw_rates->list[ice->hw_rates->count - 1])
451 spin_lock_irqsave(&ice->reg_lock, flags);
452 if ((inb(ICEMT1724(ice, DMA_CONTROL)) & DMA_STARTS) ||
453 (inb(ICEMT1724(ice, DMA_PAUSE)) & DMA_PAUSES)) {
454 /* running? we cannot change the rate now... */
455 spin_unlock_irqrestore(&ice->reg_lock, flags);
458 if (!force && is_pro_rate_locked(ice)) {
459 spin_unlock_irqrestore(&ice->reg_lock, flags);
463 old_rate = ice->get_rate(ice);
464 if (force || (old_rate != rate))
465 ice->set_rate(ice, rate);
466 else if (rate == ice->cur_rate) {
467 spin_unlock_irqrestore(&ice->reg_lock, flags);
471 ice->cur_rate = rate;
473 /* setting master clock */
474 mclk_change = ice->set_mclk(ice, rate);
476 spin_unlock_irqrestore(&ice->reg_lock, flags);
478 if (mclk_change && ice->gpio.i2s_mclk_changed)
479 ice->gpio.i2s_mclk_changed(ice);
480 if (ice->gpio.set_pro_rate)
481 ice->gpio.set_pro_rate(ice, rate);
484 for (i = 0; i < ice->akm_codecs; i++) {
485 if (ice->akm[i].ops.set_rate_val)
486 ice->akm[i].ops.set_rate_val(&ice->akm[i], rate);
488 if (ice->spdif.ops.setup_rate)
489 ice->spdif.ops.setup_rate(ice, rate);
492 static int snd_vt1724_pcm_hw_params(struct snd_pcm_substream *substream,
493 struct snd_pcm_hw_params *hw_params)
495 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
498 chs = params_channels(hw_params);
499 mutex_lock(&ice->open_mutex);
500 /* mark surround channels */
501 if (substream == ice->playback_pro_substream) {
502 /* PDMA0 can be multi-channel up to 8 */
504 for (i = 0; i < chs; i++) {
505 if (ice->pcm_reserved[i] &&
506 ice->pcm_reserved[i] != substream) {
507 mutex_unlock(&ice->open_mutex);
510 ice->pcm_reserved[i] = substream;
513 if (ice->pcm_reserved[i] == substream)
514 ice->pcm_reserved[i] = NULL;
517 for (i = 0; i < 3; i++) {
518 /* check individual playback stream */
519 if (ice->playback_con_substream_ds[i] == substream) {
520 if (ice->pcm_reserved[i] &&
521 ice->pcm_reserved[i] != substream) {
522 mutex_unlock(&ice->open_mutex);
525 ice->pcm_reserved[i] = substream;
530 mutex_unlock(&ice->open_mutex);
531 snd_vt1724_set_pro_rate(ice, params_rate(hw_params), 0);
532 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
535 static int snd_vt1724_pcm_hw_free(struct snd_pcm_substream *substream)
537 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
540 mutex_lock(&ice->open_mutex);
541 /* unmark surround channels */
542 for (i = 0; i < 3; i++)
543 if (ice->pcm_reserved[i] == substream)
544 ice->pcm_reserved[i] = NULL;
545 mutex_unlock(&ice->open_mutex);
546 return snd_pcm_lib_free_pages(substream);
549 static int snd_vt1724_playback_pro_prepare(struct snd_pcm_substream *substream)
551 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
555 spin_lock_irq(&ice->reg_lock);
556 val = (8 - substream->runtime->channels) >> 1;
557 outb(val, ICEMT1724(ice, BURST));
559 outl(substream->runtime->dma_addr, ICEMT1724(ice, PLAYBACK_ADDR));
561 size = (snd_pcm_lib_buffer_bytes(substream) >> 2) - 1;
562 // outl(size, ICEMT1724(ice, PLAYBACK_SIZE));
563 outw(size, ICEMT1724(ice, PLAYBACK_SIZE));
564 outb(size >> 16, ICEMT1724(ice, PLAYBACK_SIZE) + 2);
565 size = (snd_pcm_lib_period_bytes(substream) >> 2) - 1;
566 // outl(size, ICEMT1724(ice, PLAYBACK_COUNT));
567 outw(size, ICEMT1724(ice, PLAYBACK_COUNT));
568 outb(size >> 16, ICEMT1724(ice, PLAYBACK_COUNT) + 2);
570 spin_unlock_irq(&ice->reg_lock);
572 // 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));
576 static snd_pcm_uframes_t snd_vt1724_playback_pro_pointer(struct snd_pcm_substream *substream)
578 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
581 if (!(inl(ICEMT1724(ice, DMA_CONTROL)) & VT1724_PDMA0_START))
583 #if 0 /* read PLAYBACK_ADDR */
584 ptr = inl(ICEMT1724(ice, PLAYBACK_ADDR));
585 if (ptr < substream->runtime->dma_addr) {
586 snd_printd("ice1724: invalid negative ptr\n");
589 ptr -= substream->runtime->dma_addr;
590 ptr = bytes_to_frames(substream->runtime, ptr);
591 if (ptr >= substream->runtime->buffer_size) {
592 snd_printd("ice1724: invalid ptr %d (size=%d)\n",
593 (int)ptr, (int)substream->runtime->period_size);
596 #else /* read PLAYBACK_SIZE */
597 ptr = inl(ICEMT1724(ice, PLAYBACK_SIZE)) & 0xffffff;
598 ptr = (ptr + 1) << 2;
599 ptr = bytes_to_frames(substream->runtime, ptr);
602 else if (ptr <= substream->runtime->buffer_size)
603 ptr = substream->runtime->buffer_size - ptr;
605 snd_printd("ice1724: invalid ptr %d (size=%d)\n",
606 (int)ptr, (int)substream->runtime->buffer_size);
613 static int snd_vt1724_pcm_prepare(struct snd_pcm_substream *substream)
615 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
616 const struct vt1724_pcm_reg *reg = substream->runtime->private_data;
618 spin_lock_irq(&ice->reg_lock);
619 outl(substream->runtime->dma_addr, ice->profi_port + reg->addr);
620 outw((snd_pcm_lib_buffer_bytes(substream) >> 2) - 1,
621 ice->profi_port + reg->size);
622 outw((snd_pcm_lib_period_bytes(substream) >> 2) - 1,
623 ice->profi_port + reg->count);
624 spin_unlock_irq(&ice->reg_lock);
628 static snd_pcm_uframes_t snd_vt1724_pcm_pointer(struct snd_pcm_substream *substream)
630 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
631 const struct vt1724_pcm_reg *reg = substream->runtime->private_data;
634 if (!(inl(ICEMT1724(ice, DMA_CONTROL)) & reg->start))
636 #if 0 /* use ADDR register */
637 ptr = inl(ice->profi_port + reg->addr);
638 ptr -= substream->runtime->dma_addr;
639 return bytes_to_frames(substream->runtime, ptr);
640 #else /* use SIZE register */
641 ptr = inw(ice->profi_port + reg->size);
642 ptr = (ptr + 1) << 2;
643 ptr = bytes_to_frames(substream->runtime, ptr);
646 else if (ptr <= substream->runtime->buffer_size)
647 ptr = substream->runtime->buffer_size - ptr;
649 snd_printd("ice1724: invalid ptr %d (size=%d)\n",
650 (int)ptr, (int)substream->runtime->buffer_size);
657 static const struct vt1724_pcm_reg vt1724_playback_pro_reg = {
658 .addr = VT1724_MT_PLAYBACK_ADDR,
659 .size = VT1724_MT_PLAYBACK_SIZE,
660 .count = VT1724_MT_PLAYBACK_COUNT,
661 .start = VT1724_PDMA0_START,
664 static const struct vt1724_pcm_reg vt1724_capture_pro_reg = {
665 .addr = VT1724_MT_CAPTURE_ADDR,
666 .size = VT1724_MT_CAPTURE_SIZE,
667 .count = VT1724_MT_CAPTURE_COUNT,
668 .start = VT1724_RDMA0_START,
671 static const struct snd_pcm_hardware snd_vt1724_playback_pro =
673 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
674 SNDRV_PCM_INFO_BLOCK_TRANSFER |
675 SNDRV_PCM_INFO_MMAP_VALID |
676 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START),
677 .formats = SNDRV_PCM_FMTBIT_S32_LE,
678 .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_192000,
683 .buffer_bytes_max = (1UL << 21), /* 19bits dword */
684 .period_bytes_min = 8 * 4 * 2, /* FIXME: constraints needed */
685 .period_bytes_max = (1UL << 21),
690 static const struct snd_pcm_hardware snd_vt1724_spdif =
692 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
693 SNDRV_PCM_INFO_BLOCK_TRANSFER |
694 SNDRV_PCM_INFO_MMAP_VALID |
695 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START),
696 .formats = SNDRV_PCM_FMTBIT_S32_LE,
697 .rates = (SNDRV_PCM_RATE_32000|SNDRV_PCM_RATE_44100|
698 SNDRV_PCM_RATE_48000|SNDRV_PCM_RATE_88200|
699 SNDRV_PCM_RATE_96000|SNDRV_PCM_RATE_176400|
700 SNDRV_PCM_RATE_192000),
705 .buffer_bytes_max = (1UL << 18), /* 16bits dword */
706 .period_bytes_min = 2 * 4 * 2,
707 .period_bytes_max = (1UL << 18),
712 static const struct snd_pcm_hardware snd_vt1724_2ch_stereo =
714 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
715 SNDRV_PCM_INFO_BLOCK_TRANSFER |
716 SNDRV_PCM_INFO_MMAP_VALID |
717 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START),
718 .formats = SNDRV_PCM_FMTBIT_S32_LE,
719 .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_192000,
724 .buffer_bytes_max = (1UL << 18), /* 16bits dword */
725 .period_bytes_min = 2 * 4 * 2,
726 .period_bytes_max = (1UL << 18),
732 * set rate constraints
734 static void set_std_hw_rates(struct snd_ice1712 *ice)
736 if (ice->eeprom.data[ICE_EEP2_ACLINK] & VT1724_CFG_PRO_I2S) {
738 /* VT1720 doesn't support more than 96kHz */
739 if ((ice->eeprom.data[ICE_EEP2_I2S] & 0x08) && !ice->vt1720)
740 ice->hw_rates = &hw_constraints_rates_192;
742 ice->hw_rates = &hw_constraints_rates_96;
745 ice->hw_rates = &hw_constraints_rates_48;
749 static int set_rate_constraints(struct snd_ice1712 *ice,
750 struct snd_pcm_substream *substream)
752 struct snd_pcm_runtime *runtime = substream->runtime;
754 runtime->hw.rate_min = ice->hw_rates->list[0];
755 runtime->hw.rate_max = ice->hw_rates->list[ice->hw_rates->count - 1];
756 runtime->hw.rates = SNDRV_PCM_RATE_KNOT;
757 return snd_pcm_hw_constraint_list(runtime, 0,
758 SNDRV_PCM_HW_PARAM_RATE,
762 /* multi-channel playback needs alignment 8x32bit regardless of the channels
765 #define VT1724_BUFFER_ALIGN 0x20
767 static int snd_vt1724_playback_pro_open(struct snd_pcm_substream *substream)
769 struct snd_pcm_runtime *runtime = substream->runtime;
770 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
773 runtime->private_data = (void *)&vt1724_playback_pro_reg;
774 ice->playback_pro_substream = substream;
775 runtime->hw = snd_vt1724_playback_pro;
776 snd_pcm_set_sync(substream);
777 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
778 set_rate_constraints(ice, substream);
779 mutex_lock(&ice->open_mutex);
780 /* calculate the currently available channels */
781 for (chs = 0; chs < 3; chs++) {
782 if (ice->pcm_reserved[chs])
786 runtime->hw.channels_max = chs;
787 if (chs > 2) /* channels must be even */
788 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, 2);
789 mutex_unlock(&ice->open_mutex);
790 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
791 VT1724_BUFFER_ALIGN);
792 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
793 VT1724_BUFFER_ALIGN);
797 static int snd_vt1724_capture_pro_open(struct snd_pcm_substream *substream)
799 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
800 struct snd_pcm_runtime *runtime = substream->runtime;
802 runtime->private_data = (void *)&vt1724_capture_pro_reg;
803 ice->capture_pro_substream = substream;
804 runtime->hw = snd_vt1724_2ch_stereo;
805 snd_pcm_set_sync(substream);
806 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
807 set_rate_constraints(ice, substream);
808 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
809 VT1724_BUFFER_ALIGN);
810 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
811 VT1724_BUFFER_ALIGN);
815 static int snd_vt1724_playback_pro_close(struct snd_pcm_substream *substream)
817 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
820 snd_vt1724_set_pro_rate(ice, ice->pro_rate_default, 0);
821 ice->playback_pro_substream = NULL;
826 static int snd_vt1724_capture_pro_close(struct snd_pcm_substream *substream)
828 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
831 snd_vt1724_set_pro_rate(ice, ice->pro_rate_default, 0);
832 ice->capture_pro_substream = NULL;
836 static struct snd_pcm_ops snd_vt1724_playback_pro_ops = {
837 .open = snd_vt1724_playback_pro_open,
838 .close = snd_vt1724_playback_pro_close,
839 .ioctl = snd_pcm_lib_ioctl,
840 .hw_params = snd_vt1724_pcm_hw_params,
841 .hw_free = snd_vt1724_pcm_hw_free,
842 .prepare = snd_vt1724_playback_pro_prepare,
843 .trigger = snd_vt1724_pcm_trigger,
844 .pointer = snd_vt1724_playback_pro_pointer,
847 static struct snd_pcm_ops snd_vt1724_capture_pro_ops = {
848 .open = snd_vt1724_capture_pro_open,
849 .close = snd_vt1724_capture_pro_close,
850 .ioctl = snd_pcm_lib_ioctl,
851 .hw_params = snd_vt1724_pcm_hw_params,
852 .hw_free = snd_vt1724_pcm_hw_free,
853 .prepare = snd_vt1724_pcm_prepare,
854 .trigger = snd_vt1724_pcm_trigger,
855 .pointer = snd_vt1724_pcm_pointer,
858 static int __devinit snd_vt1724_pcm_profi(struct snd_ice1712 * ice, int device)
863 err = snd_pcm_new(ice->card, "ICE1724", device, 1, 1, &pcm);
867 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_vt1724_playback_pro_ops);
868 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_vt1724_capture_pro_ops);
870 pcm->private_data = ice;
872 strcpy(pcm->name, "ICE1724");
874 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
875 snd_dma_pci_data(ice->pci),
888 static const struct vt1724_pcm_reg vt1724_playback_spdif_reg = {
889 .addr = VT1724_MT_PDMA4_ADDR,
890 .size = VT1724_MT_PDMA4_SIZE,
891 .count = VT1724_MT_PDMA4_COUNT,
892 .start = VT1724_PDMA4_START,
895 static const struct vt1724_pcm_reg vt1724_capture_spdif_reg = {
896 .addr = VT1724_MT_RDMA1_ADDR,
897 .size = VT1724_MT_RDMA1_SIZE,
898 .count = VT1724_MT_RDMA1_COUNT,
899 .start = VT1724_RDMA1_START,
902 /* update spdif control bits; call with reg_lock */
903 static void update_spdif_bits(struct snd_ice1712 *ice, unsigned int val)
905 unsigned char cbit, disabled;
907 cbit = inb(ICEREG1724(ice, SPDIF_CFG));
908 disabled = cbit & ~VT1724_CFG_SPDIF_OUT_EN;
909 if (cbit != disabled)
910 outb(disabled, ICEREG1724(ice, SPDIF_CFG));
911 outw(val, ICEMT1724(ice, SPDIF_CTRL));
912 if (cbit != disabled)
913 outb(cbit, ICEREG1724(ice, SPDIF_CFG));
914 outw(val, ICEMT1724(ice, SPDIF_CTRL));
917 /* update SPDIF control bits according to the given rate */
918 static void update_spdif_rate(struct snd_ice1712 *ice, unsigned int rate)
920 unsigned int val, nval;
923 spin_lock_irqsave(&ice->reg_lock, flags);
924 nval = val = inw(ICEMT1724(ice, SPDIF_CTRL));
928 case 48000: nval |= 2 << 12; break;
929 case 32000: nval |= 3 << 12; break;
930 case 88200: nval |= 4 << 12; break;
931 case 96000: nval |= 5 << 12; break;
932 case 192000: nval |= 6 << 12; break;
933 case 176400: nval |= 7 << 12; break;
936 update_spdif_bits(ice, nval);
937 spin_unlock_irqrestore(&ice->reg_lock, flags);
940 static int snd_vt1724_playback_spdif_prepare(struct snd_pcm_substream *substream)
942 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
943 if (! ice->force_pdma4)
944 update_spdif_rate(ice, substream->runtime->rate);
945 return snd_vt1724_pcm_prepare(substream);
948 static int snd_vt1724_playback_spdif_open(struct snd_pcm_substream *substream)
950 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
951 struct snd_pcm_runtime *runtime = substream->runtime;
953 runtime->private_data = (void *)&vt1724_playback_spdif_reg;
954 ice->playback_con_substream = substream;
955 if (ice->force_pdma4) {
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);
966 if (ice->spdif.ops.open)
967 ice->spdif.ops.open(ice, substream);
971 static int snd_vt1724_playback_spdif_close(struct snd_pcm_substream *substream)
973 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
976 snd_vt1724_set_pro_rate(ice, ice->pro_rate_default, 0);
977 ice->playback_con_substream = NULL;
978 if (ice->spdif.ops.close)
979 ice->spdif.ops.close(ice, substream);
984 static int snd_vt1724_capture_spdif_open(struct snd_pcm_substream *substream)
986 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
987 struct snd_pcm_runtime *runtime = substream->runtime;
989 runtime->private_data = (void *)&vt1724_capture_spdif_reg;
990 ice->capture_con_substream = substream;
991 if (ice->force_rdma1) {
992 runtime->hw = snd_vt1724_2ch_stereo;
993 set_rate_constraints(ice, substream);
995 runtime->hw = snd_vt1724_spdif;
996 snd_pcm_set_sync(substream);
997 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
998 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
999 VT1724_BUFFER_ALIGN);
1000 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
1001 VT1724_BUFFER_ALIGN);
1002 if (ice->spdif.ops.open)
1003 ice->spdif.ops.open(ice, substream);
1007 static int snd_vt1724_capture_spdif_close(struct snd_pcm_substream *substream)
1009 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1012 snd_vt1724_set_pro_rate(ice, ice->pro_rate_default, 0);
1013 ice->capture_con_substream = NULL;
1014 if (ice->spdif.ops.close)
1015 ice->spdif.ops.close(ice, substream);
1020 static struct snd_pcm_ops snd_vt1724_playback_spdif_ops = {
1021 .open = snd_vt1724_playback_spdif_open,
1022 .close = snd_vt1724_playback_spdif_close,
1023 .ioctl = snd_pcm_lib_ioctl,
1024 .hw_params = snd_vt1724_pcm_hw_params,
1025 .hw_free = snd_vt1724_pcm_hw_free,
1026 .prepare = snd_vt1724_playback_spdif_prepare,
1027 .trigger = snd_vt1724_pcm_trigger,
1028 .pointer = snd_vt1724_pcm_pointer,
1031 static struct snd_pcm_ops snd_vt1724_capture_spdif_ops = {
1032 .open = snd_vt1724_capture_spdif_open,
1033 .close = snd_vt1724_capture_spdif_close,
1034 .ioctl = snd_pcm_lib_ioctl,
1035 .hw_params = snd_vt1724_pcm_hw_params,
1036 .hw_free = snd_vt1724_pcm_hw_free,
1037 .prepare = snd_vt1724_pcm_prepare,
1038 .trigger = snd_vt1724_pcm_trigger,
1039 .pointer = snd_vt1724_pcm_pointer,
1043 static int __devinit snd_vt1724_pcm_spdif(struct snd_ice1712 * ice, int device)
1046 struct snd_pcm *pcm;
1050 if (ice->force_pdma4 ||
1051 (ice->eeprom.data[ICE_EEP2_SPDIF] & VT1724_CFG_SPDIF_OUT_INT)) {
1056 if (ice->force_rdma1 ||
1057 (ice->eeprom.data[ICE_EEP2_SPDIF] & VT1724_CFG_SPDIF_IN)) {
1062 if (! play && ! capt)
1063 return 0; /* no spdif device */
1065 if (ice->force_pdma4 || ice->force_rdma1)
1066 name = "ICE1724 Secondary";
1068 name = "IEC1724 IEC958";
1069 err = snd_pcm_new(ice->card, name, device, play, capt, &pcm);
1074 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
1075 &snd_vt1724_playback_spdif_ops);
1077 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
1078 &snd_vt1724_capture_spdif_ops);
1080 pcm->private_data = ice;
1081 pcm->info_flags = 0;
1082 strcpy(pcm->name, name);
1084 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
1085 snd_dma_pci_data(ice->pci),
1095 * independent surround PCMs
1098 static const struct vt1724_pcm_reg vt1724_playback_dma_regs[3] = {
1100 .addr = VT1724_MT_PDMA1_ADDR,
1101 .size = VT1724_MT_PDMA1_SIZE,
1102 .count = VT1724_MT_PDMA1_COUNT,
1103 .start = VT1724_PDMA1_START,
1106 .addr = VT1724_MT_PDMA2_ADDR,
1107 .size = VT1724_MT_PDMA2_SIZE,
1108 .count = VT1724_MT_PDMA2_COUNT,
1109 .start = VT1724_PDMA2_START,
1112 .addr = VT1724_MT_PDMA3_ADDR,
1113 .size = VT1724_MT_PDMA3_SIZE,
1114 .count = VT1724_MT_PDMA3_COUNT,
1115 .start = VT1724_PDMA3_START,
1119 static int snd_vt1724_playback_indep_prepare(struct snd_pcm_substream *substream)
1121 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1124 spin_lock_irq(&ice->reg_lock);
1125 val = 3 - substream->number;
1126 if (inb(ICEMT1724(ice, BURST)) < val)
1127 outb(val, ICEMT1724(ice, BURST));
1128 spin_unlock_irq(&ice->reg_lock);
1129 return snd_vt1724_pcm_prepare(substream);
1132 static int snd_vt1724_playback_indep_open(struct snd_pcm_substream *substream)
1134 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1135 struct snd_pcm_runtime *runtime = substream->runtime;
1137 mutex_lock(&ice->open_mutex);
1138 /* already used by PDMA0? */
1139 if (ice->pcm_reserved[substream->number]) {
1140 mutex_unlock(&ice->open_mutex);
1141 return -EBUSY; /* FIXME: should handle blocking mode properly */
1143 mutex_unlock(&ice->open_mutex);
1144 runtime->private_data = (void *)&vt1724_playback_dma_regs[substream->number];
1145 ice->playback_con_substream_ds[substream->number] = substream;
1146 runtime->hw = snd_vt1724_2ch_stereo;
1147 snd_pcm_set_sync(substream);
1148 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
1149 set_rate_constraints(ice, substream);
1153 static int snd_vt1724_playback_indep_close(struct snd_pcm_substream *substream)
1155 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1158 snd_vt1724_set_pro_rate(ice, ice->pro_rate_default, 0);
1159 ice->playback_con_substream_ds[substream->number] = NULL;
1160 ice->pcm_reserved[substream->number] = NULL;
1165 static struct snd_pcm_ops snd_vt1724_playback_indep_ops = {
1166 .open = snd_vt1724_playback_indep_open,
1167 .close = snd_vt1724_playback_indep_close,
1168 .ioctl = snd_pcm_lib_ioctl,
1169 .hw_params = snd_vt1724_pcm_hw_params,
1170 .hw_free = snd_vt1724_pcm_hw_free,
1171 .prepare = snd_vt1724_playback_indep_prepare,
1172 .trigger = snd_vt1724_pcm_trigger,
1173 .pointer = snd_vt1724_pcm_pointer,
1177 static int __devinit snd_vt1724_pcm_indep(struct snd_ice1712 * ice, int device)
1179 struct snd_pcm *pcm;
1183 play = ice->num_total_dacs / 2 - 1;
1187 err = snd_pcm_new(ice->card, "ICE1724 Surrounds", device, play, 0, &pcm);
1191 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
1192 &snd_vt1724_playback_indep_ops);
1194 pcm->private_data = ice;
1195 pcm->info_flags = 0;
1196 strcpy(pcm->name, "ICE1724 Surround PCM");
1198 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
1199 snd_dma_pci_data(ice->pci),
1212 static int __devinit snd_vt1724_ac97_mixer(struct snd_ice1712 * ice)
1216 if (! (ice->eeprom.data[ICE_EEP2_ACLINK] & VT1724_CFG_PRO_I2S)) {
1217 struct snd_ac97_bus *pbus;
1218 struct snd_ac97_template ac97;
1219 static struct snd_ac97_bus_ops ops = {
1220 .write = snd_vt1724_ac97_write,
1221 .read = snd_vt1724_ac97_read,
1225 outb(inb(ICEMT1724(ice, AC97_CMD)) | 0x80, ICEMT1724(ice, AC97_CMD));
1226 mdelay(5); /* FIXME */
1227 outb(inb(ICEMT1724(ice, AC97_CMD)) & ~0x80, ICEMT1724(ice, AC97_CMD));
1229 if ((err = snd_ac97_bus(ice->card, 0, &ops, NULL, &pbus)) < 0)
1231 memset(&ac97, 0, sizeof(ac97));
1232 ac97.private_data = ice;
1233 if ((err = snd_ac97_mixer(pbus, &ac97, &ice->ac97)) < 0)
1234 printk(KERN_WARNING "ice1712: cannot initialize pro ac97, skipped\n");
1238 /* I2S mixer only */
1239 strcat(ice->card->mixername, "ICE1724 - multitrack");
1247 static inline unsigned int eeprom_triple(struct snd_ice1712 *ice, int idx)
1249 return (unsigned int)ice->eeprom.data[idx] | \
1250 ((unsigned int)ice->eeprom.data[idx + 1] << 8) | \
1251 ((unsigned int)ice->eeprom.data[idx + 2] << 16);
1254 static void snd_vt1724_proc_read(struct snd_info_entry *entry,
1255 struct snd_info_buffer *buffer)
1257 struct snd_ice1712 *ice = entry->private_data;
1260 snd_iprintf(buffer, "%s\n\n", ice->card->longname);
1261 snd_iprintf(buffer, "EEPROM:\n");
1263 snd_iprintf(buffer, " Subvendor : 0x%x\n", ice->eeprom.subvendor);
1264 snd_iprintf(buffer, " Size : %i bytes\n", ice->eeprom.size);
1265 snd_iprintf(buffer, " Version : %i\n", ice->eeprom.version);
1266 snd_iprintf(buffer, " System Config : 0x%x\n",
1267 ice->eeprom.data[ICE_EEP2_SYSCONF]);
1268 snd_iprintf(buffer, " ACLink : 0x%x\n",
1269 ice->eeprom.data[ICE_EEP2_ACLINK]);
1270 snd_iprintf(buffer, " I2S : 0x%x\n",
1271 ice->eeprom.data[ICE_EEP2_I2S]);
1272 snd_iprintf(buffer, " S/PDIF : 0x%x\n",
1273 ice->eeprom.data[ICE_EEP2_SPDIF]);
1274 snd_iprintf(buffer, " GPIO direction : 0x%x\n",
1275 ice->eeprom.gpiodir);
1276 snd_iprintf(buffer, " GPIO mask : 0x%x\n",
1277 ice->eeprom.gpiomask);
1278 snd_iprintf(buffer, " GPIO state : 0x%x\n",
1279 ice->eeprom.gpiostate);
1280 for (idx = 0x12; idx < ice->eeprom.size; idx++)
1281 snd_iprintf(buffer, " Extra #%02i : 0x%x\n",
1282 idx, ice->eeprom.data[idx]);
1284 snd_iprintf(buffer, "\nRegisters:\n");
1286 snd_iprintf(buffer, " PSDOUT03 : 0x%08x\n",
1287 (unsigned)inl(ICEMT1724(ice, ROUTE_PLAYBACK)));
1288 for (idx = 0x0; idx < 0x20 ; idx++)
1289 snd_iprintf(buffer, " CCS%02x : 0x%02x\n",
1290 idx, inb(ice->port+idx));
1291 for (idx = 0x0; idx < 0x30 ; idx++)
1292 snd_iprintf(buffer, " MT%02x : 0x%02x\n",
1293 idx, inb(ice->profi_port+idx));
1296 static void __devinit snd_vt1724_proc_init(struct snd_ice1712 * ice)
1298 struct snd_info_entry *entry;
1300 if (! snd_card_proc_new(ice->card, "ice1724", &entry))
1301 snd_info_set_text_ops(entry, ice, snd_vt1724_proc_read);
1308 static int snd_vt1724_eeprom_info(struct snd_kcontrol *kcontrol,
1309 struct snd_ctl_elem_info *uinfo)
1311 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
1312 uinfo->count = sizeof(struct snd_ice1712_eeprom);
1316 static int snd_vt1724_eeprom_get(struct snd_kcontrol *kcontrol,
1317 struct snd_ctl_elem_value *ucontrol)
1319 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1321 memcpy(ucontrol->value.bytes.data, &ice->eeprom, sizeof(ice->eeprom));
1325 static struct snd_kcontrol_new snd_vt1724_eeprom __devinitdata = {
1326 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1327 .name = "ICE1724 EEPROM",
1328 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1329 .info = snd_vt1724_eeprom_info,
1330 .get = snd_vt1724_eeprom_get
1335 static int snd_vt1724_spdif_info(struct snd_kcontrol *kcontrol,
1336 struct snd_ctl_elem_info *uinfo)
1338 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1343 static unsigned int encode_spdif_bits(struct snd_aes_iec958 *diga)
1345 unsigned int val, rbits;
1347 val = diga->status[0] & 0x03; /* professional, non-audio */
1350 if ((diga->status[0] & IEC958_AES0_PRO_EMPHASIS) ==
1351 IEC958_AES0_PRO_EMPHASIS_5015)
1353 rbits = (diga->status[4] >> 3) & 0x0f;
1356 case 2: val |= 5 << 12; break; /* 96k */
1357 case 3: val |= 6 << 12; break; /* 192k */
1358 case 10: val |= 4 << 12; break; /* 88.2k */
1359 case 11: val |= 7 << 12; break; /* 176.4k */
1362 switch (diga->status[0] & IEC958_AES0_PRO_FS) {
1363 case IEC958_AES0_PRO_FS_44100:
1365 case IEC958_AES0_PRO_FS_32000:
1375 val |= diga->status[1] & 0x04; /* copyright */
1376 if ((diga->status[0] & IEC958_AES0_CON_EMPHASIS) ==
1377 IEC958_AES0_CON_EMPHASIS_5015)
1379 val |= (unsigned int)(diga->status[1] & 0x3f) << 4; /* category */
1380 val |= (unsigned int)(diga->status[3] & IEC958_AES3_CON_FS) << 12; /* fs */
1385 static void decode_spdif_bits(struct snd_aes_iec958 *diga, unsigned int val)
1387 memset(diga->status, 0, sizeof(diga->status));
1388 diga->status[0] = val & 0x03; /* professional, non-audio */
1391 if (val & (1U << 3))
1392 diga->status[0] |= IEC958_AES0_PRO_EMPHASIS_5015;
1393 switch ((val >> 12) & 0x7) {
1397 diga->status[0] |= IEC958_AES0_PRO_FS_32000;
1400 diga->status[0] |= IEC958_AES0_PRO_FS_48000;
1405 diga->status[0] |= val & (1U << 2); /* copyright */
1406 if (val & (1U << 3))
1407 diga->status[0] |= IEC958_AES0_CON_EMPHASIS_5015;
1408 diga->status[1] |= (val >> 4) & 0x3f; /* category */
1409 diga->status[3] |= (val >> 12) & 0x07; /* fs */
1413 static int snd_vt1724_spdif_default_get(struct snd_kcontrol *kcontrol,
1414 struct snd_ctl_elem_value *ucontrol)
1416 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1418 val = inw(ICEMT1724(ice, SPDIF_CTRL));
1419 decode_spdif_bits(&ucontrol->value.iec958, val);
1423 static int snd_vt1724_spdif_default_put(struct snd_kcontrol *kcontrol,
1424 struct snd_ctl_elem_value *ucontrol)
1426 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1427 unsigned int val, old;
1429 val = encode_spdif_bits(&ucontrol->value.iec958);
1430 spin_lock_irq(&ice->reg_lock);
1431 old = inw(ICEMT1724(ice, SPDIF_CTRL));
1433 update_spdif_bits(ice, val);
1434 spin_unlock_irq(&ice->reg_lock);
1435 return (val != old);
1438 static struct snd_kcontrol_new snd_vt1724_spdif_default __devinitdata =
1440 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1441 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
1442 .info = snd_vt1724_spdif_info,
1443 .get = snd_vt1724_spdif_default_get,
1444 .put = snd_vt1724_spdif_default_put
1447 static int snd_vt1724_spdif_maskc_get(struct snd_kcontrol *kcontrol,
1448 struct snd_ctl_elem_value *ucontrol)
1450 ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO |
1451 IEC958_AES0_PROFESSIONAL |
1452 IEC958_AES0_CON_NOT_COPYRIGHT |
1453 IEC958_AES0_CON_EMPHASIS;
1454 ucontrol->value.iec958.status[1] = IEC958_AES1_CON_ORIGINAL |
1455 IEC958_AES1_CON_CATEGORY;
1456 ucontrol->value.iec958.status[3] = IEC958_AES3_CON_FS;
1460 static int snd_vt1724_spdif_maskp_get(struct snd_kcontrol *kcontrol,
1461 struct snd_ctl_elem_value *ucontrol)
1463 ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO |
1464 IEC958_AES0_PROFESSIONAL |
1465 IEC958_AES0_PRO_FS |
1466 IEC958_AES0_PRO_EMPHASIS;
1470 static struct snd_kcontrol_new snd_vt1724_spdif_maskc __devinitdata =
1472 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1473 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1474 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,CON_MASK),
1475 .info = snd_vt1724_spdif_info,
1476 .get = snd_vt1724_spdif_maskc_get,
1479 static struct snd_kcontrol_new snd_vt1724_spdif_maskp __devinitdata =
1481 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1482 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1483 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PRO_MASK),
1484 .info = snd_vt1724_spdif_info,
1485 .get = snd_vt1724_spdif_maskp_get,
1488 #define snd_vt1724_spdif_sw_info snd_ctl_boolean_mono_info
1490 static int snd_vt1724_spdif_sw_get(struct snd_kcontrol *kcontrol,
1491 struct snd_ctl_elem_value *ucontrol)
1493 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1494 ucontrol->value.integer.value[0] = inb(ICEREG1724(ice, SPDIF_CFG)) &
1495 VT1724_CFG_SPDIF_OUT_EN ? 1 : 0;
1499 static int snd_vt1724_spdif_sw_put(struct snd_kcontrol *kcontrol,
1500 struct snd_ctl_elem_value *ucontrol)
1502 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1503 unsigned char old, val;
1505 spin_lock_irq(&ice->reg_lock);
1506 old = val = inb(ICEREG1724(ice, SPDIF_CFG));
1507 val &= ~VT1724_CFG_SPDIF_OUT_EN;
1508 if (ucontrol->value.integer.value[0])
1509 val |= VT1724_CFG_SPDIF_OUT_EN;
1511 outb(val, ICEREG1724(ice, SPDIF_CFG));
1512 spin_unlock_irq(&ice->reg_lock);
1516 static struct snd_kcontrol_new snd_vt1724_spdif_switch __devinitdata =
1518 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1519 /* FIXME: the following conflict with IEC958 Playback Route */
1520 // .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH),
1521 .name = SNDRV_CTL_NAME_IEC958("Output ",NONE,SWITCH),
1522 .info = snd_vt1724_spdif_sw_info,
1523 .get = snd_vt1724_spdif_sw_get,
1524 .put = snd_vt1724_spdif_sw_put
1528 #if 0 /* NOT USED YET */
1530 * GPIO access from extern
1533 #define snd_vt1724_gpio_info snd_ctl_boolean_mono_info
1535 int snd_vt1724_gpio_get(struct snd_kcontrol *kcontrol,
1536 struct snd_ctl_elem_value *ucontrol)
1538 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1539 int shift = kcontrol->private_value & 0xff;
1540 int invert = (kcontrol->private_value & (1<<24)) ? 1 : 0;
1542 snd_ice1712_save_gpio_status(ice);
1543 ucontrol->value.integer.value[0] =
1544 (snd_ice1712_gpio_read(ice) & (1 << shift) ? 1 : 0) ^ invert;
1545 snd_ice1712_restore_gpio_status(ice);
1549 int snd_ice1712_gpio_put(struct snd_kcontrol *kcontrol,
1550 struct snd_ctl_elem_value *ucontrol)
1552 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1553 int shift = kcontrol->private_value & 0xff;
1554 int invert = (kcontrol->private_value & (1<<24)) ? mask : 0;
1555 unsigned int val, nval;
1557 if (kcontrol->private_value & (1 << 31))
1559 nval = (ucontrol->value.integer.value[0] ? (1 << shift) : 0) ^ invert;
1560 snd_ice1712_save_gpio_status(ice);
1561 val = snd_ice1712_gpio_read(ice);
1562 nval |= val & ~(1 << shift);
1564 snd_ice1712_gpio_write(ice, nval);
1565 snd_ice1712_restore_gpio_status(ice);
1568 #endif /* NOT USED YET */
1573 static int snd_vt1724_pro_internal_clock_info(struct snd_kcontrol *kcontrol,
1574 struct snd_ctl_elem_info *uinfo)
1576 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1578 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1580 uinfo->value.enumerated.items = ice->hw_rates->count + 1;
1581 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1582 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1583 if (uinfo->value.enumerated.item == uinfo->value.enumerated.items - 1)
1584 strcpy(uinfo->value.enumerated.name, "IEC958 Input");
1586 sprintf(uinfo->value.enumerated.name, "%d",
1587 ice->hw_rates->list[uinfo->value.enumerated.item]);
1591 static int snd_vt1724_pro_internal_clock_get(struct snd_kcontrol *kcontrol,
1592 struct snd_ctl_elem_value *ucontrol)
1594 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1595 unsigned int i, rate;
1597 spin_lock_irq(&ice->reg_lock);
1598 if (ice->is_spdif_master(ice)) {
1599 ucontrol->value.enumerated.item[0] = ice->hw_rates->count;
1601 rate = ice->get_rate(ice);
1602 ucontrol->value.enumerated.item[0] = 0;
1603 for (i = 0; i < ice->hw_rates->count; i++) {
1604 if (ice->hw_rates->list[i] == rate) {
1605 ucontrol->value.enumerated.item[0] = i;
1610 spin_unlock_irq(&ice->reg_lock);
1614 /* setting clock to external - SPDIF */
1615 static void stdclock_set_spdif_clock(struct snd_ice1712 *ice)
1618 unsigned char i2s_oval;
1619 oval = inb(ICEMT1724(ice, RATE));
1620 outb(oval | VT1724_SPDIF_MASTER, ICEMT1724(ice, RATE));
1622 i2s_oval = inb(ICEMT1724(ice, I2S_FORMAT));
1623 outb(i2s_oval & ~VT1724_MT_I2S_MCLK_128X, ICEMT1724(ice, I2S_FORMAT));
1626 static int snd_vt1724_pro_internal_clock_put(struct snd_kcontrol *kcontrol,
1627 struct snd_ctl_elem_value *ucontrol)
1629 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1630 unsigned int old_rate, new_rate;
1631 unsigned int item = ucontrol->value.enumerated.item[0];
1632 unsigned int spdif = ice->hw_rates->count;
1637 spin_lock_irq(&ice->reg_lock);
1638 if (ice->is_spdif_master(ice))
1641 old_rate = ice->get_rate(ice);
1642 if (item == spdif) {
1643 /* switching to external clock via SPDIF */
1644 ice->set_spdif_clock(ice);
1647 /* internal on-card clock */
1648 new_rate = ice->hw_rates->list[item];
1649 ice->pro_rate_default = new_rate;
1650 spin_unlock_irq(&ice->reg_lock);
1651 snd_vt1724_set_pro_rate(ice, ice->pro_rate_default, 1);
1652 spin_lock_irq(&ice->reg_lock);
1654 spin_unlock_irq(&ice->reg_lock);
1656 /* the first reset to the SPDIF master mode? */
1657 if (old_rate != new_rate && !new_rate) {
1658 /* notify akm chips as well */
1660 if (ice->gpio.set_pro_rate)
1661 ice->gpio.set_pro_rate(ice, 0);
1662 for (i = 0; i < ice->akm_codecs; i++) {
1663 if (ice->akm[i].ops.set_rate_val)
1664 ice->akm[i].ops.set_rate_val(&ice->akm[i], 0);
1667 return old_rate != new_rate;
1670 static struct snd_kcontrol_new snd_vt1724_pro_internal_clock __devinitdata = {
1671 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1672 .name = "Multi Track Internal Clock",
1673 .info = snd_vt1724_pro_internal_clock_info,
1674 .get = snd_vt1724_pro_internal_clock_get,
1675 .put = snd_vt1724_pro_internal_clock_put
1678 #define snd_vt1724_pro_rate_locking_info snd_ctl_boolean_mono_info
1680 static int snd_vt1724_pro_rate_locking_get(struct snd_kcontrol *kcontrol,
1681 struct snd_ctl_elem_value *ucontrol)
1683 ucontrol->value.integer.value[0] = PRO_RATE_LOCKED;
1687 static int snd_vt1724_pro_rate_locking_put(struct snd_kcontrol *kcontrol,
1688 struct snd_ctl_elem_value *ucontrol)
1690 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1691 int change = 0, nval;
1693 nval = ucontrol->value.integer.value[0] ? 1 : 0;
1694 spin_lock_irq(&ice->reg_lock);
1695 change = PRO_RATE_LOCKED != nval;
1696 PRO_RATE_LOCKED = nval;
1697 spin_unlock_irq(&ice->reg_lock);
1701 static struct snd_kcontrol_new snd_vt1724_pro_rate_locking __devinitdata = {
1702 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1703 .name = "Multi Track Rate Locking",
1704 .info = snd_vt1724_pro_rate_locking_info,
1705 .get = snd_vt1724_pro_rate_locking_get,
1706 .put = snd_vt1724_pro_rate_locking_put
1709 #define snd_vt1724_pro_rate_reset_info snd_ctl_boolean_mono_info
1711 static int snd_vt1724_pro_rate_reset_get(struct snd_kcontrol *kcontrol,
1712 struct snd_ctl_elem_value *ucontrol)
1714 ucontrol->value.integer.value[0] = PRO_RATE_RESET ? 1 : 0;
1718 static int snd_vt1724_pro_rate_reset_put(struct snd_kcontrol *kcontrol,
1719 struct snd_ctl_elem_value *ucontrol)
1721 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1722 int change = 0, nval;
1724 nval = ucontrol->value.integer.value[0] ? 1 : 0;
1725 spin_lock_irq(&ice->reg_lock);
1726 change = PRO_RATE_RESET != nval;
1727 PRO_RATE_RESET = nval;
1728 spin_unlock_irq(&ice->reg_lock);
1732 static struct snd_kcontrol_new snd_vt1724_pro_rate_reset __devinitdata = {
1733 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1734 .name = "Multi Track Rate Reset",
1735 .info = snd_vt1724_pro_rate_reset_info,
1736 .get = snd_vt1724_pro_rate_reset_get,
1737 .put = snd_vt1724_pro_rate_reset_put
1744 static int snd_vt1724_pro_route_info(struct snd_kcontrol *kcontrol,
1745 struct snd_ctl_elem_info *uinfo)
1747 static char *texts[] = {
1749 "H/W In 0", "H/W In 1", /* 1-2 */
1750 "IEC958 In L", "IEC958 In R", /* 3-4 */
1753 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1755 uinfo->value.enumerated.items = 5;
1756 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1757 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1758 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1762 static inline int analog_route_shift(int idx)
1764 return (idx % 2) * 12 + ((idx / 2) * 3) + 8;
1767 static inline int digital_route_shift(int idx)
1772 static int get_route_val(struct snd_ice1712 *ice, int shift)
1775 unsigned char eitem;
1776 static const unsigned char xlate[8] = {
1777 0, 255, 1, 2, 255, 255, 3, 4,
1780 val = inl(ICEMT1724(ice, ROUTE_PLAYBACK));
1782 val &= 7; //we now have 3 bits per output
1791 static int put_route_val(struct snd_ice1712 *ice, unsigned int val, int shift)
1793 unsigned int old_val, nval;
1795 static const unsigned char xroute[8] = {
1797 2, /* PSDIN0 Left */
1798 3, /* PSDIN0 Right */
1800 7, /* SPDIN Right */
1803 nval = xroute[val % 5];
1804 val = old_val = inl(ICEMT1724(ice, ROUTE_PLAYBACK));
1805 val &= ~(0x07 << shift);
1806 val |= nval << shift;
1807 change = val != old_val;
1809 outl(val, ICEMT1724(ice, ROUTE_PLAYBACK));
1813 static int snd_vt1724_pro_route_analog_get(struct snd_kcontrol *kcontrol,
1814 struct snd_ctl_elem_value *ucontrol)
1816 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1817 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1818 ucontrol->value.enumerated.item[0] =
1819 get_route_val(ice, analog_route_shift(idx));
1823 static int snd_vt1724_pro_route_analog_put(struct snd_kcontrol *kcontrol,
1824 struct snd_ctl_elem_value *ucontrol)
1826 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1827 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1828 return put_route_val(ice, ucontrol->value.enumerated.item[0],
1829 analog_route_shift(idx));
1832 static int snd_vt1724_pro_route_spdif_get(struct snd_kcontrol *kcontrol,
1833 struct snd_ctl_elem_value *ucontrol)
1835 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1836 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1837 ucontrol->value.enumerated.item[0] =
1838 get_route_val(ice, digital_route_shift(idx));
1842 static int snd_vt1724_pro_route_spdif_put(struct snd_kcontrol *kcontrol,
1843 struct snd_ctl_elem_value *ucontrol)
1845 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1846 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1847 return put_route_val(ice, ucontrol->value.enumerated.item[0],
1848 digital_route_shift(idx));
1851 static struct snd_kcontrol_new snd_vt1724_mixer_pro_analog_route __devinitdata = {
1852 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1853 .name = "H/W Playback Route",
1854 .info = snd_vt1724_pro_route_info,
1855 .get = snd_vt1724_pro_route_analog_get,
1856 .put = snd_vt1724_pro_route_analog_put,
1859 static struct snd_kcontrol_new snd_vt1724_mixer_pro_spdif_route __devinitdata = {
1860 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1861 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Route",
1862 .info = snd_vt1724_pro_route_info,
1863 .get = snd_vt1724_pro_route_spdif_get,
1864 .put = snd_vt1724_pro_route_spdif_put,
1869 static int snd_vt1724_pro_peak_info(struct snd_kcontrol *kcontrol,
1870 struct snd_ctl_elem_info *uinfo)
1872 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1873 uinfo->count = 22; /* FIXME: for compatibility with ice1712... */
1874 uinfo->value.integer.min = 0;
1875 uinfo->value.integer.max = 255;
1879 static int snd_vt1724_pro_peak_get(struct snd_kcontrol *kcontrol,
1880 struct snd_ctl_elem_value *ucontrol)
1882 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1885 spin_lock_irq(&ice->reg_lock);
1886 for (idx = 0; idx < 22; idx++) {
1887 outb(idx, ICEMT1724(ice, MONITOR_PEAKINDEX));
1888 ucontrol->value.integer.value[idx] =
1889 inb(ICEMT1724(ice, MONITOR_PEAKDATA));
1891 spin_unlock_irq(&ice->reg_lock);
1895 static struct snd_kcontrol_new snd_vt1724_mixer_pro_peak __devinitdata = {
1896 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1897 .name = "Multi Track Peak",
1898 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
1899 .info = snd_vt1724_pro_peak_info,
1900 .get = snd_vt1724_pro_peak_get
1907 static struct snd_ice1712_card_info no_matched __devinitdata;
1909 static struct snd_ice1712_card_info *card_tables[] __devinitdata = {
1910 snd_vt1724_revo_cards,
1911 snd_vt1724_amp_cards,
1912 snd_vt1724_aureon_cards,
1913 snd_vt1720_mobo_cards,
1914 snd_vt1720_pontis_cards,
1915 snd_vt1724_prodigy_hifi_cards,
1916 snd_vt1724_prodigy192_cards,
1917 snd_vt1724_juli_cards,
1918 snd_vt1724_phase_cards,
1919 snd_vt1724_wtm_cards,
1920 snd_vt1724_se_cards,
1928 static void wait_i2c_busy(struct snd_ice1712 *ice)
1931 while ((inb(ICEREG1724(ice, I2C_CTRL)) & VT1724_I2C_BUSY) && t--)
1934 printk(KERN_ERR "ice1724: i2c busy timeout\n");
1937 unsigned char snd_vt1724_read_i2c(struct snd_ice1712 *ice,
1938 unsigned char dev, unsigned char addr)
1942 mutex_lock(&ice->i2c_mutex);
1944 outb(addr, ICEREG1724(ice, I2C_BYTE_ADDR));
1945 outb(dev & ~VT1724_I2C_WRITE, ICEREG1724(ice, I2C_DEV_ADDR));
1947 val = inb(ICEREG1724(ice, I2C_DATA));
1948 mutex_unlock(&ice->i2c_mutex);
1949 //printk("i2c_read: [0x%x,0x%x] = 0x%x\n", dev, addr, val);
1953 void snd_vt1724_write_i2c(struct snd_ice1712 *ice,
1954 unsigned char dev, unsigned char addr, unsigned char data)
1956 mutex_lock(&ice->i2c_mutex);
1958 //printk("i2c_write: [0x%x,0x%x] = 0x%x\n", dev, addr, data);
1959 outb(addr, ICEREG1724(ice, I2C_BYTE_ADDR));
1960 outb(data, ICEREG1724(ice, I2C_DATA));
1961 outb(dev | VT1724_I2C_WRITE, ICEREG1724(ice, I2C_DEV_ADDR));
1963 mutex_unlock(&ice->i2c_mutex);
1966 static int __devinit snd_vt1724_read_eeprom(struct snd_ice1712 *ice,
1967 const char *modelname)
1969 const int dev = 0xa0; /* EEPROM device address */
1970 unsigned int i, size;
1971 struct snd_ice1712_card_info * const *tbl, *c;
1973 if (! modelname || ! *modelname) {
1974 ice->eeprom.subvendor = 0;
1975 if ((inb(ICEREG1724(ice, I2C_CTRL)) & VT1724_I2C_EEPROM) != 0)
1976 ice->eeprom.subvendor =
1977 (snd_vt1724_read_i2c(ice, dev, 0x00) << 0) |
1978 (snd_vt1724_read_i2c(ice, dev, 0x01) << 8) |
1979 (snd_vt1724_read_i2c(ice, dev, 0x02) << 16) |
1980 (snd_vt1724_read_i2c(ice, dev, 0x03) << 24);
1981 if (ice->eeprom.subvendor == 0 ||
1982 ice->eeprom.subvendor == (unsigned int)-1) {
1983 /* invalid subvendor from EEPROM, try the PCI
1984 * subststem ID instead
1987 pci_read_config_word(ice->pci, PCI_SUBSYSTEM_VENDOR_ID,
1989 pci_read_config_word(ice->pci, PCI_SUBSYSTEM_ID, &device);
1990 ice->eeprom.subvendor =
1991 ((unsigned int)swab16(vendor) << 16) | swab16(device);
1992 if (ice->eeprom.subvendor == 0 ||
1993 ice->eeprom.subvendor == (unsigned int)-1) {
1994 printk(KERN_ERR "ice1724: No valid ID is found\n");
1999 for (tbl = card_tables; *tbl; tbl++) {
2000 for (c = *tbl; c->subvendor; c++) {
2001 if (modelname && c->model &&
2002 ! strcmp(modelname, c->model)) {
2003 printk(KERN_INFO "ice1724: Using board model %s\n",
2005 ice->eeprom.subvendor = c->subvendor;
2006 } else if (c->subvendor != ice->eeprom.subvendor)
2008 if (! c->eeprom_size || ! c->eeprom_data)
2010 /* if the EEPROM is given by the driver, use it */
2011 snd_printdd("using the defined eeprom..\n");
2012 ice->eeprom.version = 2;
2013 ice->eeprom.size = c->eeprom_size + 6;
2014 memcpy(ice->eeprom.data, c->eeprom_data, c->eeprom_size);
2018 printk(KERN_WARNING "ice1724: No matching model found for ID 0x%x\n",
2019 ice->eeprom.subvendor);
2022 ice->eeprom.size = snd_vt1724_read_i2c(ice, dev, 0x04);
2023 if (ice->eeprom.size < 6)
2024 ice->eeprom.size = 32;
2025 else if (ice->eeprom.size > 32) {
2026 printk(KERN_ERR "ice1724: Invalid EEPROM (size = %i)\n",
2030 ice->eeprom.version = snd_vt1724_read_i2c(ice, dev, 0x05);
2031 if (ice->eeprom.version != 2)
2032 printk(KERN_WARNING "ice1724: Invalid EEPROM version %i\n",
2033 ice->eeprom.version);
2034 size = ice->eeprom.size - 6;
2035 for (i = 0; i < size; i++)
2036 ice->eeprom.data[i] = snd_vt1724_read_i2c(ice, dev, i + 6);
2039 ice->eeprom.gpiomask = eeprom_triple(ice, ICE_EEP2_GPIO_MASK);
2040 ice->eeprom.gpiostate = eeprom_triple(ice, ICE_EEP2_GPIO_STATE);
2041 ice->eeprom.gpiodir = eeprom_triple(ice, ICE_EEP2_GPIO_DIR);
2048 static void __devinit snd_vt1724_chip_reset(struct snd_ice1712 *ice)
2050 outb(VT1724_RESET , ICEREG1724(ice, CONTROL));
2052 outb(0, ICEREG1724(ice, CONTROL));
2056 static int __devinit snd_vt1724_chip_init(struct snd_ice1712 *ice)
2058 outb(ice->eeprom.data[ICE_EEP2_SYSCONF], ICEREG1724(ice, SYS_CFG));
2059 outb(ice->eeprom.data[ICE_EEP2_ACLINK], ICEREG1724(ice, AC97_CFG));
2060 outb(ice->eeprom.data[ICE_EEP2_I2S], ICEREG1724(ice, I2S_FEATURES));
2061 outb(ice->eeprom.data[ICE_EEP2_SPDIF], ICEREG1724(ice, SPDIF_CFG));
2063 ice->gpio.write_mask = ice->eeprom.gpiomask;
2064 ice->gpio.direction = ice->eeprom.gpiodir;
2065 snd_vt1724_set_gpio_mask(ice, ice->eeprom.gpiomask);
2066 snd_vt1724_set_gpio_dir(ice, ice->eeprom.gpiodir);
2067 snd_vt1724_set_gpio_data(ice, ice->eeprom.gpiostate);
2069 outb(0, ICEREG1724(ice, POWERDOWN));
2074 static int __devinit snd_vt1724_spdif_build_controls(struct snd_ice1712 *ice)
2077 struct snd_kcontrol *kctl;
2079 snd_assert(ice->pcm != NULL, return -EIO);
2081 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_mixer_pro_spdif_route, ice));
2085 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_spdif_switch, ice));
2089 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_vt1724_spdif_default, ice));
2092 kctl->id.device = ice->pcm->device;
2093 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_vt1724_spdif_maskc, ice));
2096 kctl->id.device = ice->pcm->device;
2097 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_vt1724_spdif_maskp, ice));
2100 kctl->id.device = ice->pcm->device;
2101 #if 0 /* use default only */
2102 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_vt1724_spdif_stream, ice));
2105 kctl->id.device = ice->pcm->device;
2106 ice->spdif.stream_ctl = kctl;
2112 static int __devinit snd_vt1724_build_controls(struct snd_ice1712 *ice)
2116 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_eeprom, ice));
2119 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_pro_internal_clock, ice));
2123 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_pro_rate_locking, ice));
2126 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_pro_rate_reset, ice));
2130 if (ice->num_total_dacs > 0) {
2131 struct snd_kcontrol_new tmp = snd_vt1724_mixer_pro_analog_route;
2132 tmp.count = ice->num_total_dacs;
2133 if (ice->vt1720 && tmp.count > 2)
2135 err = snd_ctl_add(ice->card, snd_ctl_new1(&tmp, ice));
2140 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_mixer_pro_peak, ice));
2147 static int snd_vt1724_free(struct snd_ice1712 *ice)
2151 /* mask all interrupts */
2152 outb(0xff, ICEMT1724(ice, DMA_INT_MASK));
2153 outb(0xff, ICEREG1724(ice, IRQMASK));
2157 free_irq(ice->irq, ice);
2158 pci_release_regions(ice->pci);
2159 snd_ice1712_akm4xxx_free(ice);
2160 pci_disable_device(ice->pci);
2166 static int snd_vt1724_dev_free(struct snd_device *device)
2168 struct snd_ice1712 *ice = device->device_data;
2169 return snd_vt1724_free(ice);
2172 static int __devinit snd_vt1724_create(struct snd_card *card,
2173 struct pci_dev *pci,
2174 const char *modelname,
2175 struct snd_ice1712 ** r_ice1712)
2177 struct snd_ice1712 *ice;
2180 static struct snd_device_ops ops = {
2181 .dev_free = snd_vt1724_dev_free,
2186 /* enable PCI device */
2187 if ((err = pci_enable_device(pci)) < 0)
2190 ice = kzalloc(sizeof(*ice), GFP_KERNEL);
2192 pci_disable_device(pci);
2196 spin_lock_init(&ice->reg_lock);
2197 mutex_init(&ice->gpio_mutex);
2198 mutex_init(&ice->open_mutex);
2199 mutex_init(&ice->i2c_mutex);
2200 ice->gpio.set_mask = snd_vt1724_set_gpio_mask;
2201 ice->gpio.set_dir = snd_vt1724_set_gpio_dir;
2202 ice->gpio.set_data = snd_vt1724_set_gpio_data;
2203 ice->gpio.get_data = snd_vt1724_get_gpio_data;
2207 pci_set_master(pci);
2208 snd_vt1724_proc_init(ice);
2209 synchronize_irq(pci->irq);
2211 if ((err = pci_request_regions(pci, "ICE1724")) < 0) {
2213 pci_disable_device(pci);
2216 ice->port = pci_resource_start(pci, 0);
2217 ice->profi_port = pci_resource_start(pci, 1);
2219 if (request_irq(pci->irq, snd_vt1724_interrupt,
2220 IRQF_SHARED, "ICE1724", ice)) {
2221 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
2222 snd_vt1724_free(ice);
2226 ice->irq = pci->irq;
2228 snd_vt1724_chip_reset(ice);
2229 if (snd_vt1724_read_eeprom(ice, modelname) < 0) {
2230 snd_vt1724_free(ice);
2233 if (snd_vt1724_chip_init(ice) < 0) {
2234 snd_vt1724_free(ice);
2238 /* unmask used interrupts */
2239 if (! (ice->eeprom.data[ICE_EEP2_SYSCONF] & VT1724_CFG_MPU401))
2240 mask = VT1724_IRQ_MPU_RX | VT1724_IRQ_MPU_TX;
2243 outb(mask, ICEREG1724(ice, IRQMASK));
2244 /* don't handle FIFO overrun/underruns (just yet),
2245 * since they cause machine lockups
2247 outb(VT1724_MULTI_FIFO_ERR, ICEMT1724(ice, DMA_INT_MASK));
2249 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, ice, &ops)) < 0) {
2250 snd_vt1724_free(ice);
2254 snd_card_set_dev(card, &pci->dev);
2267 static int __devinit snd_vt1724_probe(struct pci_dev *pci,
2268 const struct pci_device_id *pci_id)
2271 struct snd_card *card;
2272 struct snd_ice1712 *ice;
2273 int pcm_dev = 0, err;
2274 struct snd_ice1712_card_info * const *tbl, *c;
2276 if (dev >= SNDRV_CARDS)
2283 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
2287 strcpy(card->driver, "ICE1724");
2288 strcpy(card->shortname, "ICEnsemble ICE1724");
2290 if ((err = snd_vt1724_create(card, pci, model[dev], &ice)) < 0) {
2291 snd_card_free(card);
2295 for (tbl = card_tables; *tbl; tbl++) {
2296 for (c = *tbl; c->subvendor; c++) {
2297 if (c->subvendor == ice->eeprom.subvendor) {
2298 strcpy(card->shortname, c->name);
2299 if (c->driver) /* specific driver? */
2300 strcpy(card->driver, c->driver);
2302 if ((err = c->chip_init(ice)) < 0) {
2303 snd_card_free(card);
2314 * VT1724 has separate DMAs for the analog and the SPDIF streams while
2315 * ICE1712 has only one for both (mixed up).
2317 * Confusingly the analog PCM is named "professional" here because it
2318 * was called so in ice1712 driver, and vt1724 driver is derived from
2321 ice->pro_rate_default = PRO_RATE_DEFAULT;
2322 if (!ice->is_spdif_master)
2323 ice->is_spdif_master = stdclock_is_spdif_master;
2325 ice->get_rate = stdclock_get_rate;
2327 ice->set_rate = stdclock_set_rate;
2329 ice->set_mclk = stdclock_set_mclk;
2330 if (!ice->set_spdif_clock)
2331 ice->set_spdif_clock = stdclock_set_spdif_clock;
2333 set_std_hw_rates(ice);
2335 if ((err = snd_vt1724_pcm_profi(ice, pcm_dev++)) < 0) {
2336 snd_card_free(card);
2340 if ((err = snd_vt1724_pcm_spdif(ice, pcm_dev++)) < 0) {
2341 snd_card_free(card);
2345 if ((err = snd_vt1724_pcm_indep(ice, pcm_dev++)) < 0) {
2346 snd_card_free(card);
2350 if ((err = snd_vt1724_ac97_mixer(ice)) < 0) {
2351 snd_card_free(card);
2355 if ((err = snd_vt1724_build_controls(ice)) < 0) {
2356 snd_card_free(card);
2360 if (ice->pcm && ice->has_spdif) { /* has SPDIF I/O */
2361 if ((err = snd_vt1724_spdif_build_controls(ice)) < 0) {
2362 snd_card_free(card);
2367 if (c->build_controls) {
2368 if ((err = c->build_controls(ice)) < 0) {
2369 snd_card_free(card);
2374 if (! c->no_mpu401) {
2375 if (ice->eeprom.data[ICE_EEP2_SYSCONF] & VT1724_CFG_MPU401) {
2376 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_ICE1712,
2377 ICEREG1724(ice, MPU_CTRL),
2378 MPU401_INFO_INTEGRATED,
2380 &ice->rmidi[0])) < 0) {
2381 snd_card_free(card);
2387 sprintf(card->longname, "%s at 0x%lx, irq %i",
2388 card->shortname, ice->port, ice->irq);
2390 if ((err = snd_card_register(card)) < 0) {
2391 snd_card_free(card);
2394 pci_set_drvdata(pci, card);
2399 static void __devexit snd_vt1724_remove(struct pci_dev *pci)
2401 snd_card_free(pci_get_drvdata(pci));
2402 pci_set_drvdata(pci, NULL);
2405 static struct pci_driver driver = {
2407 .id_table = snd_vt1724_ids,
2408 .probe = snd_vt1724_probe,
2409 .remove = __devexit_p(snd_vt1724_remove),
2412 static int __init alsa_card_ice1724_init(void)
2414 return pci_register_driver(&driver);
2417 static void __exit alsa_card_ice1724_exit(void)
2419 pci_unregister_driver(&driver);
2422 module_init(alsa_card_ice1724_init)
2423 module_exit(alsa_card_ice1724_exit)