This source file includes following definitions.
- sb_midi_open
- sb_midi_close
- sb_midi_out
- sb_midi_start_read
- sb_midi_end_read
- sb_midi_ioctl
- sb_midi_interrupt
- sb_midi_init
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 #include "sound_config.h"
31
32 #if defined(CONFIGURE_SOUNDCARD) && !defined(EXCLUDE_SB) && !defined(EXCLUDE_MIDI)
33
34 #include "sb.h"
35 #undef SB_TEST_IRQ
36
37
38
39
40
41
42
43
44
45 extern int sb_dsp_ok;
46
47 extern int sb_midi_mode;
48 extern int sb_midi_busy;
49 extern int sb_dsp_busy;
50 extern int sb_dsp_highspeed;
51
52 extern volatile int sb_irq_mode;
53
54
55 extern int sb_duplex_midi;
56 extern int sb_intr_active;
57 extern int sbc_base;
58
59 static int input_opened = 0;
60 static void (*midi_input_intr) (int dev, unsigned char data);
61 static int my_dev = 0;
62
63 static int
64 sb_midi_open (int dev, int mode,
65 void (*input) (int dev, unsigned char data),
66 void (*output) (int dev)
67 )
68 {
69 int ret;
70
71 if (!sb_dsp_ok)
72 {
73 printk ("SB Error: MIDI hardware not installed\n");
74 return RET_ERROR (ENXIO);
75 }
76
77 if (mode != OPEN_WRITE && !sb_duplex_midi)
78 {
79 if (num_midis == 1)
80 printk ("SoundBlaster: MIDI input not supported with plain SB\n");
81 return RET_ERROR (EPERM);
82 }
83
84 sb_midi_mode = NORMAL_MIDI;
85 if (mode != OPEN_WRITE)
86 {
87 if (sb_dsp_busy || sb_intr_active)
88 return RET_ERROR (EBUSY);
89 sb_midi_mode = UART_MIDI;
90 }
91
92 if (sb_dsp_highspeed)
93 {
94 printk ("SB Error: Midi output not possible during stereo or high speed audio\n");
95 return RET_ERROR (EBUSY);
96 }
97
98 if (sb_midi_mode == UART_MIDI)
99 {
100 sb_irq_mode = IMODE_MIDI;
101
102 sb_reset_dsp ();
103
104 if (!sb_dsp_command (0xf2))
105 return RET_ERROR (EIO);
106
107 if (!sb_dsp_command (0x35))
108 return RET_ERROR (EIO);
109 sb_intr_active = 1;
110
111 if ((ret = sb_get_irq ()) < 0)
112 {
113 sb_reset_dsp ();
114 return 0;
115 }
116 input_opened = 1;
117 my_dev = dev;
118 midi_input_intr = input;
119 }
120
121 sb_midi_busy = 1;
122
123 return 0;
124 }
125
126 static void
127 sb_midi_close (int dev)
128 {
129 if (sb_midi_mode == UART_MIDI)
130 {
131 sb_reset_dsp ();
132 sb_free_irq ();
133 }
134 sb_intr_active = 0;
135 sb_midi_busy = 0;
136 input_opened = 0;
137 }
138
139 static int
140 sb_midi_out (int dev, unsigned char midi_byte)
141 {
142 unsigned long flags;
143
144 sb_midi_busy = 1;
145
146 if (sb_midi_mode == NORMAL_MIDI)
147 {
148 DISABLE_INTR (flags);
149 if (sb_dsp_command (0x38))
150 sb_dsp_command (midi_byte);
151 else
152 printk ("SB Error: Unable to send a MIDI byte\n");
153 RESTORE_INTR (flags);
154 }
155 else
156 sb_dsp_command (midi_byte);
157
158 return 1;
159 }
160
161 static int
162 sb_midi_start_read (int dev)
163 {
164 if (sb_midi_mode != UART_MIDI)
165 {
166 printk ("SoundBlaster: MIDI input not implemented.\n");
167 return RET_ERROR (EPERM);
168 }
169 return 0;
170 }
171
172 static int
173 sb_midi_end_read (int dev)
174 {
175 if (sb_midi_mode == UART_MIDI)
176 {
177 sb_reset_dsp ();
178 sb_intr_active = 0;
179 }
180 return 0;
181 }
182
183 static int
184 sb_midi_ioctl (int dev, unsigned cmd, unsigned arg)
185 {
186 return RET_ERROR (EPERM);
187 }
188
189 void
190 sb_midi_interrupt (int dummy)
191 {
192 unsigned long flags;
193 unsigned char data;
194
195 DISABLE_INTR (flags);
196
197 data = INB (DSP_READ);
198 if (input_opened)
199 midi_input_intr (my_dev, data);
200
201 RESTORE_INTR (flags);
202 }
203
204 static struct midi_operations sb_midi_operations =
205 {
206 {"SoundBlaster", 0, 0, SNDCARD_SB},
207 sb_midi_open,
208 sb_midi_close,
209 sb_midi_ioctl,
210 sb_midi_out,
211 sb_midi_start_read,
212 sb_midi_end_read,
213 NULL,
214 NULL,
215 NULL
216 };
217
218 void
219 sb_midi_init (int model)
220 {
221 midi_devs[num_midis++] = &sb_midi_operations;
222 }
223
224 #endif