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