This source file includes following definitions.
- sb_dsp_command
- ess_write
- ess_read
- sbintr
- sb_get_irq
- sb_free_irq
- sb_reset_dsp
- dsp_speaker
- ess_speed
- dsp_speed
- dsp_set_stereo
- sb_dsp_output_block
- actually_output_block
- sb_dsp_start_input
- actually_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
- ess_init
- ess_midi_init
- Jazz16_midi_init
- Jazz16_set_dma16
- dsp_get_vers
- 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 #include <linux/config.h>
30
31
32
33
34
35
36
37
38
39
40 #include "sound_config.h"
41
42 #if defined(CONFIG_SB)
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, sbc_dma;
50 static int open_mode = 0;
51 int Jazz16_detected = 0;
52 int AudioDrive = 0;
53 static int ess_mpu_irq = 0;
54 int sb_no_recording = 0;
55 static int dsp_count = 0;
56 static int trigger_bits;
57 static int mpu_base = 0, mpu_irq = 0;
58
59
60
61
62
63
64
65
66
67 int sb_dsp_ok = 0;
68
69
70
71
72 static int midi_disabled = 0;
73 int sb_dsp_highspeed = 0;
74 int sbc_major = 0, sbc_minor = 0;
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 int sb_dsp_busy = 0;
83
84 volatile int sb_irq_mode = IMODE_NONE;
85 static volatile int irq_ok = 0;
86
87 static int dma8 = 1;
88 static int dsp_16bit = 0;
89
90
91
92
93 static int dma16 = 1;
94
95 static int dsp_set_bits (int arg);
96 static int initialize_ProSonic16 (void);
97
98
99
100
101 int sb_duplex_midi = 0;
102 static int my_dev = 0;
103
104 volatile int sb_intr_active = 0;
105
106 static int dsp_speed (int);
107 static int dsp_set_stereo (int mode);
108 static void sb_dsp_reset (int dev);
109 static void dsp_get_vers (struct address_info *hw_config);
110 int *sb_osp = NULL;
111
112 #if defined(CONFIG_MIDI) || defined(CONFIG_AUDIO)
113
114
115
116
117
118 int
119 sb_dsp_command (unsigned char val)
120 {
121 int i;
122 unsigned long limit;
123
124 limit = jiffies + HZ / 10;
125
126
127
128
129
130
131
132
133
134
135
136 for (i = 0; i < 500000 && jiffies < limit; i++)
137 {
138 if ((inb (DSP_STATUS) & 0x80) == 0)
139 {
140 outb (val, DSP_COMMAND);
141 return 1;
142 }
143 }
144
145 printk ("SoundBlaster: DSP Command(%x) Timeout.\n", val);
146 return 0;
147 }
148
149 static int
150 ess_write (unsigned char reg, unsigned char data)
151 {
152
153
154 if (!sb_dsp_command (reg))
155 return 0;
156
157 return sb_dsp_command (data);
158 }
159
160 static int
161 ess_read (unsigned char reg)
162 {
163
164
165 int i;
166
167 if (!sb_dsp_command (0xc0))
168 return -1;
169
170 if (!sb_dsp_command (reg))
171 return -1;
172
173 for (i = 1000; i; i--)
174 {
175 if (inb (DSP_DATA_AVAIL) & 0x80)
176 return inb (DSP_READ);
177 }
178
179 return -1;
180 }
181
182 void
183 sbintr (int irq, void *dev_id, struct pt_regs *dummy)
184 {
185 int status;
186
187 if (sb16 && !AudioDrive)
188 {
189 unsigned char src = sb_getmixer (IRQ_STAT);
190
191 if (src & 3)
192 sb16_dsp_interrupt (irq);
193
194 #ifdef CONFIG_MIDI
195 if (src & 4)
196 sb16midiintr (irq);
197
198
199 #endif
200
201 if (!(src & 1))
202 return;
203
204
205 }
206
207 status = inb (DSP_DATA_AVAIL);
208
209
210 if (sb_intr_active)
211 switch (sb_irq_mode)
212 {
213 case IMODE_OUTPUT:
214 if (!AudioDrive)
215 sb_intr_active = 0;
216 DMAbuf_outputintr (my_dev, 1);
217 break;
218
219 case IMODE_INPUT:
220 if (!AudioDrive)
221 sb_intr_active = 0;
222 DMAbuf_inputintr (my_dev);
223 break;
224
225 case IMODE_INIT:
226 sb_intr_active = 0;
227 irq_ok = 1;
228 break;
229
230 case IMODE_MIDI:
231 #ifdef CONFIG_MIDI
232 sb_midi_interrupt (irq);
233 #endif
234 break;
235
236 default:
237 printk ("SoundBlaster: Unexpected interrupt\n");
238 }
239 }
240
241 int
242 sb_get_irq (void)
243 {
244 return 0;
245 }
246
247 void
248 sb_free_irq (void)
249 {
250 }
251
252 int
253 sb_reset_dsp (void)
254 {
255 int loopc;
256
257 if (AudioDrive)
258 outb (3, DSP_RESET);
259 else
260 outb (1, DSP_RESET);
261
262 tenmicrosec (sb_osp);
263 outb (0, DSP_RESET);
264 tenmicrosec (sb_osp);
265 tenmicrosec (sb_osp);
266 tenmicrosec (sb_osp);
267
268 for (loopc = 0; loopc < 1000 && !(inb (DSP_DATA_AVAIL) & 0x80); loopc++);
269
270 if (inb (DSP_READ) != 0xAA)
271 return 0;
272
273 if (AudioDrive)
274 sb_dsp_command (0xc6);
275
276 return 1;
277 }
278
279 #endif
280
281 #ifdef CONFIG_AUDIO
282
283 static void
284 dsp_speaker (char state)
285 {
286 if (state)
287 sb_dsp_command (DSP_CMD_SPKON);
288 else
289 sb_dsp_command (DSP_CMD_SPKOFF);
290 }
291
292 static int
293 ess_speed (int speed)
294 {
295 int divider;
296 unsigned char bits = 0;
297
298 if (speed < 4000)
299 speed = 4000;
300 else if (speed > 48000)
301 speed = 48000;
302
303 if (speed > 22000)
304 {
305 bits = 0x80;
306 divider = 256 - (795500 + speed / 2) / speed;
307 dsp_current_speed = 795500 / (256 - divider);
308 }
309 else
310 {
311 divider = 128 - (397700 + speed / 2) / speed;
312 dsp_current_speed = 397700 / (128 - divider);
313 }
314
315 bits |= (unsigned char) divider;
316 ess_write (0xa1, bits);
317
318
319
320
321
322 speed = (speed * 9) / 20;
323 divider = 256 - 7160000 / (speed * 82);
324 ess_write (0xa2, divider);
325
326 return dsp_current_speed;
327 }
328
329 static int
330 dsp_speed (int speed)
331 {
332 unsigned char tconst;
333 unsigned long flags;
334 int max_speed = 44100;
335
336 if (AudioDrive)
337 return ess_speed (speed);
338
339 if (speed < 4000)
340 speed = 4000;
341
342
343
344
345
346 if (sbc_major < 2 ||
347 (sbc_major == 2 && sbc_minor == 0))
348 max_speed = 22050;
349
350
351
352
353 if (open_mode != OPEN_WRITE)
354 if (sbc_major < 3)
355 if (sbc_major == 2 && sbc_minor > 0)
356 max_speed = 15000;
357 else
358 max_speed = 13000;
359
360 if (speed > max_speed)
361 speed = max_speed;
362
363
364
365
366 #if !defined (SM_GAMES)
367
368
369
370 if (dsp_stereo && speed > 22050 && Jazz16_detected == 0 && AudioDrive == 0)
371 speed = 22050;
372 #endif
373
374 if ((speed > 22050) && sb_midi_busy)
375 {
376 printk ("SB Warning: High speed DSP not possible simultaneously with MIDI output\n");
377 speed = 22050;
378 }
379
380 if (dsp_stereo)
381 speed *= 2;
382
383
384
385
386
387 if (speed > 22050)
388 {
389
390
391 int tmp;
392
393 tconst = (unsigned char) ((65536 -
394 ((256000000 + speed / 2) / speed)) >> 8);
395 sb_dsp_highspeed = 1;
396
397 save_flags (flags);
398 cli ();
399 if (sb_dsp_command (0x40))
400 sb_dsp_command (tconst);
401 restore_flags (flags);
402
403 tmp = 65536 - (tconst << 8);
404 speed = (256000000 + tmp / 2) / tmp;
405 }
406 else
407 {
408 int tmp;
409
410 sb_dsp_highspeed = 0;
411 tconst = (256 - ((1000000 + speed / 2) / speed)) & 0xff;
412
413 save_flags (flags);
414 cli ();
415 if (sb_dsp_command (0x40))
416
417
418 sb_dsp_command (tconst);
419 restore_flags (flags);
420
421 tmp = 256 - tconst;
422 speed = (1000000 + tmp / 2) / tmp;
423 }
424
425 if (dsp_stereo)
426 speed /= 2;
427
428 dsp_current_speed = speed;
429 return speed;
430 }
431
432 static int
433 dsp_set_stereo (int mode)
434 {
435 dsp_stereo = 0;
436
437 if (sbc_major < 3 || sb16)
438 return 0;
439
440
441
442 if (mode && sb_midi_busy)
443 {
444 printk ("SB Warning: Stereo DSP not possible simultaneously with MIDI output\n");
445 return 0;
446 }
447
448 dsp_stereo = !!mode;
449 return dsp_stereo;
450 }
451
452 static unsigned long trg_buf;
453 static int trg_bytes;
454 static int trg_intrflag;
455 static int trg_restart;
456
457 static void
458 sb_dsp_output_block (int dev, unsigned long buf, int nr_bytes,
459 int intrflag, int restart_dma)
460 {
461 trg_buf = buf;
462 trg_bytes = nr_bytes;
463 trg_intrflag = intrflag;
464 trg_restart = restart_dma;
465 sb_irq_mode = IMODE_OUTPUT;
466 }
467
468 static void
469 actually_output_block (int dev, unsigned long buf, int nr_bytes,
470 int intrflag, int restart_dma)
471 {
472 unsigned long flags;
473 int count = nr_bytes;
474
475 if (!sb_irq_mode)
476 dsp_speaker (ON);
477
478 DMAbuf_start_dma (dev, buf, count, DMA_MODE_WRITE);
479
480 sb_irq_mode = 0;
481
482 if (audio_devs[dev]->dmachan1 > 3)
483 count >>= 1;
484 count--;
485 dsp_count = count;
486
487 sb_irq_mode = IMODE_OUTPUT;
488
489 if (AudioDrive)
490 {
491 short c = -nr_bytes;
492
493 ess_write (0xa4, (unsigned char) ((unsigned short) c & 0xff));
494 ess_write (0xa5, (unsigned char) (((unsigned short) c >> 8) & 0xff));
495
496 ess_write (0xb8, ess_read (0xb8) | 0x01);
497 }
498 else if (sb_dsp_highspeed)
499 {
500 save_flags (flags);
501 cli ();
502 if (sb_dsp_command (0x48))
503
504
505 {
506 sb_dsp_command ((unsigned char) (dsp_count & 0xff));
507 sb_dsp_command ((unsigned char) ((dsp_count >> 8) & 0xff));
508 sb_dsp_command (0x91);
509
510
511 }
512 else
513 printk ("SB Error: Unable to start (high speed) DAC\n");
514 restore_flags (flags);
515 }
516 else
517 {
518 save_flags (flags);
519 cli ();
520 if (sb_dsp_command (0x14))
521
522
523 {
524 sb_dsp_command ((unsigned char) (dsp_count & 0xff));
525 sb_dsp_command ((unsigned char) ((dsp_count >> 8) & 0xff));
526 }
527 else
528 printk ("SB Error: Unable to start DAC\n");
529 restore_flags (flags);
530 }
531 sb_intr_active = 1;
532 }
533
534 static void
535 sb_dsp_start_input (int dev, unsigned long buf, int count, int intrflag,
536 int restart_dma)
537 {
538 if (sb_no_recording)
539 {
540 return;
541 }
542
543 trg_buf = buf;
544 trg_bytes = count;
545 trg_intrflag = intrflag;
546 trg_restart = restart_dma;
547 sb_irq_mode = IMODE_INPUT;
548 }
549
550 static void
551 actually_start_input (int dev, unsigned long buf, int nr_bytes, int intrflag,
552 int restart_dma)
553 {
554 unsigned long flags;
555 int count = nr_bytes;
556
557 if (sb_no_recording)
558 {
559 return;
560 }
561
562
563
564
565
566 if (!sb_irq_mode)
567 dsp_speaker (OFF);
568
569 DMAbuf_start_dma (dev, buf, count, DMA_MODE_READ);
570 sb_irq_mode = 0;
571
572 if (audio_devs[dev]->dmachan1 > 3)
573 count >>= 1;
574 count--;
575 dsp_count = count;
576
577 sb_irq_mode = IMODE_INPUT;
578
579 if (AudioDrive)
580 {
581 short c = -nr_bytes;
582
583 ess_write (0xa4, (unsigned char) ((unsigned short) c & 0xff));
584 ess_write (0xa5, (unsigned char) (((unsigned short) c >> 8) & 0xff));
585
586 ess_write (0xb8, ess_read (0xb8) | 0x01);
587 }
588 else if (sb_dsp_highspeed)
589 {
590 save_flags (flags);
591 cli ();
592 if (sb_dsp_command (0x48))
593
594
595 {
596 sb_dsp_command ((unsigned char) (dsp_count & 0xff));
597 sb_dsp_command ((unsigned char) ((dsp_count >> 8) & 0xff));
598 sb_dsp_command (0x99);
599
600
601 }
602 else
603 printk ("SB Error: Unable to start (high speed) ADC\n");
604 restore_flags (flags);
605 }
606 else
607 {
608 save_flags (flags);
609 cli ();
610 if (sb_dsp_command (0x24))
611
612
613 {
614 sb_dsp_command ((unsigned char) (dsp_count & 0xff));
615 sb_dsp_command ((unsigned char) ((dsp_count >> 8) & 0xff));
616 }
617 else
618 printk ("SB Error: Unable to start ADC\n");
619 restore_flags (flags);
620 }
621
622 sb_intr_active = 1;
623 }
624
625 static void
626 sb_dsp_trigger (int dev, int bits)
627 {
628
629 if (!bits)
630 sb_dsp_command (0xd0);
631 else if (bits & sb_irq_mode)
632 {
633 switch (sb_irq_mode)
634 {
635 case IMODE_INPUT:
636 actually_start_input (my_dev, trg_buf, trg_bytes,
637 trg_intrflag, trg_restart);
638 break;
639
640 case IMODE_OUTPUT:
641 actually_output_block (my_dev, trg_buf, trg_bytes,
642 trg_intrflag, trg_restart);
643 break;
644 }
645 }
646
647 trigger_bits = bits;
648 }
649
650 static void
651 dsp_cleanup (void)
652 {
653 sb_intr_active = 0;
654 }
655
656 static int
657 sb_dsp_prepare_for_input (int dev, int bsize, int bcount)
658 {
659 if (sb_no_recording)
660 {
661 printk ("SB Error: This device doesn't support recording\n");
662 return 0;
663 }
664
665 dsp_cleanup ();
666 dsp_speaker (OFF);
667
668 if (sbc_major == 3)
669
670
671 {
672 if (AudioDrive)
673 {
674
675 ess_write (0xb8, 0x0e);
676 ess_write (0xa8, (ess_read (0xa8) & ~0x04) |
677 (2 - dsp_stereo));
678 ess_write (0xb9, 2);
679
680 if (!dsp_stereo)
681 {
682 if (dsp_16bit == 0)
683 {
684 ess_write (0xb7, 0x51);
685 ess_write (0xb7, 0xd0);
686 }
687 else
688 {
689 ess_write (0xb7, 0x71);
690 ess_write (0xb7, 0xf4);
691 }
692 }
693 else
694 {
695 if (!dsp_16bit)
696 {
697 ess_write (0xb7, 0x51);
698 ess_write (0xb7, 0x98);
699 }
700 else
701 {
702 ess_write (0xb7, 0x71);
703 ess_write (0xb7, 0xbc);
704 }
705 }
706
707 ess_write (0xb1, (ess_read (0xb1) & 0x0f) | 0x50);
708 ess_write (0xb2, (ess_read (0xb2) & 0x0f) | 0x50);
709 }
710 else
711 {
712
713
714
715
716 audio_devs[my_dev]->dmachan1 =
717 audio_devs[my_dev]->dmachan2 =
718 dsp_16bit ? dma16 : dma8;
719 if (dsp_stereo)
720 sb_dsp_command (dsp_16bit ? 0xac : 0xa8);
721 else
722 sb_dsp_command (dsp_16bit ? 0xa4 : 0xa0);
723
724 dsp_speed (dsp_current_speed);
725 }
726 }
727 trigger_bits = 0;
728 return 0;
729 }
730
731 static int
732 sb_dsp_prepare_for_output (int dev, int bsize, int bcount)
733 {
734 dsp_cleanup ();
735 dsp_speaker (OFF);
736
737 if (sbc_major == 3)
738 {
739
740 if (AudioDrive)
741 {
742
743 ess_write (0xb8, 4);
744 ess_write (0xa8, ess_read (0xa8) |
745 (2 - dsp_stereo));
746 ess_write (0xb9, 2);
747
748 if (!dsp_stereo)
749 {
750 if (dsp_16bit == 0)
751 {
752 ess_write (0xb6, 0x80);
753 ess_write (0xb7, 0x51);
754 ess_write (0xb7, 0xd0);
755 }
756 else
757 {
758 ess_write (0xb6, 0x00);
759 ess_write (0xb7, 0x71);
760 ess_write (0xb7, 0xf4);
761 }
762 }
763 else
764 {
765 if (!dsp_16bit)
766 {
767 ess_write (0xb6, 0x80);
768 ess_write (0xb7, 0x51);
769 ess_write (0xb7, 0x98);
770 }
771 else
772 {
773 ess_write (0xb6, 0x00);
774 ess_write (0xb7, 0x71);
775 ess_write (0xb7, 0xbc);
776 }
777 }
778
779 ess_write (0xb1, (ess_read (0xb1) & 0x0f) | 0x50);
780 ess_write (0xb2, (ess_read (0xb2) & 0x0f) | 0x50);
781 }
782 else
783 {
784
785
786
787 audio_devs[my_dev]->dmachan1 =
788 audio_devs[my_dev]->dmachan2 =
789 dsp_16bit ? dma16 : dma8;
790 if (Jazz16_detected != 2)
791 sb_mixer_set_stereo (dsp_stereo);
792 if (dsp_stereo)
793 sb_dsp_command (dsp_16bit ? 0xac : 0xa8);
794 else
795 sb_dsp_command (dsp_16bit ? 0xa4 : 0xa0);
796 }
797
798 }
799
800 trigger_bits = 0;
801 dsp_speaker (ON);
802 return 0;
803 }
804
805 static void
806 sb_dsp_halt_xfer (int dev)
807 {
808 if (AudioDrive)
809 sb_reset_dsp ();
810 }
811
812 static int
813 verify_irq (void)
814 {
815 irq_ok = 1;
816 return irq_ok;
817 }
818
819 static int
820 sb_dsp_open (int dev, int mode)
821 {
822 int retval;
823
824 if (!sb_dsp_ok)
825 {
826 printk ("SB Error: SoundBlaster board not installed\n");
827 return -ENXIO;
828 }
829
830 if (sb_no_recording && mode & OPEN_READ)
831 {
832 printk ("SB Warning: Recording not supported by this device\n");
833 }
834
835 if (sb_intr_active || (sb_midi_busy && sb_midi_mode == UART_MIDI))
836 {
837 printk ("SB: PCM not possible during MIDI input\n");
838 return -EBUSY;
839 }
840
841 if (!irq_verified)
842 {
843 verify_irq ();
844 irq_verified = 1;
845 }
846 else if (!irq_ok)
847 printk ("SB Warning: Incorrect IRQ setting %d\n",
848 sbc_irq);
849
850 retval = sb_get_irq ();
851 if (retval)
852 return retval;
853
854
855
856 audio_devs[my_dev]->dmachan1 =
857 audio_devs[my_dev]->dmachan2 =
858 dma8;
859
860
861
862 if (Jazz16_detected != 0)
863 if (dma16 != dma8)
864 {
865 if (sound_open_dma (dma16, "Jazz16 16 bit"))
866 {
867 sb_free_irq ();
868
869 return -EBUSY;
870 }
871 }
872
873 sb_irq_mode = IMODE_NONE;
874
875 sb_dsp_busy = 1;
876 open_mode = mode;
877
878 return 0;
879 }
880
881 static void
882 sb_dsp_close (int dev)
883 {
884
885
886 if (Jazz16_detected)
887 {
888 audio_devs[my_dev]->dmachan1 =
889 audio_devs[my_dev]->dmachan2 =
890 dma8;
891
892 if (dma16 != dma8)
893 sound_close_dma (dma16);
894 }
895
896 if (AudioDrive)
897 sb_reset_dsp ();
898
899
900 sb_free_irq ();
901
902 dsp_cleanup ();
903 dsp_speaker (OFF);
904 sb_dsp_busy = 0;
905 sb_dsp_highspeed = 0;
906 open_mode = 0;
907 }
908
909 static int
910 dsp_set_bits (int arg)
911 {
912 if (arg)
913 if (Jazz16_detected == 0 && AudioDrive == 0)
914 dsp_16bit = 0;
915 else
916 switch (arg)
917 {
918 case 8:
919 dsp_16bit = 0;
920 break;
921 case 16:
922 dsp_16bit = 1;
923 break;
924 default:
925 dsp_16bit = 0;
926 }
927
928 return dsp_16bit ? 16 : 8;
929 }
930
931 static int
932 sb_dsp_ioctl (int dev, unsigned int cmd, caddr_t arg, int local)
933 {
934 switch (cmd)
935 {
936 case SOUND_PCM_WRITE_RATE:
937 if (local)
938 return dsp_speed ((int) arg);
939 return snd_ioctl_return ((int *) arg, dsp_speed (get_fs_long ((long *) arg)));
940 break;
941
942 case SOUND_PCM_READ_RATE:
943 if (local)
944 return dsp_current_speed;
945 return snd_ioctl_return ((int *) arg, dsp_current_speed);
946 break;
947
948 case SOUND_PCM_WRITE_CHANNELS:
949 if (local)
950 return dsp_set_stereo ((int) arg - 1) + 1;
951 return snd_ioctl_return ((int *) arg, dsp_set_stereo (get_fs_long ((long *) arg) - 1) + 1);
952 break;
953
954 case SOUND_PCM_READ_CHANNELS:
955 if (local)
956 return dsp_stereo + 1;
957 return snd_ioctl_return ((int *) arg, dsp_stereo + 1);
958 break;
959
960 case SNDCTL_DSP_STEREO:
961 if (local)
962 return dsp_set_stereo ((int) arg);
963 return snd_ioctl_return ((int *) arg, dsp_set_stereo (get_fs_long ((long *) arg)));
964 break;
965
966
967
968
969 case SNDCTL_DSP_SETFMT:
970 if (local)
971 return dsp_set_bits ((int) arg);
972 return snd_ioctl_return ((int *) arg, dsp_set_bits (get_fs_long ((long *) arg)));
973 break;
974
975 case SOUND_PCM_READ_BITS:
976 if (local)
977 return dsp_16bit ? 16 : 8;
978 return snd_ioctl_return ((int *) arg, dsp_16bit ? 16 : 8);
979 break;
980
981 case SOUND_PCM_WRITE_FILTER:
982 case SOUND_PCM_READ_FILTER:
983 return -EINVAL;
984 break;
985
986 default:;
987 }
988
989 return -EINVAL;
990 }
991
992 static void
993 sb_dsp_reset (int dev)
994 {
995 unsigned long flags;
996
997 save_flags (flags);
998 cli ();
999
1000 sb_reset_dsp ();
1001 dsp_speed (dsp_current_speed);
1002 dsp_cleanup ();
1003
1004 restore_flags (flags);
1005 }
1006
1007 #endif
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021 unsigned int
1022 get_sb_byte (void)
1023 {
1024 int i;
1025
1026 for (i = 1000; i; i--)
1027 if (inb (DSP_DATA_AVAIL) & 0x80)
1028 {
1029 return inb (DSP_READ);
1030 }
1031
1032 return 0xffff;
1033 }
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045 static void
1046 smw_putmem (int base, int addr, unsigned char val)
1047 {
1048 unsigned long flags;
1049
1050 save_flags (flags);
1051 cli ();
1052
1053 outb (addr & 0xff, base + 1);
1054 outb (addr >> 8, base + 2);
1055 outb (val, base);
1056
1057 restore_flags (flags);
1058 }
1059
1060 static unsigned char
1061 smw_getmem (int base, int addr)
1062 {
1063 unsigned long flags;
1064 unsigned char val;
1065
1066 save_flags (flags);
1067 cli ();
1068
1069 outb (addr & 0xff, base + 1);
1070 outb (addr >> 8, base + 2);
1071 val = inb (base);
1072
1073 restore_flags (flags);
1074 return val;
1075 }
1076
1077 #ifdef SMW_MIDI0001_INCLUDED
1078 #include "smw-midi0001.h"
1079 #else
1080 unsigned char *smw_ucode = NULL;
1081 int smw_ucodeLen = 0;
1082
1083 #endif
1084
1085 static int
1086 initialize_smw (int mpu_base)
1087 {
1088
1089 int mp_base = mpu_base + 4;
1090 int i;
1091 unsigned char control;
1092
1093
1094
1095
1096
1097
1098 control = inb (mpu_base + 7);
1099 outb (control | 3, mpu_base + 7);
1100 outb ((control & 0xfe) | 2, mpu_base + 7);
1101
1102 for (i = 0; i < 300; i++)
1103 tenmicrosec (sb_osp);
1104
1105 outb (control & 0xfc, mpu_base + 7);
1106
1107
1108
1109
1110 smw_putmem (mp_base, 0, 0x00);
1111 smw_putmem (mp_base, 1, 0xff);
1112 tenmicrosec (sb_osp);
1113
1114 if (smw_getmem (mp_base, 0) != 0x00 || smw_getmem (mp_base, 1) != 0xff)
1115 {
1116 printk ("\nSM Wave: No microcontroller RAM detected (%02x, %02x)\n",
1117 smw_getmem (mp_base, 0), smw_getmem (mp_base, 1));
1118 return 0;
1119 }
1120
1121
1122
1123
1124
1125 if (smw_ucodeLen > 0)
1126 {
1127 if (smw_ucodeLen != 8192)
1128 {
1129 printk ("\nSM Wave: Invalid microcode (MIDI0001.BIN) length\n");
1130 return 1;
1131 }
1132
1133
1134
1135
1136
1137 for (i = 0; i < 8192; i++)
1138 smw_putmem (mp_base, i, smw_ucode[i]);
1139
1140
1141
1142
1143
1144 for (i = 0; i < 8192; i++)
1145 if (smw_getmem (mp_base, i) != smw_ucode[i])
1146 {
1147 printk ("SM Wave: Microcode verification failed\n");
1148 return 0;
1149 }
1150 }
1151
1152 control = 0;
1153 #ifdef SMW_SCSI_IRQ
1154
1155
1156
1157
1158
1159
1160 {
1161 static unsigned char scsi_irq_bits[] =
1162 {0, 0, 3, 1, 0, 0, 0, 0, 0, 3, 2, 0, 0, 0, 0, 0};
1163
1164 control |= scsi_irq_bits[SMW_SCSI_IRQ] << 6;
1165 }
1166 #endif
1167
1168 #ifdef SMW_OPL4_ENABLE
1169
1170
1171
1172
1173
1174
1175
1176 control |= 0x10;
1177
1178 #endif
1179
1180 outb (control | 0x03, mpu_base + 7);
1181 return 1;
1182 }
1183
1184 static int
1185 initialize_ProSonic16 (void)
1186 {
1187 int x;
1188 static unsigned char int_translat[16] =
1189 {0, 0, 2, 3, 0, 1, 0, 4, 0, 2, 5, 0, 0, 0, 0, 6}, dma_translat[8] =
1190 {0, 1, 0, 2, 0, 3, 0, 4};
1191
1192 outb (0xAF, 0x201);
1193 for (x = 0; x < 1000; ++x)
1194 tenmicrosec (sb_osp);
1195 outb (0x50, 0x201);
1196 outb ((sbc_base & 0x70) | ((mpu_base & 0x30) >> 4), 0x201);
1197
1198 if (sb_reset_dsp ())
1199 {
1200
1201
1202
1203 if (!sb_dsp_command (0xFA))
1204 return 1;
1205 if (get_sb_byte () != 0x12)
1206 return 1;
1207
1208 if (sb_dsp_command (0xFB) &&
1209 sb_dsp_command ((dma_translat[dma16] << 4) | dma_translat[dma8]) &&
1210 sb_dsp_command ((int_translat[mpu_irq] << 4) | int_translat[sbc_irq]))
1211 {
1212 Jazz16_detected = 1;
1213
1214 if (mpu_base != 0)
1215 if (initialize_smw (mpu_base))
1216 Jazz16_detected = 2;
1217
1218 sb_dsp_disable_midi ();
1219 }
1220
1221 return 1;
1222 }
1223 return 0;
1224 }
1225
1226 int
1227 sb_dsp_detect (struct address_info *hw_config)
1228 {
1229 if (sb_dsp_ok)
1230 return 0;
1231
1232
1233
1234 sbc_base = hw_config->io_base;
1235 sbc_irq = hw_config->irq;
1236 sbc_dma = hw_config->dma;
1237 sb_osp = hw_config->osp;
1238 dma8 = dma16 = hw_config->dma;
1239
1240 if (sb_reset_dsp ())
1241 dsp_get_vers (hw_config);
1242 else
1243 sbc_major = 0;
1244
1245 if (sbc_major == 3 || sbc_major == 0)
1246 if (initialize_ProSonic16 ())
1247 return 1;
1248
1249 if (!sb_reset_dsp ())
1250 return 0;
1251
1252 return 1;
1253
1254
1255 }
1256
1257 #ifdef CONFIG_AUDIO
1258 static struct audio_operations sb_dsp_operations =
1259 {
1260 "SoundBlaster",
1261 NOTHING_SPECIAL,
1262 AFMT_U8,
1263 NULL,
1264 sb_dsp_open,
1265 sb_dsp_close,
1266 sb_dsp_output_block,
1267 sb_dsp_start_input,
1268 sb_dsp_ioctl,
1269 sb_dsp_prepare_for_input,
1270 sb_dsp_prepare_for_output,
1271 sb_dsp_reset,
1272 sb_dsp_halt_xfer,
1273 NULL,
1274 NULL,
1275 NULL,
1276 NULL,
1277 sb_dsp_trigger
1278 };
1279
1280 #endif
1281
1282 static void
1283 ess_init (int ess_minor)
1284 {
1285 unsigned char cfg, irq_bits = 0, dma_bits = 0;
1286
1287 AudioDrive = 1;
1288
1289 if (ess_minor >= 8)
1290 midi_disabled = 1;
1291
1292 sb_reset_dsp ();
1293
1294
1295
1296
1297
1298 cfg = 0x50;
1299
1300 switch (sbc_irq)
1301 {
1302 case 2:
1303 case 9:
1304 irq_bits = 0;
1305 break;
1306
1307 case 5:
1308 irq_bits = 1;
1309 break;
1310
1311 case 7:
1312 irq_bits = 2;
1313 break;
1314
1315 case 10:
1316 irq_bits = 3;
1317 break;
1318
1319 default:
1320 irq_bits = 0;
1321 cfg = 0x10;
1322 printk ("\nESS1688: Invalid IRQ %d\n", sbc_irq);
1323 }
1324
1325 if (!ess_write (0xb1, cfg | (irq_bits << 2)))
1326 printk ("\nESS1688: Failed to write to IRQ config register\n");
1327
1328
1329
1330
1331
1332 cfg = 0x50;
1333
1334 if (sbc_dma > 3 || sbc_dma < 0 || sbc_dma == 2)
1335 {
1336 dma_bits = 0;
1337 cfg = 0x00;
1338 printk ("\nESS1688: Invalid DMA %d\n", sbc_dma);
1339 }
1340 else
1341 {
1342 if (sbc_dma == 3)
1343 dma_bits = 3;
1344 else
1345 dma_bits = sbc_dma + 1;
1346 }
1347
1348 if (!ess_write (0xb2, cfg | (dma_bits << 2)))
1349 printk ("\nESS1688: Failed to write to DMA config register\n");
1350
1351
1352
1353
1354
1355 cfg = sb_getmixer (0x40);
1356 sb_setmixer (0x40, cfg | 0x03);
1357 }
1358
1359 #ifdef CONFIG_MIDI
1360 void
1361 ess_midi_init (struct address_info *hw_config)
1362 {
1363 unsigned char cfg, tmp;
1364
1365 cfg = sb_getmixer (0x40) & 0x03;
1366
1367 tmp = (hw_config->io_base & 0x0f0) >> 4;
1368
1369 if (tmp > 3)
1370 {
1371 sb_setmixer (0x40, cfg);
1372 return;
1373 }
1374
1375 cfg |= tmp << 3;
1376
1377 tmp = 1;
1378
1379 switch (hw_config->irq)
1380 {
1381 case 9:
1382 tmp = 0x4;
1383 break;
1384 case 5:
1385 tmp = 0x5;
1386 break;
1387 case 7:
1388 tmp = 0x6;
1389 break;
1390 case 10:
1391 tmp = 0x7;
1392 break;
1393 }
1394
1395 cfg |= tmp << 5;
1396
1397 if (tmp != 1)
1398 {
1399 ess_mpu_irq = hw_config->irq;
1400
1401 if (snd_set_irq_handler (ess_mpu_irq, sbmidiintr, "ES1688 MIDI", sb_osp) < 0)
1402 printk ("ES1688: Can't allocate IRQ%d\n", ess_mpu_irq);
1403 }
1404
1405 sb_setmixer (0x40, cfg);
1406 }
1407 #endif
1408
1409 void
1410 Jazz16_midi_init (struct address_info *hw_config)
1411 {
1412 extern void smw_mixer_init (void);
1413 extern void sb_mixer_reset (void);
1414
1415 mpu_base = hw_config->io_base;
1416 mpu_irq = hw_config->irq;
1417
1418 initialize_ProSonic16 ();
1419
1420 smw_mixer_init ();
1421 sb_mixer_reset ();
1422 }
1423
1424 void
1425 Jazz16_set_dma16 (int dma)
1426 {
1427 dma16 = dma;
1428
1429
1430
1431 if (dma16 != dma8)
1432 {
1433 if (sound_alloc_dma (dma16, "Jazz16 16 bit"))
1434 {
1435 printk ("Jazz16: Can't allocate 16 bit DMA channel\n");
1436 Jazz16_detected = 0;
1437 return;
1438 }
1439 }
1440 initialize_ProSonic16 ();
1441 }
1442
1443 static void
1444 dsp_get_vers (struct address_info *hw_config)
1445 {
1446 int i;
1447
1448 unsigned long flags;
1449
1450 save_flags (flags);
1451 cli ();
1452 sb_osp = hw_config->osp;
1453 sbc_major = sbc_minor = 0;
1454 sb_dsp_command (0xe1);
1455
1456 for (i = 100000; i; i--)
1457 {
1458 if (inb (DSP_DATA_AVAIL) & 0x80)
1459 {
1460 if (sbc_major == 0)
1461 sbc_major = inb (DSP_READ);
1462 else
1463 {
1464 sbc_minor = inb (DSP_READ);
1465 break;
1466 }
1467 }
1468 }
1469 restore_flags (flags);
1470 }
1471
1472 long
1473 sb_dsp_init (long mem_start, struct address_info *hw_config)
1474 {
1475 int i;
1476 int ess_major = 0, ess_minor = 0;
1477
1478 int mixer_type = 0;
1479
1480 if (sbc_major == 0)
1481 dsp_get_vers (hw_config);
1482
1483 if (sbc_major == 0)
1484 {
1485 sb_reset_dsp ();
1486 dsp_get_vers (hw_config);
1487 }
1488
1489 if (sbc_major == 0)
1490 {
1491 printk ("\n\nFailed to get SB version (%x) - possible I/O conflict?\n\n",
1492 inb (DSP_DATA_AVAIL));
1493 sbc_major = 1;
1494 }
1495
1496 if (sbc_major == 2 || sbc_major == 3)
1497 sb_duplex_midi = 1;
1498
1499 if (sbc_major == 4)
1500 sb16 = 1;
1501
1502 if (sbc_major == 3 && sbc_minor == 1)
1503 {
1504
1505
1506
1507
1508
1509 sb_dsp_command (0xe7);
1510
1511
1512
1513 for (i = 1000; i; i--)
1514 {
1515 if (inb (DSP_DATA_AVAIL) & 0x80)
1516 {
1517
1518
1519 if (ess_major == 0)
1520 ess_major = inb (DSP_READ);
1521 else
1522 {
1523 ess_minor = inb (DSP_READ);
1524 break;
1525 }
1526 }
1527 }
1528 }
1529
1530 if (snd_set_irq_handler (sbc_irq, sbintr, "SoundBlaster", sb_osp) < 0)
1531 printk ("sb_dsp: Can't allocate IRQ\n");;
1532
1533 #ifdef CONFIG_AUDIO
1534 if (sbc_major >= 3)
1535 {
1536 if (Jazz16_detected)
1537 {
1538 if (Jazz16_detected == 2)
1539 sprintf (sb_dsp_operations.name, "SoundMan Wave %d.%d", sbc_major, sbc_minor);
1540 else
1541 sprintf (sb_dsp_operations.name, "MV Jazz16 %d.%d", sbc_major, sbc_minor);
1542 sb_dsp_operations.format_mask |= AFMT_S16_LE;
1543 }
1544 else
1545 #ifdef __SGNXPRO__
1546 if (mixer_type == 2)
1547 {
1548 sprintf (sb_dsp_operations.name, "Sound Galaxy NX Pro %d.%d", sbc_major, sbc_minor);
1549 }
1550 else
1551 #endif
1552
1553 if (sbc_major == 4)
1554 {
1555 sprintf (sb_dsp_operations.name, "SoundBlaster 16 %d.%d", sbc_major, sbc_minor);
1556 }
1557 else if (ess_major != 0)
1558 {
1559 if (ess_major == 0x48 && (ess_minor & 0xf0) == 0x80)
1560 sprintf (sb_dsp_operations.name, "ESS ES488 AudioDrive (rev %d)",
1561 ess_minor & 0x0f);
1562 else if (ess_major == 0x68 && (ess_minor & 0xf0) == 0x80)
1563 {
1564 sprintf (sb_dsp_operations.name,
1565 "ESS ES1688 AudioDrive (rev %d)",
1566 ess_minor & 0x0f);
1567 sb_dsp_operations.format_mask |= AFMT_S16_LE;
1568 ess_init (ess_minor);
1569 }
1570 }
1571 else
1572 {
1573 sprintf (sb_dsp_operations.name, "SoundBlaster Pro %d.%d", sbc_major, sbc_minor);
1574 }
1575 }
1576 else
1577 {
1578 sprintf (sb_dsp_operations.name, "SoundBlaster %d.%d", sbc_major, sbc_minor);
1579 }
1580
1581 conf_printf (sb_dsp_operations.name, hw_config);
1582
1583 if (sbc_major >= 3)
1584 mixer_type = sb_mixer_init (sbc_major);
1585
1586 if (!sb16)
1587 if (num_audiodevs < MAX_AUDIO_DEV)
1588 {
1589 audio_devs[my_dev = num_audiodevs++] = &sb_dsp_operations;
1590
1591 if (AudioDrive)
1592 audio_devs[my_dev]->flags |= DMA_AUTOMODE;
1593
1594 audio_devs[my_dev]->buffsize = DSP_BUFFSIZE;
1595 dma8 = audio_devs[my_dev]->dmachan1 = hw_config->dma;
1596 dma16 = audio_devs[my_dev]->dmachan2 = hw_config->dma;
1597 if (sound_alloc_dma (hw_config->dma, "SoundBlaster"))
1598 printk ("sb_dsp.c: Can't allocate DMA channel\n");
1599 }
1600 else
1601 printk ("SB: Too many DSP devices available\n");
1602 #else
1603 conf_printf ("SoundBlaster (configured without audio support)", hw_config);
1604 #endif
1605
1606 #ifdef CONFIG_MIDI
1607 if (!midi_disabled && !sb16)
1608
1609
1610
1611 sb_midi_init (sbc_major);
1612 #endif
1613
1614 sb_dsp_ok = 1;
1615 sb_reset_dsp ();
1616 return mem_start;
1617 }
1618
1619 void
1620 sb_dsp_unload (void)
1621 {
1622 sound_free_dma (dma8);
1623
1624
1625
1626 if (Jazz16_detected != 0)
1627 if (dma16 != dma8)
1628 {
1629 sound_free_dma (dma16);
1630 }
1631 snd_release_irq (sbc_irq);
1632
1633 if (AudioDrive && ess_mpu_irq)
1634 {
1635 snd_release_irq (ess_mpu_irq);
1636 }
1637 }
1638
1639 void
1640 sb_dsp_disable_midi (void)
1641 {
1642 midi_disabled = 1;
1643 }
1644
1645
1646 #endif