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