- pre4:
[davej-history.git] / drivers / sound / nm256_audio.c
blobc41c858d085db9f9ef3c68654c6302bbd9374e5a
1 /*
2 * Audio driver for the NeoMagic 256AV and 256ZX chipsets in native
3 * mode, with AC97 mixer support.
5 * Overall design and parts of this code stolen from vidc_*.c and
6 * skeleton.c.
8 * Yeah, there are a lot of magic constants in here. You tell ME what
9 * they are. I just get this stuff psychically, remember?
11 * This driver was written by someone who wishes to remain anonymous.
12 * It is in the public domain, so share and enjoy. Try to make a profit
13 * off of it; go on, I dare you.
16 #define __NO_VERSION__
17 #include <linux/pci.h>
18 #include <linux/init.h>
19 #include <linux/module.h>
20 #include <linux/pm.h>
21 #include <linux/delay.h>
22 #include "sound_config.h"
23 #include "nm256.h"
24 #include "nm256_coeff.h"
26 int nm256_debug = 0;
27 static int force_load = 0;
29 /*
30 * The size of the playback reserve. When the playback buffer has less
31 * than NM256_PLAY_WMARK_SIZE bytes to output, we request a new
32 * buffer.
34 #define NM256_PLAY_WMARK_SIZE 512
36 static struct audio_driver nm256_audio_driver;
38 static int nm256_grabInterrupt (struct nm256_info *card);
39 static int nm256_releaseInterrupt (struct nm256_info *card);
40 static void nm256_interrupt (int irq, void *dev_id, struct pt_regs *dummy);
41 static void nm256_interrupt_zx (int irq, void *dev_id, struct pt_regs *dummy);
42 static int handle_pm_event (struct pm_dev *dev, pm_request_t rqst, void *data);
44 /* These belong in linux/pci.h. */
45 #define PCI_DEVICE_ID_NEOMAGIC_NM256AV_AUDIO 0x8005
46 #define PCI_DEVICE_ID_NEOMAGIC_NM256ZX_AUDIO 0x8006
48 #define RSRCADDRESS(dev,num) ((dev)->resource[(num)].start)
50 /* List of cards. */
51 static struct nm256_info *nmcard_list;
53 /* Release the mapped-in memory for CARD. */
54 static void
55 nm256_release_ports (struct nm256_info *card)
57 int x;
59 for (x = 0; x < 2; x++) {
60 if (card->port[x].ptr != NULL) {
61 u32 size =
62 card->port[x].end_offset - card->port[x].start_offset;
63 release_region ((unsigned long) card->port[x].ptr, size);
64 card->port[x].ptr = NULL;
69 /*
70 * Map in the memory ports for CARD, if they aren't already mapped in
71 * and have been configured. If successful, a zero value is returned;
72 * otherwise any previously mapped-in areas are released and a non-zero
73 * value is returned.
75 * This is invoked twice, once for each port. Ideally it would only be
76 * called once, but we now need to map in the second port in order to
77 * check how much memory the card has on the 256ZX.
79 static int
80 nm256_remap_ports (struct nm256_info *card)
82 int x;
84 for (x = 0; x < 2; x++) {
85 if (card->port[x].ptr == NULL && card->port[x].end_offset > 0) {
86 u32 physaddr
87 = card->port[x].physaddr + card->port[x].start_offset;
88 u32 size
89 = card->port[x].end_offset - card->port[x].start_offset;
91 card->port[x].ptr = ioremap_nocache (physaddr, size);
93 if (card->port[x].ptr == NULL) {
94 printk (KERN_ERR "NM256: Unable to remap port %d\n", x + 1);
95 nm256_release_ports (card);
96 return -1;
100 return 0;
103 /* Locate the card in our list. */
104 static struct nm256_info *
105 nm256_find_card (int dev)
107 struct nm256_info *card;
109 for (card = nmcard_list; card != NULL; card = card->next_card)
110 if (card->dev[0] == dev || card->dev[1] == dev)
111 return card;
113 return NULL;
117 * Ditto, but find the card struct corresponding to the mixer device DEV
118 * instead.
120 static struct nm256_info *
121 nm256_find_card_for_mixer (int dev)
123 struct nm256_info *card;
125 for (card = nmcard_list; card != NULL; card = card->next_card)
126 if (card->mixer_oss_dev == dev)
127 return card;
129 return NULL;
132 static int usecache = 0;
133 static int buffertop = 0;
135 /* Check to see if we're using the bank of cached coefficients. */
137 nm256_cachedCoefficients (struct nm256_info *card)
139 return usecache;
142 /* The actual rates supported by the card. */
143 static int samplerates[9] = {
144 8000, 11025, 16000, 22050, 24000, 32000, 44100, 48000, 99999999
148 * Set the card samplerate, word size and stereo mode to correspond to
149 * the settings in the CARD struct for the specified device in DEV.
150 * We keep two separate sets of information, one for each device; the
151 * hardware is not actually configured until a read or write is
152 * attempted.
156 nm256_setInfo (int dev, struct nm256_info *card)
158 int x;
159 int w;
160 int targetrate;
162 if (card->dev[0] == dev)
163 w = 0;
164 else if (card->dev[1] == dev)
165 w = 1;
166 else
167 return -ENODEV;
169 targetrate = card->sinfo[w].samplerate;
171 if ((card->sinfo[w].bits != 8 && card->sinfo[w].bits != 16)
172 || targetrate < samplerates[0]
173 || targetrate > samplerates[7])
174 return -EINVAL;
176 for (x = 0; x < 8; x++)
177 if (targetrate < ((samplerates[x] + samplerates[x + 1]) / 2))
178 break;
180 if (x < 8) {
181 u8 ratebits = ((x << 4) & NM_RATE_MASK);
182 if (card->sinfo[w].bits == 16)
183 ratebits |= NM_RATE_BITS_16;
184 if (card->sinfo[w].stereo)
185 ratebits |= NM_RATE_STEREO;
187 card->sinfo[w].samplerate = samplerates[x];
190 if (card->dev_for_play == dev && card->playing) {
191 if (nm256_debug)
192 printk (KERN_DEBUG "Setting play ratebits to 0x%x\n",
193 ratebits);
194 nm256_loadCoefficient (card, 0, x);
195 nm256_writePort8 (card, 2,
196 NM_PLAYBACK_REG_OFFSET + NM_RATE_REG_OFFSET,
197 ratebits);
200 if (card->dev_for_record == dev && card->recording) {
201 if (nm256_debug)
202 printk (KERN_DEBUG "Setting record ratebits to 0x%x\n",
203 ratebits);
204 nm256_loadCoefficient (card, 1, x);
205 nm256_writePort8 (card, 2,
206 NM_RECORD_REG_OFFSET + NM_RATE_REG_OFFSET,
207 ratebits);
209 return 0;
211 else
212 return -EINVAL;
215 /* Start the play process going. */
216 static void
217 startPlay (struct nm256_info *card)
219 if (! card->playing) {
220 card->playing = 1;
221 if (nm256_grabInterrupt (card) == 0) {
222 nm256_setInfo (card->dev_for_play, card);
224 /* Enable playback engine and interrupts. */
225 nm256_writePort8 (card, 2, NM_PLAYBACK_ENABLE_REG,
226 NM_PLAYBACK_ENABLE_FLAG | NM_PLAYBACK_FREERUN);
228 /* Enable both channels. */
229 nm256_writePort16 (card, 2, NM_AUDIO_MUTE_REG, 0x0);
235 * Request one chunk of AMT bytes from the recording device. When the
236 * operation is complete, the data will be copied into BUFFER and the
237 * function DMAbuf_inputintr will be invoked.
240 static void
241 nm256_startRecording (struct nm256_info *card, char *buffer, u32 amt)
243 u32 endpos;
244 int enableEngine = 0;
245 u32 ringsize = card->recordBufferSize;
246 unsigned long flags;
248 if (amt > (ringsize / 2)) {
250 * Of course this won't actually work right, because the
251 * caller is going to assume we will give what we got asked
252 * for.
254 printk (KERN_ERR "NM256: Read request too large: %d\n", amt);
255 amt = ringsize / 2;
258 if (amt < 8) {
259 printk (KERN_ERR "NM256: Read request too small; %d\n", amt);
260 return;
263 save_flags (flags);
264 cli ();
266 * If we're not currently recording, set up the start and end registers
267 * for the recording engine.
269 if (! card->recording) {
270 card->recording = 1;
271 if (nm256_grabInterrupt (card) == 0) {
272 card->curRecPos = 0;
273 nm256_setInfo (card->dev_for_record, card);
274 nm256_writePort32 (card, 2, NM_RBUFFER_START, card->abuf2);
275 nm256_writePort32 (card, 2, NM_RBUFFER_END,
276 card->abuf2 + ringsize);
278 nm256_writePort32 (card, 2, NM_RBUFFER_CURRP,
279 card->abuf2 + card->curRecPos);
280 enableEngine = 1;
282 else {
283 /* Not sure what else to do here. */
284 restore_flags (flags);
285 return;
290 * If we happen to go past the end of the buffer a bit (due to a
291 * delayed interrupt) it's OK. So might as well set the watermark
292 * right at the end of the data we want.
294 endpos = card->abuf2 + ((card->curRecPos + amt) % ringsize);
296 card->recBuf = buffer;
297 card->requestedRecAmt = amt;
298 nm256_writePort32 (card, 2, NM_RBUFFER_WMARK, endpos);
299 /* Enable recording engine and interrupts. */
300 if (enableEngine)
301 nm256_writePort8 (card, 2, NM_RECORD_ENABLE_REG,
302 NM_RECORD_ENABLE_FLAG | NM_RECORD_FREERUN);
304 restore_flags (flags);
307 /* Stop the play engine. */
308 static void
309 stopPlay (struct nm256_info *card)
311 /* Shut off sound from both channels. */
312 nm256_writePort16 (card, 2, NM_AUDIO_MUTE_REG,
313 NM_AUDIO_MUTE_LEFT | NM_AUDIO_MUTE_RIGHT);
314 /* Disable play engine. */
315 nm256_writePort8 (card, 2, NM_PLAYBACK_ENABLE_REG, 0);
316 if (card->playing) {
317 nm256_releaseInterrupt (card);
319 /* Reset the relevant state bits. */
320 card->playing = 0;
321 card->curPlayPos = 0;
325 /* Stop recording. */
326 static void
327 stopRecord (struct nm256_info *card)
329 /* Disable recording engine. */
330 nm256_writePort8 (card, 2, NM_RECORD_ENABLE_REG, 0);
332 if (card->recording) {
333 nm256_releaseInterrupt (card);
335 card->recording = 0;
336 card->curRecPos = 0;
341 * Ring buffers, man. That's where the hip-hop, wild-n-wooly action's at.
342 * 1972? (Well, I suppose it was cheep-n-easy to implement.)
344 * Write AMT bytes of BUFFER to the playback ring buffer, and start the
345 * playback engine running. It will only accept up to 1/2 of the total
346 * size of the ring buffer. No check is made that we're about to overwrite
347 * the currently-playing sample.
350 static void
351 nm256_write_block (struct nm256_info *card, char *buffer, u32 amt)
353 u32 ringsize = card->playbackBufferSize;
354 u32 endstop;
355 unsigned long flags;
357 if (amt > (ringsize / 2)) {
358 printk (KERN_ERR "NM256: Write request too large: %d\n", amt);
359 amt = (ringsize / 2);
362 if (amt < NM256_PLAY_WMARK_SIZE) {
363 printk (KERN_ERR "NM256: Write request too small: %d\n", amt);
364 return;
367 card->curPlayPos %= ringsize;
369 card->requested_amt = amt;
371 save_flags (flags);
372 cli ();
374 if ((card->curPlayPos + amt) >= ringsize) {
375 u32 rem = ringsize - card->curPlayPos;
377 nm256_writeBuffer8 (card, buffer, 1,
378 card->abuf1 + card->curPlayPos,
379 rem);
380 if (amt > rem)
381 nm256_writeBuffer8 (card, buffer + rem, 1, card->abuf1,
382 amt - rem);
384 else
385 nm256_writeBuffer8 (card, buffer, 1,
386 card->abuf1 + card->curPlayPos,
387 amt);
390 * Setup the start-n-stop-n-limit registers, and start that engine
391 * goin'.
393 * Normally we just let it wrap around to avoid the click-click
394 * action scene.
396 if (! card->playing) {
397 /* The PBUFFER_END register in this case points to one sample
398 before the end of the buffer. */
399 int w = (card->dev_for_play == card->dev[0] ? 0 : 1);
400 int sampsize = (card->sinfo[w].bits == 16 ? 2 : 1);
402 if (card->sinfo[w].stereo)
403 sampsize *= 2;
405 /* Need to set the not-normally-changing-registers up. */
406 nm256_writePort32 (card, 2, NM_PBUFFER_START,
407 card->abuf1 + card->curPlayPos);
408 nm256_writePort32 (card, 2, NM_PBUFFER_END,
409 card->abuf1 + ringsize - sampsize);
410 nm256_writePort32 (card, 2, NM_PBUFFER_CURRP,
411 card->abuf1 + card->curPlayPos);
413 endstop = (card->curPlayPos + amt - NM256_PLAY_WMARK_SIZE) % ringsize;
414 nm256_writePort32 (card, 2, NM_PBUFFER_WMARK, card->abuf1 + endstop);
416 if (! card->playing)
417 startPlay (card);
419 restore_flags (flags);
422 /* We just got a card playback interrupt; process it. */
423 static void
424 nm256_get_new_block (struct nm256_info *card)
426 /* Check to see how much got played so far. */
427 u32 amt = nm256_readPort32 (card, 2, NM_PBUFFER_CURRP) - card->abuf1;
429 if (amt >= card->playbackBufferSize) {
430 printk (KERN_ERR "NM256: Sound playback pointer invalid!\n");
431 amt = 0;
434 if (amt < card->curPlayPos)
435 amt = (card->playbackBufferSize - card->curPlayPos) + amt;
436 else
437 amt -= card->curPlayPos;
439 if (card->requested_amt > (amt + NM256_PLAY_WMARK_SIZE)) {
440 u32 endstop =
441 card->curPlayPos + card->requested_amt - NM256_PLAY_WMARK_SIZE;
442 nm256_writePort32 (card, 2, NM_PBUFFER_WMARK, card->abuf1 + endstop);
444 else {
445 card->curPlayPos += card->requested_amt;
446 /* Get a new block to write. This will eventually invoke
447 nm256_write_block () or stopPlay (). */
448 DMAbuf_outputintr (card->dev_for_play, 1);
452 /* Ultra cheez-whiz. But I'm too lazy to grep headers. */
453 #define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
456 * Read the last-recorded block from the ring buffer, copy it into the
457 * saved buffer pointer, and invoke DMAuf_inputintr() with the recording
458 * device.
461 static void
462 nm256_read_block (struct nm256_info *card)
464 /* Grab the current position of the recording pointer. */
465 u32 currptr = nm256_readPort32 (card, 2, NM_RBUFFER_CURRP) - card->abuf2;
466 u32 amtToRead = card->requestedRecAmt;
467 u32 ringsize = card->recordBufferSize;
469 if (currptr >= card->recordBufferSize) {
470 printk (KERN_ERR "NM256: Sound buffer record pointer invalid!\n");
471 currptr = 0;
475 * This test is probably redundant; we shouldn't be here unless
476 * it's true.
478 if (card->recording) {
479 /* If we wrapped around, copy everything from the start of our
480 recording buffer to the end of the buffer. */
481 if (currptr < card->curRecPos) {
482 u32 amt = MIN (ringsize - card->curRecPos, amtToRead);
484 nm256_readBuffer8 (card, card->recBuf, 1,
485 card->abuf2 + card->curRecPos,
486 amt);
487 amtToRead -= amt;
488 card->curRecPos += amt;
489 card->recBuf += amt;
490 if (card->curRecPos == ringsize)
491 card->curRecPos = 0;
494 if ((card->curRecPos < currptr) && (amtToRead > 0)) {
495 u32 amt = MIN (currptr - card->curRecPos, amtToRead);
496 nm256_readBuffer8 (card, card->recBuf, 1,
497 card->abuf2 + card->curRecPos, amt);
498 card->curRecPos = ((card->curRecPos + amt) % ringsize);
500 card->recBuf = NULL;
501 card->requestedRecAmt = 0;
502 DMAbuf_inputintr (card->dev_for_record);
505 #undef MIN
508 * Initialize the hardware.
510 static void
511 nm256_initHw (struct nm256_info *card)
513 /* Reset everything. */
514 nm256_writePort8 (card, 2, 0x0, 0x11);
515 nm256_writePort16 (card, 2, 0x214, 0);
517 stopRecord (card);
518 stopPlay (card);
522 * Handle a potential interrupt for the device referred to by DEV_ID.
524 * I don't like the cut-n-paste job here either between the two routines,
525 * but there are sufficient differences between the two interrupt handlers
526 * that parameterizing it isn't all that great either. (Could use a macro,
527 * I suppose...yucky bleah.)
530 static void
531 nm256_interrupt (int irq, void *dev_id, struct pt_regs *dummy)
533 struct nm256_info *card = (struct nm256_info *)dev_id;
534 u16 status;
535 static int badintrcount = 0;
537 if ((card == NULL) || (card->magsig != NM_MAGIC_SIG)) {
538 printk (KERN_ERR "NM256: Bad card pointer\n");
539 return;
542 status = nm256_readPort16 (card, 2, NM_INT_REG);
544 /* Not ours. */
545 if (status == 0) {
546 if (badintrcount++ > 1000) {
548 * I'm not sure if the best thing is to stop the card from
549 * playing or just release the interrupt (after all, we're in
550 * a bad situation, so doing fancy stuff may not be such a good
551 * idea).
553 * I worry about the card engine continuing to play noise
554 * over and over, however--that could become a very
555 * obnoxious problem. And we know that when this usually
556 * happens things are fairly safe, it just means the user's
557 * inserted a PCMCIA card and someone's spamming us with IRQ 9s.
560 if (card->playing)
561 stopPlay (card);
562 if (card->recording)
563 stopRecord (card);
564 badintrcount = 0;
566 return;
569 badintrcount = 0;
571 /* Rather boring; check for individual interrupts and process them. */
573 if (status & NM_PLAYBACK_INT) {
574 status &= ~NM_PLAYBACK_INT;
575 NM_ACK_INT (card, NM_PLAYBACK_INT);
577 if (card->playing)
578 nm256_get_new_block (card);
581 if (status & NM_RECORD_INT) {
582 status &= ~NM_RECORD_INT;
583 NM_ACK_INT (card, NM_RECORD_INT);
585 if (card->recording)
586 nm256_read_block (card);
589 if (status & NM_MISC_INT_1) {
590 u8 cbyte;
592 status &= ~NM_MISC_INT_1;
593 printk (KERN_ERR "NM256: Got misc interrupt #1\n");
594 NM_ACK_INT (card, NM_MISC_INT_1);
595 nm256_writePort16 (card, 2, NM_INT_REG, 0x8000);
596 cbyte = nm256_readPort8 (card, 2, 0x400);
597 nm256_writePort8 (card, 2, 0x400, cbyte | 2);
600 if (status & NM_MISC_INT_2) {
601 u8 cbyte;
603 status &= ~NM_MISC_INT_2;
604 printk (KERN_ERR "NM256: Got misc interrupt #2\n");
605 NM_ACK_INT (card, NM_MISC_INT_2);
606 cbyte = nm256_readPort8 (card, 2, 0x400);
607 nm256_writePort8 (card, 2, 0x400, cbyte & ~2);
610 /* Unknown interrupt. */
611 if (status) {
612 printk (KERN_ERR "NM256: Fire in the hole! Unknown status 0x%x\n",
613 status);
614 /* Pray. */
615 NM_ACK_INT (card, status);
620 * Handle a potential interrupt for the device referred to by DEV_ID.
621 * This handler is for the 256ZX, and is very similar to the non-ZX
622 * routine.
625 static void
626 nm256_interrupt_zx (int irq, void *dev_id, struct pt_regs *dummy)
628 struct nm256_info *card = (struct nm256_info *)dev_id;
629 u32 status;
630 static int badintrcount = 0;
632 if ((card == NULL) || (card->magsig != NM_MAGIC_SIG)) {
633 printk (KERN_ERR "NM256: Bad card pointer\n");
634 return;
637 status = nm256_readPort32 (card, 2, NM_INT_REG);
639 /* Not ours. */
640 if (status == 0) {
641 if (badintrcount++ > 1000) {
642 printk (KERN_ERR "NM256: Releasing interrupt, over 1000 invalid interrupts\n");
644 * I'm not sure if the best thing is to stop the card from
645 * playing or just release the interrupt (after all, we're in
646 * a bad situation, so doing fancy stuff may not be such a good
647 * idea).
649 * I worry about the card engine continuing to play noise
650 * over and over, however--that could become a very
651 * obnoxious problem. And we know that when this usually
652 * happens things are fairly safe, it just means the user's
653 * inserted a PCMCIA card and someone's spamming us with
654 * IRQ 9s.
657 if (card->playing)
658 stopPlay (card);
659 if (card->recording)
660 stopRecord (card);
661 badintrcount = 0;
663 return;
666 badintrcount = 0;
668 /* Rather boring; check for individual interrupts and process them. */
670 if (status & NM2_PLAYBACK_INT) {
671 status &= ~NM2_PLAYBACK_INT;
672 NM2_ACK_INT (card, NM2_PLAYBACK_INT);
674 if (card->playing)
675 nm256_get_new_block (card);
678 if (status & NM2_RECORD_INT) {
679 status &= ~NM2_RECORD_INT;
680 NM2_ACK_INT (card, NM2_RECORD_INT);
682 if (card->recording)
683 nm256_read_block (card);
686 if (status & NM2_MISC_INT_1) {
687 u8 cbyte;
689 status &= ~NM2_MISC_INT_1;
690 printk (KERN_ERR "NM256: Got misc interrupt #1\n");
691 NM2_ACK_INT (card, NM2_MISC_INT_1);
692 cbyte = nm256_readPort8 (card, 2, 0x400);
693 nm256_writePort8 (card, 2, 0x400, cbyte | 2);
696 if (status & NM2_MISC_INT_2) {
697 u8 cbyte;
699 status &= ~NM2_MISC_INT_2;
700 printk (KERN_ERR "NM256: Got misc interrupt #2\n");
701 NM2_ACK_INT (card, NM2_MISC_INT_2);
702 cbyte = nm256_readPort8 (card, 2, 0x400);
703 nm256_writePort8 (card, 2, 0x400, cbyte & ~2);
706 /* Unknown interrupt. */
707 if (status) {
708 printk (KERN_ERR "NM256: Fire in the hole! Unknown status 0x%x\n",
709 status);
710 /* Pray. */
711 NM2_ACK_INT (card, status);
716 * Request our interrupt.
718 static int
719 nm256_grabInterrupt (struct nm256_info *card)
721 if (card->has_irq++ == 0) {
722 if (request_irq (card->irq, card->introutine, SA_SHIRQ,
723 "NM256_audio", card) < 0) {
724 printk (KERN_ERR "NM256: can't obtain IRQ %d\n", card->irq);
725 return -1;
728 return 0;
732 * Release our interrupt.
734 static int
735 nm256_releaseInterrupt (struct nm256_info *card)
737 if (card->has_irq <= 0) {
738 printk (KERN_ERR "nm256: too many calls to releaseInterrupt\n");
739 return -1;
741 card->has_irq--;
742 if (card->has_irq == 0) {
743 free_irq (card->irq, card);
745 return 0;
749 * Waits for the mixer to become ready to be written; returns a zero value
750 * if it timed out.
753 static int
754 nm256_isReady (struct ac97_hwint *dev)
756 struct nm256_info *card = (struct nm256_info *)dev->driver_private;
757 int t2 = 10;
758 u32 testaddr;
759 u16 testb;
760 int done = 0;
762 if (card->magsig != NM_MAGIC_SIG) {
763 printk (KERN_ERR "NM256: Bad magic signature in isReady!\n");
764 return 0;
767 testaddr = card->mixer_status_offset;
768 testb = card->mixer_status_mask;
771 * Loop around waiting for the mixer to become ready.
773 while (! done && t2-- > 0) {
774 if ((nm256_readPort16 (card, 2, testaddr) & testb) == 0)
775 done = 1;
776 else
777 udelay (100);
779 return done;
783 * Return the contents of the AC97 mixer register REG. Returns a positive
784 * value if successful, or a negative error code.
786 static int
787 nm256_readAC97Reg (struct ac97_hwint *dev, u8 reg)
789 struct nm256_info *card = (struct nm256_info *)dev->driver_private;
791 if (card->magsig != NM_MAGIC_SIG) {
792 printk (KERN_ERR "NM256: Bad magic signature in readAC97Reg!\n");
793 return -EINVAL;
796 if (reg < 128) {
797 int res;
799 nm256_isReady (dev);
800 res = nm256_readPort16 (card, 2, card->mixer + reg);
801 /* Magic delay. Bleah yucky. */
802 udelay (1000);
803 return res;
805 else
806 return -EINVAL;
810 * Writes VALUE to AC97 mixer register REG. Returns 0 if successful, or
811 * a negative error code.
813 static int
814 nm256_writeAC97Reg (struct ac97_hwint *dev, u8 reg, u16 value)
816 unsigned long flags;
817 int tries = 2;
818 int done = 0;
819 u32 base;
821 struct nm256_info *card = (struct nm256_info *)dev->driver_private;
823 if (card->magsig != NM_MAGIC_SIG) {
824 printk (KERN_ERR "NM256: Bad magic signature in writeAC97Reg!\n");
825 return -EINVAL;
828 base = card->mixer;
830 save_flags (flags);
831 cli ();
833 nm256_isReady (dev);
835 /* Wait for the write to take, too. */
836 while ((tries-- > 0) && !done) {
837 nm256_writePort16 (card, 2, base + reg, value);
838 if (nm256_isReady (dev)) {
839 done = 1;
840 break;
845 restore_flags (flags);
846 udelay (1000);
848 return ! done;
852 * Initial register values to be written to the AC97 mixer.
853 * While most of these are identical to the reset values, we do this
854 * so that we have most of the register contents cached--this avoids
855 * reading from the mixer directly (which seems to be problematic,
856 * probably due to ignorance).
858 struct initialValues
860 unsigned short port;
861 unsigned short value;
864 static struct initialValues nm256_ac97_initial_values[] =
866 { AC97_MASTER_VOL_STEREO, 0x8000 },
867 { AC97_HEADPHONE_VOL, 0x8000 },
868 { AC97_MASTER_VOL_MONO, 0x0000 },
869 { AC97_PCBEEP_VOL, 0x0000 },
870 { AC97_PHONE_VOL, 0x0008 },
871 { AC97_MIC_VOL, 0x8000 },
872 { AC97_LINEIN_VOL, 0x8808 },
873 { AC97_CD_VOL, 0x8808 },
874 { AC97_VIDEO_VOL, 0x8808 },
875 { AC97_AUX_VOL, 0x8808 },
876 { AC97_PCMOUT_VOL, 0x0808 },
877 { AC97_RECORD_SELECT, 0x0000 },
878 { AC97_RECORD_GAIN, 0x0B0B },
879 { AC97_GENERAL_PURPOSE, 0x0000 },
880 { 0xffff, 0xffff }
883 /* Initialize the AC97 into a known state. */
884 static int
885 nm256_resetAC97 (struct ac97_hwint *dev)
887 struct nm256_info *card = (struct nm256_info *)dev->driver_private;
888 int x;
890 if (card->magsig != NM_MAGIC_SIG) {
891 printk (KERN_ERR "NM256: Bad magic signature in resetAC97!\n");
892 return -EINVAL;
895 /* Reset the mixer. 'Tis magic! */
896 nm256_writePort8 (card, 2, 0x6c0, 1);
897 nm256_writePort8 (card, 2, 0x6cc, 0x87);
898 nm256_writePort8 (card, 2, 0x6cc, 0x80);
899 nm256_writePort8 (card, 2, 0x6cc, 0x0);
901 if (! card->mixer_values_init) {
902 for (x = 0; nm256_ac97_initial_values[x].port != 0xffff; x++) {
903 ac97_put_register (dev,
904 nm256_ac97_initial_values[x].port,
905 nm256_ac97_initial_values[x].value);
906 card->mixer_values_init = 1;
910 return 0;
914 * We don't do anything particularly special here; it just passes the
915 * mixer ioctl to the AC97 driver.
917 static int
918 nm256_default_mixer_ioctl (int dev, unsigned int cmd, caddr_t arg)
920 struct nm256_info *card = nm256_find_card_for_mixer (dev);
921 if (card != NULL)
922 return ac97_mixer_ioctl (&(card->mdev), cmd, arg);
923 else
924 return -ENODEV;
927 static struct mixer_operations nm256_mixer_operations = {
928 owner: THIS_MODULE,
929 id: "NeoMagic",
930 name: "NM256AC97Mixer",
931 ioctl: nm256_default_mixer_ioctl
935 * Default settings for the OSS mixer. These are set last, after the
936 * mixer is initialized.
938 * I "love" C sometimes. Got braces?
940 static struct ac97_mixer_value_list mixer_defaults[] = {
941 { SOUND_MIXER_VOLUME, { { 85, 85 } } },
942 { SOUND_MIXER_SPEAKER, { { 100 } } },
943 { SOUND_MIXER_PCM, { { 65, 65 } } },
944 { SOUND_MIXER_CD, { { 65, 65 } } },
945 { -1, { { 0, 0 } } }
949 /* Installs the AC97 mixer into CARD. */
950 static int
951 nm256_install_mixer (struct nm256_info *card)
953 int mixer;
955 card->mdev.reset_device = nm256_resetAC97;
956 card->mdev.read_reg = nm256_readAC97Reg;
957 card->mdev.write_reg = nm256_writeAC97Reg;
958 card->mdev.driver_private = (void *)card;
960 if (ac97_init (&(card->mdev)))
961 return -1;
963 mixer = sound_alloc_mixerdev();
964 if (num_mixers >= MAX_MIXER_DEV) {
965 printk ("NM256 mixer: Unable to alloc mixerdev\n");
966 return -1;
969 mixer_devs[mixer] = &nm256_mixer_operations;
970 card->mixer_oss_dev = mixer;
972 /* Some reasonable default values. */
973 ac97_set_values (&(card->mdev), mixer_defaults);
975 printk(KERN_INFO "Initialized AC97 mixer\n");
976 return 0;
979 /* Perform a full reset on the hardware; this is invoked when an APM
980 resume event occurs. */
981 static void
982 nm256_full_reset (struct nm256_info *card)
984 nm256_initHw (card);
985 ac97_reset (&(card->mdev));
989 * See if the signature left by the NM256 BIOS is intact; if so, we use
990 * the associated address as the end of our audio buffer in the video
991 * RAM.
994 static void
995 nm256_peek_for_sig (struct nm256_info *card)
997 u32 port1offset
998 = card->port[0].physaddr + card->port[0].end_offset - 0x0400;
999 /* The signature is located 1K below the end of video RAM. */
1000 char *temp = ioremap_nocache (port1offset, 16);
1001 /* Default buffer end is 5120 bytes below the top of RAM. */
1002 u32 default_value = card->port[0].end_offset - 0x1400;
1003 u32 sig;
1005 /* Install the default value first, so we don't have to repeatedly
1006 do it if there is a problem. */
1007 card->port[0].end_offset = default_value;
1009 if (temp == NULL) {
1010 printk (KERN_ERR "NM256: Unable to scan for card signature in video RAM\n");
1011 return;
1013 sig = readl (temp);
1014 if ((sig & NM_SIG_MASK) == NM_SIGNATURE) {
1015 u32 pointer = readl (temp + 4);
1018 * If it's obviously invalid, don't use it (the port already has a
1019 * suitable default value set).
1021 if (pointer != 0xffffffff)
1022 card->port[0].end_offset = pointer;
1024 printk (KERN_INFO "NM256: Found card signature in video RAM: 0x%x\n",
1025 pointer);
1028 release_region ((unsigned long) temp, 16);
1032 * Install a driver for the PCI device referenced by PCIDEV.
1033 * VERSTR is a human-readable version string.
1036 static int
1037 nm256_install(struct pci_dev *pcidev, enum nm256rev rev, char *verstr)
1039 struct nm256_info *card;
1040 struct pm_dev *pmdev;
1041 int x;
1043 card = kmalloc (sizeof (struct nm256_info), GFP_KERNEL);
1044 if (card == NULL) {
1045 printk (KERN_ERR "NM256: out of memory!\n");
1046 return 0;
1049 card->magsig = NM_MAGIC_SIG;
1050 card->playing = 0;
1051 card->recording = 0;
1052 card->rev = rev;
1054 /* Init the memory port info. */
1055 for (x = 0; x < 2; x++) {
1056 card->port[x].physaddr = RSRCADDRESS (pcidev, x);
1057 card->port[x].ptr = NULL;
1058 card->port[x].start_offset = 0;
1059 card->port[x].end_offset = 0;
1062 /* Port 2 is easy. */
1063 card->port[1].start_offset = 0;
1064 card->port[1].end_offset = NM_PORT2_SIZE;
1066 /* Yuck. But we have to map in port 2 so we can check how much RAM the
1067 card has. */
1068 if (nm256_remap_ports (card)) {
1069 kfree (card);
1070 return 0;
1074 * The NM256 has two memory ports. The first port is nothing
1075 * more than a chunk of video RAM, which is used as the I/O ring
1076 * buffer. The second port has the actual juicy stuff (like the
1077 * mixer and the playback engine control registers).
1080 if (card->rev == REV_NM256AV) {
1081 /* Ok, try to see if this is a non-AC97 version of the hardware. */
1082 int pval = nm256_readPort16 (card, 2, NM_MIXER_PRESENCE);
1083 if ((pval & NM_PRESENCE_MASK) != NM_PRESENCE_VALUE) {
1084 if (! force_load) {
1085 printk (KERN_ERR "NM256: This doesn't look to me like the AC97-compatible version.\n");
1086 printk (KERN_ERR " You can force the driver to load by passing in the module\n");
1087 printk (KERN_ERR " parameter:\n");
1088 printk (KERN_ERR " force_ac97 = 1\n");
1089 printk (KERN_ERR "\n");
1090 printk (KERN_ERR " More likely, you should be using the appropriate SB-16 or\n");
1091 printk (KERN_ERR " CS4232 driver instead. (If your BIOS has settings for\n");
1092 printk (KERN_ERR " IRQ and/or DMA for the sound card, this is *not* the correct\n");
1093 printk (KERN_ERR " driver to use.)\n");
1094 nm256_release_ports (card);
1095 kfree (card);
1096 return 0;
1098 else {
1099 printk (KERN_INFO "NM256: Forcing driver load as per user request.\n");
1102 else {
1103 /* printk (KERN_INFO "NM256: Congratulations. You're not running Eunice.\n")*/;
1105 card->port[0].end_offset = 2560 * 1024;
1106 card->introutine = nm256_interrupt;
1107 card->mixer_status_offset = NM_MIXER_STATUS_OFFSET;
1108 card->mixer_status_mask = NM_MIXER_READY_MASK;
1110 else {
1111 /* Not sure if there is any relevant detect for the ZX or not. */
1112 if (nm256_readPort8 (card, 2, 0xa0b) != 0)
1113 card->port[0].end_offset = 6144 * 1024;
1114 else
1115 card->port[0].end_offset = 4096 * 1024;
1117 card->introutine = nm256_interrupt_zx;
1118 card->mixer_status_offset = NM2_MIXER_STATUS_OFFSET;
1119 card->mixer_status_mask = NM2_MIXER_READY_MASK;
1122 if (buffertop >= 98304 && buffertop < card->port[0].end_offset)
1123 card->port[0].end_offset = buffertop;
1124 else
1125 nm256_peek_for_sig (card);
1127 card->port[0].start_offset = card->port[0].end_offset - 98304;
1129 printk (KERN_INFO "NM256: Mapping port 1 from 0x%x - 0x%x\n",
1130 card->port[0].start_offset, card->port[0].end_offset);
1132 if (nm256_remap_ports (card)) {
1133 kfree (card);
1134 return 0;
1137 /* See if we can get the interrupt. */
1139 card->irq = pcidev->irq;
1140 card->has_irq = 0;
1142 if (nm256_grabInterrupt (card) != 0) {
1143 nm256_release_ports (card);
1144 kfree (card);
1145 return 0;
1148 nm256_releaseInterrupt (card);
1151 * Init the board.
1154 card->playbackBufferSize = 16384;
1155 card->recordBufferSize = 16384;
1157 card->coeffBuf = card->port[0].end_offset - NM_MAX_COEFFICIENT;
1158 card->abuf2 = card->coeffBuf - card->recordBufferSize;
1159 card->abuf1 = card->abuf2 - card->playbackBufferSize;
1160 card->allCoeffBuf = card->abuf2 - (NM_TOTAL_COEFF_COUNT * 4);
1162 /* Fixed setting. */
1163 card->mixer = NM_MIXER_OFFSET;
1164 card->mixer_values_init = 0;
1166 card->is_open_play = 0;
1167 card->is_open_record = 0;
1169 card->coeffsCurrent = 0;
1171 card->opencnt[0] = 0; card->opencnt[1] = 0;
1173 /* Reasonable default settings, but largely unnecessary. */
1174 for (x = 0; x < 2; x++) {
1175 card->sinfo[x].bits = 8;
1176 card->sinfo[x].stereo = 0;
1177 card->sinfo[x].samplerate = 8000;
1180 nm256_initHw (card);
1182 for (x = 0; x < 2; x++) {
1183 if ((card->dev[x] =
1184 sound_install_audiodrv(AUDIO_DRIVER_VERSION,
1185 "NM256", &nm256_audio_driver,
1186 sizeof(struct audio_driver),
1187 DMA_NODMA, AFMT_U8 | AFMT_S16_LE,
1188 NULL, -1, -1)) >= 0) {
1189 /* 1K minimum buffer size. */
1190 audio_devs[card->dev[x]]->min_fragment = 10;
1191 /* Maximum of 8K buffer size. */
1192 audio_devs[card->dev[x]]->max_fragment = 13;
1194 else {
1195 printk(KERN_ERR "NM256: Too many PCM devices available\n");
1196 nm256_release_ports (card);
1197 kfree (card);
1198 return 0;
1202 /* Insert the card in the list. */
1203 card->next_card = nmcard_list;
1204 nmcard_list = card;
1206 printk(KERN_INFO "Initialized NeoMagic %s audio in PCI native mode\n",
1207 verstr);
1210 * And our mixer. (We should allow support for other mixers, maybe.)
1213 nm256_install_mixer (card);
1215 pmdev = pm_register(PM_PCI_DEV, PM_PCI_ID(pcidev), handle_pm_event);
1216 if (pmdev)
1217 pmdev->data = card;
1219 return 1;
1224 * PM event handler, so the card is properly reinitialized after a power
1225 * event.
1227 static int
1228 handle_pm_event (struct pm_dev *dev, pm_request_t rqst, void *data)
1230 struct nm256_info *crd = (struct nm256_info*) dev->data;
1231 if (crd) {
1232 switch (rqst) {
1233 case PM_SUSPEND:
1234 break;
1235 case PM_RESUME:
1237 int playing = crd->playing;
1238 nm256_full_reset (crd);
1240 * A little ugly, but that's ok; pretend the
1241 * block we were playing is done.
1243 if (playing)
1244 DMAbuf_outputintr (crd->dev_for_play, 1);
1246 break;
1249 return 0;
1253 * This loop walks the PCI configuration database and finds where
1254 * the sound cards are.
1258 init_nm256(void)
1260 struct pci_dev *pcidev = NULL;
1261 int count = 0;
1263 if(! pci_present())
1264 return -ENODEV;
1266 while((pcidev = pci_find_device(PCI_VENDOR_ID_NEOMAGIC,
1267 PCI_DEVICE_ID_NEOMAGIC_NM256AV_AUDIO,
1268 pcidev)) != NULL) {
1269 count += nm256_install(pcidev, REV_NM256AV, "256AV");
1272 while((pcidev = pci_find_device(PCI_VENDOR_ID_NEOMAGIC,
1273 PCI_DEVICE_ID_NEOMAGIC_NM256ZX_AUDIO,
1274 pcidev)) != NULL) {
1275 count += nm256_install(pcidev, REV_NM256ZX, "256ZX");
1278 if (count == 0)
1279 return -ENODEV;
1281 printk (KERN_INFO "Done installing NM256 audio driver.\n");
1282 return 0;
1286 * Open the device
1288 * DEV - device
1289 * MODE - mode to open device (logical OR of OPEN_READ and OPEN_WRITE)
1291 * Called when opening the DMAbuf (dmabuf.c:259)
1293 static int
1294 nm256_audio_open(int dev, int mode)
1296 struct nm256_info *card = nm256_find_card (dev);
1297 int w;
1299 if (card == NULL)
1300 return -ENODEV;
1302 if (card->dev[0] == dev)
1303 w = 0;
1304 else if (card->dev[1] == dev)
1305 w = 1;
1306 else
1307 return -ENODEV;
1309 if (card->opencnt[w] > 0)
1310 return -EBUSY;
1312 /* No bits set? Huh? */
1313 if (! ((mode & OPEN_READ) || (mode & OPEN_WRITE)))
1314 return -EIO;
1317 * If it's open for both read and write, and the card's currently
1318 * being read or written to, then do the opposite of what has
1319 * already been done. Otherwise, don't specify any mode until the
1320 * user actually tries to do I/O. (Some programs open the device
1321 * for both read and write, but only actually do reading or writing.)
1324 if ((mode & OPEN_WRITE) && (mode & OPEN_READ)) {
1325 if (card->is_open_play)
1326 mode = OPEN_WRITE;
1327 else if (card->is_open_record)
1328 mode = OPEN_READ;
1329 else mode = 0;
1332 if (mode & OPEN_WRITE) {
1333 if (card->is_open_play == 0) {
1334 card->dev_for_play = dev;
1335 card->is_open_play = 1;
1337 else
1338 return -EBUSY;
1341 if (mode & OPEN_READ) {
1342 if (card->is_open_record == 0) {
1343 card->dev_for_record = dev;
1344 card->is_open_record = 1;
1346 else
1347 return -EBUSY;
1350 card->opencnt[w]++;
1351 return 0;
1355 * Close the device
1357 * DEV - device
1359 * Called when closing the DMAbuf (dmabuf.c:477)
1360 * after halt_xfer
1362 static void
1363 nm256_audio_close(int dev)
1365 struct nm256_info *card = nm256_find_card (dev);
1367 if (card != NULL) {
1368 int w;
1370 if (card->dev[0] == dev)
1371 w = 0;
1372 else if (card->dev[1] == dev)
1373 w = 1;
1374 else
1375 return;
1377 card->opencnt[w]--;
1378 if (card->opencnt[w] <= 0) {
1379 card->opencnt[w] = 0;
1381 if (card->dev_for_play == dev) {
1382 stopPlay (card);
1383 card->is_open_play = 0;
1384 card->dev_for_play = -1;
1387 if (card->dev_for_record == dev) {
1388 stopRecord (card);
1389 card->is_open_record = 0;
1390 card->dev_for_record = -1;
1396 /* Standard ioctl handler. */
1397 static int
1398 nm256_audio_ioctl(int dev, unsigned int cmd, caddr_t arg)
1400 int ret;
1401 u32 oldinfo;
1402 int w;
1404 struct nm256_info *card = nm256_find_card (dev);
1406 if (card == NULL)
1407 return -ENODEV;
1409 if (dev == card->dev[0])
1410 w = 0;
1411 else
1412 w = 1;
1415 * The code here is messy. There are probably better ways to do
1416 * it. (It should be possible to handle it the same way the AC97 mixer
1417 * is done.)
1419 switch (cmd)
1421 case SOUND_PCM_WRITE_RATE:
1422 if (get_user(ret, (int *) arg))
1423 return -EFAULT;
1425 if (ret != 0) {
1426 oldinfo = card->sinfo[w].samplerate;
1427 card->sinfo[w].samplerate = ret;
1428 ret = nm256_setInfo(dev, card);
1429 if (ret != 0)
1430 card->sinfo[w].samplerate = oldinfo;
1432 if (ret == 0)
1433 ret = card->sinfo[w].samplerate;
1434 break;
1436 case SOUND_PCM_READ_RATE:
1437 ret = card->sinfo[w].samplerate;
1438 break;
1440 case SNDCTL_DSP_STEREO:
1441 if (get_user(ret, (int *) arg))
1442 return -EFAULT;
1444 card->sinfo[w].stereo = ret ? 1 : 0;
1445 ret = nm256_setInfo (dev, card);
1446 if (ret == 0)
1447 ret = card->sinfo[w].stereo;
1449 break;
1451 case SOUND_PCM_WRITE_CHANNELS:
1452 if (get_user(ret, (int *) arg))
1453 return -EFAULT;
1455 if (ret < 1 || ret > 3)
1456 ret = card->sinfo[w].stereo + 1;
1457 else {
1458 card->sinfo[w].stereo = ret - 1;
1459 ret = nm256_setInfo (dev, card);
1460 if (ret == 0)
1461 ret = card->sinfo[w].stereo + 1;
1463 break;
1465 case SOUND_PCM_READ_CHANNELS:
1466 ret = card->sinfo[w].stereo + 1;
1467 break;
1469 case SNDCTL_DSP_SETFMT:
1470 if (get_user(ret, (int *) arg))
1471 return -EFAULT;
1473 if (ret != 0) {
1474 oldinfo = card->sinfo[w].bits;
1475 card->sinfo[w].bits = ret;
1476 ret = nm256_setInfo (dev, card);
1477 if (ret != 0)
1478 card->sinfo[w].bits = oldinfo;
1480 if (ret == 0)
1481 ret = card->sinfo[w].bits;
1482 break;
1484 case SOUND_PCM_READ_BITS:
1485 ret = card->sinfo[w].bits;
1486 break;
1488 default:
1489 return -EINVAL;
1491 return put_user(ret, (int *) arg);
1495 * Given the sound device DEV and an associated physical buffer PHYSBUF,
1496 * return a pointer to the actual buffer in kernel space.
1498 * This routine should exist as part of the soundcore routines.
1501 static char *
1502 nm256_getDMAbuffer (int dev, unsigned long physbuf)
1504 struct audio_operations *adev = audio_devs[dev];
1505 struct dma_buffparms *dmap = adev->dmap_out;
1506 char *dma_start =
1507 (char *)(physbuf - (unsigned long)dmap->raw_buf_phys
1508 + (unsigned long)dmap->raw_buf);
1510 return dma_start;
1515 * Output a block to sound device
1517 * dev - device number
1518 * buf - physical address of buffer
1519 * total_count - total byte count in buffer
1520 * intrflag - set if this has been called from an interrupt
1521 * (via DMAbuf_outputintr)
1522 * restart_dma - set if engine needs to be re-initialised
1524 * Called when:
1525 * 1. Starting output (dmabuf.c:1327)
1526 * 2. (dmabuf.c:1504)
1527 * 3. A new buffer needs to be sent to the device (dmabuf.c:1579)
1529 static void
1530 nm256_audio_output_block(int dev, unsigned long physbuf,
1531 int total_count, int intrflag)
1533 struct nm256_info *card = nm256_find_card (dev);
1535 if (card != NULL) {
1536 char *dma_buf = nm256_getDMAbuffer (dev, physbuf);
1537 card->is_open_play = 1;
1538 card->dev_for_play = dev;
1539 nm256_write_block (card, dma_buf, total_count);
1543 /* Ditto, but do recording instead. */
1544 static void
1545 nm256_audio_start_input(int dev, unsigned long physbuf, int count,
1546 int intrflag)
1548 struct nm256_info *card = nm256_find_card (dev);
1550 if (card != NULL) {
1551 char *dma_buf = nm256_getDMAbuffer (dev, physbuf);
1552 card->is_open_record = 1;
1553 card->dev_for_record = dev;
1554 nm256_startRecording (card, dma_buf, count);
1559 * Prepare for inputting samples to DEV.
1560 * Each requested buffer will be BSIZE byes long, with a total of
1561 * BCOUNT buffers.
1564 static int
1565 nm256_audio_prepare_for_input(int dev, int bsize, int bcount)
1567 struct nm256_info *card = nm256_find_card (dev);
1569 if (card == NULL)
1570 return -ENODEV;
1572 if (card->is_open_record && card->dev_for_record != dev)
1573 return -EBUSY;
1575 audio_devs[dev]->dmap_in->flags |= DMA_NODMA;
1576 return 0;
1580 * Prepare for outputting samples to `dev'
1582 * Each buffer that will be passed will be `bsize' bytes long,
1583 * with a total of `bcount' buffers.
1585 * Called when:
1586 * 1. A trigger enables audio output (dmabuf.c:978)
1587 * 2. We get a write buffer without dma_mode setup (dmabuf.c:1152)
1588 * 3. We restart a transfer (dmabuf.c:1324)
1591 static int
1592 nm256_audio_prepare_for_output(int dev, int bsize, int bcount)
1594 struct nm256_info *card = nm256_find_card (dev);
1596 if (card == NULL)
1597 return -ENODEV;
1599 if (card->is_open_play && card->dev_for_play != dev)
1600 return -EBUSY;
1602 audio_devs[dev]->dmap_out->flags |= DMA_NODMA;
1603 return 0;
1606 /* Stop the current operations associated with DEV. */
1607 static void
1608 nm256_audio_reset(int dev)
1610 struct nm256_info *card = nm256_find_card (dev);
1612 if (card != NULL) {
1613 if (card->dev_for_play == dev)
1614 stopPlay (card);
1615 if (card->dev_for_record == dev)
1616 stopRecord (card);
1620 static int
1621 nm256_audio_local_qlen(int dev)
1623 return 0;
1626 static struct audio_driver nm256_audio_driver =
1628 owner: THIS_MODULE,
1629 open: nm256_audio_open,
1630 close: nm256_audio_close,
1631 output_block: nm256_audio_output_block,
1632 start_input: nm256_audio_start_input,
1633 ioctl: nm256_audio_ioctl,
1634 prepare_for_input: nm256_audio_prepare_for_input,
1635 prepare_for_output:nm256_audio_prepare_for_output,
1636 halt_io: nm256_audio_reset,
1637 local_qlen: nm256_audio_local_qlen,
1640 EXPORT_SYMBOL(init_nm256);
1642 static int loaded = 0;
1644 MODULE_PARM (usecache, "i");
1645 MODULE_PARM (buffertop, "i");
1646 MODULE_PARM (nm256_debug, "i");
1647 MODULE_PARM (force_load, "i");
1649 static int __init do_init_nm256(void)
1651 nmcard_list = NULL;
1652 printk (KERN_INFO "NeoMagic 256AV/256ZX audio driver, version 1.1\n");
1654 if (init_nm256 () == 0) {
1655 loaded = 1;
1656 return 0;
1658 else
1659 return -ENODEV;
1662 static void __exit cleanup_nm256 (void)
1664 if (loaded) {
1665 struct nm256_info *card;
1666 struct nm256_info *next_card;
1668 for (card = nmcard_list; card != NULL; card = next_card) {
1669 stopPlay (card);
1670 stopRecord (card);
1671 if (card->has_irq)
1672 free_irq (card->irq, card);
1673 nm256_release_ports (card);
1674 sound_unload_mixerdev (card->mixer_oss_dev);
1675 sound_unload_audiodev (card->dev[0]);
1676 sound_unload_audiodev (card->dev[1]);
1677 next_card = card->next_card;
1678 kfree (card);
1680 nmcard_list = NULL;
1682 pm_unregister_all (&handle_pm_event);
1685 module_init(do_init_nm256);
1686 module_exit(cleanup_nm256);
1689 * Local variables:
1690 * c-basic-offset: 4
1691 * End: