1 /*****************************************************************************
3 * Trident 4D-Wave OSS driver for Linux 2.2.x
5 * Driver: Alan Cox <alan@redhat.com>
8 * Low level code: <audio@tridentmicro.com> from ALSA
9 * Framework: Thomas Sailer <sailer@ife.ee.ethz.ch>
10 * Extended by: Zach Brown <zab@redhat.com>
13 * Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
32 /*****************************************************************************/
35 #include <linux/config.h>
36 #include <linux/module.h>
37 #include <linux/version.h>
38 #include <linux/string.h>
39 #include <linux/ctype.h>
40 #include <linux/ioport.h>
41 #include <linux/sched.h>
42 #include <linux/delay.h>
43 #include <linux/sound.h>
44 #include <linux/malloc.h>
45 #include <linux/soundcard.h>
46 #include <linux/pci.h>
49 #include <linux/init.h>
50 #include <linux/poll.h>
51 #include <linux/spinlock.h>
52 #include <asm/uaccess.h>
53 #include <asm/hardirq.h>
56 #include <linux/apm_bios.h>
62 /* --------------------------------------------------------------------- */
68 #define M_printk(args...) {if (debug) printk(args);}
73 /* --------------------------------------------------------------------- */
74 #define DRIVER_VERSION "0.01"
76 #define TRIDENT_FMT_STEREO 0x01
77 #define TRIDENT_FMT_16BIT 0x02
78 #define TRIDENT_FMT_MASK 0x03
79 #define TRIDENT_DAC_SHIFT 0
80 #define TRIDENT_ADC_SHIFT 4
82 #define TRIDENT_ENABLE_PE 1
83 #define TRIDENT_ENABLE_RE 2
86 #define TRIDENT_CARD_MAGIC 0x5072696E
87 #define TRIDENT_STATE_MAGIC 0x63657373
94 #define SND_DEV_DSP16 5
96 static const unsigned sample_size
[] = { 1, 2, 2, 4 };
97 static const unsigned sample_shift
[] = { 0, 1, 1, 2 };
104 static const char *card_names
[]={
105 [TYPE_4DWAVE_DX
] = "Trident 4DWave DX",
106 [TYPE_4DWAVE_NX
] = "Trident 4DWave NX",
110 typedef struct tChannelControl
113 unsigned int * lpChStart
;
114 unsigned int * lpChStop
;
115 unsigned int * lpChAint
;
116 unsigned int * lpChAinten
;
118 // register addresses
119 unsigned int * lpAChStart
;
120 unsigned int * lpAChStop
;
121 unsigned int * lpAChAint
;
122 unsigned int * lpAChAinten
;
124 unsigned int data
[16];
128 /* --------------------------------------------------------------------- */
130 struct trident_state
{
133 struct trident_card
*card
; /* Card info */
135 unsigned int rateadc
, ratedac
;
136 unsigned char fmt
, enable
;
138 struct semaphore open_sem
;
140 wait_queue_head_t open_wait
;
142 /* soundcore stuff */
150 int chan
[2]; /* Hardware channel */
151 /* XXX zab - swptr only in here so that it can be referenced by
152 clear_advance, as far as I can tell :( */
153 unsigned hwptr
, swptr
;
154 unsigned total_bytes
;
156 unsigned error
; /* over/underrun */
157 wait_queue_head_t wait
;
158 /* redundant, but makes calculations easier */
161 unsigned fragsamples
;
165 unsigned endcleared
:1;
166 unsigned ossfragshift
;
168 unsigned subdivision
;
169 u16 base
; /* Offset for ptr */
176 struct trident_card
{
179 /* We keep trident cards in a linked list */
180 struct trident_card
*next
;
182 /* The trident has a certain amount of cross channel interaction
183 so we use a single per card lock */
191 /* as most of this is static,
192 perhaps it should be a pointer to a global struct */
195 int supported_mixers
;
198 /* the caller must guarantee arg sanity before calling these */
199 /* int (*read_mixer)(struct trident_card *card, int index);*/
200 void (*write_mixer
)(struct trident_card
*card
,int mixer
, unsigned int left
,unsigned int right
);
201 int (*recmask_io
)(struct trident_card
*card
,int rw
,int mask
);
202 unsigned int mixer_state
[SOUND_MIXER_NRDEVICES
];
205 struct trident_state channels
[NR_DSPS
];
207 /* hardware resources */
208 unsigned long iobase
;
214 CHANNELCONTROL ChRegs
;
218 static struct timer_list debug_timer
;
220 #define IWriteAinten( x ) \
222 for( i= 0; i < ChanDwordCount; i++) \
223 outl((x)->lpChAinten[i], TRID_REG(trident, (x)->lpAChAinten[i]));}
225 #define IReadAinten( x ) \
227 for( i= 0; i < ChanDwordCount; i++) \
228 (x)->lpChAinten[i] = inl(TRID_REG(trident, (x)->lpAChAinten[i]));}
230 #define ReadAint( x ) \
233 #define WriteAint( x ) \
236 #define IWriteAint( x ) \
238 for( i= 0; i < ChanDwordCount; i++) \
239 outl((x)->lpChAint[i], TRID_REG(trident, (x)->lpAChAint[i]));}
241 #define IReadAint( x ) \
243 for( i= 0; i < ChanDwordCount; i++) \
244 (x)->lpChAint[i] = inl(TRID_REG(trident, (x)->lpAChAint[i]));}
248 * Trident support library routines
251 /*---------------------------------------------------------------------------
252 void ResetAinten( struct trident_state *trident, int ChannelNum)
254 Description: This routine will disable interrupts and ack any
255 existing interrupts for specified channel.
257 Parameters: trident - pointer to target device class for 4DWave.
258 ChannelNum - channel number
260 returns: TRUE if everything went ok, else FALSE.
262 ---------------------------------------------------------------------------*/
264 static void ResetAinten(struct trident_card
* trident
, int ChannelNum
)
267 unsigned int x
= ChannelNum
>> 5;
268 unsigned int ChanDwordCount
= trident
->ChanDwordCount
;
270 IReadAinten(&trident
->ChRegs
);
271 dwMask
= 1 << (ChannelNum
& 0x1f);
272 trident
->ChRegs
.lpChAinten
[x
] &= ~dwMask
;
273 IWriteAinten(&trident
->ChRegs
);
274 // Ack the channel in case the interrupt was set before we disable it.
275 outl(dwMask
, TRID_REG(trident
, trident
->ChRegs
.lpAChAint
[x
]));
278 /*---------------------------------------------------------------------------
279 void EnableEndInterrupts( struct trident_card *trident)
281 Description: This routine will enable end of loop interrupts.
282 End of loop interrupts will occur when a running
285 Parameters: trident - pointer to target device class for 4DWave.
287 returns: TRUE if everything went ok, else FALSE.
289 ---------------------------------------------------------------------------*/
291 static int EnableEndInterrupts(struct trident_card
* trident
)
293 unsigned int GlobalControl
;
295 GlobalControl
= inb(TRID_REG(trident
, T4D_LFO_GC_CIR
+ 1));
296 GlobalControl
|= 0x10;
297 outb(GlobalControl
, TRID_REG(trident
, T4D_LFO_GC_CIR
+ 1));
299 M_printk("(trident) globctl=%02X\n", GlobalControl
);
300 M_printk("(trident) enabled end interrupts\n");
304 /*---------------------------------------------------------------------------
305 e void DisableEndInterrupts( struct trident_card *trident)
307 Description: This routine will disable end of loop interrupts.
308 End of loop interrupts will occur when a running
312 trident - pointer to target device class for 4DWave.
314 returns: TRUE if everything went ok, else FALSE.
316 ---------------------------------------------------------------------------*/
318 static int DisableEndInterrupts(struct trident_card
* trident
)
320 unsigned int GlobalControl
;
322 GlobalControl
= inb(TRID_REG(trident
, T4D_LFO_GC_CIR
+ 1));
323 GlobalControl
&= ~0x10;
324 outb(GlobalControl
, TRID_REG(trident
, T4D_LFO_GC_CIR
+ 1));
326 M_printk("(trident) disabled end interrupts\n");
327 M_printk("(trident) globctl=%02X\n", GlobalControl
);
331 /*---------------------------------------------------------------------------
332 void trident_enable_voice_irq( unsigned int HwChannel )
334 Description: Enable an interrupt channel, any channel 0 thru n.
335 This routine automatically handles the fact that there are
336 more than 32 channels available.
338 Parameters : HwChannel - Channel number 0 thru n.
339 trident - pointer to target device class for 4DWave.
343 ---------------------------------------------------------------------------*/
344 void trident_enable_voice_irq(struct trident_card
* trident
, unsigned int HwChannel
)
346 unsigned int x
, Data
, ChanDwordCount
;
349 Data
= 1 << (HwChannel
& 0x1f);
350 ChanDwordCount
= trident
->ChanDwordCount
;
351 IReadAinten(&trident
->ChRegs
);
352 trident
->ChRegs
.lpChAinten
[x
] |= Data
;
353 IWriteAinten(&trident
->ChRegs
);
354 M_printk("(trident) enabled voice IRQ %d\n", HwChannel
);
357 /*---------------------------------------------------------------------------
358 void trident_disable_voice_irq( unsigned int HwChannel )
360 Description: Disable an interrupt channel, any channel 0 thru n.
361 This routine automatically handles the fact that there are
362 more than 32 channels available.
364 Parameters : HwChannel - Channel number 0 thru n.
365 trident - pointer to target device class for 4DWave.
369 ---------------------------------------------------------------------------*/
370 void trident_disable_voice_irq(struct trident_card
* trident
, unsigned int HwChannel
)
372 unsigned int x
, Data
, ChanDwordCount
;
375 Data
= 1 << (HwChannel
& 0x1f);
376 ChanDwordCount
= trident
->ChanDwordCount
;
377 IReadAinten(&trident
->ChRegs
);
378 trident
->ChRegs
.lpChAinten
[x
] &= ~Data
;
379 IWriteAinten(&trident
->ChRegs
);
380 M_printk("(trident) disabled voice IRQ %d\n", HwChannel
);
383 /*---------------------------------------------------------------------------
384 unsigned int AllocateChannelPCM( void )
386 Description: Allocate hardware channel by reverse order (63-0).
388 Parameters : trident - pointer to target device class for 4DWave.
390 Return Value: hardware channel - 0-63 or -1 when no channel is available
392 ---------------------------------------------------------------------------*/
394 static int AllocateChannelPCM(struct trident_card
*trident
)
398 if (trident
->ChanPCMcnt
>= trident
->ChanPCM
)
400 M_printk(KERN_DEBUG
"(trident) no channels available.\n");
403 for (idx
= 31; idx
>= 0; idx
--) {
404 if (!(trident
->ChanMap
[1] & (1 << idx
))) {
405 trident
->ChanMap
[1] |= 1 << idx
;
406 trident
->ChanPCMcnt
++;
410 for (idx
= 31; idx
>= 0; idx
--) {
411 if (!(trident
->ChanMap
[0] & (1 << idx
))) {
412 trident
->ChanMap
[0] |= 1 << idx
;
413 trident
->ChanPCMcnt
++;
420 /*---------------------------------------------------------------------------
421 void FreeChannelPCM( int channel )
423 Description: Free hardware channel.
425 Parameters : trident - pointer to target device class for 4DWave.
426 channel - hardware channel number 0-63
430 ---------------------------------------------------------------------------*/
432 static void FreeChannelPCM(struct trident_card
*trident
, int channel
)
434 if (channel
< 0 || channel
> 63)
436 if (trident
->ChanMap
[channel
>>5] & (1 << (channel
& 0x1f))) {
437 trident
->ChanMap
[channel
>>5] &= ~(1 << (channel
& 0x1f));
438 trident
->ChanPCMcnt
--;
442 /*---------------------------------------------------------------------------
443 void trident_start_voice( ULONG HwChannel )
445 Description: Start a channel, any channel 0 thru n.
446 This routine automatically handles the fact that there are
447 more than 32 channels available.
449 Parameters : HwChannel - Channel number 0 thru n.
450 trident - pointer to target device class for 4DWave.
454 ---------------------------------------------------------------------------*/
455 void trident_start_voice(struct trident_card
* trident
, unsigned int HwChannel
)
457 unsigned int x
= HwChannel
>> 5;
458 unsigned int Data
= 1 << (HwChannel
& 0x1f);
460 outl(Data
, TRID_REG(trident
, trident
->ChRegs
.lpAChStart
[x
]));
461 M_printk("(trident) start voice %d\n", HwChannel
);
464 /*---------------------------------------------------------------------------
465 void trident_stop_voice( ULONG HwChannel )
467 Description: Stop a channel, any channel 0 thru n.
468 This routine automatically handles the fact that there are
469 more than 32 channels available.
471 Parameters : HwChannel - Channel number 0 thru n.
472 trident - pointer to target device class for 4DWave.
476 ---------------------------------------------------------------------------*/
477 void trident_stop_voice(struct trident_card
* trident
, unsigned int HwChannel
)
479 unsigned int x
= HwChannel
>> 5;
480 unsigned int Data
= 1 << (HwChannel
& 0x1f);
482 outl(Data
, TRID_REG(trident
, trident
->ChRegs
.lpAChStop
[x
]));
483 M_printk("(trident) stop voice %d\n", HwChannel
);
486 /*---------------------------------------------------------------------------
487 int DidChannelInterrupt( )
489 Description: Check if interrupt channel occurred.
491 Parameters : trident - pointer to target device class for 4DWave.
493 Return Value: TRUE if interrupt occurred, else FALSE.
495 ---------------------------------------------------------------------------*/
496 static int DidChannelInterrupt(struct trident_card
* trident
, int channel
)
498 unsigned int ChanDwordCount
= trident
->ChanDwordCount
;
499 unsigned int x
= channel
>> 5;
500 unsigned int dwMask
= 1 << (channel
& 0x1f);
502 ReadAint(&trident
->ChRegs
);
503 return (trident
->ChRegs
.lpChAint
[x
] & dwMask
) ? TRUE
: FALSE
;
506 /*---------------------------------------------------------------------------
507 void AckChannelInterrupt( )
509 Description: Acknowledge the interrupt bit for channel intrs.
511 Parameters : trident - pointer to target device class for 4DWave.
515 ---------------------------------------------------------------------------*/
516 static void AckChannelInterrupt(struct trident_card
* trident
, int channel
)
518 unsigned int ChanDwordCount
= trident
->ChanDwordCount
;
519 unsigned int x
= channel
>> 5;
520 unsigned int dwMask
= 1 << (channel
& 0x1f);
522 ReadAint(&trident
->ChRegs
);
523 trident
->ChRegs
.lpChAint
[x
] &= dwMask
;
524 IWriteAint(&trident
->ChRegs
);
527 /*---------------------------------------------------------------------------
528 int LoadDeltaHw( unsigned int HwChannel, unsigned int Delta )
530 Description: This routine writes Delta to the hardware.
532 Parameters: Delta - data to write (2 Bytes only)
533 HwChannel - Hardware channel to write to.
534 trident - pointer to target device class for 4DWave.
536 Returns: TRUE if all goes well, else FALSE.
538 ---------------------------------------------------------------------------*/
539 static int LoadDeltaHw(struct trident_card
* trident
, unsigned int HwChannel
, unsigned int Delta
)
542 outb(HwChannel
, TRID_REG(trident
, T4D_LFO_GC_CIR
));
544 if (trident
->card_type
!= TYPE_4DWAVE_NX
) {
545 outw((unsigned short) Delta
, TRID_REG(trident
, CH_DX_ESO_DELTA
));
549 outb((unsigned char) Delta
, TRID_REG(trident
, CH_NX_DELTA_CSO
+ 3));
550 outb((unsigned char) (Delta
>> 8), TRID_REG(trident
, CH_NX_DELTA_ESO
+ 3));
556 /*---------------------------------------------------------------------------
557 int LoadVirtualChannel( ULONG *Data, ULONG HwChannel)
559 Description: This routine writes all required channel registers to hardware.
561 Parameters: *Data - a pointer to the data to write (5 ULONGS always).
562 HwChannel - Hardware channel to write to.
563 trident - pointer to target device class for 4DWave.
565 Returns: TRUE if all goes well, else FALSE.
567 ---------------------------------------------------------------------------*/
568 static int LoadVirtualChannel(struct trident_card
* trident
, unsigned int *Data
, unsigned int HwChannel
)
570 unsigned int ChanData
[CHANNEL_REGS
];
571 unsigned int ULONGSToDo
= CHANNEL_REGS
;
573 unsigned int Address
= CHANNEL_START
;
575 /* Copy the data first... Hack... Before mucking with Volume! */
576 memcpy((unsigned char *) ChanData
, (unsigned char *) Data
, ULONGSToDo
* 4);
578 outb((unsigned char) HwChannel
, TRID_REG(trident
, T4D_LFO_GC_CIR
));
580 for (i
= 0; i
< ULONGSToDo
; i
++, Address
+= 4)
581 outl(ChanData
[i
], TRID_REG(trident
, Address
));
583 M_printk("(trident) load virtual channel %d\n", HwChannel
);
587 /*---------------------------------------------------------------------------
588 trident_write_voice_regs
590 Description: This routine will write the 5 hardware channel registers
593 Paramters: trident - pointer to target device class for 4DWave.
594 Channel - Real or Virtual channel number.
597 Returns: TRUE if all goes well, else FALSE.
599 ---------------------------------------------------------------------------*/
600 int trident_write_voice_regs(struct trident_card
* trident
,
601 unsigned int Channel
,
606 unsigned int ALPHA_FMS
,
607 unsigned int FMC_RVOL_CVOL
,
614 unsigned int ChanData
[CHANNEL_REGS
+ 1], FmcRvolCvol
;
617 ChanData
[4] = (GVSEL
<< 31) |
618 ((PAN
& 0x0000007f) << 24) |
619 ((VOL
& 0x000000ff) << 16) |
620 ((CTRL
& 0x0000000f) << 12) |
623 FmcRvolCvol
= FMC_RVOL_CVOL
& 0x0000ffff;
625 if (trident
->card_type
!= TYPE_4DWAVE_NX
)
627 ChanData
[0] = (CSO
<< 16) | (ALPHA_FMS
& 0x0000ffff);
628 ChanData
[2] = (ESO
<< 16) | (DELTA
& 0x0ffff);
629 ChanData
[3] = FmcRvolCvol
;
633 ChanData
[0] = (DELTA
<< 24) | (CSO
& 0x00ffffff);
634 ChanData
[2] = ((DELTA
<< 16) & 0xff000000) | (ESO
& 0x00ffffff);
635 ChanData
[3] = (ALPHA_FMS
<< 16) | FmcRvolCvol
;
638 LoadVirtualChannel(trident
, ChanData
, Channel
);
643 static int compute_rate(u32 rate
)
646 // We special case 44100 and 8000 since rounding with the equation
647 // does not give us an accurate enough value. For 11025 and 22050
648 // the equation gives us the best answer. All other frequencies will
649 // also use the equation. JDW
652 else if (rate
== 8000)
654 else if (rate
== 48000)
657 delta
= (((rate
<< 12) + rate
) / 48000) & 0x0000ffff;
661 /*---------------------------------------------------------------------------
664 Description: This routine will set the sample rate for playback.
666 Paramters: trident - pointer to target device class for 4DWave.
667 rate - desired sample rate
668 set - actually write hardware if set is true.
670 Returns: The rate allowed by device.
672 ---------------------------------------------------------------------------*/
674 static unsigned int trident_set_dac_rate(struct trident_state
* trident
,
675 unsigned int rate
, int set
)
685 delta
= compute_rate(rate
);
689 //Select channel window
690 outb(trident
->dma_dac
.chan
[1], TRID_REG(trident
->card
, T4D_LFO_GC_CIR
));
692 if (trident
->card
->card_type
!= TYPE_4DWAVE_NX
)
693 outw(delta
,TRID_REG(trident
->card
,CH_DX_ESO_DELTA
+2));
696 outb( delta
& 0xff,TRID_REG(trident
->card
,CH_NX_DELTA_CSO
));
697 outb((delta
>>8) & 0xff,TRID_REG(trident
->card
,CH_NX_DELTA_ESO
));
701 M_printk("(trident) called trident_set_dac_rate : rate = %d, set = %d delta = %4x\n",
704 trident
->ratedac
= rate
;
708 /*---------------------------------------------------------------------------
711 Description: This routine will set the sample rate for capture.
713 Paramters: trident - pointer to target device class for 4DWave.
714 rate - desired sample rate
715 set - actually write hardware if set is true.
717 Returns: The rate allowed by device.
719 ---------------------------------------------------------------------------*/
721 static unsigned int trident_set_adc_rate(struct trident_state
* trident
,
725 //snd_printk("trid: called trident_set_adc_rate\n");
731 trident
->rateadc
= rate
;
733 * FIXME: hit the hardware
739 extern __inline__
unsigned ld2(unsigned int x
)
765 /* --------------------------------------------------------------------- */
767 static struct trident_card
*devs
= NULL
;
769 /* --------------------------------------------------------------------- */
773 * Trident AC97 codec programming interface.
776 static void trident_ac97_set(struct trident_card
*trident
, u8 cmd
, u16 val
)
778 unsigned int address
, data
;
779 unsigned short count
= 0xffff;
781 data
= ((unsigned long)val
) << 16;
783 if (trident
->card_type
!= TYPE_4DWAVE_NX
)
785 address
= DX_ACR0_AC97_W
;
786 /* read AC-97 write register status */
789 if ((inw(TRID_REG(trident
,address
))&0x8000) == 0)
794 data
|= (0x8000 | (cmd
& 0x000000ff));
798 address
= NX_ACR1_AC97_W
;
799 /* read AC-97 write register status */
802 if ((inw(TRID_REG(trident
, address
)) & 0x0800) == 0)
806 data
|= (0x0800 | (cmd
& 0x000000ff));
810 printk(KERN_ERR
"trident: AC97 CODEC write timed out.\n");
814 outl(data
, TRID_REG(trident
, address
));
817 static u16
trident_ac97_get(struct trident_card
*trident
, u8 cmd
)
819 unsigned int data
= 0;
820 unsigned short count
= 0xffff;
822 if (trident
->card_type
!= TYPE_4DWAVE_NX
)
824 data
= (0x00008000L
| (cmd
& 0x000000ff));
825 outl(data
, TRID_REG(trident
, DX_ACR1_AC97_R
));
828 data
= inl(TRID_REG(trident
, DX_ACR1_AC97_R
));
829 if ( ( data
& 0x0008000 ) == 0 )
836 data
= (0x00000800L
| (cmd
& 0x000000ff));
837 outl(data
, TRID_REG(trident
, NX_ACR2_AC97_R_PRIMARY
));
840 data
= inl(TRID_REG(trident
, NX_ACR2_AC97_R_PRIMARY
));
841 if ( ( data
& 0x00000C00 ) == 0 )
848 printk("trident: AC97 CODEC read timed out.\n");
851 return ((unsigned short)(data
>> 16));
854 /* OSS interface to the ac97s.. */
856 #define AC97_STEREO_MASK (SOUND_MASK_VOLUME|\
857 SOUND_MASK_PCM|SOUND_MASK_LINE|SOUND_MASK_CD|\
858 SOUND_MASK_VIDEO|SOUND_MASK_LINE1|SOUND_MASK_IGAIN)
860 #define AC97_SUPPORTED_MASK (AC97_STEREO_MASK | \
861 SOUND_MASK_BASS|SOUND_MASK_TREBLE|SOUND_MASK_MIC|\
864 #define AC97_RECORD_MASK (SOUND_MASK_MIC|\
865 SOUND_MASK_CD| SOUND_MASK_VIDEO| SOUND_MASK_LINE1| SOUND_MASK_LINE|\
868 #define supported_mixer(CARD,FOO) ( CARD->mix.supported_mixers & (1<<FOO) )
870 /* this table has default mixer values for all OSS mixers.
871 be sure to fill it in if you add oss mixers
872 to anyone's supported mixer defines */
874 /* possible __init */
875 static struct mixer_defaults
{
878 } mixer_defaults
[SOUND_MIXER_NRDEVICES
] = {
879 /* all values 0 -> 100 in bytes */
880 {SOUND_MIXER_VOLUME
, 0x3232},
881 {SOUND_MIXER_BASS
, 0x3232},
882 {SOUND_MIXER_TREBLE
, 0x3232},
883 {SOUND_MIXER_SPEAKER
, 0x3232},
884 {SOUND_MIXER_MIC
, 0x3232},
885 {SOUND_MIXER_LINE
, 0x3232},
886 {SOUND_MIXER_CD
, 0x3232},
887 {SOUND_MIXER_VIDEO
, 0x3232},
888 {SOUND_MIXER_LINE1
, 0x3232},
889 {SOUND_MIXER_PCM
, 0x3232},
890 {SOUND_MIXER_IGAIN
, 0x3232},
894 static struct ac97_mixer_hw
{
895 unsigned char offset
;
897 } ac97_hw
[SOUND_MIXER_NRDEVICES
]= {
898 [SOUND_MIXER_VOLUME
] = {0x02,63},
899 [SOUND_MIXER_BASS
] = {0x08,15},
900 [SOUND_MIXER_TREBLE
] = {0x08,15},
901 [SOUND_MIXER_SPEAKER
] = {0x0a,15},
902 [SOUND_MIXER_MIC
] = {0x0e,31},
903 [SOUND_MIXER_LINE
] = {0x10,31},
904 [SOUND_MIXER_CD
] = {0x12,31},
905 [SOUND_MIXER_VIDEO
] = {0x14,31},
906 [SOUND_MIXER_LINE1
] = {0x16,31},
907 [SOUND_MIXER_PCM
] = {0x18,31},
908 [SOUND_MIXER_IGAIN
] = {0x1c,31}
911 #if 0 /* *shrug* removed simply because we never used it.
912 feel free to implement again if needed */
914 /* reads the given OSS mixer from the ac97
915 the caller must have insured that the ac97 knows
916 about that given mixer, and should be holding a
917 spinlock for the card */
918 static int ac97_read_mixer(struct trident_card
*card
, int mixer
)
922 struct ac97_mixer_hw
*mh
= &ac97_hw
[mixer
];
924 val
= trident_ac97_get(card
, mh
->offset
);
926 if(AC97_STEREO_MASK
& (1<<mixer
)) {
927 /* nice stereo mixers .. */
930 left
= (val
>> 8) & 0x7f;
933 if (mixer
== SOUND_MIXER_IGAIN
) {
934 right
= (right
* 100) / mh
->scale
;
935 left
= (left
* 100) / mh
->scale
;
937 right
= 100 - ((right
* 100) / mh
->scale
);
938 left
= 100 - ((left
* 100) / mh
->scale
);
941 ret
= left
| (right
<< 8);
942 } else if (mixer
== SOUND_MIXER_SPEAKER
) {
943 ret
= 100 - ((((val
& 0x1e)>>1) * 100) / mh
->scale
);
944 } else if (mixer
== SOUND_MIXER_MIC
) {
945 ret
= 100 - (((val
& 0x1f) * 100) / mh
->scale
);
946 /* the low bit is optional in the tone sliders and masking
947 it lets is avoid the 0xf 'bypass'.. */
948 } else if (mixer
== SOUND_MIXER_BASS
) {
949 ret
= 100 - ((((val
>> 8) & 0xe) * 100) / mh
->scale
);
950 } else if (mixer
== SOUND_MIXER_TREBLE
) {
951 ret
= 100 - (((val
& 0xe) * 100) / mh
->scale
);
954 printk("read mixer %d (0x%x) %x -> %x\n",mixer
,mh
->offset
,val
,ret
);
960 /* write the OSS encoded volume to the given OSS encoded mixer,
961 again caller's job to make sure all is well in arg land,
962 call with spinlock held */
963 static void ac97_write_mixer(struct trident_card
*card
, int mixer
, unsigned int left
, unsigned int right
)
966 struct ac97_mixer_hw
*mh
= &ac97_hw
[mixer
];
968 printk("(trident) wrote ac97 mixer %d (0x%x) %d,%d",mixer
,mh
->offset
,left
,right
);
970 if(AC97_STEREO_MASK
& (1<<mixer
)) {
974 if (mixer
== SOUND_MIXER_IGAIN
) {
975 right
= (right
* mh
->scale
) / 100;
976 left
= (left
* mh
->scale
) / 100;
978 right
= ((100 - right
) * mh
->scale
) / 100;
979 left
= ((100 - left
) * mh
->scale
) / 100;
982 val
= (left
<< 8) | right
;
984 } else if (mixer
== SOUND_MIXER_SPEAKER
) {
985 val
= (((100 - left
) * mh
->scale
) / 100) << 1;
986 } else if (mixer
== SOUND_MIXER_MIC
) {
987 val
= trident_ac97_get(card
, mh
->offset
) & ~0x801f;
988 val
|= (((100 - left
) * mh
->scale
) / 100);
989 /* the low bit is optional in the tone sliders and masking
990 it lets us avoid the 0xf 'bypass'.. */
991 } else if (mixer
== SOUND_MIXER_BASS
) {
992 val
= trident_ac97_get(card
, mh
->offset
) & ~0x0f00;
993 val
|= ((((100 - left
) * mh
->scale
) / 100) << 8) & 0x0e00;
994 } else if (mixer
== SOUND_MIXER_TREBLE
) {
995 val
= trident_ac97_get(card
, mh
->offset
) & ~0x000f;
996 val
|= (((100 - left
) * mh
->scale
) / 100) & 0x000e;
999 trident_ac97_set(card
, mh
->offset
, val
);
1001 printk(" -> %x\n",val
);
1004 /* the following tables allow us to go from
1005 OSS <-> ac97 quickly. */
1007 enum ac97_recsettings
{
1013 AC97_REC_STEREO
, /* combination of all enabled outputs.. */
1014 AC97_REC_MONO
, /*.. or the mono equivalent */
1018 static unsigned int ac97_rm2oss
[] = {
1019 [AC97_REC_MIC
] = SOUND_MIXER_MIC
,
1020 [AC97_REC_CD
] = SOUND_MIXER_CD
,
1021 [AC97_REC_VIDEO
] = SOUND_MIXER_VIDEO
,
1022 [AC97_REC_AUX
] = SOUND_MIXER_LINE1
,
1023 [AC97_REC_LINE
] = SOUND_MIXER_LINE
,
1024 [AC97_REC_PHONE
] = SOUND_MIXER_PHONEIN
1027 /* indexed by bit position */
1028 static unsigned int ac97_oss_rm
[] = {
1029 [SOUND_MIXER_MIC
] = AC97_REC_MIC
,
1030 [SOUND_MIXER_CD
] = AC97_REC_CD
,
1031 [SOUND_MIXER_VIDEO
] = AC97_REC_VIDEO
,
1032 [SOUND_MIXER_LINE1
] = AC97_REC_AUX
,
1033 [SOUND_MIXER_LINE
] = AC97_REC_LINE
,
1034 [SOUND_MIXER_PHONEIN
] = AC97_REC_PHONE
1037 /* read or write the recmask
1038 the ac97 can really have left and right recording
1039 inputs independantly set, but OSS doesn't seem to
1040 want us to express that to the user.
1041 the caller guarantees that we have a supported bit set,
1042 and they must be holding the card's spinlock */
1044 static int ac97_recmask_io(struct trident_card
*card
, int rw
, int mask
)
1049 /* read it from the card */
1050 val
= trident_ac97_get(card
, 0x1a) & 0x7;
1051 return ac97_rm2oss
[val
];
1054 /* else, write the first set in the mask as the
1058 val
= ac97_oss_rm
[val
-1];
1059 val
|= val
<< 8; /* set both channels */
1061 printk("trident: setting ac97 recmask to 0x%x\n",val
);
1063 trident_ac97_set(card
,0x1a,val
);
1069 * Generic AC97 codec initialisation. Need to check there are no
1070 * quirks for the Trident cards.
1073 static u16
trident_ac97_init(struct trident_card
*trident
)
1075 trident
->mix
.supported_mixers
= AC97_SUPPORTED_MASK
;
1076 trident
->mix
.stereo_mixers
= AC97_STEREO_MASK
;
1077 trident
->mix
.record_sources
= AC97_RECORD_MASK
;
1078 /* trident->mix.read_mixer = ac97_read_mixer;*/
1079 trident
->mix
.write_mixer
= ac97_write_mixer
;
1080 trident
->mix
.recmask_io
= ac97_recmask_io
;
1082 if(trident
->card_type
== TYPE_4DWAVE_NX
)
1084 unsigned short VendorID1
, VendorID2
;
1086 outl(0x02, TRID_REG(trident
, NX_ACR0_AC97_COM_STAT
));
1088 // 4 Speaker Codec initialization
1089 VendorID1
= trident_ac97_get(trident
, AC97_VENDOR_ID1
);
1090 VendorID2
= trident_ac97_get(trident
, AC97_VENDOR_ID2
);
1092 if( (VendorID1
== 0x8384) && (VendorID2
== 0x7608) )
1096 unsigned short TestReg
;
1099 trident_ac97_set(trident
, AC97_SIGMATEL_CIC1
, 0xABBAL
);
1100 trident_ac97_set(trident
, AC97_SIGMATEL_CIC2
, 0x1000L
);
1102 TestReg
= trident_ac97_get(trident
, AC97_SIGMATEL_BIAS2
);
1104 if( TestReg
!= 0x8000 ) // Errata Notice.
1106 trident_ac97_set(trident
, AC97_SIGMATEL_BIAS1
, 0xABBAL
);
1107 trident_ac97_set(trident
, AC97_SIGMATEL_BIAS2
, 0x0007L
);
1109 else // Newer version
1111 trident_ac97_set(trident
, AC97_SIGMATEL_CIC2
, 0x1001L
); // recommended
1112 trident_ac97_set(trident
, AC97_SIGMATEL_DAC2INVERT
, 0x0008L
);
1115 trident_ac97_set( trident
, AC97_SURROUND_MASTER
, 0x0000L
);
1116 trident_ac97_set( trident
, AC97_HEADPHONE_VOL
, 0x8000L
);
1118 DTemp
= (unsigned int)trident_ac97_get( trident
, AC97_GENERAL_PURPOSE
);
1119 trident_ac97_set( trident
, AC97_GENERAL_PURPOSE
, DTemp
& 0x0000FDFFL
); // bit9 = 0.
1121 DTemp
= (unsigned int)trident_ac97_get( trident
, AC97_MIC_VOL
);
1122 trident_ac97_set( trident
, AC97_MIC_VOL
, DTemp
| 0x00008000L
); // bit15 = 1.
1124 DTemp
= inl(TRID_REG(trident
, NX_ACR0_AC97_COM_STAT
));
1125 outl(DTemp
| 0x0010, TRID_REG(trident
, NX_ACR0_AC97_COM_STAT
));
1128 else if((VendorID1
== 0x5452) && (VendorID2
== 0x4108) )
1129 { // TriTech TR28028
1130 trident_ac97_set( trident
, AC97_SURROUND_MASTER
, 0x0000L
);
1131 trident_ac97_set( trident
, AC97_EXTENDED_STATUS
, 0x0000L
);
1133 else if((VendorID1
== 0x574D) &&
1134 (VendorID2
>= 0x4C00) && (VendorID2
<= 0x4C0f))
1136 trident_ac97_set( trident
, AC97_SURROUND_MASTER
, 0x0000L
);
1141 printk("trident: No four Speaker Support with on board CODEC\n") ;
1145 // S/PDIF C Channel bits 0-31 : 48khz, SCMS disabled
1146 outl(0x200004, TRID_REG(trident
, NX_SPCSTATUS
));
1147 // Enable S/PDIF out, 48khz only from ac97 fifo
1148 outb(0x28, TRID_REG(trident
, NX_SPCTRL_SPCSO
+3));
1152 outl(0x02, TRID_REG(trident
, DX_ACR2_AC97_COM_STAT
));
1158 /* this only fixes the output apu mode to be later set by start_dac and
1159 company. output apu modes are set in trident_rec_setup */
1160 static void set_fmt(struct trident_state
*s
, unsigned char mask
, unsigned char data
)
1162 s
->fmt
= (s
->fmt
& mask
) | data
;
1163 /* Set the chip ? */
1168 * Native play back driver
1171 /* the mode passed should be already shifted and masked */
1173 static void trident_play_setup(struct trident_state
*trident
, int mode
, u32 rate
, void *buffer
, int size
)
1179 unsigned int FMC_RVOL_CVOL
;
1187 /* set Loop Back Address */
1188 LBA
= virt_to_bus(buffer
);
1190 Delta
= compute_rate(rate
);
1192 M_printk("(trident) rate, delta = %d %d\n", rate
, Delta
);
1196 if (mode
& TRIDENT_FMT_16BIT
)
1198 if (mode
& TRIDENT_FMT_STEREO
)
1202 //snd_printk("trid: ESO = %d\n", ESO);
1205 CTRL default: 8-bit (unsigned) mono, loop mode enabled
1208 if (mode
& TRIDENT_FMT_16BIT
)
1210 CTRL
|= 0x00000008; // 16-bit data
1211 CTRL
|= 0x00000002; // signed data
1213 if (mode
&TRIDENT_FMT_STEREO
)
1214 CTRL
|= 0x00000004; // stereo data
1216 //FMC_RVOL_CVOL = 0x0000c000;
1217 FMC_RVOL_CVOL
= 0x0000ffff;
1223 trident_write_voice_regs(trident
->card
,
1224 trident
->dma_dac
.chan
[1],
1240 * Native record driver
1243 /* again, passed mode is alrady shifted/masked */
1245 static void trident_rec_setup(struct trident_state
*trident
, int mode
, u32 rate
, void *buffer
, int size
)
1251 unsigned int FMC_RVOL_CVOL
;
1256 unsigned char bValue
;
1257 unsigned short wValue
;
1258 unsigned int dwValue
;
1259 unsigned short wRecCODECSamples
;
1260 unsigned int dwChanFlags
;
1261 struct trident_card
*card
= trident
->card
;
1263 // Enable AC-97 ADC (capture), disable capture interrupt
1264 if (trident
->card
->card_type
!= TYPE_4DWAVE_NX
)
1266 bValue
= inb(TRID_REG(card
, DX_ACR2_AC97_COM_STAT
));
1267 outb(bValue
| 0x48, TRID_REG(card
, DX_ACR2_AC97_COM_STAT
));
1271 wValue
= inw(TRID_REG(card
, T4D_MISCINT
));
1272 outw(wValue
| 0x1000, TRID_REG(card
, T4D_MISCINT
));
1275 // Initilize the channel and set channel Mode
1276 outb(0, TRID_REG(card
, LEGACY_DMAR15
));
1278 // Set DMA channel operation mode register
1279 bValue
= inb(TRID_REG(card
, LEGACY_DMAR11
)) & 0x03;
1280 outb(bValue
| 0x54, TRID_REG(card
, LEGACY_DMAR11
));
1282 // Set channel buffer Address
1283 LBA
= virt_to_bus(buffer
);
1284 outl(LBA
, TRID_REG(card
, LEGACY_DMAR0
));
1289 dwValue
= inl(TRID_REG(card
, LEGACY_DMAR4
)) & 0xff000000;
1290 dwValue
|= (ESO
- 1) & 0x0000ffff;
1291 outl(dwValue
, TRID_REG(card
, LEGACY_DMAR4
));
1293 // Set channel sample rate , 4.12 format
1294 dwValue
= (((unsigned int) 48000L << 12) / (unsigned long) (rate
));
1295 outw((unsigned short) dwValue
, TRID_REG(card
, T4D_SBDELTA_DELTA_R
));
1297 // Set channel interrupt blk length
1298 if (mode
& TRIDENT_FMT_16BIT
) {
1299 wRecCODECSamples
= (unsigned short) ((ESO
>> 1) - 1);
1300 dwChanFlags
= 0xffffb000;
1302 wRecCODECSamples
= (unsigned short) (ESO
- 1);
1303 dwChanFlags
= 0xffff1000;
1306 dwValue
= ((unsigned int) wRecCODECSamples
) << 16;
1307 dwValue
|= (unsigned int) (wRecCODECSamples
) & 0x0000ffff;
1308 outl(dwValue
, TRID_REG(card
, T4D_SBBL_SBCL
));
1310 // Right now, set format and start to run capturing,
1311 // continuous run loop enable.
1312 trident
->bDMAStart
= 0x19; // 0001 1001b
1314 if (mode
& TRIDENT_FMT_16BIT
)
1315 trident
->bDMAStart
|= 0xa0;
1316 if (mode
& TRIDENT_FMT_STEREO
)
1317 trident
->bDMAStart
|= 0x40;
1319 // Prepare capture intr channel
1321 Delta
= ((((unsigned int) rate
) << 12) / ((unsigned long) (48000L)));
1323 /* set Loop Back Address */
1324 LBA
= virt_to_bus(buffer
);
1328 if (mode
& TRIDENT_FMT_16BIT
)
1330 if (mode
& TRIDENT_FMT_STEREO
)
1334 //snd_printk("trid: ESO = %d\n", ESO);
1337 CTRL default: 8-bit (unsigned) mono, loop mode enabled
1340 if (mode
& TRIDENT_FMT_16BIT
)
1341 CTRL
|= 0x00000008; // 16-bit data
1342 /* XXX DO UNSIGNED XXX */
1343 //if (!(mode & SND_PCM1_MODE_U))
1344 // CTRL |= 0x00000002; // signed data
1345 if (mode
& TRIDENT_FMT_STEREO
)
1346 CTRL
|= 0x00000004; // stereo data
1348 FMC_RVOL_CVOL
= 0x0000ffff;
1354 trident_write_voice_regs(card
,
1355 trident
->dma_adc
.chan
[0],
1370 /* Playback pointer */
1371 __inline__
unsigned int get_dmaa(struct trident_state
*trident
)
1377 if (!(trident
->enable
& ADC_RUNNING
))
1381 outb(trident
->dma_dac
.chan
[1], TRID_REG(trident
->card
, T4D_LFO_GC_CIR
));
1383 if (trident
->card
->card_type
!= TYPE_4DWAVE_NX
)
1385 cso
= inw(TRID_REG(trident
->card
, CH_DX_CSO_ALPHA_FMS
+ 2));
1386 eso
= inw(TRID_REG(trident
->card
, CH_DX_ESO_DELTA
+ 2));
1388 else // ID_4DWAVE_NX
1390 cso
= (unsigned int) inl(TRID_REG(trident
->card
, CH_NX_DELTA_CSO
)) & 0x00ffffff;
1391 eso
= (unsigned int) inl(TRID_REG(trident
->card
, CH_NX_DELTA_ESO
)) & 0x00ffffff;
1393 M_printk("(trident) get_dmaa: chip reported %d.%d\n", cso
, eso
);
1399 if (trident
->fmt
& TRIDENT_FMT_16BIT
)
1401 if (trident
->fmt
& TRIDENT_FMT_STEREO
)
1406 /* Record pointer */
1407 extern __inline__
unsigned get_dmac(struct trident_state
*trident
)
1411 if (!(trident
->enable
&DAC_RUNNING
))
1414 outb(trident
->dma_adc
.chan
[0], TRID_REG(trident
->card
, T4D_LFO_GC_CIR
));
1416 if (trident
->card
->card_type
!= TYPE_4DWAVE_NX
) {
1417 cso
= inw(TRID_REG(trident
->card
, CH_DX_CSO_ALPHA_FMS
+ 2));
1418 } else { // ID_4DWAVE_NX
1419 cso
= (unsigned int) inl(TRID_REG(trident
->card
, CH_NX_DELTA_CSO
)) & 0x00ffffff;
1422 printk("(trident) get_dmac: chip reported %d\n", cso
);
1426 if (trident
->fmt
& TRIDENT_FMT_16BIT
)
1428 if (trident
->fmt
& TRIDENT_FMT_STEREO
)
1433 static void trident_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
);
1435 static void trident_kick(unsigned long plop
)
1437 trident_interrupt(5, (void *)plop
, NULL
);
1438 debug_timer
.expires
=jiffies
+1;
1439 add_timer(&debug_timer
);
1442 /* Stop recording (lock held) */
1444 extern inline void __stop_adc(struct trident_state
*s
)
1446 struct trident_card
*trident
= s
->card
;
1448 M_printk("(trident) stopping ADC\n");
1451 s
->enable
&= ~ADC_RUNNING
;
1452 trident_disable_voice_irq(trident
, s
->dma_adc
.chan
[0]);
1453 outb(0x00, TRID_REG(trident
, T4D_SBCTRL_SBE2R_SBDD
));
1454 trident_disable_voice_irq(trident
, s
->dma_adc
.chan
[0]);
1455 trident_stop_voice(trident
, s
->dma_adc
.chan
[0]);
1456 ResetAinten(trident
, s
->dma_adc
.chan
[0]);
1459 extern inline void stop_adc(struct trident_state
*s
)
1461 unsigned long flags
;
1462 struct trident_card
*trident
= s
->card
;
1464 spin_lock_irqsave(&trident
->lock
, flags
);
1466 spin_unlock_irqrestore(&trident
->lock
, flags
);
1469 /* stop playback (lock held) */
1471 extern inline void __stop_dac(struct trident_state
*s
)
1473 struct trident_card
*trident
= s
->card
;
1475 M_printk("(trident) stopping DAC\n");
1477 //trident_stop_voice(trident, s->dma_dac.chan[0]);
1478 //trident_disable_voice_irq(trident, s->dma_dac.chan[0]);
1479 trident_stop_voice(trident
, s
->dma_dac
.chan
[1]);
1480 trident_disable_voice_irq(trident
, s
->dma_dac
.chan
[1]);
1481 s
->enable
&= ~DAC_RUNNING
;
1484 extern inline void stop_dac(struct trident_state
*s
)
1486 struct trident_card
*trident
= s
->card
;
1487 unsigned long flags
;
1489 spin_lock_irqsave(&trident
->lock
, flags
);
1491 spin_unlock_irqrestore(&trident
->lock
, flags
);
1494 static void start_dac(struct trident_state
*s
)
1496 unsigned long flags
;
1497 struct trident_card
*trident
= s
->card
;
1499 spin_lock_irqsave(&s
->card
->lock
, flags
);
1500 if ((s
->dma_dac
.mapped
|| s
->dma_dac
.count
> 0) && s
->dma_dac
.ready
)
1502 s
->enable
|= DAC_RUNNING
;
1503 trident_enable_voice_irq(trident
, s
->dma_dac
.chan
[1]);
1504 trident_start_voice(trident
, s
->dma_dac
.chan
[1]);
1505 //trident_start_voice(trident, s->dma_dac.chan[0]);
1506 M_printk("(trident) starting DAC\n");
1509 spin_unlock_irqrestore(&s
->card
->lock
, flags
);
1512 static void start_adc(struct trident_state
*s
)
1514 unsigned long flags
;
1516 spin_lock_irqsave(&s
->card
->lock
, flags
);
1517 if ((s
->dma_adc
.mapped
|| s
->dma_adc
.count
< (signed)(s
->dma_adc
.dmasize
- 2*s
->dma_adc
.fragsize
))
1518 && s
->dma_adc
.ready
) {
1519 s
->enable
|= ADC_RUNNING
;
1520 trident_enable_voice_irq(s
->card
, s
->dma_adc
.chan
[0]);
1521 outb(s
->bDMAStart
, TRID_REG(s
->card
, T4D_SBCTRL_SBE2R_SBDD
));
1522 trident_start_voice(s
->card
, s
->dma_adc
.chan
[0]);
1523 M_printk("(trident) starting ADC\n");
1526 spin_unlock_irqrestore(&s
->card
->lock
, flags
);
1529 /* --------------------------------------------------------------------- */
1531 /* we allocate both buffers at once */
1532 #define DMABUF_DEFAULTORDER (15-PAGE_SHIFT)
1533 #define DMABUF_MINORDER 2
1535 static void dealloc_dmabuf(struct dmabuf
*db
)
1537 unsigned long map
, mapend
;
1541 M_printk("(trident) freeing %p\n",db
->rawbuf
);
1542 /* undo marking the pages as reserved */
1543 mapend
= MAP_NR(db
->rawbuf
+ (PAGE_SIZE
<< db
->buforder
) - 1);
1544 for (map
= MAP_NR(db
->rawbuf
); map
<= mapend
; map
++)
1545 clear_bit(PG_reserved
, &mem_map
[map
].flags
);
1546 free_pages((unsigned long)db
->rawbuf
, db
->buforder
);
1549 db
->mapped
= db
->ready
= 0;
1552 static int prog_dmabuf(struct trident_state
*s
, unsigned rec
)
1554 struct dmabuf
*db
= rec
? &s
->dma_adc
: &s
->dma_dac
;
1555 unsigned rate
= rec
? s
->rateadc
: s
->ratedac
;
1557 unsigned bytepersec
;
1559 unsigned long map
, mapend
;
1561 unsigned long flags
;
1563 spin_lock_irqsave(&s
->card
->lock
, flags
);
1566 s
->enable
&= ~TRIDENT_ENABLE_RE
;
1567 fmt
>>= TRIDENT_ADC_SHIFT
;
1569 s
->enable
&= ~TRIDENT_ENABLE_PE
;
1570 fmt
>>= TRIDENT_DAC_SHIFT
;
1572 spin_unlock_irqrestore(&s
->card
->lock
, flags
);
1573 fmt
&= TRIDENT_FMT_MASK
;
1575 db
->hwptr
= db
->swptr
= db
->total_bytes
= db
->count
= db
->error
= db
->endcleared
= 0;
1579 /* haha, this thing is hacked to hell and back.
1581 s
->dma_dac
.ready
= s
->dma_dac
.mapped
= 0;
1582 s
->dma_adc
.ready
= s
->dma_adc
.mapped
= 0;
1584 /* alloc as big a chunk as we can */
1585 for (order
= DMABUF_DEFAULTORDER
; order
>= DMABUF_MINORDER
; order
--)
1586 if((rawbuf
= (void *)__get_free_pages(GFP_KERNEL
|GFP_DMA
, order
)))
1594 /* we allocated both buffers */
1595 s
->dma_adc
.rawbuf
= rawbuf
;
1596 s
->dma_dac
.rawbuf
= rawbuf
+ ( PAGE_SIZE
<< (order
- 1) );
1598 M_printk("(trident) allocated %ld bytes at %p\n",PAGE_SIZE
<<order
, db
->rawbuf
);
1600 s
->dma_adc
.buforder
= s
->dma_dac
.buforder
= order
- 1;
1602 /* XXX these checks are silly now */
1604 if ((virt_to_bus(db
->rawbuf
) ^ (virt_to_bus(db
->rawbuf
) + (PAGE_SIZE
<< order
) - 1)) & ~0xffff)
1605 printk(KERN_DEBUG
"trident: DMA buffer crosses 64k boundary: busaddr 0x%lx size %ld\n",
1606 virt_to_bus(db
->rawbuf
), PAGE_SIZE
<< order
);
1609 if ((virt_to_bus(db
->rawbuf
) + (PAGE_SIZE
<< order
) - 1) & ~0xffffff)
1610 M_printk(KERN_DEBUG
"(trident) DMA buffer beyond 16MB: busaddr 0x%lx size %ld\n",
1611 virt_to_bus(db
->rawbuf
), PAGE_SIZE
<< order
);
1613 /* now mark the pages as reserved; otherwise remap_page_range doesn't do what we want */
1614 mapend
= MAP_NR(db
->rawbuf
+ (PAGE_SIZE
<< order
) - 1);
1615 for (map
= MAP_NR(db
->rawbuf
); map
<= mapend
; map
++)
1616 set_bit(PG_reserved
, &mem_map
[map
].flags
);
1618 bytepersec
= rate
<< sample_shift
[fmt
];
1619 bufs
= PAGE_SIZE
<< db
->buforder
;
1620 if (db
->ossfragshift
) {
1621 if ((1000 << db
->ossfragshift
) < bytepersec
)
1622 db
->fragshift
= ld2(bytepersec
/1000);
1624 db
->fragshift
= db
->ossfragshift
;
1626 /* lets hand out reasonable big ass buffers by default */
1627 db
->fragshift
= (db
->buforder
+ PAGE_SHIFT
-2);
1629 db
->fragshift
= ld2(bytepersec
/100/(db
->subdivision
? db
->subdivision
: 1));
1630 if (db
->fragshift
< 3)
1634 db
->numfrag
= bufs
>> db
->fragshift
;
1635 while (db
->numfrag
< 4 && db
->fragshift
> 3) {
1637 db
->numfrag
= bufs
>> db
->fragshift
;
1639 db
->fragsize
= 1 << db
->fragshift
;
1640 if (db
->ossmaxfrags
>= 4 && db
->ossmaxfrags
< db
->numfrag
)
1641 db
->numfrag
= db
->ossmaxfrags
;
1642 db
->fragsamples
= db
->fragsize
>> sample_shift
[fmt
];
1643 db
->dmasize
= db
->numfrag
<< db
->fragshift
;
1645 memset(db
->rawbuf
, (fmt
& TRIDENT_FMT_16BIT
) ? 0 : 0x80, db
->dmasize
);
1647 spin_lock_irqsave(&s
->card
->lock
, flags
);
1649 trident_rec_setup(s
, fmt
, s
->rateadc
,
1650 db
->rawbuf
, db
->numfrag
<< db
->fragshift
);
1652 trident_play_setup(s
, fmt
, s
->ratedac
,
1653 db
->rawbuf
, db
->numfrag
<< db
->fragshift
);
1655 spin_unlock_irqrestore(&s
->card
->lock
, flags
);
1661 /* only called by trident_write */
1663 extern __inline__
void clear_advance(struct trident_state
*s
)
1665 unsigned char c
= ((s
->fmt
>> TRIDENT_DAC_SHIFT
) & TRIDENT_FMT_16BIT
) ? 0 : 0x80;
1666 unsigned char *buf
= s
->dma_dac
.rawbuf
;
1667 unsigned bsize
= s
->dma_dac
.dmasize
;
1668 unsigned bptr
= s
->dma_dac
.swptr
;
1669 unsigned len
= s
->dma_dac
.fragsize
;
1671 if (bptr
+ len
> bsize
) {
1672 unsigned x
= bsize
- bptr
;
1673 memset(buf
+ bptr
, c
, x
);
1674 /* account for wrapping? */
1678 memset(buf
+ bptr
, c
, len
);
1681 /* call with spinlock held! */
1682 static void trident_update_ptr(struct trident_state
*s
)
1687 /* update ADC pointer */
1688 if (s
->dma_adc
.ready
) {
1689 hwptr
= get_dmac(s
) % s
->dma_adc
.dmasize
;
1690 diff
= (s
->dma_adc
.dmasize
+ hwptr
- s
->dma_adc
.hwptr
) % s
->dma_adc
.dmasize
;
1691 s
->dma_adc
.hwptr
= hwptr
;
1692 s
->dma_adc
.total_bytes
+= diff
;
1693 s
->dma_adc
.count
+= diff
;
1694 if (s
->dma_adc
.count
>= (signed)s
->dma_adc
.fragsize
)
1695 wake_up(&s
->dma_adc
.wait
);
1696 if (!s
->dma_adc
.mapped
) {
1697 if (s
->dma_adc
.count
> (signed)(s
->dma_adc
.dmasize
- ((3 * s
->dma_adc
.fragsize
) >> 1))) {
1698 s
->enable
&= ~TRIDENT_ENABLE_RE
;
1704 /* update DAC pointer */
1705 if (s
->dma_dac
.ready
)
1707 /* this is so gross. */
1708 hwptr
= (/*s->dma_dac.dmasize -*/ get_dmaa(s
)) % s
->dma_dac
.dmasize
;
1709 diff
= (s
->dma_dac
.dmasize
+ hwptr
- s
->dma_dac
.hwptr
) % s
->dma_dac
.dmasize
;
1710 M_printk("(trident) updating dac: hwptr: %d diff: %d\n",hwptr
,diff
);
1711 s
->dma_dac
.hwptr
= hwptr
;
1712 s
->dma_dac
.total_bytes
+= diff
;
1713 if (s
->dma_dac
.mapped
)
1715 s
->dma_dac
.count
+= diff
;
1716 if (s
->dma_dac
.count
>= (signed)s
->dma_dac
.fragsize
)
1717 wake_up(&s
->dma_dac
.wait
);
1721 s
->dma_dac
.count
-= diff
;
1722 M_printk("(trident) trident_update_ptr: diff: %d, count: %d\n", diff
, s
->dma_dac
.count
);
1723 if (s
->dma_dac
.count
<= 0)
1725 s
->enable
&= ~TRIDENT_ENABLE_PE
;
1726 /* Lock already held */
1728 /* brute force everyone back in sync, sigh */
1729 s
->dma_dac
.count
= 0;
1730 s
->dma_dac
.swptr
= 0;
1731 s
->dma_dac
.hwptr
= 0;
1734 else if (s
->dma_dac
.count
<= (signed)s
->dma_dac
.fragsize
&&
1735 !s
->dma_dac
.endcleared
)
1738 s
->dma_dac
.endcleared
= 1;
1741 if (s
->dma_dac
.count
+ (signed)s
->dma_dac
.fragsize
<= (signed)s
->dma_dac
.dmasize
)
1742 wake_up(&s
->dma_dac
.wait
);
1748 * Trident interrupt handlers.
1751 static void trident_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
1753 struct trident_state
*s
;
1754 struct trident_card
*c
= (struct trident_card
*)dev_id
;
1758 spin_lock(&c
->lock
);
1760 event
= inl(TRID_REG(c
, T4D_MISCINT
));
1763 // printk("IRQ %04X (%08lX, %08lX)\n", event, c->iobase, TRID_REG(c, T4D_MISCINT));
1773 * Update the pointers for all channels we are running.
1776 for(i
=0;i
<NR_DSPS
;i
++)
1779 if(DidChannelInterrupt(c
, i
))
1781 AckChannelInterrupt(c
,i
);
1782 if(s
->dev_audio
!= -1)
1783 trident_update_ptr(s
);
1787 M_printk("(trident) spurious channel irq %d.\n", i
);
1788 trident_stop_voice(c
, i
);
1789 trident_disable_voice_irq(c
,i
);
1795 spin_unlock(&c
->lock
);
1799 /* --------------------------------------------------------------------- */
1801 static const char invalid_magic
[] = KERN_CRIT
"trident: invalid magic value in %s\n";
1803 #define VALIDATE_MAGIC(FOO,MAG) \
1805 if (!(FOO) || (FOO)->magic != MAG) { \
1806 printk(invalid_magic,__FUNCTION__); \
1811 #define VALIDATE_STATE(a) VALIDATE_MAGIC(a,TRIDENT_STATE_MAGIC)
1812 #define VALIDATE_CARD(a) VALIDATE_MAGIC(a,TRIDENT_CARD_MAGIC)
1814 static void set_mixer(struct trident_card
*card
,unsigned int mixer
, unsigned int val
)
1816 unsigned int left
,right
;
1817 /* cleanse input a little */
1818 right
= ((val
>> 8) & 0xff) ;
1819 left
= (val
& 0xff) ;
1821 if(right
> 100) right
= 100;
1822 if(left
> 100) left
= 100;
1824 card
->mix
.mixer_state
[mixer
]=(right
<< 8) | left
;
1825 card
->mix
.write_mixer(card
,mixer
,left
,right
);
1828 static int mixer_ioctl(struct trident_card
*card
, unsigned int cmd
, unsigned long arg
)
1830 unsigned long flags
;
1833 VALIDATE_CARD(card
);
1834 if (cmd
== SOUND_MIXER_INFO
) {
1836 strncpy(info
.id
, card_names
[card
->card_type
], sizeof(info
.id
));
1837 strncpy(info
.name
,card_names
[card
->card_type
],sizeof(info
.name
));
1838 info
.modify_counter
= card
->mix
.modcnt
;
1839 if (copy_to_user((void *)arg
, &info
, sizeof(info
)))
1843 if (cmd
== SOUND_OLD_MIXER_INFO
) {
1844 _old_mixer_info info
;
1845 strncpy(info
.id
, card_names
[card
->card_type
], sizeof(info
.id
));
1846 strncpy(info
.name
,card_names
[card
->card_type
],sizeof(info
.name
));
1847 if (copy_to_user((void *)arg
, &info
, sizeof(info
)))
1851 if (cmd
== OSS_GETVERSION
)
1852 return put_user(SOUND_VERSION
, (int *)arg
);
1854 if (_IOC_TYPE(cmd
) != 'M' || _IOC_SIZE(cmd
) != sizeof(int))
1857 if (_IOC_DIR(cmd
) == _IOC_READ
) {
1858 switch (_IOC_NR(cmd
)) {
1859 case SOUND_MIXER_RECSRC
: /* give them the current record source */
1861 if(!card
->mix
.recmask_io
) {
1864 spin_lock_irqsave(&card
->lock
, flags
);
1865 val
= card
->mix
.recmask_io(card
,1,0);
1866 spin_unlock_irqrestore(&card
->lock
, flags
);
1870 case SOUND_MIXER_DEVMASK
: /* give them the supported mixers */
1871 val
= card
->mix
.supported_mixers
;
1874 case SOUND_MIXER_RECMASK
: /* Arg contains a bit for each supported recording source */
1875 val
= card
->mix
.record_sources
;
1878 case SOUND_MIXER_STEREODEVS
: /* Mixer channels supporting stereo */
1879 val
= card
->mix
.stereo_mixers
;
1882 case SOUND_MIXER_CAPS
:
1883 val
= SOUND_CAP_EXCL_INPUT
;
1886 default: /* read a specific mixer */
1889 if ( ! supported_mixer(card
,i
))
1892 /* do we ever want to touch the hardware? */
1893 /* spin_lock_irqsave(&s->lock, flags);
1894 val = card->mix.read_mixer(card,i);
1895 spin_unlock_irqrestore(&s->lock, flags);*/
1897 val
= card
->mix
.mixer_state
[i
];
1898 /* printk("returned 0x%x for mixer %d\n",val,i);*/
1902 return put_user(val
,(int *)arg
);
1905 if (_IOC_DIR(cmd
) != (_IOC_WRITE
|_IOC_READ
))
1910 get_user_ret(val
, (int *)arg
, -EFAULT
);
1912 switch (_IOC_NR(cmd
)) {
1913 case SOUND_MIXER_RECSRC
: /* Arg contains a bit for each recording source */
1915 if (!card
->mix
.recmask_io
) return -EINVAL
;
1916 if(! (val
&= card
->mix
.record_sources
)) return -EINVAL
;
1918 spin_lock_irqsave(&card
->lock
, flags
);
1919 card
->mix
.recmask_io(card
,0,val
);
1920 spin_unlock_irqrestore(&card
->lock
, flags
);
1926 if ( ! supported_mixer(card
,i
))
1929 spin_lock_irqsave(&card
->lock
, flags
);
1930 set_mixer(card
,i
,val
);
1931 spin_unlock_irqrestore(&card
->lock
, flags
);
1937 /* --------------------------------------------------------------------- */
1939 static loff_t
trident_llseek(struct file
*file
, loff_t offset
, int origin
)
1944 /* --------------------------------------------------------------------- */
1946 static int trident_open_mixdev(struct inode
*inode
, struct file
*file
)
1948 int minor
= MINOR(inode
->i_rdev
);
1949 struct trident_card
*card
= devs
;
1951 while (card
&& card
->dev_mixer
!= minor
)
1956 file
->private_data
= card
;
1958 //MOD_INC_USE_COUNT;
1962 static int trident_release_mixdev(struct inode
*inode
, struct file
*file
)
1964 struct trident_card
*card
= (struct trident_card
*)file
->private_data
;
1966 VALIDATE_CARD(card
);
1969 //MOD_DEC_USE_COUNT;
1973 static int trident_ioctl_mixdev(struct inode
*inode
, struct file
*file
, unsigned int cmd
, unsigned long arg
)
1975 struct trident_card
*card
= (struct trident_card
*)file
->private_data
;
1977 VALIDATE_CARD(card
);
1979 return mixer_ioctl(card
, cmd
, arg
);
1982 static /*const*/ struct file_operations trident_mixer_fops
= {
1988 &trident_ioctl_mixdev
,
1990 &trident_open_mixdev
,
1992 &trident_release_mixdev
,
1995 NULL
, /* check_media_change */
1996 NULL
, /* revalidate */
2000 /* --------------------------------------------------------------------- */
2002 static int drain_dac(struct trident_state
*s
, int nonblock
)
2004 DECLARE_WAITQUEUE(wait
, current
);
2005 unsigned long flags
;
2009 if (s
->dma_dac
.mapped
|| !s
->dma_dac
.ready
)
2011 current
->state
= TASK_INTERRUPTIBLE
;
2012 add_wait_queue(&s
->dma_dac
.wait
, &wait
);
2016 spin_lock_irqsave(&s
->card
->lock
, flags
);
2017 count
= s
->dma_dac
.count
;
2018 spin_unlock_irqrestore(&s
->card
->lock
, flags
);
2023 if (signal_pending(current
))
2028 remove_wait_queue(&s
->dma_dac
.wait
, &wait
);
2029 current
->state
= TASK_RUNNING
;
2033 tmo
= (count
* HZ
) / s
->ratedac
;
2034 tmo
>>= sample_shift
[(s
->fmt
>> TRIDENT_DAC_SHIFT
) & TRIDENT_FMT_MASK
];
2036 /* XXX this is just broken. someone is waking us up alot, or schedule_timeout is broken.
2037 or something. who cares. - zach */
2038 if (!schedule_timeout(tmo
? tmo
: 1) && tmo
)
2039 printk(KERN_DEBUG
"trident: dma timed out?? %ld\n",jiffies
);
2041 remove_wait_queue(&s
->dma_dac
.wait
, &wait
);
2042 current
->state
= TASK_RUNNING
;
2043 if (signal_pending(current
))
2044 return -ERESTARTSYS
;
2048 /* --------------------------------------------------------------------- */
2050 /* in this loop, dma_adc.count signifies the amount of data thats waiting
2051 to be copied to the user's buffer. it is filled by the interrupt
2052 handler and drained by this loop. */
2053 static ssize_t
trident_read(struct file
*file
, char *buffer
, size_t count
, loff_t
*ppos
)
2055 struct trident_state
*s
= (struct trident_state
*)file
->private_data
;
2057 unsigned long flags
;
2062 if (ppos
!= &file
->f_pos
)
2064 if (s
->dma_adc
.mapped
)
2066 if (!s
->dma_adc
.ready
&& (ret
= prog_dmabuf(s
, 1)))
2068 if (!access_ok(VERIFY_WRITE
, buffer
, count
))
2073 spin_lock_irqsave(&s
->card
->lock
, flags
);
2074 /* remember, all these things are expressed in bytes to be
2075 sent to the user.. hence the evil / 2 down below */
2076 swptr
= s
->dma_adc
.swptr
;
2077 cnt
= s
->dma_adc
.dmasize
-swptr
;
2078 if (s
->dma_adc
.count
< cnt
)
2079 cnt
= s
->dma_adc
.count
;
2080 spin_unlock_irqrestore(&s
->card
->lock
, flags
);
2087 if (file
->f_flags
& O_NONBLOCK
)
2089 ret
= ret
? ret
: -EAGAIN
;
2092 if (!interruptible_sleep_on_timeout(&s
->dma_adc
.wait
, HZ
)) {
2093 M_printk(KERN_DEBUG
"(trident) read: chip lockup? dmasz %u fragsz %u count %i hwptr %u swptr %u\n",
2094 s
->dma_adc
.dmasize
, s
->dma_adc
.fragsize
, s
->dma_adc
.count
,
2095 s
->dma_adc
.hwptr
, s
->dma_adc
.swptr
);
2097 spin_lock_irqsave(&s
->card
->lock
, flags
);
2098 // set_dmac(s, virt_to_bus(s->dma_adc.rawbuf), s->dma_adc.numfrag << s->dma_adc.fragshift);
2099 s
->dma_adc
.count
= s
->dma_adc
.hwptr
= s
->dma_adc
.swptr
= 0;
2100 spin_unlock_irqrestore(&s
->card
->lock
, flags
);
2102 if (signal_pending(current
))
2104 ret
= ret
? ret
: -ERESTARTSYS
;
2110 if (copy_to_user(buffer
, s
->dma_adc
.rawbuf
+ swptr
, cnt
)) {
2111 ret
= ret
? ret
: -EFAULT
;
2115 swptr
= (swptr
+ cnt
) % s
->dma_adc
.dmasize
;
2116 spin_lock_irqsave(&s
->card
->lock
, flags
);
2117 s
->dma_adc
.swptr
= swptr
;
2118 s
->dma_adc
.count
-= cnt
;
2119 spin_unlock_irqrestore(&s
->card
->lock
, flags
);
2129 static ssize_t
trident_write(struct file
*file
, const char *buffer
, size_t count
, loff_t
*ppos
)
2131 struct trident_state
*s
= (struct trident_state
*)file
->private_data
;
2133 unsigned long flags
;
2136 int mode
= (s
->fmt
>> TRIDENT_DAC_SHIFT
) & TRIDENT_FMT_MASK
;
2138 M_printk("(trident) trident_write: count %d\n", count
);
2141 if (ppos
!= &file
->f_pos
)
2143 if (s
->dma_dac
.mapped
)
2145 if (!s
->dma_dac
.ready
&& (ret
= prog_dmabuf(s
, 0)))
2147 if (!access_ok(VERIFY_READ
, buffer
, count
))
2152 spin_lock_irqsave(&s
->card
->lock
, flags
);
2154 if (s
->dma_dac
.count
< 0)
2156 s
->dma_dac
.count
= 0;
2157 s
->dma_dac
.swptr
= s
->dma_dac
.hwptr
;
2159 swptr
= s
->dma_dac
.swptr
;
2161 cnt
= s
->dma_dac
.dmasize
-swptr
;
2163 if (s
->dma_dac
.count
+ cnt
> s
->dma_dac
.dmasize
)
2164 cnt
= s
->dma_dac
.dmasize
- s
->dma_dac
.count
;
2166 spin_unlock_irqrestore(&s
->card
->lock
, flags
);
2173 /* buffer is full, wait for it to be played */
2175 if (file
->f_flags
& O_NONBLOCK
)
2177 if(!ret
) ret
= -EAGAIN
;
2180 if (!interruptible_sleep_on_timeout(&s
->dma_dac
.wait
, HZ
))
2183 "trident: write: chip lockup? dmasz %u fragsz %u count %i hwptr %u swptr %u\n",
2184 s
->dma_dac
.dmasize
, s
->dma_dac
.fragsize
, s
->dma_dac
.count
, s
->dma_dac
.hwptr
,
2187 spin_lock_irqsave(&s
->card
->lock
, flags
);
2188 // set_dmaa(s, virt_to_bus(s->dma_dac.rawbuf), s->dma_dac.numfrag << s->dma_dac.fragshift);
2189 s
->dma_dac
.count
= s
->dma_dac
.hwptr
= s
->dma_dac
.swptr
= 0;
2190 spin_unlock_irqrestore(&s
->card
->lock
, flags
);
2192 if (signal_pending(current
))
2194 if (!ret
) ret
= -ERESTARTSYS
;
2199 if (copy_from_user(s
->dma_dac
.rawbuf
+ swptr
, buffer
, cnt
))
2206 swptr
= (swptr
+ cnt
) % s
->dma_dac
.dmasize
;
2208 spin_lock_irqsave(&s
->card
->lock
, flags
);
2209 s
->dma_dac
.swptr
= swptr
;
2210 s
->dma_dac
.count
+= cnt
;
2211 s
->dma_dac
.endcleared
= 0;
2212 spin_unlock_irqrestore(&s
->card
->lock
, flags
);
2221 static unsigned int trident_poll(struct file
*file
, struct poll_table_struct
*wait
)
2223 struct trident_state
*s
= (struct trident_state
*)file
->private_data
;
2224 unsigned long flags
;
2225 unsigned int mask
= 0;
2228 if (file
->f_mode
& FMODE_WRITE
)
2229 poll_wait(file
, &s
->dma_dac
.wait
, wait
);
2230 if (file
->f_mode
& FMODE_READ
)
2231 poll_wait(file
, &s
->dma_adc
.wait
, wait
);
2232 spin_lock_irqsave(&s
->card
->lock
, flags
);
2233 trident_update_ptr(s
);
2234 if (file
->f_mode
& FMODE_READ
) {
2235 if (s
->dma_adc
.count
>= (signed)s
->dma_adc
.fragsize
)
2236 mask
|= POLLIN
| POLLRDNORM
;
2238 if (file
->f_mode
& FMODE_WRITE
) {
2239 if (s
->dma_dac
.mapped
) {
2240 if (s
->dma_dac
.count
>= (signed)s
->dma_dac
.fragsize
)
2241 mask
|= POLLOUT
| POLLWRNORM
;
2243 if ((signed)s
->dma_dac
.dmasize
>= s
->dma_dac
.count
+ (signed)s
->dma_dac
.fragsize
)
2244 mask
|= POLLOUT
| POLLWRNORM
;
2247 spin_unlock_irqrestore(&s
->card
->lock
, flags
);
2251 /* this needs to be fixed to deal with the dual apus/buffers */
2253 static int trident_mmap(struct file
*file
, struct vm_area_struct
*vma
)
2255 struct trident_state
*s
= (struct trident_state
*)file
->private_data
;
2261 if (vma
->vm_flags
& VM_WRITE
) {
2262 if ((ret
= prog_dmabuf(s
, 1)) != 0)
2265 } else if (vma
->vm_flags
& VM_READ
) {
2266 if ((ret
= prog_dmabuf(s
, 0)) != 0)
2271 if (vma
->vm_offset
!= 0)
2273 size
= vma
->vm_end
- vma
->vm_start
;
2274 if (size
> (PAGE_SIZE
<< db
->buforder
))
2276 if (remap_page_range(vma
->vm_start
, virt_to_phys(db
->rawbuf
), size
, vma
->vm_page_prot
))
2283 static int trident_ioctl(struct inode
*inode
, struct file
*file
, unsigned int cmd
, unsigned long arg
)
2285 struct trident_state
*s
= (struct trident_state
*)file
->private_data
;
2286 unsigned long flags
;
2287 audio_buf_info abinfo
;
2289 int val
, mapped
, ret
;
2290 unsigned char fmtm
, fmtd
;
2292 /* printk("trident: trident_ioctl: cmd %d\n", cmd);*/
2295 mapped
= ((file
->f_mode
& FMODE_WRITE
) && s
->dma_dac
.mapped
) ||
2296 ((file
->f_mode
& FMODE_READ
) && s
->dma_adc
.mapped
);
2300 case OSS_GETVERSION
:
2301 return put_user(SOUND_VERSION
, (int *)arg
);
2303 case SNDCTL_DSP_SYNC
:
2304 if (file
->f_mode
& FMODE_WRITE
)
2305 return drain_dac(s
, file
->f_flags
& O_NONBLOCK
);
2308 case SNDCTL_DSP_SETDUPLEX
:
2312 case SNDCTL_DSP_GETCAPS
:
2313 return put_user(0/*DSP_CAP_DUPLEX | DSP_CAP_REALTIME | DSP_CAP_TRIGGER | DSP_CAP_MMAP*/, (int *)arg
);
2315 case SNDCTL_DSP_RESET
:
2316 if (file
->f_mode
& FMODE_WRITE
)
2320 s
->dma_dac
.swptr
= s
->dma_dac
.hwptr
= s
->dma_dac
.count
= s
->dma_dac
.total_bytes
= 0;
2322 if (file
->f_mode
& FMODE_READ
)
2326 s
->dma_adc
.swptr
= s
->dma_adc
.hwptr
= s
->dma_adc
.count
= s
->dma_adc
.total_bytes
= 0;
2330 case SNDCTL_DSP_SPEED
:
2331 get_user_ret(val
, (int *)arg
, -EFAULT
);
2334 if (file
->f_mode
& FMODE_READ
)
2337 s
->dma_adc
.ready
= 0;
2338 trident_set_adc_rate(s
, val
, 1);
2340 if (file
->f_mode
& FMODE_WRITE
)
2343 s
->dma_dac
.ready
= 0;
2344 trident_set_dac_rate(s
, val
, 1);
2347 return put_user((file
->f_mode
& FMODE_READ
) ? s
->rateadc
: s
->ratedac
, (int *)arg
);
2349 case SNDCTL_DSP_STEREO
:
2350 get_user_ret(val
, (int *)arg
, -EFAULT
);
2353 if (file
->f_mode
& FMODE_READ
)
2356 s
->dma_adc
.ready
= 0;
2358 fmtd
|= TRIDENT_FMT_STEREO
<< TRIDENT_ADC_SHIFT
;
2360 fmtm
&= ~(TRIDENT_FMT_STEREO
<< TRIDENT_ADC_SHIFT
);
2362 if (file
->f_mode
& FMODE_WRITE
)
2365 s
->dma_dac
.ready
= 0;
2367 fmtd
|= TRIDENT_FMT_STEREO
<< TRIDENT_DAC_SHIFT
;
2369 fmtm
&= ~(TRIDENT_FMT_STEREO
<< TRIDENT_DAC_SHIFT
);
2371 set_fmt(s
, fmtm
, fmtd
);
2375 case SNDCTL_DSP_CHANNELS
:
2376 get_user_ret(val
, (int *)arg
, -EFAULT
);
2382 if (file
->f_mode
& FMODE_READ
)
2385 s
->dma_adc
.ready
= 0;
2387 fmtd
|= TRIDENT_FMT_STEREO
<< TRIDENT_ADC_SHIFT
;
2389 fmtm
&= ~(TRIDENT_FMT_STEREO
<< TRIDENT_ADC_SHIFT
);
2392 if (file
->f_mode
& FMODE_WRITE
)
2395 s
->dma_dac
.ready
= 0;
2397 fmtd
|= TRIDENT_FMT_STEREO
<< TRIDENT_DAC_SHIFT
;
2399 fmtm
&= ~(TRIDENT_FMT_STEREO
<< TRIDENT_DAC_SHIFT
);
2401 set_fmt(s
, fmtm
, fmtd
);
2403 return put_user((s
->fmt
& ((file
->f_mode
& FMODE_READ
) ?
2404 (TRIDENT_FMT_STEREO
<< TRIDENT_ADC_SHIFT
) :
2405 (TRIDENT_FMT_STEREO
<< TRIDENT_DAC_SHIFT
))) ? 2 : 1, (int *)arg
);
2407 case SNDCTL_DSP_GETFMTS
: /* Returns a mask */
2408 return put_user(AFMT_S8
|AFMT_S16_LE
, (int *)arg
);
2410 case SNDCTL_DSP_SETFMT
: /* Selects ONE fmt*/
2411 get_user_ret(val
, (int *)arg
, -EFAULT
);
2412 if (val
!= AFMT_QUERY
)
2416 if (file
->f_mode
& FMODE_READ
)
2419 s
->dma_adc
.ready
= 0;
2420 /* fixed at 16bit for now */
2421 fmtd
|= TRIDENT_FMT_16BIT
<< TRIDENT_ADC_SHIFT
;
2423 if (val
== AFMT_S16_LE
)
2424 fmtd
|= TRIDENT_FMT_16BIT
<< TRIDENT_ADC_SHIFT
;
2426 fmtm
&= ~(TRIDENT_FMT_16BIT
<< TRIDENT_ADC_SHIFT
);
2429 if (file
->f_mode
& FMODE_WRITE
)
2432 s
->dma_dac
.ready
= 0;
2433 if (val
== AFMT_S16_LE
)
2434 fmtd
|= TRIDENT_FMT_16BIT
<< TRIDENT_DAC_SHIFT
;
2436 fmtm
&= ~(TRIDENT_FMT_16BIT
<< TRIDENT_DAC_SHIFT
);
2438 set_fmt(s
, fmtm
, fmtd
);
2440 return put_user((s
->fmt
& ((file
->f_mode
& FMODE_READ
) ?
2441 (TRIDENT_FMT_16BIT
<< TRIDENT_ADC_SHIFT
) :
2442 (TRIDENT_FMT_16BIT
<< TRIDENT_DAC_SHIFT
))) ?
2443 AFMT_S16_LE
: AFMT_S8
, (int *)arg
);
2445 case SNDCTL_DSP_POST
:
2448 case SNDCTL_DSP_GETTRIGGER
:
2450 if (file
->f_mode
& FMODE_READ
&& s
->enable
& TRIDENT_ENABLE_RE
)
2451 val
|= PCM_ENABLE_INPUT
;
2452 if (file
->f_mode
& FMODE_WRITE
&& s
->enable
& TRIDENT_ENABLE_PE
)
2453 val
|= PCM_ENABLE_OUTPUT
;
2454 return put_user(val
, (int *)arg
);
2456 case SNDCTL_DSP_SETTRIGGER
:
2457 get_user_ret(val
, (int *)arg
, -EFAULT
);
2458 if (file
->f_mode
& FMODE_READ
)
2460 if (val
& PCM_ENABLE_INPUT
)
2462 if (!s
->dma_adc
.ready
&& (ret
= prog_dmabuf(s
, 1)))
2469 if (file
->f_mode
& FMODE_WRITE
)
2471 if (val
& PCM_ENABLE_OUTPUT
)
2473 if (!s
->dma_dac
.ready
&& (ret
= prog_dmabuf(s
, 0)))
2482 case SNDCTL_DSP_GETOSPACE
:
2483 if (!(file
->f_mode
& FMODE_WRITE
))
2485 if (!(s
->enable
& TRIDENT_ENABLE_PE
) && (val
= prog_dmabuf(s
, 0)) != 0)
2487 spin_lock_irqsave(&s
->card
->lock
, flags
);
2488 trident_update_ptr(s
);
2489 abinfo
.fragsize
= s
->dma_dac
.fragsize
;
2490 abinfo
.bytes
= s
->dma_dac
.dmasize
- s
->dma_dac
.count
;
2491 abinfo
.fragstotal
= s
->dma_dac
.numfrag
;
2492 abinfo
.fragments
= abinfo
.bytes
>> s
->dma_dac
.fragshift
;
2493 spin_unlock_irqrestore(&s
->card
->lock
, flags
);
2494 return copy_to_user((void *)arg
, &abinfo
, sizeof(abinfo
)) ? -EFAULT
: 0;
2496 case SNDCTL_DSP_GETISPACE
:
2497 if (!(file
->f_mode
& FMODE_READ
))
2499 if (!(s
->enable
& TRIDENT_ENABLE_RE
) && (val
= prog_dmabuf(s
, 1)) != 0)
2501 spin_lock_irqsave(&s
->card
->lock
, flags
);
2502 trident_update_ptr(s
);
2503 abinfo
.fragsize
= s
->dma_adc
.fragsize
;
2504 abinfo
.bytes
= s
->dma_adc
.count
;
2505 abinfo
.fragstotal
= s
->dma_adc
.numfrag
;
2506 abinfo
.fragments
= abinfo
.bytes
>> s
->dma_adc
.fragshift
;
2507 spin_unlock_irqrestore(&s
->card
->lock
, flags
);
2508 return copy_to_user((void *)arg
, &abinfo
, sizeof(abinfo
)) ? -EFAULT
: 0;
2510 case SNDCTL_DSP_NONBLOCK
:
2511 file
->f_flags
|= O_NONBLOCK
;
2514 case SNDCTL_DSP_GETODELAY
:
2515 if (!(file
->f_mode
& FMODE_WRITE
))
2517 spin_lock_irqsave(&s
->card
->lock
, flags
);
2518 trident_update_ptr(s
);
2519 val
= s
->dma_dac
.count
;
2520 spin_unlock_irqrestore(&s
->card
->lock
, flags
);
2521 return put_user(val
, (int *)arg
);
2523 case SNDCTL_DSP_GETIPTR
:
2524 if (!(file
->f_mode
& FMODE_READ
))
2526 spin_lock_irqsave(&s
->card
->lock
, flags
);
2527 trident_update_ptr(s
);
2528 cinfo
.bytes
= s
->dma_adc
.total_bytes
;
2529 cinfo
.blocks
= s
->dma_adc
.count
>> s
->dma_adc
.fragshift
;
2530 cinfo
.ptr
= s
->dma_adc
.hwptr
;
2531 if (s
->dma_adc
.mapped
)
2532 s
->dma_adc
.count
&= s
->dma_adc
.fragsize
-1;
2533 spin_unlock_irqrestore(&s
->card
->lock
, flags
);
2534 return copy_to_user((void *)arg
, &cinfo
, sizeof(cinfo
));
2536 case SNDCTL_DSP_GETOPTR
:
2537 if (!(file
->f_mode
& FMODE_WRITE
))
2539 spin_lock_irqsave(&s
->card
->lock
, flags
);
2540 trident_update_ptr(s
);
2541 cinfo
.bytes
= s
->dma_dac
.total_bytes
;
2542 cinfo
.blocks
= s
->dma_dac
.count
>> s
->dma_dac
.fragshift
;
2543 cinfo
.ptr
= s
->dma_dac
.hwptr
;
2544 if (s
->dma_dac
.mapped
)
2545 s
->dma_dac
.count
&= s
->dma_dac
.fragsize
-1;
2546 spin_unlock_irqrestore(&s
->card
->lock
, flags
);
2547 return copy_to_user((void *)arg
, &cinfo
, sizeof(cinfo
));
2549 case SNDCTL_DSP_GETBLKSIZE
:
2550 if (file
->f_mode
& FMODE_WRITE
)
2552 if ((val
= prog_dmabuf(s
, 0)))
2554 return put_user(s
->dma_dac
.fragsize
, (int *)arg
);
2556 if ((val
= prog_dmabuf(s
, 1)))
2558 return put_user(s
->dma_adc
.fragsize
, (int *)arg
);
2560 case SNDCTL_DSP_SETFRAGMENT
:
2561 get_user_ret(val
, (int *)arg
, -EFAULT
);
2562 if (file
->f_mode
& FMODE_READ
)
2564 s
->dma_adc
.ossfragshift
= val
& 0xffff;
2565 s
->dma_adc
.ossmaxfrags
= (val
>> 16) & 0xffff;
2566 if (s
->dma_adc
.ossfragshift
< 4)
2567 s
->dma_adc
.ossfragshift
= 4;
2568 if (s
->dma_adc
.ossfragshift
> 15)
2569 s
->dma_adc
.ossfragshift
= 15;
2570 if (s
->dma_adc
.ossmaxfrags
< 4)
2571 s
->dma_adc
.ossmaxfrags
= 4;
2573 if (file
->f_mode
& FMODE_WRITE
)
2575 s
->dma_dac
.ossfragshift
= val
& 0xffff;
2576 s
->dma_dac
.ossmaxfrags
= (val
>> 16) & 0xffff;
2577 if (s
->dma_dac
.ossfragshift
< 4)
2578 s
->dma_dac
.ossfragshift
= 4;
2579 if (s
->dma_dac
.ossfragshift
> 15)
2580 s
->dma_dac
.ossfragshift
= 15;
2581 if (s
->dma_dac
.ossmaxfrags
< 4)
2582 s
->dma_dac
.ossmaxfrags
= 4;
2586 case SNDCTL_DSP_SUBDIVIDE
:
2587 if ((file
->f_mode
& FMODE_READ
&& s
->dma_adc
.subdivision
) ||
2588 (file
->f_mode
& FMODE_WRITE
&& s
->dma_dac
.subdivision
))
2590 get_user_ret(val
, (int *)arg
, -EFAULT
);
2591 if (val
!= 1 && val
!= 2 && val
!= 4)
2593 if (file
->f_mode
& FMODE_READ
)
2594 s
->dma_adc
.subdivision
= val
;
2595 if (file
->f_mode
& FMODE_WRITE
)
2596 s
->dma_dac
.subdivision
= val
;
2599 case SOUND_PCM_READ_RATE
:
2600 return put_user((file
->f_mode
& FMODE_READ
) ? s
->rateadc
: s
->ratedac
, (int *)arg
);
2602 case SOUND_PCM_READ_CHANNELS
:
2603 return put_user((s
->fmt
& ((file
->f_mode
& FMODE_READ
) ?
2604 (TRIDENT_FMT_STEREO
<< TRIDENT_ADC_SHIFT
) :
2605 (TRIDENT_FMT_STEREO
<< TRIDENT_DAC_SHIFT
))) ? 2 : 1, (int *)arg
);
2607 case SOUND_PCM_READ_BITS
:
2608 return put_user((s
->fmt
& ((file
->f_mode
& FMODE_READ
) ?
2609 (TRIDENT_FMT_16BIT
<< TRIDENT_ADC_SHIFT
) :
2610 (TRIDENT_FMT_16BIT
<< TRIDENT_DAC_SHIFT
))) ? 16 : 8, (int *)arg
);
2612 case SOUND_PCM_WRITE_FILTER
:
2613 case SNDCTL_DSP_SETSYNCRO
:
2614 case SOUND_PCM_READ_FILTER
:
2621 static int trident_open(struct inode
*inode
, struct file
*file
)
2623 int minor
= MINOR(inode
->i_rdev
);
2624 struct trident_card
*c
= devs
;
2625 struct trident_state
*s
= NULL
, *sp
;
2627 unsigned char fmtm
= ~0, fmts
= 0;
2630 * Scan the cards and find the channel. We only
2631 * do this at open time so it is ok
2636 for(i
=0;i
<NR_DSPS
;i
++)
2639 if(sp
->dev_audio
< 0)
2641 if((sp
->dev_audio
^ minor
) & ~0xf)
2652 file
->private_data
= s
;
2653 /* wait for device to become free */
2655 while (s
->open_mode
& file
->f_mode
)
2657 if (file
->f_flags
& O_NONBLOCK
)
2660 return -EWOULDBLOCK
;
2663 interruptible_sleep_on(&s
->open_wait
);
2664 if (signal_pending(current
))
2665 return -ERESTARTSYS
;
2668 if (file
->f_mode
& FMODE_READ
)
2671 fmtm &= ~((TRIDENT_FMT_STEREO | TRIDENT_FMT_16BIT) << TRIDENT_ADC_SHIFT);
2672 if ((minor & 0xf) == SND_DEV_DSP16)
2673 fmts |= TRIDENT_FMT_16BIT << TRIDENT_ADC_SHIFT; */
2675 fmtm
= (TRIDENT_FMT_STEREO
|TRIDENT_FMT_16BIT
) << TRIDENT_ADC_SHIFT
;
2677 s
->dma_adc
.ossfragshift
= s
->dma_adc
.ossmaxfrags
= s
->dma_adc
.subdivision
= 0;
2678 trident_set_adc_rate(s
, 8000, 0);
2680 if (file
->f_mode
& FMODE_WRITE
)
2682 fmtm
&= ~((TRIDENT_FMT_STEREO
| TRIDENT_FMT_16BIT
) << TRIDENT_DAC_SHIFT
);
2683 if ((minor
& 0xf) == SND_DEV_DSP16
)
2684 fmts
|= TRIDENT_FMT_16BIT
<< TRIDENT_DAC_SHIFT
;
2685 s
->dma_dac
.ossfragshift
= s
->dma_dac
.ossmaxfrags
= s
->dma_dac
.subdivision
= 0;
2686 trident_set_dac_rate(s
, 8000, 1);
2688 set_fmt(s
, fmtm
, fmts
);
2689 s
->open_mode
|= file
->f_mode
& (FMODE_READ
| FMODE_WRITE
);
2693 //MOD_INC_USE_COUNT;
2697 static int trident_release(struct inode
*inode
, struct file
*file
)
2699 struct trident_state
*s
= (struct trident_state
*)file
->private_data
;
2702 if (file
->f_mode
& FMODE_WRITE
)
2703 drain_dac(s
, file
->f_flags
& O_NONBLOCK
);
2705 if (file
->f_mode
& FMODE_WRITE
) {
2708 if (file
->f_mode
& FMODE_READ
) {
2712 /* free our shared dma buffers */
2713 dealloc_dmabuf(&s
->dma_adc
);
2714 dealloc_dmabuf(&s
->dma_dac
);
2716 s
->open_mode
&= (~file
->f_mode
) & (FMODE_READ
|FMODE_WRITE
);
2717 /* we're covered by the open_sem */
2719 wake_up(&s
->open_wait
);
2721 //MOD_DEC_USE_COUNT;
2725 static /*const*/ struct file_operations trident_audio_fops
= {
2732 NULL
, /* XXX &trident_mmap, */
2738 NULL
, /* check_media_change */
2739 NULL
, /* revalidate */
2744 int trident_apm_callback(apm_event_t ae
) {
2748 /* --------------------------------------------------------------------- */
2750 static int trident_install(struct pci_dev
*pcidev
, int card_type
)
2754 unsigned long iobase
;
2756 struct trident_card
*card
;
2757 struct trident_state
*trident
;
2761 iobase
= pcidev
->resource
[0].start
;
2763 if(check_region(iobase
, 256))
2765 M_printk(KERN_WARNING
"(trident) can't allocate 256 bytes I/O at 0x%4.4lx\n", iobase
);
2769 /* this was tripping up some machines */
2770 if(pcidev
->irq
== 0)
2772 printk(KERN_WARNING
"(trident) pci subsystem reports irq 0, this might not be correct.\n");
2775 /* just to be sure */
2776 pci_set_master(pcidev
);
2778 pci_read_config_word(pcidev
, PCI_COMMAND
, &w
);
2779 if((w
&(PCI_COMMAND_IO
|PCI_COMMAND_MASTER
)) != (PCI_COMMAND_IO
|PCI_COMMAND_MASTER
))
2781 printk("(trident) BIOS did not enable I/O access.\n");
2782 w
|=PCI_COMMAND_IO
|PCI_COMMAND_MASTER
;
2783 pci_write_config_word(pcidev
, PCI_COMMAND
,w
);
2786 card
= kmalloc(sizeof(struct trident_card
), GFP_KERNEL
);
2790 printk(KERN_WARNING
"(trident) out of memory\n");
2794 memset(card
, 0, sizeof(*card
));
2797 printk("(trident) apm_reg_callback: %d\n",apm_register_callback(trident_apm_callback
));
2800 card
->iobase
= iobase
;
2801 card
->card_type
= card_type
;
2802 card
->irq
= pcidev
->irq
;
2804 card
->magic
= TRIDENT_CARD_MAGIC
;
2807 ChanDwordCount
= card
->ChanDwordCount
= 2;
2810 card
->ChRegs
.lpChStart
= card
->ChRegs
.data
;
2811 card
->ChRegs
.lpChStop
= card
->ChRegs
.lpChStart
+ ChanDwordCount
;
2812 card
->ChRegs
.lpChAint
= card
->ChRegs
.lpChStop
+ ChanDwordCount
;
2813 card
->ChRegs
.lpChAinten
= card
->ChRegs
.lpChAint
+ ChanDwordCount
;
2814 card
->ChRegs
.lpAChStart
= card
->ChRegs
.lpChAinten
+ ChanDwordCount
;
2815 card
->ChRegs
.lpAChStop
= card
->ChRegs
.lpAChStart
+ ChanDwordCount
;
2816 card
->ChRegs
.lpAChAint
= card
->ChRegs
.lpAChStop
+ ChanDwordCount
;
2817 card
->ChRegs
.lpAChAinten
= card
->ChRegs
.lpAChAint
+ ChanDwordCount
;
2818 // Assign addresses.
2819 card
->ChRegs
.lpAChStart
[0] = T4D_START_A
;
2820 card
->ChRegs
.lpAChStop
[0] = T4D_STOP_A
;
2821 card
->ChRegs
.lpAChAint
[0] = T4D_AINT_A
;
2822 card
->ChRegs
.lpAChAinten
[0] = T4D_AINTEN_A
;
2825 card
->ChRegs
.lpAChStart
[1] = T4D_START_B
;
2826 card
->ChRegs
.lpAChStop
[1] = T4D_STOP_B
;
2827 card
->ChRegs
.lpAChAint
[1] = T4D_AINT_B
;
2828 card
->ChRegs
.lpAChAinten
[1] = T4D_AINTEN_B
;
2831 outl(0x00, TRID_REG(card
, T4D_MUSICVOL_WAVEVOL
));
2832 trident_ac97_set(card
, 0x0L
, 0L);
2833 trident_ac97_set(card
, 0x02L
, 0L);
2834 trident_ac97_set(card
, 0x18L
, 0L);
2836 if(card
->card_type
== TYPE_4DWAVE_NX
)
2838 // Enable rear channels
2839 outl(0x12, TRID_REG(card
, NX_ACR0_AC97_COM_STAT
));
2840 // ...or not, since they sound ugly. :)
2841 // outl(0x02, TRID_REG(card, NX_ACR0_AC97_COM_STAT));
2842 // S/PDIF C Channel bits 0-31 : 48khz, SCMS disabled
2843 // outl(0x200004, TRID_REG(card, NX_SPCSTATUS));
2844 // Disable S/PDIF out, 48khz only from ac97 fifo
2845 // outb(0x00, TRID_REG(card, NX_SPCTRL_SPCSO + 3));
2849 outl(0x02, TRID_REG(card
, DX_ACR2_AC97_COM_STAT
));
2852 for(i
=0;i
<NR_DSPS
;i
++)
2854 struct trident_state
*s
=&card
->channels
[i
];
2857 init_waitqueue_head(&s
->dma_adc
.wait
);
2858 init_waitqueue_head(&s
->dma_dac
.wait
);
2859 init_waitqueue_head(&s
->open_wait
);
2860 init_MUTEX(&s
->open_sem
);
2861 s
->magic
= TRIDENT_STATE_MAGIC
;
2864 if(s
->dma_adc
.ready
|| s
->dma_dac
.ready
|| s
->dma_adc
.rawbuf
)
2865 printk("(trident) BOTCH!\n");
2868 * Now allocate the hardware resources
2871 //s->dma_dac.chan[0] = AllocateChannelPCM(card);
2872 s
->dma_dac
.chan
[1] = AllocateChannelPCM(card
);
2873 //s->dma_adc.chan[0] = AllocateChannelPCM(card);
2875 /* register devices */
2876 if ((s
->dev_audio
= register_sound_dsp(&trident_audio_fops
, -1)) < 0)
2882 /* clear the rest if we ran out of slots to register */
2885 struct trident_state
*s
=&card
->channels
[i
];
2889 trident
= &card
->channels
[0];
2892 * Ok card ready. Begin setup proper
2895 printk(KERN_INFO
"(trident) Configuring %s found at IO 0x%04lX IRQ %d\n",
2896 card_names
[card_type
],card
->iobase
,card
->irq
);
2899 /* stake our claim on the iospace */
2900 request_region(iobase
, 256, card_names
[card_type
]);
2906 trident_ac97_init(card
);
2908 if ((card
->dev_mixer
= register_sound_mixer(&trident_mixer_fops
, -1)) < 0)
2910 printk("(trident) couldn't register mixer!\n");
2915 for(i
= 0 ; i
< SOUND_MIXER_NRDEVICES
; i
++)
2917 struct mixer_defaults
*md
= &mixer_defaults
[i
];
2921 if(!supported_mixer(card
,md
->mixer
))
2923 set_mixer(card
,md
->mixer
,md
->value
);
2927 if(request_irq(card
->irq
, trident_interrupt
, SA_SHIRQ
, card_names
[card_type
], card
))
2929 printk(KERN_ERR
"(trident) unable to allocate irq %d,\n", card
->irq
);
2930 unregister_sound_mixer(card
->dev_mixer
);
2931 for(i
=0;i
<NR_DSPS
;i
++)
2933 struct trident_state
*s
= &card
->channels
[i
];
2934 if(s
->dev_audio
!= -1)
2935 unregister_sound_dsp(s
->dev_audio
);
2937 release_region(card
->iobase
, 256);
2942 init_timer(&debug_timer
);
2943 debug_timer
.function
= trident_kick
;
2944 debug_timer
.data
= (unsigned long)card
;
2945 debug_timer
.expires
= jiffies
+1;
2947 // add_timer(&debug_timer);
2949 printk("(trident) %d channels configured.\n", num
);
2951 EnableEndInterrupts(card
);
2956 int init_module(void)
2958 int __init
init_trident(void)
2961 struct pci_dev
*pcidev
= NULL
;
2964 if (!pci_present()) /* No PCI bus in this machine! */
2966 printk(KERN_INFO
"(trident) version " DRIVER_VERSION
" time " __TIME__
" " __DATE__
"\n");
2971 * Find the 4DWave DX
2974 while( (pcidev
= pci_find_device(PCI_VENDOR_ID_TRIDENT
, PCI_DEVICE_ID_TRIDENT_4DWAVE_DX
, pcidev
))!=NULL
2976 ( trident_install(pcidev
, TYPE_4DWAVE_DX
) )) {
2981 * Find the 4DWave NX
2984 while((pcidev
= pci_find_device(PCI_VENDOR_ID_TRIDENT
, PCI_DEVICE_ID_TRIDENT_4DWAVE_NX
, pcidev
))!=NULL
2986 ( trident_install(pcidev
, TYPE_4DWAVE_NX
) )) {
2995 /* --------------------------------------------------------------------- */
2999 MODULE_AUTHOR("Alan Cox <alan@redhat.com>");
3000 MODULE_DESCRIPTION("Trident 4DWave Driver");
3002 MODULE_PARM(debug
,"i");
3005 void cleanup_module(void)
3007 struct trident_card
*s
;
3010 apm_unregister_callback(trident_apm_callback
);
3013 del_timer(&debug_timer
);
3015 while ((s
= devs
)) {
3020 /* Kill interrupts, and SP/DIF */
3022 DisableEndInterrupts(s
);
3023 if(s
->card_type
== TYPE_4DWAVE_NX
)
3024 outb(0x00, TRID_REG(s
, NX_SPCTRL_SPCSO
+3));
3026 free_irq(s
->irq
, s
);
3027 unregister_sound_mixer(s
->dev_mixer
);
3028 for(i
=0;i
<NR_DSPS
;i
++)
3030 struct trident_state
*trident
= &s
->channels
[i
];
3031 if(trident
->dev_audio
!= -1)
3032 unregister_sound_dsp(trident
->dev_audio
);
3034 release_region(s
->iobase
, 256);
3037 printk("(trident) unloading\n");