1 /*****************************************************************************/
4 * sonicvibes.c -- S3 Sonic Vibes audio driver.
6 * Copyright (C) 1998-2001, 2003 Thomas Sailer (t.sailer@alumni.ethz.ch)
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 * Special thanks to David C. Niemi
25 * Module command line parameters:
30 * /dev/dsp standard /dev/dsp device, (mostly) OSS compatible
31 * /dev/mixer standard /dev/mixer device, (mostly) OSS compatible
32 * /dev/midi simple MIDI UART interface, no ioctl
34 * The card has both an FM and a Wavetable synth, but I have to figure
35 * out first how to drive them...
38 * 06.05.1998 0.1 Initial release
39 * 10.05.1998 0.2 Fixed many bugs, esp. ADC rate calculation
40 * First stab at a simple midi interface (no bells&whistles)
41 * 13.05.1998 0.3 Fix stupid cut&paste error: set_adc_rate was called instead of
42 * set_dac_rate in the FMODE_WRITE case in sv_open
43 * Fix hwptr out of bounds (now mpg123 works)
44 * 14.05.1998 0.4 Don't allow excessive interrupt rates
45 * 08.06.1998 0.5 First release using Alan Cox' soundcore instead of miscdevice
46 * 03.08.1998 0.6 Do not include modversions.h
47 * Now mixer behaviour can basically be selected between
48 * "OSS documented" and "OSS actual" behaviour
49 * 31.08.1998 0.7 Fix realplayer problems - dac.count issues
50 * 10.12.1998 0.8 Fix drain_dac trying to wait on not yet initialized DMA
51 * 16.12.1998 0.9 Fix a few f_file & FMODE_ bugs
52 * 06.01.1999 0.10 remove the silly SA_INTERRUPT flag.
53 * hopefully killed the egcs section type conflict
54 * 12.03.1999 0.11 cinfo.blocks should be reset after GETxPTR ioctl.
55 * reported by Johan Maes <joma@telindus.be>
56 * 22.03.1999 0.12 return EAGAIN instead of EBUSY when O_NONBLOCK
57 * read/write cannot be executed
58 * 05.04.1999 0.13 added code to sv_read and sv_write which should detect
59 * lockups of the sound chip and revive it. This is basically
60 * an ugly hack, but at least applications using this driver
61 * won't hang forever. I don't know why these lockups happen,
62 * it might well be the motherboard chipset (an early 486 PCI
63 * board with ALI chipset), since every busmastering 100MB
64 * ethernet card I've tried (Realtek 8139 and Macronix tulip clone)
65 * exhibit similar behaviour (they work for a couple of packets
66 * and then lock up and can be revived by ifconfig down/up).
67 * 07.04.1999 0.14 implemented the following ioctl's: SOUND_PCM_READ_RATE,
68 * SOUND_PCM_READ_CHANNELS, SOUND_PCM_READ_BITS;
69 * Alpha fixes reported by Peter Jones <pjones@redhat.com>
70 * Note: dmaio hack might still be wrong on archs other than i386
71 * 15.06.1999 0.15 Fix bad allocation bug.
72 * Thanks to Deti Fliegl <fliegl@in.tum.de>
73 * 28.06.1999 0.16 Add pci_set_master
74 * 03.08.1999 0.17 adapt to Linus' new __setup/__initcall
75 * added kernel command line options "sonicvibes=reverb" and "sonicvibesdmaio=dmaioaddr"
76 * 12.08.1999 0.18 module_init/__setup fixes
77 * 24.08.1999 0.19 get rid of the dmaio kludge, replace with allocate_resource
78 * 31.08.1999 0.20 add spin_lock_init
79 * use new resource allocation to allocate DDMA IO space
80 * replaced current->state = x with set_current_state(x)
81 * 03.09.1999 0.21 change read semantics for MIDI to match
82 * OSS more closely; remove possible wakeup race
83 * 28.10.1999 0.22 More waitqueue races fixed
84 * 01.12.1999 0.23 New argument to allocate_resource
85 * 07.12.1999 0.24 More allocate_resource semantics change
86 * 08.01.2000 0.25 Prevent some ioctl's from returning bad count values on underrun/overrun;
87 * Tim Janik's BSE (Bedevilled Sound Engine) found this
88 * use Martin Mares' pci_assign_resource
89 * 07.02.2000 0.26 Use pci_alloc_consistent and pci_register_driver
90 * 21.11.2000 0.27 Initialize dma buffers in poll, otherwise poll may return a bogus mask
91 * 12.12.2000 0.28 More dma buffer initializations, patch from
92 * Tjeerd Mulder <tjeerd.mulder@fujitsu-siemens.com>
93 * 31.01.2001 0.29 Register/Unregister gameport
94 * Fix SETTRIGGER non OSS API conformity
95 * 18.05.2001 0.30 PCI probing and error values cleaned up by Marcus
96 * Meissner <mm@caldera.de>
97 * 03.01.2003 0.31 open_mode fixes from Georg Acher <acher@in.tum.de>
101 /*****************************************************************************/
103 #include <linux/module.h>
104 #include <linux/string.h>
105 #include <linux/ioport.h>
106 #include <linux/interrupt.h>
107 #include <linux/wait.h>
108 #include <linux/mm.h>
109 #include <linux/delay.h>
110 #include <linux/sound.h>
111 #include <linux/slab.h>
112 #include <linux/soundcard.h>
113 #include <linux/pci.h>
114 #include <linux/init.h>
115 #include <linux/poll.h>
116 #include <linux/spinlock.h>
117 #include <linux/smp_lock.h>
118 #include <linux/gameport.h>
119 #include <linux/mutex.h>
123 #include <asm/uaccess.h>
127 #if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))
128 #define SUPPORT_JOYSTICK 1
131 /* --------------------------------------------------------------------- */
133 #undef OSS_DOCUMENTED_MIXER_SEMANTICS
135 /* --------------------------------------------------------------------- */
137 #ifndef PCI_VENDOR_ID_S3
138 #define PCI_VENDOR_ID_S3 0x5333
140 #ifndef PCI_DEVICE_ID_S3_SONICVIBES
141 #define PCI_DEVICE_ID_S3_SONICVIBES 0xca00
144 #define SV_MAGIC ((PCI_VENDOR_ID_S3<<16)|PCI_DEVICE_ID_S3_SONICVIBES)
146 #define SV_EXTENT_SB 0x10
147 #define SV_EXTENT_ENH 0x10
148 #define SV_EXTENT_SYNTH 0x4
149 #define SV_EXTENT_MIDI 0x4
150 #define SV_EXTENT_GAME 0x8
151 #define SV_EXTENT_DMA 0x10
154 * we are not a bridge and thus use a resource for DDMA that is used for bridges but
155 * left empty for normal devices
157 #define RESOURCE_SB 0
158 #define RESOURCE_ENH 1
159 #define RESOURCE_SYNTH 2
160 #define RESOURCE_MIDI 3
161 #define RESOURCE_GAME 4
162 #define RESOURCE_DDMA 7
164 #define SV_MIDI_DATA 0
165 #define SV_MIDI_COMMAND 1
166 #define SV_MIDI_STATUS 1
168 #define SV_DMA_ADDR0 0
169 #define SV_DMA_ADDR1 1
170 #define SV_DMA_ADDR2 2
171 #define SV_DMA_ADDR3 3
172 #define SV_DMA_COUNT0 4
173 #define SV_DMA_COUNT1 5
174 #define SV_DMA_COUNT2 6
175 #define SV_DMA_MODE 0xb
176 #define SV_DMA_RESET 0xd
177 #define SV_DMA_MASK 0xf
180 * DONT reset the DMA controllers unless you understand
181 * the reset semantics. Assuming reset semantics as in
182 * the 8237 does not work.
185 #define DMA_MODE_AUTOINIT 0x10
186 #define DMA_MODE_READ 0x44 /* I/O to memory, no autoinit, increment, single mode */
187 #define DMA_MODE_WRITE 0x48 /* memory to I/O, no autoinit, increment, single mode */
189 #define SV_CODEC_CONTROL 0
190 #define SV_CODEC_INTMASK 1
191 #define SV_CODEC_STATUS 2
192 #define SV_CODEC_IADDR 4
193 #define SV_CODEC_IDATA 5
195 #define SV_CCTRL_RESET 0x80
196 #define SV_CCTRL_INTADRIVE 0x20
197 #define SV_CCTRL_WAVETABLE 0x08
198 #define SV_CCTRL_REVERB 0x04
199 #define SV_CCTRL_ENHANCED 0x01
201 #define SV_CINTMASK_DMAA 0x01
202 #define SV_CINTMASK_DMAC 0x04
203 #define SV_CINTMASK_SPECIAL 0x08
204 #define SV_CINTMASK_UPDOWN 0x40
205 #define SV_CINTMASK_MIDI 0x80
207 #define SV_CSTAT_DMAA 0x01
208 #define SV_CSTAT_DMAC 0x04
209 #define SV_CSTAT_SPECIAL 0x08
210 #define SV_CSTAT_UPDOWN 0x40
211 #define SV_CSTAT_MIDI 0x80
213 #define SV_CIADDR_TRD 0x80
214 #define SV_CIADDR_MCE 0x40
216 /* codec indirect registers */
217 #define SV_CIMIX_ADCINL 0x00
218 #define SV_CIMIX_ADCINR 0x01
219 #define SV_CIMIX_AUX1INL 0x02
220 #define SV_CIMIX_AUX1INR 0x03
221 #define SV_CIMIX_CDINL 0x04
222 #define SV_CIMIX_CDINR 0x05
223 #define SV_CIMIX_LINEINL 0x06
224 #define SV_CIMIX_LINEINR 0x07
225 #define SV_CIMIX_MICIN 0x08
226 #define SV_CIMIX_SYNTHINL 0x0A
227 #define SV_CIMIX_SYNTHINR 0x0B
228 #define SV_CIMIX_AUX2INL 0x0C
229 #define SV_CIMIX_AUX2INR 0x0D
230 #define SV_CIMIX_ANALOGINL 0x0E
231 #define SV_CIMIX_ANALOGINR 0x0F
232 #define SV_CIMIX_PCMINL 0x10
233 #define SV_CIMIX_PCMINR 0x11
235 #define SV_CIGAMECONTROL 0x09
236 #define SV_CIDATAFMT 0x12
237 #define SV_CIENABLE 0x13
238 #define SV_CIUPDOWN 0x14
239 #define SV_CIREVISION 0x15
240 #define SV_CIADCOUTPUT 0x16
241 #define SV_CIDMAABASECOUNT1 0x18
242 #define SV_CIDMAABASECOUNT0 0x19
243 #define SV_CIDMACBASECOUNT1 0x1c
244 #define SV_CIDMACBASECOUNT0 0x1d
245 #define SV_CIPCMSR0 0x1e
246 #define SV_CIPCMSR1 0x1f
247 #define SV_CISYNTHSR0 0x20
248 #define SV_CISYNTHSR1 0x21
249 #define SV_CIADCCLKSOURCE 0x22
250 #define SV_CIADCALTSR 0x23
251 #define SV_CIADCPLLM 0x24
252 #define SV_CIADCPLLN 0x25
253 #define SV_CISYNTHPLLM 0x26
254 #define SV_CISYNTHPLLN 0x27
255 #define SV_CIUARTCONTROL 0x2a
256 #define SV_CIDRIVECONTROL 0x2b
257 #define SV_CISRSSPACE 0x2c
258 #define SV_CISRSCENTER 0x2d
259 #define SV_CIWAVETABLESRC 0x2e
260 #define SV_CIANALOGPWRDOWN 0x30
261 #define SV_CIDIGITALPWRDOWN 0x31
264 #define SV_CIMIX_ADCSRC_CD 0x20
265 #define SV_CIMIX_ADCSRC_DAC 0x40
266 #define SV_CIMIX_ADCSRC_AUX2 0x60
267 #define SV_CIMIX_ADCSRC_LINE 0x80
268 #define SV_CIMIX_ADCSRC_AUX1 0xa0
269 #define SV_CIMIX_ADCSRC_MIC 0xc0
270 #define SV_CIMIX_ADCSRC_MIXOUT 0xe0
271 #define SV_CIMIX_ADCSRC_MASK 0xe0
273 #define SV_CFMT_STEREO 0x01
274 #define SV_CFMT_16BIT 0x02
275 #define SV_CFMT_MASK 0x03
276 #define SV_CFMT_ASHIFT 0
277 #define SV_CFMT_CSHIFT 4
279 static const unsigned sample_size[] = { 1, 2, 2, 4 };
280 static const unsigned sample_shift[] = { 0, 1, 1, 2 };
282 #define SV_CENABLE_PPE 0x4
283 #define SV_CENABLE_RE 0x2
284 #define SV_CENABLE_PE 0x1
287 /* MIDI buffer sizes */
289 #define MIDIINBUF 256
290 #define MIDIOUTBUF 256
292 #define FMODE_MIDI_SHIFT 2
293 #define FMODE_MIDI_READ (FMODE_READ << FMODE_MIDI_SHIFT)
294 #define FMODE_MIDI_WRITE (FMODE_WRITE << FMODE_MIDI_SHIFT)
296 #define FMODE_DMFM 0x10
298 /* --------------------------------------------------------------------- */
304 /* list of sonicvibes devices */
305 struct list_head devs;
307 /* the corresponding pci_dev structure */
310 /* soundcore stuff */
316 /* hardware resources */
317 unsigned long iosb, ioenh, iosynth, iomidi; /* long for SPARC */
318 unsigned int iodmaa, iodmac, irq;
323 #ifndef OSS_DOCUMENTED_MIXER_SEMANTICS
324 unsigned short vol[13];
325 #endif /* OSS_DOCUMENTED_MIXER_SEMANTICS */
329 unsigned int rateadc, ratedac;
330 unsigned char fmt, enable;
333 struct mutex open_mutex;
335 wait_queue_head_t open_wait;
343 unsigned hwptr, swptr;
344 unsigned total_bytes;
346 unsigned error; /* over/underrun */
347 wait_queue_head_t wait;
348 /* redundant, but makes calculations easier */
351 unsigned fragsamples;
355 unsigned endcleared:1;
357 unsigned ossfragshift;
359 unsigned subdivision;
364 unsigned ird, iwr, icnt;
365 unsigned ord, owr, ocnt;
366 wait_queue_head_t iwait;
367 wait_queue_head_t owait;
368 struct timer_list timer;
369 unsigned char ibuf[MIDIINBUF];
370 unsigned char obuf[MIDIOUTBUF];
374 struct gameport *gameport;
378 /* --------------------------------------------------------------------- */
380 static LIST_HEAD(devs);
381 static unsigned long wavetable_mem;
383 /* --------------------------------------------------------------------- */
385 static inline unsigned ld2(unsigned int x)
411 * hweightN: returns the hamming weight (i.e. the number
412 * of bits set) of a N-bit word
419 static inline unsigned int hweight32(unsigned int w)
421 unsigned int res = (w & 0x55555555) + ((w >> 1) & 0x55555555);
422 res = (res & 0x33333333) + ((res >> 2) & 0x33333333);
423 res = (res & 0x0F0F0F0F) + ((res >> 4) & 0x0F0F0F0F);
424 res = (res & 0x00FF00FF) + ((res >> 8) & 0x00FF00FF);
425 return (res & 0x0000FFFF) + ((res >> 16) & 0x0000FFFF);
428 /* --------------------------------------------------------------------- */
431 * Why use byte IO? Nobody knows, but S3 does it also in their Windows driver.
436 static void set_dmaa(struct sv_state *s, unsigned int addr, unsigned int count)
439 unsigned io = s->iodmaa, u;
442 for (u = 4; u > 0; u--, addr >>= 8, io++)
443 outb(addr & 0xff, io);
444 for (u = 3; u > 0; u--, count >>= 8, io++)
445 outb(count & 0xff, io);
446 #else /* DMABYTEIO */
448 outl(addr, s->iodmaa + SV_DMA_ADDR0);
449 outl(count, s->iodmaa + SV_DMA_COUNT0);
450 #endif /* DMABYTEIO */
451 outb(0x18, s->iodmaa + SV_DMA_MODE);
454 static void set_dmac(struct sv_state *s, unsigned int addr, unsigned int count)
457 unsigned io = s->iodmac, u;
461 for (u = 4; u > 0; u--, addr >>= 8, io++)
462 outb(addr & 0xff, io);
463 for (u = 3; u > 0; u--, count >>= 8, io++)
464 outb(count & 0xff, io);
465 #else /* DMABYTEIO */
468 outl(addr, s->iodmac + SV_DMA_ADDR0);
469 outl(count, s->iodmac + SV_DMA_COUNT0);
470 #endif /* DMABYTEIO */
471 outb(0x14, s->iodmac + SV_DMA_MODE);
474 static inline unsigned get_dmaa(struct sv_state *s)
477 unsigned io = s->iodmaa+6, v = 0, u;
479 for (u = 3; u > 0; u--, io--) {
484 #else /* DMABYTEIO */
485 return (inl(s->iodmaa + SV_DMA_COUNT0) & 0xffffff) + 1;
486 #endif /* DMABYTEIO */
489 static inline unsigned get_dmac(struct sv_state *s)
492 unsigned io = s->iodmac+6, v = 0, u;
494 for (u = 3; u > 0; u--, io--) {
499 #else /* DMABYTEIO */
500 return ((inl(s->iodmac + SV_DMA_COUNT0) & 0xffffff) + 1) << 1;
501 #endif /* DMABYTEIO */
504 static void wrindir(struct sv_state *s, unsigned char idx, unsigned char data)
506 outb(idx & 0x3f, s->ioenh + SV_CODEC_IADDR);
508 outb(data, s->ioenh + SV_CODEC_IDATA);
512 static unsigned char rdindir(struct sv_state *s, unsigned char idx)
516 outb(idx & 0x3f, s->ioenh + SV_CODEC_IADDR);
518 v = inb(s->ioenh + SV_CODEC_IDATA);
523 static void set_fmt(struct sv_state *s, unsigned char mask, unsigned char data)
527 spin_lock_irqsave(&s->lock, flags);
528 outb(SV_CIDATAFMT | SV_CIADDR_MCE, s->ioenh + SV_CODEC_IADDR);
530 s->fmt = inb(s->ioenh + SV_CODEC_IDATA);
533 s->fmt = (s->fmt & mask) | data;
534 outb(s->fmt, s->ioenh + SV_CODEC_IDATA);
536 outb(0, s->ioenh + SV_CODEC_IADDR);
537 spin_unlock_irqrestore(&s->lock, flags);
541 static void frobindir(struct sv_state *s, unsigned char idx, unsigned char mask, unsigned char data)
543 outb(idx & 0x3f, s->ioenh + SV_CODEC_IADDR);
545 outb((inb(s->ioenh + SV_CODEC_IDATA) & mask) ^ data, s->ioenh + SV_CODEC_IDATA);
549 #define REFFREQUENCY 24576000
551 #define FULLRATE 48000
553 static unsigned setpll(struct sv_state *s, unsigned char reg, unsigned rate)
556 unsigned char r, m=0, n=0;
557 unsigned xm, xn, xr, xd, metric = ~0U;
558 /* the warnings about m and n used uninitialized are bogus and may safely be ignored */
560 if (rate < 625000/ADCMULT)
561 rate = 625000/ADCMULT;
562 if (rate > 150000000/ADCMULT)
563 rate = 150000000/ADCMULT;
564 /* slight violation of specs, needed for continuous sampling rates */
565 for (r = 0; rate < 75000000/ADCMULT; r += 0x20, rate <<= 1);
566 for (xn = 3; xn < 35; xn++)
567 for (xm = 3; xm < 130; xm++) {
568 xr = REFFREQUENCY/ADCMULT * xm / xn;
569 xd = abs((signed)(xr - rate));
577 spin_lock_irqsave(&s->lock, flags);
578 outb(reg, s->ioenh + SV_CODEC_IADDR);
580 outb(m, s->ioenh + SV_CODEC_IDATA);
582 outb(reg+1, s->ioenh + SV_CODEC_IADDR);
584 outb(r | n, s->ioenh + SV_CODEC_IDATA);
585 spin_unlock_irqrestore(&s->lock, flags);
587 return (REFFREQUENCY/ADCMULT * (m + 2) / (n + 2)) >> ((r >> 5) & 7);
592 static unsigned getpll(struct sv_state *s, unsigned char reg)
598 spin_lock_irqsave(&s->lock, flags);
599 outb(reg, s->ioenh + SV_CODEC_IADDR);
601 m = inb(s->ioenh + SV_CODEC_IDATA);
603 outb(reg+1, s->ioenh + SV_CODEC_IADDR);
605 n = inb(s->ioenh + SV_CODEC_IDATA);
606 spin_unlock_irqrestore(&s->lock, flags);
608 return (REFFREQUENCY/ADCMULT * (m + 2) / ((n & 0x1f) + 2)) >> ((n >> 5) & 7);
613 static void set_dac_rate(struct sv_state *s, unsigned rate)
622 div = (rate * 65536 + FULLRATE/2) / FULLRATE;
625 spin_lock_irqsave(&s->lock, flags);
626 wrindir(s, SV_CIPCMSR1, div >> 8);
627 wrindir(s, SV_CIPCMSR0, div);
628 spin_unlock_irqrestore(&s->lock, flags);
629 s->ratedac = (div * FULLRATE + 32768) / 65536;
632 static void set_adc_rate(struct sv_state *s, unsigned rate)
635 unsigned rate1, rate2, div;
641 rate1 = setpll(s, SV_CIADCPLLM, rate);
642 div = (48000 + rate/2) / rate;
645 rate2 = (48000 + div/2) / div;
646 spin_lock_irqsave(&s->lock, flags);
647 wrindir(s, SV_CIADCALTSR, (div-1) << 4);
648 if (abs((signed)(rate-rate2)) <= abs((signed)(rate-rate1))) {
649 wrindir(s, SV_CIADCCLKSOURCE, 0x10);
652 wrindir(s, SV_CIADCCLKSOURCE, 0x00);
655 spin_unlock_irqrestore(&s->lock, flags);
658 /* --------------------------------------------------------------------- */
660 static inline void stop_adc(struct sv_state *s)
664 spin_lock_irqsave(&s->lock, flags);
665 s->enable &= ~SV_CENABLE_RE;
666 wrindir(s, SV_CIENABLE, s->enable);
667 spin_unlock_irqrestore(&s->lock, flags);
670 static inline void stop_dac(struct sv_state *s)
674 spin_lock_irqsave(&s->lock, flags);
675 s->enable &= ~(SV_CENABLE_PPE | SV_CENABLE_PE);
676 wrindir(s, SV_CIENABLE, s->enable);
677 spin_unlock_irqrestore(&s->lock, flags);
680 static void start_dac(struct sv_state *s)
684 spin_lock_irqsave(&s->lock, flags);
685 if ((s->dma_dac.mapped || s->dma_dac.count > 0) && s->dma_dac.ready) {
686 s->enable = (s->enable & ~SV_CENABLE_PPE) | SV_CENABLE_PE;
687 wrindir(s, SV_CIENABLE, s->enable);
689 spin_unlock_irqrestore(&s->lock, flags);
692 static void start_adc(struct sv_state *s)
696 spin_lock_irqsave(&s->lock, flags);
697 if ((s->dma_adc.mapped || s->dma_adc.count < (signed)(s->dma_adc.dmasize - 2*s->dma_adc.fragsize))
698 && s->dma_adc.ready) {
699 s->enable |= SV_CENABLE_RE;
700 wrindir(s, SV_CIENABLE, s->enable);
702 spin_unlock_irqrestore(&s->lock, flags);
705 /* --------------------------------------------------------------------- */
707 #define DMABUF_DEFAULTORDER (17-PAGE_SHIFT)
708 #define DMABUF_MINORDER 1
710 static void dealloc_dmabuf(struct sv_state *s, struct dmabuf *db)
712 struct page *page, *pend;
715 /* undo marking the pages as reserved */
716 pend = virt_to_page(db->rawbuf + (PAGE_SIZE << db->buforder) - 1);
717 for (page = virt_to_page(db->rawbuf); page <= pend; page++)
718 ClearPageReserved(page);
719 pci_free_consistent(s->dev, PAGE_SIZE << db->buforder, db->rawbuf, db->dmaaddr);
722 db->mapped = db->ready = 0;
726 /* DMAA is used for playback, DMAC is used for recording */
728 static int prog_dmabuf(struct sv_state *s, unsigned rec)
730 struct dmabuf *db = rec ? &s->dma_adc : &s->dma_dac;
731 unsigned rate = rec ? s->rateadc : s->ratedac;
735 struct page *page, *pend;
739 spin_lock_irqsave(&s->lock, flags);
742 s->enable &= ~SV_CENABLE_RE;
743 fmt >>= SV_CFMT_CSHIFT;
745 s->enable &= ~SV_CENABLE_PE;
746 fmt >>= SV_CFMT_ASHIFT;
748 wrindir(s, SV_CIENABLE, s->enable);
749 spin_unlock_irqrestore(&s->lock, flags);
751 db->hwptr = db->swptr = db->total_bytes = db->count = db->error = db->endcleared = 0;
753 db->ready = db->mapped = 0;
754 for (order = DMABUF_DEFAULTORDER; order >= DMABUF_MINORDER; order--)
755 if ((db->rawbuf = pci_alloc_consistent(s->dev, PAGE_SIZE << order, &db->dmaaddr)))
759 db->buforder = order;
760 if ((virt_to_bus(db->rawbuf) ^ (virt_to_bus(db->rawbuf) + (PAGE_SIZE << db->buforder) - 1)) & ~0xffff)
761 printk(KERN_DEBUG "sv: DMA buffer crosses 64k boundary: busaddr 0x%lx size %ld\n",
762 virt_to_bus(db->rawbuf), PAGE_SIZE << db->buforder);
763 if ((virt_to_bus(db->rawbuf) + (PAGE_SIZE << db->buforder) - 1) & ~0xffffff)
764 printk(KERN_DEBUG "sv: DMA buffer beyond 16MB: busaddr 0x%lx size %ld\n",
765 virt_to_bus(db->rawbuf), PAGE_SIZE << db->buforder);
766 /* now mark the pages as reserved; otherwise remap_pfn_range doesn't do what we want */
767 pend = virt_to_page(db->rawbuf + (PAGE_SIZE << db->buforder) - 1);
768 for (page = virt_to_page(db->rawbuf); page <= pend; page++)
769 SetPageReserved(page);
771 bytepersec = rate << sample_shift[fmt];
772 bufs = PAGE_SIZE << db->buforder;
773 if (db->ossfragshift) {
774 if ((1000 << db->ossfragshift) < bytepersec)
775 db->fragshift = ld2(bytepersec/1000);
777 db->fragshift = db->ossfragshift;
779 db->fragshift = ld2(bytepersec/100/(db->subdivision ? db->subdivision : 1));
780 if (db->fragshift < 3)
783 db->numfrag = bufs >> db->fragshift;
784 while (db->numfrag < 4 && db->fragshift > 3) {
786 db->numfrag = bufs >> db->fragshift;
788 db->fragsize = 1 << db->fragshift;
789 if (db->ossmaxfrags >= 4 && db->ossmaxfrags < db->numfrag)
790 db->numfrag = db->ossmaxfrags;
791 db->fragsamples = db->fragsize >> sample_shift[fmt];
792 db->dmasize = db->numfrag << db->fragshift;
793 memset(db->rawbuf, (fmt & SV_CFMT_16BIT) ? 0 : 0x80, db->dmasize);
794 spin_lock_irqsave(&s->lock, flags);
796 set_dmac(s, db->dmaaddr, db->numfrag << db->fragshift);
797 /* program enhanced mode registers */
798 wrindir(s, SV_CIDMACBASECOUNT1, (db->fragsamples-1) >> 8);
799 wrindir(s, SV_CIDMACBASECOUNT0, db->fragsamples-1);
801 set_dmaa(s, db->dmaaddr, db->numfrag << db->fragshift);
802 /* program enhanced mode registers */
803 wrindir(s, SV_CIDMAABASECOUNT1, (db->fragsamples-1) >> 8);
804 wrindir(s, SV_CIDMAABASECOUNT0, db->fragsamples-1);
806 spin_unlock_irqrestore(&s->lock, flags);
812 static inline void clear_advance(struct sv_state *s)
814 unsigned char c = (s->fmt & (SV_CFMT_16BIT << SV_CFMT_ASHIFT)) ? 0 : 0x80;
815 unsigned char *buf = s->dma_dac.rawbuf;
816 unsigned bsize = s->dma_dac.dmasize;
817 unsigned bptr = s->dma_dac.swptr;
818 unsigned len = s->dma_dac.fragsize;
820 if (bptr + len > bsize) {
821 unsigned x = bsize - bptr;
822 memset(buf + bptr, c, x);
826 memset(buf + bptr, c, len);
829 /* call with spinlock held! */
830 static void sv_update_ptr(struct sv_state *s)
835 /* update ADC pointer */
836 if (s->dma_adc.ready) {
837 hwptr = (s->dma_adc.dmasize - get_dmac(s)) % s->dma_adc.dmasize;
838 diff = (s->dma_adc.dmasize + hwptr - s->dma_adc.hwptr) % s->dma_adc.dmasize;
839 s->dma_adc.hwptr = hwptr;
840 s->dma_adc.total_bytes += diff;
841 s->dma_adc.count += diff;
842 if (s->dma_adc.count >= (signed)s->dma_adc.fragsize)
843 wake_up(&s->dma_adc.wait);
844 if (!s->dma_adc.mapped) {
845 if (s->dma_adc.count > (signed)(s->dma_adc.dmasize - ((3 * s->dma_adc.fragsize) >> 1))) {
846 s->enable &= ~SV_CENABLE_RE;
847 wrindir(s, SV_CIENABLE, s->enable);
852 /* update DAC pointer */
853 if (s->dma_dac.ready) {
854 hwptr = (s->dma_dac.dmasize - get_dmaa(s)) % s->dma_dac.dmasize;
855 diff = (s->dma_dac.dmasize + hwptr - s->dma_dac.hwptr) % s->dma_dac.dmasize;
856 s->dma_dac.hwptr = hwptr;
857 s->dma_dac.total_bytes += diff;
858 if (s->dma_dac.mapped) {
859 s->dma_dac.count += diff;
860 if (s->dma_dac.count >= (signed)s->dma_dac.fragsize)
861 wake_up(&s->dma_dac.wait);
863 s->dma_dac.count -= diff;
864 if (s->dma_dac.count <= 0) {
865 s->enable &= ~SV_CENABLE_PE;
866 wrindir(s, SV_CIENABLE, s->enable);
868 } else if (s->dma_dac.count <= (signed)s->dma_dac.fragsize && !s->dma_dac.endcleared) {
870 s->dma_dac.endcleared = 1;
872 if (s->dma_dac.count + (signed)s->dma_dac.fragsize <= (signed)s->dma_dac.dmasize)
873 wake_up(&s->dma_dac.wait);
878 /* hold spinlock for the following! */
879 static void sv_handle_midi(struct sv_state *s)
885 while (!(inb(s->iomidi+1) & 0x80)) {
887 if (s->midi.icnt < MIDIINBUF) {
888 s->midi.ibuf[s->midi.iwr] = ch;
889 s->midi.iwr = (s->midi.iwr + 1) % MIDIINBUF;
895 wake_up(&s->midi.iwait);
897 while (!(inb(s->iomidi+1) & 0x40) && s->midi.ocnt > 0) {
898 outb(s->midi.obuf[s->midi.ord], s->iomidi);
899 s->midi.ord = (s->midi.ord + 1) % MIDIOUTBUF;
901 if (s->midi.ocnt < MIDIOUTBUF-16)
905 wake_up(&s->midi.owait);
908 static irqreturn_t sv_interrupt(int irq, void *dev_id, struct pt_regs *regs)
910 struct sv_state *s = (struct sv_state *)dev_id;
913 /* fastpath out, to ease interrupt sharing */
914 intsrc = inb(s->ioenh + SV_CODEC_STATUS);
915 if (!(intsrc & (SV_CSTAT_DMAA | SV_CSTAT_DMAC | SV_CSTAT_MIDI)))
920 spin_unlock(&s->lock);
924 static void sv_midi_timer(unsigned long data)
926 struct sv_state *s = (struct sv_state *)data;
929 spin_lock_irqsave(&s->lock, flags);
931 spin_unlock_irqrestore(&s->lock, flags);
932 s->midi.timer.expires = jiffies+1;
933 add_timer(&s->midi.timer);
936 /* --------------------------------------------------------------------- */
938 static const char invalid_magic[] = KERN_CRIT "sv: invalid magic value\n";
940 #define VALIDATE_STATE(s) \
942 if (!(s) || (s)->magic != SV_MAGIC) { \
943 printk(invalid_magic); \
948 /* --------------------------------------------------------------------- */
952 #define MT_4MUTEMONO 3
955 static const struct {
960 } mixtable[SOUND_MIXER_NRDEVICES] = {
961 [SOUND_MIXER_RECLEV] = { SV_CIMIX_ADCINL, SV_CIMIX_ADCINR, MT_4, 0 },
962 [SOUND_MIXER_LINE1] = { SV_CIMIX_AUX1INL, SV_CIMIX_AUX1INR, MT_5MUTE, 5 },
963 [SOUND_MIXER_CD] = { SV_CIMIX_CDINL, SV_CIMIX_CDINR, MT_5MUTE, 1 },
964 [SOUND_MIXER_LINE] = { SV_CIMIX_LINEINL, SV_CIMIX_LINEINR, MT_5MUTE, 4 },
965 [SOUND_MIXER_MIC] = { SV_CIMIX_MICIN, SV_CIMIX_ADCINL, MT_4MUTEMONO, 6 },
966 [SOUND_MIXER_SYNTH] = { SV_CIMIX_SYNTHINL, SV_CIMIX_SYNTHINR, MT_5MUTE, 2 },
967 [SOUND_MIXER_LINE2] = { SV_CIMIX_AUX2INL, SV_CIMIX_AUX2INR, MT_5MUTE, 3 },
968 [SOUND_MIXER_VOLUME] = { SV_CIMIX_ANALOGINL, SV_CIMIX_ANALOGINR, MT_5MUTE, 7 },
969 [SOUND_MIXER_PCM] = { SV_CIMIX_PCMINL, SV_CIMIX_PCMINR, MT_6MUTE, 0 }
972 #ifdef OSS_DOCUMENTED_MIXER_SEMANTICS
974 static int return_mixval(struct sv_state *s, unsigned i, int *arg)
977 unsigned char l, r, rl, rr;
979 spin_lock_irqsave(&s->lock, flags);
980 l = rdindir(s, mixtable[i].left);
981 r = rdindir(s, mixtable[i].right);
982 spin_unlock_irqrestore(&s->lock, flags);
983 switch (mixtable[i].type) {
987 rl = 10 + 6 * (l & 15);
988 rr = 10 + 6 * (r & 15);
992 rl = 55 - 3 * (l & 15);
1001 rl = 100 - 3 * (l & 31);
1002 rr = 100 - 3 * (r & 31);
1006 rl = 100 - 3 * (l & 63) / 2;
1007 rr = 100 - 3 * (r & 63) / 2;
1014 return put_user((rr << 8) | rl, arg);
1017 #else /* OSS_DOCUMENTED_MIXER_SEMANTICS */
1019 static const unsigned char volidx[SOUND_MIXER_NRDEVICES] =
1021 [SOUND_MIXER_RECLEV] = 1,
1022 [SOUND_MIXER_LINE1] = 2,
1023 [SOUND_MIXER_CD] = 3,
1024 [SOUND_MIXER_LINE] = 4,
1025 [SOUND_MIXER_MIC] = 5,
1026 [SOUND_MIXER_SYNTH] = 6,
1027 [SOUND_MIXER_LINE2] = 7,
1028 [SOUND_MIXER_VOLUME] = 8,
1029 [SOUND_MIXER_PCM] = 9
1032 #endif /* OSS_DOCUMENTED_MIXER_SEMANTICS */
1034 static unsigned mixer_recmask(struct sv_state *s)
1036 unsigned long flags;
1039 spin_lock_irqsave(&s->lock, flags);
1040 j = rdindir(s, SV_CIMIX_ADCINL) >> 5;
1041 spin_unlock_irqrestore(&s->lock, flags);
1043 for (i = 0; i < SOUND_MIXER_NRDEVICES && mixtable[i].rec != j; i++);
1047 static int mixer_ioctl(struct sv_state *s, unsigned int cmd, unsigned long arg)
1049 unsigned long flags;
1051 unsigned char l, r, rl, rr;
1052 int __user *p = (int __user *)arg;
1055 if (cmd == SOUND_MIXER_INFO) {
1057 memset(&info, 0, sizeof(info));
1058 strlcpy(info.id, "SonicVibes", sizeof(info.id));
1059 strlcpy(info.name, "S3 SonicVibes", sizeof(info.name));
1060 info.modify_counter = s->mix.modcnt;
1061 if (copy_to_user((void __user *)arg, &info, sizeof(info)))
1065 if (cmd == SOUND_OLD_MIXER_INFO) {
1066 _old_mixer_info info;
1067 memset(&info, 0, sizeof(info));
1068 strlcpy(info.id, "SonicVibes", sizeof(info.id));
1069 strlcpy(info.name, "S3 SonicVibes", sizeof(info.name));
1070 if (copy_to_user((void __user *)arg, &info, sizeof(info)))
1074 if (cmd == OSS_GETVERSION)
1075 return put_user(SOUND_VERSION, p);
1076 if (cmd == SOUND_MIXER_PRIVATE1) { /* SRS settings */
1077 if (get_user(val, p))
1079 spin_lock_irqsave(&s->lock, flags);
1082 l = 4 - ((val >> 2) & 7);
1085 r = 4 - ((val >> 5) & 7);
1088 wrindir(s, SV_CISRSSPACE, l);
1089 wrindir(s, SV_CISRSCENTER, r);
1091 wrindir(s, SV_CISRSSPACE, 0x80);
1093 l = rdindir(s, SV_CISRSSPACE);
1094 r = rdindir(s, SV_CISRSCENTER);
1095 spin_unlock_irqrestore(&s->lock, flags);
1097 return put_user(0, p);
1098 return put_user(((4 - (l & 7)) << 2) | ((4 - (r & 7)) << 5) | 2, p);
1100 if (_IOC_TYPE(cmd) != 'M' || _SIOC_SIZE(cmd) != sizeof(int))
1102 if (_SIOC_DIR(cmd) == _SIOC_READ) {
1103 switch (_IOC_NR(cmd)) {
1104 case SOUND_MIXER_RECSRC: /* Arg contains a bit for each recording source */
1105 return put_user(mixer_recmask(s), p);
1107 case SOUND_MIXER_DEVMASK: /* Arg contains a bit for each supported device */
1108 for (val = i = 0; i < SOUND_MIXER_NRDEVICES; i++)
1109 if (mixtable[i].type)
1111 return put_user(val, p);
1113 case SOUND_MIXER_RECMASK: /* Arg contains a bit for each supported recording source */
1114 for (val = i = 0; i < SOUND_MIXER_NRDEVICES; i++)
1115 if (mixtable[i].rec)
1117 return put_user(val, p);
1119 case SOUND_MIXER_STEREODEVS: /* Mixer channels supporting stereo */
1120 for (val = i = 0; i < SOUND_MIXER_NRDEVICES; i++)
1121 if (mixtable[i].type && mixtable[i].type != MT_4MUTEMONO)
1123 return put_user(val, p);
1125 case SOUND_MIXER_CAPS:
1126 return put_user(SOUND_CAP_EXCL_INPUT, p);
1130 if (i >= SOUND_MIXER_NRDEVICES || !mixtable[i].type)
1132 #ifdef OSS_DOCUMENTED_MIXER_SEMANTICS
1133 return return_mixval(s, i, p);
1134 #else /* OSS_DOCUMENTED_MIXER_SEMANTICS */
1137 return put_user(s->mix.vol[volidx[i]-1], p);
1138 #endif /* OSS_DOCUMENTED_MIXER_SEMANTICS */
1141 if (_SIOC_DIR(cmd) != (_SIOC_READ|_SIOC_WRITE))
1144 switch (_IOC_NR(cmd)) {
1145 case SOUND_MIXER_RECSRC: /* Arg contains a bit for each recording source */
1146 if (get_user(val, p))
1150 return 0; /*val = mixer_recmask(s);*/
1152 val &= ~mixer_recmask(s);
1153 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) {
1154 if (!(val & (1 << i)))
1156 if (mixtable[i].rec)
1159 if (i == SOUND_MIXER_NRDEVICES)
1161 spin_lock_irqsave(&s->lock, flags);
1162 frobindir(s, SV_CIMIX_ADCINL, 0x1f, mixtable[i].rec << 5);
1163 frobindir(s, SV_CIMIX_ADCINR, 0x1f, mixtable[i].rec << 5);
1164 spin_unlock_irqrestore(&s->lock, flags);
1169 if (i >= SOUND_MIXER_NRDEVICES || !mixtable[i].type)
1171 if (get_user(val, p))
1174 r = (val >> 8) & 0xff;
1175 if (mixtable[i].type == MT_4MUTEMONO)
1181 spin_lock_irqsave(&s->lock, flags);
1182 switch (mixtable[i].type) {
1188 frobindir(s, mixtable[i].left, 0xf0, l / 6);
1189 frobindir(s, mixtable[i].right, 0xf0, l / 6);
1203 wrindir(s, mixtable[i].left, rl);
1204 frobindir(s, mixtable[i].right, ~0x10, rr);
1216 wrindir(s, mixtable[i].left, rl);
1217 wrindir(s, mixtable[i].right, rr);
1224 rl = (100 - l) * 2 / 3;
1228 rr = (100 - r) * 2 / 3;
1229 wrindir(s, mixtable[i].left, rl);
1230 wrindir(s, mixtable[i].right, rr);
1233 spin_unlock_irqrestore(&s->lock, flags);
1234 #ifdef OSS_DOCUMENTED_MIXER_SEMANTICS
1235 return return_mixval(s, i, p);
1236 #else /* OSS_DOCUMENTED_MIXER_SEMANTICS */
1239 s->mix.vol[volidx[i]-1] = val;
1240 return put_user(s->mix.vol[volidx[i]-1], p);
1241 #endif /* OSS_DOCUMENTED_MIXER_SEMANTICS */
1245 /* --------------------------------------------------------------------- */
1247 static int sv_open_mixdev(struct inode *inode, struct file *file)
1249 int minor = iminor(inode);
1250 struct list_head *list;
1253 for (list = devs.next; ; list = list->next) {
1256 s = list_entry(list, struct sv_state, devs);
1257 if (s->dev_mixer == minor)
1261 file->private_data = s;
1262 return nonseekable_open(inode, file);
1265 static int sv_release_mixdev(struct inode *inode, struct file *file)
1267 struct sv_state *s = (struct sv_state *)file->private_data;
1273 static int sv_ioctl_mixdev(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
1275 return mixer_ioctl((struct sv_state *)file->private_data, cmd, arg);
1278 static /*const*/ struct file_operations sv_mixer_fops = {
1279 .owner = THIS_MODULE,
1280 .llseek = no_llseek,
1281 .ioctl = sv_ioctl_mixdev,
1282 .open = sv_open_mixdev,
1283 .release = sv_release_mixdev,
1286 /* --------------------------------------------------------------------- */
1288 static int drain_dac(struct sv_state *s, int nonblock)
1290 DECLARE_WAITQUEUE(wait, current);
1291 unsigned long flags;
1294 if (s->dma_dac.mapped || !s->dma_dac.ready)
1296 add_wait_queue(&s->dma_dac.wait, &wait);
1298 __set_current_state(TASK_INTERRUPTIBLE);
1299 spin_lock_irqsave(&s->lock, flags);
1300 count = s->dma_dac.count;
1301 spin_unlock_irqrestore(&s->lock, flags);
1304 if (signal_pending(current))
1307 remove_wait_queue(&s->dma_dac.wait, &wait);
1308 set_current_state(TASK_RUNNING);
1311 tmo = 3 * HZ * (count + s->dma_dac.fragsize) / 2 / s->ratedac;
1312 tmo >>= sample_shift[(s->fmt >> SV_CFMT_ASHIFT) & SV_CFMT_MASK];
1313 if (!schedule_timeout(tmo + 1))
1314 printk(KERN_DEBUG "sv: dma timed out??\n");
1316 remove_wait_queue(&s->dma_dac.wait, &wait);
1317 set_current_state(TASK_RUNNING);
1318 if (signal_pending(current))
1319 return -ERESTARTSYS;
1323 /* --------------------------------------------------------------------- */
1325 static ssize_t sv_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
1327 struct sv_state *s = (struct sv_state *)file->private_data;
1328 DECLARE_WAITQUEUE(wait, current);
1330 unsigned long flags;
1335 if (s->dma_adc.mapped)
1337 if (!s->dma_adc.ready && (ret = prog_dmabuf(s, 1)))
1339 if (!access_ok(VERIFY_WRITE, buffer, count))
1343 spin_lock_irqsave(&s->lock, flags);
1345 spin_unlock_irqrestore(&s->lock, flags);
1347 add_wait_queue(&s->dma_adc.wait, &wait);
1349 spin_lock_irqsave(&s->lock, flags);
1350 swptr = s->dma_adc.swptr;
1351 cnt = s->dma_adc.dmasize-swptr;
1352 if (s->dma_adc.count < cnt)
1353 cnt = s->dma_adc.count;
1355 __set_current_state(TASK_INTERRUPTIBLE);
1356 spin_unlock_irqrestore(&s->lock, flags);
1360 if (s->dma_adc.enabled)
1362 if (file->f_flags & O_NONBLOCK) {
1367 if (!schedule_timeout(HZ)) {
1368 printk(KERN_DEBUG "sv: read: chip lockup? dmasz %u fragsz %u count %i hwptr %u swptr %u\n",
1369 s->dma_adc.dmasize, s->dma_adc.fragsize, s->dma_adc.count,
1370 s->dma_adc.hwptr, s->dma_adc.swptr);
1372 spin_lock_irqsave(&s->lock, flags);
1373 set_dmac(s, virt_to_bus(s->dma_adc.rawbuf), s->dma_adc.numfrag << s->dma_adc.fragshift);
1374 /* program enhanced mode registers */
1375 wrindir(s, SV_CIDMACBASECOUNT1, (s->dma_adc.fragsamples-1) >> 8);
1376 wrindir(s, SV_CIDMACBASECOUNT0, s->dma_adc.fragsamples-1);
1377 s->dma_adc.count = s->dma_adc.hwptr = s->dma_adc.swptr = 0;
1378 spin_unlock_irqrestore(&s->lock, flags);
1380 if (signal_pending(current)) {
1387 if (copy_to_user(buffer, s->dma_adc.rawbuf + swptr, cnt)) {
1392 swptr = (swptr + cnt) % s->dma_adc.dmasize;
1393 spin_lock_irqsave(&s->lock, flags);
1394 s->dma_adc.swptr = swptr;
1395 s->dma_adc.count -= cnt;
1396 spin_unlock_irqrestore(&s->lock, flags);
1400 if (s->dma_adc.enabled)
1403 remove_wait_queue(&s->dma_adc.wait, &wait);
1404 set_current_state(TASK_RUNNING);
1408 static ssize_t sv_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos)
1410 struct sv_state *s = (struct sv_state *)file->private_data;
1411 DECLARE_WAITQUEUE(wait, current);
1413 unsigned long flags;
1418 if (s->dma_dac.mapped)
1420 if (!s->dma_dac.ready && (ret = prog_dmabuf(s, 0)))
1422 if (!access_ok(VERIFY_READ, buffer, count))
1426 spin_lock_irqsave(&s->lock, flags);
1428 spin_unlock_irqrestore(&s->lock, flags);
1430 add_wait_queue(&s->dma_dac.wait, &wait);
1432 spin_lock_irqsave(&s->lock, flags);
1433 if (s->dma_dac.count < 0) {
1434 s->dma_dac.count = 0;
1435 s->dma_dac.swptr = s->dma_dac.hwptr;
1437 swptr = s->dma_dac.swptr;
1438 cnt = s->dma_dac.dmasize-swptr;
1439 if (s->dma_dac.count + cnt > s->dma_dac.dmasize)
1440 cnt = s->dma_dac.dmasize - s->dma_dac.count;
1442 __set_current_state(TASK_INTERRUPTIBLE);
1443 spin_unlock_irqrestore(&s->lock, flags);
1447 if (s->dma_dac.enabled)
1449 if (file->f_flags & O_NONBLOCK) {
1454 if (!schedule_timeout(HZ)) {
1455 printk(KERN_DEBUG "sv: write: chip lockup? dmasz %u fragsz %u count %i hwptr %u swptr %u\n",
1456 s->dma_dac.dmasize, s->dma_dac.fragsize, s->dma_dac.count,
1457 s->dma_dac.hwptr, s->dma_dac.swptr);
1459 spin_lock_irqsave(&s->lock, flags);
1460 set_dmaa(s, virt_to_bus(s->dma_dac.rawbuf), s->dma_dac.numfrag << s->dma_dac.fragshift);
1461 /* program enhanced mode registers */
1462 wrindir(s, SV_CIDMAABASECOUNT1, (s->dma_dac.fragsamples-1) >> 8);
1463 wrindir(s, SV_CIDMAABASECOUNT0, s->dma_dac.fragsamples-1);
1464 s->dma_dac.count = s->dma_dac.hwptr = s->dma_dac.swptr = 0;
1465 spin_unlock_irqrestore(&s->lock, flags);
1467 if (signal_pending(current)) {
1474 if (copy_from_user(s->dma_dac.rawbuf + swptr, buffer, cnt)) {
1479 swptr = (swptr + cnt) % s->dma_dac.dmasize;
1480 spin_lock_irqsave(&s->lock, flags);
1481 s->dma_dac.swptr = swptr;
1482 s->dma_dac.count += cnt;
1483 s->dma_dac.endcleared = 0;
1484 spin_unlock_irqrestore(&s->lock, flags);
1488 if (s->dma_dac.enabled)
1491 remove_wait_queue(&s->dma_dac.wait, &wait);
1492 set_current_state(TASK_RUNNING);
1496 /* No kernel lock - we have our own spinlock */
1497 static unsigned int sv_poll(struct file *file, struct poll_table_struct *wait)
1499 struct sv_state *s = (struct sv_state *)file->private_data;
1500 unsigned long flags;
1501 unsigned int mask = 0;
1504 if (file->f_mode & FMODE_WRITE) {
1505 if (!s->dma_dac.ready && prog_dmabuf(s, 1))
1507 poll_wait(file, &s->dma_dac.wait, wait);
1509 if (file->f_mode & FMODE_READ) {
1510 if (!s->dma_adc.ready && prog_dmabuf(s, 0))
1512 poll_wait(file, &s->dma_adc.wait, wait);
1514 spin_lock_irqsave(&s->lock, flags);
1516 if (file->f_mode & FMODE_READ) {
1517 if (s->dma_adc.count >= (signed)s->dma_adc.fragsize)
1518 mask |= POLLIN | POLLRDNORM;
1520 if (file->f_mode & FMODE_WRITE) {
1521 if (s->dma_dac.mapped) {
1522 if (s->dma_dac.count >= (signed)s->dma_dac.fragsize)
1523 mask |= POLLOUT | POLLWRNORM;
1525 if ((signed)s->dma_dac.dmasize >= s->dma_dac.count + (signed)s->dma_dac.fragsize)
1526 mask |= POLLOUT | POLLWRNORM;
1529 spin_unlock_irqrestore(&s->lock, flags);
1533 static int sv_mmap(struct file *file, struct vm_area_struct *vma)
1535 struct sv_state *s = (struct sv_state *)file->private_data;
1542 if (vma->vm_flags & VM_WRITE) {
1543 if ((ret = prog_dmabuf(s, 1)) != 0)
1546 } else if (vma->vm_flags & VM_READ) {
1547 if ((ret = prog_dmabuf(s, 0)) != 0)
1553 if (vma->vm_pgoff != 0)
1555 size = vma->vm_end - vma->vm_start;
1556 if (size > (PAGE_SIZE << db->buforder))
1559 if (remap_pfn_range(vma, vma->vm_start,
1560 virt_to_phys(db->rawbuf) >> PAGE_SHIFT,
1561 size, vma->vm_page_prot))
1570 static int sv_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
1572 struct sv_state *s = (struct sv_state *)file->private_data;
1573 unsigned long flags;
1574 audio_buf_info abinfo;
1577 int val, mapped, ret;
1578 unsigned char fmtm, fmtd;
1579 void __user *argp = (void __user *)arg;
1580 int __user *p = argp;
1583 mapped = ((file->f_mode & FMODE_WRITE) && s->dma_dac.mapped) ||
1584 ((file->f_mode & FMODE_READ) && s->dma_adc.mapped);
1586 case OSS_GETVERSION:
1587 return put_user(SOUND_VERSION, p);
1589 case SNDCTL_DSP_SYNC:
1590 if (file->f_mode & FMODE_WRITE)
1591 return drain_dac(s, 0/*file->f_flags & O_NONBLOCK*/);
1594 case SNDCTL_DSP_SETDUPLEX:
1597 case SNDCTL_DSP_GETCAPS:
1598 return put_user(DSP_CAP_DUPLEX | DSP_CAP_REALTIME | DSP_CAP_TRIGGER | DSP_CAP_MMAP, p);
1600 case SNDCTL_DSP_RESET:
1601 if (file->f_mode & FMODE_WRITE) {
1603 synchronize_irq(s->irq);
1604 s->dma_dac.swptr = s->dma_dac.hwptr = s->dma_dac.count = s->dma_dac.total_bytes = 0;
1606 if (file->f_mode & FMODE_READ) {
1608 synchronize_irq(s->irq);
1609 s->dma_adc.swptr = s->dma_adc.hwptr = s->dma_adc.count = s->dma_adc.total_bytes = 0;
1613 case SNDCTL_DSP_SPEED:
1614 if (get_user(val, p))
1617 if (file->f_mode & FMODE_READ) {
1619 s->dma_adc.ready = 0;
1620 set_adc_rate(s, val);
1622 if (file->f_mode & FMODE_WRITE) {
1624 s->dma_dac.ready = 0;
1625 set_dac_rate(s, val);
1628 return put_user((file->f_mode & FMODE_READ) ? s->rateadc : s->ratedac, p);
1630 case SNDCTL_DSP_STEREO:
1631 if (get_user(val, p))
1635 if (file->f_mode & FMODE_READ) {
1637 s->dma_adc.ready = 0;
1639 fmtd |= SV_CFMT_STEREO << SV_CFMT_CSHIFT;
1641 fmtm &= ~(SV_CFMT_STEREO << SV_CFMT_CSHIFT);
1643 if (file->f_mode & FMODE_WRITE) {
1645 s->dma_dac.ready = 0;
1647 fmtd |= SV_CFMT_STEREO << SV_CFMT_ASHIFT;
1649 fmtm &= ~(SV_CFMT_STEREO << SV_CFMT_ASHIFT);
1651 set_fmt(s, fmtm, fmtd);
1654 case SNDCTL_DSP_CHANNELS:
1655 if (get_user(val, p))
1660 if (file->f_mode & FMODE_READ) {
1662 s->dma_adc.ready = 0;
1664 fmtd |= SV_CFMT_STEREO << SV_CFMT_CSHIFT;
1666 fmtm &= ~(SV_CFMT_STEREO << SV_CFMT_CSHIFT);
1668 if (file->f_mode & FMODE_WRITE) {
1670 s->dma_dac.ready = 0;
1672 fmtd |= SV_CFMT_STEREO << SV_CFMT_ASHIFT;
1674 fmtm &= ~(SV_CFMT_STEREO << SV_CFMT_ASHIFT);
1676 set_fmt(s, fmtm, fmtd);
1678 return put_user((s->fmt & ((file->f_mode & FMODE_READ) ? (SV_CFMT_STEREO << SV_CFMT_CSHIFT)
1679 : (SV_CFMT_STEREO << SV_CFMT_ASHIFT))) ? 2 : 1, p);
1681 case SNDCTL_DSP_GETFMTS: /* Returns a mask */
1682 return put_user(AFMT_S16_LE|AFMT_U8, p);
1684 case SNDCTL_DSP_SETFMT: /* Selects ONE fmt*/
1685 if (get_user(val, p))
1687 if (val != AFMT_QUERY) {
1690 if (file->f_mode & FMODE_READ) {
1692 s->dma_adc.ready = 0;
1693 if (val == AFMT_S16_LE)
1694 fmtd |= SV_CFMT_16BIT << SV_CFMT_CSHIFT;
1696 fmtm &= ~(SV_CFMT_16BIT << SV_CFMT_CSHIFT);
1698 if (file->f_mode & FMODE_WRITE) {
1700 s->dma_dac.ready = 0;
1701 if (val == AFMT_S16_LE)
1702 fmtd |= SV_CFMT_16BIT << SV_CFMT_ASHIFT;
1704 fmtm &= ~(SV_CFMT_16BIT << SV_CFMT_ASHIFT);
1706 set_fmt(s, fmtm, fmtd);
1708 return put_user((s->fmt & ((file->f_mode & FMODE_READ) ? (SV_CFMT_16BIT << SV_CFMT_CSHIFT)
1709 : (SV_CFMT_16BIT << SV_CFMT_ASHIFT))) ? AFMT_S16_LE : AFMT_U8, p);
1711 case SNDCTL_DSP_POST:
1714 case SNDCTL_DSP_GETTRIGGER:
1716 if (file->f_mode & FMODE_READ && s->enable & SV_CENABLE_RE)
1717 val |= PCM_ENABLE_INPUT;
1718 if (file->f_mode & FMODE_WRITE && s->enable & SV_CENABLE_PE)
1719 val |= PCM_ENABLE_OUTPUT;
1720 return put_user(val, p);
1722 case SNDCTL_DSP_SETTRIGGER:
1723 if (get_user(val, p))
1725 if (file->f_mode & FMODE_READ) {
1726 if (val & PCM_ENABLE_INPUT) {
1727 if (!s->dma_adc.ready && (ret = prog_dmabuf(s, 1)))
1729 s->dma_adc.enabled = 1;
1732 s->dma_adc.enabled = 0;
1736 if (file->f_mode & FMODE_WRITE) {
1737 if (val & PCM_ENABLE_OUTPUT) {
1738 if (!s->dma_dac.ready && (ret = prog_dmabuf(s, 0)))
1740 s->dma_dac.enabled = 1;
1743 s->dma_dac.enabled = 0;
1749 case SNDCTL_DSP_GETOSPACE:
1750 if (!(file->f_mode & FMODE_WRITE))
1752 if (!s->dma_dac.ready && (val = prog_dmabuf(s, 0)) != 0)
1754 spin_lock_irqsave(&s->lock, flags);
1756 abinfo.fragsize = s->dma_dac.fragsize;
1757 count = s->dma_dac.count;
1760 abinfo.bytes = s->dma_dac.dmasize - count;
1761 abinfo.fragstotal = s->dma_dac.numfrag;
1762 abinfo.fragments = abinfo.bytes >> s->dma_dac.fragshift;
1763 spin_unlock_irqrestore(&s->lock, flags);
1764 return copy_to_user(argp, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
1766 case SNDCTL_DSP_GETISPACE:
1767 if (!(file->f_mode & FMODE_READ))
1769 if (!s->dma_adc.ready && (val = prog_dmabuf(s, 1)) != 0)
1771 spin_lock_irqsave(&s->lock, flags);
1773 abinfo.fragsize = s->dma_adc.fragsize;
1774 count = s->dma_adc.count;
1777 abinfo.bytes = count;
1778 abinfo.fragstotal = s->dma_adc.numfrag;
1779 abinfo.fragments = abinfo.bytes >> s->dma_adc.fragshift;
1780 spin_unlock_irqrestore(&s->lock, flags);
1781 return copy_to_user(argp, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
1783 case SNDCTL_DSP_NONBLOCK:
1784 file->f_flags |= O_NONBLOCK;
1787 case SNDCTL_DSP_GETODELAY:
1788 if (!(file->f_mode & FMODE_WRITE))
1790 if (!s->dma_dac.ready && (val = prog_dmabuf(s, 0)) != 0)
1792 spin_lock_irqsave(&s->lock, flags);
1794 count = s->dma_dac.count;
1795 spin_unlock_irqrestore(&s->lock, flags);
1798 return put_user(count, p);
1800 case SNDCTL_DSP_GETIPTR:
1801 if (!(file->f_mode & FMODE_READ))
1803 if (!s->dma_adc.ready && (val = prog_dmabuf(s, 1)) != 0)
1805 spin_lock_irqsave(&s->lock, flags);
1807 cinfo.bytes = s->dma_adc.total_bytes;
1808 count = s->dma_adc.count;
1811 cinfo.blocks = count >> s->dma_adc.fragshift;
1812 cinfo.ptr = s->dma_adc.hwptr;
1813 if (s->dma_adc.mapped)
1814 s->dma_adc.count &= s->dma_adc.fragsize-1;
1815 spin_unlock_irqrestore(&s->lock, flags);
1816 if (copy_to_user(argp, &cinfo, sizeof(cinfo)))
1820 case SNDCTL_DSP_GETOPTR:
1821 if (!(file->f_mode & FMODE_WRITE))
1823 if (!s->dma_dac.ready && (val = prog_dmabuf(s, 0)) != 0)
1825 spin_lock_irqsave(&s->lock, flags);
1827 cinfo.bytes = s->dma_dac.total_bytes;
1828 count = s->dma_dac.count;
1831 cinfo.blocks = count >> s->dma_dac.fragshift;
1832 cinfo.ptr = s->dma_dac.hwptr;
1833 if (s->dma_dac.mapped)
1834 s->dma_dac.count &= s->dma_dac.fragsize-1;
1835 spin_unlock_irqrestore(&s->lock, flags);
1836 if (copy_to_user(argp, &cinfo, sizeof(cinfo)))
1840 case SNDCTL_DSP_GETBLKSIZE:
1841 if (file->f_mode & FMODE_WRITE) {
1842 if ((val = prog_dmabuf(s, 0)))
1844 return put_user(s->dma_dac.fragsize, p);
1846 if ((val = prog_dmabuf(s, 1)))
1848 return put_user(s->dma_adc.fragsize, p);
1850 case SNDCTL_DSP_SETFRAGMENT:
1851 if (get_user(val, p))
1853 if (file->f_mode & FMODE_READ) {
1854 s->dma_adc.ossfragshift = val & 0xffff;
1855 s->dma_adc.ossmaxfrags = (val >> 16) & 0xffff;
1856 if (s->dma_adc.ossfragshift < 4)
1857 s->dma_adc.ossfragshift = 4;
1858 if (s->dma_adc.ossfragshift > 15)
1859 s->dma_adc.ossfragshift = 15;
1860 if (s->dma_adc.ossmaxfrags < 4)
1861 s->dma_adc.ossmaxfrags = 4;
1863 if (file->f_mode & FMODE_WRITE) {
1864 s->dma_dac.ossfragshift = val & 0xffff;
1865 s->dma_dac.ossmaxfrags = (val >> 16) & 0xffff;
1866 if (s->dma_dac.ossfragshift < 4)
1867 s->dma_dac.ossfragshift = 4;
1868 if (s->dma_dac.ossfragshift > 15)
1869 s->dma_dac.ossfragshift = 15;
1870 if (s->dma_dac.ossmaxfrags < 4)
1871 s->dma_dac.ossmaxfrags = 4;
1875 case SNDCTL_DSP_SUBDIVIDE:
1876 if ((file->f_mode & FMODE_READ && s->dma_adc.subdivision) ||
1877 (file->f_mode & FMODE_WRITE && s->dma_dac.subdivision))
1879 if (get_user(val, p))
1881 if (val != 1 && val != 2 && val != 4)
1883 if (file->f_mode & FMODE_READ)
1884 s->dma_adc.subdivision = val;
1885 if (file->f_mode & FMODE_WRITE)
1886 s->dma_dac.subdivision = val;
1889 case SOUND_PCM_READ_RATE:
1890 return put_user((file->f_mode & FMODE_READ) ? s->rateadc : s->ratedac, p);
1892 case SOUND_PCM_READ_CHANNELS:
1893 return put_user((s->fmt & ((file->f_mode & FMODE_READ) ? (SV_CFMT_STEREO << SV_CFMT_CSHIFT)
1894 : (SV_CFMT_STEREO << SV_CFMT_ASHIFT))) ? 2 : 1, p);
1896 case SOUND_PCM_READ_BITS:
1897 return put_user((s->fmt & ((file->f_mode & FMODE_READ) ? (SV_CFMT_16BIT << SV_CFMT_CSHIFT)
1898 : (SV_CFMT_16BIT << SV_CFMT_ASHIFT))) ? 16 : 8, p);
1900 case SOUND_PCM_WRITE_FILTER:
1901 case SNDCTL_DSP_SETSYNCRO:
1902 case SOUND_PCM_READ_FILTER:
1906 return mixer_ioctl(s, cmd, arg);
1909 static int sv_open(struct inode *inode, struct file *file)
1911 int minor = iminor(inode);
1912 DECLARE_WAITQUEUE(wait, current);
1913 unsigned char fmtm = ~0, fmts = 0;
1914 struct list_head *list;
1917 for (list = devs.next; ; list = list->next) {
1920 s = list_entry(list, struct sv_state, devs);
1921 if (!((s->dev_audio ^ minor) & ~0xf))
1925 file->private_data = s;
1926 /* wait for device to become free */
1927 mutex_lock(&s->open_mutex);
1928 while (s->open_mode & file->f_mode) {
1929 if (file->f_flags & O_NONBLOCK) {
1930 mutex_unlock(&s->open_mutex);
1933 add_wait_queue(&s->open_wait, &wait);
1934 __set_current_state(TASK_INTERRUPTIBLE);
1935 mutex_unlock(&s->open_mutex);
1937 remove_wait_queue(&s->open_wait, &wait);
1938 set_current_state(TASK_RUNNING);
1939 if (signal_pending(current))
1940 return -ERESTARTSYS;
1941 mutex_lock(&s->open_mutex);
1943 if (file->f_mode & FMODE_READ) {
1944 fmtm &= ~((SV_CFMT_STEREO | SV_CFMT_16BIT) << SV_CFMT_CSHIFT);
1945 if ((minor & 0xf) == SND_DEV_DSP16)
1946 fmts |= SV_CFMT_16BIT << SV_CFMT_CSHIFT;
1947 s->dma_adc.ossfragshift = s->dma_adc.ossmaxfrags = s->dma_adc.subdivision = 0;
1948 s->dma_adc.enabled = 1;
1949 set_adc_rate(s, 8000);
1951 if (file->f_mode & FMODE_WRITE) {
1952 fmtm &= ~((SV_CFMT_STEREO | SV_CFMT_16BIT) << SV_CFMT_ASHIFT);
1953 if ((minor & 0xf) == SND_DEV_DSP16)
1954 fmts |= SV_CFMT_16BIT << SV_CFMT_ASHIFT;
1955 s->dma_dac.ossfragshift = s->dma_dac.ossmaxfrags = s->dma_dac.subdivision = 0;
1956 s->dma_dac.enabled = 1;
1957 set_dac_rate(s, 8000);
1959 set_fmt(s, fmtm, fmts);
1960 s->open_mode |= file->f_mode & (FMODE_READ | FMODE_WRITE);
1961 mutex_unlock(&s->open_mutex);
1962 return nonseekable_open(inode, file);
1965 static int sv_release(struct inode *inode, struct file *file)
1967 struct sv_state *s = (struct sv_state *)file->private_data;
1971 if (file->f_mode & FMODE_WRITE)
1972 drain_dac(s, file->f_flags & O_NONBLOCK);
1973 mutex_lock(&s->open_mutex);
1974 if (file->f_mode & FMODE_WRITE) {
1976 dealloc_dmabuf(s, &s->dma_dac);
1978 if (file->f_mode & FMODE_READ) {
1980 dealloc_dmabuf(s, &s->dma_adc);
1982 s->open_mode &= ~(file->f_mode & (FMODE_READ|FMODE_WRITE));
1983 wake_up(&s->open_wait);
1984 mutex_unlock(&s->open_mutex);
1989 static /*const*/ struct file_operations sv_audio_fops = {
1990 .owner = THIS_MODULE,
1991 .llseek = no_llseek,
1998 .release = sv_release,
2001 /* --------------------------------------------------------------------- */
2003 static ssize_t sv_midi_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
2005 struct sv_state *s = (struct sv_state *)file->private_data;
2006 DECLARE_WAITQUEUE(wait, current);
2008 unsigned long flags;
2013 if (!access_ok(VERIFY_WRITE, buffer, count))
2018 add_wait_queue(&s->midi.iwait, &wait);
2020 spin_lock_irqsave(&s->lock, flags);
2022 cnt = MIDIINBUF - ptr;
2023 if (s->midi.icnt < cnt)
2026 __set_current_state(TASK_INTERRUPTIBLE);
2027 spin_unlock_irqrestore(&s->lock, flags);
2031 if (file->f_flags & O_NONBLOCK) {
2037 if (signal_pending(current)) {
2044 if (copy_to_user(buffer, s->midi.ibuf + ptr, cnt)) {
2049 ptr = (ptr + cnt) % MIDIINBUF;
2050 spin_lock_irqsave(&s->lock, flags);
2052 s->midi.icnt -= cnt;
2053 spin_unlock_irqrestore(&s->lock, flags);
2059 __set_current_state(TASK_RUNNING);
2060 remove_wait_queue(&s->midi.iwait, &wait);
2064 static ssize_t sv_midi_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos)
2066 struct sv_state *s = (struct sv_state *)file->private_data;
2067 DECLARE_WAITQUEUE(wait, current);
2069 unsigned long flags;
2074 if (!access_ok(VERIFY_READ, buffer, count))
2079 add_wait_queue(&s->midi.owait, &wait);
2081 spin_lock_irqsave(&s->lock, flags);
2083 cnt = MIDIOUTBUF - ptr;
2084 if (s->midi.ocnt + cnt > MIDIOUTBUF)
2085 cnt = MIDIOUTBUF - s->midi.ocnt;
2087 __set_current_state(TASK_INTERRUPTIBLE);
2090 spin_unlock_irqrestore(&s->lock, flags);
2094 if (file->f_flags & O_NONBLOCK) {
2100 if (signal_pending(current)) {
2107 if (copy_from_user(s->midi.obuf + ptr, buffer, cnt)) {
2112 ptr = (ptr + cnt) % MIDIOUTBUF;
2113 spin_lock_irqsave(&s->lock, flags);
2115 s->midi.ocnt += cnt;
2116 spin_unlock_irqrestore(&s->lock, flags);
2120 spin_lock_irqsave(&s->lock, flags);
2122 spin_unlock_irqrestore(&s->lock, flags);
2124 __set_current_state(TASK_RUNNING);
2125 remove_wait_queue(&s->midi.owait, &wait);
2129 /* No kernel lock - we have our own spinlock */
2130 static unsigned int sv_midi_poll(struct file *file, struct poll_table_struct *wait)
2132 struct sv_state *s = (struct sv_state *)file->private_data;
2133 unsigned long flags;
2134 unsigned int mask = 0;
2137 if (file->f_mode & FMODE_WRITE)
2138 poll_wait(file, &s->midi.owait, wait);
2139 if (file->f_mode & FMODE_READ)
2140 poll_wait(file, &s->midi.iwait, wait);
2141 spin_lock_irqsave(&s->lock, flags);
2142 if (file->f_mode & FMODE_READ) {
2143 if (s->midi.icnt > 0)
2144 mask |= POLLIN | POLLRDNORM;
2146 if (file->f_mode & FMODE_WRITE) {
2147 if (s->midi.ocnt < MIDIOUTBUF)
2148 mask |= POLLOUT | POLLWRNORM;
2150 spin_unlock_irqrestore(&s->lock, flags);
2154 static int sv_midi_open(struct inode *inode, struct file *file)
2156 int minor = iminor(inode);
2157 DECLARE_WAITQUEUE(wait, current);
2158 unsigned long flags;
2159 struct list_head *list;
2162 for (list = devs.next; ; list = list->next) {
2165 s = list_entry(list, struct sv_state, devs);
2166 if (s->dev_midi == minor)
2170 file->private_data = s;
2171 /* wait for device to become free */
2172 mutex_lock(&s->open_mutex);
2173 while (s->open_mode & (file->f_mode << FMODE_MIDI_SHIFT)) {
2174 if (file->f_flags & O_NONBLOCK) {
2175 mutex_unlock(&s->open_mutex);
2178 add_wait_queue(&s->open_wait, &wait);
2179 __set_current_state(TASK_INTERRUPTIBLE);
2180 mutex_unlock(&s->open_mutex);
2182 remove_wait_queue(&s->open_wait, &wait);
2183 set_current_state(TASK_RUNNING);
2184 if (signal_pending(current))
2185 return -ERESTARTSYS;
2186 mutex_lock(&s->open_mutex);
2188 spin_lock_irqsave(&s->lock, flags);
2189 if (!(s->open_mode & (FMODE_MIDI_READ | FMODE_MIDI_WRITE))) {
2190 s->midi.ird = s->midi.iwr = s->midi.icnt = 0;
2191 s->midi.ord = s->midi.owr = s->midi.ocnt = 0;
2192 //outb(inb(s->ioenh + SV_CODEC_CONTROL) | SV_CCTRL_WAVETABLE, s->ioenh + SV_CODEC_CONTROL);
2193 outb(inb(s->ioenh + SV_CODEC_INTMASK) | SV_CINTMASK_MIDI, s->ioenh + SV_CODEC_INTMASK);
2194 wrindir(s, SV_CIUARTCONTROL, 5); /* output MIDI data to external and internal synth */
2195 wrindir(s, SV_CIWAVETABLESRC, 1); /* Wavetable in PC RAM */
2196 outb(0xff, s->iomidi+1); /* reset command */
2197 outb(0x3f, s->iomidi+1); /* uart command */
2198 if (!(inb(s->iomidi+1) & 0x80))
2200 s->midi.ird = s->midi.iwr = s->midi.icnt = 0;
2201 init_timer(&s->midi.timer);
2202 s->midi.timer.expires = jiffies+1;
2203 s->midi.timer.data = (unsigned long)s;
2204 s->midi.timer.function = sv_midi_timer;
2205 add_timer(&s->midi.timer);
2207 if (file->f_mode & FMODE_READ) {
2208 s->midi.ird = s->midi.iwr = s->midi.icnt = 0;
2210 if (file->f_mode & FMODE_WRITE) {
2211 s->midi.ord = s->midi.owr = s->midi.ocnt = 0;
2213 spin_unlock_irqrestore(&s->lock, flags);
2214 s->open_mode |= (file->f_mode << FMODE_MIDI_SHIFT) & (FMODE_MIDI_READ | FMODE_MIDI_WRITE);
2215 mutex_unlock(&s->open_mutex);
2216 return nonseekable_open(inode, file);
2219 static int sv_midi_release(struct inode *inode, struct file *file)
2221 struct sv_state *s = (struct sv_state *)file->private_data;
2222 DECLARE_WAITQUEUE(wait, current);
2223 unsigned long flags;
2224 unsigned count, tmo;
2229 if (file->f_mode & FMODE_WRITE) {
2230 add_wait_queue(&s->midi.owait, &wait);
2232 __set_current_state(TASK_INTERRUPTIBLE);
2233 spin_lock_irqsave(&s->lock, flags);
2234 count = s->midi.ocnt;
2235 spin_unlock_irqrestore(&s->lock, flags);
2238 if (signal_pending(current))
2240 if (file->f_flags & O_NONBLOCK) {
2241 remove_wait_queue(&s->midi.owait, &wait);
2242 set_current_state(TASK_RUNNING);
2246 tmo = (count * HZ) / 3100;
2247 if (!schedule_timeout(tmo ? : 1) && tmo)
2248 printk(KERN_DEBUG "sv: midi timed out??\n");
2250 remove_wait_queue(&s->midi.owait, &wait);
2251 set_current_state(TASK_RUNNING);
2253 mutex_lock(&s->open_mutex);
2254 s->open_mode &= ~((file->f_mode << FMODE_MIDI_SHIFT) & (FMODE_MIDI_READ|FMODE_MIDI_WRITE));
2255 spin_lock_irqsave(&s->lock, flags);
2256 if (!(s->open_mode & (FMODE_MIDI_READ | FMODE_MIDI_WRITE))) {
2257 outb(inb(s->ioenh + SV_CODEC_INTMASK) & ~SV_CINTMASK_MIDI, s->ioenh + SV_CODEC_INTMASK);
2258 del_timer(&s->midi.timer);
2260 spin_unlock_irqrestore(&s->lock, flags);
2261 wake_up(&s->open_wait);
2262 mutex_unlock(&s->open_mutex);
2267 static /*const*/ struct file_operations sv_midi_fops = {
2268 .owner = THIS_MODULE,
2269 .llseek = no_llseek,
2270 .read = sv_midi_read,
2271 .write = sv_midi_write,
2272 .poll = sv_midi_poll,
2273 .open = sv_midi_open,
2274 .release = sv_midi_release,
2277 /* --------------------------------------------------------------------- */
2279 static int sv_dmfm_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
2281 static const unsigned char op_offset[18] = {
2282 0x00, 0x01, 0x02, 0x03, 0x04, 0x05,
2283 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D,
2284 0x10, 0x11, 0x12, 0x13, 0x14, 0x15
2286 struct sv_state *s = (struct sv_state *)file->private_data;
2287 struct dm_fm_voice v;
2288 struct dm_fm_note n;
2289 struct dm_fm_params p;
2294 case FM_IOCTL_RESET:
2295 for (regb = 0xb0; regb < 0xb9; regb++) {
2296 outb(regb, s->iosynth);
2297 outb(0, s->iosynth+1);
2298 outb(regb, s->iosynth+2);
2299 outb(0, s->iosynth+3);
2303 case FM_IOCTL_PLAY_NOTE:
2304 if (copy_from_user(&n, (void __user *)arg, sizeof(n)))
2315 outb(0xa0 + regb, io);
2316 outb(n.fnum & 0xff, io+1);
2317 outb(0xb0 + regb, io);
2318 outb(((n.fnum >> 8) & 3) | ((n.octave & 7) << 2) | ((n.key_on & 1) << 5), io+1);
2321 case FM_IOCTL_SET_VOICE:
2322 if (copy_from_user(&v, (void __user *)arg, sizeof(v)))
2326 regb = op_offset[v.voice];
2327 io = s->iosynth + ((v.op & 1) << 1);
2328 outb(0x20 + regb, io);
2329 outb(((v.am & 1) << 7) | ((v.vibrato & 1) << 6) | ((v.do_sustain & 1) << 5) |
2330 ((v.kbd_scale & 1) << 4) | (v.harmonic & 0xf), io+1);
2331 outb(0x40 + regb, io);
2332 outb(((v.scale_level & 0x3) << 6) | (v.volume & 0x3f), io+1);
2333 outb(0x60 + regb, io);
2334 outb(((v.attack & 0xf) << 4) | (v.decay & 0xf), io+1);
2335 outb(0x80 + regb, io);
2336 outb(((v.sustain & 0xf) << 4) | (v.release & 0xf), io+1);
2337 outb(0xe0 + regb, io);
2338 outb(v.waveform & 0x7, io+1);
2346 outb(0xc0 + regb, io);
2347 outb(((v.right & 1) << 5) | ((v.left & 1) << 4) | ((v.feedback & 7) << 1) |
2348 (v.connection & 1), io+1);
2351 case FM_IOCTL_SET_PARAMS:
2352 if (copy_from_user(&p, (void *__user )arg, sizeof(p)))
2354 outb(0x08, s->iosynth);
2355 outb((p.kbd_split & 1) << 6, s->iosynth+1);
2356 outb(0xbd, s->iosynth);
2357 outb(((p.am_depth & 1) << 7) | ((p.vib_depth & 1) << 6) | ((p.rhythm & 1) << 5) | ((p.bass & 1) << 4) |
2358 ((p.snare & 1) << 3) | ((p.tomtom & 1) << 2) | ((p.cymbal & 1) << 1) | (p.hihat & 1), s->iosynth+1);
2361 case FM_IOCTL_SET_OPL:
2362 outb(4, s->iosynth+2);
2363 outb(arg, s->iosynth+3);
2366 case FM_IOCTL_SET_MODE:
2367 outb(5, s->iosynth+2);
2368 outb(arg & 1, s->iosynth+3);
2376 static int sv_dmfm_open(struct inode *inode, struct file *file)
2378 int minor = iminor(inode);
2379 DECLARE_WAITQUEUE(wait, current);
2380 struct list_head *list;
2383 for (list = devs.next; ; list = list->next) {
2386 s = list_entry(list, struct sv_state, devs);
2387 if (s->dev_dmfm == minor)
2391 file->private_data = s;
2392 /* wait for device to become free */
2393 mutex_lock(&s->open_mutex);
2394 while (s->open_mode & FMODE_DMFM) {
2395 if (file->f_flags & O_NONBLOCK) {
2396 mutex_unlock(&s->open_mutex);
2399 add_wait_queue(&s->open_wait, &wait);
2400 __set_current_state(TASK_INTERRUPTIBLE);
2401 mutex_unlock(&s->open_mutex);
2403 remove_wait_queue(&s->open_wait, &wait);
2404 set_current_state(TASK_RUNNING);
2405 if (signal_pending(current))
2406 return -ERESTARTSYS;
2407 mutex_lock(&s->open_mutex);
2409 /* init the stuff */
2410 outb(1, s->iosynth);
2411 outb(0x20, s->iosynth+1); /* enable waveforms */
2412 outb(4, s->iosynth+2);
2413 outb(0, s->iosynth+3); /* no 4op enabled */
2414 outb(5, s->iosynth+2);
2415 outb(1, s->iosynth+3); /* enable OPL3 */
2416 s->open_mode |= FMODE_DMFM;
2417 mutex_unlock(&s->open_mutex);
2418 return nonseekable_open(inode, file);
2421 static int sv_dmfm_release(struct inode *inode, struct file *file)
2423 struct sv_state *s = (struct sv_state *)file->private_data;
2428 mutex_lock(&s->open_mutex);
2429 s->open_mode &= ~FMODE_DMFM;
2430 for (regb = 0xb0; regb < 0xb9; regb++) {
2431 outb(regb, s->iosynth);
2432 outb(0, s->iosynth+1);
2433 outb(regb, s->iosynth+2);
2434 outb(0, s->iosynth+3);
2436 wake_up(&s->open_wait);
2437 mutex_unlock(&s->open_mutex);
2442 static /*const*/ struct file_operations sv_dmfm_fops = {
2443 .owner = THIS_MODULE,
2444 .llseek = no_llseek,
2445 .ioctl = sv_dmfm_ioctl,
2446 .open = sv_dmfm_open,
2447 .release = sv_dmfm_release,
2450 /* --------------------------------------------------------------------- */
2452 /* maximum number of devices; only used for command line params */
2455 static int reverb[NR_DEVICE];
2458 static int wavetable[NR_DEVICE];
2461 static unsigned int devindex;
2463 module_param_array(reverb, bool, NULL, 0);
2464 MODULE_PARM_DESC(reverb, "if 1 enables the reverb circuitry. NOTE: your card must have the reverb RAM");
2466 MODULE_PARM(wavetable, "1-" __MODULE_STRING(NR_DEVICE) "i");
2467 MODULE_PARM_DESC(wavetable, "if 1 the wavetable synth is enabled");
2470 MODULE_AUTHOR("Thomas M. Sailer, sailer@ife.ee.ethz.ch, hb9jnx@hb9w.che.eu");
2471 MODULE_DESCRIPTION("S3 SonicVibes Driver");
2472 MODULE_LICENSE("GPL");
2475 /* --------------------------------------------------------------------- */
2477 static struct initvol {
2480 } initvol[] __devinitdata = {
2481 { SOUND_MIXER_WRITE_RECLEV, 0x4040 },
2482 { SOUND_MIXER_WRITE_LINE1, 0x4040 },
2483 { SOUND_MIXER_WRITE_CD, 0x4040 },
2484 { SOUND_MIXER_WRITE_LINE, 0x4040 },
2485 { SOUND_MIXER_WRITE_MIC, 0x4040 },
2486 { SOUND_MIXER_WRITE_SYNTH, 0x4040 },
2487 { SOUND_MIXER_WRITE_LINE2, 0x4040 },
2488 { SOUND_MIXER_WRITE_VOLUME, 0x4040 },
2489 { SOUND_MIXER_WRITE_PCM, 0x4040 }
2492 #define RSRCISIOREGION(dev,num) (pci_resource_start((dev), (num)) != 0 && \
2493 (pci_resource_flags((dev), (num)) & IORESOURCE_IO))
2495 #ifdef SUPPORT_JOYSTICK
2496 static int __devinit sv_register_gameport(struct sv_state *s, int io_port)
2498 struct gameport *gp;
2500 if (!request_region(io_port, SV_EXTENT_GAME, "S3 SonicVibes Gameport")) {
2501 printk(KERN_ERR "sv: gameport io ports are in use\n");
2505 s->gameport = gp = gameport_allocate_port();
2507 printk(KERN_ERR "sv: can not allocate memory for gameport\n");
2508 release_region(io_port, SV_EXTENT_GAME);
2512 gameport_set_name(gp, "S3 SonicVibes Gameport");
2513 gameport_set_phys(gp, "isa%04x/gameport0", io_port);
2514 gp->dev.parent = &s->dev->dev;
2517 gameport_register_port(gp);
2522 static inline void sv_unregister_gameport(struct sv_state *s)
2525 int gpio = s->gameport->io;
2526 gameport_unregister_port(s->gameport);
2527 release_region(gpio, SV_EXTENT_GAME);
2531 static inline int sv_register_gameport(struct sv_state *s, int io_port) { return -ENOSYS; }
2532 static inline void sv_unregister_gameport(struct sv_state *s) { }
2533 #endif /* SUPPORT_JOYSTICK */
2535 static int __devinit sv_probe(struct pci_dev *pcidev, const struct pci_device_id *pciid)
2537 static char __devinitdata sv_ddma_name[] = "S3 Inc. SonicVibes DDMA Controller";
2543 unsigned ddmanamelen;
2545 if ((ret=pci_enable_device(pcidev)))
2548 if (!RSRCISIOREGION(pcidev, RESOURCE_SB) ||
2549 !RSRCISIOREGION(pcidev, RESOURCE_ENH) ||
2550 !RSRCISIOREGION(pcidev, RESOURCE_SYNTH) ||
2551 !RSRCISIOREGION(pcidev, RESOURCE_MIDI) ||
2552 !RSRCISIOREGION(pcidev, RESOURCE_GAME))
2554 if (pcidev->irq == 0)
2556 if (pci_set_dma_mask(pcidev, 0x00ffffff)) {
2557 printk(KERN_WARNING "sonicvibes: architecture does not support 24bit PCI busmaster DMA\n");
2560 /* try to allocate a DDMA resource if not already available */
2561 if (!RSRCISIOREGION(pcidev, RESOURCE_DDMA)) {
2562 pcidev->resource[RESOURCE_DDMA].start = 0;
2563 pcidev->resource[RESOURCE_DDMA].end = 2*SV_EXTENT_DMA-1;
2564 pcidev->resource[RESOURCE_DDMA].flags = PCI_BASE_ADDRESS_SPACE_IO | IORESOURCE_IO;
2565 ddmanamelen = strlen(sv_ddma_name)+1;
2566 if (!(ddmaname = kmalloc(ddmanamelen, GFP_KERNEL)))
2568 memcpy(ddmaname, sv_ddma_name, ddmanamelen);
2569 pcidev->resource[RESOURCE_DDMA].name = ddmaname;
2570 if (pci_assign_resource(pcidev, RESOURCE_DDMA)) {
2571 pcidev->resource[RESOURCE_DDMA].name = NULL;
2573 printk(KERN_ERR "sv: cannot allocate DDMA controller io ports\n");
2577 if (!(s = kmalloc(sizeof(struct sv_state), GFP_KERNEL))) {
2578 printk(KERN_WARNING "sv: out of memory\n");
2581 memset(s, 0, sizeof(struct sv_state));
2582 init_waitqueue_head(&s->dma_adc.wait);
2583 init_waitqueue_head(&s->dma_dac.wait);
2584 init_waitqueue_head(&s->open_wait);
2585 init_waitqueue_head(&s->midi.iwait);
2586 init_waitqueue_head(&s->midi.owait);
2587 mutex_init(&s->open_mutex);
2588 spin_lock_init(&s->lock);
2589 s->magic = SV_MAGIC;
2591 s->iosb = pci_resource_start(pcidev, RESOURCE_SB);
2592 s->ioenh = pci_resource_start(pcidev, RESOURCE_ENH);
2593 s->iosynth = pci_resource_start(pcidev, RESOURCE_SYNTH);
2594 s->iomidi = pci_resource_start(pcidev, RESOURCE_MIDI);
2595 s->iodmaa = pci_resource_start(pcidev, RESOURCE_DDMA);
2596 s->iodmac = pci_resource_start(pcidev, RESOURCE_DDMA) + SV_EXTENT_DMA;
2597 gpio = pci_resource_start(pcidev, RESOURCE_GAME);
2598 pci_write_config_dword(pcidev, 0x40, s->iodmaa | 9); /* enable and use extended mode */
2599 pci_write_config_dword(pcidev, 0x48, s->iodmac | 9); /* enable */
2600 printk(KERN_DEBUG "sv: io ports: %#lx %#lx %#lx %#lx %#x %#x %#x\n",
2601 s->iosb, s->ioenh, s->iosynth, s->iomidi, gpio, s->iodmaa, s->iodmac);
2602 s->irq = pcidev->irq;
2605 pci_write_config_dword(pcidev, 0x60, wavetable_mem >> 12); /* wavetable base address */
2608 if (!request_region(s->ioenh, SV_EXTENT_ENH, "S3 SonicVibes PCM")) {
2609 printk(KERN_ERR "sv: io ports %#lx-%#lx in use\n", s->ioenh, s->ioenh+SV_EXTENT_ENH-1);
2612 if (!request_region(s->iodmaa, SV_EXTENT_DMA, "S3 SonicVibes DMAA")) {
2613 printk(KERN_ERR "sv: io ports %#x-%#x in use\n", s->iodmaa, s->iodmaa+SV_EXTENT_DMA-1);
2616 if (!request_region(s->iodmac, SV_EXTENT_DMA, "S3 SonicVibes DMAC")) {
2617 printk(KERN_ERR "sv: io ports %#x-%#x in use\n", s->iodmac, s->iodmac+SV_EXTENT_DMA-1);
2620 if (!request_region(s->iomidi, SV_EXTENT_MIDI, "S3 SonicVibes Midi")) {
2621 printk(KERN_ERR "sv: io ports %#lx-%#lx in use\n", s->iomidi, s->iomidi+SV_EXTENT_MIDI-1);
2624 if (!request_region(s->iosynth, SV_EXTENT_SYNTH, "S3 SonicVibes Synth")) {
2625 printk(KERN_ERR "sv: io ports %#lx-%#lx in use\n", s->iosynth, s->iosynth+SV_EXTENT_SYNTH-1);
2629 /* initialize codec registers */
2630 outb(0x80, s->ioenh + SV_CODEC_CONTROL); /* assert reset */
2632 outb(0x00, s->ioenh + SV_CODEC_CONTROL); /* deassert reset */
2634 outb(SV_CCTRL_INTADRIVE | SV_CCTRL_ENHANCED /*| SV_CCTRL_WAVETABLE */
2635 | (reverb[devindex] ? SV_CCTRL_REVERB : 0), s->ioenh + SV_CODEC_CONTROL);
2636 inb(s->ioenh + SV_CODEC_STATUS); /* clear ints */
2637 wrindir(s, SV_CIDRIVECONTROL, 0); /* drive current 16mA */
2638 wrindir(s, SV_CIENABLE, s->enable = 0); /* disable DMAA and DMAC */
2639 outb(~(SV_CINTMASK_DMAA | SV_CINTMASK_DMAC), s->ioenh + SV_CODEC_INTMASK);
2640 /* outb(0xff, s->iodmaa + SV_DMA_RESET); */
2641 /* outb(0xff, s->iodmac + SV_DMA_RESET); */
2642 inb(s->ioenh + SV_CODEC_STATUS); /* ack interrupts */
2643 wrindir(s, SV_CIADCCLKSOURCE, 0); /* use pll as ADC clock source */
2644 wrindir(s, SV_CIANALOGPWRDOWN, 0); /* power up the analog parts of the device */
2645 wrindir(s, SV_CIDIGITALPWRDOWN, 0); /* power up the digital parts of the device */
2646 setpll(s, SV_CIADCPLLM, 8000);
2647 wrindir(s, SV_CISRSSPACE, 0x80); /* SRS off */
2648 wrindir(s, SV_CIPCMSR0, (8000 * 65536 / FULLRATE) & 0xff);
2649 wrindir(s, SV_CIPCMSR1, ((8000 * 65536 / FULLRATE) >> 8) & 0xff);
2650 wrindir(s, SV_CIADCOUTPUT, 0);
2652 if ((ret=request_irq(s->irq,sv_interrupt,SA_SHIRQ,"S3 SonicVibes",s))) {
2653 printk(KERN_ERR "sv: irq %u in use\n", s->irq);
2656 printk(KERN_INFO "sv: found adapter at io %#lx irq %u dmaa %#06x dmac %#06x revision %u\n",
2657 s->ioenh, s->irq, s->iodmaa, s->iodmac, rdindir(s, SV_CIREVISION));
2658 /* register devices */
2659 if ((s->dev_audio = register_sound_dsp(&sv_audio_fops, -1)) < 0) {
2663 if ((s->dev_mixer = register_sound_mixer(&sv_mixer_fops, -1)) < 0) {
2667 if ((s->dev_midi = register_sound_midi(&sv_midi_fops, -1)) < 0) {
2671 if ((s->dev_dmfm = register_sound_special(&sv_dmfm_fops, 15 /* ?? */)) < 0) {
2675 pci_set_master(pcidev); /* enable bus mastering */
2676 /* initialize the chips */
2679 val = SOUND_MASK_LINE|SOUND_MASK_SYNTH;
2680 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long)&val);
2681 for (i = 0; i < sizeof(initvol)/sizeof(initvol[0]); i++) {
2682 val = initvol[i].vol;
2683 mixer_ioctl(s, initvol[i].mixch, (unsigned long)&val);
2686 /* register gameport */
2687 sv_register_gameport(s, gpio);
2688 /* store it in the driver field */
2689 pci_set_drvdata(pcidev, s);
2690 /* put it into driver list */
2691 list_add_tail(&s->devs, &devs);
2692 /* increment devindex */
2693 if (devindex < NR_DEVICE-1)
2698 unregister_sound_midi(s->dev_midi);
2700 unregister_sound_mixer(s->dev_mixer);
2702 unregister_sound_dsp(s->dev_audio);
2704 printk(KERN_ERR "sv: cannot register misc device\n");
2705 free_irq(s->irq, s);
2707 release_region(s->iosynth, SV_EXTENT_SYNTH);
2709 release_region(s->iomidi, SV_EXTENT_MIDI);
2711 release_region(s->iodmac, SV_EXTENT_DMA);
2713 release_region(s->iodmaa, SV_EXTENT_DMA);
2715 release_region(s->ioenh, SV_EXTENT_ENH);
2721 static void __devexit sv_remove(struct pci_dev *dev)
2723 struct sv_state *s = pci_get_drvdata(dev);
2728 outb(~0, s->ioenh + SV_CODEC_INTMASK); /* disable ints */
2729 synchronize_irq(s->irq);
2730 inb(s->ioenh + SV_CODEC_STATUS); /* ack interrupts */
2731 wrindir(s, SV_CIENABLE, 0); /* disable DMAA and DMAC */
2732 /*outb(0, s->iodmaa + SV_DMA_RESET);*/
2733 /*outb(0, s->iodmac + SV_DMA_RESET);*/
2734 free_irq(s->irq, s);
2735 sv_unregister_gameport(s);
2736 release_region(s->iodmac, SV_EXTENT_DMA);
2737 release_region(s->iodmaa, SV_EXTENT_DMA);
2738 release_region(s->ioenh, SV_EXTENT_ENH);
2739 release_region(s->iomidi, SV_EXTENT_MIDI);
2740 release_region(s->iosynth, SV_EXTENT_SYNTH);
2741 unregister_sound_dsp(s->dev_audio);
2742 unregister_sound_mixer(s->dev_mixer);
2743 unregister_sound_midi(s->dev_midi);
2744 unregister_sound_special(s->dev_dmfm);
2746 pci_set_drvdata(dev, NULL);
2749 static struct pci_device_id id_table[] = {
2750 { PCI_VENDOR_ID_S3, PCI_DEVICE_ID_S3_SONICVIBES, PCI_ANY_ID, PCI_ANY_ID, 0, 0 },
2754 MODULE_DEVICE_TABLE(pci, id_table);
2756 static struct pci_driver sv_driver = {
2757 .name = "sonicvibes",
2758 .id_table = id_table,
2760 .remove = __devexit_p(sv_remove),
2763 static int __init init_sonicvibes(void)
2765 printk(KERN_INFO "sv: version v0.31 time " __TIME__ " " __DATE__ "\n");
2767 if (!(wavetable_mem = __get_free_pages(GFP_KERNEL, 20-PAGE_SHIFT)))
2768 printk(KERN_INFO "sv: cannot allocate 1MB of contiguous nonpageable memory for wavetable data\n");
2770 return pci_register_driver(&sv_driver);
2773 static void __exit cleanup_sonicvibes(void)
2775 printk(KERN_INFO "sv: unloading\n");
2776 pci_unregister_driver(&sv_driver);
2778 free_pages(wavetable_mem, 20-PAGE_SHIFT);
2781 module_init(init_sonicvibes);
2782 module_exit(cleanup_sonicvibes);
2784 /* --------------------------------------------------------------------- */
2788 /* format is: sonicvibes=[reverb] sonicvibesdmaio=dmaioaddr */
2790 static int __init sonicvibes_setup(char *str)
2792 static unsigned __initdata nr_dev = 0;
2794 if (nr_dev >= NR_DEVICE)
2797 if (get_option(&str, &reverb[nr_dev]) == 2)
2798 (void)get_option(&str, &wavetable[nr_dev]);
2800 (void)get_option(&str, &reverb[nr_dev]);
2807 __setup("sonicvibes=", sonicvibes_setup);