4 * Common routines for Sound Blaster compatible cards.
7 * Copyright (C) by Hannu Savolainen 1993-1997
9 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
10 * Version 2 (June 1991). See the "COPYING" file distributed with this software
14 * Daniel J. Rodriksson: Modified sbintr to handle 8 and 16 bit interrupts
15 * for full duplex support ( only sb16 by now )
16 * Rolf Fokkens: Added (BETA?) support for ES1887 chips.
17 * (fokkensr@vertis.nl) Which means: You can adjust the recording levels.
19 * 2000/01/18 - separated sb_card and sb_common -
20 * Jeff Garzik <jgarzik@pobox.com>
22 * 2000/09/18 - got rid of attach_uart401
23 * Arnaldo Carvalho de Melo <acme@conectiva.com.br>
25 * 2001/01/26 - replaced CLI/STI with spinlocks
26 * Chris Rankin <rankinc@zipworld.com.au>
29 #include <linux/config.h>
30 #include <linux/init.h>
31 #include <linux/module.h>
32 #include <linux/delay.h>
33 #include <linux/spinlock.h>
35 #include "sound_config.h"
36 #include "sound_firmware.h"
50 static sb_devc *detected_devc; /* For communication from probe to init */
51 static sb_devc *last_devc; /* For MPU401 initialization */
53 static unsigned char jazz_irq_bits[] = {
54 0, 0, 2, 3, 0, 1, 0, 4, 0, 2, 5, 0, 0, 0, 0, 6
57 static unsigned char jazz_dma_bits[] = {
58 0, 1, 0, 2, 0, 3, 0, 4
64 * Jazz16 chipset specific control variables
67 static int jazz16_base; /* Not detected */
68 static unsigned char jazz16_bits; /* I/O relocation bits */
69 static spinlock_t jazz16_lock = SPIN_LOCK_UNLOCKED;
72 * Logitech Soundman Wave specific initialization code
75 #ifdef SMW_MIDI0001_INCLUDED
76 #include "smw-midi0001.h"
78 static unsigned char *smw_ucode;
79 static int smw_ucodeLen;
83 sb_devc *last_sb; /* Last sb loaded */
85 int sb_dsp_command(sb_devc * devc, unsigned char val)
90 limit = jiffies + HZ / 10; /* Timeout */
93 * Note! the i<500000 is an emergency exit. The sb_dsp_command() is sometimes
94 * called while interrupts are disabled. This means that the timer is
95 * disabled also. However the timeout situation is a abnormal condition.
96 * Normally the DSP should be ready to accept commands after just couple of
100 for (i = 0; i < 500000 && (limit-jiffies)>0; i++)
102 if ((inb(DSP_STATUS) & 0x80) == 0)
104 outb((val), DSP_COMMAND);
108 printk(KERN_WARNING "Sound Blaster: DSP command(%x) timeout.\n", val);
112 int sb_dsp_get_byte(sb_devc * devc)
116 for (i = 1000; i; i--)
118 if (inb(DSP_DATA_AVAIL) & 0x80)
119 return inb(DSP_READ);
124 static void sb_intr (sb_devc *devc)
127 unsigned char src = 0xff;
129 if (devc->model == MDL_SB16)
131 src = sb_getmixer(devc, IRQ_STAT); /* Interrupt source register */
133 if (src & 4) /* MPU401 interrupt */
134 if(devc->midi_irq_cookie)
135 uart401intr(devc->irq, devc->midi_irq_cookie, NULL);
138 return; /* Not a DSP interrupt */
140 if (devc->intr_active && (!devc->fullduplex || (src & 0x01)))
142 switch (devc->irq_mode)
145 DMAbuf_outputintr(devc->dev, 1);
149 DMAbuf_inputintr(devc->dev);
156 sb_midi_interrupt(devc);
160 /* printk(KERN_WARN "Sound Blaster: Unexpected interrupt\n"); */
164 else if (devc->intr_active_16 && (src & 0x02))
166 switch (devc->irq_mode_16)
169 DMAbuf_outputintr(devc->dev, 1);
173 DMAbuf_inputintr(devc->dev);
180 /* printk(KERN_WARN "Sound Blaster: Unexpected interrupt\n"); */
185 * Acknowledge interrupts
189 status = inb(DSP_DATA_AVAIL);
191 if (devc->model == MDL_SB16 && src & 0x02)
192 status = inb(DSP_DATA_AVL16);
195 static void pci_intr(sb_devc *devc)
197 int src = inb(devc->pcibase+0x1A);
203 static void sbintr(int irq, void *dev_id, struct pt_regs *dummy)
205 sb_devc *devc = dev_id;
209 switch (devc->model) {
223 int sb_dsp_reset(sb_devc * devc)
227 DEB(printk("Entered sb_dsp_reset()\n"));
229 if (devc->model == MDL_ESS) return ess_dsp_reset (devc);
231 /* This is only for non-ESS chips */
239 for (loopc = 0; loopc < 1000 && !(inb(DSP_DATA_AVAIL) & 0x80); loopc++);
241 if (inb(DSP_READ) != 0xAA)
243 DDB(printk("sb: No response to RESET\n"));
244 return 0; /* Sorry */
247 DEB(printk("sb_dsp_reset() OK\n"));
252 static void dsp_get_vers(sb_devc * devc)
258 DDB(printk("Entered dsp_get_vers()\n"));
259 spin_lock_irqsave(&devc->lock, flags);
260 devc->major = devc->minor = 0;
261 sb_dsp_command(devc, 0xe1); /* Get version */
263 for (i = 100000; i; i--)
265 if (inb(DSP_DATA_AVAIL) & 0x80)
267 if (devc->major == 0)
268 devc->major = inb(DSP_READ);
271 devc->minor = inb(DSP_READ);
276 spin_unlock_irqrestore(&devc->lock, flags);
277 DDB(printk("DSP version %d.%02d\n", devc->major, devc->minor));
280 static int sb16_set_dma_hw(sb_devc * devc)
284 if (devc->dma8 != 0 && devc->dma8 != 1 && devc->dma8 != 3)
286 printk(KERN_ERR "SB16: Invalid 8 bit DMA (%d)\n", devc->dma8);
289 bits = (1 << devc->dma8);
291 if (devc->dma16 >= 5 && devc->dma16 <= 7)
292 bits |= (1 << devc->dma16);
294 sb_setmixer(devc, DMA_NR, bits);
298 static void sb16_set_mpu_port(sb_devc * devc, struct address_info *hw_config)
301 * This routine initializes new MIDI port setup register of SB Vibra (CT2502).
303 unsigned char bits = sb_getmixer(devc, 0x84) & ~0x06;
305 switch (hw_config->io_base)
308 sb_setmixer(devc, 0x84, bits | 0x04);
312 sb_setmixer(devc, 0x84, bits | 0x00);
316 sb_setmixer(devc, 0x84, bits | 0x02); /* Disable MPU */
317 printk(KERN_ERR "SB16: Invalid MIDI I/O port %x\n", hw_config->io_base);
321 static int sb16_set_irq_hw(sb_devc * devc, int level)
340 printk(KERN_ERR "SB16: Invalid IRQ%d\n", level);
343 sb_setmixer(devc, IRQ_NR, ival);
347 static void relocate_Jazz16(sb_devc * devc, struct address_info *hw_config)
349 unsigned char bits = 0;
352 if (jazz16_base != 0 && jazz16_base != hw_config->io_base)
355 switch (hw_config->io_base)
369 bits = jazz16_bits = bits << 5;
370 jazz16_base = hw_config->io_base;
373 * Magic wake up sequence by writing to 0x201 (aka Joystick port)
375 spin_lock_irqsave(&jazz16_lock, flags);
379 spin_unlock_irqrestore(&jazz16_lock, flags);
382 static int init_Jazz16(sb_devc * devc, struct address_info *hw_config)
386 * First try to check that the card has Jazz16 chip. It identifies itself
387 * by returning 0x12 as response to DSP command 0xfa.
390 if (!sb_dsp_command(devc, 0xfa))
393 if (sb_dsp_get_byte(devc) != 0x12)
397 * OK so far. Now configure the IRQ and DMA channel used by the card.
399 if (hw_config->irq < 1 || hw_config->irq > 15 || jazz_irq_bits[hw_config->irq] == 0)
401 printk(KERN_ERR "Jazz16: Invalid interrupt (IRQ%d)\n", hw_config->irq);
404 if (hw_config->dma < 0 || hw_config->dma > 3 || jazz_dma_bits[hw_config->dma] == 0)
406 printk(KERN_ERR "Jazz16: Invalid 8 bit DMA (DMA%d)\n", hw_config->dma);
409 if (hw_config->dma2 < 0)
411 printk(KERN_ERR "Jazz16: No 16 bit DMA channel defined\n");
414 if (hw_config->dma2 < 5 || hw_config->dma2 > 7 || jazz_dma_bits[hw_config->dma2] == 0)
416 printk(KERN_ERR "Jazz16: Invalid 16 bit DMA (DMA%d)\n", hw_config->dma2);
419 devc->dma16 = hw_config->dma2;
421 if (!sb_dsp_command(devc, 0xfb))
424 if (!sb_dsp_command(devc, jazz_dma_bits[hw_config->dma] |
425 (jazz_dma_bits[hw_config->dma2] << 4)))
428 if (!sb_dsp_command(devc, jazz_irq_bits[hw_config->irq]))
432 * Now we have configured a standard Jazz16 device.
434 devc->model = MDL_JAZZ;
435 strcpy(name, "Jazz16");
437 hw_config->name = "Jazz16";
438 devc->caps |= SB_NO_MIDI;
442 static void relocate_ess1688(sb_devc * devc)
461 return; /* Wrong port */
464 DDB(printk("Doing ESS1688 address selection\n"));
467 * ES1688 supports two alternative ways for software address config.
468 * First try the so called Read-Sequence-Key method.
471 /* Reset the sequence logic */
476 /* Perform the read sequence */
485 /* Select the base address by reading from it. Then probe using the port. */
487 if (sb_dsp_reset(devc)) /* Bingo */
490 #if 0 /* This causes system lockups (Nokia 386/25 at least) */
492 * The last resort is the system control register method.
495 outb((0x00), 0xfb); /* 0xFB is the unlock register */
496 outb((0x00), 0xe0); /* Select index 0 */
497 outb((bits), 0xe1); /* Write the config bits */
498 outb((0x00), 0xf9); /* 0xFB is the lock register */
502 int sb_dsp_detect(struct address_info *hw_config, int pci, int pciio, struct sb_module_options *sbmo)
505 sb_devc *devc = &sb_info;
507 memset((char *) &sb_info, 0, sizeof(sb_info)); /* Zero everything */
509 /* Copy module options in place */
510 if(sbmo) memcpy(&devc->sbmo, sbmo, sizeof(struct sb_module_options));
512 sb_info.my_mididev = -1;
513 sb_info.my_mixerdev = -1;
517 * Initialize variables
520 DDB(printk("sb_dsp_detect(%x) entered\n", hw_config->io_base));
521 if (check_region(hw_config->io_base, 16))
524 printk(KERN_INFO "sb: I/O region in use.\n");
529 devc->lock = SPIN_LOCK_UNLOCKED;
530 devc->type = hw_config->card_subtype;
532 devc->base = hw_config->io_base;
533 devc->irq = hw_config->irq;
534 devc->dma8 = hw_config->dma;
537 devc->pcibase = pciio;
539 if(pci == SB_PCI_ESSMAESTRO)
541 devc->model = MDL_ESSPCI;
542 devc->caps |= SB_PCI_IRQ;
543 hw_config->driver_use_1 |= SB_PCI_IRQ;
544 hw_config->card_subtype = MDL_ESSPCI;
547 if(pci == SB_PCI_YAMAHA)
549 devc->model = MDL_YMPCI;
550 devc->caps |= SB_PCI_IRQ;
551 hw_config->driver_use_1 |= SB_PCI_IRQ;
552 hw_config->card_subtype = MDL_YMPCI;
554 printk("Yamaha PCI mode.\n");
561 spin_lock_irqsave(&devc->lock, flags);
562 inb(devc->base + 0x09);
563 inb(devc->base + 0x09);
564 inb(devc->base + 0x09);
565 inb(devc->base + 0x0b);
566 inb(devc->base + 0x09);
567 inb(devc->base + 0x0b);
568 inb(devc->base + 0x09);
569 inb(devc->base + 0x09);
570 inb(devc->base + 0x0b);
571 inb(devc->base + 0x09);
572 inb(devc->base + 0x00);
573 spin_unlock_irqrestore(&devc->lock, flags);
579 if (sb_dsp_reset(devc))
584 if (devc->type == 0 || devc->type == MDL_JAZZ || devc->type == MDL_SMW)
585 if (devc->major == 0 || (devc->major == 3 && devc->minor == 1))
586 relocate_Jazz16(devc, hw_config);
588 if (devc->major == 0 && (devc->type == MDL_ESS || devc->type == 0))
589 relocate_ess1688(devc);
591 if (!sb_dsp_reset(devc))
593 DDB(printk("SB reset failed\n"));
595 printk(KERN_INFO "sb: dsp reset failed.\n");
599 if (devc->major == 0)
602 if (devc->major == 3 && devc->minor == 1)
604 if (devc->type == MDL_AZTECH) /* SG Washington? */
606 if (sb_dsp_command(devc, 0x09))
607 if (sb_dsp_command(devc, 0x00)) /* Enter WSS mode */
611 /* Have some delay */
612 for (i = 0; i < 10000; i++)
614 devc->caps = SB_NO_AUDIO | SB_NO_MIDI; /* Mixer only */
615 devc->model = MDL_AZTECH;
620 if(devc->type == MDL_ESSPCI)
621 devc->model = MDL_ESSPCI;
623 if(devc->type == MDL_YMPCI)
625 printk("YMPCI selected\n");
626 devc->model = MDL_YMPCI;
630 * Save device information for sb_dsp_init()
634 detected_devc = (sb_devc *)kmalloc(sizeof(sb_devc), GFP_KERNEL);
635 if (detected_devc == NULL)
637 printk(KERN_ERR "sb: Can't allocate memory for device information\n");
640 memcpy(detected_devc, devc, sizeof(sb_devc));
641 MDB(printk(KERN_INFO "SB %d.%02d detected OK (%x)\n", devc->major, devc->minor, hw_config->io_base));
645 int sb_dsp_init(struct address_info *hw_config, struct module *owner)
649 extern int sb_be_quiet;
650 int mixer22, mixer30;
653 * Check if we had detected a SB device earlier
655 DDB(printk("sb_dsp_init(%x) entered\n", hw_config->io_base));
658 if (detected_devc == NULL)
660 MDB(printk("No detected device\n"));
663 devc = detected_devc;
664 detected_devc = NULL;
666 if (devc->base != hw_config->io_base)
668 DDB(printk("I/O port mismatch\n"));
672 * Now continue initialization of the device
675 devc->caps = hw_config->driver_use_1;
677 if (!((devc->caps & SB_NO_AUDIO) && (devc->caps & SB_NO_MIDI)) && hw_config->irq > 0)
681 * ESS PCI cards do shared PCI IRQ stuff. Since they
682 * will get shared PCI irq lines we must cope.
685 int i=(devc->caps&SB_PCI_IRQ)?SA_SHIRQ:0;
687 if (request_irq(hw_config->irq, sbintr, i, "soundblaster", devc) < 0)
689 printk(KERN_ERR "SB: Can't allocate IRQ%d\n", hw_config->irq);
694 if (devc->major == 4)
695 if (!sb16_set_irq_hw(devc, devc->irq)) /* Unsupported IRQ */
697 free_irq(devc->irq, devc);
700 if ((devc->type == 0 || devc->type == MDL_ESS) &&
701 devc->major == 3 && devc->minor == 1)
702 { /* Handle various chipsets which claim they are SB Pro compatible */
703 if ((devc->type != 0 && devc->type != MDL_ESS) ||
704 !ess_init(devc, hw_config))
706 if ((devc->type != 0 && devc->type != MDL_JAZZ &&
707 devc->type != MDL_SMW) || !init_Jazz16(devc, hw_config))
709 DDB(printk("This is a genuine SB Pro\n"));
713 if (devc->major == 4 && devc->minor <= 11 ) /* Won't work */
719 for (n = 0; n < 3 && devc->irq_ok == 0; n++)
721 if (sb_dsp_command(devc, 0xf2)) /* Cause interrupt immediately */
725 for (i = 0; !devc->irq_ok && i < 10000; i++);
729 printk(KERN_WARNING "sb: Interrupt test on IRQ%d failed - Probable IRQ conflict\n", devc->irq);
732 DDB(printk("IRQ test OK (IRQ%d)\n", devc->irq));
736 request_region(hw_config->io_base, 16, "soundblaster");
742 case 1: /* SB 1.0 or 1.5 */
743 devc->model = hw_config->card_subtype = MDL_SB1;
747 if (devc->minor == 0)
748 devc->model = hw_config->card_subtype = MDL_SB2;
750 devc->model = hw_config->card_subtype = MDL_SB201;
753 case 3: /* SB Pro and most clones */
754 switch (devc->model) {
756 devc->model = hw_config->card_subtype = MDL_SBPRO;
757 if (hw_config->name == NULL)
758 hw_config->name = "Sound Blaster Pro (8 BIT ONLY)";
761 ess_dsp_init(devc, hw_config);
767 devc->model = hw_config->card_subtype = MDL_SB16;
769 * ALS007 and ALS100 return DSP version 4.2 and have 2 post-reset !=0
770 * registers at 0x3c and 0x4c (output ctrl registers on ALS007) whereas
771 * a "standard" SB16 doesn't have a register at 0x4c. ALS100 actively
772 * updates register 0x22 whenever 0x30 changes, as per the SB16 spec.
773 * Since ALS007 doesn't, this can be used to differentiate the 2 cards.
775 if ((devc->minor == 2) && sb_getmixer(devc,0x3c) && sb_getmixer(devc,0x4c))
777 mixer30 = sb_getmixer(devc,0x30);
778 sb_setmixer(devc,0x22,(mixer22=sb_getmixer(devc,0x22)) & 0x0f);
779 sb_setmixer(devc,0x30,0xff);
780 /* ALS100 will force 0x30 to 0xf8 like SB16; ALS007 will allow 0xff. */
781 /* Register 0x22 & 0xf0 on ALS100 == 0xf0; on ALS007 it == 0x10. */
782 if ((sb_getmixer(devc,0x30) != 0xff) || ((sb_getmixer(devc,0x22) & 0xf0) != 0x10))
784 devc->submodel = SUBMDL_ALS100;
785 if (hw_config->name == NULL)
786 hw_config->name = "Sound Blaster 16 (ALS-100)";
790 sb_setmixer(devc,0x3c,0x1f); /* Enable all inputs */
791 sb_setmixer(devc,0x4c,0x1f);
792 sb_setmixer(devc,0x22,mixer22); /* Restore 0x22 to original value */
793 devc->submodel = SUBMDL_ALS007;
794 if (hw_config->name == NULL)
795 hw_config->name = "Sound Blaster 16 (ALS-007)";
797 sb_setmixer(devc,0x30,mixer30);
799 else if (hw_config->name == NULL)
800 hw_config->name = "Sound Blaster 16";
802 if (hw_config->dma2 == -1)
803 devc->dma16 = devc->dma8;
804 else if (hw_config->dma2 < 5 || hw_config->dma2 > 7)
806 printk(KERN_WARNING "SB16: Bad or missing 16 bit DMA channel\n");
807 devc->dma16 = devc->dma8;
810 devc->dma16 = hw_config->dma2;
812 if(!sb16_set_dma_hw(devc)) {
813 free_irq(devc->irq, devc);
814 release_region(hw_config->io_base, 16);
818 devc->caps |= SB_NO_MIDI;
821 if (!(devc->caps & SB_NO_MIXER))
822 if (devc->major == 3 || devc->major == 4)
823 sb_mixer_init(devc, owner);
825 if (!(devc->caps & SB_NO_MIDI))
826 sb_dsp_midi_init(devc, owner);
828 if (hw_config->name == NULL)
829 hw_config->name = "Sound Blaster (8 BIT/MONO ONLY)";
831 sprintf(name, "%s (%d.%02d)", hw_config->name, devc->major, devc->minor);
832 conf_printf(name, hw_config);
835 * Assuming that a sound card is Sound Blaster (compatible) is the most common
836 * configuration error and the mother of all problems. Usually sound cards
837 * emulate SB Pro but in addition they have a 16 bit native mode which should be
838 * used in Unix. See Readme.cards for more information about configuring OSS/Free
841 if (devc->model <= MDL_SBPRO)
843 if (devc->major == 3 && devc->minor != 1) /* "True" SB Pro should have v3.1 (rare ones may have 3.2). */
845 printk(KERN_INFO "This sound card may not be fully Sound Blaster Pro compatible.\n");
846 printk(KERN_INFO "In many cases there is another way to configure OSS so that\n");
847 printk(KERN_INFO "it works properly with OSS (for example in 16 bit mode).\n");
848 printk(KERN_INFO "Please ignore this message if you _really_ have a SB Pro.\n");
850 else if (!sb_be_quiet && devc->model == MDL_SBPRO)
852 printk(KERN_INFO "SB DSP version is just %d.%02d which means that your card is\n", devc->major, devc->minor);
853 printk(KERN_INFO "several years old (8 bit only device) or alternatively the sound driver\n");
854 printk(KERN_INFO "is incorrectly configured.\n");
857 hw_config->card_subtype = devc->model;
858 hw_config->slots[0]=devc->dev;
859 last_devc = devc; /* For SB MPU detection */
861 if (!(devc->caps & SB_NO_AUDIO) && devc->dma8 >= 0)
863 if (sound_alloc_dma(devc->dma8, "SoundBlaster8"))
865 printk(KERN_WARNING "Sound Blaster: Can't allocate 8 bit DMA channel %d\n", devc->dma8);
867 if (devc->dma16 >= 0 && devc->dma16 != devc->dma8)
869 if (sound_alloc_dma(devc->dma16, "SoundBlaster16"))
870 printk(KERN_WARNING "Sound Blaster: can't allocate 16 bit DMA channel %d.\n", devc->dma16);
872 sb_audio_init(devc, name, owner);
873 hw_config->slots[0]=devc->dev;
877 MDB(printk("Sound Blaster: no audio devices found.\n"));
882 void sb_dsp_disable_midi(int io_base)
886 void sb_dsp_disable_recording(int io_base)
890 /* if (sbmpu) below we allow mpu401 to manage the midi devs
891 otherwise we have to unload them. (Andrzej Krzysztofowicz) */
893 void sb_dsp_unload(struct address_info *hw_config, int sbmpu)
897 devc = audio_devs[hw_config->slots[0]]->devc;
899 if (devc && devc->base == hw_config->io_base)
901 if ((devc->model & MDL_ESS) && devc->pcibase)
902 release_region(devc->pcibase, 8);
904 release_region(devc->base, 16);
906 if (!(devc->caps & SB_NO_AUDIO))
908 sound_free_dma(devc->dma8);
909 if (devc->dma16 >= 0)
910 sound_free_dma(devc->dma16);
912 if (!(devc->caps & SB_NO_AUDIO && devc->caps & SB_NO_MIDI))
915 free_irq(devc->irq, devc);
917 sb_mixer_unload(devc);
918 /* We don't have to do this bit any more the UART401 is its own
919 master -- Krzysztof Halasa */
920 /* But we have to do it, if UART401 is not detected */
922 sound_unload_mididev(devc->my_mididev);
923 sound_unload_audiodev(devc->dev);
928 release_region(hw_config->io_base, 16);
930 kfree(detected_devc);
934 * Mixer access routines
936 * ES1887 modifications: some mixer registers reside in the
937 * range above 0xa0. These must be accessed in another way.
940 void sb_setmixer(sb_devc * devc, unsigned int port, unsigned int value)
944 if (devc->model == MDL_ESS) return ess_setmixer (devc, port, value);
946 spin_lock_irqsave(&devc->lock, flags);
948 outb(((unsigned char) (port & 0xff)), MIXER_ADDR);
950 outb(((unsigned char) (value & 0xff)), MIXER_DATA);
953 spin_unlock_irqrestore(&devc->lock, flags);
956 unsigned int sb_getmixer(sb_devc * devc, unsigned int port)
961 if (devc->model == MDL_ESS) return ess_getmixer (devc, port);
963 spin_lock_irqsave(&devc->lock, flags);
965 outb(((unsigned char) (port & 0xff)), MIXER_ADDR);
967 val = inb(MIXER_DATA);
970 spin_unlock_irqrestore(&devc->lock, flags);
976 (sb_devc * devc, unsigned int reg, unsigned int mask, unsigned int val)
980 value = sb_getmixer(devc, reg);
981 value = (value & ~mask) | (val & mask);
982 sb_setmixer(devc, reg, value);
986 * MPU401 MIDI initialization.
989 static void smw_putmem(sb_devc * devc, int base, int addr, unsigned char val)
993 spin_lock_irqsave(&jazz16_lock, flags); /* NOT the SB card? */
995 outb((addr & 0xff), base + 1); /* Low address bits */
996 outb((addr >> 8), base + 2); /* High address bits */
997 outb((val), base); /* Data */
999 spin_unlock_irqrestore(&jazz16_lock, flags);
1002 static unsigned char smw_getmem(sb_devc * devc, int base, int addr)
1004 unsigned long flags;
1007 spin_lock_irqsave(&jazz16_lock, flags); /* NOT the SB card? */
1009 outb((addr & 0xff), base + 1); /* Low address bits */
1010 outb((addr >> 8), base + 2); /* High address bits */
1011 val = inb(base); /* Data */
1013 spin_unlock_irqrestore(&jazz16_lock, flags);
1017 static int smw_midi_init(sb_devc * devc, struct address_info *hw_config)
1019 int mpu_base = hw_config->io_base;
1020 int mp_base = mpu_base + 4; /* Microcontroller base */
1022 unsigned char control;
1026 * Reset the microcontroller so that the RAM can be accessed
1029 control = inb(mpu_base + 7);
1030 outb((control | 3), mpu_base + 7); /* Set last two bits to 1 (?) */
1031 outb(((control & 0xfe) | 2), mpu_base + 7); /* xxxxxxx0 resets the mc */
1033 mdelay(3); /* Wait at least 1ms */
1035 outb((control & 0xfc), mpu_base + 7); /* xxxxxx00 enables RAM */
1038 * Detect microcontroller by probing the 8k RAM area
1040 smw_putmem(devc, mp_base, 0, 0x00);
1041 smw_putmem(devc, mp_base, 1, 0xff);
1044 if (smw_getmem(devc, mp_base, 0) != 0x00 || smw_getmem(devc, mp_base, 1) != 0xff)
1046 DDB(printk("SM Wave: No microcontroller RAM detected (%02x, %02x)\n", smw_getmem(devc, mp_base, 0), smw_getmem(devc, mp_base, 1)));
1047 return 0; /* No RAM */
1050 * There is RAM so assume it's really a SM Wave
1053 devc->model = MDL_SMW;
1054 smw_mixer_init(devc);
1059 smw_ucodeLen = mod_firmware_load("/etc/sound/midi0001.bin", (void *) &smw_ucode);
1060 smw_free = smw_ucode;
1063 if (smw_ucodeLen > 0)
1065 if (smw_ucodeLen != 8192)
1067 printk(KERN_ERR "SM Wave: Invalid microcode (MIDI0001.BIN) length\n");
1071 * Download microcode
1074 for (i = 0; i < 8192; i++)
1075 smw_putmem(devc, mp_base, i, smw_ucode[i]);
1081 for (i = 0; i < 8192; i++)
1082 if (smw_getmem(devc, mp_base, i) != smw_ucode[i])
1084 printk(KERN_ERR "SM Wave: Microcode verification failed\n");
1091 * Set the SCSI interrupt (IRQ2/9, IRQ3 or IRQ10). The SCSI interrupt
1092 * is disabled by default.
1094 * FIXME - make this a module option
1096 * BTW the Zilog 5380 SCSI controller is located at MPU base + 0x10.
1099 static unsigned char scsi_irq_bits[] = {
1100 0, 0, 3, 1, 0, 0, 0, 0, 0, 3, 2, 0, 0, 0, 0, 0
1102 control |= scsi_irq_bits[SMW_SCSI_IRQ] << 6;
1106 #ifdef SMW_OPL4_ENABLE
1108 * Make the OPL4 chip visible on the PC bus at 0x380.
1110 * There is no need to enable this feature since this driver
1111 * doesn't support OPL4 yet. Also there is no RAM in SM Wave so
1112 * enabling OPL4 is pretty useless.
1114 control |= 0x10; /* Uses IRQ12 if bit 0x20 == 0 */
1115 /* control |= 0x20; Uncomment this if you want to use IRQ7 */
1117 outb((control | 0x03), mpu_base + 7); /* xxxxxx11 restarts */
1118 hw_config->name = "SoundMan Wave";
1122 static int init_Jazz16_midi(sb_devc * devc, struct address_info *hw_config)
1124 int mpu_base = hw_config->io_base;
1125 int sb_base = devc->base;
1126 int irq = hw_config->irq;
1128 unsigned char bits = 0;
1129 unsigned long flags;
1134 if (irq < 1 || irq > 15 ||
1135 jazz_irq_bits[irq] == 0)
1137 printk(KERN_ERR "Jazz16: Invalid MIDI interrupt (IRQ%d)\n", irq);
1154 bits = jazz16_bits = bits << 5;
1167 printk(KERN_ERR "Jazz16: Invalid MIDI I/O port %x\n", mpu_base);
1171 * Magic wake up sequence by writing to 0x201 (aka Joystick port)
1173 spin_lock_irqsave(&jazz16_lock, flags);
1177 spin_unlock_irqrestore(&jazz16_lock, flags);
1179 hw_config->name = "Jazz16";
1180 smw_midi_init(devc, hw_config);
1182 if (!sb_dsp_command(devc, 0xfb))
1185 if (!sb_dsp_command(devc, jazz_dma_bits[devc->dma8] |
1186 (jazz_dma_bits[devc->dma16] << 4)))
1189 if (!sb_dsp_command(devc, jazz_irq_bits[devc->irq] |
1190 (jazz_irq_bits[irq] << 4)))
1196 int probe_sbmpu(struct address_info *hw_config, struct module *owner)
1198 sb_devc *devc = last_devc;
1201 if (last_devc == NULL)
1206 if (hw_config->io_base <= 0)
1208 /* The real vibra16 is fine about this, but we have to go
1209 wipe up after Cyrix again */
1211 if(devc->model == MDL_SB16 && devc->minor >= 12)
1213 unsigned char bits = sb_getmixer(devc, 0x84) & ~0x06;
1214 sb_setmixer(devc, 0x84, bits | 0x02); /* Disable MPU */
1219 #if defined(CONFIG_SOUND_MPU401)
1220 if (devc->model == MDL_ESS)
1222 if (check_region(hw_config->io_base, 2))
1224 printk(KERN_ERR "sbmpu: I/O port conflict (%x)\n", hw_config->io_base);
1227 if (!ess_midi_init(devc, hw_config))
1229 hw_config->name = "ESS1xxx MPU";
1230 devc->midi_irq_cookie = NULL;
1231 if (!probe_mpu401(hw_config))
1233 attach_mpu401(hw_config, owner);
1234 if (last_sb->irq == -hw_config->irq)
1235 last_sb->midi_irq_cookie=(void *)hw_config->slots[1];
1240 switch (devc->model)
1243 if (hw_config->io_base != 0x300 && hw_config->io_base != 0x330)
1245 printk(KERN_ERR "SB16: Invalid MIDI port %x\n", hw_config->io_base);
1248 hw_config->name = "Sound Blaster 16";
1249 if (hw_config->irq < 3 || hw_config->irq == devc->irq)
1250 hw_config->irq = -devc->irq;
1251 if (devc->minor > 12) /* What is Vibra's version??? */
1252 sb16_set_mpu_port(devc, hw_config);
1256 if (hw_config->irq < 3 || hw_config->irq == devc->irq)
1257 hw_config->irq = -devc->irq;
1258 if (!init_Jazz16_midi(devc, hw_config))
1263 hw_config->name = "Yamaha PCI Legacy";
1264 printk("Yamaha PCI legacy UART401 check.\n");
1270 ret = probe_uart401(hw_config, owner);
1272 last_sb->midi_irq_cookie=midi_devs[hw_config->slots[4]]->devc;
1276 void unload_sbmpu(struct address_info *hw_config)
1278 #if defined(CONFIG_SOUND_MPU401)
1279 if (!strcmp (hw_config->name, "ESS1xxx MPU")) {
1280 unload_mpu401(hw_config);
1284 unload_uart401(hw_config);
1287 EXPORT_SYMBOL(sb_dsp_init);
1288 EXPORT_SYMBOL(sb_dsp_detect);
1289 EXPORT_SYMBOL(sb_dsp_unload);
1290 EXPORT_SYMBOL(sb_dsp_disable_midi);
1291 EXPORT_SYMBOL(sb_be_quiet);
1292 EXPORT_SYMBOL(probe_sbmpu);
1293 EXPORT_SYMBOL(unload_sbmpu);
1294 EXPORT_SYMBOL(smw_free);
1295 MODULE_LICENSE("GPL");