This source file includes following definitions.
- sb_dsp_command
- sbintr
- sb_get_irq
- sb_free_irq
- sb_reset_dsp
- dsp_speaker
- dsp_speed
- dsp_set_stereo
- sb_dsp_output_block
- sb_dsp_start_input
- dsp_cleanup
- sb_dsp_prepare_for_input
- sb_dsp_prepare_for_output
- sb_dsp_halt_xfer
- verify_irq
- sb_dsp_open
- sb_dsp_close
- dsp_set_bits
- sb_dsp_ioctl
- sb_dsp_reset
- get_sb_byte
- smw_putmem
- smw_getmem
- initialize_smw
- initialize_ProSonic16
- sb_dsp_detect
- sb_dsp_init
- sb_dsp_disable_midi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36 #include "sound_config.h"
37
38 #if defined(CONFIGURE_SOUNDCARD) && !defined(EXCLUDE_SB)
39
40 #include "sb.h"
41 #include "sb_mixer.h"
42 #undef SB_TEST_IRQ
43
44 int sbc_base = 0;
45 static int sbc_irq = 0;
46 static int open_mode = 0;
47 int Jazz16_detected = 0;
48 int sb_no_recording = 0;
49
50
51
52
53
54
55
56
57
58 int sb_dsp_ok = 0;
59
60
61
62
63 static int midi_disabled = 0;
64 int sb_dsp_highspeed = 0;
65 int sbc_major = 1, sbc_minor = 0;
66
67
68
69 static int dsp_stereo = 0;
70 static int dsp_current_speed = DSP_DEFAULT_SPEED;
71 static int sb16 = 0;
72 static int irq_verified = 0;
73
74 int sb_midi_mode = NORMAL_MIDI;
75 int sb_midi_busy = 0;
76
77
78
79
80 int sb_dsp_busy = 0;
81
82 volatile int sb_irq_mode = IMODE_NONE;
83
84
85
86
87
88 static volatile int irq_ok = 0;
89
90 #ifdef JAZZ16
91
92
93
94 static int dsp_16bit = 0;
95 static int dma8 = 1;
96 static int dma16 = 5;
97
98 static int dsp_set_bits (int arg);
99 static int initialize_ProSonic16 (void);
100
101
102
103 #endif
104
105 int sb_duplex_midi = 0;
106 static int my_dev = 0;
107
108 volatile int sb_intr_active = 0;
109
110 static int dsp_speed (int);
111 static int dsp_set_stereo (int mode);
112 int sb_dsp_command (unsigned char val);
113
114 #if !defined(EXCLUDE_MIDI) || !defined(EXCLUDE_AUDIO)
115
116
117
118
119
120 int
121 sb_dsp_command (unsigned char val)
122 {
123 int i;
124 unsigned long limit;
125
126 limit = GET_TIME () + HZ / 10;
127
128
129
130
131
132
133
134
135
136
137
138 for (i = 0; i < 500000 && GET_TIME () < limit; i++)
139 {
140 if ((INB (DSP_STATUS) & 0x80) == 0)
141 {
142 OUTB (val, DSP_COMMAND);
143 return 1;
144 }
145 }
146
147 printk ("SoundBlaster: DSP Command(%x) Timeout.\n", val);
148 printk ("IRQ conflict???\n");
149 return 0;
150 }
151
152 void
153 sbintr (INT_HANDLER_PARMS (irq, dummy))
154 {
155 int status;
156
157 #ifndef EXCLUDE_SBPRO
158 if (sb16)
159 {
160 unsigned char src = sb_getmixer (IRQ_STAT);
161
162 #ifndef EXCLUDE_SB16
163 if (src & 3)
164 sb16_dsp_interrupt (irq);
165
166 #ifndef EXCLUDE_MIDI
167 if (src & 4)
168 sb16midiintr (irq);
169
170
171 #endif
172
173 #endif
174
175 if (!(src & 1))
176 return;
177
178
179 }
180 #endif
181
182 status = INB (DSP_DATA_AVAIL);
183
184
185
186 if (sb_intr_active)
187 switch (sb_irq_mode)
188 {
189 case IMODE_OUTPUT:
190 sb_intr_active = 0;
191 DMAbuf_outputintr (my_dev, 1);
192 break;
193
194 case IMODE_INPUT:
195 sb_intr_active = 0;
196 DMAbuf_inputintr (my_dev);
197
198
199
200 break;
201
202 case IMODE_INIT:
203 sb_intr_active = 0;
204 irq_ok = 1;
205 break;
206
207 case IMODE_MIDI:
208 #ifndef EXCLUDE_MIDI
209 sb_midi_interrupt (irq);
210 #endif
211 break;
212
213 default:
214 printk ("SoundBlaster: Unexpected interrupt\n");
215 }
216 }
217
218 static int sb_irq_usecount = 0;
219
220 int
221 sb_get_irq (void)
222 {
223 int ok;
224
225 if (!sb_irq_usecount)
226 if ((ok = snd_set_irq_handler (sbc_irq, sbintr, "SoundBlaster")) < 0)
227 return ok;
228
229 sb_irq_usecount++;
230
231 return 0;
232 }
233
234 void
235 sb_free_irq (void)
236 {
237 if (!sb_irq_usecount)
238 return;
239
240 sb_irq_usecount--;
241
242 if (!sb_irq_usecount)
243 snd_release_irq (sbc_irq);
244 }
245
246 int
247 sb_reset_dsp (void)
248 {
249 int loopc;
250
251 OUTB (1, DSP_RESET);
252 tenmicrosec ();
253 OUTB (0, DSP_RESET);
254 tenmicrosec ();
255 tenmicrosec ();
256 tenmicrosec ();
257
258 for (loopc = 0; loopc < 1000 && !(INB (DSP_DATA_AVAIL) & 0x80); loopc++);
259
260
261
262
263
264
265
266
267 if (INB (DSP_READ) != 0xAA)
268 return 0;
269
270
271
272 return 1;
273 }
274
275 #endif
276
277 #ifndef EXCLUDE_AUDIO
278
279 static void
280 dsp_speaker (char state)
281 {
282 if (state)
283 sb_dsp_command (DSP_CMD_SPKON);
284 else
285 sb_dsp_command (DSP_CMD_SPKOFF);
286 }
287
288 static int
289 dsp_speed (int speed)
290 {
291 unsigned char tconst;
292 unsigned long flags;
293 int max_speed = 44100;
294
295 if (speed < 4000)
296 speed = 4000;
297
298
299
300
301
302 if (sbc_major < 2 ||
303 (sbc_major == 2 && sbc_minor == 0))
304 max_speed = 22050;
305
306
307
308
309 if (open_mode != OPEN_WRITE)
310 if (sbc_major < 3)
311 if (sbc_major == 2 && sbc_minor > 0)
312 max_speed = 15000;
313 else
314 max_speed = 13000;
315
316 if (speed > max_speed)
317 speed = max_speed;
318
319
320
321
322 #if !defined (SM_GAMES)
323
324
325
326 if (dsp_stereo && speed > 22050 && Jazz16_detected == 0)
327 speed = 22050;
328 #endif
329
330 if ((speed > 22050) && sb_midi_busy)
331 {
332 printk ("SB Warning: High speed DSP not possible simultaneously with MIDI output\n");
333 speed = 22050;
334 }
335
336 if (dsp_stereo)
337 speed *= 2;
338
339
340
341
342
343 if (speed > 22050)
344 {
345
346
347 int tmp;
348
349 tconst = (unsigned char) ((65536 -
350 ((256000000 + speed / 2) / speed)) >> 8);
351 sb_dsp_highspeed = 1;
352
353 DISABLE_INTR (flags);
354 if (sb_dsp_command (0x40))
355 sb_dsp_command (tconst);
356 RESTORE_INTR (flags);
357
358 tmp = 65536 - (tconst << 8);
359 speed = (256000000 + tmp / 2) / tmp;
360 }
361 else
362 {
363 int tmp;
364
365 sb_dsp_highspeed = 0;
366 tconst = (256 - ((1000000 + speed / 2) / speed)) & 0xff;
367
368 DISABLE_INTR (flags);
369 if (sb_dsp_command (0x40))
370
371
372 sb_dsp_command (tconst);
373 RESTORE_INTR (flags);
374
375 tmp = 256 - tconst;
376 speed = (1000000 + tmp / 2) / tmp;
377 }
378
379 if (dsp_stereo)
380 speed /= 2;
381
382 dsp_current_speed = speed;
383 return speed;
384 }
385
386 static int
387 dsp_set_stereo (int mode)
388 {
389 dsp_stereo = 0;
390
391 #ifdef EXCLUDE_SBPRO
392 return 0;
393 #else
394 if (sbc_major < 3 || sb16)
395 return 0;
396
397
398
399 if (mode && sb_midi_busy)
400 {
401 printk ("SB Warning: Stereo DSP not possible simultaneously with MIDI output\n");
402 return 0;
403 }
404
405 dsp_stereo = !!mode;
406 return dsp_stereo;
407 #endif
408 }
409
410 static void
411 sb_dsp_output_block (int dev, unsigned long buf, int count,
412 int intrflag, int restart_dma)
413 {
414 unsigned long flags;
415
416 if (!sb_irq_mode)
417 dsp_speaker (ON);
418
419 sb_irq_mode = IMODE_OUTPUT;
420 DMAbuf_start_dma (dev, buf, count, DMA_MODE_WRITE);
421
422 if (audio_devs[dev]->dmachan > 3)
423 count >>= 1;
424 count--;
425
426 if (sb_dsp_highspeed)
427 {
428 DISABLE_INTR (flags);
429 if (sb_dsp_command (0x48))
430
431
432 {
433 sb_dsp_command ((unsigned char) (count & 0xff));
434 sb_dsp_command ((unsigned char) ((count >> 8) & 0xff));
435 sb_dsp_command (0x91);
436
437
438 }
439 else
440 printk ("SB Error: Unable to start (high speed) DAC\n");
441 RESTORE_INTR (flags);
442 }
443 else
444 {
445 DISABLE_INTR (flags);
446 if (sb_dsp_command (0x14))
447
448
449 {
450 sb_dsp_command ((unsigned char) (count & 0xff));
451 sb_dsp_command ((unsigned char) ((count >> 8) & 0xff));
452 }
453 else
454 printk ("SB Error: Unable to start DAC\n");
455 RESTORE_INTR (flags);
456 }
457 sb_intr_active = 1;
458 }
459
460 static void
461 sb_dsp_start_input (int dev, unsigned long buf, int count, int intrflag,
462 int restart_dma)
463 {
464
465
466
467
468 unsigned long flags;
469
470 if (!sb_irq_mode)
471 dsp_speaker (OFF);
472
473 sb_irq_mode = IMODE_INPUT;
474 DMAbuf_start_dma (dev, buf, count, DMA_MODE_READ);
475
476 if (audio_devs[dev]->dmachan > 3)
477 count >>= 1;
478 count--;
479
480 if (sb_dsp_highspeed)
481 {
482 DISABLE_INTR (flags);
483 if (sb_dsp_command (0x48))
484
485
486 {
487 sb_dsp_command ((unsigned char) (count & 0xff));
488 sb_dsp_command ((unsigned char) ((count >> 8) & 0xff));
489 sb_dsp_command (0x99);
490
491
492 }
493 else
494 printk ("SB Error: Unable to start (high speed) ADC\n");
495 RESTORE_INTR (flags);
496 }
497 else
498 {
499 DISABLE_INTR (flags);
500 if (sb_dsp_command (0x24))
501
502
503 {
504 sb_dsp_command ((unsigned char) (count & 0xff));
505 sb_dsp_command ((unsigned char) ((count >> 8) & 0xff));
506 }
507 else
508 printk ("SB Error: Unable to start ADC\n");
509 RESTORE_INTR (flags);
510 }
511
512 sb_intr_active = 1;
513 }
514
515 static void
516 dsp_cleanup (void)
517 {
518 sb_intr_active = 0;
519 }
520
521 static int
522 sb_dsp_prepare_for_input (int dev, int bsize, int bcount)
523 {
524 dsp_cleanup ();
525 dsp_speaker (OFF);
526
527 if (sbc_major == 3)
528
529
530 {
531 #ifdef JAZZ16
532
533
534
535 audio_devs[my_dev]->dmachan = dsp_16bit ? dma16 : dma8;
536 if (dsp_stereo)
537 sb_dsp_command (dsp_16bit ? 0xac : 0xa8);
538 else
539 sb_dsp_command (dsp_16bit ? 0xa4 : 0xa0);
540 #else
541
542
543 if (dsp_stereo)
544 sb_dsp_command (0xa8);
545 else
546 sb_dsp_command (0xa0);
547 #endif
548 dsp_speed (dsp_current_speed);
549
550
551
552 }
553 return 0;
554 }
555
556 static int
557 sb_dsp_prepare_for_output (int dev, int bsize, int bcount)
558 {
559 dsp_cleanup ();
560 dsp_speaker (ON);
561
562 #ifndef EXCLUDE_SBPRO
563 if (sbc_major == 3)
564
565
566 {
567 #ifdef JAZZ16
568
569
570 audio_devs[my_dev]->dmachan = dsp_16bit ? dma16 : dma8;
571 if (Jazz16_detected != 2)
572 sb_mixer_set_stereo (dsp_stereo);
573 if (dsp_stereo)
574 sb_dsp_command (dsp_16bit ? 0xac : 0xa8);
575 else
576 sb_dsp_command (dsp_16bit ? 0xa4 : 0xa0);
577 #else
578 sb_mixer_set_stereo (dsp_stereo);
579 #endif
580 dsp_speed (dsp_current_speed);
581
582
583
584 }
585 #endif
586 return 0;
587 }
588
589 static void
590 sb_dsp_halt_xfer (int dev)
591 {
592 }
593
594 static int
595 verify_irq (void)
596 {
597 #if 0
598 DEFINE_WAIT_QUEUE (testq, testf);
599
600 irq_ok = 0;
601
602 if (sb_get_irq () == -1)
603 {
604 printk ("*** SB Error: Irq %d already in use\n", sbc_irq);
605 return 0;
606 }
607
608
609 sb_irq_mode = IMODE_INIT;
610
611 sb_dsp_command (0xf2);
612
613
614
615 DO_SLEEP (testq, testf, HZ / 5);
616
617 sb_free_irq ();
618
619 if (!irq_ok)
620 {
621 printk ("SB Warning: IRQ%d test not passed!", sbc_irq);
622 irq_ok = 1;
623 }
624 #else
625 irq_ok = 1;
626 #endif
627 return irq_ok;
628 }
629
630 static int
631 sb_dsp_open (int dev, int mode)
632 {
633 int retval;
634
635 if (!sb_dsp_ok)
636 {
637 printk ("SB Error: SoundBlaster board not installed\n");
638 return RET_ERROR (ENXIO);
639 }
640
641 if (sb_no_recording && mode & OPEN_READ)
642 {
643 printk ("SB Error: Recording not supported by this device\n");
644 return RET_ERROR (ENOTTY);
645 }
646
647 if (sb_intr_active || (sb_midi_busy && sb_midi_mode == UART_MIDI))
648 {
649 printk ("SB: PCM not possible during MIDI input\n");
650 return RET_ERROR (EBUSY);
651 }
652
653 if (!irq_verified)
654 {
655 verify_irq ();
656 irq_verified = 1;
657 }
658 else if (!irq_ok)
659 printk ("SB Warning: Incorrect IRQ setting %d\n",
660 sbc_irq);
661
662 retval = sb_get_irq ();
663 if (retval)
664 return retval;
665
666
667
668 #ifdef JAZZ16
669 audio_devs[my_dev]->dmachan = dma8;
670 #endif
671
672 if (DMAbuf_open_dma (dev) < 0)
673 {
674 sb_free_irq ();
675 printk ("SB: DMA Busy\n");
676 return RET_ERROR (EBUSY);
677 }
678 #ifdef JAZZ16
679
680
681 if (Jazz16_detected != 0)
682 if (dma16 != dma8)
683 {
684 if (ALLOC_DMA_CHN (dma16, "Jazz16 16 bit"))
685 {
686 sb_free_irq ();
687 DMAbuf_close_dma (dev);
688 return RET_ERROR (EBUSY);
689 }
690 }
691 #endif
692
693 sb_irq_mode = IMODE_NONE;
694
695 sb_dsp_busy = 1;
696 open_mode = mode;
697
698 return 0;
699 }
700
701 static void
702 sb_dsp_close (int dev)
703 {
704 #ifdef JAZZ16
705
706
707 if (Jazz16_detected)
708 {
709 if (audio_devs[my_dev]->dmachan == dma8)
710 RELEASE_DMA_CHN (dma16);
711 else
712 RELEASE_DMA_CHN (dma8);
713
714 }
715 #endif
716
717 DMAbuf_close_dma (dev);
718 sb_free_irq ();
719 dsp_cleanup ();
720 dsp_speaker (OFF);
721 sb_dsp_busy = 0;
722 sb_dsp_highspeed = 0;
723 open_mode = 0;
724 }
725
726 #ifdef JAZZ16
727
728
729 static int
730 dsp_set_bits (int arg)
731 {
732 if (arg)
733 if (Jazz16_detected == 0)
734 dsp_16bit = 0;
735 else
736 switch (arg)
737 {
738 case 8:
739 dsp_16bit = 0;
740 break;
741 case 16:
742 dsp_16bit = 1;
743 break;
744 default:
745 dsp_16bit = 0;
746 }
747 return dsp_16bit ? 16 : 8;
748 }
749
750 #endif
751
752 static int
753 sb_dsp_ioctl (int dev, unsigned int cmd, unsigned int arg, int local)
754 {
755 switch (cmd)
756 {
757 case SOUND_PCM_WRITE_RATE:
758 if (local)
759 return dsp_speed (arg);
760 return IOCTL_OUT (arg, dsp_speed (IOCTL_IN (arg)));
761 break;
762
763 case SOUND_PCM_READ_RATE:
764 if (local)
765 return dsp_current_speed;
766 return IOCTL_OUT (arg, dsp_current_speed);
767 break;
768
769 case SOUND_PCM_WRITE_CHANNELS:
770 if (local)
771 return dsp_set_stereo (arg - 1) + 1;
772 return IOCTL_OUT (arg, dsp_set_stereo (IOCTL_IN (arg) - 1) + 1);
773 break;
774
775 case SOUND_PCM_READ_CHANNELS:
776 if (local)
777 return dsp_stereo + 1;
778 return IOCTL_OUT (arg, dsp_stereo + 1);
779 break;
780
781 case SNDCTL_DSP_STEREO:
782 if (local)
783 return dsp_set_stereo (arg);
784 return IOCTL_OUT (arg, dsp_set_stereo (IOCTL_IN (arg)));
785 break;
786
787 #ifdef JAZZ16
788
789
790
791 case SNDCTL_DSP_SETFMT:
792 if (local)
793 return dsp_set_bits (arg);
794 return IOCTL_OUT (arg, dsp_set_bits (IOCTL_IN (arg)));
795 break;
796
797 case SOUND_PCM_READ_BITS:
798 if (local)
799 return dsp_16bit ? 16 : 8;
800 return IOCTL_OUT (arg, dsp_16bit ? 16 : 8);
801 break;
802 #else
803 case SOUND_PCM_WRITE_BITS:
804 case SOUND_PCM_READ_BITS:
805 if (local)
806 return 8;
807 return IOCTL_OUT (arg, 8);
808
809
810 break;
811 #endif
812
813 case SOUND_PCM_WRITE_FILTER:
814 case SOUND_PCM_READ_FILTER:
815 return RET_ERROR (EINVAL);
816 break;
817
818 default:
819 return RET_ERROR (EINVAL);
820 }
821
822 return RET_ERROR (EINVAL);
823 }
824
825 static void
826 sb_dsp_reset (int dev)
827 {
828 unsigned long flags;
829
830 DISABLE_INTR (flags);
831
832 sb_reset_dsp ();
833 dsp_speed (dsp_current_speed);
834 dsp_cleanup ();
835
836 RESTORE_INTR (flags);
837 }
838
839 #endif
840
841
842 #ifdef JAZZ16
843
844
845
846
847
848
849
850
851
852
853
854
855
856 #ifndef MPU_BASE
857 #define MPU_BASE 0x330
858 #endif
859 #ifndef MPU_IRQ
860 #define MPU_IRQ 9
861 #endif
862
863 unsigned int
864 get_sb_byte (void)
865 {
866 int i;
867
868 for (i = 1000; i; i--)
869 if (INB (DSP_DATA_AVAIL) & 0x80)
870 {
871 return INB (DSP_READ);
872 }
873
874 return 0xffff;
875 }
876
877 #ifdef SM_WAVE
878
879
880
881
882
883
884
885
886
887
888 static void
889 smw_putmem (int base, int addr, unsigned char val)
890 {
891 unsigned long flags;
892
893 DISABLE_INTR (flags);
894
895 OUTB (addr & 0xff, base + 1);
896 OUTB (addr >> 8, base + 2);
897 OUTB (val, base);
898
899 RESTORE_INTR (flags);
900 }
901
902 static unsigned char
903 smw_getmem (int base, int addr)
904 {
905 unsigned long flags;
906 unsigned char val;
907
908 DISABLE_INTR (flags);
909
910 OUTB (addr & 0xff, base + 1);
911 OUTB (addr >> 8, base + 2);
912 val = INB (base);
913
914 RESTORE_INTR (flags);
915 return val;
916 }
917
918 static int
919 initialize_smw (void)
920 {
921 #ifdef SMW_MIDI0001_INCLUDED
922 #include "smw-midi0001.h"
923 #else
924 unsigned char smw_ucode[1];
925 int smw_ucodeLen = 0;
926
927 #endif
928
929 int mp_base = MPU_BASE + 4;
930 int i;
931 unsigned char control;
932
933
934
935
936
937 control = INB (MPU_BASE + 7);
938 OUTB (control | 3, MPU_BASE + 7);
939 OUTB ((control & 0xfe) | 2, MPU_BASE + 7);
940
941 for (i = 0; i < 300; i++)
942 tenmicrosec ();
943
944 OUTB (control & 0xfc, MPU_BASE + 7);
945
946
947
948
949 smw_putmem (mp_base, 0, 0x00);
950 smw_putmem (mp_base, 1, 0xff);
951 tenmicrosec ();
952
953 if (smw_getmem (mp_base, 0) != 0x00 || smw_getmem (mp_base, 1) != 0xff)
954 {
955 printk ("\nSM Wave: No microcontroller RAM detected (%02x, %02x)\n",
956 smw_getmem (mp_base, 0), smw_getmem (mp_base, 1));
957 return 0;
958 }
959
960
961
962
963
964 #ifdef SMW_MIDI0001_INCLUDED
965 if (smw_ucodeLen != 8192)
966 {
967 printk ("\nSM Wave: Invalid microcode (MIDI0001.BIN) length\n");
968 return 1;
969 }
970 #endif
971
972
973
974
975
976 for (i = 0; i < 8192; i++)
977 smw_putmem (mp_base, i, smw_ucode[i]);
978
979
980
981
982
983 for (i = 0; i < 8192; i++)
984 if (smw_getmem (mp_base, i) != smw_ucode[i])
985 {
986 printk ("SM Wave: Microcode verification failed\n");
987 return 0;
988 }
989
990 control = 0;
991 #ifdef SMW_SCSI_IRQ
992
993
994
995
996
997
998 {
999 static unsigned char scsi_irq_bits[] =
1000 {0, 0, 3, 1, 0, 0, 0, 0, 0, 3, 2, 0, 0, 0, 0, 0};
1001
1002 control |= scsi_irq_bits[SMW_SCSI_IRQ] << 6;
1003 }
1004 #endif
1005
1006 #ifdef SMW_OPL4_ENABLE
1007
1008
1009
1010
1011
1012
1013
1014 control |= 0x10;
1015
1016 #endif
1017
1018 OUTB (control | 0x03, MPU_BASE + 7);
1019 return 1;
1020 }
1021
1022 #endif
1023
1024 static int
1025 initialize_ProSonic16 (void)
1026 {
1027 int x;
1028 static unsigned char int_translat[16] =
1029 {0, 0, 2, 3, 0, 1, 0, 4, 0, 2, 5, 0, 0, 0, 0, 6}, dma_translat[8] =
1030 {0, 1, 0, 2, 0, 3, 0, 4};
1031
1032 OUTB (0xAF, 0x201);
1033 for (x = 0; x < 1000; ++x)
1034 tenmicrosec ();
1035 OUTB (0x50, 0x201);
1036 OUTB ((sbc_base & 0x70) | ((MPU_BASE & 0x30) >> 4), 0x201);
1037
1038 if (sb_reset_dsp ())
1039 {
1040
1041
1042
1043 if (!sb_dsp_command (0xFA))
1044 return 1;
1045 if (get_sb_byte () != 0x12)
1046 return 1;
1047
1048 if (sb_dsp_command (0xFB) &&
1049 sb_dsp_command ((dma_translat[JAZZ_DMA16] << 4) | dma_translat[SBC_DMA]) &&
1050 sb_dsp_command ((int_translat[MPU_IRQ] << 4) | int_translat[sbc_irq]))
1051 {
1052 Jazz16_detected = 1;
1053 #ifdef SM_WAVE
1054 if (initialize_smw ())
1055 Jazz16_detected = 2;
1056 #endif
1057 sb_dsp_disable_midi ();
1058 }
1059
1060 return 1;
1061 }
1062 return 0;
1063 }
1064
1065 #endif
1066
1067 int
1068 sb_dsp_detect (struct address_info *hw_config)
1069 {
1070 sbc_base = hw_config->io_base;
1071 sbc_irq = hw_config->irq;
1072
1073 if (sb_dsp_ok)
1074 return 0;
1075
1076
1077 #ifdef JAZZ16
1078 dma8 = hw_config->dma;
1079 dma16 = JAZZ_DMA16;
1080
1081 if (!initialize_ProSonic16 ())
1082 return 0;
1083 #else
1084 if (!sb_reset_dsp ())
1085 return 0;
1086 #endif
1087
1088 return 1;
1089
1090
1091 }
1092
1093 #ifndef EXCLUDE_AUDIO
1094 static struct audio_operations sb_dsp_operations =
1095 {
1096 "SoundBlaster",
1097 NOTHING_SPECIAL,
1098 AFMT_U8,
1099 NULL,
1100 sb_dsp_open,
1101 sb_dsp_close,
1102 sb_dsp_output_block,
1103 sb_dsp_start_input,
1104 sb_dsp_ioctl,
1105 sb_dsp_prepare_for_input,
1106 sb_dsp_prepare_for_output,
1107 sb_dsp_reset,
1108 sb_dsp_halt_xfer,
1109 NULL,
1110 NULL
1111 };
1112
1113 #endif
1114
1115 long
1116 sb_dsp_init (long mem_start, struct address_info *hw_config)
1117 {
1118 int i;
1119 int mixer_type = 0;
1120
1121 sbc_major = sbc_minor = 0;
1122 sb_dsp_command (0xe1);
1123
1124
1125
1126 for (i = 1000; i; i--)
1127 {
1128 if (INB (DSP_DATA_AVAIL) & 0x80)
1129 {
1130
1131
1132 if (sbc_major == 0)
1133 sbc_major = INB (DSP_READ);
1134 else
1135 {
1136 sbc_minor = INB (DSP_READ);
1137 break;
1138 }
1139 }
1140 }
1141
1142 if (sbc_major == 2 || sbc_major == 3)
1143 sb_duplex_midi = 1;
1144
1145 if (sbc_major == 4)
1146 sb16 = 1;
1147
1148 #ifndef EXCLUDE_SBPRO
1149 if (sbc_major >= 3)
1150 mixer_type = sb_mixer_init (sbc_major);
1151 #else
1152 if (sbc_major >= 3)
1153 printk ("\n\n\n\nNOTE! SB Pro support is required with your soundcard!\n\n\n");
1154 #endif
1155
1156 #ifndef EXCLUDE_YM3812
1157
1158 if (sbc_major > 3 ||
1159 (sbc_major == 3 && INB (0x388) == 0x00))
1160 enable_opl3_mode (OPL3_LEFT, OPL3_RIGHT, OPL3_BOTH);
1161 #endif
1162
1163 #ifndef EXCLUDE_AUDIO
1164 if (sbc_major >= 3)
1165 {
1166 if (Jazz16_detected)
1167 {
1168 if (Jazz16_detected == 2)
1169 sprintf (sb_dsp_operations.name, "SoundMan Wave %d.%d", sbc_major, sbc_minor);
1170 else
1171 sprintf (sb_dsp_operations.name, "MV Jazz16 %d.%d", sbc_major, sbc_minor);
1172 sb_dsp_operations.format_mask |= AFMT_S16_LE;
1173 }
1174 else
1175 #ifdef __SGNXPRO__
1176 if (mixer_type == 2)
1177 {
1178 sprintf (sb_dsp_operations.name, "Sound Galaxy NX Pro %d.%d", sbc_major, sbc_minor);
1179 }
1180 else
1181 #endif
1182
1183 if (sbc_major == 4)
1184 {
1185 sprintf (sb_dsp_operations.name, "SoundBlaster 16 %d.%d", sbc_major, sbc_minor);
1186 }
1187 else
1188 {
1189 sprintf (sb_dsp_operations.name, "SoundBlaster Pro %d.%d", sbc_major, sbc_minor);
1190 }
1191 }
1192 else
1193 {
1194 sprintf (sb_dsp_operations.name, "SoundBlaster %d.%d", sbc_major, sbc_minor);
1195 }
1196
1197 printk (" <%s>", sb_dsp_operations.name);
1198
1199 #if !defined(EXCLUDE_SB16) && !defined(EXCLUDE_SBPRO)
1200 if (!sb16)
1201
1202
1203 #endif
1204 if (num_audiodevs < MAX_AUDIO_DEV)
1205 {
1206 audio_devs[my_dev = num_audiodevs++] = &sb_dsp_operations;
1207 audio_devs[my_dev]->buffcount = DSP_BUFFCOUNT;
1208 audio_devs[my_dev]->buffsize = DSP_BUFFSIZE;
1209 audio_devs[my_dev]->dmachan = hw_config->dma;
1210 }
1211 else
1212 printk ("SB: Too many DSP devices available\n");
1213 #else
1214 printk (" <SoundBlaster (configured without audio support)>");
1215 #endif
1216
1217 #ifndef EXCLUDE_MIDI
1218 if (!midi_disabled && !sb16)
1219
1220
1221
1222 sb_midi_init (sbc_major);
1223 #endif
1224
1225 sb_dsp_ok = 1;
1226 return mem_start;
1227 }
1228
1229 void
1230 sb_dsp_disable_midi (void)
1231 {
1232 midi_disabled = 1;
1233 }
1234
1235 #endif