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 #include <linux/config.h>
15 #include <linux/delay.h>
18 #include "sound_config.h"
19 #include "sound_firmware.h"
24 #error You will need to configure the sound driver with CONFIG_AUDIO option.
30 static sb_devc
*detected_devc
= NULL
; /* For communication from probe to init */
31 static sb_devc
*last_devc
= NULL
; /* For MPU401 initialization */
33 static unsigned char jazz_irq_bits
[] = {
34 0, 0, 2, 3, 0, 1, 0, 4, 0, 2, 5, 0, 0, 0, 0, 6
37 static unsigned char jazz_dma_bits
[] = {
38 0, 1, 0, 2, 0, 3, 0, 4
42 * Jazz16 chipset specific control variables
45 static int jazz16_base
= 0; /* Not detected */
46 static unsigned char jazz16_bits
= 0; /* I/O relocation bits */
49 * Logitech Soundman Wave specific initialization code
52 #ifdef SMW_MIDI0001_INCLUDED
53 #include "smw-midi0001.h"
55 static unsigned char *smw_ucode
= NULL
;
56 static int smw_ucodeLen
= 0;
60 sb_devc
*last_sb
= NULL
; /* Last sb loaded */
62 int sb_dsp_command(sb_devc
* devc
, unsigned char val
)
67 limit
= jiffies
+ HZ
/ 10; /* Timeout */
70 * Note! the i<500000 is an emergency exit. The sb_dsp_command() is sometimes
71 * called while interrupts are disabled. This means that the timer is
72 * disabled also. However the timeout situation is a abnormal condition.
73 * Normally the DSP should be ready to accept commands after just couple of
77 for (i
= 0; i
< 500000 && (limit
-jiffies
)>0; i
++)
79 if ((inb(DSP_STATUS
) & 0x80) == 0)
81 outb((val
), DSP_COMMAND
);
85 printk(KERN_WARNING
"Sound Blaster: DSP command(%x) timeout.\n", val
);
89 static int sb_dsp_get_byte(sb_devc
* devc
)
93 for (i
= 1000; i
; i
--)
95 if (inb(DSP_DATA_AVAIL
) & 0x80)
101 int ess_write(sb_devc
* devc
, unsigned char reg
, unsigned char data
)
103 /* Write a byte to an extended mode register of ES1688 */
105 if (!sb_dsp_command(devc
, reg
))
108 return sb_dsp_command(devc
, data
);
111 int ess_read(sb_devc
* devc
, unsigned char reg
)
113 /* Read a byte from an extended mode register of ES1688 */
114 if (!sb_dsp_command(devc
, 0xc0)) /* Read register command */
117 if (!sb_dsp_command(devc
, reg
))
120 return sb_dsp_get_byte(devc
);
123 static void sbintr(int irq
, void *dev_id
, struct pt_regs
*dummy
)
126 unsigned char src
= 0xff;
128 sb_devc
*devc
= dev_id
;
131 if (devc
->model
== MDL_SB16
)
133 src
= sb_getmixer(devc
, IRQ_STAT
); /* Interrupt source register */
135 #if defined(CONFIG_MIDI)&& defined(CONFIG_UART401)
137 uart401intr(devc
->irq
, devc
->midi_irq_cookie
, NULL
); /* MPU401 interrupt */
141 return; /* Not a DSP interrupt */
143 if (devc
->intr_active
)
145 switch (devc
->irq_mode
)
148 DMAbuf_outputintr(devc
->dev
, 1);
152 DMAbuf_inputintr(devc
->dev
);
160 sb_midi_interrupt(devc
);
165 /* printk(KERN_WARN "Sound Blaster: Unexpected interrupt\n"); */
170 * Acknowledge interrupts
174 status
= inb(DSP_DATA_AVAIL
);
176 if (devc
->model
== MDL_SB16
&& src
& 0x02)
177 status
= inb(DSP_DATA_AVL16
);
181 int sb_dsp_reset(sb_devc
* devc
)
185 DEB(printk("Entered sb_dsp_reset()\n"));
187 if (devc
->model
== MDL_ESS
)
188 outb(3, DSP_RESET
); /* Reset FIFO too */
196 for (loopc
= 0; loopc
< 1000 && !(inb(DSP_DATA_AVAIL
) & 0x80); loopc
++);
198 if (inb(DSP_READ
) != 0xAA)
200 DDB(printk("sb: No response to RESET\n"));
201 return 0; /* Sorry */
203 if (devc
->model
== MDL_ESS
)
204 sb_dsp_command(devc
, 0xc6); /* Enable extended mode */
206 DEB(printk("sb_dsp_reset() OK\n"));
210 static void dsp_get_vers(sb_devc
* devc
)
216 DDB(printk("Entered dsp_get_vers()\n"));
219 devc
->major
= devc
->minor
= 0;
220 sb_dsp_command(devc
, 0xe1); /* Get version */
222 for (i
= 100000; i
; i
--)
224 if (inb(DSP_DATA_AVAIL
) & 0x80)
226 if (devc
->major
== 0)
227 devc
->major
= inb(DSP_READ
);
230 devc
->minor
= inb(DSP_READ
);
235 DDB(printk("DSP version %d.%d\n", devc
->major
, devc
->minor
));
236 restore_flags(flags
);
239 static int sb16_set_dma_hw(sb_devc
* devc
)
243 if (devc
->dma8
!= 0 && devc
->dma8
!= 1 && devc
->dma8
!= 3)
245 printk(KERN_ERR
"SB16: Invalid 8 bit DMA (%d)\n", devc
->dma8
);
248 bits
= (1 << devc
->dma8
);
250 if (devc
->dma16
>= 5 && devc
->dma16
<= 7)
251 bits
|= (1 << devc
->dma16
);
253 sb_setmixer(devc
, DMA_NR
, bits
);
257 #if defined(CONFIG_MIDI) && defined(CONFIG_UART401)
258 static void sb16_set_mpu_port(sb_devc
* devc
, struct address_info
*hw_config
)
261 * This routine initializes new MIDI port setup register of SB Vibra (CT2502).
263 unsigned char bits
= sb_getmixer(devc
, 0x84) & ~0x06;
265 switch (hw_config
->io_base
)
268 sb_setmixer(devc
, 0x84, bits
| 0x04);
272 sb_setmixer(devc
, 0x84, bits
| 0x00);
276 sb_setmixer(devc
, 0x84, bits
| 0x02); /* Disable MPU */
277 printk(KERN_ERR
"SB16: Invalid MIDI I/O port %x\n", hw_config
->io_base
);
282 static int sb16_set_irq_hw(sb_devc
* devc
, int level
)
301 printk(KERN_ERR
"SB16: Invalid IRQ%d\n", level
);
304 sb_setmixer(devc
, IRQ_NR
, ival
);
308 static void relocate_Jazz16(sb_devc
* devc
, struct address_info
*hw_config
)
310 unsigned char bits
= 0;
313 if (jazz16_base
!= 0 && jazz16_base
!= hw_config
->io_base
)
316 switch (hw_config
->io_base
)
330 bits
= jazz16_bits
= bits
<< 5;
331 jazz16_base
= hw_config
->io_base
;
334 * Magic wake up sequence by writing to 0x201 (aka Joystick port)
341 restore_flags(flags
);
344 static int init_Jazz16(sb_devc
* devc
, struct address_info
*hw_config
)
348 * First try to check that the card has Jazz16 chip. It identifies itself
349 * by returning 0x12 as response to DSP command 0xfa.
352 if (!sb_dsp_command(devc
, 0xfa))
355 if (sb_dsp_get_byte(devc
) != 0x12)
359 * OK so far. Now configure the IRQ and DMA channel used by the card.
361 if (hw_config
->irq
< 1 || hw_config
->irq
> 15 || jazz_irq_bits
[hw_config
->irq
] == 0)
363 printk(KERN_ERR
"Jazz16: Invalid interrupt (IRQ%d)\n", hw_config
->irq
);
366 if (hw_config
->dma
< 0 || hw_config
->dma
> 3 || jazz_dma_bits
[hw_config
->dma
] == 0)
368 printk(KERN_ERR
"Jazz16: Invalid 8 bit DMA (DMA%d)\n", hw_config
->dma
);
371 if (hw_config
->dma2
< 0)
373 printk(KERN_ERR
"Jazz16: No 16 bit DMA channel defined\n");
376 if (hw_config
->dma2
< 5 || hw_config
->dma2
> 7 || jazz_dma_bits
[hw_config
->dma2
] == 0)
378 printk(KERN_ERR
"Jazz16: Invalid 16 bit DMA (DMA%d)\n", hw_config
->dma2
);
381 devc
->dma16
= hw_config
->dma2
;
383 if (!sb_dsp_command(devc
, 0xfb))
386 if (!sb_dsp_command(devc
, jazz_dma_bits
[hw_config
->dma
] |
387 (jazz_dma_bits
[hw_config
->dma2
] << 4)))
390 if (!sb_dsp_command(devc
, jazz_irq_bits
[hw_config
->irq
]))
394 * Now we have configured a standard Jazz16 device.
396 devc
->model
= MDL_JAZZ
;
397 strcpy(name
, "Jazz16");
399 hw_config
->name
= "Jazz16";
400 devc
->caps
|= SB_NO_MIDI
;
404 static void relocate_ess1688(sb_devc
* devc
)
423 return; /* Wrong port */
426 DDB(printk("Doing ESS1688 address selection\n"));
429 * ES1688 supports two alternative ways for software address config.
430 * First try the so called Read-Sequence-Key method.
433 /* Reset the sequence logic */
438 /* Perform the read sequence */
447 /* Select the base address by reading from it. Then probe using the port. */
449 if (sb_dsp_reset(devc
)) /* Bingo */
452 #if 0 /* This causes system lockups (Nokia 386/25 at least) */
454 * The last resort is the system control register method.
457 outb((0x00), 0xfb); /* 0xFB is the unlock register */
458 outb((0x00), 0xe0); /* Select index 0 */
459 outb((bits
), 0xe1); /* Write the config bits */
460 outb((0x00), 0xf9); /* 0xFB is the lock register */
464 static int ess_init(sb_devc
* devc
, struct address_info
*hw_config
)
466 unsigned char cfg
, irq_bits
= 0, dma_bits
= 0;
467 int ess_major
= 0, ess_minor
= 0;
469 static char name
[100];
472 * Try to detect ESS chips.
475 sb_dsp_command(devc
, 0xe7); /* Return identification */
477 for (i
= 1000; i
; i
--)
479 if (inb(DSP_DATA_AVAIL
) & 0x80)
482 ess_major
= inb(DSP_READ
);
485 ess_minor
= inb(DSP_READ
);
494 if (ess_major
== 0x48 && (ess_minor
& 0xf0) == 0x80)
496 sprintf(name
, "ESS ES488 AudioDrive (rev %d)",
498 hw_config
->name
= name
;
499 devc
->model
= MDL_SBPRO
;
502 else if (ess_major
== 0x68 && (ess_minor
& 0xf0) == 0x80)
504 char *chip
= "ES688";
506 if ((ess_minor
& 0x0f) >= 8)
509 sprintf(name
,"ESS %s AudioDrive (rev %d)",
510 chip
, ess_minor
& 0x0f);
513 strcpy(name
, "Jazz16");
515 devc
->model
= MDL_ESS
;
516 devc
->submodel
= ess_minor
& 0x0f;
517 hw_config
->name
= name
;
518 sb_dsp_reset(devc
); /* Turn on extended mode */
521 * Set IRQ configuration register
524 cfg
= 0x50; /* Enable only DMA counter interrupt */
547 cfg
= 0x10; /* Disable all interrupts */
548 printk(KERN_ERR
"ESS1688: Invalid IRQ %d\n", devc
->irq
);
552 if (!ess_write(devc
, 0xb1, cfg
| (irq_bits
<< 2)))
553 printk(KERN_ERR
"ESS1688: Failed to write to IRQ config register\n");
556 * Set DMA configuration register
559 cfg
= 0x50; /* Extended mode DMA enable */
561 if (devc
->dma8
> 3 || devc
->dma8
< 0 || devc
->dma8
== 2)
564 cfg
= 0x00; /* Disable all DMA */
565 printk(KERN_ERR
"ESS1688: Invalid DMA %d\n", devc
->dma8
);
572 dma_bits
= devc
->dma8
+ 1;
575 if (!ess_write(devc
, 0xb2, cfg
| (dma_bits
<< 2)))
576 printk(KERN_ERR
"ESS1688: Failed to write to DMA config register\n");
579 * Enable joystick and OPL3
582 cfg
= sb_getmixer(devc
, 0x40);
583 sb_setmixer(devc
, 0x40, cfg
| 0x03);
584 if (devc
->submodel
>= 8) /* ES1688 */
585 devc
->caps
|= SB_NO_MIDI
; /* ES1688 uses MPU401 MIDI mode */
590 int sb_dsp_detect(struct address_info
*hw_config
)
593 sb_devc
*devc
= &sb_info
;
595 sb_info
.my_mididev
= -1;
596 sb_info
.my_mixerdev
= -1;
600 * Initialize variables
603 DDB(printk("sb_dsp_detect(%x) entered\n", hw_config
->io_base
));
604 if (check_region(hw_config
->io_base
, 16))
607 printk(KERN_INFO
"sb: I/O region in use.\n");
611 memset((char *) &sb_info
, 0, sizeof(sb_info
)); /* Zero everything */
613 devc
->type
= hw_config
->card_subtype
;
615 devc
->base
= hw_config
->io_base
;
616 devc
->irq
= hw_config
->irq
;
617 devc
->dma8
= hw_config
->dma
;
624 inb(devc
->base
+ 0x09);
625 inb(devc
->base
+ 0x09);
626 inb(devc
->base
+ 0x09);
627 inb(devc
->base
+ 0x0b);
628 inb(devc
->base
+ 0x09);
629 inb(devc
->base
+ 0x0b);
630 inb(devc
->base
+ 0x09);
631 inb(devc
->base
+ 0x09);
632 inb(devc
->base
+ 0x0b);
633 inb(devc
->base
+ 0x09);
634 inb(devc
->base
+ 0x00);
641 if (sb_dsp_reset(devc
))
646 if (devc
->type
== 0 || devc
->type
== MDL_JAZZ
|| devc
->type
== MDL_SMW
)
647 if (devc
->major
== 0 || (devc
->major
== 3 && devc
->minor
== 1))
648 relocate_Jazz16(devc
, hw_config
);
650 if (devc
->major
== 0 && (devc
->type
== MDL_ESS
|| devc
->type
== 0))
651 relocate_ess1688(devc
);
653 if (!sb_dsp_reset(devc
))
655 DDB(printk("SB reset failed\n"));
657 printk(KERN_INFO
"sb: dsp reset failed.\n");
661 if (devc
->major
== 0)
664 if (devc
->major
== 3 && devc
->minor
== 1)
666 if (devc
->type
== MDL_AZTECH
) /* SG Washington? */
668 if (sb_dsp_command(devc
, 0x09))
669 if (sb_dsp_command(devc
, 0x00)) /* Enter WSS mode */
673 /* Have some delay */
674 for (i
= 0; i
< 10000; i
++)
676 devc
->caps
= SB_NO_AUDIO
| SB_NO_MIDI
; /* Mixer only */
677 devc
->model
= MDL_AZTECH
;
682 * Save device information for sb_dsp_init()
686 detected_devc
= (sb_devc
*)kmalloc(sizeof(sb_devc
), GFP_KERNEL
);
687 if (detected_devc
== NULL
)
689 printk(KERN_ERR
"sb: Can't allocate memory for device information\n");
692 memcpy((char *) detected_devc
, (char *) devc
, sizeof(sb_devc
));
693 MDB(printk("SB %d.%d detected OK (%x)\n", devc
->major
, devc
->minor
, hw_config
->io_base
));
697 int sb_dsp_init(struct address_info
*hw_config
)
701 extern int sb_be_quiet
;
702 int mixer22
, mixer30
;
705 * Check if we had detected a SB device earlier
707 DDB(printk("sb_dsp_init(%x) entered\n", hw_config
->io_base
));
710 if (detected_devc
== NULL
)
712 MDB(printk("No detected device\n"));
715 devc
= detected_devc
;
716 detected_devc
= NULL
;
718 if (devc
->base
!= hw_config
->io_base
)
720 DDB(printk("I/O port mismatch\n"));
724 * Now continue initialization of the device
727 devc
->caps
= hw_config
->driver_use_1
;
729 if (!(devc
->caps
& SB_NO_AUDIO
&& devc
->caps
& SB_NO_MIDI
) && hw_config
->irq
> 0)
731 if (request_irq(hw_config
->irq
, sbintr
, 0, "soundblaster", devc
) < 0)
733 printk(KERN_ERR
"SB: Can't allocate IRQ%d\n", hw_config
->irq
);
738 if (devc
->major
== 4)
739 if (!sb16_set_irq_hw(devc
, devc
->irq
)) /* Unsupported IRQ */
741 free_irq(devc
->irq
, devc
);
744 if ((devc
->type
== 0 || devc
->type
== MDL_ESS
) &&
745 devc
->major
== 3 && devc
->minor
== 1)
746 { /* Handle various chipsets which claim they are SB Pro compatible */
747 if ((devc
->type
!= 0 && devc
->type
!= MDL_ESS
) ||
748 !ess_init(devc
, hw_config
))
750 if ((devc
->type
!= 0 && devc
->type
!= MDL_JAZZ
&&
751 devc
->type
!= MDL_SMW
) || !init_Jazz16(devc
, hw_config
))
753 DDB(printk("This is a genuine SB Pro\n"));
758 /* Skip IRQ detection if SMP (doesn't work) */
761 if (devc
->major
== 4 && devc
->minor
<= 11 ) /* Won't work */
767 for (n
= 0; n
< 3 && devc
->irq_ok
== 0; n
++)
769 if (sb_dsp_command(devc
, 0xf2)) /* Cause interrupt immediately */
773 for (i
= 0; !devc
->irq_ok
&& i
< 10000; i
++);
777 printk(KERN_WARNING
"sb: Interrupt test on IRQ%d failed - Probable IRQ conflict\n", devc
->irq
);
780 DDB(printk("IRQ test OK (IRQ%d)\n", devc
->irq
));
785 request_region(hw_config
->io_base
, 16, "soundblaster");
791 case 1: /* SB 1.0 or 1.5 */
792 devc
->model
= hw_config
->card_subtype
= MDL_SB1
;
796 if (devc
->minor
== 0)
797 devc
->model
= hw_config
->card_subtype
= MDL_SB2
;
799 devc
->model
= hw_config
->card_subtype
= MDL_SB201
;
802 case 3: /* SB Pro and most clones */
803 if (devc
->model
== 0)
805 devc
->model
= hw_config
->card_subtype
= MDL_SBPRO
;
806 if (hw_config
->name
== NULL
)
807 hw_config
->name
= "Sound Blaster Pro (8 BIT ONLY)";
812 devc
->model
= hw_config
->card_subtype
= MDL_SB16
;
814 * ALS007 and ALS100 return DSP version 4.2 and have 2 post-reset !=0
815 * registers at 0x3c and 0x4c (output ctrl registers on ALS007) whereas
816 * a "standard" SB16 doesn't have a register at 0x4c. ALS100 actively
817 * updates register 0x22 whenever 0x30 changes, as per the SB16 spec.
818 * Since ALS007 doesn't, this can be used to differentiate the 2 cards.
820 if ((devc
->minor
== 2) && sb_getmixer(devc
,0x3c) && sb_getmixer(devc
,0x4c))
822 mixer30
= sb_getmixer(devc
,0x30);
823 sb_setmixer(devc
,0x22,(mixer22
=sb_getmixer(devc
,0x22)) & 0x0f);
824 sb_setmixer(devc
,0x30,0xff);
825 /* ALS100 will force 0x30 to 0xf8 like SB16; ALS007 will allow 0xff. */
826 /* Register 0x22 & 0xf0 on ALS100 == 0xf0; on ALS007 it == 0x10. */
827 if ((sb_getmixer(devc
,0x30) != 0xff) || ((sb_getmixer(devc
,0x22) & 0xf0) != 0x10))
829 if (hw_config
->name
== NULL
)
830 hw_config
->name
= "Sound Blaster 16 (ALS-100)";
834 sb_setmixer(devc
,0x3c,0x1f); /* Enable all inputs */
835 sb_setmixer(devc
,0x4c,0x1f);
836 sb_setmixer(devc
,0x22,mixer22
); /* Restore 0x22 to original value */
837 devc
->submodel
= SUBMDL_ALS007
;
838 if (hw_config
->name
== NULL
)
839 hw_config
->name
= "Sound Blaster 16 (ALS-007)";
841 sb_setmixer(devc
,0x30,mixer30
);
843 else if (hw_config
->name
== NULL
)
844 hw_config
->name
= "Sound Blaster 16";
846 if (hw_config
->dma2
== -1)
847 devc
->dma16
= devc
->dma8
;
848 else if (hw_config
->dma2
< 5 || hw_config
->dma2
> 7)
850 printk(KERN_WARNING
"SB16: Bad or missing 16 bit DMA channel\n");
851 devc
->dma16
= devc
->dma8
;
854 devc
->dma16
= hw_config
->dma2
;
856 if(!sb16_set_dma_hw(devc
)) {
857 free_irq(devc
->irq
, devc
);
861 devc
->caps
|= SB_NO_MIDI
;
864 if (!(devc
->caps
& SB_NO_MIXER
))
865 if (devc
->major
== 3 || devc
->major
== 4)
869 if (!(devc
->caps
& SB_NO_MIDI
))
870 sb_dsp_midi_init(devc
);
873 if (hw_config
->name
== NULL
)
874 hw_config
->name
= "Sound Blaster (8 BIT/MONO ONLY)";
876 sprintf(name
, "%s (%d.%d)", hw_config
->name
, devc
->major
, devc
->minor
);
877 conf_printf(name
, hw_config
);
880 * Assuming that a sound card is Sound Blaster (compatible) is the most common
881 * configuration error and the mother of all problems. Usually sound cards
882 * emulate SB Pro but in addition they have a 16 bit native mode which should be
883 * used in Unix. See Readme.cards for more information about configuring OSS/Free
886 if (devc
->model
<= MDL_SBPRO
)
888 if (devc
->major
== 3 && devc
->minor
!= 1) /* "True" SB Pro should have v3.1 (rare ones may have 3.2). */
890 printk(KERN_INFO
"This sound card may not be fully Sound Blaster Pro compatible.\n");
891 printk(KERN_INFO
"In many cases there is another way to configure OSS so that\n");
892 printk(KERN_INFO
"it works properly with OSS (for example in 16 bit mode).\n");
893 printk(KERN_INFO
"Please ignore this message if you _really_ have a SB Pro.\n");
895 else if (!sb_be_quiet
&& devc
->model
== MDL_SBPRO
)
897 printk(KERN_INFO
"SB DSP version is just %d.%d which means that your card is\n", devc
->major
, devc
->minor
);
898 printk(KERN_INFO
"several years old (8 bit only device) or alternatively the sound driver\n");
899 printk(KERN_INFO
"is incorrectly configured.\n");
902 hw_config
->card_subtype
= devc
->model
;
903 hw_config
->slots
[0]=devc
->dev
;
904 last_devc
= devc
; /* For SB MPU detection */
906 if (!(devc
->caps
& SB_NO_AUDIO
) && devc
->dma8
>= 0)
908 if (sound_alloc_dma(devc
->dma8
, "SoundBlaster8"))
910 printk(KERN_WARNING
"Sound Blaster: Can't allocate 8 bit DMA channel %d\n", devc
->dma8
);
912 if (devc
->dma16
>= 0 && devc
->dma16
!= devc
->dma8
)
914 if (sound_alloc_dma(devc
->dma16
, "SoundBlaster16"))
915 printk(KERN_WARNING
"Sound Blaster: can't allocate 16 bit DMA channel %d.\n", devc
->dma16
);
917 sb_audio_init(devc
, name
);
918 hw_config
->slots
[0]=devc
->dev
;
922 MDB(printk("Sound Blaster: no audio devices found.\n"));
927 void sb_dsp_disable_midi(int io_base
)
931 void sb_dsp_disable_recording(int io_base
)
935 void sb_dsp_unload(struct address_info
*hw_config
)
939 devc
= audio_devs
[hw_config
->slots
[0]]->devc
;
941 if (devc
&& devc
->base
== hw_config
->io_base
)
943 release_region(devc
->base
, 16);
945 if (!(devc
->caps
& SB_NO_AUDIO
))
947 sound_free_dma(devc
->dma8
);
948 if (devc
->dma16
>= 0)
949 sound_free_dma(devc
->dma16
);
951 if (!(devc
->caps
& SB_NO_AUDIO
&& devc
->caps
& SB_NO_MIDI
) && devc
->irq
> 0)
953 free_irq(devc
->irq
, devc
);
954 sound_unload_mixerdev(devc
->my_mixerdev
);
955 /* We don't have to do this bit any more the UART401 is its own
956 master -- Krzysztof Halasa */
957 /* sound_unload_mididev(devc->my_mididev); */
958 sound_unload_audiodev(devc
->my_dev
);
963 release_region(hw_config
->io_base
, 16);
965 kfree(detected_devc
);
969 * Mixer access routines
972 void sb_setmixer(sb_devc
* devc
, unsigned int port
, unsigned int value
)
978 outb(((unsigned char) (port
& 0xff)), MIXER_ADDR
);
981 outb(((unsigned char) (value
& 0xff)), MIXER_DATA
);
983 restore_flags(flags
);
986 unsigned int sb_getmixer(sb_devc
* devc
, unsigned int port
)
993 outb(((unsigned char) (port
& 0xff)), MIXER_ADDR
);
996 val
= inb(MIXER_DATA
);
998 restore_flags(flags
);
1006 * MPU401 MIDI initialization.
1009 static void smw_putmem(sb_devc
* devc
, int base
, int addr
, unsigned char val
)
1011 unsigned long flags
;
1016 outb((addr
& 0xff), base
+ 1); /* Low address bits */
1017 outb((addr
>> 8), base
+ 2); /* High address bits */
1018 outb((val
), base
); /* Data */
1020 restore_flags(flags
);
1023 static unsigned char smw_getmem(sb_devc
* devc
, int base
, int addr
)
1025 unsigned long flags
;
1031 outb((addr
& 0xff), base
+ 1); /* Low address bits */
1032 outb((addr
>> 8), base
+ 2); /* High address bits */
1033 val
= inb(base
); /* Data */
1035 restore_flags(flags
);
1039 static int smw_midi_init(sb_devc
* devc
, struct address_info
*hw_config
)
1041 int mpu_base
= hw_config
->io_base
;
1042 int mp_base
= mpu_base
+ 4; /* Microcontroller base */
1044 unsigned char control
;
1048 * Reset the microcontroller so that the RAM can be accessed
1051 control
= inb(mpu_base
+ 7);
1052 outb((control
| 3), mpu_base
+ 7); /* Set last two bits to 1 (?) */
1053 outb(((control
& 0xfe) | 2), mpu_base
+ 7); /* xxxxxxx0 resets the mc */
1055 mdelay(3); /* Wait at least 1ms */
1057 outb((control
& 0xfc), mpu_base
+ 7); /* xxxxxx00 enables RAM */
1060 * Detect microcontroller by probing the 8k RAM area
1062 smw_putmem(devc
, mp_base
, 0, 0x00);
1063 smw_putmem(devc
, mp_base
, 1, 0xff);
1066 if (smw_getmem(devc
, mp_base
, 0) != 0x00 || smw_getmem(devc
, mp_base
, 1) != 0xff)
1068 DDB(printk("SM Wave: No microcontroller RAM detected (%02x, %02x)\n", smw_getmem(devc
, mp_base
, 0), smw_getmem(devc
, mp_base
, 1)));
1069 return 0; /* No RAM */
1072 * There is RAM so assume it's really a SM Wave
1075 devc
->model
= MDL_SMW
;
1076 smw_mixer_init(devc
);
1081 extern void *smw_free
;
1083 smw_ucodeLen
= mod_firmware_load("/etc/sound/midi0001.bin", (void *) &smw_ucode
);
1084 smw_free
= smw_ucode
;
1087 if (smw_ucodeLen
> 0)
1089 if (smw_ucodeLen
!= 8192)
1091 printk(KERN_ERR
"SM Wave: Invalid microcode (MIDI0001.BIN) length\n");
1095 * Download microcode
1098 for (i
= 0; i
< 8192; i
++)
1099 smw_putmem(devc
, mp_base
, i
, smw_ucode
[i
]);
1105 for (i
= 0; i
< 8192; i
++)
1106 if (smw_getmem(devc
, mp_base
, i
) != smw_ucode
[i
])
1108 printk(KERN_ERR
"SM Wave: Microcode verification failed\n");
1115 * Set the SCSI interrupt (IRQ2/9, IRQ3 or IRQ10). The SCSI interrupt
1116 * is disabled by default.
1118 * FIXME - make this a module option
1120 * BTW the Zilog 5380 SCSI controller is located at MPU base + 0x10.
1123 static unsigned char scsi_irq_bits
[] = {
1124 0, 0, 3, 1, 0, 0, 0, 0, 0, 3, 2, 0, 0, 0, 0, 0
1126 control
|= scsi_irq_bits
[SMW_SCSI_IRQ
] << 6;
1130 #ifdef SMW_OPL4_ENABLE
1132 * Make the OPL4 chip visible on the PC bus at 0x380.
1134 * There is no need to enable this feature since this driver
1135 * doesn't support OPL4 yet. Also there is no RAM in SM Wave so
1136 * enabling OPL4 is pretty useless.
1138 control
|= 0x10; /* Uses IRQ12 if bit 0x20 == 0 */
1139 /* control |= 0x20; Uncomment this if you want to use IRQ7 */
1141 outb((control
| 0x03), mpu_base
+ 7); /* xxxxxx11 restarts */
1142 hw_config
->name
= "SoundMan Wave";
1146 static int ess_midi_init(sb_devc
* devc
, struct address_info
*hw_config
)
1148 unsigned char cfg
, tmp
;
1150 cfg
= sb_getmixer(devc
, 0x40) & 0x03;
1152 if (devc
->submodel
< 8)
1154 sb_setmixer(devc
, 0x40, cfg
| 0x03); /* Enable OPL3 & joystick */
1155 return 0; /* ES688 doesn't support MPU401 mode */
1157 tmp
= (hw_config
->io_base
& 0x0f0) >> 4;
1161 sb_setmixer(devc
, 0x40, cfg
);
1166 tmp
= 1; /* MPU enabled without interrupts */
1168 /* May be shared: if so the value is -ve */
1170 switch(abs(hw_config
->irq
))
1189 sb_setmixer(devc
, 0x40, cfg
| 0x03);
1193 static int init_Jazz16_midi(sb_devc
* devc
, struct address_info
*hw_config
)
1195 int mpu_base
= hw_config
->io_base
;
1196 int sb_base
= devc
->base
;
1197 int irq
= hw_config
->irq
;
1199 unsigned char bits
= 0;
1200 unsigned long flags
;
1205 if (irq
< 1 || irq
> 15 ||
1206 jazz_irq_bits
[irq
] == 0)
1208 printk(KERN_ERR
"Jazz16: Invalid MIDI interrupt (IRQ%d)\n", irq
);
1225 bits
= jazz16_bits
= bits
<< 5;
1238 printk(KERN_ERR
"Jazz16: Invalid MIDI I/O port %x\n", mpu_base
);
1242 * Magic wake up sequence by writing to 0x201 (aka Joystick port)
1249 restore_flags(flags
);
1251 hw_config
->name
= "Jazz16";
1252 smw_midi_init(devc
, hw_config
);
1254 if (!sb_dsp_command(devc
, 0xfb))
1257 if (!sb_dsp_command(devc
, jazz_dma_bits
[devc
->dma8
] |
1258 (jazz_dma_bits
[devc
->dma16
] << 4)))
1261 if (!sb_dsp_command(devc
, jazz_irq_bits
[devc
->irq
] |
1262 (jazz_irq_bits
[irq
] << 4)))
1268 void attach_sbmpu(struct address_info
*hw_config
)
1270 #if defined(CONFIG_MIDI) && defined(CONFIG_UART401)
1271 attach_uart401(hw_config
);
1272 last_sb
->midi_irq_cookie
=midi_devs
[hw_config
->slots
[4]]->devc
;
1276 int probe_sbmpu(struct address_info
*hw_config
)
1278 #if defined(CONFIG_MIDI) && defined(CONFIG_UART401)
1279 sb_devc
*devc
= last_devc
;
1281 if (last_devc
== NULL
)
1286 if (hw_config
->io_base
<= 0)
1289 if (check_region(hw_config
->io_base
, 4))
1291 printk(KERN_ERR
"sbmpu: I/O port conflict (%x)\n", hw_config
->io_base
);
1294 switch (devc
->model
)
1297 if (hw_config
->io_base
!= 0x300 && hw_config
->io_base
!= 0x330)
1299 printk(KERN_ERR
"SB16: Invalid MIDI port %x\n", hw_config
->io_base
);
1302 hw_config
->name
= "Sound Blaster 16";
1303 hw_config
->irq
= -devc
->irq
;
1304 #if defined(CONFIG_MIDI) && defined(CONFIG_UART401)
1305 if (devc
->minor
> 12) /* What is Vibra's version??? */
1306 sb16_set_mpu_port(devc
, hw_config
);
1311 if (hw_config
->irq
< 3 || hw_config
->irq
== devc
->irq
)
1312 hw_config
->irq
= -devc
->irq
;
1313 if (!ess_midi_init(devc
, hw_config
))
1315 hw_config
->name
= "ESS ES1688";
1319 if (hw_config
->irq
< 3 || hw_config
->irq
== devc
->irq
)
1320 hw_config
->irq
= -devc
->irq
;
1321 if (!init_Jazz16_midi(devc
, hw_config
))
1328 return probe_uart401(hw_config
);
1334 void unload_sbmpu(struct address_info
*hw_config
)
1336 #if defined(CONFIG_MIDI) && defined(CONFIG_UART401)
1337 unload_uart401(hw_config
);
1340 #else /* !CONFIG_MIDI */
1342 void unload_sbmpu(struct address_info
*hw_config
)
1346 int probe_sbmpu(struct address_info
*hw_config
)
1351 void attach_sbmpu(struct address_info
*hw_config
)