2 * Maintained by Jaroslav Kysela <perex@suse.cz>
3 * Originated by audio@tridentmicro.com
4 * Fri Feb 19 15:55:28 MST 1999
5 * Routines for control of Trident 4DWave (DX and NX) chip
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 * SiS7018 S/PDIF support by Thomas Winischhofer <thomas@winischhofer.net>
30 #include <sound/driver.h>
31 #include <linux/delay.h>
32 #include <linux/init.h>
33 #include <linux/interrupt.h>
34 #include <linux/pci.h>
35 #include <linux/slab.h>
36 #include <linux/vmalloc.h>
37 #include <linux/gameport.h>
39 #include <sound/core.h>
40 #include <sound/info.h>
41 #include <sound/control.h>
42 #include <sound/trident.h>
43 #include <sound/asoundef.h>
47 static int snd_trident_pcm_mixer_build(trident_t
*trident
, snd_trident_voice_t
* voice
, snd_pcm_substream_t
*substream
);
48 static int snd_trident_pcm_mixer_free(trident_t
*trident
, snd_trident_voice_t
* voice
, snd_pcm_substream_t
*substream
);
49 static irqreturn_t
snd_trident_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
);
51 static int snd_trident_suspend(snd_card_t
*card
, pm_message_t state
);
52 static int snd_trident_resume(snd_card_t
*card
);
54 static int snd_trident_sis_reset(trident_t
*trident
);
56 static void snd_trident_clear_voices(trident_t
* trident
, unsigned short v_min
, unsigned short v_max
);
57 static int snd_trident_free(trident_t
*trident
);
65 static void snd_trident_print_voice_regs(trident_t
*trident
, int voice
)
67 unsigned int val
, tmp
;
69 printk("Trident voice %i:\n", voice
);
70 outb(voice
, TRID_REG(trident
, T4D_LFO_GC_CIR
));
71 val
= inl(TRID_REG(trident
, CH_LBA
));
72 printk("LBA: 0x%x\n", val
);
73 val
= inl(TRID_REG(trident
, CH_GVSEL_PAN_VOL_CTRL_EC
));
74 printk("GVSel: %i\n", val
>> 31);
75 printk("Pan: 0x%x\n", (val
>> 24) & 0x7f);
76 printk("Vol: 0x%x\n", (val
>> 16) & 0xff);
77 printk("CTRL: 0x%x\n", (val
>> 12) & 0x0f);
78 printk("EC: 0x%x\n", val
& 0x0fff);
79 if (trident
->device
!= TRIDENT_DEVICE_ID_NX
) {
80 val
= inl(TRID_REG(trident
, CH_DX_CSO_ALPHA_FMS
));
81 printk("CSO: 0x%x\n", val
>> 16);
82 printk("Alpha: 0x%x\n", (val
>> 4) & 0x0fff);
83 printk("FMS: 0x%x\n", val
& 0x0f);
84 val
= inl(TRID_REG(trident
, CH_DX_ESO_DELTA
));
85 printk("ESO: 0x%x\n", val
>> 16);
86 printk("Delta: 0x%x\n", val
& 0xffff);
87 val
= inl(TRID_REG(trident
, CH_DX_FMC_RVOL_CVOL
));
88 } else { // TRIDENT_DEVICE_ID_NX
89 val
= inl(TRID_REG(trident
, CH_NX_DELTA_CSO
));
90 tmp
= (val
>> 24) & 0xff;
91 printk("CSO: 0x%x\n", val
& 0x00ffffff);
92 val
= inl(TRID_REG(trident
, CH_NX_DELTA_ESO
));
93 tmp
|= (val
>> 16) & 0xff00;
94 printk("Delta: 0x%x\n", tmp
);
95 printk("ESO: 0x%x\n", val
& 0x00ffffff);
96 val
= inl(TRID_REG(trident
, CH_NX_ALPHA_FMS_FMC_RVOL_CVOL
));
97 printk("Alpha: 0x%x\n", val
>> 20);
98 printk("FMS: 0x%x\n", (val
>> 16) & 0x0f);
100 printk("FMC: 0x%x\n", (val
>> 14) & 3);
101 printk("RVol: 0x%x\n", (val
>> 7) & 0x7f);
102 printk("CVol: 0x%x\n", val
& 0x7f);
106 /*---------------------------------------------------------------------------
107 unsigned short snd_trident_codec_read(ac97_t *ac97, unsigned short reg)
109 Description: This routine will do all of the reading from the external
112 Parameters: ac97 - ac97 codec structure
113 reg - CODEC register index, from AC97 Hal.
115 returns: 16 bit value read from the AC97.
117 ---------------------------------------------------------------------------*/
118 static unsigned short snd_trident_codec_read(ac97_t
*ac97
, unsigned short reg
)
120 unsigned int data
= 0, treg
;
121 unsigned short count
= 0xffff;
123 trident_t
*trident
= ac97
->private_data
;
125 spin_lock_irqsave(&trident
->reg_lock
, flags
);
126 if (trident
->device
== TRIDENT_DEVICE_ID_DX
) {
127 data
= (DX_AC97_BUSY_READ
| (reg
& 0x000000ff));
128 outl(data
, TRID_REG(trident
, DX_ACR1_AC97_R
));
130 data
= inl(TRID_REG(trident
, DX_ACR1_AC97_R
));
131 if ((data
& DX_AC97_BUSY_READ
) == 0)
134 } else if (trident
->device
== TRIDENT_DEVICE_ID_NX
) {
135 data
= (NX_AC97_BUSY_READ
| (reg
& 0x000000ff));
136 treg
= ac97
->num
== 0 ? NX_ACR2_AC97_R_PRIMARY
: NX_ACR3_AC97_R_SECONDARY
;
137 outl(data
, TRID_REG(trident
, treg
));
139 data
= inl(TRID_REG(trident
, treg
));
140 if ((data
& 0x00000C00) == 0)
143 } else if (trident
->device
== TRIDENT_DEVICE_ID_SI7018
) {
144 data
= SI_AC97_BUSY_READ
| SI_AC97_AUDIO_BUSY
| (reg
& 0x000000ff);
146 data
|= SI_AC97_SECONDARY
;
147 outl(data
, TRID_REG(trident
, SI_AC97_READ
));
149 data
= inl(TRID_REG(trident
, SI_AC97_READ
));
150 if ((data
& (SI_AC97_BUSY_READ
)) == 0)
155 if (count
== 0 && !trident
->ac97_detect
) {
156 snd_printk("ac97 codec read TIMEOUT [0x%x/0x%x]!!!\n", reg
, data
);
160 spin_unlock_irqrestore(&trident
->reg_lock
, flags
);
161 return ((unsigned short) (data
>> 16));
164 /*---------------------------------------------------------------------------
165 void snd_trident_codec_write(ac97_t *ac97, unsigned short reg, unsigned short wdata)
167 Description: This routine will do all of the writing to the external
170 Parameters: ac97 - ac97 codec structure
171 reg - CODEC register index, from AC97 Hal.
172 data - Lower 16 bits are the data to write to CODEC.
174 returns: TRUE if everything went ok, else FALSE.
176 ---------------------------------------------------------------------------*/
177 static void snd_trident_codec_write(ac97_t
*ac97
, unsigned short reg
, unsigned short wdata
)
179 unsigned int address
, data
;
180 unsigned short count
= 0xffff;
182 trident_t
*trident
= ac97
->private_data
;
184 data
= ((unsigned long) wdata
) << 16;
186 spin_lock_irqsave(&trident
->reg_lock
, flags
);
187 if (trident
->device
== TRIDENT_DEVICE_ID_DX
) {
188 address
= DX_ACR0_AC97_W
;
190 /* read AC-97 write register status */
192 if ((inw(TRID_REG(trident
, address
)) & DX_AC97_BUSY_WRITE
) == 0)
196 data
|= (DX_AC97_BUSY_WRITE
| (reg
& 0x000000ff));
197 } else if (trident
->device
== TRIDENT_DEVICE_ID_NX
) {
198 address
= NX_ACR1_AC97_W
;
200 /* read AC-97 write register status */
202 if ((inw(TRID_REG(trident
, address
)) & NX_AC97_BUSY_WRITE
) == 0)
206 data
|= (NX_AC97_BUSY_WRITE
| (ac97
->num
<< 8) | (reg
& 0x000000ff));
207 } else if (trident
->device
== TRIDENT_DEVICE_ID_SI7018
) {
208 address
= SI_AC97_WRITE
;
210 /* read AC-97 write register status */
212 if ((inw(TRID_REG(trident
, address
)) & (SI_AC97_BUSY_WRITE
)) == 0)
216 data
|= SI_AC97_BUSY_WRITE
| SI_AC97_AUDIO_BUSY
| (reg
& 0x000000ff);
218 data
|= SI_AC97_SECONDARY
;
220 address
= 0; /* keep GCC happy */
221 count
= 0; /* return */
225 spin_unlock_irqrestore(&trident
->reg_lock
, flags
);
228 outl(data
, TRID_REG(trident
, address
));
229 spin_unlock_irqrestore(&trident
->reg_lock
, flags
);
232 /*---------------------------------------------------------------------------
233 void snd_trident_enable_eso(trident_t *trident)
235 Description: This routine will enable end of loop interrupts.
236 End of loop interrupts will occur when a running
238 Also enables middle of loop interrupts.
240 Parameters: trident - pointer to target device class for 4DWave.
242 ---------------------------------------------------------------------------*/
244 static void snd_trident_enable_eso(trident_t
* trident
)
248 val
= inl(TRID_REG(trident
, T4D_LFO_GC_CIR
));
251 if (trident
->device
== TRIDENT_DEVICE_ID_SI7018
)
253 outl(val
, TRID_REG(trident
, T4D_LFO_GC_CIR
));
256 /*---------------------------------------------------------------------------
257 void snd_trident_disable_eso(trident_t *trident)
259 Description: This routine will disable end of loop interrupts.
260 End of loop interrupts will occur when a running
262 Also disables middle of loop interrupts.
265 trident - pointer to target device class for 4DWave.
267 returns: TRUE if everything went ok, else FALSE.
269 ---------------------------------------------------------------------------*/
271 static void snd_trident_disable_eso(trident_t
* trident
)
275 tmp
= inl(TRID_REG(trident
, T4D_LFO_GC_CIR
));
278 outl(tmp
, TRID_REG(trident
, T4D_LFO_GC_CIR
));
281 /*---------------------------------------------------------------------------
282 void snd_trident_start_voice(trident_t * trident, unsigned int voice)
284 Description: Start a voice, any channel 0 thru 63.
285 This routine automatically handles the fact that there are
286 more than 32 channels available.
288 Parameters : voice - Voice number 0 thru n.
289 trident - pointer to target device class for 4DWave.
293 ---------------------------------------------------------------------------*/
295 void snd_trident_start_voice(trident_t
* trident
, unsigned int voice
)
297 unsigned int mask
= 1 << (voice
& 0x1f);
298 unsigned int reg
= (voice
& 0x20) ? T4D_START_B
: T4D_START_A
;
300 outl(mask
, TRID_REG(trident
, reg
));
303 /*---------------------------------------------------------------------------
304 void snd_trident_stop_voice(trident_t * trident, unsigned int voice)
306 Description: Stop a voice, any channel 0 thru 63.
307 This routine automatically handles the fact that there are
308 more than 32 channels available.
310 Parameters : voice - Voice number 0 thru n.
311 trident - pointer to target device class for 4DWave.
315 ---------------------------------------------------------------------------*/
317 void snd_trident_stop_voice(trident_t
* trident
, unsigned int voice
)
319 unsigned int mask
= 1 << (voice
& 0x1f);
320 unsigned int reg
= (voice
& 0x20) ? T4D_STOP_B
: T4D_STOP_A
;
322 outl(mask
, TRID_REG(trident
, reg
));
325 /*---------------------------------------------------------------------------
326 int snd_trident_allocate_pcm_channel(trident_t *trident)
328 Description: Allocate hardware channel in Bank B (32-63).
330 Parameters : trident - pointer to target device class for 4DWave.
332 Return Value: hardware channel - 32-63 or -1 when no channel is available
334 ---------------------------------------------------------------------------*/
336 static int snd_trident_allocate_pcm_channel(trident_t
* trident
)
340 if (trident
->ChanPCMcnt
>= trident
->ChanPCM
)
342 for (idx
= 31; idx
>= 0; idx
--) {
343 if (!(trident
->ChanMap
[T4D_BANK_B
] & (1 << idx
))) {
344 trident
->ChanMap
[T4D_BANK_B
] |= 1 << idx
;
345 trident
->ChanPCMcnt
++;
352 /*---------------------------------------------------------------------------
353 void snd_trident_free_pcm_channel(int channel)
355 Description: Free hardware channel in Bank B (32-63)
357 Parameters : trident - pointer to target device class for 4DWave.
358 channel - hardware channel number 0-63
362 ---------------------------------------------------------------------------*/
364 static void snd_trident_free_pcm_channel(trident_t
*trident
, int channel
)
366 if (channel
< 32 || channel
> 63)
369 if (trident
->ChanMap
[T4D_BANK_B
] & (1 << channel
)) {
370 trident
->ChanMap
[T4D_BANK_B
] &= ~(1 << channel
);
371 trident
->ChanPCMcnt
--;
375 /*---------------------------------------------------------------------------
376 unsigned int snd_trident_allocate_synth_channel(void)
378 Description: Allocate hardware channel in Bank A (0-31).
380 Parameters : trident - pointer to target device class for 4DWave.
382 Return Value: hardware channel - 0-31 or -1 when no channel is available
384 ---------------------------------------------------------------------------*/
386 static int snd_trident_allocate_synth_channel(trident_t
* trident
)
390 for (idx
= 31; idx
>= 0; idx
--) {
391 if (!(trident
->ChanMap
[T4D_BANK_A
] & (1 << idx
))) {
392 trident
->ChanMap
[T4D_BANK_A
] |= 1 << idx
;
393 trident
->synth
.ChanSynthCount
++;
400 /*---------------------------------------------------------------------------
401 void snd_trident_free_synth_channel( int channel )
403 Description: Free hardware channel in Bank B (0-31).
405 Parameters : trident - pointer to target device class for 4DWave.
406 channel - hardware channel number 0-63
410 ---------------------------------------------------------------------------*/
412 static void snd_trident_free_synth_channel(trident_t
*trident
, int channel
)
414 if (channel
< 0 || channel
> 31)
417 if (trident
->ChanMap
[T4D_BANK_A
] & (1 << channel
)) {
418 trident
->ChanMap
[T4D_BANK_A
] &= ~(1 << channel
);
419 trident
->synth
.ChanSynthCount
--;
423 /*---------------------------------------------------------------------------
424 snd_trident_write_voice_regs
426 Description: This routine will complete and write the 5 hardware channel
427 registers to hardware.
429 Paramters: trident - pointer to target device class for 4DWave.
430 voice - synthesizer voice structure
433 ---------------------------------------------------------------------------*/
435 void snd_trident_write_voice_regs(trident_t
* trident
,
436 snd_trident_voice_t
* voice
)
438 unsigned int FmcRvolCvol
;
439 unsigned int regs
[5];
441 regs
[1] = voice
->LBA
;
442 regs
[4] = (voice
->GVSel
<< 31) |
443 ((voice
->Pan
& 0x0000007f) << 24) |
444 ((voice
->CTRL
& 0x0000000f) << 12);
445 FmcRvolCvol
= ((voice
->FMC
& 3) << 14) |
446 ((voice
->RVol
& 0x7f) << 7) |
447 (voice
->CVol
& 0x7f);
449 switch (trident
->device
) {
450 case TRIDENT_DEVICE_ID_SI7018
:
451 regs
[4] |= voice
->number
> 31 ?
452 (voice
->Vol
& 0x000003ff) :
453 ((voice
->Vol
& 0x00003fc) << (16-2)) |
454 (voice
->EC
& 0x00000fff);
455 regs
[0] = (voice
->CSO
<< 16) | ((voice
->Alpha
& 0x00000fff) << 4) | (voice
->FMS
& 0x0000000f);
456 regs
[2] = (voice
->ESO
<< 16) | (voice
->Delta
& 0x0ffff);
457 regs
[3] = (voice
->Attribute
<< 16) | FmcRvolCvol
;
459 case TRIDENT_DEVICE_ID_DX
:
460 regs
[4] |= ((voice
->Vol
& 0x000003fc) << (16-2)) |
461 (voice
->EC
& 0x00000fff);
462 regs
[0] = (voice
->CSO
<< 16) | ((voice
->Alpha
& 0x00000fff) << 4) | (voice
->FMS
& 0x0000000f);
463 regs
[2] = (voice
->ESO
<< 16) | (voice
->Delta
& 0x0ffff);
464 regs
[3] = FmcRvolCvol
;
466 case TRIDENT_DEVICE_ID_NX
:
467 regs
[4] |= ((voice
->Vol
& 0x000003fc) << (16-2)) |
468 (voice
->EC
& 0x00000fff);
469 regs
[0] = (voice
->Delta
<< 24) | (voice
->CSO
& 0x00ffffff);
470 regs
[2] = ((voice
->Delta
<< 16) & 0xff000000) | (voice
->ESO
& 0x00ffffff);
471 regs
[3] = (voice
->Alpha
<< 20) | ((voice
->FMS
& 0x0000000f) << 16) | FmcRvolCvol
;
477 outb(voice
->number
, TRID_REG(trident
, T4D_LFO_GC_CIR
));
478 outl(regs
[0], TRID_REG(trident
, CH_START
+ 0));
479 outl(regs
[1], TRID_REG(trident
, CH_START
+ 4));
480 outl(regs
[2], TRID_REG(trident
, CH_START
+ 8));
481 outl(regs
[3], TRID_REG(trident
, CH_START
+ 12));
482 outl(regs
[4], TRID_REG(trident
, CH_START
+ 16));
485 printk("written %i channel:\n", voice
->number
);
486 printk(" regs[0] = 0x%x/0x%x\n", regs
[0], inl(TRID_REG(trident
, CH_START
+ 0)));
487 printk(" regs[1] = 0x%x/0x%x\n", regs
[1], inl(TRID_REG(trident
, CH_START
+ 4)));
488 printk(" regs[2] = 0x%x/0x%x\n", regs
[2], inl(TRID_REG(trident
, CH_START
+ 8)));
489 printk(" regs[3] = 0x%x/0x%x\n", regs
[3], inl(TRID_REG(trident
, CH_START
+ 12)));
490 printk(" regs[4] = 0x%x/0x%x\n", regs
[4], inl(TRID_REG(trident
, CH_START
+ 16)));
494 /*---------------------------------------------------------------------------
495 snd_trident_write_cso_reg
497 Description: This routine will write the new CSO offset
498 register to hardware.
500 Paramters: trident - pointer to target device class for 4DWave.
501 voice - synthesizer voice structure
504 ---------------------------------------------------------------------------*/
506 static void snd_trident_write_cso_reg(trident_t
* trident
, snd_trident_voice_t
* voice
, unsigned int CSO
)
509 outb(voice
->number
, TRID_REG(trident
, T4D_LFO_GC_CIR
));
510 if (trident
->device
!= TRIDENT_DEVICE_ID_NX
) {
511 outw(voice
->CSO
, TRID_REG(trident
, CH_DX_CSO_ALPHA_FMS
) + 2);
513 outl((voice
->Delta
<< 24) | (voice
->CSO
& 0x00ffffff), TRID_REG(trident
, CH_NX_DELTA_CSO
));
517 /*---------------------------------------------------------------------------
518 snd_trident_write_eso_reg
520 Description: This routine will write the new ESO offset
521 register to hardware.
523 Paramters: trident - pointer to target device class for 4DWave.
524 voice - synthesizer voice structure
527 ---------------------------------------------------------------------------*/
529 static void snd_trident_write_eso_reg(trident_t
* trident
, snd_trident_voice_t
* voice
, unsigned int ESO
)
532 outb(voice
->number
, TRID_REG(trident
, T4D_LFO_GC_CIR
));
533 if (trident
->device
!= TRIDENT_DEVICE_ID_NX
) {
534 outw(voice
->ESO
, TRID_REG(trident
, CH_DX_ESO_DELTA
) + 2);
536 outl(((voice
->Delta
<< 16) & 0xff000000) | (voice
->ESO
& 0x00ffffff), TRID_REG(trident
, CH_NX_DELTA_ESO
));
540 /*---------------------------------------------------------------------------
541 snd_trident_write_vol_reg
543 Description: This routine will write the new voice volume
544 register to hardware.
546 Paramters: trident - pointer to target device class for 4DWave.
547 voice - synthesizer voice structure
548 Vol - new voice volume
550 ---------------------------------------------------------------------------*/
552 static void snd_trident_write_vol_reg(trident_t
* trident
, snd_trident_voice_t
* voice
, unsigned int Vol
)
555 outb(voice
->number
, TRID_REG(trident
, T4D_LFO_GC_CIR
));
556 switch (trident
->device
) {
557 case TRIDENT_DEVICE_ID_DX
:
558 case TRIDENT_DEVICE_ID_NX
:
559 outb(voice
->Vol
>> 2, TRID_REG(trident
, CH_GVSEL_PAN_VOL_CTRL_EC
+ 2));
561 case TRIDENT_DEVICE_ID_SI7018
:
562 // printk("voice->Vol = 0x%x\n", voice->Vol);
563 outw((voice
->CTRL
<< 12) | voice
->Vol
, TRID_REG(trident
, CH_GVSEL_PAN_VOL_CTRL_EC
));
568 /*---------------------------------------------------------------------------
569 snd_trident_write_pan_reg
571 Description: This routine will write the new voice pan
572 register to hardware.
574 Paramters: trident - pointer to target device class for 4DWave.
575 voice - synthesizer voice structure
578 ---------------------------------------------------------------------------*/
580 static void snd_trident_write_pan_reg(trident_t
* trident
, snd_trident_voice_t
* voice
, unsigned int Pan
)
583 outb(voice
->number
, TRID_REG(trident
, T4D_LFO_GC_CIR
));
584 outb(((voice
->GVSel
& 0x01) << 7) | (voice
->Pan
& 0x7f), TRID_REG(trident
, CH_GVSEL_PAN_VOL_CTRL_EC
+ 3));
587 /*---------------------------------------------------------------------------
588 snd_trident_write_rvol_reg
590 Description: This routine will write the new reverb volume
591 register to hardware.
593 Paramters: trident - pointer to target device class for 4DWave.
594 voice - synthesizer voice structure
595 RVol - new reverb volume
597 ---------------------------------------------------------------------------*/
599 static void snd_trident_write_rvol_reg(trident_t
* trident
, snd_trident_voice_t
* voice
, unsigned int RVol
)
602 outb(voice
->number
, TRID_REG(trident
, T4D_LFO_GC_CIR
));
603 outw(((voice
->FMC
& 0x0003) << 14) | ((voice
->RVol
& 0x007f) << 7) | (voice
->CVol
& 0x007f),
604 TRID_REG(trident
, trident
->device
== TRIDENT_DEVICE_ID_NX
? CH_NX_ALPHA_FMS_FMC_RVOL_CVOL
: CH_DX_FMC_RVOL_CVOL
));
607 /*---------------------------------------------------------------------------
608 snd_trident_write_cvol_reg
610 Description: This routine will write the new chorus volume
611 register to hardware.
613 Paramters: trident - pointer to target device class for 4DWave.
614 voice - synthesizer voice structure
615 CVol - new chorus volume
617 ---------------------------------------------------------------------------*/
619 static void snd_trident_write_cvol_reg(trident_t
* trident
, snd_trident_voice_t
* voice
, unsigned int CVol
)
622 outb(voice
->number
, TRID_REG(trident
, T4D_LFO_GC_CIR
));
623 outw(((voice
->FMC
& 0x0003) << 14) | ((voice
->RVol
& 0x007f) << 7) | (voice
->CVol
& 0x007f),
624 TRID_REG(trident
, trident
->device
== TRIDENT_DEVICE_ID_NX
? CH_NX_ALPHA_FMS_FMC_RVOL_CVOL
: CH_DX_FMC_RVOL_CVOL
));
627 /*---------------------------------------------------------------------------
628 snd_trident_convert_rate
630 Description: This routine converts rate in HZ to hardware delta value.
632 Paramters: trident - pointer to target device class for 4DWave.
633 rate - Real or Virtual channel number.
635 Returns: Delta value.
637 ---------------------------------------------------------------------------*/
638 static unsigned int snd_trident_convert_rate(unsigned int rate
)
642 // We special case 44100 and 8000 since rounding with the equation
643 // does not give us an accurate enough value. For 11025 and 22050
644 // the equation gives us the best answer. All other frequencies will
645 // also use the equation. JDW
648 else if (rate
== 8000)
650 else if (rate
== 48000)
653 delta
= (((rate
<< 12) + 24000) / 48000) & 0x0000ffff;
657 /*---------------------------------------------------------------------------
658 snd_trident_convert_adc_rate
660 Description: This routine converts rate in HZ to hardware delta value.
662 Paramters: trident - pointer to target device class for 4DWave.
663 rate - Real or Virtual channel number.
665 Returns: Delta value.
667 ---------------------------------------------------------------------------*/
668 static unsigned int snd_trident_convert_adc_rate(unsigned int rate
)
672 // We special case 44100 and 8000 since rounding with the equation
673 // does not give us an accurate enough value. For 11025 and 22050
674 // the equation gives us the best answer. All other frequencies will
675 // also use the equation. JDW
678 else if (rate
== 8000)
680 else if (rate
== 48000)
683 delta
= ((48000 << 12) / rate
) & 0x0000ffff;
687 /*---------------------------------------------------------------------------
688 snd_trident_spurious_threshold
690 Description: This routine converts rate in HZ to spurious threshold.
692 Paramters: trident - pointer to target device class for 4DWave.
693 rate - Real or Virtual channel number.
695 Returns: Delta value.
697 ---------------------------------------------------------------------------*/
698 static unsigned int snd_trident_spurious_threshold(unsigned int rate
, unsigned int period_size
)
700 unsigned int res
= (rate
* period_size
) / 48000;
708 /*---------------------------------------------------------------------------
709 snd_trident_control_mode
711 Description: This routine returns a control mode for a PCM channel.
713 Paramters: trident - pointer to target device class for 4DWave.
714 substream - PCM substream
716 Returns: Control value.
718 ---------------------------------------------------------------------------*/
719 static unsigned int snd_trident_control_mode(snd_pcm_substream_t
*substream
)
722 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
725 CTRL default: 8-bit (unsigned) mono, loop mode enabled
728 if (snd_pcm_format_width(runtime
->format
) == 16)
729 CTRL
|= 0x00000008; // 16-bit data
730 if (snd_pcm_format_signed(runtime
->format
))
731 CTRL
|= 0x00000002; // signed data
732 if (runtime
->channels
> 1)
733 CTRL
|= 0x00000004; // stereo data
741 /*---------------------------------------------------------------------------
744 Description: Device I/O control handler for playback/capture parameters.
746 Paramters: substream - PCM substream class
747 cmd - what ioctl message to process
748 arg - additional message infoarg
750 Returns: Error status
752 ---------------------------------------------------------------------------*/
754 static int snd_trident_ioctl(snd_pcm_substream_t
* substream
,
758 /* FIXME: it seems that with small periods the behaviour of
759 trident hardware is unpredictable and interrupt generator
761 return snd_pcm_lib_ioctl(substream
, cmd
, arg
);
764 /*---------------------------------------------------------------------------
765 snd_trident_allocate_pcm_mem
767 Description: Allocate PCM ring buffer for given substream
769 Parameters: substream - PCM substream class
770 hw_params - hardware parameters
772 Returns: Error status
774 ---------------------------------------------------------------------------*/
776 static int snd_trident_allocate_pcm_mem(snd_pcm_substream_t
* substream
,
777 snd_pcm_hw_params_t
* hw_params
)
779 trident_t
*trident
= snd_pcm_substream_chip(substream
);
780 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
781 snd_trident_voice_t
*voice
= (snd_trident_voice_t
*) runtime
->private_data
;
784 if ((err
= snd_pcm_lib_malloc_pages(substream
, params_buffer_bytes(hw_params
))) < 0)
786 if (trident
->tlb
.entries
) {
787 if (err
> 0) { /* change */
789 snd_trident_free_pages(trident
, voice
->memblk
);
790 voice
->memblk
= snd_trident_alloc_pages(trident
, substream
);
791 if (voice
->memblk
== NULL
)
798 /*---------------------------------------------------------------------------
799 snd_trident_allocate_evoice
801 Description: Allocate extra voice as interrupt generator
803 Parameters: substream - PCM substream class
804 hw_params - hardware parameters
806 Returns: Error status
808 ---------------------------------------------------------------------------*/
810 static int snd_trident_allocate_evoice(snd_pcm_substream_t
* substream
,
811 snd_pcm_hw_params_t
* hw_params
)
813 trident_t
*trident
= snd_pcm_substream_chip(substream
);
814 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
815 snd_trident_voice_t
*voice
= (snd_trident_voice_t
*) runtime
->private_data
;
816 snd_trident_voice_t
*evoice
= voice
->extra
;
818 /* voice management */
820 if (params_buffer_size(hw_params
) / 2 != params_period_size(hw_params
)) {
821 if (evoice
== NULL
) {
822 evoice
= snd_trident_alloc_voice(trident
, SNDRV_TRIDENT_VOICE_TYPE_PCM
, 0, 0);
825 voice
->extra
= evoice
;
826 evoice
->substream
= substream
;
829 if (evoice
!= NULL
) {
830 snd_trident_free_voice(trident
, evoice
);
831 voice
->extra
= evoice
= NULL
;
838 /*---------------------------------------------------------------------------
839 snd_trident_hw_params
841 Description: Set the hardware parameters for the playback device.
843 Parameters: substream - PCM substream class
844 hw_params - hardware parameters
846 Returns: Error status
848 ---------------------------------------------------------------------------*/
850 static int snd_trident_hw_params(snd_pcm_substream_t
* substream
,
851 snd_pcm_hw_params_t
* hw_params
)
855 err
= snd_trident_allocate_pcm_mem(substream
, hw_params
);
857 err
= snd_trident_allocate_evoice(substream
, hw_params
);
861 /*---------------------------------------------------------------------------
862 snd_trident_playback_hw_free
864 Description: Release the hardware resources for the playback device.
866 Parameters: substream - PCM substream class
868 Returns: Error status
870 ---------------------------------------------------------------------------*/
872 static int snd_trident_hw_free(snd_pcm_substream_t
* substream
)
874 trident_t
*trident
= snd_pcm_substream_chip(substream
);
875 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
876 snd_trident_voice_t
*voice
= (snd_trident_voice_t
*) runtime
->private_data
;
877 snd_trident_voice_t
*evoice
= voice
? voice
->extra
: NULL
;
879 if (trident
->tlb
.entries
) {
880 if (voice
&& voice
->memblk
) {
881 snd_trident_free_pages(trident
, voice
->memblk
);
882 voice
->memblk
= NULL
;
885 snd_pcm_lib_free_pages(substream
);
886 if (evoice
!= NULL
) {
887 snd_trident_free_voice(trident
, evoice
);
893 /*---------------------------------------------------------------------------
894 snd_trident_playback_prepare
896 Description: Prepare playback device for playback.
898 Parameters: substream - PCM substream class
900 Returns: Error status
902 ---------------------------------------------------------------------------*/
904 static int snd_trident_playback_prepare(snd_pcm_substream_t
* substream
)
906 trident_t
*trident
= snd_pcm_substream_chip(substream
);
907 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
908 snd_trident_voice_t
*voice
= (snd_trident_voice_t
*) runtime
->private_data
;
909 snd_trident_voice_t
*evoice
= voice
->extra
;
910 snd_trident_pcm_mixer_t
*mix
= &trident
->pcm_mixer
[substream
->number
];
912 spin_lock_irq(&trident
->reg_lock
);
914 /* set delta (rate) value */
915 voice
->Delta
= snd_trident_convert_rate(runtime
->rate
);
916 voice
->spurious_threshold
= snd_trident_spurious_threshold(runtime
->rate
, runtime
->period_size
);
918 /* set Loop Begin Address */
920 voice
->LBA
= voice
->memblk
->offset
;
922 voice
->LBA
= runtime
->dma_addr
;
925 voice
->ESO
= runtime
->buffer_size
- 1; /* in samples */
926 voice
->CTRL
= snd_trident_control_mode(substream
);
932 voice
->Vol
= mix
->vol
;
933 voice
->RVol
= mix
->rvol
;
934 voice
->CVol
= mix
->cvol
;
935 voice
->Pan
= mix
->pan
;
936 voice
->Attribute
= 0;
938 voice
->Attribute
= (1<<(30-16))|(2<<(26-16))|
939 (0<<(24-16))|(0x1f<<(19-16));
941 voice
->Attribute
= 0;
944 snd_trident_write_voice_regs(trident
, voice
);
946 if (evoice
!= NULL
) {
947 evoice
->Delta
= voice
->Delta
;
948 evoice
->spurious_threshold
= voice
->spurious_threshold
;
949 evoice
->LBA
= voice
->LBA
;
951 evoice
->ESO
= (runtime
->period_size
* 2) + 4 - 1; /* in samples */
952 evoice
->CTRL
= voice
->CTRL
;
954 evoice
->GVSel
= trident
->device
== TRIDENT_DEVICE_ID_SI7018
? 0 : 1;
958 evoice
->Vol
= 0x3ff; /* mute */
959 evoice
->RVol
= evoice
->CVol
= 0x7f; /* mute */
960 evoice
->Pan
= 0x7f; /* mute */
962 evoice
->Attribute
= (1<<(30-16))|(2<<(26-16))|
963 (0<<(24-16))|(0x1f<<(19-16));
965 evoice
->Attribute
= 0;
967 snd_trident_write_voice_regs(trident
, evoice
);
969 evoice
->isync_mark
= runtime
->period_size
;
970 evoice
->ESO
= (runtime
->period_size
* 2) - 1;
973 spin_unlock_irq(&trident
->reg_lock
);
978 /*---------------------------------------------------------------------------
979 snd_trident_capture_hw_params
981 Description: Set the hardware parameters for the capture device.
983 Parameters: substream - PCM substream class
984 hw_params - hardware parameters
986 Returns: Error status
988 ---------------------------------------------------------------------------*/
990 static int snd_trident_capture_hw_params(snd_pcm_substream_t
* substream
,
991 snd_pcm_hw_params_t
* hw_params
)
993 return snd_trident_allocate_pcm_mem(substream
, hw_params
);
996 /*---------------------------------------------------------------------------
997 snd_trident_capture_prepare
999 Description: Prepare capture device for playback.
1001 Parameters: substream - PCM substream class
1003 Returns: Error status
1005 ---------------------------------------------------------------------------*/
1007 static int snd_trident_capture_prepare(snd_pcm_substream_t
* substream
)
1009 trident_t
*trident
= snd_pcm_substream_chip(substream
);
1010 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
1011 snd_trident_voice_t
*voice
= (snd_trident_voice_t
*) runtime
->private_data
;
1012 unsigned int val
, ESO_bytes
;
1014 spin_lock_irq(&trident
->reg_lock
);
1016 // Initilize the channel and set channel Mode
1017 outb(0, TRID_REG(trident
, LEGACY_DMAR15
));
1019 // Set DMA channel operation mode register
1020 outb(0x54, TRID_REG(trident
, LEGACY_DMAR11
));
1022 // Set channel buffer Address, DMAR0 expects contiguous PCI memory area
1023 voice
->LBA
= runtime
->dma_addr
;
1024 outl(voice
->LBA
, TRID_REG(trident
, LEGACY_DMAR0
));
1026 voice
->LBA
= voice
->memblk
->offset
;
1029 ESO_bytes
= snd_pcm_lib_buffer_bytes(substream
) - 1;
1030 outb((ESO_bytes
& 0x00ff0000) >> 16, TRID_REG(trident
, LEGACY_DMAR6
));
1031 outw((ESO_bytes
& 0x0000ffff), TRID_REG(trident
, LEGACY_DMAR4
));
1034 // Set channel sample rate, 4.12 format
1035 val
= (((unsigned int) 48000L << 12) + (runtime
->rate
/2)) / runtime
->rate
;
1036 outw(val
, TRID_REG(trident
, T4D_SBDELTA_DELTA_R
));
1038 // Set channel interrupt blk length
1039 if (snd_pcm_format_width(runtime
->format
) == 16) {
1040 val
= (unsigned short) ((ESO_bytes
>> 1) - 1);
1042 val
= (unsigned short) (ESO_bytes
- 1);
1045 outl((val
<< 16) | val
, TRID_REG(trident
, T4D_SBBL_SBCL
));
1047 // Right now, set format and start to run captureing,
1048 // continuous run loop enable.
1049 trident
->bDMAStart
= 0x19; // 0001 1001b
1051 if (snd_pcm_format_width(runtime
->format
) == 16)
1052 trident
->bDMAStart
|= 0x80;
1053 if (snd_pcm_format_signed(runtime
->format
))
1054 trident
->bDMAStart
|= 0x20;
1055 if (runtime
->channels
> 1)
1056 trident
->bDMAStart
|= 0x40;
1058 // Prepare capture intr channel
1060 voice
->Delta
= snd_trident_convert_rate(runtime
->rate
);
1061 voice
->spurious_threshold
= snd_trident_spurious_threshold(runtime
->rate
, runtime
->period_size
);
1063 voice
->isync_mark
= runtime
->period_size
;
1064 voice
->isync_max
= runtime
->buffer_size
;
1066 // Set voice parameters
1068 voice
->ESO
= voice
->isync_ESO
= (runtime
->period_size
* 2) + 6 - 1;
1069 voice
->CTRL
= snd_trident_control_mode(substream
);
1074 voice
->Pan
= 0x7f; /* mute */
1075 voice
->Vol
= 0x3ff; /* mute */
1079 voice
->Attribute
= 0;
1081 snd_trident_write_voice_regs(trident
, voice
);
1083 spin_unlock_irq(&trident
->reg_lock
);
1087 /*---------------------------------------------------------------------------
1088 snd_trident_si7018_capture_hw_params
1090 Description: Set the hardware parameters for the capture device.
1092 Parameters: substream - PCM substream class
1093 hw_params - hardware parameters
1095 Returns: Error status
1097 ---------------------------------------------------------------------------*/
1099 static int snd_trident_si7018_capture_hw_params(snd_pcm_substream_t
* substream
,
1100 snd_pcm_hw_params_t
* hw_params
)
1104 if ((err
= snd_pcm_lib_malloc_pages(substream
, params_buffer_bytes(hw_params
))) < 0)
1107 return snd_trident_allocate_evoice(substream
, hw_params
);
1110 /*---------------------------------------------------------------------------
1111 snd_trident_si7018_capture_hw_free
1113 Description: Release the hardware resources for the capture device.
1115 Parameters: substream - PCM substream class
1117 Returns: Error status
1119 ---------------------------------------------------------------------------*/
1121 static int snd_trident_si7018_capture_hw_free(snd_pcm_substream_t
* substream
)
1123 trident_t
*trident
= snd_pcm_substream_chip(substream
);
1124 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
1125 snd_trident_voice_t
*voice
= (snd_trident_voice_t
*) runtime
->private_data
;
1126 snd_trident_voice_t
*evoice
= voice
? voice
->extra
: NULL
;
1128 snd_pcm_lib_free_pages(substream
);
1129 if (evoice
!= NULL
) {
1130 snd_trident_free_voice(trident
, evoice
);
1131 voice
->extra
= NULL
;
1136 /*---------------------------------------------------------------------------
1137 snd_trident_si7018_capture_prepare
1139 Description: Prepare capture device for playback.
1141 Parameters: substream - PCM substream class
1143 Returns: Error status
1145 ---------------------------------------------------------------------------*/
1147 static int snd_trident_si7018_capture_prepare(snd_pcm_substream_t
* substream
)
1149 trident_t
*trident
= snd_pcm_substream_chip(substream
);
1150 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
1151 snd_trident_voice_t
*voice
= (snd_trident_voice_t
*) runtime
->private_data
;
1152 snd_trident_voice_t
*evoice
= voice
->extra
;
1154 spin_lock_irq(&trident
->reg_lock
);
1156 voice
->LBA
= runtime
->dma_addr
;
1157 voice
->Delta
= snd_trident_convert_adc_rate(runtime
->rate
);
1158 voice
->spurious_threshold
= snd_trident_spurious_threshold(runtime
->rate
, runtime
->period_size
);
1160 // Set voice parameters
1162 voice
->ESO
= runtime
->buffer_size
- 1; /* in samples */
1163 voice
->CTRL
= snd_trident_control_mode(substream
);
1168 voice
->Pan
= T4D_DEFAULT_PCM_PAN
;
1174 voice
->Attribute
= (2 << (30-16)) |
1179 snd_trident_write_voice_regs(trident
, voice
);
1181 if (evoice
!= NULL
) {
1182 evoice
->Delta
= snd_trident_convert_rate(runtime
->rate
);
1183 evoice
->spurious_threshold
= voice
->spurious_threshold
;
1184 evoice
->LBA
= voice
->LBA
;
1186 evoice
->ESO
= (runtime
->period_size
* 2) + 20 - 1; /* in samples, 20 means correction */
1187 evoice
->CTRL
= voice
->CTRL
;
1193 evoice
->Vol
= 0x3ff; /* mute */
1194 evoice
->RVol
= evoice
->CVol
= 0x7f; /* mute */
1195 evoice
->Pan
= 0x7f; /* mute */
1196 evoice
->Attribute
= 0;
1197 snd_trident_write_voice_regs(trident
, evoice
);
1199 evoice
->isync_mark
= runtime
->period_size
;
1200 evoice
->ESO
= (runtime
->period_size
* 2) - 1;
1203 spin_unlock_irq(&trident
->reg_lock
);
1207 /*---------------------------------------------------------------------------
1208 snd_trident_foldback_prepare
1210 Description: Prepare foldback capture device for playback.
1212 Parameters: substream - PCM substream class
1214 Returns: Error status
1216 ---------------------------------------------------------------------------*/
1218 static int snd_trident_foldback_prepare(snd_pcm_substream_t
* substream
)
1220 trident_t
*trident
= snd_pcm_substream_chip(substream
);
1221 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
1222 snd_trident_voice_t
*voice
= (snd_trident_voice_t
*) runtime
->private_data
;
1223 snd_trident_voice_t
*evoice
= voice
->extra
;
1225 spin_lock_irq(&trident
->reg_lock
);
1227 /* Set channel buffer Address */
1229 voice
->LBA
= voice
->memblk
->offset
;
1231 voice
->LBA
= runtime
->dma_addr
;
1233 /* set target ESO for channel */
1234 voice
->ESO
= runtime
->buffer_size
- 1; /* in samples */
1236 /* set sample rate */
1237 voice
->Delta
= 0x1000;
1238 voice
->spurious_threshold
= snd_trident_spurious_threshold(48000, runtime
->period_size
);
1241 voice
->CTRL
= snd_trident_control_mode(substream
);
1246 voice
->Pan
= 0x7f; /* mute */
1247 voice
->Vol
= 0x3ff; /* mute */
1251 voice
->Attribute
= 0;
1253 /* set up capture channel */
1254 outb(((voice
->number
& 0x3f) | 0x80), TRID_REG(trident
, T4D_RCI
+ voice
->foldback_chan
));
1256 snd_trident_write_voice_regs(trident
, voice
);
1258 if (evoice
!= NULL
) {
1259 evoice
->Delta
= voice
->Delta
;
1260 evoice
->spurious_threshold
= voice
->spurious_threshold
;
1261 evoice
->LBA
= voice
->LBA
;
1263 evoice
->ESO
= (runtime
->period_size
* 2) + 4 - 1; /* in samples */
1264 evoice
->CTRL
= voice
->CTRL
;
1266 evoice
->GVSel
= trident
->device
== TRIDENT_DEVICE_ID_SI7018
? 0 : 1;
1270 evoice
->Vol
= 0x3ff; /* mute */
1271 evoice
->RVol
= evoice
->CVol
= 0x7f; /* mute */
1272 evoice
->Pan
= 0x7f; /* mute */
1273 evoice
->Attribute
= 0;
1274 snd_trident_write_voice_regs(trident
, evoice
);
1276 evoice
->isync_mark
= runtime
->period_size
;
1277 evoice
->ESO
= (runtime
->period_size
* 2) - 1;
1280 spin_unlock_irq(&trident
->reg_lock
);
1284 /*---------------------------------------------------------------------------
1285 snd_trident_spdif_hw_params
1287 Description: Set the hardware parameters for the spdif device.
1289 Parameters: substream - PCM substream class
1290 hw_params - hardware parameters
1292 Returns: Error status
1294 ---------------------------------------------------------------------------*/
1296 static int snd_trident_spdif_hw_params(snd_pcm_substream_t
* substream
,
1297 snd_pcm_hw_params_t
* hw_params
)
1299 trident_t
*trident
= snd_pcm_substream_chip(substream
);
1300 unsigned int old_bits
= 0, change
= 0;
1303 err
= snd_trident_allocate_pcm_mem(substream
, hw_params
);
1307 if (trident
->device
== TRIDENT_DEVICE_ID_SI7018
) {
1308 err
= snd_trident_allocate_evoice(substream
, hw_params
);
1313 /* prepare SPDIF channel */
1314 spin_lock_irq(&trident
->reg_lock
);
1315 old_bits
= trident
->spdif_pcm_bits
;
1316 if (old_bits
& IEC958_AES0_PROFESSIONAL
)
1317 trident
->spdif_pcm_bits
&= ~IEC958_AES0_PRO_FS
;
1319 trident
->spdif_pcm_bits
&= ~(IEC958_AES3_CON_FS
<< 24);
1320 if (params_rate(hw_params
) >= 48000) {
1321 trident
->spdif_pcm_ctrl
= 0x3c; // 48000 Hz
1322 trident
->spdif_pcm_bits
|=
1323 trident
->spdif_bits
& IEC958_AES0_PROFESSIONAL
?
1324 IEC958_AES0_PRO_FS_48000
:
1325 (IEC958_AES3_CON_FS_48000
<< 24);
1327 else if (params_rate(hw_params
) >= 44100) {
1328 trident
->spdif_pcm_ctrl
= 0x3e; // 44100 Hz
1329 trident
->spdif_pcm_bits
|=
1330 trident
->spdif_bits
& IEC958_AES0_PROFESSIONAL
?
1331 IEC958_AES0_PRO_FS_44100
:
1332 (IEC958_AES3_CON_FS_44100
<< 24);
1335 trident
->spdif_pcm_ctrl
= 0x3d; // 32000 Hz
1336 trident
->spdif_pcm_bits
|=
1337 trident
->spdif_bits
& IEC958_AES0_PROFESSIONAL
?
1338 IEC958_AES0_PRO_FS_32000
:
1339 (IEC958_AES3_CON_FS_32000
<< 24);
1341 change
= old_bits
!= trident
->spdif_pcm_bits
;
1342 spin_unlock_irq(&trident
->reg_lock
);
1345 snd_ctl_notify(trident
->card
, SNDRV_CTL_EVENT_MASK_VALUE
, &trident
->spdif_pcm_ctl
->id
);
1350 /*---------------------------------------------------------------------------
1351 snd_trident_spdif_prepare
1353 Description: Prepare SPDIF device for playback.
1355 Parameters: substream - PCM substream class
1357 Returns: Error status
1359 ---------------------------------------------------------------------------*/
1361 static int snd_trident_spdif_prepare(snd_pcm_substream_t
* substream
)
1363 trident_t
*trident
= snd_pcm_substream_chip(substream
);
1364 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
1365 snd_trident_voice_t
*voice
= (snd_trident_voice_t
*) runtime
->private_data
;
1366 snd_trident_voice_t
*evoice
= voice
->extra
;
1367 snd_trident_pcm_mixer_t
*mix
= &trident
->pcm_mixer
[substream
->number
];
1368 unsigned int RESO
, LBAO
;
1371 spin_lock_irq(&trident
->reg_lock
);
1373 if (trident
->device
!= TRIDENT_DEVICE_ID_SI7018
) {
1375 /* set delta (rate) value */
1376 voice
->Delta
= snd_trident_convert_rate(runtime
->rate
);
1377 voice
->spurious_threshold
= snd_trident_spurious_threshold(runtime
->rate
, runtime
->period_size
);
1379 /* set Loop Back Address */
1380 LBAO
= runtime
->dma_addr
;
1382 voice
->LBA
= voice
->memblk
->offset
;
1388 voice
->isync_mark
= runtime
->period_size
;
1389 voice
->isync_max
= runtime
->buffer_size
;
1391 /* set target ESO for channel */
1392 RESO
= runtime
->buffer_size
- 1;
1393 voice
->ESO
= voice
->isync_ESO
= (runtime
->period_size
* 2) + 6 - 1;
1396 voice
->CTRL
= snd_trident_control_mode(substream
);
1408 voice
->Attribute
= 0;
1410 /* prepare surrogate IRQ channel */
1411 snd_trident_write_voice_regs(trident
, voice
);
1413 outw((RESO
& 0xffff), TRID_REG(trident
, NX_SPESO
));
1414 outb((RESO
>> 16), TRID_REG(trident
, NX_SPESO
+ 2));
1415 outl((LBAO
& 0xfffffffc), TRID_REG(trident
, NX_SPLBA
));
1416 outw((voice
->CSO
& 0xffff), TRID_REG(trident
, NX_SPCTRL_SPCSO
));
1417 outb((voice
->CSO
>> 16), TRID_REG(trident
, NX_SPCTRL_SPCSO
+ 2));
1419 /* set SPDIF setting */
1420 outb(trident
->spdif_pcm_ctrl
, TRID_REG(trident
, NX_SPCTRL_SPCSO
+ 3));
1421 outl(trident
->spdif_pcm_bits
, TRID_REG(trident
, NX_SPCSTATUS
));
1425 /* set delta (rate) value */
1426 voice
->Delta
= 0x800;
1427 voice
->spurious_threshold
= snd_trident_spurious_threshold(48000, runtime
->period_size
);
1429 /* set Loop Begin Address */
1431 voice
->LBA
= voice
->memblk
->offset
;
1433 voice
->LBA
= runtime
->dma_addr
;
1436 voice
->ESO
= runtime
->buffer_size
- 1; /* in samples */
1437 voice
->CTRL
= snd_trident_control_mode(substream
);
1443 voice
->Vol
= mix
->vol
;
1444 voice
->RVol
= mix
->rvol
;
1445 voice
->CVol
= mix
->cvol
;
1446 voice
->Pan
= mix
->pan
;
1447 voice
->Attribute
= (1<<(30-16))|(7<<(26-16))|
1448 (0<<(24-16))|(0<<(19-16));
1450 snd_trident_write_voice_regs(trident
, voice
);
1452 if (evoice
!= NULL
) {
1453 evoice
->Delta
= voice
->Delta
;
1454 evoice
->spurious_threshold
= voice
->spurious_threshold
;
1455 evoice
->LBA
= voice
->LBA
;
1457 evoice
->ESO
= (runtime
->period_size
* 2) + 4 - 1; /* in samples */
1458 evoice
->CTRL
= voice
->CTRL
;
1460 evoice
->GVSel
= trident
->device
== TRIDENT_DEVICE_ID_SI7018
? 0 : 1;
1464 evoice
->Vol
= 0x3ff; /* mute */
1465 evoice
->RVol
= evoice
->CVol
= 0x7f; /* mute */
1466 evoice
->Pan
= 0x7f; /* mute */
1467 evoice
->Attribute
= 0;
1468 snd_trident_write_voice_regs(trident
, evoice
);
1470 evoice
->isync_mark
= runtime
->period_size
;
1471 evoice
->ESO
= (runtime
->period_size
* 2) - 1;
1474 outl(trident
->spdif_pcm_bits
, TRID_REG(trident
, SI_SPDIF_CS
));
1475 temp
= inl(TRID_REG(trident
, T4D_LFO_GC_CIR
));
1477 outl(temp
, TRID_REG(trident
, T4D_LFO_GC_CIR
));
1478 temp
= inl(TRID_REG(trident
, SI_SERIAL_INTF_CTRL
));
1480 outl(temp
, TRID_REG(trident
, SI_SERIAL_INTF_CTRL
));
1483 spin_unlock_irq(&trident
->reg_lock
);
1488 /*---------------------------------------------------------------------------
1491 Description: Start/stop devices
1493 Parameters: substream - PCM substream class
1494 cmd - trigger command (STOP, GO)
1496 Returns: Error status
1498 ---------------------------------------------------------------------------*/
1500 static int snd_trident_trigger(snd_pcm_substream_t
*substream
,
1504 trident_t
*trident
= snd_pcm_substream_chip(substream
);
1505 struct list_head
*pos
;
1506 snd_pcm_substream_t
*s
;
1507 unsigned int what
, whati
, capture_flag
, spdif_flag
;
1508 snd_trident_voice_t
*voice
, *evoice
;
1509 unsigned int val
, go
;
1512 case SNDRV_PCM_TRIGGER_START
:
1513 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
1514 case SNDRV_PCM_TRIGGER_RESUME
:
1517 case SNDRV_PCM_TRIGGER_STOP
:
1518 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
1519 case SNDRV_PCM_TRIGGER_SUSPEND
:
1525 what
= whati
= capture_flag
= spdif_flag
= 0;
1526 spin_lock(&trident
->reg_lock
);
1527 val
= inl(TRID_REG(trident
, T4D_STIMER
)) & 0x00ffffff;
1528 snd_pcm_group_for_each(pos
, substream
) {
1529 s
= snd_pcm_group_substream_entry(pos
);
1530 if ((trident_t
*) snd_pcm_substream_chip(s
) == trident
) {
1531 voice
= (snd_trident_voice_t
*) s
->runtime
->private_data
;
1532 evoice
= voice
->extra
;
1533 what
|= 1 << (voice
->number
& 0x1f);
1534 if (evoice
== NULL
) {
1535 whati
|= 1 << (voice
->number
& 0x1f);
1537 what
|= 1 << (evoice
->number
& 0x1f);
1538 whati
|= 1 << (evoice
->number
& 0x1f);
1540 evoice
->stimer
= val
;
1544 voice
->stimer
= val
;
1548 snd_pcm_trigger_done(s
, substream
);
1556 if (trident
->device
!= TRIDENT_DEVICE_ID_SI7018
) {
1557 outl(trident
->spdif_pcm_bits
, TRID_REG(trident
, NX_SPCSTATUS
));
1558 outb(trident
->spdif_pcm_ctrl
, TRID_REG(trident
, NX_SPCTRL_SPCSO
+ 3));
1560 outl(trident
->spdif_pcm_bits
, TRID_REG(trident
, SI_SPDIF_CS
));
1561 val
= inl(TRID_REG(trident
, SI_SERIAL_INTF_CTRL
)) | SPDIF_EN
;
1562 outl(val
, TRID_REG(trident
, SI_SERIAL_INTF_CTRL
));
1566 outl(what
, TRID_REG(trident
, T4D_STOP_B
));
1567 val
= inl(TRID_REG(trident
, T4D_AINTEN_B
));
1573 outl(val
, TRID_REG(trident
, T4D_AINTEN_B
));
1575 outl(what
, TRID_REG(trident
, T4D_START_B
));
1577 if (capture_flag
&& trident
->device
!= TRIDENT_DEVICE_ID_SI7018
)
1578 outb(trident
->bDMAStart
, TRID_REG(trident
, T4D_SBCTRL_SBE2R_SBDD
));
1580 if (capture_flag
&& trident
->device
!= TRIDENT_DEVICE_ID_SI7018
)
1581 outb(0x00, TRID_REG(trident
, T4D_SBCTRL_SBE2R_SBDD
));
1583 spin_unlock(&trident
->reg_lock
);
1587 /*---------------------------------------------------------------------------
1588 snd_trident_playback_pointer
1590 Description: This routine return the playback position
1592 Parameters: substream - PCM substream class
1594 Returns: position of buffer
1596 ---------------------------------------------------------------------------*/
1598 static snd_pcm_uframes_t
snd_trident_playback_pointer(snd_pcm_substream_t
* substream
)
1600 trident_t
*trident
= snd_pcm_substream_chip(substream
);
1601 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
1602 snd_trident_voice_t
*voice
= (snd_trident_voice_t
*) runtime
->private_data
;
1605 if (!voice
->running
)
1608 spin_lock(&trident
->reg_lock
);
1610 outb(voice
->number
, TRID_REG(trident
, T4D_LFO_GC_CIR
));
1612 if (trident
->device
!= TRIDENT_DEVICE_ID_NX
) {
1613 cso
= inw(TRID_REG(trident
, CH_DX_CSO_ALPHA_FMS
+ 2));
1614 } else { // ID_4DWAVE_NX
1615 cso
= (unsigned int) inl(TRID_REG(trident
, CH_NX_DELTA_CSO
)) & 0x00ffffff;
1618 spin_unlock(&trident
->reg_lock
);
1620 if (cso
>= runtime
->buffer_size
)
1626 /*---------------------------------------------------------------------------
1627 snd_trident_capture_pointer
1629 Description: This routine return the capture position
1631 Paramters: pcm1 - PCM device class
1633 Returns: position of buffer
1635 ---------------------------------------------------------------------------*/
1637 static snd_pcm_uframes_t
snd_trident_capture_pointer(snd_pcm_substream_t
* substream
)
1639 trident_t
*trident
= snd_pcm_substream_chip(substream
);
1640 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
1641 snd_trident_voice_t
*voice
= (snd_trident_voice_t
*) runtime
->private_data
;
1642 unsigned int result
;
1644 if (!voice
->running
)
1647 result
= inw(TRID_REG(trident
, T4D_SBBL_SBCL
));
1648 if (runtime
->channels
> 1)
1651 result
= runtime
->buffer_size
- result
;
1656 /*---------------------------------------------------------------------------
1657 snd_trident_spdif_pointer
1659 Description: This routine return the SPDIF playback position
1661 Parameters: substream - PCM substream class
1663 Returns: position of buffer
1665 ---------------------------------------------------------------------------*/
1667 static snd_pcm_uframes_t
snd_trident_spdif_pointer(snd_pcm_substream_t
* substream
)
1669 trident_t
*trident
= snd_pcm_substream_chip(substream
);
1670 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
1671 snd_trident_voice_t
*voice
= (snd_trident_voice_t
*) runtime
->private_data
;
1672 unsigned int result
;
1674 if (!voice
->running
)
1677 result
= inl(TRID_REG(trident
, NX_SPCTRL_SPCSO
)) & 0x00ffffff;
1683 * Playback support device description
1686 static snd_pcm_hardware_t snd_trident_playback
=
1688 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
1689 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
1690 SNDRV_PCM_INFO_MMAP_VALID
| SNDRV_PCM_INFO_SYNC_START
|
1691 SNDRV_PCM_INFO_PAUSE
| SNDRV_PCM_INFO_RESUME
),
1692 .formats
= (SNDRV_PCM_FMTBIT_U8
| SNDRV_PCM_FMTBIT_S16_LE
|
1693 SNDRV_PCM_FMTBIT_S8
| SNDRV_PCM_FMTBIT_U16_LE
),
1694 .rates
= SNDRV_PCM_RATE_CONTINUOUS
| SNDRV_PCM_RATE_8000_48000
,
1699 .buffer_bytes_max
= (256*1024),
1700 .period_bytes_min
= 64,
1701 .period_bytes_max
= (256*1024),
1703 .periods_max
= 1024,
1708 * Capture support device description
1711 static snd_pcm_hardware_t snd_trident_capture
=
1713 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
1714 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
1715 SNDRV_PCM_INFO_MMAP_VALID
| SNDRV_PCM_INFO_SYNC_START
|
1716 SNDRV_PCM_INFO_PAUSE
| SNDRV_PCM_INFO_RESUME
),
1717 .formats
= (SNDRV_PCM_FMTBIT_U8
| SNDRV_PCM_FMTBIT_S16_LE
|
1718 SNDRV_PCM_FMTBIT_S8
| SNDRV_PCM_FMTBIT_U16_LE
),
1719 .rates
= SNDRV_PCM_RATE_CONTINUOUS
| SNDRV_PCM_RATE_8000_48000
,
1724 .buffer_bytes_max
= (128*1024),
1725 .period_bytes_min
= 64,
1726 .period_bytes_max
= (128*1024),
1728 .periods_max
= 1024,
1733 * Foldback capture support device description
1736 static snd_pcm_hardware_t snd_trident_foldback
=
1738 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
1739 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
1740 SNDRV_PCM_INFO_MMAP_VALID
| SNDRV_PCM_INFO_SYNC_START
|
1741 SNDRV_PCM_INFO_PAUSE
| SNDRV_PCM_INFO_RESUME
),
1742 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
1743 .rates
= SNDRV_PCM_RATE_48000
,
1748 .buffer_bytes_max
= (128*1024),
1749 .period_bytes_min
= 64,
1750 .period_bytes_max
= (128*1024),
1752 .periods_max
= 1024,
1757 * SPDIF playback support device description
1760 static snd_pcm_hardware_t snd_trident_spdif
=
1762 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
1763 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
1764 SNDRV_PCM_INFO_MMAP_VALID
| SNDRV_PCM_INFO_SYNC_START
|
1765 SNDRV_PCM_INFO_PAUSE
| SNDRV_PCM_INFO_RESUME
),
1766 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
1767 .rates
= (SNDRV_PCM_RATE_32000
| SNDRV_PCM_RATE_44100
|
1768 SNDRV_PCM_RATE_48000
),
1773 .buffer_bytes_max
= (128*1024),
1774 .period_bytes_min
= 64,
1775 .period_bytes_max
= (128*1024),
1777 .periods_max
= 1024,
1781 static snd_pcm_hardware_t snd_trident_spdif_7018
=
1783 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
1784 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
1785 SNDRV_PCM_INFO_MMAP_VALID
| SNDRV_PCM_INFO_SYNC_START
|
1786 SNDRV_PCM_INFO_PAUSE
| SNDRV_PCM_INFO_RESUME
),
1787 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
1788 .rates
= SNDRV_PCM_RATE_48000
,
1793 .buffer_bytes_max
= (128*1024),
1794 .period_bytes_min
= 64,
1795 .period_bytes_max
= (128*1024),
1797 .periods_max
= 1024,
1801 static void snd_trident_pcm_free_substream(snd_pcm_runtime_t
*runtime
)
1803 snd_trident_voice_t
*voice
= (snd_trident_voice_t
*) runtime
->private_data
;
1807 trident
= voice
->trident
;
1808 snd_trident_free_voice(trident
, voice
);
1812 static int snd_trident_playback_open(snd_pcm_substream_t
* substream
)
1814 trident_t
*trident
= snd_pcm_substream_chip(substream
);
1815 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
1816 snd_trident_voice_t
*voice
;
1818 voice
= snd_trident_alloc_voice(trident
, SNDRV_TRIDENT_VOICE_TYPE_PCM
, 0, 0);
1821 snd_trident_pcm_mixer_build(trident
, voice
, substream
);
1822 voice
->substream
= substream
;
1823 runtime
->private_data
= voice
;
1824 runtime
->private_free
= snd_trident_pcm_free_substream
;
1825 runtime
->hw
= snd_trident_playback
;
1826 snd_pcm_set_sync(substream
);
1827 snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_BUFFER_SIZE
, 0, 64*1024);
1831 /*---------------------------------------------------------------------------
1832 snd_trident_playback_close
1834 Description: This routine will close the 4DWave playback device. For now
1835 we will simply free the dma transfer buffer.
1837 Parameters: substream - PCM substream class
1839 ---------------------------------------------------------------------------*/
1840 static int snd_trident_playback_close(snd_pcm_substream_t
* substream
)
1842 trident_t
*trident
= snd_pcm_substream_chip(substream
);
1843 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
1844 snd_trident_voice_t
*voice
= (snd_trident_voice_t
*) runtime
->private_data
;
1846 snd_trident_pcm_mixer_free(trident
, voice
, substream
);
1850 /*---------------------------------------------------------------------------
1851 snd_trident_spdif_open
1853 Description: This routine will open the 4DWave SPDIF device.
1855 Parameters: substream - PCM substream class
1857 Returns: status - success or failure flag
1859 ---------------------------------------------------------------------------*/
1861 static int snd_trident_spdif_open(snd_pcm_substream_t
* substream
)
1863 trident_t
*trident
= snd_pcm_substream_chip(substream
);
1864 snd_trident_voice_t
*voice
;
1865 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
1867 voice
= snd_trident_alloc_voice(trident
, SNDRV_TRIDENT_VOICE_TYPE_PCM
, 0, 0);
1871 voice
->substream
= substream
;
1872 spin_lock_irq(&trident
->reg_lock
);
1873 trident
->spdif_pcm_bits
= trident
->spdif_bits
;
1874 spin_unlock_irq(&trident
->reg_lock
);
1876 runtime
->private_data
= voice
;
1877 runtime
->private_free
= snd_trident_pcm_free_substream
;
1878 if (trident
->device
== TRIDENT_DEVICE_ID_SI7018
) {
1879 runtime
->hw
= snd_trident_spdif
;
1881 runtime
->hw
= snd_trident_spdif_7018
;
1884 trident
->spdif_pcm_ctl
->vd
[0].access
&= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE
;
1885 snd_ctl_notify(trident
->card
, SNDRV_CTL_EVENT_MASK_VALUE
|
1886 SNDRV_CTL_EVENT_MASK_INFO
, &trident
->spdif_pcm_ctl
->id
);
1888 snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_BUFFER_SIZE
, 0, 64*1024);
1893 /*---------------------------------------------------------------------------
1894 snd_trident_spdif_close
1896 Description: This routine will close the 4DWave SPDIF device.
1898 Parameters: substream - PCM substream class
1900 ---------------------------------------------------------------------------*/
1902 static int snd_trident_spdif_close(snd_pcm_substream_t
* substream
)
1904 trident_t
*trident
= snd_pcm_substream_chip(substream
);
1907 spin_lock_irq(&trident
->reg_lock
);
1908 // restore default SPDIF setting
1909 if (trident
->device
!= TRIDENT_DEVICE_ID_SI7018
) {
1910 outb(trident
->spdif_ctrl
, TRID_REG(trident
, NX_SPCTRL_SPCSO
+ 3));
1911 outl(trident
->spdif_bits
, TRID_REG(trident
, NX_SPCSTATUS
));
1913 outl(trident
->spdif_bits
, TRID_REG(trident
, SI_SPDIF_CS
));
1914 temp
= inl(TRID_REG(trident
, SI_SERIAL_INTF_CTRL
));
1915 if (trident
->spdif_ctrl
) {
1920 outl(temp
, TRID_REG(trident
, SI_SERIAL_INTF_CTRL
));
1922 spin_unlock_irq(&trident
->reg_lock
);
1923 trident
->spdif_pcm_ctl
->vd
[0].access
|= SNDRV_CTL_ELEM_ACCESS_INACTIVE
;
1924 snd_ctl_notify(trident
->card
, SNDRV_CTL_EVENT_MASK_VALUE
|
1925 SNDRV_CTL_EVENT_MASK_INFO
, &trident
->spdif_pcm_ctl
->id
);
1929 /*---------------------------------------------------------------------------
1930 snd_trident_capture_open
1932 Description: This routine will open the 4DWave capture device.
1934 Parameters: substream - PCM substream class
1936 Returns: status - success or failure flag
1938 ---------------------------------------------------------------------------*/
1940 static int snd_trident_capture_open(snd_pcm_substream_t
* substream
)
1942 trident_t
*trident
= snd_pcm_substream_chip(substream
);
1943 snd_trident_voice_t
*voice
;
1944 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
1946 voice
= snd_trident_alloc_voice(trident
, SNDRV_TRIDENT_VOICE_TYPE_PCM
, 0, 0);
1950 voice
->substream
= substream
;
1951 runtime
->private_data
= voice
;
1952 runtime
->private_free
= snd_trident_pcm_free_substream
;
1953 runtime
->hw
= snd_trident_capture
;
1954 snd_pcm_set_sync(substream
);
1955 snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_BUFFER_SIZE
, 0, 64*1024);
1959 /*---------------------------------------------------------------------------
1960 snd_trident_capture_close
1962 Description: This routine will close the 4DWave capture device. For now
1963 we will simply free the dma transfer buffer.
1965 Parameters: substream - PCM substream class
1967 ---------------------------------------------------------------------------*/
1968 static int snd_trident_capture_close(snd_pcm_substream_t
* substream
)
1973 /*---------------------------------------------------------------------------
1974 snd_trident_foldback_open
1976 Description: This routine will open the 4DWave foldback capture device.
1978 Parameters: substream - PCM substream class
1980 Returns: status - success or failure flag
1982 ---------------------------------------------------------------------------*/
1984 static int snd_trident_foldback_open(snd_pcm_substream_t
* substream
)
1986 trident_t
*trident
= snd_pcm_substream_chip(substream
);
1987 snd_trident_voice_t
*voice
;
1988 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
1990 voice
= snd_trident_alloc_voice(trident
, SNDRV_TRIDENT_VOICE_TYPE_PCM
, 0, 0);
1993 voice
->foldback_chan
= substream
->number
;
1994 voice
->substream
= substream
;
1995 runtime
->private_data
= voice
;
1996 runtime
->private_free
= snd_trident_pcm_free_substream
;
1997 runtime
->hw
= snd_trident_foldback
;
1998 snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_BUFFER_SIZE
, 0, 64*1024);
2002 /*---------------------------------------------------------------------------
2003 snd_trident_foldback_close
2005 Description: This routine will close the 4DWave foldback capture device.
2006 For now we will simply free the dma transfer buffer.
2008 Parameters: substream - PCM substream class
2010 ---------------------------------------------------------------------------*/
2011 static int snd_trident_foldback_close(snd_pcm_substream_t
* substream
)
2013 trident_t
*trident
= snd_pcm_substream_chip(substream
);
2014 snd_trident_voice_t
*voice
;
2015 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
2016 voice
= (snd_trident_voice_t
*) runtime
->private_data
;
2018 /* stop capture channel */
2019 spin_lock_irq(&trident
->reg_lock
);
2020 outb(0x00, TRID_REG(trident
, T4D_RCI
+ voice
->foldback_chan
));
2021 spin_unlock_irq(&trident
->reg_lock
);
2025 /*---------------------------------------------------------------------------
2027 ---------------------------------------------------------------------------*/
2029 static snd_pcm_ops_t snd_trident_playback_ops
= {
2030 .open
= snd_trident_playback_open
,
2031 .close
= snd_trident_playback_close
,
2032 .ioctl
= snd_trident_ioctl
,
2033 .hw_params
= snd_trident_hw_params
,
2034 .hw_free
= snd_trident_hw_free
,
2035 .prepare
= snd_trident_playback_prepare
,
2036 .trigger
= snd_trident_trigger
,
2037 .pointer
= snd_trident_playback_pointer
,
2040 static snd_pcm_ops_t snd_trident_nx_playback_ops
= {
2041 .open
= snd_trident_playback_open
,
2042 .close
= snd_trident_playback_close
,
2043 .ioctl
= snd_trident_ioctl
,
2044 .hw_params
= snd_trident_hw_params
,
2045 .hw_free
= snd_trident_hw_free
,
2046 .prepare
= snd_trident_playback_prepare
,
2047 .trigger
= snd_trident_trigger
,
2048 .pointer
= snd_trident_playback_pointer
,
2049 .page
= snd_pcm_sgbuf_ops_page
,
2052 static snd_pcm_ops_t snd_trident_capture_ops
= {
2053 .open
= snd_trident_capture_open
,
2054 .close
= snd_trident_capture_close
,
2055 .ioctl
= snd_trident_ioctl
,
2056 .hw_params
= snd_trident_capture_hw_params
,
2057 .hw_free
= snd_trident_hw_free
,
2058 .prepare
= snd_trident_capture_prepare
,
2059 .trigger
= snd_trident_trigger
,
2060 .pointer
= snd_trident_capture_pointer
,
2063 static snd_pcm_ops_t snd_trident_si7018_capture_ops
= {
2064 .open
= snd_trident_capture_open
,
2065 .close
= snd_trident_capture_close
,
2066 .ioctl
= snd_trident_ioctl
,
2067 .hw_params
= snd_trident_si7018_capture_hw_params
,
2068 .hw_free
= snd_trident_si7018_capture_hw_free
,
2069 .prepare
= snd_trident_si7018_capture_prepare
,
2070 .trigger
= snd_trident_trigger
,
2071 .pointer
= snd_trident_playback_pointer
,
2074 static snd_pcm_ops_t snd_trident_foldback_ops
= {
2075 .open
= snd_trident_foldback_open
,
2076 .close
= snd_trident_foldback_close
,
2077 .ioctl
= snd_trident_ioctl
,
2078 .hw_params
= snd_trident_hw_params
,
2079 .hw_free
= snd_trident_hw_free
,
2080 .prepare
= snd_trident_foldback_prepare
,
2081 .trigger
= snd_trident_trigger
,
2082 .pointer
= snd_trident_playback_pointer
,
2085 static snd_pcm_ops_t snd_trident_nx_foldback_ops
= {
2086 .open
= snd_trident_foldback_open
,
2087 .close
= snd_trident_foldback_close
,
2088 .ioctl
= snd_trident_ioctl
,
2089 .hw_params
= snd_trident_hw_params
,
2090 .hw_free
= snd_trident_hw_free
,
2091 .prepare
= snd_trident_foldback_prepare
,
2092 .trigger
= snd_trident_trigger
,
2093 .pointer
= snd_trident_playback_pointer
,
2094 .page
= snd_pcm_sgbuf_ops_page
,
2097 static snd_pcm_ops_t snd_trident_spdif_ops
= {
2098 .open
= snd_trident_spdif_open
,
2099 .close
= snd_trident_spdif_close
,
2100 .ioctl
= snd_trident_ioctl
,
2101 .hw_params
= snd_trident_spdif_hw_params
,
2102 .hw_free
= snd_trident_hw_free
,
2103 .prepare
= snd_trident_spdif_prepare
,
2104 .trigger
= snd_trident_trigger
,
2105 .pointer
= snd_trident_spdif_pointer
,
2108 static snd_pcm_ops_t snd_trident_spdif_7018_ops
= {
2109 .open
= snd_trident_spdif_open
,
2110 .close
= snd_trident_spdif_close
,
2111 .ioctl
= snd_trident_ioctl
,
2112 .hw_params
= snd_trident_spdif_hw_params
,
2113 .hw_free
= snd_trident_hw_free
,
2114 .prepare
= snd_trident_spdif_prepare
,
2115 .trigger
= snd_trident_trigger
,
2116 .pointer
= snd_trident_playback_pointer
,
2119 /*---------------------------------------------------------------------------
2120 snd_trident_pcm_free
2122 Description: This routine release the 4DWave private data.
2124 Paramters: private_data - pointer to 4DWave device info.
2128 ---------------------------------------------------------------------------*/
2129 static void snd_trident_pcm_free(snd_pcm_t
*pcm
)
2131 trident_t
*trident
= pcm
->private_data
;
2132 trident
->pcm
= NULL
;
2133 snd_pcm_lib_preallocate_free_for_all(pcm
);
2136 static void snd_trident_foldback_pcm_free(snd_pcm_t
*pcm
)
2138 trident_t
*trident
= pcm
->private_data
;
2139 trident
->foldback
= NULL
;
2140 snd_pcm_lib_preallocate_free_for_all(pcm
);
2143 static void snd_trident_spdif_pcm_free(snd_pcm_t
*pcm
)
2145 trident_t
*trident
= pcm
->private_data
;
2146 trident
->spdif
= NULL
;
2147 snd_pcm_lib_preallocate_free_for_all(pcm
);
2150 /*---------------------------------------------------------------------------
2153 Description: This routine registers the 4DWave device for PCM support.
2155 Paramters: trident - pointer to target device class for 4DWave.
2159 ---------------------------------------------------------------------------*/
2161 int __devinit
snd_trident_pcm(trident_t
* trident
, int device
, snd_pcm_t
** rpcm
)
2168 if ((err
= snd_pcm_new(trident
->card
, "trident_dx_nx", device
, trident
->ChanPCM
, 1, &pcm
)) < 0)
2171 pcm
->private_data
= trident
;
2172 pcm
->private_free
= snd_trident_pcm_free
;
2174 if (trident
->tlb
.entries
) {
2175 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_trident_nx_playback_ops
);
2177 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_trident_playback_ops
);
2179 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
,
2180 trident
->device
!= TRIDENT_DEVICE_ID_SI7018
?
2181 &snd_trident_capture_ops
:
2182 &snd_trident_si7018_capture_ops
);
2184 pcm
->info_flags
= 0;
2185 pcm
->dev_subclass
= SNDRV_PCM_SUBCLASS_GENERIC_MIX
;
2186 strcpy(pcm
->name
, "Trident 4DWave");
2189 if (trident
->tlb
.entries
) {
2190 snd_pcm_substream_t
*substream
;
2191 for (substream
= pcm
->streams
[SNDRV_PCM_STREAM_PLAYBACK
].substream
; substream
; substream
= substream
->next
)
2192 snd_pcm_lib_preallocate_pages(substream
, SNDRV_DMA_TYPE_DEV_SG
,
2193 snd_dma_pci_data(trident
->pci
),
2195 snd_pcm_lib_preallocate_pages(pcm
->streams
[SNDRV_PCM_STREAM_CAPTURE
].substream
,
2196 SNDRV_DMA_TYPE_DEV
, snd_dma_pci_data(trident
->pci
),
2199 snd_pcm_lib_preallocate_pages_for_all(pcm
, SNDRV_DMA_TYPE_DEV
,
2200 snd_dma_pci_data(trident
->pci
), 64*1024, 128*1024);
2208 /*---------------------------------------------------------------------------
2209 snd_trident_foldback_pcm
2211 Description: This routine registers the 4DWave device for foldback PCM support.
2213 Paramters: trident - pointer to target device class for 4DWave.
2217 ---------------------------------------------------------------------------*/
2219 int __devinit
snd_trident_foldback_pcm(trident_t
* trident
, int device
, snd_pcm_t
** rpcm
)
2221 snd_pcm_t
*foldback
;
2224 snd_pcm_substream_t
*substream
;
2228 if (trident
->device
== TRIDENT_DEVICE_ID_NX
)
2230 if ((err
= snd_pcm_new(trident
->card
, "trident_dx_nx", device
, 0, num_chan
, &foldback
)) < 0)
2233 foldback
->private_data
= trident
;
2234 foldback
->private_free
= snd_trident_foldback_pcm_free
;
2235 if (trident
->tlb
.entries
)
2236 snd_pcm_set_ops(foldback
, SNDRV_PCM_STREAM_CAPTURE
, &snd_trident_nx_foldback_ops
);
2238 snd_pcm_set_ops(foldback
, SNDRV_PCM_STREAM_CAPTURE
, &snd_trident_foldback_ops
);
2239 foldback
->info_flags
= 0;
2240 strcpy(foldback
->name
, "Trident 4DWave");
2241 substream
= foldback
->streams
[SNDRV_PCM_STREAM_CAPTURE
].substream
;
2242 strcpy(substream
->name
, "Front Mixer");
2243 substream
= substream
->next
;
2244 strcpy(substream
->name
, "Reverb Mixer");
2245 substream
= substream
->next
;
2246 strcpy(substream
->name
, "Chorus Mixer");
2247 if (num_chan
== 4) {
2248 substream
= substream
->next
;
2249 strcpy(substream
->name
, "Second AC'97 ADC");
2251 trident
->foldback
= foldback
;
2253 if (trident
->tlb
.entries
)
2254 snd_pcm_lib_preallocate_pages_for_all(foldback
, SNDRV_DMA_TYPE_DEV_SG
,
2255 snd_dma_pci_data(trident
->pci
), 0, 128*1024);
2257 snd_pcm_lib_preallocate_pages_for_all(foldback
, SNDRV_DMA_TYPE_DEV
,
2258 snd_dma_pci_data(trident
->pci
), 64*1024, 128*1024);
2265 /*---------------------------------------------------------------------------
2268 Description: This routine registers the 4DWave-NX device for SPDIF support.
2270 Paramters: trident - pointer to target device class for 4DWave-NX.
2274 ---------------------------------------------------------------------------*/
2276 int __devinit
snd_trident_spdif_pcm(trident_t
* trident
, int device
, snd_pcm_t
** rpcm
)
2283 if ((err
= snd_pcm_new(trident
->card
, "trident_dx_nx IEC958", device
, 1, 0, &spdif
)) < 0)
2286 spdif
->private_data
= trident
;
2287 spdif
->private_free
= snd_trident_spdif_pcm_free
;
2288 if (trident
->device
!= TRIDENT_DEVICE_ID_SI7018
) {
2289 snd_pcm_set_ops(spdif
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_trident_spdif_ops
);
2291 snd_pcm_set_ops(spdif
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_trident_spdif_7018_ops
);
2293 spdif
->info_flags
= 0;
2294 strcpy(spdif
->name
, "Trident 4DWave IEC958");
2295 trident
->spdif
= spdif
;
2297 snd_pcm_lib_preallocate_pages_for_all(spdif
, SNDRV_DMA_TYPE_DEV
, snd_dma_pci_data(trident
->pci
), 64*1024, 128*1024);
2309 /*---------------------------------------------------------------------------
2310 snd_trident_spdif_control
2312 Description: enable/disable S/PDIF out from ac97 mixer
2313 ---------------------------------------------------------------------------*/
2315 static int snd_trident_spdif_control_info(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
* uinfo
)
2317 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
2319 uinfo
->value
.integer
.min
= 0;
2320 uinfo
->value
.integer
.max
= 1;
2324 static int snd_trident_spdif_control_get(snd_kcontrol_t
* kcontrol
,
2325 snd_ctl_elem_value_t
* ucontrol
)
2327 trident_t
*trident
= snd_kcontrol_chip(kcontrol
);
2330 spin_lock_irq(&trident
->reg_lock
);
2331 val
= trident
->spdif_ctrl
;
2332 ucontrol
->value
.integer
.value
[0] = val
== kcontrol
->private_value
;
2333 spin_unlock_irq(&trident
->reg_lock
);
2337 static int snd_trident_spdif_control_put(snd_kcontrol_t
* kcontrol
,
2338 snd_ctl_elem_value_t
* ucontrol
)
2340 trident_t
*trident
= snd_kcontrol_chip(kcontrol
);
2344 val
= ucontrol
->value
.integer
.value
[0] ? (unsigned char) kcontrol
->private_value
: 0x00;
2345 spin_lock_irq(&trident
->reg_lock
);
2346 /* S/PDIF C Channel bits 0-31 : 48khz, SCMS disabled */
2347 change
= trident
->spdif_ctrl
!= val
;
2348 trident
->spdif_ctrl
= val
;
2349 if (trident
->device
!= TRIDENT_DEVICE_ID_SI7018
) {
2350 if ((inb(TRID_REG(trident
, NX_SPCTRL_SPCSO
+ 3)) & 0x10) == 0) {
2351 outl(trident
->spdif_bits
, TRID_REG(trident
, NX_SPCSTATUS
));
2352 outb(trident
->spdif_ctrl
, TRID_REG(trident
, NX_SPCTRL_SPCSO
+ 3));
2355 if (trident
->spdif
== NULL
) {
2357 outl(trident
->spdif_bits
, TRID_REG(trident
, SI_SPDIF_CS
));
2358 temp
= inl(TRID_REG(trident
, SI_SERIAL_INTF_CTRL
)) & ~SPDIF_EN
;
2361 outl(temp
, TRID_REG(trident
, SI_SERIAL_INTF_CTRL
));
2364 spin_unlock_irq(&trident
->reg_lock
);
2368 static snd_kcontrol_new_t snd_trident_spdif_control __devinitdata
=
2370 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2371 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,SWITCH
),
2372 .info
= snd_trident_spdif_control_info
,
2373 .get
= snd_trident_spdif_control_get
,
2374 .put
= snd_trident_spdif_control_put
,
2375 .private_value
= 0x28,
2378 /*---------------------------------------------------------------------------
2379 snd_trident_spdif_default
2381 Description: put/get the S/PDIF default settings
2382 ---------------------------------------------------------------------------*/
2384 static int snd_trident_spdif_default_info(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
* uinfo
)
2386 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_IEC958
;
2391 static int snd_trident_spdif_default_get(snd_kcontrol_t
* kcontrol
,
2392 snd_ctl_elem_value_t
* ucontrol
)
2394 trident_t
*trident
= snd_kcontrol_chip(kcontrol
);
2396 spin_lock_irq(&trident
->reg_lock
);
2397 ucontrol
->value
.iec958
.status
[0] = (trident
->spdif_bits
>> 0) & 0xff;
2398 ucontrol
->value
.iec958
.status
[1] = (trident
->spdif_bits
>> 8) & 0xff;
2399 ucontrol
->value
.iec958
.status
[2] = (trident
->spdif_bits
>> 16) & 0xff;
2400 ucontrol
->value
.iec958
.status
[3] = (trident
->spdif_bits
>> 24) & 0xff;
2401 spin_unlock_irq(&trident
->reg_lock
);
2405 static int snd_trident_spdif_default_put(snd_kcontrol_t
* kcontrol
,
2406 snd_ctl_elem_value_t
* ucontrol
)
2408 trident_t
*trident
= snd_kcontrol_chip(kcontrol
);
2412 val
= (ucontrol
->value
.iec958
.status
[0] << 0) |
2413 (ucontrol
->value
.iec958
.status
[1] << 8) |
2414 (ucontrol
->value
.iec958
.status
[2] << 16) |
2415 (ucontrol
->value
.iec958
.status
[3] << 24);
2416 spin_lock_irq(&trident
->reg_lock
);
2417 change
= trident
->spdif_bits
!= val
;
2418 trident
->spdif_bits
= val
;
2419 if (trident
->device
!= TRIDENT_DEVICE_ID_SI7018
) {
2420 if ((inb(TRID_REG(trident
, NX_SPCTRL_SPCSO
+ 3)) & 0x10) == 0)
2421 outl(trident
->spdif_bits
, TRID_REG(trident
, NX_SPCSTATUS
));
2423 if (trident
->spdif
== NULL
)
2424 outl(trident
->spdif_bits
, TRID_REG(trident
, SI_SPDIF_CS
));
2426 spin_unlock_irq(&trident
->reg_lock
);
2430 static snd_kcontrol_new_t snd_trident_spdif_default __devinitdata
=
2432 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
2433 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,DEFAULT
),
2434 .info
= snd_trident_spdif_default_info
,
2435 .get
= snd_trident_spdif_default_get
,
2436 .put
= snd_trident_spdif_default_put
2439 /*---------------------------------------------------------------------------
2440 snd_trident_spdif_mask
2442 Description: put/get the S/PDIF mask
2443 ---------------------------------------------------------------------------*/
2445 static int snd_trident_spdif_mask_info(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
* uinfo
)
2447 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_IEC958
;
2452 static int snd_trident_spdif_mask_get(snd_kcontrol_t
* kcontrol
,
2453 snd_ctl_elem_value_t
* ucontrol
)
2455 ucontrol
->value
.iec958
.status
[0] = 0xff;
2456 ucontrol
->value
.iec958
.status
[1] = 0xff;
2457 ucontrol
->value
.iec958
.status
[2] = 0xff;
2458 ucontrol
->value
.iec958
.status
[3] = 0xff;
2462 static snd_kcontrol_new_t snd_trident_spdif_mask __devinitdata
=
2464 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
2465 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
2466 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,MASK
),
2467 .info
= snd_trident_spdif_mask_info
,
2468 .get
= snd_trident_spdif_mask_get
,
2471 /*---------------------------------------------------------------------------
2472 snd_trident_spdif_stream
2474 Description: put/get the S/PDIF stream settings
2475 ---------------------------------------------------------------------------*/
2477 static int snd_trident_spdif_stream_info(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
* uinfo
)
2479 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_IEC958
;
2484 static int snd_trident_spdif_stream_get(snd_kcontrol_t
* kcontrol
,
2485 snd_ctl_elem_value_t
* ucontrol
)
2487 trident_t
*trident
= snd_kcontrol_chip(kcontrol
);
2489 spin_lock_irq(&trident
->reg_lock
);
2490 ucontrol
->value
.iec958
.status
[0] = (trident
->spdif_pcm_bits
>> 0) & 0xff;
2491 ucontrol
->value
.iec958
.status
[1] = (trident
->spdif_pcm_bits
>> 8) & 0xff;
2492 ucontrol
->value
.iec958
.status
[2] = (trident
->spdif_pcm_bits
>> 16) & 0xff;
2493 ucontrol
->value
.iec958
.status
[3] = (trident
->spdif_pcm_bits
>> 24) & 0xff;
2494 spin_unlock_irq(&trident
->reg_lock
);
2498 static int snd_trident_spdif_stream_put(snd_kcontrol_t
* kcontrol
,
2499 snd_ctl_elem_value_t
* ucontrol
)
2501 trident_t
*trident
= snd_kcontrol_chip(kcontrol
);
2505 val
= (ucontrol
->value
.iec958
.status
[0] << 0) |
2506 (ucontrol
->value
.iec958
.status
[1] << 8) |
2507 (ucontrol
->value
.iec958
.status
[2] << 16) |
2508 (ucontrol
->value
.iec958
.status
[3] << 24);
2509 spin_lock_irq(&trident
->reg_lock
);
2510 change
= trident
->spdif_pcm_bits
!= val
;
2511 trident
->spdif_pcm_bits
= val
;
2512 if (trident
->spdif
!= NULL
) {
2513 if (trident
->device
!= TRIDENT_DEVICE_ID_SI7018
) {
2514 outl(trident
->spdif_pcm_bits
, TRID_REG(trident
, NX_SPCSTATUS
));
2516 outl(trident
->spdif_bits
, TRID_REG(trident
, SI_SPDIF_CS
));
2519 spin_unlock_irq(&trident
->reg_lock
);
2523 static snd_kcontrol_new_t snd_trident_spdif_stream __devinitdata
=
2525 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
| SNDRV_CTL_ELEM_ACCESS_INACTIVE
,
2526 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
2527 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,PCM_STREAM
),
2528 .info
= snd_trident_spdif_stream_info
,
2529 .get
= snd_trident_spdif_stream_get
,
2530 .put
= snd_trident_spdif_stream_put
2533 /*---------------------------------------------------------------------------
2534 snd_trident_ac97_control
2536 Description: enable/disable rear path for ac97
2537 ---------------------------------------------------------------------------*/
2539 static int snd_trident_ac97_control_info(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
* uinfo
)
2541 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
2543 uinfo
->value
.integer
.min
= 0;
2544 uinfo
->value
.integer
.max
= 1;
2548 static int snd_trident_ac97_control_get(snd_kcontrol_t
* kcontrol
,
2549 snd_ctl_elem_value_t
* ucontrol
)
2551 trident_t
*trident
= snd_kcontrol_chip(kcontrol
);
2554 spin_lock_irq(&trident
->reg_lock
);
2555 val
= trident
->ac97_ctrl
= inl(TRID_REG(trident
, NX_ACR0_AC97_COM_STAT
));
2556 ucontrol
->value
.integer
.value
[0] = (val
& (1 << kcontrol
->private_value
)) ? 1 : 0;
2557 spin_unlock_irq(&trident
->reg_lock
);
2561 static int snd_trident_ac97_control_put(snd_kcontrol_t
* kcontrol
,
2562 snd_ctl_elem_value_t
* ucontrol
)
2564 trident_t
*trident
= snd_kcontrol_chip(kcontrol
);
2568 spin_lock_irq(&trident
->reg_lock
);
2569 val
= trident
->ac97_ctrl
= inl(TRID_REG(trident
, NX_ACR0_AC97_COM_STAT
));
2570 val
&= ~(1 << kcontrol
->private_value
);
2571 if (ucontrol
->value
.integer
.value
[0])
2572 val
|= 1 << kcontrol
->private_value
;
2573 change
= val
!= trident
->ac97_ctrl
;
2574 trident
->ac97_ctrl
= val
;
2575 outl(trident
->ac97_ctrl
= val
, TRID_REG(trident
, NX_ACR0_AC97_COM_STAT
));
2576 spin_unlock_irq(&trident
->reg_lock
);
2580 static snd_kcontrol_new_t snd_trident_ac97_rear_control __devinitdata
=
2582 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2583 .name
= "Rear Path",
2584 .info
= snd_trident_ac97_control_info
,
2585 .get
= snd_trident_ac97_control_get
,
2586 .put
= snd_trident_ac97_control_put
,
2590 /*---------------------------------------------------------------------------
2591 snd_trident_vol_control
2593 Description: wave & music volume control
2594 ---------------------------------------------------------------------------*/
2596 static int snd_trident_vol_control_info(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
* uinfo
)
2598 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2600 uinfo
->value
.integer
.min
= 0;
2601 uinfo
->value
.integer
.max
= 255;
2605 static int snd_trident_vol_control_get(snd_kcontrol_t
* kcontrol
,
2606 snd_ctl_elem_value_t
* ucontrol
)
2608 trident_t
*trident
= snd_kcontrol_chip(kcontrol
);
2611 val
= trident
->musicvol_wavevol
;
2612 ucontrol
->value
.integer
.value
[0] = 255 - ((val
>> kcontrol
->private_value
) & 0xff);
2613 ucontrol
->value
.integer
.value
[1] = 255 - ((val
>> (kcontrol
->private_value
+ 8)) & 0xff);
2617 static int snd_trident_vol_control_put(snd_kcontrol_t
* kcontrol
,
2618 snd_ctl_elem_value_t
* ucontrol
)
2620 trident_t
*trident
= snd_kcontrol_chip(kcontrol
);
2624 spin_lock_irq(&trident
->reg_lock
);
2625 val
= trident
->musicvol_wavevol
;
2626 val
&= ~(0xffff << kcontrol
->private_value
);
2627 val
|= ((255 - (ucontrol
->value
.integer
.value
[0] & 0xff)) |
2628 ((255 - (ucontrol
->value
.integer
.value
[1] & 0xff)) << 8)) << kcontrol
->private_value
;
2629 change
= val
!= trident
->musicvol_wavevol
;
2630 outl(trident
->musicvol_wavevol
= val
, TRID_REG(trident
, T4D_MUSICVOL_WAVEVOL
));
2631 spin_unlock_irq(&trident
->reg_lock
);
2635 static snd_kcontrol_new_t snd_trident_vol_music_control __devinitdata
=
2637 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2638 .name
= "Music Playback Volume",
2639 .info
= snd_trident_vol_control_info
,
2640 .get
= snd_trident_vol_control_get
,
2641 .put
= snd_trident_vol_control_put
,
2642 .private_value
= 16,
2645 static snd_kcontrol_new_t snd_trident_vol_wave_control __devinitdata
=
2647 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2648 .name
= "Wave Playback Volume",
2649 .info
= snd_trident_vol_control_info
,
2650 .get
= snd_trident_vol_control_get
,
2651 .put
= snd_trident_vol_control_put
,
2655 /*---------------------------------------------------------------------------
2656 snd_trident_pcm_vol_control
2658 Description: PCM front volume control
2659 ---------------------------------------------------------------------------*/
2661 static int snd_trident_pcm_vol_control_info(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
* uinfo
)
2663 trident_t
*trident
= snd_kcontrol_chip(kcontrol
);
2665 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2667 uinfo
->value
.integer
.min
= 0;
2668 uinfo
->value
.integer
.max
= 255;
2669 if (trident
->device
== TRIDENT_DEVICE_ID_SI7018
)
2670 uinfo
->value
.integer
.max
= 1023;
2674 static int snd_trident_pcm_vol_control_get(snd_kcontrol_t
* kcontrol
,
2675 snd_ctl_elem_value_t
* ucontrol
)
2677 trident_t
*trident
= snd_kcontrol_chip(kcontrol
);
2678 snd_trident_pcm_mixer_t
*mix
= &trident
->pcm_mixer
[snd_ctl_get_ioffnum(kcontrol
, &ucontrol
->id
)];
2680 if (trident
->device
== TRIDENT_DEVICE_ID_SI7018
) {
2681 ucontrol
->value
.integer
.value
[0] = 1023 - mix
->vol
;
2683 ucontrol
->value
.integer
.value
[0] = 255 - (mix
->vol
>>2);
2688 static int snd_trident_pcm_vol_control_put(snd_kcontrol_t
* kcontrol
,
2689 snd_ctl_elem_value_t
* ucontrol
)
2691 trident_t
*trident
= snd_kcontrol_chip(kcontrol
);
2692 snd_trident_pcm_mixer_t
*mix
= &trident
->pcm_mixer
[snd_ctl_get_ioffnum(kcontrol
, &ucontrol
->id
)];
2696 if (trident
->device
== TRIDENT_DEVICE_ID_SI7018
) {
2697 val
= 1023 - (ucontrol
->value
.integer
.value
[0] & 1023);
2699 val
= (255 - (ucontrol
->value
.integer
.value
[0] & 255)) << 2;
2701 spin_lock_irq(&trident
->reg_lock
);
2702 change
= val
!= mix
->vol
;
2704 if (mix
->voice
!= NULL
)
2705 snd_trident_write_vol_reg(trident
, mix
->voice
, val
);
2706 spin_unlock_irq(&trident
->reg_lock
);
2710 static snd_kcontrol_new_t snd_trident_pcm_vol_control __devinitdata
=
2712 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2713 .name
= "PCM Front Playback Volume",
2714 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
| SNDRV_CTL_ELEM_ACCESS_INACTIVE
,
2716 .info
= snd_trident_pcm_vol_control_info
,
2717 .get
= snd_trident_pcm_vol_control_get
,
2718 .put
= snd_trident_pcm_vol_control_put
,
2721 /*---------------------------------------------------------------------------
2722 snd_trident_pcm_pan_control
2724 Description: PCM front pan control
2725 ---------------------------------------------------------------------------*/
2727 static int snd_trident_pcm_pan_control_info(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
* uinfo
)
2729 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2731 uinfo
->value
.integer
.min
= 0;
2732 uinfo
->value
.integer
.max
= 127;
2736 static int snd_trident_pcm_pan_control_get(snd_kcontrol_t
* kcontrol
,
2737 snd_ctl_elem_value_t
* ucontrol
)
2739 trident_t
*trident
= snd_kcontrol_chip(kcontrol
);
2740 snd_trident_pcm_mixer_t
*mix
= &trident
->pcm_mixer
[snd_ctl_get_ioffnum(kcontrol
, &ucontrol
->id
)];
2742 ucontrol
->value
.integer
.value
[0] = mix
->pan
;
2743 if (ucontrol
->value
.integer
.value
[0] & 0x40) {
2744 ucontrol
->value
.integer
.value
[0] = (0x3f - (ucontrol
->value
.integer
.value
[0] & 0x3f));
2746 ucontrol
->value
.integer
.value
[0] |= 0x40;
2751 static int snd_trident_pcm_pan_control_put(snd_kcontrol_t
* kcontrol
,
2752 snd_ctl_elem_value_t
* ucontrol
)
2754 trident_t
*trident
= snd_kcontrol_chip(kcontrol
);
2755 snd_trident_pcm_mixer_t
*mix
= &trident
->pcm_mixer
[snd_ctl_get_ioffnum(kcontrol
, &ucontrol
->id
)];
2759 if (ucontrol
->value
.integer
.value
[0] & 0x40)
2760 val
= ucontrol
->value
.integer
.value
[0] & 0x3f;
2762 val
= (0x3f - (ucontrol
->value
.integer
.value
[0] & 0x3f)) | 0x40;
2763 spin_lock_irq(&trident
->reg_lock
);
2764 change
= val
!= mix
->pan
;
2766 if (mix
->voice
!= NULL
)
2767 snd_trident_write_pan_reg(trident
, mix
->voice
, val
);
2768 spin_unlock_irq(&trident
->reg_lock
);
2772 static snd_kcontrol_new_t snd_trident_pcm_pan_control __devinitdata
=
2774 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2775 .name
= "PCM Pan Playback Control",
2776 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
| SNDRV_CTL_ELEM_ACCESS_INACTIVE
,
2778 .info
= snd_trident_pcm_pan_control_info
,
2779 .get
= snd_trident_pcm_pan_control_get
,
2780 .put
= snd_trident_pcm_pan_control_put
,
2783 /*---------------------------------------------------------------------------
2784 snd_trident_pcm_rvol_control
2786 Description: PCM reverb volume control
2787 ---------------------------------------------------------------------------*/
2789 static int snd_trident_pcm_rvol_control_info(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
* uinfo
)
2791 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2793 uinfo
->value
.integer
.min
= 0;
2794 uinfo
->value
.integer
.max
= 127;
2798 static int snd_trident_pcm_rvol_control_get(snd_kcontrol_t
* kcontrol
,
2799 snd_ctl_elem_value_t
* ucontrol
)
2801 trident_t
*trident
= snd_kcontrol_chip(kcontrol
);
2802 snd_trident_pcm_mixer_t
*mix
= &trident
->pcm_mixer
[snd_ctl_get_ioffnum(kcontrol
, &ucontrol
->id
)];
2804 ucontrol
->value
.integer
.value
[0] = 127 - mix
->rvol
;
2808 static int snd_trident_pcm_rvol_control_put(snd_kcontrol_t
* kcontrol
,
2809 snd_ctl_elem_value_t
* ucontrol
)
2811 trident_t
*trident
= snd_kcontrol_chip(kcontrol
);
2812 snd_trident_pcm_mixer_t
*mix
= &trident
->pcm_mixer
[snd_ctl_get_ioffnum(kcontrol
, &ucontrol
->id
)];
2816 val
= 0x7f - (ucontrol
->value
.integer
.value
[0] & 0x7f);
2817 spin_lock_irq(&trident
->reg_lock
);
2818 change
= val
!= mix
->rvol
;
2820 if (mix
->voice
!= NULL
)
2821 snd_trident_write_rvol_reg(trident
, mix
->voice
, val
);
2822 spin_unlock_irq(&trident
->reg_lock
);
2826 static snd_kcontrol_new_t snd_trident_pcm_rvol_control __devinitdata
=
2828 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2829 .name
= "PCM Reverb Playback Volume",
2830 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
| SNDRV_CTL_ELEM_ACCESS_INACTIVE
,
2832 .info
= snd_trident_pcm_rvol_control_info
,
2833 .get
= snd_trident_pcm_rvol_control_get
,
2834 .put
= snd_trident_pcm_rvol_control_put
,
2837 /*---------------------------------------------------------------------------
2838 snd_trident_pcm_cvol_control
2840 Description: PCM chorus volume control
2841 ---------------------------------------------------------------------------*/
2843 static int snd_trident_pcm_cvol_control_info(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
* uinfo
)
2845 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2847 uinfo
->value
.integer
.min
= 0;
2848 uinfo
->value
.integer
.max
= 127;
2852 static int snd_trident_pcm_cvol_control_get(snd_kcontrol_t
* kcontrol
,
2853 snd_ctl_elem_value_t
* ucontrol
)
2855 trident_t
*trident
= snd_kcontrol_chip(kcontrol
);
2856 snd_trident_pcm_mixer_t
*mix
= &trident
->pcm_mixer
[snd_ctl_get_ioffnum(kcontrol
, &ucontrol
->id
)];
2858 ucontrol
->value
.integer
.value
[0] = 127 - mix
->cvol
;
2862 static int snd_trident_pcm_cvol_control_put(snd_kcontrol_t
* kcontrol
,
2863 snd_ctl_elem_value_t
* ucontrol
)
2865 trident_t
*trident
= snd_kcontrol_chip(kcontrol
);
2866 snd_trident_pcm_mixer_t
*mix
= &trident
->pcm_mixer
[snd_ctl_get_ioffnum(kcontrol
, &ucontrol
->id
)];
2870 val
= 0x7f - (ucontrol
->value
.integer
.value
[0] & 0x7f);
2871 spin_lock_irq(&trident
->reg_lock
);
2872 change
= val
!= mix
->cvol
;
2874 if (mix
->voice
!= NULL
)
2875 snd_trident_write_cvol_reg(trident
, mix
->voice
, val
);
2876 spin_unlock_irq(&trident
->reg_lock
);
2880 static snd_kcontrol_new_t snd_trident_pcm_cvol_control __devinitdata
=
2882 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2883 .name
= "PCM Chorus Playback Volume",
2884 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
| SNDRV_CTL_ELEM_ACCESS_INACTIVE
,
2886 .info
= snd_trident_pcm_cvol_control_info
,
2887 .get
= snd_trident_pcm_cvol_control_get
,
2888 .put
= snd_trident_pcm_cvol_control_put
,
2891 static void snd_trident_notify_pcm_change1(snd_card_t
* card
, snd_kcontrol_t
*kctl
, int num
, int activate
)
2893 snd_ctl_elem_id_t id
;
2895 snd_runtime_check(kctl
!= NULL
, return);
2897 kctl
->vd
[num
].access
&= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE
;
2899 kctl
->vd
[num
].access
|= SNDRV_CTL_ELEM_ACCESS_INACTIVE
;
2900 snd_ctl_notify(card
, SNDRV_CTL_EVENT_MASK_VALUE
|
2901 SNDRV_CTL_EVENT_MASK_INFO
,
2902 snd_ctl_build_ioff(&id
, kctl
, num
));
2905 static void snd_trident_notify_pcm_change(trident_t
*trident
, snd_trident_pcm_mixer_t
*tmix
, int num
, int activate
)
2907 snd_trident_notify_pcm_change1(trident
->card
, trident
->ctl_vol
, num
, activate
);
2908 snd_trident_notify_pcm_change1(trident
->card
, trident
->ctl_pan
, num
, activate
);
2909 snd_trident_notify_pcm_change1(trident
->card
, trident
->ctl_rvol
, num
, activate
);
2910 snd_trident_notify_pcm_change1(trident
->card
, trident
->ctl_cvol
, num
, activate
);
2913 static int snd_trident_pcm_mixer_build(trident_t
*trident
, snd_trident_voice_t
*voice
, snd_pcm_substream_t
*substream
)
2915 snd_trident_pcm_mixer_t
*tmix
;
2917 snd_assert(trident
!= NULL
&& voice
!= NULL
&& substream
!= NULL
, return -EINVAL
);
2918 tmix
= &trident
->pcm_mixer
[substream
->number
];
2919 tmix
->voice
= voice
;
2920 tmix
->vol
= T4D_DEFAULT_PCM_VOL
;
2921 tmix
->pan
= T4D_DEFAULT_PCM_PAN
;
2922 tmix
->rvol
= T4D_DEFAULT_PCM_RVOL
;
2923 tmix
->cvol
= T4D_DEFAULT_PCM_CVOL
;
2924 snd_trident_notify_pcm_change(trident
, tmix
, substream
->number
, 1);
2928 static int snd_trident_pcm_mixer_free(trident_t
*trident
, snd_trident_voice_t
*voice
, snd_pcm_substream_t
*substream
)
2930 snd_trident_pcm_mixer_t
*tmix
;
2932 snd_assert(trident
!= NULL
&& substream
!= NULL
, return -EINVAL
);
2933 tmix
= &trident
->pcm_mixer
[substream
->number
];
2935 snd_trident_notify_pcm_change(trident
, tmix
, substream
->number
, 0);
2939 /*---------------------------------------------------------------------------
2942 Description: This routine registers the 4DWave device for mixer support.
2944 Paramters: trident - pointer to target device class for 4DWave.
2948 ---------------------------------------------------------------------------*/
2950 static int __devinit
snd_trident_mixer(trident_t
* trident
, int pcm_spdif_device
)
2952 ac97_template_t _ac97
;
2953 snd_card_t
* card
= trident
->card
;
2954 snd_kcontrol_t
*kctl
;
2955 snd_ctl_elem_value_t
*uctl
;
2956 int idx
, err
, retries
= 2;
2957 static ac97_bus_ops_t ops
= {
2958 .write
= snd_trident_codec_write
,
2959 .read
= snd_trident_codec_read
,
2962 uctl
= kcalloc(1, sizeof(*uctl
), GFP_KERNEL
);
2966 if ((err
= snd_ac97_bus(trident
->card
, 0, &ops
, NULL
, &trident
->ac97_bus
)) < 0)
2969 memset(&_ac97
, 0, sizeof(_ac97
));
2970 _ac97
.private_data
= trident
;
2971 trident
->ac97_detect
= 1;
2974 if ((err
= snd_ac97_mixer(trident
->ac97_bus
, &_ac97
, &trident
->ac97
)) < 0) {
2975 if (trident
->device
== TRIDENT_DEVICE_ID_SI7018
) {
2976 if ((err
= snd_trident_sis_reset(trident
)) < 0)
2985 /* secondary codec? */
2986 if (trident
->device
== TRIDENT_DEVICE_ID_SI7018
&&
2987 (inl(TRID_REG(trident
, SI_SERIAL_INTF_CTRL
)) & SI_AC97_PRIMARY_READY
) != 0) {
2989 err
= snd_ac97_mixer(trident
->ac97_bus
, &_ac97
, &trident
->ac97_sec
);
2991 snd_printk("SI7018: the secondary codec - invalid access\n");
2992 #if 0 // only for my testing purpose --jk
2995 err
= snd_ac97_modem(trident
->card
, &_ac97
, &mc97
);
2997 snd_printk("snd_ac97_modem returned error %i\n", err
);
3002 trident
->ac97_detect
= 0;
3004 if (trident
->device
!= TRIDENT_DEVICE_ID_SI7018
) {
3005 if ((err
= snd_ctl_add(card
, kctl
= snd_ctl_new1(&snd_trident_vol_wave_control
, trident
))) < 0)
3007 kctl
->put(kctl
, uctl
);
3008 if ((err
= snd_ctl_add(card
, kctl
= snd_ctl_new1(&snd_trident_vol_music_control
, trident
))) < 0)
3010 kctl
->put(kctl
, uctl
);
3011 outl(trident
->musicvol_wavevol
= 0x00000000, TRID_REG(trident
, T4D_MUSICVOL_WAVEVOL
));
3013 outl(trident
->musicvol_wavevol
= 0xffff0000, TRID_REG(trident
, T4D_MUSICVOL_WAVEVOL
));
3016 for (idx
= 0; idx
< 32; idx
++) {
3017 snd_trident_pcm_mixer_t
*tmix
;
3019 tmix
= &trident
->pcm_mixer
[idx
];
3022 if ((trident
->ctl_vol
= snd_ctl_new1(&snd_trident_pcm_vol_control
, trident
)) == NULL
)
3024 if ((err
= snd_ctl_add(card
, trident
->ctl_vol
)))
3027 if ((trident
->ctl_pan
= snd_ctl_new1(&snd_trident_pcm_pan_control
, trident
)) == NULL
)
3029 if ((err
= snd_ctl_add(card
, trident
->ctl_pan
)))
3032 if ((trident
->ctl_rvol
= snd_ctl_new1(&snd_trident_pcm_rvol_control
, trident
)) == NULL
)
3034 if ((err
= snd_ctl_add(card
, trident
->ctl_rvol
)))
3037 if ((trident
->ctl_cvol
= snd_ctl_new1(&snd_trident_pcm_cvol_control
, trident
)) == NULL
)
3039 if ((err
= snd_ctl_add(card
, trident
->ctl_cvol
)))
3042 if (trident
->device
== TRIDENT_DEVICE_ID_NX
) {
3043 if ((err
= snd_ctl_add(card
, kctl
= snd_ctl_new1(&snd_trident_ac97_rear_control
, trident
))) < 0)
3045 kctl
->put(kctl
, uctl
);
3047 if (trident
->device
== TRIDENT_DEVICE_ID_NX
|| trident
->device
== TRIDENT_DEVICE_ID_SI7018
) {
3049 kctl
= snd_ctl_new1(&snd_trident_spdif_control
, trident
);
3054 if (trident
->ac97
->ext_id
& AC97_EI_SPDIF
)
3056 if (trident
->ac97_sec
&& (trident
->ac97_sec
->ext_id
& AC97_EI_SPDIF
))
3058 idx
= kctl
->id
.index
;
3059 if ((err
= snd_ctl_add(card
, kctl
)) < 0)
3061 kctl
->put(kctl
, uctl
);
3063 kctl
= snd_ctl_new1(&snd_trident_spdif_default
, trident
);
3068 kctl
->id
.index
= idx
;
3069 kctl
->id
.device
= pcm_spdif_device
;
3070 if ((err
= snd_ctl_add(card
, kctl
)) < 0)
3073 kctl
= snd_ctl_new1(&snd_trident_spdif_mask
, trident
);
3078 kctl
->id
.index
= idx
;
3079 kctl
->id
.device
= pcm_spdif_device
;
3080 if ((err
= snd_ctl_add(card
, kctl
)) < 0)
3083 kctl
= snd_ctl_new1(&snd_trident_spdif_stream
, trident
);
3088 kctl
->id
.index
= idx
;
3089 kctl
->id
.device
= pcm_spdif_device
;
3090 if ((err
= snd_ctl_add(card
, kctl
)) < 0)
3092 trident
->spdif_pcm_ctl
= kctl
;
3108 * gameport interface
3111 #if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))
3113 static unsigned char snd_trident_gameport_read(struct gameport
*gameport
)
3115 trident_t
*chip
= gameport_get_port_data(gameport
);
3117 snd_assert(chip
, return 0);
3118 return inb(TRID_REG(chip
, GAMEPORT_LEGACY
));
3121 static void snd_trident_gameport_trigger(struct gameport
*gameport
)
3123 trident_t
*chip
= gameport_get_port_data(gameport
);
3125 snd_assert(chip
, return);
3126 outb(0xff, TRID_REG(chip
, GAMEPORT_LEGACY
));
3129 static int snd_trident_gameport_cooked_read(struct gameport
*gameport
, int *axes
, int *buttons
)
3131 trident_t
*chip
= gameport_get_port_data(gameport
);
3134 snd_assert(chip
, return 0);
3136 *buttons
= (~inb(TRID_REG(chip
, GAMEPORT_LEGACY
)) >> 4) & 0xf;
3138 for (i
= 0; i
< 4; i
++) {
3139 axes
[i
] = inw(TRID_REG(chip
, GAMEPORT_AXES
+ i
* 2));
3140 if (axes
[i
] == 0xffff) axes
[i
] = -1;
3146 static int snd_trident_gameport_open(struct gameport
*gameport
, int mode
)
3148 trident_t
*chip
= gameport_get_port_data(gameport
);
3150 snd_assert(chip
, return 0);
3153 case GAMEPORT_MODE_COOKED
:
3154 outb(GAMEPORT_MODE_ADC
, TRID_REG(chip
, GAMEPORT_GCR
));
3155 set_current_state(TASK_UNINTERRUPTIBLE
);
3156 schedule_timeout(1 + 20 * HZ
/ 1000); /* 20msec */
3158 case GAMEPORT_MODE_RAW
:
3159 outb(0, TRID_REG(chip
, GAMEPORT_GCR
));
3166 int __devinit
snd_trident_create_gameport(trident_t
*chip
)
3168 struct gameport
*gp
;
3170 chip
->gameport
= gp
= gameport_allocate_port();
3172 printk(KERN_ERR
"trident: cannot allocate memory for gameport\n");
3176 gameport_set_name(gp
, "Trident 4DWave");
3177 gameport_set_phys(gp
, "pci%s/gameport0", pci_name(chip
->pci
));
3178 gameport_set_dev_parent(gp
, &chip
->pci
->dev
);
3180 gameport_set_port_data(gp
, chip
);
3182 gp
->read
= snd_trident_gameport_read
;
3183 gp
->trigger
= snd_trident_gameport_trigger
;
3184 gp
->cooked_read
= snd_trident_gameport_cooked_read
;
3185 gp
->open
= snd_trident_gameport_open
;
3187 gameport_register_port(gp
);
3192 static inline void snd_trident_free_gameport(trident_t
*chip
)
3194 if (chip
->gameport
) {
3195 gameport_unregister_port(chip
->gameport
);
3196 chip
->gameport
= NULL
;
3200 int __devinit
snd_trident_create_gameport(trident_t
*chip
) { return -ENOSYS
; }
3201 static inline void snd_trident_free_gameport(trident_t
*chip
) { }
3202 #endif /* CONFIG_GAMEPORT */
3207 inline static void do_delay(trident_t
*chip
)
3209 set_current_state(TASK_UNINTERRUPTIBLE
);
3210 schedule_timeout(1);
3217 static int snd_trident_sis_reset(trident_t
*trident
)
3219 unsigned long end_time
;
3223 r
= trident
->in_suspend
? 0 : 2; /* count of retries */
3225 pci_write_config_byte(trident
->pci
, 0x46, 0x04); /* SOFTWARE RESET */
3227 pci_write_config_byte(trident
->pci
, 0x46, 0x00);
3229 /* disable AC97 GPIO interrupt */
3230 outb(0x00, TRID_REG(trident
, SI_AC97_GPIO
));
3231 /* initialize serial interface, force cold reset */
3232 i
= PCMOUT
|SURROUT
|CENTEROUT
|LFEOUT
|SECONDARY_ID
|COLD_RESET
;
3233 outl(i
, TRID_REG(trident
, SI_SERIAL_INTF_CTRL
));
3235 /* remove cold reset */
3237 outl(i
, TRID_REG(trident
, SI_SERIAL_INTF_CTRL
));
3239 /* wait, until the codec is ready */
3240 end_time
= (jiffies
+ (HZ
* 3) / 4) + 1;
3242 if ((inl(TRID_REG(trident
, SI_SERIAL_INTF_CTRL
)) & SI_AC97_PRIMARY_READY
) != 0)
3245 } while (time_after_eq(end_time
, jiffies
));
3246 snd_printk("AC'97 codec ready error [0x%x]\n", inl(TRID_REG(trident
, SI_SERIAL_INTF_CTRL
)));
3248 end_time
= jiffies
+ HZ
;
3251 } while (time_after_eq(end_time
, jiffies
));
3252 goto __si7018_retry
;
3255 /* wait for the second codec */
3257 if ((inl(TRID_REG(trident
, SI_SERIAL_INTF_CTRL
)) & SI_AC97_SECONDARY_READY
) != 0)
3260 } while (time_after_eq(end_time
, jiffies
));
3261 /* enable 64 channel mode */
3262 outl(BANK_B_EN
, TRID_REG(trident
, T4D_LFO_GC_CIR
));
3270 static void snd_trident_proc_read(snd_info_entry_t
*entry
,
3271 snd_info_buffer_t
* buffer
)
3273 trident_t
*trident
= entry
->private_data
;
3276 switch (trident
->device
) {
3277 case TRIDENT_DEVICE_ID_SI7018
:
3278 s
= "SiS 7018 Audio";
3280 case TRIDENT_DEVICE_ID_DX
:
3281 s
= "Trident 4DWave PCI DX";
3283 case TRIDENT_DEVICE_ID_NX
:
3284 s
= "Trident 4DWave PCI NX";
3289 snd_iprintf(buffer
, "%s\n\n", s
);
3290 snd_iprintf(buffer
, "Spurious IRQs : %d\n", trident
->spurious_irq_count
);
3291 snd_iprintf(buffer
, "Spurious IRQ dlta: %d\n", trident
->spurious_irq_max_delta
);
3292 if (trident
->device
== TRIDENT_DEVICE_ID_NX
|| trident
->device
== TRIDENT_DEVICE_ID_SI7018
)
3293 snd_iprintf(buffer
, "IEC958 Mixer Out : %s\n", trident
->spdif_ctrl
== 0x28 ? "on" : "off");
3294 if (trident
->device
== TRIDENT_DEVICE_ID_NX
) {
3295 snd_iprintf(buffer
, "Rear Speakers : %s\n", trident
->ac97_ctrl
& 0x00000010 ? "on" : "off");
3296 if (trident
->tlb
.entries
) {
3297 snd_iprintf(buffer
,"\nVirtual Memory\n");
3298 snd_iprintf(buffer
, "Memory Maximum : %d\n", trident
->tlb
.memhdr
->size
);
3299 snd_iprintf(buffer
, "Memory Used : %d\n", trident
->tlb
.memhdr
->used
);
3300 snd_iprintf(buffer
, "Memory Free : %d\n", snd_util_mem_avail(trident
->tlb
.memhdr
));
3303 #if defined(CONFIG_SND_SEQUENCER) || (defined(MODULE) && defined(CONFIG_SND_SEQUENCER_MODULE))
3304 snd_iprintf(buffer
,"\nWavetable Synth\n");
3305 snd_iprintf(buffer
, "Memory Maximum : %d\n", trident
->synth
.max_size
);
3306 snd_iprintf(buffer
, "Memory Used : %d\n", trident
->synth
.current_size
);
3307 snd_iprintf(buffer
, "Memory Free : %d\n", (trident
->synth
.max_size
-trident
->synth
.current_size
));
3311 static void __devinit
snd_trident_proc_init(trident_t
* trident
)
3313 snd_info_entry_t
*entry
;
3314 const char *s
= "trident";
3316 if (trident
->device
== TRIDENT_DEVICE_ID_SI7018
)
3318 if (! snd_card_proc_new(trident
->card
, s
, &entry
))
3319 snd_info_set_text_ops(entry
, trident
, 1024, snd_trident_proc_read
);
3322 static int snd_trident_dev_free(snd_device_t
*device
)
3324 trident_t
*trident
= device
->device_data
;
3325 return snd_trident_free(trident
);
3328 /*---------------------------------------------------------------------------
3329 snd_trident_tlb_alloc
3331 Description: Allocate and set up the TLB page table on 4D NX.
3332 Each entry has 4 bytes (physical PCI address).
3334 Paramters: trident - pointer to target device class for 4DWave.
3336 Returns: 0 or negative error code
3338 ---------------------------------------------------------------------------*/
3340 static int __devinit
snd_trident_tlb_alloc(trident_t
*trident
)
3344 /* TLB array must be aligned to 16kB !!! so we allocate
3345 32kB region and correct offset when necessary */
3347 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV
, snd_dma_pci_data(trident
->pci
),
3348 2 * SNDRV_TRIDENT_MAX_PAGES
* 4, &trident
->tlb
.buffer
) < 0) {
3349 snd_printk(KERN_ERR
"trident: unable to allocate TLB buffer\n");
3352 trident
->tlb
.entries
= (unsigned int*)(((unsigned long)trident
->tlb
.buffer
.area
+ SNDRV_TRIDENT_MAX_PAGES
* 4 - 1) & ~(SNDRV_TRIDENT_MAX_PAGES
* 4 - 1));
3353 trident
->tlb
.entries_dmaaddr
= (trident
->tlb
.buffer
.addr
+ SNDRV_TRIDENT_MAX_PAGES
* 4 - 1) & ~(SNDRV_TRIDENT_MAX_PAGES
* 4 - 1);
3354 /* allocate shadow TLB page table (virtual addresses) */
3355 trident
->tlb
.shadow_entries
= (unsigned long *)vmalloc(SNDRV_TRIDENT_MAX_PAGES
*sizeof(unsigned long));
3356 if (trident
->tlb
.shadow_entries
== NULL
) {
3357 snd_printk(KERN_ERR
"trident: unable to allocate shadow TLB entries\n");
3360 /* allocate and setup silent page and initialise TLB entries */
3361 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV
, snd_dma_pci_data(trident
->pci
),
3362 SNDRV_TRIDENT_PAGE_SIZE
, &trident
->tlb
.silent_page
) < 0) {
3363 snd_printk(KERN_ERR
"trident: unable to allocate silent page\n");
3366 memset(trident
->tlb
.silent_page
.area
, 0, SNDRV_TRIDENT_PAGE_SIZE
);
3367 for (i
= 0; i
< SNDRV_TRIDENT_MAX_PAGES
; i
++) {
3368 trident
->tlb
.entries
[i
] = cpu_to_le32(trident
->tlb
.silent_page
.addr
& ~(SNDRV_TRIDENT_PAGE_SIZE
-1));
3369 trident
->tlb
.shadow_entries
[i
] = (unsigned long)trident
->tlb
.silent_page
.area
;
3372 /* use emu memory block manager code to manage tlb page allocation */
3373 trident
->tlb
.memhdr
= snd_util_memhdr_new(SNDRV_TRIDENT_PAGE_SIZE
* SNDRV_TRIDENT_MAX_PAGES
);
3374 if (trident
->tlb
.memhdr
== NULL
)
3377 trident
->tlb
.memhdr
->block_extra_size
= sizeof(snd_trident_memblk_arg_t
);
3382 * initialize 4D DX chip
3385 static void snd_trident_stop_all_voices(trident_t
*trident
)
3387 outl(0xffffffff, TRID_REG(trident
, T4D_STOP_A
));
3388 outl(0xffffffff, TRID_REG(trident
, T4D_STOP_B
));
3389 outl(0, TRID_REG(trident
, T4D_AINTEN_A
));
3390 outl(0, TRID_REG(trident
, T4D_AINTEN_B
));
3393 static int snd_trident_4d_dx_init(trident_t
*trident
)
3395 struct pci_dev
*pci
= trident
->pci
;
3396 unsigned long end_time
;
3398 /* reset the legacy configuration and whole audio/wavetable block */
3399 pci_write_config_dword(pci
, 0x40, 0); /* DDMA */
3400 pci_write_config_byte(pci
, 0x44, 0); /* ports */
3401 pci_write_config_byte(pci
, 0x45, 0); /* Legacy DMA */
3402 pci_write_config_byte(pci
, 0x46, 4); /* reset */
3404 pci_write_config_byte(pci
, 0x46, 0); /* release reset */
3407 /* warm reset of the AC'97 codec */
3408 outl(0x00000001, TRID_REG(trident
, DX_ACR2_AC97_COM_STAT
));
3410 outl(0x00000000, TRID_REG(trident
, DX_ACR2_AC97_COM_STAT
));
3411 /* DAC on, disable SB IRQ and try to force ADC valid signal */
3412 trident
->ac97_ctrl
= 0x0000004a;
3413 outl(trident
->ac97_ctrl
, TRID_REG(trident
, DX_ACR2_AC97_COM_STAT
));
3414 /* wait, until the codec is ready */
3415 end_time
= (jiffies
+ (HZ
* 3) / 4) + 1;
3417 if ((inl(TRID_REG(trident
, DX_ACR2_AC97_COM_STAT
)) & 0x0010) != 0)
3420 } while (time_after_eq(end_time
, jiffies
));
3421 snd_printk(KERN_ERR
"AC'97 codec ready error\n");
3425 snd_trident_stop_all_voices(trident
);
3431 * initialize 4D NX chip
3433 static int snd_trident_4d_nx_init(trident_t
*trident
)
3435 struct pci_dev
*pci
= trident
->pci
;
3436 unsigned long end_time
;
3438 /* reset the legacy configuration and whole audio/wavetable block */
3439 pci_write_config_dword(pci
, 0x40, 0); /* DDMA */
3440 pci_write_config_byte(pci
, 0x44, 0); /* ports */
3441 pci_write_config_byte(pci
, 0x45, 0); /* Legacy DMA */
3443 pci_write_config_byte(pci
, 0x46, 1); /* reset */
3445 pci_write_config_byte(pci
, 0x46, 0); /* release reset */
3448 /* warm reset of the AC'97 codec */
3449 outl(0x00000001, TRID_REG(trident
, NX_ACR0_AC97_COM_STAT
));
3451 outl(0x00000000, TRID_REG(trident
, NX_ACR0_AC97_COM_STAT
));
3452 /* wait, until the codec is ready */
3453 end_time
= (jiffies
+ (HZ
* 3) / 4) + 1;
3455 if ((inl(TRID_REG(trident
, NX_ACR0_AC97_COM_STAT
)) & 0x0008) != 0)
3458 } while (time_after_eq(end_time
, jiffies
));
3459 snd_printk(KERN_ERR
"AC'97 codec ready error [0x%x]\n", inl(TRID_REG(trident
, NX_ACR0_AC97_COM_STAT
)));
3464 trident
->ac97_ctrl
= 0x00000002;
3465 outl(trident
->ac97_ctrl
, TRID_REG(trident
, NX_ACR0_AC97_COM_STAT
));
3466 /* disable SB IRQ */
3467 outl(NX_SB_IRQ_DISABLE
, TRID_REG(trident
, T4D_MISCINT
));
3469 snd_trident_stop_all_voices(trident
);
3471 if (trident
->tlb
.entries
!= NULL
) {
3473 /* enable virtual addressing via TLB */
3474 i
= trident
->tlb
.entries_dmaaddr
;
3476 outl(i
, TRID_REG(trident
, NX_TLBC
));
3478 outl(0, TRID_REG(trident
, NX_TLBC
));
3480 /* initialize S/PDIF */
3481 outl(trident
->spdif_bits
, TRID_REG(trident
, NX_SPCSTATUS
));
3482 outb(trident
->spdif_ctrl
, TRID_REG(trident
, NX_SPCTRL_SPCSO
+ 3));
3488 * initialize sis7018 chip
3490 static int snd_trident_sis_init(trident_t
*trident
)
3494 if ((err
= snd_trident_sis_reset(trident
)) < 0)
3497 snd_trident_stop_all_voices(trident
);
3499 /* initialize S/PDIF */
3500 outl(trident
->spdif_bits
, TRID_REG(trident
, SI_SPDIF_CS
));
3505 /*---------------------------------------------------------------------------
3508 Description: This routine will create the device specific class for
3509 the 4DWave card. It will also perform basic initialization.
3511 Paramters: card - which card to create
3512 pci - interface to PCI bus resource info
3513 dma1ptr - playback dma buffer
3514 dma2ptr - capture dma buffer
3515 irqptr - interrupt resource info
3517 Returns: 4DWave device class private data
3519 ---------------------------------------------------------------------------*/
3521 int __devinit
snd_trident_create(snd_card_t
* card
,
3522 struct pci_dev
*pci
,
3524 int pcm_spdif_device
,
3525 int max_wavetable_size
,
3526 trident_t
** rtrident
)
3530 snd_trident_voice_t
*voice
;
3531 snd_trident_pcm_mixer_t
*tmix
;
3532 static snd_device_ops_t ops
= {
3533 .dev_free
= snd_trident_dev_free
,
3538 /* enable PCI device */
3539 if ((err
= pci_enable_device(pci
)) < 0)
3541 /* check, if we can restrict PCI DMA transfers to 30 bits */
3542 if (pci_set_dma_mask(pci
, 0x3fffffff) < 0 ||
3543 pci_set_consistent_dma_mask(pci
, 0x3fffffff) < 0) {
3544 snd_printk("architecture does not support 30bit PCI busmaster DMA\n");
3545 pci_disable_device(pci
);
3549 trident
= kcalloc(1, sizeof(*trident
), GFP_KERNEL
);
3550 if (trident
== NULL
) {
3551 pci_disable_device(pci
);
3554 trident
->device
= (pci
->vendor
<< 16) | pci
->device
;
3555 trident
->card
= card
;
3557 spin_lock_init(&trident
->reg_lock
);
3558 spin_lock_init(&trident
->event_lock
);
3559 spin_lock_init(&trident
->voice_alloc
);
3560 if (pcm_streams
< 1)
3562 if (pcm_streams
> 32)
3564 trident
->ChanPCM
= pcm_streams
;
3565 if (max_wavetable_size
< 0 )
3566 max_wavetable_size
= 0;
3567 trident
->synth
.max_size
= max_wavetable_size
* 1024;
3570 trident
->midi_port
= TRID_REG(trident
, T4D_MPU401_BASE
);
3571 pci_set_master(pci
);
3573 if ((err
= pci_request_regions(pci
, "Trident Audio")) < 0) {
3575 pci_disable_device(pci
);
3578 trident
->port
= pci_resource_start(pci
, 0);
3580 if (request_irq(pci
->irq
, snd_trident_interrupt
, SA_INTERRUPT
|SA_SHIRQ
, "Trident Audio", (void *) trident
)) {
3581 snd_printk("unable to grab IRQ %d\n", pci
->irq
);
3582 snd_trident_free(trident
);
3585 trident
->irq
= pci
->irq
;
3587 /* allocate 16k-aligned TLB for NX cards */
3588 trident
->tlb
.entries
= NULL
;
3589 trident
->tlb
.buffer
.area
= NULL
;
3590 if (trident
->device
== TRIDENT_DEVICE_ID_NX
) {
3591 if ((err
= snd_trident_tlb_alloc(trident
)) < 0) {
3592 snd_trident_free(trident
);
3597 trident
->spdif_bits
= trident
->spdif_pcm_bits
= SNDRV_PCM_DEFAULT_CON_SPDIF
;
3599 /* initialize chip */
3600 switch (trident
->device
) {
3601 case TRIDENT_DEVICE_ID_DX
:
3602 err
= snd_trident_4d_dx_init(trident
);
3604 case TRIDENT_DEVICE_ID_NX
:
3605 err
= snd_trident_4d_nx_init(trident
);
3607 case TRIDENT_DEVICE_ID_SI7018
:
3608 err
= snd_trident_sis_init(trident
);
3615 snd_trident_free(trident
);
3619 if ((err
= snd_device_new(card
, SNDRV_DEV_LOWLEVEL
, trident
, &ops
)) < 0) {
3620 snd_trident_free(trident
);
3624 if ((err
= snd_trident_mixer(trident
, pcm_spdif_device
)) < 0)
3627 /* initialise synth voices */
3628 for (i
= 0; i
< 64; i
++) {
3629 voice
= &trident
->synth
.voices
[i
];
3631 voice
->trident
= trident
;
3633 /* initialize pcm mixer entries */
3634 for (i
= 0; i
< 32; i
++) {
3635 tmix
= &trident
->pcm_mixer
[i
];
3636 tmix
->vol
= T4D_DEFAULT_PCM_VOL
;
3637 tmix
->pan
= T4D_DEFAULT_PCM_PAN
;
3638 tmix
->rvol
= T4D_DEFAULT_PCM_RVOL
;
3639 tmix
->cvol
= T4D_DEFAULT_PCM_CVOL
;
3642 snd_trident_enable_eso(trident
);
3645 snd_card_set_pm_callback(card
, snd_trident_suspend
, snd_trident_resume
, trident
);
3646 snd_trident_proc_init(trident
);
3647 snd_card_set_dev(card
, &pci
->dev
);
3648 *rtrident
= trident
;
3652 /*---------------------------------------------------------------------------
3655 Description: This routine will free the device specific class for
3658 Paramters: trident - device specific private data for 4DWave card
3662 ---------------------------------------------------------------------------*/
3664 static int snd_trident_free(trident_t
*trident
)
3666 snd_trident_free_gameport(trident
);
3667 snd_trident_disable_eso(trident
);
3668 // Disable S/PDIF out
3669 if (trident
->device
== TRIDENT_DEVICE_ID_NX
)
3670 outb(0x00, TRID_REG(trident
, NX_SPCTRL_SPCSO
+ 3));
3671 else if (trident
->device
== TRIDENT_DEVICE_ID_SI7018
) {
3672 outl(0, TRID_REG(trident
, SI_SERIAL_INTF_CTRL
));
3674 if (trident
->tlb
.buffer
.area
) {
3675 outl(0, TRID_REG(trident
, NX_TLBC
));
3676 if (trident
->tlb
.memhdr
)
3677 snd_util_memhdr_free(trident
->tlb
.memhdr
);
3678 if (trident
->tlb
.silent_page
.area
)
3679 snd_dma_free_pages(&trident
->tlb
.silent_page
);
3680 vfree(trident
->tlb
.shadow_entries
);
3681 snd_dma_free_pages(&trident
->tlb
.buffer
);
3683 if (trident
->irq
>= 0)
3684 free_irq(trident
->irq
, (void *)trident
);
3685 pci_release_regions(trident
->pci
);
3686 pci_disable_device(trident
->pci
);
3691 /*---------------------------------------------------------------------------
3692 snd_trident_interrupt
3694 Description: ISR for Trident 4DWave device
3696 Paramters: trident - device specific private data for 4DWave card
3698 Problems: It seems that Trident chips generates interrupts more than
3699 one time in special cases. The spurious interrupts are
3700 detected via sample timer (T4D_STIMER) and computing
3701 corresponding delta value. The limits are detected with
3702 the method try & fail so it is possible that it won't
3703 work on all computers. [jaroslav]
3707 ---------------------------------------------------------------------------*/
3709 static irqreturn_t
snd_trident_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
3711 trident_t
*trident
= dev_id
;
3712 unsigned int audio_int
, chn_int
, stimer
, channel
, mask
, tmp
;
3714 snd_trident_voice_t
*voice
;
3716 audio_int
= inl(TRID_REG(trident
, T4D_MISCINT
));
3717 if ((audio_int
& (ADDRESS_IRQ
|MPU401_IRQ
)) == 0)
3719 if (audio_int
& ADDRESS_IRQ
) {
3720 // get interrupt status for all channels
3721 spin_lock(&trident
->reg_lock
);
3722 stimer
= inl(TRID_REG(trident
, T4D_STIMER
)) & 0x00ffffff;
3723 chn_int
= inl(TRID_REG(trident
, T4D_AINT_A
));
3726 outl(chn_int
, TRID_REG(trident
, T4D_AINT_A
)); /* ack */
3728 chn_int
= inl(TRID_REG(trident
, T4D_AINT_B
));
3731 for (channel
= 63; channel
>= 32; channel
--) {
3732 mask
= 1 << (channel
&0x1f);
3733 if ((chn_int
& mask
) == 0)
3735 voice
= &trident
->synth
.voices
[channel
];
3736 if (!voice
->pcm
|| voice
->substream
== NULL
) {
3737 outl(mask
, TRID_REG(trident
, T4D_STOP_B
));
3740 delta
= (int)stimer
- (int)voice
->stimer
;
3743 if ((unsigned int)delta
< voice
->spurious_threshold
) {
3744 /* do some statistics here */
3745 trident
->spurious_irq_count
++;
3746 if (trident
->spurious_irq_max_delta
< (unsigned int)delta
)
3747 trident
->spurious_irq_max_delta
= delta
;
3750 voice
->stimer
= stimer
;
3752 if (!voice
->isync3
) {
3753 tmp
= inw(TRID_REG(trident
, T4D_SBBL_SBCL
));
3754 if (trident
->bDMAStart
& 0x40)
3757 tmp
= voice
->isync_max
- tmp
;
3759 tmp
= inl(TRID_REG(trident
, NX_SPCTRL_SPCSO
)) & 0x00ffffff;
3761 if (tmp
< voice
->isync_mark
) {
3763 tmp
= voice
->isync_ESO
- 7;
3765 tmp
= voice
->isync_ESO
+ 2;
3766 /* update ESO for IRQ voice to preserve sync */
3767 snd_trident_stop_voice(trident
, voice
->number
);
3768 snd_trident_write_eso_reg(trident
, voice
, tmp
);
3769 snd_trident_start_voice(trident
, voice
->number
);
3771 } else if (voice
->isync2
) {
3773 /* write original ESO and update CSO for IRQ voice to preserve sync */
3774 snd_trident_stop_voice(trident
, voice
->number
);
3775 snd_trident_write_cso_reg(trident
, voice
, voice
->isync_mark
);
3776 snd_trident_write_eso_reg(trident
, voice
, voice
->ESO
);
3777 snd_trident_start_voice(trident
, voice
->number
);
3781 /* update CSO for extra voice to preserve sync */
3782 snd_trident_stop_voice(trident
, voice
->extra
->number
);
3783 snd_trident_write_cso_reg(trident
, voice
->extra
, 0);
3784 snd_trident_start_voice(trident
, voice
->extra
->number
);
3787 spin_unlock(&trident
->reg_lock
);
3788 snd_pcm_period_elapsed(voice
->substream
);
3789 spin_lock(&trident
->reg_lock
);
3791 outl(chn_int
, TRID_REG(trident
, T4D_AINT_B
)); /* ack */
3793 spin_unlock(&trident
->reg_lock
);
3795 if (audio_int
& MPU401_IRQ
) {
3796 if (trident
->rmidi
) {
3797 snd_mpu401_uart_interrupt(irq
, trident
->rmidi
->private_data
, regs
);
3799 inb(TRID_REG(trident
, T4D_MPUR0
));
3802 // outl((ST_TARGET_REACHED | MIXER_OVERFLOW | MIXER_UNDERFLOW), TRID_REG(trident, T4D_MISCINT));
3806 /*---------------------------------------------------------------------------
3807 snd_trident_attach_synthesizer
3809 Description: Attach synthesizer hooks
3811 Paramters: trident - device specific private data for 4DWave card
3815 ---------------------------------------------------------------------------*/
3816 int snd_trident_attach_synthesizer(trident_t
*trident
)
3818 #if defined(CONFIG_SND_SEQUENCER) || (defined(MODULE) && defined(CONFIG_SND_SEQUENCER_MODULE))
3819 if (snd_seq_device_new(trident
->card
, 1, SNDRV_SEQ_DEV_ID_TRIDENT
,
3820 sizeof(trident_t
*), &trident
->seq_dev
) >= 0) {
3821 strcpy(trident
->seq_dev
->name
, "4DWave");
3822 *(trident_t
**)SNDRV_SEQ_DEVICE_ARGPTR(trident
->seq_dev
) = trident
;
3828 snd_trident_voice_t
*snd_trident_alloc_voice(trident_t
* trident
, int type
, int client
, int port
)
3830 snd_trident_voice_t
*pvoice
;
3831 unsigned long flags
;
3834 spin_lock_irqsave(&trident
->voice_alloc
, flags
);
3835 if (type
== SNDRV_TRIDENT_VOICE_TYPE_PCM
) {
3836 idx
= snd_trident_allocate_pcm_channel(trident
);
3838 spin_unlock_irqrestore(&trident
->voice_alloc
, flags
);
3841 pvoice
= &trident
->synth
.voices
[idx
];
3844 pvoice
->capture
= 0;
3846 pvoice
->memblk
= NULL
;
3847 pvoice
->substream
= NULL
;
3848 spin_unlock_irqrestore(&trident
->voice_alloc
, flags
);
3851 if (type
== SNDRV_TRIDENT_VOICE_TYPE_SYNTH
) {
3852 idx
= snd_trident_allocate_synth_channel(trident
);
3854 spin_unlock_irqrestore(&trident
->voice_alloc
, flags
);
3857 pvoice
= &trident
->synth
.voices
[idx
];
3860 pvoice
->client
= client
;
3861 pvoice
->port
= port
;
3862 pvoice
->memblk
= NULL
;
3863 spin_unlock_irqrestore(&trident
->voice_alloc
, flags
);
3866 if (type
== SNDRV_TRIDENT_VOICE_TYPE_MIDI
) {
3868 spin_unlock_irqrestore(&trident
->voice_alloc
, flags
);
3872 void snd_trident_free_voice(trident_t
* trident
, snd_trident_voice_t
*voice
)
3874 unsigned long flags
;
3875 void (*private_free
)(snd_trident_voice_t
*);
3878 if (voice
== NULL
|| !voice
->use
)
3880 snd_trident_clear_voices(trident
, voice
->number
, voice
->number
);
3881 spin_lock_irqsave(&trident
->voice_alloc
, flags
);
3882 private_free
= voice
->private_free
;
3883 private_data
= voice
->private_data
;
3884 voice
->private_free
= NULL
;
3885 voice
->private_data
= NULL
;
3887 snd_trident_free_pcm_channel(trident
, voice
->number
);
3889 snd_trident_free_synth_channel(trident
, voice
->number
);
3890 voice
->use
= voice
->pcm
= voice
->synth
= voice
->midi
= 0;
3891 voice
->capture
= voice
->spdif
= 0;
3892 voice
->sample_ops
= NULL
;
3893 voice
->substream
= NULL
;
3894 voice
->extra
= NULL
;
3895 spin_unlock_irqrestore(&trident
->voice_alloc
, flags
);
3897 private_free(voice
);
3900 static void snd_trident_clear_voices(trident_t
* trident
, unsigned short v_min
, unsigned short v_max
)
3902 unsigned int i
, val
, mask
[2] = { 0, 0 };
3904 snd_assert(v_min
<= 63, return);
3905 snd_assert(v_max
<= 63, return);
3906 for (i
= v_min
; i
<= v_max
; i
++)
3907 mask
[i
>> 5] |= 1 << (i
& 0x1f);
3909 outl(mask
[0], TRID_REG(trident
, T4D_STOP_A
));
3910 val
= inl(TRID_REG(trident
, T4D_AINTEN_A
));
3911 outl(val
& ~mask
[0], TRID_REG(trident
, T4D_AINTEN_A
));
3914 outl(mask
[1], TRID_REG(trident
, T4D_STOP_B
));
3915 val
= inl(TRID_REG(trident
, T4D_AINTEN_B
));
3916 outl(val
& ~mask
[1], TRID_REG(trident
, T4D_AINTEN_B
));
3921 static int snd_trident_suspend(snd_card_t
*card
, pm_message_t state
)
3923 trident_t
*trident
= card
->pm_private_data
;
3925 trident
->in_suspend
= 1;
3926 snd_pcm_suspend_all(trident
->pcm
);
3927 if (trident
->foldback
)
3928 snd_pcm_suspend_all(trident
->foldback
);
3930 snd_pcm_suspend_all(trident
->spdif
);
3932 snd_ac97_suspend(trident
->ac97
);
3933 if (trident
->ac97_sec
)
3934 snd_ac97_suspend(trident
->ac97_sec
);
3936 switch (trident
->device
) {
3937 case TRIDENT_DEVICE_ID_DX
:
3938 case TRIDENT_DEVICE_ID_NX
:
3940 case TRIDENT_DEVICE_ID_SI7018
:
3943 pci_disable_device(trident
->pci
);
3947 static int snd_trident_resume(snd_card_t
*card
)
3949 trident_t
*trident
= card
->pm_private_data
;
3951 pci_enable_device(trident
->pci
);
3952 if (pci_set_dma_mask(trident
->pci
, 0x3fffffff) < 0 ||
3953 pci_set_consistent_dma_mask(trident
->pci
, 0x3fffffff) < 0)
3954 snd_printk(KERN_WARNING
"trident: can't set the proper DMA mask\n");
3955 pci_set_master(trident
->pci
); /* to be sure */
3957 switch (trident
->device
) {
3958 case TRIDENT_DEVICE_ID_DX
:
3959 snd_trident_4d_dx_init(trident
);
3961 case TRIDENT_DEVICE_ID_NX
:
3962 snd_trident_4d_nx_init(trident
);
3964 case TRIDENT_DEVICE_ID_SI7018
:
3965 snd_trident_sis_init(trident
);
3969 snd_ac97_resume(trident
->ac97
);
3970 if (trident
->ac97_sec
)
3971 snd_ac97_resume(trident
->ac97_sec
);
3973 /* restore some registers */
3974 outl(trident
->musicvol_wavevol
, TRID_REG(trident
, T4D_MUSICVOL_WAVEVOL
));
3976 snd_trident_enable_eso(trident
);
3978 trident
->in_suspend
= 0;
3981 #endif /* CONFIG_PM */
3983 EXPORT_SYMBOL(snd_trident_alloc_voice
);
3984 EXPORT_SYMBOL(snd_trident_free_voice
);
3985 EXPORT_SYMBOL(snd_trident_start_voice
);
3986 EXPORT_SYMBOL(snd_trident_stop_voice
);
3987 EXPORT_SYMBOL(snd_trident_write_voice_regs
);
3988 /* trident_memory.c symbols */
3989 EXPORT_SYMBOL(snd_trident_synth_alloc
);
3990 EXPORT_SYMBOL(snd_trident_synth_free
);
3991 EXPORT_SYMBOL(snd_trident_synth_copy_from_user
);