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