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