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
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 <linux/mutex.h>
34 #include <sound/core.h>
35 #include <sound/info.h>
36 #include <sound/mpu401.h>
37 #include <sound/initval.h>
39 #include <sound/asoundef.h>
44 /* lowlevel routines */
48 #include "vt1720_mobo.h"
50 #include "prodigy192.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
72 "{ICEnsemble,Generic ICE1724},"
73 "{ICEnsemble,Generic Envy24HT}"
74 "{ICEnsemble,Generic Envy24PT}}");
76 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
77 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
78 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */
79 static char *model[SNDRV_CARDS];
81 module_param_array(index, int, NULL, 0444);
82 MODULE_PARM_DESC(index, "Index value for ICE1724 soundcard.");
83 module_param_array(id, charp, NULL, 0444);
84 MODULE_PARM_DESC(id, "ID string for ICE1724 soundcard.");
85 module_param_array(enable, bool, NULL, 0444);
86 MODULE_PARM_DESC(enable, "Enable ICE1724 soundcard.");
87 module_param_array(model, charp, NULL, 0444);
88 MODULE_PARM_DESC(model, "Use the given board model.");
91 /* Both VT1720 and VT1724 have the same PCI IDs */
92 static const struct pci_device_id snd_vt1724_ids[] = {
93 { PCI_VENDOR_ID_ICE, PCI_DEVICE_ID_VT1724, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
97 MODULE_DEVICE_TABLE(pci, snd_vt1724_ids);
100 static int PRO_RATE_LOCKED;
101 static int PRO_RATE_RESET = 1;
102 static unsigned int PRO_RATE_DEFAULT = 44100;
108 /* check whether the clock mode is spdif-in */
109 static inline int is_spdif_master(struct snd_ice1712 *ice)
111 return (inb(ICEMT1724(ice, RATE)) & VT1724_SPDIF_MASTER) ? 1 : 0;
114 static inline int is_pro_rate_locked(struct snd_ice1712 *ice)
116 return is_spdif_master(ice) || PRO_RATE_LOCKED;
123 static unsigned char snd_vt1724_ac97_ready(struct snd_ice1712 *ice)
125 unsigned char old_cmd;
127 for (tm = 0; tm < 0x10000; tm++) {
128 old_cmd = inb(ICEMT1724(ice, AC97_CMD));
129 if (old_cmd & (VT1724_AC97_WRITE | VT1724_AC97_READ))
131 if (!(old_cmd & VT1724_AC97_READY))
135 snd_printd(KERN_ERR "snd_vt1724_ac97_ready: timeout\n");
139 static int snd_vt1724_ac97_wait_bit(struct snd_ice1712 *ice, unsigned char bit)
142 for (tm = 0; tm < 0x10000; tm++)
143 if ((inb(ICEMT1724(ice, AC97_CMD)) & bit) == 0)
145 snd_printd(KERN_ERR "snd_vt1724_ac97_wait_bit: timeout\n");
149 static void snd_vt1724_ac97_write(struct snd_ac97 *ac97,
153 struct snd_ice1712 *ice = ac97->private_data;
154 unsigned char old_cmd;
156 old_cmd = snd_vt1724_ac97_ready(ice);
157 old_cmd &= ~VT1724_AC97_ID_MASK;
158 old_cmd |= ac97->num;
159 outb(reg, ICEMT1724(ice, AC97_INDEX));
160 outw(val, ICEMT1724(ice, AC97_DATA));
161 outb(old_cmd | VT1724_AC97_WRITE, ICEMT1724(ice, AC97_CMD));
162 snd_vt1724_ac97_wait_bit(ice, VT1724_AC97_WRITE);
165 static unsigned short snd_vt1724_ac97_read(struct snd_ac97 *ac97, unsigned short reg)
167 struct snd_ice1712 *ice = ac97->private_data;
168 unsigned char old_cmd;
170 old_cmd = snd_vt1724_ac97_ready(ice);
171 old_cmd &= ~VT1724_AC97_ID_MASK;
172 old_cmd |= ac97->num;
173 outb(reg, ICEMT1724(ice, AC97_INDEX));
174 outb(old_cmd | VT1724_AC97_READ, ICEMT1724(ice, AC97_CMD));
175 if (snd_vt1724_ac97_wait_bit(ice, VT1724_AC97_READ) < 0)
177 return inw(ICEMT1724(ice, AC97_DATA));
185 /* set gpio direction 0 = read, 1 = write */
186 static void snd_vt1724_set_gpio_dir(struct snd_ice1712 *ice, unsigned int data)
188 outl(data, ICEREG1724(ice, GPIO_DIRECTION));
189 inw(ICEREG1724(ice, GPIO_DIRECTION)); /* dummy read for pci-posting */
192 /* set the gpio mask (0 = writable) */
193 static void snd_vt1724_set_gpio_mask(struct snd_ice1712 *ice, unsigned int data)
195 outw(data, ICEREG1724(ice, GPIO_WRITE_MASK));
196 if (! ice->vt1720) /* VT1720 supports only 16 GPIO bits */
197 outb((data >> 16) & 0xff, ICEREG1724(ice, GPIO_WRITE_MASK_22));
198 inw(ICEREG1724(ice, GPIO_WRITE_MASK)); /* dummy read for pci-posting */
201 static void snd_vt1724_set_gpio_data(struct snd_ice1712 *ice, unsigned int data)
203 outw(data, ICEREG1724(ice, GPIO_DATA));
205 outb(data >> 16, ICEREG1724(ice, GPIO_DATA_22));
206 inw(ICEREG1724(ice, GPIO_DATA)); /* dummy read for pci-posting */
209 static unsigned int snd_vt1724_get_gpio_data(struct snd_ice1712 *ice)
213 data = (unsigned int)inb(ICEREG1724(ice, GPIO_DATA_22));
216 data = (data << 16) | inw(ICEREG1724(ice, GPIO_DATA));
224 static irqreturn_t snd_vt1724_interrupt(int irq, void *dev_id)
226 struct snd_ice1712 *ice = dev_id;
227 unsigned char status;
231 status = inb(ICEREG1724(ice, IRQSTAT));
236 /* these should probably be separated at some point,
237 * but as we don't currently have MPU support on the board
240 if ((status & VT1724_IRQ_MPU_RX)||(status & VT1724_IRQ_MPU_TX)) {
242 snd_mpu401_uart_interrupt(irq, ice->rmidi[0]->private_data);
243 outb(status & (VT1724_IRQ_MPU_RX|VT1724_IRQ_MPU_TX), ICEREG1724(ice, IRQSTAT));
244 status &= ~(VT1724_IRQ_MPU_RX|VT1724_IRQ_MPU_TX);
246 if (status & VT1724_IRQ_MTPCM) {
249 * PCM assignment are:
250 * Playback DMA0 (M/C) = playback_pro_substream
251 * Playback DMA1 = playback_con_substream_ds[0]
252 * Playback DMA2 = playback_con_substream_ds[1]
253 * Playback DMA3 = playback_con_substream_ds[2]
254 * Playback DMA4 (SPDIF) = playback_con_substream
255 * Record DMA0 = capture_pro_substream
256 * Record DMA1 = capture_con_substream
258 unsigned char mtstat = inb(ICEMT1724(ice, IRQ));
259 if (mtstat & VT1724_MULTI_PDMA0) {
260 if (ice->playback_pro_substream)
261 snd_pcm_period_elapsed(ice->playback_pro_substream);
263 if (mtstat & VT1724_MULTI_RDMA0) {
264 if (ice->capture_pro_substream)
265 snd_pcm_period_elapsed(ice->capture_pro_substream);
267 if (mtstat & VT1724_MULTI_PDMA1) {
268 if (ice->playback_con_substream_ds[0])
269 snd_pcm_period_elapsed(ice->playback_con_substream_ds[0]);
271 if (mtstat & VT1724_MULTI_PDMA2) {
272 if (ice->playback_con_substream_ds[1])
273 snd_pcm_period_elapsed(ice->playback_con_substream_ds[1]);
275 if (mtstat & VT1724_MULTI_PDMA3) {
276 if (ice->playback_con_substream_ds[2])
277 snd_pcm_period_elapsed(ice->playback_con_substream_ds[2]);
279 if (mtstat & VT1724_MULTI_PDMA4) {
280 if (ice->playback_con_substream)
281 snd_pcm_period_elapsed(ice->playback_con_substream);
283 if (mtstat & VT1724_MULTI_RDMA1) {
284 if (ice->capture_con_substream)
285 snd_pcm_period_elapsed(ice->capture_con_substream);
287 /* ack anyway to avoid freeze */
288 outb(mtstat, ICEMT1724(ice, IRQ));
289 /* ought to really handle this properly */
290 if (mtstat & VT1724_MULTI_FIFO_ERR) {
291 unsigned char fstat = inb(ICEMT1724(ice, DMA_FIFO_ERR));
292 outb(fstat, ICEMT1724(ice, DMA_FIFO_ERR));
293 outb(VT1724_MULTI_FIFO_ERR | inb(ICEMT1724(ice, DMA_INT_MASK)), ICEMT1724(ice, DMA_INT_MASK));
294 /* If I don't do this, I get machine lockup due to continual interrupts */
299 return IRQ_RETVAL(handled);
303 * PCM code - professional part (multitrack)
306 static unsigned int rates[] = {
307 8000, 9600, 11025, 12000, 16000, 22050, 24000,
308 32000, 44100, 48000, 64000, 88200, 96000,
312 static struct snd_pcm_hw_constraint_list hw_constraints_rates_96 = {
313 .count = ARRAY_SIZE(rates) - 2, /* up to 96000 */
318 static struct snd_pcm_hw_constraint_list hw_constraints_rates_48 = {
319 .count = ARRAY_SIZE(rates) - 5, /* up to 48000 */
324 static struct snd_pcm_hw_constraint_list hw_constraints_rates_192 = {
325 .count = ARRAY_SIZE(rates),
330 struct vt1724_pcm_reg {
331 unsigned int addr; /* ADDR register offset */
332 unsigned int size; /* SIZE register offset */
333 unsigned int count; /* COUNT register offset */
334 unsigned int start; /* start & pause bit */
337 static int snd_vt1724_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
339 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
342 struct snd_pcm_substream *s;
345 snd_pcm_group_for_each_entry(s, substream) {
346 if (snd_pcm_substream_chip(s) == ice) {
347 const struct vt1724_pcm_reg *reg;
348 reg = s->runtime->private_data;
350 snd_pcm_trigger_done(s, substream);
355 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
356 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
357 spin_lock(&ice->reg_lock);
358 old = inb(ICEMT1724(ice, DMA_PAUSE));
359 if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH)
363 outb(old, ICEMT1724(ice, DMA_PAUSE));
364 spin_unlock(&ice->reg_lock);
367 case SNDRV_PCM_TRIGGER_START:
368 case SNDRV_PCM_TRIGGER_STOP:
369 spin_lock(&ice->reg_lock);
370 old = inb(ICEMT1724(ice, DMA_CONTROL));
371 if (cmd == SNDRV_PCM_TRIGGER_START)
375 outb(old, ICEMT1724(ice, DMA_CONTROL));
376 spin_unlock(&ice->reg_lock);
388 #define DMA_STARTS (VT1724_RDMA0_START|VT1724_PDMA0_START|VT1724_RDMA1_START|\
389 VT1724_PDMA1_START|VT1724_PDMA2_START|VT1724_PDMA3_START|VT1724_PDMA4_START)
390 #define DMA_PAUSES (VT1724_RDMA0_PAUSE|VT1724_PDMA0_PAUSE|VT1724_RDMA1_PAUSE|\
391 VT1724_PDMA1_PAUSE|VT1724_PDMA2_PAUSE|VT1724_PDMA3_PAUSE|VT1724_PDMA4_PAUSE)
393 static int get_max_rate(struct snd_ice1712 *ice)
395 if (ice->eeprom.data[ICE_EEP2_ACLINK] & VT1724_CFG_PRO_I2S) {
396 if ((ice->eeprom.data[ICE_EEP2_I2S] & 0x08) && !ice->vt1720)
404 static void snd_vt1724_set_pro_rate(struct snd_ice1712 *ice, unsigned int rate,
408 unsigned char val, old;
409 unsigned int i, mclk_change;
411 if (rate > get_max_rate(ice))
415 case 8000: val = 6; break;
416 case 9600: val = 3; break;
417 case 11025: val = 10; break;
418 case 12000: val = 2; break;
419 case 16000: val = 5; break;
420 case 22050: val = 9; break;
421 case 24000: val = 1; break;
422 case 32000: val = 4; break;
423 case 44100: val = 8; break;
424 case 48000: val = 0; break;
425 case 64000: val = 15; break;
426 case 88200: val = 11; break;
427 case 96000: val = 7; break;
428 case 176400: val = 12; break;
429 case 192000: val = 14; break;
436 spin_lock_irqsave(&ice->reg_lock, flags);
437 if ((inb(ICEMT1724(ice, DMA_CONTROL)) & DMA_STARTS) ||
438 (inb(ICEMT1724(ice, DMA_PAUSE)) & DMA_PAUSES)) {
439 /* running? we cannot change the rate now... */
440 spin_unlock_irqrestore(&ice->reg_lock, flags);
443 if (!force && is_pro_rate_locked(ice)) {
444 spin_unlock_irqrestore(&ice->reg_lock, flags);
448 old = inb(ICEMT1724(ice, RATE));
449 if (force || old != val)
450 outb(val, ICEMT1724(ice, RATE));
451 else if (rate == ice->cur_rate) {
452 spin_unlock_irqrestore(&ice->reg_lock, flags);
456 ice->cur_rate = rate;
460 if (ice->eeprom.data[ICE_EEP2_ACLINK] & VT1724_CFG_PRO_I2S) {
461 val = old = inb(ICEMT1724(ice, I2S_FORMAT));
463 val |= VT1724_MT_I2S_MCLK_128X; /* 128x MCLK */
465 val &= ~VT1724_MT_I2S_MCLK_128X; /* 256x MCLK */
467 outb(val, ICEMT1724(ice, I2S_FORMAT));
471 spin_unlock_irqrestore(&ice->reg_lock, flags);
473 if (mclk_change && ice->gpio.i2s_mclk_changed)
474 ice->gpio.i2s_mclk_changed(ice);
475 if (ice->gpio.set_pro_rate)
476 ice->gpio.set_pro_rate(ice, rate);
479 for (i = 0; i < ice->akm_codecs; i++) {
480 if (ice->akm[i].ops.set_rate_val)
481 ice->akm[i].ops.set_rate_val(&ice->akm[i], rate);
483 if (ice->spdif.ops.setup_rate)
484 ice->spdif.ops.setup_rate(ice, rate);
487 static int snd_vt1724_pcm_hw_params(struct snd_pcm_substream *substream,
488 struct snd_pcm_hw_params *hw_params)
490 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
493 chs = params_channels(hw_params);
494 mutex_lock(&ice->open_mutex);
495 /* mark surround channels */
496 if (substream == ice->playback_pro_substream) {
497 /* PDMA0 can be multi-channel up to 8 */
499 for (i = 0; i < chs; i++) {
500 if (ice->pcm_reserved[i] &&
501 ice->pcm_reserved[i] != substream) {
502 mutex_unlock(&ice->open_mutex);
505 ice->pcm_reserved[i] = substream;
508 if (ice->pcm_reserved[i] == substream)
509 ice->pcm_reserved[i] = NULL;
512 for (i = 0; i < 3; i++) {
513 /* check individual playback stream */
514 if (ice->playback_con_substream_ds[i] == substream) {
515 if (ice->pcm_reserved[i] &&
516 ice->pcm_reserved[i] != substream) {
517 mutex_unlock(&ice->open_mutex);
520 ice->pcm_reserved[i] = substream;
525 mutex_unlock(&ice->open_mutex);
526 snd_vt1724_set_pro_rate(ice, params_rate(hw_params), 0);
527 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
530 static int snd_vt1724_pcm_hw_free(struct snd_pcm_substream *substream)
532 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
535 mutex_lock(&ice->open_mutex);
536 /* unmark surround channels */
537 for (i = 0; i < 3; i++)
538 if (ice->pcm_reserved[i] == substream)
539 ice->pcm_reserved[i] = NULL;
540 mutex_unlock(&ice->open_mutex);
541 return snd_pcm_lib_free_pages(substream);
544 static int snd_vt1724_playback_pro_prepare(struct snd_pcm_substream *substream)
546 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
550 spin_lock_irq(&ice->reg_lock);
551 val = (8 - substream->runtime->channels) >> 1;
552 outb(val, ICEMT1724(ice, BURST));
554 outl(substream->runtime->dma_addr, ICEMT1724(ice, PLAYBACK_ADDR));
556 size = (snd_pcm_lib_buffer_bytes(substream) >> 2) - 1;
557 // outl(size, ICEMT1724(ice, PLAYBACK_SIZE));
558 outw(size, ICEMT1724(ice, PLAYBACK_SIZE));
559 outb(size >> 16, ICEMT1724(ice, PLAYBACK_SIZE) + 2);
560 size = (snd_pcm_lib_period_bytes(substream) >> 2) - 1;
561 // outl(size, ICEMT1724(ice, PLAYBACK_COUNT));
562 outw(size, ICEMT1724(ice, PLAYBACK_COUNT));
563 outb(size >> 16, ICEMT1724(ice, PLAYBACK_COUNT) + 2);
565 spin_unlock_irq(&ice->reg_lock);
567 // 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));
571 static snd_pcm_uframes_t snd_vt1724_playback_pro_pointer(struct snd_pcm_substream *substream)
573 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
576 if (!(inl(ICEMT1724(ice, DMA_CONTROL)) & VT1724_PDMA0_START))
578 #if 0 /* read PLAYBACK_ADDR */
579 ptr = inl(ICEMT1724(ice, PLAYBACK_ADDR));
580 if (ptr < substream->runtime->dma_addr) {
581 snd_printd("ice1724: invalid negative ptr\n");
584 ptr -= substream->runtime->dma_addr;
585 ptr = bytes_to_frames(substream->runtime, ptr);
586 if (ptr >= substream->runtime->buffer_size) {
587 snd_printd("ice1724: invalid ptr %d (size=%d)\n",
588 (int)ptr, (int)substream->runtime->period_size);
591 #else /* read PLAYBACK_SIZE */
592 ptr = inl(ICEMT1724(ice, PLAYBACK_SIZE)) & 0xffffff;
593 ptr = (ptr + 1) << 2;
594 ptr = bytes_to_frames(substream->runtime, ptr);
597 else if (ptr <= substream->runtime->buffer_size)
598 ptr = substream->runtime->buffer_size - ptr;
600 snd_printd("ice1724: invalid ptr %d (size=%d)\n",
601 (int)ptr, (int)substream->runtime->buffer_size);
608 static int snd_vt1724_pcm_prepare(struct snd_pcm_substream *substream)
610 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
611 const struct vt1724_pcm_reg *reg = substream->runtime->private_data;
613 spin_lock_irq(&ice->reg_lock);
614 outl(substream->runtime->dma_addr, ice->profi_port + reg->addr);
615 outw((snd_pcm_lib_buffer_bytes(substream) >> 2) - 1,
616 ice->profi_port + reg->size);
617 outw((snd_pcm_lib_period_bytes(substream) >> 2) - 1,
618 ice->profi_port + reg->count);
619 spin_unlock_irq(&ice->reg_lock);
623 static snd_pcm_uframes_t snd_vt1724_pcm_pointer(struct snd_pcm_substream *substream)
625 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
626 const struct vt1724_pcm_reg *reg = substream->runtime->private_data;
629 if (!(inl(ICEMT1724(ice, DMA_CONTROL)) & reg->start))
631 #if 0 /* use ADDR register */
632 ptr = inl(ice->profi_port + reg->addr);
633 ptr -= substream->runtime->dma_addr;
634 return bytes_to_frames(substream->runtime, ptr);
635 #else /* use SIZE register */
636 ptr = inw(ice->profi_port + reg->size);
637 ptr = (ptr + 1) << 2;
638 ptr = bytes_to_frames(substream->runtime, ptr);
641 else if (ptr <= substream->runtime->buffer_size)
642 ptr = substream->runtime->buffer_size - ptr;
644 snd_printd("ice1724: invalid ptr %d (size=%d)\n",
645 (int)ptr, (int)substream->runtime->buffer_size);
652 static const struct vt1724_pcm_reg vt1724_playback_pro_reg = {
653 .addr = VT1724_MT_PLAYBACK_ADDR,
654 .size = VT1724_MT_PLAYBACK_SIZE,
655 .count = VT1724_MT_PLAYBACK_COUNT,
656 .start = VT1724_PDMA0_START,
659 static const struct vt1724_pcm_reg vt1724_capture_pro_reg = {
660 .addr = VT1724_MT_CAPTURE_ADDR,
661 .size = VT1724_MT_CAPTURE_SIZE,
662 .count = VT1724_MT_CAPTURE_COUNT,
663 .start = VT1724_RDMA0_START,
666 static const struct snd_pcm_hardware snd_vt1724_playback_pro =
668 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
669 SNDRV_PCM_INFO_BLOCK_TRANSFER |
670 SNDRV_PCM_INFO_MMAP_VALID |
671 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START),
672 .formats = SNDRV_PCM_FMTBIT_S32_LE,
673 .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_192000,
678 .buffer_bytes_max = (1UL << 21), /* 19bits dword */
679 .period_bytes_min = 8 * 4 * 2, /* FIXME: constraints needed */
680 .period_bytes_max = (1UL << 21),
685 static const struct snd_pcm_hardware snd_vt1724_spdif =
687 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
688 SNDRV_PCM_INFO_BLOCK_TRANSFER |
689 SNDRV_PCM_INFO_MMAP_VALID |
690 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START),
691 .formats = SNDRV_PCM_FMTBIT_S32_LE,
692 .rates = (SNDRV_PCM_RATE_32000|SNDRV_PCM_RATE_44100|
693 SNDRV_PCM_RATE_48000|SNDRV_PCM_RATE_88200|
694 SNDRV_PCM_RATE_96000|SNDRV_PCM_RATE_176400|
695 SNDRV_PCM_RATE_192000),
700 .buffer_bytes_max = (1UL << 18), /* 16bits dword */
701 .period_bytes_min = 2 * 4 * 2,
702 .period_bytes_max = (1UL << 18),
707 static const struct snd_pcm_hardware snd_vt1724_2ch_stereo =
709 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
710 SNDRV_PCM_INFO_BLOCK_TRANSFER |
711 SNDRV_PCM_INFO_MMAP_VALID |
712 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START),
713 .formats = SNDRV_PCM_FMTBIT_S32_LE,
714 .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_192000,
719 .buffer_bytes_max = (1UL << 18), /* 16bits dword */
720 .period_bytes_min = 2 * 4 * 2,
721 .period_bytes_max = (1UL << 18),
727 * set rate constraints
729 static int set_rate_constraints(struct snd_ice1712 *ice,
730 struct snd_pcm_substream *substream)
732 struct snd_pcm_runtime *runtime = substream->runtime;
734 /* hardware specific */
735 runtime->hw.rate_min = ice->hw_rates->list[0];
736 runtime->hw.rate_max = ice->hw_rates->list[ice->hw_rates->count - 1];
737 runtime->hw.rates = SNDRV_PCM_RATE_KNOT;
738 return snd_pcm_hw_constraint_list(runtime, 0,
739 SNDRV_PCM_HW_PARAM_RATE,
742 if (ice->eeprom.data[ICE_EEP2_ACLINK] & VT1724_CFG_PRO_I2S) {
744 /* VT1720 doesn't support more than 96kHz */
745 if ((ice->eeprom.data[ICE_EEP2_I2S] & 0x08) && !ice->vt1720)
746 return snd_pcm_hw_constraint_list(runtime, 0,
747 SNDRV_PCM_HW_PARAM_RATE,
748 &hw_constraints_rates_192);
750 runtime->hw.rates = SNDRV_PCM_RATE_KNOT |
751 SNDRV_PCM_RATE_8000_96000;
752 runtime->hw.rate_max = 96000;
753 return snd_pcm_hw_constraint_list(runtime, 0,
754 SNDRV_PCM_HW_PARAM_RATE,
755 &hw_constraints_rates_96);
757 } else if (ice->ac97) {
759 runtime->hw.rate_max = 48000;
760 runtime->hw.rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000;
761 return snd_pcm_hw_constraint_list(runtime, 0,
762 SNDRV_PCM_HW_PARAM_RATE,
763 &hw_constraints_rates_48);
768 /* multi-channel playback needs alignment 8x32bit regardless of the channels
771 #define VT1724_BUFFER_ALIGN 0x20
773 static int snd_vt1724_playback_pro_open(struct snd_pcm_substream *substream)
775 struct snd_pcm_runtime *runtime = substream->runtime;
776 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
779 runtime->private_data = (void *)&vt1724_playback_pro_reg;
780 ice->playback_pro_substream = substream;
781 runtime->hw = snd_vt1724_playback_pro;
782 snd_pcm_set_sync(substream);
783 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
784 set_rate_constraints(ice, substream);
785 mutex_lock(&ice->open_mutex);
786 /* calculate the currently available channels */
787 for (chs = 0; chs < 3; chs++) {
788 if (ice->pcm_reserved[chs])
792 runtime->hw.channels_max = chs;
793 if (chs > 2) /* channels must be even */
794 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, 2);
795 mutex_unlock(&ice->open_mutex);
796 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
797 VT1724_BUFFER_ALIGN);
798 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
799 VT1724_BUFFER_ALIGN);
803 static int snd_vt1724_capture_pro_open(struct snd_pcm_substream *substream)
805 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
806 struct snd_pcm_runtime *runtime = substream->runtime;
808 runtime->private_data = (void *)&vt1724_capture_pro_reg;
809 ice->capture_pro_substream = substream;
810 runtime->hw = snd_vt1724_2ch_stereo;
811 snd_pcm_set_sync(substream);
812 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
813 set_rate_constraints(ice, substream);
814 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
815 VT1724_BUFFER_ALIGN);
816 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
817 VT1724_BUFFER_ALIGN);
821 static int snd_vt1724_playback_pro_close(struct snd_pcm_substream *substream)
823 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
826 snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
827 ice->playback_pro_substream = NULL;
832 static int snd_vt1724_capture_pro_close(struct snd_pcm_substream *substream)
834 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
837 snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
838 ice->capture_pro_substream = NULL;
842 static struct snd_pcm_ops snd_vt1724_playback_pro_ops = {
843 .open = snd_vt1724_playback_pro_open,
844 .close = snd_vt1724_playback_pro_close,
845 .ioctl = snd_pcm_lib_ioctl,
846 .hw_params = snd_vt1724_pcm_hw_params,
847 .hw_free = snd_vt1724_pcm_hw_free,
848 .prepare = snd_vt1724_playback_pro_prepare,
849 .trigger = snd_vt1724_pcm_trigger,
850 .pointer = snd_vt1724_playback_pro_pointer,
853 static struct snd_pcm_ops snd_vt1724_capture_pro_ops = {
854 .open = snd_vt1724_capture_pro_open,
855 .close = snd_vt1724_capture_pro_close,
856 .ioctl = snd_pcm_lib_ioctl,
857 .hw_params = snd_vt1724_pcm_hw_params,
858 .hw_free = snd_vt1724_pcm_hw_free,
859 .prepare = snd_vt1724_pcm_prepare,
860 .trigger = snd_vt1724_pcm_trigger,
861 .pointer = snd_vt1724_pcm_pointer,
864 static int __devinit snd_vt1724_pcm_profi(struct snd_ice1712 * ice, int device)
869 err = snd_pcm_new(ice->card, "ICE1724", device, 1, 1, &pcm);
873 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_vt1724_playback_pro_ops);
874 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_vt1724_capture_pro_ops);
876 pcm->private_data = ice;
878 strcpy(pcm->name, "ICE1724");
880 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
881 snd_dma_pci_data(ice->pci),
894 static const struct vt1724_pcm_reg vt1724_playback_spdif_reg = {
895 .addr = VT1724_MT_PDMA4_ADDR,
896 .size = VT1724_MT_PDMA4_SIZE,
897 .count = VT1724_MT_PDMA4_COUNT,
898 .start = VT1724_PDMA4_START,
901 static const struct vt1724_pcm_reg vt1724_capture_spdif_reg = {
902 .addr = VT1724_MT_RDMA1_ADDR,
903 .size = VT1724_MT_RDMA1_SIZE,
904 .count = VT1724_MT_RDMA1_COUNT,
905 .start = VT1724_RDMA1_START,
908 /* update spdif control bits; call with reg_lock */
909 static void update_spdif_bits(struct snd_ice1712 *ice, unsigned int val)
911 unsigned char cbit, disabled;
913 cbit = inb(ICEREG1724(ice, SPDIF_CFG));
914 disabled = cbit & ~VT1724_CFG_SPDIF_OUT_EN;
915 if (cbit != disabled)
916 outb(disabled, ICEREG1724(ice, SPDIF_CFG));
917 outw(val, ICEMT1724(ice, SPDIF_CTRL));
918 if (cbit != disabled)
919 outb(cbit, ICEREG1724(ice, SPDIF_CFG));
920 outw(val, ICEMT1724(ice, SPDIF_CTRL));
923 /* update SPDIF control bits according to the given rate */
924 static void update_spdif_rate(struct snd_ice1712 *ice, unsigned int rate)
926 unsigned int val, nval;
929 spin_lock_irqsave(&ice->reg_lock, flags);
930 nval = val = inw(ICEMT1724(ice, SPDIF_CTRL));
934 case 48000: nval |= 2 << 12; break;
935 case 32000: nval |= 3 << 12; break;
936 case 88200: nval |= 4 << 12; break;
937 case 96000: nval |= 5 << 12; break;
938 case 192000: nval |= 6 << 12; break;
939 case 176400: nval |= 7 << 12; break;
942 update_spdif_bits(ice, nval);
943 spin_unlock_irqrestore(&ice->reg_lock, flags);
946 static int snd_vt1724_playback_spdif_prepare(struct snd_pcm_substream *substream)
948 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
949 if (! ice->force_pdma4)
950 update_spdif_rate(ice, substream->runtime->rate);
951 return snd_vt1724_pcm_prepare(substream);
954 static int snd_vt1724_playback_spdif_open(struct snd_pcm_substream *substream)
956 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
957 struct snd_pcm_runtime *runtime = substream->runtime;
959 runtime->private_data = (void *)&vt1724_playback_spdif_reg;
960 ice->playback_con_substream = substream;
961 if (ice->force_pdma4) {
962 runtime->hw = snd_vt1724_2ch_stereo;
963 set_rate_constraints(ice, substream);
965 runtime->hw = snd_vt1724_spdif;
966 snd_pcm_set_sync(substream);
967 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
968 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
969 VT1724_BUFFER_ALIGN);
970 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
971 VT1724_BUFFER_ALIGN);
975 static int snd_vt1724_playback_spdif_close(struct snd_pcm_substream *substream)
977 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
980 snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
981 ice->playback_con_substream = NULL;
986 static int snd_vt1724_capture_spdif_open(struct snd_pcm_substream *substream)
988 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
989 struct snd_pcm_runtime *runtime = substream->runtime;
991 runtime->private_data = (void *)&vt1724_capture_spdif_reg;
992 ice->capture_con_substream = substream;
993 if (ice->force_rdma1) {
994 runtime->hw = snd_vt1724_2ch_stereo;
995 set_rate_constraints(ice, substream);
997 runtime->hw = snd_vt1724_spdif;
998 snd_pcm_set_sync(substream);
999 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
1000 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
1001 VT1724_BUFFER_ALIGN);
1002 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
1003 VT1724_BUFFER_ALIGN);
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, PRO_RATE_DEFAULT, 0);
1013 ice->capture_con_substream = NULL;
1018 static struct snd_pcm_ops snd_vt1724_playback_spdif_ops = {
1019 .open = snd_vt1724_playback_spdif_open,
1020 .close = snd_vt1724_playback_spdif_close,
1021 .ioctl = snd_pcm_lib_ioctl,
1022 .hw_params = snd_vt1724_pcm_hw_params,
1023 .hw_free = snd_vt1724_pcm_hw_free,
1024 .prepare = snd_vt1724_playback_spdif_prepare,
1025 .trigger = snd_vt1724_pcm_trigger,
1026 .pointer = snd_vt1724_pcm_pointer,
1029 static struct snd_pcm_ops snd_vt1724_capture_spdif_ops = {
1030 .open = snd_vt1724_capture_spdif_open,
1031 .close = snd_vt1724_capture_spdif_close,
1032 .ioctl = snd_pcm_lib_ioctl,
1033 .hw_params = snd_vt1724_pcm_hw_params,
1034 .hw_free = snd_vt1724_pcm_hw_free,
1035 .prepare = snd_vt1724_pcm_prepare,
1036 .trigger = snd_vt1724_pcm_trigger,
1037 .pointer = snd_vt1724_pcm_pointer,
1041 static int __devinit snd_vt1724_pcm_spdif(struct snd_ice1712 * ice, int device)
1044 struct snd_pcm *pcm;
1048 if (ice->force_pdma4 ||
1049 (ice->eeprom.data[ICE_EEP2_SPDIF] & VT1724_CFG_SPDIF_OUT_INT)) {
1054 if (ice->force_rdma1 ||
1055 (ice->eeprom.data[ICE_EEP2_SPDIF] & VT1724_CFG_SPDIF_IN)) {
1060 if (! play && ! capt)
1061 return 0; /* no spdif device */
1063 if (ice->force_pdma4 || ice->force_rdma1)
1064 name = "ICE1724 Secondary";
1066 name = "IEC1724 IEC958";
1067 err = snd_pcm_new(ice->card, name, device, play, capt, &pcm);
1072 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
1073 &snd_vt1724_playback_spdif_ops);
1075 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
1076 &snd_vt1724_capture_spdif_ops);
1078 pcm->private_data = ice;
1079 pcm->info_flags = 0;
1080 strcpy(pcm->name, name);
1082 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
1083 snd_dma_pci_data(ice->pci),
1093 * independent surround PCMs
1096 static const struct vt1724_pcm_reg vt1724_playback_dma_regs[3] = {
1098 .addr = VT1724_MT_PDMA1_ADDR,
1099 .size = VT1724_MT_PDMA1_SIZE,
1100 .count = VT1724_MT_PDMA1_COUNT,
1101 .start = VT1724_PDMA1_START,
1104 .addr = VT1724_MT_PDMA2_ADDR,
1105 .size = VT1724_MT_PDMA2_SIZE,
1106 .count = VT1724_MT_PDMA2_COUNT,
1107 .start = VT1724_PDMA2_START,
1110 .addr = VT1724_MT_PDMA3_ADDR,
1111 .size = VT1724_MT_PDMA3_SIZE,
1112 .count = VT1724_MT_PDMA3_COUNT,
1113 .start = VT1724_PDMA3_START,
1117 static int snd_vt1724_playback_indep_prepare(struct snd_pcm_substream *substream)
1119 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1122 spin_lock_irq(&ice->reg_lock);
1123 val = 3 - substream->number;
1124 if (inb(ICEMT1724(ice, BURST)) < val)
1125 outb(val, ICEMT1724(ice, BURST));
1126 spin_unlock_irq(&ice->reg_lock);
1127 return snd_vt1724_pcm_prepare(substream);
1130 static int snd_vt1724_playback_indep_open(struct snd_pcm_substream *substream)
1132 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1133 struct snd_pcm_runtime *runtime = substream->runtime;
1135 mutex_lock(&ice->open_mutex);
1136 /* already used by PDMA0? */
1137 if (ice->pcm_reserved[substream->number]) {
1138 mutex_unlock(&ice->open_mutex);
1139 return -EBUSY; /* FIXME: should handle blocking mode properly */
1141 mutex_unlock(&ice->open_mutex);
1142 runtime->private_data = (void *)&vt1724_playback_dma_regs[substream->number];
1143 ice->playback_con_substream_ds[substream->number] = substream;
1144 runtime->hw = snd_vt1724_2ch_stereo;
1145 snd_pcm_set_sync(substream);
1146 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
1147 set_rate_constraints(ice, substream);
1151 static int snd_vt1724_playback_indep_close(struct snd_pcm_substream *substream)
1153 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1156 snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
1157 ice->playback_con_substream_ds[substream->number] = NULL;
1158 ice->pcm_reserved[substream->number] = NULL;
1163 static struct snd_pcm_ops snd_vt1724_playback_indep_ops = {
1164 .open = snd_vt1724_playback_indep_open,
1165 .close = snd_vt1724_playback_indep_close,
1166 .ioctl = snd_pcm_lib_ioctl,
1167 .hw_params = snd_vt1724_pcm_hw_params,
1168 .hw_free = snd_vt1724_pcm_hw_free,
1169 .prepare = snd_vt1724_playback_indep_prepare,
1170 .trigger = snd_vt1724_pcm_trigger,
1171 .pointer = snd_vt1724_pcm_pointer,
1175 static int __devinit snd_vt1724_pcm_indep(struct snd_ice1712 * ice, int device)
1177 struct snd_pcm *pcm;
1181 play = ice->num_total_dacs / 2 - 1;
1185 err = snd_pcm_new(ice->card, "ICE1724 Surrounds", device, play, 0, &pcm);
1189 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
1190 &snd_vt1724_playback_indep_ops);
1192 pcm->private_data = ice;
1193 pcm->info_flags = 0;
1194 strcpy(pcm->name, "ICE1724 Surround PCM");
1196 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
1197 snd_dma_pci_data(ice->pci),
1210 static int __devinit snd_vt1724_ac97_mixer(struct snd_ice1712 * ice)
1214 if (! (ice->eeprom.data[ICE_EEP2_ACLINK] & VT1724_CFG_PRO_I2S)) {
1215 struct snd_ac97_bus *pbus;
1216 struct snd_ac97_template ac97;
1217 static struct snd_ac97_bus_ops ops = {
1218 .write = snd_vt1724_ac97_write,
1219 .read = snd_vt1724_ac97_read,
1223 outb(inb(ICEMT1724(ice, AC97_CMD)) | 0x80, ICEMT1724(ice, AC97_CMD));
1224 mdelay(5); /* FIXME */
1225 outb(inb(ICEMT1724(ice, AC97_CMD)) & ~0x80, ICEMT1724(ice, AC97_CMD));
1227 if ((err = snd_ac97_bus(ice->card, 0, &ops, NULL, &pbus)) < 0)
1229 memset(&ac97, 0, sizeof(ac97));
1230 ac97.private_data = ice;
1231 if ((err = snd_ac97_mixer(pbus, &ac97, &ice->ac97)) < 0)
1232 printk(KERN_WARNING "ice1712: cannot initialize pro ac97, skipped\n");
1236 /* I2S mixer only */
1237 strcat(ice->card->mixername, "ICE1724 - multitrack");
1245 static inline unsigned int eeprom_triple(struct snd_ice1712 *ice, int idx)
1247 return (unsigned int)ice->eeprom.data[idx] | \
1248 ((unsigned int)ice->eeprom.data[idx + 1] << 8) | \
1249 ((unsigned int)ice->eeprom.data[idx + 2] << 16);
1252 static void snd_vt1724_proc_read(struct snd_info_entry *entry,
1253 struct snd_info_buffer *buffer)
1255 struct snd_ice1712 *ice = entry->private_data;
1258 snd_iprintf(buffer, "%s\n\n", ice->card->longname);
1259 snd_iprintf(buffer, "EEPROM:\n");
1261 snd_iprintf(buffer, " Subvendor : 0x%x\n", ice->eeprom.subvendor);
1262 snd_iprintf(buffer, " Size : %i bytes\n", ice->eeprom.size);
1263 snd_iprintf(buffer, " Version : %i\n", ice->eeprom.version);
1264 snd_iprintf(buffer, " System Config : 0x%x\n",
1265 ice->eeprom.data[ICE_EEP2_SYSCONF]);
1266 snd_iprintf(buffer, " ACLink : 0x%x\n",
1267 ice->eeprom.data[ICE_EEP2_ACLINK]);
1268 snd_iprintf(buffer, " I2S : 0x%x\n",
1269 ice->eeprom.data[ICE_EEP2_I2S]);
1270 snd_iprintf(buffer, " S/PDIF : 0x%x\n",
1271 ice->eeprom.data[ICE_EEP2_SPDIF]);
1272 snd_iprintf(buffer, " GPIO direction : 0x%x\n",
1273 ice->eeprom.gpiodir);
1274 snd_iprintf(buffer, " GPIO mask : 0x%x\n",
1275 ice->eeprom.gpiomask);
1276 snd_iprintf(buffer, " GPIO state : 0x%x\n",
1277 ice->eeprom.gpiostate);
1278 for (idx = 0x12; idx < ice->eeprom.size; idx++)
1279 snd_iprintf(buffer, " Extra #%02i : 0x%x\n",
1280 idx, ice->eeprom.data[idx]);
1282 snd_iprintf(buffer, "\nRegisters:\n");
1284 snd_iprintf(buffer, " PSDOUT03 : 0x%08x\n",
1285 (unsigned)inl(ICEMT1724(ice, ROUTE_PLAYBACK)));
1286 for (idx = 0x0; idx < 0x20 ; idx++)
1287 snd_iprintf(buffer, " CCS%02x : 0x%02x\n",
1288 idx, inb(ice->port+idx));
1289 for (idx = 0x0; idx < 0x30 ; idx++)
1290 snd_iprintf(buffer, " MT%02x : 0x%02x\n",
1291 idx, inb(ice->profi_port+idx));
1294 static void __devinit snd_vt1724_proc_init(struct snd_ice1712 * ice)
1296 struct snd_info_entry *entry;
1298 if (! snd_card_proc_new(ice->card, "ice1724", &entry))
1299 snd_info_set_text_ops(entry, ice, snd_vt1724_proc_read);
1306 static int snd_vt1724_eeprom_info(struct snd_kcontrol *kcontrol,
1307 struct snd_ctl_elem_info *uinfo)
1309 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
1310 uinfo->count = sizeof(struct snd_ice1712_eeprom);
1314 static int snd_vt1724_eeprom_get(struct snd_kcontrol *kcontrol,
1315 struct snd_ctl_elem_value *ucontrol)
1317 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1319 memcpy(ucontrol->value.bytes.data, &ice->eeprom, sizeof(ice->eeprom));
1323 static struct snd_kcontrol_new snd_vt1724_eeprom __devinitdata = {
1324 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1325 .name = "ICE1724 EEPROM",
1326 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1327 .info = snd_vt1724_eeprom_info,
1328 .get = snd_vt1724_eeprom_get
1333 static int snd_vt1724_spdif_info(struct snd_kcontrol *kcontrol,
1334 struct snd_ctl_elem_info *uinfo)
1336 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1341 static unsigned int encode_spdif_bits(struct snd_aes_iec958 *diga)
1343 unsigned int val, rbits;
1345 val = diga->status[0] & 0x03; /* professional, non-audio */
1348 if ((diga->status[0] & IEC958_AES0_PRO_EMPHASIS) ==
1349 IEC958_AES0_PRO_EMPHASIS_5015)
1351 rbits = (diga->status[4] >> 3) & 0x0f;
1354 case 2: val |= 5 << 12; break; /* 96k */
1355 case 3: val |= 6 << 12; break; /* 192k */
1356 case 10: val |= 4 << 12; break; /* 88.2k */
1357 case 11: val |= 7 << 12; break; /* 176.4k */
1360 switch (diga->status[0] & IEC958_AES0_PRO_FS) {
1361 case IEC958_AES0_PRO_FS_44100:
1363 case IEC958_AES0_PRO_FS_32000:
1373 val |= diga->status[1] & 0x04; /* copyright */
1374 if ((diga->status[0] & IEC958_AES0_CON_EMPHASIS) ==
1375 IEC958_AES0_CON_EMPHASIS_5015)
1377 val |= (unsigned int)(diga->status[1] & 0x3f) << 4; /* category */
1378 val |= (unsigned int)(diga->status[3] & IEC958_AES3_CON_FS) << 12; /* fs */
1383 static void decode_spdif_bits(struct snd_aes_iec958 *diga, unsigned int val)
1385 memset(diga->status, 0, sizeof(diga->status));
1386 diga->status[0] = val & 0x03; /* professional, non-audio */
1389 if (val & (1U << 3))
1390 diga->status[0] |= IEC958_AES0_PRO_EMPHASIS_5015;
1391 switch ((val >> 12) & 0x7) {
1395 diga->status[0] |= IEC958_AES0_PRO_FS_32000;
1398 diga->status[0] |= IEC958_AES0_PRO_FS_48000;
1403 diga->status[0] |= val & (1U << 2); /* copyright */
1404 if (val & (1U << 3))
1405 diga->status[0] |= IEC958_AES0_CON_EMPHASIS_5015;
1406 diga->status[1] |= (val >> 4) & 0x3f; /* category */
1407 diga->status[3] |= (val >> 12) & 0x07; /* fs */
1411 static int snd_vt1724_spdif_default_get(struct snd_kcontrol *kcontrol,
1412 struct snd_ctl_elem_value *ucontrol)
1414 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1416 val = inw(ICEMT1724(ice, SPDIF_CTRL));
1417 decode_spdif_bits(&ucontrol->value.iec958, val);
1421 static int snd_vt1724_spdif_default_put(struct snd_kcontrol *kcontrol,
1422 struct snd_ctl_elem_value *ucontrol)
1424 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1425 unsigned int val, old;
1427 val = encode_spdif_bits(&ucontrol->value.iec958);
1428 spin_lock_irq(&ice->reg_lock);
1429 old = inw(ICEMT1724(ice, SPDIF_CTRL));
1431 update_spdif_bits(ice, val);
1432 spin_unlock_irq(&ice->reg_lock);
1433 return (val != old);
1436 static struct snd_kcontrol_new snd_vt1724_spdif_default __devinitdata =
1438 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1439 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
1440 .info = snd_vt1724_spdif_info,
1441 .get = snd_vt1724_spdif_default_get,
1442 .put = snd_vt1724_spdif_default_put
1445 static int snd_vt1724_spdif_maskc_get(struct snd_kcontrol *kcontrol,
1446 struct snd_ctl_elem_value *ucontrol)
1448 ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO |
1449 IEC958_AES0_PROFESSIONAL |
1450 IEC958_AES0_CON_NOT_COPYRIGHT |
1451 IEC958_AES0_CON_EMPHASIS;
1452 ucontrol->value.iec958.status[1] = IEC958_AES1_CON_ORIGINAL |
1453 IEC958_AES1_CON_CATEGORY;
1454 ucontrol->value.iec958.status[3] = IEC958_AES3_CON_FS;
1458 static int snd_vt1724_spdif_maskp_get(struct snd_kcontrol *kcontrol,
1459 struct snd_ctl_elem_value *ucontrol)
1461 ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO |
1462 IEC958_AES0_PROFESSIONAL |
1463 IEC958_AES0_PRO_FS |
1464 IEC958_AES0_PRO_EMPHASIS;
1468 static struct snd_kcontrol_new snd_vt1724_spdif_maskc __devinitdata =
1470 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1471 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1472 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,CON_MASK),
1473 .info = snd_vt1724_spdif_info,
1474 .get = snd_vt1724_spdif_maskc_get,
1477 static struct snd_kcontrol_new snd_vt1724_spdif_maskp __devinitdata =
1479 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1480 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1481 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PRO_MASK),
1482 .info = snd_vt1724_spdif_info,
1483 .get = snd_vt1724_spdif_maskp_get,
1486 #define snd_vt1724_spdif_sw_info snd_ctl_boolean_mono_info
1488 static int snd_vt1724_spdif_sw_get(struct snd_kcontrol *kcontrol,
1489 struct snd_ctl_elem_value *ucontrol)
1491 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1492 ucontrol->value.integer.value[0] = inb(ICEREG1724(ice, SPDIF_CFG)) &
1493 VT1724_CFG_SPDIF_OUT_EN ? 1 : 0;
1497 static int snd_vt1724_spdif_sw_put(struct snd_kcontrol *kcontrol,
1498 struct snd_ctl_elem_value *ucontrol)
1500 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1501 unsigned char old, val;
1503 spin_lock_irq(&ice->reg_lock);
1504 old = val = inb(ICEREG1724(ice, SPDIF_CFG));
1505 val &= ~VT1724_CFG_SPDIF_OUT_EN;
1506 if (ucontrol->value.integer.value[0])
1507 val |= VT1724_CFG_SPDIF_OUT_EN;
1509 outb(val, ICEREG1724(ice, SPDIF_CFG));
1510 spin_unlock_irq(&ice->reg_lock);
1514 static struct snd_kcontrol_new snd_vt1724_spdif_switch __devinitdata =
1516 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1517 /* FIXME: the following conflict with IEC958 Playback Route */
1518 // .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH),
1519 .name = SNDRV_CTL_NAME_IEC958("Output ",NONE,SWITCH),
1520 .info = snd_vt1724_spdif_sw_info,
1521 .get = snd_vt1724_spdif_sw_get,
1522 .put = snd_vt1724_spdif_sw_put
1526 #if 0 /* NOT USED YET */
1528 * GPIO access from extern
1531 #define snd_vt1724_gpio_info snd_ctl_boolean_mono_info
1533 int snd_vt1724_gpio_get(struct snd_kcontrol *kcontrol,
1534 struct snd_ctl_elem_value *ucontrol)
1536 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1537 int shift = kcontrol->private_value & 0xff;
1538 int invert = (kcontrol->private_value & (1<<24)) ? 1 : 0;
1540 snd_ice1712_save_gpio_status(ice);
1541 ucontrol->value.integer.value[0] =
1542 (snd_ice1712_gpio_read(ice) & (1 << shift) ? 1 : 0) ^ invert;
1543 snd_ice1712_restore_gpio_status(ice);
1547 int snd_ice1712_gpio_put(struct snd_kcontrol *kcontrol,
1548 struct snd_ctl_elem_value *ucontrol)
1550 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1551 int shift = kcontrol->private_value & 0xff;
1552 int invert = (kcontrol->private_value & (1<<24)) ? mask : 0;
1553 unsigned int val, nval;
1555 if (kcontrol->private_value & (1 << 31))
1557 nval = (ucontrol->value.integer.value[0] ? (1 << shift) : 0) ^ invert;
1558 snd_ice1712_save_gpio_status(ice);
1559 val = snd_ice1712_gpio_read(ice);
1560 nval |= val & ~(1 << shift);
1562 snd_ice1712_gpio_write(ice, nval);
1563 snd_ice1712_restore_gpio_status(ice);
1566 #endif /* NOT USED YET */
1571 static int snd_vt1724_pro_internal_clock_info(struct snd_kcontrol *kcontrol,
1572 struct snd_ctl_elem_info *uinfo)
1574 static const char * const texts_1724[] = {
1577 "11025", /* 2: 10 */
1585 "64000", /* 10: 15 */
1586 "88200", /* 11: 11 */
1587 "96000", /* 12: 7 */
1588 "176400", /* 13: 12 */
1589 "192000", /* 14: 14 */
1590 "IEC958 Input", /* 15: -- */
1592 static const char * const texts_1720[] = {
1595 "11025", /* 2: 10 */
1603 "64000", /* 10: 15 */
1604 "88200", /* 11: 11 */
1605 "96000", /* 12: 7 */
1606 "IEC958 Input", /* 13: -- */
1608 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1610 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1612 uinfo->value.enumerated.items = ice->vt1720 ? 14 : 16;
1613 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1614 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1615 strcpy(uinfo->value.enumerated.name,
1616 ice->vt1720 ? texts_1720[uinfo->value.enumerated.item] :
1617 texts_1724[uinfo->value.enumerated.item]);
1621 static int snd_vt1724_pro_internal_clock_get(struct snd_kcontrol *kcontrol,
1622 struct snd_ctl_elem_value *ucontrol)
1624 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1625 static const unsigned char xlate[16] = {
1626 9, 6, 3, 1, 7, 4, 0, 12, 8, 5, 2, 11, 13, 255, 14, 10
1630 spin_lock_irq(&ice->reg_lock);
1631 if (is_spdif_master(ice)) {
1632 ucontrol->value.enumerated.item[0] = ice->vt1720 ? 13 : 15;
1634 val = xlate[inb(ICEMT1724(ice, RATE)) & 15];
1639 ucontrol->value.enumerated.item[0] = val;
1641 spin_unlock_irq(&ice->reg_lock);
1645 static int snd_vt1724_pro_internal_clock_put(struct snd_kcontrol *kcontrol,
1646 struct snd_ctl_elem_value *ucontrol)
1648 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1652 int spdif = ice->vt1720 ? 13 : 15;
1654 spin_lock_irq(&ice->reg_lock);
1655 oval = inb(ICEMT1724(ice, RATE));
1656 if (ucontrol->value.enumerated.item[0] == spdif) {
1657 unsigned char i2s_oval;
1658 outb(oval | VT1724_SPDIF_MASTER, ICEMT1724(ice, RATE));
1660 i2s_oval = inb(ICEMT1724(ice, I2S_FORMAT));
1661 outb(i2s_oval & ~VT1724_MT_I2S_MCLK_128X,
1662 ICEMT1724(ice, I2S_FORMAT));
1664 rate = rates[ucontrol->value.integer.value[0] % 15];
1665 if (rate <= get_max_rate(ice)) {
1666 PRO_RATE_DEFAULT = rate;
1667 spin_unlock_irq(&ice->reg_lock);
1668 snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 1);
1669 spin_lock_irq(&ice->reg_lock);
1672 change = inb(ICEMT1724(ice, RATE)) != oval;
1673 spin_unlock_irq(&ice->reg_lock);
1675 if ((oval & VT1724_SPDIF_MASTER) !=
1676 (inb(ICEMT1724(ice, RATE)) & VT1724_SPDIF_MASTER)) {
1677 /* notify akm chips as well */
1678 if (is_spdif_master(ice)) {
1680 for (i = 0; i < ice->akm_codecs; i++) {
1681 if (ice->akm[i].ops.set_rate_val)
1682 ice->akm[i].ops.set_rate_val(&ice->akm[i], 0);
1689 static struct snd_kcontrol_new snd_vt1724_pro_internal_clock __devinitdata = {
1690 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1691 .name = "Multi Track Internal Clock",
1692 .info = snd_vt1724_pro_internal_clock_info,
1693 .get = snd_vt1724_pro_internal_clock_get,
1694 .put = snd_vt1724_pro_internal_clock_put
1697 #define snd_vt1724_pro_rate_locking_info snd_ctl_boolean_mono_info
1699 static int snd_vt1724_pro_rate_locking_get(struct snd_kcontrol *kcontrol,
1700 struct snd_ctl_elem_value *ucontrol)
1702 ucontrol->value.integer.value[0] = PRO_RATE_LOCKED;
1706 static int snd_vt1724_pro_rate_locking_put(struct snd_kcontrol *kcontrol,
1707 struct snd_ctl_elem_value *ucontrol)
1709 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1710 int change = 0, nval;
1712 nval = ucontrol->value.integer.value[0] ? 1 : 0;
1713 spin_lock_irq(&ice->reg_lock);
1714 change = PRO_RATE_LOCKED != nval;
1715 PRO_RATE_LOCKED = nval;
1716 spin_unlock_irq(&ice->reg_lock);
1720 static struct snd_kcontrol_new snd_vt1724_pro_rate_locking __devinitdata = {
1721 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1722 .name = "Multi Track Rate Locking",
1723 .info = snd_vt1724_pro_rate_locking_info,
1724 .get = snd_vt1724_pro_rate_locking_get,
1725 .put = snd_vt1724_pro_rate_locking_put
1728 #define snd_vt1724_pro_rate_reset_info snd_ctl_boolean_mono_info
1730 static int snd_vt1724_pro_rate_reset_get(struct snd_kcontrol *kcontrol,
1731 struct snd_ctl_elem_value *ucontrol)
1733 ucontrol->value.integer.value[0] = PRO_RATE_RESET ? 1 : 0;
1737 static int snd_vt1724_pro_rate_reset_put(struct snd_kcontrol *kcontrol,
1738 struct snd_ctl_elem_value *ucontrol)
1740 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1741 int change = 0, nval;
1743 nval = ucontrol->value.integer.value[0] ? 1 : 0;
1744 spin_lock_irq(&ice->reg_lock);
1745 change = PRO_RATE_RESET != nval;
1746 PRO_RATE_RESET = nval;
1747 spin_unlock_irq(&ice->reg_lock);
1751 static struct snd_kcontrol_new snd_vt1724_pro_rate_reset __devinitdata = {
1752 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1753 .name = "Multi Track Rate Reset",
1754 .info = snd_vt1724_pro_rate_reset_info,
1755 .get = snd_vt1724_pro_rate_reset_get,
1756 .put = snd_vt1724_pro_rate_reset_put
1763 static int snd_vt1724_pro_route_info(struct snd_kcontrol *kcontrol,
1764 struct snd_ctl_elem_info *uinfo)
1766 static char *texts[] = {
1768 "H/W In 0", "H/W In 1", /* 1-2 */
1769 "IEC958 In L", "IEC958 In R", /* 3-4 */
1772 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1774 uinfo->value.enumerated.items = 5;
1775 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1776 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1777 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1781 static inline int analog_route_shift(int idx)
1783 return (idx % 2) * 12 + ((idx / 2) * 3) + 8;
1786 static inline int digital_route_shift(int idx)
1791 static int get_route_val(struct snd_ice1712 *ice, int shift)
1794 unsigned char eitem;
1795 static const unsigned char xlate[8] = {
1796 0, 255, 1, 2, 255, 255, 3, 4,
1799 val = inl(ICEMT1724(ice, ROUTE_PLAYBACK));
1801 val &= 7; //we now have 3 bits per output
1810 static int put_route_val(struct snd_ice1712 *ice, unsigned int val, int shift)
1812 unsigned int old_val, nval;
1814 static const unsigned char xroute[8] = {
1816 2, /* PSDIN0 Left */
1817 3, /* PSDIN0 Right */
1819 7, /* SPDIN Right */
1822 nval = xroute[val % 5];
1823 val = old_val = inl(ICEMT1724(ice, ROUTE_PLAYBACK));
1824 val &= ~(0x07 << shift);
1825 val |= nval << shift;
1826 change = val != old_val;
1828 outl(val, ICEMT1724(ice, ROUTE_PLAYBACK));
1832 static int snd_vt1724_pro_route_analog_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, analog_route_shift(idx));
1842 static int snd_vt1724_pro_route_analog_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 analog_route_shift(idx));
1851 static int snd_vt1724_pro_route_spdif_get(struct snd_kcontrol *kcontrol,
1852 struct snd_ctl_elem_value *ucontrol)
1854 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1855 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1856 ucontrol->value.enumerated.item[0] =
1857 get_route_val(ice, digital_route_shift(idx));
1861 static int snd_vt1724_pro_route_spdif_put(struct snd_kcontrol *kcontrol,
1862 struct snd_ctl_elem_value *ucontrol)
1864 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1865 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1866 return put_route_val(ice, ucontrol->value.enumerated.item[0],
1867 digital_route_shift(idx));
1870 static struct snd_kcontrol_new snd_vt1724_mixer_pro_analog_route __devinitdata = {
1871 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1872 .name = "H/W Playback Route",
1873 .info = snd_vt1724_pro_route_info,
1874 .get = snd_vt1724_pro_route_analog_get,
1875 .put = snd_vt1724_pro_route_analog_put,
1878 static struct snd_kcontrol_new snd_vt1724_mixer_pro_spdif_route __devinitdata = {
1879 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1880 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Route",
1881 .info = snd_vt1724_pro_route_info,
1882 .get = snd_vt1724_pro_route_spdif_get,
1883 .put = snd_vt1724_pro_route_spdif_put,
1888 static int snd_vt1724_pro_peak_info(struct snd_kcontrol *kcontrol,
1889 struct snd_ctl_elem_info *uinfo)
1891 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1892 uinfo->count = 22; /* FIXME: for compatibility with ice1712... */
1893 uinfo->value.integer.min = 0;
1894 uinfo->value.integer.max = 255;
1898 static int snd_vt1724_pro_peak_get(struct snd_kcontrol *kcontrol,
1899 struct snd_ctl_elem_value *ucontrol)
1901 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1904 spin_lock_irq(&ice->reg_lock);
1905 for (idx = 0; idx < 22; idx++) {
1906 outb(idx, ICEMT1724(ice, MONITOR_PEAKINDEX));
1907 ucontrol->value.integer.value[idx] =
1908 inb(ICEMT1724(ice, MONITOR_PEAKDATA));
1910 spin_unlock_irq(&ice->reg_lock);
1914 static struct snd_kcontrol_new snd_vt1724_mixer_pro_peak __devinitdata = {
1915 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1916 .name = "Multi Track Peak",
1917 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
1918 .info = snd_vt1724_pro_peak_info,
1919 .get = snd_vt1724_pro_peak_get
1926 static struct snd_ice1712_card_info no_matched __devinitdata;
1928 static struct snd_ice1712_card_info *card_tables[] __devinitdata = {
1929 snd_vt1724_revo_cards,
1930 snd_vt1724_amp_cards,
1931 snd_vt1724_aureon_cards,
1932 snd_vt1720_mobo_cards,
1933 snd_vt1720_pontis_cards,
1934 snd_vt1724_prodigy192_cards,
1935 snd_vt1724_juli_cards,
1936 snd_vt1724_phase_cards,
1937 snd_vt1724_wtm_cards,
1938 snd_vt1724_se_cards,
1946 static void wait_i2c_busy(struct snd_ice1712 *ice)
1949 while ((inb(ICEREG1724(ice, I2C_CTRL)) & VT1724_I2C_BUSY) && t--)
1952 printk(KERN_ERR "ice1724: i2c busy timeout\n");
1955 unsigned char snd_vt1724_read_i2c(struct snd_ice1712 *ice,
1956 unsigned char dev, unsigned char addr)
1960 mutex_lock(&ice->i2c_mutex);
1961 outb(addr, ICEREG1724(ice, I2C_BYTE_ADDR));
1962 outb(dev & ~VT1724_I2C_WRITE, ICEREG1724(ice, I2C_DEV_ADDR));
1964 val = inb(ICEREG1724(ice, I2C_DATA));
1965 mutex_unlock(&ice->i2c_mutex);
1966 //printk("i2c_read: [0x%x,0x%x] = 0x%x\n", dev, addr, val);
1970 void snd_vt1724_write_i2c(struct snd_ice1712 *ice,
1971 unsigned char dev, unsigned char addr, unsigned char data)
1973 mutex_lock(&ice->i2c_mutex);
1975 //printk("i2c_write: [0x%x,0x%x] = 0x%x\n", dev, addr, data);
1976 outb(addr, ICEREG1724(ice, I2C_BYTE_ADDR));
1977 outb(data, ICEREG1724(ice, I2C_DATA));
1978 outb(dev | VT1724_I2C_WRITE, ICEREG1724(ice, I2C_DEV_ADDR));
1980 mutex_unlock(&ice->i2c_mutex);
1983 static int __devinit snd_vt1724_read_eeprom(struct snd_ice1712 *ice,
1984 const char *modelname)
1986 const int dev = 0xa0; /* EEPROM device address */
1987 unsigned int i, size;
1988 struct snd_ice1712_card_info * const *tbl, *c;
1990 if (! modelname || ! *modelname) {
1991 ice->eeprom.subvendor = 0;
1992 if ((inb(ICEREG1724(ice, I2C_CTRL)) & VT1724_I2C_EEPROM) != 0)
1993 ice->eeprom.subvendor =
1994 (snd_vt1724_read_i2c(ice, dev, 0x00) << 0) |
1995 (snd_vt1724_read_i2c(ice, dev, 0x01) << 8) |
1996 (snd_vt1724_read_i2c(ice, dev, 0x02) << 16) |
1997 (snd_vt1724_read_i2c(ice, dev, 0x03) << 24);
1998 if (ice->eeprom.subvendor == 0 ||
1999 ice->eeprom.subvendor == (unsigned int)-1) {
2000 /* invalid subvendor from EEPROM, try the PCI
2001 * subststem ID instead
2004 pci_read_config_word(ice->pci, PCI_SUBSYSTEM_VENDOR_ID,
2006 pci_read_config_word(ice->pci, PCI_SUBSYSTEM_ID, &device);
2007 ice->eeprom.subvendor =
2008 ((unsigned int)swab16(vendor) << 16) | swab16(device);
2009 if (ice->eeprom.subvendor == 0 ||
2010 ice->eeprom.subvendor == (unsigned int)-1) {
2011 printk(KERN_ERR "ice1724: No valid ID is found\n");
2016 for (tbl = card_tables; *tbl; tbl++) {
2017 for (c = *tbl; c->subvendor; c++) {
2018 if (modelname && c->model &&
2019 ! strcmp(modelname, c->model)) {
2020 printk(KERN_INFO "ice1724: Using board model %s\n",
2022 ice->eeprom.subvendor = c->subvendor;
2023 } else if (c->subvendor != ice->eeprom.subvendor)
2025 if (! c->eeprom_size || ! c->eeprom_data)
2027 /* if the EEPROM is given by the driver, use it */
2028 snd_printdd("using the defined eeprom..\n");
2029 ice->eeprom.version = 2;
2030 ice->eeprom.size = c->eeprom_size + 6;
2031 memcpy(ice->eeprom.data, c->eeprom_data, c->eeprom_size);
2035 printk(KERN_WARNING "ice1724: No matching model found for ID 0x%x\n",
2036 ice->eeprom.subvendor);
2039 ice->eeprom.size = snd_vt1724_read_i2c(ice, dev, 0x04);
2040 if (ice->eeprom.size < 6)
2041 ice->eeprom.size = 32;
2042 else if (ice->eeprom.size > 32) {
2043 printk(KERN_ERR "ice1724: Invalid EEPROM (size = %i)\n",
2047 ice->eeprom.version = snd_vt1724_read_i2c(ice, dev, 0x05);
2048 if (ice->eeprom.version != 2)
2049 printk(KERN_WARNING "ice1724: Invalid EEPROM version %i\n",
2050 ice->eeprom.version);
2051 size = ice->eeprom.size - 6;
2052 for (i = 0; i < size; i++)
2053 ice->eeprom.data[i] = snd_vt1724_read_i2c(ice, dev, i + 6);
2056 ice->eeprom.gpiomask = eeprom_triple(ice, ICE_EEP2_GPIO_MASK);
2057 ice->eeprom.gpiostate = eeprom_triple(ice, ICE_EEP2_GPIO_STATE);
2058 ice->eeprom.gpiodir = eeprom_triple(ice, ICE_EEP2_GPIO_DIR);
2065 static int __devinit snd_vt1724_chip_init(struct snd_ice1712 *ice)
2067 outb(VT1724_RESET , ICEREG1724(ice, CONTROL));
2069 outb(0, ICEREG1724(ice, CONTROL));
2071 outb(ice->eeprom.data[ICE_EEP2_SYSCONF], ICEREG1724(ice, SYS_CFG));
2072 outb(ice->eeprom.data[ICE_EEP2_ACLINK], ICEREG1724(ice, AC97_CFG));
2073 outb(ice->eeprom.data[ICE_EEP2_I2S], ICEREG1724(ice, I2S_FEATURES));
2074 outb(ice->eeprom.data[ICE_EEP2_SPDIF], ICEREG1724(ice, SPDIF_CFG));
2076 ice->gpio.write_mask = ice->eeprom.gpiomask;
2077 ice->gpio.direction = ice->eeprom.gpiodir;
2078 snd_vt1724_set_gpio_mask(ice, ice->eeprom.gpiomask);
2079 snd_vt1724_set_gpio_dir(ice, ice->eeprom.gpiodir);
2080 snd_vt1724_set_gpio_data(ice, ice->eeprom.gpiostate);
2082 outb(0, ICEREG1724(ice, POWERDOWN));
2087 static int __devinit snd_vt1724_spdif_build_controls(struct snd_ice1712 *ice)
2090 struct snd_kcontrol *kctl;
2092 snd_assert(ice->pcm != NULL, return -EIO);
2094 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_mixer_pro_spdif_route, ice));
2098 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_spdif_switch, ice));
2102 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_vt1724_spdif_default, ice));
2105 kctl->id.device = ice->pcm->device;
2106 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_vt1724_spdif_maskc, ice));
2109 kctl->id.device = ice->pcm->device;
2110 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_vt1724_spdif_maskp, ice));
2113 kctl->id.device = ice->pcm->device;
2114 #if 0 /* use default only */
2115 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_vt1724_spdif_stream, ice));
2118 kctl->id.device = ice->pcm->device;
2119 ice->spdif.stream_ctl = kctl;
2125 static int __devinit snd_vt1724_build_controls(struct snd_ice1712 *ice)
2129 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_eeprom, ice));
2132 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_pro_internal_clock, ice));
2136 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_pro_rate_locking, ice));
2139 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_pro_rate_reset, ice));
2143 if (ice->num_total_dacs > 0) {
2144 struct snd_kcontrol_new tmp = snd_vt1724_mixer_pro_analog_route;
2145 tmp.count = ice->num_total_dacs;
2146 if (ice->vt1720 && tmp.count > 2)
2148 err = snd_ctl_add(ice->card, snd_ctl_new1(&tmp, ice));
2153 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_mixer_pro_peak, ice));
2160 static int snd_vt1724_free(struct snd_ice1712 *ice)
2164 /* mask all interrupts */
2165 outb(0xff, ICEMT1724(ice, DMA_INT_MASK));
2166 outb(0xff, ICEREG1724(ice, IRQMASK));
2169 if (ice->irq >= 0) {
2170 synchronize_irq(ice->irq);
2171 free_irq(ice->irq, ice);
2173 pci_release_regions(ice->pci);
2174 snd_ice1712_akm4xxx_free(ice);
2175 pci_disable_device(ice->pci);
2180 static int snd_vt1724_dev_free(struct snd_device *device)
2182 struct snd_ice1712 *ice = device->device_data;
2183 return snd_vt1724_free(ice);
2186 static int __devinit snd_vt1724_create(struct snd_card *card,
2187 struct pci_dev *pci,
2188 const char *modelname,
2189 struct snd_ice1712 ** r_ice1712)
2191 struct snd_ice1712 *ice;
2194 static struct snd_device_ops ops = {
2195 .dev_free = snd_vt1724_dev_free,
2200 /* enable PCI device */
2201 if ((err = pci_enable_device(pci)) < 0)
2204 ice = kzalloc(sizeof(*ice), GFP_KERNEL);
2206 pci_disable_device(pci);
2210 spin_lock_init(&ice->reg_lock);
2211 mutex_init(&ice->gpio_mutex);
2212 mutex_init(&ice->open_mutex);
2213 mutex_init(&ice->i2c_mutex);
2214 ice->gpio.set_mask = snd_vt1724_set_gpio_mask;
2215 ice->gpio.set_dir = snd_vt1724_set_gpio_dir;
2216 ice->gpio.set_data = snd_vt1724_set_gpio_data;
2217 ice->gpio.get_data = snd_vt1724_get_gpio_data;
2221 pci_set_master(pci);
2222 snd_vt1724_proc_init(ice);
2223 synchronize_irq(pci->irq);
2225 if ((err = pci_request_regions(pci, "ICE1724")) < 0) {
2227 pci_disable_device(pci);
2230 ice->port = pci_resource_start(pci, 0);
2231 ice->profi_port = pci_resource_start(pci, 1);
2233 if (request_irq(pci->irq, snd_vt1724_interrupt,
2234 IRQF_SHARED, "ICE1724", ice)) {
2235 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
2236 snd_vt1724_free(ice);
2240 ice->irq = pci->irq;
2242 if (snd_vt1724_read_eeprom(ice, modelname) < 0) {
2243 snd_vt1724_free(ice);
2246 if (snd_vt1724_chip_init(ice) < 0) {
2247 snd_vt1724_free(ice);
2251 /* unmask used interrupts */
2252 if (! (ice->eeprom.data[ICE_EEP2_SYSCONF] & VT1724_CFG_MPU401))
2253 mask = VT1724_IRQ_MPU_RX | VT1724_IRQ_MPU_TX;
2256 outb(mask, ICEREG1724(ice, IRQMASK));
2257 /* don't handle FIFO overrun/underruns (just yet),
2258 * since they cause machine lockups
2260 outb(VT1724_MULTI_FIFO_ERR, ICEMT1724(ice, DMA_INT_MASK));
2262 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, ice, &ops)) < 0) {
2263 snd_vt1724_free(ice);
2267 snd_card_set_dev(card, &pci->dev);
2280 static int __devinit snd_vt1724_probe(struct pci_dev *pci,
2281 const struct pci_device_id *pci_id)
2284 struct snd_card *card;
2285 struct snd_ice1712 *ice;
2286 int pcm_dev = 0, err;
2287 struct snd_ice1712_card_info * const *tbl, *c;
2289 if (dev >= SNDRV_CARDS)
2296 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
2300 strcpy(card->driver, "ICE1724");
2301 strcpy(card->shortname, "ICEnsemble ICE1724");
2303 if ((err = snd_vt1724_create(card, pci, model[dev], &ice)) < 0) {
2304 snd_card_free(card);
2308 for (tbl = card_tables; *tbl; tbl++) {
2309 for (c = *tbl; c->subvendor; c++) {
2310 if (c->subvendor == ice->eeprom.subvendor) {
2311 strcpy(card->shortname, c->name);
2312 if (c->driver) /* specific driver? */
2313 strcpy(card->driver, c->driver);
2315 if ((err = c->chip_init(ice)) < 0) {
2316 snd_card_free(card);
2327 * VT1724 has separate DMAs for the analog and the SPDIF streams while
2328 * ICE1712 has only one for both (mixed up).
2330 * Confusingly the analog PCM is named "professional" here because it
2331 * was called so in ice1712 driver, and vt1724 driver is derived from
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)