2 * ALSA driver for VT1724 ICEnsemble ICE1724 / VIA VT1724 (Envy24HT)
3 * VIA VT1720 (Envy24PT)
5 * Copyright (c) 2000 Jaroslav Kysela <perex@suse.cz>
6 * 2002 James Stafford <jstafford@ampltd.com>
7 * 2003 Takashi Iwai <tiwai@suse.de>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include <sound/driver.h>
27 #include <linux/delay.h>
28 #include <linux/interrupt.h>
29 #include <linux/init.h>
30 #include <linux/pci.h>
31 #include <linux/slab.h>
32 #include <linux/moduleparam.h>
33 #include <sound/core.h>
34 #include <sound/info.h>
35 #include <sound/mpu401.h>
36 #include <sound/initval.h>
38 #include <sound/asoundef.h>
43 /* lowlevel routines */
47 #include "vt1720_mobo.h"
49 #include "prodigy192.h"
54 MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
55 MODULE_DESCRIPTION("VIA ICEnsemble ICE1724/1720 (Envy24HT/PT)");
56 MODULE_LICENSE("GPL");
57 MODULE_SUPPORTED_DEVICE("{"
59 AMP_AUDIO2000_DEVICE_DESC
61 VT1720_MOBO_DEVICE_DESC
63 PRODIGY192_DEVICE_DESC
68 "{ICEnsemble,Generic ICE1724},"
69 "{ICEnsemble,Generic Envy24HT}"
70 "{ICEnsemble,Generic Envy24PT}}");
72 static int index
[SNDRV_CARDS
] = SNDRV_DEFAULT_IDX
; /* Index 0-MAX */
73 static char *id
[SNDRV_CARDS
] = SNDRV_DEFAULT_STR
; /* ID for this card */
74 static int enable
[SNDRV_CARDS
] = SNDRV_DEFAULT_ENABLE_PNP
; /* Enable this card */
75 static char *model
[SNDRV_CARDS
];
77 module_param_array(index
, int, NULL
, 0444);
78 MODULE_PARM_DESC(index
, "Index value for ICE1724 soundcard.");
79 module_param_array(id
, charp
, NULL
, 0444);
80 MODULE_PARM_DESC(id
, "ID string for ICE1724 soundcard.");
81 module_param_array(enable
, bool, NULL
, 0444);
82 MODULE_PARM_DESC(enable
, "Enable ICE1724 soundcard.");
83 module_param_array(model
, charp
, NULL
, 0444);
84 MODULE_PARM_DESC(model
, "Use the given board model.");
87 /* Both VT1720 and VT1724 have the same PCI IDs */
88 static struct pci_device_id snd_vt1724_ids
[] = {
89 { PCI_VENDOR_ID_ICE
, PCI_DEVICE_ID_VT1724
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
93 MODULE_DEVICE_TABLE(pci
, snd_vt1724_ids
);
96 static int PRO_RATE_LOCKED
;
97 static int PRO_RATE_RESET
= 1;
98 static unsigned int PRO_RATE_DEFAULT
= 44100;
104 /* check whether the clock mode is spdif-in */
105 static inline int is_spdif_master(ice1712_t
*ice
)
107 return (inb(ICEMT1724(ice
, RATE
)) & VT1724_SPDIF_MASTER
) ? 1 : 0;
110 static inline int is_pro_rate_locked(ice1712_t
*ice
)
112 return is_spdif_master(ice
) || PRO_RATE_LOCKED
;
119 static unsigned char snd_vt1724_ac97_ready(ice1712_t
*ice
)
121 unsigned char old_cmd
;
123 for (tm
= 0; tm
< 0x10000; tm
++) {
124 old_cmd
= inb(ICEMT1724(ice
, AC97_CMD
));
125 if (old_cmd
& (VT1724_AC97_WRITE
| VT1724_AC97_READ
))
127 if (!(old_cmd
& VT1724_AC97_READY
))
131 snd_printd(KERN_ERR
"snd_vt1724_ac97_ready: timeout\n");
135 static int snd_vt1724_ac97_wait_bit(ice1712_t
*ice
, unsigned char bit
)
138 for (tm
= 0; tm
< 0x10000; tm
++)
139 if ((inb(ICEMT1724(ice
, AC97_CMD
)) & bit
) == 0)
141 snd_printd(KERN_ERR
"snd_vt1724_ac97_wait_bit: timeout\n");
145 static void snd_vt1724_ac97_write(ac97_t
*ac97
,
149 ice1712_t
*ice
= (ice1712_t
*)ac97
->private_data
;
150 unsigned char old_cmd
;
152 old_cmd
= snd_vt1724_ac97_ready(ice
);
153 old_cmd
&= ~VT1724_AC97_ID_MASK
;
154 old_cmd
|= ac97
->num
;
155 outb(reg
, ICEMT1724(ice
, AC97_INDEX
));
156 outw(val
, ICEMT1724(ice
, AC97_DATA
));
157 outb(old_cmd
| VT1724_AC97_WRITE
, ICEMT1724(ice
, AC97_CMD
));
158 snd_vt1724_ac97_wait_bit(ice
, VT1724_AC97_WRITE
);
161 static unsigned short snd_vt1724_ac97_read(ac97_t
*ac97
, unsigned short reg
)
163 ice1712_t
*ice
= (ice1712_t
*)ac97
->private_data
;
164 unsigned char old_cmd
;
166 old_cmd
= snd_vt1724_ac97_ready(ice
);
167 old_cmd
&= ~VT1724_AC97_ID_MASK
;
168 old_cmd
|= ac97
->num
;
169 outb(reg
, ICEMT1724(ice
, AC97_INDEX
));
170 outb(old_cmd
| VT1724_AC97_READ
, ICEMT1724(ice
, AC97_CMD
));
171 if (snd_vt1724_ac97_wait_bit(ice
, VT1724_AC97_READ
) < 0)
173 return inw(ICEMT1724(ice
, AC97_DATA
));
181 /* set gpio direction 0 = read, 1 = write */
182 static void snd_vt1724_set_gpio_dir(ice1712_t
*ice
, unsigned int data
)
184 outl(data
, ICEREG1724(ice
, GPIO_DIRECTION
));
185 inw(ICEREG1724(ice
, GPIO_DIRECTION
)); /* dummy read for pci-posting */
188 /* set the gpio mask (0 = writable) */
189 static void snd_vt1724_set_gpio_mask(ice1712_t
*ice
, unsigned int data
)
191 outw(data
, ICEREG1724(ice
, GPIO_WRITE_MASK
));
192 if (! ice
->vt1720
) /* VT1720 supports only 16 GPIO bits */
193 outb((data
>> 16) & 0xff, ICEREG1724(ice
, GPIO_WRITE_MASK_22
));
194 inw(ICEREG1724(ice
, GPIO_WRITE_MASK
)); /* dummy read for pci-posting */
197 static void snd_vt1724_set_gpio_data(ice1712_t
*ice
, unsigned int data
)
199 outw(data
, ICEREG1724(ice
, GPIO_DATA
));
201 outb(data
>> 16, ICEREG1724(ice
, GPIO_DATA_22
));
202 inw(ICEREG1724(ice
, GPIO_DATA
)); /* dummy read for pci-posting */
205 static unsigned int snd_vt1724_get_gpio_data(ice1712_t
*ice
)
209 data
= (unsigned int)inb(ICEREG1724(ice
, GPIO_DATA_22
));
212 data
= (data
<< 16) | inw(ICEREG1724(ice
, GPIO_DATA
));
220 static irqreturn_t
snd_vt1724_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
222 ice1712_t
*ice
= dev_id
;
223 unsigned char status
;
227 status
= inb(ICEREG1724(ice
, IRQSTAT
));
232 /* these should probably be separated at some point,
233 but as we don't currently have MPU support on the board I will leave it */
234 if ((status
& VT1724_IRQ_MPU_RX
)||(status
& VT1724_IRQ_MPU_TX
)) {
236 snd_mpu401_uart_interrupt(irq
, ice
->rmidi
[0]->private_data
, regs
);
237 outb(status
& (VT1724_IRQ_MPU_RX
|VT1724_IRQ_MPU_TX
), ICEREG1724(ice
, IRQSTAT
));
238 status
&= ~(VT1724_IRQ_MPU_RX
|VT1724_IRQ_MPU_TX
);
240 if (status
& VT1724_IRQ_MTPCM
) {
243 * PCM assignment are:
244 * Playback DMA0 (M/C) = playback_pro_substream
245 * Playback DMA1 = playback_con_substream_ds[0]
246 * Playback DMA2 = playback_con_substream_ds[1]
247 * Playback DMA3 = playback_con_substream_ds[2]
248 * Playback DMA4 (SPDIF) = playback_con_substream
249 * Record DMA0 = capture_pro_substream
250 * Record DMA1 = capture_con_substream
252 unsigned char mtstat
= inb(ICEMT1724(ice
, IRQ
));
253 if (mtstat
& VT1724_MULTI_PDMA0
) {
254 if (ice
->playback_pro_substream
)
255 snd_pcm_period_elapsed(ice
->playback_pro_substream
);
257 if (mtstat
& VT1724_MULTI_RDMA0
) {
258 if (ice
->capture_pro_substream
)
259 snd_pcm_period_elapsed(ice
->capture_pro_substream
);
261 if (mtstat
& VT1724_MULTI_PDMA1
) {
262 if (ice
->playback_con_substream_ds
[0])
263 snd_pcm_period_elapsed(ice
->playback_con_substream_ds
[0]);
265 if (mtstat
& VT1724_MULTI_PDMA2
) {
266 if (ice
->playback_con_substream_ds
[1])
267 snd_pcm_period_elapsed(ice
->playback_con_substream_ds
[1]);
269 if (mtstat
& VT1724_MULTI_PDMA3
) {
270 if (ice
->playback_con_substream_ds
[2])
271 snd_pcm_period_elapsed(ice
->playback_con_substream_ds
[2]);
273 if (mtstat
& VT1724_MULTI_PDMA4
) {
274 if (ice
->playback_con_substream
)
275 snd_pcm_period_elapsed(ice
->playback_con_substream
);
277 if (mtstat
& VT1724_MULTI_RDMA1
) {
278 if (ice
->capture_con_substream
)
279 snd_pcm_period_elapsed(ice
->capture_con_substream
);
281 /* ack anyway to avoid freeze */
282 outb(mtstat
, ICEMT1724(ice
, IRQ
));
283 /* ought to really handle this properly */
284 if (mtstat
& VT1724_MULTI_FIFO_ERR
) {
285 unsigned char fstat
= inb(ICEMT1724(ice
, DMA_FIFO_ERR
));
286 outb(fstat
, ICEMT1724(ice
, DMA_FIFO_ERR
));
287 outb(VT1724_MULTI_FIFO_ERR
| inb(ICEMT1724(ice
, DMA_INT_MASK
)), ICEMT1724(ice
, DMA_INT_MASK
));
288 /* If I don't do this, I get machine lockup due to continual interrupts */
293 return IRQ_RETVAL(handled
);
297 * PCM code - professional part (multitrack)
300 static unsigned int rates
[] = {
301 8000, 9600, 11025, 12000, 16000, 22050, 24000,
302 32000, 44100, 48000, 64000, 88200, 96000,
306 static snd_pcm_hw_constraint_list_t hw_constraints_rates_96
= {
307 .count
= ARRAY_SIZE(rates
) - 2, /* up to 96000 */
312 static snd_pcm_hw_constraint_list_t hw_constraints_rates_48
= {
313 .count
= ARRAY_SIZE(rates
) - 5, /* up to 48000 */
318 static snd_pcm_hw_constraint_list_t hw_constraints_rates_192
= {
319 .count
= ARRAY_SIZE(rates
),
324 struct vt1724_pcm_reg
{
325 unsigned int addr
; /* ADDR register offset */
326 unsigned int size
; /* SIZE register offset */
327 unsigned int count
; /* COUNT register offset */
328 unsigned int start
; /* start & pause bit */
331 static int snd_vt1724_pcm_trigger(snd_pcm_substream_t
*substream
, int cmd
)
333 ice1712_t
*ice
= snd_pcm_substream_chip(substream
);
336 struct list_head
*pos
;
337 snd_pcm_substream_t
*s
;
340 snd_pcm_group_for_each(pos
, substream
) {
341 struct vt1724_pcm_reg
*reg
;
342 s
= snd_pcm_group_substream_entry(pos
);
343 reg
= s
->runtime
->private_data
;
345 snd_pcm_trigger_done(s
, substream
);
349 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
350 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
351 spin_lock(&ice
->reg_lock
);
352 old
= inb(ICEMT1724(ice
, DMA_PAUSE
));
353 if (cmd
== SNDRV_PCM_TRIGGER_PAUSE_PUSH
)
357 outb(old
, ICEMT1724(ice
, DMA_PAUSE
));
358 spin_unlock(&ice
->reg_lock
);
361 case SNDRV_PCM_TRIGGER_START
:
362 case SNDRV_PCM_TRIGGER_STOP
:
363 spin_lock(&ice
->reg_lock
);
364 old
= inb(ICEMT1724(ice
, DMA_CONTROL
));
365 if (cmd
== SNDRV_PCM_TRIGGER_START
)
369 outb(old
, ICEMT1724(ice
, DMA_CONTROL
));
370 spin_unlock(&ice
->reg_lock
);
382 #define DMA_STARTS (VT1724_RDMA0_START|VT1724_PDMA0_START|VT1724_RDMA1_START|\
383 VT1724_PDMA1_START|VT1724_PDMA2_START|VT1724_PDMA3_START|VT1724_PDMA4_START)
384 #define DMA_PAUSES (VT1724_RDMA0_PAUSE|VT1724_PDMA0_PAUSE|VT1724_RDMA1_PAUSE|\
385 VT1724_PDMA1_PAUSE|VT1724_PDMA2_PAUSE|VT1724_PDMA3_PAUSE|VT1724_PDMA4_PAUSE)
387 static int get_max_rate(ice1712_t
*ice
)
389 if (ice
->eeprom
.data
[ICE_EEP2_ACLINK
] & VT1724_CFG_PRO_I2S
) {
390 if ((ice
->eeprom
.data
[ICE_EEP2_I2S
] & 0x08) && !ice
->vt1720
)
398 static void snd_vt1724_set_pro_rate(ice1712_t
*ice
, unsigned int rate
, int force
)
401 unsigned char val
, old
;
402 unsigned int i
, mclk_change
;
404 if (rate
> get_max_rate(ice
))
408 case 8000: val
= 6; break;
409 case 9600: val
= 3; break;
410 case 11025: val
= 10; break;
411 case 12000: val
= 2; break;
412 case 16000: val
= 5; break;
413 case 22050: val
= 9; break;
414 case 24000: val
= 1; break;
415 case 32000: val
= 4; break;
416 case 44100: val
= 8; break;
417 case 48000: val
= 0; break;
418 case 64000: val
= 15; break;
419 case 88200: val
= 11; break;
420 case 96000: val
= 7; break;
421 case 176400: val
= 12; break;
422 case 192000: val
= 14; break;
429 spin_lock_irqsave(&ice
->reg_lock
, flags
);
430 if ((inb(ICEMT1724(ice
, DMA_CONTROL
)) & DMA_STARTS
) ||
431 (inb(ICEMT1724(ice
, DMA_PAUSE
)) & DMA_PAUSES
)) {
432 /* running? we cannot change the rate now... */
433 spin_unlock_irqrestore(&ice
->reg_lock
, flags
);
436 if (!force
&& is_pro_rate_locked(ice
)) {
437 spin_unlock_irqrestore(&ice
->reg_lock
, flags
);
441 old
= inb(ICEMT1724(ice
, RATE
));
442 if (force
|| old
!= val
)
443 outb(val
, ICEMT1724(ice
, RATE
));
444 else if (rate
== ice
->cur_rate
) {
445 spin_unlock_irqrestore(&ice
->reg_lock
, flags
);
449 ice
->cur_rate
= rate
;
453 if (ice
->eeprom
.data
[ICE_EEP2_ACLINK
] & VT1724_CFG_PRO_I2S
) {
454 val
= old
= inb(ICEMT1724(ice
, I2S_FORMAT
));
456 val
|= VT1724_MT_I2S_MCLK_128X
; /* 128x MCLK */
458 val
&= ~VT1724_MT_I2S_MCLK_128X
; /* 256x MCLK */
460 outb(val
, ICEMT1724(ice
, I2S_FORMAT
));
464 spin_unlock_irqrestore(&ice
->reg_lock
, flags
);
466 if (mclk_change
&& ice
->gpio
.i2s_mclk_changed
)
467 ice
->gpio
.i2s_mclk_changed(ice
);
468 if (ice
->gpio
.set_pro_rate
)
469 ice
->gpio
.set_pro_rate(ice
, rate
);
472 for (i
= 0; i
< ice
->akm_codecs
; i
++) {
473 if (ice
->akm
[i
].ops
.set_rate_val
)
474 ice
->akm
[i
].ops
.set_rate_val(&ice
->akm
[i
], rate
);
476 if (ice
->spdif
.ops
.setup_rate
)
477 ice
->spdif
.ops
.setup_rate(ice
, rate
);
480 static int snd_vt1724_pcm_hw_params(snd_pcm_substream_t
* substream
,
481 snd_pcm_hw_params_t
* hw_params
)
483 ice1712_t
*ice
= snd_pcm_substream_chip(substream
);
486 chs
= params_channels(hw_params
);
487 down(&ice
->open_mutex
);
488 /* mark surround channels */
489 if (substream
== ice
->playback_pro_substream
) {
490 /* PDMA0 can be multi-channel up to 8 */
492 for (i
= 0; i
< chs
; i
++) {
493 if (ice
->pcm_reserved
[i
] && ice
->pcm_reserved
[i
] != substream
) {
494 up(&ice
->open_mutex
);
497 ice
->pcm_reserved
[i
] = substream
;
500 if (ice
->pcm_reserved
[i
] == substream
)
501 ice
->pcm_reserved
[i
] = NULL
;
504 for (i
= 0; i
< 3; i
++) {
505 /* check individual playback stream */
506 if (ice
->playback_con_substream_ds
[i
] == substream
) {
507 if (ice
->pcm_reserved
[i
] && ice
->pcm_reserved
[i
] != substream
) {
508 up(&ice
->open_mutex
);
511 ice
->pcm_reserved
[i
] = substream
;
516 up(&ice
->open_mutex
);
517 snd_vt1724_set_pro_rate(ice
, params_rate(hw_params
), 0);
518 return snd_pcm_lib_malloc_pages(substream
, params_buffer_bytes(hw_params
));
521 static int snd_vt1724_pcm_hw_free(snd_pcm_substream_t
* substream
)
523 ice1712_t
*ice
= snd_pcm_substream_chip(substream
);
526 down(&ice
->open_mutex
);
527 /* unmark surround channels */
528 for (i
= 0; i
< 3; i
++)
529 if (ice
->pcm_reserved
[i
] == substream
)
530 ice
->pcm_reserved
[i
] = NULL
;
531 up(&ice
->open_mutex
);
532 return snd_pcm_lib_free_pages(substream
);
535 static int snd_vt1724_playback_pro_prepare(snd_pcm_substream_t
* substream
)
537 ice1712_t
*ice
= snd_pcm_substream_chip(substream
);
541 spin_lock_irq(&ice
->reg_lock
);
542 val
= (8 - substream
->runtime
->channels
) >> 1;
543 outb(val
, ICEMT1724(ice
, BURST
));
545 outl(substream
->runtime
->dma_addr
, ICEMT1724(ice
, PLAYBACK_ADDR
));
547 size
= (snd_pcm_lib_buffer_bytes(substream
) >> 2) - 1;
548 // outl(size, ICEMT1724(ice, PLAYBACK_SIZE));
549 outw(size
, ICEMT1724(ice
, PLAYBACK_SIZE
));
550 outb(size
>> 16, ICEMT1724(ice
, PLAYBACK_SIZE
) + 2);
551 size
= (snd_pcm_lib_period_bytes(substream
) >> 2) - 1;
552 // outl(size, ICEMT1724(ice, PLAYBACK_COUNT));
553 outw(size
, ICEMT1724(ice
, PLAYBACK_COUNT
));
554 outb(size
>> 16, ICEMT1724(ice
, PLAYBACK_COUNT
) + 2);
556 spin_unlock_irq(&ice
->reg_lock
);
558 // 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));
562 static snd_pcm_uframes_t
snd_vt1724_playback_pro_pointer(snd_pcm_substream_t
* substream
)
564 ice1712_t
*ice
= snd_pcm_substream_chip(substream
);
567 if (!(inl(ICEMT1724(ice
, DMA_CONTROL
)) & VT1724_PDMA0_START
))
569 #if 0 /* read PLAYBACK_ADDR */
570 ptr
= inl(ICEMT1724(ice
, PLAYBACK_ADDR
));
571 if (ptr
< substream
->runtime
->dma_addr
) {
572 snd_printd("ice1724: invalid negative ptr\n");
575 ptr
-= substream
->runtime
->dma_addr
;
576 ptr
= bytes_to_frames(substream
->runtime
, ptr
);
577 if (ptr
>= substream
->runtime
->buffer_size
) {
578 snd_printd("ice1724: invalid ptr %d (size=%d)\n", (int)ptr
, (int)substream
->runtime
->period_size
);
581 #else /* read PLAYBACK_SIZE */
582 ptr
= inl(ICEMT1724(ice
, PLAYBACK_SIZE
)) & 0xffffff;
583 ptr
= (ptr
+ 1) << 2;
584 ptr
= bytes_to_frames(substream
->runtime
, ptr
);
587 else if (ptr
<= substream
->runtime
->buffer_size
)
588 ptr
= substream
->runtime
->buffer_size
- ptr
;
590 snd_printd("ice1724: invalid ptr %d (size=%d)\n", (int)ptr
, (int)substream
->runtime
->buffer_size
);
597 static int snd_vt1724_pcm_prepare(snd_pcm_substream_t
*substream
)
599 ice1712_t
*ice
= snd_pcm_substream_chip(substream
);
600 struct vt1724_pcm_reg
*reg
= substream
->runtime
->private_data
;
602 spin_lock_irq(&ice
->reg_lock
);
603 outl(substream
->runtime
->dma_addr
, ice
->profi_port
+ reg
->addr
);
604 outw((snd_pcm_lib_buffer_bytes(substream
) >> 2) - 1, ice
->profi_port
+ reg
->size
);
605 outw((snd_pcm_lib_period_bytes(substream
) >> 2) - 1, ice
->profi_port
+ reg
->count
);
606 spin_unlock_irq(&ice
->reg_lock
);
610 static snd_pcm_uframes_t
snd_vt1724_pcm_pointer(snd_pcm_substream_t
*substream
)
612 ice1712_t
*ice
= snd_pcm_substream_chip(substream
);
613 struct vt1724_pcm_reg
*reg
= substream
->runtime
->private_data
;
616 if (!(inl(ICEMT1724(ice
, DMA_CONTROL
)) & reg
->start
))
618 #if 0 /* use ADDR register */
619 ptr
= inl(ice
->profi_port
+ reg
->addr
);
620 ptr
-= substream
->runtime
->dma_addr
;
621 return bytes_to_frames(substream
->runtime
, ptr
);
622 #else /* use SIZE register */
623 ptr
= inw(ice
->profi_port
+ reg
->size
);
624 ptr
= (ptr
+ 1) << 2;
625 ptr
= bytes_to_frames(substream
->runtime
, ptr
);
628 else if (ptr
<= substream
->runtime
->buffer_size
)
629 ptr
= substream
->runtime
->buffer_size
- ptr
;
631 snd_printd("ice1724: invalid ptr %d (size=%d)\n", (int)ptr
, (int)substream
->runtime
->buffer_size
);
638 static struct vt1724_pcm_reg vt1724_playback_pro_reg
= {
639 .addr
= VT1724_MT_PLAYBACK_ADDR
,
640 .size
= VT1724_MT_PLAYBACK_SIZE
,
641 .count
= VT1724_MT_PLAYBACK_COUNT
,
642 .start
= VT1724_PDMA0_START
,
645 static struct vt1724_pcm_reg vt1724_capture_pro_reg
= {
646 .addr
= VT1724_MT_CAPTURE_ADDR
,
647 .size
= VT1724_MT_CAPTURE_SIZE
,
648 .count
= VT1724_MT_CAPTURE_COUNT
,
649 .start
= VT1724_RDMA0_START
,
652 static snd_pcm_hardware_t snd_vt1724_playback_pro
=
654 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
655 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
656 SNDRV_PCM_INFO_MMAP_VALID
|
657 SNDRV_PCM_INFO_PAUSE
| SNDRV_PCM_INFO_SYNC_START
),
658 .formats
= SNDRV_PCM_FMTBIT_S32_LE
,
659 .rates
= SNDRV_PCM_RATE_KNOT
| SNDRV_PCM_RATE_8000_192000
,
664 .buffer_bytes_max
= (1UL << 21), /* 19bits dword */
665 .period_bytes_min
= 8 * 4 * 2, /* FIXME: constraints needed */
666 .period_bytes_max
= (1UL << 21),
671 static snd_pcm_hardware_t snd_vt1724_spdif
=
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_32000
|SNDRV_PCM_RATE_44100
|
679 SNDRV_PCM_RATE_48000
|SNDRV_PCM_RATE_88200
|
680 SNDRV_PCM_RATE_96000
|SNDRV_PCM_RATE_176400
|
681 SNDRV_PCM_RATE_192000
),
686 .buffer_bytes_max
= (1UL << 18), /* 16bits dword */
687 .period_bytes_min
= 2 * 4 * 2,
688 .period_bytes_max
= (1UL << 18),
693 static snd_pcm_hardware_t snd_vt1724_2ch_stereo
=
695 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
696 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
697 SNDRV_PCM_INFO_MMAP_VALID
|
698 SNDRV_PCM_INFO_PAUSE
| SNDRV_PCM_INFO_SYNC_START
),
699 .formats
= SNDRV_PCM_FMTBIT_S32_LE
,
700 .rates
= SNDRV_PCM_RATE_KNOT
| SNDRV_PCM_RATE_8000_192000
,
705 .buffer_bytes_max
= (1UL << 18), /* 16bits dword */
706 .period_bytes_min
= 2 * 4 * 2,
707 .period_bytes_max
= (1UL << 18),
713 * set rate constraints
715 static int set_rate_constraints(ice1712_t
*ice
, snd_pcm_substream_t
*substream
)
717 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
719 /* hardware specific */
720 runtime
->hw
.rate_min
= ice
->hw_rates
->list
[0];
721 runtime
->hw
.rate_max
= ice
->hw_rates
->list
[ice
->hw_rates
->count
- 1];
722 runtime
->hw
.rates
= SNDRV_PCM_RATE_KNOT
;
723 return snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
, ice
->hw_rates
);
725 if (ice
->eeprom
.data
[ICE_EEP2_ACLINK
] & VT1724_CFG_PRO_I2S
) {
727 /* VT1720 doesn't support more than 96kHz */
728 if ((ice
->eeprom
.data
[ICE_EEP2_I2S
] & 0x08) && !ice
->vt1720
)
729 return snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
, &hw_constraints_rates_192
);
731 runtime
->hw
.rates
= SNDRV_PCM_RATE_KNOT
| SNDRV_PCM_RATE_8000_96000
;
732 runtime
->hw
.rate_max
= 96000;
733 return snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
, &hw_constraints_rates_96
);
735 } else if (ice
->ac97
) {
737 runtime
->hw
.rate_max
= 48000;
738 runtime
->hw
.rates
= SNDRV_PCM_RATE_KNOT
| SNDRV_PCM_RATE_8000_48000
;
739 return snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
, &hw_constraints_rates_48
);
744 /* multi-channel playback needs alignment 8x32bit regardless of the channels
747 #define VT1724_BUFFER_ALIGN 0x20
749 static int snd_vt1724_playback_pro_open(snd_pcm_substream_t
* substream
)
751 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
752 ice1712_t
*ice
= snd_pcm_substream_chip(substream
);
755 runtime
->private_data
= &vt1724_playback_pro_reg
;
756 ice
->playback_pro_substream
= substream
;
757 runtime
->hw
= snd_vt1724_playback_pro
;
758 snd_pcm_set_sync(substream
);
759 snd_pcm_hw_constraint_msbits(runtime
, 0, 32, 24);
760 set_rate_constraints(ice
, substream
);
761 down(&ice
->open_mutex
);
762 /* calculate the currently available channels */
763 for (chs
= 0; chs
< 3; chs
++) {
764 if (ice
->pcm_reserved
[chs
])
768 runtime
->hw
.channels_max
= chs
;
769 if (chs
> 2) /* channels must be even */
770 snd_pcm_hw_constraint_step(runtime
, 0, SNDRV_PCM_HW_PARAM_CHANNELS
, 2);
771 up(&ice
->open_mutex
);
772 snd_pcm_hw_constraint_step(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES
,
773 VT1724_BUFFER_ALIGN
);
774 snd_pcm_hw_constraint_step(runtime
, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES
,
775 VT1724_BUFFER_ALIGN
);
779 static int snd_vt1724_capture_pro_open(snd_pcm_substream_t
* substream
)
781 ice1712_t
*ice
= snd_pcm_substream_chip(substream
);
782 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
784 runtime
->private_data
= &vt1724_capture_pro_reg
;
785 ice
->capture_pro_substream
= substream
;
786 runtime
->hw
= snd_vt1724_2ch_stereo
;
787 snd_pcm_set_sync(substream
);
788 snd_pcm_hw_constraint_msbits(runtime
, 0, 32, 24);
789 set_rate_constraints(ice
, substream
);
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_playback_pro_close(snd_pcm_substream_t
* substream
)
799 ice1712_t
*ice
= snd_pcm_substream_chip(substream
);
802 snd_vt1724_set_pro_rate(ice
, PRO_RATE_DEFAULT
, 0);
803 ice
->playback_pro_substream
= NULL
;
808 static int snd_vt1724_capture_pro_close(snd_pcm_substream_t
* substream
)
810 ice1712_t
*ice
= snd_pcm_substream_chip(substream
);
813 snd_vt1724_set_pro_rate(ice
, PRO_RATE_DEFAULT
, 0);
814 ice
->capture_pro_substream
= NULL
;
818 static snd_pcm_ops_t snd_vt1724_playback_pro_ops
= {
819 .open
= snd_vt1724_playback_pro_open
,
820 .close
= snd_vt1724_playback_pro_close
,
821 .ioctl
= snd_pcm_lib_ioctl
,
822 .hw_params
= snd_vt1724_pcm_hw_params
,
823 .hw_free
= snd_vt1724_pcm_hw_free
,
824 .prepare
= snd_vt1724_playback_pro_prepare
,
825 .trigger
= snd_vt1724_pcm_trigger
,
826 .pointer
= snd_vt1724_playback_pro_pointer
,
829 static snd_pcm_ops_t snd_vt1724_capture_pro_ops
= {
830 .open
= snd_vt1724_capture_pro_open
,
831 .close
= snd_vt1724_capture_pro_close
,
832 .ioctl
= snd_pcm_lib_ioctl
,
833 .hw_params
= snd_vt1724_pcm_hw_params
,
834 .hw_free
= snd_vt1724_pcm_hw_free
,
835 .prepare
= snd_vt1724_pcm_prepare
,
836 .trigger
= snd_vt1724_pcm_trigger
,
837 .pointer
= snd_vt1724_pcm_pointer
,
840 static int __devinit
snd_vt1724_pcm_profi(ice1712_t
* ice
, int device
)
845 err
= snd_pcm_new(ice
->card
, "ICE1724", device
, 1, 1, &pcm
);
849 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_vt1724_playback_pro_ops
);
850 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
, &snd_vt1724_capture_pro_ops
);
852 pcm
->private_data
= ice
;
854 strcpy(pcm
->name
, "ICE1724");
856 snd_pcm_lib_preallocate_pages_for_all(pcm
, SNDRV_DMA_TYPE_DEV
,
857 snd_dma_pci_data(ice
->pci
), 256*1024, 256*1024);
869 static struct vt1724_pcm_reg vt1724_playback_spdif_reg
= {
870 .addr
= VT1724_MT_PDMA4_ADDR
,
871 .size
= VT1724_MT_PDMA4_SIZE
,
872 .count
= VT1724_MT_PDMA4_COUNT
,
873 .start
= VT1724_PDMA4_START
,
876 static struct vt1724_pcm_reg vt1724_capture_spdif_reg
= {
877 .addr
= VT1724_MT_RDMA1_ADDR
,
878 .size
= VT1724_MT_RDMA1_SIZE
,
879 .count
= VT1724_MT_RDMA1_COUNT
,
880 .start
= VT1724_RDMA1_START
,
883 /* update spdif control bits; call with reg_lock */
884 static void update_spdif_bits(ice1712_t
*ice
, unsigned int val
)
886 unsigned char cbit
, disabled
;
888 cbit
= inb(ICEREG1724(ice
, SPDIF_CFG
));
889 disabled
= cbit
& ~VT1724_CFG_SPDIF_OUT_EN
;
890 if (cbit
!= disabled
)
891 outb(disabled
, ICEREG1724(ice
, SPDIF_CFG
));
892 outw(val
, ICEMT1724(ice
, SPDIF_CTRL
));
893 if (cbit
!= disabled
)
894 outb(cbit
, ICEREG1724(ice
, SPDIF_CFG
));
895 outw(val
, ICEMT1724(ice
, SPDIF_CTRL
));
898 /* update SPDIF control bits according to the given rate */
899 static void update_spdif_rate(ice1712_t
*ice
, unsigned int rate
)
901 unsigned int val
, nval
;
904 spin_lock_irqsave(&ice
->reg_lock
, flags
);
905 nval
= val
= inw(ICEMT1724(ice
, SPDIF_CTRL
));
909 case 48000: nval
|= 2 << 12; break;
910 case 32000: nval
|= 3 << 12; break;
911 case 88200: nval
|= 4 << 12; break;
912 case 96000: nval
|= 5 << 12; break;
913 case 192000: nval
|= 6 << 12; break;
914 case 176400: nval
|= 7 << 12; break;
917 update_spdif_bits(ice
, nval
);
918 spin_unlock_irqrestore(&ice
->reg_lock
, flags
);
921 static int snd_vt1724_playback_spdif_prepare(snd_pcm_substream_t
* substream
)
923 ice1712_t
*ice
= snd_pcm_substream_chip(substream
);
924 if (! ice
->force_pdma4
)
925 update_spdif_rate(ice
, substream
->runtime
->rate
);
926 return snd_vt1724_pcm_prepare(substream
);
929 static int snd_vt1724_playback_spdif_open(snd_pcm_substream_t
*substream
)
931 ice1712_t
*ice
= snd_pcm_substream_chip(substream
);
932 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
934 runtime
->private_data
= &vt1724_playback_spdif_reg
;
935 ice
->playback_con_substream
= substream
;
936 if (ice
->force_pdma4
) {
937 runtime
->hw
= snd_vt1724_2ch_stereo
;
938 set_rate_constraints(ice
, substream
);
940 runtime
->hw
= snd_vt1724_spdif
;
941 snd_pcm_set_sync(substream
);
942 snd_pcm_hw_constraint_msbits(runtime
, 0, 32, 24);
943 snd_pcm_hw_constraint_step(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES
,
944 VT1724_BUFFER_ALIGN
);
945 snd_pcm_hw_constraint_step(runtime
, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES
,
946 VT1724_BUFFER_ALIGN
);
950 static int snd_vt1724_playback_spdif_close(snd_pcm_substream_t
* substream
)
952 ice1712_t
*ice
= snd_pcm_substream_chip(substream
);
955 snd_vt1724_set_pro_rate(ice
, PRO_RATE_DEFAULT
, 0);
956 ice
->playback_con_substream
= NULL
;
961 static int snd_vt1724_capture_spdif_open(snd_pcm_substream_t
*substream
)
963 ice1712_t
*ice
= snd_pcm_substream_chip(substream
);
964 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
966 runtime
->private_data
= &vt1724_capture_spdif_reg
;
967 ice
->capture_con_substream
= substream
;
968 if (ice
->force_rdma1
) {
969 runtime
->hw
= snd_vt1724_2ch_stereo
;
970 set_rate_constraints(ice
, substream
);
972 runtime
->hw
= snd_vt1724_spdif
;
973 snd_pcm_set_sync(substream
);
974 snd_pcm_hw_constraint_msbits(runtime
, 0, 32, 24);
975 snd_pcm_hw_constraint_step(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES
,
976 VT1724_BUFFER_ALIGN
);
977 snd_pcm_hw_constraint_step(runtime
, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES
,
978 VT1724_BUFFER_ALIGN
);
982 static int snd_vt1724_capture_spdif_close(snd_pcm_substream_t
* substream
)
984 ice1712_t
*ice
= snd_pcm_substream_chip(substream
);
987 snd_vt1724_set_pro_rate(ice
, PRO_RATE_DEFAULT
, 0);
988 ice
->capture_con_substream
= NULL
;
993 static snd_pcm_ops_t snd_vt1724_playback_spdif_ops
= {
994 .open
= snd_vt1724_playback_spdif_open
,
995 .close
= snd_vt1724_playback_spdif_close
,
996 .ioctl
= snd_pcm_lib_ioctl
,
997 .hw_params
= snd_vt1724_pcm_hw_params
,
998 .hw_free
= snd_vt1724_pcm_hw_free
,
999 .prepare
= snd_vt1724_playback_spdif_prepare
,
1000 .trigger
= snd_vt1724_pcm_trigger
,
1001 .pointer
= snd_vt1724_pcm_pointer
,
1004 static snd_pcm_ops_t snd_vt1724_capture_spdif_ops
= {
1005 .open
= snd_vt1724_capture_spdif_open
,
1006 .close
= snd_vt1724_capture_spdif_close
,
1007 .ioctl
= snd_pcm_lib_ioctl
,
1008 .hw_params
= snd_vt1724_pcm_hw_params
,
1009 .hw_free
= snd_vt1724_pcm_hw_free
,
1010 .prepare
= snd_vt1724_pcm_prepare
,
1011 .trigger
= snd_vt1724_pcm_trigger
,
1012 .pointer
= snd_vt1724_pcm_pointer
,
1016 static int __devinit
snd_vt1724_pcm_spdif(ice1712_t
* ice
, int device
)
1023 if (ice
->force_pdma4
||
1024 (ice
->eeprom
.data
[ICE_EEP2_SPDIF
] & VT1724_CFG_SPDIF_OUT_INT
)) {
1029 if (ice
->force_rdma1
||
1030 (ice
->eeprom
.data
[ICE_EEP2_SPDIF
] & VT1724_CFG_SPDIF_IN
)) {
1035 if (! play
&& ! capt
)
1036 return 0; /* no spdif device */
1038 if (ice
->force_pdma4
|| ice
->force_rdma1
)
1039 name
= "ICE1724 Secondary";
1041 name
= "IEC1724 IEC958";
1042 err
= snd_pcm_new(ice
->card
, name
, device
, play
, capt
, &pcm
);
1047 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
,
1048 &snd_vt1724_playback_spdif_ops
);
1050 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
,
1051 &snd_vt1724_capture_spdif_ops
);
1053 pcm
->private_data
= ice
;
1054 pcm
->info_flags
= 0;
1055 strcpy(pcm
->name
, name
);
1057 snd_pcm_lib_preallocate_pages_for_all(pcm
, SNDRV_DMA_TYPE_DEV
,
1058 snd_dma_pci_data(ice
->pci
), 64*1024, 64*1024);
1067 * independent surround PCMs
1070 static struct vt1724_pcm_reg vt1724_playback_dma_regs
[3] = {
1072 .addr
= VT1724_MT_PDMA1_ADDR
,
1073 .size
= VT1724_MT_PDMA1_SIZE
,
1074 .count
= VT1724_MT_PDMA1_COUNT
,
1075 .start
= VT1724_PDMA1_START
,
1078 .addr
= VT1724_MT_PDMA2_ADDR
,
1079 .size
= VT1724_MT_PDMA2_SIZE
,
1080 .count
= VT1724_MT_PDMA2_COUNT
,
1081 .start
= VT1724_PDMA2_START
,
1084 .addr
= VT1724_MT_PDMA3_ADDR
,
1085 .size
= VT1724_MT_PDMA3_SIZE
,
1086 .count
= VT1724_MT_PDMA3_COUNT
,
1087 .start
= VT1724_PDMA3_START
,
1091 static int snd_vt1724_playback_indep_prepare(snd_pcm_substream_t
* substream
)
1093 ice1712_t
*ice
= snd_pcm_substream_chip(substream
);
1096 spin_lock_irq(&ice
->reg_lock
);
1097 val
= 3 - substream
->number
;
1098 if (inb(ICEMT1724(ice
, BURST
)) < val
)
1099 outb(val
, ICEMT1724(ice
, BURST
));
1100 spin_unlock_irq(&ice
->reg_lock
);
1101 return snd_vt1724_pcm_prepare(substream
);
1104 static int snd_vt1724_playback_indep_open(snd_pcm_substream_t
*substream
)
1106 ice1712_t
*ice
= snd_pcm_substream_chip(substream
);
1107 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
1109 down(&ice
->open_mutex
);
1110 /* already used by PDMA0? */
1111 if (ice
->pcm_reserved
[substream
->number
]) {
1112 up(&ice
->open_mutex
);
1113 return -EBUSY
; /* FIXME: should handle blocking mode properly */
1115 up(&ice
->open_mutex
);
1116 runtime
->private_data
= &vt1724_playback_dma_regs
[substream
->number
];
1117 ice
->playback_con_substream_ds
[substream
->number
] = substream
;
1118 runtime
->hw
= snd_vt1724_2ch_stereo
;
1119 snd_pcm_set_sync(substream
);
1120 snd_pcm_hw_constraint_msbits(runtime
, 0, 32, 24);
1121 set_rate_constraints(ice
, substream
);
1125 static int snd_vt1724_playback_indep_close(snd_pcm_substream_t
* substream
)
1127 ice1712_t
*ice
= snd_pcm_substream_chip(substream
);
1130 snd_vt1724_set_pro_rate(ice
, PRO_RATE_DEFAULT
, 0);
1131 ice
->playback_con_substream_ds
[substream
->number
] = NULL
;
1132 ice
->pcm_reserved
[substream
->number
] = NULL
;
1137 static snd_pcm_ops_t snd_vt1724_playback_indep_ops
= {
1138 .open
= snd_vt1724_playback_indep_open
,
1139 .close
= snd_vt1724_playback_indep_close
,
1140 .ioctl
= snd_pcm_lib_ioctl
,
1141 .hw_params
= snd_vt1724_pcm_hw_params
,
1142 .hw_free
= snd_vt1724_pcm_hw_free
,
1143 .prepare
= snd_vt1724_playback_indep_prepare
,
1144 .trigger
= snd_vt1724_pcm_trigger
,
1145 .pointer
= snd_vt1724_pcm_pointer
,
1149 static int __devinit
snd_vt1724_pcm_indep(ice1712_t
* ice
, int device
)
1155 play
= ice
->num_total_dacs
/ 2 - 1;
1159 err
= snd_pcm_new(ice
->card
, "ICE1724 Surrounds", device
, play
, 0, &pcm
);
1163 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
,
1164 &snd_vt1724_playback_indep_ops
);
1166 pcm
->private_data
= ice
;
1167 pcm
->info_flags
= 0;
1168 strcpy(pcm
->name
, "ICE1724 Surround PCM");
1170 snd_pcm_lib_preallocate_pages_for_all(pcm
, SNDRV_DMA_TYPE_DEV
,
1171 snd_dma_pci_data(ice
->pci
), 64*1024, 64*1024);
1183 static int __devinit
snd_vt1724_ac97_mixer(ice1712_t
* ice
)
1187 if (! (ice
->eeprom
.data
[ICE_EEP2_ACLINK
] & VT1724_CFG_PRO_I2S
)) {
1189 ac97_template_t ac97
;
1190 static ac97_bus_ops_t ops
= {
1191 .write
= snd_vt1724_ac97_write
,
1192 .read
= snd_vt1724_ac97_read
,
1196 outb(inb(ICEMT1724(ice
, AC97_CMD
)) | 0x80, ICEMT1724(ice
, AC97_CMD
));
1197 mdelay(5); /* FIXME */
1198 outb(inb(ICEMT1724(ice
, AC97_CMD
)) & ~0x80, ICEMT1724(ice
, AC97_CMD
));
1200 if ((err
= snd_ac97_bus(ice
->card
, 0, &ops
, NULL
, &pbus
)) < 0)
1202 memset(&ac97
, 0, sizeof(ac97
));
1203 ac97
.private_data
= ice
;
1204 if ((err
= snd_ac97_mixer(pbus
, &ac97
, &ice
->ac97
)) < 0)
1205 printk(KERN_WARNING
"ice1712: cannot initialize pro ac97, skipped\n");
1209 /* I2S mixer only */
1210 strcat(ice
->card
->mixername
, "ICE1724 - multitrack");
1218 static inline unsigned int eeprom_triple(ice1712_t
*ice
, int idx
)
1220 return (unsigned int)ice
->eeprom
.data
[idx
] | \
1221 ((unsigned int)ice
->eeprom
.data
[idx
+ 1] << 8) | \
1222 ((unsigned int)ice
->eeprom
.data
[idx
+ 2] << 16);
1225 static void snd_vt1724_proc_read(snd_info_entry_t
*entry
,
1226 snd_info_buffer_t
* buffer
)
1228 ice1712_t
*ice
= entry
->private_data
;
1231 snd_iprintf(buffer
, "%s\n\n", ice
->card
->longname
);
1232 snd_iprintf(buffer
, "EEPROM:\n");
1234 snd_iprintf(buffer
, " Subvendor : 0x%x\n", ice
->eeprom
.subvendor
);
1235 snd_iprintf(buffer
, " Size : %i bytes\n", ice
->eeprom
.size
);
1236 snd_iprintf(buffer
, " Version : %i\n", ice
->eeprom
.version
);
1237 snd_iprintf(buffer
, " System Config : 0x%x\n", ice
->eeprom
.data
[ICE_EEP2_SYSCONF
]);
1238 snd_iprintf(buffer
, " ACLink : 0x%x\n", ice
->eeprom
.data
[ICE_EEP2_ACLINK
]);
1239 snd_iprintf(buffer
, " I2S : 0x%x\n", ice
->eeprom
.data
[ICE_EEP2_I2S
]);
1240 snd_iprintf(buffer
, " S/PDIF : 0x%x\n", ice
->eeprom
.data
[ICE_EEP2_SPDIF
]);
1241 snd_iprintf(buffer
, " GPIO direction : 0x%x\n", ice
->eeprom
.gpiodir
);
1242 snd_iprintf(buffer
, " GPIO mask : 0x%x\n", ice
->eeprom
.gpiomask
);
1243 snd_iprintf(buffer
, " GPIO state : 0x%x\n", ice
->eeprom
.gpiostate
);
1244 for (idx
= 0x12; idx
< ice
->eeprom
.size
; idx
++)
1245 snd_iprintf(buffer
, " Extra #%02i : 0x%x\n", idx
, ice
->eeprom
.data
[idx
]);
1247 snd_iprintf(buffer
, "\nRegisters:\n");
1249 snd_iprintf(buffer
, " PSDOUT03 : 0x%08x\n", (unsigned)inl(ICEMT1724(ice
, ROUTE_PLAYBACK
)));
1250 for (idx
= 0x0; idx
< 0x20 ; idx
++)
1251 snd_iprintf(buffer
, " CCS%02x : 0x%02x\n", idx
, inb(ice
->port
+idx
));
1252 for (idx
= 0x0; idx
< 0x30 ; idx
++)
1253 snd_iprintf(buffer
, " MT%02x : 0x%02x\n", idx
, inb(ice
->profi_port
+idx
));
1256 static void __devinit
snd_vt1724_proc_init(ice1712_t
* ice
)
1258 snd_info_entry_t
*entry
;
1260 if (! snd_card_proc_new(ice
->card
, "ice1724", &entry
))
1261 snd_info_set_text_ops(entry
, ice
, 1024, snd_vt1724_proc_read
);
1268 static int snd_vt1724_eeprom_info(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
* uinfo
)
1270 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BYTES
;
1271 uinfo
->count
= sizeof(ice1712_eeprom_t
);
1275 static int snd_vt1724_eeprom_get(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
1277 ice1712_t
*ice
= snd_kcontrol_chip(kcontrol
);
1279 memcpy(ucontrol
->value
.bytes
.data
, &ice
->eeprom
, sizeof(ice
->eeprom
));
1283 static snd_kcontrol_new_t snd_vt1724_eeprom __devinitdata
= {
1284 .iface
= SNDRV_CTL_ELEM_IFACE_CARD
,
1285 .name
= "ICE1724 EEPROM",
1286 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
1287 .info
= snd_vt1724_eeprom_info
,
1288 .get
= snd_vt1724_eeprom_get
1293 static int snd_vt1724_spdif_info(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
* uinfo
)
1295 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_IEC958
;
1300 static unsigned int encode_spdif_bits(snd_aes_iec958_t
*diga
)
1302 unsigned int val
, rbits
;
1304 val
= diga
->status
[0] & 0x03; /* professional, non-audio */
1307 if ((diga
->status
[0] & IEC958_AES0_PRO_EMPHASIS
) == IEC958_AES0_PRO_EMPHASIS_5015
)
1309 rbits
= (diga
->status
[4] >> 3) & 0x0f;
1312 case 2: val
|= 5 << 12; break; /* 96k */
1313 case 3: val
|= 6 << 12; break; /* 192k */
1314 case 10: val
|= 4 << 12; break; /* 88.2k */
1315 case 11: val
|= 7 << 12; break; /* 176.4k */
1318 switch (diga
->status
[0] & IEC958_AES0_PRO_FS
) {
1319 case IEC958_AES0_PRO_FS_44100
:
1321 case IEC958_AES0_PRO_FS_32000
:
1331 val
|= diga
->status
[1] & 0x04; /* copyright */
1332 if ((diga
->status
[0] & IEC958_AES0_CON_EMPHASIS
)== IEC958_AES0_CON_EMPHASIS_5015
)
1334 val
|= (unsigned int)(diga
->status
[1] & 0x3f) << 4; /* category */
1335 val
|= (unsigned int)(diga
->status
[3] & IEC958_AES3_CON_FS
) << 12; /* fs */
1340 static void decode_spdif_bits(snd_aes_iec958_t
*diga
, unsigned int val
)
1342 memset(diga
->status
, 0, sizeof(diga
->status
));
1343 diga
->status
[0] = val
& 0x03; /* professional, non-audio */
1346 if (val
& (1U << 3))
1347 diga
->status
[0] |= IEC958_AES0_PRO_EMPHASIS_5015
;
1348 switch ((val
>> 12) & 0x7) {
1352 diga
->status
[0] |= IEC958_AES0_PRO_FS_32000
;
1355 diga
->status
[0] |= IEC958_AES0_PRO_FS_48000
;
1360 diga
->status
[0] |= val
& (1U << 2); /* copyright */
1361 if (val
& (1U << 3))
1362 diga
->status
[0] |= IEC958_AES0_CON_EMPHASIS_5015
;
1363 diga
->status
[1] |= (val
>> 4) & 0x3f; /* category */
1364 diga
->status
[3] |= (val
>> 12) & 0x07; /* fs */
1368 static int snd_vt1724_spdif_default_get(snd_kcontrol_t
* kcontrol
,
1369 snd_ctl_elem_value_t
* ucontrol
)
1371 ice1712_t
*ice
= snd_kcontrol_chip(kcontrol
);
1373 val
= inw(ICEMT1724(ice
, SPDIF_CTRL
));
1374 decode_spdif_bits(&ucontrol
->value
.iec958
, val
);
1378 static int snd_vt1724_spdif_default_put(snd_kcontrol_t
* kcontrol
,
1379 snd_ctl_elem_value_t
* ucontrol
)
1381 ice1712_t
*ice
= snd_kcontrol_chip(kcontrol
);
1382 unsigned int val
, old
;
1384 val
= encode_spdif_bits(&ucontrol
->value
.iec958
);
1385 spin_lock_irq(&ice
->reg_lock
);
1386 old
= inw(ICEMT1724(ice
, SPDIF_CTRL
));
1388 update_spdif_bits(ice
, val
);
1389 spin_unlock_irq(&ice
->reg_lock
);
1390 return (val
!= old
);
1393 static snd_kcontrol_new_t snd_vt1724_spdif_default __devinitdata
=
1395 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
1396 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,DEFAULT
),
1397 .info
= snd_vt1724_spdif_info
,
1398 .get
= snd_vt1724_spdif_default_get
,
1399 .put
= snd_vt1724_spdif_default_put
1402 static int snd_vt1724_spdif_maskc_get(snd_kcontrol_t
* kcontrol
,
1403 snd_ctl_elem_value_t
* ucontrol
)
1405 ucontrol
->value
.iec958
.status
[0] = IEC958_AES0_NONAUDIO
|
1406 IEC958_AES0_PROFESSIONAL
|
1407 IEC958_AES0_CON_NOT_COPYRIGHT
|
1408 IEC958_AES0_CON_EMPHASIS
;
1409 ucontrol
->value
.iec958
.status
[1] = IEC958_AES1_CON_ORIGINAL
|
1410 IEC958_AES1_CON_CATEGORY
;
1411 ucontrol
->value
.iec958
.status
[3] = IEC958_AES3_CON_FS
;
1415 static int snd_vt1724_spdif_maskp_get(snd_kcontrol_t
* kcontrol
,
1416 snd_ctl_elem_value_t
* ucontrol
)
1418 ucontrol
->value
.iec958
.status
[0] = IEC958_AES0_NONAUDIO
|
1419 IEC958_AES0_PROFESSIONAL
|
1420 IEC958_AES0_PRO_FS
|
1421 IEC958_AES0_PRO_EMPHASIS
;
1425 static snd_kcontrol_new_t snd_vt1724_spdif_maskc __devinitdata
=
1427 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
1428 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
1429 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,CON_MASK
),
1430 .info
= snd_vt1724_spdif_info
,
1431 .get
= snd_vt1724_spdif_maskc_get
,
1434 static snd_kcontrol_new_t snd_vt1724_spdif_maskp __devinitdata
=
1436 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
1437 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
1438 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,PRO_MASK
),
1439 .info
= snd_vt1724_spdif_info
,
1440 .get
= snd_vt1724_spdif_maskp_get
,
1443 static int snd_vt1724_spdif_sw_info(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
* uinfo
)
1445 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
1447 uinfo
->value
.integer
.min
= 0;
1448 uinfo
->value
.integer
.max
= 1;
1452 static int snd_vt1724_spdif_sw_get(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
1454 ice1712_t
*ice
= snd_kcontrol_chip(kcontrol
);
1455 ucontrol
->value
.integer
.value
[0] = inb(ICEREG1724(ice
, SPDIF_CFG
)) & VT1724_CFG_SPDIF_OUT_EN
? 1 : 0;
1459 static int snd_vt1724_spdif_sw_put(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
1461 ice1712_t
*ice
= snd_kcontrol_chip(kcontrol
);
1462 unsigned char old
, val
;
1464 spin_lock_irq(&ice
->reg_lock
);
1465 old
= val
= inb(ICEREG1724(ice
, SPDIF_CFG
));
1466 val
&= ~VT1724_CFG_SPDIF_OUT_EN
;
1467 if (ucontrol
->value
.integer
.value
[0])
1468 val
|= VT1724_CFG_SPDIF_OUT_EN
;
1470 outb(val
, ICEREG1724(ice
, SPDIF_CFG
));
1471 spin_unlock_irq(&ice
->reg_lock
);
1475 static snd_kcontrol_new_t snd_vt1724_spdif_switch __devinitdata
=
1477 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1478 /* FIXME: the following conflict with IEC958 Playback Route */
1479 // .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH),
1480 .name
= SNDRV_CTL_NAME_IEC958("Output ",NONE
,SWITCH
),
1481 .info
= snd_vt1724_spdif_sw_info
,
1482 .get
= snd_vt1724_spdif_sw_get
,
1483 .put
= snd_vt1724_spdif_sw_put
1487 #if 0 /* NOT USED YET */
1489 * GPIO access from extern
1492 int snd_vt1724_gpio_info(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
* uinfo
)
1494 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
1496 uinfo
->value
.integer
.min
= 0;
1497 uinfo
->value
.integer
.max
= 1;
1501 int snd_vt1724_gpio_get(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
1503 ice1712_t
*ice
= snd_kcontrol_chip(kcontrol
);
1504 int shift
= kcontrol
->private_value
& 0xff;
1505 int invert
= (kcontrol
->private_value
& (1<<24)) ? 1 : 0;
1507 snd_ice1712_save_gpio_status(ice
);
1508 ucontrol
->value
.integer
.value
[0] = (snd_ice1712_gpio_read(ice
) & (1 << shift
) ? 1 : 0) ^ invert
;
1509 snd_ice1712_restore_gpio_status(ice
);
1513 int snd_ice1712_gpio_put(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
1515 ice1712_t
*ice
= snd_kcontrol_chip(kcontrol
);
1516 int shift
= kcontrol
->private_value
& 0xff;
1517 int invert
= (kcontrol
->private_value
& (1<<24)) ? mask
: 0;
1518 unsigned int val
, nval
;
1520 if (kcontrol
->private_value
& (1 << 31))
1522 nval
= (ucontrol
->value
.integer
.value
[0] ? (1 << shift
) : 0) ^ invert
;
1523 snd_ice1712_save_gpio_status(ice
);
1524 val
= snd_ice1712_gpio_read(ice
);
1525 nval
|= val
& ~(1 << shift
);
1527 snd_ice1712_gpio_write(ice
, nval
);
1528 snd_ice1712_restore_gpio_status(ice
);
1531 #endif /* NOT USED YET */
1536 static int snd_vt1724_pro_internal_clock_info(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
* uinfo
)
1538 static char *texts_1724
[] = {
1541 "11025", /* 2: 10 */
1549 "64000", /* 10: 15 */
1550 "88200", /* 11: 11 */
1551 "96000", /* 12: 7 */
1552 "176400", /* 13: 12 */
1553 "192000", /* 14: 14 */
1554 "IEC958 Input", /* 15: -- */
1556 static char *texts_1720
[] = {
1559 "11025", /* 2: 10 */
1567 "64000", /* 10: 15 */
1568 "88200", /* 11: 11 */
1569 "96000", /* 12: 7 */
1570 "IEC958 Input", /* 13: -- */
1572 ice1712_t
*ice
= snd_kcontrol_chip(kcontrol
);
1574 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
1576 uinfo
->value
.enumerated
.items
= ice
->vt1720
? 14 : 16;
1577 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
)
1578 uinfo
->value
.enumerated
.item
= uinfo
->value
.enumerated
.items
- 1;
1579 strcpy(uinfo
->value
.enumerated
.name
,
1580 ice
->vt1720
? texts_1720
[uinfo
->value
.enumerated
.item
] :
1581 texts_1724
[uinfo
->value
.enumerated
.item
]);
1585 static int snd_vt1724_pro_internal_clock_get(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
1587 ice1712_t
*ice
= snd_kcontrol_chip(kcontrol
);
1588 static unsigned char xlate
[16] = {
1589 9, 6, 3, 1, 7, 4, 0, 12, 8, 5, 2, 11, 13, 255, 14, 10
1593 spin_lock_irq(&ice
->reg_lock
);
1594 if (is_spdif_master(ice
)) {
1595 ucontrol
->value
.enumerated
.item
[0] = ice
->vt1720
? 13 : 15;
1597 val
= xlate
[inb(ICEMT1724(ice
, RATE
)) & 15];
1602 ucontrol
->value
.enumerated
.item
[0] = val
;
1604 spin_unlock_irq(&ice
->reg_lock
);
1608 static int snd_vt1724_pro_internal_clock_put(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
1610 ice1712_t
*ice
= snd_kcontrol_chip(kcontrol
);
1614 int spdif
= ice
->vt1720
? 13 : 15;
1616 spin_lock_irq(&ice
->reg_lock
);
1617 oval
= inb(ICEMT1724(ice
, RATE
));
1618 if (ucontrol
->value
.enumerated
.item
[0] == spdif
) {
1619 outb(oval
| VT1724_SPDIF_MASTER
, ICEMT1724(ice
, RATE
));
1621 rate
= rates
[ucontrol
->value
.integer
.value
[0] % 15];
1622 if (rate
<= get_max_rate(ice
)) {
1623 PRO_RATE_DEFAULT
= rate
;
1624 spin_unlock_irq(&ice
->reg_lock
);
1625 snd_vt1724_set_pro_rate(ice
, PRO_RATE_DEFAULT
, 1);
1626 spin_lock_irq(&ice
->reg_lock
);
1629 change
= inb(ICEMT1724(ice
, RATE
)) != oval
;
1630 spin_unlock_irq(&ice
->reg_lock
);
1632 if ((oval
& VT1724_SPDIF_MASTER
) != (inb(ICEMT1724(ice
, RATE
)) & VT1724_SPDIF_MASTER
)) {
1633 /* notify akm chips as well */
1634 if (is_spdif_master(ice
)) {
1636 for (i
= 0; i
< ice
->akm_codecs
; i
++) {
1637 if (ice
->akm
[i
].ops
.set_rate_val
)
1638 ice
->akm
[i
].ops
.set_rate_val(&ice
->akm
[i
], 0);
1645 static snd_kcontrol_new_t snd_vt1724_pro_internal_clock __devinitdata
= {
1646 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1647 .name
= "Multi Track Internal Clock",
1648 .info
= snd_vt1724_pro_internal_clock_info
,
1649 .get
= snd_vt1724_pro_internal_clock_get
,
1650 .put
= snd_vt1724_pro_internal_clock_put
1653 static int snd_vt1724_pro_rate_locking_info(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
* uinfo
)
1655 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
1657 uinfo
->value
.integer
.min
= 0;
1658 uinfo
->value
.integer
.max
= 1;
1662 static int snd_vt1724_pro_rate_locking_get(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
1664 ucontrol
->value
.integer
.value
[0] = PRO_RATE_LOCKED
;
1668 static int snd_vt1724_pro_rate_locking_put(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
1670 ice1712_t
*ice
= snd_kcontrol_chip(kcontrol
);
1671 int change
= 0, nval
;
1673 nval
= ucontrol
->value
.integer
.value
[0] ? 1 : 0;
1674 spin_lock_irq(&ice
->reg_lock
);
1675 change
= PRO_RATE_LOCKED
!= nval
;
1676 PRO_RATE_LOCKED
= nval
;
1677 spin_unlock_irq(&ice
->reg_lock
);
1681 static snd_kcontrol_new_t snd_vt1724_pro_rate_locking __devinitdata
= {
1682 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1683 .name
= "Multi Track Rate Locking",
1684 .info
= snd_vt1724_pro_rate_locking_info
,
1685 .get
= snd_vt1724_pro_rate_locking_get
,
1686 .put
= snd_vt1724_pro_rate_locking_put
1689 static int snd_vt1724_pro_rate_reset_info(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
* uinfo
)
1691 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
1693 uinfo
->value
.integer
.min
= 0;
1694 uinfo
->value
.integer
.max
= 1;
1698 static int snd_vt1724_pro_rate_reset_get(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
1700 ucontrol
->value
.integer
.value
[0] = PRO_RATE_RESET
? 1 : 0;
1704 static int snd_vt1724_pro_rate_reset_put(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
1706 ice1712_t
*ice
= snd_kcontrol_chip(kcontrol
);
1707 int change
= 0, nval
;
1709 nval
= ucontrol
->value
.integer
.value
[0] ? 1 : 0;
1710 spin_lock_irq(&ice
->reg_lock
);
1711 change
= PRO_RATE_RESET
!= nval
;
1712 PRO_RATE_RESET
= nval
;
1713 spin_unlock_irq(&ice
->reg_lock
);
1717 static snd_kcontrol_new_t snd_vt1724_pro_rate_reset __devinitdata
= {
1718 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1719 .name
= "Multi Track Rate Reset",
1720 .info
= snd_vt1724_pro_rate_reset_info
,
1721 .get
= snd_vt1724_pro_rate_reset_get
,
1722 .put
= snd_vt1724_pro_rate_reset_put
1729 static int snd_vt1724_pro_route_info(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
* uinfo
)
1731 static char *texts
[] = {
1733 "H/W In 0", "H/W In 1", /* 1-2 */
1734 "IEC958 In L", "IEC958 In R", /* 3-4 */
1737 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
1739 uinfo
->value
.enumerated
.items
= 5;
1740 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
)
1741 uinfo
->value
.enumerated
.item
= uinfo
->value
.enumerated
.items
- 1;
1742 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
1746 static inline int analog_route_shift(int idx
)
1748 return (idx
% 2) * 12 + ((idx
/ 2) * 3) + 8;
1751 static inline int digital_route_shift(int idx
)
1756 static int get_route_val(ice1712_t
*ice
, int shift
)
1759 unsigned char eitem
;
1760 static unsigned char xlate
[8] = {
1761 0, 255, 1, 2, 255, 255, 3, 4,
1764 val
= inl(ICEMT1724(ice
, ROUTE_PLAYBACK
));
1766 val
&= 7; //we now have 3 bits per output
1775 static int put_route_val(ice1712_t
*ice
, unsigned int val
, int shift
)
1777 unsigned int old_val
, nval
;
1779 static unsigned char xroute
[8] = {
1781 2, /* PSDIN0 Left */
1782 3, /* PSDIN0 Right */
1784 7, /* SPDIN Right */
1787 nval
= xroute
[val
% 5];
1788 val
= old_val
= inl(ICEMT1724(ice
, ROUTE_PLAYBACK
));
1789 val
&= ~(0x07 << shift
);
1790 val
|= nval
<< shift
;
1791 change
= val
!= old_val
;
1793 outl(val
, ICEMT1724(ice
, ROUTE_PLAYBACK
));
1797 static int snd_vt1724_pro_route_analog_get(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
*ucontrol
)
1799 ice1712_t
*ice
= snd_kcontrol_chip(kcontrol
);
1800 int idx
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
1801 ucontrol
->value
.enumerated
.item
[0] = get_route_val(ice
, analog_route_shift(idx
));
1805 static int snd_vt1724_pro_route_analog_put(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
*ucontrol
)
1807 ice1712_t
*ice
= snd_kcontrol_chip(kcontrol
);
1808 int idx
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
1809 return put_route_val(ice
, ucontrol
->value
.enumerated
.item
[0],
1810 analog_route_shift(idx
));
1813 static int snd_vt1724_pro_route_spdif_get(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
*ucontrol
)
1815 ice1712_t
*ice
= snd_kcontrol_chip(kcontrol
);
1816 int idx
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
1817 ucontrol
->value
.enumerated
.item
[0] = get_route_val(ice
, digital_route_shift(idx
));
1821 static int snd_vt1724_pro_route_spdif_put(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
*ucontrol
)
1823 ice1712_t
*ice
= snd_kcontrol_chip(kcontrol
);
1824 int idx
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
1825 return put_route_val(ice
, ucontrol
->value
.enumerated
.item
[0],
1826 digital_route_shift(idx
));
1829 static snd_kcontrol_new_t snd_vt1724_mixer_pro_analog_route __devinitdata
= {
1830 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1831 .name
= "H/W Playback Route",
1832 .info
= snd_vt1724_pro_route_info
,
1833 .get
= snd_vt1724_pro_route_analog_get
,
1834 .put
= snd_vt1724_pro_route_analog_put
,
1837 static snd_kcontrol_new_t snd_vt1724_mixer_pro_spdif_route __devinitdata
= {
1838 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1839 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,NONE
) "Route",
1840 .info
= snd_vt1724_pro_route_info
,
1841 .get
= snd_vt1724_pro_route_spdif_get
,
1842 .put
= snd_vt1724_pro_route_spdif_put
,
1847 static int snd_vt1724_pro_peak_info(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
* uinfo
)
1849 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1850 uinfo
->count
= 22; /* FIXME: for compatibility with ice1712... */
1851 uinfo
->value
.integer
.min
= 0;
1852 uinfo
->value
.integer
.max
= 255;
1856 static int snd_vt1724_pro_peak_get(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
1858 ice1712_t
*ice
= snd_kcontrol_chip(kcontrol
);
1861 spin_lock_irq(&ice
->reg_lock
);
1862 for (idx
= 0; idx
< 22; idx
++) {
1863 outb(idx
, ICEMT1724(ice
, MONITOR_PEAKINDEX
));
1864 ucontrol
->value
.integer
.value
[idx
] = inb(ICEMT1724(ice
, MONITOR_PEAKDATA
));
1866 spin_unlock_irq(&ice
->reg_lock
);
1870 static snd_kcontrol_new_t snd_vt1724_mixer_pro_peak __devinitdata
= {
1871 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1872 .name
= "Multi Track Peak",
1873 .access
= SNDRV_CTL_ELEM_ACCESS_READ
| SNDRV_CTL_ELEM_ACCESS_VOLATILE
,
1874 .info
= snd_vt1724_pro_peak_info
,
1875 .get
= snd_vt1724_pro_peak_get
1882 static struct snd_ice1712_card_info no_matched __devinitdata
;
1884 static struct snd_ice1712_card_info
*card_tables
[] __devinitdata
= {
1885 snd_vt1724_revo_cards
,
1886 snd_vt1724_amp_cards
,
1887 snd_vt1724_aureon_cards
,
1888 snd_vt1720_mobo_cards
,
1889 snd_vt1720_pontis_cards
,
1890 snd_vt1724_prodigy192_cards
,
1891 snd_vt1724_juli_cards
,
1892 snd_vt1724_phase_cards
,
1900 static void wait_i2c_busy(ice1712_t
*ice
)
1903 while ((inb(ICEREG1724(ice
, I2C_CTRL
)) & VT1724_I2C_BUSY
) && t
--)
1906 printk(KERN_ERR
"ice1724: i2c busy timeout\n");
1909 unsigned char snd_vt1724_read_i2c(ice1712_t
*ice
, unsigned char dev
, unsigned char addr
)
1913 down(&ice
->i2c_mutex
);
1914 outb(addr
, ICEREG1724(ice
, I2C_BYTE_ADDR
));
1915 outb(dev
& ~VT1724_I2C_WRITE
, ICEREG1724(ice
, I2C_DEV_ADDR
));
1917 val
= inb(ICEREG1724(ice
, I2C_DATA
));
1918 up(&ice
->i2c_mutex
);
1919 //printk("i2c_read: [0x%x,0x%x] = 0x%x\n", dev, addr, val);
1923 void snd_vt1724_write_i2c(ice1712_t
*ice
, unsigned char dev
, unsigned char addr
, unsigned char data
)
1925 down(&ice
->i2c_mutex
);
1927 //printk("i2c_write: [0x%x,0x%x] = 0x%x\n", dev, addr, data);
1928 outb(addr
, ICEREG1724(ice
, I2C_BYTE_ADDR
));
1929 outb(data
, ICEREG1724(ice
, I2C_DATA
));
1930 outb(dev
| VT1724_I2C_WRITE
, ICEREG1724(ice
, I2C_DEV_ADDR
));
1932 up(&ice
->i2c_mutex
);
1935 static int __devinit
snd_vt1724_read_eeprom(ice1712_t
*ice
, const char *modelname
)
1937 const int dev
= 0xa0; /* EEPROM device address */
1938 unsigned int i
, size
;
1939 struct snd_ice1712_card_info
**tbl
, *c
;
1941 if (! modelname
|| ! *modelname
) {
1942 ice
->eeprom
.subvendor
= 0;
1943 if ((inb(ICEREG1724(ice
, I2C_CTRL
)) & VT1724_I2C_EEPROM
) != 0)
1944 ice
->eeprom
.subvendor
=
1945 (snd_vt1724_read_i2c(ice
, dev
, 0x00) << 0) |
1946 (snd_vt1724_read_i2c(ice
, dev
, 0x01) << 8) |
1947 (snd_vt1724_read_i2c(ice
, dev
, 0x02) << 16) |
1948 (snd_vt1724_read_i2c(ice
, dev
, 0x03) << 24);
1949 if (ice
->eeprom
.subvendor
== 0 || ice
->eeprom
.subvendor
== (unsigned int)-1) {
1950 /* invalid subvendor from EEPROM, try the PCI subststem ID instead */
1952 pci_read_config_word(ice
->pci
, PCI_SUBSYSTEM_VENDOR_ID
, &vendor
);
1953 pci_read_config_word(ice
->pci
, PCI_SUBSYSTEM_ID
, &device
);
1954 ice
->eeprom
.subvendor
= ((unsigned int)swab16(vendor
) << 16) | swab16(device
);
1955 if (ice
->eeprom
.subvendor
== 0 || ice
->eeprom
.subvendor
== (unsigned int)-1) {
1956 printk(KERN_ERR
"ice1724: No valid ID is found\n");
1961 for (tbl
= card_tables
; *tbl
; tbl
++) {
1962 for (c
= *tbl
; c
->subvendor
; c
++) {
1963 if (modelname
&& c
->model
&& ! strcmp(modelname
, c
->model
)) {
1964 printk(KERN_INFO
"ice1724: Using board model %s\n", c
->name
);
1965 ice
->eeprom
.subvendor
= c
->subvendor
;
1966 } else if (c
->subvendor
!= ice
->eeprom
.subvendor
)
1968 if (! c
->eeprom_size
|| ! c
->eeprom_data
)
1970 /* if the EEPROM is given by the driver, use it */
1971 snd_printdd("using the defined eeprom..\n");
1972 ice
->eeprom
.version
= 2;
1973 ice
->eeprom
.size
= c
->eeprom_size
+ 6;
1974 memcpy(ice
->eeprom
.data
, c
->eeprom_data
, c
->eeprom_size
);
1978 printk(KERN_WARNING
"ice1724: No matching model found for ID 0x%x\n", ice
->eeprom
.subvendor
);
1981 ice
->eeprom
.size
= snd_vt1724_read_i2c(ice
, dev
, 0x04);
1982 if (ice
->eeprom
.size
< 6)
1983 ice
->eeprom
.size
= 32;
1984 else if (ice
->eeprom
.size
> 32) {
1985 printk(KERN_ERR
"ice1724: Invalid EEPROM (size = %i)\n", ice
->eeprom
.size
);
1988 ice
->eeprom
.version
= snd_vt1724_read_i2c(ice
, dev
, 0x05);
1989 if (ice
->eeprom
.version
!= 2)
1990 printk(KERN_WARNING
"ice1724: Invalid EEPROM version %i\n", ice
->eeprom
.version
);
1991 size
= ice
->eeprom
.size
- 6;
1992 for (i
= 0; i
< size
; i
++)
1993 ice
->eeprom
.data
[i
] = snd_vt1724_read_i2c(ice
, dev
, i
+ 6);
1996 ice
->eeprom
.gpiomask
= eeprom_triple(ice
, ICE_EEP2_GPIO_MASK
);
1997 ice
->eeprom
.gpiostate
= eeprom_triple(ice
, ICE_EEP2_GPIO_STATE
);
1998 ice
->eeprom
.gpiodir
= eeprom_triple(ice
, ICE_EEP2_GPIO_DIR
);
2005 static int __devinit
snd_vt1724_chip_init(ice1712_t
*ice
)
2007 outb(VT1724_RESET
, ICEREG1724(ice
, CONTROL
));
2009 outb(0, ICEREG1724(ice
, CONTROL
));
2011 outb(ice
->eeprom
.data
[ICE_EEP2_SYSCONF
], ICEREG1724(ice
, SYS_CFG
));
2012 outb(ice
->eeprom
.data
[ICE_EEP2_ACLINK
], ICEREG1724(ice
, AC97_CFG
));
2013 outb(ice
->eeprom
.data
[ICE_EEP2_I2S
], ICEREG1724(ice
, I2S_FEATURES
));
2014 outb(ice
->eeprom
.data
[ICE_EEP2_SPDIF
], ICEREG1724(ice
, SPDIF_CFG
));
2016 ice
->gpio
.write_mask
= ice
->eeprom
.gpiomask
;
2017 ice
->gpio
.direction
= ice
->eeprom
.gpiodir
;
2018 snd_vt1724_set_gpio_mask(ice
, ice
->eeprom
.gpiomask
);
2019 snd_vt1724_set_gpio_dir(ice
, ice
->eeprom
.gpiodir
);
2020 snd_vt1724_set_gpio_data(ice
, ice
->eeprom
.gpiostate
);
2022 outb(0, ICEREG1724(ice
, POWERDOWN
));
2027 static int __devinit
snd_vt1724_spdif_build_controls(ice1712_t
*ice
)
2030 snd_kcontrol_t
*kctl
;
2032 snd_assert(ice
->pcm
!= NULL
, return -EIO
);
2034 err
= snd_ctl_add(ice
->card
, snd_ctl_new1(&snd_vt1724_mixer_pro_spdif_route
, ice
));
2038 err
= snd_ctl_add(ice
->card
, snd_ctl_new1(&snd_vt1724_spdif_switch
, ice
));
2042 err
= snd_ctl_add(ice
->card
, kctl
= snd_ctl_new1(&snd_vt1724_spdif_default
, ice
));
2045 kctl
->id
.device
= ice
->pcm
->device
;
2046 err
= snd_ctl_add(ice
->card
, kctl
= snd_ctl_new1(&snd_vt1724_spdif_maskc
, ice
));
2049 kctl
->id
.device
= ice
->pcm
->device
;
2050 err
= snd_ctl_add(ice
->card
, kctl
= snd_ctl_new1(&snd_vt1724_spdif_maskp
, ice
));
2053 kctl
->id
.device
= ice
->pcm
->device
;
2054 #if 0 /* use default only */
2055 err
= snd_ctl_add(ice
->card
, kctl
= snd_ctl_new1(&snd_vt1724_spdif_stream
, ice
));
2058 kctl
->id
.device
= ice
->pcm
->device
;
2059 ice
->spdif
.stream_ctl
= kctl
;
2065 static int __devinit
snd_vt1724_build_controls(ice1712_t
*ice
)
2069 err
= snd_ctl_add(ice
->card
, snd_ctl_new1(&snd_vt1724_eeprom
, ice
));
2072 err
= snd_ctl_add(ice
->card
, snd_ctl_new1(&snd_vt1724_pro_internal_clock
, ice
));
2076 err
= snd_ctl_add(ice
->card
, snd_ctl_new1(&snd_vt1724_pro_rate_locking
, ice
));
2079 err
= snd_ctl_add(ice
->card
, snd_ctl_new1(&snd_vt1724_pro_rate_reset
, ice
));
2083 if (ice
->num_total_dacs
> 0) {
2084 snd_kcontrol_new_t tmp
= snd_vt1724_mixer_pro_analog_route
;
2085 tmp
.count
= ice
->num_total_dacs
;
2086 if (ice
->vt1720
&& tmp
.count
> 2)
2088 err
= snd_ctl_add(ice
->card
, snd_ctl_new1(&tmp
, ice
));
2093 err
= snd_ctl_add(ice
->card
, snd_ctl_new1(&snd_vt1724_mixer_pro_peak
, ice
));
2100 static int snd_vt1724_free(ice1712_t
*ice
)
2104 /* mask all interrupts */
2105 outb(0xff, ICEMT1724(ice
, DMA_INT_MASK
));
2106 outb(0xff, ICEREG1724(ice
, IRQMASK
));
2109 if (ice
->irq
>= 0) {
2110 synchronize_irq(ice
->irq
);
2111 free_irq(ice
->irq
, (void *) ice
);
2113 pci_release_regions(ice
->pci
);
2114 snd_ice1712_akm4xxx_free(ice
);
2115 pci_disable_device(ice
->pci
);
2120 static int snd_vt1724_dev_free(snd_device_t
*device
)
2122 ice1712_t
*ice
= device
->device_data
;
2123 return snd_vt1724_free(ice
);
2126 static int __devinit
snd_vt1724_create(snd_card_t
* card
,
2127 struct pci_dev
*pci
,
2128 const char *modelname
,
2129 ice1712_t
** r_ice1712
)
2134 static snd_device_ops_t ops
= {
2135 .dev_free
= snd_vt1724_dev_free
,
2140 /* enable PCI device */
2141 if ((err
= pci_enable_device(pci
)) < 0)
2144 ice
= kzalloc(sizeof(*ice
), GFP_KERNEL
);
2146 pci_disable_device(pci
);
2150 spin_lock_init(&ice
->reg_lock
);
2151 init_MUTEX(&ice
->gpio_mutex
);
2152 init_MUTEX(&ice
->open_mutex
);
2153 init_MUTEX(&ice
->i2c_mutex
);
2154 ice
->gpio
.set_mask
= snd_vt1724_set_gpio_mask
;
2155 ice
->gpio
.set_dir
= snd_vt1724_set_gpio_dir
;
2156 ice
->gpio
.set_data
= snd_vt1724_set_gpio_data
;
2157 ice
->gpio
.get_data
= snd_vt1724_get_gpio_data
;
2161 pci_set_master(pci
);
2162 snd_vt1724_proc_init(ice
);
2163 synchronize_irq(pci
->irq
);
2165 if ((err
= pci_request_regions(pci
, "ICE1724")) < 0) {
2167 pci_disable_device(pci
);
2170 ice
->port
= pci_resource_start(pci
, 0);
2171 ice
->profi_port
= pci_resource_start(pci
, 1);
2173 if (request_irq(pci
->irq
, snd_vt1724_interrupt
, SA_INTERRUPT
|SA_SHIRQ
, "ICE1724", (void *) ice
)) {
2174 snd_printk(KERN_ERR
"unable to grab IRQ %d\n", pci
->irq
);
2175 snd_vt1724_free(ice
);
2179 ice
->irq
= pci
->irq
;
2181 if (snd_vt1724_read_eeprom(ice
, modelname
) < 0) {
2182 snd_vt1724_free(ice
);
2185 if (snd_vt1724_chip_init(ice
) < 0) {
2186 snd_vt1724_free(ice
);
2190 /* unmask used interrupts */
2191 if (! (ice
->eeprom
.data
[ICE_EEP2_SYSCONF
] & VT1724_CFG_MPU401
))
2192 mask
= VT1724_IRQ_MPU_RX
| VT1724_IRQ_MPU_TX
;
2195 outb(mask
, ICEREG1724(ice
, IRQMASK
));
2196 /* don't handle FIFO overrun/underruns (just yet), since they cause machine lockups */
2197 outb(VT1724_MULTI_FIFO_ERR
, ICEMT1724(ice
, DMA_INT_MASK
));
2199 if ((err
= snd_device_new(card
, SNDRV_DEV_LOWLEVEL
, ice
, &ops
)) < 0) {
2200 snd_vt1724_free(ice
);
2204 snd_card_set_dev(card
, &pci
->dev
);
2217 static int __devinit
snd_vt1724_probe(struct pci_dev
*pci
,
2218 const struct pci_device_id
*pci_id
)
2223 int pcm_dev
= 0, err
;
2224 struct snd_ice1712_card_info
**tbl
, *c
;
2226 if (dev
>= SNDRV_CARDS
)
2233 card
= snd_card_new(index
[dev
], id
[dev
], THIS_MODULE
, 0);
2237 strcpy(card
->driver
, "ICE1724");
2238 strcpy(card
->shortname
, "ICEnsemble ICE1724");
2240 if ((err
= snd_vt1724_create(card
, pci
, model
[dev
], &ice
)) < 0) {
2241 snd_card_free(card
);
2245 for (tbl
= card_tables
; *tbl
; tbl
++) {
2246 for (c
= *tbl
; c
->subvendor
; c
++) {
2247 if (c
->subvendor
== ice
->eeprom
.subvendor
) {
2248 strcpy(card
->shortname
, c
->name
);
2249 if (c
->driver
) /* specific driver? */
2250 strcpy(card
->driver
, c
->driver
);
2252 if ((err
= c
->chip_init(ice
)) < 0) {
2253 snd_card_free(card
);
2264 if ((err
= snd_vt1724_pcm_profi(ice
, pcm_dev
++)) < 0) {
2265 snd_card_free(card
);
2269 if ((err
= snd_vt1724_pcm_spdif(ice
, pcm_dev
++)) < 0) {
2270 snd_card_free(card
);
2274 if ((err
= snd_vt1724_pcm_indep(ice
, pcm_dev
++)) < 0) {
2275 snd_card_free(card
);
2279 if ((err
= snd_vt1724_ac97_mixer(ice
)) < 0) {
2280 snd_card_free(card
);
2284 if ((err
= snd_vt1724_build_controls(ice
)) < 0) {
2285 snd_card_free(card
);
2289 if (ice
->pcm
&& ice
->has_spdif
) { /* has SPDIF I/O */
2290 if ((err
= snd_vt1724_spdif_build_controls(ice
)) < 0) {
2291 snd_card_free(card
);
2296 if (c
->build_controls
) {
2297 if ((err
= c
->build_controls(ice
)) < 0) {
2298 snd_card_free(card
);
2303 if (! c
->no_mpu401
) {
2304 if (ice
->eeprom
.data
[ICE_EEP2_SYSCONF
] & VT1724_CFG_MPU401
) {
2305 if ((err
= snd_mpu401_uart_new(card
, 0, MPU401_HW_ICE1712
,
2306 ICEREG1724(ice
, MPU_CTRL
), 1,
2308 &ice
->rmidi
[0])) < 0) {
2309 snd_card_free(card
);
2315 sprintf(card
->longname
, "%s at 0x%lx, irq %i",
2316 card
->shortname
, ice
->port
, ice
->irq
);
2318 if ((err
= snd_card_register(card
)) < 0) {
2319 snd_card_free(card
);
2322 pci_set_drvdata(pci
, card
);
2327 static void __devexit
snd_vt1724_remove(struct pci_dev
*pci
)
2329 snd_card_free(pci_get_drvdata(pci
));
2330 pci_set_drvdata(pci
, NULL
);
2333 static struct pci_driver driver
= {
2335 .id_table
= snd_vt1724_ids
,
2336 .probe
= snd_vt1724_probe
,
2337 .remove
= __devexit_p(snd_vt1724_remove
),
2340 static int __init
alsa_card_ice1724_init(void)
2342 return pci_register_driver(&driver
);
2345 static void __exit
alsa_card_ice1724_exit(void)
2347 pci_unregister_driver(&driver
);
2350 module_init(alsa_card_ice1724_init
)
2351 module_exit(alsa_card_ice1724_exit
)