2 * Maintained by Jaroslav Kysela <perex@perex.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 <linux/delay.h>
31 #include <linux/init.h>
32 #include <linux/interrupt.h>
33 #include <linux/pci.h>
34 #include <linux/slab.h>
35 #include <linux/vmalloc.h>
36 #include <linux/gameport.h>
37 #include <linux/dma-mapping.h>
39 #include <sound/core.h>
40 #include <sound/info.h>
41 #include <sound/control.h>
42 #include <sound/tlv.h>
43 #include <sound/trident.h>
44 #include <sound/asoundef.h>
48 static int snd_trident_pcm_mixer_build(struct snd_trident
*trident
,
49 struct snd_trident_voice
* voice
,
50 struct snd_pcm_substream
*substream
);
51 static int snd_trident_pcm_mixer_free(struct snd_trident
*trident
,
52 struct snd_trident_voice
* voice
,
53 struct snd_pcm_substream
*substream
);
54 static irqreturn_t
snd_trident_interrupt(int irq
, void *dev_id
);
55 static int snd_trident_sis_reset(struct snd_trident
*trident
);
57 static void snd_trident_clear_voices(struct snd_trident
* trident
,
58 unsigned short v_min
, unsigned short v_max
);
59 static int snd_trident_free(struct snd_trident
*trident
);
67 static void snd_trident_print_voice_regs(struct snd_trident
*trident
, int voice
)
69 unsigned int val
, tmp
;
71 printk("Trident voice %i:\n", voice
);
72 outb(voice
, TRID_REG(trident
, T4D_LFO_GC_CIR
));
73 val
= inl(TRID_REG(trident
, CH_LBA
));
74 printk("LBA: 0x%x\n", val
);
75 val
= inl(TRID_REG(trident
, CH_GVSEL_PAN_VOL_CTRL_EC
));
76 printk("GVSel: %i\n", val
>> 31);
77 printk("Pan: 0x%x\n", (val
>> 24) & 0x7f);
78 printk("Vol: 0x%x\n", (val
>> 16) & 0xff);
79 printk("CTRL: 0x%x\n", (val
>> 12) & 0x0f);
80 printk("EC: 0x%x\n", val
& 0x0fff);
81 if (trident
->device
!= TRIDENT_DEVICE_ID_NX
) {
82 val
= inl(TRID_REG(trident
, CH_DX_CSO_ALPHA_FMS
));
83 printk("CSO: 0x%x\n", val
>> 16);
84 printk("Alpha: 0x%x\n", (val
>> 4) & 0x0fff);
85 printk("FMS: 0x%x\n", val
& 0x0f);
86 val
= inl(TRID_REG(trident
, CH_DX_ESO_DELTA
));
87 printk("ESO: 0x%x\n", val
>> 16);
88 printk("Delta: 0x%x\n", val
& 0xffff);
89 val
= inl(TRID_REG(trident
, CH_DX_FMC_RVOL_CVOL
));
90 } else { // TRIDENT_DEVICE_ID_NX
91 val
= inl(TRID_REG(trident
, CH_NX_DELTA_CSO
));
92 tmp
= (val
>> 24) & 0xff;
93 printk("CSO: 0x%x\n", val
& 0x00ffffff);
94 val
= inl(TRID_REG(trident
, CH_NX_DELTA_ESO
));
95 tmp
|= (val
>> 16) & 0xff00;
96 printk("Delta: 0x%x\n", tmp
);
97 printk("ESO: 0x%x\n", val
& 0x00ffffff);
98 val
= inl(TRID_REG(trident
, CH_NX_ALPHA_FMS_FMC_RVOL_CVOL
));
99 printk("Alpha: 0x%x\n", val
>> 20);
100 printk("FMS: 0x%x\n", (val
>> 16) & 0x0f);
102 printk("FMC: 0x%x\n", (val
>> 14) & 3);
103 printk("RVol: 0x%x\n", (val
>> 7) & 0x7f);
104 printk("CVol: 0x%x\n", val
& 0x7f);
108 /*---------------------------------------------------------------------------
109 unsigned short snd_trident_codec_read(struct snd_ac97 *ac97, unsigned short reg)
111 Description: This routine will do all of the reading from the external
114 Parameters: ac97 - ac97 codec structure
115 reg - CODEC register index, from AC97 Hal.
117 returns: 16 bit value read from the AC97.
119 ---------------------------------------------------------------------------*/
120 static unsigned short snd_trident_codec_read(struct snd_ac97
*ac97
, unsigned short reg
)
122 unsigned int data
= 0, treg
;
123 unsigned short count
= 0xffff;
125 struct snd_trident
*trident
= ac97
->private_data
;
127 spin_lock_irqsave(&trident
->reg_lock
, flags
);
128 if (trident
->device
== TRIDENT_DEVICE_ID_DX
) {
129 data
= (DX_AC97_BUSY_READ
| (reg
& 0x000000ff));
130 outl(data
, TRID_REG(trident
, DX_ACR1_AC97_R
));
132 data
= inl(TRID_REG(trident
, DX_ACR1_AC97_R
));
133 if ((data
& DX_AC97_BUSY_READ
) == 0)
136 } else if (trident
->device
== TRIDENT_DEVICE_ID_NX
) {
137 data
= (NX_AC97_BUSY_READ
| (reg
& 0x000000ff));
138 treg
= ac97
->num
== 0 ? NX_ACR2_AC97_R_PRIMARY
: NX_ACR3_AC97_R_SECONDARY
;
139 outl(data
, TRID_REG(trident
, treg
));
141 data
= inl(TRID_REG(trident
, treg
));
142 if ((data
& 0x00000C00) == 0)
145 } else if (trident
->device
== TRIDENT_DEVICE_ID_SI7018
) {
146 data
= SI_AC97_BUSY_READ
| SI_AC97_AUDIO_BUSY
| (reg
& 0x000000ff);
148 data
|= SI_AC97_SECONDARY
;
149 outl(data
, TRID_REG(trident
, SI_AC97_READ
));
151 data
= inl(TRID_REG(trident
, SI_AC97_READ
));
152 if ((data
& (SI_AC97_BUSY_READ
)) == 0)
157 if (count
== 0 && !trident
->ac97_detect
) {
158 snd_printk(KERN_ERR
"ac97 codec read TIMEOUT [0x%x/0x%x]!!!\n",
163 spin_unlock_irqrestore(&trident
->reg_lock
, flags
);
164 return ((unsigned short) (data
>> 16));
167 /*---------------------------------------------------------------------------
168 void snd_trident_codec_write(struct snd_ac97 *ac97, unsigned short reg,
169 unsigned short wdata)
171 Description: This routine will do all of the writing to the external
174 Parameters: ac97 - ac97 codec structure
175 reg - CODEC register index, from AC97 Hal.
176 data - Lower 16 bits are the data to write to CODEC.
178 returns: TRUE if everything went ok, else FALSE.
180 ---------------------------------------------------------------------------*/
181 static void snd_trident_codec_write(struct snd_ac97
*ac97
, unsigned short reg
,
182 unsigned short wdata
)
184 unsigned int address
, data
;
185 unsigned short count
= 0xffff;
187 struct snd_trident
*trident
= ac97
->private_data
;
189 data
= ((unsigned long) wdata
) << 16;
191 spin_lock_irqsave(&trident
->reg_lock
, flags
);
192 if (trident
->device
== TRIDENT_DEVICE_ID_DX
) {
193 address
= DX_ACR0_AC97_W
;
195 /* read AC-97 write register status */
197 if ((inw(TRID_REG(trident
, address
)) & DX_AC97_BUSY_WRITE
) == 0)
201 data
|= (DX_AC97_BUSY_WRITE
| (reg
& 0x000000ff));
202 } else if (trident
->device
== TRIDENT_DEVICE_ID_NX
) {
203 address
= NX_ACR1_AC97_W
;
205 /* read AC-97 write register status */
207 if ((inw(TRID_REG(trident
, address
)) & NX_AC97_BUSY_WRITE
) == 0)
211 data
|= (NX_AC97_BUSY_WRITE
| (ac97
->num
<< 8) | (reg
& 0x000000ff));
212 } else if (trident
->device
== TRIDENT_DEVICE_ID_SI7018
) {
213 address
= SI_AC97_WRITE
;
215 /* read AC-97 write register status */
217 if ((inw(TRID_REG(trident
, address
)) & (SI_AC97_BUSY_WRITE
)) == 0)
221 data
|= SI_AC97_BUSY_WRITE
| SI_AC97_AUDIO_BUSY
| (reg
& 0x000000ff);
223 data
|= SI_AC97_SECONDARY
;
225 address
= 0; /* keep GCC happy */
226 count
= 0; /* return */
230 spin_unlock_irqrestore(&trident
->reg_lock
, flags
);
233 outl(data
, TRID_REG(trident
, address
));
234 spin_unlock_irqrestore(&trident
->reg_lock
, flags
);
237 /*---------------------------------------------------------------------------
238 void snd_trident_enable_eso(struct snd_trident *trident)
240 Description: This routine will enable end of loop interrupts.
241 End of loop interrupts will occur when a running
243 Also enables middle of loop interrupts.
245 Parameters: trident - pointer to target device class for 4DWave.
247 ---------------------------------------------------------------------------*/
249 static void snd_trident_enable_eso(struct snd_trident
* trident
)
253 val
= inl(TRID_REG(trident
, T4D_LFO_GC_CIR
));
256 if (trident
->device
== TRIDENT_DEVICE_ID_SI7018
)
258 outl(val
, TRID_REG(trident
, T4D_LFO_GC_CIR
));
261 /*---------------------------------------------------------------------------
262 void snd_trident_disable_eso(struct snd_trident *trident)
264 Description: This routine will disable end of loop interrupts.
265 End of loop interrupts will occur when a running
267 Also disables middle of loop interrupts.
270 trident - pointer to target device class for 4DWave.
272 returns: TRUE if everything went ok, else FALSE.
274 ---------------------------------------------------------------------------*/
276 static void snd_trident_disable_eso(struct snd_trident
* trident
)
280 tmp
= inl(TRID_REG(trident
, T4D_LFO_GC_CIR
));
283 outl(tmp
, TRID_REG(trident
, T4D_LFO_GC_CIR
));
286 /*---------------------------------------------------------------------------
287 void snd_trident_start_voice(struct snd_trident * trident, unsigned int voice)
289 Description: Start a voice, any channel 0 thru 63.
290 This routine automatically handles the fact that there are
291 more than 32 channels available.
293 Parameters : voice - Voice number 0 thru n.
294 trident - pointer to target device class for 4DWave.
298 ---------------------------------------------------------------------------*/
300 void snd_trident_start_voice(struct snd_trident
* trident
, unsigned int voice
)
302 unsigned int mask
= 1 << (voice
& 0x1f);
303 unsigned int reg
= (voice
& 0x20) ? T4D_START_B
: T4D_START_A
;
305 outl(mask
, TRID_REG(trident
, reg
));
308 EXPORT_SYMBOL(snd_trident_start_voice
);
310 /*---------------------------------------------------------------------------
311 void snd_trident_stop_voice(struct snd_trident * trident, unsigned int voice)
313 Description: Stop a voice, any channel 0 thru 63.
314 This routine automatically handles the fact that there are
315 more than 32 channels available.
317 Parameters : voice - Voice number 0 thru n.
318 trident - pointer to target device class for 4DWave.
322 ---------------------------------------------------------------------------*/
324 void snd_trident_stop_voice(struct snd_trident
* trident
, unsigned int voice
)
326 unsigned int mask
= 1 << (voice
& 0x1f);
327 unsigned int reg
= (voice
& 0x20) ? T4D_STOP_B
: T4D_STOP_A
;
329 outl(mask
, TRID_REG(trident
, reg
));
332 EXPORT_SYMBOL(snd_trident_stop_voice
);
334 /*---------------------------------------------------------------------------
335 int snd_trident_allocate_pcm_channel(struct snd_trident *trident)
337 Description: Allocate hardware channel in Bank B (32-63).
339 Parameters : trident - pointer to target device class for 4DWave.
341 Return Value: hardware channel - 32-63 or -1 when no channel is available
343 ---------------------------------------------------------------------------*/
345 static int snd_trident_allocate_pcm_channel(struct snd_trident
* trident
)
349 if (trident
->ChanPCMcnt
>= trident
->ChanPCM
)
351 for (idx
= 31; idx
>= 0; idx
--) {
352 if (!(trident
->ChanMap
[T4D_BANK_B
] & (1 << idx
))) {
353 trident
->ChanMap
[T4D_BANK_B
] |= 1 << idx
;
354 trident
->ChanPCMcnt
++;
361 /*---------------------------------------------------------------------------
362 void snd_trident_free_pcm_channel(int channel)
364 Description: Free hardware channel in Bank B (32-63)
366 Parameters : trident - pointer to target device class for 4DWave.
367 channel - hardware channel number 0-63
371 ---------------------------------------------------------------------------*/
373 static void snd_trident_free_pcm_channel(struct snd_trident
*trident
, int channel
)
375 if (channel
< 32 || channel
> 63)
378 if (trident
->ChanMap
[T4D_BANK_B
] & (1 << channel
)) {
379 trident
->ChanMap
[T4D_BANK_B
] &= ~(1 << channel
);
380 trident
->ChanPCMcnt
--;
384 /*---------------------------------------------------------------------------
385 unsigned int snd_trident_allocate_synth_channel(void)
387 Description: Allocate hardware channel in Bank A (0-31).
389 Parameters : trident - pointer to target device class for 4DWave.
391 Return Value: hardware channel - 0-31 or -1 when no channel is available
393 ---------------------------------------------------------------------------*/
395 static int snd_trident_allocate_synth_channel(struct snd_trident
* trident
)
399 for (idx
= 31; idx
>= 0; idx
--) {
400 if (!(trident
->ChanMap
[T4D_BANK_A
] & (1 << idx
))) {
401 trident
->ChanMap
[T4D_BANK_A
] |= 1 << idx
;
402 trident
->synth
.ChanSynthCount
++;
409 /*---------------------------------------------------------------------------
410 void snd_trident_free_synth_channel( int channel )
412 Description: Free hardware channel in Bank B (0-31).
414 Parameters : trident - pointer to target device class for 4DWave.
415 channel - hardware channel number 0-63
419 ---------------------------------------------------------------------------*/
421 static void snd_trident_free_synth_channel(struct snd_trident
*trident
, int channel
)
423 if (channel
< 0 || channel
> 31)
426 if (trident
->ChanMap
[T4D_BANK_A
] & (1 << channel
)) {
427 trident
->ChanMap
[T4D_BANK_A
] &= ~(1 << channel
);
428 trident
->synth
.ChanSynthCount
--;
432 /*---------------------------------------------------------------------------
433 snd_trident_write_voice_regs
435 Description: This routine will complete and write the 5 hardware channel
436 registers to hardware.
438 Parameters: trident - pointer to target device class for 4DWave.
439 voice - synthesizer voice structure
442 ---------------------------------------------------------------------------*/
444 void snd_trident_write_voice_regs(struct snd_trident
* trident
,
445 struct snd_trident_voice
* voice
)
447 unsigned int FmcRvolCvol
;
448 unsigned int regs
[5];
450 regs
[1] = voice
->LBA
;
451 regs
[4] = (voice
->GVSel
<< 31) |
452 ((voice
->Pan
& 0x0000007f) << 24) |
453 ((voice
->CTRL
& 0x0000000f) << 12);
454 FmcRvolCvol
= ((voice
->FMC
& 3) << 14) |
455 ((voice
->RVol
& 0x7f) << 7) |
456 (voice
->CVol
& 0x7f);
458 switch (trident
->device
) {
459 case TRIDENT_DEVICE_ID_SI7018
:
460 regs
[4] |= voice
->number
> 31 ?
461 (voice
->Vol
& 0x000003ff) :
462 ((voice
->Vol
& 0x00003fc) << (16-2)) |
463 (voice
->EC
& 0x00000fff);
464 regs
[0] = (voice
->CSO
<< 16) | ((voice
->Alpha
& 0x00000fff) << 4) |
465 (voice
->FMS
& 0x0000000f);
466 regs
[2] = (voice
->ESO
<< 16) | (voice
->Delta
& 0x0ffff);
467 regs
[3] = (voice
->Attribute
<< 16) | FmcRvolCvol
;
469 case TRIDENT_DEVICE_ID_DX
:
470 regs
[4] |= ((voice
->Vol
& 0x000003fc) << (16-2)) |
471 (voice
->EC
& 0x00000fff);
472 regs
[0] = (voice
->CSO
<< 16) | ((voice
->Alpha
& 0x00000fff) << 4) |
473 (voice
->FMS
& 0x0000000f);
474 regs
[2] = (voice
->ESO
<< 16) | (voice
->Delta
& 0x0ffff);
475 regs
[3] = FmcRvolCvol
;
477 case TRIDENT_DEVICE_ID_NX
:
478 regs
[4] |= ((voice
->Vol
& 0x000003fc) << (16-2)) |
479 (voice
->EC
& 0x00000fff);
480 regs
[0] = (voice
->Delta
<< 24) | (voice
->CSO
& 0x00ffffff);
481 regs
[2] = ((voice
->Delta
<< 16) & 0xff000000) |
482 (voice
->ESO
& 0x00ffffff);
483 regs
[3] = (voice
->Alpha
<< 20) |
484 ((voice
->FMS
& 0x0000000f) << 16) | FmcRvolCvol
;
491 outb(voice
->number
, TRID_REG(trident
, T4D_LFO_GC_CIR
));
492 outl(regs
[0], TRID_REG(trident
, CH_START
+ 0));
493 outl(regs
[1], TRID_REG(trident
, CH_START
+ 4));
494 outl(regs
[2], TRID_REG(trident
, CH_START
+ 8));
495 outl(regs
[3], TRID_REG(trident
, CH_START
+ 12));
496 outl(regs
[4], TRID_REG(trident
, CH_START
+ 16));
499 printk("written %i channel:\n", voice
->number
);
500 printk(" regs[0] = 0x%x/0x%x\n", regs
[0], inl(TRID_REG(trident
, CH_START
+ 0)));
501 printk(" regs[1] = 0x%x/0x%x\n", regs
[1], inl(TRID_REG(trident
, CH_START
+ 4)));
502 printk(" regs[2] = 0x%x/0x%x\n", regs
[2], inl(TRID_REG(trident
, CH_START
+ 8)));
503 printk(" regs[3] = 0x%x/0x%x\n", regs
[3], inl(TRID_REG(trident
, CH_START
+ 12)));
504 printk(" regs[4] = 0x%x/0x%x\n", regs
[4], inl(TRID_REG(trident
, CH_START
+ 16)));
508 EXPORT_SYMBOL(snd_trident_write_voice_regs
);
510 /*---------------------------------------------------------------------------
511 snd_trident_write_cso_reg
513 Description: This routine will write the new CSO offset
514 register to hardware.
516 Parameters: trident - pointer to target device class for 4DWave.
517 voice - synthesizer voice structure
520 ---------------------------------------------------------------------------*/
522 static void snd_trident_write_cso_reg(struct snd_trident
* trident
,
523 struct snd_trident_voice
* voice
,
527 outb(voice
->number
, TRID_REG(trident
, T4D_LFO_GC_CIR
));
528 if (trident
->device
!= TRIDENT_DEVICE_ID_NX
) {
529 outw(voice
->CSO
, TRID_REG(trident
, CH_DX_CSO_ALPHA_FMS
) + 2);
531 outl((voice
->Delta
<< 24) |
532 (voice
->CSO
& 0x00ffffff), TRID_REG(trident
, CH_NX_DELTA_CSO
));
536 /*---------------------------------------------------------------------------
537 snd_trident_write_eso_reg
539 Description: This routine will write the new ESO offset
540 register to hardware.
542 Parameters: trident - pointer to target device class for 4DWave.
543 voice - synthesizer voice structure
546 ---------------------------------------------------------------------------*/
548 static void snd_trident_write_eso_reg(struct snd_trident
* trident
,
549 struct snd_trident_voice
* voice
,
553 outb(voice
->number
, TRID_REG(trident
, T4D_LFO_GC_CIR
));
554 if (trident
->device
!= TRIDENT_DEVICE_ID_NX
) {
555 outw(voice
->ESO
, TRID_REG(trident
, CH_DX_ESO_DELTA
) + 2);
557 outl(((voice
->Delta
<< 16) & 0xff000000) | (voice
->ESO
& 0x00ffffff),
558 TRID_REG(trident
, CH_NX_DELTA_ESO
));
562 /*---------------------------------------------------------------------------
563 snd_trident_write_vol_reg
565 Description: This routine will write the new voice volume
566 register to hardware.
568 Parameters: trident - pointer to target device class for 4DWave.
569 voice - synthesizer voice structure
570 Vol - new voice volume
572 ---------------------------------------------------------------------------*/
574 static void snd_trident_write_vol_reg(struct snd_trident
* trident
,
575 struct snd_trident_voice
* voice
,
579 outb(voice
->number
, TRID_REG(trident
, T4D_LFO_GC_CIR
));
580 switch (trident
->device
) {
581 case TRIDENT_DEVICE_ID_DX
:
582 case TRIDENT_DEVICE_ID_NX
:
583 outb(voice
->Vol
>> 2, TRID_REG(trident
, CH_GVSEL_PAN_VOL_CTRL_EC
+ 2));
585 case TRIDENT_DEVICE_ID_SI7018
:
586 // printk("voice->Vol = 0x%x\n", voice->Vol);
587 outw((voice
->CTRL
<< 12) | voice
->Vol
,
588 TRID_REG(trident
, CH_GVSEL_PAN_VOL_CTRL_EC
));
593 /*---------------------------------------------------------------------------
594 snd_trident_write_pan_reg
596 Description: This routine will write the new voice pan
597 register to hardware.
599 Parameters: trident - pointer to target device class for 4DWave.
600 voice - synthesizer voice structure
603 ---------------------------------------------------------------------------*/
605 static void snd_trident_write_pan_reg(struct snd_trident
* trident
,
606 struct snd_trident_voice
* voice
,
610 outb(voice
->number
, TRID_REG(trident
, T4D_LFO_GC_CIR
));
611 outb(((voice
->GVSel
& 0x01) << 7) | (voice
->Pan
& 0x7f),
612 TRID_REG(trident
, CH_GVSEL_PAN_VOL_CTRL_EC
+ 3));
615 /*---------------------------------------------------------------------------
616 snd_trident_write_rvol_reg
618 Description: This routine will write the new reverb volume
619 register to hardware.
621 Parameters: trident - pointer to target device class for 4DWave.
622 voice - synthesizer voice structure
623 RVol - new reverb volume
625 ---------------------------------------------------------------------------*/
627 static void snd_trident_write_rvol_reg(struct snd_trident
* trident
,
628 struct snd_trident_voice
* voice
,
632 outb(voice
->number
, TRID_REG(trident
, T4D_LFO_GC_CIR
));
633 outw(((voice
->FMC
& 0x0003) << 14) | ((voice
->RVol
& 0x007f) << 7) |
634 (voice
->CVol
& 0x007f),
635 TRID_REG(trident
, trident
->device
== TRIDENT_DEVICE_ID_NX
?
636 CH_NX_ALPHA_FMS_FMC_RVOL_CVOL
: CH_DX_FMC_RVOL_CVOL
));
639 /*---------------------------------------------------------------------------
640 snd_trident_write_cvol_reg
642 Description: This routine will write the new chorus volume
643 register to hardware.
645 Parameters: trident - pointer to target device class for 4DWave.
646 voice - synthesizer voice structure
647 CVol - new chorus volume
649 ---------------------------------------------------------------------------*/
651 static void snd_trident_write_cvol_reg(struct snd_trident
* trident
,
652 struct snd_trident_voice
* voice
,
656 outb(voice
->number
, TRID_REG(trident
, T4D_LFO_GC_CIR
));
657 outw(((voice
->FMC
& 0x0003) << 14) | ((voice
->RVol
& 0x007f) << 7) |
658 (voice
->CVol
& 0x007f),
659 TRID_REG(trident
, trident
->device
== TRIDENT_DEVICE_ID_NX
?
660 CH_NX_ALPHA_FMS_FMC_RVOL_CVOL
: CH_DX_FMC_RVOL_CVOL
));
663 /*---------------------------------------------------------------------------
664 snd_trident_convert_rate
666 Description: This routine converts rate in HZ to hardware delta value.
668 Parameters: trident - pointer to target device class for 4DWave.
669 rate - Real or Virtual channel number.
671 Returns: Delta value.
673 ---------------------------------------------------------------------------*/
674 static unsigned int snd_trident_convert_rate(unsigned int rate
)
678 // We special case 44100 and 8000 since rounding with the equation
679 // does not give us an accurate enough value. For 11025 and 22050
680 // the equation gives us the best answer. All other frequencies will
681 // also use the equation. JDW
684 else if (rate
== 8000)
686 else if (rate
== 48000)
689 delta
= (((rate
<< 12) + 24000) / 48000) & 0x0000ffff;
693 /*---------------------------------------------------------------------------
694 snd_trident_convert_adc_rate
696 Description: This routine converts rate in HZ to hardware delta value.
698 Parameters: trident - pointer to target device class for 4DWave.
699 rate - Real or Virtual channel number.
701 Returns: Delta value.
703 ---------------------------------------------------------------------------*/
704 static unsigned int snd_trident_convert_adc_rate(unsigned int rate
)
708 // We special case 44100 and 8000 since rounding with the equation
709 // does not give us an accurate enough value. For 11025 and 22050
710 // the equation gives us the best answer. All other frequencies will
711 // also use the equation. JDW
714 else if (rate
== 8000)
716 else if (rate
== 48000)
719 delta
= ((48000 << 12) / rate
) & 0x0000ffff;
723 /*---------------------------------------------------------------------------
724 snd_trident_spurious_threshold
726 Description: This routine converts rate in HZ to spurious threshold.
728 Parameters: trident - pointer to target device class for 4DWave.
729 rate - Real or Virtual channel number.
731 Returns: Delta value.
733 ---------------------------------------------------------------------------*/
734 static unsigned int snd_trident_spurious_threshold(unsigned int rate
,
735 unsigned int period_size
)
737 unsigned int res
= (rate
* period_size
) / 48000;
745 /*---------------------------------------------------------------------------
746 snd_trident_control_mode
748 Description: This routine returns a control mode for a PCM channel.
750 Parameters: trident - pointer to target device class for 4DWave.
751 substream - PCM substream
753 Returns: Control value.
755 ---------------------------------------------------------------------------*/
756 static unsigned int snd_trident_control_mode(struct snd_pcm_substream
*substream
)
759 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
762 CTRL default: 8-bit (unsigned) mono, loop mode enabled
765 if (snd_pcm_format_width(runtime
->format
) == 16)
766 CTRL
|= 0x00000008; // 16-bit data
767 if (snd_pcm_format_signed(runtime
->format
))
768 CTRL
|= 0x00000002; // signed data
769 if (runtime
->channels
> 1)
770 CTRL
|= 0x00000004; // stereo data
778 /*---------------------------------------------------------------------------
781 Description: Device I/O control handler for playback/capture parameters.
783 Parameters: substream - PCM substream class
784 cmd - what ioctl message to process
785 arg - additional message infoarg
787 Returns: Error status
789 ---------------------------------------------------------------------------*/
791 static int snd_trident_ioctl(struct snd_pcm_substream
*substream
,
795 /* FIXME: it seems that with small periods the behaviour of
796 trident hardware is unpredictable and interrupt generator
798 return snd_pcm_lib_ioctl(substream
, cmd
, arg
);
801 /*---------------------------------------------------------------------------
802 snd_trident_allocate_pcm_mem
804 Description: Allocate PCM ring buffer for given substream
806 Parameters: substream - PCM substream class
807 hw_params - hardware parameters
809 Returns: Error status
811 ---------------------------------------------------------------------------*/
813 static int snd_trident_allocate_pcm_mem(struct snd_pcm_substream
*substream
,
814 struct snd_pcm_hw_params
*hw_params
)
816 struct snd_trident
*trident
= snd_pcm_substream_chip(substream
);
817 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
818 struct snd_trident_voice
*voice
= runtime
->private_data
;
821 if ((err
= snd_pcm_lib_malloc_pages(substream
, params_buffer_bytes(hw_params
))) < 0)
823 if (trident
->tlb
.entries
) {
824 if (err
> 0) { /* change */
826 snd_trident_free_pages(trident
, voice
->memblk
);
827 voice
->memblk
= snd_trident_alloc_pages(trident
, substream
);
828 if (voice
->memblk
== NULL
)
835 /*---------------------------------------------------------------------------
836 snd_trident_allocate_evoice
838 Description: Allocate extra voice as interrupt generator
840 Parameters: substream - PCM substream class
841 hw_params - hardware parameters
843 Returns: Error status
845 ---------------------------------------------------------------------------*/
847 static int snd_trident_allocate_evoice(struct snd_pcm_substream
*substream
,
848 struct snd_pcm_hw_params
*hw_params
)
850 struct snd_trident
*trident
= snd_pcm_substream_chip(substream
);
851 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
852 struct snd_trident_voice
*voice
= runtime
->private_data
;
853 struct snd_trident_voice
*evoice
= voice
->extra
;
855 /* voice management */
857 if (params_buffer_size(hw_params
) / 2 != params_period_size(hw_params
)) {
858 if (evoice
== NULL
) {
859 evoice
= snd_trident_alloc_voice(trident
, SNDRV_TRIDENT_VOICE_TYPE_PCM
, 0, 0);
862 voice
->extra
= evoice
;
863 evoice
->substream
= substream
;
866 if (evoice
!= NULL
) {
867 snd_trident_free_voice(trident
, evoice
);
868 voice
->extra
= evoice
= NULL
;
875 /*---------------------------------------------------------------------------
876 snd_trident_hw_params
878 Description: Set the hardware parameters for the playback device.
880 Parameters: substream - PCM substream class
881 hw_params - hardware parameters
883 Returns: Error status
885 ---------------------------------------------------------------------------*/
887 static int snd_trident_hw_params(struct snd_pcm_substream
*substream
,
888 struct snd_pcm_hw_params
*hw_params
)
892 err
= snd_trident_allocate_pcm_mem(substream
, hw_params
);
894 err
= snd_trident_allocate_evoice(substream
, hw_params
);
898 /*---------------------------------------------------------------------------
899 snd_trident_playback_hw_free
901 Description: Release the hardware resources for the playback device.
903 Parameters: substream - PCM substream class
905 Returns: Error status
907 ---------------------------------------------------------------------------*/
909 static int snd_trident_hw_free(struct snd_pcm_substream
*substream
)
911 struct snd_trident
*trident
= snd_pcm_substream_chip(substream
);
912 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
913 struct snd_trident_voice
*voice
= runtime
->private_data
;
914 struct snd_trident_voice
*evoice
= voice
? voice
->extra
: NULL
;
916 if (trident
->tlb
.entries
) {
917 if (voice
&& voice
->memblk
) {
918 snd_trident_free_pages(trident
, voice
->memblk
);
919 voice
->memblk
= NULL
;
922 snd_pcm_lib_free_pages(substream
);
923 if (evoice
!= NULL
) {
924 snd_trident_free_voice(trident
, evoice
);
930 /*---------------------------------------------------------------------------
931 snd_trident_playback_prepare
933 Description: Prepare playback device for playback.
935 Parameters: substream - PCM substream class
937 Returns: Error status
939 ---------------------------------------------------------------------------*/
941 static int snd_trident_playback_prepare(struct snd_pcm_substream
*substream
)
943 struct snd_trident
*trident
= snd_pcm_substream_chip(substream
);
944 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
945 struct snd_trident_voice
*voice
= runtime
->private_data
;
946 struct snd_trident_voice
*evoice
= voice
->extra
;
947 struct snd_trident_pcm_mixer
*mix
= &trident
->pcm_mixer
[substream
->number
];
949 spin_lock_irq(&trident
->reg_lock
);
951 /* set delta (rate) value */
952 voice
->Delta
= snd_trident_convert_rate(runtime
->rate
);
953 voice
->spurious_threshold
= snd_trident_spurious_threshold(runtime
->rate
, runtime
->period_size
);
955 /* set Loop Begin Address */
957 voice
->LBA
= voice
->memblk
->offset
;
959 voice
->LBA
= runtime
->dma_addr
;
962 voice
->ESO
= runtime
->buffer_size
- 1; /* in samples */
963 voice
->CTRL
= snd_trident_control_mode(substream
);
969 voice
->Vol
= mix
->vol
;
970 voice
->RVol
= mix
->rvol
;
971 voice
->CVol
= mix
->cvol
;
972 voice
->Pan
= mix
->pan
;
973 voice
->Attribute
= 0;
975 voice
->Attribute
= (1<<(30-16))|(2<<(26-16))|
976 (0<<(24-16))|(0x1f<<(19-16));
978 voice
->Attribute
= 0;
981 snd_trident_write_voice_regs(trident
, voice
);
983 if (evoice
!= NULL
) {
984 evoice
->Delta
= voice
->Delta
;
985 evoice
->spurious_threshold
= voice
->spurious_threshold
;
986 evoice
->LBA
= voice
->LBA
;
988 evoice
->ESO
= (runtime
->period_size
* 2) + 4 - 1; /* in samples */
989 evoice
->CTRL
= voice
->CTRL
;
991 evoice
->GVSel
= trident
->device
== TRIDENT_DEVICE_ID_SI7018
? 0 : 1;
995 evoice
->Vol
= 0x3ff; /* mute */
996 evoice
->RVol
= evoice
->CVol
= 0x7f; /* mute */
997 evoice
->Pan
= 0x7f; /* mute */
999 evoice
->Attribute
= (1<<(30-16))|(2<<(26-16))|
1000 (0<<(24-16))|(0x1f<<(19-16));
1002 evoice
->Attribute
= 0;
1004 snd_trident_write_voice_regs(trident
, evoice
);
1006 evoice
->isync_mark
= runtime
->period_size
;
1007 evoice
->ESO
= (runtime
->period_size
* 2) - 1;
1010 spin_unlock_irq(&trident
->reg_lock
);
1015 /*---------------------------------------------------------------------------
1016 snd_trident_capture_hw_params
1018 Description: Set the hardware parameters for the capture device.
1020 Parameters: substream - PCM substream class
1021 hw_params - hardware parameters
1023 Returns: Error status
1025 ---------------------------------------------------------------------------*/
1027 static int snd_trident_capture_hw_params(struct snd_pcm_substream
*substream
,
1028 struct snd_pcm_hw_params
*hw_params
)
1030 return snd_trident_allocate_pcm_mem(substream
, hw_params
);
1033 /*---------------------------------------------------------------------------
1034 snd_trident_capture_prepare
1036 Description: Prepare capture device for playback.
1038 Parameters: substream - PCM substream class
1040 Returns: Error status
1042 ---------------------------------------------------------------------------*/
1044 static int snd_trident_capture_prepare(struct snd_pcm_substream
*substream
)
1046 struct snd_trident
*trident
= snd_pcm_substream_chip(substream
);
1047 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1048 struct snd_trident_voice
*voice
= runtime
->private_data
;
1049 unsigned int val
, ESO_bytes
;
1051 spin_lock_irq(&trident
->reg_lock
);
1053 // Initilize the channel and set channel Mode
1054 outb(0, TRID_REG(trident
, LEGACY_DMAR15
));
1056 // Set DMA channel operation mode register
1057 outb(0x54, TRID_REG(trident
, LEGACY_DMAR11
));
1059 // Set channel buffer Address, DMAR0 expects contiguous PCI memory area
1060 voice
->LBA
= runtime
->dma_addr
;
1061 outl(voice
->LBA
, TRID_REG(trident
, LEGACY_DMAR0
));
1063 voice
->LBA
= voice
->memblk
->offset
;
1066 ESO_bytes
= snd_pcm_lib_buffer_bytes(substream
) - 1;
1067 outb((ESO_bytes
& 0x00ff0000) >> 16, TRID_REG(trident
, LEGACY_DMAR6
));
1068 outw((ESO_bytes
& 0x0000ffff), TRID_REG(trident
, LEGACY_DMAR4
));
1071 // Set channel sample rate, 4.12 format
1072 val
= (((unsigned int) 48000L << 12) + (runtime
->rate
/2)) / runtime
->rate
;
1073 outw(val
, TRID_REG(trident
, T4D_SBDELTA_DELTA_R
));
1075 // Set channel interrupt blk length
1076 if (snd_pcm_format_width(runtime
->format
) == 16) {
1077 val
= (unsigned short) ((ESO_bytes
>> 1) - 1);
1079 val
= (unsigned short) (ESO_bytes
- 1);
1082 outl((val
<< 16) | val
, TRID_REG(trident
, T4D_SBBL_SBCL
));
1084 // Right now, set format and start to run captureing,
1085 // continuous run loop enable.
1086 trident
->bDMAStart
= 0x19; // 0001 1001b
1088 if (snd_pcm_format_width(runtime
->format
) == 16)
1089 trident
->bDMAStart
|= 0x80;
1090 if (snd_pcm_format_signed(runtime
->format
))
1091 trident
->bDMAStart
|= 0x20;
1092 if (runtime
->channels
> 1)
1093 trident
->bDMAStart
|= 0x40;
1095 // Prepare capture intr channel
1097 voice
->Delta
= snd_trident_convert_rate(runtime
->rate
);
1098 voice
->spurious_threshold
= snd_trident_spurious_threshold(runtime
->rate
, runtime
->period_size
);
1100 voice
->isync_mark
= runtime
->period_size
;
1101 voice
->isync_max
= runtime
->buffer_size
;
1103 // Set voice parameters
1105 voice
->ESO
= voice
->isync_ESO
= (runtime
->period_size
* 2) + 6 - 1;
1106 voice
->CTRL
= snd_trident_control_mode(substream
);
1111 voice
->Pan
= 0x7f; /* mute */
1112 voice
->Vol
= 0x3ff; /* mute */
1116 voice
->Attribute
= 0;
1118 snd_trident_write_voice_regs(trident
, voice
);
1120 spin_unlock_irq(&trident
->reg_lock
);
1124 /*---------------------------------------------------------------------------
1125 snd_trident_si7018_capture_hw_params
1127 Description: Set the hardware parameters for the capture device.
1129 Parameters: substream - PCM substream class
1130 hw_params - hardware parameters
1132 Returns: Error status
1134 ---------------------------------------------------------------------------*/
1136 static int snd_trident_si7018_capture_hw_params(struct snd_pcm_substream
*substream
,
1137 struct snd_pcm_hw_params
*hw_params
)
1141 if ((err
= snd_pcm_lib_malloc_pages(substream
, params_buffer_bytes(hw_params
))) < 0)
1144 return snd_trident_allocate_evoice(substream
, hw_params
);
1147 /*---------------------------------------------------------------------------
1148 snd_trident_si7018_capture_hw_free
1150 Description: Release the hardware resources for the capture device.
1152 Parameters: substream - PCM substream class
1154 Returns: Error status
1156 ---------------------------------------------------------------------------*/
1158 static int snd_trident_si7018_capture_hw_free(struct snd_pcm_substream
*substream
)
1160 struct snd_trident
*trident
= snd_pcm_substream_chip(substream
);
1161 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1162 struct snd_trident_voice
*voice
= runtime
->private_data
;
1163 struct snd_trident_voice
*evoice
= voice
? voice
->extra
: NULL
;
1165 snd_pcm_lib_free_pages(substream
);
1166 if (evoice
!= NULL
) {
1167 snd_trident_free_voice(trident
, evoice
);
1168 voice
->extra
= NULL
;
1173 /*---------------------------------------------------------------------------
1174 snd_trident_si7018_capture_prepare
1176 Description: Prepare capture device for playback.
1178 Parameters: substream - PCM substream class
1180 Returns: Error status
1182 ---------------------------------------------------------------------------*/
1184 static int snd_trident_si7018_capture_prepare(struct snd_pcm_substream
*substream
)
1186 struct snd_trident
*trident
= snd_pcm_substream_chip(substream
);
1187 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1188 struct snd_trident_voice
*voice
= runtime
->private_data
;
1189 struct snd_trident_voice
*evoice
= voice
->extra
;
1191 spin_lock_irq(&trident
->reg_lock
);
1193 voice
->LBA
= runtime
->dma_addr
;
1194 voice
->Delta
= snd_trident_convert_adc_rate(runtime
->rate
);
1195 voice
->spurious_threshold
= snd_trident_spurious_threshold(runtime
->rate
, runtime
->period_size
);
1197 // Set voice parameters
1199 voice
->ESO
= runtime
->buffer_size
- 1; /* in samples */
1200 voice
->CTRL
= snd_trident_control_mode(substream
);
1205 voice
->Pan
= T4D_DEFAULT_PCM_PAN
;
1211 voice
->Attribute
= (2 << (30-16)) |
1216 snd_trident_write_voice_regs(trident
, voice
);
1218 if (evoice
!= NULL
) {
1219 evoice
->Delta
= snd_trident_convert_rate(runtime
->rate
);
1220 evoice
->spurious_threshold
= voice
->spurious_threshold
;
1221 evoice
->LBA
= voice
->LBA
;
1223 evoice
->ESO
= (runtime
->period_size
* 2) + 20 - 1; /* in samples, 20 means correction */
1224 evoice
->CTRL
= voice
->CTRL
;
1230 evoice
->Vol
= 0x3ff; /* mute */
1231 evoice
->RVol
= evoice
->CVol
= 0x7f; /* mute */
1232 evoice
->Pan
= 0x7f; /* mute */
1233 evoice
->Attribute
= 0;
1234 snd_trident_write_voice_regs(trident
, evoice
);
1236 evoice
->isync_mark
= runtime
->period_size
;
1237 evoice
->ESO
= (runtime
->period_size
* 2) - 1;
1240 spin_unlock_irq(&trident
->reg_lock
);
1244 /*---------------------------------------------------------------------------
1245 snd_trident_foldback_prepare
1247 Description: Prepare foldback capture device for playback.
1249 Parameters: substream - PCM substream class
1251 Returns: Error status
1253 ---------------------------------------------------------------------------*/
1255 static int snd_trident_foldback_prepare(struct snd_pcm_substream
*substream
)
1257 struct snd_trident
*trident
= snd_pcm_substream_chip(substream
);
1258 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1259 struct snd_trident_voice
*voice
= runtime
->private_data
;
1260 struct snd_trident_voice
*evoice
= voice
->extra
;
1262 spin_lock_irq(&trident
->reg_lock
);
1264 /* Set channel buffer Address */
1266 voice
->LBA
= voice
->memblk
->offset
;
1268 voice
->LBA
= runtime
->dma_addr
;
1270 /* set target ESO for channel */
1271 voice
->ESO
= runtime
->buffer_size
- 1; /* in samples */
1273 /* set sample rate */
1274 voice
->Delta
= 0x1000;
1275 voice
->spurious_threshold
= snd_trident_spurious_threshold(48000, runtime
->period_size
);
1278 voice
->CTRL
= snd_trident_control_mode(substream
);
1283 voice
->Pan
= 0x7f; /* mute */
1284 voice
->Vol
= 0x3ff; /* mute */
1288 voice
->Attribute
= 0;
1290 /* set up capture channel */
1291 outb(((voice
->number
& 0x3f) | 0x80), TRID_REG(trident
, T4D_RCI
+ voice
->foldback_chan
));
1293 snd_trident_write_voice_regs(trident
, voice
);
1295 if (evoice
!= NULL
) {
1296 evoice
->Delta
= voice
->Delta
;
1297 evoice
->spurious_threshold
= voice
->spurious_threshold
;
1298 evoice
->LBA
= voice
->LBA
;
1300 evoice
->ESO
= (runtime
->period_size
* 2) + 4 - 1; /* in samples */
1301 evoice
->CTRL
= voice
->CTRL
;
1303 evoice
->GVSel
= trident
->device
== TRIDENT_DEVICE_ID_SI7018
? 0 : 1;
1307 evoice
->Vol
= 0x3ff; /* mute */
1308 evoice
->RVol
= evoice
->CVol
= 0x7f; /* mute */
1309 evoice
->Pan
= 0x7f; /* mute */
1310 evoice
->Attribute
= 0;
1311 snd_trident_write_voice_regs(trident
, evoice
);
1313 evoice
->isync_mark
= runtime
->period_size
;
1314 evoice
->ESO
= (runtime
->period_size
* 2) - 1;
1317 spin_unlock_irq(&trident
->reg_lock
);
1321 /*---------------------------------------------------------------------------
1322 snd_trident_spdif_hw_params
1324 Description: Set the hardware parameters for the spdif device.
1326 Parameters: substream - PCM substream class
1327 hw_params - hardware parameters
1329 Returns: Error status
1331 ---------------------------------------------------------------------------*/
1333 static int snd_trident_spdif_hw_params(struct snd_pcm_substream
*substream
,
1334 struct snd_pcm_hw_params
*hw_params
)
1336 struct snd_trident
*trident
= snd_pcm_substream_chip(substream
);
1337 unsigned int old_bits
= 0, change
= 0;
1340 err
= snd_trident_allocate_pcm_mem(substream
, hw_params
);
1344 if (trident
->device
== TRIDENT_DEVICE_ID_SI7018
) {
1345 err
= snd_trident_allocate_evoice(substream
, hw_params
);
1350 /* prepare SPDIF channel */
1351 spin_lock_irq(&trident
->reg_lock
);
1352 old_bits
= trident
->spdif_pcm_bits
;
1353 if (old_bits
& IEC958_AES0_PROFESSIONAL
)
1354 trident
->spdif_pcm_bits
&= ~IEC958_AES0_PRO_FS
;
1356 trident
->spdif_pcm_bits
&= ~(IEC958_AES3_CON_FS
<< 24);
1357 if (params_rate(hw_params
) >= 48000) {
1358 trident
->spdif_pcm_ctrl
= 0x3c; // 48000 Hz
1359 trident
->spdif_pcm_bits
|=
1360 trident
->spdif_bits
& IEC958_AES0_PROFESSIONAL
?
1361 IEC958_AES0_PRO_FS_48000
:
1362 (IEC958_AES3_CON_FS_48000
<< 24);
1364 else if (params_rate(hw_params
) >= 44100) {
1365 trident
->spdif_pcm_ctrl
= 0x3e; // 44100 Hz
1366 trident
->spdif_pcm_bits
|=
1367 trident
->spdif_bits
& IEC958_AES0_PROFESSIONAL
?
1368 IEC958_AES0_PRO_FS_44100
:
1369 (IEC958_AES3_CON_FS_44100
<< 24);
1372 trident
->spdif_pcm_ctrl
= 0x3d; // 32000 Hz
1373 trident
->spdif_pcm_bits
|=
1374 trident
->spdif_bits
& IEC958_AES0_PROFESSIONAL
?
1375 IEC958_AES0_PRO_FS_32000
:
1376 (IEC958_AES3_CON_FS_32000
<< 24);
1378 change
= old_bits
!= trident
->spdif_pcm_bits
;
1379 spin_unlock_irq(&trident
->reg_lock
);
1382 snd_ctl_notify(trident
->card
, SNDRV_CTL_EVENT_MASK_VALUE
, &trident
->spdif_pcm_ctl
->id
);
1387 /*---------------------------------------------------------------------------
1388 snd_trident_spdif_prepare
1390 Description: Prepare SPDIF device for playback.
1392 Parameters: substream - PCM substream class
1394 Returns: Error status
1396 ---------------------------------------------------------------------------*/
1398 static int snd_trident_spdif_prepare(struct snd_pcm_substream
*substream
)
1400 struct snd_trident
*trident
= snd_pcm_substream_chip(substream
);
1401 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1402 struct snd_trident_voice
*voice
= runtime
->private_data
;
1403 struct snd_trident_voice
*evoice
= voice
->extra
;
1404 struct snd_trident_pcm_mixer
*mix
= &trident
->pcm_mixer
[substream
->number
];
1405 unsigned int RESO
, LBAO
;
1408 spin_lock_irq(&trident
->reg_lock
);
1410 if (trident
->device
!= TRIDENT_DEVICE_ID_SI7018
) {
1412 /* set delta (rate) value */
1413 voice
->Delta
= snd_trident_convert_rate(runtime
->rate
);
1414 voice
->spurious_threshold
= snd_trident_spurious_threshold(runtime
->rate
, runtime
->period_size
);
1416 /* set Loop Back Address */
1417 LBAO
= runtime
->dma_addr
;
1419 voice
->LBA
= voice
->memblk
->offset
;
1425 voice
->isync_mark
= runtime
->period_size
;
1426 voice
->isync_max
= runtime
->buffer_size
;
1428 /* set target ESO for channel */
1429 RESO
= runtime
->buffer_size
- 1;
1430 voice
->ESO
= voice
->isync_ESO
= (runtime
->period_size
* 2) + 6 - 1;
1433 voice
->CTRL
= snd_trident_control_mode(substream
);
1445 voice
->Attribute
= 0;
1447 /* prepare surrogate IRQ channel */
1448 snd_trident_write_voice_regs(trident
, voice
);
1450 outw((RESO
& 0xffff), TRID_REG(trident
, NX_SPESO
));
1451 outb((RESO
>> 16), TRID_REG(trident
, NX_SPESO
+ 2));
1452 outl((LBAO
& 0xfffffffc), TRID_REG(trident
, NX_SPLBA
));
1453 outw((voice
->CSO
& 0xffff), TRID_REG(trident
, NX_SPCTRL_SPCSO
));
1454 outb((voice
->CSO
>> 16), TRID_REG(trident
, NX_SPCTRL_SPCSO
+ 2));
1456 /* set SPDIF setting */
1457 outb(trident
->spdif_pcm_ctrl
, TRID_REG(trident
, NX_SPCTRL_SPCSO
+ 3));
1458 outl(trident
->spdif_pcm_bits
, TRID_REG(trident
, NX_SPCSTATUS
));
1462 /* set delta (rate) value */
1463 voice
->Delta
= 0x800;
1464 voice
->spurious_threshold
= snd_trident_spurious_threshold(48000, runtime
->period_size
);
1466 /* set Loop Begin Address */
1468 voice
->LBA
= voice
->memblk
->offset
;
1470 voice
->LBA
= runtime
->dma_addr
;
1473 voice
->ESO
= runtime
->buffer_size
- 1; /* in samples */
1474 voice
->CTRL
= snd_trident_control_mode(substream
);
1480 voice
->Vol
= mix
->vol
;
1481 voice
->RVol
= mix
->rvol
;
1482 voice
->CVol
= mix
->cvol
;
1483 voice
->Pan
= mix
->pan
;
1484 voice
->Attribute
= (1<<(30-16))|(7<<(26-16))|
1485 (0<<(24-16))|(0<<(19-16));
1487 snd_trident_write_voice_regs(trident
, voice
);
1489 if (evoice
!= NULL
) {
1490 evoice
->Delta
= voice
->Delta
;
1491 evoice
->spurious_threshold
= voice
->spurious_threshold
;
1492 evoice
->LBA
= voice
->LBA
;
1494 evoice
->ESO
= (runtime
->period_size
* 2) + 4 - 1; /* in samples */
1495 evoice
->CTRL
= voice
->CTRL
;
1497 evoice
->GVSel
= trident
->device
== TRIDENT_DEVICE_ID_SI7018
? 0 : 1;
1501 evoice
->Vol
= 0x3ff; /* mute */
1502 evoice
->RVol
= evoice
->CVol
= 0x7f; /* mute */
1503 evoice
->Pan
= 0x7f; /* mute */
1504 evoice
->Attribute
= 0;
1505 snd_trident_write_voice_regs(trident
, evoice
);
1507 evoice
->isync_mark
= runtime
->period_size
;
1508 evoice
->ESO
= (runtime
->period_size
* 2) - 1;
1511 outl(trident
->spdif_pcm_bits
, TRID_REG(trident
, SI_SPDIF_CS
));
1512 temp
= inl(TRID_REG(trident
, T4D_LFO_GC_CIR
));
1514 outl(temp
, TRID_REG(trident
, T4D_LFO_GC_CIR
));
1515 temp
= inl(TRID_REG(trident
, SI_SERIAL_INTF_CTRL
));
1517 outl(temp
, TRID_REG(trident
, SI_SERIAL_INTF_CTRL
));
1520 spin_unlock_irq(&trident
->reg_lock
);
1525 /*---------------------------------------------------------------------------
1528 Description: Start/stop devices
1530 Parameters: substream - PCM substream class
1531 cmd - trigger command (STOP, GO)
1533 Returns: Error status
1535 ---------------------------------------------------------------------------*/
1537 static int snd_trident_trigger(struct snd_pcm_substream
*substream
,
1541 struct snd_trident
*trident
= snd_pcm_substream_chip(substream
);
1542 struct snd_pcm_substream
*s
;
1543 unsigned int what
, whati
, capture_flag
, spdif_flag
;
1544 struct snd_trident_voice
*voice
, *evoice
;
1545 unsigned int val
, go
;
1548 case SNDRV_PCM_TRIGGER_START
:
1549 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
1550 case SNDRV_PCM_TRIGGER_RESUME
:
1553 case SNDRV_PCM_TRIGGER_STOP
:
1554 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
1555 case SNDRV_PCM_TRIGGER_SUSPEND
:
1561 what
= whati
= capture_flag
= spdif_flag
= 0;
1562 spin_lock(&trident
->reg_lock
);
1563 val
= inl(TRID_REG(trident
, T4D_STIMER
)) & 0x00ffffff;
1564 snd_pcm_group_for_each_entry(s
, substream
) {
1565 if ((struct snd_trident
*) snd_pcm_substream_chip(s
) == trident
) {
1566 voice
= s
->runtime
->private_data
;
1567 evoice
= voice
->extra
;
1568 what
|= 1 << (voice
->number
& 0x1f);
1569 if (evoice
== NULL
) {
1570 whati
|= 1 << (voice
->number
& 0x1f);
1572 what
|= 1 << (evoice
->number
& 0x1f);
1573 whati
|= 1 << (evoice
->number
& 0x1f);
1575 evoice
->stimer
= val
;
1579 voice
->stimer
= val
;
1583 snd_pcm_trigger_done(s
, substream
);
1591 if (trident
->device
!= TRIDENT_DEVICE_ID_SI7018
) {
1592 outl(trident
->spdif_pcm_bits
, TRID_REG(trident
, NX_SPCSTATUS
));
1593 val
= trident
->spdif_pcm_ctrl
;
1596 outb(val
, TRID_REG(trident
, NX_SPCTRL_SPCSO
+ 3));
1598 outl(trident
->spdif_pcm_bits
, TRID_REG(trident
, SI_SPDIF_CS
));
1599 val
= inl(TRID_REG(trident
, SI_SERIAL_INTF_CTRL
)) | SPDIF_EN
;
1600 outl(val
, TRID_REG(trident
, SI_SERIAL_INTF_CTRL
));
1604 outl(what
, TRID_REG(trident
, T4D_STOP_B
));
1605 val
= inl(TRID_REG(trident
, T4D_AINTEN_B
));
1611 outl(val
, TRID_REG(trident
, T4D_AINTEN_B
));
1613 outl(what
, TRID_REG(trident
, T4D_START_B
));
1615 if (capture_flag
&& trident
->device
!= TRIDENT_DEVICE_ID_SI7018
)
1616 outb(trident
->bDMAStart
, TRID_REG(trident
, T4D_SBCTRL_SBE2R_SBDD
));
1618 if (capture_flag
&& trident
->device
!= TRIDENT_DEVICE_ID_SI7018
)
1619 outb(0x00, TRID_REG(trident
, T4D_SBCTRL_SBE2R_SBDD
));
1621 spin_unlock(&trident
->reg_lock
);
1625 /*---------------------------------------------------------------------------
1626 snd_trident_playback_pointer
1628 Description: This routine return the playback position
1630 Parameters: substream - PCM substream class
1632 Returns: position of buffer
1634 ---------------------------------------------------------------------------*/
1636 static snd_pcm_uframes_t
snd_trident_playback_pointer(struct snd_pcm_substream
*substream
)
1638 struct snd_trident
*trident
= snd_pcm_substream_chip(substream
);
1639 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1640 struct snd_trident_voice
*voice
= runtime
->private_data
;
1643 if (!voice
->running
)
1646 spin_lock(&trident
->reg_lock
);
1648 outb(voice
->number
, TRID_REG(trident
, T4D_LFO_GC_CIR
));
1650 if (trident
->device
!= TRIDENT_DEVICE_ID_NX
) {
1651 cso
= inw(TRID_REG(trident
, CH_DX_CSO_ALPHA_FMS
+ 2));
1652 } else { // ID_4DWAVE_NX
1653 cso
= (unsigned int) inl(TRID_REG(trident
, CH_NX_DELTA_CSO
)) & 0x00ffffff;
1656 spin_unlock(&trident
->reg_lock
);
1658 if (cso
>= runtime
->buffer_size
)
1664 /*---------------------------------------------------------------------------
1665 snd_trident_capture_pointer
1667 Description: This routine return the capture position
1669 Parameters: pcm1 - PCM device class
1671 Returns: position of buffer
1673 ---------------------------------------------------------------------------*/
1675 static snd_pcm_uframes_t
snd_trident_capture_pointer(struct snd_pcm_substream
*substream
)
1677 struct snd_trident
*trident
= snd_pcm_substream_chip(substream
);
1678 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1679 struct snd_trident_voice
*voice
= runtime
->private_data
;
1680 unsigned int result
;
1682 if (!voice
->running
)
1685 result
= inw(TRID_REG(trident
, T4D_SBBL_SBCL
));
1686 if (runtime
->channels
> 1)
1689 result
= runtime
->buffer_size
- result
;
1694 /*---------------------------------------------------------------------------
1695 snd_trident_spdif_pointer
1697 Description: This routine return the SPDIF playback position
1699 Parameters: substream - PCM substream class
1701 Returns: position of buffer
1703 ---------------------------------------------------------------------------*/
1705 static snd_pcm_uframes_t
snd_trident_spdif_pointer(struct snd_pcm_substream
*substream
)
1707 struct snd_trident
*trident
= snd_pcm_substream_chip(substream
);
1708 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1709 struct snd_trident_voice
*voice
= runtime
->private_data
;
1710 unsigned int result
;
1712 if (!voice
->running
)
1715 result
= inl(TRID_REG(trident
, NX_SPCTRL_SPCSO
)) & 0x00ffffff;
1721 * Playback support device description
1724 static struct snd_pcm_hardware snd_trident_playback
=
1726 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
1727 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
1728 SNDRV_PCM_INFO_MMAP_VALID
| SNDRV_PCM_INFO_SYNC_START
|
1729 SNDRV_PCM_INFO_PAUSE
/* | SNDRV_PCM_INFO_RESUME */),
1730 .formats
= (SNDRV_PCM_FMTBIT_U8
| SNDRV_PCM_FMTBIT_S16_LE
|
1731 SNDRV_PCM_FMTBIT_S8
| SNDRV_PCM_FMTBIT_U16_LE
),
1732 .rates
= SNDRV_PCM_RATE_CONTINUOUS
| SNDRV_PCM_RATE_8000_48000
,
1737 .buffer_bytes_max
= (256*1024),
1738 .period_bytes_min
= 64,
1739 .period_bytes_max
= (256*1024),
1741 .periods_max
= 1024,
1746 * Capture support device description
1749 static struct snd_pcm_hardware snd_trident_capture
=
1751 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
1752 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
1753 SNDRV_PCM_INFO_MMAP_VALID
| SNDRV_PCM_INFO_SYNC_START
|
1754 SNDRV_PCM_INFO_PAUSE
/* | SNDRV_PCM_INFO_RESUME */),
1755 .formats
= (SNDRV_PCM_FMTBIT_U8
| SNDRV_PCM_FMTBIT_S16_LE
|
1756 SNDRV_PCM_FMTBIT_S8
| SNDRV_PCM_FMTBIT_U16_LE
),
1757 .rates
= SNDRV_PCM_RATE_CONTINUOUS
| SNDRV_PCM_RATE_8000_48000
,
1762 .buffer_bytes_max
= (128*1024),
1763 .period_bytes_min
= 64,
1764 .period_bytes_max
= (128*1024),
1766 .periods_max
= 1024,
1771 * Foldback capture support device description
1774 static struct snd_pcm_hardware snd_trident_foldback
=
1776 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
1777 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
1778 SNDRV_PCM_INFO_MMAP_VALID
| SNDRV_PCM_INFO_SYNC_START
|
1779 SNDRV_PCM_INFO_PAUSE
/* | SNDRV_PCM_INFO_RESUME */),
1780 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
1781 .rates
= SNDRV_PCM_RATE_48000
,
1786 .buffer_bytes_max
= (128*1024),
1787 .period_bytes_min
= 64,
1788 .period_bytes_max
= (128*1024),
1790 .periods_max
= 1024,
1795 * SPDIF playback support device description
1798 static struct snd_pcm_hardware snd_trident_spdif
=
1800 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
1801 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
1802 SNDRV_PCM_INFO_MMAP_VALID
| SNDRV_PCM_INFO_SYNC_START
|
1803 SNDRV_PCM_INFO_PAUSE
/* | SNDRV_PCM_INFO_RESUME */),
1804 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
1805 .rates
= (SNDRV_PCM_RATE_32000
| SNDRV_PCM_RATE_44100
|
1806 SNDRV_PCM_RATE_48000
),
1811 .buffer_bytes_max
= (128*1024),
1812 .period_bytes_min
= 64,
1813 .period_bytes_max
= (128*1024),
1815 .periods_max
= 1024,
1819 static struct snd_pcm_hardware snd_trident_spdif_7018
=
1821 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
1822 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
1823 SNDRV_PCM_INFO_MMAP_VALID
| SNDRV_PCM_INFO_SYNC_START
|
1824 SNDRV_PCM_INFO_PAUSE
/* | SNDRV_PCM_INFO_RESUME */),
1825 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
1826 .rates
= SNDRV_PCM_RATE_48000
,
1831 .buffer_bytes_max
= (128*1024),
1832 .period_bytes_min
= 64,
1833 .period_bytes_max
= (128*1024),
1835 .periods_max
= 1024,
1839 static void snd_trident_pcm_free_substream(struct snd_pcm_runtime
*runtime
)
1841 struct snd_trident_voice
*voice
= runtime
->private_data
;
1842 struct snd_trident
*trident
;
1845 trident
= voice
->trident
;
1846 snd_trident_free_voice(trident
, voice
);
1850 static int snd_trident_playback_open(struct snd_pcm_substream
*substream
)
1852 struct snd_trident
*trident
= snd_pcm_substream_chip(substream
);
1853 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1854 struct snd_trident_voice
*voice
;
1856 voice
= snd_trident_alloc_voice(trident
, SNDRV_TRIDENT_VOICE_TYPE_PCM
, 0, 0);
1859 snd_trident_pcm_mixer_build(trident
, voice
, substream
);
1860 voice
->substream
= substream
;
1861 runtime
->private_data
= voice
;
1862 runtime
->private_free
= snd_trident_pcm_free_substream
;
1863 runtime
->hw
= snd_trident_playback
;
1864 snd_pcm_set_sync(substream
);
1865 snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_BUFFER_SIZE
, 0, 64*1024);
1869 /*---------------------------------------------------------------------------
1870 snd_trident_playback_close
1872 Description: This routine will close the 4DWave playback device. For now
1873 we will simply free the dma transfer buffer.
1875 Parameters: substream - PCM substream class
1877 ---------------------------------------------------------------------------*/
1878 static int snd_trident_playback_close(struct snd_pcm_substream
*substream
)
1880 struct snd_trident
*trident
= snd_pcm_substream_chip(substream
);
1881 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1882 struct snd_trident_voice
*voice
= runtime
->private_data
;
1884 snd_trident_pcm_mixer_free(trident
, voice
, substream
);
1888 /*---------------------------------------------------------------------------
1889 snd_trident_spdif_open
1891 Description: This routine will open the 4DWave SPDIF device.
1893 Parameters: substream - PCM substream class
1895 Returns: status - success or failure flag
1897 ---------------------------------------------------------------------------*/
1899 static int snd_trident_spdif_open(struct snd_pcm_substream
*substream
)
1901 struct snd_trident
*trident
= snd_pcm_substream_chip(substream
);
1902 struct snd_trident_voice
*voice
;
1903 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1905 voice
= snd_trident_alloc_voice(trident
, SNDRV_TRIDENT_VOICE_TYPE_PCM
, 0, 0);
1909 voice
->substream
= substream
;
1910 spin_lock_irq(&trident
->reg_lock
);
1911 trident
->spdif_pcm_bits
= trident
->spdif_bits
;
1912 spin_unlock_irq(&trident
->reg_lock
);
1914 runtime
->private_data
= voice
;
1915 runtime
->private_free
= snd_trident_pcm_free_substream
;
1916 if (trident
->device
== TRIDENT_DEVICE_ID_SI7018
) {
1917 runtime
->hw
= snd_trident_spdif
;
1919 runtime
->hw
= snd_trident_spdif_7018
;
1922 trident
->spdif_pcm_ctl
->vd
[0].access
&= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE
;
1923 snd_ctl_notify(trident
->card
, SNDRV_CTL_EVENT_MASK_VALUE
|
1924 SNDRV_CTL_EVENT_MASK_INFO
, &trident
->spdif_pcm_ctl
->id
);
1926 snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_BUFFER_SIZE
, 0, 64*1024);
1931 /*---------------------------------------------------------------------------
1932 snd_trident_spdif_close
1934 Description: This routine will close the 4DWave SPDIF device.
1936 Parameters: substream - PCM substream class
1938 ---------------------------------------------------------------------------*/
1940 static int snd_trident_spdif_close(struct snd_pcm_substream
*substream
)
1942 struct snd_trident
*trident
= snd_pcm_substream_chip(substream
);
1945 spin_lock_irq(&trident
->reg_lock
);
1946 // restore default SPDIF setting
1947 if (trident
->device
!= TRIDENT_DEVICE_ID_SI7018
) {
1948 outb(trident
->spdif_ctrl
, TRID_REG(trident
, NX_SPCTRL_SPCSO
+ 3));
1949 outl(trident
->spdif_bits
, TRID_REG(trident
, NX_SPCSTATUS
));
1951 outl(trident
->spdif_bits
, TRID_REG(trident
, SI_SPDIF_CS
));
1952 temp
= inl(TRID_REG(trident
, SI_SERIAL_INTF_CTRL
));
1953 if (trident
->spdif_ctrl
) {
1958 outl(temp
, TRID_REG(trident
, SI_SERIAL_INTF_CTRL
));
1960 spin_unlock_irq(&trident
->reg_lock
);
1961 trident
->spdif_pcm_ctl
->vd
[0].access
|= SNDRV_CTL_ELEM_ACCESS_INACTIVE
;
1962 snd_ctl_notify(trident
->card
, SNDRV_CTL_EVENT_MASK_VALUE
|
1963 SNDRV_CTL_EVENT_MASK_INFO
, &trident
->spdif_pcm_ctl
->id
);
1967 /*---------------------------------------------------------------------------
1968 snd_trident_capture_open
1970 Description: This routine will open the 4DWave capture device.
1972 Parameters: substream - PCM substream class
1974 Returns: status - success or failure flag
1976 ---------------------------------------------------------------------------*/
1978 static int snd_trident_capture_open(struct snd_pcm_substream
*substream
)
1980 struct snd_trident
*trident
= snd_pcm_substream_chip(substream
);
1981 struct snd_trident_voice
*voice
;
1982 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1984 voice
= snd_trident_alloc_voice(trident
, SNDRV_TRIDENT_VOICE_TYPE_PCM
, 0, 0);
1988 voice
->substream
= substream
;
1989 runtime
->private_data
= voice
;
1990 runtime
->private_free
= snd_trident_pcm_free_substream
;
1991 runtime
->hw
= snd_trident_capture
;
1992 snd_pcm_set_sync(substream
);
1993 snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_BUFFER_SIZE
, 0, 64*1024);
1997 /*---------------------------------------------------------------------------
1998 snd_trident_capture_close
2000 Description: This routine will close the 4DWave capture device. For now
2001 we will simply free the dma transfer buffer.
2003 Parameters: substream - PCM substream class
2005 ---------------------------------------------------------------------------*/
2006 static int snd_trident_capture_close(struct snd_pcm_substream
*substream
)
2011 /*---------------------------------------------------------------------------
2012 snd_trident_foldback_open
2014 Description: This routine will open the 4DWave foldback capture device.
2016 Parameters: substream - PCM substream class
2018 Returns: status - success or failure flag
2020 ---------------------------------------------------------------------------*/
2022 static int snd_trident_foldback_open(struct snd_pcm_substream
*substream
)
2024 struct snd_trident
*trident
= snd_pcm_substream_chip(substream
);
2025 struct snd_trident_voice
*voice
;
2026 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2028 voice
= snd_trident_alloc_voice(trident
, SNDRV_TRIDENT_VOICE_TYPE_PCM
, 0, 0);
2031 voice
->foldback_chan
= substream
->number
;
2032 voice
->substream
= substream
;
2033 runtime
->private_data
= voice
;
2034 runtime
->private_free
= snd_trident_pcm_free_substream
;
2035 runtime
->hw
= snd_trident_foldback
;
2036 snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_BUFFER_SIZE
, 0, 64*1024);
2040 /*---------------------------------------------------------------------------
2041 snd_trident_foldback_close
2043 Description: This routine will close the 4DWave foldback capture device.
2044 For now we will simply free the dma transfer buffer.
2046 Parameters: substream - PCM substream class
2048 ---------------------------------------------------------------------------*/
2049 static int snd_trident_foldback_close(struct snd_pcm_substream
*substream
)
2051 struct snd_trident
*trident
= snd_pcm_substream_chip(substream
);
2052 struct snd_trident_voice
*voice
;
2053 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2054 voice
= runtime
->private_data
;
2056 /* stop capture channel */
2057 spin_lock_irq(&trident
->reg_lock
);
2058 outb(0x00, TRID_REG(trident
, T4D_RCI
+ voice
->foldback_chan
));
2059 spin_unlock_irq(&trident
->reg_lock
);
2063 /*---------------------------------------------------------------------------
2065 ---------------------------------------------------------------------------*/
2067 static struct snd_pcm_ops snd_trident_playback_ops
= {
2068 .open
= snd_trident_playback_open
,
2069 .close
= snd_trident_playback_close
,
2070 .ioctl
= snd_trident_ioctl
,
2071 .hw_params
= snd_trident_hw_params
,
2072 .hw_free
= snd_trident_hw_free
,
2073 .prepare
= snd_trident_playback_prepare
,
2074 .trigger
= snd_trident_trigger
,
2075 .pointer
= snd_trident_playback_pointer
,
2078 static struct snd_pcm_ops snd_trident_nx_playback_ops
= {
2079 .open
= snd_trident_playback_open
,
2080 .close
= snd_trident_playback_close
,
2081 .ioctl
= snd_trident_ioctl
,
2082 .hw_params
= snd_trident_hw_params
,
2083 .hw_free
= snd_trident_hw_free
,
2084 .prepare
= snd_trident_playback_prepare
,
2085 .trigger
= snd_trident_trigger
,
2086 .pointer
= snd_trident_playback_pointer
,
2087 .page
= snd_pcm_sgbuf_ops_page
,
2090 static struct snd_pcm_ops snd_trident_capture_ops
= {
2091 .open
= snd_trident_capture_open
,
2092 .close
= snd_trident_capture_close
,
2093 .ioctl
= snd_trident_ioctl
,
2094 .hw_params
= snd_trident_capture_hw_params
,
2095 .hw_free
= snd_trident_hw_free
,
2096 .prepare
= snd_trident_capture_prepare
,
2097 .trigger
= snd_trident_trigger
,
2098 .pointer
= snd_trident_capture_pointer
,
2101 static struct snd_pcm_ops snd_trident_si7018_capture_ops
= {
2102 .open
= snd_trident_capture_open
,
2103 .close
= snd_trident_capture_close
,
2104 .ioctl
= snd_trident_ioctl
,
2105 .hw_params
= snd_trident_si7018_capture_hw_params
,
2106 .hw_free
= snd_trident_si7018_capture_hw_free
,
2107 .prepare
= snd_trident_si7018_capture_prepare
,
2108 .trigger
= snd_trident_trigger
,
2109 .pointer
= snd_trident_playback_pointer
,
2112 static struct snd_pcm_ops snd_trident_foldback_ops
= {
2113 .open
= snd_trident_foldback_open
,
2114 .close
= snd_trident_foldback_close
,
2115 .ioctl
= snd_trident_ioctl
,
2116 .hw_params
= snd_trident_hw_params
,
2117 .hw_free
= snd_trident_hw_free
,
2118 .prepare
= snd_trident_foldback_prepare
,
2119 .trigger
= snd_trident_trigger
,
2120 .pointer
= snd_trident_playback_pointer
,
2123 static struct snd_pcm_ops snd_trident_nx_foldback_ops
= {
2124 .open
= snd_trident_foldback_open
,
2125 .close
= snd_trident_foldback_close
,
2126 .ioctl
= snd_trident_ioctl
,
2127 .hw_params
= snd_trident_hw_params
,
2128 .hw_free
= snd_trident_hw_free
,
2129 .prepare
= snd_trident_foldback_prepare
,
2130 .trigger
= snd_trident_trigger
,
2131 .pointer
= snd_trident_playback_pointer
,
2132 .page
= snd_pcm_sgbuf_ops_page
,
2135 static struct snd_pcm_ops snd_trident_spdif_ops
= {
2136 .open
= snd_trident_spdif_open
,
2137 .close
= snd_trident_spdif_close
,
2138 .ioctl
= snd_trident_ioctl
,
2139 .hw_params
= snd_trident_spdif_hw_params
,
2140 .hw_free
= snd_trident_hw_free
,
2141 .prepare
= snd_trident_spdif_prepare
,
2142 .trigger
= snd_trident_trigger
,
2143 .pointer
= snd_trident_spdif_pointer
,
2146 static struct snd_pcm_ops snd_trident_spdif_7018_ops
= {
2147 .open
= snd_trident_spdif_open
,
2148 .close
= snd_trident_spdif_close
,
2149 .ioctl
= snd_trident_ioctl
,
2150 .hw_params
= snd_trident_spdif_hw_params
,
2151 .hw_free
= snd_trident_hw_free
,
2152 .prepare
= snd_trident_spdif_prepare
,
2153 .trigger
= snd_trident_trigger
,
2154 .pointer
= snd_trident_playback_pointer
,
2157 /*---------------------------------------------------------------------------
2160 Description: This routine registers the 4DWave device for PCM support.
2162 Parameters: trident - pointer to target device class for 4DWave.
2166 ---------------------------------------------------------------------------*/
2168 int __devinit
snd_trident_pcm(struct snd_trident
* trident
,
2169 int device
, struct snd_pcm
** rpcm
)
2171 struct snd_pcm
*pcm
;
2176 if ((err
= snd_pcm_new(trident
->card
, "trident_dx_nx", device
, trident
->ChanPCM
, 1, &pcm
)) < 0)
2179 pcm
->private_data
= trident
;
2181 if (trident
->tlb
.entries
) {
2182 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_trident_nx_playback_ops
);
2184 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_trident_playback_ops
);
2186 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
,
2187 trident
->device
!= TRIDENT_DEVICE_ID_SI7018
?
2188 &snd_trident_capture_ops
:
2189 &snd_trident_si7018_capture_ops
);
2191 pcm
->info_flags
= 0;
2192 pcm
->dev_subclass
= SNDRV_PCM_SUBCLASS_GENERIC_MIX
;
2193 strcpy(pcm
->name
, "Trident 4DWave");
2196 if (trident
->tlb
.entries
) {
2197 struct snd_pcm_substream
*substream
;
2198 for (substream
= pcm
->streams
[SNDRV_PCM_STREAM_PLAYBACK
].substream
; substream
; substream
= substream
->next
)
2199 snd_pcm_lib_preallocate_pages(substream
, SNDRV_DMA_TYPE_DEV_SG
,
2200 snd_dma_pci_data(trident
->pci
),
2202 snd_pcm_lib_preallocate_pages(pcm
->streams
[SNDRV_PCM_STREAM_CAPTURE
].substream
,
2203 SNDRV_DMA_TYPE_DEV
, snd_dma_pci_data(trident
->pci
),
2206 snd_pcm_lib_preallocate_pages_for_all(pcm
, SNDRV_DMA_TYPE_DEV
,
2207 snd_dma_pci_data(trident
->pci
), 64*1024, 128*1024);
2215 /*---------------------------------------------------------------------------
2216 snd_trident_foldback_pcm
2218 Description: This routine registers the 4DWave device for foldback PCM support.
2220 Parameters: trident - pointer to target device class for 4DWave.
2224 ---------------------------------------------------------------------------*/
2226 int __devinit
snd_trident_foldback_pcm(struct snd_trident
* trident
,
2227 int device
, struct snd_pcm
** rpcm
)
2229 struct snd_pcm
*foldback
;
2232 struct snd_pcm_substream
*substream
;
2236 if (trident
->device
== TRIDENT_DEVICE_ID_NX
)
2238 if ((err
= snd_pcm_new(trident
->card
, "trident_dx_nx", device
, 0, num_chan
, &foldback
)) < 0)
2241 foldback
->private_data
= trident
;
2242 if (trident
->tlb
.entries
)
2243 snd_pcm_set_ops(foldback
, SNDRV_PCM_STREAM_CAPTURE
, &snd_trident_nx_foldback_ops
);
2245 snd_pcm_set_ops(foldback
, SNDRV_PCM_STREAM_CAPTURE
, &snd_trident_foldback_ops
);
2246 foldback
->info_flags
= 0;
2247 strcpy(foldback
->name
, "Trident 4DWave");
2248 substream
= foldback
->streams
[SNDRV_PCM_STREAM_CAPTURE
].substream
;
2249 strcpy(substream
->name
, "Front Mixer");
2250 substream
= substream
->next
;
2251 strcpy(substream
->name
, "Reverb Mixer");
2252 substream
= substream
->next
;
2253 strcpy(substream
->name
, "Chorus Mixer");
2254 if (num_chan
== 4) {
2255 substream
= substream
->next
;
2256 strcpy(substream
->name
, "Second AC'97 ADC");
2258 trident
->foldback
= foldback
;
2260 if (trident
->tlb
.entries
)
2261 snd_pcm_lib_preallocate_pages_for_all(foldback
, SNDRV_DMA_TYPE_DEV_SG
,
2262 snd_dma_pci_data(trident
->pci
), 0, 128*1024);
2264 snd_pcm_lib_preallocate_pages_for_all(foldback
, SNDRV_DMA_TYPE_DEV
,
2265 snd_dma_pci_data(trident
->pci
), 64*1024, 128*1024);
2272 /*---------------------------------------------------------------------------
2275 Description: This routine registers the 4DWave-NX device for SPDIF support.
2277 Parameters: trident - pointer to target device class for 4DWave-NX.
2281 ---------------------------------------------------------------------------*/
2283 int __devinit
snd_trident_spdif_pcm(struct snd_trident
* trident
,
2284 int device
, struct snd_pcm
** rpcm
)
2286 struct snd_pcm
*spdif
;
2291 if ((err
= snd_pcm_new(trident
->card
, "trident_dx_nx IEC958", device
, 1, 0, &spdif
)) < 0)
2294 spdif
->private_data
= trident
;
2295 if (trident
->device
!= TRIDENT_DEVICE_ID_SI7018
) {
2296 snd_pcm_set_ops(spdif
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_trident_spdif_ops
);
2298 snd_pcm_set_ops(spdif
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_trident_spdif_7018_ops
);
2300 spdif
->info_flags
= 0;
2301 strcpy(spdif
->name
, "Trident 4DWave IEC958");
2302 trident
->spdif
= spdif
;
2304 snd_pcm_lib_preallocate_pages_for_all(spdif
, SNDRV_DMA_TYPE_DEV
, snd_dma_pci_data(trident
->pci
), 64*1024, 128*1024);
2316 /*---------------------------------------------------------------------------
2317 snd_trident_spdif_control
2319 Description: enable/disable S/PDIF out from ac97 mixer
2320 ---------------------------------------------------------------------------*/
2322 #define snd_trident_spdif_control_info snd_ctl_boolean_mono_info
2324 static int snd_trident_spdif_control_get(struct snd_kcontrol
*kcontrol
,
2325 struct snd_ctl_elem_value
*ucontrol
)
2327 struct snd_trident
*trident
= snd_kcontrol_chip(kcontrol
);
2330 spin_lock_irq(&trident
->reg_lock
);
2331 val
= trident
->spdif_ctrl
;
2332 ucontrol
->value
.integer
.value
[0] = val
== kcontrol
->private_value
;
2333 spin_unlock_irq(&trident
->reg_lock
);
2337 static int snd_trident_spdif_control_put(struct snd_kcontrol
*kcontrol
,
2338 struct snd_ctl_elem_value
*ucontrol
)
2340 struct snd_trident
*trident
= snd_kcontrol_chip(kcontrol
);
2344 val
= ucontrol
->value
.integer
.value
[0] ? (unsigned char) kcontrol
->private_value
: 0x00;
2345 spin_lock_irq(&trident
->reg_lock
);
2346 /* S/PDIF C Channel bits 0-31 : 48khz, SCMS disabled */
2347 change
= trident
->spdif_ctrl
!= val
;
2348 trident
->spdif_ctrl
= val
;
2349 if (trident
->device
!= TRIDENT_DEVICE_ID_SI7018
) {
2350 if ((inb(TRID_REG(trident
, NX_SPCTRL_SPCSO
+ 3)) & 0x10) == 0) {
2351 outl(trident
->spdif_bits
, TRID_REG(trident
, NX_SPCSTATUS
));
2352 outb(trident
->spdif_ctrl
, TRID_REG(trident
, NX_SPCTRL_SPCSO
+ 3));
2355 if (trident
->spdif
== NULL
) {
2357 outl(trident
->spdif_bits
, TRID_REG(trident
, SI_SPDIF_CS
));
2358 temp
= inl(TRID_REG(trident
, SI_SERIAL_INTF_CTRL
)) & ~SPDIF_EN
;
2361 outl(temp
, TRID_REG(trident
, SI_SERIAL_INTF_CTRL
));
2364 spin_unlock_irq(&trident
->reg_lock
);
2368 static struct snd_kcontrol_new snd_trident_spdif_control __devinitdata
=
2370 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2371 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,SWITCH
),
2372 .info
= snd_trident_spdif_control_info
,
2373 .get
= snd_trident_spdif_control_get
,
2374 .put
= snd_trident_spdif_control_put
,
2375 .private_value
= 0x28,
2378 /*---------------------------------------------------------------------------
2379 snd_trident_spdif_default
2381 Description: put/get the S/PDIF default settings
2382 ---------------------------------------------------------------------------*/
2384 static int snd_trident_spdif_default_info(struct snd_kcontrol
*kcontrol
,
2385 struct snd_ctl_elem_info
*uinfo
)
2387 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_IEC958
;
2392 static int snd_trident_spdif_default_get(struct snd_kcontrol
*kcontrol
,
2393 struct snd_ctl_elem_value
*ucontrol
)
2395 struct snd_trident
*trident
= snd_kcontrol_chip(kcontrol
);
2397 spin_lock_irq(&trident
->reg_lock
);
2398 ucontrol
->value
.iec958
.status
[0] = (trident
->spdif_bits
>> 0) & 0xff;
2399 ucontrol
->value
.iec958
.status
[1] = (trident
->spdif_bits
>> 8) & 0xff;
2400 ucontrol
->value
.iec958
.status
[2] = (trident
->spdif_bits
>> 16) & 0xff;
2401 ucontrol
->value
.iec958
.status
[3] = (trident
->spdif_bits
>> 24) & 0xff;
2402 spin_unlock_irq(&trident
->reg_lock
);
2406 static int snd_trident_spdif_default_put(struct snd_kcontrol
*kcontrol
,
2407 struct snd_ctl_elem_value
*ucontrol
)
2409 struct snd_trident
*trident
= snd_kcontrol_chip(kcontrol
);
2413 val
= (ucontrol
->value
.iec958
.status
[0] << 0) |
2414 (ucontrol
->value
.iec958
.status
[1] << 8) |
2415 (ucontrol
->value
.iec958
.status
[2] << 16) |
2416 (ucontrol
->value
.iec958
.status
[3] << 24);
2417 spin_lock_irq(&trident
->reg_lock
);
2418 change
= trident
->spdif_bits
!= val
;
2419 trident
->spdif_bits
= val
;
2420 if (trident
->device
!= TRIDENT_DEVICE_ID_SI7018
) {
2421 if ((inb(TRID_REG(trident
, NX_SPCTRL_SPCSO
+ 3)) & 0x10) == 0)
2422 outl(trident
->spdif_bits
, TRID_REG(trident
, NX_SPCSTATUS
));
2424 if (trident
->spdif
== NULL
)
2425 outl(trident
->spdif_bits
, TRID_REG(trident
, SI_SPDIF_CS
));
2427 spin_unlock_irq(&trident
->reg_lock
);
2431 static struct snd_kcontrol_new snd_trident_spdif_default __devinitdata
=
2433 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
2434 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,DEFAULT
),
2435 .info
= snd_trident_spdif_default_info
,
2436 .get
= snd_trident_spdif_default_get
,
2437 .put
= snd_trident_spdif_default_put
2440 /*---------------------------------------------------------------------------
2441 snd_trident_spdif_mask
2443 Description: put/get the S/PDIF mask
2444 ---------------------------------------------------------------------------*/
2446 static int snd_trident_spdif_mask_info(struct snd_kcontrol
*kcontrol
,
2447 struct snd_ctl_elem_info
*uinfo
)
2449 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_IEC958
;
2454 static int snd_trident_spdif_mask_get(struct snd_kcontrol
*kcontrol
,
2455 struct snd_ctl_elem_value
*ucontrol
)
2457 ucontrol
->value
.iec958
.status
[0] = 0xff;
2458 ucontrol
->value
.iec958
.status
[1] = 0xff;
2459 ucontrol
->value
.iec958
.status
[2] = 0xff;
2460 ucontrol
->value
.iec958
.status
[3] = 0xff;
2464 static struct snd_kcontrol_new snd_trident_spdif_mask __devinitdata
=
2466 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
2467 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
2468 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,MASK
),
2469 .info
= snd_trident_spdif_mask_info
,
2470 .get
= snd_trident_spdif_mask_get
,
2473 /*---------------------------------------------------------------------------
2474 snd_trident_spdif_stream
2476 Description: put/get the S/PDIF stream settings
2477 ---------------------------------------------------------------------------*/
2479 static int snd_trident_spdif_stream_info(struct snd_kcontrol
*kcontrol
,
2480 struct snd_ctl_elem_info
*uinfo
)
2482 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_IEC958
;
2487 static int snd_trident_spdif_stream_get(struct snd_kcontrol
*kcontrol
,
2488 struct snd_ctl_elem_value
*ucontrol
)
2490 struct snd_trident
*trident
= snd_kcontrol_chip(kcontrol
);
2492 spin_lock_irq(&trident
->reg_lock
);
2493 ucontrol
->value
.iec958
.status
[0] = (trident
->spdif_pcm_bits
>> 0) & 0xff;
2494 ucontrol
->value
.iec958
.status
[1] = (trident
->spdif_pcm_bits
>> 8) & 0xff;
2495 ucontrol
->value
.iec958
.status
[2] = (trident
->spdif_pcm_bits
>> 16) & 0xff;
2496 ucontrol
->value
.iec958
.status
[3] = (trident
->spdif_pcm_bits
>> 24) & 0xff;
2497 spin_unlock_irq(&trident
->reg_lock
);
2501 static int snd_trident_spdif_stream_put(struct snd_kcontrol
*kcontrol
,
2502 struct snd_ctl_elem_value
*ucontrol
)
2504 struct snd_trident
*trident
= snd_kcontrol_chip(kcontrol
);
2508 val
= (ucontrol
->value
.iec958
.status
[0] << 0) |
2509 (ucontrol
->value
.iec958
.status
[1] << 8) |
2510 (ucontrol
->value
.iec958
.status
[2] << 16) |
2511 (ucontrol
->value
.iec958
.status
[3] << 24);
2512 spin_lock_irq(&trident
->reg_lock
);
2513 change
= trident
->spdif_pcm_bits
!= val
;
2514 trident
->spdif_pcm_bits
= val
;
2515 if (trident
->spdif
!= NULL
) {
2516 if (trident
->device
!= TRIDENT_DEVICE_ID_SI7018
) {
2517 outl(trident
->spdif_pcm_bits
, TRID_REG(trident
, NX_SPCSTATUS
));
2519 outl(trident
->spdif_bits
, TRID_REG(trident
, SI_SPDIF_CS
));
2522 spin_unlock_irq(&trident
->reg_lock
);
2526 static struct snd_kcontrol_new snd_trident_spdif_stream __devinitdata
=
2528 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
| SNDRV_CTL_ELEM_ACCESS_INACTIVE
,
2529 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
2530 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,PCM_STREAM
),
2531 .info
= snd_trident_spdif_stream_info
,
2532 .get
= snd_trident_spdif_stream_get
,
2533 .put
= snd_trident_spdif_stream_put
2536 /*---------------------------------------------------------------------------
2537 snd_trident_ac97_control
2539 Description: enable/disable rear path for ac97
2540 ---------------------------------------------------------------------------*/
2542 #define snd_trident_ac97_control_info snd_ctl_boolean_mono_info
2544 static int snd_trident_ac97_control_get(struct snd_kcontrol
*kcontrol
,
2545 struct snd_ctl_elem_value
*ucontrol
)
2547 struct snd_trident
*trident
= snd_kcontrol_chip(kcontrol
);
2550 spin_lock_irq(&trident
->reg_lock
);
2551 val
= trident
->ac97_ctrl
= inl(TRID_REG(trident
, NX_ACR0_AC97_COM_STAT
));
2552 ucontrol
->value
.integer
.value
[0] = (val
& (1 << kcontrol
->private_value
)) ? 1 : 0;
2553 spin_unlock_irq(&trident
->reg_lock
);
2557 static int snd_trident_ac97_control_put(struct snd_kcontrol
*kcontrol
,
2558 struct snd_ctl_elem_value
*ucontrol
)
2560 struct snd_trident
*trident
= snd_kcontrol_chip(kcontrol
);
2564 spin_lock_irq(&trident
->reg_lock
);
2565 val
= trident
->ac97_ctrl
= inl(TRID_REG(trident
, NX_ACR0_AC97_COM_STAT
));
2566 val
&= ~(1 << kcontrol
->private_value
);
2567 if (ucontrol
->value
.integer
.value
[0])
2568 val
|= 1 << kcontrol
->private_value
;
2569 change
= val
!= trident
->ac97_ctrl
;
2570 trident
->ac97_ctrl
= val
;
2571 outl(trident
->ac97_ctrl
= val
, TRID_REG(trident
, NX_ACR0_AC97_COM_STAT
));
2572 spin_unlock_irq(&trident
->reg_lock
);
2576 static struct snd_kcontrol_new snd_trident_ac97_rear_control __devinitdata
=
2578 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2579 .name
= "Rear Path",
2580 .info
= snd_trident_ac97_control_info
,
2581 .get
= snd_trident_ac97_control_get
,
2582 .put
= snd_trident_ac97_control_put
,
2586 /*---------------------------------------------------------------------------
2587 snd_trident_vol_control
2589 Description: wave & music volume control
2590 ---------------------------------------------------------------------------*/
2592 static int snd_trident_vol_control_info(struct snd_kcontrol
*kcontrol
,
2593 struct snd_ctl_elem_info
*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(struct snd_kcontrol
*kcontrol
,
2603 struct snd_ctl_elem_value
*ucontrol
)
2605 struct snd_trident
*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 const DECLARE_TLV_DB_SCALE(db_scale_gvol
, -6375, 25, 0);
2616 static int snd_trident_vol_control_put(struct snd_kcontrol
*kcontrol
,
2617 struct snd_ctl_elem_value
*ucontrol
)
2619 struct snd_trident
*trident
= snd_kcontrol_chip(kcontrol
);
2623 spin_lock_irq(&trident
->reg_lock
);
2624 val
= trident
->musicvol_wavevol
;
2625 val
&= ~(0xffff << kcontrol
->private_value
);
2626 val
|= ((255 - (ucontrol
->value
.integer
.value
[0] & 0xff)) |
2627 ((255 - (ucontrol
->value
.integer
.value
[1] & 0xff)) << 8)) << kcontrol
->private_value
;
2628 change
= val
!= trident
->musicvol_wavevol
;
2629 outl(trident
->musicvol_wavevol
= val
, TRID_REG(trident
, T4D_MUSICVOL_WAVEVOL
));
2630 spin_unlock_irq(&trident
->reg_lock
);
2634 static struct snd_kcontrol_new snd_trident_vol_music_control __devinitdata
=
2636 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2637 .name
= "Music Playback Volume",
2638 .info
= snd_trident_vol_control_info
,
2639 .get
= snd_trident_vol_control_get
,
2640 .put
= snd_trident_vol_control_put
,
2641 .private_value
= 16,
2642 .tlv
= { .p
= db_scale_gvol
},
2645 static struct snd_kcontrol_new snd_trident_vol_wave_control __devinitdata
=
2647 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2648 .name
= "Wave Playback Volume",
2649 .info
= snd_trident_vol_control_info
,
2650 .get
= snd_trident_vol_control_get
,
2651 .put
= snd_trident_vol_control_put
,
2653 .tlv
= { .p
= db_scale_gvol
},
2656 /*---------------------------------------------------------------------------
2657 snd_trident_pcm_vol_control
2659 Description: PCM front volume control
2660 ---------------------------------------------------------------------------*/
2662 static int snd_trident_pcm_vol_control_info(struct snd_kcontrol
*kcontrol
,
2663 struct snd_ctl_elem_info
*uinfo
)
2665 struct snd_trident
*trident
= snd_kcontrol_chip(kcontrol
);
2667 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2669 uinfo
->value
.integer
.min
= 0;
2670 uinfo
->value
.integer
.max
= 255;
2671 if (trident
->device
== TRIDENT_DEVICE_ID_SI7018
)
2672 uinfo
->value
.integer
.max
= 1023;
2676 static int snd_trident_pcm_vol_control_get(struct snd_kcontrol
*kcontrol
,
2677 struct snd_ctl_elem_value
*ucontrol
)
2679 struct snd_trident
*trident
= snd_kcontrol_chip(kcontrol
);
2680 struct snd_trident_pcm_mixer
*mix
= &trident
->pcm_mixer
[snd_ctl_get_ioffnum(kcontrol
, &ucontrol
->id
)];
2682 if (trident
->device
== TRIDENT_DEVICE_ID_SI7018
) {
2683 ucontrol
->value
.integer
.value
[0] = 1023 - mix
->vol
;
2685 ucontrol
->value
.integer
.value
[0] = 255 - (mix
->vol
>>2);
2690 static int snd_trident_pcm_vol_control_put(struct snd_kcontrol
*kcontrol
,
2691 struct snd_ctl_elem_value
*ucontrol
)
2693 struct snd_trident
*trident
= snd_kcontrol_chip(kcontrol
);
2694 struct snd_trident_pcm_mixer
*mix
= &trident
->pcm_mixer
[snd_ctl_get_ioffnum(kcontrol
, &ucontrol
->id
)];
2698 if (trident
->device
== TRIDENT_DEVICE_ID_SI7018
) {
2699 val
= 1023 - (ucontrol
->value
.integer
.value
[0] & 1023);
2701 val
= (255 - (ucontrol
->value
.integer
.value
[0] & 255)) << 2;
2703 spin_lock_irq(&trident
->reg_lock
);
2704 change
= val
!= mix
->vol
;
2706 if (mix
->voice
!= NULL
)
2707 snd_trident_write_vol_reg(trident
, mix
->voice
, val
);
2708 spin_unlock_irq(&trident
->reg_lock
);
2712 static struct snd_kcontrol_new snd_trident_pcm_vol_control __devinitdata
=
2714 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2715 .name
= "PCM Front Playback Volume",
2716 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
| SNDRV_CTL_ELEM_ACCESS_INACTIVE
,
2718 .info
= snd_trident_pcm_vol_control_info
,
2719 .get
= snd_trident_pcm_vol_control_get
,
2720 .put
= snd_trident_pcm_vol_control_put
,
2721 /* FIXME: no tlv yet */
2724 /*---------------------------------------------------------------------------
2725 snd_trident_pcm_pan_control
2727 Description: PCM front pan control
2728 ---------------------------------------------------------------------------*/
2730 static int snd_trident_pcm_pan_control_info(struct snd_kcontrol
*kcontrol
,
2731 struct snd_ctl_elem_info
*uinfo
)
2733 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2735 uinfo
->value
.integer
.min
= 0;
2736 uinfo
->value
.integer
.max
= 127;
2740 static int snd_trident_pcm_pan_control_get(struct snd_kcontrol
*kcontrol
,
2741 struct snd_ctl_elem_value
*ucontrol
)
2743 struct snd_trident
*trident
= snd_kcontrol_chip(kcontrol
);
2744 struct snd_trident_pcm_mixer
*mix
= &trident
->pcm_mixer
[snd_ctl_get_ioffnum(kcontrol
, &ucontrol
->id
)];
2746 ucontrol
->value
.integer
.value
[0] = mix
->pan
;
2747 if (ucontrol
->value
.integer
.value
[0] & 0x40) {
2748 ucontrol
->value
.integer
.value
[0] = (0x3f - (ucontrol
->value
.integer
.value
[0] & 0x3f));
2750 ucontrol
->value
.integer
.value
[0] |= 0x40;
2755 static int snd_trident_pcm_pan_control_put(struct snd_kcontrol
*kcontrol
,
2756 struct snd_ctl_elem_value
*ucontrol
)
2758 struct snd_trident
*trident
= snd_kcontrol_chip(kcontrol
);
2759 struct snd_trident_pcm_mixer
*mix
= &trident
->pcm_mixer
[snd_ctl_get_ioffnum(kcontrol
, &ucontrol
->id
)];
2763 if (ucontrol
->value
.integer
.value
[0] & 0x40)
2764 val
= ucontrol
->value
.integer
.value
[0] & 0x3f;
2766 val
= (0x3f - (ucontrol
->value
.integer
.value
[0] & 0x3f)) | 0x40;
2767 spin_lock_irq(&trident
->reg_lock
);
2768 change
= val
!= mix
->pan
;
2770 if (mix
->voice
!= NULL
)
2771 snd_trident_write_pan_reg(trident
, mix
->voice
, val
);
2772 spin_unlock_irq(&trident
->reg_lock
);
2776 static struct snd_kcontrol_new snd_trident_pcm_pan_control __devinitdata
=
2778 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2779 .name
= "PCM Pan Playback Control",
2780 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
| SNDRV_CTL_ELEM_ACCESS_INACTIVE
,
2782 .info
= snd_trident_pcm_pan_control_info
,
2783 .get
= snd_trident_pcm_pan_control_get
,
2784 .put
= snd_trident_pcm_pan_control_put
,
2787 /*---------------------------------------------------------------------------
2788 snd_trident_pcm_rvol_control
2790 Description: PCM reverb volume control
2791 ---------------------------------------------------------------------------*/
2793 static int snd_trident_pcm_rvol_control_info(struct snd_kcontrol
*kcontrol
,
2794 struct snd_ctl_elem_info
*uinfo
)
2796 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2798 uinfo
->value
.integer
.min
= 0;
2799 uinfo
->value
.integer
.max
= 127;
2803 static int snd_trident_pcm_rvol_control_get(struct snd_kcontrol
*kcontrol
,
2804 struct snd_ctl_elem_value
*ucontrol
)
2806 struct snd_trident
*trident
= snd_kcontrol_chip(kcontrol
);
2807 struct snd_trident_pcm_mixer
*mix
= &trident
->pcm_mixer
[snd_ctl_get_ioffnum(kcontrol
, &ucontrol
->id
)];
2809 ucontrol
->value
.integer
.value
[0] = 127 - mix
->rvol
;
2813 static int snd_trident_pcm_rvol_control_put(struct snd_kcontrol
*kcontrol
,
2814 struct snd_ctl_elem_value
*ucontrol
)
2816 struct snd_trident
*trident
= snd_kcontrol_chip(kcontrol
);
2817 struct snd_trident_pcm_mixer
*mix
= &trident
->pcm_mixer
[snd_ctl_get_ioffnum(kcontrol
, &ucontrol
->id
)];
2821 val
= 0x7f - (ucontrol
->value
.integer
.value
[0] & 0x7f);
2822 spin_lock_irq(&trident
->reg_lock
);
2823 change
= val
!= mix
->rvol
;
2825 if (mix
->voice
!= NULL
)
2826 snd_trident_write_rvol_reg(trident
, mix
->voice
, val
);
2827 spin_unlock_irq(&trident
->reg_lock
);
2831 static const DECLARE_TLV_DB_SCALE(db_scale_crvol
, -3175, 25, 1);
2833 static struct snd_kcontrol_new snd_trident_pcm_rvol_control __devinitdata
=
2835 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2836 .name
= "PCM Reverb Playback Volume",
2837 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
| SNDRV_CTL_ELEM_ACCESS_INACTIVE
,
2839 .info
= snd_trident_pcm_rvol_control_info
,
2840 .get
= snd_trident_pcm_rvol_control_get
,
2841 .put
= snd_trident_pcm_rvol_control_put
,
2842 .tlv
= { .p
= db_scale_crvol
},
2845 /*---------------------------------------------------------------------------
2846 snd_trident_pcm_cvol_control
2848 Description: PCM chorus volume control
2849 ---------------------------------------------------------------------------*/
2851 static int snd_trident_pcm_cvol_control_info(struct snd_kcontrol
*kcontrol
,
2852 struct snd_ctl_elem_info
*uinfo
)
2854 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2856 uinfo
->value
.integer
.min
= 0;
2857 uinfo
->value
.integer
.max
= 127;
2861 static int snd_trident_pcm_cvol_control_get(struct snd_kcontrol
*kcontrol
,
2862 struct snd_ctl_elem_value
*ucontrol
)
2864 struct snd_trident
*trident
= snd_kcontrol_chip(kcontrol
);
2865 struct snd_trident_pcm_mixer
*mix
= &trident
->pcm_mixer
[snd_ctl_get_ioffnum(kcontrol
, &ucontrol
->id
)];
2867 ucontrol
->value
.integer
.value
[0] = 127 - mix
->cvol
;
2871 static int snd_trident_pcm_cvol_control_put(struct snd_kcontrol
*kcontrol
,
2872 struct snd_ctl_elem_value
*ucontrol
)
2874 struct snd_trident
*trident
= snd_kcontrol_chip(kcontrol
);
2875 struct snd_trident_pcm_mixer
*mix
= &trident
->pcm_mixer
[snd_ctl_get_ioffnum(kcontrol
, &ucontrol
->id
)];
2879 val
= 0x7f - (ucontrol
->value
.integer
.value
[0] & 0x7f);
2880 spin_lock_irq(&trident
->reg_lock
);
2881 change
= val
!= mix
->cvol
;
2883 if (mix
->voice
!= NULL
)
2884 snd_trident_write_cvol_reg(trident
, mix
->voice
, val
);
2885 spin_unlock_irq(&trident
->reg_lock
);
2889 static struct snd_kcontrol_new snd_trident_pcm_cvol_control __devinitdata
=
2891 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2892 .name
= "PCM Chorus Playback Volume",
2893 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
| SNDRV_CTL_ELEM_ACCESS_INACTIVE
,
2895 .info
= snd_trident_pcm_cvol_control_info
,
2896 .get
= snd_trident_pcm_cvol_control_get
,
2897 .put
= snd_trident_pcm_cvol_control_put
,
2898 .tlv
= { .p
= db_scale_crvol
},
2901 static void snd_trident_notify_pcm_change1(struct snd_card
*card
,
2902 struct snd_kcontrol
*kctl
,
2903 int num
, int activate
)
2905 struct snd_ctl_elem_id id
;
2910 kctl
->vd
[num
].access
&= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE
;
2912 kctl
->vd
[num
].access
|= SNDRV_CTL_ELEM_ACCESS_INACTIVE
;
2913 snd_ctl_notify(card
, SNDRV_CTL_EVENT_MASK_VALUE
|
2914 SNDRV_CTL_EVENT_MASK_INFO
,
2915 snd_ctl_build_ioff(&id
, kctl
, num
));
2918 static void snd_trident_notify_pcm_change(struct snd_trident
*trident
,
2919 struct snd_trident_pcm_mixer
*tmix
,
2920 int num
, int activate
)
2922 snd_trident_notify_pcm_change1(trident
->card
, trident
->ctl_vol
, num
, activate
);
2923 snd_trident_notify_pcm_change1(trident
->card
, trident
->ctl_pan
, num
, activate
);
2924 snd_trident_notify_pcm_change1(trident
->card
, trident
->ctl_rvol
, num
, activate
);
2925 snd_trident_notify_pcm_change1(trident
->card
, trident
->ctl_cvol
, num
, activate
);
2928 static int snd_trident_pcm_mixer_build(struct snd_trident
*trident
,
2929 struct snd_trident_voice
*voice
,
2930 struct snd_pcm_substream
*substream
)
2932 struct snd_trident_pcm_mixer
*tmix
;
2934 snd_assert(trident
!= NULL
&& voice
!= NULL
&& substream
!= NULL
, return -EINVAL
);
2935 tmix
= &trident
->pcm_mixer
[substream
->number
];
2936 tmix
->voice
= voice
;
2937 tmix
->vol
= T4D_DEFAULT_PCM_VOL
;
2938 tmix
->pan
= T4D_DEFAULT_PCM_PAN
;
2939 tmix
->rvol
= T4D_DEFAULT_PCM_RVOL
;
2940 tmix
->cvol
= T4D_DEFAULT_PCM_CVOL
;
2941 snd_trident_notify_pcm_change(trident
, tmix
, substream
->number
, 1);
2945 static int snd_trident_pcm_mixer_free(struct snd_trident
*trident
, struct snd_trident_voice
*voice
, struct snd_pcm_substream
*substream
)
2947 struct snd_trident_pcm_mixer
*tmix
;
2949 snd_assert(trident
!= NULL
&& substream
!= NULL
, return -EINVAL
);
2950 tmix
= &trident
->pcm_mixer
[substream
->number
];
2952 snd_trident_notify_pcm_change(trident
, tmix
, substream
->number
, 0);
2956 /*---------------------------------------------------------------------------
2959 Description: This routine registers the 4DWave device for mixer support.
2961 Parameters: trident - pointer to target device class for 4DWave.
2965 ---------------------------------------------------------------------------*/
2967 static int __devinit
snd_trident_mixer(struct snd_trident
* trident
, int pcm_spdif_device
)
2969 struct snd_ac97_template _ac97
;
2970 struct snd_card
*card
= trident
->card
;
2971 struct snd_kcontrol
*kctl
;
2972 struct snd_ctl_elem_value
*uctl
;
2973 int idx
, err
, retries
= 2;
2974 static struct snd_ac97_bus_ops ops
= {
2975 .write
= snd_trident_codec_write
,
2976 .read
= snd_trident_codec_read
,
2979 uctl
= kzalloc(sizeof(*uctl
), GFP_KERNEL
);
2983 if ((err
= snd_ac97_bus(trident
->card
, 0, &ops
, NULL
, &trident
->ac97_bus
)) < 0)
2986 memset(&_ac97
, 0, sizeof(_ac97
));
2987 _ac97
.private_data
= trident
;
2988 trident
->ac97_detect
= 1;
2991 if ((err
= snd_ac97_mixer(trident
->ac97_bus
, &_ac97
, &trident
->ac97
)) < 0) {
2992 if (trident
->device
== TRIDENT_DEVICE_ID_SI7018
) {
2993 if ((err
= snd_trident_sis_reset(trident
)) < 0)
3002 /* secondary codec? */
3003 if (trident
->device
== TRIDENT_DEVICE_ID_SI7018
&&
3004 (inl(TRID_REG(trident
, SI_SERIAL_INTF_CTRL
)) & SI_AC97_PRIMARY_READY
) != 0) {
3006 err
= snd_ac97_mixer(trident
->ac97_bus
, &_ac97
, &trident
->ac97_sec
);
3008 snd_printk(KERN_ERR
"SI7018: the secondary codec - invalid access\n");
3009 #if 0 // only for my testing purpose --jk
3011 struct snd_ac97
*mc97
;
3012 err
= snd_ac97_modem(trident
->card
, &_ac97
, &mc97
);
3014 snd_printk(KERN_ERR
"snd_ac97_modem returned error %i\n", err
);
3019 trident
->ac97_detect
= 0;
3021 if (trident
->device
!= TRIDENT_DEVICE_ID_SI7018
) {
3022 if ((err
= snd_ctl_add(card
, kctl
= snd_ctl_new1(&snd_trident_vol_wave_control
, trident
))) < 0)
3024 kctl
->put(kctl
, uctl
);
3025 if ((err
= snd_ctl_add(card
, kctl
= snd_ctl_new1(&snd_trident_vol_music_control
, trident
))) < 0)
3027 kctl
->put(kctl
, uctl
);
3028 outl(trident
->musicvol_wavevol
= 0x00000000, TRID_REG(trident
, T4D_MUSICVOL_WAVEVOL
));
3030 outl(trident
->musicvol_wavevol
= 0xffff0000, TRID_REG(trident
, T4D_MUSICVOL_WAVEVOL
));
3033 for (idx
= 0; idx
< 32; idx
++) {
3034 struct snd_trident_pcm_mixer
*tmix
;
3036 tmix
= &trident
->pcm_mixer
[idx
];
3039 if ((trident
->ctl_vol
= snd_ctl_new1(&snd_trident_pcm_vol_control
, trident
)) == NULL
)
3041 if ((err
= snd_ctl_add(card
, trident
->ctl_vol
)))
3044 if ((trident
->ctl_pan
= snd_ctl_new1(&snd_trident_pcm_pan_control
, trident
)) == NULL
)
3046 if ((err
= snd_ctl_add(card
, trident
->ctl_pan
)))
3049 if ((trident
->ctl_rvol
= snd_ctl_new1(&snd_trident_pcm_rvol_control
, trident
)) == NULL
)
3051 if ((err
= snd_ctl_add(card
, trident
->ctl_rvol
)))
3054 if ((trident
->ctl_cvol
= snd_ctl_new1(&snd_trident_pcm_cvol_control
, trident
)) == NULL
)
3056 if ((err
= snd_ctl_add(card
, trident
->ctl_cvol
)))
3059 if (trident
->device
== TRIDENT_DEVICE_ID_NX
) {
3060 if ((err
= snd_ctl_add(card
, kctl
= snd_ctl_new1(&snd_trident_ac97_rear_control
, trident
))) < 0)
3062 kctl
->put(kctl
, uctl
);
3064 if (trident
->device
== TRIDENT_DEVICE_ID_NX
|| trident
->device
== TRIDENT_DEVICE_ID_SI7018
) {
3066 kctl
= snd_ctl_new1(&snd_trident_spdif_control
, trident
);
3071 if (trident
->ac97
->ext_id
& AC97_EI_SPDIF
)
3073 if (trident
->ac97_sec
&& (trident
->ac97_sec
->ext_id
& AC97_EI_SPDIF
))
3075 idx
= kctl
->id
.index
;
3076 if ((err
= snd_ctl_add(card
, kctl
)) < 0)
3078 kctl
->put(kctl
, uctl
);
3080 kctl
= snd_ctl_new1(&snd_trident_spdif_default
, trident
);
3085 kctl
->id
.index
= idx
;
3086 kctl
->id
.device
= pcm_spdif_device
;
3087 if ((err
= snd_ctl_add(card
, kctl
)) < 0)
3090 kctl
= snd_ctl_new1(&snd_trident_spdif_mask
, trident
);
3095 kctl
->id
.index
= idx
;
3096 kctl
->id
.device
= pcm_spdif_device
;
3097 if ((err
= snd_ctl_add(card
, kctl
)) < 0)
3100 kctl
= snd_ctl_new1(&snd_trident_spdif_stream
, trident
);
3105 kctl
->id
.index
= idx
;
3106 kctl
->id
.device
= pcm_spdif_device
;
3107 if ((err
= snd_ctl_add(card
, kctl
)) < 0)
3109 trident
->spdif_pcm_ctl
= kctl
;
3125 * gameport interface
3128 #if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))
3130 static unsigned char snd_trident_gameport_read(struct gameport
*gameport
)
3132 struct snd_trident
*chip
= gameport_get_port_data(gameport
);
3134 snd_assert(chip
, return 0);
3135 return inb(TRID_REG(chip
, GAMEPORT_LEGACY
));
3138 static void snd_trident_gameport_trigger(struct gameport
*gameport
)
3140 struct snd_trident
*chip
= gameport_get_port_data(gameport
);
3142 snd_assert(chip
, return);
3143 outb(0xff, TRID_REG(chip
, GAMEPORT_LEGACY
));
3146 static int snd_trident_gameport_cooked_read(struct gameport
*gameport
, int *axes
, int *buttons
)
3148 struct snd_trident
*chip
= gameport_get_port_data(gameport
);
3151 snd_assert(chip
, return 0);
3153 *buttons
= (~inb(TRID_REG(chip
, GAMEPORT_LEGACY
)) >> 4) & 0xf;
3155 for (i
= 0; i
< 4; i
++) {
3156 axes
[i
] = inw(TRID_REG(chip
, GAMEPORT_AXES
+ i
* 2));
3157 if (axes
[i
] == 0xffff) axes
[i
] = -1;
3163 static int snd_trident_gameport_open(struct gameport
*gameport
, int mode
)
3165 struct snd_trident
*chip
= gameport_get_port_data(gameport
);
3167 snd_assert(chip
, return 0);
3170 case GAMEPORT_MODE_COOKED
:
3171 outb(GAMEPORT_MODE_ADC
, TRID_REG(chip
, GAMEPORT_GCR
));
3174 case GAMEPORT_MODE_RAW
:
3175 outb(0, TRID_REG(chip
, GAMEPORT_GCR
));
3182 int __devinit
snd_trident_create_gameport(struct snd_trident
*chip
)
3184 struct gameport
*gp
;
3186 chip
->gameport
= gp
= gameport_allocate_port();
3188 printk(KERN_ERR
"trident: cannot allocate memory for gameport\n");
3192 gameport_set_name(gp
, "Trident 4DWave");
3193 gameport_set_phys(gp
, "pci%s/gameport0", pci_name(chip
->pci
));
3194 gameport_set_dev_parent(gp
, &chip
->pci
->dev
);
3196 gameport_set_port_data(gp
, chip
);
3198 gp
->read
= snd_trident_gameport_read
;
3199 gp
->trigger
= snd_trident_gameport_trigger
;
3200 gp
->cooked_read
= snd_trident_gameport_cooked_read
;
3201 gp
->open
= snd_trident_gameport_open
;
3203 gameport_register_port(gp
);
3208 static inline void snd_trident_free_gameport(struct snd_trident
*chip
)
3210 if (chip
->gameport
) {
3211 gameport_unregister_port(chip
->gameport
);
3212 chip
->gameport
= NULL
;
3216 int __devinit
snd_trident_create_gameport(struct snd_trident
*chip
) { return -ENOSYS
; }
3217 static inline void snd_trident_free_gameport(struct snd_trident
*chip
) { }
3218 #endif /* CONFIG_GAMEPORT */
3223 static inline void do_delay(struct snd_trident
*chip
)
3225 schedule_timeout_uninterruptible(1);
3232 static int snd_trident_sis_reset(struct snd_trident
*trident
)
3234 unsigned long end_time
;
3238 r
= trident
->in_suspend
? 0 : 2; /* count of retries */
3240 pci_write_config_byte(trident
->pci
, 0x46, 0x04); /* SOFTWARE RESET */
3242 pci_write_config_byte(trident
->pci
, 0x46, 0x00);
3244 /* disable AC97 GPIO interrupt */
3245 outb(0x00, TRID_REG(trident
, SI_AC97_GPIO
));
3246 /* initialize serial interface, force cold reset */
3247 i
= PCMOUT
|SURROUT
|CENTEROUT
|LFEOUT
|SECONDARY_ID
|COLD_RESET
;
3248 outl(i
, TRID_REG(trident
, SI_SERIAL_INTF_CTRL
));
3250 /* remove cold reset */
3252 outl(i
, TRID_REG(trident
, SI_SERIAL_INTF_CTRL
));
3254 /* wait, until the codec is ready */
3255 end_time
= (jiffies
+ (HZ
* 3) / 4) + 1;
3257 if ((inl(TRID_REG(trident
, SI_SERIAL_INTF_CTRL
)) & SI_AC97_PRIMARY_READY
) != 0)
3260 } while (time_after_eq(end_time
, jiffies
));
3261 snd_printk(KERN_ERR
"AC'97 codec ready error [0x%x]\n", inl(TRID_REG(trident
, SI_SERIAL_INTF_CTRL
)));
3263 end_time
= jiffies
+ HZ
;
3266 } while (time_after_eq(end_time
, jiffies
));
3267 goto __si7018_retry
;
3270 /* wait for the second codec */
3272 if ((inl(TRID_REG(trident
, SI_SERIAL_INTF_CTRL
)) & SI_AC97_SECONDARY_READY
) != 0)
3275 } while (time_after_eq(end_time
, jiffies
));
3276 /* enable 64 channel mode */
3277 outl(BANK_B_EN
, TRID_REG(trident
, T4D_LFO_GC_CIR
));
3285 static void snd_trident_proc_read(struct snd_info_entry
*entry
,
3286 struct snd_info_buffer
*buffer
)
3288 struct snd_trident
*trident
= entry
->private_data
;
3291 switch (trident
->device
) {
3292 case TRIDENT_DEVICE_ID_SI7018
:
3293 s
= "SiS 7018 Audio";
3295 case TRIDENT_DEVICE_ID_DX
:
3296 s
= "Trident 4DWave PCI DX";
3298 case TRIDENT_DEVICE_ID_NX
:
3299 s
= "Trident 4DWave PCI NX";
3304 snd_iprintf(buffer
, "%s\n\n", s
);
3305 snd_iprintf(buffer
, "Spurious IRQs : %d\n", trident
->spurious_irq_count
);
3306 snd_iprintf(buffer
, "Spurious IRQ dlta: %d\n", trident
->spurious_irq_max_delta
);
3307 if (trident
->device
== TRIDENT_DEVICE_ID_NX
|| trident
->device
== TRIDENT_DEVICE_ID_SI7018
)
3308 snd_iprintf(buffer
, "IEC958 Mixer Out : %s\n", trident
->spdif_ctrl
== 0x28 ? "on" : "off");
3309 if (trident
->device
== TRIDENT_DEVICE_ID_NX
) {
3310 snd_iprintf(buffer
, "Rear Speakers : %s\n", trident
->ac97_ctrl
& 0x00000010 ? "on" : "off");
3311 if (trident
->tlb
.entries
) {
3312 snd_iprintf(buffer
,"\nVirtual Memory\n");
3313 snd_iprintf(buffer
, "Memory Maximum : %d\n", trident
->tlb
.memhdr
->size
);
3314 snd_iprintf(buffer
, "Memory Used : %d\n", trident
->tlb
.memhdr
->used
);
3315 snd_iprintf(buffer
, "Memory Free : %d\n", snd_util_mem_avail(trident
->tlb
.memhdr
));
3320 static void __devinit
snd_trident_proc_init(struct snd_trident
* trident
)
3322 struct snd_info_entry
*entry
;
3323 const char *s
= "trident";
3325 if (trident
->device
== TRIDENT_DEVICE_ID_SI7018
)
3327 if (! snd_card_proc_new(trident
->card
, s
, &entry
))
3328 snd_info_set_text_ops(entry
, trident
, snd_trident_proc_read
);
3331 static int snd_trident_dev_free(struct snd_device
*device
)
3333 struct snd_trident
*trident
= device
->device_data
;
3334 return snd_trident_free(trident
);
3337 /*---------------------------------------------------------------------------
3338 snd_trident_tlb_alloc
3340 Description: Allocate and set up the TLB page table on 4D NX.
3341 Each entry has 4 bytes (physical PCI address).
3343 Parameters: trident - pointer to target device class for 4DWave.
3345 Returns: 0 or negative error code
3347 ---------------------------------------------------------------------------*/
3349 static int __devinit
snd_trident_tlb_alloc(struct snd_trident
*trident
)
3353 /* TLB array must be aligned to 16kB !!! so we allocate
3354 32kB region and correct offset when necessary */
3356 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV
, snd_dma_pci_data(trident
->pci
),
3357 2 * SNDRV_TRIDENT_MAX_PAGES
* 4, &trident
->tlb
.buffer
) < 0) {
3358 snd_printk(KERN_ERR
"trident: unable to allocate TLB buffer\n");
3361 trident
->tlb
.entries
= (unsigned int*)ALIGN((unsigned long)trident
->tlb
.buffer
.area
, SNDRV_TRIDENT_MAX_PAGES
* 4);
3362 trident
->tlb
.entries_dmaaddr
= ALIGN(trident
->tlb
.buffer
.addr
, SNDRV_TRIDENT_MAX_PAGES
* 4);
3363 /* allocate shadow TLB page table (virtual addresses) */
3364 trident
->tlb
.shadow_entries
= vmalloc(SNDRV_TRIDENT_MAX_PAGES
*sizeof(unsigned long));
3365 if (trident
->tlb
.shadow_entries
== NULL
) {
3366 snd_printk(KERN_ERR
"trident: unable to allocate shadow TLB entries\n");
3369 /* allocate and setup silent page and initialise TLB entries */
3370 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV
, snd_dma_pci_data(trident
->pci
),
3371 SNDRV_TRIDENT_PAGE_SIZE
, &trident
->tlb
.silent_page
) < 0) {
3372 snd_printk(KERN_ERR
"trident: unable to allocate silent page\n");
3375 memset(trident
->tlb
.silent_page
.area
, 0, SNDRV_TRIDENT_PAGE_SIZE
);
3376 for (i
= 0; i
< SNDRV_TRIDENT_MAX_PAGES
; i
++) {
3377 trident
->tlb
.entries
[i
] = cpu_to_le32(trident
->tlb
.silent_page
.addr
& ~(SNDRV_TRIDENT_PAGE_SIZE
-1));
3378 trident
->tlb
.shadow_entries
[i
] = (unsigned long)trident
->tlb
.silent_page
.area
;
3381 /* use emu memory block manager code to manage tlb page allocation */
3382 trident
->tlb
.memhdr
= snd_util_memhdr_new(SNDRV_TRIDENT_PAGE_SIZE
* SNDRV_TRIDENT_MAX_PAGES
);
3383 if (trident
->tlb
.memhdr
== NULL
)
3386 trident
->tlb
.memhdr
->block_extra_size
= sizeof(struct snd_trident_memblk_arg
);
3391 * initialize 4D DX chip
3394 static void snd_trident_stop_all_voices(struct snd_trident
*trident
)
3396 outl(0xffffffff, TRID_REG(trident
, T4D_STOP_A
));
3397 outl(0xffffffff, TRID_REG(trident
, T4D_STOP_B
));
3398 outl(0, TRID_REG(trident
, T4D_AINTEN_A
));
3399 outl(0, TRID_REG(trident
, T4D_AINTEN_B
));
3402 static int snd_trident_4d_dx_init(struct snd_trident
*trident
)
3404 struct pci_dev
*pci
= trident
->pci
;
3405 unsigned long end_time
;
3407 /* reset the legacy configuration and whole audio/wavetable block */
3408 pci_write_config_dword(pci
, 0x40, 0); /* DDMA */
3409 pci_write_config_byte(pci
, 0x44, 0); /* ports */
3410 pci_write_config_byte(pci
, 0x45, 0); /* Legacy DMA */
3411 pci_write_config_byte(pci
, 0x46, 4); /* reset */
3413 pci_write_config_byte(pci
, 0x46, 0); /* release reset */
3416 /* warm reset of the AC'97 codec */
3417 outl(0x00000001, TRID_REG(trident
, DX_ACR2_AC97_COM_STAT
));
3419 outl(0x00000000, TRID_REG(trident
, DX_ACR2_AC97_COM_STAT
));
3420 /* DAC on, disable SB IRQ and try to force ADC valid signal */
3421 trident
->ac97_ctrl
= 0x0000004a;
3422 outl(trident
->ac97_ctrl
, TRID_REG(trident
, DX_ACR2_AC97_COM_STAT
));
3423 /* wait, until the codec is ready */
3424 end_time
= (jiffies
+ (HZ
* 3) / 4) + 1;
3426 if ((inl(TRID_REG(trident
, DX_ACR2_AC97_COM_STAT
)) & 0x0010) != 0)
3429 } while (time_after_eq(end_time
, jiffies
));
3430 snd_printk(KERN_ERR
"AC'97 codec ready error\n");
3434 snd_trident_stop_all_voices(trident
);
3440 * initialize 4D NX chip
3442 static int snd_trident_4d_nx_init(struct snd_trident
*trident
)
3444 struct pci_dev
*pci
= trident
->pci
;
3445 unsigned long end_time
;
3447 /* reset the legacy configuration and whole audio/wavetable block */
3448 pci_write_config_dword(pci
, 0x40, 0); /* DDMA */
3449 pci_write_config_byte(pci
, 0x44, 0); /* ports */
3450 pci_write_config_byte(pci
, 0x45, 0); /* Legacy DMA */
3452 pci_write_config_byte(pci
, 0x46, 1); /* reset */
3454 pci_write_config_byte(pci
, 0x46, 0); /* release reset */
3457 /* warm reset of the AC'97 codec */
3458 outl(0x00000001, TRID_REG(trident
, NX_ACR0_AC97_COM_STAT
));
3460 outl(0x00000000, TRID_REG(trident
, NX_ACR0_AC97_COM_STAT
));
3461 /* wait, until the codec is ready */
3462 end_time
= (jiffies
+ (HZ
* 3) / 4) + 1;
3464 if ((inl(TRID_REG(trident
, NX_ACR0_AC97_COM_STAT
)) & 0x0008) != 0)
3467 } while (time_after_eq(end_time
, jiffies
));
3468 snd_printk(KERN_ERR
"AC'97 codec ready error [0x%x]\n", inl(TRID_REG(trident
, NX_ACR0_AC97_COM_STAT
)));
3473 trident
->ac97_ctrl
= 0x00000002;
3474 outl(trident
->ac97_ctrl
, TRID_REG(trident
, NX_ACR0_AC97_COM_STAT
));
3475 /* disable SB IRQ */
3476 outl(NX_SB_IRQ_DISABLE
, TRID_REG(trident
, T4D_MISCINT
));
3478 snd_trident_stop_all_voices(trident
);
3480 if (trident
->tlb
.entries
!= NULL
) {
3482 /* enable virtual addressing via TLB */
3483 i
= trident
->tlb
.entries_dmaaddr
;
3485 outl(i
, TRID_REG(trident
, NX_TLBC
));
3487 outl(0, TRID_REG(trident
, NX_TLBC
));
3489 /* initialize S/PDIF */
3490 outl(trident
->spdif_bits
, TRID_REG(trident
, NX_SPCSTATUS
));
3491 outb(trident
->spdif_ctrl
, TRID_REG(trident
, NX_SPCTRL_SPCSO
+ 3));
3497 * initialize sis7018 chip
3499 static int snd_trident_sis_init(struct snd_trident
*trident
)
3503 if ((err
= snd_trident_sis_reset(trident
)) < 0)
3506 snd_trident_stop_all_voices(trident
);
3508 /* initialize S/PDIF */
3509 outl(trident
->spdif_bits
, TRID_REG(trident
, SI_SPDIF_CS
));
3514 /*---------------------------------------------------------------------------
3517 Description: This routine will create the device specific class for
3518 the 4DWave card. It will also perform basic initialization.
3520 Parameters: card - which card to create
3521 pci - interface to PCI bus resource info
3522 dma1ptr - playback dma buffer
3523 dma2ptr - capture dma buffer
3524 irqptr - interrupt resource info
3526 Returns: 4DWave device class private data
3528 ---------------------------------------------------------------------------*/
3530 int __devinit
snd_trident_create(struct snd_card
*card
,
3531 struct pci_dev
*pci
,
3533 int pcm_spdif_device
,
3534 int max_wavetable_size
,
3535 struct snd_trident
** rtrident
)
3537 struct snd_trident
*trident
;
3539 struct snd_trident_voice
*voice
;
3540 struct snd_trident_pcm_mixer
*tmix
;
3541 static struct snd_device_ops ops
= {
3542 .dev_free
= snd_trident_dev_free
,
3547 /* enable PCI device */
3548 if ((err
= pci_enable_device(pci
)) < 0)
3550 /* check, if we can restrict PCI DMA transfers to 30 bits */
3551 if (pci_set_dma_mask(pci
, DMA_30BIT_MASK
) < 0 ||
3552 pci_set_consistent_dma_mask(pci
, DMA_30BIT_MASK
) < 0) {
3553 snd_printk(KERN_ERR
"architecture does not support 30bit PCI busmaster DMA\n");
3554 pci_disable_device(pci
);
3558 trident
= kzalloc(sizeof(*trident
), GFP_KERNEL
);
3559 if (trident
== NULL
) {
3560 pci_disable_device(pci
);
3563 trident
->device
= (pci
->vendor
<< 16) | pci
->device
;
3564 trident
->card
= card
;
3566 spin_lock_init(&trident
->reg_lock
);
3567 spin_lock_init(&trident
->event_lock
);
3568 spin_lock_init(&trident
->voice_alloc
);
3569 if (pcm_streams
< 1)
3571 if (pcm_streams
> 32)
3573 trident
->ChanPCM
= pcm_streams
;
3574 if (max_wavetable_size
< 0 )
3575 max_wavetable_size
= 0;
3576 trident
->synth
.max_size
= max_wavetable_size
* 1024;
3579 trident
->midi_port
= TRID_REG(trident
, T4D_MPU401_BASE
);
3580 pci_set_master(pci
);
3582 if ((err
= pci_request_regions(pci
, "Trident Audio")) < 0) {
3584 pci_disable_device(pci
);
3587 trident
->port
= pci_resource_start(pci
, 0);
3589 if (request_irq(pci
->irq
, snd_trident_interrupt
, IRQF_SHARED
,
3590 "Trident Audio", trident
)) {
3591 snd_printk(KERN_ERR
"unable to grab IRQ %d\n", pci
->irq
);
3592 snd_trident_free(trident
);
3595 trident
->irq
= pci
->irq
;
3597 /* allocate 16k-aligned TLB for NX cards */
3598 trident
->tlb
.entries
= NULL
;
3599 trident
->tlb
.buffer
.area
= NULL
;
3600 if (trident
->device
== TRIDENT_DEVICE_ID_NX
) {
3601 if ((err
= snd_trident_tlb_alloc(trident
)) < 0) {
3602 snd_trident_free(trident
);
3607 trident
->spdif_bits
= trident
->spdif_pcm_bits
= SNDRV_PCM_DEFAULT_CON_SPDIF
;
3609 /* initialize chip */
3610 switch (trident
->device
) {
3611 case TRIDENT_DEVICE_ID_DX
:
3612 err
= snd_trident_4d_dx_init(trident
);
3614 case TRIDENT_DEVICE_ID_NX
:
3615 err
= snd_trident_4d_nx_init(trident
);
3617 case TRIDENT_DEVICE_ID_SI7018
:
3618 err
= snd_trident_sis_init(trident
);
3625 snd_trident_free(trident
);
3629 if ((err
= snd_device_new(card
, SNDRV_DEV_LOWLEVEL
, trident
, &ops
)) < 0) {
3630 snd_trident_free(trident
);
3634 if ((err
= snd_trident_mixer(trident
, pcm_spdif_device
)) < 0)
3637 /* initialise synth voices */
3638 for (i
= 0; i
< 64; i
++) {
3639 voice
= &trident
->synth
.voices
[i
];
3641 voice
->trident
= trident
;
3643 /* initialize pcm mixer entries */
3644 for (i
= 0; i
< 32; i
++) {
3645 tmix
= &trident
->pcm_mixer
[i
];
3646 tmix
->vol
= T4D_DEFAULT_PCM_VOL
;
3647 tmix
->pan
= T4D_DEFAULT_PCM_PAN
;
3648 tmix
->rvol
= T4D_DEFAULT_PCM_RVOL
;
3649 tmix
->cvol
= T4D_DEFAULT_PCM_CVOL
;
3652 snd_trident_enable_eso(trident
);
3654 snd_trident_proc_init(trident
);
3655 snd_card_set_dev(card
, &pci
->dev
);
3656 *rtrident
= trident
;
3660 /*---------------------------------------------------------------------------
3663 Description: This routine will free the device specific class for
3666 Parameters: trident - device specific private data for 4DWave card
3670 ---------------------------------------------------------------------------*/
3672 static int snd_trident_free(struct snd_trident
*trident
)
3674 snd_trident_free_gameport(trident
);
3675 snd_trident_disable_eso(trident
);
3676 // Disable S/PDIF out
3677 if (trident
->device
== TRIDENT_DEVICE_ID_NX
)
3678 outb(0x00, TRID_REG(trident
, NX_SPCTRL_SPCSO
+ 3));
3679 else if (trident
->device
== TRIDENT_DEVICE_ID_SI7018
) {
3680 outl(0, TRID_REG(trident
, SI_SERIAL_INTF_CTRL
));
3682 if (trident
->tlb
.buffer
.area
) {
3683 outl(0, TRID_REG(trident
, NX_TLBC
));
3684 if (trident
->tlb
.memhdr
)
3685 snd_util_memhdr_free(trident
->tlb
.memhdr
);
3686 if (trident
->tlb
.silent_page
.area
)
3687 snd_dma_free_pages(&trident
->tlb
.silent_page
);
3688 vfree(trident
->tlb
.shadow_entries
);
3689 snd_dma_free_pages(&trident
->tlb
.buffer
);
3691 if (trident
->irq
>= 0)
3692 free_irq(trident
->irq
, trident
);
3693 pci_release_regions(trident
->pci
);
3694 pci_disable_device(trident
->pci
);
3699 /*---------------------------------------------------------------------------
3700 snd_trident_interrupt
3702 Description: ISR for Trident 4DWave device
3704 Parameters: trident - device specific private data for 4DWave card
3706 Problems: It seems that Trident chips generates interrupts more than
3707 one time in special cases. The spurious interrupts are
3708 detected via sample timer (T4D_STIMER) and computing
3709 corresponding delta value. The limits are detected with
3710 the method try & fail so it is possible that it won't
3711 work on all computers. [jaroslav]
3715 ---------------------------------------------------------------------------*/
3717 static irqreturn_t
snd_trident_interrupt(int irq
, void *dev_id
)
3719 struct snd_trident
*trident
= dev_id
;
3720 unsigned int audio_int
, chn_int
, stimer
, channel
, mask
, tmp
;
3722 struct snd_trident_voice
*voice
;
3724 audio_int
= inl(TRID_REG(trident
, T4D_MISCINT
));
3725 if ((audio_int
& (ADDRESS_IRQ
|MPU401_IRQ
)) == 0)
3727 if (audio_int
& ADDRESS_IRQ
) {
3728 // get interrupt status for all channels
3729 spin_lock(&trident
->reg_lock
);
3730 stimer
= inl(TRID_REG(trident
, T4D_STIMER
)) & 0x00ffffff;
3731 chn_int
= inl(TRID_REG(trident
, T4D_AINT_A
));
3734 outl(chn_int
, TRID_REG(trident
, T4D_AINT_A
)); /* ack */
3736 chn_int
= inl(TRID_REG(trident
, T4D_AINT_B
));
3739 for (channel
= 63; channel
>= 32; channel
--) {
3740 mask
= 1 << (channel
&0x1f);
3741 if ((chn_int
& mask
) == 0)
3743 voice
= &trident
->synth
.voices
[channel
];
3744 if (!voice
->pcm
|| voice
->substream
== NULL
) {
3745 outl(mask
, TRID_REG(trident
, T4D_STOP_B
));
3748 delta
= (int)stimer
- (int)voice
->stimer
;
3751 if ((unsigned int)delta
< voice
->spurious_threshold
) {
3752 /* do some statistics here */
3753 trident
->spurious_irq_count
++;
3754 if (trident
->spurious_irq_max_delta
< (unsigned int)delta
)
3755 trident
->spurious_irq_max_delta
= delta
;
3758 voice
->stimer
= stimer
;
3760 if (!voice
->isync3
) {
3761 tmp
= inw(TRID_REG(trident
, T4D_SBBL_SBCL
));
3762 if (trident
->bDMAStart
& 0x40)
3765 tmp
= voice
->isync_max
- tmp
;
3767 tmp
= inl(TRID_REG(trident
, NX_SPCTRL_SPCSO
)) & 0x00ffffff;
3769 if (tmp
< voice
->isync_mark
) {
3771 tmp
= voice
->isync_ESO
- 7;
3773 tmp
= voice
->isync_ESO
+ 2;
3774 /* update ESO for IRQ voice to preserve sync */
3775 snd_trident_stop_voice(trident
, voice
->number
);
3776 snd_trident_write_eso_reg(trident
, voice
, tmp
);
3777 snd_trident_start_voice(trident
, voice
->number
);
3779 } else if (voice
->isync2
) {
3781 /* write original ESO and update CSO for IRQ voice to preserve sync */
3782 snd_trident_stop_voice(trident
, voice
->number
);
3783 snd_trident_write_cso_reg(trident
, voice
, voice
->isync_mark
);
3784 snd_trident_write_eso_reg(trident
, voice
, voice
->ESO
);
3785 snd_trident_start_voice(trident
, voice
->number
);
3789 /* update CSO for extra voice to preserve sync */
3790 snd_trident_stop_voice(trident
, voice
->extra
->number
);
3791 snd_trident_write_cso_reg(trident
, voice
->extra
, 0);
3792 snd_trident_start_voice(trident
, voice
->extra
->number
);
3795 spin_unlock(&trident
->reg_lock
);
3796 snd_pcm_period_elapsed(voice
->substream
);
3797 spin_lock(&trident
->reg_lock
);
3799 outl(chn_int
, TRID_REG(trident
, T4D_AINT_B
)); /* ack */
3801 spin_unlock(&trident
->reg_lock
);
3803 if (audio_int
& MPU401_IRQ
) {
3804 if (trident
->rmidi
) {
3805 snd_mpu401_uart_interrupt(irq
, trident
->rmidi
->private_data
);
3807 inb(TRID_REG(trident
, T4D_MPUR0
));
3810 // outl((ST_TARGET_REACHED | MIXER_OVERFLOW | MIXER_UNDERFLOW), TRID_REG(trident, T4D_MISCINT));
3814 struct snd_trident_voice
*snd_trident_alloc_voice(struct snd_trident
* trident
, int type
, int client
, int port
)
3816 struct snd_trident_voice
*pvoice
;
3817 unsigned long flags
;
3820 spin_lock_irqsave(&trident
->voice_alloc
, flags
);
3821 if (type
== SNDRV_TRIDENT_VOICE_TYPE_PCM
) {
3822 idx
= snd_trident_allocate_pcm_channel(trident
);
3824 spin_unlock_irqrestore(&trident
->voice_alloc
, flags
);
3827 pvoice
= &trident
->synth
.voices
[idx
];
3830 pvoice
->capture
= 0;
3832 pvoice
->memblk
= NULL
;
3833 pvoice
->substream
= NULL
;
3834 spin_unlock_irqrestore(&trident
->voice_alloc
, flags
);
3837 if (type
== SNDRV_TRIDENT_VOICE_TYPE_SYNTH
) {
3838 idx
= snd_trident_allocate_synth_channel(trident
);
3840 spin_unlock_irqrestore(&trident
->voice_alloc
, flags
);
3843 pvoice
= &trident
->synth
.voices
[idx
];
3846 pvoice
->client
= client
;
3847 pvoice
->port
= port
;
3848 pvoice
->memblk
= NULL
;
3849 spin_unlock_irqrestore(&trident
->voice_alloc
, flags
);
3852 if (type
== SNDRV_TRIDENT_VOICE_TYPE_MIDI
) {
3854 spin_unlock_irqrestore(&trident
->voice_alloc
, flags
);
3858 EXPORT_SYMBOL(snd_trident_alloc_voice
);
3860 void snd_trident_free_voice(struct snd_trident
* trident
, struct snd_trident_voice
*voice
)
3862 unsigned long flags
;
3863 void (*private_free
)(struct snd_trident_voice
*);
3866 if (voice
== NULL
|| !voice
->use
)
3868 snd_trident_clear_voices(trident
, voice
->number
, voice
->number
);
3869 spin_lock_irqsave(&trident
->voice_alloc
, flags
);
3870 private_free
= voice
->private_free
;
3871 private_data
= voice
->private_data
;
3872 voice
->private_free
= NULL
;
3873 voice
->private_data
= NULL
;
3875 snd_trident_free_pcm_channel(trident
, voice
->number
);
3877 snd_trident_free_synth_channel(trident
, voice
->number
);
3878 voice
->use
= voice
->pcm
= voice
->synth
= voice
->midi
= 0;
3879 voice
->capture
= voice
->spdif
= 0;
3880 voice
->sample_ops
= NULL
;
3881 voice
->substream
= NULL
;
3882 voice
->extra
= NULL
;
3883 spin_unlock_irqrestore(&trident
->voice_alloc
, flags
);
3885 private_free(voice
);
3888 EXPORT_SYMBOL(snd_trident_free_voice
);
3890 static void snd_trident_clear_voices(struct snd_trident
* trident
, unsigned short v_min
, unsigned short v_max
)
3892 unsigned int i
, val
, mask
[2] = { 0, 0 };
3894 snd_assert(v_min
<= 63, return);
3895 snd_assert(v_max
<= 63, return);
3896 for (i
= v_min
; i
<= v_max
; i
++)
3897 mask
[i
>> 5] |= 1 << (i
& 0x1f);
3899 outl(mask
[0], TRID_REG(trident
, T4D_STOP_A
));
3900 val
= inl(TRID_REG(trident
, T4D_AINTEN_A
));
3901 outl(val
& ~mask
[0], TRID_REG(trident
, T4D_AINTEN_A
));
3904 outl(mask
[1], TRID_REG(trident
, T4D_STOP_B
));
3905 val
= inl(TRID_REG(trident
, T4D_AINTEN_B
));
3906 outl(val
& ~mask
[1], TRID_REG(trident
, T4D_AINTEN_B
));
3911 int snd_trident_suspend(struct pci_dev
*pci
, pm_message_t state
)
3913 struct snd_card
*card
= pci_get_drvdata(pci
);
3914 struct snd_trident
*trident
= card
->private_data
;
3916 trident
->in_suspend
= 1;
3917 snd_power_change_state(card
, SNDRV_CTL_POWER_D3hot
);
3918 snd_pcm_suspend_all(trident
->pcm
);
3919 snd_pcm_suspend_all(trident
->foldback
);
3920 snd_pcm_suspend_all(trident
->spdif
);
3922 snd_ac97_suspend(trident
->ac97
);
3923 snd_ac97_suspend(trident
->ac97_sec
);
3925 pci_disable_device(pci
);
3926 pci_save_state(pci
);
3927 pci_set_power_state(pci
, pci_choose_state(pci
, state
));
3931 int snd_trident_resume(struct pci_dev
*pci
)
3933 struct snd_card
*card
= pci_get_drvdata(pci
);
3934 struct snd_trident
*trident
= card
->private_data
;
3936 pci_set_power_state(pci
, PCI_D0
);
3937 pci_restore_state(pci
);
3938 if (pci_enable_device(pci
) < 0) {
3939 printk(KERN_ERR
"trident: pci_enable_device failed, "
3940 "disabling device\n");
3941 snd_card_disconnect(card
);
3944 pci_set_master(pci
);
3946 switch (trident
->device
) {
3947 case TRIDENT_DEVICE_ID_DX
:
3948 snd_trident_4d_dx_init(trident
);
3950 case TRIDENT_DEVICE_ID_NX
:
3951 snd_trident_4d_nx_init(trident
);
3953 case TRIDENT_DEVICE_ID_SI7018
:
3954 snd_trident_sis_init(trident
);
3958 snd_ac97_resume(trident
->ac97
);
3959 snd_ac97_resume(trident
->ac97_sec
);
3961 /* restore some registers */
3962 outl(trident
->musicvol_wavevol
, TRID_REG(trident
, T4D_MUSICVOL_WAVEVOL
));
3964 snd_trident_enable_eso(trident
);
3966 snd_power_change_state(card
, SNDRV_CTL_POWER_D0
);
3967 trident
->in_suspend
= 0;
3970 #endif /* CONFIG_PM */