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 ((long) 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 ((long) 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 ((long) 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 *) arg, 8);
789 break;
790 #endif
791
792 case SOUND_PCM_WRITE_FILTER:
793 case SOUND_PCM_READ_FILTER:
794 return -EINVAL;
795 break;
796
797 default:;
798 }
799
800 return -EINVAL;
801 }
802
803 static void
804 sb_dsp_reset (int dev)
805 {
806 unsigned long flags;
807
808 save_flags (flags);
809 cli ();
810
811 sb_reset_dsp ();
812 dsp_speed (dsp_current_speed);
813 dsp_cleanup ();
814
815 restore_flags (flags);
816 }
817
818 #endif
819
820
821 #ifdef JAZZ16
822
823
824
825
826
827
828
829
830
831
832
833
834 unsigned int
835 get_sb_byte (void)
836 {
837 int i;
838
839 for (i = 1000; i; i--)
840 if (inb (DSP_DATA_AVAIL) & 0x80)
841 {
842 return inb (DSP_READ);
843 }
844
845 return 0xffff;
846 }
847
848 #ifdef SM_WAVE
849
850
851
852
853
854
855
856
857
858
859 static void
860 smw_putmem (int base, int addr, unsigned char val)
861 {
862 unsigned long flags;
863
864 save_flags (flags);
865 cli ();
866
867 outb (addr & 0xff, base + 1);
868 outb (addr >> 8, base + 2);
869 outb (val, base);
870
871 restore_flags (flags);
872 }
873
874 static unsigned char
875 smw_getmem (int base, int addr)
876 {
877 unsigned long flags;
878 unsigned char val;
879
880 save_flags (flags);
881 cli ();
882
883 outb (addr & 0xff, base + 1);
884 outb (addr >> 8, base + 2);
885 val = inb (base);
886
887 restore_flags (flags);
888 return val;
889 }
890
891 #ifdef SMW_MIDI0001_INCLUDED
892 #include "smw-midi0001.h"
893 #else
894 unsigned char *smw_ucode = NULL;
895 int smw_ucodeLen = 0;
896
897 #endif
898
899 static int
900 initialize_smw (int mpu_base)
901 {
902
903 int mp_base = mpu_base + 4;
904 int i;
905 unsigned char control;
906
907
908
909
910
911
912 control = inb (mpu_base + 7);
913 outb (control | 3, mpu_base + 7);
914 outb ((control & 0xfe) | 2, mpu_base + 7);
915
916 for (i = 0; i < 300; i++)
917 tenmicrosec ();
918
919 outb (control & 0xfc, mpu_base + 7);
920
921
922
923
924 smw_putmem (mp_base, 0, 0x00);
925 smw_putmem (mp_base, 1, 0xff);
926 tenmicrosec ();
927
928 if (smw_getmem (mp_base, 0) != 0x00 || smw_getmem (mp_base, 1) != 0xff)
929 {
930 printk ("\nSM Wave: No microcontroller RAM detected (%02x, %02x)\n",
931 smw_getmem (mp_base, 0), smw_getmem (mp_base, 1));
932 return 0;
933 }
934
935
936
937
938
939 if (smw_ucodeLen > 0)
940 {
941 if (smw_ucodeLen != 8192)
942 {
943 printk ("\nSM Wave: Invalid microcode (MIDI0001.BIN) length\n");
944 return 1;
945 }
946
947
948
949
950
951 for (i = 0; i < 8192; i++)
952 smw_putmem (mp_base, i, smw_ucode[i]);
953
954
955
956
957
958 for (i = 0; i < 8192; i++)
959 if (smw_getmem (mp_base, i) != smw_ucode[i])
960 {
961 printk ("SM Wave: Microcode verification failed\n");
962 return 0;
963 }
964 }
965
966 control = 0;
967 #ifdef SMW_SCSI_IRQ
968
969
970
971
972
973
974 {
975 static unsigned char scsi_irq_bits[] =
976 {0, 0, 3, 1, 0, 0, 0, 0, 0, 3, 2, 0, 0, 0, 0, 0};
977
978 control |= scsi_irq_bits[SMW_SCSI_IRQ] << 6;
979 }
980 #endif
981
982 #ifdef SMW_OPL4_ENABLE
983
984
985
986
987
988
989
990 control |= 0x10;
991
992 #endif
993
994 outb (control | 0x03, mpu_base + 7);
995 return 1;
996 }
997
998 #endif
999
1000 static int
1001 initialize_ProSonic16 (void)
1002 {
1003 int x;
1004 static unsigned char int_translat[16] =
1005 {0, 0, 2, 3, 0, 1, 0, 4, 0, 2, 5, 0, 0, 0, 0, 6}, dma_translat[8] =
1006 {0, 1, 0, 2, 0, 3, 0, 4};
1007
1008 struct address_info *mpu_config;
1009
1010 int mpu_base, mpu_irq;
1011
1012 if ((mpu_config = sound_getconf (SNDCARD_MPU401)))
1013 {
1014 mpu_base = mpu_config->io_base;
1015 mpu_irq = mpu_config->irq;
1016 }
1017 else
1018 {
1019 mpu_base = mpu_irq = 0;
1020 }
1021
1022 outb (0xAF, 0x201);
1023 for (x = 0; x < 1000; ++x)
1024 tenmicrosec ();
1025 outb (0x50, 0x201);
1026 outb ((sbc_base & 0x70) | ((mpu_base & 0x30) >> 4), 0x201);
1027
1028 if (sb_reset_dsp ())
1029 {
1030
1031
1032
1033 if (!sb_dsp_command (0xFA))
1034 return 1;
1035 if (get_sb_byte () != 0x12)
1036 return 1;
1037
1038 if (sb_dsp_command (0xFB) &&
1039 sb_dsp_command ((dma_translat[JAZZ_DMA16] << 4) | dma_translat[dma8]) &&
1040 sb_dsp_command ((int_translat[mpu_irq] << 4) | int_translat[sbc_irq]))
1041 {
1042 Jazz16_detected = 1;
1043 if (mpu_base == 0)
1044 printk ("Jazz16: No MPU401 devices configured - MIDI port not initialized\n");
1045
1046 #ifdef SM_WAVE
1047 if (mpu_base != 0)
1048 if (initialize_smw (mpu_base))
1049 Jazz16_detected = 2;
1050 #endif
1051 sb_dsp_disable_midi ();
1052 }
1053
1054 return 1;
1055 }
1056 return 0;
1057 }
1058
1059 #endif
1060
1061 int
1062 sb_dsp_detect (struct address_info *hw_config)
1063 {
1064 sbc_base = hw_config->io_base;
1065 sbc_irq = hw_config->irq;
1066 sb_osp = hw_config->osp;
1067
1068 if (sb_dsp_ok)
1069 return 0;
1070
1071
1072 dma8 = hw_config->dma;
1073
1074 #ifdef JAZZ16
1075 dma16 = JAZZ_DMA16;
1076
1077 if (!initialize_ProSonic16 ())
1078 return 0;
1079 #else
1080 if (!sb_reset_dsp ())
1081 return 0;
1082 #endif
1083
1084 return 1;
1085
1086
1087 }
1088
1089 #ifndef EXCLUDE_AUDIO
1090 static struct audio_operations sb_dsp_operations =
1091 {
1092 "SoundBlaster",
1093 NOTHING_SPECIAL,
1094 AFMT_U8,
1095 NULL,
1096 sb_dsp_open,
1097 sb_dsp_close,
1098 sb_dsp_output_block,
1099 sb_dsp_start_input,
1100 sb_dsp_ioctl,
1101 sb_dsp_prepare_for_input,
1102 sb_dsp_prepare_for_output,
1103 sb_dsp_reset,
1104 sb_dsp_halt_xfer,
1105 NULL,
1106 NULL,
1107 NULL,
1108 NULL,
1109 sb_dsp_trigger
1110 };
1111
1112 #endif
1113
1114 long
1115 sb_dsp_init (long mem_start, struct address_info *hw_config)
1116 {
1117 int i;
1118
1119 #ifndef EXCLUDE_SBPRO
1120 int mixer_type = 0;
1121
1122 #endif
1123
1124 sb_osp = hw_config->osp;
1125 sbc_major = sbc_minor = 0;
1126 sb_dsp_command (0xe1);
1127
1128
1129
1130 for (i = 1000; i; i--)
1131 {
1132 if (inb (DSP_DATA_AVAIL) & 0x80)
1133 {
1134
1135
1136 if (sbc_major == 0)
1137 sbc_major = inb (DSP_READ);
1138 else
1139 {
1140 sbc_minor = inb (DSP_READ);
1141 break;
1142 }
1143 }
1144 }
1145
1146 if (sbc_major == 0)
1147 {
1148 printk ("\n\nFailed to get SB version (%x) - possible I/O conflict\n\n",
1149 inb (DSP_DATA_AVAIL));
1150 sbc_major = 1;
1151 }
1152
1153 if (sbc_major == 2 || sbc_major == 3)
1154 sb_duplex_midi = 1;
1155
1156 if (sbc_major == 4)
1157 sb16 = 1;
1158
1159 if (sbc_major == 3 && sbc_minor == 1)
1160 {
1161 int ess_major = 0, ess_minor = 0;
1162
1163
1164
1165
1166
1167 sb_dsp_command (0xe7);
1168
1169
1170
1171 for (i = 1000; i; i--)
1172 {
1173 if (inb (DSP_DATA_AVAIL) & 0x80)
1174 {
1175
1176
1177 if (ess_major == 0)
1178 ess_major = inb (DSP_READ);
1179 else
1180 {
1181 ess_minor = inb (DSP_READ);
1182 break;
1183 }
1184 }
1185 }
1186
1187 if (ess_major == 0x48 && (ess_minor & 0xf0) == 0x80)
1188 printk ("Hmm... Could this be an ESS488 based card (rev %d)\n",
1189 ess_minor & 0x0f);
1190 else if (ess_major == 0x68 && (ess_minor & 0xf0) == 0x80)
1191 printk ("Hmm... Could this be an ESS688 based card (rev %d)\n",
1192 ess_minor & 0x0f);
1193 }
1194
1195 if (snd_set_irq_handler (sbc_irq, sbintr, "SoundBlaster", sb_osp) < 0)
1196 printk ("sb_dsp: Can't allocate IRQ\n");;
1197
1198 #ifndef EXCLUDE_SBPRO
1199 if (sbc_major >= 3)
1200 mixer_type = sb_mixer_init (sbc_major);
1201 #else
1202 if (sbc_major >= 3)
1203 printk ("\n\n\n\nNOTE! SB Pro support is required with your soundcard!\n\n\n");
1204 #endif
1205
1206
1207 #ifndef EXCLUDE_AUDIO
1208 if (sbc_major >= 3)
1209 {
1210 if (Jazz16_detected)
1211 {
1212 if (Jazz16_detected == 2)
1213 sprintf (sb_dsp_operations.name, "SoundMan Wave %d.%d", sbc_major, sbc_minor);
1214 else
1215 sprintf (sb_dsp_operations.name, "MV Jazz16 %d.%d", sbc_major, sbc_minor);
1216 sb_dsp_operations.format_mask |= AFMT_S16_LE;
1217 }
1218 else
1219 #ifdef __SGNXPRO__
1220 if (mixer_type == 2)
1221 {
1222 sprintf (sb_dsp_operations.name, "Sound Galaxy NX Pro %d.%d", sbc_major, sbc_minor);
1223 }
1224 else
1225 #endif
1226
1227 if (sbc_major == 4)
1228 {
1229 sprintf (sb_dsp_operations.name, "SoundBlaster 16 %d.%d", sbc_major, sbc_minor);
1230 }
1231 else
1232 {
1233 sprintf (sb_dsp_operations.name, "SoundBlaster Pro %d.%d", sbc_major, sbc_minor);
1234 }
1235 }
1236 else
1237 {
1238 sprintf (sb_dsp_operations.name, "SoundBlaster %d.%d", sbc_major, sbc_minor);
1239 }
1240
1241 printk (" <%s>", sb_dsp_operations.name);
1242
1243 #if !defined(EXCLUDE_SB16) && !defined(EXCLUDE_SBPRO)
1244 if (!sb16)
1245
1246
1247 #endif
1248 if (num_audiodevs < MAX_AUDIO_DEV)
1249 {
1250 audio_devs[my_dev = num_audiodevs++] = &sb_dsp_operations;
1251 audio_devs[my_dev]->buffsize = DSP_BUFFSIZE;
1252 dma8 = audio_devs[my_dev]->dmachan1 = hw_config->dma;
1253 audio_devs[my_dev]->dmachan2 = -1;
1254 if (sound_alloc_dma (hw_config->dma, "soundblaster"))
1255 printk ("sb_dsp.c: Can't allocate DMA channel\n");
1256 #ifdef JAZZ16
1257
1258
1259 if (Jazz16_detected != 0)
1260 if (dma16 != dma8)
1261 {
1262 if (sound_alloc_dma (dma16, "Jazz16 16 bit"))
1263 {
1264 printk ("Jazz16: Can't allocate 16 bit DMA channel\n");
1265 }
1266 }
1267 #endif
1268 }
1269 else
1270 printk ("SB: Too many DSP devices available\n");
1271 #else
1272 printk (" <SoundBlaster (configured without audio support)>");
1273 #endif
1274
1275 #ifndef EXCLUDE_MIDI
1276 if (!midi_disabled && !sb16)
1277
1278
1279
1280 sb_midi_init (sbc_major);
1281 #endif
1282
1283 sb_dsp_ok = 1;
1284 return mem_start;
1285 }
1286
1287 void
1288 sb_dsp_unload (void)
1289 {
1290 sound_free_dma (dma8);
1291 #ifdef JAZZ16
1292
1293
1294 if (Jazz16_detected != 0)
1295 if (dma16 != dma8)
1296 {
1297 sound_free_dma (dma16);
1298 }
1299 #endif
1300 snd_release_irq (sbc_irq);
1301 }
1302
1303 void
1304 sb_dsp_disable_midi (void)
1305 {
1306 midi_disabled = 1;
1307 }
1308
1309
1310 #endif