Merge with Linux 2.4.0-test5-pre3.
[linux-2.6/linux-mips.git] / drivers / sound / nm256_audio.c
blobe9ec909f660035fa290f27ed04483f2ff2100e20
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 "soundmodule.h"
24 #include "nm256.h"
25 #include "nm256_coeff.h"
27 int nm256_debug = 0;
28 static int force_load = 0;
30 /*
31 * The size of the playback reserve. When the playback buffer has less
32 * than NM256_PLAY_WMARK_SIZE bytes to output, we request a new
33 * buffer.
35 #define NM256_PLAY_WMARK_SIZE 512
37 static struct audio_driver nm256_audio_driver;
39 static int nm256_grabInterrupt (struct nm256_info *card);
40 static int nm256_releaseInterrupt (struct nm256_info *card);
41 static void nm256_interrupt (int irq, void *dev_id, struct pt_regs *dummy);
42 static void nm256_interrupt_zx (int irq, void *dev_id, struct pt_regs *dummy);
43 static int handle_pm_event (struct pm_dev *dev, pm_request_t rqst, void *data);
45 /* These belong in linux/pci.h. */
46 #define PCI_DEVICE_ID_NEOMAGIC_NM256AV_AUDIO 0x8005
47 #define PCI_DEVICE_ID_NEOMAGIC_NM256ZX_AUDIO 0x8006
49 #define RSRCADDRESS(dev,num) ((dev)->resource[(num)].start)
51 /* List of cards. */
52 static struct nm256_info *nmcard_list;
54 /* Release the mapped-in memory for CARD. */
55 static void
56 nm256_release_ports (struct nm256_info *card)
58 int x;
60 for (x = 0; x < 2; x++) {
61 if (card->port[x].ptr != NULL) {
62 u32 size =
63 card->port[x].end_offset - card->port[x].start_offset;
64 release_region ((unsigned long) card->port[x].ptr, size);
65 card->port[x].ptr = NULL;
70 /*
71 * Map in the memory ports for CARD, if they aren't already mapped in
72 * and have been configured. If successful, a zero value is returned;
73 * otherwise any previously mapped-in areas are released and a non-zero
74 * value is returned.
76 * This is invoked twice, once for each port. Ideally it would only be
77 * called once, but we now need to map in the second port in order to
78 * check how much memory the card has on the 256ZX.
80 static int
81 nm256_remap_ports (struct nm256_info *card)
83 int x;
85 for (x = 0; x < 2; x++) {
86 if (card->port[x].ptr == NULL && card->port[x].end_offset > 0) {
87 u32 physaddr
88 = card->port[x].physaddr + card->port[x].start_offset;
89 u32 size
90 = card->port[x].end_offset - card->port[x].start_offset;
92 card->port[x].ptr = ioremap_nocache (physaddr, size);
94 if (card->port[x].ptr == NULL) {
95 printk (KERN_ERR "NM256: Unable to remap port %d\n", x + 1);
96 nm256_release_ports (card);
97 return -1;
101 return 0;
104 /* Locate the card in our list. */
105 static struct nm256_info *
106 nm256_find_card (int dev)
108 struct nm256_info *card;
110 for (card = nmcard_list; card != NULL; card = card->next_card)
111 if (card->dev[0] == dev || card->dev[1] == dev)
112 return card;
114 return NULL;
118 * Ditto, but find the card struct corresponding to the mixer device DEV
119 * instead.
121 static struct nm256_info *
122 nm256_find_card_for_mixer (int dev)
124 struct nm256_info *card;
126 for (card = nmcard_list; card != NULL; card = card->next_card)
127 if (card->mixer_oss_dev == dev)
128 return card;
130 return NULL;
133 static int usecache = 0;
134 static int buffertop = 0;
136 /* Check to see if we're using the bank of cached coefficients. */
138 nm256_cachedCoefficients (struct nm256_info *card)
140 return usecache;
143 /* The actual rates supported by the card. */
144 static int samplerates[9] = {
145 8000, 11025, 16000, 22050, 24000, 32000, 44100, 48000, 99999999
149 * Set the card samplerate, word size and stereo mode to correspond to
150 * the settings in the CARD struct for the specified device in DEV.
151 * We keep two separate sets of information, one for each device; the
152 * hardware is not actually configured until a read or write is
153 * attempted.
157 nm256_setInfo (int dev, struct nm256_info *card)
159 int x;
160 int w;
161 int targetrate;
163 if (card->dev[0] == dev)
164 w = 0;
165 else if (card->dev[1] == dev)
166 w = 1;
167 else
168 return -ENODEV;
170 targetrate = card->sinfo[w].samplerate;
172 if ((card->sinfo[w].bits != 8 && card->sinfo[w].bits != 16)
173 || targetrate < samplerates[0]
174 || targetrate > samplerates[7])
175 return -EINVAL;
177 for (x = 0; x < 8; x++)
178 if (targetrate < ((samplerates[x] + samplerates[x + 1]) / 2))
179 break;
181 if (x < 8) {
182 u8 ratebits = ((x << 4) & NM_RATE_MASK);
183 if (card->sinfo[w].bits == 16)
184 ratebits |= NM_RATE_BITS_16;
185 if (card->sinfo[w].stereo)
186 ratebits |= NM_RATE_STEREO;
188 card->sinfo[w].samplerate = samplerates[x];
191 if (card->dev_for_play == dev && card->playing) {
192 if (nm256_debug)
193 printk (KERN_DEBUG "Setting play ratebits to 0x%x\n",
194 ratebits);
195 nm256_loadCoefficient (card, 0, x);
196 nm256_writePort8 (card, 2,
197 NM_PLAYBACK_REG_OFFSET + NM_RATE_REG_OFFSET,
198 ratebits);
201 if (card->dev_for_record == dev && card->recording) {
202 if (nm256_debug)
203 printk (KERN_DEBUG "Setting record ratebits to 0x%x\n",
204 ratebits);
205 nm256_loadCoefficient (card, 1, x);
206 nm256_writePort8 (card, 2,
207 NM_RECORD_REG_OFFSET + NM_RATE_REG_OFFSET,
208 ratebits);
210 return 0;
212 else
213 return -EINVAL;
216 /* Start the play process going. */
217 static void
218 startPlay (struct nm256_info *card)
220 if (! card->playing) {
221 card->playing = 1;
222 if (nm256_grabInterrupt (card) == 0) {
223 nm256_setInfo (card->dev_for_play, card);
225 /* Enable playback engine and interrupts. */
226 nm256_writePort8 (card, 2, NM_PLAYBACK_ENABLE_REG,
227 NM_PLAYBACK_ENABLE_FLAG | NM_PLAYBACK_FREERUN);
229 /* Enable both channels. */
230 nm256_writePort16 (card, 2, NM_AUDIO_MUTE_REG, 0x0);
236 * Request one chunk of AMT bytes from the recording device. When the
237 * operation is complete, the data will be copied into BUFFER and the
238 * function DMAbuf_inputintr will be invoked.
241 static void
242 nm256_startRecording (struct nm256_info *card, char *buffer, u32 amt)
244 u32 endpos;
245 int enableEngine = 0;
246 u32 ringsize = card->recordBufferSize;
247 unsigned long flags;
249 if (amt > (ringsize / 2)) {
251 * Of course this won't actually work right, because the
252 * caller is going to assume we will give what we got asked
253 * for.
255 printk (KERN_ERR "NM256: Read request too large: %d\n", amt);
256 amt = ringsize / 2;
259 if (amt < 8) {
260 printk (KERN_ERR "NM256: Read request too small; %d\n", amt);
261 return;
264 save_flags (flags);
265 cli ();
267 * If we're not currently recording, set up the start and end registers
268 * for the recording engine.
270 if (! card->recording) {
271 card->recording = 1;
272 if (nm256_grabInterrupt (card) == 0) {
273 card->curRecPos = 0;
274 nm256_setInfo (card->dev_for_record, card);
275 nm256_writePort32 (card, 2, NM_RBUFFER_START, card->abuf2);
276 nm256_writePort32 (card, 2, NM_RBUFFER_END,
277 card->abuf2 + ringsize);
279 nm256_writePort32 (card, 2, NM_RBUFFER_CURRP,
280 card->abuf2 + card->curRecPos);
281 enableEngine = 1;
283 else {
284 /* Not sure what else to do here. */
285 restore_flags (flags);
286 return;
291 * If we happen to go past the end of the buffer a bit (due to a
292 * delayed interrupt) it's OK. So might as well set the watermark
293 * right at the end of the data we want.
295 endpos = card->abuf2 + ((card->curRecPos + amt) % ringsize);
297 card->recBuf = buffer;
298 card->requestedRecAmt = amt;
299 nm256_writePort32 (card, 2, NM_RBUFFER_WMARK, endpos);
300 /* Enable recording engine and interrupts. */
301 if (enableEngine)
302 nm256_writePort8 (card, 2, NM_RECORD_ENABLE_REG,
303 NM_RECORD_ENABLE_FLAG | NM_RECORD_FREERUN);
305 restore_flags (flags);
308 /* Stop the play engine. */
309 static void
310 stopPlay (struct nm256_info *card)
312 /* Shut off sound from both channels. */
313 nm256_writePort16 (card, 2, NM_AUDIO_MUTE_REG,
314 NM_AUDIO_MUTE_LEFT | NM_AUDIO_MUTE_RIGHT);
315 /* Disable play engine. */
316 nm256_writePort8 (card, 2, NM_PLAYBACK_ENABLE_REG, 0);
317 if (card->playing) {
318 nm256_releaseInterrupt (card);
320 /* Reset the relevant state bits. */
321 card->playing = 0;
322 card->curPlayPos = 0;
326 /* Stop recording. */
327 static void
328 stopRecord (struct nm256_info *card)
330 /* Disable recording engine. */
331 nm256_writePort8 (card, 2, NM_RECORD_ENABLE_REG, 0);
333 if (card->recording) {
334 nm256_releaseInterrupt (card);
336 card->recording = 0;
337 card->curRecPos = 0;
342 * Ring buffers, man. That's where the hip-hop, wild-n-wooly action's at.
343 * 1972? (Well, I suppose it was cheep-n-easy to implement.)
345 * Write AMT bytes of BUFFER to the playback ring buffer, and start the
346 * playback engine running. It will only accept up to 1/2 of the total
347 * size of the ring buffer. No check is made that we're about to overwrite
348 * the currently-playing sample.
351 static void
352 nm256_write_block (struct nm256_info *card, char *buffer, u32 amt)
354 u32 ringsize = card->playbackBufferSize;
355 u32 endstop;
356 unsigned long flags;
358 if (amt > (ringsize / 2)) {
359 printk (KERN_ERR "NM256: Write request too large: %d\n", amt);
360 amt = (ringsize / 2);
363 if (amt < NM256_PLAY_WMARK_SIZE) {
364 printk (KERN_ERR "NM256: Write request too small: %d\n", amt);
365 return;
368 card->curPlayPos %= ringsize;
370 card->requested_amt = amt;
372 save_flags (flags);
373 cli ();
375 if ((card->curPlayPos + amt) >= ringsize) {
376 u32 rem = ringsize - card->curPlayPos;
378 nm256_writeBuffer8 (card, buffer, 1,
379 card->abuf1 + card->curPlayPos,
380 rem);
381 if (amt > rem)
382 nm256_writeBuffer8 (card, buffer + rem, 1, card->abuf1,
383 amt - rem);
385 else
386 nm256_writeBuffer8 (card, buffer, 1,
387 card->abuf1 + card->curPlayPos,
388 amt);
391 * Setup the start-n-stop-n-limit registers, and start that engine
392 * goin'.
394 * Normally we just let it wrap around to avoid the click-click
395 * action scene.
397 if (! card->playing) {
398 /* The PBUFFER_END register in this case points to one sample
399 before the end of the buffer. */
400 int w = (card->dev_for_play == card->dev[0] ? 0 : 1);
401 int sampsize = (card->sinfo[w].bits == 16 ? 2 : 1);
403 if (card->sinfo[w].stereo)
404 sampsize *= 2;
406 /* Need to set the not-normally-changing-registers up. */
407 nm256_writePort32 (card, 2, NM_PBUFFER_START,
408 card->abuf1 + card->curPlayPos);
409 nm256_writePort32 (card, 2, NM_PBUFFER_END,
410 card->abuf1 + ringsize - sampsize);
411 nm256_writePort32 (card, 2, NM_PBUFFER_CURRP,
412 card->abuf1 + card->curPlayPos);
414 endstop = (card->curPlayPos + amt - NM256_PLAY_WMARK_SIZE) % ringsize;
415 nm256_writePort32 (card, 2, NM_PBUFFER_WMARK, card->abuf1 + endstop);
417 if (! card->playing)
418 startPlay (card);
420 restore_flags (flags);
423 /* We just got a card playback interrupt; process it. */
424 static void
425 nm256_get_new_block (struct nm256_info *card)
427 /* Check to see how much got played so far. */
428 u32 amt = nm256_readPort32 (card, 2, NM_PBUFFER_CURRP) - card->abuf1;
430 if (amt >= card->playbackBufferSize) {
431 printk (KERN_ERR "NM256: Sound playback pointer invalid!\n");
432 amt = 0;
435 if (amt < card->curPlayPos)
436 amt = (card->playbackBufferSize - card->curPlayPos) + amt;
437 else
438 amt -= card->curPlayPos;
440 if (card->requested_amt > (amt + NM256_PLAY_WMARK_SIZE)) {
441 u32 endstop =
442 card->curPlayPos + card->requested_amt - NM256_PLAY_WMARK_SIZE;
443 nm256_writePort32 (card, 2, NM_PBUFFER_WMARK, card->abuf1 + endstop);
445 else {
446 card->curPlayPos += card->requested_amt;
447 /* Get a new block to write. This will eventually invoke
448 nm256_write_block () or stopPlay (). */
449 DMAbuf_outputintr (card->dev_for_play, 1);
453 /* Ultra cheez-whiz. But I'm too lazy to grep headers. */
454 #define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
457 * Read the last-recorded block from the ring buffer, copy it into the
458 * saved buffer pointer, and invoke DMAuf_inputintr() with the recording
459 * device.
462 static void
463 nm256_read_block (struct nm256_info *card)
465 /* Grab the current position of the recording pointer. */
466 u32 currptr = nm256_readPort32 (card, 2, NM_RBUFFER_CURRP) - card->abuf2;
467 u32 amtToRead = card->requestedRecAmt;
468 u32 ringsize = card->recordBufferSize;
470 if (currptr >= card->recordBufferSize) {
471 printk (KERN_ERR "NM256: Sound buffer record pointer invalid!\n");
472 currptr = 0;
476 * This test is probably redundant; we shouldn't be here unless
477 * it's true.
479 if (card->recording) {
480 /* If we wrapped around, copy everything from the start of our
481 recording buffer to the end of the buffer. */
482 if (currptr < card->curRecPos) {
483 u32 amt = MIN (ringsize - card->curRecPos, amtToRead);
485 nm256_readBuffer8 (card, card->recBuf, 1,
486 card->abuf2 + card->curRecPos,
487 amt);
488 amtToRead -= amt;
489 card->curRecPos += amt;
490 card->recBuf += amt;
491 if (card->curRecPos == ringsize)
492 card->curRecPos = 0;
495 if ((card->curRecPos < currptr) && (amtToRead > 0)) {
496 u32 amt = MIN (currptr - card->curRecPos, amtToRead);
497 nm256_readBuffer8 (card, card->recBuf, 1,
498 card->abuf2 + card->curRecPos, amt);
499 card->curRecPos = ((card->curRecPos + amt) % ringsize);
501 card->recBuf = NULL;
502 card->requestedRecAmt = 0;
503 DMAbuf_inputintr (card->dev_for_record);
506 #undef MIN
509 * Initialize the hardware.
511 static void
512 nm256_initHw (struct nm256_info *card)
514 /* Reset everything. */
515 nm256_writePort8 (card, 2, 0x0, 0x11);
516 nm256_writePort16 (card, 2, 0x214, 0);
518 stopRecord (card);
519 stopPlay (card);
523 * Handle a potential interrupt for the device referred to by DEV_ID.
525 * I don't like the cut-n-paste job here either between the two routines,
526 * but there are sufficient differences between the two interrupt handlers
527 * that parameterizing it isn't all that great either. (Could use a macro,
528 * I suppose...yucky bleah.)
531 static void
532 nm256_interrupt (int irq, void *dev_id, struct pt_regs *dummy)
534 struct nm256_info *card = (struct nm256_info *)dev_id;
535 u16 status;
536 static int badintrcount = 0;
538 if ((card == NULL) || (card->magsig != NM_MAGIC_SIG)) {
539 printk (KERN_ERR "NM256: Bad card pointer\n");
540 return;
543 status = nm256_readPort16 (card, 2, NM_INT_REG);
545 /* Not ours. */
546 if (status == 0) {
547 if (badintrcount++ > 1000) {
549 * I'm not sure if the best thing is to stop the card from
550 * playing or just release the interrupt (after all, we're in
551 * a bad situation, so doing fancy stuff may not be such a good
552 * idea).
554 * I worry about the card engine continuing to play noise
555 * over and over, however--that could become a very
556 * obnoxious problem. And we know that when this usually
557 * happens things are fairly safe, it just means the user's
558 * inserted a PCMCIA card and someone's spamming us with IRQ 9s.
561 if (card->playing)
562 stopPlay (card);
563 if (card->recording)
564 stopRecord (card);
565 badintrcount = 0;
567 return;
570 badintrcount = 0;
572 /* Rather boring; check for individual interrupts and process them. */
574 if (status & NM_PLAYBACK_INT) {
575 status &= ~NM_PLAYBACK_INT;
576 NM_ACK_INT (card, NM_PLAYBACK_INT);
578 if (card->playing)
579 nm256_get_new_block (card);
582 if (status & NM_RECORD_INT) {
583 status &= ~NM_RECORD_INT;
584 NM_ACK_INT (card, NM_RECORD_INT);
586 if (card->recording)
587 nm256_read_block (card);
590 if (status & NM_MISC_INT_1) {
591 u8 cbyte;
593 status &= ~NM_MISC_INT_1;
594 printk (KERN_ERR "NM256: Got misc interrupt #1\n");
595 NM_ACK_INT (card, NM_MISC_INT_1);
596 nm256_writePort16 (card, 2, NM_INT_REG, 0x8000);
597 cbyte = nm256_readPort8 (card, 2, 0x400);
598 nm256_writePort8 (card, 2, 0x400, cbyte | 2);
601 if (status & NM_MISC_INT_2) {
602 u8 cbyte;
604 status &= ~NM_MISC_INT_2;
605 printk (KERN_ERR "NM256: Got misc interrupt #2\n");
606 NM_ACK_INT (card, NM_MISC_INT_2);
607 cbyte = nm256_readPort8 (card, 2, 0x400);
608 nm256_writePort8 (card, 2, 0x400, cbyte & ~2);
611 /* Unknown interrupt. */
612 if (status) {
613 printk (KERN_ERR "NM256: Fire in the hole! Unknown status 0x%x\n",
614 status);
615 /* Pray. */
616 NM_ACK_INT (card, status);
621 * Handle a potential interrupt for the device referred to by DEV_ID.
622 * This handler is for the 256ZX, and is very similar to the non-ZX
623 * routine.
626 static void
627 nm256_interrupt_zx (int irq, void *dev_id, struct pt_regs *dummy)
629 struct nm256_info *card = (struct nm256_info *)dev_id;
630 u32 status;
631 static int badintrcount = 0;
633 if ((card == NULL) || (card->magsig != NM_MAGIC_SIG)) {
634 printk (KERN_ERR "NM256: Bad card pointer\n");
635 return;
638 status = nm256_readPort32 (card, 2, NM_INT_REG);
640 /* Not ours. */
641 if (status == 0) {
642 if (badintrcount++ > 1000) {
643 printk (KERN_ERR "NM256: Releasing interrupt, over 1000 invalid interrupts\n");
645 * I'm not sure if the best thing is to stop the card from
646 * playing or just release the interrupt (after all, we're in
647 * a bad situation, so doing fancy stuff may not be such a good
648 * idea).
650 * I worry about the card engine continuing to play noise
651 * over and over, however--that could become a very
652 * obnoxious problem. And we know that when this usually
653 * happens things are fairly safe, it just means the user's
654 * inserted a PCMCIA card and someone's spamming us with
655 * IRQ 9s.
658 if (card->playing)
659 stopPlay (card);
660 if (card->recording)
661 stopRecord (card);
662 badintrcount = 0;
664 return;
667 badintrcount = 0;
669 /* Rather boring; check for individual interrupts and process them. */
671 if (status & NM2_PLAYBACK_INT) {
672 status &= ~NM2_PLAYBACK_INT;
673 NM2_ACK_INT (card, NM2_PLAYBACK_INT);
675 if (card->playing)
676 nm256_get_new_block (card);
679 if (status & NM2_RECORD_INT) {
680 status &= ~NM2_RECORD_INT;
681 NM2_ACK_INT (card, NM2_RECORD_INT);
683 if (card->recording)
684 nm256_read_block (card);
687 if (status & NM2_MISC_INT_1) {
688 u8 cbyte;
690 status &= ~NM2_MISC_INT_1;
691 printk (KERN_ERR "NM256: Got misc interrupt #1\n");
692 NM2_ACK_INT (card, NM2_MISC_INT_1);
693 cbyte = nm256_readPort8 (card, 2, 0x400);
694 nm256_writePort8 (card, 2, 0x400, cbyte | 2);
697 if (status & NM2_MISC_INT_2) {
698 u8 cbyte;
700 status &= ~NM2_MISC_INT_2;
701 printk (KERN_ERR "NM256: Got misc interrupt #2\n");
702 NM2_ACK_INT (card, NM2_MISC_INT_2);
703 cbyte = nm256_readPort8 (card, 2, 0x400);
704 nm256_writePort8 (card, 2, 0x400, cbyte & ~2);
707 /* Unknown interrupt. */
708 if (status) {
709 printk (KERN_ERR "NM256: Fire in the hole! Unknown status 0x%x\n",
710 status);
711 /* Pray. */
712 NM2_ACK_INT (card, status);
717 * Request our interrupt.
719 static int
720 nm256_grabInterrupt (struct nm256_info *card)
722 if (card->has_irq++ == 0) {
723 if (request_irq (card->irq, card->introutine, SA_SHIRQ,
724 "NM256_audio", card) < 0) {
725 printk (KERN_ERR "NM256: can't obtain IRQ %d\n", card->irq);
726 return -1;
729 return 0;
733 * Release our interrupt.
735 static int
736 nm256_releaseInterrupt (struct nm256_info *card)
738 if (card->has_irq <= 0) {
739 printk (KERN_ERR "nm256: too many calls to releaseInterrupt\n");
740 return -1;
742 card->has_irq--;
743 if (card->has_irq == 0) {
744 free_irq (card->irq, card);
746 return 0;
750 * Waits for the mixer to become ready to be written; returns a zero value
751 * if it timed out.
754 static int
755 nm256_isReady (struct ac97_hwint *dev)
757 struct nm256_info *card = (struct nm256_info *)dev->driver_private;
758 int t2 = 10;
759 u32 testaddr;
760 u16 testb;
761 int done = 0;
763 if (card->magsig != NM_MAGIC_SIG) {
764 printk (KERN_ERR "NM256: Bad magic signature in isReady!\n");
765 return 0;
768 testaddr = card->mixer_status_offset;
769 testb = card->mixer_status_mask;
772 * Loop around waiting for the mixer to become ready.
774 while (! done && t2-- > 0) {
775 if ((nm256_readPort16 (card, 2, testaddr) & testb) == 0)
776 done = 1;
777 else
778 udelay (100);
780 return done;
784 * Return the contents of the AC97 mixer register REG. Returns a positive
785 * value if successful, or a negative error code.
787 static int
788 nm256_readAC97Reg (struct ac97_hwint *dev, u8 reg)
790 struct nm256_info *card = (struct nm256_info *)dev->driver_private;
792 if (card->magsig != NM_MAGIC_SIG) {
793 printk (KERN_ERR "NM256: Bad magic signature in readAC97Reg!\n");
794 return -EINVAL;
797 if (reg < 128) {
798 int res;
800 nm256_isReady (dev);
801 res = nm256_readPort16 (card, 2, card->mixer + reg);
802 /* Magic delay. Bleah yucky. */
803 udelay (1000);
804 return res;
806 else
807 return -EINVAL;
811 * Writes VALUE to AC97 mixer register REG. Returns 0 if successful, or
812 * a negative error code.
814 static int
815 nm256_writeAC97Reg (struct ac97_hwint *dev, u8 reg, u16 value)
817 unsigned long flags;
818 int tries = 2;
819 int done = 0;
820 u32 base;
822 struct nm256_info *card = (struct nm256_info *)dev->driver_private;
824 if (card->magsig != NM_MAGIC_SIG) {
825 printk (KERN_ERR "NM256: Bad magic signature in writeAC97Reg!\n");
826 return -EINVAL;
829 base = card->mixer;
831 save_flags (flags);
832 cli ();
834 nm256_isReady (dev);
836 /* Wait for the write to take, too. */
837 while ((tries-- > 0) && !done) {
838 nm256_writePort16 (card, 2, base + reg, value);
839 if (nm256_isReady (dev)) {
840 done = 1;
841 break;
846 restore_flags (flags);
847 udelay (1000);
849 return ! done;
853 * Initial register values to be written to the AC97 mixer.
854 * While most of these are identical to the reset values, we do this
855 * so that we have most of the register contents cached--this avoids
856 * reading from the mixer directly (which seems to be problematic,
857 * probably due to ignorance).
859 struct initialValues
861 unsigned short port;
862 unsigned short value;
865 static struct initialValues nm256_ac97_initial_values[] =
867 { AC97_MASTER_VOL_STEREO, 0x8000 },
868 { AC97_HEADPHONE_VOL, 0x8000 },
869 { AC97_MASTER_VOL_MONO, 0x0000 },
870 { AC97_PCBEEP_VOL, 0x0000 },
871 { AC97_PHONE_VOL, 0x0008 },
872 { AC97_MIC_VOL, 0x8000 },
873 { AC97_LINEIN_VOL, 0x8808 },
874 { AC97_CD_VOL, 0x8808 },
875 { AC97_VIDEO_VOL, 0x8808 },
876 { AC97_AUX_VOL, 0x8808 },
877 { AC97_PCMOUT_VOL, 0x0808 },
878 { AC97_RECORD_SELECT, 0x0000 },
879 { AC97_RECORD_GAIN, 0x0B0B },
880 { AC97_GENERAL_PURPOSE, 0x0000 },
881 { 0xffff, 0xffff }
884 /* Initialize the AC97 into a known state. */
885 static int
886 nm256_resetAC97 (struct ac97_hwint *dev)
888 struct nm256_info *card = (struct nm256_info *)dev->driver_private;
889 int x;
891 if (card->magsig != NM_MAGIC_SIG) {
892 printk (KERN_ERR "NM256: Bad magic signature in resetAC97!\n");
893 return -EINVAL;
896 /* Reset the mixer. 'Tis magic! */
897 nm256_writePort8 (card, 2, 0x6c0, 1);
898 nm256_writePort8 (card, 2, 0x6cc, 0x87);
899 nm256_writePort8 (card, 2, 0x6cc, 0x80);
900 nm256_writePort8 (card, 2, 0x6cc, 0x0);
902 if (! card->mixer_values_init) {
903 for (x = 0; nm256_ac97_initial_values[x].port != 0xffff; x++) {
904 ac97_put_register (dev,
905 nm256_ac97_initial_values[x].port,
906 nm256_ac97_initial_values[x].value);
907 card->mixer_values_init = 1;
911 return 0;
915 * We don't do anything particularly special here; it just passes the
916 * mixer ioctl to the AC97 driver.
918 static int
919 nm256_default_mixer_ioctl (int dev, unsigned int cmd, caddr_t arg)
921 struct nm256_info *card = nm256_find_card_for_mixer (dev);
922 if (card != NULL)
923 return ac97_mixer_ioctl (&(card->mdev), cmd, arg);
924 else
925 return -ENODEV;
928 static struct mixer_operations nm256_mixer_operations = {
929 "NeoMagic",
930 "NM256AC97Mixer",
931 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 get_user_ret(ret, (int *) arg, -EFAULT);
1424 if (ret != 0) {
1425 oldinfo = card->sinfo[w].samplerate;
1426 card->sinfo[w].samplerate = ret;
1427 ret = nm256_setInfo(dev, card);
1428 if (ret != 0)
1429 card->sinfo[w].samplerate = oldinfo;
1431 if (ret == 0)
1432 ret = card->sinfo[w].samplerate;
1433 break;
1435 case SOUND_PCM_READ_RATE:
1436 ret = card->sinfo[w].samplerate;
1437 break;
1439 case SNDCTL_DSP_STEREO:
1440 get_user_ret(ret, (int *) arg, -EFAULT);
1442 card->sinfo[w].stereo = ret ? 1 : 0;
1443 ret = nm256_setInfo (dev, card);
1444 if (ret == 0)
1445 ret = card->sinfo[w].stereo;
1447 break;
1449 case SOUND_PCM_WRITE_CHANNELS:
1450 get_user_ret(ret, (int *) arg, -EFAULT);
1452 if (ret < 1 || ret > 3)
1453 ret = card->sinfo[w].stereo + 1;
1454 else {
1455 card->sinfo[w].stereo = ret - 1;
1456 ret = nm256_setInfo (dev, card);
1457 if (ret == 0)
1458 ret = card->sinfo[w].stereo + 1;
1460 break;
1462 case SOUND_PCM_READ_CHANNELS:
1463 ret = card->sinfo[w].stereo + 1;
1464 break;
1466 case SNDCTL_DSP_SETFMT:
1467 get_user_ret(ret, (int *) arg, -EFAULT);
1469 if (ret != 0) {
1470 oldinfo = card->sinfo[w].bits;
1471 card->sinfo[w].bits = ret;
1472 ret = nm256_setInfo (dev, card);
1473 if (ret != 0)
1474 card->sinfo[w].bits = oldinfo;
1476 if (ret == 0)
1477 ret = card->sinfo[w].bits;
1478 break;
1480 case SOUND_PCM_READ_BITS:
1481 ret = card->sinfo[w].bits;
1482 break;
1484 default:
1485 return -EINVAL;
1487 return put_user(ret, (int *) arg);
1491 * Given the sound device DEV and an associated physical buffer PHYSBUF,
1492 * return a pointer to the actual buffer in kernel space.
1494 * This routine should exist as part of the soundcore routines.
1497 static char *
1498 nm256_getDMAbuffer (int dev, unsigned long physbuf)
1500 struct audio_operations *adev = audio_devs[dev];
1501 struct dma_buffparms *dmap = adev->dmap_out;
1502 char *dma_start =
1503 (char *)(physbuf - (unsigned long)dmap->raw_buf_phys
1504 + (unsigned long)dmap->raw_buf);
1506 return dma_start;
1511 * Output a block to sound device
1513 * dev - device number
1514 * buf - physical address of buffer
1515 * total_count - total byte count in buffer
1516 * intrflag - set if this has been called from an interrupt
1517 * (via DMAbuf_outputintr)
1518 * restart_dma - set if engine needs to be re-initialised
1520 * Called when:
1521 * 1. Starting output (dmabuf.c:1327)
1522 * 2. (dmabuf.c:1504)
1523 * 3. A new buffer needs to be sent to the device (dmabuf.c:1579)
1525 static void
1526 nm256_audio_output_block(int dev, unsigned long physbuf,
1527 int total_count, int intrflag)
1529 struct nm256_info *card = nm256_find_card (dev);
1531 if (card != NULL) {
1532 char *dma_buf = nm256_getDMAbuffer (dev, physbuf);
1533 card->is_open_play = 1;
1534 card->dev_for_play = dev;
1535 nm256_write_block (card, dma_buf, total_count);
1539 /* Ditto, but do recording instead. */
1540 static void
1541 nm256_audio_start_input(int dev, unsigned long physbuf, int count,
1542 int intrflag)
1544 struct nm256_info *card = nm256_find_card (dev);
1546 if (card != NULL) {
1547 char *dma_buf = nm256_getDMAbuffer (dev, physbuf);
1548 card->is_open_record = 1;
1549 card->dev_for_record = dev;
1550 nm256_startRecording (card, dma_buf, count);
1555 * Prepare for inputting samples to DEV.
1556 * Each requested buffer will be BSIZE byes long, with a total of
1557 * BCOUNT buffers.
1560 static int
1561 nm256_audio_prepare_for_input(int dev, int bsize, int bcount)
1563 struct nm256_info *card = nm256_find_card (dev);
1565 if (card == NULL)
1566 return -ENODEV;
1568 if (card->is_open_record && card->dev_for_record != dev)
1569 return -EBUSY;
1571 audio_devs[dev]->dmap_in->flags |= DMA_NODMA;
1572 return 0;
1576 * Prepare for outputting samples to `dev'
1578 * Each buffer that will be passed will be `bsize' bytes long,
1579 * with a total of `bcount' buffers.
1581 * Called when:
1582 * 1. A trigger enables audio output (dmabuf.c:978)
1583 * 2. We get a write buffer without dma_mode setup (dmabuf.c:1152)
1584 * 3. We restart a transfer (dmabuf.c:1324)
1587 static int
1588 nm256_audio_prepare_for_output(int dev, int bsize, int bcount)
1590 struct nm256_info *card = nm256_find_card (dev);
1592 if (card == NULL)
1593 return -ENODEV;
1595 if (card->is_open_play && card->dev_for_play != dev)
1596 return -EBUSY;
1598 audio_devs[dev]->dmap_out->flags |= DMA_NODMA;
1599 return 0;
1602 /* Stop the current operations associated with DEV. */
1603 static void
1604 nm256_audio_reset(int dev)
1606 struct nm256_info *card = nm256_find_card (dev);
1608 if (card != NULL) {
1609 if (card->dev_for_play == dev)
1610 stopPlay (card);
1611 if (card->dev_for_record == dev)
1612 stopRecord (card);
1616 static int
1617 nm256_audio_local_qlen(int dev)
1619 return 0;
1622 static struct audio_driver nm256_audio_driver =
1624 nm256_audio_open, /* open */
1625 nm256_audio_close, /* close */
1626 nm256_audio_output_block, /* output_block */
1627 nm256_audio_start_input, /* start_input */
1628 nm256_audio_ioctl, /* ioctl */
1629 nm256_audio_prepare_for_input, /* prepare_for_input */
1630 nm256_audio_prepare_for_output, /* prepare_for_output */
1631 nm256_audio_reset, /* reset */
1632 nm256_audio_local_qlen, /*+local_qlen */
1633 NULL, /*+copy_from_user */
1634 NULL, /*+halt_input */
1635 NULL, /* halt_output */
1636 NULL, /*+trigger */
1637 NULL, /*+set_speed */
1638 NULL, /*+set_bits */
1639 NULL, /*+set_channels */
1642 EXPORT_SYMBOL(init_nm256);
1644 static int loaded = 0;
1646 MODULE_PARM (usecache, "i");
1647 MODULE_PARM (buffertop, "i");
1648 MODULE_PARM (nm256_debug, "i");
1649 MODULE_PARM (force_load, "i");
1651 static int __init do_init_nm256(void)
1653 nmcard_list = NULL;
1654 printk (KERN_INFO "NeoMagic 256AV/256ZX audio driver, version 1.1\n");
1656 if (init_nm256 () == 0) {
1657 SOUND_LOCK;
1658 loaded = 1;
1659 return 0;
1661 else
1662 return -ENODEV;
1665 static void __exit cleanup_nm256 (void)
1667 if (loaded) {
1668 struct nm256_info *card;
1669 struct nm256_info *next_card;
1671 SOUND_LOCK_END;
1673 for (card = nmcard_list; card != NULL; card = next_card) {
1674 stopPlay (card);
1675 stopRecord (card);
1676 if (card->has_irq)
1677 free_irq (card->irq, card);
1678 nm256_release_ports (card);
1679 sound_unload_mixerdev (card->mixer_oss_dev);
1680 sound_unload_audiodev (card->dev[0]);
1681 sound_unload_audiodev (card->dev[1]);
1682 next_card = card->next_card;
1683 kfree (card);
1685 nmcard_list = NULL;
1687 pm_unregister_all (&handle_pm_event);
1690 module_init(do_init_nm256);
1691 module_exit(cleanup_nm256);
1694 * Local variables:
1695 * c-basic-offset: 4
1696 * End: