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>
38 #include <linux/export.h>
40 #include <sound/core.h>
41 #include <sound/info.h>
42 #include <sound/control.h>
43 #include <sound/tlv.h>
45 #include <sound/asoundef.h>
49 static int snd_trident_pcm_mixer_build(struct snd_trident
*trident
,
50 struct snd_trident_voice
* voice
,
51 struct snd_pcm_substream
*substream
);
52 static int snd_trident_pcm_mixer_free(struct snd_trident
*trident
,
53 struct snd_trident_voice
* voice
,
54 struct snd_pcm_substream
*substream
);
55 static irqreturn_t
snd_trident_interrupt(int irq
, void *dev_id
);
56 static int snd_trident_sis_reset(struct snd_trident
*trident
);
58 static void snd_trident_clear_voices(struct snd_trident
* trident
,
59 unsigned short v_min
, unsigned short v_max
);
60 static int snd_trident_free(struct snd_trident
*trident
);
68 static void snd_trident_print_voice_regs(struct snd_trident
*trident
, int voice
)
70 unsigned int val
, tmp
;
72 dev_dbg(trident
->card
->dev
, "Trident voice %i:\n", voice
);
73 outb(voice
, TRID_REG(trident
, T4D_LFO_GC_CIR
));
74 val
= inl(TRID_REG(trident
, CH_LBA
));
75 dev_dbg(trident
->card
->dev
, "LBA: 0x%x\n", val
);
76 val
= inl(TRID_REG(trident
, CH_GVSEL_PAN_VOL_CTRL_EC
));
77 dev_dbg(trident
->card
->dev
, "GVSel: %i\n", val
>> 31);
78 dev_dbg(trident
->card
->dev
, "Pan: 0x%x\n", (val
>> 24) & 0x7f);
79 dev_dbg(trident
->card
->dev
, "Vol: 0x%x\n", (val
>> 16) & 0xff);
80 dev_dbg(trident
->card
->dev
, "CTRL: 0x%x\n", (val
>> 12) & 0x0f);
81 dev_dbg(trident
->card
->dev
, "EC: 0x%x\n", val
& 0x0fff);
82 if (trident
->device
!= TRIDENT_DEVICE_ID_NX
) {
83 val
= inl(TRID_REG(trident
, CH_DX_CSO_ALPHA_FMS
));
84 dev_dbg(trident
->card
->dev
, "CSO: 0x%x\n", val
>> 16);
85 dev_dbg(trident
->card
->dev
, "Alpha: 0x%x\n", (val
>> 4) & 0x0fff);
86 dev_dbg(trident
->card
->dev
, "FMS: 0x%x\n", val
& 0x0f);
87 val
= inl(TRID_REG(trident
, CH_DX_ESO_DELTA
));
88 dev_dbg(trident
->card
->dev
, "ESO: 0x%x\n", val
>> 16);
89 dev_dbg(trident
->card
->dev
, "Delta: 0x%x\n", val
& 0xffff);
90 val
= inl(TRID_REG(trident
, CH_DX_FMC_RVOL_CVOL
));
91 } else { // TRIDENT_DEVICE_ID_NX
92 val
= inl(TRID_REG(trident
, CH_NX_DELTA_CSO
));
93 tmp
= (val
>> 24) & 0xff;
94 dev_dbg(trident
->card
->dev
, "CSO: 0x%x\n", val
& 0x00ffffff);
95 val
= inl(TRID_REG(trident
, CH_NX_DELTA_ESO
));
96 tmp
|= (val
>> 16) & 0xff00;
97 dev_dbg(trident
->card
->dev
, "Delta: 0x%x\n", tmp
);
98 dev_dbg(trident
->card
->dev
, "ESO: 0x%x\n", val
& 0x00ffffff);
99 val
= inl(TRID_REG(trident
, CH_NX_ALPHA_FMS_FMC_RVOL_CVOL
));
100 dev_dbg(trident
->card
->dev
, "Alpha: 0x%x\n", val
>> 20);
101 dev_dbg(trident
->card
->dev
, "FMS: 0x%x\n", (val
>> 16) & 0x0f);
103 dev_dbg(trident
->card
->dev
, "FMC: 0x%x\n", (val
>> 14) & 3);
104 dev_dbg(trident
->card
->dev
, "RVol: 0x%x\n", (val
>> 7) & 0x7f);
105 dev_dbg(trident
->card
->dev
, "CVol: 0x%x\n", val
& 0x7f);
109 /*---------------------------------------------------------------------------
110 unsigned short snd_trident_codec_read(struct snd_ac97 *ac97, unsigned short reg)
112 Description: This routine will do all of the reading from the external
115 Parameters: ac97 - ac97 codec structure
116 reg - CODEC register index, from AC97 Hal.
118 returns: 16 bit value read from the AC97.
120 ---------------------------------------------------------------------------*/
121 static unsigned short snd_trident_codec_read(struct snd_ac97
*ac97
, unsigned short reg
)
123 unsigned int data
= 0, treg
;
124 unsigned short count
= 0xffff;
126 struct snd_trident
*trident
= ac97
->private_data
;
128 spin_lock_irqsave(&trident
->reg_lock
, flags
);
129 if (trident
->device
== TRIDENT_DEVICE_ID_DX
) {
130 data
= (DX_AC97_BUSY_READ
| (reg
& 0x000000ff));
131 outl(data
, TRID_REG(trident
, DX_ACR1_AC97_R
));
133 data
= inl(TRID_REG(trident
, DX_ACR1_AC97_R
));
134 if ((data
& DX_AC97_BUSY_READ
) == 0)
137 } else if (trident
->device
== TRIDENT_DEVICE_ID_NX
) {
138 data
= (NX_AC97_BUSY_READ
| (reg
& 0x000000ff));
139 treg
= ac97
->num
== 0 ? NX_ACR2_AC97_R_PRIMARY
: NX_ACR3_AC97_R_SECONDARY
;
140 outl(data
, TRID_REG(trident
, treg
));
142 data
= inl(TRID_REG(trident
, treg
));
143 if ((data
& 0x00000C00) == 0)
146 } else if (trident
->device
== TRIDENT_DEVICE_ID_SI7018
) {
147 data
= SI_AC97_BUSY_READ
| SI_AC97_AUDIO_BUSY
| (reg
& 0x000000ff);
149 data
|= SI_AC97_SECONDARY
;
150 outl(data
, TRID_REG(trident
, SI_AC97_READ
));
152 data
= inl(TRID_REG(trident
, SI_AC97_READ
));
153 if ((data
& (SI_AC97_BUSY_READ
)) == 0)
158 if (count
== 0 && !trident
->ac97_detect
) {
159 dev_err(trident
->card
->dev
,
160 "ac97 codec read TIMEOUT [0x%x/0x%x]!!!\n",
165 spin_unlock_irqrestore(&trident
->reg_lock
, flags
);
166 return ((unsigned short) (data
>> 16));
169 /*---------------------------------------------------------------------------
170 void snd_trident_codec_write(struct snd_ac97 *ac97, unsigned short reg,
171 unsigned short wdata)
173 Description: This routine will do all of the writing to the external
176 Parameters: ac97 - ac97 codec structure
177 reg - CODEC register index, from AC97 Hal.
178 data - Lower 16 bits are the data to write to CODEC.
180 returns: TRUE if everything went ok, else FALSE.
182 ---------------------------------------------------------------------------*/
183 static void snd_trident_codec_write(struct snd_ac97
*ac97
, unsigned short reg
,
184 unsigned short wdata
)
186 unsigned int address
, data
;
187 unsigned short count
= 0xffff;
189 struct snd_trident
*trident
= ac97
->private_data
;
191 data
= ((unsigned long) wdata
) << 16;
193 spin_lock_irqsave(&trident
->reg_lock
, flags
);
194 if (trident
->device
== TRIDENT_DEVICE_ID_DX
) {
195 address
= DX_ACR0_AC97_W
;
197 /* read AC-97 write register status */
199 if ((inw(TRID_REG(trident
, address
)) & DX_AC97_BUSY_WRITE
) == 0)
203 data
|= (DX_AC97_BUSY_WRITE
| (reg
& 0x000000ff));
204 } else if (trident
->device
== TRIDENT_DEVICE_ID_NX
) {
205 address
= NX_ACR1_AC97_W
;
207 /* read AC-97 write register status */
209 if ((inw(TRID_REG(trident
, address
)) & NX_AC97_BUSY_WRITE
) == 0)
213 data
|= (NX_AC97_BUSY_WRITE
| (ac97
->num
<< 8) | (reg
& 0x000000ff));
214 } else if (trident
->device
== TRIDENT_DEVICE_ID_SI7018
) {
215 address
= SI_AC97_WRITE
;
217 /* read AC-97 write register status */
219 if ((inw(TRID_REG(trident
, address
)) & (SI_AC97_BUSY_WRITE
)) == 0)
223 data
|= SI_AC97_BUSY_WRITE
| SI_AC97_AUDIO_BUSY
| (reg
& 0x000000ff);
225 data
|= SI_AC97_SECONDARY
;
227 address
= 0; /* keep GCC happy */
228 count
= 0; /* return */
232 spin_unlock_irqrestore(&trident
->reg_lock
, flags
);
235 outl(data
, TRID_REG(trident
, address
));
236 spin_unlock_irqrestore(&trident
->reg_lock
, flags
);
239 /*---------------------------------------------------------------------------
240 void snd_trident_enable_eso(struct snd_trident *trident)
242 Description: This routine will enable end of loop interrupts.
243 End of loop interrupts will occur when a running
245 Also enables middle of loop interrupts.
247 Parameters: trident - pointer to target device class for 4DWave.
249 ---------------------------------------------------------------------------*/
251 static void snd_trident_enable_eso(struct snd_trident
* trident
)
255 val
= inl(TRID_REG(trident
, T4D_LFO_GC_CIR
));
258 if (trident
->device
== TRIDENT_DEVICE_ID_SI7018
)
260 outl(val
, TRID_REG(trident
, T4D_LFO_GC_CIR
));
263 /*---------------------------------------------------------------------------
264 void snd_trident_disable_eso(struct snd_trident *trident)
266 Description: This routine will disable end of loop interrupts.
267 End of loop interrupts will occur when a running
269 Also disables middle of loop interrupts.
272 trident - pointer to target device class for 4DWave.
274 returns: TRUE if everything went ok, else FALSE.
276 ---------------------------------------------------------------------------*/
278 static void snd_trident_disable_eso(struct snd_trident
* trident
)
282 tmp
= inl(TRID_REG(trident
, T4D_LFO_GC_CIR
));
285 outl(tmp
, TRID_REG(trident
, T4D_LFO_GC_CIR
));
288 /*---------------------------------------------------------------------------
289 void snd_trident_start_voice(struct snd_trident * trident, unsigned int voice)
291 Description: Start a voice, any channel 0 thru 63.
292 This routine automatically handles the fact that there are
293 more than 32 channels available.
295 Parameters : voice - Voice number 0 thru n.
296 trident - pointer to target device class for 4DWave.
300 ---------------------------------------------------------------------------*/
302 void snd_trident_start_voice(struct snd_trident
* trident
, unsigned int voice
)
304 unsigned int mask
= 1 << (voice
& 0x1f);
305 unsigned int reg
= (voice
& 0x20) ? T4D_START_B
: T4D_START_A
;
307 outl(mask
, TRID_REG(trident
, reg
));
310 EXPORT_SYMBOL(snd_trident_start_voice
);
312 /*---------------------------------------------------------------------------
313 void snd_trident_stop_voice(struct snd_trident * trident, unsigned int voice)
315 Description: Stop a voice, any channel 0 thru 63.
316 This routine automatically handles the fact that there are
317 more than 32 channels available.
319 Parameters : voice - Voice number 0 thru n.
320 trident - pointer to target device class for 4DWave.
324 ---------------------------------------------------------------------------*/
326 void snd_trident_stop_voice(struct snd_trident
* trident
, unsigned int voice
)
328 unsigned int mask
= 1 << (voice
& 0x1f);
329 unsigned int reg
= (voice
& 0x20) ? T4D_STOP_B
: T4D_STOP_A
;
331 outl(mask
, TRID_REG(trident
, reg
));
334 EXPORT_SYMBOL(snd_trident_stop_voice
);
336 /*---------------------------------------------------------------------------
337 int snd_trident_allocate_pcm_channel(struct snd_trident *trident)
339 Description: Allocate hardware channel in Bank B (32-63).
341 Parameters : trident - pointer to target device class for 4DWave.
343 Return Value: hardware channel - 32-63 or -1 when no channel is available
345 ---------------------------------------------------------------------------*/
347 static int snd_trident_allocate_pcm_channel(struct snd_trident
* trident
)
351 if (trident
->ChanPCMcnt
>= trident
->ChanPCM
)
353 for (idx
= 31; idx
>= 0; idx
--) {
354 if (!(trident
->ChanMap
[T4D_BANK_B
] & (1 << idx
))) {
355 trident
->ChanMap
[T4D_BANK_B
] |= 1 << idx
;
356 trident
->ChanPCMcnt
++;
363 /*---------------------------------------------------------------------------
364 void snd_trident_free_pcm_channel(int channel)
366 Description: Free hardware channel in Bank B (32-63)
368 Parameters : trident - pointer to target device class for 4DWave.
369 channel - hardware channel number 0-63
373 ---------------------------------------------------------------------------*/
375 static void snd_trident_free_pcm_channel(struct snd_trident
*trident
, int channel
)
377 if (channel
< 32 || channel
> 63)
380 if (trident
->ChanMap
[T4D_BANK_B
] & (1 << channel
)) {
381 trident
->ChanMap
[T4D_BANK_B
] &= ~(1 << channel
);
382 trident
->ChanPCMcnt
--;
386 /*---------------------------------------------------------------------------
387 unsigned int snd_trident_allocate_synth_channel(void)
389 Description: Allocate hardware channel in Bank A (0-31).
391 Parameters : trident - pointer to target device class for 4DWave.
393 Return Value: hardware channel - 0-31 or -1 when no channel is available
395 ---------------------------------------------------------------------------*/
397 static int snd_trident_allocate_synth_channel(struct snd_trident
* trident
)
401 for (idx
= 31; idx
>= 0; idx
--) {
402 if (!(trident
->ChanMap
[T4D_BANK_A
] & (1 << idx
))) {
403 trident
->ChanMap
[T4D_BANK_A
] |= 1 << idx
;
404 trident
->synth
.ChanSynthCount
++;
411 /*---------------------------------------------------------------------------
412 void snd_trident_free_synth_channel( int channel )
414 Description: Free hardware channel in Bank B (0-31).
416 Parameters : trident - pointer to target device class for 4DWave.
417 channel - hardware channel number 0-63
421 ---------------------------------------------------------------------------*/
423 static void snd_trident_free_synth_channel(struct snd_trident
*trident
, int channel
)
425 if (channel
< 0 || channel
> 31)
428 if (trident
->ChanMap
[T4D_BANK_A
] & (1 << channel
)) {
429 trident
->ChanMap
[T4D_BANK_A
] &= ~(1 << channel
);
430 trident
->synth
.ChanSynthCount
--;
434 /*---------------------------------------------------------------------------
435 snd_trident_write_voice_regs
437 Description: This routine will complete and write the 5 hardware channel
438 registers to hardware.
440 Parameters: trident - pointer to target device class for 4DWave.
441 voice - synthesizer voice structure
444 ---------------------------------------------------------------------------*/
446 void snd_trident_write_voice_regs(struct snd_trident
* trident
,
447 struct snd_trident_voice
* voice
)
449 unsigned int FmcRvolCvol
;
450 unsigned int regs
[5];
452 regs
[1] = voice
->LBA
;
453 regs
[4] = (voice
->GVSel
<< 31) |
454 ((voice
->Pan
& 0x0000007f) << 24) |
455 ((voice
->CTRL
& 0x0000000f) << 12);
456 FmcRvolCvol
= ((voice
->FMC
& 3) << 14) |
457 ((voice
->RVol
& 0x7f) << 7) |
458 (voice
->CVol
& 0x7f);
460 switch (trident
->device
) {
461 case TRIDENT_DEVICE_ID_SI7018
:
462 regs
[4] |= voice
->number
> 31 ?
463 (voice
->Vol
& 0x000003ff) :
464 ((voice
->Vol
& 0x00003fc) << (16-2)) |
465 (voice
->EC
& 0x00000fff);
466 regs
[0] = (voice
->CSO
<< 16) | ((voice
->Alpha
& 0x00000fff) << 4) |
467 (voice
->FMS
& 0x0000000f);
468 regs
[2] = (voice
->ESO
<< 16) | (voice
->Delta
& 0x0ffff);
469 regs
[3] = (voice
->Attribute
<< 16) | FmcRvolCvol
;
471 case TRIDENT_DEVICE_ID_DX
:
472 regs
[4] |= ((voice
->Vol
& 0x000003fc) << (16-2)) |
473 (voice
->EC
& 0x00000fff);
474 regs
[0] = (voice
->CSO
<< 16) | ((voice
->Alpha
& 0x00000fff) << 4) |
475 (voice
->FMS
& 0x0000000f);
476 regs
[2] = (voice
->ESO
<< 16) | (voice
->Delta
& 0x0ffff);
477 regs
[3] = FmcRvolCvol
;
479 case TRIDENT_DEVICE_ID_NX
:
480 regs
[4] |= ((voice
->Vol
& 0x000003fc) << (16-2)) |
481 (voice
->EC
& 0x00000fff);
482 regs
[0] = (voice
->Delta
<< 24) | (voice
->CSO
& 0x00ffffff);
483 regs
[2] = ((voice
->Delta
<< 16) & 0xff000000) |
484 (voice
->ESO
& 0x00ffffff);
485 regs
[3] = (voice
->Alpha
<< 20) |
486 ((voice
->FMS
& 0x0000000f) << 16) | FmcRvolCvol
;
493 outb(voice
->number
, TRID_REG(trident
, T4D_LFO_GC_CIR
));
494 outl(regs
[0], TRID_REG(trident
, CH_START
+ 0));
495 outl(regs
[1], TRID_REG(trident
, CH_START
+ 4));
496 outl(regs
[2], TRID_REG(trident
, CH_START
+ 8));
497 outl(regs
[3], TRID_REG(trident
, CH_START
+ 12));
498 outl(regs
[4], TRID_REG(trident
, CH_START
+ 16));
501 dev_dbg(trident
->card
->dev
, "written %i channel:\n", voice
->number
);
502 dev_dbg(trident
->card
->dev
, " regs[0] = 0x%x/0x%x\n",
503 regs
[0], inl(TRID_REG(trident
, CH_START
+ 0)));
504 dev_dbg(trident
->card
->dev
, " regs[1] = 0x%x/0x%x\n",
505 regs
[1], inl(TRID_REG(trident
, CH_START
+ 4)));
506 dev_dbg(trident
->card
->dev
, " regs[2] = 0x%x/0x%x\n",
507 regs
[2], inl(TRID_REG(trident
, CH_START
+ 8)));
508 dev_dbg(trident
->card
->dev
, " regs[3] = 0x%x/0x%x\n",
509 regs
[3], inl(TRID_REG(trident
, CH_START
+ 12)));
510 dev_dbg(trident
->card
->dev
, " regs[4] = 0x%x/0x%x\n",
511 regs
[4], inl(TRID_REG(trident
, CH_START
+ 16)));
515 EXPORT_SYMBOL(snd_trident_write_voice_regs
);
517 /*---------------------------------------------------------------------------
518 snd_trident_write_cso_reg
520 Description: This routine will write the new CSO offset
521 register to hardware.
523 Parameters: trident - pointer to target device class for 4DWave.
524 voice - synthesizer voice structure
527 ---------------------------------------------------------------------------*/
529 static void snd_trident_write_cso_reg(struct snd_trident
* trident
,
530 struct snd_trident_voice
* voice
,
534 outb(voice
->number
, TRID_REG(trident
, T4D_LFO_GC_CIR
));
535 if (trident
->device
!= TRIDENT_DEVICE_ID_NX
) {
536 outw(voice
->CSO
, TRID_REG(trident
, CH_DX_CSO_ALPHA_FMS
) + 2);
538 outl((voice
->Delta
<< 24) |
539 (voice
->CSO
& 0x00ffffff), TRID_REG(trident
, CH_NX_DELTA_CSO
));
543 /*---------------------------------------------------------------------------
544 snd_trident_write_eso_reg
546 Description: This routine will write the new ESO offset
547 register to hardware.
549 Parameters: trident - pointer to target device class for 4DWave.
550 voice - synthesizer voice structure
553 ---------------------------------------------------------------------------*/
555 static void snd_trident_write_eso_reg(struct snd_trident
* trident
,
556 struct snd_trident_voice
* voice
,
560 outb(voice
->number
, TRID_REG(trident
, T4D_LFO_GC_CIR
));
561 if (trident
->device
!= TRIDENT_DEVICE_ID_NX
) {
562 outw(voice
->ESO
, TRID_REG(trident
, CH_DX_ESO_DELTA
) + 2);
564 outl(((voice
->Delta
<< 16) & 0xff000000) | (voice
->ESO
& 0x00ffffff),
565 TRID_REG(trident
, CH_NX_DELTA_ESO
));
569 /*---------------------------------------------------------------------------
570 snd_trident_write_vol_reg
572 Description: This routine will write the new voice volume
573 register to hardware.
575 Parameters: trident - pointer to target device class for 4DWave.
576 voice - synthesizer voice structure
577 Vol - new voice volume
579 ---------------------------------------------------------------------------*/
581 static void snd_trident_write_vol_reg(struct snd_trident
* trident
,
582 struct snd_trident_voice
* voice
,
586 outb(voice
->number
, TRID_REG(trident
, T4D_LFO_GC_CIR
));
587 switch (trident
->device
) {
588 case TRIDENT_DEVICE_ID_DX
:
589 case TRIDENT_DEVICE_ID_NX
:
590 outb(voice
->Vol
>> 2, TRID_REG(trident
, CH_GVSEL_PAN_VOL_CTRL_EC
+ 2));
592 case TRIDENT_DEVICE_ID_SI7018
:
593 /* dev_dbg(trident->card->dev, "voice->Vol = 0x%x\n", voice->Vol); */
594 outw((voice
->CTRL
<< 12) | voice
->Vol
,
595 TRID_REG(trident
, CH_GVSEL_PAN_VOL_CTRL_EC
));
600 /*---------------------------------------------------------------------------
601 snd_trident_write_pan_reg
603 Description: This routine will write the new voice pan
604 register to hardware.
606 Parameters: trident - pointer to target device class for 4DWave.
607 voice - synthesizer voice structure
610 ---------------------------------------------------------------------------*/
612 static void snd_trident_write_pan_reg(struct snd_trident
* trident
,
613 struct snd_trident_voice
* voice
,
617 outb(voice
->number
, TRID_REG(trident
, T4D_LFO_GC_CIR
));
618 outb(((voice
->GVSel
& 0x01) << 7) | (voice
->Pan
& 0x7f),
619 TRID_REG(trident
, CH_GVSEL_PAN_VOL_CTRL_EC
+ 3));
622 /*---------------------------------------------------------------------------
623 snd_trident_write_rvol_reg
625 Description: This routine will write the new reverb volume
626 register to hardware.
628 Parameters: trident - pointer to target device class for 4DWave.
629 voice - synthesizer voice structure
630 RVol - new reverb volume
632 ---------------------------------------------------------------------------*/
634 static void snd_trident_write_rvol_reg(struct snd_trident
* trident
,
635 struct snd_trident_voice
* voice
,
639 outb(voice
->number
, TRID_REG(trident
, T4D_LFO_GC_CIR
));
640 outw(((voice
->FMC
& 0x0003) << 14) | ((voice
->RVol
& 0x007f) << 7) |
641 (voice
->CVol
& 0x007f),
642 TRID_REG(trident
, trident
->device
== TRIDENT_DEVICE_ID_NX
?
643 CH_NX_ALPHA_FMS_FMC_RVOL_CVOL
: CH_DX_FMC_RVOL_CVOL
));
646 /*---------------------------------------------------------------------------
647 snd_trident_write_cvol_reg
649 Description: This routine will write the new chorus volume
650 register to hardware.
652 Parameters: trident - pointer to target device class for 4DWave.
653 voice - synthesizer voice structure
654 CVol - new chorus volume
656 ---------------------------------------------------------------------------*/
658 static void snd_trident_write_cvol_reg(struct snd_trident
* trident
,
659 struct snd_trident_voice
* voice
,
663 outb(voice
->number
, TRID_REG(trident
, T4D_LFO_GC_CIR
));
664 outw(((voice
->FMC
& 0x0003) << 14) | ((voice
->RVol
& 0x007f) << 7) |
665 (voice
->CVol
& 0x007f),
666 TRID_REG(trident
, trident
->device
== TRIDENT_DEVICE_ID_NX
?
667 CH_NX_ALPHA_FMS_FMC_RVOL_CVOL
: CH_DX_FMC_RVOL_CVOL
));
670 /*---------------------------------------------------------------------------
671 snd_trident_convert_rate
673 Description: This routine converts rate in HZ to hardware delta value.
675 Parameters: trident - pointer to target device class for 4DWave.
676 rate - Real or Virtual channel number.
678 Returns: Delta value.
680 ---------------------------------------------------------------------------*/
681 static unsigned int snd_trident_convert_rate(unsigned int rate
)
685 // We special case 44100 and 8000 since rounding with the equation
686 // does not give us an accurate enough value. For 11025 and 22050
687 // the equation gives us the best answer. All other frequencies will
688 // also use the equation. JDW
691 else if (rate
== 8000)
693 else if (rate
== 48000)
696 delta
= (((rate
<< 12) + 24000) / 48000) & 0x0000ffff;
700 /*---------------------------------------------------------------------------
701 snd_trident_convert_adc_rate
703 Description: This routine converts rate in HZ to hardware delta value.
705 Parameters: trident - pointer to target device class for 4DWave.
706 rate - Real or Virtual channel number.
708 Returns: Delta value.
710 ---------------------------------------------------------------------------*/
711 static unsigned int snd_trident_convert_adc_rate(unsigned int rate
)
715 // We special case 44100 and 8000 since rounding with the equation
716 // does not give us an accurate enough value. For 11025 and 22050
717 // the equation gives us the best answer. All other frequencies will
718 // also use the equation. JDW
721 else if (rate
== 8000)
723 else if (rate
== 48000)
726 delta
= ((48000 << 12) / rate
) & 0x0000ffff;
730 /*---------------------------------------------------------------------------
731 snd_trident_spurious_threshold
733 Description: This routine converts rate in HZ to spurious threshold.
735 Parameters: trident - pointer to target device class for 4DWave.
736 rate - Real or Virtual channel number.
738 Returns: Delta value.
740 ---------------------------------------------------------------------------*/
741 static unsigned int snd_trident_spurious_threshold(unsigned int rate
,
742 unsigned int period_size
)
744 unsigned int res
= (rate
* period_size
) / 48000;
752 /*---------------------------------------------------------------------------
753 snd_trident_control_mode
755 Description: This routine returns a control mode for a PCM channel.
757 Parameters: trident - pointer to target device class for 4DWave.
758 substream - PCM substream
760 Returns: Control value.
762 ---------------------------------------------------------------------------*/
763 static unsigned int snd_trident_control_mode(struct snd_pcm_substream
*substream
)
766 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
769 CTRL default: 8-bit (unsigned) mono, loop mode enabled
772 if (snd_pcm_format_width(runtime
->format
) == 16)
773 CTRL
|= 0x00000008; // 16-bit data
774 if (snd_pcm_format_signed(runtime
->format
))
775 CTRL
|= 0x00000002; // signed data
776 if (runtime
->channels
> 1)
777 CTRL
|= 0x00000004; // stereo data
785 /*---------------------------------------------------------------------------
788 Description: Device I/O control handler for playback/capture parameters.
790 Parameters: substream - PCM substream class
791 cmd - what ioctl message to process
792 arg - additional message infoarg
794 Returns: Error status
796 ---------------------------------------------------------------------------*/
798 static int snd_trident_ioctl(struct snd_pcm_substream
*substream
,
802 /* FIXME: it seems that with small periods the behaviour of
803 trident hardware is unpredictable and interrupt generator
805 return snd_pcm_lib_ioctl(substream
, cmd
, arg
);
808 /*---------------------------------------------------------------------------
809 snd_trident_allocate_pcm_mem
811 Description: Allocate PCM ring buffer for given substream
813 Parameters: substream - PCM substream class
814 hw_params - hardware parameters
816 Returns: Error status
818 ---------------------------------------------------------------------------*/
820 static int snd_trident_allocate_pcm_mem(struct snd_pcm_substream
*substream
,
821 struct snd_pcm_hw_params
*hw_params
)
823 struct snd_trident
*trident
= snd_pcm_substream_chip(substream
);
824 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
825 struct snd_trident_voice
*voice
= runtime
->private_data
;
828 if ((err
= snd_pcm_lib_malloc_pages(substream
, params_buffer_bytes(hw_params
))) < 0)
830 if (trident
->tlb
.entries
) {
831 if (err
> 0) { /* change */
833 snd_trident_free_pages(trident
, voice
->memblk
);
834 voice
->memblk
= snd_trident_alloc_pages(trident
, substream
);
835 if (voice
->memblk
== NULL
)
842 /*---------------------------------------------------------------------------
843 snd_trident_allocate_evoice
845 Description: Allocate extra voice as interrupt generator
847 Parameters: substream - PCM substream class
848 hw_params - hardware parameters
850 Returns: Error status
852 ---------------------------------------------------------------------------*/
854 static int snd_trident_allocate_evoice(struct snd_pcm_substream
*substream
,
855 struct snd_pcm_hw_params
*hw_params
)
857 struct snd_trident
*trident
= snd_pcm_substream_chip(substream
);
858 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
859 struct snd_trident_voice
*voice
= runtime
->private_data
;
860 struct snd_trident_voice
*evoice
= voice
->extra
;
862 /* voice management */
864 if (params_buffer_size(hw_params
) / 2 != params_period_size(hw_params
)) {
865 if (evoice
== NULL
) {
866 evoice
= snd_trident_alloc_voice(trident
, SNDRV_TRIDENT_VOICE_TYPE_PCM
, 0, 0);
869 voice
->extra
= evoice
;
870 evoice
->substream
= substream
;
873 if (evoice
!= NULL
) {
874 snd_trident_free_voice(trident
, evoice
);
875 voice
->extra
= evoice
= NULL
;
882 /*---------------------------------------------------------------------------
883 snd_trident_hw_params
885 Description: Set the hardware parameters for the playback device.
887 Parameters: substream - PCM substream class
888 hw_params - hardware parameters
890 Returns: Error status
892 ---------------------------------------------------------------------------*/
894 static int snd_trident_hw_params(struct snd_pcm_substream
*substream
,
895 struct snd_pcm_hw_params
*hw_params
)
899 err
= snd_trident_allocate_pcm_mem(substream
, hw_params
);
901 err
= snd_trident_allocate_evoice(substream
, hw_params
);
905 /*---------------------------------------------------------------------------
906 snd_trident_playback_hw_free
908 Description: Release the hardware resources for the playback device.
910 Parameters: substream - PCM substream class
912 Returns: Error status
914 ---------------------------------------------------------------------------*/
916 static int snd_trident_hw_free(struct snd_pcm_substream
*substream
)
918 struct snd_trident
*trident
= snd_pcm_substream_chip(substream
);
919 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
920 struct snd_trident_voice
*voice
= runtime
->private_data
;
921 struct snd_trident_voice
*evoice
= voice
? voice
->extra
: NULL
;
923 if (trident
->tlb
.entries
) {
924 if (voice
&& voice
->memblk
) {
925 snd_trident_free_pages(trident
, voice
->memblk
);
926 voice
->memblk
= NULL
;
929 snd_pcm_lib_free_pages(substream
);
930 if (evoice
!= NULL
) {
931 snd_trident_free_voice(trident
, evoice
);
937 /*---------------------------------------------------------------------------
938 snd_trident_playback_prepare
940 Description: Prepare playback device for playback.
942 Parameters: substream - PCM substream class
944 Returns: Error status
946 ---------------------------------------------------------------------------*/
948 static int snd_trident_playback_prepare(struct snd_pcm_substream
*substream
)
950 struct snd_trident
*trident
= snd_pcm_substream_chip(substream
);
951 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
952 struct snd_trident_voice
*voice
= runtime
->private_data
;
953 struct snd_trident_voice
*evoice
= voice
->extra
;
954 struct snd_trident_pcm_mixer
*mix
= &trident
->pcm_mixer
[substream
->number
];
956 spin_lock_irq(&trident
->reg_lock
);
958 /* set delta (rate) value */
959 voice
->Delta
= snd_trident_convert_rate(runtime
->rate
);
960 voice
->spurious_threshold
= snd_trident_spurious_threshold(runtime
->rate
, runtime
->period_size
);
962 /* set Loop Begin Address */
964 voice
->LBA
= voice
->memblk
->offset
;
966 voice
->LBA
= runtime
->dma_addr
;
969 voice
->ESO
= runtime
->buffer_size
- 1; /* in samples */
970 voice
->CTRL
= snd_trident_control_mode(substream
);
976 voice
->Vol
= mix
->vol
;
977 voice
->RVol
= mix
->rvol
;
978 voice
->CVol
= mix
->cvol
;
979 voice
->Pan
= mix
->pan
;
980 voice
->Attribute
= 0;
982 voice
->Attribute
= (1<<(30-16))|(2<<(26-16))|
983 (0<<(24-16))|(0x1f<<(19-16));
985 voice
->Attribute
= 0;
988 snd_trident_write_voice_regs(trident
, voice
);
990 if (evoice
!= NULL
) {
991 evoice
->Delta
= voice
->Delta
;
992 evoice
->spurious_threshold
= voice
->spurious_threshold
;
993 evoice
->LBA
= voice
->LBA
;
995 evoice
->ESO
= (runtime
->period_size
* 2) + 4 - 1; /* in samples */
996 evoice
->CTRL
= voice
->CTRL
;
998 evoice
->GVSel
= trident
->device
== TRIDENT_DEVICE_ID_SI7018
? 0 : 1;
1002 evoice
->Vol
= 0x3ff; /* mute */
1003 evoice
->RVol
= evoice
->CVol
= 0x7f; /* mute */
1004 evoice
->Pan
= 0x7f; /* mute */
1006 evoice
->Attribute
= (1<<(30-16))|(2<<(26-16))|
1007 (0<<(24-16))|(0x1f<<(19-16));
1009 evoice
->Attribute
= 0;
1011 snd_trident_write_voice_regs(trident
, evoice
);
1013 evoice
->isync_mark
= runtime
->period_size
;
1014 evoice
->ESO
= (runtime
->period_size
* 2) - 1;
1017 spin_unlock_irq(&trident
->reg_lock
);
1022 /*---------------------------------------------------------------------------
1023 snd_trident_capture_hw_params
1025 Description: Set the hardware parameters for the capture device.
1027 Parameters: substream - PCM substream class
1028 hw_params - hardware parameters
1030 Returns: Error status
1032 ---------------------------------------------------------------------------*/
1034 static int snd_trident_capture_hw_params(struct snd_pcm_substream
*substream
,
1035 struct snd_pcm_hw_params
*hw_params
)
1037 return snd_trident_allocate_pcm_mem(substream
, hw_params
);
1040 /*---------------------------------------------------------------------------
1041 snd_trident_capture_prepare
1043 Description: Prepare capture device for playback.
1045 Parameters: substream - PCM substream class
1047 Returns: Error status
1049 ---------------------------------------------------------------------------*/
1051 static int snd_trident_capture_prepare(struct snd_pcm_substream
*substream
)
1053 struct snd_trident
*trident
= snd_pcm_substream_chip(substream
);
1054 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1055 struct snd_trident_voice
*voice
= runtime
->private_data
;
1056 unsigned int val
, ESO_bytes
;
1058 spin_lock_irq(&trident
->reg_lock
);
1060 // Initialize the channel and set channel Mode
1061 outb(0, TRID_REG(trident
, LEGACY_DMAR15
));
1063 // Set DMA channel operation mode register
1064 outb(0x54, TRID_REG(trident
, LEGACY_DMAR11
));
1066 // Set channel buffer Address, DMAR0 expects contiguous PCI memory area
1067 voice
->LBA
= runtime
->dma_addr
;
1068 outl(voice
->LBA
, TRID_REG(trident
, LEGACY_DMAR0
));
1070 voice
->LBA
= voice
->memblk
->offset
;
1073 ESO_bytes
= snd_pcm_lib_buffer_bytes(substream
) - 1;
1074 outb((ESO_bytes
& 0x00ff0000) >> 16, TRID_REG(trident
, LEGACY_DMAR6
));
1075 outw((ESO_bytes
& 0x0000ffff), TRID_REG(trident
, LEGACY_DMAR4
));
1078 // Set channel sample rate, 4.12 format
1079 val
= (((unsigned int) 48000L << 12) + (runtime
->rate
/2)) / runtime
->rate
;
1080 outw(val
, TRID_REG(trident
, T4D_SBDELTA_DELTA_R
));
1082 // Set channel interrupt blk length
1083 if (snd_pcm_format_width(runtime
->format
) == 16) {
1084 val
= (unsigned short) ((ESO_bytes
>> 1) - 1);
1086 val
= (unsigned short) (ESO_bytes
- 1);
1089 outl((val
<< 16) | val
, TRID_REG(trident
, T4D_SBBL_SBCL
));
1091 // Right now, set format and start to run captureing,
1092 // continuous run loop enable.
1093 trident
->bDMAStart
= 0x19; // 0001 1001b
1095 if (snd_pcm_format_width(runtime
->format
) == 16)
1096 trident
->bDMAStart
|= 0x80;
1097 if (snd_pcm_format_signed(runtime
->format
))
1098 trident
->bDMAStart
|= 0x20;
1099 if (runtime
->channels
> 1)
1100 trident
->bDMAStart
|= 0x40;
1102 // Prepare capture intr channel
1104 voice
->Delta
= snd_trident_convert_rate(runtime
->rate
);
1105 voice
->spurious_threshold
= snd_trident_spurious_threshold(runtime
->rate
, runtime
->period_size
);
1107 voice
->isync_mark
= runtime
->period_size
;
1108 voice
->isync_max
= runtime
->buffer_size
;
1110 // Set voice parameters
1112 voice
->ESO
= voice
->isync_ESO
= (runtime
->period_size
* 2) + 6 - 1;
1113 voice
->CTRL
= snd_trident_control_mode(substream
);
1118 voice
->Pan
= 0x7f; /* mute */
1119 voice
->Vol
= 0x3ff; /* mute */
1123 voice
->Attribute
= 0;
1125 snd_trident_write_voice_regs(trident
, voice
);
1127 spin_unlock_irq(&trident
->reg_lock
);
1131 /*---------------------------------------------------------------------------
1132 snd_trident_si7018_capture_hw_params
1134 Description: Set the hardware parameters for the capture device.
1136 Parameters: substream - PCM substream class
1137 hw_params - hardware parameters
1139 Returns: Error status
1141 ---------------------------------------------------------------------------*/
1143 static int snd_trident_si7018_capture_hw_params(struct snd_pcm_substream
*substream
,
1144 struct snd_pcm_hw_params
*hw_params
)
1148 if ((err
= snd_pcm_lib_malloc_pages(substream
, params_buffer_bytes(hw_params
))) < 0)
1151 return snd_trident_allocate_evoice(substream
, hw_params
);
1154 /*---------------------------------------------------------------------------
1155 snd_trident_si7018_capture_hw_free
1157 Description: Release the hardware resources for the capture device.
1159 Parameters: substream - PCM substream class
1161 Returns: Error status
1163 ---------------------------------------------------------------------------*/
1165 static int snd_trident_si7018_capture_hw_free(struct snd_pcm_substream
*substream
)
1167 struct snd_trident
*trident
= snd_pcm_substream_chip(substream
);
1168 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1169 struct snd_trident_voice
*voice
= runtime
->private_data
;
1170 struct snd_trident_voice
*evoice
= voice
? voice
->extra
: NULL
;
1172 snd_pcm_lib_free_pages(substream
);
1173 if (evoice
!= NULL
) {
1174 snd_trident_free_voice(trident
, evoice
);
1175 voice
->extra
= NULL
;
1180 /*---------------------------------------------------------------------------
1181 snd_trident_si7018_capture_prepare
1183 Description: Prepare capture device for playback.
1185 Parameters: substream - PCM substream class
1187 Returns: Error status
1189 ---------------------------------------------------------------------------*/
1191 static int snd_trident_si7018_capture_prepare(struct snd_pcm_substream
*substream
)
1193 struct snd_trident
*trident
= snd_pcm_substream_chip(substream
);
1194 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1195 struct snd_trident_voice
*voice
= runtime
->private_data
;
1196 struct snd_trident_voice
*evoice
= voice
->extra
;
1198 spin_lock_irq(&trident
->reg_lock
);
1200 voice
->LBA
= runtime
->dma_addr
;
1201 voice
->Delta
= snd_trident_convert_adc_rate(runtime
->rate
);
1202 voice
->spurious_threshold
= snd_trident_spurious_threshold(runtime
->rate
, runtime
->period_size
);
1204 // Set voice parameters
1206 voice
->ESO
= runtime
->buffer_size
- 1; /* in samples */
1207 voice
->CTRL
= snd_trident_control_mode(substream
);
1212 voice
->Pan
= T4D_DEFAULT_PCM_PAN
;
1218 voice
->Attribute
= (2 << (30-16)) |
1223 snd_trident_write_voice_regs(trident
, voice
);
1225 if (evoice
!= NULL
) {
1226 evoice
->Delta
= snd_trident_convert_rate(runtime
->rate
);
1227 evoice
->spurious_threshold
= voice
->spurious_threshold
;
1228 evoice
->LBA
= voice
->LBA
;
1230 evoice
->ESO
= (runtime
->period_size
* 2) + 20 - 1; /* in samples, 20 means correction */
1231 evoice
->CTRL
= voice
->CTRL
;
1237 evoice
->Vol
= 0x3ff; /* mute */
1238 evoice
->RVol
= evoice
->CVol
= 0x7f; /* mute */
1239 evoice
->Pan
= 0x7f; /* mute */
1240 evoice
->Attribute
= 0;
1241 snd_trident_write_voice_regs(trident
, evoice
);
1243 evoice
->isync_mark
= runtime
->period_size
;
1244 evoice
->ESO
= (runtime
->period_size
* 2) - 1;
1247 spin_unlock_irq(&trident
->reg_lock
);
1251 /*---------------------------------------------------------------------------
1252 snd_trident_foldback_prepare
1254 Description: Prepare foldback capture device for playback.
1256 Parameters: substream - PCM substream class
1258 Returns: Error status
1260 ---------------------------------------------------------------------------*/
1262 static int snd_trident_foldback_prepare(struct snd_pcm_substream
*substream
)
1264 struct snd_trident
*trident
= snd_pcm_substream_chip(substream
);
1265 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1266 struct snd_trident_voice
*voice
= runtime
->private_data
;
1267 struct snd_trident_voice
*evoice
= voice
->extra
;
1269 spin_lock_irq(&trident
->reg_lock
);
1271 /* Set channel buffer Address */
1273 voice
->LBA
= voice
->memblk
->offset
;
1275 voice
->LBA
= runtime
->dma_addr
;
1277 /* set target ESO for channel */
1278 voice
->ESO
= runtime
->buffer_size
- 1; /* in samples */
1280 /* set sample rate */
1281 voice
->Delta
= 0x1000;
1282 voice
->spurious_threshold
= snd_trident_spurious_threshold(48000, runtime
->period_size
);
1285 voice
->CTRL
= snd_trident_control_mode(substream
);
1290 voice
->Pan
= 0x7f; /* mute */
1291 voice
->Vol
= 0x3ff; /* mute */
1295 voice
->Attribute
= 0;
1297 /* set up capture channel */
1298 outb(((voice
->number
& 0x3f) | 0x80), TRID_REG(trident
, T4D_RCI
+ voice
->foldback_chan
));
1300 snd_trident_write_voice_regs(trident
, voice
);
1302 if (evoice
!= NULL
) {
1303 evoice
->Delta
= voice
->Delta
;
1304 evoice
->spurious_threshold
= voice
->spurious_threshold
;
1305 evoice
->LBA
= voice
->LBA
;
1307 evoice
->ESO
= (runtime
->period_size
* 2) + 4 - 1; /* in samples */
1308 evoice
->CTRL
= voice
->CTRL
;
1310 evoice
->GVSel
= trident
->device
== TRIDENT_DEVICE_ID_SI7018
? 0 : 1;
1314 evoice
->Vol
= 0x3ff; /* mute */
1315 evoice
->RVol
= evoice
->CVol
= 0x7f; /* mute */
1316 evoice
->Pan
= 0x7f; /* mute */
1317 evoice
->Attribute
= 0;
1318 snd_trident_write_voice_regs(trident
, evoice
);
1320 evoice
->isync_mark
= runtime
->period_size
;
1321 evoice
->ESO
= (runtime
->period_size
* 2) - 1;
1324 spin_unlock_irq(&trident
->reg_lock
);
1328 /*---------------------------------------------------------------------------
1329 snd_trident_spdif_hw_params
1331 Description: Set the hardware parameters for the spdif device.
1333 Parameters: substream - PCM substream class
1334 hw_params - hardware parameters
1336 Returns: Error status
1338 ---------------------------------------------------------------------------*/
1340 static int snd_trident_spdif_hw_params(struct snd_pcm_substream
*substream
,
1341 struct snd_pcm_hw_params
*hw_params
)
1343 struct snd_trident
*trident
= snd_pcm_substream_chip(substream
);
1344 unsigned int old_bits
= 0, change
= 0;
1347 err
= snd_trident_allocate_pcm_mem(substream
, hw_params
);
1351 if (trident
->device
== TRIDENT_DEVICE_ID_SI7018
) {
1352 err
= snd_trident_allocate_evoice(substream
, hw_params
);
1357 /* prepare SPDIF channel */
1358 spin_lock_irq(&trident
->reg_lock
);
1359 old_bits
= trident
->spdif_pcm_bits
;
1360 if (old_bits
& IEC958_AES0_PROFESSIONAL
)
1361 trident
->spdif_pcm_bits
&= ~IEC958_AES0_PRO_FS
;
1363 trident
->spdif_pcm_bits
&= ~(IEC958_AES3_CON_FS
<< 24);
1364 if (params_rate(hw_params
) >= 48000) {
1365 trident
->spdif_pcm_ctrl
= 0x3c; // 48000 Hz
1366 trident
->spdif_pcm_bits
|=
1367 trident
->spdif_bits
& IEC958_AES0_PROFESSIONAL
?
1368 IEC958_AES0_PRO_FS_48000
:
1369 (IEC958_AES3_CON_FS_48000
<< 24);
1371 else if (params_rate(hw_params
) >= 44100) {
1372 trident
->spdif_pcm_ctrl
= 0x3e; // 44100 Hz
1373 trident
->spdif_pcm_bits
|=
1374 trident
->spdif_bits
& IEC958_AES0_PROFESSIONAL
?
1375 IEC958_AES0_PRO_FS_44100
:
1376 (IEC958_AES3_CON_FS_44100
<< 24);
1379 trident
->spdif_pcm_ctrl
= 0x3d; // 32000 Hz
1380 trident
->spdif_pcm_bits
|=
1381 trident
->spdif_bits
& IEC958_AES0_PROFESSIONAL
?
1382 IEC958_AES0_PRO_FS_32000
:
1383 (IEC958_AES3_CON_FS_32000
<< 24);
1385 change
= old_bits
!= trident
->spdif_pcm_bits
;
1386 spin_unlock_irq(&trident
->reg_lock
);
1389 snd_ctl_notify(trident
->card
, SNDRV_CTL_EVENT_MASK_VALUE
, &trident
->spdif_pcm_ctl
->id
);
1394 /*---------------------------------------------------------------------------
1395 snd_trident_spdif_prepare
1397 Description: Prepare SPDIF device for playback.
1399 Parameters: substream - PCM substream class
1401 Returns: Error status
1403 ---------------------------------------------------------------------------*/
1405 static int snd_trident_spdif_prepare(struct snd_pcm_substream
*substream
)
1407 struct snd_trident
*trident
= snd_pcm_substream_chip(substream
);
1408 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1409 struct snd_trident_voice
*voice
= runtime
->private_data
;
1410 struct snd_trident_voice
*evoice
= voice
->extra
;
1411 struct snd_trident_pcm_mixer
*mix
= &trident
->pcm_mixer
[substream
->number
];
1412 unsigned int RESO
, LBAO
;
1415 spin_lock_irq(&trident
->reg_lock
);
1417 if (trident
->device
!= TRIDENT_DEVICE_ID_SI7018
) {
1419 /* set delta (rate) value */
1420 voice
->Delta
= snd_trident_convert_rate(runtime
->rate
);
1421 voice
->spurious_threshold
= snd_trident_spurious_threshold(runtime
->rate
, runtime
->period_size
);
1423 /* set Loop Back Address */
1424 LBAO
= runtime
->dma_addr
;
1426 voice
->LBA
= voice
->memblk
->offset
;
1432 voice
->isync_mark
= runtime
->period_size
;
1433 voice
->isync_max
= runtime
->buffer_size
;
1435 /* set target ESO for channel */
1436 RESO
= runtime
->buffer_size
- 1;
1437 voice
->ESO
= voice
->isync_ESO
= (runtime
->period_size
* 2) + 6 - 1;
1440 voice
->CTRL
= snd_trident_control_mode(substream
);
1452 voice
->Attribute
= 0;
1454 /* prepare surrogate IRQ channel */
1455 snd_trident_write_voice_regs(trident
, voice
);
1457 outw((RESO
& 0xffff), TRID_REG(trident
, NX_SPESO
));
1458 outb((RESO
>> 16), TRID_REG(trident
, NX_SPESO
+ 2));
1459 outl((LBAO
& 0xfffffffc), TRID_REG(trident
, NX_SPLBA
));
1460 outw((voice
->CSO
& 0xffff), TRID_REG(trident
, NX_SPCTRL_SPCSO
));
1461 outb((voice
->CSO
>> 16), TRID_REG(trident
, NX_SPCTRL_SPCSO
+ 2));
1463 /* set SPDIF setting */
1464 outb(trident
->spdif_pcm_ctrl
, TRID_REG(trident
, NX_SPCTRL_SPCSO
+ 3));
1465 outl(trident
->spdif_pcm_bits
, TRID_REG(trident
, NX_SPCSTATUS
));
1469 /* set delta (rate) value */
1470 voice
->Delta
= 0x800;
1471 voice
->spurious_threshold
= snd_trident_spurious_threshold(48000, runtime
->period_size
);
1473 /* set Loop Begin Address */
1475 voice
->LBA
= voice
->memblk
->offset
;
1477 voice
->LBA
= runtime
->dma_addr
;
1480 voice
->ESO
= runtime
->buffer_size
- 1; /* in samples */
1481 voice
->CTRL
= snd_trident_control_mode(substream
);
1487 voice
->Vol
= mix
->vol
;
1488 voice
->RVol
= mix
->rvol
;
1489 voice
->CVol
= mix
->cvol
;
1490 voice
->Pan
= mix
->pan
;
1491 voice
->Attribute
= (1<<(30-16))|(7<<(26-16))|
1492 (0<<(24-16))|(0<<(19-16));
1494 snd_trident_write_voice_regs(trident
, voice
);
1496 if (evoice
!= NULL
) {
1497 evoice
->Delta
= voice
->Delta
;
1498 evoice
->spurious_threshold
= voice
->spurious_threshold
;
1499 evoice
->LBA
= voice
->LBA
;
1501 evoice
->ESO
= (runtime
->period_size
* 2) + 4 - 1; /* in samples */
1502 evoice
->CTRL
= voice
->CTRL
;
1504 evoice
->GVSel
= trident
->device
== TRIDENT_DEVICE_ID_SI7018
? 0 : 1;
1508 evoice
->Vol
= 0x3ff; /* mute */
1509 evoice
->RVol
= evoice
->CVol
= 0x7f; /* mute */
1510 evoice
->Pan
= 0x7f; /* mute */
1511 evoice
->Attribute
= 0;
1512 snd_trident_write_voice_regs(trident
, evoice
);
1514 evoice
->isync_mark
= runtime
->period_size
;
1515 evoice
->ESO
= (runtime
->period_size
* 2) - 1;
1518 outl(trident
->spdif_pcm_bits
, TRID_REG(trident
, SI_SPDIF_CS
));
1519 temp
= inl(TRID_REG(trident
, T4D_LFO_GC_CIR
));
1521 outl(temp
, TRID_REG(trident
, T4D_LFO_GC_CIR
));
1522 temp
= inl(TRID_REG(trident
, SI_SERIAL_INTF_CTRL
));
1524 outl(temp
, TRID_REG(trident
, SI_SERIAL_INTF_CTRL
));
1527 spin_unlock_irq(&trident
->reg_lock
);
1532 /*---------------------------------------------------------------------------
1535 Description: Start/stop devices
1537 Parameters: substream - PCM substream class
1538 cmd - trigger command (STOP, GO)
1540 Returns: Error status
1542 ---------------------------------------------------------------------------*/
1544 static int snd_trident_trigger(struct snd_pcm_substream
*substream
,
1548 struct snd_trident
*trident
= snd_pcm_substream_chip(substream
);
1549 struct snd_pcm_substream
*s
;
1550 unsigned int what
, whati
, capture_flag
, spdif_flag
;
1551 struct snd_trident_voice
*voice
, *evoice
;
1552 unsigned int val
, go
;
1555 case SNDRV_PCM_TRIGGER_START
:
1556 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
1557 case SNDRV_PCM_TRIGGER_RESUME
:
1560 case SNDRV_PCM_TRIGGER_STOP
:
1561 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
1562 case SNDRV_PCM_TRIGGER_SUSPEND
:
1568 what
= whati
= capture_flag
= spdif_flag
= 0;
1569 spin_lock(&trident
->reg_lock
);
1570 val
= inl(TRID_REG(trident
, T4D_STIMER
)) & 0x00ffffff;
1571 snd_pcm_group_for_each_entry(s
, substream
) {
1572 if ((struct snd_trident
*) snd_pcm_substream_chip(s
) == trident
) {
1573 voice
= s
->runtime
->private_data
;
1574 evoice
= voice
->extra
;
1575 what
|= 1 << (voice
->number
& 0x1f);
1576 if (evoice
== NULL
) {
1577 whati
|= 1 << (voice
->number
& 0x1f);
1579 what
|= 1 << (evoice
->number
& 0x1f);
1580 whati
|= 1 << (evoice
->number
& 0x1f);
1582 evoice
->stimer
= val
;
1586 voice
->stimer
= val
;
1590 snd_pcm_trigger_done(s
, substream
);
1598 if (trident
->device
!= TRIDENT_DEVICE_ID_SI7018
) {
1599 outl(trident
->spdif_pcm_bits
, TRID_REG(trident
, NX_SPCSTATUS
));
1600 val
= trident
->spdif_pcm_ctrl
;
1603 outb(val
, TRID_REG(trident
, NX_SPCTRL_SPCSO
+ 3));
1605 outl(trident
->spdif_pcm_bits
, TRID_REG(trident
, SI_SPDIF_CS
));
1606 val
= inl(TRID_REG(trident
, SI_SERIAL_INTF_CTRL
)) | SPDIF_EN
;
1607 outl(val
, TRID_REG(trident
, SI_SERIAL_INTF_CTRL
));
1611 outl(what
, TRID_REG(trident
, T4D_STOP_B
));
1612 val
= inl(TRID_REG(trident
, T4D_AINTEN_B
));
1618 outl(val
, TRID_REG(trident
, T4D_AINTEN_B
));
1620 outl(what
, TRID_REG(trident
, T4D_START_B
));
1622 if (capture_flag
&& trident
->device
!= TRIDENT_DEVICE_ID_SI7018
)
1623 outb(trident
->bDMAStart
, TRID_REG(trident
, T4D_SBCTRL_SBE2R_SBDD
));
1625 if (capture_flag
&& trident
->device
!= TRIDENT_DEVICE_ID_SI7018
)
1626 outb(0x00, TRID_REG(trident
, T4D_SBCTRL_SBE2R_SBDD
));
1628 spin_unlock(&trident
->reg_lock
);
1632 /*---------------------------------------------------------------------------
1633 snd_trident_playback_pointer
1635 Description: This routine return the playback position
1637 Parameters: substream - PCM substream class
1639 Returns: position of buffer
1641 ---------------------------------------------------------------------------*/
1643 static snd_pcm_uframes_t
snd_trident_playback_pointer(struct snd_pcm_substream
*substream
)
1645 struct snd_trident
*trident
= snd_pcm_substream_chip(substream
);
1646 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1647 struct snd_trident_voice
*voice
= runtime
->private_data
;
1650 if (!voice
->running
)
1653 spin_lock(&trident
->reg_lock
);
1655 outb(voice
->number
, TRID_REG(trident
, T4D_LFO_GC_CIR
));
1657 if (trident
->device
!= TRIDENT_DEVICE_ID_NX
) {
1658 cso
= inw(TRID_REG(trident
, CH_DX_CSO_ALPHA_FMS
+ 2));
1659 } else { // ID_4DWAVE_NX
1660 cso
= (unsigned int) inl(TRID_REG(trident
, CH_NX_DELTA_CSO
)) & 0x00ffffff;
1663 spin_unlock(&trident
->reg_lock
);
1665 if (cso
>= runtime
->buffer_size
)
1671 /*---------------------------------------------------------------------------
1672 snd_trident_capture_pointer
1674 Description: This routine return the capture position
1676 Parameters: pcm1 - PCM device class
1678 Returns: position of buffer
1680 ---------------------------------------------------------------------------*/
1682 static snd_pcm_uframes_t
snd_trident_capture_pointer(struct snd_pcm_substream
*substream
)
1684 struct snd_trident
*trident
= snd_pcm_substream_chip(substream
);
1685 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1686 struct snd_trident_voice
*voice
= runtime
->private_data
;
1687 unsigned int result
;
1689 if (!voice
->running
)
1692 result
= inw(TRID_REG(trident
, T4D_SBBL_SBCL
));
1693 if (runtime
->channels
> 1)
1696 result
= runtime
->buffer_size
- result
;
1701 /*---------------------------------------------------------------------------
1702 snd_trident_spdif_pointer
1704 Description: This routine return the SPDIF playback position
1706 Parameters: substream - PCM substream class
1708 Returns: position of buffer
1710 ---------------------------------------------------------------------------*/
1712 static snd_pcm_uframes_t
snd_trident_spdif_pointer(struct snd_pcm_substream
*substream
)
1714 struct snd_trident
*trident
= snd_pcm_substream_chip(substream
);
1715 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1716 struct snd_trident_voice
*voice
= runtime
->private_data
;
1717 unsigned int result
;
1719 if (!voice
->running
)
1722 result
= inl(TRID_REG(trident
, NX_SPCTRL_SPCSO
)) & 0x00ffffff;
1728 * Playback support device description
1731 static struct snd_pcm_hardware snd_trident_playback
=
1733 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
1734 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
1735 SNDRV_PCM_INFO_MMAP_VALID
| SNDRV_PCM_INFO_SYNC_START
|
1736 SNDRV_PCM_INFO_PAUSE
/* | SNDRV_PCM_INFO_RESUME */),
1737 .formats
= (SNDRV_PCM_FMTBIT_U8
| SNDRV_PCM_FMTBIT_S16_LE
|
1738 SNDRV_PCM_FMTBIT_S8
| SNDRV_PCM_FMTBIT_U16_LE
),
1739 .rates
= SNDRV_PCM_RATE_CONTINUOUS
| SNDRV_PCM_RATE_8000_48000
,
1744 .buffer_bytes_max
= (256*1024),
1745 .period_bytes_min
= 64,
1746 .period_bytes_max
= (256*1024),
1748 .periods_max
= 1024,
1753 * Capture support device description
1756 static struct snd_pcm_hardware snd_trident_capture
=
1758 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
1759 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
1760 SNDRV_PCM_INFO_MMAP_VALID
| SNDRV_PCM_INFO_SYNC_START
|
1761 SNDRV_PCM_INFO_PAUSE
/* | SNDRV_PCM_INFO_RESUME */),
1762 .formats
= (SNDRV_PCM_FMTBIT_U8
| SNDRV_PCM_FMTBIT_S16_LE
|
1763 SNDRV_PCM_FMTBIT_S8
| SNDRV_PCM_FMTBIT_U16_LE
),
1764 .rates
= SNDRV_PCM_RATE_CONTINUOUS
| SNDRV_PCM_RATE_8000_48000
,
1769 .buffer_bytes_max
= (128*1024),
1770 .period_bytes_min
= 64,
1771 .period_bytes_max
= (128*1024),
1773 .periods_max
= 1024,
1778 * Foldback capture support device description
1781 static struct snd_pcm_hardware snd_trident_foldback
=
1783 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
1784 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
1785 SNDRV_PCM_INFO_MMAP_VALID
| SNDRV_PCM_INFO_SYNC_START
|
1786 SNDRV_PCM_INFO_PAUSE
/* | SNDRV_PCM_INFO_RESUME */),
1787 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
1788 .rates
= SNDRV_PCM_RATE_48000
,
1793 .buffer_bytes_max
= (128*1024),
1794 .period_bytes_min
= 64,
1795 .period_bytes_max
= (128*1024),
1797 .periods_max
= 1024,
1802 * SPDIF playback support device description
1805 static struct snd_pcm_hardware snd_trident_spdif
=
1807 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
1808 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
1809 SNDRV_PCM_INFO_MMAP_VALID
| SNDRV_PCM_INFO_SYNC_START
|
1810 SNDRV_PCM_INFO_PAUSE
/* | SNDRV_PCM_INFO_RESUME */),
1811 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
1812 .rates
= (SNDRV_PCM_RATE_32000
| SNDRV_PCM_RATE_44100
|
1813 SNDRV_PCM_RATE_48000
),
1818 .buffer_bytes_max
= (128*1024),
1819 .period_bytes_min
= 64,
1820 .period_bytes_max
= (128*1024),
1822 .periods_max
= 1024,
1826 static struct snd_pcm_hardware snd_trident_spdif_7018
=
1828 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
1829 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
1830 SNDRV_PCM_INFO_MMAP_VALID
| SNDRV_PCM_INFO_SYNC_START
|
1831 SNDRV_PCM_INFO_PAUSE
/* | SNDRV_PCM_INFO_RESUME */),
1832 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
1833 .rates
= SNDRV_PCM_RATE_48000
,
1838 .buffer_bytes_max
= (128*1024),
1839 .period_bytes_min
= 64,
1840 .period_bytes_max
= (128*1024),
1842 .periods_max
= 1024,
1846 static void snd_trident_pcm_free_substream(struct snd_pcm_runtime
*runtime
)
1848 struct snd_trident_voice
*voice
= runtime
->private_data
;
1849 struct snd_trident
*trident
;
1852 trident
= voice
->trident
;
1853 snd_trident_free_voice(trident
, voice
);
1857 static int snd_trident_playback_open(struct snd_pcm_substream
*substream
)
1859 struct snd_trident
*trident
= snd_pcm_substream_chip(substream
);
1860 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1861 struct snd_trident_voice
*voice
;
1863 voice
= snd_trident_alloc_voice(trident
, SNDRV_TRIDENT_VOICE_TYPE_PCM
, 0, 0);
1866 snd_trident_pcm_mixer_build(trident
, voice
, substream
);
1867 voice
->substream
= substream
;
1868 runtime
->private_data
= voice
;
1869 runtime
->private_free
= snd_trident_pcm_free_substream
;
1870 runtime
->hw
= snd_trident_playback
;
1871 snd_pcm_set_sync(substream
);
1872 snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_BUFFER_SIZE
, 0, 64*1024);
1876 /*---------------------------------------------------------------------------
1877 snd_trident_playback_close
1879 Description: This routine will close the 4DWave playback device. For now
1880 we will simply free the dma transfer buffer.
1882 Parameters: substream - PCM substream class
1884 ---------------------------------------------------------------------------*/
1885 static int snd_trident_playback_close(struct snd_pcm_substream
*substream
)
1887 struct snd_trident
*trident
= snd_pcm_substream_chip(substream
);
1888 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1889 struct snd_trident_voice
*voice
= runtime
->private_data
;
1891 snd_trident_pcm_mixer_free(trident
, voice
, substream
);
1895 /*---------------------------------------------------------------------------
1896 snd_trident_spdif_open
1898 Description: This routine will open the 4DWave SPDIF device.
1900 Parameters: substream - PCM substream class
1902 Returns: status - success or failure flag
1904 ---------------------------------------------------------------------------*/
1906 static int snd_trident_spdif_open(struct snd_pcm_substream
*substream
)
1908 struct snd_trident
*trident
= snd_pcm_substream_chip(substream
);
1909 struct snd_trident_voice
*voice
;
1910 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1912 voice
= snd_trident_alloc_voice(trident
, SNDRV_TRIDENT_VOICE_TYPE_PCM
, 0, 0);
1916 voice
->substream
= substream
;
1917 spin_lock_irq(&trident
->reg_lock
);
1918 trident
->spdif_pcm_bits
= trident
->spdif_bits
;
1919 spin_unlock_irq(&trident
->reg_lock
);
1921 runtime
->private_data
= voice
;
1922 runtime
->private_free
= snd_trident_pcm_free_substream
;
1923 if (trident
->device
== TRIDENT_DEVICE_ID_SI7018
) {
1924 runtime
->hw
= snd_trident_spdif
;
1926 runtime
->hw
= snd_trident_spdif_7018
;
1929 trident
->spdif_pcm_ctl
->vd
[0].access
&= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE
;
1930 snd_ctl_notify(trident
->card
, SNDRV_CTL_EVENT_MASK_VALUE
|
1931 SNDRV_CTL_EVENT_MASK_INFO
, &trident
->spdif_pcm_ctl
->id
);
1933 snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_BUFFER_SIZE
, 0, 64*1024);
1938 /*---------------------------------------------------------------------------
1939 snd_trident_spdif_close
1941 Description: This routine will close the 4DWave SPDIF device.
1943 Parameters: substream - PCM substream class
1945 ---------------------------------------------------------------------------*/
1947 static int snd_trident_spdif_close(struct snd_pcm_substream
*substream
)
1949 struct snd_trident
*trident
= snd_pcm_substream_chip(substream
);
1952 spin_lock_irq(&trident
->reg_lock
);
1953 // restore default SPDIF setting
1954 if (trident
->device
!= TRIDENT_DEVICE_ID_SI7018
) {
1955 outb(trident
->spdif_ctrl
, TRID_REG(trident
, NX_SPCTRL_SPCSO
+ 3));
1956 outl(trident
->spdif_bits
, TRID_REG(trident
, NX_SPCSTATUS
));
1958 outl(trident
->spdif_bits
, TRID_REG(trident
, SI_SPDIF_CS
));
1959 temp
= inl(TRID_REG(trident
, SI_SERIAL_INTF_CTRL
));
1960 if (trident
->spdif_ctrl
) {
1965 outl(temp
, TRID_REG(trident
, SI_SERIAL_INTF_CTRL
));
1967 spin_unlock_irq(&trident
->reg_lock
);
1968 trident
->spdif_pcm_ctl
->vd
[0].access
|= SNDRV_CTL_ELEM_ACCESS_INACTIVE
;
1969 snd_ctl_notify(trident
->card
, SNDRV_CTL_EVENT_MASK_VALUE
|
1970 SNDRV_CTL_EVENT_MASK_INFO
, &trident
->spdif_pcm_ctl
->id
);
1974 /*---------------------------------------------------------------------------
1975 snd_trident_capture_open
1977 Description: This routine will open the 4DWave capture device.
1979 Parameters: substream - PCM substream class
1981 Returns: status - success or failure flag
1983 ---------------------------------------------------------------------------*/
1985 static int snd_trident_capture_open(struct snd_pcm_substream
*substream
)
1987 struct snd_trident
*trident
= snd_pcm_substream_chip(substream
);
1988 struct snd_trident_voice
*voice
;
1989 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1991 voice
= snd_trident_alloc_voice(trident
, SNDRV_TRIDENT_VOICE_TYPE_PCM
, 0, 0);
1995 voice
->substream
= substream
;
1996 runtime
->private_data
= voice
;
1997 runtime
->private_free
= snd_trident_pcm_free_substream
;
1998 runtime
->hw
= snd_trident_capture
;
1999 snd_pcm_set_sync(substream
);
2000 snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_BUFFER_SIZE
, 0, 64*1024);
2004 /*---------------------------------------------------------------------------
2005 snd_trident_capture_close
2007 Description: This routine will close the 4DWave capture device. For now
2008 we will simply free the dma transfer buffer.
2010 Parameters: substream - PCM substream class
2012 ---------------------------------------------------------------------------*/
2013 static int snd_trident_capture_close(struct snd_pcm_substream
*substream
)
2018 /*---------------------------------------------------------------------------
2019 snd_trident_foldback_open
2021 Description: This routine will open the 4DWave foldback capture device.
2023 Parameters: substream - PCM substream class
2025 Returns: status - success or failure flag
2027 ---------------------------------------------------------------------------*/
2029 static int snd_trident_foldback_open(struct snd_pcm_substream
*substream
)
2031 struct snd_trident
*trident
= snd_pcm_substream_chip(substream
);
2032 struct snd_trident_voice
*voice
;
2033 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2035 voice
= snd_trident_alloc_voice(trident
, SNDRV_TRIDENT_VOICE_TYPE_PCM
, 0, 0);
2038 voice
->foldback_chan
= substream
->number
;
2039 voice
->substream
= substream
;
2040 runtime
->private_data
= voice
;
2041 runtime
->private_free
= snd_trident_pcm_free_substream
;
2042 runtime
->hw
= snd_trident_foldback
;
2043 snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_BUFFER_SIZE
, 0, 64*1024);
2047 /*---------------------------------------------------------------------------
2048 snd_trident_foldback_close
2050 Description: This routine will close the 4DWave foldback capture device.
2051 For now we will simply free the dma transfer buffer.
2053 Parameters: substream - PCM substream class
2055 ---------------------------------------------------------------------------*/
2056 static int snd_trident_foldback_close(struct snd_pcm_substream
*substream
)
2058 struct snd_trident
*trident
= snd_pcm_substream_chip(substream
);
2059 struct snd_trident_voice
*voice
;
2060 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2061 voice
= runtime
->private_data
;
2063 /* stop capture channel */
2064 spin_lock_irq(&trident
->reg_lock
);
2065 outb(0x00, TRID_REG(trident
, T4D_RCI
+ voice
->foldback_chan
));
2066 spin_unlock_irq(&trident
->reg_lock
);
2070 /*---------------------------------------------------------------------------
2072 ---------------------------------------------------------------------------*/
2074 static struct snd_pcm_ops snd_trident_playback_ops
= {
2075 .open
= snd_trident_playback_open
,
2076 .close
= snd_trident_playback_close
,
2077 .ioctl
= snd_trident_ioctl
,
2078 .hw_params
= snd_trident_hw_params
,
2079 .hw_free
= snd_trident_hw_free
,
2080 .prepare
= snd_trident_playback_prepare
,
2081 .trigger
= snd_trident_trigger
,
2082 .pointer
= snd_trident_playback_pointer
,
2085 static struct snd_pcm_ops snd_trident_nx_playback_ops
= {
2086 .open
= snd_trident_playback_open
,
2087 .close
= snd_trident_playback_close
,
2088 .ioctl
= snd_trident_ioctl
,
2089 .hw_params
= snd_trident_hw_params
,
2090 .hw_free
= snd_trident_hw_free
,
2091 .prepare
= snd_trident_playback_prepare
,
2092 .trigger
= snd_trident_trigger
,
2093 .pointer
= snd_trident_playback_pointer
,
2094 .page
= snd_pcm_sgbuf_ops_page
,
2097 static struct snd_pcm_ops snd_trident_capture_ops
= {
2098 .open
= snd_trident_capture_open
,
2099 .close
= snd_trident_capture_close
,
2100 .ioctl
= snd_trident_ioctl
,
2101 .hw_params
= snd_trident_capture_hw_params
,
2102 .hw_free
= snd_trident_hw_free
,
2103 .prepare
= snd_trident_capture_prepare
,
2104 .trigger
= snd_trident_trigger
,
2105 .pointer
= snd_trident_capture_pointer
,
2108 static struct snd_pcm_ops snd_trident_si7018_capture_ops
= {
2109 .open
= snd_trident_capture_open
,
2110 .close
= snd_trident_capture_close
,
2111 .ioctl
= snd_trident_ioctl
,
2112 .hw_params
= snd_trident_si7018_capture_hw_params
,
2113 .hw_free
= snd_trident_si7018_capture_hw_free
,
2114 .prepare
= snd_trident_si7018_capture_prepare
,
2115 .trigger
= snd_trident_trigger
,
2116 .pointer
= snd_trident_playback_pointer
,
2119 static struct snd_pcm_ops snd_trident_foldback_ops
= {
2120 .open
= snd_trident_foldback_open
,
2121 .close
= snd_trident_foldback_close
,
2122 .ioctl
= snd_trident_ioctl
,
2123 .hw_params
= snd_trident_hw_params
,
2124 .hw_free
= snd_trident_hw_free
,
2125 .prepare
= snd_trident_foldback_prepare
,
2126 .trigger
= snd_trident_trigger
,
2127 .pointer
= snd_trident_playback_pointer
,
2130 static struct snd_pcm_ops snd_trident_nx_foldback_ops
= {
2131 .open
= snd_trident_foldback_open
,
2132 .close
= snd_trident_foldback_close
,
2133 .ioctl
= snd_trident_ioctl
,
2134 .hw_params
= snd_trident_hw_params
,
2135 .hw_free
= snd_trident_hw_free
,
2136 .prepare
= snd_trident_foldback_prepare
,
2137 .trigger
= snd_trident_trigger
,
2138 .pointer
= snd_trident_playback_pointer
,
2139 .page
= snd_pcm_sgbuf_ops_page
,
2142 static struct snd_pcm_ops snd_trident_spdif_ops
= {
2143 .open
= snd_trident_spdif_open
,
2144 .close
= snd_trident_spdif_close
,
2145 .ioctl
= snd_trident_ioctl
,
2146 .hw_params
= snd_trident_spdif_hw_params
,
2147 .hw_free
= snd_trident_hw_free
,
2148 .prepare
= snd_trident_spdif_prepare
,
2149 .trigger
= snd_trident_trigger
,
2150 .pointer
= snd_trident_spdif_pointer
,
2153 static struct snd_pcm_ops snd_trident_spdif_7018_ops
= {
2154 .open
= snd_trident_spdif_open
,
2155 .close
= snd_trident_spdif_close
,
2156 .ioctl
= snd_trident_ioctl
,
2157 .hw_params
= snd_trident_spdif_hw_params
,
2158 .hw_free
= snd_trident_hw_free
,
2159 .prepare
= snd_trident_spdif_prepare
,
2160 .trigger
= snd_trident_trigger
,
2161 .pointer
= snd_trident_playback_pointer
,
2164 /*---------------------------------------------------------------------------
2167 Description: This routine registers the 4DWave device for PCM support.
2169 Parameters: trident - pointer to target device class for 4DWave.
2173 ---------------------------------------------------------------------------*/
2175 int snd_trident_pcm(struct snd_trident
*trident
,
2176 int device
, struct snd_pcm
**rpcm
)
2178 struct snd_pcm
*pcm
;
2183 if ((err
= snd_pcm_new(trident
->card
, "trident_dx_nx", device
, trident
->ChanPCM
, 1, &pcm
)) < 0)
2186 pcm
->private_data
= trident
;
2188 if (trident
->tlb
.entries
) {
2189 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_trident_nx_playback_ops
);
2191 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_trident_playback_ops
);
2193 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
,
2194 trident
->device
!= TRIDENT_DEVICE_ID_SI7018
?
2195 &snd_trident_capture_ops
:
2196 &snd_trident_si7018_capture_ops
);
2198 pcm
->info_flags
= 0;
2199 pcm
->dev_subclass
= SNDRV_PCM_SUBCLASS_GENERIC_MIX
;
2200 strcpy(pcm
->name
, "Trident 4DWave");
2203 if (trident
->tlb
.entries
) {
2204 struct snd_pcm_substream
*substream
;
2205 for (substream
= pcm
->streams
[SNDRV_PCM_STREAM_PLAYBACK
].substream
; substream
; substream
= substream
->next
)
2206 snd_pcm_lib_preallocate_pages(substream
, SNDRV_DMA_TYPE_DEV_SG
,
2207 snd_dma_pci_data(trident
->pci
),
2209 snd_pcm_lib_preallocate_pages(pcm
->streams
[SNDRV_PCM_STREAM_CAPTURE
].substream
,
2210 SNDRV_DMA_TYPE_DEV
, snd_dma_pci_data(trident
->pci
),
2213 snd_pcm_lib_preallocate_pages_for_all(pcm
, SNDRV_DMA_TYPE_DEV
,
2214 snd_dma_pci_data(trident
->pci
), 64*1024, 128*1024);
2222 /*---------------------------------------------------------------------------
2223 snd_trident_foldback_pcm
2225 Description: This routine registers the 4DWave device for foldback PCM support.
2227 Parameters: trident - pointer to target device class for 4DWave.
2231 ---------------------------------------------------------------------------*/
2233 int snd_trident_foldback_pcm(struct snd_trident
*trident
,
2234 int device
, struct snd_pcm
**rpcm
)
2236 struct snd_pcm
*foldback
;
2239 struct snd_pcm_substream
*substream
;
2243 if (trident
->device
== TRIDENT_DEVICE_ID_NX
)
2245 if ((err
= snd_pcm_new(trident
->card
, "trident_dx_nx", device
, 0, num_chan
, &foldback
)) < 0)
2248 foldback
->private_data
= trident
;
2249 if (trident
->tlb
.entries
)
2250 snd_pcm_set_ops(foldback
, SNDRV_PCM_STREAM_CAPTURE
, &snd_trident_nx_foldback_ops
);
2252 snd_pcm_set_ops(foldback
, SNDRV_PCM_STREAM_CAPTURE
, &snd_trident_foldback_ops
);
2253 foldback
->info_flags
= 0;
2254 strcpy(foldback
->name
, "Trident 4DWave");
2255 substream
= foldback
->streams
[SNDRV_PCM_STREAM_CAPTURE
].substream
;
2256 strcpy(substream
->name
, "Front Mixer");
2257 substream
= substream
->next
;
2258 strcpy(substream
->name
, "Reverb Mixer");
2259 substream
= substream
->next
;
2260 strcpy(substream
->name
, "Chorus Mixer");
2261 if (num_chan
== 4) {
2262 substream
= substream
->next
;
2263 strcpy(substream
->name
, "Second AC'97 ADC");
2265 trident
->foldback
= foldback
;
2267 if (trident
->tlb
.entries
)
2268 snd_pcm_lib_preallocate_pages_for_all(foldback
, SNDRV_DMA_TYPE_DEV_SG
,
2269 snd_dma_pci_data(trident
->pci
), 0, 128*1024);
2271 snd_pcm_lib_preallocate_pages_for_all(foldback
, SNDRV_DMA_TYPE_DEV
,
2272 snd_dma_pci_data(trident
->pci
), 64*1024, 128*1024);
2279 /*---------------------------------------------------------------------------
2282 Description: This routine registers the 4DWave-NX device for SPDIF support.
2284 Parameters: trident - pointer to target device class for 4DWave-NX.
2288 ---------------------------------------------------------------------------*/
2290 int snd_trident_spdif_pcm(struct snd_trident
*trident
,
2291 int device
, struct snd_pcm
**rpcm
)
2293 struct snd_pcm
*spdif
;
2298 if ((err
= snd_pcm_new(trident
->card
, "trident_dx_nx IEC958", device
, 1, 0, &spdif
)) < 0)
2301 spdif
->private_data
= trident
;
2302 if (trident
->device
!= TRIDENT_DEVICE_ID_SI7018
) {
2303 snd_pcm_set_ops(spdif
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_trident_spdif_ops
);
2305 snd_pcm_set_ops(spdif
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_trident_spdif_7018_ops
);
2307 spdif
->info_flags
= 0;
2308 strcpy(spdif
->name
, "Trident 4DWave IEC958");
2309 trident
->spdif
= spdif
;
2311 snd_pcm_lib_preallocate_pages_for_all(spdif
, SNDRV_DMA_TYPE_DEV
, snd_dma_pci_data(trident
->pci
), 64*1024, 128*1024);
2323 /*---------------------------------------------------------------------------
2324 snd_trident_spdif_control
2326 Description: enable/disable S/PDIF out from ac97 mixer
2327 ---------------------------------------------------------------------------*/
2329 #define snd_trident_spdif_control_info snd_ctl_boolean_mono_info
2331 static int snd_trident_spdif_control_get(struct snd_kcontrol
*kcontrol
,
2332 struct snd_ctl_elem_value
*ucontrol
)
2334 struct snd_trident
*trident
= snd_kcontrol_chip(kcontrol
);
2337 spin_lock_irq(&trident
->reg_lock
);
2338 val
= trident
->spdif_ctrl
;
2339 ucontrol
->value
.integer
.value
[0] = val
== kcontrol
->private_value
;
2340 spin_unlock_irq(&trident
->reg_lock
);
2344 static int snd_trident_spdif_control_put(struct snd_kcontrol
*kcontrol
,
2345 struct snd_ctl_elem_value
*ucontrol
)
2347 struct snd_trident
*trident
= snd_kcontrol_chip(kcontrol
);
2351 val
= ucontrol
->value
.integer
.value
[0] ? (unsigned char) kcontrol
->private_value
: 0x00;
2352 spin_lock_irq(&trident
->reg_lock
);
2353 /* S/PDIF C Channel bits 0-31 : 48khz, SCMS disabled */
2354 change
= trident
->spdif_ctrl
!= val
;
2355 trident
->spdif_ctrl
= val
;
2356 if (trident
->device
!= TRIDENT_DEVICE_ID_SI7018
) {
2357 if ((inb(TRID_REG(trident
, NX_SPCTRL_SPCSO
+ 3)) & 0x10) == 0) {
2358 outl(trident
->spdif_bits
, TRID_REG(trident
, NX_SPCSTATUS
));
2359 outb(trident
->spdif_ctrl
, TRID_REG(trident
, NX_SPCTRL_SPCSO
+ 3));
2362 if (trident
->spdif
== NULL
) {
2364 outl(trident
->spdif_bits
, TRID_REG(trident
, SI_SPDIF_CS
));
2365 temp
= inl(TRID_REG(trident
, SI_SERIAL_INTF_CTRL
)) & ~SPDIF_EN
;
2368 outl(temp
, TRID_REG(trident
, SI_SERIAL_INTF_CTRL
));
2371 spin_unlock_irq(&trident
->reg_lock
);
2375 static struct snd_kcontrol_new snd_trident_spdif_control
=
2377 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2378 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,SWITCH
),
2379 .info
= snd_trident_spdif_control_info
,
2380 .get
= snd_trident_spdif_control_get
,
2381 .put
= snd_trident_spdif_control_put
,
2382 .private_value
= 0x28,
2385 /*---------------------------------------------------------------------------
2386 snd_trident_spdif_default
2388 Description: put/get the S/PDIF default settings
2389 ---------------------------------------------------------------------------*/
2391 static int snd_trident_spdif_default_info(struct snd_kcontrol
*kcontrol
,
2392 struct snd_ctl_elem_info
*uinfo
)
2394 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_IEC958
;
2399 static int snd_trident_spdif_default_get(struct snd_kcontrol
*kcontrol
,
2400 struct snd_ctl_elem_value
*ucontrol
)
2402 struct snd_trident
*trident
= snd_kcontrol_chip(kcontrol
);
2404 spin_lock_irq(&trident
->reg_lock
);
2405 ucontrol
->value
.iec958
.status
[0] = (trident
->spdif_bits
>> 0) & 0xff;
2406 ucontrol
->value
.iec958
.status
[1] = (trident
->spdif_bits
>> 8) & 0xff;
2407 ucontrol
->value
.iec958
.status
[2] = (trident
->spdif_bits
>> 16) & 0xff;
2408 ucontrol
->value
.iec958
.status
[3] = (trident
->spdif_bits
>> 24) & 0xff;
2409 spin_unlock_irq(&trident
->reg_lock
);
2413 static int snd_trident_spdif_default_put(struct snd_kcontrol
*kcontrol
,
2414 struct snd_ctl_elem_value
*ucontrol
)
2416 struct snd_trident
*trident
= snd_kcontrol_chip(kcontrol
);
2420 val
= (ucontrol
->value
.iec958
.status
[0] << 0) |
2421 (ucontrol
->value
.iec958
.status
[1] << 8) |
2422 (ucontrol
->value
.iec958
.status
[2] << 16) |
2423 (ucontrol
->value
.iec958
.status
[3] << 24);
2424 spin_lock_irq(&trident
->reg_lock
);
2425 change
= trident
->spdif_bits
!= val
;
2426 trident
->spdif_bits
= val
;
2427 if (trident
->device
!= TRIDENT_DEVICE_ID_SI7018
) {
2428 if ((inb(TRID_REG(trident
, NX_SPCTRL_SPCSO
+ 3)) & 0x10) == 0)
2429 outl(trident
->spdif_bits
, TRID_REG(trident
, NX_SPCSTATUS
));
2431 if (trident
->spdif
== NULL
)
2432 outl(trident
->spdif_bits
, TRID_REG(trident
, SI_SPDIF_CS
));
2434 spin_unlock_irq(&trident
->reg_lock
);
2438 static struct snd_kcontrol_new snd_trident_spdif_default
=
2440 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
2441 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,DEFAULT
),
2442 .info
= snd_trident_spdif_default_info
,
2443 .get
= snd_trident_spdif_default_get
,
2444 .put
= snd_trident_spdif_default_put
2447 /*---------------------------------------------------------------------------
2448 snd_trident_spdif_mask
2450 Description: put/get the S/PDIF mask
2451 ---------------------------------------------------------------------------*/
2453 static int snd_trident_spdif_mask_info(struct snd_kcontrol
*kcontrol
,
2454 struct snd_ctl_elem_info
*uinfo
)
2456 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_IEC958
;
2461 static int snd_trident_spdif_mask_get(struct snd_kcontrol
*kcontrol
,
2462 struct snd_ctl_elem_value
*ucontrol
)
2464 ucontrol
->value
.iec958
.status
[0] = 0xff;
2465 ucontrol
->value
.iec958
.status
[1] = 0xff;
2466 ucontrol
->value
.iec958
.status
[2] = 0xff;
2467 ucontrol
->value
.iec958
.status
[3] = 0xff;
2471 static struct snd_kcontrol_new snd_trident_spdif_mask
=
2473 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
2474 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
2475 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,MASK
),
2476 .info
= snd_trident_spdif_mask_info
,
2477 .get
= snd_trident_spdif_mask_get
,
2480 /*---------------------------------------------------------------------------
2481 snd_trident_spdif_stream
2483 Description: put/get the S/PDIF stream settings
2484 ---------------------------------------------------------------------------*/
2486 static int snd_trident_spdif_stream_info(struct snd_kcontrol
*kcontrol
,
2487 struct snd_ctl_elem_info
*uinfo
)
2489 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_IEC958
;
2494 static int snd_trident_spdif_stream_get(struct snd_kcontrol
*kcontrol
,
2495 struct snd_ctl_elem_value
*ucontrol
)
2497 struct snd_trident
*trident
= snd_kcontrol_chip(kcontrol
);
2499 spin_lock_irq(&trident
->reg_lock
);
2500 ucontrol
->value
.iec958
.status
[0] = (trident
->spdif_pcm_bits
>> 0) & 0xff;
2501 ucontrol
->value
.iec958
.status
[1] = (trident
->spdif_pcm_bits
>> 8) & 0xff;
2502 ucontrol
->value
.iec958
.status
[2] = (trident
->spdif_pcm_bits
>> 16) & 0xff;
2503 ucontrol
->value
.iec958
.status
[3] = (trident
->spdif_pcm_bits
>> 24) & 0xff;
2504 spin_unlock_irq(&trident
->reg_lock
);
2508 static int snd_trident_spdif_stream_put(struct snd_kcontrol
*kcontrol
,
2509 struct snd_ctl_elem_value
*ucontrol
)
2511 struct snd_trident
*trident
= snd_kcontrol_chip(kcontrol
);
2515 val
= (ucontrol
->value
.iec958
.status
[0] << 0) |
2516 (ucontrol
->value
.iec958
.status
[1] << 8) |
2517 (ucontrol
->value
.iec958
.status
[2] << 16) |
2518 (ucontrol
->value
.iec958
.status
[3] << 24);
2519 spin_lock_irq(&trident
->reg_lock
);
2520 change
= trident
->spdif_pcm_bits
!= val
;
2521 trident
->spdif_pcm_bits
= val
;
2522 if (trident
->spdif
!= NULL
) {
2523 if (trident
->device
!= TRIDENT_DEVICE_ID_SI7018
) {
2524 outl(trident
->spdif_pcm_bits
, TRID_REG(trident
, NX_SPCSTATUS
));
2526 outl(trident
->spdif_bits
, TRID_REG(trident
, SI_SPDIF_CS
));
2529 spin_unlock_irq(&trident
->reg_lock
);
2533 static struct snd_kcontrol_new snd_trident_spdif_stream
=
2535 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
| SNDRV_CTL_ELEM_ACCESS_INACTIVE
,
2536 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
2537 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,PCM_STREAM
),
2538 .info
= snd_trident_spdif_stream_info
,
2539 .get
= snd_trident_spdif_stream_get
,
2540 .put
= snd_trident_spdif_stream_put
2543 /*---------------------------------------------------------------------------
2544 snd_trident_ac97_control
2546 Description: enable/disable rear path for ac97
2547 ---------------------------------------------------------------------------*/
2549 #define snd_trident_ac97_control_info snd_ctl_boolean_mono_info
2551 static int snd_trident_ac97_control_get(struct snd_kcontrol
*kcontrol
,
2552 struct snd_ctl_elem_value
*ucontrol
)
2554 struct snd_trident
*trident
= snd_kcontrol_chip(kcontrol
);
2557 spin_lock_irq(&trident
->reg_lock
);
2558 val
= trident
->ac97_ctrl
= inl(TRID_REG(trident
, NX_ACR0_AC97_COM_STAT
));
2559 ucontrol
->value
.integer
.value
[0] = (val
& (1 << kcontrol
->private_value
)) ? 1 : 0;
2560 spin_unlock_irq(&trident
->reg_lock
);
2564 static int snd_trident_ac97_control_put(struct snd_kcontrol
*kcontrol
,
2565 struct snd_ctl_elem_value
*ucontrol
)
2567 struct snd_trident
*trident
= snd_kcontrol_chip(kcontrol
);
2571 spin_lock_irq(&trident
->reg_lock
);
2572 val
= trident
->ac97_ctrl
= inl(TRID_REG(trident
, NX_ACR0_AC97_COM_STAT
));
2573 val
&= ~(1 << kcontrol
->private_value
);
2574 if (ucontrol
->value
.integer
.value
[0])
2575 val
|= 1 << kcontrol
->private_value
;
2576 change
= val
!= trident
->ac97_ctrl
;
2577 trident
->ac97_ctrl
= val
;
2578 outl(trident
->ac97_ctrl
= val
, TRID_REG(trident
, NX_ACR0_AC97_COM_STAT
));
2579 spin_unlock_irq(&trident
->reg_lock
);
2583 static struct snd_kcontrol_new snd_trident_ac97_rear_control
=
2585 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2586 .name
= "Rear Path",
2587 .info
= snd_trident_ac97_control_info
,
2588 .get
= snd_trident_ac97_control_get
,
2589 .put
= snd_trident_ac97_control_put
,
2593 /*---------------------------------------------------------------------------
2594 snd_trident_vol_control
2596 Description: wave & music volume control
2597 ---------------------------------------------------------------------------*/
2599 static int snd_trident_vol_control_info(struct snd_kcontrol
*kcontrol
,
2600 struct snd_ctl_elem_info
*uinfo
)
2602 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2604 uinfo
->value
.integer
.min
= 0;
2605 uinfo
->value
.integer
.max
= 255;
2609 static int snd_trident_vol_control_get(struct snd_kcontrol
*kcontrol
,
2610 struct snd_ctl_elem_value
*ucontrol
)
2612 struct snd_trident
*trident
= snd_kcontrol_chip(kcontrol
);
2615 val
= trident
->musicvol_wavevol
;
2616 ucontrol
->value
.integer
.value
[0] = 255 - ((val
>> kcontrol
->private_value
) & 0xff);
2617 ucontrol
->value
.integer
.value
[1] = 255 - ((val
>> (kcontrol
->private_value
+ 8)) & 0xff);
2621 static const DECLARE_TLV_DB_SCALE(db_scale_gvol
, -6375, 25, 0);
2623 static int snd_trident_vol_control_put(struct snd_kcontrol
*kcontrol
,
2624 struct snd_ctl_elem_value
*ucontrol
)
2626 struct snd_trident
*trident
= snd_kcontrol_chip(kcontrol
);
2630 spin_lock_irq(&trident
->reg_lock
);
2631 val
= trident
->musicvol_wavevol
;
2632 val
&= ~(0xffff << kcontrol
->private_value
);
2633 val
|= ((255 - (ucontrol
->value
.integer
.value
[0] & 0xff)) |
2634 ((255 - (ucontrol
->value
.integer
.value
[1] & 0xff)) << 8)) << kcontrol
->private_value
;
2635 change
= val
!= trident
->musicvol_wavevol
;
2636 outl(trident
->musicvol_wavevol
= val
, TRID_REG(trident
, T4D_MUSICVOL_WAVEVOL
));
2637 spin_unlock_irq(&trident
->reg_lock
);
2641 static struct snd_kcontrol_new snd_trident_vol_music_control
=
2643 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2644 .name
= "Music Playback Volume",
2645 .info
= snd_trident_vol_control_info
,
2646 .get
= snd_trident_vol_control_get
,
2647 .put
= snd_trident_vol_control_put
,
2648 .private_value
= 16,
2649 .tlv
= { .p
= db_scale_gvol
},
2652 static struct snd_kcontrol_new snd_trident_vol_wave_control
=
2654 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2655 .name
= "Wave Playback Volume",
2656 .info
= snd_trident_vol_control_info
,
2657 .get
= snd_trident_vol_control_get
,
2658 .put
= snd_trident_vol_control_put
,
2660 .tlv
= { .p
= db_scale_gvol
},
2663 /*---------------------------------------------------------------------------
2664 snd_trident_pcm_vol_control
2666 Description: PCM front volume control
2667 ---------------------------------------------------------------------------*/
2669 static int snd_trident_pcm_vol_control_info(struct snd_kcontrol
*kcontrol
,
2670 struct snd_ctl_elem_info
*uinfo
)
2672 struct snd_trident
*trident
= snd_kcontrol_chip(kcontrol
);
2674 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2676 uinfo
->value
.integer
.min
= 0;
2677 uinfo
->value
.integer
.max
= 255;
2678 if (trident
->device
== TRIDENT_DEVICE_ID_SI7018
)
2679 uinfo
->value
.integer
.max
= 1023;
2683 static int snd_trident_pcm_vol_control_get(struct snd_kcontrol
*kcontrol
,
2684 struct snd_ctl_elem_value
*ucontrol
)
2686 struct snd_trident
*trident
= snd_kcontrol_chip(kcontrol
);
2687 struct snd_trident_pcm_mixer
*mix
= &trident
->pcm_mixer
[snd_ctl_get_ioffnum(kcontrol
, &ucontrol
->id
)];
2689 if (trident
->device
== TRIDENT_DEVICE_ID_SI7018
) {
2690 ucontrol
->value
.integer
.value
[0] = 1023 - mix
->vol
;
2692 ucontrol
->value
.integer
.value
[0] = 255 - (mix
->vol
>>2);
2697 static int snd_trident_pcm_vol_control_put(struct snd_kcontrol
*kcontrol
,
2698 struct snd_ctl_elem_value
*ucontrol
)
2700 struct snd_trident
*trident
= snd_kcontrol_chip(kcontrol
);
2701 struct snd_trident_pcm_mixer
*mix
= &trident
->pcm_mixer
[snd_ctl_get_ioffnum(kcontrol
, &ucontrol
->id
)];
2705 if (trident
->device
== TRIDENT_DEVICE_ID_SI7018
) {
2706 val
= 1023 - (ucontrol
->value
.integer
.value
[0] & 1023);
2708 val
= (255 - (ucontrol
->value
.integer
.value
[0] & 255)) << 2;
2710 spin_lock_irq(&trident
->reg_lock
);
2711 change
= val
!= mix
->vol
;
2713 if (mix
->voice
!= NULL
)
2714 snd_trident_write_vol_reg(trident
, mix
->voice
, val
);
2715 spin_unlock_irq(&trident
->reg_lock
);
2719 static struct snd_kcontrol_new snd_trident_pcm_vol_control
=
2721 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2722 .name
= "PCM Front Playback Volume",
2723 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
| SNDRV_CTL_ELEM_ACCESS_INACTIVE
,
2725 .info
= snd_trident_pcm_vol_control_info
,
2726 .get
= snd_trident_pcm_vol_control_get
,
2727 .put
= snd_trident_pcm_vol_control_put
,
2728 /* FIXME: no tlv yet */
2731 /*---------------------------------------------------------------------------
2732 snd_trident_pcm_pan_control
2734 Description: PCM front pan control
2735 ---------------------------------------------------------------------------*/
2737 static int snd_trident_pcm_pan_control_info(struct snd_kcontrol
*kcontrol
,
2738 struct snd_ctl_elem_info
*uinfo
)
2740 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2742 uinfo
->value
.integer
.min
= 0;
2743 uinfo
->value
.integer
.max
= 127;
2747 static int snd_trident_pcm_pan_control_get(struct snd_kcontrol
*kcontrol
,
2748 struct snd_ctl_elem_value
*ucontrol
)
2750 struct snd_trident
*trident
= snd_kcontrol_chip(kcontrol
);
2751 struct snd_trident_pcm_mixer
*mix
= &trident
->pcm_mixer
[snd_ctl_get_ioffnum(kcontrol
, &ucontrol
->id
)];
2753 ucontrol
->value
.integer
.value
[0] = mix
->pan
;
2754 if (ucontrol
->value
.integer
.value
[0] & 0x40) {
2755 ucontrol
->value
.integer
.value
[0] = (0x3f - (ucontrol
->value
.integer
.value
[0] & 0x3f));
2757 ucontrol
->value
.integer
.value
[0] |= 0x40;
2762 static int snd_trident_pcm_pan_control_put(struct snd_kcontrol
*kcontrol
,
2763 struct snd_ctl_elem_value
*ucontrol
)
2765 struct snd_trident
*trident
= snd_kcontrol_chip(kcontrol
);
2766 struct snd_trident_pcm_mixer
*mix
= &trident
->pcm_mixer
[snd_ctl_get_ioffnum(kcontrol
, &ucontrol
->id
)];
2770 if (ucontrol
->value
.integer
.value
[0] & 0x40)
2771 val
= ucontrol
->value
.integer
.value
[0] & 0x3f;
2773 val
= (0x3f - (ucontrol
->value
.integer
.value
[0] & 0x3f)) | 0x40;
2774 spin_lock_irq(&trident
->reg_lock
);
2775 change
= val
!= mix
->pan
;
2777 if (mix
->voice
!= NULL
)
2778 snd_trident_write_pan_reg(trident
, mix
->voice
, val
);
2779 spin_unlock_irq(&trident
->reg_lock
);
2783 static struct snd_kcontrol_new snd_trident_pcm_pan_control
=
2785 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2786 .name
= "PCM Pan Playback Control",
2787 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
| SNDRV_CTL_ELEM_ACCESS_INACTIVE
,
2789 .info
= snd_trident_pcm_pan_control_info
,
2790 .get
= snd_trident_pcm_pan_control_get
,
2791 .put
= snd_trident_pcm_pan_control_put
,
2794 /*---------------------------------------------------------------------------
2795 snd_trident_pcm_rvol_control
2797 Description: PCM reverb volume control
2798 ---------------------------------------------------------------------------*/
2800 static int snd_trident_pcm_rvol_control_info(struct snd_kcontrol
*kcontrol
,
2801 struct snd_ctl_elem_info
*uinfo
)
2803 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2805 uinfo
->value
.integer
.min
= 0;
2806 uinfo
->value
.integer
.max
= 127;
2810 static int snd_trident_pcm_rvol_control_get(struct snd_kcontrol
*kcontrol
,
2811 struct snd_ctl_elem_value
*ucontrol
)
2813 struct snd_trident
*trident
= snd_kcontrol_chip(kcontrol
);
2814 struct snd_trident_pcm_mixer
*mix
= &trident
->pcm_mixer
[snd_ctl_get_ioffnum(kcontrol
, &ucontrol
->id
)];
2816 ucontrol
->value
.integer
.value
[0] = 127 - mix
->rvol
;
2820 static int snd_trident_pcm_rvol_control_put(struct snd_kcontrol
*kcontrol
,
2821 struct snd_ctl_elem_value
*ucontrol
)
2823 struct snd_trident
*trident
= snd_kcontrol_chip(kcontrol
);
2824 struct snd_trident_pcm_mixer
*mix
= &trident
->pcm_mixer
[snd_ctl_get_ioffnum(kcontrol
, &ucontrol
->id
)];
2828 val
= 0x7f - (ucontrol
->value
.integer
.value
[0] & 0x7f);
2829 spin_lock_irq(&trident
->reg_lock
);
2830 change
= val
!= mix
->rvol
;
2832 if (mix
->voice
!= NULL
)
2833 snd_trident_write_rvol_reg(trident
, mix
->voice
, val
);
2834 spin_unlock_irq(&trident
->reg_lock
);
2838 static const DECLARE_TLV_DB_SCALE(db_scale_crvol
, -3175, 25, 1);
2840 static struct snd_kcontrol_new snd_trident_pcm_rvol_control
=
2842 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2843 .name
= "PCM Reverb Playback Volume",
2844 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
| SNDRV_CTL_ELEM_ACCESS_INACTIVE
,
2846 .info
= snd_trident_pcm_rvol_control_info
,
2847 .get
= snd_trident_pcm_rvol_control_get
,
2848 .put
= snd_trident_pcm_rvol_control_put
,
2849 .tlv
= { .p
= db_scale_crvol
},
2852 /*---------------------------------------------------------------------------
2853 snd_trident_pcm_cvol_control
2855 Description: PCM chorus volume control
2856 ---------------------------------------------------------------------------*/
2858 static int snd_trident_pcm_cvol_control_info(struct snd_kcontrol
*kcontrol
,
2859 struct snd_ctl_elem_info
*uinfo
)
2861 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2863 uinfo
->value
.integer
.min
= 0;
2864 uinfo
->value
.integer
.max
= 127;
2868 static int snd_trident_pcm_cvol_control_get(struct snd_kcontrol
*kcontrol
,
2869 struct snd_ctl_elem_value
*ucontrol
)
2871 struct snd_trident
*trident
= snd_kcontrol_chip(kcontrol
);
2872 struct snd_trident_pcm_mixer
*mix
= &trident
->pcm_mixer
[snd_ctl_get_ioffnum(kcontrol
, &ucontrol
->id
)];
2874 ucontrol
->value
.integer
.value
[0] = 127 - mix
->cvol
;
2878 static int snd_trident_pcm_cvol_control_put(struct snd_kcontrol
*kcontrol
,
2879 struct snd_ctl_elem_value
*ucontrol
)
2881 struct snd_trident
*trident
= snd_kcontrol_chip(kcontrol
);
2882 struct snd_trident_pcm_mixer
*mix
= &trident
->pcm_mixer
[snd_ctl_get_ioffnum(kcontrol
, &ucontrol
->id
)];
2886 val
= 0x7f - (ucontrol
->value
.integer
.value
[0] & 0x7f);
2887 spin_lock_irq(&trident
->reg_lock
);
2888 change
= val
!= mix
->cvol
;
2890 if (mix
->voice
!= NULL
)
2891 snd_trident_write_cvol_reg(trident
, mix
->voice
, val
);
2892 spin_unlock_irq(&trident
->reg_lock
);
2896 static struct snd_kcontrol_new snd_trident_pcm_cvol_control
=
2898 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2899 .name
= "PCM Chorus Playback Volume",
2900 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
| SNDRV_CTL_ELEM_ACCESS_INACTIVE
,
2902 .info
= snd_trident_pcm_cvol_control_info
,
2903 .get
= snd_trident_pcm_cvol_control_get
,
2904 .put
= snd_trident_pcm_cvol_control_put
,
2905 .tlv
= { .p
= db_scale_crvol
},
2908 static void snd_trident_notify_pcm_change1(struct snd_card
*card
,
2909 struct snd_kcontrol
*kctl
,
2910 int num
, int activate
)
2912 struct snd_ctl_elem_id id
;
2917 kctl
->vd
[num
].access
&= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE
;
2919 kctl
->vd
[num
].access
|= SNDRV_CTL_ELEM_ACCESS_INACTIVE
;
2920 snd_ctl_notify(card
, SNDRV_CTL_EVENT_MASK_VALUE
|
2921 SNDRV_CTL_EVENT_MASK_INFO
,
2922 snd_ctl_build_ioff(&id
, kctl
, num
));
2925 static void snd_trident_notify_pcm_change(struct snd_trident
*trident
,
2926 struct snd_trident_pcm_mixer
*tmix
,
2927 int num
, int activate
)
2929 snd_trident_notify_pcm_change1(trident
->card
, trident
->ctl_vol
, num
, activate
);
2930 snd_trident_notify_pcm_change1(trident
->card
, trident
->ctl_pan
, num
, activate
);
2931 snd_trident_notify_pcm_change1(trident
->card
, trident
->ctl_rvol
, num
, activate
);
2932 snd_trident_notify_pcm_change1(trident
->card
, trident
->ctl_cvol
, num
, activate
);
2935 static int snd_trident_pcm_mixer_build(struct snd_trident
*trident
,
2936 struct snd_trident_voice
*voice
,
2937 struct snd_pcm_substream
*substream
)
2939 struct snd_trident_pcm_mixer
*tmix
;
2941 if (snd_BUG_ON(!trident
|| !voice
|| !substream
))
2943 tmix
= &trident
->pcm_mixer
[substream
->number
];
2944 tmix
->voice
= voice
;
2945 tmix
->vol
= T4D_DEFAULT_PCM_VOL
;
2946 tmix
->pan
= T4D_DEFAULT_PCM_PAN
;
2947 tmix
->rvol
= T4D_DEFAULT_PCM_RVOL
;
2948 tmix
->cvol
= T4D_DEFAULT_PCM_CVOL
;
2949 snd_trident_notify_pcm_change(trident
, tmix
, substream
->number
, 1);
2953 static int snd_trident_pcm_mixer_free(struct snd_trident
*trident
, struct snd_trident_voice
*voice
, struct snd_pcm_substream
*substream
)
2955 struct snd_trident_pcm_mixer
*tmix
;
2957 if (snd_BUG_ON(!trident
|| !substream
))
2959 tmix
= &trident
->pcm_mixer
[substream
->number
];
2961 snd_trident_notify_pcm_change(trident
, tmix
, substream
->number
, 0);
2965 /*---------------------------------------------------------------------------
2968 Description: This routine registers the 4DWave device for mixer support.
2970 Parameters: trident - pointer to target device class for 4DWave.
2974 ---------------------------------------------------------------------------*/
2976 static int snd_trident_mixer(struct snd_trident
*trident
, int pcm_spdif_device
)
2978 struct snd_ac97_template _ac97
;
2979 struct snd_card
*card
= trident
->card
;
2980 struct snd_kcontrol
*kctl
;
2981 struct snd_ctl_elem_value
*uctl
;
2982 int idx
, err
, retries
= 2;
2983 static struct snd_ac97_bus_ops ops
= {
2984 .write
= snd_trident_codec_write
,
2985 .read
= snd_trident_codec_read
,
2988 uctl
= kzalloc(sizeof(*uctl
), GFP_KERNEL
);
2992 if ((err
= snd_ac97_bus(trident
->card
, 0, &ops
, NULL
, &trident
->ac97_bus
)) < 0)
2995 memset(&_ac97
, 0, sizeof(_ac97
));
2996 _ac97
.private_data
= trident
;
2997 trident
->ac97_detect
= 1;
3000 if ((err
= snd_ac97_mixer(trident
->ac97_bus
, &_ac97
, &trident
->ac97
)) < 0) {
3001 if (trident
->device
== TRIDENT_DEVICE_ID_SI7018
) {
3002 if ((err
= snd_trident_sis_reset(trident
)) < 0)
3011 /* secondary codec? */
3012 if (trident
->device
== TRIDENT_DEVICE_ID_SI7018
&&
3013 (inl(TRID_REG(trident
, SI_SERIAL_INTF_CTRL
)) & SI_AC97_PRIMARY_READY
) != 0) {
3015 err
= snd_ac97_mixer(trident
->ac97_bus
, &_ac97
, &trident
->ac97_sec
);
3017 dev_err(trident
->card
->dev
,
3018 "SI7018: the secondary codec - invalid access\n");
3019 #if 0 // only for my testing purpose --jk
3021 struct snd_ac97
*mc97
;
3022 err
= snd_ac97_modem(trident
->card
, &_ac97
, &mc97
);
3024 dev_err(trident
->card
->dev
,
3025 "snd_ac97_modem returned error %i\n", err
);
3030 trident
->ac97_detect
= 0;
3032 if (trident
->device
!= TRIDENT_DEVICE_ID_SI7018
) {
3033 if ((err
= snd_ctl_add(card
, kctl
= snd_ctl_new1(&snd_trident_vol_wave_control
, trident
))) < 0)
3035 kctl
->put(kctl
, uctl
);
3036 if ((err
= snd_ctl_add(card
, kctl
= snd_ctl_new1(&snd_trident_vol_music_control
, trident
))) < 0)
3038 kctl
->put(kctl
, uctl
);
3039 outl(trident
->musicvol_wavevol
= 0x00000000, TRID_REG(trident
, T4D_MUSICVOL_WAVEVOL
));
3041 outl(trident
->musicvol_wavevol
= 0xffff0000, TRID_REG(trident
, T4D_MUSICVOL_WAVEVOL
));
3044 for (idx
= 0; idx
< 32; idx
++) {
3045 struct snd_trident_pcm_mixer
*tmix
;
3047 tmix
= &trident
->pcm_mixer
[idx
];
3050 if ((trident
->ctl_vol
= snd_ctl_new1(&snd_trident_pcm_vol_control
, trident
)) == NULL
)
3052 if ((err
= snd_ctl_add(card
, trident
->ctl_vol
)))
3055 if ((trident
->ctl_pan
= snd_ctl_new1(&snd_trident_pcm_pan_control
, trident
)) == NULL
)
3057 if ((err
= snd_ctl_add(card
, trident
->ctl_pan
)))
3060 if ((trident
->ctl_rvol
= snd_ctl_new1(&snd_trident_pcm_rvol_control
, trident
)) == NULL
)
3062 if ((err
= snd_ctl_add(card
, trident
->ctl_rvol
)))
3065 if ((trident
->ctl_cvol
= snd_ctl_new1(&snd_trident_pcm_cvol_control
, trident
)) == NULL
)
3067 if ((err
= snd_ctl_add(card
, trident
->ctl_cvol
)))
3070 if (trident
->device
== TRIDENT_DEVICE_ID_NX
) {
3071 if ((err
= snd_ctl_add(card
, kctl
= snd_ctl_new1(&snd_trident_ac97_rear_control
, trident
))) < 0)
3073 kctl
->put(kctl
, uctl
);
3075 if (trident
->device
== TRIDENT_DEVICE_ID_NX
|| trident
->device
== TRIDENT_DEVICE_ID_SI7018
) {
3077 kctl
= snd_ctl_new1(&snd_trident_spdif_control
, trident
);
3082 if (trident
->ac97
->ext_id
& AC97_EI_SPDIF
)
3084 if (trident
->ac97_sec
&& (trident
->ac97_sec
->ext_id
& AC97_EI_SPDIF
))
3086 idx
= kctl
->id
.index
;
3087 if ((err
= snd_ctl_add(card
, kctl
)) < 0)
3089 kctl
->put(kctl
, uctl
);
3091 kctl
= snd_ctl_new1(&snd_trident_spdif_default
, trident
);
3096 kctl
->id
.index
= idx
;
3097 kctl
->id
.device
= pcm_spdif_device
;
3098 if ((err
= snd_ctl_add(card
, kctl
)) < 0)
3101 kctl
= snd_ctl_new1(&snd_trident_spdif_mask
, trident
);
3106 kctl
->id
.index
= idx
;
3107 kctl
->id
.device
= pcm_spdif_device
;
3108 if ((err
= snd_ctl_add(card
, kctl
)) < 0)
3111 kctl
= snd_ctl_new1(&snd_trident_spdif_stream
, trident
);
3116 kctl
->id
.index
= idx
;
3117 kctl
->id
.device
= pcm_spdif_device
;
3118 if ((err
= snd_ctl_add(card
, kctl
)) < 0)
3120 trident
->spdif_pcm_ctl
= kctl
;
3136 * gameport interface
3139 #if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))
3141 static unsigned char snd_trident_gameport_read(struct gameport
*gameport
)
3143 struct snd_trident
*chip
= gameport_get_port_data(gameport
);
3145 if (snd_BUG_ON(!chip
))
3147 return inb(TRID_REG(chip
, GAMEPORT_LEGACY
));
3150 static void snd_trident_gameport_trigger(struct gameport
*gameport
)
3152 struct snd_trident
*chip
= gameport_get_port_data(gameport
);
3154 if (snd_BUG_ON(!chip
))
3156 outb(0xff, TRID_REG(chip
, GAMEPORT_LEGACY
));
3159 static int snd_trident_gameport_cooked_read(struct gameport
*gameport
, int *axes
, int *buttons
)
3161 struct snd_trident
*chip
= gameport_get_port_data(gameport
);
3164 if (snd_BUG_ON(!chip
))
3167 *buttons
= (~inb(TRID_REG(chip
, GAMEPORT_LEGACY
)) >> 4) & 0xf;
3169 for (i
= 0; i
< 4; i
++) {
3170 axes
[i
] = inw(TRID_REG(chip
, GAMEPORT_AXES
+ i
* 2));
3171 if (axes
[i
] == 0xffff) axes
[i
] = -1;
3177 static int snd_trident_gameport_open(struct gameport
*gameport
, int mode
)
3179 struct snd_trident
*chip
= gameport_get_port_data(gameport
);
3181 if (snd_BUG_ON(!chip
))
3185 case GAMEPORT_MODE_COOKED
:
3186 outb(GAMEPORT_MODE_ADC
, TRID_REG(chip
, GAMEPORT_GCR
));
3189 case GAMEPORT_MODE_RAW
:
3190 outb(0, TRID_REG(chip
, GAMEPORT_GCR
));
3197 int snd_trident_create_gameport(struct snd_trident
*chip
)
3199 struct gameport
*gp
;
3201 chip
->gameport
= gp
= gameport_allocate_port();
3203 dev_err(chip
->card
->dev
,
3204 "cannot allocate memory for gameport\n");
3208 gameport_set_name(gp
, "Trident 4DWave");
3209 gameport_set_phys(gp
, "pci%s/gameport0", pci_name(chip
->pci
));
3210 gameport_set_dev_parent(gp
, &chip
->pci
->dev
);
3212 gameport_set_port_data(gp
, chip
);
3214 gp
->read
= snd_trident_gameport_read
;
3215 gp
->trigger
= snd_trident_gameport_trigger
;
3216 gp
->cooked_read
= snd_trident_gameport_cooked_read
;
3217 gp
->open
= snd_trident_gameport_open
;
3219 gameport_register_port(gp
);
3224 static inline void snd_trident_free_gameport(struct snd_trident
*chip
)
3226 if (chip
->gameport
) {
3227 gameport_unregister_port(chip
->gameport
);
3228 chip
->gameport
= NULL
;
3232 int snd_trident_create_gameport(struct snd_trident
*chip
) { return -ENOSYS
; }
3233 static inline void snd_trident_free_gameport(struct snd_trident
*chip
) { }
3234 #endif /* CONFIG_GAMEPORT */
3239 static inline void do_delay(struct snd_trident
*chip
)
3241 schedule_timeout_uninterruptible(1);
3248 static int snd_trident_sis_reset(struct snd_trident
*trident
)
3250 unsigned long end_time
;
3254 r
= trident
->in_suspend
? 0 : 2; /* count of retries */
3256 pci_write_config_byte(trident
->pci
, 0x46, 0x04); /* SOFTWARE RESET */
3258 pci_write_config_byte(trident
->pci
, 0x46, 0x00);
3260 /* disable AC97 GPIO interrupt */
3261 outb(0x00, TRID_REG(trident
, SI_AC97_GPIO
));
3262 /* initialize serial interface, force cold reset */
3263 i
= PCMOUT
|SURROUT
|CENTEROUT
|LFEOUT
|SECONDARY_ID
|COLD_RESET
;
3264 outl(i
, TRID_REG(trident
, SI_SERIAL_INTF_CTRL
));
3266 /* remove cold reset */
3268 outl(i
, TRID_REG(trident
, SI_SERIAL_INTF_CTRL
));
3270 /* wait, until the codec is ready */
3271 end_time
= (jiffies
+ (HZ
* 3) / 4) + 1;
3273 if ((inl(TRID_REG(trident
, SI_SERIAL_INTF_CTRL
)) & SI_AC97_PRIMARY_READY
) != 0)
3276 } while (time_after_eq(end_time
, jiffies
));
3277 dev_err(trident
->card
->dev
, "AC'97 codec ready error [0x%x]\n",
3278 inl(TRID_REG(trident
, SI_SERIAL_INTF_CTRL
)));
3280 end_time
= jiffies
+ HZ
;
3283 } while (time_after_eq(end_time
, jiffies
));
3284 goto __si7018_retry
;
3287 /* wait for the second codec */
3289 if ((inl(TRID_REG(trident
, SI_SERIAL_INTF_CTRL
)) & SI_AC97_SECONDARY_READY
) != 0)
3292 } while (time_after_eq(end_time
, jiffies
));
3293 /* enable 64 channel mode */
3294 outl(BANK_B_EN
, TRID_REG(trident
, T4D_LFO_GC_CIR
));
3302 static void snd_trident_proc_read(struct snd_info_entry
*entry
,
3303 struct snd_info_buffer
*buffer
)
3305 struct snd_trident
*trident
= entry
->private_data
;
3308 switch (trident
->device
) {
3309 case TRIDENT_DEVICE_ID_SI7018
:
3310 s
= "SiS 7018 Audio";
3312 case TRIDENT_DEVICE_ID_DX
:
3313 s
= "Trident 4DWave PCI DX";
3315 case TRIDENT_DEVICE_ID_NX
:
3316 s
= "Trident 4DWave PCI NX";
3321 snd_iprintf(buffer
, "%s\n\n", s
);
3322 snd_iprintf(buffer
, "Spurious IRQs : %d\n", trident
->spurious_irq_count
);
3323 snd_iprintf(buffer
, "Spurious IRQ dlta: %d\n", trident
->spurious_irq_max_delta
);
3324 if (trident
->device
== TRIDENT_DEVICE_ID_NX
|| trident
->device
== TRIDENT_DEVICE_ID_SI7018
)
3325 snd_iprintf(buffer
, "IEC958 Mixer Out : %s\n", trident
->spdif_ctrl
== 0x28 ? "on" : "off");
3326 if (trident
->device
== TRIDENT_DEVICE_ID_NX
) {
3327 snd_iprintf(buffer
, "Rear Speakers : %s\n", trident
->ac97_ctrl
& 0x00000010 ? "on" : "off");
3328 if (trident
->tlb
.entries
) {
3329 snd_iprintf(buffer
,"\nVirtual Memory\n");
3330 snd_iprintf(buffer
, "Memory Maximum : %d\n", trident
->tlb
.memhdr
->size
);
3331 snd_iprintf(buffer
, "Memory Used : %d\n", trident
->tlb
.memhdr
->used
);
3332 snd_iprintf(buffer
, "Memory Free : %d\n", snd_util_mem_avail(trident
->tlb
.memhdr
));
3337 static void snd_trident_proc_init(struct snd_trident
*trident
)
3339 struct snd_info_entry
*entry
;
3340 const char *s
= "trident";
3342 if (trident
->device
== TRIDENT_DEVICE_ID_SI7018
)
3344 if (! snd_card_proc_new(trident
->card
, s
, &entry
))
3345 snd_info_set_text_ops(entry
, trident
, snd_trident_proc_read
);
3348 static int snd_trident_dev_free(struct snd_device
*device
)
3350 struct snd_trident
*trident
= device
->device_data
;
3351 return snd_trident_free(trident
);
3354 /*---------------------------------------------------------------------------
3355 snd_trident_tlb_alloc
3357 Description: Allocate and set up the TLB page table on 4D NX.
3358 Each entry has 4 bytes (physical PCI address).
3360 Parameters: trident - pointer to target device class for 4DWave.
3362 Returns: 0 or negative error code
3364 ---------------------------------------------------------------------------*/
3366 static int snd_trident_tlb_alloc(struct snd_trident
*trident
)
3370 /* TLB array must be aligned to 16kB !!! so we allocate
3371 32kB region and correct offset when necessary */
3373 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV
, snd_dma_pci_data(trident
->pci
),
3374 2 * SNDRV_TRIDENT_MAX_PAGES
* 4, &trident
->tlb
.buffer
) < 0) {
3375 dev_err(trident
->card
->dev
, "unable to allocate TLB buffer\n");
3378 trident
->tlb
.entries
= (unsigned int*)ALIGN((unsigned long)trident
->tlb
.buffer
.area
, SNDRV_TRIDENT_MAX_PAGES
* 4);
3379 trident
->tlb
.entries_dmaaddr
= ALIGN(trident
->tlb
.buffer
.addr
, SNDRV_TRIDENT_MAX_PAGES
* 4);
3380 /* allocate shadow TLB page table (virtual addresses) */
3381 trident
->tlb
.shadow_entries
= vmalloc(SNDRV_TRIDENT_MAX_PAGES
*sizeof(unsigned long));
3382 if (trident
->tlb
.shadow_entries
== NULL
) {
3383 dev_err(trident
->card
->dev
,
3384 "unable to allocate shadow TLB entries\n");
3387 /* allocate and setup silent page and initialise TLB entries */
3388 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV
, snd_dma_pci_data(trident
->pci
),
3389 SNDRV_TRIDENT_PAGE_SIZE
, &trident
->tlb
.silent_page
) < 0) {
3390 dev_err(trident
->card
->dev
, "unable to allocate silent page\n");
3393 memset(trident
->tlb
.silent_page
.area
, 0, SNDRV_TRIDENT_PAGE_SIZE
);
3394 for (i
= 0; i
< SNDRV_TRIDENT_MAX_PAGES
; i
++) {
3395 trident
->tlb
.entries
[i
] = cpu_to_le32(trident
->tlb
.silent_page
.addr
& ~(SNDRV_TRIDENT_PAGE_SIZE
-1));
3396 trident
->tlb
.shadow_entries
[i
] = (unsigned long)trident
->tlb
.silent_page
.area
;
3399 /* use emu memory block manager code to manage tlb page allocation */
3400 trident
->tlb
.memhdr
= snd_util_memhdr_new(SNDRV_TRIDENT_PAGE_SIZE
* SNDRV_TRIDENT_MAX_PAGES
);
3401 if (trident
->tlb
.memhdr
== NULL
)
3404 trident
->tlb
.memhdr
->block_extra_size
= sizeof(struct snd_trident_memblk_arg
);
3409 * initialize 4D DX chip
3412 static void snd_trident_stop_all_voices(struct snd_trident
*trident
)
3414 outl(0xffffffff, TRID_REG(trident
, T4D_STOP_A
));
3415 outl(0xffffffff, TRID_REG(trident
, T4D_STOP_B
));
3416 outl(0, TRID_REG(trident
, T4D_AINTEN_A
));
3417 outl(0, TRID_REG(trident
, T4D_AINTEN_B
));
3420 static int snd_trident_4d_dx_init(struct snd_trident
*trident
)
3422 struct pci_dev
*pci
= trident
->pci
;
3423 unsigned long end_time
;
3425 /* reset the legacy configuration and whole audio/wavetable block */
3426 pci_write_config_dword(pci
, 0x40, 0); /* DDMA */
3427 pci_write_config_byte(pci
, 0x44, 0); /* ports */
3428 pci_write_config_byte(pci
, 0x45, 0); /* Legacy DMA */
3429 pci_write_config_byte(pci
, 0x46, 4); /* reset */
3431 pci_write_config_byte(pci
, 0x46, 0); /* release reset */
3434 /* warm reset of the AC'97 codec */
3435 outl(0x00000001, TRID_REG(trident
, DX_ACR2_AC97_COM_STAT
));
3437 outl(0x00000000, TRID_REG(trident
, DX_ACR2_AC97_COM_STAT
));
3438 /* DAC on, disable SB IRQ and try to force ADC valid signal */
3439 trident
->ac97_ctrl
= 0x0000004a;
3440 outl(trident
->ac97_ctrl
, TRID_REG(trident
, DX_ACR2_AC97_COM_STAT
));
3441 /* wait, until the codec is ready */
3442 end_time
= (jiffies
+ (HZ
* 3) / 4) + 1;
3444 if ((inl(TRID_REG(trident
, DX_ACR2_AC97_COM_STAT
)) & 0x0010) != 0)
3447 } while (time_after_eq(end_time
, jiffies
));
3448 dev_err(trident
->card
->dev
, "AC'97 codec ready error\n");
3452 snd_trident_stop_all_voices(trident
);
3458 * initialize 4D NX chip
3460 static int snd_trident_4d_nx_init(struct snd_trident
*trident
)
3462 struct pci_dev
*pci
= trident
->pci
;
3463 unsigned long end_time
;
3465 /* reset the legacy configuration and whole audio/wavetable block */
3466 pci_write_config_dword(pci
, 0x40, 0); /* DDMA */
3467 pci_write_config_byte(pci
, 0x44, 0); /* ports */
3468 pci_write_config_byte(pci
, 0x45, 0); /* Legacy DMA */
3470 pci_write_config_byte(pci
, 0x46, 1); /* reset */
3472 pci_write_config_byte(pci
, 0x46, 0); /* release reset */
3475 /* warm reset of the AC'97 codec */
3476 outl(0x00000001, TRID_REG(trident
, NX_ACR0_AC97_COM_STAT
));
3478 outl(0x00000000, TRID_REG(trident
, NX_ACR0_AC97_COM_STAT
));
3479 /* wait, until the codec is ready */
3480 end_time
= (jiffies
+ (HZ
* 3) / 4) + 1;
3482 if ((inl(TRID_REG(trident
, NX_ACR0_AC97_COM_STAT
)) & 0x0008) != 0)
3485 } while (time_after_eq(end_time
, jiffies
));
3486 dev_err(trident
->card
->dev
, "AC'97 codec ready error [0x%x]\n",
3487 inl(TRID_REG(trident
, NX_ACR0_AC97_COM_STAT
)));
3492 trident
->ac97_ctrl
= 0x00000002;
3493 outl(trident
->ac97_ctrl
, TRID_REG(trident
, NX_ACR0_AC97_COM_STAT
));
3494 /* disable SB IRQ */
3495 outl(NX_SB_IRQ_DISABLE
, TRID_REG(trident
, T4D_MISCINT
));
3497 snd_trident_stop_all_voices(trident
);
3499 if (trident
->tlb
.entries
!= NULL
) {
3501 /* enable virtual addressing via TLB */
3502 i
= trident
->tlb
.entries_dmaaddr
;
3504 outl(i
, TRID_REG(trident
, NX_TLBC
));
3506 outl(0, TRID_REG(trident
, NX_TLBC
));
3508 /* initialize S/PDIF */
3509 outl(trident
->spdif_bits
, TRID_REG(trident
, NX_SPCSTATUS
));
3510 outb(trident
->spdif_ctrl
, TRID_REG(trident
, NX_SPCTRL_SPCSO
+ 3));
3516 * initialize sis7018 chip
3518 static int snd_trident_sis_init(struct snd_trident
*trident
)
3522 if ((err
= snd_trident_sis_reset(trident
)) < 0)
3525 snd_trident_stop_all_voices(trident
);
3527 /* initialize S/PDIF */
3528 outl(trident
->spdif_bits
, TRID_REG(trident
, SI_SPDIF_CS
));
3533 /*---------------------------------------------------------------------------
3536 Description: This routine will create the device specific class for
3537 the 4DWave card. It will also perform basic initialization.
3539 Parameters: card - which card to create
3540 pci - interface to PCI bus resource info
3541 dma1ptr - playback dma buffer
3542 dma2ptr - capture dma buffer
3543 irqptr - interrupt resource info
3545 Returns: 4DWave device class private data
3547 ---------------------------------------------------------------------------*/
3549 int snd_trident_create(struct snd_card
*card
,
3550 struct pci_dev
*pci
,
3552 int pcm_spdif_device
,
3553 int max_wavetable_size
,
3554 struct snd_trident
** rtrident
)
3556 struct snd_trident
*trident
;
3558 struct snd_trident_voice
*voice
;
3559 struct snd_trident_pcm_mixer
*tmix
;
3560 static struct snd_device_ops ops
= {
3561 .dev_free
= snd_trident_dev_free
,
3566 /* enable PCI device */
3567 if ((err
= pci_enable_device(pci
)) < 0)
3569 /* check, if we can restrict PCI DMA transfers to 30 bits */
3570 if (pci_set_dma_mask(pci
, DMA_BIT_MASK(30)) < 0 ||
3571 pci_set_consistent_dma_mask(pci
, DMA_BIT_MASK(30)) < 0) {
3573 "architecture does not support 30bit PCI busmaster DMA\n");
3574 pci_disable_device(pci
);
3578 trident
= kzalloc(sizeof(*trident
), GFP_KERNEL
);
3579 if (trident
== NULL
) {
3580 pci_disable_device(pci
);
3583 trident
->device
= (pci
->vendor
<< 16) | pci
->device
;
3584 trident
->card
= card
;
3586 spin_lock_init(&trident
->reg_lock
);
3587 spin_lock_init(&trident
->event_lock
);
3588 spin_lock_init(&trident
->voice_alloc
);
3589 if (pcm_streams
< 1)
3591 if (pcm_streams
> 32)
3593 trident
->ChanPCM
= pcm_streams
;
3594 if (max_wavetable_size
< 0 )
3595 max_wavetable_size
= 0;
3596 trident
->synth
.max_size
= max_wavetable_size
* 1024;
3599 trident
->midi_port
= TRID_REG(trident
, T4D_MPU401_BASE
);
3600 pci_set_master(pci
);
3602 if ((err
= pci_request_regions(pci
, "Trident Audio")) < 0) {
3604 pci_disable_device(pci
);
3607 trident
->port
= pci_resource_start(pci
, 0);
3609 if (request_irq(pci
->irq
, snd_trident_interrupt
, IRQF_SHARED
,
3610 KBUILD_MODNAME
, trident
)) {
3611 dev_err(card
->dev
, "unable to grab IRQ %d\n", pci
->irq
);
3612 snd_trident_free(trident
);
3615 trident
->irq
= pci
->irq
;
3617 /* allocate 16k-aligned TLB for NX cards */
3618 trident
->tlb
.entries
= NULL
;
3619 trident
->tlb
.buffer
.area
= NULL
;
3620 if (trident
->device
== TRIDENT_DEVICE_ID_NX
) {
3621 if ((err
= snd_trident_tlb_alloc(trident
)) < 0) {
3622 snd_trident_free(trident
);
3627 trident
->spdif_bits
= trident
->spdif_pcm_bits
= SNDRV_PCM_DEFAULT_CON_SPDIF
;
3629 /* initialize chip */
3630 switch (trident
->device
) {
3631 case TRIDENT_DEVICE_ID_DX
:
3632 err
= snd_trident_4d_dx_init(trident
);
3634 case TRIDENT_DEVICE_ID_NX
:
3635 err
= snd_trident_4d_nx_init(trident
);
3637 case TRIDENT_DEVICE_ID_SI7018
:
3638 err
= snd_trident_sis_init(trident
);
3645 snd_trident_free(trident
);
3649 if ((err
= snd_device_new(card
, SNDRV_DEV_LOWLEVEL
, trident
, &ops
)) < 0) {
3650 snd_trident_free(trident
);
3654 if ((err
= snd_trident_mixer(trident
, pcm_spdif_device
)) < 0)
3657 /* initialise synth voices */
3658 for (i
= 0; i
< 64; i
++) {
3659 voice
= &trident
->synth
.voices
[i
];
3661 voice
->trident
= trident
;
3663 /* initialize pcm mixer entries */
3664 for (i
= 0; i
< 32; i
++) {
3665 tmix
= &trident
->pcm_mixer
[i
];
3666 tmix
->vol
= T4D_DEFAULT_PCM_VOL
;
3667 tmix
->pan
= T4D_DEFAULT_PCM_PAN
;
3668 tmix
->rvol
= T4D_DEFAULT_PCM_RVOL
;
3669 tmix
->cvol
= T4D_DEFAULT_PCM_CVOL
;
3672 snd_trident_enable_eso(trident
);
3674 snd_trident_proc_init(trident
);
3675 *rtrident
= trident
;
3679 /*---------------------------------------------------------------------------
3682 Description: This routine will free the device specific class for
3685 Parameters: trident - device specific private data for 4DWave card
3689 ---------------------------------------------------------------------------*/
3691 static int snd_trident_free(struct snd_trident
*trident
)
3693 snd_trident_free_gameport(trident
);
3694 snd_trident_disable_eso(trident
);
3695 // Disable S/PDIF out
3696 if (trident
->device
== TRIDENT_DEVICE_ID_NX
)
3697 outb(0x00, TRID_REG(trident
, NX_SPCTRL_SPCSO
+ 3));
3698 else if (trident
->device
== TRIDENT_DEVICE_ID_SI7018
) {
3699 outl(0, TRID_REG(trident
, SI_SERIAL_INTF_CTRL
));
3701 if (trident
->irq
>= 0)
3702 free_irq(trident
->irq
, trident
);
3703 if (trident
->tlb
.buffer
.area
) {
3704 outl(0, TRID_REG(trident
, NX_TLBC
));
3705 if (trident
->tlb
.memhdr
)
3706 snd_util_memhdr_free(trident
->tlb
.memhdr
);
3707 if (trident
->tlb
.silent_page
.area
)
3708 snd_dma_free_pages(&trident
->tlb
.silent_page
);
3709 vfree(trident
->tlb
.shadow_entries
);
3710 snd_dma_free_pages(&trident
->tlb
.buffer
);
3712 pci_release_regions(trident
->pci
);
3713 pci_disable_device(trident
->pci
);
3718 /*---------------------------------------------------------------------------
3719 snd_trident_interrupt
3721 Description: ISR for Trident 4DWave device
3723 Parameters: trident - device specific private data for 4DWave card
3725 Problems: It seems that Trident chips generates interrupts more than
3726 one time in special cases. The spurious interrupts are
3727 detected via sample timer (T4D_STIMER) and computing
3728 corresponding delta value. The limits are detected with
3729 the method try & fail so it is possible that it won't
3730 work on all computers. [jaroslav]
3734 ---------------------------------------------------------------------------*/
3736 static irqreturn_t
snd_trident_interrupt(int irq
, void *dev_id
)
3738 struct snd_trident
*trident
= dev_id
;
3739 unsigned int audio_int
, chn_int
, stimer
, channel
, mask
, tmp
;
3741 struct snd_trident_voice
*voice
;
3743 audio_int
= inl(TRID_REG(trident
, T4D_MISCINT
));
3744 if ((audio_int
& (ADDRESS_IRQ
|MPU401_IRQ
)) == 0)
3746 if (audio_int
& ADDRESS_IRQ
) {
3747 // get interrupt status for all channels
3748 spin_lock(&trident
->reg_lock
);
3749 stimer
= inl(TRID_REG(trident
, T4D_STIMER
)) & 0x00ffffff;
3750 chn_int
= inl(TRID_REG(trident
, T4D_AINT_A
));
3753 outl(chn_int
, TRID_REG(trident
, T4D_AINT_A
)); /* ack */
3755 chn_int
= inl(TRID_REG(trident
, T4D_AINT_B
));
3758 for (channel
= 63; channel
>= 32; channel
--) {
3759 mask
= 1 << (channel
&0x1f);
3760 if ((chn_int
& mask
) == 0)
3762 voice
= &trident
->synth
.voices
[channel
];
3763 if (!voice
->pcm
|| voice
->substream
== NULL
) {
3764 outl(mask
, TRID_REG(trident
, T4D_STOP_B
));
3767 delta
= (int)stimer
- (int)voice
->stimer
;
3770 if ((unsigned int)delta
< voice
->spurious_threshold
) {
3771 /* do some statistics here */
3772 trident
->spurious_irq_count
++;
3773 if (trident
->spurious_irq_max_delta
< (unsigned int)delta
)
3774 trident
->spurious_irq_max_delta
= delta
;
3777 voice
->stimer
= stimer
;
3779 if (!voice
->isync3
) {
3780 tmp
= inw(TRID_REG(trident
, T4D_SBBL_SBCL
));
3781 if (trident
->bDMAStart
& 0x40)
3784 tmp
= voice
->isync_max
- tmp
;
3786 tmp
= inl(TRID_REG(trident
, NX_SPCTRL_SPCSO
)) & 0x00ffffff;
3788 if (tmp
< voice
->isync_mark
) {
3790 tmp
= voice
->isync_ESO
- 7;
3792 tmp
= voice
->isync_ESO
+ 2;
3793 /* update ESO for IRQ voice to preserve sync */
3794 snd_trident_stop_voice(trident
, voice
->number
);
3795 snd_trident_write_eso_reg(trident
, voice
, tmp
);
3796 snd_trident_start_voice(trident
, voice
->number
);
3798 } else if (voice
->isync2
) {
3800 /* write original ESO and update CSO for IRQ voice to preserve sync */
3801 snd_trident_stop_voice(trident
, voice
->number
);
3802 snd_trident_write_cso_reg(trident
, voice
, voice
->isync_mark
);
3803 snd_trident_write_eso_reg(trident
, voice
, voice
->ESO
);
3804 snd_trident_start_voice(trident
, voice
->number
);
3808 /* update CSO for extra voice to preserve sync */
3809 snd_trident_stop_voice(trident
, voice
->extra
->number
);
3810 snd_trident_write_cso_reg(trident
, voice
->extra
, 0);
3811 snd_trident_start_voice(trident
, voice
->extra
->number
);
3814 spin_unlock(&trident
->reg_lock
);
3815 snd_pcm_period_elapsed(voice
->substream
);
3816 spin_lock(&trident
->reg_lock
);
3818 outl(chn_int
, TRID_REG(trident
, T4D_AINT_B
)); /* ack */
3820 spin_unlock(&trident
->reg_lock
);
3822 if (audio_int
& MPU401_IRQ
) {
3823 if (trident
->rmidi
) {
3824 snd_mpu401_uart_interrupt(irq
, trident
->rmidi
->private_data
);
3826 inb(TRID_REG(trident
, T4D_MPUR0
));
3829 // outl((ST_TARGET_REACHED | MIXER_OVERFLOW | MIXER_UNDERFLOW), TRID_REG(trident, T4D_MISCINT));
3833 struct snd_trident_voice
*snd_trident_alloc_voice(struct snd_trident
* trident
, int type
, int client
, int port
)
3835 struct snd_trident_voice
*pvoice
;
3836 unsigned long flags
;
3839 spin_lock_irqsave(&trident
->voice_alloc
, flags
);
3840 if (type
== SNDRV_TRIDENT_VOICE_TYPE_PCM
) {
3841 idx
= snd_trident_allocate_pcm_channel(trident
);
3843 spin_unlock_irqrestore(&trident
->voice_alloc
, flags
);
3846 pvoice
= &trident
->synth
.voices
[idx
];
3849 pvoice
->capture
= 0;
3851 pvoice
->memblk
= NULL
;
3852 pvoice
->substream
= NULL
;
3853 spin_unlock_irqrestore(&trident
->voice_alloc
, flags
);
3856 if (type
== SNDRV_TRIDENT_VOICE_TYPE_SYNTH
) {
3857 idx
= snd_trident_allocate_synth_channel(trident
);
3859 spin_unlock_irqrestore(&trident
->voice_alloc
, flags
);
3862 pvoice
= &trident
->synth
.voices
[idx
];
3865 pvoice
->client
= client
;
3866 pvoice
->port
= port
;
3867 pvoice
->memblk
= NULL
;
3868 spin_unlock_irqrestore(&trident
->voice_alloc
, flags
);
3871 if (type
== SNDRV_TRIDENT_VOICE_TYPE_MIDI
) {
3873 spin_unlock_irqrestore(&trident
->voice_alloc
, flags
);
3877 EXPORT_SYMBOL(snd_trident_alloc_voice
);
3879 void snd_trident_free_voice(struct snd_trident
* trident
, struct snd_trident_voice
*voice
)
3881 unsigned long flags
;
3882 void (*private_free
)(struct snd_trident_voice
*);
3885 if (voice
== NULL
|| !voice
->use
)
3887 snd_trident_clear_voices(trident
, voice
->number
, voice
->number
);
3888 spin_lock_irqsave(&trident
->voice_alloc
, flags
);
3889 private_free
= voice
->private_free
;
3890 private_data
= voice
->private_data
;
3891 voice
->private_free
= NULL
;
3892 voice
->private_data
= NULL
;
3894 snd_trident_free_pcm_channel(trident
, voice
->number
);
3896 snd_trident_free_synth_channel(trident
, voice
->number
);
3897 voice
->use
= voice
->pcm
= voice
->synth
= voice
->midi
= 0;
3898 voice
->capture
= voice
->spdif
= 0;
3899 voice
->sample_ops
= NULL
;
3900 voice
->substream
= NULL
;
3901 voice
->extra
= NULL
;
3902 spin_unlock_irqrestore(&trident
->voice_alloc
, flags
);
3904 private_free(voice
);
3907 EXPORT_SYMBOL(snd_trident_free_voice
);
3909 static void snd_trident_clear_voices(struct snd_trident
* trident
, unsigned short v_min
, unsigned short v_max
)
3911 unsigned int i
, val
, mask
[2] = { 0, 0 };
3913 if (snd_BUG_ON(v_min
> 63 || v_max
> 63))
3915 for (i
= v_min
; i
<= v_max
; i
++)
3916 mask
[i
>> 5] |= 1 << (i
& 0x1f);
3918 outl(mask
[0], TRID_REG(trident
, T4D_STOP_A
));
3919 val
= inl(TRID_REG(trident
, T4D_AINTEN_A
));
3920 outl(val
& ~mask
[0], TRID_REG(trident
, T4D_AINTEN_A
));
3923 outl(mask
[1], TRID_REG(trident
, T4D_STOP_B
));
3924 val
= inl(TRID_REG(trident
, T4D_AINTEN_B
));
3925 outl(val
& ~mask
[1], TRID_REG(trident
, T4D_AINTEN_B
));
3929 #ifdef CONFIG_PM_SLEEP
3930 static int snd_trident_suspend(struct device
*dev
)
3932 struct pci_dev
*pci
= to_pci_dev(dev
);
3933 struct snd_card
*card
= dev_get_drvdata(dev
);
3934 struct snd_trident
*trident
= card
->private_data
;
3936 trident
->in_suspend
= 1;
3937 snd_power_change_state(card
, SNDRV_CTL_POWER_D3hot
);
3938 snd_pcm_suspend_all(trident
->pcm
);
3939 snd_pcm_suspend_all(trident
->foldback
);
3940 snd_pcm_suspend_all(trident
->spdif
);
3942 snd_ac97_suspend(trident
->ac97
);
3943 snd_ac97_suspend(trident
->ac97_sec
);
3945 pci_disable_device(pci
);
3946 pci_save_state(pci
);
3947 pci_set_power_state(pci
, PCI_D3hot
);
3951 static int snd_trident_resume(struct device
*dev
)
3953 struct pci_dev
*pci
= to_pci_dev(dev
);
3954 struct snd_card
*card
= dev_get_drvdata(dev
);
3955 struct snd_trident
*trident
= card
->private_data
;
3957 pci_set_power_state(pci
, PCI_D0
);
3958 pci_restore_state(pci
);
3959 if (pci_enable_device(pci
) < 0) {
3960 dev_err(dev
, "pci_enable_device failed, disabling device\n");
3961 snd_card_disconnect(card
);
3964 pci_set_master(pci
);
3966 switch (trident
->device
) {
3967 case TRIDENT_DEVICE_ID_DX
:
3968 snd_trident_4d_dx_init(trident
);
3970 case TRIDENT_DEVICE_ID_NX
:
3971 snd_trident_4d_nx_init(trident
);
3973 case TRIDENT_DEVICE_ID_SI7018
:
3974 snd_trident_sis_init(trident
);
3978 snd_ac97_resume(trident
->ac97
);
3979 snd_ac97_resume(trident
->ac97_sec
);
3981 /* restore some registers */
3982 outl(trident
->musicvol_wavevol
, TRID_REG(trident
, T4D_MUSICVOL_WAVEVOL
));
3984 snd_trident_enable_eso(trident
);
3986 snd_power_change_state(card
, SNDRV_CTL_POWER_D0
);
3987 trident
->in_suspend
= 0;
3991 SIMPLE_DEV_PM_OPS(snd_trident_pm
, snd_trident_suspend
, snd_trident_resume
);
3992 #endif /* CONFIG_PM_SLEEP */