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
, unsigned int state
);
52 static int snd_trident_resume(snd_card_t
*card
, unsigned int state
);
54 static int snd_trident_sis_reset(trident_t
*trident
);
62 static void snd_trident_print_voice_regs(trident_t
*trident
, int voice
)
64 unsigned int val
, tmp
;
66 printk("Trident voice %i:\n", voice
);
67 outb(voice
, TRID_REG(trident
, T4D_LFO_GC_CIR
));
68 val
= inl(TRID_REG(trident
, CH_LBA
));
69 printk("LBA: 0x%x\n", val
);
70 val
= inl(TRID_REG(trident
, CH_GVSEL_PAN_VOL_CTRL_EC
));
71 printk("GVSel: %i\n", val
>> 31);
72 printk("Pan: 0x%x\n", (val
>> 24) & 0x7f);
73 printk("Vol: 0x%x\n", (val
>> 16) & 0xff);
74 printk("CTRL: 0x%x\n", (val
>> 12) & 0x0f);
75 printk("EC: 0x%x\n", val
& 0x0fff);
76 if (trident
->device
!= TRIDENT_DEVICE_ID_NX
) {
77 val
= inl(TRID_REG(trident
, CH_DX_CSO_ALPHA_FMS
));
78 printk("CSO: 0x%x\n", val
>> 16);
79 printk("Alpha: 0x%x\n", (val
>> 4) & 0x0fff);
80 printk("FMS: 0x%x\n", val
& 0x0f);
81 val
= inl(TRID_REG(trident
, CH_DX_ESO_DELTA
));
82 printk("ESO: 0x%x\n", val
>> 16);
83 printk("Delta: 0x%x\n", val
& 0xffff);
84 val
= inl(TRID_REG(trident
, CH_DX_FMC_RVOL_CVOL
));
85 } else { // TRIDENT_DEVICE_ID_NX
86 val
= inl(TRID_REG(trident
, CH_NX_DELTA_CSO
));
87 tmp
= (val
>> 24) & 0xff;
88 printk("CSO: 0x%x\n", val
& 0x00ffffff);
89 val
= inl(TRID_REG(trident
, CH_NX_DELTA_ESO
));
90 tmp
|= (val
>> 16) & 0xff00;
91 printk("Delta: 0x%x\n", tmp
);
92 printk("ESO: 0x%x\n", val
& 0x00ffffff);
93 val
= inl(TRID_REG(trident
, CH_NX_ALPHA_FMS_FMC_RVOL_CVOL
));
94 printk("Alpha: 0x%x\n", val
>> 20);
95 printk("FMS: 0x%x\n", (val
>> 16) & 0x0f);
97 printk("FMC: 0x%x\n", (val
>> 14) & 3);
98 printk("RVol: 0x%x\n", (val
>> 7) & 0x7f);
99 printk("CVol: 0x%x\n", val
& 0x7f);
103 /*---------------------------------------------------------------------------
104 unsigned short snd_trident_codec_read(ac97_t *ac97, unsigned short reg)
106 Description: This routine will do all of the reading from the external
109 Parameters: ac97 - ac97 codec structure
110 reg - CODEC register index, from AC97 Hal.
112 returns: 16 bit value read from the AC97.
114 ---------------------------------------------------------------------------*/
115 static unsigned short snd_trident_codec_read(ac97_t
*ac97
, unsigned short reg
)
117 unsigned int data
= 0, treg
;
118 unsigned short count
= 0xffff;
120 trident_t
*trident
= ac97
->private_data
;
122 spin_lock_irqsave(&trident
->reg_lock
, flags
);
123 if (trident
->device
== TRIDENT_DEVICE_ID_DX
) {
124 data
= (DX_AC97_BUSY_READ
| (reg
& 0x000000ff));
125 outl(data
, TRID_REG(trident
, DX_ACR1_AC97_R
));
127 data
= inl(TRID_REG(trident
, DX_ACR1_AC97_R
));
128 if ((data
& DX_AC97_BUSY_READ
) == 0)
131 } else if (trident
->device
== TRIDENT_DEVICE_ID_NX
) {
132 data
= (NX_AC97_BUSY_READ
| (reg
& 0x000000ff));
133 treg
= ac97
->num
== 0 ? NX_ACR2_AC97_R_PRIMARY
: NX_ACR3_AC97_R_SECONDARY
;
134 outl(data
, TRID_REG(trident
, treg
));
136 data
= inl(TRID_REG(trident
, treg
));
137 if ((data
& 0x00000C00) == 0)
140 } else if (trident
->device
== TRIDENT_DEVICE_ID_SI7018
) {
141 data
= SI_AC97_BUSY_READ
| SI_AC97_AUDIO_BUSY
| (reg
& 0x000000ff);
143 data
|= SI_AC97_SECONDARY
;
144 outl(data
, TRID_REG(trident
, SI_AC97_READ
));
146 data
= inl(TRID_REG(trident
, SI_AC97_READ
));
147 if ((data
& (SI_AC97_BUSY_READ
)) == 0)
152 if (count
== 0 && !trident
->ac97_detect
) {
153 snd_printk("ac97 codec read TIMEOUT [0x%x/0x%x]!!!\n", reg
, data
);
157 spin_unlock_irqrestore(&trident
->reg_lock
, flags
);
158 return ((unsigned short) (data
>> 16));
161 /*---------------------------------------------------------------------------
162 void snd_trident_codec_write(ac97_t *ac97, unsigned short reg, unsigned short wdata)
164 Description: This routine will do all of the writing to the external
167 Parameters: ac97 - ac97 codec structure
168 reg - CODEC register index, from AC97 Hal.
169 data - Lower 16 bits are the data to write to CODEC.
171 returns: TRUE if everything went ok, else FALSE.
173 ---------------------------------------------------------------------------*/
174 static void snd_trident_codec_write(ac97_t
*ac97
, unsigned short reg
, unsigned short wdata
)
176 unsigned int address
, data
;
177 unsigned short count
= 0xffff;
179 trident_t
*trident
= ac97
->private_data
;
181 data
= ((unsigned long) wdata
) << 16;
183 spin_lock_irqsave(&trident
->reg_lock
, flags
);
184 if (trident
->device
== TRIDENT_DEVICE_ID_DX
) {
185 address
= DX_ACR0_AC97_W
;
187 /* read AC-97 write register status */
189 if ((inw(TRID_REG(trident
, address
)) & DX_AC97_BUSY_WRITE
) == 0)
193 data
|= (DX_AC97_BUSY_WRITE
| (reg
& 0x000000ff));
194 } else if (trident
->device
== TRIDENT_DEVICE_ID_NX
) {
195 address
= NX_ACR1_AC97_W
;
197 /* read AC-97 write register status */
199 if ((inw(TRID_REG(trident
, address
)) & NX_AC97_BUSY_WRITE
) == 0)
203 data
|= (NX_AC97_BUSY_WRITE
| (ac97
->num
<< 8) | (reg
& 0x000000ff));
204 } else if (trident
->device
== TRIDENT_DEVICE_ID_SI7018
) {
205 address
= SI_AC97_WRITE
;
207 /* read AC-97 write register status */
209 if ((inw(TRID_REG(trident
, address
)) & (SI_AC97_BUSY_WRITE
)) == 0)
213 data
|= SI_AC97_BUSY_WRITE
| SI_AC97_AUDIO_BUSY
| (reg
& 0x000000ff);
215 data
|= SI_AC97_SECONDARY
;
217 address
= 0; /* keep GCC happy */
218 count
= 0; /* return */
222 spin_unlock_irqrestore(&trident
->reg_lock
, flags
);
225 outl(data
, TRID_REG(trident
, address
));
226 spin_unlock_irqrestore(&trident
->reg_lock
, flags
);
229 /*---------------------------------------------------------------------------
230 void snd_trident_enable_eso(trident_t *trident)
232 Description: This routine will enable end of loop interrupts.
233 End of loop interrupts will occur when a running
235 Also enables middle of loop interrupts.
237 Parameters: trident - pointer to target device class for 4DWave.
239 ---------------------------------------------------------------------------*/
241 static void snd_trident_enable_eso(trident_t
* trident
)
245 val
= inl(TRID_REG(trident
, T4D_LFO_GC_CIR
));
248 if (trident
->device
== TRIDENT_DEVICE_ID_SI7018
)
250 outl(val
, TRID_REG(trident
, T4D_LFO_GC_CIR
));
253 /*---------------------------------------------------------------------------
254 void snd_trident_disable_eso(trident_t *trident)
256 Description: This routine will disable end of loop interrupts.
257 End of loop interrupts will occur when a running
259 Also disables middle of loop interrupts.
262 trident - pointer to target device class for 4DWave.
264 returns: TRUE if everything went ok, else FALSE.
266 ---------------------------------------------------------------------------*/
268 static void snd_trident_disable_eso(trident_t
* trident
)
272 tmp
= inl(TRID_REG(trident
, T4D_LFO_GC_CIR
));
275 outl(tmp
, TRID_REG(trident
, T4D_LFO_GC_CIR
));
278 /*---------------------------------------------------------------------------
279 void snd_trident_start_voice(trident_t * trident, unsigned int voice)
281 Description: Start a voice, any channel 0 thru 63.
282 This routine automatically handles the fact that there are
283 more than 32 channels available.
285 Parameters : voice - Voice number 0 thru n.
286 trident - pointer to target device class for 4DWave.
290 ---------------------------------------------------------------------------*/
292 void snd_trident_start_voice(trident_t
* trident
, unsigned int voice
)
294 unsigned int mask
= 1 << (voice
& 0x1f);
295 unsigned int reg
= (voice
& 0x20) ? T4D_START_B
: T4D_START_A
;
297 outl(mask
, TRID_REG(trident
, reg
));
300 /*---------------------------------------------------------------------------
301 void snd_trident_stop_voice(trident_t * trident, unsigned int voice)
303 Description: Stop a voice, any channel 0 thru 63.
304 This routine automatically handles the fact that there are
305 more than 32 channels available.
307 Parameters : voice - Voice number 0 thru n.
308 trident - pointer to target device class for 4DWave.
312 ---------------------------------------------------------------------------*/
314 void snd_trident_stop_voice(trident_t
* trident
, unsigned int voice
)
316 unsigned int mask
= 1 << (voice
& 0x1f);
317 unsigned int reg
= (voice
& 0x20) ? T4D_STOP_B
: T4D_STOP_A
;
319 outl(mask
, TRID_REG(trident
, reg
));
322 /*---------------------------------------------------------------------------
323 int snd_trident_allocate_pcm_channel(trident_t *trident)
325 Description: Allocate hardware channel in Bank B (32-63).
327 Parameters : trident - pointer to target device class for 4DWave.
329 Return Value: hardware channel - 32-63 or -1 when no channel is available
331 ---------------------------------------------------------------------------*/
333 static int snd_trident_allocate_pcm_channel(trident_t
* trident
)
337 if (trident
->ChanPCMcnt
>= trident
->ChanPCM
)
339 for (idx
= 31; idx
>= 0; idx
--) {
340 if (!(trident
->ChanMap
[T4D_BANK_B
] & (1 << idx
))) {
341 trident
->ChanMap
[T4D_BANK_B
] |= 1 << idx
;
342 trident
->ChanPCMcnt
++;
349 /*---------------------------------------------------------------------------
350 void snd_trident_free_pcm_channel(int channel)
352 Description: Free hardware channel in Bank B (32-63)
354 Parameters : trident - pointer to target device class for 4DWave.
355 channel - hardware channel number 0-63
359 ---------------------------------------------------------------------------*/
361 static void snd_trident_free_pcm_channel(trident_t
*trident
, int channel
)
363 if (channel
< 32 || channel
> 63)
366 if (trident
->ChanMap
[T4D_BANK_B
] & (1 << channel
)) {
367 trident
->ChanMap
[T4D_BANK_B
] &= ~(1 << channel
);
368 trident
->ChanPCMcnt
--;
372 /*---------------------------------------------------------------------------
373 unsigned int snd_trident_allocate_synth_channel(void)
375 Description: Allocate hardware channel in Bank A (0-31).
377 Parameters : trident - pointer to target device class for 4DWave.
379 Return Value: hardware channel - 0-31 or -1 when no channel is available
381 ---------------------------------------------------------------------------*/
383 static int snd_trident_allocate_synth_channel(trident_t
* trident
)
387 for (idx
= 31; idx
>= 0; idx
--) {
388 if (!(trident
->ChanMap
[T4D_BANK_A
] & (1 << idx
))) {
389 trident
->ChanMap
[T4D_BANK_A
] |= 1 << idx
;
390 trident
->synth
.ChanSynthCount
++;
397 /*---------------------------------------------------------------------------
398 void snd_trident_free_synth_channel( int channel )
400 Description: Free hardware channel in Bank B (0-31).
402 Parameters : trident - pointer to target device class for 4DWave.
403 channel - hardware channel number 0-63
407 ---------------------------------------------------------------------------*/
409 static void snd_trident_free_synth_channel(trident_t
*trident
, int channel
)
411 if (channel
< 0 || channel
> 31)
414 if (trident
->ChanMap
[T4D_BANK_A
] & (1 << channel
)) {
415 trident
->ChanMap
[T4D_BANK_A
] &= ~(1 << channel
);
416 trident
->synth
.ChanSynthCount
--;
420 /*---------------------------------------------------------------------------
421 snd_trident_write_voice_regs
423 Description: This routine will complete and write the 5 hardware channel
424 registers to hardware.
426 Paramters: trident - pointer to target device class for 4DWave.
427 voice - synthesizer voice structure
430 ---------------------------------------------------------------------------*/
432 void snd_trident_write_voice_regs(trident_t
* trident
,
433 snd_trident_voice_t
* voice
)
435 unsigned int FmcRvolCvol
;
436 unsigned int regs
[5];
438 regs
[1] = voice
->LBA
;
439 regs
[4] = (voice
->GVSel
<< 31) |
440 ((voice
->Pan
& 0x0000007f) << 24) |
441 ((voice
->CTRL
& 0x0000000f) << 12);
442 FmcRvolCvol
= ((voice
->FMC
& 3) << 14) |
443 ((voice
->RVol
& 0x7f) << 7) |
444 (voice
->CVol
& 0x7f);
446 switch (trident
->device
) {
447 case TRIDENT_DEVICE_ID_SI7018
:
448 regs
[4] |= voice
->number
> 31 ?
449 (voice
->Vol
& 0x000003ff) :
450 ((voice
->Vol
& 0x00003fc) << (16-2)) |
451 (voice
->EC
& 0x00000fff);
452 regs
[0] = (voice
->CSO
<< 16) | ((voice
->Alpha
& 0x00000fff) << 4) | (voice
->FMS
& 0x0000000f);
453 regs
[2] = (voice
->ESO
<< 16) | (voice
->Delta
& 0x0ffff);
454 regs
[3] = (voice
->Attribute
<< 16) | FmcRvolCvol
;
456 case TRIDENT_DEVICE_ID_DX
:
457 regs
[4] |= ((voice
->Vol
& 0x000003fc) << (16-2)) |
458 (voice
->EC
& 0x00000fff);
459 regs
[0] = (voice
->CSO
<< 16) | ((voice
->Alpha
& 0x00000fff) << 4) | (voice
->FMS
& 0x0000000f);
460 regs
[2] = (voice
->ESO
<< 16) | (voice
->Delta
& 0x0ffff);
461 regs
[3] = FmcRvolCvol
;
463 case TRIDENT_DEVICE_ID_NX
:
464 regs
[4] |= ((voice
->Vol
& 0x000003fc) << (16-2)) |
465 (voice
->EC
& 0x00000fff);
466 regs
[0] = (voice
->Delta
<< 24) | (voice
->CSO
& 0x00ffffff);
467 regs
[2] = ((voice
->Delta
<< 16) & 0xff000000) | (voice
->ESO
& 0x00ffffff);
468 regs
[3] = (voice
->Alpha
<< 20) | ((voice
->FMS
& 0x0000000f) << 16) | FmcRvolCvol
;
474 outb(voice
->number
, TRID_REG(trident
, T4D_LFO_GC_CIR
));
475 outl(regs
[0], TRID_REG(trident
, CH_START
+ 0));
476 outl(regs
[1], TRID_REG(trident
, CH_START
+ 4));
477 outl(regs
[2], TRID_REG(trident
, CH_START
+ 8));
478 outl(regs
[3], TRID_REG(trident
, CH_START
+ 12));
479 outl(regs
[4], TRID_REG(trident
, CH_START
+ 16));
482 printk("written %i channel:\n", voice
->number
);
483 printk(" regs[0] = 0x%x/0x%x\n", regs
[0], inl(TRID_REG(trident
, CH_START
+ 0)));
484 printk(" regs[1] = 0x%x/0x%x\n", regs
[1], inl(TRID_REG(trident
, CH_START
+ 4)));
485 printk(" regs[2] = 0x%x/0x%x\n", regs
[2], inl(TRID_REG(trident
, CH_START
+ 8)));
486 printk(" regs[3] = 0x%x/0x%x\n", regs
[3], inl(TRID_REG(trident
, CH_START
+ 12)));
487 printk(" regs[4] = 0x%x/0x%x\n", regs
[4], inl(TRID_REG(trident
, CH_START
+ 16)));
491 /*---------------------------------------------------------------------------
492 snd_trident_write_cso_reg
494 Description: This routine will write the new CSO offset
495 register to hardware.
497 Paramters: trident - pointer to target device class for 4DWave.
498 voice - synthesizer voice structure
501 ---------------------------------------------------------------------------*/
503 static void snd_trident_write_cso_reg(trident_t
* trident
, snd_trident_voice_t
* voice
, unsigned int CSO
)
506 outb(voice
->number
, TRID_REG(trident
, T4D_LFO_GC_CIR
));
507 if (trident
->device
!= TRIDENT_DEVICE_ID_NX
) {
508 outw(voice
->CSO
, TRID_REG(trident
, CH_DX_CSO_ALPHA_FMS
) + 2);
510 outl((voice
->Delta
<< 24) | (voice
->CSO
& 0x00ffffff), TRID_REG(trident
, CH_NX_DELTA_CSO
));
514 /*---------------------------------------------------------------------------
515 snd_trident_write_eso_reg
517 Description: This routine will write the new ESO offset
518 register to hardware.
520 Paramters: trident - pointer to target device class for 4DWave.
521 voice - synthesizer voice structure
524 ---------------------------------------------------------------------------*/
526 static void snd_trident_write_eso_reg(trident_t
* trident
, snd_trident_voice_t
* voice
, unsigned int ESO
)
529 outb(voice
->number
, TRID_REG(trident
, T4D_LFO_GC_CIR
));
530 if (trident
->device
!= TRIDENT_DEVICE_ID_NX
) {
531 outw(voice
->ESO
, TRID_REG(trident
, CH_DX_ESO_DELTA
) + 2);
533 outl(((voice
->Delta
<< 16) & 0xff000000) | (voice
->ESO
& 0x00ffffff), TRID_REG(trident
, CH_NX_DELTA_ESO
));
537 /*---------------------------------------------------------------------------
538 snd_trident_write_vol_reg
540 Description: This routine will write the new voice volume
541 register to hardware.
543 Paramters: trident - pointer to target device class for 4DWave.
544 voice - synthesizer voice structure
545 Vol - new voice volume
547 ---------------------------------------------------------------------------*/
549 static void snd_trident_write_vol_reg(trident_t
* trident
, snd_trident_voice_t
* voice
, unsigned int Vol
)
552 outb(voice
->number
, TRID_REG(trident
, T4D_LFO_GC_CIR
));
553 switch (trident
->device
) {
554 case TRIDENT_DEVICE_ID_DX
:
555 case TRIDENT_DEVICE_ID_NX
:
556 outb(voice
->Vol
>> 2, TRID_REG(trident
, CH_GVSEL_PAN_VOL_CTRL_EC
+ 2));
558 case TRIDENT_DEVICE_ID_SI7018
:
559 // printk("voice->Vol = 0x%x\n", voice->Vol);
560 outw((voice
->CTRL
<< 12) | voice
->Vol
, TRID_REG(trident
, CH_GVSEL_PAN_VOL_CTRL_EC
));
565 /*---------------------------------------------------------------------------
566 snd_trident_write_pan_reg
568 Description: This routine will write the new voice pan
569 register to hardware.
571 Paramters: trident - pointer to target device class for 4DWave.
572 voice - synthesizer voice structure
575 ---------------------------------------------------------------------------*/
577 static void snd_trident_write_pan_reg(trident_t
* trident
, snd_trident_voice_t
* voice
, unsigned int Pan
)
580 outb(voice
->number
, TRID_REG(trident
, T4D_LFO_GC_CIR
));
581 outb(((voice
->GVSel
& 0x01) << 7) | (voice
->Pan
& 0x7f), TRID_REG(trident
, CH_GVSEL_PAN_VOL_CTRL_EC
+ 3));
584 /*---------------------------------------------------------------------------
585 snd_trident_write_rvol_reg
587 Description: This routine will write the new reverb volume
588 register to hardware.
590 Paramters: trident - pointer to target device class for 4DWave.
591 voice - synthesizer voice structure
592 RVol - new reverb volume
594 ---------------------------------------------------------------------------*/
596 static void snd_trident_write_rvol_reg(trident_t
* trident
, snd_trident_voice_t
* voice
, unsigned int RVol
)
599 outb(voice
->number
, TRID_REG(trident
, T4D_LFO_GC_CIR
));
600 outw(((voice
->FMC
& 0x0003) << 14) | ((voice
->RVol
& 0x007f) << 7) | (voice
->CVol
& 0x007f),
601 TRID_REG(trident
, trident
->device
== TRIDENT_DEVICE_ID_NX
? CH_NX_ALPHA_FMS_FMC_RVOL_CVOL
: CH_DX_FMC_RVOL_CVOL
));
604 /*---------------------------------------------------------------------------
605 snd_trident_write_cvol_reg
607 Description: This routine will write the new chorus volume
608 register to hardware.
610 Paramters: trident - pointer to target device class for 4DWave.
611 voice - synthesizer voice structure
612 CVol - new chorus volume
614 ---------------------------------------------------------------------------*/
616 static void snd_trident_write_cvol_reg(trident_t
* trident
, snd_trident_voice_t
* voice
, unsigned int CVol
)
619 outb(voice
->number
, TRID_REG(trident
, T4D_LFO_GC_CIR
));
620 outw(((voice
->FMC
& 0x0003) << 14) | ((voice
->RVol
& 0x007f) << 7) | (voice
->CVol
& 0x007f),
621 TRID_REG(trident
, trident
->device
== TRIDENT_DEVICE_ID_NX
? CH_NX_ALPHA_FMS_FMC_RVOL_CVOL
: CH_DX_FMC_RVOL_CVOL
));
624 /*---------------------------------------------------------------------------
625 snd_trident_convert_rate
627 Description: This routine converts rate in HZ to hardware delta value.
629 Paramters: trident - pointer to target device class for 4DWave.
630 rate - Real or Virtual channel number.
632 Returns: Delta value.
634 ---------------------------------------------------------------------------*/
635 unsigned int snd_trident_convert_rate(unsigned int rate
)
639 // We special case 44100 and 8000 since rounding with the equation
640 // does not give us an accurate enough value. For 11025 and 22050
641 // the equation gives us the best answer. All other frequencies will
642 // also use the equation. JDW
645 else if (rate
== 8000)
647 else if (rate
== 48000)
650 delta
= (((rate
<< 12) + 24000) / 48000) & 0x0000ffff;
654 /*---------------------------------------------------------------------------
655 snd_trident_convert_adc_rate
657 Description: This routine converts rate in HZ to hardware delta value.
659 Paramters: trident - pointer to target device class for 4DWave.
660 rate - Real or Virtual channel number.
662 Returns: Delta value.
664 ---------------------------------------------------------------------------*/
665 static unsigned int snd_trident_convert_adc_rate(unsigned int rate
)
669 // We special case 44100 and 8000 since rounding with the equation
670 // does not give us an accurate enough value. For 11025 and 22050
671 // the equation gives us the best answer. All other frequencies will
672 // also use the equation. JDW
675 else if (rate
== 8000)
677 else if (rate
== 48000)
680 delta
= ((48000 << 12) / rate
) & 0x0000ffff;
684 /*---------------------------------------------------------------------------
685 snd_trident_spurious_threshold
687 Description: This routine converts rate in HZ to spurious threshold.
689 Paramters: trident - pointer to target device class for 4DWave.
690 rate - Real or Virtual channel number.
692 Returns: Delta value.
694 ---------------------------------------------------------------------------*/
695 unsigned int snd_trident_spurious_threshold(unsigned int rate
, unsigned int period_size
)
697 unsigned int res
= (rate
* period_size
) / 48000;
705 /*---------------------------------------------------------------------------
706 snd_trident_control_mode
708 Description: This routine returns a control mode for a PCM channel.
710 Paramters: trident - pointer to target device class for 4DWave.
711 substream - PCM substream
713 Returns: Control value.
715 ---------------------------------------------------------------------------*/
716 unsigned int snd_trident_control_mode(snd_pcm_substream_t
*substream
)
719 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
722 CTRL default: 8-bit (unsigned) mono, loop mode enabled
725 if (snd_pcm_format_width(runtime
->format
) == 16)
726 CTRL
|= 0x00000008; // 16-bit data
727 if (snd_pcm_format_signed(runtime
->format
))
728 CTRL
|= 0x00000002; // signed data
729 if (runtime
->channels
> 1)
730 CTRL
|= 0x00000004; // stereo data
738 /*---------------------------------------------------------------------------
741 Description: Device I/O control handler for playback/capture parameters.
743 Paramters: substream - PCM substream class
744 cmd - what ioctl message to process
745 arg - additional message infoarg
747 Returns: Error status
749 ---------------------------------------------------------------------------*/
751 static int snd_trident_ioctl(snd_pcm_substream_t
* substream
,
755 /* FIXME: it seems that with small periods the behaviour of
756 trident hardware is unpredictable and interrupt generator
758 return snd_pcm_lib_ioctl(substream
, cmd
, arg
);
761 /*---------------------------------------------------------------------------
762 snd_trident_allocate_pcm_mem
764 Description: Allocate PCM ring buffer for given substream
766 Parameters: substream - PCM substream class
767 hw_params - hardware parameters
769 Returns: Error status
771 ---------------------------------------------------------------------------*/
773 int snd_trident_allocate_pcm_mem(snd_pcm_substream_t
* substream
,
774 snd_pcm_hw_params_t
* hw_params
)
776 trident_t
*trident
= snd_pcm_substream_chip(substream
);
777 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
778 snd_trident_voice_t
*voice
= (snd_trident_voice_t
*) runtime
->private_data
;
781 if ((err
= snd_pcm_lib_malloc_pages(substream
, params_buffer_bytes(hw_params
))) < 0)
783 if (trident
->tlb
.entries
) {
784 if (err
> 0) { /* change */
786 snd_trident_free_pages(trident
, voice
->memblk
);
787 voice
->memblk
= snd_trident_alloc_pages(trident
, substream
);
788 if (voice
->memblk
== NULL
)
795 /*---------------------------------------------------------------------------
796 snd_trident_allocate_evoice
798 Description: Allocate extra voice as interrupt generator
800 Parameters: substream - PCM substream class
801 hw_params - hardware parameters
803 Returns: Error status
805 ---------------------------------------------------------------------------*/
807 int snd_trident_allocate_evoice(snd_pcm_substream_t
* substream
,
808 snd_pcm_hw_params_t
* hw_params
)
810 trident_t
*trident
= snd_pcm_substream_chip(substream
);
811 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
812 snd_trident_voice_t
*voice
= (snd_trident_voice_t
*) runtime
->private_data
;
813 snd_trident_voice_t
*evoice
= voice
->extra
;
815 /* voice management */
817 if (params_buffer_size(hw_params
) / 2 != params_period_size(hw_params
)) {
818 if (evoice
== NULL
) {
819 evoice
= snd_trident_alloc_voice(trident
, SNDRV_TRIDENT_VOICE_TYPE_PCM
, 0, 0);
822 voice
->extra
= evoice
;
823 evoice
->substream
= substream
;
826 if (evoice
!= NULL
) {
827 snd_trident_free_voice(trident
, evoice
);
828 voice
->extra
= evoice
= NULL
;
835 /*---------------------------------------------------------------------------
836 snd_trident_hw_params
838 Description: Set the hardware parameters for the playback device.
840 Parameters: substream - PCM substream class
841 hw_params - hardware parameters
843 Returns: Error status
845 ---------------------------------------------------------------------------*/
847 static int snd_trident_hw_params(snd_pcm_substream_t
* substream
,
848 snd_pcm_hw_params_t
* hw_params
)
852 err
= snd_trident_allocate_pcm_mem(substream
, hw_params
);
854 err
= snd_trident_allocate_evoice(substream
, hw_params
);
858 /*---------------------------------------------------------------------------
859 snd_trident_playback_hw_free
861 Description: Release the hardware resources for the playback device.
863 Parameters: substream - PCM substream class
865 Returns: Error status
867 ---------------------------------------------------------------------------*/
869 static int snd_trident_hw_free(snd_pcm_substream_t
* substream
)
871 trident_t
*trident
= snd_pcm_substream_chip(substream
);
872 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
873 snd_trident_voice_t
*voice
= (snd_trident_voice_t
*) runtime
->private_data
;
874 snd_trident_voice_t
*evoice
= voice
? voice
->extra
: NULL
;
876 if (trident
->tlb
.entries
) {
877 if (voice
&& voice
->memblk
) {
878 snd_trident_free_pages(trident
, voice
->memblk
);
879 voice
->memblk
= NULL
;
882 snd_pcm_lib_free_pages(substream
);
883 if (evoice
!= NULL
) {
884 snd_trident_free_voice(trident
, evoice
);
890 /*---------------------------------------------------------------------------
891 snd_trident_playback_prepare
893 Description: Prepare playback device for playback.
895 Parameters: substream - PCM substream class
897 Returns: Error status
899 ---------------------------------------------------------------------------*/
901 static int snd_trident_playback_prepare(snd_pcm_substream_t
* substream
)
903 trident_t
*trident
= snd_pcm_substream_chip(substream
);
904 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
905 snd_trident_voice_t
*voice
= (snd_trident_voice_t
*) runtime
->private_data
;
906 snd_trident_voice_t
*evoice
= voice
->extra
;
907 snd_trident_pcm_mixer_t
*mix
= &trident
->pcm_mixer
[substream
->number
];
909 spin_lock_irq(&trident
->reg_lock
);
911 /* set delta (rate) value */
912 voice
->Delta
= snd_trident_convert_rate(runtime
->rate
);
913 voice
->spurious_threshold
= snd_trident_spurious_threshold(runtime
->rate
, runtime
->period_size
);
915 /* set Loop Begin Address */
917 voice
->LBA
= voice
->memblk
->offset
;
919 voice
->LBA
= runtime
->dma_addr
;
922 voice
->ESO
= runtime
->buffer_size
- 1; /* in samples */
923 voice
->CTRL
= snd_trident_control_mode(substream
);
929 voice
->Vol
= mix
->vol
;
930 voice
->RVol
= mix
->rvol
;
931 voice
->CVol
= mix
->cvol
;
932 voice
->Pan
= mix
->pan
;
933 voice
->Attribute
= 0;
935 voice
->Attribute
= (1<<(30-16))|(2<<(26-16))|
936 (0<<(24-16))|(0x1f<<(19-16));
938 voice
->Attribute
= 0;
941 snd_trident_write_voice_regs(trident
, voice
);
943 if (evoice
!= NULL
) {
944 evoice
->Delta
= voice
->Delta
;
945 evoice
->spurious_threshold
= voice
->spurious_threshold
;
946 evoice
->LBA
= voice
->LBA
;
948 evoice
->ESO
= (runtime
->period_size
* 2) + 4 - 1; /* in samples */
949 evoice
->CTRL
= voice
->CTRL
;
951 evoice
->GVSel
= trident
->device
== TRIDENT_DEVICE_ID_SI7018
? 0 : 1;
955 evoice
->Vol
= 0x3ff; /* mute */
956 evoice
->RVol
= evoice
->CVol
= 0x7f; /* mute */
957 evoice
->Pan
= 0x7f; /* mute */
959 evoice
->Attribute
= (1<<(30-16))|(2<<(26-16))|
960 (0<<(24-16))|(0x1f<<(19-16));
962 evoice
->Attribute
= 0;
964 snd_trident_write_voice_regs(trident
, evoice
);
966 evoice
->isync_mark
= runtime
->period_size
;
967 evoice
->ESO
= (runtime
->period_size
* 2) - 1;
970 spin_unlock_irq(&trident
->reg_lock
);
975 /*---------------------------------------------------------------------------
976 snd_trident_capture_hw_params
978 Description: Set the hardware parameters for the capture device.
980 Parameters: substream - PCM substream class
981 hw_params - hardware parameters
983 Returns: Error status
985 ---------------------------------------------------------------------------*/
987 static int snd_trident_capture_hw_params(snd_pcm_substream_t
* substream
,
988 snd_pcm_hw_params_t
* hw_params
)
990 return snd_trident_allocate_pcm_mem(substream
, hw_params
);
993 /*---------------------------------------------------------------------------
994 snd_trident_capture_prepare
996 Description: Prepare capture device for playback.
998 Parameters: substream - PCM substream class
1000 Returns: Error status
1002 ---------------------------------------------------------------------------*/
1004 static int snd_trident_capture_prepare(snd_pcm_substream_t
* substream
)
1006 trident_t
*trident
= snd_pcm_substream_chip(substream
);
1007 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
1008 snd_trident_voice_t
*voice
= (snd_trident_voice_t
*) runtime
->private_data
;
1009 unsigned int val
, ESO_bytes
;
1011 spin_lock_irq(&trident
->reg_lock
);
1013 // Initilize the channel and set channel Mode
1014 outb(0, TRID_REG(trident
, LEGACY_DMAR15
));
1016 // Set DMA channel operation mode register
1017 outb(0x54, TRID_REG(trident
, LEGACY_DMAR11
));
1019 // Set channel buffer Address, DMAR0 expects contiguous PCI memory area
1020 voice
->LBA
= runtime
->dma_addr
;
1021 outl(voice
->LBA
, TRID_REG(trident
, LEGACY_DMAR0
));
1023 voice
->LBA
= voice
->memblk
->offset
;
1026 ESO_bytes
= snd_pcm_lib_buffer_bytes(substream
) - 1;
1027 outb((ESO_bytes
& 0x00ff0000) >> 16, TRID_REG(trident
, LEGACY_DMAR6
));
1028 outw((ESO_bytes
& 0x0000ffff), TRID_REG(trident
, LEGACY_DMAR4
));
1031 // Set channel sample rate, 4.12 format
1032 val
= (((unsigned int) 48000L << 12) + (runtime
->rate
/2)) / runtime
->rate
;
1033 outw(val
, TRID_REG(trident
, T4D_SBDELTA_DELTA_R
));
1035 // Set channel interrupt blk length
1036 if (snd_pcm_format_width(runtime
->format
) == 16) {
1037 val
= (unsigned short) ((ESO_bytes
>> 1) - 1);
1039 val
= (unsigned short) (ESO_bytes
- 1);
1042 outl((val
<< 16) | val
, TRID_REG(trident
, T4D_SBBL_SBCL
));
1044 // Right now, set format and start to run captureing,
1045 // continuous run loop enable.
1046 trident
->bDMAStart
= 0x19; // 0001 1001b
1048 if (snd_pcm_format_width(runtime
->format
) == 16)
1049 trident
->bDMAStart
|= 0x80;
1050 if (snd_pcm_format_signed(runtime
->format
))
1051 trident
->bDMAStart
|= 0x20;
1052 if (runtime
->channels
> 1)
1053 trident
->bDMAStart
|= 0x40;
1055 // Prepare capture intr channel
1057 voice
->Delta
= snd_trident_convert_rate(runtime
->rate
);
1058 voice
->spurious_threshold
= snd_trident_spurious_threshold(runtime
->rate
, runtime
->period_size
);
1060 voice
->isync_mark
= runtime
->period_size
;
1061 voice
->isync_max
= runtime
->buffer_size
;
1063 // Set voice parameters
1065 voice
->ESO
= voice
->isync_ESO
= (runtime
->period_size
* 2) + 6 - 1;
1066 voice
->CTRL
= snd_trident_control_mode(substream
);
1071 voice
->Pan
= 0x7f; /* mute */
1072 voice
->Vol
= 0x3ff; /* mute */
1076 voice
->Attribute
= 0;
1078 snd_trident_write_voice_regs(trident
, voice
);
1080 spin_unlock_irq(&trident
->reg_lock
);
1084 /*---------------------------------------------------------------------------
1085 snd_trident_si7018_capture_hw_params
1087 Description: Set the hardware parameters for the capture device.
1089 Parameters: substream - PCM substream class
1090 hw_params - hardware parameters
1092 Returns: Error status
1094 ---------------------------------------------------------------------------*/
1096 static int snd_trident_si7018_capture_hw_params(snd_pcm_substream_t
* substream
,
1097 snd_pcm_hw_params_t
* hw_params
)
1101 if ((err
= snd_pcm_lib_malloc_pages(substream
, params_buffer_bytes(hw_params
))) < 0)
1104 return snd_trident_allocate_evoice(substream
, hw_params
);
1107 /*---------------------------------------------------------------------------
1108 snd_trident_si7018_capture_hw_free
1110 Description: Release the hardware resources for the capture device.
1112 Parameters: substream - PCM substream class
1114 Returns: Error status
1116 ---------------------------------------------------------------------------*/
1118 static int snd_trident_si7018_capture_hw_free(snd_pcm_substream_t
* substream
)
1120 trident_t
*trident
= snd_pcm_substream_chip(substream
);
1121 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
1122 snd_trident_voice_t
*voice
= (snd_trident_voice_t
*) runtime
->private_data
;
1123 snd_trident_voice_t
*evoice
= voice
? voice
->extra
: NULL
;
1125 snd_pcm_lib_free_pages(substream
);
1126 if (evoice
!= NULL
) {
1127 snd_trident_free_voice(trident
, evoice
);
1128 voice
->extra
= NULL
;
1133 /*---------------------------------------------------------------------------
1134 snd_trident_si7018_capture_prepare
1136 Description: Prepare capture device for playback.
1138 Parameters: substream - PCM substream class
1140 Returns: Error status
1142 ---------------------------------------------------------------------------*/
1144 static int snd_trident_si7018_capture_prepare(snd_pcm_substream_t
* substream
)
1146 trident_t
*trident
= snd_pcm_substream_chip(substream
);
1147 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
1148 snd_trident_voice_t
*voice
= (snd_trident_voice_t
*) runtime
->private_data
;
1149 snd_trident_voice_t
*evoice
= voice
->extra
;
1151 spin_lock_irq(&trident
->reg_lock
);
1153 voice
->LBA
= runtime
->dma_addr
;
1154 voice
->Delta
= snd_trident_convert_adc_rate(runtime
->rate
);
1155 voice
->spurious_threshold
= snd_trident_spurious_threshold(runtime
->rate
, runtime
->period_size
);
1157 // Set voice parameters
1159 voice
->ESO
= runtime
->buffer_size
- 1; /* in samples */
1160 voice
->CTRL
= snd_trident_control_mode(substream
);
1165 voice
->Pan
= T4D_DEFAULT_PCM_PAN
;
1171 voice
->Attribute
= (2 << (30-16)) |
1176 snd_trident_write_voice_regs(trident
, voice
);
1178 if (evoice
!= NULL
) {
1179 evoice
->Delta
= snd_trident_convert_rate(runtime
->rate
);
1180 evoice
->spurious_threshold
= voice
->spurious_threshold
;
1181 evoice
->LBA
= voice
->LBA
;
1183 evoice
->ESO
= (runtime
->period_size
* 2) + 20 - 1; /* in samples, 20 means correction */
1184 evoice
->CTRL
= voice
->CTRL
;
1190 evoice
->Vol
= 0x3ff; /* mute */
1191 evoice
->RVol
= evoice
->CVol
= 0x7f; /* mute */
1192 evoice
->Pan
= 0x7f; /* mute */
1193 evoice
->Attribute
= 0;
1194 snd_trident_write_voice_regs(trident
, evoice
);
1196 evoice
->isync_mark
= runtime
->period_size
;
1197 evoice
->ESO
= (runtime
->period_size
* 2) - 1;
1200 spin_unlock_irq(&trident
->reg_lock
);
1204 /*---------------------------------------------------------------------------
1205 snd_trident_foldback_prepare
1207 Description: Prepare foldback capture device for playback.
1209 Parameters: substream - PCM substream class
1211 Returns: Error status
1213 ---------------------------------------------------------------------------*/
1215 static int snd_trident_foldback_prepare(snd_pcm_substream_t
* substream
)
1217 trident_t
*trident
= snd_pcm_substream_chip(substream
);
1218 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
1219 snd_trident_voice_t
*voice
= (snd_trident_voice_t
*) runtime
->private_data
;
1220 snd_trident_voice_t
*evoice
= voice
->extra
;
1222 spin_lock_irq(&trident
->reg_lock
);
1224 /* Set channel buffer Address */
1226 voice
->LBA
= voice
->memblk
->offset
;
1228 voice
->LBA
= runtime
->dma_addr
;
1230 /* set target ESO for channel */
1231 voice
->ESO
= runtime
->buffer_size
- 1; /* in samples */
1233 /* set sample rate */
1234 voice
->Delta
= 0x1000;
1235 voice
->spurious_threshold
= snd_trident_spurious_threshold(48000, runtime
->period_size
);
1238 voice
->CTRL
= snd_trident_control_mode(substream
);
1243 voice
->Pan
= 0x7f; /* mute */
1244 voice
->Vol
= 0x3ff; /* mute */
1248 voice
->Attribute
= 0;
1250 /* set up capture channel */
1251 outb(((voice
->number
& 0x3f) | 0x80), TRID_REG(trident
, T4D_RCI
+ voice
->foldback_chan
));
1253 snd_trident_write_voice_regs(trident
, voice
);
1255 if (evoice
!= NULL
) {
1256 evoice
->Delta
= voice
->Delta
;
1257 evoice
->spurious_threshold
= voice
->spurious_threshold
;
1258 evoice
->LBA
= voice
->LBA
;
1260 evoice
->ESO
= (runtime
->period_size
* 2) + 4 - 1; /* in samples */
1261 evoice
->CTRL
= voice
->CTRL
;
1263 evoice
->GVSel
= trident
->device
== TRIDENT_DEVICE_ID_SI7018
? 0 : 1;
1267 evoice
->Vol
= 0x3ff; /* mute */
1268 evoice
->RVol
= evoice
->CVol
= 0x7f; /* mute */
1269 evoice
->Pan
= 0x7f; /* mute */
1270 evoice
->Attribute
= 0;
1271 snd_trident_write_voice_regs(trident
, evoice
);
1273 evoice
->isync_mark
= runtime
->period_size
;
1274 evoice
->ESO
= (runtime
->period_size
* 2) - 1;
1277 spin_unlock_irq(&trident
->reg_lock
);
1281 /*---------------------------------------------------------------------------
1282 snd_trident_spdif_hw_params
1284 Description: Set the hardware parameters for the spdif device.
1286 Parameters: substream - PCM substream class
1287 hw_params - hardware parameters
1289 Returns: Error status
1291 ---------------------------------------------------------------------------*/
1293 static int snd_trident_spdif_hw_params(snd_pcm_substream_t
* substream
,
1294 snd_pcm_hw_params_t
* hw_params
)
1296 trident_t
*trident
= snd_pcm_substream_chip(substream
);
1297 unsigned int old_bits
= 0, change
= 0;
1300 err
= snd_trident_allocate_pcm_mem(substream
, hw_params
);
1304 if (trident
->device
== TRIDENT_DEVICE_ID_SI7018
) {
1305 err
= snd_trident_allocate_evoice(substream
, hw_params
);
1310 /* prepare SPDIF channel */
1311 spin_lock_irq(&trident
->reg_lock
);
1312 old_bits
= trident
->spdif_pcm_bits
;
1313 if (old_bits
& IEC958_AES0_PROFESSIONAL
)
1314 trident
->spdif_pcm_bits
&= ~IEC958_AES0_PRO_FS
;
1316 trident
->spdif_pcm_bits
&= ~(IEC958_AES3_CON_FS
<< 24);
1317 if (params_rate(hw_params
) >= 48000) {
1318 trident
->spdif_pcm_ctrl
= 0x3c; // 48000 Hz
1319 trident
->spdif_pcm_bits
|=
1320 trident
->spdif_bits
& IEC958_AES0_PROFESSIONAL
?
1321 IEC958_AES0_PRO_FS_48000
:
1322 (IEC958_AES3_CON_FS_48000
<< 24);
1324 else if (params_rate(hw_params
) >= 44100) {
1325 trident
->spdif_pcm_ctrl
= 0x3e; // 44100 Hz
1326 trident
->spdif_pcm_bits
|=
1327 trident
->spdif_bits
& IEC958_AES0_PROFESSIONAL
?
1328 IEC958_AES0_PRO_FS_44100
:
1329 (IEC958_AES3_CON_FS_44100
<< 24);
1332 trident
->spdif_pcm_ctrl
= 0x3d; // 32000 Hz
1333 trident
->spdif_pcm_bits
|=
1334 trident
->spdif_bits
& IEC958_AES0_PROFESSIONAL
?
1335 IEC958_AES0_PRO_FS_32000
:
1336 (IEC958_AES3_CON_FS_32000
<< 24);
1338 change
= old_bits
!= trident
->spdif_pcm_bits
;
1339 spin_unlock_irq(&trident
->reg_lock
);
1342 snd_ctl_notify(trident
->card
, SNDRV_CTL_EVENT_MASK_VALUE
, &trident
->spdif_pcm_ctl
->id
);
1347 /*---------------------------------------------------------------------------
1348 snd_trident_spdif_prepare
1350 Description: Prepare SPDIF device for playback.
1352 Parameters: substream - PCM substream class
1354 Returns: Error status
1356 ---------------------------------------------------------------------------*/
1358 static int snd_trident_spdif_prepare(snd_pcm_substream_t
* substream
)
1360 trident_t
*trident
= snd_pcm_substream_chip(substream
);
1361 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
1362 snd_trident_voice_t
*voice
= (snd_trident_voice_t
*) runtime
->private_data
;
1363 snd_trident_voice_t
*evoice
= voice
->extra
;
1364 snd_trident_pcm_mixer_t
*mix
= &trident
->pcm_mixer
[substream
->number
];
1365 unsigned int RESO
, LBAO
;
1368 spin_lock_irq(&trident
->reg_lock
);
1370 if (trident
->device
!= TRIDENT_DEVICE_ID_SI7018
) {
1372 /* set delta (rate) value */
1373 voice
->Delta
= snd_trident_convert_rate(runtime
->rate
);
1374 voice
->spurious_threshold
= snd_trident_spurious_threshold(runtime
->rate
, runtime
->period_size
);
1376 /* set Loop Back Address */
1377 LBAO
= runtime
->dma_addr
;
1379 voice
->LBA
= voice
->memblk
->offset
;
1385 voice
->isync_mark
= runtime
->period_size
;
1386 voice
->isync_max
= runtime
->buffer_size
;
1388 /* set target ESO for channel */
1389 RESO
= runtime
->buffer_size
- 1;
1390 voice
->ESO
= voice
->isync_ESO
= (runtime
->period_size
* 2) + 6 - 1;
1393 voice
->CTRL
= snd_trident_control_mode(substream
);
1405 voice
->Attribute
= 0;
1407 /* prepare surrogate IRQ channel */
1408 snd_trident_write_voice_regs(trident
, voice
);
1410 outw((RESO
& 0xffff), TRID_REG(trident
, NX_SPESO
));
1411 outb((RESO
>> 16), TRID_REG(trident
, NX_SPESO
+ 2));
1412 outl((LBAO
& 0xfffffffc), TRID_REG(trident
, NX_SPLBA
));
1413 outw((voice
->CSO
& 0xffff), TRID_REG(trident
, NX_SPCTRL_SPCSO
));
1414 outb((voice
->CSO
>> 16), TRID_REG(trident
, NX_SPCTRL_SPCSO
+ 2));
1416 /* set SPDIF setting */
1417 outb(trident
->spdif_pcm_ctrl
, TRID_REG(trident
, NX_SPCTRL_SPCSO
+ 3));
1418 outl(trident
->spdif_pcm_bits
, TRID_REG(trident
, NX_SPCSTATUS
));
1422 /* set delta (rate) value */
1423 voice
->Delta
= 0x800;
1424 voice
->spurious_threshold
= snd_trident_spurious_threshold(48000, runtime
->period_size
);
1426 /* set Loop Begin Address */
1428 voice
->LBA
= voice
->memblk
->offset
;
1430 voice
->LBA
= runtime
->dma_addr
;
1433 voice
->ESO
= runtime
->buffer_size
- 1; /* in samples */
1434 voice
->CTRL
= snd_trident_control_mode(substream
);
1440 voice
->Vol
= mix
->vol
;
1441 voice
->RVol
= mix
->rvol
;
1442 voice
->CVol
= mix
->cvol
;
1443 voice
->Pan
= mix
->pan
;
1444 voice
->Attribute
= (1<<(30-16))|(7<<(26-16))|
1445 (0<<(24-16))|(0<<(19-16));
1447 snd_trident_write_voice_regs(trident
, voice
);
1449 if (evoice
!= NULL
) {
1450 evoice
->Delta
= voice
->Delta
;
1451 evoice
->spurious_threshold
= voice
->spurious_threshold
;
1452 evoice
->LBA
= voice
->LBA
;
1454 evoice
->ESO
= (runtime
->period_size
* 2) + 4 - 1; /* in samples */
1455 evoice
->CTRL
= voice
->CTRL
;
1457 evoice
->GVSel
= trident
->device
== TRIDENT_DEVICE_ID_SI7018
? 0 : 1;
1461 evoice
->Vol
= 0x3ff; /* mute */
1462 evoice
->RVol
= evoice
->CVol
= 0x7f; /* mute */
1463 evoice
->Pan
= 0x7f; /* mute */
1464 evoice
->Attribute
= 0;
1465 snd_trident_write_voice_regs(trident
, evoice
);
1467 evoice
->isync_mark
= runtime
->period_size
;
1468 evoice
->ESO
= (runtime
->period_size
* 2) - 1;
1471 outl(trident
->spdif_pcm_bits
, TRID_REG(trident
, SI_SPDIF_CS
));
1472 temp
= inl(TRID_REG(trident
, T4D_LFO_GC_CIR
));
1474 outl(temp
, TRID_REG(trident
, T4D_LFO_GC_CIR
));
1475 temp
= inl(TRID_REG(trident
, SI_SERIAL_INTF_CTRL
));
1477 outl(temp
, TRID_REG(trident
, SI_SERIAL_INTF_CTRL
));
1480 spin_unlock_irq(&trident
->reg_lock
);
1485 /*---------------------------------------------------------------------------
1488 Description: Start/stop devices
1490 Parameters: substream - PCM substream class
1491 cmd - trigger command (STOP, GO)
1493 Returns: Error status
1495 ---------------------------------------------------------------------------*/
1497 static int snd_trident_trigger(snd_pcm_substream_t
*substream
,
1501 trident_t
*trident
= snd_pcm_substream_chip(substream
);
1502 struct list_head
*pos
;
1503 snd_pcm_substream_t
*s
;
1504 unsigned int what
, whati
, capture_flag
, spdif_flag
;
1505 snd_trident_voice_t
*voice
, *evoice
;
1506 unsigned int val
, go
;
1509 case SNDRV_PCM_TRIGGER_START
:
1510 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
1511 case SNDRV_PCM_TRIGGER_RESUME
:
1514 case SNDRV_PCM_TRIGGER_STOP
:
1515 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
1516 case SNDRV_PCM_TRIGGER_SUSPEND
:
1522 what
= whati
= capture_flag
= spdif_flag
= 0;
1523 spin_lock(&trident
->reg_lock
);
1524 val
= inl(TRID_REG(trident
, T4D_STIMER
)) & 0x00ffffff;
1525 snd_pcm_group_for_each(pos
, substream
) {
1526 s
= snd_pcm_group_substream_entry(pos
);
1527 if ((trident_t
*) snd_pcm_substream_chip(s
) == trident
) {
1528 voice
= (snd_trident_voice_t
*) s
->runtime
->private_data
;
1529 evoice
= voice
->extra
;
1530 what
|= 1 << (voice
->number
& 0x1f);
1531 if (evoice
== NULL
) {
1532 whati
|= 1 << (voice
->number
& 0x1f);
1534 what
|= 1 << (evoice
->number
& 0x1f);
1535 whati
|= 1 << (evoice
->number
& 0x1f);
1537 evoice
->stimer
= val
;
1541 voice
->stimer
= val
;
1545 snd_pcm_trigger_done(s
, substream
);
1553 if (trident
->device
!= TRIDENT_DEVICE_ID_SI7018
) {
1554 outl(trident
->spdif_pcm_bits
, TRID_REG(trident
, NX_SPCSTATUS
));
1555 outb(trident
->spdif_pcm_ctrl
, TRID_REG(trident
, NX_SPCTRL_SPCSO
+ 3));
1557 outl(trident
->spdif_pcm_bits
, TRID_REG(trident
, SI_SPDIF_CS
));
1558 val
= inl(TRID_REG(trident
, SI_SERIAL_INTF_CTRL
)) | SPDIF_EN
;
1559 outl(val
, TRID_REG(trident
, SI_SERIAL_INTF_CTRL
));
1563 outl(what
, TRID_REG(trident
, T4D_STOP_B
));
1564 val
= inl(TRID_REG(trident
, T4D_AINTEN_B
));
1570 outl(val
, TRID_REG(trident
, T4D_AINTEN_B
));
1572 outl(what
, TRID_REG(trident
, T4D_START_B
));
1574 if (capture_flag
&& trident
->device
!= TRIDENT_DEVICE_ID_SI7018
)
1575 outb(trident
->bDMAStart
, TRID_REG(trident
, T4D_SBCTRL_SBE2R_SBDD
));
1577 if (capture_flag
&& trident
->device
!= TRIDENT_DEVICE_ID_SI7018
)
1578 outb(0x00, TRID_REG(trident
, T4D_SBCTRL_SBE2R_SBDD
));
1580 spin_unlock(&trident
->reg_lock
);
1584 /*---------------------------------------------------------------------------
1585 snd_trident_playback_pointer
1587 Description: This routine return the playback position
1589 Parameters: substream - PCM substream class
1591 Returns: position of buffer
1593 ---------------------------------------------------------------------------*/
1595 static snd_pcm_uframes_t
snd_trident_playback_pointer(snd_pcm_substream_t
* substream
)
1597 trident_t
*trident
= snd_pcm_substream_chip(substream
);
1598 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
1599 snd_trident_voice_t
*voice
= (snd_trident_voice_t
*) runtime
->private_data
;
1602 if (!voice
->running
)
1605 spin_lock(&trident
->reg_lock
);
1607 outb(voice
->number
, TRID_REG(trident
, T4D_LFO_GC_CIR
));
1609 if (trident
->device
!= TRIDENT_DEVICE_ID_NX
) {
1610 cso
= inw(TRID_REG(trident
, CH_DX_CSO_ALPHA_FMS
+ 2));
1611 } else { // ID_4DWAVE_NX
1612 cso
= (unsigned int) inl(TRID_REG(trident
, CH_NX_DELTA_CSO
)) & 0x00ffffff;
1615 spin_unlock(&trident
->reg_lock
);
1617 if (cso
>= runtime
->buffer_size
)
1623 /*---------------------------------------------------------------------------
1624 snd_trident_capture_pointer
1626 Description: This routine return the capture position
1628 Paramters: pcm1 - PCM device class
1630 Returns: position of buffer
1632 ---------------------------------------------------------------------------*/
1634 static snd_pcm_uframes_t
snd_trident_capture_pointer(snd_pcm_substream_t
* substream
)
1636 trident_t
*trident
= snd_pcm_substream_chip(substream
);
1637 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
1638 snd_trident_voice_t
*voice
= (snd_trident_voice_t
*) runtime
->private_data
;
1639 unsigned int result
;
1641 if (!voice
->running
)
1644 result
= inw(TRID_REG(trident
, T4D_SBBL_SBCL
));
1645 if (runtime
->channels
> 1)
1648 result
= runtime
->buffer_size
- result
;
1653 /*---------------------------------------------------------------------------
1654 snd_trident_spdif_pointer
1656 Description: This routine return the SPDIF playback position
1658 Parameters: substream - PCM substream class
1660 Returns: position of buffer
1662 ---------------------------------------------------------------------------*/
1664 static snd_pcm_uframes_t
snd_trident_spdif_pointer(snd_pcm_substream_t
* substream
)
1666 trident_t
*trident
= snd_pcm_substream_chip(substream
);
1667 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
1668 snd_trident_voice_t
*voice
= (snd_trident_voice_t
*) runtime
->private_data
;
1669 unsigned int result
;
1671 if (!voice
->running
)
1674 result
= inl(TRID_REG(trident
, NX_SPCTRL_SPCSO
)) & 0x00ffffff;
1680 * Playback support device description
1683 static snd_pcm_hardware_t snd_trident_playback
=
1685 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
1686 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
1687 SNDRV_PCM_INFO_MMAP_VALID
| SNDRV_PCM_INFO_SYNC_START
|
1688 SNDRV_PCM_INFO_PAUSE
| SNDRV_PCM_INFO_RESUME
),
1689 .formats
= (SNDRV_PCM_FMTBIT_U8
| SNDRV_PCM_FMTBIT_S16_LE
|
1690 SNDRV_PCM_FMTBIT_S8
| SNDRV_PCM_FMTBIT_U16_LE
),
1691 .rates
= SNDRV_PCM_RATE_CONTINUOUS
| SNDRV_PCM_RATE_8000_48000
,
1696 .buffer_bytes_max
= (256*1024),
1697 .period_bytes_min
= 64,
1698 .period_bytes_max
= (256*1024),
1700 .periods_max
= 1024,
1705 * Capture support device description
1708 static snd_pcm_hardware_t snd_trident_capture
=
1710 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
1711 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
1712 SNDRV_PCM_INFO_MMAP_VALID
| SNDRV_PCM_INFO_SYNC_START
|
1713 SNDRV_PCM_INFO_PAUSE
| SNDRV_PCM_INFO_RESUME
),
1714 .formats
= (SNDRV_PCM_FMTBIT_U8
| SNDRV_PCM_FMTBIT_S16_LE
|
1715 SNDRV_PCM_FMTBIT_S8
| SNDRV_PCM_FMTBIT_U16_LE
),
1716 .rates
= SNDRV_PCM_RATE_CONTINUOUS
| SNDRV_PCM_RATE_8000_48000
,
1721 .buffer_bytes_max
= (128*1024),
1722 .period_bytes_min
= 64,
1723 .period_bytes_max
= (128*1024),
1725 .periods_max
= 1024,
1730 * Foldback capture support device description
1733 static snd_pcm_hardware_t snd_trident_foldback
=
1735 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
1736 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
1737 SNDRV_PCM_INFO_MMAP_VALID
| SNDRV_PCM_INFO_SYNC_START
|
1738 SNDRV_PCM_INFO_PAUSE
| SNDRV_PCM_INFO_RESUME
),
1739 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
1740 .rates
= SNDRV_PCM_RATE_48000
,
1745 .buffer_bytes_max
= (128*1024),
1746 .period_bytes_min
= 64,
1747 .period_bytes_max
= (128*1024),
1749 .periods_max
= 1024,
1754 * SPDIF playback support device description
1757 static snd_pcm_hardware_t snd_trident_spdif
=
1759 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
1760 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
1761 SNDRV_PCM_INFO_MMAP_VALID
| SNDRV_PCM_INFO_SYNC_START
|
1762 SNDRV_PCM_INFO_PAUSE
| SNDRV_PCM_INFO_RESUME
),
1763 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
1764 .rates
= (SNDRV_PCM_RATE_32000
| SNDRV_PCM_RATE_44100
|
1765 SNDRV_PCM_RATE_48000
),
1770 .buffer_bytes_max
= (128*1024),
1771 .period_bytes_min
= 64,
1772 .period_bytes_max
= (128*1024),
1774 .periods_max
= 1024,
1778 static snd_pcm_hardware_t snd_trident_spdif_7018
=
1780 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
1781 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
1782 SNDRV_PCM_INFO_MMAP_VALID
| SNDRV_PCM_INFO_SYNC_START
|
1783 SNDRV_PCM_INFO_PAUSE
| SNDRV_PCM_INFO_RESUME
),
1784 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
1785 .rates
= SNDRV_PCM_RATE_48000
,
1790 .buffer_bytes_max
= (128*1024),
1791 .period_bytes_min
= 64,
1792 .period_bytes_max
= (128*1024),
1794 .periods_max
= 1024,
1798 static void snd_trident_pcm_free_substream(snd_pcm_runtime_t
*runtime
)
1800 snd_trident_voice_t
*voice
= (snd_trident_voice_t
*) runtime
->private_data
;
1804 trident
= voice
->trident
;
1805 snd_trident_free_voice(trident
, voice
);
1809 static int snd_trident_playback_open(snd_pcm_substream_t
* substream
)
1811 trident_t
*trident
= snd_pcm_substream_chip(substream
);
1812 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
1813 snd_trident_voice_t
*voice
;
1815 voice
= snd_trident_alloc_voice(trident
, SNDRV_TRIDENT_VOICE_TYPE_PCM
, 0, 0);
1818 snd_trident_pcm_mixer_build(trident
, voice
, substream
);
1819 voice
->substream
= substream
;
1820 runtime
->private_data
= voice
;
1821 runtime
->private_free
= snd_trident_pcm_free_substream
;
1822 runtime
->hw
= snd_trident_playback
;
1823 snd_pcm_set_sync(substream
);
1824 snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_BUFFER_SIZE
, 0, 64*1024);
1828 /*---------------------------------------------------------------------------
1829 snd_trident_playback_close
1831 Description: This routine will close the 4DWave playback device. For now
1832 we will simply free the dma transfer buffer.
1834 Parameters: substream - PCM substream class
1836 ---------------------------------------------------------------------------*/
1837 static int snd_trident_playback_close(snd_pcm_substream_t
* substream
)
1839 trident_t
*trident
= snd_pcm_substream_chip(substream
);
1840 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
1841 snd_trident_voice_t
*voice
= (snd_trident_voice_t
*) runtime
->private_data
;
1843 snd_trident_pcm_mixer_free(trident
, voice
, substream
);
1847 /*---------------------------------------------------------------------------
1848 snd_trident_spdif_open
1850 Description: This routine will open the 4DWave SPDIF device.
1852 Parameters: substream - PCM substream class
1854 Returns: status - success or failure flag
1856 ---------------------------------------------------------------------------*/
1858 static int snd_trident_spdif_open(snd_pcm_substream_t
* substream
)
1860 trident_t
*trident
= snd_pcm_substream_chip(substream
);
1861 snd_trident_voice_t
*voice
;
1862 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
1864 voice
= snd_trident_alloc_voice(trident
, SNDRV_TRIDENT_VOICE_TYPE_PCM
, 0, 0);
1868 voice
->substream
= substream
;
1869 spin_lock_irq(&trident
->reg_lock
);
1870 trident
->spdif_pcm_bits
= trident
->spdif_bits
;
1871 spin_unlock_irq(&trident
->reg_lock
);
1873 runtime
->private_data
= voice
;
1874 runtime
->private_free
= snd_trident_pcm_free_substream
;
1875 if (trident
->device
== TRIDENT_DEVICE_ID_SI7018
) {
1876 runtime
->hw
= snd_trident_spdif
;
1878 runtime
->hw
= snd_trident_spdif_7018
;
1881 trident
->spdif_pcm_ctl
->vd
[0].access
&= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE
;
1882 snd_ctl_notify(trident
->card
, SNDRV_CTL_EVENT_MASK_VALUE
|
1883 SNDRV_CTL_EVENT_MASK_INFO
, &trident
->spdif_pcm_ctl
->id
);
1885 snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_BUFFER_SIZE
, 0, 64*1024);
1890 /*---------------------------------------------------------------------------
1891 snd_trident_spdif_close
1893 Description: This routine will close the 4DWave SPDIF device.
1895 Parameters: substream - PCM substream class
1897 ---------------------------------------------------------------------------*/
1899 static int snd_trident_spdif_close(snd_pcm_substream_t
* substream
)
1901 trident_t
*trident
= snd_pcm_substream_chip(substream
);
1904 spin_lock_irq(&trident
->reg_lock
);
1905 // restore default SPDIF setting
1906 if (trident
->device
!= TRIDENT_DEVICE_ID_SI7018
) {
1907 outb(trident
->spdif_ctrl
, TRID_REG(trident
, NX_SPCTRL_SPCSO
+ 3));
1908 outl(trident
->spdif_bits
, TRID_REG(trident
, NX_SPCSTATUS
));
1910 outl(trident
->spdif_bits
, TRID_REG(trident
, SI_SPDIF_CS
));
1911 temp
= inl(TRID_REG(trident
, SI_SERIAL_INTF_CTRL
));
1912 if (trident
->spdif_ctrl
) {
1917 outl(temp
, TRID_REG(trident
, SI_SERIAL_INTF_CTRL
));
1919 spin_unlock_irq(&trident
->reg_lock
);
1920 trident
->spdif_pcm_ctl
->vd
[0].access
|= SNDRV_CTL_ELEM_ACCESS_INACTIVE
;
1921 snd_ctl_notify(trident
->card
, SNDRV_CTL_EVENT_MASK_VALUE
|
1922 SNDRV_CTL_EVENT_MASK_INFO
, &trident
->spdif_pcm_ctl
->id
);
1926 /*---------------------------------------------------------------------------
1927 snd_trident_capture_open
1929 Description: This routine will open the 4DWave capture device.
1931 Parameters: substream - PCM substream class
1933 Returns: status - success or failure flag
1935 ---------------------------------------------------------------------------*/
1937 static int snd_trident_capture_open(snd_pcm_substream_t
* substream
)
1939 trident_t
*trident
= snd_pcm_substream_chip(substream
);
1940 snd_trident_voice_t
*voice
;
1941 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
1943 voice
= snd_trident_alloc_voice(trident
, SNDRV_TRIDENT_VOICE_TYPE_PCM
, 0, 0);
1947 voice
->substream
= substream
;
1948 runtime
->private_data
= voice
;
1949 runtime
->private_free
= snd_trident_pcm_free_substream
;
1950 runtime
->hw
= snd_trident_capture
;
1951 snd_pcm_set_sync(substream
);
1952 snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_BUFFER_SIZE
, 0, 64*1024);
1956 /*---------------------------------------------------------------------------
1957 snd_trident_capture_close
1959 Description: This routine will close the 4DWave capture device. For now
1960 we will simply free the dma transfer buffer.
1962 Parameters: substream - PCM substream class
1964 ---------------------------------------------------------------------------*/
1965 static int snd_trident_capture_close(snd_pcm_substream_t
* substream
)
1970 /*---------------------------------------------------------------------------
1971 snd_trident_foldback_open
1973 Description: This routine will open the 4DWave foldback capture device.
1975 Parameters: substream - PCM substream class
1977 Returns: status - success or failure flag
1979 ---------------------------------------------------------------------------*/
1981 static int snd_trident_foldback_open(snd_pcm_substream_t
* substream
)
1983 trident_t
*trident
= snd_pcm_substream_chip(substream
);
1984 snd_trident_voice_t
*voice
;
1985 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
1987 voice
= snd_trident_alloc_voice(trident
, SNDRV_TRIDENT_VOICE_TYPE_PCM
, 0, 0);
1990 voice
->foldback_chan
= substream
->number
;
1991 voice
->substream
= substream
;
1992 runtime
->private_data
= voice
;
1993 runtime
->private_free
= snd_trident_pcm_free_substream
;
1994 runtime
->hw
= snd_trident_foldback
;
1995 snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_BUFFER_SIZE
, 0, 64*1024);
1999 /*---------------------------------------------------------------------------
2000 snd_trident_foldback_close
2002 Description: This routine will close the 4DWave foldback capture device.
2003 For now we will simply free the dma transfer buffer.
2005 Parameters: substream - PCM substream class
2007 ---------------------------------------------------------------------------*/
2008 static int snd_trident_foldback_close(snd_pcm_substream_t
* substream
)
2010 trident_t
*trident
= snd_pcm_substream_chip(substream
);
2011 snd_trident_voice_t
*voice
;
2012 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
2013 voice
= (snd_trident_voice_t
*) runtime
->private_data
;
2015 /* stop capture channel */
2016 spin_lock_irq(&trident
->reg_lock
);
2017 outb(0x00, TRID_REG(trident
, T4D_RCI
+ voice
->foldback_chan
));
2018 spin_unlock_irq(&trident
->reg_lock
);
2022 /*---------------------------------------------------------------------------
2024 ---------------------------------------------------------------------------*/
2026 static snd_pcm_ops_t snd_trident_playback_ops
= {
2027 .open
= snd_trident_playback_open
,
2028 .close
= snd_trident_playback_close
,
2029 .ioctl
= snd_trident_ioctl
,
2030 .hw_params
= snd_trident_hw_params
,
2031 .hw_free
= snd_trident_hw_free
,
2032 .prepare
= snd_trident_playback_prepare
,
2033 .trigger
= snd_trident_trigger
,
2034 .pointer
= snd_trident_playback_pointer
,
2037 static snd_pcm_ops_t snd_trident_nx_playback_ops
= {
2038 .open
= snd_trident_playback_open
,
2039 .close
= snd_trident_playback_close
,
2040 .ioctl
= snd_trident_ioctl
,
2041 .hw_params
= snd_trident_hw_params
,
2042 .hw_free
= snd_trident_hw_free
,
2043 .prepare
= snd_trident_playback_prepare
,
2044 .trigger
= snd_trident_trigger
,
2045 .pointer
= snd_trident_playback_pointer
,
2046 .page
= snd_pcm_sgbuf_ops_page
,
2049 static snd_pcm_ops_t snd_trident_capture_ops
= {
2050 .open
= snd_trident_capture_open
,
2051 .close
= snd_trident_capture_close
,
2052 .ioctl
= snd_trident_ioctl
,
2053 .hw_params
= snd_trident_capture_hw_params
,
2054 .hw_free
= snd_trident_hw_free
,
2055 .prepare
= snd_trident_capture_prepare
,
2056 .trigger
= snd_trident_trigger
,
2057 .pointer
= snd_trident_capture_pointer
,
2060 static snd_pcm_ops_t snd_trident_si7018_capture_ops
= {
2061 .open
= snd_trident_capture_open
,
2062 .close
= snd_trident_capture_close
,
2063 .ioctl
= snd_trident_ioctl
,
2064 .hw_params
= snd_trident_si7018_capture_hw_params
,
2065 .hw_free
= snd_trident_si7018_capture_hw_free
,
2066 .prepare
= snd_trident_si7018_capture_prepare
,
2067 .trigger
= snd_trident_trigger
,
2068 .pointer
= snd_trident_playback_pointer
,
2071 static snd_pcm_ops_t snd_trident_foldback_ops
= {
2072 .open
= snd_trident_foldback_open
,
2073 .close
= snd_trident_foldback_close
,
2074 .ioctl
= snd_trident_ioctl
,
2075 .hw_params
= snd_trident_hw_params
,
2076 .hw_free
= snd_trident_hw_free
,
2077 .prepare
= snd_trident_foldback_prepare
,
2078 .trigger
= snd_trident_trigger
,
2079 .pointer
= snd_trident_playback_pointer
,
2082 static snd_pcm_ops_t snd_trident_nx_foldback_ops
= {
2083 .open
= snd_trident_foldback_open
,
2084 .close
= snd_trident_foldback_close
,
2085 .ioctl
= snd_trident_ioctl
,
2086 .hw_params
= snd_trident_hw_params
,
2087 .hw_free
= snd_trident_hw_free
,
2088 .prepare
= snd_trident_foldback_prepare
,
2089 .trigger
= snd_trident_trigger
,
2090 .pointer
= snd_trident_playback_pointer
,
2091 .page
= snd_pcm_sgbuf_ops_page
,
2094 static snd_pcm_ops_t snd_trident_spdif_ops
= {
2095 .open
= snd_trident_spdif_open
,
2096 .close
= snd_trident_spdif_close
,
2097 .ioctl
= snd_trident_ioctl
,
2098 .hw_params
= snd_trident_spdif_hw_params
,
2099 .hw_free
= snd_trident_hw_free
,
2100 .prepare
= snd_trident_spdif_prepare
,
2101 .trigger
= snd_trident_trigger
,
2102 .pointer
= snd_trident_spdif_pointer
,
2105 static snd_pcm_ops_t snd_trident_spdif_7018_ops
= {
2106 .open
= snd_trident_spdif_open
,
2107 .close
= snd_trident_spdif_close
,
2108 .ioctl
= snd_trident_ioctl
,
2109 .hw_params
= snd_trident_spdif_hw_params
,
2110 .hw_free
= snd_trident_hw_free
,
2111 .prepare
= snd_trident_spdif_prepare
,
2112 .trigger
= snd_trident_trigger
,
2113 .pointer
= snd_trident_playback_pointer
,
2116 /*---------------------------------------------------------------------------
2117 snd_trident_pcm_free
2119 Description: This routine release the 4DWave private data.
2121 Paramters: private_data - pointer to 4DWave device info.
2125 ---------------------------------------------------------------------------*/
2126 static void snd_trident_pcm_free(snd_pcm_t
*pcm
)
2128 trident_t
*trident
= pcm
->private_data
;
2129 trident
->pcm
= NULL
;
2130 snd_pcm_lib_preallocate_free_for_all(pcm
);
2133 static void snd_trident_foldback_pcm_free(snd_pcm_t
*pcm
)
2135 trident_t
*trident
= pcm
->private_data
;
2136 trident
->foldback
= NULL
;
2137 snd_pcm_lib_preallocate_free_for_all(pcm
);
2140 static void snd_trident_spdif_pcm_free(snd_pcm_t
*pcm
)
2142 trident_t
*trident
= pcm
->private_data
;
2143 trident
->spdif
= NULL
;
2144 snd_pcm_lib_preallocate_free_for_all(pcm
);
2147 /*---------------------------------------------------------------------------
2150 Description: This routine registers the 4DWave device for PCM support.
2152 Paramters: trident - pointer to target device class for 4DWave.
2156 ---------------------------------------------------------------------------*/
2158 int __devinit
snd_trident_pcm(trident_t
* trident
, int device
, snd_pcm_t
** rpcm
)
2165 if ((err
= snd_pcm_new(trident
->card
, "trident_dx_nx", device
, trident
->ChanPCM
, 1, &pcm
)) < 0)
2168 pcm
->private_data
= trident
;
2169 pcm
->private_free
= snd_trident_pcm_free
;
2171 if (trident
->tlb
.entries
) {
2172 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_trident_nx_playback_ops
);
2174 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_trident_playback_ops
);
2176 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
,
2177 trident
->device
!= TRIDENT_DEVICE_ID_SI7018
?
2178 &snd_trident_capture_ops
:
2179 &snd_trident_si7018_capture_ops
);
2181 pcm
->info_flags
= 0;
2182 pcm
->dev_subclass
= SNDRV_PCM_SUBCLASS_GENERIC_MIX
;
2183 strcpy(pcm
->name
, "Trident 4DWave");
2186 if (trident
->tlb
.entries
) {
2187 snd_pcm_substream_t
*substream
;
2188 for (substream
= pcm
->streams
[SNDRV_PCM_STREAM_PLAYBACK
].substream
; substream
; substream
= substream
->next
)
2189 snd_pcm_lib_preallocate_pages(substream
, SNDRV_DMA_TYPE_DEV_SG
,
2190 snd_dma_pci_data(trident
->pci
),
2192 snd_pcm_lib_preallocate_pages(pcm
->streams
[SNDRV_PCM_STREAM_CAPTURE
].substream
,
2193 SNDRV_DMA_TYPE_DEV
, snd_dma_pci_data(trident
->pci
),
2196 snd_pcm_lib_preallocate_pages_for_all(pcm
, SNDRV_DMA_TYPE_DEV
,
2197 snd_dma_pci_data(trident
->pci
), 64*1024, 128*1024);
2205 /*---------------------------------------------------------------------------
2206 snd_trident_foldback_pcm
2208 Description: This routine registers the 4DWave device for foldback PCM support.
2210 Paramters: trident - pointer to target device class for 4DWave.
2214 ---------------------------------------------------------------------------*/
2216 int __devinit
snd_trident_foldback_pcm(trident_t
* trident
, int device
, snd_pcm_t
** rpcm
)
2218 snd_pcm_t
*foldback
;
2221 snd_pcm_substream_t
*substream
;
2225 if (trident
->device
== TRIDENT_DEVICE_ID_NX
)
2227 if ((err
= snd_pcm_new(trident
->card
, "trident_dx_nx", device
, 0, num_chan
, &foldback
)) < 0)
2230 foldback
->private_data
= trident
;
2231 foldback
->private_free
= snd_trident_foldback_pcm_free
;
2232 if (trident
->tlb
.entries
)
2233 snd_pcm_set_ops(foldback
, SNDRV_PCM_STREAM_CAPTURE
, &snd_trident_nx_foldback_ops
);
2235 snd_pcm_set_ops(foldback
, SNDRV_PCM_STREAM_CAPTURE
, &snd_trident_foldback_ops
);
2236 foldback
->info_flags
= 0;
2237 strcpy(foldback
->name
, "Trident 4DWave");
2238 substream
= foldback
->streams
[SNDRV_PCM_STREAM_CAPTURE
].substream
;
2239 strcpy(substream
->name
, "Front Mixer");
2240 substream
= substream
->next
;
2241 strcpy(substream
->name
, "Reverb Mixer");
2242 substream
= substream
->next
;
2243 strcpy(substream
->name
, "Chorus Mixer");
2244 if (num_chan
== 4) {
2245 substream
= substream
->next
;
2246 strcpy(substream
->name
, "Second AC'97 ADC");
2248 trident
->foldback
= foldback
;
2250 if (trident
->tlb
.entries
)
2251 snd_pcm_lib_preallocate_pages_for_all(foldback
, SNDRV_DMA_TYPE_DEV_SG
,
2252 snd_dma_pci_data(trident
->pci
), 0, 128*1024);
2254 snd_pcm_lib_preallocate_pages_for_all(foldback
, SNDRV_DMA_TYPE_DEV
,
2255 snd_dma_pci_data(trident
->pci
), 64*1024, 128*1024);
2262 /*---------------------------------------------------------------------------
2265 Description: This routine registers the 4DWave-NX device for SPDIF support.
2267 Paramters: trident - pointer to target device class for 4DWave-NX.
2271 ---------------------------------------------------------------------------*/
2273 int __devinit
snd_trident_spdif_pcm(trident_t
* trident
, int device
, snd_pcm_t
** rpcm
)
2280 if ((err
= snd_pcm_new(trident
->card
, "trident_dx_nx IEC958", device
, 1, 0, &spdif
)) < 0)
2283 spdif
->private_data
= trident
;
2284 spdif
->private_free
= snd_trident_spdif_pcm_free
;
2285 if (trident
->device
!= TRIDENT_DEVICE_ID_SI7018
) {
2286 snd_pcm_set_ops(spdif
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_trident_spdif_ops
);
2288 snd_pcm_set_ops(spdif
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_trident_spdif_7018_ops
);
2290 spdif
->info_flags
= 0;
2291 strcpy(spdif
->name
, "Trident 4DWave IEC958");
2292 trident
->spdif
= spdif
;
2294 snd_pcm_lib_preallocate_pages_for_all(spdif
, SNDRV_DMA_TYPE_DEV
, snd_dma_pci_data(trident
->pci
), 64*1024, 128*1024);
2306 /*---------------------------------------------------------------------------
2307 snd_trident_spdif_control
2309 Description: enable/disable S/PDIF out from ac97 mixer
2310 ---------------------------------------------------------------------------*/
2312 static int snd_trident_spdif_control_info(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
* uinfo
)
2314 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
2316 uinfo
->value
.integer
.min
= 0;
2317 uinfo
->value
.integer
.max
= 1;
2321 static int snd_trident_spdif_control_get(snd_kcontrol_t
* kcontrol
,
2322 snd_ctl_elem_value_t
* ucontrol
)
2324 trident_t
*trident
= snd_kcontrol_chip(kcontrol
);
2327 spin_lock_irq(&trident
->reg_lock
);
2328 val
= trident
->spdif_ctrl
;
2329 ucontrol
->value
.integer
.value
[0] = val
== kcontrol
->private_value
;
2330 spin_unlock_irq(&trident
->reg_lock
);
2334 static int snd_trident_spdif_control_put(snd_kcontrol_t
* kcontrol
,
2335 snd_ctl_elem_value_t
* ucontrol
)
2337 trident_t
*trident
= snd_kcontrol_chip(kcontrol
);
2341 val
= ucontrol
->value
.integer
.value
[0] ? (unsigned char) kcontrol
->private_value
: 0x00;
2342 spin_lock_irq(&trident
->reg_lock
);
2343 /* S/PDIF C Channel bits 0-31 : 48khz, SCMS disabled */
2344 change
= trident
->spdif_ctrl
!= val
;
2345 trident
->spdif_ctrl
= val
;
2346 if (trident
->device
!= TRIDENT_DEVICE_ID_SI7018
) {
2347 if ((inb(TRID_REG(trident
, NX_SPCTRL_SPCSO
+ 3)) & 0x10) == 0) {
2348 outl(trident
->spdif_bits
, TRID_REG(trident
, NX_SPCSTATUS
));
2349 outb(trident
->spdif_ctrl
, TRID_REG(trident
, NX_SPCTRL_SPCSO
+ 3));
2352 if (trident
->spdif
== NULL
) {
2354 outl(trident
->spdif_bits
, TRID_REG(trident
, SI_SPDIF_CS
));
2355 temp
= inl(TRID_REG(trident
, SI_SERIAL_INTF_CTRL
)) & ~SPDIF_EN
;
2358 outl(temp
, TRID_REG(trident
, SI_SERIAL_INTF_CTRL
));
2361 spin_unlock_irq(&trident
->reg_lock
);
2365 static snd_kcontrol_new_t snd_trident_spdif_control __devinitdata
=
2367 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2368 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,SWITCH
),
2369 .info
= snd_trident_spdif_control_info
,
2370 .get
= snd_trident_spdif_control_get
,
2371 .put
= snd_trident_spdif_control_put
,
2372 .private_value
= 0x28,
2375 /*---------------------------------------------------------------------------
2376 snd_trident_spdif_default
2378 Description: put/get the S/PDIF default settings
2379 ---------------------------------------------------------------------------*/
2381 static int snd_trident_spdif_default_info(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
* uinfo
)
2383 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_IEC958
;
2388 static int snd_trident_spdif_default_get(snd_kcontrol_t
* kcontrol
,
2389 snd_ctl_elem_value_t
* ucontrol
)
2391 trident_t
*trident
= snd_kcontrol_chip(kcontrol
);
2393 spin_lock_irq(&trident
->reg_lock
);
2394 ucontrol
->value
.iec958
.status
[0] = (trident
->spdif_bits
>> 0) & 0xff;
2395 ucontrol
->value
.iec958
.status
[1] = (trident
->spdif_bits
>> 8) & 0xff;
2396 ucontrol
->value
.iec958
.status
[2] = (trident
->spdif_bits
>> 16) & 0xff;
2397 ucontrol
->value
.iec958
.status
[3] = (trident
->spdif_bits
>> 24) & 0xff;
2398 spin_unlock_irq(&trident
->reg_lock
);
2402 static int snd_trident_spdif_default_put(snd_kcontrol_t
* kcontrol
,
2403 snd_ctl_elem_value_t
* ucontrol
)
2405 trident_t
*trident
= snd_kcontrol_chip(kcontrol
);
2409 val
= (ucontrol
->value
.iec958
.status
[0] << 0) |
2410 (ucontrol
->value
.iec958
.status
[1] << 8) |
2411 (ucontrol
->value
.iec958
.status
[2] << 16) |
2412 (ucontrol
->value
.iec958
.status
[3] << 24);
2413 spin_lock_irq(&trident
->reg_lock
);
2414 change
= trident
->spdif_bits
!= val
;
2415 trident
->spdif_bits
= val
;
2416 if (trident
->device
!= TRIDENT_DEVICE_ID_SI7018
) {
2417 if ((inb(TRID_REG(trident
, NX_SPCTRL_SPCSO
+ 3)) & 0x10) == 0)
2418 outl(trident
->spdif_bits
, TRID_REG(trident
, NX_SPCSTATUS
));
2420 if (trident
->spdif
== NULL
)
2421 outl(trident
->spdif_bits
, TRID_REG(trident
, SI_SPDIF_CS
));
2423 spin_unlock_irq(&trident
->reg_lock
);
2427 static snd_kcontrol_new_t snd_trident_spdif_default __devinitdata
=
2429 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
2430 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,DEFAULT
),
2431 .info
= snd_trident_spdif_default_info
,
2432 .get
= snd_trident_spdif_default_get
,
2433 .put
= snd_trident_spdif_default_put
2436 /*---------------------------------------------------------------------------
2437 snd_trident_spdif_mask
2439 Description: put/get the S/PDIF mask
2440 ---------------------------------------------------------------------------*/
2442 static int snd_trident_spdif_mask_info(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
* uinfo
)
2444 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_IEC958
;
2449 static int snd_trident_spdif_mask_get(snd_kcontrol_t
* kcontrol
,
2450 snd_ctl_elem_value_t
* ucontrol
)
2452 ucontrol
->value
.iec958
.status
[0] = 0xff;
2453 ucontrol
->value
.iec958
.status
[1] = 0xff;
2454 ucontrol
->value
.iec958
.status
[2] = 0xff;
2455 ucontrol
->value
.iec958
.status
[3] = 0xff;
2459 static snd_kcontrol_new_t snd_trident_spdif_mask __devinitdata
=
2461 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
2462 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
2463 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,MASK
),
2464 .info
= snd_trident_spdif_mask_info
,
2465 .get
= snd_trident_spdif_mask_get
,
2468 /*---------------------------------------------------------------------------
2469 snd_trident_spdif_stream
2471 Description: put/get the S/PDIF stream settings
2472 ---------------------------------------------------------------------------*/
2474 static int snd_trident_spdif_stream_info(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
* uinfo
)
2476 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_IEC958
;
2481 static int snd_trident_spdif_stream_get(snd_kcontrol_t
* kcontrol
,
2482 snd_ctl_elem_value_t
* ucontrol
)
2484 trident_t
*trident
= snd_kcontrol_chip(kcontrol
);
2486 spin_lock_irq(&trident
->reg_lock
);
2487 ucontrol
->value
.iec958
.status
[0] = (trident
->spdif_pcm_bits
>> 0) & 0xff;
2488 ucontrol
->value
.iec958
.status
[1] = (trident
->spdif_pcm_bits
>> 8) & 0xff;
2489 ucontrol
->value
.iec958
.status
[2] = (trident
->spdif_pcm_bits
>> 16) & 0xff;
2490 ucontrol
->value
.iec958
.status
[3] = (trident
->spdif_pcm_bits
>> 24) & 0xff;
2491 spin_unlock_irq(&trident
->reg_lock
);
2495 static int snd_trident_spdif_stream_put(snd_kcontrol_t
* kcontrol
,
2496 snd_ctl_elem_value_t
* ucontrol
)
2498 trident_t
*trident
= snd_kcontrol_chip(kcontrol
);
2502 val
= (ucontrol
->value
.iec958
.status
[0] << 0) |
2503 (ucontrol
->value
.iec958
.status
[1] << 8) |
2504 (ucontrol
->value
.iec958
.status
[2] << 16) |
2505 (ucontrol
->value
.iec958
.status
[3] << 24);
2506 spin_lock_irq(&trident
->reg_lock
);
2507 change
= trident
->spdif_pcm_bits
!= val
;
2508 trident
->spdif_pcm_bits
= val
;
2509 if (trident
->spdif
!= NULL
) {
2510 if (trident
->device
!= TRIDENT_DEVICE_ID_SI7018
) {
2511 outl(trident
->spdif_pcm_bits
, TRID_REG(trident
, NX_SPCSTATUS
));
2513 outl(trident
->spdif_bits
, TRID_REG(trident
, SI_SPDIF_CS
));
2516 spin_unlock_irq(&trident
->reg_lock
);
2520 static snd_kcontrol_new_t snd_trident_spdif_stream __devinitdata
=
2522 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
| SNDRV_CTL_ELEM_ACCESS_INACTIVE
,
2523 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
2524 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,PCM_STREAM
),
2525 .info
= snd_trident_spdif_stream_info
,
2526 .get
= snd_trident_spdif_stream_get
,
2527 .put
= snd_trident_spdif_stream_put
2530 /*---------------------------------------------------------------------------
2531 snd_trident_ac97_control
2533 Description: enable/disable rear path for ac97
2534 ---------------------------------------------------------------------------*/
2536 static int snd_trident_ac97_control_info(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
* uinfo
)
2538 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
2540 uinfo
->value
.integer
.min
= 0;
2541 uinfo
->value
.integer
.max
= 1;
2545 static int snd_trident_ac97_control_get(snd_kcontrol_t
* kcontrol
,
2546 snd_ctl_elem_value_t
* ucontrol
)
2548 trident_t
*trident
= snd_kcontrol_chip(kcontrol
);
2551 spin_lock_irq(&trident
->reg_lock
);
2552 val
= trident
->ac97_ctrl
= inl(TRID_REG(trident
, NX_ACR0_AC97_COM_STAT
));
2553 ucontrol
->value
.integer
.value
[0] = (val
& (1 << kcontrol
->private_value
)) ? 1 : 0;
2554 spin_unlock_irq(&trident
->reg_lock
);
2558 static int snd_trident_ac97_control_put(snd_kcontrol_t
* kcontrol
,
2559 snd_ctl_elem_value_t
* ucontrol
)
2561 trident_t
*trident
= snd_kcontrol_chip(kcontrol
);
2565 spin_lock_irq(&trident
->reg_lock
);
2566 val
= trident
->ac97_ctrl
= inl(TRID_REG(trident
, NX_ACR0_AC97_COM_STAT
));
2567 val
&= ~(1 << kcontrol
->private_value
);
2568 if (ucontrol
->value
.integer
.value
[0])
2569 val
|= 1 << kcontrol
->private_value
;
2570 change
= val
!= trident
->ac97_ctrl
;
2571 trident
->ac97_ctrl
= val
;
2572 outl(trident
->ac97_ctrl
= val
, TRID_REG(trident
, NX_ACR0_AC97_COM_STAT
));
2573 spin_unlock_irq(&trident
->reg_lock
);
2577 static snd_kcontrol_new_t snd_trident_ac97_rear_control __devinitdata
=
2579 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2580 .name
= "Rear Path",
2581 .info
= snd_trident_ac97_control_info
,
2582 .get
= snd_trident_ac97_control_get
,
2583 .put
= snd_trident_ac97_control_put
,
2587 /*---------------------------------------------------------------------------
2588 snd_trident_vol_control
2590 Description: wave & music volume control
2591 ---------------------------------------------------------------------------*/
2593 static int snd_trident_vol_control_info(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
* uinfo
)
2595 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2597 uinfo
->value
.integer
.min
= 0;
2598 uinfo
->value
.integer
.max
= 255;
2602 static int snd_trident_vol_control_get(snd_kcontrol_t
* kcontrol
,
2603 snd_ctl_elem_value_t
* ucontrol
)
2605 trident_t
*trident
= snd_kcontrol_chip(kcontrol
);
2608 val
= trident
->musicvol_wavevol
;
2609 ucontrol
->value
.integer
.value
[0] = 255 - ((val
>> kcontrol
->private_value
) & 0xff);
2610 ucontrol
->value
.integer
.value
[1] = 255 - ((val
>> (kcontrol
->private_value
+ 8)) & 0xff);
2614 static int snd_trident_vol_control_put(snd_kcontrol_t
* kcontrol
,
2615 snd_ctl_elem_value_t
* ucontrol
)
2617 trident_t
*trident
= snd_kcontrol_chip(kcontrol
);
2621 spin_lock_irq(&trident
->reg_lock
);
2622 val
= trident
->musicvol_wavevol
;
2623 val
&= ~(0xffff << kcontrol
->private_value
);
2624 val
|= ((255 - (ucontrol
->value
.integer
.value
[0] & 0xff)) |
2625 ((255 - (ucontrol
->value
.integer
.value
[1] & 0xff)) << 8)) << kcontrol
->private_value
;
2626 change
= val
!= trident
->musicvol_wavevol
;
2627 outl(trident
->musicvol_wavevol
= val
, TRID_REG(trident
, T4D_MUSICVOL_WAVEVOL
));
2628 spin_unlock_irq(&trident
->reg_lock
);
2632 static snd_kcontrol_new_t snd_trident_vol_music_control __devinitdata
=
2634 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2635 .name
= "Music Playback Volume",
2636 .info
= snd_trident_vol_control_info
,
2637 .get
= snd_trident_vol_control_get
,
2638 .put
= snd_trident_vol_control_put
,
2639 .private_value
= 16,
2642 static snd_kcontrol_new_t snd_trident_vol_wave_control __devinitdata
=
2644 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2645 .name
= "Wave Playback Volume",
2646 .info
= snd_trident_vol_control_info
,
2647 .get
= snd_trident_vol_control_get
,
2648 .put
= snd_trident_vol_control_put
,
2652 /*---------------------------------------------------------------------------
2653 snd_trident_pcm_vol_control
2655 Description: PCM front volume control
2656 ---------------------------------------------------------------------------*/
2658 static int snd_trident_pcm_vol_control_info(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
* uinfo
)
2660 trident_t
*trident
= snd_kcontrol_chip(kcontrol
);
2662 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2664 uinfo
->value
.integer
.min
= 0;
2665 uinfo
->value
.integer
.max
= 255;
2666 if (trident
->device
== TRIDENT_DEVICE_ID_SI7018
)
2667 uinfo
->value
.integer
.max
= 1023;
2671 static int snd_trident_pcm_vol_control_get(snd_kcontrol_t
* kcontrol
,
2672 snd_ctl_elem_value_t
* ucontrol
)
2674 trident_t
*trident
= snd_kcontrol_chip(kcontrol
);
2675 snd_trident_pcm_mixer_t
*mix
= &trident
->pcm_mixer
[snd_ctl_get_ioffnum(kcontrol
, &ucontrol
->id
)];
2677 if (trident
->device
== TRIDENT_DEVICE_ID_SI7018
) {
2678 ucontrol
->value
.integer
.value
[0] = 1023 - mix
->vol
;
2680 ucontrol
->value
.integer
.value
[0] = 255 - (mix
->vol
>>2);
2685 static int snd_trident_pcm_vol_control_put(snd_kcontrol_t
* kcontrol
,
2686 snd_ctl_elem_value_t
* ucontrol
)
2688 trident_t
*trident
= snd_kcontrol_chip(kcontrol
);
2689 snd_trident_pcm_mixer_t
*mix
= &trident
->pcm_mixer
[snd_ctl_get_ioffnum(kcontrol
, &ucontrol
->id
)];
2693 if (trident
->device
== TRIDENT_DEVICE_ID_SI7018
) {
2694 val
= 1023 - (ucontrol
->value
.integer
.value
[0] & 1023);
2696 val
= (255 - (ucontrol
->value
.integer
.value
[0] & 255)) << 2;
2698 spin_lock_irq(&trident
->reg_lock
);
2699 change
= val
!= mix
->vol
;
2701 if (mix
->voice
!= NULL
)
2702 snd_trident_write_vol_reg(trident
, mix
->voice
, val
);
2703 spin_unlock_irq(&trident
->reg_lock
);
2707 static snd_kcontrol_new_t snd_trident_pcm_vol_control __devinitdata
=
2709 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2710 .name
= "PCM Front Playback Volume",
2711 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
| SNDRV_CTL_ELEM_ACCESS_INACTIVE
,
2713 .info
= snd_trident_pcm_vol_control_info
,
2714 .get
= snd_trident_pcm_vol_control_get
,
2715 .put
= snd_trident_pcm_vol_control_put
,
2718 /*---------------------------------------------------------------------------
2719 snd_trident_pcm_pan_control
2721 Description: PCM front pan control
2722 ---------------------------------------------------------------------------*/
2724 static int snd_trident_pcm_pan_control_info(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
* uinfo
)
2726 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2728 uinfo
->value
.integer
.min
= 0;
2729 uinfo
->value
.integer
.max
= 127;
2733 static int snd_trident_pcm_pan_control_get(snd_kcontrol_t
* kcontrol
,
2734 snd_ctl_elem_value_t
* ucontrol
)
2736 trident_t
*trident
= snd_kcontrol_chip(kcontrol
);
2737 snd_trident_pcm_mixer_t
*mix
= &trident
->pcm_mixer
[snd_ctl_get_ioffnum(kcontrol
, &ucontrol
->id
)];
2739 ucontrol
->value
.integer
.value
[0] = mix
->pan
;
2740 if (ucontrol
->value
.integer
.value
[0] & 0x40) {
2741 ucontrol
->value
.integer
.value
[0] = (0x3f - (ucontrol
->value
.integer
.value
[0] & 0x3f));
2743 ucontrol
->value
.integer
.value
[0] |= 0x40;
2748 static int snd_trident_pcm_pan_control_put(snd_kcontrol_t
* kcontrol
,
2749 snd_ctl_elem_value_t
* ucontrol
)
2751 trident_t
*trident
= snd_kcontrol_chip(kcontrol
);
2752 snd_trident_pcm_mixer_t
*mix
= &trident
->pcm_mixer
[snd_ctl_get_ioffnum(kcontrol
, &ucontrol
->id
)];
2756 if (ucontrol
->value
.integer
.value
[0] & 0x40)
2757 val
= ucontrol
->value
.integer
.value
[0] & 0x3f;
2759 val
= (0x3f - (ucontrol
->value
.integer
.value
[0] & 0x3f)) | 0x40;
2760 spin_lock_irq(&trident
->reg_lock
);
2761 change
= val
!= mix
->pan
;
2763 if (mix
->voice
!= NULL
)
2764 snd_trident_write_pan_reg(trident
, mix
->voice
, val
);
2765 spin_unlock_irq(&trident
->reg_lock
);
2769 static snd_kcontrol_new_t snd_trident_pcm_pan_control __devinitdata
=
2771 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2772 .name
= "PCM Pan Playback Control",
2773 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
| SNDRV_CTL_ELEM_ACCESS_INACTIVE
,
2775 .info
= snd_trident_pcm_pan_control_info
,
2776 .get
= snd_trident_pcm_pan_control_get
,
2777 .put
= snd_trident_pcm_pan_control_put
,
2780 /*---------------------------------------------------------------------------
2781 snd_trident_pcm_rvol_control
2783 Description: PCM reverb volume control
2784 ---------------------------------------------------------------------------*/
2786 static int snd_trident_pcm_rvol_control_info(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
* uinfo
)
2788 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2790 uinfo
->value
.integer
.min
= 0;
2791 uinfo
->value
.integer
.max
= 127;
2795 static int snd_trident_pcm_rvol_control_get(snd_kcontrol_t
* kcontrol
,
2796 snd_ctl_elem_value_t
* ucontrol
)
2798 trident_t
*trident
= snd_kcontrol_chip(kcontrol
);
2799 snd_trident_pcm_mixer_t
*mix
= &trident
->pcm_mixer
[snd_ctl_get_ioffnum(kcontrol
, &ucontrol
->id
)];
2801 ucontrol
->value
.integer
.value
[0] = 127 - mix
->rvol
;
2805 static int snd_trident_pcm_rvol_control_put(snd_kcontrol_t
* kcontrol
,
2806 snd_ctl_elem_value_t
* ucontrol
)
2808 trident_t
*trident
= snd_kcontrol_chip(kcontrol
);
2809 snd_trident_pcm_mixer_t
*mix
= &trident
->pcm_mixer
[snd_ctl_get_ioffnum(kcontrol
, &ucontrol
->id
)];
2813 val
= 0x7f - (ucontrol
->value
.integer
.value
[0] & 0x7f);
2814 spin_lock_irq(&trident
->reg_lock
);
2815 change
= val
!= mix
->rvol
;
2817 if (mix
->voice
!= NULL
)
2818 snd_trident_write_rvol_reg(trident
, mix
->voice
, val
);
2819 spin_unlock_irq(&trident
->reg_lock
);
2823 static snd_kcontrol_new_t snd_trident_pcm_rvol_control __devinitdata
=
2825 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2826 .name
= "PCM Reverb Playback Volume",
2827 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
| SNDRV_CTL_ELEM_ACCESS_INACTIVE
,
2829 .info
= snd_trident_pcm_rvol_control_info
,
2830 .get
= snd_trident_pcm_rvol_control_get
,
2831 .put
= snd_trident_pcm_rvol_control_put
,
2834 /*---------------------------------------------------------------------------
2835 snd_trident_pcm_cvol_control
2837 Description: PCM chorus volume control
2838 ---------------------------------------------------------------------------*/
2840 static int snd_trident_pcm_cvol_control_info(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
* uinfo
)
2842 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2844 uinfo
->value
.integer
.min
= 0;
2845 uinfo
->value
.integer
.max
= 127;
2849 static int snd_trident_pcm_cvol_control_get(snd_kcontrol_t
* kcontrol
,
2850 snd_ctl_elem_value_t
* ucontrol
)
2852 trident_t
*trident
= snd_kcontrol_chip(kcontrol
);
2853 snd_trident_pcm_mixer_t
*mix
= &trident
->pcm_mixer
[snd_ctl_get_ioffnum(kcontrol
, &ucontrol
->id
)];
2855 ucontrol
->value
.integer
.value
[0] = 127 - mix
->cvol
;
2859 static int snd_trident_pcm_cvol_control_put(snd_kcontrol_t
* kcontrol
,
2860 snd_ctl_elem_value_t
* ucontrol
)
2862 trident_t
*trident
= snd_kcontrol_chip(kcontrol
);
2863 snd_trident_pcm_mixer_t
*mix
= &trident
->pcm_mixer
[snd_ctl_get_ioffnum(kcontrol
, &ucontrol
->id
)];
2867 val
= 0x7f - (ucontrol
->value
.integer
.value
[0] & 0x7f);
2868 spin_lock_irq(&trident
->reg_lock
);
2869 change
= val
!= mix
->cvol
;
2871 if (mix
->voice
!= NULL
)
2872 snd_trident_write_cvol_reg(trident
, mix
->voice
, val
);
2873 spin_unlock_irq(&trident
->reg_lock
);
2877 static snd_kcontrol_new_t snd_trident_pcm_cvol_control __devinitdata
=
2879 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2880 .name
= "PCM Chorus Playback Volume",
2881 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
| SNDRV_CTL_ELEM_ACCESS_INACTIVE
,
2883 .info
= snd_trident_pcm_cvol_control_info
,
2884 .get
= snd_trident_pcm_cvol_control_get
,
2885 .put
= snd_trident_pcm_cvol_control_put
,
2888 static void snd_trident_notify_pcm_change1(snd_card_t
* card
, snd_kcontrol_t
*kctl
, int num
, int activate
)
2890 snd_ctl_elem_id_t id
;
2892 snd_runtime_check(kctl
!= NULL
, return);
2894 kctl
->vd
[num
].access
&= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE
;
2896 kctl
->vd
[num
].access
|= SNDRV_CTL_ELEM_ACCESS_INACTIVE
;
2897 snd_ctl_notify(card
, SNDRV_CTL_EVENT_MASK_VALUE
|
2898 SNDRV_CTL_EVENT_MASK_INFO
,
2899 snd_ctl_build_ioff(&id
, kctl
, num
));
2902 static void snd_trident_notify_pcm_change(trident_t
*trident
, snd_trident_pcm_mixer_t
*tmix
, int num
, int activate
)
2904 snd_trident_notify_pcm_change1(trident
->card
, trident
->ctl_vol
, num
, activate
);
2905 snd_trident_notify_pcm_change1(trident
->card
, trident
->ctl_pan
, num
, activate
);
2906 snd_trident_notify_pcm_change1(trident
->card
, trident
->ctl_rvol
, num
, activate
);
2907 snd_trident_notify_pcm_change1(trident
->card
, trident
->ctl_cvol
, num
, activate
);
2910 static int snd_trident_pcm_mixer_build(trident_t
*trident
, snd_trident_voice_t
*voice
, snd_pcm_substream_t
*substream
)
2912 snd_trident_pcm_mixer_t
*tmix
;
2914 snd_assert(trident
!= NULL
&& voice
!= NULL
&& substream
!= NULL
, return -EINVAL
);
2915 tmix
= &trident
->pcm_mixer
[substream
->number
];
2916 tmix
->voice
= voice
;
2917 tmix
->vol
= T4D_DEFAULT_PCM_VOL
;
2918 tmix
->pan
= T4D_DEFAULT_PCM_PAN
;
2919 tmix
->rvol
= T4D_DEFAULT_PCM_RVOL
;
2920 tmix
->cvol
= T4D_DEFAULT_PCM_CVOL
;
2921 snd_trident_notify_pcm_change(trident
, tmix
, substream
->number
, 1);
2925 static int snd_trident_pcm_mixer_free(trident_t
*trident
, snd_trident_voice_t
*voice
, snd_pcm_substream_t
*substream
)
2927 snd_trident_pcm_mixer_t
*tmix
;
2929 snd_assert(trident
!= NULL
&& substream
!= NULL
, return -EINVAL
);
2930 tmix
= &trident
->pcm_mixer
[substream
->number
];
2932 snd_trident_notify_pcm_change(trident
, tmix
, substream
->number
, 0);
2936 /*---------------------------------------------------------------------------
2939 Description: This routine registers the 4DWave device for mixer support.
2941 Paramters: trident - pointer to target device class for 4DWave.
2945 ---------------------------------------------------------------------------*/
2947 static int __devinit
snd_trident_mixer(trident_t
* trident
, int pcm_spdif_device
)
2949 ac97_template_t _ac97
;
2950 snd_card_t
* card
= trident
->card
;
2951 snd_kcontrol_t
*kctl
;
2952 snd_ctl_elem_value_t
*uctl
;
2953 int idx
, err
, retries
= 2;
2954 static ac97_bus_ops_t ops
= {
2955 .write
= snd_trident_codec_write
,
2956 .read
= snd_trident_codec_read
,
2959 uctl
= kcalloc(1, sizeof(*uctl
), GFP_KERNEL
);
2963 if ((err
= snd_ac97_bus(trident
->card
, 0, &ops
, NULL
, &trident
->ac97_bus
)) < 0)
2966 memset(&_ac97
, 0, sizeof(_ac97
));
2967 _ac97
.private_data
= trident
;
2968 trident
->ac97_detect
= 1;
2971 if ((err
= snd_ac97_mixer(trident
->ac97_bus
, &_ac97
, &trident
->ac97
)) < 0) {
2972 if (trident
->device
== TRIDENT_DEVICE_ID_SI7018
) {
2973 if ((err
= snd_trident_sis_reset(trident
)) < 0)
2982 /* secondary codec? */
2983 if (trident
->device
== TRIDENT_DEVICE_ID_SI7018
&&
2984 (inl(TRID_REG(trident
, SI_SERIAL_INTF_CTRL
)) & SI_AC97_PRIMARY_READY
) != 0) {
2986 err
= snd_ac97_mixer(trident
->ac97_bus
, &_ac97
, &trident
->ac97_sec
);
2988 snd_printk("SI7018: the secondary codec - invalid access\n");
2989 #if 0 // only for my testing purpose --jk
2992 err
= snd_ac97_modem(trident
->card
, &_ac97
, &mc97
);
2994 snd_printk("snd_ac97_modem returned error %i\n", err
);
2999 trident
->ac97_detect
= 0;
3001 if (trident
->device
!= TRIDENT_DEVICE_ID_SI7018
) {
3002 if ((err
= snd_ctl_add(card
, kctl
= snd_ctl_new1(&snd_trident_vol_wave_control
, trident
))) < 0)
3004 kctl
->put(kctl
, uctl
);
3005 if ((err
= snd_ctl_add(card
, kctl
= snd_ctl_new1(&snd_trident_vol_music_control
, trident
))) < 0)
3007 kctl
->put(kctl
, uctl
);
3008 outl(trident
->musicvol_wavevol
= 0x00000000, TRID_REG(trident
, T4D_MUSICVOL_WAVEVOL
));
3010 outl(trident
->musicvol_wavevol
= 0xffff0000, TRID_REG(trident
, T4D_MUSICVOL_WAVEVOL
));
3013 for (idx
= 0; idx
< 32; idx
++) {
3014 snd_trident_pcm_mixer_t
*tmix
;
3016 tmix
= &trident
->pcm_mixer
[idx
];
3019 if ((trident
->ctl_vol
= snd_ctl_new1(&snd_trident_pcm_vol_control
, trident
)) == NULL
)
3021 if ((err
= snd_ctl_add(card
, trident
->ctl_vol
)))
3024 if ((trident
->ctl_pan
= snd_ctl_new1(&snd_trident_pcm_pan_control
, trident
)) == NULL
)
3026 if ((err
= snd_ctl_add(card
, trident
->ctl_pan
)))
3029 if ((trident
->ctl_rvol
= snd_ctl_new1(&snd_trident_pcm_rvol_control
, trident
)) == NULL
)
3031 if ((err
= snd_ctl_add(card
, trident
->ctl_rvol
)))
3034 if ((trident
->ctl_cvol
= snd_ctl_new1(&snd_trident_pcm_cvol_control
, trident
)) == NULL
)
3036 if ((err
= snd_ctl_add(card
, trident
->ctl_cvol
)))
3039 if (trident
->device
== TRIDENT_DEVICE_ID_NX
) {
3040 if ((err
= snd_ctl_add(card
, kctl
= snd_ctl_new1(&snd_trident_ac97_rear_control
, trident
))) < 0)
3042 kctl
->put(kctl
, uctl
);
3044 if (trident
->device
== TRIDENT_DEVICE_ID_NX
|| trident
->device
== TRIDENT_DEVICE_ID_SI7018
) {
3046 kctl
= snd_ctl_new1(&snd_trident_spdif_control
, trident
);
3051 if (trident
->ac97
->ext_id
& AC97_EI_SPDIF
)
3053 if (trident
->ac97_sec
&& (trident
->ac97_sec
->ext_id
& AC97_EI_SPDIF
))
3055 idx
= kctl
->id
.index
;
3056 if ((err
= snd_ctl_add(card
, kctl
)) < 0)
3058 kctl
->put(kctl
, uctl
);
3060 kctl
= snd_ctl_new1(&snd_trident_spdif_default
, trident
);
3065 kctl
->id
.index
= idx
;
3066 kctl
->id
.device
= pcm_spdif_device
;
3067 if ((err
= snd_ctl_add(card
, kctl
)) < 0)
3070 kctl
= snd_ctl_new1(&snd_trident_spdif_mask
, trident
);
3075 kctl
->id
.index
= idx
;
3076 kctl
->id
.device
= pcm_spdif_device
;
3077 if ((err
= snd_ctl_add(card
, kctl
)) < 0)
3080 kctl
= snd_ctl_new1(&snd_trident_spdif_stream
, trident
);
3085 kctl
->id
.index
= idx
;
3086 kctl
->id
.device
= pcm_spdif_device
;
3087 if ((err
= snd_ctl_add(card
, kctl
)) < 0)
3089 trident
->spdif_pcm_ctl
= kctl
;
3105 * gameport interface
3108 #if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))
3110 typedef struct snd_trident_gameport
{
3111 struct gameport info
;
3113 } trident_gameport_t
;
3115 static unsigned char snd_trident_gameport_read(struct gameport
*gameport
)
3117 trident_gameport_t
*gp
= (trident_gameport_t
*)gameport
;
3119 snd_assert(gp
, return 0);
3121 return inb(TRID_REG(chip
, GAMEPORT_LEGACY
));
3124 static void snd_trident_gameport_trigger(struct gameport
*gameport
)
3126 trident_gameport_t
*gp
= (trident_gameport_t
*)gameport
;
3128 snd_assert(gp
, return);
3130 outb(0xff, TRID_REG(chip
, GAMEPORT_LEGACY
));
3133 static int snd_trident_gameport_cooked_read(struct gameport
*gameport
, int *axes
, int *buttons
)
3135 trident_gameport_t
*gp
= (trident_gameport_t
*)gameport
;
3139 snd_assert(gp
, return 0);
3142 *buttons
= (~inb(TRID_REG(chip
, GAMEPORT_LEGACY
)) >> 4) & 0xf;
3144 for (i
= 0; i
< 4; i
++) {
3145 axes
[i
] = inw(TRID_REG(chip
, GAMEPORT_AXES
+ i
* 2));
3146 if (axes
[i
] == 0xffff) axes
[i
] = -1;
3152 static int snd_trident_gameport_open(struct gameport
*gameport
, int mode
)
3154 trident_gameport_t
*gp
= (trident_gameport_t
*)gameport
;
3156 snd_assert(gp
, return -1);
3160 case GAMEPORT_MODE_COOKED
:
3161 outb(GAMEPORT_MODE_ADC
, TRID_REG(chip
, GAMEPORT_GCR
));
3162 set_current_state(TASK_UNINTERRUPTIBLE
);
3163 schedule_timeout(1 + 20 * HZ
/ 1000); /* 20msec */
3165 case GAMEPORT_MODE_RAW
:
3166 outb(0, TRID_REG(chip
, GAMEPORT_GCR
));
3173 void __devinit
snd_trident_gameport(trident_t
*chip
)
3175 trident_gameport_t
*gp
;
3176 gp
= kmalloc(sizeof(*gp
), GFP_KERNEL
);
3178 snd_printk("cannot allocate gameport area\n");
3181 memset(gp
, 0, sizeof(*gp
));
3184 gp
->info
.read
= snd_trident_gameport_read
;
3185 gp
->info
.trigger
= snd_trident_gameport_trigger
;
3186 gp
->info
.cooked_read
= snd_trident_gameport_cooked_read
;
3187 gp
->info
.open
= snd_trident_gameport_open
;
3188 chip
->gameport
= gp
;
3190 gameport_register_port(&gp
->info
);
3194 void __devinit
snd_trident_gameport(trident_t
*chip
)
3197 #endif /* CONFIG_GAMEPORT */
3202 inline static void do_delay(trident_t
*chip
)
3204 set_current_state(TASK_UNINTERRUPTIBLE
);
3205 schedule_timeout(1);
3212 static int snd_trident_sis_reset(trident_t
*trident
)
3214 unsigned long end_time
;
3218 r
= trident
->in_suspend
? 0 : 2; /* count of retries */
3220 pci_write_config_byte(trident
->pci
, 0x46, 0x04); /* SOFTWARE RESET */
3222 pci_write_config_byte(trident
->pci
, 0x46, 0x00);
3224 /* disable AC97 GPIO interrupt */
3225 outb(0x00, TRID_REG(trident
, SI_AC97_GPIO
));
3226 /* initialize serial interface, force cold reset */
3227 i
= PCMOUT
|SURROUT
|CENTEROUT
|LFEOUT
|SECONDARY_ID
|COLD_RESET
;
3228 outl(i
, TRID_REG(trident
, SI_SERIAL_INTF_CTRL
));
3230 /* remove cold reset */
3232 outl(i
, TRID_REG(trident
, SI_SERIAL_INTF_CTRL
));
3234 /* wait, until the codec is ready */
3235 end_time
= (jiffies
+ (HZ
* 3) / 4) + 1;
3237 if ((inl(TRID_REG(trident
, SI_SERIAL_INTF_CTRL
)) & SI_AC97_PRIMARY_READY
) != 0)
3240 } while (time_after_eq(end_time
, jiffies
));
3241 snd_printk("AC'97 codec ready error [0x%x]\n", inl(TRID_REG(trident
, SI_SERIAL_INTF_CTRL
)));
3243 end_time
= jiffies
+ HZ
;
3246 } while (time_after_eq(end_time
, jiffies
));
3247 goto __si7018_retry
;
3250 /* wait for the second codec */
3252 if ((inl(TRID_REG(trident
, SI_SERIAL_INTF_CTRL
)) & SI_AC97_SECONDARY_READY
) != 0)
3255 } while (time_after_eq(end_time
, jiffies
));
3256 /* enable 64 channel mode */
3257 outl(BANK_B_EN
, TRID_REG(trident
, T4D_LFO_GC_CIR
));
3265 static void snd_trident_proc_read(snd_info_entry_t
*entry
,
3266 snd_info_buffer_t
* buffer
)
3268 trident_t
*trident
= entry
->private_data
;
3271 switch (trident
->device
) {
3272 case TRIDENT_DEVICE_ID_SI7018
:
3273 s
= "SiS 7018 Audio";
3275 case TRIDENT_DEVICE_ID_DX
:
3276 s
= "Trident 4DWave PCI DX";
3278 case TRIDENT_DEVICE_ID_NX
:
3279 s
= "Trident 4DWave PCI NX";
3284 snd_iprintf(buffer
, "%s\n\n", s
);
3285 snd_iprintf(buffer
, "Spurious IRQs : %d\n", trident
->spurious_irq_count
);
3286 snd_iprintf(buffer
, "Spurious IRQ dlta: %d\n", trident
->spurious_irq_max_delta
);
3287 if (trident
->device
== TRIDENT_DEVICE_ID_NX
|| trident
->device
== TRIDENT_DEVICE_ID_SI7018
)
3288 snd_iprintf(buffer
, "IEC958 Mixer Out : %s\n", trident
->spdif_ctrl
== 0x28 ? "on" : "off");
3289 if (trident
->device
== TRIDENT_DEVICE_ID_NX
) {
3290 snd_iprintf(buffer
, "Rear Speakers : %s\n", trident
->ac97_ctrl
& 0x00000010 ? "on" : "off");
3291 if (trident
->tlb
.entries
) {
3292 snd_iprintf(buffer
,"\nVirtual Memory\n");
3293 snd_iprintf(buffer
, "Memory Maximum : %d\n", trident
->tlb
.memhdr
->size
);
3294 snd_iprintf(buffer
, "Memory Used : %d\n", trident
->tlb
.memhdr
->used
);
3295 snd_iprintf(buffer
, "Memory Free : %d\n", snd_util_mem_avail(trident
->tlb
.memhdr
));
3298 #if defined(CONFIG_SND_SEQUENCER) || (defined(MODULE) && defined(CONFIG_SND_SEQUENCER_MODULE))
3299 snd_iprintf(buffer
,"\nWavetable Synth\n");
3300 snd_iprintf(buffer
, "Memory Maximum : %d\n", trident
->synth
.max_size
);
3301 snd_iprintf(buffer
, "Memory Used : %d\n", trident
->synth
.current_size
);
3302 snd_iprintf(buffer
, "Memory Free : %d\n", (trident
->synth
.max_size
-trident
->synth
.current_size
));
3306 static void __devinit
snd_trident_proc_init(trident_t
* trident
)
3308 snd_info_entry_t
*entry
;
3309 const char *s
= "trident";
3311 if (trident
->device
== TRIDENT_DEVICE_ID_SI7018
)
3313 if (! snd_card_proc_new(trident
->card
, s
, &entry
))
3314 snd_info_set_text_ops(entry
, trident
, 1024, snd_trident_proc_read
);
3317 static int snd_trident_dev_free(snd_device_t
*device
)
3319 trident_t
*trident
= device
->device_data
;
3320 return snd_trident_free(trident
);
3323 /*---------------------------------------------------------------------------
3324 snd_trident_tlb_alloc
3326 Description: Allocate and set up the TLB page table on 4D NX.
3327 Each entry has 4 bytes (physical PCI address).
3329 Paramters: trident - pointer to target device class for 4DWave.
3331 Returns: 0 or negative error code
3333 ---------------------------------------------------------------------------*/
3335 static int __devinit
snd_trident_tlb_alloc(trident_t
*trident
)
3339 /* TLB array must be aligned to 16kB !!! so we allocate
3340 32kB region and correct offset when necessary */
3342 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV
, snd_dma_pci_data(trident
->pci
),
3343 2 * SNDRV_TRIDENT_MAX_PAGES
* 4, &trident
->tlb
.buffer
) < 0) {
3344 snd_printk(KERN_ERR
"trident: unable to allocate TLB buffer\n");
3347 trident
->tlb
.entries
= (unsigned int*)(((unsigned long)trident
->tlb
.buffer
.area
+ SNDRV_TRIDENT_MAX_PAGES
* 4 - 1) & ~(SNDRV_TRIDENT_MAX_PAGES
* 4 - 1));
3348 trident
->tlb
.entries_dmaaddr
= (trident
->tlb
.buffer
.addr
+ SNDRV_TRIDENT_MAX_PAGES
* 4 - 1) & ~(SNDRV_TRIDENT_MAX_PAGES
* 4 - 1);
3349 /* allocate shadow TLB page table (virtual addresses) */
3350 trident
->tlb
.shadow_entries
= (unsigned long *)vmalloc(SNDRV_TRIDENT_MAX_PAGES
*sizeof(unsigned long));
3351 if (trident
->tlb
.shadow_entries
== NULL
) {
3352 snd_printk(KERN_ERR
"trident: unable to allocate shadow TLB entries\n");
3355 /* allocate and setup silent page and initialise TLB entries */
3356 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV
, snd_dma_pci_data(trident
->pci
),
3357 SNDRV_TRIDENT_PAGE_SIZE
, &trident
->tlb
.silent_page
) < 0) {
3358 snd_printk(KERN_ERR
"trident: unable to allocate silent page\n");
3361 memset(trident
->tlb
.silent_page
.area
, 0, SNDRV_TRIDENT_PAGE_SIZE
);
3362 for (i
= 0; i
< SNDRV_TRIDENT_MAX_PAGES
; i
++) {
3363 trident
->tlb
.entries
[i
] = cpu_to_le32(trident
->tlb
.silent_page
.addr
& ~(SNDRV_TRIDENT_PAGE_SIZE
-1));
3364 trident
->tlb
.shadow_entries
[i
] = (unsigned long)trident
->tlb
.silent_page
.area
;
3367 /* use emu memory block manager code to manage tlb page allocation */
3368 trident
->tlb
.memhdr
= snd_util_memhdr_new(SNDRV_TRIDENT_PAGE_SIZE
* SNDRV_TRIDENT_MAX_PAGES
);
3369 if (trident
->tlb
.memhdr
== NULL
)
3372 trident
->tlb
.memhdr
->block_extra_size
= sizeof(snd_trident_memblk_arg_t
);
3377 * initialize 4D DX chip
3380 static void snd_trident_stop_all_voices(trident_t
*trident
)
3382 outl(0xffffffff, TRID_REG(trident
, T4D_STOP_A
));
3383 outl(0xffffffff, TRID_REG(trident
, T4D_STOP_B
));
3384 outl(0, TRID_REG(trident
, T4D_AINTEN_A
));
3385 outl(0, TRID_REG(trident
, T4D_AINTEN_B
));
3388 static int snd_trident_4d_dx_init(trident_t
*trident
)
3390 struct pci_dev
*pci
= trident
->pci
;
3391 unsigned long end_time
;
3393 /* reset the legacy configuration and whole audio/wavetable block */
3394 pci_write_config_dword(pci
, 0x40, 0); /* DDMA */
3395 pci_write_config_byte(pci
, 0x44, 0); /* ports */
3396 pci_write_config_byte(pci
, 0x45, 0); /* Legacy DMA */
3397 pci_write_config_byte(pci
, 0x46, 4); /* reset */
3399 pci_write_config_byte(pci
, 0x46, 0); /* release reset */
3402 /* warm reset of the AC'97 codec */
3403 outl(0x00000001, TRID_REG(trident
, DX_ACR2_AC97_COM_STAT
));
3405 outl(0x00000000, TRID_REG(trident
, DX_ACR2_AC97_COM_STAT
));
3406 /* DAC on, disable SB IRQ and try to force ADC valid signal */
3407 trident
->ac97_ctrl
= 0x0000004a;
3408 outl(trident
->ac97_ctrl
, TRID_REG(trident
, DX_ACR2_AC97_COM_STAT
));
3409 /* wait, until the codec is ready */
3410 end_time
= (jiffies
+ (HZ
* 3) / 4) + 1;
3412 if ((inl(TRID_REG(trident
, DX_ACR2_AC97_COM_STAT
)) & 0x0010) != 0)
3415 } while (time_after_eq(end_time
, jiffies
));
3416 snd_printk(KERN_ERR
"AC'97 codec ready error\n");
3420 snd_trident_stop_all_voices(trident
);
3426 * initialize 4D NX chip
3428 static int snd_trident_4d_nx_init(trident_t
*trident
)
3430 struct pci_dev
*pci
= trident
->pci
;
3431 unsigned long end_time
;
3433 /* reset the legacy configuration and whole audio/wavetable block */
3434 pci_write_config_dword(pci
, 0x40, 0); /* DDMA */
3435 pci_write_config_byte(pci
, 0x44, 0); /* ports */
3436 pci_write_config_byte(pci
, 0x45, 0); /* Legacy DMA */
3438 pci_write_config_byte(pci
, 0x46, 1); /* reset */
3440 pci_write_config_byte(pci
, 0x46, 0); /* release reset */
3443 /* warm reset of the AC'97 codec */
3444 outl(0x00000001, TRID_REG(trident
, NX_ACR0_AC97_COM_STAT
));
3446 outl(0x00000000, TRID_REG(trident
, NX_ACR0_AC97_COM_STAT
));
3447 /* wait, until the codec is ready */
3448 end_time
= (jiffies
+ (HZ
* 3) / 4) + 1;
3450 if ((inl(TRID_REG(trident
, NX_ACR0_AC97_COM_STAT
)) & 0x0008) != 0)
3453 } while (time_after_eq(end_time
, jiffies
));
3454 snd_printk(KERN_ERR
"AC'97 codec ready error [0x%x]\n", inl(TRID_REG(trident
, NX_ACR0_AC97_COM_STAT
)));
3459 trident
->ac97_ctrl
= 0x00000002;
3460 outl(trident
->ac97_ctrl
, TRID_REG(trident
, NX_ACR0_AC97_COM_STAT
));
3461 /* disable SB IRQ */
3462 outl(NX_SB_IRQ_DISABLE
, TRID_REG(trident
, T4D_MISCINT
));
3464 snd_trident_stop_all_voices(trident
);
3466 if (trident
->tlb
.entries
!= NULL
) {
3468 /* enable virtual addressing via TLB */
3469 i
= trident
->tlb
.entries_dmaaddr
;
3471 outl(i
, TRID_REG(trident
, NX_TLBC
));
3473 outl(0, TRID_REG(trident
, NX_TLBC
));
3475 /* initialize S/PDIF */
3476 outl(trident
->spdif_bits
, TRID_REG(trident
, NX_SPCSTATUS
));
3477 outb(trident
->spdif_ctrl
, TRID_REG(trident
, NX_SPCTRL_SPCSO
+ 3));
3483 * initialize sis7018 chip
3485 static int snd_trident_sis_init(trident_t
*trident
)
3489 if ((err
= snd_trident_sis_reset(trident
)) < 0)
3492 snd_trident_stop_all_voices(trident
);
3494 /* initialize S/PDIF */
3495 outl(trident
->spdif_bits
, TRID_REG(trident
, SI_SPDIF_CS
));
3500 /*---------------------------------------------------------------------------
3503 Description: This routine will create the device specific class for
3504 the 4DWave card. It will also perform basic initialization.
3506 Paramters: card - which card to create
3507 pci - interface to PCI bus resource info
3508 dma1ptr - playback dma buffer
3509 dma2ptr - capture dma buffer
3510 irqptr - interrupt resource info
3512 Returns: 4DWave device class private data
3514 ---------------------------------------------------------------------------*/
3516 int __devinit
snd_trident_create(snd_card_t
* card
,
3517 struct pci_dev
*pci
,
3519 int pcm_spdif_device
,
3520 int max_wavetable_size
,
3521 trident_t
** rtrident
)
3525 snd_trident_voice_t
*voice
;
3526 snd_trident_pcm_mixer_t
*tmix
;
3527 static snd_device_ops_t ops
= {
3528 .dev_free
= snd_trident_dev_free
,
3533 /* enable PCI device */
3534 if ((err
= pci_enable_device(pci
)) < 0)
3536 /* check, if we can restrict PCI DMA transfers to 30 bits */
3537 if (pci_set_dma_mask(pci
, 0x3fffffff) < 0 ||
3538 pci_set_consistent_dma_mask(pci
, 0x3fffffff) < 0) {
3539 snd_printk("architecture does not support 30bit PCI busmaster DMA\n");
3543 trident
= kcalloc(1, sizeof(*trident
), GFP_KERNEL
);
3544 if (trident
== NULL
)
3546 trident
->device
= (pci
->vendor
<< 16) | pci
->device
;
3547 trident
->card
= card
;
3549 spin_lock_init(&trident
->reg_lock
);
3550 spin_lock_init(&trident
->event_lock
);
3551 spin_lock_init(&trident
->voice_alloc
);
3552 if (pcm_streams
< 1)
3554 if (pcm_streams
> 32)
3556 trident
->ChanPCM
= pcm_streams
;
3557 if (max_wavetable_size
< 0 )
3558 max_wavetable_size
= 0;
3559 trident
->synth
.max_size
= max_wavetable_size
* 1024;
3562 trident
->midi_port
= TRID_REG(trident
, T4D_MPU401_BASE
);
3563 pci_set_master(pci
);
3565 if ((err
= pci_request_regions(pci
, "Trident Audio")) < 0) {
3569 trident
->port
= pci_resource_start(pci
, 0);
3571 if (request_irq(pci
->irq
, snd_trident_interrupt
, SA_INTERRUPT
|SA_SHIRQ
, "Trident Audio", (void *) trident
)) {
3572 snd_printk("unable to grab IRQ %d\n", pci
->irq
);
3573 snd_trident_free(trident
);
3576 trident
->irq
= pci
->irq
;
3578 /* allocate 16k-aligned TLB for NX cards */
3579 trident
->tlb
.entries
= NULL
;
3580 trident
->tlb
.buffer
.area
= NULL
;
3581 if (trident
->device
== TRIDENT_DEVICE_ID_NX
) {
3582 if ((err
= snd_trident_tlb_alloc(trident
)) < 0) {
3583 snd_trident_free(trident
);
3588 trident
->spdif_bits
= trident
->spdif_pcm_bits
= SNDRV_PCM_DEFAULT_CON_SPDIF
;
3590 /* initialize chip */
3591 switch (trident
->device
) {
3592 case TRIDENT_DEVICE_ID_DX
:
3593 err
= snd_trident_4d_dx_init(trident
);
3595 case TRIDENT_DEVICE_ID_NX
:
3596 err
= snd_trident_4d_nx_init(trident
);
3598 case TRIDENT_DEVICE_ID_SI7018
:
3599 err
= snd_trident_sis_init(trident
);
3606 snd_trident_free(trident
);
3610 if ((err
= snd_trident_mixer(trident
, pcm_spdif_device
)) < 0) {
3611 snd_trident_free(trident
);
3615 /* initialise synth voices */
3616 for (i
= 0; i
< 64; i
++) {
3617 voice
= &trident
->synth
.voices
[i
];
3619 voice
->trident
= trident
;
3621 /* initialize pcm mixer entries */
3622 for (i
= 0; i
< 32; i
++) {
3623 tmix
= &trident
->pcm_mixer
[i
];
3624 tmix
->vol
= T4D_DEFAULT_PCM_VOL
;
3625 tmix
->pan
= T4D_DEFAULT_PCM_PAN
;
3626 tmix
->rvol
= T4D_DEFAULT_PCM_RVOL
;
3627 tmix
->cvol
= T4D_DEFAULT_PCM_CVOL
;
3630 snd_trident_enable_eso(trident
);
3633 snd_card_set_pm_callback(card
, snd_trident_suspend
, snd_trident_resume
, trident
);
3635 snd_trident_proc_init(trident
);
3636 if ((err
= snd_device_new(card
, SNDRV_DEV_LOWLEVEL
, trident
, &ops
)) < 0) {
3637 snd_trident_free(trident
);
3640 snd_card_set_dev(card
, &pci
->dev
);
3641 *rtrident
= trident
;
3645 /*---------------------------------------------------------------------------
3648 Description: This routine will free the device specific class for
3651 Paramters: trident - device specific private data for 4DWave card
3655 ---------------------------------------------------------------------------*/
3657 int snd_trident_free(trident_t
*trident
)
3659 #if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))
3660 if (trident
->gameport
) {
3661 gameport_unregister_port(&trident
->gameport
->info
);
3662 kfree(trident
->gameport
);
3665 snd_trident_disable_eso(trident
);
3666 // Disable S/PDIF out
3667 if (trident
->device
== TRIDENT_DEVICE_ID_NX
)
3668 outb(0x00, TRID_REG(trident
, NX_SPCTRL_SPCSO
+ 3));
3669 else if (trident
->device
== TRIDENT_DEVICE_ID_SI7018
) {
3670 outl(0, TRID_REG(trident
, SI_SERIAL_INTF_CTRL
));
3672 if (trident
->tlb
.buffer
.area
) {
3673 outl(0, TRID_REG(trident
, NX_TLBC
));
3674 if (trident
->tlb
.memhdr
)
3675 snd_util_memhdr_free(trident
->tlb
.memhdr
);
3676 if (trident
->tlb
.silent_page
.area
)
3677 snd_dma_free_pages(&trident
->tlb
.silent_page
);
3678 if (trident
->tlb
.shadow_entries
)
3679 vfree(trident
->tlb
.shadow_entries
);
3680 snd_dma_free_pages(&trident
->tlb
.buffer
);
3682 if (trident
->irq
>= 0)
3683 free_irq(trident
->irq
, (void *)trident
);
3684 pci_release_regions(trident
->pci
);
3689 /*---------------------------------------------------------------------------
3690 snd_trident_interrupt
3692 Description: ISR for Trident 4DWave device
3694 Paramters: trident - device specific private data for 4DWave card
3696 Problems: It seems that Trident chips generates interrupts more than
3697 one time in special cases. The spurious interrupts are
3698 detected via sample timer (T4D_STIMER) and computing
3699 corresponding delta value. The limits are detected with
3700 the method try & fail so it is possible that it won't
3701 work on all computers. [jaroslav]
3705 ---------------------------------------------------------------------------*/
3707 static irqreturn_t
snd_trident_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
3709 trident_t
*trident
= dev_id
;
3710 unsigned int audio_int
, chn_int
, stimer
, channel
, mask
, tmp
;
3712 snd_trident_voice_t
*voice
;
3714 audio_int
= inl(TRID_REG(trident
, T4D_MISCINT
));
3715 if ((audio_int
& (ADDRESS_IRQ
|MPU401_IRQ
)) == 0)
3717 if (audio_int
& ADDRESS_IRQ
) {
3718 // get interrupt status for all channels
3719 spin_lock(&trident
->reg_lock
);
3720 stimer
= inl(TRID_REG(trident
, T4D_STIMER
)) & 0x00ffffff;
3721 chn_int
= inl(TRID_REG(trident
, T4D_AINT_A
));
3724 outl(chn_int
, TRID_REG(trident
, T4D_AINT_A
)); /* ack */
3726 chn_int
= inl(TRID_REG(trident
, T4D_AINT_B
));
3729 for (channel
= 63; channel
>= 32; channel
--) {
3730 mask
= 1 << (channel
&0x1f);
3731 if ((chn_int
& mask
) == 0)
3733 voice
= &trident
->synth
.voices
[channel
];
3734 if (!voice
->pcm
|| voice
->substream
== NULL
) {
3735 outl(mask
, TRID_REG(trident
, T4D_STOP_B
));
3738 delta
= (int)stimer
- (int)voice
->stimer
;
3741 if ((unsigned int)delta
< voice
->spurious_threshold
) {
3742 /* do some statistics here */
3743 trident
->spurious_irq_count
++;
3744 if (trident
->spurious_irq_max_delta
< (unsigned int)delta
)
3745 trident
->spurious_irq_max_delta
= delta
;
3748 voice
->stimer
= stimer
;
3750 if (!voice
->isync3
) {
3751 tmp
= inw(TRID_REG(trident
, T4D_SBBL_SBCL
));
3752 if (trident
->bDMAStart
& 0x40)
3755 tmp
= voice
->isync_max
- tmp
;
3757 tmp
= inl(TRID_REG(trident
, NX_SPCTRL_SPCSO
)) & 0x00ffffff;
3759 if (tmp
< voice
->isync_mark
) {
3761 tmp
= voice
->isync_ESO
- 7;
3763 tmp
= voice
->isync_ESO
+ 2;
3764 /* update ESO for IRQ voice to preserve sync */
3765 snd_trident_stop_voice(trident
, voice
->number
);
3766 snd_trident_write_eso_reg(trident
, voice
, tmp
);
3767 snd_trident_start_voice(trident
, voice
->number
);
3769 } else if (voice
->isync2
) {
3771 /* write original ESO and update CSO for IRQ voice to preserve sync */
3772 snd_trident_stop_voice(trident
, voice
->number
);
3773 snd_trident_write_cso_reg(trident
, voice
, voice
->isync_mark
);
3774 snd_trident_write_eso_reg(trident
, voice
, voice
->ESO
);
3775 snd_trident_start_voice(trident
, voice
->number
);
3779 /* update CSO for extra voice to preserve sync */
3780 snd_trident_stop_voice(trident
, voice
->extra
->number
);
3781 snd_trident_write_cso_reg(trident
, voice
->extra
, 0);
3782 snd_trident_start_voice(trident
, voice
->extra
->number
);
3785 spin_unlock(&trident
->reg_lock
);
3786 snd_pcm_period_elapsed(voice
->substream
);
3787 spin_lock(&trident
->reg_lock
);
3789 outl(chn_int
, TRID_REG(trident
, T4D_AINT_B
)); /* ack */
3791 spin_unlock(&trident
->reg_lock
);
3793 if (audio_int
& MPU401_IRQ
) {
3794 if (trident
->rmidi
) {
3795 snd_mpu401_uart_interrupt(irq
, trident
->rmidi
->private_data
, regs
);
3797 inb(TRID_REG(trident
, T4D_MPUR0
));
3800 // outl((ST_TARGET_REACHED | MIXER_OVERFLOW | MIXER_UNDERFLOW), TRID_REG(trident, T4D_MISCINT));
3804 /*---------------------------------------------------------------------------
3805 snd_trident_attach_synthesizer, snd_trident_detach_synthesizer
3807 Description: Attach/detach synthesizer hooks
3809 Paramters: trident - device specific private data for 4DWave card
3813 ---------------------------------------------------------------------------*/
3814 int snd_trident_attach_synthesizer(trident_t
*trident
)
3816 #if defined(CONFIG_SND_SEQUENCER) || (defined(MODULE) && defined(CONFIG_SND_SEQUENCER_MODULE))
3817 if (snd_seq_device_new(trident
->card
, 1, SNDRV_SEQ_DEV_ID_TRIDENT
,
3818 sizeof(trident_t
*), &trident
->seq_dev
) >= 0) {
3819 strcpy(trident
->seq_dev
->name
, "4DWave");
3820 *(trident_t
**)SNDRV_SEQ_DEVICE_ARGPTR(trident
->seq_dev
) = trident
;
3826 int snd_trident_detach_synthesizer(trident_t
*trident
)
3828 #if defined(CONFIG_SND_SEQUENCER) || (defined(MODULE) && defined(CONFIG_SND_SEQUENCER_MODULE))
3829 if (trident
->seq_dev
) {
3830 snd_device_free(trident
->card
, trident
->seq_dev
);
3831 trident
->seq_dev
= NULL
;
3837 snd_trident_voice_t
*snd_trident_alloc_voice(trident_t
* trident
, int type
, int client
, int port
)
3839 snd_trident_voice_t
*pvoice
;
3840 unsigned long flags
;
3843 spin_lock_irqsave(&trident
->voice_alloc
, flags
);
3844 if (type
== SNDRV_TRIDENT_VOICE_TYPE_PCM
) {
3845 idx
= snd_trident_allocate_pcm_channel(trident
);
3847 spin_unlock_irqrestore(&trident
->voice_alloc
, flags
);
3850 pvoice
= &trident
->synth
.voices
[idx
];
3853 pvoice
->capture
= 0;
3855 pvoice
->memblk
= NULL
;
3856 pvoice
->substream
= NULL
;
3857 spin_unlock_irqrestore(&trident
->voice_alloc
, flags
);
3860 if (type
== SNDRV_TRIDENT_VOICE_TYPE_SYNTH
) {
3861 idx
= snd_trident_allocate_synth_channel(trident
);
3863 spin_unlock_irqrestore(&trident
->voice_alloc
, flags
);
3866 pvoice
= &trident
->synth
.voices
[idx
];
3869 pvoice
->client
= client
;
3870 pvoice
->port
= port
;
3871 pvoice
->memblk
= NULL
;
3872 spin_unlock_irqrestore(&trident
->voice_alloc
, flags
);
3875 if (type
== SNDRV_TRIDENT_VOICE_TYPE_MIDI
) {
3877 spin_unlock_irqrestore(&trident
->voice_alloc
, flags
);
3881 void snd_trident_free_voice(trident_t
* trident
, snd_trident_voice_t
*voice
)
3883 unsigned long flags
;
3884 void (*private_free
)(snd_trident_voice_t
*);
3887 if (voice
== NULL
|| !voice
->use
)
3889 snd_trident_clear_voices(trident
, voice
->number
, voice
->number
);
3890 spin_lock_irqsave(&trident
->voice_alloc
, flags
);
3891 private_free
= voice
->private_free
;
3892 private_data
= voice
->private_data
;
3893 voice
->private_free
= NULL
;
3894 voice
->private_data
= NULL
;
3896 snd_trident_free_pcm_channel(trident
, voice
->number
);
3898 snd_trident_free_synth_channel(trident
, voice
->number
);
3899 voice
->use
= voice
->pcm
= voice
->synth
= voice
->midi
= 0;
3900 voice
->capture
= voice
->spdif
= 0;
3901 voice
->sample_ops
= NULL
;
3902 voice
->substream
= NULL
;
3903 voice
->extra
= NULL
;
3904 spin_unlock_irqrestore(&trident
->voice_alloc
, flags
);
3906 private_free(voice
);
3909 void snd_trident_clear_voices(trident_t
* trident
, unsigned short v_min
, unsigned short v_max
)
3911 unsigned int i
, val
, mask
[2] = { 0, 0 };
3913 snd_assert(v_min
<= 63, return);
3914 snd_assert(v_max
<= 63, return);
3915 for (i
= v_min
; i
<= v_max
; i
++)
3916 mask
[i
>> 5] |= 1 << (i
& 0x1f);
3918 outl(mask
[0], TRID_REG(trident
, T4D_STOP_A
));
3919 val
= inl(TRID_REG(trident
, T4D_AINTEN_A
));
3920 outl(val
& ~mask
[0], TRID_REG(trident
, T4D_AINTEN_A
));
3923 outl(mask
[1], TRID_REG(trident
, T4D_STOP_B
));
3924 val
= inl(TRID_REG(trident
, T4D_AINTEN_B
));
3925 outl(val
& ~mask
[1], TRID_REG(trident
, T4D_AINTEN_B
));
3930 static int snd_trident_suspend(snd_card_t
*card
, unsigned int state
)
3932 trident_t
*trident
= card
->pm_private_data
;
3934 trident
->in_suspend
= 1;
3935 snd_pcm_suspend_all(trident
->pcm
);
3936 if (trident
->foldback
)
3937 snd_pcm_suspend_all(trident
->foldback
);
3939 snd_pcm_suspend_all(trident
->spdif
);
3941 snd_ac97_suspend(trident
->ac97
);
3942 if (trident
->ac97_sec
)
3943 snd_ac97_suspend(trident
->ac97_sec
);
3945 switch (trident
->device
) {
3946 case TRIDENT_DEVICE_ID_DX
:
3947 case TRIDENT_DEVICE_ID_NX
:
3949 case TRIDENT_DEVICE_ID_SI7018
:
3952 snd_power_change_state(card
, SNDRV_CTL_POWER_D3hot
);
3956 static int snd_trident_resume(snd_card_t
*card
, unsigned int state
)
3958 trident_t
*trident
= card
->pm_private_data
;
3960 pci_enable_device(trident
->pci
);
3961 if (pci_set_dma_mask(trident
->pci
, 0x3fffffff) < 0 ||
3962 pci_set_consistent_dma_mask(trident
->pci
, 0x3fffffff) < 0)
3963 snd_printk(KERN_WARNING
"trident: can't set the proper DMA mask\n");
3964 pci_set_master(trident
->pci
); /* to be sure */
3966 switch (trident
->device
) {
3967 case TRIDENT_DEVICE_ID_DX
:
3968 snd_trident_4d_dx_init(trident
);
3970 case TRIDENT_DEVICE_ID_NX
:
3971 snd_trident_4d_nx_init(trident
);
3973 case TRIDENT_DEVICE_ID_SI7018
:
3974 snd_trident_sis_init(trident
);
3978 snd_ac97_resume(trident
->ac97
);
3979 if (trident
->ac97_sec
)
3980 snd_ac97_resume(trident
->ac97_sec
);
3982 /* restore some registers */
3983 outl(trident
->musicvol_wavevol
, TRID_REG(trident
, T4D_MUSICVOL_WAVEVOL
));
3985 snd_trident_enable_eso(trident
);
3987 snd_power_change_state(card
, SNDRV_CTL_POWER_D0
);
3988 trident
->in_suspend
= 0;
3991 #endif /* CONFIG_PM */
3993 EXPORT_SYMBOL(snd_trident_alloc_voice
);
3994 EXPORT_SYMBOL(snd_trident_free_voice
);
3995 EXPORT_SYMBOL(snd_trident_start_voice
);
3996 EXPORT_SYMBOL(snd_trident_stop_voice
);
3997 EXPORT_SYMBOL(snd_trident_write_voice_regs
);
3998 EXPORT_SYMBOL(snd_trident_clear_voices
);
3999 /* trident_memory.c symbols */
4000 EXPORT_SYMBOL(snd_trident_synth_alloc
);
4001 EXPORT_SYMBOL(snd_trident_synth_free
);
4002 EXPORT_SYMBOL(snd_trident_synth_bzero
);
4003 EXPORT_SYMBOL(snd_trident_synth_copy_from_user
);